-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
20.6: Change TravelTargetApi over to ServiceLoader
- Loading branch information
Showing
14 changed files
with
81 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.enderio.api.travel; | ||
|
||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.world.level.Level; | ||
|
||
import java.util.Collection; | ||
import java.util.Optional; | ||
import java.util.ServiceLoader; | ||
import java.util.stream.Stream; | ||
|
||
public interface TravelTargetApi { | ||
|
||
TravelTargetApi INSTANCE = ServiceLoader.load(TravelTargetApi.class).findFirst().orElseThrow(); | ||
|
||
Optional<TravelTarget> get(Level level, BlockPos pos); | ||
<T extends TravelTarget> void set(Level level, T travelTarget); | ||
void removeAt(Level level, BlockPos pos); | ||
Collection<TravelTarget> getAll(Level level); | ||
Stream<TravelTarget> getInItemRange(Level level, BlockPos center); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/main/java/com/enderio/base/common/travel/TravelTargetApiImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.enderio.base.common.travel; | ||
|
||
import com.enderio.api.travel.TravelTarget; | ||
import com.enderio.api.travel.TravelTargetApi; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.world.level.Level; | ||
|
||
import java.util.Collection; | ||
import java.util.Optional; | ||
import java.util.stream.Stream; | ||
|
||
public class TravelTargetApiImpl implements TravelTargetApi { | ||
|
||
@Override | ||
public Optional<TravelTarget> get(Level level, BlockPos pos) { | ||
return TravelTargetSavedData.getTravelData(level).getTravelTarget(pos); | ||
} | ||
|
||
@Override | ||
public <T extends TravelTarget> void set(Level level, T travelTarget) { | ||
TravelTargetSavedData.getTravelData(level).setTravelTarget(level, travelTarget); | ||
} | ||
|
||
@Override | ||
public void removeAt(Level level, BlockPos pos) { | ||
TravelTargetSavedData.getTravelData(level).removeTravelTargetAt(level, pos); | ||
} | ||
|
||
@Override | ||
public Collection<TravelTarget> getAll(Level level) { | ||
return TravelTargetSavedData.getTravelData(level).getTravelTargets(); | ||
} | ||
|
||
@Override | ||
public Stream<TravelTarget> getInItemRange(Level level, BlockPos center) { | ||
return TravelTargetSavedData.getTravelData(level).getTravelTargetsInItemRange(center); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
src/main/resources/META-INF/services/com.enderio.api.travel.TravelTargetApi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
com.enderio.base.common.travel.TravelTargetApiImpl |