Search in sources :

Example 1 with IGregTechTileEntity

use of gregtech.api.interfaces.tileentity.IGregTechTileEntity in project NewHorizonsCoreMod by GTNewHorizons.

the class GT_CustomMetaPipeEntity_Item method onPostTick.

@Override
public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) {
    if (aBaseMetaTileEntity.isServerSide() && aTick % 10 == 0) {
        mConnections = 0;
        if (aTick % mCustomTickTime == 0)
            mTransferredItems = 0;
        for (byte i = 0; i < 6; i++) {
            TileEntity tTileEntity = aBaseMetaTileEntity.getTileEntityAtSide(i);
            if (tTileEntity != null) {
                boolean temp = GT_Utility.isConnectableNonInventoryPipe(tTileEntity, GT_Utility.getOppositeSide(i));
                if (tTileEntity instanceof IGregTechTileEntity) {
                    temp = true;
                    if (((IGregTechTileEntity) tTileEntity).getMetaTileEntity() == null)
                        continue;
                    if (aBaseMetaTileEntity.getColorization() >= 0) {
                        byte tColor = ((IGregTechTileEntity) tTileEntity).getColorization();
                        if (tColor >= 0 && tColor != aBaseMetaTileEntity.getColorization()) {
                            continue;
                        }
                    }
                    if (((IGregTechTileEntity) tTileEntity).getMetaTileEntity().connectsToItemPipe(GT_Utility.getOppositeSide(i))) {
                        mConnections |= (1 << i);
                        continue;
                    }
                }
                if (tTileEntity instanceof IInventory) {
                    temp = true;
                    if (((IInventory) tTileEntity).getSizeInventory() <= 0) {
                        continue;
                    }
                }
                if (tTileEntity instanceof ISidedInventory) {
                    temp = true;
                    int[] tSlots = ((ISidedInventory) tTileEntity).getAccessibleSlotsFromSide(GT_Utility.getOppositeSide(i));
                    if (tSlots == null || tSlots.length <= 0) {
                        continue;
                    }
                }
                if (temp) {
                    if (tTileEntity instanceof ICoverable && ((ICoverable) tTileEntity).getCoverBehaviorAtSide(GT_Utility.getOppositeSide(i)).alwaysLookConnected(GT_Utility.getOppositeSide(i), ((ICoverable) tTileEntity).getCoverIDAtSide(GT_Utility.getOppositeSide(i)), ((ICoverable) tTileEntity).getCoverDataAtSide(GT_Utility.getOppositeSide(i)), ((ICoverable) tTileEntity))) {
                        mConnections |= (1 << i);
                        continue;
                    }
                    if (aBaseMetaTileEntity.getCoverBehaviorAtSide(i).alwaysLookConnected(i, aBaseMetaTileEntity.getCoverIDAtSide(i), aBaseMetaTileEntity.getCoverDataAtSide(i), aBaseMetaTileEntity)) {
                        mConnections |= (1 << i);
                        continue;
                    }
                    if (aBaseMetaTileEntity.getCoverBehaviorAtSide(i).letsItemsIn(i, aBaseMetaTileEntity.getCoverIDAtSide(i), aBaseMetaTileEntity.getCoverDataAtSide(i), -1, aBaseMetaTileEntity)) {
                        mConnections |= (1 << i);
                        continue;
                    }
                    if (aBaseMetaTileEntity.getCoverBehaviorAtSide(i).letsItemsOut(i, aBaseMetaTileEntity.getCoverIDAtSide(i), aBaseMetaTileEntity.getCoverDataAtSide(i), -1, aBaseMetaTileEntity)) {
                        mConnections |= (1 << i);
                        continue;
                    }
                }
            }
        }
        if (oLastReceivedFrom == mLastReceivedFrom) {
            doTickProfilingInThisTick = false;
            ArrayList<IMetaTileEntityItemPipe> tPipeList = new ArrayList<IMetaTileEntityItemPipe>();
            for (boolean temp = true; temp && !isInventoryEmpty() && pipeCapacityCheck(); ) {
                temp = false;
                tPipeList.clear();
                for (IMetaTileEntityItemPipe tTileEntity : GT_Utility.sortMapByValuesAcending(IMetaTileEntityItemPipe.Util.scanPipes(this, new HashMap<IMetaTileEntityItemPipe, Long>(), 0, false, false)).keySet()) {
                    if (temp)
                        break;
                    tPipeList.add(tTileEntity);
                    while (!temp && !isInventoryEmpty() && tTileEntity.sendItemStack(aBaseMetaTileEntity)) for (IMetaTileEntityItemPipe tPipe : tPipeList) if (!tPipe.incrementTransferCounter(1))
                        temp = true;
                }
            }
        }
        if (isInventoryEmpty())
            mLastReceivedFrom = 6;
        oLastReceivedFrom = mLastReceivedFrom;
    } else if (aBaseMetaTileEntity.isClientSide() && GT_Client.changeDetected == 4)
        aBaseMetaTileEntity.issueTextureUpdate();
}
Also used : IInventory(net.minecraft.inventory.IInventory) ICoverable(gregtech.api.interfaces.tileentity.ICoverable) IGregTechTileEntity(gregtech.api.interfaces.tileentity.IGregTechTileEntity) IMetaTileEntityItemPipe(gregtech.api.interfaces.metatileentity.IMetaTileEntityItemPipe) ArrayList(java.util.ArrayList) IGregTechTileEntity(gregtech.api.interfaces.tileentity.IGregTechTileEntity) IMetaTileEntity(gregtech.api.interfaces.metatileentity.IMetaTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) ISidedInventory(net.minecraft.inventory.ISidedInventory)

