From 2a6a1b9bbee793838884ded734c183037574018e Mon Sep 17 00:00:00 2001 From: westernat Date: Mon, 4 Aug 2025 21:29:03 +0800 Subject: [PATCH 01/61] =?UTF-8?q?maven=E4=BE=8B=E5=AD=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gradle.properties | 1 + 1 file changed, 1 insertion(+) diff --git a/gradle.properties b/gradle.properties index bb2dbbf..7e18829 100644 --- a/gradle.properties +++ b/gradle.properties @@ -29,6 +29,7 @@ mod_name=Confluence Magic Lib # The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default. mod_license=MIT # The mod version. See https://semver.org/ +###### remove '-SNAPSHOT' when merge to main branch ###### mod_version=0.0.2-SNAPSHOT # The group ID for the mod. It is only important when publishing as an artifact to a Maven repository. # This should match the base package used for the mod sources. From 69be8f4e103baa0dcabc5cdaa13f6fc443db05d2 Mon Sep 17 00:00:00 2001 From: westernat Date: Mon, 4 Aug 2025 22:02:40 +0800 Subject: [PATCH 02/61] =?UTF-8?q?=E4=BF=AElib=E4=B8=8D=E8=83=BD=E5=8D=95?= =?UTF-8?q?=E7=8B=AC=E6=9F=93=E8=89=B2=E7=A8=80=E6=9C=89=E5=BA=A6=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lib/client/event/LibGameEvents.java | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/confluence/lib/client/event/LibGameEvents.java b/src/main/java/org/confluence/lib/client/event/LibGameEvents.java index cb5e2f7..62baf39 100644 --- a/src/main/java/org/confluence/lib/client/event/LibGameEvents.java +++ b/src/main/java/org/confluence/lib/client/event/LibGameEvents.java @@ -3,18 +3,40 @@ import com.mojang.datafixers.util.Either; import net.minecraft.ChatFormatting; import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.FormattedText; +import net.minecraft.world.inventory.tooltip.TooltipComponent; +import net.minecraft.world.item.ItemStack; import net.neoforged.api.distmarker.Dist; +import net.neoforged.bus.api.EventPriority; import net.neoforged.bus.api.SubscribeEvent; import net.neoforged.fml.common.EventBusSubscriber; import net.neoforged.neoforge.client.event.RenderTooltipEvent; import org.confluence.lib.ConfluenceMagicLib; import org.confluence.lib.common.LibTags; +import org.confluence.lib.common.component.ModRarity; + +import java.util.List; +import java.util.Optional; @EventBusSubscriber(modid = ConfluenceMagicLib.LIB_ID, bus = EventBusSubscriber.Bus.GAME, value = Dist.CLIENT) public final class LibGameEvents { - @SubscribeEvent + @SubscribeEvent(priority = EventPriority.HIGHEST, receiveCanceled = true) public static void renderTooltip$GatherComponents(RenderTooltipEvent.GatherComponents event) { - if (event.getItemStack().isEmpty() || !event.getItemStack().is(LibTags.Items.WIP)) return; - event.getTooltipElements().add(1, Either.left(Component.translatable("tooltip.confluence.work_in_progress").withStyle(ChatFormatting.RED))); + ItemStack itemStack = event.getItemStack(); + if (itemStack.isEmpty()) return; + + List> tooltipElements = event.getTooltipElements(); + if (tooltipElements.isEmpty()) return; + Optional displayName = tooltipElements.getFirst().left(); + if (displayName.isPresent() && displayName.get() instanceof Component component) { + ModRarity rarity = ModRarity.getRarity(itemStack); + if (rarity != null) { + tooltipElements.set(0, Either.left(component.copy().withColor(rarity.color()))); + } + } + + if (itemStack.is(LibTags.Items.WIP)) { + event.getTooltipElements().add(1, Either.left(Component.translatable("tooltip.confluence.work_in_progress").withStyle(ChatFormatting.RED))); + } } } From 1554bb975a46f5e696948be3faef97c77b31e1dc Mon Sep 17 00:00:00 2001 From: westernat Date: Mon, 4 Aug 2025 22:52:07 +0800 Subject: [PATCH 03/61] =?UTF-8?q?=E6=B8=90=E5=8F=98=E7=A8=80=E6=9C=89?= =?UTF-8?q?=E5=BA=A6=E7=9A=84=E6=9B=B4=E6=96=B0=E8=BD=AC=E7=A7=BB=E5=88=B0?= =?UTF-8?q?lib?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lib/client/event/LibGameEvents.java | 11 +- .../client/particle/CrossDustParticle.java | 187 +++++++++--------- .../confluence/lib/color/GlobalColors.java | 2 +- .../lib/common/component/ModRarity.java | 8 +- .../lib/common/component/NbtComponent.java | 10 + .../lib/common/component/ToolMode.java | 10 + 6 files changed, 129 insertions(+), 99 deletions(-) diff --git a/src/main/java/org/confluence/lib/client/event/LibGameEvents.java b/src/main/java/org/confluence/lib/client/event/LibGameEvents.java index 62baf39..bccc919 100644 --- a/src/main/java/org/confluence/lib/client/event/LibGameEvents.java +++ b/src/main/java/org/confluence/lib/client/event/LibGameEvents.java @@ -10,8 +10,11 @@ import net.neoforged.bus.api.EventPriority; import net.neoforged.bus.api.SubscribeEvent; import net.neoforged.fml.common.EventBusSubscriber; +import net.neoforged.neoforge.client.event.ClientTickEvent; import net.neoforged.neoforge.client.event.RenderTooltipEvent; import org.confluence.lib.ConfluenceMagicLib; +import org.confluence.lib.client.animate.ExpertColorAnimation; +import org.confluence.lib.client.animate.MasterColorAnimation; import org.confluence.lib.common.LibTags; import org.confluence.lib.common.component.ModRarity; @@ -20,7 +23,13 @@ @EventBusSubscriber(modid = ConfluenceMagicLib.LIB_ID, bus = EventBusSubscriber.Bus.GAME, value = Dist.CLIENT) public final class LibGameEvents { - @SubscribeEvent(priority = EventPriority.HIGHEST, receiveCanceled = true) + @SubscribeEvent + public static void clientTick$Post(ClientTickEvent.Pre event) { + ExpertColorAnimation.INSTANCE.updateColor(); + MasterColorAnimation.INSTANCE.updateColor(); + } + + @SubscribeEvent(priority = EventPriority.HIGHEST) public static void renderTooltip$GatherComponents(RenderTooltipEvent.GatherComponents event) { ItemStack itemStack = event.getItemStack(); if (itemStack.isEmpty()) return; diff --git a/src/main/java/org/confluence/lib/client/particle/CrossDustParticle.java b/src/main/java/org/confluence/lib/client/particle/CrossDustParticle.java index f66b51e..f73b23f 100644 --- a/src/main/java/org/confluence/lib/client/particle/CrossDustParticle.java +++ b/src/main/java/org/confluence/lib/client/particle/CrossDustParticle.java @@ -1,17 +1,14 @@ package org.confluence.lib.client.particle; -import com.mojang.blaze3d.vertex.VertexConsumer; -import net.minecraft.client.Camera; import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.client.particle.*; -import net.minecraft.util.Mth; import org.confluence.lib.common.particle.CrossDustParticleOptions; -import org.confluence.lib.util.LibUtils; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.annotation.ParametersAreNonnullByDefault; +// fixme @ParametersAreNonnullByDefault public class CrossDustParticle extends TextureSheetParticle { protected final SpriteSet sprites; @@ -26,99 +23,99 @@ public CrossDustParticle(ClientLevel level, double x, double y, double z, CrossD super(level, x, y, z); this.sprites = sprites; this.options = options; - this.lifetime = options.getLifetime(); - this.gravity = options.isNoGravity() ? 0 : 0.7f; - this.hasPhysics = !options.isNoPhysics(); - this.quadSize = 0.1f; - setScale(options.isPulse() ? 0 : options.getScale()); - quadSizeOld = quadSize; - xd = options.getVelocity().x; - yd = options.getVelocity().y; - zd = options.getVelocity().z; - age = 1; +// this.lifetime = options.getLifetime(); +// this.gravity = options.isNoGravity() ? 0 : 0.7f; +// this.hasPhysics = !options.isNoPhysics(); +// this.quadSize = 0.1f; +// setScale(options.isPulse() ? 0 : options.getScale()); +// quadSizeOld = quadSize; +// xd = options.getVelocity().x; +// yd = options.getVelocity().y; +// zd = options.getVelocity().z; +// age = 1; } - @Override - public void render(VertexConsumer buffer, Camera renderInfo, float partialTicks) { - useCenterSprite(); - super.render(buffer, renderInfo, partialTicks); - useEdgeSprite(); - super.render(buffer, renderInfo, partialTicks); - } - - @Override - public void tick() { - float lastProgress = ((float) age - 1) / lifetime; - float progress = (float) age / lifetime; - if (options.isNoGravity()) { - accelOld = accel; - accel = LibUtils.cubicBezier(progress, options.getSpeedCurve().x, options.getSpeedCurve().y, options.getSpeedCurve().z, options.getSpeedCurve().w); - float k = (accel - accelOld) / (progress - lastProgress); - xd = options.getVelocity().x * k; - yd = options.getVelocity().y * k; - zd = options.getVelocity().z * k; - } - oRoll = roll; - rollDeltaOld = rollDelta; - rollDelta = LibUtils.cubicBezier(progress, options.getRollCurve().x, options.getRollCurve().y, options.getRollCurve().z, options.getRollCurve().w); - float k = (rollDelta - rollDeltaOld) / (progress - lastProgress); - roll += options.getRoll() * k * Mth.DEG_TO_RAD; - - quadSizeOld = quadSize; - if (options.isPulse()) { - if (progress < 0.5f) { - setScale(options.getScale() * progress * 2); - }else{ - setScale(options.getScale() * (1 - progress) * 2); - } - }else{ - setScale(options.getScale() * (1 - progress)); - } - - super.tick(); - } - - public void setScale(float scale) { - quadSize = scale * 0.1f; - setSize(scale * 0.2f, scale * 0.2f); - } - - @Override - public float getQuadSize(float partialTicks) { - return Mth.lerp(partialTicks, quadSizeOld, quadSize); - } - - protected void useCenterSprite() { - setSprite(sprites.get(options.isLarge() ? 3 : 1, 4)); - float a = (options.getCenterColor() >>> 24 & 0xff) / 255f; - float r = (options.getCenterColor() >>> 16 & 0xff) / 255f; - float g = (options.getCenterColor() >>> 8 & 0xff) / 255f; - float b = (options.getCenterColor() & 0xff) / 255f; - this.alpha = a; - this.rCol = r; - this.gCol = g; - this.bCol = b; - } - - protected void useEdgeSprite() { - setSprite(sprites.get(options.isLarge() ? 4 : 2, 4)); - float a = (options.getEdgeColor() >>> 24 & 0xff) / 255f; - float r = (options.getEdgeColor() >>> 16 & 0xff) / 255f; - float g = (options.getEdgeColor() >>> 8 & 0xff) / 255f; - float b = (options.getEdgeColor() & 0xff) / 255f; - this.alpha = a; - this.rCol = r; - this.gCol = g; - this.bCol = b; - } - - @Override - protected int getLightColor(float partialTick) { - if (options.isFullBrightness()) { - return 15 << 20 | 15 << 4; - } - return super.getLightColor(partialTick); - } +// @Override +// public void render(VertexConsumer buffer, Camera renderInfo, float partialTicks) { +// useCenterSprite(); +// super.render(buffer, renderInfo, partialTicks); +// useEdgeSprite(); +// super.render(buffer, renderInfo, partialTicks); +// } +// +// @Override +// public void tick() { +// float lastProgress = ((float) age - 1) / lifetime; +// float progress = (float) age / lifetime; +// if (options.isNoGravity()) { +// accelOld = accel; +// accel = LibUtils.cubicBezier(progress, options.getSpeedCurve().x, options.getSpeedCurve().y, options.getSpeedCurve().z, options.getSpeedCurve().w); +// float k = (accel - accelOld) / (progress - lastProgress); +// xd = options.getVelocity().x * k; +// yd = options.getVelocity().y * k; +// zd = options.getVelocity().z * k; +// } +// oRoll = roll; +// rollDeltaOld = rollDelta; +// rollDelta = LibUtils.cubicBezier(progress, options.getRollCurve().x, options.getRollCurve().y, options.getRollCurve().z, options.getRollCurve().w); +// float k = (rollDelta - rollDeltaOld) / (progress - lastProgress); +// roll += options.getRoll() * k * Mth.DEG_TO_RAD; +// +// quadSizeOld = quadSize; +// if (options.isPulse()) { +// if (progress < 0.5f) { +// setScale(options.getScale() * progress * 2); +// }else{ +// setScale(options.getScale() * (1 - progress) * 2); +// } +// }else{ +// setScale(options.getScale() * (1 - progress)); +// } +// +// super.tick(); +// } +// +// public void setScale(float scale) { +// quadSize = scale * 0.1f; +// setSize(scale * 0.2f, scale * 0.2f); +// } +// +// @Override +// public float getQuadSize(float partialTicks) { +// return Mth.lerp(partialTicks, quadSizeOld, quadSize); +// } +// +// protected void useCenterSprite() { +// setSprite(sprites.get(options.isLarge() ? 3 : 1, 4)); +// float a = (options.getCenterColor() >>> 24 & 0xff) / 255f; +// float r = (options.getCenterColor() >>> 16 & 0xff) / 255f; +// float g = (options.getCenterColor() >>> 8 & 0xff) / 255f; +// float b = (options.getCenterColor() & 0xff) / 255f; +// this.alpha = a; +// this.rCol = r; +// this.gCol = g; +// this.bCol = b; +// } +// +// protected void useEdgeSprite() { +// setSprite(sprites.get(options.isLarge() ? 4 : 2, 4)); +// float a = (options.getEdgeColor() >>> 24 & 0xff) / 255f; +// float r = (options.getEdgeColor() >>> 16 & 0xff) / 255f; +// float g = (options.getEdgeColor() >>> 8 & 0xff) / 255f; +// float b = (options.getEdgeColor() & 0xff) / 255f; +// this.alpha = a; +// this.rCol = r; +// this.gCol = g; +// this.bCol = b; +// } +// +// @Override +// protected int getLightColor(float partialTick) { +// if (options.isFullBrightness()) { +// return 15 << 20 | 15 << 4; +// } +// return super.getLightColor(partialTick); +// } @Override @NotNull diff --git a/src/main/java/org/confluence/lib/color/GlobalColors.java b/src/main/java/org/confluence/lib/color/GlobalColors.java index 2c87665..ac839c3 100644 --- a/src/main/java/org/confluence/lib/color/GlobalColors.java +++ b/src/main/java/org/confluence/lib/color/GlobalColors.java @@ -1,6 +1,6 @@ package org.confluence.lib.color; -public class GlobalColors { +public final class GlobalColors { public static final IntegerRGB NPC_ARRIVED = IntegerRGB.of(0x327dff); public static final IntegerRGB NPC_SLAIN = IntegerRGB.of(0xff1919); public static final IntegerRGB MESSAGE = IntegerRGB.of(0x32ff82); diff --git a/src/main/java/org/confluence/lib/common/component/ModRarity.java b/src/main/java/org/confluence/lib/common/component/ModRarity.java index 94d6cd5..d004f4d 100644 --- a/src/main/java/org/confluence/lib/common/component/ModRarity.java +++ b/src/main/java/org/confluence/lib/common/component/ModRarity.java @@ -86,8 +86,12 @@ public StreamCodec streamCodec() { @Override public boolean equals(Object o) { - if (o == this) return true; - return o instanceof ModRarity rarity && rarity.color == color && rarity.name.equals(name); + return o == this || (o instanceof ModRarity(String name1, int color1) && color == color1 && name.equals(name1)); + } + + @Override + public int hashCode() { + return 31 * name.hashCode() + color; } @Override diff --git a/src/main/java/org/confluence/lib/common/component/NbtComponent.java b/src/main/java/org/confluence/lib/common/component/NbtComponent.java index 3616eb8..55f83e8 100644 --- a/src/main/java/org/confluence/lib/common/component/NbtComponent.java +++ b/src/main/java/org/confluence/lib/common/component/NbtComponent.java @@ -23,4 +23,14 @@ public record NbtComponent(CompoundTag nbt) implements DataComponentType streamCodec() { return STREAM_CODEC; } + + @Override + public boolean equals(Object o) { + return o == this || (o instanceof NbtComponent(CompoundTag nbt1) && nbt.equals(nbt1)); + } + + @Override + public int hashCode() { + return nbt.hashCode(); + } } diff --git a/src/main/java/org/confluence/lib/common/component/ToolMode.java b/src/main/java/org/confluence/lib/common/component/ToolMode.java index 087ec3c..bdd7f3f 100644 --- a/src/main/java/org/confluence/lib/common/component/ToolMode.java +++ b/src/main/java/org/confluence/lib/common/component/ToolMode.java @@ -25,4 +25,14 @@ public Codec codec() { public StreamCodec streamCodec() { return STREAM_CODEC; } + + @Override + public boolean equals(Object o) { + return o == this || (o instanceof ToolMode(int mode1) && mode == mode1); + } + + @Override + public int hashCode() { + return mode; + } } From cabb7138b9c83f3b558ff4e91ef215b053a053ba Mon Sep 17 00:00:00 2001 From: westernat Date: Mon, 4 Aug 2025 23:27:36 +0800 Subject: [PATCH 04/61] 0.0.2a --- gradle.properties | 2 +- .../client/particle/CrossDustParticle.java | 183 +++++++++--------- 2 files changed, 92 insertions(+), 93 deletions(-) diff --git a/gradle.properties b/gradle.properties index 7e18829..e30e387 100644 --- a/gradle.properties +++ b/gradle.properties @@ -30,7 +30,7 @@ mod_name=Confluence Magic Lib mod_license=MIT # The mod version. See https://semver.org/ ###### remove '-SNAPSHOT' when merge to main branch ###### -mod_version=0.0.2-SNAPSHOT +mod_version=0.0.2a-SNAPSHOT # The group ID for the mod. It is only important when publishing as an artifact to a Maven repository. # This should match the base package used for the mod sources. # See https://maven.apache.org/guides/mini/guide-naming-conventions.html diff --git a/src/main/java/org/confluence/lib/client/particle/CrossDustParticle.java b/src/main/java/org/confluence/lib/client/particle/CrossDustParticle.java index f73b23f..37edd83 100644 --- a/src/main/java/org/confluence/lib/client/particle/CrossDustParticle.java +++ b/src/main/java/org/confluence/lib/client/particle/CrossDustParticle.java @@ -8,7 +8,6 @@ import javax.annotation.ParametersAreNonnullByDefault; -// fixme @ParametersAreNonnullByDefault public class CrossDustParticle extends TextureSheetParticle { protected final SpriteSet sprites; @@ -23,99 +22,99 @@ public CrossDustParticle(ClientLevel level, double x, double y, double z, CrossD super(level, x, y, z); this.sprites = sprites; this.options = options; -// this.lifetime = options.getLifetime(); -// this.gravity = options.isNoGravity() ? 0 : 0.7f; -// this.hasPhysics = !options.isNoPhysics(); -// this.quadSize = 0.1f; -// setScale(options.isPulse() ? 0 : options.getScale()); -// quadSizeOld = quadSize; -// xd = options.getVelocity().x; -// yd = options.getVelocity().y; -// zd = options.getVelocity().z; -// age = 1; + this.lifetime = options.getLifetime(); + this.gravity = options.isNoGravity() ? 0 : 0.7f; + this.hasPhysics = !options.isNoPhysics(); + this.quadSize = 0.1f; + setScale(options.isPulse() ? 0 : options.getScale()); + quadSizeOld = quadSize; + xd = options.getVelocity().x; + yd = options.getVelocity().y; + zd = options.getVelocity().z; + age = 1; } -// @Override -// public void render(VertexConsumer buffer, Camera renderInfo, float partialTicks) { -// useCenterSprite(); -// super.render(buffer, renderInfo, partialTicks); -// useEdgeSprite(); -// super.render(buffer, renderInfo, partialTicks); -// } -// -// @Override -// public void tick() { -// float lastProgress = ((float) age - 1) / lifetime; -// float progress = (float) age / lifetime; -// if (options.isNoGravity()) { -// accelOld = accel; -// accel = LibUtils.cubicBezier(progress, options.getSpeedCurve().x, options.getSpeedCurve().y, options.getSpeedCurve().z, options.getSpeedCurve().w); -// float k = (accel - accelOld) / (progress - lastProgress); -// xd = options.getVelocity().x * k; -// yd = options.getVelocity().y * k; -// zd = options.getVelocity().z * k; -// } -// oRoll = roll; -// rollDeltaOld = rollDelta; -// rollDelta = LibUtils.cubicBezier(progress, options.getRollCurve().x, options.getRollCurve().y, options.getRollCurve().z, options.getRollCurve().w); -// float k = (rollDelta - rollDeltaOld) / (progress - lastProgress); -// roll += options.getRoll() * k * Mth.DEG_TO_RAD; -// -// quadSizeOld = quadSize; -// if (options.isPulse()) { -// if (progress < 0.5f) { -// setScale(options.getScale() * progress * 2); -// }else{ -// setScale(options.getScale() * (1 - progress) * 2); -// } -// }else{ -// setScale(options.getScale() * (1 - progress)); -// } -// -// super.tick(); -// } -// -// public void setScale(float scale) { -// quadSize = scale * 0.1f; -// setSize(scale * 0.2f, scale * 0.2f); -// } -// -// @Override -// public float getQuadSize(float partialTicks) { -// return Mth.lerp(partialTicks, quadSizeOld, quadSize); -// } -// -// protected void useCenterSprite() { -// setSprite(sprites.get(options.isLarge() ? 3 : 1, 4)); -// float a = (options.getCenterColor() >>> 24 & 0xff) / 255f; -// float r = (options.getCenterColor() >>> 16 & 0xff) / 255f; -// float g = (options.getCenterColor() >>> 8 & 0xff) / 255f; -// float b = (options.getCenterColor() & 0xff) / 255f; -// this.alpha = a; -// this.rCol = r; -// this.gCol = g; -// this.bCol = b; -// } -// -// protected void useEdgeSprite() { -// setSprite(sprites.get(options.isLarge() ? 4 : 2, 4)); -// float a = (options.getEdgeColor() >>> 24 & 0xff) / 255f; -// float r = (options.getEdgeColor() >>> 16 & 0xff) / 255f; -// float g = (options.getEdgeColor() >>> 8 & 0xff) / 255f; -// float b = (options.getEdgeColor() & 0xff) / 255f; -// this.alpha = a; -// this.rCol = r; -// this.gCol = g; -// this.bCol = b; -// } -// -// @Override -// protected int getLightColor(float partialTick) { -// if (options.isFullBrightness()) { -// return 15 << 20 | 15 << 4; -// } -// return super.getLightColor(partialTick); -// } + @Override + public void render(VertexConsumer buffer, Camera renderInfo, float partialTicks) { + useCenterSprite(); + super.render(buffer, renderInfo, partialTicks); + useEdgeSprite(); + super.render(buffer, renderInfo, partialTicks); + } + + @Override + public void tick() { + float lastProgress = ((float) age - 1) / lifetime; + float progress = (float) age / lifetime; + if (options.isNoGravity()) { + accelOld = accel; + accel = LibUtils.cubicBezier(progress, options.getSpeedCurve().x, options.getSpeedCurve().y, options.getSpeedCurve().z, options.getSpeedCurve().w); + float k = (accel - accelOld) / (progress - lastProgress); + xd = options.getVelocity().x * k; + yd = options.getVelocity().y * k; + zd = options.getVelocity().z * k; + } + oRoll = roll; + rollDeltaOld = rollDelta; + rollDelta = LibUtils.cubicBezier(progress, options.getRollCurve().x, options.getRollCurve().y, options.getRollCurve().z, options.getRollCurve().w); + float k = (rollDelta - rollDeltaOld) / (progress - lastProgress); + roll += options.getRoll() * k * Mth.DEG_TO_RAD; + + quadSizeOld = quadSize; + if (options.isPulse()) { + if (progress < 0.5f) { + setScale(options.getScale() * progress * 2); + } else { + setScale(options.getScale() * (1 - progress) * 2); + } + } else { + setScale(options.getScale() * (1 - progress)); + } + + super.tick(); + } + + public void setScale(float scale) { + quadSize = scale * 0.1f; + setSize(scale * 0.2f, scale * 0.2f); + } + + @Override + public float getQuadSize(float partialTicks) { + return Mth.lerp(partialTicks, quadSizeOld, quadSize); + } + + protected void useCenterSprite() { + setSprite(sprites.get(options.isLarge() ? 3 : 1, 4)); + float a = (options.getCenterColor() >>> 24 & 0xff) / 255f; + float r = (options.getCenterColor() >>> 16 & 0xff) / 255f; + float g = (options.getCenterColor() >>> 8 & 0xff) / 255f; + float b = (options.getCenterColor() & 0xff) / 255f; + this.alpha = a; + this.rCol = r; + this.gCol = g; + this.bCol = b; + } + + protected void useEdgeSprite() { + setSprite(sprites.get(options.isLarge() ? 4 : 2, 4)); + float a = (options.getEdgeColor() >>> 24 & 0xff) / 255f; + float r = (options.getEdgeColor() >>> 16 & 0xff) / 255f; + float g = (options.getEdgeColor() >>> 8 & 0xff) / 255f; + float b = (options.getEdgeColor() & 0xff) / 255f; + this.alpha = a; + this.rCol = r; + this.gCol = g; + this.bCol = b; + } + + @Override + protected int getLightColor(float partialTick) { + if (options.isFullBrightness()) { + return 15 << 20 | 15 << 4; + } + return super.getLightColor(partialTick); + } @Override @NotNull From 4fe6815fc4abfe88ec65638bdd75632b77207c42 Mon Sep 17 00:00:00 2001 From: westernat Date: Mon, 4 Aug 2025 23:31:05 +0800 Subject: [PATCH 05/61] =?UTF-8?q?=E6=B3=A8=E9=87=8A=E6=8E=89lombok?= =?UTF-8?q?=E7=94=9F=E6=88=90=E7=9A=84=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../client/particle/CrossDustParticle.java | 183 +++++++++--------- 1 file changed, 92 insertions(+), 91 deletions(-) diff --git a/src/main/java/org/confluence/lib/client/particle/CrossDustParticle.java b/src/main/java/org/confluence/lib/client/particle/CrossDustParticle.java index 37edd83..ce3b535 100644 --- a/src/main/java/org/confluence/lib/client/particle/CrossDustParticle.java +++ b/src/main/java/org/confluence/lib/client/particle/CrossDustParticle.java @@ -8,6 +8,7 @@ import javax.annotation.ParametersAreNonnullByDefault; +// fixme @ParametersAreNonnullByDefault public class CrossDustParticle extends TextureSheetParticle { protected final SpriteSet sprites; @@ -22,99 +23,99 @@ public CrossDustParticle(ClientLevel level, double x, double y, double z, CrossD super(level, x, y, z); this.sprites = sprites; this.options = options; - this.lifetime = options.getLifetime(); - this.gravity = options.isNoGravity() ? 0 : 0.7f; - this.hasPhysics = !options.isNoPhysics(); - this.quadSize = 0.1f; - setScale(options.isPulse() ? 0 : options.getScale()); - quadSizeOld = quadSize; - xd = options.getVelocity().x; - yd = options.getVelocity().y; - zd = options.getVelocity().z; - age = 1; +// this.lifetime = options.getLifetime(); +// this.gravity = options.isNoGravity() ? 0 : 0.7f; +// this.hasPhysics = !options.isNoPhysics(); +// this.quadSize = 0.1f; +// setScale(options.isPulse() ? 0 : options.getScale()); +// quadSizeOld = quadSize; +// xd = options.getVelocity().x; +// yd = options.getVelocity().y; +// zd = options.getVelocity().z; +// age = 1; } - @Override - public void render(VertexConsumer buffer, Camera renderInfo, float partialTicks) { - useCenterSprite(); - super.render(buffer, renderInfo, partialTicks); - useEdgeSprite(); - super.render(buffer, renderInfo, partialTicks); - } - - @Override - public void tick() { - float lastProgress = ((float) age - 1) / lifetime; - float progress = (float) age / lifetime; - if (options.isNoGravity()) { - accelOld = accel; - accel = LibUtils.cubicBezier(progress, options.getSpeedCurve().x, options.getSpeedCurve().y, options.getSpeedCurve().z, options.getSpeedCurve().w); - float k = (accel - accelOld) / (progress - lastProgress); - xd = options.getVelocity().x * k; - yd = options.getVelocity().y * k; - zd = options.getVelocity().z * k; - } - oRoll = roll; - rollDeltaOld = rollDelta; - rollDelta = LibUtils.cubicBezier(progress, options.getRollCurve().x, options.getRollCurve().y, options.getRollCurve().z, options.getRollCurve().w); - float k = (rollDelta - rollDeltaOld) / (progress - lastProgress); - roll += options.getRoll() * k * Mth.DEG_TO_RAD; - - quadSizeOld = quadSize; - if (options.isPulse()) { - if (progress < 0.5f) { - setScale(options.getScale() * progress * 2); - } else { - setScale(options.getScale() * (1 - progress) * 2); - } - } else { - setScale(options.getScale() * (1 - progress)); - } - - super.tick(); - } - - public void setScale(float scale) { - quadSize = scale * 0.1f; - setSize(scale * 0.2f, scale * 0.2f); - } - - @Override - public float getQuadSize(float partialTicks) { - return Mth.lerp(partialTicks, quadSizeOld, quadSize); - } - - protected void useCenterSprite() { - setSprite(sprites.get(options.isLarge() ? 3 : 1, 4)); - float a = (options.getCenterColor() >>> 24 & 0xff) / 255f; - float r = (options.getCenterColor() >>> 16 & 0xff) / 255f; - float g = (options.getCenterColor() >>> 8 & 0xff) / 255f; - float b = (options.getCenterColor() & 0xff) / 255f; - this.alpha = a; - this.rCol = r; - this.gCol = g; - this.bCol = b; - } - - protected void useEdgeSprite() { - setSprite(sprites.get(options.isLarge() ? 4 : 2, 4)); - float a = (options.getEdgeColor() >>> 24 & 0xff) / 255f; - float r = (options.getEdgeColor() >>> 16 & 0xff) / 255f; - float g = (options.getEdgeColor() >>> 8 & 0xff) / 255f; - float b = (options.getEdgeColor() & 0xff) / 255f; - this.alpha = a; - this.rCol = r; - this.gCol = g; - this.bCol = b; - } - - @Override - protected int getLightColor(float partialTick) { - if (options.isFullBrightness()) { - return 15 << 20 | 15 << 4; - } - return super.getLightColor(partialTick); - } +// @Override +// public void render(VertexConsumer buffer, Camera renderInfo, float partialTicks) { +// useCenterSprite(); +// super.render(buffer, renderInfo, partialTicks); +// useEdgeSprite(); +// super.render(buffer, renderInfo, partialTicks); +// } +// +// @Override +// public void tick() { +// float lastProgress = ((float) age - 1) / lifetime; +// float progress = (float) age / lifetime; +// if (options.isNoGravity()) { +// accelOld = accel; +// accel = LibUtils.cubicBezier(progress, options.getSpeedCurve().x, options.getSpeedCurve().y, options.getSpeedCurve().z, options.getSpeedCurve().w); +// float k = (accel - accelOld) / (progress - lastProgress); +// xd = options.getVelocity().x * k; +// yd = options.getVelocity().y * k; +// zd = options.getVelocity().z * k; +// } +// oRoll = roll; +// rollDeltaOld = rollDelta; +// rollDelta = LibUtils.cubicBezier(progress, options.getRollCurve().x, options.getRollCurve().y, options.getRollCurve().z, options.getRollCurve().w); +// float k = (rollDelta - rollDeltaOld) / (progress - lastProgress); +// roll += options.getRoll() * k * Mth.DEG_TO_RAD; +// +// quadSizeOld = quadSize; +// if (options.isPulse()) { +// if (progress < 0.5f) { +// setScale(options.getScale() * progress * 2); +// } else { +// setScale(options.getScale() * (1 - progress) * 2); +// } +// } else { +// setScale(options.getScale() * (1 - progress)); +// } +// +// super.tick(); +// } +// +// public void setScale(float scale) { +// quadSize = scale * 0.1f; +// setSize(scale * 0.2f, scale * 0.2f); +// } +// +// @Override +// public float getQuadSize(float partialTicks) { +// return Mth.lerp(partialTicks, quadSizeOld, quadSize); +// } +// +// protected void useCenterSprite() { +// setSprite(sprites.get(options.isLarge() ? 3 : 1, 4)); +// float a = (options.getCenterColor() >>> 24 & 0xff) / 255f; +// float r = (options.getCenterColor() >>> 16 & 0xff) / 255f; +// float g = (options.getCenterColor() >>> 8 & 0xff) / 255f; +// float b = (options.getCenterColor() & 0xff) / 255f; +// this.alpha = a; +// this.rCol = r; +// this.gCol = g; +// this.bCol = b; +// } +// +// protected void useEdgeSprite() { +// setSprite(sprites.get(options.isLarge() ? 4 : 2, 4)); +// float a = (options.getEdgeColor() >>> 24 & 0xff) / 255f; +// float r = (options.getEdgeColor() >>> 16 & 0xff) / 255f; +// float g = (options.getEdgeColor() >>> 8 & 0xff) / 255f; +// float b = (options.getEdgeColor() & 0xff) / 255f; +// this.alpha = a; +// this.rCol = r; +// this.gCol = g; +// this.bCol = b; +// } +// +// @Override +// protected int getLightColor(float partialTick) { +// if (options.isFullBrightness()) { +// return 15 << 20 | 15 << 4; +// } +// return super.getLightColor(partialTick); +// } @Override @NotNull From b00c771c7e051ac1e250671f887217ea1806b020 Mon Sep 17 00:00:00 2001 From: westernat Date: Wed, 6 Aug 2025 13:09:07 +0800 Subject: [PATCH 06/61] =?UTF-8?q?=E7=A7=BB=E9=99=A4lombok?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 2 - .../client/particle/CrossDustParticle.java | 180 +++++++++--------- .../particle/CrossDustParticleOptions.java | 62 +++--- 3 files changed, 116 insertions(+), 128 deletions(-) diff --git a/build.gradle b/build.gradle index d709047..12bf2d9 100644 --- a/build.gradle +++ b/build.gradle @@ -99,8 +99,6 @@ sourceSets.main.resources { srcDir 'src/generated/resources' } dependencies { - compileOnly 'org.projectlombok:lombok:1.18.38' - annotationProcessor 'org.projectlombok:lombok:1.18.38' // Example mod dependency with JEI // The JEI API is declared for compile time use, while the full JEI artifact is used at runtime // compileOnly "mezz.jei:jei-${mc_version}-common-api:${jei_version}" diff --git a/src/main/java/org/confluence/lib/client/particle/CrossDustParticle.java b/src/main/java/org/confluence/lib/client/particle/CrossDustParticle.java index ce3b535..3356a99 100644 --- a/src/main/java/org/confluence/lib/client/particle/CrossDustParticle.java +++ b/src/main/java/org/confluence/lib/client/particle/CrossDustParticle.java @@ -1,14 +1,17 @@ package org.confluence.lib.client.particle; +import com.mojang.blaze3d.vertex.VertexConsumer; +import net.minecraft.client.Camera; import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.client.particle.*; +import net.minecraft.util.Mth; import org.confluence.lib.common.particle.CrossDustParticleOptions; +import org.confluence.lib.util.LibUtils; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.annotation.ParametersAreNonnullByDefault; -// fixme @ParametersAreNonnullByDefault public class CrossDustParticle extends TextureSheetParticle { protected final SpriteSet sprites; @@ -23,99 +26,92 @@ public CrossDustParticle(ClientLevel level, double x, double y, double z, CrossD super(level, x, y, z); this.sprites = sprites; this.options = options; -// this.lifetime = options.getLifetime(); -// this.gravity = options.isNoGravity() ? 0 : 0.7f; -// this.hasPhysics = !options.isNoPhysics(); -// this.quadSize = 0.1f; -// setScale(options.isPulse() ? 0 : options.getScale()); -// quadSizeOld = quadSize; -// xd = options.getVelocity().x; -// yd = options.getVelocity().y; -// zd = options.getVelocity().z; -// age = 1; + this.lifetime = options.lifetime; + this.gravity = options.noGravity ? 0 : 0.7F; + this.hasPhysics = !options.noPhysics; + this.quadSize = 0.1F; + setScale(options.pulse ? 0 : options.scale); + this.quadSizeOld = quadSize; + this.xd = options.velocity.x; + this.yd = options.velocity.y; + this.zd = options.velocity.z; + this.age = 1; } -// @Override -// public void render(VertexConsumer buffer, Camera renderInfo, float partialTicks) { -// useCenterSprite(); -// super.render(buffer, renderInfo, partialTicks); -// useEdgeSprite(); -// super.render(buffer, renderInfo, partialTicks); -// } -// -// @Override -// public void tick() { -// float lastProgress = ((float) age - 1) / lifetime; -// float progress = (float) age / lifetime; -// if (options.isNoGravity()) { -// accelOld = accel; -// accel = LibUtils.cubicBezier(progress, options.getSpeedCurve().x, options.getSpeedCurve().y, options.getSpeedCurve().z, options.getSpeedCurve().w); -// float k = (accel - accelOld) / (progress - lastProgress); -// xd = options.getVelocity().x * k; -// yd = options.getVelocity().y * k; -// zd = options.getVelocity().z * k; -// } -// oRoll = roll; -// rollDeltaOld = rollDelta; -// rollDelta = LibUtils.cubicBezier(progress, options.getRollCurve().x, options.getRollCurve().y, options.getRollCurve().z, options.getRollCurve().w); -// float k = (rollDelta - rollDeltaOld) / (progress - lastProgress); -// roll += options.getRoll() * k * Mth.DEG_TO_RAD; -// -// quadSizeOld = quadSize; -// if (options.isPulse()) { -// if (progress < 0.5f) { -// setScale(options.getScale() * progress * 2); -// } else { -// setScale(options.getScale() * (1 - progress) * 2); -// } -// } else { -// setScale(options.getScale() * (1 - progress)); -// } -// -// super.tick(); -// } -// -// public void setScale(float scale) { -// quadSize = scale * 0.1f; -// setSize(scale * 0.2f, scale * 0.2f); -// } -// -// @Override -// public float getQuadSize(float partialTicks) { -// return Mth.lerp(partialTicks, quadSizeOld, quadSize); -// } -// -// protected void useCenterSprite() { -// setSprite(sprites.get(options.isLarge() ? 3 : 1, 4)); -// float a = (options.getCenterColor() >>> 24 & 0xff) / 255f; -// float r = (options.getCenterColor() >>> 16 & 0xff) / 255f; -// float g = (options.getCenterColor() >>> 8 & 0xff) / 255f; -// float b = (options.getCenterColor() & 0xff) / 255f; -// this.alpha = a; -// this.rCol = r; -// this.gCol = g; -// this.bCol = b; -// } -// -// protected void useEdgeSprite() { -// setSprite(sprites.get(options.isLarge() ? 4 : 2, 4)); -// float a = (options.getEdgeColor() >>> 24 & 0xff) / 255f; -// float r = (options.getEdgeColor() >>> 16 & 0xff) / 255f; -// float g = (options.getEdgeColor() >>> 8 & 0xff) / 255f; -// float b = (options.getEdgeColor() & 0xff) / 255f; -// this.alpha = a; -// this.rCol = r; -// this.gCol = g; -// this.bCol = b; -// } -// -// @Override -// protected int getLightColor(float partialTick) { -// if (options.isFullBrightness()) { -// return 15 << 20 | 15 << 4; -// } -// return super.getLightColor(partialTick); -// } + @Override + public void render(VertexConsumer buffer, Camera renderInfo, float partialTicks) { + useCenterSprite(); + super.render(buffer, renderInfo, partialTicks); + useEdgeSprite(); + super.render(buffer, renderInfo, partialTicks); + } + + @Override + public void tick() { + float lastProgress = ((float) age - 1) / lifetime; + float progress = (float) age / lifetime; + if (options.noGravity) { + this.accelOld = accel; + this.accel = LibUtils.cubicBezier(progress, options.speedCurve.x, options.speedCurve.y, options.speedCurve.z, options.speedCurve.w); + float k = (accel - accelOld) / (progress - lastProgress); + this.xd = options.velocity.x * k; + this.yd = options.velocity.y * k; + this.zd = options.velocity.z * k; + } + this.oRoll = roll; + this.rollDeltaOld = rollDelta; + this.rollDelta = LibUtils.cubicBezier(progress, options.rollCurve.x, options.rollCurve.y, options.rollCurve.z, options.rollCurve.w); + float k = (rollDelta - rollDeltaOld) / (progress - lastProgress); + this.roll += options.roll * k * Mth.DEG_TO_RAD; + + this.quadSizeOld = quadSize; + if (options.pulse) { + if (progress < 0.5f) { + setScale(options.scale * progress * 2); + } else { + setScale(options.scale * (1 - progress) * 2); + } + } else { + setScale(options.scale * (1 - progress)); + } + + super.tick(); + } + + public void setScale(float scale) { + this.quadSize = scale * 0.1F; + scale = quadSize + quadSize; + setSize(scale, scale); + } + + @Override + public float getQuadSize(float partialTicks) { + return Mth.lerp(partialTicks, quadSizeOld, quadSize); + } + + protected void useCenterSprite() { + setSprite(sprites.get(options.large ? 3 : 1, 4)); + this.alpha = (options.centerColor >>> 24 & 0xFF) / 255F; + this.rCol = (options.centerColor >>> 16 & 0xFF) / 255F; + this.gCol = (options.centerColor >>> 8 & 0xFF) / 255F; + this.bCol = (options.centerColor & 0xFF) / 255F; + } + + protected void useEdgeSprite() { + setSprite(sprites.get(options.large ? 4 : 2, 4)); + this.alpha = (options.edgeColor >>> 24 & 0xFF) / 255F; + this.rCol = (options.edgeColor >>> 16 & 0xFF) / 255F; + this.gCol = (options.edgeColor >>> 8 & 0xFF) / 255F; + this.bCol = (options.edgeColor & 0xFF) / 255F; + } + + @Override + protected int getLightColor(float partialTick) { + if (options.fullBrightness) { + return 0xF000F0; + } + return super.getLightColor(partialTick); + } @Override @NotNull diff --git a/src/main/java/org/confluence/lib/common/particle/CrossDustParticleOptions.java b/src/main/java/org/confluence/lib/common/particle/CrossDustParticleOptions.java index 8382bb2..c8c089f 100644 --- a/src/main/java/org/confluence/lib/common/particle/CrossDustParticleOptions.java +++ b/src/main/java/org/confluence/lib/common/particle/CrossDustParticleOptions.java @@ -4,9 +4,6 @@ import com.mojang.serialization.MapCodec; import com.mojang.serialization.codecs.RecordCodecBuilder; import io.netty.buffer.ByteBuf; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.ToString; import net.minecraft.MethodsReturnNonnullByDefault; import net.minecraft.core.particles.ParticleOptions; import net.minecraft.core.particles.ParticleType; @@ -21,27 +18,9 @@ import javax.annotation.ParametersAreNonnullByDefault; -@Getter -@EqualsAndHashCode -@ToString +@ParametersAreNonnullByDefault +@MethodsReturnNonnullByDefault public final class CrossDustParticleOptions implements ParticleOptions { - private final boolean large; - /** argb */ - private final int centerColor; - /** argb */ - private final int edgeColor; - private final Vector3f velocity; - private final Vector4f speedCurve; - private final float scale; - private final int lifetime; - private final int roll; - private final Vector4f rollCurve; - private final boolean noGravity; - private final boolean noPhysics; - private final boolean fullBrightness; - private final boolean pulse; - private final int flags; - public static final int FLAG_LARGE = 0b00001; public static final int FLAG_NO_GRAVITY = 0b00010; public static final int FLAG_NO_PHYSICS = 0b00100; @@ -49,15 +28,15 @@ public final class CrossDustParticleOptions implements ParticleOptions { public static final int FLAG_PULSE = 0b10000; public static final MapCodec CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group( - Codec.INT.fieldOf("centerColor").forGetter(thisOptions -> thisOptions.centerColor), - Codec.INT.fieldOf("edgeColor").forGetter(thisOptions -> thisOptions.edgeColor), - ExtraCodecs.VECTOR3F.fieldOf("velocity").forGetter(thisOptions -> thisOptions.velocity), - ExtraCodecs.VECTOR4F.fieldOf("speedCurve").forGetter(thisOptions -> thisOptions.speedCurve), - Codec.FLOAT.fieldOf("scale").forGetter(thisOptions -> thisOptions.scale), - Codec.INT.fieldOf("lifetime").forGetter(thisOptions -> thisOptions.lifetime), - Codec.INT.fieldOf("roll").forGetter(thisOptions -> thisOptions.roll), - ExtraCodecs.VECTOR4F.fieldOf("rollCurve").forGetter(thisOptions -> thisOptions.rollCurve), - Codec.INT.fieldOf("flags").forGetter(thisOptions -> thisOptions.flags) + Codec.INT.fieldOf("centerColor").forGetter(thisOptions -> thisOptions.centerColor), + Codec.INT.fieldOf("edgeColor").forGetter(thisOptions -> thisOptions.edgeColor), + ExtraCodecs.VECTOR3F.fieldOf("velocity").forGetter(thisOptions -> thisOptions.velocity), + ExtraCodecs.VECTOR4F.fieldOf("speedCurve").forGetter(thisOptions -> thisOptions.speedCurve), + Codec.FLOAT.fieldOf("scale").forGetter(thisOptions -> thisOptions.scale), + Codec.INT.fieldOf("lifetime").forGetter(thisOptions -> thisOptions.lifetime), + Codec.INT.fieldOf("roll").forGetter(thisOptions -> thisOptions.roll), + ExtraCodecs.VECTOR4F.fieldOf("rollCurve").forGetter(thisOptions -> thisOptions.rollCurve), + Codec.INT.fieldOf("flags").forGetter(thisOptions -> thisOptions.flags) ).apply(instance, CrossDustParticleOptions::new)); private static final StreamCodec VEC4F_CODEC = new StreamCodec<>() { @@ -74,8 +53,6 @@ public void encode(ByteBuf buffer, Vector4f vector4f) { } }; - @ParametersAreNonnullByDefault - @MethodsReturnNonnullByDefault public static final StreamCodec STREAM_CODEC = new StreamCodec<>() { @Override public CrossDustParticleOptions decode(FriendlyByteBuf buffer) { @@ -105,6 +82,23 @@ public void encode(FriendlyByteBuf buffer, CrossDustParticleOptions value) { } }; + public final boolean large; + /** argb */ + public final int centerColor; + /** argb */ + public final int edgeColor; + public final Vector3f velocity; + public final Vector4f speedCurve; + public final float scale; + public final int lifetime; + public final int roll; + public final Vector4f rollCurve; + public final boolean noGravity; + public final boolean noPhysics; + public final boolean fullBrightness; + public final boolean pulse; + public final int flags; + public CrossDustParticleOptions(boolean large, int centerColor, int edgeColor, Vector3f velocity, Vector4f speedCurve, float scale, int lifetime, int roll, Vector4f rollCurve, boolean noGravity, boolean noPhysics, boolean fullBrightness, boolean pulse) { this.large = large; From 211cfdde00b6135939049fccf38a8677145b375c Mon Sep 17 00:00:00 2001 From: westernat Date: Wed, 6 Aug 2025 15:38:32 +0800 Subject: [PATCH 07/61] =?UTF-8?q?=E4=BD=BFIdFixer=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E5=A4=9A=E6=AC=A1=E5=8E=86=E5=8F=B2=E5=8F=98=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/confluence/lib/common/data/IdFixer.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/confluence/lib/common/data/IdFixer.java b/src/main/java/org/confluence/lib/common/data/IdFixer.java index fbafec1..e71452f 100644 --- a/src/main/java/org/confluence/lib/common/data/IdFixer.java +++ b/src/main/java/org/confluence/lib/common/data/IdFixer.java @@ -102,8 +102,9 @@ public DataResult> apply(DynamicOps ops, T input, DataResult

