Search in sources :

Example 26 with Pos

use of icbm.classic.lib.transform.vector.Pos in project ICBM-Classic by BuiltBrokenModding.

the class EntityMissile method readEntityFromNBT.

/**
 * (abstract) Protected helper method to read subclass entity additionalMissileData from NBT.
 */
@Override
public void readEntityFromNBT(NBTTagCompound nbt) {
    super.readEntityFromNBT(nbt);
    this.targetPos = new Pos(nbt.getCompoundTag(NBTConstants.TARGET));
    this.launcherPos = new Pos(nbt.getCompoundTag(NBTConstants.LAUNCHER_POS));
    this.acceleration = nbt.getFloat(NBTConstants.ACCELERATION);
    this.targetHeight = nbt.getInteger(NBTConstants.TARGET_HEIGHT);
    this.explosiveID = nbt.getInteger(NBTConstants.EXPLOSIVE_ID);
    this.ticksInAir = nbt.getInteger(NBTConstants.TICKS_IN_AIR);
    this.lockHeight = nbt.getDouble(NBTConstants.LOCK_HEIGHT);
    this.missileType = MissileFlightType.get(nbt.getInteger(NBTConstants.MISSILE_TYPE));
    this.preLaunchSmokeTimer = nbt.getInteger(NBTConstants.PRE_LAUNCH_SMOKE_TIMER);
    this.blastData = nbt.getCompoundTag(NBTConstants.ADDITIONAL_MISSILE_DATA);
}
Also used : Pos(icbm.classic.lib.transform.vector.Pos) BlockPos(net.minecraft.util.math.BlockPos)

Example 27 with Pos

use of icbm.classic.lib.transform.vector.Pos in project ICBM-Classic by BuiltBrokenModding.

the class MissileTrackerData method readFromNBT.

// Helper methods for saving and loading
public void readFromNBT(NBTTagCompound nbt) {
    ticksLeftToTarget = nbt.getInteger(NBTConstants.TICKS);
    targetPos = new Pos(nbt.getCompoundTag(NBTConstants.TARGET));
    missileData = nbt.getCompoundTag(NBTConstants.DATA);
}
Also used : Pos(icbm.classic.lib.transform.vector.Pos)

Example 28 with Pos

use of icbm.classic.lib.transform.vector.Pos in project ICBM-Classic by BuiltBrokenModding.

the class TileLauncherScreen method receiveRadioWave.

@Override
public // TODO pack as message object
void receiveRadioWave(// TODO pack as message object
float hz, // TODO pack as message object
IRadioWaveSender sender, // TODO pack as message object
String messageHeader, // TODO pack as message object
Object[] data) {
    // TODO make sure other launchers don't trigger when a laser designator is used
    if (isServer()) {
        // Floor frequency as we do not care about sub ranges
        int frequency = (int) Math.floor(hz);
        // Only tier 3 (2 for tier value) can be remotely fired
        if (getTier() == EnumTier.THREE && frequency == getFrequency() && launcherBase != null) {
            // Laser detonator signal
            if (// TODO cache headers somewhere like API references
            messageHeader.equals("activateLauncherWithTarget")) {
                Pos pos = (Pos) data[0];
                if (new Pos((IPos3D) this).distance(pos) < this.launcherBase.getRange()) {
                    setTarget(pos);
                    launch();
                    ((FakeRadioSender) sender).player.sendMessage(new TextComponentString("Firing missile at " + pos));
                }
            } else // Remote detonator signal
            if (messageHeader.equals("activateLauncher")) {
                ((FakeRadioSender) sender).player.sendMessage(new TextComponentString("Firing missile at " + getTarget()));
                launch();
            }
        }
    }
}
Also used : Pos(icbm.classic.lib.transform.vector.Pos) FakeRadioSender(icbm.classic.prefab.FakeRadioSender) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 29 with Pos

use of icbm.classic.lib.transform.vector.Pos in project ICBM-Classic by BuiltBrokenModding.

the class TileLauncherScreen method update.

