resonant.lib.transform.vector.Vector3 - java examples

Here are the examples of the java api resonant.lib.transform.vector.Vector3 taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

68 Examples 7

19 View Complete Implementation : TileLauncherBase.java
Copyright MIT License
Author : BuiltBrokenModding
/**
 * Checks to see if the target is too close.
 *
 * @param target
 * @return
 */
public boolean replacedaiJin(Vector3 target) {
    // Check if it is greater than the minimum range
    if (new Vector3(this.xCoord, 0, this.zCoord).subtract(new Vector3(target.x(), 0, target.z())).magnitude() < 10) {
        return true;
    }
    return false;
}

19 View Complete Implementation : TileLauncherPrefab.java
Copyright MIT License
Author : BuiltBrokenModding
public abstract clreplaced TileLauncherPrefab extends TileFrequency implements ILauncherController {

    protected Vector3 targetPos = null;

    public TileLauncherPrefab() {
        super(Material.iron);
    }

    @Override
    public void onInstantiate() {
        super.onInstantiate();
        FrequencyGridRegistry.instance().add(this);
    }

    @Override
    public void invalidate() {
        FrequencyGridRegistry.instance().remove(this);
        super.invalidate();
    }

    @Override
    public Vector3 getTarget() {
        if (this.targetPos == null) {
            this.targetPos = new Vector3(this.xCoord, 0, this.zCoord);
        }
        return this.targetPos;
    }

    @Override
    public void setTarget(Vector3 target) {
        this.targetPos = target.floor();
    }

    @Override
    public void readFromNBT(NBTTagCompound nbt) {
        super.readFromNBT(nbt);
        this.targetPos = new Vector3(nbt.getCompoundTag("target"));
    }

    @Override
    public void writeToNBT(NBTTagCompound nbt) {
        super.writeToNBT(nbt);
        if (this.targetPos != null) {
            nbt.setTag("target", this.targetPos.writeNBT(new NBTTagCompound()));
        }
    }
}

19 View Complete Implementation : TileProximityDetector.java
Copyright MIT License
Author : BuiltBrokenModding
@Override
public boolean configure(EnreplacedyPlayer player, int side, Vector3 hit) {
    isInverted = !isInverted;
    if (!worldObj.isRemote) {
        player.addChatMessage(new ChatComponentText("Proximity Detector Inversion: " + isInverted));
    }
    return true;
}

19 View Complete Implementation : TileLauncherBase.java
Copyright MIT License
Author : BuiltBrokenModding
// Is the target too far?
public boolean replacedaiYuan(Vector3 target) {
    double distance = new Vector3(this.xCoord, 0, this.zCoord).subtract(new Vector3(target.x(), 0, target.z())).magnitude();
    // Checks if it is greater than the maximum range for the launcher base
    if (this.tier == 0) {
        if (distance < Settings.MAX_MISSILE_RANGE / 10) {
            return false;
        }
    } else if (this.tier == 1) {
        if (distance < Settings.MAX_MISSILE_RANGE / 5) {
            return false;
        }
    } else if (this.tier == 2) {
        if (distance < Settings.MAX_MISSILE_RANGE) {
            return false;
        }
    }
    return true;
}

19 View Complete Implementation : TileCamouflage.java
Copyright MIT License
Author : BuiltBrokenModding
public boolean use(EnreplacedyPlayer player, int side, Vector3 hit) {
    if (player.getCurrentEquippedItem() != null) {
        Block block = Block.getBlockFromItem(player.getCurrentEquippedItem().gereplacedem());
        if (block != null && block != this.getBlockType()) {
            if (block instanceof ICamouflageMaterial || (block.isNormalCube() && (block.getRenderType() == 0 || block.getRenderType() == 31))) {
                this.block = block;
                this.blockMeta = player.getCurrentEquippedItem().gereplacedemDamage();
                if (!this.worldObj.isRemote) {
                    ResonantEngine.instance.packetHandler.sendToAllInDimension(this.getDescPacket(), world());
                }
                world().markBlockForUpdate(xi(), yi(), zi());
                return true;
            }
        }
    }
    return true;
}

19 View Complete Implementation : TileLauncherBase.java
Copyright MIT License
Author : BuiltBrokenModding
// Checks if the missile target is in range
public boolean isInRange(Vector3 target) {
    if (target != null)
        return !replacedaiYuan(target) && !replacedaiJin(target);
    return false;
}

19 View Complete Implementation : TileLauncherPrefab.java
Copyright MIT License
Author : BuiltBrokenModding
@Override
public void setTarget(Vector3 target) {
    this.targetPos = target.floor();
}

19 View Complete Implementation : WeaponSystem.java
Copyright MIT License
Author : BuiltBrokenModding
/**
 * Called when the weapon hits a block
 */
protected abstract void onHitBlock(Vector3 block);

19 View Complete Implementation : TileCamouflage.java
Copyright MIT License
Author : BuiltBrokenModding
@Override
public boolean configure(EnreplacedyPlayer player, int side, Vector3 hit) {
    if (!player.isSneaking())
        toggleRenderSide(ForgeDirection.getOrientation(side));
    else
        toggleCollision();
    worldObj.markBlockForUpdate(xi(), yi(), zi());
    return true;
}

19 View Complete Implementation : TurretAI.java
Copyright MIT License
Author : BuiltBrokenModding
public boolean isTargetInBounds(Vector3 target) {
    return isTargetInBounds(this.turret().fromCenter(), target);
}

