Search in sources :

Example 6 with Location

use of com.builtbroken.mc.imp.transform.vector.Location in project Engine by VoltzEngine-Project.

the class MultiBlockHelper method updateStructure.

/**
     * Runs a world update on all members of the structure
     *
     * @param world
     * @param host
     * @param offset - off set the location data by the center of the host
     */
public static void updateStructure(World world, IMultiTileHost host, boolean offset) {
    //TODO junit test
    if (!(host instanceof TileEntity)) {
        Engine.error("Tile host is not an instance of TileEntity");
    }
    if (world == null) {
        Engine.error("Tile host is not an instance of TileEntity");
    }
    HashMap<IPos3D, String> map = host.getLayoutOfMultiBlock();
    if (map != null && !map.isEmpty()) {
        int x = ((TileEntity) host).xCoord;
        int y = ((TileEntity) host).yCoord;
        int z = ((TileEntity) host).zCoord;
        Pos center = new Pos(x, y, z);
        for (Map.Entry<IPos3D, String> entry : map.entrySet()) {
            Location pos = new Location(world, entry.getKey());
            if (offset) {
                pos = pos.add(center);
            }
            pos.markForUpdate();
        }
        center.markForUpdate(world);
    } else {
        logger.error("Tile[" + host + "]'s structure map is empty");
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IPos3D(com.builtbroken.jlib.data.vector.IPos3D) Pos(com.builtbroken.mc.imp.transform.vector.Pos) HashMap(java.util.HashMap) Map(java.util.Map) Location(com.builtbroken.mc.imp.transform.vector.Location)

Example 7 with Location

use of com.builtbroken.mc.imp.transform.vector.Location in project ICBM-Classic by BuiltBrokenModding.

the class GuiMissileCoordinator method drawGuiContainerForegroundLayer.

/** Draw the foreground layer for the GuiContainer (everything in front of the items) */
@Override
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
    this.fontRendererObj.drawString("ยง7" + tileEntity.getInventoryName(), 48, 6, 4210752);
    this.fontRendererObj.drawString(LanguageUtility.getLocal("gui.coordinator.sim"), 50, 20, 4210752);
    this.fontRendererObj.drawString(LanguageUtility.getLocal("gui.coordinator.from"), 13, 30, 4210752);
    this.fontRendererObj.drawString(LanguageUtility.getLocal("gui.coordinator.to"), 134, 30, 4210752);
    if (this.tileEntity.getStackInSlot(0) != null && this.tileEntity.getStackInSlot(1) != null) {
        if (this.tileEntity.getStackInSlot(0).getItem() instanceof IWorldPosItem && this.tileEntity.getStackInSlot(1).getItem() instanceof IWorldPosItem) {
            Location pos1 = new Location((IWorldPosition) ((IWorldPosItem) this.tileEntity.getStackInSlot(0).getItem()).getLocation(this.tileEntity.getStackInSlot(0)));
            Location pos2 = new Location((IWorldPosition) ((IWorldPosItem) this.tileEntity.getStackInSlot(1).getItem()).getLocation(this.tileEntity.getStackInSlot(1)));
            double displacement = pos1.distance(pos2);
            this.fontRendererObj.drawString(LanguageUtility.getLocal("gui.coordinator.displace").replaceAll("%p", "" + UnitDisplay.roundDecimals(displacement)), 13, 65, 4210752);
            double w = pos1.toVector2().distance(pos2.toVector2());
            double h = 160 + (w * 3) - pos1.y();
            double distance = 0.5 * Math.sqrt(16 * (h * h) + (w * w)) + (((w * w) / (8 * h)) * (Math.log(4 * h + Math.sqrt(16 * (h * h) + (w * w))) - Math.log(w)));
            this.fontRendererObj.drawString(LanguageUtility.getLocal("gui.coordinator.arc").replaceAll("%p", "" + UnitDisplay.roundDecimals(distance)), 13, 75, 4210752);
            this.fontRendererObj.drawString(LanguageUtility.getLocal("gui.coordinator.time").replaceAll("%p", "" + UnitDisplay.roundDecimals(Math.max(100, 2 * displacement) / 20)), 13, 85, 4210752);
            Location delta = pos1.subtract(pos2);
            double rotation = MathHelper.wrapAngleTo180_double(Math.toDegrees(Math.atan2(delta.z(), delta.x()))) - 90;
            int heading = MathHelper.floor_double(rotation * 4.0F / 360.0F + 0.5D) & 3;
            this.fontRendererObj.drawString(LanguageUtility.getLocal("gui.coordinator.direction") + " " + UnitDisplay.roundDecimals(rotation) + " (" + Direction.directions[heading] + ")", 13, 95, 4210752);
        }
    }
    //this.fontRendererObj.drawString(LanguageUtility.getLocal("gui.coordinator.wip"), 13, 120, 4210752);
    super.drawGuiContainerForegroundLayer(mouseX, mouseY);
}
Also used : IWorldPosItem(com.builtbroken.mc.api.items.tools.IWorldPosItem) Location(com.builtbroken.mc.imp.transform.vector.Location)

Example 8 with Location

use of com.builtbroken.mc.imp.transform.vector.Location in project ICBM-Classic by BuiltBrokenModding.

the class ItemRadarGun method onItemUse.

@Override
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hit_x, float hit_y, float hit_z) {
    if (world.isRemote) {
        return true;
    }
    Location location = new Location(world, x, y, z);
    TileEntity tile = location.getTileEntity();
    if (tile instanceof IMultiTile) {
        IMultiTileHost host = ((IMultiTile) tile).getHost();
        if (host instanceof TileEntity) {
            tile = (TileEntity) host;
        }
    }
    if (player.isSneaking()) {
        stack.setTagCompound(null);
        stack.setItemDamage(0);
        LanguageUtility.addChatToPlayer(player, "gps.cleared");
        player.inventoryContainer.detectAndSendChanges();
        return true;
    } else {
        Location storedLocation = getLocation(stack);
        if (storedLocation == null || !storedLocation.isAboveBedrock()) {
            LanguageUtility.addChatToPlayer(player, "gps.error.pos.invalid");
            return true;
        } else if (tile instanceof ILauncherController) {
            ((ILauncherController) tile).setTarget(storedLocation.toPos());
            LanguageUtility.addChatToPlayer(player, "gps.data.transferred");
            return true;
        }
    }
    return false;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ILauncherController(resonant.api.explosion.ILauncherController) IMultiTile(com.builtbroken.mc.api.tile.multiblock.IMultiTile) IMultiTileHost(com.builtbroken.mc.api.tile.multiblock.IMultiTileHost) Location(com.builtbroken.mc.imp.transform.vector.Location)

Example 9 with Location

use of com.builtbroken.mc.imp.transform.vector.Location in project ICBM-Classic by BuiltBrokenModding.

the class BlastNuclear method doExplode.

@Override
public void doExplode() {
    int r = this.callCount;
    if (this.world().isRemote) {
        if (ICBMClassic.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) {
                        Location targetPosition = this.position.add(new Pos(x, 0, z));
                        if (this.world().rand.nextFloat() < Math.max(0.001 * r, 0.05)) {
                            ICBMClassic.proxy.spawnParticle("smoke", this.world(), targetPosition, 5F, 1F);
                        }
                    }
                }
            }
        }
    } else {
        if (this.thread != null) {
            if (this.thread.isComplete) {
                this.controller.endExplosion();
            }
        } else {
            this.controller.endExplosion();
            ICBMClassic.INSTANCE.logger().error("Something went wrong with multi-threading while detonating the nuclear explosive.");
        }
    }
}
Also used : Pos(com.builtbroken.mc.imp.transform.vector.Pos) Location(com.builtbroken.mc.imp.transform.vector.Location)

