use of mcjty.lib.varia.GlobalCoordinate in project RFTools by McJty.
the class BlockProtectorTileEntity method toggleCoordinate.
// Toggle a coordinate to be protected or not. The coordinate given here is absolute.
public void toggleCoordinate(GlobalCoordinate c) {
if (c.getDimension() != worldObj.provider.dimensionId) {
// Wrong dimension. Don't do anything.
return;
}
Coordinate relative = absoluteToRelative(c.getCoordinate());
if (protectedBlocks.contains(relative)) {
protectedBlocks.remove(relative);
} else {
protectedBlocks.add(relative);
}
markDirty();
notifyBlockUpdate();
}
use of mcjty.lib.varia.GlobalCoordinate in project RFTools by McJty.
the class BlockProtectorTileEntity method getOrCalculateID.
public int getOrCalculateID() {
if (id == -1) {
BlockProtectors protectors = BlockProtectors.getProtectors(worldObj);
GlobalCoordinate gc = new GlobalCoordinate(new Coordinate(xCoord, yCoord, zCoord), worldObj.provider.dimensionId);
id = protectors.getNewId(gc);
protectors.save(worldObj);
setId(id);
}
return id;
}
use of mcjty.lib.varia.GlobalCoordinate in project RFTools by McJty.
the class RenderWorldLastEventHandler method renderProtectedBlocks.
private static void renderProtectedBlocks(RenderWorldLastEvent evt) {
Minecraft mc = Minecraft.getMinecraft();
EntityClientPlayerMP p = mc.thePlayer;
ItemStack heldItem = p.getHeldItem();
if (heldItem == null) {
return;
}
if (heldItem.getItem() == ModItems.smartWrenchItem) {
if (SmartWrenchItem.getCurrentMode(heldItem) == SmartWrenchMode.MODE_SELECT) {
GlobalCoordinate current = SmartWrenchItem.getCurrentBlock(heldItem);
if (current != null) {
if (current.getDimension() == mc.theWorld.provider.dimensionId) {
TileEntity te = mc.theWorld.getTileEntity(current.getCoordinate().getX(), current.getCoordinate().getY(), current.getCoordinate().getZ());
if (te instanceof BlockProtectorTileEntity) {
BlockProtectorTileEntity blockProtectorTileEntity = (BlockProtectorTileEntity) te;
Set<Coordinate> coordinates = blockProtectorTileEntity.getProtectedBlocks();
if (!coordinates.isEmpty()) {
renderHighlightedBlocks(evt, p, new Coordinate(te.xCoord, te.yCoord, te.zCoord), coordinates);
}
}
}
}
}
} else if (heldItem.getItem() == ModItems.shapeCardItem) {
int mode = ShapeCardItem.getMode(heldItem);
if (mode == ShapeCardItem.MODE_CORNER1 || mode == ShapeCardItem.MODE_CORNER2) {
GlobalCoordinate current = ShapeCardItem.getCurrentBlock(heldItem);
if (current != null && current.getDimension() == mc.theWorld.provider.dimensionId) {
Set<Coordinate> coordinates = new HashSet<Coordinate>();
coordinates.add(new Coordinate(0, 0, 0));
if (mode == ShapeCardItem.MODE_CORNER2) {
Coordinate cur = current.getCoordinate();
Coordinate c = ShapeCardItem.getCorner1(heldItem);
if (c != null) {
coordinates.add(new Coordinate(c.getX() - cur.getX(), c.getY() - cur.getY(), c.getZ() - cur.getZ()));
}
}
renderHighlightedBlocks(evt, p, current.getCoordinate(), coordinates);
}
}
}
}
use of mcjty.lib.varia.GlobalCoordinate in project RFTools by McJty.
the class ChargedPorterItem method startTeleport.
private void startTeleport(ItemStack stack, EntityPlayer player, World world) {
NBTTagCompound tagCompound = stack.getTagCompound();
if (tagCompound == null || (!tagCompound.hasKey("target")) || tagCompound.getInteger("target") == -1) {
if (world.isRemote) {
Logging.message(player, EnumChatFormatting.RED + "The charged porter has no target.");
}
return;
}
if (!world.isRemote) {
IExtendedEntityProperties properties = player.getExtendedProperties(PlayerExtendedProperties.ID);
PlayerExtendedProperties playerExtendedProperties = (PlayerExtendedProperties) properties;
if (playerExtendedProperties.getPorterProperties().isTeleporting()) {
Logging.message(player, EnumChatFormatting.RED + "Already teleporting!");
return;
}
int target = tagCompound.getInteger("target");
TeleportDestinations destinations = TeleportDestinations.getDestinations(world);
GlobalCoordinate coordinate = destinations.getCoordinateForId(target);
if (coordinate == null) {
Logging.message(player, EnumChatFormatting.RED + "Something went wrong! The target has disappeared!");
TeleportationTools.applyEffectForSeverity(player, 3, false);
return;
}
TeleportDestination destination = destinations.getDestination(coordinate);
if (!TeleportationTools.checkValidTeleport(player, world.provider.dimensionId, destination.getDimension())) {
return;
}
Coordinate playerCoordinate = new Coordinate((int) player.posX, (int) player.posY, (int) player.posZ);
int cost = TeleportationTools.calculateRFCost(world, playerCoordinate, destination);
cost *= 1.5f;
int energy = getEnergyStored(stack);
if (cost > energy) {
Logging.message(player, EnumChatFormatting.RED + "Not enough energy to start the teleportation!");
return;
}
extractEnergyNoMax(stack, cost, false);
int ticks = TeleportationTools.calculateTime(world, playerCoordinate, destination);
ticks /= getSpeedBonus();
playerExtendedProperties.getPorterProperties().startTeleport(target, ticks);
Logging.message(player, EnumChatFormatting.YELLOW + "Start teleportation!");
}
}
use of mcjty.lib.varia.GlobalCoordinate in project RFTools by McJty.
the class SmartWrenchItem method getCurrentBlock.
public static GlobalCoordinate getCurrentBlock(ItemStack itemStack) {
NBTTagCompound tagCompound = itemStack.getTagCompound();
if (tagCompound != null && tagCompound.hasKey("selectedX")) {
int x = tagCompound.getInteger("selectedX");
int y = tagCompound.getInteger("selectedY");
int z = tagCompound.getInteger("selectedZ");
int dim = tagCompound.getInteger("selectedDim");
return new GlobalCoordinate(new Coordinate(x, y, z), dim);
}
return null;
}
Aggregations