mirror of
https://github.com/Minestom/Minestom.git
synced 2025-02-14 11:21:23 +01:00
fix: preserve handler in block placement rule neighbor updates
This commit is contained in:
parent
5cb192157c
commit
2c73b4b8f0
@ -641,8 +641,8 @@ public class InstanceContainer extends Instance {
|
|||||||
final int neighborZ = blockPosition.blockZ() + direction.normalZ();
|
final int neighborZ = blockPosition.blockZ() + direction.normalZ();
|
||||||
if (neighborY < getCachedDimensionType().minY() || neighborY > getCachedDimensionType().height())
|
if (neighborY < getCachedDimensionType().minY() || neighborY > getCachedDimensionType().height())
|
||||||
continue;
|
continue;
|
||||||
final Block neighborBlock = cache.getBlock(neighborX, neighborY, neighborZ, Condition.TYPE);
|
final Block neighborBlock = cache.getBlock(neighborX, neighborY, neighborZ, Condition.NONE);
|
||||||
if (neighborBlock == null)
|
if (neighborBlock == null || neighborBlock.isAir())
|
||||||
continue;
|
continue;
|
||||||
final BlockPlacementRule neighborBlockPlacementRule = MinecraftServer.getBlockManager().getBlockPlacementRule(neighborBlock);
|
final BlockPlacementRule neighborBlockPlacementRule = MinecraftServer.getBlockManager().getBlockPlacementRule(neighborBlock);
|
||||||
if (neighborBlockPlacementRule == null || updateDistance >= neighborBlockPlacementRule.maxUpdateDistance()) continue;
|
if (neighborBlockPlacementRule == null || updateDistance >= neighborBlockPlacementRule.maxUpdateDistance()) continue;
|
||||||
|
@ -1,12 +1,18 @@
|
|||||||
package net.minestom.server.instance;
|
package net.minestom.server.instance;
|
||||||
|
|
||||||
import net.minestom.testing.Env;
|
|
||||||
import net.minestom.testing.EnvTest;
|
|
||||||
import net.minestom.server.coordinate.Vec;
|
import net.minestom.server.coordinate.Vec;
|
||||||
import net.minestom.server.instance.block.Block;
|
import net.minestom.server.instance.block.Block;
|
||||||
|
import net.minestom.server.instance.block.SuspiciousGravelBlockHandler;
|
||||||
|
import net.minestom.server.instance.block.rule.BlockPlacementRule;
|
||||||
import net.minestom.server.tag.Tag;
|
import net.minestom.server.tag.Tag;
|
||||||
|
import net.minestom.testing.Env;
|
||||||
|
import net.minestom.testing.EnvTest;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
@ -73,4 +79,30 @@ public class InstanceBlockIntegrationTest {
|
|||||||
instance.setBlock(point, Block.GRASS_BLOCK.withTag(tag, 8));
|
instance.setBlock(point, Block.GRASS_BLOCK.withTag(tag, 8));
|
||||||
assertEquals(8, instance.getBlock(point).getTag(tag));
|
assertEquals(8, instance.getBlock(point).getTag(tag));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void handlerPresentInPlacementRuleUpdate(Env env) {
|
||||||
|
|
||||||
|
AtomicReference<Block> currentBlock = new AtomicReference<>();
|
||||||
|
env.process().block().registerHandler(SuspiciousGravelBlockHandler.INSTANCE.getNamespaceId(), () -> SuspiciousGravelBlockHandler.INSTANCE);
|
||||||
|
env.process().block().registerBlockPlacementRule(new BlockPlacementRule(Block.SUSPICIOUS_GRAVEL) {
|
||||||
|
@Override
|
||||||
|
public @Nullable Block blockPlace(@NotNull PlacementState placementState) {
|
||||||
|
return block;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull Block blockUpdate(@NotNull UpdateState updateState) {
|
||||||
|
currentBlock.set(updateState.currentBlock());
|
||||||
|
return super.blockUpdate(updateState);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
var instance = env.createFlatInstance();
|
||||||
|
var theBlock = Block.SUSPICIOUS_GRAVEL.withHandler(SuspiciousGravelBlockHandler.INSTANCE);
|
||||||
|
instance.setBlock(0, 50, 0, theBlock);
|
||||||
|
instance.setBlock(1, 50, 0, theBlock);
|
||||||
|
|
||||||
|
assertEquals(theBlock, currentBlock.get());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user