Skip to content

Commit

Permalink
Clean up a lil bit and fix some issues with MuTEs (#2316)
Browse files Browse the repository at this point in the history
* clean up fixes

* actual fix and remove useless if
  • Loading branch information
BlueWeabo committed Dec 27, 2023
1 parent 879dae2 commit 9249e3d
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ public final void breakBlock(World aWorld, int aX, int aY, int aZ, Block aBlock,
@Override
public ArrayList<String> 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<>();
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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<ItemStack> tList = ((IMultiTileEntity) aTileEntity).getDrops(aFortune, aSilkTouch);
final ArrayList<ItemStack> tList = mte.getDrops(aFortune, aSilkTouch);
aChance = ForgeEventFactory
.fireBlockHarvesting(tList, aWorld, this, aX, aY, aZ, aMeta, aFortune, aChance, aSilkTouch, aPlayer);
for (final ItemStack tStack : tList)
Expand All @@ -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);
}

Expand Down Expand Up @@ -532,7 +532,7 @@ public boolean hasTileEntity(int aMeta) {
public final ArrayList<ItemStack> 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<>();
}

Expand All @@ -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;
}

Expand All @@ -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);
}

Expand Down Expand Up @@ -596,23 +596,22 @@ 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,
short aID) {
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;

Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ public void addInformation(ItemStack aStack, EntityPlayer aPlayer, List<String>
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);
}
Expand Down Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/**
Expand All @@ -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();

Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand Down
12 changes: 5 additions & 7 deletions src/main/java/gregtech/api/task/tasks/ProcessingTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down

0 comments on commit 9249e3d

Please sign in to comment.