Search in sources :

Example 46 with GlobalCoordinate

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

the class BlockProtectorEventHandlers method onDetonate.

@SubscribeEvent
public static void onDetonate(ExplosionEvent.Detonate event) {
    Explosion explosion = event.getExplosion();
    Vec3d explosionVector = explosion.getPosition();
    Collection<GlobalCoordinate> protectors = BlockProtectors.getProtectors(event.getWorld(), (int) explosionVector.x, (int) explosionVector.y, (int) explosionVector.z);
    if (protectors.isEmpty()) {
        return;
    }
    List<BlockPos> affectedBlocks = event.getAffectedBlocks();
    List<BlockPos> toremove = new ArrayList<>();
    int rf = 0;
    for (GlobalCoordinate protector : protectors) {
        BlockPos pos = protector.getCoordinate();
        TileEntity te = event.getWorld().getTileEntity(pos);
        if (te instanceof BlockProtectorTileEntity) {
            BlockProtectorTileEntity blockProtectorTileEntity = (BlockProtectorTileEntity) te;
            for (BlockPos block : affectedBlocks) {
                BlockPos relative = blockProtectorTileEntity.absoluteToRelative(block);
                boolean b = blockProtectorTileEntity.isProtected(relative);
                if (b) {
                    Vec3d blockVector = new Vec3d(block);
                    double distanceTo = explosionVector.distanceTo(blockVector);
                    int rfneeded = blockProtectorTileEntity.attemptExplosionProtection((float) (distanceTo / explosion.size), explosion.size);
                    if (rfneeded > 0) {
                        toremove.add(block);
                        rf += rfneeded;
                    } else {
                        blockProtectorTileEntity.removeProtection(relative);
                    }
                }
            }
        }
    }
    affectedBlocks.removeAll(toremove);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) Explosion(net.minecraft.world.Explosion) ArrayList(java.util.ArrayList) BlockPos(net.minecraft.util.math.BlockPos) GlobalCoordinate(mcjty.lib.varia.GlobalCoordinate) Vec3d(net.minecraft.util.math.Vec3d) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 47 with GlobalCoordinate

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

the class BlockProtectorEventHandlers method onLivingDestroyBlock.

@SubscribeEvent
public static void onLivingDestroyBlock(LivingDestroyBlockEvent event) {
    int x = event.getPos().getX();
    int y = event.getPos().getY();
    int z = event.getPos().getZ();
    World world = event.getEntity().getEntityWorld();
    Collection<GlobalCoordinate> protectors = BlockProtectors.getProtectors(world, x, y, z);
    if (BlockProtectors.checkHarvestProtection(x, y, z, world, protectors)) {
        event.setCanceled(true);
    }
}
Also used : GlobalCoordinate(mcjty.lib.varia.GlobalCoordinate) World(net.minecraft.world.World) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 48 with GlobalCoordinate

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

the class ForgeEventHandlers method onEntityTeleport.

@SubscribeEvent
public void onEntityTeleport(EnderTeleportEvent event) {
    World world = event.getEntity().getEntityWorld();
    int id = world.provider.getDimension();
    Entity entity = event.getEntity();
    BlockPos coordinate = new BlockPos((int) entity.posX, (int) entity.posY, (int) entity.posZ);
    if (NoTeleportAreaManager.isTeleportPrevented(entity, new GlobalCoordinate(coordinate, id))) {
        event.setCanceled(true);
    } else {
        coordinate = new BlockPos((int) event.getTargetX(), (int) event.getTargetY(), (int) event.getTargetZ());
        if (NoTeleportAreaManager.isTeleportPrevented(entity, new GlobalCoordinate(coordinate, id))) {
            event.setCanceled(true);
        }
    }
}
Also used : Entity(net.minecraft.entity.Entity) EndergenicTileEntity(mcjty.rftools.blocks.endergen.EndergenicTileEntity) BlockPos(net.minecraft.util.math.BlockPos) GlobalCoordinate(mcjty.lib.varia.GlobalCoordinate) World(net.minecraft.world.World) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 49 with GlobalCoordinate

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

the class ForgeEventHandlers method onEntitySpawnEvent.

