Search in sources :

Example 1 with MetaTileEntity

use of gregtech.api.metatileentity.MetaTileEntity in project NewHorizonsCoreMod by GTNewHorizons.

the class GT_MetaTileEntity_TurboCharger method onPostTick.

@Override
public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) {
    if (aBaseMetaTileEntity.isServerSide()) {
        mCharge = aBaseMetaTileEntity.getStoredEU() / 2 > aBaseMetaTileEntity.getEUCapacity() / 3 || !aBaseMetaTileEntity.isAllowedToWork();
        mDecharge = aBaseMetaTileEntity.getStoredEU() < aBaseMetaTileEntity.getEUCapacity() / 3 && aBaseMetaTileEntity.isAllowedToWork();
        mBatteryCount = 0;
        mChargeableCount = 0;
        for (ItemStack tStack : mInventory) if (GT_ModHandler.isElectricItem(tStack, mTier)) {
            if (GT_ModHandler.isChargerItem(tStack))
                mBatteryCount++;
            mChargeableCount++;
        }
        if (this.getBaseMetaTileEntity() instanceof BaseMetaTileEntity) {
            BaseMetaTileEntity mBaseMetaTileEntity = (BaseMetaTileEntity) getBaseMetaTileEntity();
            if (mBaseMetaTileEntity.getMetaTileEntity() instanceof MetaTileEntity) {
                MetaTileEntity mMetaTileEntity = (MetaTileEntity) mBaseMetaTileEntity.getMetaTileEntity();
                //for (int t = 0; t < 6; t++) {
                if (mMetaTileEntity.dechargerSlotCount() > 0 && mBaseMetaTileEntity.getStoredEU() < mBaseMetaTileEntity.getEUCapacity()) {
                    for (int i = mMetaTileEntity.dechargerSlotStartIndex(), k = mMetaTileEntity.dechargerSlotCount() + i; i < k; i++) {
                        if (mMetaTileEntity.mInventory[i] != null && mBaseMetaTileEntity.getStoredEU() < mBaseMetaTileEntity.getEUCapacity()) {
                            //CODE
                            mBaseMetaTileEntity.increaseStoredEnergyUnits(GT_ModHandler.dischargeElectricItem(mMetaTileEntity.mInventory[i], GT_Utility.safeInt(Math.min(V[mTier] * 120, mBaseMetaTileEntity.getEUCapacity() - mBaseMetaTileEntity.getStoredEU())), (int) Math.min(Integer.MAX_VALUE, mMetaTileEntity.getInputTier()), true, false, false), true);
                            if (mMetaTileEntity.mInventory[i].stackSize <= 0)
                                mMetaTileEntity.mInventory[i] = null;
                        }
                    }
                }
                if (mMetaTileEntity.rechargerSlotCount() > 0 && mBaseMetaTileEntity.getStoredEU() > 0) {
                    for (int i = mMetaTileEntity.rechargerSlotStartIndex(), k = mMetaTileEntity.rechargerSlotCount() + i; i < k; i++) {
                        if (mBaseMetaTileEntity.getStoredEU() > 0 && mMetaTileEntity.mInventory[i] != null) {
                            //CODE
                            mBaseMetaTileEntity.decreaseStoredEU(GT_ModHandler.chargeElectricItem(mMetaTileEntity.mInventory[i], GT_Utility.safeInt(Math.min(V[mTier] * 120, mBaseMetaTileEntity.getStoredEU())), (int) Math.min(Integer.MAX_VALUE, mMetaTileEntity.getOutputTier()), true, false), true);
                            if (mMetaTileEntity.mInventory[i].stackSize <= 0)
                                mMetaTileEntity.mInventory[i] = null;
                        }
                    }
                //}
                }
            }
        }
    }
}
Also used : BaseMetaTileEntity(gregtech.api.metatileentity.BaseMetaTileEntity) MetaTileEntity(gregtech.api.metatileentity.MetaTileEntity) IMetaTileEntity(gregtech.api.interfaces.metatileentity.IMetaTileEntity) BaseMetaTileEntity(gregtech.api.metatileentity.BaseMetaTileEntity) ItemStack(net.minecraft.item.ItemStack)

Example 2 with MetaTileEntity

use of gregtech.api.metatileentity.MetaTileEntity in project GregTech by GregTechCE.

the class BlockMachine method onBlockPlacedBy.

