use of net.silentchaos512.gems.item.ItemTeleporterLinker in project SilentGems by SilentChaos512.
the class TileTeleporter method linkTeleporters.
public boolean linkTeleporters(EntityPlayer player, World world, BlockPos pos, ItemStack heldItem, EnumHand hand) {
if (world.isRemote) {
return true;
}
LogHelper log = SilentGems.logHelper;
LocalizationHelper loc = SilentGems.localizationHelper;
ItemTeleporterLinker linker = ModItems.teleporterLinker;
if (StackHelper.isEmpty(heldItem) || heldItem.getItem() != linker) {
log.warning("TileTeleporter.linkTeleporters: heldItem is not a linker?");
return false;
}
if (linker.isLinked(heldItem)) {
// Active state: link teleporters and set inactive.
DimensionalPosition position1 = linker.getLinkedPosition(heldItem);
DimensionalPosition position2 = new DimensionalPosition(pos, player.dimension);
if (position1 == null) {
log.warning("Teleporter Linker tried to link with no position set?");
return true;
}
TileTeleporter tile1 = (TileTeleporter) player.getServer().getWorld(position1.dim).getTileEntity(position1.toBlockPos());
TileTeleporter tile2 = (TileTeleporter) player.getServer().getWorld(position2.dim).getTileEntity(position2.toBlockPos());
if (tile1 == null || tile2 == null) {
// Could not find a teleporter?
ChatHelper.sendMessage(player, loc.getBlockSubText(Names.TELEPORTER, "LinkFail"));
log.warning("Could not find teleporter when linking:" + "\nTeleporter1 @ " + position1.toString() + "\nTeleporter2 @ " + position2.toString());
linker.setLinked(heldItem, false);
return false;
}
// Create "link"
tile1.destination = position2;
tile2.destination = position1;
ChatHelper.sendMessage(player, loc.getBlockSubText(Names.TELEPORTER, "LinkSuccess"));
linker.setLinked(heldItem, false);
tile1.markDirty();
tile2.markDirty();
} else {
// Inactive state: set active and location.
linker.setLinkedPosition(heldItem, new DimensionalPosition(pos, player.dimension));
linker.setLinked(heldItem, true);
ChatHelper.sendMessage(player, loc.getBlockSubText(Names.TELEPORTER, "LinkStart"));
}
return true;
}
Aggregations