Memory Card can now be used on most Blocks/Parts to save/load settings.

This commit is contained in:
AlgorithmX2 2014-02-19 23:18:49 -06:00
parent 921c681b47
commit b23aab81e6
15 changed files with 220 additions and 34 deletions

View file

@ -7,6 +7,7 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.StatCollector;
import net.minecraft.world.World;
import appeng.api.implementations.items.IMemoryCard;
import appeng.api.implementations.items.MemoryCardMessages;
import appeng.core.features.AEFeature;
@ -35,6 +36,12 @@ public class ToolMemoryCard extends AEBaseItem implements IMemoryCard
}
}
@Override
public boolean doesSneakBypassUse(World world, int x, int y, int z, EntityPlayer player)
{
return true;
}
@Override
public void setMemoryCardContents(ItemStack is, String SettingsName, NBTTagCompound data)
{

View file

@ -21,6 +21,9 @@ import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import appeng.api.config.Upgrades;
import appeng.api.implementations.IUpgradeableHost;
import appeng.api.implementations.items.IMemoryCard;
import appeng.api.implementations.items.MemoryCardMessages;
import appeng.api.implementations.tiles.ISegmentedInventory;
import appeng.api.networking.IGridNode;
import appeng.api.networking.security.IActionHost;
import appeng.api.parts.BusSupport;
@ -34,10 +37,14 @@ import appeng.api.util.AECableType;
import appeng.api.util.AEColor;
import appeng.api.util.DimensionalCoord;
import appeng.api.util.IConfigManager;
import appeng.api.util.IConfigureableObject;
import appeng.helpers.IPriorityHost;
import appeng.me.helpers.AENetworkProxy;
import appeng.me.helpers.IGridProxyable;
import appeng.parts.networking.PartCable;
import appeng.tile.inventory.AppEngInternalAEInventory;
import appeng.util.Platform;
import appeng.util.SettingsFrom;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@ -226,12 +233,6 @@ public class AEBasePart implements IPart, IGridProxyable, IActionHost, IUpgradea
return 0;
}
@Override
public boolean onActivate(EntityPlayer player, Vec3 pos)
{
return false;
}
@Override
public AECableType getCableConnectionType(ForgeDirection dir)
{
@ -280,8 +281,140 @@ public class AEBasePart implements IPart, IGridProxyable, IActionHost, IUpgradea
return 0;
}
/**
* depending on the from, diffrent settings will be accepted, don't call this with null
*
* @param from
* @param compound
*/
public void uploadSettings(SettingsFrom from, NBTTagCompound compound)
{
if ( compound != null && this instanceof IConfigureableObject )
{
IConfigManager cm = ((IConfigureableObject) this).getConfigManager();
if ( cm != null )
cm.readFromNBT( compound );
}
if ( this instanceof IPriorityHost )
{
IPriorityHost pHost = (IPriorityHost) this;
pHost.setPriority( compound.getInteger( "priority" ) );
}
if ( this instanceof ISegmentedInventory )
{
IInventory inv = ((ISegmentedInventory) this).getInventoryByName( "config" );
if ( inv != null && inv instanceof AppEngInternalAEInventory )
{
AppEngInternalAEInventory target = (AppEngInternalAEInventory) inv;
AppEngInternalAEInventory tmp = new AppEngInternalAEInventory( null, target.getSizeInventory() );
tmp.readFromNBT( compound, "config" );
for (int x = 0; x < tmp.getSizeInventory(); x++)
target.setInventorySlotContents( x, tmp.getStackInSlot( x ) );
}
}
}
/**
* null means nothing to store...
*
* @param from
* @return
*/
public NBTTagCompound downloadSettings(SettingsFrom from)
{
NBTTagCompound output = new NBTTagCompound();
if ( this instanceof IConfigureableObject )
{
IConfigManager cm = this.getConfigManager();
if ( cm != null )
cm.writeToNBT( output );
}
if ( this instanceof IPriorityHost )
{
IPriorityHost pHost = (IPriorityHost) this;
output.setInteger( "priority", pHost.getPriority() );
}
if ( this instanceof ISegmentedInventory )
{
IInventory inv = ((ISegmentedInventory) this).getInventoryByName( "config" );
if ( inv != null && inv instanceof AppEngInternalAEInventory )
{
((AppEngInternalAEInventory) inv).writeToNBT( output, "config" );
}
}
return output.hasNoTags() ? null : output;
}
public boolean useStandardMemoryCard()
{
return true;
}
private boolean useMemoryCard(EntityPlayer player)
{
ItemStack memCardIS = player.inventory.getCurrentItem();
if ( memCardIS != null && useStandardMemoryCard() && memCardIS.getItem() instanceof IMemoryCard )
{
IMemoryCard memc = (IMemoryCard) memCardIS.getItem();
String name = getItemStack( PartItemStack.Network ).getUnlocalizedName();
if ( player.isSneaking() )
{
NBTTagCompound data = downloadSettings( SettingsFrom.MEMORY_CARD );
if ( data != null )
{
memc.setMemoryCardContents( memCardIS, name, data );
memc.notifyUser( player, MemoryCardMessages.SETTINGS_SAVED );
}
}
else
{
String stordName = memc.getSettingsName( memCardIS );
NBTTagCompound data = memc.getData( memCardIS );
if ( name.equals( stordName ) )
{
uploadSettings( SettingsFrom.MEMORY_CARD, data );
memc.notifyUser( player, MemoryCardMessages.SETTINGS_LOADED );
}
else
memc.notifyUser( player, MemoryCardMessages.INVALID_MACHINE );
}
return true;
}
return false;
}
@Override
public boolean onShiftActivate(EntityPlayer player, Vec3 pos)
final public boolean onActivate(EntityPlayer player, Vec3 pos)
{
if ( useMemoryCard( player ) )
return true;
return onPartActivate( player, pos );
}
@Override
final public boolean onShiftActivate(EntityPlayer player, Vec3 pos)
{
if ( useMemoryCard( player ) )
return true;
return onPartShiftActivate( player, pos );
}
public boolean onPartActivate(EntityPlayer player, Vec3 pos)
{
return false;
}
public boolean onPartShiftActivate(EntityPlayer player, Vec3 pos)
{
return false;
}