{ T t = map.get("Name"); if (t != null) ops.getStringValue(t).ifSuccess(s -> { - String s1 = BLOCK_NAME_FIX_MAP.get(s); - if (s1 != null) ops.mergeToMap(input, ops.createString("Name"), ops.createString(s1)) + String s1 = s; + while ((s = BLOCK_NAME_FIX_MAP.get(s1)) != null) s1 = s; + ops.mergeToMap(input, ops.createString("Name"), ops.createString(s1)) .ifSuccess(t1 -> mutableObject.setValue(codec.decode(ops, t1))); }); }); @@ -148,8 +149,9 @@ public static Codec> fixItemName(Codec> codec) { public DataResult, T>> apply(DynamicOps ops, T input, DataResult, T>> a) { if (a.isSuccess()) return a; return ops.getStringValue(input).result().map(s -> { - String s1 = ITEM_NAME_FIX_MAP.get(s); - return s1 == null ? a : codec.decode(ops, ops.createString(s1)); + String s1 = s; + while ((s = ITEM_NAME_FIX_MAP.get(s1)) != null) s1 = s; + return codec.decode(ops, ops.createString(s1)); }).orElse(a); } @@ -166,8 +168,9 @@ public static Codec.ResultFunction> fixBiomeName(Codec DataResult, T>> apply(DynamicOps ops, T input, DataResult, T>> a) { if (a.isSuccess()) return a; return ops.getStringValue(input).result().map(s -> { - String s1 = BIOME_NAME_FIX_MAP.get(s); - return s1 == null ? a : codec.decode(ops, ops.createString(s1)); + String s1 = s; + while ((s = BIOME_NAME_FIX_MAP.get(s1)) != null) s1 = s; + return codec.decode(ops, ops.createString(s1)); }).orElse(a); } From 2d4ce4b8be0aca4e97017975c8b8969cf419b9f0 Mon Sep 17 00:00:00 2001 From: westernat Date: Thu, 7 Aug 2025 20:48:17 +0800 Subject: [PATCH 08/61] =?UTF-8?q?=E7=A5=9E=E7=A7=98=E7=9A=84=E6=B3=A8?= =?UTF-8?q?=E9=87=8A=E5=86=85getPrefab?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/org/confluence/lib/util/LibClientUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/confluence/lib/util/LibClientUtils.java b/src/main/java/org/confluence/lib/util/LibClientUtils.java index aa1ee03..20028a5 100644 --- a/src/main/java/org/confluence/lib/util/LibClientUtils.java +++ b/src/main/java/org/confluence/lib/util/LibClientUtils.java @@ -54,7 +54,7 @@ public static boolean shouldDrawSurvivalElements(Minecraft minecraft) { * 将游戏缓存的贴图写入文件 * * @param nativeImage 游戏缓存的贴图 - * @param path 文件全路径,比如FMLPaths.GAMEDIR.getPrefab().resolve("redstone.png") + * @param path 文件全路径,比如FMLPaths.GAMEDIR.get().resolve("redstone.png") * @param argbMixer argb的混合方法 */ public static void writeImageToFile(NativeImage nativeImage, Path path, Function4 argbMixer) { From 8828f940dbc8d2bd6a2fb19e599f2237c1f4662c Mon Sep 17 00:00:00 2001 From: westernat Date: Sat, 9 Aug 2025 13:14:37 +0800 Subject: [PATCH 09/61] =?UTF-8?q?=E6=99=B6=E6=B4=9E=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E9=80=89=E6=8B=A9=E6=B7=B1=E6=9D=BF=E5=B2=A9=E5=8F=98=E7=A7=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/confluence/lib/util/FeatureUtils.java | 95 ++++++++++++++++--- 1 file changed, 82 insertions(+), 13 deletions(-) diff --git a/src/main/java/org/confluence/lib/util/FeatureUtils.java b/src/main/java/org/confluence/lib/util/FeatureUtils.java index 8096f14..065d259 100644 --- a/src/main/java/org/confluence/lib/util/FeatureUtils.java +++ b/src/main/java/org/confluence/lib/util/FeatureUtils.java @@ -11,6 +11,7 @@ import org.confluence.lib.ConfluenceMagicLib; import org.jetbrains.annotations.Nullable; +import java.util.function.Function; import java.util.function.Predicate; public final class FeatureUtils { @@ -79,7 +80,20 @@ public static void ball8(BlockPos.MutableBlockPos posCheck, boolean replace, int for (int i = 0; i < 8; i++) { posCheck.set(centerPos.getX() + (x * ((i < 4) ? 1 : -1)), centerPos.getY() + (y * ((i % 4 < 2) ? 1 : -1)), centerPos.getZ() + (z * ((i % 2 < 1) ? 1 : -1))); if (replace || level.getBlockState(posCheck).isAir()) { - level.setBlock(posCheck.immutable(), blockState, 3); + level.setBlock(posCheck, blockState, 3); + } + } + } + + public static void ball8(BlockPos.MutableBlockPos posCheck, boolean replace, int x, int y, int z, Function blockState, BlockPos centerPos, WorldGenLevel level) { + for (int i = 0; i < 8; i++) { + posCheck.set(centerPos.getX() + (x * ((i < 4) ? 1 : -1)), centerPos.getY() + (y * ((i % 4 < 2) ? 1 : -1)), centerPos.getZ() + (z * ((i % 2 < 1) ? 1 : -1))); + BlockState state = level.getBlockState(posCheck); + if (replace || state.isAir()) { + BlockState apply = blockState.apply(state); + if (apply != null) { + level.setBlock(posCheck, apply, 3); + } } } } @@ -89,9 +103,9 @@ public static void ball8(BlockPos.MutableBlockPos posCheck, boolean replace, int posCheck.set(centerPos.getX() + (x * ((i < 4) ? 1 : -1)), centerPos.getY() + (y * ((i % 4 < 2) ? 1 : -1)), centerPos.getZ() + (z * ((i % 2 < 1) ? 1 : -1))); if (replace || level.getBlockState(posCheck).isAir()) { if (posCheck.getY() > checkY) { - level.setBlock(posCheck.immutable(), blockState1, 3); + level.setBlock(posCheck, blockState1, 3); } else { - level.setBlock(posCheck.immutable(), blockState2, 3); + level.setBlock(posCheck, blockState2, 3); } } } @@ -102,14 +116,29 @@ public static void ball8(BlockPos.MutableBlockPos posCheck, boolean replace, int if (placePer >= random.nextFloat()) { posCheck.set(centerPos.getX() + (x * ((i < 4) ? 1 : -1)), centerPos.getY() + (y * ((i % 4 < 2) ? 1 : -1)), centerPos.getZ() + (z * ((i % 2 < 1) ? 1 : -1))); if (replace || level.getBlockState(posCheck).isAir()) { - level.setBlock(posCheck.immutable(), blockState, 3); + level.setBlock(posCheck, blockState, 3); + } + } + } + } + + public static void ball8(BlockPos.MutableBlockPos posCheck, boolean replace, int x, int y, int z, Function blockState, BlockPos centerPos, WorldGenLevel level, float placePer, RandomSource random) { + for (int i = 0; i < 8; i++) { + if (placePer >= random.nextFloat()) { + posCheck.set(centerPos.getX() + (x * ((i < 4) ? 1 : -1)), centerPos.getY() + (y * ((i % 4 < 2) ? 1 : -1)), centerPos.getZ() + (z * ((i % 2 < 1) ? 1 : -1))); + BlockState state = level.getBlockState(posCheck); + if (replace || state.isAir()) { + BlockState apply = blockState.apply(state); + if (apply != null) { + level.setBlock(posCheck, apply, 3); + } } } } } - //填充方法 - //球体填充 + // 填充方法 + // 球体填充 public static void ball(double radiusD, BlockPos centerPos, BlockState blockState, boolean replace, WorldGenLevel level) { int radius = (int) radiusD + 1; double radius2 = radiusD * radiusD; @@ -129,7 +158,27 @@ public static void ball(double radiusD, BlockPos centerPos, BlockState blockStat } } - //球体填充,带有指定y坐标上下不同种方块填充 + // 球体填充,且允许根据原方块状态灵活调整新方块状态 + public static void ball(double radiusD, BlockPos centerPos, Function blockState, boolean replace, WorldGenLevel level) { + int radius = (int) radiusD + 1; + double radius2 = radiusD * radiusD; + int x2; + int y2; + BlockPos.MutableBlockPos posCheck = centerPos.mutable(); + for (int x = 0; x < radius; x++) { + x2 = x * x; + for (int y = 0; y < radius; y++) { + y2 = y * y; + for (int z = 0; z < radius; z++) { + if ((x2 + y2 + z * z <= radius2)) { + ball8(posCheck, replace, x, y, z, blockState, centerPos, level); + } + } + } + } + } + + // 球体填充,带有指定y坐标上下不同种方块填充 public static void ball(double radiusD, BlockPos centerPos, BlockState blockState1, BlockState blockState2, boolean replace, WorldGenLevel level, int checkY) { int radius = (int) radiusD + 1; double radius2 = radiusD * radiusD; @@ -149,7 +198,7 @@ public static void ball(double radiusD, BlockPos centerPos, BlockState blockStat } } - //球体填充,带有随机比例 + // 球体填充,带有随机比例 public static void ball(double radiusD, BlockPos centerPos, BlockState blockState, boolean replace, WorldGenLevel level, float placePer, RandomSource random) { int radius = (int) radiusD + 1; double radius2 = radiusD * radiusD; @@ -169,7 +218,27 @@ public static void ball(double radiusD, BlockPos centerPos, BlockState blockStat } } - //立方体填充 + // 球体填充,带有随机比例,且允许根据原方块状态灵活调整新方块状态 + public static void ball(double radiusD, BlockPos centerPos, Function blockState, boolean replace, WorldGenLevel level, float placePer, RandomSource random) { + int radius = (int) radiusD + 1; + double radius2 = radiusD * radiusD; + int x2; + int y2; + BlockPos.MutableBlockPos posCheck = centerPos.mutable(); + for (int x = 0; x < radius; x++) { + x2 = x * x; + for (int y = 0; y < radius; y++) { + y2 = y * y; + for (int z = 0; z < radius; z++) { + if ((x2 + y2 + z * z <= radius2)) { + ball8(posCheck, replace, x, y, z, blockState, centerPos, level, placePer, random); + } + } + } + } + } + + // 立方体填充 public static void rectangular(BlockPos startPos, BlockPos endPos, BlockState blockstate, WorldGenLevel level, boolean replace) { int startX = Math.min(endPos.getX(), startPos.getX()); int startY = Math.min(endPos.getY(), startPos.getY()); @@ -185,13 +254,13 @@ public static void rectangular(BlockPos startPos, BlockPos endPos, BlockState bl for (int y = 0; y <= yLength; y++) { for (int z = 0; z <= zLength; z++) { posCheck.set(startX + x, startY + y, startZ + z); - if (replace || level.getBlockState(posCheck.immutable()).canBeReplaced()) level.setBlock(posCheck.immutable(), blockstate, 3); + if (replace || level.getBlockState(posCheck).canBeReplaced()) level.setBlock(posCheck, blockstate, 3); } } } } - //椭球体填充 + // 椭球体填充 public static void ellipsoid(double radiusDX, double radiusDY, double radiusDZ, BlockPos centerPos, BlockState blockState, boolean replace, WorldGenLevel level) { int radiusX = (int) radiusDX + 1; int radiusY = (int) radiusDY + 1; @@ -215,7 +284,7 @@ public static void ellipsoid(double radiusDX, double radiusDY, double radiusDZ, } } - //立方体检查 + // 立方体检查 public static boolean rectangularCheck(BlockPos startPos, BlockPos endPos, WorldGenLevel level) { int startX = Math.min(endPos.getX(), startPos.getX()); int startY = Math.min(endPos.getY(), startPos.getY()); @@ -232,7 +301,7 @@ public static boolean rectangularCheck(BlockPos startPos, BlockPos endPos, World for (int y = 0; (y <= yLength) && bl; y++) { for (int z = 0; (z <= zLength) && bl; z++) { posCheck.set(startX + x, startY + y, startZ + z); - if (!level.getBlockState(posCheck.immutable()).canBeReplaced()) bl = false; + if (!level.getBlockState(posCheck).canBeReplaced()) bl = false; } } } From 8d074607e853c173af6550708d89d9b5664d9011 Mon Sep 17 00:00:00 2001 From: westernat Date: Sat, 9 Aug 2025 23:27:03 +0800 Subject: [PATCH 10/61] =?UTF-8?q?=E5=85=B3=E4=BA=8E=E6=B8=B8=E6=88=8F?= =?UTF-8?q?=E6=97=B6=E9=97=B4=E7=9A=84=E5=B7=A5=E5=85=B7=E7=A7=BB=E5=88=B0?= =?UTF-8?q?lib?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../confluence/lib/ConfluenceMagicLib.java | 2 +- .../org/confluence/lib/util/LibDateUtils.java | 81 +++++++++++++++++++ 2 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 src/main/java/org/confluence/lib/util/LibDateUtils.java diff --git a/src/main/java/org/confluence/lib/ConfluenceMagicLib.java b/src/main/java/org/confluence/lib/ConfluenceMagicLib.java index 43dff22..90dd4fb 100644 --- a/src/main/java/org/confluence/lib/ConfluenceMagicLib.java +++ b/src/main/java/org/confluence/lib/ConfluenceMagicLib.java @@ -35,7 +35,7 @@ public class ConfluenceMagicLib { public static final String LIB_ID = "confluence_magic_lib"; public static final String CONFLUENCE_ID = "confluence"; public static final Logger LOGGER = LoggerFactory.getLogger("Confluence Magic Lib"); - public static final com.google.common.base.Supplier IS_CONFLUENCE_LOADED = Suppliers.memoize(() -> ModList.get().isLoaded(CONFLUENCE_ID)); + public static final Supplier IS_CONFLUENCE_LOADED = Suppliers.memoize(() -> ModList.get().isLoaded(CONFLUENCE_ID)); public static final DeferredRegister> INGREDIENT_TYPES = DeferredRegister.create(NeoForgeRegistries.Keys.INGREDIENT_TYPES, LIB_ID); public static final Supplier> AMOUNT_INGREDIENT_TYPE = INGREDIENT_TYPES.register("amount_ingredient", () -> new IngredientType<>(AmountIngredient.CODEC, AmountIngredient.STREAM_CODEC)); diff --git a/src/main/java/org/confluence/lib/util/LibDateUtils.java b/src/main/java/org/confluence/lib/util/LibDateUtils.java new file mode 100644 index 0000000..68430ec --- /dev/null +++ b/src/main/java/org/confluence/lib/util/LibDateUtils.java @@ -0,0 +1,81 @@ +package org.confluence.lib.util; + +import net.minecraft.Util; +import net.minecraft.world.level.Level; + +import java.time.format.DateTimeParseException; + +public final class LibDateUtils { + private static final short[] TIMES = Util.make(new short[24 * 60], times -> { + for (int h = 0; h < 24; h++) { + int t = h * 60; + int i = (h - 6) * 1000; + if (i < 0) i += 24000; + for (int m = 0; m < 60; m++) { + times[t + m] = (short) (i + (int) (m / 0.06F)); + } + } + }); + public static final int _00$00 = getDayTime(0, 0); + public static final int _04$30 = getDayTime(4, 30); + public static final int _06$00 = getDayTime(6, 0); + public static final int _19$30 = getDayTime(19, 30); + + public static int getDayTime(Level level) { + return getDayTime(level.getDayTime()); + } + + public static int getDayTime(long dayTime) { + return (int) (dayTime % 24000L); + } + + /** + * 映射到游戏内的dayTime + */ + public static int getDayTime(int hour, int minute) { + if (hour < 0 || hour > 23) throw new DateTimeParseException("hour bounds is [0, 23], currently is " + hour, "", 0); + if (minute < 0 || minute > 59) throw new DateTimeParseException("minute bounds is [0, 59], currently is " + minute, "", 0); + return TIMES[hour * 60 + minute]; + } + + /** + * @param start 开始的dayTime + * @param end 结束的dayTime + * @param dayTime 判断的dayTime + * @return start <= dayTime <= end + */ + public static boolean isWithinDayTime(int start, int end, int dayTime) { + if (start > end) { + return dayTime >= start || dayTime <= end; + } + return dayTime >= start && dayTime <= end; + } + + public static boolean isWithinDayTime(int start, int end, Level level) { + return isWithinDayTime(start, end, getDayTime(level)); + } + + public static boolean isWithinDayTime(int startHour, int startMinute, int endHour, int endMinute, int dayTime) { + return isWithinDayTime(getDayTime(startHour, startMinute), getDayTime(endHour, endMinute), dayTime); + } + + public static boolean isWithinDayTime(int startHour, int startMinute, int endHour, int endMinute, Level level) { + return isWithinDayTime(startHour, startMinute, endHour, endMinute, getDayTime(level)); + } + + public static boolean isDay(int dayTime) { + return isWithinDayTime(_04$30, _19$30, dayTime); + } + + public static boolean isDay(Level level) { + return isDay(getDayTime(level)); + } + + public static boolean isNight(int dayTime) { + return isWithinDayTime(_19$30, _04$30, dayTime); + } + + public static boolean isNight(Level level) { + return isNight(getDayTime(level)); + } +} From 2767c13bfdf5050c160bd373beaaf2750bbe6ad4 Mon Sep 17 00:00:00 2001 From: westernat Date: Sun, 10 Aug 2025 15:37:21 +0800 Subject: [PATCH 11/61] =?UTF-8?q?=E9=95=BF=E7=9F=9B=E8=BF=9E=E7=BB=AD?= =?UTF-8?q?=E6=94=BB=E5=87=BB=E3=80=81=E6=B7=BB=E5=8A=A0=E6=94=BB=E5=87=BB?= =?UTF-8?q?=E9=97=B4=E9=9A=94=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/org/confluence/lib/util/LibUtils.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/confluence/lib/util/LibUtils.java b/src/main/java/org/confluence/lib/util/LibUtils.java index 4d5edc9..54277f5 100644 --- a/src/main/java/org/confluence/lib/util/LibUtils.java +++ b/src/main/java/org/confluence/lib/util/LibUtils.java @@ -205,13 +205,17 @@ public static void setItemAndDropChance(Mob mob, DifficultyInstance difficulty, } public static CompoundTag getItemStackNbt(ItemStack itemStack) { + return getItemStackNbtNoCopy(itemStack).copy(); + } + + public static CompoundTag getItemStackNbtNoCopy(ItemStack itemStack) { NbtComponent nbtComponent = itemStack.get(ConfluenceMagicLib.NBT); if (nbtComponent == null) { CompoundTag nbt = new CompoundTag(); itemStack.set(ConfluenceMagicLib.NBT, new NbtComponent(nbt)); return nbt; } - return nbtComponent.nbt().copy(); + return nbtComponent.nbt(); } public static @Nullable CompoundTag getItemStackNbtIfPresent(ItemStack itemStack) { From 1ea08a2a9c28b3a86d4f9720cd86a34e414a6d79 Mon Sep 17 00:00:00 2001 From: westernat Date: Mon, 11 Aug 2025 11:34:00 +0800 Subject: [PATCH 12/61] 1.1.5.1 --- src/main/java/org/confluence/lib/util/LibUtils.java | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/main/java/org/confluence/lib/util/LibUtils.java b/src/main/java/org/confluence/lib/util/LibUtils.java index 54277f5..2d3f37b 100644 --- a/src/main/java/org/confluence/lib/util/LibUtils.java +++ b/src/main/java/org/confluence/lib/util/LibUtils.java @@ -226,12 +226,7 @@ public static CompoundTag getItemStackNbtNoCopy(ItemStack itemStack) { public static void updateItemStackNbt(ItemStack itemStack, Consumer consumer) { NbtComponent nbtComponent = itemStack.get(ConfluenceMagicLib.NBT); - CompoundTag nbt; - if (nbtComponent == null) { - nbt = new CompoundTag(); - } else { - nbt = nbtComponent.nbt().copy(); - } + CompoundTag nbt = nbtComponent == null ? new CompoundTag() : nbtComponent.nbt().copy(); consumer.accept(nbt); itemStack.set(ConfluenceMagicLib.NBT, new NbtComponent(nbt)); } From 5d70f43c139092e6524fd9762583af9cbd6a5420 Mon Sep 17 00:00:00 2001 From: westernat Date: Mon, 11 Aug 2025 15:26:17 +0800 Subject: [PATCH 13/61] =?UTF-8?q?DPS=E5=A4=A7=E4=BF=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/org/confluence/lib/util/LibUtils.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/org/confluence/lib/util/LibUtils.java b/src/main/java/org/confluence/lib/util/LibUtils.java index 2d3f37b..597bc2e 100644 --- a/src/main/java/org/confluence/lib/util/LibUtils.java +++ b/src/main/java/org/confluence/lib/util/LibUtils.java @@ -11,6 +11,7 @@ import net.minecraft.network.codec.ByteBufCodecs; import net.minecraft.network.codec.StreamCodec; import net.minecraft.tags.TagKey; +import net.minecraft.util.RandomSource; import net.minecraft.util.Tuple; import net.minecraft.world.DifficultyInstance; import net.minecraft.world.entity.EquipmentSlot; @@ -309,4 +310,8 @@ public static void resetDataComponent(ItemStack itemStack, DataComponentType itemStack.set(type, value); } } + + public static boolean checkChance(double value, RandomSource random) { + return value >= 1.0 || (value > 0.0 && random.nextDouble() < value); + } } From f74500b3c21c8090d7a03c638e2b42c656c4bfb0 Mon Sep 17 00:00:00 2001 From: westernat Date: Tue, 12 Aug 2025 20:48:01 +0800 Subject: [PATCH 14/61] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index e30e387..522f361 100644 --- a/gradle.properties +++ b/gradle.properties @@ -30,7 +30,7 @@ mod_name=Confluence Magic Lib mod_license=MIT # The mod version. See https://semver.org/ ###### remove '-SNAPSHOT' when merge to main branch ###### -mod_version=0.0.2a-SNAPSHOT +mod_version=0.0.2b-SNAPSHOT # The group ID for the mod. It is only important when publishing as an artifact to a Maven repository. # This should match the base package used for the mod sources. # See https://maven.apache.org/guides/mini/guide-naming-conventions.html From 44cdc7060d518ad946c61bed37ebf8d424ff3031 Mon Sep 17 00:00:00 2001 From: westernat Date: Wed, 13 Aug 2025 13:58:43 +0800 Subject: [PATCH 15/61] =?UTF-8?q?=E5=90=91=E4=B8=8B=E5=85=BC=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/org/confluence/lib/ConfluenceMagicLib.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/confluence/lib/ConfluenceMagicLib.java b/src/main/java/org/confluence/lib/ConfluenceMagicLib.java index 90dd4fb..fb79e81 100644 --- a/src/main/java/org/confluence/lib/ConfluenceMagicLib.java +++ b/src/main/java/org/confluence/lib/ConfluenceMagicLib.java @@ -37,19 +37,19 @@ public class ConfluenceMagicLib { public static final Logger LOGGER = LoggerFactory.getLogger("Confluence Magic Lib"); public static final Supplier IS_CONFLUENCE_LOADED = Suppliers.memoize(() -> ModList.get().isLoaded(CONFLUENCE_ID)); - public static final DeferredRegister> INGREDIENT_TYPES = DeferredRegister.create(NeoForgeRegistries.Keys.INGREDIENT_TYPES, LIB_ID); + private static final DeferredRegister> INGREDIENT_TYPES = DeferredRegister.create(NeoForgeRegistries.Keys.INGREDIENT_TYPES, LIB_ID); public static final Supplier> AMOUNT_INGREDIENT_TYPE = INGREDIENT_TYPES.register("amount_ingredient", () -> new IngredientType<>(AmountIngredient.CODEC, AmountIngredient.STREAM_CODEC)); - public static final DeferredRegister PIECE_TYPES = DeferredRegister.create(BuiltInRegistries.STRUCTURE_PIECE, LIB_ID); + private static final DeferredRegister PIECE_TYPES = DeferredRegister.create(BuiltInRegistries.STRUCTURE_PIECE, LIB_ID); public static final Supplier SIMPLE_TEMPLATE_PIECE = PIECE_TYPES.register("simple_template_piece", () -> SimpleTemplatePiece::new); public static final Supplier GRID_PIECE = PIECE_TYPES.register("grid_piece", () -> GridPiece::new); - public static final DeferredRegister.DataComponents DATA_COMPONENT_TYPES = DeferredRegister.createDataComponents(Registries.DATA_COMPONENT_TYPE, LIB_ID); + private static final DeferredRegister.DataComponents DATA_COMPONENT_TYPES = DeferredRegister.createDataComponents(Registries.DATA_COMPONENT_TYPE, LIB_ID); public static final Supplier> MOD_RARITY = DATA_COMPONENT_TYPES.registerComponentType("mod_rarity", builder -> builder.persistent(ModRarity.CODEC).networkSynchronized(ModRarity.STREAM_CODEC)); public static final Supplier> TOOL_MODE = DATA_COMPONENT_TYPES.registerComponentType("tool_mode", builder -> builder.persistent(ToolMode.CODEC).networkSynchronized(ToolMode.STREAM_CODEC)); public static final Supplier> NBT = DATA_COMPONENT_TYPES.registerComponentType("nbt", builder -> builder.persistent(NbtComponent.CODEC).networkSynchronized(NbtComponent.STREAM_CODEC)); - public static final DeferredRegister> PARTICLES = DeferredRegister.create(BuiltInRegistries.PARTICLE_TYPE, LIB_ID); + private static final DeferredRegister> PARTICLES = DeferredRegister.create(BuiltInRegistries.PARTICLE_TYPE, LIB_ID); public static final Supplier> CROSS_DUST_PARTICLE = PARTICLES.register("cross_dust", () -> new ParticleType<>(false) { @Override @NotNull @@ -74,4 +74,9 @@ public ConfluenceMagicLib(IEventBus modEventBus, ModContainer modContainer) { public static ResourceLocation asResource(String path) { return ResourceLocation.fromNamespaceAndPath(LIB_ID, path); } + + @Deprecated + public static boolean isConfluenceLoaded() { + return IS_CONFLUENCE_LOADED.get(); + } } From c0dd0d22a3b4db96fa0d330e59745f533631f7b7 Mon Sep 17 00:00:00 2001 From: westernat Date: Thu, 14 Aug 2025 13:49:07 +0800 Subject: [PATCH 16/61] =?UTF-8?q?=E7=88=86=E7=82=B8=E5=85=94=E5=90=88?= =?UTF-8?q?=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lib/common/component/NbtComponent.java | 8 ++++ .../confluence/lib/common/data/IdFixer.java | 3 +- .../common/worldgen/structure/GridPiece.java | 5 ++- .../confluence/lib/util/LibCodecUtils.java | 37 +++++++++++++++++++ .../lib/util/LibStreamCodecUtils.java | 36 ++++++++++++++++++ .../org/confluence/lib/util/LibUtils.java | 26 +++---------- 6 files changed, 92 insertions(+), 23 deletions(-) create mode 100644 src/main/java/org/confluence/lib/util/LibCodecUtils.java create mode 100644 src/main/java/org/confluence/lib/util/LibStreamCodecUtils.java diff --git a/src/main/java/org/confluence/lib/common/component/NbtComponent.java b/src/main/java/org/confluence/lib/common/component/NbtComponent.java index 55f83e8..b42b890 100644 --- a/src/main/java/org/confluence/lib/common/component/NbtComponent.java +++ b/src/main/java/org/confluence/lib/common/component/NbtComponent.java @@ -10,6 +10,8 @@ import net.minecraft.network.codec.StreamCodec; import org.jetbrains.annotations.Nullable; +import java.util.function.Consumer; + public record NbtComponent(CompoundTag nbt) implements DataComponentType { public static final Codec CODEC = Codec.withAlternative(CompoundTag.CODEC, TagParser.AS_CODEC).xmap(NbtComponent::new, NbtComponent::nbt); public static final StreamCodec STREAM_CODEC = ByteBufCodecs.COMPOUND_TAG.map(NbtComponent::new, NbtComponent::nbt); @@ -33,4 +35,10 @@ public boolean equals(Object o) { public int hashCode() { return nbt.hashCode(); } + + public static NbtComponent create(Consumer consumer) { + CompoundTag tag = new CompoundTag(); + consumer.accept(tag); + return new NbtComponent(tag); + } } diff --git a/src/main/java/org/confluence/lib/common/data/IdFixer.java b/src/main/java/org/confluence/lib/common/data/IdFixer.java index e71452f..62c1561 100644 --- a/src/main/java/org/confluence/lib/common/data/IdFixer.java +++ b/src/main/java/org/confluence/lib/common/data/IdFixer.java @@ -23,6 +23,7 @@ import org.apache.commons.lang3.mutable.MutableObject; import org.confluence.lib.ConfluenceMagicLib; import org.confluence.lib.api.NameFixRegisterEvent; +import org.confluence.lib.util.LibCodecUtils; import org.confluence.lib.util.LibUtils; import org.jetbrains.annotations.ApiStatus; @@ -36,7 +37,7 @@ @ApiStatus.ScheduledForRemoval(inVersion = "1.3.0") public class IdFixer { public static final Codec>> FIXED_BLOCK_MAP_CODEC = Codec.lazyInitialized(() -> { - Codec>> codec = LibUtils.tupleCodec(Codec.INT, Codec.LONG.listOf().xmap(LongArrayList::new, Function.identity())).listOf(); + Codec>> codec = LibCodecUtils.tupleCodec(Codec.INT, Codec.LONG.listOf().xmap(LongArrayList::new, Function.identity())).listOf(); return new Codec<>() { @Override public DataResult>, T>> decode(DynamicOps ops, T input) { diff --git a/src/main/java/org/confluence/lib/common/worldgen/structure/GridPiece.java b/src/main/java/org/confluence/lib/common/worldgen/structure/GridPiece.java index 0997be9..229a4f9 100644 --- a/src/main/java/org/confluence/lib/common/worldgen/structure/GridPiece.java +++ b/src/main/java/org/confluence/lib/common/worldgen/structure/GridPiece.java @@ -24,6 +24,7 @@ import net.minecraft.world.level.levelgen.structure.pieces.StructurePiecesBuilder; import org.confluence.lib.ConfluenceMagicLib; import org.confluence.lib.common.data.IdFixer; +import org.confluence.lib.util.LibCodecUtils; import org.confluence.lib.util.LibUtils; import org.jetbrains.annotations.ApiStatus; @@ -34,8 +35,8 @@ import java.util.function.Function; public class GridPiece extends StructurePiece { - public static final Codec>> BLOCK_MAP_CODEC = LibUtils.tupleCodec(Codec.INT, Codec.INT.listOf().xmap(IntArrayList::new, Function.identity())).listOf(); - public static final Codec>> FEATURES_CODEC = LibUtils.tupleCodec(BlockPos.CODEC, ResourceLocation.CODEC).listOf(); + public static final Codec>> BLOCK_MAP_CODEC = LibCodecUtils.tupleCodec(Codec.INT, Codec.INT.listOf().xmap(IntArrayList::new, Function.identity())).listOf(); + public static final Codec>> FEATURES_CODEC = LibCodecUtils.tupleCodec(BlockPos.CODEC, ResourceLocation.CODEC).listOf(); private final ChunkPos startPos; private final List> blockMap; diff --git a/src/main/java/org/confluence/lib/util/LibCodecUtils.java b/src/main/java/org/confluence/lib/util/LibCodecUtils.java new file mode 100644 index 0000000..ef5b3b3 --- /dev/null +++ b/src/main/java/org/confluence/lib/util/LibCodecUtils.java @@ -0,0 +1,37 @@ +package org.confluence.lib.util; + +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import net.minecraft.util.Tuple; +import net.minecraft.world.phys.Vec2; +import org.apache.commons.lang3.tuple.ImmutableTriple; + +public final class LibCodecUtils { + public static final Codec VEC_2_CODEC = RecordCodecBuilder.create(instance -> instance.group( + Codec.FLOAT.fieldOf("x").forGetter(vec2 -> vec2.x), + Codec.FLOAT.fieldOf("y").forGetter(vec2 -> vec2.y) + ).apply(instance, Vec2::new)); + + public static Codec> tupleCodec(Codec aCodec, Codec bCodec) { + return tupleCodec("a", aCodec, "b", bCodec); + } + + public static Codec> tupleCodec(String aName, Codec aCodec, String bName, Codec bCodec) { + return RecordCodecBuilder.create(instance -> instance.group( + aCodec.fieldOf(aName).forGetter(Tuple::getA), + bCodec.fieldOf(bName).forGetter(Tuple::getB) + ).apply(instance, Tuple::new)); + } + + public static Codec> tripleCodec(Codec lCodec, Codec mCodec, Codec rCodec) { + return tripleCodec("l", lCodec, "m", mCodec, "r", rCodec); + } + + public static Codec> tripleCodec(String lName, Codec lCodec, String mName, Codec mCodec, String rName, Codec rCodec) { + return RecordCodecBuilder.create(instance -> instance.group( + lCodec.fieldOf(lName).forGetter(ImmutableTriple::getLeft), + mCodec.fieldOf(mName).forGetter(ImmutableTriple::getMiddle), + rCodec.fieldOf(rName).forGetter(ImmutableTriple::getRight) + ).apply(instance, ImmutableTriple::new)); + } +} diff --git a/src/main/java/org/confluence/lib/util/LibStreamCodecUtils.java b/src/main/java/org/confluence/lib/util/LibStreamCodecUtils.java new file mode 100644 index 0000000..ebd1f6e --- /dev/null +++ b/src/main/java/org/confluence/lib/util/LibStreamCodecUtils.java @@ -0,0 +1,36 @@ +package org.confluence.lib.util; + +import io.netty.buffer.ByteBuf; +import net.minecraft.MethodsReturnNonnullByDefault; +import net.minecraft.network.codec.ByteBufCodecs; +import net.minecraft.network.codec.StreamCodec; +import net.minecraft.world.phys.Vec2; + +import javax.annotation.ParametersAreNonnullByDefault; +import java.util.function.Supplier; + +@ParametersAreNonnullByDefault +@MethodsReturnNonnullByDefault +public final class LibStreamCodecUtils { + public static final StreamCodec VEC_2_STREAM_CODEC = StreamCodec.composite( + ByteBufCodecs.FLOAT, vec2 -> vec2.x, + ByteBufCodecs.FLOAT, vec2 -> vec2.y, + Vec2::new + ); + + public static StreamCodec unit(Supplier expectedValue) { + return new StreamCodec<>() { + @Override + public V decode(B buffer) { + return expectedValue.get(); + } + + @Override + public void encode(B buffer, V value) { + if (!value.equals(expectedValue.get())) { + throw new IllegalStateException("Can't encode '" + value + "', expected '" + expectedValue.get() + "'"); + } + } + }; + } +} diff --git a/src/main/java/org/confluence/lib/util/LibUtils.java b/src/main/java/org/confluence/lib/util/LibUtils.java index 597bc2e..16ade24 100644 --- a/src/main/java/org/confluence/lib/util/LibUtils.java +++ b/src/main/java/org/confluence/lib/util/LibUtils.java @@ -1,14 +1,12 @@ package org.confluence.lib.util; import com.mojang.serialization.Codec; -import com.mojang.serialization.codecs.RecordCodecBuilder; import io.netty.buffer.ByteBuf; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.core.component.DataComponentType; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.Tag; -import net.minecraft.network.codec.ByteBufCodecs; import net.minecraft.network.codec.StreamCodec; import net.minecraft.tags.TagKey; import net.minecraft.util.RandomSource; @@ -51,15 +49,8 @@ public final class LibUtils { public static final int MAX_STACK_SIZE = 9999; public static final String NO_DROPS_TAG = "confluence:no_drops"; public static final EffectCure DENY_HEAL = EffectCure.get("confluence:deny_heal"); - public static final Codec VEC_2_CODEC = RecordCodecBuilder.create(instance -> instance.group( - Codec.FLOAT.fieldOf("x").forGetter(vec2 -> vec2.x), - Codec.FLOAT.fieldOf("y").forGetter(vec2 -> vec2.y) - ).apply(instance, Vec2::new)); - public static final StreamCodec VEC_2_STREAM_CODEC = StreamCodec.composite( - ByteBufCodecs.FLOAT, vec2 -> vec2.x, - ByteBufCodecs.FLOAT, vec2 -> vec2.y, - Vec2::new - ); + public static final @Deprecated Codec VEC_2_CODEC = LibCodecUtils.VEC_2_CODEC; + public static final @Deprecated StreamCodec VEC_2_STREAM_CODEC = LibStreamCodecUtils.VEC_2_STREAM_CODEC; @ApiStatus.Internal public static void forMixin$Inject() {} @@ -180,19 +171,14 @@ public static void devRun(Runnable runnable) { } } + @Deprecated public static Codec> tupleCodec(Codec aCodec, Codec bCodec) { - return RecordCodecBuilder.create(instance -> instance.group( - aCodec.fieldOf("a").forGetter(Tuple::getA), - bCodec.fieldOf("b").forGetter(Tuple::getB) - ).apply(instance, Tuple::new)); + return LibCodecUtils.tupleCodec(aCodec, bCodec); } + @Deprecated public static Codec> tripleCodec(Codec lCodec, Codec mCodec, Codec rCodec) { - return RecordCodecBuilder.create(instance -> instance.group( - lCodec.fieldOf("l").forGetter(ImmutableTriple::getLeft), - mCodec.fieldOf("m").forGetter(ImmutableTriple::getMiddle), - rCodec.fieldOf("r").forGetter(ImmutableTriple::getRight) - ).apply(instance, ImmutableTriple::new)); + return LibCodecUtils.tripleCodec(lCodec, mCodec, rCodec); } public static void setItemAndDropChance(Mob mob, DifficultyInstance difficulty, EquipmentSlot slot, Item item, float chance) { From d60a436963204eba8f354e029fb9f6bbf0d04dba Mon Sep 17 00:00:00 2001 From: westernat Date: Fri, 15 Aug 2025 00:17:29 +0800 Subject: [PATCH 17/61] =?UTF-8?q?=E7=8E=AF=E5=A2=83=E6=A3=80=E6=B5=8B?= =?UTF-8?q?=E5=90=88=E6=88=90=E6=94=B9=E4=B8=BA=E6=95=B0=E6=8D=AE=E9=A9=B1?= =?UTF-8?q?=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...HorizontalDirectionalWaterloggedBlock.java | 9 +- ...talDirectionalWithForwardTwoPartBlock.java | 9 +- ...irectionalWithHorizontalFourPartBlock.java | 9 +- ...DirectionalWithHorizontalTwoPartBlock.java | 9 +- ...lDirectionalWithVerticalFourPartBlock.java | 9 +- ...alDirectionalWithVerticalTwoPartBlock.java | 9 +- .../common/recipe/AbstractAmountRecipe.java | 17 +--- .../common/recipe/EitherAmountRecipe4x.java | 36 ++----- .../recipe/EnvironmentAmountRecipe.java | 47 +++++++++ .../EnvironmentEitherAmountRecipe4x.java | 76 ++++++++++++++ .../common/recipe/EnvironmentLevelAccess.java | 99 +++++++++++++++++++ .../lib/util/LibStreamCodecUtils.java | 5 + 12 files changed, 290 insertions(+), 44 deletions(-) create mode 100644 src/main/java/org/confluence/lib/common/recipe/EnvironmentAmountRecipe.java create mode 100644 src/main/java/org/confluence/lib/common/recipe/EnvironmentEitherAmountRecipe4x.java diff --git a/src/main/java/org/confluence/lib/common/block/HorizontalDirectionalWaterloggedBlock.java b/src/main/java/org/confluence/lib/common/block/HorizontalDirectionalWaterloggedBlock.java index 5266da2..31f8d5d 100644 --- a/src/main/java/org/confluence/lib/common/block/HorizontalDirectionalWaterloggedBlock.java +++ b/src/main/java/org/confluence/lib/common/block/HorizontalDirectionalWaterloggedBlock.java @@ -1,5 +1,6 @@ package org.confluence.lib.common.block; +import com.mojang.serialization.MapCodec; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.world.item.context.BlockPlaceContext; @@ -14,7 +15,8 @@ import net.minecraft.world.level.material.FluidState; import net.minecraft.world.level.material.Fluids; -public abstract class HorizontalDirectionalWaterloggedBlock extends HorizontalDirectionalBlock implements SimpleWaterloggedBlock { +public class HorizontalDirectionalWaterloggedBlock extends HorizontalDirectionalBlock implements SimpleWaterloggedBlock { + public static final MapCodec CODEC = simpleCodec(HorizontalDirectionalWaterloggedBlock::new); public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED; public HorizontalDirectionalWaterloggedBlock(Properties properties) { @@ -22,6 +24,11 @@ public HorizontalDirectionalWaterloggedBlock(Properties properties) { registerDefaultState(stateDefinition.any().setValue(FACING, Direction.NORTH).setValue(WATERLOGGED, false)); } + @Override + protected MapCodec codec() { + return CODEC; + } + @Override protected void createBlockStateDefinition(StateDefinition.Builder builder) { builder.add(FACING, WATERLOGGED); diff --git a/src/main/java/org/confluence/lib/common/block/HorizontalDirectionalWithForwardTwoPartBlock.java b/src/main/java/org/confluence/lib/common/block/HorizontalDirectionalWithForwardTwoPartBlock.java index 0e6cac6..70167e7 100644 --- a/src/main/java/org/confluence/lib/common/block/HorizontalDirectionalWithForwardTwoPartBlock.java +++ b/src/main/java/org/confluence/lib/common/block/HorizontalDirectionalWithForwardTwoPartBlock.java @@ -1,5 +1,6 @@ package org.confluence.lib.common.block; +import com.mojang.serialization.MapCodec; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.world.entity.LivingEntity; @@ -14,7 +15,8 @@ import net.minecraft.world.level.material.PushReaction; import org.jetbrains.annotations.Nullable; -public abstract class HorizontalDirectionalWithForwardTwoPartBlock extends HorizontalDirectionalBlock { +public class HorizontalDirectionalWithForwardTwoPartBlock extends HorizontalDirectionalBlock { + public static final MapCodec CODEC = simpleCodec(HorizontalDirectionalWithForwardTwoPartBlock::new); public static final EnumProperty PART = StateProperties.FORWARD_TWO_PART; public HorizontalDirectionalWithForwardTwoPartBlock(Properties properties) { @@ -22,6 +24,11 @@ public HorizontalDirectionalWithForwardTwoPartBlock(Properties properties) { registerDefaultState(stateDefinition.any().setValue(PART, StateProperties.ForwardTwoPart.BASE).setValue(FACING, Direction.NORTH)); } + @Override + protected MapCodec codec() { + return CODEC; + } + @Override protected void createBlockStateDefinition(StateDefinition.Builder builder) { builder.add(StateProperties.FORWARD_TWO_PART, FACING); diff --git a/src/main/java/org/confluence/lib/common/block/HorizontalDirectionalWithHorizontalFourPartBlock.java b/src/main/java/org/confluence/lib/common/block/HorizontalDirectionalWithHorizontalFourPartBlock.java index 57a6a30..1d140c5 100644 --- a/src/main/java/org/confluence/lib/common/block/HorizontalDirectionalWithHorizontalFourPartBlock.java +++ b/src/main/java/org/confluence/lib/common/block/HorizontalDirectionalWithHorizontalFourPartBlock.java @@ -1,5 +1,6 @@ package org.confluence.lib.common.block; +import com.mojang.serialization.MapCodec; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.world.entity.LivingEntity; @@ -16,7 +17,8 @@ import java.util.Map; -public abstract class HorizontalDirectionalWithHorizontalFourPartBlock extends HorizontalDirectionalBlock { +public class HorizontalDirectionalWithHorizontalFourPartBlock extends HorizontalDirectionalBlock { + public static final MapCodec CODEC = simpleCodec(HorizontalDirectionalWithHorizontalFourPartBlock::new); public static final EnumProperty PART = StateProperties.HORIZONTAL_FOUR_PART; protected HorizontalDirectionalWithHorizontalFourPartBlock(Properties properties) { @@ -24,6 +26,11 @@ protected HorizontalDirectionalWithHorizontalFourPartBlock(Properties properties registerDefaultState(stateDefinition.any().setValue(PART, StateProperties.HorizontalFourPart.BASE).setValue(FACING, Direction.NORTH)); } + @Override + protected MapCodec codec() { + return CODEC; + } + @Override protected void createBlockStateDefinition(StateDefinition.Builder builder) { builder.add(StateProperties.HORIZONTAL_FOUR_PART, FACING); diff --git a/src/main/java/org/confluence/lib/common/block/HorizontalDirectionalWithHorizontalTwoPartBlock.java b/src/main/java/org/confluence/lib/common/block/HorizontalDirectionalWithHorizontalTwoPartBlock.java index 9b6db6e..70ec201 100644 --- a/src/main/java/org/confluence/lib/common/block/HorizontalDirectionalWithHorizontalTwoPartBlock.java +++ b/src/main/java/org/confluence/lib/common/block/HorizontalDirectionalWithHorizontalTwoPartBlock.java @@ -1,5 +1,6 @@ package org.confluence.lib.common.block; +import com.mojang.serialization.MapCodec; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.world.entity.LivingEntity; @@ -14,7 +15,8 @@ import net.minecraft.world.level.material.PushReaction; import org.jetbrains.annotations.Nullable; -public abstract class HorizontalDirectionalWithHorizontalTwoPartBlock extends HorizontalDirectionalBlock { +public class HorizontalDirectionalWithHorizontalTwoPartBlock extends HorizontalDirectionalBlock { + public static final MapCodec CODEC = simpleCodec(HorizontalDirectionalWithHorizontalTwoPartBlock::new); public static final EnumProperty PART = StateProperties.HORIZONTAL_TWO_PART; public HorizontalDirectionalWithHorizontalTwoPartBlock(Properties properties) { @@ -22,6 +24,11 @@ public HorizontalDirectionalWithHorizontalTwoPartBlock(Properties properties) { registerDefaultState(stateDefinition.any().setValue(PART, StateProperties.HorizontalTwoPart.BASE).setValue(FACING, Direction.NORTH)); } + @Override + protected MapCodec codec() { + return CODEC; + } + @Override protected void createBlockStateDefinition(StateDefinition.Builder builder) { builder.add(PART, FACING); diff --git a/src/main/java/org/confluence/lib/common/block/HorizontalDirectionalWithVerticalFourPartBlock.java b/src/main/java/org/confluence/lib/common/block/HorizontalDirectionalWithVerticalFourPartBlock.java index 919904c..ca933e7 100644 --- a/src/main/java/org/confluence/lib/common/block/HorizontalDirectionalWithVerticalFourPartBlock.java +++ b/src/main/java/org/confluence/lib/common/block/HorizontalDirectionalWithVerticalFourPartBlock.java @@ -1,5 +1,6 @@ package org.confluence.lib.common.block; +import com.mojang.serialization.MapCodec; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.world.entity.LivingEntity; @@ -14,7 +15,8 @@ import net.minecraft.world.level.material.PushReaction; import org.jetbrains.annotations.Nullable; -public abstract class HorizontalDirectionalWithVerticalFourPartBlock extends HorizontalDirectionalBlock { +public class HorizontalDirectionalWithVerticalFourPartBlock extends HorizontalDirectionalBlock { + public static final MapCodec CODEC = simpleCodec(HorizontalDirectionalWithVerticalFourPartBlock::new); public static final EnumProperty PART = StateProperties.VERTICAL_FOUR_PART; public HorizontalDirectionalWithVerticalFourPartBlock(Properties properties) { @@ -22,6 +24,11 @@ public HorizontalDirectionalWithVerticalFourPartBlock(Properties properties) { registerDefaultState(stateDefinition.any().setValue(PART, StateProperties.VerticalFourPart.BASE).setValue(FACING, Direction.NORTH)); } + @Override + protected MapCodec codec() { + return CODEC; + } + @Override protected void createBlockStateDefinition(StateDefinition.Builder builder) { builder.add(PART, FACING); diff --git a/src/main/java/org/confluence/lib/common/block/HorizontalDirectionalWithVerticalTwoPartBlock.java b/src/main/java/org/confluence/lib/common/block/HorizontalDirectionalWithVerticalTwoPartBlock.java index 6610097..10244b5 100644 --- a/src/main/java/org/confluence/lib/common/block/HorizontalDirectionalWithVerticalTwoPartBlock.java +++ b/src/main/java/org/confluence/lib/common/block/HorizontalDirectionalWithVerticalTwoPartBlock.java @@ -1,5 +1,6 @@ package org.confluence.lib.common.block; +import com.mojang.serialization.MapCodec; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.world.entity.LivingEntity; @@ -14,7 +15,8 @@ import net.minecraft.world.level.material.PushReaction; import org.jetbrains.annotations.Nullable; -public abstract class HorizontalDirectionalWithVerticalTwoPartBlock extends HorizontalDirectionalBlock { +public class HorizontalDirectionalWithVerticalTwoPartBlock extends HorizontalDirectionalBlock { + public static final MapCodec CODEC = simpleCodec(HorizontalDirectionalWithVerticalTwoPartBlock::new); public static final EnumProperty PART = StateProperties.VERTICAL_TWO_PART; public HorizontalDirectionalWithVerticalTwoPartBlock(Properties properties) { @@ -22,6 +24,11 @@ public HorizontalDirectionalWithVerticalTwoPartBlock(Properties properties) { registerDefaultState(stateDefinition.any().setValue(FACING, Direction.NORTH).setValue(PART, StateProperties.VerticalTwoPart.BASE)); } + @Override + protected MapCodec codec() { + return CODEC; + } + @Override protected void createBlockStateDefinition(StateDefinition.Builder builder) { builder.add(FACING, PART); diff --git a/src/main/java/org/confluence/lib/common/recipe/AbstractAmountRecipe.java b/src/main/java/org/confluence/lib/common/recipe/AbstractAmountRecipe.java index 8d5e7d0..03ffbce 100644 --- a/src/main/java/org/confluence/lib/common/recipe/AbstractAmountRecipe.java +++ b/src/main/java/org/confluence/lib/common/recipe/AbstractAmountRecipe.java @@ -228,17 +228,10 @@ public static > MapCodec shapelessSerialize } public static > StreamCodec shapelessSerializerSteamCodec(BiFunction, R> factory) { - return new StreamCodec<>() { - @Override - public R decode(RegistryFriendlyByteBuf buffer) { - return factory.apply(ItemStack.STREAM_CODEC.decode(buffer), ExtraByteBufCodecs.INGREDIENTS.decode(buffer)); - } - - @Override - public void encode(RegistryFriendlyByteBuf buffer, R recipe) { - ItemStack.STREAM_CODEC.encode(buffer, recipe.result); - ExtraByteBufCodecs.INGREDIENTS.encode(buffer, recipe.ingredients); - } - }; + return StreamCodec.composite( + ItemStack.STREAM_CODEC, r -> r.result, + ExtraByteBufCodecs.INGREDIENTS, r -> r.getIngredients(), + factory + ); } } diff --git a/src/main/java/org/confluence/lib/common/recipe/EitherAmountRecipe4x.java b/src/main/java/org/confluence/lib/common/recipe/EitherAmountRecipe4x.java index 67b4b17..a41215b 100644 --- a/src/main/java/org/confluence/lib/common/recipe/EitherAmountRecipe4x.java +++ b/src/main/java/org/confluence/lib/common/recipe/EitherAmountRecipe4x.java @@ -85,20 +85,11 @@ public static > MapCodec shapedSerializerMa } public static > StreamCodec shapedSerializerSteamCodec(BiFunction factory) { - return new StreamCodec<>() { - @Override - public R decode(RegistryFriendlyByteBuf buffer) { - ItemStack itemstack = ItemStack.STREAM_CODEC.decode(buffer); - ShapedRecipePattern shapedrecipepattern = ShapedRecipePattern.STREAM_CODEC.decode(buffer); - return factory.apply(itemstack, shapedrecipepattern); - } - - @Override - public void encode(RegistryFriendlyByteBuf buffer, R recipe) { - ItemStack.STREAM_CODEC.encode(buffer, recipe.result); - ShapedRecipePattern.STREAM_CODEC.encode(buffer, recipe.either.left().orElseThrow()); - } - }; + return StreamCodec.composite( + ItemStack.STREAM_CODEC, r -> r.result, + ShapedRecipePattern.STREAM_CODEC, r -> r.either.left().orElseThrow(), + factory + ); } public static > MapCodec eitherSerializerMapCodec(BiFunction>, R> factory) { @@ -109,17 +100,10 @@ public static > MapCodec eitherSerializerMa } public static > StreamCodec eitherSerializerStreamCodec(BiFunction>, R> factory) { - return new StreamCodec<>() { - @Override - public R decode(RegistryFriendlyByteBuf buffer) { - return factory.apply(ItemStack.STREAM_CODEC.decode(buffer), EITHER_CODEC.decode(buffer)); - } - - @Override - public void encode(RegistryFriendlyByteBuf buffer, R recipe) { - ItemStack.STREAM_CODEC.encode(buffer, recipe.result); - EITHER_CODEC.encode(buffer, recipe.either); - } - }; + return StreamCodec.composite( + ItemStack.STREAM_CODEC, r -> r.result, + EITHER_CODEC, r -> r.either, + factory + ); } } diff --git a/src/main/java/org/confluence/lib/common/recipe/EnvironmentAmountRecipe.java b/src/main/java/org/confluence/lib/common/recipe/EnvironmentAmountRecipe.java new file mode 100644 index 0000000..0618686 --- /dev/null +++ b/src/main/java/org/confluence/lib/common/recipe/EnvironmentAmountRecipe.java @@ -0,0 +1,47 @@ +package org.confluence.lib.common.recipe; + +import com.mojang.datafixers.util.Function3; +import com.mojang.serialization.MapCodec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import net.minecraft.core.NonNullList; +import net.minecraft.network.RegistryFriendlyByteBuf; +import net.minecraft.network.codec.StreamCodec; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.Ingredient; +import net.minecraft.world.level.Level; +import org.confluence.lib.network.ExtraByteBufCodecs; + +public abstract class EnvironmentAmountRecipe extends AbstractAmountRecipe { + protected final EnvironmentLevelAccess.Matcher environment; + + protected EnvironmentAmountRecipe(ItemStack result, NonNullList ingredients, EnvironmentLevelAccess.Matcher environment) { + super(result, ingredients); + this.environment = environment; + } + + public EnvironmentLevelAccess.Matcher getEnvironment() { + return environment; + } + + @Override + public boolean matches(EnvironmentRecipeInput input, Level pLevel) { + return environment.matches(input.getAccess()) && super.matches(input, pLevel); + } + + public static MapCodec environmentShapelessSerializerMapCodec(Function3, EnvironmentLevelAccess.Matcher, R> factory) { + return RecordCodecBuilder.mapCodec(instance -> instance.group( + ItemStack.STRICT_CODEC.fieldOf("result").forGetter(recipe -> recipe.result), + INGREDIENTS_CODEC.forGetter(recipe -> recipe.ingredients), + EnvironmentLevelAccess.Matcher.MAP_CODEC.forGetter(EnvironmentAmountRecipe::getEnvironment) + ).apply(instance, factory)); + } + + public static StreamCodec environmentShapelessSerializerSteamCodec(Function3, EnvironmentLevelAccess.Matcher, R> factory) { + return StreamCodec.composite( + ItemStack.STREAM_CODEC, r -> r.result, + ExtraByteBufCodecs.INGREDIENTS, AbstractAmountRecipe::getIngredients, + EnvironmentLevelAccess.Matcher.STREAM_CODEC, EnvironmentAmountRecipe::getEnvironment, + factory + ); + } +} diff --git a/src/main/java/org/confluence/lib/common/recipe/EnvironmentEitherAmountRecipe4x.java b/src/main/java/org/confluence/lib/common/recipe/EnvironmentEitherAmountRecipe4x.java new file mode 100644 index 0000000..ce5db56 --- /dev/null +++ b/src/main/java/org/confluence/lib/common/recipe/EnvironmentEitherAmountRecipe4x.java @@ -0,0 +1,76 @@ +package org.confluence.lib.common.recipe; + +import com.mojang.datafixers.util.Either; +import com.mojang.datafixers.util.Function3; +import com.mojang.serialization.Codec; +import com.mojang.serialization.MapCodec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import net.minecraft.core.NonNullList; +import net.minecraft.network.RegistryFriendlyByteBuf; +import net.minecraft.network.codec.StreamCodec; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.Ingredient; +import net.minecraft.world.item.crafting.ShapedRecipePattern; +import net.minecraft.world.level.Level; + +public abstract class EnvironmentEitherAmountRecipe4x extends EitherAmountRecipe4x { + protected final EnvironmentLevelAccess.Matcher environment; + + public EnvironmentEitherAmountRecipe4x(ItemStack result, ShapedRecipePattern pattern, EnvironmentLevelAccess.Matcher environment) { + super(result, pattern); + this.environment = environment; + } + + public EnvironmentEitherAmountRecipe4x(ItemStack result, NonNullList ingredients, EnvironmentLevelAccess.Matcher environment) { + super(result, ingredients); + this.environment = environment; + } + + public EnvironmentEitherAmountRecipe4x(ItemStack result, Either> either, EnvironmentLevelAccess.Matcher environment) { + super(result, either); + this.environment = environment; + } + + public EnvironmentLevelAccess.Matcher getEnvironment() { + return environment; + } + + @Override + public boolean matches(EnvironmentRecipeInput input, Level level) { + return environment.matches(input.getAccess()) && super.matches(input, level); + } + + public static MapCodec environmentShapedSerializerMapCodec(Function3 factory) { + return RecordCodecBuilder.mapCodec(instance -> instance.group( + ItemStack.STRICT_CODEC.fieldOf("result").forGetter(recipe -> recipe.result), + ShapedRecipePattern.MAP_CODEC.forGetter(recipe -> recipe.either.left().orElseThrow()), + EnvironmentLevelAccess.Matcher.MAP_CODEC.forGetter(EnvironmentEitherAmountRecipe4x::getEnvironment) + ).apply(instance, factory)); + } + + public static StreamCodec environmentShapedSerializerSteamCodec(Function3 factory) { + return StreamCodec.composite( + ItemStack.STREAM_CODEC, r -> r.result, + ShapedRecipePattern.STREAM_CODEC, r -> r.either.left().orElseThrow(), + EnvironmentLevelAccess.Matcher.STREAM_CODEC, EnvironmentEitherAmountRecipe4x::getEnvironment, + factory + ); + } + + public static MapCodec environmentEitherSerializerMapCodec(Function3>, EnvironmentLevelAccess.Matcher, R> factory) { + return RecordCodecBuilder.mapCodec(instance -> instance.group( + ItemStack.STRICT_CODEC.fieldOf("result").forGetter(recipe -> recipe.result), + Codec.mapEither(ShapedRecipePattern.MAP_CODEC, INGREDIENTS_CODEC).forGetter(recipe -> recipe.either), + EnvironmentLevelAccess.Matcher.MAP_CODEC.forGetter(EnvironmentEitherAmountRecipe4x::getEnvironment) + ).apply(instance, factory)); + } + + public static StreamCodec environmentEitherSerializerStreamCodec(Function3>, EnvironmentLevelAccess.Matcher, R> factory) { + return StreamCodec.composite( + ItemStack.STREAM_CODEC, r -> r.result, + EITHER_CODEC, r -> r.either, + EnvironmentLevelAccess.Matcher.STREAM_CODEC, EnvironmentEitherAmountRecipe4x::getEnvironment, + factory + ); + } +} diff --git a/src/main/java/org/confluence/lib/common/recipe/EnvironmentLevelAccess.java b/src/main/java/org/confluence/lib/common/recipe/EnvironmentLevelAccess.java index 4615167..b4b1319 100644 --- a/src/main/java/org/confluence/lib/common/recipe/EnvironmentLevelAccess.java +++ b/src/main/java/org/confluence/lib/common/recipe/EnvironmentLevelAccess.java @@ -1,18 +1,32 @@ package org.confluence.lib.common.recipe; +import com.mojang.serialization.Codec; +import com.mojang.serialization.MapCodec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import net.minecraft.advancements.critereon.StatePropertiesPredicate; import net.minecraft.core.BlockPos; import net.minecraft.core.Holder; +import net.minecraft.core.HolderSet; +import net.minecraft.core.RegistryCodecs; +import net.minecraft.core.registries.Registries; +import net.minecraft.network.RegistryFriendlyByteBuf; +import net.minecraft.network.codec.ByteBufCodecs; +import net.minecraft.network.codec.StreamCodec; +import net.minecraft.util.ExtraCodecs; import net.minecraft.world.entity.player.Player; import net.minecraft.world.inventory.ContainerLevelAccess; import net.minecraft.world.item.crafting.Recipe; import net.minecraft.world.level.ClipContext; import net.minecraft.world.level.Level; import net.minecraft.world.level.biome.Biome; +import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.material.Fluid; import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.HitResult; import net.minecraft.world.phys.Vec3; import net.minecraft.world.phys.shapes.CollisionContext; +import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; import java.util.List; @@ -58,6 +72,7 @@ public void initializeIfNeeded(Player player) { return pos; } + @ApiStatus.OverrideOnly public > boolean matches(R recipe) { return true; } @@ -89,4 +104,88 @@ public boolean anyMatch(Predicate predicate, int inflate) { public Optional evaluate(BiFunction levelPosConsumer) { return level == null || pos == null ? Optional.empty() : Optional.of(levelPosConsumer.apply(level, pos)); } + + public static Matcher matcher(@Nullable HolderSet biome, @Nullable SearchContext block, boolean graveyard) { + return new Matcher(Optional.ofNullable(biome), Optional.ofNullable(block), graveyard); + } + + public record Matcher(Optional> biome, Optional block, boolean graveyard) { + public static final Matcher EMPTY = new Matcher(Optional.empty(), Optional.empty(), false); + public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( + RegistryCodecs.homogeneousList(Registries.BIOME).lenientOptionalFieldOf("biome").forGetter(Matcher::biome), + SearchContext.CODEC.lenientOptionalFieldOf("block").forGetter(Matcher::block), + Codec.BOOL.lenientOptionalFieldOf("graveyard", false).forGetter(Matcher::graveyard) + ).apply(instance, Matcher::new)); + public static final MapCodec MAP_CODEC = CODEC.lenientOptionalFieldOf("environment", EMPTY); + public static final StreamCodec STREAM_CODEC = StreamCodec.composite( + ByteBufCodecs.optional(ByteBufCodecs.holderSet(Registries.BIOME)), Matcher::biome, + ByteBufCodecs.optional(SearchContext.STREAM_CODEC), Matcher::block, + ByteBufCodecs.BOOL, Matcher::graveyard, + Matcher::new + ); + + public boolean matches(EnvironmentLevelAccess access) { + Level level = access.getLevel(); + BlockPos pos = access.getPos(); + if (level == null || pos == null) return false; + if (!matchesBiome(level, pos)) return false; + if (!matchesBlock(level, pos)) return false; + if (!matchesGraveyard(level, pos)) return false; + return true; + } + + public boolean matchesBiome(Level level, BlockPos pos) { + return biome.isEmpty() || biome.get().contains(level.getBiome(pos)); + } + + public boolean matchesBlock(Level level, BlockPos pos) { + return block.isEmpty() || block.get().matches(level, pos); + } + + public boolean matchesGraveyard(Level level, BlockPos pos) { + return !graveyard || isGraveyard(level, pos); + } + + private static boolean isGraveyard(Level level, BlockPos pos) { + return true; // confluence mixin here + } + } + + public record SearchContext(int inflate, Optional> blocks, List statePredicates, Optional> fluids) { + public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( + ExtraCodecs.POSITIVE_INT.fieldOf("inflate").forGetter(SearchContext::inflate), + RegistryCodecs.homogeneousList(Registries.BLOCK).lenientOptionalFieldOf("blocks").forGetter(SearchContext::blocks), + StatePropertiesPredicate.CODEC.listOf().lenientOptionalFieldOf("state_predicates", List.of()).forGetter(SearchContext::statePredicates), + RegistryCodecs.homogeneousList(Registries.FLUID).lenientOptionalFieldOf("fluids").forGetter(SearchContext::fluids) + ).apply(instance, SearchContext::new)); + public static final StreamCodec STREAM_CODEC = StreamCodec.composite( + ByteBufCodecs.VAR_INT, SearchContext::inflate, + ByteBufCodecs.optional(ByteBufCodecs.holderSet(Registries.BLOCK)), SearchContext::blocks, + StatePropertiesPredicate.STREAM_CODEC.apply(ByteBufCodecs.list()), SearchContext::statePredicates, + ByteBufCodecs.optional(ByteBufCodecs.holderSet(Registries.FLUID)), SearchContext::fluids, + SearchContext::new + ); + + public boolean matches(Level level, BlockPos pos) { + if (blocks.isPresent() || !statePredicates.isEmpty() || fluids.isPresent()) { + for (BlockPos blockPos : BlockPos.betweenClosed(pos.offset(-inflate, -inflate, -inflate), pos.offset(inflate, inflate, inflate))) { + BlockState blockState = level.getBlockState(blockPos); + if (blocks.isPresent() && blockState.is(blocks.get())) return true; + if (statePredicates.stream().anyMatch(predicates -> predicates.matches(blockState))) return true; + if (fluids.isPresent() && blockState.getFluidState().is(fluids.get())) return true; + } + return false; + } + return true; + } + + public String toDescription() { + // todo + return "{" + + ", blocks=" + blocks + + ", statePredicates=" + statePredicates + + ", fluids=" + fluids + + '}'; + } + } } diff --git a/src/main/java/org/confluence/lib/util/LibStreamCodecUtils.java b/src/main/java/org/confluence/lib/util/LibStreamCodecUtils.java index ebd1f6e..d39ac58 100644 --- a/src/main/java/org/confluence/lib/util/LibStreamCodecUtils.java +++ b/src/main/java/org/confluence/lib/util/LibStreamCodecUtils.java @@ -4,6 +4,7 @@ import net.minecraft.MethodsReturnNonnullByDefault; import net.minecraft.network.codec.ByteBufCodecs; import net.minecraft.network.codec.StreamCodec; +import net.minecraft.util.Tuple; import net.minecraft.world.phys.Vec2; import javax.annotation.ParametersAreNonnullByDefault; @@ -33,4 +34,8 @@ public void encode(B buffer, V value) { } }; } + + public static StreamCodec> tuple(StreamCodec aCodec, StreamCodec bCodec) { + return StreamCodec.composite(aCodec, Tuple::getA, bCodec, Tuple::getB, Tuple::new); + } } From a6a190bb89583df63de8b3e5ae436ba3114f97a9 Mon Sep 17 00:00:00 2001 From: westernat Date: Fri, 15 Aug 2025 10:47:59 +0800 Subject: [PATCH 18/61] =?UTF-8?q?=E5=B7=A5=E5=8C=A0=E4=BD=9C=E5=9D=8A?= =?UTF-8?q?=E7=9B=B4=E6=8E=A5=E5=8A=A0=E4=B8=8A=E7=8E=AF=E5=A2=83=E6=A3=80?= =?UTF-8?q?=E6=B5=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lib/common/recipe/EnvironmentLevelAccess.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/confluence/lib/common/recipe/EnvironmentLevelAccess.java b/src/main/java/org/confluence/lib/common/recipe/EnvironmentLevelAccess.java index b4b1319..c7b9a77 100644 --- a/src/main/java/org/confluence/lib/common/recipe/EnvironmentLevelAccess.java +++ b/src/main/java/org/confluence/lib/common/recipe/EnvironmentLevelAccess.java @@ -44,9 +44,9 @@ public EnvironmentLevelAccess(@Nullable Level level, @Nullable BlockPos pos) { this.pos = pos; } - public void initializeIfNeeded(Level pLevel, BlockPos pPos) { - if (level == null) this.level = pLevel; - if (pos == null) this.pos = pPos; + public void initializeIfNeeded(Level level, BlockPos pos) { + if (this.level == null) this.level = level; + if (this.pos == null) this.pos = pos; } public void initializeIfNeeded(Player player) { @@ -105,6 +105,10 @@ public Optional evaluate(BiFunction levelPosConsumer) return level == null || pos == null ? Optional.empty() : Optional.of(levelPosConsumer.apply(level, pos)); } + public static EnvironmentLevelAccess empty() { + return new EnvironmentLevelAccess(null, null); + } + public static Matcher matcher(@Nullable HolderSet biome, @Nullable SearchContext block, boolean graveyard) { return new Matcher(Optional.ofNullable(biome), Optional.ofNullable(block), graveyard); } From 6f702b099f0e19ae6e8a828b72ce9cbc7343017f Mon Sep 17 00:00:00 2001 From: westernat Date: Sat, 16 Aug 2025 13:06:07 +0800 Subject: [PATCH 19/61] =?UTF-8?q?=E8=A1=A5=E4=B8=8A=E6=A0=91=E5=A6=96?= =?UTF-8?q?=E7=9A=84=E4=BA=A4=E6=98=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lib/common/recipe/EnvironmentLevelAccess.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/main/java/org/confluence/lib/common/recipe/EnvironmentLevelAccess.java b/src/main/java/org/confluence/lib/common/recipe/EnvironmentLevelAccess.java index c7b9a77..4463e14 100644 --- a/src/main/java/org/confluence/lib/common/recipe/EnvironmentLevelAccess.java +++ b/src/main/java/org/confluence/lib/common/recipe/EnvironmentLevelAccess.java @@ -30,6 +30,7 @@ import org.jetbrains.annotations.Nullable; import java.util.List; +import java.util.Objects; import java.util.Optional; import java.util.function.BiFunction; import java.util.function.Function; @@ -150,6 +151,20 @@ public boolean matchesGraveyard(Level level, BlockPos pos) { return !graveyard || isGraveyard(level, pos); } + @Override + public boolean equals(Object o) { + return o == this || (o instanceof Matcher(Optional> biome1, Optional block1, boolean graveyard1) && + graveyard == graveyard1 && Objects.equals(block, block1) && Objects.equals(biome, biome1)); + } + + @Override + public int hashCode() { + int result = Objects.hashCode(biome); + result = 31 * result + Objects.hashCode(block); + result = 31 * result + Boolean.hashCode(graveyard); + return result; + } + private static boolean isGraveyard(Level level, BlockPos pos) { return true; // confluence mixin here } From 85159a6e12c86d79356b30f26d84656b694d9cf0 Mon Sep 17 00:00:00 2001 From: westernat Date: Sat, 16 Aug 2025 19:59:02 +0800 Subject: [PATCH 20/61] =?UTF-8?q?=E9=92=93=E9=B1=BC=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E5=9F=BA=E6=9C=AC=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../confluence/lib/common/data/IdFixer.java | 2 +- .../lib/common/recipe/AmountIngredient.java | 12 ++++++--- .../common/worldgen/structure/GridPiece.java | 4 +-- .../confluence/lib/util/LibCodecUtils.java | 14 +++++----- .../org/confluence/lib/util/LibUtils.java | 26 ++++++++++++++++--- 5 files changed, 41 insertions(+), 17 deletions(-) diff --git a/src/main/java/org/confluence/lib/common/data/IdFixer.java b/src/main/java/org/confluence/lib/common/data/IdFixer.java index 62c1561..9058018 100644 --- a/src/main/java/org/confluence/lib/common/data/IdFixer.java +++ b/src/main/java/org/confluence/lib/common/data/IdFixer.java @@ -37,7 +37,7 @@ @ApiStatus.ScheduledForRemoval(inVersion = "1.3.0") public class IdFixer { public static final Codec>> FIXED_BLOCK_MAP_CODEC = Codec.lazyInitialized(() -> { - Codec>> codec = LibCodecUtils.tupleCodec(Codec.INT, Codec.LONG.listOf().xmap(LongArrayList::new, Function.identity())).listOf(); + Codec>> codec = LibCodecUtils.tuple(Codec.INT, Codec.LONG.listOf().xmap(LongArrayList::new, Function.identity())).listOf(); return new Codec<>() { @Override public DataResult>, T>> decode(DynamicOps ops, T input) { diff --git a/src/main/java/org/confluence/lib/common/recipe/AmountIngredient.java b/src/main/java/org/confluence/lib/common/recipe/AmountIngredient.java index 15467b2..550c60b 100644 --- a/src/main/java/org/confluence/lib/common/recipe/AmountIngredient.java +++ b/src/main/java/org/confluence/lib/common/recipe/AmountIngredient.java @@ -33,12 +33,12 @@ public Stream getItems() { } @Override - public boolean test(@Nullable ItemStack pStack) { - if (pStack == null) return false; - if (pStack.getCount() < amount) { + public boolean test(@Nullable ItemStack stack) { + if (stack == null) return false; + if (stack.getCount() < amount) { return false; } else { - return ingredient.test(pStack); + return ingredient.test(stack); } } @@ -71,4 +71,8 @@ public static Ingredient of(int amount, ItemStack... stacks) { public static Ingredient of(int amount, TagKey tag) { return new AmountIngredient(Ingredient.of(tag), amount).toVanilla(); } + + public static Ingredient of(ItemStack stack) { + return new AmountIngredient(Ingredient.of(stack), stack.getCount()).toVanilla(); + } } diff --git a/src/main/java/org/confluence/lib/common/worldgen/structure/GridPiece.java b/src/main/java/org/confluence/lib/common/worldgen/structure/GridPiece.java index 229a4f9..197890d 100644 --- a/src/main/java/org/confluence/lib/common/worldgen/structure/GridPiece.java +++ b/src/main/java/org/confluence/lib/common/worldgen/structure/GridPiece.java @@ -35,8 +35,8 @@ import java.util.function.Function; public class GridPiece extends StructurePiece { - public static final Codec>> BLOCK_MAP_CODEC = LibCodecUtils.tupleCodec(Codec.INT, Codec.INT.listOf().xmap(IntArrayList::new, Function.identity())).listOf(); - public static final Codec>> FEATURES_CODEC = LibCodecUtils.tupleCodec(BlockPos.CODEC, ResourceLocation.CODEC).listOf(); + public static final Codec>> BLOCK_MAP_CODEC = LibCodecUtils.tuple(Codec.INT, Codec.INT.listOf().xmap(IntArrayList::new, Function.identity())).listOf(); + public static final Codec>> FEATURES_CODEC = LibCodecUtils.tuple(BlockPos.CODEC, ResourceLocation.CODEC).listOf(); private final ChunkPos startPos; private final List> blockMap; diff --git a/src/main/java/org/confluence/lib/util/LibCodecUtils.java b/src/main/java/org/confluence/lib/util/LibCodecUtils.java index ef5b3b3..f56a79b 100644 --- a/src/main/java/org/confluence/lib/util/LibCodecUtils.java +++ b/src/main/java/org/confluence/lib/util/LibCodecUtils.java @@ -7,27 +7,27 @@ import org.apache.commons.lang3.tuple.ImmutableTriple; public final class LibCodecUtils { - public static final Codec VEC_2_CODEC = RecordCodecBuilder.create(instance -> instance.group( + public static final Codec VEC_2 = RecordCodecBuilder.create(instance -> instance.group( Codec.FLOAT.fieldOf("x").forGetter(vec2 -> vec2.x), Codec.FLOAT.fieldOf("y").forGetter(vec2 -> vec2.y) ).apply(instance, Vec2::new)); - public static Codec> tupleCodec(Codec aCodec, Codec bCodec) { - return tupleCodec("a", aCodec, "b", bCodec); + public static Codec> tuple(Codec aCodec, Codec bCodec) { + return tuple("a", aCodec, "b", bCodec); } - public static Codec> tupleCodec(String aName, Codec aCodec, String bName, Codec bCodec) { + public static Codec> tuple(String aName, Codec aCodec, String bName, Codec bCodec) { return RecordCodecBuilder.create(instance -> instance.group( aCodec.fieldOf(aName).forGetter(Tuple::getA), bCodec.fieldOf(bName).forGetter(Tuple::getB) ).apply(instance, Tuple::new)); } - public static Codec> tripleCodec(Codec lCodec, Codec mCodec, Codec rCodec) { - return tripleCodec("l", lCodec, "m", mCodec, "r", rCodec); + public static Codec> triple(Codec lCodec, Codec mCodec, Codec rCodec) { + return triple("l", lCodec, "m", mCodec, "r", rCodec); } - public static Codec> tripleCodec(String lName, Codec lCodec, String mName, Codec mCodec, String rName, Codec rCodec) { + public static Codec> triple(String lName, Codec lCodec, String mName, Codec mCodec, String rName, Codec rCodec) { return RecordCodecBuilder.create(instance -> instance.group( lCodec.fieldOf(lName).forGetter(ImmutableTriple::getLeft), mCodec.fieldOf(mName).forGetter(ImmutableTriple::getMiddle), diff --git a/src/main/java/org/confluence/lib/util/LibUtils.java b/src/main/java/org/confluence/lib/util/LibUtils.java index 16ade24..12647c4 100644 --- a/src/main/java/org/confluence/lib/util/LibUtils.java +++ b/src/main/java/org/confluence/lib/util/LibUtils.java @@ -1,5 +1,7 @@ package org.confluence.lib.util; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; import com.mojang.serialization.Codec; import io.netty.buffer.ByteBuf; import net.minecraft.core.BlockPos; @@ -39,6 +41,8 @@ import org.jetbrains.annotations.Nullable; import java.util.Arrays; +import java.util.List; +import java.util.Map; import java.util.function.Consumer; import java.util.function.Predicate; import java.util.stream.Collectors; @@ -49,7 +53,7 @@ public final class LibUtils { public static final int MAX_STACK_SIZE = 9999; public static final String NO_DROPS_TAG = "confluence:no_drops"; public static final EffectCure DENY_HEAL = EffectCure.get("confluence:deny_heal"); - public static final @Deprecated Codec VEC_2_CODEC = LibCodecUtils.VEC_2_CODEC; + public static final @Deprecated Codec VEC_2_CODEC = LibCodecUtils.VEC_2; public static final @Deprecated StreamCodec VEC_2_STREAM_CODEC = LibStreamCodecUtils.VEC_2_STREAM_CODEC; @ApiStatus.Internal @@ -173,12 +177,12 @@ public static void devRun(Runnable runnable) { @Deprecated public static Codec> tupleCodec(Codec aCodec, Codec bCodec) { - return LibCodecUtils.tupleCodec(aCodec, bCodec); + return LibCodecUtils.tuple(aCodec, bCodec); } @Deprecated public static Codec> tripleCodec(Codec lCodec, Codec mCodec, Codec rCodec) { - return LibCodecUtils.tripleCodec(lCodec, mCodec, rCodec); + return LibCodecUtils.triple(lCodec, mCodec, rCodec); } public static void setItemAndDropChance(Mob mob, DifficultyInstance difficulty, EquipmentSlot slot, Item item, float chance) { @@ -300,4 +304,20 @@ public static void resetDataComponent(ItemStack itemStack, DataComponentType public static boolean checkChance(double value, RandomSource random) { return value >= 1.0 || (value > 0.0 && random.nextDouble() < value); } + + public static Map convertTupleListToMap(List> list) { + ImmutableMap.Builder map = ImmutableMap.builder(); + for (Tuple tuple : list) { + map.put(tuple.getA(), tuple.getB()); + } + return map.build(); + } + + public static List> convertMapToTupleList(Map map) { + ImmutableList.Builder> list = ImmutableList.builder(); + for (Map.Entry entry : map.entrySet()) { + list.add(new Tuple<>(entry.getKey(), entry.getValue())); + } + return list.build(); + } } From fcdae8c75b128fead7ab3ae9efcff91d1555c2e9 Mon Sep 17 00:00:00 2001 From: westernat Date: Sat, 16 Aug 2025 23:48:39 +0800 Subject: [PATCH 21/61] =?UTF-8?q?=E6=98=9F=E4=B9=8B=E5=8A=9B=E6=88=90?= =?UTF-8?q?=E5=B0=B1=E4=BD=8D=E7=BD=AE=E7=A7=BB=E5=88=B0=E9=92=A9=E7=88=AA?= =?UTF-8?q?=E5=89=8D=E9=9D=A2=EF=BC=8C=E5=AE=89=E9=9D=99=E7=9A=84=E9=82=BB?= =?UTF-8?q?=E9=87=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/recipe/EnvironmentLevelAccess.java | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/confluence/lib/common/recipe/EnvironmentLevelAccess.java b/src/main/java/org/confluence/lib/common/recipe/EnvironmentLevelAccess.java index 4463e14..78a1b9d 100644 --- a/src/main/java/org/confluence/lib/common/recipe/EnvironmentLevelAccess.java +++ b/src/main/java/org/confluence/lib/common/recipe/EnvironmentLevelAccess.java @@ -3,6 +3,7 @@ import com.mojang.serialization.Codec; import com.mojang.serialization.MapCodec; import com.mojang.serialization.codecs.RecordCodecBuilder; +import net.minecraft.Util; import net.minecraft.advancements.critereon.StatePropertiesPredicate; import net.minecraft.core.BlockPos; import net.minecraft.core.Holder; @@ -10,6 +11,7 @@ import net.minecraft.core.RegistryCodecs; import net.minecraft.core.registries.Registries; import net.minecraft.network.RegistryFriendlyByteBuf; +import net.minecraft.network.chat.Component; import net.minecraft.network.codec.ByteBufCodecs; import net.minecraft.network.codec.StreamCodec; import net.minecraft.util.ExtraCodecs; @@ -29,6 +31,7 @@ import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; +import java.util.ArrayList; import java.util.List; import java.util.Objects; import java.util.Optional; @@ -168,6 +171,20 @@ public int hashCode() { private static boolean isGraveyard(Level level, BlockPos pos) { return true; // confluence mixin here } + + public List toDescriptions() { + List list = new ArrayList<>(); + biome.ifPresent(biomes -> { + for (Holder holder : biomes) { + list.add(Component.translatable(Util.makeDescriptionId("biome", holder.getKey().location()))); + } + }); + // todo block + if (graveyard) { + list.add(Component.translatable("jei.tooltip.environment.graveyard")); + } + return list; + } } public record SearchContext(int inflate, Optional> blocks, List statePredicates, Optional> fluids) { @@ -198,13 +215,13 @@ public boolean matches(Level level, BlockPos pos) { return true; } - public String toDescription() { + public Component toDescription() { // todo - return "{" + + return Component.literal('{' + ", blocks=" + blocks + ", statePredicates=" + statePredicates + ", fluids=" + fluids + - '}'; + '}'); } } } From c39616826e41deeae03dc3c21f58e2f7632b053b Mon Sep 17 00:00:00 2001 From: westernat Date: Sun, 17 Aug 2025 12:13:51 +0800 Subject: [PATCH 22/61] =?UTF-8?q?JEI=E7=8E=AF=E5=A2=83=E5=90=88=E6=88=90?= =?UTF-8?q?=E6=9D=A1=E4=BB=B6=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/recipe/EnvironmentLevelAccess.java | 83 ++++++++++++++----- .../resources/META-INF/accesstransformer.cfg | 3 + .../confluence_magic_lib/lang/en_us.json | 10 ++- .../confluence_magic_lib/lang/zh_cn.json | 10 ++- 4 files changed, 85 insertions(+), 21 deletions(-) diff --git a/src/main/java/org/confluence/lib/common/recipe/EnvironmentLevelAccess.java b/src/main/java/org/confluence/lib/common/recipe/EnvironmentLevelAccess.java index 78a1b9d..3cf844d 100644 --- a/src/main/java/org/confluence/lib/common/recipe/EnvironmentLevelAccess.java +++ b/src/main/java/org/confluence/lib/common/recipe/EnvironmentLevelAccess.java @@ -3,6 +3,7 @@ import com.mojang.serialization.Codec; import com.mojang.serialization.MapCodec; import com.mojang.serialization.codecs.RecordCodecBuilder; +import net.minecraft.ChatFormatting; import net.minecraft.Util; import net.minecraft.advancements.critereon.StatePropertiesPredicate; import net.minecraft.core.BlockPos; @@ -113,22 +114,22 @@ public static EnvironmentLevelAccess empty() { return new EnvironmentLevelAccess(null, null); } - public static Matcher matcher(@Nullable HolderSet biome, @Nullable SearchContext block, boolean graveyard) { - return new Matcher(Optional.ofNullable(biome), Optional.ofNullable(block), graveyard); + public static Matcher matcher(@Nullable HolderSet biome, @Nullable SearchContext block, boolean ectoMist) { + return new Matcher(Optional.ofNullable(biome), Optional.ofNullable(block), ectoMist); } - public record Matcher(Optional> biome, Optional block, boolean graveyard) { + public record Matcher(Optional> biome, Optional block, boolean ectoMist) { public static final Matcher EMPTY = new Matcher(Optional.empty(), Optional.empty(), false); public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( RegistryCodecs.homogeneousList(Registries.BIOME).lenientOptionalFieldOf("biome").forGetter(Matcher::biome), SearchContext.CODEC.lenientOptionalFieldOf("block").forGetter(Matcher::block), - Codec.BOOL.lenientOptionalFieldOf("graveyard", false).forGetter(Matcher::graveyard) + Codec.BOOL.lenientOptionalFieldOf("ecto_mist", false).forGetter(Matcher::ectoMist) ).apply(instance, Matcher::new)); public static final MapCodec MAP_CODEC = CODEC.lenientOptionalFieldOf("environment", EMPTY); public static final StreamCodec STREAM_CODEC = StreamCodec.composite( ByteBufCodecs.optional(ByteBufCodecs.holderSet(Registries.BIOME)), Matcher::biome, ByteBufCodecs.optional(SearchContext.STREAM_CODEC), Matcher::block, - ByteBufCodecs.BOOL, Matcher::graveyard, + ByteBufCodecs.BOOL, Matcher::ectoMist, Matcher::new ); @@ -138,7 +139,7 @@ public boolean matches(EnvironmentLevelAccess access) { if (level == null || pos == null) return false; if (!matchesBiome(level, pos)) return false; if (!matchesBlock(level, pos)) return false; - if (!matchesGraveyard(level, pos)) return false; + if (!matchesEctoMist(level, pos)) return false; return true; } @@ -150,38 +151,45 @@ public boolean matchesBlock(Level level, BlockPos pos) { return block.isEmpty() || block.get().matches(level, pos); } - public boolean matchesGraveyard(Level level, BlockPos pos) { - return !graveyard || isGraveyard(level, pos); + /** + * 灵雾环境 + */ + public boolean matchesEctoMist(Level level, BlockPos pos) { + return !ectoMist || isEctoMist(level, pos); } @Override public boolean equals(Object o) { - return o == this || (o instanceof Matcher(Optional> biome1, Optional block1, boolean graveyard1) && - graveyard == graveyard1 && Objects.equals(block, block1) && Objects.equals(biome, biome1)); + return o == this || (o instanceof Matcher(Optional> biome1, Optional block1, boolean ectoMist1) && + ectoMist == ectoMist1 && Objects.equals(block, block1) && Objects.equals(biome, biome1)); } @Override public int hashCode() { int result = Objects.hashCode(biome); result = 31 * result + Objects.hashCode(block); - result = 31 * result + Boolean.hashCode(graveyard); + result = 31 * result + Boolean.hashCode(ectoMist); return result; } - private static boolean isGraveyard(Level level, BlockPos pos) { + private static boolean isEctoMist(Level level, BlockPos pos) { return true; // confluence mixin here } public List toDescriptions() { List list = new ArrayList<>(); biome.ifPresent(biomes -> { + list.add(Component.translatable("jei.tooltip.environment.biome").withStyle(ChatFormatting.AQUA)); for (Holder holder : biomes) { - list.add(Component.translatable(Util.makeDescriptionId("biome", holder.getKey().location()))); + list.add(Component.translatable(Util.makeDescriptionId("biome", holder.getKey().location())).withStyle(ChatFormatting.GRAY)); } }); - // todo block - if (graveyard) { - list.add(Component.translatable("jei.tooltip.environment.graveyard")); + block.ifPresent(context -> { + list.add(Component.translatable("jei.tooltip.environment.block").withStyle(ChatFormatting.AQUA)); + list.addAll(context.toDescriptions()); + }); + if (ectoMist) { + list.add(Component.translatable("jei.tooltip.environment.ecto_mist").withStyle(ChatFormatting.AQUA)); } return list; } @@ -215,13 +223,50 @@ public boolean matches(Level level, BlockPos pos) { return true; } - public Component toDescription() { + public String toDescription() { // todo - return Component.literal('{' + + return '{' + ", blocks=" + blocks + ", statePredicates=" + statePredicates + ", fluids=" + fluids + - '}'); + '}'; + } + + public List toDescriptions() { + List list = new ArrayList<>(); + list.add(Component.translatable("jei.tooltip.environment.block.inflate", inflate).withStyle(ChatFormatting.GRAY)); + blocks.ifPresent(blockz -> { + list.add(Component.translatable("jei.tooltip.environment.block.blocks").withStyle(ChatFormatting.GRAY)); + blockz.stream().map(holder -> holder.value().getName().withStyle(ChatFormatting.DARK_GRAY)).forEach(list::add); + }); + for (StatePropertiesPredicate predicate : statePredicates) { + list.add(Component.translatable("jei.tooltip.environment.block.predicates").withStyle(ChatFormatting.GRAY)); + for (StatePropertiesPredicate.PropertyMatcher property : predicate.properties()) { + String s = property.name() + '='; + if (property.valueMatcher() instanceof StatePropertiesPredicate.ExactMatcher(String value)) { + s += value; + } else if (property.valueMatcher() instanceof StatePropertiesPredicate.RangedMatcher(Optional minValue, Optional maxValue)) { + if (minValue.isPresent()) { + if (maxValue.isPresent()) { + s += '[' + minValue.get() + ", " + maxValue.get() + ']'; + } else { + s += '[' + minValue.get() + ",)"; + } + } else if (maxValue.isPresent()) { + s += "(," + maxValue.get() + ']'; + } + } else { + s += property.valueMatcher(); + } + list.add(Component.translatable("jei.tooltip.environment.block.predicates.property", s).withStyle(ChatFormatting.DARK_GRAY)); + } + } + fluids.ifPresent(fluidz -> { + list.add(Component.translatable("jei.tooltip.environment.block.fluids").withStyle(ChatFormatting.GRAY)); + fluidz.stream().map(holder -> holder.value().getFluidType()).distinct() + .forEach(type -> list.add(Component.translatable(type.getDescriptionId()).withStyle(ChatFormatting.DARK_GRAY))); + }); + return list; } } } diff --git a/src/main/resources/META-INF/accesstransformer.cfg b/src/main/resources/META-INF/accesstransformer.cfg index a3461db..808d2b3 100644 --- a/src/main/resources/META-INF/accesstransformer.cfg +++ b/src/main/resources/META-INF/accesstransformer.cfg @@ -1 +1,4 @@ public net.minecraft.world.item.crafting.ShapedRecipePattern data +public net.minecraft.advancements.critereon.StatePropertiesPredicate$PropertyMatcher +public net.minecraft.advancements.critereon.StatePropertiesPredicate$RangedMatcher +public net.minecraft.advancements.critereon.StatePropertiesPredicate$ExactMatcher diff --git a/src/main/resources/assets/confluence_magic_lib/lang/en_us.json b/src/main/resources/assets/confluence_magic_lib/lang/en_us.json index db0a7de..f5c4fa1 100644 --- a/src/main/resources/assets/confluence_magic_lib/lang/en_us.json +++ b/src/main/resources/assets/confluence_magic_lib/lang/en_us.json @@ -1,4 +1,12 @@ { "tooltip.confluence.work_in_progress": "Still Work In Progress!", - "error.confluence.null": "Find a null pointer exception! Please report the log to Confluence: Otherworld for help!" + "error.confluence.null": "Find a null pointer exception! Please report the log to Confluence: Otherworld for help!", + "jei.tooltip.environment.biome": "Requires any biome:", + "jei.tooltip.environment.block": "Requires any block nearby:", + "jei.tooltip.environment.block.inflate": "Search range: %s", + "jei.tooltip.environment.block.blocks": "Blocks:", + "jei.tooltip.environment.block.predicates": "Block States:", + "jei.tooltip.environment.block.predicates.property": "Property: %s", + "jei.tooltip.environment.block.fluids": "Fluids:", + "jei.tooltip.environment.ecto_mist": "Requires ecto mist" } diff --git a/src/main/resources/assets/confluence_magic_lib/lang/zh_cn.json b/src/main/resources/assets/confluence_magic_lib/lang/zh_cn.json index 808d31f..c7fede5 100644 --- a/src/main/resources/assets/confluence_magic_lib/lang/zh_cn.json +++ b/src/main/resources/assets/confluence_magic_lib/lang/zh_cn.json @@ -1,4 +1,12 @@ { "tooltip.confluence.work_in_progress": "仍在开发中!", - "error.confluence.null": "发现一个空指针异常!请报告给《汇流来世》以寻求帮助!" + "error.confluence.null": "发现一个空指针异常!请报告给《汇流来世》以寻求帮助!", + "jei.tooltip.environment.biome": "需要任意生物群系:", + "jei.tooltip.environment.block": "需要任意方块在附近:", + "jei.tooltip.environment.block.inflate": "搜索范围:%s", + "jei.tooltip.environment.block.blocks": "方块:", + "jei.tooltip.environment.block.predicates": "方块状态:", + "jei.tooltip.environment.block.predicates.property": "属性:%s", + "jei.tooltip.environment.block.fluids": "流体:", + "jei.tooltip.environment.ecto_mist": "需要灵雾环境" } From 3e7aea856709f34c5ba831cf14f25acabd39d674 Mon Sep 17 00:00:00 2001 From: westernat Date: Sun, 17 Aug 2025 16:36:30 +0800 Subject: [PATCH 23/61] =?UTF-8?q?=E5=8C=BA=E5=88=86=E7=81=B5=E9=9B=BE?= =?UTF-8?q?=E4=B8=8E=E5=A2=93=E5=9C=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/recipe/EnvironmentLevelAccess.java | 22 +++++++++---------- .../confluence_magic_lib/lang/en_us.json | 2 +- .../confluence_magic_lib/lang/zh_cn.json | 2 +- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/main/java/org/confluence/lib/common/recipe/EnvironmentLevelAccess.java b/src/main/java/org/confluence/lib/common/recipe/EnvironmentLevelAccess.java index 3cf844d..cfd5d7b 100644 --- a/src/main/java/org/confluence/lib/common/recipe/EnvironmentLevelAccess.java +++ b/src/main/java/org/confluence/lib/common/recipe/EnvironmentLevelAccess.java @@ -118,18 +118,18 @@ public static Matcher matcher(@Nullable HolderSet biome, @Nullable Search return new Matcher(Optional.ofNullable(biome), Optional.ofNullable(block), ectoMist); } - public record Matcher(Optional> biome, Optional block, boolean ectoMist) { + public record Matcher(Optional> biome, Optional block, boolean graveyard) { public static final Matcher EMPTY = new Matcher(Optional.empty(), Optional.empty(), false); public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( RegistryCodecs.homogeneousList(Registries.BIOME).lenientOptionalFieldOf("biome").forGetter(Matcher::biome), SearchContext.CODEC.lenientOptionalFieldOf("block").forGetter(Matcher::block), - Codec.BOOL.lenientOptionalFieldOf("ecto_mist", false).forGetter(Matcher::ectoMist) + Codec.BOOL.lenientOptionalFieldOf("graveyard", false).forGetter(Matcher::graveyard) ).apply(instance, Matcher::new)); public static final MapCodec MAP_CODEC = CODEC.lenientOptionalFieldOf("environment", EMPTY); public static final StreamCodec STREAM_CODEC = StreamCodec.composite( ByteBufCodecs.optional(ByteBufCodecs.holderSet(Registries.BIOME)), Matcher::biome, ByteBufCodecs.optional(SearchContext.STREAM_CODEC), Matcher::block, - ByteBufCodecs.BOOL, Matcher::ectoMist, + ByteBufCodecs.BOOL, Matcher::graveyard, Matcher::new ); @@ -139,7 +139,7 @@ public boolean matches(EnvironmentLevelAccess access) { if (level == null || pos == null) return false; if (!matchesBiome(level, pos)) return false; if (!matchesBlock(level, pos)) return false; - if (!matchesEctoMist(level, pos)) return false; + if (!matchesGraveyard(level, pos)) return false; return true; } @@ -154,25 +154,25 @@ public boolean matchesBlock(Level level, BlockPos pos) { /** * 灵雾环境 */ - public boolean matchesEctoMist(Level level, BlockPos pos) { - return !ectoMist || isEctoMist(level, pos); + public boolean matchesGraveyard(Level level, BlockPos pos) { + return !graveyard || isGraveyard(level, pos); } @Override public boolean equals(Object o) { return o == this || (o instanceof Matcher(Optional> biome1, Optional block1, boolean ectoMist1) && - ectoMist == ectoMist1 && Objects.equals(block, block1) && Objects.equals(biome, biome1)); + graveyard == ectoMist1 && Objects.equals(block, block1) && Objects.equals(biome, biome1)); } @Override public int hashCode() { int result = Objects.hashCode(biome); result = 31 * result + Objects.hashCode(block); - result = 31 * result + Boolean.hashCode(ectoMist); + result = 31 * result + Boolean.hashCode(graveyard); return result; } - private static boolean isEctoMist(Level level, BlockPos pos) { + private static boolean isGraveyard(Level level, BlockPos pos) { return true; // confluence mixin here } @@ -188,8 +188,8 @@ public List toDescriptions() { list.add(Component.translatable("jei.tooltip.environment.block").withStyle(ChatFormatting.AQUA)); list.addAll(context.toDescriptions()); }); - if (ectoMist) { - list.add(Component.translatable("jei.tooltip.environment.ecto_mist").withStyle(ChatFormatting.AQUA)); + if (graveyard) { + list.add(Component.translatable("jei.tooltip.environment.graveyard").withStyle(ChatFormatting.AQUA)); } return list; } diff --git a/src/main/resources/assets/confluence_magic_lib/lang/en_us.json b/src/main/resources/assets/confluence_magic_lib/lang/en_us.json index f5c4fa1..ea50204 100644 --- a/src/main/resources/assets/confluence_magic_lib/lang/en_us.json +++ b/src/main/resources/assets/confluence_magic_lib/lang/en_us.json @@ -8,5 +8,5 @@ "jei.tooltip.environment.block.predicates": "Block States:", "jei.tooltip.environment.block.predicates.property": "Property: %s", "jei.tooltip.environment.block.fluids": "Fluids:", - "jei.tooltip.environment.ecto_mist": "Requires ecto mist" + "jei.tooltip.environment.graveyard": "Requires graveyard" } diff --git a/src/main/resources/assets/confluence_magic_lib/lang/zh_cn.json b/src/main/resources/assets/confluence_magic_lib/lang/zh_cn.json index c7fede5..e0f7988 100644 --- a/src/main/resources/assets/confluence_magic_lib/lang/zh_cn.json +++ b/src/main/resources/assets/confluence_magic_lib/lang/zh_cn.json @@ -8,5 +8,5 @@ "jei.tooltip.environment.block.predicates": "方块状态:", "jei.tooltip.environment.block.predicates.property": "属性:%s", "jei.tooltip.environment.block.fluids": "流体:", - "jei.tooltip.environment.ecto_mist": "需要灵雾环境" + "jei.tooltip.environment.graveyard": "需要灵雾环境" } From 74849d85202e17eacd43576d93adb4452573e576 Mon Sep 17 00:00:00 2001 From: westernat Date: Sun, 17 Aug 2025 17:00:23 +0800 Subject: [PATCH 24/61] =?UTF-8?q?=E6=B8=94=E5=A4=AB=E9=98=B6=E6=AE=B5?= =?UTF-8?q?=E6=80=A7=E6=88=98=E5=88=A9=E5=93=81=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lib/common/recipe/EnvironmentLevelAccess.java | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/main/java/org/confluence/lib/common/recipe/EnvironmentLevelAccess.java b/src/main/java/org/confluence/lib/common/recipe/EnvironmentLevelAccess.java index cfd5d7b..e850384 100644 --- a/src/main/java/org/confluence/lib/common/recipe/EnvironmentLevelAccess.java +++ b/src/main/java/org/confluence/lib/common/recipe/EnvironmentLevelAccess.java @@ -223,15 +223,6 @@ public boolean matches(Level level, BlockPos pos) { return true; } - public String toDescription() { - // todo - return '{' + - ", blocks=" + blocks + - ", statePredicates=" + statePredicates + - ", fluids=" + fluids + - '}'; - } - public List toDescriptions() { List list = new ArrayList<>(); list.add(Component.translatable("jei.tooltip.environment.block.inflate", inflate).withStyle(ChatFormatting.GRAY)); From 6ca461bb8a4d490270c73baffe1fb53950a11ef7 Mon Sep 17 00:00:00 2001 From: cooobird <113522396+cooobird@users.noreply.github.com> Date: Sun, 24 Aug 2025 20:30:42 +0800 Subject: [PATCH 25/61] Update gradle.properties --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 522f361..6490474 100644 --- a/gradle.properties +++ b/gradle.properties @@ -30,7 +30,7 @@ mod_name=Confluence Magic Lib mod_license=MIT # The mod version. See https://semver.org/ ###### remove '-SNAPSHOT' when merge to main branch ###### -mod_version=0.0.2b-SNAPSHOT +mod_version=0.0.2c-SNAPSHOT # The group ID for the mod. It is only important when publishing as an artifact to a Maven repository. # This should match the base package used for the mod sources. # See https://maven.apache.org/guides/mini/guide-naming-conventions.html From 1100fb173d042b805f99474babd16ed42699baa8 Mon Sep 17 00:00:00 2001 From: westernat Date: Tue, 26 Aug 2025 23:26:22 +0800 Subject: [PATCH 26/61] =?UTF-8?q?=E5=90=91=E5=AF=BC=E5=B7=AB=E6=AF=92?= =?UTF-8?q?=E5=A8=83=E5=A8=83=E5=85=89=E6=95=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/org/confluence/lib/common/data/IdFixer.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/confluence/lib/common/data/IdFixer.java b/src/main/java/org/confluence/lib/common/data/IdFixer.java index 9058018..604625b 100644 --- a/src/main/java/org/confluence/lib/common/data/IdFixer.java +++ b/src/main/java/org/confluence/lib/common/data/IdFixer.java @@ -19,6 +19,7 @@ import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.Item; import net.minecraft.world.level.biome.Biome; +import net.minecraft.world.level.block.state.StateHolder; import net.neoforged.fml.ModLoader; import org.apache.commons.lang3.mutable.MutableObject; import org.confluence.lib.ConfluenceMagicLib; @@ -101,11 +102,11 @@ public DataResult> apply(DynamicOps ops, T input, DataResult

>> mutableObject = new MutableObject<>(a); ops.getMap(input).ifSuccess(map -> { - T t = map.get("Name"); + T t = map.get(StateHolder.NAME_TAG); if (t != null) ops.getStringValue(t).ifSuccess(s -> { String s1 = s; while ((s = BLOCK_NAME_FIX_MAP.get(s1)) != null) s1 = s; - ops.mergeToMap(input, ops.createString("Name"), ops.createString(s1)) + ops.mergeToMap(input, ops.createString(StateHolder.NAME_TAG), ops.createString(s1)) .ifSuccess(t1 -> mutableObject.setValue(codec.decode(ops, t1))); }); }); From 6b685de61d108f1991b0ba457b646cb0d830f262 Mon Sep 17 00:00:00 2001 From: westernat Date: Thu, 28 Aug 2025 00:13:29 +0800 Subject: [PATCH 27/61] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E5=90=88=E5=B9=B6en=5F?= =?UTF-8?q?us.json?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/confluence/lib/util/LangMerger.java | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 src/main/java/org/confluence/lib/util/LangMerger.java diff --git a/src/main/java/org/confluence/lib/util/LangMerger.java b/src/main/java/org/confluence/lib/util/LangMerger.java new file mode 100644 index 0000000..83bf081 --- /dev/null +++ b/src/main/java/org/confluence/lib/util/LangMerger.java @@ -0,0 +1,48 @@ +package org.confluence.lib.util; + +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import net.minecraft.data.CachedOutput; +import net.minecraft.data.DataProvider; +import net.minecraft.util.GsonHelper; +import net.neoforged.fml.loading.FMLEnvironment; + +import java.io.FileReader; +import java.io.IOException; +import java.io.Reader; +import java.nio.file.*; +import java.nio.file.attribute.BasicFileAttributes; +import java.util.EnumSet; +import java.util.Map; + +public class LangMerger { + private static final JsonObject mergedResult = new JsonObject(); + + public static void main(String[] args) { + if (FMLEnvironment.production || args.length == 0) return; + Path startPath = Paths.get(args[0]); + + try { + Files.walkFileTree(startPath, EnumSet.noneOf(FileVisitOption.class), Integer.MAX_VALUE, new SimpleFileVisitor<>() { + @Override + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) { + if (file.getFileName().toString().equals("en_us.json")) { + try (Reader reader = new FileReader(file.toFile())) { + for (Map.Entry entry : GsonHelper.parse(reader).entrySet()) { + mergedResult.add(entry.getKey(), entry.getValue()); + } + } catch (Exception ignored) {} + } + return FileVisitResult.CONTINUE; + } + + @Override + public FileVisitResult visitFileFailed(Path file, IOException exc) { + return FileVisitResult.CONTINUE; + } + }); + + DataProvider.saveStable(CachedOutput.NO_CACHE, mergedResult, startPath.resolve("en_us.json")).join(); + } catch (IOException ignored) {} + } +} From 9e17de2894e7f90badc21f5c37557f7bd78066ae Mon Sep 17 00:00:00 2001 From: westernat Date: Thu, 28 Aug 2025 00:30:47 +0800 Subject: [PATCH 28/61] =?UTF-8?q?=E8=BF=87=E6=BB=A4=E4=B8=80=E4=BA=9B?= =?UTF-8?q?=E4=B8=8D=E9=9C=80=E8=A6=81=E5=90=88=E5=B9=B6=E7=9A=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/org/confluence/lib/util/LangMerger.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/confluence/lib/util/LangMerger.java b/src/main/java/org/confluence/lib/util/LangMerger.java index 83bf081..7c65537 100644 --- a/src/main/java/org/confluence/lib/util/LangMerger.java +++ b/src/main/java/org/confluence/lib/util/LangMerger.java @@ -21,17 +21,21 @@ public class LangMerger { public static void main(String[] args) { if (FMLEnvironment.production || args.length == 0) return; Path startPath = Paths.get(args[0]); + String s1 = startPath.toString(); try { Files.walkFileTree(startPath, EnumSet.noneOf(FileVisitOption.class), Integer.MAX_VALUE, new SimpleFileVisitor<>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) { if (file.getFileName().toString().equals("en_us.json")) { - try (Reader reader = new FileReader(file.toFile())) { - for (Map.Entry entry : GsonHelper.parse(reader).entrySet()) { - mergedResult.add(entry.getKey(), entry.getValue()); - } - } catch (Exception ignored) {} + String s2 = file.toString(); + if (s2.contains("resources") && !s2.contains("build") && !s2.contains("resourcepacks") && !s2.equals(s1)) { + try (Reader reader = new FileReader(file.toFile())) { + for (Map.Entry entry : GsonHelper.parse(reader).entrySet()) { + mergedResult.add(entry.getKey(), entry.getValue()); + } + } catch (Exception ignored) {} + } } return FileVisitResult.CONTINUE; } From a654dbb071a14d759b49e3713e72bb2e95d4e094 Mon Sep 17 00:00:00 2001 From: westernat Date: Thu, 28 Aug 2025 15:51:53 +0800 Subject: [PATCH 29/61] =?UTF-8?q?=E4=B8=8D=E5=B0=8F=E5=BF=83=E4=BC=98?= =?UTF-8?q?=E5=8C=96import=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lib/util/IgnoreThrowerExplosionDamageCalculator.java | 1 - src/main/java/org/confluence/lib/util/VectorUtils.java | 1 - 2 files changed, 2 deletions(-) diff --git a/src/main/java/org/confluence/lib/util/IgnoreThrowerExplosionDamageCalculator.java b/src/main/java/org/confluence/lib/util/IgnoreThrowerExplosionDamageCalculator.java index faadb9e..ada4648 100644 --- a/src/main/java/org/confluence/lib/util/IgnoreThrowerExplosionDamageCalculator.java +++ b/src/main/java/org/confluence/lib/util/IgnoreThrowerExplosionDamageCalculator.java @@ -3,7 +3,6 @@ import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.player.Player; import net.minecraft.world.level.Explosion; -import net.minecraft.world.level.ExplosionDamageCalculator; /** * 忽略对使用者和玩家伤害 diff --git a/src/main/java/org/confluence/lib/util/VectorUtils.java b/src/main/java/org/confluence/lib/util/VectorUtils.java index 16bd342..959973d 100644 --- a/src/main/java/org/confluence/lib/util/VectorUtils.java +++ b/src/main/java/org/confluence/lib/util/VectorUtils.java @@ -1,6 +1,5 @@ package org.confluence.lib.util; -import it.unimi.dsi.fastutil.objects.Object2IntMap; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.util.Mth; From d1b83013402ea34cd7e4c603251b138352e81e3b Mon Sep 17 00:00:00 2001 From: westernat Date: Fri, 29 Aug 2025 19:31:49 +0800 Subject: [PATCH 30/61] =?UTF-8?q?=E6=89=93=E8=8D=89=E7=88=86=E8=99=AB?= =?UTF-8?q?=E5=AD=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/org/confluence/lib/util/LibCodecUtils.java | 11 ++++++----- src/main/java/org/confluence/lib/util/LibUtils.java | 4 ++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/confluence/lib/util/LibCodecUtils.java b/src/main/java/org/confluence/lib/util/LibCodecUtils.java index f56a79b..7b0c32c 100644 --- a/src/main/java/org/confluence/lib/util/LibCodecUtils.java +++ b/src/main/java/org/confluence/lib/util/LibCodecUtils.java @@ -5,6 +5,7 @@ import net.minecraft.util.Tuple; import net.minecraft.world.phys.Vec2; import org.apache.commons.lang3.tuple.ImmutableTriple; +import org.apache.commons.lang3.tuple.Triple; public final class LibCodecUtils { public static final Codec VEC_2 = RecordCodecBuilder.create(instance -> instance.group( @@ -23,15 +24,15 @@ public static Codec> tuple(String aName, Codec aCodec, Str ).apply(instance, Tuple::new)); } - public static Codec> triple(Codec lCodec, Codec mCodec, Codec rCodec) { + public static Codec> triple(Codec lCodec, Codec mCodec, Codec rCodec) { return triple("l", lCodec, "m", mCodec, "r", rCodec); } - public static Codec> triple(String lName, Codec lCodec, String mName, Codec mCodec, String rName, Codec rCodec) { + public static Codec> triple(String lName, Codec lCodec, String mName, Codec mCodec, String rName, Codec rCodec) { return RecordCodecBuilder.create(instance -> instance.group( - lCodec.fieldOf(lName).forGetter(ImmutableTriple::getLeft), - mCodec.fieldOf(mName).forGetter(ImmutableTriple::getMiddle), - rCodec.fieldOf(rName).forGetter(ImmutableTriple::getRight) + lCodec.fieldOf(lName).forGetter(Triple::getLeft), + mCodec.fieldOf(mName).forGetter(Triple::getMiddle), + rCodec.fieldOf(rName).forGetter(Triple::getRight) ).apply(instance, ImmutableTriple::new)); } } diff --git a/src/main/java/org/confluence/lib/util/LibUtils.java b/src/main/java/org/confluence/lib/util/LibUtils.java index 12647c4..d51cd4b 100644 --- a/src/main/java/org/confluence/lib/util/LibUtils.java +++ b/src/main/java/org/confluence/lib/util/LibUtils.java @@ -34,7 +34,7 @@ import net.neoforged.fml.loading.FMLEnvironment; import net.neoforged.neoforge.common.EffectCure; import net.neoforged.neoforge.server.ServerLifecycleHooks; -import org.apache.commons.lang3.tuple.ImmutableTriple; +import org.apache.commons.lang3.tuple.Triple; import org.confluence.lib.ConfluenceMagicLib; import org.confluence.lib.common.component.NbtComponent; import org.jetbrains.annotations.ApiStatus; @@ -181,7 +181,7 @@ public static Codec> tupleCodec(Codec aCodec, Codec bCo } @Deprecated - public static Codec> tripleCodec(Codec lCodec, Codec mCodec, Codec rCodec) { + public static Codec> tripleCodec(Codec lCodec, Codec mCodec, Codec rCodec) { return LibCodecUtils.triple(lCodec, mCodec, rCodec); } From aa2cb4e569b4fb081d695eb45cdd002700943e25 Mon Sep 17 00:00:00 2001 From: westernat Date: Sat, 30 Aug 2025 15:26:36 +0800 Subject: [PATCH 31/61] =?UTF-8?q?=E7=BB=87=E5=B8=83=E6=9C=BA=EF=BC=8C?= =?UTF-8?q?=E5=BC=95=E7=88=86=E5=99=A8=EF=BC=88=E9=83=BD=E6=98=AF=E5=8D=8A?= =?UTF-8?q?=E6=88=90=E5=93=81=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/org/confluence/lib/util/FeatureUtils.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/org/confluence/lib/util/FeatureUtils.java b/src/main/java/org/confluence/lib/util/FeatureUtils.java index 065d259..d7c01a2 100644 --- a/src/main/java/org/confluence/lib/util/FeatureUtils.java +++ b/src/main/java/org/confluence/lib/util/FeatureUtils.java @@ -26,6 +26,10 @@ public static boolean isPosAir(WorldGenLevel level, BlockPos blockPos) { return level.isStateAtPosition(blockPos, BlockBehaviour.BlockStateBase::isAir); } + public static boolean isPosLiquid(WorldGenLevel level, BlockPos blockPos) { + return level.isStateAtPosition(blockPos, BlockBehaviour.BlockStateBase::liquid); + } + public static boolean isPosSturdy(WorldGenLevel level, BlockPos blockPos, Direction face) { return level.isStateAtPosition(blockPos, blockState -> blockState.isFaceSturdy(level, blockPos, face)); } From aeccb693e08d170d98dcb595619d56d075ba0e72 Mon Sep 17 00:00:00 2001 From: westernat Date: Mon, 1 Sep 2025 12:10:12 +0800 Subject: [PATCH 32/61] =?UTF-8?q?=E6=8F=90=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/org/confluence/lib/util/LibStreamCodecUtils.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/org/confluence/lib/util/LibStreamCodecUtils.java b/src/main/java/org/confluence/lib/util/LibStreamCodecUtils.java index d39ac58..9bc8259 100644 --- a/src/main/java/org/confluence/lib/util/LibStreamCodecUtils.java +++ b/src/main/java/org/confluence/lib/util/LibStreamCodecUtils.java @@ -8,6 +8,8 @@ import net.minecraft.world.phys.Vec2; import javax.annotation.ParametersAreNonnullByDefault; +import java.util.Map; +import java.util.function.IntFunction; import java.util.function.Supplier; @ParametersAreNonnullByDefault @@ -38,4 +40,8 @@ public void encode(B buffer, V value) { public static StreamCodec> tuple(StreamCodec aCodec, StreamCodec bCodec) { return StreamCodec.composite(aCodec, Tuple::getA, bCodec, Tuple::getB, Tuple::new); } + + public static StreamCodec> map(IntFunction> factory, StreamCodec keyCodec, StreamCodec valueCodec) { + return ByteBufCodecs.map(factory, keyCodec, valueCodec); + } } From 31cd751196a6f8f1ecf57dadbc3724e17a6d494d Mon Sep 17 00:00:00 2001 From: westernat Date: Mon, 1 Sep 2025 22:45:52 +0800 Subject: [PATCH 33/61] =?UTF-8?q?=E5=90=84=E7=A7=8D=E4=B8=9C=E8=A5=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/confluence/lib/common/item/ColoredItem.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/confluence/lib/common/item/ColoredItem.java b/src/main/java/org/confluence/lib/common/item/ColoredItem.java index f21dd8a..9852c8d 100644 --- a/src/main/java/org/confluence/lib/common/item/ColoredItem.java +++ b/src/main/java/org/confluence/lib/common/item/ColoredItem.java @@ -7,10 +7,6 @@ import org.confluence.lib.util.LibUtils; public class ColoredItem extends CustomRarityItem { - public ColoredItem(ModRarity rarity) { - super(rarity); - } - public ColoredItem(Properties properties, ModRarity rarity) { super(properties, rarity); } @@ -26,4 +22,10 @@ public static int getColor(ItemStack itemStack) { } return nbtComponent.nbt().getInt("color"); } + + public static void merge(ItemStack carried, ItemStack onSlot) { + if (onSlot.getItem() instanceof ColoredItem && ItemStack.isSameItem(onSlot, carried)) { + ColoredItem.setColor(carried, ColoredItem.getColor(onSlot)); + } + } } From cf5a186adf93c7663035fbaf8533a88ce7d3d7bd Mon Sep 17 00:00:00 2001 From: westernat Date: Wed, 3 Sep 2025 00:35:52 +0800 Subject: [PATCH 34/61] =?UTF-8?q?=E5=85=88=E5=86=99=E4=B8=80=E9=83=A8?= =?UTF-8?q?=E5=88=86=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/org/confluence/lib/common/menu/AmountResultSlot.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/confluence/lib/common/menu/AmountResultSlot.java b/src/main/java/org/confluence/lib/common/menu/AmountResultSlot.java index 86a35e7..d74fede 100644 --- a/src/main/java/org/confluence/lib/common/menu/AmountResultSlot.java +++ b/src/main/java/org/confluence/lib/common/menu/AmountResultSlot.java @@ -12,8 +12,8 @@ public class AmountResultSlot> extends Slot { protected final MenuRecipeInput input; protected @Nullable R recipe; - public AmountResultSlot(MenuRecipeInput input, Container result, int pSlot, int pX, int pY) { - super(result, pSlot, pX, pY); + public AmountResultSlot(MenuRecipeInput input, Container result, int slot, int x, int y) { + super(result, slot, x, y); this.input = input; } From 29d2e595139eeece4af767324e64cde974c5c1cd Mon Sep 17 00:00:00 2001 From: westernat Date: Sat, 6 Sep 2025 17:50:41 +0800 Subject: [PATCH 35/61] =?UTF-8?q?=E5=AE=8C=E6=95=B4=E7=9A=84en=5Fus?= =?UTF-8?q?=E5=92=8Czh=5Fcn?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/confluence/lib/util/LangMerger.java | 49 ++++++++++--------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/src/main/java/org/confluence/lib/util/LangMerger.java b/src/main/java/org/confluence/lib/util/LangMerger.java index 7c65537..17043a0 100644 --- a/src/main/java/org/confluence/lib/util/LangMerger.java +++ b/src/main/java/org/confluence/lib/util/LangMerger.java @@ -17,36 +17,41 @@ public class LangMerger { private static final JsonObject mergedResult = new JsonObject(); + private static final String[] locals = new String[]{"en_us.json", "zh_cn.json"}; public static void main(String[] args) { if (FMLEnvironment.production || args.length == 0) return; Path startPath = Paths.get(args[0]); - String s1 = startPath.toString(); + for (String local : locals) { + String s1 = startPath.toString(); - try { - Files.walkFileTree(startPath, EnumSet.noneOf(FileVisitOption.class), Integer.MAX_VALUE, new SimpleFileVisitor<>() { - @Override - public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) { - if (file.getFileName().toString().equals("en_us.json")) { - String s2 = file.toString(); - if (s2.contains("resources") && !s2.contains("build") && !s2.contains("resourcepacks") && !s2.equals(s1)) { - try (Reader reader = new FileReader(file.toFile())) { - for (Map.Entry entry : GsonHelper.parse(reader).entrySet()) { - mergedResult.add(entry.getKey(), entry.getValue()); - } - } catch (Exception ignored) {} + try { + Files.walkFileTree(startPath, EnumSet.noneOf(FileVisitOption.class), Integer.MAX_VALUE, new SimpleFileVisitor<>() { + @Override + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) { + if (file.getFileName().toString().equals(local)) { + String s2 = file.toString(); + if (s2.contains("resources") && !s2.contains("build") && !s2.contains("resourcepacks") && !s2.equals(s1)) { + try (Reader reader = new FileReader(file.toFile())) { + for (Map.Entry entry : GsonHelper.parse(reader).entrySet()) { + mergedResult.add(entry.getKey(), entry.getValue()); + } + } catch (Exception ignored) {} + } } + return FileVisitResult.CONTINUE; } - return FileVisitResult.CONTINUE; - } - @Override - public FileVisitResult visitFileFailed(Path file, IOException exc) { - return FileVisitResult.CONTINUE; - } - }); + @Override + public FileVisitResult visitFileFailed(Path file, IOException exc) { + return FileVisitResult.CONTINUE; + } + }); - DataProvider.saveStable(CachedOutput.NO_CACHE, mergedResult, startPath.resolve("en_us.json")).join(); - } catch (IOException ignored) {} + Path resultPath = startPath.resolve("i18n").resolve(local); + Files.deleteIfExists(resultPath); + DataProvider.saveStable(CachedOutput.NO_CACHE, mergedResult, resultPath).join(); + } catch (IOException ignored) {} + } } } From f17f3d2cee62281a295214d4b6962bb11847dd76 Mon Sep 17 00:00:00 2001 From: westernat Date: Sat, 6 Sep 2025 20:39:16 +0800 Subject: [PATCH 36/61] =?UTF-8?q?=E6=A0=B9=E6=8D=AE=E6=B8=B8=E6=88=8F?= =?UTF-8?q?=E9=98=B6=E6=AE=B5=E6=94=B9=E5=8F=98=E7=94=9F=E7=89=A9=E5=B1=9E?= =?UTF-8?q?=E6=80=A7=E7=9A=84datamap?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../confluence/lib/util/LibCodecUtils.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/main/java/org/confluence/lib/util/LibCodecUtils.java b/src/main/java/org/confluence/lib/util/LibCodecUtils.java index 7b0c32c..0ddb206 100644 --- a/src/main/java/org/confluence/lib/util/LibCodecUtils.java +++ b/src/main/java/org/confluence/lib/util/LibCodecUtils.java @@ -1,5 +1,7 @@ package org.confluence.lib.util; +import com.google.common.collect.ImmutableListMultimap; +import com.mojang.datafixers.util.Either; import com.mojang.serialization.Codec; import com.mojang.serialization.codecs.RecordCodecBuilder; import net.minecraft.util.Tuple; @@ -7,6 +9,11 @@ import org.apache.commons.lang3.tuple.ImmutableTriple; import org.apache.commons.lang3.tuple.Triple; +import java.util.Hashtable; +import java.util.List; +import java.util.Map; +import java.util.function.Function; + public final class LibCodecUtils { public static final Codec VEC_2 = RecordCodecBuilder.create(instance -> instance.group( Codec.FLOAT.fieldOf("x").forGetter(vec2 -> vec2.x), @@ -35,4 +42,28 @@ public static Codec> triple(String lName, Codec lCo rCodec.fieldOf(rName).forGetter(Triple::getRight) ).apply(instance, ImmutableTriple::new)); } + + public static Codec> homogenousList(Codec codec, boolean disallowInline) { + Codec> listCodec = codec.listOf(); + return disallowInline ? listCodec : Codec.either(listCodec, codec).xmap( + either -> either.map(Function.identity(), List::of), + list -> list.size() == 1 ? Either.right(list.getFirst()) : Either.left(list) + ); + } + + public static Codec> multimapCodec(Codec keyCodec, Codec valueCodec) { + return Codec.unboundedMap(keyCodec, LibCodecUtils.homogenousList(valueCodec, false)).xmap(map -> { + ImmutableListMultimap.Builder builder = ImmutableListMultimap.builder(); + for (Map.Entry> entry : map.entrySet()) { + builder.putAll(entry.getKey(), entry.getValue()); + } + return builder.build(); + }, multimap -> { + Map> map = new Hashtable<>(); + for (K holder : multimap.keySet()) { + map.put(holder, multimap.get(holder)); + } + return map; + }); + } } From 572e586d143bb3a593b4961e20fff69ea6fcd172 Mon Sep 17 00:00:00 2001 From: westernat Date: Sun, 7 Sep 2025 11:46:55 +0800 Subject: [PATCH 37/61] =?UTF-8?q?=E4=BF=AE=E4=B8=89=E6=9C=AC=E4=BF=9D?= =?UTF-8?q?=E6=8A=A4=E4=B9=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../confluence/lib/common/data/IdFixer.java | 2 +- .../lib/common/event/GameEvents.java | 33 ++++++++++++++-- .../lib/common/item/FunctionItem.java | 26 +++++++++++++ .../lib/common/item/IFunctionCouldEnable.java | 29 ++++++++++++++ .../{api => event}/NameFixRegisterEvent.java | 2 +- .../lib/event/SwitchItemFunctionEvent.java | 38 +++++++++++++++++++ .../confluence/lib/util/LibClientUtils.java | 7 ++++ 7 files changed, 131 insertions(+), 6 deletions(-) create mode 100644 src/main/java/org/confluence/lib/common/item/FunctionItem.java create mode 100644 src/main/java/org/confluence/lib/common/item/IFunctionCouldEnable.java rename src/main/java/org/confluence/lib/{api => event}/NameFixRegisterEvent.java (98%) create mode 100644 src/main/java/org/confluence/lib/event/SwitchItemFunctionEvent.java diff --git a/src/main/java/org/confluence/lib/common/data/IdFixer.java b/src/main/java/org/confluence/lib/common/data/IdFixer.java index 604625b..ff1822c 100644 --- a/src/main/java/org/confluence/lib/common/data/IdFixer.java +++ b/src/main/java/org/confluence/lib/common/data/IdFixer.java @@ -23,7 +23,7 @@ import net.neoforged.fml.ModLoader; import org.apache.commons.lang3.mutable.MutableObject; import org.confluence.lib.ConfluenceMagicLib; -import org.confluence.lib.api.NameFixRegisterEvent; +import org.confluence.lib.event.NameFixRegisterEvent; import org.confluence.lib.util.LibCodecUtils; import org.confluence.lib.util.LibUtils; import org.jetbrains.annotations.ApiStatus; diff --git a/src/main/java/org/confluence/lib/common/event/GameEvents.java b/src/main/java/org/confluence/lib/common/event/GameEvents.java index 2259adb..840998a 100644 --- a/src/main/java/org/confluence/lib/common/event/GameEvents.java +++ b/src/main/java/org/confluence/lib/common/event/GameEvents.java @@ -2,20 +2,28 @@ import net.minecraft.ChatFormatting; import net.minecraft.network.chat.Component; -import net.minecraft.server.level.ServerLevel; +import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.ClickAction; +import net.minecraft.world.item.ItemStack; import net.neoforged.bus.api.EventPriority; import net.neoforged.bus.api.SubscribeEvent; import net.neoforged.fml.common.EventBusSubscriber; +import net.neoforged.neoforge.common.NeoForge; +import net.neoforged.neoforge.event.ItemStackedOnOtherEvent; import net.neoforged.neoforge.event.entity.living.LivingDeathEvent; import net.neoforged.neoforge.event.entity.living.LivingDropsEvent; import net.neoforged.neoforge.event.entity.living.LivingHealEvent; import net.neoforged.neoforge.event.entity.player.PlayerEvent; import net.neoforged.neoforge.event.server.ServerStoppedEvent; import net.neoforged.neoforge.network.PacketDistributor; +import net.neoforged.neoforge.server.ServerLifecycleHooks; import org.confluence.lib.ConfluenceMagicLib; import org.confluence.lib.common.data.IdFixer; import org.confluence.lib.common.data.saved.IGlobalData; +import org.confluence.lib.common.item.IFunctionCouldEnable; +import org.confluence.lib.event.SwitchItemFunctionEvent; import org.confluence.lib.mixed.IExtraSyncedData; import org.confluence.lib.network.SetEntityDataPacketS2C; import org.confluence.lib.util.LibUtils; @@ -63,13 +71,30 @@ public static void playerLogged(PlayerEvent.PlayerLoggedInEvent event) { public static void checkForNull(LivingDeathEvent event) { if (event.getSource() == null) { event.setCanceled(true); - if (event.getEntity() != null && event.getEntity().level() instanceof ServerLevel level) { + MinecraftServer server = ServerLifecycleHooks.getCurrentServer(); + if (server != null) { StringBuilder builder = new StringBuilder(); - for (StackTraceElement element : level.getServer().getRunningThread().getStackTrace()) { + for (StackTraceElement element : server.getRunningThread().getStackTrace()) { builder.append(element).append('\n'); } ConfluenceMagicLib.LOGGER.error(builder.toString()); - level.getServer().sendSystemMessage(Component.translatable("error.confluence.null").withStyle(ChatFormatting.RED)); + server.sendSystemMessage(Component.translatable("error.confluence.null").withStyle(ChatFormatting.RED)); + } + } + } + + @SubscribeEvent(priority = EventPriority.HIGH, receiveCanceled = true) + public static void itemStackedOnOther(ItemStackedOnOtherEvent event) { + if (event.getClickAction() != ClickAction.SECONDARY) return; + ItemStack carried = event.getCarriedItem(); + ItemStack onSlot = event.getStackedOnItem(); + // 需要注意创造模式物品栏是仅客户端的,所以创造模式无法正常使用 + if (carried.isEmpty() && onSlot.getItem() instanceof IFunctionCouldEnable couldEnable) { + Player player = event.getPlayer(); + if (!NeoForge.EVENT_BUS.post(new SwitchItemFunctionEvent.Pre(player, onSlot)).isCanceled()) { + couldEnable.cycleEnable(onSlot); + NeoForge.EVENT_BUS.post(new SwitchItemFunctionEvent.Post(player, onSlot, couldEnable.isEnabled(onSlot))); + event.setCanceled(true); } } } diff --git a/src/main/java/org/confluence/lib/common/item/FunctionItem.java b/src/main/java/org/confluence/lib/common/item/FunctionItem.java new file mode 100644 index 0000000..31452e1 --- /dev/null +++ b/src/main/java/org/confluence/lib/common/item/FunctionItem.java @@ -0,0 +1,26 @@ +package org.confluence.lib.common.item; + +import net.minecraft.network.chat.Component; +import net.minecraft.world.item.ItemStack; +import org.confluence.lib.common.component.ModRarity; + +import java.util.List; + +public class FunctionItem extends TooltipItem implements IFunctionCouldEnable { + public FunctionItem(Properties properties, ModRarity rarity, List tooltips) { + super(properties, rarity, tooltips); + } + + public FunctionItem(Properties properties, ModRarity rarity, Component tooltip) { + super(properties, rarity, tooltip); + } + + public FunctionItem(Properties properties, ModRarity rarity, String tooltip) { + super(properties, rarity, tooltip); + } + + @Override + public Component getName(ItemStack stack) { + return isEnabled(stack) ? super.getName(stack) : Component.translatable(getDescriptionId(stack) + ".disable"); + } +} diff --git a/src/main/java/org/confluence/lib/common/item/IFunctionCouldEnable.java b/src/main/java/org/confluence/lib/common/item/IFunctionCouldEnable.java new file mode 100644 index 0000000..5a1b474 --- /dev/null +++ b/src/main/java/org/confluence/lib/common/item/IFunctionCouldEnable.java @@ -0,0 +1,29 @@ +package org.confluence.lib.common.item; + +import net.minecraft.world.inventory.tooltip.TooltipComponent; +import net.minecraft.world.item.ItemStack; +import org.confluence.lib.util.LibUtils; +import org.jetbrains.annotations.Nullable; + +public interface IFunctionCouldEnable { + String DISABLE_KEY = "disable"; + + default String getDisableKey() { + return DISABLE_KEY; + } + + default boolean isEnabled(ItemStack itemStack) { + return !LibUtils.getItemStackNbtNoCopy(itemStack).getBoolean(getDisableKey()); + } + + default void cycleEnable(ItemStack itemStack) { + LibUtils.updateItemStackNbt(itemStack, tag -> { + String key = getDisableKey(); + tag.putBoolean(key, !tag.getBoolean(key)); + }); + } + + default @Nullable TooltipComponent getTooltipComponent(ItemStack itemStack) { + return null; + } +} diff --git a/src/main/java/org/confluence/lib/api/NameFixRegisterEvent.java b/src/main/java/org/confluence/lib/event/NameFixRegisterEvent.java similarity index 98% rename from src/main/java/org/confluence/lib/api/NameFixRegisterEvent.java rename to src/main/java/org/confluence/lib/event/NameFixRegisterEvent.java index 2a1d018..aa6c997 100644 --- a/src/main/java/org/confluence/lib/api/NameFixRegisterEvent.java +++ b/src/main/java/org/confluence/lib/event/NameFixRegisterEvent.java @@ -1,4 +1,4 @@ -package org.confluence.lib.api; +package org.confluence.lib.event; import com.google.common.collect.ImmutableMap; import net.minecraft.resources.ResourceLocation; diff --git a/src/main/java/org/confluence/lib/event/SwitchItemFunctionEvent.java b/src/main/java/org/confluence/lib/event/SwitchItemFunctionEvent.java new file mode 100644 index 0000000..6688478 --- /dev/null +++ b/src/main/java/org/confluence/lib/event/SwitchItemFunctionEvent.java @@ -0,0 +1,38 @@ +package org.confluence.lib.event; + +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +import net.neoforged.bus.api.ICancellableEvent; +import net.neoforged.neoforge.event.entity.player.PlayerEvent; + +public abstract class SwitchItemFunctionEvent extends PlayerEvent { + private final ItemStack stack; + + public SwitchItemFunctionEvent(Player player, ItemStack stack) { + super(player); + this.stack = stack; + } + + public ItemStack getStack() { + return stack; + } + + public static class Pre extends SwitchItemFunctionEvent implements ICancellableEvent { + public Pre(Player player, ItemStack stack) { + super(player, stack); + } + } + + public static class Post extends SwitchItemFunctionEvent { + private final boolean enabled; + + public Post(Player player, ItemStack stack, boolean enabled) { + super(player, stack); + this.enabled = enabled; + } + + public boolean isEnabled() { + return enabled; + } + } +} diff --git a/src/main/java/org/confluence/lib/util/LibClientUtils.java b/src/main/java/org/confluence/lib/util/LibClientUtils.java index 20028a5..662c4f6 100644 --- a/src/main/java/org/confluence/lib/util/LibClientUtils.java +++ b/src/main/java/org/confluence/lib/util/LibClientUtils.java @@ -6,11 +6,14 @@ import com.mojang.math.Axis; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.GameRenderer; +import net.minecraft.client.renderer.item.ClampedItemPropertyFunction; +import net.minecraft.nbt.CompoundTag; import net.minecraft.util.FastColor; import net.minecraft.util.Mth; import net.minecraft.world.entity.player.Player; import net.neoforged.api.distmarker.Dist; import net.neoforged.api.distmarker.OnlyIn; +import org.confluence.lib.common.item.IFunctionCouldEnable; import org.joml.Quaternionf; import javax.imageio.ImageIO; @@ -27,6 +30,10 @@ public final class LibClientUtils { public static final Quaternionf ANGLE_N90 = Axis.YP.rotation(-Mth.HALF_PI); public static final int[] FULL_BRIGHT = {0xF000F0, 0xF000F0, 0xF000F0, 0xF000F0}; public static final float INV_255 = 1.0F / 255.0F; + public static final ClampedItemPropertyFunction COULD_ENABLE_PROPERTY_FUNCTION = (stack, level, living, seed) -> { + CompoundTag tag = LibUtils.getItemStackNbtIfPresent(stack); + return tag != null && tag.getBoolean(IFunctionCouldEnable.DISABLE_KEY) ? 0 : 1; + }; public static void setupOverlayRenderState(boolean blend, boolean depthTest) { if (blend) { From c971e1e23b7ef5ae17dbeb0d545b4660af9ddb82 Mon Sep 17 00:00:00 2001 From: westernat Date: Sun, 7 Sep 2025 15:45:37 +0800 Subject: [PATCH 38/61] =?UTF-8?q?=E5=AE=8C=E5=96=84=E9=A3=8E=E6=9A=B4?= =?UTF-8?q?=E9=95=BF=E7=9F=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/confluence/lib/common/entitiy/IAxisZRotate.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/org/confluence/lib/common/entitiy/IAxisZRotate.java b/src/main/java/org/confluence/lib/common/entitiy/IAxisZRotate.java index 5b3bb49..79f8dea 100644 --- a/src/main/java/org/confluence/lib/common/entitiy/IAxisZRotate.java +++ b/src/main/java/org/confluence/lib/common/entitiy/IAxisZRotate.java @@ -25,5 +25,13 @@ class Rotate { public boolean different() { return neo != old; } + + @Override + public String toString() { + return "Rotate{" + + "neo=" + neo + + ", old=" + old + + '}'; + } } } From a63c6bb1d0b6f82fd62b4ca13ce2c191fc4df8b2 Mon Sep 17 00:00:00 2001 From: westernat Date: Tue, 9 Sep 2025 12:00:23 +0800 Subject: [PATCH 39/61] =?UTF-8?q?=E6=88=90=E5=B0=B1=E4=BB=85=E5=90=8C?= =?UTF-8?q?=E6=AD=A5=E6=98=AF=E5=90=A6=E9=9A=90=E8=97=8F=E8=BF=9E=E7=BA=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/org/confluence/lib/util/LibStreamCodecUtils.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/org/confluence/lib/util/LibStreamCodecUtils.java b/src/main/java/org/confluence/lib/util/LibStreamCodecUtils.java index 9bc8259..4d619ec 100644 --- a/src/main/java/org/confluence/lib/util/LibStreamCodecUtils.java +++ b/src/main/java/org/confluence/lib/util/LibStreamCodecUtils.java @@ -1,6 +1,9 @@ package org.confluence.lib.util; import io.netty.buffer.ByteBuf; +import it.unimi.dsi.fastutil.objects.Object2BooleanMap; +import it.unimi.dsi.fastutil.objects.Object2BooleanOpenHashMap; +import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import net.minecraft.MethodsReturnNonnullByDefault; import net.minecraft.network.codec.ByteBufCodecs; import net.minecraft.network.codec.StreamCodec; @@ -44,4 +47,9 @@ public static StreamCodec> tuple(St public static StreamCodec> map(IntFunction> factory, StreamCodec keyCodec, StreamCodec valueCodec) { return ByteBufCodecs.map(factory, keyCodec, valueCodec); } + + @SuppressWarnings("unchecked") + public static StreamCodec> object2BooleanMap(StreamCodec codec) { + return (StreamCodec>) map(Object2BooleanOpenHashMap::new, codec, ByteBufCodecs.BOOL).>map(Object2BooleanOpenHashMap::new, Object2ObjectOpenHashMap::new); + } } From 58097d6cfe01a6105546607b8b614f4859630226 Mon Sep 17 00:00:00 2001 From: westernat Date: Tue, 9 Sep 2025 12:48:52 +0800 Subject: [PATCH 40/61] =?UTF-8?q?=E6=94=B9StreamCodec?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/recipe/AbstractAmountRecipe.java | 4 +- .../common/recipe/EitherAmountRecipe4x.java | 4 +- .../recipe/EnvironmentAmountRecipe.java | 4 +- .../lib/network/ExtraByteBufCodecs.java | 45 ++--------- .../lib/util/LibStreamCodecUtils.java | 75 +++++++++++++++++-- .../org/confluence/lib/util/LibUtils.java | 2 +- 6 files changed, 84 insertions(+), 50 deletions(-) diff --git a/src/main/java/org/confluence/lib/common/recipe/AbstractAmountRecipe.java b/src/main/java/org/confluence/lib/common/recipe/AbstractAmountRecipe.java index 03ffbce..925cb02 100644 --- a/src/main/java/org/confluence/lib/common/recipe/AbstractAmountRecipe.java +++ b/src/main/java/org/confluence/lib/common/recipe/AbstractAmountRecipe.java @@ -22,7 +22,7 @@ import net.minecraft.world.item.crafting.ShapedRecipePattern; import net.minecraft.world.level.Level; import net.neoforged.neoforge.common.crafting.ICustomIngredient; -import org.confluence.lib.network.ExtraByteBufCodecs; +import org.confluence.lib.util.LibStreamCodecUtils; import org.jetbrains.annotations.Nullable; import org.joml.Vector2i; @@ -230,7 +230,7 @@ public static > MapCodec shapelessSerialize public static > StreamCodec shapelessSerializerSteamCodec(BiFunction, R> factory) { return StreamCodec.composite( ItemStack.STREAM_CODEC, r -> r.result, - ExtraByteBufCodecs.INGREDIENTS, r -> r.getIngredients(), + LibStreamCodecUtils.INGREDIENTS, r -> r.getIngredients(), factory ); } diff --git a/src/main/java/org/confluence/lib/common/recipe/EitherAmountRecipe4x.java b/src/main/java/org/confluence/lib/common/recipe/EitherAmountRecipe4x.java index a41215b..4e6d450 100644 --- a/src/main/java/org/confluence/lib/common/recipe/EitherAmountRecipe4x.java +++ b/src/main/java/org/confluence/lib/common/recipe/EitherAmountRecipe4x.java @@ -14,13 +14,13 @@ import net.minecraft.world.item.crafting.ShapedRecipePattern; import net.minecraft.world.level.Level; import org.confluence.lib.mixed.LibShapedRecipePattern; -import org.confluence.lib.network.ExtraByteBufCodecs; +import org.confluence.lib.util.LibStreamCodecUtils; import java.util.function.BiFunction; import java.util.function.Function; public abstract class EitherAmountRecipe4x extends AbstractAmountRecipe { - public static final StreamCodec>> EITHER_CODEC = ByteBufCodecs.either(ShapedRecipePattern.STREAM_CODEC, ExtraByteBufCodecs.INGREDIENTS); + public static final StreamCodec>> EITHER_CODEC = ByteBufCodecs.either(ShapedRecipePattern.STREAM_CODEC, LibStreamCodecUtils.INGREDIENTS); public final Either> either; public EitherAmountRecipe4x(ItemStack result, ShapedRecipePattern pattern) { diff --git a/src/main/java/org/confluence/lib/common/recipe/EnvironmentAmountRecipe.java b/src/main/java/org/confluence/lib/common/recipe/EnvironmentAmountRecipe.java index 0618686..b82c3fe 100644 --- a/src/main/java/org/confluence/lib/common/recipe/EnvironmentAmountRecipe.java +++ b/src/main/java/org/confluence/lib/common/recipe/EnvironmentAmountRecipe.java @@ -9,7 +9,7 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.crafting.Ingredient; import net.minecraft.world.level.Level; -import org.confluence.lib.network.ExtraByteBufCodecs; +import org.confluence.lib.util.LibStreamCodecUtils; public abstract class EnvironmentAmountRecipe extends AbstractAmountRecipe { protected final EnvironmentLevelAccess.Matcher environment; @@ -39,7 +39,7 @@ public static MapCodec environmentShapele public static StreamCodec environmentShapelessSerializerSteamCodec(Function3, EnvironmentLevelAccess.Matcher, R> factory) { return StreamCodec.composite( ItemStack.STREAM_CODEC, r -> r.result, - ExtraByteBufCodecs.INGREDIENTS, AbstractAmountRecipe::getIngredients, + LibStreamCodecUtils.INGREDIENTS, AbstractAmountRecipe::getIngredients, EnvironmentLevelAccess.Matcher.STREAM_CODEC, EnvironmentAmountRecipe::getEnvironment, factory ); diff --git a/src/main/java/org/confluence/lib/network/ExtraByteBufCodecs.java b/src/main/java/org/confluence/lib/network/ExtraByteBufCodecs.java index 0f40665..d76f322 100644 --- a/src/main/java/org/confluence/lib/network/ExtraByteBufCodecs.java +++ b/src/main/java/org/confluence/lib/network/ExtraByteBufCodecs.java @@ -8,11 +8,11 @@ import net.minecraft.network.RegistryFriendlyByteBuf; import net.minecraft.network.codec.StreamCodec; import net.minecraft.resources.ResourceKey; -import net.minecraft.resources.ResourceLocation; import net.minecraft.tags.TagKey; import net.minecraft.util.Tuple; import net.minecraft.world.item.crafting.Ingredient; -import org.confluence.lib.common.recipe.AmountIngredient; +import org.confluence.lib.util.LibStreamCodecUtils; +import org.jetbrains.annotations.ApiStatus; import javax.annotation.ParametersAreNonnullByDefault; import java.util.ArrayList; @@ -20,6 +20,8 @@ @ParametersAreNonnullByDefault @MethodsReturnNonnullByDefault +@Deprecated(forRemoval = true) +@ApiStatus.ScheduledForRemoval(inVersion = "1.3.0") public interface ExtraByteBufCodecs { StreamCodec LONG = new StreamCodec<>() { public Long decode(ByteBuf buffer) { @@ -30,33 +32,8 @@ public void encode(ByteBuf buffer, Long value) { buffer.writeLong(value); } }; - StreamCodec> INGREDIENTS = new StreamCodec<>() { - @Override - public NonNullList decode(RegistryFriendlyByteBuf buffer) { - NonNullList nonnulllist = NonNullList.withSize(buffer.readVarInt(), AmountIngredient.EMPTY); - nonnulllist.replaceAll(ignore -> Ingredient.CONTENTS_STREAM_CODEC.decode(buffer)); - return nonnulllist; - } - - @Override - public void encode(RegistryFriendlyByteBuf buffer, NonNullList value) { - buffer.writeVarInt(value.size()); - for (Ingredient ingredient : value) { - Ingredient.CONTENTS_STREAM_CODEC.encode(buffer, ingredient); - } - } - }; - StreamCodec UUID = new StreamCodec<>() { - @Override - public java.util.UUID decode(FriendlyByteBuf buffer) { - return buffer.readUUID(); - } - - @Override - public void encode(FriendlyByteBuf buffer, java.util.UUID value) { - buffer.writeUUID(value); - } - }; + StreamCodec> INGREDIENTS = LibStreamCodecUtils.INGREDIENTS; + StreamCodec UUID = LibStreamCodecUtils.UUID; static StreamCodec> tuple(StreamCodec codecA, StreamCodec codecB) { return new StreamCodec<>() { @@ -96,14 +73,6 @@ public void encode(B buffer, List value) { } static StreamCodec> tagKey(ResourceKey> resourceKey) { - return new StreamCodec<>() { - public TagKey decode(B buffer) { - return TagKey.create(resourceKey, ResourceLocation.STREAM_CODEC.decode(buffer)); - } - - public void encode(B buffer, TagKey tagKey) { - ResourceLocation.STREAM_CODEC.encode(buffer, tagKey.location()); - } - }; + return LibStreamCodecUtils.tagKey(resourceKey); } } diff --git a/src/main/java/org/confluence/lib/util/LibStreamCodecUtils.java b/src/main/java/org/confluence/lib/util/LibStreamCodecUtils.java index 4d619ec..692f67e 100644 --- a/src/main/java/org/confluence/lib/util/LibStreamCodecUtils.java +++ b/src/main/java/org/confluence/lib/util/LibStreamCodecUtils.java @@ -3,12 +3,20 @@ import io.netty.buffer.ByteBuf; import it.unimi.dsi.fastutil.objects.Object2BooleanMap; import it.unimi.dsi.fastutil.objects.Object2BooleanOpenHashMap; -import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import net.minecraft.MethodsReturnNonnullByDefault; +import net.minecraft.core.NonNullList; +import net.minecraft.core.Registry; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.RegistryFriendlyByteBuf; import net.minecraft.network.codec.ByteBufCodecs; import net.minecraft.network.codec.StreamCodec; +import net.minecraft.resources.ResourceKey; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.tags.TagKey; import net.minecraft.util.Tuple; +import net.minecraft.world.item.crafting.Ingredient; import net.minecraft.world.phys.Vec2; +import org.confluence.lib.common.recipe.AmountIngredient; import javax.annotation.ParametersAreNonnullByDefault; import java.util.Map; @@ -18,13 +26,40 @@ @ParametersAreNonnullByDefault @MethodsReturnNonnullByDefault public final class LibStreamCodecUtils { - public static final StreamCodec VEC_2_STREAM_CODEC = StreamCodec.composite( + public static final StreamCodec VEC_2 = StreamCodec.composite( ByteBufCodecs.FLOAT, vec2 -> vec2.x, ByteBufCodecs.FLOAT, vec2 -> vec2.y, Vec2::new ); + public static final StreamCodec UUID = new StreamCodec<>() { + @Override + public java.util.UUID decode(FriendlyByteBuf buffer) { + return buffer.readUUID(); + } - public static StreamCodec unit(Supplier expectedValue) { + @Override + public void encode(FriendlyByteBuf buffer, java.util.UUID value) { + buffer.writeUUID(value); + } + }; + public static final StreamCodec> INGREDIENTS = new StreamCodec<>() { + @Override + public NonNullList decode(RegistryFriendlyByteBuf buffer) { + NonNullList nonnulllist = NonNullList.withSize(buffer.readVarInt(), AmountIngredient.EMPTY); + nonnulllist.replaceAll(ignore -> Ingredient.CONTENTS_STREAM_CODEC.decode(buffer)); + return nonnulllist; + } + + @Override + public void encode(RegistryFriendlyByteBuf buffer, NonNullList value) { + buffer.writeVarInt(value.size()); + for (Ingredient ingredient : value) { + Ingredient.CONTENTS_STREAM_CODEC.encode(buffer, ingredient); + } + } + }; + + public static StreamCodec unit(Supplier expectedValue) { return new StreamCodec<>() { @Override public V decode(B buffer) { @@ -48,8 +83,38 @@ public static StreamCodec> map(IntFunctio return ByteBufCodecs.map(factory, keyCodec, valueCodec); } + public static StreamCodec> object2BooleanMap(StreamCodec codec) { + return ByteBufCodecs.map(Object2BooleanOpenHashMap::new, codec, ByteBufCodecs.BOOL); + } + + public static StreamCodec> tagKey(ResourceKey> resourceKey) { + return new StreamCodec<>() { + public TagKey decode(B buffer) { + return TagKey.create(resourceKey, ResourceLocation.STREAM_CODEC.decode(buffer)); + } + + public void encode(B buffer, TagKey tagKey) { + ResourceLocation.STREAM_CODEC.encode(buffer, tagKey.location()); + } + }; + } + @SuppressWarnings("unchecked") - public static StreamCodec> object2BooleanMap(StreamCodec codec) { - return (StreamCodec>) map(Object2BooleanOpenHashMap::new, codec, ByteBufCodecs.BOOL).>map(Object2BooleanOpenHashMap::new, Object2ObjectOpenHashMap::new); + public static StreamCodec registry(Registry registry) { + return (StreamCodec) ResourceLocation.STREAM_CODEC.map(registry::get, registry::getKey); + } + + public static StreamCodec lazyInitialized(Supplier> delegate) { + return new StreamCodec<>() { + @Override + public V decode(B buffer) { + return delegate.get().decode(buffer); + } + + @Override + public void encode(B buffer, V value) { + delegate.get().encode(buffer, value); + } + }; } } diff --git a/src/main/java/org/confluence/lib/util/LibUtils.java b/src/main/java/org/confluence/lib/util/LibUtils.java index d51cd4b..5c8ef8c 100644 --- a/src/main/java/org/confluence/lib/util/LibUtils.java +++ b/src/main/java/org/confluence/lib/util/LibUtils.java @@ -54,7 +54,7 @@ public final class LibUtils { public static final String NO_DROPS_TAG = "confluence:no_drops"; public static final EffectCure DENY_HEAL = EffectCure.get("confluence:deny_heal"); public static final @Deprecated Codec VEC_2_CODEC = LibCodecUtils.VEC_2; - public static final @Deprecated StreamCodec VEC_2_STREAM_CODEC = LibStreamCodecUtils.VEC_2_STREAM_CODEC; + public static final @Deprecated StreamCodec VEC_2_STREAM_CODEC = LibStreamCodecUtils.VEC_2; @ApiStatus.Internal public static void forMixin$Inject() {} From d2f31828a4b85ed102bcc982c22d9e20e7a99b22 Mon Sep 17 00:00:00 2001 From: westernat Date: Thu, 11 Sep 2025 21:19:29 +0800 Subject: [PATCH 41/61] =?UTF-8?q?=E4=B8=BA4x=E5=90=88=E6=88=90=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E7=89=A9=E5=93=81=E8=BD=AC=E7=A7=BB=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/confluence/lib/ConfluenceMagicLib.java | 4 +++- .../confluence/lib/common/item/ColoredItem.java | 17 +++++++++++++++-- .../menu/EitherAmountContainerMenu4x.java | 10 +++++++--- .../lib/common/recipe/EitherAmountRecipe4x.java | 6 +++--- .../java/org/confluence/lib/util/LibUtils.java | 14 ++++++++++---- 5 files changed, 38 insertions(+), 13 deletions(-) diff --git a/src/main/java/org/confluence/lib/ConfluenceMagicLib.java b/src/main/java/org/confluence/lib/ConfluenceMagicLib.java index fb79e81..bc7bcd9 100644 --- a/src/main/java/org/confluence/lib/ConfluenceMagicLib.java +++ b/src/main/java/org/confluence/lib/ConfluenceMagicLib.java @@ -24,6 +24,7 @@ import org.confluence.lib.common.recipe.AmountIngredient; import org.confluence.lib.common.worldgen.structure.GridPiece; import org.confluence.lib.common.worldgen.structure.SimpleTemplatePiece; +import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -75,7 +76,8 @@ public static ResourceLocation asResource(String path) { return ResourceLocation.fromNamespaceAndPath(LIB_ID, path); } - @Deprecated + @Deprecated(since = "1.2.0", forRemoval = true) + @ApiStatus.ScheduledForRemoval(inVersion = "1.3.0") public static boolean isConfluenceLoaded() { return IS_CONFLUENCE_LOADED.get(); } diff --git a/src/main/java/org/confluence/lib/common/item/ColoredItem.java b/src/main/java/org/confluence/lib/common/item/ColoredItem.java index 9852c8d..8e80f00 100644 --- a/src/main/java/org/confluence/lib/common/item/ColoredItem.java +++ b/src/main/java/org/confluence/lib/common/item/ColoredItem.java @@ -5,17 +5,30 @@ import org.confluence.lib.common.component.ModRarity; import org.confluence.lib.common.component.NbtComponent; import org.confluence.lib.util.LibUtils; +import org.jetbrains.annotations.ApiStatus; public class ColoredItem extends CustomRarityItem { public ColoredItem(Properties properties, ModRarity rarity) { super(properties, rarity); } + @Deprecated(since = "1.2.0", forRemoval = true) + @ApiStatus.ScheduledForRemoval(inVersion = "1.3.0") public static void setColor(ItemStack itemStack, int rgb) { - LibUtils.updateItemStackNbt(itemStack, tag -> tag.putInt("color", rgb)); + setRGBA(itemStack, rgb); } + public static void setRGBA(ItemStack itemStack, int rgba) { + LibUtils.updateItemStackNbt(itemStack, tag -> tag.putInt("color", rgba)); + } + + @Deprecated(since = "1.2.0", forRemoval = true) + @ApiStatus.ScheduledForRemoval(inVersion = "1.3.0") public static int getColor(ItemStack itemStack) { + return getRGBA(itemStack); + } + + public static int getRGBA(ItemStack itemStack) { NbtComponent nbtComponent = itemStack.get(ConfluenceMagicLib.NBT); if (nbtComponent == null) { return 0xFF66CCFF; @@ -25,7 +38,7 @@ public static int getColor(ItemStack itemStack) { public static void merge(ItemStack carried, ItemStack onSlot) { if (onSlot.getItem() instanceof ColoredItem && ItemStack.isSameItem(onSlot, carried)) { - ColoredItem.setColor(carried, ColoredItem.getColor(onSlot)); + setRGBA(carried, getRGBA(onSlot)); } } } diff --git a/src/main/java/org/confluence/lib/common/menu/EitherAmountContainerMenu4x.java b/src/main/java/org/confluence/lib/common/menu/EitherAmountContainerMenu4x.java index 5147d1d..daf3bf7 100644 --- a/src/main/java/org/confluence/lib/common/menu/EitherAmountContainerMenu4x.java +++ b/src/main/java/org/confluence/lib/common/menu/EitherAmountContainerMenu4x.java @@ -60,6 +60,10 @@ public > EitherAmountContainer addDataSlot(selectedRecipeIndex); } + public A getAccess() { + return access; + } + public int getCurrentIndex() { return selectedRecipeIndex.get(); } @@ -226,12 +230,12 @@ public Container getContainer() { } public void clearContainerNoUpdate(Player player) { - if (!player.isAlive() || player instanceof ServerPlayer && ((ServerPlayer)player).hasDisconnected()) { - for(int j = 0; j < input.getContainerSize(); ++j) { + if (!player.isAlive() || player instanceof ServerPlayer && ((ServerPlayer) player).hasDisconnected()) { + for (int j = 0; j < input.getContainerSize(); ++j) { player.drop(input.removeItemNoUpdate(j), false); } } else { - for(int i = 0; i < input.getContainerSize(); ++i) { + for (int i = 0; i < input.getContainerSize(); ++i) { Inventory inventory = player.getInventory(); if (inventory.player instanceof ServerPlayer) { inventory.placeItemBackInInventory(input.removeItemNoUpdate(i), false); diff --git a/src/main/java/org/confluence/lib/common/recipe/EitherAmountRecipe4x.java b/src/main/java/org/confluence/lib/common/recipe/EitherAmountRecipe4x.java index 4e6d450..b5c9163 100644 --- a/src/main/java/org/confluence/lib/common/recipe/EitherAmountRecipe4x.java +++ b/src/main/java/org/confluence/lib/common/recipe/EitherAmountRecipe4x.java @@ -19,7 +19,7 @@ import java.util.function.BiFunction; import java.util.function.Function; -public abstract class EitherAmountRecipe4x extends AbstractAmountRecipe { +public abstract class EitherAmountRecipe4x extends AbstractAmountRecipe { public static final StreamCodec>> EITHER_CODEC = ByteBufCodecs.either(ShapedRecipePattern.STREAM_CODEC, LibStreamCodecUtils.INGREDIENTS); public final Either> either; @@ -49,7 +49,7 @@ public boolean canCraftInDimensions(int width, int height) { } @Override - public boolean matches(T input, Level level) { + public boolean matches(I input, Level level) { return either.map( shaped -> shaped.matches(input.asCraftingInput(false)), shapeless -> matches(input.size(), input::getItem, shapeless) @@ -57,7 +57,7 @@ public boolean matches(T input, Level level) { } @Override - public ItemStack assembleAndExtract(T input, HolderLookup.Provider registries) { + public ItemStack assembleAndExtract(I input, HolderLookup.Provider registries) { either .ifLeft(shaped -> consumeShaped(input, 4, 4, shaped)) .ifRight(shapeless -> consumeShapeless(input, shapeless)); diff --git a/src/main/java/org/confluence/lib/util/LibUtils.java b/src/main/java/org/confluence/lib/util/LibUtils.java index 5c8ef8c..56585ed 100644 --- a/src/main/java/org/confluence/lib/util/LibUtils.java +++ b/src/main/java/org/confluence/lib/util/LibUtils.java @@ -53,8 +53,12 @@ public final class LibUtils { public static final int MAX_STACK_SIZE = 9999; public static final String NO_DROPS_TAG = "confluence:no_drops"; public static final EffectCure DENY_HEAL = EffectCure.get("confluence:deny_heal"); - public static final @Deprecated Codec VEC_2_CODEC = LibCodecUtils.VEC_2; - public static final @Deprecated StreamCodec VEC_2_STREAM_CODEC = LibStreamCodecUtils.VEC_2; + @Deprecated(since = "1.2.0", forRemoval = true) + @ApiStatus.ScheduledForRemoval(inVersion = "1.3.0") + public static final Codec VEC_2_CODEC = LibCodecUtils.VEC_2; + @Deprecated(since = "1.2.0", forRemoval = true) + @ApiStatus.ScheduledForRemoval(inVersion = "1.3.0") + public static final StreamCodec VEC_2_STREAM_CODEC = LibStreamCodecUtils.VEC_2; @ApiStatus.Internal public static void forMixin$Inject() {} @@ -175,12 +179,14 @@ public static void devRun(Runnable runnable) { } } - @Deprecated + @Deprecated(since = "1.2.0", forRemoval = true) + @ApiStatus.ScheduledForRemoval(inVersion = "1.3.0") public static Codec> tupleCodec(Codec aCodec, Codec bCodec) { return LibCodecUtils.tuple(aCodec, bCodec); } - @Deprecated + @Deprecated(since = "1.2.0", forRemoval = true) + @ApiStatus.ScheduledForRemoval(inVersion = "1.3.0") public static Codec> tripleCodec(Codec lCodec, Codec mCodec, Codec rCodec) { return LibCodecUtils.triple(lCodec, mCodec, rCodec); } From daefad545b59b876ea768744491f0b5c5774f10c Mon Sep 17 00:00:00 2001 From: westernat Date: Thu, 11 Sep 2025 22:35:48 +0800 Subject: [PATCH 42/61] =?UTF-8?q?=E9=9D=9E=E5=BC=80=E5=8F=91=E7=8E=AF?= =?UTF-8?q?=E5=A2=83=E7=9A=84=E5=88=9B=E9=80=A0=E6=A8=A1=E5=BC=8F=E7=89=A9?= =?UTF-8?q?=E5=93=81=E6=A0=8F=E4=B8=8D=E6=98=BE=E7=A4=BAWIP=E7=89=A9?= =?UTF-8?q?=E5=93=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lib/util/WipNotDisplayOutput.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/main/java/org/confluence/lib/util/WipNotDisplayOutput.java diff --git a/src/main/java/org/confluence/lib/util/WipNotDisplayOutput.java b/src/main/java/org/confluence/lib/util/WipNotDisplayOutput.java new file mode 100644 index 0000000..6dbd813 --- /dev/null +++ b/src/main/java/org/confluence/lib/util/WipNotDisplayOutput.java @@ -0,0 +1,27 @@ +package org.confluence.lib.util; + +import net.minecraft.world.item.CreativeModeTab; +import net.minecraft.world.item.ItemStack; +import net.neoforged.fml.loading.FMLEnvironment; +import org.confluence.lib.common.LibTags; + +import javax.annotation.ParametersAreNonnullByDefault; + +@ParametersAreNonnullByDefault +public class WipNotDisplayOutput implements CreativeModeTab.Output { + private final CreativeModeTab.Output delegate; + + public WipNotDisplayOutput(CreativeModeTab.Output delegate) { + this.delegate = delegate; + } + + @Override + public void accept(ItemStack stack, CreativeModeTab.TabVisibility tabVisibility) { + if (displayable(stack)) return; + delegate.accept(stack, tabVisibility); + } + + public static boolean displayable(ItemStack stack) { + return FMLEnvironment.production && stack.is(LibTags.Items.WIP); + } +} From 4f077d92fd18f0bc9eb72ead28a84725661b828b Mon Sep 17 00:00:00 2001 From: westernat Date: Fri, 12 Sep 2025 10:19:16 +0800 Subject: [PATCH 43/61] =?UTF-8?q?=E5=85=81=E8=AE=B8=E9=80=9A=E8=BF=87?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E5=BC=80=E5=85=B3wip=E7=89=A9=E5=93=81?= =?UTF-8?q?=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/confluence/lib/util/WipNotDisplayOutput.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/confluence/lib/util/WipNotDisplayOutput.java b/src/main/java/org/confluence/lib/util/WipNotDisplayOutput.java index 6dbd813..06d96f8 100644 --- a/src/main/java/org/confluence/lib/util/WipNotDisplayOutput.java +++ b/src/main/java/org/confluence/lib/util/WipNotDisplayOutput.java @@ -9,6 +9,7 @@ @ParametersAreNonnullByDefault public class WipNotDisplayOutput implements CreativeModeTab.Output { + private static boolean forceAllow = !FMLEnvironment.production; private final CreativeModeTab.Output delegate; public WipNotDisplayOutput(CreativeModeTab.Output delegate) { @@ -17,11 +18,16 @@ public WipNotDisplayOutput(CreativeModeTab.Output delegate) { @Override public void accept(ItemStack stack, CreativeModeTab.TabVisibility tabVisibility) { - if (displayable(stack)) return; - delegate.accept(stack, tabVisibility); + if (displayable(stack)) { + delegate.accept(stack, tabVisibility); + } } public static boolean displayable(ItemStack stack) { - return FMLEnvironment.production && stack.is(LibTags.Items.WIP); + return forceAllow || !stack.is(LibTags.Items.WIP); + } + + public static void forceAllow() { + forceAllow = true; } } From 837c9277034853e661786373b535c27218703244 Mon Sep 17 00:00:00 2001 From: westernat Date: Fri, 12 Sep 2025 19:18:20 +0800 Subject: [PATCH 44/61] =?UTF-8?q?=E7=89=A9=E5=93=81=E7=A8=80=E6=9C=89?= =?UTF-8?q?=E5=BA=A6=E9=A2=9C=E8=89=B2=E7=8E=B0=E5=9C=A8=E5=85=BC=E5=AE=B9?= =?UTF-8?q?=E4=BC=A0=E8=AF=B4=E7=89=A9=E5=93=81=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lib/common/component/ModRarity.java | 40 ++++++++++++++++--- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/confluence/lib/common/component/ModRarity.java b/src/main/java/org/confluence/lib/common/component/ModRarity.java index d004f4d..0707beb 100644 --- a/src/main/java/org/confluence/lib/common/component/ModRarity.java +++ b/src/main/java/org/confluence/lib/common/component/ModRarity.java @@ -8,6 +8,7 @@ import net.minecraft.network.RegistryFriendlyByteBuf; import net.minecraft.network.chat.MutableComponent; import net.minecraft.network.chat.Style; +import net.minecraft.network.chat.TextColor; import net.minecraft.network.codec.ByteBufCodecs; import net.minecraft.network.codec.StreamCodec; import net.minecraft.world.item.ItemStack; @@ -17,7 +18,7 @@ import org.jetbrains.annotations.Nullable; -public record ModRarity(String name, int color) implements DataComponentType { +public final class ModRarity implements DataComponentType { public static final ModRarity COMMON = new ModRarity("common", 16777215); public static final ModRarity UNCOMMON = new ModRarity("uncommon", 16777045); public static final ModRarity RARE = new ModRarity("rare", 5636095); @@ -73,6 +74,21 @@ public record ModRarity(String name, int color) implements DataComponentType codec() { @@ -86,7 +102,7 @@ public StreamCodec streamCodec() { @Override public boolean equals(Object o) { - return o == this || (o instanceof ModRarity(String name1, int color1) && color == color1 && name.equals(name1)); + return o == this || (o instanceof ModRarity r && color == r.color && name.equals(r.name)); } @Override @@ -94,7 +110,6 @@ public int hashCode() { return 31 * name.hashCode() + color; } - @Override public int color() { if (color == -1) return ExpertColorAnimation.INSTANCE.getColor(); if (color == -2) return MasterColorAnimation.INSTANCE.getColor(); @@ -102,8 +117,7 @@ public int color() { } public static @Nullable ModRarity getRarity(ItemStack itemStack, boolean prototype) { - DataComponentType type = ConfluenceMagicLib.MOD_RARITY.get(); - ModRarity rarity = prototype ? itemStack.getPrototype().get(type) : itemStack.get(type); + ModRarity rarity = getModRarity(itemStack, prototype); if (rarity != null) return rarity; return switch (itemStack.getRarity()) { case COMMON -> COMMON; @@ -118,6 +132,11 @@ public int color() { return getRarity(itemStack, false); } + public static @Nullable ModRarity getModRarity(ItemStack itemStack, boolean prototype) { + DataComponentType type = ConfluenceMagicLib.MOD_RARITY.get(); + return prototype ? itemStack.getPrototype().get(type) : itemStack.get(type); + } + public static Style withColor(ItemStack itemStack, Style style) { ModRarity rarity = getRarity(itemStack); if (rarity == null) return itemStack.getRarity().getStyleModifier().apply(style); @@ -127,4 +146,15 @@ public static Style withColor(ItemStack itemStack, Style style) { public static MutableComponent withColor(ItemStack itemStack, MutableComponent component) { return component.withStyle(style -> withColor(itemStack, style)); } + + public String name() { + return name; + } + + @Override + public String toString() { + return "ModRarity[" + + "name=" + name + ", " + + "color=" + color + ']'; + } } From 3b025dc193d22ced4b5c7fb9a8beb4f992238470 Mon Sep 17 00:00:00 2001 From: westernat Date: Fri, 12 Sep 2025 20:17:35 +0800 Subject: [PATCH 45/61] =?UTF-8?q?=E7=89=A9=E5=93=81=E7=A8=80=E6=9C=89?= =?UTF-8?q?=E5=BA=A6=E9=A2=9C=E8=89=B2=E7=8E=B0=E5=9C=A8=E5=85=BC=E5=AE=B9?= =?UTF-8?q?=E7=89=A9=E5=93=81=E8=BE=B9=E6=A1=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lib/common/component/ModRarity.java | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/confluence/lib/common/component/ModRarity.java b/src/main/java/org/confluence/lib/common/component/ModRarity.java index 0707beb..51b2d22 100644 --- a/src/main/java/org/confluence/lib/common/component/ModRarity.java +++ b/src/main/java/org/confluence/lib/common/component/ModRarity.java @@ -38,8 +38,8 @@ public final class ModRarity implements DataComponentType { public static final ModRarity RED = new ModRarity("red", 0xFF2864); public static final ModRarity PURPLE = new ModRarity("purple", 0xB428FF); - public static final ModRarity EXPERT = new ModRarity("expert", -1); - public static final ModRarity MASTER = new ModRarity("master", -2); + public static final ModRarity EXPERT = new ModRarity("expert", -1, true); + public static final ModRarity MASTER = new ModRarity("master", -2, true); public static final ModRarity QUEST = new ModRarity("quest", 0xFFAF00); public static final HashBiMap ID_MAP = Util.make(HashBiMap.create(), map -> { @@ -76,14 +76,25 @@ public final class ModRarity implements DataComponentType { ); private final String name; private final int color; + private final boolean special; private TextColor textColor; public ModRarity(String name, int color) { this.name = name; this.color = color; + this.special = false; + } + + public ModRarity(String name, int color, boolean special) { + this.name = name; + this.color = color; + this.special = special; } public TextColor asTextColor() { + if (special) { + return TextColor.fromRgb(color()); + } if (textColor == null) { this.textColor = TextColor.fromRgb(color); } @@ -116,6 +127,10 @@ public int color() { return color; } + public boolean isSpecial() { + return special; + } + public static @Nullable ModRarity getRarity(ItemStack itemStack, boolean prototype) { ModRarity rarity = getModRarity(itemStack, prototype); if (rarity != null) return rarity; From 42ed8deda537ec014d2ee52c20ae3b2ecea6b399 Mon Sep 17 00:00:00 2001 From: westernat Date: Fri, 12 Sep 2025 21:11:12 +0800 Subject: [PATCH 46/61] =?UTF-8?q?=E5=8F=8D=E8=BD=AC=E9=87=8D=E5=8A=9B?= =?UTF-8?q?=E9=94=AE=E4=BD=8D=E6=94=B9=E4=B8=BA=E2=86=91=EF=BC=8C=E5=85=81?= =?UTF-8?q?=E8=AE=B8=E5=8F=8D=E8=BD=AC=E9=87=8D=E5=8A=9B=E8=B7=B3=E8=B7=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/org/confluence/lib/common/component/ModRarity.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/org/confluence/lib/common/component/ModRarity.java b/src/main/java/org/confluence/lib/common/component/ModRarity.java index 51b2d22..df154fc 100644 --- a/src/main/java/org/confluence/lib/common/component/ModRarity.java +++ b/src/main/java/org/confluence/lib/common/component/ModRarity.java @@ -17,8 +17,7 @@ import org.confluence.lib.client.animate.MasterColorAnimation; import org.jetbrains.annotations.Nullable; - -public final class ModRarity implements DataComponentType { +public class ModRarity implements DataComponentType { public static final ModRarity COMMON = new ModRarity("common", 16777215); public static final ModRarity UNCOMMON = new ModRarity("uncommon", 16777045); public static final ModRarity RARE = new ModRarity("rare", 5636095); From d9dbeca233fab3fec3d5b884c4224af7a3097710 Mon Sep 17 00:00:00 2001 From: westernat Date: Sat, 13 Sep 2025 20:10:49 +0800 Subject: [PATCH 47/61] =?UTF-8?q?=E6=80=AA=E7=89=A9=E5=9B=BE=E9=89=B4?= =?UTF-8?q?=E5=9F=BA=E7=A1=80=E5=86=85=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lib/util/LibStreamCodecUtils.java | 93 +++++++++++++++++++ 1 file changed, 93 insertions(+) diff --git a/src/main/java/org/confluence/lib/util/LibStreamCodecUtils.java b/src/main/java/org/confluence/lib/util/LibStreamCodecUtils.java index 692f67e..f999916 100644 --- a/src/main/java/org/confluence/lib/util/LibStreamCodecUtils.java +++ b/src/main/java/org/confluence/lib/util/LibStreamCodecUtils.java @@ -1,5 +1,7 @@ package org.confluence.lib.util; +import com.mojang.datafixers.util.Function7; +import com.mojang.datafixers.util.Function8; import io.netty.buffer.ByteBuf; import it.unimi.dsi.fastutil.objects.Object2BooleanMap; import it.unimi.dsi.fastutil.objects.Object2BooleanOpenHashMap; @@ -20,6 +22,7 @@ import javax.annotation.ParametersAreNonnullByDefault; import java.util.Map; +import java.util.function.Function; import java.util.function.IntFunction; import java.util.function.Supplier; @@ -117,4 +120,94 @@ public void encode(B buffer, V value) { } }; } + + public static StreamCodec composite( + final StreamCodec codec1, + final Function getter1, + final StreamCodec codec2, + final Function getter2, + final StreamCodec codec3, + final Function getter3, + final StreamCodec codec4, + final Function getter4, + final StreamCodec codec5, + final Function getter5, + final StreamCodec codec6, + final Function getter6, + final StreamCodec codec7, + final Function getter7, + final Function7 factory + ) { + return new StreamCodec<>() { + @Override + public C decode(B buffer) { + T1 t1 = codec1.decode(buffer); + T2 t2 = codec2.decode(buffer); + T3 t3 = codec3.decode(buffer); + T4 t4 = codec4.decode(buffer); + T5 t5 = codec5.decode(buffer); + T6 t6 = codec6.decode(buffer); + T7 t7 = codec7.decode(buffer); + return factory.apply(t1, t2, t3, t4, t5, t6, t7); + } + + @Override + public void encode(B buffer, C composite) { + codec1.encode(buffer, getter1.apply(composite)); + codec2.encode(buffer, getter2.apply(composite)); + codec3.encode(buffer, getter3.apply(composite)); + codec4.encode(buffer, getter4.apply(composite)); + codec5.encode(buffer, getter5.apply(composite)); + codec6.encode(buffer, getter6.apply(composite)); + codec7.encode(buffer, getter7.apply(composite)); + } + }; + } + + public static StreamCodec composite( + final StreamCodec codec1, + final Function getter1, + final StreamCodec codec2, + final Function getter2, + final StreamCodec codec3, + final Function getter3, + final StreamCodec codec4, + final Function getter4, + final StreamCodec codec5, + final Function getter5, + final StreamCodec codec6, + final Function getter6, + final StreamCodec codec7, + final Function getter7, + final StreamCodec codec8, + final Function getter8, + final Function8 factory + ) { + return new StreamCodec<>() { + @Override + public C decode(B buffer) { + T1 t1 = codec1.decode(buffer); + T2 t2 = codec2.decode(buffer); + T3 t3 = codec3.decode(buffer); + T4 t4 = codec4.decode(buffer); + T5 t5 = codec5.decode(buffer); + T6 t6 = codec6.decode(buffer); + T7 t7 = codec7.decode(buffer); + T8 t8 = codec8.decode(buffer); + return factory.apply(t1, t2, t3, t4, t5, t6, t7, t8); + } + + @Override + public void encode(B buffer, C composite) { + codec1.encode(buffer, getter1.apply(composite)); + codec2.encode(buffer, getter2.apply(composite)); + codec3.encode(buffer, getter3.apply(composite)); + codec4.encode(buffer, getter4.apply(composite)); + codec5.encode(buffer, getter5.apply(composite)); + codec6.encode(buffer, getter6.apply(composite)); + codec7.encode(buffer, getter7.apply(composite)); + codec8.encode(buffer, getter8.apply(composite)); + } + }; + } } From 378132d83ab55af4af7f5915d04866ffb6999be4 Mon Sep 17 00:00:00 2001 From: westernat Date: Sun, 14 Sep 2025 13:51:16 +0800 Subject: [PATCH 48/61] =?UTF-8?q?=E5=AE=A2=E6=88=B7=E7=AB=AF=E6=80=AA?= =?UTF-8?q?=E7=89=A9=E5=9B=BE=E9=89=B4datagen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lib/common/data/gen/CollectRecipeProvider.java | 9 ++++++++- src/main/resources/META-INF/accesstransformer.cfg | 3 +++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/confluence/lib/common/data/gen/CollectRecipeProvider.java b/src/main/java/org/confluence/lib/common/data/gen/CollectRecipeProvider.java index 12d4b64..228d5ff 100644 --- a/src/main/java/org/confluence/lib/common/data/gen/CollectRecipeProvider.java +++ b/src/main/java/org/confluence/lib/common/data/gen/CollectRecipeProvider.java @@ -12,9 +12,11 @@ public class CollectRecipeProvider extends RecipeProvider { private final List subProviders; + private final String name; - public CollectRecipeProvider(PackOutput output, CompletableFuture registries, Factory... factories) { + public CollectRecipeProvider(String name, PackOutput output, CompletableFuture registries, Factory... factories) { super(output, registries); + this.name = name; this.subProviders = Arrays.stream(factories).map(factory -> factory.create(output, registries)).toList(); } @@ -35,6 +37,11 @@ protected CompletableFuture run(CachedOutput output, HolderLookup.Provider re .toArray(CompletableFuture[]::new)); } + @Override + public String getName() { + return name; + } + @FunctionalInterface public interface Factory { AbstractRecipeProvider create(PackOutput output, CompletableFuture registries); diff --git a/src/main/resources/META-INF/accesstransformer.cfg b/src/main/resources/META-INF/accesstransformer.cfg index 808d2b3..5d06926 100644 --- a/src/main/resources/META-INF/accesstransformer.cfg +++ b/src/main/resources/META-INF/accesstransformer.cfg @@ -1,4 +1,7 @@ public net.minecraft.world.item.crafting.ShapedRecipePattern data + public net.minecraft.advancements.critereon.StatePropertiesPredicate$PropertyMatcher public net.minecraft.advancements.critereon.StatePropertiesPredicate$RangedMatcher public net.minecraft.advancements.critereon.StatePropertiesPredicate$ExactMatcher + +public-f net.minecraft.data.recipes.RecipeProvider getName()Ljava/lang/String; From 97ace224146e97c3f0bcb5eb9fc724c91e3e84d2 Mon Sep 17 00:00:00 2001 From: westernat Date: Sun, 14 Sep 2025 20:49:43 +0800 Subject: [PATCH 49/61] =?UTF-8?q?=E9=87=8D=E5=86=99=E9=A6=99=E8=92=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/org/confluence/lib/util/LibCodecUtils.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/org/confluence/lib/util/LibCodecUtils.java b/src/main/java/org/confluence/lib/util/LibCodecUtils.java index 0ddb206..3c1b156 100644 --- a/src/main/java/org/confluence/lib/util/LibCodecUtils.java +++ b/src/main/java/org/confluence/lib/util/LibCodecUtils.java @@ -3,6 +3,7 @@ import com.google.common.collect.ImmutableListMultimap; import com.mojang.datafixers.util.Either; import com.mojang.serialization.Codec; +import com.mojang.serialization.DataResult; import com.mojang.serialization.codecs.RecordCodecBuilder; import net.minecraft.util.Tuple; import net.minecraft.world.phys.Vec2; @@ -66,4 +67,11 @@ public static Codec> multimapCodec(Codec k return map; }); } + + public static Codec floatRange(float min, float max) { + return Codec.FLOAT.validate(value -> value.compareTo(min) >= 0 && value.compareTo(max) <= 0 + ? DataResult.success(value) + : DataResult.error(() -> "Value must be within range [" + min + ";" + max + "]: " + value) + ); + } } From 51a7d63bd6d2145cb2450a124d882b214f4aced1 Mon Sep 17 00:00:00 2001 From: cooobird <113522396+cooobird@users.noreply.github.com> Date: Mon, 15 Sep 2025 09:48:42 +0800 Subject: [PATCH 50/61] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 6490474..c6447b2 100644 --- a/gradle.properties +++ b/gradle.properties @@ -30,7 +30,7 @@ mod_name=Confluence Magic Lib mod_license=MIT # The mod version. See https://semver.org/ ###### remove '-SNAPSHOT' when merge to main branch ###### -mod_version=0.0.2c-SNAPSHOT +mod_version=0.0.2d-SNAPSHOT # The group ID for the mod. It is only important when publishing as an artifact to a Maven repository. # This should match the base package used for the mod sources. # See https://maven.apache.org/guides/mini/guide-naming-conventions.html From 4082e82588f2b4928a24e3d8c8874184b7f59ea3 Mon Sep 17 00:00:00 2001 From: westernat Date: Mon, 15 Sep 2025 22:44:02 +0800 Subject: [PATCH 51/61] =?UTF-8?q?=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/org/confluence/lib/util/LibUtils.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/org/confluence/lib/util/LibUtils.java b/src/main/java/org/confluence/lib/util/LibUtils.java index 56585ed..da3cb6d 100644 --- a/src/main/java/org/confluence/lib/util/LibUtils.java +++ b/src/main/java/org/confluence/lib/util/LibUtils.java @@ -17,6 +17,8 @@ import net.minecraft.world.entity.EquipmentSlot; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.Mob; +import net.minecraft.world.entity.animal.Animal; +import net.minecraft.world.entity.animal.WaterAnimal; import net.minecraft.world.entity.item.ItemEntity; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.Item; @@ -326,4 +328,8 @@ public static List> convertMapToTupleList(Map map) { } return list.build(); } + + public static boolean isAnimal(LivingEntity living) { + return living instanceof Animal || living instanceof WaterAnimal; + } } From 63d1b5ab6c87b733664b3dd2139561dbea9645b5 Mon Sep 17 00:00:00 2001 From: westernat Date: Fri, 19 Sep 2025 22:41:38 +0800 Subject: [PATCH 52/61] =?UTF-8?q?=E8=A1=A5=E5=A4=A7=E9=83=A8=E5=88=86?= =?UTF-8?q?=E6=9D=A1=E7=9B=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/org/confluence/lib/common/data/IdFixer.java | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/confluence/lib/common/data/IdFixer.java b/src/main/java/org/confluence/lib/common/data/IdFixer.java index ff1822c..b066301 100644 --- a/src/main/java/org/confluence/lib/common/data/IdFixer.java +++ b/src/main/java/org/confluence/lib/common/data/IdFixer.java @@ -26,7 +26,6 @@ import org.confluence.lib.event.NameFixRegisterEvent; import org.confluence.lib.util.LibCodecUtils; import org.confluence.lib.util.LibUtils; -import org.jetbrains.annotations.ApiStatus; import java.util.ArrayList; import java.util.List; @@ -34,8 +33,6 @@ import java.util.Optional; import java.util.function.Function; -@Deprecated(since = "1.1.3") -@ApiStatus.ScheduledForRemoval(inVersion = "1.3.0") public class IdFixer { public static final Codec>> FIXED_BLOCK_MAP_CODEC = Codec.lazyInitialized(() -> { Codec>> codec = LibCodecUtils.tuple(Codec.INT, Codec.LONG.listOf().xmap(LongArrayList::new, Function.identity())).listOf(); @@ -185,21 +182,21 @@ public DataResult coApply(DynamicOps ops, Holder input, DataRes public static void postRegisterEvents() { ImmutableMap.Builder blockWithItem = ImmutableMap.builder(); - ModLoader.postEventWrapContainerInModOrder(new NameFixRegisterEvent.BlockWithItem(blockWithItem)); + ModLoader.postEvent(new NameFixRegisterEvent.BlockWithItem(blockWithItem)); ImmutableMap map = blockWithItem.build(); ImmutableMap.Builder block = ImmutableMap.builder(); - ModLoader.postEventWrapContainerInModOrder(new NameFixRegisterEvent.Block(block)); + ModLoader.postEvent(new NameFixRegisterEvent.Block(block)); block.putAll(map); BLOCK_NAME_FIX_MAP = block.build(); ImmutableMap.Builder item = ImmutableMap.builder(); - ModLoader.postEventWrapContainerInModOrder(new NameFixRegisterEvent.Item(item)); + ModLoader.postEvent(new NameFixRegisterEvent.Item(item)); item.putAll(map); ITEM_NAME_FIX_MAP = item.build(); ImmutableMap.Builder biome = ImmutableMap.builder(); - ModLoader.postEventWrapContainerInModOrder(new NameFixRegisterEvent.Biome(biome)); + ModLoader.postEvent(new NameFixRegisterEvent.Biome(biome)); BIOME_NAME_FIX_MAP = biome.build(); } } From 6af47f8ade5122166fccc4d0979957b94b25a0e3 Mon Sep 17 00:00:00 2001 From: westernat Date: Sat, 20 Sep 2025 21:00:36 +0800 Subject: [PATCH 53/61] =?UTF-8?q?=E6=88=BF=E5=B1=8B=E5=86=99=E4=B8=80?= =?UTF-8?q?=E5=8D=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lib/util/LibStreamCodecUtils.java | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/src/main/java/org/confluence/lib/util/LibStreamCodecUtils.java b/src/main/java/org/confluence/lib/util/LibStreamCodecUtils.java index f999916..91a3092 100644 --- a/src/main/java/org/confluence/lib/util/LibStreamCodecUtils.java +++ b/src/main/java/org/confluence/lib/util/LibStreamCodecUtils.java @@ -121,6 +121,49 @@ public void encode(B buffer, V value) { }; } + public static StreamCodec booleanArray(int size) { + int length = size % 8 == 0 ? size / 8 : size / 8 + 1; + return new StreamCodec<>() { + @Override + public boolean[] decode(ByteBuf buffer) { + boolean[] result = new boolean[size]; + for (int i = 0; i < length; i++) { + byte b = buffer.readByte(); + int startIndex = i * 8; + + for (int j = 0; j < 8; j++) { + int index = startIndex + j; + if (index < size) { + result[index] = (b & (1 << j)) != 0; + } + } + } + return result; + } + + @Override + public void encode(ByteBuf buffer, boolean[] value) { + if (value.length != size) { + throw new IllegalArgumentException("Boolean array size mismatch. Expected: " + size + ", actual: " + value.length); + } + + for (int i = 0; i < length; i++) { + byte b = 0; + int startIndex = i * 8; + + for (int j = 0; j < 8; j++) { + int index = startIndex + j; + if (index < value.length && value[index]) { + b |= (byte) (1 << j); + } + } + + buffer.writeByte(b); + } + } + }; + } + public static StreamCodec composite( final StreamCodec codec1, final Function getter1, From 7779e5704265b9b6e7907255ccb110c5998b4d1e Mon Sep 17 00:00:00 2001 From: MakerTechno <102357646+makertechno@users.noreply.github.com> Date: Sun, 21 Sep 2025 23:44:19 +0800 Subject: [PATCH 54/61] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=8F=AF=E4=BB=A5?= =?UTF-8?q?=E6=91=87=E6=99=83=E7=9A=84=E5=A4=A7=E5=9E=8B=E5=90=8A=E7=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...irectionalWithHorizontalNinePartBlock.java | 90 +++++++++++++ ...DirectionalWithHorizontalTenPartBlock.java | 87 ++++++++++++ .../lib/common/block/StateProperties.java | 126 ++++++++++++++++++ 3 files changed, 303 insertions(+) create mode 100644 src/main/java/org/confluence/lib/common/block/HorizontalDirectionalWithHorizontalNinePartBlock.java create mode 100644 src/main/java/org/confluence/lib/common/block/HorizontalDirectionalWithHorizontalTenPartBlock.java diff --git a/src/main/java/org/confluence/lib/common/block/HorizontalDirectionalWithHorizontalNinePartBlock.java b/src/main/java/org/confluence/lib/common/block/HorizontalDirectionalWithHorizontalNinePartBlock.java new file mode 100644 index 0000000..93af13c --- /dev/null +++ b/src/main/java/org/confluence/lib/common/block/HorizontalDirectionalWithHorizontalNinePartBlock.java @@ -0,0 +1,90 @@ +package org.confluence.lib.common.block; + +import com.mojang.serialization.MapCodec; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.context.BlockPlaceContext; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.LevelReader; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.HorizontalDirectionalBlock; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.StateDefinition; +import net.minecraft.world.level.block.state.properties.EnumProperty; +import net.minecraft.world.level.material.PushReaction; +import org.jetbrains.annotations.Nullable; + +public class HorizontalDirectionalWithHorizontalNinePartBlock extends HorizontalDirectionalBlock { + public static final MapCodec CODEC = simpleCodec(HorizontalDirectionalWithHorizontalNinePartBlock::new); + public static final EnumProperty PART = StateProperties.HORIZONTAL_NINE_PART; + public HorizontalDirectionalWithHorizontalNinePartBlock(Properties properties) { + super(properties); + registerDefaultState(this.getStateDefinition().any().setValue(PART, StateProperties.HorizontalNinePart.CENTER).setValue(FACING, Direction.NORTH)); + } + @Override + public MapCodec codec() { + return CODEC; + } + + @Override + public void createBlockStateDefinition(StateDefinition.Builder builder) { + builder.add(PART, FACING); + } + + @Override + public void setPlacedBy(Level level, BlockPos pos, BlockState state, @Nullable LivingEntity placer, ItemStack stack) { + if (!level.isClientSide) { + Direction facing = state.getValue(FACING); + StateProperties.HorizontalNinePart.getAllExcept(facing, pos, state.getValue(PART)).forEach((part, posNew) -> level.setBlockAndUpdate(posNew, state.setValue(PART, part).setValue(FACING, facing))); + } + } + + @Override + public @Nullable BlockState getStateForPlacement(BlockPlaceContext context) { + Level level = context.getLevel(); + BlockPos pos = context.getClickedPos(); + Direction facing = context.getHorizontalDirection().getOpposite(); + + for (BlockPos probableCenter : StateProperties.HorizontalNinePart.getAllExcept(facing, pos, null).values()) { + if (check(probableCenter, facing, level, context)) { + StateProperties.HorizontalNinePart role = StateProperties.HorizontalNinePart.infer(probableCenter, pos, facing); + if (role == null) return null; + else return defaultBlockState().setValue(PART, role).setValue(FACING, facing); + } + } + return null; + } + + private boolean check(BlockPos probableCenter, Direction facing, Level level, BlockPlaceContext context) { + return StateProperties.HorizontalNinePart.getAllExcept(facing, probableCenter, null).entrySet().stream() + .allMatch(entry -> { + if (!canSurvive(defaultBlockState().setValue(PART, entry.getKey()).setValue(FACING, facing), level, entry.getValue())) return false; + if (!level.getBlockState(entry.getValue()).canBeReplaced(context)) return false; + return level.getWorldBorder().isWithinBounds(entry.getValue()); + }); + } + + @Override + public void onRemove(BlockState state, Level level, BlockPos pos, BlockState newState, boolean movedByPiston) { + super.onRemove(state, level, pos, newState, movedByPiston); + StateProperties.HorizontalNinePart partBase = state.getValue(PART); + Direction facing = state.getValue(FACING); + StateProperties.HorizontalNinePart.getAllExcept(facing, partBase.toCenter(pos, facing, false), partBase).forEach((part, posO) -> level.destroyBlock(posO, false)); + } + + @Override + public @Nullable PushReaction getPistonPushReaction(BlockState state) { + return PushReaction.BLOCK; + } + + @Override + public boolean canSurvive(BlockState state, LevelReader level, BlockPos pos) { + if (state.getValue(PART).equals(StateProperties.HorizontalNinePart.CENTER)) { + BlockPos suspendingPos = pos.above(); + return level.getBlockState(suspendingPos).isFaceSturdy(level, suspendingPos, Direction.DOWN); + } + else return super.canSurvive(state, level, pos); + } +} diff --git a/src/main/java/org/confluence/lib/common/block/HorizontalDirectionalWithHorizontalTenPartBlock.java b/src/main/java/org/confluence/lib/common/block/HorizontalDirectionalWithHorizontalTenPartBlock.java new file mode 100644 index 0000000..af3bd07 --- /dev/null +++ b/src/main/java/org/confluence/lib/common/block/HorizontalDirectionalWithHorizontalTenPartBlock.java @@ -0,0 +1,87 @@ +package org.confluence.lib.common.block; + +import com.mojang.serialization.MapCodec; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.context.BlockPlaceContext; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.LevelReader; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.HorizontalDirectionalBlock; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.StateDefinition; +import net.minecraft.world.level.block.state.properties.EnumProperty; +import net.minecraft.world.level.material.PushReaction; +import org.jetbrains.annotations.Nullable; + +public class HorizontalDirectionalWithHorizontalTenPartBlock extends HorizontalDirectionalBlock { + public static final MapCodec CODEC = simpleCodec(HorizontalDirectionalWithHorizontalTenPartBlock::new); + public static final EnumProperty PART = StateProperties.HORIZONTAL_TEN_PART; + public HorizontalDirectionalWithHorizontalTenPartBlock(Properties properties) { + super(properties); + registerDefaultState(this.getStateDefinition().any().setValue(PART, StateProperties.HorizontalTenPart.UP).setValue(FACING, Direction.NORTH)); + } + @Override + public MapCodec codec() { + return CODEC; + } + + @Override + public void createBlockStateDefinition(StateDefinition.Builder builder) { + builder.add(PART, FACING); + } + + @Override + public void setPlacedBy(Level level, BlockPos pos, BlockState state, @Nullable LivingEntity placer, ItemStack stack) { + if (!level.isClientSide) { + Direction facing = state.getValue(FACING); + StateProperties.HorizontalTenPart.getAllExcept(facing, pos, state.getValue(PART)).forEach((part, posNew) -> level.setBlockAndUpdate(posNew, state.setValue(PART, part).setValue(FACING, facing))); + } + } + + @Override + public @Nullable BlockState getStateForPlacement(BlockPlaceContext context) { + Level level = context.getLevel(); + BlockPos pos = context.getClickedPos(); + Direction facing = context.getHorizontalDirection().getOpposite(); + + if (check(pos, facing, level, context)) { + return defaultBlockState().setValue(PART, StateProperties.HorizontalTenPart.UP).setValue(FACING, facing); + } + + return null; + } + + private boolean check(BlockPos probableCenter, Direction facing, Level level, BlockPlaceContext context) { + return StateProperties.HorizontalTenPart.getAllExcept(facing, probableCenter, null).entrySet().stream() + .allMatch(entry -> { + if (!canSurvive(defaultBlockState().setValue(PART, entry.getKey()).setValue(FACING, facing), level, entry.getValue())) return false; + if (!level.getBlockState(entry.getValue()).canBeReplaced(context)) return false; + return level.getWorldBorder().isWithinBounds(entry.getValue()); + }); + } + + @Override + public void onRemove(BlockState state, Level level, BlockPos pos, BlockState newState, boolean movedByPiston) { + super.onRemove(state, level, pos, newState, movedByPiston); + StateProperties.HorizontalTenPart partBase = state.getValue(PART); + Direction facing = state.getValue(FACING); + StateProperties.HorizontalTenPart.getAllExcept(facing, partBase.toBase(pos, facing, false), partBase).forEach((part, posO) -> level.destroyBlock(posO, false)); + } + + @Override + public @Nullable PushReaction getPistonPushReaction(BlockState state) { + return PushReaction.BLOCK; + } + + @Override + public boolean canSurvive(BlockState state, LevelReader level, BlockPos pos) { + if (state.getValue(PART).equals(StateProperties.HorizontalTenPart.UP)) { + BlockPos suspendingPos = pos.above(); + return level.getBlockState(suspendingPos).isFaceSturdy(level, suspendingPos, Direction.DOWN); + } + else return super.canSurvive(state, level, pos); + } +} diff --git a/src/main/java/org/confluence/lib/common/block/StateProperties.java b/src/main/java/org/confluence/lib/common/block/StateProperties.java index 678a316..9f1ca52 100644 --- a/src/main/java/org/confluence/lib/common/block/StateProperties.java +++ b/src/main/java/org/confluence/lib/common/block/StateProperties.java @@ -7,8 +7,11 @@ import net.minecraft.world.level.block.state.properties.BlockStateProperties; import net.minecraft.world.level.block.state.properties.BooleanProperty; import net.minecraft.world.level.block.state.properties.EnumProperty; +import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import java.util.HashMap; import java.util.Map; public class StateProperties { @@ -23,6 +26,8 @@ public class StateProperties { public static final EnumProperty FORWARD_TWO_PART = EnumProperty.create("forward_two_part", ForwardTwoPart.class); public static final EnumProperty HORIZONTAL_FOUR_PART = EnumProperty.create("horizontal_four_part", HorizontalFourPart.class); public static final EnumProperty VERTICAL_FOUR_PART = EnumProperty.create("vertical_four_part", VerticalFourPart.class); + public static final EnumProperty HORIZONTAL_NINE_PART = EnumProperty.create("horizontal_nine_part", HorizontalNinePart.class); + public static final EnumProperty HORIZONTAL_TEN_PART = EnumProperty.create("horizontal_ten_part", HorizontalTenPart.class); public enum HorizontalTwoPart implements StringRepresentable { BASE("base"), @@ -314,4 +319,125 @@ public boolean isUpper() { return this == UP || this == RIGHT_UP; } } + + public enum HorizontalNinePart implements StringRepresentable { + CENTER("center"), + FRONT("front"), + LEFT("left"), + RIGHT("right"), + BACK("back"), + LEFT_FRONT("left_front"), + RIGHT_FRONT("right_front"), + LEFT_BACK("left_back"), + RIGHT_BACK("right_back"); + private final String name; + HorizontalNinePart(String name) { + this.name = name; + } + @Contract(pure = true) + @Override + public @NotNull String getSerializedName() { + return name; + } + + /** + * 从某个方块获取中心方块的相对位置,或从中心获取某个方块的相对位置 + *

+ * 前提是必须要存在该属性 + * + * @param now 正在处理的位置,获取中心时填入本方块位置,获取对应其它方块时填入中心方块位置 + * @param reverseRelative 是否反转延伸。当该值为false时返回中心,为true时返回对应块位置 + * @return 请求的方块位置 + */ + public BlockPos toCenter(BlockPos now, Direction facing, boolean reverseRelative) { + if (reverseRelative) facing = facing.getOpposite(); + return switch (this){ + case FRONT -> now.relative(facing.getOpposite()); + case LEFT_FRONT -> now.relative(facing.getOpposite()).relative(facing.getClockWise()); + case RIGHT_FRONT -> now.relative(facing.getOpposite()).relative(facing.getCounterClockWise()); + case LEFT -> now.relative(facing.getClockWise()); + case RIGHT -> now.relative(facing.getCounterClockWise()); + case LEFT_BACK -> now.relative(facing).relative(facing.getClockWise()); + case RIGHT_BACK -> now.relative(facing).relative(facing.getCounterClockWise()); + case BACK -> now.relative(facing); + default -> now; + }; + } + + /** + * 获取除了ign之外的所有方块的相对位属性和世界坐标 + */ + public static Map getAllExcept(Direction facing, BlockPos center, @Nullable StateProperties.HorizontalNinePart ign) { + Map allEx = new HashMap<>(); + for (HorizontalNinePart part : HorizontalNinePart.values()) { + if (part == ign) continue; + allEx.put(part, part.toCenter(center, facing, true)); + } + return allEx; + } + + /** + * 通过世界位置推断当前方块的相对位属性 + */ + public static @Nullable StateProperties.HorizontalNinePart infer(BlockPos center, BlockPos current, Direction facing) { + for (Map.Entry entry : getAllExcept(facing, center ,null).entrySet()) { + if (entry.getValue().equals(current)) return entry.getKey(); + } + return null; + } + } + + public enum HorizontalTenPart implements StringRepresentable { + UP("up"), + CENTER("center"), + FRONT("front"), + LEFT("left"), + RIGHT("right"), + BACK("back"), + LEFT_FRONT("left_front"), + RIGHT_FRONT("right_front"), + LEFT_BACK("left_back"), + RIGHT_BACK("right_back"); + private final String name; + HorizontalTenPart(String name) { + this.name = name; + } + @Contract(pure = true) + @Override + public @NotNull String getSerializedName() { + return name; + } + public BlockPos toBase(BlockPos now, Direction facing, boolean reverseRelative) { + if (reverseRelative) facing = facing.getOpposite(); + int verticalReverse = reverseRelative? -1 : 1; + return switch (this){ + case UP -> now; + case CENTER -> now.above(verticalReverse); + case FRONT -> now.relative(facing.getOpposite()).above(verticalReverse); + case LEFT_FRONT -> now.relative(facing.getOpposite()).relative(facing.getClockWise()).above(verticalReverse); + case RIGHT_FRONT -> now.relative(facing.getOpposite()).relative(facing.getCounterClockWise()).above(verticalReverse); + case LEFT -> now.relative(facing.getClockWise()).above(verticalReverse); + case RIGHT -> now.relative(facing.getCounterClockWise()).above(verticalReverse); + case LEFT_BACK -> now.relative(facing).relative(facing.getClockWise()).above(verticalReverse); + case RIGHT_BACK -> now.relative(facing).relative(facing.getCounterClockWise()).above(verticalReverse); + case BACK -> now.relative(facing).above(verticalReverse); + }; + } + + public static @NotNull Map getAllExcept(Direction facing, BlockPos center, @Nullable StateProperties.HorizontalTenPart ign) { + Map allEx = new HashMap<>(); + for (HorizontalTenPart part : HorizontalTenPart.values()) { + if (part == ign) continue; + allEx.put(part, part.toBase(center, facing, true)); + } + return allEx; + } + + public static @Nullable StateProperties.HorizontalTenPart infer(BlockPos center, BlockPos current, Direction facing) { + for (Map.Entry entry : getAllExcept(facing, center ,null).entrySet()) { + if (entry.getValue().equals(current)) return entry.getKey(); + } + return null; + } + } } From 9c2d90607788dd75b5237edfb891f845100665da Mon Sep 17 00:00:00 2001 From: westernat Date: Mon, 22 Sep 2025 13:07:56 +0800 Subject: [PATCH 55/61] =?UTF-8?q?=E9=A2=9D=E5=A4=96=E6=A0=8F=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E5=BC=80=E5=85=B3=E6=8C=89=E9=92=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/org/confluence/lib/color/FloatRGB.java | 2 -- .../confluence/lib/common/data/gen/AbstractRecipeProvider.java | 2 +- .../org/confluence/lib/common/recipe/AbstractAmountRecipe.java | 2 +- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/confluence/lib/color/FloatRGB.java b/src/main/java/org/confluence/lib/color/FloatRGB.java index 3bd3ef3..776ab74 100644 --- a/src/main/java/org/confluence/lib/color/FloatRGB.java +++ b/src/main/java/org/confluence/lib/color/FloatRGB.java @@ -7,8 +7,6 @@ public record FloatRGB(float red, float green, float blue) { public static final FloatRGB ZERO = new FloatRGB(0.0F, 0.0F, 0.0F); - public static final FloatRGB DEMON_A = new FloatRGB(0.5F, 0.3F, 1.0F); - public static final FloatRGB DEMON_B = new FloatRGB(1.0F, 0.3F, 0.0F); public static FloatRGB fromVector(Vector3f vector3f) { return new FloatRGB(vector3f.x, vector3f.y, vector3f.z); diff --git a/src/main/java/org/confluence/lib/common/data/gen/AbstractRecipeProvider.java b/src/main/java/org/confluence/lib/common/data/gen/AbstractRecipeProvider.java index 06b76d3..9fdda2e 100644 --- a/src/main/java/org/confluence/lib/common/data/gen/AbstractRecipeProvider.java +++ b/src/main/java/org/confluence/lib/common/data/gen/AbstractRecipeProvider.java @@ -42,7 +42,7 @@ protected CompletableFuture run(CachedOutput output, HolderLookup.Provider re futures.add(DataProvider.saveStable(output, entry.getValue(), entry.getKey())); } } - return CompletableFuture.allOf(futures.toArray(CompletableFuture[]::new)); + return CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])); }, Util.backgroundExecutor()).thenCompose(completableFuture -> completableFuture); } diff --git a/src/main/java/org/confluence/lib/common/recipe/AbstractAmountRecipe.java b/src/main/java/org/confluence/lib/common/recipe/AbstractAmountRecipe.java index 925cb02..cc0c7e6 100644 --- a/src/main/java/org/confluence/lib/common/recipe/AbstractAmountRecipe.java +++ b/src/main/java/org/confluence/lib/common/recipe/AbstractAmountRecipe.java @@ -32,7 +32,7 @@ public abstract class AbstractAmountRecipe implements Recipe { public static final MapCodec> INGREDIENTS_CODEC = Ingredient.CODEC_NONEMPTY.listOf().fieldOf("ingredients").flatXmap(list -> { - Ingredient[] ingredients = list.toArray(Ingredient[]::new); + Ingredient[] ingredients = list.toArray(new Ingredient[0]); if (ingredients.length == 0) { return DataResult.error(() -> "No ingredients for recipe"); } else { From ad8916146a19889d0692bfcf9737941ff28da7a3 Mon Sep 17 00:00:00 2001 From: MakerTechno <102357646+makertechno@users.noreply.github.com> Date: Sat, 27 Sep 2025 11:49:33 +0800 Subject: [PATCH 56/61] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=90=8A=E7=81=AF?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E9=97=AE=E9=A2=98=E5=B9=B6=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../block/HorizontalDirectionalWithHorizontalNinePartBlock.java | 1 + .../block/HorizontalDirectionalWithHorizontalTenPartBlock.java | 1 + 2 files changed, 2 insertions(+) diff --git a/src/main/java/org/confluence/lib/common/block/HorizontalDirectionalWithHorizontalNinePartBlock.java b/src/main/java/org/confluence/lib/common/block/HorizontalDirectionalWithHorizontalNinePartBlock.java index 93af13c..97ad0b5 100644 --- a/src/main/java/org/confluence/lib/common/block/HorizontalDirectionalWithHorizontalNinePartBlock.java +++ b/src/main/java/org/confluence/lib/common/block/HorizontalDirectionalWithHorizontalNinePartBlock.java @@ -69,6 +69,7 @@ private boolean check(BlockPos probableCenter, Direction facing, Level level, Bl @Override public void onRemove(BlockState state, Level level, BlockPos pos, BlockState newState, boolean movedByPiston) { super.onRemove(state, level, pos, newState, movedByPiston); + if (newState.getBlock() instanceof HorizontalDirectionalWithHorizontalNinePartBlock) return; StateProperties.HorizontalNinePart partBase = state.getValue(PART); Direction facing = state.getValue(FACING); StateProperties.HorizontalNinePart.getAllExcept(facing, partBase.toCenter(pos, facing, false), partBase).forEach((part, posO) -> level.destroyBlock(posO, false)); diff --git a/src/main/java/org/confluence/lib/common/block/HorizontalDirectionalWithHorizontalTenPartBlock.java b/src/main/java/org/confluence/lib/common/block/HorizontalDirectionalWithHorizontalTenPartBlock.java index af3bd07..d9fbfc7 100644 --- a/src/main/java/org/confluence/lib/common/block/HorizontalDirectionalWithHorizontalTenPartBlock.java +++ b/src/main/java/org/confluence/lib/common/block/HorizontalDirectionalWithHorizontalTenPartBlock.java @@ -66,6 +66,7 @@ private boolean check(BlockPos probableCenter, Direction facing, Level level, Bl @Override public void onRemove(BlockState state, Level level, BlockPos pos, BlockState newState, boolean movedByPiston) { super.onRemove(state, level, pos, newState, movedByPiston); + if (newState.getBlock() instanceof HorizontalDirectionalWithHorizontalTenPartBlock) return; StateProperties.HorizontalTenPart partBase = state.getValue(PART); Direction facing = state.getValue(FACING); StateProperties.HorizontalTenPart.getAllExcept(facing, partBase.toBase(pos, facing, false), partBase).forEach((part, posO) -> level.destroyBlock(posO, false)); From 3c4bf0e0dcad20f3bf401b565530538c532bf738 Mon Sep 17 00:00:00 2001 From: westernat Date: Sat, 27 Sep 2025 21:16:07 +0800 Subject: [PATCH 57/61] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=8C=87=E8=B7=AF?= =?UTF-8?q?=E7=9F=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/org/confluence/lib/util/LibStreamCodecUtils.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/java/org/confluence/lib/util/LibStreamCodecUtils.java b/src/main/java/org/confluence/lib/util/LibStreamCodecUtils.java index 91a3092..1b60bec 100644 --- a/src/main/java/org/confluence/lib/util/LibStreamCodecUtils.java +++ b/src/main/java/org/confluence/lib/util/LibStreamCodecUtils.java @@ -18,6 +18,8 @@ import net.minecraft.util.Tuple; import net.minecraft.world.item.crafting.Ingredient; import net.minecraft.world.phys.Vec2; +import org.apache.commons.lang3.tuple.ImmutableTriple; +import org.apache.commons.lang3.tuple.Triple; import org.confluence.lib.common.recipe.AmountIngredient; import javax.annotation.ParametersAreNonnullByDefault; @@ -28,6 +30,7 @@ @ParametersAreNonnullByDefault @MethodsReturnNonnullByDefault +@SuppressWarnings("unused") public final class LibStreamCodecUtils { public static final StreamCodec VEC_2 = StreamCodec.composite( ByteBufCodecs.FLOAT, vec2 -> vec2.x, @@ -82,6 +85,10 @@ public static StreamCodec> tuple(St return StreamCodec.composite(aCodec, Tuple::getA, bCodec, Tuple::getB, Tuple::new); } + public static StreamCodec> triple(StreamCodec lCodec, StreamCodec mCodec, StreamCodec rCodec) { + return StreamCodec.composite(lCodec, Triple::getLeft, mCodec, Triple::getMiddle, rCodec, Triple::getRight, ImmutableTriple::new); + } + public static StreamCodec> map(IntFunction> factory, StreamCodec keyCodec, StreamCodec valueCodec) { return ByteBufCodecs.map(factory, keyCodec, valueCodec); } From 069b5f36ae38e371f9b06bc44bb22f1324a3ef48 Mon Sep 17 00:00:00 2001 From: westernat Date: Sun, 28 Sep 2025 23:02:32 +0800 Subject: [PATCH 58/61] =?UTF-8?q?=E9=AA=91=E6=9E=AA=E8=AE=A1=E7=AE=97?= =?UTF-8?q?=E7=9B=B8=E5=AF=B9=E9=80=9F=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/org/confluence/lib/util/VectorUtils.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/confluence/lib/util/VectorUtils.java b/src/main/java/org/confluence/lib/util/VectorUtils.java index 959973d..3dd560e 100644 --- a/src/main/java/org/confluence/lib/util/VectorUtils.java +++ b/src/main/java/org/confluence/lib/util/VectorUtils.java @@ -168,9 +168,9 @@ public static ToDoubleFunction getThresholdInterpolator(double efficienc * @return 投影结果 */ public static Vec3 vectorProjection(Vec3 vector, Vec3 toProjectOnto) { - // toProjectOnto.lengthSqr = toProjectOnto.dot(toProjectOnto) - double factor = toProjectOnto.dot(vector) / toProjectOnto.lengthSqr(); - return toProjectOnto.multiply(factor, factor, factor); + double sqr = toProjectOnto.lengthSqr(); + if (sqr == 0.0) throw new IllegalArgumentException("Length of toProjectOnto could not be zero"); + return toProjectOnto.scale(toProjectOnto.dot(vector) / sqr); } /** From d2a21d38b6e972cb407e440fa7505d4c3bac5cde Mon Sep 17 00:00:00 2001 From: MakerTechno <102357646+makertechno@users.noreply.github.com> Date: Fri, 3 Oct 2025 15:38:21 +0800 Subject: [PATCH 59/61] =?UTF-8?q?=E6=94=B9=E5=90=8A=E6=8C=82=E7=9B=86?= =?UTF-8?q?=E4=B8=BA=E5=A4=9A=E6=96=B9=E5=9D=97=E5=B9=B6=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=85=89=E7=85=A7=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../block/HorizontalDirectionalWithVerticalTwoPartBlock.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/confluence/lib/common/block/HorizontalDirectionalWithVerticalTwoPartBlock.java b/src/main/java/org/confluence/lib/common/block/HorizontalDirectionalWithVerticalTwoPartBlock.java index 10244b5..edd6259 100644 --- a/src/main/java/org/confluence/lib/common/block/HorizontalDirectionalWithVerticalTwoPartBlock.java +++ b/src/main/java/org/confluence/lib/common/block/HorizontalDirectionalWithVerticalTwoPartBlock.java @@ -38,7 +38,7 @@ protected void createBlockStateDefinition(StateDefinition.Builder Date: Fri, 3 Oct 2025 18:34:35 +0800 Subject: [PATCH 60/61] =?UTF-8?q?=E5=9C=B0=E7=89=A9=E4=B8=AD=E7=9A=84?= =?UTF-8?q?=E6=AF=92=E9=95=96=E7=8E=B0=E5=9C=A8=E4=BC=9A=E6=A3=80=E6=9F=A5?= =?UTF-8?q?=E6=98=AF=E5=90=A6=E8=B6=8A=E7=95=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/confluence/lib/util/FeatureUtils.java | 23 +++++++++++++++++++ .../resources/META-INF/accesstransformer.cfg | 3 +++ 2 files changed, 26 insertions(+) diff --git a/src/main/java/org/confluence/lib/util/FeatureUtils.java b/src/main/java/org/confluence/lib/util/FeatureUtils.java index d7c01a2..0094084 100644 --- a/src/main/java/org/confluence/lib/util/FeatureUtils.java +++ b/src/main/java/org/confluence/lib/util/FeatureUtils.java @@ -2,7 +2,11 @@ import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; +import net.minecraft.core.SectionPos; +import net.minecraft.server.level.WorldGenRegion; import net.minecraft.util.RandomSource; +import net.minecraft.world.level.ChunkPos; +import net.minecraft.world.level.LevelHeightAccessor; import net.minecraft.world.level.WorldGenLevel; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockBehaviour; @@ -311,4 +315,23 @@ public static boolean rectangularCheck(BlockPos startPos, BlockPos endPos, World } return bl; } + + public static boolean ensureCanWrite(WorldGenLevel level, BlockPos pos) { + if (level instanceof WorldGenRegion region) { + int i = SectionPos.blockToSectionCoord(pos.getX()); + int j = SectionPos.blockToSectionCoord(pos.getZ()); + ChunkPos chunkpos = region.getCenter(); + int k = Math.abs(chunkpos.x - i); + int l = Math.abs(chunkpos.z - j); + if (k <= region.generatingStep.blockStateWriteRadius() && l <= region.generatingStep.blockStateWriteRadius()) { + if (region.center.isUpgrading()) { + LevelHeightAccessor levelheightaccessor = region.center.getHeightAccessorForGeneration(); + return pos.getY() >= levelheightaccessor.getMinBuildHeight() && pos.getY() < levelheightaccessor.getMaxBuildHeight(); + } + return true; + } + return false; + } + return true; + } } diff --git a/src/main/resources/META-INF/accesstransformer.cfg b/src/main/resources/META-INF/accesstransformer.cfg index 5d06926..0419322 100644 --- a/src/main/resources/META-INF/accesstransformer.cfg +++ b/src/main/resources/META-INF/accesstransformer.cfg @@ -5,3 +5,6 @@ public net.minecraft.advancements.critereon.StatePropertiesPredicate$RangedMatch public net.minecraft.advancements.critereon.StatePropertiesPredicate$ExactMatcher public-f net.minecraft.data.recipes.RecipeProvider getName()Ljava/lang/String; + +public net.minecraft.server.level.WorldGenRegion center +public net.minecraft.server.level.WorldGenRegion generatingStep From 79f1ff1fd2c4f8482d3622ffde3b497040f04780 Mon Sep 17 00:00:00 2001 From: westernat Date: Sat, 4 Oct 2025 20:05:57 +0800 Subject: [PATCH 61/61] =?UTF-8?q?=E5=85=81=E8=AE=B8=E9=83=A8=E5=88=86?= =?UTF-8?q?=E5=89=91=E4=BB=A580%=E5=8E=9F=E4=BC=A4=E5=AE=B3=E8=BF=9B?= =?UTF-8?q?=E8=A1=8C=E6=A8=AA=E6=89=AB=EF=BC=8C=E4=B8=94=E5=85=81=E8=AE=B8?= =?UTF-8?q?=E7=A9=BA=E6=8C=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lib/client/AntiPushPoseStack.java | 21 ++++++++++++------- .../org/confluence/lib/mixed/IPoseStack.java | 17 +++++++++++++++ .../lib/mixin/client/PoseSackMixin.java | 8 +++++++ .../confluence_magic_lib.mixins.json | 3 ++- 4 files changed, 41 insertions(+), 8 deletions(-) create mode 100644 src/main/java/org/confluence/lib/mixed/IPoseStack.java create mode 100644 src/main/java/org/confluence/lib/mixin/client/PoseSackMixin.java diff --git a/src/main/java/org/confluence/lib/client/AntiPushPoseStack.java b/src/main/java/org/confluence/lib/client/AntiPushPoseStack.java index 9de3b3f..e20e66e 100644 --- a/src/main/java/org/confluence/lib/client/AntiPushPoseStack.java +++ b/src/main/java/org/confluence/lib/client/AntiPushPoseStack.java @@ -1,26 +1,33 @@ package org.confluence.lib.client; import com.mojang.blaze3d.vertex.PoseStack; +import org.confluence.lib.mixed.IPoseStack; -public class AntiPushPoseStack extends PoseStack { +public class AntiPushPoseStack extends PoseStack implements IPoseStack { @Override - public void popPose(){ + public void popPose() { popPose(false); } @Override - public void pushPose(){ + public void pushPose() { pushPose(false); } - public void popPose(boolean real){ - if(real){ + public void popPose(boolean real) { + if (real) { super.popPose(); } } - public void pushPose(boolean real){ - if(real){ + + public void pushPose(boolean real) { + if (real) { super.pushPose(); } } + + @Override + public boolean confluence$isAntiPush() { + return true; + } } diff --git a/src/main/java/org/confluence/lib/mixed/IPoseStack.java b/src/main/java/org/confluence/lib/mixed/IPoseStack.java new file mode 100644 index 0000000..ce7837e --- /dev/null +++ b/src/main/java/org/confluence/lib/mixed/IPoseStack.java @@ -0,0 +1,17 @@ +package org.confluence.lib.mixed; + +import com.mojang.blaze3d.vertex.PoseStack; + +public interface IPoseStack { + default boolean confluence$isAntiPush() { + return false; + } + + static IPoseStack of(PoseStack poseStack) { + return (IPoseStack) poseStack; + } + + static boolean isAntiPush(PoseStack poseStack) { + return of(poseStack).confluence$isAntiPush(); + } +} diff --git a/src/main/java/org/confluence/lib/mixin/client/PoseSackMixin.java b/src/main/java/org/confluence/lib/mixin/client/PoseSackMixin.java new file mode 100644 index 0000000..5cf74b7 --- /dev/null +++ b/src/main/java/org/confluence/lib/mixin/client/PoseSackMixin.java @@ -0,0 +1,8 @@ +package org.confluence.lib.mixin.client; + +import com.mojang.blaze3d.vertex.PoseStack; +import org.confluence.lib.mixed.IPoseStack; +import org.spongepowered.asm.mixin.Mixin; + +@Mixin(PoseStack.class) +public abstract class PoseSackMixin implements IPoseStack {} diff --git a/src/main/resources/confluence_magic_lib.mixins.json b/src/main/resources/confluence_magic_lib.mixins.json index b2f1e63..59565f9 100644 --- a/src/main/resources/confluence_magic_lib.mixins.json +++ b/src/main/resources/confluence_magic_lib.mixins.json @@ -20,7 +20,8 @@ "client.BlockModelShaperMixin", "client.GuiGraphicsMixin", "client.LocalPlayerMixin", - "client.MissingTextureAtlasSpriteMixin" + "client.MissingTextureAtlasSpriteMixin", + "client.PoseSackMixin" ], "injectors": { "defaultRequire": 1