Example 2 with IGregTechTileEntity

use of gregtech.api.interfaces.tileentity.IGregTechTileEntity in project NewHorizonsCoreMod by GTNewHorizons.

the class GT_MetaTileEntity_WorldAccelerator method doAccelerateTileEntities.

private void doAccelerateTileEntities(IGregTechTileEntity pBaseMetaTileEntity, World pWorld) {
    try {
        if (!pBaseMetaTileEntity.isActive())
            getBaseMetaTileEntity().setActive(true);
        for (ForgeDirection tDir : ForgeDirection.VALID_DIRECTIONS) {
            TileEntity tTile = pBaseMetaTileEntity.getTileEntityAtSide((byte) tDir.ordinal());
            if (isTEBlackListed(tTile))
                continue;
            long tMaxTime = System.nanoTime() + 1000000;
            for (int j = 0; j < mAccelerateStatic[mTier]; j++) {
                tTile.updateEntity();
                if (System.nanoTime() > tMaxTime)
                    break;
            }
        }
    } catch (Exception e) {
        MainRegistry.Logger.error("GT_MetaTileEntity_WorldAccelerator.doAccelerateTileEntities.crash", e.getMessage());
    }
}
Also used : IGregTechTileEntity(gregtech.api.interfaces.tileentity.IGregTechTileEntity) MetaTileEntity(gregtech.api.metatileentity.MetaTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) ForgeDirection(net.minecraftforge.common.util.ForgeDirection)

Example 3 with IGregTechTileEntity

use of gregtech.api.interfaces.tileentity.IGregTechTileEntity in project NewHorizonsCoreMod by GTNewHorizons.

the class GT_Block_CasingsNH method getIcon.

