From 263713ab49680dd84555526d1be456c25c74b84a Mon Sep 17 00:00:00 2001 From: jglrxavpok Date: Wed, 29 Apr 2020 00:12:53 +0200 Subject: [PATCH] Custom block breaking and data creation now both have an instance and a position accessible --- src/main/java/fr/themode/demo/blocks/StoneBlock.java | 2 +- src/main/java/fr/themode/demo/blocks/UpdatableBlockDemo.java | 2 +- .../java/net/minestom/server/instance/InstanceContainer.java | 2 +- .../java/net/minestom/server/instance/block/CustomBlock.java | 4 ++-- .../net/minestom/server/listener/PlayerDiggingListener.java | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/fr/themode/demo/blocks/StoneBlock.java b/src/main/java/fr/themode/demo/blocks/StoneBlock.java index 7a500935c..5be8fe0d0 100644 --- a/src/main/java/fr/themode/demo/blocks/StoneBlock.java +++ b/src/main/java/fr/themode/demo/blocks/StoneBlock.java @@ -30,7 +30,7 @@ public class StoneBlock extends CustomBlock { } @Override - public int getBreakDelay(Player player) { + public int getBreakDelay(Player player, BlockPosition position) { return 750; } diff --git a/src/main/java/fr/themode/demo/blocks/UpdatableBlockDemo.java b/src/main/java/fr/themode/demo/blocks/UpdatableBlockDemo.java index 1cfe92945..362aa8292 100644 --- a/src/main/java/fr/themode/demo/blocks/UpdatableBlockDemo.java +++ b/src/main/java/fr/themode/demo/blocks/UpdatableBlockDemo.java @@ -43,7 +43,7 @@ public class UpdatableBlockDemo extends CustomBlock { } @Override - public int getBreakDelay(Player player) { + public int getBreakDelay(Player player, BlockPosition position) { return 500; } diff --git a/src/main/java/net/minestom/server/instance/InstanceContainer.java b/src/main/java/net/minestom/server/instance/InstanceContainer.java index 7fbfb1eee..bbc7e9bc0 100644 --- a/src/main/java/net/minestom/server/instance/InstanceContainer.java +++ b/src/main/java/net/minestom/server/instance/InstanceContainer.java @@ -75,7 +75,7 @@ public class InstanceContainer extends Instance { // Set the block if (isCustomBlock) { - data = customBlock.createData(blockPosition, data); + data = customBlock.createData(this, blockPosition, data); chunk.UNSAFE_setCustomBlock(x, y, z, customBlock, data); } else { chunk.UNSAFE_setBlock(x, y, z, blockId, data); diff --git a/src/main/java/net/minestom/server/instance/block/CustomBlock.java b/src/main/java/net/minestom/server/instance/block/CustomBlock.java index 18b36bb81..d10d65fbe 100644 --- a/src/main/java/net/minestom/server/instance/block/CustomBlock.java +++ b/src/main/java/net/minestom/server/instance/block/CustomBlock.java @@ -63,7 +63,7 @@ public abstract class CustomBlock { * @param player the player who is trying to break the block * @return the time in ms to break it */ - public abstract int getBreakDelay(Player player); + public abstract int getBreakDelay(Player player, BlockPosition position); public boolean hasUpdate() { UpdateOption updateOption = getUpdateOption(); @@ -88,7 +88,7 @@ public abstract class CustomBlock { * @param data data given to 'setBlock', can be null * @return Data for this block. Can be null, 'data', or a new object */ - public Data createData(BlockPosition blockPosition, Data data) { + public Data createData(Instance instance, BlockPosition blockPosition, Data data) { return data; } } diff --git a/src/main/java/net/minestom/server/listener/PlayerDiggingListener.java b/src/main/java/net/minestom/server/listener/PlayerDiggingListener.java index abf1b0830..64e22780a 100644 --- a/src/main/java/net/minestom/server/listener/PlayerDiggingListener.java +++ b/src/main/java/net/minestom/server/listener/PlayerDiggingListener.java @@ -37,7 +37,7 @@ public class PlayerDiggingListener { if (instance != null) { CustomBlock customBlock = instance.getCustomBlock(blockPosition.getX(), blockPosition.getY(), blockPosition.getZ()); if (customBlock != null) { - int breakTime = customBlock.getBreakDelay(player); + int breakTime = customBlock.getBreakDelay(player, blockPosition); if (breakTime >= 0) { PlayerStartDiggingEvent playerStartDiggingEvent = new PlayerStartDiggingEvent(blockPosition, customBlock); player.callEvent(PlayerStartDiggingEvent.class, playerStartDiggingEvent);