Search in sources :

Example 1 with IWorldPosition

use of com.builtbroken.mc.api.IWorldPosition in project Engine by VoltzEngine-Project.

the class MultiBlockHelper method destroyMultiBlockStructure.

/**
     * Breaks down the multiblock stucture linked to the host
     *
     * @param host     - host providing the layour of the structure
     * @param doDrops  - attempt to drop blocks?
     * @param offset   - offset the layout by the location of the host?
     * @param killHost - destroy the host block as well?
     */
public static void destroyMultiBlockStructure(IMultiTileHost host, boolean doDrops, boolean offset, boolean killHost) {
    if (host != null) {
        HashMap<IPos3D, String> map = host.getLayoutOfMultiBlock();
        if (map != null && !map.isEmpty()) {
            IWorldPosition center;
            if (host instanceof TileEntity) {
                center = new Location((TileEntity) host);
            } else if (host instanceof IWorldPosition) {
                center = (IWorldPosition) host;
            } else {
                logger.error("MultiBlockHelper >> Tile[" + host + "]'s is not a TileEntity or IWorldPosition instance, thus we can not get a position to break down the structure.");
                return;
            }
            for (Map.Entry<IPos3D, String> entry : map.entrySet()) {
                Pos pos = entry.getKey() instanceof Pos ? (Pos) entry.getKey() : new Pos(entry.getKey());
                if (offset) {
                    pos = pos.add(center);
                }
                TileEntity tile = pos.getTileEntity(center.world());
                if (tile instanceof IMultiTile) {
                    ((IMultiTile) tile).setHost(null);
                    pos.setBlockToAir(center.world());
                }
            }
            if (doDrops) {
                InventoryUtility.dropBlockAsItem(center, killHost);
            } else if (killHost) {
                center.world().setBlockToAir(center.xi(), center.yi(), center.zi());
            }
        } else {
            logger.error("MultiBlockHelper >> 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) IWorldPosition(com.builtbroken.mc.api.IWorldPosition) IMultiTile(com.builtbroken.mc.api.tile.multiblock.IMultiTile) HashMap(java.util.HashMap) Map(java.util.Map) Location(com.builtbroken.mc.imp.transform.vector.Location)

Example 2 with IWorldPosition

use of com.builtbroken.mc.api.IWorldPosition in project ICBM-Classic by BuiltBrokenModding.

the class TileLauncherScreen method onPlayerActivated.

@Override
public boolean onPlayerActivated(EntityPlayer player, int side, Pos hit) {
    if (isServer()) {
        boolean notNull = player.getHeldItem() != null;
        if (notNull && player.getHeldItem().getItem() == Items.redstone) {
            if (canLaunch()) {
                launch();
            } else {
                player.addChatComponentMessage(new ChatComponentText(LanguageUtility.getLocal("chat.launcher.failedToFire")));
                String translation = LanguageUtility.getLocal("chat.launcher.status");
                translation = translation.replace("%1", getStatus());
                player.addChatComponentMessage(new ChatComponentText(translation));
            }
        } else if (notNull && player.getHeldItem().getItem() instanceof ItemRemoteDetonator) {
            ((ItemRemoteDetonator) player.getHeldItem().getItem()).setBroadCastHz(player.getHeldItem(), getFrequency());
            player.addChatComponentMessage(new ChatComponentText(LanguageUtility.getLocal("chat.launcher.toolFrequencySet").replace("%1", "" + getFrequency())));
        } else if (notNull && player.getHeldItem().getItem() instanceof IWorldPosItem) {
            IWorldPosition location = ((IWorldPosItem) player.getHeldItem().getItem()).getLocation(player.getHeldItem());
            if (location != null) {
                if (location.world() == world()) {
                    setTarget(new Pos(location.x(), location.y(), location.z()));
                    player.addChatComponentMessage(new ChatComponentText(LanguageUtility.getLocal("chat.launcher.toolTargetSet")));
                } else {
                    player.addChatComponentMessage(new ChatComponentText(LanguageUtility.getLocal("chat.launcher.toolWorldNotMatch")));
                }
            } else {
                player.addChatComponentMessage(new ChatComponentText(LanguageUtility.getLocal("chat.launcher.noTargetInTool")));
            }
        } else {
            player.openGui(ICBMClassic.INSTANCE, 0, this.worldObj, this.xCoord, this.yCoord, this.zCoord);
        }
    }
    return true;
}
Also used : Pos(com.builtbroken.mc.imp.transform.vector.Pos) IWorldPosition(com.builtbroken.mc.api.IWorldPosition) IWorldPosItem(com.builtbroken.mc.api.items.tools.IWorldPosItem) ChatComponentText(net.minecraft.util.ChatComponentText) ItemRemoteDetonator(icbm.classic.content.items.ItemRemoteDetonator)

Example 3 with IWorldPosition

use of com.builtbroken.mc.api.IWorldPosition in project Engine by VoltzEngine-Project.

the class TestAbstractLocation method testInit.

/**
 * Tests constructors
 */
public void testInit() {
    List<TLocation> locations = new ArrayList();
    // Test main method
    locations.add(new TLocation(world, 10, 11, 12));
    // Test entity method
    Entity entity = new EntitySheep(world);
    entity.setPosition(10, 11, 12);
    locations.add(new TLocation(entity));
    // Test tile
    TileEntity tile = new TileEntity();
    tile.setWorldObj(world);
    tile.xCoord = 10;
    tile.yCoord = 11;
    tile.zCoord = 12;
    locations.add(new TLocation(tile));
    // Test NBT method
    NBTTagCompound tag = new NBTTagCompound();
    tag.setInteger("dimension", world.provider.dimensionId);
    tag.setDouble("x", 10);
    tag.setDouble("y", 11);
    tag.setDouble("z", 12);
    locations.add(new TLocation(tag));
    // Test byte buf method
    ByteBuf buf = Unpooled.buffer();
    buf.writeInt(world.provider.dimensionId);
    buf.writeDouble(10);
    buf.writeDouble(11);
    buf.writeDouble(12);
    locations.add(new TLocation(buf));
    // Test IWorldPosition
    locations.add(new TLocation(new IWorldPosition() {

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

        @Override
        public double x() {
            return 10;
        }

        @Override
        public double y() {
            return 11;
        }

        @Override
        public double z() {
            return 12;
        }
    }));
    // Test world, IPos3D
    locations.add(new TLocation(world, new IPos3D() {

        @Override
        public double x() {
            return 10;
        }

        @Override
        public double y() {
            return 11;
        }

        @Override
        public double z() {
            return 12;
        }
    }));
    // Test world, vec3
    locations.add(new TLocation(world, Vec3.createVectorHelper(10, 11, 12)));
    // Test world, moving object
    locations.add(new TLocation(world, new MovingObjectPosition(10, 11, 12, 0, Vec3.createVectorHelper(10, 11, 12))));
    for (int i = 0; i < locations.size(); i++) {
        TLocation location = locations.get(i);
        assertTrue("" + i, location.world == world);
        assertTrue("" + i, location.xi() == 10);
        assertTrue("" + i, location.yi() == 11);
        assertTrue("" + i, location.zi() == 12);
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) Entity(net.minecraft.entity.Entity) TileEntity(net.minecraft.tileentity.TileEntity) IPos3D(com.builtbroken.jlib.data.vector.IPos3D) MovingObjectPosition(net.minecraft.util.MovingObjectPosition) ArrayList(java.util.ArrayList) EntitySheep(net.minecraft.entity.passive.EntitySheep) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IWorldPosition(com.builtbroken.mc.api.IWorldPosition) ByteBuf(io.netty.buffer.ByteBuf)

Example 4 with IWorldPosition

use of com.builtbroken.mc.api.IWorldPosition in project ICBM-Classic by BuiltBrokenModding.

the class TileCruiseLauncher method onPlayerActivated.

@Override
public boolean onPlayerActivated(EntityPlayer player, int side, Pos hit) {
    if (isServer()) {
        boolean notNull = player.getHeldItem() != null;
        if (notNull && player.getHeldItem().getItem() == Items.redstone) {
            if (canLaunch()) {
                launch();
            } else {
                player.addChatComponentMessage(new ChatComponentText(LanguageUtility.getLocal("chat.launcher.failedToFire")));
                String translation = LanguageUtility.getLocal("chat.launcher.status");
                translation = translation.replace("%1", getStatus());
                player.addChatComponentMessage(new ChatComponentText(translation));
            }
        } else if (notNull && player.getHeldItem().getItem() instanceof IWorldPosItem) {
            IWorldPosition location = ((IWorldPosItem) player.getHeldItem().getItem()).getLocation(player.getHeldItem());
            if (location != null) {
                if (location.world() == world()) {
                    setTarget(new Pos(location.x(), location.y(), location.z()));
                    player.addChatComponentMessage(new ChatComponentText(LanguageUtility.getLocal("chat.launcher.toolTargetSet")));
                } else {
                    player.addChatComponentMessage(new ChatComponentText(LanguageUtility.getLocal("chat.launcher.toolWorldNotMatch")));
                }
            } else {
                player.addChatComponentMessage(new ChatComponentText(LanguageUtility.getLocal("chat.launcher.noTargetInTool")));
            }
        } else {
            player.openGui(ICBMClassic.INSTANCE, 0, this.worldObj, this.xCoord, this.yCoord, this.zCoord);
        }
    }
    return true;
}
Also used : Pos(com.builtbroken.mc.imp.transform.vector.Pos) IWorldPosition(com.builtbroken.mc.api.IWorldPosition) IWorldPosItem(com.builtbroken.mc.api.items.tools.IWorldPosItem) ChatComponentText(net.minecraft.util.ChatComponentText)

Aggregations

IWorldPosition (com.builtbroken.mc.api.IWorldPosition)4 Pos (com.builtbroken.mc.imp.transform.vector.Pos)3 IPos3D (com.builtbroken.jlib.data.vector.IPos3D)2 IWorldPosItem (com.builtbroken.mc.api.items.tools.IWorldPosItem)2 TileEntity (net.minecraft.tileentity.TileEntity)2 ChatComponentText (net.minecraft.util.ChatComponentText)2 IMultiTile (com.builtbroken.mc.api.tile.multiblock.IMultiTile)1 Location (com.builtbroken.mc.imp.transform.vector.Location)1 ItemRemoteDetonator (icbm.classic.content.items.ItemRemoteDetonator)1 ByteBuf (io.netty.buffer.ByteBuf)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Entity (net.minecraft.entity.Entity)1 EntitySheep (net.minecraft.entity.passive.EntitySheep)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 MovingObjectPosition (net.minecraft.util.MovingObjectPosition)1