Search in sources :

Example 1 with ITileStructure

use of forestry.api.core.ITileStructure in project ForestryMC by ForestryMC.

the class Utils method dropInventory.

public static void dropInventory(TileForestry tile, World world, int x, int y, int z) {
    if (tile == null) {
        return;
    }
    // Release inventory
    if (tile instanceof ITileStructure) {
        IInventory inventory = ((ITileStructure) tile).getInventory();
        if (inventory != null) {
            for (int i = 0; i < inventory.getSizeInventory(); i++) {
                if (inventory.getStackInSlot(i) == null) {
                    continue;
                }
                StackUtils.dropItemStackAsEntity(inventory.getStackInSlot(i), world, x, y, z);
                inventory.setInventorySlotContents(i, null);
            }
        }
    } else {
        for (int slot = 0; slot < tile.getSizeInventory(); slot++) {
            ItemStack itemstack = tile.getStackInSlot(slot);
            if (itemstack == null) {
                continue;
            }
            float f = world.rand.nextFloat() * 0.8F + 0.1F;
            float f1 = world.rand.nextFloat() * 0.8F + 0.1F;
            float f2 = world.rand.nextFloat() * 0.8F + 0.1F;
            while (itemstack.stackSize > 0) {
                int stackPartial = world.rand.nextInt(21) + 10;
                if (stackPartial > itemstack.stackSize) {
                    stackPartial = itemstack.stackSize;
                }
                ItemStack drop = itemstack.splitStack(stackPartial);
                EntityItem entityitem = new EntityItem(world, x + f, y + f1, z + f2, drop);
                float accel = 0.05F;
                entityitem.motionX = (float) world.rand.nextGaussian() * accel;
                entityitem.motionY = (float) world.rand.nextGaussian() * accel + 0.2F;
                entityitem.motionZ = (float) world.rand.nextGaussian() * accel;
                world.spawnEntityInWorld(entityitem);
            }
            tile.setInventorySlotContents(slot, null);
        }
    }
}
Also used : IInventory(net.minecraft.inventory.IInventory) ITileStructure(forestry.api.core.ITileStructure) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem)

Example 2 with ITileStructure

use of forestry.api.core.ITileStructure in project ForestryMC by ForestryMC.

the class BlockStructure method breakBlock.

