Custom block breaking and data creation now both have an instance and a position accessible

This commit is contained in:
jglrxavpok 2020-04-29 00:12:53 +02:00
parent d49cfc2215
commit 263713ab49
5 changed files with 6 additions and 6 deletions

View File

@ -30,7 +30,7 @@ public class StoneBlock extends CustomBlock {
} }
@Override @Override
public int getBreakDelay(Player player) { public int getBreakDelay(Player player, BlockPosition position) {
return 750; return 750;
} }

View File

@ -43,7 +43,7 @@ public class UpdatableBlockDemo extends CustomBlock {
} }
@Override @Override
public int getBreakDelay(Player player) { public int getBreakDelay(Player player, BlockPosition position) {
return 500; return 500;
} }

View File

@ -75,7 +75,7 @@ public class InstanceContainer extends Instance {
// Set the block // Set the block
if (isCustomBlock) { if (isCustomBlock) {
data = customBlock.createData(blockPosition, data); data = customBlock.createData(this, blockPosition, data);
chunk.UNSAFE_setCustomBlock(x, y, z, customBlock, data); chunk.UNSAFE_setCustomBlock(x, y, z, customBlock, data);
} else { } else {
chunk.UNSAFE_setBlock(x, y, z, blockId, data); chunk.UNSAFE_setBlock(x, y, z, blockId, data);

View File

@ -63,7 +63,7 @@ public abstract class CustomBlock {
* @param player the player who is trying to break the block * @param player the player who is trying to break the block
* @return the time in ms to break it * @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() { public boolean hasUpdate() {
UpdateOption updateOption = getUpdateOption(); UpdateOption updateOption = getUpdateOption();
@ -88,7 +88,7 @@ public abstract class CustomBlock {
* @param data data given to 'setBlock', can be null * @param data data given to 'setBlock', can be null
* @return Data for this block. Can be null, 'data', or a new object * @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; return data;
} }
} }

View File

@ -37,7 +37,7 @@ public class PlayerDiggingListener {
if (instance != null) { if (instance != null) {
CustomBlock customBlock = instance.getCustomBlock(blockPosition.getX(), blockPosition.getY(), blockPosition.getZ()); CustomBlock customBlock = instance.getCustomBlock(blockPosition.getX(), blockPosition.getY(), blockPosition.getZ());
if (customBlock != null) { if (customBlock != null) {
int breakTime = customBlock.getBreakDelay(player); int breakTime = customBlock.getBreakDelay(player, blockPosition);
if (breakTime >= 0) { if (breakTime >= 0) {
PlayerStartDiggingEvent playerStartDiggingEvent = new PlayerStartDiggingEvent(blockPosition, customBlock); PlayerStartDiggingEvent playerStartDiggingEvent = new PlayerStartDiggingEvent(blockPosition, customBlock);
player.callEvent(PlayerStartDiggingEvent.class, playerStartDiggingEvent); player.callEvent(PlayerStartDiggingEvent.class, playerStartDiggingEvent);