IAEStack#fuzzyComparison now compares the same subtypes. (#3384)
To reduce the amount of instanceof checks, it will now compare the same subtupe. Comparing an ItemStack and IAEItemStack can simply wrap it before calling it. Heavy use should already use an IAEStack internal. Analogue for fluids or other types.
This commit is contained in:
@@ -149,16 +149,14 @@ public interface IAEStack<T extends IAEStack<T>>
|
|||||||
boolean equals( Object obj );
|
boolean equals( Object obj );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* compare stacks using fuzzy logic
|
* Compare the same subtype of {@link IAEStack} with another using a fuzzy comparison.
|
||||||
*
|
*
|
||||||
* a IAEItemStack to another AEItemStack or a ItemStack.
|
* @param other The stack to compare.
|
||||||
*
|
* @param mode Which {@link FuzzyMode} should be used.
|
||||||
* @param st stacks
|
|
||||||
* @param mode used fuzzy mode
|
|
||||||
*
|
*
|
||||||
* @return true if two stacks are equal based on AE Fuzzy Comparison.
|
* @return true if two stacks are equal based on AE Fuzzy Comparison.
|
||||||
*/
|
*/
|
||||||
boolean fuzzyComparison( Object st, FuzzyMode mode );
|
boolean fuzzyComparison( T other, FuzzyMode mode );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Slower for disk saving, but smaller/more efficient for packets.
|
* Slower for disk saving, but smaller/more efficient for packets.
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ import io.netty.buffer.ByteBuf;
|
|||||||
|
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.CompressedStreamTools;
|
import net.minecraft.nbt.CompressedStreamTools;
|
||||||
import net.minecraft.nbt.NBTBase;
|
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraftforge.fluids.Fluid;
|
import net.minecraftforge.fluids.Fluid;
|
||||||
import net.minecraftforge.fluids.FluidStack;
|
import net.minecraftforge.fluids.FluidStack;
|
||||||
@@ -207,7 +206,7 @@ public final class AEFluidStack extends AEStack<IAEFluidStack> implements IAEFlu
|
|||||||
|
|
||||||
if( this.tagCompound != null )
|
if( this.tagCompound != null )
|
||||||
{
|
{
|
||||||
i.setTag( "tag", (NBTBase) this.tagCompound );
|
i.setTag( "tag", this.tagCompound );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -216,19 +215,9 @@ public final class AEFluidStack extends AEStack<IAEFluidStack> implements IAEFlu
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean fuzzyComparison( final Object st, final FuzzyMode mode )
|
public boolean fuzzyComparison( final IAEFluidStack other, final FuzzyMode mode )
|
||||||
{
|
{
|
||||||
if( st instanceof FluidStack )
|
return this.fluid == other.getFluid();
|
||||||
{
|
|
||||||
return ( (FluidStack) st ).getFluid() == this.fluid;
|
|
||||||
}
|
|
||||||
|
|
||||||
if( st instanceof IAEFluidStack )
|
|
||||||
{
|
|
||||||
return ( (IAEFluidStack) st ).getFluid() == this.fluid;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -289,7 +278,7 @@ public final class AEFluidStack extends AEStack<IAEFluidStack> implements IAEFlu
|
|||||||
|
|
||||||
if( is.getFluid() == this.fluid )
|
if( is.getFluid() == this.fluid )
|
||||||
{
|
{
|
||||||
final NBTTagCompound ta = (NBTTagCompound) this.tagCompound;
|
final NBTTagCompound ta = this.tagCompound;
|
||||||
final NBTTagCompound tb = is.tag;
|
final NBTTagCompound tb = is.tag;
|
||||||
if( ta == tb )
|
if( ta == tb )
|
||||||
{
|
{
|
||||||
@@ -347,7 +336,7 @@ public final class AEFluidStack extends AEStack<IAEFluidStack> implements IAEFlu
|
|||||||
public ItemStack asItemStackRepresentation()
|
public ItemStack asItemStackRepresentation()
|
||||||
{
|
{
|
||||||
// TODO: fluids, how do they even work?
|
// TODO: fluids, how do they even work?
|
||||||
return FluidUtil.getFilledBucket( getFluidStack() );
|
return FluidUtil.getFilledBucket( this.getFluidStack() );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -358,7 +347,7 @@ public final class AEFluidStack extends AEStack<IAEFluidStack> implements IAEFlu
|
|||||||
|
|
||||||
i.writeByte( mask );
|
i.writeByte( mask );
|
||||||
|
|
||||||
writeToStream( i );
|
this.writeToStream( i );
|
||||||
|
|
||||||
this.putPacketValue( i, this.getStackSize() );
|
this.putPacketValue( i, this.getStackSize() );
|
||||||
this.putPacketValue( i, this.getCountRequestable() );
|
this.putPacketValue( i, this.getCountRequestable() );
|
||||||
|
|||||||
@@ -163,37 +163,17 @@ public final class AEItemStack extends AEStack<IAEItemStack> implements IAEItemS
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean fuzzyComparison( final Object st, final FuzzyMode mode )
|
public boolean fuzzyComparison( final IAEItemStack other, final FuzzyMode mode )
|
||||||
{
|
{
|
||||||
if( st instanceof IAEItemStack )
|
if( mode == FuzzyMode.IGNORE_ALL && OreHelper.INSTANCE.sameOre( this, other ) )
|
||||||
{
|
{
|
||||||
final IAEItemStack other = (IAEItemStack) st;
|
return true;
|
||||||
|
|
||||||
if( OreHelper.INSTANCE.sameOre( this, other ) )
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
final ItemStack itemStack = this.getDefinition();
|
|
||||||
final ItemStack otherStack = other.getDefinition();
|
|
||||||
|
|
||||||
return this.fuzzyItemStackComparison( itemStack, otherStack, mode );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if( st instanceof ItemStack )
|
final ItemStack itemStack = this.getDefinition();
|
||||||
{
|
final ItemStack otherStack = other.getDefinition();
|
||||||
final ItemStack otherStack = (ItemStack) st;
|
|
||||||
|
|
||||||
if( OreHelper.INSTANCE.sameOre( this, otherStack ) )
|
return this.fuzzyItemStackComparison( itemStack, otherStack, mode );
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
final ItemStack itemStack = this.getDefinition();
|
|
||||||
return this.fuzzyItemStackComparison( itemStack, otherStack, mode );
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user