Moving to source sets

This commit is contained in:
Sebastian Hartte
2020-07-01 23:36:51 +02:00
parent f2e3d81fd7
commit 2642ced86b
2924 changed files with 794 additions and 796 deletions
@@ -1,62 +0,0 @@
/*
* 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.block;
import javax.annotation.Nullable;
import net.minecraft.block.Material;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import appeng.block.AEBaseTileBlock;
import appeng.container.ContainerLocator;
import appeng.container.ContainerOpener;
import appeng.fluids.container.FluidInterfaceContainer;
import appeng.fluids.tile.FluidInterfaceBlockEntity;
import appeng.util.Platform;
public class FluidInterfaceBlock extends AEBaseTileBlock<FluidInterfaceBlockEntity> {
public FluidInterfaceBlock() {
super(defaultProps(Material.METAL));
}
@Override
public ActionResult onActivated(final World w, final BlockPos pos, final PlayerEntity p, final Hand hand,
final @Nullable ItemStack heldItem, final BlockHitResult hit) {
if (p.isInSneakingPose()) {
return ActionResult.PASS;
}
final BlockEntity tg = this.getBlockEntity(w, pos);
if (tg != null) {
if (Platform.isServer()) {
ContainerOpener.openContainer(FluidInterfaceContainer.TYPE, p,
ContainerLocator.forTileEntitySide(tg, hit.getSide()));
}
return ActionResult.SUCCESS;
}
return ActionResult.PASS;
}
}
@@ -1,65 +0,0 @@
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.ySize = 251;
}
@Override
public void init() {
super.init();
final int xo = 8;
final int yo = 23 + 6;
final IAEFluidTank config = container.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, container, idx, idx, y - 2, xo, yo, x, y));
}
}
}
}
@Override
protected void addButtons() {
this.addButton(new TabButton(this.guiLeft + 154, this.guiTop, 2 + 4 * 16, GuiText.Priority.getLocal(),
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;
}
}
@@ -1,67 +0,0 @@
/*
* 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.container.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, container, 1, 1, 1, x, y, -1, 0));
this.guiSlots.add(new OptionalFluidSlotWidget(inv, container, 2, 2, 1, x, y, 1, 0));
this.guiSlots.add(new OptionalFluidSlotWidget(inv, container, 3, 3, 1, x, y, 0, -1));
this.guiSlots.add(new OptionalFluidSlotWidget(inv, container, 4, 4, 1, x, y, 0, 1));
this.guiSlots.add(new OptionalFluidSlotWidget(inv, container, 5, 5, 2, x, y, -1, -1));
this.guiSlots.add(new OptionalFluidSlotWidget(inv, container, 6, 6, 2, x, y, 1, -1));
this.guiSlots.add(new OptionalFluidSlotWidget(inv, container, 7, 7, 2, x, y, -1, 1));
this.guiSlots.add(new OptionalFluidSlotWidget(inv, container, 8, 8, 2, x, y, 1, 1));
}
@Override
protected GuiText getName() {
return this.bc instanceof FluidImportBusPart ? GuiText.ImportBusFluids : GuiText.ExportBusFluids;
}
}
@@ -1,88 +0,0 @@
/*
* 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 net.minecraftforge.fml.client.gui.GuiUtils;
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.ySize = 231;
}
@Override
public void init() {
super.init();
final IAEFluidTank configFluids = this.container.getFluidConfigInventory();
final IAEFluidTank fluidTank = this.container.getTanks();
for (int i = 0; i < DualityFluidInterface.NUMBER_OF_TANKS; ++i) {
final FluidTankWidget guiTank = new FluidTankWidget(fluidTank, i, this.getGuiLeft() + 35 + 18 * i,
this.getGuiTop() + 53, 16, 68);
this.addButton(guiTank);
this.guiSlots.add(new FluidSlotWidget(configFluids, i, i, 35 + 18 * i, 35));
}
this.addButton(new TabButton(this.getGuiLeft() + 154, this.getGuiTop(), 2 + 4 * 16, GuiText.Priority.getLocal(),
this.itemRenderer, btn -> openPriorityGui()));
}
@Override
protected void addButtons() {
}
@Override
public void drawFG(int offsetX, int offsetY, int mouseX, int mouseY) {
this.font.drawString(this.getGuiDisplayName(GuiText.FluidInterface.getLocal()), 8, 6, 4210752);
this.font.drawString(GuiText.Config.getLocal(), 35, 6 + 11 + 7, 4210752);
this.font.drawString(GuiText.StoredFluids.getLocal(), 35, 6 + 112 + 7, 4210752);
this.font.drawString(GuiText.inventory.getLocal(), 8, this.ySize - 96 + 3, 4210752);
}
@Override
public void drawBG(int offsetX, int offsetY, int mouseX, int mouseY, float partialTicks) {
this.bindTexture("guis/interfacefluid.png");
GuiUtils.drawTexturedModalRect(offsetX, offsetY, 0, 0, this.xSize, this.ySize, 0 /* FIXME ZINDEX */ );
}
private void openPriorityGui() {
NetworkHandler.instance().sendToServer(new SwitchGuisPacket(PriorityContainer.TYPE));
}
@Override
protected boolean drawUpgrades() {
return false;
}
}
@@ -1,180 +0,0 @@
package appeng.fluids.client.gui;
import net.minecraft.client.gui.widget.button.Button;
import net.minecraft.client.util.InputMappings;
import net.minecraft.entity.player.PlayerInventory;
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.font, this.guiLeft + 24, this.guiTop + 43, 79, this.font.FONT_HEIGHT,
Long.class);
this.level.setEnableBackgroundDrawing(false);
this.level.setMaxStringLength(16);
this.level.setTextColor(0xFFFFFF);
this.level.setVisible(true);
this.level.changeFocus(true);
container.setTextField(this.level);
final int y = 40;
final int x = 80 + 44;
this.guiSlots.add(new FluidSlotWidget(this.container.getFluidConfigInventory(), 0, 0, x, y));
}
@Override
protected void addButtons() {
this.redstoneMode = new ServerSettingToggleButton<>(this.guiLeft - 18, this.guiTop + 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 Button(this.guiLeft + 20, this.guiTop + 17, 22, 20, "+" + a, btn -> addQty(a)));
this.addButton(new Button(this.guiLeft + 48, this.guiTop + 17, 28, 20, "+" + b, btn -> addQty(b)));
this.addButton(new Button(this.guiLeft + 82, this.guiTop + 17, 32, 20, "+" + c, btn -> addQty(c)));
this.addButton(new Button(this.guiLeft + 120, this.guiTop + 17, 38, 20, "+" + d, btn -> addQty(d)));
this.addButton(new Button(this.guiLeft + 20, this.guiTop + 59, 22, 20, "-" + a, btn -> addQty(-a)));
this.addButton(new Button(this.guiLeft + 48, this.guiTop + 59, 28, 20, "-" + b, btn -> addQty(-b)));
this.addButton(new Button(this.guiLeft + 82, this.guiTop + 59, 32, 20, "-" + c, btn -> addQty(-c)));
this.addButton(new Button(this.guiLeft + 120, this.guiTop + 59, 38, 20, "-" + d, btn -> addQty(-d)));
this.addButton(this.redstoneMode);
}
@Override
public void drawBG(final int offsetX, final int offsetY, final int mouseX, final int mouseY, float partialTicks) {
super.drawBG(offsetX, offsetY, mouseX, mouseY, partialTicks);
this.level.render(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(InputMappings.getInputByCode(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_);
}
}
@@ -1,138 +0,0 @@
/*
* 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.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.ySize = 251;
}
@Override
public void init() {
super.init();
final int xo = 8;
final int yo = 23 + 6;
final IAEFluidTank config = this.container.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, container, idx, idx, y - 2, xo, yo, x, y));
}
}
}
}
@Override
protected void addButtons() {
addButton(new ActionButton(this.guiLeft - 18, this.guiTop + 8, ActionItems.CLOSE, btn -> clear()));
addButton(new ActionButton(this.guiLeft - 18, this.guiTop + 28, ActionItems.WRENCH, btn -> partition()));
this.rwMode = new ServerSettingToggleButton<>(this.guiLeft - 18, this.guiTop + 48, Settings.ACCESS,
AccessRestriction.READ_WRITE);
this.storageFilter = new ServerSettingToggleButton<>(this.guiLeft - 18, this.guiTop + 68,
Settings.STORAGE_FILTER, StorageFilter.EXTRACTABLE_ONLY);
this.fuzzyMode = new ServerSettingToggleButton<>(this.guiLeft - 18, this.guiTop + 88, Settings.FUZZY_MODE,
FuzzyMode.IGNORE_ALL);
addButton(this.addButton(new TabButton(this.guiLeft + 154, this.guiTop, 2 + 4 * 16, GuiText.Priority.getLocal(),
this.itemRenderer, btn -> openPriorityGui())));
this.addButton(this.storageFilter);
this.addButton(this.fuzzyMode);
this.addButton(this.rwMode);
}
@Override
public void drawFG(final int offsetX, final int offsetY, final int mouseX, final int mouseY) {
this.font.drawString(this.getGuiDisplayName(this.getName().getLocal()), 8, 6, 4210752);
this.font.drawString(GuiText.inventory.getLocal(), 8, this.ySize - 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;
}
}
@@ -1,336 +0,0 @@
/*
* 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 java.text.NumberFormat;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import net.minecraft.client.util.InputUtil;
import org.lwjgl.glfw.GLFW;
import net.minecraft.client.util.InputMappings;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.container.ClickType;
import net.minecraft.inventory.container.Slot;
import net.minecraft.text.Text;
import net.minecraftforge.fml.client.gui.GuiUtils;
import appeng.api.config.Settings;
import appeng.api.config.SortDir;
import appeng.api.config.SortOrder;
import appeng.api.config.ViewItems;
import appeng.api.storage.data.IAEFluidStack;
import appeng.api.util.IConfigManager;
import appeng.client.ActionKey;
import appeng.client.gui.AEBaseMEScreen;
import appeng.client.gui.widgets.AETextField;
import appeng.client.gui.widgets.ISortSource;
import appeng.client.gui.widgets.Scrollbar;
import appeng.client.gui.widgets.SettingToggleButton;
import appeng.client.me.FluidRepo;
import appeng.client.me.InternalFluidSlotME;
import appeng.client.me.SlotFluidME;
import appeng.core.AELog;
import appeng.core.AppEng;
import appeng.core.localization.GuiText;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.ConfigValuePacket;
import appeng.core.sync.packets.InventoryActionPacket;
import appeng.fluids.container.FluidTerminalContainer;
import appeng.fluids.container.slots.IMEFluidSlot;
import appeng.helpers.InventoryAction;
import appeng.util.IConfigManagerHost;
import appeng.util.Platform;
/**
* @author BrockWS
* @version rv6 - 12/05/2018
* @since rv6 12/05/2018
*/
public class FluidTerminalScreen extends AEBaseMEScreen<FluidTerminalContainer>
implements ISortSource, IConfigManagerHost {
private final List<SlotFluidME> meFluidSlots = new LinkedList<>();
private final FluidRepo repo;
private final IConfigManager configSrc;
private static final int GRID_OFFSET_X = 9;
private static final int GRID_OFFSET_Y = 18;
private static final int ROWS = 6;
private static final int COLS = 9;
private AETextField searchField;
private SettingToggleButton<SortOrder> sortByBox;
private SettingToggleButton<SortDir> sortDirBox;
public FluidTerminalScreen(FluidTerminalContainer container, PlayerInventory playerInventory,
Text title) {
super(container, playerInventory, title);
this.xSize = 185;
this.ySize = 222;
final Scrollbar scrollbar = new Scrollbar();
this.setScrollBar(scrollbar);
this.repo = new FluidRepo(scrollbar, this);
this.configSrc = container.getConfigManager();
this.container.setGui(this);
}
@Override
public void init() {
this.guiLeft = (this.width - this.xSize) / 2;
this.guiTop = (this.height - this.ySize) / 2;
this.searchField = new AETextField(this.font, this.guiLeft + 80, this.guiTop + 4, 90, 12);
this.searchField.setEnableBackgroundDrawing(false);
this.searchField.setMaxStringLength(25);
this.searchField.setTextColor(0xFFFFFF);
this.searchField.setSelectionColor(0xFF99FF99);
this.searchField.setVisible(true);
int offset = this.guiTop;
this.sortByBox = this.addButton(new SettingToggleButton<>(this.guiLeft - 18, offset, Settings.SORT_BY,
getSortBy(), Platform::isSortOrderAvailable, this::toggleServerSetting));
offset += 20;
this.sortDirBox = this.addButton(new SettingToggleButton<>(this.guiLeft - 18, offset, Settings.SORT_DIRECTION,
getSortDir(), this::toggleServerSetting));
for (int y = 0; y < ROWS; y++) {
for (int x = 0; x < COLS; x++) {
SlotFluidME slot = new SlotFluidME(new InternalFluidSlotME(this.repo, x + y * COLS,
GRID_OFFSET_X + x * 18, GRID_OFFSET_Y + y * 18));
this.getMeFluidSlots().add(slot);
this.container.inventorySlots.add(slot);
}
}
this.setScrollBar();
}
@Override
public void drawFG(int offsetX, int offsetY, int mouseX, int mouseY) {
this.font.drawString(this.getGuiDisplayName("Fluid Terminal"), 8, 6, 4210752);
this.font.drawString(GuiText.inventory.getLocal(), 8, this.ySize - 96 + 3, 4210752);
}
@Override
public void drawBG(int offsetX, int offsetY, int mouseX, int mouseY, float partialTicks) {
this.bindTexture(this.getBackground());
final int x_width = 197;
GuiUtils.drawTexturedModalRect(offsetX, offsetY, 0, 0, x_width, 18, getBlitOffset());
for (int x = 0; x < 6; x++) {
GuiUtils.drawTexturedModalRect(offsetX, offsetY + 18 + x * 18, 0, 18, x_width, 18, getBlitOffset());
}
GuiUtils.drawTexturedModalRect(offsetX, offsetY + 16 + 6 * 18, 0, 106 - 18 - 18, x_width, 99 + 77,
getBlitOffset());
if (this.searchField != null) {
this.searchField.render(mouseX, mouseY, partialTicks);
}
}
@Override
public void tick() {
this.repo.setPower(this.container.isPowered());
super.tick();
}
@Override
protected void renderHoveredToolTip(int mouseX, int mouseY) {
final Slot slot = this.getSlot(mouseX, mouseY);
if (slot instanceof IMEFluidSlot && slot.isEnabled()) {
final IMEFluidSlot fluidSlot = (IMEFluidSlot) slot;
if (fluidSlot.getAEFluidStack() != null && fluidSlot.shouldRenderAsFluid()) {
final IAEFluidStack fluidStack = fluidSlot.getAEFluidStack();
final String formattedAmount = NumberFormat.getNumberInstance(Locale.US)
.format(fluidStack.getStackSize() / 1000.0) + " B";
final String modName = Platform.getModName(Platform.getModId(fluidStack));
final List<String> list = new ArrayList<>();
list.add(fluidStack.getFluidStack().getName().getFormattedText());
list.add(formattedAmount);
list.add(modName);
this.renderTooltip(list, mouseX, mouseY);
return;
}
}
super.renderHoveredToolTip(mouseX, mouseY);
}
private <S extends Enum<S>> void toggleServerSetting(SettingToggleButton<S> btn, boolean backwards) {
S next = btn.getNextValue(backwards);
NetworkHandler.instance().sendToServer(new ConfigValuePacket(btn.getSetting().name(), next.name()));
btn.set(next);
}
@Override
protected void handleMouseClick(Slot slot, int slotIdx, int mouseButton, ClickType clickType) {
if (slot instanceof SlotFluidME) {
final SlotFluidME meSlot = (SlotFluidME) slot;
if (clickType == ClickType.PICKUP) {
// TODO: Allow more options
if (mouseButton == 0 && meSlot.getHasStack()) {
this.container.setTargetStack(meSlot.getAEFluidStack());
AELog.debug("mouse0 GUI STACK SIZE %s", meSlot.getAEFluidStack().getStackSize());
NetworkHandler.instance()
.sendToServer(new InventoryActionPacket(InventoryAction.FILL_ITEM, slot.slotNumber, 0));
} else {
this.container.setTargetStack(meSlot.getAEFluidStack());
if (meSlot.getAEFluidStack() != null) {
AELog.debug("mouse1 GUI STACK SIZE %s", meSlot.getAEFluidStack().getStackSize());
}
NetworkHandler.instance()
.sendToServer(new InventoryActionPacket(InventoryAction.EMPTY_ITEM, slot.slotNumber, 0));
}
}
return;
}
super.handleMouseClick(slot, slotIdx, mouseButton, clickType);
}
@Override
public boolean charTyped(char character, int p_charTyped_2_) {
if (character == ' ' && this.searchField.getText().isEmpty()) {
return true;
}
if (this.searchField.isFocused() && this.searchField.charTyped(character, p_charTyped_2_)) {
this.repo.setSearchString(this.searchField.getText());
this.repo.updateView();
this.setScrollBar();
return true;
}
return false;
}
@Override
public boolean keyPressed(int keyCode, int scanCode, int p_keyPressed_3_) {
InputUtil.Key input = InputMappings.getInputByCode(keyCode, scanCode);
if (keyCode != GLFW.GLFW_KEY_ESCAPE && !this.checkHotbarKeys(input)) {
if (AppEng.instance().isActionKey(ActionKey.TOGGLE_FOCUS, input)) {
this.searchField.setFocused2(!this.searchField.isFocused());
return true;
}
if (this.searchField.isFocused()) {
if (keyCode == GLFW.GLFW_KEY_ENTER) {
this.searchField.setFocused2(false);
return true;
}
if (this.searchField.keyPressed(keyCode, scanCode, p_keyPressed_3_)) {
this.repo.setSearchString(this.searchField.getText());
this.repo.updateView();
this.setScrollBar();
}
// We need to swallow key presses if the field is focused because typing 'e'
// would otherwise close
// the screen
return true;
}
}
return super.keyPressed(keyCode, scanCode, p_keyPressed_3_);
}
@Override
public boolean mouseClicked(final double xCoord, final double yCoord, final int btn) {
if (this.searchField.mouseClicked(xCoord, yCoord, btn)) {
if (btn == 1 && this.searchField.isMouseOver(xCoord, yCoord)) {
this.searchField.setText("");
this.repo.setSearchString("");
this.repo.updateView();
this.setScrollBar();
}
return true;
}
return super.mouseClicked(xCoord, yCoord, btn);
}
public void postUpdate(final List<IAEFluidStack> list) {
for (final IAEFluidStack is : list) {
this.repo.postUpdate(is);
}
this.repo.updateView();
this.setScrollBar();
}
private void setScrollBar() {
this.getScrollBar().setTop(18).setLeft(175).setHeight(ROWS * 18 - 2);
this.getScrollBar().setRange(0, (this.repo.size() + COLS - 1) / COLS - ROWS, ROWS / 6);
}
@Override
public SortOrder getSortBy() {
return (SortOrder) this.configSrc.getSetting(Settings.SORT_BY);
}
@Override
public SortDir getSortDir() {
return (SortDir) this.configSrc.getSetting(Settings.SORT_DIRECTION);
}
@Override
public ViewItems getSortDisplay() {
return (ViewItems) this.configSrc.getSetting(Settings.VIEW_MODE);
}
@Override
public void updateSetting(IConfigManager manager, Settings settingName, Enum<?> newValue) {
if (this.sortByBox != null) {
this.sortByBox.set(getSortBy());
}
if (this.sortDirBox != null) {
this.sortDirBox.set(getSortDir());
}
this.repo.updateView();
}
protected List<SlotFluidME> getMeFluidSlots() {
return this.meFluidSlots;
}
@Override
protected boolean isPowered() {
return this.repo.hasPower();
}
protected String getBackground() {
return "guis/terminal.png";
}
}
@@ -1,101 +0,0 @@
package appeng.fluids.client.gui.widgets;
import java.util.Collections;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.texture.SpriteAtlasTexture;
import net.minecraft.client.texture.Sprite;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.fluid.Fluid;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.fluids.FluidAttributes;
import alexiil.mc.lib.attributes.fluid.volume.FluidVolume;
import net.minecraftforge.fluids.FluidUtil;
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
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) {
RenderSystem.disableBlend();
final Fluid fluid = fs.getFluid();
final FluidAttributes attributes = fluid.getAttributes();
mc.getTextureManager().bindTexture(SpriteAtlasTexture.BLOCK_ATLAS_TEX);
final Sprite sprite = mc.getAtlasSpriteGetter(SpriteAtlasTexture.BLOCK_ATLAS_TEX)
.apply(attributes.getStillTexture(fs.getFluidStack()));
// Set color for dynamic fluids
// Convert int color to RGB
final float red = (attributes.getColor() >> 16 & 255) / 255.0F;
final float green = (attributes.getColor() >> 8 & 255) / 255.0F;
final float blue = (attributes.getColor() & 255) / 255.0F;
RenderSystem.color3f(red, green, blue);
blit(xPos(), yPos(), this.getBlitOffset(), getWidth(), getHeight(), sprite);
}
}
@Override
public boolean canClick(final PlayerEntity player) {
final ItemStack mouseStack = player.inventory.getItemStack();
return mouseStack.isEmpty()
|| mouseStack.getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY).isPresent();
}
@Override
public void slotClicked(final ItemStack clickStack, int mouseButton) {
if (clickStack.isEmpty() || mouseButton == 1) {
this.setFluidStack(null);
} else if (mouseButton == 0) {
final LazyOptional<FluidVolume> fluidOpt = FluidUtil.getFluidContained(clickStack);
fluidOpt.ifPresent(fluid -> {
this.setFluidStack(AEFluidStack.fromFluidStack(fluid));
});
}
}
@Override
public String getMessage() {
final IAEFluidStack fluid = this.getFluidStack();
if (fluid != null) {
return I18n.format(fluid.getFluidStack().getTranslationKey());
}
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())));
}
}
@@ -1,124 +0,0 @@
/*
* 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 com.mojang.blaze3d.systems.RenderSystem;
import net.fabricmc.api.EnvType;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.widget.Widget;
import net.minecraft.client.texture.SpriteAtlasTexture;
import net.minecraft.client.texture.Sprite;
import net.minecraft.fluid.Fluid;
import net.fabricmc.api.Environment;
import net.minecraftforge.fluids.FluidAttributes;
import appeng.api.storage.data.IAEFluidStack;
import appeng.api.util.AEColor;
import appeng.client.gui.widgets.ITooltip;
import appeng.fluids.util.IAEFluidTank;
@Environment(EnvType.CLIENT)
public class FluidTankWidget extends Widget 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, "");
this.tank = tank;
this.slot = slot;
}
@Override
public void renderButton(int mouseX, int mouseY, float partialTicks) {
if (this.visible) {
RenderSystem.disableBlend();
fill(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) {
Fluid fluid = fluidStack.getFluid();
FluidAttributes attributes = fluid.getAttributes();
float red = (attributes.getColor() >> 16 & 255) / 255.0F;
float green = (attributes.getColor() >> 8 & 255) / 255.0F;
float blue = (attributes.getColor() & 255) / 255.0F;
RenderSystem.color3f(red, green, blue);
MinecraftClient mc = MinecraftClient.getInstance();
mc.getTextureManager().bindTexture(SpriteAtlasTexture.BLOCK_ATLAS_TEX);
final Sprite sprite = mc.getAtlasSpriteGetter(SpriteAtlasTexture.BLOCK_ATLAS_TEX)
.apply(attributes.getStillTexture(fluidStack.getFluidStack()));
final int scaledHeight = (int) (this.height
* ((float) fluidStack.getStackSize() / this.tank.getTankCapacity(this.slot)));
int iconHeightRemainder = scaledHeight % 16;
if (iconHeightRemainder > 0) {
blit(this.x, this.y + this.height - iconHeightRemainder, getBlitOffset(), 16, iconHeightRemainder,
sprite);
}
for (int i = 0; i < scaledHeight / 16; i++) {
blit(this.x, this.y + this.height - iconHeightRemainder - (i + 1) * 16, getBlitOffset(), 16, 16,
sprite);
}
}
}
}
@Override
public String getMessage() {
final IAEFluidStack fluid = this.tank.getFluidInSlot(this.slot);
if (fluid != null && fluid.getStackSize() > 0) {
String desc = fluid.getFluid().getAttributes().getName(fluid.getFluidStack()).getFormattedText();
String amountToText = fluid.getStackSize() + "mB";
return desc + "\n" + 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;
}
}
@@ -1,54 +0,0 @@
package appeng.fluids.client.gui.widgets;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraftforge.fml.client.gui.GuiUtils;
import appeng.api.storage.data.IAEFluidStack;
import appeng.container.slot.IOptionalSlotHost;
import appeng.fluids.util.IAEFluidTank;
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(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);
}
GuiUtils.drawTexturedModalRect(guileft + this.xPos() - 1, guitop + this.yPos() - 1, this.srcX - 1,
this.srcY - 1, this.getWidth() + 2, this.getHeight() + 2, currentZIndex);
}
}
@@ -1,96 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, 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.render;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import net.minecraft.client.gui.FontRenderer;
import appeng.api.storage.data.IAEFluidStack;
import appeng.client.render.StackSizeRenderer;
import appeng.core.AEConfig;
import appeng.util.ISlimReadableNumberConverter;
import appeng.util.IWideReadableNumberConverter;
import appeng.util.ReadableNumberConverter;
/**
* @author AlgorithmX2
* @author thatsIch
* @author yueh
* @version rv6
* @since rv6
*/
public class FluidStackSizeRenderer {
private static final String[] NUMBER_FORMATS = new String[] { "#.000", "#.00", "#.0", "#" };
private static final ISlimReadableNumberConverter SLIM_CONVERTER = ReadableNumberConverter.INSTANCE;
private static final IWideReadableNumberConverter WIDE_CONVERTER = ReadableNumberConverter.INSTANCE;
public void renderStackSize(FontRenderer fontRenderer, IAEFluidStack aeStack, int xPos, int yPos) {
if (aeStack != null && aeStack.getStackSize() > 0) {
final String stackSize = this.getToBeRenderedStackSize(aeStack.getStackSize());
StackSizeRenderer.renderSizeLabel(fontRenderer, xPos, yPos, stackSize);
}
}
private String getToBeRenderedStackSize(final long originalSize) {
// Handle any value below 100 (large font) or 1000 (small font) Buckets with a
// custom formatter,
// otherwise pass it to the normal number converter
if (originalSize < 1000 * 100 && AEConfig.instance().isUseLargeFonts()) {
return this.getSlimRenderedStacksize(originalSize);
} else if (originalSize < 1000 * 1000 && !AEConfig.instance().isUseLargeFonts()) {
return this.getWideRenderedStacksize(originalSize);
}
if (AEConfig.instance().isUseLargeFonts()) {
return SLIM_CONVERTER.toSlimReadableForm(originalSize / 1000);
} else {
return WIDE_CONVERTER.toWideReadableForm(originalSize / 1000);
}
}
private String getSlimRenderedStacksize(final long originalSize) {
final int log = 1 + (int) Math.floor(Math.log10(originalSize)) / 2;
return this.getRenderedFluidStackSize(originalSize, log);
}
private String getWideRenderedStacksize(final long originalSize) {
final int log = (int) Math.floor(Math.log10(originalSize)) / 2;
return this.getRenderedFluidStackSize(originalSize, log);
}
private String getRenderedFluidStackSize(final long originalSize, final int log) {
final int index = Math.max(0, Math.min(3, log));
final DecimalFormatSymbols symbols = new DecimalFormatSymbols();
symbols.setDecimalSeparator('.');
final DecimalFormat format = new DecimalFormat(NUMBER_FORMATS[index]);
format.setDecimalFormatSymbols(symbols);
format.setRoundingMode(RoundingMode.DOWN);
return format.format(originalSize / 1000d);
}
}
@@ -1,99 +0,0 @@
package appeng.fluids.container;
import java.util.Collections;
import java.util.Map;
import alexiil.mc.lib.attributes.fluid.volume.FluidVolume;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.inventory.container.IContainerListener;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.fluids.FluidUtil;
import appeng.api.config.Upgrades;
import appeng.api.implementations.IUpgradeableHost;
import appeng.api.storage.data.IAEFluidStack;
import appeng.container.implementations.UpgradeableContainer;
import appeng.fluids.helper.FluidSyncHelper;
import appeng.fluids.util.AEFluidStack;
import appeng.fluids.util.IAEFluidTank;
import appeng.util.Platform;
public abstract class FluidConfigurableContainer extends UpgradeableContainer implements IFluidSyncContainer {
private FluidSyncHelper sync = null;
public FluidConfigurableContainer(ScreenHandlerType<?> containerType, int id, PlayerInventory ip, IUpgradeableHost te) {
super(containerType, id, ip, te);
}
public abstract IAEFluidTank getFluidConfigInventory();
private FluidSyncHelper getSyncHelper() {
if (this.sync == null) {
this.sync = new FluidSyncHelper(this.getFluidConfigInventory(), 0);
}
return this.sync;
}
@Override
protected ItemStack transferStackToContainer(ItemStack input) {
LazyOptional<FluidVolume> fsOpt = FluidUtil.getFluidContained(input);
if (fsOpt.isPresent()) {
final IAEFluidTank t = this.getFluidConfigInventory();
final IAEFluidStack stack = AEFluidStack.fromFluidStack(fsOpt.orElse(null));
for (int i = 0; i < t.getSlots(); ++i) {
if (t.getFluidInSlot(i) == null && this.isValidForConfig(i, stack)) {
t.setFluidInSlot(i, stack);
break;
}
}
}
return input;
}
protected boolean isValidForConfig(int slot, IAEFluidStack fs) {
if (this.supportCapacity()) {
// assumes 4 slots per upgrade
final int upgrades = this.getUpgradeable().getInstalledUpgrades(Upgrades.CAPACITY);
if (slot > 0 && upgrades < 1) {
return false;
}
if (slot > 4 && upgrades < 2) {
return false;
}
}
return true;
}
@Override
protected void standardDetectAndSendChanges() {
if (Platform.isServer()) {
this.getSyncHelper().sendDiff(this.listeners);
// clear out config items that are no longer valid (eg capacity upgrade removed)
final IAEFluidTank t = this.getFluidConfigInventory();
for (int i = 0; i < t.getSlots(); ++i) {
if (t.getFluidInSlot(i) != null && !this.isValidForConfig(i, t.getFluidInSlot(i))) {
t.setFluidInSlot(i, null);
}
}
}
super.standardDetectAndSendChanges();
}
@Override
public void addListener(IContainerListener listener) {
super.addListener(listener);
this.getSyncHelper().sendFull(Collections.singleton(listener));
}
@Override
public void receiveFluidSlots(Map<Integer, IAEFluidStack> fluids) {
this.getSyncHelper().readPacket(fluids);
}
}
@@ -1,104 +0,0 @@
package appeng.fluids.container;
import alexiil.mc.lib.attributes.item.FixedItemInv;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.network.PacketByteBuf;
import appeng.api.config.SecurityPermissions;
import appeng.api.config.Upgrades;
import appeng.api.storage.data.IAEFluidStack;
import appeng.container.ContainerLocator;
import appeng.container.implementations.ContainerHelper;
import appeng.container.slot.RestrictedInputSlot;
import appeng.fluids.parts.FluidFormationPlanePart;
import appeng.fluids.util.IAEFluidTank;
public class FluidFormationPlaneContainer extends FluidConfigurableContainer {
public static ScreenHandlerType<FluidFormationPlaneContainer> TYPE;
private static final ContainerHelper<FluidFormationPlaneContainer, FluidFormationPlanePart> helper = new ContainerHelper<>(
FluidFormationPlaneContainer::new, FluidFormationPlanePart.class, SecurityPermissions.BUILD);
public static FluidFormationPlaneContainer fromNetwork(int windowId, PlayerInventory inv, PacketByteBuf buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
private final FluidFormationPlanePart plane;
public FluidFormationPlaneContainer(int id, final PlayerInventory ip, final FluidFormationPlanePart te) {
super(TYPE, id, ip, te);
this.plane = te;
}
@Override
protected int getHeight() {
return 251;
}
@Override
public IAEFluidTank getFluidConfigInventory() {
return this.plane.getConfig();
}
@Override
protected void setupConfig() {
final FixedItemInv upgrades = this.getUpgradeable().getInventoryByName("upgrades");
this.addSlot((new RestrictedInputSlot(RestrictedInputSlot.PlacableItemType.UPGRADES, upgrades, 0, 187, 8,
this.getPlayerInventory())).setNotDraggable());
this.addSlot((new RestrictedInputSlot(RestrictedInputSlot.PlacableItemType.UPGRADES, upgrades, 1, 187, 8 + 18,
this.getPlayerInventory())).setNotDraggable());
this.addSlot((new RestrictedInputSlot(RestrictedInputSlot.PlacableItemType.UPGRADES, upgrades, 2, 187,
8 + 18 * 2, this.getPlayerInventory())).setNotDraggable());
this.addSlot((new RestrictedInputSlot(RestrictedInputSlot.PlacableItemType.UPGRADES, upgrades, 3, 187,
8 + 18 * 3, this.getPlayerInventory())).setNotDraggable());
this.addSlot((new RestrictedInputSlot(RestrictedInputSlot.PlacableItemType.UPGRADES, upgrades, 4, 187,
8 + 18 * 4, this.getPlayerInventory())).setNotDraggable());
}
@Override
public void detectAndSendChanges() {
this.verifyPermissions(SecurityPermissions.BUILD, false);
this.checkToolbox();
this.standardDetectAndSendChanges();
}
@Override
protected boolean isValidForConfig(int slot, IAEFluidStack fs) {
if (this.supportCapacity()) {
final int upgrades = this.getUpgradeable().getInstalledUpgrades(Upgrades.CAPACITY);
final int y = slot / 9;
if (y >= upgrades + 2) {
return false;
}
}
return true;
}
@Override
public boolean isSlotEnabled(final int idx) {
final int upgrades = this.getUpgradeable().getInstalledUpgrades(Upgrades.CAPACITY);
return upgrades > idx;
}
@Override
protected boolean supportCapacity() {
return true;
}
@Override
public int availableUpgrades() {
return 5;
}
}
@@ -1,68 +0,0 @@
/*
* 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.container;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.network.PacketByteBuf;
import appeng.api.config.SecurityPermissions;
import appeng.container.ContainerLocator;
import appeng.container.implementations.ContainerHelper;
import appeng.fluids.parts.SharedFluidBusPart;
import appeng.fluids.util.IAEFluidTank;
/**
* @author BrockWS
* @version rv5 - 1/05/2018
* @since rv5 1/05/2018
*/
public class FluidIOContainer extends FluidConfigurableContainer {
public static ScreenHandlerType<FluidIOContainer> TYPE;
private static final ContainerHelper<FluidIOContainer, SharedFluidBusPart> helper = new ContainerHelper<>(
FluidIOContainer::new, SharedFluidBusPart.class, SecurityPermissions.BUILD);
public static FluidIOContainer fromNetwork(int windowId, PlayerInventory inv, PacketByteBuf buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
private final SharedFluidBusPart bus;
public FluidIOContainer(int id, PlayerInventory ip, SharedFluidBusPart te) {
super(TYPE, id, ip, te);
this.bus = te;
}
@Override
public IAEFluidTank getFluidConfigInventory() {
return this.bus.getConfig();
}
@Override
protected void setupConfig() {
this.setupUpgrades();
}
}
@@ -1,125 +0,0 @@
/*
* 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.container;
import java.util.Collections;
import java.util.Map;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.inventory.container.IContainerListener;
import net.minecraft.network.PacketByteBuf;
import appeng.api.config.SecurityPermissions;
import appeng.api.storage.data.IAEFluidStack;
import appeng.api.util.IConfigManager;
import appeng.container.ContainerLocator;
import appeng.container.implementations.ContainerHelper;
import appeng.fluids.helper.DualityFluidInterface;
import appeng.fluids.helper.FluidSyncHelper;
import appeng.fluids.helper.IFluidInterfaceHost;
import appeng.fluids.util.IAEFluidTank;
import appeng.util.Platform;
public class FluidInterfaceContainer extends FluidConfigurableContainer {
public static ScreenHandlerType<FluidInterfaceContainer> TYPE;
private static final ContainerHelper<FluidInterfaceContainer, IFluidInterfaceHost> helper = new ContainerHelper<>(
FluidInterfaceContainer::new, IFluidInterfaceHost.class, SecurityPermissions.BUILD);
public static FluidInterfaceContainer fromNetwork(int windowId, PlayerInventory inv, PacketByteBuf buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
private final DualityFluidInterface myDuality;
private final FluidSyncHelper tankSync;
public FluidInterfaceContainer(int id, final PlayerInventory ip, final IFluidInterfaceHost te) {
super(TYPE, id, ip, te.getDualityFluidInterface().getHost());
this.myDuality = te.getDualityFluidInterface();
this.tankSync = new FluidSyncHelper(this.myDuality.getTanks(), DualityFluidInterface.NUMBER_OF_TANKS);
}
@Override
protected int getHeight() {
return 231;
}
public IAEFluidTank getTanks() {
return myDuality.getTanks();
}
@Override
public IAEFluidTank getFluidConfigInventory() {
return this.myDuality.getConfig();
}
@Override
public void detectAndSendChanges() {
this.verifyPermissions(SecurityPermissions.BUILD, false);
if (Platform.isServer()) {
this.tankSync.sendDiff(this.listeners);
}
super.detectAndSendChanges();
}
@Override
protected void setupConfig() {
}
@Override
protected void loadSettingsFromHost(final IConfigManager cm) {
}
@Override
public void addListener(IContainerListener listener) {
super.addListener(listener);
this.tankSync.sendFull(Collections.singleton(listener));
}
@Override
public void receiveFluidSlots(Map<Integer, IAEFluidStack> fluids) {
super.receiveFluidSlots(fluids);
this.tankSync.readPacket(fluids);
}
@Override
protected boolean supportCapacity() {
return false;
}
@Override
public int availableUpgrades() {
return 0;
}
@Override
public boolean hasToolbox() {
return false;
}
}
@@ -1,99 +0,0 @@
package appeng.fluids.container;
import net.minecraft.client.gui.widget.TextFieldWidget;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.network.PacketByteBuf;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import appeng.api.config.RedstoneMode;
import appeng.api.config.SecurityPermissions;
import appeng.api.config.Settings;
import appeng.container.ContainerLocator;
import appeng.container.guisync.GuiSync;
import appeng.container.implementations.ContainerHelper;
import appeng.fluids.parts.FluidLevelEmitterPart;
import appeng.fluids.util.IAEFluidTank;
import appeng.util.Platform;
public class FluidLevelEmitterContainer extends FluidConfigurableContainer {
public static ScreenHandlerType<FluidLevelEmitterContainer> TYPE;
private static final ContainerHelper<FluidLevelEmitterContainer, FluidLevelEmitterPart> helper = new ContainerHelper<>(
FluidLevelEmitterContainer::new, FluidLevelEmitterPart.class, SecurityPermissions.BUILD);
public static FluidLevelEmitterContainer fromNetwork(int windowId, PlayerInventory inv, PacketByteBuf buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
private final FluidLevelEmitterPart lvlEmitter;
@Environment(EnvType.CLIENT)
private TextFieldWidget textField;
@GuiSync(3)
public long EmitterValue = -1;
public FluidLevelEmitterContainer(int id, final PlayerInventory ip, final FluidLevelEmitterPart te) {
super(TYPE, id, ip, te);
this.lvlEmitter = te;
}
@Environment(EnvType.CLIENT)
public void setTextField(final TextFieldWidget level) {
this.textField = level;
this.textField.setText(String.valueOf(this.EmitterValue));
}
public void setLevel(final long l, final PlayerEntity player) {
this.lvlEmitter.setReportingValue(l);
this.EmitterValue = l;
}
@Override
protected void setupConfig() {
}
@Override
protected boolean supportCapacity() {
return false;
}
@Override
public int availableUpgrades() {
return 0;
}
@Override
public void detectAndSendChanges() {
this.verifyPermissions(SecurityPermissions.BUILD, false);
if (Platform.isServer()) {
this.EmitterValue = this.lvlEmitter.getReportingValue();
this.setRedStoneMode(
(RedstoneMode) this.getUpgradeable().getConfigManager().getSetting(Settings.REDSTONE_EMITTER));
}
this.standardDetectAndSendChanges();
}
@Override
public void onUpdate(final String field, final Object oldValue, final Object newValue) {
if (field.equals("EmitterValue")) {
if (this.textField != null) {
this.textField.setText(String.valueOf(this.EmitterValue));
}
}
}
@Override
public IAEFluidTank getFluidConfigInventory() {
return this.lvlEmitter.getConfig();
}
}
@@ -1,199 +0,0 @@
/*
* 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.container;
import java.util.Iterator;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.network.PacketByteBuf;
import alexiil.mc.lib.attributes.item.FixedItemInv;
import appeng.api.AEApi;
import appeng.api.config.AccessRestriction;
import appeng.api.config.FuzzyMode;
import appeng.api.config.SecurityPermissions;
import appeng.api.config.Settings;
import appeng.api.config.StorageFilter;
import appeng.api.config.Upgrades;
import appeng.api.storage.IMEInventory;
import appeng.api.storage.channels.IFluidStorageChannel;
import appeng.api.storage.data.IAEFluidStack;
import appeng.api.storage.data.IItemList;
import appeng.container.ContainerLocator;
import appeng.container.guisync.GuiSync;
import appeng.container.implementations.ContainerHelper;
import appeng.container.slot.RestrictedInputSlot;
import appeng.fluids.parts.FluidStorageBusPart;
import appeng.fluids.util.IAEFluidTank;
import appeng.util.Platform;
import appeng.util.iterators.NullIterator;
/**
* @author BrockWS
* @version rv6 - 22/05/2018
* @since rv6 22/05/2018
*/
public class FluidStorageBusContainer extends FluidConfigurableContainer {
public static ScreenHandlerType<FluidStorageBusContainer> TYPE;
private static final ContainerHelper<FluidStorageBusContainer, FluidStorageBusPart> helper = new ContainerHelper<>(
FluidStorageBusContainer::new, FluidStorageBusPart.class);
public static FluidStorageBusContainer fromNetwork(int windowId, PlayerInventory inv, PacketByteBuf buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
private final FluidStorageBusPart storageBus;
@GuiSync(3)
public AccessRestriction rwMode = AccessRestriction.READ_WRITE;
@GuiSync(4)
public StorageFilter storageFilter = StorageFilter.EXTRACTABLE_ONLY;
public FluidStorageBusContainer(int id, PlayerInventory ip, FluidStorageBusPart te) {
super(TYPE, id, ip, te);
this.storageBus = te;
}
@Override
protected int getHeight() {
return 251;
}
@Override
protected void setupConfig() {
final FixedItemInv upgrades = this.getUpgradeable().getInventoryByName("upgrades");
this.addSlot((new RestrictedInputSlot(RestrictedInputSlot.PlacableItemType.UPGRADES, upgrades, 0, 187, 8,
this.getPlayerInventory())).setNotDraggable());
this.addSlot((new RestrictedInputSlot(RestrictedInputSlot.PlacableItemType.UPGRADES, upgrades, 1, 187, 8 + 18,
this.getPlayerInventory())).setNotDraggable());
this.addSlot((new RestrictedInputSlot(RestrictedInputSlot.PlacableItemType.UPGRADES, upgrades, 2, 187,
8 + 18 * 2, this.getPlayerInventory())).setNotDraggable());
this.addSlot((new RestrictedInputSlot(RestrictedInputSlot.PlacableItemType.UPGRADES, upgrades, 3, 187,
8 + 18 * 3, this.getPlayerInventory())).setNotDraggable());
this.addSlot((new RestrictedInputSlot(RestrictedInputSlot.PlacableItemType.UPGRADES, upgrades, 4, 187,
8 + 18 * 4, this.getPlayerInventory())).setNotDraggable());
}
@Override
protected boolean isValidForConfig(int slot, IAEFluidStack fs) {
if (this.supportCapacity()) {
final int upgrades = this.getUpgradeable().getInstalledUpgrades(Upgrades.CAPACITY);
final int y = slot / 9;
if (y >= upgrades + 2) {
return false;
}
}
return true;
}
@Override
protected boolean supportCapacity() {
return true;
}
@Override
public int availableUpgrades() {
return 5;
}
@Override
public void detectAndSendChanges() {
this.verifyPermissions(SecurityPermissions.BUILD, false);
if (Platform.isServer()) {
this.setFuzzyMode((FuzzyMode) this.getUpgradeable().getConfigManager().getSetting(Settings.FUZZY_MODE));
this.setReadWriteMode(
(AccessRestriction) this.getUpgradeable().getConfigManager().getSetting(Settings.ACCESS));
this.setStorageFilter(
(StorageFilter) this.getUpgradeable().getConfigManager().getSetting(Settings.STORAGE_FILTER));
}
this.standardDetectAndSendChanges();
}
@Override
public boolean isSlotEnabled(final int idx) {
final int upgrades = this.getUpgradeable().getInstalledUpgrades(Upgrades.CAPACITY);
return upgrades > idx;
}
public void clear() {
IAEFluidTank h = this.storageBus.getConfig();
for (int i = 0; i < h.getSlots(); ++i) {
h.setFluidInSlot(i, null);
}
this.detectAndSendChanges();
}
public void partition() {
IAEFluidTank h = this.storageBus.getConfig();
final IMEInventory<IAEFluidStack> cellInv = this.storageBus.getInternalHandler();
Iterator<IAEFluidStack> i = new NullIterator<>();
if (cellInv != null) {
final IItemList<IAEFluidStack> list = cellInv.getAvailableItems(
AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class).createList());
i = list.iterator();
}
for (int x = 0; x < h.getSlots(); x++) {
if (i.hasNext() && this.isSlotEnabled((x / 9) - 2)) {
h.setFluidInSlot(x, i.next());
} else {
h.setFluidInSlot(x, null);
}
}
this.detectAndSendChanges();
}
public AccessRestriction getReadWriteMode() {
return this.rwMode;
}
private void setReadWriteMode(final AccessRestriction rwMode) {
this.rwMode = rwMode;
}
public StorageFilter getStorageFilter() {
return this.storageFilter;
}
private void setStorageFilter(final StorageFilter storageFilter) {
this.storageFilter = storageFilter;
}
@Override
public IAEFluidTank getFluidConfigInventory() {
return this.storageBus.getConfig();
}
}
@@ -1,435 +0,0 @@
/*
* 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.container;
import java.io.IOException;
import java.nio.BufferOverflowException;
import javax.annotation.Nonnull;
import alexiil.mc.lib.attributes.fluid.volume.FluidVolume;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.inventory.container.IContainerListener;
import net.minecraft.item.ItemStack;
import net.minecraft.network.PacketByteBuf;
import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.fluids.FluidUtil;
import net.minecraftforge.fluids.capability.IFluidHandler.FluidAction;
import net.minecraftforge.fluids.capability.IFluidHandlerItem;
import appeng.api.AEApi;
import appeng.api.config.Actionable;
import appeng.api.config.PowerMultiplier;
import appeng.api.config.SecurityPermissions;
import appeng.api.config.Settings;
import appeng.api.config.SortDir;
import appeng.api.config.SortOrder;
import appeng.api.config.ViewItems;
import appeng.api.networking.IGrid;
import appeng.api.networking.IGridHost;
import appeng.api.networking.IGridNode;
import appeng.api.networking.energy.IEnergyGrid;
import appeng.api.networking.energy.IEnergySource;
import appeng.api.networking.security.IActionHost;
import appeng.api.networking.security.IActionSource;
import appeng.api.networking.storage.IBaseMonitor;
import appeng.api.storage.IMEMonitor;
import appeng.api.storage.IMEMonitorHandlerReceiver;
import appeng.api.storage.ITerminalHost;
import appeng.api.storage.channels.IFluidStorageChannel;
import appeng.api.storage.data.IAEFluidStack;
import appeng.api.storage.data.IItemList;
import appeng.api.util.AEPartLocation;
import appeng.api.util.IConfigManager;
import appeng.api.util.IConfigurableObject;
import appeng.container.AEBaseContainer;
import appeng.container.ContainerLocator;
import appeng.container.guisync.GuiSync;
import appeng.container.implementations.ContainerHelper;
import appeng.core.AELog;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.ConfigValuePacket;
import appeng.core.sync.packets.MEFluidInventoryUpdatePacket;
import appeng.core.sync.packets.TargetFluidStackPacket;
import appeng.fluids.util.AEFluidStack;
import appeng.helpers.InventoryAction;
import appeng.me.helpers.ChannelPowerSrc;
import appeng.util.ConfigManager;
import appeng.util.IConfigManagerHost;
import appeng.util.Platform;
/**
* @author BrockWS
* @version rv6 - 12/05/2018
* @since rv6 12/05/2018
*/
public class FluidTerminalContainer extends AEBaseContainer
implements IConfigManagerHost, IConfigurableObject, IMEMonitorHandlerReceiver<IAEFluidStack> {
public static ScreenHandlerType<FluidTerminalContainer> TYPE;
private static final ContainerHelper<FluidTerminalContainer, ITerminalHost> helper = new ContainerHelper<>(
FluidTerminalContainer::new, ITerminalHost.class, SecurityPermissions.BUILD);
public static FluidTerminalContainer fromNetwork(int windowId, PlayerInventory inv, PacketByteBuf buf) {
return helper.fromNetwork(windowId, inv, buf);
}
public static boolean open(PlayerEntity player, ContainerLocator locator) {
return helper.open(player, locator);
}
private final IConfigManager clientCM;
private final IMEMonitor<IAEFluidStack> monitor;
private final IItemList<IAEFluidStack> fluids = AEApi.instance().storage()
.getStorageChannel(IFluidStorageChannel.class).createList();
@GuiSync(99)
public boolean hasPower = false;
private ITerminalHost terminal;
private IConfigManager serverCM;
private IConfigManagerHost gui;
private IGridNode networkNode;
// Holds the fluid the client wishes to extract, or null for insert
private IAEFluidStack clientRequestedTargetFluid = null;
public FluidTerminalContainer(int id, PlayerInventory ip, ITerminalHost terminal) {
super(TYPE, id, ip, terminal);
this.terminal = terminal;
this.clientCM = new ConfigManager(this);
this.clientCM.registerSetting(Settings.SORT_BY, SortOrder.NAME);
this.clientCM.registerSetting(Settings.SORT_DIRECTION, SortDir.ASCENDING);
this.clientCM.registerSetting(Settings.VIEW_MODE, ViewItems.ALL);
if (Platform.isServer()) {
this.serverCM = terminal.getConfigManager();
this.monitor = terminal
.getInventory(AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class));
if (this.monitor != null) {
this.monitor.addListener(this, null);
if (terminal instanceof IEnergySource) {
this.setPowerSource((IEnergySource) terminal);
} else if (terminal instanceof IGridHost || terminal instanceof IActionHost) {
final IGridNode node;
if (terminal instanceof IGridHost) {
node = ((IGridHost) terminal).getGridNode(AEPartLocation.INTERNAL);
} else if (terminal instanceof IActionHost) {
node = ((IActionHost) terminal).getActionableNode();
} else {
node = null;
}
if (node != null) {
this.networkNode = node;
final IGrid g = node.getGrid();
if (g != null) {
this.setPowerSource(new ChannelPowerSrc(this.networkNode,
(IEnergySource) g.getCache(IEnergyGrid.class)));
}
}
}
}
} else {
this.monitor = null;
}
this.bindPlayerInventory(ip, 0, 222 - 82);
}
@Override
public boolean isValid(Object verificationToken) {
return true;
}
@Override
public void postChange(IBaseMonitor<IAEFluidStack> monitor, Iterable<IAEFluidStack> change,
IActionSource actionSource) {
for (final IAEFluidStack is : change) {
this.fluids.add(is);
}
}
@Override
public void onListUpdate() {
for (final IContainerListener c : this.listeners) {
this.queueInventory(c);
}
}
@Override
public void addListener(IContainerListener listener) {
super.addListener(listener);
this.queueInventory(listener);
}
@Override
public void onContainerClosed(final PlayerEntity player) {
super.onContainerClosed(player);
if (this.monitor != null) {
this.monitor.removeListener(this);
}
}
private void queueInventory(final IContainerListener c) {
if (Platform.isServer() && c instanceof PlayerEntity && this.monitor != null) {
try {
MEFluidInventoryUpdatePacket piu = new MEFluidInventoryUpdatePacket();
final IItemList<IAEFluidStack> monitorCache = this.monitor.getStorageList();
for (final IAEFluidStack send : monitorCache) {
try {
piu.appendFluid(send);
} catch (final BufferOverflowException boe) {
NetworkHandler.instance().sendTo(piu, (ServerPlayerEntity) c);
piu = new MEFluidInventoryUpdatePacket();
piu.appendFluid(send);
}
}
NetworkHandler.instance().sendTo(piu, (ServerPlayerEntity) c);
} catch (final IOException e) {
AELog.debug(e);
}
}
}
@Override
public IConfigManager getConfigManager() {
if (Platform.isServer()) {
return this.serverCM;
}
return this.clientCM;
}
public void setTargetStack(final IAEFluidStack stack) {
if (Platform.isClient()) {
if (stack == null && this.clientRequestedTargetFluid == null) {
return;
}
if (stack != null && this.clientRequestedTargetFluid != null
&& stack.getFluidStack().isFluidEqual(this.clientRequestedTargetFluid.getFluidStack())) {
return;
}
NetworkHandler.instance().sendToServer(new TargetFluidStackPacket((AEFluidStack) stack));
}
this.clientRequestedTargetFluid = stack == null ? null : stack.copy();
}
@Override
public void updateSetting(IConfigManager manager, Settings settingName, Enum<?> newValue) {
if (this.getGui() != null) {
this.getGui().updateSetting(manager, settingName, newValue);
}
}
@Override
public void detectAndSendChanges() {
if (Platform.isServer()) {
if (this.monitor != this.terminal
.getInventory(AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class))) {
this.setValidContainer(false);
}
for (final Settings set : this.serverCM.getSettings()) {
final Enum<?> sideLocal = this.serverCM.getSetting(set);
final Enum<?> sideRemote = this.clientCM.getSetting(set);
if (sideLocal != sideRemote) {
this.clientCM.putSetting(set, sideLocal);
for (final IContainerListener crafter : this.listeners) {
if (crafter instanceof ServerPlayerEntity) {
NetworkHandler.instance().sendTo(new ConfigValuePacket(set.name(), sideLocal.name()),
(ServerPlayerEntity) crafter);
}
}
}
}
if (!this.fluids.isEmpty()) {
try {
final IItemList<IAEFluidStack> monitorCache = this.monitor.getStorageList();
final MEFluidInventoryUpdatePacket piu = new MEFluidInventoryUpdatePacket();
for (final IAEFluidStack is : this.fluids) {
final IAEFluidStack send = monitorCache.findPrecise(is);
if (send == null) {
is.setStackSize(0);
piu.appendFluid(is);
} else {
piu.appendFluid(send);
}
}
if (!piu.isEmpty()) {
this.fluids.resetStatus();
for (final Object c : this.listeners) {
if (c instanceof PlayerEntity) {
NetworkHandler.instance().sendTo(piu, (ServerPlayerEntity) c);
}
}
}
} catch (final IOException e) {
AELog.debug(e);
}
}
this.updatePowerStatus();
super.detectAndSendChanges();
}
}
@Override
public void doAction(ServerPlayerEntity player, InventoryAction action, int slot, long id) {
if (action != InventoryAction.FILL_ITEM && action != InventoryAction.EMPTY_ITEM) {
super.doAction(player, action, slot, id);
return;
}
final ItemStack held = player.inventory.getItemStack();
if (held.getCount() != 1) {
// only support stacksize 1 for now
return;
}
final LazyOptional<IFluidHandlerItem> fhOpt = FluidUtil.getFluidHandler(held);
if (!fhOpt.isPresent()) {
// only fluid handlers items
return;
}
IFluidHandlerItem fh = fhOpt.orElse(null);
if (action == InventoryAction.FILL_ITEM && this.clientRequestedTargetFluid != null) {
final IAEFluidStack stack = this.clientRequestedTargetFluid.copy();
// Check how much we can store in the item
stack.setStackSize(Integer.MAX_VALUE);
int amountAllowed = fh.fill(stack.getFluidStack(), FluidAction.SIMULATE);
stack.setStackSize(amountAllowed);
// Check if we can pull out of the system
final IAEFluidStack canPull = Platform.poweredExtraction(this.getPowerSource(), this.monitor, stack,
this.getActionSource(), Actionable.SIMULATE);
if (canPull == null || canPull.getStackSize() < 1) {
return;
}
// How much could fit into the container
final int canFill = fh.fill(canPull.getFluidStack(), FluidAction.SIMULATE);
if (canFill == 0) {
return;
}
// Now actually pull out of the system
stack.setStackSize(canFill);
final IAEFluidStack pulled = Platform.poweredExtraction(this.getPowerSource(), this.monitor, stack,
this.getActionSource());
if (pulled == null || pulled.getStackSize() < 1) {
// Something went wrong
AELog.error("Unable to pull fluid out of the ME system even though the simulation said yes ");
return;
}
// Actually fill
final int used = fh.fill(pulled.getFluidStack(), FluidAction.EXECUTE);
if (used != canFill) {
AELog.error("Fluid item [%s] reported a different possible amount than it actually accepted.",
held.getName());
}
player.inventory.setItemStack(fh.getContainer());
this.updateHeld(player);
} else if (action == InventoryAction.EMPTY_ITEM) {
// See how much we can drain from the item
final FluidVolume extract = fh.drain(Integer.MAX_VALUE, FluidAction.SIMULATE);
if (extract.isEmpty() || extract.getAmount() < 1) {
return;
}
// Check if we can push into the system
final IAEFluidStack notStorable = Platform.poweredInsert(this.getPowerSource(), this.monitor,
AEFluidStack.fromFluidStack(extract), this.getActionSource(), Actionable.SIMULATE);
if (notStorable != null && notStorable.getStackSize() > 0) {
final int toStore = (int) (extract.getAmount() - notStorable.getStackSize());
final FluidVolume storable = fh.drain(toStore, FluidAction.SIMULATE);
if (storable.isEmpty() || storable.getAmount() == 0) {
return;
} else {
extract.setAmount(storable.getAmount());
}
}
// Actually drain
final FluidVolume drained = fh.drain(extract, FluidAction.EXECUTE);
extract.setAmount(drained.getAmount());
final IAEFluidStack notInserted = Platform.poweredInsert(this.getPowerSource(), this.monitor,
AEFluidStack.fromFluidStack(extract), this.getActionSource());
if (notInserted != null && notInserted.getStackSize() > 0) {
AELog.error("Fluid item [%s] reported a different possible amount to drain than it actually provided.",
held.getName());
}
player.inventory.setItemStack(fh.getContainer());
this.updateHeld(player);
}
}
protected void updatePowerStatus() {
try {
if (this.networkNode != null) {
this.setPowered(this.networkNode.isActive());
} else if (this.getPowerSource() instanceof IEnergyGrid) {
this.setPowered(((IEnergyGrid) this.getPowerSource()).isNetworkPowered());
} else {
this.setPowered(
this.getPowerSource().extractAEPower(1, Actionable.SIMULATE, PowerMultiplier.CONFIG) > 0.8);
}
} catch (final Exception ignore) {
// :P
}
}
private IConfigManagerHost getGui() {
return this.gui;
}
public void setGui(@Nonnull final IConfigManagerHost gui) {
this.gui = gui;
}
public boolean isPowered() {
return this.hasPower;
}
private void setPowered(final boolean isPowered) {
this.hasPower = isPowered;
}
}
@@ -1,10 +0,0 @@
package appeng.fluids.container;
import java.util.Map;
import appeng.api.storage.data.IAEFluidStack;
public interface IFluidSyncContainer {
void receiveFluidSlots(final Map<Integer, IAEFluidStack> fluids);
}
@@ -1,34 +0,0 @@
/*
* 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.container.slots;
import appeng.api.storage.data.IAEFluidStack;
/**
* @author yueh
* @version rv6
* @since rv6
*/
public interface IMEFluidSlot {
IAEFluidStack getAEFluidStack();
default boolean shouldRenderAsFluid() {
return true;
}
}
@@ -1,511 +0,0 @@
/*
* 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.helper;
import java.util.Optional;
import alexiil.mc.lib.attributes.item.FixedItemInv;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.util.math.Direction;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.fluids.FluidAttributes;
import alexiil.mc.lib.attributes.fluid.volume.FluidVolume;
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
import appeng.api.AEApi;
import appeng.api.config.Actionable;
import appeng.api.config.Settings;
import appeng.api.config.Upgrades;
import appeng.api.implementations.IUpgradeableHost;
import appeng.api.networking.GridFlags;
import appeng.api.networking.IGridNode;
import appeng.api.networking.energy.IEnergySource;
import appeng.api.networking.security.IActionHost;
import appeng.api.networking.security.IActionSource;
import appeng.api.networking.ticking.IGridTickable;
import appeng.api.networking.ticking.TickRateModulation;
import appeng.api.networking.ticking.TickingRequest;
import appeng.api.storage.IMEInventory;
import appeng.api.storage.IMEMonitor;
import appeng.api.storage.IStorageChannel;
import appeng.api.storage.IStorageMonitorable;
import appeng.api.storage.IStorageMonitorableAccessor;
import appeng.api.storage.channels.IFluidStorageChannel;
import appeng.api.storage.channels.IItemStorageChannel;
import appeng.api.storage.data.IAEFluidStack;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IAEStack;
import appeng.api.util.AECableType;
import appeng.api.util.AEPartLocation;
import appeng.api.util.DimensionalCoord;
import appeng.api.util.IConfigManager;
import appeng.capabilities.Capabilities;
import appeng.core.settings.TickRates;
import appeng.fluids.util.AEFluidInventory;
import appeng.fluids.util.IAEFluidInventory;
import appeng.fluids.util.IAEFluidTank;
import appeng.me.GridAccessException;
import appeng.me.helpers.AENetworkProxy;
import appeng.me.helpers.MachineSource;
import appeng.me.storage.MEMonitorIFluidHandler;
import appeng.me.storage.MEMonitorPassThrough;
import appeng.me.storage.NullInventory;
import appeng.util.ConfigManager;
import appeng.util.IConfigManagerHost;
import appeng.util.Platform;
public class DualityFluidInterface
implements IGridTickable, IStorageMonitorable, IAEFluidInventory, IUpgradeableHost, IConfigManagerHost {
public static final int NUMBER_OF_TANKS = 6;
public static final int TANK_CAPACITY = FluidAttributes.BUCKET_VOLUME * 4;
private final ConfigManager cm = new ConfigManager(this);
private final AENetworkProxy gridProxy;
private final IFluidInterfaceHost iHost;
private final IActionSource mySource;
private final IActionSource interfaceRequestSource;
private boolean hasConfig = false;
private final IStorageMonitorableAccessor accessor = this::getMonitorable;
private final AEFluidInventory tanks = new AEFluidInventory(this, NUMBER_OF_TANKS, TANK_CAPACITY);
private final AEFluidInventory config = new AEFluidInventory(this, NUMBER_OF_TANKS);
private final IAEFluidStack[] requireWork;
private int isWorking = -1;
private int priority;
private final MEMonitorPassThrough<IAEItemStack> items = new MEMonitorPassThrough<>(
new NullInventory<IAEItemStack>(), AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class));
private final MEMonitorPassThrough<IAEFluidStack> fluids = new MEMonitorPassThrough<>(
new NullInventory<IAEFluidStack>(),
AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class));
public DualityFluidInterface(final AENetworkProxy networkProxy, final IFluidInterfaceHost ih) {
this.gridProxy = networkProxy;
this.gridProxy.setFlags(GridFlags.REQUIRE_CHANNEL);
this.iHost = ih;
this.mySource = new MachineSource(this.iHost);
this.interfaceRequestSource = new InterfaceRequestSource(this.iHost);
this.fluids.setChangeSource(this.mySource);
this.items.setChangeSource(this.mySource);
this.requireWork = new IAEFluidStack[NUMBER_OF_TANKS];
for (int i = 0; i < NUMBER_OF_TANKS; ++i) {
this.requireWork[i] = null;
}
}
public IUpgradeableHost getHost() {
if (this.iHost instanceof IUpgradeableHost) {
return this.iHost;
}
if (this.iHost instanceof IUpgradeableHost) {
return this.iHost;
}
return null;
}
@Override
public <T extends IAEStack<T>> IMEMonitor<T> getInventory(IStorageChannel<T> channel) {
if (channel == AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)) {
if (this.hasConfig()) {
return null;
}
return (IMEMonitor<T>) this.items;
} else if (channel == AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class)) {
if (this.hasConfig()) {
return (IMEMonitor<T>) new InterfaceInventory(this);
}
return (IMEMonitor<T>) this.fluids;
}
return null;
}
public IStorageMonitorable getMonitorable(final IActionSource src) {
if (Platform.canAccess(this.gridProxy, src)) {
return this;
}
return null;
}
@Override
public TickingRequest getTickingRequest(final IGridNode node) {
return new TickingRequest(TickRates.Interface.getMin(), TickRates.Interface.getMax(), !this.hasWorkToDo(),
true);
}
@Override
public TickRateModulation tickingRequest(final IGridNode node, final int ticksSinceLastCall) {
if (!this.gridProxy.isActive()) {
return TickRateModulation.SLEEP;
}
final boolean couldDoWork = this.updateStorage();
return this.hasWorkToDo() ? (couldDoWork ? TickRateModulation.URGENT : TickRateModulation.SLOWER)
: TickRateModulation.SLEEP;
}
public void notifyNeighbors() {
if (this.gridProxy.isActive()) {
try {
this.gridProxy.getTick().wakeDevice(this.gridProxy.getNode());
} catch (final GridAccessException e) {
// :P
}
}
final BlockEntity te = this.iHost.getBlockEntity();
if (te != null && te.getWorld() != null) {
Platform.notifyBlocksOfNeighbors(te.getWorld(), te.getPos());
}
}
public void gridChanged() {
try {
this.items.setInternal(this.gridProxy.getStorage()
.getInventory(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)));
this.fluids.setInternal(this.gridProxy.getStorage()
.getInventory(AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class)));
} catch (final GridAccessException gae) {
this.items.setInternal(new NullInventory<IAEItemStack>());
this.fluids.setInternal(new NullInventory<IAEFluidStack>());
}
this.notifyNeighbors();
}
public AECableType getCableConnectionType(final AEPartLocation dir) {
return AECableType.SMART;
}
public DimensionalCoord getLocation() {
return new DimensionalCoord(this.iHost.getBlockEntity());
}
@SuppressWarnings("unchecked")
public <T> LazyOptional<T> getCapability(Capability<T> capabilityClass, Direction facing) {
if (capabilityClass == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) {
return (LazyOptional<T>) LazyOptional.of(() -> this.tanks);
} else if (capabilityClass == Capabilities.STORAGE_MONITORABLE_ACCESSOR) {
return (LazyOptional<T>) LazyOptional.of(() -> this.accessor);
}
return null;
}
private boolean hasConfig() {
return this.hasConfig;
}
private void readConfig() {
this.hasConfig = false;
for (int i = 0; i < this.config.getSlots(); i++) {
if (this.config.getFluidInSlot(i) != null) {
this.hasConfig = true;
break;
}
}
final boolean had = this.hasWorkToDo();
for (int x = 0; x < NUMBER_OF_TANKS; x++) {
this.updatePlan(x);
}
final boolean has = this.hasWorkToDo();
if (had != has) {
try {
if (has) {
this.gridProxy.getTick().alertDevice(this.gridProxy.getNode());
} else {
this.gridProxy.getTick().sleepDevice(this.gridProxy.getNode());
}
} catch (final GridAccessException e) {
// :P
}
}
this.notifyNeighbors();
}
private boolean updateStorage() {
boolean didSomething = false;
for (int x = 0; x < NUMBER_OF_TANKS; x++) {
if (this.requireWork[x] != null) {
didSomething = this.usePlan(x) || didSomething;
}
}
return didSomething;
}
private boolean hasWorkToDo() {
for (final IAEFluidStack requiredWork : this.requireWork) {
if (requiredWork != null) {
return true;
}
}
return false;
}
private void updatePlan(final int slot) {
final IAEFluidStack req = this.config.getFluidInSlot(slot);
final IAEFluidStack stored = this.tanks.getFluidInSlot(slot);
if (req == null && (stored != null && stored.getStackSize() > 0)) {
final IAEFluidStack work = stored.copy();
this.requireWork[slot] = work.setStackSize(-work.getStackSize());
return;
} else if (req != null) {
if (stored == null || stored.getStackSize() == 0) // need to add stuff!
{
this.requireWork[slot] = req.copy();
this.requireWork[slot].setStackSize(TANK_CAPACITY);
return;
} else if (req.equals(stored)) // same type ( qty different? )!
{
if (stored.getStackSize() < TANK_CAPACITY) {
this.requireWork[slot] = req.copy();
this.requireWork[slot].setStackSize(TANK_CAPACITY - stored.getStackSize());
return;
}
} else
// Stored != null; dispose!
{
final IAEFluidStack work = stored.copy();
this.requireWork[slot] = work.setStackSize(-work.getStackSize());
return;
}
}
this.requireWork[slot] = null;
}
private boolean usePlan(final int slot) {
IAEFluidStack work = this.requireWork[slot];
this.isWorking = slot;
boolean changed = false;
try {
final IMEInventory<IAEFluidStack> dest = this.gridProxy.getStorage()
.getInventory(AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class));
final IEnergySource src = this.gridProxy.getEnergy();
if (work.getStackSize() > 0) {
// make sure strange things didn't happen...
if (this.tanks.fill(slot, work.getFluidStack(), false) != work.getStackSize()) {
changed = true;
} else {
final IAEFluidStack acquired = Platform.poweredExtraction(src, dest, work,
this.interfaceRequestSource);
if (acquired != null) {
changed = true;
final int filled = this.tanks.fill(slot, acquired.getFluidStack(), true);
if (filled != acquired.getStackSize()) {
throw new IllegalStateException("bad attempt at managing tanks. ( fill )");
}
}
}
} else if (work.getStackSize() < 0) {
IAEFluidStack toStore = work.copy();
toStore.setStackSize(-toStore.getStackSize());
// make sure strange things didn't happen...
final FluidVolume canExtract = this.tanks.drain(slot, toStore.getFluidStack(), false);
if (canExtract.isEmpty() || canExtract.getAmount() != toStore.getStackSize()) {
changed = true;
} else {
IAEFluidStack notStored = Platform.poweredInsert(src, dest, toStore, this.interfaceRequestSource);
toStore.setStackSize(toStore.getStackSize() - (notStored == null ? 0 : notStored.getStackSize()));
if (toStore.getStackSize() > 0) {
// extract items!
changed = true;
final FluidVolume removed = this.tanks.drain(slot, toStore.getFluidStack(), true);
if (removed.isEmpty() || toStore.getStackSize() != removed.getAmount()) {
throw new IllegalStateException("bad attempt at managing tanks. ( drain )");
}
}
}
}
} catch (final GridAccessException e) {
// :P
}
if (changed) {
this.updatePlan(slot);
}
this.isWorking = -1;
return changed;
}
@Override
public void onFluidInventoryChanged(final IAEFluidTank inventory, final int slot) {
if (this.isWorking == slot) {
return;
}
if (inventory == this.config) {
this.readConfig();
} else if (inventory == this.tanks) {
this.saveChanges();
final boolean had = this.hasWorkToDo();
this.updatePlan(slot);
final boolean now = this.hasWorkToDo();
if (had != now) {
try {
if (now) {
this.gridProxy.getTick().alertDevice(this.gridProxy.getNode());
} else {
this.gridProxy.getTick().sleepDevice(this.gridProxy.getNode());
}
} catch (final GridAccessException e) {
// :P
}
}
}
}
public int getPriority() {
return this.priority;
}
public void setPriority(final int newValue) {
this.priority = newValue;
}
public void writeToNBT(final CompoundTag data) {
data.putInt("priority", this.priority);
this.tanks.writeToNBT(data, "storage");
this.config.writeToNBT(data, "config");
}
public void readFromNBT(final CompoundTag data) {
this.config.readFromNBT(data, "config");
this.tanks.readFromNBT(data, "storage");
this.priority = data.getInt("priority");
this.readConfig();
}
public IAEFluidTank getConfig() {
return this.config;
}
public IAEFluidTank getTanks() {
return this.tanks;
}
private class InterfaceRequestSource extends MachineSource {
private final InterfaceRequestContext context;
InterfaceRequestSource(IActionHost v) {
super(v);
this.context = new InterfaceRequestContext();
}
@Override
public <T> Optional<T> context(Class<T> key) {
if (key == InterfaceRequestContext.class) {
return (Optional<T>) Optional.of(this.context);
}
return super.context(key);
}
}
private class InterfaceRequestContext implements Comparable<Integer> {
@Override
public int compareTo(Integer o) {
return Integer.compare(DualityFluidInterface.this.priority, o);
}
}
private class InterfaceInventory extends MEMonitorIFluidHandler {
InterfaceInventory(final DualityFluidInterface tileInterface) {
super(tileInterface.tanks);
this.setActionSource(new MachineSource(tileInterface.iHost));
}
@Override
public IAEFluidStack injectItems(final IAEFluidStack input, final Actionable type, final IActionSource src) {
final Optional<InterfaceRequestContext> context = src.context(InterfaceRequestContext.class);
final boolean isInterface = context.isPresent();
if (isInterface) {
return input;
}
return super.injectItems(input, type, src);
}
@Override
public IAEFluidStack extractItems(final IAEFluidStack request, final Actionable type, final IActionSource src) {
final Optional<InterfaceRequestContext> context = src.context(InterfaceRequestContext.class);
final boolean hasLowerOrEqualPriority = context
.map(c -> c.compareTo(DualityFluidInterface.this.priority) <= 0).orElse(false);
if (hasLowerOrEqualPriority) {
return null;
}
return super.extractItems(request, type, src);
}
}
public void saveChanges() {
this.iHost.saveChanges();
}
@Override
public IConfigManager getConfigManager() {
return this.cm;
}
@Override
public FixedItemInv getInventoryByName(String name) {
return null;
}
@Override
public int getInstalledUpgrades(Upgrades u) {
return 0;
}
@Override
public BlockEntity getTile() {
return (BlockEntity) (this.iHost instanceof BlockEntity ? this.iHost : null);
}
@Override
public void updateSetting(IConfigManager manager, Settings settingName, Enum<?> newValue) {
}
}
@@ -1,101 +0,0 @@
/*
* 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.helper;
import javax.annotation.Nonnull;
import alexiil.mc.lib.attributes.fluid.volume.FluidVolume;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.fluids.FluidAttributes;
import net.minecraftforge.fluids.FluidUtil;
import appeng.api.AEApi;
import appeng.fluids.items.FluidDummyItem;
import appeng.items.contents.CellConfig;
/**
* @author DrummerMC
* @version rv6 - 2018-01-22
* @since rv6 2018-01-22
*/
public class FluidCellConfig extends CellConfig {
public FluidCellConfig(ItemStack is) {
super(is);
}
@Override
@Nonnull
public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate) {
if (stack.isEmpty() || stack.getItem() instanceof FluidDummyItem) {
super.insertItem(slot, stack, simulate);
}
LazyOptional<FluidVolume> fluidOpt = FluidUtil.getFluidContained(stack);
if (!fluidOpt.isPresent()
|| !AEApi.instance().definitions().items().dummyFluidItem().maybeStack(1).isPresent()) {
return stack;
}
FluidVolume fluid = fluidOpt.orElse(null);
fluid.setAmount(FluidAttributes.BUCKET_VOLUME);
ItemStack is = AEApi.instance().definitions().items().dummyFluidItem().maybeStack(1).get();
FluidDummyItem item = (FluidDummyItem) is.getItem();
item.setFluidStack(is, fluid);
return super.insertItem(slot, is, simulate);
}
@Override
public void setStackInSlot(int slot, @Nonnull ItemStack stack) {
if (stack.isEmpty() || stack.getItem() instanceof FluidDummyItem) {
super.setInvStack(slot, stack);
}
LazyOptional<FluidVolume> fluidOpt = FluidUtil.getFluidContained(stack);
if (!fluidOpt.isPresent()
|| !AEApi.instance().definitions().items().dummyFluidItem().maybeStack(1).isPresent()) {
return;
}
FluidVolume fluid = fluidOpt.orElse(null);
fluid.setAmount(FluidAttributes.BUCKET_VOLUME);
ItemStack is = AEApi.instance().definitions().items().dummyFluidItem().maybeStack(1).get();
FluidDummyItem item = (FluidDummyItem) is.getItem();
item.setFluidStack(is, fluid);
super.setInvStack(slot, is);
}
@Override
public boolean isItemValidForSlot(int slot, ItemStack stack) {
if (stack.isEmpty() || stack.getItem() instanceof FluidDummyItem) {
super.isItemValid(slot, stack);
}
LazyOptional<FluidVolume> fluidOpt = FluidUtil.getFluidContained(stack);
if (!fluidOpt.isPresent()
|| !AEApi.instance().definitions().items().dummyFluidItem().maybeStack(1).isPresent()) {
return false;
}
FluidVolume fluid = fluidOpt.orElse(null);
fluid.setAmount(FluidAttributes.BUCKET_VOLUME);
ItemStack is = AEApi.instance().definitions().items().dummyFluidItem().maybeStack(1).get();
FluidDummyItem item = (FluidDummyItem) is.getItem();
item.setFluidStack(is, fluid);
return super.isItemValid(slot, is);
}
}
@@ -1,79 +0,0 @@
package appeng.fluids.helper;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.inventory.container.IContainerListener;
import appeng.api.storage.data.IAEFluidStack;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.FluidSlotPacket;
import appeng.fluids.util.AEFluidInventory;
import appeng.fluids.util.IAEFluidTank;
public class FluidSyncHelper {
private final IAEFluidTank inv;
private final IAEFluidTank cache;
private final int idOffset;
public FluidSyncHelper(final IAEFluidTank inv, final int idOffset) {
this.inv = inv;
this.cache = new AEFluidInventory(null, inv.getSlots());
this.idOffset = idOffset;
}
public void sendFull(final Iterable<IContainerListener> listeners) {
this.sendDiffMap(this.createDiffMap(true), listeners);
}
public void sendDiff(final Iterable<IContainerListener> listeners) {
this.sendDiffMap(this.createDiffMap(false), listeners);
}
public void readPacket(final Map<Integer, IAEFluidStack> data) {
for (int i = 0; i < this.inv.getSlots(); ++i) {
if (data.containsKey(i + this.idOffset)) {
this.inv.setFluidInSlot(i, data.get(i + this.idOffset));
}
}
}
private void sendDiffMap(final Map<Integer, IAEFluidStack> data, final Iterable<IContainerListener> listeners) {
if (data.isEmpty()) {
return;
}
for (final IContainerListener l : listeners) {
if (l instanceof ServerPlayerEntity) {
NetworkHandler.instance().sendTo(new FluidSlotPacket(data), (ServerPlayerEntity) l);
}
}
}
private final Map<Integer, IAEFluidStack> createDiffMap(final boolean full) {
final Map<Integer, IAEFluidStack> ret = new HashMap<>();
for (int i = 0; i < this.inv.getSlots(); ++i) {
if (full || !this.equalsSlot(i)) {
ret.put(i + this.idOffset, this.inv.getFluidInSlot(i));
}
if (!full) {
this.cache.setFluidInSlot(i, this.inv.getFluidInSlot(i));
}
}
return ret;
}
private final boolean equalsSlot(int slot) {
final IAEFluidStack stackA = this.inv.getFluidInSlot(slot);
final IAEFluidStack stackB = this.cache.getFluidInSlot(slot);
if (!Objects.equals(stackA, stackB)) {
return false;
}
return stackA == null || stackA.getStackSize() == stackB.getStackSize();
}
}
@@ -1,38 +0,0 @@
/*
* 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.helper;
import java.util.EnumSet;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.util.math.Direction;
import appeng.api.implementations.IUpgradeableHost;
import appeng.api.networking.security.IActionHost;
import appeng.me.helpers.IGridProxyable;
public interface IFluidInterfaceHost extends IActionHost, IGridProxyable, IUpgradeableHost {
DualityFluidInterface getDualityFluidInterface();
EnumSet<Direction> getTargets();
BlockEntity getBlockEntity();
void saveChanges();
}
@@ -1,104 +0,0 @@
/*
* 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.items;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import alexiil.mc.lib.attributes.item.FixedItemInv;
import appeng.api.AEApi;
import appeng.api.storage.IStorageChannel;
import appeng.api.storage.channels.IFluidStorageChannel;
import appeng.api.storage.data.IAEFluidStack;
import appeng.fluids.helper.FluidCellConfig;
import appeng.items.materials.MaterialType;
import appeng.items.storage.AbstractStorageCell;
import appeng.util.InventoryAdaptor;
/**
* @author DrummerMC
* @version rv6 - 2018-01-17
* @since rv6 2018-01-17
*/
public final class BasicFluidStorageCell extends AbstractStorageCell<IAEFluidStack> {
private final int perType;
private final double idleDrain;
public BasicFluidStorageCell(Properties props, final MaterialType whichCell, final int kilobytes) {
super(props, whichCell, kilobytes);
switch (whichCell) {
case FLUID_1K_CELL_COMPONENT:
this.idleDrain = 0.5;
this.perType = 8;
break;
case FLUID_4K_CELL_COMPONENT:
this.idleDrain = 1.0;
this.perType = 32;
break;
case FLUID_16K_CELL_COMPONENT:
this.idleDrain = 1.5;
this.perType = 128;
break;
case FLUID_64K_CELL_COMPONENT:
this.idleDrain = 2.0;
this.perType = 512;
break;
default:
this.idleDrain = 0.0;
this.perType = 8;
}
}
@Override
public int getBytesPerType(ItemStack cellItem) {
return this.perType;
}
@Override
public double getIdleDrain() {
return this.idleDrain;
}
@Override
public IStorageChannel<IAEFluidStack> getChannel() {
return AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class);
}
@Override
public int getTotalTypes(final ItemStack cellItem) {
return 5;
}
@Override
public FixedItemInv getConfigInventory(final ItemStack is) {
return new FluidCellConfig(is);
}
@Override
protected void dropEmptyStorageCellCase(final InventoryAdaptor ia, final PlayerEntity player) {
AEApi.instance().definitions().materials().emptyStorageCell().maybeStack(1).ifPresent(is -> {
final ItemStack extraA = ia.addItems(is);
if (!extraA.isEmpty()) {
player.dropItem(extraA, false);
}
});
}
}
@@ -0,0 +1,76 @@
/*
* 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.items;
import alexiil.mc.lib.attributes.fluid.FluidVolumeUtil;
import alexiil.mc.lib.attributes.fluid.amount.FluidAmount;
import alexiil.mc.lib.attributes.fluid.volume.FluidKeys;
import alexiil.mc.lib.attributes.fluid.volume.FluidVolume;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.util.collection.DefaultedList;
import appeng.items.AEBaseItem;
/**
* Dummy item to display the fluid Icon
*
* @author DrummerMC
* @version rv6 - 2018-01-22
* @since rv6 2018-01-22
*/
public class FluidDummyItem extends AEBaseItem {
public FluidDummyItem(Settings properties) {
super(properties);
}
@Override
public String getTranslationKey(ItemStack stack) {
FluidVolume fluidStack = this.getFluidStack(stack);
if (fluidStack.isEmpty()) {
fluidStack = FluidKeys.WATER.withAmount(FluidAmount.BUCKET);
}
return fluidStack.getName().getString();
}
public FluidVolume getFluidStack(ItemStack is) {
CompoundTag tag = is.getTag();
if (tag != null) {
return FluidVolume.fromTag(tag);
}
return FluidVolumeUtil.EMPTY;
}
public void setFluidStack(ItemStack is, FluidVolume fs) {
if (fs.isEmpty()) {
is.setTag(null);
} else {
CompoundTag tag = new CompoundTag();
fs.toTag(tag);
is.setTag(tag);
}
}
@Override
public void appendStacks(ItemGroup group, DefaultedList<ItemStack> items) {
// Don't show this item in CreativeTabs
}
}
@@ -1,27 +0,0 @@
package appeng.fluids.items;
import net.minecraft.client.renderer.color.IItemColor;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.fluids.FluidStack;
@OnlyIn(Dist.CLIENT)
public class FluidDummyItemColor implements IItemColor {
@Override
public int getColor(ItemStack stack, int tintIndex) {
Item item = stack.getItem();
if (!(item instanceof FluidDummyItem)) {
return -1;
}
FluidDummyItem fluidItem = (FluidDummyItem) item;
FluidStack fluidStack = fluidItem.getFluidStack(stack);
return fluidStack.getFluid().getAttributes().getColor(fluidStack);
}
}
@@ -1,320 +0,0 @@
package appeng.fluids.parts;
import java.util.List;
import javax.annotation.Nonnull;
import alexiil.mc.lib.attributes.fluid.volume.FluidVolume;
import net.minecraft.block.BlockState;
import net.minecraft.block.IBucketPickupHandler;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.fluid.Fluid;
import net.minecraft.fluid.Fluids;
import net.minecraft.fluid.IFluidState;
import net.minecraft.item.ItemStack;
import net.minecraft.tag.FluidTags;
import net.minecraft.tag.Tag;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
import net.minecraftforge.fluids.FluidAttributes;
import appeng.api.AEApi;
import appeng.api.config.Actionable;
import appeng.api.config.PowerMultiplier;
import appeng.api.networking.IGridNode;
import appeng.api.networking.energy.IEnergyGrid;
import appeng.api.networking.events.MENetworkChannelsChanged;
import appeng.api.networking.events.MENetworkEventSubscribe;
import appeng.api.networking.events.MENetworkPowerStatusChange;
import appeng.api.networking.security.IActionSource;
import appeng.api.networking.storage.IStorageGrid;
import appeng.api.networking.ticking.IGridTickable;
import appeng.api.networking.ticking.TickRateModulation;
import appeng.api.networking.ticking.TickingRequest;
import appeng.api.parts.IPart;
import appeng.api.parts.IPartCollisionHelper;
import appeng.api.parts.IPartHost;
import appeng.api.parts.IPartModel;
import appeng.api.storage.IMEInventory;
import appeng.api.storage.channels.IFluidStorageChannel;
import appeng.api.storage.data.IAEFluidStack;
import appeng.api.util.AECableType;
import appeng.api.util.AEPartLocation;
import appeng.core.AppEng;
import appeng.core.settings.TickRates;
import appeng.core.sync.packets.BlockTransitionEffectPacket;
import appeng.fluids.util.AEFluidStack;
import appeng.items.parts.PartModels;
import appeng.me.GridAccessException;
import appeng.me.helpers.MachineSource;
import appeng.parts.BasicStatePart;
import appeng.parts.automation.PlaneConnections;
import appeng.parts.automation.PlaneModelData;
import appeng.parts.automation.PlaneModels;
import appeng.util.Platform;
public class FluidAnnihilationPlanePart extends BasicStatePart implements IGridTickable {
public static final Identifier TAG_BLACKLIST = new Identifier(AppEng.MOD_ID,
"blacklisted/fluid_annihilation_plane");
private static final PlaneModels MODELS = new PlaneModels("part/fluid_annihilation_plane",
"part/fluid_annihilation_plane_on");
@PartModels
public static List<IPartModel> getModels() {
return MODELS.getModels();
}
private final IActionSource mySrc = new MachineSource(this);
public FluidAnnihilationPlanePart(final ItemStack is) {
super(is);
}
@Override
public void getBoxes(final IPartCollisionHelper bch) {
int minX = 1;
int minY = 1;
int maxX = 15;
int maxY = 15;
final IPartHost host = this.getHost();
if (host != null) {
final BlockEntity te = host.getTile();
final BlockPos pos = te.getPos();
final Direction e = bch.getWorldX();
final Direction u = bch.getWorldY();
if (this.isAnnihilationPlane(te.getWorld().getBlockEntity(pos.offset(e.getOpposite())), this.getSide())) {
minX = 0;
}
if (this.isAnnihilationPlane(te.getWorld().getBlockEntity(pos.offset(e)), this.getSide())) {
maxX = 16;
}
if (this.isAnnihilationPlane(te.getWorld().getBlockEntity(pos.offset(u.getOpposite())), this.getSide())) {
minY = 0;
}
if (this.isAnnihilationPlane(te.getWorld().getBlockEntity(pos.offset(e)), this.getSide())) {
maxY = 16;
}
}
bch.addBox(5, 5, 14, 11, 11, 15);
bch.addBox(minX, minY, 15, maxX, maxY, 16);
}
public PlaneConnections getConnections() {
final Direction facingRight, facingUp;
AEPartLocation location = this.getSide();
switch (location) {
case UP:
facingRight = Direction.EAST;
facingUp = Direction.NORTH;
break;
case DOWN:
facingRight = Direction.WEST;
facingUp = Direction.NORTH;
break;
case NORTH:
facingRight = Direction.WEST;
facingUp = Direction.UP;
break;
case SOUTH:
facingRight = Direction.EAST;
facingUp = Direction.UP;
break;
case WEST:
facingRight = Direction.SOUTH;
facingUp = Direction.UP;
break;
case EAST:
facingRight = Direction.NORTH;
facingUp = Direction.UP;
break;
default:
case INTERNAL:
return PlaneConnections.of(false, false, false, false);
}
boolean left = false, right = false, down = false, up = false;
final IPartHost host = this.getHost();
if (host != null) {
final BlockEntity te = host.getTile();
final BlockPos pos = te.getPos();
if (this.isAnnihilationPlane(te.getWorld().getBlockEntity(pos.offset(facingRight.getOpposite())),
this.getSide())) {
left = true;
}
if (this.isAnnihilationPlane(te.getWorld().getBlockEntity(pos.offset(facingRight)), this.getSide())) {
right = true;
}
if (this.isAnnihilationPlane(te.getWorld().getBlockEntity(pos.offset(facingUp.getOpposite())),
this.getSide())) {
down = true;
}
if (this.isAnnihilationPlane(te.getWorld().getBlockEntity(pos.offset(facingUp)), this.getSide())) {
up = true;
}
}
return PlaneConnections.of(up, right, down, left);
}
@Override
public void onneighborUpdate(BlockView w, BlockPos pos, BlockPos neighbor) {
if (pos.offset(this.getSide().getFacing()).equals(neighbor)) {
this.refresh();
}
}
@Override
public float getCableConnectionLength(AECableType cable) {
return 1;
}
private boolean isAnnihilationPlane(final BlockEntity blockTileEntity, final AEPartLocation side) {
if (blockTileEntity instanceof IPartHost) {
final IPart p = ((IPartHost) blockTileEntity).getPart(side);
return p != null && p.getClass() == this.getClass();
}
return false;
}
private void refresh() {
try {
this.getProxy().getTick().alertDevice(this.getProxy().getNode());
} catch (final GridAccessException e) {
// :P
}
}
@Override
@MENetworkEventSubscribe
public void chanRender(final MENetworkChannelsChanged c) {
this.refresh();
this.getHost().markForUpdate();
}
@Override
@MENetworkEventSubscribe
public void powerRender(final MENetworkPowerStatusChange c) {
this.refresh();
this.getHost().markForUpdate();
}
private TickRateModulation pickupFluid() {
if (!this.getProxy().isActive()) {
return TickRateModulation.SLEEP;
}
final BlockEntity te = this.getTile();
final World w = te.getWorld();
final BlockPos pos = te.getPos().offset(this.getSide().getFacing());
BlockState blockstate = w.getBlockState(pos);
if (blockstate.getBlock() instanceof IBucketPickupHandler) {
IFluidState fluidState = blockstate.getFluidState();
Fluid fluid = fluidState.getFluid();
if (isFluidBlacklisted(fluid)) {
return TickRateModulation.SLEEP;
}
if (fluid != Fluids.EMPTY && fluidState.isSource()) {
// Attempt to store the fluid in the network
final IAEFluidStack blockFluid = AEFluidStack
.fromFluidStack(new FluidVolume(fluidState.getFluid(), FluidAttributes.BUCKET_VOLUME));
if (this.storeFluid(blockFluid, false)) {
// If that would succeed, actually slurp up the liquid as if we were using a
// bucket
// This _MIGHT_ change the liquid, and if it does, and we dont have enough
// space, tough luck. you loose the source block.
fluid = ((IBucketPickupHandler) blockstate.getBlock()).pickupFluid(w, pos, blockstate);
this.storeFluid(AEFluidStack.fromFluidStack(new FluidVolume(fluid, FluidAttributes.BUCKET_VOLUME)),
true);
AppEng.instance().sendToAllNearExcept(null, pos.getX(), pos.getY(), pos.getZ(), 64, w,
new BlockTransitionEffectPacket(pos, blockstate, this.getSide().getOpposite(),
BlockTransitionEffectPacket.SoundMode.FLUID));
return TickRateModulation.URGENT;
}
return TickRateModulation.IDLE;
}
}
// nothing to do here :)
return TickRateModulation.SLEEP;
}
@Override
public TickingRequest getTickingRequest(final IGridNode node) {
return new TickingRequest(TickRates.AnnihilationPlane.getMin(), TickRates.AnnihilationPlane.getMax(), false,
true);
}
@Override
public TickRateModulation tickingRequest(final IGridNode node, final int ticksSinceLastCall) {
return this.pickupFluid();
}
private boolean storeFluid(IAEFluidStack stack, boolean modulate) {
try {
final IStorageGrid storage = this.getProxy().getStorage();
final IMEInventory<IAEFluidStack> inv = storage
.getInventory(AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class));
if (modulate) {
final IEnergyGrid energy = this.getProxy().getEnergy();
return Platform.poweredInsert(energy, inv, stack, this.mySrc) == null;
} else {
final float requiredPower = stack.getStackSize() / Math.min(1.0f, stack.getChannel().transferFactor());
final IEnergyGrid energy = this.getProxy().getEnergy();
if (energy.extractAEPower(requiredPower, Actionable.SIMULATE, PowerMultiplier.CONFIG) < requiredPower) {
return false;
}
final IAEFluidStack leftOver = inv.injectItems(stack, Actionable.SIMULATE, this.mySrc);
return leftOver == null || leftOver.getStackSize() == 0;
}
} catch (final GridAccessException e) {
// :P
}
return false;
}
@Override
public IPartModel getStaticModels() {
return MODELS.getModel(this.isPowered(), this.isActive());
}
@Nonnull
@Override
public IModelData getModelData() {
return new PlaneModelData(getConnections());
}
private boolean isFluidBlacklisted(Fluid fluid) {
Tag<Fluid> tag = FluidTags.getCollection().getOrCreate(TAG_BLACKLIST);
return fluid.isIn(tag);
}
}
@@ -1,170 +0,0 @@
/*
* 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.parts;
import javax.annotation.Nonnull;
import net.minecraft.item.ItemStack;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.util.Identifier;
import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
import net.minecraftforge.fluids.capability.IFluidHandler;
import net.minecraftforge.fluids.capability.IFluidHandler.FluidAction;
import appeng.api.config.Actionable;
import appeng.api.config.FuzzyMode;
import appeng.api.config.RedstoneMode;
import appeng.api.config.SchedulingMode;
import appeng.api.config.Settings;
import appeng.api.config.YesNo;
import appeng.api.networking.IGridNode;
import appeng.api.networking.security.IActionSource;
import appeng.api.networking.ticking.TickRateModulation;
import appeng.api.networking.ticking.TickingRequest;
import appeng.api.parts.IPartCollisionHelper;
import appeng.api.parts.IPartModel;
import appeng.api.storage.IMEMonitor;
import appeng.api.storage.data.IAEFluidStack;
import appeng.core.AppEng;
import appeng.core.settings.TickRates;
import appeng.items.parts.PartModels;
import appeng.me.GridAccessException;
import appeng.me.helpers.MachineSource;
import appeng.parts.PartModel;
/**
* @author BrockWS
* @version rv6 - 30/04/2018
* @since rv6 30/04/2018
*/
public class FluidExportBusPart extends SharedFluidBusPart {
public static final Identifier MODEL_BASE = new Identifier(AppEng.MOD_ID, "part/fluid_export_bus_base");
@PartModels
public static final IPartModel MODELS_OFF = new PartModel(MODEL_BASE,
new Identifier(AppEng.MOD_ID, "part/fluid_export_bus_off"));
@PartModels
public static final IPartModel MODELS_ON = new PartModel(MODEL_BASE,
new Identifier(AppEng.MOD_ID, "part/fluid_export_bus_on"));
@PartModels
public static final IPartModel MODELS_HAS_CHANNEL = new PartModel(MODEL_BASE,
new Identifier(AppEng.MOD_ID, "part/fluid_export_bus_has_channel"));
private final IActionSource source;
public FluidExportBusPart(ItemStack is) {
super(is);
this.getConfigManager().registerSetting(Settings.REDSTONE_CONTROLLED, RedstoneMode.IGNORE);
this.getConfigManager().registerSetting(Settings.FUZZY_MODE, FuzzyMode.IGNORE_ALL);
this.getConfigManager().registerSetting(Settings.CRAFT_ONLY, YesNo.NO);
this.getConfigManager().registerSetting(Settings.SCHEDULING_MODE, SchedulingMode.DEFAULT);
this.source = new MachineSource(this);
}
@Override
public TickingRequest getTickingRequest(IGridNode node) {
return new TickingRequest(TickRates.FluidExportBus.getMin(), TickRates.FluidExportBus.getMax(),
this.isSleeping(), false);
}
@Override
public TickRateModulation tickingRequest(IGridNode node, int ticksSinceLastCall) {
return this.canDoBusWork() ? this.doBusWork() : TickRateModulation.IDLE;
}
@Override
protected boolean canDoBusWork() {
return this.getProxy().isActive();
}
@Override
protected TickRateModulation doBusWork() {
if (!this.canDoBusWork()) {
return TickRateModulation.IDLE;
}
final BlockEntity te = this.getConnectedTE();
LazyOptional<IFluidHandler> fhOpt = LazyOptional.empty();
if (te != null) {
fhOpt = te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY,
this.getSide().getFacing().getOpposite());
}
if (fhOpt.isPresent()) {
try {
final IFluidHandler fh = fhOpt.orElse(null);
final IMEMonitor<IAEFluidStack> inv = this.getProxy().getStorage().getInventory(this.getChannel());
if (fh != null) {
for (int i = 0; i < this.getConfig().getSlots(); i++) {
IAEFluidStack fluid = this.getConfig().getFluidInSlot(i);
if (fluid != null) {
final IAEFluidStack toExtract = fluid.copy();
toExtract.setStackSize(this.calculateAmountToSend());
final IAEFluidStack out = inv.extractItems(toExtract, Actionable.SIMULATE, this.source);
if (out != null) {
int wasInserted = fh.fill(out.getFluidStack(), FluidAction.EXECUTE);
if (wasInserted > 0) {
toExtract.setStackSize(wasInserted);
inv.extractItems(toExtract, Actionable.MODULATE, this.source);
return TickRateModulation.FASTER;
}
}
}
}
return TickRateModulation.SLOWER;
}
} catch (GridAccessException e) {
// Ignore
}
}
return TickRateModulation.SLEEP;
}
@Override
public void getBoxes(final IPartCollisionHelper bch) {
bch.addBox(4, 4, 12, 12, 12, 14);
bch.addBox(5, 5, 14, 11, 11, 15);
bch.addBox(6, 6, 15, 10, 10, 16);
bch.addBox(6, 6, 11, 10, 10, 12);
}
@Override
public RedstoneMode getRSMode() {
return (RedstoneMode) this.getConfigManager().getSetting(Settings.REDSTONE_CONTROLLED);
}
@Nonnull
@Override
public IPartModel getStaticModels() {
if (this.isActive() && this.isPowered()) {
return MODELS_HAS_CHANNEL;
} else if (this.isPowered()) {
return MODELS_ON;
} else {
return MODELS_OFF;
}
}
}
@@ -1,224 +0,0 @@
package appeng.fluids.parts;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import javax.annotation.Nonnull;
import alexiil.mc.lib.attributes.fluid.volume.FluidVolume;
import net.minecraft.block.BlockState;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.util.Hand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.minecraft.server.world.ServerWorld;
import net.minecraftforge.common.util.FakePlayer;
import net.minecraftforge.common.util.FakePlayerFactory;
import net.minecraftforge.fluids.FluidAttributes;
import net.minecraftforge.fluids.FluidUtil;
import net.minecraftforge.fluids.capability.IFluidHandler;
import net.minecraftforge.fluids.capability.templates.FluidTank;
import appeng.api.AEApi;
import appeng.api.config.AccessRestriction;
import appeng.api.config.Actionable;
import appeng.api.config.IncludeExclude;
import appeng.api.config.Upgrades;
import appeng.api.networking.events.MENetworkCellArrayUpdate;
import appeng.api.networking.events.MENetworkChannelsChanged;
import appeng.api.networking.events.MENetworkEventSubscribe;
import appeng.api.networking.events.MENetworkPowerStatusChange;
import appeng.api.networking.security.IActionSource;
import appeng.api.parts.IPartModel;
import appeng.api.storage.IMEInventoryHandler;
import appeng.api.storage.IStorageChannel;
import appeng.api.storage.channels.IFluidStorageChannel;
import appeng.api.storage.data.IAEFluidStack;
import appeng.api.storage.data.IItemList;
import appeng.api.util.AEPartLocation;
import appeng.container.ContainerLocator;
import appeng.container.ContainerOpener;
import appeng.fluids.container.FluidFormationPlaneContainer;
import appeng.fluids.util.AEFluidInventory;
import appeng.fluids.util.IAEFluidInventory;
import appeng.fluids.util.IAEFluidTank;
import appeng.items.parts.PartModels;
import appeng.me.GridAccessException;
import appeng.me.storage.MEInventoryHandler;
import appeng.parts.automation.AbstractFormationPlanePart;
import appeng.parts.automation.PlaneModelData;
import appeng.parts.automation.PlaneModels;
import appeng.util.Platform;
import appeng.util.prioritylist.PrecisePriorityList;
public class FluidFormationPlanePart extends AbstractFormationPlanePart<IAEFluidStack> implements IAEFluidInventory {
private static final PlaneModels MODELS = new PlaneModels("part/fluid_formation_plane",
"part/fluid_formation_plane_on");
@PartModels
public static List<IPartModel> getModels() {
return MODELS.getModels();
}
private final MEInventoryHandler<IAEFluidStack> myHandler = new MEInventoryHandler<>(this,
AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class));
private final AEFluidInventory config = new AEFluidInventory(this, 63);
public FluidFormationPlanePart(final ItemStack is) {
super(is);
this.updateHandler();
}
@Override
protected void updateHandler() {
this.myHandler.setBaseAccess(AccessRestriction.WRITE);
this.myHandler.setWhitelist(
this.getInstalledUpgrades(Upgrades.INVERTER) > 0 ? IncludeExclude.BLACKLIST : IncludeExclude.WHITELIST);
this.myHandler.setPriority(this.getPriority());
final IItemList<IAEFluidStack> priorityList = AEApi.instance().storage()
.getStorageChannel(IFluidStorageChannel.class).createList();
final int slotsToUse = 18 + this.getInstalledUpgrades(Upgrades.CAPACITY) * 9;
for (int x = 0; x < this.config.getSlots() && x < slotsToUse; x++) {
final IAEFluidStack is = this.config.getFluidInSlot(x);
if (is != null) {
priorityList.add(is);
}
}
this.myHandler.setPartitionList(new PrecisePriorityList<IAEFluidStack>(priorityList));
try {
this.getProxy().getGrid().postEvent(new MENetworkCellArrayUpdate());
} catch (final GridAccessException e) {
// :P
}
}
@Override
public IAEFluidStack injectItems(IAEFluidStack input, Actionable type, IActionSource src) {
if (this.blocked || input == null || input.getStackSize() < FluidAttributes.BUCKET_VOLUME) {
// need a full bucket
return input;
}
final BlockEntity te = this.getHost().getTile();
final World w = te.getWorld();
final AEPartLocation side = this.getSide();
final BlockPos pos = te.getPos().offset(side.getFacing());
final BlockState state = w.getBlockState(pos);
if (this.canReplace(w, state, pos)) {
if (type == Actionable.MODULATE) {
final FluidVolume fs = input.getFluidStack();
fs.setAmount(FluidAttributes.BUCKET_VOLUME);
final FluidTank tank = new FluidTank(FluidAttributes.BUCKET_VOLUME);
tank.fill(fs, IFluidHandler.FluidAction.EXECUTE);
FakePlayer fakePlayer = FakePlayerFactory.getMinecraft((ServerWorld) w);
if (!FluidUtil.tryPlaceFluid(fakePlayer, w, Hand.MAIN_HAND, pos, tank, fs)) {
return input;
}
}
final IAEFluidStack ret = input.copy();
ret.setStackSize(input.getStackSize() - FluidAttributes.BUCKET_VOLUME);
return ret.getStackSize() == 0 ? null : ret;
}
this.blocked = true;
return input;
}
private boolean canReplace(World w, BlockState state, BlockPos pos) {
return state.getMaterial().isReplaceable() && w.getFluidState(pos).isEmpty() && !state.getMaterial().isLiquid();
}
@Override
public void onFluidInventoryChanged(IAEFluidTank inv, int slot) {
if (inv == this.config) {
this.updateHandler();
}
}
@Override
public void readFromNBT(final CompoundTag data) {
super.readFromNBT(data);
this.config.readFromNBT(data, "config");
this.updateHandler();
}
@Override
public void writeToNBT(final CompoundTag data) {
super.writeToNBT(data);
this.config.writeToNBT(data, "config");
}
@Override
@MENetworkEventSubscribe
public void powerRender(final MENetworkPowerStatusChange c) {
this.stateChanged();
}
@MENetworkEventSubscribe
public void updateChannels(final MENetworkChannelsChanged changedChannels) {
this.stateChanged();
}
@Override
public boolean onPartActivate(final PlayerEntity player, final Hand hand, final Vec3d pos) {
if (Platform.isServer()) {
ContainerOpener.openContainer(FluidFormationPlaneContainer.TYPE, player, ContainerLocator.forPart(this));
}
return true;
}
@Override
public IStorageChannel<IAEFluidStack> getChannel() {
return AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class);
}
@Override
public List<IMEInventoryHandler> getCellArray(final IStorageChannel channel) {
if (this.getProxy().isActive()
&& channel == AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class)) {
final List<IMEInventoryHandler> handler = new ArrayList<>(1);
handler.add(this.myHandler);
return handler;
}
return Collections.emptyList();
}
@Override
public IPartModel getStaticModels() {
return MODELS.getModel(this.isPowered(), this.isActive());
}
@Nonnull
@Override
public IModelData getModelData() {
return new PlaneModelData(getConnections());
}
public IAEFluidTank getConfig() {
return this.config;
}
@Override
public ItemStack getItemStackRepresentation() {
return AEApi.instance().definitions().parts().fluidFormationnPlane().maybeStack(1).orElse(ItemStack.EMPTY);
}
@Override
public ScreenHandlerType<?> getContainerType() {
return FluidFormationPlaneContainer.TYPE;
}
}
@@ -1,256 +0,0 @@
/*
* 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.parts;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import alexiil.mc.lib.attributes.fluid.volume.FluidVolume;
import net.minecraftforge.fluids.capability.IFluidHandler;
import appeng.api.AEApi;
import appeng.api.config.Actionable;
import appeng.api.networking.security.IActionSource;
import appeng.api.networking.storage.IBaseMonitor;
import appeng.api.networking.ticking.TickRateModulation;
import appeng.api.storage.IMEInventory;
import appeng.api.storage.IMEMonitorHandlerReceiver;
import appeng.api.storage.IStorageChannel;
import appeng.api.storage.channels.IFluidStorageChannel;
import appeng.api.storage.data.IAEFluidStack;
import appeng.api.storage.data.IItemList;
import appeng.fluids.util.AEFluidStack;
import appeng.me.GridAccessException;
import appeng.me.helpers.IGridProxyable;
import appeng.me.storage.ITickingMonitor;
/**
* Wraps an Fluid Handler in such a way that it can be used as an IMEInventory
* for fluids.
*
* @author BrockWS
* @version rv6 - 22/05/2018
* @since rv6 22/05/2018
*/
public class FluidHandlerAdapter implements IMEInventory<IAEFluidStack>, IBaseMonitor<IAEFluidStack>, ITickingMonitor {
private final Map<IMEMonitorHandlerReceiver<IAEFluidStack>, Object> listeners = new HashMap<>();
private IActionSource source;
private final IFluidHandler fluidHandler;
private final IGridProxyable proxyable;
private final FluidHandlerAdapter.InventoryCache cache;
FluidHandlerAdapter(IFluidHandler fluidHandler, IGridProxyable proxy) {
this.fluidHandler = fluidHandler;
this.proxyable = proxy;
this.cache = new FluidHandlerAdapter.InventoryCache(this.fluidHandler);
}
@Override
public IAEFluidStack injectItems(IAEFluidStack input, Actionable type, IActionSource src) {
FluidVolume fluidStack = input.getFluidStack();
// Insert
int wasFillled = this.fluidHandler.fill(fluidStack, type.getFluidAction());
int remaining = fluidStack.getAmount() - wasFillled;
if (fluidStack.getAmount() == remaining) {
// The stack was unmodified, target tank is full
return input;
}
if (type == Actionable.MODULATE) {
try {
this.proxyable.getProxy().getTick().alertDevice(this.proxyable.getProxy().getNode());
} catch (GridAccessException ignore) {
// meh
}
}
fluidStack.setAmount(remaining);
return AEFluidStack.fromFluidStack(fluidStack);
}
@Override
public IAEFluidStack extractItems(IAEFluidStack request, Actionable mode, IActionSource src) {
FluidVolume requestedFluidStack = request.getFluidStack();
// Drain the fluid from the tank
FluidVolume gathered = this.fluidHandler.drain(requestedFluidStack, mode.getFluidAction());
if (gathered.isEmpty()) {
// If nothing was pulled from the tank, return null
return null;
}
if (mode == Actionable.MODULATE) {
try {
this.proxyable.getProxy().getTick().alertDevice(this.proxyable.getProxy().getNode());
} catch (GridAccessException ignore) {
// meh
}
}
return AEFluidStack.fromFluidStack(gathered);
}
@Override
public TickRateModulation onTick() {
List<IAEFluidStack> changes = this.cache.update();
if (!changes.isEmpty()) {
this.postDifference(changes);
return TickRateModulation.URGENT;
} else {
return TickRateModulation.SLOWER;
}
}
@Override
public IItemList<IAEFluidStack> getAvailableItems(IItemList<IAEFluidStack> out) {
return this.cache.getAvailableItems(out);
}
@Override
public IStorageChannel<IAEFluidStack> getChannel() {
return AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class);
}
@Override
public void setActionSource(IActionSource source) {
this.source = source;
}
@Override
public void addListener(final IMEMonitorHandlerReceiver<IAEFluidStack> l, final Object verificationToken) {
this.listeners.put(l, verificationToken);
}
@Override
public void removeListener(final IMEMonitorHandlerReceiver<IAEFluidStack> l) {
this.listeners.remove(l);
}
private void postDifference(Iterable<IAEFluidStack> a) {
final Iterator<Map.Entry<IMEMonitorHandlerReceiver<IAEFluidStack>, Object>> i = this.listeners.entrySet()
.iterator();
while (i.hasNext()) {
final Map.Entry<IMEMonitorHandlerReceiver<IAEFluidStack>, Object> l = i.next();
final IMEMonitorHandlerReceiver<IAEFluidStack> key = l.getKey();
if (key.isValid(l.getValue())) {
key.postChange(this, a, this.source);
} else {
i.remove();
}
}
}
private static class InventoryCache {
private IAEFluidStack[] cachedAeStacks = new IAEFluidStack[0];
private final IFluidHandler fluidHandler;
public InventoryCache(IFluidHandler fluidHandler) {
this.fluidHandler = fluidHandler;
}
public List<IAEFluidStack> update() {
final List<IAEFluidStack> changes = new ArrayList<>();
final int slots = fluidHandler.getTanks();
// Make room for new slots
if (slots > this.cachedAeStacks.length) {
this.cachedAeStacks = Arrays.copyOf(this.cachedAeStacks, slots);
}
for (int slot = 0; slot < slots; slot++) {
// Save the old stuff
final IAEFluidStack oldAEFS = this.cachedAeStacks[slot];
final FluidVolume newFS = fluidHandler.getFluidInTank(slot);
this.handlePossibleSlotChanges(slot, oldAEFS, newFS, changes);
}
// Handle cases where the number of slots actually is lower now than before
if (slots < this.cachedAeStacks.length) {
for (int slot = slots; slot < this.cachedAeStacks.length; slot++) {
final IAEFluidStack aeStack = this.cachedAeStacks[slot];
if (aeStack != null) {
final IAEFluidStack a = aeStack.copy();
a.setStackSize(-a.getStackSize());
changes.add(a);
}
}
this.cachedAeStacks = Arrays.copyOf(this.cachedAeStacks, slots);
}
return changes;
}
public IItemList<IAEFluidStack> getAvailableItems(IItemList<IAEFluidStack> out) {
Arrays.stream(this.cachedAeStacks).forEach(out::add);
return out;
}
private void handlePossibleSlotChanges(int slot, IAEFluidStack oldAeFS, FluidVolume newFS,
List<IAEFluidStack> changes) {
if (oldAeFS != null && oldAeFS.getFluidStack().isFluidEqual(newFS)) {
this.handleStackSizeChanged(slot, oldAeFS, newFS, changes);
} else {
this.handleFluidChanged(slot, oldAeFS, newFS, changes);
}
}
private void handleStackSizeChanged(int slot, IAEFluidStack oldAeFS, FluidVolume newFS,
List<IAEFluidStack> changes) {
// Still the same fluid, but amount might have changed
final long diff = newFS.getAmount() - oldAeFS.getStackSize();
if (diff != 0) {
final IAEFluidStack stack = oldAeFS.copy();
stack.setStackSize(newFS.getAmount());
this.cachedAeStacks[slot] = stack;
final IAEFluidStack a = stack.copy();
a.setStackSize(diff);
changes.add(a);
}
}
private void handleFluidChanged(int slot, IAEFluidStack oldAeFS, FluidVolume newFS,
List<IAEFluidStack> changes) {
// Completely different fluid
this.cachedAeStacks[slot] = AEFluidStack.fromFluidStack(newFS);
// If we had a stack previously in this slot, notify the network about its
// disappearance
if (oldAeFS != null) {
oldAeFS.setStackSize(-oldAeFS.getStackSize());
changes.add(oldAeFS);
}
// Notify the network about the new stack. Note that this is null if newFS was
// null
if (this.cachedAeStacks[slot] != null) {
changes.add(this.cachedAeStacks[slot]);
}
}
}
}
@@ -1,181 +0,0 @@
/*
* 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.parts;
import javax.annotation.Nonnull;
import alexiil.mc.lib.attributes.fluid.volume.FluidVolume;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Identifier;
import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
import net.minecraftforge.fluids.capability.IFluidHandler;
import net.minecraftforge.fluids.capability.IFluidHandler.FluidAction;
import appeng.api.config.Actionable;
import appeng.api.config.FuzzyMode;
import appeng.api.config.RedstoneMode;
import appeng.api.config.SchedulingMode;
import appeng.api.config.Settings;
import appeng.api.config.YesNo;
import appeng.api.networking.IGridNode;
import appeng.api.networking.security.IActionSource;
import appeng.api.networking.ticking.TickRateModulation;
import appeng.api.networking.ticking.TickingRequest;
import appeng.api.parts.IPartModel;
import appeng.api.storage.IMEMonitor;
import appeng.api.storage.data.IAEFluidStack;
import appeng.core.AppEng;
import appeng.core.settings.TickRates;
import appeng.fluids.util.AEFluidStack;
import appeng.items.parts.PartModels;
import appeng.me.GridAccessException;
import appeng.me.helpers.MachineSource;
import appeng.parts.PartModel;
/**
* @author BrockWS
* @version rv6 - 30/04/2018
* @since rv6 30/04/2018
*/
public class FluidImportBusPart extends SharedFluidBusPart {
public static final Identifier MODEL_BASE = new Identifier(AppEng.MOD_ID, "part/fluid_import_bus_base");
@PartModels
public static final IPartModel MODELS_OFF = new PartModel(MODEL_BASE,
new Identifier(AppEng.MOD_ID, "part/fluid_import_bus_off"));
@PartModels
public static final IPartModel MODELS_ON = new PartModel(MODEL_BASE,
new Identifier(AppEng.MOD_ID, "part/fluid_import_bus_on"));
@PartModels
public static final IPartModel MODELS_HAS_CHANNEL = new PartModel(MODEL_BASE,
new Identifier(AppEng.MOD_ID, "part/fluid_import_bus_has_channel"));
private final IActionSource source;
public FluidImportBusPart(ItemStack is) {
super(is);
this.getConfigManager().registerSetting(Settings.REDSTONE_CONTROLLED, RedstoneMode.IGNORE);
this.getConfigManager().registerSetting(Settings.FUZZY_MODE, FuzzyMode.IGNORE_ALL);
this.getConfigManager().registerSetting(Settings.CRAFT_ONLY, YesNo.NO);
this.getConfigManager().registerSetting(Settings.SCHEDULING_MODE, SchedulingMode.DEFAULT);
this.source = new MachineSource(this);
}
@Override
public TickingRequest getTickingRequest(IGridNode node) {
return new TickingRequest(TickRates.FluidImportBus.getMin(), TickRates.FluidImportBus.getMax(),
this.isSleeping(), false);
}
@Override
public TickRateModulation tickingRequest(IGridNode node, int ticksSinceLastCall) {
return this.canDoBusWork() ? this.doBusWork() : TickRateModulation.IDLE;
}
@Override
protected TickRateModulation doBusWork() {
if (!this.canDoBusWork()) {
return TickRateModulation.IDLE;
}
final BlockEntity te = this.getConnectedTE();
LazyOptional<IFluidHandler> fhOpt = LazyOptional.empty();
if (te != null) {
te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, this.getSide().getFacing().getOpposite());
}
if (fhOpt.isPresent()) {
try {
final IFluidHandler fh = fhOpt.orElse(null);
final IMEMonitor<IAEFluidStack> inv = this.getProxy().getStorage().getInventory(this.getChannel());
if (fh != null) {
final FluidVolume fluidStack = fh.drain(this.calculateAmountToSend(), FluidAction.SIMULATE);
if (this.filterEnabled() && !this.isInFilter(fluidStack)) {
return TickRateModulation.SLOWER;
}
final AEFluidStack aeFluidStack = AEFluidStack.fromFluidStack(fluidStack);
if (aeFluidStack != null) {
final IAEFluidStack notInserted = inv.injectItems(aeFluidStack, Actionable.MODULATE,
this.source);
if (notInserted != null && notInserted.getStackSize() > 0) {
aeFluidStack.decStackSize(notInserted.getStackSize());
}
fh.drain(aeFluidStack.getFluidStack(), FluidAction.EXECUTE);
return TickRateModulation.FASTER;
}
return TickRateModulation.IDLE;
}
} catch (GridAccessException e) {
e.printStackTrace();
}
}
return TickRateModulation.SLEEP;
}
@Override
protected boolean canDoBusWork() {
return this.getProxy().isActive();
}
private boolean isInFilter(FluidVolume fluid) {
for (int i = 0; i < this.getConfig().getSlots(); i++) {
final IAEFluidStack stack = this.getConfig().getFluidInSlot(i);
if (stack != null && stack.equals(fluid)) {
return true;
}
}
return false;
}
private boolean filterEnabled() {
for (int i = 0; i < this.getConfig().getSlots(); i++) {
final IAEFluidStack stack = this.getConfig().getFluidInSlot(i);
if (stack != null) {
return true;
}
}
return false;
}
@Override
public RedstoneMode getRSMode() {
return (RedstoneMode) this.getConfigManager().getSetting(Settings.REDSTONE_CONTROLLED);
}
@Nonnull
@Override
public IPartModel getStaticModels() {
if (this.isActive() && this.isPowered()) {
return MODELS_HAS_CHANNEL;
} else if (this.isPowered()) {
return MODELS_ON;
} else {
return MODELS_OFF;
}
}
}
@@ -1,216 +0,0 @@
/*
* 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.parts;
import java.util.EnumSet;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.util.math.Direction;
import net.minecraft.util.Hand;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.Vec3d;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.util.LazyOptional;
import alexiil.mc.lib.attributes.item.FixedItemInv;
import appeng.api.AEApi;
import appeng.api.config.Upgrades;
import appeng.api.networking.IGridNode;
import appeng.api.networking.events.MENetworkChannelsChanged;
import appeng.api.networking.events.MENetworkEventSubscribe;
import appeng.api.networking.events.MENetworkPowerStatusChange;
import appeng.api.networking.ticking.IGridTickable;
import appeng.api.networking.ticking.TickRateModulation;
import appeng.api.networking.ticking.TickingRequest;
import appeng.api.parts.IPartCollisionHelper;
import appeng.api.parts.IPartModel;
import appeng.api.storage.IMEMonitor;
import appeng.api.storage.IStorageChannel;
import appeng.api.storage.IStorageMonitorable;
import appeng.api.storage.data.IAEStack;
import appeng.api.util.AECableType;
import appeng.api.util.IConfigManager;
import appeng.container.ContainerLocator;
import appeng.container.ContainerOpener;
import appeng.core.AppEng;
import appeng.fluids.container.FluidInterfaceContainer;
import appeng.fluids.helper.DualityFluidInterface;
import appeng.fluids.helper.IFluidInterfaceHost;
import appeng.helpers.IPriorityHost;
import appeng.helpers.Reflected;
import appeng.items.parts.PartModels;
import appeng.parts.BasicStatePart;
import appeng.parts.PartModel;
import appeng.util.Platform;
public class FluidInterfacePart extends BasicStatePart
implements IGridTickable, IStorageMonitorable, IFluidInterfaceHost, IPriorityHost {
public static final Identifier MODEL_BASE = new Identifier(AppEng.MOD_ID, "part/fluid_interface_base");
@PartModels
public static final PartModel MODELS_OFF = new PartModel(MODEL_BASE,
new Identifier(AppEng.MOD_ID, "part/fluid_interface_off"));
@PartModels
public static final PartModel MODELS_ON = new PartModel(MODEL_BASE,
new Identifier(AppEng.MOD_ID, "part/fluid_interface_on"));
@PartModels
public static final PartModel MODELS_HAS_CHANNEL = new PartModel(MODEL_BASE,
new Identifier(AppEng.MOD_ID, "part/fluid_interface_has_channel"));
private final DualityFluidInterface duality = new DualityFluidInterface(this.getProxy(), this);
@Reflected
public FluidInterfacePart(final ItemStack is) {
super(is);
}
@Override
public DualityFluidInterface getDualityFluidInterface() {
return this.duality;
}
@MENetworkEventSubscribe
public void stateChange(final MENetworkChannelsChanged c) {
this.duality.notifyNeighbors();
}
@MENetworkEventSubscribe
public void stateChange(final MENetworkPowerStatusChange c) {
this.duality.notifyNeighbors();
}
@Override
public void getBoxes(final IPartCollisionHelper bch) {
bch.addBox(2, 2, 14, 14, 14, 16);
bch.addBox(5, 5, 12, 11, 11, 14);
}
@Override
public void gridChanged() {
this.duality.gridChanged();
}
@Override
public void readFromNBT(final CompoundTag data) {
super.readFromNBT(data);
this.duality.readFromNBT(data);
}
@Override
public void writeToNBT(final CompoundTag data) {
super.writeToNBT(data);
this.duality.writeToNBT(data);
}
@Override
public float getCableConnectionLength(AECableType cable) {
return 4;
}
@Override
public boolean onPartActivate(final PlayerEntity p, final Hand hand, final Vec3d pos) {
if (Platform.isServer()) {
ContainerOpener.openContainer(FluidInterfaceContainer.TYPE, p, ContainerLocator.forPart(this));
}
return true;
}
@Override
public <T extends IAEStack<T>> IMEMonitor<T> getInventory(IStorageChannel<T> channel) {
return this.duality.getInventory(channel);
}
@Override
public TickingRequest getTickingRequest(final IGridNode node) {
return this.duality.getTickingRequest(node);
}
@Override
public TickRateModulation tickingRequest(final IGridNode node, final int ticksSinceLastCall) {
return this.duality.tickingRequest(node, ticksSinceLastCall);
}
@Override
public EnumSet<Direction> getTargets() {
return EnumSet.of(this.getSide().getFacing());
}
@Override
public BlockEntity getBlockEntity() {
return super.getHost().getTile();
}
@Override
public IPartModel getStaticModels() {
if (this.isActive() && this.isPowered()) {
return MODELS_HAS_CHANNEL;
} else if (this.isPowered()) {
return MODELS_ON;
} else {
return MODELS_OFF;
}
}
@Override
public int getPriority() {
return this.duality.getPriority();
}
@Override
public void setPriority(final int newValue) {
this.duality.setPriority(newValue);
}
@Override
public <T> LazyOptional<T> getCapability(Capability<T> capabilityClass) {
return this.duality.getCapability(capabilityClass, this.getSide().getFacing());
}
@Override
public int getInstalledUpgrades(Upgrades u) {
return this.duality.getInstalledUpgrades(u);
}
@Override
public IConfigManager getConfigManager() {
return this.duality.getConfigManager();
}
@Override
public FixedItemInv getInventoryByName(String name) {
return this.duality.getInventoryByName(name);
}
@Override
public ItemStack getItemStackRepresentation() {
return AEApi.instance().definitions().parts().fluidIface().maybeStack(1).orElse(ItemStack.EMPTY);
}
@Override
public ScreenHandlerType<?> getContainerType() {
return FluidInterfaceContainer.TYPE;
}
}
@@ -1,324 +0,0 @@
package appeng.fluids.parts;
import java.util.Random;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.particle.DustParticleEffect;
import net.minecraft.util.Hand;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import appeng.api.AEApi;
import appeng.api.config.RedstoneMode;
import appeng.api.config.Settings;
import appeng.api.networking.events.MENetworkChannelsChanged;
import appeng.api.networking.events.MENetworkEventSubscribe;
import appeng.api.networking.events.MENetworkPowerStatusChange;
import appeng.api.networking.security.IActionSource;
import appeng.api.networking.storage.IBaseMonitor;
import appeng.api.networking.storage.IStackWatcher;
import appeng.api.networking.storage.IStackWatcherHost;
import appeng.api.parts.IPartCollisionHelper;
import appeng.api.parts.IPartModel;
import appeng.api.storage.IMEMonitor;
import appeng.api.storage.IMEMonitorHandlerReceiver;
import appeng.api.storage.IStorageChannel;
import appeng.api.storage.channels.IFluidStorageChannel;
import appeng.api.storage.data.IAEFluidStack;
import appeng.api.storage.data.IAEStack;
import appeng.api.storage.data.IItemList;
import appeng.api.util.AECableType;
import appeng.api.util.AEPartLocation;
import appeng.api.util.IConfigManager;
import appeng.container.ContainerLocator;
import appeng.container.ContainerOpener;
import appeng.core.AppEng;
import appeng.fluids.container.FluidLevelEmitterContainer;
import appeng.fluids.util.AEFluidInventory;
import appeng.fluids.util.IAEFluidInventory;
import appeng.fluids.util.IAEFluidTank;
import appeng.items.parts.PartModels;
import appeng.me.GridAccessException;
import appeng.parts.PartModel;
import appeng.parts.automation.UpgradeablePart;
import appeng.util.IConfigManagerHost;
import appeng.util.Platform;
public class FluidLevelEmitterPart extends UpgradeablePart
implements IStackWatcherHost, IConfigManagerHost, IAEFluidInventory, IMEMonitorHandlerReceiver<IAEFluidStack> {
@PartModels
public static final Identifier MODEL_BASE_OFF = new Identifier(AppEng.MOD_ID,
"part/level_emitter_base_off");
@PartModels
public static final Identifier MODEL_BASE_ON = new Identifier(AppEng.MOD_ID,
"part/level_emitter_base_on");
@PartModels
public static final Identifier MODEL_STATUS_OFF = new Identifier(AppEng.MOD_ID,
"part/level_emitter_status_off");
@PartModels
public static final Identifier MODEL_STATUS_ON = new Identifier(AppEng.MOD_ID,
"part/level_emitter_status_on");
@PartModels
public static final Identifier MODEL_STATUS_HAS_CHANNEL = new Identifier(AppEng.MOD_ID,
"part/level_emitter_status_has_channel");
public static final PartModel MODEL_OFF_OFF = new PartModel(MODEL_BASE_OFF, MODEL_STATUS_OFF);
public static final PartModel MODEL_OFF_ON = new PartModel(MODEL_BASE_OFF, MODEL_STATUS_ON);
public static final PartModel MODEL_OFF_HAS_CHANNEL = new PartModel(MODEL_BASE_OFF, MODEL_STATUS_HAS_CHANNEL);
public static final PartModel MODEL_ON_OFF = new PartModel(MODEL_BASE_ON, MODEL_STATUS_OFF);
public static final PartModel MODEL_ON_ON = new PartModel(MODEL_BASE_ON, MODEL_STATUS_ON);
public static final PartModel MODEL_ON_HAS_CHANNEL = new PartModel(MODEL_BASE_ON, MODEL_STATUS_HAS_CHANNEL);
private static final int FLAG_ON = 4;
private boolean prevState = false;
private long lastReportedValue = 0;
private long reportingValue = 0;
private IStackWatcher stackWatcher = null;
private final AEFluidInventory config = new AEFluidInventory(this, 1);
public FluidLevelEmitterPart(ItemStack is) {
super(is);
this.getConfigManager().registerSetting(Settings.REDSTONE_EMITTER, RedstoneMode.HIGH_SIGNAL);
}
public long getReportingValue() {
return this.reportingValue;
}
public void setReportingValue(final long v) {
this.reportingValue = v;
this.updateState();
}
@Override
public void updateSetting(IConfigManager manager, Settings settingName, Enum<?> newValue) {
this.configureWatchers();
}
@Override
public void updateWatcher(IStackWatcher newWatcher) {
this.stackWatcher = newWatcher;
this.configureWatchers();
}
@Override
public void onStackChange(IItemList<?> o, IAEStack<?> fullStack, IAEStack<?> diffStack, IActionSource src,
IStorageChannel<?> chan) {
if (chan == AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class)
&& fullStack.equals(this.config.getFluidInSlot(0))) {
this.lastReportedValue = fullStack.getStackSize();
this.updateState();
}
}
@Override
public void onFluidInventoryChanged(IAEFluidTank inv, int slot) {
this.configureWatchers();
}
@MENetworkEventSubscribe
public void channelChanged(final MENetworkChannelsChanged c) {
this.updateState();
}
@MENetworkEventSubscribe
public void powerChanged(final MENetworkPowerStatusChange c) {
this.updateState();
}
@Override
public int isProvidingStrongPower() {
return this.prevState ? 15 : 0;
}
@Override
public int isProvidingWeakPower() {
return this.prevState ? 15 : 0;
}
@Override
protected int populateFlags(final int cf) {
return cf | (this.prevState ? FLAG_ON : 0);
}
@Override
public boolean isValid(final Object effectiveGrid) {
try {
return this.getProxy().getGrid() == effectiveGrid;
} catch (final GridAccessException e) {
return false;
}
}
@Override
public void postChange(final IBaseMonitor<IAEFluidStack> monitor, final Iterable<IAEFluidStack> change,
final IActionSource actionSource) {
this.updateReportingValue((IMEMonitor<IAEFluidStack>) monitor);
}
@Override
public void onListUpdate() {
try {
final IStorageChannel<IAEFluidStack> channel = AEApi.instance().storage()
.getStorageChannel(IFluidStorageChannel.class);
final IMEMonitor<IAEFluidStack> inventory = this.getProxy().getStorage().getInventory(channel);
this.updateReportingValue(inventory);
} catch (final GridAccessException e) {
// ;P
}
}
private void updateState() {
final boolean isOn = this.isLevelEmitterOn();
if (this.prevState != isOn) {
this.getHost().markForUpdate();
final BlockEntity te = this.getHost().getTile();
this.prevState = isOn;
Platform.notifyBlocksOfNeighbors(te.getWorld(), te.getPos());
Platform.notifyBlocksOfNeighbors(te.getWorld(), te.getPos().offset(this.getSide().getFacing()));
}
}
private void configureWatchers() {
final IFluidStorageChannel channel = AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class);
if (this.stackWatcher != null) {
this.stackWatcher.reset();
final IAEFluidStack myStack = this.config.getFluidInSlot(0);
try {
if (myStack != null) {
this.getProxy().getStorage().getInventory(channel).removeListener(this);
this.stackWatcher.add(myStack);
} else {
this.getProxy().getStorage().getInventory(channel).addListener(this, this.getProxy().getGrid());
}
final IMEMonitor<IAEFluidStack> inventory = this.getProxy().getStorage().getInventory(channel);
this.updateReportingValue(inventory);
} catch (GridAccessException e) {
// NOP
}
}
}
private void updateReportingValue(final IMEMonitor<IAEFluidStack> monitor) {
final IAEFluidStack myStack = this.config.getFluidInSlot(0);
if (myStack == null) {
this.lastReportedValue = 0;
for (final IAEFluidStack st : monitor.getStorageList()) {
this.lastReportedValue += st.getStackSize();
}
} else {
final IAEFluidStack r = monitor.getStorageList().findPrecise(myStack);
if (r == null) {
this.lastReportedValue = 0;
} else {
this.lastReportedValue = r.getStackSize();
}
}
this.updateState();
}
private boolean isLevelEmitterOn() {
if (Platform.isClient()) {
return (this.getClientFlags() & FLAG_ON) == FLAG_ON;
}
if (!this.getProxy().isActive()) {
return false;
}
final boolean flipState = this.getConfigManager()
.getSetting(Settings.REDSTONE_EMITTER) == RedstoneMode.LOW_SIGNAL;
return flipState ? this.reportingValue > this.lastReportedValue : this.reportingValue <= this.lastReportedValue;
}
@Override
public AECableType getCableConnectionType(final AEPartLocation dir) {
return AECableType.SMART;
}
@Override
public float getCableConnectionLength(AECableType cable) {
return 16;
}
@Override
public boolean canConnectRedstone() {
return true;
}
@Override
public void getBoxes(final IPartCollisionHelper bch) {
bch.addBox(7, 7, 11, 9, 9, 16);
}
@Override
public void randomDisplayTick(final World world, final BlockPos pos, final Random r) {
if (this.isLevelEmitterOn()) {
final AEPartLocation d = this.getSide();
final double d0 = d.xOffset * 0.45F + (r.nextFloat() - 0.5F) * 0.2D;
final double d1 = d.yOffset * 0.45F + (r.nextFloat() - 0.5F) * 0.2D;
final double d2 = d.zOffset * 0.45F + (r.nextFloat() - 0.5F) * 0.2D;
world.addParticle(DustParticleEffect.REDSTONE_DUST, 0.5 + pos.getX() + d0, 0.5 + pos.getY() + d1,
0.5 + pos.getZ() + d2, 0.0D, 0.0D, 0.0D);
}
}
@Override
public boolean onPartActivate(final PlayerEntity player, final Hand hand, final Vec3d pos) {
if (Platform.isServer()) {
ContainerOpener.openContainer(FluidLevelEmitterContainer.TYPE, player, ContainerLocator.forPart(this));
}
return true;
}
@Override
public IPartModel getStaticModels() {
if (this.isActive() && this.isPowered()) {
return this.isLevelEmitterOn() ? MODEL_ON_HAS_CHANNEL : MODEL_OFF_HAS_CHANNEL;
} else if (this.isPowered()) {
return this.isLevelEmitterOn() ? MODEL_ON_ON : MODEL_OFF_ON;
} else {
return this.isLevelEmitterOn() ? MODEL_ON_OFF : MODEL_OFF_OFF;
}
}
public IAEFluidTank getConfig() {
return this.config;
}
@Override
public void readFromNBT(final CompoundTag data) {
super.readFromNBT(data);
this.lastReportedValue = data.getLong("lastReportedValue");
this.reportingValue = data.getLong("reportingValue");
this.prevState = data.getBoolean("prevState");
this.config.readFromNBT(data, "config");
}
@Override
public void writeToNBT(final CompoundTag data) {
super.writeToNBT(data);
data.putLong("lastReportedValue", this.lastReportedValue);
data.putLong("reportingValue", this.reportingValue);
data.putBoolean("prevState", this.prevState);
this.config.writeToNBT(data, "config");
}
}
@@ -1,444 +0,0 @@
/*
* 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.parts;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import javax.annotation.Nonnull;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.Direction;
import net.minecraft.util.Hand;
import net.minecraft.util.math.Vec3d;
import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
import net.minecraftforge.fluids.capability.IFluidHandler;
import appeng.api.AEApi;
import appeng.api.config.AccessRestriction;
import appeng.api.config.FuzzyMode;
import appeng.api.config.IncludeExclude;
import appeng.api.config.Settings;
import appeng.api.config.StorageFilter;
import appeng.api.config.Upgrades;
import appeng.api.networking.IGridNode;
import appeng.api.networking.events.MENetworkCellArrayUpdate;
import appeng.api.networking.security.IActionSource;
import appeng.api.networking.storage.IBaseMonitor;
import appeng.api.networking.ticking.ITickManager;
import appeng.api.networking.ticking.TickRateModulation;
import appeng.api.networking.ticking.TickingRequest;
import appeng.api.parts.IPartHost;
import appeng.api.parts.IPartModel;
import appeng.api.storage.IMEInventory;
import appeng.api.storage.IMEInventoryHandler;
import appeng.api.storage.IMEMonitorHandlerReceiver;
import appeng.api.storage.IStorageChannel;
import appeng.api.storage.IStorageMonitorable;
import appeng.api.storage.IStorageMonitorableAccessor;
import appeng.api.storage.channels.IFluidStorageChannel;
import appeng.api.storage.data.IAEFluidStack;
import appeng.api.storage.data.IItemList;
import appeng.api.util.AEPartLocation;
import appeng.capabilities.Capabilities;
import appeng.container.ContainerLocator;
import appeng.container.ContainerOpener;
import appeng.core.AppEng;
import appeng.core.settings.TickRates;
import appeng.fluids.container.FluidStorageBusContainer;
import appeng.fluids.util.AEFluidInventory;
import appeng.fluids.util.IAEFluidInventory;
import appeng.fluids.util.IAEFluidTank;
import appeng.helpers.IInterfaceHost;
import appeng.items.parts.PartModels;
import appeng.me.GridAccessException;
import appeng.me.helpers.MachineSource;
import appeng.me.storage.ITickingMonitor;
import appeng.me.storage.MEInventoryHandler;
import appeng.parts.PartModel;
import appeng.parts.misc.SharedStorageBusPart;
import appeng.util.Platform;
import appeng.util.prioritylist.FuzzyPriorityList;
import appeng.util.prioritylist.PrecisePriorityList;
/**
* @author BrockWS
* @version rv6 - 22/05/2018
* @since rv6 22/05/2018
*/
public class FluidStorageBusPart extends SharedStorageBusPart
implements IMEMonitorHandlerReceiver<IAEFluidStack>, IAEFluidInventory {
public static final Identifier MODEL_BASE = new Identifier(AppEng.MOD_ID,
"part/fluid_storage_bus_base");
@PartModels
public static final IPartModel MODELS_OFF = new PartModel(MODEL_BASE,
new Identifier(AppEng.MOD_ID, "part/fluid_storage_bus_off"));
@PartModels
public static final IPartModel MODELS_ON = new PartModel(MODEL_BASE,
new Identifier(AppEng.MOD_ID, "part/fluid_storage_bus_on"));
@PartModels
public static final IPartModel MODELS_HAS_CHANNEL = new PartModel(MODEL_BASE,
new Identifier(AppEng.MOD_ID, "part/fluid_storage_bus_has_channel"));
private final IActionSource source;
private final AEFluidInventory config = new AEFluidInventory(this, 63);
private boolean cached = false;
private ITickingMonitor monitor = null;
private MEInventoryHandler<IAEFluidStack> handler = null;
private int handlerHash = 0;
private byte resetCacheLogic = 0;
public FluidStorageBusPart(ItemStack is) {
super(is);
this.getConfigManager().registerSetting(Settings.ACCESS, AccessRestriction.READ_WRITE);
this.getConfigManager().registerSetting(Settings.FUZZY_MODE, FuzzyMode.IGNORE_ALL);
this.getConfigManager().registerSetting(Settings.STORAGE_FILTER, StorageFilter.EXTRACTABLE_ONLY);
this.source = new MachineSource(this);
}
private IMEInventory<IAEFluidStack> getInventoryWrapper(BlockEntity target) {
Direction targetSide = this.getSide().getFacing().getOpposite();
// Prioritize a handler to directly link to another ME network
IStorageMonitorableAccessor accessor = target
.getCapability(Capabilities.STORAGE_MONITORABLE_ACCESSOR, targetSide).orElse(null);
if (accessor != null) {
IStorageMonitorable inventory = accessor.getInventory(this.source);
if (inventory != null) {
return inventory.getInventory(AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class));
}
// So this could / can be a design decision. If the tile does support our custom
// capability,
// but it does not return an inventory for the action source, we do NOT fall
// back to using
// IItemHandler's, as that might circumvent the security setings, and might also
// cause
// performance issues.
return null;
}
// Check via cap for IItemHandler
IFluidHandler handlerExt = target.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, targetSide)
.orElse(null);
if (handlerExt != null) {
return new FluidHandlerAdapter(handlerExt, this);
}
return null;
}
@Override
public TickRateModulation tickingRequest(IGridNode node, int ticksSinceLastCall) {
if (this.resetCacheLogic != 0) {
this.resetCache();
}
if (this.monitor != null) {
return this.monitor.onTick();
}
return TickRateModulation.SLEEP;
}
@Override
protected void resetCache() {
final boolean fullReset = this.resetCacheLogic == 2;
this.resetCacheLogic = 0;
final IMEInventory<IAEFluidStack> in = this.getInternalHandler();
IItemList<IAEFluidStack> before = AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class)
.createList();
if (in != null) {
before = in.getAvailableItems(before);
}
this.cached = false;
if (fullReset) {
this.handlerHash = 0;
}
final IMEInventory<IAEFluidStack> out = this.getInternalHandler();
if (in != out) {
IItemList<IAEFluidStack> after = AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class)
.createList();
if (out != null) {
after = out.getAvailableItems(after);
}
Platform.postListChanges(before, after, this, this.source);
}
}
@Override
protected void resetCache(final boolean fullReset) {
if (this.getHost() == null || this.getHost().getTile() == null || this.getHost().getTile().getWorld() == null
|| this.getHost().getTile().getWorld().isClient) {
return;
}
if (fullReset) {
this.resetCacheLogic = 2;
} else {
this.resetCacheLogic = 1;
}
try {
this.getProxy().getTick().alertDevice(this.getProxy().getNode());
} catch (final GridAccessException e) {
// :P
}
}
@Override
public boolean onPartActivate(final PlayerEntity player, final Hand hand, final Vec3d pos) {
if (Platform.isServer()) {
ContainerOpener.openContainer(FluidStorageBusContainer.TYPE, player, ContainerLocator.forPart(this));
}
return true;
}
@Override
public void onFluidInventoryChanged(IAEFluidTank inv, int slot) {
if (inv == this.config) {
this.resetCache(true);
}
}
@Override
public void readFromNBT(final CompoundTag data) {
super.readFromNBT(data);
this.config.readFromNBT(data, "config");
}
@Override
public void writeToNBT(final CompoundTag data) {
super.writeToNBT(data);
this.config.writeToNBT(data, "config");
}
@Override
public boolean isValid(final Object verificationToken) {
return this.handler == verificationToken;
}
@Override
public void postChange(final IBaseMonitor<IAEFluidStack> monitor, final Iterable<IAEFluidStack> change,
final IActionSource source) {
try {
if (this.getProxy().isActive()) {
this.getProxy().getStorage().postAlterationOfStoredItems(
AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class), change, this.source);
}
} catch (final GridAccessException e) {
// :(
}
}
public MEInventoryHandler<IAEFluidStack> getInternalHandler() {
if (this.cached) {
return this.handler;
}
final boolean wasSleeping = this.monitor == null;
this.cached = true;
final BlockEntity self = this.getHost().getTile();
final BlockEntity target = self.getWorld().getBlockEntity(self.getPos().offset(this.getSide().getFacing()));
final int newHandlerHash = this.createHandlerHash(target);
if (newHandlerHash != 0 && newHandlerHash == this.handlerHash) {
return this.handler;
}
this.handlerHash = newHandlerHash;
this.handler = null;
this.monitor = null;
if (target != null) {
IMEInventory<IAEFluidStack> inv = this.getInventoryWrapper(target);
if (inv instanceof ITickingMonitor) {
this.monitor = (ITickingMonitor) inv;
this.monitor.setActionSource(new MachineSource(this));
}
if (inv != null) {
this.checkInterfaceVsStorageBus(target, this.getSide().getOpposite());
this.handler = new MEInventoryHandler<>(inv,
AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class));
this.handler.setBaseAccess((AccessRestriction) this.getConfigManager().getSetting(Settings.ACCESS));
this.handler.setWhitelist(this.getInstalledUpgrades(Upgrades.INVERTER) > 0 ? IncludeExclude.BLACKLIST
: IncludeExclude.WHITELIST);
this.handler.setPriority(this.getPriority());
final IItemList<IAEFluidStack> priorityList = AEApi.instance().storage()
.getStorageChannel(IFluidStorageChannel.class).createList();
final int slotsToUse = 18 + this.getInstalledUpgrades(Upgrades.CAPACITY) * 9;
for (int x = 0; x < this.config.getSlots() && x < slotsToUse; x++) {
final IAEFluidStack is = this.config.getFluidInSlot(x);
if (is != null) {
priorityList.add(is);
}
}
if (this.getInstalledUpgrades(Upgrades.FUZZY) > 0) {
this.handler.setPartitionList(new FuzzyPriorityList<IAEFluidStack>(priorityList,
(FuzzyMode) this.getConfigManager().getSetting(Settings.FUZZY_MODE)));
} else {
this.handler.setPartitionList(new PrecisePriorityList<IAEFluidStack>(priorityList));
}
if (inv instanceof IBaseMonitor) {
((IBaseMonitor<IAEFluidStack>) inv).addListener(this, this.handler);
}
}
}
// update sleep state...
if (wasSleeping != (this.monitor == null)) {
try {
final ITickManager tm = this.getProxy().getTick();
if (this.monitor == null) {
tm.sleepDevice(this.getProxy().getNode());
} else {
tm.wakeDevice(this.getProxy().getNode());
}
} catch (final GridAccessException ignore) {
// :(
}
}
try {
// force grid to update handlers...
this.getProxy().getGrid().postEvent(new MENetworkCellArrayUpdate());
} catch (final GridAccessException ignore) {
// :3
}
return this.handler;
}
private void checkInterfaceVsStorageBus(final BlockEntity target, final AEPartLocation side) {
IInterfaceHost achievement = null;
if (target instanceof IInterfaceHost) {
achievement = (IInterfaceHost) target;
}
if (target instanceof IPartHost) {
final Object part = ((IPartHost) target).getPart(side);
if (part instanceof IInterfaceHost) {
achievement = (IInterfaceHost) part;
}
}
if (achievement != null && achievement.getActionableNode() != null) {
// Platform.increaseStat( achievement.getActionableNode().getPlayerID(),
// Achievements.Recursive.getAchievement()
// );
// Platform.increaseStat( getActionableNode().getPlayerID(),
// Achievements.Recursive.getAchievement() );
}
}
@Override
public List<IMEInventoryHandler> getCellArray(final IStorageChannel channel) {
if (channel == this.getStorageChannel()) {
final IMEInventoryHandler<IAEFluidStack> out = this.getProxy().isActive() ? this.getInternalHandler()
: null;
if (out != null) {
return Collections.singletonList(out);
}
}
return super.getCellArray(channel);
}
private int createHandlerHash(BlockEntity target) {
if (target == null) {
return 0;
}
final Direction targetSide = this.getSide().getFacing().getOpposite();
LazyOptional<IStorageMonitorableAccessor> accessorOpt = target
.getCapability(Capabilities.STORAGE_MONITORABLE_ACCESSOR, targetSide);
if (accessorOpt.isPresent()) {
return Objects.hash(target, accessorOpt.orElse(null));
}
final IFluidHandler fluidHandler = target
.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, targetSide).orElse(null);
if (fluidHandler != null) {
return Objects.hash(target, fluidHandler, fluidHandler.getTanks());
}
return 0;
}
@Override
public TickingRequest getTickingRequest(IGridNode node) {
return new TickingRequest(TickRates.FluidStorageBus.getMin(), TickRates.FluidStorageBus.getMax(),
this.isSleeping(), true);
}
@Override
public void onListUpdate() {
// not used here.
}
@Override
public IStorageChannel getStorageChannel() {
return AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class);
}
public IAEFluidTank getConfig() {
return this.config;
}
@Nonnull
@Override
public IPartModel getStaticModels() {
if (this.isActive() && this.isPowered()) {
return MODELS_HAS_CHANNEL;
} else if (this.isPowered()) {
return MODELS_ON;
} else {
return MODELS_OFF;
}
}
@Override
public ItemStack getItemStackRepresentation() {
return AEApi.instance().definitions().parts().fluidStorageBus().maybeStack(1).orElse(ItemStack.EMPTY);
}
@Override
public ScreenHandlerType<?> getContainerType() {
return FluidStorageBusContainer.TYPE;
}
}
@@ -1,62 +0,0 @@
/*
* 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.parts;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Identifier;
import appeng.api.parts.IPartModel;
import appeng.core.AppEng;
import appeng.fluids.container.FluidTerminalContainer;
import appeng.items.parts.PartModels;
import appeng.parts.PartModel;
import appeng.parts.reporting.AbstractTerminalPart;
/**
* @author BrockWS
* @version rv6 - 12/05/2018
* @since rv6 12/05/2018
*/
public class FluidTerminalPart extends AbstractTerminalPart {
@PartModels
public static final Identifier MODEL_OFF = new Identifier(AppEng.MOD_ID, "part/fluid_terminal_off");
@PartModels
public static final Identifier MODEL_ON = new Identifier(AppEng.MOD_ID, "part/fluid_terminal_on");
public static final IPartModel MODELS_OFF = new PartModel(MODEL_BASE, MODEL_OFF, MODEL_STATUS_OFF);
public static final IPartModel MODELS_ON = new PartModel(MODEL_BASE, MODEL_ON, MODEL_STATUS_ON);
public static final IPartModel MODELS_HAS_CHANNEL = new PartModel(MODEL_BASE, MODEL_ON, MODEL_STATUS_HAS_CHANNEL);
public FluidTerminalPart(ItemStack is) {
super(is);
}
@Override
public ScreenHandlerType<?> getContainerType(PlayerEntity player) {
return FluidTerminalContainer.TYPE;
}
@Override
public IPartModel getStaticModels() {
return this.selectModel(MODELS_OFF, MODELS_ON, MODELS_HAS_CHANNEL);
}
}
@@ -1,168 +0,0 @@
/*
* 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.parts;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.util.Hand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
import appeng.api.AEApi;
import appeng.api.config.RedstoneMode;
import appeng.api.config.Upgrades;
import appeng.api.networking.ticking.IGridTickable;
import appeng.api.networking.ticking.TickRateModulation;
import appeng.api.parts.IPartCollisionHelper;
import appeng.api.storage.channels.IFluidStorageChannel;
import appeng.api.util.AECableType;
import appeng.container.ContainerLocator;
import appeng.container.ContainerOpener;
import appeng.fluids.container.FluidIOContainer;
import appeng.fluids.util.AEFluidInventory;
import appeng.fluids.util.IAEFluidTank;
import appeng.me.GridAccessException;
import appeng.parts.automation.UpgradeablePart;
import appeng.util.Platform;
/**
* @author BrockWS
* @version rv6 - 30/04/2018
* @since rv6 30/04/2018
*/
public abstract class SharedFluidBusPart extends UpgradeablePart implements IGridTickable {
private final AEFluidInventory config = new AEFluidInventory(null, 9);
private boolean lastRedstone;
public SharedFluidBusPart(ItemStack is) {
super(is);
}
@Override
public void upgradesChanged() {
this.updateState();
}
@Override
public void onneighborUpdate(BlockView w, BlockPos pos, BlockPos neighbor) {
this.updateState();
if (this.lastRedstone != this.getHost().hasRedstone(this.getSide())) {
this.lastRedstone = !this.lastRedstone;
if (this.lastRedstone && this.getRSMode() == RedstoneMode.SIGNAL_PULSE) {
this.doBusWork();
}
}
}
private void updateState() {
try {
if (!this.isSleeping()) {
this.getProxy().getTick().wakeDevice(this.getProxy().getNode());
} else {
this.getProxy().getTick().sleepDevice(this.getProxy().getNode());
}
} catch (final GridAccessException e) {
// :P
}
}
@Override
public boolean onPartActivate(final PlayerEntity player, final Hand hand, final Vec3d pos) {
if (Platform.isServer()) {
ContainerOpener.openContainer(FluidIOContainer.TYPE, player, ContainerLocator.forPart(this));
}
return true;
}
@Override
public void getBoxes(IPartCollisionHelper bch) {
bch.addBox(6, 6, 11, 10, 10, 13);
bch.addBox(5, 5, 13, 11, 11, 14);
bch.addBox(4, 4, 14, 12, 12, 16);
}
protected BlockEntity getConnectedTE() {
BlockEntity self = this.getHost().getTile();
return this.getBlockEntity(self, self.getPos().offset(this.getSide().getFacing()));
}
private BlockEntity getBlockEntity(final BlockEntity self, final BlockPos pos) {
final World w = self.getWorld();
if (w.getChunkManager().isChunkLoaded(new ChunkPos(pos))) {
return w.getBlockEntity(pos);
}
return null;
}
protected int calculateAmountToSend() {
double amount = this.getChannel().transferFactor();
switch (this.getInstalledUpgrades(Upgrades.SPEED)) {
case 4:
amount = amount * 1.5;
case 3:
amount = amount * 2;
case 2:
amount = amount * 4;
case 1:
amount = amount * 8;
case 0:
default:
return MathHelper.floor(amount);
}
}
@Override
public void readFromNBT(CompoundTag extra) {
super.readFromNBT(extra);
this.config.readFromNBT(extra, "config");
}
@Override
public void writeToNBT(CompoundTag extra) {
super.writeToNBT(extra);
this.config.writeToNBT(extra, "config");
}
public IAEFluidTank getConfig() {
return this.config;
}
protected IFluidStorageChannel getChannel() {
return AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class);
}
@Override
public float getCableConnectionLength(AECableType cable) {
return 5;
}
protected abstract TickRateModulation doBusWork();
protected abstract boolean canDoBusWork();
}
@@ -1,50 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2015, 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.registries;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import appeng.api.AEApi;
import appeng.api.implementations.tiles.IChestOrDrive;
import appeng.api.storage.IMEInventoryHandler;
import appeng.api.storage.IStorageChannel;
import appeng.api.storage.cells.ICellGuiHandler;
import appeng.api.storage.cells.ICellHandler;
import appeng.api.storage.channels.IFluidStorageChannel;
import appeng.api.storage.data.IAEStack;
import appeng.container.ContainerLocator;
import appeng.container.ContainerOpener;
import appeng.fluids.container.FluidTerminalContainer;
public class BasicFluidCellGuiHandler implements ICellGuiHandler {
@Override
public <T extends IAEStack<T>> boolean isHandlerFor(final IStorageChannel<T> channel) {
return channel == AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class);
}
@Override
public void openChestGui(final PlayerEntity player, final IChestOrDrive chest, final ICellHandler cellHandler,
final IMEInventoryHandler inv, final ItemStack is, final IStorageChannel chan) {
ContainerOpener.openContainer(FluidTerminalContainer.TYPE, player,
ContainerLocator.forTileEntitySide((BlockEntity) chest, chest.getUp()));
}
}
@@ -1,169 +0,0 @@
/*
* 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.tile;
import java.util.EnumSet;
import javax.annotation.Nullable;
import alexiil.mc.lib.attributes.item.FixedItemInv;
import net.minecraft.block.BlockState;
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.util.math.Direction;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.util.LazyOptional;
import appeng.api.AEApi;
import appeng.api.config.Upgrades;
import appeng.api.networking.IGridNode;
import appeng.api.networking.events.MENetworkChannelsChanged;
import appeng.api.networking.events.MENetworkEventSubscribe;
import appeng.api.networking.events.MENetworkPowerStatusChange;
import appeng.api.networking.ticking.IGridTickable;
import appeng.api.networking.ticking.TickRateModulation;
import appeng.api.networking.ticking.TickingRequest;
import appeng.api.util.AECableType;
import appeng.api.util.AEPartLocation;
import appeng.api.util.DimensionalCoord;
import appeng.api.util.IConfigManager;
import appeng.fluids.container.FluidInterfaceContainer;
import appeng.fluids.helper.DualityFluidInterface;
import appeng.fluids.helper.IFluidInterfaceHost;
import appeng.helpers.IPriorityHost;
import appeng.tile.grid.AENetworkBlockEntity;
public class FluidInterfaceBlockEntity extends AENetworkBlockEntity
implements IGridTickable, IFluidInterfaceHost, IPriorityHost {
private final DualityFluidInterface duality = new DualityFluidInterface(this.getProxy(), this);
public FluidInterfaceBlockEntity(BlockEntityType<?> tileEntityTypeIn) {
super(tileEntityTypeIn);
}
@MENetworkEventSubscribe
public void stateChange(final MENetworkChannelsChanged c) {
this.duality.notifyNeighbors();
}
@MENetworkEventSubscribe
public void stateChange(final MENetworkPowerStatusChange c) {
this.duality.notifyNeighbors();
}
@Override
public TickingRequest getTickingRequest(IGridNode node) {
return this.duality.getTickingRequest(node);
}
@Override
public TickRateModulation tickingRequest(IGridNode node, int ticksSinceLastCall) {
return this.duality.tickingRequest(node, ticksSinceLastCall);
}
@Override
public DualityFluidInterface getDualityFluidInterface() {
return this.duality;
}
@Override
public BlockEntity getBlockEntity() {
return this;
}
@Override
public void gridChanged() {
this.duality.gridChanged();
}
@Override
public CompoundTag toTag(final CompoundTag data) {
super.toTag(data);
this.duality.writeToNBT(data);
return data;
}
@Override
public void fromTag(BlockState state, final CompoundTag data) {
super.fromTag(state, data);
this.duality.readFromNBT(data);
}
@Override
public AECableType getCableConnectionType(final AEPartLocation dir) {
return this.duality.getCableConnectionType(dir);
}
@Override
public DimensionalCoord getLocation() {
return this.duality.getLocation();
}
@Override
public EnumSet<Direction> getTargets() {
return EnumSet.allOf(Direction.class);
}
@Override
public int getPriority() {
return this.duality.getPriority();
}
@Override
public void setPriority(final int newValue) {
this.duality.setPriority(newValue);
}
@Override
public <T> LazyOptional<T> getCapability(Capability<T> capability, @Nullable Direction facing) {
LazyOptional<T> result = this.duality.getCapability(capability, facing);
if (result.isPresent()) {
return result;
}
return super.getCapability(capability, facing);
}
@Override
public int getInstalledUpgrades(Upgrades u) {
return this.duality.getInstalledUpgrades(u);
}
@Override
public IConfigManager getConfigManager() {
return this.duality.getConfigManager();
}
@Override
public FixedItemInv getInventoryByName(String name) {
return this.duality.getInventoryByName(name);
}
@Override
public ItemStack getItemStackRepresentation() {
return AEApi.instance().definitions().blocks().fluidIface().maybeStack(1).orElse(ItemStack.EMPTY);
}
@Override
public ScreenHandlerType<?> getContainerType() {
return FluidInterfaceContainer.TYPE;
}
}
@@ -1,311 +0,0 @@
package appeng.fluids.util;
import java.util.Objects;
import javax.annotation.Nonnull;
import alexiil.mc.lib.attributes.fluid.volume.FluidVolume;
import net.minecraft.nbt.CompoundTag;
import appeng.api.storage.data.IAEFluidStack;
import appeng.core.AELog;
import appeng.util.Platform;
public class AEFluidInventory implements IAEFluidTank {
private final IAEFluidStack[] fluids;
private final IAEFluidInventory handler;
private final int capacity;
public AEFluidInventory(final IAEFluidInventory handler, final int slots, final int capacity) {
this.fluids = new IAEFluidStack[slots];
this.handler = handler;
this.capacity = capacity;
}
public AEFluidInventory(final IAEFluidInventory handler, final int slots) {
this(handler, slots, Integer.MAX_VALUE);
}
@Override
public void setFluidInSlot(final int slot, final IAEFluidStack fluid) {
if (slot >= 0 && slot < this.getSlots()) {
if (Objects.equals(this.fluids[slot], fluid)) {
if (fluid != null && fluid.getStackSize() != this.fluids[slot].getStackSize()) {
this.fluids[slot].setStackSize(Math.min(fluid.getStackSize(), this.capacity));
this.onContentChanged(slot);
}
} else {
if (fluid == null) {
this.fluids[slot] = null;
} else {
this.fluids[slot] = fluid.copy();
this.fluids[slot].setStackSize(Math.min(fluid.getStackSize(), this.capacity));
}
this.onContentChanged(slot);
}
}
}
private void onContentChanged(final int slot) {
if (this.handler != null && Platform.isServer()) {
this.handler.onFluidInventoryChanged(this, slot);
}
}
@Override
public IAEFluidStack getFluidInSlot(final int slot) {
if (slot >= 0 && slot < this.getSlots()) {
return this.fluids[slot];
}
return null;
}
@Override
public int getSlots() {
return this.fluids.length;
}
@Override
public int getTanks() {
return this.fluids.length;
}
@Nonnull
@Override
public FluidVolume getFluidInTank(int tank) {
if (tank < 0 || tank >= fluids.length) {
return FluidVolumeUtil.EMPTY;
}
return fluids[tank] == null ? FluidVolumeUtil.EMPTY : fluids[tank].getFluidStack();
}
@Override
public int getTankCapacity(int tank) {
return Math.min(this.capacity, Integer.MAX_VALUE);
}
@Override
public boolean isFluidValid(int tank, @Nonnull FluidVolume stack) {
return stack != FluidVolumeUtil.EMPTY;
}
public int fill(final int slot, final FluidVolume resource, final boolean doFill) {
if (resource.isEmpty() || resource.getAmount() <= 0) {
return 0;
}
final IAEFluidStack fluid = this.fluids[slot];
if (fluid != null && !fluid.getFluidStack().equals(resource)) {
return 0;
}
int amountToStore = this.capacity;
if (fluid != null) {
amountToStore -= fluid.getStackSize();
}
amountToStore = Math.min(amountToStore, resource.getAmount());
if (doFill) {
if (fluid == null) {
this.setFluidInSlot(slot, AEFluidStack.fromFluidStack(resource));
} else {
fluid.setStackSize(fluid.getStackSize() + amountToStore);
this.onContentChanged(slot);
}
}
return amountToStore;
}
@Override
public int fill(FluidVolume resource, FluidAction action) {
if (resource.isEmpty() || resource.getAmount() <= 0) {
return 0;
}
// Find a suitable slot
int slot = indexOfFluid(resource);
if (slot == -1) {
slot = indexOfEmptySlot();
if (slot == -1) {
return 0;
}
}
final IAEFluidStack fluid = this.fluids[slot];
int amountToStore = this.capacity;
if (fluid != null) {
amountToStore -= fluid.getStackSize();
}
amountToStore = Math.min(amountToStore, resource.getAmount());
if (action == FluidAction.EXECUTE) {
if (fluid == null) {
this.setFluidInSlot(slot, AEFluidStack.fromFluidStack(resource));
} else {
fluid.setStackSize(fluid.getStackSize() + amountToStore);
this.onContentChanged(slot);
}
}
return amountToStore;
}
@Override
public FluidVolume drain(final FluidVolume fluid, final FluidAction action) {
if (fluid.isEmpty() || fluid.getAmount() <= 0) {
return FluidVolumeUtil.EMPTY;
}
final FluidVolume resource = fluid.copy();
FluidVolume totalDrained = FluidVolumeUtil.EMPTY;
for (int slot = 0; slot < this.getSlots(); ++slot) {
FluidVolume drain = this.drain(slot, resource, action == FluidAction.EXECUTE);
if (drain != null) {
if (totalDrained.isEmpty()) {
totalDrained = drain;
} else {
totalDrained.setAmount(totalDrained.getAmount() + drain.getAmount());
}
resource.setAmount(resource.getAmount() - drain.getAmount());
if (resource.getAmount() <= 0) {
break;
}
}
}
return totalDrained;
}
@Override
public FluidVolume drain(final int maxDrain, final FluidAction action) {
if (maxDrain == 0) {
return FluidVolumeUtil.EMPTY;
}
FluidVolume totalDrained = FluidVolumeUtil.EMPTY;
int toDrain = maxDrain;
for (int slot = 0; slot < this.getSlots(); ++slot) {
if (totalDrained.isEmpty()) {
totalDrained = this.drain(slot, toDrain, action == FluidAction.EXECUTE);
if (totalDrained.isEmpty()) {
toDrain -= totalDrained.getAmount();
}
} else {
FluidVolume copy = totalDrained.copy();
copy.setAmount(toDrain);
FluidVolume drain = this.drain(slot, copy, action == FluidAction.EXECUTE);
if (drain != null) {
totalDrained.setAmount(totalDrained.getAmount() + drain.getAmount());
toDrain -= drain.getAmount();
}
}
if (toDrain <= 0) {
break;
}
}
return totalDrained;
}
private int indexOfFluid(FluidVolume resource) {
for (int slot = 0; slot < fluids.length; slot++) {
if (fluids[slot] != null && fluids[slot].getFluidStack().isFluidEqual(resource)) {
return slot;
}
}
return -1;
}
private int indexOfEmptySlot() {
for (int slot = 0; slot < fluids.length; slot++) {
if (fluids[slot] == null) {
return slot;
}
}
return -1;
}
public FluidVolume drain(final int slot, final FluidVolume resource, final boolean doDrain) {
final IAEFluidStack fluid = this.fluids[slot];
if (resource.isEmpty() || fluid == null || !fluid.getFluidStack().equals(resource)) {
return null;
}
return this.drain(slot, resource.getAmount(), doDrain);
}
public FluidVolume drain(final int slot, final int maxDrain, boolean doDrain) {
final IAEFluidStack fluid = this.fluids[slot];
if (fluid == null || maxDrain <= 0) {
return null;
}
int drained = maxDrain;
if (fluid.getStackSize() < drained) {
drained = (int) fluid.getStackSize();
}
FluidVolume stack = new FluidVolume(fluid.getFluid(), drained);
if (doDrain) {
fluid.setStackSize(fluid.getStackSize() - drained);
if (fluid.getStackSize() <= 0) {
this.fluids[slot] = null;
}
this.onContentChanged(slot);
}
return stack;
}
public void writeToNBT(final CompoundTag data, final String name) {
final CompoundTag c = new CompoundTag();
this.writeToNBT(c);
data.put(name, c);
}
private void writeToNBT(final CompoundTag target) {
for (int x = 0; x < this.fluids.length; x++) {
try {
final CompoundTag c = new CompoundTag();
if (this.fluids[x] != null) {
this.fluids[x].writeToNBT(c);
}
target.put("#" + x, c);
} catch (final Exception ignored) {
}
}
}
public void readFromNBT(final CompoundTag data, final String name) {
final CompoundTag c = data.getCompound(name);
if (!c.isEmpty()) {
this.readFromNBT(c);
}
}
private void readFromNBT(final CompoundTag target) {
for (int x = 0; x < this.fluids.length; x++) {
try {
final CompoundTag c = target.getCompound("#" + x);
if (!c.isEmpty()) {
this.fluids[x] = AEFluidStack.fromNBT(c);
}
} catch (final Exception e) {
AELog.debug(e);
}
}
}
}
@@ -0,0 +1,259 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, 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.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;
import alexiil.mc.lib.attributes.fluid.volume.FluidKeys;
import alexiil.mc.lib.attributes.fluid.volume.FluidVolume;
import com.google.common.base.Preconditions;
import net.fabricmc.fabric.api.util.NbtType;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.PacketByteBuf;
import appeng.api.AEApi;
import appeng.api.config.FuzzyMode;
import appeng.api.storage.IStorageChannel;
import appeng.api.storage.channels.IFluidStorageChannel;
import appeng.api.storage.data.IAEFluidStack;
import appeng.fluids.items.FluidDummyItem;
import appeng.util.Platform;
import appeng.util.item.AEStack;
public final class AEFluidStack extends AEStack<IAEFluidStack> implements IAEFluidStack, Comparable<AEFluidStack> {
private static final String NBT_STACKSIZE = "cnt";
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;
this.setStackSize(fluidStack.getStackSize());
// 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) {
this.fluid = Preconditions.checkNotNull(fluid);
this.setStackSize(amount);
this.setCraftable(false);
this.setCountRequestable(0);
this.tagCompound = tag;
}
public static AEFluidStack fromFluidStack(final FluidVolume input) {
if (input.isEmpty()) {
return null;
}
FluidKey fluid = input.getFluidKey();
if (fluid == null) {
throw new IllegalArgumentException("Fluid is null.");
}
CompoundTag tag = input.toTag();
if (tag.isEmpty()) {
tag = null;
}
// FIXME FABRIC NOPE NO FRACTIONS YOU FREAKS THIS IS NOT FROG FRACTIONS
long amount = (long)(input.amount().asInexactDouble() * 1000.0);
return new AEFluidStack(fluid, amount, tag);
}
public static IAEFluidStack fromNBT(final CompoundTag data) {
CompoundTag fluidId = data.getCompound(NBT_FLUID_ID);
FluidKey fluid = FluidKey.fromTag(fluidId);
if (fluid == FluidKeys.EMPTY) {
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);
fluidStack.setCountRequestable(data.getLong(NBT_REQUESTABLE));
fluidStack.setCraftable(data.getBoolean(NBT_CRAFTABLE));
return fluidStack;
}
@Override
public void add(final IAEFluidStack option) {
if (option == null) {
return;
}
this.incStackSize(option.getStackSize());
this.setCountRequestable(this.getCountRequestable() + option.getCountRequestable());
this.setCraftable(this.isCraftable() || option.isCraftable());
}
@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());
}
@Override
public boolean fuzzyComparison(final IAEFluidStack other, final FuzzyMode mode) {
return this.fluid == other.getFluid();
}
@Override
public IAEFluidStack copy() {
return new AEFluidStack(this);
}
@Override
public IAEFluidStack empty() {
final IAEFluidStack dup = this.copy();
dup.reset();
return dup;
}
@Override
public boolean isItem() {
return false;
}
@Override
public boolean isFluid() {
return true;
}
@Override
public IStorageChannel<IAEFluidStack> getChannel() {
return AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class);
}
@Override
public int compareTo(final AEFluidStack other) {
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();
}
@Override
public int hashCode() {
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;
}
@Override
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);
} else if (other instanceof FluidVolume) {
final FluidVolume is = (FluidVolume) other;
return is.getFluidKey() == this.fluid
&& Platform.itemComparisons().isNbtTagEqual(this.tagCompound, is.toTag());
}
return false;
}
@Override
public String toString() {
return this.getStackSize() + "x" + this.getFluidStack().getFluidKey().entry.getId() + " " + this.tagCompound;
}
@Override
public boolean hasTagCompound() {
return this.tagCompound != null;
}
@Override
public FluidVolume getFluidStack() {
FluidAmount amount = FluidAmount.of(this.getStackSize(), 1000);
return this.fluid.readVolume(tagCompound).withAmount(amount);
}
@Override
public FluidKey getFluid() {
return this.fluid;
}
@Override
public ItemStack asItemStackRepresentation() {
ItemStack is = AEApi.instance().definitions().items().dummyFluidItem().maybeStack(1).orElse(ItemStack.EMPTY);
if (!is.isEmpty()) {
FluidDummyItem item = (FluidDummyItem) is.getItem();
item.setFluidStack(is, this.getFluidStack());
return is;
}
return ItemStack.EMPTY;
}
public static IAEFluidStack fromPacket(final PacketByteBuf buffer) {
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);
fluidStack.setCountRequestable(countRequestable);
fluidStack.setCraftable(isCraftable);
return fluidStack;
}
@Override
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());
}
}
@@ -1,63 +0,0 @@
/*
* 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.util;
import net.minecraftforge.fluids.capability.templates.FluidTank;
import appeng.api.storage.data.IAEFluidStack;
import appeng.util.Platform;
public class AEFluidTank extends FluidTank implements IAEFluidTank {
private final IAEFluidInventory host;
public AEFluidTank(IAEFluidInventory host, int capacity) {
super(capacity);
this.host = host;
}
@Override
protected void onContentsChanged() {
if (this.host != null && Platform.isServer()) {
this.host.onFluidInventoryChanged(this, 0);
}
super.onContentsChanged();
}
@Override
public void setFluidInSlot(int slot, IAEFluidStack fluid) {
if (slot == 0) {
this.setFluid(fluid == null ? null : fluid.getFluidStack());
this.onContentsChanged();
}
}
@Override
public IAEFluidStack getFluidInSlot(int slot) {
if (slot == 0) {
return AEFluidStack.fromFluidStack(this.getFluid());
}
return null;
}
@Override
public int getSlots() {
return 1;
}
}
@@ -0,0 +1,174 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2015, 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.util;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import appeng.api.config.FuzzyMode;
import appeng.api.storage.data.IAEFluidStack;
import appeng.api.storage.data.IItemList;
public final class FluidList implements IItemList<IAEFluidStack> {
private final Map<IAEFluidStack, IAEFluidStack> records = new HashMap<>();
@Override
public void add(final IAEFluidStack option) {
if (option == null) {
return;
}
final IAEFluidStack st = this.getFluidRecord(option);
if (st != null) {
st.add(option);
return;
}
final IAEFluidStack opt = option.copy();
this.putFluidRecord(opt);
}
@Override
public IAEFluidStack findPrecise(final IAEFluidStack fluidStack) {
if (fluidStack == null) {
return null;
}
return this.getFluidRecord(fluidStack);
}
@Override
public Collection<IAEFluidStack> findFuzzy(final IAEFluidStack filter, final FuzzyMode fuzzy) {
if (filter == null) {
return Collections.emptyList();
}
return Collections.singletonList(this.findPrecise(filter));
}
@Override
public boolean isEmpty() {
return !this.iterator().hasNext();
}
@Override
public void addStorage(final IAEFluidStack option) {
if (option == null) {
return;
}
final IAEFluidStack st = this.getFluidRecord(option);
if (st != null) {
st.incStackSize(option.getStackSize());
return;
}
final IAEFluidStack opt = option.copy();
this.putFluidRecord(opt);
}
/*
* public synchronized void clean() { Iterator<StackType> i = iterator(); while
* (i.hasNext()) { StackType AEI = i.next(); if ( !AEI.isMeaningful() )
* i.remove(); } }
*/
@Override
public void addCrafting(final IAEFluidStack option) {
if (option == null) {
return;
}
final IAEFluidStack st = this.getFluidRecord(option);
if (st != null) {
st.setCraftable(true);
return;
}
final IAEFluidStack opt = option.copy();
opt.setStackSize(0);
opt.setCraftable(true);
this.putFluidRecord(opt);
}
@Override
public void addRequestable(final IAEFluidStack option) {
if (option == null) {
return;
}
final IAEFluidStack st = this.getFluidRecord(option);
if (st != null) {
st.setCountRequestable(st.getCountRequestable() + option.getCountRequestable());
return;
}
final IAEFluidStack opt = option.copy();
opt.setStackSize(0);
opt.setCraftable(false);
opt.setCountRequestable(option.getCountRequestable());
this.putFluidRecord(opt);
}
@Override
public IAEFluidStack getFirstItem() {
for (final IAEFluidStack stackType : this) {
return stackType;
}
return null;
}
@Override
public int size() {
return this.records.values().size();
}
@Override
public Iterator<IAEFluidStack> iterator() {
return new MeaningfulFluidIterator<>(this.records.values().iterator());
}
@Override
public void resetStatus() {
for (final IAEFluidStack i : this) {
i.reset();
}
}
private IAEFluidStack getFluidRecord(final IAEFluidStack fluid) {
return this.records.get(fluid);
}
private IAEFluidStack putFluidRecord(final IAEFluidStack fluid) {
return this.records.put(fluid, fluid);
}
}
@@ -1,85 +0,0 @@
/*
* 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.util;
import java.util.Comparator;
import appeng.api.config.SortDir;
import appeng.api.storage.data.IAEFluidStack;
import appeng.util.Platform;
/**
* @author BrockWS
* @version rv6 - 22/05/2018
* @since rv6 22/05/2018
*/
public class FluidSorters {
private static SortDir Direction = SortDir.ASCENDING;
public static final Comparator<IAEFluidStack> CONFIG_BASED_SORT_BY_NAME = (o1, o2) -> {
// FIXME: Calling .getString() to compare two untranslated strings is a problem,
// we need to investigate how to do this better
if (getDirection() == SortDir.ASCENDING) {
return Platform.getFluidDisplayName(o1).getString()
.compareToIgnoreCase(Platform.getFluidDisplayName(o2).getString());
}
return Platform.getFluidDisplayName(o2).getString()
.compareToIgnoreCase(Platform.getFluidDisplayName(o1).getString());
};
public static final Comparator<IAEFluidStack> CONFIG_BASED_SORT_BY_MOD = new Comparator<IAEFluidStack>() {
@Override
public int compare(final IAEFluidStack o1, final IAEFluidStack o2) {
final AEFluidStack op1 = (AEFluidStack) o1;
final AEFluidStack op2 = (AEFluidStack) o2;
if (getDirection() == SortDir.ASCENDING) {
return this.secondarySort(Platform.getModId(op1).compareToIgnoreCase(Platform.getModId(op2)), o2, o1);
}
return this.secondarySort(Platform.getModId(op2).compareToIgnoreCase(Platform.getModId(op1)), o1, o2);
}
private int secondarySort(final int compareToIgnoreCase, final IAEFluidStack o1, final IAEFluidStack o2) {
if (compareToIgnoreCase == 0) {
// FIXME: Calling .getString() to compare two untranslated strings is a problem,
// we need to investigate how to do this better
return Platform.getFluidDisplayName(o2).getString()
.compareToIgnoreCase(Platform.getFluidDisplayName(o1).getString());
}
return compareToIgnoreCase;
}
};
public static final Comparator<IAEFluidStack> CONFIG_BASED_SORT_BY_SIZE = (o1, o2) -> {
if (getDirection() == SortDir.ASCENDING) {
return Long.compare(o2.getStackSize(), o1.getStackSize());
}
return Long.compare(o1.getStackSize(), o2.getStackSize());
};
private static SortDir getDirection() {
return Direction;
}
public static void setDirection(final SortDir direction) {
Direction = direction;
}
}
@@ -1,24 +0,0 @@
/*
* 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.util;
@FunctionalInterface
public interface IAEFluidInventory {
void onFluidInventoryChanged(final IAEFluidTank inv, final int slot);
}
@@ -1,15 +0,0 @@
package appeng.fluids.util;
import net.minecraftforge.fluids.capability.IFluidHandler;
import appeng.api.storage.data.IAEFluidStack;
public interface IAEFluidTank extends IFluidHandler {
void setFluidInSlot(final int slot, final IAEFluidStack fluid);
IAEFluidStack getFluidInSlot(final int slot);
int getSlots();
}
@@ -0,0 +1,63 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2015, 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.util;
import java.util.Iterator;
import java.util.NoSuchElementException;
import appeng.api.storage.data.IAEStack;
public class MeaningfulFluidIterator<T extends IAEStack> implements Iterator<T> {
private final Iterator<T> parent;
private T next;
public MeaningfulFluidIterator(final Iterator<T> iterator) {
this.parent = iterator;
}
@Override
public boolean hasNext() {
while (this.parent.hasNext()) {
this.next = this.parent.next();
if (this.next.isMeaningful()) {
return true;
} else {
this.parent.remove(); // self cleaning :3
}
}
this.next = null;
return false;
}
@Override
public T next() {
if (this.next == null) {
throw new NoSuchElementException();
}
return this.next;
}
@Override
public void remove() {
this.parent.remove();
}
}