Temporary fix for Forge 1.17 setRemoved() regression

This commit is contained in:
reidbhuntley 2021-12-21 16:28:14 -05:00
parent b9310e93a9
commit 10f84bcd79
7 changed files with 66 additions and 16 deletions

View file

@ -185,12 +185,17 @@ public class KineticTileEntity extends SmartTileEntity
@Override
public void setRemoved() {
super.setRemoved();
}
@Override
protected void setRemovedNotDueToChunkUnload() {
if (!level.isClientSide) {
if (hasNetwork())
getOrCreateNetwork().remove(this);
detachKinetics();
}
super.setRemoved();
super.setRemovedNotDueToChunkUnload();
}
@Override

View file

@ -86,10 +86,15 @@ public class EngineTileEntity extends SmartTileEntity implements IInstanceRender
@Override
public void setRemoved() {
detachWheel();
super.setRemoved();
}
@Override
protected void setRemovedNotDueToChunkUnload() {
detachWheel();
super.setRemovedNotDueToChunkUnload();
}
protected void refreshWheelSpeed() {
if (poweredWheel == null)
return;

View file

@ -362,9 +362,14 @@ public class ClockworkBearingTileEntity extends KineticTileEntity
@Override
public void setRemoved() {
super.setRemoved();
}
@Override
protected void setRemovedNotDueToChunkUnload() {
if (!level.isClientSide)
disassemble();
super.setRemoved();
super.setRemovedNotDueToChunkUnload();
}
@Override

View file

@ -59,9 +59,14 @@ public class MechanicalBearingTileEntity extends GeneratingKineticTileEntity
@Override
public void setRemoved() {
super.setRemoved();
}
@Override
protected void setRemovedNotDueToChunkUnload() {
if (!level.isClientSide)
disassemble();
super.setRemoved();
super.setRemovedNotDueToChunkUnload();
}
@Override

View file

@ -107,7 +107,7 @@ public abstract class LinearActuatorTileEntity extends KineticTileEntity
boolean contraptionPresent = movedContraption != null;
if (needsContraption && !contraptionPresent)
return;
float movementSpeed = getMovementSpeed();
float newOffset = offset + movementSpeed;
if ((int) newOffset != (int) offset)
@ -122,7 +122,7 @@ public abstract class LinearActuatorTileEntity extends KineticTileEntity
return;
}
}
if (!contraptionPresent || !movedContraption.isStalled())
offset = newOffset;
@ -173,10 +173,15 @@ public abstract class LinearActuatorTileEntity extends KineticTileEntity
@Override
public void setRemoved() {
super.setRemoved();
}
@Override
protected void setRemovedNotDueToChunkUnload() {
this.remove = true;
if (!level.isClientSide)
disassemble();
super.setRemoved();
super.setRemovedNotDueToChunkUnload();
}
@Override
@ -261,13 +266,13 @@ public abstract class LinearActuatorTileEntity extends KineticTileEntity
movedContraption.setContraptionMotion(Vec3.ZERO);
return false;
}
Vec3 motion = getMotionVector();
movedContraption.setContraptionMotion(getMotionVector());
movedContraption.move(motion.x, motion.y, motion.z);
return ContraptionCollider.collideBlocks(movedContraption);
}
protected void collided() {
if (level.isClientSide) {
waitingForSpeedChange = true;

View file

@ -197,12 +197,17 @@ public class BasinTileEntity extends SmartTileEntity implements IHaveGoggleInfor
@Override
public void setRemoved() {
onEmptied();
itemCapability.invalidate();
fluidCapability.invalidate();
super.setRemoved();
}
@Override
protected void setRemovedNotDueToChunkUnload() {
onEmptied();
super.setRemovedNotDueToChunkUnload();
}
@Nonnull
@Override
public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap, Direction side) {
@ -288,7 +293,7 @@ public class BasinTileEntity extends SmartTileEntity implements IHaveGoggleInfor
tryClearingSpoutputOverflow();
if (!contentsChanged)
return;
contentsChanged = false;
getOperator().ifPresent(te -> te.basinChecker.scheduleUpdate());
@ -312,7 +317,7 @@ public class BasinTileEntity extends SmartTileEntity implements IHaveGoggleInfor
Direction direction = blockState.getValue(BasinBlock.FACING);
BlockEntity te = level.getBlockEntity(worldPosition.below()
.relative(direction));
FilteringBehaviour filter = null;
InvManipulationBehaviour inserter = null;
if (te != null) {
@ -362,7 +367,7 @@ public class BasinTileEntity extends SmartTileEntity implements IHaveGoggleInfor
update = true;
continue;
}
if (targetTank == null)
break;
@ -459,7 +464,7 @@ public class BasinTileEntity extends SmartTileEntity implements IHaveGoggleInfor
Direction direction = blockState.getValue(BasinBlock.FACING);
if (direction != Direction.DOWN) {
BlockEntity te = level.getBlockEntity(worldPosition.below()
.relative(direction));
@ -472,7 +477,7 @@ public class BasinTileEntity extends SmartTileEntity implements IHaveGoggleInfor
: te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, direction.getOpposite())
.orElse(null);
boolean externalTankNotPresent = targetTank == null;
if (!outputItems.isEmpty() && targetInv == null)
return false;
if (!outputFluids.isEmpty() && externalTankNotPresent) {
@ -484,7 +489,7 @@ public class BasinTileEntity extends SmartTileEntity implements IHaveGoggleInfor
if (!acceptFluidOutputsIntoBasin(outputFluids, simulate, targetTank))
return false;
}
if (simulate)
return true;
for (ItemStack itemStack : outputItems) {

View file

@ -146,10 +146,30 @@ public abstract class SmartTileEntity extends SyncedTileEntity implements IParti
.reduce(ItemRequirement.NONE, (a, b) -> a.with(b.getRequiredItems()), (a, b) -> a.with(b));
}
/* TODO: Remove this hack once this issue is resolved: https://github.com/MinecraftForge/MinecraftForge/issues/8302
Once the PR linked in the issue is accepted, we should use the new method for determining whether setRemoved was
called due to a chunk unload or not, and remove this volatile workaround
*/
private boolean unloaded;
@Override
public void onChunkUnloaded() {
super.onChunkUnloaded();
unloaded = true;
}
protected void setRemovedNotDueToChunkUnload() {
}
@Override
public void setRemoved() {
forEachBehaviour(TileEntityBehaviour::remove);
super.setRemoved();
if (!unloaded) {
setRemovedNotDueToChunkUnload();
}
}
public void setLazyTickRate(int slowTickRate) {