Clear Memory Card When Shift Clicking on a non-machine / air.

Fixed Tooltip to properly localize names.
This commit is contained in:
AlgorithmX2 2014-05-25 18:32:16 -05:00
parent cbc2486161
commit 6b0fa0f142
5 changed files with 68 additions and 6 deletions

View file

@ -694,7 +694,7 @@ public class AEBaseBlock extends BlockContainer implements IAEFeature
{ {
memc.setMemoryCardContents( is, name, data ); memc.setMemoryCardContents( is, name, data );
memc.notifyUser( player, MemoryCardMessages.SETTINGS_SAVED ); memc.notifyUser( player, MemoryCardMessages.SETTINGS_SAVED );
return false; return true;
} }
} }
} }

View file

@ -7,7 +7,7 @@ public enum PlayerMessages
{ {
ChestCannotReadStorageCell, InvalidMachine, LoadedSettings, SavedSettings, MachineNotPowered, ChestCannotReadStorageCell, InvalidMachine, LoadedSettings, SavedSettings, MachineNotPowered,
isNowLocked, isNowUnlocked, AmmoDepleted, CommunicationError, OutOfRange, DeviceNotPowered; isNowLocked, isNowUnlocked, AmmoDepleted, CommunicationError, OutOfRange, DeviceNotPowered, SettingCleared;
String getName() String getName()
{ {

View file

@ -7,6 +7,9 @@ import java.io.IOException;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack; 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.AppEngPacket;
import appeng.core.sync.network.INetworkInfo; import appeng.core.sync.network.INetworkInfo;
import appeng.items.tools.ToolNetworkTool; import appeng.items.tools.ToolNetworkTool;
@ -37,6 +40,12 @@ public class PacketClick extends AppEngPacket
ToolNetworkTool tnt = (ToolNetworkTool) is.getItem(); ToolNetworkTool tnt = (ToolNetworkTool) is.getItem();
tnt.serverSideToolLogic( is, player, player.worldObj, x, y, z, side, hitX, hitY, hitZ ); 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 // api

View file

@ -25,15 +25,35 @@ public class ToolMemoryCard extends AEBaseItem implements IMemoryCard
setMaxStackSize( 1 ); 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 @Override
public void addInformation(ItemStack i, EntityPlayer p, List l, boolean b) 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 ); NBTTagCompound data = getData( i );
if ( data.hasKey( "tooltip" ) ) if ( data.hasKey( "tooltip" ) )
{ l.add( StatCollector.translateToLocal( getLocalizedName( data.getString( "tooltip" ) + ".name", data.getString( "tooltip" ) ) ) );
l.add( StatCollector.translateToLocal( data.getString( "tooltip" ) ) );
}
} }
@Override @Override
@ -68,6 +88,20 @@ public class ToolMemoryCard extends AEBaseItem implements IMemoryCard
return (NBTTagCompound) o.copy(); 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 @Override
public void notifyUser(EntityPlayer player, MemoryCardMessages msg) public void notifyUser(EntityPlayer player, MemoryCardMessages msg)
{ {
@ -76,6 +110,9 @@ public class ToolMemoryCard extends AEBaseItem implements IMemoryCard
switch (msg) switch (msg)
{ {
case SETTINGS_CLEARED:
player.addChatMessage( PlayerMessages.SettingCleared.get() );
break;
case INVALID_MACHINE: case INVALID_MACHINE:
player.addChatMessage( PlayerMessages.InvalidMachine.get() ); player.addChatMessage( PlayerMessages.InvalidMachine.get() );
break; break;

View file

@ -28,6 +28,7 @@ import appeng.api.parts.SelectedPart;
import appeng.core.AELog; import appeng.core.AELog;
import appeng.core.AppEng; import appeng.core.AppEng;
import appeng.core.sync.network.NetworkHandler; import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.PacketClick;
import appeng.core.sync.packets.PacketPartPlacement; import appeng.core.sync.packets.PacketPartPlacement;
import appeng.facade.IFacadeItem; import appeng.facade.IFacadeItem;
import appeng.integration.abstraction.IBC; import appeng.integration.abstraction.IBC;
@ -61,6 +62,21 @@ public class PartPlacement
if ( te instanceof IPartHost ) if ( te instanceof IPartHost )
event.setCanceled( true ); 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 ) else if ( event.action == Action.RIGHT_CLICK_BLOCK && event.entityPlayer.worldObj.isRemote )
{ {