Guest User

Untitled

a guest
Jun 23rd, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.30 KB | None | 0 0
  1. package pinelabs.magic;
  2.  
  3. import dan200.computer.client.GuiComputer;
  4. import dan200.computer.shared.TileEntityComputer;
  5. import net.minecraft.src.EntityPlayer;
  6. import net.minecraft.src.Item;
  7. import net.minecraft.src.ItemStack;
  8. import net.minecraft.src.ModLoader;
  9. import net.minecraft.src.NBTTagCompound;
  10. import net.minecraft.src.World;
  11. import net.minecraft.src.mod_ComputerCraft;
  12. import net.minecraft.src.mod_ccmagic;
  13. import net.minecraft.src.forge.ITextureProvider;
  14.  
  15. public class ItemMagicRemote extends Item implements ITextureProvider {
  16.  
  17.     private int computerX;
  18.  
  19.     private int computerY;
  20.  
  21.     private int computerZ;
  22.  
  23.     private int computerID;
  24.  
  25.     private String computerName;
  26.  
  27.     private boolean isLinked = false;
  28.  
  29.     public ItemMagicRemote( int i ) {
  30.         super( i );
  31.         setIconIndex( 0 );
  32.         setItemName( "Magic Remote" );
  33.     }
  34.  
  35.     @Override
  36.     public int getItemStackLimit() {
  37.         return 1;
  38.     }
  39.  
  40.     @Override
  41.     public String getTextureFile() {
  42.         return mod_ccmagic.sprites;
  43.     }
  44.  
  45.     @Override
  46.     public boolean onItemUse( ItemStack itemstack, EntityPlayer entityplayer, World world, int i, int j, int k, int l ) {
  47.  
  48.         TileEntityComputer tileentitycomputer = (TileEntityComputer) world.getBlockTileEntity( i, j, k ); // l is
  49.         // clicked
  50.         if ( tileentitycomputer != null ) {
  51.             logMsg( "Linking Computer" );
  52.             computerX = i;
  53.             computerY = j;
  54.             computerZ = k;
  55.             computerID = tileentitycomputer.getComputerID();
  56.  
  57.             NBTTagCompound nbttagcompound = new NBTTagCompound();
  58.             if (itemstack.stackTagCompound == null)
  59.             {
  60.                     itemstack.setTagCompound(new NBTTagCompound());
  61.             }
  62.             nbttagcompound.setInteger( "x", computerX );
  63.             nbttagcompound.setInteger( "y", computerY );
  64.             nbttagcompound.setInteger( "z", computerZ );
  65.             nbttagcompound.setInteger( "id", computerID );
  66.  
  67.             itemstack.setTagCompound( nbttagcompound ); // magic ???
  68.             itemstack.writeToNBT( nbttagcompound );
  69.  
  70.             isLinked = true;
  71.             logMsg( "using computer id: " + computerID );
  72.         }
  73.  
  74.         // ModLoader.getMinecraftInstance().ingameGUI.addChatMessage( "i: " + i + " j: " + j + " k: " + k + " l: " + l
  75.         // );
  76.         return true;
  77.  
  78.     }
  79.  
  80.     private void logMsg( String s ) {
  81.         ModLoader.getMinecraftInstance().ingameGUI.addChatMessage( s );
  82.     }
  83.  
  84.     public ItemStack onItemRightClick( ItemStack itemstack, World world, EntityPlayer entityplayer ) {
  85.         if ( !isLinked ) {
  86.             logMsg( "Attempting to load" );
  87.             NBTTagCompound nbttagcompound = new NBTTagCompound();
  88.             itemstack.readFromNBT( nbttagcompound );
  89.             if ( nbttagcompound.hasKey( "id" ) ) {
  90.                 computerID = nbttagcompound.getInteger( "id" );
  91.                 computerX = nbttagcompound.getInteger( "x" );
  92.                 computerY = nbttagcompound.getInteger( "y" );
  93.                 computerZ = nbttagcompound.getInteger( "z" );
  94.                 logMsg( "using computer id: " + computerID  );
  95.             } else {
  96.                 return ( new ItemStack( mod_ccmagic.itemMagicRemote ) ); // were not linked
  97.             }
  98.  
  99.         }
  100.  
  101.         logMsg( "Prepare to die" );
  102.         TileEntityComputer tileentitycomputer = (TileEntityComputer) world.getBlockTileEntity( computerX, computerY,
  103.                                                                                                computerZ );
  104.         if ( tileentitycomputer != null ) {
  105.             // Problems with mod_ComputerCraft Access
  106.             // mod_ComputerCraft.openComputerGUI(entityplayer, tileentitycomputer);
  107.             GuiComputer guicomputer = new GuiComputer( tileentitycomputer );
  108.             ModLoader.OpenGUI( entityplayer, guicomputer );
  109.             tileentitycomputer.turnOn();
  110.             tileentitycomputer.updateClient( entityplayer );
  111.         }
  112.  
  113.         // ModLoader.getMinecraftInstance().ingameGUI.addChatMessage( "TODO: activate terminal" );
  114.         return itemstack;
  115.     }
  116.  
  117.     public void readFromNBT( NBTTagCompound nbttagcompound ) { // you can empty all these they really arnt needed
  118.     }
  119.  
  120.     public void writeToNBT( NBTTagCompound nbttagcompound ) {
  121.     }
  122.  
  123. }
Add Comment
Please, Sign In to add comment