mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-28 11:29:17 +00:00
迁移新版配方
This commit is contained in:
@@ -3007,18 +3007,32 @@ public class BukkitNetworkManager implements NetworkManager, Listener, PluginMes
|
||||
@Override
|
||||
public void onPacketSend(NetWorkUser user, ByteBufPacketEvent event) {
|
||||
if (Config.disableItemOperations()) return;
|
||||
MutableBoolean changed = new MutableBoolean(false);
|
||||
FriendlyByteBuf buf = event.getBuffer();
|
||||
List<RecipeBookEntry> entries = buf.readCollection(ArrayList::new, byteBuf -> {
|
||||
RecipeBookEntry entry = RecipeBookEntry.read(byteBuf);
|
||||
entry.applyClientboundData((BukkitServerPlayer) user);
|
||||
BukkitItemManager itemManager = BukkitItemManager.instance();
|
||||
BukkitServerPlayer player = (BukkitServerPlayer) user;
|
||||
Object friendlyBuf = FastNMS.INSTANCE.constructor$FriendlyByteBuf(buf.source());
|
||||
List<RecipeBookEntry<ItemStack>> entries = buf.readCollection(ArrayList::new, byteBuf -> {
|
||||
RecipeBookEntry<ItemStack> entry = RecipeBookEntry.read(byteBuf, __ -> itemManager.wrap(FastNMS.INSTANCE.method$FriendlyByteBuf$readItem(friendlyBuf)));
|
||||
entry.applyClientboundData(item -> {
|
||||
Optional<Item<ItemStack>> remapped = itemManager.s2cNew(item, player);
|
||||
if (remapped.isEmpty()) {
|
||||
return item;
|
||||
}
|
||||
changed.set(true);
|
||||
return remapped.get();
|
||||
});
|
||||
return entry;
|
||||
});
|
||||
boolean replace = buf.readBoolean();
|
||||
event.setChanged(true);
|
||||
buf.clear();
|
||||
buf.writeVarInt(event.packetID());
|
||||
buf.writeCollection(entries, ((byteBuf, recipeBookEntry) -> recipeBookEntry.write(byteBuf)));
|
||||
buf.writeBoolean(replace);
|
||||
if (changed.booleanValue()) {
|
||||
event.setChanged(true);
|
||||
buf.clear();
|
||||
buf.writeVarInt(event.packetID());
|
||||
buf.writeCollection(entries, ((byteBuf, recipeBookEntry) -> recipeBookEntry.write(byteBuf,
|
||||
(__, item) -> FastNMS.INSTANCE.method$FriendlyByteBuf$writeItem(friendlyBuf, item.getItem()))));
|
||||
buf.writeBoolean(replace);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3028,19 +3042,33 @@ public class BukkitNetworkManager implements NetworkManager, Listener, PluginMes
|
||||
public void onPacketSend(NetWorkUser user, ByteBufPacketEvent event) {
|
||||
if (Config.disableItemOperations()) return;
|
||||
if (!VersionHelper.isOrAbove1_21_2()) return;
|
||||
MutableBoolean changed = new MutableBoolean(false);
|
||||
FriendlyByteBuf buf = event.getBuffer();
|
||||
Object friendlyBuf = FastNMS.INSTANCE.constructor$FriendlyByteBuf(buf.source());
|
||||
BukkitServerPlayer player = (BukkitServerPlayer) user;
|
||||
BukkitItemManager itemManager = BukkitItemManager.instance();
|
||||
int containerId = buf.readContainerId();
|
||||
RecipeDisplay display = RecipeDisplay.read(buf);
|
||||
display.applyClientboundData((BukkitServerPlayer) user);
|
||||
event.setChanged(true);
|
||||
buf.clear();
|
||||
buf.writeVarInt(event.packetID());
|
||||
buf.writeContainerId(containerId);
|
||||
display.write(buf);
|
||||
RecipeDisplay<ItemStack> display = RecipeDisplay.read(buf, __ -> itemManager.wrap(FastNMS.INSTANCE.method$FriendlyByteBuf$readItem(friendlyBuf)));
|
||||
display.applyClientboundData(item -> {
|
||||
Optional<Item<ItemStack>> remapped = itemManager.s2cNew(item, player);
|
||||
if (remapped.isEmpty()) {
|
||||
return item;
|
||||
}
|
||||
changed.set(true);
|
||||
return remapped.get();
|
||||
});
|
||||
|
||||
if (changed.booleanValue()) {
|
||||
event.setChanged(true);
|
||||
buf.clear();
|
||||
buf.writeVarInt(event.packetID());
|
||||
buf.writeContainerId(containerId);
|
||||
display.write(buf, (__, item) -> FastNMS.INSTANCE.method$FriendlyByteBuf$writeItem(friendlyBuf, item.getItem()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class UpdateRecipesListener implements ByteBufferPacketListener {
|
||||
public static class UpdateRecipesListener implements ByteBufferPacketListener {
|
||||
|
||||
@Override
|
||||
public void onPacketSend(NetWorkUser user, ByteBufPacketEvent event) {
|
||||
@@ -3054,7 +3082,7 @@ public class BukkitNetworkManager implements NetworkManager, Listener, PluginMes
|
||||
List<LegacyRecipeHolder<ItemStack>> holders = buf.readCollection(ArrayList::new, byteBuf -> {
|
||||
LegacyRecipeHolder<ItemStack> holder = LegacyRecipeHolder.read(byteBuf, __ -> itemManager.wrap(FastNMS.INSTANCE.method$FriendlyByteBuf$readItem(friendlyBuf)));
|
||||
holder.recipe().applyClientboundData(item -> {
|
||||
Optional<Item<ItemStack>> remapped = plugin.itemManager().s2cNew(item, player);
|
||||
Optional<Item<ItemStack>> remapped = itemManager.s2cNew(item, player);
|
||||
if (remapped.isEmpty()) {
|
||||
return item;
|
||||
}
|
||||
@@ -3068,8 +3096,8 @@ public class BukkitNetworkManager implements NetworkManager, Listener, PluginMes
|
||||
buf.clear();
|
||||
buf.writeVarInt(event.packetID());
|
||||
buf.writeCollection(holders, ((byteBuf, recipeHolder)
|
||||
-> recipeHolder.write(byteBuf, (__, item)
|
||||
-> FastNMS.INSTANCE.method$FriendlyByteBuf$writeItem(friendlyBuf, item.getItem()))));
|
||||
-> recipeHolder.write(byteBuf,
|
||||
(__, item) -> FastNMS.INSTANCE.method$FriendlyByteBuf$writeItem(friendlyBuf, item.getItem()))));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package net.momirealms.craftengine.core.item.recipe.network.modern;
|
||||
|
||||
import com.mojang.datafixers.util.Either;
|
||||
import net.momirealms.craftengine.core.entity.player.Player;
|
||||
import net.momirealms.craftengine.core.item.Item;
|
||||
import net.momirealms.craftengine.core.item.recipe.network.modern.display.RecipeDisplay;
|
||||
import net.momirealms.craftengine.core.util.FriendlyByteBuf;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
@@ -11,25 +11,27 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.OptionalInt;
|
||||
import java.util.function.Function;
|
||||
|
||||
public record RecipeBookDisplayEntry(RecipeDisplayId displayId, RecipeDisplay display, OptionalInt group, int category, Optional<List<Ingredient>> ingredients) {
|
||||
public record RecipeBookDisplayEntry<I>(RecipeDisplayId displayId, RecipeDisplay<I> display, OptionalInt group, int category, Optional<List<Ingredient>> ingredients) {
|
||||
|
||||
public static RecipeBookDisplayEntry read(FriendlyByteBuf buffer) {
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
public static <I> RecipeBookDisplayEntry<I> read(FriendlyByteBuf buffer, FriendlyByteBuf.Reader<Item<I>> reader) {
|
||||
RecipeDisplayId displayId = RecipeDisplayId.read(buffer);
|
||||
RecipeDisplay display = RecipeDisplay.read(buffer);
|
||||
RecipeDisplay display = RecipeDisplay.read(buffer, reader);
|
||||
OptionalInt group = buffer.readOptionalVarInt();
|
||||
int category = buffer.readVarInt(); // simplify the registry lookup since we don't care about the category
|
||||
Optional<List<Ingredient>> requirements = buffer.readOptional(buf -> buf.readCollection(ArrayList::new, byteBuf -> new Ingredient(byteBuf.readHolderSet()))); // simplify the registry lookup since we don't care about the ingredient ids
|
||||
return new RecipeBookDisplayEntry(displayId, display, group, category, requirements);
|
||||
}
|
||||
|
||||
public void applyClientboundData(Player player) {
|
||||
this.display.applyClientboundData(player);
|
||||
public void applyClientboundData(Function<Item<I>, Item<I>> function) {
|
||||
this.display.applyClientboundData(function);
|
||||
}
|
||||
|
||||
public void write(FriendlyByteBuf buffer) {
|
||||
public void write(FriendlyByteBuf buffer, FriendlyByteBuf.Writer<Item<I>> writer) {
|
||||
this.displayId.write(buffer);
|
||||
this.display.write(buffer);
|
||||
this.display.write(buffer, writer);
|
||||
buffer.writeOptionalVarInt(this.group);
|
||||
buffer.writeVarInt(this.category);
|
||||
buffer.writeOptional(this.ingredients, (buf, recipeIngredients) -> buf.writeCollection(recipeIngredients, (byteBuf, ingredient) -> byteBuf.writeHolderSet(ingredient.holderSet)));
|
||||
|
||||
@@ -1,22 +1,25 @@
|
||||
package net.momirealms.craftengine.core.item.recipe.network.modern;
|
||||
|
||||
import net.momirealms.craftengine.core.entity.player.Player;
|
||||
import net.momirealms.craftengine.core.item.Item;
|
||||
import net.momirealms.craftengine.core.util.FriendlyByteBuf;
|
||||
|
||||
public record RecipeBookEntry(RecipeBookDisplayEntry entry, byte flags) {
|
||||
import java.util.function.Function;
|
||||
|
||||
public void applyClientboundData(Player player) {
|
||||
this.entry.applyClientboundData(player);
|
||||
public record RecipeBookEntry<I>(RecipeBookDisplayEntry<I> entry, byte flags) {
|
||||
|
||||
public void applyClientboundData(Function<Item<I>, Item<I>> function) {
|
||||
this.entry.applyClientboundData(function);
|
||||
}
|
||||
|
||||
public static RecipeBookEntry read(FriendlyByteBuf buffer) {
|
||||
RecipeBookDisplayEntry displayEntry = RecipeBookDisplayEntry.read(buffer);
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
public static <I> RecipeBookEntry<I> read(FriendlyByteBuf buffer, FriendlyByteBuf.Reader<Item<I>> reader) {
|
||||
RecipeBookDisplayEntry displayEntry = RecipeBookDisplayEntry.read(buffer, reader);
|
||||
byte flags = buffer.readByte();
|
||||
return new RecipeBookEntry(displayEntry, flags);
|
||||
}
|
||||
|
||||
public void write(FriendlyByteBuf buffer) {
|
||||
this.entry.write(buffer);
|
||||
public void write(FriendlyByteBuf buffer, FriendlyByteBuf.Writer<Item<I>> writer) {
|
||||
this.entry.write(buffer, writer);
|
||||
buffer.writeByte(this.flags);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,41 +1,44 @@
|
||||
package net.momirealms.craftengine.core.item.recipe.network.modern.display;
|
||||
|
||||
import net.momirealms.craftengine.core.entity.player.Player;
|
||||
import net.momirealms.craftengine.core.item.Item;
|
||||
import net.momirealms.craftengine.core.item.recipe.network.modern.display.slot.SlotDisplay;
|
||||
import net.momirealms.craftengine.core.util.FriendlyByteBuf;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public record FurnaceRecipeDisplay(SlotDisplay ingredient, SlotDisplay fuel, SlotDisplay result, SlotDisplay craftingStation, int duration, float experience) implements RecipeDisplay {
|
||||
import java.util.function.Function;
|
||||
|
||||
public static FurnaceRecipeDisplay read(FriendlyByteBuf buffer) {
|
||||
SlotDisplay ingredient = SlotDisplay.read(buffer);
|
||||
SlotDisplay fuel = SlotDisplay.read(buffer);
|
||||
SlotDisplay result = SlotDisplay.read(buffer);
|
||||
SlotDisplay craftingStation = SlotDisplay.read(buffer);
|
||||
public record FurnaceRecipeDisplay<I>(SlotDisplay<I> ingredient, SlotDisplay<I> fuel, SlotDisplay<I> result, SlotDisplay<I> craftingStation, int duration, float experience)
|
||||
implements RecipeDisplay<I> {
|
||||
|
||||
public static <I> FurnaceRecipeDisplay<I> read(FriendlyByteBuf buffer, FriendlyByteBuf.Reader<Item<I>> reader) {
|
||||
SlotDisplay<I> ingredient = SlotDisplay.read(buffer, reader);
|
||||
SlotDisplay<I> fuel = SlotDisplay.read(buffer, reader);
|
||||
SlotDisplay<I> result = SlotDisplay.read(buffer, reader);
|
||||
SlotDisplay<I> craftingStation = SlotDisplay.read(buffer, reader);
|
||||
int duration = buffer.readVarInt();
|
||||
float experience = buffer.readFloat();
|
||||
return new FurnaceRecipeDisplay(ingredient, fuel, result, craftingStation, duration, experience);
|
||||
return new FurnaceRecipeDisplay<>(ingredient, fuel, result, craftingStation, duration, experience);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyClientboundData(Player player) {
|
||||
this.ingredient.applyClientboundData(player);
|
||||
this.fuel.applyClientboundData(player);
|
||||
this.result.applyClientboundData(player);
|
||||
this.craftingStation.applyClientboundData(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(FriendlyByteBuf buf) {
|
||||
public void write(FriendlyByteBuf buf, FriendlyByteBuf.Writer<Item<I>> writer) {
|
||||
buf.writeVarInt(2);
|
||||
this.ingredient.write(buf);
|
||||
this.fuel.write(buf);
|
||||
this.result.write(buf);
|
||||
this.craftingStation.write(buf);
|
||||
this.ingredient.write(buf, writer);
|
||||
this.fuel.write(buf, writer);
|
||||
this.result.write(buf, writer);
|
||||
this.craftingStation.write(buf, writer);
|
||||
buf.writeVarInt(this.duration);
|
||||
buf.writeFloat(this.experience);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyClientboundData(Function<Item<I>, Item<I>> function) {
|
||||
this.ingredient.applyClientboundData(function);
|
||||
this.fuel.applyClientboundData(function);
|
||||
this.result.applyClientboundData(function);
|
||||
this.craftingStation.applyClientboundData(function);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String toString() {
|
||||
return "FurnaceRecipeDisplay{" +
|
||||
|
||||
@@ -1,25 +1,27 @@
|
||||
package net.momirealms.craftengine.core.item.recipe.network.modern.display;
|
||||
|
||||
import net.momirealms.craftengine.core.entity.player.Player;
|
||||
import net.momirealms.craftengine.core.item.Item;
|
||||
import net.momirealms.craftengine.core.registry.BuiltInRegistries;
|
||||
import net.momirealms.craftengine.core.util.FriendlyByteBuf;
|
||||
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
|
||||
public interface RecipeDisplay {
|
||||
public interface RecipeDisplay<I> {
|
||||
|
||||
void write(FriendlyByteBuf buf);
|
||||
void write(FriendlyByteBuf buf, FriendlyByteBuf.Writer<Item<I>> writer);
|
||||
|
||||
void applyClientboundData(Player player);
|
||||
void applyClientboundData(Function<Item<I>, Item<I>> function);
|
||||
|
||||
static RecipeDisplay read(final FriendlyByteBuf buf) {
|
||||
return buf.readById(BuiltInRegistries.RECIPE_DISPLAY_TYPE).read(buf);
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
static <I> RecipeDisplay<I> read(final FriendlyByteBuf buf, FriendlyByteBuf.Reader<Item<I>> reader) {
|
||||
return buf.readById(BuiltInRegistries.RECIPE_DISPLAY_TYPE).read(buf, (FriendlyByteBuf.Reader) reader);
|
||||
}
|
||||
|
||||
record Type(Function<FriendlyByteBuf, RecipeDisplay> reader) {
|
||||
record Type<I>(BiFunction<FriendlyByteBuf, FriendlyByteBuf.Reader<Item<I>>, RecipeDisplay<I>> reader) {
|
||||
|
||||
public RecipeDisplay read(final FriendlyByteBuf buf) {
|
||||
return this.reader.apply(buf);
|
||||
public RecipeDisplay<I> read(final FriendlyByteBuf buf, FriendlyByteBuf.Reader<Item<I>> reader) {
|
||||
return this.reader.apply(buf, reader);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,16 @@
|
||||
package net.momirealms.craftengine.core.item.recipe.network.modern.display;
|
||||
|
||||
import net.momirealms.craftengine.core.item.Item;
|
||||
import net.momirealms.craftengine.core.registry.BuiltInRegistries;
|
||||
import net.momirealms.craftengine.core.registry.Registries;
|
||||
import net.momirealms.craftengine.core.registry.WritableRegistry;
|
||||
import net.momirealms.craftengine.core.util.FriendlyByteBuf;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import net.momirealms.craftengine.core.util.ResourceKey;
|
||||
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
public final class RecipeDisplayTypes {
|
||||
private RecipeDisplayTypes() {}
|
||||
|
||||
@@ -19,14 +24,20 @@ public final class RecipeDisplayTypes {
|
||||
}
|
||||
|
||||
static {
|
||||
register(CRAFTING_SHAPELESS, new RecipeDisplay.Type(ShapelessCraftingRecipeDisplay::read));
|
||||
register(CRAFTING_SHAPED, new RecipeDisplay.Type(ShapedCraftingRecipeDisplay::read));
|
||||
register(FURNACE, new RecipeDisplay.Type(FurnaceRecipeDisplay::read));
|
||||
register(STONECUTTER, new RecipeDisplay.Type(StonecutterRecipeDisplay::read));
|
||||
register(SMITHING, new RecipeDisplay.Type(SmithingRecipeDisplay::read));
|
||||
register(CRAFTING_SHAPELESS, new RecipeDisplay.Type(createReaderFunction(ShapelessCraftingRecipeDisplay::read)));
|
||||
register(CRAFTING_SHAPED, new RecipeDisplay.Type(createReaderFunction(ShapedCraftingRecipeDisplay::read)));
|
||||
register(FURNACE, new RecipeDisplay.Type(createReaderFunction(FurnaceRecipeDisplay::read)));
|
||||
register(STONECUTTER, new RecipeDisplay.Type(createReaderFunction(StonecutterRecipeDisplay::read)));
|
||||
register(SMITHING, new RecipeDisplay.Type(createReaderFunction(SmithingRecipeDisplay::read)));
|
||||
}
|
||||
|
||||
public static void register(Key key, RecipeDisplay.Type type) {
|
||||
((WritableRegistry<RecipeDisplay.Type>) BuiltInRegistries.RECIPE_DISPLAY_TYPE).register(ResourceKey.create(Registries.RECIPE_DISPLAY_TYPE.location(), key), type);
|
||||
private static <I> BiFunction<FriendlyByteBuf, FriendlyByteBuf.Reader<Item<I>>, RecipeDisplay<I>> createReaderFunction(
|
||||
BiFunction<FriendlyByteBuf, FriendlyByteBuf.Reader, RecipeDisplay> function) {
|
||||
return (BiFunction) function;
|
||||
}
|
||||
|
||||
public static <I> void register(Key key, RecipeDisplay.Type<I> type) {
|
||||
((WritableRegistry<RecipeDisplay.Type<?>>) BuiltInRegistries.RECIPE_DISPLAY_TYPE)
|
||||
.register(ResourceKey.create(Registries.RECIPE_DISPLAY_TYPE.location(), key), type);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,41 +1,42 @@
|
||||
package net.momirealms.craftengine.core.item.recipe.network.modern.display;
|
||||
|
||||
import net.momirealms.craftengine.core.entity.player.Player;
|
||||
import net.momirealms.craftengine.core.item.Item;
|
||||
import net.momirealms.craftengine.core.item.recipe.network.modern.display.slot.SlotDisplay;
|
||||
import net.momirealms.craftengine.core.util.FriendlyByteBuf;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
|
||||
public record ShapedCraftingRecipeDisplay(int width, int height, List<SlotDisplay> ingredients, SlotDisplay result, SlotDisplay craftingStation) implements RecipeDisplay {
|
||||
public record ShapedCraftingRecipeDisplay<I>(int width, int height, List<SlotDisplay<I>> ingredients, SlotDisplay<I> result, SlotDisplay<I> craftingStation) implements RecipeDisplay<I> {
|
||||
|
||||
public static ShapedCraftingRecipeDisplay read(FriendlyByteBuf buffer) {
|
||||
public static <I> ShapedCraftingRecipeDisplay<I> read(FriendlyByteBuf buffer, FriendlyByteBuf.Reader<Item<I>> reader) {
|
||||
int width = buffer.readVarInt();
|
||||
int height = buffer.readVarInt();
|
||||
List<SlotDisplay> ingredients = buffer.readCollection(ArrayList::new, SlotDisplay::read);
|
||||
SlotDisplay result = SlotDisplay.read(buffer);
|
||||
SlotDisplay craftingStation = SlotDisplay.read(buffer);
|
||||
return new ShapedCraftingRecipeDisplay(width, height, ingredients, result, craftingStation);
|
||||
List<SlotDisplay<I>> ingredients = buffer.readCollection(ArrayList::new, buf -> SlotDisplay.read(buf, reader));
|
||||
SlotDisplay<I> result = SlotDisplay.read(buffer, reader);
|
||||
SlotDisplay<I> craftingStation = SlotDisplay.read(buffer, reader);
|
||||
return new ShapedCraftingRecipeDisplay<>(width, height, ingredients, result, craftingStation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyClientboundData(Player player) {
|
||||
for (SlotDisplay ingredient : this.ingredients) {
|
||||
ingredient.applyClientboundData(player);
|
||||
}
|
||||
this.result.applyClientboundData(player);
|
||||
this.craftingStation.applyClientboundData(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(FriendlyByteBuf buf) {
|
||||
public void write(FriendlyByteBuf buf, FriendlyByteBuf.Writer<Item<I>> writer) {
|
||||
buf.writeVarInt(1);
|
||||
buf.writeVarInt(this.width);
|
||||
buf.writeVarInt(this.height);
|
||||
buf.writeCollection(this.ingredients, (byteBuf, slotDisplay) -> slotDisplay.write(buf));
|
||||
this.result.write(buf);
|
||||
this.craftingStation.write(buf);
|
||||
buf.writeCollection(this.ingredients, (byteBuf, slotDisplay) -> slotDisplay.write(buf, writer));
|
||||
this.result.write(buf, writer);
|
||||
this.craftingStation.write(buf, writer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyClientboundData(Function<Item<I>, Item<I>> function) {
|
||||
for (SlotDisplay<I> ingredient : this.ingredients) {
|
||||
ingredient.applyClientboundData(function);
|
||||
}
|
||||
this.result.applyClientboundData(function);
|
||||
this.craftingStation.applyClientboundData(function);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,37 +1,38 @@
|
||||
package net.momirealms.craftengine.core.item.recipe.network.modern.display;
|
||||
|
||||
import net.momirealms.craftengine.core.entity.player.Player;
|
||||
import net.momirealms.craftengine.core.item.Item;
|
||||
import net.momirealms.craftengine.core.item.recipe.network.modern.display.slot.SlotDisplay;
|
||||
import net.momirealms.craftengine.core.util.FriendlyByteBuf;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
|
||||
public record ShapelessCraftingRecipeDisplay(List<SlotDisplay> ingredients, SlotDisplay result, SlotDisplay craftingStation) implements RecipeDisplay {
|
||||
public record ShapelessCraftingRecipeDisplay<I>(List<SlotDisplay<I>> ingredients, SlotDisplay<I> result, SlotDisplay<I> craftingStation) implements RecipeDisplay<I> {
|
||||
|
||||
public static ShapelessCraftingRecipeDisplay read(FriendlyByteBuf buffer) {
|
||||
List<SlotDisplay> ingredients = buffer.readCollection(ArrayList::new, SlotDisplay::read);
|
||||
SlotDisplay result = SlotDisplay.read(buffer);
|
||||
SlotDisplay craftingStation = SlotDisplay.read(buffer);
|
||||
return new ShapelessCraftingRecipeDisplay(ingredients, result, craftingStation);
|
||||
public static <I> ShapelessCraftingRecipeDisplay<I> read(FriendlyByteBuf buffer, FriendlyByteBuf.Reader<Item<I>> reader) {
|
||||
List<SlotDisplay<I>> ingredients = buffer.readCollection(ArrayList::new, buf -> SlotDisplay.read(buf, reader));
|
||||
SlotDisplay<I> result = SlotDisplay.read(buffer, reader);
|
||||
SlotDisplay<I> craftingStation = SlotDisplay.read(buffer, reader);
|
||||
return new ShapelessCraftingRecipeDisplay<>(ingredients, result, craftingStation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyClientboundData(Player player) {
|
||||
for (SlotDisplay ingredient : ingredients) {
|
||||
ingredient.applyClientboundData(player);
|
||||
}
|
||||
this.result.applyClientboundData(player);
|
||||
this.craftingStation.applyClientboundData(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(FriendlyByteBuf buf) {
|
||||
public void write(FriendlyByteBuf buf, FriendlyByteBuf.Writer<Item<I>> writer) {
|
||||
buf.writeVarInt(0);
|
||||
buf.writeCollection(this.ingredients, (byteBuf, slotDisplay) -> slotDisplay.write(buf));
|
||||
this.result.write(buf);
|
||||
this.craftingStation.write(buf);
|
||||
buf.writeCollection(this.ingredients, (byteBuf, slotDisplay) -> slotDisplay.write(buf, writer));
|
||||
this.result.write(buf, writer);
|
||||
this.craftingStation.write(buf, writer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyClientboundData(Function<Item<I>, Item<I>> function) {
|
||||
for (SlotDisplay<I> ingredient : ingredients) {
|
||||
ingredient.applyClientboundData(function);
|
||||
}
|
||||
this.result.applyClientboundData(function);
|
||||
this.craftingStation.applyClientboundData(function);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,38 +1,40 @@
|
||||
package net.momirealms.craftengine.core.item.recipe.network.modern.display;
|
||||
|
||||
import net.momirealms.craftengine.core.entity.player.Player;
|
||||
import net.momirealms.craftengine.core.item.Item;
|
||||
import net.momirealms.craftengine.core.item.recipe.network.modern.display.slot.SlotDisplay;
|
||||
import net.momirealms.craftengine.core.util.FriendlyByteBuf;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public record SmithingRecipeDisplay(SlotDisplay template, SlotDisplay base, SlotDisplay addition, SlotDisplay result, SlotDisplay craftingStation) implements RecipeDisplay {
|
||||
import java.util.function.Function;
|
||||
|
||||
public static SmithingRecipeDisplay read(FriendlyByteBuf buffer) {
|
||||
SlotDisplay template = SlotDisplay.read(buffer);
|
||||
SlotDisplay base = SlotDisplay.read(buffer);
|
||||
SlotDisplay addition = SlotDisplay.read(buffer);
|
||||
SlotDisplay result = SlotDisplay.read(buffer);
|
||||
SlotDisplay craftingStation = SlotDisplay.read(buffer);
|
||||
return new SmithingRecipeDisplay(template, base, addition, result, craftingStation);
|
||||
public record SmithingRecipeDisplay<I>(SlotDisplay<I> template, SlotDisplay<I> base, SlotDisplay<I> addition, SlotDisplay<I> result, SlotDisplay<I> craftingStation) implements RecipeDisplay<I> {
|
||||
|
||||
public static <I> SmithingRecipeDisplay<I> read(FriendlyByteBuf buffer, FriendlyByteBuf.Reader<Item<I>> reader) {
|
||||
SlotDisplay<I> template = SlotDisplay.read(buffer, reader);
|
||||
SlotDisplay<I> base = SlotDisplay.read(buffer, reader);
|
||||
SlotDisplay<I> addition = SlotDisplay.read(buffer, reader);
|
||||
SlotDisplay<I> result = SlotDisplay.read(buffer, reader);
|
||||
SlotDisplay<I> craftingStation = SlotDisplay.read(buffer, reader);
|
||||
return new SmithingRecipeDisplay<>(template, base, addition, result, craftingStation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyClientboundData(Player player) {
|
||||
this.template.applyClientboundData(player);
|
||||
this.base.applyClientboundData(player);
|
||||
this.addition.applyClientboundData(player);
|
||||
this.result.applyClientboundData(player);
|
||||
this.craftingStation.applyClientboundData(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(FriendlyByteBuf buf) {
|
||||
public void write(FriendlyByteBuf buf, FriendlyByteBuf.Writer<Item<I>> writer) {
|
||||
buf.writeVarInt(4);
|
||||
this.template.write(buf);
|
||||
this.base.write(buf);
|
||||
this.addition.write(buf);
|
||||
this.result.write(buf);
|
||||
this.craftingStation.write(buf);
|
||||
this.template.write(buf, writer);
|
||||
this.base.write(buf, writer);
|
||||
this.addition.write(buf, writer);
|
||||
this.result.write(buf, writer);
|
||||
this.craftingStation.write(buf, writer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyClientboundData(Function<Item<I>, Item<I>> function) {
|
||||
this.template.applyClientboundData(function);
|
||||
this.base.applyClientboundData(function);
|
||||
this.addition.applyClientboundData(function);
|
||||
this.result.applyClientboundData(function);
|
||||
this.craftingStation.applyClientboundData(function);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,32 +1,34 @@
|
||||
package net.momirealms.craftengine.core.item.recipe.network.modern.display;
|
||||
|
||||
import net.momirealms.craftengine.core.entity.player.Player;
|
||||
import net.momirealms.craftengine.core.item.Item;
|
||||
import net.momirealms.craftengine.core.item.recipe.network.modern.display.slot.SlotDisplay;
|
||||
import net.momirealms.craftengine.core.util.FriendlyByteBuf;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public record StonecutterRecipeDisplay(SlotDisplay input, SlotDisplay result, SlotDisplay craftingStation) implements RecipeDisplay {
|
||||
import java.util.function.Function;
|
||||
|
||||
public static StonecutterRecipeDisplay read(FriendlyByteBuf buffer) {
|
||||
SlotDisplay input = SlotDisplay.read(buffer);
|
||||
SlotDisplay result = SlotDisplay.read(buffer);
|
||||
SlotDisplay craftingStation = SlotDisplay.read(buffer);
|
||||
return new StonecutterRecipeDisplay(input, result, craftingStation);
|
||||
public record StonecutterRecipeDisplay<I>(SlotDisplay<I> input, SlotDisplay<I> result, SlotDisplay<I> craftingStation) implements RecipeDisplay<I> {
|
||||
|
||||
public static <I> StonecutterRecipeDisplay<I> read(FriendlyByteBuf buffer, FriendlyByteBuf.Reader<Item<I>> reader) {
|
||||
SlotDisplay<I> input = SlotDisplay.read(buffer, reader);
|
||||
SlotDisplay<I> result = SlotDisplay.read(buffer, reader);
|
||||
SlotDisplay<I> craftingStation = SlotDisplay.read(buffer, reader);
|
||||
return new StonecutterRecipeDisplay<>(input, result, craftingStation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyClientboundData(Player player) {
|
||||
this.input.applyClientboundData(player);
|
||||
this.result.applyClientboundData(player);
|
||||
this.craftingStation.applyClientboundData(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(FriendlyByteBuf buf) {
|
||||
public void write(FriendlyByteBuf buf, FriendlyByteBuf.Writer<Item<I>> writer) {
|
||||
buf.writeVarInt(3);
|
||||
this.input.write(buf);
|
||||
this.result.write(buf);
|
||||
this.craftingStation.write(buf);
|
||||
this.input.write(buf, writer);
|
||||
this.result.write(buf, writer);
|
||||
this.craftingStation.write(buf, writer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyClientboundData(Function<Item<I>, Item<I>> function) {
|
||||
this.input.applyClientboundData(function);
|
||||
this.result.applyClientboundData(function);
|
||||
this.craftingStation.applyClientboundData(function);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,16 +1,18 @@
|
||||
package net.momirealms.craftengine.core.item.recipe.network.modern.display.slot;
|
||||
|
||||
import net.momirealms.craftengine.core.item.Item;
|
||||
import net.momirealms.craftengine.core.util.FriendlyByteBuf;
|
||||
|
||||
public class AnyFuelDisplay implements SlotDisplay {
|
||||
public static final AnyFuelDisplay INSTANCE = new AnyFuelDisplay();
|
||||
public class AnyFuelDisplay<I> implements SlotDisplay<I> {
|
||||
public static final AnyFuelDisplay<?> INSTANCE = new AnyFuelDisplay<>();
|
||||
|
||||
public static AnyFuelDisplay read(FriendlyByteBuf buf) {
|
||||
return INSTANCE;
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <I> AnyFuelDisplay<I> read(FriendlyByteBuf buf, FriendlyByteBuf.Reader<Item<I>> reader) {
|
||||
return (AnyFuelDisplay<I>) INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(FriendlyByteBuf buf) {
|
||||
public void write(FriendlyByteBuf buf, FriendlyByteBuf.Writer<Item<I>> writer) {
|
||||
buf.writeVarInt(1);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,37 +1,38 @@
|
||||
package net.momirealms.craftengine.core.item.recipe.network.modern.display.slot;
|
||||
|
||||
import net.momirealms.craftengine.core.entity.player.Player;
|
||||
import net.momirealms.craftengine.core.item.Item;
|
||||
import net.momirealms.craftengine.core.util.FriendlyByteBuf;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class CompositeSlotDisplay implements SlotDisplay {
|
||||
private final List<SlotDisplay> slots;
|
||||
public class CompositeSlotDisplay<I> implements SlotDisplay<I> {
|
||||
private final List<SlotDisplay<I>> slots;
|
||||
|
||||
public CompositeSlotDisplay(List<SlotDisplay> slots) {
|
||||
public CompositeSlotDisplay(List<SlotDisplay<I>> slots) {
|
||||
this.slots = slots;
|
||||
}
|
||||
|
||||
public static CompositeSlotDisplay read(FriendlyByteBuf buf) {
|
||||
List<SlotDisplay> slots = buf.readCollection(ArrayList::new, SlotDisplay::read);
|
||||
return new CompositeSlotDisplay(slots);
|
||||
public static <I> CompositeSlotDisplay<I> read(FriendlyByteBuf buf, FriendlyByteBuf.Reader<Item<I>> reader) {
|
||||
List<SlotDisplay<I>> slots = buf.readCollection(ArrayList::new, buffer -> SlotDisplay.read(buf, reader));
|
||||
return new CompositeSlotDisplay<>(slots);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyClientboundData(Player player) {
|
||||
for (SlotDisplay slotDisplay : this.slots) {
|
||||
slotDisplay.applyClientboundData(player);
|
||||
public void applyClientboundData(Function<Item<I>, Item<I>> function) {
|
||||
for (SlotDisplay<I> slotDisplay : this.slots) {
|
||||
slotDisplay.applyClientboundData(function);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(FriendlyByteBuf buf) {
|
||||
public void write(FriendlyByteBuf buf, FriendlyByteBuf.Writer<Item<I>> writer) {
|
||||
buf.writeVarInt(7);
|
||||
buf.writeCollection(this.slots, (byteBuf, slotDisplay) -> slotDisplay.write(buf));
|
||||
buf.writeCollection(this.slots, (byteBuf, slotDisplay) -> slotDisplay.write(buf, writer));
|
||||
}
|
||||
|
||||
public List<SlotDisplay> slots() {
|
||||
public List<SlotDisplay<I>> slots() {
|
||||
return this.slots;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,16 +1,18 @@
|
||||
package net.momirealms.craftengine.core.item.recipe.network.modern.display.slot;
|
||||
|
||||
import net.momirealms.craftengine.core.item.Item;
|
||||
import net.momirealms.craftengine.core.util.FriendlyByteBuf;
|
||||
|
||||
public class EmptySlotDisplay implements SlotDisplay {
|
||||
public static final EmptySlotDisplay INSTANCE = new EmptySlotDisplay();
|
||||
public class EmptySlotDisplay<I> implements SlotDisplay<I> {
|
||||
public static final EmptySlotDisplay<?> INSTANCE = new EmptySlotDisplay<>();
|
||||
|
||||
public static EmptySlotDisplay read(FriendlyByteBuf buf) {
|
||||
return INSTANCE;
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <I> EmptySlotDisplay<I> read(FriendlyByteBuf buf, FriendlyByteBuf.Reader<Item<I>> reader) {
|
||||
return (EmptySlotDisplay<I>) INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(FriendlyByteBuf buf) {
|
||||
public void write(FriendlyByteBuf buf, FriendlyByteBuf.Writer<Item<I>> writer) {
|
||||
buf.writeVarInt(0);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,21 +1,22 @@
|
||||
package net.momirealms.craftengine.core.item.recipe.network.modern.display.slot;
|
||||
|
||||
import net.momirealms.craftengine.core.item.Item;
|
||||
import net.momirealms.craftengine.core.util.FriendlyByteBuf;
|
||||
|
||||
public class ItemSlotDisplay implements SlotDisplay {
|
||||
public class ItemSlotDisplay<I> implements SlotDisplay<I> {
|
||||
private final int item;
|
||||
|
||||
public ItemSlotDisplay(int item) {
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
public static ItemSlotDisplay read(FriendlyByteBuf buf) {
|
||||
public static <I> ItemSlotDisplay<I> read(FriendlyByteBuf buf, FriendlyByteBuf.Reader<Item<I>> reader) {
|
||||
int item = buf.readVarInt();
|
||||
return new ItemSlotDisplay(item);
|
||||
return new ItemSlotDisplay<>(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(FriendlyByteBuf buf) {
|
||||
public void write(FriendlyByteBuf buf, FriendlyByteBuf.Writer<Item<I>> writer) {
|
||||
buf.writeVarInt(2);
|
||||
buf.writeVarInt(this.item);
|
||||
}
|
||||
|
||||
@@ -1,39 +1,35 @@
|
||||
package net.momirealms.craftengine.core.item.recipe.network.modern.display.slot;
|
||||
|
||||
import net.momirealms.craftengine.core.entity.player.Player;
|
||||
import net.momirealms.craftengine.core.item.Item;
|
||||
import net.momirealms.craftengine.core.plugin.CraftEngine;
|
||||
import net.momirealms.craftengine.core.util.FriendlyByteBuf;
|
||||
|
||||
public class ItemStackSlotDisplay implements SlotDisplay {
|
||||
private Item<Object> item;
|
||||
import java.util.function.Function;
|
||||
|
||||
public ItemStackSlotDisplay(Item<Object> item) {
|
||||
public class ItemStackSlotDisplay<I> implements SlotDisplay<I> {
|
||||
private Item<I> item;
|
||||
|
||||
public ItemStackSlotDisplay(Item<I> item) {
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
public static ItemStackSlotDisplay read(FriendlyByteBuf buf) {
|
||||
Item<Object> itemStack = CraftEngine.instance().itemManager().decode(buf);
|
||||
return new ItemStackSlotDisplay(itemStack);
|
||||
public static <I> ItemStackSlotDisplay<I> read(FriendlyByteBuf buf, FriendlyByteBuf.Reader<Item<I>> reader) {
|
||||
Item<I> itemStack = reader.apply(buf);
|
||||
return new ItemStackSlotDisplay<>(itemStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(FriendlyByteBuf buf) {
|
||||
public void write(FriendlyByteBuf buf, FriendlyByteBuf.Writer<Item<I>> writer) {
|
||||
buf.writeVarInt(3);
|
||||
CraftEngine.instance().itemManager().encode(buf, this.item);
|
||||
writer.accept(buf, item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyClientboundData(Player player) {
|
||||
this.item = CraftEngine.instance().itemManager().s2c(this.item, player);
|
||||
public void applyClientboundData(Function<Item<I>, Item<I>> function) {
|
||||
this.item = function.apply(this.item);
|
||||
}
|
||||
|
||||
public Item<?> item() {
|
||||
return this.item;
|
||||
}
|
||||
|
||||
public void setItem(Item<Object> item) {
|
||||
this.item = item;
|
||||
public Item<I> item() {
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,26 +1,28 @@
|
||||
package net.momirealms.craftengine.core.item.recipe.network.modern.display.slot;
|
||||
|
||||
import net.momirealms.craftengine.core.entity.player.Player;
|
||||
import net.momirealms.craftengine.core.item.Item;
|
||||
import net.momirealms.craftengine.core.registry.BuiltInRegistries;
|
||||
import net.momirealms.craftengine.core.util.FriendlyByteBuf;
|
||||
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
|
||||
public interface SlotDisplay {
|
||||
public interface SlotDisplay<I> {
|
||||
|
||||
void write(FriendlyByteBuf buf);
|
||||
void write(FriendlyByteBuf buf, FriendlyByteBuf.Writer<Item<I>> writer);
|
||||
|
||||
default void applyClientboundData(Player player) {
|
||||
default void applyClientboundData(Function<Item<I>, Item<I>> function) {
|
||||
}
|
||||
|
||||
static SlotDisplay read(FriendlyByteBuf buf) {
|
||||
return buf.readById(BuiltInRegistries.SLOT_DISPLAY_TYPE).read(buf);
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
static <I> SlotDisplay<I> read(FriendlyByteBuf buf, FriendlyByteBuf.Reader<Item<I>> reader) {
|
||||
return buf.readById(BuiltInRegistries.SLOT_DISPLAY_TYPE).read(buf, (FriendlyByteBuf.Reader) reader);
|
||||
}
|
||||
|
||||
record Type(Function<FriendlyByteBuf, SlotDisplay> reader) {
|
||||
record Type<I>(BiFunction<FriendlyByteBuf, FriendlyByteBuf.Reader<Item<I>>, SlotDisplay<I>> reader) {
|
||||
|
||||
public SlotDisplay read(final FriendlyByteBuf buf) {
|
||||
return this.reader.apply(buf);
|
||||
public SlotDisplay<I> read(final FriendlyByteBuf buf, FriendlyByteBuf.Reader<Item<I>> reader) {
|
||||
return this.reader.apply(buf, reader);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,16 @@
|
||||
package net.momirealms.craftengine.core.item.recipe.network.modern.display.slot;
|
||||
|
||||
import net.momirealms.craftengine.core.item.Item;
|
||||
import net.momirealms.craftengine.core.registry.BuiltInRegistries;
|
||||
import net.momirealms.craftengine.core.registry.Registries;
|
||||
import net.momirealms.craftengine.core.registry.WritableRegistry;
|
||||
import net.momirealms.craftengine.core.util.FriendlyByteBuf;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import net.momirealms.craftengine.core.util.ResourceKey;
|
||||
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
public final class SlotDisplayTypes {
|
||||
private SlotDisplayTypes() {}
|
||||
|
||||
@@ -22,18 +27,23 @@ public final class SlotDisplayTypes {
|
||||
}
|
||||
|
||||
static {
|
||||
register(EMPTY, new SlotDisplay.Type(EmptySlotDisplay::read));
|
||||
register(ANY_FUEL, new SlotDisplay.Type(AnyFuelDisplay::read));
|
||||
register(ITEM, new SlotDisplay.Type(ItemSlotDisplay::read));
|
||||
register(ITEM_STACK, new SlotDisplay.Type(ItemStackSlotDisplay::read));
|
||||
register(TAG, new SlotDisplay.Type(TagSlotDisplay::read));
|
||||
register(SMITHING_TRIM, new SlotDisplay.Type(SmithingTrimDemoSlotDisplay::read));
|
||||
register(WITH_REMAINDER, new SlotDisplay.Type(WithRemainderSlotDisplay::read));
|
||||
register(COMPOSITE, new SlotDisplay.Type(CompositeSlotDisplay::read));
|
||||
register(EMPTY, new SlotDisplay.Type(createReaderFunction(EmptySlotDisplay::read)));
|
||||
register(ANY_FUEL, new SlotDisplay.Type(createReaderFunction(AnyFuelDisplay::read)));
|
||||
register(ITEM, new SlotDisplay.Type(createReaderFunction(ItemSlotDisplay::read)));
|
||||
register(ITEM_STACK, new SlotDisplay.Type(createReaderFunction(ItemStackSlotDisplay::read)));
|
||||
register(TAG, new SlotDisplay.Type(createReaderFunction(TagSlotDisplay::read)));
|
||||
register(SMITHING_TRIM, new SlotDisplay.Type(createReaderFunction(SmithingTrimDemoSlotDisplay::read)));
|
||||
register(WITH_REMAINDER, new SlotDisplay.Type(createReaderFunction(WithRemainderSlotDisplay::read)));
|
||||
register(COMPOSITE, new SlotDisplay.Type(createReaderFunction(CompositeSlotDisplay::read)));
|
||||
}
|
||||
|
||||
public static void register(Key key, SlotDisplay.Type type) {
|
||||
((WritableRegistry<SlotDisplay.Type>) BuiltInRegistries.SLOT_DISPLAY_TYPE)
|
||||
private static <I> BiFunction<FriendlyByteBuf, FriendlyByteBuf.Reader<Item<I>>, SlotDisplay<I>> createReaderFunction(
|
||||
BiFunction<FriendlyByteBuf, FriendlyByteBuf.Reader, SlotDisplay> function) {
|
||||
return (BiFunction) function;
|
||||
}
|
||||
|
||||
public static <I> void register(Key key, SlotDisplay.Type<I> type) {
|
||||
((WritableRegistry<SlotDisplay.Type<?>>) BuiltInRegistries.SLOT_DISPLAY_TYPE)
|
||||
.register(ResourceKey.create(Registries.SLOT_DISPLAY_TYPE.location(), key), type);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,35 +2,36 @@ package net.momirealms.craftengine.core.item.recipe.network.modern.display.slot;
|
||||
|
||||
import com.mojang.datafixers.util.Either;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.momirealms.craftengine.core.item.Item;
|
||||
import net.momirealms.craftengine.core.util.AdventureHelper;
|
||||
import net.momirealms.craftengine.core.util.FriendlyByteBuf;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import net.momirealms.craftengine.core.util.VersionHelper;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class SmithingTrimDemoSlotDisplay implements SlotDisplay {
|
||||
private final SlotDisplay base;
|
||||
private final SlotDisplay material;
|
||||
public class SmithingTrimDemoSlotDisplay<I> implements SlotDisplay<I> {
|
||||
private final SlotDisplay<I> base;
|
||||
private final SlotDisplay<I> material;
|
||||
// 1.21.2-1.21.4
|
||||
private SlotDisplay trimPattern;
|
||||
private SlotDisplay<I> trimPattern;
|
||||
// 1.21.5
|
||||
private Either<Integer, TrimPattern> either;
|
||||
|
||||
public SmithingTrimDemoSlotDisplay(SlotDisplay base, SlotDisplay material, SlotDisplay trimPattern) {
|
||||
public SmithingTrimDemoSlotDisplay(SlotDisplay<I> base, SlotDisplay<I> material, SlotDisplay<I> trimPattern) {
|
||||
this.base = base;
|
||||
this.material = material;
|
||||
this.trimPattern = trimPattern;
|
||||
}
|
||||
|
||||
public SmithingTrimDemoSlotDisplay(SlotDisplay base, SlotDisplay material, Either<Integer, TrimPattern> either) {
|
||||
public SmithingTrimDemoSlotDisplay(SlotDisplay<I> base, SlotDisplay<I> material, Either<Integer, TrimPattern> either) {
|
||||
this.base = base;
|
||||
this.either = either;
|
||||
this.material = material;
|
||||
}
|
||||
|
||||
public static SmithingTrimDemoSlotDisplay read(FriendlyByteBuf buf) {
|
||||
SlotDisplay base = SlotDisplay.read(buf);
|
||||
SlotDisplay material = SlotDisplay.read(buf);
|
||||
public static <I> SmithingTrimDemoSlotDisplay<I> read(FriendlyByteBuf buf, FriendlyByteBuf.Reader<Item<I>> reader) {
|
||||
SlotDisplay<I> base = SlotDisplay.read(buf, reader);
|
||||
SlotDisplay<I> material = SlotDisplay.read(buf, reader);
|
||||
if (VersionHelper.isOrAbove1_21_5()) {
|
||||
Either<Integer, TrimPattern> either = buf.readHolder(byteBuf -> {
|
||||
Key assetId = buf.readKey();
|
||||
@@ -38,18 +39,18 @@ public class SmithingTrimDemoSlotDisplay implements SlotDisplay {
|
||||
boolean decal = buf.readBoolean();
|
||||
return new TrimPattern(assetId, component, decal);
|
||||
});
|
||||
return new SmithingTrimDemoSlotDisplay(base, material, either);
|
||||
return new SmithingTrimDemoSlotDisplay<>(base, material, either);
|
||||
} else {
|
||||
SlotDisplay trimPattern = SlotDisplay.read(buf);
|
||||
return new SmithingTrimDemoSlotDisplay(base, material, trimPattern);
|
||||
SlotDisplay<I> trimPattern = SlotDisplay.read(buf, reader);
|
||||
return new SmithingTrimDemoSlotDisplay<>(base, material, trimPattern);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(FriendlyByteBuf buf) {
|
||||
public void write(FriendlyByteBuf buf, FriendlyByteBuf.Writer<Item<I>> writer) {
|
||||
buf.writeVarInt(5);
|
||||
this.base.write(buf);
|
||||
this.material.write(buf);
|
||||
this.base.write(buf, writer);
|
||||
this.material.write(buf, writer);
|
||||
if (VersionHelper.isOrAbove1_21_5()) {
|
||||
buf.writeHolder(this.either, (byteBuf, pattern) -> {
|
||||
byteBuf.writeKey(pattern.assetId);
|
||||
@@ -57,7 +58,7 @@ public class SmithingTrimDemoSlotDisplay implements SlotDisplay {
|
||||
byteBuf.writeBoolean(pattern.decal);
|
||||
});
|
||||
} else {
|
||||
this.trimPattern.write(buf);
|
||||
this.trimPattern.write(buf, writer);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,21 +1,22 @@
|
||||
package net.momirealms.craftengine.core.item.recipe.network.modern.display.slot;
|
||||
|
||||
import net.momirealms.craftengine.core.item.Item;
|
||||
import net.momirealms.craftengine.core.util.FriendlyByteBuf;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
|
||||
public class TagSlotDisplay implements SlotDisplay {
|
||||
public class TagSlotDisplay<I> implements SlotDisplay<I> {
|
||||
private final Key tag;
|
||||
|
||||
public TagSlotDisplay(Key tag) {
|
||||
this.tag = tag;
|
||||
}
|
||||
|
||||
public static TagSlotDisplay read(FriendlyByteBuf buf) {
|
||||
return new TagSlotDisplay(buf.readKey());
|
||||
public static <I> TagSlotDisplay<I> read(FriendlyByteBuf buf, FriendlyByteBuf.Reader<Item<I>> reader) {
|
||||
return new TagSlotDisplay<>(buf.readKey());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(FriendlyByteBuf buf) {
|
||||
public void write(FriendlyByteBuf buf, FriendlyByteBuf.Writer<Item<I>> writer) {
|
||||
buf.writeVarInt(4);
|
||||
buf.writeKey(this.tag);
|
||||
}
|
||||
|
||||
@@ -1,27 +1,28 @@
|
||||
package net.momirealms.craftengine.core.item.recipe.network.modern.display.slot;
|
||||
|
||||
import net.momirealms.craftengine.core.item.Item;
|
||||
import net.momirealms.craftengine.core.util.FriendlyByteBuf;
|
||||
|
||||
public class WithRemainderSlotDisplay implements SlotDisplay {
|
||||
private final SlotDisplay input;
|
||||
private final SlotDisplay remainder;
|
||||
public class WithRemainderSlotDisplay<I> implements SlotDisplay<I> {
|
||||
private final SlotDisplay<I> input;
|
||||
private final SlotDisplay<I> remainder;
|
||||
|
||||
public WithRemainderSlotDisplay(SlotDisplay input, SlotDisplay remainder) {
|
||||
public WithRemainderSlotDisplay(SlotDisplay<I> input, SlotDisplay<I> remainder) {
|
||||
this.input = input;
|
||||
this.remainder = remainder;
|
||||
}
|
||||
|
||||
public static WithRemainderSlotDisplay read(FriendlyByteBuf buf) {
|
||||
SlotDisplay input = SlotDisplay.read(buf);
|
||||
SlotDisplay remainder = SlotDisplay.read(buf);
|
||||
return new WithRemainderSlotDisplay(input, remainder);
|
||||
public static <I> WithRemainderSlotDisplay<I> read(FriendlyByteBuf buf, FriendlyByteBuf.Reader<Item<I>> reader) {
|
||||
SlotDisplay<I> input = SlotDisplay.read(buf, reader);
|
||||
SlotDisplay<I> remainder = SlotDisplay.read(buf, reader);
|
||||
return new WithRemainderSlotDisplay<>(input, remainder);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(FriendlyByteBuf buf) {
|
||||
public void write(FriendlyByteBuf buf, FriendlyByteBuf.Writer<Item<I>> writer) {
|
||||
buf.writeVarInt(6);
|
||||
this.input.write(buf);
|
||||
this.remainder.write(buf);
|
||||
this.input.write(buf, writer);
|
||||
this.remainder.write(buf, writer);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -81,8 +81,8 @@ public class BuiltInRegistries {
|
||||
public static final Registry<ConditionFactory<PlayerOptionalContext>> EVENT_CONDITION_FACTORY = createConstantBoundRegistry(Registries.EVENT_CONDITION_FACTORY, 128);
|
||||
public static final Registry<PlayerSelectorFactory<?>> PLAYER_SELECTOR_FACTORY = createConstantBoundRegistry(Registries.PLAYER_SELECTOR_FACTORY, 16);
|
||||
public static final Registry<EquipmentFactory> EQUIPMENT_FACTORY = createConstantBoundRegistry(Registries.EQUIPMENT_FACTORY, 8);
|
||||
public static final Registry<SlotDisplay.Type> SLOT_DISPLAY_TYPE = createConstantBoundRegistry(Registries.SLOT_DISPLAY_TYPE, 16);
|
||||
public static final Registry<RecipeDisplay.Type> RECIPE_DISPLAY_TYPE = createConstantBoundRegistry(Registries.RECIPE_DISPLAY_TYPE, 16);
|
||||
public static final Registry<SlotDisplay.Type<?>> SLOT_DISPLAY_TYPE = createConstantBoundRegistry(Registries.SLOT_DISPLAY_TYPE, 16);
|
||||
public static final Registry<RecipeDisplay.Type<?>> RECIPE_DISPLAY_TYPE = createConstantBoundRegistry(Registries.RECIPE_DISPLAY_TYPE, 16);
|
||||
public static final Registry<LegacyRecipe.Type<?>> LEGACY_RECIPE_TYPE = createConstantBoundRegistry(Registries.LEGACY_RECIPE_TYPE, 16);
|
||||
public static final Registry<PostProcessor.Type<?>> RECIPE_POST_PROCESSOR_TYPE = createConstantBoundRegistry(Registries.RECIPE_POST_PROCESSOR_TYPE, 16);
|
||||
public static final Registry<ItemUpdaterType<?>> ITEM_UPDATER_TYPE = createConstantBoundRegistry(Registries.ITEM_UPDATER_TYPE, 16);
|
||||
|
||||
@@ -83,8 +83,8 @@ public class Registries {
|
||||
public static final ResourceKey<Registry<ConditionFactory<PlayerOptionalContext>>> EVENT_CONDITION_FACTORY = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("event_condition_factory"));
|
||||
public static final ResourceKey<Registry<PlayerSelectorFactory<?>>> PLAYER_SELECTOR_FACTORY = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("player_selector_factory"));
|
||||
public static final ResourceKey<Registry<EquipmentFactory>> EQUIPMENT_FACTORY = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("equipment_factory"));
|
||||
public static final ResourceKey<Registry<SlotDisplay.Type>> SLOT_DISPLAY_TYPE = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("slot_display_type"));
|
||||
public static final ResourceKey<Registry<RecipeDisplay.Type>> RECIPE_DISPLAY_TYPE = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("recipe_display_type"));
|
||||
public static final ResourceKey<Registry<SlotDisplay.Type<?>>> SLOT_DISPLAY_TYPE = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("slot_display_type"));
|
||||
public static final ResourceKey<Registry<RecipeDisplay.Type<?>>> RECIPE_DISPLAY_TYPE = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("recipe_display_type"));
|
||||
public static final ResourceKey<Registry<LegacyRecipe.Type<?>>> LEGACY_RECIPE_TYPE = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("legacy_recipe_type"));
|
||||
public static final ResourceKey<Registry<PostProcessor.Type<?>>> RECIPE_POST_PROCESSOR_TYPE = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("recipe_post_processor_type"));
|
||||
public static final ResourceKey<Registry<ItemUpdaterType<?>>> ITEM_UPDATER_TYPE = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("item_updater_type"));
|
||||
|
||||
Reference in New Issue
Block a user