Search in sources :

Example 96 with ForgeDirection

use of net.minecraftforge.common.util.ForgeDirection in project PneumaticCraft by MineMaarten.

the class TileEntityLiquidHopper method exportItem.

@Override
protected boolean exportItem(int maxItems) {
    ForgeDirection dir = ForgeDirection.getOrientation(getBlockMetadata());
    if (tank.getFluid() != null) {
        TileEntity neighbor = IOHelper.getNeighbor(this, dir);
        if (neighbor instanceof IFluidHandler) {
            IFluidHandler fluidHandler = (IFluidHandler) neighbor;
            if (fluidHandler.canFill(dir.getOpposite(), tank.getFluid().getFluid())) {
                FluidStack fluid = tank.getFluid().copy();
                fluid.amount = Math.min(maxItems * 100, tank.getFluid().amount - (leaveMaterial ? 1000 : 0));
                if (fluid.amount > 0) {
                    tank.getFluid().amount -= fluidHandler.fill(dir.getOpposite(), fluid, true);
                    if (tank.getFluidAmount() <= 0)
                        tank.setFluid(null);
                    return true;
                }
            }
        }
    }
    if (worldObj.isAirBlock(xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ)) {
        for (EntityItem entity : getNeighborItems(this, dir)) {
            if (!entity.isDead) {
                List<ItemStack> returnedItems = new ArrayList<ItemStack>();
                if (FluidUtils.tryExtractingLiquid(this, entity.getEntityItem(), returnedItems)) {
                    if (entity.getEntityItem().stackSize <= 0)
                        entity.setDead();
                    for (ItemStack stack : returnedItems) {
                        EntityItem item = new EntityItem(worldObj, entity.posX, entity.posY, entity.posZ, stack);
                        item.motionX = entity.motionX;
                        item.motionY = entity.motionY;
                        item.motionZ = entity.motionZ;
                        worldObj.spawnEntityInWorld(item);
                    }
                    return true;
                }
            }
        }
    }
    if (getUpgrades(ItemMachineUpgrade.UPGRADE_DISPENSER_DAMAGE) > 0) {
        if (worldObj.isAirBlock(xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ)) {
            FluidStack extractedFluid = drain(ForgeDirection.UNKNOWN, 1000, false);
            if (extractedFluid != null && extractedFluid.amount == 1000) {
                Block fluidBlock = extractedFluid.getFluid().getBlock();
                if (fluidBlock != null) {
                    drain(ForgeDirection.UNKNOWN, 1000, true);
                    worldObj.setBlock(xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ, fluidBlock);
                }
            }
        }
    }
    return false;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) FluidStack(net.minecraftforge.fluids.FluidStack) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) ArrayList(java.util.ArrayList) Block(net.minecraft.block.Block) ItemStack(net.minecraft.item.ItemStack) IFluidHandler(net.minecraftforge.fluids.IFluidHandler) EntityItem(net.minecraft.entity.item.EntityItem)

Example 97 with ForgeDirection

use of net.minecraftforge.common.util.ForgeDirection in project PneumaticCraft by MineMaarten.

the class TileEntityPneumaticBase method updateEntity.

@Override
public void updateEntity() {
    // volume calculations
    if (!worldObj.isRemote && getUpgradeSlots() != null) {
        int upgradeVolume = getVolumeFromUpgrades(getUpgradeSlots());
        setVolume(DEFAULT_VOLUME + upgradeVolume);
        if (getUpgrades(ItemMachineUpgrade.UPGRADE_SECURITY, getUpgradeSlots()) > 0) {
            if (getPressure(ForgeDirection.UNKNOWN) >= DANGER_PRESSURE - 0.1) {
                airLeak(ForgeDirection.DOWN);
            }
            //Remove the remaining air if there is any still.
            int excessAir = getCurrentAir(ForgeDirection.UNKNOWN) - (int) (getVolume() * (DANGER_PRESSURE - 0.1));
            if (excessAir > 0) {
                addAir(-excessAir, ForgeDirection.DOWN);
                onAirDispersion(-excessAir, ForgeDirection.DOWN);
            }
        }
    }
    super.updateEntity();
    // getPressure());
    for (ForgeDirection pneumaticSide : ForgeDirection.values()) {
        if (!worldObj.isRemote && getPressure(pneumaticSide) > maxPressure) {
            worldObj.createExplosion(null, xCoord + 0.5D, yCoord + 0.5D, zCoord + 0.5D, 1.0F, true);
            worldObj.setBlockToAir(xCoord, yCoord, zCoord);
        }
    }
    if (!worldObj.isRemote)
        disperseAir();
    if (soundCounter > 0)
        soundCounter--;
}
Also used : ForgeDirection(net.minecraftforge.common.util.ForgeDirection)

