-
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.
Merge pull request #103 from mystchonky/dev/travel-staff
- Loading branch information
Showing
52 changed files
with
1,622 additions
and
137 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.enderio.api.travel; | ||
|
||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.nbt.CompoundTag; | ||
import net.minecraft.resources.ResourceLocation; | ||
|
||
public interface ITravelTarget { | ||
ResourceLocation getSerializationName(); | ||
|
||
BlockPos getPos(); | ||
|
||
CompoundTag save(); | ||
|
||
int getItem2BlockRange(); | ||
|
||
int getBlock2BlockRange(); | ||
|
||
default boolean canTravelTo() { | ||
return true; | ||
} | ||
} |
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,9 @@ | ||
package com.enderio.api.travel; | ||
|
||
import net.minecraft.nbt.CompoundTag; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraftforge.common.util.Lazy; | ||
|
||
import java.util.function.Function; | ||
public record TravelEntry<T extends ITravelTarget>(ResourceLocation serializationName, Function<CompoundTag, T> constructor, | ||
Lazy<TravelRenderer<T>> renderer) {} |
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,45 @@ | ||
package com.enderio.api.travel; | ||
|
||
import net.minecraft.nbt.CompoundTag; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraftforge.common.util.Lazy; | ||
import org.jetbrains.annotations.ApiStatus; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.function.Function; | ||
|
||
@ApiStatus.Internal | ||
public class TravelRegistry { | ||
|
||
private static final Map<ResourceLocation, TravelEntry<?>> registry = new HashMap<>(); | ||
|
||
public static <T extends ITravelTarget> void addTravelEntry(ResourceLocation serializationName, Function<CompoundTag, T> constructor, | ||
Lazy<TravelRenderer<T>> renderer) { | ||
registry.put(serializationName, new TravelEntry<>(serializationName, constructor, renderer)); | ||
} | ||
|
||
public static <T extends ITravelTarget> void addTravelEntry(TravelEntry<?> travelEntry) { | ||
registry.put(travelEntry.serializationName(), travelEntry); | ||
} | ||
|
||
public static <T extends ITravelTarget> TravelRenderer<T> getRenderer(T entry) { | ||
return (TravelRenderer<T>) registry.get(entry.getSerializationName()).renderer().get(); | ||
} | ||
|
||
public static Optional<ITravelTarget> deserialize(CompoundTag nbt) { | ||
return Optional.ofNullable(registry.get(new ResourceLocation(nbt.getString("name")))).map(entry -> entry.constructor().apply(nbt.getCompound("data"))); | ||
} | ||
|
||
public static boolean isRegistered(ITravelTarget target) { | ||
return registry.containsKey(target.getSerializationName()); | ||
} | ||
|
||
public static CompoundTag serialize(ITravelTarget travelData) { | ||
CompoundTag nbt = new CompoundTag(); | ||
nbt.putString("name", travelData.getSerializationName().toString()); | ||
nbt.put("data", travelData.save()); | ||
return nbt; | ||
} | ||
} |
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,8 @@ | ||
package com.enderio.api.travel; | ||
|
||
import com.mojang.blaze3d.vertex.PoseStack; | ||
import net.minecraft.client.renderer.LevelRenderer; | ||
|
||
public interface TravelRenderer<T extends ITravelTarget> { | ||
void render(T travelData, LevelRenderer levelRenderer, PoseStack poseStack, double distanceSquared, boolean active); | ||
} |
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,5 @@ | ||
@javax.annotation.ParametersAreNonnullByDefault | ||
@net.minecraft.MethodsReturnNonnullByDefault | ||
@com.tterrag.registrate.util.nullness.FieldsAreNonnullByDefault | ||
|
||
package com.enderio.api.travel; |
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
42 changes: 42 additions & 0 deletions
42
src/core/java/com/enderio/core/common/network/slot/StringNetworkDataSlot.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,42 @@ | ||
package com.enderio.core.common.network.slot; | ||
|
||
import net.minecraft.nbt.StringTag; | ||
import net.minecraft.nbt.Tag; | ||
import net.minecraft.network.FriendlyByteBuf; | ||
|
||
import java.util.function.Consumer; | ||
import java.util.function.Supplier; | ||
|
||
public class StringNetworkDataSlot extends NetworkDataSlot<String> { | ||
public StringNetworkDataSlot(Supplier<String> getter, Consumer<String> setter) { | ||
super(getter, setter); | ||
} | ||
|
||
@Override | ||
public Tag serializeValueNBT(String value) { | ||
return StringTag.valueOf(value); | ||
} | ||
|
||
@Override | ||
protected String valueFromNBT(Tag nbt) { | ||
if (nbt instanceof StringTag stringTag) { | ||
return stringTag.getAsString(); | ||
} else { | ||
throw new IllegalStateException("Invalid string tag was passed over the network."); | ||
} | ||
} | ||
|
||
@Override | ||
public void toBuffer(FriendlyByteBuf buf, String value) { | ||
buf.writeUtf(value); | ||
} | ||
|
||
@Override | ||
public String valueFromBuffer(FriendlyByteBuf buf) { | ||
try { | ||
return buf.readUtf(); | ||
} catch (Exception e) { | ||
throw new IllegalStateException("Invalid string buffer was passed over the network."); | ||
} | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/generated/resources/assets/enderio/blockstates/travel_anchor.json
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,7 @@ | ||
{ | ||
"variants": { | ||
"": { | ||
"model": "enderio:block/travel_anchor" | ||
} | ||
} | ||
} |
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
6 changes: 6 additions & 0 deletions
6
src/generated/resources/assets/enderio/models/item/staff_of_travelling.json
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,6 @@ | ||
{ | ||
"parent": "minecraft:item/generated", | ||
"textures": { | ||
"layer0": "enderio:item/staff_of_travelling" | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
src/generated/resources/assets/enderio/models/item/travel_anchor.json
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,3 @@ | ||
{ | ||
"parent": "enderio:block/travel_anchor" | ||
} |
29 changes: 29 additions & 0 deletions
29
src/generated/resources/data/enderio/loot_tables/blocks/travel_anchor.json
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,29 @@ | ||
{ | ||
"type": "minecraft:block", | ||
"pools": [ | ||
{ | ||
"bonus_rolls": 0.0, | ||
"entries": [ | ||
{ | ||
"type": "minecraft:item", | ||
"functions": [ | ||
{ | ||
"function": "minecraft:copy_nbt", | ||
"ops": [ | ||
{ | ||
"op": "replace", | ||
"source": "", | ||
"target": "BlockEntityTag" | ||
} | ||
], | ||
"source": "block_entity" | ||
} | ||
], | ||
"name": "enderio:travel_anchor" | ||
} | ||
], | ||
"rolls": 1.0 | ||
} | ||
], | ||
"random_sequence": "enderio:blocks/travel_anchor" | ||
} |
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
Oops, something went wrong.