Lots of fixes
This commit is contained in:
@@ -35,12 +35,12 @@ public class FluidLevelEmitterScreen extends UpgradeableScreen<FluidLevelEmitter
|
||||
this.level = new NumberEntryWidget(this, 20, 17, 138, 62, NumberEntryType.LEVEL_FLUID_VOLUME,
|
||||
this::onLevelChange);
|
||||
this.level.setTextFieldBounds(25, 44, 75);
|
||||
container.setTextField(this.level);
|
||||
handler.setTextField(this.level);
|
||||
this.level.addButtons(children::add, this::addButton);
|
||||
|
||||
final int y = 40;
|
||||
final int x = 80 + 57;
|
||||
this.guiSlots.add(new FluidSlotWidget(this.container.getFluidConfigInventory(), 0, 0, x, y));
|
||||
this.guiSlots.add(new FluidSlotWidget(this.handler.getFluidConfigInventory(), 0, 0, x, y));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -57,10 +57,10 @@ public class FluidLevelEmitterScreen extends UpgradeableScreen<FluidLevelEmitter
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawFG(int offsetX, int offsetY, int mouseX, int mouseY) {
|
||||
super.drawFG(offsetX, offsetY, mouseX, mouseY);
|
||||
public void drawFG(MatrixStack matrices, int offsetX, int offsetY, int mouseX, int mouseY) {
|
||||
super.drawFG(matrices, offsetX, offsetY, mouseX, mouseY);
|
||||
|
||||
this.font.drawString(GuiText.FluidLevelEmitterUnit.getLocal(), 110, 44, COLOR_DARK_GRAY);
|
||||
this.textRenderer.draw(matrices, GuiText.FluidLevelEmitterUnit.getLocal(), 110, 44, COLOR_DARK_GRAY);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,24 +1,23 @@
|
||||
package appeng.fluids.client.gui.widgets;
|
||||
|
||||
import java.math.RoundingMode;
|
||||
import java.util.Collections;
|
||||
|
||||
import alexiil.mc.lib.attributes.Simulation;
|
||||
import alexiil.mc.lib.attributes.fluid.FluidAttributes;
|
||||
import alexiil.mc.lib.attributes.fluid.FluidExtractable;
|
||||
import alexiil.mc.lib.attributes.fluid.amount.FluidAmount;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.text.Text;
|
||||
import alexiil.mc.lib.attributes.fluid.GroupedFluidInvView;
|
||||
import alexiil.mc.lib.attributes.fluid.volume.FluidKey;
|
||||
import alexiil.mc.lib.attributes.fluid.volume.FluidVolume;
|
||||
|
||||
import appeng.api.storage.data.IAEFluidStack;
|
||||
import appeng.client.gui.widgets.CustomSlotWidget;
|
||||
import appeng.core.sync.network.NetworkHandler;
|
||||
import appeng.core.sync.packets.FluidSlotPacket;
|
||||
import appeng.fluids.util.AEFluidStack;
|
||||
import appeng.fluids.util.IAEFluidTank;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.text.Text;
|
||||
|
||||
import java.math.RoundingMode;
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
public class FluidSlotWidget extends CustomSlotWidget {
|
||||
private final IAEFluidTank fluids;
|
||||
@@ -50,9 +49,11 @@ public class FluidSlotWidget extends CustomSlotWidget {
|
||||
if (clickStack.isEmpty() || mouseButton == 1) {
|
||||
this.setFluidStack(null);
|
||||
} else if (mouseButton == 0) {
|
||||
FluidExtractable extractable = FluidAttributes.EXTRACTABLE.getFirstOrNull(clickStack);
|
||||
if (extractable != null && extractable.couldExtractAnything()) {
|
||||
FluidVolume volume = extractable.attemptAnyExtraction(FluidAmount.MAX_VALUE, Simulation.ACTION);
|
||||
GroupedFluidInvView groupView = FluidAttributes.GROUPED_INV_VIEW.get(clickStack);
|
||||
Set<FluidKey> fluids = groupView.getStoredFluids();
|
||||
if (!fluids.isEmpty()) {
|
||||
FluidKey firstFluid = groupView.getStoredFluids().iterator().next();
|
||||
FluidVolume volume = firstFluid.withAmount(groupView.getAmount_F(firstFluid));
|
||||
this.setFluidStack(AEFluidStack.fromFluidVolume(volume, RoundingMode.DOWN));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@ public class FluidTankWidget extends AbstractButtonWidget implements ITooltip {
|
||||
|
||||
return desc.copy().append("\n").append(amountToText);
|
||||
}
|
||||
return "";
|
||||
return LiteralText.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -25,9 +25,12 @@ import java.nio.BufferOverflowException;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import alexiil.mc.lib.attributes.Simulation;
|
||||
import alexiil.mc.lib.attributes.fluid.FixedFluidInv;
|
||||
import alexiil.mc.lib.attributes.fluid.FluidAttributes;
|
||||
import alexiil.mc.lib.attributes.fluid.FluidExtractable;
|
||||
import alexiil.mc.lib.attributes.fluid.FluidInsertable;
|
||||
import alexiil.mc.lib.attributes.fluid.GroupedFluidInv;
|
||||
import alexiil.mc.lib.attributes.fluid.SingleFluidTank;
|
||||
import alexiil.mc.lib.attributes.fluid.amount.FluidAmount;
|
||||
import alexiil.mc.lib.attributes.fluid.filter.ExactFluidFilter;
|
||||
import alexiil.mc.lib.attributes.fluid.volume.FluidVolume;
|
||||
@@ -327,9 +330,10 @@ public class FluidTerminalContainer extends AEBaseContainer
|
||||
}
|
||||
|
||||
// Check how much we can store in the item
|
||||
FluidVolume volumeAllowed = insertable.attemptInsertion(this.clientRequestedTargetFluid.getFluidStack().withAmount(FluidAmount.MAX_VALUE), Simulation.SIMULATE);
|
||||
FluidVolume volumeOverflow = insertable.attemptInsertion(this.clientRequestedTargetFluid.getFluidStack().withAmount(FluidAmount.ofWhole(Long.MAX_VALUE)), Simulation.SIMULATE);
|
||||
FluidAmount amountAllowed = FluidAmount.ofWhole(Long.MAX_VALUE).saturatedSub(volumeOverflow.amount());
|
||||
|
||||
final IAEFluidStack stack = AEFluidStack.fromFluidVolume(this.clientRequestedTargetFluid.getFluidStack().withAmount(volumeAllowed.amount()), RoundingMode.DOWN);
|
||||
final IAEFluidStack stack = AEFluidStack.fromFluidVolume(this.clientRequestedTargetFluid.getFluidStack().withAmount(amountAllowed), RoundingMode.DOWN);
|
||||
if (stack == null) {
|
||||
return; // Might be nothing allowed...
|
||||
}
|
||||
@@ -342,13 +346,13 @@ public class FluidTerminalContainer extends AEBaseContainer
|
||||
}
|
||||
|
||||
// How much could fit into the container
|
||||
volumeAllowed = insertable.attemptInsertion(canPull.getFluidStack(), Simulation.SIMULATE);
|
||||
if (volumeAllowed.isEmpty()) {
|
||||
volumeOverflow = insertable.attemptInsertion(canPull.getFluidStack(), Simulation.SIMULATE);
|
||||
if (!volumeOverflow.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Now actually pull out of the system
|
||||
stack.setStackSize(volumeAllowed.amount().asLong(1000, RoundingMode.DOWN));
|
||||
stack.setStackSize(canPull.getStackSize());
|
||||
final IAEFluidStack pulled = Platform.poweredExtraction(this.getPowerSource(), this.monitor, stack,
|
||||
this.getActionSource());
|
||||
if (pulled == null || pulled.getStackSize() < 1) {
|
||||
@@ -358,11 +362,11 @@ public class FluidTerminalContainer extends AEBaseContainer
|
||||
}
|
||||
|
||||
// Actually fill
|
||||
final FluidVolume reallyFilled = insertable.attemptInsertion(pulled.getFluidStack(), Simulation.ACTION);
|
||||
volumeOverflow = insertable.attemptInsertion(pulled.getFluidStack(), Simulation.ACTION);
|
||||
|
||||
if (!reallyFilled.amount().equals(volumeAllowed.amount())) {
|
||||
AELog.error("Fluid item [%s] reported a different possible amount than it actually accepted.",
|
||||
held.getName());
|
||||
if (!volumeOverflow.isEmpty()) {
|
||||
AELog.error("Fluid item [%s] reported a different possible amount than it actually accepted. Overflow: %s.",
|
||||
held, volumeOverflow);
|
||||
}
|
||||
|
||||
player.inventory.setCursorStack(container.get());
|
||||
|
||||
@@ -4,7 +4,7 @@ package appeng.fluids.parts;
|
||||
import alexiil.mc.lib.attributes.Simulation;
|
||||
import alexiil.mc.lib.attributes.fluid.amount.FluidAmount;
|
||||
import alexiil.mc.lib.attributes.fluid.volume.FluidVolume;
|
||||
import appeng.core.Api;
|
||||
import alexiil.mc.lib.attributes.fluid.world.FluidWorldUtil;
|
||||
import appeng.api.config.AccessRestriction;
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.config.IncludeExclude;
|
||||
@@ -42,16 +42,14 @@ import net.minecraft.block.FluidBlock;
|
||||
import net.minecraft.block.FluidFillable;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.fluid.Fluid;
|
||||
import net.minecraft.fluid.FluidState;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.screen.ScreenHandlerType;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.BlockView;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldAccess;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.math.RoundingMode;
|
||||
@@ -116,7 +114,7 @@ public class FluidFormationPlanePart extends AbstractFormationPlanePart<IAEFluid
|
||||
final BlockPos pos = te.getPos().offset(side.getFacing());
|
||||
|
||||
FluidVolume volume = input.getFluidStack();
|
||||
FluidVolume remainder = fill(w, pos, volume, type == Actionable.MODULATE ? Simulation.ACTION : Simulation.SIMULATE);
|
||||
FluidVolume remainder = FluidWorldUtil.fill(w, pos, volume, type == Actionable.MODULATE ? Simulation.ACTION : Simulation.SIMULATE);
|
||||
if (remainder.getAmount_F().isLessThan(volume.getAmount_F())) {
|
||||
// calculate the effective amount consumed
|
||||
// round UP here because we might otherwise duplicate fluids
|
||||
@@ -132,62 +130,6 @@ public class FluidFormationPlanePart extends AbstractFormationPlanePart<IAEFluid
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME https://github.com/AlexIIL/LibBlockAttributes/pull/21
|
||||
/**
|
||||
* Attempts to fill the given block with a bucket's worth of fluid
|
||||
* @return The remainder of the given fluid volume after placing a bucket
|
||||
*/
|
||||
public static FluidVolume fill(WorldAccess world, BlockPos pos, FluidVolume volume, Simulation simulation) {
|
||||
|
||||
if (volume.getAmount_F().isLessThan(FluidAmount.BUCKET)) {
|
||||
return volume; // Need at least a buckets worth
|
||||
}
|
||||
|
||||
Fluid fluid = volume.getRawFluid();
|
||||
if (fluid == null) {
|
||||
return volume; // Can't be placed if it doesn't have an associated vanilla fluid
|
||||
}
|
||||
|
||||
// This code assumes that placing a fluid in the world will always consume a bucket's worth
|
||||
boolean success = false;
|
||||
|
||||
BlockState state = world.getBlockState(pos);
|
||||
Block block = state.getBlock();
|
||||
if (state.isAir()) {
|
||||
// The easiest case, probably
|
||||
if (simulation == Simulation.ACTION) {
|
||||
BlockState fluidStillState = fluid.getDefaultState().getBlockState();
|
||||
world.setBlockState(pos, fluidStillState, 3);
|
||||
}
|
||||
success = true;
|
||||
|
||||
} else if (block instanceof FluidFillable) {
|
||||
// FluidFillable includes waterloggable blocks, but not cauldrons, etc.
|
||||
FluidFillable fillable = (FluidFillable) block;
|
||||
if (simulation == Simulation.SIMULATE) {
|
||||
success = fillable.canFillWithFluid(world, pos, state, fluid);
|
||||
} else {
|
||||
success = fillable.tryFillWithFluid(world, pos, state, fluid.getDefaultState());
|
||||
}
|
||||
} else if (block instanceof FluidBlock) {
|
||||
FluidState fluidState = world.getFluidState(pos);
|
||||
// Top up a non-still fluid block, but this consumes a full bucket regardless of the level
|
||||
if (!fluidState.isStill() && fluidState.getFluid() == fluid) {
|
||||
if (simulation == Simulation.ACTION) {
|
||||
world.setBlockState(pos, fluid.getDefaultState().getBlockState(), 3);
|
||||
}
|
||||
success = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (success) {
|
||||
// Reduce by one bucket
|
||||
return volume.copy().withAmount(volume.getAmount_F().roundedSub(FluidAmount.ONE, RoundingMode.DOWN));
|
||||
} else {
|
||||
return volume;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFluidInventoryChanged(IAEFluidTank inv, int slot) {
|
||||
if (inv == this.config) {
|
||||
@@ -195,6 +137,13 @@ public class FluidFormationPlanePart extends AbstractFormationPlanePart<IAEFluid
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean isBlocking(BlockView w, BlockPos pos) {
|
||||
// Mirror the restrictions from the fill method
|
||||
BlockState state = w.getBlockState(pos);
|
||||
Block block = state.getBlock();
|
||||
return !state.isAir() && !(block instanceof FluidFillable) && !(block instanceof FluidBlock);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(final CompoundTag data) {
|
||||
super.readFromNBT(data);
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
package appeng.fluids.util;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import alexiil.mc.lib.attributes.fluid.amount.FluidAmount;
|
||||
import alexiil.mc.lib.attributes.fluid.volume.FluidKey;
|
||||
@@ -48,10 +47,8 @@ public final class AEFluidStack extends AEStack<IAEFluidStack> implements IAEFlu
|
||||
private static final String NBT_REQUESTABLE = "req";
|
||||
private static final String NBT_CRAFTABLE = "craft";
|
||||
private static final String NBT_FLUID_ID = "f";
|
||||
private static final String NBT_FLUID_TAG = "ft";
|
||||
|
||||
private final FluidKey fluid;
|
||||
private CompoundTag tagCompound;
|
||||
|
||||
private AEFluidStack(final AEFluidStack fluidStack) {
|
||||
this.fluid = fluidStack.fluid;
|
||||
@@ -60,18 +57,13 @@ public final class AEFluidStack extends AEStack<IAEFluidStack> implements IAEFlu
|
||||
// priority = is.priority;
|
||||
this.setCraftable(fluidStack.isCraftable());
|
||||
this.setCountRequestable(fluidStack.getCountRequestable());
|
||||
|
||||
if (fluidStack.hasTagCompound()) {
|
||||
this.tagCompound = fluidStack.tagCompound.copy();
|
||||
}
|
||||
}
|
||||
|
||||
private AEFluidStack(@Nonnull FluidKey fluid, long amount, @Nullable CompoundTag tag) {
|
||||
private AEFluidStack(@Nonnull FluidKey fluid, long amount) {
|
||||
this.fluid = Preconditions.checkNotNull(fluid);
|
||||
this.setStackSize(amount);
|
||||
this.setCraftable(false);
|
||||
this.setCountRequestable(0);
|
||||
this.tagCompound = tag;
|
||||
}
|
||||
|
||||
public static AEFluidStack fromFluidVolume(final FluidVolume input, RoundingMode roundingMode) {
|
||||
@@ -84,14 +76,9 @@ public final class AEFluidStack extends AEStack<IAEFluidStack> implements IAEFlu
|
||||
throw new IllegalArgumentException("Fluid is null.");
|
||||
}
|
||||
|
||||
CompoundTag tag = input.toTag();
|
||||
if (tag.isEmpty()) {
|
||||
tag = null;
|
||||
}
|
||||
|
||||
long amount = input.amount().asLong(1000, roundingMode);
|
||||
|
||||
return new AEFluidStack(fluid, amount, tag);
|
||||
return new AEFluidStack(fluid, amount);
|
||||
}
|
||||
|
||||
public static IAEFluidStack fromNBT(final CompoundTag data) {
|
||||
@@ -101,14 +88,9 @@ public final class AEFluidStack extends AEStack<IAEFluidStack> implements IAEFlu
|
||||
return null;
|
||||
}
|
||||
|
||||
CompoundTag tag = null;
|
||||
if (data.contains(NBT_FLUID_TAG, NbtType.COMPOUND)) {
|
||||
tag = data.getCompound(NBT_FLUID_TAG);
|
||||
}
|
||||
|
||||
long amount = data.getLong(NBT_STACKSIZE);
|
||||
|
||||
AEFluidStack fluidStack = new AEFluidStack(fluid, amount, tag);
|
||||
AEFluidStack fluidStack = new AEFluidStack(fluid, amount);
|
||||
fluidStack.setCountRequestable(data.getLong(NBT_REQUESTABLE));
|
||||
fluidStack.setCraftable(data.getBoolean(NBT_CRAFTABLE));
|
||||
return fluidStack;
|
||||
@@ -127,9 +109,6 @@ public final class AEFluidStack extends AEStack<IAEFluidStack> implements IAEFlu
|
||||
@Override
|
||||
public void writeToNBT(final CompoundTag data) {
|
||||
data.put(NBT_FLUID_ID, this.fluid.toTag());
|
||||
if (this.hasTagCompound()) {
|
||||
data.put(NBT_FLUID_TAG, this.tagCompound);
|
||||
}
|
||||
data.putLong(NBT_STACKSIZE, this.getStackSize());
|
||||
data.putLong(NBT_REQUESTABLE, this.getCountRequestable());
|
||||
data.putBoolean(NBT_CRAFTABLE, this.isCraftable());
|
||||
@@ -162,12 +141,7 @@ public final class AEFluidStack extends AEStack<IAEFluidStack> implements IAEFlu
|
||||
if (this.fluid != other.fluid) {
|
||||
return this.fluid.entry.getId().compareTo(other.fluid.entry.getId());
|
||||
}
|
||||
|
||||
if (Platform.itemComparisons().isNbtTagEqual(this.tagCompound, other.tagCompound)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return this.tagCompound.hashCode() - other.tagCompound.hashCode();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -175,7 +149,6 @@ public final class AEFluidStack extends AEStack<IAEFluidStack> implements IAEFlu
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((this.fluid == null) ? 0 : this.fluid.hashCode());
|
||||
result = prime * result + ((this.tagCompound == null) ? 0 : this.tagCompound.hashCode());
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -184,29 +157,28 @@ public final class AEFluidStack extends AEStack<IAEFluidStack> implements IAEFlu
|
||||
public boolean equals(final Object other) {
|
||||
if (other instanceof AEFluidStack) {
|
||||
final AEFluidStack is = (AEFluidStack) other;
|
||||
return is.fluid == this.fluid && Platform.itemComparisons().isNbtTagEqual(this.tagCompound, is.tagCompound);
|
||||
return is.fluid == this.fluid;
|
||||
} else if (other instanceof FluidVolume) {
|
||||
final FluidVolume is = (FluidVolume) other;
|
||||
return is.getFluidKey() == this.fluid
|
||||
&& Platform.itemComparisons().isNbtTagEqual(this.tagCompound, is.toTag());
|
||||
return is.getFluidKey() == this.fluid;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.getStackSize() + "x" + this.getFluidStack().getFluidKey().entry.getId() + " " + this.tagCompound;
|
||||
return this.getStackSize() + "x" + this.getFluidStack().getFluidKey().entry.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTagCompound() {
|
||||
return this.tagCompound != null;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidVolume getFluidStack() {
|
||||
FluidAmount amount = FluidAmount.of(this.getStackSize(), 1000);
|
||||
return this.fluid.readVolume(tagCompound).withAmount(amount);
|
||||
return this.fluid.withAmount(amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -234,11 +206,10 @@ public final class AEFluidStack extends AEStack<IAEFluidStack> implements IAEFlu
|
||||
final boolean isCraftable = buffer.readBoolean();
|
||||
|
||||
FluidKey fluid = FluidKey.fromTag(buffer.readCompoundTag());
|
||||
CompoundTag compoundTag = buffer.readCompoundTag();
|
||||
final long amount = buffer.readVarLong();
|
||||
final long countRequestable = buffer.readVarLong();
|
||||
|
||||
final AEFluidStack fluidStack = new AEFluidStack(fluid, amount, compoundTag);
|
||||
final AEFluidStack fluidStack = new AEFluidStack(fluid, amount);
|
||||
fluidStack.setCountRequestable(countRequestable);
|
||||
fluidStack.setCraftable(isCraftable);
|
||||
return fluidStack;
|
||||
@@ -248,7 +219,6 @@ public final class AEFluidStack extends AEStack<IAEFluidStack> implements IAEFlu
|
||||
public void writeToPacket(final PacketByteBuf buffer) {
|
||||
buffer.writeBoolean(this.isCraftable());
|
||||
buffer.writeCompoundTag(fluid.toTag());
|
||||
buffer.writeCompoundTag(tagCompound);
|
||||
buffer.writeVarLong(this.getStackSize());
|
||||
buffer.writeVarLong(this.getCountRequestable());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user