@SubscribeEvent
public void onEntitySpawnEvent(LivingSpawnEvent.CheckSpawn event) {
    World world = event.getWorld();
    int id = world.provider.getDimension();
    Entity entity = event.getEntity();
    if (entity instanceof IMob) {
        BlockPos coordinate = new BlockPos((int) entity.posX, (int) entity.posY, (int) entity.posZ);
        if (PeacefulAreaManager.isPeaceful(new GlobalCoordinate(coordinate, id))) {
            event.setResult(Event.Result.DENY);
        }
    }
}
Also used : Entity(net.minecraft.entity.Entity) EndergenicTileEntity(mcjty.rftools.blocks.endergen.EndergenicTileEntity) IMob(net.minecraft.entity.monster.IMob) BlockPos(net.minecraft.util.math.BlockPos) GlobalCoordinate(mcjty.lib.varia.GlobalCoordinate) World(net.minecraft.world.World) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 50 with GlobalCoordinate

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

the class PorterTools method returnTargets.

public static void returnTargets(EntityPlayer player) {
    ItemStack heldItem = player.getHeldItem(EnumHand.MAIN_HAND);
    if (heldItem.isEmpty()) {
        return;
    }
    NBTTagCompound tagCompound = heldItem.getTagCompound();
    int target = -1;
    int[] targets = new int[AdvancedChargedPorterItem.MAXTARGETS];
    String[] names = new String[AdvancedChargedPorterItem.MAXTARGETS];
    TeleportDestinations destinations = TeleportDestinations.getDestinations(player.getEntityWorld());
    if (tagCompound != null) {
        if (tagCompound.hasKey("target")) {
            target = tagCompound.getInteger("target");
        } else {
            target = -1;
        }
        for (int i = 0; i < AdvancedChargedPorterItem.MAXTARGETS; i++) {
            names[i] = "";
            if (tagCompound.hasKey("target" + i)) {
                targets[i] = tagCompound.getInteger("target" + i);
                GlobalCoordinate gc = destinations.getCoordinateForId(targets[i]);
                if (gc != null) {
                    TeleportDestination destination = destinations.getDestination(gc);
                    if (destination != null) {
                        names[i] = destination.getName() + " (dimension " + destination.getDimension() + ")";
                    }
                }
            } else {
                targets[i] = -1;
            }
        }
    } else {
        for (int i = 0; i < AdvancedChargedPorterItem.MAXTARGETS; i++) {
            targets[i] = -1;
            names[i] = "";
        }
    }
    PacketTargetsReady msg = new PacketTargetsReady(target, targets, names);
    RFToolsMessages.INSTANCE.sendTo(msg, (EntityPlayerMP) player);
}
Also used : TeleportDestinations(mcjty.rftools.blocks.teleporter.TeleportDestinations) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) TextComponentString(net.minecraft.util.text.TextComponentString) GlobalCoordinate(mcjty.lib.varia.GlobalCoordinate) ItemStack(net.minecraft.item.ItemStack) TeleportDestination(mcjty.rftools.blocks.teleporter.TeleportDestination)

Aggregations

GlobalCoordinate (mcjty.lib.varia.GlobalCoordinate)53 BlockPos (net.minecraft.util.math.BlockPos)17 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)9 TileEntity (net.minecraft.tileentity.TileEntity)9 World (net.minecraft.world.World)8 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)6 ItemStack (net.minecraft.item.ItemStack)5 IBlockState (net.minecraft.block.state.IBlockState)4 MovingSound (net.minecraft.client.audio.MovingSound)4 NBTTagList (net.minecraft.nbt.NBTTagList)4 ArrayList (java.util.ArrayList)3 Block (net.minecraft.block.Block)3 WorldServer (net.minecraft.world.WorldServer)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 SmartWrenchMode (mcjty.lib.api.smartwrench.SmartWrenchMode)2 IModuleData (mcjty.rftools.api.screens.data.IModuleData)2 EndergenicTileEntity (mcjty.rftools.blocks.endergen.EndergenicTileEntity)2 EnvironmentModule (mcjty.rftools.blocks.environmental.modules.EnvironmentModule)2 TeleportDestination (mcjty.rftools.blocks.teleporter.TeleportDestination)2