Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package pinelabs.magic;
- import dan200.computer.client.GuiComputer;
- import dan200.computer.shared.TileEntityComputer;
- import net.minecraft.src.EntityPlayer;
- import net.minecraft.src.Item;
- import net.minecraft.src.ItemStack;
- import net.minecraft.src.ModLoader;
- import net.minecraft.src.NBTTagCompound;
- import net.minecraft.src.World;
- import net.minecraft.src.mod_ComputerCraft;
- import net.minecraft.src.mod_ccmagic;
- import net.minecraft.src.forge.ITextureProvider;
- public class ItemMagicRemote extends Item implements ITextureProvider {
- private int computerX;
- private int computerY;
- private int computerZ;
- private int computerID;
- private String computerName;
- private boolean isLinked = false;
- public ItemMagicRemote( int i ) {
- super( i );
- setIconIndex( 0 );
- setItemName( "Magic Remote" );
- }
- @Override
- public int getItemStackLimit() {
- return 1;
- }
- @Override
- public String getTextureFile() {
- return mod_ccmagic.sprites;
- }
- @Override
- public boolean onItemUse( ItemStack itemstack, EntityPlayer entityplayer, World world, int i, int j, int k, int l ) {
- TileEntityComputer tileentitycomputer = (TileEntityComputer) world.getBlockTileEntity( i, j, k ); // l is
- // clicked
- if ( tileentitycomputer != null ) {
- logMsg( "Linking Computer" );
- computerX = i;
- computerY = j;
- computerZ = k;
- computerID = tileentitycomputer.getComputerID();
- NBTTagCompound nbttagcompound = new NBTTagCompound();
- if (itemstack.stackTagCompound == null)
- {
- itemstack.setTagCompound(new NBTTagCompound());
- }
- nbttagcompound.setInteger( "x", computerX );
- nbttagcompound.setInteger( "y", computerY );
- nbttagcompound.setInteger( "z", computerZ );
- nbttagcompound.setInteger( "id", computerID );
- itemstack.setTagCompound( nbttagcompound ); // magic ???
- itemstack.writeToNBT( nbttagcompound );
- isLinked = true;
- logMsg( "using computer id: " + computerID );
- }
- // ModLoader.getMinecraftInstance().ingameGUI.addChatMessage( "i: " + i + " j: " + j + " k: " + k + " l: " + l
- // );
- return true;
- }
- private void logMsg( String s ) {
- ModLoader.getMinecraftInstance().ingameGUI.addChatMessage( s );
- }
- public ItemStack onItemRightClick( ItemStack itemstack, World world, EntityPlayer entityplayer ) {
- if ( !isLinked ) {
- logMsg( "Attempting to load" );
- NBTTagCompound nbttagcompound = new NBTTagCompound();
- itemstack.readFromNBT( nbttagcompound );
- if ( nbttagcompound.hasKey( "id" ) ) {
- computerID = nbttagcompound.getInteger( "id" );
- computerX = nbttagcompound.getInteger( "x" );
- computerY = nbttagcompound.getInteger( "y" );
- computerZ = nbttagcompound.getInteger( "z" );
- logMsg( "using computer id: " + computerID );
- } else {
- return ( new ItemStack( mod_ccmagic.itemMagicRemote ) ); // were not linked
- }
- }
- logMsg( "Prepare to die" );
- TileEntityComputer tileentitycomputer = (TileEntityComputer) world.getBlockTileEntity( computerX, computerY,
- computerZ );
- if ( tileentitycomputer != null ) {
- // Problems with mod_ComputerCraft Access
- // mod_ComputerCraft.openComputerGUI(entityplayer, tileentitycomputer);
- GuiComputer guicomputer = new GuiComputer( tileentitycomputer );
- ModLoader.OpenGUI( entityplayer, guicomputer );
- tileentitycomputer.turnOn();
- tileentitycomputer.updateClient( entityplayer );
- }
- // ModLoader.getMinecraftInstance().ingameGUI.addChatMessage( "TODO: activate terminal" );
- return itemstack;
- }
- public void readFromNBT( NBTTagCompound nbttagcompound ) { // you can empty all these they really arnt needed
- }
- public void writeToNBT( NBTTagCompound nbttagcompound ) {
- }
- }
Add Comment
Please, Sign In to add comment