pick 97420a31d The big reformat of 2020

This commit is contained in:
yueh
2020-06-16 21:41:28 +02:00
parent 5304b3febe
commit 5225ea426b
2252 changed files with 95466 additions and 118582 deletions
@@ -1,9 +1,10 @@
package appeng.fluids.util;
import java.util.Objects;
import javax.annotation.Nonnull;
import net.minecraft.nbt.CompoundNBT;
import net.minecraftforge.fluids.FluidStack;
@@ -11,373 +12,300 @@ import appeng.api.storage.data.IAEFluidStack;
import appeng.core.AELog;
import appeng.util.Platform;
import javax.annotation.Nonnull;
public class AEFluidInventory implements IAEFluidTank {
private final IAEFluidStack[] fluids;
private final IAEFluidInventory handler;
private final int capacity;
public AEFluidInventory(final IAEFluidInventory handler, final int slots, final int capacity) {
this.fluids = new IAEFluidStack[slots];
this.handler = handler;
this.capacity = capacity;
}
public class AEFluidInventory implements IAEFluidTank
{
private final IAEFluidStack[] fluids;
private final IAEFluidInventory handler;
private final int capacity;
public AEFluidInventory(final IAEFluidInventory handler, final int slots) {
this(handler, slots, Integer.MAX_VALUE);
}
public AEFluidInventory( final IAEFluidInventory handler, final int slots, final int capacity )
{
this.fluids = new IAEFluidStack[slots];
this.handler = handler;
this.capacity = capacity;
}
@Override
public void setFluidInSlot(final int slot, final IAEFluidStack fluid) {
if (slot >= 0 && slot < this.getSlots()) {
if (Objects.equals(this.fluids[slot], fluid)) {
if (fluid != null && fluid.getStackSize() != this.fluids[slot].getStackSize()) {
this.fluids[slot].setStackSize(Math.min(fluid.getStackSize(), this.capacity));
this.onContentChanged(slot);
}
} else {
if (fluid == null) {
this.fluids[slot] = null;
} else {
this.fluids[slot] = fluid.copy();
this.fluids[slot].setStackSize(Math.min(fluid.getStackSize(), this.capacity));
}
public AEFluidInventory( final IAEFluidInventory handler, final int slots )
{
this( handler, slots, Integer.MAX_VALUE );
}
this.onContentChanged(slot);
}
}
}
@Override
public void setFluidInSlot( final int slot, final IAEFluidStack fluid )
{
if( slot >= 0 && slot < this.getSlots() )
{
if( Objects.equals( this.fluids[slot], fluid ) )
{
if( fluid != null && fluid.getStackSize() != this.fluids[slot].getStackSize() )
{
this.fluids[slot].setStackSize( Math.min( fluid.getStackSize(), this.capacity ) );
this.onContentChanged( slot );
}
}
else
{
if( fluid == null )
{
this.fluids[slot] = null;
}
else
{
this.fluids[slot] = fluid.copy();
this.fluids[slot].setStackSize( Math.min( fluid.getStackSize(), this.capacity ) );
}
private void onContentChanged(final int slot) {
if (this.handler != null && Platform.isServer()) {
this.handler.onFluidInventoryChanged(this, slot);
}
}
this.onContentChanged( slot );
}
}
}
@Override
public IAEFluidStack getFluidInSlot(final int slot) {
if (slot >= 0 && slot < this.getSlots()) {
return this.fluids[slot];
}
return null;
}
private void onContentChanged( final int slot )
{
if( this.handler != null && Platform.isServer() )
{
this.handler.onFluidInventoryChanged( this, slot );
}
}
@Override
public int getSlots() {
return this.fluids.length;
}
@Override
public IAEFluidStack getFluidInSlot( final int slot )
{
if( slot >= 0 && slot < this.getSlots() )
{
return this.fluids[slot];
}
return null;
}
@Override
public int getTanks() {
return this.fluids.length;
}
@Override
public int getSlots()
{
return this.fluids.length;
}
@Nonnull
@Override
public FluidStack getFluidInTank(int tank) {
if (tank < 0 || tank >= fluids.length) {
return FluidStack.EMPTY;
}
return fluids[tank] == null ? FluidStack.EMPTY : fluids[tank].getFluidStack();
}
@Override
public int getTanks() {
return this.fluids.length;
}
@Override
public int getTankCapacity(int tank) {
return Math.min(this.capacity, Integer.MAX_VALUE);
}
@Nonnull
@Override
public FluidStack getFluidInTank(int tank) {
if (tank < 0 || tank >= fluids.length) {
return FluidStack.EMPTY;
}
return fluids[tank] == null ? FluidStack.EMPTY : fluids[tank].getFluidStack();
}
@Override
public boolean isFluidValid(int tank, @Nonnull FluidStack stack) {
return stack != FluidStack.EMPTY;
}
@Override
public int getTankCapacity(int tank) {
return Math.min( this.capacity, Integer.MAX_VALUE );
}
public int fill(final int slot, final FluidStack resource, final boolean doFill) {
if (resource.isEmpty() || resource.getAmount() <= 0) {
return 0;
}
@Override
public boolean isFluidValid(int tank, @Nonnull FluidStack stack) {
return stack != FluidStack.EMPTY;
}
final IAEFluidStack fluid = this.fluids[slot];
public int fill( final int slot, final FluidStack resource, final boolean doFill )
{
if( resource.isEmpty()|| resource.getAmount() <= 0 )
{
return 0;
}
if (fluid != null && !fluid.getFluidStack().equals(resource)) {
return 0;
}
final IAEFluidStack fluid = this.fluids[slot];
int amountToStore = this.capacity;
if( fluid != null && !fluid.getFluidStack().equals( resource ) )
{
return 0;
}
if (fluid != null) {
amountToStore -= fluid.getStackSize();
}
int amountToStore = this.capacity;
amountToStore = Math.min(amountToStore, resource.getAmount());
if( fluid != null )
{
amountToStore -= fluid.getStackSize();
}
if (doFill) {
if (fluid == null) {
this.setFluidInSlot(slot, AEFluidStack.fromFluidStack(resource));
} else {
fluid.setStackSize(fluid.getStackSize() + amountToStore);
this.onContentChanged(slot);
}
}
amountToStore = Math.min( amountToStore, resource.getAmount() );
return amountToStore;
}
if( doFill )
{
if( fluid == null )
{
this.setFluidInSlot( slot, AEFluidStack.fromFluidStack( resource ) );
}
else
{
fluid.setStackSize( fluid.getStackSize() + amountToStore );
this.onContentChanged( slot );
}
}
@Override
public int fill(FluidStack resource, FluidAction action) {
if (resource == null || resource.isEmpty() || resource.getAmount() <= 0) {
return 0;
}
return amountToStore;
}
// Find a suitable slot
int slot = indexOfFluid(resource);
if (slot == -1) {
slot = indexOfEmptySlot();
if (slot == -1) {
return 0;
}
}
@Override
public int fill(FluidStack resource, FluidAction action) {
if( resource == null || resource.isEmpty() || resource.getAmount() <= 0 )
{
return 0;
}
final IAEFluidStack fluid = this.fluids[slot];
// Find a suitable slot
int slot = indexOfFluid(resource);
if (slot == -1) {
slot = indexOfEmptySlot();
if (slot == -1) {
return 0;
}
}
int amountToStore = this.capacity;
final IAEFluidStack fluid = this.fluids[slot];
if (fluid != null) {
amountToStore -= fluid.getStackSize();
}
int amountToStore = this.capacity;
amountToStore = Math.min(amountToStore, resource.getAmount());
if( fluid != null )
{
amountToStore -= fluid.getStackSize();
}
if (action == FluidAction.EXECUTE) {
if (fluid == null) {
this.setFluidInSlot(slot, AEFluidStack.fromFluidStack(resource));
} else {
fluid.setStackSize(fluid.getStackSize() + amountToStore);
this.onContentChanged(slot);
}
}
amountToStore = Math.min( amountToStore, resource.getAmount() );
return amountToStore;
}
if( action == FluidAction.EXECUTE )
{
if( fluid == null )
{
this.setFluidInSlot( slot, AEFluidStack.fromFluidStack( resource ) );
}
else
{
fluid.setStackSize( fluid.getStackSize() + amountToStore );
this.onContentChanged( slot );
}
}
@Override
public FluidStack drain(final FluidStack fluid, final FluidAction action) {
if (fluid == null || fluid.getAmount() <= 0) {
return FluidStack.EMPTY;
}
return amountToStore;
}
final FluidStack resource = fluid.copy();
@Override
public FluidStack drain( final FluidStack fluid, final FluidAction action )
{
if( fluid == null || fluid.getAmount() <= 0 )
{
return FluidStack.EMPTY;
}
FluidStack totalDrained = FluidStack.EMPTY;
for (int slot = 0; slot < this.getSlots(); ++slot) {
FluidStack drain = this.drain(slot, resource, action == FluidAction.EXECUTE);
if (drain != null) {
if (totalDrained.isEmpty()) {
totalDrained = drain;
} else {
totalDrained.setAmount(totalDrained.getAmount() + drain.getAmount());
}
final FluidStack resource = fluid.copy();
resource.setAmount(resource.getAmount() - drain.getAmount());
if (resource.getAmount() <= 0) {
break;
}
}
}
return totalDrained;
}
FluidStack totalDrained = FluidStack.EMPTY;
for( int slot = 0; slot < this.getSlots(); ++slot )
{
FluidStack drain = this.drain( slot, resource, action == FluidAction.EXECUTE );
if( drain != null )
{
if( totalDrained.isEmpty() )
{
totalDrained = drain;
}
else
{
totalDrained.setAmount(totalDrained.getAmount() + drain.getAmount());
}
@Override
public FluidStack drain(final int maxDrain, final FluidAction action) {
if (maxDrain == 0) {
return FluidStack.EMPTY;
}
resource.setAmount(resource.getAmount() - drain.getAmount());
if( resource.getAmount() <= 0 )
{
break;
}
}
}
return totalDrained;
}
FluidStack totalDrained = FluidStack.EMPTY;
int toDrain = maxDrain;
@Override
public FluidStack drain( final int maxDrain, final FluidAction action )
{
if( maxDrain == 0 )
{
return FluidStack.EMPTY;
}
for (int slot = 0; slot < this.getSlots(); ++slot) {
if (totalDrained.isEmpty()) {
totalDrained = this.drain(slot, toDrain, action == FluidAction.EXECUTE);
if (totalDrained.isEmpty()) {
toDrain -= totalDrained.getAmount();
}
} else {
FluidStack copy = totalDrained.copy();
copy.setAmount(toDrain);
FluidStack drain = this.drain(slot, copy, action == FluidAction.EXECUTE);
if (drain != null) {
totalDrained.setAmount(totalDrained.getAmount() + drain.getAmount());
toDrain -= drain.getAmount();
}
}
FluidStack totalDrained = FluidStack.EMPTY;
int toDrain = maxDrain;
if (toDrain <= 0) {
break;
}
}
return totalDrained;
}
for( int slot = 0; slot < this.getSlots(); ++slot )
{
if( totalDrained.isEmpty() )
{
totalDrained = this.drain( slot, toDrain, action == FluidAction.EXECUTE );
if( totalDrained.isEmpty() )
{
toDrain -= totalDrained.getAmount();
}
}
else
{
FluidStack copy = totalDrained.copy();
copy.setAmount(toDrain);
FluidStack drain = this.drain( slot, copy, action == FluidAction.EXECUTE );
if( drain != null )
{
totalDrained.setAmount(totalDrained.getAmount() + drain.getAmount());
toDrain -= drain.getAmount();
}
}
private int indexOfFluid(FluidStack resource) {
for (int slot = 0; slot < fluids.length; slot++) {
if (fluids[slot] != null && fluids[slot].getFluidStack().isFluidEqual(resource)) {
return slot;
}
}
return -1;
}
if( toDrain <= 0 )
{
break;
}
}
return totalDrained;
}
private int indexOfEmptySlot() {
for (int slot = 0; slot < fluids.length; slot++) {
if (fluids[slot] == null) {
return slot;
}
}
return -1;
}
private int indexOfFluid(FluidStack resource) {
for (int slot = 0; slot < fluids.length; slot++) {
if (fluids[slot] != null && fluids[slot].getFluidStack().isFluidEqual(resource)) {
return slot;
}
}
return -1;
}
public FluidStack drain(final int slot, final FluidStack resource, final boolean doDrain) {
final IAEFluidStack fluid = this.fluids[slot];
if (resource.isEmpty() || fluid == null || !fluid.getFluidStack().equals(resource)) {
return null;
}
return this.drain(slot, resource.getAmount(), doDrain);
}
private int indexOfEmptySlot() {
for (int slot = 0; slot < fluids.length; slot++) {
if (fluids[slot] == null) {
return slot;
}
}
return -1;
}
public FluidStack drain(final int slot, final int maxDrain, boolean doDrain) {
final IAEFluidStack fluid = this.fluids[slot];
if (fluid == null || maxDrain <= 0) {
return null;
}
public FluidStack drain( final int slot, final FluidStack resource, final boolean doDrain )
{
final IAEFluidStack fluid = this.fluids[slot];
if( resource.isEmpty() || fluid == null || !fluid.getFluidStack().equals( resource ) )
{
return null;
}
return this.drain( slot, resource.getAmount(), doDrain );
}
int drained = maxDrain;
if (fluid.getStackSize() < drained) {
drained = (int) fluid.getStackSize();
}
public FluidStack drain( final int slot, final int maxDrain, boolean doDrain )
{
final IAEFluidStack fluid = this.fluids[slot];
if( fluid == null || maxDrain <= 0 )
{
return null;
}
FluidStack stack = new FluidStack(fluid.getFluid(), drained);
if (doDrain) {
fluid.setStackSize(fluid.getStackSize() - drained);
if (fluid.getStackSize() <= 0) {
this.fluids[slot] = null;
}
this.onContentChanged(slot);
}
return stack;
}
int drained = maxDrain;
if( fluid.getStackSize() < drained )
{
drained = (int) fluid.getStackSize();
}
public void writeToNBT(final CompoundNBT data, final String name) {
final CompoundNBT c = new CompoundNBT();
this.writeToNBT(c);
data.put(name, c);
}
FluidStack stack = new FluidStack( fluid.getFluid(), drained );
if( doDrain )
{
fluid.setStackSize( fluid.getStackSize() - drained );
if( fluid.getStackSize() <= 0 )
{
this.fluids[slot] = null;
}
this.onContentChanged( slot );
}
return stack;
}
private void writeToNBT(final CompoundNBT target) {
for (int x = 0; x < this.fluids.length; x++) {
try {
final CompoundNBT c = new CompoundNBT();
public void writeToNBT( final CompoundNBT data, final String name )
{
final CompoundNBT c = new CompoundNBT();
this.writeToNBT( c );
data.put( name, c );
}
if (this.fluids[x] != null) {
this.fluids[x].writeToNBT(c);
}
private void writeToNBT( final CompoundNBT target )
{
for( int x = 0; x < this.fluids.length; x++ )
{
try
{
final CompoundNBT c = new CompoundNBT();
target.put("#" + x, c);
} catch (final Exception ignored) {
}
}
}
if( this.fluids[x] != null )
{
this.fluids[x].writeToNBT( c );
}
public void readFromNBT(final CompoundNBT data, final String name) {
final CompoundNBT c = data.getCompound(name);
if (!c.isEmpty()) {
this.readFromNBT(c);
}
}
target.put( "#" + x, c );
}
catch( final Exception ignored )
{
}
}
}
private void readFromNBT(final CompoundNBT target) {
for (int x = 0; x < this.fluids.length; x++) {
try {
final CompoundNBT c = target.getCompound("#" + x);
public void readFromNBT( final CompoundNBT data, final String name )
{
final CompoundNBT c = data.getCompound( name );
if( !c.isEmpty() )
{
this.readFromNBT( c );
}
}
private void readFromNBT( final CompoundNBT target )
{
for( int x = 0; x < this.fluids.length; x++ )
{
try
{
final CompoundNBT c = target.getCompound( "#" + x );
if( !c.isEmpty() )
{
this.fluids[x] = AEFluidStack.fromNBT( c );
}
}
catch( final Exception e )
{
AELog.debug( e );
}
}
}
if (!c.isEmpty()) {
this.fluids[x] = AEFluidStack.fromNBT(c);
}
} catch (final Exception e) {
AELog.debug(e);
}
}
}
}
+176 -217
View File
@@ -18,7 +18,6 @@
package appeng.fluids.util;
import javax.annotation.Nonnull;
import net.minecraft.fluid.Fluid;
@@ -36,261 +35,221 @@ import appeng.fluids.items.FluidDummyItem;
import appeng.util.Platform;
import appeng.util.item.AEStack;
public final class AEFluidStack extends AEStack<IAEFluidStack> implements IAEFluidStack, Comparable<AEFluidStack> {
private static final String NBT_STACKSIZE = "cnt";
private static final String NBT_REQUESTABLE = "req";
private static final String NBT_CRAFTABLE = "craft";
private static final String NBT_FLUIDSTACK = "fs";
public final class AEFluidStack extends AEStack<IAEFluidStack> implements IAEFluidStack, Comparable<AEFluidStack>
{
private static final String NBT_STACKSIZE = "cnt";
private static final String NBT_REQUESTABLE = "req";
private static final String NBT_CRAFTABLE = "craft";
private static final String NBT_FLUIDSTACK = "fs";
private final Fluid fluid;
private CompoundNBT tagCompound;
private final Fluid fluid;
private CompoundNBT tagCompound;
private AEFluidStack(final AEFluidStack fluidStack) {
this.fluid = fluidStack.fluid;
this.setStackSize(fluidStack.getStackSize());
private AEFluidStack( final AEFluidStack fluidStack )
{
this.fluid = fluidStack.fluid;
this.setStackSize( fluidStack.getStackSize() );
// priority = is.priority;
this.setCraftable(fluidStack.isCraftable());
this.setCountRequestable(fluidStack.getCountRequestable());
// priority = is.priority;
this.setCraftable( fluidStack.isCraftable() );
this.setCountRequestable( fluidStack.getCountRequestable() );
if (fluidStack.hasTagCompound()) {
this.tagCompound = fluidStack.tagCompound.copy();
}
}
if( fluidStack.hasTagCompound() )
{
this.tagCompound = fluidStack.tagCompound.copy();
}
}
private AEFluidStack(@Nonnull final FluidStack fluidStack) {
this.fluid = fluidStack.getFluid();
private AEFluidStack( @Nonnull final FluidStack fluidStack )
{
this.fluid = fluidStack.getFluid();
if (this.fluid == null) {
throw new IllegalArgumentException("Fluid is null.");
}
if( this.fluid == null )
{
throw new IllegalArgumentException( "Fluid is null." );
}
this.setStackSize(fluidStack.getAmount());
this.setCraftable(false);
this.setCountRequestable(0);
this.setStackSize( fluidStack.getAmount() );
this.setCraftable( false );
this.setCountRequestable( 0 );
if (fluidStack.getTag() != null) {
this.tagCompound = fluidStack.getTag().copy();
}
}
if( fluidStack.getTag() != null )
{
this.tagCompound = fluidStack.getTag().copy();
}
}
public static AEFluidStack fromFluidStack(final FluidStack input) {
if (input == null) {
return null;
}
public static AEFluidStack fromFluidStack( final FluidStack input )
{
if( input == null )
{
return null;
}
return new AEFluidStack(input);
}
return new AEFluidStack( input );
}
public static IAEFluidStack fromNBT(final CompoundNBT data) {
final FluidStack fluidStack = FluidStack.loadFluidStackFromNBT(data.getCompound(NBT_FLUIDSTACK));
public static IAEFluidStack fromNBT( final CompoundNBT data )
{
final FluidStack fluidStack = FluidStack.loadFluidStackFromNBT( data.getCompound( NBT_FLUIDSTACK ) );
if (fluidStack == null) {
return null;
}
if( fluidStack == null )
{
return null;
}
final AEFluidStack fluid = AEFluidStack.fromFluidStack(fluidStack);
fluid.setStackSize(data.getLong(NBT_STACKSIZE));
fluid.setCountRequestable(data.getLong(NBT_REQUESTABLE));
fluid.setCraftable(data.getBoolean(NBT_CRAFTABLE));
final AEFluidStack fluid = AEFluidStack.fromFluidStack( fluidStack );
fluid.setStackSize( data.getLong( NBT_STACKSIZE ) );
fluid.setCountRequestable( data.getLong( NBT_REQUESTABLE ) );
fluid.setCraftable( data.getBoolean( NBT_CRAFTABLE ) );
if (fluid.hasTagCompound()) {
fluid.tagCompound = fluid.tagCompound.copy();
}
if( fluid.hasTagCompound() )
{
fluid.tagCompound = fluid.tagCompound.copy();
}
return fluid;
}
return fluid;
}
@Override
public void add(final IAEFluidStack option) {
if (option == null) {
return;
}
this.incStackSize(option.getStackSize());
this.setCountRequestable(this.getCountRequestable() + option.getCountRequestable());
this.setCraftable(this.isCraftable() || option.isCraftable());
}
@Override
public void add( final IAEFluidStack option )
{
if( option == null )
{
return;
}
this.incStackSize( option.getStackSize() );
this.setCountRequestable( this.getCountRequestable() + option.getCountRequestable() );
this.setCraftable( this.isCraftable() || option.isCraftable() );
}
@Override
public void writeToNBT(final CompoundNBT data) {
data.getCompound(NBT_FLUIDSTACK).putString("FluidName", this.fluid.getRegistryName().toString());
data.getCompound(NBT_FLUIDSTACK).putInt("Amount", 0);
if (this.hasTagCompound()) {
data.getCompound(NBT_FLUIDSTACK).put("Tag", this.tagCompound);
} else {
data.getCompound(NBT_FLUIDSTACK).remove("Tag");
}
@Override
public void writeToNBT( final CompoundNBT data )
{
data.getCompound( NBT_FLUIDSTACK ).putString( "FluidName", this.fluid.getRegistryName().toString() );
data.getCompound( NBT_FLUIDSTACK ).putInt( "Amount", 0 );
if( this.hasTagCompound() )
{
data.getCompound( NBT_FLUIDSTACK ).put( "Tag", this.tagCompound );
}
else
{
data.getCompound( NBT_FLUIDSTACK ).remove( "Tag" );
}
data.putLong(NBT_STACKSIZE, this.getStackSize());
data.putLong(NBT_REQUESTABLE, this.getCountRequestable());
data.putBoolean(NBT_CRAFTABLE, this.isCraftable());
}
data.putLong( NBT_STACKSIZE, this.getStackSize() );
data.putLong( NBT_REQUESTABLE, this.getCountRequestable() );
data.putBoolean( NBT_CRAFTABLE, this.isCraftable() );
}
@Override
public boolean fuzzyComparison(final IAEFluidStack other, final FuzzyMode mode) {
return this.fluid == other.getFluid();
}
@Override
public boolean fuzzyComparison( final IAEFluidStack other, final FuzzyMode mode )
{
return this.fluid == other.getFluid();
}
@Override
public IAEFluidStack copy() {
return new AEFluidStack(this);
}
@Override
public IAEFluidStack copy()
{
return new AEFluidStack( this );
}
@Override
public IAEFluidStack empty() {
final IAEFluidStack dup = this.copy();
dup.reset();
return dup;
}
@Override
public IAEFluidStack empty()
{
final IAEFluidStack dup = this.copy();
dup.reset();
return dup;
}
@Override
public boolean isItem() {
return false;
}
@Override
public boolean isItem()
{
return false;
}
@Override
public boolean isFluid() {
return true;
}
@Override
public boolean isFluid()
{
return true;
}
@Override
public IStorageChannel<IAEFluidStack> getChannel() {
return AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class);
}
@Override
public IStorageChannel<IAEFluidStack> getChannel()
{
return AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class );
}
@Override
public int compareTo(final AEFluidStack other) {
if (this.fluid != other.fluid) {
return this.fluid.getRegistryName().compareTo(other.fluid.getRegistryName());
}
@Override
public int compareTo( final AEFluidStack other )
{
if( this.fluid != other.fluid )
{
return this.fluid.getRegistryName().compareTo( other.fluid.getRegistryName() );
}
if (Platform.itemComparisons().isNbtTagEqual(this.tagCompound, other.tagCompound)) {
return 0;
}
if( Platform.itemComparisons().isNbtTagEqual( this.tagCompound, other.tagCompound ) )
{
return 0;
}
return this.tagCompound.hashCode() - other.tagCompound.hashCode();
}
return this.tagCompound.hashCode() - other.tagCompound.hashCode();
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((this.fluid == null) ? 0 : this.fluid.hashCode());
result = prime * result + ((this.tagCompound == null) ? 0 : this.tagCompound.hashCode());
@Override
public int hashCode()
{
final int prime = 31;
int result = 1;
result = prime * result + ( ( this.fluid == null ) ? 0 : this.fluid.hashCode() );
result = prime * result + ( ( this.tagCompound == null ) ? 0 : this.tagCompound.hashCode() );
return result;
}
return result;
}
@Override
public boolean equals(final Object other) {
if (other instanceof AEFluidStack) {
final AEFluidStack is = (AEFluidStack) other;
return is.fluid == this.fluid && Platform.itemComparisons().isNbtTagEqual(this.tagCompound, is.tagCompound);
} else if (other instanceof FluidStack) {
final FluidStack is = (FluidStack) other;
return is.getFluid() == this.fluid
&& Platform.itemComparisons().isNbtTagEqual(this.tagCompound, is.getTag());
}
return false;
}
@Override
public boolean equals( final Object other )
{
if( other instanceof AEFluidStack )
{
final AEFluidStack is = (AEFluidStack) other;
return is.fluid == this.fluid && Platform.itemComparisons().isNbtTagEqual( this.tagCompound, is.tagCompound );
}
else if( other instanceof FluidStack )
{
final FluidStack is = (FluidStack) other;
return is.getFluid() == this.fluid && Platform.itemComparisons().isNbtTagEqual( this.tagCompound, is.getTag() );
}
return false;
}
@Override
public String toString() {
return this.getStackSize() + "x" + this.getFluidStack().getFluid().getRegistryName() + " " + this.tagCompound;
}
@Override
public String toString()
{
return this.getStackSize() + "x" + this.getFluidStack().getFluid().getRegistryName() + " " + this.tagCompound;
}
@Override
public boolean hasTagCompound() {
return this.tagCompound != null;
}
@Override
public boolean hasTagCompound()
{
return this.tagCompound != null;
}
@Override
public FluidStack getFluidStack() {
final int amount = (int) Math.min(Integer.MAX_VALUE, this.getStackSize());
final FluidStack is = new FluidStack(this.fluid, amount, this.tagCompound);
@Override
public FluidStack getFluidStack()
{
final int amount = (int) Math.min( Integer.MAX_VALUE, this.getStackSize() );
final FluidStack is = new FluidStack( this.fluid, amount, this.tagCompound );
return is;
}
return is;
}
@Override
public Fluid getFluid() {
return this.fluid;
}
@Override
public Fluid getFluid()
{
return this.fluid;
}
@Override
public ItemStack asItemStackRepresentation() {
ItemStack is = AEApi.instance().definitions().items().dummyFluidItem().maybeStack(1).orElse(ItemStack.EMPTY);
if (!is.isEmpty()) {
FluidDummyItem item = (FluidDummyItem) is.getItem();
item.setFluidStack(is, this.getFluidStack());
return is;
}
return ItemStack.EMPTY;
}
@Override
public ItemStack asItemStackRepresentation()
{
ItemStack is = AEApi.instance().definitions().items().dummyFluidItem().maybeStack( 1 ).orElse( ItemStack.EMPTY );
if( !is.isEmpty() )
{
FluidDummyItem item = (FluidDummyItem) is.getItem();
item.setFluidStack( is, this.getFluidStack() );
return is;
}
return ItemStack.EMPTY;
}
public static IAEFluidStack fromPacket(final PacketBuffer buffer) {
final boolean isCraftable = buffer.readBoolean();
final FluidStack fluidStack = buffer.readFluidStack();
public static IAEFluidStack fromPacket( final PacketBuffer buffer )
{
final boolean isCraftable = buffer.readBoolean();
final FluidStack fluidStack = buffer.readFluidStack();
final long stackSize = buffer.readVarLong();
final long countRequestable = buffer.readVarLong();
final long stackSize = buffer.readVarLong();
final long countRequestable = buffer.readVarLong();
if (fluidStack == null) {
return null;
}
if( fluidStack == null )
{
return null;
}
final AEFluidStack fluid = AEFluidStack.fromFluidStack(fluidStack);
fluid.setStackSize(stackSize);
fluid.setCountRequestable(countRequestable);
fluid.setCraftable(isCraftable);
return fluid;
}
final AEFluidStack fluid = AEFluidStack.fromFluidStack( fluidStack );
fluid.setStackSize( stackSize );
fluid.setCountRequestable( countRequestable );
fluid.setCraftable( isCraftable );
return fluid;
}
@Override
public void writeToPacket( final PacketBuffer buffer )
{
buffer.writeBoolean( this.isCraftable() );
buffer.writeFluidStack( this.getFluidStack() );
buffer.writeVarLong( this.getStackSize() );
buffer.writeVarLong( this.getCountRequestable() );
}
@Override
public void writeToPacket(final PacketBuffer buffer) {
buffer.writeBoolean(this.isCraftable());
buffer.writeFluidStack(this.getFluidStack());
buffer.writeVarLong(this.getStackSize());
buffer.writeVarLong(this.getCountRequestable());
}
}
@@ -18,60 +18,50 @@
package appeng.fluids.util;
import net.minecraftforge.fluids.capability.templates.FluidTank;
import appeng.api.storage.data.IAEFluidStack;
import appeng.util.Platform;
import net.minecraftforge.fluids.capability.templates.FluidTank;
public class AEFluidTank extends FluidTank implements IAEFluidTank {
private final IAEFluidInventory host;
public class AEFluidTank extends FluidTank implements IAEFluidTank
{
private final IAEFluidInventory host;
public AEFluidTank( IAEFluidInventory host, int capacity )
{
super( capacity );
this.host = host;
public AEFluidTank(IAEFluidInventory host, int capacity) {
super(capacity);
this.host = host;
// FIXME if( host instanceof TileEntity )
// FIXME {
// FIXME this.setTileEntity( (TileEntity) host );
// FIXME }
}
}
@Override
protected void onContentsChanged()
{
if( this.host != null && Platform.isServer() )
{
this.host.onFluidInventoryChanged( this, 0 );
}
super.onContentsChanged();
}
@Override
protected void onContentsChanged() {
if (this.host != null && Platform.isServer()) {
this.host.onFluidInventoryChanged(this, 0);
}
super.onContentsChanged();
}
@Override
public void setFluidInSlot( int slot, IAEFluidStack fluid )
{
if( slot == 0 )
{
this.setFluid( fluid == null ? null : fluid.getFluidStack() );
this.onContentsChanged();
}
}
@Override
public void setFluidInSlot(int slot, IAEFluidStack fluid) {
if (slot == 0) {
this.setFluid(fluid == null ? null : fluid.getFluidStack());
this.onContentsChanged();
}
}
@Override
public IAEFluidStack getFluidInSlot( int slot )
{
if( slot == 0 )
{
return AEFluidStack.fromFluidStack( this.getFluid() );
}
return null;
}
@Override
public IAEFluidStack getFluidInSlot(int slot) {
if (slot == 0) {
return AEFluidStack.fromFluidStack(this.getFluid());
}
return null;
}
@Override
public int getSlots()
{
return 1;
}
@Override
public int getSlots() {
return 1;
}
}
+109 -136
View File
@@ -18,7 +18,6 @@
package appeng.fluids.util;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
@@ -29,173 +28,147 @@ import appeng.api.config.FuzzyMode;
import appeng.api.storage.data.IAEFluidStack;
import appeng.api.storage.data.IItemList;
public final class FluidList implements IItemList<IAEFluidStack> {
public final class FluidList implements IItemList<IAEFluidStack>
{
private final Map<IAEFluidStack, IAEFluidStack> records = new HashMap<>();
private final Map<IAEFluidStack, IAEFluidStack> records = new HashMap<>();
@Override
public void add(final IAEFluidStack option) {
if (option == null) {
return;
}
@Override
public void add( final IAEFluidStack option )
{
if( option == null )
{
return;
}
final IAEFluidStack st = this.getFluidRecord(option);
final IAEFluidStack st = this.getFluidRecord( option );
if (st != null) {
st.add(option);
return;
}
if( st != null )
{
st.add( option );
return;
}
final IAEFluidStack opt = option.copy();
final IAEFluidStack opt = option.copy();
this.putFluidRecord(opt);
}
this.putFluidRecord( opt );
}
@Override
public IAEFluidStack findPrecise(final IAEFluidStack fluidStack) {
if (fluidStack == null) {
return null;
}
@Override
public IAEFluidStack findPrecise( final IAEFluidStack fluidStack )
{
if( fluidStack == null )
{
return null;
}
return this.getFluidRecord(fluidStack);
}
return this.getFluidRecord( fluidStack );
}
@Override
public Collection<IAEFluidStack> findFuzzy(final IAEFluidStack filter, final FuzzyMode fuzzy) {
if (filter == null) {
return Collections.emptyList();
}
@Override
public Collection<IAEFluidStack> findFuzzy( final IAEFluidStack filter, final FuzzyMode fuzzy )
{
if( filter == null )
{
return Collections.emptyList();
}
return Collections.singletonList(this.findPrecise(filter));
}
return Collections.singletonList( this.findPrecise( filter ) );
}
@Override
public boolean isEmpty() {
return !this.iterator().hasNext();
}
@Override
public boolean isEmpty()
{
return !this.iterator().hasNext();
}
@Override
public void addStorage(final IAEFluidStack option) {
if (option == null) {
return;
}
@Override
public void addStorage( final IAEFluidStack option )
{
if( option == null )
{
return;
}
final IAEFluidStack st = this.getFluidRecord(option);
final IAEFluidStack st = this.getFluidRecord( option );
if (st != null) {
st.incStackSize(option.getStackSize());
return;
}
if( st != null )
{
st.incStackSize( option.getStackSize() );
return;
}
final IAEFluidStack opt = option.copy();
final IAEFluidStack opt = option.copy();
this.putFluidRecord(opt);
}
this.putFluidRecord( opt );
}
/*
* public synchronized void clean() { Iterator<StackType> i = iterator(); while
* (i.hasNext()) { StackType AEI = i.next(); if ( !AEI.isMeaningful() )
* i.remove(); } }
*/
/*
* public synchronized void clean() { Iterator<StackType> i = iterator(); while (i.hasNext()) { StackType AEI =
* i.next(); if ( !AEI.isMeaningful() ) i.remove(); } }
*/
@Override
public void addCrafting(final IAEFluidStack option) {
if (option == null) {
return;
}
@Override
public void addCrafting( final IAEFluidStack option )
{
if( option == null )
{
return;
}
final IAEFluidStack st = this.getFluidRecord(option);
final IAEFluidStack st = this.getFluidRecord( option );
if (st != null) {
st.setCraftable(true);
return;
}
if( st != null )
{
st.setCraftable( true );
return;
}
final IAEFluidStack opt = option.copy();
opt.setStackSize(0);
opt.setCraftable(true);
final IAEFluidStack opt = option.copy();
opt.setStackSize( 0 );
opt.setCraftable( true );
this.putFluidRecord(opt);
}
this.putFluidRecord( opt );
}
@Override
public void addRequestable(final IAEFluidStack option) {
if (option == null) {
return;
}
@Override
public void addRequestable( final IAEFluidStack option )
{
if( option == null )
{
return;
}
final IAEFluidStack st = this.getFluidRecord(option);
final IAEFluidStack st = this.getFluidRecord( option );
if (st != null) {
st.setCountRequestable(st.getCountRequestable() + option.getCountRequestable());
return;
}
if( st != null )
{
st.setCountRequestable( st.getCountRequestable() + option.getCountRequestable() );
return;
}
final IAEFluidStack opt = option.copy();
opt.setStackSize(0);
opt.setCraftable(false);
opt.setCountRequestable(option.getCountRequestable());
final IAEFluidStack opt = option.copy();
opt.setStackSize( 0 );
opt.setCraftable( false );
opt.setCountRequestable( option.getCountRequestable() );
this.putFluidRecord(opt);
}
this.putFluidRecord( opt );
}
@Override
public IAEFluidStack getFirstItem() {
for (final IAEFluidStack stackType : this) {
return stackType;
}
@Override
public IAEFluidStack getFirstItem()
{
for( final IAEFluidStack stackType : this )
{
return stackType;
}
return null;
}
return null;
}
@Override
public int size() {
return this.records.values().size();
}
@Override
public int size()
{
return this.records.values().size();
}
@Override
public Iterator<IAEFluidStack> iterator() {
return new MeaningfulFluidIterator<>(this.records.values().iterator());
}
@Override
public Iterator<IAEFluidStack> iterator()
{
return new MeaningfulFluidIterator<>( this.records.values().iterator() );
}
@Override
public void resetStatus() {
for (final IAEFluidStack i : this) {
i.reset();
}
}
@Override
public void resetStatus()
{
for( final IAEFluidStack i : this )
{
i.reset();
}
}
private IAEFluidStack getFluidRecord(final IAEFluidStack fluid) {
return this.records.get(fluid);
}
private IAEFluidStack getFluidRecord( final IAEFluidStack fluid )
{
return this.records.get( fluid );
}
private IAEFluidStack putFluidRecord( final IAEFluidStack fluid )
{
return this.records.put( fluid, fluid );
}
private IAEFluidStack putFluidRecord(final IAEFluidStack fluid) {
return this.records.put(fluid, fluid);
}
}
@@ -18,77 +18,68 @@
package appeng.fluids.util;
import java.util.Comparator;
import appeng.api.config.SortDir;
import appeng.api.storage.data.IAEFluidStack;
import appeng.util.Platform;
/**
* @author BrockWS
* @version rv6 - 22/05/2018
* @since rv6 22/05/2018
*/
public class FluidSorters
{
private static SortDir Direction = SortDir.ASCENDING;
public class FluidSorters {
private static SortDir Direction = SortDir.ASCENDING;
public static final Comparator<IAEFluidStack> CONFIG_BASED_SORT_BY_NAME = ( o1, o2 ) ->
{
// FIXME: Calling .getString() to compare two untranslated strings is a problem, we need to investigate how to do this better
if( getDirection() == SortDir.ASCENDING )
{
return Platform.getFluidDisplayName( o1 ).getString().compareToIgnoreCase( Platform.getFluidDisplayName( o2 ).getString() );
}
return Platform.getFluidDisplayName( o2 ).getString().compareToIgnoreCase( Platform.getFluidDisplayName( o1 ).getString() );
};
public static final Comparator<IAEFluidStack> CONFIG_BASED_SORT_BY_NAME = (o1, o2) -> {
// FIXME: Calling .getString() to compare two untranslated strings is a problem,
// we need to investigate how to do this better
if (getDirection() == SortDir.ASCENDING) {
return Platform.getFluidDisplayName(o1).getString()
.compareToIgnoreCase(Platform.getFluidDisplayName(o2).getString());
}
return Platform.getFluidDisplayName(o2).getString()
.compareToIgnoreCase(Platform.getFluidDisplayName(o1).getString());
};
public static final Comparator<IAEFluidStack> CONFIG_BASED_SORT_BY_MOD = new Comparator<IAEFluidStack>()
{
public static final Comparator<IAEFluidStack> CONFIG_BASED_SORT_BY_MOD = new Comparator<IAEFluidStack>() {
@Override
public int compare( final IAEFluidStack o1, final IAEFluidStack o2 )
{
final AEFluidStack op1 = (AEFluidStack) o1;
final AEFluidStack op2 = (AEFluidStack) o2;
@Override
public int compare(final IAEFluidStack o1, final IAEFluidStack o2) {
final AEFluidStack op1 = (AEFluidStack) o1;
final AEFluidStack op2 = (AEFluidStack) o2;
if( getDirection() == SortDir.ASCENDING )
{
return this.secondarySort( Platform.getModId( op1 ).compareToIgnoreCase( Platform.getModId( op2 ) ), o2, o1 );
}
return this.secondarySort( Platform.getModId( op2 ).compareToIgnoreCase( Platform.getModId( op1 ) ), o1, o2 );
}
if (getDirection() == SortDir.ASCENDING) {
return this.secondarySort(Platform.getModId(op1).compareToIgnoreCase(Platform.getModId(op2)), o2, o1);
}
return this.secondarySort(Platform.getModId(op2).compareToIgnoreCase(Platform.getModId(op1)), o1, o2);
}
private int secondarySort( final int compareToIgnoreCase, final IAEFluidStack o1, final IAEFluidStack o2 )
{
if( compareToIgnoreCase == 0 )
{
// FIXME: Calling .getString() to compare two untranslated strings is a problem, we need to investigate how to do this better
return Platform.getFluidDisplayName( o2 ).getString().compareToIgnoreCase( Platform.getFluidDisplayName( o1 ).getString() );
}
private int secondarySort(final int compareToIgnoreCase, final IAEFluidStack o1, final IAEFluidStack o2) {
if (compareToIgnoreCase == 0) {
// FIXME: Calling .getString() to compare two untranslated strings is a problem,
// we need to investigate how to do this better
return Platform.getFluidDisplayName(o2).getString()
.compareToIgnoreCase(Platform.getFluidDisplayName(o1).getString());
}
return compareToIgnoreCase;
}
};
return compareToIgnoreCase;
}
};
public static final Comparator<IAEFluidStack> CONFIG_BASED_SORT_BY_SIZE = ( o1, o2 ) ->
{
if( getDirection() == SortDir.ASCENDING )
{
return Long.compare( o2.getStackSize(), o1.getStackSize() );
}
return Long.compare( o1.getStackSize(), o2.getStackSize() );
};
public static final Comparator<IAEFluidStack> CONFIG_BASED_SORT_BY_SIZE = (o1, o2) -> {
if (getDirection() == SortDir.ASCENDING) {
return Long.compare(o2.getStackSize(), o1.getStackSize());
}
return Long.compare(o1.getStackSize(), o2.getStackSize());
};
private static SortDir getDirection()
{
return Direction;
}
private static SortDir getDirection() {
return Direction;
}
public static void setDirection( final SortDir direction )
{
Direction = direction;
}
public static void setDirection(final SortDir direction) {
Direction = direction;
}
}
@@ -18,9 +18,7 @@
package appeng.fluids.util;
@FunctionalInterface
public interface IAEFluidInventory
{
void onFluidInventoryChanged( final IAEFluidTank inv, final int slot );
public interface IAEFluidInventory {
void onFluidInventoryChanged(final IAEFluidTank inv, final int slot);
}
@@ -1,18 +1,15 @@
package appeng.fluids.util;
import net.minecraftforge.fluids.capability.IFluidHandler;
import appeng.api.storage.data.IAEFluidStack;
public interface IAEFluidTank extends IFluidHandler {
void setFluidInSlot(final int slot, final IAEFluidStack fluid);
public interface IAEFluidTank extends IFluidHandler
{
void setFluidInSlot( final int slot, final IAEFluidStack fluid );
IAEFluidStack getFluidInSlot(final int slot);
IAEFluidStack getFluidInSlot( final int slot );
int getSlots();
int getSlots();
}
@@ -18,58 +18,46 @@
package appeng.fluids.util;
import java.util.Iterator;
import java.util.NoSuchElementException;
import appeng.api.storage.data.IAEStack;
public class MeaningfulFluidIterator<T extends IAEStack> implements Iterator<T> {
public class MeaningfulFluidIterator<T extends IAEStack> implements Iterator<T>
{
private final Iterator<T> parent;
private T next;
private final Iterator<T> parent;
private T next;
public MeaningfulFluidIterator(final Iterator<T> iterator) {
this.parent = iterator;
}
public MeaningfulFluidIterator( final Iterator<T> iterator )
{
this.parent = iterator;
}
@Override
public boolean hasNext() {
while (this.parent.hasNext()) {
this.next = this.parent.next();
if (this.next.isMeaningful()) {
return true;
} else {
this.parent.remove(); // self cleaning :3
}
}
@Override
public boolean hasNext()
{
while( this.parent.hasNext() )
{
this.next = this.parent.next();
if( this.next.isMeaningful() )
{
return true;
}
else
{
this.parent.remove(); // self cleaning :3
}
}
this.next = null;
return false;
}
this.next = null;
return false;
}
@Override
public T next() {
if (this.next == null) {
throw new NoSuchElementException();
}
@Override
public T next()
{
if( this.next == null )
{
throw new NoSuchElementException();
}
return this.next;
}
return this.next;
}
@Override
public void remove()
{
this.parent.remove();
}
@Override
public void remove() {
this.parent.remove();
}
}