pick 97420a31d The big reformat of 2020
This commit is contained in:
@@ -18,12 +18,8 @@
|
||||
|
||||
package appeng.fluids.block;
|
||||
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import appeng.container.ContainerLocator;
|
||||
import appeng.container.ContainerOpener;
|
||||
import appeng.fluids.container.ContainerFluidInterface;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -35,35 +31,32 @@ import net.minecraft.util.math.BlockRayTraceResult;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import appeng.block.AEBaseTileBlock;
|
||||
|
||||
import appeng.container.ContainerLocator;
|
||||
import appeng.container.ContainerOpener;
|
||||
import appeng.fluids.container.ContainerFluidInterface;
|
||||
import appeng.fluids.tile.TileFluidInterface;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public class BlockFluidInterface extends AEBaseTileBlock<TileFluidInterface> {
|
||||
public BlockFluidInterface() {
|
||||
super(defaultProps(Material.IRON));
|
||||
}
|
||||
|
||||
public class BlockFluidInterface extends AEBaseTileBlock<TileFluidInterface>
|
||||
{
|
||||
public BlockFluidInterface()
|
||||
{
|
||||
super(defaultProps( Material.IRON ));
|
||||
}
|
||||
@Override
|
||||
public ActionResultType onActivated(final World w, final BlockPos pos, final PlayerEntity p, final Hand hand,
|
||||
final @Nullable ItemStack heldItem, final BlockRayTraceResult hit) {
|
||||
if (p.isCrouching()) {
|
||||
return ActionResultType.PASS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResultType onActivated(final World w, final BlockPos pos, final PlayerEntity p, final Hand hand, final @Nullable ItemStack heldItem, final BlockRayTraceResult hit)
|
||||
{
|
||||
if( p.isCrouching() )
|
||||
{
|
||||
return ActionResultType.PASS;
|
||||
}
|
||||
|
||||
final TileEntity tg = this.getTileEntity( w, pos );
|
||||
if( tg != null )
|
||||
{
|
||||
if( Platform.isServer() )
|
||||
{
|
||||
ContainerOpener.openContainer(ContainerFluidInterface.TYPE, p, ContainerLocator.forTileEntitySide(tg, hit.getFace()));
|
||||
}
|
||||
return ActionResultType.SUCCESS;
|
||||
}
|
||||
return ActionResultType.PASS;
|
||||
}
|
||||
final TileEntity tg = this.getTileEntity(w, pos);
|
||||
if (tg != null) {
|
||||
if (Platform.isServer()) {
|
||||
ContainerOpener.openContainer(ContainerFluidInterface.TYPE, p,
|
||||
ContainerLocator.forTileEntitySide(tg, hit.getFace()));
|
||||
}
|
||||
return ActionResultType.SUCCESS;
|
||||
}
|
||||
return ActionResultType.PASS;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
|
||||
package appeng.fluids.client.gui;
|
||||
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
|
||||
import appeng.client.gui.implementations.GuiUpgradeable;
|
||||
import appeng.client.gui.widgets.GuiTabButton;
|
||||
@@ -12,64 +14,52 @@ import appeng.fluids.client.gui.widgets.GuiFluidSlot;
|
||||
import appeng.fluids.client.gui.widgets.GuiOptionalFluidSlot;
|
||||
import appeng.fluids.container.ContainerFluidFormationPlane;
|
||||
import appeng.fluids.util.IAEFluidTank;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
|
||||
public class GuiFluidFormationPlane extends GuiUpgradeable<ContainerFluidFormationPlane> {
|
||||
public GuiFluidFormationPlane(ContainerFluidFormationPlane container, PlayerInventory playerInventory,
|
||||
ITextComponent title) {
|
||||
super(container, playerInventory, title);
|
||||
this.ySize = 251;
|
||||
}
|
||||
|
||||
public class GuiFluidFormationPlane extends GuiUpgradeable<ContainerFluidFormationPlane>
|
||||
{
|
||||
public GuiFluidFormationPlane(ContainerFluidFormationPlane container, PlayerInventory playerInventory, ITextComponent title)
|
||||
{
|
||||
super(container, playerInventory, title);
|
||||
this.ySize = 251;
|
||||
}
|
||||
@Override
|
||||
public void init() {
|
||||
super.init();
|
||||
|
||||
@Override
|
||||
public void init()
|
||||
{
|
||||
super.init();
|
||||
final int xo = 8;
|
||||
final int yo = 23 + 6;
|
||||
|
||||
final int xo = 8;
|
||||
final int yo = 23 + 6;
|
||||
final IAEFluidTank config = container.getFluidConfigInventory();
|
||||
|
||||
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 GuiFluidSlot(config, idx, idx, xo + x * 18, yo + y * 18));
|
||||
} else {
|
||||
this.guiSlots.add(new GuiOptionalFluidSlot(config, container, idx, idx, y - 2, xo, yo, x, y));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 GuiFluidSlot( config, idx, idx, xo + x * 18, yo + y * 18 ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
this.guiSlots.add( new GuiOptionalFluidSlot( config, container, idx, idx, y - 2, xo, yo, x, y ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
protected void addButtons() {
|
||||
this.addButton(new GuiTabButton(this.guiLeft + 154, this.guiTop, 2 + 4 * 16, GuiText.Priority.getLocal(),
|
||||
this.itemRenderer, btn -> openPriorityGui()));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addButtons()
|
||||
{
|
||||
this.addButton( new GuiTabButton( this.guiLeft + 154, this.guiTop, 2 + 4 * 16, GuiText.Priority.getLocal(), this.itemRenderer, btn -> openPriorityGui() ) );
|
||||
}
|
||||
private void openPriorityGui() {
|
||||
NetworkHandler.instance().sendToServer(new PacketSwitchGuis(ContainerPriority.TYPE));
|
||||
}
|
||||
|
||||
private void openPriorityGui() {
|
||||
NetworkHandler.instance().sendToServer( new PacketSwitchGuis( ContainerPriority.TYPE ) );
|
||||
}
|
||||
@Override
|
||||
protected String getBackground() {
|
||||
return "guis/storagebus.png";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getBackground()
|
||||
{
|
||||
return "guis/storagebus.png";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected GuiText getName()
|
||||
{
|
||||
return GuiText.FluidFormationPlane;
|
||||
}
|
||||
@Override
|
||||
protected GuiText getName() {
|
||||
return GuiText.FluidFormationPlane;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
|
||||
package appeng.fluids.client.gui;
|
||||
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
|
||||
import appeng.client.gui.implementations.GuiUpgradeable;
|
||||
import appeng.core.localization.GuiText;
|
||||
@@ -26,47 +28,40 @@ import appeng.fluids.client.gui.widgets.GuiOptionalFluidSlot;
|
||||
import appeng.fluids.container.ContainerFluidIO;
|
||||
import appeng.fluids.parts.PartFluidImportBus;
|
||||
import appeng.fluids.util.IAEFluidTank;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
|
||||
|
||||
/**
|
||||
* @author BrockWS
|
||||
* @version rv5 - 1/05/2018
|
||||
* @since rv5 1/05/2018
|
||||
*/
|
||||
public class GuiFluidIO extends GuiUpgradeable<ContainerFluidIO>
|
||||
{
|
||||
public class GuiFluidIO extends GuiUpgradeable<ContainerFluidIO> {
|
||||
|
||||
public GuiFluidIO(ContainerFluidIO container, PlayerInventory playerInventory, ITextComponent title)
|
||||
{
|
||||
super(container, playerInventory, title);
|
||||
}
|
||||
public GuiFluidIO(ContainerFluidIO container, PlayerInventory playerInventory, ITextComponent title) {
|
||||
super(container, playerInventory, title);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init()
|
||||
{
|
||||
super.init();
|
||||
@Override
|
||||
public void init() {
|
||||
super.init();
|
||||
|
||||
final IAEFluidTank inv = this.container.getFluidConfigInventory();
|
||||
final int y = 40;
|
||||
final int x = 80;
|
||||
final IAEFluidTank inv = this.container.getFluidConfigInventory();
|
||||
final int y = 40;
|
||||
final int x = 80;
|
||||
|
||||
this.guiSlots.add( new GuiFluidSlot( inv, 0, 0, x, y ) );
|
||||
this.guiSlots.add( new GuiOptionalFluidSlot( inv, container, 1, 1, 1, x, y, -1, 0 ) );
|
||||
this.guiSlots.add( new GuiOptionalFluidSlot( inv, container, 2, 2, 1, x, y, 1, 0 ) );
|
||||
this.guiSlots.add( new GuiOptionalFluidSlot( inv, container, 3, 3, 1, x, y, 0, -1 ) );
|
||||
this.guiSlots.add( new GuiOptionalFluidSlot( inv, container, 4, 4, 1, x, y, 0, 1 ) );
|
||||
this.guiSlots.add(new GuiFluidSlot(inv, 0, 0, x, y));
|
||||
this.guiSlots.add(new GuiOptionalFluidSlot(inv, container, 1, 1, 1, x, y, -1, 0));
|
||||
this.guiSlots.add(new GuiOptionalFluidSlot(inv, container, 2, 2, 1, x, y, 1, 0));
|
||||
this.guiSlots.add(new GuiOptionalFluidSlot(inv, container, 3, 3, 1, x, y, 0, -1));
|
||||
this.guiSlots.add(new GuiOptionalFluidSlot(inv, container, 4, 4, 1, x, y, 0, 1));
|
||||
|
||||
this.guiSlots.add( new GuiOptionalFluidSlot( inv, container, 5, 5, 2, x, y, -1, -1 ) );
|
||||
this.guiSlots.add( new GuiOptionalFluidSlot( inv, container, 6, 6, 2, x, y, 1, -1 ) );
|
||||
this.guiSlots.add( new GuiOptionalFluidSlot( inv, container, 7, 7, 2, x, y, -1, 1 ) );
|
||||
this.guiSlots.add( new GuiOptionalFluidSlot( inv, container, 8, 8, 2, x, y, 1, 1 ) );
|
||||
}
|
||||
this.guiSlots.add(new GuiOptionalFluidSlot(inv, container, 5, 5, 2, x, y, -1, -1));
|
||||
this.guiSlots.add(new GuiOptionalFluidSlot(inv, container, 6, 6, 2, x, y, 1, -1));
|
||||
this.guiSlots.add(new GuiOptionalFluidSlot(inv, container, 7, 7, 2, x, y, -1, 1));
|
||||
this.guiSlots.add(new GuiOptionalFluidSlot(inv, container, 8, 8, 2, x, y, 1, 1));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected GuiText getName()
|
||||
{
|
||||
return this.bc instanceof PartFluidImportBus ? GuiText.ImportBusFluids : GuiText.ExportBusFluids;
|
||||
}
|
||||
@Override
|
||||
protected GuiText getName() {
|
||||
return this.bc instanceof PartFluidImportBus ? GuiText.ImportBusFluids : GuiText.ExportBusFluids;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,9 @@
|
||||
|
||||
package appeng.fluids.client.gui;
|
||||
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraftforge.fml.client.gui.GuiUtils;
|
||||
|
||||
import appeng.client.gui.implementations.GuiUpgradeable;
|
||||
import appeng.client.gui.widgets.GuiTabButton;
|
||||
@@ -30,65 +33,55 @@ import appeng.fluids.client.gui.widgets.GuiFluidTank;
|
||||
import appeng.fluids.container.ContainerFluidInterface;
|
||||
import appeng.fluids.helper.DualityFluidInterface;
|
||||
import appeng.fluids.util.IAEFluidTank;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraftforge.fml.client.gui.GuiUtils;
|
||||
|
||||
public class GuiFluidInterface extends GuiUpgradeable<ContainerFluidInterface>
|
||||
{
|
||||
public GuiFluidInterface(ContainerFluidInterface container, PlayerInventory playerInventory, ITextComponent title)
|
||||
{
|
||||
super(container, playerInventory, title);
|
||||
this.ySize = 231;
|
||||
}
|
||||
public class GuiFluidInterface extends GuiUpgradeable<ContainerFluidInterface> {
|
||||
public GuiFluidInterface(ContainerFluidInterface container, PlayerInventory playerInventory, ITextComponent title) {
|
||||
super(container, playerInventory, title);
|
||||
this.ySize = 231;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init()
|
||||
{
|
||||
super.init();
|
||||
@Override
|
||||
public void init() {
|
||||
super.init();
|
||||
|
||||
final IAEFluidTank configFluids = this.container.getFluidConfigInventory();
|
||||
final IAEFluidTank fluidTank = this.container.getTanks();
|
||||
final IAEFluidTank configFluids = this.container.getFluidConfigInventory();
|
||||
final IAEFluidTank fluidTank = this.container.getTanks();
|
||||
|
||||
for( int i = 0; i < DualityFluidInterface.NUMBER_OF_TANKS; ++i )
|
||||
{
|
||||
final GuiFluidTank guiTank = new GuiFluidTank( fluidTank, i, this.getGuiLeft() + 35 + 18 * i, this
|
||||
.getGuiTop() + 53, 16, 68 );
|
||||
this.addButton( guiTank );
|
||||
this.guiSlots.add( new GuiFluidSlot( configFluids, i, i, 35 + 18 * i, 35 ) );
|
||||
}
|
||||
for (int i = 0; i < DualityFluidInterface.NUMBER_OF_TANKS; ++i) {
|
||||
final GuiFluidTank guiTank = new GuiFluidTank(fluidTank, i, this.getGuiLeft() + 35 + 18 * i,
|
||||
this.getGuiTop() + 53, 16, 68);
|
||||
this.addButton(guiTank);
|
||||
this.guiSlots.add(new GuiFluidSlot(configFluids, i, i, 35 + 18 * i, 35));
|
||||
}
|
||||
|
||||
this.addButton( new GuiTabButton( this.getGuiLeft() + 154, this.getGuiTop(), 2 + 4 * 16, GuiText.Priority.getLocal(), this.itemRenderer, btn -> openPriorityGui() ) );
|
||||
}
|
||||
this.addButton(new GuiTabButton(this.getGuiLeft() + 154, this.getGuiTop(), 2 + 4 * 16,
|
||||
GuiText.Priority.getLocal(), this.itemRenderer, btn -> openPriorityGui()));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addButtons()
|
||||
{
|
||||
}
|
||||
@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 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 */ );
|
||||
}
|
||||
@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 PacketSwitchGuis( ContainerPriority.TYPE ) );
|
||||
}
|
||||
private void openPriorityGui() {
|
||||
NetworkHandler.instance().sendToServer(new PacketSwitchGuis(ContainerPriority.TYPE));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean drawUpgrades()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
protected boolean drawUpgrades() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,204 +1,180 @@
|
||||
|
||||
package appeng.fluids.client.gui;
|
||||
|
||||
|
||||
|
||||
import appeng.client.gui.widgets.GuiServerSettingToggleButton;
|
||||
import net.minecraft.client.gui.widget.button.Button;
|
||||
import net.minecraft.client.util.InputMappings;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
|
||||
import appeng.api.config.RedstoneMode;
|
||||
import appeng.api.config.Settings;
|
||||
import appeng.client.gui.implementations.GuiUpgradeable;
|
||||
import appeng.client.gui.widgets.GuiNumberBox;
|
||||
import appeng.client.gui.widgets.GuiServerSettingToggleButton;
|
||||
import appeng.core.AEConfig;
|
||||
import appeng.core.localization.GuiText;
|
||||
import appeng.core.sync.network.NetworkHandler;
|
||||
import appeng.core.sync.packets.PacketValueConfig;
|
||||
import appeng.fluids.client.gui.widgets.GuiFluidSlot;
|
||||
import appeng.fluids.container.ContainerFluidLevelEmitter;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
|
||||
public class GuiFluidLevelEmitter extends GuiUpgradeable<ContainerFluidLevelEmitter> {
|
||||
private GuiNumberBox level;
|
||||
|
||||
public class GuiFluidLevelEmitter extends GuiUpgradeable<ContainerFluidLevelEmitter>
|
||||
{
|
||||
private GuiNumberBox level;
|
||||
public GuiFluidLevelEmitter(ContainerFluidLevelEmitter container, PlayerInventory playerInventory,
|
||||
ITextComponent title) {
|
||||
super(container, playerInventory, title);
|
||||
}
|
||||
|
||||
public GuiFluidLevelEmitter(ContainerFluidLevelEmitter container, PlayerInventory playerInventory, ITextComponent title) {
|
||||
super(container, playerInventory, title);
|
||||
}
|
||||
@Override
|
||||
public void init() {
|
||||
super.init();
|
||||
|
||||
@Override
|
||||
public void init()
|
||||
{
|
||||
super.init();
|
||||
this.level = new GuiNumberBox(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);
|
||||
|
||||
this.level = new GuiNumberBox( 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 GuiFluidSlot(this.container.getFluidConfigInventory(), 0, 0, x, y));
|
||||
}
|
||||
|
||||
final int y = 40;
|
||||
final int x = 80 + 44;
|
||||
this.guiSlots.add( new GuiFluidSlot( this.container.getFluidConfigInventory(), 0, 0, x, y ) );
|
||||
}
|
||||
@Override
|
||||
protected void addButtons() {
|
||||
this.redstoneMode = new GuiServerSettingToggleButton<>(this.guiLeft - 18, this.guiTop + 28,
|
||||
Settings.REDSTONE_EMITTER, RedstoneMode.LOW_SIGNAL);
|
||||
|
||||
@Override
|
||||
protected void addButtons()
|
||||
{
|
||||
this.redstoneMode = new GuiServerSettingToggleButton<>( 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);
|
||||
|
||||
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 + 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( 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);
|
||||
}
|
||||
|
||||
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
|
||||
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 boolean drawUpgrades()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
protected String getBackground() {
|
||||
return "guis/lvlemitter.png";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getBackground()
|
||||
{
|
||||
return "guis/lvlemitter.png";
|
||||
}
|
||||
@Override
|
||||
protected GuiText getName() {
|
||||
return GuiText.FluidLevelEmitter;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected GuiText getName()
|
||||
{
|
||||
return GuiText.FluidLevelEmitter;
|
||||
}
|
||||
@Override
|
||||
protected void handleButtonVisibility() {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleButtonVisibility()
|
||||
{
|
||||
}
|
||||
private void addQty(final long i) {
|
||||
try {
|
||||
String Out = this.level.getText();
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
boolean Fixed = false;
|
||||
while( Out.startsWith( "0" ) && Out.length() > 1 )
|
||||
{
|
||||
Out = Out.substring( 1 );
|
||||
Fixed = true;
|
||||
}
|
||||
if (Fixed) {
|
||||
this.level.setText(Out);
|
||||
}
|
||||
|
||||
if( Fixed )
|
||||
{
|
||||
this.level.setText( Out );
|
||||
}
|
||||
if (Out.isEmpty()) {
|
||||
Out = "0";
|
||||
}
|
||||
|
||||
if( Out.isEmpty() )
|
||||
{
|
||||
Out = "0";
|
||||
}
|
||||
long result = Long.parseLong(Out);
|
||||
result += i;
|
||||
if (result < 0) {
|
||||
result = 0;
|
||||
}
|
||||
|
||||
long result = Long.parseLong( Out );
|
||||
result += i;
|
||||
if( result < 0 )
|
||||
{
|
||||
result = 0;
|
||||
}
|
||||
this.level.setText(Out = Long.toString(result));
|
||||
|
||||
this.level.setText( Out = Long.toString( result ) );
|
||||
NetworkHandler.instance().sendToServer(new PacketValueConfig("FluidLevelEmitter.Value", Out));
|
||||
} catch (final NumberFormatException e) {
|
||||
// nope..
|
||||
this.level.setText("0");
|
||||
}
|
||||
}
|
||||
|
||||
NetworkHandler.instance().sendToServer( new PacketValueConfig( "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();
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
boolean Fixed = false;
|
||||
while( Out.startsWith( "0" ) && Out.length() > 1 )
|
||||
{
|
||||
Out = Out.substring( 1 );
|
||||
Fixed = true;
|
||||
}
|
||||
if (Fixed) {
|
||||
this.level.setText(Out);
|
||||
}
|
||||
|
||||
if( Fixed )
|
||||
{
|
||||
this.level.setText( Out );
|
||||
}
|
||||
if (Out.isEmpty()) {
|
||||
Out = "0";
|
||||
}
|
||||
|
||||
if( Out.isEmpty() )
|
||||
{
|
||||
Out = "0";
|
||||
}
|
||||
NetworkHandler.instance().sendToServer(new PacketValueConfig("FluidLevelEmitter.Value", Out));
|
||||
return true;
|
||||
}
|
||||
return super.charTyped(character, keyCode);
|
||||
}
|
||||
|
||||
NetworkHandler.instance().sendToServer( new PacketValueConfig( "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();
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
boolean Fixed = false;
|
||||
while( Out.startsWith( "0" ) && Out.length() > 1 )
|
||||
{
|
||||
Out = Out.substring( 1 );
|
||||
Fixed = true;
|
||||
}
|
||||
if (Fixed) {
|
||||
this.level.setText(Out);
|
||||
}
|
||||
|
||||
if( Fixed )
|
||||
{
|
||||
this.level.setText( Out );
|
||||
}
|
||||
if (Out.isEmpty()) {
|
||||
Out = "0";
|
||||
}
|
||||
|
||||
if( Out.isEmpty() )
|
||||
{
|
||||
Out = "0";
|
||||
}
|
||||
|
||||
NetworkHandler.instance().sendToServer( new PacketValueConfig( "FluidLevelEmitter.Value", Out ) );
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return super.keyPressed(keyCode, scanCode, p_keyPressed_3_);
|
||||
}
|
||||
NetworkHandler.instance().sendToServer(new PacketValueConfig("FluidLevelEmitter.Value", Out));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return super.keyPressed(keyCode, scanCode, p_keyPressed_3_);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,150 +1,138 @@
|
||||
/*
|
||||
* 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 appeng.client.gui.widgets.GuiActionButton;
|
||||
import appeng.client.gui.widgets.GuiServerSettingToggleButton;
|
||||
import appeng.container.implementations.ContainerPriority;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
|
||||
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.GuiUpgradeable;
|
||||
import appeng.client.gui.widgets.GuiSettingToggleButton;
|
||||
import appeng.client.gui.widgets.GuiTabButton;
|
||||
import appeng.core.localization.GuiText;
|
||||
|
||||
import appeng.core.sync.network.NetworkHandler;
|
||||
import appeng.core.sync.packets.PacketSwitchGuis;
|
||||
import appeng.core.sync.packets.PacketValueConfig;
|
||||
import appeng.fluids.client.gui.widgets.GuiFluidSlot;
|
||||
import appeng.fluids.client.gui.widgets.GuiOptionalFluidSlot;
|
||||
import appeng.fluids.container.ContainerFluidStorageBus;
|
||||
import appeng.fluids.util.IAEFluidTank;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
|
||||
|
||||
/**
|
||||
* @author BrockWS
|
||||
* @version rv6 - 22/05/2018
|
||||
* @since rv6 22/05/2018
|
||||
*/
|
||||
public class GuiFluidStorageBus extends GuiUpgradeable<ContainerFluidStorageBus>
|
||||
{
|
||||
private GuiSettingToggleButton<AccessRestriction> rwMode;
|
||||
private GuiSettingToggleButton<StorageFilter> storageFilter;
|
||||
|
||||
public GuiFluidStorageBus(ContainerFluidStorageBus container, PlayerInventory playerInventory, ITextComponent 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 GuiFluidSlot( config, idx, idx, xo + x * 18, yo + y * 18 ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
this.guiSlots.add( new GuiOptionalFluidSlot( config, container, idx, idx, y - 2, xo, yo, x, y ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addButtons()
|
||||
{
|
||||
addButton( new GuiActionButton( this.guiLeft - 18, this.guiTop + 8, ActionItems.CLOSE, btn -> clear() ) );
|
||||
addButton( new GuiActionButton( this.guiLeft - 18, this.guiTop + 28, ActionItems.WRENCH, btn -> partition() ) );
|
||||
this.rwMode = new GuiServerSettingToggleButton<>( this.guiLeft - 18, this.guiTop + 48, Settings.ACCESS, AccessRestriction.READ_WRITE );
|
||||
this.storageFilter = new GuiServerSettingToggleButton<>( this.guiLeft - 18, this.guiTop + 68, Settings.STORAGE_FILTER, StorageFilter.EXTRACTABLE_ONLY );
|
||||
this.fuzzyMode = new GuiServerSettingToggleButton<>( this.guiLeft - 18, this.guiTop + 88, Settings.FUZZY_MODE, FuzzyMode.IGNORE_ALL );
|
||||
|
||||
addButton( this.addButton( new GuiTabButton( 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( ( (ContainerFluidStorageBus) this.cvb ).getStorageFilter() );
|
||||
}
|
||||
|
||||
if( this.rwMode != null )
|
||||
{
|
||||
this.rwMode.set( ( (ContainerFluidStorageBus) this.cvb ).getReadWriteMode() );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getBackground()
|
||||
{
|
||||
return "guis/storagebus.png";
|
||||
}
|
||||
|
||||
private void partition() {
|
||||
NetworkHandler.instance().sendToServer( new PacketValueConfig( "StorageBus.Action", "Partition" ) );
|
||||
}
|
||||
|
||||
private void clear() {
|
||||
NetworkHandler.instance().sendToServer( new PacketValueConfig( "StorageBus.Action", "Clear" ) );
|
||||
}
|
||||
|
||||
private void openPriorityGui() {
|
||||
NetworkHandler.instance().sendToServer( new PacketSwitchGuis( ContainerPriority.TYPE ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected GuiText getName()
|
||||
{
|
||||
return GuiText.StorageBusFluids;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* 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.util.text.ITextComponent;
|
||||
|
||||
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.GuiUpgradeable;
|
||||
import appeng.client.gui.widgets.GuiActionButton;
|
||||
import appeng.client.gui.widgets.GuiServerSettingToggleButton;
|
||||
import appeng.client.gui.widgets.GuiSettingToggleButton;
|
||||
import appeng.client.gui.widgets.GuiTabButton;
|
||||
import appeng.container.implementations.ContainerPriority;
|
||||
import appeng.core.localization.GuiText;
|
||||
import appeng.core.sync.network.NetworkHandler;
|
||||
import appeng.core.sync.packets.PacketSwitchGuis;
|
||||
import appeng.core.sync.packets.PacketValueConfig;
|
||||
import appeng.fluids.client.gui.widgets.GuiFluidSlot;
|
||||
import appeng.fluids.client.gui.widgets.GuiOptionalFluidSlot;
|
||||
import appeng.fluids.container.ContainerFluidStorageBus;
|
||||
import appeng.fluids.util.IAEFluidTank;
|
||||
|
||||
/**
|
||||
* @author BrockWS
|
||||
* @version rv6 - 22/05/2018
|
||||
* @since rv6 22/05/2018
|
||||
*/
|
||||
public class GuiFluidStorageBus extends GuiUpgradeable<ContainerFluidStorageBus> {
|
||||
private GuiSettingToggleButton<AccessRestriction> rwMode;
|
||||
private GuiSettingToggleButton<StorageFilter> storageFilter;
|
||||
|
||||
public GuiFluidStorageBus(ContainerFluidStorageBus container, PlayerInventory playerInventory,
|
||||
ITextComponent 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 GuiFluidSlot(config, idx, idx, xo + x * 18, yo + y * 18));
|
||||
} else {
|
||||
this.guiSlots.add(new GuiOptionalFluidSlot(config, container, idx, idx, y - 2, xo, yo, x, y));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addButtons() {
|
||||
addButton(new GuiActionButton(this.guiLeft - 18, this.guiTop + 8, ActionItems.CLOSE, btn -> clear()));
|
||||
addButton(new GuiActionButton(this.guiLeft - 18, this.guiTop + 28, ActionItems.WRENCH, btn -> partition()));
|
||||
this.rwMode = new GuiServerSettingToggleButton<>(this.guiLeft - 18, this.guiTop + 48, Settings.ACCESS,
|
||||
AccessRestriction.READ_WRITE);
|
||||
this.storageFilter = new GuiServerSettingToggleButton<>(this.guiLeft - 18, this.guiTop + 68,
|
||||
Settings.STORAGE_FILTER, StorageFilter.EXTRACTABLE_ONLY);
|
||||
this.fuzzyMode = new GuiServerSettingToggleButton<>(this.guiLeft - 18, this.guiTop + 88, Settings.FUZZY_MODE,
|
||||
FuzzyMode.IGNORE_ALL);
|
||||
|
||||
addButton(this.addButton(new GuiTabButton(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(((ContainerFluidStorageBus) this.cvb).getStorageFilter());
|
||||
}
|
||||
|
||||
if (this.rwMode != null) {
|
||||
this.rwMode.set(((ContainerFluidStorageBus) this.cvb).getReadWriteMode());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getBackground() {
|
||||
return "guis/storagebus.png";
|
||||
}
|
||||
|
||||
private void partition() {
|
||||
NetworkHandler.instance().sendToServer(new PacketValueConfig("StorageBus.Action", "Partition"));
|
||||
}
|
||||
|
||||
private void clear() {
|
||||
NetworkHandler.instance().sendToServer(new PacketValueConfig("StorageBus.Action", "Clear"));
|
||||
}
|
||||
|
||||
private void openPriorityGui() {
|
||||
NetworkHandler.instance().sendToServer(new PacketSwitchGuis(ContainerPriority.TYPE));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected GuiText getName() {
|
||||
return GuiText.StorageBusFluids;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,340 +1,312 @@
|
||||
/*
|
||||
* 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 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.gui.AEBaseMEGui;
|
||||
import appeng.client.gui.widgets.GuiSettingToggleButton;
|
||||
import appeng.client.gui.widgets.GuiScrollbar;
|
||||
import appeng.client.gui.widgets.ISortSource;
|
||||
import appeng.client.gui.widgets.MEGuiTextField;
|
||||
import appeng.client.me.FluidRepo;
|
||||
import appeng.client.me.InternalFluidSlotME;
|
||||
import appeng.client.me.SlotFluidME;
|
||||
import appeng.core.AELog;
|
||||
import appeng.core.localization.GuiText;
|
||||
import appeng.core.sync.network.NetworkHandler;
|
||||
import appeng.core.sync.packets.PacketInventoryAction;
|
||||
import appeng.core.sync.packets.PacketValueConfig;
|
||||
import appeng.fluids.container.ContainerFluidTerminal;
|
||||
import appeng.fluids.container.slots.IMEFluidSlot;
|
||||
import appeng.helpers.InventoryAction;
|
||||
import appeng.util.IConfigManagerHost;
|
||||
import appeng.util.Platform;
|
||||
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.util.text.ITextComponent;
|
||||
import net.minecraftforge.fml.client.gui.GuiUtils;
|
||||
|
||||
import java.text.NumberFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
|
||||
/**
|
||||
* @author BrockWS
|
||||
* @version rv6 - 12/05/2018
|
||||
* @since rv6 12/05/2018
|
||||
*/
|
||||
public class GuiFluidTerminal extends AEBaseMEGui<ContainerFluidTerminal> implements ISortSource, IConfigManagerHost
|
||||
{
|
||||
private final List<SlotFluidME> meFluidSlots = new LinkedList<>();
|
||||
private final FluidRepo repo;
|
||||
private final IConfigManager configSrc;
|
||||
private final int offsetX = 9;
|
||||
private int rows = 6;
|
||||
private int perRow = 9;
|
||||
|
||||
private MEGuiTextField searchField;
|
||||
private GuiSettingToggleButton<SortOrder> sortByBox;
|
||||
private GuiSettingToggleButton<SortDir> sortDirBox;
|
||||
|
||||
public GuiFluidTerminal(ContainerFluidTerminal container, PlayerInventory playerInventory, ITextComponent title) {
|
||||
super(container, playerInventory, title);
|
||||
this.xSize = 185;
|
||||
this.ySize = 222;
|
||||
final GuiScrollbar scrollbar = new GuiScrollbar();
|
||||
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 MEGuiTextField( this.font, this.guiLeft + Math.max( 80, this.offsetX ), 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 GuiSettingToggleButton<>( this.guiLeft - 18, offset, Settings.SORT_BY, getSortBy(), Platform::isSortOrderAvailable, this::toggleServerSetting ) );
|
||||
offset += 20;
|
||||
|
||||
this.sortDirBox = this.addButton( new GuiSettingToggleButton<>( this.guiLeft - 18, offset, Settings.SORT_DIRECTION, getSortDir(), this::toggleServerSetting ) );
|
||||
|
||||
for( int y = 0; y < this.rows; y++ )
|
||||
{
|
||||
for( int x = 0; x < this.perRow; x++ )
|
||||
{
|
||||
SlotFluidME slot = new SlotFluidME( new InternalFluidSlotME( this.repo, x + y * this.perRow, this.offsetX + x * 18, 18 + 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().getDisplayName().getFormattedText() );
|
||||
list.add( formattedAmount );
|
||||
list.add( modName );
|
||||
|
||||
this.renderTooltip( list, mouseX, mouseY );
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
super.renderHoveredToolTip( mouseX, mouseY );
|
||||
}
|
||||
|
||||
private <S extends Enum<S>> void toggleServerSetting(GuiSettingToggleButton<S> btn, boolean backwards) {
|
||||
S next = btn.getNextValue(backwards);
|
||||
NetworkHandler.instance().sendToServer( new PacketValueConfig( 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 PacketInventoryAction( 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 PacketInventoryAction( InventoryAction.EMPTY_ITEM, slot.slotNumber, 0 ) );
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
super.handleMouseClick( slot, slotIdx, mouseButton, clickType );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean charTyped(char character, int keyCode) {
|
||||
if (character == ' ' && this.searchField.getText().isEmpty())
|
||||
{
|
||||
// Swallow spaces if the text field is still empty
|
||||
return true;
|
||||
}
|
||||
|
||||
if (this.searchField.charTyped(character, keyCode)) {
|
||||
this.repo.setSearchString( this.searchField.getText() );
|
||||
this.repo.updateView();
|
||||
this.setScrollBar();
|
||||
return true;
|
||||
}
|
||||
|
||||
return super.charTyped(character, keyCode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean keyPressed(int keyCode, int scanCode, int p_keyPressed_3_)
|
||||
{
|
||||
InputMappings.Input input = InputMappings.getInputByCode(keyCode, scanCode);
|
||||
if( !this.checkHotbarKeys(input) )
|
||||
{
|
||||
if( this.searchField.keyPressed( keyCode, scanCode, p_keyPressed_3_ ) )
|
||||
{
|
||||
this.repo.setSearchString( this.searchField.getText() );
|
||||
this.repo.updateView();
|
||||
this.setScrollBar();
|
||||
}
|
||||
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( this.rows * 18 - 2 );
|
||||
this.getScrollBar().setRange( 0, ( this.repo.size() + this.perRow - 1 ) / this.perRow - this.rows, Math.max( 1, this.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";
|
||||
}
|
||||
}
|
||||
/*
|
||||
* 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.InputMappings;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.container.ClickType;
|
||||
import net.minecraft.inventory.container.Slot;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
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.gui.AEBaseMEGui;
|
||||
import appeng.client.gui.widgets.GuiScrollbar;
|
||||
import appeng.client.gui.widgets.GuiSettingToggleButton;
|
||||
import appeng.client.gui.widgets.ISortSource;
|
||||
import appeng.client.gui.widgets.MEGuiTextField;
|
||||
import appeng.client.me.FluidRepo;
|
||||
import appeng.client.me.InternalFluidSlotME;
|
||||
import appeng.client.me.SlotFluidME;
|
||||
import appeng.core.AELog;
|
||||
import appeng.core.localization.GuiText;
|
||||
import appeng.core.sync.network.NetworkHandler;
|
||||
import appeng.core.sync.packets.PacketInventoryAction;
|
||||
import appeng.core.sync.packets.PacketValueConfig;
|
||||
import appeng.fluids.container.ContainerFluidTerminal;
|
||||
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 GuiFluidTerminal extends AEBaseMEGui<ContainerFluidTerminal> implements ISortSource, IConfigManagerHost {
|
||||
private final List<SlotFluidME> meFluidSlots = new LinkedList<>();
|
||||
private final FluidRepo repo;
|
||||
private final IConfigManager configSrc;
|
||||
private final int offsetX = 9;
|
||||
private int rows = 6;
|
||||
private int perRow = 9;
|
||||
|
||||
private MEGuiTextField searchField;
|
||||
private GuiSettingToggleButton<SortOrder> sortByBox;
|
||||
private GuiSettingToggleButton<SortDir> sortDirBox;
|
||||
|
||||
public GuiFluidTerminal(ContainerFluidTerminal container, PlayerInventory playerInventory, ITextComponent title) {
|
||||
super(container, playerInventory, title);
|
||||
this.xSize = 185;
|
||||
this.ySize = 222;
|
||||
final GuiScrollbar scrollbar = new GuiScrollbar();
|
||||
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 MEGuiTextField(this.font, this.guiLeft + Math.max(80, this.offsetX), 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 GuiSettingToggleButton<>(this.guiLeft - 18, offset, Settings.SORT_BY,
|
||||
getSortBy(), Platform::isSortOrderAvailable, this::toggleServerSetting));
|
||||
offset += 20;
|
||||
|
||||
this.sortDirBox = this.addButton(new GuiSettingToggleButton<>(this.guiLeft - 18, offset,
|
||||
Settings.SORT_DIRECTION, getSortDir(), this::toggleServerSetting));
|
||||
|
||||
for (int y = 0; y < this.rows; y++) {
|
||||
for (int x = 0; x < this.perRow; x++) {
|
||||
SlotFluidME slot = new SlotFluidME(
|
||||
new InternalFluidSlotME(this.repo, x + y * this.perRow, this.offsetX + x * 18, 18 + 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().getDisplayName().getFormattedText());
|
||||
list.add(formattedAmount);
|
||||
list.add(modName);
|
||||
|
||||
this.renderTooltip(list, mouseX, mouseY);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
super.renderHoveredToolTip(mouseX, mouseY);
|
||||
}
|
||||
|
||||
private <S extends Enum<S>> void toggleServerSetting(GuiSettingToggleButton<S> btn, boolean backwards) {
|
||||
S next = btn.getNextValue(backwards);
|
||||
NetworkHandler.instance().sendToServer(new PacketValueConfig(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 PacketInventoryAction(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 PacketInventoryAction(InventoryAction.EMPTY_ITEM, slot.slotNumber, 0));
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
super.handleMouseClick(slot, slotIdx, mouseButton, clickType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean charTyped(char character, int keyCode) {
|
||||
if (character == ' ' && this.searchField.getText().isEmpty()) {
|
||||
// Swallow spaces if the text field is still empty
|
||||
return true;
|
||||
}
|
||||
|
||||
if (this.searchField.charTyped(character, keyCode)) {
|
||||
this.repo.setSearchString(this.searchField.getText());
|
||||
this.repo.updateView();
|
||||
this.setScrollBar();
|
||||
return true;
|
||||
}
|
||||
|
||||
return super.charTyped(character, keyCode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean keyPressed(int keyCode, int scanCode, int p_keyPressed_3_) {
|
||||
InputMappings.Input input = InputMappings.getInputByCode(keyCode, scanCode);
|
||||
if (!this.checkHotbarKeys(input)) {
|
||||
if (this.searchField.keyPressed(keyCode, scanCode, p_keyPressed_3_)) {
|
||||
this.repo.setSearchString(this.searchField.getText());
|
||||
this.repo.updateView();
|
||||
this.setScrollBar();
|
||||
}
|
||||
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(this.rows * 18 - 2);
|
||||
this.getScrollBar().setRange(0, (this.repo.size() + this.perRow - 1) / this.perRow - this.rows,
|
||||
Math.max(1, this.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,6 +1,5 @@
|
||||
package appeng.fluids.client.gui.widgets;
|
||||
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
@@ -17,6 +16,7 @@ import net.minecraftforge.fluids.FluidAttributes;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.FluidUtil;
|
||||
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
|
||||
import net.minecraftforge.fml.client.gui.GuiUtils;
|
||||
|
||||
import appeng.api.storage.data.IAEFluidStack;
|
||||
import appeng.client.gui.widgets.GuiCustomSlot;
|
||||
@@ -24,92 +24,79 @@ import appeng.core.sync.network.NetworkHandler;
|
||||
import appeng.core.sync.packets.PacketFluidSlot;
|
||||
import appeng.fluids.util.AEFluidStack;
|
||||
import appeng.fluids.util.IAEFluidTank;
|
||||
import net.minecraftforge.fml.client.gui.GuiUtils;
|
||||
|
||||
public class GuiFluidSlot extends GuiCustomSlot {
|
||||
private final IAEFluidTank fluids;
|
||||
private final int slot;
|
||||
|
||||
public class GuiFluidSlot extends GuiCustomSlot
|
||||
{
|
||||
private final IAEFluidTank fluids;
|
||||
private final int slot;
|
||||
public GuiFluidSlot(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;
|
||||
}
|
||||
|
||||
public GuiFluidSlot( 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 Minecraft 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(AtlasTexture.LOCATION_BLOCKS_TEXTURE);
|
||||
final TextureAtlasSprite sprite = mc.getAtlasSpriteGetter(AtlasTexture.LOCATION_BLOCKS_TEXTURE)
|
||||
.apply(attributes.getStillTexture(fs.getFluidStack()));
|
||||
|
||||
@Override
|
||||
public void drawContent( final Minecraft 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( AtlasTexture.LOCATION_BLOCKS_TEXTURE );
|
||||
final TextureAtlasSprite sprite = mc.getAtlasSpriteGetter( AtlasTexture.LOCATION_BLOCKS_TEXTURE ).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);
|
||||
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
||||
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 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<FluidStack> fluidOpt = FluidUtil.getFluidContained(clickStack);
|
||||
fluidOpt.ifPresent(fluid -> {
|
||||
this.setFluidStack(AEFluidStack.fromFluidStack(fluid));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void slotClicked( final ItemStack clickStack, int mouseButton )
|
||||
{
|
||||
if( clickStack.isEmpty() || mouseButton == 1 )
|
||||
{
|
||||
this.setFluidStack( null );
|
||||
}
|
||||
else if( mouseButton == 0 )
|
||||
{
|
||||
final LazyOptional<FluidStack> 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 String getMessage()
|
||||
{
|
||||
final IAEFluidStack fluid = this.getFluidStack();
|
||||
if( fluid != null )
|
||||
{
|
||||
return I18n.format( fluid.getFluidStack().getTranslationKey() );
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public boolean isVisible() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVisible()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public IAEFluidStack getFluidStack() {
|
||||
return this.fluids.getFluidInSlot(this.slot);
|
||||
}
|
||||
|
||||
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 PacketFluidSlot( Collections.singletonMap( this.getId(), this.getFluidStack() ) ) );
|
||||
}
|
||||
public void setFluidStack(final IAEFluidStack stack) {
|
||||
this.fluids.setFluidInSlot(this.slot, stack);
|
||||
NetworkHandler.instance()
|
||||
.sendToServer(new PacketFluidSlot(Collections.singletonMap(this.getId(), this.getFluidStack())));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,12 +18,8 @@
|
||||
|
||||
package appeng.fluids.client.gui.widgets;
|
||||
|
||||
|
||||
import appeng.api.storage.data.IAEFluidStack;
|
||||
import appeng.api.util.AEColor;
|
||||
import appeng.client.gui.widgets.ITooltip;
|
||||
import appeng.fluids.util.IAEFluidTank;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.widget.Widget;
|
||||
import net.minecraft.client.renderer.texture.AtlasTexture;
|
||||
@@ -33,101 +29,96 @@ import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
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;
|
||||
|
||||
@OnlyIn( Dist.CLIENT )
|
||||
public class GuiFluidTank extends Widget implements ITooltip
|
||||
{
|
||||
private final IAEFluidTank tank;
|
||||
private final int slot;
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public class GuiFluidTank extends Widget implements ITooltip {
|
||||
private final IAEFluidTank tank;
|
||||
private final int slot;
|
||||
|
||||
public GuiFluidTank(IAEFluidTank tank, int slot, int x, int y, int w, int h)
|
||||
{
|
||||
super( x, y, w, h, "" );
|
||||
this.tank = tank;
|
||||
this.slot = slot;
|
||||
}
|
||||
public GuiFluidTank(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();
|
||||
@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 );
|
||||
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();
|
||||
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 );
|
||||
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);
|
||||
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
mc.getTextureManager().bindTexture( AtlasTexture.LOCATION_BLOCKS_TEXTURE );
|
||||
final TextureAtlasSprite sprite = mc.getAtlasSpriteGetter( AtlasTexture.LOCATION_BLOCKS_TEXTURE ).apply( attributes.getStillTexture(fluidStack.getFluidStack()) );
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
mc.getTextureManager().bindTexture(AtlasTexture.LOCATION_BLOCKS_TEXTURE);
|
||||
final TextureAtlasSprite sprite = mc.getAtlasSpriteGetter(AtlasTexture.LOCATION_BLOCKS_TEXTURE)
|
||||
.apply(attributes.getStillTexture(fluidStack.getFluidStack()));
|
||||
|
||||
final int scaledHeight = (int) ( this.height * ( (float) fluidStack.getStackSize() / this.tank.getTankCapacity(this.slot) ) );
|
||||
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 );
|
||||
}
|
||||
}
|
||||
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().getDisplayName( fluid.getFluidStack() ).getFormattedText();
|
||||
String amountToText = fluid.getStackSize() + "mB";
|
||||
@Override
|
||||
public String getMessage() {
|
||||
final IAEFluidStack fluid = this.tank.getFluidInSlot(this.slot);
|
||||
if (fluid != null && fluid.getStackSize() > 0) {
|
||||
String desc = fluid.getFluid().getAttributes().getDisplayName(fluid.getFluidStack()).getFormattedText();
|
||||
String amountToText = fluid.getStackSize() + "mB";
|
||||
|
||||
return desc + "\n" + amountToText;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return desc + "\n" + amountToText;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int xPos()
|
||||
{
|
||||
return this.x - 2;
|
||||
}
|
||||
@Override
|
||||
public int xPos() {
|
||||
return this.x - 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int yPos()
|
||||
{
|
||||
return this.y - 2;
|
||||
}
|
||||
@Override
|
||||
public int yPos() {
|
||||
return this.y - 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWidth()
|
||||
{
|
||||
return this.width + 4;
|
||||
}
|
||||
@Override
|
||||
public int getWidth() {
|
||||
return this.width + 4;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight()
|
||||
{
|
||||
return this.height + 4;
|
||||
}
|
||||
@Override
|
||||
public int getHeight() {
|
||||
return this.height + 4;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVisible()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean isVisible() {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,63 +1,54 @@
|
||||
|
||||
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;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import net.minecraftforge.fml.client.gui.GuiUtils;
|
||||
|
||||
public class GuiOptionalFluidSlot extends GuiFluidSlot {
|
||||
private final IOptionalSlotHost containerBus;
|
||||
private final int groupNum;
|
||||
private final int srcX;
|
||||
private final int srcY;
|
||||
|
||||
public class GuiOptionalFluidSlot extends GuiFluidSlot
|
||||
{
|
||||
private final IOptionalSlotHost containerBus;
|
||||
private final int groupNum;
|
||||
private final int srcX;
|
||||
private final int srcY;
|
||||
public GuiOptionalFluidSlot(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;
|
||||
}
|
||||
|
||||
public GuiOptionalFluidSlot( 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 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 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 );
|
||||
}
|
||||
@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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,22 +18,21 @@
|
||||
|
||||
package appeng.fluids.client.render;
|
||||
|
||||
|
||||
import java.math.RoundingMode;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.DecimalFormatSymbols;
|
||||
|
||||
import appeng.client.render.StackSizeRenderer;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
|
||||
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
|
||||
@@ -41,70 +40,59 @@ import appeng.util.ReadableNumberConverter;
|
||||
* @version rv6
|
||||
* @since rv6
|
||||
*/
|
||||
public class FluidStackSizeRenderer
|
||||
{
|
||||
public class FluidStackSizeRenderer {
|
||||
|
||||
private static final String[] NUMBER_FORMATS = new String[] { "#.000", "#.00", "#.0", "#" };
|
||||
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;
|
||||
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);
|
||||
}
|
||||
}
|
||||
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().useTerminalUseLargeFont() )
|
||||
{
|
||||
return this.getSlimRenderedStacksize( originalSize );
|
||||
}
|
||||
else if( originalSize < 1000 * 1000 && !AEConfig.instance().useTerminalUseLargeFont() )
|
||||
{
|
||||
return this.getWideRenderedStacksize( originalSize );
|
||||
}
|
||||
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().useTerminalUseLargeFont()) {
|
||||
return this.getSlimRenderedStacksize(originalSize);
|
||||
} else if (originalSize < 1000 * 1000 && !AEConfig.instance().useTerminalUseLargeFont()) {
|
||||
return this.getWideRenderedStacksize(originalSize);
|
||||
}
|
||||
|
||||
if( AEConfig.instance().useTerminalUseLargeFont() )
|
||||
{
|
||||
return SLIM_CONVERTER.toSlimReadableForm( originalSize / 1000 );
|
||||
}
|
||||
else
|
||||
{
|
||||
return WIDE_CONVERTER.toWideReadableForm( originalSize / 1000 );
|
||||
}
|
||||
}
|
||||
if (AEConfig.instance().useTerminalUseLargeFont()) {
|
||||
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;
|
||||
private String getSlimRenderedStacksize(final long originalSize) {
|
||||
final int log = 1 + (int) Math.floor(Math.log10(originalSize)) / 2;
|
||||
|
||||
return this.getRenderedFluidStackSize( originalSize, log );
|
||||
}
|
||||
return this.getRenderedFluidStackSize(originalSize, log);
|
||||
}
|
||||
|
||||
private String getWideRenderedStacksize( final long originalSize )
|
||||
{
|
||||
final int log = (int) Math.floor( Math.log10( originalSize ) ) / 2;
|
||||
private String getWideRenderedStacksize(final long originalSize) {
|
||||
final int log = (int) Math.floor(Math.log10(originalSize)) / 2;
|
||||
|
||||
return this.getRenderedFluidStackSize( originalSize, log );
|
||||
}
|
||||
return this.getRenderedFluidStackSize(originalSize, log);
|
||||
}
|
||||
|
||||
private String getRenderedFluidStackSize( final long originalSize, final int log )
|
||||
{
|
||||
final int index = Math.max( 0, Math.min( 3, 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 );
|
||||
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 );
|
||||
}
|
||||
return format.format(originalSize / 1000d);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
|
||||
package appeng.fluids.container;
|
||||
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -22,98 +21,79 @@ import appeng.fluids.util.AEFluidStack;
|
||||
import appeng.fluids.util.IAEFluidTank;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public abstract class ContainerFluidConfigurable extends ContainerUpgradeable implements IFluidSyncContainer {
|
||||
private FluidSyncHelper sync = null;
|
||||
|
||||
public abstract class ContainerFluidConfigurable extends ContainerUpgradeable implements IFluidSyncContainer
|
||||
{
|
||||
private FluidSyncHelper sync = null;
|
||||
public ContainerFluidConfigurable(ContainerType<?> containerType, int id, PlayerInventory ip, IUpgradeableHost te) {
|
||||
super(containerType, id, ip, te);
|
||||
}
|
||||
|
||||
public ContainerFluidConfigurable(ContainerType<?> containerType, int id, PlayerInventory ip, IUpgradeableHost te )
|
||||
{
|
||||
super( containerType, id, ip, te );
|
||||
}
|
||||
public abstract IAEFluidTank getFluidConfigInventory();
|
||||
|
||||
public abstract IAEFluidTank getFluidConfigInventory();
|
||||
private FluidSyncHelper getSyncHelper() {
|
||||
if (this.sync == null) {
|
||||
this.sync = new FluidSyncHelper(this.getFluidConfigInventory(), 0);
|
||||
}
|
||||
return this.sync;
|
||||
}
|
||||
|
||||
private FluidSyncHelper getSyncHelper()
|
||||
{
|
||||
if( this.sync == null )
|
||||
{
|
||||
this.sync = new FluidSyncHelper( this.getFluidConfigInventory(), 0 );
|
||||
}
|
||||
return this.sync;
|
||||
}
|
||||
@Override
|
||||
protected ItemStack transferStackToContainer(ItemStack input) {
|
||||
LazyOptional<FluidStack> 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;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ItemStack transferStackToContainer( ItemStack input )
|
||||
{
|
||||
LazyOptional<FluidStack> 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);
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
if( slot > 0 && upgrades < 1 )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if( slot > 4 && upgrades < 2 )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
protected void standardDetectAndSendChanges() {
|
||||
if (Platform.isServer()) {
|
||||
this.getSyncHelper().sendDiff(this.listeners);
|
||||
|
||||
@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();
|
||||
}
|
||||
|
||||
// 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 addListener( IContainerListener listener )
|
||||
{
|
||||
super.addListener( listener );
|
||||
this.getSyncHelper().sendFull( Collections.singleton( listener ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receiveFluidSlots( Map<Integer, IAEFluidStack> fluids )
|
||||
{
|
||||
this.getSyncHelper().readPacket( fluids );
|
||||
}
|
||||
@Override
|
||||
public void receiveFluidSlots(Map<Integer, IAEFluidStack> fluids) {
|
||||
this.getSyncHelper().readPacket(fluids);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
|
||||
package appeng.fluids.container;
|
||||
|
||||
|
||||
import appeng.container.ContainerLocator;
|
||||
import appeng.container.implementations.ContainerHelper;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.container.ContainerType;
|
||||
@@ -13,110 +10,95 @@ import net.minecraftforge.items.IItemHandler;
|
||||
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.SlotRestrictedInput;
|
||||
import appeng.fluids.parts.PartFluidFormationPlane;
|
||||
import appeng.fluids.util.IAEFluidTank;
|
||||
|
||||
public class ContainerFluidFormationPlane extends ContainerFluidConfigurable {
|
||||
|
||||
public class ContainerFluidFormationPlane extends ContainerFluidConfigurable
|
||||
{
|
||||
public static ContainerType<ContainerFluidFormationPlane> TYPE;
|
||||
|
||||
public static ContainerType<ContainerFluidFormationPlane> TYPE;
|
||||
private static final ContainerHelper<ContainerFluidFormationPlane, PartFluidFormationPlane> helper = new ContainerHelper<>(
|
||||
ContainerFluidFormationPlane::new, PartFluidFormationPlane.class, SecurityPermissions.BUILD);
|
||||
|
||||
private static final ContainerHelper<ContainerFluidFormationPlane, PartFluidFormationPlane> helper
|
||||
= new ContainerHelper<>(ContainerFluidFormationPlane::new, PartFluidFormationPlane.class, SecurityPermissions.BUILD);
|
||||
public static ContainerFluidFormationPlane fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
|
||||
return helper.fromNetwork(windowId, inv, buf);
|
||||
}
|
||||
|
||||
public static ContainerFluidFormationPlane fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
|
||||
return helper.fromNetwork(windowId, inv, buf);
|
||||
}
|
||||
public static boolean open(PlayerEntity player, ContainerLocator locator) {
|
||||
return helper.open(player, locator);
|
||||
}
|
||||
|
||||
public static boolean open(PlayerEntity player, ContainerLocator locator) {
|
||||
return helper.open(player, locator);
|
||||
}
|
||||
private final PartFluidFormationPlane plane;
|
||||
|
||||
private final PartFluidFormationPlane plane;
|
||||
public ContainerFluidFormationPlane(int id, final PlayerInventory ip, final PartFluidFormationPlane te) {
|
||||
super(TYPE, id, ip, te);
|
||||
this.plane = te;
|
||||
}
|
||||
|
||||
public ContainerFluidFormationPlane(int id, final PlayerInventory ip, final PartFluidFormationPlane te )
|
||||
{
|
||||
super( TYPE, id,ip, te );
|
||||
this.plane = te;
|
||||
}
|
||||
@Override
|
||||
protected int getHeight() {
|
||||
return 251;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getHeight()
|
||||
{
|
||||
return 251;
|
||||
}
|
||||
@Override
|
||||
public IAEFluidTank getFluidConfigInventory() {
|
||||
return this.plane.getConfig();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEFluidTank getFluidConfigInventory()
|
||||
{
|
||||
return this.plane.getConfig();
|
||||
}
|
||||
@Override
|
||||
protected void setupConfig() {
|
||||
final IItemHandler upgrades = this.getUpgradeable().getInventoryByName("upgrades");
|
||||
this.addSlot((new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 0, 187, 8,
|
||||
this.getPlayerInventory())).setNotDraggable());
|
||||
this.addSlot((new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 1, 187, 8 + 18,
|
||||
this.getPlayerInventory())).setNotDraggable());
|
||||
this.addSlot((new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 2, 187,
|
||||
8 + 18 * 2, this.getPlayerInventory())).setNotDraggable());
|
||||
this.addSlot((new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 3, 187,
|
||||
8 + 18 * 3, this.getPlayerInventory())).setNotDraggable());
|
||||
this.addSlot((new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 4, 187,
|
||||
8 + 18 * 4, this.getPlayerInventory())).setNotDraggable());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setupConfig()
|
||||
{
|
||||
final IItemHandler upgrades = this.getUpgradeable().getInventoryByName( "upgrades" );
|
||||
this.addSlot( ( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 0, 187, 8, this.getPlayerInventory() ) )
|
||||
.setNotDraggable() );
|
||||
this.addSlot(
|
||||
( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 1, 187, 8 + 18, this.getPlayerInventory() ) )
|
||||
.setNotDraggable() );
|
||||
this.addSlot(
|
||||
( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 2, 187, 8 + 18 * 2, this.getPlayerInventory() ) )
|
||||
.setNotDraggable() );
|
||||
this.addSlot(
|
||||
( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 3, 187, 8 + 18 * 3, this.getPlayerInventory() ) )
|
||||
.setNotDraggable() );
|
||||
this.addSlot(
|
||||
( new SlotRestrictedInput( SlotRestrictedInput.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
|
||||
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);
|
||||
|
||||
@Override
|
||||
protected boolean isValidForConfig( int slot, IAEFluidStack fs )
|
||||
{
|
||||
if( this.supportCapacity() )
|
||||
{
|
||||
final int upgrades = this.getUpgradeable().getInstalledUpgrades( Upgrades.CAPACITY );
|
||||
final int y = slot / 9;
|
||||
|
||||
final int y = slot / 9;
|
||||
if (y >= upgrades + 2) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if( y >= upgrades + 2 )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean isSlotEnabled(final int idx) {
|
||||
final int upgrades = this.getUpgradeable().getInstalledUpgrades(Upgrades.CAPACITY);
|
||||
|
||||
@Override
|
||||
public boolean isSlotEnabled( final int idx )
|
||||
{
|
||||
final int upgrades = this.getUpgradeable().getInstalledUpgrades( Upgrades.CAPACITY );
|
||||
return upgrades > idx;
|
||||
}
|
||||
|
||||
return upgrades > idx;
|
||||
}
|
||||
@Override
|
||||
protected boolean supportCapacity() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean supportCapacity()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int availableUpgrades()
|
||||
{
|
||||
return 5;
|
||||
}
|
||||
@Override
|
||||
public int availableUpgrades() {
|
||||
return 5;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,57 +18,51 @@
|
||||
|
||||
package appeng.fluids.container;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.container.ContainerType;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
|
||||
import appeng.api.config.SecurityPermissions;
|
||||
import appeng.container.ContainerLocator;
|
||||
import appeng.container.implementations.ContainerHelper;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
|
||||
import appeng.fluids.parts.PartSharedFluidBus;
|
||||
import appeng.fluids.util.IAEFluidTank;
|
||||
import net.minecraft.inventory.container.ContainerType;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
|
||||
|
||||
/**
|
||||
* @author BrockWS
|
||||
* @version rv5 - 1/05/2018
|
||||
* @since rv5 1/05/2018
|
||||
*/
|
||||
public class ContainerFluidIO extends ContainerFluidConfigurable
|
||||
{
|
||||
public class ContainerFluidIO extends ContainerFluidConfigurable {
|
||||
|
||||
public static ContainerType<ContainerFluidIO> TYPE;
|
||||
public static ContainerType<ContainerFluidIO> TYPE;
|
||||
|
||||
private static final ContainerHelper<ContainerFluidIO, PartSharedFluidBus> helper
|
||||
= new ContainerHelper<>(ContainerFluidIO::new, PartSharedFluidBus.class, SecurityPermissions.BUILD);
|
||||
private static final ContainerHelper<ContainerFluidIO, PartSharedFluidBus> helper = new ContainerHelper<>(
|
||||
ContainerFluidIO::new, PartSharedFluidBus.class, SecurityPermissions.BUILD);
|
||||
|
||||
public static ContainerFluidIO fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
|
||||
return helper.fromNetwork(windowId, inv, buf);
|
||||
}
|
||||
public static ContainerFluidIO fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
|
||||
return helper.fromNetwork(windowId, inv, buf);
|
||||
}
|
||||
|
||||
public static boolean open(PlayerEntity player, ContainerLocator locator) {
|
||||
return helper.open(player, locator);
|
||||
}
|
||||
public static boolean open(PlayerEntity player, ContainerLocator locator) {
|
||||
return helper.open(player, locator);
|
||||
}
|
||||
|
||||
private final PartSharedFluidBus bus;
|
||||
private final PartSharedFluidBus bus;
|
||||
|
||||
public ContainerFluidIO(int id, PlayerInventory ip, PartSharedFluidBus te )
|
||||
{
|
||||
super( TYPE, id,ip, te );
|
||||
this.bus = te;
|
||||
}
|
||||
public ContainerFluidIO(int id, PlayerInventory ip, PartSharedFluidBus te) {
|
||||
super(TYPE, id, ip, te);
|
||||
this.bus = te;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEFluidTank getFluidConfigInventory()
|
||||
{
|
||||
return this.bus.getConfig();
|
||||
}
|
||||
@Override
|
||||
public IAEFluidTank getFluidConfigInventory() {
|
||||
return this.bus.getConfig();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setupConfig()
|
||||
{
|
||||
this.setupUpgrades();
|
||||
}
|
||||
@Override
|
||||
protected void setupConfig() {
|
||||
this.setupUpgrades();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,14 @@
|
||||
|
||||
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.inventory.container.ContainerType;
|
||||
import net.minecraft.inventory.container.IContainerListener;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
|
||||
import appeng.api.config.SecurityPermissions;
|
||||
import appeng.api.storage.data.IAEFluidStack;
|
||||
@@ -29,111 +37,89 @@ import appeng.fluids.helper.FluidSyncHelper;
|
||||
import appeng.fluids.helper.IFluidInterfaceHost;
|
||||
import appeng.fluids.util.IAEFluidTank;
|
||||
import appeng.util.Platform;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.container.ContainerType;
|
||||
import net.minecraft.inventory.container.IContainerListener;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
public class ContainerFluidInterface extends ContainerFluidConfigurable {
|
||||
|
||||
public static ContainerType<ContainerFluidInterface> TYPE;
|
||||
|
||||
public class ContainerFluidInterface extends ContainerFluidConfigurable
|
||||
{
|
||||
private static final ContainerHelper<ContainerFluidInterface, IFluidInterfaceHost> helper = new ContainerHelper<>(
|
||||
ContainerFluidInterface::new, IFluidInterfaceHost.class, SecurityPermissions.BUILD);
|
||||
|
||||
public static ContainerType<ContainerFluidInterface> TYPE;
|
||||
public static ContainerFluidInterface fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
|
||||
return helper.fromNetwork(windowId, inv, buf);
|
||||
}
|
||||
|
||||
private static final ContainerHelper<ContainerFluidInterface, IFluidInterfaceHost> helper
|
||||
= new ContainerHelper<>(ContainerFluidInterface::new, IFluidInterfaceHost.class, SecurityPermissions.BUILD);
|
||||
public static boolean open(PlayerEntity player, ContainerLocator locator) {
|
||||
return helper.open(player, locator);
|
||||
}
|
||||
|
||||
public static ContainerFluidInterface fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
|
||||
return helper.fromNetwork(windowId, inv, buf);
|
||||
}
|
||||
private final DualityFluidInterface myDuality;
|
||||
private final FluidSyncHelper tankSync;
|
||||
|
||||
public static boolean open(PlayerEntity player, ContainerLocator locator) {
|
||||
return helper.open(player, locator);
|
||||
}
|
||||
public ContainerFluidInterface(int id, final PlayerInventory ip, final IFluidInterfaceHost te) {
|
||||
super(TYPE, id, ip, te.getDualityFluidInterface().getHost());
|
||||
|
||||
private final DualityFluidInterface myDuality;
|
||||
private final FluidSyncHelper tankSync;
|
||||
this.myDuality = te.getDualityFluidInterface();
|
||||
this.tankSync = new FluidSyncHelper(this.myDuality.getTanks(), DualityFluidInterface.NUMBER_OF_TANKS);
|
||||
}
|
||||
|
||||
public ContainerFluidInterface(int id, final PlayerInventory ip, final IFluidInterfaceHost te )
|
||||
{
|
||||
super( TYPE, id,ip, te.getDualityFluidInterface().getHost() );
|
||||
@Override
|
||||
protected int getHeight() {
|
||||
return 231;
|
||||
}
|
||||
|
||||
this.myDuality = te.getDualityFluidInterface();
|
||||
this.tankSync = new FluidSyncHelper( this.myDuality.getTanks(), DualityFluidInterface.NUMBER_OF_TANKS );
|
||||
}
|
||||
public IAEFluidTank getTanks() {
|
||||
return myDuality.getTanks();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getHeight()
|
||||
{
|
||||
return 231;
|
||||
}
|
||||
@Override
|
||||
public IAEFluidTank getFluidConfigInventory() {
|
||||
return this.myDuality.getConfig();
|
||||
}
|
||||
|
||||
public IAEFluidTank getTanks() {
|
||||
return myDuality.getTanks();
|
||||
}
|
||||
@Override
|
||||
public void detectAndSendChanges() {
|
||||
this.verifyPermissions(SecurityPermissions.BUILD, false);
|
||||
|
||||
@Override
|
||||
public IAEFluidTank getFluidConfigInventory()
|
||||
{
|
||||
return this.myDuality.getConfig();
|
||||
}
|
||||
if (Platform.isServer()) {
|
||||
this.tankSync.sendDiff(this.listeners);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detectAndSendChanges()
|
||||
{
|
||||
this.verifyPermissions( SecurityPermissions.BUILD, false );
|
||||
super.detectAndSendChanges();
|
||||
}
|
||||
|
||||
if( Platform.isServer() )
|
||||
{
|
||||
this.tankSync.sendDiff( this.listeners );
|
||||
}
|
||||
@Override
|
||||
protected void setupConfig() {
|
||||
}
|
||||
|
||||
super.detectAndSendChanges();
|
||||
}
|
||||
@Override
|
||||
protected void loadSettingsFromHost(final IConfigManager cm) {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setupConfig()
|
||||
{
|
||||
}
|
||||
@Override
|
||||
public void addListener(IContainerListener listener) {
|
||||
super.addListener(listener);
|
||||
this.tankSync.sendFull(Collections.singleton(listener));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadSettingsFromHost( final IConfigManager cm )
|
||||
{
|
||||
}
|
||||
@Override
|
||||
public void receiveFluidSlots(Map<Integer, IAEFluidStack> fluids) {
|
||||
super.receiveFluidSlots(fluids);
|
||||
this.tankSync.readPacket(fluids);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addListener( IContainerListener listener )
|
||||
{
|
||||
super.addListener( listener );
|
||||
this.tankSync.sendFull( Collections.singleton( listener ) );
|
||||
}
|
||||
@Override
|
||||
protected boolean supportCapacity() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receiveFluidSlots( Map<Integer, IAEFluidStack> fluids )
|
||||
{
|
||||
super.receiveFluidSlots( fluids );
|
||||
this.tankSync.readPacket( fluids );
|
||||
}
|
||||
@Override
|
||||
public int availableUpgrades() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean supportCapacity()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int availableUpgrades()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasToolbox()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean hasToolbox() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
package appeng.fluids.container;
|
||||
|
||||
|
||||
import appeng.container.ContainerLocator;
|
||||
import appeng.container.implementations.ContainerHelper;
|
||||
import net.minecraft.client.gui.widget.TextFieldWidget;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
@@ -14,100 +11,89 @@ import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
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.PartFluidLevelEmitter;
|
||||
import appeng.fluids.util.IAEFluidTank;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public class ContainerFluidLevelEmitter extends ContainerFluidConfigurable {
|
||||
public static ContainerType<ContainerFluidLevelEmitter> TYPE;
|
||||
|
||||
public class ContainerFluidLevelEmitter extends ContainerFluidConfigurable
|
||||
{
|
||||
public static ContainerType<ContainerFluidLevelEmitter> TYPE;
|
||||
private static final ContainerHelper<ContainerFluidLevelEmitter, PartFluidLevelEmitter> helper = new ContainerHelper<>(
|
||||
ContainerFluidLevelEmitter::new, PartFluidLevelEmitter.class, SecurityPermissions.BUILD);
|
||||
|
||||
private static final ContainerHelper<ContainerFluidLevelEmitter, PartFluidLevelEmitter> helper
|
||||
= new ContainerHelper<>(ContainerFluidLevelEmitter::new, PartFluidLevelEmitter.class, SecurityPermissions.BUILD);
|
||||
public static ContainerFluidLevelEmitter fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
|
||||
return helper.fromNetwork(windowId, inv, buf);
|
||||
}
|
||||
|
||||
public static ContainerFluidLevelEmitter fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
|
||||
return helper.fromNetwork(windowId, inv, buf);
|
||||
}
|
||||
public static boolean open(PlayerEntity player, ContainerLocator locator) {
|
||||
return helper.open(player, locator);
|
||||
}
|
||||
|
||||
public static boolean open(PlayerEntity player, ContainerLocator locator) {
|
||||
return helper.open(player, locator);
|
||||
}
|
||||
private final PartFluidLevelEmitter lvlEmitter;
|
||||
|
||||
private final PartFluidLevelEmitter lvlEmitter;
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
private TextFieldWidget textField;
|
||||
@GuiSync(3)
|
||||
public long EmitterValue = -1;
|
||||
|
||||
@OnlyIn( Dist.CLIENT )
|
||||
private TextFieldWidget textField;
|
||||
@GuiSync( 3 )
|
||||
public long EmitterValue = -1;
|
||||
public ContainerFluidLevelEmitter(int id, final PlayerInventory ip, final PartFluidLevelEmitter te) {
|
||||
super(TYPE, id, ip, te);
|
||||
this.lvlEmitter = te;
|
||||
}
|
||||
|
||||
public ContainerFluidLevelEmitter(int id, final PlayerInventory ip, final PartFluidLevelEmitter te )
|
||||
{
|
||||
super( TYPE, id,ip, te );
|
||||
this.lvlEmitter = te;
|
||||
}
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public void setTextField(final TextFieldWidget level) {
|
||||
this.textField = level;
|
||||
this.textField.setText(String.valueOf(this.EmitterValue));
|
||||
}
|
||||
|
||||
@OnlyIn( Dist.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;
|
||||
}
|
||||
|
||||
public void setLevel( final long l, final PlayerEntity player )
|
||||
{
|
||||
this.lvlEmitter.setReportingValue( l );
|
||||
this.EmitterValue = l;
|
||||
}
|
||||
@Override
|
||||
protected void setupConfig() {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setupConfig()
|
||||
{
|
||||
}
|
||||
@Override
|
||||
protected boolean supportCapacity() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean supportCapacity()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public int availableUpgrades() {
|
||||
|
||||
@Override
|
||||
public int availableUpgrades()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@Override
|
||||
public void detectAndSendChanges() {
|
||||
this.verifyPermissions(SecurityPermissions.BUILD, false);
|
||||
|
||||
@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));
|
||||
}
|
||||
|
||||
if( Platform.isServer() )
|
||||
{
|
||||
this.EmitterValue = this.lvlEmitter.getReportingValue();
|
||||
this.setRedStoneMode( (RedstoneMode) this.getUpgradeable().getConfigManager().getSetting( Settings.REDSTONE_EMITTER ) );
|
||||
}
|
||||
this.standardDetectAndSendChanges();
|
||||
}
|
||||
|
||||
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 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();
|
||||
}
|
||||
@Override
|
||||
public IAEFluidTank getFluidConfigInventory() {
|
||||
return this.lvlEmitter.getConfig();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,228 +1,199 @@
|
||||
/*
|
||||
* 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 appeng.container.ContainerLocator;
|
||||
import appeng.container.implementations.ContainerHelper;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.container.ContainerType;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
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.guisync.GuiSync;
|
||||
import appeng.container.slot.SlotRestrictedInput;
|
||||
import appeng.fluids.parts.PartFluidStorageBus;
|
||||
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 ContainerFluidStorageBus extends ContainerFluidConfigurable
|
||||
{
|
||||
|
||||
public static ContainerType<ContainerFluidStorageBus> TYPE;
|
||||
|
||||
private static final ContainerHelper<ContainerFluidStorageBus, PartFluidStorageBus> helper
|
||||
= new ContainerHelper<>(ContainerFluidStorageBus::new, PartFluidStorageBus.class);
|
||||
|
||||
public static ContainerFluidStorageBus fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
|
||||
return helper.fromNetwork(windowId, inv, buf);
|
||||
}
|
||||
|
||||
public static boolean open(PlayerEntity player, ContainerLocator locator) {
|
||||
return helper.open(player, locator);
|
||||
}
|
||||
|
||||
private final PartFluidStorageBus storageBus;
|
||||
|
||||
@GuiSync( 3 )
|
||||
public AccessRestriction rwMode = AccessRestriction.READ_WRITE;
|
||||
|
||||
@GuiSync( 4 )
|
||||
public StorageFilter storageFilter = StorageFilter.EXTRACTABLE_ONLY;
|
||||
|
||||
public ContainerFluidStorageBus(int id, PlayerInventory ip, PartFluidStorageBus te )
|
||||
{
|
||||
super( TYPE, id,ip, te );
|
||||
this.storageBus = te;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getHeight()
|
||||
{
|
||||
return 251;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setupConfig()
|
||||
{
|
||||
final IItemHandler upgrades = this.getUpgradeable().getInventoryByName( "upgrades" );
|
||||
this.addSlot( ( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 0, 187, 8, this.getPlayerInventory() ) )
|
||||
.setNotDraggable() );
|
||||
this.addSlot(
|
||||
( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 1, 187, 8 + 18, this.getPlayerInventory() ) )
|
||||
.setNotDraggable() );
|
||||
this.addSlot(
|
||||
( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 2, 187, 8 + 18 * 2, this.getPlayerInventory() ) )
|
||||
.setNotDraggable() );
|
||||
this.addSlot(
|
||||
( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 3, 187, 8 + 18 * 3, this.getPlayerInventory() ) )
|
||||
.setNotDraggable() );
|
||||
this.addSlot(
|
||||
( new SlotRestrictedInput( SlotRestrictedInput.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();
|
||||
}
|
||||
}
|
||||
/*
|
||||
* 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.inventory.container.ContainerType;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
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.SlotRestrictedInput;
|
||||
import appeng.fluids.parts.PartFluidStorageBus;
|
||||
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 ContainerFluidStorageBus extends ContainerFluidConfigurable {
|
||||
|
||||
public static ContainerType<ContainerFluidStorageBus> TYPE;
|
||||
|
||||
private static final ContainerHelper<ContainerFluidStorageBus, PartFluidStorageBus> helper = new ContainerHelper<>(
|
||||
ContainerFluidStorageBus::new, PartFluidStorageBus.class);
|
||||
|
||||
public static ContainerFluidStorageBus fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
|
||||
return helper.fromNetwork(windowId, inv, buf);
|
||||
}
|
||||
|
||||
public static boolean open(PlayerEntity player, ContainerLocator locator) {
|
||||
return helper.open(player, locator);
|
||||
}
|
||||
|
||||
private final PartFluidStorageBus storageBus;
|
||||
|
||||
@GuiSync(3)
|
||||
public AccessRestriction rwMode = AccessRestriction.READ_WRITE;
|
||||
|
||||
@GuiSync(4)
|
||||
public StorageFilter storageFilter = StorageFilter.EXTRACTABLE_ONLY;
|
||||
|
||||
public ContainerFluidStorageBus(int id, PlayerInventory ip, PartFluidStorageBus te) {
|
||||
super(TYPE, id, ip, te);
|
||||
this.storageBus = te;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getHeight() {
|
||||
return 251;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setupConfig() {
|
||||
final IItemHandler upgrades = this.getUpgradeable().getInventoryByName("upgrades");
|
||||
this.addSlot((new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 0, 187, 8,
|
||||
this.getPlayerInventory())).setNotDraggable());
|
||||
this.addSlot((new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 1, 187, 8 + 18,
|
||||
this.getPlayerInventory())).setNotDraggable());
|
||||
this.addSlot((new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 2, 187,
|
||||
8 + 18 * 2, this.getPlayerInventory())).setNotDraggable());
|
||||
this.addSlot((new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 3, 187,
|
||||
8 + 18 * 3, this.getPlayerInventory())).setNotDraggable());
|
||||
this.addSlot((new SlotRestrictedInput(SlotRestrictedInput.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,504 +1,429 @@
|
||||
/*
|
||||
* 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 appeng.api.AEApi;
|
||||
import appeng.api.config.*;
|
||||
import appeng.container.ContainerLocator;
|
||||
import appeng.container.implementations.ContainerHelper;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||
import net.minecraft.inventory.container.ContainerType;
|
||||
import net.minecraft.inventory.container.IContainerListener;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraftforge.common.util.LazyOptional;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.FluidUtil;
|
||||
import net.minecraftforge.fluids.capability.IFluidHandler.FluidAction;
|
||||
import net.minecraftforge.fluids.capability.IFluidHandlerItem;
|
||||
|
||||
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.guisync.GuiSync;
|
||||
import appeng.core.AELog;
|
||||
import appeng.core.sync.network.NetworkHandler;
|
||||
import appeng.core.sync.packets.PacketMEFluidInventoryUpdate;
|
||||
import appeng.core.sync.packets.PacketTargetFluidStack;
|
||||
import appeng.core.sync.packets.PacketValueConfig;
|
||||
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 ContainerFluidTerminal extends AEBaseContainer implements IConfigManagerHost, IConfigurableObject, IMEMonitorHandlerReceiver<IAEFluidStack>
|
||||
{
|
||||
|
||||
public static ContainerType<ContainerFluidTerminal> TYPE;
|
||||
|
||||
private static final ContainerHelper<ContainerFluidTerminal, ITerminalHost> helper
|
||||
= new ContainerHelper<>(ContainerFluidTerminal::new, ITerminalHost.class, SecurityPermissions.BUILD);
|
||||
|
||||
public static ContainerFluidTerminal fromNetwork(int windowId, PlayerInventory inv, PacketBuffer 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 ContainerFluidTerminal(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
|
||||
{
|
||||
PacketMEFluidInventoryUpdate piu = new PacketMEFluidInventoryUpdate();
|
||||
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 PacketMEFluidInventoryUpdate();
|
||||
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 PacketTargetFluidStack( (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 PacketValueConfig( set.name(), sideLocal.name() ), (ServerPlayerEntity) crafter );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( !this.fluids.isEmpty() )
|
||||
{
|
||||
try
|
||||
{
|
||||
final IItemList<IAEFluidStack> monitorCache = this.monitor.getStorageList();
|
||||
|
||||
final PacketMEFluidInventoryUpdate piu = new PacketMEFluidInventoryUpdate();
|
||||
|
||||
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.getDisplayName() );
|
||||
}
|
||||
|
||||
player.inventory.setItemStack( fh.getContainer() );
|
||||
this.updateHeld( player );
|
||||
}
|
||||
else if( action == InventoryAction.EMPTY_ITEM )
|
||||
{
|
||||
// See how much we can drain from the item
|
||||
final FluidStack extract = fh.drain( Integer.MAX_VALUE, FluidAction.SIMULATE );
|
||||
if( extract == null || 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 FluidStack storable = fh.drain( toStore, FluidAction.SIMULATE );
|
||||
|
||||
if( storable == null || storable.getAmount() == 0 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
extract.setAmount( storable.getAmount() );
|
||||
}
|
||||
}
|
||||
|
||||
// Actually drain
|
||||
final FluidStack 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.getDisplayName() );
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* 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 net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||
import net.minecraft.inventory.container.ContainerType;
|
||||
import net.minecraft.inventory.container.IContainerListener;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraftforge.common.util.LazyOptional;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
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.*;
|
||||
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.PacketMEFluidInventoryUpdate;
|
||||
import appeng.core.sync.packets.PacketTargetFluidStack;
|
||||
import appeng.core.sync.packets.PacketValueConfig;
|
||||
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 ContainerFluidTerminal extends AEBaseContainer
|
||||
implements IConfigManagerHost, IConfigurableObject, IMEMonitorHandlerReceiver<IAEFluidStack> {
|
||||
|
||||
public static ContainerType<ContainerFluidTerminal> TYPE;
|
||||
|
||||
private static final ContainerHelper<ContainerFluidTerminal, ITerminalHost> helper = new ContainerHelper<>(
|
||||
ContainerFluidTerminal::new, ITerminalHost.class, SecurityPermissions.BUILD);
|
||||
|
||||
public static ContainerFluidTerminal fromNetwork(int windowId, PlayerInventory inv, PacketBuffer 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 ContainerFluidTerminal(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 {
|
||||
PacketMEFluidInventoryUpdate piu = new PacketMEFluidInventoryUpdate();
|
||||
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 PacketMEFluidInventoryUpdate();
|
||||
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 PacketTargetFluidStack((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 PacketValueConfig(set.name(), sideLocal.name()),
|
||||
(ServerPlayerEntity) crafter);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!this.fluids.isEmpty()) {
|
||||
try {
|
||||
final IItemList<IAEFluidStack> monitorCache = this.monitor.getStorageList();
|
||||
|
||||
final PacketMEFluidInventoryUpdate piu = new PacketMEFluidInventoryUpdate();
|
||||
|
||||
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.getDisplayName());
|
||||
}
|
||||
|
||||
player.inventory.setItemStack(fh.getContainer());
|
||||
this.updateHeld(player);
|
||||
} else if (action == InventoryAction.EMPTY_ITEM) {
|
||||
// See how much we can drain from the item
|
||||
final FluidStack extract = fh.drain(Integer.MAX_VALUE, FluidAction.SIMULATE);
|
||||
if (extract == null || 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 FluidStack storable = fh.drain(toStore, FluidAction.SIMULATE);
|
||||
|
||||
if (storable == null || storable.getAmount() == 0) {
|
||||
return;
|
||||
} else {
|
||||
extract.setAmount(storable.getAmount());
|
||||
}
|
||||
}
|
||||
|
||||
// Actually drain
|
||||
final FluidStack 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.getDisplayName());
|
||||
}
|
||||
|
||||
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,13 +1,10 @@
|
||||
|
||||
package appeng.fluids.container;
|
||||
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import appeng.api.storage.data.IAEFluidStack;
|
||||
|
||||
|
||||
public interface IFluidSyncContainer
|
||||
{
|
||||
void receiveFluidSlots( final Map<Integer, IAEFluidStack> fluids );
|
||||
public interface IFluidSyncContainer {
|
||||
void receiveFluidSlots(final Map<Integer, IAEFluidStack> fluids);
|
||||
}
|
||||
|
||||
@@ -18,21 +18,17 @@
|
||||
|
||||
package appeng.fluids.container.slots;
|
||||
|
||||
|
||||
import appeng.api.storage.data.IAEFluidStack;
|
||||
|
||||
|
||||
/**
|
||||
* @author yueh
|
||||
* @version rv6
|
||||
* @since rv6
|
||||
*/
|
||||
public interface IMEFluidSlot
|
||||
{
|
||||
IAEFluidStack getAEFluidStack();
|
||||
public interface IMEFluidSlot {
|
||||
IAEFluidStack getAEFluidStack();
|
||||
|
||||
default boolean shouldRenderAsFluid()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
default boolean shouldRenderAsFluid() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -18,11 +18,10 @@
|
||||
|
||||
package appeng.fluids.helper;
|
||||
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.fluid.Fluid;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.common.util.LazyOptional;
|
||||
import net.minecraftforge.fluids.FluidAttributes;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
@@ -32,81 +31,72 @@ 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 );
|
||||
}
|
||||
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<FluidStack> fluidOpt = FluidUtil.getFluidContained( stack );
|
||||
if( !fluidOpt.isPresent() || !AEApi.instance().definitions().items().dummyFluidItem().maybeStack( 1 ).isPresent() )
|
||||
{
|
||||
return stack;
|
||||
}
|
||||
FluidStack fluid = fluidOpt.orElse( null );
|
||||
@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<FluidStack> fluidOpt = FluidUtil.getFluidContained(stack);
|
||||
if (!fluidOpt.isPresent()
|
||||
|| !AEApi.instance().definitions().items().dummyFluidItem().maybeStack(1).isPresent()) {
|
||||
return stack;
|
||||
}
|
||||
FluidStack 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 );
|
||||
}
|
||||
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.setStackInSlot( slot, stack );
|
||||
}
|
||||
LazyOptional<FluidStack> fluidOpt = FluidUtil.getFluidContained( stack );
|
||||
if( !fluidOpt.isPresent() || !AEApi.instance().definitions().items().dummyFluidItem().maybeStack( 1 ).isPresent() )
|
||||
{
|
||||
return;
|
||||
}
|
||||
FluidStack fluid = fluidOpt.orElse( null );
|
||||
@Override
|
||||
public void setStackInSlot(int slot, @Nonnull ItemStack stack) {
|
||||
if (stack.isEmpty() || stack.getItem() instanceof FluidDummyItem) {
|
||||
super.setStackInSlot(slot, stack);
|
||||
}
|
||||
LazyOptional<FluidStack> fluidOpt = FluidUtil.getFluidContained(stack);
|
||||
if (!fluidOpt.isPresent()
|
||||
|| !AEApi.instance().definitions().items().dummyFluidItem().maybeStack(1).isPresent()) {
|
||||
return;
|
||||
}
|
||||
FluidStack 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.setStackInSlot( slot, is );
|
||||
}
|
||||
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.setStackInSlot(slot, is);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValid( int slot, ItemStack stack )
|
||||
{
|
||||
if( stack.isEmpty() || stack.getItem() instanceof FluidDummyItem )
|
||||
{
|
||||
super.isItemValid( slot, stack );
|
||||
}
|
||||
LazyOptional<FluidStack> fluidOpt = FluidUtil.getFluidContained( stack );
|
||||
if( !fluidOpt.isPresent() || !AEApi.instance().definitions().items().dummyFluidItem().maybeStack( 1 ).isPresent() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
FluidStack fluid = fluidOpt.orElse( null );
|
||||
@Override
|
||||
public boolean isItemValid(int slot, ItemStack stack) {
|
||||
if (stack.isEmpty() || stack.getItem() instanceof FluidDummyItem) {
|
||||
super.isItemValid(slot, stack);
|
||||
}
|
||||
LazyOptional<FluidStack> fluidOpt = FluidUtil.getFluidContained(stack);
|
||||
if (!fluidOpt.isPresent()
|
||||
|| !AEApi.instance().definitions().items().dummyFluidItem().maybeStack(1).isPresent()) {
|
||||
return false;
|
||||
}
|
||||
FluidStack 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 );
|
||||
}
|
||||
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,7 +1,6 @@
|
||||
|
||||
package appeng.fluids.helper;
|
||||
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
@@ -15,84 +14,66 @@ import appeng.core.sync.packets.PacketFluidSlot;
|
||||
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 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 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 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 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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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 PacketFluidSlot(data), (ServerPlayerEntity) l);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for( final IContainerListener l : listeners )
|
||||
{
|
||||
if( l instanceof ServerPlayerEntity )
|
||||
{
|
||||
NetworkHandler.instance().sendTo( new PacketFluidSlot( 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 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);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
if( !Objects.equals( stackA, stackB ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return stackA == null || stackA.getStackSize() == stackB.getStackSize();
|
||||
}
|
||||
return stackA == null || stackA.getStackSize() == stackB.getStackSize();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.fluids.helper;
|
||||
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
@@ -28,14 +27,12 @@ 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();
|
||||
|
||||
public interface IFluidInterfaceHost extends IActionHost, IGridProxyable, IUpgradeableHost
|
||||
{
|
||||
DualityFluidInterface getDualityFluidInterface();
|
||||
EnumSet<Direction> getTargets();
|
||||
|
||||
EnumSet<Direction> getTargets();
|
||||
TileEntity getTileEntity();
|
||||
|
||||
TileEntity getTileEntity();
|
||||
|
||||
void saveChanges();
|
||||
void saveChanges();
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.fluids.items;
|
||||
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
@@ -32,86 +31,74 @@ 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>
|
||||
{
|
||||
public final class BasicFluidStorageCell extends AbstractStorageCell<IAEFluidStack> {
|
||||
|
||||
private final int perType;
|
||||
private final double idleDrain;
|
||||
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;
|
||||
}
|
||||
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 int getBytesPerType(ItemStack cellItem) {
|
||||
return this.perType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getIdleDrain()
|
||||
{
|
||||
return this.idleDrain;
|
||||
}
|
||||
@Override
|
||||
public double getIdleDrain() {
|
||||
return this.idleDrain;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IStorageChannel<IAEFluidStack> getChannel()
|
||||
{
|
||||
return AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class );
|
||||
}
|
||||
@Override
|
||||
public IStorageChannel<IAEFluidStack> getChannel() {
|
||||
return AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTotalTypes( final ItemStack cellItem )
|
||||
{
|
||||
return 5;
|
||||
}
|
||||
@Override
|
||||
public int getTotalTypes(final ItemStack cellItem) {
|
||||
return 5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemHandler getConfigInventory( final ItemStack is )
|
||||
{
|
||||
return new FluidCellConfig( is );
|
||||
}
|
||||
@Override
|
||||
public IItemHandler 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 );
|
||||
}
|
||||
} );
|
||||
}
|
||||
@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);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.fluids.items;
|
||||
|
||||
|
||||
import net.minecraft.fluid.Fluids;
|
||||
import net.minecraft.item.ItemGroup;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -29,7 +28,6 @@ import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
import appeng.items.AEBaseItem;
|
||||
|
||||
|
||||
/**
|
||||
* Dummy item to display the fluid Icon
|
||||
*
|
||||
@@ -37,49 +35,41 @@ import appeng.items.AEBaseItem;
|
||||
* @version rv6 - 2018-01-22
|
||||
* @since rv6 2018-01-22
|
||||
*/
|
||||
public class FluidDummyItem extends AEBaseItem
|
||||
{
|
||||
public class FluidDummyItem extends AEBaseItem {
|
||||
|
||||
public FluidDummyItem(Properties properties) {
|
||||
super(properties);
|
||||
}
|
||||
public FluidDummyItem(Properties properties) {
|
||||
super(properties);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTranslationKey(ItemStack stack) {
|
||||
FluidStack fluidStack = this.getFluidStack( stack );
|
||||
if( fluidStack == null )
|
||||
{
|
||||
fluidStack = new FluidStack( Fluids.WATER, FluidAttributes.BUCKET_VOLUME );
|
||||
}
|
||||
return fluidStack.getTranslationKey();
|
||||
}
|
||||
@Override
|
||||
public String getTranslationKey(ItemStack stack) {
|
||||
FluidStack fluidStack = this.getFluidStack(stack);
|
||||
if (fluidStack == null) {
|
||||
fluidStack = new FluidStack(Fluids.WATER, FluidAttributes.BUCKET_VOLUME);
|
||||
}
|
||||
return fluidStack.getTranslationKey();
|
||||
}
|
||||
|
||||
public FluidStack getFluidStack( ItemStack is )
|
||||
{
|
||||
if( is.hasTag() )
|
||||
{
|
||||
CompoundNBT tag = is.getTag();
|
||||
return FluidStack.loadFluidStackFromNBT( tag );
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public FluidStack getFluidStack(ItemStack is) {
|
||||
if (is.hasTag()) {
|
||||
CompoundNBT tag = is.getTag();
|
||||
return FluidStack.loadFluidStackFromNBT(tag);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setFluidStack( ItemStack is, FluidStack fs )
|
||||
{
|
||||
if( fs == null )
|
||||
{
|
||||
is.setTag( null );
|
||||
}
|
||||
else
|
||||
{
|
||||
CompoundNBT tag = new CompoundNBT();
|
||||
fs.writeToNBT( tag );
|
||||
is.setTag( tag );
|
||||
}
|
||||
}
|
||||
public void setFluidStack(ItemStack is, FluidStack fs) {
|
||||
if (fs == null) {
|
||||
is.setTag(null);
|
||||
} else {
|
||||
CompoundNBT tag = new CompoundNBT();
|
||||
fs.writeToNBT(tag);
|
||||
is.setTag(tag);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fillItemGroup(ItemGroup group, NonNullList<ItemStack> items) {
|
||||
// Don't show this item in CreativeTabs
|
||||
}
|
||||
@Override
|
||||
public void fillItemGroup(ItemGroup group, NonNullList<ItemStack> items) {
|
||||
// Don't show this item in CreativeTabs
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,21 +18,18 @@
|
||||
|
||||
package appeng.fluids.items;
|
||||
|
||||
|
||||
import appeng.bootstrap.IItemRendering;
|
||||
import appeng.bootstrap.ItemRenderingCustomizer;
|
||||
|
||||
|
||||
/**
|
||||
* @author DrummerMC
|
||||
* @version rv6 - 2018-01-22
|
||||
* @since rv6 2018-01-22
|
||||
*/
|
||||
public class FluidDummyItemRendering extends ItemRenderingCustomizer
|
||||
{
|
||||
@Override
|
||||
public void customize( IItemRendering rendering )
|
||||
{
|
||||
// FIXME rendering.builtInModel( "models/item/dummy_fluid_item", new DummyFluidItemModel() );
|
||||
}
|
||||
public class FluidDummyItemRendering extends ItemRenderingCustomizer {
|
||||
@Override
|
||||
public void customize(IItemRendering rendering) {
|
||||
// FIXME rendering.builtInModel( "models/item/dummy_fluid_item", new
|
||||
// DummyFluidItemModel() );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.fluids.parts;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
@@ -45,253 +44,213 @@ 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.
|
||||
* 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;
|
||||
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 );
|
||||
}
|
||||
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 )
|
||||
{
|
||||
FluidStack fluidStack = input.getFluidStack();
|
||||
@Override
|
||||
public IAEFluidStack injectItems(IAEFluidStack input, Actionable type, IActionSource src) {
|
||||
FluidStack 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;
|
||||
}
|
||||
// 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
|
||||
}
|
||||
}
|
||||
if (type == Actionable.MODULATE) {
|
||||
try {
|
||||
this.proxyable.getProxy().getTick().alertDevice(this.proxyable.getProxy().getNode());
|
||||
} catch (GridAccessException ignore) {
|
||||
// meh
|
||||
}
|
||||
}
|
||||
|
||||
fluidStack.setAmount( remaining );
|
||||
fluidStack.setAmount(remaining);
|
||||
|
||||
return AEFluidStack.fromFluidStack( fluidStack );
|
||||
}
|
||||
return AEFluidStack.fromFluidStack(fluidStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEFluidStack extractItems( IAEFluidStack request, Actionable mode, IActionSource src )
|
||||
{
|
||||
FluidStack requestedFluidStack = request.getFluidStack();
|
||||
@Override
|
||||
public IAEFluidStack extractItems(IAEFluidStack request, Actionable mode, IActionSource src) {
|
||||
FluidStack requestedFluidStack = request.getFluidStack();
|
||||
|
||||
// Drain the fluid from the tank
|
||||
FluidStack gathered = this.fluidHandler.drain( requestedFluidStack, mode.getFluidAction() );
|
||||
if( gathered == null )
|
||||
{
|
||||
// If nothing was pulled from the tank, return null
|
||||
return null;
|
||||
}
|
||||
// Drain the fluid from the tank
|
||||
FluidStack gathered = this.fluidHandler.drain(requestedFluidStack, mode.getFluidAction());
|
||||
if (gathered == null) {
|
||||
// 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 );
|
||||
}
|
||||
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 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 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 IStorageChannel<IAEFluidStack> getChannel() {
|
||||
return AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setActionSource( IActionSource source )
|
||||
{
|
||||
this.source = source;
|
||||
}
|
||||
@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 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 );
|
||||
}
|
||||
@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 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;
|
||||
private static class InventoryCache {
|
||||
private IAEFluidStack[] cachedAeStacks = new IAEFluidStack[0];
|
||||
private final IFluidHandler fluidHandler;
|
||||
|
||||
public InventoryCache( IFluidHandler fluidHandler )
|
||||
{
|
||||
this.fluidHandler = fluidHandler;
|
||||
}
|
||||
public InventoryCache(IFluidHandler fluidHandler) {
|
||||
this.fluidHandler = fluidHandler;
|
||||
}
|
||||
|
||||
public List<IAEFluidStack> update()
|
||||
{
|
||||
final List<IAEFluidStack> changes = new ArrayList<>();
|
||||
final int slots = fluidHandler.getTanks();
|
||||
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 );
|
||||
}
|
||||
// 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 FluidStack newFS = fluidHandler.getFluidInTank( slot );
|
||||
for (int slot = 0; slot < slots; slot++) {
|
||||
// Save the old stuff
|
||||
final IAEFluidStack oldAEFS = this.cachedAeStacks[slot];
|
||||
final FluidStack newFS = fluidHandler.getFluidInTank(slot);
|
||||
|
||||
this.handlePossibleSlotChanges( slot, oldAEFS, newFS, changes );
|
||||
}
|
||||
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];
|
||||
// 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 );
|
||||
}
|
||||
}
|
||||
if (aeStack != null) {
|
||||
final IAEFluidStack a = aeStack.copy();
|
||||
a.setStackSize(-a.getStackSize());
|
||||
changes.add(a);
|
||||
}
|
||||
}
|
||||
|
||||
this.cachedAeStacks = Arrays.copyOf( this.cachedAeStacks, slots );
|
||||
}
|
||||
return changes;
|
||||
}
|
||||
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;
|
||||
}
|
||||
public IItemList<IAEFluidStack> getAvailableItems(IItemList<IAEFluidStack> out) {
|
||||
Arrays.stream(this.cachedAeStacks).forEach(out::add);
|
||||
return out;
|
||||
}
|
||||
|
||||
private void handlePossibleSlotChanges( int slot, IAEFluidStack oldAeFS, FluidStack 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 handlePossibleSlotChanges(int slot, IAEFluidStack oldAeFS, FluidStack 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, FluidStack newFS, List<IAEFluidStack> changes )
|
||||
{
|
||||
// Still the same fluid, but amount might have changed
|
||||
final long diff = newFS.getAmount() - oldAeFS.getStackSize();
|
||||
private void handleStackSizeChanged(int slot, IAEFluidStack oldAeFS, FluidStack 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() );
|
||||
if (diff != 0) {
|
||||
final IAEFluidStack stack = oldAeFS.copy();
|
||||
stack.setStackSize(newFS.getAmount());
|
||||
|
||||
this.cachedAeStacks[slot] = stack;
|
||||
this.cachedAeStacks[slot] = stack;
|
||||
|
||||
final IAEFluidStack a = stack.copy();
|
||||
a.setStackSize( diff );
|
||||
changes.add( a );
|
||||
}
|
||||
}
|
||||
final IAEFluidStack a = stack.copy();
|
||||
a.setStackSize(diff);
|
||||
changes.add(a);
|
||||
}
|
||||
}
|
||||
|
||||
private void handleFluidChanged( int slot, IAEFluidStack oldAeFS, FluidStack newFS, List<IAEFluidStack> changes )
|
||||
{
|
||||
// Completely different fluid
|
||||
this.cachedAeStacks[slot] = AEFluidStack.fromFluidStack( newFS );
|
||||
private void handleFluidChanged(int slot, IAEFluidStack oldAeFS, FluidStack 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 );
|
||||
}
|
||||
// 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] );
|
||||
}
|
||||
}
|
||||
}
|
||||
// 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,10 +1,10 @@
|
||||
|
||||
package appeng.fluids.parts;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import appeng.parts.automation.PlaneModelData;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import net.minecraft.advancements.CriteriaTriggers;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
@@ -63,289 +63,255 @@ import appeng.me.GridAccessException;
|
||||
import appeng.me.helpers.MachineSource;
|
||||
import appeng.parts.PartBasicState;
|
||||
import appeng.parts.automation.PlaneConnections;
|
||||
import appeng.parts.automation.PlaneModelData;
|
||||
import appeng.parts.automation.PlaneModels;
|
||||
import appeng.util.Platform;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
public class PartFluidAnnihilationPlane extends PartBasicState implements IGridTickable {
|
||||
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();
|
||||
}
|
||||
|
||||
public class PartFluidAnnihilationPlane extends PartBasicState implements IGridTickable
|
||||
{
|
||||
private static final PlaneModels MODELS = new PlaneModels( "part/fluid_annihilation_plane", "part/fluid_annihilation_plane_on" );
|
||||
private final IActionSource mySrc = new MachineSource(this);
|
||||
|
||||
@PartModels
|
||||
public static List<IPartModel> getModels()
|
||||
{
|
||||
return MODELS.getModels();
|
||||
}
|
||||
public PartFluidAnnihilationPlane(final ItemStack is) {
|
||||
super(is);
|
||||
}
|
||||
|
||||
private final IActionSource mySrc = new MachineSource( this );
|
||||
@Override
|
||||
public void getBoxes(final IPartCollisionHelper bch) {
|
||||
int minX = 1;
|
||||
int minY = 1;
|
||||
int maxX = 15;
|
||||
int maxY = 15;
|
||||
|
||||
public PartFluidAnnihilationPlane( final ItemStack is )
|
||||
{
|
||||
super( is );
|
||||
}
|
||||
final IPartHost host = this.getHost();
|
||||
if (host != null) {
|
||||
final TileEntity te = host.getTile();
|
||||
|
||||
@Override
|
||||
public void getBoxes( final IPartCollisionHelper bch )
|
||||
{
|
||||
int minX = 1;
|
||||
int minY = 1;
|
||||
int maxX = 15;
|
||||
int maxY = 15;
|
||||
final BlockPos pos = te.getPos();
|
||||
|
||||
final IPartHost host = this.getHost();
|
||||
if( host != null )
|
||||
{
|
||||
final TileEntity te = host.getTile();
|
||||
final Direction e = bch.getWorldX();
|
||||
final Direction u = bch.getWorldY();
|
||||
|
||||
final BlockPos pos = te.getPos();
|
||||
if (this.isAnnihilationPlane(te.getWorld().getTileEntity(pos.offset(e.getOpposite())), this.getSide())) {
|
||||
minX = 0;
|
||||
}
|
||||
|
||||
final Direction e = bch.getWorldX();
|
||||
final Direction u = bch.getWorldY();
|
||||
if (this.isAnnihilationPlane(te.getWorld().getTileEntity(pos.offset(e)), this.getSide())) {
|
||||
maxX = 16;
|
||||
}
|
||||
|
||||
if( this.isAnnihilationPlane( te.getWorld().getTileEntity( pos.offset( e.getOpposite() ) ), this.getSide() ) )
|
||||
{
|
||||
minX = 0;
|
||||
}
|
||||
if (this.isAnnihilationPlane(te.getWorld().getTileEntity(pos.offset(u.getOpposite())), this.getSide())) {
|
||||
minY = 0;
|
||||
}
|
||||
|
||||
if( this.isAnnihilationPlane( te.getWorld().getTileEntity( pos.offset( e ) ), this.getSide() ) )
|
||||
{
|
||||
maxX = 16;
|
||||
}
|
||||
if (this.isAnnihilationPlane(te.getWorld().getTileEntity(pos.offset(e)), this.getSide())) {
|
||||
maxY = 16;
|
||||
}
|
||||
}
|
||||
|
||||
if( this.isAnnihilationPlane( te.getWorld().getTileEntity( pos.offset( u.getOpposite() ) ), this.getSide() ) )
|
||||
{
|
||||
minY = 0;
|
||||
}
|
||||
bch.addBox(5, 5, 14, 11, 11, 15);
|
||||
bch.addBox(minX, minY, 15, maxX, maxY, 16);
|
||||
}
|
||||
|
||||
if( this.isAnnihilationPlane( te.getWorld().getTileEntity( pos.offset( e ) ), this.getSide() ) )
|
||||
{
|
||||
maxY = 16;
|
||||
}
|
||||
}
|
||||
public PlaneConnections getConnections() {
|
||||
|
||||
bch.addBox( 5, 5, 14, 11, 11, 15 );
|
||||
bch.addBox( minX, minY, 15, maxX, maxY, 16 );
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
public PlaneConnections getConnections()
|
||||
{
|
||||
boolean left = false, right = false, down = false, up = false;
|
||||
|
||||
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 );
|
||||
}
|
||||
final IPartHost host = this.getHost();
|
||||
if (host != null) {
|
||||
final TileEntity te = host.getTile();
|
||||
|
||||
boolean left = false, right = false, down = false, up = false;
|
||||
final BlockPos pos = te.getPos();
|
||||
|
||||
final IPartHost host = this.getHost();
|
||||
if( host != null )
|
||||
{
|
||||
final TileEntity te = host.getTile();
|
||||
if (this.isAnnihilationPlane(te.getWorld().getTileEntity(pos.offset(facingRight.getOpposite())),
|
||||
this.getSide())) {
|
||||
left = true;
|
||||
}
|
||||
|
||||
final BlockPos pos = te.getPos();
|
||||
if (this.isAnnihilationPlane(te.getWorld().getTileEntity(pos.offset(facingRight)), this.getSide())) {
|
||||
right = true;
|
||||
}
|
||||
|
||||
if( this.isAnnihilationPlane( te.getWorld().getTileEntity( pos.offset( facingRight.getOpposite() ) ), this.getSide() ) )
|
||||
{
|
||||
left = true;
|
||||
}
|
||||
if (this.isAnnihilationPlane(te.getWorld().getTileEntity(pos.offset(facingUp.getOpposite())),
|
||||
this.getSide())) {
|
||||
down = true;
|
||||
}
|
||||
|
||||
if( this.isAnnihilationPlane( te.getWorld().getTileEntity( pos.offset( facingRight ) ), this.getSide() ) )
|
||||
{
|
||||
right = true;
|
||||
}
|
||||
if (this.isAnnihilationPlane(te.getWorld().getTileEntity(pos.offset(facingUp)), this.getSide())) {
|
||||
up = true;
|
||||
}
|
||||
}
|
||||
|
||||
if( this.isAnnihilationPlane( te.getWorld().getTileEntity( pos.offset( facingUp.getOpposite() ) ), this.getSide() ) )
|
||||
{
|
||||
down = true;
|
||||
}
|
||||
return PlaneConnections.of(up, right, down, left);
|
||||
}
|
||||
|
||||
if( this.isAnnihilationPlane( te.getWorld().getTileEntity( pos.offset( facingUp ) ), this.getSide() ) )
|
||||
{
|
||||
up = true;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void onNeighborChanged(IBlockReader w, BlockPos pos, BlockPos neighbor) {
|
||||
if (pos.offset(this.getSide().getFacing()).equals(neighbor)) {
|
||||
this.refresh();
|
||||
}
|
||||
}
|
||||
|
||||
return PlaneConnections.of( up, right, down, left );
|
||||
}
|
||||
@Override
|
||||
public float getCableConnectionLength(AECableType cable) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNeighborChanged( IBlockReader w, BlockPos pos, BlockPos neighbor )
|
||||
{
|
||||
if( pos.offset( this.getSide().getFacing() ).equals( neighbor ) )
|
||||
{
|
||||
this.refresh();
|
||||
}
|
||||
}
|
||||
private boolean isAnnihilationPlane(final TileEntity blockTileEntity, final AEPartLocation side) {
|
||||
if (blockTileEntity instanceof IPartHost) {
|
||||
final IPart p = ((IPartHost) blockTileEntity).getPart(side);
|
||||
return p != null && p.getClass() == this.getClass();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getCableConnectionLength( AECableType cable )
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
private void refresh() {
|
||||
try {
|
||||
this.getProxy().getTick().alertDevice(this.getProxy().getNode());
|
||||
} catch (final GridAccessException e) {
|
||||
// :P
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isAnnihilationPlane( final TileEntity blockTileEntity, final AEPartLocation side )
|
||||
{
|
||||
if( blockTileEntity instanceof IPartHost )
|
||||
{
|
||||
final IPart p = ( (IPartHost) blockTileEntity ).getPart( side );
|
||||
return p != null && p.getClass() == this.getClass();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
@MENetworkEventSubscribe
|
||||
public void chanRender(final MENetworkChannelsChanged c) {
|
||||
this.refresh();
|
||||
this.getHost().markForUpdate();
|
||||
}
|
||||
|
||||
private void refresh()
|
||||
{
|
||||
try
|
||||
{
|
||||
this.getProxy().getTick().alertDevice( this.getProxy().getNode() );
|
||||
}
|
||||
catch( final GridAccessException e )
|
||||
{
|
||||
// :P
|
||||
}
|
||||
}
|
||||
@Override
|
||||
@MENetworkEventSubscribe
|
||||
public void powerRender(final MENetworkPowerStatusChange c) {
|
||||
this.refresh();
|
||||
this.getHost().markForUpdate();
|
||||
}
|
||||
|
||||
@Override
|
||||
@MENetworkEventSubscribe
|
||||
public void chanRender( final MENetworkChannelsChanged c )
|
||||
{
|
||||
this.refresh();
|
||||
this.getHost().markForUpdate();
|
||||
}
|
||||
private TickRateModulation pickupFluid() {
|
||||
if (!this.getProxy().isActive()) {
|
||||
return TickRateModulation.SLEEP;
|
||||
}
|
||||
|
||||
@Override
|
||||
@MENetworkEventSubscribe
|
||||
public void powerRender( final MENetworkPowerStatusChange c )
|
||||
{
|
||||
this.refresh();
|
||||
this.getHost().markForUpdate();
|
||||
}
|
||||
final TileEntity te = this.getTile();
|
||||
final World w = te.getWorld();
|
||||
final BlockPos pos = te.getPos().offset(this.getSide().getFacing());
|
||||
|
||||
private TickRateModulation pickupFluid()
|
||||
{
|
||||
if( !this.getProxy().isActive() )
|
||||
{
|
||||
return TickRateModulation.SLEEP;
|
||||
}
|
||||
BlockState blockstate = w.getBlockState(pos);
|
||||
if (blockstate.getBlock() instanceof IBucketPickupHandler) {
|
||||
IFluidState fluidState = blockstate.getFluidState();
|
||||
|
||||
final TileEntity te = this.getTile();
|
||||
final World w = te.getWorld();
|
||||
final BlockPos pos = te.getPos().offset( this.getSide().getFacing() );
|
||||
Fluid fluid = fluidState.getFluid();
|
||||
if (fluid != Fluids.EMPTY && fluidState.isSource()) {
|
||||
|
||||
BlockState blockstate = w.getBlockState(pos);
|
||||
if (blockstate.getBlock() instanceof IBucketPickupHandler) {
|
||||
IFluidState fluidState = blockstate.getFluidState();
|
||||
// Attempt to store the fluid in the network
|
||||
final IAEFluidStack blockFluid = AEFluidStack
|
||||
.fromFluidStack(new FluidStack(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 FluidStack(fluid, FluidAttributes.BUCKET_VOLUME)),
|
||||
true);
|
||||
|
||||
Fluid fluid = fluidState.getFluid();
|
||||
if (fluid != Fluids.EMPTY && fluidState.isSource()) {
|
||||
AppEng.proxy.sendToAllNearExcept(null, pos.getX(), pos.getY(), pos.getZ(), 64, w,
|
||||
new PacketTransitionEffect(pos.getX(), pos.getY(), pos.getZ(), this.getSide(), true));
|
||||
|
||||
// Attempt to store the fluid in the network
|
||||
final IAEFluidStack blockFluid = AEFluidStack.fromFluidStack( new FluidStack(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 FluidStack( fluid, FluidAttributes.BUCKET_VOLUME) ), true );
|
||||
return TickRateModulation.URGENT;
|
||||
}
|
||||
return TickRateModulation.IDLE;
|
||||
}
|
||||
}
|
||||
|
||||
AppEng.proxy.sendToAllNearExcept( null, pos.getX(), pos.getY(), pos.getZ(), 64, w,
|
||||
new PacketTransitionEffect( pos.getX(), pos.getY(), pos.getZ(), this.getSide(), true ) );
|
||||
// nothing to do here :)
|
||||
return TickRateModulation.SLEEP;
|
||||
}
|
||||
|
||||
return TickRateModulation.URGENT;
|
||||
}
|
||||
return TickRateModulation.IDLE;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public TickingRequest getTickingRequest(final IGridNode node) {
|
||||
return new TickingRequest(TickRates.AnnihilationPlane.getMin(), TickRates.AnnihilationPlane.getMax(), false,
|
||||
true);
|
||||
}
|
||||
|
||||
// nothing to do here :)
|
||||
return TickRateModulation.SLEEP;
|
||||
}
|
||||
@Override
|
||||
public TickRateModulation tickingRequest(final IGridNode node, final int ticksSinceLastCall) {
|
||||
return this.pickupFluid();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickingRequest getTickingRequest( final IGridNode node )
|
||||
{
|
||||
return new TickingRequest( TickRates.AnnihilationPlane.getMin(), TickRates.AnnihilationPlane.getMax(), false, true );
|
||||
}
|
||||
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));
|
||||
|
||||
@Override
|
||||
public TickRateModulation tickingRequest( final IGridNode node, final int ticksSinceLastCall )
|
||||
{
|
||||
return this.pickupFluid();
|
||||
}
|
||||
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();
|
||||
|
||||
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 (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;
|
||||
}
|
||||
|
||||
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();
|
||||
@Override
|
||||
public IPartModel getStaticModels() {
|
||||
return MODELS.getModel(this.isPowered(), this.isActive());
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
@Nonnull
|
||||
@Override
|
||||
public IModelData getModelData() {
|
||||
return new PlaneModelData(getConnections());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.fluids.parts;
|
||||
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -50,143 +49,121 @@ 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 PartFluidExportBus extends PartSharedFluidBus
|
||||
{
|
||||
public static final ResourceLocation MODEL_BASE = new ResourceLocation( AppEng.MOD_ID, "part/fluid_export_bus_base" );
|
||||
@PartModels
|
||||
public static final IPartModel MODELS_OFF = new PartModel( MODEL_BASE, new ResourceLocation( AppEng.MOD_ID, "part/fluid_export_bus_off" ) );
|
||||
@PartModels
|
||||
public static final IPartModel MODELS_ON = new PartModel( MODEL_BASE, new ResourceLocation( AppEng.MOD_ID, "part/fluid_export_bus_on" ) );
|
||||
@PartModels
|
||||
public static final IPartModel MODELS_HAS_CHANNEL = new PartModel( MODEL_BASE, new ResourceLocation( AppEng.MOD_ID, "part/fluid_export_bus_has_channel" ) );
|
||||
public class PartFluidExportBus extends PartSharedFluidBus {
|
||||
public static final ResourceLocation MODEL_BASE = new ResourceLocation(AppEng.MOD_ID, "part/fluid_export_bus_base");
|
||||
@PartModels
|
||||
public static final IPartModel MODELS_OFF = new PartModel(MODEL_BASE,
|
||||
new ResourceLocation(AppEng.MOD_ID, "part/fluid_export_bus_off"));
|
||||
@PartModels
|
||||
public static final IPartModel MODELS_ON = new PartModel(MODEL_BASE,
|
||||
new ResourceLocation(AppEng.MOD_ID, "part/fluid_export_bus_on"));
|
||||
@PartModels
|
||||
public static final IPartModel MODELS_HAS_CHANNEL = new PartModel(MODEL_BASE,
|
||||
new ResourceLocation(AppEng.MOD_ID, "part/fluid_export_bus_has_channel"));
|
||||
|
||||
private final IActionSource source;
|
||||
private final IActionSource source;
|
||||
|
||||
public PartFluidExportBus( 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 );
|
||||
}
|
||||
public PartFluidExportBus(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 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
|
||||
public TickRateModulation tickingRequest(IGridNode node, int ticksSinceLastCall) {
|
||||
return this.canDoBusWork() ? this.doBusWork() : TickRateModulation.IDLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean canDoBusWork()
|
||||
{
|
||||
return this.getProxy().isActive();
|
||||
}
|
||||
@Override
|
||||
protected boolean canDoBusWork() {
|
||||
return this.getProxy().isActive();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TickRateModulation doBusWork()
|
||||
{
|
||||
if( !this.canDoBusWork() )
|
||||
{
|
||||
return TickRateModulation.IDLE;
|
||||
}
|
||||
@Override
|
||||
protected TickRateModulation doBusWork() {
|
||||
if (!this.canDoBusWork()) {
|
||||
return TickRateModulation.IDLE;
|
||||
}
|
||||
|
||||
final TileEntity 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() );
|
||||
final TileEntity 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 )
|
||||
{
|
||||
for( int i = 0; i < this.getConfig().getSlots(); i++ )
|
||||
{
|
||||
IAEFluidStack fluid = this.getConfig().getFluidInSlot( i );
|
||||
if( fluid != null )
|
||||
{
|
||||
final IAEFluidStack toExtract = fluid.copy();
|
||||
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() );
|
||||
toExtract.setStackSize(this.calculateAmountToSend());
|
||||
|
||||
final IAEFluidStack out = inv.extractItems( toExtract, Actionable.SIMULATE, this.source );
|
||||
final IAEFluidStack out = inv.extractItems(toExtract, Actionable.SIMULATE, this.source);
|
||||
|
||||
if( out != null )
|
||||
{
|
||||
int wasInserted = fh.fill( out.getFluidStack(), FluidAction.EXECUTE );
|
||||
if (out != null) {
|
||||
int wasInserted = fh.fill(out.getFluidStack(), FluidAction.EXECUTE);
|
||||
|
||||
if( wasInserted > 0 )
|
||||
{
|
||||
toExtract.setStackSize( wasInserted );
|
||||
inv.extractItems( toExtract, Actionable.MODULATE, this.source );
|
||||
if (wasInserted > 0) {
|
||||
toExtract.setStackSize(wasInserted);
|
||||
inv.extractItems(toExtract, Actionable.MODULATE, this.source);
|
||||
|
||||
return TickRateModulation.FASTER;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return TickRateModulation.FASTER;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return TickRateModulation.SLOWER;
|
||||
}
|
||||
}
|
||||
catch( GridAccessException e )
|
||||
{
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
return TickRateModulation.SLOWER;
|
||||
}
|
||||
} catch (GridAccessException e) {
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
|
||||
return TickRateModulation.SLEEP;
|
||||
}
|
||||
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 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 );
|
||||
}
|
||||
@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;
|
||||
}
|
||||
}
|
||||
@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,19 +1,16 @@
|
||||
|
||||
package appeng.fluids.parts;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import appeng.container.ContainerLocator;
|
||||
import appeng.container.ContainerOpener;
|
||||
import appeng.container.implementations.ContainerFormationPlane;
|
||||
import appeng.fluids.container.ContainerFluidFormationPlane;
|
||||
import appeng.parts.automation.PlaneModelData;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.fluid.Fluid;
|
||||
import net.minecraft.inventory.container.ContainerType;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
@@ -22,7 +19,6 @@ 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.fluid.Fluid;
|
||||
import net.minecraftforge.client.model.data.IModelData;
|
||||
import net.minecraftforge.fluids.FluidAttributes;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
@@ -47,7 +43,10 @@ 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.container.implementations.ContainerFormationPlane;
|
||||
import appeng.fluids.container.ContainerFluidFormationPlane;
|
||||
import appeng.fluids.util.AEFluidInventory;
|
||||
import appeng.fluids.util.IAEFluidInventory;
|
||||
import appeng.fluids.util.IAEFluidTank;
|
||||
@@ -55,197 +54,168 @@ import appeng.items.parts.PartModels;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.me.storage.MEInventoryHandler;
|
||||
import appeng.parts.automation.PartAbstractFormationPlane;
|
||||
import appeng.parts.automation.PlaneModelData;
|
||||
import appeng.parts.automation.PlaneModels;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.prioritylist.PrecisePriorityList;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
public class PartFluidFormationPlane extends PartAbstractFormationPlane<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();
|
||||
}
|
||||
|
||||
public class PartFluidFormationPlane extends PartAbstractFormationPlane<IAEFluidStack> implements IAEFluidInventory
|
||||
{
|
||||
private static final PlaneModels MODELS = new PlaneModels( "part/fluid_formation_plane", "part/fluid_formation_plane_on" );
|
||||
private final MEInventoryHandler<IAEFluidStack> myHandler = new MEInventoryHandler<>(this,
|
||||
AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class));
|
||||
private final AEFluidInventory config = new AEFluidInventory(this, 63);
|
||||
|
||||
@PartModels
|
||||
public static List<IPartModel> getModels()
|
||||
{
|
||||
return MODELS.getModels();
|
||||
}
|
||||
public PartFluidFormationPlane(final ItemStack is) {
|
||||
super(is);
|
||||
this.updateHandler();
|
||||
}
|
||||
|
||||
private final MEInventoryHandler<IAEFluidStack> myHandler = new MEInventoryHandler<>( this, AEApi.instance()
|
||||
.storage()
|
||||
.getStorageChannel( IFluidStorageChannel.class ) );
|
||||
private final AEFluidInventory config = new AEFluidInventory( this, 63 );
|
||||
@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());
|
||||
|
||||
public PartFluidFormationPlane( final ItemStack is )
|
||||
{
|
||||
super( is );
|
||||
this.updateHandler();
|
||||
}
|
||||
final IItemList<IAEFluidStack> priorityList = AEApi.instance().storage()
|
||||
.getStorageChannel(IFluidStorageChannel.class).createList();
|
||||
|
||||
@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 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));
|
||||
|
||||
final IItemList<IAEFluidStack> priorityList = AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ).createList();
|
||||
try {
|
||||
this.getProxy().getGrid().postEvent(new MENetworkCellArrayUpdate());
|
||||
} catch (final GridAccessException e) {
|
||||
// :P
|
||||
}
|
||||
}
|
||||
|
||||
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 ) );
|
||||
@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;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
this.getProxy().getGrid().postEvent( new MENetworkCellArrayUpdate() );
|
||||
}
|
||||
catch( final GridAccessException e )
|
||||
{
|
||||
// :P
|
||||
}
|
||||
}
|
||||
final TileEntity 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);
|
||||
|
||||
@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;
|
||||
}
|
||||
if (this.canReplace(w, state, pos)) {
|
||||
if (type == Actionable.MODULATE) {
|
||||
final FluidStack fs = input.getFluidStack();
|
||||
fs.setAmount(FluidAttributes.BUCKET_VOLUME);
|
||||
|
||||
final TileEntity 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 );
|
||||
final FluidTank tank = new FluidTank(FluidAttributes.BUCKET_VOLUME, e -> e.isFluidEqual(fs));
|
||||
if (!FluidUtil.tryPlaceFluid(null, 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;
|
||||
}
|
||||
|
||||
if( this.canReplace( w, state, pos ) )
|
||||
{
|
||||
if( type == Actionable.MODULATE )
|
||||
{
|
||||
final FluidStack fs = input.getFluidStack();
|
||||
fs.setAmount( FluidAttributes.BUCKET_VOLUME );
|
||||
private boolean canReplace(World w, BlockState state, BlockPos pos) {
|
||||
return state.getMaterial().isReplaceable() && w.getFluidState(pos).isEmpty() && !state.getMaterial().isLiquid();
|
||||
}
|
||||
|
||||
final FluidTank tank = new FluidTank( FluidAttributes.BUCKET_VOLUME, e -> e.isFluidEqual( fs ) );
|
||||
if( !FluidUtil.tryPlaceFluid( null, 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;
|
||||
}
|
||||
@Override
|
||||
public void onFluidInventoryChanged(IAEFluidTank inv, int slot) {
|
||||
if (inv == this.config) {
|
||||
this.updateHandler();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean canReplace( World w, BlockState state, BlockPos pos )
|
||||
{
|
||||
return state.getMaterial().isReplaceable() && w.getFluidState(pos).isEmpty() && !state.getMaterial().isLiquid();
|
||||
}
|
||||
@Override
|
||||
public void readFromNBT(final CompoundNBT data) {
|
||||
super.readFromNBT(data);
|
||||
this.config.readFromNBT(data, "config");
|
||||
this.updateHandler();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFluidInventoryChanged( IAEFluidTank inv, int slot )
|
||||
{
|
||||
if( inv == this.config )
|
||||
{
|
||||
this.updateHandler();
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void writeToNBT(final CompoundNBT data) {
|
||||
super.writeToNBT(data);
|
||||
this.config.writeToNBT(data, "config");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT( final CompoundNBT data )
|
||||
{
|
||||
super.readFromNBT( data );
|
||||
this.config.readFromNBT( data, "config" );
|
||||
this.updateHandler();
|
||||
}
|
||||
@Override
|
||||
@MENetworkEventSubscribe
|
||||
public void powerRender(final MENetworkPowerStatusChange c) {
|
||||
this.stateChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT( final CompoundNBT data )
|
||||
{
|
||||
super.writeToNBT( data );
|
||||
this.config.writeToNBT( data, "config" );
|
||||
}
|
||||
@MENetworkEventSubscribe
|
||||
public void updateChannels(final MENetworkChannelsChanged changedChannels) {
|
||||
this.stateChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
@MENetworkEventSubscribe
|
||||
public void powerRender( final MENetworkPowerStatusChange c )
|
||||
{
|
||||
this.stateChanged();
|
||||
}
|
||||
@Override
|
||||
public boolean onPartActivate(final PlayerEntity player, final Hand hand, final Vec3d pos) {
|
||||
if (Platform.isServer()) {
|
||||
ContainerOpener.openContainer(ContainerFluidFormationPlane.TYPE, player, ContainerLocator.forPart(this));
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void updateChannels( final MENetworkChannelsChanged changedChannels )
|
||||
{
|
||||
this.stateChanged();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPartActivate( final PlayerEntity player, final Hand hand, final Vec3d pos )
|
||||
{
|
||||
if( Platform.isServer() )
|
||||
{
|
||||
ContainerOpener.openContainer(ContainerFluidFormationPlane.TYPE, player, ContainerLocator.forPart(this));
|
||||
}
|
||||
@Override
|
||||
public IStorageChannel<IAEFluidStack> getChannel() {
|
||||
return AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@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 IStorageChannel<IAEFluidStack> getChannel()
|
||||
{
|
||||
return AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class );
|
||||
}
|
||||
@Override
|
||||
public IPartModel getStaticModels() {
|
||||
return MODELS.getModel(this.isPowered(), this.isActive());
|
||||
}
|
||||
|
||||
@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();
|
||||
}
|
||||
@Nonnull
|
||||
@Override
|
||||
public IModelData getModelData() {
|
||||
return new PlaneModelData(getConnections());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPartModel getStaticModels()
|
||||
{
|
||||
return MODELS.getModel( this.isPowered(), this.isActive() );
|
||||
}
|
||||
public IAEFluidTank getConfig() {
|
||||
return this.config;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public IModelData getModelData() {
|
||||
return new PlaneModelData(getConnections());
|
||||
}
|
||||
@Override
|
||||
public ItemStack getItemStackRepresentation() {
|
||||
return AEApi.instance().definitions().parts().fluidFormationnPlane().maybeStack(1).orElse(ItemStack.EMPTY);
|
||||
}
|
||||
|
||||
public IAEFluidTank getConfig()
|
||||
{
|
||||
return this.config;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItemStackRepresentation()
|
||||
{
|
||||
return AEApi.instance().definitions().parts().fluidFormationnPlane().maybeStack( 1 ).orElse( ItemStack.EMPTY );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContainerType<?> getContainerType()
|
||||
{
|
||||
return ContainerFluidFormationPlane.TYPE;
|
||||
}
|
||||
@Override
|
||||
public ContainerType<?> getContainerType() {
|
||||
return ContainerFluidFormationPlane.TYPE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.fluids.parts;
|
||||
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -51,157 +50,132 @@ 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 PartFluidImportBus extends PartSharedFluidBus
|
||||
{
|
||||
public static final ResourceLocation MODEL_BASE = new ResourceLocation( AppEng.MOD_ID, "part/fluid_import_bus_base" );
|
||||
@PartModels
|
||||
public static final IPartModel MODELS_OFF = new PartModel( MODEL_BASE, new ResourceLocation( AppEng.MOD_ID, "part/fluid_import_bus_off" ) );
|
||||
@PartModels
|
||||
public static final IPartModel MODELS_ON = new PartModel( MODEL_BASE, new ResourceLocation( AppEng.MOD_ID, "part/fluid_import_bus_on" ) );
|
||||
@PartModels
|
||||
public static final IPartModel MODELS_HAS_CHANNEL = new PartModel( MODEL_BASE, new ResourceLocation( AppEng.MOD_ID, "part/fluid_import_bus_has_channel" ) );
|
||||
public class PartFluidImportBus extends PartSharedFluidBus {
|
||||
public static final ResourceLocation MODEL_BASE = new ResourceLocation(AppEng.MOD_ID, "part/fluid_import_bus_base");
|
||||
@PartModels
|
||||
public static final IPartModel MODELS_OFF = new PartModel(MODEL_BASE,
|
||||
new ResourceLocation(AppEng.MOD_ID, "part/fluid_import_bus_off"));
|
||||
@PartModels
|
||||
public static final IPartModel MODELS_ON = new PartModel(MODEL_BASE,
|
||||
new ResourceLocation(AppEng.MOD_ID, "part/fluid_import_bus_on"));
|
||||
@PartModels
|
||||
public static final IPartModel MODELS_HAS_CHANNEL = new PartModel(MODEL_BASE,
|
||||
new ResourceLocation(AppEng.MOD_ID, "part/fluid_import_bus_has_channel"));
|
||||
|
||||
private final IActionSource source;
|
||||
private final IActionSource source;
|
||||
|
||||
public PartFluidImportBus( 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 );
|
||||
}
|
||||
public PartFluidImportBus(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 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
|
||||
public TickRateModulation tickingRequest(IGridNode node, int ticksSinceLastCall) {
|
||||
return this.canDoBusWork() ? this.doBusWork() : TickRateModulation.IDLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TickRateModulation doBusWork()
|
||||
{
|
||||
if( !this.canDoBusWork() )
|
||||
{
|
||||
return TickRateModulation.IDLE;
|
||||
}
|
||||
@Override
|
||||
protected TickRateModulation doBusWork() {
|
||||
if (!this.canDoBusWork()) {
|
||||
return TickRateModulation.IDLE;
|
||||
}
|
||||
|
||||
final TileEntity 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() );
|
||||
final TileEntity 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 FluidStack fluidStack = fh.drain( this.calculateAmountToSend(), FluidAction.SIMULATE );
|
||||
if (fh != null) {
|
||||
final FluidStack fluidStack = fh.drain(this.calculateAmountToSend(), FluidAction.SIMULATE);
|
||||
|
||||
if( this.filterEnabled() && !this.isInFilter( fluidStack ) )
|
||||
{
|
||||
return TickRateModulation.SLOWER;
|
||||
}
|
||||
if (this.filterEnabled() && !this.isInFilter(fluidStack)) {
|
||||
return TickRateModulation.SLOWER;
|
||||
}
|
||||
|
||||
final AEFluidStack aeFluidStack = AEFluidStack.fromFluidStack( fluidStack );
|
||||
final AEFluidStack aeFluidStack = AEFluidStack.fromFluidStack(fluidStack);
|
||||
|
||||
if( aeFluidStack != null )
|
||||
{
|
||||
final IAEFluidStack notInserted = inv.injectItems( aeFluidStack, Actionable.MODULATE, this.source );
|
||||
if (aeFluidStack != null) {
|
||||
final IAEFluidStack notInserted = inv.injectItems(aeFluidStack, Actionable.MODULATE,
|
||||
this.source);
|
||||
|
||||
if( notInserted != null && notInserted.getStackSize() > 0 )
|
||||
{
|
||||
aeFluidStack.decStackSize( notInserted.getStackSize() );
|
||||
}
|
||||
if (notInserted != null && notInserted.getStackSize() > 0) {
|
||||
aeFluidStack.decStackSize(notInserted.getStackSize());
|
||||
}
|
||||
|
||||
fh.drain( aeFluidStack.getFluidStack(), FluidAction.EXECUTE );
|
||||
fh.drain(aeFluidStack.getFluidStack(), FluidAction.EXECUTE);
|
||||
|
||||
return TickRateModulation.FASTER;
|
||||
}
|
||||
return TickRateModulation.FASTER;
|
||||
}
|
||||
|
||||
return TickRateModulation.IDLE;
|
||||
}
|
||||
}
|
||||
catch( GridAccessException e )
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return TickRateModulation.IDLE;
|
||||
}
|
||||
} catch (GridAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
return TickRateModulation.SLEEP;
|
||||
}
|
||||
return TickRateModulation.SLEEP;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean canDoBusWork()
|
||||
{
|
||||
return this.getProxy().isActive();
|
||||
}
|
||||
@Override
|
||||
protected boolean canDoBusWork() {
|
||||
return this.getProxy().isActive();
|
||||
}
|
||||
|
||||
private boolean isInFilter( FluidStack 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 isInFilter(FluidStack 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;
|
||||
}
|
||||
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 );
|
||||
}
|
||||
@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;
|
||||
}
|
||||
}
|
||||
@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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,12 +18,8 @@
|
||||
|
||||
package appeng.fluids.parts;
|
||||
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
import appeng.container.ContainerLocator;
|
||||
import appeng.container.ContainerOpener;
|
||||
import appeng.fluids.container.ContainerFluidInterface;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.inventory.container.ContainerType;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -54,8 +50,10 @@ 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.ContainerFluidInterface;
|
||||
import appeng.fluids.helper.DualityFluidInterface;
|
||||
import appeng.fluids.helper.IFluidInterfaceHost;
|
||||
import appeng.helpers.IPriorityHost;
|
||||
@@ -65,182 +63,154 @@ import appeng.parts.PartBasicState;
|
||||
import appeng.parts.PartModel;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public class PartFluidInterface extends PartBasicState
|
||||
implements IGridTickable, IStorageMonitorable, IFluidInterfaceHost, IPriorityHost {
|
||||
public static final ResourceLocation MODEL_BASE = new ResourceLocation(AppEng.MOD_ID, "part/fluid_interface_base");
|
||||
|
||||
public class PartFluidInterface extends PartBasicState implements IGridTickable, IStorageMonitorable, IFluidInterfaceHost, IPriorityHost
|
||||
{
|
||||
public static final ResourceLocation MODEL_BASE = new ResourceLocation( AppEng.MOD_ID, "part/fluid_interface_base" );
|
||||
@PartModels
|
||||
public static final PartModel MODELS_OFF = new PartModel(MODEL_BASE,
|
||||
new ResourceLocation(AppEng.MOD_ID, "part/fluid_interface_off"));
|
||||
|
||||
@PartModels
|
||||
public static final PartModel MODELS_OFF = new PartModel( MODEL_BASE, new ResourceLocation( AppEng.MOD_ID, "part/fluid_interface_off" ) );
|
||||
@PartModels
|
||||
public static final PartModel MODELS_ON = new PartModel(MODEL_BASE,
|
||||
new ResourceLocation(AppEng.MOD_ID, "part/fluid_interface_on"));
|
||||
|
||||
@PartModels
|
||||
public static final PartModel MODELS_ON = new PartModel( MODEL_BASE, new ResourceLocation( AppEng.MOD_ID, "part/fluid_interface_on" ) );
|
||||
@PartModels
|
||||
public static final PartModel MODELS_HAS_CHANNEL = new PartModel(MODEL_BASE,
|
||||
new ResourceLocation(AppEng.MOD_ID, "part/fluid_interface_has_channel"));
|
||||
|
||||
@PartModels
|
||||
public static final PartModel MODELS_HAS_CHANNEL = new PartModel( MODEL_BASE, new ResourceLocation( AppEng.MOD_ID, "part/fluid_interface_has_channel" ) );
|
||||
private final DualityFluidInterface duality = new DualityFluidInterface(this.getProxy(), this);
|
||||
|
||||
private final DualityFluidInterface duality = new DualityFluidInterface( this.getProxy(), this );
|
||||
@Reflected
|
||||
public PartFluidInterface(final ItemStack is) {
|
||||
super(is);
|
||||
}
|
||||
|
||||
@Reflected
|
||||
public PartFluidInterface( final ItemStack is )
|
||||
{
|
||||
super( is );
|
||||
}
|
||||
@Override
|
||||
public DualityFluidInterface getDualityFluidInterface() {
|
||||
return this.duality;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DualityFluidInterface getDualityFluidInterface()
|
||||
{
|
||||
return this.duality;
|
||||
}
|
||||
@MENetworkEventSubscribe
|
||||
public void stateChange(final MENetworkChannelsChanged c) {
|
||||
this.duality.notifyNeighbors();
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void stateChange( final MENetworkChannelsChanged c )
|
||||
{
|
||||
this.duality.notifyNeighbors();
|
||||
}
|
||||
@MENetworkEventSubscribe
|
||||
public void stateChange(final MENetworkPowerStatusChange 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 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 gridChanged()
|
||||
{
|
||||
this.duality.gridChanged();
|
||||
}
|
||||
@Override
|
||||
public void readFromNBT(final CompoundNBT data) {
|
||||
super.readFromNBT(data);
|
||||
this.duality.readFromNBT(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT( final CompoundNBT data )
|
||||
{
|
||||
super.readFromNBT( data );
|
||||
this.duality.readFromNBT( data );
|
||||
}
|
||||
@Override
|
||||
public void writeToNBT(final CompoundNBT data) {
|
||||
super.writeToNBT(data);
|
||||
this.duality.writeToNBT(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT( final CompoundNBT data )
|
||||
{
|
||||
super.writeToNBT( data );
|
||||
this.duality.writeToNBT( data );
|
||||
}
|
||||
@Override
|
||||
public float getCableConnectionLength(AECableType cable) {
|
||||
return 4;
|
||||
}
|
||||
|
||||
@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(ContainerFluidInterface.TYPE, p, ContainerLocator.forPart(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPartActivate( final PlayerEntity p, final Hand hand, final Vec3d pos )
|
||||
{
|
||||
if( Platform.isServer() )
|
||||
{
|
||||
ContainerOpener.openContainer(ContainerFluidInterface.TYPE, p, ContainerLocator.forPart(this));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public <T extends IAEStack<T>> IMEMonitor<T> getInventory(IStorageChannel<T> channel) {
|
||||
return this.duality.getInventory(channel);
|
||||
}
|
||||
|
||||
@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 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 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 EnumSet<Direction> getTargets()
|
||||
{
|
||||
return EnumSet.of( this.getSide().getFacing() );
|
||||
}
|
||||
@Override
|
||||
public TileEntity getTileEntity() {
|
||||
return super.getHost().getTile();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity getTileEntity()
|
||||
{
|
||||
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 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 int getPriority()
|
||||
{
|
||||
return this.duality.getPriority();
|
||||
}
|
||||
@Override
|
||||
public void setPriority(final int newValue) {
|
||||
this.duality.setPriority(newValue);
|
||||
}
|
||||
|
||||
@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 <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 int getInstalledUpgrades( Upgrades u )
|
||||
{
|
||||
return this.duality.getInstalledUpgrades( u );
|
||||
}
|
||||
@Override
|
||||
public IConfigManager getConfigManager() {
|
||||
return this.duality.getConfigManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IConfigManager getConfigManager()
|
||||
{
|
||||
return this.duality.getConfigManager();
|
||||
}
|
||||
@Override
|
||||
public IItemHandler getInventoryByName(String name) {
|
||||
return this.duality.getInventoryByName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemHandler 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 ItemStack getItemStackRepresentation()
|
||||
{
|
||||
return AEApi.instance().definitions().parts().fluidIface().maybeStack( 1 ).orElse( ItemStack.EMPTY );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContainerType<?> getContainerType()
|
||||
{
|
||||
return ContainerFluidInterface.TYPE;
|
||||
}
|
||||
@Override
|
||||
public ContainerType<?> getContainerType() {
|
||||
return ContainerFluidInterface.TYPE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
|
||||
package appeng.fluids.parts;
|
||||
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import appeng.container.ContainerLocator;
|
||||
import appeng.container.ContainerOpener;
|
||||
import appeng.fluids.container.ContainerFluidLevelEmitter;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
@@ -39,8 +35,10 @@ 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.ContainerFluidLevelEmitter;
|
||||
import appeng.fluids.util.AEFluidInventory;
|
||||
import appeng.fluids.util.IAEFluidInventory;
|
||||
import appeng.fluids.util.IAEFluidTank;
|
||||
@@ -51,329 +49,276 @@ import appeng.parts.automation.PartUpgradeable;
|
||||
import appeng.util.IConfigManagerHost;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public class PartFluidLevelEmitter extends PartUpgradeable
|
||||
implements IStackWatcherHost, IConfigManagerHost, IAEFluidInventory, IMEMonitorHandlerReceiver<IAEFluidStack> {
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_BASE_OFF = new ResourceLocation(AppEng.MOD_ID,
|
||||
"part/level_emitter_base_off");
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_BASE_ON = new ResourceLocation(AppEng.MOD_ID,
|
||||
"part/level_emitter_base_on");
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_STATUS_OFF = new ResourceLocation(AppEng.MOD_ID,
|
||||
"part/level_emitter_status_off");
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_STATUS_ON = new ResourceLocation(AppEng.MOD_ID,
|
||||
"part/level_emitter_status_on");
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_STATUS_HAS_CHANNEL = new ResourceLocation(AppEng.MOD_ID,
|
||||
"part/level_emitter_status_has_channel");
|
||||
|
||||
public class PartFluidLevelEmitter extends PartUpgradeable implements IStackWatcherHost, IConfigManagerHost, IAEFluidInventory, IMEMonitorHandlerReceiver<IAEFluidStack>
|
||||
{
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_BASE_OFF = new ResourceLocation( AppEng.MOD_ID, "part/level_emitter_base_off" );
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_BASE_ON = new ResourceLocation( AppEng.MOD_ID, "part/level_emitter_base_on" );
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_STATUS_OFF = new ResourceLocation( AppEng.MOD_ID, "part/level_emitter_status_off" );
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_STATUS_ON = new ResourceLocation( AppEng.MOD_ID, "part/level_emitter_status_on" );
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_STATUS_HAS_CHANNEL = new ResourceLocation( 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);
|
||||
|
||||
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 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);
|
||||
|
||||
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 PartFluidLevelEmitter(ItemStack is) {
|
||||
super(is);
|
||||
|
||||
public PartFluidLevelEmitter( ItemStack is )
|
||||
{
|
||||
super( is );
|
||||
this.getConfigManager().registerSetting(Settings.REDSTONE_EMITTER, RedstoneMode.HIGH_SIGNAL);
|
||||
}
|
||||
|
||||
this.getConfigManager().registerSetting( Settings.REDSTONE_EMITTER, RedstoneMode.HIGH_SIGNAL );
|
||||
}
|
||||
public long getReportingValue() {
|
||||
return this.reportingValue;
|
||||
}
|
||||
|
||||
public long getReportingValue()
|
||||
{
|
||||
return this.reportingValue;
|
||||
}
|
||||
public void setReportingValue(final long v) {
|
||||
this.reportingValue = v;
|
||||
this.updateState();
|
||||
}
|
||||
|
||||
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 updateSetting(IConfigManager manager, Settings settingName, Enum<?> newValue )
|
||||
{
|
||||
this.configureWatchers();
|
||||
}
|
||||
@Override
|
||||
public void updateWatcher(IStackWatcher newWatcher) {
|
||||
this.stackWatcher = newWatcher;
|
||||
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 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();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFluidInventoryChanged( IAEFluidTank inv, int slot )
|
||||
{
|
||||
this.configureWatchers();
|
||||
}
|
||||
@MENetworkEventSubscribe
|
||||
public void channelChanged(final MENetworkChannelsChanged c) {
|
||||
this.updateState();
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void channelChanged( final MENetworkChannelsChanged c )
|
||||
{
|
||||
this.updateState();
|
||||
}
|
||||
@MENetworkEventSubscribe
|
||||
public void powerChanged(final MENetworkPowerStatusChange c) {
|
||||
this.updateState();
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void powerChanged( final MENetworkPowerStatusChange c )
|
||||
{
|
||||
this.updateState();
|
||||
}
|
||||
@Override
|
||||
public int isProvidingStrongPower() {
|
||||
return this.prevState ? 15 : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int isProvidingStrongPower()
|
||||
{
|
||||
return this.prevState ? 15 : 0;
|
||||
}
|
||||
@Override
|
||||
public int isProvidingWeakPower() {
|
||||
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
|
||||
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 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 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);
|
||||
|
||||
@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
|
||||
}
|
||||
}
|
||||
|
||||
this.updateReportingValue( inventory );
|
||||
}
|
||||
catch( final GridAccessException e )
|
||||
{
|
||||
// ;P
|
||||
}
|
||||
}
|
||||
private void updateState() {
|
||||
final boolean isOn = this.isLevelEmitterOn();
|
||||
if (this.prevState != isOn) {
|
||||
this.getHost().markForUpdate();
|
||||
final TileEntity 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 updateState()
|
||||
{
|
||||
final boolean isOn = this.isLevelEmitterOn();
|
||||
if( this.prevState != isOn )
|
||||
{
|
||||
this.getHost().markForUpdate();
|
||||
final TileEntity 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);
|
||||
|
||||
private void configureWatchers()
|
||||
{
|
||||
final IFluidStorageChannel channel = AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class );
|
||||
if (this.stackWatcher != null) {
|
||||
this.stackWatcher.reset();
|
||||
|
||||
if( this.stackWatcher != null )
|
||||
{
|
||||
this.stackWatcher.reset();
|
||||
final IAEFluidStack myStack = this.config.getFluidInSlot(0);
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
final IMEMonitor<IAEFluidStack> inventory = this.getProxy().getStorage().getInventory( channel );
|
||||
this.updateReportingValue(inventory);
|
||||
} catch (GridAccessException e) {
|
||||
// NOP
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.updateReportingValue( inventory );
|
||||
}
|
||||
catch( GridAccessException e )
|
||||
{
|
||||
// NOP
|
||||
}
|
||||
}
|
||||
}
|
||||
private void updateReportingValue(final IMEMonitor<IAEFluidStack> monitor) {
|
||||
final IAEFluidStack myStack = this.config.getFluidInSlot(0);
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
private boolean isLevelEmitterOn()
|
||||
{
|
||||
if( Platform.isClient() )
|
||||
{
|
||||
return ( this.getClientFlags() & FLAG_ON ) == FLAG_ON;
|
||||
}
|
||||
if (!this.getProxy().isActive()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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 AECableType getCableConnectionType( final AEPartLocation dir )
|
||||
{
|
||||
return AECableType.SMART;
|
||||
}
|
||||
@Override
|
||||
public float getCableConnectionLength(AECableType cable) {
|
||||
return 16;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getCableConnectionLength( AECableType cable )
|
||||
{
|
||||
return 16;
|
||||
}
|
||||
@Override
|
||||
public boolean canConnectRedstone() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canConnectRedstone()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public void getBoxes(final IPartCollisionHelper bch) {
|
||||
bch.addBox(7, 7, 11, 9, 9, 16);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getBoxes( final IPartCollisionHelper bch )
|
||||
{
|
||||
bch.addBox( 7, 7, 11, 9, 9, 16 );
|
||||
}
|
||||
@Override
|
||||
public void animateTick(final World world, final BlockPos pos, final Random r) {
|
||||
if (this.isLevelEmitterOn()) {
|
||||
final AEPartLocation d = this.getSide();
|
||||
|
||||
@Override
|
||||
public void animateTick( 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;
|
||||
|
||||
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;
|
||||
// FIXME world.spawnParticle( EnumParticleTypes.REDSTONE, 0.5 + pos.getX() + d0,
|
||||
// 0.5 + pos.getY() + d1, 0.5 + pos.getZ() + d2, 0.0D, 0.0D, 0.0D,
|
||||
// FIXME new int[0] );
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME world.spawnParticle( EnumParticleTypes.REDSTONE, 0.5 + pos.getX() + d0, 0.5 + pos.getY() + d1, 0.5 + pos.getZ() + d2, 0.0D, 0.0D, 0.0D,
|
||||
// FIXME new int[0] );
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public boolean onPartActivate(final PlayerEntity player, final Hand hand, final Vec3d pos) {
|
||||
if (Platform.isServer()) {
|
||||
ContainerOpener.openContainer(ContainerFluidLevelEmitter.TYPE, player, ContainerLocator.forPart(this));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPartActivate( final PlayerEntity player, final Hand hand, final Vec3d pos )
|
||||
{
|
||||
if( Platform.isServer() )
|
||||
{
|
||||
ContainerOpener.openContainer(ContainerFluidLevelEmitter.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;
|
||||
}
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
public IAEFluidTank getConfig()
|
||||
{
|
||||
return this.config;
|
||||
}
|
||||
@Override
|
||||
public void readFromNBT(final CompoundNBT 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 readFromNBT( final CompoundNBT 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 CompoundNBT data )
|
||||
{
|
||||
super.writeToNBT( data );
|
||||
data.putLong( "lastReportedValue", this.lastReportedValue );
|
||||
data.putLong( "reportingValue", this.reportingValue );
|
||||
data.putBoolean("prevState", this.prevState);
|
||||
this.config.writeToNBT( data, "config" );
|
||||
}
|
||||
@Override
|
||||
public void writeToNBT(final CompoundNBT data) {
|
||||
super.writeToNBT(data);
|
||||
data.putLong("lastReportedValue", this.lastReportedValue);
|
||||
data.putLong("reportingValue", this.reportingValue);
|
||||
data.putBoolean("prevState", this.prevState);
|
||||
this.config.writeToNBT(data, "config");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,16 +18,12 @@
|
||||
|
||||
package appeng.fluids.parts;
|
||||
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import appeng.container.ContainerLocator;
|
||||
import appeng.container.ContainerOpener;
|
||||
import appeng.fluids.container.ContainerFluidInterface;
|
||||
import appeng.fluids.container.ContainerFluidStorageBus;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.inventory.container.ContainerType;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -68,9 +64,12 @@ 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.ContainerFluidInterface;
|
||||
import appeng.fluids.container.ContainerFluidStorageBus;
|
||||
import appeng.fluids.util.AEFluidInventory;
|
||||
import appeng.fluids.util.IAEFluidInventory;
|
||||
import appeng.fluids.util.IAEFluidTank;
|
||||
@@ -86,417 +85,361 @@ 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 PartFluidStorageBus extends PartSharedStorageBus implements IMEMonitorHandlerReceiver<IAEFluidStack>, IAEFluidInventory
|
||||
{
|
||||
public static final ResourceLocation MODEL_BASE = new ResourceLocation( AppEng.MOD_ID, "part/fluid_storage_bus_base" );
|
||||
@PartModels
|
||||
public static final IPartModel MODELS_OFF = new PartModel( MODEL_BASE, new ResourceLocation( AppEng.MOD_ID, "part/fluid_storage_bus_off" ) );
|
||||
@PartModels
|
||||
public static final IPartModel MODELS_ON = new PartModel( MODEL_BASE, new ResourceLocation( AppEng.MOD_ID, "part/fluid_storage_bus_on" ) );
|
||||
@PartModels
|
||||
public static final IPartModel MODELS_HAS_CHANNEL = new PartModel( MODEL_BASE, new ResourceLocation( AppEng.MOD_ID, "part/fluid_storage_bus_has_channel" ) );
|
||||
public class PartFluidStorageBus extends PartSharedStorageBus
|
||||
implements IMEMonitorHandlerReceiver<IAEFluidStack>, IAEFluidInventory {
|
||||
public static final ResourceLocation MODEL_BASE = new ResourceLocation(AppEng.MOD_ID,
|
||||
"part/fluid_storage_bus_base");
|
||||
@PartModels
|
||||
public static final IPartModel MODELS_OFF = new PartModel(MODEL_BASE,
|
||||
new ResourceLocation(AppEng.MOD_ID, "part/fluid_storage_bus_off"));
|
||||
@PartModels
|
||||
public static final IPartModel MODELS_ON = new PartModel(MODEL_BASE,
|
||||
new ResourceLocation(AppEng.MOD_ID, "part/fluid_storage_bus_on"));
|
||||
@PartModels
|
||||
public static final IPartModel MODELS_HAS_CHANNEL = new PartModel(MODEL_BASE,
|
||||
new ResourceLocation(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;
|
||||
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 PartFluidStorageBus( 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 );
|
||||
}
|
||||
public PartFluidStorageBus(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( TileEntity 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 ) );
|
||||
}
|
||||
private IMEInventory<IAEFluidStack> getInventoryWrapper(TileEntity 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;
|
||||
}
|
||||
// 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 );
|
||||
}
|
||||
// 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;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickRateModulation tickingRequest( IGridNode node, int ticksSinceLastCall )
|
||||
{
|
||||
if( this.resetCacheLogic != 0 )
|
||||
{
|
||||
this.resetCache();
|
||||
}
|
||||
@Override
|
||||
public TickRateModulation tickingRequest(IGridNode node, int ticksSinceLastCall) {
|
||||
if (this.resetCacheLogic != 0) {
|
||||
this.resetCache();
|
||||
}
|
||||
|
||||
if( this.monitor != null )
|
||||
{
|
||||
return this.monitor.onTick();
|
||||
}
|
||||
if (this.monitor != null) {
|
||||
return this.monitor.onTick();
|
||||
}
|
||||
|
||||
return TickRateModulation.SLEEP;
|
||||
}
|
||||
return TickRateModulation.SLEEP;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void resetCache()
|
||||
{
|
||||
final boolean fullReset = this.resetCacheLogic == 2;
|
||||
this.resetCacheLogic = 0;
|
||||
@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 );
|
||||
}
|
||||
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;
|
||||
}
|
||||
this.cached = false;
|
||||
if (fullReset) {
|
||||
this.handlerHash = 0;
|
||||
}
|
||||
|
||||
final IMEInventory<IAEFluidStack> out = this.getInternalHandler();
|
||||
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 );
|
||||
}
|
||||
}
|
||||
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().isRemote )
|
||||
{
|
||||
return;
|
||||
}
|
||||
@Override
|
||||
protected void resetCache(final boolean fullReset) {
|
||||
if (this.getHost() == null || this.getHost().getTile() == null || this.getHost().getTile().getWorld() == null
|
||||
|| this.getHost().getTile().getWorld().isRemote) {
|
||||
return;
|
||||
}
|
||||
|
||||
if( fullReset )
|
||||
{
|
||||
this.resetCacheLogic = 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.resetCacheLogic = 1;
|
||||
}
|
||||
if (fullReset) {
|
||||
this.resetCacheLogic = 2;
|
||||
} else {
|
||||
this.resetCacheLogic = 1;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
this.getProxy().getTick().alertDevice( this.getProxy().getNode() );
|
||||
}
|
||||
catch( final GridAccessException e )
|
||||
{
|
||||
// :P
|
||||
}
|
||||
}
|
||||
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(ContainerFluidStorageBus.TYPE, player, ContainerLocator.forPart(this));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean onPartActivate(final PlayerEntity player, final Hand hand, final Vec3d pos) {
|
||||
if (Platform.isServer()) {
|
||||
ContainerOpener.openContainer(ContainerFluidStorageBus.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 onFluidInventoryChanged(IAEFluidTank inv, int slot) {
|
||||
if (inv == this.config) {
|
||||
this.resetCache(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT( final CompoundNBT data )
|
||||
{
|
||||
super.readFromNBT( data );
|
||||
this.config.readFromNBT( data, "config" );
|
||||
}
|
||||
@Override
|
||||
public void readFromNBT(final CompoundNBT data) {
|
||||
super.readFromNBT(data);
|
||||
this.config.readFromNBT(data, "config");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT( final CompoundNBT data )
|
||||
{
|
||||
super.writeToNBT( data );
|
||||
this.config.writeToNBT( data, "config" );
|
||||
}
|
||||
@Override
|
||||
public void writeToNBT(final CompoundNBT data) {
|
||||
super.writeToNBT(data);
|
||||
this.config.writeToNBT(data, "config");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid( final Object verificationToken )
|
||||
{
|
||||
return this.handler == verificationToken;
|
||||
}
|
||||
@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 )
|
||||
{
|
||||
// :(
|
||||
}
|
||||
}
|
||||
@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;
|
||||
}
|
||||
public MEInventoryHandler<IAEFluidStack> getInternalHandler() {
|
||||
if (this.cached) {
|
||||
return this.handler;
|
||||
}
|
||||
|
||||
final boolean wasSleeping = this.monitor == null;
|
||||
final boolean wasSleeping = this.monitor == null;
|
||||
|
||||
this.cached = true;
|
||||
final TileEntity self = this.getHost().getTile();
|
||||
final TileEntity target = self.getWorld().getTileEntity( self.getPos().offset( this.getSide().getFacing() ) );
|
||||
final int newHandlerHash = this.createHandlerHash( target );
|
||||
this.cached = true;
|
||||
final TileEntity self = this.getHost().getTile();
|
||||
final TileEntity target = self.getWorld().getTileEntity(self.getPos().offset(this.getSide().getFacing()));
|
||||
final int newHandlerHash = this.createHandlerHash(target);
|
||||
|
||||
if( newHandlerHash != 0 && newHandlerHash == this.handlerHash )
|
||||
{
|
||||
return this.handler;
|
||||
}
|
||||
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 ) );
|
||||
}
|
||||
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() );
|
||||
if (inv != null) {
|
||||
this.checkInterfaceVsStorageBus(target, this.getSide().getOpposite());
|
||||
|
||||
this.handler = new MEInventoryHandler<>( inv, AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ) );
|
||||
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() );
|
||||
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 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 );
|
||||
}
|
||||
}
|
||||
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 (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 );
|
||||
}
|
||||
}
|
||||
}
|
||||
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 )
|
||||
{
|
||||
// :(
|
||||
}
|
||||
}
|
||||
// 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
|
||||
}
|
||||
try {
|
||||
// force grid to update handlers...
|
||||
this.getProxy().getGrid().postEvent(new MENetworkCellArrayUpdate());
|
||||
} catch (final GridAccessException ignore) {
|
||||
// :3
|
||||
}
|
||||
|
||||
return this.handler;
|
||||
}
|
||||
return this.handler;
|
||||
}
|
||||
|
||||
private void checkInterfaceVsStorageBus( final TileEntity target, final AEPartLocation side )
|
||||
{
|
||||
IInterfaceHost achievement = null;
|
||||
private void checkInterfaceVsStorageBus(final TileEntity target, final AEPartLocation side) {
|
||||
IInterfaceHost achievement = null;
|
||||
|
||||
if( target instanceof IInterfaceHost )
|
||||
{
|
||||
achievement = (IInterfaceHost) target;
|
||||
}
|
||||
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 (target instanceof IPartHost) {
|
||||
final Object part = ((IPartHost) target).getPart(side);
|
||||
if (part instanceof IInterfaceHost) {
|
||||
achievement = (IInterfaceHost) part;
|
||||
}
|
||||
}
|
||||
|
||||
if( achievement != null && achievement.getActionableNode() != null )
|
||||
{
|
||||
// Platform.addStat( achievement.getActionableNode().getPlayerID(), Achievements.Recursive.getAchievement()
|
||||
// );
|
||||
// Platform.addStat( getActionableNode().getPlayerID(), Achievements.Recursive.getAchievement() );
|
||||
}
|
||||
}
|
||||
if (achievement != null && achievement.getActionableNode() != null) {
|
||||
// Platform.addStat( achievement.getActionableNode().getPlayerID(),
|
||||
// Achievements.Recursive.getAchievement()
|
||||
// );
|
||||
// Platform.addStat( 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 );
|
||||
}
|
||||
@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( TileEntity target )
|
||||
{
|
||||
if( target == null )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
private int createHandlerHash(TileEntity target) {
|
||||
if (target == null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
final Direction targetSide = this.getSide().getFacing().getOpposite();
|
||||
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 ) );
|
||||
}
|
||||
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 );
|
||||
final IFluidHandler fluidHandler = target
|
||||
.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, targetSide).orElse(null);
|
||||
|
||||
if( fluidHandler != null )
|
||||
{
|
||||
return Objects.hash( target, fluidHandler, fluidHandler.getTanks() );
|
||||
}
|
||||
if (fluidHandler != null) {
|
||||
return Objects.hash(target, fluidHandler, fluidHandler.getTanks());
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickingRequest getTickingRequest( IGridNode node )
|
||||
{
|
||||
return new TickingRequest( TickRates.FluidStorageBus.getMin(), TickRates.FluidStorageBus.getMax(), this.isSleeping(), true );
|
||||
}
|
||||
@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 void onListUpdate() {
|
||||
// not used here.
|
||||
}
|
||||
|
||||
@Override
|
||||
public IStorageChannel getStorageChannel()
|
||||
{
|
||||
return AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class );
|
||||
}
|
||||
@Override
|
||||
public IStorageChannel getStorageChannel() {
|
||||
return AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class);
|
||||
}
|
||||
|
||||
public IAEFluidTank getConfig()
|
||||
{
|
||||
return this.config;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
@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 ItemStack getItemStackRepresentation() {
|
||||
return AEApi.instance().definitions().parts().fluidStorageBus().maybeStack(1).orElse(ItemStack.EMPTY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContainerType<?> getContainerType()
|
||||
{
|
||||
return ContainerFluidStorageBus.TYPE;
|
||||
}
|
||||
@Override
|
||||
public ContainerType<?> getContainerType() {
|
||||
return ContainerFluidStorageBus.TYPE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,8 +18,6 @@
|
||||
|
||||
package appeng.fluids.parts;
|
||||
|
||||
|
||||
import appeng.fluids.container.ContainerFluidTerminal;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.inventory.container.ContainerType;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -27,43 +25,38 @@ import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import appeng.api.parts.IPartModel;
|
||||
import appeng.core.AppEng;
|
||||
|
||||
import appeng.fluids.container.ContainerFluidTerminal;
|
||||
import appeng.items.parts.PartModels;
|
||||
import appeng.parts.PartModel;
|
||||
import appeng.parts.reporting.AbstractPartTerminal;
|
||||
|
||||
|
||||
/**
|
||||
* @author BrockWS
|
||||
* @version rv6 - 12/05/2018
|
||||
* @since rv6 12/05/2018
|
||||
*/
|
||||
public class PartFluidTerminal extends AbstractPartTerminal
|
||||
{
|
||||
public class PartFluidTerminal extends AbstractPartTerminal {
|
||||
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_OFF = new ResourceLocation( AppEng.MOD_ID, "part/fluid_terminal_off" );
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_ON = new ResourceLocation( AppEng.MOD_ID, "part/fluid_terminal_on" );
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_OFF = new ResourceLocation(AppEng.MOD_ID, "part/fluid_terminal_off");
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_ON = new ResourceLocation(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 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 PartFluidTerminal( ItemStack is )
|
||||
{
|
||||
super( is );
|
||||
}
|
||||
public PartFluidTerminal(ItemStack is) {
|
||||
super(is);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContainerType<?> getContainerType(PlayerEntity player )
|
||||
{
|
||||
return ContainerFluidTerminal.TYPE;
|
||||
}
|
||||
@Override
|
||||
public ContainerType<?> getContainerType(PlayerEntity player) {
|
||||
return ContainerFluidTerminal.TYPE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPartModel getStaticModels()
|
||||
{
|
||||
return this.selectModel( MODELS_OFF, MODELS_ON, MODELS_HAS_CHANNEL );
|
||||
}
|
||||
@Override
|
||||
public IPartModel getStaticModels() {
|
||||
return this.selectModel(MODELS_OFF, MODELS_ON, MODELS_HAS_CHANNEL);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,11 +18,6 @@
|
||||
|
||||
package appeng.fluids.parts;
|
||||
|
||||
|
||||
import appeng.container.ContainerLocator;
|
||||
import appeng.container.ContainerOpener;
|
||||
import appeng.fluids.container.ContainerFluidIO;
|
||||
import appeng.fluids.container.ContainerFluidInterface;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
@@ -43,156 +38,132 @@ 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.ContainerFluidIO;
|
||||
import appeng.fluids.container.ContainerFluidInterface;
|
||||
import appeng.fluids.util.AEFluidInventory;
|
||||
import appeng.fluids.util.IAEFluidTank;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.parts.automation.PartUpgradeable;
|
||||
import appeng.util.Platform;
|
||||
|
||||
|
||||
/**
|
||||
* @author BrockWS
|
||||
* @version rv6 - 30/04/2018
|
||||
* @since rv6 30/04/2018
|
||||
*/
|
||||
public abstract class PartSharedFluidBus extends PartUpgradeable implements IGridTickable
|
||||
{
|
||||
public abstract class PartSharedFluidBus extends PartUpgradeable implements IGridTickable {
|
||||
|
||||
private final AEFluidInventory config = new AEFluidInventory( null, 9 );
|
||||
private boolean lastRedstone;
|
||||
private final AEFluidInventory config = new AEFluidInventory(null, 9);
|
||||
private boolean lastRedstone;
|
||||
|
||||
public PartSharedFluidBus( ItemStack is )
|
||||
{
|
||||
super( is );
|
||||
}
|
||||
public PartSharedFluidBus(ItemStack is) {
|
||||
super(is);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void upgradesChanged()
|
||||
{
|
||||
this.updateState();
|
||||
}
|
||||
@Override
|
||||
public void upgradesChanged() {
|
||||
this.updateState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNeighborChanged( IBlockReader 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void onNeighborChanged(IBlockReader 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
|
||||
}
|
||||
}
|
||||
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(ContainerFluidIO.TYPE, player, ContainerLocator.forPart(this));
|
||||
}
|
||||
@Override
|
||||
public boolean onPartActivate(final PlayerEntity player, final Hand hand, final Vec3d pos) {
|
||||
if (Platform.isServer()) {
|
||||
ContainerOpener.openContainer(ContainerFluidIO.TYPE, player, ContainerLocator.forPart(this));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
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 );
|
||||
}
|
||||
@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 TileEntity getConnectedTE()
|
||||
{
|
||||
TileEntity self = this.getHost().getTile();
|
||||
return this.getTileEntity( self, self.getPos().offset( this.getSide().getFacing() ) );
|
||||
}
|
||||
protected TileEntity getConnectedTE() {
|
||||
TileEntity self = this.getHost().getTile();
|
||||
return this.getTileEntity(self, self.getPos().offset(this.getSide().getFacing()));
|
||||
}
|
||||
|
||||
private TileEntity getTileEntity( final TileEntity self, final BlockPos pos )
|
||||
{
|
||||
final World w = self.getWorld();
|
||||
private TileEntity getTileEntity(final TileEntity self, final BlockPos pos) {
|
||||
final World w = self.getWorld();
|
||||
|
||||
if( w.getChunkProvider().isChunkLoaded( new ChunkPos( pos ) ) )
|
||||
{
|
||||
return w.getTileEntity( pos );
|
||||
}
|
||||
if (w.getChunkProvider().isChunkLoaded(new ChunkPos(pos))) {
|
||||
return w.getTileEntity(pos);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
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 );
|
||||
}
|
||||
}
|
||||
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( CompoundNBT extra )
|
||||
{
|
||||
super.readFromNBT( extra );
|
||||
this.config.readFromNBT( extra, "config" );
|
||||
}
|
||||
@Override
|
||||
public void readFromNBT(CompoundNBT extra) {
|
||||
super.readFromNBT(extra);
|
||||
this.config.readFromNBT(extra, "config");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT( CompoundNBT extra )
|
||||
{
|
||||
super.writeToNBT( extra );
|
||||
this.config.writeToNBT( extra, "config" );
|
||||
}
|
||||
@Override
|
||||
public void writeToNBT(CompoundNBT extra) {
|
||||
super.writeToNBT(extra);
|
||||
this.config.writeToNBT(extra, "config");
|
||||
}
|
||||
|
||||
public IAEFluidTank getConfig()
|
||||
{
|
||||
return this.config;
|
||||
}
|
||||
public IAEFluidTank getConfig() {
|
||||
return this.config;
|
||||
}
|
||||
|
||||
protected IFluidStorageChannel getChannel()
|
||||
{
|
||||
return AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class );
|
||||
}
|
||||
protected IFluidStorageChannel getChannel() {
|
||||
return AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getCableConnectionLength( AECableType cable )
|
||||
{
|
||||
return 5;
|
||||
}
|
||||
@Override
|
||||
public float getCableConnectionLength(AECableType cable) {
|
||||
return 5;
|
||||
}
|
||||
|
||||
protected abstract TickRateModulation doBusWork();
|
||||
protected abstract TickRateModulation doBusWork();
|
||||
|
||||
protected abstract boolean canDoBusWork();
|
||||
protected abstract boolean canDoBusWork();
|
||||
}
|
||||
|
||||
@@ -18,11 +18,6 @@
|
||||
|
||||
package appeng.fluids.registries;
|
||||
|
||||
|
||||
import appeng.container.ContainerLocator;
|
||||
import appeng.container.ContainerOpener;
|
||||
import appeng.container.implementations.ContainerFormationPlane;
|
||||
import appeng.fluids.container.ContainerFluidTerminal;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
@@ -36,22 +31,23 @@ import appeng.api.storage.IStorageChannel;
|
||||
import appeng.api.storage.channels.IFluidStorageChannel;
|
||||
import appeng.api.storage.data.IAEStack;
|
||||
import appeng.api.util.AEPartLocation;
|
||||
|
||||
import appeng.container.ContainerLocator;
|
||||
import appeng.container.ContainerOpener;
|
||||
import appeng.container.implementations.ContainerFormationPlane;
|
||||
import appeng.fluids.container.ContainerFluidTerminal;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public class BasicFluidCellGuiHandler implements ICellGuiHandler {
|
||||
|
||||
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 <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(ContainerFluidTerminal.TYPE, player, ContainerLocator.forTileEntitySide((TileEntity) chest, chest.getUp()));
|
||||
}
|
||||
@Override
|
||||
public void openChestGui(final PlayerEntity player, final IChestOrDrive chest, final ICellHandler cellHandler,
|
||||
final IMEInventoryHandler inv, final ItemStack is, final IStorageChannel chan) {
|
||||
ContainerOpener.openContainer(ContainerFluidTerminal.TYPE, player,
|
||||
ContainerLocator.forTileEntitySide((TileEntity) chest, chest.getUp()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,12 +18,10 @@
|
||||
|
||||
package appeng.fluids.tile;
|
||||
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import appeng.fluids.container.ContainerFluidInterface;
|
||||
import net.minecraft.inventory.container.ContainerType;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
@@ -47,146 +45,123 @@ import appeng.api.util.AECableType;
|
||||
import appeng.api.util.AEPartLocation;
|
||||
import appeng.api.util.DimensionalCoord;
|
||||
import appeng.api.util.IConfigManager;
|
||||
|
||||
import appeng.fluids.container.ContainerFluidInterface;
|
||||
import appeng.fluids.helper.DualityFluidInterface;
|
||||
import appeng.fluids.helper.IFluidInterfaceHost;
|
||||
import appeng.helpers.IPriorityHost;
|
||||
import appeng.tile.grid.AENetworkTile;
|
||||
|
||||
public class TileFluidInterface extends AENetworkTile implements IGridTickable, IFluidInterfaceHost, IPriorityHost {
|
||||
private final DualityFluidInterface duality = new DualityFluidInterface(this.getProxy(), this);
|
||||
|
||||
public class TileFluidInterface extends AENetworkTile implements IGridTickable, IFluidInterfaceHost, IPriorityHost
|
||||
{
|
||||
private final DualityFluidInterface duality = new DualityFluidInterface( this.getProxy(), this );
|
||||
public TileFluidInterface(TileEntityType<?> tileEntityTypeIn) {
|
||||
super(tileEntityTypeIn);
|
||||
}
|
||||
|
||||
public TileFluidInterface(TileEntityType<?> tileEntityTypeIn) {
|
||||
super(tileEntityTypeIn);
|
||||
}
|
||||
@MENetworkEventSubscribe
|
||||
public void stateChange(final MENetworkChannelsChanged c) {
|
||||
this.duality.notifyNeighbors();
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void stateChange( final MENetworkChannelsChanged c )
|
||||
{
|
||||
this.duality.notifyNeighbors();
|
||||
}
|
||||
@MENetworkEventSubscribe
|
||||
public void stateChange(final MENetworkPowerStatusChange 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 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 TickRateModulation tickingRequest( IGridNode node, int ticksSinceLastCall )
|
||||
{
|
||||
return this.duality.tickingRequest( node, ticksSinceLastCall );
|
||||
}
|
||||
@Override
|
||||
public DualityFluidInterface getDualityFluidInterface() {
|
||||
return this.duality;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DualityFluidInterface getDualityFluidInterface()
|
||||
{
|
||||
return this.duality;
|
||||
}
|
||||
@Override
|
||||
public TileEntity getTileEntity() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity getTileEntity()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
@Override
|
||||
public void gridChanged() {
|
||||
this.duality.gridChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void gridChanged()
|
||||
{
|
||||
this.duality.gridChanged();
|
||||
}
|
||||
@Override
|
||||
public CompoundNBT write(final CompoundNBT data) {
|
||||
super.write(data);
|
||||
this.duality.writeToNBT(data);
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundNBT write(final CompoundNBT data )
|
||||
{
|
||||
super.write( data );
|
||||
this.duality.writeToNBT( data );
|
||||
return data;
|
||||
}
|
||||
@Override
|
||||
public void read(final CompoundNBT data) {
|
||||
super.read(data);
|
||||
this.duality.readFromNBT(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(final CompoundNBT data )
|
||||
{
|
||||
super.read( data );
|
||||
this.duality.readFromNBT( data );
|
||||
}
|
||||
@Override
|
||||
public AECableType getCableConnectionType(final AEPartLocation dir) {
|
||||
return this.duality.getCableConnectionType(dir);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AECableType getCableConnectionType( final AEPartLocation dir )
|
||||
{
|
||||
return this.duality.getCableConnectionType( dir );
|
||||
}
|
||||
@Override
|
||||
public DimensionalCoord getLocation() {
|
||||
return this.duality.getLocation();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DimensionalCoord getLocation()
|
||||
{
|
||||
return this.duality.getLocation();
|
||||
}
|
||||
@Override
|
||||
public EnumSet<Direction> getTargets() {
|
||||
return EnumSet.allOf(Direction.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumSet<Direction> getTargets()
|
||||
{
|
||||
return EnumSet.allOf( Direction.class );
|
||||
}
|
||||
@Override
|
||||
public int getPriority() {
|
||||
return this.duality.getPriority();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPriority()
|
||||
{
|
||||
return this.duality.getPriority();
|
||||
}
|
||||
@Override
|
||||
public void setPriority(final int newValue) {
|
||||
this.duality.setPriority(newValue);
|
||||
}
|
||||
|
||||
@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 <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 int getInstalledUpgrades( Upgrades u )
|
||||
{
|
||||
return this.duality.getInstalledUpgrades( u );
|
||||
}
|
||||
@Override
|
||||
public IConfigManager getConfigManager() {
|
||||
return this.duality.getConfigManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IConfigManager getConfigManager()
|
||||
{
|
||||
return this.duality.getConfigManager();
|
||||
}
|
||||
@Override
|
||||
public IItemHandler getInventoryByName(String name) {
|
||||
return this.duality.getInventoryByName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemHandler 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 ItemStack getItemStackRepresentation()
|
||||
{
|
||||
return AEApi.instance().definitions().blocks().fluidIface().maybeStack( 1 ).orElse( ItemStack.EMPTY );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContainerType<?> getContainerType()
|
||||
{
|
||||
return ContainerFluidInterface.TYPE;
|
||||
}
|
||||
@Override
|
||||
public ContainerType<?> getContainerType() {
|
||||
return ContainerFluidInterface.TYPE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
|
||||
package appeng.fluids.util;
|
||||
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
@@ -11,373 +12,300 @@ import appeng.api.storage.data.IAEFluidStack;
|
||||
import appeng.core.AELog;
|
||||
import appeng.util.Platform;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
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 class AEFluidInventory implements IAEFluidTank
|
||||
{
|
||||
private final IAEFluidStack[] fluids;
|
||||
private final IAEFluidInventory handler;
|
||||
private final int capacity;
|
||||
public AEFluidInventory(final IAEFluidInventory handler, final int slots) {
|
||||
this(handler, slots, Integer.MAX_VALUE);
|
||||
}
|
||||
|
||||
public AEFluidInventory( final IAEFluidInventory handler, final int slots, final int capacity )
|
||||
{
|
||||
this.fluids = new IAEFluidStack[slots];
|
||||
this.handler = handler;
|
||||
this.capacity = capacity;
|
||||
}
|
||||
@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));
|
||||
}
|
||||
|
||||
public AEFluidInventory( final IAEFluidInventory handler, final int slots )
|
||||
{
|
||||
this( handler, slots, Integer.MAX_VALUE );
|
||||
}
|
||||
this.onContentChanged(slot);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@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 ) );
|
||||
}
|
||||
private void onContentChanged(final int slot) {
|
||||
if (this.handler != null && Platform.isServer()) {
|
||||
this.handler.onFluidInventoryChanged(this, slot);
|
||||
}
|
||||
}
|
||||
|
||||
this.onContentChanged( slot );
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public IAEFluidStack getFluidInSlot(final int slot) {
|
||||
if (slot >= 0 && slot < this.getSlots()) {
|
||||
return this.fluids[slot];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void onContentChanged( final int slot )
|
||||
{
|
||||
if( this.handler != null && Platform.isServer() )
|
||||
{
|
||||
this.handler.onFluidInventoryChanged( this, slot );
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public int getSlots() {
|
||||
return this.fluids.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEFluidStack getFluidInSlot( final int slot )
|
||||
{
|
||||
if( slot >= 0 && slot < this.getSlots() )
|
||||
{
|
||||
return this.fluids[slot];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public int getTanks() {
|
||||
return this.fluids.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlots()
|
||||
{
|
||||
return this.fluids.length;
|
||||
}
|
||||
@Nonnull
|
||||
@Override
|
||||
public FluidStack getFluidInTank(int tank) {
|
||||
if (tank < 0 || tank >= fluids.length) {
|
||||
return FluidStack.EMPTY;
|
||||
}
|
||||
return fluids[tank] == null ? FluidStack.EMPTY : fluids[tank].getFluidStack();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTanks() {
|
||||
return this.fluids.length;
|
||||
}
|
||||
@Override
|
||||
public int getTankCapacity(int tank) {
|
||||
return Math.min(this.capacity, Integer.MAX_VALUE);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public FluidStack getFluidInTank(int tank) {
|
||||
if (tank < 0 || tank >= fluids.length) {
|
||||
return FluidStack.EMPTY;
|
||||
}
|
||||
return fluids[tank] == null ? FluidStack.EMPTY : fluids[tank].getFluidStack();
|
||||
}
|
||||
@Override
|
||||
public boolean isFluidValid(int tank, @Nonnull FluidStack stack) {
|
||||
return stack != FluidStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTankCapacity(int tank) {
|
||||
return Math.min( this.capacity, Integer.MAX_VALUE );
|
||||
}
|
||||
public int fill(final int slot, final FluidStack resource, final boolean doFill) {
|
||||
if (resource.isEmpty() || resource.getAmount() <= 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFluidValid(int tank, @Nonnull FluidStack stack) {
|
||||
return stack != FluidStack.EMPTY;
|
||||
}
|
||||
final IAEFluidStack fluid = this.fluids[slot];
|
||||
|
||||
public int fill( final int slot, final FluidStack resource, final boolean doFill )
|
||||
{
|
||||
if( resource.isEmpty()|| resource.getAmount() <= 0 )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (fluid != null && !fluid.getFluidStack().equals(resource)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
final IAEFluidStack fluid = this.fluids[slot];
|
||||
int amountToStore = this.capacity;
|
||||
|
||||
if( fluid != null && !fluid.getFluidStack().equals( resource ) )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (fluid != null) {
|
||||
amountToStore -= fluid.getStackSize();
|
||||
}
|
||||
|
||||
int amountToStore = this.capacity;
|
||||
amountToStore = Math.min(amountToStore, resource.getAmount());
|
||||
|
||||
if( fluid != null )
|
||||
{
|
||||
amountToStore -= fluid.getStackSize();
|
||||
}
|
||||
if (doFill) {
|
||||
if (fluid == null) {
|
||||
this.setFluidInSlot(slot, AEFluidStack.fromFluidStack(resource));
|
||||
} else {
|
||||
fluid.setStackSize(fluid.getStackSize() + amountToStore);
|
||||
this.onContentChanged(slot);
|
||||
}
|
||||
}
|
||||
|
||||
amountToStore = Math.min( amountToStore, resource.getAmount() );
|
||||
return amountToStore;
|
||||
}
|
||||
|
||||
if( doFill )
|
||||
{
|
||||
if( fluid == null )
|
||||
{
|
||||
this.setFluidInSlot( slot, AEFluidStack.fromFluidStack( resource ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
fluid.setStackSize( fluid.getStackSize() + amountToStore );
|
||||
this.onContentChanged( slot );
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public int fill(FluidStack resource, FluidAction action) {
|
||||
if (resource == null || resource.isEmpty() || resource.getAmount() <= 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return amountToStore;
|
||||
}
|
||||
// Find a suitable slot
|
||||
int slot = indexOfFluid(resource);
|
||||
if (slot == -1) {
|
||||
slot = indexOfEmptySlot();
|
||||
if (slot == -1) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int fill(FluidStack resource, FluidAction action) {
|
||||
if( resource == null || resource.isEmpty() || resource.getAmount() <= 0 )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
final IAEFluidStack fluid = this.fluids[slot];
|
||||
|
||||
// Find a suitable slot
|
||||
int slot = indexOfFluid(resource);
|
||||
if (slot == -1) {
|
||||
slot = indexOfEmptySlot();
|
||||
if (slot == -1) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
int amountToStore = this.capacity;
|
||||
|
||||
final IAEFluidStack fluid = this.fluids[slot];
|
||||
if (fluid != null) {
|
||||
amountToStore -= fluid.getStackSize();
|
||||
}
|
||||
|
||||
int amountToStore = this.capacity;
|
||||
amountToStore = Math.min(amountToStore, resource.getAmount());
|
||||
|
||||
if( fluid != null )
|
||||
{
|
||||
amountToStore -= fluid.getStackSize();
|
||||
}
|
||||
if (action == FluidAction.EXECUTE) {
|
||||
if (fluid == null) {
|
||||
this.setFluidInSlot(slot, AEFluidStack.fromFluidStack(resource));
|
||||
} else {
|
||||
fluid.setStackSize(fluid.getStackSize() + amountToStore);
|
||||
this.onContentChanged(slot);
|
||||
}
|
||||
}
|
||||
|
||||
amountToStore = Math.min( amountToStore, resource.getAmount() );
|
||||
return amountToStore;
|
||||
}
|
||||
|
||||
if( action == FluidAction.EXECUTE )
|
||||
{
|
||||
if( fluid == null )
|
||||
{
|
||||
this.setFluidInSlot( slot, AEFluidStack.fromFluidStack( resource ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
fluid.setStackSize( fluid.getStackSize() + amountToStore );
|
||||
this.onContentChanged( slot );
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public FluidStack drain(final FluidStack fluid, final FluidAction action) {
|
||||
if (fluid == null || fluid.getAmount() <= 0) {
|
||||
return FluidStack.EMPTY;
|
||||
}
|
||||
|
||||
return amountToStore;
|
||||
}
|
||||
final FluidStack resource = fluid.copy();
|
||||
|
||||
@Override
|
||||
public FluidStack drain( final FluidStack fluid, final FluidAction action )
|
||||
{
|
||||
if( fluid == null || fluid.getAmount() <= 0 )
|
||||
{
|
||||
return FluidStack.EMPTY;
|
||||
}
|
||||
FluidStack totalDrained = FluidStack.EMPTY;
|
||||
for (int slot = 0; slot < this.getSlots(); ++slot) {
|
||||
FluidStack drain = this.drain(slot, resource, action == FluidAction.EXECUTE);
|
||||
if (drain != null) {
|
||||
if (totalDrained.isEmpty()) {
|
||||
totalDrained = drain;
|
||||
} else {
|
||||
totalDrained.setAmount(totalDrained.getAmount() + drain.getAmount());
|
||||
}
|
||||
|
||||
final FluidStack resource = fluid.copy();
|
||||
resource.setAmount(resource.getAmount() - drain.getAmount());
|
||||
if (resource.getAmount() <= 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return totalDrained;
|
||||
}
|
||||
|
||||
FluidStack totalDrained = FluidStack.EMPTY;
|
||||
for( int slot = 0; slot < this.getSlots(); ++slot )
|
||||
{
|
||||
FluidStack drain = this.drain( slot, resource, action == FluidAction.EXECUTE );
|
||||
if( drain != null )
|
||||
{
|
||||
if( totalDrained.isEmpty() )
|
||||
{
|
||||
totalDrained = drain;
|
||||
}
|
||||
else
|
||||
{
|
||||
totalDrained.setAmount(totalDrained.getAmount() + drain.getAmount());
|
||||
}
|
||||
@Override
|
||||
public FluidStack drain(final int maxDrain, final FluidAction action) {
|
||||
if (maxDrain == 0) {
|
||||
return FluidStack.EMPTY;
|
||||
}
|
||||
|
||||
resource.setAmount(resource.getAmount() - drain.getAmount());
|
||||
if( resource.getAmount() <= 0 )
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return totalDrained;
|
||||
}
|
||||
FluidStack totalDrained = FluidStack.EMPTY;
|
||||
int toDrain = maxDrain;
|
||||
|
||||
@Override
|
||||
public FluidStack drain( final int maxDrain, final FluidAction action )
|
||||
{
|
||||
if( maxDrain == 0 )
|
||||
{
|
||||
return FluidStack.EMPTY;
|
||||
}
|
||||
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 {
|
||||
FluidStack copy = totalDrained.copy();
|
||||
copy.setAmount(toDrain);
|
||||
FluidStack drain = this.drain(slot, copy, action == FluidAction.EXECUTE);
|
||||
if (drain != null) {
|
||||
totalDrained.setAmount(totalDrained.getAmount() + drain.getAmount());
|
||||
toDrain -= drain.getAmount();
|
||||
}
|
||||
}
|
||||
|
||||
FluidStack totalDrained = FluidStack.EMPTY;
|
||||
int toDrain = maxDrain;
|
||||
if (toDrain <= 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return totalDrained;
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
FluidStack copy = totalDrained.copy();
|
||||
copy.setAmount(toDrain);
|
||||
FluidStack drain = this.drain( slot, copy, action == FluidAction.EXECUTE );
|
||||
if( drain != null )
|
||||
{
|
||||
totalDrained.setAmount(totalDrained.getAmount() + drain.getAmount());
|
||||
toDrain -= drain.getAmount();
|
||||
}
|
||||
}
|
||||
private int indexOfFluid(FluidStack resource) {
|
||||
for (int slot = 0; slot < fluids.length; slot++) {
|
||||
if (fluids[slot] != null && fluids[slot].getFluidStack().isFluidEqual(resource)) {
|
||||
return slot;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
if( toDrain <= 0 )
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
return totalDrained;
|
||||
}
|
||||
private int indexOfEmptySlot() {
|
||||
for (int slot = 0; slot < fluids.length; slot++) {
|
||||
if (fluids[slot] == null) {
|
||||
return slot;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
private int indexOfFluid(FluidStack resource) {
|
||||
for (int slot = 0; slot < fluids.length; slot++) {
|
||||
if (fluids[slot] != null && fluids[slot].getFluidStack().isFluidEqual(resource)) {
|
||||
return slot;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
public FluidStack drain(final int slot, final FluidStack 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);
|
||||
}
|
||||
|
||||
private int indexOfEmptySlot() {
|
||||
for (int slot = 0; slot < fluids.length; slot++) {
|
||||
if (fluids[slot] == null) {
|
||||
return slot;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
public FluidStack drain(final int slot, final int maxDrain, boolean doDrain) {
|
||||
final IAEFluidStack fluid = this.fluids[slot];
|
||||
if (fluid == null || maxDrain <= 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public FluidStack drain( final int slot, final FluidStack 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 );
|
||||
}
|
||||
int drained = maxDrain;
|
||||
if (fluid.getStackSize() < drained) {
|
||||
drained = (int) fluid.getStackSize();
|
||||
}
|
||||
|
||||
public FluidStack drain( final int slot, final int maxDrain, boolean doDrain )
|
||||
{
|
||||
final IAEFluidStack fluid = this.fluids[slot];
|
||||
if( fluid == null || maxDrain <= 0 )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
FluidStack stack = new FluidStack(fluid.getFluid(), drained);
|
||||
if (doDrain) {
|
||||
fluid.setStackSize(fluid.getStackSize() - drained);
|
||||
if (fluid.getStackSize() <= 0) {
|
||||
this.fluids[slot] = null;
|
||||
}
|
||||
this.onContentChanged(slot);
|
||||
}
|
||||
return stack;
|
||||
}
|
||||
|
||||
int drained = maxDrain;
|
||||
if( fluid.getStackSize() < drained )
|
||||
{
|
||||
drained = (int) fluid.getStackSize();
|
||||
}
|
||||
public void writeToNBT(final CompoundNBT data, final String name) {
|
||||
final CompoundNBT c = new CompoundNBT();
|
||||
this.writeToNBT(c);
|
||||
data.put(name, c);
|
||||
}
|
||||
|
||||
FluidStack stack = new FluidStack( fluid.getFluid(), drained );
|
||||
if( doDrain )
|
||||
{
|
||||
fluid.setStackSize( fluid.getStackSize() - drained );
|
||||
if( fluid.getStackSize() <= 0 )
|
||||
{
|
||||
this.fluids[slot] = null;
|
||||
}
|
||||
this.onContentChanged( slot );
|
||||
}
|
||||
return stack;
|
||||
}
|
||||
private void writeToNBT(final CompoundNBT target) {
|
||||
for (int x = 0; x < this.fluids.length; x++) {
|
||||
try {
|
||||
final CompoundNBT c = new CompoundNBT();
|
||||
|
||||
public void writeToNBT( final CompoundNBT data, final String name )
|
||||
{
|
||||
final CompoundNBT c = new CompoundNBT();
|
||||
this.writeToNBT( c );
|
||||
data.put( name, c );
|
||||
}
|
||||
if (this.fluids[x] != null) {
|
||||
this.fluids[x].writeToNBT(c);
|
||||
}
|
||||
|
||||
private void writeToNBT( final CompoundNBT target )
|
||||
{
|
||||
for( int x = 0; x < this.fluids.length; x++ )
|
||||
{
|
||||
try
|
||||
{
|
||||
final CompoundNBT c = new CompoundNBT();
|
||||
target.put("#" + x, c);
|
||||
} catch (final Exception ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( this.fluids[x] != null )
|
||||
{
|
||||
this.fluids[x].writeToNBT( c );
|
||||
}
|
||||
public void readFromNBT(final CompoundNBT data, final String name) {
|
||||
final CompoundNBT c = data.getCompound(name);
|
||||
if (!c.isEmpty()) {
|
||||
this.readFromNBT(c);
|
||||
}
|
||||
}
|
||||
|
||||
target.put( "#" + x, c );
|
||||
}
|
||||
catch( final Exception ignored )
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
private void readFromNBT(final CompoundNBT target) {
|
||||
for (int x = 0; x < this.fluids.length; x++) {
|
||||
try {
|
||||
final CompoundNBT c = target.getCompound("#" + x);
|
||||
|
||||
public void readFromNBT( final CompoundNBT data, final String name )
|
||||
{
|
||||
final CompoundNBT c = data.getCompound( name );
|
||||
if( !c.isEmpty() )
|
||||
{
|
||||
this.readFromNBT( c );
|
||||
}
|
||||
}
|
||||
|
||||
private void readFromNBT( final CompoundNBT target )
|
||||
{
|
||||
for( int x = 0; x < this.fluids.length; x++ )
|
||||
{
|
||||
try
|
||||
{
|
||||
final CompoundNBT c = target.getCompound( "#" + x );
|
||||
|
||||
if( !c.isEmpty() )
|
||||
{
|
||||
this.fluids[x] = AEFluidStack.fromNBT( c );
|
||||
}
|
||||
}
|
||||
catch( final Exception e )
|
||||
{
|
||||
AELog.debug( e );
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!c.isEmpty()) {
|
||||
this.fluids[x] = AEFluidStack.fromNBT(c);
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
AELog.debug(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.fluids.util;
|
||||
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import net.minecraft.fluid.Fluid;
|
||||
@@ -36,261 +35,221 @@ 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_FLUIDSTACK = "fs";
|
||||
|
||||
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_FLUIDSTACK = "fs";
|
||||
private final Fluid fluid;
|
||||
private CompoundNBT tagCompound;
|
||||
|
||||
private final Fluid fluid;
|
||||
private CompoundNBT tagCompound;
|
||||
private AEFluidStack(final AEFluidStack fluidStack) {
|
||||
this.fluid = fluidStack.fluid;
|
||||
this.setStackSize(fluidStack.getStackSize());
|
||||
|
||||
private AEFluidStack( final AEFluidStack fluidStack )
|
||||
{
|
||||
this.fluid = fluidStack.fluid;
|
||||
this.setStackSize( fluidStack.getStackSize() );
|
||||
// priority = is.priority;
|
||||
this.setCraftable(fluidStack.isCraftable());
|
||||
this.setCountRequestable(fluidStack.getCountRequestable());
|
||||
|
||||
// priority = is.priority;
|
||||
this.setCraftable( fluidStack.isCraftable() );
|
||||
this.setCountRequestable( fluidStack.getCountRequestable() );
|
||||
if (fluidStack.hasTagCompound()) {
|
||||
this.tagCompound = fluidStack.tagCompound.copy();
|
||||
}
|
||||
}
|
||||
|
||||
if( fluidStack.hasTagCompound() )
|
||||
{
|
||||
this.tagCompound = fluidStack.tagCompound.copy();
|
||||
}
|
||||
}
|
||||
private AEFluidStack(@Nonnull final FluidStack fluidStack) {
|
||||
this.fluid = fluidStack.getFluid();
|
||||
|
||||
private AEFluidStack( @Nonnull final FluidStack fluidStack )
|
||||
{
|
||||
this.fluid = fluidStack.getFluid();
|
||||
if (this.fluid == null) {
|
||||
throw new IllegalArgumentException("Fluid is null.");
|
||||
}
|
||||
|
||||
if( this.fluid == null )
|
||||
{
|
||||
throw new IllegalArgumentException( "Fluid is null." );
|
||||
}
|
||||
this.setStackSize(fluidStack.getAmount());
|
||||
this.setCraftable(false);
|
||||
this.setCountRequestable(0);
|
||||
|
||||
this.setStackSize( fluidStack.getAmount() );
|
||||
this.setCraftable( false );
|
||||
this.setCountRequestable( 0 );
|
||||
if (fluidStack.getTag() != null) {
|
||||
this.tagCompound = fluidStack.getTag().copy();
|
||||
}
|
||||
}
|
||||
|
||||
if( fluidStack.getTag() != null )
|
||||
{
|
||||
this.tagCompound = fluidStack.getTag().copy();
|
||||
}
|
||||
}
|
||||
public static AEFluidStack fromFluidStack(final FluidStack input) {
|
||||
if (input == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static AEFluidStack fromFluidStack( final FluidStack input )
|
||||
{
|
||||
if( input == null )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new AEFluidStack(input);
|
||||
}
|
||||
|
||||
return new AEFluidStack( input );
|
||||
}
|
||||
public static IAEFluidStack fromNBT(final CompoundNBT data) {
|
||||
final FluidStack fluidStack = FluidStack.loadFluidStackFromNBT(data.getCompound(NBT_FLUIDSTACK));
|
||||
|
||||
public static IAEFluidStack fromNBT( final CompoundNBT data )
|
||||
{
|
||||
final FluidStack fluidStack = FluidStack.loadFluidStackFromNBT( data.getCompound( NBT_FLUIDSTACK ) );
|
||||
if (fluidStack == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if( fluidStack == null )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
final AEFluidStack fluid = AEFluidStack.fromFluidStack(fluidStack);
|
||||
fluid.setStackSize(data.getLong(NBT_STACKSIZE));
|
||||
fluid.setCountRequestable(data.getLong(NBT_REQUESTABLE));
|
||||
fluid.setCraftable(data.getBoolean(NBT_CRAFTABLE));
|
||||
|
||||
final AEFluidStack fluid = AEFluidStack.fromFluidStack( fluidStack );
|
||||
fluid.setStackSize( data.getLong( NBT_STACKSIZE ) );
|
||||
fluid.setCountRequestable( data.getLong( NBT_REQUESTABLE ) );
|
||||
fluid.setCraftable( data.getBoolean( NBT_CRAFTABLE ) );
|
||||
if (fluid.hasTagCompound()) {
|
||||
fluid.tagCompound = fluid.tagCompound.copy();
|
||||
}
|
||||
|
||||
if( fluid.hasTagCompound() )
|
||||
{
|
||||
fluid.tagCompound = fluid.tagCompound.copy();
|
||||
}
|
||||
return fluid;
|
||||
}
|
||||
|
||||
return fluid;
|
||||
}
|
||||
@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 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 CompoundNBT data) {
|
||||
data.getCompound(NBT_FLUIDSTACK).putString("FluidName", this.fluid.getRegistryName().toString());
|
||||
data.getCompound(NBT_FLUIDSTACK).putInt("Amount", 0);
|
||||
if (this.hasTagCompound()) {
|
||||
data.getCompound(NBT_FLUIDSTACK).put("Tag", this.tagCompound);
|
||||
} else {
|
||||
data.getCompound(NBT_FLUIDSTACK).remove("Tag");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT( final CompoundNBT data )
|
||||
{
|
||||
data.getCompound( NBT_FLUIDSTACK ).putString( "FluidName", this.fluid.getRegistryName().toString() );
|
||||
data.getCompound( NBT_FLUIDSTACK ).putInt( "Amount", 0 );
|
||||
if( this.hasTagCompound() )
|
||||
{
|
||||
data.getCompound( NBT_FLUIDSTACK ).put( "Tag", this.tagCompound );
|
||||
}
|
||||
else
|
||||
{
|
||||
data.getCompound( NBT_FLUIDSTACK ).remove( "Tag" );
|
||||
}
|
||||
data.putLong(NBT_STACKSIZE, this.getStackSize());
|
||||
data.putLong(NBT_REQUESTABLE, this.getCountRequestable());
|
||||
data.putBoolean(NBT_CRAFTABLE, this.isCraftable());
|
||||
}
|
||||
|
||||
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 boolean fuzzyComparison( final IAEFluidStack other, final FuzzyMode mode )
|
||||
{
|
||||
return this.fluid == other.getFluid();
|
||||
}
|
||||
@Override
|
||||
public IAEFluidStack copy() {
|
||||
return new AEFluidStack(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEFluidStack copy()
|
||||
{
|
||||
return new AEFluidStack( this );
|
||||
}
|
||||
@Override
|
||||
public IAEFluidStack empty() {
|
||||
final IAEFluidStack dup = this.copy();
|
||||
dup.reset();
|
||||
return dup;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEFluidStack empty()
|
||||
{
|
||||
final IAEFluidStack dup = this.copy();
|
||||
dup.reset();
|
||||
return dup;
|
||||
}
|
||||
@Override
|
||||
public boolean isItem() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItem()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean isFluid() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFluid()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public IStorageChannel<IAEFluidStack> getChannel() {
|
||||
return AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class);
|
||||
}
|
||||
|
||||
@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.getRegistryName().compareTo(other.fluid.getRegistryName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo( final AEFluidStack other )
|
||||
{
|
||||
if( this.fluid != other.fluid )
|
||||
{
|
||||
return this.fluid.getRegistryName().compareTo( other.fluid.getRegistryName() );
|
||||
}
|
||||
if (Platform.itemComparisons().isNbtTagEqual(this.tagCompound, other.tagCompound)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if( Platform.itemComparisons().isNbtTagEqual( this.tagCompound, other.tagCompound ) )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return this.tagCompound.hashCode() - other.tagCompound.hashCode();
|
||||
}
|
||||
|
||||
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());
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
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 FluidStack) {
|
||||
final FluidStack is = (FluidStack) other;
|
||||
return is.getFluid() == this.fluid
|
||||
&& Platform.itemComparisons().isNbtTagEqual(this.tagCompound, is.getTag());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@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 FluidStack )
|
||||
{
|
||||
final FluidStack is = (FluidStack) other;
|
||||
return is.getFluid() == this.fluid && Platform.itemComparisons().isNbtTagEqual( this.tagCompound, is.getTag() );
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.getStackSize() + "x" + this.getFluidStack().getFluid().getRegistryName() + " " + this.tagCompound;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return this.getStackSize() + "x" + this.getFluidStack().getFluid().getRegistryName() + " " + this.tagCompound;
|
||||
}
|
||||
@Override
|
||||
public boolean hasTagCompound() {
|
||||
return this.tagCompound != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTagCompound()
|
||||
{
|
||||
return this.tagCompound != null;
|
||||
}
|
||||
@Override
|
||||
public FluidStack getFluidStack() {
|
||||
final int amount = (int) Math.min(Integer.MAX_VALUE, this.getStackSize());
|
||||
final FluidStack is = new FluidStack(this.fluid, amount, this.tagCompound);
|
||||
|
||||
@Override
|
||||
public FluidStack getFluidStack()
|
||||
{
|
||||
final int amount = (int) Math.min( Integer.MAX_VALUE, this.getStackSize() );
|
||||
final FluidStack is = new FluidStack( this.fluid, amount, this.tagCompound );
|
||||
return is;
|
||||
}
|
||||
|
||||
return is;
|
||||
}
|
||||
@Override
|
||||
public Fluid getFluid() {
|
||||
return this.fluid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Fluid 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;
|
||||
}
|
||||
|
||||
@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 PacketBuffer buffer) {
|
||||
final boolean isCraftable = buffer.readBoolean();
|
||||
final FluidStack fluidStack = buffer.readFluidStack();
|
||||
|
||||
public static IAEFluidStack fromPacket( final PacketBuffer buffer )
|
||||
{
|
||||
final boolean isCraftable = buffer.readBoolean();
|
||||
final FluidStack fluidStack = buffer.readFluidStack();
|
||||
final long stackSize = buffer.readVarLong();
|
||||
final long countRequestable = buffer.readVarLong();
|
||||
|
||||
final long stackSize = buffer.readVarLong();
|
||||
final long countRequestable = buffer.readVarLong();
|
||||
if (fluidStack == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if( fluidStack == null )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
final AEFluidStack fluid = AEFluidStack.fromFluidStack(fluidStack);
|
||||
fluid.setStackSize(stackSize);
|
||||
fluid.setCountRequestable(countRequestable);
|
||||
fluid.setCraftable(isCraftable);
|
||||
return fluid;
|
||||
}
|
||||
|
||||
final AEFluidStack fluid = AEFluidStack.fromFluidStack( fluidStack );
|
||||
fluid.setStackSize( stackSize );
|
||||
fluid.setCountRequestable( countRequestable );
|
||||
fluid.setCraftable( isCraftable );
|
||||
return fluid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToPacket( final PacketBuffer buffer )
|
||||
{
|
||||
buffer.writeBoolean( this.isCraftable() );
|
||||
buffer.writeFluidStack( this.getFluidStack() );
|
||||
buffer.writeVarLong( this.getStackSize() );
|
||||
buffer.writeVarLong( this.getCountRequestable() );
|
||||
}
|
||||
@Override
|
||||
public void writeToPacket(final PacketBuffer buffer) {
|
||||
buffer.writeBoolean(this.isCraftable());
|
||||
buffer.writeFluidStack(this.getFluidStack());
|
||||
buffer.writeVarLong(this.getStackSize());
|
||||
buffer.writeVarLong(this.getCountRequestable());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,60 +18,50 @@
|
||||
|
||||
package appeng.fluids.util;
|
||||
|
||||
import net.minecraftforge.fluids.capability.templates.FluidTank;
|
||||
|
||||
import appeng.api.storage.data.IAEFluidStack;
|
||||
import appeng.util.Platform;
|
||||
import net.minecraftforge.fluids.capability.templates.FluidTank;
|
||||
|
||||
public class AEFluidTank extends FluidTank implements IAEFluidTank {
|
||||
private final IAEFluidInventory host;
|
||||
|
||||
public class AEFluidTank extends FluidTank implements IAEFluidTank
|
||||
{
|
||||
private final IAEFluidInventory host;
|
||||
|
||||
public AEFluidTank( IAEFluidInventory host, int capacity )
|
||||
{
|
||||
super( capacity );
|
||||
this.host = host;
|
||||
public AEFluidTank(IAEFluidInventory host, int capacity) {
|
||||
super(capacity);
|
||||
this.host = host;
|
||||
// FIXME if( host instanceof TileEntity )
|
||||
// FIXME {
|
||||
// FIXME this.setTileEntity( (TileEntity) host );
|
||||
// FIXME }
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onContentsChanged()
|
||||
{
|
||||
if( this.host != null && Platform.isServer() )
|
||||
{
|
||||
this.host.onFluidInventoryChanged( this, 0 );
|
||||
}
|
||||
super.onContentsChanged();
|
||||
}
|
||||
@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 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 IAEFluidStack getFluidInSlot(int slot) {
|
||||
if (slot == 0) {
|
||||
return AEFluidStack.fromFluidStack(this.getFluid());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlots()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
@Override
|
||||
public int getSlots() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.fluids.util;
|
||||
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
@@ -29,173 +28,147 @@ import appeng.api.config.FuzzyMode;
|
||||
import appeng.api.storage.data.IAEFluidStack;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
|
||||
public final class FluidList implements IItemList<IAEFluidStack> {
|
||||
|
||||
public final class FluidList implements IItemList<IAEFluidStack>
|
||||
{
|
||||
private final Map<IAEFluidStack, IAEFluidStack> records = new HashMap<>();
|
||||
|
||||
private final Map<IAEFluidStack, IAEFluidStack> records = new HashMap<>();
|
||||
@Override
|
||||
public void add(final IAEFluidStack option) {
|
||||
if (option == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add( final IAEFluidStack option )
|
||||
{
|
||||
if( option == null )
|
||||
{
|
||||
return;
|
||||
}
|
||||
final IAEFluidStack st = this.getFluidRecord(option);
|
||||
|
||||
final IAEFluidStack st = this.getFluidRecord( option );
|
||||
if (st != null) {
|
||||
st.add(option);
|
||||
return;
|
||||
}
|
||||
|
||||
if( st != null )
|
||||
{
|
||||
st.add( option );
|
||||
return;
|
||||
}
|
||||
final IAEFluidStack opt = option.copy();
|
||||
|
||||
final IAEFluidStack opt = option.copy();
|
||||
this.putFluidRecord(opt);
|
||||
}
|
||||
|
||||
this.putFluidRecord( opt );
|
||||
}
|
||||
@Override
|
||||
public IAEFluidStack findPrecise(final IAEFluidStack fluidStack) {
|
||||
if (fluidStack == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEFluidStack findPrecise( final IAEFluidStack fluidStack )
|
||||
{
|
||||
if( fluidStack == null )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return this.getFluidRecord(fluidStack);
|
||||
}
|
||||
|
||||
return this.getFluidRecord( fluidStack );
|
||||
}
|
||||
@Override
|
||||
public Collection<IAEFluidStack> findFuzzy(final IAEFluidStack filter, final FuzzyMode fuzzy) {
|
||||
if (filter == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<IAEFluidStack> findFuzzy( final IAEFluidStack filter, final FuzzyMode fuzzy )
|
||||
{
|
||||
if( filter == null )
|
||||
{
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return Collections.singletonList(this.findPrecise(filter));
|
||||
}
|
||||
|
||||
return Collections.singletonList( this.findPrecise( filter ) );
|
||||
}
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return !this.iterator().hasNext();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty()
|
||||
{
|
||||
return !this.iterator().hasNext();
|
||||
}
|
||||
@Override
|
||||
public void addStorage(final IAEFluidStack option) {
|
||||
if (option == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addStorage( final IAEFluidStack option )
|
||||
{
|
||||
if( option == null )
|
||||
{
|
||||
return;
|
||||
}
|
||||
final IAEFluidStack st = this.getFluidRecord(option);
|
||||
|
||||
final IAEFluidStack st = this.getFluidRecord( option );
|
||||
if (st != null) {
|
||||
st.incStackSize(option.getStackSize());
|
||||
return;
|
||||
}
|
||||
|
||||
if( st != null )
|
||||
{
|
||||
st.incStackSize( option.getStackSize() );
|
||||
return;
|
||||
}
|
||||
final IAEFluidStack opt = option.copy();
|
||||
|
||||
final IAEFluidStack opt = option.copy();
|
||||
this.putFluidRecord(opt);
|
||||
}
|
||||
|
||||
this.putFluidRecord( opt );
|
||||
}
|
||||
/*
|
||||
* public synchronized void clean() { Iterator<StackType> i = iterator(); while
|
||||
* (i.hasNext()) { StackType AEI = i.next(); if ( !AEI.isMeaningful() )
|
||||
* i.remove(); } }
|
||||
*/
|
||||
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCrafting( final IAEFluidStack option )
|
||||
{
|
||||
if( option == null )
|
||||
{
|
||||
return;
|
||||
}
|
||||
final IAEFluidStack st = this.getFluidRecord(option);
|
||||
|
||||
final IAEFluidStack st = this.getFluidRecord( option );
|
||||
if (st != null) {
|
||||
st.setCraftable(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if( st != null )
|
||||
{
|
||||
st.setCraftable( true );
|
||||
return;
|
||||
}
|
||||
final IAEFluidStack opt = option.copy();
|
||||
opt.setStackSize(0);
|
||||
opt.setCraftable(true);
|
||||
|
||||
final IAEFluidStack opt = option.copy();
|
||||
opt.setStackSize( 0 );
|
||||
opt.setCraftable( true );
|
||||
this.putFluidRecord(opt);
|
||||
}
|
||||
|
||||
this.putFluidRecord( opt );
|
||||
}
|
||||
@Override
|
||||
public void addRequestable(final IAEFluidStack option) {
|
||||
if (option == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addRequestable( final IAEFluidStack option )
|
||||
{
|
||||
if( option == null )
|
||||
{
|
||||
return;
|
||||
}
|
||||
final IAEFluidStack st = this.getFluidRecord(option);
|
||||
|
||||
final IAEFluidStack st = this.getFluidRecord( option );
|
||||
if (st != null) {
|
||||
st.setCountRequestable(st.getCountRequestable() + option.getCountRequestable());
|
||||
return;
|
||||
}
|
||||
|
||||
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());
|
||||
|
||||
final IAEFluidStack opt = option.copy();
|
||||
opt.setStackSize( 0 );
|
||||
opt.setCraftable( false );
|
||||
opt.setCountRequestable( option.getCountRequestable() );
|
||||
this.putFluidRecord(opt);
|
||||
}
|
||||
|
||||
this.putFluidRecord( opt );
|
||||
}
|
||||
@Override
|
||||
public IAEFluidStack getFirstItem() {
|
||||
for (final IAEFluidStack stackType : this) {
|
||||
return stackType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEFluidStack getFirstItem()
|
||||
{
|
||||
for( final IAEFluidStack stackType : this )
|
||||
{
|
||||
return stackType;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public int size() {
|
||||
return this.records.values().size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size()
|
||||
{
|
||||
return this.records.values().size();
|
||||
}
|
||||
@Override
|
||||
public Iterator<IAEFluidStack> iterator() {
|
||||
return new MeaningfulFluidIterator<>(this.records.values().iterator());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<IAEFluidStack> iterator()
|
||||
{
|
||||
return new MeaningfulFluidIterator<>( this.records.values().iterator() );
|
||||
}
|
||||
@Override
|
||||
public void resetStatus() {
|
||||
for (final IAEFluidStack i : this) {
|
||||
i.reset();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetStatus()
|
||||
{
|
||||
for( final IAEFluidStack i : this )
|
||||
{
|
||||
i.reset();
|
||||
}
|
||||
}
|
||||
private IAEFluidStack getFluidRecord(final IAEFluidStack fluid) {
|
||||
return this.records.get(fluid);
|
||||
}
|
||||
|
||||
private IAEFluidStack getFluidRecord( final IAEFluidStack fluid )
|
||||
{
|
||||
return this.records.get( fluid );
|
||||
}
|
||||
|
||||
private IAEFluidStack putFluidRecord( final IAEFluidStack fluid )
|
||||
{
|
||||
return this.records.put( fluid, fluid );
|
||||
}
|
||||
private IAEFluidStack putFluidRecord(final IAEFluidStack fluid) {
|
||||
return this.records.put(fluid, fluid);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,77 +18,68 @@
|
||||
|
||||
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 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_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>()
|
||||
{
|
||||
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;
|
||||
@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 );
|
||||
}
|
||||
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() );
|
||||
}
|
||||
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;
|
||||
}
|
||||
};
|
||||
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() );
|
||||
};
|
||||
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;
|
||||
}
|
||||
private static SortDir getDirection() {
|
||||
return Direction;
|
||||
}
|
||||
|
||||
public static void setDirection( final SortDir direction )
|
||||
{
|
||||
Direction = direction;
|
||||
}
|
||||
public static void setDirection(final SortDir direction) {
|
||||
Direction = direction;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,9 +18,7 @@
|
||||
|
||||
package appeng.fluids.util;
|
||||
|
||||
|
||||
@FunctionalInterface
|
||||
public interface IAEFluidInventory
|
||||
{
|
||||
void onFluidInventoryChanged( final IAEFluidTank inv, final int slot );
|
||||
public interface IAEFluidInventory {
|
||||
void onFluidInventoryChanged(final IAEFluidTank inv, final int slot);
|
||||
}
|
||||
|
||||
@@ -1,18 +1,15 @@
|
||||
|
||||
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);
|
||||
|
||||
public interface IAEFluidTank extends IFluidHandler
|
||||
{
|
||||
void setFluidInSlot( final int slot, final IAEFluidStack fluid );
|
||||
IAEFluidStack getFluidInSlot(final int slot);
|
||||
|
||||
IAEFluidStack getFluidInSlot( final int slot );
|
||||
|
||||
int getSlots();
|
||||
int getSlots();
|
||||
|
||||
}
|
||||
|
||||
@@ -18,58 +18,46 @@
|
||||
|
||||
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> {
|
||||
|
||||
public class MeaningfulFluidIterator<T extends IAEStack> implements Iterator<T>
|
||||
{
|
||||
private final Iterator<T> parent;
|
||||
private T next;
|
||||
|
||||
private final Iterator<T> parent;
|
||||
private T next;
|
||||
public MeaningfulFluidIterator(final Iterator<T> iterator) {
|
||||
this.parent = iterator;
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
this.next = null;
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public T next() {
|
||||
if (this.next == null) {
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public T next()
|
||||
{
|
||||
if( this.next == null )
|
||||
{
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
return this.next;
|
||||
}
|
||||
|
||||
return this.next;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove()
|
||||
{
|
||||
this.parent.remove();
|
||||
}
|
||||
@Override
|
||||
public void remove() {
|
||||
this.parent.remove();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user