reformatted all src files (#141)

This commit is contained in:
YoungOnion
2022-09-17 05:08:02 -06:00
committed by GitHub
parent 3328bfcda2
commit 9011273229
1056 changed files with 88127 additions and 110597 deletions
@@ -19,8 +19,11 @@
package appeng.fluids.block;
import javax.annotation.Nullable;
import appeng.api.util.AEPartLocation;
import appeng.block.AEBaseTileBlock;
import appeng.core.sync.GuiBridge;
import appeng.fluids.tile.TileFluidInterface;
import appeng.util.Platform;
import net.minecraft.block.material.Material;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
@@ -30,37 +33,27 @@ import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import appeng.api.util.AEPartLocation;
import appeng.block.AEBaseTileBlock;
import appeng.core.sync.GuiBridge;
import appeng.fluids.tile.TileFluidInterface;
import appeng.util.Platform;
import javax.annotation.Nullable;
public class BlockFluidInterface extends AEBaseTileBlock
{
public BlockFluidInterface()
{
super( Material.IRON );
}
public class BlockFluidInterface extends AEBaseTileBlock {
public BlockFluidInterface() {
super(Material.IRON);
}
@Override
public boolean onActivated( final World w, final BlockPos pos, final EntityPlayer p, final EnumHand hand, final @Nullable ItemStack heldItem, final EnumFacing side, final float hitX, final float hitY, final float hitZ )
{
if( p.isSneaking() )
{
return false;
}
@Override
public boolean onActivated(final World w, final BlockPos pos, final EntityPlayer p, final EnumHand hand, final @Nullable ItemStack heldItem, final EnumFacing side, final float hitX, final float hitY, final float hitZ) {
if (p.isSneaking()) {
return false;
}
final TileEntity tg = this.getTileEntity( w, pos );
if( tg instanceof TileFluidInterface )
{
if( Platform.isServer() )
{
Platform.openGUI( p, tg, AEPartLocation.fromFacing( side ), GuiBridge.GUI_FLUID_INTERFACE );
}
return true;
}
return false;
}
final TileEntity tg = this.getTileEntity(w, pos);
if (tg instanceof TileFluidInterface) {
if (Platform.isServer()) {
Platform.openGUI(p, tg, AEPartLocation.fromFacing(side), GuiBridge.GUI_FLUID_INTERFACE);
}
return true;
}
return false;
}
}
@@ -1,12 +1,6 @@
package appeng.fluids.client.gui;
import java.io.IOException;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.entity.player.InventoryPlayer;
import appeng.client.gui.implementations.GuiUpgradeable;
import appeng.client.gui.widgets.GuiTabButton;
import appeng.core.localization.GuiText;
@@ -18,73 +12,64 @@ import appeng.fluids.client.gui.widgets.GuiOptionalFluidSlot;
import appeng.fluids.container.ContainerFluidFormationPlane;
import appeng.fluids.parts.PartFluidFormationPlane;
import appeng.fluids.util.IAEFluidTank;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.entity.player.InventoryPlayer;
import java.io.IOException;
public class GuiFluidFormationPlane extends GuiUpgradeable
{
private final PartFluidFormationPlane plane;
private GuiTabButton priority;
public class GuiFluidFormationPlane extends GuiUpgradeable {
private final PartFluidFormationPlane plane;
private GuiTabButton priority;
public GuiFluidFormationPlane( InventoryPlayer inventoryPlayer, PartFluidFormationPlane te )
{
super( new ContainerFluidFormationPlane( inventoryPlayer, te ) );
this.ySize = 251;
this.plane = te;
}
public GuiFluidFormationPlane(InventoryPlayer inventoryPlayer, PartFluidFormationPlane te) {
super(new ContainerFluidFormationPlane(inventoryPlayer, te));
this.ySize = 251;
this.plane = te;
}
@Override
public void initGui()
{
super.initGui();
@Override
public void initGui() {
super.initGui();
final int xo = 8;
final int yo = 23 + 6;
final int xo = 8;
final int yo = 23 + 6;
final IAEFluidTank config = this.plane.getConfig();
final ContainerFluidFormationPlane container = (ContainerFluidFormationPlane) this.inventorySlots;
final IAEFluidTank config = this.plane.getConfig();
final ContainerFluidFormationPlane container = (ContainerFluidFormationPlane) this.inventorySlots;
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.buttonList.add( this.priority = new GuiTabButton( this.guiLeft + 154, this.guiTop, 2 + 4 * 16, GuiText.Priority.getLocal(), this.itemRender ) );
}
@Override
protected void addButtons() {
this.buttonList.add(this.priority = new GuiTabButton(this.guiLeft + 154, this.guiTop, 2 + 4 * 16, GuiText.Priority.getLocal(), this.itemRender));
}
@Override
protected String getBackground()
{
return "guis/storagebus.png";
}
@Override
protected String getBackground() {
return "guis/storagebus.png";
}
@Override
protected void actionPerformed( final GuiButton btn ) throws IOException
{
super.actionPerformed( btn );
if( btn == this.priority )
{
NetworkHandler.instance().sendToServer( new PacketSwitchGuis( GuiBridge.GUI_PRIORITY ) );
}
}
@Override
protected void actionPerformed(final GuiButton btn) throws IOException {
super.actionPerformed(btn);
if (btn == this.priority) {
NetworkHandler.instance().sendToServer(new PacketSwitchGuis(GuiBridge.GUI_PRIORITY));
}
}
@Override
protected GuiText getName()
{
return GuiText.FluidFormationPlane;
}
@Override
protected GuiText getName() {
return GuiText.FluidFormationPlane;
}
}
@@ -19,8 +19,6 @@
package appeng.fluids.client.gui;
import net.minecraft.entity.player.InventoryPlayer;
import appeng.client.gui.implementations.GuiUpgradeable;
import appeng.core.localization.GuiText;
import appeng.fluids.client.gui.widgets.GuiFluidSlot;
@@ -29,6 +27,7 @@ import appeng.fluids.container.ContainerFluidIO;
import appeng.fluids.parts.PartFluidImportBus;
import appeng.fluids.parts.PartSharedFluidBus;
import appeng.fluids.util.IAEFluidTank;
import net.minecraft.entity.player.InventoryPlayer;
/**
@@ -36,41 +35,37 @@ import appeng.fluids.util.IAEFluidTank;
* @version rv5 - 1/05/2018
* @since rv5 1/05/2018
*/
public class GuiFluidIO extends GuiUpgradeable
{
private final PartSharedFluidBus bus;
public class GuiFluidIO extends GuiUpgradeable {
private final PartSharedFluidBus bus;
public GuiFluidIO( InventoryPlayer inventoryPlayer, PartSharedFluidBus te )
{
super( new ContainerFluidIO( inventoryPlayer, te ) );
this.bus = te;
}
public GuiFluidIO(InventoryPlayer inventoryPlayer, PartSharedFluidBus te) {
super(new ContainerFluidIO(inventoryPlayer, te));
this.bus = te;
}
@Override
public void initGui()
{
super.initGui();
@Override
public void initGui() {
super.initGui();
final ContainerFluidIO container = (ContainerFluidIO) this.inventorySlots;
final IAEFluidTank inv = this.bus.getConfig();
final int y = 40;
final int x = 80;
final ContainerFluidIO container = (ContainerFluidIO) this.inventorySlots;
final IAEFluidTank inv = this.bus.getConfig();
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;
}
}
@@ -19,15 +19,9 @@
package appeng.fluids.client.gui;
import java.io.IOException;
import appeng.api.util.IConfigManager;
import appeng.client.gui.widgets.GuiCustomSlot;
import appeng.util.IConfigManagerHost;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.entity.player.InventoryPlayer;
import appeng.client.gui.implementations.GuiUpgradeable;
import appeng.client.gui.widgets.GuiCustomSlot;
import appeng.client.gui.widgets.GuiTabButton;
import appeng.core.localization.GuiText;
import appeng.core.sync.GuiBridge;
@@ -39,102 +33,92 @@ import appeng.fluids.container.ContainerFluidInterface;
import appeng.fluids.helper.DualityFluidInterface;
import appeng.fluids.helper.IFluidInterfaceHost;
import appeng.fluids.util.IAEFluidTank;
import appeng.util.IConfigManagerHost;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.entity.player.InventoryPlayer;
import java.io.IOException;
public class GuiFluidInterface extends GuiUpgradeable implements IConfigManagerHost
{
public final static int ID_BUTTON_TANK = 222;
public class GuiFluidInterface extends GuiUpgradeable implements IConfigManagerHost {
public final static int ID_BUTTON_TANK = 222;
private final IFluidInterfaceHost host;
private final ContainerFluidInterface container;
private GuiTabButton priority;
private final IFluidInterfaceHost host;
private final ContainerFluidInterface container;
private GuiTabButton priority;
public GuiFluidInterface( final InventoryPlayer ip, final IFluidInterfaceHost te )
{
super( new ContainerFluidInterface( ip, te ) );
this.ySize = 231;
this.host = te;
( this.container = (ContainerFluidInterface) this.inventorySlots ).setGui( this );
public GuiFluidInterface(final InventoryPlayer ip, final IFluidInterfaceHost te) {
super(new ContainerFluidInterface(ip, te));
this.ySize = 231;
this.host = te;
(this.container = (ContainerFluidInterface) this.inventorySlots).setGui(this);
}
}
@Override
public void initGui()
{
super.initGui();
@Override
public void initGui() {
super.initGui();
final IAEFluidTank configFluids = this.host.getDualityFluidInterface().getConfig();
final IAEFluidTank fluidTank = this.host.getDualityFluidInterface().getTanks();
final IAEFluidTank configFluids = this.host.getDualityFluidInterface().getConfig();
final IAEFluidTank fluidTank = this.host.getDualityFluidInterface().getTanks();
for( int i = 0; i < DualityFluidInterface.NUMBER_OF_TANKS; ++i )
{
this.guiSlots.add( new GuiFluidTank( fluidTank, i, DualityFluidInterface.NUMBER_OF_TANKS + i, 36 + 18 * i, 57, 16, 64 ) );
this.guiSlots.add( new GuiFluidSlot( configFluids, i, i, 35 + 18 * i, 35 ) );
}
for (int i = 0; i < DualityFluidInterface.NUMBER_OF_TANKS; ++i) {
this.guiSlots.add(new GuiFluidTank(fluidTank, i, DualityFluidInterface.NUMBER_OF_TANKS + i, 36 + 18 * i, 57, 16, 64));
this.guiSlots.add(new GuiFluidSlot(configFluids, i, i, 35 + 18 * i, 35));
}
this.priority = new GuiTabButton( this.getGuiLeft() + 154, this.getGuiTop(), 2 + 4 * 16, GuiText.Priority.getLocal(), this.itemRender );
this.buttonList.add( this.priority );
}
this.priority = new GuiTabButton(this.getGuiLeft() + 154, this.getGuiTop(), 2 + 4 * 16, GuiText.Priority.getLocal(), this.itemRender);
this.buttonList.add(this.priority);
}
@Override
protected void addButtons()
{
}
@Override
protected void addButtons() {
}
@Override
public void drawFG( int offsetX, int offsetY, int mouseX, int mouseY )
{
this.fontRenderer.drawString( this.getGuiDisplayName( GuiText.FluidInterface.getLocal() ), 8, 6, 4210752 );
this.fontRenderer.drawString( GuiText.Config.getLocal(), 35, 6 + 11 + 7, 4210752 );
this.fontRenderer.drawString( GuiText.StoredFluids.getLocal(), 35, 6 + 112 + 7, 4210752 );
this.fontRenderer.drawString( GuiText.inventory.getLocal(), 8, this.ySize - 96 + 3, 4210752 );
}
@Override
public void drawFG(int offsetX, int offsetY, int mouseX, int mouseY) {
this.fontRenderer.drawString(this.getGuiDisplayName(GuiText.FluidInterface.getLocal()), 8, 6, 4210752);
this.fontRenderer.drawString(GuiText.Config.getLocal(), 35, 6 + 11 + 7, 4210752);
this.fontRenderer.drawString(GuiText.StoredFluids.getLocal(), 35, 6 + 112 + 7, 4210752);
this.fontRenderer.drawString(GuiText.inventory.getLocal(), 8, this.ySize - 96 + 3, 4210752);
}
@Override
public void drawBG( int offsetX, int offsetY, int mouseX, int mouseY )
{
this.bindTexture( "guis/interfacefluid.png" );
this.drawTexturedModalRect( offsetX, offsetY, 0, 0, this.xSize, this.ySize );
}
@Override
public void drawBG(int offsetX, int offsetY, int mouseX, int mouseY) {
this.bindTexture("guis/interfacefluid.png");
this.drawTexturedModalRect(offsetX, offsetY, 0, 0, this.xSize, this.ySize);
}
@Override
protected void actionPerformed( final GuiButton btn ) throws IOException
{
super.actionPerformed( btn );
@Override
protected void actionPerformed(final GuiButton btn) throws IOException {
super.actionPerformed(btn);
if( btn == this.priority )
{
NetworkHandler.instance().sendToServer( new PacketSwitchGuis( GuiBridge.GUI_PRIORITY ) );
}
}
if (btn == this.priority) {
NetworkHandler.instance().sendToServer(new PacketSwitchGuis(GuiBridge.GUI_PRIORITY));
}
}
@Override
protected void mouseClicked( int xCoord, int yCoord, int btn ) throws IOException
{
for( GuiCustomSlot slot : this.guiSlots )
{
if( slot instanceof GuiFluidTank )
{
if( this.isPointInRegion( slot.xPos(), slot.yPos(), slot.getWidth(), slot.getHeight(), xCoord, yCoord ) && slot.canClick( this.mc.player ) )
{
this.container.setTargetStack( ( (GuiFluidTank) slot ).getFluidStack() );
slot.slotClicked( this.mc.player.inventory.getItemStack(), btn );
return;
}
}
}
super.mouseClicked( xCoord, yCoord, btn );
}
@Override
protected void mouseClicked(int xCoord, int yCoord, int btn) throws IOException {
for (GuiCustomSlot slot : this.guiSlots) {
if (slot instanceof GuiFluidTank) {
if (this.isPointInRegion(slot.xPos(), slot.yPos(), slot.getWidth(), slot.getHeight(), xCoord, yCoord) && slot.canClick(this.mc.player)) {
this.container.setTargetStack(((GuiFluidTank) slot).getFluidStack());
slot.slotClicked(this.mc.player.inventory.getItemStack(), btn);
return;
}
}
}
super.mouseClicked(xCoord, yCoord, btn);
}
@Override
protected boolean drawUpgrades()
{
return false;
}
@Override
protected boolean drawUpgrades() {
return false;
}
@Override
public void updateSetting( IConfigManager manager, Enum settingName, Enum newValue )
{
@Override
public void updateSetting(IConfigManager manager, Enum settingName, Enum newValue) {
}
}
}
@@ -1,12 +1,6 @@
package appeng.fluids.client.gui;
import java.io.IOException;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.entity.player.InventoryPlayer;
import appeng.api.config.RedstoneMode;
import appeng.api.config.Settings;
import appeng.client.gui.implementations.GuiUpgradeable;
@@ -20,204 +14,176 @@ import appeng.core.sync.packets.PacketValueConfig;
import appeng.fluids.client.gui.widgets.GuiFluidSlot;
import appeng.fluids.container.ContainerFluidLevelEmitter;
import appeng.fluids.parts.PartFluidLevelEmitter;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.entity.player.InventoryPlayer;
import java.io.IOException;
public class GuiFluidLevelEmitter extends GuiUpgradeable
{
private final PartFluidLevelEmitter levelEmitter;
private GuiNumberBox level;
public class GuiFluidLevelEmitter extends GuiUpgradeable {
private final PartFluidLevelEmitter levelEmitter;
private GuiNumberBox level;
private GuiButton plus1;
private GuiButton plus10;
private GuiButton plus100;
private GuiButton plus1000;
private GuiButton minus1;
private GuiButton minus10;
private GuiButton minus100;
private GuiButton minus1000;
private GuiButton plus1;
private GuiButton plus10;
private GuiButton plus100;
private GuiButton plus1000;
private GuiButton minus1;
private GuiButton minus10;
private GuiButton minus100;
private GuiButton minus1000;
public GuiFluidLevelEmitter( final InventoryPlayer inventoryPlayer, final PartFluidLevelEmitter te )
{
super( new ContainerFluidLevelEmitter( inventoryPlayer, te ) );
this.levelEmitter = te;
}
public GuiFluidLevelEmitter(final InventoryPlayer inventoryPlayer, final PartFluidLevelEmitter te) {
super(new ContainerFluidLevelEmitter(inventoryPlayer, te));
this.levelEmitter = te;
}
@Override
public void initGui()
{
super.initGui();
@Override
public void initGui() {
super.initGui();
this.level = new GuiNumberBox( this.fontRenderer, this.guiLeft + 24, this.guiTop + 43, 79, this.fontRenderer.FONT_HEIGHT, Long.class );
this.level.setEnableBackgroundDrawing( false );
this.level.setMaxStringLength( 16 );
this.level.setTextColor( 0xFFFFFF );
this.level.setVisible( true );
this.level.setFocused( true );
( (ContainerFluidLevelEmitter) this.inventorySlots ).setTextField( this.level );
this.level = new GuiNumberBox(this.fontRenderer, this.guiLeft + 24, this.guiTop + 43, 79, this.fontRenderer.FONT_HEIGHT, Long.class);
this.level.setEnableBackgroundDrawing(false);
this.level.setMaxStringLength(16);
this.level.setTextColor(0xFFFFFF);
this.level.setVisible(true);
this.level.setFocused(true);
((ContainerFluidLevelEmitter) this.inventorySlots).setTextField(this.level);
final int y = 40;
final int x = 80 + 44;
this.guiSlots.add( new GuiFluidSlot( this.levelEmitter.getConfig(), 0, 0, x, y ) );
}
final int y = 40;
final int x = 80 + 44;
this.guiSlots.add(new GuiFluidSlot(this.levelEmitter.getConfig(), 0, 0, x, y));
}
@Override
protected void addButtons()
{
this.redstoneMode = new GuiImgButton( this.guiLeft - 18, this.guiTop + 28, Settings.REDSTONE_EMITTER, RedstoneMode.LOW_SIGNAL );
@Override
protected void addButtons() {
this.redstoneMode = new GuiImgButton(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.buttonList.add( this.plus1 = new GuiButton( 0, this.guiLeft + 20, this.guiTop + 17, 22, 20, "+" + a ) );
this.buttonList.add( this.plus10 = new GuiButton( 0, this.guiLeft + 48, this.guiTop + 17, 28, 20, "+" + b ) );
this.buttonList.add( this.plus100 = new GuiButton( 0, this.guiLeft + 82, this.guiTop + 17, 32, 20, "+" + c ) );
this.buttonList.add( this.plus1000 = new GuiButton( 0, this.guiLeft + 120, this.guiTop + 17, 38, 20, "+" + d ) );
this.buttonList.add(this.plus1 = new GuiButton(0, this.guiLeft + 20, this.guiTop + 17, 22, 20, "+" + a));
this.buttonList.add(this.plus10 = new GuiButton(0, this.guiLeft + 48, this.guiTop + 17, 28, 20, "+" + b));
this.buttonList.add(this.plus100 = new GuiButton(0, this.guiLeft + 82, this.guiTop + 17, 32, 20, "+" + c));
this.buttonList.add(this.plus1000 = new GuiButton(0, this.guiLeft + 120, this.guiTop + 17, 38, 20, "+" + d));
this.buttonList.add( this.minus1 = new GuiButton( 0, this.guiLeft + 20, this.guiTop + 59, 22, 20, "-" + a ) );
this.buttonList.add( this.minus10 = new GuiButton( 0, this.guiLeft + 48, this.guiTop + 59, 28, 20, "-" + b ) );
this.buttonList.add( this.minus100 = new GuiButton( 0, this.guiLeft + 82, this.guiTop + 59, 32, 20, "-" + c ) );
this.buttonList.add( this.minus1000 = new GuiButton( 0, this.guiLeft + 120, this.guiTop + 59, 38, 20, "-" + d ) );
this.buttonList.add(this.minus1 = new GuiButton(0, this.guiLeft + 20, this.guiTop + 59, 22, 20, "-" + a));
this.buttonList.add(this.minus10 = new GuiButton(0, this.guiLeft + 48, this.guiTop + 59, 28, 20, "-" + b));
this.buttonList.add(this.minus100 = new GuiButton(0, this.guiLeft + 82, this.guiTop + 59, 32, 20, "-" + c));
this.buttonList.add(this.minus1000 = new GuiButton(0, this.guiLeft + 120, this.guiTop + 59, 38, 20, "-" + d));
this.buttonList.add( this.redstoneMode );
}
this.buttonList.add(this.redstoneMode);
}
@Override
public void drawBG( final int offsetX, final int offsetY, final int mouseX, final int mouseY )
{
super.drawBG( offsetX, offsetY, mouseX, mouseY );
this.level.drawTextBox();
}
@Override
public void drawBG(final int offsetX, final int offsetY, final int mouseX, final int mouseY) {
super.drawBG(offsetX, offsetY, mouseX, mouseY);
this.level.drawTextBox();
}
@Override
public void drawFG( int offsetX, int offsetY, int mouseX, int mouseY )
{
if( isPointInRegion( 24, 43,89,this.fontRenderer.FONT_HEIGHT,mouseX,mouseY ) ) drawTooltip( mouseX - guiLeft - 7, mouseY - guiTop + 25, "Amount in millibuckets" );
super.drawFG( offsetX, offsetY, mouseX, mouseY );
}
@Override
public void drawFG(int offsetX, int offsetY, int mouseX, int mouseY) {
if (isPointInRegion(24, 43, 89, this.fontRenderer.FONT_HEIGHT, mouseX, mouseY))
drawTooltip(mouseX - guiLeft - 7, mouseY - guiTop + 25, "Amount in millibuckets");
super.drawFG(offsetX, offsetY, mouseX, mouseY);
}
@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() {
}
@Override
protected void actionPerformed( final GuiButton btn ) throws IOException
{
super.actionPerformed( btn );
@Override
protected void actionPerformed(final GuiButton btn) throws IOException {
super.actionPerformed(btn);
final boolean isPlus = btn == this.plus1 || btn == this.plus10 || btn == this.plus100 || btn == this.plus1000;
final boolean isMinus = btn == this.minus1 || btn == this.minus10 || btn == this.minus100 || btn == this.minus1000;
final boolean isPlus = btn == this.plus1 || btn == this.plus10 || btn == this.plus100 || btn == this.plus1000;
final boolean isMinus = btn == this.minus1 || btn == this.minus10 || btn == this.minus100 || btn == this.minus1000;
if( isPlus || isMinus )
{
this.addQty( this.getQty( btn ) );
}
}
if (isPlus || isMinus) {
this.addQty(this.getQty(btn));
}
}
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" );
}
catch( final IOException e )
{
AELog.debug( e );
}
}
NetworkHandler.instance().sendToServer(new PacketValueConfig("FluidLevelEmitter.Value", Out));
} catch (final NumberFormatException e) {
// nope..
this.level.setText("0");
} catch (final IOException e) {
AELog.debug(e);
}
}
@Override
protected void keyTyped( final char character, final int key ) throws IOException
{
if( !this.checkHotbarKeys( key ) )
{
if( ( key == 211 || key == 205 || key == 203 || key == 14 || Character.isDigit( character ) ) && this.level.textboxKeyTyped( character, key ) )
{
try
{
String Out = this.level.getText();
@Override
protected void keyTyped(final char character, final int key) throws IOException {
if (!this.checkHotbarKeys(key)) {
if ((key == 211 || key == 205 || key == 203 || key == 14 || Character.isDigit(character)) && this.level.textboxKeyTyped(character, key)) {
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";
}
NetworkHandler.instance().sendToServer( new PacketValueConfig( "FluidLevelEmitter.Value", Out ) );
}
catch( final IOException e )
{
AELog.debug( e );
}
}
else
{
super.keyTyped( character, key );
}
}
}
NetworkHandler.instance().sendToServer(new PacketValueConfig("FluidLevelEmitter.Value", Out));
} catch (final IOException e) {
AELog.debug(e);
}
} else {
super.keyTyped(character, key);
}
}
}
}
@@ -19,18 +19,7 @@
package appeng.fluids.client.gui;
import java.io.IOException;
import org.lwjgl.input.Mouse;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.entity.player.InventoryPlayer;
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.api.config.*;
import appeng.client.gui.implementations.GuiUpgradeable;
import appeng.client.gui.widgets.GuiImgButton;
import appeng.client.gui.widgets.GuiTabButton;
@@ -46,6 +35,11 @@ import appeng.fluids.client.gui.widgets.GuiOptionalFluidSlot;
import appeng.fluids.container.ContainerFluidStorageBus;
import appeng.fluids.parts.PartFluidStorageBus;
import appeng.fluids.util.IAEFluidTank;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.entity.player.InventoryPlayer;
import org.lwjgl.input.Mouse;
import java.io.IOException;
/**
@@ -53,135 +47,107 @@ import appeng.fluids.util.IAEFluidTank;
* @version rv6 - 22/05/2018
* @since rv6 22/05/2018
*/
public class GuiFluidStorageBus extends GuiUpgradeable
{
private GuiImgButton rwMode;
private GuiImgButton storageFilter;
private GuiTabButton priority;
private GuiImgButton partition;
private GuiImgButton clear;
private final PartFluidStorageBus bus;
public class GuiFluidStorageBus extends GuiUpgradeable {
private GuiImgButton rwMode;
private GuiImgButton storageFilter;
private GuiTabButton priority;
private GuiImgButton partition;
private GuiImgButton clear;
private final PartFluidStorageBus bus;
public GuiFluidStorageBus( InventoryPlayer inventoryPlayer, PartFluidStorageBus te )
{
super( new ContainerFluidStorageBus( inventoryPlayer, te ) );
this.ySize = 251;
this.bus = te;
}
public GuiFluidStorageBus(InventoryPlayer inventoryPlayer, PartFluidStorageBus te) {
super(new ContainerFluidStorageBus(inventoryPlayer, te));
this.ySize = 251;
this.bus = te;
}
@Override
public void initGui()
{
super.initGui();
@Override
public void initGui() {
super.initGui();
final int xo = 8;
final int yo = 23 + 6;
final int xo = 8;
final int yo = 23 + 6;
final IAEFluidTank config = this.bus.getConfig();
final ContainerFluidStorageBus container = (ContainerFluidStorageBus) this.inventorySlots;
final IAEFluidTank config = this.bus.getConfig();
final ContainerFluidStorageBus container = (ContainerFluidStorageBus) this.inventorySlots;
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.clear = new GuiImgButton( this.guiLeft - 18, this.guiTop + 8, Settings.ACTIONS, ActionItems.CLOSE );
this.partition = new GuiImgButton( this.guiLeft - 18, this.guiTop + 28, Settings.ACTIONS, ActionItems.WRENCH );
this.rwMode = new GuiImgButton( this.guiLeft - 18, this.guiTop + 48, Settings.ACCESS, AccessRestriction.READ_WRITE );
this.storageFilter = new GuiImgButton( this.guiLeft - 18, this.guiTop + 68, Settings.STORAGE_FILTER, StorageFilter.EXTRACTABLE_ONLY );
this.fuzzyMode = new GuiImgButton( this.guiLeft - 18, this.guiTop + 88, Settings.FUZZY_MODE, FuzzyMode.IGNORE_ALL );
@Override
protected void addButtons() {
this.clear = new GuiImgButton(this.guiLeft - 18, this.guiTop + 8, Settings.ACTIONS, ActionItems.CLOSE);
this.partition = new GuiImgButton(this.guiLeft - 18, this.guiTop + 28, Settings.ACTIONS, ActionItems.WRENCH);
this.rwMode = new GuiImgButton(this.guiLeft - 18, this.guiTop + 48, Settings.ACCESS, AccessRestriction.READ_WRITE);
this.storageFilter = new GuiImgButton(this.guiLeft - 18, this.guiTop + 68, Settings.STORAGE_FILTER, StorageFilter.EXTRACTABLE_ONLY);
this.fuzzyMode = new GuiImgButton(this.guiLeft - 18, this.guiTop + 88, Settings.FUZZY_MODE, FuzzyMode.IGNORE_ALL);
this.buttonList.add( this.priority = new GuiTabButton( this.guiLeft + 154, this.guiTop, 2 + 4 * 16, GuiText.Priority.getLocal(), this.itemRender ) );
this.buttonList.add(this.priority = new GuiTabButton(this.guiLeft + 154, this.guiTop, 2 + 4 * 16, GuiText.Priority.getLocal(), this.itemRender));
this.buttonList.add( this.storageFilter );
this.buttonList.add( this.fuzzyMode );
this.buttonList.add( this.rwMode );
this.buttonList.add( this.partition );
this.buttonList.add( this.clear );
}
this.buttonList.add(this.storageFilter);
this.buttonList.add(this.fuzzyMode);
this.buttonList.add(this.rwMode);
this.buttonList.add(this.partition);
this.buttonList.add(this.clear);
}
@Override
public void drawFG( final int offsetX, final int offsetY, final int mouseX, final int mouseY )
{
this.fontRenderer.drawString( this.getGuiDisplayName( this.getName().getLocal() ), 8, 6, 4210752 );
this.fontRenderer.drawString( GuiText.inventory.getLocal(), 8, this.ySize - 96 + 3, 4210752 );
@Override
public void drawFG(final int offsetX, final int offsetY, final int mouseX, final int mouseY) {
this.fontRenderer.drawString(this.getGuiDisplayName(this.getName().getLocal()), 8, 6, 4210752);
this.fontRenderer.drawString(GuiText.inventory.getLocal(), 8, this.ySize - 96 + 3, 4210752);
if( this.fuzzyMode != null )
{
this.fuzzyMode.set( this.cvb.getFuzzyMode() );
}
if (this.fuzzyMode != null) {
this.fuzzyMode.set(this.cvb.getFuzzyMode());
}
if( this.storageFilter != null )
{
this.storageFilter.set( ( (ContainerFluidStorageBus) this.cvb ).getStorageFilter() );
}
if (this.storageFilter != null) {
this.storageFilter.set(((ContainerFluidStorageBus) this.cvb).getStorageFilter());
}
if( this.rwMode != null )
{
this.rwMode.set( ( (ContainerFluidStorageBus) this.cvb ).getReadWriteMode() );
}
}
if (this.rwMode != null) {
this.rwMode.set(((ContainerFluidStorageBus) this.cvb).getReadWriteMode());
}
}
@Override
protected String getBackground()
{
return "guis/storagebus.png";
}
@Override
protected String getBackground() {
return "guis/storagebus.png";
}
@Override
protected void actionPerformed( final GuiButton btn ) throws IOException
{
super.actionPerformed( btn );
@Override
protected void actionPerformed(final GuiButton btn) throws IOException {
super.actionPerformed(btn);
final boolean backwards = Mouse.isButtonDown( 1 );
final boolean backwards = Mouse.isButtonDown(1);
try
{
if( btn == this.partition )
{
NetworkHandler.instance().sendToServer( new PacketValueConfig( "StorageBus.Action", "Partition" ) );
}
else if( btn == this.clear )
{
NetworkHandler.instance().sendToServer( new PacketValueConfig( "StorageBus.Action", "Clear" ) );
}
else if( btn == this.priority )
{
NetworkHandler.instance().sendToServer( new PacketSwitchGuis( GuiBridge.GUI_PRIORITY ) );
}
else if( btn == this.rwMode )
{
NetworkHandler.instance().sendToServer( new PacketConfigButton( this.rwMode.getSetting(), backwards ) );
}
else if( btn == this.storageFilter )
{
NetworkHandler.instance().sendToServer( new PacketConfigButton( this.storageFilter.getSetting(), backwards ) );
}
}
catch( final IOException e )
{
AELog.debug( e );
}
}
try {
if (btn == this.partition) {
NetworkHandler.instance().sendToServer(new PacketValueConfig("StorageBus.Action", "Partition"));
} else if (btn == this.clear) {
NetworkHandler.instance().sendToServer(new PacketValueConfig("StorageBus.Action", "Clear"));
} else if (btn == this.priority) {
NetworkHandler.instance().sendToServer(new PacketSwitchGuis(GuiBridge.GUI_PRIORITY));
} else if (btn == this.rwMode) {
NetworkHandler.instance().sendToServer(new PacketConfigButton(this.rwMode.getSetting(), backwards));
} else if (btn == this.storageFilter) {
NetworkHandler.instance().sendToServer(new PacketConfigButton(this.storageFilter.getSetting(), backwards));
}
} catch (final IOException e) {
AELog.debug(e);
}
}
@Override
protected GuiText getName()
{
return GuiText.StorageBusFluids;
}
@Override
protected GuiText getName() {
return GuiText.StorageBusFluids;
}
}
@@ -19,22 +19,6 @@
package appeng.fluids.client.gui;
import java.io.IOException;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import org.lwjgl.input.Mouse;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.ClickType;
import net.minecraft.inventory.Slot;
import net.minecraft.util.text.TextFormatting;
import net.minecraftforge.fml.common.Loader;
import appeng.api.config.Settings;
import appeng.api.storage.ITerminalHost;
import appeng.api.storage.data.IAEFluidStack;
@@ -58,6 +42,20 @@ import appeng.fluids.container.slots.IMEFluidSlot;
import appeng.helpers.InventoryAction;
import appeng.util.IConfigManagerHost;
import appeng.util.Platform;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.ClickType;
import net.minecraft.inventory.Slot;
import net.minecraft.util.text.TextFormatting;
import net.minecraftforge.fml.common.Loader;
import org.lwjgl.input.Mouse;
import java.io.IOException;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
/**
@@ -65,302 +63,255 @@ import appeng.util.Platform;
* @version rv6 - 12/05/2018
* @since rv6 12/05/2018
*/
public class GuiFluidTerminal extends AEBaseMEGui implements ISortSource, IConfigManagerHost
{
private final List<SlotFluidME> meFluidSlots = new LinkedList<>();
private final FluidRepo repo;
private final IConfigManager configSrc;
private final ContainerFluidTerminal container;
private final int offsetX = 9;
private int rows = 6;
private int perRow = 9;
public class GuiFluidTerminal extends AEBaseMEGui implements ISortSource, IConfigManagerHost {
private final List<SlotFluidME> meFluidSlots = new LinkedList<>();
private final FluidRepo repo;
private final IConfigManager configSrc;
private final ContainerFluidTerminal container;
private final int offsetX = 9;
private final int rows = 6;
private final int perRow = 9;
protected ITerminalHost terminal;
protected ITerminalHost terminal;
private MEGuiTextField searchField;
private GuiImgButton sortByBox;
private GuiImgButton sortDirBox;
private MEGuiTextField searchField;
private GuiImgButton sortByBox;
private GuiImgButton sortDirBox;
public GuiFluidTerminal( final InventoryPlayer inventoryPlayer, final ITerminalHost te )
{
this( inventoryPlayer, te, new ContainerFluidTerminal( inventoryPlayer, te ) );
}
public GuiFluidTerminal(final InventoryPlayer inventoryPlayer, final ITerminalHost te) {
this(inventoryPlayer, te, new ContainerFluidTerminal(inventoryPlayer, te));
}
public GuiFluidTerminal( InventoryPlayer inventoryPlayer, final ITerminalHost te, final ContainerFluidTerminal c )
{
super( c );
this.terminal = te;
this.xSize = 185;
this.ySize = 222;
final GuiScrollbar scrollbar = new GuiScrollbar();
this.setScrollBar( scrollbar );
this.repo = new FluidRepo( scrollbar, this );
this.configSrc = ( (IConfigurableObject) this.inventorySlots ).getConfigManager();
( this.container = (ContainerFluidTerminal) this.inventorySlots ).setGui( this );
}
public GuiFluidTerminal(InventoryPlayer inventoryPlayer, final ITerminalHost te, final ContainerFluidTerminal c) {
super(c);
this.terminal = te;
this.xSize = 185;
this.ySize = 222;
final GuiScrollbar scrollbar = new GuiScrollbar();
this.setScrollBar(scrollbar);
this.repo = new FluidRepo(scrollbar, this);
this.configSrc = ((IConfigurableObject) this.inventorySlots).getConfigManager();
(this.container = (ContainerFluidTerminal) this.inventorySlots).setGui(this);
}
@Override
public void initGui()
{
this.mc.player.openContainer = this.inventorySlots;
this.guiLeft = ( this.width - this.xSize ) / 2;
this.guiTop = ( this.height - this.ySize ) / 2;
@Override
public void initGui() {
this.mc.player.openContainer = this.inventorySlots;
this.guiLeft = (this.width - this.xSize) / 2;
this.guiTop = (this.height - this.ySize) / 2;
this.searchField = new MEGuiTextField( this.fontRenderer, 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 );
this.searchField = new MEGuiTextField(this.fontRenderer, 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;
int offset = this.guiTop;
this.buttonList.add( this.sortByBox = new GuiImgButton( this.guiLeft - 18, offset, Settings.SORT_BY, this.configSrc.getSetting( Settings.SORT_BY ) ) );
offset += 20;
this.buttonList.add(this.sortByBox = new GuiImgButton(this.guiLeft - 18, offset, Settings.SORT_BY, this.configSrc.getSetting(Settings.SORT_BY)));
offset += 20;
this.buttonList.add( this.sortDirBox = new GuiImgButton( this.guiLeft - 18, offset, Settings.SORT_DIRECTION, this.configSrc
.getSetting( Settings.SORT_DIRECTION ) ) );
this.buttonList.add(this.sortDirBox = new GuiImgButton(this.guiLeft - 18, offset, Settings.SORT_DIRECTION, this.configSrc
.getSetting(Settings.SORT_DIRECTION)));
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.inventorySlots.inventorySlots.add( slot );
}
}
this.setScrollBar();
}
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.inventorySlots.inventorySlots.add(slot);
}
}
this.setScrollBar();
}
@Override
public void drawFG( int offsetX, int offsetY, int mouseX, int mouseY )
{
this.fontRenderer.drawString( this.getGuiDisplayName( "Fluid Terminal" ), 8, 6, 4210752 );
this.fontRenderer.drawString( GuiText.inventory.getLocal(), 8, this.ySize - 96 + 3, 4210752 );
}
@Override
public void drawFG(int offsetX, int offsetY, int mouseX, int mouseY) {
this.fontRenderer.drawString(this.getGuiDisplayName("Fluid Terminal"), 8, 6, 4210752);
this.fontRenderer.drawString(GuiText.inventory.getLocal(), 8, this.ySize - 96 + 3, 4210752);
}
@Override
public void drawBG( int offsetX, int offsetY, int mouseX, int mouseY )
{
this.bindTexture( this.getBackground() );
final int x_width = 197;
this.drawTexturedModalRect( offsetX, offsetY, 0, 0, x_width, 18 );
@Override
public void drawBG(int offsetX, int offsetY, int mouseX, int mouseY) {
this.bindTexture(this.getBackground());
final int x_width = 197;
this.drawTexturedModalRect(offsetX, offsetY, 0, 0, x_width, 18);
for( int x = 0; x < 6; x++ )
{
this.drawTexturedModalRect( offsetX, offsetY + 18 + x * 18, 0, 18, x_width, 18 );
}
for (int x = 0; x < 6; x++) {
this.drawTexturedModalRect(offsetX, offsetY + 18 + x * 18, 0, 18, x_width, 18);
}
this.drawTexturedModalRect( offsetX, offsetY + 16 + 6 * 18, 0, 106 - 18 - 18, x_width, 99 + 77 );
this.drawTexturedModalRect(offsetX, offsetY + 16 + 6 * 18, 0, 106 - 18 - 18, x_width, 99 + 77);
if( this.searchField != null )
{
this.searchField.drawTextBox();
}
}
if (this.searchField != null) {
this.searchField.drawTextBox();
}
}
@Override
public void updateScreen()
{
this.repo.setPower( this.container.isPowered() );
super.updateScreen();
}
@Override
public void updateScreen() {
this.repo.setPower(this.container.isPowered());
super.updateScreen();
}
@Override
protected void renderHoveredToolTip( int mouseX, int mouseY )
{
final Slot slot = this.getSlot( mouseX, mouseY );
@Override
protected void renderHoveredToolTip(int mouseX, int mouseY) {
final Slot slot = this.getSlot(mouseX, mouseY);
if( slot != null && slot instanceof IMEFluidSlot && slot.isEnabled() )
{
final IMEFluidSlot fluidSlot = (IMEFluidSlot) slot;
if (slot != null && 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";
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 = "" + TextFormatting.BLUE + TextFormatting.ITALIC + Loader.instance()
.getIndexedModList()
.get( Platform.getModId( fluidStack ) )
.getName();
final String modName = "" + TextFormatting.BLUE + TextFormatting.ITALIC + Loader.instance()
.getIndexedModList()
.get(Platform.getModId(fluidStack))
.getName();
final List<String> list = new ArrayList<>();
final List<String> list = new ArrayList<>();
list.add( fluidStack.getFluidStack().getLocalizedName() );
list.add( formattedAmount );
list.add( modName );
list.add(fluidStack.getFluidStack().getLocalizedName());
list.add(formattedAmount);
list.add(modName);
this.drawHoveringText( list, mouseX, mouseY );
this.drawHoveringText(list, mouseX, mouseY);
return;
}
}
super.renderHoveredToolTip( mouseX, mouseY );
}
return;
}
}
super.renderHoveredToolTip(mouseX, mouseY);
}
@Override
protected void actionPerformed( GuiButton btn ) throws IOException
{
if( btn instanceof GuiImgButton )
{
final boolean backwards = Mouse.isButtonDown( 1 );
final GuiImgButton iBtn = (GuiImgButton) btn;
@Override
protected void actionPerformed(GuiButton btn) throws IOException {
if (btn instanceof GuiImgButton) {
final boolean backwards = Mouse.isButtonDown(1);
final GuiImgButton iBtn = (GuiImgButton) btn;
if( iBtn.getSetting() != Settings.ACTIONS )
{
final Enum cv = iBtn.getCurrentValue();
final Enum next = Platform.rotateEnum( cv, backwards, iBtn.getSetting().getPossibleValues() );
if (iBtn.getSetting() != Settings.ACTIONS) {
final Enum cv = iBtn.getCurrentValue();
final Enum next = Platform.rotateEnum(cv, backwards, iBtn.getSetting().getPossibleValues());
try
{
NetworkHandler.instance().sendToServer( new PacketValueConfig( iBtn.getSetting().name(), next.name() ) );
}
catch( final IOException e )
{
AELog.debug( e );
}
try {
NetworkHandler.instance().sendToServer(new PacketValueConfig(iBtn.getSetting().name(), next.name()));
} catch (final IOException e) {
AELog.debug(e);
}
iBtn.set( next );
}
}
}
iBtn.set(next);
}
}
}
@Override
protected void handleMouseClick( Slot slot, int slotIdx, int mouseButton, ClickType clickType )
{
if( slot instanceof SlotFluidME )
{
final SlotFluidME meSlot = (SlotFluidME) slot;
@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 );
}
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
protected void keyTyped( final char character, final int key ) throws IOException
{
if( !this.checkHotbarKeys( key ) )
{
if( character == ' ' && this.searchField.getText().isEmpty() )
{
return;
}
@Override
protected void keyTyped(final char character, final int key) throws IOException {
if (!this.checkHotbarKeys(key)) {
if (character == ' ' && this.searchField.getText().isEmpty()) {
return;
}
if( this.searchField.textboxKeyTyped( character, key ) )
{
this.repo.setSearchString( this.searchField.getText() );
this.repo.updateView();
this.setScrollBar();
}
else
{
super.keyTyped( character, key );
}
}
}
if (this.searchField.textboxKeyTyped(character, key)) {
this.repo.setSearchString(this.searchField.getText());
this.repo.updateView();
this.setScrollBar();
} else {
super.keyTyped(character, key);
}
}
}
@Override
protected void mouseClicked( final int xCoord, final int yCoord, final int btn ) throws IOException
{
this.searchField.mouseClicked( xCoord, yCoord, btn );
@Override
protected void mouseClicked(final int xCoord, final int yCoord, final int btn) throws IOException {
this.searchField.mouseClicked(xCoord, yCoord, btn);
if( btn == 1 && this.searchField.isMouseIn( xCoord, yCoord ) )
{
this.searchField.setText( "" );
this.repo.setSearchString( "" );
this.repo.updateView();
this.setScrollBar();
}
if (btn == 1 && this.searchField.isMouseIn(xCoord, yCoord)) {
this.searchField.setText("");
this.repo.setSearchString("");
this.repo.updateView();
this.setScrollBar();
}
super.mouseClicked( xCoord, yCoord, btn );
}
super.mouseClicked(xCoord, yCoord, btn);
}
public void postUpdate( final List<IAEFluidStack> list )
{
for( final IAEFluidStack is : list )
{
this.repo.postUpdate( is );
}
public void postUpdate(final List<IAEFluidStack> list) {
for (final IAEFluidStack is : list) {
this.repo.postUpdate(is);
}
this.repo.updateView();
this.setScrollBar();
}
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 ) );
}
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 Enum getSortBy()
{
return this.configSrc.getSetting( Settings.SORT_BY );
}
@Override
public Enum getSortBy() {
return this.configSrc.getSetting(Settings.SORT_BY);
}
@Override
public Enum getSortDir()
{
return this.configSrc.getSetting( Settings.SORT_DIRECTION );
}
@Override
public Enum getSortDir() {
return this.configSrc.getSetting(Settings.SORT_DIRECTION);
}
@Override
public Enum getSortDisplay()
{
return this.configSrc.getSetting( Settings.VIEW_MODE );
}
@Override
public Enum getSortDisplay() {
return this.configSrc.getSetting(Settings.VIEW_MODE);
}
@Override
public void updateSetting( IConfigManager manager, Enum settingName, Enum newValue )
{
if( this.sortByBox != null )
{
this.sortByBox.set( this.configSrc.getSetting( Settings.SORT_BY ) );
}
@Override
public void updateSetting(IConfigManager manager, Enum settingName, Enum newValue) {
if (this.sortByBox != null) {
this.sortByBox.set(this.configSrc.getSetting(Settings.SORT_BY));
}
if( this.sortDirBox != null )
{
this.sortDirBox.set( this.configSrc.getSetting( Settings.SORT_DIRECTION ) );
}
if (this.sortDirBox != null) {
this.sortDirBox.set(this.configSrc.getSetting(Settings.SORT_DIRECTION));
}
this.repo.updateView();
}
this.repo.updateView();
}
protected List<SlotFluidME> getMeFluidSlots()
{
return this.meFluidSlots;
}
protected List<SlotFluidME> getMeFluidSlots() {
return this.meFluidSlots;
}
@Override
protected boolean isPowered()
{
return this.repo.hasPower();
}
@Override
protected boolean isPowered() {
return this.repo.hasPower();
}
protected String getBackground()
{
return "guis/terminal.png";
}
protected String getBackground() {
return "guis/terminal.png";
}
}
@@ -1,10 +1,13 @@
package appeng.fluids.client.gui.widgets;
import java.util.Collections;
import appeng.api.storage.data.IAEFluidStack;
import appeng.client.gui.widgets.GuiCustomSlot;
import appeng.container.slot.IJEITargetSlot;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.PacketFluidSlot;
import appeng.fluids.util.AEFluidStack;
import appeng.fluids.util.IAEFluidTank;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
@@ -16,98 +19,78 @@ import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidUtil;
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
import appeng.api.storage.data.IAEFluidStack;
import appeng.client.gui.widgets.GuiCustomSlot;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.PacketFluidSlot;
import appeng.fluids.util.AEFluidStack;
import appeng.fluids.util.IAEFluidTank;
import java.util.Collections;
public class GuiFluidSlot extends GuiCustomSlot implements IJEITargetSlot
{
private final IAEFluidTank fluids;
private final int slot;
public class GuiFluidSlot extends GuiCustomSlot implements IJEITargetSlot {
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 )
{
GlStateManager.disableLighting();
GlStateManager.disableBlend();
final Fluid fluid = fs.getFluid();
mc.getTextureManager().bindTexture( TextureMap.LOCATION_BLOCKS_TEXTURE );
final TextureAtlasSprite sprite = mc.getTextureMapBlocks().getAtlasSprite( fluid.getStill().toString() );
@Override
public void drawContent(final Minecraft mc, final int mouseX, final int mouseY, final float partialTicks) {
final IAEFluidStack fs = this.getFluidStack();
if (fs != null) {
GlStateManager.disableLighting();
GlStateManager.disableBlend();
final Fluid fluid = fs.getFluid();
mc.getTextureManager().bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
final TextureAtlasSprite sprite = mc.getTextureMapBlocks().getAtlasSprite(fluid.getStill().toString());
// Set color for dynamic fluids
// Convert int color to RGB
final float red = ( fluid.getColor() >> 16 & 255 ) / 255.0F;
final float green = ( fluid.getColor() >> 8 & 255 ) / 255.0F;
final float blue = ( fluid.getColor() & 255 ) / 255.0F;
GlStateManager.color( red, green, blue );
// Set color for dynamic fluids
// Convert int color to RGB
final float red = (fluid.getColor() >> 16 & 255) / 255.0F;
final float green = (fluid.getColor() >> 8 & 255) / 255.0F;
final float blue = (fluid.getColor() & 255) / 255.0F;
GlStateManager.color(red, green, blue);
this.drawTexturedModalRect( this.xPos(), this.yPos(), sprite, this.getWidth(), this.getHeight() );
}
}
this.drawTexturedModalRect(this.xPos(), this.yPos(), sprite, this.getWidth(), this.getHeight());
}
}
@Override
public boolean canClick( final EntityPlayer player )
{
final ItemStack mouseStack = player.inventory.getItemStack();
return mouseStack.isEmpty() || mouseStack.hasCapability( CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null );
}
@Override
public boolean canClick(final EntityPlayer player) {
final ItemStack mouseStack = player.inventory.getItemStack();
return mouseStack.isEmpty() || mouseStack.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null);
}
@Override
public void slotClicked( final ItemStack clickStack, int mouseButton )
{
if( clickStack.isEmpty() || mouseButton == 1 )
{
this.setFluidStack( null );
}
else if( mouseButton == 0 )
{
final FluidStack fluid = FluidUtil.getFluidContained( clickStack );
if( fluid != null )
{
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 FluidStack fluid = FluidUtil.getFluidContained(clickStack);
if (fluid != null) {
this.setFluidStack(AEFluidStack.fromFluidStack(fluid));
}
}
}
@Override
public String getMessage()
{
final IAEFluidStack fluid = this.getFluidStack();
if( fluid != null )
{
return fluid.getFluidStack().getLocalizedName();
}
return null;
}
@Override
public String getMessage() {
final IAEFluidStack fluid = this.getFluidStack();
if (fluid != null) {
return fluid.getFluidStack().getLocalizedName();
}
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())));
}
}
@@ -19,9 +19,12 @@
package appeng.fluids.client.gui.widgets;
import appeng.api.storage.data.IAEFluidStack;
import appeng.client.gui.widgets.GuiCustomSlot;
import appeng.client.gui.widgets.ITooltip;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.PacketInventoryAction;
import appeng.fluids.util.IAEFluidTank;
import appeng.helpers.InventoryAction;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GlStateManager;
@@ -31,127 +34,104 @@ import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import appeng.api.storage.data.IAEFluidStack;
import appeng.client.gui.widgets.ITooltip;
import appeng.fluids.util.IAEFluidTank;
@SideOnly(Side.CLIENT)
public class GuiFluidTank extends GuiCustomSlot implements ITooltip {
private final IAEFluidTank tank;
private final int slot;
private final int width;
private final int height;
@SideOnly( Side.CLIENT )
public class GuiFluidTank extends GuiCustomSlot implements ITooltip
{
private final IAEFluidTank tank;
private final int slot;
private final int width;
private final int height;
public GuiFluidTank(IAEFluidTank tank, int slot, int id, int x, int y, int w, int h) {
super(id, x, y);
this.tank = tank;
this.slot = slot;
this.width = w;
this.height = h;
}
public GuiFluidTank( IAEFluidTank tank, int slot, int id, int x, int y, int w, int h )
{
super( id, x, y );
this.tank = tank;
this.slot = slot;
this.width = w;
this.height = h;
}
@Override
public void drawContent(Minecraft mc, int mouseX, int mouseY, float partialTicks) {
final IAEFluidStack fs = this.getFluidStack();
if (fs != null) {
GlStateManager.disableBlend();
GlStateManager.disableLighting();
@Override
public void drawContent( Minecraft mc, int mouseX, int mouseY, float partialTicks )
{
final IAEFluidStack fs = this.getFluidStack();
if( fs != null )
{
GlStateManager.disableBlend();
GlStateManager.disableLighting();
//drawRect( this.x, this.y, this.x + this.width, this.y + this.height, AEColor.GRAY.blackVariant | 0xFF000000 );
//drawRect( this.x, this.y, this.x + this.width, this.y + this.height, AEColor.GRAY.blackVariant | 0xFF000000 );
final IAEFluidStack fluid = this.tank.getFluidInSlot(this.slot);
if (fluid != null && fluid.getStackSize() > 0) {
mc.getTextureManager().bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
final IAEFluidStack fluid = this.tank.getFluidInSlot( this.slot );
if( fluid != null && fluid.getStackSize() > 0 )
{
mc.getTextureManager().bindTexture( TextureMap.LOCATION_BLOCKS_TEXTURE );
float red = (fluid.getFluid().getColor() >> 16 & 255) / 255.0F;
float green = (fluid.getFluid().getColor() >> 8 & 255) / 255.0F;
float blue = (fluid.getFluid().getColor() & 255) / 255.0F;
GlStateManager.color(red, green, blue);
float red = ( fluid.getFluid().getColor() >> 16 & 255 ) / 255.0F;
float green = ( fluid.getFluid().getColor() >> 8 & 255 ) / 255.0F;
float blue = ( fluid.getFluid().getColor() & 255 ) / 255.0F;
GlStateManager.color( red, green, blue );
TextureAtlasSprite sprite = mc.getTextureMapBlocks().getAtlasSprite(fluid.getFluid().getStill().toString());
final int scaledHeight = (int) (this.height * ((float) fluid.getStackSize() / this.tank.getTankProperties()[this.slot].getCapacity()));
TextureAtlasSprite sprite = mc.getTextureMapBlocks().getAtlasSprite( fluid.getFluid().getStill().toString() );
final int scaledHeight = (int) ( this.height * ( (float) fluid.getStackSize() / this.tank.getTankProperties()[this.slot].getCapacity() ) );
int iconHeightRemainder = scaledHeight % 16;
if (iconHeightRemainder > 0) {
this.drawTexturedModalRect(this.xPos(), this.yPos() + this.getHeight() - iconHeightRemainder, sprite, 16, iconHeightRemainder);
}
for (int i = 0; i < scaledHeight / 16; i++) {
this.drawTexturedModalRect(this.xPos(), this.yPos() + this.getHeight() - iconHeightRemainder - (i + 1) * 16, sprite, 16, 16);
}
}
}
}
int iconHeightRemainder = scaledHeight % 16;
if( iconHeightRemainder > 0 )
{
this.drawTexturedModalRect( this.xPos(), this.yPos() + this.getHeight() - iconHeightRemainder, sprite, 16, iconHeightRemainder );
}
for( int i = 0; i < scaledHeight / 16; i++ )
{
this.drawTexturedModalRect( this.xPos(), this.yPos() + this.getHeight() - iconHeightRemainder - ( i + 1 ) * 16, sprite, 16, 16 );
}
}
}
}
@Override
public String getMessage() {
final IAEFluidStack fluid = this.tank.getFluidInSlot(this.slot);
if (fluid != null && fluid.getStackSize() > 0) {
String desc = fluid.getFluid().getLocalizedName(fluid.getFluidStack());
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().getLocalizedName( fluid.getFluidStack() );
String amountToText = fluid.getStackSize() + "mB";
return desc + "\n" + amountToText;
}
return null;
}
return desc + "\n" + amountToText;
}
return null;
}
@Override
public int xPos() {
return this.x - 1;
}
@Override
public int xPos()
{
return this.x - 1;
}
@Override
public int yPos() {
return this.y - 4;
}
@Override
public int yPos()
{
return this.y - 4;
}
@Override
public int getWidth() {
return this.width;
}
@Override
public int getWidth()
{
return this.width;
}
@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;
}
public IAEFluidStack getFluidStack() {
return this.tank.getFluidInSlot(this.slot);
}
public IAEFluidStack getFluidStack()
{
return this.tank.getFluidInSlot( this.slot );
}
@Override
public void slotClicked(ItemStack clickStack, final int mouseButton) {
@Override
public void slotClicked( ItemStack clickStack, final int mouseButton )
{
if (getFluidStack() != null) {
NetworkHandler.instance().sendToServer(new PacketInventoryAction(InventoryAction.FILL_ITEM, slot, 0));
} else {
NetworkHandler.instance().sendToServer(new PacketInventoryAction(InventoryAction.EMPTY_ITEM, slot, 0));
}
if( getFluidStack() != null )
{
NetworkHandler.instance().sendToServer( new PacketInventoryAction( InventoryAction.FILL_ITEM, slot, 0 ) );
}
else
{
NetworkHandler.instance().sendToServer( new PacketInventoryAction( InventoryAction.EMPTY_ITEM, slot, 0 ) );
}
}
}
}
@@ -1,63 +1,51 @@
package appeng.fluids.client.gui.widgets;
import net.minecraft.client.renderer.GlStateManager;
import appeng.api.storage.data.IAEFluidStack;
import appeng.container.slot.IOptionalSlotHost;
import appeng.fluids.util.IAEFluidTank;
import net.minecraft.client.renderer.GlStateManager;
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 )
{
GlStateManager.enableBlend();
if( this.isSlotEnabled() )
{
GlStateManager.color( 1.0F, 1.0F, 1.0F, 1.0F );
}
else
{
GlStateManager.color( 1.0F, 1.0F, 1.0F, 0.4F );
}
this.drawTexturedModalRect( guileft + this.xPos() - 1, guitop + this.yPos() - 1, this.srcX - 1, this.srcY - 1, this.getWidth() + 2,
this.getHeight() + 2 );
}
@Override
public void drawBackground(int guileft, int guitop) {
GlStateManager.enableBlend();
if (this.isSlotEnabled()) {
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
} else {
GlStateManager.color(1.0F, 1.0F, 1.0F, 0.4F);
}
this.drawTexturedModalRect(guileft + this.xPos() - 1, guitop + this.yPos() - 1, this.srcX - 1, this.srcY - 1, this.getWidth() + 2,
this.getHeight() + 2);
}
}
@@ -19,18 +19,17 @@
package appeng.fluids.client.render;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.renderer.GlStateManager;
import appeng.api.storage.data.IAEFluidStack;
import appeng.core.AEConfig;
import appeng.util.ISlimReadableNumberConverter;
import appeng.util.IWideReadableNumberConverter;
import appeng.util.ReadableNumberConverter;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.renderer.GlStateManager;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
/**
@@ -40,95 +39,81 @@ 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 )
{
final float scaleFactor = AEConfig.instance().useTerminalUseLargeFont() ? 0.85f : 0.5f;
final float inverseScaleFactor = 1.0f / scaleFactor;
final int offset = AEConfig.instance().useTerminalUseLargeFont() ? 0 : -1;
public void renderStackSize(FontRenderer fontRenderer, IAEFluidStack aeStack, int xPos, int yPos) {
if (aeStack != null) {
final float scaleFactor = AEConfig.instance().useTerminalUseLargeFont() ? 0.85f : 0.5f;
final float inverseScaleFactor = 1.0f / scaleFactor;
final int offset = AEConfig.instance().useTerminalUseLargeFont() ? 0 : -1;
final boolean unicodeFlag = fontRenderer.getUnicodeFlag();
fontRenderer.setUnicodeFlag( false );
final boolean unicodeFlag = fontRenderer.getUnicodeFlag();
fontRenderer.setUnicodeFlag(false);
if( aeStack.getStackSize() > 0 )
{
final String stackSize = this.getToBeRenderedStackSize( aeStack.getStackSize() );
if (aeStack.getStackSize() > 0) {
final String stackSize = this.getToBeRenderedStackSize(aeStack.getStackSize());
GlStateManager.disableLighting();
GlStateManager.disableDepth();
GlStateManager.disableBlend();
GlStateManager.pushMatrix();
GlStateManager.scale( scaleFactor, scaleFactor, scaleFactor );
final int X = (int) ( ( (float) xPos + offset + 16.0f - fontRenderer.getStringWidth( stackSize ) * scaleFactor ) * inverseScaleFactor );
final int Y = (int) ( ( (float) yPos + offset + 16.0f - 7.0f * scaleFactor ) * inverseScaleFactor );
fontRenderer.drawStringWithShadow( stackSize, X, Y, 16777215 );
GlStateManager.popMatrix();
GlStateManager.enableLighting();
GlStateManager.enableDepth();
GlStateManager.enableBlend();
}
GlStateManager.disableLighting();
GlStateManager.disableDepth();
GlStateManager.disableBlend();
GlStateManager.pushMatrix();
GlStateManager.scale(scaleFactor, scaleFactor, scaleFactor);
final int X = (int) (((float) xPos + offset + 16.0f - fontRenderer.getStringWidth(stackSize) * scaleFactor) * inverseScaleFactor);
final int Y = (int) (((float) yPos + offset + 16.0f - 7.0f * scaleFactor) * inverseScaleFactor);
fontRenderer.drawStringWithShadow(stackSize, X, Y, 16777215);
GlStateManager.popMatrix();
GlStateManager.enableLighting();
GlStateManager.enableDepth();
GlStateManager.enableBlend();
}
fontRenderer.setUnicodeFlag( unicodeFlag );
}
}
fontRenderer.setUnicodeFlag(unicodeFlag);
}
}
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,16 +1,6 @@
package appeng.fluids.container;
import java.util.Collections;
import java.util.Map;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.IContainerListener;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidUtil;
import appeng.api.config.Upgrades;
import appeng.api.implementations.IUpgradeableHost;
import appeng.api.storage.data.IAEFluidStack;
@@ -19,99 +9,87 @@ import appeng.fluids.helper.FluidSyncHelper;
import appeng.fluids.util.AEFluidStack;
import appeng.fluids.util.IAEFluidTank;
import appeng.util.Platform;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.IContainerListener;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidUtil;
import java.util.Collections;
import java.util.Map;
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( InventoryPlayer ip, IUpgradeableHost te )
{
super( ip, te );
}
public ContainerFluidConfigurable(InventoryPlayer ip, IUpgradeableHost te) {
super(ip, te);
}
public abstract IAEFluidTank getFluidConfigInventory();
public abstract IAEFluidTank getFluidConfigInventory();
private FluidSyncHelper getSynchHelper()
{
if( this.sync == null )
{
this.sync = new FluidSyncHelper( this.getFluidConfigInventory(), 0 );
}
return this.sync;
}
private FluidSyncHelper getSynchHelper() {
if (this.sync == null) {
this.sync = new FluidSyncHelper(this.getFluidConfigInventory(), 0);
}
return this.sync;
}
@Override
protected ItemStack transferStackToContainer( ItemStack input )
{
FluidStack fs = FluidUtil.getFluidContained( input );
if( fs != null )
{
final IAEFluidTank t = this.getFluidConfigInventory();
final IAEFluidStack stack = AEFluidStack.fromFluidStack( fs );
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) {
FluidStack fs = FluidUtil.getFluidContained(input);
if (fs != null) {
final IAEFluidTank t = this.getFluidConfigInventory();
final IAEFluidStack stack = AEFluidStack.fromFluidStack(fs);
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;
}
return slot <= 4 || upgrades >= 2;
}
return true;
}
return true;
}
@Override
protected void standardDetectAndSendChanges()
{
if( Platform.isServer() )
{
this.getSynchHelper().sendDiff( this.listeners );
@Override
protected void standardDetectAndSendChanges() {
if (Platform.isServer()) {
this.getSynchHelper().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.getSynchHelper().sendFull( Collections.singleton( listener ) );
}
@Override
public void addListener(IContainerListener listener) {
super.addListener(listener);
this.getSynchHelper().sendFull(Collections.singleton(listener));
}
@Override
public void receiveFluidSlots( Map<Integer, IAEFluidStack> fluids )
{
this.getSynchHelper().readPacket( fluids );
}
@Override
public void receiveFluidSlots(Map<Integer, IAEFluidStack> fluids) {
this.getSynchHelper().readPacket(fluids);
}
}
@@ -1,103 +1,87 @@
package appeng.fluids.container;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraftforge.items.IItemHandler;
import appeng.api.config.SecurityPermissions;
import appeng.api.config.Upgrades;
import appeng.api.storage.data.IAEFluidStack;
import appeng.container.slot.SlotRestrictedInput;
import appeng.fluids.parts.PartFluidFormationPlane;
import appeng.fluids.util.IAEFluidTank;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraftforge.items.IItemHandler;
public class ContainerFluidFormationPlane extends ContainerFluidConfigurable
{
private final PartFluidFormationPlane plane;
public class ContainerFluidFormationPlane extends ContainerFluidConfigurable {
private final PartFluidFormationPlane plane;
public ContainerFluidFormationPlane( final InventoryPlayer ip, final PartFluidFormationPlane te )
{
super( ip, te );
this.plane = te;
}
public ContainerFluidFormationPlane(final InventoryPlayer ip, final PartFluidFormationPlane te) {
super(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.addSlotToContainer( ( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 0, 187, 8, this.getInventoryPlayer() ) )
.setNotDraggable() );
this.addSlotToContainer(
( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 1, 187, 8 + 18, this.getInventoryPlayer() ) )
.setNotDraggable() );
this.addSlotToContainer(
( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 2, 187, 8 + 18 * 2, this.getInventoryPlayer() ) )
.setNotDraggable() );
this.addSlotToContainer(
( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 3, 187, 8 + 18 * 3, this.getInventoryPlayer() ) )
.setNotDraggable() );
this.addSlotToContainer(
( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 4, 187, 8 + 18 * 4, this.getInventoryPlayer() ) )
.setNotDraggable() );
}
@Override
protected void setupConfig() {
final IItemHandler upgrades = this.getUpgradeable().getInventoryByName("upgrades");
this.addSlotToContainer((new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 0, 187, 8, this.getInventoryPlayer()))
.setNotDraggable());
this.addSlotToContainer(
(new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 1, 187, 8 + 18, this.getInventoryPlayer()))
.setNotDraggable());
this.addSlotToContainer(
(new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 2, 187, 8 + 18 * 2, this.getInventoryPlayer()))
.setNotDraggable());
this.addSlotToContainer(
(new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 3, 187, 8 + 18 * 3, this.getInventoryPlayer()))
.setNotDraggable());
this.addSlotToContainer(
(new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 4, 187, 8 + 18 * 4, this.getInventoryPlayer()))
.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;
}
}
return y < upgrades + 2;
}
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;
}
}
@@ -19,10 +19,9 @@
package appeng.fluids.container;
import net.minecraft.entity.player.InventoryPlayer;
import appeng.fluids.parts.PartSharedFluidBus;
import appeng.fluids.util.IAEFluidTank;
import net.minecraft.entity.player.InventoryPlayer;
/**
@@ -30,25 +29,21 @@ import appeng.fluids.util.IAEFluidTank;
* @version rv5 - 1/05/2018
* @since rv5 1/05/2018
*/
public class ContainerFluidIO extends ContainerFluidConfigurable
{
private final PartSharedFluidBus bus;
public class ContainerFluidIO extends ContainerFluidConfigurable {
private final PartSharedFluidBus bus;
public ContainerFluidIO( InventoryPlayer ip, PartSharedFluidBus te )
{
super( ip, te );
this.bus = te;
}
public ContainerFluidIO(InventoryPlayer ip, PartSharedFluidBus te) {
super(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();
}
}
@@ -19,243 +19,201 @@
package appeng.fluids.container;
import javax.annotation.Nonnull;
import java.util.Collections;
import java.util.Map;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.PacketTargetFluidStack;
import appeng.fluids.util.AEFluidStack;
import appeng.helpers.InventoryAction;
import appeng.util.IConfigManagerHost;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.IContainerListener;
import appeng.api.config.SecurityPermissions;
import appeng.api.storage.data.IAEFluidStack;
import appeng.api.util.IConfigManager;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.PacketTargetFluidStack;
import appeng.fluids.helper.DualityFluidInterface;
import appeng.fluids.helper.FluidSyncHelper;
import appeng.fluids.helper.IFluidInterfaceHost;
import appeng.fluids.util.AEFluidStack;
import appeng.fluids.util.IAEFluidTank;
import appeng.helpers.InventoryAction;
import appeng.util.IConfigManagerHost;
import appeng.util.Platform;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.IContainerListener;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidUtil;
import net.minecraftforge.fluids.capability.IFluidHandlerItem;
import javax.annotation.Nonnull;
import java.util.Collections;
import java.util.Map;
public class ContainerFluidInterface extends ContainerFluidConfigurable implements IConfigManagerHost
{
private final DualityFluidInterface myDuality;
private final FluidSyncHelper tankSync;
private IConfigManagerHost gui;
// Holds the fluid the client wishes to extract, or null for insert
private IAEFluidStack clientRequestedTargetFluid = null;
public ContainerFluidInterface( final InventoryPlayer ip, final IFluidInterfaceHost te )
{
super( ip, te.getDualityFluidInterface().getHost() );
public class ContainerFluidInterface extends ContainerFluidConfigurable implements IConfigManagerHost {
private final DualityFluidInterface myDuality;
private final FluidSyncHelper tankSync;
private IConfigManagerHost gui;
// Holds the fluid the client wishes to extract, or null for insert
private IAEFluidStack clientRequestedTargetFluid = null;
this.myDuality = te.getDualityFluidInterface();
this.tankSync = new FluidSyncHelper( this.myDuality.getTanks(), DualityFluidInterface.NUMBER_OF_TANKS );
}
public ContainerFluidInterface(final InventoryPlayer ip, final IFluidInterfaceHost te) {
super(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);
}
@Override
public IAEFluidTank getFluidConfigInventory()
{
return this.myDuality.getConfig();
}
@Override
protected int getHeight() {
return 231;
}
@Override
public void updateSetting( IConfigManager manager, Enum settingName, Enum newValue )
{
if( this.getGui() != null )
{
this.getGui().updateSetting( manager, settingName, newValue );
}
}
@Override
public IAEFluidTank getFluidConfigInventory() {
return this.myDuality.getConfig();
}
@Override
public void detectAndSendChanges()
{
this.verifyPermissions( SecurityPermissions.BUILD, false );
@Override
public void updateSetting(IConfigManager manager, Enum settingName, Enum newValue) {
if (this.getGui() != null) {
this.getGui().updateSetting(manager, settingName, newValue);
}
}
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));
}
private IConfigManagerHost getGui()
{
return this.gui;
}
@Override
public void receiveFluidSlots(Map<Integer, IAEFluidStack> fluids) {
super.receiveFluidSlots(fluids);
this.tankSync.readPacket(fluids);
}
public void setGui( @Nonnull final IConfigManagerHost gui )
{
this.gui = gui;
}
private IConfigManagerHost getGui() {
return this.gui;
}
public void doAction( EntityPlayerMP player, InventoryAction action, int slot, long id )
{
if( action != InventoryAction.FILL_ITEM && action != InventoryAction.EMPTY_ITEM )
{
super.doAction( player, action, slot, id );
return;
}
public void setGui(@Nonnull final IConfigManagerHost gui) {
this.gui = gui;
}
final ItemStack held = player.inventory.getItemStack();
ItemStack heldCopy = held.copy();
heldCopy.setCount( 1 );
IFluidHandlerItem fh = FluidUtil.getFluidHandler( heldCopy );
if( fh == null )
{
// only fluid handlers items
return;
}
public void doAction(EntityPlayerMP player, InventoryAction action, int slot, long id) {
if (action != InventoryAction.FILL_ITEM && action != InventoryAction.EMPTY_ITEM) {
super.doAction(player, action, slot, id);
return;
}
if( action == InventoryAction.FILL_ITEM && this.clientRequestedTargetFluid != null )
{
final IAEFluidStack stack = this.clientRequestedTargetFluid.copy();
final ItemStack held = player.inventory.getItemStack();
ItemStack heldCopy = held.copy();
heldCopy.setCount(1);
IFluidHandlerItem fh = FluidUtil.getFluidHandler(heldCopy);
if (fh == null) {
// only fluid handlers items
return;
}
// Check how much we can store in the item
stack.setStackSize( Integer.MAX_VALUE );
int amountAllowed = fh.fill( stack.getFluidStack(), false );
int heldAmount = held.getCount();
for( int i = 0; i < heldAmount; i++ )
{
ItemStack copiedFluidContainer = held.copy();
copiedFluidContainer.setCount( 1 );
fh = FluidUtil.getFluidHandler( copiedFluidContainer );
if (action == InventoryAction.FILL_ITEM && this.clientRequestedTargetFluid != null) {
final IAEFluidStack stack = this.clientRequestedTargetFluid.copy();
FluidStack extractableFluid = this.myDuality.getTanks().drain( stack.setStackSize( amountAllowed ).getFluidStack(), false );
if( extractableFluid == null || extractableFluid.amount == 0 )
{
break;
}
// Check how much we can store in the item
stack.setStackSize(Integer.MAX_VALUE);
int amountAllowed = fh.fill(stack.getFluidStack(), false);
int heldAmount = held.getCount();
for (int i = 0; i < heldAmount; i++) {
ItemStack copiedFluidContainer = held.copy();
copiedFluidContainer.setCount(1);
fh = FluidUtil.getFluidHandler(copiedFluidContainer);
int fillableAmount = fh.fill( extractableFluid, false );
if( fillableAmount > 0 )
{
FluidStack extractedFluid = this.myDuality.getTanks().drain( extractableFluid, true );
fh.fill( extractedFluid, true );
}
FluidStack extractableFluid = this.myDuality.getTanks().drain(stack.setStackSize(amountAllowed).getFluidStack(), false);
if (extractableFluid == null || extractableFluid.amount == 0) {
break;
}
if( held.getCount() == 1 )
{
player.inventory.setItemStack( fh.getContainer() );
}
else
{
player.inventory.getItemStack().shrink( 1 );
if( !player.inventory.addItemStackToInventory( fh.getContainer() ) )
{
player.dropItem( fh.getContainer(), false );
}
}
}
}
else if( action == InventoryAction.EMPTY_ITEM )
{
int heldAmount = held.getCount();
for( int i = 0; i < heldAmount; i++ )
{
ItemStack copiedFluidContainer = held.copy();
copiedFluidContainer.setCount( 1 );
fh = FluidUtil.getFluidHandler( copiedFluidContainer );
int fillableAmount = fh.fill(extractableFluid, false);
if (fillableAmount > 0) {
FluidStack extractedFluid = this.myDuality.getTanks().drain(extractableFluid, true);
fh.fill(extractedFluid, true);
}
FluidStack drainable = fh.drain( this.myDuality.getTanks().getTankProperties()[slot].getCapacity(), false );
if( drainable != null )
{
fh.drain( drainable, true );
this.myDuality.getTanks().fill( drainable, true );
}
if (held.getCount() == 1) {
player.inventory.setItemStack(fh.getContainer());
} else {
player.inventory.getItemStack().shrink(1);
if (!player.inventory.addItemStackToInventory(fh.getContainer())) {
player.dropItem(fh.getContainer(), false);
}
}
}
} else if (action == InventoryAction.EMPTY_ITEM) {
int heldAmount = held.getCount();
for (int i = 0; i < heldAmount; i++) {
ItemStack copiedFluidContainer = held.copy();
copiedFluidContainer.setCount(1);
fh = FluidUtil.getFluidHandler(copiedFluidContainer);
if( held.getCount() == 1 )
{
player.inventory.setItemStack( fh.getContainer() );
}
else
{
player.inventory.getItemStack().shrink( 1 );
if( !player.inventory.addItemStackToInventory( fh.getContainer() ) )
{
player.dropItem( fh.getContainer(), false );
}
}
}
}
this.updateHeld( player );
}
FluidStack drainable = fh.drain(this.myDuality.getTanks().getTankProperties()[slot].getCapacity(), false);
if (drainable != null) {
fh.drain(drainable, true);
this.myDuality.getTanks().fill(drainable, true);
}
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 ) );
}
if (held.getCount() == 1) {
player.inventory.setItemStack(fh.getContainer());
} else {
player.inventory.getItemStack().shrink(1);
if (!player.inventory.addItemStackToInventory(fh.getContainer())) {
player.dropItem(fh.getContainer(), false);
}
}
}
}
this.updateHeld(player);
}
this.clientRequestedTargetFluid = stack == null ? null : stack.copy();
}
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));
}
@Override
protected boolean supportCapacity()
{
return false;
}
this.clientRequestedTargetFluid = stack == null ? null : stack.copy();
}
@Override
public int availableUpgrades()
{
return 0;
}
@Override
protected boolean supportCapacity() {
return false;
}
@Override
public boolean hasToolbox()
{
return false;
}
@Override
public int availableUpgrades() {
return 0;
}
@Override
public boolean hasToolbox() {
return false;
}
}
@@ -1,13 +1,6 @@
package appeng.fluids.container;
import net.minecraft.client.gui.GuiTextField;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import appeng.api.config.RedstoneMode;
import appeng.api.config.SecurityPermissions;
import appeng.api.config.Settings;
@@ -15,83 +8,75 @@ import appeng.container.guisync.GuiSync;
import appeng.fluids.parts.PartFluidLevelEmitter;
import appeng.fluids.util.IAEFluidTank;
import appeng.util.Platform;
import net.minecraft.client.gui.GuiTextField;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class ContainerFluidLevelEmitter extends ContainerFluidConfigurable
{
private final PartFluidLevelEmitter lvlEmitter;
public class ContainerFluidLevelEmitter extends ContainerFluidConfigurable {
private final PartFluidLevelEmitter lvlEmitter;
@SideOnly( Side.CLIENT )
private GuiTextField textField;
@GuiSync( 3 )
public long EmitterValue = -1;
@SideOnly(Side.CLIENT)
private GuiTextField textField;
@GuiSync(3)
public long EmitterValue = -1;
public ContainerFluidLevelEmitter( final InventoryPlayer ip, final PartFluidLevelEmitter te )
{
super( ip, te );
this.lvlEmitter = te;
}
public ContainerFluidLevelEmitter(final InventoryPlayer ip, final PartFluidLevelEmitter te) {
super(ip, te);
this.lvlEmitter = te;
}
@SideOnly( Side.CLIENT )
public void setTextField( final GuiTextField level )
{
this.textField = level;
this.textField.setText( String.valueOf( this.EmitterValue ) );
}
@SideOnly(Side.CLIENT)
public void setTextField(final GuiTextField level) {
this.textField = level;
this.textField.setText(String.valueOf(this.EmitterValue));
}
public void setLevel( final long l, final EntityPlayer player )
{
this.lvlEmitter.setReportingValue( l );
this.EmitterValue = l;
}
public void setLevel(final long l, final EntityPlayer 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();
}
}
@@ -19,18 +19,8 @@
package appeng.fluids.container;
import java.util.Iterator;
import net.minecraft.entity.player.InventoryPlayer;
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.config.*;
import appeng.api.storage.IMEInventory;
import appeng.api.storage.channels.IFluidStorageChannel;
import appeng.api.storage.data.IAEFluidStack;
@@ -41,6 +31,10 @@ import appeng.fluids.parts.PartFluidStorageBus;
import appeng.fluids.util.IAEFluidTank;
import appeng.util.Platform;
import appeng.util.iterators.NullIterator;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraftforge.items.IItemHandler;
import java.util.Iterator;
/**
@@ -48,163 +42,136 @@ import appeng.util.iterators.NullIterator;
* @version rv6 - 22/05/2018
* @since rv6 22/05/2018
*/
public class ContainerFluidStorageBus extends ContainerFluidConfigurable
{
public class ContainerFluidStorageBus extends ContainerFluidConfigurable {
private final PartFluidStorageBus storageBus;
private final PartFluidStorageBus storageBus;
@GuiSync( 3 )
public AccessRestriction rwMode = AccessRestriction.READ_WRITE;
@GuiSync(3)
public AccessRestriction rwMode = AccessRestriction.READ_WRITE;
@GuiSync( 4 )
public StorageFilter storageFilter = StorageFilter.EXTRACTABLE_ONLY;
@GuiSync(4)
public StorageFilter storageFilter = StorageFilter.EXTRACTABLE_ONLY;
public ContainerFluidStorageBus( InventoryPlayer ip, PartFluidStorageBus te )
{
super( ip, te );
this.storageBus = te;
}
public ContainerFluidStorageBus(InventoryPlayer ip, PartFluidStorageBus te) {
super(ip, te);
this.storageBus = te;
}
@Override
protected int getHeight()
{
return 251;
}
@Override
protected int getHeight() {
return 251;
}
@Override
protected void setupConfig()
{
final IItemHandler upgrades = this.getUpgradeable().getInventoryByName( "upgrades" );
this.addSlotToContainer( ( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 0, 187, 8, this.getInventoryPlayer() ) )
.setNotDraggable() );
this.addSlotToContainer(
( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 1, 187, 8 + 18, this.getInventoryPlayer() ) )
.setNotDraggable() );
this.addSlotToContainer(
( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 2, 187, 8 + 18 * 2, this.getInventoryPlayer() ) )
.setNotDraggable() );
this.addSlotToContainer(
( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 3, 187, 8 + 18 * 3, this.getInventoryPlayer() ) )
.setNotDraggable() );
this.addSlotToContainer(
( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 4, 187, 8 + 18 * 4, this.getInventoryPlayer() ) )
.setNotDraggable() );
}
@Override
protected void setupConfig() {
final IItemHandler upgrades = this.getUpgradeable().getInventoryByName("upgrades");
this.addSlotToContainer((new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 0, 187, 8, this.getInventoryPlayer()))
.setNotDraggable());
this.addSlotToContainer(
(new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 1, 187, 8 + 18, this.getInventoryPlayer()))
.setNotDraggable());
this.addSlotToContainer(
(new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 2, 187, 8 + 18 * 2, this.getInventoryPlayer()))
.setNotDraggable());
this.addSlotToContainer(
(new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 3, 187, 8 + 18 * 3, this.getInventoryPlayer()))
.setNotDraggable());
this.addSlotToContainer(
(new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 4, 187, 8 + 18 * 4, this.getInventoryPlayer()))
.setNotDraggable());
}
@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;
}
}
return y < upgrades + 2;
}
return true;
}
return true;
}
@Override
protected boolean supportCapacity()
{
return true;
}
@Override
protected boolean supportCapacity() {
return true;
}
@Override
public int availableUpgrades()
{
return 5;
}
@Override
public int availableUpgrades() {
return 5;
}
@Override
public void detectAndSendChanges()
{
this.verifyPermissions( SecurityPermissions.BUILD, false );
@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 ) );
}
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();
}
this.standardDetectAndSendChanges();
}
@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;
}
public void clear()
{
IAEFluidTank h = this.storageBus.getConfig();
for( int i = 0; i < h.getSlots(); ++i )
{
h.setFluidInSlot( i, null );
}
this.detectAndSendChanges();
}
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();
public void partition() {
IAEFluidTank h = this.storageBus.getConfig();
final IMEInventory<IAEFluidStack> cellInv = this.storageBus.getInternalHandler();
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();
}
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();
}
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;
}
public AccessRestriction getReadWriteMode() {
return this.rwMode;
}
private void setReadWriteMode( final AccessRestriction rwMode )
{
this.rwMode = rwMode;
}
private void setReadWriteMode(final AccessRestriction rwMode) {
this.rwMode = rwMode;
}
public StorageFilter getStorageFilter()
{
return this.storageFilter;
}
public StorageFilter getStorageFilter() {
return this.storageFilter;
}
private void setStorageFilter( final StorageFilter storageFilter )
{
this.storageFilter = storageFilter;
}
private void setStorageFilter(final StorageFilter storageFilter) {
this.storageFilter = storageFilter;
}
@Override
public IAEFluidTank getFluidConfigInventory()
{
return this.storageBus.getConfig();
}
@Override
public IAEFluidTank getFluidConfigInventory() {
return this.storageBus.getConfig();
}
}
@@ -19,30 +19,8 @@
package appeng.fluids.container;
import java.io.IOException;
import java.nio.BufferOverflowException;
import javax.annotation.Nonnull;
import appeng.container.slot.AppEngSlot;
import appeng.container.slot.SlotPlayerHotBar;
import appeng.container.slot.SlotPlayerInv;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.IContainerListener;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidUtil;
import net.minecraftforge.fluids.capability.IFluidHandlerItem;
import appeng.api.AEApi;
import appeng.api.config.Actionable;
import appeng.api.config.PowerMultiplier;
import appeng.api.config.Settings;
import appeng.api.config.SortDir;
import appeng.api.config.SortOrder;
import appeng.api.config.ViewItems;
import appeng.api.config.*;
import appeng.api.networking.IGrid;
import appeng.api.networking.IGridHost;
import appeng.api.networking.IGridNode;
@@ -62,6 +40,9 @@ import appeng.api.util.IConfigManager;
import appeng.api.util.IConfigurableObject;
import appeng.container.AEBaseContainer;
import appeng.container.guisync.GuiSync;
import appeng.container.slot.AppEngSlot;
import appeng.container.slot.SlotPlayerHotBar;
import appeng.container.slot.SlotPlayerInv;
import appeng.core.AELog;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.PacketMEFluidInventoryUpdate;
@@ -73,7 +54,18 @@ import appeng.me.helpers.ChannelPowerSrc;
import appeng.util.ConfigManager;
import appeng.util.IConfigManagerHost;
import appeng.util.Platform;
import net.minecraftforge.items.IItemHandler;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.IContainerListener;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidUtil;
import net.minecraftforge.fluids.capability.IFluidHandlerItem;
import javax.annotation.Nonnull;
import java.io.IOException;
import java.nio.BufferOverflowException;
/**
@@ -81,540 +73,424 @@ import net.minecraftforge.items.IItemHandler;
* @version rv6 - 12/05/2018
* @since rv6 12/05/2018
*/
public class ContainerFluidTerminal extends AEBaseContainer implements IConfigManagerHost, IConfigurableObject, IMEMonitorHandlerReceiver<IAEFluidStack>
{
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 class ContainerFluidTerminal extends AEBaseContainer implements IConfigManagerHost, IConfigurableObject, IMEMonitorHandlerReceiver<IAEFluidStack> {
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 final 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( InventoryPlayer ip, ITerminalHost terminal )
{
super( ip, terminal );
this.terminal = terminal;
this.clientCM = new ConfigManager( this );
public ContainerFluidTerminal(InventoryPlayer ip, ITerminalHost terminal) {
super(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 ) );
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 (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 (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 );
}
if (node != null) {
this.networkNode = node;
final IGrid g = node.getGrid();
if (g != null) {
this.setPowerSource(new ChannelPowerSrc(this.networkNode, g.getCache(IEnergyGrid.class)));
}
}
}
}
} else {
this.monitor = null;
}
this.bindPlayerInventory(ip, 0, 222 - 82);
}
@Override
public boolean isValid( Object verificationToken )
{
return true;
}
@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 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 onListUpdate() {
for (final IContainerListener c : this.listeners) {
this.queueInventory(c);
}
}
@Override
public void addListener( IContainerListener listener )
{
super.addListener( listener );
@Override
public void addListener(IContainerListener listener) {
super.addListener(listener);
this.queueInventory( listener );
}
this.queueInventory(listener);
}
@Override
public void onContainerClosed( final EntityPlayer player )
{
super.onContainerClosed( player );
if( this.monitor != null )
{
this.monitor.removeListener( this );
}
}
@Override
public void onContainerClosed(final EntityPlayer player) {
super.onContainerClosed(player);
if (this.monitor != null) {
this.monitor.removeListener(this);
}
}
private void queueInventory( final IContainerListener c )
{
if( Platform.isServer() && c instanceof EntityPlayer && this.monitor != null )
{
try
{
PacketMEFluidInventoryUpdate piu = new PacketMEFluidInventoryUpdate();
final IItemList<IAEFluidStack> monitorCache = this.monitor.getStorageList();
private void queueInventory(final IContainerListener c) {
if (Platform.isServer() && c instanceof EntityPlayer && 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, (EntityPlayerMP) c );
for (final IAEFluidStack send : monitorCache) {
try {
piu.appendFluid(send);
} catch (final BufferOverflowException boe) {
NetworkHandler.instance().sendTo(piu, (EntityPlayerMP) c);
piu = new PacketMEFluidInventoryUpdate();
piu.appendFluid( send );
}
}
piu = new PacketMEFluidInventoryUpdate();
piu.appendFluid(send);
}
}
NetworkHandler.instance().sendTo( piu, (EntityPlayerMP) c );
}
catch( final IOException e )
{
AELog.debug( e );
}
}
}
NetworkHandler.instance().sendTo(piu, (EntityPlayerMP) c);
} catch (final IOException e) {
AELog.debug(e);
}
}
}
@Override
public IConfigManager getConfigManager()
{
if( Platform.isServer() )
{
return this.serverCM;
}
return this.clientCM;
}
@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 ) );
}
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();
}
this.clientRequestedTargetFluid = stack == null ? null : stack.copy();
}
@Override
public void updateSetting( IConfigManager manager, Enum settingName, Enum newValue )
{
if( this.getGui() != null )
{
this.getGui().updateSetting( manager, settingName, newValue );
}
}
@Override
public void updateSetting(IConfigManager manager, Enum 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 );
}
@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 );
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 EntityPlayerMP )
{
try
{
NetworkHandler.instance().sendTo( new PacketValueConfig( set.name(), sideLocal.name() ), (EntityPlayerMP) crafter );
}
catch( final IOException e )
{
AELog.debug( e );
}
}
}
}
}
if (sideLocal != sideRemote) {
this.clientCM.putSetting(set, sideLocal);
for (final IContainerListener crafter : this.listeners) {
if (crafter instanceof EntityPlayerMP) {
try {
NetworkHandler.instance().sendTo(new PacketValueConfig(set.name(), sideLocal.name()), (EntityPlayerMP) crafter);
} catch (final IOException e) {
AELog.debug(e);
}
}
}
}
}
if( !this.fluids.isEmpty() )
{
try
{
final IItemList<IAEFluidStack> monitorCache = this.monitor.getStorageList();
if (!this.fluids.isEmpty()) {
try {
final IItemList<IAEFluidStack> monitorCache = this.monitor.getStorageList();
final PacketMEFluidInventoryUpdate piu = new PacketMEFluidInventoryUpdate();
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 );
}
}
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();
if (!piu.isEmpty()) {
this.fluids.resetStatus();
for( final Object c : this.listeners )
{
if( c instanceof EntityPlayer )
{
NetworkHandler.instance().sendTo( piu, (EntityPlayerMP) c );
}
}
}
}
catch( final IOException e )
{
AELog.debug( e );
}
}
this.updatePowerStatus();
for (final Object c : this.listeners) {
if (c instanceof EntityPlayer) {
NetworkHandler.instance().sendTo(piu, (EntityPlayerMP) c);
}
}
}
} catch (final IOException e) {
AELog.debug(e);
}
}
this.updatePowerStatus();
super.detectAndSendChanges();
}
}
super.detectAndSendChanges();
}
}
@Override
public ItemStack transferStackInSlot( final EntityPlayer p, final int idx )
{
if( Platform.isClient() )
{
return ItemStack.EMPTY;
}
EntityPlayerMP player = (EntityPlayerMP) p;
if( this.inventorySlots.get( idx ) instanceof SlotPlayerInv || this.inventorySlots.get( idx ) instanceof SlotPlayerHotBar )
{
final AppEngSlot clickSlot = (AppEngSlot) this.inventorySlots.get( idx ); // require AE SLots!
ItemStack itemStack = clickSlot.getStack();
@Override
public ItemStack transferStackInSlot(final EntityPlayer p, final int idx) {
if (Platform.isClient()) {
return ItemStack.EMPTY;
}
EntityPlayerMP player = (EntityPlayerMP) p;
if (this.inventorySlots.get(idx) instanceof SlotPlayerInv || this.inventorySlots.get(idx) instanceof SlotPlayerHotBar) {
final AppEngSlot clickSlot = (AppEngSlot) this.inventorySlots.get(idx); // require AE SLots!
ItemStack itemStack = clickSlot.getStack();
ItemStack copy = itemStack.copy();
copy.setCount( 1 );
IFluidHandlerItem fh = FluidUtil.getFluidHandler( copy );
if( fh == null )
{
// only fluid handlers items
return ItemStack.EMPTY;
}
ItemStack copy = itemStack.copy();
copy.setCount(1);
IFluidHandlerItem fh = FluidUtil.getFluidHandler(copy);
if (fh == null) {
// only fluid handlers items
return ItemStack.EMPTY;
}
int heldAmount = itemStack.getCount();
for( int i = 0; i < heldAmount; i++ )
{
copy = itemStack.copy();
copy.setCount( 1 );
fh = FluidUtil.getFluidHandler( copy );
int heldAmount = itemStack.getCount();
for (int i = 0; i < heldAmount; i++) {
copy = itemStack.copy();
copy.setCount(1);
fh = FluidUtil.getFluidHandler(copy);
final FluidStack extract = fh.drain( Integer.MAX_VALUE, false );
if( extract == null || extract.amount < 1 )
{
return ItemStack.EMPTY;
}
final FluidStack extract = fh.drain(Integer.MAX_VALUE, false);
if (extract == null || extract.amount < 1) {
return ItemStack.EMPTY;
}
// Check if we can push into the system
final IAEFluidStack notStorable = Platform.poweredInsert( this.getPowerSource(), this.monitor, AEFluidStack.fromFluidStack( extract ), this.getActionSource(), Actionable.SIMULATE );
// 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.amount - notStorable.getStackSize() );
final FluidStack storable = fh.drain( toStore, false );
if (notStorable != null && notStorable.getStackSize() > 0) {
final int toStore = (int) (extract.amount - notStorable.getStackSize());
final FluidStack storable = fh.drain(toStore, false);
if( storable == null || storable.amount == 0 )
{
return ItemStack.EMPTY;
}
else
{
extract.amount = storable.amount;
}
}
if (storable == null || storable.amount == 0) {
return ItemStack.EMPTY;
} else {
extract.amount = storable.amount;
}
}
// Actually drain
final FluidStack drained = fh.drain( extract, true );
extract.amount = drained.amount;
// Actually drain
final FluidStack drained = fh.drain(extract, true);
extract.amount = drained.amount;
final IAEFluidStack notInserted = Platform.poweredInsert( this.getPowerSource(), this.monitor, AEFluidStack.fromFluidStack( extract ), this.getActionSource() );
final IAEFluidStack notInserted = Platform.poweredInsert(this.getPowerSource(), this.monitor, AEFluidStack.fromFluidStack(extract), this.getActionSource());
if( notInserted != null && notInserted.getStackSize() > 0 )
{
IAEFluidStack spill = this.monitor.injectItems( notInserted, Actionable.MODULATE, this.getActionSource() );
if( spill != null && spill.getStackSize() > 0 )
{
fh.fill( spill.getFluidStack(), true );
}
}
if (notInserted != null && notInserted.getStackSize() > 0) {
IAEFluidStack spill = this.monitor.injectItems(notInserted, Actionable.MODULATE, this.getActionSource());
if (spill != null && spill.getStackSize() > 0) {
fh.fill(spill.getFluidStack(), true);
}
}
if( notInserted == null || notInserted.getStackSize() == 0 )
{
if( !player.inventory.addItemStackToInventory( fh.getContainer() ) )
{
player.dropItem( fh.getContainer(), false );
}
clickSlot.decrStackSize( 1 );
}
}
this.detectAndSendChanges();
return ItemStack.EMPTY;
}
return super.transferStackInSlot( p, idx );
}
if (notInserted == null || notInserted.getStackSize() == 0) {
if (!player.inventory.addItemStackToInventory(fh.getContainer())) {
player.dropItem(fh.getContainer(), false);
}
clickSlot.decrStackSize(1);
}
}
this.detectAndSendChanges();
return ItemStack.EMPTY;
}
return super.transferStackInSlot(p, idx);
}
@Override
public void doAction( EntityPlayerMP player, InventoryAction action, int slot, long id )
{
if( action != InventoryAction.FILL_ITEM && action != InventoryAction.EMPTY_ITEM )
{
super.doAction( player, action, slot, id );
return;
}
@Override
public void doAction(EntityPlayerMP 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();
ItemStack heldCopy = held.copy();
heldCopy.setCount( 1 );
IFluidHandlerItem fh = FluidUtil.getFluidHandler( heldCopy );
if( fh == null )
{
// only fluid handlers items
return;
}
final ItemStack held = player.inventory.getItemStack();
ItemStack heldCopy = held.copy();
heldCopy.setCount(1);
IFluidHandlerItem fh = FluidUtil.getFluidHandler(heldCopy);
if (fh == null) {
// only fluid handlers items
return;
}
if( action == InventoryAction.FILL_ITEM && this.clientRequestedTargetFluid != null )
{
final IAEFluidStack stack = this.clientRequestedTargetFluid.copy();
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(), false );
int heldAmount = held.getCount();
for( int i = 0; i < heldAmount; i++ )
{
ItemStack copiedFluidContainer = held.copy();
copiedFluidContainer.setCount( 1 );
fh = FluidUtil.getFluidHandler( copiedFluidContainer );
// Check how much we can store in the item
stack.setStackSize(Integer.MAX_VALUE);
int amountAllowed = fh.fill(stack.getFluidStack(), false);
int heldAmount = held.getCount();
for (int i = 0; i < heldAmount; i++) {
ItemStack copiedFluidContainer = held.copy();
copiedFluidContainer.setCount(1);
fh = FluidUtil.getFluidHandler(copiedFluidContainer);
// Check if we can pull out of the system
final IAEFluidStack canPull = Platform.poweredExtraction( this.getPowerSource(), this.monitor, stack.setStackSize( amountAllowed ), this.getActionSource(), Actionable.SIMULATE );
if( canPull == null || canPull.getStackSize() < 1 )
{
return;
}
// Check if we can pull out of the system
final IAEFluidStack canPull = Platform.poweredExtraction(this.getPowerSource(), this.monitor, stack.setStackSize(amountAllowed), 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(), false );
if( canFill == 0 )
{
return;
}
// How much could fit into the container
final int canFill = fh.fill(canPull.getFluidStack(), false);
if (canFill == 0) {
return;
}
// Now actually pull out of the system
final IAEFluidStack pulled = Platform.poweredExtraction( this.getPowerSource(), this.monitor, stack.setStackSize( canFill ), 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;
}
// Now actually pull out of the system
final IAEFluidStack pulled = Platform.poweredExtraction(this.getPowerSource(), this.monitor, stack.setStackSize(canFill), 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(), true );
// Actually fill
final int used = fh.fill(pulled.getFluidStack(), true);
if( used != canFill )
{
AELog.error( "Fluid item [%s] reported a different possible amount than it actually accepted.", held.getDisplayName() );
}
if (used != canFill) {
AELog.error("Fluid item [%s] reported a different possible amount than it actually accepted.", held.getDisplayName());
}
if( held.getCount() == 1 )
{
player.inventory.setItemStack( fh.getContainer() );
}
else
{
player.inventory.getItemStack().shrink( 1 );
if( !player.inventory.addItemStackToInventory( fh.getContainer() ) )
{
player.dropItem( fh.getContainer(), false );
}
}
}
this.updateHeld( player );
if (held.getCount() == 1) {
player.inventory.setItemStack(fh.getContainer());
} else {
player.inventory.getItemStack().shrink(1);
if (!player.inventory.addItemStackToInventory(fh.getContainer())) {
player.dropItem(fh.getContainer(), false);
}
}
}
this.updateHeld(player);
}
else if( action == InventoryAction.EMPTY_ITEM )
{
int heldAmount = held.getCount();
for( int i = 0; i < heldAmount; i++ )
{
ItemStack copiedFluidContainer = held.copy();
copiedFluidContainer.setCount( 1 );
fh = FluidUtil.getFluidHandler( copiedFluidContainer );
} else if (action == InventoryAction.EMPTY_ITEM) {
int heldAmount = held.getCount();
for (int i = 0; i < heldAmount; i++) {
ItemStack copiedFluidContainer = held.copy();
copiedFluidContainer.setCount(1);
fh = FluidUtil.getFluidHandler(copiedFluidContainer);
// See how much we can drain from the item
final FluidStack extract = fh.drain( Integer.MAX_VALUE, false );
if( extract == null || extract.amount < 1 )
{
return;
}
// See how much we can drain from the item
final FluidStack extract = fh.drain(Integer.MAX_VALUE, false);
if (extract == null || extract.amount < 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 );
// 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.amount - notStorable.getStackSize() );
final FluidStack storable = fh.drain( toStore, false );
if (notStorable != null && notStorable.getStackSize() > 0) {
final int toStore = (int) (extract.amount - notStorable.getStackSize());
final FluidStack storable = fh.drain(toStore, false);
if( storable == null || storable.amount == 0 )
{
return;
}
else
{
extract.amount = storable.amount;
}
}
if (storable == null || storable.amount == 0) {
return;
} else {
extract.amount = storable.amount;
}
}
// Actually drain
final FluidStack drained = fh.drain( extract, true );
extract.amount = drained.amount;
// Actually drain
final FluidStack drained = fh.drain(extract, true);
extract.amount = drained.amount;
final IAEFluidStack notInserted = Platform.poweredInsert( this.getPowerSource(), this.monitor, AEFluidStack.fromFluidStack( extract ), this.getActionSource() );
final IAEFluidStack notInserted = Platform.poweredInsert(this.getPowerSource(), this.monitor, AEFluidStack.fromFluidStack(extract), this.getActionSource());
if( notInserted != null && notInserted.getStackSize() > 0 )
{
IAEFluidStack spill = this.monitor.injectItems( notInserted, Actionable.MODULATE, this.getActionSource() );
if( spill != null && spill.getStackSize() > 0 )
{
fh.fill( spill.getFluidStack(), true );
}
}
if (notInserted != null && notInserted.getStackSize() > 0) {
IAEFluidStack spill = this.monitor.injectItems(notInserted, Actionable.MODULATE, this.getActionSource());
if (spill != null && spill.getStackSize() > 0) {
fh.fill(spill.getFluidStack(), true);
}
}
if( held.getCount() == 1 )
{
player.inventory.setItemStack( fh.getContainer() );
}
else
{
player.inventory.getItemStack().shrink( 1 );
if( !player.inventory.addItemStackToInventory( fh.getContainer() ) )
{
player.dropItem( fh.getContainer(), false );
}
}
}
this.updateHeld( player );
}
}
if (held.getCount() == 1) {
player.inventory.setItemStack(fh.getContainer());
} else {
player.inventory.getItemStack().shrink(1);
if (!player.inventory.addItemStackToInventory(fh.getContainer())) {
player.dropItem(fh.getContainer(), false);
}
}
}
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
}
}
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;
}
private IConfigManagerHost getGui() {
return this.gui;
}
public void setGui( @Nonnull final IConfigManagerHost gui )
{
this.gui = gui;
}
public void setGui(@Nonnull final IConfigManagerHost gui) {
this.gui = gui;
}
public boolean isPowered()
{
return this.hasPower;
}
public boolean isPowered() {
return this.hasPower;
}
private void setPowered( final boolean isPowered )
{
this.hasPower = isPowered;
}
private void setPowered(final boolean isPowered) {
this.hasPower = isPowered;
}
}
@@ -1,13 +1,11 @@
package appeng.fluids.container;
import java.util.Map;
import appeng.api.storage.data.IAEFluidStack;
import java.util.Map;
public interface IFluidSyncContainer
{
void receiveFluidSlots( final Map<Integer, IAEFluidStack> fluids );
public interface IFluidSyncContainer {
void receiveFluidSlots(final Map<Integer, IAEFluidStack> fluids);
}
@@ -27,12 +27,10 @@ import appeng.api.storage.data.IAEFluidStack;
* @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
@@ -19,16 +19,15 @@
package appeng.fluids.helper;
import javax.annotation.Nonnull;
import appeng.core.Api;
import appeng.fluids.items.FluidDummyItem;
import appeng.items.contents.CellConfig;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidUtil;
import appeng.core.Api;
import appeng.fluids.items.FluidDummyItem;
import appeng.items.contents.CellConfig;
import javax.annotation.Nonnull;
/**
@@ -36,71 +35,60 @@ import appeng.items.contents.CellConfig;
* @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 );
}
FluidStack fluid = FluidUtil.getFluidContained( stack );
if( fluid == null || !Api.INSTANCE.definitions().items().dummyFluidItem().maybeStack( 1 ).isPresent() )
{
return stack;
}
@Override
@Nonnull
public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate) {
if (stack.isEmpty() || stack.getItem() instanceof FluidDummyItem) {
super.insertItem(slot, stack, simulate);
}
FluidStack fluid = FluidUtil.getFluidContained(stack);
if (fluid == null || !Api.INSTANCE.definitions().items().dummyFluidItem().maybeStack(1).isPresent()) {
return stack;
}
fluid.amount = Fluid.BUCKET_VOLUME;
ItemStack is = Api.INSTANCE.definitions().items().dummyFluidItem().maybeStack( 1 ).get();
FluidDummyItem item = (FluidDummyItem) is.getItem();
item.setFluidStack( is, fluid );
return super.insertItem( slot, is, simulate );
}
fluid.amount = Fluid.BUCKET_VOLUME;
ItemStack is = Api.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 );
}
FluidStack fluid = FluidUtil.getFluidContained( stack );
if( fluid == null || !Api.INSTANCE.definitions().items().dummyFluidItem().maybeStack( 1 ).isPresent() )
{
return;
}
@Override
public void setStackInSlot(int slot, @Nonnull ItemStack stack) {
if (stack.isEmpty() || stack.getItem() instanceof FluidDummyItem) {
super.setStackInSlot(slot, stack);
}
FluidStack fluid = FluidUtil.getFluidContained(stack);
if (fluid == null || !Api.INSTANCE.definitions().items().dummyFluidItem().maybeStack(1).isPresent()) {
return;
}
fluid.amount = Fluid.BUCKET_VOLUME;
ItemStack is = Api.INSTANCE.definitions().items().dummyFluidItem().maybeStack( 1 ).get();
FluidDummyItem item = (FluidDummyItem) is.getItem();
item.setFluidStack( is, fluid );
super.setStackInSlot( slot, is );
}
fluid.amount = Fluid.BUCKET_VOLUME;
ItemStack is = Api.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 );
}
FluidStack fluid = FluidUtil.getFluidContained( stack );
if( fluid == null || !Api.INSTANCE.definitions().items().dummyFluidItem().maybeStack( 1 ).isPresent() )
{
return false;
}
fluid.amount = Fluid.BUCKET_VOLUME;
ItemStack is = Api.INSTANCE.definitions().items().dummyFluidItem().maybeStack( 1 ).get();
FluidDummyItem item = (FluidDummyItem) is.getItem();
item.setFluidStack( is, fluid );
return super.isItemValid( slot, is );
}
@Override
public boolean isItemValid(int slot, ItemStack stack) {
if (stack.isEmpty() || stack.getItem() instanceof FluidDummyItem) {
super.isItemValid(slot, stack);
}
FluidStack fluid = FluidUtil.getFluidContained(stack);
if (fluid == null || !Api.INSTANCE.definitions().items().dummyFluidItem().maybeStack(1).isPresent()) {
return false;
}
fluid.amount = Fluid.BUCKET_VOLUME;
ItemStack is = Api.INSTANCE.definitions().items().dummyFluidItem().maybeStack(1).get();
FluidDummyItem item = (FluidDummyItem) is.getItem();
item.setFluidStack(is, fluid);
return super.isItemValid(slot, is);
}
}
@@ -1,98 +1,79 @@
package appeng.fluids.helper;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.inventory.IContainerListener;
import appeng.api.storage.data.IAEFluidStack;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.PacketFluidSlot;
import appeng.fluids.util.AEFluidInventory;
import appeng.fluids.util.IAEFluidTank;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.inventory.IContainerListener;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
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 EntityPlayerMP )
{
NetworkHandler.instance().sendTo( new PacketFluidSlot( data ), (EntityPlayerMP) l );
}
}
}
for (final IContainerListener l : listeners) {
if (l instanceof EntityPlayerMP) {
NetworkHandler.instance().sendTo(new PacketFluidSlot(data), (EntityPlayerMP) 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();
}
}
@@ -2,10 +2,8 @@ package appeng.fluids.helper;
import net.minecraftforge.fluids.capability.IFluidHandler;
public interface IConfigurableFluidInventory
{
default IFluidHandler getFluidInventoryByName( String name )
{
public interface IConfigurableFluidInventory {
default IFluidHandler getFluidInventoryByName(String name) {
return null;
}
}
@@ -19,23 +19,21 @@
package appeng.fluids.helper;
import java.util.EnumSet;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import appeng.api.implementations.IUpgradeableHost;
import appeng.api.networking.security.IActionHost;
import appeng.me.helpers.IGridProxyable;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import java.util.EnumSet;
public interface IFluidInterfaceHost extends IActionHost, IGridProxyable, IUpgradeableHost
{
DualityFluidInterface getDualityFluidInterface();
public interface IFluidInterfaceHost extends IActionHost, IGridProxyable, IUpgradeableHost {
DualityFluidInterface getDualityFluidInterface();
EnumSet<EnumFacing> getTargets();
EnumSet<EnumFacing> getTargets();
TileEntity getTileEntity();
TileEntity getTileEntity();
void saveChanges();
void saveChanges();
}
@@ -19,10 +19,6 @@
package appeng.fluids.items;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraftforge.items.IItemHandler;
import appeng.api.AEApi;
import appeng.api.storage.IStorageChannel;
import appeng.api.storage.channels.IFluidStorageChannel;
@@ -31,6 +27,9 @@ import appeng.fluids.helper.FluidCellConfig;
import appeng.items.materials.MaterialType;
import appeng.items.storage.AbstractStorageCell;
import appeng.util.InventoryAdaptor;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraftforge.items.IItemHandler;
/**
@@ -38,80 +37,70 @@ import appeng.util.InventoryAdaptor;
* @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( final MaterialType whichCell, final int kilobytes )
{
super( whichCell, kilobytes );
switch( whichCell )
{
case FLUID_CELL1K_PART:
this.idleDrain = 0.5;
this.perType = 8;
break;
case FLUID_CELL4K_PART:
this.idleDrain = 1.0;
this.perType = 32;
break;
case FLUID_CELL16K_PART:
this.idleDrain = 1.5;
this.perType = 128;
break;
case FLUID_CELL64K_PART:
this.idleDrain = 2.0;
this.perType = 512;
break;
default:
this.idleDrain = 0.0;
this.perType = 8;
}
public BasicFluidStorageCell(final MaterialType whichCell, final int kilobytes) {
super(whichCell, kilobytes);
switch (whichCell) {
case FLUID_CELL1K_PART:
this.idleDrain = 0.5;
this.perType = 8;
break;
case FLUID_CELL4K_PART:
this.idleDrain = 1.0;
this.perType = 32;
break;
case FLUID_CELL16K_PART:
this.idleDrain = 1.5;
this.perType = 128;
break;
case FLUID_CELL64K_PART:
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 EntityPlayer 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 EntityPlayer player) {
AEApi.instance().definitions().materials().emptyStorageCell().maybeStack(1).ifPresent(is ->
{
final ItemStack extraA = ia.addItems(is);
if (!extraA.isEmpty()) {
player.dropItem(extraA, false);
}
});
}
}
@@ -19,6 +19,7 @@
package appeng.fluids.items;
import appeng.items.AEBaseItem;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
@@ -27,8 +28,6 @@ import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import appeng.items.AEBaseItem;
/**
* Dummy item to display the fluid Icon
@@ -37,47 +36,37 @@ import appeng.items.AEBaseItem;
* @version rv6 - 2018-01-22
* @since rv6 2018-01-22
*/
public class FluidDummyItem extends AEBaseItem
{
@Override
public String getItemStackDisplayName( ItemStack stack )
{
public class FluidDummyItem extends AEBaseItem {
@Override
public String getItemStackDisplayName(ItemStack stack) {
FluidStack fluidStack = this.getFluidStack( stack );
if( fluidStack == null )
{
fluidStack = new FluidStack( FluidRegistry.WATER, Fluid.BUCKET_VOLUME );
}
return fluidStack.getLocalizedName();
}
FluidStack fluidStack = this.getFluidStack(stack);
if (fluidStack == null) {
fluidStack = new FluidStack(FluidRegistry.WATER, Fluid.BUCKET_VOLUME);
}
return fluidStack.getLocalizedName();
}
public FluidStack getFluidStack( ItemStack is )
{
if( is.hasTagCompound() )
{
NBTTagCompound tag = is.getTagCompound();
return FluidStack.loadFluidStackFromNBT( tag );
}
return null;
}
public FluidStack getFluidStack(ItemStack is) {
if (is.hasTagCompound()) {
NBTTagCompound tag = is.getTagCompound();
return FluidStack.loadFluidStackFromNBT(tag);
}
return null;
}
public void setFluidStack( ItemStack is, FluidStack fs )
{
if( fs == null )
{
is.setTagCompound( null );
}
else
{
NBTTagCompound tag = new NBTTagCompound();
fs.writeToNBT( tag );
is.setTagCompound( tag );
}
}
public void setFluidStack(ItemStack is, FluidStack fs) {
if (fs == null) {
is.setTagCompound(null);
} else {
NBTTagCompound tag = new NBTTagCompound();
fs.writeToNBT(tag);
is.setTagCompound(tag);
}
}
@Override
protected void getCheckedSubItems( final CreativeTabs creativeTab, final NonNullList<ItemStack> itemStacks )
{
// Don't show this item in CreativeTabs
}
@Override
protected void getCheckedSubItems(final CreativeTabs creativeTab, final NonNullList<ItemStack> itemStacks) {
// Don't show this item in CreativeTabs
}
}
@@ -29,11 +29,9 @@ import appeng.client.render.DummyFluidItemModel;
* @version rv6 - 2018-01-22
* @since rv6 2018-01-22
*/
public class FluidDummyItemRendering extends ItemRenderingCustomizer
{
@Override
public void customize( IItemRendering rendering )
{
rendering.builtInModel( "models/item/dummy_fluid_item", new DummyFluidItemModel() );
}
public class FluidDummyItemRendering extends ItemRenderingCustomizer {
@Override
public void customize(IItemRendering rendering) {
rendering.builtInModel("models/item/dummy_fluid_item", new DummyFluidItemModel());
}
}
@@ -19,21 +19,11 @@
package appeng.fluids.parts;
import java.util.*;
import appeng.api.AEApi;
import appeng.api.config.AccessRestriction;
import appeng.api.config.Actionable;
import appeng.api.config.Settings;
import appeng.api.config.StorageFilter;
import appeng.api.storage.data.IAEItemStack;
import appeng.me.GridAccessException;
import appeng.util.inv.ItemSlot;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.capability.IFluidHandler;
import net.minecraftforge.fluids.capability.IFluidTankProperties;
import appeng.api.AEApi;
import appeng.api.config.Actionable;
import appeng.api.networking.security.IActionSource;
import appeng.api.networking.storage.IBaseMonitor;
import appeng.api.networking.ticking.TickRateModulation;
@@ -44,8 +34,14 @@ import appeng.api.storage.channels.IFluidStorageChannel;
import appeng.api.storage.data.IAEFluidStack;
import appeng.api.storage.data.IItemList;
import appeng.fluids.util.AEFluidStack;
import appeng.me.GridAccessException;
import appeng.me.helpers.IGridProxyable;
import appeng.me.storage.ITickingMonitor;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.capability.IFluidHandler;
import net.minecraftforge.fluids.capability.IFluidTankProperties;
import java.util.*;
/**
@@ -55,218 +51,178 @@ import appeng.me.storage.ITickingMonitor;
* @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;
private StorageFilter mode;
private AccessRestriction access;
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;
private StorageFilter mode;
private AccessRestriction access;
FluidHandlerAdapter( IFluidHandler fluidHandler, IGridProxyable proxy )
{
this.fluidHandler = fluidHandler;
this.proxyable = proxy;
if( this.proxyable instanceof PartFluidStorageBus )
{
PartFluidStorageBus partFluidStorageBus = (PartFluidStorageBus) this.proxyable;
this.mode = ( (StorageFilter) partFluidStorageBus.getConfigManager().getSetting( Settings.STORAGE_FILTER ) );
this.access = ( (AccessRestriction) partFluidStorageBus.getConfigManager().getSetting( Settings.ACCESS ) );
}
this.cache = new FluidHandlerAdapter.InventoryCache( this.fluidHandler, this.mode );
this.cache.update();
}
FluidHandlerAdapter(IFluidHandler fluidHandler, IGridProxyable proxy) {
this.fluidHandler = fluidHandler;
this.proxyable = proxy;
if (this.proxyable instanceof PartFluidStorageBus) {
PartFluidStorageBus partFluidStorageBus = (PartFluidStorageBus) this.proxyable;
this.mode = ((StorageFilter) partFluidStorageBus.getConfigManager().getSetting(Settings.STORAGE_FILTER));
this.access = ((AccessRestriction) partFluidStorageBus.getConfigManager().getSetting(Settings.ACCESS));
}
this.cache = new FluidHandlerAdapter.InventoryCache(this.fluidHandler, this.mode);
this.cache.update();
}
@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 != Actionable.SIMULATE );
int remaining = fluidStack.amount - wasFillled;
if( fluidStack.amount == remaining )
{
// The stack was unmodified, target tank is full
return input;
}
// Insert
int wasFillled = this.fluidHandler.fill(fluidStack, type != Actionable.SIMULATE);
int remaining = fluidStack.amount - wasFillled;
if (fluidStack.amount == remaining) {
// The stack was unmodified, target tank is full
return input;
}
if( type == Actionable.MODULATE )
{
IAEFluidStack added = input.copy().setStackSize( input.getStackSize() - remaining );
this.cache.currentlyCached.add( added );
this.postDifference( Collections.singletonList( added ) );
try
{
this.proxyable.getProxy().getTick().alertDevice( this.proxyable.getProxy().getNode() );
}
catch( GridAccessException ex )
{
// meh
}
}
if (type == Actionable.MODULATE) {
IAEFluidStack added = input.copy().setStackSize(input.getStackSize() - remaining);
this.cache.currentlyCached.add(added);
this.postDifference(Collections.singletonList(added));
try {
this.proxyable.getProxy().getTick().alertDevice(this.proxyable.getProxy().getNode());
} catch (GridAccessException ex) {
// meh
}
}
fluidStack.amount = remaining;
fluidStack.amount = remaining;
return AEFluidStack.fromFluidStack( fluidStack );
}
return AEFluidStack.fromFluidStack(fluidStack);
}
@Override
public IAEFluidStack extractItems( IAEFluidStack request, Actionable mode, IActionSource src )
{
FluidStack requestedFluidStack = request.getFluidStack();
final boolean doDrain = ( mode == Actionable.MODULATE );
@Override
public IAEFluidStack extractItems(IAEFluidStack request, Actionable mode, IActionSource src) {
FluidStack requestedFluidStack = request.getFluidStack();
final boolean doDrain = (mode == Actionable.MODULATE);
// Drain the fluid from the tank
FluidStack gathered = this.fluidHandler.drain( requestedFluidStack, doDrain );
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, doDrain);
if (gathered == null) {
// If nothing was pulled from the tank, return null
return null;
}
IAEFluidStack gatheredAEFluidstack = AEFluidStack.fromFluidStack( gathered );
if( mode == Actionable.MODULATE )
{
IAEFluidStack cachedStack = this.cache.currentlyCached.findPrecise( request );
if( cachedStack != null )
{
cachedStack.decStackSize( gatheredAEFluidstack.getStackSize() );
this.postDifference( Collections.singletonList( gatheredAEFluidstack.copy().setStackSize( -gatheredAEFluidstack.getStackSize() ) ) );
}
try
{
this.proxyable.getProxy().getTick().alertDevice( this.proxyable.getProxy().getNode() );
}
catch( GridAccessException ex )
{
// meh
}
}
return gatheredAEFluidstack;
}
IAEFluidStack gatheredAEFluidstack = AEFluidStack.fromFluidStack(gathered);
if (mode == Actionable.MODULATE) {
IAEFluidStack cachedStack = this.cache.currentlyCached.findPrecise(request);
if (cachedStack != null) {
cachedStack.decStackSize(gatheredAEFluidstack.getStackSize());
this.postDifference(Collections.singletonList(gatheredAEFluidstack.copy().setStackSize(-gatheredAEFluidstack.getStackSize())));
}
try {
this.proxyable.getProxy().getTick().alertDevice(this.proxyable.getProxy().getNode());
} catch (GridAccessException ex) {
// meh
}
}
return gatheredAEFluidstack;
}
@Override
public TickRateModulation onTick()
{
List<IAEFluidStack> changes = this.cache.update();
if( !changes.isEmpty() && access.hasPermission( AccessRestriction.READ ) )
{
this.postDifference( changes );
return TickRateModulation.URGENT;
}
else
{
return TickRateModulation.SLOWER;
}
}
@Override
public TickRateModulation onTick() {
List<IAEFluidStack> changes = this.cache.update();
if (!changes.isEmpty() && access.hasPermission(AccessRestriction.READ)) {
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 final IFluidHandler fluidHandler;
private final StorageFilter mode;
IItemList<IAEFluidStack> currentlyCached = AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ).createList();
private static class InventoryCache {
private final IFluidHandler fluidHandler;
private final StorageFilter mode;
IItemList<IAEFluidStack> currentlyCached = AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class).createList();
public InventoryCache( IFluidHandler fluidHandler, StorageFilter mode )
{
this.mode = mode;
this.fluidHandler = fluidHandler;
}
public InventoryCache(IFluidHandler fluidHandler, StorageFilter mode) {
this.mode = mode;
this.fluidHandler = fluidHandler;
}
public List<IAEFluidStack> update()
{
final List<IAEFluidStack> changes = new ArrayList<>();
final IFluidTankProperties[] tankProperties = this.fluidHandler.getTankProperties();
public List<IAEFluidStack> update() {
final List<IAEFluidStack> changes = new ArrayList<>();
final IFluidTankProperties[] tankProperties = this.fluidHandler.getTankProperties();
IItemList<IAEFluidStack> currentlyOnStorage = AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ).createList();
IItemList<IAEFluidStack> currentlyOnStorage = AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class).createList();
for( IFluidTankProperties tankProperty : tankProperties )
{
if( this.mode == StorageFilter.EXTRACTABLE_ONLY && this.fluidHandler.drain( 1, false ) == null )
{
continue;
}
currentlyOnStorage.add( AEFluidStack.fromFluidStack( tankProperty.getContents() ) );
}
for (IFluidTankProperties tankProperty : tankProperties) {
if (this.mode == StorageFilter.EXTRACTABLE_ONLY && this.fluidHandler.drain(1, false) == null) {
continue;
}
currentlyOnStorage.add(AEFluidStack.fromFluidStack(tankProperty.getContents()));
}
for ( final IAEFluidStack is : currentlyCached )
{
is.setStackSize( -is.getStackSize() );
}
for (final IAEFluidStack is : currentlyCached) {
is.setStackSize(-is.getStackSize());
}
for ( final IAEFluidStack is : currentlyOnStorage )
{
currentlyCached.add( is );
}
for (final IAEFluidStack is : currentlyOnStorage) {
currentlyCached.add(is);
}
for ( final IAEFluidStack is : currentlyCached )
{
if( is.getStackSize() != 0 )
{
changes.add( is );
}
}
for (final IAEFluidStack is : currentlyCached) {
if (is.getStackSize() != 0) {
changes.add(is);
}
}
currentlyCached = currentlyOnStorage;
currentlyCached = currentlyOnStorage;
return changes;
}
return changes;
}
public IItemList<IAEFluidStack> getAvailableItems( IItemList<IAEFluidStack> out )
{
currentlyCached.iterator().forEachRemaining( out::add );
return out;
}
public IItemList<IAEFluidStack> getAvailableItems(IItemList<IAEFluidStack> out) {
currentlyCached.iterator().forEachRemaining(out::add);
return out;
}
}
}
}
@@ -1,22 +1,6 @@
package appeng.fluids.parts;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.block.BlockLiquid;
import net.minecraft.block.state.IBlockState;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fluids.FluidUtil;
import net.minecraftforge.fluids.IFluidBlock;
import net.minecraftforge.fluids.capability.IFluidHandler;
import appeng.api.AEApi;
import appeng.api.config.Actionable;
import appeng.api.config.PowerMultiplier;
@@ -50,274 +34,245 @@ import appeng.parts.PartBasicState;
import appeng.parts.automation.PlaneConnections;
import appeng.parts.automation.PlaneModels;
import appeng.util.Platform;
import net.minecraft.block.Block;
import net.minecraft.block.BlockLiquid;
import net.minecraft.block.state.IBlockState;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fluids.FluidUtil;
import net.minecraftforge.fluids.IFluidBlock;
import net.minecraftforge.fluids.capability.IFluidHandler;
import java.util.List;
public class PartFluidAnnihilationPlane extends PartBasicState implements IGridTickable
{
private static final PlaneModels MODELS = new PlaneModels( "part/fluid_annihilation_plane_", "part/fluid_annihilation_plane_on_" );
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();
}
@PartModels
public static List<IPartModel> getModels() {
return MODELS.getModels();
}
private final IActionSource mySrc = new MachineSource( this );
private final IActionSource mySrc = new MachineSource(this);
public PartFluidAnnihilationPlane( final ItemStack is )
{
super( is );
}
public PartFluidAnnihilationPlane(final ItemStack is) {
super(is);
}
@Override
public void getBoxes( final IPartCollisionHelper bch )
{
int minX = 1;
int minY = 1;
int maxX = 15;
int maxY = 15;
@Override
public void getBoxes(final IPartCollisionHelper bch) {
int minX = 1;
int minY = 1;
int maxX = 15;
int maxY = 15;
final IPartHost host = this.getHost();
if( host != null )
{
final TileEntity te = host.getTile();
final IPartHost host = this.getHost();
if (host != null) {
final TileEntity te = host.getTile();
final BlockPos pos = te.getPos();
final BlockPos pos = te.getPos();
final EnumFacing e = bch.getWorldX();
final EnumFacing u = bch.getWorldY();
final EnumFacing e = bch.getWorldX();
final EnumFacing u = bch.getWorldY();
if( this.isAnnihilationPlane( te.getWorld().getTileEntity( pos.offset( e.getOpposite() ) ), this.getSide() ) )
{
minX = 0;
}
if (this.isAnnihilationPlane(te.getWorld().getTileEntity(pos.offset(e.getOpposite())), this.getSide())) {
minX = 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())) {
maxX = 16;
}
if( this.isAnnihilationPlane( te.getWorld().getTileEntity( pos.offset( u.getOpposite() ) ), this.getSide() ) )
{
minY = 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() ) )
{
maxY = 16;
}
}
if (this.isAnnihilationPlane(te.getWorld().getTileEntity(pos.offset(e)), this.getSide())) {
maxY = 16;
}
}
bch.addBox( 5, 5, 14, 11, 11, 15 );
bch.addBox( minX, minY, 15, maxX, maxY, 16 );
}
bch.addBox(5, 5, 14, 11, 11, 15);
bch.addBox(minX, minY, 15, maxX, maxY, 16);
}
public PlaneConnections getConnections()
{
public PlaneConnections getConnections() {
final EnumFacing facingRight, facingUp;
AEPartLocation location = this.getSide();
switch( location )
{
case UP:
facingRight = EnumFacing.EAST;
facingUp = EnumFacing.NORTH;
break;
case DOWN:
facingRight = EnumFacing.WEST;
facingUp = EnumFacing.NORTH;
break;
case NORTH:
facingRight = EnumFacing.WEST;
facingUp = EnumFacing.UP;
break;
case SOUTH:
facingRight = EnumFacing.EAST;
facingUp = EnumFacing.UP;
break;
case WEST:
facingRight = EnumFacing.SOUTH;
facingUp = EnumFacing.UP;
break;
case EAST:
facingRight = EnumFacing.NORTH;
facingUp = EnumFacing.UP;
break;
default:
case INTERNAL:
return PlaneConnections.of( false, false, false, false );
}
final EnumFacing facingRight, facingUp;
AEPartLocation location = this.getSide();
switch (location) {
case UP:
facingRight = EnumFacing.EAST;
facingUp = EnumFacing.NORTH;
break;
case DOWN:
facingRight = EnumFacing.WEST;
facingUp = EnumFacing.NORTH;
break;
case NORTH:
facingRight = EnumFacing.WEST;
facingUp = EnumFacing.UP;
break;
case SOUTH:
facingRight = EnumFacing.EAST;
facingUp = EnumFacing.UP;
break;
case WEST:
facingRight = EnumFacing.SOUTH;
facingUp = EnumFacing.UP;
break;
case EAST:
facingRight = EnumFacing.NORTH;
facingUp = EnumFacing.UP;
break;
default:
case INTERNAL:
return PlaneConnections.of(false, false, false, false);
}
boolean left = false, right = false, down = false, up = false;
boolean left = false, right = false, down = false, up = false;
final IPartHost host = this.getHost();
if( host != null )
{
final TileEntity te = host.getTile();
final IPartHost host = this.getHost();
if (host != null) {
final TileEntity te = host.getTile();
final BlockPos pos = te.getPos();
final BlockPos pos = te.getPos();
if( this.isAnnihilationPlane( te.getWorld().getTileEntity( pos.offset( facingRight.getOpposite() ) ), this.getSide() ) )
{
left = true;
}
if (this.isAnnihilationPlane(te.getWorld().getTileEntity(pos.offset(facingRight.getOpposite())), this.getSide())) {
left = true;
}
if( this.isAnnihilationPlane( te.getWorld().getTileEntity( pos.offset( facingRight ) ), this.getSide() ) )
{
right = true;
}
if (this.isAnnihilationPlane(te.getWorld().getTileEntity(pos.offset(facingRight)), this.getSide())) {
right = true;
}
if( this.isAnnihilationPlane( te.getWorld().getTileEntity( pos.offset( facingUp.getOpposite() ) ), this.getSide() ) )
{
down = true;
}
if (this.isAnnihilationPlane(te.getWorld().getTileEntity(pos.offset(facingUp.getOpposite())), this.getSide())) {
down = true;
}
if( this.isAnnihilationPlane( te.getWorld().getTileEntity( pos.offset( facingUp ) ), this.getSide() ) )
{
up = true;
}
}
if (this.isAnnihilationPlane(te.getWorld().getTileEntity(pos.offset(facingUp)), this.getSide())) {
up = true;
}
}
return PlaneConnections.of( up, right, down, left );
}
return PlaneConnections.of(up, right, down, left);
}
@Override
public void onNeighborChanged( IBlockAccess w, BlockPos pos, BlockPos neighbor )
{
if( pos.offset( this.getSide().getFacing() ).equals( neighbor ) )
{
this.refresh();
}
}
@Override
public void onNeighborChanged(IBlockAccess w, BlockPos pos, BlockPos neighbor) {
if (pos.offset(this.getSide().getFacing()).equals(neighbor)) {
this.refresh();
}
}
@Override
public float getCableConnectionLength( AECableType cable )
{
return 1;
}
@Override
public float getCableConnectionLength(AECableType cable) {
return 1;
}
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;
}
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;
}
private void refresh()
{
try
{
this.getProxy().getTick().alertDevice( this.getProxy().getNode() );
}
catch( final GridAccessException e )
{
// :P
}
}
private void refresh() {
try {
this.getProxy().getTick().alertDevice(this.getProxy().getNode());
} catch (final GridAccessException e) {
// :P
}
}
@Override
@MENetworkEventSubscribe
public void chanRender( final MENetworkChannelsChanged c )
{
this.refresh();
this.getHost().markForUpdate();
}
@Override
@MENetworkEventSubscribe
public void chanRender(final MENetworkChannelsChanged c) {
this.refresh();
this.getHost().markForUpdate();
}
@Override
@MENetworkEventSubscribe
public void powerRender( final MENetworkPowerStatusChange c )
{
this.refresh();
this.getHost().markForUpdate();
}
@Override
@MENetworkEventSubscribe
public void powerRender(final MENetworkPowerStatusChange c) {
this.refresh();
this.getHost().markForUpdate();
}
private TickRateModulation pickupFluid()
{
if( !this.getProxy().isActive() )
{
return TickRateModulation.SLEEP;
}
private TickRateModulation pickupFluid() {
if (!this.getProxy().isActive()) {
return TickRateModulation.SLEEP;
}
final TileEntity te = this.getTile();
final World w = te.getWorld();
final BlockPos pos = te.getPos().offset( this.getSide().getFacing() );
final IBlockState state = w.getBlockState( pos );
final Block block = state.getBlock();
final TileEntity te = this.getTile();
final World w = te.getWorld();
final BlockPos pos = te.getPos().offset(this.getSide().getFacing());
final IBlockState state = w.getBlockState(pos);
final Block block = state.getBlock();
if( block instanceof IFluidBlock || block instanceof BlockLiquid )
{
final IFluidHandler fh = FluidUtil.getFluidHandler( w, pos, null );
final IAEFluidStack blockFluid = AEFluidStack.fromFluidStack( fh.drain( Integer.MAX_VALUE, false ) );
if (block instanceof IFluidBlock || block instanceof BlockLiquid) {
final IFluidHandler fh = FluidUtil.getFluidHandler(w, pos, null);
final IAEFluidStack blockFluid = AEFluidStack.fromFluidStack(fh.drain(Integer.MAX_VALUE, false));
if( blockFluid != null )
{
if( this.storeFluid( blockFluid, false ) )
{
this.storeFluid( AEFluidStack.fromFluidStack( fh.drain( Integer.MAX_VALUE, true ) ), true );
if (blockFluid != null) {
if (this.storeFluid(blockFluid, false)) {
this.storeFluid(AEFluidStack.fromFluidStack(fh.drain(Integer.MAX_VALUE, true)), true);
AppEng.proxy.sendToAllNearExcept( null, pos.getX(), pos.getY(), pos.getZ(), 64, w,
new PacketTransitionEffect( pos.getX(), pos.getY(), pos.getZ(), this.getSide(), true ) );
AppEng.proxy.sendToAllNearExcept(null, pos.getX(), pos.getY(), pos.getZ(), 64, w,
new PacketTransitionEffect(pos.getX(), pos.getY(), pos.getZ(), this.getSide(), true));
return TickRateModulation.URGENT;
}
return TickRateModulation.IDLE;
}
}
return TickRateModulation.URGENT;
}
return TickRateModulation.IDLE;
}
}
// nothing to do here :)
return TickRateModulation.SLEEP;
}
// nothing to do here :)
return TickRateModulation.SLEEP;
}
@Override
public TickingRequest getTickingRequest( final IGridNode node )
{
return new TickingRequest( TickRates.AnnihilationPlane.getMin(), TickRates.AnnihilationPlane.getMax(), false, true );
}
@Override
public TickingRequest getTickingRequest(final IGridNode node) {
return new TickingRequest(TickRates.AnnihilationPlane.getMin(), TickRates.AnnihilationPlane.getMax(), false, true);
}
@Override
public TickRateModulation tickingRequest( final IGridNode node, final int ticksSinceLastCall )
{
return this.pickupFluid();
}
@Override
public TickRateModulation tickingRequest(final IGridNode node, final int ticksSinceLastCall) {
return this.pickupFluid();
}
private boolean storeFluid( IAEFluidStack stack, boolean modulate )
{
try
{
final IStorageGrid storage = this.getProxy().getStorage();
final IMEInventory<IAEFluidStack> inv = storage.getInventory( AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ) );
private boolean storeFluid(IAEFluidStack stack, boolean modulate) {
try {
final IStorageGrid storage = this.getProxy().getStorage();
final IMEInventory<IAEFluidStack> inv = storage.getInventory(AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class));
if( modulate )
{
final IEnergyGrid energy = this.getProxy().getEnergy();
return Platform.poweredInsert( energy, inv, stack, this.mySrc ) == null;
}
else
{
final float requiredPower = stack.getStackSize() / Math.min( 1.0f, stack.getChannel().transferFactor() );
final IEnergyGrid energy = this.getProxy().getEnergy();
if (modulate) {
final IEnergyGrid energy = this.getProxy().getEnergy();
return Platform.poweredInsert(energy, inv, stack, this.mySrc) == null;
} else {
final float requiredPower = stack.getStackSize() / Math.min(1.0f, stack.getChannel().transferFactor());
final IEnergyGrid energy = this.getProxy().getEnergy();
if( energy.extractAEPower( requiredPower, Actionable.SIMULATE, PowerMultiplier.CONFIG ) < requiredPower )
{
return false;
}
final IAEFluidStack leftOver = inv.injectItems( stack, Actionable.SIMULATE, this.mySrc );
return leftOver == null || leftOver.getStackSize() == 0;
}
}
catch( final GridAccessException e )
{
// :P
}
return false;
}
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.getConnections(), this.isPowered(), this.isActive() );
}
@Override
public IPartModel getStaticModels() {
return MODELS.getModel(this.getConnections(), this.isPowered(), this.isActive());
}
}
@@ -19,20 +19,7 @@
package appeng.fluids.parts;
import javax.annotation.Nonnull;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
import net.minecraftforge.fluids.capability.IFluidHandler;
import appeng.api.config.Actionable;
import appeng.api.config.FuzzyMode;
import appeng.api.config.RedstoneMode;
import appeng.api.config.SchedulingMode;
import appeng.api.config.Settings;
import appeng.api.config.YesNo;
import appeng.api.config.*;
import appeng.api.networking.IGridNode;
import appeng.api.networking.security.IActionSource;
import appeng.api.networking.ticking.TickRateModulation;
@@ -47,6 +34,13 @@ import appeng.items.parts.PartModels;
import appeng.me.GridAccessException;
import appeng.me.helpers.MachineSource;
import appeng.parts.PartModel;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
import net.minecraftforge.fluids.capability.IFluidHandler;
import javax.annotation.Nonnull;
/**
@@ -54,133 +48,109 @@ import appeng.parts.PartModel;
* @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();
final TileEntity te = this.getConnectedTE();
if( te != null && te.hasCapability( CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, this.getSide().getFacing().getOpposite() ) )
{
try
{
final IFluidHandler fh = te.getCapability( CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, this.getSide().getFacing().getOpposite() );
final IMEMonitor<IAEFluidStack> inv = this.getProxy().getStorage().getInventory( this.getChannel() );
if (te != null && te.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, this.getSide().getFacing().getOpposite())) {
try {
final IFluidHandler fh = te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, this.getSide().getFacing().getOpposite());
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(), true );
if (out != null) {
int wasInserted = fh.fill(out.getFluidStack(), true);
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,29 +1,6 @@
package appeng.fluids.parts;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import appeng.fluids.helper.IConfigurableFluidInventory;
import net.minecraft.block.Block;
import net.minecraft.block.BlockLiquid;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTank;
import net.minecraftforge.fluids.FluidUtil;
import net.minecraftforge.fluids.IFluidBlock;
import appeng.api.AEApi;
import appeng.api.config.AccessRestriction;
import appeng.api.config.Actionable;
@@ -42,6 +19,7 @@ import appeng.api.storage.data.IAEFluidStack;
import appeng.api.storage.data.IItemList;
import appeng.api.util.AEPartLocation;
import appeng.core.sync.GuiBridge;
import appeng.fluids.helper.IConfigurableFluidInventory;
import appeng.fluids.util.AEFluidInventory;
import appeng.fluids.util.IAEFluidInventory;
import appeng.fluids.util.IAEFluidTank;
@@ -52,196 +30,182 @@ import appeng.parts.automation.PartAbstractFormationPlane;
import appeng.parts.automation.PlaneModels;
import appeng.util.Platform;
import appeng.util.prioritylist.PrecisePriorityList;
import net.minecraft.block.Block;
import net.minecraft.block.BlockLiquid;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.minecraftforge.fluids.*;
import net.minecraftforge.fluids.capability.IFluidHandler;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class PartFluidFormationPlane extends PartAbstractFormationPlane<IAEFluidStack> implements IAEFluidInventory, IConfigurableFluidInventory
{
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, IConfigurableFluidInventory {
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() < Fluid.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 IBlockState state = w.getBlockState( pos );
@Override
public IAEFluidStack injectItems(IAEFluidStack input, Actionable type, IActionSource src) {
if (this.blocked || input == null || input.getStackSize() < Fluid.BUCKET_VOLUME) {
// need a full bucket
return input;
}
if( this.canReplace( w, state, state.getBlock(), pos ) )
{
if( type == Actionable.MODULATE )
{
final FluidStack fs = input.getFluidStack();
fs.amount = Fluid.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 IBlockState state = w.getBlockState(pos);
final FluidTank tank = new FluidTank( fs, Fluid.BUCKET_VOLUME );
if( !FluidUtil.tryPlaceFluid( null, w, pos, tank, fs ) )
{
return input;
}
}
final IAEFluidStack ret = input.copy();
ret.setStackSize( input.getStackSize() - Fluid.BUCKET_VOLUME );
return ret.getStackSize() == 0 ? null : ret;
}
this.blocked = true;
return input;
}
if (this.canReplace(w, state, state.getBlock(), pos)) {
if (type == Actionable.MODULATE) {
final FluidStack fs = input.getFluidStack();
fs.amount = Fluid.BUCKET_VOLUME;
private boolean canReplace( World w, IBlockState state, Block block, BlockPos pos )
{
return block.isReplaceable( w, pos ) && !( block instanceof IFluidBlock ) && !( block instanceof BlockLiquid ) && !state.getMaterial().isLiquid();
}
final FluidTank tank = new FluidTank(fs, Fluid.BUCKET_VOLUME);
if (!FluidUtil.tryPlaceFluid(null, w, pos, tank, fs)) {
return input;
}
}
final IAEFluidStack ret = input.copy();
ret.setStackSize(input.getStackSize() - Fluid.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, IBlockState state, Block block, BlockPos pos) {
return block.isReplaceable(w, pos) && !(block instanceof IFluidBlock) && !(block instanceof BlockLiquid) && !state.getMaterial().isLiquid();
}
@Override
public void readFromNBT( final NBTTagCompound 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 NBTTagCompound data )
{
super.writeToNBT( data );
this.config.writeToNBT( data, "config" );
}
@Override
public void readFromNBT(final NBTTagCompound 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 NBTTagCompound data) {
super.writeToNBT(data);
this.config.writeToNBT(data, "config");
}
@Override
@MENetworkEventSubscribe
public void chanRender( final MENetworkChannelsChanged changedChannels )
{
this.stateChanged();
}
@Override
@MENetworkEventSubscribe
public void powerRender(final MENetworkPowerStatusChange c) {
this.stateChanged();
}
@Override
public boolean onPartActivate( final EntityPlayer player, final EnumHand hand, final Vec3d pos )
{
if( Platform.isServer() )
{
Platform.openGUI( player, this.getHost().getTile(), this.getSide(), GuiBridge.GUI_FLUID_FORMATION_PLANE );
}
@Override
@MENetworkEventSubscribe
public void chanRender(final MENetworkChannelsChanged changedChannels) {
this.stateChanged();
}
return true;
}
@Override
public boolean onPartActivate(final EntityPlayer player, final EnumHand hand, final Vec3d pos) {
if (Platform.isServer()) {
Platform.openGUI(player, this.getHost().getTile(), this.getSide(), GuiBridge.GUI_FLUID_FORMATION_PLANE);
}
@Override
public IStorageChannel<IAEFluidStack> getChannel()
{
return AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class );
}
return true;
}
@Override
public List<IMEInventoryHandler> getCellArray( final IStorageChannel channel )
{
if( 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.getConnections(), this.isPowered(), this.isActive() );
}
@Override
public List<IMEInventoryHandler> getCellArray(final IStorageChannel channel) {
if (channel == AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class)) {
final List<IMEInventoryHandler> handler = new ArrayList<>(1);
handler.add(this.myHandler);
return handler;
}
return Collections.emptyList();
}
public IAEFluidTank getConfig()
{
return this.config;
}
@Override
public IPartModel getStaticModels() {
return MODELS.getModel(this.getConnections(), this.isPowered(), this.isActive());
}
@Override
public IFluidHandler getFluidInventoryByName( final String name) {
if (name.equals("config")) {
return this.config;
}
return null;
}
public IAEFluidTank getConfig() {
return this.config;
}
@Override
public ItemStack getItemStackRepresentation()
{
return AEApi.instance().definitions().parts().fluidFormationnPlane().maybeStack( 1 ).orElse( ItemStack.EMPTY );
}
@Override
public IFluidHandler getFluidInventoryByName(final String name) {
if (name.equals("config")) {
return this.config;
}
return null;
}
@Override
public GuiBridge getGuiBridge()
{
return GuiBridge.GUI_FLUID_FORMATION_PLANE;
}
@Override
public ItemStack getItemStackRepresentation() {
return AEApi.instance().definitions().parts().fluidFormationnPlane().maybeStack(1).orElse(ItemStack.EMPTY);
}
@Override
public GuiBridge getGuiBridge() {
return GuiBridge.GUI_FLUID_FORMATION_PLANE;
}
}
@@ -19,21 +19,7 @@
package appeng.fluids.parts;
import javax.annotation.Nonnull;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
import net.minecraftforge.fluids.capability.IFluidHandler;
import appeng.api.config.Actionable;
import appeng.api.config.FuzzyMode;
import appeng.api.config.RedstoneMode;
import appeng.api.config.SchedulingMode;
import appeng.api.config.Settings;
import appeng.api.config.YesNo;
import appeng.api.config.*;
import appeng.api.networking.IGridNode;
import appeng.api.networking.security.IActionSource;
import appeng.api.networking.ticking.TickRateModulation;
@@ -48,6 +34,14 @@ import appeng.items.parts.PartModels;
import appeng.me.GridAccessException;
import appeng.me.helpers.MachineSource;
import appeng.parts.PartModel;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
import net.minecraftforge.fluids.capability.IFluidHandler;
import javax.annotation.Nonnull;
/**
@@ -55,147 +49,119 @@ import appeng.parts.PartModel;
* @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();
final TileEntity te = this.getConnectedTE();
if( te != null && te.hasCapability( CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, this.getSide().getFacing().getOpposite() ) )
{
try
{
final IFluidHandler fh = te.getCapability( CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, this.getSide().getFacing().getOpposite() );
final IMEMonitor<IAEFluidStack> inv = this.getProxy().getStorage().getInventory( this.getChannel() );
if (te != null && te.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, this.getSide().getFacing().getOpposite())) {
try {
final IFluidHandler fh = te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, this.getSide().getFacing().getOpposite());
final IMEMonitor<IAEFluidStack> inv = this.getProxy().getStorage().getInventory(this.getChannel());
if( fh != null )
{
final FluidStack fluidStack = fh.drain( this.calculateAmountToSend(), false );
if (fh != null) {
final FluidStack fluidStack = fh.drain(this.calculateAmountToSend(), false);
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(), true );
fh.drain(aeFluidStack.getFluidStack(), true);
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;
}
}
}
@@ -19,21 +19,6 @@
package appeng.fluids.parts;
import java.util.EnumSet;
import appeng.fluids.helper.IConfigurableFluidInventory;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.Vec3d;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.fluids.capability.IFluidHandler;
import net.minecraftforge.items.IItemHandler;
import appeng.api.AEApi;
import appeng.api.config.Upgrades;
import appeng.api.networking.IGridNode;
@@ -54,6 +39,7 @@ import appeng.api.util.IConfigManager;
import appeng.core.AppEng;
import appeng.core.sync.GuiBridge;
import appeng.fluids.helper.DualityFluidInterface;
import appeng.fluids.helper.IConfigurableFluidInventory;
import appeng.fluids.helper.IFluidInterfaceHost;
import appeng.helpers.IPriorityHost;
import appeng.helpers.Reflected;
@@ -61,196 +47,177 @@ import appeng.items.parts.PartModels;
import appeng.parts.PartBasicState;
import appeng.parts.PartModel;
import appeng.util.Platform;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.Vec3d;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.fluids.capability.IFluidHandler;
import net.minecraftforge.items.IItemHandler;
import java.util.EnumSet;
public class PartFluidInterface extends PartBasicState implements IGridTickable, IStorageMonitorable, IFluidInterfaceHost, IPriorityHost, IConfigurableFluidInventory
{
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, IConfigurableFluidInventory {
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;
}
@Override
@MENetworkEventSubscribe
public void chanRender( final MENetworkChannelsChanged c )
{
this.duality.notifyNeighbors();
}
@Override
@MENetworkEventSubscribe
public void chanRender(final MENetworkChannelsChanged c) {
this.duality.notifyNeighbors();
}
@Override
@MENetworkEventSubscribe
public void powerRender( final MENetworkPowerStatusChange c )
{
this.duality.notifyNeighbors();
}
@Override
@MENetworkEventSubscribe
public void powerRender(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 NBTTagCompound data )
{
super.readFromNBT( data );
this.duality.readFromNBT( data );
}
@Override
public void readFromNBT(final NBTTagCompound data) {
super.readFromNBT(data);
this.duality.readFromNBT(data);
}
@Override
public void writeToNBT( final NBTTagCompound data )
{
super.writeToNBT( data );
this.duality.writeToNBT( data );
}
@Override
public void writeToNBT(final NBTTagCompound 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 EntityPlayer p, final EnumHand hand, final Vec3d pos )
{
if( Platform.isServer() )
{
Platform.openGUI( p, this.getTileEntity(), this.getSide(), GuiBridge.GUI_FLUID_INTERFACE );
}
@Override
public boolean onPartActivate(final EntityPlayer p, final EnumHand hand, final Vec3d pos) {
if (Platform.isServer()) {
Platform.openGUI(p, this.getTileEntity(), this.getSide(), GuiBridge.GUI_FLUID_INTERFACE);
}
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<EnumFacing> getTargets()
{
return EnumSet.of( this.getSide().getFacing() );
}
@Override
public EnumSet<EnumFacing> 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 boolean hasCapability( Capability<?> capabilityClass )
{
return this.duality.hasCapability( capabilityClass, this.getSide().getFacing() );
}
@Override
public boolean hasCapability(Capability<?> capabilityClass) {
return this.duality.hasCapability(capabilityClass, this.getSide().getFacing());
}
@Override
public <T> T getCapability( Capability<T> capabilityClass )
{
return this.duality.getCapability( capabilityClass, this.getSide().getFacing() );
}
@Override
public <T> 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 IFluidHandler getFluidInventoryByName( final String name) {
return this.duality.getFluidInventoryByName(name);
}
@Override
public IFluidHandler getFluidInventoryByName(final String name) {
return this.duality.getFluidInventoryByName(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 GuiBridge getGuiBridge()
{
return GuiBridge.GUI_FLUID_INTERFACE;
}
@Override
public GuiBridge getGuiBridge() {
return GuiBridge.GUI_FLUID_INTERFACE;
}
}
@@ -1,23 +1,6 @@
package appeng.fluids.parts;
import java.util.Random;
import appeng.api.storage.data.IItemList;
import appeng.fluids.helper.IConfigurableFluidInventory;
import appeng.me.cache.NetworkMonitor;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumHand;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import appeng.api.AEApi;
import appeng.api.config.RedstoneMode;
import appeng.api.config.Settings;
@@ -36,362 +19,314 @@ import appeng.api.storage.IStorageChannel;
import appeng.api.storage.channels.IFluidStorageChannel;
import appeng.api.storage.data.IAEFluidStack;
import appeng.api.storage.data.IAEStack;
import appeng.api.storage.data.IItemList;
import appeng.api.util.AECableType;
import appeng.api.util.AEPartLocation;
import appeng.api.util.IConfigManager;
import appeng.core.AppEng;
import appeng.core.sync.GuiBridge;
import appeng.fluids.helper.IConfigurableFluidInventory;
import appeng.fluids.util.AEFluidInventory;
import appeng.fluids.util.IAEFluidInventory;
import appeng.fluids.util.IAEFluidTank;
import appeng.items.parts.PartModels;
import appeng.me.GridAccessException;
import appeng.me.cache.NetworkMonitor;
import appeng.parts.PartModel;
import appeng.parts.automation.PartUpgradeable;
import appeng.util.IConfigManagerHost;
import appeng.util.Platform;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumHand;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.minecraftforge.fluids.capability.IFluidHandler;
import java.util.Random;
public class PartFluidLevelEmitter extends PartUpgradeable implements IStackWatcherHost, IConfigManagerHost, IAEFluidInventory, IMEMonitorHandlerReceiver<IAEFluidStack>, IConfigurableFluidInventory
{
@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 class PartFluidLevelEmitter extends PartUpgradeable implements IStackWatcherHost, IConfigManagerHost, IAEFluidInventory, IMEMonitorHandlerReceiver<IAEFluidStack>, IConfigurableFluidInventory {
@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");
private static final int FLAG_ON = 4;
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 boolean prevState = false;
private long lastReportedValue = 0;
private long reportingValue = 0;
private IStackWatcher stackWatcher = null;
private final AEFluidInventory config = new AEFluidInventory( this, 1 );
private static final int FLAG_ON = 4;
public PartFluidLevelEmitter( ItemStack is )
{
super( is );
private boolean prevState = false;
private long lastReportedValue = 0;
private long reportingValue = 0;
private IStackWatcher stackWatcher = null;
private final AEFluidInventory config = new AEFluidInventory(this, 1);
this.getConfigManager().registerSetting( Settings.REDSTONE_EMITTER, RedstoneMode.HIGH_SIGNAL );
}
public PartFluidLevelEmitter(ItemStack is) {
super(is);
public long getReportingValue()
{
return this.reportingValue;
}
this.getConfigManager().registerSetting(Settings.REDSTONE_EMITTER, RedstoneMode.HIGH_SIGNAL);
}
public void setReportingValue( final long v )
{
this.reportingValue = v;
this.updateState();
}
public long getReportingValue() {
return this.reportingValue;
}
@Override
public void updateSetting( IConfigManager manager, Enum settingName, Enum newValue )
{
this.configureWatchers();
}
public void setReportingValue(final long v) {
this.reportingValue = v;
this.updateState();
}
@Override
public void updateWatcher( IStackWatcher newWatcher )
{
this.stackWatcher = newWatcher;
this.configureWatchers();
}
@Override
public void updateSetting(IConfigManager manager, Enum settingName, Enum newValue) {
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 updateWatcher(IStackWatcher newWatcher) {
this.stackWatcher = newWatcher;
this.configureWatchers();
}
@Override
public void onFluidInventoryChanged( IAEFluidTank inv, int slot )
{
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
@MENetworkEventSubscribe
public void powerRender( final MENetworkPowerStatusChange powerEvent )
{
if (this.getProxy().isActive())
{
onListUpdate();
}
this.updateState();
}
@Override
public void onFluidInventoryChanged(IAEFluidTank inv, int slot) {
this.configureWatchers();
}
@Override
@MENetworkEventSubscribe
public void chanRender( final MENetworkChannelsChanged c )
{
if (this.getProxy().isActive())
{
onListUpdate();
}
this.updateState();
}
@Override
@MENetworkEventSubscribe
public void powerRender(final MENetworkPowerStatusChange powerEvent) {
if (this.getProxy().isActive()) {
onListUpdate();
}
this.updateState();
}
@Override
public int isProvidingStrongPower()
{
return this.prevState ? 15 : 0;
}
@Override
@MENetworkEventSubscribe
public void chanRender(final MENetworkChannelsChanged c) {
if (this.getProxy().isActive()) {
onListUpdate();
}
this.updateState();
}
@Override
public int isProvidingWeakPower()
{
return this.prevState ? 15 : 0;
}
@Override
public int isProvidingStrongPower() {
return this.prevState ? 15 : 0;
}
@Override
protected int populateFlags( final int cf )
{
return cf | ( this.prevState ? FLAG_ON : 0 );
}
@Override
public int isProvidingWeakPower() {
return this.prevState ? 15 : 0;
}
@Override
public boolean isValid( final Object effectiveGrid )
{
try
{
return this.getProxy().getGrid() == effectiveGrid;
}
catch( final GridAccessException e )
{
return false;
}
}
@Override
protected int populateFlags(final int cf) {
return cf | (this.prevState ? FLAG_ON : 0);
}
@Override
public void postChange( final IBaseMonitor<IAEFluidStack> monitor, final Iterable<IAEFluidStack> change, final IActionSource actionSource )
{
this.updateReportingValue( (IMEMonitor<IAEFluidStack>) monitor );
}
@Override
public boolean isValid(final Object effectiveGrid) {
try {
return this.getProxy().getGrid() == effectiveGrid;
} catch (final GridAccessException e) {
return false;
}
}
@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 postChange(final IBaseMonitor<IAEFluidStack> monitor, final Iterable<IAEFluidStack> change, final IActionSource actionSource) {
this.updateReportingValue((IMEMonitor<IAEFluidStack>) monitor);
}
this.updateReportingValue( inventory );
}
catch( final GridAccessException e )
{
// ;P
}
}
@Override
public void onListUpdate() {
try {
final IStorageChannel<IAEFluidStack> channel = AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class);
final IMEMonitor<IAEFluidStack> inventory = this.getProxy().getStorage().getInventory(channel);
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() ) );
}
}
this.updateReportingValue(inventory);
} catch (final GridAccessException e) {
// ;P
}
}
private void configureWatchers()
{
final IFluidStorageChannel channel = AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class );
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()));
}
}
if( this.stackWatcher != null )
{
this.stackWatcher.reset();
private void configureWatchers() {
final IFluidStorageChannel channel = AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class);
final IAEFluidStack myStack = this.config.getFluidInSlot( 0 );
if (this.stackWatcher != null) {
this.stackWatcher.reset();
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 IAEFluidStack myStack = this.config.getFluidInSlot(0);
final IMEMonitor<IAEFluidStack> inventory = this.getProxy().getStorage().getInventory( channel );
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());
}
this.updateReportingValue( inventory );
}
catch( GridAccessException e )
{
// NOP
}
}
}
final IMEMonitor<IAEFluidStack> inventory = this.getProxy().getStorage().getInventory(channel);
private void updateReportingValue( final IMEMonitor<IAEFluidStack> monitor )
{
final IAEFluidStack myStack = this.config.getFluidInSlot( 0 );
this.updateReportingValue(inventory);
} catch (GridAccessException e) {
// NOP
}
}
}
if( myStack == null )
{
if( monitor instanceof NetworkMonitor )
{
this.lastReportedValue = ( (NetworkMonitor<IAEFluidStack>) monitor ).getGridCurrentCount();
}
}
else
{
final IAEFluidStack r = monitor.getStorageList().findPrecise( myStack );
if( r == null )
{
this.lastReportedValue = 0;
}
else
{
this.lastReportedValue = r.getStackSize();
}
}
this.updateState();
}
private void updateReportingValue(final IMEMonitor<IAEFluidStack> monitor) {
final IAEFluidStack myStack = this.config.getFluidInSlot(0);
private boolean isLevelEmitterOn()
{
if( Platform.isClient() )
{
return ( this.getClientFlags() & FLAG_ON ) == FLAG_ON;
}
if (myStack == null) {
if (monitor instanceof NetworkMonitor) {
this.lastReportedValue = ((NetworkMonitor<IAEFluidStack>) monitor).getGridCurrentCount();
}
} else {
final IAEFluidStack r = monitor.getStorageList().findPrecise(myStack);
if (r == null) {
this.lastReportedValue = 0;
} else {
this.lastReportedValue = r.getStackSize();
}
}
this.updateState();
}
if( !this.getProxy().isActive() )
{
return false;
}
private boolean isLevelEmitterOn() {
if (Platform.isClient()) {
return (this.getClientFlags() & FLAG_ON) == FLAG_ON;
}
final boolean flipState = this.getConfigManager().getSetting( Settings.REDSTONE_EMITTER ) == RedstoneMode.LOW_SIGNAL;
return flipState ? this.reportingValue > this.lastReportedValue : this.reportingValue <= this.lastReportedValue;
}
if (!this.getProxy().isActive()) {
return false;
}
@Override
public AECableType getCableConnectionType( final AEPartLocation dir )
{
return AECableType.SMART;
}
final boolean flipState = this.getConfigManager().getSetting(Settings.REDSTONE_EMITTER) == RedstoneMode.LOW_SIGNAL;
return flipState == (this.reportingValue > this.lastReportedValue);
}
@Override
public float getCableConnectionLength( AECableType cable )
{
return 16;
}
@Override
public AECableType getCableConnectionType(final AEPartLocation dir) {
return AECableType.SMART;
}
@Override
public boolean canConnectRedstone()
{
return true;
}
@Override
public float getCableConnectionLength(AECableType cable) {
return 16;
}
@Override
public void getBoxes( final IPartCollisionHelper bch )
{
bch.addBox( 7, 7, 11, 9, 9, 16 );
}
@Override
public boolean canConnectRedstone() {
return true;
}
@Override
public void randomDisplayTick( final World world, final BlockPos pos, final Random r )
{
if( this.isLevelEmitterOn() )
{
final AEPartLocation d = this.getSide();
@Override
public void getBoxes(final IPartCollisionHelper bch) {
bch.addBox(7, 7, 11, 9, 9, 16);
}
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;
@Override
public void randomDisplayTick(final World world, final BlockPos pos, final Random r) {
if (this.isLevelEmitterOn()) {
final AEPartLocation d = this.getSide();
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,
new int[0] );
}
}
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;
@Override
public boolean onPartActivate( final EntityPlayer player, final EnumHand hand, final Vec3d pos )
{
if( Platform.isServer() )
{
Platform.openGUI( player, this.getHost().getTile(), this.getSide(), GuiBridge.GUI_FLUID_LEVEL_EMITTER );
}
return true;
}
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
);
}
}
@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 boolean onPartActivate(final EntityPlayer player, final EnumHand hand, final Vec3d pos) {
if (Platform.isServer()) {
Platform.openGUI(player, this.getHost().getTile(), this.getSide(), GuiBridge.GUI_FLUID_LEVEL_EMITTER);
}
return true;
}
public IAEFluidTank getConfig()
{
return this.config;
}
@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 IFluidHandler getFluidInventoryByName( final String name) {
if (name.equals("config")) {
return this.config;
}
return null;
}
public IAEFluidTank getConfig() {
return this.config;
}
@Override
public void readFromNBT( final NBTTagCompound 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 IFluidHandler getFluidInventoryByName(final String name) {
if (name.equals("config")) {
return this.config;
}
return null;
}
@Override
public void writeToNBT( final NBTTagCompound data )
{
super.writeToNBT( data );
data.setLong( "lastReportedValue", this.lastReportedValue );
data.setLong( "reportingValue", this.reportingValue );
data.setBoolean( "prevState", this.prevState );
this.config.writeToNBT( data, "config" );
}
@Override
public void readFromNBT(final NBTTagCompound 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 NBTTagCompound data) {
super.writeToNBT(data);
data.setLong("lastReportedValue", this.lastReportedValue);
data.setLong("reportingValue", this.reportingValue);
data.setBoolean("prevState", this.prevState);
this.config.writeToNBT(data, "config");
}
}
@@ -19,8 +19,6 @@
package appeng.fluids.parts;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import appeng.api.AEApi;
import appeng.api.config.*;
import appeng.api.networking.IGridNode;
@@ -80,6 +78,8 @@ import net.minecraft.world.IBlockAccess;
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
import net.minecraftforge.fluids.capability.IFluidHandler;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
@@ -90,18 +90,17 @@ import java.util.Objects;
* @version rv6 - 22/05/2018
* @since rv6 22/05/2018
*/
public class PartFluidStorageBus extends PartUpgradeable implements IGridTickable, ICellContainer, IMEMonitorHandlerReceiver<IAEFluidStack>, IAEFluidInventory, IConfigurableFluidInventory, IPriorityHost
{
public static final ResourceLocation MODEL_BASE = new ResourceLocation( AppEng.MOD_ID, "part/fluid_storage_bus_base" );
public class PartFluidStorageBus extends PartUpgradeable implements IGridTickable, ICellContainer, IMEMonitorHandlerReceiver<IAEFluidStack>, IAEFluidInventory, IConfigurableFluidInventory, IPriorityHost {
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" ) );
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" ) );
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 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 final AEFluidInventory config = new AEFluidInventory(this, 63);
private int priority = 0;
private boolean cached = false;
private ITickingMonitor monitor = null;
@@ -112,35 +111,28 @@ public class PartFluidStorageBus extends PartUpgradeable implements IGridTickabl
private boolean accessChanged;
private boolean readOncePass;
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);
}
@Override
@MENetworkEventSubscribe
public void powerRender( final MENetworkPowerStatusChange c )
{
public void powerRender(final MENetworkPowerStatusChange c) {
this.updateStatus();
}
protected void updateStatus()
{
protected void updateStatus() {
final boolean currentActive = this.getProxy().isActive();
if( this.wasActive != currentActive )
{
if (this.wasActive != currentActive) {
this.wasActive = currentActive;
try
{
this.getProxy().getGrid().postEvent( new MENetworkCellArrayUpdate() );
try {
this.getProxy().getGrid().postEvent(new MENetworkCellArrayUpdate());
this.getHost().markForUpdate();
}
catch( final GridAccessException e )
{
} catch (final GridAccessException e) {
// :P
}
}
@@ -148,277 +140,218 @@ public class PartFluidStorageBus extends PartUpgradeable implements IGridTickabl
@Override
@MENetworkEventSubscribe
public void chanRender( final MENetworkChannelsChanged changedChannels )
{
public void chanRender(final MENetworkChannelsChanged changedChannels) {
this.updateStatus();
}
@Override
protected int getUpgradeSlots()
{
protected int getUpgradeSlots() {
return 5;
}
@Override
public void updateSetting( final IConfigManager manager, final Enum settingName, final Enum newValue )
{
if( settingName.name().equals( "ACCESS" ) )
{
public void updateSetting(final IConfigManager manager, final Enum settingName, final Enum newValue) {
if (settingName.name().equals("ACCESS")) {
this.accessChanged = true;
}
this.resetCache( true );
this.resetCache(true);
this.getHost().markForSave();
}
@Override
public void onFluidInventoryChanged( IAEFluidTank inv, int slot )
{
if( inv == this.config )
{
this.resetCache( true );
public void onFluidInventoryChanged(IAEFluidTank inv, int slot) {
if (inv == this.config) {
this.resetCache(true);
}
}
@Override
public void upgradesChanged()
{
public void upgradesChanged() {
super.upgradesChanged();
this.resetCache( true );
this.resetCache(true);
}
@Override
public void readFromNBT( final NBTTagCompound data )
{
super.readFromNBT( data );
this.config.readFromNBT( data, "config" );
this.priority = data.getInteger( "priority" );
public void readFromNBT(final NBTTagCompound data) {
super.readFromNBT(data);
this.config.readFromNBT(data, "config");
this.priority = data.getInteger("priority");
this.accessChanged = false;
}
@Override
public void writeToNBT( final NBTTagCompound data )
{
super.writeToNBT( data );
this.config.writeToNBT( data, "config" );
data.setInteger( "priority", this.priority );
public void writeToNBT(final NBTTagCompound data) {
super.writeToNBT(data);
this.config.writeToNBT(data, "config");
data.setInteger("priority", this.priority);
}
@Override
public IFluidHandler getFluidInventoryByName( final String name )
{
if( name.equals( "config" ) )
{
public IFluidHandler getFluidInventoryByName(final String name) {
if (name.equals("config")) {
return this.config;
}
return null;
}
protected void resetCache( final boolean fullReset )
{
if( this.getHost() == null || this.getHost().getTile() == null || this.getHost().getTile().getWorld() == null || this.getHost().getTile().getWorld().isRemote )
{
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 )
{
if (fullReset) {
this.resetCacheLogic = 2;
}
else if( this.resetCacheLogic < 2 )
{
} else if (this.resetCacheLogic < 2) {
this.resetCacheLogic = 1;
}
try
{
this.getProxy().getTick().alertDevice( this.getProxy().getNode() );
}
catch( final GridAccessException e )
{
try {
this.getProxy().getTick().alertDevice(this.getProxy().getNode());
} catch (final GridAccessException e) {
// :P
}
}
@Override
public boolean isValid( final Object verificationToken )
{
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 )
{
if( this.getProxy().isActive() )
{
AccessRestriction currentAccess = (AccessRestriction) ( (ConfigManager) this.getConfigManager() ).getSetting( Settings.ACCESS );
if( readOncePass )
{
public void postChange(final IBaseMonitor<IAEFluidStack> monitor, final Iterable<IAEFluidStack> change, final IActionSource source) {
if (this.getProxy().isActive()) {
AccessRestriction currentAccess = (AccessRestriction) ((ConfigManager) this.getConfigManager()).getSetting(Settings.ACCESS);
if (readOncePass) {
readOncePass = false;
try
{
this.getProxy().getStorage().postAlterationOfStoredItems( AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ), change, this.source );
}
catch( final GridAccessException e )
{
try {
this.getProxy().getStorage().postAlterationOfStoredItems(AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class), change, this.source);
} catch (final GridAccessException e) {
// :(
}
return;
}
if( !currentAccess.hasPermission( AccessRestriction.READ ) )
{
if (!currentAccess.hasPermission(AccessRestriction.READ)) {
return;
}
try
{
this.getProxy().getStorage().postAlterationOfStoredItems( AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ), change, source );
}
catch( final GridAccessException e )
{
try {
this.getProxy().getStorage().postAlterationOfStoredItems(AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class), change, source);
} catch (final GridAccessException e) {
// :(
}
}
}
@Override
public void onListUpdate()
{
public void onListUpdate() {
// not used here.
}
@Override
public void getBoxes( final IPartCollisionHelper bch )
{
bch.addBox( 3, 3, 15, 13, 13, 16 );
bch.addBox( 2, 2, 14, 14, 14, 15 );
bch.addBox( 5, 5, 12, 11, 11, 14 );
public void getBoxes(final IPartCollisionHelper bch) {
bch.addBox(3, 3, 15, 13, 13, 16);
bch.addBox(2, 2, 14, 14, 14, 15);
bch.addBox(5, 5, 12, 11, 11, 14);
}
@Override
public void onNeighborChanged( IBlockAccess w, BlockPos pos, BlockPos neighbor )
{
if( pos.offset( this.getSide().getFacing() ).equals( neighbor ) )
{
public void onNeighborChanged(IBlockAccess w, BlockPos pos, BlockPos neighbor) {
if (pos.offset(this.getSide().getFacing()).equals(neighbor)) {
final TileEntity te = w.getTileEntity( neighbor );
final TileEntity te = w.getTileEntity(neighbor);
// In case the TE was destroyed, we have to do a full reset immediately.
if( te instanceof TileCableBus )
{
IPart iPart = ( (TileCableBus) te ).getPart( this.getSide().getOpposite() );
if( iPart == null || iPart instanceof PartFluidInterface )
{
this.resetCache( true );
if (te instanceof TileCableBus) {
IPart iPart = ((TileCableBus) te).getPart(this.getSide().getOpposite());
if (iPart == null || iPart instanceof PartFluidInterface) {
this.resetCache(true);
this.resetCache();
}
}
else if( te == null || te instanceof TileFluidInterface )
{
this.resetCache( true );
} else if (te == null || te instanceof TileFluidInterface) {
this.resetCache(true);
this.resetCache();
}
else
{
this.resetCache( false );
} else {
this.resetCache(false);
}
}
}
@Override
public float getCableConnectionLength( AECableType cable )
{
public float getCableConnectionLength(AECableType cable) {
return 4;
}
@Override
public boolean onPartActivate( final EntityPlayer player, final EnumHand hand, final Vec3d pos )
{
if( Platform.isServer() )
{
Platform.openGUI( player, this.getHost().getTile(), this.getSide(), GuiBridge.GUI_STORAGEBUS_FLUID );
public boolean onPartActivate(final EntityPlayer player, final EnumHand hand, final Vec3d pos) {
if (Platform.isServer()) {
Platform.openGUI(player, this.getHost().getTile(), this.getSide(), GuiBridge.GUI_STORAGEBUS_FLUID);
}
return true;
}
@Override
public TickingRequest getTickingRequest( IGridNode node )
{
return new TickingRequest( TickRates.FluidStorageBus.getMin(), TickRates.FluidStorageBus.getMax(), monitor == null, true );
public TickingRequest getTickingRequest(IGridNode node) {
return new TickingRequest(TickRates.FluidStorageBus.getMin(), TickRates.FluidStorageBus.getMax(), monitor == null, true);
}
@Override
public TickRateModulation tickingRequest( IGridNode node, int ticksSinceLastCall )
{
if( this.resetCacheLogic != 0 )
{
public TickRateModulation tickingRequest(IGridNode node, int ticksSinceLastCall) {
if (this.resetCacheLogic != 0) {
this.resetCache();
}
if( this.monitor != null )
{
if (this.monitor != null) {
return this.monitor.onTick();
}
return TickRateModulation.SLEEP;
}
protected void resetCache()
{
protected void resetCache() {
final boolean fullReset = this.resetCacheLogic == 2;
this.resetCacheLogic = 0;
final MEInventoryHandler<IAEFluidStack> in = this.getInternalHandler();
IItemList<IAEFluidStack> before = AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ).createList();
if( in != null )
{
if( accessChanged )
{
AccessRestriction currentAccess = (AccessRestriction) ( (ConfigManager) this.getConfigManager() ).getSetting( Settings.ACCESS );
AccessRestriction oldAccess = (AccessRestriction) ( (ConfigManager) this.getConfigManager() ).getOldSetting( Settings.ACCESS );
if( oldAccess.hasPermission( AccessRestriction.READ ) && !currentAccess.hasPermission( AccessRestriction.READ ) )
{
IItemList<IAEFluidStack> before = AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class).createList();
if (in != null) {
if (accessChanged) {
AccessRestriction currentAccess = (AccessRestriction) ((ConfigManager) this.getConfigManager()).getSetting(Settings.ACCESS);
AccessRestriction oldAccess = (AccessRestriction) ((ConfigManager) this.getConfigManager()).getOldSetting(Settings.ACCESS);
if (oldAccess.hasPermission(AccessRestriction.READ) && !currentAccess.hasPermission(AccessRestriction.READ)) {
readOncePass = true;
}
in.setBaseAccess( oldAccess );
before = in.getAvailableItems( before );
in.setBaseAccess( currentAccess );
in.setBaseAccess(oldAccess);
before = in.getAvailableItems(before);
in.setBaseAccess(currentAccess);
accessChanged = false;
}
else
{
before = in.getAvailableItems( before );
} else {
before = in.getAvailableItems(before);
}
}
this.cached = false;
if( fullReset )
{
if (fullReset) {
this.handlerHash = 0;
}
final MEInventoryHandler<IAEFluidStack> out = this.getInternalHandler();
IItemList<IAEFluidStack> after = AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ).createList();
IItemList<IAEFluidStack> after = AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class).createList();
if( in != out )
{
if( out != null )
{
after = out.getAvailableItems( after );
if (in != out) {
if (out != null) {
after = out.getAvailableItems(after);
}
Platform.postListChanges( before, after, this, this.source );
Platform.postListChanges(before, after, this, this.source);
}
}
private IMEInventory<IAEFluidStack> getInventoryWrapper( TileEntity target )
{
private IMEInventory<IAEFluidStack> getInventoryWrapper(TileEntity target) {
EnumFacing targetSide = this.getSide().getFacing().getOpposite();
// Prioritize a handler to directly link to another ME network
IStorageMonitorableAccessor accessor = target.getCapability( Capabilities.STORAGE_MONITORABLE_ACCESSOR, targetSide );
if( accessor != null )
{
IStorageMonitorable inventory = accessor.getInventory( this.source );
if( inventory != null )
{
return inventory.getInventory( AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ) );
IStorageMonitorableAccessor accessor = target.getCapability(Capabilities.STORAGE_MONITORABLE_ACCESSOR, targetSide);
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,
@@ -429,43 +362,36 @@ public class PartFluidStorageBus extends PartUpgradeable implements IGridTickabl
}
// Check via cap for IItemHandler
IFluidHandler handlerExt = target.getCapability( CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, targetSide );
if( handlerExt != null )
{
return new FluidHandlerAdapter( handlerExt, this );
IFluidHandler handlerExt = target.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, targetSide);
if (handlerExt != null) {
return new FluidHandlerAdapter(handlerExt, this);
}
return null;
}
private int createHandlerHash( TileEntity target )
{
if( target == null )
{
private int createHandlerHash(TileEntity target) {
if (target == null) {
return 0;
}
final EnumFacing targetSide = this.getSide().getFacing().getOpposite();
if( target.hasCapability( Capabilities.STORAGE_MONITORABLE_ACCESSOR, targetSide ) )
{
return Objects.hash( target, target.getCapability( Capabilities.STORAGE_MONITORABLE_ACCESSOR, targetSide ) );
if (target.hasCapability(Capabilities.STORAGE_MONITORABLE_ACCESSOR, targetSide)) {
return Objects.hash(target, target.getCapability(Capabilities.STORAGE_MONITORABLE_ACCESSOR, targetSide));
}
final IFluidHandler fluidHandler = target.getCapability( CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, targetSide );
final IFluidHandler fluidHandler = target.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, targetSide);
if( fluidHandler != null )
{
return Objects.hash( target, fluidHandler, fluidHandler.getTankProperties().length );
if (fluidHandler != null) {
return Objects.hash(target, fluidHandler, fluidHandler.getTankProperties().length);
}
return 0;
}
public MEInventoryHandler<IAEFluidStack> getInternalHandler()
{
if( this.cached )
{
public MEInventoryHandler<IAEFluidStack> getInternalHandler() {
if (this.cached) {
return this.handler;
}
@@ -473,98 +399,76 @@ public class PartFluidStorageBus extends PartUpgradeable implements IGridTickabl
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 );
final TileEntity target = self.getWorld().getTileEntity(self.getPos().offset(this.getSide().getFacing()));
final int newHandlerHash = this.createHandlerHash(target);
if( newHandlerHash != 0 && newHandlerHash == this.handlerHash )
{
if (newHandlerHash != 0 && newHandlerHash == this.handlerHash) {
return this.handler;
}
this.handlerHash = newHandlerHash;
this.handler = null;
if( this.monitor != null )
{
( (IBaseMonitor<IAEFluidStack>) monitor ).removeListener( this );
if (this.monitor != null) {
((IBaseMonitor<IAEFluidStack>) monitor).removeListener(this);
}
this.monitor = null;
if( target != null )
{
IMEInventory<IAEFluidStack> inv = this.getInventoryWrapper( target );
if( inv instanceof ITickingMonitor )
{
if (target != null) {
IMEInventory<IAEFluidStack> inv = this.getInventoryWrapper(target);
if (inv instanceof ITickingMonitor) {
this.monitor = (ITickingMonitor) inv;
this.monitor.setActionSource( this.source );
this.monitor.setMode( (StorageFilter) this.getConfigManager().getSetting( Settings.STORAGE_FILTER ) );
this.monitor.setActionSource(this.source);
this.monitor.setMode((StorageFilter) this.getConfigManager().getSetting(Settings.STORAGE_FILTER));
}
if( inv != null )
{
this.handler = new MEInventoryHandler<>( inv, AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ) );
if (inv != null) {
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 )
{
if( ( (AccessRestriction) ( (ConfigManager) this.getConfigManager() ).getSetting( Settings.ACCESS ) ).hasPermission( AccessRestriction.READ ) )
{
( (IBaseMonitor<IAEFluidStack>) inv ).addListener( this, this.handler );
if (inv instanceof IBaseMonitor) {
if (((AccessRestriction) ((ConfigManager) this.getConfigManager()).getSetting(Settings.ACCESS)).hasPermission(AccessRestriction.READ)) {
((IBaseMonitor<IAEFluidStack>) inv).addListener(this, this.handler);
}
}
}
}
// update sleep state...
if( wasSleeping != ( this.monitor == null ) )
{
try
{
if (wasSleeping != (this.monitor == null)) {
try {
final ITickManager tm = this.getProxy().getTick();
if( this.monitor == null )
{
tm.sleepDevice( this.getProxy().getNode() );
if (this.monitor == null) {
tm.sleepDevice(this.getProxy().getNode());
} else {
tm.wakeDevice(this.getProxy().getNode());
}
else
{
tm.wakeDevice( this.getProxy().getNode() );
}
}
catch( final GridAccessException ignore )
{
} catch (final GridAccessException ignore) {
// :(
}
}
try
{
try {
// force grid to update handlers...
( (GridStorageCache) this.getProxy().getGrid().getCache( IStorageGrid.class ) ).cellUpdate( null );
}
catch( final GridAccessException e )
{
((GridStorageCache) this.getProxy().getGrid().getCache(IStorageGrid.class)).cellUpdate(null);
} catch (final GridAccessException e) {
// :3
}
@@ -572,77 +476,61 @@ public class PartFluidStorageBus extends PartUpgradeable implements IGridTickabl
}
@Override
public List<IMEInventoryHandler> getCellArray( final IStorageChannel channel )
{
if( channel == AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ) )
{
public List<IMEInventoryHandler> getCellArray(final IStorageChannel channel) {
if (channel == AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class)) {
final IMEInventoryHandler<IAEFluidStack> out = this.getInternalHandler();
if( out != null )
{
return Collections.singletonList( out );
if (out != null) {
return Collections.singletonList(out);
}
}
return Collections.emptyList();
}
@Override
public int getPriority()
{
public int getPriority() {
return this.priority;
}
@Override
public void setPriority( int newValue )
{
public void setPriority(int newValue) {
this.priority = newValue;
this.getHost().markForSave();
this.resetCache( true );
this.resetCache(true);
}
@Override
public void blinkCell( int slot )
{
public void blinkCell(int slot) {
}
@Override
public void saveChanges( @Nullable ICellInventory<?> cellInventory )
{
public void saveChanges(@Nullable ICellInventory<?> cellInventory) {
}
public IAEFluidTank getConfig()
{
public IAEFluidTank getConfig() {
return this.config;
}
@Nonnull
@Override
public IPartModel getStaticModels()
{
if( this.isActive() && this.isPowered() )
{
public IPartModel getStaticModels() {
if (this.isActive() && this.isPowered()) {
return MODELS_HAS_CHANNEL;
}
else if( this.isPowered() )
{
} else if (this.isPowered()) {
return MODELS_ON;
}
else
{
} else {
return MODELS_OFF;
}
}
@Override
public ItemStack getItemStackRepresentation()
{
return AEApi.instance().definitions().parts().fluidStorageBus().maybeStack( 1 ).orElse( ItemStack.EMPTY );
public ItemStack getItemStackRepresentation() {
return AEApi.instance().definitions().parts().fluidStorageBus().maybeStack(1).orElse(ItemStack.EMPTY);
}
@Override
public GuiBridge getGuiBridge()
{
public GuiBridge getGuiBridge() {
return GuiBridge.GUI_STORAGEBUS_FLUID;
}
}
@@ -19,16 +19,15 @@
package appeng.fluids.parts;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import appeng.api.parts.IPartModel;
import appeng.core.AppEng;
import appeng.core.sync.GuiBridge;
import appeng.items.parts.PartModels;
import appeng.parts.PartModel;
import appeng.parts.reporting.AbstractPartTerminal;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
/**
@@ -36,32 +35,28 @@ import appeng.parts.reporting.AbstractPartTerminal;
* @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 GuiBridge getGui( EntityPlayer player )
{
return GuiBridge.GUI_FLUID_TERMINAL;
}
@Override
public GuiBridge getGui(EntityPlayer player) {
return GuiBridge.GUI_FLUID_TERMINAL;
}
@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);
}
}
@@ -19,7 +19,21 @@
package appeng.fluids.parts;
import appeng.api.AEApi;
import appeng.api.config.RedstoneMode;
import appeng.api.config.Upgrades;
import appeng.api.networking.ticking.IGridTickable;
import appeng.api.networking.ticking.TickRateModulation;
import appeng.api.parts.IPartCollisionHelper;
import appeng.api.storage.channels.IFluidStorageChannel;
import appeng.api.util.AECableType;
import appeng.core.sync.GuiBridge;
import appeng.fluids.helper.IConfigurableFluidInventory;
import appeng.fluids.util.AEFluidInventory;
import appeng.fluids.util.IAEFluidTank;
import appeng.me.GridAccessException;
import appeng.parts.automation.PartUpgradeable;
import appeng.util.Platform;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
@@ -30,21 +44,6 @@ import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import appeng.api.AEApi;
import appeng.api.config.RedstoneMode;
import appeng.api.config.Upgrades;
import appeng.api.networking.ticking.IGridTickable;
import appeng.api.networking.ticking.TickRateModulation;
import appeng.api.parts.IPartCollisionHelper;
import appeng.api.storage.channels.IFluidStorageChannel;
import appeng.api.util.AECableType;
import appeng.core.sync.GuiBridge;
import appeng.fluids.util.AEFluidInventory;
import appeng.fluids.util.IAEFluidTank;
import appeng.me.GridAccessException;
import appeng.parts.automation.PartUpgradeable;
import appeng.util.Platform;
import net.minecraftforge.fluids.capability.IFluidHandler;
@@ -53,151 +52,125 @@ import net.minecraftforge.fluids.capability.IFluidHandler;
* @version rv6 - 30/04/2018
* @since rv6 30/04/2018
*/
public abstract class PartSharedFluidBus extends PartUpgradeable implements IGridTickable, IConfigurableFluidInventory
{
public abstract class PartSharedFluidBus extends PartUpgradeable implements IGridTickable, IConfigurableFluidInventory {
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( IBlockAccess 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(IBlockAccess 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 EntityPlayer player, final EnumHand hand, final Vec3d pos )
{
if( Platform.isServer() )
{
Platform.openGUI( player, this.getHost().getTile(), this.getSide(), GuiBridge.GUI_BUS_FLUID );
}
@Override
public boolean onPartActivate(final EntityPlayer player, final EnumHand hand, final Vec3d pos) {
if (Platform.isServer()) {
Platform.openGUI(player, this.getHost().getTile(), this.getSide(), GuiBridge.GUI_BUS_FLUID);
}
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().getLoadedChunk( pos.getX() >> 4, pos.getZ() >> 4 ) != null )
{
return w.getTileEntity( pos );
}
if (w.getChunkProvider().getLoadedChunk(pos.getX() >> 4, pos.getZ() >> 4) != null) {
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( NBTTagCompound extra )
{
super.readFromNBT( extra );
this.config.readFromNBT( extra, "config" );
}
@Override
public void readFromNBT(NBTTagCompound extra) {
super.readFromNBT(extra);
this.config.readFromNBT(extra, "config");
}
@Override
public void writeToNBT( NBTTagCompound extra )
{
super.writeToNBT( extra );
this.config.writeToNBT( extra, "config" );
}
@Override
public void writeToNBT(NBTTagCompound extra) {
super.writeToNBT(extra);
this.config.writeToNBT(extra, "config");
}
public IAEFluidTank getConfig()
{
return this.config;
}
public IAEFluidTank getConfig() {
return this.config;
}
@Override
public IFluidHandler getFluidInventoryByName( final String name) {
if (name.equals("config")) {
return this.config;
}
return null;
}
@Override
public IFluidHandler getFluidInventoryByName(final String name) {
if (name.equals("config")) {
return this.config;
}
return null;
}
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();
}
@@ -19,10 +19,6 @@
package appeng.fluids.registries;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import appeng.api.AEApi;
import appeng.api.implementations.tiles.IChestOrDrive;
import appeng.api.storage.ICellGuiHandler;
@@ -34,20 +30,20 @@ import appeng.api.storage.data.IAEStack;
import appeng.api.util.AEPartLocation;
import appeng.core.sync.GuiBridge;
import appeng.util.Platform;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
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 EntityPlayer player, final IChestOrDrive chest, final ICellHandler cellHandler, final IMEInventoryHandler inv, final ItemStack is, final IStorageChannel chan )
{
Platform.openGUI( player, (TileEntity) chest, AEPartLocation.fromFacing( chest.getUp() ), GuiBridge.GUI_FLUID_TERMINAL );
}
@Override
public void openChestGui(final EntityPlayer player, final IChestOrDrive chest, final ICellHandler cellHandler, final IMEInventoryHandler inv, final ItemStack is, final IStorageChannel chan) {
Platform.openGUI(player, (TileEntity) chest, AEPartLocation.fromFacing(chest.getUp()), GuiBridge.GUI_FLUID_TERMINAL);
}
}
@@ -19,19 +19,6 @@
package appeng.fluids.tile;
import java.util.EnumSet;
import javax.annotation.Nullable;
import appeng.fluids.helper.IConfigurableFluidInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.fluids.capability.IFluidHandler;
import net.minecraftforge.items.IItemHandler;
import appeng.api.AEApi;
import appeng.api.config.Upgrades;
import appeng.api.networking.IGridNode;
@@ -47,151 +34,139 @@ import appeng.api.util.DimensionalCoord;
import appeng.api.util.IConfigManager;
import appeng.core.sync.GuiBridge;
import appeng.fluids.helper.DualityFluidInterface;
import appeng.fluids.helper.IConfigurableFluidInventory;
import appeng.fluids.helper.IFluidInterfaceHost;
import appeng.helpers.IPriorityHost;
import appeng.tile.grid.AENetworkTile;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.fluids.capability.IFluidHandler;
import net.minecraftforge.items.IItemHandler;
import javax.annotation.Nullable;
import java.util.EnumSet;
public class TileFluidInterface extends AENetworkTile implements IGridTickable, IFluidInterfaceHost, IPriorityHost, IConfigurableFluidInventory
{
private final DualityFluidInterface duality = new DualityFluidInterface( this.getProxy(), this );
public class TileFluidInterface extends AENetworkTile implements IGridTickable, IFluidInterfaceHost, IPriorityHost, IConfigurableFluidInventory {
private final DualityFluidInterface duality = new DualityFluidInterface(this.getProxy(), this);
@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 NBTTagCompound writeToNBT( final NBTTagCompound data )
{
super.writeToNBT( data );
this.duality.writeToNBT( data );
return data;
}
@Override
public NBTTagCompound writeToNBT(final NBTTagCompound data) {
super.writeToNBT(data);
this.duality.writeToNBT(data);
return data;
}
@Override
public void readFromNBT( final NBTTagCompound data )
{
super.readFromNBT( data );
this.duality.readFromNBT( data );
}
@Override
public void readFromNBT(final NBTTagCompound data) {
super.readFromNBT(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<EnumFacing> getTargets()
{
return EnumSet.allOf( EnumFacing.class );
}
@Override
public EnumSet<EnumFacing> getTargets() {
return EnumSet.allOf(EnumFacing.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 boolean hasCapability( Capability<?> capability, @Nullable EnumFacing facing )
{
return this.duality.hasCapability( capability, facing ) || super.hasCapability( capability, facing );
}
@Override
public boolean hasCapability(Capability<?> capability, @Nullable EnumFacing facing) {
return this.duality.hasCapability(capability, facing) || super.hasCapability(capability, facing);
}
@Override
public <T> T getCapability( Capability<T> capability, @Nullable EnumFacing facing )
{
T result = this.duality.getCapability( capability, facing );
if( result != null )
{
return result;
}
return super.getCapability( capability, facing );
}
@Override
public <T> T getCapability(Capability<T> capability, @Nullable EnumFacing facing) {
T result = this.duality.getCapability(capability, facing);
if (result != null) {
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 IFluidHandler getFluidInventoryByName(final String name) {
return this.duality.getFluidInventoryByName(name);
}
@Override
public IFluidHandler getFluidInventoryByName(final String name) {
return this.duality.getFluidInventoryByName(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 GuiBridge getGuiBridge()
{
return GuiBridge.GUI_FLUID_INTERFACE;
}
@Override
public GuiBridge getGuiBridge() {
return GuiBridge.GUI_FLUID_INTERFACE;
}
}
@@ -1,382 +1,301 @@
package appeng.fluids.util;
import java.util.Objects;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.capability.IFluidTankProperties;
import appeng.api.storage.data.IAEFluidStack;
import appeng.core.AELog;
import appeng.util.Platform;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.capability.IFluidTankProperties;
import java.util.Objects;
public class AEFluidInventory implements IAEFluidTank
{
private final IAEFluidStack[] fluids;
private final IAEFluidInventory handler;
private final int capacity;
private IFluidTankProperties[] props = null;
public class AEFluidInventory implements IAEFluidTank {
private final IAEFluidStack[] fluids;
private final IAEFluidInventory handler;
private final int capacity;
private IFluidTankProperties[] props = null;
public AEFluidInventory( final IAEFluidInventory handler, final int slots, final int capcity )
{
this.fluids = new IAEFluidStack[slots];
this.handler = handler;
this.capacity = capcity;
}
public AEFluidInventory(final IAEFluidInventory handler, final int slots, final int capcity) {
this.fluids = new IAEFluidStack[slots];
this.handler = handler;
this.capacity = capcity;
}
public AEFluidInventory( final IAEFluidInventory handler, final int slots )
{
this( handler, slots, Integer.MAX_VALUE );
}
public AEFluidInventory(final IAEFluidInventory handler, final int slots) {
this(handler, slots, Integer.MAX_VALUE);
}
@Override
public void setFluidInSlot( final int slot, final IAEFluidStack fluid )
{
if( slot >= 0 && slot < this.getSlots() )
{
if( Objects.equals( this.fluids[slot], fluid ) )
{
if( fluid != null && fluid.getStackSize() != this.fluids[slot].getStackSize() )
{
this.fluids[slot].setStackSize( Math.min( fluid.getStackSize(), this.capacity ) );
this.onContentChanged( slot );
}
}
else
{
if( fluid == null )
{
this.fluids[slot] = null;
}
else
{
this.fluids[slot] = fluid.copy();
this.fluids[slot].setStackSize( Math.min( fluid.getStackSize(), this.capacity ) );
}
@Override
public void setFluidInSlot(final int slot, final IAEFluidStack fluid) {
if (slot >= 0 && slot < this.getSlots()) {
if (Objects.equals(this.fluids[slot], fluid)) {
if (fluid != null && fluid.getStackSize() != this.fluids[slot].getStackSize()) {
this.fluids[slot].setStackSize(Math.min(fluid.getStackSize(), this.capacity));
this.onContentChanged(slot);
}
} else {
if (fluid == null) {
this.fluids[slot] = null;
} else {
this.fluids[slot] = fluid.copy();
this.fluids[slot].setStackSize(Math.min(fluid.getStackSize(), this.capacity));
}
this.onContentChanged( slot );
}
}
}
this.onContentChanged(slot);
}
}
}
private void onContentChanged( final int slot )
{
if( this.handler != null && Platform.isServer() )
{
this.handler.onFluidInventoryChanged( this, slot );
}
}
private void onContentChanged(final int slot) {
if (this.handler != null && Platform.isServer()) {
this.handler.onFluidInventoryChanged(this, slot);
}
}
@Override
public IAEFluidStack getFluidInSlot( final int slot )
{
if( slot >= 0 && slot < this.getSlots() )
{
return this.fluids[slot];
}
return null;
}
@Override
public IAEFluidStack getFluidInSlot(final int slot) {
if (slot >= 0 && slot < this.getSlots()) {
return this.fluids[slot];
}
return null;
}
@Override
public int getSlots()
{
return this.fluids.length;
}
@Override
public int getSlots() {
return this.fluids.length;
}
@Override
public IFluidTankProperties[] getTankProperties()
{
if( this.props == null )
{
this.props = new IFluidTankProperties[this.getSlots()];
for( int i = 0; i < this.getSlots(); ++i )
{
this.props[i] = new FluidTankPropertiesWrapper( i );
}
@Override
public IFluidTankProperties[] getTankProperties() {
if (this.props == null) {
this.props = new IFluidTankProperties[this.getSlots()];
for (int i = 0; i < this.getSlots(); ++i) {
this.props[i] = new FluidTankPropertiesWrapper(i);
}
}
return this.props;
}
}
return this.props;
}
public int fill( final int slot, final FluidStack resource, final boolean doFill )
{
if( resource == null || resource.amount <= 0 )
{
return 0;
}
public int fill(final int slot, final FluidStack resource, final boolean doFill) {
if (resource == null || resource.amount <= 0) {
return 0;
}
final IAEFluidStack fluid = this.fluids[slot];
final IAEFluidStack fluid = this.fluids[slot];
if( fluid != null && !fluid.equals( resource ) )
{
return 0;
}
if (fluid != null && !fluid.equals(resource)) {
return 0;
}
int amountToStore = this.capacity;
int amountToStore = this.capacity;
if( fluid != null )
{
amountToStore -= fluid.getStackSize();
}
if (fluid != null) {
amountToStore -= fluid.getStackSize();
}
amountToStore = Math.min( amountToStore, resource.amount );
amountToStore = Math.min(amountToStore, resource.amount);
if( doFill )
{
if( fluid == null )
{
this.setFluidInSlot( slot, AEFluidStack.fromFluidStack( resource ) );
}
else
{
fluid.setStackSize( fluid.getStackSize() + amountToStore );
this.onContentChanged( slot );
}
}
if (doFill) {
if (fluid == null) {
this.setFluidInSlot(slot, AEFluidStack.fromFluidStack(resource));
} else {
fluid.setStackSize(fluid.getStackSize() + amountToStore);
this.onContentChanged(slot);
}
}
return amountToStore;
}
return amountToStore;
}
public FluidStack drain( final int slot, final FluidStack resource, final boolean doDrain )
{
final IAEFluidStack fluid = this.fluids[slot];
if( resource == null || fluid == null || !fluid.equals( resource ) )
{
return null;
}
return this.drain( slot, resource.amount, doDrain );
}
public FluidStack drain(final int slot, final FluidStack resource, final boolean doDrain) {
final IAEFluidStack fluid = this.fluids[slot];
if (resource == null || fluid == null || !fluid.equals(resource)) {
return null;
}
return this.drain(slot, resource.amount, doDrain);
}
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 int maxDrain, boolean doDrain) {
final IAEFluidStack fluid = this.fluids[slot];
if (fluid == null || maxDrain <= 0) {
return null;
}
int drained = maxDrain;
if( fluid.getStackSize() < drained )
{
drained = (int) fluid.getStackSize();
}
int drained = maxDrain;
if (fluid.getStackSize() < drained) {
drained = (int) fluid.getStackSize();
}
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;
}
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;
}
@Override
public int fill( final FluidStack fluid, final boolean doFill )
{
if( fluid == null || fluid.amount <= 0 )
{
return 0;
}
@Override
public int fill(final FluidStack fluid, final boolean doFill) {
if (fluid == null || fluid.amount <= 0) {
return 0;
}
final FluidStack insert = fluid.copy();
final FluidStack insert = fluid.copy();
int totalFillAmount = 0;
for( int slot = 0; slot < this.getSlots(); ++slot )
{
int fillAmount = this.fill( slot, insert, doFill );
totalFillAmount += fillAmount;
insert.amount -= fillAmount;
if( insert.amount <= 0 )
{
break;
}
}
return totalFillAmount;
}
int totalFillAmount = 0;
for (int slot = 0; slot < this.getSlots(); ++slot) {
int fillAmount = this.fill(slot, insert, doFill);
totalFillAmount += fillAmount;
insert.amount -= fillAmount;
if (insert.amount <= 0) {
break;
}
}
return totalFillAmount;
}
@Override
public FluidStack drain( final FluidStack fluid, final boolean doDrain )
{
if( fluid == null || fluid.amount <= 0 )
{
return null;
}
@Override
public FluidStack drain(final FluidStack fluid, final boolean doDrain) {
if (fluid == null || fluid.amount <= 0) {
return null;
}
final FluidStack resource = fluid.copy();
final FluidStack resource = fluid.copy();
FluidStack totalDrained = null;
for( int slot = 0; slot < this.getSlots(); ++slot )
{
FluidStack drain = this.drain( slot, resource, doDrain );
if( drain != null )
{
if( totalDrained == null )
{
totalDrained = drain;
}
else
{
totalDrained.amount += drain.amount;
}
FluidStack totalDrained = null;
for (int slot = 0; slot < this.getSlots(); ++slot) {
FluidStack drain = this.drain(slot, resource, doDrain);
if (drain != null) {
if (totalDrained == null) {
totalDrained = drain;
} else {
totalDrained.amount += drain.amount;
}
resource.amount -= drain.amount;
if( resource.amount <= 0 )
{
break;
}
}
}
return totalDrained;
}
resource.amount -= drain.amount;
if (resource.amount <= 0) {
break;
}
}
}
return totalDrained;
}
@Override
public FluidStack drain( final int maxDrain, final boolean doDrain )
{
if( maxDrain == 0 )
{
return null;
}
@Override
public FluidStack drain(final int maxDrain, final boolean doDrain) {
if (maxDrain == 0) {
return null;
}
FluidStack totalDrained = null;
int toDrain = maxDrain;
FluidStack totalDrained = null;
int toDrain = maxDrain;
for( int slot = 0; slot < this.getSlots(); ++slot )
{
if( totalDrained == null )
{
totalDrained = this.drain( slot, toDrain, doDrain );
if( totalDrained != null )
{
toDrain -= totalDrained.amount;
}
}
else
{
FluidStack copy = totalDrained.copy();
copy.amount = toDrain;
FluidStack drain = this.drain( slot, copy, doDrain );
if( drain != null )
{
totalDrained.amount += drain.amount;
toDrain -= drain.amount;
}
}
for (int slot = 0; slot < this.getSlots(); ++slot) {
if (totalDrained == null) {
totalDrained = this.drain(slot, toDrain, doDrain);
if (totalDrained != null) {
toDrain -= totalDrained.amount;
}
} else {
FluidStack copy = totalDrained.copy();
copy.amount = toDrain;
FluidStack drain = this.drain(slot, copy, doDrain);
if (drain != null) {
totalDrained.amount += drain.amount;
toDrain -= drain.amount;
}
}
if( toDrain <= 0 )
{
break;
}
}
return totalDrained;
}
if (toDrain <= 0) {
break;
}
}
return totalDrained;
}
public void writeToNBT( final NBTTagCompound data, final String name )
{
final NBTTagCompound c = new NBTTagCompound();
this.writeToNBT( c );
data.setTag( name, c );
}
public void writeToNBT(final NBTTagCompound data, final String name) {
final NBTTagCompound c = new NBTTagCompound();
this.writeToNBT(c);
data.setTag(name, c);
}
private void writeToNBT( final NBTTagCompound target )
{
for( int x = 0; x < this.fluids.length; x++ )
{
try
{
final NBTTagCompound c = new NBTTagCompound();
private void writeToNBT(final NBTTagCompound target) {
for (int x = 0; x < this.fluids.length; x++) {
try {
final NBTTagCompound c = new NBTTagCompound();
if( this.fluids[x] != null )
{
this.fluids[x].writeToNBT( c );
}
if (this.fluids[x] != null) {
this.fluids[x].writeToNBT(c);
}
target.setTag( "#" + x, c );
}
catch( final Exception ignored )
{
}
}
}
target.setTag("#" + x, c);
} catch (final Exception ignored) {
}
}
}
public void readFromNBT( final NBTTagCompound data, final String name )
{
final NBTTagCompound c = data.getCompoundTag( name );
if( c != null )
{
this.readFromNBT( c );
}
}
public void readFromNBT(final NBTTagCompound data, final String name) {
final NBTTagCompound c = data.getCompoundTag(name);
if (c != null) {
this.readFromNBT(c);
}
}
private void readFromNBT( final NBTTagCompound target )
{
for( int x = 0; x < this.fluids.length; x++ )
{
try
{
final NBTTagCompound c = target.getCompoundTag( "#" + x );
private void readFromNBT(final NBTTagCompound target) {
for (int x = 0; x < this.fluids.length; x++) {
try {
final NBTTagCompound c = target.getCompoundTag("#" + x);
if( c != null )
{
this.fluids[x] = AEFluidStack.fromNBT( c );
}
}
catch( final Exception e )
{
AELog.debug( e );
}
}
}
if (c != null) {
this.fluids[x] = AEFluidStack.fromNBT(c);
}
} catch (final Exception e) {
AELog.debug(e);
}
}
}
private class FluidTankPropertiesWrapper implements IFluidTankProperties
{
private final int slot;
private class FluidTankPropertiesWrapper implements IFluidTankProperties {
private final int slot;
public FluidTankPropertiesWrapper( final int slot )
{
this.slot = slot;
}
public FluidTankPropertiesWrapper(final int slot) {
this.slot = slot;
}
@Override
public FluidStack getContents()
{
return AEFluidInventory.this.fluids[this.slot] == null ? null : AEFluidInventory.this.fluids[this.slot].getFluidStack();
}
@Override
public FluidStack getContents() {
return AEFluidInventory.this.fluids[this.slot] == null ? null : AEFluidInventory.this.fluids[this.slot].getFluidStack();
}
@Override
public int getCapacity()
{
return Math.min( AEFluidInventory.this.capacity, Integer.MAX_VALUE );
}
@Override
public int getCapacity() {
return Math.min(AEFluidInventory.this.capacity, Integer.MAX_VALUE);
}
@Override
public boolean canFill()
{
return true;
}
@Override
public boolean canFill() {
return true;
}
@Override
public boolean canDrain()
{
return true;
}
@Override
public boolean canDrain() {
return true;
}
@Override
public boolean canFillFluidType( FluidStack fluidStack )
{
return true;
}
@Override
public boolean canFillFluidType(FluidStack fluidStack) {
return true;
}
@Override
public boolean canDrainFluidType( FluidStack fluidStack )
{
return fluidStack != null;
}
}
@Override
public boolean canDrainFluidType(FluidStack fluidStack) {
return fluidStack != null;
}
}
}
+216 -265
View File
@@ -19,22 +19,6 @@
package appeng.fluids.util;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import javax.annotation.Nonnull;
import io.netty.buffer.ByteBuf;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;
import appeng.api.AEApi;
import appeng.api.config.FuzzyMode;
import appeng.api.storage.IStorageChannel;
@@ -44,310 +28,277 @@ import appeng.core.Api;
import appeng.fluids.items.FluidDummyItem;
import appeng.util.Platform;
import appeng.util.item.AEStack;
import io.netty.buffer.ByteBuf;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;
import javax.annotation.Nonnull;
import java.io.*;
import java.nio.charset.StandardCharsets;
public final class AEFluidStack extends AEStack<IAEFluidStack> implements IAEFluidStack, Comparable<AEFluidStack>
{
public final class AEFluidStack extends AEStack<IAEFluidStack> implements IAEFluidStack, Comparable<AEFluidStack> {
private final Fluid fluid;
private NBTTagCompound tagCompound;
private final Fluid fluid;
private NBTTagCompound 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.amount );
this.setCraftable( false );
this.setCountRequestable( 0 );
this.setStackSize(fluidStack.amount);
this.setCraftable(false);
this.setCountRequestable(0);
if( fluidStack.tag != null )
{
this.tagCompound = fluidStack.tag.copy();
}
}
if (fluidStack.tag != null) {
this.tagCompound = fluidStack.tag.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 NBTTagCompound data )
{
final FluidStack fluidStack = FluidStack.loadFluidStackFromNBT( data );
public static IAEFluidStack fromNBT(final NBTTagCompound data) {
final FluidStack fluidStack = FluidStack.loadFluidStackFromNBT(data);
if( fluidStack == null )
{
return null;
}
if (fluidStack == null) {
return null;
}
final AEFluidStack fluid = AEFluidStack.fromFluidStack( fluidStack );
fluid.setStackSize( data.getLong( "Cnt" ) );
fluid.setCountRequestable( data.getLong( "Req" ) );
fluid.setCraftable( data.getBoolean( "Craft" ) );
final AEFluidStack fluid = AEFluidStack.fromFluidStack(fluidStack);
fluid.setStackSize(data.getLong("Cnt"));
fluid.setCountRequestable(data.getLong("Req"));
fluid.setCraftable(data.getBoolean("Craft"));
if( fluid.hasTagCompound() )
{
fluid.tagCompound = fluid.tagCompound.copy();
}
if (fluid.hasTagCompound()) {
fluid.tagCompound = fluid.tagCompound.copy();
}
return fluid;
}
return fluid;
}
public static IAEFluidStack fromPacket( final ByteBuf buffer ) throws IOException
{
final byte mask = buffer.readByte();
final byte stackType = (byte) ( ( mask & 0x0C ) >> 2 );
final byte countReqType = (byte) ( ( mask & 0x30 ) >> 4 );
final boolean isCraftable = ( mask & 0x40 ) > 0;
final boolean hasTagCompound = ( mask & 0x80 ) > 0;
public static IAEFluidStack fromPacket(final ByteBuf buffer) throws IOException {
final byte mask = buffer.readByte();
final byte stackType = (byte) ((mask & 0x0C) >> 2);
final byte countReqType = (byte) ((mask & 0x30) >> 4);
final boolean isCraftable = (mask & 0x40) > 0;
final boolean hasTagCompound = (mask & 0x80) > 0;
// don't send this...
final NBTTagCompound d = new NBTTagCompound();
// don't send this...
final NBTTagCompound d = new NBTTagCompound();
final byte len2 = buffer.readByte();
final byte[] name = new byte[len2];
buffer.readBytes( name, 0, len2 );
final byte len2 = buffer.readByte();
final byte[] name = new byte[len2];
buffer.readBytes(name, 0, len2);
d.setString( "FluidName", new String( name, "UTF-8" ) );
d.setByte( "Count", (byte) 0 );
d.setString("FluidName", new String(name, StandardCharsets.UTF_8));
d.setByte("Count", (byte) 0);
if( hasTagCompound )
{
final int len = buffer.readInt();
if (hasTagCompound) {
final int len = buffer.readInt();
final byte[] bd = new byte[len];
buffer.readBytes( bd );
final byte[] bd = new byte[len];
buffer.readBytes(bd);
final DataInputStream di = new DataInputStream( new ByteArrayInputStream( bd ) );
d.setTag( "Tag", CompressedStreamTools.read( di ) );
}
final DataInputStream di = new DataInputStream(new ByteArrayInputStream(bd));
d.setTag("Tag", CompressedStreamTools.read(di));
}
final long stackSize = getPacketValue( stackType, buffer );
final long countRequestable = getPacketValue( countReqType, buffer );
final long stackSize = getPacketValue(stackType, buffer);
final long countRequestable = getPacketValue(countReqType, buffer);
final FluidStack fluidStack = FluidStack.loadFluidStackFromNBT( d );
final FluidStack fluidStack = FluidStack.loadFluidStackFromNBT(d);
if( fluidStack == null )
{
return null;
}
if (fluidStack == null) {
return null;
}
final AEFluidStack fluid = AEFluidStack.fromFluidStack( fluidStack );
// fluid.priority = (int) priority;
fluid.setStackSize( stackSize );
fluid.setCountRequestable( countRequestable );
fluid.setCraftable( isCraftable );
return fluid;
}
final AEFluidStack fluid = AEFluidStack.fromFluidStack(fluidStack);
// fluid.priority = (int) priority;
fluid.setStackSize(stackSize);
fluid.setCountRequestable(countRequestable);
fluid.setCraftable(isCraftable);
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 NBTTagCompound data )
{
data.setString( "FluidName", this.fluid.getName() );
data.setByte( "Count", (byte) 0 );
data.setLong( "Cnt", this.getStackSize() );
data.setLong( "Req", this.getCountRequestable() );
data.setBoolean( "Craft", this.isCraftable() );
@Override
public void writeToNBT(final NBTTagCompound data) {
data.setString("FluidName", this.fluid.getName());
data.setByte("Count", (byte) 0);
data.setLong("Cnt", this.getStackSize());
data.setLong("Req", this.getCountRequestable());
data.setBoolean("Craft", this.isCraftable());
if( this.hasTagCompound() )
{
data.setTag( "Tag", this.tagCompound );
}
else
{
data.removeTag( "Tag" );
}
}
if (this.hasTagCompound()) {
data.setTag("Tag", this.tagCompound);
} else {
data.removeTag("Tag");
}
}
@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.getName().compareTo( other.fluid.getName() );
}
@Override
public int compareTo(final AEFluidStack other) {
if (this.fluid != other.fluid) {
return this.fluid.getName().compareTo(other.fluid.getName());
}
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.tag );
}
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.tag);
}
return false;
}
@Override
public String toString()
{
return this.getStackSize() + "x" + this.getFluidStack().getFluid().getName() + " " + this.tagCompound;
}
@Override
public String toString() {
return this.getStackSize() + "x" + this.getFluidStack().getFluid().getName() + " " + 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 = Api.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 = Api.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 void writeToPacket( final ByteBuf buffer ) throws IOException
{
final byte mask = (byte) ( ( this.getType( this.getStackSize() ) << 2 ) | ( this
.getType( this.getCountRequestable() ) << 4 ) | ( (byte) ( this.isCraftable() ? 1 : 0 ) << 6 ) | ( this.hasTagCompound() ? 1 : 0 ) << 7 );
@Override
public void writeToPacket(final ByteBuf buffer) throws IOException {
final byte mask = (byte) ((this.getType(this.getStackSize()) << 2) | (this
.getType(this.getCountRequestable()) << 4) | ((byte) (this.isCraftable() ? 1 : 0) << 6) | (this.hasTagCompound() ? 1 : 0) << 7);
buffer.writeByte( mask );
buffer.writeByte(mask);
this.writeToStream( buffer );
this.writeToStream(buffer);
this.putPacketValue( buffer, this.getStackSize() );
this.putPacketValue( buffer, this.getCountRequestable() );
}
this.putPacketValue(buffer, this.getStackSize());
this.putPacketValue(buffer, this.getCountRequestable());
}
private void writeToStream( final ByteBuf buffer ) throws IOException
{
final byte[] name = this.fluid.getName().getBytes( "UTF-8" );
buffer.writeByte( (byte) name.length );
buffer.writeBytes( name );
if( this.hasTagCompound() )
{
final ByteArrayOutputStream bytes = new ByteArrayOutputStream();
final DataOutputStream data = new DataOutputStream( bytes );
private void writeToStream(final ByteBuf buffer) throws IOException {
final byte[] name = this.fluid.getName().getBytes(StandardCharsets.UTF_8);
buffer.writeByte((byte) name.length);
buffer.writeBytes(name);
if (this.hasTagCompound()) {
final ByteArrayOutputStream bytes = new ByteArrayOutputStream();
final DataOutputStream data = new DataOutputStream(bytes);
CompressedStreamTools.write( this.tagCompound, data );
CompressedStreamTools.write(this.tagCompound, data);
final byte[] tagBytes = bytes.toByteArray();
final int size = tagBytes.length;
final byte[] tagBytes = bytes.toByteArray();
final int size = tagBytes.length;
buffer.writeInt( size );
buffer.writeBytes( tagBytes );
}
}
buffer.writeInt(size);
buffer.writeBytes(tagBytes);
}
}
}
@@ -19,61 +19,50 @@
package appeng.fluids.util;
import appeng.api.storage.data.IAEFluidStack;
import appeng.util.Platform;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.fluids.FluidTank;
import appeng.api.storage.data.IAEFluidStack;
import appeng.util.Platform;
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;
if (host instanceof TileEntity) {
this.setTileEntity((TileEntity) host);
}
}
public AEFluidTank( IAEFluidInventory host, int capacity )
{
super( capacity );
this.host = host;
if( host instanceof TileEntity )
{
this.setTileEntity( (TileEntity) host );
}
}
@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;
}
}
+110 -140
View File
@@ -19,183 +19,153 @@
package appeng.fluids.util;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import appeng.api.config.FuzzyMode;
import appeng.api.storage.data.IAEFluidStack;
import appeng.api.storage.data.IItemList;
import java.util.*;
public final class FluidList implements IItemList<IAEFluidStack>
{
private final Map<IAEFluidStack, IAEFluidStack> records = new HashMap<>();
public final class FluidList implements IItemList<IAEFluidStack> {
@Override
public void add( final IAEFluidStack option )
{
if( option == null )
{
return;
}
private final Map<IAEFluidStack, IAEFluidStack> records = new HashMap<>();
final IAEFluidStack st = this.getFluidRecord( option );
@Override
public void add(final IAEFluidStack option) {
if (option == null) {
return;
}
if( st != null )
{
st.add( option );
return;
}
final IAEFluidStack st = this.getFluidRecord(option);
final IAEFluidStack opt = option.copy();
if (st != null) {
st.add(option);
return;
}
this.putFluidRecord( opt );
}
final IAEFluidStack opt = option.copy();
@Override
public IAEFluidStack findPrecise( final IAEFluidStack fluidStack )
{
if( fluidStack == null )
{
return null;
}
this.putFluidRecord(opt);
}
return this.getFluidRecord( fluidStack );
}
@Override
public IAEFluidStack findPrecise(final IAEFluidStack fluidStack) {
if (fluidStack == null) {
return null;
}
@Override
public Collection<IAEFluidStack> findFuzzy( final IAEFluidStack filter, final FuzzyMode fuzzy )
{
if( filter == null )
{
return Collections.emptyList();
}
return this.getFluidRecord(fluidStack);
}
return Collections.singletonList( this.findPrecise( filter ) );
}
@Override
public Collection<IAEFluidStack> findFuzzy(final IAEFluidStack filter, final FuzzyMode fuzzy) {
if (filter == null) {
return Collections.emptyList();
}
@Override
public boolean isEmpty()
{
return !this.iterator().hasNext();
}
return Collections.singletonList(this.findPrecise(filter));
}
@Override
public void addStorage( final IAEFluidStack option )
{
if( option == null )
{
return;
}
@Override
public boolean isEmpty() {
return !this.iterator().hasNext();
}
final IAEFluidStack st = this.getFluidRecord( option );
@Override
public void addStorage(final IAEFluidStack option) {
if (option == null) {
return;
}
if( st != null )
{
st.incStackSize( option.getStackSize() );
return;
}
final IAEFluidStack st = this.getFluidRecord(option);
final IAEFluidStack opt = option.copy();
if (st != null) {
st.incStackSize(option.getStackSize());
return;
}
this.putFluidRecord( opt );
}
final IAEFluidStack opt = option.copy();
/*
* public synchronized void clean() { Iterator<StackType> i = iterator(); while (i.hasNext()) { StackType AEI =
* i.next(); if ( !AEI.isMeaningful() ) i.remove(); } }
*/
this.putFluidRecord(opt);
}
@Override
public void addCrafting( final IAEFluidStack option )
{
if( option == null )
{
return;
}
/*
* public synchronized void clean() { Iterator<StackType> i = iterator(); while (i.hasNext()) { StackType AEI =
* i.next(); if ( !AEI.isMeaningful() ) i.remove(); } }
*/
final IAEFluidStack st = this.getFluidRecord( option );
@Override
public void addCrafting(final IAEFluidStack option) {
if (option == null) {
return;
}
if( st != null )
{
st.setCraftable( true );
return;
}
final IAEFluidStack st = this.getFluidRecord(option);
final IAEFluidStack opt = option.copy();
opt.setStackSize( 0 );
opt.setCraftable( true );
if (st != null) {
st.setCraftable(true);
return;
}
this.putFluidRecord( opt );
}
final IAEFluidStack opt = option.copy();
opt.setStackSize(0);
opt.setCraftable(true);
@Override
public void addRequestable( final IAEFluidStack option )
{
if( option == null )
{
return;
}
this.putFluidRecord(opt);
}
final IAEFluidStack st = this.getFluidRecord( option );
@Override
public void addRequestable(final IAEFluidStack option) {
if (option == null) {
return;
}
if( st != null )
{
st.setCountRequestable( st.getCountRequestable() + option.getCountRequestable() );
return;
}
final IAEFluidStack st = this.getFluidRecord(option);
final IAEFluidStack opt = option.copy();
opt.setStackSize( 0 );
opt.setCraftable( false );
opt.setCountRequestable( option.getCountRequestable() );
if (st != null) {
st.setCountRequestable(st.getCountRequestable() + option.getCountRequestable());
return;
}
this.putFluidRecord( opt );
}
final IAEFluidStack opt = option.copy();
opt.setStackSize(0);
opt.setCraftable(false);
opt.setCountRequestable(option.getCountRequestable());
@Override
public IAEFluidStack getFirstItem()
{
for( final IAEFluidStack stackType : this )
{
return stackType;
}
this.putFluidRecord(opt);
}
return null;
}
@Override
public IAEFluidStack getFirstItem() {
for (final IAEFluidStack stackType : this) {
return stackType;
}
@Override
public int size()
{
return this.records.values().size();
}
return null;
}
@Override
public Iterator<IAEFluidStack> iterator()
{
return new MeaningfulFluidIterator<>( this.records.values().iterator() );
}
@Override
public int size() {
return this.records.values().size();
}
@Override
public void resetStatus()
{
for( final IAEFluidStack i : this )
{
i.reset();
}
}
@Override
public Iterator<IAEFluidStack> iterator() {
return new MeaningfulFluidIterator<>(this.records.values().iterator());
}
private IAEFluidStack getFluidRecord( final IAEFluidStack fluid )
{
return this.records.get( fluid );
}
@Override
public void resetStatus() {
for (final IAEFluidStack i : this) {
i.reset();
}
}
private IAEFluidStack putFluidRecord( final IAEFluidStack fluid )
{
return this.records.put( fluid, fluid );
}
private IAEFluidStack getFluidRecord(final IAEFluidStack fluid) {
return this.records.get(fluid);
}
private IAEFluidStack putFluidRecord(final IAEFluidStack fluid) {
return this.records.put(fluid, fluid);
}
}
@@ -19,74 +19,64 @@
package appeng.fluids.util;
import java.util.Comparator;
import appeng.api.config.SortDir;
import appeng.api.storage.data.IAEFluidStack;
import appeng.util.Platform;
import java.util.Comparator;
/**
* @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 ) ->
{
if( getDirection() == SortDir.ASCENDING )
{
return Platform.getFluidDisplayName( o1 ).compareToIgnoreCase( Platform.getFluidDisplayName( o2 ) );
}
return Platform.getFluidDisplayName( o2 ).compareToIgnoreCase( Platform.getFluidDisplayName( o1 ) );
};
public static final Comparator<IAEFluidStack> CONFIG_BASED_SORT_BY_NAME = (o1, o2) ->
{
if (getDirection() == SortDir.ASCENDING) {
return Platform.getFluidDisplayName(o1).compareToIgnoreCase(Platform.getFluidDisplayName(o2));
}
return Platform.getFluidDisplayName(o2).compareToIgnoreCase(Platform.getFluidDisplayName(o1));
};
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 )
{
return Platform.getFluidDisplayName( o2 ).compareToIgnoreCase( Platform.getFluidDisplayName( o1 ) );
}
private int secondarySort(final int compareToIgnoreCase, final IAEFluidStack o1, final IAEFluidStack o2) {
if (compareToIgnoreCase == 0) {
return Platform.getFluidDisplayName(o2).compareToIgnoreCase(Platform.getFluidDisplayName(o1));
}
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;
}
}
@@ -20,7 +20,6 @@ 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 appeng.api.storage.data.IAEFluidStack;
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();
}
@@ -19,57 +19,47 @@
package appeng.fluids.util;
import appeng.api.storage.data.IAEStack;
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();
}
}