Work on GUIs (specifically to get SkyChest GUI)

This commit is contained in:
Sebastian Hartte
2020-06-02 02:14:09 +02:00
parent 271e8889a1
commit 9f63859769
109 changed files with 1133 additions and 1301 deletions
@@ -33,9 +33,9 @@ public class GuiFluidFormationPlane extends GuiUpgradeable
}
@Override
public void initGui()
public void init()
{
super.initGui();
super.init();
final int xo = 8;
final int yo = 23 + 6;
@@ -63,7 +63,7 @@ public class GuiFluidFormationPlane extends GuiUpgradeable
@Override
protected void addButtons()
{
this.buttonList.add( this.priority = new GuiTabButton( this.guiLeft + 154, this.guiTop, 2 + 4 * 16, GuiText.Priority.getLocal(), this.itemRender ) );
this.addButton( this.priority = new GuiTabButton( this.guiLeft + 154, this.guiTop, 2 + 4 * 16, GuiText.Priority.getLocal(), this.itemRender ) );
}
@Override
@@ -47,9 +47,9 @@ public class GuiFluidIO extends GuiUpgradeable
}
@Override
public void initGui()
public void init()
{
super.initGui();
super.init();
final ContainerFluidIO container = (ContainerFluidIO) this.inventorySlots;
final IAEFluidTank inv = this.bus.getConfig();
@@ -53,9 +53,9 @@ public class GuiFluidInterface extends GuiUpgradeable
}
@Override
public void initGui()
public void init()
{
super.initGui();
super.init();
final IAEFluidTank configFluids = this.host.getDualityFluidInterface().getConfig();
final IAEFluidTank fluidTank = this.host.getDualityFluidInterface().getTanks();
@@ -64,12 +64,12 @@ public class GuiFluidInterface extends GuiUpgradeable
{
final GuiFluidTank guiTank = new GuiFluidTank( fluidTank, i, DualityFluidInterface.NUMBER_OF_TANKS + i, this.getGuiLeft() + 35 + 18 * i, this
.getGuiTop() + 53, 16, 68 );
this.buttonList.add( guiTank );
this.addButton( guiTank );
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.addButton( this.priority );
}
@Override
@@ -80,10 +80,10 @@ public class GuiFluidInterface extends GuiUpgradeable
@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 );
this.font.drawString( this.getGuiDisplayName( GuiText.FluidInterface.getLocal() ), 8, 6, 4210752 );
this.font.drawString( GuiText.Config.getLocal(), 35, 6 + 11 + 7, 4210752 );
this.font.drawString( GuiText.StoredFluids.getLocal(), 35, 6 + 112 + 7, 4210752 );
this.font.drawString( GuiText.inventory.getLocal(), 8, this.ySize - 96 + 3, 4210752 );
}
@Override
@@ -43,11 +43,11 @@ public class GuiFluidLevelEmitter extends GuiUpgradeable
}
@Override
public void initGui()
public void init()
{
super.initGui();
super.init();
this.level = new GuiNumberBox( this.fontRenderer, this.guiLeft + 24, this.guiTop + 43, 79, this.fontRenderer.FONT_HEIGHT, Long.class );
this.level = new GuiNumberBox( this.font, this.guiLeft + 24, this.guiTop + 43, 79, this.font.FONT_HEIGHT, Long.class );
this.level.setEnableBackgroundDrawing( false );
this.level.setMaxStringLength( 16 );
this.level.setTextColor( 0xFFFFFF );
@@ -70,17 +70,17 @@ public class GuiFluidLevelEmitter extends GuiUpgradeable
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.addButton( this.plus1 = new GuiButton( 0, this.guiLeft + 20, this.guiTop + 17, 22, 20, "+" + a ) );
this.addButton( this.plus10 = new GuiButton( 0, this.guiLeft + 48, this.guiTop + 17, 28, 20, "+" + b ) );
this.addButton( this.plus100 = new GuiButton( 0, this.guiLeft + 82, this.guiTop + 17, 32, 20, "+" + c ) );
this.addButton( 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.addButton( this.minus1 = new GuiButton( 0, this.guiLeft + 20, this.guiTop + 59, 22, 20, "-" + a ) );
this.addButton( this.minus10 = new GuiButton( 0, this.guiLeft + 48, this.guiTop + 59, 28, 20, "-" + b ) );
this.addButton( this.minus100 = new GuiButton( 0, this.guiLeft + 82, this.guiTop + 59, 32, 20, "-" + c ) );
this.addButton( this.minus1000 = new GuiButton( 0, this.guiLeft + 120, this.guiTop + 59, 38, 20, "-" + d ) );
this.buttonList.add( this.redstoneMode );
this.addButton( this.redstoneMode );
}
@Override
@@ -70,9 +70,9 @@ public class GuiFluidStorageBus extends GuiUpgradeable
}
@Override
public void initGui()
public void init()
{
super.initGui();
super.init();
final int xo = 8;
final int yo = 23 + 6;
@@ -106,20 +106,20 @@ public class GuiFluidStorageBus extends GuiUpgradeable
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.addButton( 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.addButton( this.storageFilter );
this.addButton( this.fuzzyMode );
this.addButton( this.rwMode );
this.addButton( this.partition );
this.addButton( 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 );
this.font.drawString( this.getGuiDisplayName( this.getName().getLocal() ), 8, 6, 4210752 );
this.font.drawString( GuiText.inventory.getLocal(), 8, this.ySize - 96 + 3, 4210752 );
if( this.fuzzyMode != null )
{
@@ -100,13 +100,13 @@ public class GuiFluidTerminal extends AEBaseMEGui implements ISortSource, IConfi
}
@Override
public void initGui()
public void init()
{
this.mc.player.openContainer = this.inventorySlots;
this.minecraft.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 = new MEGuiTextField( this.font, this.guiLeft + Math.max( 80, this.offsetX ), this.guiTop + 4, 90, 12 );
this.searchField.setEnableBackgroundDrawing( false );
this.searchField.setMaxStringLength( 25 );
this.searchField.setTextColor( 0xFFFFFF );
@@ -115,10 +115,10 @@ public class GuiFluidTerminal extends AEBaseMEGui implements ISortSource, IConfi
int offset = this.guiTop;
this.buttonList.add( this.sortByBox = new GuiImgButton( this.guiLeft - 18, offset, Settings.SORT_BY, this.configSrc.getSetting( Settings.SORT_BY ) ) );
this.addButton( 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
this.addButton( 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++ )
@@ -136,8 +136,8 @@ public class GuiFluidTerminal extends AEBaseMEGui implements ISortSource, IConfi
@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 );
this.font.drawString( this.getGuiDisplayName( "Fluid Terminal" ), 8, 6, 4210752 );
this.font.drawString( GuiText.inventory.getLocal(), 8, this.ySize - 96 + 3, 4210752 );
}
@Override
@@ -41,8 +41,8 @@ public class GuiFluidSlot extends GuiCustomSlot
final IAEFluidStack fs = this.getFluidStack();
if( fs != null )
{
GlStateManager.disableLighting();
GlStateManager.disableBlend();
RenderSystem.disableLighting();
RenderSystem.disableBlend();
final Fluid fluid = fs.getFluid();
mc.getTextureManager().bindTexture( TextureMap.LOCATION_BLOCKS_TEXTURE );
final TextureAtlasSprite sprite = mc.getTextureMapBlocks().getAtlasSprite( fluid.getStill().toString() );
@@ -52,7 +52,7 @@ public class GuiFluidSlot extends GuiCustomSlot
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 );
RenderSystem.color4f( red, green, blue );
this.drawTexturedModalRect( this.xPos(), this.yPos(), sprite, this.getWidth(), this.getHeight() );
}
@@ -51,10 +51,10 @@ public class GuiFluidTank extends GuiButton implements ITooltip
{
if( this.visible )
{
GlStateManager.disableBlend();
GlStateManager.disableLighting();
RenderSystem.disableBlend();
RenderSystem.disableLighting();
drawRect( this.x, this.y, this.x + this.width, this.y + this.height, AEColor.GRAY.blackVariant | 0xFF000000 );
fill( this.x, this.y, this.x + this.width, this.y + this.height, AEColor.GRAY.blackVariant | 0xFF000000 );
final IAEFluidStack fluid = this.tank.getFluidInSlot( this.slot );
if( fluid != null && fluid.getStackSize() > 0 )
@@ -64,7 +64,7 @@ public class GuiFluidTank extends GuiButton implements ITooltip
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 );
RenderSystem.color4f( 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() ) );
@@ -48,14 +48,14 @@ public class GuiOptionalFluidSlot extends GuiFluidSlot
@Override
public void drawBackground( int guileft, int guitop )
{
GlStateManager.enableBlend();
RenderSystem.enableBlend();
if( this.isSlotEnabled() )
{
GlStateManager.color( 1.0F, 1.0F, 1.0F, 1.0F );
RenderSystem.color4f( 1.0F, 1.0F, 1.0F, 1.0F );
}
else
{
GlStateManager.color( 1.0F, 1.0F, 1.0F, 0.4F );
RenderSystem.color4f( 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 );
@@ -63,18 +63,18 @@ public class FluidStackSizeRenderer
{
final String stackSize = this.getToBeRenderedStackSize( aeStack.getStackSize() );
GlStateManager.disableLighting();
GlStateManager.disableDepth();
GlStateManager.disableBlend();
RenderSystem.disableLighting();
RenderSystem.disableDepthTest();
RenderSystem.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();
RenderSystem.enableLighting();
RenderSystem.enableDepthTest();
RenderSystem.enableBlend();
}
fontRenderer.setUnicodeFlag( unicodeFlag );
@@ -75,7 +75,7 @@ import appeng.util.Platform;
public class DualityFluidInterface implements IGridTickable, IStorageMonitorable, IAEFluidInventory, IUpgradeableHost, IConfigManagerHost
{
public static final int NUMBER_OF_TANKS = 6;
public static final int TANK_CAPACITY = Fluid.BUCKET_VOLUME * 4;
public static final int TANK_CAPACITY = FluidAttributes.BUCKET_VOLUME * 4;
private final ConfigManager cm = new ConfigManager( this );
private final AENetworkProxy gridProxy;
@@ -57,7 +57,7 @@ public class FluidCellConfig extends CellConfig
return stack;
}
fluid.amount = Fluid.BUCKET_VOLUME;
fluid.amount = FluidAttributes.BUCKET_VOLUME;
ItemStack is = Api.INSTANCE.definitions().items().dummyFluidItem().maybeStack( 1 ).get();
FluidDummyItem item = (FluidDummyItem) is.getItem();
item.setFluidStack( is, fluid );
@@ -77,7 +77,7 @@ public class FluidCellConfig extends CellConfig
return;
}
fluid.amount = Fluid.BUCKET_VOLUME;
fluid.amount = FluidAttributes.BUCKET_VOLUME;
ItemStack is = Api.INSTANCE.definitions().items().dummyFluidItem().maybeStack( 1 ).get();
FluidDummyItem item = (FluidDummyItem) is.getItem();
item.setFluidStack( is, fluid );
@@ -96,7 +96,7 @@ public class FluidCellConfig extends CellConfig
{
return false;
}
fluid.amount = Fluid.BUCKET_VOLUME;
fluid.amount = FluidAttributes.BUCKET_VOLUME;
ItemStack is = Api.INSTANCE.definitions().items().dummyFluidItem().maybeStack( 1 ).get();
FluidDummyItem item = (FluidDummyItem) is.getItem();
item.setFluidStack( is, fluid );
@@ -19,12 +19,12 @@
package appeng.fluids.items;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.fluid.Fluids;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.util.NonNullList;
import net.minecraft.fluid.Fluid;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidAttributes;
import net.minecraftforge.fluids.FluidStack;
import appeng.items.AEBaseItem;
@@ -39,16 +39,19 @@ import appeng.items.AEBaseItem;
*/
public class FluidDummyItem extends AEBaseItem
{
@Override
public String getItemStackDisplayName( ItemStack stack )
{
public FluidDummyItem(Properties properties) {
super(properties);
}
@Override
public String getTranslationKey(ItemStack stack) {
FluidStack fluidStack = this.getFluidStack( stack );
if( fluidStack == null )
{
fluidStack = new FluidStack( FluidRegistry.WATER, Fluid.BUCKET_VOLUME );
fluidStack = new FluidStack( Fluids.WATER, FluidAttributes.BUCKET_VOLUME );
}
return fluidStack.getLocalizedName();
return fluidStack.getTranslationKey();
}
public FluidStack getFluidStack( ItemStack is )
@@ -65,19 +68,18 @@ public class FluidDummyItem extends AEBaseItem
{
if( fs == null )
{
is.setTagCompound( null );
is.setTag( null );
}
else
{
CompoundNBT tag = new CompoundNBT();
fs.writeToNBT( tag );
is.setTagCompound( tag );
is.setTag( tag );
}
}
@Override
protected void getCheckedSubItems( final CreativeTabs creativeTab, final NonNullList<ItemStack> itemStacks )
{
public void fillItemGroup(ItemGroup group, NonNullList<ItemStack> items) {
// Don't show this item in CreativeTabs
}
}
@@ -107,7 +107,7 @@ public class PartFluidFormationPlane extends PartAbstractFormationPlane<IAEFluid
@Override
public IAEFluidStack injectItems( IAEFluidStack input, Actionable type, IActionSource src )
{
if( this.blocked || input == null || input.getStackSize() < Fluid.BUCKET_VOLUME )
if( this.blocked || input == null || input.getStackSize() < FluidAttributes.BUCKET_VOLUME )
{
// need a full bucket
return input;
@@ -124,16 +124,16 @@ public class PartFluidFormationPlane extends PartAbstractFormationPlane<IAEFluid
if( type == Actionable.MODULATE )
{
final FluidStack fs = input.getFluidStack();
fs.amount = Fluid.BUCKET_VOLUME;
fs.amount = FluidAttributes.BUCKET_VOLUME;
final FluidTank tank = new FluidTank( fs, Fluid.BUCKET_VOLUME );
final FluidTank tank = new FluidTank( fs, FluidAttributes.BUCKET_VOLUME );
if( !FluidUtil.tryPlaceFluid( null, w, pos, tank, fs ) )
{
return input;
}
}
final IAEFluidStack ret = input.copy();
ret.setStackSize( input.getStackSize() - Fluid.BUCKET_VOLUME );
ret.setStackSize( input.getStackSize() - FluidAttributes.BUCKET_VOLUME );
return ret.getStackSize() == 0 ? null : ret;
}
this.blocked = true;
@@ -6,25 +6,25 @@ import java.util.Objects;
import net.minecraft.nbt.CompoundNBT;
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 javax.annotation.Nonnull;
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 )
public AEFluidInventory( final IAEFluidInventory handler, final int slots, final int capacity )
{
this.fluids = new IAEFluidStack[slots];
this.handler = handler;
this.capacity = capcity;
this.capacity = capacity;
}
public AEFluidInventory( final IAEFluidInventory handler, final int slots )
@@ -87,34 +87,47 @@ public class AEFluidInventory implements IAEFluidTank
}
@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;
public int getTanks() {
return this.fluids.length;
}
public int fill( final int slot, final FluidStack resource, final boolean doFill )
{
if( resource == null || resource.amount <= 0 )
@Nonnull
@Override
public FluidStack getFluidInTank(int tank) {
if (tank < 0 || tank >= fluids.length) {
return FluidStack.EMPTY;
}
return fluids[tank] == null ? FluidStack.EMPTY : fluids[tank].getFluidStack();
}
@Override
public int getTankCapacity(int tank) {
return Math.min( this.capacity, Integer.MAX_VALUE );
}
@Override
public boolean isFluidValid(int tank, @Nonnull FluidStack stack) {
return stack != FluidStack.EMPTY;
}
@Override
public int fill(FluidStack resource, FluidAction action) {
if( resource == null || resource == FluidStack.EMPTY || resource.getAmount() <= 0 )
{
return 0;
}
// Find a suitable slot
int slot = indexOfFluid(resource);
if (slot == -1) {
slot = indexOfEmptySlot();
if (slot == -1) {
return 0;
}
}
final IAEFluidStack fluid = this.fluids[slot];
if( fluid != null && !fluid.equals( resource ) )
{
return 0;
}
int amountToStore = this.capacity;
if( fluid != null )
@@ -122,9 +135,9 @@ public class AEFluidInventory implements IAEFluidTank
amountToStore -= fluid.getStackSize();
}
amountToStore = Math.min( amountToStore, resource.amount );
amountToStore = Math.min( amountToStore, resource.getAmount() );
if( doFill )
if( action == FluidAction.EXECUTE )
{
if( fluid == null )
{
@@ -140,6 +153,100 @@ public class AEFluidInventory implements IAEFluidTank
return amountToStore;
}
@Override
public FluidStack drain( final FluidStack fluid, final FluidAction action )
{
if( fluid == null || fluid.getAmount() <= 0 )
{
return null;
}
final FluidStack resource = fluid.copy();
FluidStack totalDrained = null;
for( int slot = 0; slot < this.getSlots(); ++slot )
{
FluidStack drain = this.drain( slot, resource, action == FluidAction.EXECUTE );
if( drain != null )
{
if( totalDrained == null )
{
totalDrained = drain;
}
else
{
totalDrained.setAmount(totalDrained.getAmount() + drain.getAmount());
}
resource.setAmount(resource.getAmount() - drain.getAmount());
if( resource.getAmount() <= 0 )
{
break;
}
}
}
return totalDrained;
}
@Override
public FluidStack drain( final int maxDrain, final FluidAction action )
{
if( maxDrain == 0 )
{
return null;
}
FluidStack totalDrained = null;
int toDrain = maxDrain;
for( int slot = 0; slot < this.getSlots(); ++slot )
{
if( totalDrained == null )
{
totalDrained = this.drain( slot, toDrain, action == FluidAction.EXECUTE );
if( totalDrained != null )
{
toDrain -= totalDrained.getAmount();
}
}
else
{
FluidStack copy = totalDrained.copy();
copy.setAmount(toDrain);
FluidStack drain = this.drain( slot, copy, action == FluidAction.EXECUTE );
if( drain != null )
{
totalDrained.setAmount(totalDrained.getAmount() + drain.getAmount());
toDrain -= drain.getAmount();
}
}
if( toDrain <= 0 )
{
break;
}
}
return totalDrained;
}
private int indexOfFluid(FluidStack resource) {
for (int slot = 0; slot < fluids.length; slot++) {
if (fluids[slot] != null && fluids[slot].getFluidStack().isFluidEqual(resource)) {
return slot;
}
}
return -1;
}
private int indexOfEmptySlot() {
for (int slot = 0; slot < fluids.length; slot++) {
if (fluids[slot] == null) {
return slot;
}
}
return -1;
}
public FluidStack drain( final int slot, final FluidStack resource, final boolean doDrain )
{
final IAEFluidStack fluid = this.fluids[slot];
@@ -147,7 +254,7 @@ public class AEFluidInventory implements IAEFluidTank
{
return null;
}
return this.drain( slot, resource.amount, doDrain );
return this.drain( slot, resource.getAmount(), doDrain );
}
public FluidStack drain( final int slot, final int maxDrain, boolean doDrain )
@@ -177,111 +284,11 @@ public class AEFluidInventory implements IAEFluidTank
return stack;
}
@Override
public int fill( final FluidStack fluid, final boolean doFill )
{
if( fluid == null || fluid.amount <= 0 )
{
return 0;
}
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;
}
@Override
public FluidStack drain( final FluidStack fluid, final boolean doDrain )
{
if( fluid == null || fluid.amount <= 0 )
{
return null;
}
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;
}
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;
}
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;
}
}
if( toDrain <= 0 )
{
break;
}
}
return totalDrained;
}
public void writeToNBT( final CompoundNBT data, final String name )
{
final CompoundNBT c = new CompoundNBT();
this.writeToNBT( c );
data.setTag( name, c );
data.put( name, c );
}
private void writeToNBT( final CompoundNBT target )
@@ -297,7 +304,7 @@ public class AEFluidInventory implements IAEFluidTank
this.fluids[x].writeToNBT( c );
}
target.setTag( "#" + x, c );
target.put( "#" + x, c );
}
catch( final Exception ignored )
{
@@ -307,8 +314,8 @@ public class AEFluidInventory implements IAEFluidTank
public void readFromNBT( final CompoundNBT data, final String name )
{
final CompoundNBT c = data.getCompoundTag( name );
if( c != null )
final CompoundNBT c = data.getCompound( name );
if( !c.isEmpty() )
{
this.readFromNBT( c );
}
@@ -320,9 +327,9 @@ public class AEFluidInventory implements IAEFluidTank
{
try
{
final CompoundNBT c = target.getCompoundTag( "#" + x );
final CompoundNBT c = target.getCompound( "#" + x );
if( c != null )
if( !c.isEmpty() )
{
this.fluids[x] = AEFluidStack.fromNBT( c );
}
@@ -334,49 +341,4 @@ public class AEFluidInventory implements IAEFluidTank
}
}
private class FluidTankPropertiesWrapper implements IFluidTankProperties
{
private final int 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 int getCapacity()
{
return Math.min( AEFluidInventory.this.capacity, Integer.MAX_VALUE );
}
@Override
public boolean canFill()
{
return true;
}
@Override
public boolean canDrain()
{
return true;
}
@Override
public boolean canFillFluidType( FluidStack fluidStack )
{
return true;
}
@Override
public boolean canDrainFluidType( FluidStack fluidStack )
{
return fluidStack != null;
}
}
}
@@ -24,6 +24,7 @@ import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import javax.annotation.Nonnull;
@@ -36,7 +37,6 @@ import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.network.PacketBuffer;
import net.minecraftforge.fluids.FluidStack;
import appeng.api.AEApi;
import appeng.api.config.FuzzyMode;
import appeng.api.storage.IStorageChannel;
import appeng.api.storage.channels.IFluidStorageChannel;
@@ -134,8 +134,8 @@ public final class AEFluidStack extends AEStack<IAEFluidStack> implements IAEFlu
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.putString( "FluidName", new String( name, "UTF-8" ) );
d.putByte( "Count", (byte) 0 );
if( hasTagCompound )
{
@@ -145,7 +145,7 @@ public final class AEFluidStack extends AEStack<IAEFluidStack> implements IAEFlu
buffer.readBytes( bd );
final DataInputStream di = new DataInputStream( new ByteArrayInputStream( bd ) );
d.setTag( "Tag", CompressedStreamTools.read( di ) );
d.put( "Tag", CompressedStreamTools.read( di ) );
}
final long stackSize = getPacketValue( stackType, buffer );
@@ -181,19 +181,19 @@ public final class AEFluidStack extends AEStack<IAEFluidStack> implements IAEFlu
@Override
public void writeToNBT( final CompoundNBT 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() );
data.putString( "FluidName", this.fluid.getRegistryName().toString() );
data.putByte( "Count", (byte) 0 );
data.putLong( "Cnt", this.getStackSize() );
data.putLong( "Req", this.getCountRequestable() );
data.putBoolean( "Craft", this.isCraftable() );
if( this.hasTagCompound() )
{
data.setTag( "Tag", this.tagCompound );
data.put( "Tag", this.tagCompound );
}
else
{
data.removeTag( "Tag" );
data.remove( "Tag" );
}
}
@@ -240,7 +240,7 @@ public final class AEFluidStack extends AEStack<IAEFluidStack> implements IAEFlu
{
if( this.fluid != other.fluid )
{
return this.fluid.getName().compareTo( other.fluid.getName() );
return this.fluid.getRegistryName().compareTo( other.fluid.getRegistryName() );
}
if( Platform.itemComparisons().isNbtTagEqual( this.tagCompound, other.tagCompound ) )
@@ -273,7 +273,7 @@ public final class AEFluidStack extends AEStack<IAEFluidStack> implements IAEFlu
else if( other instanceof FluidStack )
{
final FluidStack is = (FluidStack) other;
return is.getFluid() == this.fluid && Platform.itemComparisons().isNbtTagEqual( this.tagCompound, is.tag );
return is.getFluid() == this.fluid && Platform.itemComparisons().isNbtTagEqual( this.tagCompound, is.getTag() );
}
return false;
}
@@ -281,7 +281,7 @@ public final class AEFluidStack extends AEStack<IAEFluidStack> implements IAEFlu
@Override
public String toString()
{
return this.getStackSize() + "x" + this.getFluidStack().getFluid().getName() + " " + this.tagCompound;
return this.getStackSize() + "x" + this.getFluidStack().getFluid().getRegistryName() + " " + this.tagCompound;
}
@Override
@@ -334,7 +334,7 @@ public final class AEFluidStack extends AEStack<IAEFluidStack> implements IAEFlu
private void writeToStream( final PacketBuffer buffer ) throws IOException
{
final byte[] name = this.fluid.getName().getBytes( "UTF-8" );
final byte[] name = this.fluid.getRegistryName().toString().getBytes(StandardCharsets.UTF_8);
buffer.writeByte( (byte) name.length );
buffer.writeBytes( name );
if( this.hasTagCompound() )
@@ -19,11 +19,9 @@
package appeng.fluids.util;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.fluids.FluidTank;
import appeng.api.storage.data.IAEFluidStack;
import appeng.util.Platform;
import net.minecraftforge.fluids.capability.templates.FluidTank;
public class AEFluidTank extends FluidTank implements IAEFluidTank
@@ -34,10 +32,10 @@ public class AEFluidTank extends FluidTank implements IAEFluidTank
{
super( capacity );
this.host = host;
if( host instanceof TileEntity )
{
this.setTileEntity( (TileEntity) host );
}
// FIXME if( host instanceof TileEntity )
// FIXME {
// FIXME this.setTileEntity( (TileEntity) host );
// FIXME }
}
@Override