1.15 port
This commit is contained in:
@@ -21,7 +21,6 @@ package appeng.util.item;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
@@ -30,11 +29,11 @@ import io.netty.buffer.ByteBuf;
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.fml.common.network.ByteBufUtils;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.minecraftforge.items.ItemHandlerHelper;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
@@ -48,13 +47,12 @@ import appeng.util.Platform;
|
||||
public final class AEItemStack extends AEStack<IAEItemStack> implements IAEItemStack
|
||||
{
|
||||
private AESharedItemStack sharedStack;
|
||||
private Optional<OreReference> oreReference;
|
||||
|
||||
@SideOnly( Side.CLIENT )
|
||||
@OnlyIn( Dist.CLIENT )
|
||||
private String displayName;
|
||||
@SideOnly( Side.CLIENT )
|
||||
@OnlyIn( Dist.CLIENT )
|
||||
private List<String> tooltip;
|
||||
@SideOnly( Side.CLIENT )
|
||||
@OnlyIn( Dist.CLIENT )
|
||||
private ResourceLocation uniqueID;
|
||||
|
||||
private AEItemStack( final AEItemStack is )
|
||||
@@ -63,7 +61,6 @@ public final class AEItemStack extends AEStack<IAEItemStack> implements IAEItemS
|
||||
this.setCraftable( is.isCraftable() );
|
||||
this.setCountRequestable( is.getCountRequestable() );
|
||||
this.sharedStack = is.sharedStack;
|
||||
this.oreReference = is.oreReference;
|
||||
}
|
||||
|
||||
private AEItemStack( final AESharedItemStack is, long size )
|
||||
@@ -72,7 +69,6 @@ public final class AEItemStack extends AEStack<IAEItemStack> implements IAEItemS
|
||||
this.setStackSize( size );
|
||||
this.setCraftable( false );
|
||||
this.setCountRequestable( 0 );
|
||||
this.oreReference = OreHelper.INSTANCE.getOre( is.getDefinition() );
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -86,14 +82,14 @@ public final class AEItemStack extends AEStack<IAEItemStack> implements IAEItemS
|
||||
return new AEItemStack( AEItemStackRegistry.getRegisteredStack( stack ), stack.getCount() );
|
||||
}
|
||||
|
||||
public static IAEItemStack fromNBT( final NBTTagCompound i )
|
||||
public static IAEItemStack fromNBT( final CompoundNBT i )
|
||||
{
|
||||
if( i == null )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
final ItemStack itemstack = new ItemStack( i );
|
||||
final ItemStack itemstack = ItemStack.read( i );
|
||||
if( itemstack.isEmpty() )
|
||||
{
|
||||
return null;
|
||||
@@ -107,12 +103,12 @@ public final class AEItemStack extends AEStack<IAEItemStack> implements IAEItemS
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT( final NBTTagCompound i )
|
||||
public void writeToNBT( final CompoundNBT i )
|
||||
{
|
||||
this.getDefinition().writeToNBT( i );
|
||||
i.setLong( "Cnt", this.getStackSize() );
|
||||
i.setLong( "Req", this.getCountRequestable() );
|
||||
i.setBoolean( "Craft", this.isCraftable() );
|
||||
this.getDefinition().write( i );
|
||||
i.putLong( "Cnt", this.getStackSize() );
|
||||
i.putLong( "Req", this.getCountRequestable() );
|
||||
i.putBoolean( "Craft", this.isCraftable() );
|
||||
}
|
||||
|
||||
public static AEItemStack fromPacket( final ByteBuf data )
|
||||
@@ -122,7 +118,8 @@ public final class AEItemStack extends AEStack<IAEItemStack> implements IAEItemS
|
||||
final byte countReqType = (byte) ( ( mask & 0x30 ) >> 4 );
|
||||
final boolean isCraftable = ( mask & 0x40 ) > 0;
|
||||
|
||||
final ItemStack itemstack = new ItemStack( ByteBufUtils.readTag( data ) );
|
||||
final PacketBuffer p = new PacketBuffer( data );
|
||||
final ItemStack itemstack = p.readItemStack();
|
||||
final long stackSize = getPacketValue( stackType, data );
|
||||
final long countRequestable = getPacketValue( countReqType, data );
|
||||
|
||||
@@ -138,13 +135,13 @@ public final class AEItemStack extends AEStack<IAEItemStack> implements IAEItemS
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToPacket( final ByteBuf i )
|
||||
public void writeToPacket( final PacketBuffer i )
|
||||
{
|
||||
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 );
|
||||
|
||||
i.writeByte( mask );
|
||||
ByteBufUtils.writeTag( i, this.getDefinition().serializeNBT() );
|
||||
i.writeCompoundTag( this.getDefinition().serializeNBT() );
|
||||
this.putPacketValue( i, this.getStackSize() );
|
||||
this.putPacketValue( i, this.getCountRequestable() );
|
||||
}
|
||||
@@ -165,11 +162,6 @@ public final class AEItemStack extends AEStack<IAEItemStack> implements IAEItemS
|
||||
@Override
|
||||
public boolean fuzzyComparison( final IAEItemStack other, final FuzzyMode mode )
|
||||
{
|
||||
if( mode == FuzzyMode.IGNORE_ALL && OreHelper.INSTANCE.sameOre( this, other ) )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
final ItemStack itemStack = this.getDefinition();
|
||||
final ItemStack otherStack = other.getDefinition();
|
||||
|
||||
@@ -218,12 +210,6 @@ public final class AEItemStack extends AEStack<IAEItemStack> implements IAEItemS
|
||||
return this.sharedStack.getItemDamage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean sameOre( final IAEItemStack is )
|
||||
{
|
||||
return OreHelper.INSTANCE.sameOre( this, is );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSameType( final IAEItemStack otherStack )
|
||||
{
|
||||
@@ -274,10 +260,10 @@ public final class AEItemStack extends AEStack<IAEItemStack> implements IAEItemS
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return this.getStackSize() + "x" + this.getDefinition().getItem().getUnlocalizedName() + "@" + this.getDefinition().getItemDamage();
|
||||
return this.getStackSize() + "x" + this.getDefinition().getItem().getRegistryName();
|
||||
}
|
||||
|
||||
@SideOnly( Side.CLIENT )
|
||||
@OnlyIn( Dist.CLIENT )
|
||||
public List<String> getToolTip()
|
||||
{
|
||||
if( this.tooltip == null )
|
||||
@@ -287,7 +273,7 @@ public final class AEItemStack extends AEStack<IAEItemStack> implements IAEItemS
|
||||
return this.tooltip;
|
||||
}
|
||||
|
||||
@SideOnly( Side.CLIENT )
|
||||
@OnlyIn( Dist.CLIENT )
|
||||
public String getDisplayName()
|
||||
{
|
||||
if( this.displayName == null )
|
||||
@@ -297,31 +283,16 @@ public final class AEItemStack extends AEStack<IAEItemStack> implements IAEItemS
|
||||
return this.displayName;
|
||||
}
|
||||
|
||||
@SideOnly( Side.CLIENT )
|
||||
@OnlyIn( Dist.CLIENT )
|
||||
public String getModID()
|
||||
{
|
||||
if( this.uniqueID == null )
|
||||
{
|
||||
this.uniqueID = Item.REGISTRY.getNameForObject( this.getDefinition().getItem() );
|
||||
}
|
||||
|
||||
if( this.uniqueID == null )
|
||||
{
|
||||
return "** Null";
|
||||
}
|
||||
|
||||
return this.uniqueID.getResourceDomain() == null ? "** Null" : this.uniqueID.getResourceDomain();
|
||||
}
|
||||
|
||||
public Optional<OreReference> getOre()
|
||||
{
|
||||
return this.oreReference;
|
||||
return this.getDefinition().getItem().getRegistryName().getNamespace();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTagCompound()
|
||||
{
|
||||
return this.getDefinition().hasTagCompound();
|
||||
return this.getDefinition().hasTag();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -353,21 +324,18 @@ public final class AEItemStack extends AEStack<IAEItemStack> implements IAEItemS
|
||||
}
|
||||
else if( mode == FuzzyMode.PERCENT_99 )
|
||||
{
|
||||
return ( a.getItemDamage() > 1 ) == ( b.getItemDamage() > 1 );
|
||||
return ( a.getDamage() > 1 ) == ( b.getDamage() > 1 );
|
||||
}
|
||||
else
|
||||
{
|
||||
final float percentDamageOfA = (float) a.getItemDamage() / (float) a.getMaxDamage();
|
||||
final float percentDamageOfB = (float) b.getItemDamage() / (float) b.getMaxDamage();
|
||||
final float percentDamageOfA = (float) a.getDamage() / a.getMaxDamage();
|
||||
final float percentDamageOfB = (float) b.getDamage() / b.getMaxDamage();
|
||||
|
||||
return ( percentDamageOfA > mode.breakPoint ) == ( percentDamageOfB > mode.breakPoint );
|
||||
}
|
||||
}
|
||||
|
||||
return a.getMetadata() == b.getMetadata();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user