diff --git a/block/AEBaseBlock.java b/block/AEBaseBlock.java index 8088535b..fc6c1d93 100644 --- a/block/AEBaseBlock.java +++ b/block/AEBaseBlock.java @@ -694,7 +694,7 @@ public class AEBaseBlock extends BlockContainer implements IAEFeature { memc.setMemoryCardContents( is, name, data ); memc.notifyUser( player, MemoryCardMessages.SETTINGS_SAVED ); - return false; + return true; } } } diff --git a/core/localization/PlayerMessages.java b/core/localization/PlayerMessages.java index 56bb615b..64424fba 100644 --- a/core/localization/PlayerMessages.java +++ b/core/localization/PlayerMessages.java @@ -7,7 +7,7 @@ public enum PlayerMessages { ChestCannotReadStorageCell, InvalidMachine, LoadedSettings, SavedSettings, MachineNotPowered, - isNowLocked, isNowUnlocked, AmmoDepleted, CommunicationError, OutOfRange, DeviceNotPowered; + isNowLocked, isNowUnlocked, AmmoDepleted, CommunicationError, OutOfRange, DeviceNotPowered, SettingCleared; String getName() { diff --git a/core/sync/packets/PacketClick.java b/core/sync/packets/PacketClick.java index e2d1c1a1..63b5b169 100644 --- a/core/sync/packets/PacketClick.java +++ b/core/sync/packets/PacketClick.java @@ -7,6 +7,9 @@ import java.io.IOException; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; +import appeng.api.AEApi; +import appeng.api.implementations.items.IMemoryCard; +import appeng.api.implementations.items.MemoryCardMessages; import appeng.core.sync.AppEngPacket; import appeng.core.sync.network.INetworkInfo; import appeng.items.tools.ToolNetworkTool; @@ -37,6 +40,12 @@ public class PacketClick extends AppEngPacket ToolNetworkTool tnt = (ToolNetworkTool) is.getItem(); tnt.serverSideToolLogic( is, player, player.worldObj, x, y, z, side, hitX, hitY, hitZ ); } + else if ( is != null && AEApi.instance().items().itemMemoryCard.sameAs( is ) ) + { + IMemoryCard mem = (IMemoryCard) is.getItem(); + mem.notifyUser( player, MemoryCardMessages.SETTINGS_CLEARED ); + is.setTagCompound( null ); + } } // api diff --git a/items/tools/ToolMemoryCard.java b/items/tools/ToolMemoryCard.java index 90a8d36a..1d820c32 100644 --- a/items/tools/ToolMemoryCard.java +++ b/items/tools/ToolMemoryCard.java @@ -25,15 +25,35 @@ public class ToolMemoryCard extends AEBaseItem implements IMemoryCard setMaxStackSize( 1 ); } + /** + * Find the localized string... + * + * @param name + * @return + */ + private String getLocalizedName(String... name) + { + for (String n : name) + { + String l = StatCollector.translateToLocal( n ); + if ( !l.equals( n ) ) + return l; + } + + for (String n : name) + return n; + + return ""; + } + @Override public void addInformation(ItemStack i, EntityPlayer p, List l, boolean b) { - l.add( StatCollector.translateToLocal( getSettingsName( i ) ) ); + l.add( getLocalizedName( getSettingsName( i ) + ".name", getSettingsName( i ) ) ); + NBTTagCompound data = getData( i ); if ( data.hasKey( "tooltip" ) ) - { - l.add( StatCollector.translateToLocal( data.getString( "tooltip" ) ) ); - } + l.add( StatCollector.translateToLocal( getLocalizedName( data.getString( "tooltip" ) + ".name", data.getString( "tooltip" ) ) ) ); } @Override @@ -68,6 +88,20 @@ public class ToolMemoryCard extends AEBaseItem implements IMemoryCard return (NBTTagCompound) o.copy(); } + @Override + public boolean onItemUse(ItemStack is, EntityPlayer player, World w, int x, int y, int z, int side, float hx, float hy, float hz) + { + if ( player.isSneaking() && !w.isRemote ) + { + IMemoryCard mem = (IMemoryCard) is.getItem(); + mem.notifyUser( player, MemoryCardMessages.SETTINGS_CLEARED ); + is.setTagCompound( null ); + return true; + } + else + return super.onItemUse( is, player, w, x, y, z, side, hx, hy, hz ); + } + @Override public void notifyUser(EntityPlayer player, MemoryCardMessages msg) { @@ -76,6 +110,9 @@ public class ToolMemoryCard extends AEBaseItem implements IMemoryCard switch (msg) { + case SETTINGS_CLEARED: + player.addChatMessage( PlayerMessages.SettingCleared.get() ); + break; case INVALID_MACHINE: player.addChatMessage( PlayerMessages.InvalidMachine.get() ); break; diff --git a/parts/PartPlacement.java b/parts/PartPlacement.java index f942ce4c..aea4aa16 100644 --- a/parts/PartPlacement.java +++ b/parts/PartPlacement.java @@ -28,6 +28,7 @@ import appeng.api.parts.SelectedPart; import appeng.core.AELog; import appeng.core.AppEng; import appeng.core.sync.network.NetworkHandler; +import appeng.core.sync.packets.PacketClick; import appeng.core.sync.packets.PacketPartPlacement; import appeng.facade.IFacadeItem; import appeng.integration.abstraction.IBC; @@ -61,6 +62,21 @@ public class PartPlacement if ( te instanceof IPartHost ) event.setCanceled( true ); } + else if ( event.entityPlayer != null ) + { + ItemStack held = event.entityPlayer.getHeldItem(); + if ( event.entityPlayer.isSneaking() && held != null && AEApi.instance().items().itemMemoryCard.sameAs( held ) ) + { + try + { + NetworkHandler.instance.sendToServer( new PacketClick( event.x, event.y, event.z, event.face, 0, 0, 0 ) ); + } + catch (IOException e) + { + // :P + } + } + } } else if ( event.action == Action.RIGHT_CLICK_BLOCK && event.entityPlayer.worldObj.isRemote ) {