@Override
public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) {
    MetaTileEntityHolder holder = (MetaTileEntityHolder) worldIn.getTileEntity(pos);
    MetaTileEntity sampleMetaTileEntity = GregTechAPI.META_TILE_ENTITY_REGISTRY.getObjectById(stack.getItemDamage());
    if (holder != null && sampleMetaTileEntity != null) {
        MetaTileEntity metaTileEntity = holder.setMetaTileEntity(sampleMetaTileEntity);
        if (stack.hasTagCompound()) {
            metaTileEntity.initFromItemStackData(stack.getTagCompound());
        }
        EnumFacing placeFacing = placer.getHorizontalFacing().getOpposite();
        if (metaTileEntity.isValidFrontFacing(placeFacing)) {
            metaTileEntity.setFrontFacing(placeFacing);
        }
    }
}
Also used : MetaTileEntityHolder(gregtech.api.metatileentity.MetaTileEntityHolder) MetaTileEntity(gregtech.api.metatileentity.MetaTileEntity)

Example 3 with MetaTileEntity

use of gregtech.api.metatileentity.MetaTileEntity in project GregTech by GregTechCE.

the class BlockMachine method getCollisionBox.

private List<IndexedCuboid6> getCollisionBox(IBlockAccess blockAccess, BlockPos pos) {
    MetaTileEntity metaTileEntity = getMetaTileEntity(blockAccess, pos);
    if (metaTileEntity == null)
        return EMPTY_COLLISION_BOX;
    ArrayList<IndexedCuboid6> collisionList = new ArrayList<>();
    metaTileEntity.addCollisionBoundingBox(collisionList);
    metaTileEntity.addCoverCollisionBoundingBox(collisionList);
    return collisionList;
}
Also used : IndexedCuboid6(codechicken.lib.raytracer.IndexedCuboid6) ArrayList(java.util.ArrayList) MetaTileEntity(gregtech.api.metatileentity.MetaTileEntity)

Example 4 with MetaTileEntity

use of gregtech.api.metatileentity.MetaTileEntity in project GregTech by GregTechCE.

the class BlockMachine method breakBlock.

@Override
public void breakBlock(World worldIn, BlockPos pos, IBlockState state) {
    MetaTileEntity metaTileEntity = getMetaTileEntity(worldIn, pos);
    if (metaTileEntity != null) {
        if (!metaTileEntity.keepsInventory()) {
            NonNullList<ItemStack> inventoryContents = NonNullList.create();
            metaTileEntity.clearMachineInventory(inventoryContents);
            for (ItemStack itemStack : inventoryContents) {
                Block.spawnAsEntity(worldIn, pos, itemStack);
            }
        }
        metaTileEntity.dropAllCovers();
        metaTileEntity.onRemoval();
        tileEntities.set(metaTileEntity);
    }
    super.breakBlock(worldIn, pos, state);
}
Also used : MetaTileEntity(gregtech.api.metatileentity.MetaTileEntity) ItemStack(net.minecraft.item.ItemStack)

Example 5 with MetaTileEntity

use of gregtech.api.metatileentity.MetaTileEntity in project GregTech by GregTechCE.

the class BlockMachine method rotateBlock.

@Override
public boolean rotateBlock(World world, BlockPos pos, EnumFacing axis) {
    MetaTileEntity metaTileEntity = getMetaTileEntity(world, pos);
    if (metaTileEntity == null || !metaTileEntity.isValidFrontFacing(axis) || metaTileEntity.getFrontFacing() == axis || !metaTileEntity.hasFrontFacing())
        return false;
    metaTileEntity.setFrontFacing(axis);
    return true;
}
Also used : MetaTileEntity(gregtech.api.metatileentity.MetaTileEntity)

Aggregations

MetaTileEntity (gregtech.api.metatileentity.MetaTileEntity)25 IFastRenderMetaTileEntity (gregtech.api.metatileentity.IFastRenderMetaTileEntity)6 CCRenderState (codechicken.lib.render.CCRenderState)5 ItemStack (net.minecraft.item.ItemStack)5 Matrix4 (codechicken.lib.vec.Matrix4)4 IRenderMetaTileEntity (gregtech.api.metatileentity.IRenderMetaTileEntity)4 MetaTileEntityHolder (gregtech.api.metatileentity.MetaTileEntityHolder)4 ResourceLocation (net.minecraft.util.ResourceLocation)4 ArrayList (java.util.ArrayList)3 CuboidRayTraceResult (codechicken.lib.raytracer.CuboidRayTraceResult)2 IndexedCuboid6 (codechicken.lib.raytracer.IndexedCuboid6)2 IVertexOperation (codechicken.lib.render.pipeline.IVertexOperation)2 IMetaTileEntity (gregtech.api.interfaces.metatileentity.IMetaTileEntity)2 ITieredMetaTileEntity (gregtech.api.metatileentity.ITieredMetaTileEntity)2 TextureAtlasSprite (net.minecraft.client.renderer.texture.TextureAtlasSprite)2 TileEntity (net.minecraft.tileentity.TileEntity)2 EnumFacing (net.minecraft.util.EnumFacing)2 ColourMultiplier (codechicken.lib.render.pipeline.ColourMultiplier)1 Cuboid6 (codechicken.lib.vec.Cuboid6)1 Vector3 (codechicken.lib.vec.Vector3)1