use of mcjty.rftools.blocks.blockprotector.BlockProtectorTileEntity in project RFTools by McJty.
the class RenderWorldLastEventHandler method renderProtectedBlocks.
private static void renderProtectedBlocks(RenderWorldLastEvent evt) {
Minecraft mc = Minecraft.getMinecraft();
EntityClientPlayerMP p = mc.thePlayer;
ItemStack heldItem = p.getHeldItem();
if (heldItem == null) {
return;
}
if (heldItem.getItem() == ModItems.smartWrenchItem) {
if (SmartWrenchItem.getCurrentMode(heldItem) == SmartWrenchMode.MODE_SELECT) {
GlobalCoordinate current = SmartWrenchItem.getCurrentBlock(heldItem);
if (current != null) {
if (current.getDimension() == mc.theWorld.provider.dimensionId) {
TileEntity te = mc.theWorld.getTileEntity(current.getCoordinate().getX(), current.getCoordinate().getY(), current.getCoordinate().getZ());
if (te instanceof BlockProtectorTileEntity) {
BlockProtectorTileEntity blockProtectorTileEntity = (BlockProtectorTileEntity) te;
Set<Coordinate> coordinates = blockProtectorTileEntity.getProtectedBlocks();
if (!coordinates.isEmpty()) {
renderHighlightedBlocks(evt, p, new Coordinate(te.xCoord, te.yCoord, te.zCoord), coordinates);
}
}
}
}
}
} else if (heldItem.getItem() == ModItems.shapeCardItem) {
int mode = ShapeCardItem.getMode(heldItem);
if (mode == ShapeCardItem.MODE_CORNER1 || mode == ShapeCardItem.MODE_CORNER2) {
GlobalCoordinate current = ShapeCardItem.getCurrentBlock(heldItem);
if (current != null && current.getDimension() == mc.theWorld.provider.dimensionId) {
Set<Coordinate> coordinates = new HashSet<Coordinate>();
coordinates.add(new Coordinate(0, 0, 0));
if (mode == ShapeCardItem.MODE_CORNER2) {
Coordinate cur = current.getCoordinate();
Coordinate c = ShapeCardItem.getCorner1(heldItem);
if (c != null) {
coordinates.add(new Coordinate(c.getX() - cur.getX(), c.getY() - cur.getY(), c.getZ() - cur.getZ()));
}
}
renderHighlightedBlocks(evt, p, current.getCoordinate(), coordinates);
}
}
}
}
use of mcjty.rftools.blocks.blockprotector.BlockProtectorTileEntity in project RFTools by McJty.
the class ForgeEventHandlers method onDetonate.
@SubscribeEvent
public void onDetonate(ExplosionEvent.Detonate event) {
Explosion explosion = event.explosion;
Collection<GlobalCoordinate> protectors = getProtectors(event.world, (int) explosion.explosionX, (int) explosion.explosionY, (int) explosion.explosionZ);
if (protectors.isEmpty()) {
return;
}
List<ChunkPosition> affectedBlocks = event.getAffectedBlocks();
List<ChunkPosition> toremove = new ArrayList<ChunkPosition>();
Vec3 explosionVector = Vec3.createVectorHelper(explosion.explosionX, explosion.explosionY, explosion.explosionZ);
int rf = 0;
for (GlobalCoordinate protector : protectors) {
int cx = protector.getCoordinate().getX();
int cy = protector.getCoordinate().getY();
int cz = protector.getCoordinate().getZ();
TileEntity te = event.world.getTileEntity(cx, cy, cz);
if (te instanceof BlockProtectorTileEntity) {
BlockProtectorTileEntity blockProtectorTileEntity = (BlockProtectorTileEntity) te;
for (ChunkPosition block : affectedBlocks) {
Coordinate relative = blockProtectorTileEntity.absoluteToRelative(block.chunkPosX, block.chunkPosY, block.chunkPosZ);
boolean b = blockProtectorTileEntity.isProtected(relative);
if (b) {
Vec3 blockVector = Vec3.createVectorHelper(block.chunkPosX, block.chunkPosY, block.chunkPosZ);
double distanceTo = explosionVector.distanceTo(blockVector);
int rfneeded = blockProtectorTileEntity.attemptExplosionProtection((float) (distanceTo / explosion.explosionSize), explosion.explosionSize);
if (rfneeded > 0) {
toremove.add(block);
rf += rfneeded;
} else {
blockProtectorTileEntity.removeProtection(relative);
}
}
}
}
}
for (ChunkPosition block : toremove) {
affectedBlocks.remove(block);
}
Logging.logDebug("RF Needed for one explosion:" + rf);
}
use of mcjty.rftools.blocks.blockprotector.BlockProtectorTileEntity in project RFTools by McJty.
the class ForgeEventHandlers method checkHarvestProtection.
private void checkHarvestProtection(Event event, int x, int y, int z, World world, Collection<GlobalCoordinate> protectors) {
for (GlobalCoordinate protector : protectors) {
int cx = protector.getCoordinate().getX();
int cy = protector.getCoordinate().getY();
int cz = protector.getCoordinate().getZ();
TileEntity te = world.getTileEntity(cx, cy, cz);
if (te instanceof BlockProtectorTileEntity) {
BlockProtectorTileEntity blockProtectorTileEntity = (BlockProtectorTileEntity) te;
Coordinate relative = blockProtectorTileEntity.absoluteToRelative(x, y, z);
boolean b = blockProtectorTileEntity.isProtected(relative);
if (b) {
if (blockProtectorTileEntity.attemptHarvestProtection()) {
event.setCanceled(true);
} else {
blockProtectorTileEntity.removeProtection(relative);
}
return;
}
}
}
}
Aggregations