@SideOnly(Side.CLIENT)
public IIcon getIcon(IBlockAccess aWorld, int xCoord, int yCoord, int zCoord, int aSide) {
    int tMeta = aWorld.getBlockMetadata(xCoord, yCoord, zCoord);
    if (tMeta > 0 && tMeta < 9 || tMeta == 15) {
        return getIcon(aSide, tMeta);
    }
    if (tMeta != 0 || (!mConnectedMachineTextures)) {
        return getIcon(aSide, tMeta);
    }
    if (aSide == 1) {
        TileEntity tTileEntity;
        IMetaTileEntity tMetaTileEntity;
        for (int xi = -2; xi <= 2; xi++) {
            for (int zi = -2; zi <= 2; zi++) {
                if (null != (tTileEntity = aWorld.getTileEntity(xCoord + xi, yCoord - 3 < 0 ? 0 : yCoord - 3, zCoord + zi)) && tTileEntity instanceof IGregTechTileEntity && null != (tMetaTileEntity = ((IGregTechTileEntity) tTileEntity).getMetaTileEntity()) && tMetaTileEntity instanceof GT_MetaTileEntity_AirFilter) {
                    boolean active = false;
                    if (((IGregTechTileEntity) tTileEntity).isActive())
                        active = true;
                    //check for direction and placement and apply the texture
                    switch(((IGregTechTileEntity) tTileEntity).getFrontFacing()) {
                        case 2:
                            if (xi < 2 && xi > -2 && zi < 1) {
                                //if invalid position ignore (aka too far away)
                                try {
                                    return getTurbineCasing(tMeta, -xi + 1 - zi * 3, active);
                                } catch (Exception e) {
                                    return Textures.BlockIcons.MACHINE_CASING_SOLID_STEEL.getIcon();
                                }
                            }
                            break;
                        case 3:
                            if (xi < 2 && xi > -2 && zi > -1) {
                                try {
                                    return getTurbineCasing(tMeta, -xi + 1 + (2 - zi) * 3, active);
                                } catch (Exception e) {
                                    return Textures.BlockIcons.MACHINE_CASING_SOLID_STEEL.getIcon();
                                }
                            }
                            break;
                        case 4:
                            if (zi < 2 && zi > -2 && xi < 1) {
                                try {
                                    return getTurbineCasing(tMeta, -xi + (1 - zi) * 3, active);
                                } catch (Exception e) {
                                    return Textures.BlockIcons.MACHINE_CASING_SOLID_STEEL.getIcon();
                                }
                            }
                            break;
                        case 5:
                            if (zi < 2 && zi > -2 && xi > -1) {
                                try {
                                    return getTurbineCasing(tMeta, -xi + 2 + (1 - zi) * 3, active);
                                } catch (Exception e) {
                                    return Textures.BlockIcons.MACHINE_CASING_SOLID_STEEL.getIcon();
                                }
                            }
                    }
                }
            }
        }
    }
    return Textures.BlockIcons.MACHINE_CASING_SOLID_STEEL.getIcon();
}
Also used : IGregTechTileEntity(gregtech.api.interfaces.tileentity.IGregTechTileEntity) IMetaTileEntity(gregtech.api.interfaces.metatileentity.IMetaTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) GT_MetaTileEntity_AirFilter(com.dreammaster.gthandler.multiAirFilter.GT_MetaTileEntity_AirFilter) IGregTechTileEntity(gregtech.api.interfaces.tileentity.IGregTechTileEntity) IMetaTileEntity(gregtech.api.interfaces.metatileentity.IMetaTileEntity) SideOnly(cpw.mods.fml.relauncher.SideOnly)

Example 4 with IGregTechTileEntity

use of gregtech.api.interfaces.tileentity.IGregTechTileEntity in project NewHorizonsCoreMod by GTNewHorizons.

the class GT_MetaTileEntity_AirFilter method checkMachine.

