diff --git a/src/main/java/gregtech/api/logic/ComplexParallelProcessingLogic.java b/src/main/java/gregtech/api/logic/ComplexParallelProcessingLogic.java index 8c1c775571b..72a74ebd045 100644 --- a/src/main/java/gregtech/api/logic/ComplexParallelProcessingLogic.java +++ b/src/main/java/gregtech/api/logic/ComplexParallelProcessingLogic.java @@ -39,10 +39,10 @@ public FluidStack[] getOutputFluids(int index) { public boolean canWork() { for (int i = 0; i < maxComplexParallels; i++) { if (progresses[i] >= durations[i]) { - return false; + return machineHost.isAllowedToWork(); } } - return true; + return false; } @Override diff --git a/src/main/java/gregtech/api/multitileentity/MultiTileEntityBlock.java b/src/main/java/gregtech/api/multitileentity/MultiTileEntityBlock.java index 0e43efa6993..5ea10691934 100644 --- a/src/main/java/gregtech/api/multitileentity/MultiTileEntityBlock.java +++ b/src/main/java/gregtech/api/multitileentity/MultiTileEntityBlock.java @@ -189,8 +189,8 @@ public final void breakBlock(World aWorld, int aX, int aY, int aZ, Block aBlock, @Override public ArrayList getDebugInfo(EntityPlayer aPlayer, int aX, int aY, int aZ, int aLogLevel) { final TileEntity aTileEntity = aPlayer.worldObj.getTileEntity(aX, aY, aZ); - if (aTileEntity instanceof IDebugableTileEntity) { - return ((IDebugableTileEntity) aTileEntity).getDebugInfo(aPlayer, aLogLevel); + if (aTileEntity instanceof IDebugableTileEntity mte) { + return mte.getDebugInfo(aPlayer, aLogLevel); } return new ArrayList<>(); } @@ -291,7 +291,7 @@ public void onNeighborBlockChange(World aWorld, int aX, int aY, int aZ, Block aB final TileEntity aTileEntity = aWorld.getTileEntity(aX, aY, aZ); if (!LOCK) { LOCK = true; - if (aTileEntity instanceof BaseTileEntity) ((BaseTileEntity) aTileEntity).onAdjacentBlockChange(aX, aY, aZ); + if (aTileEntity instanceof BaseTileEntity bte) bte.onAdjacentBlockChange(aX, aY, aZ); LOCK = false; } if (aTileEntity instanceof IMTE_OnNeighborBlockChange change) change.onNeighborBlockChange(aWorld, aBlock); @@ -369,11 +369,11 @@ public final void harvestBlock(World aWorld, EntityPlayer aPlayer, int aX, int a float aChance = 1.0F; final TileEntity aTileEntity = getTileEntity(aWorld, aX, aY, aZ, true); - if (!(aTileEntity instanceof IMultiTileEntity)) { + if (!(aTileEntity instanceof IMultiTileEntity mte)) { return; } - final ArrayList tList = ((IMultiTileEntity) aTileEntity).getDrops(aFortune, aSilkTouch); + final ArrayList tList = mte.getDrops(aFortune, aSilkTouch); aChance = ForgeEventFactory .fireBlockHarvesting(tList, aWorld, this, aX, aY, aZ, aMeta, aFortune, aChance, aSilkTouch, aPlayer); for (final ItemStack tStack : tList) @@ -385,8 +385,8 @@ public final void harvestBlock(World aWorld, EntityPlayer aPlayer, int aX, int a public final boolean shouldSideBeRendered(IBlockAccess aWorld, int aX, int aY, int aZ, int ordinalSide) { final TileEntity aTileEntity = aWorld .getTileEntity(aX - OFFX[ordinalSide], aY - OFFY[ordinalSide], aZ - OFFZ[ordinalSide]); - return aTileEntity instanceof IMultiTileEntity - ? ((IMultiTileEntity) aTileEntity).shouldSideBeRendered(ForgeDirection.getOrientation(ordinalSide)) + return aTileEntity instanceof IMultiTileEntity mte + ? mte.shouldSideBeRendered(ForgeDirection.getOrientation(ordinalSide)) : super.shouldSideBeRendered(aWorld, aX, aY, aZ, ordinalSide); } @@ -532,7 +532,7 @@ public boolean hasTileEntity(int aMeta) { public final ArrayList getDrops(World aWorld, int aX, int aY, int aZ, int aUnusableMetaData, int aFortune) { final TileEntity aTileEntity = getTileEntity(aWorld, aX, aY, aZ, true); - if (aTileEntity instanceof IMultiTileEntity) return ((IMultiTileEntity) aTileEntity).getDrops(aFortune, false); + if (aTileEntity instanceof IMultiTileEntity mte) return mte.getDrops(aFortune, false); return new ArrayList<>(); } @@ -545,8 +545,8 @@ public boolean canCreatureSpawn(EnumCreatureType type, IBlockAccess aWorld, int public final float getExplosionResistance(Entity aExploder, World aWorld, int aX, int aY, int aZ, double aExplosionX, double aExplosionY, double aExplosionZ) { final TileEntity aTileEntity = aWorld.getTileEntity(aX, aY, aZ); - return aTileEntity instanceof IMultiTileEntity - ? ((IMultiTileEntity) aTileEntity).getExplosionResistance(aExploder, aExplosionX, aExplosionY, aExplosionZ) + return aTileEntity instanceof IMultiTileEntity mte + ? mte.getExplosionResistance(aExploder, aExplosionX, aExplosionY, aExplosionZ) : 1.0F; } @@ -555,14 +555,14 @@ public final void onBlockExploded(World aWorld, int aX, int aY, int aZ, Explosio if (aWorld.isRemote) return; final TileEntity aTileEntity = getTileEntity(aWorld, aX, aY, aZ, true); if (aTileEntity != null) LAST_BROKEN_TILEENTITY.set(aTileEntity); - if (aTileEntity instanceof IMultiTileEntity) { + if (aTileEntity instanceof IMultiTileEntity mte) { GT_Log.exp.printf( "Explosion at : %d | %d | %d DIMID: %s due to near explosion!%n", aX, aY, aZ, aWorld.provider.dimensionId); - ((IMultiTileEntity) aTileEntity).onExploded(aExplosion); + mte.onExploded(aExplosion); } else aWorld.setBlockToAir(aX, aY, aZ); } @@ -596,13 +596,13 @@ public final boolean isToolEffective(String aType, int aMeta) { public final ItemStack getPickBlock(MovingObjectPosition aTarget, World aWorld, int aX, int aY, int aZ, EntityPlayer aPlayer) { final TileEntity aTileEntity = aWorld.getTileEntity(aX, aY, aZ); - return aTileEntity instanceof IMultiTileEntity ? ((IMultiTileEntity) aTileEntity).getPickBlock(aTarget) : null; + return aTileEntity instanceof IMultiTileEntity mte ? mte.getPickBlock(aTarget) : null; } @Override public final ItemStack getPickBlock(MovingObjectPosition aTarget, World aWorld, int aX, int aY, int aZ) { final TileEntity aTileEntity = aWorld.getTileEntity(aX, aY, aZ); - return aTileEntity instanceof IMultiTileEntity ? ((IMultiTileEntity) aTileEntity).getPickBlock(aTarget) : null; + return aTileEntity instanceof IMultiTileEntity mte ? mte.getPickBlock(aTarget) : null; } public final IMultiTileEntity receiveMultiTileEntityData(IBlockAccess aWorld, int aX, short aY, int aZ, short aRID, @@ -610,9 +610,8 @@ public final IMultiTileEntity receiveMultiTileEntityData(IBlockAccess aWorld, in if (!(aWorld instanceof World)) return null; TileEntity aTileEntity = aWorld.getTileEntity(aX, aY, aZ); - if (!(aTileEntity instanceof IMultiTileEntity) - || ((IMultiTileEntity) aTileEntity).getMultiTileEntityRegistryID() != aRID - || ((IMultiTileEntity) aTileEntity).getMultiTileEntityID() != aID) { + if (!(aTileEntity instanceof IMultiTileEntity mte) || mte.getMultiTileEntityRegistryID() != aRID + || mte.getMultiTileEntityID() != aID) { final MultiTileEntityRegistry tRegistry = MultiTileEntityRegistry.getRegistry(aRID); if (tRegistry == null) return null; @@ -621,7 +620,7 @@ public final IMultiTileEntity receiveMultiTileEntityData(IBlockAccess aWorld, in setTileEntity((World) aWorld, aX, aY, aZ, aTileEntity, false); } - return ((IMultiTileEntity) aTileEntity); + return (IMultiTileEntity) aTileEntity; } public void receiveCoverData(IMultiTileEntity mte, int aCover0, int aCover1, int aCover2, int aCover3, int aCover4, diff --git a/src/main/java/gregtech/api/multitileentity/MultiTileEntityItemInternal.java b/src/main/java/gregtech/api/multitileentity/MultiTileEntityItemInternal.java index 1715b1b8e0e..cc10485f845 100644 --- a/src/main/java/gregtech/api/multitileentity/MultiTileEntityItemInternal.java +++ b/src/main/java/gregtech/api/multitileentity/MultiTileEntityItemInternal.java @@ -56,9 +56,9 @@ public void addInformation(ItemStack aStack, EntityPlayer aPlayer, List aList.add("INVALID ITEM!"); return; } - if (tTileEntityContainer.mTileEntity instanceof IMTE_AddToolTips) { + if (tTileEntityContainer.mTileEntity instanceof IMTE_AddToolTips mte) { try { - ((IMTE_AddToolTips) tTileEntityContainer.mTileEntity).addToolTips(aList, aStack, aF3_H); + mte.addToolTips(aList, aStack, aF3_H); } catch (Throwable e) { GT_FML_LOGGER.error("addInformation", e); } @@ -123,13 +123,10 @@ public boolean onItemUse(ItemStack aStack, EntityPlayer aPlayer, World aWorld, i return false; } - if (!aWorld.checkNoEntityCollision(AxisAlignedBB.getBoundingBox(aX, aY, aZ, aX + 1, aY + 1, aZ + 1))) { - return false; - } - - if (!(aMTEContainer.mTileEntity instanceof IMTE_IgnoreEntityCollisionWhenPlacing mteIgnoreCollision) + if ((!(aMTEContainer.mTileEntity instanceof IMTE_IgnoreEntityCollisionWhenPlacing mteIgnoreCollision) || !mteIgnoreCollision - .ignoreEntityCollisionWhenPlacing(aStack, aPlayer, aWorld, aX, aY, aZ, side, aHitX, aHitY, aHitZ)) { + .ignoreEntityCollisionWhenPlacing(aStack, aPlayer, aWorld, aX, aY, aZ, side, aHitX, aHitY, aHitZ)) + && !aWorld.checkNoEntityCollision(AxisAlignedBB.getBoundingBox(aX, aY, aZ, aX + 1, aY + 1, aZ + 1))) { return false; } diff --git a/src/main/java/gregtech/api/multitileentity/interfaces/IMultiBlockController.java b/src/main/java/gregtech/api/multitileentity/interfaces/IMultiBlockController.java index b4ba8f78501..435fecdc73e 100644 --- a/src/main/java/gregtech/api/multitileentity/interfaces/IMultiBlockController.java +++ b/src/main/java/gregtech/api/multitileentity/interfaces/IMultiBlockController.java @@ -14,13 +14,13 @@ import gregtech.api.enums.InventoryType; import gregtech.api.logic.FluidInventoryLogic; import gregtech.api.logic.ItemInventoryLogic; -import gregtech.api.logic.PowerLogic; import gregtech.api.logic.interfaces.FluidInventoryLogicHost; import gregtech.api.logic.interfaces.ItemInventoryLogicHost; +import gregtech.api.logic.interfaces.PowerLogicHost; import gregtech.api.multitileentity.enums.MultiTileCasingPurpose; public interface IMultiBlockController - extends IMultiTileEntity, FluidInventoryLogicHost, ItemInventoryLogicHost, UpgradableMuTE { + extends IMultiTileEntity, FluidInventoryLogicHost, ItemInventoryLogicHost, UpgradableMuTE, PowerLogicHost { boolean checkStructure(boolean aForceReset); @@ -38,8 +38,6 @@ public interface IMultiBlockController void unregisterCaseWithPurpose(MultiTileCasingPurpose purpose, IMultiBlockPart part); - PowerLogic getPowerLogic(); - ModularWindow createWindowGUI(UIBuildContext buildContext); UUID registerItemInventory(int slots, int tier, @Nonnull InventoryType type, boolean isUpgradeInventory); diff --git a/src/main/java/gregtech/api/multitileentity/machine/MultiTileBasicMachine.java b/src/main/java/gregtech/api/multitileentity/machine/MultiTileBasicMachine.java index 2e23342fcff..e8a1d34fbe0 100644 --- a/src/main/java/gregtech/api/multitileentity/machine/MultiTileBasicMachine.java +++ b/src/main/java/gregtech/api/multitileentity/machine/MultiTileBasicMachine.java @@ -362,9 +362,7 @@ protected void runMachine(long tick) { * @param tick The current tick of the machine */ protected void runningTick(long tick) { - if (this instanceof PowerLogicHost) { - consumeEnergy(); - } + consumeEnergy(); } /** @@ -378,11 +376,7 @@ protected boolean checkRecipe() { * Runs only on server side */ protected void consumeEnergy() { - PowerLogic logic = ((PowerLogicHost) this).getPowerLogic(ForgeDirection.UNKNOWN); - - if (logic == null) { - return; - } + PowerLogic logic = getPowerLogic(); P processing = getProcessingLogic(); @@ -773,10 +767,12 @@ public ForgeDirection getPowerOutputSide() { protected void updatePowerLogic() { power.setEnergyCapacity(GT_Values.V[tier] * power.getMaxAmperage() * 2 * MINUTE); power.setMaxVoltage(GT_Values.V[tier]); + power.setMaxAmperage(1); } @Nonnull protected PowerLogic createPowerLogic() { - return new PowerLogic().setType(PowerLogic.RECEIVER); + return new PowerLogic().setMaxAmperage(1) + .setType(PowerLogic.RECEIVER); } } diff --git a/src/main/java/gregtech/api/multitileentity/multiblock/base/Controller.java b/src/main/java/gregtech/api/multitileentity/multiblock/base/Controller.java index 97d0d2f6c84..1af4207764f 100644 --- a/src/main/java/gregtech/api/multitileentity/multiblock/base/Controller.java +++ b/src/main/java/gregtech/api/multitileentity/multiblock/base/Controller.java @@ -68,8 +68,6 @@ import gregtech.api.logic.FluidInventoryLogic; import gregtech.api.logic.ItemInventoryLogic; import gregtech.api.logic.MuTEProcessingLogic; -import gregtech.api.logic.PowerLogic; -import gregtech.api.logic.interfaces.PowerLogicHost; import gregtech.api.multitileentity.enums.MultiTileCasingPurpose; import gregtech.api.multitileentity.interfaces.IMultiBlockController; import gregtech.api.multitileentity.interfaces.IMultiBlockPart; @@ -870,19 +868,6 @@ public void changeItemInventoryDisplayName(@Nullable UUID id, @Nullable String d // #endregion Item - // #region Energy - - @Override - public PowerLogic getPowerLogic() { - if (!(this instanceof PowerLogicHost powerLogicHost)) { - return null; - } - - return powerLogicHost.getPowerLogic(ForgeDirection.UNKNOWN); - } - - // #endregion Energy - @Override protected void updateSlots() { controllerItemInput.getAllInventoryLogics() diff --git a/src/main/java/gregtech/api/task/tasks/ProcessingTask.java b/src/main/java/gregtech/api/task/tasks/ProcessingTask.java index b727344a14c..410c8d7a6f6 100644 --- a/src/main/java/gregtech/api/task/tasks/ProcessingTask.java +++ b/src/main/java/gregtech/api/task/tasks/ProcessingTask.java @@ -33,13 +33,11 @@ public void update(long tick, boolean isServerSide) { taskHost.setProcessingUpdate(false); } if (logic.canWork() && tick % 100 == 0) { - if (tick % 100 == 0) { - taskHost.setProcessingLogicPower(logic); - logic.startCheck(); - if (logic.getResult() - .wasSuccessful()) { - taskHost.setActive(true); - } + taskHost.setProcessingLogicPower(logic); + logic.startCheck(); + if (logic.getResult() + .wasSuccessful()) { + taskHost.setActive(true); } }