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)");
}
}
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);
}
}
}
}
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();
}
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;
}
}
}
}
}
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;
}
}
}
}
}
Aggregations