partial implementation of oredict storage bus

missing proper GUI, text, item models, memorycard support.
logic works
This commit is contained in:
PrototypeTrousers
2022-01-03 02:33:08 -03:00
parent 13afa6908a
commit 9eef9d3840
13 changed files with 492 additions and 32 deletions
@@ -0,0 +1,173 @@
package appeng.parts.misc;
import appeng.api.AEApi;
import appeng.api.config.*;
import appeng.api.networking.storage.IBaseMonitor;
import appeng.api.networking.storage.IStorageGrid;
import appeng.api.networking.ticking.ITickManager;
import appeng.api.storage.IMEInventory;
import appeng.api.storage.channels.IItemStorageChannel;
import appeng.api.storage.data.IAEItemStack;
import appeng.core.sync.GuiBridge;
import appeng.me.GridAccessException;
import appeng.me.cache.GridStorageCache;
import appeng.me.storage.ITickingMonitor;
import appeng.me.storage.MEInventoryHandler;
import appeng.util.ConfigManager;
import appeng.util.Platform;
import appeng.util.item.OreHelper;
import appeng.util.prioritylist.OreDictPriorityList;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.Vec3d;
public class PartOreDicStorageBus extends PartStorageBus
{
public String oreMatch = "";
public PartOreDicStorageBus( ItemStack is )
{
super( is );
}
@Override
public boolean onPartActivate( final EntityPlayer player, final EnumHand hand, final Vec3d pos )
{
if( Platform.isServer() )
{
Platform.openGUI( player, this.getHost().getTile(), this.getSide(), GuiBridge.GUI_OREDICTSTORAGEBUS );
}
return true;
}
@Override
public GuiBridge getGuiBridge()
{
return GuiBridge.GUI_OREDICTSTORAGEBUS;
}
@Override
public MEInventoryHandler<IAEItemStack> getInternalHandler()
{
if( this.cached )
{
return this.handler;
}
final boolean wasSleeping = this.monitor == null;
this.cached = true;
final TileEntity self = this.getHost().getTile();
final TileEntity target = self.getWorld().getTileEntity( self.getPos().offset( this.getSide().getFacing() ) );
final int newHandlerHash = this.createHandlerHash( target );
if( newHandlerHash != 0 && newHandlerHash == this.handlerHash )
{
return this.handler;
}
this.handlerHash = newHandlerHash;
this.handler = null;
if( this.monitor != null )
{
( (IBaseMonitor<IAEItemStack>) monitor ).removeListener( this );
}
this.monitor = null;
if( target != null )
{
IMEInventory<IAEItemStack> inv = this.getInventoryWrapper( target );
if( inv instanceof ITickingMonitor )
{
this.monitor = (ITickingMonitor) inv;
this.monitor.setActionSource( mySrc );
this.monitor.setMode( (StorageFilter) this.getConfigManager().getSetting( Settings.STORAGE_FILTER ) );
}
if( inv != null )
{
this.handler = new MEInventoryHandler<>( inv, AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) );
this.handler.setBaseAccess( (AccessRestriction) this.getConfigManager().getSetting( Settings.ACCESS ) );
this.handler.setWhitelist( this.getInstalledUpgrades( Upgrades.INVERTER ) > 0 ? IncludeExclude.BLACKLIST : IncludeExclude.WHITELIST );
this.handler.setPriority( this.priority );
this.handler.setPartitionList( new OreDictPriorityList<>( OreHelper.INSTANCE.getMatchingOre( oreMatch ), oreMatch ) );
if( inv instanceof IBaseMonitor )
{
if( ( (AccessRestriction) ( (ConfigManager) this.getConfigManager() ).getSetting( Settings.ACCESS ) ).hasPermission( AccessRestriction.READ ) )
{
( (IBaseMonitor<IAEItemStack>) inv ).addListener( this, this.handler );
}
}
}
}
// update sleep state...
if( wasSleeping != ( this.monitor == null ) )
{
try
{
final ITickManager tm = this.getProxy().getTick();
if( this.monitor == null )
{
tm.sleepDevice( this.getProxy().getNode() );
}
else
{
tm.wakeDevice( this.getProxy().getNode() );
}
}
catch( final GridAccessException e )
{
// :(
}
}
try
{
// force grid to update handlers...
( (GridStorageCache) this.getProxy().getGrid().getCache( IStorageGrid.class ) ).cellUpdate( null );
}
catch( final GridAccessException e )
{
// :3
}
return this.handler;
}
public String getOreMatch()
{
if( this.oreMatch == null )
{
return "";
}
return oreMatch;
}
public void saveOreMatch( String oreMatch )
{
this.oreMatch = oreMatch;
this.getHost().markForSave();
}
@Override
public void readFromNBT( NBTTagCompound data )
{
super.readFromNBT( data );
this.oreMatch = data.getString( "oreMatch" );
}
@Override
public void writeToNBT( NBTTagCompound data )
{
super.writeToNBT( data );
data.setString( "oreMatch", oreMatch );
}
}
@@ -96,13 +96,13 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC
public static final IPartModel MODELS_HAS_CHANNEL = new PartModel( MODEL_BASE, new ResourceLocation( AppEng.MOD_ID, "part/storage_bus_has_channel" ) );
@CapabilityInject( IItemRepository.class )
public static Capability<IItemRepository> ITEM_REPOSITORY_CAPABILITY = null;
private final IActionSource mySrc;
private final AppEngInternalAEInventory Config = new AppEngInternalAEInventory( this, 63 );
private int priority = 0;
private boolean cached = false;
private ITickingMonitor monitor = null;
private MEInventoryHandler<IAEItemStack> handler = null;
private int handlerHash = 0;
protected final IActionSource mySrc;
protected final AppEngInternalAEInventory Config = new AppEngInternalAEInventory( this, 63 );
protected int priority = 0;
protected boolean cached = false;
protected ITickingMonitor monitor = null;
protected MEInventoryHandler<IAEItemStack> handler = null;
protected int handlerHash = 0;
private boolean wasActive = false;
private byte resetCacheLogic = 0;
private boolean accessChanged;
@@ -409,7 +409,7 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC
}
}
private IMEInventory<IAEItemStack> getInventoryWrapper( TileEntity target )
IMEInventory<IAEItemStack> getInventoryWrapper( TileEntity target )
{
EnumFacing targetSide = this.getSide().getFacing().getOpposite();
@@ -452,7 +452,7 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC
}
private int createHandlerHash( TileEntity target )
int createHandlerHash( TileEntity target )
{
if( target == null )
{