Added HWYLA

This commit is contained in:
Sebastian Hartte
2020-07-05 16:50:39 +02:00
parent 1478e4c378
commit 9220ca0048
97 changed files with 2123 additions and 613 deletions
@@ -0,0 +1,65 @@
package appeng.fluids.client.gui;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.text.Text;
import appeng.client.gui.implementations.UpgradeableScreen;
import appeng.client.gui.widgets.TabButton;
import appeng.container.implementations.PriorityContainer;
import appeng.core.localization.GuiText;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.SwitchGuisPacket;
import appeng.fluids.client.gui.widgets.FluidSlotWidget;
import appeng.fluids.client.gui.widgets.OptionalFluidSlotWidget;
import appeng.fluids.container.FluidFormationPlaneContainer;
import appeng.fluids.util.IAEFluidTank;
public class FluidFormationPlaneScreen extends UpgradeableScreen<FluidFormationPlaneContainer> {
public FluidFormationPlaneScreen(FluidFormationPlaneContainer container, PlayerInventory playerInventory,
Text title) {
super(container, playerInventory, title);
this.backgroundHeight = 251;
}
@Override
public void init() {
super.init();
final int xo = 8;
final int yo = 23 + 6;
final IAEFluidTank config = handler.getFluidConfigInventory();
for (int y = 0; y < 7; y++) {
for (int x = 0; x < 9; x++) {
final int idx = y * 9 + x;
if (y < 2) {
this.guiSlots.add(new FluidSlotWidget(config, idx, idx, xo + x * 18, yo + y * 18));
} else {
this.guiSlots.add(new OptionalFluidSlotWidget(config, handler, idx, idx, y - 2, xo, yo, x, y));
}
}
}
}
@Override
protected void addButtons() {
this.addButton(new TabButton(this.x + 154, this.y, 2 + 4 * 16, GuiText.Priority.text(),
this.itemRenderer, btn -> openPriorityGui()));
}
private void openPriorityGui() {
NetworkHandler.instance().sendToServer(new SwitchGuisPacket(PriorityContainer.TYPE));
}
@Override
protected String getBackground() {
return "guis/storagebus.png";
}
@Override
protected GuiText getName() {
return GuiText.FluidFormationPlane;
}
}
@@ -0,0 +1,67 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2018, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.fluids.client.gui;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.text.Text;
import appeng.client.gui.implementations.UpgradeableScreen;
import appeng.core.localization.GuiText;
import appeng.fluids.client.gui.widgets.FluidSlotWidget;
import appeng.fluids.client.gui.widgets.OptionalFluidSlotWidget;
import appeng.fluids.container.FluidIOContainer;
import appeng.fluids.parts.FluidImportBusPart;
import appeng.fluids.util.IAEFluidTank;
/**
* @author BrockWS
* @version rv5 - 1/05/2018
* @since rv5 1/05/2018
*/
public class FluidIOScreen extends UpgradeableScreen<FluidIOContainer> {
public FluidIOScreen(FluidIOContainer container, PlayerInventory playerInventory, Text title) {
super(container, playerInventory, title);
}
@Override
public void init() {
super.init();
final IAEFluidTank inv = this.handler.getFluidConfigInventory();
final int y = 40;
final int x = 80;
this.guiSlots.add(new FluidSlotWidget(inv, 0, 0, x, y));
this.guiSlots.add(new OptionalFluidSlotWidget(inv, handler, 1, 1, 1, x, y, -1, 0));
this.guiSlots.add(new OptionalFluidSlotWidget(inv, handler, 2, 2, 1, x, y, 1, 0));
this.guiSlots.add(new OptionalFluidSlotWidget(inv, handler, 3, 3, 1, x, y, 0, -1));
this.guiSlots.add(new OptionalFluidSlotWidget(inv, handler, 4, 4, 1, x, y, 0, 1));
this.guiSlots.add(new OptionalFluidSlotWidget(inv, handler, 5, 5, 2, x, y, -1, -1));
this.guiSlots.add(new OptionalFluidSlotWidget(inv, handler, 6, 6, 2, x, y, 1, -1));
this.guiSlots.add(new OptionalFluidSlotWidget(inv, handler, 7, 7, 2, x, y, -1, 1));
this.guiSlots.add(new OptionalFluidSlotWidget(inv, handler, 8, 8, 2, x, y, 1, 1));
}
@Override
protected GuiText getName() {
return this.bc instanceof FluidImportBusPart ? GuiText.ImportBusFluids : GuiText.ExportBusFluids;
}
}
@@ -0,0 +1,89 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2018, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.fluids.client.gui;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.text.Text;
import appeng.client.gui.implementations.UpgradeableScreen;
import appeng.client.gui.widgets.TabButton;
import appeng.container.implementations.PriorityContainer;
import appeng.core.localization.GuiText;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.SwitchGuisPacket;
import appeng.fluids.client.gui.widgets.FluidSlotWidget;
import appeng.fluids.client.gui.widgets.FluidTankWidget;
import appeng.fluids.container.FluidInterfaceContainer;
import appeng.fluids.helper.DualityFluidInterface;
import appeng.fluids.util.IAEFluidTank;
public class FluidInterfaceScreen extends UpgradeableScreen<FluidInterfaceContainer> {
public FluidInterfaceScreen(FluidInterfaceContainer container, PlayerInventory playerInventory,
Text title) {
super(container, playerInventory, title);
this.backgroundHeight = 231;
}
@Override
public void init() {
super.init();
final IAEFluidTank configFluids = this.handler.getFluidConfigInventory();
final IAEFluidTank fluidTank = this.handler.getTanks();
for (int i = 0; i < DualityFluidInterface.NUMBER_OF_TANKS; ++i) {
final FluidTankWidget guiTank = new FluidTankWidget(fluidTank, i, this.getX() + 35 + 18 * i,
this.getY() + 53, 16, 68);
this.addButton(guiTank);
this.guiSlots.add(new FluidSlotWidget(configFluids, i, i, 35 + 18 * i, 35));
}
this.addButton(new TabButton(this.getX() + 154, this.getY(), 2 + 4 * 16, GuiText.Priority.text(),
this.itemRenderer, btn -> openPriorityGui()));
}
@Override
protected void addButtons() {
}
@Override
public void drawFG(MatrixStack matrices, int offsetX, int offsetY, int mouseX, int mouseY) {
this.textRenderer.draw(matrices, this.getGuiDisplayName(GuiText.FluidInterface.text()), 8, 6, 4210752);
this.textRenderer.draw(matrices, GuiText.Config.getLocal(), 35, 6 + 11 + 7, 4210752);
this.textRenderer.draw(matrices, GuiText.StoredFluids.getLocal(), 35, 6 + 112 + 7, 4210752);
this.textRenderer.draw(matrices, GuiText.inventory.getLocal(), 8, this.backgroundHeight - 96 + 3, 4210752);
}
@Override
public void drawBG(MatrixStack matrices, int offsetX, int offsetY, int mouseX, int mouseY, float partialTicks) {
this.bindTexture("guis/interfacefluid.png");
drawTexture(matrices, offsetX, offsetY, 0, 0, this.backgroundWidth, this.backgroundHeight);
}
private void openPriorityGui() {
NetworkHandler.instance().sendToServer(new SwitchGuisPacket(PriorityContainer.TYPE));
}
@Override
protected boolean drawUpgrades() {
return false;
}
}
@@ -0,0 +1,181 @@
package appeng.fluids.client.gui;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.text.LiteralText;
import net.minecraft.text.Text;
import appeng.api.config.RedstoneMode;
import appeng.api.config.Settings;
import appeng.client.gui.implementations.UpgradeableScreen;
import appeng.client.gui.widgets.NumberBox;
import appeng.client.gui.widgets.ServerSettingToggleButton;
import appeng.core.AEConfig;
import appeng.core.localization.GuiText;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.ConfigValuePacket;
import appeng.fluids.client.gui.widgets.FluidSlotWidget;
import appeng.fluids.container.FluidLevelEmitterContainer;
public class FluidLevelEmitterScreen extends UpgradeableScreen<FluidLevelEmitterContainer> {
private NumberBox level;
public FluidLevelEmitterScreen(FluidLevelEmitterContainer container, PlayerInventory playerInventory,
Text title) {
super(container, playerInventory, title);
}
@Override
public void init() {
super.init();
this.level = new NumberBox(this.textRenderer, this.x + 24, this.y + 43, 79, this.textRenderer.fontHeight,
Long.class);
this.level.setHasBorder(false);
this.level.setMaxLength(16);
this.level.setEditableColor(0xFFFFFF);
this.level.setVisible(true);
this.level.changeFocus(true);
handler.setTextField(this.level);
final int y = 40;
final int x = 80 + 44;
this.guiSlots.add(new FluidSlotWidget(this.handler.getFluidConfigInventory(), 0, 0, x, y));
}
@Override
protected void addButtons() {
this.redstoneMode = new ServerSettingToggleButton<>(this.x - 18, this.y + 28,
Settings.REDSTONE_EMITTER, RedstoneMode.LOW_SIGNAL);
final int a = AEConfig.instance().levelByMillyBuckets(0);
final int b = AEConfig.instance().levelByMillyBuckets(1);
final int c = AEConfig.instance().levelByMillyBuckets(2);
final int d = AEConfig.instance().levelByMillyBuckets(3);
this.addButton(new ButtonWidget(this.x + 20, this.y + 17, 22, 20, new LiteralText("+" + a), btn -> addQty(a)));
this.addButton(new ButtonWidget(this.x + 48, this.y + 17, 28, 20, new LiteralText("+" + b), btn -> addQty(b)));
this.addButton(new ButtonWidget(this.x + 82, this.y + 17, 32, 20, new LiteralText("+" + c), btn -> addQty(c)));
this.addButton(new ButtonWidget(this.x + 120, this.y + 17, 38, 20, new LiteralText("+" + d), btn -> addQty(d)));
this.addButton(new ButtonWidget(this.x + 20, this.y + 59, 22, 20, new LiteralText("-" + a), btn -> addQty(-a)));
this.addButton(new ButtonWidget(this.x + 48, this.y + 59, 28, 20, new LiteralText("-" + b), btn -> addQty(-b)));
this.addButton(new ButtonWidget(this.x + 82, this.y + 59, 32, 20, new LiteralText("-" + c), btn -> addQty(-c)));
this.addButton(new ButtonWidget(this.x + 120, this.y + 59, 38, 20, new LiteralText("-" + d), btn -> addQty(-d)));
this.addButton(this.redstoneMode);
}
@Override
public void drawBG(MatrixStack matrices, final int offsetX, final int offsetY, final int mouseX, final int mouseY, float partialTicks) {
super.drawBG(matrices, offsetX, offsetY, mouseX, mouseY, partialTicks);
this.level.render(matrices, mouseX, mouseY, partialTicks);
}
@Override
protected boolean drawUpgrades() {
return false;
}
@Override
protected String getBackground() {
return "guis/lvlemitter.png";
}
@Override
protected GuiText getName() {
return GuiText.FluidLevelEmitter;
}
@Override
protected void handleButtonVisibility() {
}
private void addQty(final long i) {
try {
String Out = this.level.getText();
boolean Fixed = false;
while (Out.startsWith("0") && Out.length() > 1) {
Out = Out.substring(1);
Fixed = true;
}
if (Fixed) {
this.level.setText(Out);
}
if (Out.isEmpty()) {
Out = "0";
}
long result = Long.parseLong(Out);
result += i;
if (result < 0) {
result = 0;
}
this.level.setText(Out = Long.toString(result));
NetworkHandler.instance().sendToServer(new ConfigValuePacket("FluidLevelEmitter.Value", Out));
} catch (final NumberFormatException e) {
// nope..
this.level.setText("0");
}
}
@Override
public boolean charTyped(char character, int keyCode) {
if (level.charTyped(character, keyCode)) {
String Out = this.level.getText();
boolean Fixed = false;
while (Out.startsWith("0") && Out.length() > 1) {
Out = Out.substring(1);
Fixed = true;
}
if (Fixed) {
this.level.setText(Out);
}
if (Out.isEmpty()) {
Out = "0";
}
NetworkHandler.instance().sendToServer(new ConfigValuePacket("FluidLevelEmitter.Value", Out));
return true;
}
return super.charTyped(character, keyCode);
}
@Override
public boolean keyPressed(int keyCode, int scanCode, int p_keyPressed_3_) {
if (!this.checkHotbarKeys(keyCode, scanCode)) {
if ((keyCode == 211 || keyCode == 205 || keyCode == 203 || keyCode == 14)
&& this.level.keyPressed(keyCode, scanCode, p_keyPressed_3_)) {
String Out = this.level.getText();
boolean Fixed = false;
while (Out.startsWith("0") && Out.length() > 1) {
Out = Out.substring(1);
Fixed = true;
}
if (Fixed) {
this.level.setText(Out);
}
if (Out.isEmpty()) {
Out = "0";
}
NetworkHandler.instance().sendToServer(new ConfigValuePacket("FluidLevelEmitter.Value", Out));
return true;
}
}
return super.keyPressed(keyCode, scanCode, p_keyPressed_3_);
}
}
@@ -0,0 +1,139 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2018, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.fluids.client.gui;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.text.Text;
import appeng.api.config.AccessRestriction;
import appeng.api.config.ActionItems;
import appeng.api.config.FuzzyMode;
import appeng.api.config.Settings;
import appeng.api.config.StorageFilter;
import appeng.client.gui.implementations.UpgradeableScreen;
import appeng.client.gui.widgets.ActionButton;
import appeng.client.gui.widgets.ServerSettingToggleButton;
import appeng.client.gui.widgets.SettingToggleButton;
import appeng.client.gui.widgets.TabButton;
import appeng.container.implementations.PriorityContainer;
import appeng.core.localization.GuiText;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.ConfigValuePacket;
import appeng.core.sync.packets.SwitchGuisPacket;
import appeng.fluids.client.gui.widgets.FluidSlotWidget;
import appeng.fluids.client.gui.widgets.OptionalFluidSlotWidget;
import appeng.fluids.container.FluidStorageBusContainer;
import appeng.fluids.util.IAEFluidTank;
/**
* @author BrockWS
* @version rv6 - 22/05/2018
* @since rv6 22/05/2018
*/
public class FluidStorageBusScreen extends UpgradeableScreen<FluidStorageBusContainer> {
private SettingToggleButton<AccessRestriction> rwMode;
private SettingToggleButton<StorageFilter> storageFilter;
public FluidStorageBusScreen(FluidStorageBusContainer container, PlayerInventory playerInventory,
Text title) {
super(container, playerInventory, title);
this.backgroundHeight = 251;
}
@Override
public void init() {
super.init();
final int xo = 8;
final int yo = 23 + 6;
final IAEFluidTank config = this.handler.getFluidConfigInventory();
for (int y = 0; y < 7; y++) {
for (int x = 0; x < 9; x++) {
final int idx = y * 9 + x;
if (y < 2) {
this.guiSlots.add(new FluidSlotWidget(config, idx, idx, xo + x * 18, yo + y * 18));
} else {
this.guiSlots.add(new OptionalFluidSlotWidget(config, handler, idx, idx, y - 2, xo, yo, x, y));
}
}
}
}
@Override
protected void addButtons() {
addButton(new ActionButton(this.x - 18, this.y + 8, ActionItems.CLOSE, btn -> clear()));
addButton(new ActionButton(this.x - 18, this.y + 28, ActionItems.WRENCH, btn -> partition()));
this.rwMode = new ServerSettingToggleButton<>(this.x - 18, this.y + 48, Settings.ACCESS,
AccessRestriction.READ_WRITE);
this.storageFilter = new ServerSettingToggleButton<>(this.x - 18, this.y + 68,
Settings.STORAGE_FILTER, StorageFilter.EXTRACTABLE_ONLY);
this.fuzzyMode = new ServerSettingToggleButton<>(this.x - 18, this.y + 88, Settings.FUZZY_MODE,
FuzzyMode.IGNORE_ALL);
addButton(this.addButton(new TabButton(this.x + 154, this.y, 2 + 4 * 16, GuiText.Priority.text(),
this.itemRenderer, btn -> openPriorityGui())));
this.addButton(this.storageFilter);
this.addButton(this.fuzzyMode);
this.addButton(this.rwMode);
}
@Override
public void drawFG(MatrixStack matrices, final int offsetX, final int offsetY, final int mouseX, final int mouseY) {
this.textRenderer.draw(matrices, this.getGuiDisplayName(this.getName().text()), 8, 6, 4210752);
this.textRenderer.draw(matrices, GuiText.inventory.getLocal(), 8, this.backgroundHeight - 96 + 3, 4210752);
if (this.fuzzyMode != null) {
this.fuzzyMode.set(this.cvb.getFuzzyMode());
}
if (this.storageFilter != null) {
this.storageFilter.set(((FluidStorageBusContainer) this.cvb).getStorageFilter());
}
if (this.rwMode != null) {
this.rwMode.set(((FluidStorageBusContainer) this.cvb).getReadWriteMode());
}
}
@Override
protected String getBackground() {
return "guis/storagebus.png";
}
private void partition() {
NetworkHandler.instance().sendToServer(new ConfigValuePacket("StorageBus.Action", "Partition"));
}
private void clear() {
NetworkHandler.instance().sendToServer(new ConfigValuePacket("StorageBus.Action", "Clear"));
}
private void openPriorityGui() {
NetworkHandler.instance().sendToServer(new SwitchGuisPacket(PriorityContainer.TYPE));
}
@Override
protected GuiText getName() {
return GuiText.StorageBusFluids;
}
}
@@ -127,7 +127,7 @@ public class FluidTerminalScreen extends AEBaseMEScreen<FluidTerminalContainer>
@Override
public void drawFG(MatrixStack matrices, int offsetX, int offsetY, int mouseX, int mouseY) {
this.textRenderer.draw(matrices, this.getGuiDisplayName("Fluid Terminal"), 8, 6, 4210752);
this.textRenderer.draw(matrices, this.getGuiDisplayName(new LiteralText("Fluid Terminal")), 8, 6, 4210752);
this.textRenderer.draw(matrices, GuiText.inventory.getLocal(), 8, this.backgroundHeight - 96 + 3, 4210752);
}
@@ -0,0 +1,84 @@
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.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;
public class FluidSlotWidget extends CustomSlotWidget {
private final IAEFluidTank fluids;
private final int slot;
public FluidSlotWidget(final IAEFluidTank fluids, final int slot, final int id, final int x, final int y) {
super(id, x, y);
this.fluids = fluids;
this.slot = slot;
}
@Override
public void drawContent(final MinecraftClient mc, final int mouseX, final int mouseY, final float partialTicks) {
final IAEFluidStack fs = this.getFluidStack();
if (fs != null) {
fs.getFluidStack().renderGuiRect(xPos(), yPos(), xPos() + getWidth(), yPos() + getHeight());
}
}
@Override
public boolean canClick(final PlayerEntity player) {
final ItemStack mouseStack = player.inventory.getCursorStack();
return mouseStack.isEmpty()
|| FluidAttributes.EXTRACTABLE.getFirstOrNull(mouseStack) != null;
}
@Override
public void slotClicked(final ItemStack clickStack, int mouseButton) {
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);
this.setFluidStack(AEFluidStack.fromFluidVolume(volume, RoundingMode.DOWN));
}
}
}
@Override
public Text getMessage() {
final IAEFluidStack fluid = this.getFluidStack();
if (fluid != null) {
return fluid.getFluidStack().getName();
}
return null;
}
@Override
public boolean isVisible() {
return true;
}
public IAEFluidStack getFluidStack() {
return this.fluids.getFluidInSlot(this.slot);
}
public void setFluidStack(final IAEFluidStack stack) {
this.fluids.setFluidInSlot(this.slot, stack);
NetworkHandler.instance()
.sendToServer(new FluidSlotPacket(Collections.singletonMap(this.getId(), this.getFluidStack())));
}
}
@@ -0,0 +1,119 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2018, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.fluids.client.gui.widgets;
import alexiil.mc.lib.attributes.fluid.amount.FluidAmount;
import alexiil.mc.lib.attributes.fluid.volume.FluidVolume;
import appeng.api.storage.data.IAEFluidStack;
import appeng.api.util.AEColor;
import appeng.client.gui.widgets.ITooltip;
import appeng.fluids.util.IAEFluidTank;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.gui.widget.AbstractButtonWidget;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.LiteralText;
import net.minecraft.text.Text;
@Environment(EnvType.CLIENT)
public class FluidTankWidget extends AbstractButtonWidget implements ITooltip {
private final IAEFluidTank tank;
private final int slot;
public FluidTankWidget(IAEFluidTank tank, int slot, int x, int y, int w, int h) {
super(x, y, w, h, LiteralText.EMPTY);
this.tank = tank;
this.slot = slot;
}
@Override
public void renderButton(MatrixStack matrices, int mouseX, int mouseY, float partialTicks) {
if (this.visible) {
fill(matrices, this.x, this.y, this.x + this.width, this.y + this.height, AEColor.GRAY.blackVariant | 0xFF000000);
final IAEFluidStack fluidStack = this.tank.getFluidInSlot(this.slot);
if (fluidStack != null && fluidStack.getStackSize() > 0) {
FluidVolume volume = fluidStack.getFluidStack();
FluidAmount maxAmount = this.tank.getMaxAmount_F(this.slot);
double fillRatio = volume.amount().div(maxAmount).asInexactDouble();
final int scaledHeight = (int) (this.height * fillRatio);
// Render the tank's content unstretched in patches of 16x16 squares,
// with a partial square for the remainder
int iconHeightRemainder = scaledHeight % 16;
int top = this.y + this.height - iconHeightRemainder;
if (iconHeightRemainder > 0) {
int x1 = this.x;
int y1 = top;
int x2 = x1 + 16;
int y2 = y1 + iconHeightRemainder;
volume.renderGuiRect(x1, y2, x2, y2);
}
for (int i = 0; i < scaledHeight / 16; i++) {
int x1 = this.x;
int y1 = top - (i + 1) * 16;
int x2 = x1 + 16;
int y2 = y1 + 16;
volume.renderGuiRect(x1, y2, x2, y2);
}
}
}
}
@Override
public Text getMessage() {
final IAEFluidStack fluid = this.tank.getFluidInSlot(this.slot);
if (fluid != null && fluid.getStackSize() > 0) {
Text desc = fluid.getFluidStack().getName();
String amountToText = fluid.getStackSize() + "mB";
return desc.copy().append("\n").append(amountToText);
}
return null;
}
@Override
public int xPos() {
return this.x - 2;
}
@Override
public int yPos() {
return this.y - 2;
}
@Override
public int getWidth() {
return this.width + 4;
}
@Override
public int getHeight() {
return this.height + 4;
}
@Override
public boolean isVisible() {
return true;
}
}
@@ -0,0 +1,58 @@
package appeng.fluids.client.gui.widgets;
import com.mojang.blaze3d.systems.RenderSystem;
import appeng.api.storage.data.IAEFluidStack;
import appeng.container.slot.IOptionalSlotHost;
import appeng.fluids.util.IAEFluidTank;
import net.minecraft.client.util.math.MatrixStack;
public class OptionalFluidSlotWidget extends FluidSlotWidget {
private final IOptionalSlotHost containerBus;
private final int groupNum;
private final int srcX;
private final int srcY;
public OptionalFluidSlotWidget(IAEFluidTank fluids, final IOptionalSlotHost containerBus, int slot, int id,
int groupNum, int x, int y, int xoffs, int yoffs) {
super(fluids, slot, id, x + xoffs * 18, y + yoffs * 18);
this.containerBus = containerBus;
this.groupNum = groupNum;
this.srcX = x;
this.srcY = y;
}
@Override
public boolean isSlotEnabled() {
if (this.containerBus == null) {
return false;
}
return this.containerBus.isSlotEnabled(this.groupNum);
}
@Override
public IAEFluidStack getFluidStack() {
if (!this.isSlotEnabled() && super.getFluidStack() != null) {
this.setFluidStack(null);
}
return super.getFluidStack();
}
@Override
public void drawBackground(MatrixStack matrices, int guileft, int guitop, int currentZIndex) {
RenderSystem.enableBlend();
if (this.isSlotEnabled()) {
RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F);
} else {
RenderSystem.color4f(1.0F, 1.0F, 1.0F, 0.4F);
}
int oldZOffset = getZOffset();
setZOffset(currentZIndex);
drawTexture(matrices, guileft + this.xPos() - 1, guitop + this.yPos() - 1, this.srcX - 1,
this.srcY - 1, this.getWidth() + 2, this.getHeight() + 2);
setZOffset(oldZOffset);
}
}