mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-11-18 16:02:19 +01:00
Pulley a Stunt
- Fluid manipulation of Hose Pulleys can no longer cause chunks to be loaded - Hose Pulleys no longer lose infinite status upon un- and reloading - Hose Pulleys now retain infinite status if surrounding lake is not fully loaded - Fixed Hose Pulley not loading in extended on the client side
This commit is contained in:
parent
fecb410909
commit
450359b212
4 changed files with 49 additions and 23 deletions
|
@ -86,7 +86,7 @@ public class FluidDrainingBehaviour extends FluidManipulationBehaviour {
|
||||||
while (!queue.isEmpty()) {
|
while (!queue.isEmpty()) {
|
||||||
// Dont dequeue here, so we can decide not to dequeue a valid entry when
|
// Dont dequeue here, so we can decide not to dequeue a valid entry when
|
||||||
// simulating
|
// simulating
|
||||||
BlockPos currentPos = queue.first().pos;
|
BlockPos currentPos = queue.first().pos();
|
||||||
BlockState blockState = world.getBlockState(currentPos);
|
BlockState blockState = world.getBlockState(currentPos);
|
||||||
BlockState emptied = blockState;
|
BlockState emptied = blockState;
|
||||||
Fluid fluid = Fluids.EMPTY;
|
Fluid fluid = Fluids.EMPTY;
|
||||||
|
@ -262,10 +262,15 @@ public class FluidDrainingBehaviour extends FluidManipulationBehaviour {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void continueSearch() {
|
private void continueSearch() {
|
||||||
fluid = search(fluid, frontier, visited, (e, d) -> {
|
try {
|
||||||
queue.enqueue(new BlockPosEntry(e, d));
|
fluid = search(fluid, frontier, visited, (e, d) -> {
|
||||||
validationSet.add(e);
|
queue.enqueue(new BlockPosEntry(e, d));
|
||||||
}, false);
|
validationSet.add(e);
|
||||||
|
}, false);
|
||||||
|
} catch (ChunkNotLoadedException e) {
|
||||||
|
tileEntity.sendData();
|
||||||
|
visited.clear();
|
||||||
|
}
|
||||||
|
|
||||||
Level world = getWorld();
|
Level world = getWorld();
|
||||||
int maxBlocks = maxBlocks();
|
int maxBlocks = maxBlocks();
|
||||||
|
@ -273,14 +278,14 @@ public class FluidDrainingBehaviour extends FluidManipulationBehaviour {
|
||||||
infinite = true;
|
infinite = true;
|
||||||
// Find first block with valid fluid
|
// Find first block with valid fluid
|
||||||
while (true) {
|
while (true) {
|
||||||
BlockPos first = queue.first().pos;
|
BlockPos first = queue.first().pos();
|
||||||
if (canPullFluidsFrom(world.getBlockState(first), first) != FluidBlockType.SOURCE) {
|
if (canPullFluidsFrom(world.getBlockState(first), first) != FluidBlockType.SOURCE) {
|
||||||
queue.dequeue();
|
queue.dequeue();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
BlockPos firstValid = queue.first().pos;
|
BlockPos firstValid = queue.first().pos();
|
||||||
frontier.clear();
|
frontier.clear();
|
||||||
visited.clear();
|
visited.clear();
|
||||||
queue.clear();
|
queue.clear();
|
||||||
|
@ -297,7 +302,13 @@ public class FluidDrainingBehaviour extends FluidManipulationBehaviour {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void continueValidation() {
|
private void continueValidation() {
|
||||||
search(fluid, validationFrontier, validationVisited, (e, d) -> newValidationSet.add(e), false);
|
try {
|
||||||
|
search(fluid, validationFrontier, validationVisited, (e, d) -> newValidationSet.add(e), false);
|
||||||
|
} catch (ChunkNotLoadedException e) {
|
||||||
|
validationFrontier.clear();
|
||||||
|
setLongValidationTimer();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
int maxBlocks = maxBlocks();
|
int maxBlocks = maxBlocks();
|
||||||
if (validationVisited.size() > maxBlocks && canDrainInfinitely(fluid)) {
|
if (validationVisited.size() > maxBlocks && canDrainInfinitely(fluid)) {
|
||||||
|
|
|
@ -71,8 +71,15 @@ public class FluidFillingBehaviour extends FluidManipulationBehaviour {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void continueValidation(Fluid fluid) {
|
protected void continueValidation(Fluid fluid) {
|
||||||
search(fluid, infinityCheckFrontier, infinityCheckVisited,
|
try {
|
||||||
(p, d) -> infinityCheckFrontier.add(new BlockPosEntry(p, d)), true);
|
search(fluid, infinityCheckFrontier, infinityCheckVisited,
|
||||||
|
(p, d) -> infinityCheckFrontier.add(new BlockPosEntry(p, d)), true);
|
||||||
|
} catch (ChunkNotLoadedException e) {
|
||||||
|
infinityCheckFrontier.clear();
|
||||||
|
setLongValidationTimer();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
int maxBlocks = maxBlocks();
|
int maxBlocks = maxBlocks();
|
||||||
|
|
||||||
if (infinityCheckVisited.size() > maxBlocks && maxBlocks != -1 && !fillInfinite()) {
|
if (infinityCheckVisited.size() > maxBlocks && maxBlocks != -1 && !fillInfinite()) {
|
||||||
|
@ -154,7 +161,7 @@ public class FluidFillingBehaviour extends FluidManipulationBehaviour {
|
||||||
boolean success = false;
|
boolean success = false;
|
||||||
for (int i = 0; !success && !queue.isEmpty() && i < searchedPerTick; i++) {
|
for (int i = 0; !success && !queue.isEmpty() && i < searchedPerTick; i++) {
|
||||||
BlockPosEntry entry = queue.first();
|
BlockPosEntry entry = queue.first();
|
||||||
BlockPos currentPos = entry.pos;
|
BlockPos currentPos = entry.pos();
|
||||||
|
|
||||||
if (visited.contains(currentPos)) {
|
if (visited.contains(currentPos)) {
|
||||||
queue.dequeue();
|
queue.dequeue();
|
||||||
|
@ -223,7 +230,7 @@ public class FluidFillingBehaviour extends FluidManipulationBehaviour {
|
||||||
|
|
||||||
SpaceType nextSpaceType = getAtPos(world, offsetPos, fluid);
|
SpaceType nextSpaceType = getAtPos(world, offsetPos, fluid);
|
||||||
if (nextSpaceType != SpaceType.BLOCKING)
|
if (nextSpaceType != SpaceType.BLOCKING)
|
||||||
queue.enqueue(new BlockPosEntry(offsetPos, entry.distance + 1));
|
queue.enqueue(new BlockPosEntry(offsetPos, entry.distance() + 1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@ import com.simibubi.create.foundation.networking.AllPackets;
|
||||||
import com.simibubi.create.foundation.tileEntity.SmartTileEntity;
|
import com.simibubi.create.foundation.tileEntity.SmartTileEntity;
|
||||||
import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour;
|
import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour;
|
||||||
import com.simibubi.create.foundation.utility.Iterate;
|
import com.simibubi.create.foundation.utility.Iterate;
|
||||||
|
import com.simibubi.create.foundation.utility.NBTHelper;
|
||||||
import com.simibubi.create.foundation.utility.VecHelper;
|
import com.simibubi.create.foundation.utility.VecHelper;
|
||||||
|
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
|
@ -35,23 +36,20 @@ import net.minecraftforge.fluids.FluidStack;
|
||||||
|
|
||||||
public abstract class FluidManipulationBehaviour extends TileEntityBehaviour {
|
public abstract class FluidManipulationBehaviour extends TileEntityBehaviour {
|
||||||
|
|
||||||
protected static class BlockPosEntry {
|
public static record BlockPosEntry(BlockPos pos, int distance) {
|
||||||
public BlockPos pos;
|
};
|
||||||
public int distance;
|
|
||||||
|
public static class ChunkNotLoadedException extends Exception {
|
||||||
public BlockPosEntry(BlockPos pos, int distance) {
|
private static final long serialVersionUID = 1L;
|
||||||
this.pos = pos;
|
|
||||||
this.distance = distance;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BoundingBox affectedArea;
|
BoundingBox affectedArea;
|
||||||
BlockPos rootPos;
|
BlockPos rootPos;
|
||||||
boolean infinite;
|
boolean infinite;
|
||||||
protected boolean counterpartActed;
|
protected boolean counterpartActed;
|
||||||
|
|
||||||
// Search
|
// Search
|
||||||
static final int searchedPerTick = 256;
|
static final int searchedPerTick = 1024;
|
||||||
static final int validationTimerMin = 160;
|
static final int validationTimerMin = 160;
|
||||||
List<BlockPosEntry> frontier;
|
List<BlockPosEntry> frontier;
|
||||||
Set<BlockPos> visited;
|
Set<BlockPos> visited;
|
||||||
|
@ -143,7 +141,7 @@ public abstract class FluidManipulationBehaviour extends TileEntityBehaviour {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Fluid search(Fluid fluid, List<BlockPosEntry> frontier, Set<BlockPos> visited,
|
protected Fluid search(Fluid fluid, List<BlockPosEntry> frontier, Set<BlockPos> visited,
|
||||||
BiConsumer<BlockPos, Integer> add, boolean searchDownward) {
|
BiConsumer<BlockPos, Integer> add, boolean searchDownward) throws ChunkNotLoadedException {
|
||||||
Level world = getWorld();
|
Level world = getWorld();
|
||||||
int maxBlocks = maxBlocks();
|
int maxBlocks = maxBlocks();
|
||||||
int maxRange = canDrainInfinitely(fluid) ? maxRange() : maxRange() / 2;
|
int maxRange = canDrainInfinitely(fluid) ? maxRange() : maxRange() / 2;
|
||||||
|
@ -158,6 +156,9 @@ public abstract class FluidManipulationBehaviour extends TileEntityBehaviour {
|
||||||
continue;
|
continue;
|
||||||
visited.add(currentPos);
|
visited.add(currentPos);
|
||||||
|
|
||||||
|
if (!world.isLoaded(currentPos))
|
||||||
|
throw new ChunkNotLoadedException();
|
||||||
|
|
||||||
FluidState fluidState = world.getFluidState(currentPos);
|
FluidState fluidState = world.getFluidState(currentPos);
|
||||||
if (fluidState.isEmpty())
|
if (fluidState.isEmpty())
|
||||||
continue;
|
continue;
|
||||||
|
@ -175,6 +176,8 @@ public abstract class FluidManipulationBehaviour extends TileEntityBehaviour {
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
BlockPos offsetPos = currentPos.relative(side);
|
BlockPos offsetPos = currentPos.relative(side);
|
||||||
|
if (!world.isLoaded(offsetPos))
|
||||||
|
throw new ChunkNotLoadedException();
|
||||||
if (visited.contains(offsetPos))
|
if (visited.contains(offsetPos))
|
||||||
continue;
|
continue;
|
||||||
if (offsetPos.distSqr(rootPos) > maxRangeSq)
|
if (offsetPos.distSqr(rootPos) > maxRangeSq)
|
||||||
|
@ -221,6 +224,8 @@ public abstract class FluidManipulationBehaviour extends TileEntityBehaviour {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(CompoundTag nbt, boolean clientPacket) {
|
public void write(CompoundTag nbt, boolean clientPacket) {
|
||||||
|
if (infinite)
|
||||||
|
NBTHelper.putMarker(nbt, "Infinite");
|
||||||
if (rootPos != null)
|
if (rootPos != null)
|
||||||
nbt.put("LastPos", NbtUtils.writeBlockPos(rootPos));
|
nbt.put("LastPos", NbtUtils.writeBlockPos(rootPos));
|
||||||
if (affectedArea != null) {
|
if (affectedArea != null) {
|
||||||
|
@ -234,6 +239,7 @@ public abstract class FluidManipulationBehaviour extends TileEntityBehaviour {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void read(CompoundTag nbt, boolean clientPacket) {
|
public void read(CompoundTag nbt, boolean clientPacket) {
|
||||||
|
infinite = nbt.contains("Infinite");
|
||||||
if (nbt.contains("LastPos"))
|
if (nbt.contains("LastPos"))
|
||||||
rootPos = NbtUtils.readBlockPos(nbt.getCompound("LastPos"));
|
rootPos = NbtUtils.readBlockPos(nbt.getCompound("LastPos"));
|
||||||
if (nbt.contains("AffectedAreaFrom") && nbt.contains("AffectedAreaTo"))
|
if (nbt.contains("AffectedAreaFrom") && nbt.contains("AffectedAreaTo"))
|
||||||
|
|
|
@ -147,6 +147,8 @@ public class HosePulleyTileEntity extends KineticTileEntity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void write(CompoundTag compound, boolean clientPacket) {
|
protected void write(CompoundTag compound, boolean clientPacket) {
|
||||||
|
if (clientPacket)
|
||||||
|
offset.forceNextSync();
|
||||||
compound.put("Offset", offset.writeNBT());
|
compound.put("Offset", offset.writeNBT());
|
||||||
compound.put("Tank", internalTank.writeToNBT(new CompoundTag()));
|
compound.put("Tank", internalTank.writeToNBT(new CompoundTag()));
|
||||||
super.write(compound, clientPacket);
|
super.write(compound, clientPacket);
|
||||||
|
|
Loading…
Reference in a new issue