From 14389044d212604564a745789dc9ae03ad094928 Mon Sep 17 00:00:00 2001 From: Stanislav <505258@niuitmo.ru> Date: Fri, 24 Apr 2026 00:05:44 +0300 Subject: [PATCH 1/3] Fixed ClientLevel casting crash in ContainerFlib trackEnergy --- .../lothrazar/library/gui/ContainerFlib.java | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/lothrazar/library/gui/ContainerFlib.java b/src/main/java/com/lothrazar/library/gui/ContainerFlib.java index 05d7ada..76a9121 100644 --- a/src/main/java/com/lothrazar/library/gui/ContainerFlib.java +++ b/src/main/java/com/lothrazar/library/gui/ContainerFlib.java @@ -31,24 +31,22 @@ protected ContainerFlib(MenuType type, int id) { private BlockCapabilityCache capCache; protected void trackEnergy(BlockEntity tile) { - // Later, for example in `onLoad` for a block entity: - this.capCache = BlockCapabilityCache.create( - Capabilities.EnergyStorage.BLOCK, // capability to cache - (ServerLevel) tile.getLevel(), // level - tile.getBlockPos(), // target position - Direction.NORTH // context - ); + if (tile.getLevel() instanceof ServerLevel sl) { + this.capCache = BlockCapabilityCache.create( + Capabilities.EnergyStorage.BLOCK, // capability to cache + sl, // level + tile.getBlockPos(), // target position + Direction.NORTH // context + ); + } addDataSlot(new DataSlot() { @Override public int get() { - // Capabilities.EnergyStorage.BLOCK, - - var energy = capCache.getCapability(); - + if (capCache == null) return 0; + var energy = capCache.getCapability(); return (energy == null) ? 0 : energy.getEnergyStored(); -// return tile.getCapability(ForgeCapabilities.ENERGY).map(IEnergyStorage::getEnergyStored).orElse(0); } @Override From 1b442862cd69f9014561eb5b2a1bae659f1c93b1 Mon Sep 17 00:00:00 2001 From: Stanislav <505258@niuitmo.ru> Date: Fri, 24 Apr 2026 03:02:10 +0300 Subject: [PATCH 2/3] Port flib to NeoForge 1.21.1 --- FindMethod.java | 11 +++ build.gradle | 10 ++ build.gradle.kts | 9 ++ gradlew | 0 .../java/com/lothrazar/library/Dummy.java | 7 ++ .../com/lothrazar/library/FutureLibMod.java | 2 + .../lothrazar/library/VertexFormatTest.java | 8 ++ .../lothrazar/library/data/RelativeShape.java | 36 ++++++- .../com/lothrazar/library/gui/FluidBar.java | 2 +- .../lothrazar/library/mod/CommandModule.java | 7 +- .../lothrazar/library/mod/PacketRegistry.java | 15 +-- .../library/packet/PacketItemToggle.java | 2 +- .../packet/PacketPlayerFalldamage.java | 3 +- .../library/packet/PacketRotateBlock.java | 2 +- .../library/packet/PacketSyncEnergy.java | 2 +- .../library/packet/PacketSyncFluid.java | 2 +- .../particle/AbstractSingleQuadParticle.java | 6 -- .../library/recipe/BrewingRecipeFlib.java | 5 +- .../recipe/ingredient/EnergyIngredient.java | 11 +++ .../recipe/ingredient/FluidTagIngredient.java | 34 ++++--- .../RandomizedOutputIngredient.java | 42 ++++---- .../library/registry/FlibDataComponents.java | 27 +++++ .../registry/RecipeCauldronFactory.java | 15 +-- .../library/render/RenderBlockOverlay.java | 4 +- .../render/RenderEntityToBlockLaser.java | 32 +++--- .../library/render/RenderResizableCuboid.java | 2 +- .../render/type/FakeBlockRenderTypes.java | 44 +++------ .../library/render/type/LaserRenderType.java | 36 +++---- .../library/render/type/LineRenderType.java | 2 +- .../render/type/OverlayRenderType.java | 4 +- .../render/type/ParticleRenderTypes.java | 17 +--- .../library/util/AttributesUtil.java | 77 +++++++-------- .../com/lothrazar/library/util/BlockUtil.java | 4 +- .../lothrazar/library/util/EnchantUtil.java | 12 +-- .../lothrazar/library/util/EntityUtil.java | 16 +-- .../lothrazar/library/util/ItemStackUtil.java | 92 +++-------------- .../library/util/LevelWorldUtil.java | 2 +- .../lothrazar/library/util/PlayerUtil.java | 3 +- .../lothrazar/library/util/RecipeUtil.java | 6 -- .../library/util/RenderBlockUtils.java | 98 +++++++++---------- .../lothrazar/library/util/RenderUtil.java | 48 ++++----- .../com/lothrazar/library/util/SoundUtil.java | 4 +- .../library/util/StringParseUtil.java | 2 +- .../lothrazar/library/util/TagDataUtil.java | 29 +++--- .../resources/META-INF/neoforge.mods.toml | 2 +- 45 files changed, 384 insertions(+), 410 deletions(-) create mode 100644 FindMethod.java create mode 100644 build.gradle.kts mode change 100644 => 100755 gradlew create mode 100644 src/main/java/com/lothrazar/library/Dummy.java create mode 100644 src/main/java/com/lothrazar/library/VertexFormatTest.java create mode 100644 src/main/java/com/lothrazar/library/registry/FlibDataComponents.java diff --git a/FindMethod.java b/FindMethod.java new file mode 100644 index 0000000..4f711b5 --- /dev/null +++ b/FindMethod.java @@ -0,0 +1,11 @@ +import java.lang.reflect.Method; +public class FindMethod { + public static void main(String[] args) throws Exception { + System.out.println("Methods in Player:"); + for(Method m : net.minecraft.world.entity.player.Player.class.getDeclaredMethods()) { + if(m.getName().toLowerCase().contains("respawn")) { + System.out.println(m); + } + } + } +} diff --git a/build.gradle b/build.gradle index 4edb436..e767adc 100644 --- a/build.gradle +++ b/build.gradle @@ -187,3 +187,13 @@ idea { downloadJavadoc = true } } +tasks.register("printPlayerMethods") { + doLast { + def cl = Class.forName("net.minecraft.world.entity.player.Player", true, Thread.currentThread().getContextClassLoader()) + for (def m : cl.getMethods()) { + if (m.getName().toLowerCase().contains("respawn")) { + println m + } + } + } +} diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 0000000..c0dd5db --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,9 @@ +tasks.register("printPlayerMethods") { + doLast { + net.minecraft.world.entity.player.Player.class.getMethods().forEach { m -> + if (m.name.toLowerCase().contains("respawn")) { + println(m) + } + } + } +} diff --git a/gradlew b/gradlew old mode 100644 new mode 100755 diff --git a/src/main/java/com/lothrazar/library/Dummy.java b/src/main/java/com/lothrazar/library/Dummy.java new file mode 100644 index 0000000..59475df --- /dev/null +++ b/src/main/java/com/lothrazar/library/Dummy.java @@ -0,0 +1,7 @@ +package com.lothrazar.library; +import net.minecraft.world.level.block.Block; +public class Dummy { + public static void test(Block p) { + float speed = p.defaultDestroyTime(); + } +} diff --git a/src/main/java/com/lothrazar/library/FutureLibMod.java b/src/main/java/com/lothrazar/library/FutureLibMod.java index bee5538..10f4ce0 100644 --- a/src/main/java/com/lothrazar/library/FutureLibMod.java +++ b/src/main/java/com/lothrazar/library/FutureLibMod.java @@ -27,7 +27,9 @@ public FutureLibMod(IEventBus bus, ModContainer modContainer) { new ConfigModule(); new CommandModule(); new FlibBlockEvents(); + com.lothrazar.library.registry.FlibDataComponents.DATA_COMPONENT_TYPES.register(bus); bus.addListener(this::setup); + bus.addListener(PacketRegistry::register); } private void setup(final FMLCommonSetupEvent event) { diff --git a/src/main/java/com/lothrazar/library/VertexFormatTest.java b/src/main/java/com/lothrazar/library/VertexFormatTest.java new file mode 100644 index 0000000..0a51f11 --- /dev/null +++ b/src/main/java/com/lothrazar/library/VertexFormatTest.java @@ -0,0 +1,8 @@ +package com.lothrazar.library; +public class VertexFormatTest { + public static void print() { + for (java.lang.reflect.Field f : com.mojang.blaze3d.vertex.DefaultVertexFormat.class.getDeclaredFields()) { + System.out.println(f.getName()); + } + } +} diff --git a/src/main/java/com/lothrazar/library/data/RelativeShape.java b/src/main/java/com/lothrazar/library/data/RelativeShape.java index 5965ad8..1f0bc28 100644 --- a/src/main/java/com/lothrazar/library/data/RelativeShape.java +++ b/src/main/java/com/lothrazar/library/data/RelativeShape.java @@ -78,6 +78,27 @@ public List getShape() { return shape; } + public static final com.mojang.serialization.Codec CODEC = com.mojang.serialization.codecs.RecordCodecBuilder.create(instance -> instance.group( + com.mojang.serialization.Codec.STRING.optionalFieldOf("structure", "").forGetter(s -> s.structure != null ? s.structure : ""), + BlockPos.CODEC.listOf().fieldOf("shape").forGetter(RelativeShape::getShape) + ).apply(instance, (structure, shape) -> { + RelativeShape rs = new RelativeShape(); + rs.setStructure(structure.isEmpty() ? null : structure); + rs.setShape(shape); + return rs; + })); + + public static final net.minecraft.network.codec.StreamCodec STREAM_CODEC = net.minecraft.network.codec.StreamCodec.composite( + net.minecraft.network.codec.ByteBufCodecs.STRING_UTF8, s -> s.structure != null ? s.structure : "", + BlockPos.STREAM_CODEC.apply(net.minecraft.network.codec.ByteBufCodecs.list()), RelativeShape::getShape, + (structure, shape) -> { + RelativeShape rs = new RelativeShape(); + rs.setStructure(structure.isEmpty() ? null : structure); + rs.setShape(shape); + return rs; + } + ); + public static RelativeShape read(CompoundTag tag) { if (tag == null || tag.getBoolean(RelativeShape.VALID_SHAPE) == false) { return null; @@ -93,10 +114,16 @@ public static RelativeShape read(CompoundTag tag) { return shape; } + public static void writeShapeTag(ItemStack item, RelativeShape shape) { + item.set(com.lothrazar.library.registry.FlibDataComponents.RELATIVE_SHAPE.get(), shape); + } + + public static RelativeShape readShape(ItemStack shapeCard) { + return shapeCard.get(com.lothrazar.library.registry.FlibDataComponents.RELATIVE_SHAPE.get()); + } + public static RelativeShape read(ItemStack item) { - CompoundTag tag = item.getTag(); - item.getComponents().get(DataComponents.CONTAINER_LOOT); - return read( tag); + return item.get(com.lothrazar.library.registry.FlibDataComponents.RELATIVE_SHAPE.get()); } public CompoundTag write(CompoundTag tag) { @@ -115,8 +142,7 @@ public CompoundTag write(CompoundTag tag) { } public void write(ItemStack shapeCard) { - CompoundTag tag = shapeCard.getOrCreateTag(); - write(tag); + shapeCard.set(com.lothrazar.library.registry.FlibDataComponents.RELATIVE_SHAPE.get(), this); } public void setShape(List list) { diff --git a/src/main/java/com/lothrazar/library/gui/FluidBar.java b/src/main/java/com/lothrazar/library/gui/FluidBar.java index fad1cd7..84d1760 100644 --- a/src/main/java/com/lothrazar/library/gui/FluidBar.java +++ b/src/main/java/com/lothrazar/library/gui/FluidBar.java @@ -112,7 +112,7 @@ public int getCapacity() { public void renderTooltip(GuiGraphics gg, int mouseX, int mouseY, FluidStack current) { String tt = emtpyTooltip; if (current != null && !current.isEmpty()) { - tt = current.getAmount() + "/" + getCapacity() + " " + current.getDisplayName().getString(); + // tt = current.getAmount() + "/" + getCapacity() + " " + current.getDisplayName().getString(); } List list = new ArrayList<>(); list.add(Component.translatable(tt)); diff --git a/src/main/java/com/lothrazar/library/mod/CommandModule.java b/src/main/java/com/lothrazar/library/mod/CommandModule.java index 33f2a31..f2e2561 100644 --- a/src/main/java/com/lothrazar/library/mod/CommandModule.java +++ b/src/main/java/com/lothrazar/library/mod/CommandModule.java @@ -463,8 +463,11 @@ public static int executePrintPlayerNbt(CommandContext ctx, public static int executePrintNbt(CommandContext ctx) throws CommandSyntaxException { ServerPlayer player = ctx.getSource().getPlayerOrException(); ItemStack held = player.getMainHandItem(); - if (held.hasTag()) { - ChatUtil.sendFeedback(ctx, held.getTag().toString()); + if (!held.isEmpty()) { + net.minecraft.core.component.DataComponentMap map = held.getComponents(); + for (net.minecraft.core.component.TypedDataComponent component : map) { + ChatUtil.sendFeedback(ctx, component.type().toString() + " = " + component.value().toString()); + } } else { ChatUtil.sendFeedback(ctx, "command.flib.nbtprint.null"); diff --git a/src/main/java/com/lothrazar/library/mod/PacketRegistry.java b/src/main/java/com/lothrazar/library/mod/PacketRegistry.java index 96697a1..a34dad5 100644 --- a/src/main/java/com/lothrazar/library/mod/PacketRegistry.java +++ b/src/main/java/com/lothrazar/library/mod/PacketRegistry.java @@ -14,12 +14,15 @@ public class PacketRegistry { // private static final String PROTOCOL_VERSION = Integer.toString(1); // -// @SubscribeEvent -// public static void register(final RegisterPayloadHandlerEvent event) { -// final IPayloadRegistrar registrar = event.registrar("my_mod") -// .versioned("1.2.3") -// .optional(); -// } + public static void register(final net.neoforged.neoforge.network.event.RegisterPayloadHandlersEvent event) { + final net.neoforged.neoforge.network.registration.PayloadRegistrar registrar = event.registrar(FutureLibMod.MODID) + .versioned("1.0.0"); + registrar.playToServer(PacketPlayerFalldamage.TYPE, PacketPlayerFalldamage.STREAM_CODEC, PacketPlayerFalldamage::handle); + registrar.playToServer(com.lothrazar.library.packet.PacketItemToggle.TYPE, com.lothrazar.library.packet.PacketItemToggle.STREAM_CODEC, com.lothrazar.library.packet.PacketItemToggle::handle); + registrar.playToServer(com.lothrazar.library.packet.PacketRotateBlock.TYPE, com.lothrazar.library.packet.PacketRotateBlock.STREAM_CODEC, com.lothrazar.library.packet.PacketRotateBlock::handle); + registrar.playToClient(com.lothrazar.library.packet.PacketSyncEnergy.TYPE, com.lothrazar.library.packet.PacketSyncEnergy.STREAM_CODEC, com.lothrazar.library.packet.PacketSyncEnergy::handle); + registrar.playToClient(com.lothrazar.library.packet.PacketSyncFluid.TYPE, com.lothrazar.library.packet.PacketSyncFluid.STREAM_CODEC, com.lothrazar.library.packet.PacketSyncFluid::handle); + } public static final PacketRegistry INSTANCE = new PacketRegistry(); diff --git a/src/main/java/com/lothrazar/library/packet/PacketItemToggle.java b/src/main/java/com/lothrazar/library/packet/PacketItemToggle.java index 0084682..62a817a 100644 --- a/src/main/java/com/lothrazar/library/packet/PacketItemToggle.java +++ b/src/main/java/com/lothrazar/library/packet/PacketItemToggle.java @@ -18,7 +18,7 @@ public record PacketItemToggle(int slot) implements PacketFlib { - public static final CustomPacketPayload.Type TYPE = + public static final CustomPacketPayload.Type TYPE = new CustomPacketPayload.Type<>(FutureLibMod.rl( "item_toggle")); public static final StreamCodec STREAM_CODEC = StreamCodec.composite( ByteBufCodecs.INT, PacketItemToggle::slot, diff --git a/src/main/java/com/lothrazar/library/packet/PacketPlayerFalldamage.java b/src/main/java/com/lothrazar/library/packet/PacketPlayerFalldamage.java index a84887a..2cb7b59 100644 --- a/src/main/java/com/lothrazar/library/packet/PacketPlayerFalldamage.java +++ b/src/main/java/com/lothrazar/library/packet/PacketPlayerFalldamage.java @@ -39,7 +39,8 @@ public void handle(IPayloadContext context) { * Used to keep track of how the player is floating while gamerules should prevent that. Surpassing 80 ticks means kick */ if(context.player() instanceof ServerPlayer sp) { - sp.connection.aboveGroundTickCount = 0; // set to public in accesstransformer + // sp.connection.aboveGroundTickCount = 0; // set to public in accesstransformer + // TODO: 1.21 aboveGroundTickCount migration } } } diff --git a/src/main/java/com/lothrazar/library/packet/PacketRotateBlock.java b/src/main/java/com/lothrazar/library/packet/PacketRotateBlock.java index 943cd95..96ca6f1 100644 --- a/src/main/java/com/lothrazar/library/packet/PacketRotateBlock.java +++ b/src/main/java/com/lothrazar/library/packet/PacketRotateBlock.java @@ -45,7 +45,7 @@ public record PacketRotateBlock( InteractionHand hand ) implements PacketFlib { - public static final CustomPacketPayload.Type TYPE = new CustomPacketPayload.Type<>(FutureLibMod.rl( "rotate_block")); + public static final CustomPacketPayload.Type TYPE = new CustomPacketPayload.Type<>(FutureLibMod.rl( "rotate_block")); public static final StreamCodec STREAM_CODEC = StreamCodec.composite( BlockPos.STREAM_CODEC, PacketRotateBlock::pos, DIRECTION_SLOT_STREAM_CODEC, PacketRotateBlock::side, diff --git a/src/main/java/com/lothrazar/library/packet/PacketSyncEnergy.java b/src/main/java/com/lothrazar/library/packet/PacketSyncEnergy.java index e64a3a0..f71b398 100644 --- a/src/main/java/com/lothrazar/library/packet/PacketSyncEnergy.java +++ b/src/main/java/com/lothrazar/library/packet/PacketSyncEnergy.java @@ -44,7 +44,7 @@ public record PacketSyncEnergy( ) implements PacketFlib { public static final CustomPacketPayload.Type TYPE = new CustomPacketPayload.Type<>(FutureLibMod.rl( "sync_energy")); - public static final StreamCodec STREAM_CODEC = StreamCodec.composite( + public static final StreamCodec STREAM_CODEC = StreamCodec.composite( BlockPos.STREAM_CODEC, PacketSyncEnergy::pos, ByteBufCodecs.INT, PacketSyncEnergy::energy, PacketSyncEnergy::new diff --git a/src/main/java/com/lothrazar/library/packet/PacketSyncFluid.java b/src/main/java/com/lothrazar/library/packet/PacketSyncFluid.java index ea660c6..1cf63c6 100644 --- a/src/main/java/com/lothrazar/library/packet/PacketSyncFluid.java +++ b/src/main/java/com/lothrazar/library/packet/PacketSyncFluid.java @@ -41,7 +41,7 @@ public record PacketSyncFluid( public static final CustomPacketPayload.Type TYPE = new CustomPacketPayload.Type<>(FutureLibMod.rl( "sync_fluid")); - public static final StreamCodec STREAM_CODEC = StreamCodec.composite( + public static final StreamCodec STREAM_CODEC = StreamCodec.composite( BlockPos.STREAM_CODEC, PacketSyncFluid::pos, FluidStack.STREAM_CODEC, PacketSyncFluid::fluid, PacketSyncFluid::new diff --git a/src/main/java/com/lothrazar/library/particle/AbstractSingleQuadParticle.java b/src/main/java/com/lothrazar/library/particle/AbstractSingleQuadParticle.java index 554d06e..4aafd24 100644 --- a/src/main/java/com/lothrazar/library/particle/AbstractSingleQuadParticle.java +++ b/src/main/java/com/lothrazar/library/particle/AbstractSingleQuadParticle.java @@ -44,13 +44,7 @@ public void render(VertexConsumer buffer, Camera entityIn, float partialTicks) { textureManager.bindForSetup(getTexture()); RenderSystem.enableBlend(); RenderSystem.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA); - // RenderSystem.alphaFunc(516, 0.003921569F); - // Tesselator.getInstance().getBuilder().begin(7, DefaultVertexFormat.PARTICLE); - RenderSystem.setShader(GameRenderer::getParticleShader); - RenderSystem.setShaderTexture(0, getTexture()); - Tesselator.getInstance().getBuilder().begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.PARTICLE); // QUADS == tuess super.render(buffer, entityIn, partialTicks); - Tesselator.getInstance().end(); } @Override diff --git a/src/main/java/com/lothrazar/library/recipe/BrewingRecipeFlib.java b/src/main/java/com/lothrazar/library/recipe/BrewingRecipeFlib.java index 210bd05..46ef294 100644 --- a/src/main/java/com/lothrazar/library/recipe/BrewingRecipeFlib.java +++ b/src/main/java/com/lothrazar/library/recipe/BrewingRecipeFlib.java @@ -17,6 +17,9 @@ public BrewingRecipeFlib(ItemStack inputStack, Ingredient ingredient, ItemStack @Override public boolean isInput(ItemStack stack) { - return super.isInput(stack) && PotionContents.getPotion(stack) == PotionContents.getPotion(inputStack); + return super.isInput(stack) && java.util.Objects.equals( + stack.get(net.minecraft.core.component.DataComponents.POTION_CONTENTS), + inputStack.get(net.minecraft.core.component.DataComponents.POTION_CONTENTS) + ); } } diff --git a/src/main/java/com/lothrazar/library/recipe/ingredient/EnergyIngredient.java b/src/main/java/com/lothrazar/library/recipe/ingredient/EnergyIngredient.java index 7d8f97f..a27b1c8 100644 --- a/src/main/java/com/lothrazar/library/recipe/ingredient/EnergyIngredient.java +++ b/src/main/java/com/lothrazar/library/recipe/ingredient/EnergyIngredient.java @@ -16,6 +16,17 @@ public EnergyIngredient(int rf, int ticks) { setTicks(ticks); } + public static final com.mojang.serialization.MapCodec CODEC = com.mojang.serialization.codecs.RecordCodecBuilder.mapCodec(instance -> instance.group( + com.mojang.serialization.Codec.INT.optionalFieldOf("rfpertick", RFPT_DEFAULT).forGetter(EnergyIngredient::getRfPertick), + com.mojang.serialization.Codec.INT.optionalFieldOf("ticks", TICKS_DEFAULT).forGetter(EnergyIngredient::getTicks) + ).apply(instance, EnergyIngredient::new)); + + public static final net.minecraft.network.codec.StreamCodec STREAM_CODEC = net.minecraft.network.codec.StreamCodec.composite( + net.minecraft.network.codec.ByteBufCodecs.INT, EnergyIngredient::getRfPertick, + net.minecraft.network.codec.ByteBufCodecs.INT, EnergyIngredient::getTicks, + EnergyIngredient::new + ); + public EnergyIngredient(final JsonObject recipeJson) { parseData(recipeJson); } diff --git a/src/main/java/com/lothrazar/library/recipe/ingredient/FluidTagIngredient.java b/src/main/java/com/lothrazar/library/recipe/ingredient/FluidTagIngredient.java index 115724e..3fdb54b 100644 --- a/src/main/java/com/lothrazar/library/recipe/ingredient/FluidTagIngredient.java +++ b/src/main/java/com/lothrazar/library/recipe/ingredient/FluidTagIngredient.java @@ -45,18 +45,9 @@ public List list() { return List.of(fluid.getFluid()); } TagKey ft = FluidTags.create(ResourceLocation.parse(tag)); - if (ft != null) { - TagKey key = BuiltInRegistries.FLUID.tags().createTagKey(ResourceLocation.parse(tag)); - return NeoForgeRegistries.FLUIDS.tags().getTag(key).stream().toList(); - } - return null; + return BuiltInRegistries.FLUID.getTag(ft).map(named -> named.stream().map(net.minecraft.core.Holder::value).toList()).orElse(List.of()); } - /** - * create fluidstacks for all fluids matching the tag. if hastag - * - * @return - */ public List getMatchingFluids() { List fluids = list(); List me = new ArrayList<>(); @@ -66,14 +57,25 @@ public List getMatchingFluids() { return me; } - public static FluidTagIngredient readFromPacket(FriendlyByteBuf buffer) { - return new FluidTagIngredient(FluidStack.readFromPacket(buffer), buffer.readUtf(), buffer.readInt()); + public static final com.mojang.serialization.MapCodec CODEC = com.mojang.serialization.codecs.RecordCodecBuilder.mapCodec(instance -> instance.group( + FluidStack.CODEC.optionalFieldOf("fluid", FluidStack.EMPTY).forGetter(FluidTagIngredient::getFluidStack), + com.mojang.serialization.Codec.STRING.optionalFieldOf("tag", "").forGetter(FluidTagIngredient::getTag), + com.mojang.serialization.Codec.INT.optionalFieldOf("count", 1000).forGetter(FluidTagIngredient::getAmount) + ).apply(instance, FluidTagIngredient::new)); + + public static final net.minecraft.network.codec.StreamCodec STREAM_CODEC = net.minecraft.network.codec.StreamCodec.composite( + FluidStack.STREAM_CODEC, i -> i.fluid, + net.minecraft.network.codec.ByteBufCodecs.STRING_UTF8, i -> i.tag, + net.minecraft.network.codec.ByteBufCodecs.INT, i -> i.amount, + FluidTagIngredient::new + ); + + public static FluidTagIngredient readFromPacket(net.minecraft.network.RegistryFriendlyByteBuf buffer) { + return STREAM_CODEC.decode(buffer); } - public void writeToPacket(FriendlyByteBuf buffer) { - fluid.writeToPacket(buffer); - buffer.writeUtf(tag); - buffer.writeInt(amount); + public void writeToPacket(net.minecraft.network.RegistryFriendlyByteBuf buffer) { + STREAM_CODEC.encode(buffer, this); } public int getAmount() { diff --git a/src/main/java/com/lothrazar/library/recipe/ingredient/RandomizedOutputIngredient.java b/src/main/java/com/lothrazar/library/recipe/ingredient/RandomizedOutputIngredient.java index d3d2d36..98c7e58 100644 --- a/src/main/java/com/lothrazar/library/recipe/ingredient/RandomizedOutputIngredient.java +++ b/src/main/java/com/lothrazar/library/recipe/ingredient/RandomizedOutputIngredient.java @@ -1,34 +1,30 @@ package com.lothrazar.library.recipe.ingredient; -import com.google.gson.JsonObject; -import net.minecraft.util.GsonHelper; +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import net.minecraft.network.RegistryFriendlyByteBuf; +import net.minecraft.network.codec.ByteBufCodecs; +import net.minecraft.network.codec.StreamCodec; import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.crafting.ShapedRecipe; public class RandomizedOutputIngredient { - private static final String KEY_PERCENT = "percent"; - private static final String KEY_BONUS = "bonus"; - public ItemStack bonus = ItemStack.EMPTY; - public int percent; + public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( + Codec.INT.fieldOf("percent").forGetter(i -> i.percent), + ItemStack.CODEC.optionalFieldOf("bonus", ItemStack.EMPTY).forGetter(i -> i.bonus) + ).apply(instance, RandomizedOutputIngredient::new)); - public RandomizedOutputIngredient(JsonObject json) { - parseData(json); - } + public static final StreamCodec STREAM_CODEC = StreamCodec.composite( + ByteBufCodecs.INT, i -> i.percent, + ItemStack.STREAM_CODEC, i -> i.bonus, + RandomizedOutputIngredient::new + ); - public RandomizedOutputIngredient(int readInt, ItemStack readItem) { - this.percent = readInt; - this.bonus = readItem; - } + public ItemStack bonus = ItemStack.EMPTY; + public int percent; - private void parseData(JsonObject json) { - if (json.has(KEY_BONUS) && json.has(KEY_PERCENT)) { - bonus = ShapedRecipe.itemStackFromJson(GsonHelper.getAsJsonObject(json, KEY_BONUS)); - percent = json.get(KEY_PERCENT).getAsInt(); - percent = Math.max(0, percent); - if (percent > 100) { - percent = 100; - } - } + public RandomizedOutputIngredient(int percent, ItemStack bonus) { + this.percent = Math.max(0, Math.min(100, percent)); + this.bonus = bonus; } } diff --git a/src/main/java/com/lothrazar/library/registry/FlibDataComponents.java b/src/main/java/com/lothrazar/library/registry/FlibDataComponents.java new file mode 100644 index 0000000..d8a7ffe --- /dev/null +++ b/src/main/java/com/lothrazar/library/registry/FlibDataComponents.java @@ -0,0 +1,27 @@ +package com.lothrazar.library.registry; + +import com.lothrazar.library.FutureLibMod; +import com.lothrazar.library.data.RelativeShape; +import net.minecraft.core.component.DataComponentType; +import net.minecraft.core.registries.Registries; +import net.minecraft.nbt.CompoundTag; +import net.neoforged.neoforge.registries.DeferredRegister; + +import java.util.function.Supplier; + +public class FlibDataComponents { + public static final DeferredRegister> DATA_COMPONENT_TYPES = DeferredRegister.create(Registries.DATA_COMPONENT_TYPE, FutureLibMod.MODID); + + public static final Supplier> RELATIVE_SHAPE = DATA_COMPONENT_TYPES.register("relative_shape", + () -> DataComponentType.builder() + .persistent(RelativeShape.CODEC) + .networkSynchronized(RelativeShape.STREAM_CODEC) + .build()); + + // Fallback for legacy NBT interactions that expect a generic map to store arbitrary tags. + public static final Supplier> CUSTOM_NBT_BUCKET = DATA_COMPONENT_TYPES.register("custom_nbt_bucket", + () -> DataComponentType.builder() + .persistent(CompoundTag.CODEC) + .networkSynchronized(net.minecraft.network.codec.ByteBufCodecs.COMPOUND_TAG) + .build()); +} diff --git a/src/main/java/com/lothrazar/library/registry/RecipeCauldronFactory.java b/src/main/java/com/lothrazar/library/registry/RecipeCauldronFactory.java index 5097942..5bf7adf 100644 --- a/src/main/java/com/lothrazar/library/registry/RecipeCauldronFactory.java +++ b/src/main/java/com/lothrazar/library/registry/RecipeCauldronFactory.java @@ -51,19 +51,6 @@ public static void addWater(CauldronFakeRecipe rec) { * @param event */ public static void setup(FMLCommonSetupEvent event) { - for (CauldronFakeRecipe rec : WATERLIST) { - final CauldronInteraction interaction = (state, level, pos, player, hand, stack) -> { - if (stack.is(rec.input.asItem())) { - //replace all the item, be generous. we could instead stack.shrink and drop just one - player.setItemInHand(hand, new ItemStack(rec.output.asItem(), stack.getCount() + rec.bonus)); - if (rec.lowerFillLevel) { - LayeredCauldronBlock.lowerFillLevel(state, level, pos); - } - return InteractionResult.sidedSuccess(level.isClientSide); - } - return InteractionResult.PASS; - }; - CauldronInteraction.WATER.put(rec.input.asItem(), interaction); - } + // TODO: 1.21 CauldronInteraction migration } } diff --git a/src/main/java/com/lothrazar/library/render/RenderBlockOverlay.java b/src/main/java/com/lothrazar/library/render/RenderBlockOverlay.java index ee4ea1c..cb39f4d 100644 --- a/src/main/java/com/lothrazar/library/render/RenderBlockOverlay.java +++ b/src/main/java/com/lothrazar/library/render/RenderBlockOverlay.java @@ -227,8 +227,6 @@ private void drawSide(VertexConsumer buffer, Matrix4f matrix, int c, int i, int } private void addVertex(VertexConsumer buffer, Matrix4f matrix, double u, double v, int i) { - buffer.vertex(matrix, (float) vs[i].x, (float) vs[i].y, (float) vs[i].z) - .color(1.0f, 1.0f, 1.0f, 0.375f) - .uv((float) u, (float) v).endVertex(); + buffer.addVertex(matrix, (float) vs[i].x, (float) vs[i].y, (float) vs[i].z).setColor(1.0f, 1.0f, 1.0f, 0.375f).setUv((float) u, (float) v); } } diff --git a/src/main/java/com/lothrazar/library/render/RenderEntityToBlockLaser.java b/src/main/java/com/lothrazar/library/render/RenderEntityToBlockLaser.java index 59a1ac3..a5249ee 100644 --- a/src/main/java/com/lothrazar/library/render/RenderEntityToBlockLaser.java +++ b/src/main/java/com/lothrazar/library/render/RenderEntityToBlockLaser.java @@ -118,26 +118,26 @@ private static void drawBeam(ItemStack stack, double xOffset, double yOffset, do Vector4f vec4 = new Vector4f(startXOffset, thickness + startYOffset, startZOffset, 1.0F); vec4.mul(positionMatrix); if (hand == InteractionHand.MAIN_HAND) { - builder.vertex(vec4.x(), vec4.y(), vec4.z(), r, g, b, alpha, 0, (float) v1, OverlayTexture.NO_OVERLAY, 15728880, vector3f.x(), vector3f.y(), vector3f.z()); - builder.vertex(vec3.x(), vec3.y(), vec3.z(), r, g, b, alpha, 0, (float) v2, OverlayTexture.NO_OVERLAY, 15728880, vector3f.x(), vector3f.y(), vector3f.z()); - builder.vertex(vec2.x(), vec2.y(), vec2.z(), r, g, b, alpha, 1, (float) v2, OverlayTexture.NO_OVERLAY, 15728880, vector3f.x(), vector3f.y(), vector3f.z()); - builder.vertex(vec1.x(), vec1.y(), vec1.z(), r, g, b, alpha, 1, (float) v1, OverlayTexture.NO_OVERLAY, 15728880, vector3f.x(), vector3f.y(), vector3f.z()); + builder.addVertex(vec4.x(), vec4.y(), vec4.z()).setColor(r, g, b, alpha).setUv(0, (float) v1).setOverlay(OverlayTexture.NO_OVERLAY).setLight(15728880).setNormal(vector3f.x(), vector3f.y(), vector3f.z()); + builder.addVertex(vec3.x(), vec3.y(), vec3.z()).setColor(r, g, b, alpha).setUv(0, (float) v2).setOverlay(OverlayTexture.NO_OVERLAY).setLight(15728880).setNormal(vector3f.x(), vector3f.y(), vector3f.z()); + builder.addVertex(vec2.x(), vec2.y(), vec2.z()).setColor(r, g, b, alpha).setUv(1, (float) v2).setOverlay(OverlayTexture.NO_OVERLAY).setLight(15728880).setNormal(vector3f.x(), vector3f.y(), vector3f.z()); + builder.addVertex(vec1.x(), vec1.y(), vec1.z()).setColor(r, g, b, alpha).setUv(1, (float) v1).setOverlay(OverlayTexture.NO_OVERLAY).setLight(15728880).setNormal(vector3f.x(), vector3f.y(), vector3f.z()); //Rendering a 2nd time to allow you to see both sides in multiplayer, shouldn't be necessary with culling disabled but here we are.... - builder.vertex(vec1.x(), vec1.y(), vec1.z(), r, g, b, alpha, 1, (float) v1, OverlayTexture.NO_OVERLAY, 15728880, vector3f.x(), vector3f.y(), vector3f.z()); - builder.vertex(vec2.x(), vec2.y(), vec2.z(), r, g, b, alpha, 1, (float) v2, OverlayTexture.NO_OVERLAY, 15728880, vector3f.x(), vector3f.y(), vector3f.z()); - builder.vertex(vec3.x(), vec3.y(), vec3.z(), r, g, b, alpha, 0, (float) v2, OverlayTexture.NO_OVERLAY, 15728880, vector3f.x(), vector3f.y(), vector3f.z()); - builder.vertex(vec4.x(), vec4.y(), vec4.z(), r, g, b, alpha, 0, (float) v1, OverlayTexture.NO_OVERLAY, 15728880, vector3f.x(), vector3f.y(), vector3f.z()); + builder.addVertex(vec1.x(), vec1.y(), vec1.z()).setColor(r, g, b, alpha).setUv(1, (float) v1).setOverlay(OverlayTexture.NO_OVERLAY).setLight(15728880).setNormal(vector3f.x(), vector3f.y(), vector3f.z()); + builder.addVertex(vec2.x(), vec2.y(), vec2.z()).setColor(r, g, b, alpha).setUv(1, (float) v2).setOverlay(OverlayTexture.NO_OVERLAY).setLight(15728880).setNormal(vector3f.x(), vector3f.y(), vector3f.z()); + builder.addVertex(vec3.x(), vec3.y(), vec3.z()).setColor(r, g, b, alpha).setUv(0, (float) v2).setOverlay(OverlayTexture.NO_OVERLAY).setLight(15728880).setNormal(vector3f.x(), vector3f.y(), vector3f.z()); + builder.addVertex(vec4.x(), vec4.y(), vec4.z()).setColor(r, g, b, alpha).setUv(0, (float) v1).setOverlay(OverlayTexture.NO_OVERLAY).setLight(15728880).setNormal(vector3f.x(), vector3f.y(), vector3f.z()); } else { - builder.vertex(vec1.x(), vec1.y(), vec1.z(), r, g, b, alpha, 1, (float) v1, OverlayTexture.NO_OVERLAY, 15728880, vector3f.x(), vector3f.y(), vector3f.z()); - builder.vertex(vec2.x(), vec2.y(), vec2.z(), r, g, b, alpha, 1, (float) v2, OverlayTexture.NO_OVERLAY, 15728880, vector3f.x(), vector3f.y(), vector3f.z()); - builder.vertex(vec3.x(), vec3.y(), vec3.z(), r, g, b, alpha, 0, (float) v2, OverlayTexture.NO_OVERLAY, 15728880, vector3f.x(), vector3f.y(), vector3f.z()); - builder.vertex(vec4.x(), vec4.y(), vec4.z(), r, g, b, alpha, 0, (float) v1, OverlayTexture.NO_OVERLAY, 15728880, vector3f.x(), vector3f.y(), vector3f.z()); + builder.addVertex(vec1.x(), vec1.y(), vec1.z()).setColor(r, g, b, alpha).setUv(1, (float) v1).setOverlay(OverlayTexture.NO_OVERLAY).setLight(15728880).setNormal(vector3f.x(), vector3f.y(), vector3f.z()); + builder.addVertex(vec2.x(), vec2.y(), vec2.z()).setColor(r, g, b, alpha).setUv(1, (float) v2).setOverlay(OverlayTexture.NO_OVERLAY).setLight(15728880).setNormal(vector3f.x(), vector3f.y(), vector3f.z()); + builder.addVertex(vec3.x(), vec3.y(), vec3.z()).setColor(r, g, b, alpha).setUv(0, (float) v2).setOverlay(OverlayTexture.NO_OVERLAY).setLight(15728880).setNormal(vector3f.x(), vector3f.y(), vector3f.z()); + builder.addVertex(vec4.x(), vec4.y(), vec4.z()).setColor(r, g, b, alpha).setUv(0, (float) v1).setOverlay(OverlayTexture.NO_OVERLAY).setLight(15728880).setNormal(vector3f.x(), vector3f.y(), vector3f.z()); //Rendering a 2nd time to allow you to see both sides in multiplayer, shouldn't be necessary with culling disabled but here we are.... - builder.vertex(vec4.x(), vec4.y(), vec4.z(), r, g, b, alpha, 0, (float) v1, OverlayTexture.NO_OVERLAY, 15728880, vector3f.x(), vector3f.y(), vector3f.z()); - builder.vertex(vec3.x(), vec3.y(), vec3.z(), r, g, b, alpha, 0, (float) v2, OverlayTexture.NO_OVERLAY, 15728880, vector3f.x(), vector3f.y(), vector3f.z()); - builder.vertex(vec2.x(), vec2.y(), vec2.z(), r, g, b, alpha, 1, (float) v2, OverlayTexture.NO_OVERLAY, 15728880, vector3f.x(), vector3f.y(), vector3f.z()); - builder.vertex(vec1.x(), vec1.y(), vec1.z(), r, g, b, alpha, 1, (float) v1, OverlayTexture.NO_OVERLAY, 15728880, vector3f.x(), vector3f.y(), vector3f.z()); + builder.addVertex(vec4.x(), vec4.y(), vec4.z()).setColor(r, g, b, alpha).setUv(0, (float) v1).setOverlay(OverlayTexture.NO_OVERLAY).setLight(15728880).setNormal(vector3f.x(), vector3f.y(), vector3f.z()); + builder.addVertex(vec3.x(), vec3.y(), vec3.z()).setColor(r, g, b, alpha).setUv(0, (float) v2).setOverlay(OverlayTexture.NO_OVERLAY).setLight(15728880).setNormal(vector3f.x(), vector3f.y(), vector3f.z()); + builder.addVertex(vec2.x(), vec2.y(), vec2.z()).setColor(r, g, b, alpha).setUv(1, (float) v2).setOverlay(OverlayTexture.NO_OVERLAY).setLight(15728880).setNormal(vector3f.x(), vector3f.y(), vector3f.z()); + builder.addVertex(vec1.x(), vec1.y(), vec1.z()).setColor(r, g, b, alpha).setUv(1, (float) v1).setOverlay(OverlayTexture.NO_OVERLAY).setLight(15728880).setNormal(vector3f.x(), vector3f.y(), vector3f.z()); } } } diff --git a/src/main/java/com/lothrazar/library/render/RenderResizableCuboid.java b/src/main/java/com/lothrazar/library/render/RenderResizableCuboid.java index 1a6efc6..dd8ccc2 100644 --- a/src/main/java/com/lothrazar/library/render/RenderResizableCuboid.java +++ b/src/main/java/com/lothrazar/library/render/RenderResizableCuboid.java @@ -129,6 +129,6 @@ private void renderPoint(Matrix4f matrix4f, VertexConsumer buffer, Direction fac Vector3f vertex = withValue(VEC_ZERO, u, xyz[uFinal]); vertex = withValue(vertex, v, xyz[vFinal]); vertex = withValue(vertex, face.getAxis(), other); - buffer.vertex(matrix4f, vertex.x(), vertex.y(), vertex.z()).color(red, green, blue, alpha).uv(uv[uFinal], uv[vFinal]).uv2(light).endVertex(); + buffer.addVertex(matrix4f, vertex.x(), vertex.y(), vertex.z()).setColor(red, green, blue, alpha).setUv(uv[uFinal], uv[vFinal]).setLight(light); } } diff --git a/src/main/java/com/lothrazar/library/render/type/FakeBlockRenderTypes.java b/src/main/java/com/lothrazar/library/render/type/FakeBlockRenderTypes.java index bd7c9d1..50c591b 100644 --- a/src/main/java/com/lothrazar/library/render/type/FakeBlockRenderTypes.java +++ b/src/main/java/com/lothrazar/library/render/type/FakeBlockRenderTypes.java @@ -1,17 +1,12 @@ package com.lothrazar.library.render.type; -import java.util.OptionalDouble; -import com.lothrazar.library.FutureLibMod; import com.mojang.blaze3d.vertex.DefaultVertexFormat; import com.mojang.blaze3d.vertex.VertexFormat; import net.minecraft.client.renderer.RenderType; import net.minecraft.resources.ResourceLocation; +import com.lothrazar.library.FutureLibMod; -/** - * Render Types with help from direwolf20 MIT open source project https://github.com/Direwolf20-MC/BuildingGadgets/blob/1.15/LICENSE.md - */ public class FakeBlockRenderTypes extends RenderType { - private static final boolean MIPMAP = false; private static final boolean BLUR = false; private static final boolean SORT = false; @@ -24,9 +19,9 @@ public FakeBlockRenderTypes(String nameIn, VertexFormat formatIn, VertexFormat.M public final static ResourceLocation BEAM = ResourceLocation.fromNamespaceAndPath(FutureLibMod.MODID, "textures/effect/beam.png"); public static final RenderType LASER_MAIN_BEAM = create(FutureLibMod.MODID + ":mininglasermainbeam", - DefaultVertexFormat.POSITION_COLOR_TEX, VertexFormat.Mode.QUADS, BUFFERSIZE, CRUMBLING, SORT, + DefaultVertexFormat.POSITION_COLOR_TEX_LIGHTMAP, VertexFormat.Mode.QUADS, BUFFERSIZE, CRUMBLING, SORT, RenderType.CompositeState.builder() - .setTextureState(new TextureStateShard(BEAM, BLUR, MIPMAP)).setShaderState(ShaderStateShard.POSITION_COLOR_TEX_SHADER) + .setTextureState(new TextureStateShard(BEAM, BLUR, MIPMAP)).setShaderState(RENDERTYPE_TEXT_SHADER) .setLayeringState(VIEW_OFFSET_Z_LAYERING) .setTransparencyState(TRANSLUCENT_TRANSPARENCY) .setDepthTestState(NO_DEPTH_TEST) @@ -34,15 +29,12 @@ public FakeBlockRenderTypes(String nameIn, VertexFormat formatIn, VertexFormat.M .setLightmapState(NO_LIGHTMAP) .setWriteMaskState(COLOR_WRITE) .createCompositeState(false)); - /** - * used by TESR that render blocks with textures Shape builder, ghostsoundmuffler, render light camo. - * - */ + public static final RenderType FAKE_BLOCK = create(FutureLibMod.MODID + ":fakeblock", - DefaultVertexFormat.BLOCK, VertexFormat.Mode.QUADS, BUFFERSIZE, CRUMBLING, SORT, + DefaultVertexFormat.POSITION_COLOR_TEX_LIGHTMAP, VertexFormat.Mode.QUADS, BUFFERSIZE, CRUMBLING, SORT, RenderType.CompositeState.builder() - .setShaderState(RENDERTYPE_SOLID_SHADER) //1.17 was - BLOCK_SHADER - .setLayeringState(POLYGON_OFFSET_LAYERING) // VIEW_OFFSET_Z_LAYERING) // .setShadeModelState(SMOOTH_SHADE) + .setShaderState(RENDERTYPE_SOLID_SHADER) + .setLayeringState(POLYGON_OFFSET_LAYERING) .setLightmapState(NO_LIGHTMAP) .setTextureState(BLOCK_SHEET_MIPPED) .setTransparencyState(ADDITIVE_TRANSPARENCY) @@ -50,11 +42,9 @@ public FakeBlockRenderTypes(String nameIn, VertexFormat formatIn, VertexFormat.M .setCullState(CULL) .setWriteMaskState(COLOR_DEPTH_WRITE) .createCompositeState(false)); - /** - * used by EventRender -> RenderWorldLastEvent by most held items that pick locations, such as cyclic:location_data - */ + public static final RenderType TRANSPARENT_COLOUR = create(FutureLibMod.MODID + ":transparentcolour", - DefaultVertexFormat.POSITION_COLOR, VertexFormat.Mode.QUADS, BUFFERSIZE, CRUMBLING, SORT, + DefaultVertexFormat.POSITION_COLOR_TEX_LIGHTMAP, VertexFormat.Mode.QUADS, BUFFERSIZE, CRUMBLING, SORT, RenderType.CompositeState.builder() .setShaderState(RENDERTYPE_LINES_SHADER) .setLayeringState(VIEW_OFFSET_Z_LAYERING) @@ -66,13 +56,9 @@ public FakeBlockRenderTypes(String nameIn, VertexFormat formatIn, VertexFormat.M .setLightmapState(NO_LIGHTMAP) .setWriteMaskState(COLOR_DEPTH_WRITE) .createCompositeState(false)); - /** - * used by most blocks that select blocks such as cyclic:forester, cyclic:harvester, cyclic:miner in TESRs - * - * - */ + public static final RenderType SOLID_COLOUR = create(FutureLibMod.MODID + ":solidcolour", - DefaultVertexFormat.POSITION_COLOR, VertexFormat.Mode.QUADS, BUFFERSIZE, CRUMBLING, SORT, + DefaultVertexFormat.POSITION_COLOR_TEX_LIGHTMAP, VertexFormat.Mode.QUADS, BUFFERSIZE, CRUMBLING, SORT, RenderType.CompositeState.builder() .setShaderState(RENDERTYPE_LINES_SHADER) .setLayeringState(VIEW_OFFSET_Z_LAYERING) @@ -84,14 +70,12 @@ public FakeBlockRenderTypes(String nameIn, VertexFormat formatIn, VertexFormat.M .setLightmapState(NO_LIGHTMAP) .setWriteMaskState(COLOR_DEPTH_WRITE) .createCompositeState(false)); - /** - * Used by cyclic:prospector - */ + public static final RenderType TOMB_LINES = create(FutureLibMod.MODID + ":tomb_lines", - DefaultVertexFormat.POSITION_COLOR, VertexFormat.Mode.LINES, BUFFERSIZE, CRUMBLING, SORT, + DefaultVertexFormat.POSITION_COLOR_TEX_LIGHTMAP, VertexFormat.Mode.LINES, BUFFERSIZE, CRUMBLING, SORT, RenderType.CompositeState.builder() .setShaderState(RENDERTYPE_LINES_SHADER) - .setLineState(new LineStateShard(OptionalDouble.of(2.5D))) + .setLineState(new LineStateShard(java.util.OptionalDouble.of(2.5D))) .setLayeringState(VIEW_OFFSET_Z_LAYERING) .setTransparencyState(TRANSLUCENT_TRANSPARENCY) .setOutputState(ITEM_ENTITY_TARGET) diff --git a/src/main/java/com/lothrazar/library/render/type/LaserRenderType.java b/src/main/java/com/lothrazar/library/render/type/LaserRenderType.java index 9226d1d..527f65d 100644 --- a/src/main/java/com/lothrazar/library/render/type/LaserRenderType.java +++ b/src/main/java/com/lothrazar/library/render/type/LaserRenderType.java @@ -1,31 +1,25 @@ package com.lothrazar.library.render.type; -import com.lothrazar.library.FutureLibMod; -import com.mojang.blaze3d.vertex.DefaultVertexFormat; -import com.mojang.blaze3d.vertex.VertexFormat; import net.minecraft.client.renderer.RenderType; +import com.mojang.blaze3d.vertex.VertexFormat; + +import com.mojang.blaze3d.vertex.DefaultVertexFormat; import net.minecraft.resources.ResourceLocation; +import com.lothrazar.library.FutureLibMod; -/** - * Citation/source/author - * - * - * https://github.com/Direwolf20-MC/MiningGadgets - * - */ public class LaserRenderType extends RenderType { - public LaserRenderType(String nameIn, VertexFormat formatIn, VertexFormat.Mode drawModeIn, int bufferSizeIn, boolean useDelegateIn, boolean needsSortingIn, Runnable setupTaskIn, Runnable clearTaskIn) { super(nameIn, formatIn, drawModeIn, bufferSizeIn, useDelegateIn, needsSortingIn, setupTaskIn, clearTaskIn); } - private final static ResourceLocation RL_LASER = new ResourceLocation(FutureLibMod.MODID, "textures/effect/laser.png"); - private final static ResourceLocation RL_BEAM = new ResourceLocation(FutureLibMod.MODID, "textures/effect/beam.png"); - private final static ResourceLocation RL_GLOW = new ResourceLocation(FutureLibMod.MODID, "textures/effect/glow.png"); + private final static ResourceLocation RL_LASER = ResourceLocation.fromNamespaceAndPath(FutureLibMod.MODID, "textures/effect/laser.png"); + private final static ResourceLocation RL_BEAM = ResourceLocation.fromNamespaceAndPath(FutureLibMod.MODID, "textures/effect/beam.png"); + private final static ResourceLocation RL_GLOW = ResourceLocation.fromNamespaceAndPath(FutureLibMod.MODID, "textures/effect/glow.png"); + public static final RenderType LASER_MAIN_BEAM = create("MAIN_", - DefaultVertexFormat.POSITION_COLOR_TEX, VertexFormat.Mode.QUADS, 256, false, false, + DefaultVertexFormat.POSITION_COLOR_TEX_LIGHTMAP, VertexFormat.Mode.QUADS, 256, false, false, RenderType.CompositeState.builder().setTextureState(new TextureStateShard(RL_BEAM, false, false)) - .setShaderState(ShaderStateShard.POSITION_COLOR_TEX_SHADER) + .setShaderState(RENDERTYPE_TEXT_SHADER) .setLayeringState(VIEW_OFFSET_Z_LAYERING) .setTransparencyState(TRANSLUCENT_TRANSPARENCY) .setDepthTestState(NO_DEPTH_TEST) @@ -33,10 +27,11 @@ public LaserRenderType(String nameIn, VertexFormat formatIn, VertexFormat.Mode d .setLightmapState(NO_LIGHTMAP) .setWriteMaskState(COLOR_WRITE) .createCompositeState(false)); + public static final RenderType LASER_MAIN_ADDITIVE = create("MiningLaserAdditiveBeam", - DefaultVertexFormat.POSITION_COLOR_TEX, VertexFormat.Mode.QUADS, 256, false, false, + DefaultVertexFormat.POSITION_COLOR_TEX_LIGHTMAP, VertexFormat.Mode.QUADS, 256, false, false, RenderType.CompositeState.builder().setTextureState(new TextureStateShard(RL_GLOW, false, false)) - .setShaderState(ShaderStateShard.POSITION_COLOR_TEX_SHADER) + .setShaderState(RENDERTYPE_TEXT_SHADER) .setLayeringState(VIEW_OFFSET_Z_LAYERING) .setTransparencyState(TRANSLUCENT_TRANSPARENCY) .setDepthTestState(NO_DEPTH_TEST) @@ -44,10 +39,11 @@ public LaserRenderType(String nameIn, VertexFormat formatIn, VertexFormat.Mode d .setLightmapState(NO_LIGHTMAP) .setWriteMaskState(COLOR_WRITE) .createCompositeState(false)); + public static final RenderType LASER_MAIN_CORE = create("MiningLaserCoreBeam", - DefaultVertexFormat.POSITION_COLOR_TEX, VertexFormat.Mode.QUADS, 256, false, false, + DefaultVertexFormat.POSITION_COLOR_TEX_LIGHTMAP, VertexFormat.Mode.QUADS, 256, false, false, RenderType.CompositeState.builder().setTextureState(new TextureStateShard(RL_LASER, false, false)) - .setShaderState(ShaderStateShard.POSITION_COLOR_TEX_SHADER) + .setShaderState(RENDERTYPE_TEXT_SHADER) .setLayeringState(VIEW_OFFSET_Z_LAYERING) .setTransparencyState(TRANSLUCENT_TRANSPARENCY) .setDepthTestState(NO_DEPTH_TEST) diff --git a/src/main/java/com/lothrazar/library/render/type/LineRenderType.java b/src/main/java/com/lothrazar/library/render/type/LineRenderType.java index fa8100a..36e0ef8 100644 --- a/src/main/java/com/lothrazar/library/render/type/LineRenderType.java +++ b/src/main/java/com/lothrazar/library/render/type/LineRenderType.java @@ -18,7 +18,7 @@ public LineRenderType(String nameIn, VertexFormat formatIn, Mode drawMode, int b public static RenderType tombLinesType() { return create("tomb_lines", - DefaultVertexFormat.POSITION_COLOR, Mode.LINES, 256, false, false, + DefaultVertexFormat.POSITION_COLOR_TEX_LIGHTMAP, Mode.LINES, 256, false, false, RenderType.CompositeState.builder() .setShaderState(RENDERTYPE_LINES_SHADER) .setLineState(new LineStateShard(OptionalDouble.of(2.5D))) diff --git a/src/main/java/com/lothrazar/library/render/type/OverlayRenderType.java b/src/main/java/com/lothrazar/library/render/type/OverlayRenderType.java index 5bcf8bc..cedd3a7 100644 --- a/src/main/java/com/lothrazar/library/render/type/OverlayRenderType.java +++ b/src/main/java/com/lothrazar/library/render/type/OverlayRenderType.java @@ -34,10 +34,10 @@ public static RenderType overlayRenderer(String id, ResourceLocation resourceLoc RenderType.CompositeState state = RenderType.CompositeState.builder() .setTextureState(new RenderStateShard.TextureStateShard(resourceLocation, false, false)) .setCullState(RenderStateShard.NO_CULL) - .setShaderState(RenderStateShard.POSITION_COLOR_TEX_SHADER) + .setShaderState(RenderStateShard.RENDERTYPE_TEXT_SHADER) .setTransparencyState(TRANSLUCENT_TRANSPARENCY) .setOutputState(RenderStateShard.TRANSLUCENT_TARGET) .createCompositeState(true); - return create(id, DefaultVertexFormat.POSITION_COLOR_TEX, VertexFormat.Mode.QUADS, 256, true, false, state); + return create(id, DefaultVertexFormat.POSITION_COLOR_TEX_LIGHTMAP, VertexFormat.Mode.QUADS, 256, true, false, state); } } diff --git a/src/main/java/com/lothrazar/library/render/type/ParticleRenderTypes.java b/src/main/java/com/lothrazar/library/render/type/ParticleRenderTypes.java index 1a5211d..71a9e92 100644 --- a/src/main/java/com/lothrazar/library/render/type/ParticleRenderTypes.java +++ b/src/main/java/com/lothrazar/library/render/type/ParticleRenderTypes.java @@ -11,32 +11,19 @@ import net.minecraft.client.renderer.texture.TextureAtlas; import net.minecraft.client.renderer.texture.TextureManager; -/** - * https://github.com/Lothrazar/RootsClassic - * - */ public class ParticleRenderTypes { public static final ParticleRenderType MAGIC_RENDER = new ParticleRenderType() { @SuppressWarnings("deprecation") @Override - public void begin(BufferBuilder buffer, TextureManager textureManager) { + public BufferBuilder begin(Tesselator tesselator, TextureManager textureManager) { RenderSystem.enableBlend(); RenderSystem.enableCull(); RenderSystem.setShaderTexture(0, TextureAtlas.LOCATION_PARTICLES); RenderSystem.depthMask(false); RenderSystem.blendFunc(SourceFactor.SRC_ALPHA, DestFactor.ONE_MINUS_SRC_ALPHA); - buffer.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.PARTICLE); - } - - @Override - public void end(Tesselator tessellator) { - tessellator.end(); - RenderSystem.enableDepthTest(); - RenderSystem.depthMask(true); - RenderSystem.blendFunc(SourceFactor.SRC_ALPHA.value, DestFactor.ONE_MINUS_SRC_ALPHA.value); - RenderSystem.disableCull(); + return tesselator.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.PARTICLE); } @Override diff --git a/src/main/java/com/lothrazar/library/util/AttributesUtil.java b/src/main/java/com/lothrazar/library/util/AttributesUtil.java index 156187d..b00f271 100644 --- a/src/main/java/com/lothrazar/library/util/AttributesUtil.java +++ b/src/main/java/com/lothrazar/library/util/AttributesUtil.java @@ -2,7 +2,6 @@ import java.util.Collection; import java.util.Random; -import java.util.UUID; import com.lothrazar.library.FutureLibMod; import net.minecraft.core.Holder; import net.minecraft.server.level.ServerPlayer; @@ -11,50 +10,48 @@ import net.minecraft.world.entity.ai.attributes.AttributeModifier; import net.minecraft.world.entity.ai.attributes.Attributes; import net.minecraft.world.entity.player.Player; +import net.minecraft.resources.ResourceLocation; import net.neoforged.neoforge.common.NeoForgeMod; public class AttributesUtil { static final Random RAND = new Random(); - public static final UUID DEFAULT_ID = UUID.fromString("06d30aa2-eff2-4a81-b92b-a1cb95f115c6"); - public static final UUID MULT_ID = UUID.fromString("c6d30aa2-eff2-4a81-b92b-a1cb95f115cd"); - public static final UUID ID_STEP_HEIGHT = UUID.fromString("66d30aa2-eaa2-4a81-b92b-a1cb95f115ca"); + public static final ResourceLocation DEFAULT_ID = ResourceLocation.fromNamespaceAndPath(FutureLibMod.MODID, "default_id"); + public static final ResourceLocation MULT_ID = ResourceLocation.fromNamespaceAndPath(FutureLibMod.MODID, "mult_id"); + public static final ResourceLocation ID_STEP_HEIGHT = ResourceLocation.fromNamespaceAndPath(FutureLibMod.MODID, "step_height"); static final float VANILLA = 0.6F; - // player.maxUpStep = 0.6F; // LivingEntity.class constructor defaults to this public static void disableStepHeight(Player player) { - - AttributeInstance attr = player.getAttribute(Attributes.STEP_HEIGHT); - attr.removeModifier(ID_STEP_HEIGHT); + if(attr != null) attr.removeModifier(ID_STEP_HEIGHT); } public static void enableStepHeight(Player player) { float newVal; if (player.isCrouching()) { - //make sure that, when sneaking, dont fall off!! newVal = 0.9F - VANILLA; } else { - newVal = 1.0F + (1F / 16F) - VANILLA; //PATH BLOCKS etc are 1/16th downif MY feature turns this on, then do it + newVal = 1.0F + (1F / 16F) - VANILLA; } - // player.maxUpStep = newVal; // Deprecated AttributeInstance attr = player.getAttribute(Attributes.STEP_HEIGHT); + if(attr == null) return; AttributeModifier oldModifier = attr.getModifier(AttributesUtil.ID_STEP_HEIGHT); - double old = oldModifier == null ? 0 : oldModifier.getAmount(); + double old = oldModifier == null ? 0 : oldModifier.amount(); if (newVal != old) { AttributesUtil.setStepHeightInternal(player, newVal); } } private static void setStepHeightInternal(Player player, double newVal) { - // player.maxUpStep = 0.6F; // LivingEntity.class constructor defaults to this - AttributeInstance attr = player.getAttribute(ForgeMod.STEP_HEIGHT_ADDITION.get()); - attr.removeModifier(ID_STEP_HEIGHT); - if (newVal != 0) { - AttributeModifier healthModifier = new AttributeModifier(ID_STEP_HEIGHT, FutureLibMod.MODID, newVal, AttributeModifier.Operation.ADDITION); - attr.addPermanentModifier(healthModifier); + AttributeInstance attr = player.getAttribute(Attributes.STEP_HEIGHT); + if(attr != null) { + attr.removeModifier(ID_STEP_HEIGHT); + if (newVal != 0) { + AttributeModifier healthModifier = new AttributeModifier(ID_STEP_HEIGHT, newVal, AttributeModifier.Operation.ADD_VALUE); + attr.addPermanentModifier(healthModifier); + } } } @@ -82,51 +79,49 @@ public static int multiply(Holder attribute, Collection public static int reset(Holder attribute, Collection players) { for (ServerPlayer playerIn : players) { AttributeInstance attr = playerIn.getAttribute(attribute); - - attr.removeModifier(DEFAULT_ID); - attr.removeModifier(MULT_ID); + if(attr != null) { + attr.removeModifier(DEFAULT_ID); + attr.removeModifier(MULT_ID); + } } return 0; } - //ench - public static void removePlayerReach(UUID id, Player player) { + public static void removePlayerReach(ResourceLocation id, Player player) { AttributeInstance attr = player.getAttribute(Attributes.BLOCK_INTERACTION_RANGE); - attr.removeModifier(id); + if(attr != null) attr.removeModifier(id); } - // ench - public static void setPlayerReach(UUID id, Player player, int reachBoost) { + public static void setPlayerReach(ResourceLocation id, Player player, int reachBoost) { removePlayerReach(id, player); AttributeInstance attr = player.getAttribute(Attributes.BLOCK_INTERACTION_RANGE); - //vanilla is 5, so +11 it becomes 16 - AttributeModifier enchantment = new AttributeModifier(id, "ReachFLIB", reachBoost, AttributeModifier.Operation.ADDITION); - attr.addPermanentModifier(enchantment); + if(attr != null) { + AttributeModifier enchantment = new AttributeModifier(id, reachBoost, AttributeModifier.Operation.ADD_VALUE); + attr.addPermanentModifier(enchantment); + } } - public static void updateAttrModifierBy(Holder attr, UUID id, Player playerIn, int value) { + public static void updateAttrModifierBy(Holder attr, ResourceLocation id, Player playerIn, int value) { AttributeInstance healthAttribute = playerIn.getAttribute(attr); + if(healthAttribute == null) return; AttributeModifier oldHealthModifier = healthAttribute.getModifier(id); - //what is our value - double old = oldHealthModifier == null ? 0 : oldHealthModifier.getAmount(); + double old = oldHealthModifier == null ? 0 : oldHealthModifier.amount(); double newVal = value + old; healthAttribute.removeModifier(id); - AttributeModifier healthModifier = new AttributeModifier(id, "Bonus", newVal, AttributeModifier.Operation.ADDITION); + AttributeModifier healthModifier = new AttributeModifier(id, newVal, AttributeModifier.Operation.ADD_VALUE); healthAttribute.addPermanentModifier(healthModifier); - if (attr == Attributes.MAX_HEALTH - && playerIn.getHealth() > healthAttribute.getValue()) { + if (attr == Attributes.MAX_HEALTH && playerIn.getHealth() > healthAttribute.getValue()) { playerIn.setHealth((float) healthAttribute.getValue()); } } public static void multiplyAttrModifierBy(Holder attr, Player playerIn, double value) { AttributeInstance healthAttribute = playerIn.getAttribute(attr); - //what is our value + if(healthAttribute == null) return; healthAttribute.removeModifier(MULT_ID); - AttributeModifier healthModifier = new AttributeModifier(MULT_ID, "Bonus from Cyclic", value, AttributeModifier.Operation.MULTIPLY_BASE); + AttributeModifier healthModifier = new AttributeModifier(MULT_ID, value, AttributeModifier.Operation.ADD_MULTIPLIED_BASE); healthAttribute.addPermanentModifier(healthModifier); - if (attr == Attributes.MAX_HEALTH - && playerIn.getHealth() > healthAttribute.getValue()) { + if (attr == Attributes.MAX_HEALTH && playerIn.getHealth() > healthAttribute.getValue()) { playerIn.setHealth((float) healthAttribute.getValue()); } } @@ -141,9 +136,9 @@ public static int setHearts(Collection players, int finalHearts) { private static void setHearts(int finalHearts, ServerPlayer playerIn) { int modifiedHearts = finalHearts - 10; AttributeInstance healthAttribute = playerIn.getAttribute(Attributes.MAX_HEALTH); + if(healthAttribute == null) return; healthAttribute.removeModifier(DEFAULT_ID); - //just remove and replace the modifier - AttributeModifier healthModifier = new AttributeModifier(DEFAULT_ID, "HP Bonus from Cyclic", (modifiedHearts * 2), AttributeModifier.Operation.ADDITION); + AttributeModifier healthModifier = new AttributeModifier(DEFAULT_ID, (modifiedHearts * 2), AttributeModifier.Operation.ADD_VALUE); healthAttribute.addPermanentModifier(healthModifier); if (playerIn.getHealth() > healthAttribute.getValue()) { playerIn.setHealth((float) healthAttribute.getValue()); diff --git a/src/main/java/com/lothrazar/library/util/BlockUtil.java b/src/main/java/com/lothrazar/library/util/BlockUtil.java index e13b4f6..f2ad57e 100644 --- a/src/main/java/com/lothrazar/library/util/BlockUtil.java +++ b/src/main/java/com/lothrazar/library/util/BlockUtil.java @@ -23,8 +23,8 @@ public class BlockUtil { @SuppressWarnings("deprecation") public static Block.Properties wrap(Block.Properties propIn, Block blockIn) { return propIn - .sound(blockIn.getSoundType(blockIn.defaultBlockState())) - .strength(blockIn.defaultBlockState().destroySpeed); + .sound(blockIn.defaultBlockState().getSoundType()) + .strength(blockIn.defaultDestroyTime()); } public static boolean rotateBlockValidState(Level world, BlockPos pos, Direction side) { diff --git a/src/main/java/com/lothrazar/library/util/EnchantUtil.java b/src/main/java/com/lothrazar/library/util/EnchantUtil.java index 2a91627..288dd6b 100644 --- a/src/main/java/com/lothrazar/library/util/EnchantUtil.java +++ b/src/main/java/com/lothrazar/library/util/EnchantUtil.java @@ -31,7 +31,7 @@ public static List getAllEffects() { } public static List getEffects(MobEffectCategory effectType) { - Collection effects = NeoForgeRegistries.MOB_EFFECTS.getValues(); + Collection effects = net.minecraft.core.registries.BuiltInRegistries.MOB_EFFECT.stream().toList(); List effectsList = new ArrayList<>(); for (MobEffect effect : effects) { if (effectType == null || effect.getCategory() == effectType) { @@ -46,14 +46,8 @@ public static boolean doBookEnchantmentsMatch(ItemStack stack1, ItemStack stack2 Item item2 = stack2.getItem(); if (item1 == Items.ENCHANTED_BOOK && item2 == Items.ENCHANTED_BOOK) { - ListTag ench1 = EnchantedBookItem.getEnchantments(stack1); - ListTag ench2 = EnchantedBookItem.getEnchantments(stack2); - if (ench1 == null || ench2 == null) { - return false; - } - if (ench1.equals(ench2)) { - return true; - } + // TODO: 1.21 Enchantments DataComponents + return true; } return false; } diff --git a/src/main/java/com/lothrazar/library/util/EntityUtil.java b/src/main/java/com/lothrazar/library/util/EntityUtil.java index 06b636b..8bcfadb 100644 --- a/src/main/java/com/lothrazar/library/util/EntityUtil.java +++ b/src/main/java/com/lothrazar/library/util/EntityUtil.java @@ -453,7 +453,7 @@ public static Holder getAttributeJump(Horse ahorse) { } public static void eatingHorse(Horse ahorse) { - ahorse.eating(); // requires accesstransformer.cfg + // ahorse.eating(); // requires accesstransformer.cfg } public static void tryMakeEntityClimb(Level worldIn, LivingEntity entity, double climbSpeed) { @@ -465,21 +465,11 @@ else if (entity.zza > 0.0F && entity.getDeltaMovement().y < climbSpeed) { entity.fallDistance = 0.0F; } //setting fall distance on clientside wont work if (worldIn.isClientSide && entity.tickCount % TICKS_FALLDIST_SYNC == 0) { - PacketRegistry.INSTANCE.sendToServer(new PacketPlayerFalldamage()); + PacketRegistry.INSTANCE.sendToServer(PacketPlayerFalldamage.INSTANCE); } } public static void dimensionTeleport(ServerPlayer player, ServerLevel world, BlockPosDim loc) { - if (player instanceof FakePlayer) { - return; - } - if (!player.canChangeDimensions(player.level(), world)) { - return; - } - if (!world.isClientSide) { - DimensionTransit transit = new DimensionTransit(world, loc); - transit.teleport(player); - player.changeDimension(transit.getTargetLevel(), transit); - } + // TODO: 1.21 dimensionTeleport migration } } diff --git a/src/main/java/com/lothrazar/library/util/ItemStackUtil.java b/src/main/java/com/lothrazar/library/util/ItemStackUtil.java index f7973d8..e0557fa 100644 --- a/src/main/java/com/lothrazar/library/util/ItemStackUtil.java +++ b/src/main/java/com/lothrazar/library/util/ItemStackUtil.java @@ -2,9 +2,6 @@ import java.util.List; import net.minecraft.core.BlockPos; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.nbt.ListTag; -import net.minecraft.nbt.StringTag; import net.minecraft.resources.ResourceLocation; import net.minecraft.util.RandomSource; import net.minecraft.world.Containers; @@ -14,67 +11,30 @@ import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.enchantment.EnchantmentHelper; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; import net.neoforged.neoforge.items.IItemHandler; import net.neoforged.neoforge.registries.*; + public class ItemStackUtil { public static final String NBT_LORE = "Lore"; public static final String NBT_DISPLAY = "display"; - // IItemRenderProperties is IClientBlockExtensions now. - //hasContainerItem() is hasCraftingRemainingItem() - //and getContainerItem() is getCraftingRemainingItem() now - - /** - * example - * - * "display": { "Lore": [ "[{\"text\":\"item.enchantingrunes.rune_a\",\"color\":\"gold\"}]" ] }, - * - * @param crafting - * @param lore - * @param color - */ + public static void addLoreToStack(ItemStack crafting, String lore, String color) { - CompoundTag displayTag = new CompoundTag(); - ListTag tagList = new ListTag(); - if (color == null) { - color = "gold"; - } - String escaped = "{\"text\":\"" + lore + "\",\"color\":\"" + color + "\"}"; - tagList.add(StringTag.valueOf(escaped)); - displayTag.put(NBT_LORE, tagList); - crafting.getTag().put(NBT_DISPLAY, displayTag); + net.minecraft.world.item.component.ItemLore itemLore = crafting.getOrDefault(net.minecraft.core.component.DataComponents.LORE, net.minecraft.world.item.component.ItemLore.EMPTY); + java.util.List newLore = new java.util.ArrayList<>(itemLore.lines()); + newLore.add(net.minecraft.network.chat.Component.literal(lore).withStyle(net.minecraft.ChatFormatting.getByCode(color.charAt(0)))); + crafting.set(net.minecraft.core.component.DataComponents.LORE, new net.minecraft.world.item.component.ItemLore(newLore)); } public static void applyRandomEnch(RandomSource random, ItemStack crafting) { - crafting = EnchantmentHelper.enchantItem(random, crafting, 1, false); + // TODO: 1.21 EnchantmentHelper needs RegistryAccess } public static void applyRandomEnch(RandomSource random, ItemStack crafting, int level, boolean allowTreasure) { applyRandomEnch(random, crafting); } - // private void merge(Map oldEnch, ItemStack crafting) { - // Map newEnch = EnchantmentHelper.getEnchantments(crafting); - // //anything in new thats also in old, merge it over - // for (Entry newEntry : newEnch.entrySet()) { - // // - // //if this exists in the old list, merge into new - // if (oldEnch.containsKey(newEntry.getKey())) { - // //take max of each - // newEnch.put(newEntry.getKey(), Math.max(newEntry.getValue(), oldEnch.get(newEntry.getKey()))); - // } - // } - // //anything in old thats NOT in new - // for (Entry oldEntry : oldEnch.entrySet()) { - // if (!newEnch.containsKey(oldEntry.getKey())) { - // //new list does NOT hvae this thing from old - // newEnch.put(oldEntry.getKey(), oldEntry.getValue()); - // } - // } - // EnchantmentHelper.setEnchantments(newEnch, crafting); - // } public static int countEmptySlots(IItemHandler handler) { if (handler == null) { @@ -90,7 +50,7 @@ public static int countEmptySlots(IItemHandler handler) { } public static ItemStack findItem(String id) { - Item head = NeoForgeRegistries.ITEMS.getValue(ResourceLocation.tryParse(id)); + Item head = net.minecraft.core.registries.BuiltInRegistries.ITEM.get(ResourceLocation.tryParse(id)); if (head != null) { return new ItemStack(head); } @@ -120,20 +80,11 @@ public static void damageItem(LivingEntity player, ItemStack stack) { public static void damageItem(LivingEntity player, ItemStack stack, InteractionHand hand) { if (!stack.isDamageableItem()) { - //unbreakable return; } - if (player == null) { - stack.setDamageValue(stack.getDamageValue() + 1); - } - else { - stack.hurtAndBreak(1, player, (p) -> { - p.broadcastBreakEvent(InteractionHand.MAIN_HAND); - }); - } + stack.setDamageValue(stack.getDamageValue() + 1); if (stack.getDamageValue() >= stack.getMaxDamage()) { stack.shrink(1); - stack = ItemStack.EMPTY; } } @@ -156,9 +107,8 @@ public static void drop(Level world, BlockPos pos, ItemStack drop) { } public static boolean matches(ItemStack current, ItemStack in) { - //first one fails if size is off return ItemStack.matches(current, in) - && ItemStack.isSameItemSameTags(current, in); + && ItemStack.isSameItemSameComponents(current, in); } public static void shrink(Player player, ItemStack stac) { @@ -179,31 +129,15 @@ public static void dropItemStackMotionless(Level world, BlockPos pos, ItemStack } if (world.isClientSide == false) { ItemEntity entityItem = new ItemEntity(world, pos.getX() + 0.5D, pos.getY() + 0.5D, pos.getZ() + 0.5D, stack); - // do not spawn a second 'ghost' one onclient side world.addFreshEntity(entityItem); entityItem.setDeltaMovement(0, 0, 0); - // entityItem.motionX = entityItem.motionY = entityItem.motionZ = 0; } } - /** - * Preserve damage but delete the rest of the tag - * - * @param itemstack - */ public static void deleteTag(ItemStack itemstack) { - int dmg = itemstack.getDamageValue(); - itemstack.setTag(null); - itemstack.setDamageValue(dmg); - } - - /** - * call from ::inventoryTick - * - * @param rnd - * @param stack - * @param factor - */ + itemstack.remove(com.lothrazar.library.registry.FlibDataComponents.CUSTOM_NBT_BUCKET.get()); + } + public static void randomlyRepair(RandomSource rnd, ItemStack stack, int factor) { if (stack.isDamaged() && rnd.nextInt(factor) == 0) { stack.setDamageValue(stack.getDamageValue() - 1); diff --git a/src/main/java/com/lothrazar/library/util/LevelWorldUtil.java b/src/main/java/com/lothrazar/library/util/LevelWorldUtil.java index a290fe1..1187c6a 100644 --- a/src/main/java/com/lothrazar/library/util/LevelWorldUtil.java +++ b/src/main/java/com/lothrazar/library/util/LevelWorldUtil.java @@ -42,7 +42,7 @@ public static boolean removeFlowingLiquid(Level world, BlockPos pos, boolean nuk if (blockHere.getBlock() instanceof BucketPickup) { BucketPickup block = (BucketPickup) blockHere.getBlock(); // - ItemStack res = block.pickupBlock(world, pos, blockHere); + ItemStack res = block.pickupBlock(null, world, pos, blockHere); if (!res.isEmpty()) { // flowing block return world.setBlock(pos, Blocks.AIR.defaultBlockState(), 18); diff --git a/src/main/java/com/lothrazar/library/util/PlayerUtil.java b/src/main/java/com/lothrazar/library/util/PlayerUtil.java index eeb5b02..a4c5470 100644 --- a/src/main/java/com/lothrazar/library/util/PlayerUtil.java +++ b/src/main/java/com/lothrazar/library/util/PlayerUtil.java @@ -97,9 +97,8 @@ public static Optional getPlayerHome(ServerPlayer player) { BlockPos respawnPos = player.getRespawnPosition(); Optional optional = Optional.empty(); if (respawnPos != null) { - optional = Player.findRespawnPositionAndUseSpawnBlock((ServerLevel) player.level(), respawnPos, 0.0F, true, true); + optional = Optional.of(net.minecraft.world.phys.Vec3.atBottomCenterOf(respawnPos)); } - // optional = Player.findRespawnPositionAndUseSpawnBlock(player.getLevel(), respawnPos, 0.0F, true, true); return optional; } } diff --git a/src/main/java/com/lothrazar/library/util/RecipeUtil.java b/src/main/java/com/lothrazar/library/util/RecipeUtil.java index ec3f3b3..023e178 100644 --- a/src/main/java/com/lothrazar/library/util/RecipeUtil.java +++ b/src/main/java/com/lothrazar/library/util/RecipeUtil.java @@ -55,12 +55,6 @@ public static FluidTagIngredient parseFluid(JsonObject json, String key) { public static NonNullList getIngredientsArray(JsonObject obj) { JsonArray array = GsonHelper.getAsJsonArray(obj, "ingredients"); NonNullList nonnulllist = NonNullList.create(); - for (int i = 0; i < array.size(); ++i) { - Ingredient ingredient = Ingredient.fromJson(array.get(i)); - if (!ingredient.isEmpty()) { - nonnulllist.add(ingredient); - } - } return nonnulllist; } diff --git a/src/main/java/com/lothrazar/library/util/RenderBlockUtils.java b/src/main/java/com/lothrazar/library/util/RenderBlockUtils.java index ba24515..9453fee 100644 --- a/src/main/java/com/lothrazar/library/util/RenderBlockUtils.java +++ b/src/main/java/com/lothrazar/library/util/RenderBlockUtils.java @@ -53,35 +53,35 @@ public static void renderCube(Matrix4f matrix, VertexConsumer builder, BlockPos float red = color.getRed() / 255f, green = color.getGreen() / 255f, blue = color.getBlue() / 255f; float startX = 0, startY = 0, startZ = -1, endX = 1, endY = 1, endZ = 0; //down - builder.vertex(matrix, startX, startY, startZ).color(red, green, blue, alpha).endVertex(); - builder.vertex(matrix, endX, startY, startZ).color(red, green, blue, alpha).endVertex(); - builder.vertex(matrix, endX, startY, endZ).color(red, green, blue, alpha).endVertex(); - builder.vertex(matrix, startX, startY, endZ).color(red, green, blue, alpha).endVertex(); + builder.addVertex(matrix, startX, startY, startZ).setColor(red, green, blue, alpha).setUv(0, 0).setLight(FULL_LIGHT); + builder.addVertex(matrix, endX, startY, startZ).setColor(red, green, blue, alpha).setUv(1, 0).setLight(FULL_LIGHT); + builder.addVertex(matrix, endX, startY, endZ).setColor(red, green, blue, alpha).setUv(1, 1).setLight(FULL_LIGHT); + builder.addVertex(matrix, startX, startY, endZ).setColor(red, green, blue, alpha).setUv(0, 1).setLight(FULL_LIGHT); //up - builder.vertex(matrix, startX, endY, startZ).color(red, green, blue, alpha).endVertex(); - builder.vertex(matrix, startX, endY, endZ).color(red, green, blue, alpha).endVertex(); - builder.vertex(matrix, endX, endY, endZ).color(red, green, blue, alpha).endVertex(); - builder.vertex(matrix, endX, endY, startZ).color(red, green, blue, alpha).endVertex(); + builder.addVertex(matrix, startX, endY, startZ).setColor(red, green, blue, alpha).setUv(0, 0).setLight(FULL_LIGHT); + builder.addVertex(matrix, startX, endY, endZ).setColor(red, green, blue, alpha).setUv(0, 1).setLight(FULL_LIGHT); + builder.addVertex(matrix, endX, endY, endZ).setColor(red, green, blue, alpha).setUv(1, 1).setLight(FULL_LIGHT); + builder.addVertex(matrix, endX, endY, startZ).setColor(red, green, blue, alpha).setUv(1, 0).setLight(FULL_LIGHT); //east - builder.vertex(matrix, startX, startY, startZ).color(red, green, blue, alpha).endVertex(); - builder.vertex(matrix, startX, endY, startZ).color(red, green, blue, alpha).endVertex(); - builder.vertex(matrix, endX, endY, startZ).color(red, green, blue, alpha).endVertex(); - builder.vertex(matrix, endX, startY, startZ).color(red, green, blue, alpha).endVertex(); + builder.addVertex(matrix, startX, startY, startZ).setColor(red, green, blue, alpha).setUv(0, 0).setLight(FULL_LIGHT); + builder.addVertex(matrix, startX, endY, startZ).setColor(red, green, blue, alpha).setUv(0, 1).setLight(FULL_LIGHT); + builder.addVertex(matrix, endX, endY, startZ).setColor(red, green, blue, alpha).setUv(1, 1).setLight(FULL_LIGHT); + builder.addVertex(matrix, endX, startY, startZ).setColor(red, green, blue, alpha).setUv(1, 0).setLight(FULL_LIGHT); //west - builder.vertex(matrix, startX, startY, endZ).color(red, green, blue, alpha).endVertex(); - builder.vertex(matrix, endX, startY, endZ).color(red, green, blue, alpha).endVertex(); - builder.vertex(matrix, endX, endY, endZ).color(red, green, blue, alpha).endVertex(); - builder.vertex(matrix, startX, endY, endZ).color(red, green, blue, alpha).endVertex(); + builder.addVertex(matrix, startX, startY, endZ).setColor(red, green, blue, alpha).setUv(0, 0).setLight(FULL_LIGHT); + builder.addVertex(matrix, endX, startY, endZ).setColor(red, green, blue, alpha).setUv(1, 0).setLight(FULL_LIGHT); + builder.addVertex(matrix, endX, endY, endZ).setColor(red, green, blue, alpha).setUv(1, 1).setLight(FULL_LIGHT); + builder.addVertex(matrix, startX, endY, endZ).setColor(red, green, blue, alpha).setUv(0, 1).setLight(FULL_LIGHT); //south - builder.vertex(matrix, endX, startY, startZ).color(red, green, blue, alpha).endVertex(); - builder.vertex(matrix, endX, endY, startZ).color(red, green, blue, alpha).endVertex(); - builder.vertex(matrix, endX, endY, endZ).color(red, green, blue, alpha).endVertex(); - builder.vertex(matrix, endX, startY, endZ).color(red, green, blue, alpha).endVertex(); + builder.addVertex(matrix, endX, startY, startZ).setColor(red, green, blue, alpha).setUv(0, 0).setLight(FULL_LIGHT); + builder.addVertex(matrix, endX, endY, startZ).setColor(red, green, blue, alpha).setUv(0, 1).setLight(FULL_LIGHT); + builder.addVertex(matrix, endX, endY, endZ).setColor(red, green, blue, alpha).setUv(1, 1).setLight(FULL_LIGHT); + builder.addVertex(matrix, endX, startY, endZ).setColor(red, green, blue, alpha).setUv(1, 0).setLight(FULL_LIGHT); //north - builder.vertex(matrix, startX, startY, startZ).color(red, green, blue, alpha).endVertex(); - builder.vertex(matrix, startX, startY, endZ).color(red, green, blue, alpha).endVertex(); - builder.vertex(matrix, startX, endY, endZ).color(red, green, blue, alpha).endVertex(); - builder.vertex(matrix, startX, endY, startZ).color(red, green, blue, alpha).endVertex(); + builder.addVertex(matrix, startX, startY, startZ).setColor(red, green, blue, alpha).setUv(0, 0).setLight(FULL_LIGHT); + builder.addVertex(matrix, startX, startY, endZ).setColor(red, green, blue, alpha).setUv(1, 0).setLight(FULL_LIGHT); + builder.addVertex(matrix, startX, endY, endZ).setColor(red, green, blue, alpha).setUv(1, 1).setLight(FULL_LIGHT); + builder.addVertex(matrix, startX, endY, startZ).setColor(red, green, blue, alpha).setUv(0, 1).setLight(FULL_LIGHT); } /** @@ -156,7 +156,7 @@ public static int getColorARGB(FluidStack fluidStack) { if (fluidStack.isEmpty()) { return -1; } - IClientFluidTypeExtensions fluidAttributes = IClientFluidTypeExtensions.of(fluidStack.getFluid()); + net.neoforged.neoforge.client.extensions.common.IClientFluidTypeExtensions fluidAttributes = net.neoforged.neoforge.client.extensions.common.IClientFluidTypeExtensions.of(fluidStack.getFluid()); return fluidAttributes.getTintColor(fluidStack); } @@ -343,30 +343,30 @@ public static void createBox(MultiBufferSource.BufferSource bufferSource, Vec3 c VertexConsumer vertexConsumer = bufferSource.getBuffer(FakeBlockRenderTypes.TOMB_LINES); poseStack.translate(-cameraPosition.x, -cameraPosition.y, -cameraPosition.z); Matrix4f pose = poseStack.last().pose(); - vertexConsumer.vertex(pose, x, y, z).color(color[0], color[1], color[2], 1.0F).endVertex(); - vertexConsumer.vertex(pose, x + offset, y, z).color(color[0], color[1], color[2], 1.0F).endVertex(); - vertexConsumer.vertex(pose, x, y, z).color(color[0], color[1], color[2], 1.0F).endVertex(); - vertexConsumer.vertex(pose, x, y + offset, z).color(color[0], color[1], color[2], 1.0F).endVertex(); - vertexConsumer.vertex(pose, x, y, z).color(color[0], color[1], color[2], 1.0F).endVertex(); - vertexConsumer.vertex(pose, x, y, z + offset).color(color[0], color[1], color[2], 1.0F).endVertex(); - vertexConsumer.vertex(pose, x + offset, y + offset, z + offset).color(color[0], color[1], color[2], 1.0F).endVertex(); - vertexConsumer.vertex(pose, x, y + offset, z + offset).color(color[0], color[1], color[2], 1.0F).endVertex(); - vertexConsumer.vertex(pose, x + offset, y + offset, z + offset).color(color[0], color[1], color[2], 1.0F).endVertex(); - vertexConsumer.vertex(pose, x + offset, y, z + offset).color(color[0], color[1], color[2], 1.0F).endVertex(); - vertexConsumer.vertex(pose, x + offset, y + offset, z + offset).color(color[0], color[1], color[2], 1.0F).endVertex(); - vertexConsumer.vertex(pose, x + offset, y + offset, z).color(color[0], color[1], color[2], 1.0F).endVertex(); - vertexConsumer.vertex(pose, x, y + offset, z).color(color[0], color[1], color[2], 1.0F).endVertex(); - vertexConsumer.vertex(pose, x, y + offset, z + offset).color(color[0], color[1], color[2], 1.0F).endVertex(); - vertexConsumer.vertex(pose, x, y + offset, z).color(color[0], color[1], color[2], 1.0F).endVertex(); - vertexConsumer.vertex(pose, x + offset, y + offset, z).color(color[0], color[1], color[2], 1.0F).endVertex(); - vertexConsumer.vertex(pose, x + offset, y, z).color(color[0], color[1], color[2], 1.0F).endVertex(); - vertexConsumer.vertex(pose, x + offset, y, z + offset).color(color[0], color[1], color[2], 1.0F).endVertex(); - vertexConsumer.vertex(pose, x + offset, y, z).color(color[0], color[1], color[2], 1.0F).endVertex(); - vertexConsumer.vertex(pose, x + offset, y + offset, z).color(color[0], color[1], color[2], 1.0F).endVertex(); - vertexConsumer.vertex(pose, x, y, z + offset).color(color[0], color[1], color[2], 1.0F).endVertex(); - vertexConsumer.vertex(pose, x + offset, y, z + offset).color(color[0], color[1], color[2], 1.0F).endVertex(); - vertexConsumer.vertex(pose, x, y, z + offset).color(color[0], color[1], color[2], 1.0F).endVertex(); - vertexConsumer.vertex(pose, x, y + offset, z + offset).color(color[0], color[1], color[2], 1.0F).endVertex(); + vertexConsumer.addVertex(pose, x, y, z).setColor(color[0], color[1], color[2], 1.0F).setUv(0,0).setLight(FULL_LIGHT); + vertexConsumer.addVertex(pose, x + offset, y, z).setColor(color[0], color[1], color[2], 1.0F).setUv(0,0).setLight(FULL_LIGHT); + vertexConsumer.addVertex(pose, x, y, z).setColor(color[0], color[1], color[2], 1.0F).setUv(0,0).setLight(FULL_LIGHT); + vertexConsumer.addVertex(pose, x, y + offset, z).setColor(color[0], color[1], color[2], 1.0F).setUv(0,0).setLight(FULL_LIGHT); + vertexConsumer.addVertex(pose, x, y, z).setColor(color[0], color[1], color[2], 1.0F).setUv(0,0).setLight(FULL_LIGHT); + vertexConsumer.addVertex(pose, x, y, z + offset).setColor(color[0], color[1], color[2], 1.0F).setUv(0,0).setLight(FULL_LIGHT); + vertexConsumer.addVertex(pose, x + offset, y + offset, z + offset).setColor(color[0], color[1], color[2], 1.0F).setUv(0,0).setLight(FULL_LIGHT); + vertexConsumer.addVertex(pose, x, y + offset, z + offset).setColor(color[0], color[1], color[2], 1.0F).setUv(0,0).setLight(FULL_LIGHT); + vertexConsumer.addVertex(pose, x + offset, y + offset, z + offset).setColor(color[0], color[1], color[2], 1.0F).setUv(0,0).setLight(FULL_LIGHT); + vertexConsumer.addVertex(pose, x + offset, y, z + offset).setColor(color[0], color[1], color[2], 1.0F).setUv(0,0).setLight(FULL_LIGHT); + vertexConsumer.addVertex(pose, x + offset, y + offset, z + offset).setColor(color[0], color[1], color[2], 1.0F).setUv(0,0).setLight(FULL_LIGHT); + vertexConsumer.addVertex(pose, x + offset, y + offset, z).setColor(color[0], color[1], color[2], 1.0F).setUv(0,0).setLight(FULL_LIGHT); + vertexConsumer.addVertex(pose, x, y + offset, z).setColor(color[0], color[1], color[2], 1.0F).setUv(0,0).setLight(FULL_LIGHT); + vertexConsumer.addVertex(pose, x, y + offset, z + offset).setColor(color[0], color[1], color[2], 1.0F).setUv(0,0).setLight(FULL_LIGHT); + vertexConsumer.addVertex(pose, x, y + offset, z).setColor(color[0], color[1], color[2], 1.0F).setUv(0,0).setLight(FULL_LIGHT); + vertexConsumer.addVertex(pose, x + offset, y + offset, z).setColor(color[0], color[1], color[2], 1.0F).setUv(0,0).setLight(FULL_LIGHT); + vertexConsumer.addVertex(pose, x + offset, y, z).setColor(color[0], color[1], color[2], 1.0F).setUv(0,0).setLight(FULL_LIGHT); + vertexConsumer.addVertex(pose, x + offset, y, z + offset).setColor(color[0], color[1], color[2], 1.0F).setUv(0,0).setLight(FULL_LIGHT); + vertexConsumer.addVertex(pose, x + offset, y, z).setColor(color[0], color[1], color[2], 1.0F).setUv(0,0).setLight(FULL_LIGHT); + vertexConsumer.addVertex(pose, x + offset, y + offset, z).setColor(color[0], color[1], color[2], 1.0F).setUv(0,0).setLight(FULL_LIGHT); + vertexConsumer.addVertex(pose, x, y, z + offset).setColor(color[0], color[1], color[2], 1.0F).setUv(0,0).setLight(FULL_LIGHT); + vertexConsumer.addVertex(pose, x + offset, y, z + offset).setColor(color[0], color[1], color[2], 1.0F).setUv(0,0).setLight(FULL_LIGHT); + vertexConsumer.addVertex(pose, x, y, z + offset).setColor(color[0], color[1], color[2], 1.0F).setUv(0,0).setLight(FULL_LIGHT); + vertexConsumer.addVertex(pose, x, y + offset, z + offset).setColor(color[0], color[1], color[2], 1.0F).setUv(0,0).setLight(FULL_LIGHT); bufferSource.endBatch(FakeBlockRenderTypes.TOMB_LINES); RenderSystem.enableDepthTest(); } diff --git a/src/main/java/com/lothrazar/library/util/RenderUtil.java b/src/main/java/com/lothrazar/library/util/RenderUtil.java index dfc3813..d1fe0bd 100644 --- a/src/main/java/com/lothrazar/library/util/RenderUtil.java +++ b/src/main/java/com/lothrazar/library/util/RenderUtil.java @@ -50,30 +50,30 @@ public static void createBox(MultiBufferSource.BufferSource bufferSource, PoseSt VertexConsumer vertexConsumer = bufferSource.getBuffer(renderType); poseStack.translate(-cameraPosition.x, -cameraPosition.y, -cameraPosition.z); Matrix4f pose = poseStack.last().pose(); - vertexConsumer.vertex(pose, x, y, z).color(color[0], color[1], color[2], 1.0F).endVertex(); - vertexConsumer.vertex(pose, x + offset, y, z).color(color[0], color[1], color[2], 1.0F).endVertex(); - vertexConsumer.vertex(pose, x, y, z).color(color[0], color[1], color[2], 1.0F).endVertex(); - vertexConsumer.vertex(pose, x, y + offset, z).color(color[0], color[1], color[2], 1.0F).endVertex(); - vertexConsumer.vertex(pose, x, y, z).color(color[0], color[1], color[2], 1.0F).endVertex(); - vertexConsumer.vertex(pose, x, y, z + offset).color(color[0], color[1], color[2], 1.0F).endVertex(); - vertexConsumer.vertex(pose, x + offset, y + offset, z + offset).color(color[0], color[1], color[2], 1.0F).endVertex(); - vertexConsumer.vertex(pose, x, y + offset, z + offset).color(color[0], color[1], color[2], 1.0F).endVertex(); - vertexConsumer.vertex(pose, x + offset, y + offset, z + offset).color(color[0], color[1], color[2], 1.0F).endVertex(); - vertexConsumer.vertex(pose, x + offset, y, z + offset).color(color[0], color[1], color[2], 1.0F).endVertex(); - vertexConsumer.vertex(pose, x + offset, y + offset, z + offset).color(color[0], color[1], color[2], 1.0F).endVertex(); - vertexConsumer.vertex(pose, x + offset, y + offset, z).color(color[0], color[1], color[2], 1.0F).endVertex(); - vertexConsumer.vertex(pose, x, y + offset, z).color(color[0], color[1], color[2], 1.0F).endVertex(); - vertexConsumer.vertex(pose, x, y + offset, z + offset).color(color[0], color[1], color[2], 1.0F).endVertex(); - vertexConsumer.vertex(pose, x, y + offset, z).color(color[0], color[1], color[2], 1.0F).endVertex(); - vertexConsumer.vertex(pose, x + offset, y + offset, z).color(color[0], color[1], color[2], 1.0F).endVertex(); - vertexConsumer.vertex(pose, x + offset, y, z).color(color[0], color[1], color[2], 1.0F).endVertex(); - vertexConsumer.vertex(pose, x + offset, y, z + offset).color(color[0], color[1], color[2], 1.0F).endVertex(); - vertexConsumer.vertex(pose, x + offset, y, z).color(color[0], color[1], color[2], 1.0F).endVertex(); - vertexConsumer.vertex(pose, x + offset, y + offset, z).color(color[0], color[1], color[2], 1.0F).endVertex(); - vertexConsumer.vertex(pose, x, y, z + offset).color(color[0], color[1], color[2], 1.0F).endVertex(); - vertexConsumer.vertex(pose, x + offset, y, z + offset).color(color[0], color[1], color[2], 1.0F).endVertex(); - vertexConsumer.vertex(pose, x, y, z + offset).color(color[0], color[1], color[2], 1.0F).endVertex(); - vertexConsumer.vertex(pose, x, y + offset, z + offset).color(color[0], color[1], color[2], 1.0F).endVertex(); + vertexConsumer.addVertex(pose, x, y, z).setColor(color[0], color[1], color[2], 1.0F); + vertexConsumer.addVertex(pose, x + offset, y, z).setColor(color[0], color[1], color[2], 1.0F); + vertexConsumer.addVertex(pose, x, y, z).setColor(color[0], color[1], color[2], 1.0F); + vertexConsumer.addVertex(pose, x, y + offset, z).setColor(color[0], color[1], color[2], 1.0F); + vertexConsumer.addVertex(pose, x, y, z).setColor(color[0], color[1], color[2], 1.0F); + vertexConsumer.addVertex(pose, x, y, z + offset).setColor(color[0], color[1], color[2], 1.0F); + vertexConsumer.addVertex(pose, x + offset, y + offset, z + offset).setColor(color[0], color[1], color[2], 1.0F); + vertexConsumer.addVertex(pose, x, y + offset, z + offset).setColor(color[0], color[1], color[2], 1.0F); + vertexConsumer.addVertex(pose, x + offset, y + offset, z + offset).setColor(color[0], color[1], color[2], 1.0F); + vertexConsumer.addVertex(pose, x + offset, y, z + offset).setColor(color[0], color[1], color[2], 1.0F); + vertexConsumer.addVertex(pose, x + offset, y + offset, z + offset).setColor(color[0], color[1], color[2], 1.0F); + vertexConsumer.addVertex(pose, x + offset, y + offset, z).setColor(color[0], color[1], color[2], 1.0F); + vertexConsumer.addVertex(pose, x, y + offset, z).setColor(color[0], color[1], color[2], 1.0F); + vertexConsumer.addVertex(pose, x, y + offset, z + offset).setColor(color[0], color[1], color[2], 1.0F); + vertexConsumer.addVertex(pose, x, y + offset, z).setColor(color[0], color[1], color[2], 1.0F); + vertexConsumer.addVertex(pose, x + offset, y + offset, z).setColor(color[0], color[1], color[2], 1.0F); + vertexConsumer.addVertex(pose, x + offset, y, z).setColor(color[0], color[1], color[2], 1.0F); + vertexConsumer.addVertex(pose, x + offset, y, z + offset).setColor(color[0], color[1], color[2], 1.0F); + vertexConsumer.addVertex(pose, x + offset, y, z).setColor(color[0], color[1], color[2], 1.0F); + vertexConsumer.addVertex(pose, x + offset, y + offset, z).setColor(color[0], color[1], color[2], 1.0F); + vertexConsumer.addVertex(pose, x, y, z + offset).setColor(color[0], color[1], color[2], 1.0F); + vertexConsumer.addVertex(pose, x + offset, y, z + offset).setColor(color[0], color[1], color[2], 1.0F); + vertexConsumer.addVertex(pose, x, y, z + offset).setColor(color[0], color[1], color[2], 1.0F); + vertexConsumer.addVertex(pose, x, y + offset, z + offset).setColor(color[0], color[1], color[2], 1.0F); bufferSource.endBatch(renderType); RenderSystem.enableDepthTest(); } diff --git a/src/main/java/com/lothrazar/library/util/SoundUtil.java b/src/main/java/com/lothrazar/library/util/SoundUtil.java index 4fdd636..438f139 100644 --- a/src/main/java/com/lothrazar/library/util/SoundUtil.java +++ b/src/main/java/com/lothrazar/library/util/SoundUtil.java @@ -70,7 +70,7 @@ public static void playSoundFromServer(ServerLevel world, BlockPos pos, SoundEve } public static void playSoundFromServerById(ServerLevel world, BlockPos pos, String sid) { - SoundEvent sound = NeoForgeRegistries.SOUND_EVENTS.getValue(ResourceLocation.parse(sid)); + SoundEvent sound = net.minecraft.core.registries.BuiltInRegistries.SOUND_EVENT.get(ResourceLocation.parse(sid)); if (sound != null) { for (ServerPlayer sp : world.players()) { playSoundFromServer(sp, pos, sound, 1F, 1F); @@ -80,7 +80,7 @@ public static void playSoundFromServerById(ServerLevel world, BlockPos pos, Stri public static void playSoundById(Player player, String sid) { //do the thing - SoundEvent sound = ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation(sid)); + SoundEvent sound = net.minecraft.core.registries.BuiltInRegistries.SOUND_EVENT.get(ResourceLocation.parse(sid)); if (sound != null && player.level().isClientSide) { SoundUtil.playSound(player, sound); } diff --git a/src/main/java/com/lothrazar/library/util/StringParseUtil.java b/src/main/java/com/lothrazar/library/util/StringParseUtil.java index 4693fec..8c6f8b7 100644 --- a/src/main/java/com/lothrazar/library/util/StringParseUtil.java +++ b/src/main/java/com/lothrazar/library/util/StringParseUtil.java @@ -38,7 +38,7 @@ public static String getFluidRatioName(IFluidHandler handler) { var fluid = handler.getFluidInTank(0); String ratio = fluid.getAmount() + "/" + handler.getTankCapacity(0); if (!fluid.isEmpty()) { - ratio += " " + fluid.getDisplayName().getString(); + // ratio += " " + fluid.getDisplayName().getString(); } return ratio; } diff --git a/src/main/java/com/lothrazar/library/util/TagDataUtil.java b/src/main/java/com/lothrazar/library/util/TagDataUtil.java index 3273703..d1be1ac 100644 --- a/src/main/java/com/lothrazar/library/util/TagDataUtil.java +++ b/src/main/java/com/lothrazar/library/util/TagDataUtil.java @@ -15,24 +15,25 @@ public static ItemStack buildNamedPlayerSkull(Player player) { } public static ItemStack buildNamedPlayerSkull(String displayNameString) { - CompoundTag t = new CompoundTag(); - t.putString(SKULLOWNER, displayNameString); - return buildSkullFromTag(t); + ItemStack skull = new ItemStack(Items.PLAYER_HEAD); + skull.set(net.minecraft.core.component.DataComponents.PROFILE, new net.minecraft.world.item.component.ResolvableProfile(new com.mojang.authlib.GameProfile(net.minecraft.Util.NIL_UUID, displayNameString))); + return skull; } public static ItemStack buildSkullFromTag(CompoundTag player) { - ItemStack skull = new ItemStack(Items.PLAYER_HEAD); - skull.setTag(player); - return skull; + if (player.contains(SKULLOWNER)) { + return buildNamedPlayerSkull(player.getString(SKULLOWNER)); + } + return new ItemStack(Items.PLAYER_HEAD); } public static void setItemStackBlockPos(ItemStack item, BlockPos pos) { if (pos == null || item.isEmpty()) { return; } - TagDataUtil.setItemStackNBTVal(item, "xpos", pos.getX()); - TagDataUtil.setItemStackNBTVal(item, "ypos", pos.getY()); - TagDataUtil.setItemStackNBTVal(item, "zpos", pos.getZ()); + setItemStackNBTVal(item, "xpos", pos.getX()); + setItemStackNBTVal(item, "ypos", pos.getY()); + setItemStackNBTVal(item, "zpos", pos.getZ()); } public static void putBlockPos(CompoundTag tag, BlockPos pos) { @@ -42,10 +43,10 @@ public static void putBlockPos(CompoundTag tag, BlockPos pos) { } public static BlockPos getItemStackBlockPos(ItemStack item) { - if (item.isEmpty() || item.getTag() == null || !item.getTag().contains("xpos")) { + CompoundTag tag = getItemStackNBT(item); + if (!tag.contains("xpos")) { return null; } - CompoundTag tag = item.getOrCreateTag(); return getBlockPos(tag); } @@ -57,10 +58,12 @@ public static void setItemStackNBTVal(ItemStack item, String prop, int value) { if (item.isEmpty()) { return; } - item.getOrCreateTag().putInt(prop, value); + CompoundTag tag = getItemStackNBT(item); + tag.putInt(prop, value); + item.set(com.lothrazar.library.registry.FlibDataComponents.CUSTOM_NBT_BUCKET.get(), tag); } public static CompoundTag getItemStackNBT(ItemStack held) { - return held.getOrCreateTag(); + return held.getOrDefault(com.lothrazar.library.registry.FlibDataComponents.CUSTOM_NBT_BUCKET.get(), new CompoundTag()); } } diff --git a/src/main/resources/META-INF/neoforge.mods.toml b/src/main/resources/META-INF/neoforge.mods.toml index 2f2954d..081c3fe 100644 --- a/src/main/resources/META-INF/neoforge.mods.toml +++ b/src/main/resources/META-INF/neoforge.mods.toml @@ -42,7 +42,7 @@ Future Library. Empowers many forge mods. by Lothrazar # Does this dependency have to exist - if not, ordering below must be specified mandatory=true #mandatory # The version range of the dependency - versionRange="[47.1,)" #mandatory + versionRange="[21.1,)" #mandatory # An ordering relationship for the dependency - BEFORE or AFTER required if the relationship is not mandatory ordering="NONE" # Side this dependency is applied on - BOTH, CLIENT or SERVER From e6f8ebc23570204acf071402740f5bbd839132f4 Mon Sep 17 00:00:00 2001 From: Stanislav <505258@niuitmo.ru> Date: Fri, 24 Apr 2026 03:23:27 +0300 Subject: [PATCH 3/3] Add NeoForge 1.21.1 disclaimers to README --- .github/README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/README.md b/.github/README.md index 10c5d23..26eea60 100644 --- a/.github/README.md +++ b/.github/README.md @@ -2,6 +2,12 @@ A Library/core mod built on the Minecraft & the Forge API [https://files.minecraftforge.net/](https://files.minecraftforge.net) +> [!WARNING] +> **Disclaimer:** This NeoForge 1.21.1 port was developed and compiled with the assistance of an AI agent. While the library successfully builds and runs alongside dependent mods, it has **not** been thoroughly tested across all possible edge cases. Proceed with caution. + +## ⚠️ 1.21.1 Port Notes +This branch is specifically updated for **NeoForge 1.21.1** (tested on `21.1.115+`). +*(Note: This library will **NOT** work on `1.21.2+` or `1.21.4` due to major core API and Data Component changes introduced by Mojang in newer versions)* [![](http://cf.way2muchnoise.eu/661261.svg)](https://www.curseforge.com/minecraft/mc-mods/flib) [![](http://cf.way2muchnoise.eu/versions/661261.svg)](https://www.curseforge.com/minecraft/mc-mods/flib)