Example 10 with Location

use of com.builtbroken.mc.imp.transform.vector.Location in project ICBM-Classic by BuiltBrokenModding.

the class BlastRedmatter method affectEntity.

/**
     * Makes an entity get affected by Red Matter.
     *
     * @Return True if explosion happened
     */
public boolean affectEntity(float radius, Entity entity, boolean doExplosion) {
    //Ignore players that are in creative mode or can't be harmed
    if (entity instanceof EntityPlayer && (((EntityPlayer) entity).capabilities.isCreativeMode || ((EntityPlayer) entity).capabilities.disableDamage)) {
        return false;
    }
    //Ignore self
    if (entity == this.controller) {
        return false;
    }
    //Ignore entities that mark themselves are ignorable
    if (entity instanceof IExplosiveIgnore) {
        if (((IExplosiveIgnore) entity).canIgnore(this)) {
            return false;
        }
    }
    //Calculate different from center
    double xDifference = entity.posX - position.xi() + 0.5;
    double yDifference = entity.posY - position.yi() + 0.5;
    double zDifference = entity.posZ - position.zi() + 0.5;
    /** The percentage of the closeness of the entity. */
    double xPercentage = 1 - (xDifference / radius);
    double yPercentage = 1 - (yDifference / radius);
    double zPercentage = 1 - (zDifference / radius);
    double distancePercentage = this.position.distance(entity) / radius;
    Pos entityPosition = new Pos(entity);
    Pos centeredPosition = entityPosition.subtract(this.position);
    centeredPosition = (Pos) centeredPosition.transform(new EulerAngle(1.5 * distancePercentage * Math.random(), 1.5 * distancePercentage * Math.random(), 1.5 * distancePercentage * Math.random()));
    Location newPosition = this.position.add(centeredPosition);
    // Orbit Velocity
    entity.addVelocity(newPosition.x() - entityPosition.x(), 0, newPosition.z() - entityPosition.z());
    // Gravity Velocity (0.015 is barely enough to overcome y gravity so do not lower)
    entity.addVelocity(-xDifference * 0.015 * xPercentage, -yDifference * 0.015 * yPercentage, -zDifference * 0.015 * zPercentage);
    boolean explosionCreated = false;
    if (new Pos(entity.posX, entity.posY, entity.posZ).distance(position) < (ENTITY_DESTROY_RADIUS * (getRadius() / NORMAL_RADIUS))) {
        if (entity instanceof EntityExplosion) {
            if (((EntityExplosion) entity).getBlast() instanceof BlastAntimatter) {
                if (doAudio) {
                    this.world().playSoundEffect(position.x(), position.y(), position.z(), ICBMClassic.PREFIX + "explosion", 7.0F, (1.0F + (this.world().rand.nextFloat() - this.world().rand.nextFloat()) * 0.2F) * 0.7F);
                }
                if (this.world().rand.nextFloat() > 0.85 && !this.world().isRemote) {
                    entity.setDead();
                    return explosionCreated;
                }
            } else if (((EntityExplosion) entity).getBlast() instanceof BlastRedmatter) {
                //https://www.wolframalpha.com/input/?i=(4%2F3)pi+*+r%5E3+%3D+(4%2F3)pi+*+a%5E3+%2B+(4%2F3)pi+*+b%5E3
                //We are going to merge both blasts together
                double sizeA = this.getRadius();
                sizeA = sizeA * sizeA * sizeA;
                double sizeB = ((EntityExplosion) entity).getBlast().getRadius();
                sizeB = sizeB * sizeB * sizeB;
                float radiusNew = (float) Math.cbrt(sizeA + sizeB);
                //Average out timer
                this.callCount = (callCount + ((EntityExplosion) entity).getBlast().callCount) / 2;
                //Destroy current instance
                this.isAlive = false;
                this.controller.setDead();
                //Create new to avoid doing packet syncing
                new BlastRedmatter(world(), entity, position.x(), position.y(), position.z(), radiusNew).explode();
            }
            //Kill explosion entity
            ((EntityExplosion) entity).getBlast().isAlive = false;
            //Kill entity in the center of the ball
            entity.setDead();
        } else if (entity instanceof EntityExplosive) {
            ((EntityExplosive) entity).explode();
        } else if (entity instanceof EntityLiving) {
            ((EntityLiving) entity).attackEntityFrom(DamageSource.outOfWorld, 99999999);
        } else {
            //Kill entity in the center of the ball
            entity.setDead();
        }
    }
    return explosionCreated;
}
Also used : EntityLiving(net.minecraft.entity.EntityLiving) Pos(com.builtbroken.mc.imp.transform.vector.Pos) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EntityExplosion(icbm.classic.content.entity.EntityExplosion) EntityExplosive(icbm.classic.content.entity.EntityExplosive) EulerAngle(com.builtbroken.mc.imp.transform.rotation.EulerAngle) IExplosiveIgnore(resonant.api.explosion.IExplosiveIgnore) Location(com.builtbroken.mc.imp.transform.vector.Location)

