Remove custom block when breaking it

Use Math.floor() to correct coordinates
This commit is contained in:
jglrxavpok 2020-05-01 23:05:47 +02:00
parent f38d3718c3
commit d96bf48eb2
3 changed files with 8 additions and 6 deletions

View File

@ -582,11 +582,11 @@ public abstract class Entity implements Viewable, DataContainer {
public boolean sameChunk(Position position) {
Position pos = getPosition();
int chunkX1 = ChunkUtils.getChunkCoordinate((int) pos.getX());
int chunkZ1 = ChunkUtils.getChunkCoordinate((int) pos.getZ());
int chunkX1 = ChunkUtils.getChunkCoordinate((int) Math.floor(pos.getX()));
int chunkZ1 = ChunkUtils.getChunkCoordinate((int) Math.floor(pos.getZ()));
int chunkX2 = ChunkUtils.getChunkCoordinate((int) position.getX());
int chunkZ2 = ChunkUtils.getChunkCoordinate((int) position.getZ());
int chunkX2 = ChunkUtils.getChunkCoordinate((int) Math.floor(position.getX()));
int chunkZ2 = ChunkUtils.getChunkCoordinate((int) Math.floor(position.getZ()));
return chunkX1 == chunkX2 && chunkZ1 == chunkZ2;
}

View File

@ -7,6 +7,7 @@ import net.minestom.server.entity.Player;
import net.minestom.server.event.PlayerBlockBreakEvent;
import net.minestom.server.instance.batch.BlockBatch;
import net.minestom.server.instance.batch.ChunkBatch;
import net.minestom.server.instance.block.Block;
import net.minestom.server.instance.block.CustomBlock;
import net.minestom.server.instance.block.rule.BlockPlacementRule;
import net.minestom.server.network.PacketWriterUtils;
@ -118,6 +119,7 @@ public class InstanceContainer extends Instance {
if (previousBlock != null) {
Data previousData = chunk.getData(index);
previousBlock.onDestroy(this, blockPosition, previousData);
chunk.UNSAFE_setCustomBlock(blockPosition.getX(), blockPosition.getY(), blockPosition.getZ(), Block.AIR.getBlockId(), (short) 0, null);
}
}

View File

@ -14,9 +14,9 @@ public class BlockPosition {
public BlockPosition(float x, float y, float z) {
final int castedY = (int) y;
this.x = (int) (x < 0 ? x - 1 : x);
this.x = (int) Math.floor(x);
this.y = (y == castedY) ? castedY : castedY + 1;
this.z = (int) (z < 0 ? z - 1 : z);
this.z = (int) Math.floor(z);
}
public BlockPosition add(int x, int y, int z) {