Search in sources :

Example 1 with BlockProtectorTileEntity

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);
            }
        }
    }
}
Also used : BlockProtectorTileEntity(mcjty.rftools.blocks.blockprotector.BlockProtectorTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) BlockProtectorTileEntity(mcjty.rftools.blocks.blockprotector.BlockProtectorTileEntity) EntityClientPlayerMP(net.minecraft.client.entity.EntityClientPlayerMP) Set(java.util.Set) HashSet(java.util.HashSet) GlobalCoordinate(mcjty.lib.varia.GlobalCoordinate) Coordinate(mcjty.lib.varia.Coordinate) GlobalCoordinate(mcjty.lib.varia.GlobalCoordinate) ItemStack(net.minecraft.item.ItemStack) Minecraft(net.minecraft.client.Minecraft)

Example 2 with BlockProtectorTileEntity

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);
}
Also used : Explosion(net.minecraft.world.Explosion) ChunkPosition(net.minecraft.world.ChunkPosition) ArrayList(java.util.ArrayList) GlobalCoordinate(mcjty.lib.varia.GlobalCoordinate) BlockProtectorTileEntity(mcjty.rftools.blocks.blockprotector.BlockProtectorTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) BlockProtectorTileEntity(mcjty.rftools.blocks.blockprotector.BlockProtectorTileEntity) GlobalCoordinate(mcjty.lib.varia.GlobalCoordinate) Coordinate(mcjty.lib.varia.Coordinate) Vec3(net.minecraft.util.Vec3) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Example 3 with BlockProtectorTileEntity

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;
            }
        }
    }
}
Also used : BlockProtectorTileEntity(mcjty.rftools.blocks.blockprotector.BlockProtectorTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) BlockProtectorTileEntity(mcjty.rftools.blocks.blockprotector.BlockProtectorTileEntity) GlobalCoordinate(mcjty.lib.varia.GlobalCoordinate) Coordinate(mcjty.lib.varia.Coordinate) GlobalCoordinate(mcjty.lib.varia.GlobalCoordinate)

Aggregations

Coordinate (mcjty.lib.varia.Coordinate)3 GlobalCoordinate (mcjty.lib.varia.GlobalCoordinate)3 BlockProtectorTileEntity (mcjty.rftools.blocks.blockprotector.BlockProtectorTileEntity)3 TileEntity (net.minecraft.tileentity.TileEntity)3 SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 Minecraft (net.minecraft.client.Minecraft)1 EntityClientPlayerMP (net.minecraft.client.entity.EntityClientPlayerMP)1 ItemStack (net.minecraft.item.ItemStack)1 Vec3 (net.minecraft.util.Vec3)1 ChunkPosition (net.minecraft.world.ChunkPosition)1 Explosion (net.minecraft.world.Explosion)1