Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.nosrick.minersgotchi.entities;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.Map.Entry;
- import java.util.Random;
- import java.util.UUID;
- import assets.minersgotchi.models.entities.ModelBabyGotchiEntity;
- import com.nosrick.minersgotchi.ai.GotchiAIFollowOwner;
- import com.nosrick.minersgotchi.blocks.GotchiBlockRegistry;
- import com.nosrick.minersgotchi.blocks.GotchiPoopBlock;
- import com.nosrick.minersgotchi.needs.GotchiNeed;
- import com.nosrick.minersgotchi.needs.GotchiNeedsManager;
- import com.nosrick.minersgotchi.types.BaseGotchiType;
- import com.nosrick.minersgotchi.types.BasicBabyGotchiType;
- import net.minecraft.block.BlockClay;
- import net.minecraft.block.material.Material;
- import net.minecraft.entity.EntityCreature;
- import net.minecraft.entity.SharedMonsterAttributes;
- import net.minecraft.entity.ai.EntityAIEatGrass;
- import net.minecraft.entity.ai.EntityAIFollowOwner;
- import net.minecraft.entity.ai.EntityAIHurtByTarget;
- import net.minecraft.entity.ai.EntityAILookIdle;
- import net.minecraft.entity.ai.EntityAIOwnerHurtByTarget;
- import net.minecraft.entity.ai.EntityAIOwnerHurtTarget;
- import net.minecraft.entity.ai.EntityAISwimming;
- import net.minecraft.entity.ai.EntityAIWander;
- import net.minecraft.entity.ai.EntityAIWatchClosest;
- import net.minecraft.entity.passive.EntityTameable;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.init.Blocks;
- import net.minecraft.init.Items;
- import net.minecraft.item.Item;
- import net.minecraft.item.ItemFood;
- import net.minecraft.item.ItemStack;
- import net.minecraft.nbt.NBTTagCompound;
- import net.minecraft.server.MinecraftServer;
- import net.minecraft.world.World;
- import net.minecraftforge.common.IExtendedEntityProperties;
- public class BaseGotchiEntity extends EntityCreature
- {
- public final static String name = "BaseGotchiEntity";
- protected int m_Age;
- protected int m_AgeTimer;
- protected final int AGETIMER_MAX = 100;
- protected final int NEEDTIMER_MAX = 1200;
- protected UUID m_OwnerID;
- protected int m_OwnerDimension;
- protected GotchiAIFollowOwner m_FollowAI;
- protected BaseGotchiType m_Type;
- public BaseGotchiEntity(World worldRef)
- {
- super(worldRef);
- m_Age = 0;
- m_AgeTimer = 0;
- m_OwnerID = null;
- m_OwnerDimension = 0;
- Random roller = new Random();
- getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(40.0D);
- getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.4D);
- HashMap<String, GotchiNeed> needs = new HashMap<String, GotchiNeed>();
- needs.put("Hunger", new GotchiNeed("Hunger", roller.nextInt(11), NEEDTIMER_MAX));
- needs.put("Poop", new GotchiNeed("Poop", roller.nextInt(11), NEEDTIMER_MAX));
- m_Type = new BasicBabyGotchiType(new GotchiNeedsManager(needs), new ModelBabyGotchiEntity(), "BabyGotchiEntity.png");
- this.isImmuneToFire = true;
- m_FollowAI = new GotchiAIFollowOwner(this, m_OwnerID, 0.5D, 10.0F, 2.0F);
- this.tasks.addTask(1, m_FollowAI);
- this.tasks.addTask(2, new EntityAIEatGrass(this));
- this.tasks.addTask(3, new EntityAISwimming(this));
- this.tasks.addTask(4, new EntityAIWatchClosest(this, EntityPlayer.class, 8.0F));
- this.tasks.addTask(5, new EntityAILookIdle(this));
- this.tasks.addTask(6, new EntityAIWander(this, 1.0F));
- this.targetTasks.addTask(1, new EntityAIHurtByTarget(this, true));
- }
- public BaseGotchiEntity(World worldRef, String ownerIDRef)
- {
- super(worldRef);
- m_Age = 0;
- m_AgeTimer = 0;
- m_OwnerID = UUID.fromString(ownerIDRef);
- m_OwnerDimension = worldObj.func_152378_a(m_OwnerID).dimension;
- System.out.println("New Gotchi created");
- Random roller = new Random();
- getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(40.0D);
- getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.4D);
- HashMap<String, GotchiNeed> needs = new HashMap<String, GotchiNeed>();
- needs.put("Hunger", new GotchiNeed("Hunger", roller.nextInt(11), NEEDTIMER_MAX));
- needs.put("Poop", new GotchiNeed("Poop", roller.nextInt(11), NEEDTIMER_MAX));
- m_Type = new BasicBabyGotchiType(new GotchiNeedsManager(needs), new ModelBabyGotchiEntity(), "BabyGotchiEntity.png");
- this.isImmuneToFire = true;
- m_FollowAI = new GotchiAIFollowOwner(this, m_OwnerID, 1.0D, 2.0F, 10.0F);
- this.tasks.addTask(1, m_FollowAI);
- this.tasks.addTask(2, new EntityAIEatGrass(this));
- this.tasks.addTask(3, new EntityAISwimming(this));
- this.tasks.addTask(4, new EntityAIWatchClosest(this, EntityPlayer.class, 8.0F));
- this.tasks.addTask(5, new EntityAILookIdle(this));
- this.tasks.addTask(6, new EntityAIWander(this, 1.0F));
- this.targetTasks.addTask(1, new EntityAIHurtByTarget(this, true));
- }
- @Override
- public boolean isAIEnabled()
- {
- return true;
- }
- @Override
- public boolean interact(EntityPlayer playerRef)
- {
- ItemStack currentItemStack = playerRef.inventory.getCurrentItem();
- Item currentItem = currentItemStack.getItem();
- if(currentItem instanceof ItemFood)
- {
- ItemFood foodItem = (ItemFood)currentItemStack.getItem();
- currentItemStack.stackSize -= 1;
- m_Type.GetNeeds().SatisfyNeed("Hunger", foodItem.func_150905_g(currentItemStack));
- return true;
- }
- return false;
- }
- public void Poop()
- {
- if(!worldObj.isRemote && worldObj.getBlock((int)posX, (int)posY, (int)posZ) == Blocks.air)
- {
- Random roller = new Random();
- worldObj.setBlock((int)posX, (int)posY, (int)posZ, GotchiBlockRegistry.poopBlock);
- worldObj.markBlockForUpdate((int)posX, (int)posY, (int)posZ);
- m_Type.GetNeeds().SatisfyNeed("Poop", roller.nextInt(11));
- worldObj.playSoundAtEntity(this, "mob.chicken.plop", 1.0F, 1.0F);
- }
- }
- @Override
- public void writeEntityToNBT(NBTTagCompound compound)
- {
- System.out.println("Saving Gotchi");
- super.writeEntityToNBT(compound);
- compound.setInteger("age", m_Age);
- compound.setInteger("ageTimer", m_AgeTimer);
- compound.setString("ownerID", m_OwnerID.toString());
- EntityPlayer player = worldObj.func_152378_a(m_OwnerID);
- compound.setInteger("ownerDimension", player.dimension);
- m_Type.writeToNBT(compound);
- }
- @Override
- public void readEntityFromNBT(NBTTagCompound compound)
- {
- System.out.println("Loading Gotchi");
- super.readEntityFromNBT(compound);
- m_Age = compound.getInteger("age");
- m_AgeTimer = compound.getInteger("ageTimer");
- m_OwnerID = UUID.fromString(compound.getString("ownerID"));
- m_Type.readFromNBT(compound);
- m_OwnerDimension = compound.getInteger("ownerDimension");
- m_FollowAI.SetOwner(m_OwnerID, m_OwnerDimension);
- }
- @Override
- public void onEntityUpdate()
- {
- super.onEntityUpdate();
- if(!worldObj.isRemote)
- {
- m_Type.Update();
- if(m_Type.GetNeeds().GetSatisfaction("Poop") == 0)
- {
- this.Poop();
- }
- m_AgeTimer += 1;
- if(m_AgeTimer == AGETIMER_MAX)
- {
- m_Age += 1;
- m_AgeTimer = 0;
- ArrayList<BaseGotchiType> evolutions = m_Type.GetPossibleEvolutions(m_Age);
- if(!evolutions.isEmpty())
- {
- m_Type.AgeUp(evolutions.get(evolutions.size() - 1));
- }
- }
- }
- }
- //Eat grass to restore hunger
- @Override
- public void eatGrassBonus()
- {
- m_Type.GetNeeds().SatisfyNeed("Hunger", 5);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement