2013-12-27 23:59:59 +01:00
|
|
|
package appeng.items.tools;
|
|
|
|
|
|
|
|
import java.util.EnumSet;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
import net.minecraft.util.StatCollector;
|
2014-02-20 06:18:49 +01:00
|
|
|
import net.minecraft.world.World;
|
2014-01-23 20:02:48 +01:00
|
|
|
import appeng.api.implementations.items.IMemoryCard;
|
|
|
|
import appeng.api.implementations.items.MemoryCardMessages;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.core.features.AEFeature;
|
2014-01-30 19:54:32 +01:00
|
|
|
import appeng.core.localization.GuiText;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.core.localization.PlayerMessages;
|
|
|
|
import appeng.items.AEBaseItem;
|
|
|
|
import appeng.util.Platform;
|
|
|
|
|
|
|
|
public class ToolMemoryCard extends AEBaseItem implements IMemoryCard
|
|
|
|
{
|
|
|
|
|
|
|
|
public ToolMemoryCard() {
|
|
|
|
super( ToolMemoryCard.class );
|
|
|
|
setfeature( EnumSet.of( AEFeature.Core ) );
|
2014-01-20 17:41:37 +01:00
|
|
|
setMaxStackSize( 1 );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
2014-05-26 01:32:16 +02:00
|
|
|
/**
|
|
|
|
* 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 "";
|
|
|
|
}
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
@Override
|
|
|
|
public void addInformation(ItemStack i, EntityPlayer p, List l, boolean b)
|
|
|
|
{
|
2014-05-26 01:32:16 +02:00
|
|
|
l.add( getLocalizedName( getSettingsName( i ) + ".name", getSettingsName( i ) ) );
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
NBTTagCompound data = getData( i );
|
|
|
|
if ( data.hasKey( "tooltip" ) )
|
2014-05-26 01:32:16 +02:00
|
|
|
l.add( StatCollector.translateToLocal( getLocalizedName( data.getString( "tooltip" ) + ".name", data.getString( "tooltip" ) ) ) );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
2014-02-20 06:18:49 +01:00
|
|
|
@Override
|
|
|
|
public boolean doesSneakBypassUse(World world, int x, int y, int z, EntityPlayer player)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
@Override
|
|
|
|
public void setMemoryCardContents(ItemStack is, String SettingsName, NBTTagCompound data)
|
|
|
|
{
|
|
|
|
NBTTagCompound c = Platform.openNbtData( is );
|
|
|
|
c.setString( "Config", SettingsName );
|
2014-02-09 02:34:52 +01:00
|
|
|
c.setTag( "Data", data );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getSettingsName(ItemStack is)
|
|
|
|
{
|
|
|
|
NBTTagCompound c = Platform.openNbtData( is );
|
|
|
|
String name = c.getString( "Config" );
|
2014-01-30 19:54:32 +01:00
|
|
|
return name == null || name == "" ? GuiText.Blank.getUnlocalized() : name;
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public NBTTagCompound getData(ItemStack is)
|
|
|
|
{
|
|
|
|
NBTTagCompound c = Platform.openNbtData( is );
|
|
|
|
NBTTagCompound o = c.getCompoundTag( "Data" );
|
|
|
|
if ( o == null )
|
|
|
|
o = new NBTTagCompound();
|
|
|
|
return (NBTTagCompound) o.copy();
|
|
|
|
}
|
|
|
|
|
2014-05-26 01:32:16 +02:00
|
|
|
@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 );
|
|
|
|
}
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
@Override
|
2014-01-30 22:06:26 +01:00
|
|
|
public void notifyUser(EntityPlayer player, MemoryCardMessages msg)
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-01-20 17:41:37 +01:00
|
|
|
if ( Platform.isClient() )
|
|
|
|
return;
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
switch (msg)
|
|
|
|
{
|
2014-05-26 01:32:16 +02:00
|
|
|
case SETTINGS_CLEARED:
|
|
|
|
player.addChatMessage( PlayerMessages.SettingCleared.get() );
|
|
|
|
break;
|
2013-12-27 23:59:59 +01:00
|
|
|
case INVALID_MACHINE:
|
2014-02-09 02:34:52 +01:00
|
|
|
player.addChatMessage( PlayerMessages.InvalidMachine.get() );
|
2013-12-27 23:59:59 +01:00
|
|
|
break;
|
|
|
|
case SETTINGS_LOADED:
|
2014-02-09 02:34:52 +01:00
|
|
|
player.addChatMessage( PlayerMessages.LoadedSettings.get() );
|
2013-12-27 23:59:59 +01:00
|
|
|
break;
|
|
|
|
case SETTINGS_SAVED:
|
2014-02-09 02:34:52 +01:00
|
|
|
player.addChatMessage( PlayerMessages.SavedSettings.get() );
|
2013-12-27 23:59:59 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|