Example 98 with ForgeDirection

use of net.minecraftforge.common.util.ForgeDirection in project PneumaticCraft by MineMaarten.

the class TileEntityUVLightBox method updateConnections.

public void updateConnections() {
    for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) {
        if (isConnectedTo(direction)) {
            boolean checkingLeft = ForgeDirection.getOrientation(getBlockMetadata()).getRotation(ForgeDirection.UP) == direction;
            TileEntity te = worldObj.getTileEntity(xCoord + direction.offsetX, yCoord + direction.offsetY, zCoord + direction.offsetZ);
            if (te instanceof IPneumaticMachine) {
                /*sidesConnected[direction.ordinal()]*/
                boolean isConnected = ((IPneumaticMachine) te).isConnectedTo(direction.getOpposite());
                if (checkingLeft)
                    leftConnected = isConnected;
                else
                    rightConnected = isConnected;
            } else {
                /*sidesConnected[direction.ordinal()]*/
                if (checkingLeft)
                    leftConnected = false;
                else
                    rightConnected = false;
            }
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IPneumaticMachine(pneumaticCraft.api.tileentity.IPneumaticMachine) ForgeDirection(net.minecraftforge.common.util.ForgeDirection)

Example 99 with ForgeDirection

use of net.minecraftforge.common.util.ForgeDirection in project PneumaticCraft by MineMaarten.

the class TileEntityCache method getDefaultCache.

public static TileEntityCache[] getDefaultCache(World world, int x, int y, int z) {
    TileEntityCache[] cache = new TileEntityCache[6];
    for (int i = 0; i < 6; i++) {
        ForgeDirection d = ForgeDirection.getOrientation(i);
        cache[i] = new TileEntityCache(world, x + d.offsetX, y + d.offsetY, z + d.offsetZ);
    }
    return cache;
}
Also used : ForgeDirection(net.minecraftforge.common.util.ForgeDirection)

Example 100 with ForgeDirection

use of net.minecraftforge.common.util.ForgeDirection in project Minechem by iopleke.

the class AugmentRedstone method onItemUse.

@Override
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ, int level) {
    ForgeDirection dir = ForgeDirection.getOrientation(side);
    x += dir.offsetX;
    y += dir.offsetY;
    z += dir.offsetZ;
    if (!world.isRemote && player != null && player.canPlayerEdit(x, y, z, side, null)) {
        if (world.isAirBlock(x, y, z)) {
            world.setBlock(x, y, z, BlockRegistry.blockRedstone, levels[level], 7);
        }
    }
    return false;
}
Also used : ForgeDirection(net.minecraftforge.common.util.ForgeDirection)

Aggregations

ForgeDirection (net.minecraftforge.common.util.ForgeDirection)242 TileEntity (net.minecraft.tileentity.TileEntity)80 ItemStack (net.minecraft.item.ItemStack)47 ArrayList (java.util.ArrayList)29 Block (net.minecraft.block.Block)28 DoubleCoordinates (network.rs485.logisticspipes.world.DoubleCoordinates)24 LogisticsTileGenericPipe (logisticspipes.pipes.basic.LogisticsTileGenericPipe)21 IInventory (net.minecraft.inventory.IInventory)19 FluidStack (net.minecraftforge.fluids.FluidStack)18 SideOnly (cpw.mods.fml.relauncher.SideOnly)17 CoreRoutedPipe (logisticspipes.pipes.basic.CoreRoutedPipe)17 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)17 IFluidHandler (net.minecraftforge.fluids.IFluidHandler)16 HashMap (java.util.HashMap)12 Pair (logisticspipes.utils.tuples.Pair)11 MovingObjectPosition (net.minecraft.util.MovingObjectPosition)10 World (net.minecraft.world.World)10 IRoutedItem (logisticspipes.logisticspipes.IRoutedItem)9 ItemIdentifier (logisticspipes.utils.item.ItemIdentifier)9 List (java.util.List)8