Search in sources :

Example 91 with Coordinate

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

the class EndergenicTileEntity method useWrench.

// Called from client side when a wrench is used.
public void useWrench(EntityPlayer player) {
    Coordinate thisCoord = new Coordinate(xCoord, yCoord, zCoord);
    Coordinate coord = RFTools.instance.clientInfo.getSelectedTE();
    TileEntity tileEntity = null;
    if (coord != null) {
        tileEntity = worldObj.getTileEntity(coord.getX(), coord.getY(), coord.getZ());
    }
    if (!(tileEntity instanceof EndergenicTileEntity)) {
        // None selected. Just select this one.
        RFTools.instance.clientInfo.setSelectedTE(thisCoord);
        EndergenicTileEntity destinationTE = getDestinationTE();
        if (destinationTE == null) {
            RFTools.instance.clientInfo.setDestinationTE(null);
            Logging.message(player, "Select another endergenic generator as destination");
        } else {
            RFTools.instance.clientInfo.setDestinationTE(new Coordinate(destinationTE.xCoord, destinationTE.yCoord, destinationTE.zCoord));
            int distance = getDistanceInTicks();
            Logging.message(player, "Select another endergenic generator as destination (current distance " + distance + ")");
        }
    } else if (coord.equals(thisCoord)) {
        // Unselect this one.
        RFTools.instance.clientInfo.setSelectedTE(null);
        RFTools.instance.clientInfo.setDestinationTE(null);
    } else {
        // Make a link.
        EndergenicTileEntity otherTE = (EndergenicTileEntity) tileEntity;
        int distance = otherTE.calculateDistance(thisCoord);
        if (distance >= 5) {
            Logging.warn(player, "Distance is too far (maximum 4)");
            return;
        }
        otherTE.setDestination(thisCoord);
        RFTools.instance.clientInfo.setSelectedTE(null);
        RFTools.instance.clientInfo.setDestinationTE(null);
        Logging.message(player, "Destination is set (distance " + otherTE.getDistanceInTicks() + " ticks)");
    }
}
Also used : GenericEnergyProviderTileEntity(mcjty.lib.entity.GenericEnergyProviderTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) Coordinate(mcjty.lib.varia.Coordinate)

Example 92 with Coordinate

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

the class EndergenicTileEntity method fireMonitors.

/**
 * Something happens, we need to notify all ender monitors.
 * @param mode is the new mode
 */
private void fireMonitors(EnderMonitorMode mode) {
    Coordinate pos = getCoordinate();
    for (ForgeDirection dir : HORIZ_DIRECTIONS) {
        Coordinate c = pos.addDirection(dir);
        TileEntity te = worldObj.getTileEntity(c.getX(), c.getY(), c.getZ());
        if (te instanceof EnderMonitorTileEntity) {
            int meta = worldObj.getBlockMetadata(c.getX(), c.getY(), c.getZ());
            ForgeDirection k = BlockTools.getOrientationHoriz(meta);
            if (k == dir.getOpposite()) {
                EnderMonitorTileEntity enderMonitorTileEntity = (EnderMonitorTileEntity) te;
                enderMonitorTileEntity.fireFromEndergenic(mode);
            }
        }
    }
}
Also used : GenericEnergyProviderTileEntity(mcjty.lib.entity.GenericEnergyProviderTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) Coordinate(mcjty.lib.varia.Coordinate) ForgeDirection(net.minecraftforge.common.util.ForgeDirection)

Example 93 with Coordinate

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

the class RfToolsDimensionManager method freezeDimension.

/**
 * Freeze a dimension: avoid ticking all tile entities and remove all
 * active entities (they are still there but will not do anything).
 * Entities that are within range of a player having a PFG will be kept
 * active (but not tile entities).
 */
public static void freezeDimension(World world) {
    // First find all players that have a valid PFG.
    List<Coordinate> pfgList = new ArrayList<Coordinate>();
    int radius = DimletConfiguration.phasedFieldGeneratorRange;
    if (radius > 0) {
        for (Object ent : world.playerEntities) {
            EntityPlayer player = (EntityPlayer) ent;
            // Check if this player has a valid PFG but don't consume energy.
            int cost = 0;
            if (DimletConfiguration.dimensionDifficulty != -1) {
                RfToolsDimensionManager dimensionManager = RfToolsDimensionManager.getDimensionManager(world);
                DimensionInformation information = dimensionManager.getDimensionInformation(world.provider.dimensionId);
                cost = information.getActualRfCost();
                if (cost == 0) {
                    DimensionDescriptor descriptor = dimensionManager.getDimensionDescriptor(world.provider.dimensionId);
                    cost = descriptor.getRfMaintainCost();
                }
            }
            if (checkValidPhasedFieldGenerator(player, false, cost)) {
                pfgList.add(new Coordinate((int) player.posX, (int) player.posY, (int) player.posZ));
            }
        }
    }
    // If there are players with a valid PFG then we check if there are entities we want to keep.
    List tokeep = new ArrayList();
    // We want to keep all players for sure.
    tokeep.addAll(world.playerEntities);
    // Add all entities that are within range of a PFG.
    for (Coordinate coordinate : pfgList) {
        getEntitiesInSphere(world, coordinate, radius, tokeep);
    }
    world.loadedEntityList.clear();
    world.loadedEntityList.addAll(tokeep);
    world.loadedTileEntityList.clear();
}
Also used : Coordinate(mcjty.lib.varia.Coordinate) DimensionDescriptor(mcjty.rftools.dimension.description.DimensionDescriptor) EntityPlayer(net.minecraft.entity.player.EntityPlayer) NBTTagList(net.minecraft.nbt.NBTTagList)

Example 94 with Coordinate

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

the class CounterScreenModule method setupFromNBT.

@Override
public void setupFromNBT(NBTTagCompound tagCompound, int dim, int x, int y, int z) {
    if (tagCompound != null) {
        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)

Example 95 with Coordinate

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

the class EnergyBarScreenModule method setupFromNBT.

@Override
public void setupFromNBT(NBTTagCompound tagCompound, int dim, int x, int y, int z) {
    if (tagCompound != null) {
        helper.setShowdiff(tagCompound.getBoolean("showdiff"));
        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