Refactored StorageChannel enum into an interface (#3138)
This replaces the static enum with a more dynamic interface providing factory methods for handling network storage.
This commit is contained in:
@@ -37,10 +37,11 @@ import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.FluidUtil;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.FuzzyMode;
|
||||
import appeng.api.storage.StorageChannel;
|
||||
import appeng.api.storage.IStorageChannel;
|
||||
import appeng.api.storage.channels.IFluidStorageChannel;
|
||||
import appeng.api.storage.data.IAEFluidStack;
|
||||
import appeng.api.storage.data.IAEStack;
|
||||
import appeng.util.Platform;
|
||||
|
||||
|
||||
@@ -80,14 +81,26 @@ public final class AEFluidStack extends AEStack<IAEFluidStack> implements IAEFlu
|
||||
this.myHash = this.fluid.hashCode() ^ ( this.tagCompound == null ? 0 : System.identityHashCode( this.tagCompound ) );
|
||||
}
|
||||
|
||||
public static IAEFluidStack loadFluidStackFromNBT( final NBTTagCompound i )
|
||||
public static AEFluidStack fromFluidStack( final FluidStack input )
|
||||
{
|
||||
final ItemStack itemstack = new ItemStack( i );
|
||||
if( itemstack.isEmpty() )
|
||||
if( input == null )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
final AEFluidStack fluid = AEFluidStack.create( itemstack );
|
||||
|
||||
return new AEFluidStack( input );
|
||||
}
|
||||
|
||||
public static IAEFluidStack fromNBT( final NBTTagCompound i )
|
||||
{
|
||||
final FluidStack fluidStack = FluidStack.loadFluidStackFromNBT( i );
|
||||
|
||||
if( fluidStack == null )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
final AEFluidStack fluid = AEFluidStack.fromFluidStack( fluidStack );
|
||||
// fluid.priority = i.getInteger( "Priority" );
|
||||
fluid.setStackSize( i.getLong( "Cnt" ) );
|
||||
fluid.setCountRequestable( i.getLong( "Req" ) );
|
||||
@@ -95,24 +108,7 @@ public final class AEFluidStack extends AEStack<IAEFluidStack> implements IAEFlu
|
||||
return fluid;
|
||||
}
|
||||
|
||||
public static AEFluidStack create( final Object a )
|
||||
{
|
||||
if( a == null )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
if( a instanceof AEFluidStack )
|
||||
{
|
||||
( (IAEStack<IAEFluidStack>) a ).copy();
|
||||
}
|
||||
if( a instanceof FluidStack )
|
||||
{
|
||||
return new AEFluidStack( (FluidStack) a );
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static IAEFluidStack loadFluidStackFromPacket( final ByteBuf data ) throws IOException
|
||||
public static IAEFluidStack fromPacket( final ByteBuf data ) throws IOException
|
||||
{
|
||||
final byte mask = data.readByte();
|
||||
// byte PriorityType = (byte) (mask & 0x03);
|
||||
@@ -159,7 +155,7 @@ public final class AEFluidStack extends AEStack<IAEFluidStack> implements IAEFlu
|
||||
return null;
|
||||
}
|
||||
|
||||
final AEFluidStack fluid = AEFluidStack.create( fluidStack );
|
||||
final AEFluidStack fluid = AEFluidStack.fromFluidStack( fluidStack );
|
||||
// fluid.priority = (int) priority;
|
||||
fluid.setStackSize( stackSize );
|
||||
fluid.setCountRequestable( countRequestable );
|
||||
@@ -275,9 +271,9 @@ public final class AEFluidStack extends AEStack<IAEFluidStack> implements IAEFlu
|
||||
}
|
||||
|
||||
@Override
|
||||
public StorageChannel getChannel()
|
||||
public IStorageChannel<IAEFluidStack> getChannel()
|
||||
{
|
||||
return StorageChannel.FLUIDS;
|
||||
return AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -23,6 +23,7 @@ import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
@@ -36,8 +37,10 @@ import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import net.minecraftforge.items.ItemHandlerHelper;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.FuzzyMode;
|
||||
import appeng.api.storage.StorageChannel;
|
||||
import appeng.api.storage.IStorageChannel;
|
||||
import appeng.api.storage.channels.IItemStorageChannel;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.util.Platform;
|
||||
|
||||
@@ -72,7 +75,18 @@ public final class AEItemStack extends AEStack<IAEItemStack> implements IAEItemS
|
||||
this.oreReference = OreHelper.INSTANCE.getOre( is.getDefinition() );
|
||||
}
|
||||
|
||||
public static IAEItemStack loadItemStackFromNBT( final NBTTagCompound i )
|
||||
@Nullable
|
||||
public static AEItemStack fromItemStack( @Nonnull final ItemStack stack )
|
||||
{
|
||||
if( stack.isEmpty() )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new AEItemStack( AEItemStackRegistry.getRegisteredStack( stack ), stack.getCount() );
|
||||
}
|
||||
|
||||
public static IAEItemStack fromNBT( final NBTTagCompound i )
|
||||
{
|
||||
if( i == null )
|
||||
{
|
||||
@@ -85,25 +99,14 @@ public final class AEItemStack extends AEStack<IAEItemStack> implements IAEItemS
|
||||
return null;
|
||||
}
|
||||
|
||||
final AEItemStack item = AEItemStack.create( itemstack );
|
||||
final AEItemStack item = AEItemStack.fromItemStack( itemstack );
|
||||
item.setStackSize( i.getLong( "Cnt" ) );
|
||||
item.setCountRequestable( i.getLong( "Req" ) );
|
||||
item.setCraftable( i.getBoolean( "Craft" ) );
|
||||
return item;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static AEItemStack create( final ItemStack stack )
|
||||
{
|
||||
if( stack.isEmpty() )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new AEItemStack( AEItemStackRegistry.getRegisteredStack( stack ), stack.getCount() );
|
||||
}
|
||||
|
||||
public static IAEItemStack loadItemStackFromPacket( final ByteBuf data ) throws IOException
|
||||
public static IAEItemStack fromPacket( final ByteBuf data ) throws IOException
|
||||
{
|
||||
final byte mask = data.readByte();
|
||||
// byte PriorityType = (byte) (mask & 0x03);
|
||||
@@ -120,7 +123,7 @@ public final class AEItemStack extends AEStack<IAEItemStack> implements IAEItemS
|
||||
return null;
|
||||
}
|
||||
|
||||
final AEItemStack item = AEItemStack.create( itemstack );
|
||||
final AEItemStack item = AEItemStack.fromItemStack( itemstack );
|
||||
item.setStackSize( stackSize );
|
||||
item.setCountRequestable( countRequestable );
|
||||
item.setCraftable( isCraftable );
|
||||
@@ -298,9 +301,9 @@ public final class AEItemStack extends AEStack<IAEItemStack> implements IAEItemS
|
||||
}
|
||||
|
||||
@Override
|
||||
public StorageChannel getChannel()
|
||||
public IStorageChannel<IAEItemStack> getChannel()
|
||||
{
|
||||
return StorageChannel.ITEMS;
|
||||
return AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -23,6 +23,7 @@ import java.util.Collection;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.FuzzyMode;
|
||||
import appeng.api.storage.channels.IItemStorageChannel;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.storage.data.IItemContainer;
|
||||
|
||||
@@ -31,7 +32,7 @@ public class ItemModList implements IItemContainer<IAEItemStack>
|
||||
{
|
||||
|
||||
private final IItemContainer<IAEItemStack> backingStore;
|
||||
private final IItemContainer<IAEItemStack> overrides = AEApi.instance().storage().createItemList();
|
||||
private final IItemContainer<IAEItemStack> overrides = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList();
|
||||
|
||||
public ItemModList( final IItemContainer<IAEItemStack> backend )
|
||||
{
|
||||
|
||||
@@ -57,7 +57,7 @@ public class OreReference
|
||||
{
|
||||
if( is.getItem() != Items.AIR )
|
||||
{
|
||||
this.aeOtherOptions.add( AEItemStack.create( is ) );
|
||||
this.aeOtherOptions.add( AEItemStack.fromItemStack( is ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user