@Override
public void update() {
    super.update();
    if (this.launcherBase == null || this.launcherBase.isInvalid()) {
        this.launcherBase = null;
        for (EnumFacing rotation : EnumFacing.HORIZONTALS) {
            final Pos position = new Pos((IPos3D) this).add(rotation);
            final TileEntity tileEntity = position.getTileEntity(world);
            if (tileEntity != null) {
                if (tileEntity instanceof TileLauncherBase) {
                    this.launcherBase = (TileLauncherBase) tileEntity;
                    if (isServer()) {
                        setRotation(rotation.getOpposite());
                        updateClient = true;
                    }
                }
            }
        }
    }
    if (isServer()) {
        // Delay launch, basically acts as a reload time
        if (launchDelay > 0) {
            launchDelay--;
        } else // Only launch if redstone
        if (// TODO replace with countdown
        ticks % 10 == 0 && world.getRedstonePowerFromNeighbors(getPos()) > 0) {
            this.launch();
        }
        // Update packet TODO see if this is needed
        if (ticks % 3 == 0) {
            sendDescPacket();
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IPos3D(com.builtbroken.jlib.data.vector.IPos3D) Pos(icbm.classic.lib.transform.vector.Pos) EnumFacing(net.minecraft.util.EnumFacing) TileLauncherBase(icbm.classic.content.blocks.launcher.base.TileLauncherBase)

Example 30 with Pos

use of icbm.classic.lib.transform.vector.Pos in project ICBM-Classic by BuiltBrokenModding.

the class ItemLaserDetonator method read.

@Override
public boolean read(ByteBuf buf, int id, EntityPlayer player, IPacket packet) {
    ItemStack stack = player.inventory.getCurrentItem();
    if (stack != null && stack.getItem() == this) {
        if (!player.world.isRemote) {
            int x = buf.readInt();
            int y = buf.readInt();
            int z = buf.readInt();
            LaserRemoteTriggerEvent event = new LaserRemoteTriggerEvent(player.world, new BlockPos(x, y, z), 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)
                RadioRegistry.popMessage(player.world, new FakeRadioSender(player, stack, 2000), getBroadCastHz(stack), "activateLauncherWithTarget", new Pos(x, y, z));
            else
                RadioRegistry.popMessage(player.world, new FakeRadioSender(player, stack, 2000), getBroadCastHz(stack), "activateLauncherWithTarget", new Pos(event.pos.getX(), event.pos.getY(), event.pos.getZ()));
        } else {
            player.sendMessage(new TextComponentString("Not encoded with launch data! Right click on launcher screen to encode."));
        }
    }
    return true;
}
Also used : LaserRemoteTriggerEvent(icbm.classic.api.events.LaserRemoteTriggerEvent) Pos(icbm.classic.lib.transform.vector.Pos) BlockPos(net.minecraft.util.math.BlockPos) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) FakeRadioSender(icbm.classic.prefab.FakeRadioSender) TextComponentString(net.minecraft.util.text.TextComponentString)

Aggregations

Pos (icbm.classic.lib.transform.vector.Pos)39 BlockPos (net.minecraft.util.math.BlockPos)22 TileEntity (net.minecraft.tileentity.TileEntity)8 Entity (net.minecraft.entity.Entity)6 ChunkPos (net.minecraft.util.math.ChunkPos)6 EnumFacing (net.minecraft.util.EnumFacing)5 TextComponentString (net.minecraft.util.text.TextComponentString)5 IPos3D (com.builtbroken.jlib.data.vector.IPos3D)4 ItemStack (net.minecraft.item.ItemStack)4 Location (icbm.classic.lib.transform.vector.Location)3 Point (icbm.classic.lib.transform.vector.Point)3 FakeRadioSender (icbm.classic.prefab.FakeRadioSender)3 EntityPlayer (net.minecraft.entity.player.EntityPlayer)3 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)3 ICBMClassic (icbm.classic.ICBMClassic)2 IWorldPosition (icbm.classic.api.data.IWorldPosition)2 IWorldPosItem (icbm.classic.api.items.IWorldPosItem)2 IExplosiveData (icbm.classic.api.reg.IExplosiveData)2 ItemLaserDetonator (icbm.classic.content.items.ItemLaserDetonator)2 ItemRemoteDetonator (icbm.classic.content.items.ItemRemoteDetonator)2