Advertisement
Guest User

Untitled

a guest
Nov 16th, 2015
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.46 KB | None | 0 0
  1. package rox.whistle;
  2.  
  3. import java.util.List;
  4.  
  5. import net.minecraft.creativetab.CreativeTabs;
  6. import net.minecraft.entity.passive.EntityWolf;
  7. import net.minecraft.entity.player.EntityPlayer;
  8. import net.minecraft.item.Item;
  9. import net.minecraft.item.ItemStack;
  10. import net.minecraft.util.AxisAlignedBB;
  11. import net.minecraft.util.ChatComponentText;
  12. import net.minecraft.world.World;
  13. import net.minecraftforge.fml.common.registry.GameRegistry;
  14.  
  15. public class SitWhistle extends Item {
  16.     //Item object reference.
  17.     public static Item sit_whistle;
  18.    
  19.     //Initialization method.
  20.     public static void init(){
  21.         //Assigning object to the object reference.
  22.         sit_whistle = new SitWhistle()
  23.             .setUnlocalizedName("sit_whistle")
  24.             .setMaxStackSize(1)
  25.             .setCreativeTab(CreativeTabs.tabTools);
  26.        
  27.         //Registering the item as this is called in Forge's preInit.
  28.         GameRegistry.registerItem(sit_whistle, sit_whistle.getUnlocalizedName().substring(5));
  29.     }
  30.    
  31.     //Overriding super's right click.
  32.     public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player){
  33.         //Getting a list of wolves within six blocks of the player.
  34.         List<?> e = player.worldObj.getEntitiesWithinAABB(EntityWolf.class, AxisAlignedBB.fromBounds(player.posX - 6, player.posY - 3, player.posZ - 6, player.posX + 6, player.posY + 3, player.posZ + 6));
  35.        
  36.         //If the list is empty, I want to catch it and tell the player that no wolves are in range.
  37.         if(e.isEmpty()){
  38.             if(!player.worldObj.isRemote){
  39.                 player.addChatMessage(new ChatComponentText("No wolves within range."));
  40.             }
  41.         }
  42.         //If the list is not empty, I want to check if the player is not sneaking.
  43.         else if(!player.isSneaking()){
  44.             for(int i = 0; i <= e.size(); i++){
  45.                 //If they aren't sneaking, I want to tell all wolves around him/her to stand up.
  46.                 EntityWolf wolf = (EntityWolf) e.get(i); //This is the problem line of code that the crash gives me.
  47.                 if(wolf.isTamed() && wolf.isOwner(player) && wolf.isSitting()){
  48.                     wolf.setSitting(false);
  49.                 }
  50.             }
  51.         }
  52.         //If they're not standing, then check if they're sneaking.
  53.         else if(player.isSneaking()){
  54.             for(int i = 0; i <= e.size(); i++){
  55.                 //If they're sneaking, I want to tell all wolves to sit.
  56.                 EntityWolf wolf = (EntityWolf)e.get(i);
  57.                 if(wolf.isOwner(player) && !wolf.isSitting()){
  58.                     wolf.setSitting(true);
  59.                 }
  60.             }
  61.         }
  62.        
  63.         //Return the item in it's original state since onItemRightClick needs a return statement.
  64.         return stack;
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement