Search in sources :

Example 76 with Coordinate

use of mcjty.lib.varia.Coordinate 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 77 with Coordinate

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

the class MatterTransmitterBlock method addInformation.

@SideOnly(Side.CLIENT)
@Override
public void addInformation(ItemStack itemStack, EntityPlayer player, List list, boolean whatIsThis) {
    super.addInformation(itemStack, player, list, whatIsThis);
    NBTTagCompound tagCompound = itemStack.getTagCompound();
    if (tagCompound != null) {
        String name = tagCompound.getString("tpName");
        list.add(EnumChatFormatting.GREEN + "Name: " + name);
        boolean dialed = false;
        Coordinate c = Coordinate.readFromNBT(tagCompound, "dest");
        if (c != null && c.getY() >= 0) {
            dialed = true;
        } else if (tagCompound.hasKey("destId")) {
            if (tagCompound.getInteger("destId") != -1) {
                dialed = true;
            }
        }
        if (dialed) {
            int destId = tagCompound.getInteger("destId");
            if (System.currentTimeMillis() - lastTime > 500) {
                lastTime = System.currentTimeMillis();
                RFToolsMessages.INSTANCE.sendToServer(new PacketGetDestinationInfo(destId));
            }
            String destname = "?";
            if (ReturnDestinationInfoHelper.id != null && ReturnDestinationInfoHelper.id == destId) {
                destname = ReturnDestinationInfoHelper.name;
            }
            list.add(EnumChatFormatting.YELLOW + "[DIALED to " + destname + "]");
        }
        boolean once = tagCompound.getBoolean("once");
        if (once) {
            list.add(EnumChatFormatting.YELLOW + "[ONCE]");
        }
    }
    if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT)) {
        list.add(EnumChatFormatting.WHITE + "If you place this block near a Dialing Device then");
        list.add(EnumChatFormatting.WHITE + "you can dial it to a Matter Receiver. Make sure to give");
        list.add(EnumChatFormatting.WHITE + "it sufficient power!");
        list.add(EnumChatFormatting.WHITE + "Use a Destination Analyzer adjacent to this block");
        list.add(EnumChatFormatting.WHITE + "to check destination status (red is bad, green ok,");
        list.add(EnumChatFormatting.WHITE + "yellow is unknown).");
        list.add(EnumChatFormatting.WHITE + "Use a  Matter Booster adjacent to this block");
        list.add(EnumChatFormatting.WHITE + "to be able to teleport to unpowered receivers.");
        list.add(EnumChatFormatting.YELLOW + "Infusing bonus: reduced power consumption and");
        list.add(EnumChatFormatting.YELLOW + "increased teleportation speed.");
    } else {
        list.add(EnumChatFormatting.WHITE + RFTools.SHIFT_MESSAGE);
    }
}
Also used : PacketGetDestinationInfo(mcjty.rftools.dimension.network.PacketGetDestinationInfo) Coordinate(mcjty.lib.varia.Coordinate) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) SideOnly(cpw.mods.fml.relauncher.SideOnly)

Example 78 with Coordinate

use of mcjty.lib.varia.Coordinate 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 79 with Coordinate

use of mcjty.lib.varia.Coordinate 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 80 with Coordinate

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

the class MachineInformationClientScreenModule method setupCoordinateFromNBT.

protected void setupCoordinateFromNBT(NBTTagCompound tagCompound, int dim, int x, int y, int z) {
    coordinate = Coordinate.INVALID;
    if (tagCompound.hasKey("monitorx")) {
        this.dim = tagCompound.getInteger("dim");
        if (dim == this.dim) {
            Coordinate c = new Coordinate(tagCompound.getInteger("monitorx"), tagCompound.getInteger("monitory"), tagCompound.getInteger("monitorz"));
            int dx = Math.abs(c.getX() - x);
            int dy = Math.abs(c.getY() - y);
            int dz = Math.abs(c.getZ() - z);
            if (dx <= 64 && dy <= 64 && dz <= 64) {
                coordinate = c;
            }
        }
    }
}
Also used : Coordinate(mcjty.lib.varia.Coordinate)

Aggregations

Coordinate (mcjty.lib.varia.Coordinate)181 GlobalCoordinate (mcjty.lib.varia.GlobalCoordinate)63 TileEntity (net.minecraft.tileentity.TileEntity)30 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)19 Block (net.minecraft.block.Block)14 HashMap (java.util.HashMap)13 Map (java.util.Map)13 GenericEnergyReceiverTileEntity (mcjty.lib.entity.GenericEnergyReceiverTileEntity)13 World (net.minecraft.world.World)12 NBTTagList (net.minecraft.nbt.NBTTagList)11 Callback (li.cil.oc.api.machine.Callback)10 HorizontalLayout (mcjty.lib.gui.layout.HorizontalLayout)10 Panel (mcjty.lib.gui.widgets.Panel)10 ItemStack (net.minecraft.item.ItemStack)10 ArrayList (java.util.ArrayList)9 Label (mcjty.lib.gui.widgets.Label)8 BlockInfo (mcjty.rftools.BlockInfo)7 SyncedCoordinate (mcjty.lib.entity.SyncedCoordinate)5 ChoiceEvent (mcjty.lib.gui.events.ChoiceEvent)4 TeleportDestinationClientInfo (mcjty.rftools.blocks.teleporter.TeleportDestinationClientInfo)4