Advertisement
Guest User

Untitled

a guest
May 16th, 2015
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.28 KB | None | 0 0
  1. package com.nosrick.minersgotchi.entities;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.HashMap;
  5. import java.util.Map.Entry;
  6. import java.util.Random;
  7. import java.util.UUID;
  8.  
  9. import assets.minersgotchi.models.entities.ModelBabyGotchiEntity;
  10.  
  11. import com.nosrick.minersgotchi.ai.GotchiAIFollowOwner;
  12. import com.nosrick.minersgotchi.blocks.GotchiBlockRegistry;
  13. import com.nosrick.minersgotchi.blocks.GotchiPoopBlock;
  14. import com.nosrick.minersgotchi.needs.GotchiNeed;
  15. import com.nosrick.minersgotchi.needs.GotchiNeedsManager;
  16. import com.nosrick.minersgotchi.types.BaseGotchiType;
  17. import com.nosrick.minersgotchi.types.BasicBabyGotchiType;
  18.  
  19. import net.minecraft.block.BlockClay;
  20. import net.minecraft.block.material.Material;
  21. import net.minecraft.entity.EntityCreature;
  22. import net.minecraft.entity.SharedMonsterAttributes;
  23. import net.minecraft.entity.ai.EntityAIEatGrass;
  24. import net.minecraft.entity.ai.EntityAIFollowOwner;
  25. import net.minecraft.entity.ai.EntityAIHurtByTarget;
  26. import net.minecraft.entity.ai.EntityAILookIdle;
  27. import net.minecraft.entity.ai.EntityAIOwnerHurtByTarget;
  28. import net.minecraft.entity.ai.EntityAIOwnerHurtTarget;
  29. import net.minecraft.entity.ai.EntityAISwimming;
  30. import net.minecraft.entity.ai.EntityAIWander;
  31. import net.minecraft.entity.ai.EntityAIWatchClosest;
  32. import net.minecraft.entity.passive.EntityTameable;
  33. import net.minecraft.entity.player.EntityPlayer;
  34. import net.minecraft.init.Blocks;
  35. import net.minecraft.init.Items;
  36. import net.minecraft.item.Item;
  37. import net.minecraft.item.ItemFood;
  38. import net.minecraft.item.ItemStack;
  39. import net.minecraft.nbt.NBTTagCompound;
  40. import net.minecraft.server.MinecraftServer;
  41. import net.minecraft.world.World;
  42. import net.minecraftforge.common.IExtendedEntityProperties;
  43.  
  44. public class BaseGotchiEntity extends EntityCreature
  45. {
  46.     public final static String name = "BaseGotchiEntity";
  47.    
  48.     protected int m_Age;
  49.     protected int m_AgeTimer;
  50.     protected final int AGETIMER_MAX = 100;
  51.    
  52.     protected final int NEEDTIMER_MAX = 1200;
  53.    
  54.     protected UUID m_OwnerID;
  55.     protected int m_OwnerDimension;
  56.    
  57.     protected GotchiAIFollowOwner m_FollowAI;
  58.    
  59.     protected BaseGotchiType m_Type;
  60.    
  61.     public BaseGotchiEntity(World worldRef)
  62.     {
  63.         super(worldRef);
  64.         m_Age = 0;
  65.         m_AgeTimer = 0;
  66.        
  67.         m_OwnerID = null;
  68.         m_OwnerDimension = 0;
  69.        
  70.         Random roller = new Random();
  71.        
  72.         getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(40.0D);
  73.         getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.4D);
  74.        
  75.         HashMap<String, GotchiNeed> needs = new HashMap<String, GotchiNeed>();
  76.        
  77.         needs.put("Hunger", new GotchiNeed("Hunger", roller.nextInt(11), NEEDTIMER_MAX));
  78.         needs.put("Poop", new GotchiNeed("Poop", roller.nextInt(11), NEEDTIMER_MAX));
  79.        
  80.         m_Type = new BasicBabyGotchiType(new GotchiNeedsManager(needs), new ModelBabyGotchiEntity(), "BabyGotchiEntity.png");
  81.        
  82.         this.isImmuneToFire = true;
  83.  
  84.         m_FollowAI = new GotchiAIFollowOwner(this, m_OwnerID, 0.5D, 10.0F, 2.0F);
  85.        
  86.         this.tasks.addTask(1, m_FollowAI);
  87.         this.tasks.addTask(2, new EntityAIEatGrass(this));
  88.         this.tasks.addTask(3, new EntityAISwimming(this));
  89.         this.tasks.addTask(4, new EntityAIWatchClosest(this, EntityPlayer.class, 8.0F));
  90.         this.tasks.addTask(5, new EntityAILookIdle(this));
  91.         this.tasks.addTask(6, new EntityAIWander(this, 1.0F));
  92.         this.targetTasks.addTask(1, new EntityAIHurtByTarget(this, true));
  93.     }
  94.    
  95.     public BaseGotchiEntity(World worldRef, String ownerIDRef)
  96.     {
  97.         super(worldRef);
  98.        
  99.         m_Age = 0;
  100.         m_AgeTimer = 0;
  101.        
  102.         m_OwnerID = UUID.fromString(ownerIDRef);
  103.         m_OwnerDimension = worldObj.func_152378_a(m_OwnerID).dimension;
  104.        
  105.         System.out.println("New Gotchi created");
  106.        
  107.         Random roller = new Random();
  108.  
  109.         getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(40.0D);
  110.         getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.4D);
  111.        
  112.         HashMap<String, GotchiNeed> needs = new HashMap<String, GotchiNeed>();
  113.        
  114.         needs.put("Hunger", new GotchiNeed("Hunger", roller.nextInt(11), NEEDTIMER_MAX));
  115.         needs.put("Poop", new GotchiNeed("Poop", roller.nextInt(11), NEEDTIMER_MAX));
  116.        
  117.         m_Type = new BasicBabyGotchiType(new GotchiNeedsManager(needs), new ModelBabyGotchiEntity(), "BabyGotchiEntity.png");
  118.        
  119.         this.isImmuneToFire = true;
  120.  
  121.         m_FollowAI = new GotchiAIFollowOwner(this, m_OwnerID, 1.0D, 2.0F, 10.0F);
  122.        
  123.         this.tasks.addTask(1, m_FollowAI);
  124.         this.tasks.addTask(2, new EntityAIEatGrass(this));
  125.         this.tasks.addTask(3, new EntityAISwimming(this));
  126.         this.tasks.addTask(4, new EntityAIWatchClosest(this, EntityPlayer.class, 8.0F));
  127.         this.tasks.addTask(5, new EntityAILookIdle(this));
  128.         this.tasks.addTask(6, new EntityAIWander(this, 1.0F));
  129.         this.targetTasks.addTask(1, new EntityAIHurtByTarget(this, true));
  130.     }
  131.    
  132.     @Override
  133.     public boolean isAIEnabled()
  134.     {
  135.         return true;
  136.     }
  137.    
  138.     @Override
  139.     public boolean interact(EntityPlayer playerRef)
  140.     {
  141.         ItemStack currentItemStack = playerRef.inventory.getCurrentItem();
  142.         Item currentItem = currentItemStack.getItem();
  143.        
  144.         if(currentItem instanceof ItemFood)
  145.         {
  146.             ItemFood foodItem = (ItemFood)currentItemStack.getItem();
  147.            
  148.             currentItemStack.stackSize -= 1;
  149.             m_Type.GetNeeds().SatisfyNeed("Hunger", foodItem.func_150905_g(currentItemStack));
  150.            
  151.             return true;
  152.         }
  153.        
  154.         return false;
  155.     }
  156.    
  157.     public void Poop()
  158.     {
  159.         if(!worldObj.isRemote && worldObj.getBlock((int)posX, (int)posY, (int)posZ) == Blocks.air)
  160.         {
  161.             Random roller = new Random();
  162.            
  163.             worldObj.setBlock((int)posX, (int)posY, (int)posZ, GotchiBlockRegistry.poopBlock);
  164.             worldObj.markBlockForUpdate((int)posX, (int)posY, (int)posZ);
  165.             m_Type.GetNeeds().SatisfyNeed("Poop", roller.nextInt(11));
  166.             worldObj.playSoundAtEntity(this, "mob.chicken.plop", 1.0F, 1.0F);
  167.         }
  168.     }
  169.    
  170.     @Override
  171.     public void writeEntityToNBT(NBTTagCompound compound)
  172.     {
  173.         System.out.println("Saving Gotchi");
  174.         super.writeEntityToNBT(compound);
  175.         compound.setInteger("age", m_Age);
  176.         compound.setInteger("ageTimer", m_AgeTimer);
  177.         compound.setString("ownerID", m_OwnerID.toString());
  178.        
  179.         EntityPlayer player = worldObj.func_152378_a(m_OwnerID);
  180.        
  181.         compound.setInteger("ownerDimension", player.dimension);
  182.         m_Type.writeToNBT(compound);
  183.     }
  184.    
  185.     @Override
  186.     public void readEntityFromNBT(NBTTagCompound compound)
  187.     {
  188.         System.out.println("Loading Gotchi");
  189.         super.readEntityFromNBT(compound);
  190.         m_Age = compound.getInteger("age");
  191.         m_AgeTimer = compound.getInteger("ageTimer");
  192.         m_OwnerID = UUID.fromString(compound.getString("ownerID"));
  193.         m_Type.readFromNBT(compound);
  194.         m_OwnerDimension = compound.getInteger("ownerDimension");
  195.        
  196.         m_FollowAI.SetOwner(m_OwnerID, m_OwnerDimension);
  197.     }
  198.    
  199.     @Override
  200.     public void onEntityUpdate()
  201.     {
  202.         super.onEntityUpdate();
  203.        
  204.         if(!worldObj.isRemote)
  205.         {
  206.             m_Type.Update();
  207.            
  208.             if(m_Type.GetNeeds().GetSatisfaction("Poop") == 0)
  209.             {
  210.                 this.Poop();
  211.             }
  212.            
  213.             m_AgeTimer += 1;
  214.            
  215.             if(m_AgeTimer == AGETIMER_MAX)
  216.             {
  217.                 m_Age += 1;
  218.                 m_AgeTimer = 0;
  219.                
  220.                 ArrayList<BaseGotchiType> evolutions = m_Type.GetPossibleEvolutions(m_Age);
  221.                 if(!evolutions.isEmpty())
  222.                 {
  223.                     m_Type.AgeUp(evolutions.get(evolutions.size() - 1));
  224.                 }
  225.             }
  226.         }
  227.     }
  228.    
  229.     //Eat grass to restore hunger
  230.     @Override
  231.     public void eatGrassBonus()
  232.     {
  233.         m_Type.GetNeeds().SatisfyNeed("Hunger", 5);
  234.     }
  235. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement