Search in sources :

Example 61 with TileEntity

use of net.minecraft.tileentity.TileEntity in project PneumaticCraft by MineMaarten.

the class BlockOmnidirectionalHopper method collisionRayTrace.

@Override
public MovingObjectPosition collisionRayTrace(World world, int x, int y, int z, Vec3 origin, Vec3 direction) {
    TileEntity te = world.getTileEntity(x, y, z);
    if (te instanceof TileEntityOmnidirectionalHopper) {
        ForgeDirection o = ((TileEntityOmnidirectionalHopper) te).getDirection();
        boolean isColliding = false;
        setBlockBounds(o.offsetX == 1 ? 10 / 16F : 0, o.offsetY == 1 ? 10 / 16F : 0, o.offsetZ == 1 ? 10 / 16F : 0, o.offsetX == -1 ? 6 / 16F : 1, o.offsetY == -1 ? 6 / 16F : 1, o.offsetZ == -1 ? 6 / 16F : 1);
        if (super.collisionRayTrace(world, x, y, z, origin, direction) != null)
            isColliding = true;
        setBlockBounds(4 / 16F, 4 / 16F, 4 / 16F, 12 / 16F, 12 / 16F, 12 / 16F);
        if (super.collisionRayTrace(world, x, y, z, origin, direction) != null)
            isColliding = true;
        setBlockBounds(0, 0, 0, 1, 1, 1);
        return isColliding ? super.collisionRayTrace(world, x, y, z, origin, direction) : null;
    }
    return null;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityOmnidirectionalHopper(pneumaticCraft.common.tileentity.TileEntityOmnidirectionalHopper) ForgeDirection(net.minecraftforge.common.util.ForgeDirection)

Example 62 with TileEntity

use of net.minecraft.tileentity.TileEntity in project PneumaticCraft by MineMaarten.

the class BlockPneumaticCraft method dropInventory.

protected void dropInventory(World world, int x, int y, int z) {
    TileEntity tileEntity = world.getTileEntity(x, y, z);
    if (!(tileEntity instanceof IInventory))
        return;
    IInventory inventory = (IInventory) tileEntity;
    Random rand = new Random();
    for (int i = getInventoryDropStartSlot(inventory); i < getInventoryDropEndSlot(inventory); i++) {
        ItemStack itemStack = inventory.getStackInSlot(i);
        if (itemStack != null && itemStack.stackSize > 0) {
            float dX = rand.nextFloat() * 0.8F + 0.1F;
            float dY = rand.nextFloat() * 0.8F + 0.1F;
            float dZ = rand.nextFloat() * 0.8F + 0.1F;
            EntityItem entityItem = new EntityItem(world, x + dX, y + dY, z + dZ, new ItemStack(itemStack.getItem(), itemStack.stackSize, itemStack.getItemDamage()));
            if (itemStack.hasTagCompound()) {
                entityItem.getEntityItem().setTagCompound((NBTTagCompound) itemStack.getTagCompound().copy());
            }
            float factor = 0.05F;
            entityItem.motionX = rand.nextGaussian() * factor;
            entityItem.motionY = rand.nextGaussian() * factor + 0.2F;
            entityItem.motionZ = rand.nextGaussian() * factor;
            world.spawnEntityInWorld(entityItem);
            itemStack.stackSize = 0;
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IInventory(net.minecraft.inventory.IInventory) Random(java.util.Random) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem)

Example 63 with TileEntity

use of net.minecraft.tileentity.TileEntity in project PneumaticCraft by MineMaarten.

the class BlockPneumaticCraft method rotateBlock.

@Override
public boolean rotateBlock(World world, EntityPlayer player, int x, int y, int z, ForgeDirection side) {
    if (player.isSneaking()) {
        if (!player.capabilities.isCreativeMode)
            dropBlockAsItem(world, x, y, z, world.getBlockMetadata(x, y, z), 0);
        world.setBlockToAir(x, y, z);
        return true;
    } else {
        if (isRotatable()) {
            int meta = world.getBlockMetadata(x, y, z);
            if (!rotateCustom(world, x, y, z, side, meta)) {
                int newMeta;
                if (rotateForgeWay()) {
                    if (!canRotateToTopOrBottom())
                        side = ForgeDirection.UP;
                    newMeta = ForgeDirection.getOrientation(meta).getRotation(side).ordinal();
                    world.setBlockMetadataWithNotify(x, y, z, newMeta, 3);
                } else {
                    newMeta = (meta + 1) % 6;
                    if (!canRotateToTopOrBottom()) {
                        if (newMeta == 0) {
                            newMeta = 2;
                        }
                    }
                }
                world.setBlockMetadataWithNotify(x, y, z, newMeta, 3);
            }
            TileEntity te = world.getTileEntity(x, y, z);
            if (te instanceof TileEntityBase) {
                ((TileEntityBase) te).onBlockRotated();
            }
            return true;
        } else {
            return false;
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityBase(pneumaticCraft.common.tileentity.TileEntityBase)

Example 64 with TileEntity

use of net.minecraft.tileentity.TileEntity in project PneumaticCraft by MineMaarten.

the class BlockPneumaticCraft method onBlockActivated.

@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int par6, float par7, float par8, float par9) {
    if (player.isSneaking() || getGuiID() == null || isRotatable() && player.getCurrentEquippedItem() != null && (player.getCurrentEquippedItem().getItem() == Itemss.manometer || ModInteractionUtils.getInstance().isModdedWrench(player.getCurrentEquippedItem().getItem())))
        return false;
    else {
        if (!world.isRemote) {
            TileEntity te = world.getTileEntity(x, y, z);
            List<ItemStack> returnedItems = new ArrayList<ItemStack>();
            if (te != null && !FluidUtils.tryInsertingLiquid(te, player.getCurrentEquippedItem(), player.capabilities.isCreativeMode, returnedItems)) {
                player.openGui(PneumaticCraft.instance, getGuiID().ordinal(), world, x, y, z);
            } else {
                if (player.getCurrentEquippedItem() != null && player.getCurrentEquippedItem().stackSize <= 0) {
                    player.setCurrentItemOrArmor(0, null);
                }
                for (ItemStack returnedItem : returnedItems) {
                    returnedItem = returnedItem.copy();
                    if (player.getCurrentEquippedItem() == null) {
                        player.setCurrentItemOrArmor(0, returnedItem);
                    } else {
                        player.inventory.addItemStackToInventory(returnedItem);
                    }
                }
            }
        }
        return true;
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack)

Example 65 with TileEntity

use of net.minecraft.tileentity.TileEntity in project PneumaticCraft by MineMaarten.

the class BlockPneumaticCraft method addInformation.

@SideOnly(Side.CLIENT)
public void addInformation(ItemStack stack, EntityPlayer player, List curInfo, boolean extraInfo) {
    if (PneumaticCraft.proxy.isSneakingInGui()) {
        TileEntity te = createNewTileEntity(player.worldObj, 0);
        if (te instanceof TileEntityPneumaticBase) {
            float pressure = ((TileEntityPneumaticBase) te).DANGER_PRESSURE;
            curInfo.add(EnumChatFormatting.YELLOW + I18n.format("gui.tooltip.maxPressure", pressure));
        }
    }
    String info = "gui.tab.info." + stack.getUnlocalizedName();
    String translatedInfo = I18n.format(info);
    if (!translatedInfo.equals(info)) {
        if (PneumaticCraft.proxy.isSneakingInGui()) {
            translatedInfo = EnumChatFormatting.AQUA + translatedInfo.substring(2);
            if (!Loader.isModLoaded(ModIds.IGWMOD))
                translatedInfo += " \\n \\n" + I18n.format("gui.tab.info.assistIGW");
            curInfo.addAll(PneumaticCraftUtils.convertStringIntoList(translatedInfo, 60));
        } else {
            curInfo.add(EnumChatFormatting.AQUA + I18n.format("gui.tooltip.sneakForInfo"));
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityPneumaticBase(pneumaticCraft.common.tileentity.TileEntityPneumaticBase) SideOnly(cpw.mods.fml.relauncher.SideOnly)

Aggregations

TileEntity (net.minecraft.tileentity.TileEntity)822 ItemStack (net.minecraft.item.ItemStack)149 BlockPos (net.minecraft.util.math.BlockPos)130 Block (net.minecraft.block.Block)83 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)76 EnumFacing (net.minecraft.util.EnumFacing)62 ArrayList (java.util.ArrayList)61 IBlockState (net.minecraft.block.state.IBlockState)61 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)57 IInventory (net.minecraft.inventory.IInventory)49 DoubleCoordinates (network.rs485.logisticspipes.world.DoubleCoordinates)44 World (net.minecraft.world.World)43 EntityItem (net.minecraft.entity.item.EntityItem)39 LogisticsTileGenericPipe (logisticspipes.pipes.basic.LogisticsTileGenericPipe)35 FluidStack (net.minecraftforge.fluids.FluidStack)29 EntityPlayer (net.minecraft.entity.player.EntityPlayer)28 HashMap (java.util.HashMap)25 IFluidHandler (net.minecraftforge.fluids.IFluidHandler)23 AMVector3 (am2.api.math.AMVector3)21 Entity (net.minecraft.entity.Entity)21