Skip to content

Commit

Permalink
Quantum Chest Voiding + Quantum Storage Improvements (#2078)
Browse files Browse the repository at this point in the history
  • Loading branch information
ghzdude authored and serenibyss committed Nov 23, 2023
1 parent 87e9810 commit f5f3f6c
Show file tree
Hide file tree
Showing 10 changed files with 602 additions and 110 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public static int assignId() {
public static final int UPDATE_OUTPUT_FACING = assignId();
public static final int UPDATE_AUTO_OUTPUT_ITEMS = assignId();
public static final int UPDATE_AUTO_OUTPUT_FLUIDS = assignId();
public static final int UPDATE_IS_VOIDING = assignId();

// Drum
public static final int UPDATE_AUTO_OUTPUT = assignId();
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/gregtech/api/gui/GuiTextures.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ public class GuiTextures {
public static final TextureArea BUTTON_FLUID_OUTPUT = TextureArea.fullImage("textures/gui/widget/button_fluid_output_overlay.png");
public static final TextureArea BUTTON_ITEM_OUTPUT = TextureArea.fullImage("textures/gui/widget/button_item_output_overlay.png");
public static final TextureArea BUTTON_LOCK = TextureArea.fullImage("textures/gui/widget/button_lock.png");
public static final TextureArea BUTTON_VOID = TextureArea.fullImage("textures/gui/widget/button_void.png");
public static final TextureArea BUTTON_FLUID_VOID = TextureArea.fullImage("textures/gui/widget/button_fluid_void.png");
public static final TextureArea BUTTON_ITEM_VOID = TextureArea.fullImage("textures/gui/widget/button_item_void.png");
public static final TextureArea BUTTON_VOID_NONE = TextureArea.fullImage("textures/gui/widget/button_void_none.png");
public static final TextureArea BUTTON_VOID_MULTIBLOCK = TextureArea.fullImage("textures/gui/widget/button_void_multiblock.png");
public static final TextureArea BUTTON_LEFT = TextureArea.fullImage("textures/gui/widget/left.png");
Expand Down
28 changes: 28 additions & 0 deletions src/main/java/gregtech/api/util/TextFormattingUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,32 @@ public static String formatNumbers(double number) {
public static String formatNumbers(Object number) {
return NUMBER_FORMAT.format(number);
}

/**
* Formats a string to multiple lines, attempting to place a new line at the closest space from "maxLength" characters away.
* @param toFormat the string to be formatted to multiple lines.
* @param maxLength the length where a newline should be placed in the nearest space.
* @return a string formatted with newlines.
*/
public static String formatStringWithNewlines(String toFormat, int maxLength) {
String[] name = toFormat.split(" ");
StringBuilder builder = new StringBuilder();
int length = 0;
for (String s : name) {
length += s.length();

if (length > maxLength) {
builder.append("\n");
builder.append(s);
length = 0;
continue;
}

if (builder.length() != 0)
builder.append(" ");

builder.append(s);
}
return builder.toString();
}
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ public class MetaTileEntityQuantumTank extends MetaTileEntity implements ITiered
protected IFluidHandler outputFluidInventory;

@Nullable
private FluidStack previousFluid;
private boolean locked;
private boolean voiding;
protected FluidStack previousFluid;
protected boolean locked;
protected boolean voiding;
@Nullable
private FluidStack lockedFluid;

Expand Down Expand Up @@ -135,7 +135,7 @@ public void update() {
}

// should only be called on the server
private void updatePreviousFluid(FluidStack currentFluid) {
protected void updatePreviousFluid(FluidStack currentFluid) {
previousFluid = currentFluid == null ? null : currentFluid.copy();
writeCustomData(UPDATE_FLUID, buf -> buf.writeCompoundTag(currentFluid == null ? null : currentFluid.writeToNBT(new NBTTagCompound())));
}
Expand Down Expand Up @@ -337,7 +337,7 @@ protected ModularUI createUI(EntityPlayer entityPlayer) {
.setTooltipText("gregtech.gui.fluid_lock.tooltip")
.shouldUseBaseBackground())
.widget(new ToggleButtonWidget(43, 64, 18, 18,
GuiTextures.BUTTON_VOID, this::isVoiding, this::setVoiding)
GuiTextures.BUTTON_FLUID_VOID, this::isVoiding, this::setVoiding)
.setTooltipText("gregtech.gui.fluid_voiding.tooltip")
.shouldUseBaseBackground())
.bindPlayerInventory(entityPlayer.inventory)
Expand Down Expand Up @@ -440,6 +440,8 @@ public void receiveCustomData(int dataId, PacketBuffer buf) {
stack.amount = Math.min(buf.readInt(), fluidTank.getCapacity());
scheduleRenderUpdate();
}
} else if (dataId == UPDATE_IS_VOIDING) {
setVoiding(buf.readBoolean());
}
}

Expand All @@ -455,6 +457,7 @@ public void writeInitialSyncData(PacketBuffer buf) {
buf.writeBoolean(autoOutputFluids);
buf.writeBoolean(locked);
buf.writeCompoundTag(fluidTank.getFluid() == null ? null : fluidTank.getFluid().writeToNBT(new NBTTagCompound()));
buf.writeBoolean(voiding);
}

@Override
Expand All @@ -476,6 +479,7 @@ public void receiveInitialSyncData(PacketBuffer buf) {
} catch (IOException e) {
GTLog.logger.warn("Failed to load fluid from NBT in a quantum tank at " + this.getPos() + " on initial server/client sync");
}
this.voiding = buf.readBoolean();
}

public void setOutputFacing(EnumFacing outputFacing) {
Expand Down Expand Up @@ -559,11 +563,11 @@ public void setAutoOutputFluids(boolean autoOutputFluids) {
}
}

private boolean isLocked() {
protected boolean isLocked() {
return this.locked;
}

private void setLocked(boolean locked) {
protected void setLocked(boolean locked) {
if (this.locked == locked) return;
this.locked = locked;
if (!getWorld().isRemote) {
Expand All @@ -577,13 +581,14 @@ private void setLocked(boolean locked) {
this.lockedFluid = null;
}

private boolean isVoiding() {
protected boolean isVoiding() {
return voiding;
}

private void setVoiding(boolean isPartialVoid) {
protected void setVoiding(boolean isPartialVoid) {
this.voiding = isPartialVoid;
if (!getWorld().isRemote) {
writeCustomData(UPDATE_IS_VOIDING, buf -> buf.writeBoolean(this.voiding));
markDirty();
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/main/resources/assets/gregtech/lang/en_us.lang
Original file line number Diff line number Diff line change
Expand Up @@ -5260,7 +5260,7 @@ gregtech.universal.tooltip.energy_storage_capacity=§cEnergy Capacity: §f%,d EU
gregtech.universal.tooltip.energy_tier_range=§aAllowed Voltage Tiers: §f%s §f- %s
gregtech.universal.tooltip.item_storage_capacity=§6Item Slots: §f%,d
gregtech.universal.tooltip.item_storage_total=§6Item Capacity: §f%,d items
gregtech.universal.tooltip.item_stored=§dItem Stored: §f%s, %,d items
gregtech.universal.tooltip.item_stored=§dItem Stored: §f%s, %,d + %,d items
gregtech.universal.tooltip.item_transfer_rate=§bTransfer Rate: §f%,d items/s
gregtech.universal.tooltip.item_transfer_rate_stacks=§bTransfer Rate: §f%,d stacks/s
gregtech.universal.tooltip.fluid_storage_capacity=§9Fluid Capacity: §f%,d L
Expand Down Expand Up @@ -5366,6 +5366,8 @@ gregtech.gui.fluid_lock.tooltip.enabled=Fluid Locking Enabled
gregtech.gui.fluid_lock.tooltip.disabled=Fluid Locking Disabled
gregtech.gui.fluid_voiding.tooltip.enabled=Excess Fluid Voiding Enabled
gregtech.gui.fluid_voiding.tooltip.disabled=Excess Fluid Voiding Disabled
gregtech.gui.item_voiding.tooltip.enabled=Excess Item Voiding Enabled
gregtech.gui.item_voiding.tooltip.disabled=Excess Item Voiding Disabled
gregtech.gui.multiblock_item_voiding=Voiding Mode/n§7Voiding §6Items
gregtech.gui.multiblock_fluid_voiding=Voiding Mode/n§7Voiding §9Fluids
gregtech.gui.multiblock_item_fluid_voiding=Voiding Mode/n§7Voiding §6Items §7and §9Fluids
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit f5f3f6c

Please sign in to comment.