reformatted all src files (#141)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user