Search in sources :

Example 36 with GlobalCoordinate

use of mcjty.lib.varia.GlobalCoordinate in project RFTools by McJty.

the class TeleportDestinations method cleanupInvalid.

public void cleanupInvalid(World world) {
    Set<GlobalCoordinate> keys = new HashSet<GlobalCoordinate>(destinations.keySet());
    for (GlobalCoordinate key : keys) {
        World transWorld = RfToolsDimensionManager.getDimensionManager(world).getWorldForDimension(key.getDimension());
        boolean removed = false;
        if (transWorld == null) {
            Logging.log("Receiver on dimension " + key.getDimension() + " removed because world can't be loaded!");
            removed = true;
        } else {
            Coordinate c = key.getCoordinate();
            TileEntity te;
            try {
                te = transWorld.getTileEntity(c.getX(), c.getY(), c.getZ());
            } catch (Exception e) {
                te = null;
            }
            if (!(te instanceof MatterReceiverTileEntity)) {
                Logging.log("Receiver at " + c + " on dimension " + key.getDimension() + " removed because there is no receiver there!");
                removed = true;
            }
        }
        if (removed) {
            destinations.remove(key);
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) GlobalCoordinate(mcjty.lib.varia.GlobalCoordinate) Coordinate(mcjty.lib.varia.Coordinate) GlobalCoordinate(mcjty.lib.varia.GlobalCoordinate) World(net.minecraft.world.World)

Example 37 with GlobalCoordinate

use of mcjty.lib.varia.GlobalCoordinate in project RFTools by McJty.

the class ForgeEventHandlers method getProtectors.

private Collection<GlobalCoordinate> getProtectors(World world, int x, int y, int z) {
    Collection<GlobalCoordinate> protectors;
    BlockProtectors blockProtectors = BlockProtectors.getProtectors(world);
    if (blockProtectors == null) {
        protectors = Collections.emptyList();
    } else {
        int id = world.provider.dimensionId;
        protectors = blockProtectors.findProtectors(x, y, z, id, 2);
    }
    return protectors;
}
Also used : GlobalCoordinate(mcjty.lib.varia.GlobalCoordinate) BlockProtectors(mcjty.rftools.blocks.blockprotector.BlockProtectors)

Example 38 with GlobalCoordinate

use of mcjty.lib.varia.GlobalCoordinate 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 39 with GlobalCoordinate

use of mcjty.lib.varia.GlobalCoordinate 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)

Example 40 with GlobalCoordinate

use of mcjty.lib.varia.GlobalCoordinate in project RFTools by McJty.

the class ForgeEventHandlers method onPlayerInteractEvent.

@SubscribeEvent
public void onPlayerInteractEvent(PlayerInteractEvent event) {
    ItemStack heldItem = event.entityPlayer.getHeldItem();
    if (heldItem == null || heldItem.getItem() == null) {
        return;
    }
    if (event.entityPlayer.isSneaking() && WrenchChecker.isAWrench(heldItem.getItem())) {
        // If the block is protected we prevent sneak-wrenching it.
        World world = event.world;
        int x = event.x;
        int y = event.y;
        int z = event.z;
        Collection<GlobalCoordinate> protectors = getProtectors(world, x, y, z);
        checkHarvestProtection(event, x, y, z, world, protectors);
    }
}
Also used : GlobalCoordinate(mcjty.lib.varia.GlobalCoordinate) ItemStack(net.minecraft.item.ItemStack) World(net.minecraft.world.World) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Aggregations

GlobalCoordinate (mcjty.lib.varia.GlobalCoordinate)78 Coordinate (mcjty.lib.varia.Coordinate)33 TileEntity (net.minecraft.tileentity.TileEntity)15 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)14 World (net.minecraft.world.World)13 NBTTagList (net.minecraft.nbt.NBTTagList)7 ItemStack (net.minecraft.item.ItemStack)6 BlockPos (net.minecraft.util.math.BlockPos)6 ArrayList (java.util.ArrayList)5 TeleportDestination (mcjty.rftools.blocks.teleporter.TeleportDestination)5 SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)4 TeleportDestinations (mcjty.rftools.blocks.teleporter.TeleportDestinations)4 MovingSound (net.minecraft.client.audio.MovingSound)4 BlockProtectorTileEntity (mcjty.rftools.blocks.blockprotector.BlockProtectorTileEntity)3 PlayerExtendedProperties (mcjty.rftools.playerprops.PlayerExtendedProperties)3 IBlockState (net.minecraft.block.state.IBlockState)3 EntityPlayer (net.minecraft.entity.player.EntityPlayer)3 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)3 WorldServer (net.minecraft.world.WorldServer)3 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)3