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;
}
}
//}
}
}
}
}
}
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);
}
}
}
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;
}
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);
}
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;
}
Aggregations