mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-12-27 23:47:38 +01:00
Bug fixes
- Fixed spout creating potions from any fluid - Fixed pipes not actually transferring the type of fluid selected by layer II flow propagation - Fixed some fluid handlers erasing nbt data of extracted fluidstacks - Fix sidedness issues in Config packets
This commit is contained in:
parent
f8b3a77f26
commit
64b2c61389
4 changed files with 73 additions and 32 deletions
|
@ -13,6 +13,7 @@ import java.util.function.Supplier;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
import com.simibubi.create.content.contraptions.fluids.PipeConnection.Flow;
|
import com.simibubi.create.content.contraptions.fluids.PipeConnection.Flow;
|
||||||
|
import com.simibubi.create.foundation.fluid.FluidHelper;
|
||||||
import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour;
|
import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour;
|
||||||
import com.simibubi.create.foundation.utility.BlockFace;
|
import com.simibubi.create.foundation.utility.BlockFace;
|
||||||
import com.simibubi.create.foundation.utility.Iterate;
|
import com.simibubi.create.foundation.utility.Iterate;
|
||||||
|
@ -29,7 +30,7 @@ import net.minecraftforge.fluids.capability.IFluidHandler.FluidAction;
|
||||||
public class FluidNetwork {
|
public class FluidNetwork {
|
||||||
|
|
||||||
private static int CYCLES_PER_TICK = 16;
|
private static int CYCLES_PER_TICK = 16;
|
||||||
|
|
||||||
World world;
|
World world;
|
||||||
BlockFace start;
|
BlockFace start;
|
||||||
|
|
||||||
|
@ -41,6 +42,7 @@ public class FluidNetwork {
|
||||||
List<BlockFace> queued;
|
List<BlockFace> queued;
|
||||||
Set<Pair<BlockFace, PipeConnection>> frontier;
|
Set<Pair<BlockFace, PipeConnection>> frontier;
|
||||||
Set<BlockPos> visited;
|
Set<BlockPos> visited;
|
||||||
|
FluidStack fluid;
|
||||||
List<Pair<BlockFace, LazyOptional<IFluidHandler>>> targets;
|
List<Pair<BlockFace, LazyOptional<IFluidHandler>>> targets;
|
||||||
Map<BlockPos, WeakReference<FluidTransportBehaviour>> cache;
|
Map<BlockPos, WeakReference<FluidTransportBehaviour>> cache;
|
||||||
|
|
||||||
|
@ -49,6 +51,7 @@ public class FluidNetwork {
|
||||||
this.start = location;
|
this.start = location;
|
||||||
this.sourceSupplier = sourceSupplier;
|
this.sourceSupplier = sourceSupplier;
|
||||||
this.source = LazyOptional.empty();
|
this.source = LazyOptional.empty();
|
||||||
|
this.fluid = FluidStack.EMPTY;
|
||||||
this.frontier = new HashSet<>();
|
this.frontier = new HashSet<>();
|
||||||
this.visited = new HashSet<>();
|
this.visited = new HashSet<>();
|
||||||
this.targets = new ArrayList<>();
|
this.targets = new ArrayList<>();
|
||||||
|
@ -62,7 +65,7 @@ public class FluidNetwork {
|
||||||
pauseBeforePropagation--;
|
pauseBeforePropagation--;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int cycle = 0; cycle < CYCLES_PER_TICK; cycle++) {
|
for (int cycle = 0; cycle < CYCLES_PER_TICK; cycle++) {
|
||||||
boolean shouldContinue = false;
|
boolean shouldContinue = false;
|
||||||
for (Iterator<BlockFace> iterator = queued.iterator(); iterator.hasNext();) {
|
for (Iterator<BlockFace> iterator = queued.iterator(); iterator.hasNext();) {
|
||||||
|
@ -77,17 +80,22 @@ public class FluidNetwork {
|
||||||
}
|
}
|
||||||
iterator.remove();
|
iterator.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
// drawDebugOutlines();
|
// drawDebugOutlines();
|
||||||
|
|
||||||
for (Iterator<Pair<BlockFace, PipeConnection>> iterator = frontier.iterator(); iterator.hasNext();) {
|
for (Iterator<Pair<BlockFace, PipeConnection>> iterator = frontier.iterator(); iterator.hasNext();) {
|
||||||
Pair<BlockFace, PipeConnection> pair = iterator.next();
|
Pair<BlockFace, PipeConnection> pair = iterator.next();
|
||||||
BlockFace blockFace = pair.getFirst();
|
BlockFace blockFace = pair.getFirst();
|
||||||
PipeConnection pipeConnection = pair.getSecond();
|
PipeConnection pipeConnection = pair.getSecond();
|
||||||
|
|
||||||
if (!pipeConnection.hasFlow())
|
if (!pipeConnection.hasFlow())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
Flow flow = pipeConnection.flow.get();
|
Flow flow = pipeConnection.flow.get();
|
||||||
|
if (!fluid.isEmpty() && !flow.fluid.isFluidEqual(fluid)) {
|
||||||
|
iterator.remove();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (!flow.inbound) {
|
if (!flow.inbound) {
|
||||||
if (pipeConnection.comparePressure() >= 0)
|
if (pipeConnection.comparePressure() >= 0)
|
||||||
iterator.remove();
|
iterator.remove();
|
||||||
|
@ -96,6 +104,9 @@ public class FluidNetwork {
|
||||||
if (!flow.complete)
|
if (!flow.complete)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
if (fluid.isEmpty())
|
||||||
|
fluid = flow.fluid;
|
||||||
|
|
||||||
boolean canRemove = true;
|
boolean canRemove = true;
|
||||||
for (Direction side : Iterate.directions) {
|
for (Direction side : Iterate.directions) {
|
||||||
if (side == blockFace.getFace())
|
if (side == blockFace.getFace())
|
||||||
|
@ -120,14 +131,14 @@ public class FluidNetwork {
|
||||||
canRemove = false;
|
canRemove = false;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (adjacent.source.isPresent() && adjacent.source.get()
|
if (adjacent.source.isPresent() && adjacent.source.get()
|
||||||
.isEndpoint()) {
|
.isEndpoint()) {
|
||||||
targets.add(Pair.of(adjacentLocation, adjacent.source.get()
|
targets.add(Pair.of(adjacentLocation, adjacent.source.get()
|
||||||
.provideHandler()));
|
.provideHandler()));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (visited.add(adjacentLocation.getConnectedPos())) {
|
if (visited.add(adjacentLocation.getConnectedPos())) {
|
||||||
queued.add(adjacentLocation.getOpposite());
|
queued.add(adjacentLocation.getOpposite());
|
||||||
shouldContinue = true;
|
shouldContinue = true;
|
||||||
|
@ -139,7 +150,7 @@ public class FluidNetwork {
|
||||||
if (!shouldContinue)
|
if (!shouldContinue)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// drawDebugOutlines();
|
// drawDebugOutlines();
|
||||||
|
|
||||||
if (!source.isPresent())
|
if (!source.isPresent())
|
||||||
|
@ -168,7 +179,18 @@ public class FluidNetwork {
|
||||||
IFluidHandler handler = source.orElse(null);
|
IFluidHandler handler = source.orElse(null);
|
||||||
if (handler == null)
|
if (handler == null)
|
||||||
return;
|
return;
|
||||||
FluidStack transfer = handler.drain(flowSpeed, action);
|
|
||||||
|
FluidStack transfer = FluidStack.EMPTY;
|
||||||
|
for (int i = 0; i < handler.getTanks(); i++) {
|
||||||
|
FluidStack contained = handler.getFluidInTank(i);
|
||||||
|
if (contained.isEmpty())
|
||||||
|
continue;
|
||||||
|
if (!contained.isFluidEqual(fluid))
|
||||||
|
continue;
|
||||||
|
FluidStack toExtract = FluidHelper.copyStackWithAmount(contained, flowSpeed);
|
||||||
|
transfer = handler.drain(toExtract, action);
|
||||||
|
}
|
||||||
|
|
||||||
if (transfer.isEmpty())
|
if (transfer.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -229,6 +251,7 @@ public class FluidNetwork {
|
||||||
visited.clear();
|
visited.clear();
|
||||||
targets.clear();
|
targets.clear();
|
||||||
queued.clear();
|
queued.clear();
|
||||||
|
fluid = FluidStack.EMPTY;
|
||||||
queued.add(start);
|
queued.add(start);
|
||||||
pauseBeforePropagation = 2;
|
pauseBeforePropagation = 2;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
package com.simibubi.create.content.contraptions.fluids.actors;
|
package com.simibubi.create.content.contraptions.fluids.actors;
|
||||||
|
|
||||||
|
import com.simibubi.create.AllFluids;
|
||||||
import com.simibubi.create.content.contraptions.fluids.potion.PotionFluidHandler;
|
import com.simibubi.create.content.contraptions.fluids.potion.PotionFluidHandler;
|
||||||
import com.simibubi.create.foundation.fluid.FluidHelper;
|
import com.simibubi.create.foundation.fluid.FluidHelper;
|
||||||
|
|
||||||
|
import net.minecraft.fluid.Fluids;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.item.Items;
|
import net.minecraft.item.Items;
|
||||||
|
@ -19,7 +21,7 @@ import net.minecraftforge.fluids.capability.wrappers.FluidBucketWrapper;
|
||||||
public class GenericItemFilling {
|
public class GenericItemFilling {
|
||||||
|
|
||||||
public static boolean canItemBeFilled(World world, ItemStack stack) {
|
public static boolean canItemBeFilled(World world, ItemStack stack) {
|
||||||
if (stack.getItem() == Items.GLASS_BOTTLE)
|
if (stack.getItem() == Items.GLASS_BOTTLE)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
LazyOptional<IFluidHandlerItem> capability =
|
LazyOptional<IFluidHandlerItem> capability =
|
||||||
|
@ -34,9 +36,9 @@ public class GenericItemFilling {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getRequiredAmountForItem(World world, ItemStack stack, FluidStack availableFluid) {
|
public static int getRequiredAmountForItem(World world, ItemStack stack, FluidStack availableFluid) {
|
||||||
if (stack.getItem() == Items.GLASS_BOTTLE)
|
if (stack.getItem() == Items.GLASS_BOTTLE && canFillGlassBottleInternally(availableFluid))
|
||||||
return PotionFluidHandler.getRequiredAmountForFilledBottle(stack, availableFluid);
|
return PotionFluidHandler.getRequiredAmountForFilledBottle(stack, availableFluid);
|
||||||
|
|
||||||
LazyOptional<IFluidHandlerItem> capability =
|
LazyOptional<IFluidHandlerItem> capability =
|
||||||
|
@ -45,7 +47,8 @@ public class GenericItemFilling {
|
||||||
if (tank == null)
|
if (tank == null)
|
||||||
return -1;
|
return -1;
|
||||||
if (tank instanceof FluidBucketWrapper) {
|
if (tank instanceof FluidBucketWrapper) {
|
||||||
Item filledBucket = availableFluid.getFluid().getFilledBucket();
|
Item filledBucket = availableFluid.getFluid()
|
||||||
|
.getFilledBucket();
|
||||||
if (filledBucket == null || filledBucket == Items.AIR)
|
if (filledBucket == null || filledBucket == Items.AIR)
|
||||||
return -1;
|
return -1;
|
||||||
return 1000;
|
return 1000;
|
||||||
|
@ -54,13 +57,20 @@ public class GenericItemFilling {
|
||||||
int filled = tank.fill(availableFluid, FluidAction.SIMULATE);
|
int filled = tank.fill(availableFluid, FluidAction.SIMULATE);
|
||||||
return filled == 0 ? -1 : filled;
|
return filled == 0 ? -1 : filled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean canFillGlassBottleInternally(FluidStack availableFluid) {
|
||||||
|
return availableFluid.getFluid()
|
||||||
|
.isEquivalentTo(Fluids.WATER)
|
||||||
|
|| availableFluid.getFluid()
|
||||||
|
.isEquivalentTo(AllFluids.POTION.get());
|
||||||
|
}
|
||||||
|
|
||||||
public static ItemStack fillItem(World world, int requiredAmount, ItemStack stack, FluidStack availableFluid) {
|
public static ItemStack fillItem(World world, int requiredAmount, ItemStack stack, FluidStack availableFluid) {
|
||||||
FluidStack toFill = availableFluid.copy();
|
FluidStack toFill = availableFluid.copy();
|
||||||
toFill.setAmount(requiredAmount);
|
toFill.setAmount(requiredAmount);
|
||||||
availableFluid.shrink(requiredAmount);
|
availableFluid.shrink(requiredAmount);
|
||||||
|
|
||||||
if (stack.getItem() == Items.GLASS_BOTTLE) {
|
if (stack.getItem() == Items.GLASS_BOTTLE && canFillGlassBottleInternally(availableFluid)) {
|
||||||
ItemStack fillBottle = ItemStack.EMPTY;
|
ItemStack fillBottle = ItemStack.EMPTY;
|
||||||
if (FluidHelper.isWater(toFill.getFluid()))
|
if (FluidHelper.isWater(toFill.getFluid()))
|
||||||
fillBottle = PotionUtils.addPotionToItemStack(new ItemStack(Items.POTION), Potions.WATER);
|
fillBottle = PotionUtils.addPotionToItemStack(new ItemStack(Items.POTION), Potions.WATER);
|
||||||
|
@ -83,5 +93,5 @@ public class GenericItemFilling {
|
||||||
stack.shrink(1);
|
stack.shrink(1);
|
||||||
return container;
|
return container;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,35 +57,42 @@ public class ConfigureConfigPacket extends SimplePacketBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
enum Actions {
|
enum Actions {
|
||||||
rainbowDebug((value) -> {
|
rainbowDebug(() -> Actions::rainbowDebug),
|
||||||
AllConfigs.CLIENT.rainbowDebug.set(Boolean.parseBoolean(value));
|
overlayScreen(() -> Actions::overlayScreen),
|
||||||
}),
|
fixLighting(() -> Actions::experimentalLighting),
|
||||||
overlayScreen(Actions::overlayScreenAction),
|
overlayReset(() -> Actions::overlayReset),
|
||||||
fixLighting(Actions::experimentalLightingAction),
|
|
||||||
overlayReset((value) -> {
|
|
||||||
AllConfigs.CLIENT.overlayOffsetX.set(0);
|
|
||||||
AllConfigs.CLIENT.overlayOffsetY.set(0);
|
|
||||||
}),
|
|
||||||
|
|
||||||
;
|
;
|
||||||
|
|
||||||
private final Consumer<String> consumer;
|
private final Supplier<Consumer<String>> consumer;
|
||||||
|
|
||||||
Actions(Consumer<String> action) {
|
Actions(Supplier<Consumer<String>> action) {
|
||||||
this.consumer = action;
|
this.consumer = action;
|
||||||
}
|
}
|
||||||
|
|
||||||
void performAction(String value) {
|
void performAction(String value) {
|
||||||
consumer.accept(value);
|
consumer.get()
|
||||||
|
.accept(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@OnlyIn(Dist.CLIENT)
|
@OnlyIn(Dist.CLIENT)
|
||||||
private static void overlayScreenAction(String value) {
|
private static void rainbowDebug(String value) {
|
||||||
|
AllConfigs.CLIENT.rainbowDebug.set(Boolean.parseBoolean(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
@OnlyIn(Dist.CLIENT)
|
||||||
|
private static void overlayReset(String value) {
|
||||||
|
AllConfigs.CLIENT.overlayOffsetX.set(0);
|
||||||
|
AllConfigs.CLIENT.overlayOffsetY.set(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@OnlyIn(Dist.CLIENT)
|
||||||
|
private static void overlayScreen(String value) {
|
||||||
ScreenOpener.open(new GoggleConfigScreen());
|
ScreenOpener.open(new GoggleConfigScreen());
|
||||||
}
|
}
|
||||||
|
|
||||||
@OnlyIn(Dist.CLIENT)
|
@OnlyIn(Dist.CLIENT)
|
||||||
private static void experimentalLightingAction(String value) {
|
private static void experimentalLighting(String value) {
|
||||||
ForgeConfig.CLIENT.experimentalForgeLightPipelineEnabled.set(true);
|
ForgeConfig.CLIENT.experimentalForgeLightPipelineEnabled.set(true);
|
||||||
Minecraft.getInstance().worldRenderer.loadRenderers();
|
Minecraft.getInstance().worldRenderer.loadRenderers();
|
||||||
}
|
}
|
||||||
|
|
|
@ -108,7 +108,8 @@ public class CombinedTankWrapper implements IFluidHandler {
|
||||||
resource.shrink(amount);
|
resource.shrink(amount);
|
||||||
|
|
||||||
if (!drainedFromCurrent.isEmpty() && (drained.isEmpty() || drainedFromCurrent.isFluidEqual(drained)))
|
if (!drainedFromCurrent.isEmpty() && (drained.isEmpty() || drainedFromCurrent.isFluidEqual(drained)))
|
||||||
drained = new FluidStack(drainedFromCurrent.getFluid(), amount + drained.getAmount(), drained.getTag());
|
drained = new FluidStack(drainedFromCurrent.getFluid(), amount + drained.getAmount(),
|
||||||
|
drainedFromCurrent.getTag());
|
||||||
if (resource.isEmpty())
|
if (resource.isEmpty())
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue