Refactored BlockPlaceEvent and BlockChangeDelegate. Adds BUKKIT-5558
23 classes have been removed as they are no longer needed using the new capture logic. This should help quite a bit with future MC updates. BlockPlaceEvent Refactor Before calling Item.interactWith, a recording flag is turned on for setTypeAndData to capture a blockstate for each block that attempts to be set. When a block place event is cancelled, the recorded blockstate, stack size, and metadata will revert back to the captured state. If the event is not cancelled, a notification will be sent to clients and block physics will be updated. BlockChangeDelegate Refactor Now that we have the ability to capture blockstates through world, there is no need to modify world gen classes with BlockChangeDelegate. Instead we will simply capture blocks during world generation in order to "replay" all of the captured blockstates to send back to delegates. StructureGrowDelegate and BlockSapling.TreeGenerator have also been removed as part of this change. BlockSapling and BlockMushroom will capture blockstates the same as block placement and revert back any grow events if needed. By: bloodshot <jdroque@gmail.com>
This commit is contained in:
@@ -22,6 +22,7 @@ public class CraftBlockState implements BlockState {
|
||||
private final int z;
|
||||
protected int type;
|
||||
protected MaterialData data;
|
||||
protected int flag;
|
||||
protected final byte light;
|
||||
|
||||
public CraftBlockState(final Block block) {
|
||||
@@ -32,14 +33,24 @@ public class CraftBlockState implements BlockState {
|
||||
this.type = block.getTypeId();
|
||||
this.light = block.getLightLevel();
|
||||
this.chunk = (CraftChunk) block.getChunk();
|
||||
this.flag = 3;
|
||||
|
||||
createData(block.getData());
|
||||
}
|
||||
|
||||
public CraftBlockState(final Block block, int flag) {
|
||||
this(block);
|
||||
this.flag = flag;
|
||||
}
|
||||
|
||||
public static CraftBlockState getBlockState(net.minecraft.server.World world, int x, int y, int z) {
|
||||
return new CraftBlockState(world.getWorld().getBlockAt(x, y, z));
|
||||
}
|
||||
|
||||
public static CraftBlockState getBlockState(net.minecraft.server.World world, int x, int y, int z, int flag) {
|
||||
return new CraftBlockState(world.getWorld().getBlockAt(x, y, z), flag);
|
||||
}
|
||||
|
||||
public World getWorld() {
|
||||
return world;
|
||||
}
|
||||
@@ -96,6 +107,14 @@ public class CraftBlockState implements BlockState {
|
||||
return Material.getMaterial(getTypeId());
|
||||
}
|
||||
|
||||
public void setFlag(int flag) {
|
||||
this.flag = flag;
|
||||
}
|
||||
|
||||
public int getFlag() {
|
||||
return flag;
|
||||
}
|
||||
|
||||
public int getTypeId() {
|
||||
return type;
|
||||
}
|
||||
@@ -224,4 +243,4 @@ public class CraftBlockState implements BlockState {
|
||||
public void removeMetadata(String metadataKey, Plugin owningPlugin) {
|
||||
chunk.getCraftWorld().getBlockMetadata().removeMetadata(getBlock(), metadataKey, owningPlugin);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user