Search in sources :

Example 1 with ForgeDirection

use of net.minecraftforge.common.ForgeDirection in project MineFactoryReloaded by powercrystals.

the class MFRUtil method directionsWithoutConveyors.

public static ForgeDirection[] directionsWithoutConveyors(World world, int x, int y, int z) {
    ArrayList<ForgeDirection> nonConveyors = new ArrayList<ForgeDirection>();
    for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) {
        BlockPosition bp = new BlockPosition(x, y, z);
        bp.orientation = direction;
        bp.moveForwards(1);
        TileEntity te = world.getBlockTileEntity(bp.x, bp.y, bp.z);
        if (te == null || !(te instanceof TileEntityConveyor)) {
            nonConveyors.add(direction);
        }
    }
    return nonConveyors.toArray(new ForgeDirection[nonConveyors.size()]);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityConveyor(powercrystals.minefactoryreloaded.tile.conveyor.TileEntityConveyor) BlockPosition(powercrystals.core.position.BlockPosition) ArrayList(java.util.ArrayList) ForgeDirection(net.minecraftforge.common.ForgeDirection)

Example 2 with ForgeDirection

use of net.minecraftforge.common.ForgeDirection in project MineFactoryReloaded by powercrystals.

the class BlockRailCargoPickup method onEntityCollidedWithBlock.

@Override
public void onEntityCollidedWithBlock(World world, int x, int y, int z, Entity entity) {
    if (world.isRemote || !(entity instanceof EntityMinecartContainer)) {
        return;
    }
    IInventoryManager minecart = InventoryManager.create((EntityMinecartContainer) entity, ForgeDirection.UNKNOWN);
    for (Entry<ForgeDirection, IInventory> inventory : UtilInventory.findChests(world, x, y, z).entrySet()) {
        IInventoryManager chest = InventoryManager.create(inventory.getValue(), inventory.getKey().getOpposite());
        for (Entry<Integer, ItemStack> contents : chest.getContents().entrySet()) {
            if (contents.getValue() == null) {
                continue;
            }
            ItemStack stackToAdd = contents.getValue().copy();
            ItemStack remaining = minecart.addItem(stackToAdd);
            if (remaining != null) {
                stackToAdd.stackSize -= remaining.stackSize;
                if (stackToAdd.stackSize > 0) {
                    chest.removeItem(stackToAdd.stackSize, stackToAdd);
                }
            } else {
                chest.removeItem(stackToAdd.stackSize, stackToAdd);
                break;
            }
        }
    }
}
Also used : IInventory(net.minecraft.inventory.IInventory) EntityMinecartContainer(net.minecraft.entity.item.EntityMinecartContainer) ForgeDirection(net.minecraftforge.common.ForgeDirection) ItemStack(net.minecraft.item.ItemStack) IInventoryManager(powercrystals.core.inventory.IInventoryManager)

Example 3 with ForgeDirection

use of net.minecraftforge.common.ForgeDirection in project MineFactoryReloaded by powercrystals.

the class BlockRedNetCable method breakBlock.

@Override
public void breakBlock(World world, int x, int y, int z, int id, int meta) {
    TileEntity te = world.getBlockTileEntity(x, y, z);
    if (te instanceof TileEntityRedNetCable && ((TileEntityRedNetCable) te).getNetwork() != null) {
        ((TileEntityRedNetCable) te).getNetwork().setInvalid();
    }
    for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) {
        BlockPosition bp = new BlockPosition(x, y, z);
        bp.orientation = d;
        bp.moveForwards(1);
        world.notifyBlockOfNeighborChange(bp.x, bp.y, bp.z, MineFactoryReloadedCore.rednetCableBlock.blockID);
        world.notifyBlocksOfNeighborChange(bp.x, bp.y, bp.z, MineFactoryReloadedCore.rednetCableBlock.blockID);
    }
    super.breakBlock(world, x, y, z, id, meta);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) BlockPosition(powercrystals.core.position.BlockPosition) TileEntityRedNetCable(powercrystals.minefactoryreloaded.tile.rednet.TileEntityRedNetCable) ForgeDirection(net.minecraftforge.common.ForgeDirection)

Aggregations

ForgeDirection (net.minecraftforge.common.ForgeDirection)3 TileEntity (net.minecraft.tileentity.TileEntity)2 BlockPosition (powercrystals.core.position.BlockPosition)2 ArrayList (java.util.ArrayList)1 EntityMinecartContainer (net.minecraft.entity.item.EntityMinecartContainer)1 IInventory (net.minecraft.inventory.IInventory)1 ItemStack (net.minecraft.item.ItemStack)1 IInventoryManager (powercrystals.core.inventory.IInventoryManager)1 TileEntityConveyor (powercrystals.minefactoryreloaded.tile.conveyor.TileEntityConveyor)1 TileEntityRedNetCable (powercrystals.minefactoryreloaded.tile.rednet.TileEntityRedNetCable)1