Aggregations

Location (com.builtbroken.mc.imp.transform.vector.Location)30 Pos (com.builtbroken.mc.imp.transform.vector.Pos)11 Block (net.minecraft.block.Block)7 TileEntity (net.minecraft.tileentity.TileEntity)6 IPos3D (com.builtbroken.jlib.data.vector.IPos3D)5 HashMap (java.util.HashMap)5 IMultiTile (com.builtbroken.mc.api.tile.multiblock.IMultiTile)4 FakeWorld (com.builtbroken.mc.testing.junit.world.FakeWorld)4 ByteBuf (io.netty.buffer.ByteBuf)4 Map (java.util.Map)4 World (net.minecraft.world.World)4 IFluidBlock (net.minecraftforge.fluids.IFluidBlock)4 IPacketIDReceiver (com.builtbroken.mc.core.network.IPacketIDReceiver)3 IPacketReceiver (com.builtbroken.mc.core.network.IPacketReceiver)3 PacketIDException (com.builtbroken.mc.core.network.ex.PacketIDException)3 PacketTileReadException (com.builtbroken.mc.core.network.ex.PacketTileReadException)3 EntityFlyingBlock (icbm.classic.content.entity.EntityFlyingBlock)3 Entity (net.minecraft.entity.Entity)3 Test (org.junit.Test)3 AbstractTest (com.builtbroken.mc.testing.junit.AbstractTest)2