Skip to content

Commit

Permalink
[1.21.4] Fix BlockParticleOption#pos not getting sent to the client (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
XFactHD authored Dec 16, 2024
1 parent 52733f5 commit 709add9
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -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<BlockParticleOption> 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<BlockParticleOption> codec(ParticleType<BlockParticleOption> 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<? super RegistryFriendlyByteBuf, BlockParticleOption> streamCodec(ParticleType<BlockParticleOption> 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<BlockParticleOption> 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<BlockParticleOption> 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;
+ }
}
}
2 changes: 1 addition & 1 deletion patches/net/minecraft/world/entity/Entity.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
4 changes: 2 additions & 2 deletions patches/net/minecraft/world/entity/LivingEntity.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,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);
}
}

Expand Down

0 comments on commit 709add9

Please sign in to comment.