@Override
public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) {
    int xDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetX;
    int zDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetZ;
    int one = 1;
    int two = 2;
    //air check and top casing check
    if (!aBaseMetaTileEntity.getAirOffset(xDir, one, zDir) || !aBaseMetaTileEntity.getAirOffset(xDir, two, zDir)) {
        //check air inside
        return false;
    }
    for (int i = -one; i < two; i++) {
        for (int j = -one; j < two; j++) {
            if (!aBaseMetaTileEntity.getAirOffset(xDir + i, 4, zDir + j) || !aBaseMetaTileEntity.getAirOffset(xDir + i, 5, zDir + j)) {
                //check air at on top of top layer
                return false;
            }
            //top casing
            if (aBaseMetaTileEntity.getBlockOffset(xDir + i, 3, zDir + j) != GT_Container_CasingsNH.sBlockCasingsNH)
                return false;
            //top casing
            if (aBaseMetaTileEntity.getMetaIDOffset(xDir + i, 3, zDir + j) != 0)
                return false;
        }
    }
    if (!aBaseMetaTileEntity.getAirOffset(two + xDir, one, zDir) || !aBaseMetaTileEntity.getAirOffset(two + xDir, two, zDir))
        return false;
    if (!aBaseMetaTileEntity.getAirOffset(xDir - two, one, zDir) || !aBaseMetaTileEntity.getAirOffset(xDir - two, two, zDir))
        return false;
    if (!aBaseMetaTileEntity.getAirOffset(xDir, one, two + zDir) || !aBaseMetaTileEntity.getAirOffset(xDir, two, two + zDir))
        return false;
    if (!aBaseMetaTileEntity.getAirOffset(xDir, one, zDir - two) || !aBaseMetaTileEntity.getAirOffset(xDir, two, zDir - two))
        return false;
    if (!aBaseMetaTileEntity.getAirOffset(two + xDir, one, one + zDir) || !aBaseMetaTileEntity.getAirOffset(two + xDir, two, one + zDir))
        return false;
    if (!aBaseMetaTileEntity.getAirOffset(two + xDir, one, zDir - one) || !aBaseMetaTileEntity.getAirOffset(two + xDir, two, zDir - one))
        return false;
    if (!aBaseMetaTileEntity.getAirOffset(xDir - two, one, one + zDir) || !aBaseMetaTileEntity.getAirOffset(xDir - two, two, one + zDir))
        return false;
    if (!aBaseMetaTileEntity.getAirOffset(xDir - two, one, zDir - one) || !aBaseMetaTileEntity.getAirOffset(xDir - two, two, zDir - one))
        return false;
    if (!aBaseMetaTileEntity.getAirOffset(one + xDir, one, two + zDir) || !aBaseMetaTileEntity.getAirOffset(one + xDir, two, two + zDir))
        return false;
    if (!aBaseMetaTileEntity.getAirOffset(xDir - one, one, two + zDir) || !aBaseMetaTileEntity.getAirOffset(xDir - one, two, two + zDir))
        return false;
    if (!aBaseMetaTileEntity.getAirOffset(one + xDir, one, zDir - two) || !aBaseMetaTileEntity.getAirOffset(one + xDir, two, zDir - two))
        return false;
    if (!aBaseMetaTileEntity.getAirOffset(xDir - one, one, zDir - two) || !aBaseMetaTileEntity.getAirOffset(xDir - one, two, zDir - two))
        return false;
    //air check and top casing check done
    //muffler check
    mMufflerHatches.clear();
    if (!addMufflerToMachineList(aBaseMetaTileEntity.getIGregTechTileEntityOffset(one + xDir, one, zDir), 57)) {
        if (aBaseMetaTileEntity.getBlockOffset(one + xDir, one, zDir) != GT_Container_CasingsNH.sBlockCasingsNH)
            return false;
        if (aBaseMetaTileEntity.getMetaIDOffset(one + xDir, one, zDir) != 0)
            return false;
    }
    if (!addMufflerToMachineList(aBaseMetaTileEntity.getIGregTechTileEntityOffset(one + xDir, two, zDir), 57)) {
        if (aBaseMetaTileEntity.getBlockOffset(one + xDir, two, zDir) != GT_Container_CasingsNH.sBlockCasingsNH)
            return false;
        if (aBaseMetaTileEntity.getMetaIDOffset(one + xDir, two, zDir) != 0)
            return false;
    }
    if (!addMufflerToMachineList(aBaseMetaTileEntity.getIGregTechTileEntityOffset(xDir - one, one, zDir), 57)) {
        if (aBaseMetaTileEntity.getBlockOffset(xDir - one, one, zDir) != GT_Container_CasingsNH.sBlockCasingsNH)
            return false;
        if (aBaseMetaTileEntity.getMetaIDOffset(xDir - one, one, zDir) != 0)
            return false;
    }
    if (!addMufflerToMachineList(aBaseMetaTileEntity.getIGregTechTileEntityOffset(xDir - one, two, zDir), 57)) {
        if (aBaseMetaTileEntity.getBlockOffset(xDir - one, two, zDir) != GT_Container_CasingsNH.sBlockCasingsNH)
            return false;
        if (aBaseMetaTileEntity.getMetaIDOffset(xDir - one, two, zDir) != 0)
            return false;
    }
    if (!addMufflerToMachineList(aBaseMetaTileEntity.getIGregTechTileEntityOffset(xDir, one, one + zDir), 57)) {
        if (aBaseMetaTileEntity.getBlockOffset(xDir, one, one + zDir) != GT_Container_CasingsNH.sBlockCasingsNH)
            return false;
        if (aBaseMetaTileEntity.getMetaIDOffset(xDir, one, one + zDir) != 0)
            return false;
    }
    if (!addMufflerToMachineList(aBaseMetaTileEntity.getIGregTechTileEntityOffset(xDir, two, one + zDir), 57)) {
        if (aBaseMetaTileEntity.getBlockOffset(xDir, two, one + zDir) != GT_Container_CasingsNH.sBlockCasingsNH)
            return false;
        if (aBaseMetaTileEntity.getMetaIDOffset(xDir, two, one + zDir) != 0)
            return false;
    }
    if (!addMufflerToMachineList(aBaseMetaTileEntity.getIGregTechTileEntityOffset(xDir, one, zDir - one), 57)) {
        if (aBaseMetaTileEntity.getBlockOffset(xDir, one, zDir - one) != GT_Container_CasingsNH.sBlockCasingsNH)
            return false;
        if (aBaseMetaTileEntity.getMetaIDOffset(xDir, one, zDir - one) != 0)
            return false;
    }
    if (!addMufflerToMachineList(aBaseMetaTileEntity.getIGregTechTileEntityOffset(xDir, two, zDir - one), 57)) {
        if (aBaseMetaTileEntity.getBlockOffset(xDir, two, zDir - one) != GT_Container_CasingsNH.sBlockCasingsNH)
            return false;
        if (aBaseMetaTileEntity.getMetaIDOffset(xDir, two, zDir - one) != 0)
            return false;
    }
    if (mMufflerHatches.isEmpty())
        return false;
    //pipe casing check
    if (aBaseMetaTileEntity.getBlockOffset(one + xDir, one, one + zDir) != GT_Container_CasingsNH.sBlockCasingsNH)
        return false;
    if (aBaseMetaTileEntity.getMetaIDOffset(one + xDir, one, one + zDir) != 1)
        return false;
    if (aBaseMetaTileEntity.getBlockOffset(one + xDir, two, one + zDir) != GT_Container_CasingsNH.sBlockCasingsNH)
        return false;
    if (aBaseMetaTileEntity.getMetaIDOffset(one + xDir, two, one + zDir) != 1)
        return false;
    if (aBaseMetaTileEntity.getBlockOffset(xDir - one, one, one + zDir) != GT_Container_CasingsNH.sBlockCasingsNH)
        return false;
    if (aBaseMetaTileEntity.getMetaIDOffset(xDir - one, one, one + zDir) != 1)
        return false;
    if (aBaseMetaTileEntity.getBlockOffset(xDir - one, two, one + zDir) != GT_Container_CasingsNH.sBlockCasingsNH)
        return false;
    if (aBaseMetaTileEntity.getMetaIDOffset(xDir - one, two, one + zDir) != 1)
        return false;
    if (aBaseMetaTileEntity.getBlockOffset(one + xDir, one, zDir - one) != GT_Container_CasingsNH.sBlockCasingsNH)
        return false;
    if (aBaseMetaTileEntity.getMetaIDOffset(one + xDir, one, zDir - one) != 1)
        return false;
    if (aBaseMetaTileEntity.getBlockOffset(one + xDir, two, zDir - one) != GT_Container_CasingsNH.sBlockCasingsNH)
        return false;
    if (aBaseMetaTileEntity.getMetaIDOffset(one + xDir, two, zDir - one) != 1)
        return false;
    if (aBaseMetaTileEntity.getBlockOffset(xDir - one, one, zDir - one) != GT_Container_CasingsNH.sBlockCasingsNH)
        return false;
    if (aBaseMetaTileEntity.getMetaIDOffset(xDir - one, one, zDir - one) != 1)
        return false;
    if (aBaseMetaTileEntity.getBlockOffset(xDir - one, two, zDir - one) != GT_Container_CasingsNH.sBlockCasingsNH)
        return false;
    if (aBaseMetaTileEntity.getMetaIDOffset(xDir - one, two, zDir - one) != 1)
        return false;
    //bottom casing
    for (int i = -one; i < two; i++) {
        for (int j = -one; j < two; j++) {
            if ((xDir + i != 0) || (zDir + j != 0)) {
                //sneak exclusion of the controller block
                IGregTechTileEntity tTileEntity = aBaseMetaTileEntity.getIGregTechTileEntityOffset(xDir + i, 0, zDir + j);
                if ((!addMaintenanceToMachineList(tTileEntity, 57)) && (!addInputToMachineList(tTileEntity, 57)) && (!addOutputToMachineList(tTileEntity, 57)) && (!addEnergyInputToMachineList(tTileEntity, 57))) {
                    if (aBaseMetaTileEntity.getBlockOffset(xDir + i, 0, zDir + j) != GT_Container_CasingsNH.sBlockCasingsNH)
                        return false;
                    if (aBaseMetaTileEntity.getMetaIDOffset(xDir + i, 0, zDir + j) != 0)
                        return false;
                }
            }
        }
    }
    //bottom casing done
    return true;
}
Also used : IGregTechTileEntity(gregtech.api.interfaces.tileentity.IGregTechTileEntity)

Aggregations

IGregTechTileEntity (gregtech.api.interfaces.tileentity.IGregTechTileEntity)4 TileEntity (net.minecraft.tileentity.TileEntity)3 IMetaTileEntity (gregtech.api.interfaces.metatileentity.IMetaTileEntity)2 GT_MetaTileEntity_AirFilter (com.dreammaster.gthandler.multiAirFilter.GT_MetaTileEntity_AirFilter)1 SideOnly (cpw.mods.fml.relauncher.SideOnly)1 IMetaTileEntityItemPipe (gregtech.api.interfaces.metatileentity.IMetaTileEntityItemPipe)1 ICoverable (gregtech.api.interfaces.tileentity.ICoverable)1 MetaTileEntity (gregtech.api.metatileentity.MetaTileEntity)1 ArrayList (java.util.ArrayList)1 IInventory (net.minecraft.inventory.IInventory)1 ISidedInventory (net.minecraft.inventory.ISidedInventory)1 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)1