From ad7c54bdcef2375c7007c900feb0a8b4a3f1db6b Mon Sep 17 00:00:00 2001 From: XFactHD Date: Sat, 9 Nov 2024 01:42:51 +0100 Subject: [PATCH] Fix patched-in BlockParticleOption#pos not getting sent to the client on NF->NF connections --- .../particles/BlockParticleOption.java.patch | 55 ++++++++++++++++--- .../minecraft/world/entity/Entity.java.patch | 2 +- .../world/entity/LivingEntity.java.patch | 4 +- 3 files changed, 50 insertions(+), 11 deletions(-) diff --git a/patches/net/minecraft/core/particles/BlockParticleOption.java.patch b/patches/net/minecraft/core/particles/BlockParticleOption.java.patch index 992032b695..f415767a4b 100644 --- a/patches/net/minecraft/core/particles/BlockParticleOption.java.patch +++ b/patches/net/minecraft/core/particles/BlockParticleOption.java.patch @@ -1,18 +1,57 @@ --- a/net/minecraft/core/particles/BlockParticleOption.java +++ b/net/minecraft/core/particles/BlockParticleOption.java -@@ -37,4 +_,15 @@ - public BlockState getState() { - return this.state; +@@ -15,18 +_,39 @@ + ); + private final ParticleType type; + private final BlockState state; ++ /** Neo: Position of the block this particle was spawned for, if available, to provide model data for the particle texture selection */ ++ @org.jetbrains.annotations.Nullable ++ private final net.minecraft.core.BlockPos pos; + + public static MapCodec codec(ParticleType p_123635_) { + return BLOCK_STATE_CODEC.xmap(p_123638_ -> new BlockParticleOption(p_123635_, p_123638_), p_123633_ -> p_123633_.state).fieldOf("block_state"); + } + + public static StreamCodec streamCodec(ParticleType p_320740_) { +- return ByteBufCodecs.idMapper(Block.BLOCK_STATE_REGISTRY).map(p_319424_ -> new BlockParticleOption(p_320740_, p_319424_), p_319425_ -> p_319425_.state); ++ return StreamCodec.composite( ++ ByteBufCodecs.idMapper(Block.BLOCK_STATE_REGISTRY), ++ option -> option.state, ++ net.neoforged.neoforge.network.codec.NeoForgeStreamCodecs.connectionAware( ++ ByteBufCodecs.optional(net.minecraft.core.BlockPos.STREAM_CODEC), ++ net.neoforged.neoforge.network.codec.NeoForgeStreamCodecs.uncheckedUnit(java.util.Optional.empty()) ++ ), ++ option -> java.util.Optional.ofNullable(option.pos), ++ (state, pos) -> new BlockParticleOption(p_320740_, state, pos.orElse(null)) ++ ); } + + public BlockParticleOption(ParticleType p_123629_, BlockState p_123630_) { ++ this(p_123629_, p_123630_, null); ++ } + -+ //FORGE: Add a source pos property, so we can provide models with additional model data -+ private net.minecraft.core.BlockPos pos; -+ public BlockParticleOption setPos(net.minecraft.core.BlockPos pos) { ++ /** ++ * Neo: construct a {@link BlockParticleOption} for the given type and {@link BlockState} and optionally the position ++ * of the block this particle is being spawned for ++ */ ++ public BlockParticleOption(ParticleType p_123629_, BlockState p_123630_, @org.jetbrains.annotations.Nullable net.minecraft.core.BlockPos pos) { + this.type = p_123629_; + this.state = p_123630_; + this.pos = pos; -+ return this; + } + + @Override +@@ -36,5 +_,13 @@ + + public BlockState getState() { + return this.state; + } + ++ /** ++ * Neo: returns the position of the block this particle was spawned for, if available ++ */ ++ @org.jetbrains.annotations.Nullable + public net.minecraft.core.BlockPos getPos() { + return pos; -+ } + } } diff --git a/patches/net/minecraft/world/entity/Entity.java.patch b/patches/net/minecraft/world/entity/Entity.java.patch index 15f8303a24..c578716b29 100644 --- a/patches/net/minecraft/world/entity/Entity.java.patch +++ b/patches/net/minecraft/world/entity/Entity.java.patch @@ -166,7 +166,7 @@ } - this.level().addParticle(new BlockParticleOption(ParticleTypes.BLOCK, blockstate), d0, this.getY() + 0.1, d1, vec3.x * -4.0, 1.5, vec3.z * -4.0); -+ this.level().addParticle(new BlockParticleOption(ParticleTypes.BLOCK, blockstate).setPos(blockpos), d0, this.getY() + 0.1, d1, vec3.x * -4.0, 1.5, vec3.z * -4.0); ++ this.level().addParticle(new BlockParticleOption(ParticleTypes.BLOCK, blockstate, blockpos), d0, this.getY() + 0.1, d1, vec3.x * -4.0, 1.5, vec3.z * -4.0); } } diff --git a/patches/net/minecraft/world/entity/LivingEntity.java.patch b/patches/net/minecraft/world/entity/LivingEntity.java.patch index d20fca6ed0..d9bcc4aaa2 100644 --- a/patches/net/minecraft/world/entity/LivingEntity.java.patch +++ b/patches/net/minecraft/world/entity/LivingEntity.java.patch @@ -61,8 +61,8 @@ double d4 = Math.min((double)(0.2F + f / 15.0F), 2.5); int i = (int)(150.0 * d4); - serverlevel.sendParticles(new BlockParticleOption(ParticleTypes.BLOCK, p_20992_), d0, d1, d2, i, 0.0, 0.0, 0.0, 0.15F); -+ if (!p_20992_.addLandingEffects((ServerLevel) this.level(), p_20993_, p_20992_, this, i)) -+ ((ServerLevel)this.level()).sendParticles(new BlockParticleOption(ParticleTypes.BLOCK, p_20992_).setPos(p_20993_), d0, d1, d2, i, 0.0, 0.0, 0.0, 0.15F); ++ if (!p_20992_.addLandingEffects(serverlevel, p_20993_, p_20992_, this, i)) ++ serverlevel.sendParticles(new BlockParticleOption(ParticleTypes.BLOCK, p_20992_, p_20993_), d0, d1, d2, i, 0.0, 0.0, 0.0, 0.15F); } }