Updated block update detection to use FML events
This commit is contained in:
parent
2b74ed96fa
commit
d81767747e
5 changed files with 25 additions and 9 deletions
|
@ -1,6 +1,7 @@
|
|||
package cr0s.warpdrive.api;
|
||||
|
||||
import cr0s.warpdrive.data.VectorI;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
|
||||
import java.util.UUID;
|
||||
|
@ -26,5 +27,5 @@ public interface IStarMapRegistryTileEntity {
|
|||
String getStarMapName();
|
||||
|
||||
// report an update in the area
|
||||
void onBlockUpdatedInArea(final VectorI vector);
|
||||
void onBlockUpdatedInArea(final VectorI vector, final Block block, final int metadata);
|
||||
}
|
||||
|
|
|
@ -44,10 +44,4 @@ public class BlockAbstractAccelerator extends Block {
|
|||
public boolean canCreatureSpawn(EnumCreatureType type, IBlockAccess world, int x, int y, int z) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void breakBlock(World world, int x, int y, int z, Block block, int metadata) {
|
||||
WarpDrive.starMap.onBlockUpdated(world, x, y, z);
|
||||
super.breakBlock(world, x, y, z, block, metadata);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -88,13 +88,13 @@ public class StarMapRegistry {
|
|||
// not found => ignore it
|
||||
}
|
||||
|
||||
public void onBlockUpdated(World world, final int x, final int y, final int z) {
|
||||
public void onBlockUpdated(World world, final int x, final int y, final int z, final Block block, final int metadata) {
|
||||
CopyOnWriteArraySet<StarMapRegistryItem> setStarMapRegistryItems = registry.get(world.provider.dimensionId);
|
||||
for (StarMapRegistryItem registryItem : setStarMapRegistryItems) {
|
||||
if (registryItem.contains(x, y, z)) {
|
||||
TileEntity tileEntity = world.getTileEntity(registryItem.x, registryItem.y, registryItem.z);
|
||||
if (tileEntity instanceof IStarMapRegistryTileEntity) {
|
||||
((IStarMapRegistryTileEntity) tileEntity).onBlockUpdatedInArea(new VectorI(x, y, z));
|
||||
((IStarMapRegistryTileEntity) tileEntity).onBlockUpdatedInArea(new VectorI(x, y, z), block, metadata);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -142,4 +142,13 @@ public class StarMapRegistryItem extends GlobalPosition {
|
|||
public int hashCode() {
|
||||
return dimensionId << 24 + (x >> 10) << 12 + y << 10 + (z >> 10);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("%s @ DIM%d (%d %d %d) (%d %d %d) -> (%d %d %d)",
|
||||
getClass().getSimpleName(), dimensionId,
|
||||
x, y, z,
|
||||
minX, minY, minZ,
|
||||
maxX, maxY, maxZ);
|
||||
}
|
||||
}
|
|
@ -8,9 +8,11 @@ import cpw.mods.fml.common.network.FMLNetworkEvent.ClientConnectedToServerEvent;
|
|||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import cr0s.warpdrive.WarpDrive;
|
||||
import cr0s.warpdrive.config.WarpDriveConfig;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.world.ChunkCoordIntPair;
|
||||
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
|
||||
import net.minecraftforge.event.world.BlockEvent;
|
||||
import net.minecraftforge.event.world.ChunkWatchEvent;
|
||||
import net.minecraftforge.event.world.WorldEvent;
|
||||
|
||||
|
@ -78,4 +80,14 @@ public class WorldHandler {
|
|||
|
||||
AbstractSequencer.updateTick();
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onBlockUpdated(BlockEvent blockEvent) {
|
||||
if (WarpDriveConfig.LOGGING_BREAK_PLACE && WarpDrive.isDev) {
|
||||
WarpDrive.logger.info("onBlockUpdate args " + blockEvent.block + "@" + blockEvent.blockMetadata
|
||||
+ " actual " + blockEvent.world.getBlock(blockEvent.x, blockEvent.y, blockEvent.z)
|
||||
+ "@" + blockEvent.world.getBlockMetadata(blockEvent.x, blockEvent.y, blockEvent.z));
|
||||
}
|
||||
WarpDrive.starMap.onBlockUpdated(blockEvent.world, blockEvent.x, blockEvent.y, blockEvent.z, blockEvent.block, blockEvent.blockMetadata);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue