use of net.silentchaos512.lib.util.DimensionalPosition in project SilentGems by SilentChaos512.
the class TileTeleporter method linkReturnHomeCharm.
public boolean linkReturnHomeCharm(EntityPlayer player, World world, BlockPos pos, ItemStack heldItem, EnumHand hand) {
if (world.isRemote) {
return true;
}
if (!heldItem.hasTagCompound()) {
heldItem.setTagCompound(new NBTTagCompound());
}
DimensionalPosition position = new DimensionalPosition(pos, player.dimension);
position.writeToNBT(heldItem.getTagCompound());
ChatHelper.sendMessage(player, SilentGems.localizationHelper.getBlockSubText(Names.TELEPORTER, "ReturnHomeBound"));
return true;
}
use of net.silentchaos512.lib.util.DimensionalPosition in project SilentGems by SilentChaos512.
the class BlockTeleporter method getWitLines.
@Override
public List<String> getWitLines(IBlockState state, BlockPos pos, EntityPlayer player, boolean advanced) {
TileEntity tile = player.world.getTileEntity(pos);
if (tile == null || !(tile instanceof TileTeleporter)) {
return null;
}
TileTeleporter teleporter = (TileTeleporter) tile;
DimensionalPosition destination = teleporter.getDestination();
return Lists.newArrayList(destination != null ? destination.toString() : "null");
}
use of net.silentchaos512.lib.util.DimensionalPosition in project SilentGems by SilentChaos512.
the class BlockTeleporterRedstone method clOnNeighborChanged.
@Override
protected void clOnNeighborChanged(IBlockState state, World world, BlockPos pos, Block block) {
final double searchRange = GemsConfig.TELEPORTER_REDSTONE_SEARCH_RADIUS * GemsConfig.TELEPORTER_REDSTONE_SEARCH_RADIUS;
TileTeleporter tile = (TileTeleporter) world.getTileEntity(pos);
if (!world.isRemote && world.isBlockIndirectlyGettingPowered(pos) != 0) {
// Is this a "dumb" teleport and are they allowed if so?
if (!tile.isDestinationAllowedIfDumb(null)) {
String str = SilentGems.instance.localizationHelper.getBlockSubText(Names.TELEPORTER, "NoReceiver");
return;
}
// Destination safe?
if (!tile.isDestinationSafe(null)) {
return;
}
boolean playSound = false;
// Check all entities, teleport those close to the teleporter.
DimensionalPosition source = null;
for (Entity entity : world.getEntities(Entity.class, e -> e.getDistanceSqToCenter(pos) < searchRange)) {
// Get source position (have to have the entity for this because dim?)
if (source == null) {
source = new DimensionalPosition(pos, entity.dimension);
}
if (entity instanceof EntityPlayer) {
EntityPlayer player = (EntityPlayer) entity;
// Chaos drain.
if (!tile.checkAndDrainChaos(player)) {
continue;
}
}
if (tile.teleportEntityToDestination(entity)) {
playSound = true;
}
}
if (playSound) {
float pitch = 0.7f + 0.3f * SilentGems.instance.random.nextFloat();
for (BlockPos p : new BlockPos[] { pos, tile.getDestination().toBlockPos() }) {
world.playSound(null, p, SoundEvents.ENTITY_ENDERMEN_TELEPORT, SoundCategory.BLOCKS, 1.0f, pitch);
}
}
}
}
use of net.silentchaos512.lib.util.DimensionalPosition in project SilentGems by SilentChaos512.
the class ItemReturnHome method clOnItemRightClick.
@Override
protected ActionResult<ItemStack> clOnItemRightClick(World world, EntityPlayer player, EnumHand hand) {
ItemStack stack = player.getHeldItem(hand);
DimensionalPosition pos = getBoundPosition(stack);
if (pos != null) {
player.setActiveHand(hand);
return new ActionResult(EnumActionResult.SUCCESS, stack);
} else {
// SilentGems.instance.localizationHelper.getItemSubText(itemName, TEXT_NOT_BOUND));
return new ActionResult(EnumActionResult.PASS, stack);
}
}
use of net.silentchaos512.lib.util.DimensionalPosition in project SilentGems by SilentChaos512.
the class ItemReturnHome method clAddInformation.
@Override
public void clAddInformation(ItemStack stack, World world, List list, boolean par4) {
// Is ctrl key down?
boolean modifier = Keyboard.isKeyDown(Keyboard.KEY_LCONTROL) || Keyboard.isKeyDown(Keyboard.KEY_RCONTROL);
LocalizationHelper loc = SilentGems.instance.localizationHelper;
// How to use
list.addAll(loc.getItemDescriptionLines(itemName));
// Display coordinates if modifier key is held.
DimensionalPosition pos = getBoundPosition(stack);
if (pos != null) {
if (modifier) {
list.add(loc.getItemSubText(itemName, TEXT_BOUND_TO, pos));
} else {
list.add(loc.getMiscText("PressCtrl"));
}
} else {
list.add(loc.getItemSubText(itemName, TEXT_NOT_BOUND));
}
}
Aggregations