@Override
public void breakBlock(World world, int x, int y, int z, Block block, int meta) {
    TileEntity tile = world.getTileEntity(x, y, z);
    super.breakBlock(world, x, y, z, block, meta);
    if (tile instanceof ITileStructure) {
        ITileStructure structure = (ITileStructure) tile;
        if (structure.isIntegratedIntoStructure() && !structure.isMaster()) {
            ITileStructure central = structure.getCentralTE();
            if (central != null) {
                central.validateStructure();
            }
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ITileStructure(forestry.api.core.ITileStructure)

Example 3 with ITileStructure

use of forestry.api.core.ITileStructure in project ForestryMC by ForestryMC.

the class StructureLogic method markStructureBlocks.

protected void markStructureBlocks(Schemata schemata) {
    Vect dimensions = schemata.getDimensions(isRotated);
    int offsetX = schemata.getxOffset();
    int offsetZ = schemata.getzOffset();
    if (isRotated) {
        offsetX = schemata.getzOffset();
        offsetZ = schemata.getxOffset();
    }
    for (int i = 0; i < dimensions.x; i++) {
        for (int j = 0; j < schemata.getHeight(); j++) {
            for (int k = 0; k < dimensions.z; k++) {
                int x = structureTile.xCoord + i + offsetX;
                int y = structureTile.yCoord + j + schemata.getyOffset();
                int z = structureTile.zCoord + k + offsetZ;
                TileEntity tile = structureTile.getWorldObj().getTileEntity(x, y, z);
                if (!(tile instanceof ITileStructure)) {
                    continue;
                }
                ITileStructure part = (ITileStructure) tile;
                if (!part.getTypeUID().equals(getTypeUID())) {
                    continue;
                }
                part.setCentralTE((TileEntity) structure);
                EnumStructureBlock type = schemata.getAt(i, j, k, isRotated);
                if (metaOnValid.containsKey(type)) {
                    structureTile.getWorldObj().setBlockMetadataWithNotify(x, y, z, metaOnValid.get(type), Defaults.FLAG_BLOCK_SYNCH);
                    structureTile.getWorldObj().markBlockForUpdate(x, y, z);
                }
            }
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ITileStructure(forestry.api.core.ITileStructure) Vect(forestry.core.vect.Vect) EnumStructureBlock(forestry.core.utils.Schemata.EnumStructureBlock)

Example 4 with ITileStructure

use of forestry.api.core.ITileStructure in project ForestryMC by ForestryMC.

the class StructureLogicFarm method determineMasterState.

@Override
protected EnumStructureState determineMasterState(Schemata schemata, boolean rotate) {
    Vect dimensions = schemata.getDimensions(rotate);
    int offsetX = schemata.getxOffset();
    int offsetZ = schemata.getzOffset();
    if (rotate) {
        offsetX = schemata.getzOffset();
        offsetZ = schemata.getxOffset();
    }
    for (int i = 0; i < dimensions.x; i++) {
        for (int j = 0; j < schemata.getHeight(); j++) {
            for (int k = 0; k < dimensions.z; k++) {
                int x = structureTile.xCoord + i + offsetX;
                int y = structureTile.yCoord + j + schemata.getyOffset();
                int z = structureTile.zCoord + k + offsetZ;
                if (!structureTile.getWorldObj().blockExists(x, y, z)) {
                    return EnumStructureState.INDETERMINATE;
                }
                EnumStructureBlock required = schemata.getAt(i, j, k, rotate);
                if (required == EnumStructureBlock.ANY) {
                    continue;
                }
                TileEntity tile = structureTile.getWorldObj().getTileEntity(x, y, z);
                Block block = structureTile.getWorldObj().getBlock(x, y, z);
                switch(required) {
                    case AIR:
                        if (!block.isAir(structureTile.getWorldObj(), x, y, z)) {
                            return EnumStructureState.INVALID;
                        }
                        break;
                    case BLOCK_A:
                        if (tile == null || !(tile instanceof IFarmComponent)) {
                            return EnumStructureState.INVALID;
                        }
                        if (!((ITileStructure) tile).getTypeUID().equals(UID_FARM)) {
                            return EnumStructureState.INVALID;
                        }
                        break;
                    case BLOCK_B:
                    case MASTER:
                        if (tile == null || !(tile instanceof TileFarm)) {
                            return EnumStructureState.INVALID;
                        }
                        if (((TileFarm) tile).hasFunction()) {
                            return EnumStructureState.INVALID;
                        }
                        break;
                    case BLOCK_C:
                        if (!bricks.contains(block)) {
                            return EnumStructureState.INVALID;
                        }
                        break;
                    case FOREIGN:
                        if (tile instanceof ITileStructure) {
                            return EnumStructureState.INVALID;
                        }
                        break;
                    default:
                        return EnumStructureState.INDETERMINATE;
                }
            }
        }
    }
    return EnumStructureState.VALID;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IFarmComponent(forestry.api.farming.IFarmComponent) ITileStructure(forestry.api.core.ITileStructure) Vect(forestry.core.vect.Vect) Block(net.minecraft.block.Block) EnumStructureBlock(forestry.core.utils.Schemata.EnumStructureBlock) EnumStructureBlock(forestry.core.utils.Schemata.EnumStructureBlock)

Example 5 with ITileStructure

use of forestry.api.core.ITileStructure in project ForestryMC by ForestryMC.

the class TileControl method registerWithMaster.

private void registerWithMaster() {
    if (!hasMaster()) {
        return;
    }
    ITileStructure central = getCentralTE();
    if (!(central instanceof IFarmComponent)) {
        return;
    }
    ((IFarmComponent) central).registerListener(this);
}
Also used : ITileStructure(forestry.api.core.ITileStructure) IFarmComponent(forestry.api.farming.IFarmComponent)

Aggregations

ITileStructure (forestry.api.core.ITileStructure)12 TileEntity (net.minecraft.tileentity.TileEntity)6 Vect (forestry.core.vect.Vect)4 EnumStructureBlock (forestry.core.utils.Schemata.EnumStructureBlock)3 IFarmComponent (forestry.api.farming.IFarmComponent)2 TileFarmPlain (forestry.farming.gadgets.TileFarmPlain)2 TileHatch (forestry.farming.gadgets.TileHatch)2 Block (net.minecraft.block.Block)2 ItemStack (net.minecraft.item.ItemStack)2 IStatementParameter (buildcraft.api.statements.IStatementParameter)1 IAlvearyComponent (forestry.api.apiculture.IAlvearyComponent)1 IFarmHousing (forestry.api.farming.IFarmHousing)1 ForestryBlock (forestry.core.config.ForestryBlock)1 TankManager (forestry.core.fluids.TankManager)1 EnumStructureState (forestry.core.gadgets.BlockStructure.EnumStructureState)1 TileForestry (forestry.core.gadgets.TileForestry)1 EntityItem (net.minecraft.entity.item.EntityItem)1 IInventory (net.minecraft.inventory.IInventory)1 FluidTankInfo (net.minecraftforge.fluids.FluidTankInfo)1