19 View Complete Implementation : TileProximityDetector.java
Copyright MIT License
Author : BuiltBrokenModding
public clreplaced TileProximityDetector extends TileFrequency implements IRedstoneProvider, IPacketReceiver {

    private static final int MAX_DISTANCE = 30;

    private static final float DIAN = 5;

    public boolean isDetect = false;

    public Vector3 minCoord = new Vector3(9, 9, 9);

    public Vector3 maxCoord = new Vector3(9, 9, 9);

    public byte mode = 0;

    private final Set<EnreplacedyPlayer> yongZhe = new HashSet<EnreplacedyPlayer>();

    public boolean isInverted = false;

    public TileProximityDetector() {
        super(Material.iron);
        this.normalRender(true);
        this.canProvidePower(true);
        this.useSidedTextures_$eq(true);
    }

    @Override
    public void update() {
        super.update();
        if (!this.worldObj.isRemote) {
            if (this.ticks() % 20 == 0) {
                for (EnreplacedyPlayer player : this.yongZhe) {
                    ResonantEngine.instance.packetHandler.sendToPlayer(this.getDescPacket(), (EnreplacedyPlayerMP) player);
                }
                boolean isDetectThisCheck = false;
                if (this.getEnergyStorage().checkExtract()) {
                    AxisAlignedBB bounds = AxisAlignedBB.getBoundingBox(this.xCoord - minCoord.x(), this.yCoord - minCoord.y(), this.zCoord - minCoord.z(), this.xCoord + maxCoord.x() + 1D, this.yCoord + maxCoord.y() + 1D, this.zCoord + maxCoord.z() + 1D);
                    List<EnreplacedyLivingBase> enreplacediesNearby = worldObj.getEnreplacediesWithinAABB(EnreplacedyLivingBase.clreplaced, bounds);
                    for (EnreplacedyLivingBase enreplacedy : enreplacediesNearby) {
                        if (enreplacedy instanceof EnreplacedyPlayer && (this.mode == 0 || this.mode == 1)) {
                            boolean gotDisrupter = false;
                            for (ItemStack inventory : ((EnreplacedyPlayer) enreplacedy).inventory.mainInventory) {
                                if (inventory != null) {
                                    if (inventory.gereplacedem() instanceof ItemSignalDisrupter) {
                                        if (((ItemSignalDisrupter) inventory.gereplacedem()).getFrequency(inventory) == getFrequency()) {
                                            gotDisrupter = true;
                                            break;
                                        }
                                    }
                                }
                            }
                            if (gotDisrupter) {
                                if (this.isInverted) {
                                    isDetectThisCheck = true;
                                    break;
                                }
                                continue;
                            }
                            if (!this.isInverted) {
                                isDetectThisCheck = true;
                            }
                        } else if (!this.isInverted && !(enreplacedy instanceof EnreplacedyPlayer) && (this.mode == 0 || this.mode == 2)) {
                            isDetectThisCheck = true;
                            break;
                        }
                    }
                    this.getEnergyStorage().extractEnergy();
                }
                if (isDetectThisCheck != this.isDetect) {
                    this.isDetect = isDetectThisCheck;
                    this.worldObj.notifyBlocksOfNeighborChange(this.xCoord, this.yCoord, this.zCoord, this.getBlockType());
                }
            }
        }
    }

    @Override
    public boolean use(EnreplacedyPlayer player, int side, Vector3 hit) {
        if (!world().isRemote)
            player.openGui(ICBM.INSTANCE, 0, world(), hit.xi(), hit.yi(), hit.zi());
        return false;
    }

    @Override
    public boolean configure(EnreplacedyPlayer player, int side, Vector3 hit) {
        isInverted = !isInverted;
        if (!worldObj.isRemote) {
            player.addChatMessage(new ChatComponentText("Proximity Detector Inversion: " + isInverted));
        }
        return true;
    }

    @Override
    public PacketTile getDescPacket() {
        return new PacketTile(this, 0, this.getEnergyStorage().getEnergy(), getFrequency(), this.mode, this.isInverted, this.minCoord.xi(), this.minCoord.yi(), this.minCoord.zi(), this.maxCoord.xi(), this.maxCoord.yi(), this.maxCoord.zi());
    }

    @Override
    public void read(ByteBuf data, EnreplacedyPlayer player, PacketType type) {
        try {
            switch(data.readInt()) {
                case 0:
                    {
                        this.getEnergyStorage().setEnergy(data.readDouble());
                        this.setFrequency(data.readInt());
                        this.mode = data.readByte();
                        this.isInverted = data.readBoolean();
                        this.minCoord = new Vector3(Math.max(0, Math.min(MAX_DISTANCE, data.readInt())), Math.max(0, Math.min(MAX_DISTANCE, data.readInt())), Math.max(0, Math.min(MAX_DISTANCE, data.readInt())));
                        this.maxCoord = new Vector3(Math.max(0, Math.min(MAX_DISTANCE, data.readInt())), Math.max(0, Math.min(MAX_DISTANCE, data.readInt())), Math.max(0, Math.min(MAX_DISTANCE, data.readInt())));
                        break;
                    }
                case 1:
                    {
                        // Mode
                        mode = data.readByte();
                        break;
                    }
                case 2:
                    {
                        // Freq
                        setFrequency(data.readInt());
                        break;
                    }
                case 3:
                    {
                        // MinVec
                        minCoord = new Vector3(Math.max(0, Math.min(MAX_DISTANCE, data.readInt())), Math.max(0, Math.min(MAX_DISTANCE, data.readInt())), Math.max(0, Math.min(MAX_DISTANCE, data.readInt())));
                        break;
                    }
                case 4:
                    {
                        // MaxVec
                        maxCoord = new Vector3(Math.max(0, Math.min(MAX_DISTANCE, data.readInt())), Math.max(0, Math.min(MAX_DISTANCE, data.readInt())), Math.max(0, Math.min(MAX_DISTANCE, data.readInt())));
                        break;
                    }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * Reads a tile enreplacedy from NBT.
     */
    @Override
    public void readFromNBT(NBTTagCompound nbt) {
        super.readFromNBT(nbt);
        this.mode = nbt.getByte("mode");
        this.isInverted = nbt.getBoolean("isInverted");
        this.minCoord = new Vector3(nbt.getCompoundTag("minCoord"));
        this.maxCoord = new Vector3(nbt.getCompoundTag("maxCoord"));
    }

    /**
     * Writes a tile enreplacedy to NBT.
     */
    @Override
    public void writeToNBT(NBTTagCompound nbt) {
        super.writeToNBT(nbt);
        nbt.setByte("mode", this.mode);
        nbt.setBoolean("isInverted", this.isInverted);
        nbt.setTag("minCoord", this.minCoord.writeNBT(new NBTTagCompound()));
        nbt.setTag("maxCoord", this.maxCoord.writeNBT(new NBTTagCompound()));
    }

    @Override
    public boolean isPoweringTo(ForgeDirection side) {
        return this.isDetect;
    }

    @Override
    public boolean isIndirectlyPoweringTo(ForgeDirection side) {
        return this.isDetect;
    }
}

19 View Complete Implementation : BlastEnderman.java
Copyright MIT License
Author : BuiltBrokenModding
public clreplaced BlastEnderman extends Blast {

    public int duration = 20 * 8;

    private Vector3 teleportTarget;

    public BlastEnderman(World world, Enreplacedy enreplacedy, double x, double y, double z, float size) {
        super(world, enreplacedy, x, y, z, size);
    }

    public BlastEnderman(World world, Enreplacedy enreplacedy, double x, double y, double z, float size, Vector3 teleportTarget) {
        super(world, enreplacedy, x, y, z, size);
        this.teleportTarget = teleportTarget;
    }

    @Override
    public void doExplode() {
        if (this.world().isRemote) {
            int r = (int) (this.getRadius() - ((double) this.callCount / (double) this.duration) * this.getRadius());
            for (int x = -r; x < r; x++) {
                for (int z = -r; z < r; z++) {
                    for (int y = -r; y < r; y++) {
                        Vector3 targetPosition = position.add(new Vector3(x, y, z));
                        double distance = targetPosition.distance(position);
                        if (distance < r && distance > r - 1) {
                            if (!targetPosition.isAirBlock(world()))
                                continue;
                            if (this.world().rand.nextFloat() < Math.max(0.001 * r, 0.01)) {
                                float velX = (float) ((targetPosition.x() - position.x()) * 0.6);
                                float velY = (float) ((targetPosition.y() - position.y()) * 0.6);
                                float velZ = (float) ((targetPosition.z() - position.z()) * 0.6);
                                ICBM.proxy.spawnParticle("portal", world(), targetPosition, velX, velY, velZ, 5f, 1);
                            }
                        }
                    }
                }
            }
        }
        int radius = (int) this.getRadius();
        AxisAlignedBB bounds = AxisAlignedBB.getBoundingBox(position.x() - radius, position.y() - radius, position.z() - radius, position.x() + radius, position.y() + radius, position.z() + radius);
        List<Enreplacedy> allEnreplacedies = world().getEnreplacediesWithinAABB(Enreplacedy.clreplaced, bounds);
        boolean explosionCreated = false;
        for (Enreplacedy enreplacedy : allEnreplacedies) {
            if (enreplacedy != this.controller) {
                double xDifference = enreplacedy.posX - position.x();
                double yDifference = enreplacedy.posY - position.y();
                double zDifference = enreplacedy.posZ - position.z();
                int r = (int) this.getRadius();
                if (xDifference < 0)
                    r = (int) -this.getRadius();
                enreplacedy.motionX -= (r - xDifference) * Math.abs(xDifference) * 0.0006;
                r = (int) this.getRadius();
                if (enreplacedy.posY > position.y())
                    r = (int) -this.getRadius();
                enreplacedy.motionY += (r - yDifference) * Math.abs(yDifference) * 0.0011;
                r = (int) this.getRadius();
                if (zDifference < 0)
                    r = (int) -this.getRadius();
                enreplacedy.motionZ -= (r - zDifference) * Math.abs(zDifference) * 0.0006;
                if (new Vector3(enreplacedy.posX, enreplacedy.posY, enreplacedy.posZ).subtract(position).magnitude() < 4) {
                    if (!explosionCreated && callCount % 5 == 0) {
                        world().spawnParticle("hugeexplosion", enreplacedy.posX, enreplacedy.posY, enreplacedy.posZ, 0.0D, 0.0D, 0.0D);
                        explosionCreated = true;
                    }
                    try {
                        /**
                         * If a target doesn't exist, search for a random one within 100 block
                         * range.
                         */
                        if (this.teleportTarget == null) {
                            int checkY;
                            int checkX = this.world().rand.nextInt(300) - 150 + (int) this.controller.posX;
                            int checkZ = this.world().rand.nextInt(300) - 150 + (int) this.controller.posZ;
                            for (checkY = 63; !this.world().isAirBlock(checkX, checkY, checkZ) && !this.world().isAirBlock(checkX, checkY + 1, checkZ); ++checkY) {
                                ;
                            }
                            this.teleportTarget = new Vector3(checkX, checkY, checkZ);
                        }
                        this.world().playSoundAtEnreplacedy(enreplacedy, "mob.endermen.portal", 1.0F, 1.0F);
                        if (enreplacedy instanceof EnreplacedyPlayerMP) {
                            ((EnreplacedyPlayerMP) enreplacedy).playerNetServerHandler.setPlayerLocation(this.teleportTarget.x() + 0.5, this.teleportTarget.y() + 0.5, this.teleportTarget.z() + 0.5, enreplacedy.rotationYaw, enreplacedy.rotationPitch);
                        } else {
                            enreplacedy.setPosition(this.teleportTarget.x() + 0.5, this.teleportTarget.y() + 0.5, this.teleportTarget.z() + 0.5);
                        }
                    } catch (Exception e) {
                        Reference.LOGGER.severe("Failed to teleport enreplacedy to the End.");
                        e.printStackTrace();
                    }
                }
            }
        }
        this.world().playSound(this.position.x(), this.position.y(), this.position.z(), "portal.portal", 2F, world().rand.nextFloat() * 0.4F + 0.8F, false);
        if (this.callCount > this.duration) {
            this.controller.endExplosion();
        }
    }

    @Override
    public void doPostExplode() {
        super.doPostExplode();
        if (!this.world().isRemote) {
            for (int i = 0; i < 8; i++) {
                EnreplacedyEnderman enderman = new EnreplacedyEnderman(world());
                enderman.setPosition(this.position.x(), this.position.y(), this.position.z());
                this.world().spawnEnreplacedyInWorld(enderman);
            }
        }
    }

    /**
     * The interval in ticks before the next procedural call of this explosive
     *
     * @return - Return -1 if this explosive does not need proceudral calls
     */
    @Override
    public int proceduralInterval() {
        return 1;
    }

    @Override
    public float getRadius() {
        return 20;
    }

    @Override
    public long getEnergy() {
        return 0;
    }

    @Override
    public boolean isMovable() {
        return true;
    }
}

19 View Complete Implementation : TileMissileAssembler.java
Copyright MIT License
Author : BuiltBrokenModding
@Override
public boolean configure(EnreplacedyPlayer enreplacedyPlayer, int s, Vector3 hit) {
    if (world().isRemote) {
        return true;
    }
    byte rotation = rotationSide;
    ForgeDirection side = placedSide;
    if (rotation == 3) {
        rotation = 0;
    } else {
        rotation++;
    }
    if (canPlaceBlockAt(side, rotation)) {
        // TODO re-implement wrench rotation
        return true;
    }
    return false;
}

19 View Complete Implementation : GuiLauncherScreen.java
Copyright MIT License
Author : BuiltBrokenModding
/**
 * Call this method from you GuiScreen to process the keys into textbox.
 */
@Override
public void keyTyped(char par1, int par2) {
    super.keyTyped(par1, par2);
    this.target_xCoord_field.textboxKeyTyped(par1, par2);
    this.target_zCoord_field.textboxKeyTyped(par1, par2);
    if (tileEnreplacedy.getTier() >= 1) {
        this.target_yCoord_field.textboxKeyTyped(par1, par2);
        this.target_height_field.textboxKeyTyped(par1, par2);
        if (tileEnreplacedy.getTier() > 1) {
            this.target_freq_field.textboxKeyTyped(par1, par2);
        }
    }
    try {
        Vector3 newTarget = new Vector3(Integer.parseInt(this.target_xCoord_field.getText()), Math.max(Integer.parseInt(this.target_yCoord_field.getText()), 0), Integer.parseInt(this.target_zCoord_field.getText()));
        this.tileEnreplacedy.setTarget(newTarget);
        ResonantEngine.instance.packetHandler.sendToServer(new PacketTile(this.tileEnreplacedy, 2, this.tileEnreplacedy.getTarget().xi(), this.tileEnreplacedy.getTarget().yi(), this.tileEnreplacedy.getTarget().zi()));
    } catch (NumberFormatException e) {
    }
    try {
        short newFrequency = (short) Math.max(Short.parseShort(this.target_freq_field.getText()), 0);
        this.tileEnreplacedy.setFrequency(newFrequency);
        ResonantEngine.instance.packetHandler.sendToServer(new PacketTile(this.tileEnreplacedy, 1, this.tileEnreplacedy.getFrequency()));
    } catch (NumberFormatException e) {
    }
    try {
        short newGaoDu = (short) Math.max(Math.min(Short.parseShort(this.target_height_field.getText()), Short.MAX_VALUE), 3);
        this.tileEnreplacedy.gaoDu = newGaoDu;
        ResonantEngine.instance.packetHandler.sendToServer(new PacketTile(this.tileEnreplacedy, 3, this.tileEnreplacedy.gaoDu));
    } catch (NumberFormatException e) {
    }
}

19 View Complete Implementation : TileMissileAssembler.java
Copyright MIT License
Author : BuiltBrokenModding
public boolean canPlaceBlockAt(ForgeDirection placeSide, int rot) {
    VectorWorld pos = toVectorWorld();
    if (pos.isAirBlock() || pos.isBlockEqual(ICBM.blockMissilereplacedembler)) {
        List<Vector3> vecs = TileMissilereplacedembler.getMultiBlockVectors(placeSide, (byte) rot);
        for (Vector3 v : vecs) {
            VectorWorld vec = pos.clone().add(v);
            if (!vec.isAirBlock()) {
                return false;
            }
        }
        return true;
    }
    return false;
}

19 View Complete Implementation : GuiProximityDetector.java
Copyright MIT License
Author : BuiltBrokenModding
/**
 * Call this method from you GuiScreen to process the keys into textbox.
 */
@Override
public void keyTyped(char par1, int par2) {
    super.keyTyped(par1, par2);
    this.textFieldminX.textboxKeyTyped(par1, par2);
    this.textFieldminY.textboxKeyTyped(par1, par2);
    this.textFieldminZ.textboxKeyTyped(par1, par2);
    this.textFieldmaxX.textboxKeyTyped(par1, par2);
    this.textFieldmaxY.textboxKeyTyped(par1, par2);
    this.textFieldmaxZ.textboxKeyTyped(par1, par2);
    this.textFieldFreq.textboxKeyTyped(par1, par2);
    try {
        int newFrequency = Math.max(0, Integer.parseInt(this.textFieldFreq.getText()));
        this.tileEnreplacedy.setFrequency(newFrequency);
        ResonantEngine.instance.packetHandler.sendToServer(new PacketTile(this.tileEnreplacedy, 2, this.tileEnreplacedy.getFrequency()));
    } catch (Exception e) {
    }
    try {
        Vector3 newMinCoord = new Vector3(Integer.parseInt(this.textFieldminX.getText()), Integer.parseInt(this.textFieldminY.getText()), Integer.parseInt(this.textFieldminZ.getText()));
        this.tileEnreplacedy.minCoord = newMinCoord;
        ResonantEngine.instance.packetHandler.sendToServer(new PacketTile(this.tileEnreplacedy, 3, this.tileEnreplacedy.minCoord.xi(), this.tileEnreplacedy.minCoord.yi(), this.tileEnreplacedy.minCoord.zi()));
    } catch (Exception e) {
    }
    try {
        Vector3 newMaxCoord = new Vector3(Integer.parseInt(this.textFieldmaxX.getText()), Integer.parseInt(this.textFieldmaxY.getText()), Integer.parseInt(this.textFieldmaxZ.getText()));
        this.tileEnreplacedy.maxCoord = newMaxCoord;
        ResonantEngine.instance.packetHandler.sendToServer(new PacketTile(this.tileEnreplacedy, 4, this.tileEnreplacedy.maxCoord.xi(), this.tileEnreplacedy.maxCoord.yi(), this.tileEnreplacedy.maxCoord.zi()));
    } catch (Exception e) {
    }
}

19 View Complete Implementation : TurretAI.java
Copyright MIT License
Author : BuiltBrokenModding
/**
 * Adjusts the turret target to look at a specific location.
 */
public void lookAt(Vector3 target) {
    turret().getServo().setTargetRotation(turret().fromCenter().toEulerAngle(target));
}

18 View Complete Implementation : TurretAI.java
Copyright MIT License
Author : BuiltBrokenModding
/**
 * Translates the aim offset "out of the turret block" to prevent the turret itself from block
 * the ray trace.
 *
 * @param enreplacedy
 * @return
 */
public boolean canEnreplacedyBeSeen(Enreplacedy enreplacedy) {
    Vector3 traceStart = turret().fromCenter().add(turret().getWeaponOffset());
    return canEnreplacedyBeSeen(traceStart, enreplacedy);
}

18 View Complete Implementation : TurretAI.java
Copyright MIT License
Author : BuiltBrokenModding
/**
 * checks to see if the tileTurret is looking the target location
 *
 * @param target - xyz target
 * @param allowedError - amount these tileTurret can be off in degrees from target
 * @return true if its with in error range
 */
public boolean isLookingAt(Vector3 target, float allowedError) {
    EulerAngle targetAngle = turret().fromCenter().toEulerAngle(target);
    return turret().getServo().isWithin(targetAngle, allowedError);
}

18 View Complete Implementation : TurretAI.java
Copyright MIT License
Author : BuiltBrokenModding
public MovingObjectPosition rayTrace(double distance) {
    // Ray Tracing is needed for Mounted Sentries aswell
    Vector3 reach = turret.getServo().toVector().multiply(distance);
    MovingObjectPosition hitTarget = turret.fromCenter().add(turret.getWeaponOffset()).rayTrace(turret.world(), reach, 500);
    return hitTarget;
}

18 View Complete Implementation : TileMissileAssembler.java
Copyright MIT License
Author : BuiltBrokenModding
@Override
public boolean use(EnreplacedyPlayer enreplacedyPlayer, int side, Vector3 hit) {
    if (enreplacedyPlayer.inventory.getCurrenreplacedem() != null && this.getStackInSlot(0) == null) {
        if (enreplacedyPlayer.inventory.getCurrenreplacedem().gereplacedem() instanceof ItemMissile) {
            this.setInventorySlotContents(0, enreplacedyPlayer.inventory.getCurrenreplacedem());
            enreplacedyPlayer.inventory.setInventorySlotContents(enreplacedyPlayer.inventory.currenreplacedem, null);
            this.onInventoryChanged();
            return true;
        }
    }
    if (!this.worldObj.isRemote)
        enreplacedyPlayer.openGui(ICBM.INSTANCE, 0, this.worldObj, this.xCoord, this.yCoord, this.zCoord);
    return true;
}

18 View Complete Implementation : TileEMPTower.java
Copyright MIT License
Author : BuiltBrokenModding
@Override
public boolean use(EnreplacedyPlayer enreplacedyPlayer, int side, Vector3 hit) {
    if (!this.worldObj.isRemote)
        enreplacedyPlayer.openGui(ICBM.INSTANCE, 0, this.worldObj, this.xCoord, this.yCoord, this.zCoord);
    return true;
}

18 View Complete Implementation : TileLauncherBase.java
Copyright MIT License
Author : BuiltBrokenModding
/**
 * Launches the missile
 *
 * @param target - The target in which the missile will land in
 */
public void launchMissile(Vector3 target, int gaoDu) {
    // Apply inaccuracy
    float inaccuracy;
    if (this.supportFrame != null) {
        inaccuracy = this.supportFrame.getInaccuracy();
    } else {
        inaccuracy = 30f;
    }
    inaccuracy *= (float) Math.random() * 2 - 1;
    target.addEquals(inaccuracy, 0, inaccuracy);
    this.decrStackSize(0, 1);
    this.missile.launch(target, gaoDu);
    this.missile = null;
}

18 View Complete Implementation : TileLauncherBase.java
Copyright MIT License
Author : BuiltBrokenModding
public void setMissile() {
    if (!this.worldObj.isRemote) {
        if (this.getStackInSlot(0) != null) {
            if (this.getStackInSlot(0).gereplacedem() instanceof ItemMissile) {
                int explosiveID = this.getStackInSlot(0).gereplacedemDamage();
                if (ExplosiveRegistry.get(explosiveID) instanceof Explosion) {
                    Explosion missile = (Explosion) ExplosiveRegistry.get(explosiveID);
                    ExplosivePreDetonationEvent evt = new ExplosivePreDetonationEvent(this.worldObj, this.xCoord, this.yCoord, this.zCoord, missile);
                    MinecraftForge.EVENT_BUS.post(evt);
                    if (!evt.isCanceled()) {
                        if (this.missile == null) {
                            Vector3 startingPosition = new Vector3((this.xCoord + 0.5f), (this.yCoord + 1.8f), (this.zCoord + 0.5f));
                            this.missile = new EnreplacedyMissile(this.worldObj, startingPosition, new Vector3(x(), y(), z()), explosiveID);
                            this.worldObj.spawnEnreplacedyInWorld((Enreplacedy) this.missile);
                            return;
                        } else {
                        // if (this.missile.getExplosiveType().getID() == explosiveID)
                        // {
                        // return;
                        // }
                        }
                    }
                }
            }
        }
        if (this.missile != null) {
            ((Enreplacedy) this.missile).setDead();
        }
        this.missile = null;
    }
}

18 View Complete Implementation : TileLauncherBase.java
Copyright MIT License
Author : BuiltBrokenModding
@Override
public ILauncherController getController() {
    for (byte i = 2; i < 6; i++) {
        Vector3 position = new Vector3(x(), y(), z()).add(ForgeDirection.getOrientation(i));
        TileEnreplacedy tileEnreplacedy = position.getTileEnreplacedy(this.worldObj);
        if (tileEnreplacedy instanceof ILauncherController) {
            return (ILauncherController) tileEnreplacedy;
        }
    }
    return null;
}

18 View Complete Implementation : BlastAntimatter.java
Copyright MIT License
Author : BuiltBrokenModding
@Override
public void doExplode() {
    if (!this.world().isRemote) {
        for (int x = (int) -this.getRadius(); x < this.getRadius(); x++) {
            for (int y = (int) -this.getRadius(); y < this.getRadius(); y++) {
                for (int z = (int) -this.getRadius(); z < this.getRadius(); z++) {
                    Vector3 targetPosition = this.position.clone().add(new Vector3(x, y, z));
                    double dist = position.distance(targetPosition);
                    if (dist < this.getRadius()) {
                        Block block = position.getBlock();
                        if (block != null && !block.isAir(this.world(), x, y, x)) {
                            if (!this.destroyBedrock && block.getBlockHardness(this.world(), x, y, x) < 0) {
                                continue;
                            }
                            if (dist < this.getRadius() - 1 || world().rand.nextFloat() > 0.7) {
                                targetPosition.setBlockToAir(world());
                            }
                        }
                    }
                }
            }
        }
    }
// TODO: Render antimatter shockwave
/*
         * else if (ZhuYao.proxy.isGaoQing()) { for (int x = -this.getRadius(); x <
         * this.getRadius(); x++) { for (int y = -this.getRadius(); y < this.getRadius(); y++) { for
         * (int z = -this.getRadius(); z < this.getRadius(); z++) { Vector3 targetPosition =
         * Vector3.add(position, new Vector3(x, y, z)); double distance =
         * position.distanceTo(targetPosition);
         * if (targetPosition.getBlockID(worldObj) == 0) { if (distance < this.getRadius() &&
         * distance > this.getRadius() - 1 && worldObj.rand.nextFloat() > 0.5) {
         * ParticleSpawner.spawnParticle("antimatter", worldObj, targetPosition); } } } } } }
         */
}

18 View Complete Implementation : TurretAI.java
Copyright MIT License
Author : BuiltBrokenModding
public boolean canEnreplacedyBeSeen(Vector3 traceStart, Enreplacedy enreplacedy) {
    // TODO set distance equal to max sentry gun range
    MovingObjectPosition hitTarget = traceStart.clone().rayTrace(enreplacedy.worldObj, new Vector3(enreplacedy), 500);
    return hitTarget != null && enreplacedy.equals(hitTarget.enreplacedyHit);
}

18 View Complete Implementation : BlastBreech.java
Copyright MIT License
Author : BuiltBrokenModding
@Override
public void doExplode() {
    if (!this.world().isRemote) {
        final Vector3 difference = new Vector3();
        if (this.exploder instanceof IRotatable) {
            difference.add(((IRotatable) this.exploder).getDirection());
        } else {
            difference.add(ForgeDirection.DOWN);
        }
        this.world().playSoundEffect(position.x(), position.y(), position.z(), "random.explode", 5.0F, (1.0F + (world().rand.nextFloat() - world().rand.nextFloat()) * 0.2F) * 0.7F);
        for (int i = 0; i < this.depth; i++) {
            if (position.getBlock(world()) != null) {
                if (position.getBlock(world()).getExplosionResistance(this.exploder, world(), position.xi(), position.yi(), position.zi(), position.x(), position.y(), position.z()) > Blocks.obsidian.getExplosionResistance(this.exploder)) {
                    break;
                }
            }
            super.doExplode();
            this.position.add(difference);
        }
    }
}

18 View Complete Implementation : BlastEndothermic.java
Copyright MIT License
Author : BuiltBrokenModding
@Override
public boolean canFocusBeam(World worldObj, Vector3 position) {
    long worldTime = worldObj.getWorldTime();
    while (worldTime > 23999) {
        worldTime -= 23999;
    }
    return worldTime > 12000 && super.canFocusBeam(worldObj, position);
}

18 View Complete Implementation : BlastExothermic.java
Copyright MIT License
Author : BuiltBrokenModding
@Override
public boolean canFocusBeam(World worldObj, Vector3 position) {
    long worldTime = worldObj.getWorldTime();
    while (worldTime > 23999) {
        worldTime -= 23999;
    }
    return worldTime < 12000 && !worldObj.isRaining() && super.canFocusBeam(worldObj, position);
}

18 View Complete Implementation : BlastNuclear.java
Copyright MIT License
Author : BuiltBrokenModding
@Override
public void doPreExplode() {
    if (!this.world().isRemote) {
        this.thread = new ThreadLargeExplosion(this.position, (int) this.getRadius(), this.energy, this.exploder);
        this.thread.start();
    } else if (this.spawnMoreParticles && ICBM.proxy.isGaoQing()) {
        // Spawn nuclear cloud.
        for (int y = 0; y < 26; y++) {
            int r = 4;
            if (y < 8) {
                r = Math.max(Math.min((8 - y) * 2, 10), 4);
            } else if (y > 15) {
                r = Math.max(Math.min((y - 15) * 2, 15), 5);
            }
            for (int x = -r; x < r; x++) {
                for (int z = -r; z < r; z++) {
                    double distance = MathHelper.sqrt_double(x * x + z * z);
                    if (r > distance && r - 3 < distance) {
                        Vector3 spawnPosition = position.add(new Vector3(x * 2, (y - 2) * 2, z * 2));
                        float xDiff = (float) (spawnPosition.x() - position.x());
                        float zDiff = (float) (spawnPosition.z() - position.z());
                        ICBM.proxy.spawnParticle("smoke", world(), spawnPosition, xDiff * 0.3 * world().rand.nextFloat(), -world().rand.nextFloat(), zDiff * 0.3 * world().rand.nextFloat(), (float) (distance / this.getRadius()) * world().rand.nextFloat(), 0, 0, 8F, 1.2F);
                    }
                }
            }
        }
    }
    this.doDamageEnreplacedies(this.getRadius(), this.energy * 1000);
    this.world().playSoundEffect(this.position.x(), this.position.y(), this.position.z(), Reference.PREFIX + "explosion", 7.0F, (1.0F + (this.world().rand.nextFloat() - this.world().rand.nextFloat()) * 0.2F) * 0.7F);
}

18 View Complete Implementation : BlastNuclear.java
Copyright MIT License
Author : BuiltBrokenModding
@Override
public void doExplode() {
    int r = this.callCount;
    if (this.world().isRemote) {
        if (ICBM.proxy.isGaoQing()) {
            for (int x = -r; x < r; x++) {
                for (int z = -r; z < r; z++) {
                    double distance = MathHelper.sqrt_double(x * x + z * z);
                    if (distance < r && distance > r - 1) {
                        Vector3 targetPosition = this.position.add(new Vector3(x, 0, z));
                        if (this.world().rand.nextFloat() < Math.max(0.001 * r, 0.05)) {
                            ICBM.proxy.spawnParticle("smoke", this.world(), targetPosition, 5F, 1F);
                        }
                    }
                }
            }
        }
    } else {
        if (this.thread != null) {
            if (this.thread.isComplete) {
                this.controller.endExplosion();
            }
        } else {
            this.controller.endExplosion();
            Reference.LOGGER.severe("Something went wrong with multi-threading while detonating the nuclear explosive.");
        }
    }
}

18 View Complete Implementation : BlastRepulsive.java
Copyright MIT License
Author : BuiltBrokenModding
@Override
public void doExplode() {
    if (!this.world().isRemote) {
        for (int x = 0; x < this.checkBanJing; ++x) {
            for (int y = 0; y < this.checkBanJing; ++y) {
                for (int z = 0; z < this.checkBanJing; ++z) {
                    if (x == 0 || x == this.checkBanJing - 1 || y == 0 || y == this.checkBanJing - 1 || z == 0 || z == this.checkBanJing - 1) {
                        double xStep = x / (this.checkBanJing - 1.0F) * 2.0F - 1.0F;
                        double yStep = y / (this.checkBanJing - 1.0F) * 2.0F - 1.0F;
                        double zStep = z / (this.checkBanJing - 1.0F) * 2.0F - 1.0F;
                        double diagonalDistance = Math.sqrt(xStep * xStep + yStep * yStep + zStep * zStep);
                        xStep /= diagonalDistance;
                        yStep /= diagonalDistance;
                        zStep /= diagonalDistance;
                        float var14 = this.getRadius() * (0.7F + this.world().rand.nextFloat() * 0.6F);
                        double var15 = this.position.x();
                        double var17 = this.position.y();
                        double var19 = this.position.z();
                        for (float var21 = 0.3F; var14 > 0.0F; var14 -= var21 * 0.75F) {
                            int var22 = MathHelper.floor_double(var15);
                            int var23 = MathHelper.floor_double(var17);
                            int var24 = MathHelper.floor_double(var19);
                            Block var25 = this.world().getBlock(var22, var23, var24);
                            if (var25 != null) {
                                var14 -= (var25.getExplosionResistance(this.exploder, this.world(), var22, var23, var24, this.position.xi(), this.position.yi(), this.position.zi()) + 0.3F) * var21;
                            }
                            if (var14 > 0.0F) {
                                blownBlocks.add(new Vector3(var22, var23, var24));
                            }
                            var15 += xStep * var21;
                            var17 += yStep * var21;
                            var19 += zStep * var21;
                        }
                    }
                }
            }
        }
    }
    this.world().playSoundEffect(this.position.x(), this.position.y(), this.position.z(), "random.explode", 4.0F, (1.0F + (this.world().rand.nextFloat() - this.world().rand.nextFloat()) * 0.2F) * 0.7F);
    switch(this.pushType) {
        case 0:
            this.doDamageEnreplacedies(this.getRadius(), nengLiang, this.destroyItem);
            break;
        default:
            this.pushEnreplacedies(12, this.getRadius() * 4, this.pushType);
            break;
    }
    if (!this.world().isRemote) {
        int var3;
        Vector3 blownPosition;
        int var5;
        int var6;
        int var7;
        Block blockID;
        int metadata;
        for (var3 = blownBlocks.size() - 1; var3 >= 0; --var3) {
            blownPosition = blownBlocks.get(var3);
            var5 = blownPosition.xi();
            var6 = blownPosition.yi();
            var7 = blownPosition.zi();
            blockID = this.world().getBlock(var5, var6, var7);
            metadata = this.world().getBlockMetadata(var5, var6, var7);
            double var9 = (var5 + this.world().rand.nextFloat());
            double var11 = (var6 + this.world().rand.nextFloat());
            double var13 = (var7 + this.world().rand.nextFloat());
            double var151 = var9 - this.position.y();
            double var171 = var11 - this.position.y();
            double var191 = var13 - this.position.z();
            double var211 = MathHelper.sqrt_double(var151 * var151 + var171 * var171 + var191 * var191);
            var151 /= var211;
            var171 /= var211;
            var191 /= var211;
            double var23 = 0.5D / (var211 / this.getRadius() + 0.1D);
            var23 *= (this.world().rand.nextFloat() * this.world().rand.nextFloat() + 0.3F);
            var151 *= var23;
            var171 *= var23;
            var191 *= var23;
            this.world().spawnParticle("explode", (var9 + this.position.x() * 1.0D) / 2.0D, (var11 + this.position.y() * 1.0D) / 2.0D, (var13 + this.position.z() * 1.0D) / 2.0D, var151, var171, var191);
            this.world().spawnParticle("smoke", var9, var11, var13, var151, var171, var191);
            if (blockID != null) {
                try {
                    Block block = blockID;
                    if (block.canDropFromExplosion(null)) {
                        block.dropBlockAsItemWithChance(this.world(), var5, var6, var7, this.world().getBlockMetadata(var5, var6, var7), 1F, 0);
                    }
                    block.onBlockExploded(this.world(), var5, var6, var7, this);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }
}

18 View Complete Implementation : ExSMine.java
Copyright MIT License
Author : BuiltBrokenModding
@Override
public void onYinZha(World worldObj, Vector3 position, int fuseTicks) {
}

18 View Complete Implementation : TurretAI.java
Copyright MIT License
Author : BuiltBrokenModding
/**
 * This update should only be called server side.
 */
public void update() {
    ticks++;
    if (turret() != null) {
        this.search_range = SentryTrait.asDouble(turret().getTrait(ITurret.SEARCH_RANGE_TRAIT), 10);
        // Only get new target if the current is missing or it will switch targets each update
        if (turret().getTarget() == null) {
            debug("\tSearching for target within " + search_range + " blocks");
            turret().setTarget(findTarget(turret(), turret().getEnreplacedySelector(), search_range));
        }
        // If we have a target start aiming logic
        if (turret().getTarget() != null && isValidTarget(turret().getTarget(), false)) {
            if (canEnreplacedyBeSeen(turret().getTarget())) {
                debug("\tTarget can be seen");
                if (isLookingAt(turret().getTarget(), 3)) {
                    if (turret().canFire()) {
                        debug("\tTarget locked and firing weapon");
                        turret().fire(turret().getTarget());
                    } else {
                        debug("\tTarget locked but weapon is not ready");
                    }
                } else {
                    debug("\tPowering servos to aim at target");
                    lookAtEnreplacedy(turret().getTarget());
                }
                targetLostTimer = 0;
            } else {
                debug("\tSight on target lost");
                // Drop the target after 2 seconds of no sight
                if (targetLostTimer >= 100) {
                    turret().setTarget(null);
                }
                targetLostTimer++;
            }
        } else {
            debug("\tInvalid or null target");
            // Only start random rotation after a second of no target
            if (targetLostTimer >= 20) {
                debug("\tTarget market as lost, resetting target");
                if (rotationDelayTimer >= 60) {
                    debug("\tNo Target Selected. Wandering.");
                    rotationDelayTimer = 0;
                    Vector3 location = new Vector3(this.turret().x(), this.turret().y(), this.turret().z());
                    location.add(new Vector3(this.turret().world().rand.nextInt(40) - 20, 0, this.turret().world().rand.nextInt(40) - 20));
                    lookAt(location);
                }
                turret().setTarget(null);
                rotationDelayTimer++;
            }
            targetLostTimer++;
        }
    }
}

17 View Complete Implementation : TileLauncherBase.java
Copyright MIT License
Author : BuiltBrokenModding
@Override
public boolean use(EnreplacedyPlayer player, int side, Vector3 hit) {
    if (player.inventory.getCurrenreplacedem() != null) {
        if (player.inventory.getCurrenreplacedem().gereplacedem() instanceof ItemMissile) {
            if (this.getStackInSlot(0) == null) {
                this.setInventorySlotContents(0, player.inventory.getCurrenreplacedem());
                if (!player.capabilities.isCreativeMode)
                    player.inventory.setInventorySlotContents(player.inventory.currenreplacedem, null);
                return true;
            } else {
                ItemStack player_held = player.inventory.getCurrenreplacedem();
                if (!player.capabilities.isCreativeMode)
                    player.inventory.setInventorySlotContents(player.inventory.currenreplacedem, this.getStackInSlot(0));
                this.setInventorySlotContents(0, player_held);
                return true;
            }
        }
    } else if (this.getStackInSlot(0) != null) {
        player.inventory.setInventorySlotContents(player.inventory.currenreplacedem, this.getStackInSlot(0));
        this.setInventorySlotContents(0, null);
        return true;
    }
    return true;
}

17 View Complete Implementation : BlastRepulsive.java
Copyright MIT License
Author : BuiltBrokenModding
public void pushEnreplacedies(float radius, float force, int type) {
    // Step 2: Damage all enreplacedies
    Vector3 minCoord = position.clone();
    minCoord.add(-radius - 1);
    Vector3 maxCoord = position.clone();
    maxCoord.add(radius + 1);
    Cuboid region = new Cuboid(minCoord, maxCoord);
    List<Enreplacedy> enreplacedies = region.getEnreplacedies(this.world(), Enreplacedy.clreplaced);
    for (Enreplacedy enreplacedy : enreplacedies) {
        double var13 = enreplacedy.getDistance(position.x(), position.y(), position.z()) / radius;
        if (var13 <= 1.0D) {
            double xDifference = enreplacedy.posX - position.x();
            double yDifference = enreplacedy.posY - position.y();
            double zDifference = enreplacedy.posZ - position.z();
            double distance = MathHelper.sqrt_double(xDifference * xDifference + yDifference * yDifference + zDifference * zDifference);
            xDifference /= distance;
            yDifference /= distance;
            zDifference /= distance;
            if (type == 1) {
                double modifier = var13 * force * (enreplacedy instanceof EnreplacedyPlayer ? 0.5 : 1);
                enreplacedy.addVelocity(-xDifference * modifier, -yDifference * modifier, -zDifference * modifier);
            } else if (type == 2) {
                double modifier = (1.0D - var13) * force * (enreplacedy instanceof EnreplacedyPlayer ? 0.5 : 1);
                enreplacedy.addVelocity(xDifference * modifier, yDifference * modifier, zDifference * modifier);
            }
        }
    }
}

17 View Complete Implementation : ThreadLargeExplosion.java
Copyright MIT License
Author : BuiltBrokenModding
@Override
public void run() {
    int steps = (int) Math.ceil(Math.PI / Math.atan(1.0D / this.radius));
    for (int phi_n = 0; phi_n < 2 * steps; phi_n++) {
        for (int theta_n = 0; theta_n < steps; theta_n++) {
            double phi = Math.PI * 2 / steps * phi_n;
            double theta = Math.PI / steps * theta_n;
            Vector3 delta = new Vector3(Math.sin(theta) * Math.cos(phi), Math.cos(theta), Math.sin(theta) * Math.sin(phi));
            float power = this.energy - (this.energy * this.position.world().rand.nextFloat() / 2);
            VectorWorld t = position.clone();
            for (float d = 0.3F; power > 0f; power -= d * 0.75F * 10) {
                if (t.distance(position) > this.radius)
                    break;
                Block block = t.getBlock();
                if (block != null) {
                    if (block.getBlockHardness(this.position.world(), t.xi(), t.yi(), t.zi()) >= 0) {
                        power -= this.callBack.getResistance(this.position.world(), position, t, source, block);
                        if (power > 0f) {
                            this.results.add(t.clone());
                        }
                    }
                }
                t.addEquals(delta);
            }
        }
    }
    super.run();
}

17 View Complete Implementation : TurretAI.java
Copyright MIT License
Author : BuiltBrokenModding
public boolean isTargetInBounds(Vector3 start, Vector3 target) {
    EulerAngle angle = start.toEulerAngle(target);
    return turret().getServo().isWithinLimit(angle);
}

17 View Complete Implementation : WeaponSystem.java
Copyright MIT License
Author : BuiltBrokenModding
/**
 * Modular system designed to handle all weapon related firing, and impact for an object. Requires
 * that it be constructed with a defined location. This location can be provided by using an enreplacedy,
 * tile, or world location.
 *
 * @author DarkGuardsman
 */
public abstract clreplaced WeaponSystem implements IWeaponSystem, IVectorWorld, IRotation {

    // Location of the weapon system
    private IVectorWorld host_vector = null;

    private Enreplacedy host_enreplacedy = null;

    private TileEnreplacedy host_tile = null;

    // Properties
    protected float rayTraceLimit = 100;

    protected int itemsConsumedPerShot = 0;

    public Vector3 aimOffset = new Vector3();

    protected IInventory inventory = null;

    public String soundEffect = null;

    public WeaponSystem(IVectorWorld pos) {
        this.host_vector = pos;
    }

    public WeaponSystem(TileEnreplacedy tile) {
        this.host_tile = tile;
    }

    public WeaponSystem(Enreplacedy enreplacedy) {
        this.host_enreplacedy = enreplacedy;
    }

    public void setHost(VectorWorld placement) {
        this.host_vector = placement;
    }

    public void setHost(TileEnreplacedy host) {
        this.host_tile = host;
    }

    public void setHost(Enreplacedy host) {
        this.host_enreplacedy = host;
    }

    @Override
    public World world() {
        if (host_enreplacedy != null)
            return host_enreplacedy.worldObj;
        else if (host_tile != null)
            return host_tile.getWorldObj();
        else
            return host_vector.world();
    }

    @Override
    public double x() {
        if (host_enreplacedy != null)
            return host_enreplacedy.posX;
        else if (host_tile != null)
            return host_tile.xCoord + 0.5;
        else
            return this.host_vector.x();
    }

    @Override
    public double y() {
        if (host_enreplacedy != null)
            return host_enreplacedy.posY;
        else if (host_tile != null)
            return host_tile.yCoord + 0.5;
        else
            return this.host_vector.y();
    }

    @Override
    public double z() {
        if (host_enreplacedy != null)
            return host_enreplacedy.posZ;
        else if (host_tile != null)
            return host_tile.zCoord + 0.5;
        else
            return this.host_vector.z();
    }

    @Override
    public double yaw() {
        if (turret() != null)
            return turret().yaw();
        else if (host_enreplacedy != null)
            return host_enreplacedy.rotationYaw;
        else
            return 0.0;
    }

    @Override
    public double pitch() {
        if (turret() != null)
            return turret().pitch();
        else if (host_enreplacedy != null)
            return host_enreplacedy.rotationPitch;
        else
            return 0.0;
    }

    @Override
    public double roll() {
        return 0.0;
    }

    @Override
    public void fire(double range) {
        fire(new Vector3(x(), y(), z()).add(turret().getWeaponOffset().multiply(range)));
    }

    @Override
    public void fire(IVector3 target) {
        playFiringAudio();
        doFire(target);
    }

    @Override
    public void fire(Enreplacedy enreplacedy) {
        fire(new Vector3(enreplacedy));
    }

    /**
     * Called to play the firing audio
     */
    protected void playFiringAudio() {
        boolean hreplacedilencer = turret().getUpgradeEffect(IUpgrade.SILENCER) > 0;
        if (this.soundEffect != null && !this.soundEffect.isEmpty()) {
            float pitch = 1F - (world().rand.nextFloat() * 0.2f);
            float volume = 4F;
            if (hreplacedilencer) {
                volume /= 10;
            }
            world().playSoundEffect(x(), y(), z(), this.soundEffect, volume, pitch);
        }
    }

    @Override
    public void fireClient(IVector3 hit) {
    }

    /**
     * Draws a particle stream towards a location.
     *
     * @author Based on MachineMuse
     */
    public void drawParticleStreamTo(World world, Vector3 start, IVector3 hit) {
        double scale = 0.02;
        Vector3 currentPoint = start.clone();
        Vector3 difference = new Vector3(hit).subtract(start);
        while (currentPoint.distance(new Vector3(hit)) > scale) {
            world.spawnParticle("townaura", currentPoint.x(), currentPoint.y(), currentPoint.z(), 0.0D, 0.0D, 0.0D);
            currentPoint.add(difference.clone().multiply(scale));
        }
    }

    /**
     * Gets the current end point for the barrel in the world
     */
    protected Vector3 getBarrelEnd() {
        if (turret() != null) {
            return new Vector3(x(), y(), z()).add(turret().getWeaponOffset());
        }
        return new Vector3(x(), y(), z()).add(this.aimOffset);
    }

    /**
     * Internal version of fire(Vector3) allowing repeat fire events
     */
    protected abstract void doFire(IVector3 target);

    /**
     * Called when the weapon hits an enreplacedy
     */
    protected abstract void onHitEnreplacedy(Enreplacedy enreplacedy);

    /**
     * Called when the weapon hits a block
     */
    protected abstract void onHitBlock(Vector3 block);

    @Override
    public boolean isAmmo(ItemStack stack) {
        return stack != null && stack.gereplacedem() instanceof IAmmunition && ((IAmmunition) stack.gereplacedem()).getType(stack) != ProjectileType.UNKNOWN;
    }

    @Override
    public boolean canFire() {
        return itemsConsumedPerShot <= 0 || consumeAmmo(itemsConsumedPerShot, false);
    }

    /**
     * Used to consume ammo or check if ammo can be consumed
     *
     * @param count - number of items to consume
     * @param doConsume - true items will be consumed
     * @return true if all rounds were consumed
     */
    public boolean consumeAmmo(int count, boolean doConsume) {
        int consumeCount = 0;
        int need = count;
        if (count > 0 && getAmmoBay() != null) {
            for (int slot = 0; slot < getAmmoBay().getSizeInventory(); slot++) {
                ItemStack itemStack = getAmmoBay().getStackInSlot(slot);
                if (isAmmo(itemStack)) {
                    int ammo_count = itemStack.stackSize;
                    if (itemStack.gereplacedem() instanceof IAmmunition)
                        ammo_count = ((IAmmunition) itemStack.gereplacedem()).getAmmoCount(itemStack);
                    if (ammo_count >= need) {
                        if (doConsume) {
                            getAmmoBay().setInventorySlotContents(slot, this.doConsumeAmmo(itemStack, need));
                        }
                        return true;
                    } else {
                        int consume = need - (need - ammo_count);
                        if (doConsume) {
                            getAmmoBay().setInventorySlotContents(slot, this.doConsumeAmmo(itemStack, consume));
                        }
                        need -= consume;
                    }
                    consumeCount += ammo_count;
                }
            }
        }
        return consumeCount >= count;
    }

    /**
     * Internal method for handle what happens when ammo is consumed
     *
     * @return ItemStack that goes back into the inventory after removing a few rounds of ammo from
     * it
     */
    protected ItemStack doConsumeAmmo(ItemStack stack, int sum) {
        if (stack != null && sum > 0) {
            if (!(stack.gereplacedem() instanceof IAmmunition)) {
                ItemStack splitStack = stack.splitStack(stack.stackSize - 1);
                if (stack != null && stack.stackSize > 0) {
                    return splitStack;
                }
            } else {
                IAmmunition ammo = (IAmmunition) stack.gereplacedem();
                ItemStack shell = ammo.getShell(stack, sum);
                ItemStack ammo_left = ammo.consumeAmmo(stack, sum);
                if (turret() != null && shell != null) {
                    if (turret().upgrades().containsKey(IUpgrade.SHELL_COLLECTOR))
                        shell = InventoryUtility.putStackInInventory(getAmmoBay(), shell, ForgeDirection.UNKNOWN.ordinal(), true);
                    if (shell != null)
                        InventoryUtility.dropItemStack(world(), x(), y(), z(), shell, 5, 0);
                }
                if (ammo_left != null && ammo_left.stackSize > 0) {
                    return ammo_left;
                }
                return null;
            }
        }
        return stack;
    }

    public ITurret turret() {
        if (asTurret(this.host_enreplacedy) != null) {
            return asTurret(this.host_enreplacedy);
        } else if (asTurret(this.host_tile) != null) {
            return asTurret(this.host_tile);
        } else if (asTurret(this.host_vector) != null) {
            return asTurret(this.host_vector);
        }
        return null;
    }

    public IInventory getAmmoBay() {
        if (this.inventory == null) {
            if (asInv(this.host_enreplacedy) != null) {
                this.inventory = asInv(this.host_enreplacedy);
            } else if (asInv(this.host_tile) != null) {
                this.inventory = asInv(this.host_tile);
            } else if (asInv(this.host_vector) != null) {
                this.inventory = asInv(this.host_vector);
            }
        }
        return this.inventory;
    }

    public ITurret asTurret(Object object) {
        if (object instanceof ITurret) {
            return (ITurret) object;
        } else if (object instanceof ITurretProvider) {
            return ((ITurretProvider) object).getTurret();
        } else if (object instanceof Enreplacedy) {
            return new EnreplacedyTurret((Enreplacedy) object);
        }
        return null;
    }

    public IInventory asInv(Object object) {
        if (object instanceof IInventory) {
            return (IInventory) object;
        }
        if (asTurret(object) != null) {
            if (asTurret(object).getHost() instanceof IInventory) {
                return (IInventory) asTurret(object).getHost();
            }
        }
        return null;
    }
}

16 View Complete Implementation : ItemRadarGun.java
Copyright MIT License
Author : BuiltBrokenModding
public void setLink(ItemStack itemStack, Vector3 position) {
    // Saves the frequency in the ItemStack
    if (itemStack.getTagCompound() == null) {
        itemStack.setTagCompound(new NBTTagCompound());
    }
    position.writeIntNBT(itemStack.getTagCompound());
}

16 View Complete Implementation : ItemRadarGun.java
Copyright MIT License
Author : BuiltBrokenModding
/**
 * Allows items to add custom lines of information to the mouseover description
 */
@Override
public void addInformation(ItemStack itemStack, EnreplacedyPlayer enreplacedyPlayer, List par3List, boolean par4) {
    Vector3 coord = getLink(itemStack);
    par3List.add("\uaa74" + LanguageUtility.getLocal("info.radarGun.savedCoords"));
    par3List.add(LanguageUtility.getLocal("gui.misc.x") + " " + (int) coord.x() + ", " + LanguageUtility.getLocal("gui.misc.y") + " " + (int) coord.y() + ", " + LanguageUtility.getLocal("gui.misc.z") + " " + (int) coord.z());
    par3List.add((int) new Vector3(enreplacedyPlayer).distance(coord) + " " + LanguageUtility.getLocal("info.radarGun.meters") + " (" + (int) (new Vector3(enreplacedyPlayer).x() - coord.x()) + ", " + (int) (new Vector3(enreplacedyPlayer).y() - coord.y()) + ", " + (int) (new Vector3(enreplacedyPlayer).z() - coord.z()) + ")");
    super.addInformation(itemStack, enreplacedyPlayer, par3List, par4);
}

16 View Complete Implementation : BlastBeam.java
Copyright MIT License
Author : BuiltBrokenModding
public boolean canFocusBeam(World worldObj, Vector3 position) {
    return worldObj.canBlockSeeTheSky(position.xi(), position.yi() + 1, position.zi());
}

16 View Complete Implementation : MissileHoming.java
Copyright MIT License
Author : BuiltBrokenModding
@Override
public boolean onInteract(EnreplacedyMissile missileObj, EnreplacedyPlayer enreplacedyPlayer) {
    if (!missileObj.worldObj.isRemote && missileObj.feiXingTick <= 0) {
        if (enreplacedyPlayer.getCurrentEquippedItem() != null) {
            if (enreplacedyPlayer.getCurrentEquippedItem().gereplacedem() instanceof IItemTracker) {
                Enreplacedy trackingEnreplacedy = ((IItemTracker) enreplacedyPlayer.getCurrentEquippedItem().gereplacedem()).getTrackingEnreplacedy(missileObj.worldObj, enreplacedyPlayer.getCurrentEquippedItem());
                if (trackingEnreplacedy != null) {
                    if (missileObj.trackingVar != trackingEnreplacedy.getEnreplacedyId()) {
                        missileObj.trackingVar = trackingEnreplacedy.getEnreplacedyId();
                        enreplacedyPlayer.addChatMessage(new ChatComponentText("Missile target locked to: " + trackingEnreplacedy.getEnreplacedyId()));
                        if (missileObj.getLauncher() != null && missileObj.getLauncher().getController() != null) {
                            Vector3 newTarget = new Vector3(trackingEnreplacedy);
                            newTarget.y_$eq(0);
                            missileObj.getLauncher().getController().setTarget(newTarget);
                        }
                        return true;
                    }
                }
            }
        }
    }
    return false;
}

15 View Complete Implementation : TileProximityDetector.java
Copyright MIT License
Author : BuiltBrokenModding
@Override
public boolean use(EnreplacedyPlayer player, int side, Vector3 hit) {
    if (!world().isRemote)
        player.openGui(ICBM.INSTANCE, 0, world(), hit.xi(), hit.yi(), hit.zi());
    return false;
}

15 View Complete Implementation : BlastFire.java
Copyright MIT License
Author : BuiltBrokenModding
@Override
public void doExplode() {
    if (!this.world().isRemote) {
        int radius = (int) this.getRadius();
        for (int x = 0; x < radius; ++x) {
            for (int y = 0; y < radius; ++y) {
                for (int z = 0; z < radius; ++z) {
                    if (x == 0 || x == radius - 1 || y == 0 || y == radius - 1 || z == 0 || z == radius - 1) {
                        double xStep = x / (radius - 1.0F) * 2.0F - 1.0F;
                        double yStep = y / (radius - 1.0F) * 2.0F - 1.0F;
                        double zStep = z / (radius - 1.0F) * 2.0F - 1.0F;
                        double diagonalDistance = Math.sqrt(xStep * xStep + yStep * yStep + zStep * zStep);
                        xStep /= diagonalDistance;
                        yStep /= diagonalDistance;
                        zStep /= diagonalDistance;
                        float var14 = radius * (0.7F + world().rand.nextFloat() * 0.6F);
                        double var15 = position.x();
                        double var17 = position.y();
                        double var19 = position.z();
                        for (float var21 = 0.3F; var14 > 0.0F; var14 -= var21 * 0.75F) {
                            Vector3 targetPosition = new Vector3(var15, var17, var19);
                            double distanceFromCenter = position.distance(targetPosition);
                            Block var25 = world().getBlock(targetPosition.xi(), targetPosition.yi(), targetPosition.zi());
                            if (var25 != null) {
                                var14 -= (var25.getExplosionResistance(this.exploder, world(), targetPosition.xi(), targetPosition.yi(), targetPosition.zi(), position.xi(), position.yi(), position.zi()) + 0.3F) * var21;
                            }
                            if (var14 > 0.0F) {
                                // Set fire by chance and distance
                                double chance = radius - (Math.random() * distanceFromCenter);
                                if (chance > distanceFromCenter * 0.55) {
                                    /*
                                         * Check to see if the block is an air block and there is a
                                         * block below it to support the fire.
                                         */
                                    Block blockID = world().getBlock((int) targetPosition.x(), (int) targetPosition.y(), (int) targetPosition.z());
                                    if ((blockID == null || blockID == Blocks.snow)) {
                                        world().setBlock((int) targetPosition.x(), (int) targetPosition.y(), (int) targetPosition.z(), Blocks.fire, 0, 2);
                                    } else if (blockID == Blocks.ice) {
                                        world().setBlockToAir(targetPosition.xi(), targetPosition.yi(), targetPosition.zi());
                                    }
                                }
                            }
                            var15 += xStep * var21;
                            var17 += yStep * var21;
                            var19 += zStep * var21;
                        }
                    }
                }
            }
        }
    }
    world().playSoundEffect(position.x() + 0.5D, position.y() + 0.5D, position.z() + 0.5D, Reference.PREFIX + "explosionfire", 4.0F, (1.0F + (world().rand.nextFloat() - world().rand.nextFloat()) * 0.2F) * 1F);
}

15 View Complete Implementation : BlastNuclear.java
Copyright MIT License
Author : BuiltBrokenModding
@Override
public void doPostExplode() {
    try {
        if (!this.world().isRemote && this.thread.isComplete) {
            for (Vector3 p : this.thread.results) {
                Block block = this.world().getBlock(p.xi(), p.yi(), p.zi());
                if (block != null)
                    block.onBlockExploded(this.world(), p.xi(), p.yi(), p.zi(), this);
            }
        }
    } catch (Exception e) {
        Reference.LOGGER.severe("Nuclear-type detonation Failed!");
        e.printStackTrace();
    }
    this.doDamageEnreplacedies(this.getRadius(), this.energy * 1000);
    if (this.isRadioactive) {
        new BlastRot(world(), this.exploder, position.x(), position.y(), position.z(), this.getRadius(), this.energy).explode();
        // new BlastMutation(world(), this.exploder, position.x(), position.y(), position.z(), this.getRadius()).explode();
        if (this.world().rand.nextInt(3) == 0) {
        // world().toggleRain();
        }
    }
    this.world().playSoundEffect(this.position.x(), this.position.y(), this.position.z(), Reference.PREFIX + "explosion", 10.0F, (1.0F + (this.world().rand.nextFloat() - this.world().rand.nextFloat()) * 0.2F) * 0.7F);
}

15 View Complete Implementation : BlastRot.java
Copyright MIT License
Author : BuiltBrokenModding
@Override
public void doExplode() {
    if (!this.world().isRemote) {
        if (this.thread.isComplete) {
            for (Vector3 targetPosition : this.thread.results) {
                /**
                 * Decay the blocks.
                 */
                Block blockID = targetPosition.getBlock(this.world());
                if (blockID != null) {
                    if (blockID == Blocks.grreplaced || blockID == Blocks.sand) {
                        if (this.world().rand.nextFloat() > 0.96) {
                            targetPosition.setBlock(this.world(), ICBM.blockRadioactive);
                        }
                    }
                    if (blockID == Blocks.stone) {
                        if (this.world().rand.nextFloat() > 0.99) {
                            targetPosition.setBlock(this.world(), ICBM.blockRadioactive);
                        }
                    } else if (blockID == Blocks.leaves) {
                        targetPosition.setBlock(this.world(), ICBM.blockRadioactive, 0);
                    } else if (blockID == Blocks.tallgrreplaced) {
                        if (Math.random() * 100 > 50) {
                            targetPosition.setBlock(this.world(), Blocks.cobblestone);
                        } else {
                            targetPosition.setBlock(this.world(), ICBM.blockRadioactive, 0);
                        }
                    } else if (blockID == Blocks.farmland) {
                        targetPosition.setBlock(this.world(), ICBM.blockRadioactive);
                    } else if (blockID == Blocks.water || blockID == Blocks.flowing_water) {
                        if (FluidRegistry.getFluid("toxicwaste") != null) {
                            targetPosition.setBlock(this.world(), FluidRegistry.getFluid("toxicwaste").getBlock());
                        }
                    }
                }
            }
            this.controller.endExplosion();
        }
    }
}

15 View Complete Implementation : Turret.java
Copyright MIT License
Author : BuiltBrokenModding
/**
 * Modular way to deal with sentry guns
 *
 * @author DarkGuardsman, tgame14
 */
public abstract clreplaced Turret implements IEnergyTurret, IWeaponProvider, IKillCount, ITurret {

    /**
     * Host of the sentry gun
     */
    private final ITurretProvider host;

    /**
     * Count of upgrades
     */
    private final HashMap<String, Double> upgrade_count = new HashMap<String, Double>();

    /**
     * Traits applied to the sentry
     */
    private final HashMap<String, ISentryTrait> traits = new HashMap<String, ISentryTrait>();

    /**
     * Count of kills
     */
    private final HashMap<String, Integer> kill_count = new HashMap<String, Integer>();

    /**
     * Turret Weapon system
     */
    protected WeaponSystem weaponSystem;

    /**
     * Offset from the center point were the barrel would be at zero rotation
     */
    protected Vector3 barrelOffset = new Vector3();

    /**
     * Offset from the host location were the center of the sentry's turret is located
     */
    protected Vector3 centerOffset = new Vector3();

    private int cooldown = 0;

    protected long ticks = 0;

    protected float barrelLength = 1;

    /**
     * Axis and rotation controller
     */
    private EulerServo servo;

    /**
     * Energy storage unit for the turret
     */
    public EnergyStorage battery;

    /**
     * AI for the sentry, defines how the sentry acts without a controller
     */
    private TurretAI ai;

    public Turret(ITurretProvider host) {
        this.host = host;
        this.ai = new TurretAI(this);
        this.battery = new EnergyStorage() {

            @Override
            public double getEnergyCapacity() {
                return SentryTrait.asDouble(Turret.this.getTrait(ITurret.ENERGY_STORAGE_TRAIT), this.capacity());
            }

            @Override
            public double getMaxReceive() {
                return this.getEnergyCapacity();
            }

            @Override
            public double getMaxExtract() {
                return this.getEnergyCapacity();
            }
        };
        newTrait(new SentryTraitLong(ITurret.ENERGY_STORAGE_TRAIT, IUpgrade.ENERGY_STORAGE, 100000));
        newTrait(new SentryTraitLong(ITurret.ENERGY_RUNNING_TRAIT, IUpgrade.ENERGY_EFFICIENCY, 10));
        newTrait(new SentryTraitDouble(ITurret.MAX_HEALTH_TRAIT, 50.0));
        newTrait(new SentryTraitDouble(ITurret.SEARCH_RANGE_TRAIT, IUpgrade.TARGET_RANGE, 20.0));
        newTrait(new SentryTraitDouble(ITurret.ROTATION_SPEED_TRAIT, 5.0));
        newTrait(new SentryTraitDouble(ITurret.ROTATION_SPEED_WITH_TARGET_TRAIT, 7.0));
        newTrait(new SentryTraitInteger(ITurret.AMMO_RELOAD_TIME_TRAIT, 20));
    }

    /**
     * Called directly after the sentry has loaded into the world & updated once
     */
    public void init() {
        this.onInventoryChanged();
        this.onSettingsChanged();
    }

    @Override
    public void update() {
        tick();
        if (cooldown > 0) {
            cooldown--;
        }
    }

    public void tick() {
        if (ticks == 0) {
            this.init();
        }
        ticks++;
        if (ticks >= Long.MAX_VALUE - 10) {
            ticks = 1;
        }
    }

    /**
     * Applies a trait to a sentry, prevents addition after first update
     */
    public void newTrait(ISentryTrait<?> value) {
        if (this.ticks == 0) {
            this.traits.put(value.getName(), value);
        }
    }

    /**
     * Sets the default value of a trait
     */
    public void setTrait(String value, Object data) {
        // System.out.println("Value: " + value + "  Data: " + data);
        if (this.ticks == 0) {
            if (data != null) {
                ISentryTrait<Object> trait = getTrait(value);
                // System.out.println("Before>Trait: " + trait.toString());
                if (trait != null) {
                    try {
                        trait.setDefaultValue(data);
                        trait.setValue(data);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            // System.out.println("After>Trait: " + trait.toString());
            }
        }
    }

    public boolean canFire() {
        boolean cooldown_flag = cooldown <= 0;
        boolean fire_flag = this.getWeaponSystem().canFire();
        if (this.getWeaponSystem() instanceof IEnergyWeapon) {
            if (battery.extractEnergy(((IEnergyWeapon) this.getWeaponSystem()).getEnergyPerShot(), false) < ((IEnergyWeapon) this.getWeaponSystem()).getEnergyPerShot()) {
                return false;
            }
        }
        return cooldown_flag && fire_flag;
    }

    @Override
    public boolean fire(IVector3 target) {
        if (getHost().world().isRemote) {
            this.getWeaponSystem().fireClient(target);
            return true;
        } else if (canFire()) {
            if (target != null) {
                getHost().sendFireEventToClient(target);
            }
            this.getWeaponSystem().fire(target);
            if (this.getWeaponSystem() instanceof IEnergyWeapon) {
                battery.extractEnergy(((IEnergyWeapon) this.getWeaponSystem()).getEnergyPerShot(), true);
            }
            cooldown = SentryTrait.asInt(getTrait(ITurret.AMMO_RELOAD_TIME_TRAIT), 13);
            return true;
        }
        return false;
    }

    @Override
    public boolean fire(Enreplacedy target) {
        if (getHost().world().isRemote) {
            this.getWeaponSystem().fireClient(new Vector3(target));
            return true;
        } else if (canFire()) {
            if (target != null) {
                getHost().sendFireEventToClient(new Vector3(target));
            }
            this.getWeaponSystem().fire(target);
            if (this.getWeaponSystem() instanceof IEnergyWeapon) {
                battery.extractEnergy(((IEnergyWeapon) this.getWeaponSystem()).getEnergyPerShot(), true);
            }
            cooldown = SentryTrait.asInt(getTrait(ITurret.AMMO_RELOAD_TIME_TRAIT), 10);
            return true;
        }
        return false;
    }

    @Override
    public Vector3 getWeaponOffset() {
        return getServo().toVector().multiply(barrelLength).add(barrelOffset);
    }

    /**
     * Offset from host location to were the sentries center is located
     */
    public Vector3 getCenterOffset() {
        return centerOffset.clone();
    }

    @Override
    public void setEnergy(ForgeDirection dir, double energy) {
        this.battery.setEnergy(energy);
    }

    @Override
    public double getEnergy(ForgeDirection dir) {
        return this.battery.getEnergy();
    }

    @Override
    public double getEnergyCapacity(ForgeDirection dir) {
        return this.battery.getEnergyCapacity();
    }

    @Override
    public void save(NBTTagCompound nbt) {
        nbt.setString(ITurret.SENTRY_TYPE_SAVE_ID, SaveManager.getID(this.getClreplaced()));
        if (this.battery != null) {
            this.battery.writeToNBT(nbt);
        }
        nbt.setDouble("yaw", getServo().yaw());
        nbt.setDouble("pitch", getServo().pitch());
        // Save kill counts
        NBTTagList killCounts = new NBTTagList();
        for (Entry<String, Integer> entry : this.kill_count.entrySet()) {
            if (entry.getKey() != null && !entry.getKey().isEmpty()) {
                NBTTagCompound accessData = new NBTTagCompound();
                accessData.setString("name", entry.getKey());
                accessData.setInteger("count", entry.getValue());
                killCounts.appendTag(accessData);
            }
        }
        nbt.setTag("killCount", killCounts);
    }

    @Override
    public void load(NBTTagCompound nbt) {
        if (this.battery != null) {
            this.battery.readFromNBT(nbt);
        }
        getServo().yaw_$eq(nbt.getDouble("yaw"));
        getServo().pitch_$eq(nbt.getDouble("pitch"));
        getServo().hasChanged = true;
        // Load kill count
        NBTTagList nodeList = nbt.getTagList("killCount", 0);
        kill_count.clear();
        for (int i = 0; i < nodeList.tagCount(); ++i) {
            NBTTagCompound tag = nodeList.getCompoundTagAt(i);
            kill_count.put(tag.getString("name"), tag.getInteger("count"));
        }
    }

    @Override
    public ITurretProvider getHost() {
        return host;
    }

    @Override
    public World world() {
        return getHost().world();
    }

    @Override
    public double x() {
        return getHost().x();
    }

    @Override
    public double y() {
        return getHost().y();
    }

    @Override
    public double z() {
        return getHost().z();
    }

    @Override
    public double yaw() {
        return getServo().yaw();
    }

    @Override
    public double pitch() {
        return getServo().pitch();
    }

    @Override
    public double roll() {
        return getServo().roll();
    }

    public VectorWorld getPosition() {
        return new VectorWorld(world(), x(), y(), z());
    }

    @Override
    public VectorWorld fromCenter() {
        return (VectorWorld) getPosition().add(getCenterOffset());
    }

    public EulerServo getServo() {
        if (servo == null) {
            servo = new EulerServo(5);
        }
        return servo;
    }

    @Override
    public String toString() {
        String id = TurretRegistry.getID(this);
        return "[Turret] ID: " + (id != null ? id : "unknown") + "   " + super.toString();
    }

    public TurretAI getAi() {
        return ai;
    }

    @Override
    public IWeaponSystem getWeaponSystem() {
        return this.weaponSystem;
    }

    @Override
    public void onSettingsChanged() {
    // TODO when GUI settings are implemented update sentry traits here
    // TODO when range settings are implemented confuse the sentry if max_limit range is set higher than AI max range.
    // Possible effect for confusion are targeting allies past he max range
    }

    @Override
    public void onInventoryChanged() {
        // TODO: change to only scan upgrade slots
        IInventory inv = this.getHost().getInventory();
        // Reset
        this.upgrade_count.clear();
        // Update upgrade count
        for (int slot = 0; slot < inv.getSizeInventory(); slot++) {
            if (inv.getStackInSlot(slot) != null && inv.getStackInSlot(slot).gereplacedem() instanceof IUpgrade && ((IUpgrade) inv.getStackInSlot(slot).gereplacedem()).canApplyTo(inv.getStackInSlot(slot), this)) {
                final List<String> id_list = new ArrayList<String>();
                ((IUpgrade) inv.getStackInSlot(slot).gereplacedem()).getTypes(id_list, inv.getStackInSlot(slot));
                for (String id : id_list) {
                    if (!this.upgrade_count.containsKey(id)) {
                        this.upgrade_count.put(id, 0.0D);
                    }
                    this.upgrade_count.put(id, this.upgrade_count.get(id) + ((IUpgrade) inv.getStackInSlot(slot).gereplacedem()).getUpgradeEfficiance(inv.getStackInSlot(slot), id));
                }
            }
        }
        // Update traits
        for (Entry<String, ISentryTrait> entry : this.traits().entrySet()) {
            if (entry.getValue() != null) {
                entry.getValue().updateTrait(this);
            }
        }
    }

    @Override
    public HashMap<String, Double> upgrades() {
        return this.upgrade_count;
    }

    @Override
    public double getUpgradeEffect(String upgrade) {
        if (this.upgrades().containsKey(upgrade)) {
            return this.upgrades().get(upgrade);
        }
        return 0.0;
    }

    @Override
    public HashMap<String, ISentryTrait> traits() {
        return this.traits;
    }

    @Override
    public ISentryTrait getTrait(String trait) {
        if (this.traits().containsKey(trait)) {
            return this.traits().get(trait);
        }
        return new SentryTraitDouble(trait, 0.0);
    }

    @Override
    public int getKillCount() {
        return getKillCount("Total");
    }

    @Override
    public int getKillCount(String type) {
        return kill_count.containsKey(type) ? kill_count.get(type) : 0;
    }

    @Override
    public void onKillOfEnreplacedy(Enreplacedy enreplacedy) {
        if (enreplacedy != null) {
            if (enreplacedy instanceof IMob) {
                increaseKill("Mobs");
            } else if (enreplacedy instanceof INpc) {
                increaseKill("NPCs");
            } else if (enreplacedy instanceof IAnimals) {
                increaseKill("Animals");
            } else if (enreplacedy instanceof EnreplacedyPlayer) {
                increaseKill("Players");
                increaseKill(((EnreplacedyPlayer) enreplacedy).getDisplayName());
            } else {
                increaseKill(EnreplacedyList.getEnreplacedyString(enreplacedy));
            }
            increaseKill("Total");
        }
    }

    /**
     * Increase the kill count
     */
    private void increaseKill(String type) {
        if (type != null && !type.isEmpty())
            kill_count.put(type, 1 + (kill_count.containsKey(type) ? kill_count.get(type) : 0));
    }

    @Override
    public long getRunningCost() {
        return SentryTrait.asLong(getTrait(ITurret.ENERGY_RUNNING_TRAIT), 0L);
    }
}

14 View Complete Implementation : ItemLaserDesignator.java
Copyright MIT License
Author : BuiltBrokenModding
/**
 * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack,
 * world, enreplacedyPlayer
 */
@Override
public ItemStack onItemRightClick(ItemStack par1ItemStack, World world, EnreplacedyPlayer player) {
    if (world.isRemote) {
        MovingObjectPosition objectMouseOver = player.rayTrace(BAN_JING * 2, 1);
        if (objectMouseOver != null && objectMouseOver.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) {
            Block block = world.getBlock(objectMouseOver.blockX, objectMouseOver.blockY, objectMouseOver.blockZ);
            int blockMetadata = world.getBlockMetadata(objectMouseOver.blockX, objectMouseOver.blockY, objectMouseOver.blockZ);
            if (this.getLauncherCountDown(par1ItemStack) > 0) {
                return par1ItemStack;
            }
            /*
                 * Prevents calling air strike if the user is trying to set the frequency of the
                 * remote.
                 */
            if (block == ICBM.blockMachine) {
                return par1ItemStack;
            } else {
                int airStrikeFreq = this.getFrequency(par1ItemStack);
                // Check if it is possible to do an air strike.
                if (airStrikeFreq > 0) {
                    if (this.getEnergy(par1ItemStack) >= energyCost) {
                        Vector3 position = new Vector3(player.posX, player.posY, player.posZ);
                        boolean doAirStrike = false;
                        int errorCount = 0;
                        for (IBlockFrequency blockFrequency : FrequencyGridRegistry.instance().getNodes(world, position, ItemLaserDesignator.BAN_JING, airStrikeFreq)) {
                            if (blockFrequency instanceof TileLauncherPrefab) {
                                // Do airstrike!
                                TileLauncherPrefab missileLauncher = (TileLauncherPrefab) blockFrequency;
                                double yHit = objectMouseOver.blockY;
                                if (missileLauncher instanceof TileLauncherScreen) {
                                    if (missileLauncher.getTarget() != null)
                                        yHit = missileLauncher.getTarget().y();
                                    else
                                        yHit = 0;
                                }
                                missileLauncher.setTarget(new Vector3(objectMouseOver.blockX, yHit, objectMouseOver.blockZ));
                                ResonantEngine.instance.packetHandler.sendToServer(new PacketTile(missileLauncher, 2, missileLauncher.getTarget().xi(), missileLauncher.getTarget().yi(), missileLauncher.getTarget().zi()));
                                if (missileLauncher.canLaunch()) {
                                    doAirStrike = true;
                                } else {
                                    errorCount++;
                                    player.addChatMessage(new ChatComponentText("#" + errorCount + " Missile Launcher Error: " + missileLauncher.getStatus()));
                                }
                            }
                        }
                        if (doAirStrike && this.getLauncherCountDown(par1ItemStack) >= 0) {
                            ResonantEngine.instance.packetHandler.sendToServer(new PacketPlayerItem(player, objectMouseOver.blockX, objectMouseOver.blockY, objectMouseOver.blockZ));
                            player.addChatMessage(new ChatComponentText(LanguageUtility.getLocal("message.designator.callBlast")));
                        }
                    } else {
                        player.addChatMessage(new ChatComponentText(LanguageUtility.getLocal("message.designator.nopower")));
                    }
                } else {
                    player.addChatMessage(new ChatComponentText(LanguageUtility.getLocal("message.designator.noFreq")));
                }
            }
        }
    }
    return par1ItemStack;
}