View file

@ -41,7 +41,7 @@ public class PartExportBus extends PartSharedItemBus implements IGridTickable
}
@Override
public boolean onActivate(EntityPlayer player, Vec3 pos)
public boolean onPartActivate(EntityPlayer player, Vec3 pos)
{
if ( !player.isSneaking() )
{

View file

@ -69,7 +69,7 @@ public class PartFormationPlane extends PartUpgradeable implements ICellContaine
}
@Override
public boolean onActivate(EntityPlayer player, Vec3 pos)
public boolean onPartActivate(EntityPlayer player, Vec3 pos)
{
if ( !player.isSneaking() )
{

View file

@ -48,7 +48,7 @@ public class PartImportBus extends PartSharedItemBus implements IGridTickable, I
}
@Override
public boolean onActivate(EntityPlayer player, Vec3 pos)
public boolean onPartActivate(EntityPlayer player, Vec3 pos)
{
if ( !player.isSneaking() )
{

View file

@ -179,7 +179,7 @@ public class PartLevelEmitter extends PartUpgradeable implements IStackWatcherHo
}
@Override
public boolean onActivate(EntityPlayer player, Vec3 pos)
public boolean onPartActivate(EntityPlayer player, Vec3 pos)
{
if ( !player.isSneaking() )
{

View file

@ -267,7 +267,7 @@ public class PartInterface extends PartBasicState implements IGridTickable, ISeg
}
@Override
public boolean onActivate(EntityPlayer p, Vec3 pos)
public boolean onPartActivate(EntityPlayer p, Vec3 pos)
{
if ( p.isSneaking() )
return false;

View file

@ -102,7 +102,7 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC
}
@Override
public boolean onActivate(EntityPlayer player, Vec3 pos)
public boolean onPartActivate(EntityPlayer player, Vec3 pos)
{
if ( !player.isSneaking() )
{

View file

@ -41,6 +41,12 @@ public class PartP2PTunnel<T extends PartP2PTunnel> extends PartBasicState
throw new RuntimeException( "Don't construct the root tunnel!" );
}
@Override
public boolean useStandardMemoryCard()
{
return false;
}
@Override
public void writeToNBT(NBTTagCompound data)
{
@ -56,7 +62,7 @@ public class PartP2PTunnel<T extends PartP2PTunnel> extends PartBasicState
}
@Override
public boolean onActivate(EntityPlayer player, Vec3 pos)
public boolean onPartActivate(EntityPlayer player, Vec3 pos)
{
ItemStack is = player.inventory.getCurrentItem();
@ -178,7 +184,7 @@ public class PartP2PTunnel<T extends PartP2PTunnel> extends PartBasicState
}
@Override
public boolean onShiftActivate(EntityPlayer player, Vec3 pos)
public boolean onPartShiftActivate(EntityPlayer player, Vec3 pos)
{
ItemStack is = player.inventory.getCurrentItem();
if ( is != null && is.getItem() instanceof IMemoryCard )

View file

@ -30,7 +30,7 @@ public class PartConversionMonitor extends PartStorageMonitor
}
@Override
public boolean onShiftActivate(EntityPlayer player, Vec3 pos)
public boolean onPartShiftActivate(EntityPlayer player, Vec3 pos)
{
if ( Platform.isClient() )
return true;

View file

@ -6,9 +6,7 @@ import java.io.IOException;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Vec3;
import net.minecraftforge.common.util.ForgeDirection;
import appeng.api.implementations.parts.IPartMonitor;
import appeng.api.networking.GridFlags;
@ -220,10 +218,4 @@ public class PartMonitor extends AEBasePart implements IPartMonitor
bch.addBox( 4, 4, 13, 12, 12, 14 );
}
@Override
public boolean onActivate(EntityPlayer player, Vec3 pos)
{
return false;
}
}

View file

@ -116,7 +116,7 @@ public class PartStorageMonitor extends PartMonitor implements IPartStorageMonit
}
@Override
public boolean onActivate(EntityPlayer player, Vec3 pos)
public boolean onPartActivate(EntityPlayer player, Vec3 pos)
{
if ( Platform.isClient() )
return true;

View file

@ -64,7 +64,7 @@ public class PartTerminal extends PartMonitor implements ITerminalHost, IConfigM
}
@Override
public boolean onActivate(EntityPlayer player, Vec3 pos)
public boolean onPartActivate(EntityPlayer player, Vec3 pos)
{
if ( !player.isSneaking() )
{

View file

@ -16,12 +16,7 @@ import appeng.api.recipes.IIngredient;
import appeng.api.recipes.IRecipeHandler;
import appeng.api.recipes.IRecipeLoader;
import appeng.core.AELog;
import appeng.recipes.handlers.Grind;
import appeng.recipes.handlers.OreRegistration;
import appeng.recipes.handlers.Pureify;
import appeng.recipes.handlers.Shaped;
import appeng.recipes.handlers.Shapeless;
import appeng.recipes.handlers.Smelt;
public class RecipeHandler implements IRecipeHandler
{
@ -213,7 +208,7 @@ public class RecipeHandler implements IRecipeHandler
try
{
IRecipeHandlerRegistry cr = AEApi.instance().registries().recipes();
if ( tokens.isEmpty() )
return;
@ -266,7 +261,7 @@ public class RecipeHandler implements IRecipeHandler
List<List<IIngredient>> inputs = parseLines( pre );
List<List<IIngredient>> outputs = parseLines( post );
ICraftHandler ch = cr.getCraftHandlerFor(operation);
ICraftHandler ch = cr.getCraftHandlerFor( operation );
if ( ch != null )
{

View file

@ -20,12 +20,17 @@ import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import appeng.api.implementations.tiles.ISegmentedInventory;
import appeng.api.util.ICommonTile;
import appeng.api.util.IConfigManager;
import appeng.api.util.IConfigureableObject;
import appeng.api.util.IOrientable;
import appeng.core.AELog;
import appeng.core.features.ItemStackSrc;
import appeng.helpers.IPriorityHost;
import appeng.tile.events.AETileEventHandler;
import appeng.tile.events.TileEventType;
import appeng.tile.inventory.AppEngInternalAEInventory;
import appeng.util.Platform;
import appeng.util.SettingsFrom;
@ -325,7 +330,31 @@ public class AEBaseTile extends TileEntity implements IOrientable, ICommonTile
*/
public void uploadSettings(SettingsFrom from, NBTTagCompound compound)
{
if ( compound != null && this instanceof IConfigureableObject )
{
IConfigManager cm = ((IConfigureableObject) this).getConfigManager();
if ( cm != null )
cm.readFromNBT( compound );
}
if ( this instanceof IPriorityHost )
{
IPriorityHost pHost = (IPriorityHost) this;
pHost.setPriority( compound.getInteger( "priority" ) );
}
if ( this instanceof ISegmentedInventory )
{
IInventory inv = ((ISegmentedInventory) this).getInventoryByName( "config" );
if ( inv != null && inv instanceof AppEngInternalAEInventory )
{
AppEngInternalAEInventory target = (AppEngInternalAEInventory) inv;
AppEngInternalAEInventory tmp = new AppEngInternalAEInventory( null, target.getSizeInventory() );
tmp.readFromNBT( compound, "config" );
for (int x = 0; x < tmp.getSizeInventory(); x++)
target.setInventorySlotContents( x, tmp.getStackInSlot( x ) );
}
}
}
/**
@ -336,7 +365,31 @@ public class AEBaseTile extends TileEntity implements IOrientable, ICommonTile
*/
public NBTTagCompound downloadSettings(SettingsFrom from)
{
return null;
NBTTagCompound output = new NBTTagCompound();
if ( this instanceof IConfigureableObject )
{
IConfigManager cm = ((IConfigureableObject) this).getConfigManager();
if ( cm != null )
cm.writeToNBT( output );
}
if ( this instanceof IPriorityHost )
{
IPriorityHost pHost = (IPriorityHost) this;
output.setInteger( "priority", pHost.getPriority() );
}
if ( this instanceof ISegmentedInventory )
{
IInventory inv = ((ISegmentedInventory) this).getInventoryByName( "config" );
if ( inv != null && inv instanceof AppEngInternalAEInventory )
{
((AppEngInternalAEInventory) inv).writeToNBT( output, "config" );
}
}
return output.hasNoTags() ? null : output;
}
public void securityBreak()