mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-12-27 07:27:15 +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 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.utility.BlockFace;
|
||||
import com.simibubi.create.foundation.utility.Iterate;
|
||||
|
@ -29,7 +30,7 @@ import net.minecraftforge.fluids.capability.IFluidHandler.FluidAction;
|
|||
public class FluidNetwork {
|
||||
|
||||
private static int CYCLES_PER_TICK = 16;
|
||||
|
||||
|
||||
World world;
|
||||
BlockFace start;
|
||||
|
||||
|
@ -41,6 +42,7 @@ public class FluidNetwork {
|
|||
List<BlockFace> queued;
|
||||
Set<Pair<BlockFace, PipeConnection>> frontier;
|
||||
Set<BlockPos> visited;
|
||||
FluidStack fluid;
|
||||
List<Pair<BlockFace, LazyOptional<IFluidHandler>>> targets;
|
||||
Map<BlockPos, WeakReference<FluidTransportBehaviour>> cache;
|
||||
|
||||
|
@ -49,6 +51,7 @@ public class FluidNetwork {
|
|||
this.start = location;
|
||||
this.sourceSupplier = sourceSupplier;
|
||||
this.source = LazyOptional.empty();
|
||||
this.fluid = FluidStack.EMPTY;
|
||||
this.frontier = new HashSet<>();
|
||||
this.visited = new HashSet<>();
|
||||
this.targets = new ArrayList<>();
|
||||
|
@ -62,7 +65,7 @@ public class FluidNetwork {
|
|||
pauseBeforePropagation--;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
for (int cycle = 0; cycle < CYCLES_PER_TICK; cycle++) {
|
||||
boolean shouldContinue = false;
|
||||
for (Iterator<BlockFace> iterator = queued.iterator(); iterator.hasNext();) {
|
||||
|
@ -77,17 +80,22 @@ public class FluidNetwork {
|
|||
}
|
||||
iterator.remove();
|
||||
}
|
||||
|
||||
|
||||
// drawDebugOutlines();
|
||||
|
||||
|
||||
for (Iterator<Pair<BlockFace, PipeConnection>> iterator = frontier.iterator(); iterator.hasNext();) {
|
||||
Pair<BlockFace, PipeConnection> pair = iterator.next();
|
||||
BlockFace blockFace = pair.getFirst();
|
||||
PipeConnection pipeConnection = pair.getSecond();
|
||||
|
||||
|
||||
if (!pipeConnection.hasFlow())
|
||||
continue;
|
||||
|
||||
Flow flow = pipeConnection.flow.get();
|
||||
if (!fluid.isEmpty() && !flow.fluid.isFluidEqual(fluid)) {
|
||||
iterator.remove();
|
||||
continue;
|
||||
}
|
||||
if (!flow.inbound) {
|
||||
if (pipeConnection.comparePressure() >= 0)
|
||||
iterator.remove();
|
||||
|
@ -96,6 +104,9 @@ public class FluidNetwork {
|
|||
if (!flow.complete)
|
||||
continue;
|
||||
|
||||
if (fluid.isEmpty())
|
||||
fluid = flow.fluid;
|
||||
|
||||
boolean canRemove = true;
|
||||
for (Direction side : Iterate.directions) {
|
||||
if (side == blockFace.getFace())
|
||||
|
@ -120,14 +131,14 @@ public class FluidNetwork {
|
|||
canRemove = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if (adjacent.source.isPresent() && adjacent.source.get()
|
||||
.isEndpoint()) {
|
||||
targets.add(Pair.of(adjacentLocation, adjacent.source.get()
|
||||
.provideHandler()));
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if (visited.add(adjacentLocation.getConnectedPos())) {
|
||||
queued.add(adjacentLocation.getOpposite());
|
||||
shouldContinue = true;
|
||||
|
@ -139,7 +150,7 @@ public class FluidNetwork {
|
|||
if (!shouldContinue)
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
// drawDebugOutlines();
|
||||
|
||||
if (!source.isPresent())
|
||||
|
@ -168,7 +179,18 @@ public class FluidNetwork {
|
|||
IFluidHandler handler = source.orElse(null);
|
||||
if (handler == null)
|
||||
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())
|
||||
return;
|
||||
|
||||
|
@ -229,6 +251,7 @@ public class FluidNetwork {
|
|||
visited.clear();
|
||||
targets.clear();
|
||||
queued.clear();
|
||||
fluid = FluidStack.EMPTY;
|
||||
queued.add(start);
|
||||
pauseBeforePropagation = 2;
|
||||
}
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
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.foundation.fluid.FluidHelper;
|
||||
|
||||
import net.minecraft.fluid.Fluids;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
|
@ -19,7 +21,7 @@ import net.minecraftforge.fluids.capability.wrappers.FluidBucketWrapper;
|
|||
public class GenericItemFilling {
|
||||
|
||||
public static boolean canItemBeFilled(World world, ItemStack stack) {
|
||||
if (stack.getItem() == Items.GLASS_BOTTLE)
|
||||
if (stack.getItem() == Items.GLASS_BOTTLE)
|
||||
return true;
|
||||
|
||||
LazyOptional<IFluidHandlerItem> capability =
|
||||
|
@ -34,9 +36,9 @@ public class GenericItemFilling {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
|
||||
LazyOptional<IFluidHandlerItem> capability =
|
||||
|
@ -45,7 +47,8 @@ public class GenericItemFilling {
|
|||
if (tank == null)
|
||||
return -1;
|
||||
if (tank instanceof FluidBucketWrapper) {
|
||||
Item filledBucket = availableFluid.getFluid().getFilledBucket();
|
||||
Item filledBucket = availableFluid.getFluid()
|
||||
.getFilledBucket();
|
||||
if (filledBucket == null || filledBucket == Items.AIR)
|
||||
return -1;
|
||||
return 1000;
|
||||
|
@ -54,13 +57,20 @@ public class GenericItemFilling {
|
|||
int filled = tank.fill(availableFluid, FluidAction.SIMULATE);
|
||||
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) {
|
||||
FluidStack toFill = availableFluid.copy();
|
||||
toFill.setAmount(requiredAmount);
|
||||
availableFluid.shrink(requiredAmount);
|
||||
|
||||
if (stack.getItem() == Items.GLASS_BOTTLE) {
|
||||
|
||||
if (stack.getItem() == Items.GLASS_BOTTLE && canFillGlassBottleInternally(availableFluid)) {
|
||||
ItemStack fillBottle = ItemStack.EMPTY;
|
||||
if (FluidHelper.isWater(toFill.getFluid()))
|
||||
fillBottle = PotionUtils.addPotionToItemStack(new ItemStack(Items.POTION), Potions.WATER);
|
||||
|
@ -83,5 +93,5 @@ public class GenericItemFilling {
|
|||
stack.shrink(1);
|
||||
return container;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -57,35 +57,42 @@ public class ConfigureConfigPacket extends SimplePacketBase {
|
|||
}
|
||||
|
||||
enum Actions {
|
||||
rainbowDebug((value) -> {
|
||||
AllConfigs.CLIENT.rainbowDebug.set(Boolean.parseBoolean(value));
|
||||
}),
|
||||
overlayScreen(Actions::overlayScreenAction),
|
||||
fixLighting(Actions::experimentalLightingAction),
|
||||
overlayReset((value) -> {
|
||||
AllConfigs.CLIENT.overlayOffsetX.set(0);
|
||||
AllConfigs.CLIENT.overlayOffsetY.set(0);
|
||||
}),
|
||||
rainbowDebug(() -> Actions::rainbowDebug),
|
||||
overlayScreen(() -> Actions::overlayScreen),
|
||||
fixLighting(() -> Actions::experimentalLighting),
|
||||
overlayReset(() -> Actions::overlayReset),
|
||||
|
||||
;
|
||||
|
||||
private final Consumer<String> consumer;
|
||||
private final Supplier<Consumer<String>> consumer;
|
||||
|
||||
Actions(Consumer<String> action) {
|
||||
Actions(Supplier<Consumer<String>> action) {
|
||||
this.consumer = action;
|
||||
}
|
||||
|
||||
void performAction(String value) {
|
||||
consumer.accept(value);
|
||||
consumer.get()
|
||||
.accept(value);
|
||||
}
|
||||
|
||||
@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());
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
private static void experimentalLightingAction(String value) {
|
||||
private static void experimentalLighting(String value) {
|
||||
ForgeConfig.CLIENT.experimentalForgeLightPipelineEnabled.set(true);
|
||||
Minecraft.getInstance().worldRenderer.loadRenderers();
|
||||
}
|
||||
|
|
|
@ -108,7 +108,8 @@ public class CombinedTankWrapper implements IFluidHandler {
|
|||
resource.shrink(amount);
|
||||
|
||||
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())
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue