use of icbm.classic.lib.transform.vector.Location in project ICBM-Classic by BuiltBrokenModding.
the class ExplosiveInit method enderBlockCoordSet.
private static boolean enderBlockCoordSet(World world, BlockPos pos, EntityPlayer entityPlayer, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
final ItemStack heldItem = entityPlayer.getHeldItem(hand);
if (heldItem.getItem() instanceof IWorldPosItem) {
final IWorldPosItem posItem = ((IWorldPosItem) heldItem.getItem());
final IWorldPosition link = posItem.getLocation(heldItem);
if (link instanceof Location) {
TileEntity tileEntity = world.getTileEntity(pos);
if (tileEntity.hasCapability(ICBMClassicAPI.EXPLOSIVE_CAPABILITY, facing)) {
IExplosive explosive = tileEntity.getCapability(ICBMClassicAPI.EXPLOSIVE_CAPABILITY, facing);
if (explosive != null) {
NBTTagCompound tag = new NBTTagCompound();
((Location) link).writeIntNBT(tag);
explosive.getCustomBlastData().setTag("", tag);
if (!world.isRemote) {
// entityPlayer.sendMessage(new TextComponentString("Synced coordinate with " + this.getExplosiveName())); //TODO translate
}
return true;
}
}
}
}
return false;
}
use of icbm.classic.lib.transform.vector.Location in project ICBM-Classic by BuiltBrokenModding.
the class ItemRadarGun method setLocation.
@Override
public void setLocation(ItemStack stack, IWorldPosition loc) {
if (loc != null) {
if (stack.getTagCompound() == null) {
stack.setTagCompound(new NBTTagCompound());
}
NBTTagCompound save = new NBTTagCompound();
if (loc instanceof Location) {
((Location) loc).writeNBT(save);
} else {
new Location(loc).writeNBT(save);
}
stack.getTagCompound().setTag(NBT_LINK_POS, save);
} else if (stack.getTagCompound() != null) {
stack.getTagCompound().removeTag(NBT_LINK_POS);
}
}
use of icbm.classic.lib.transform.vector.Location in project ICBM-Classic by BuiltBrokenModding.
the class ItemRadarGun method trace.
public boolean trace(BlockPos pos, EntityPlayer player) {
ItemStack stack = player.inventory.getCurrentItem();
if (stack != null && stack.getItem() == this) {
RadarGunTraceEvent event = new RadarGunTraceEvent(player.world, pos, player);
if (// event was canceled
MinecraftForge.EVENT_BUS.post(event))
return false;
if (// someone set the pos in the event to null, use original data
event.pos == null)
setLocation(stack, new Location(player.world, pos.getX(), pos.getY(), pos.getZ()));
else
setLocation(stack, new Location(player.world, event.pos.getX(), event.pos.getY(), event.pos.getZ()));
LanguageUtility.addChatToPlayer(player, "gps.pos.set.name");
System.out.println(getLocation(stack));
}
return true;
}
use of icbm.classic.lib.transform.vector.Location in project ICBM-Classic by BuiltBrokenModding.
the class ItemRadarGun method onItemUse.
@Override
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
ItemStack stack = player.getHeldItem(hand);
if (world.isRemote) {
return EnumActionResult.SUCCESS;
}
Location location = new Location(world, pos);
TileEntity tile = location.getTileEntity();
if (tile instanceof IMultiTile) {
IMultiTileHost host = ((IMultiTile) tile).getHost();
if (host instanceof TileEntity) {
tile = (TileEntity) host;
}
}
if (player.isSneaking()) {
stack.setTagCompound(null);
stack.setItemDamage(0);
LanguageUtility.addChatToPlayer(player, "gps.cleared.name");
player.inventoryContainer.detectAndSendChanges();
return EnumActionResult.SUCCESS;
} else {
Location storedLocation = getLocation(stack);
if (ICBMClassicHelpers.isLauncher(tile, facing)) {
if (storedLocation == null) {
LanguageUtility.addChatToPlayer(player, "gps.error.pos.invalid.null.name");
return EnumActionResult.SUCCESS;
} else if (!storedLocation.isAboveBedrock()) {
LanguageUtility.addChatToPlayer(player, "gps.error.pos.invalid.name");
return EnumActionResult.SUCCESS;
} else if (storedLocation.world != world) {
LanguageUtility.addChatToPlayer(player, "gps.error.pos.invalid.world.name");
return EnumActionResult.SUCCESS;
} else {
final IMissileLauncher launcher = ICBMClassicHelpers.getLauncher(tile, facing);
if (launcher != null) {
launcher.setTarget(storedLocation.x(), storedLocation.y(), storedLocation.z());
LanguageUtility.addChatToPlayer(player, "gps.data.transferred.name");
return EnumActionResult.SUCCESS;
}
}
} else if (// otherwise, save the currently clicked block as a location if the trace event has not been canceled
trace(pos, player))
return EnumActionResult.SUCCESS;
}
return EnumActionResult.PASS;
}
use of icbm.classic.lib.transform.vector.Location in project ICBM-Classic by BuiltBrokenModding.
the class PacketTile method handle.
/**
* Called to handler a packet when it is received
*
* @param player - player who received the packet
* @param tile - tile who is receiving the packet
*/
public void handle(EntityPlayer player, TileEntity tile) {
// TODO add checksum or hash to verify the packet is sent to the correct tile
final Location location = new Location(player.world, x, y, z);
if (tile == null) {
ICBMClassic.logger().error(new PacketTileReadException(location, "Null tile"));
} else if (tile.isInvalid()) {
ICBMClassic.logger().error(new PacketTileReadException(location, "Invalidated tile"));
} else if (tile instanceof IPacketIDReceiver) {
if (((IPacketIDReceiver) tile).shouldReadPacket(player, location, this)) {
try {
IPacketIDReceiver receiver = (IPacketIDReceiver) tile;
receiver.read(dataToRead, id, player, this);
} catch (IndexOutOfBoundsException e) {
ICBMClassic.logger().error(new PacketTileReadException(location, "Packet was read past its size."));
ICBMClassic.logger().error("Error: ", e);
} catch (NullPointerException e) {
ICBMClassic.logger().error(new PacketTileReadException(location, "Null pointer while reading data", e));
ICBMClassic.logger().error("Error: ", e);
} catch (Exception e) {
ICBMClassic.logger().error(new PacketTileReadException(location, "Failed to read packet", e));
ICBMClassic.logger().error("Error: ", e);
}
} else {
ICBMClassic.logger().error("Error: " + tile + " rejected packet " + this + " due to invalid conditions.");
}
} else {
ICBMClassic.logger().error(new PacketTileReadException(location, "Unsupported action for " + tile));
}
}
Aggregations