Search in sources :

Example 1 with Location

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;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IWorldPosition(icbm.classic.api.data.IWorldPosition) IExplosive(icbm.classic.api.caps.IExplosive) ItemStack(net.minecraft.item.ItemStack) IWorldPosItem(icbm.classic.api.items.IWorldPosItem) Location(icbm.classic.lib.transform.vector.Location) ResourceLocation(net.minecraft.util.ResourceLocation)

Example 2 with Location

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);
    }
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Location(icbm.classic.lib.transform.vector.Location)

Example 3 with Location

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;
}
Also used : RadarGunTraceEvent(icbm.classic.api.events.RadarGunTraceEvent) ItemStack(net.minecraft.item.ItemStack) Location(icbm.classic.lib.transform.vector.Location)

Example 4 with Location

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;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IMissileLauncher(icbm.classic.api.caps.IMissileLauncher) ItemStack(net.minecraft.item.ItemStack) IMultiTile(icbm.classic.api.tile.multiblock.IMultiTile) IMultiTileHost(icbm.classic.api.tile.multiblock.IMultiTileHost) Location(icbm.classic.lib.transform.vector.Location)

Example 5 with Location

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));
    }
}
Also used : IPacketIDReceiver(icbm.classic.lib.network.IPacketIDReceiver) PacketTileReadException(icbm.classic.lib.network.ex.PacketTileReadException) PacketTileReadException(icbm.classic.lib.network.ex.PacketTileReadException) Location(icbm.classic.lib.transform.vector.Location)

Aggregations

Location (icbm.classic.lib.transform.vector.Location)11 ItemStack (net.minecraft.item.ItemStack)4 Pos (icbm.classic.lib.transform.vector.Pos)3 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)3 BlockPos (net.minecraft.util.math.BlockPos)3 IExplosive (icbm.classic.api.caps.IExplosive)2 IWorldPosition (icbm.classic.api.data.IWorldPosition)2 IWorldPosItem (icbm.classic.api.items.IWorldPosItem)2 Entity (net.minecraft.entity.Entity)2 TileEntity (net.minecraft.tileentity.TileEntity)2 ResourceLocation (net.minecraft.util.ResourceLocation)2 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)2 IMissile (icbm.classic.api.caps.IMissile)1 IMissileLauncher (icbm.classic.api.caps.IMissileLauncher)1 RadarGunTraceEvent (icbm.classic.api.events.RadarGunTraceEvent)1 IMultiTile (icbm.classic.api.tile.multiblock.IMultiTile)1 IMultiTileHost (icbm.classic.api.tile.multiblock.IMultiTileHost)1 BlastAntimatter (icbm.classic.content.blast.threaded.BlastAntimatter)1 EntityExplosion (icbm.classic.content.entity.EntityExplosion)1 IPacketIDReceiver (icbm.classic.lib.network.IPacketIDReceiver)1