use of net.silentchaos512.lib.util.DimensionalPosition in project SilentGems by SilentChaos512.
the class ItemTeleporterLinker method renderGameOverlay.
@SideOnly(Side.CLIENT)
public void renderGameOverlay(RenderGameOverlayEvent event) {
if (event.getType() != ElementType.TEXT) {
return;
}
Minecraft mc = Minecraft.getMinecraft();
EntityPlayer player = mc.player;
ItemStack heldItem = mc.player.getHeldItem(EnumHand.MAIN_HAND);
if (StackHelper.isEmpty(heldItem)) {
heldItem = mc.player.getHeldItem(EnumHand.OFF_HAND);
}
if (StackHelper.isValid(heldItem) && heldItem.getItem() == this) {
ScaledResolution res = new ScaledResolution(mc);
FontRenderer fontRender = mc.fontRenderer;
int width = res.getScaledWidth();
int height = res.getScaledHeight();
String str;
if (isLinked(heldItem)) {
DimensionalPosition pos = getLinkedPosition(heldItem);
double x = pos.x - player.posX;
double z = pos.z - player.posZ;
int distance = (int) Math.sqrt(x * x + z * z);
LocalizationHelper loc = SilentGems.instance.localizationHelper;
str = loc.getItemSubText(itemName, "Distance", distance);
int textX = width / 2 - fontRender.getStringWidth(str) / 2;
int textY = height * 3 / 5;
// Text colored differently depending on situation.
// Outside free range, same dimension
int color = 0xffff00;
if (pos.dim != player.dimension) {
// Different dimension
color = 0xff6600;
str = loc.getItemSubText(itemName, "DifferentDimension");
} else if (distance < GemsConfig.TELEPORTER_FREE_RANGE) {
// Inside free range
color = 0x00aaff;
}
fontRender.drawStringWithShadow(str, textX, textY, color);
}
}
}
use of net.silentchaos512.lib.util.DimensionalPosition in project SilentGems by SilentChaos512.
the class ItemReturnHome method tryTeleportPlayer.
public void tryTeleportPlayer(ItemStack stack, EntityPlayer player) {
LocalizationHelper loc = SilentGems.localizationHelper;
DimensionalPosition pos = getBoundPosition(stack);
// Not bound?
if (pos == null) {
return;
}
// Enough charge?
if (getCharge(stack) < getTeleportCost(stack, player)) {
ChatHelper.sendMessage(player, loc.getItemSubText(itemName, TEXT_NOT_ENOUGH_CHARGE));
return;
}
// Is the destination sane? (ie, y > 0)
if (pos.y <= 0) {
ChatHelper.sendMessage(player, loc.getItemSubText(itemName, TEXT_NOT_SANE));
return;
}
// Is the destination safe? (ie, no solid block at head level)
WorldServer worldServer = player.getServer().getWorld(pos.dim);
int height = (int) Math.ceil(player.eyeHeight);
BlockPos target = pos.toBlockPos().up(height);
// FIXME: Obstruction checks?
// if (worldServer.isBlockNormalCube(target, true)) {
// PlayerHelper.addChatMessage(player, loc.getItemSubText(itemName, TEXT_NOT_SAFE));
// PlayerHelper.addChatMessage(player, "" + target);
// PlayerHelper.addChatMessage(player, "" + worldServer.getBlockState(target));
// SilentGems.logHelper.warning("Return Home Charm believes destination is obstructed:\n"
// + "Target: " + target + "\nBlockstate: " + worldServer.getBlockState(target));
// return;
// }
// It should be safe to teleport.
// Reset fall distance then teleport.
player.fallDistance = 0.0f;
teleportPlayer(stack, player, pos);
// Play sounds
float soundPitch = 0.8f + 0.3f * SilentGems.random.nextFloat();
for (BlockPos p : new BlockPos[] { player.getPosition(), pos.toBlockPos() }) {
player.world.playSound(null, p, SoundEvents.ENTITY_ENDERMEN_TELEPORT, SoundCategory.PLAYERS, 1.0f, soundPitch);
}
}
use of net.silentchaos512.lib.util.DimensionalPosition in project SilentGems by SilentChaos512.
the class TileTeleporter method getRequiredChaos.
public int getRequiredChaos(EntityPlayer player) {
if (destination == null || destination.equals(DimensionalPosition.ZERO)) {
return 0;
}
DimensionalPosition source = new DimensionalPosition(pos, player.dimension);
if (source.dim != destination.dim) {
return GemsConfig.TELEPORTER_COST_CROSS_DIMENSION;
}
double distance = getDistanceBetweenTeleporters(source);
if (distance < GemsConfig.TELEPORTER_FREE_RANGE) {
return 0;
}
return MathHelper.clamp((int) (GemsConfig.TELEPORTER_COST_PER_BLOCK * distance), 0, getMaxCharge());
}
use of net.silentchaos512.lib.util.DimensionalPosition 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;
}
use of net.silentchaos512.lib.util.DimensionalPosition in project SilentGems by SilentChaos512.
the class TeleportUtil method teleportPlayerTo.
public static boolean teleportPlayerTo(EntityPlayerMP player, DimensionalPosition pos) {
int oldDimension = player.dimension;
// Debug line TODO: Remove later.
String debugLine = "Teleporting %s from {%s} to {%s}.";
debugLine = String.format(debugLine, player.getName(), new DimensionalPosition(player.getPosition(), player.dimension), pos);
SilentGems.logHelper.info(debugLine);
if (pos.dim != oldDimension) {
WorldServer oldWorldServer = player.getServer().getWorld(oldDimension);
WorldServer newWorldServer = player.getServer().getWorld(pos.dim);
// Dismount and teleport mount
if (player.getRidingEntity() != null) {
Entity mount = player.getRidingEntity();
player.dismountEntity(mount);
teleportEntityTo(mount, pos);
}
// Teleport player to dimension, using a custom teleporter to prevent Nether portal spawns
player.getServer().getPlayerList().transferPlayerToDimension(player, pos.dim, new TeleporterGems(newWorldServer));
if (oldDimension == 1) {
// Fixes world not loading when teleporting from the End.
newWorldServer.spawnEntity(player);
}
}
player.setPositionAndUpdate(pos.x + 0.5, pos.y + 1.0, pos.z + 0.5);
return true;
}
Aggregations