Guest User

EntityNPC.class

a guest
Oct 18th, 2016
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 22.12 KB | None | 0 0
  1. package net.rexozz.pixelengine.entity;
  2.  
  3. import net.minecraft.entity.Entity;
  4. import net.minecraft.entity.EntityLiving;
  5. import net.minecraft.entity.INpc;
  6. import net.minecraft.entity.SharedMonsterAttributes;
  7. import net.minecraft.entity.ai.EntityAIAttackMelee;
  8. import net.minecraft.entity.ai.EntityAIBase;
  9. import net.minecraft.entity.ai.EntityAIFleeSun;
  10. import net.minecraft.entity.ai.EntityAIHurtByTarget;
  11. import net.minecraft.entity.ai.EntityAILookIdle;
  12. import net.minecraft.entity.ai.EntityAINearestAttackableTarget;
  13. import net.minecraft.entity.ai.EntityAIRestrictSun;
  14. import net.minecraft.entity.ai.EntityAISwimming;
  15. import net.minecraft.entity.ai.EntityAIWander;
  16. import net.minecraft.entity.item.EntityBoat;
  17. import net.minecraft.entity.player.EntityPlayer;
  18. import net.minecraft.entity.player.EntityPlayerMP;
  19. import net.minecraft.inventory.EntityEquipmentSlot;
  20. import net.minecraft.inventory.IInventory;
  21. import net.minecraft.inventory.IInventoryChangedListener;
  22. import net.minecraft.inventory.InventoryBasic;
  23. import net.minecraft.item.ItemStack;
  24. import net.minecraft.nbt.NBTTagCompound;
  25. import net.minecraft.nbt.NBTTagList;
  26. import net.minecraft.network.datasync.DataParameter;
  27. import net.minecraft.network.datasync.DataSerializers;
  28. import net.minecraft.network.datasync.EntityDataManager;
  29. import net.minecraft.util.DamageSource;
  30. import net.minecraft.util.EnumHand;
  31. import net.minecraft.util.ResourceLocation;
  32. import net.minecraft.util.SoundEvent;
  33. import net.minecraft.util.math.BlockPos;
  34. import net.minecraft.world.World;
  35. import net.rexozz.pixelengine.PEGuiHandler;
  36. import net.rexozz.pixelengine.PEItems;
  37. import net.rexozz.pixelengine.PixelEngine;
  38. import net.rexozz.pixelengine.entity.ai.EntityAISwitchable;
  39. import net.rexozz.pixelengine.entity.ai.EntityAITargetSwitchable;
  40. import net.rexozz.pixelengine.entity.ai.EntityAIWatchClosestAdvanced;
  41. import net.rexozz.pixelengine.network.C01PacketOpenNPCGui;
  42. import net.rexozz.pixelengine.network.PacketHandler;
  43. import net.rexozz.pixelengine.server.container.ContainerNPC;
  44.  
  45. public class EntityNPC extends PEEntityCreature implements INpc, IInventoryChangedListener{
  46.    
  47.     /**Method to use bitflags
  48.     public static final int REVENGE=1, FIRE_IMMUNE=2, CAN_BREATH=4, FALL_DAMAGE=8, CAN_SWIM=16;
  49.    
  50.     private static int flags=0;
  51.    
  52.     private boolean getValue(int type){
  53.         return (this.dataManager.get(DATA_FLAGS)&type)==type;
  54.     }
  55.    
  56.     private void setValue(int type, boolean value){
  57.         int flags=this.dataManager.get(DATA_FLAGS);
  58.         if(value)
  59.             flags=flags|type;
  60.         else
  61.             flags=flags&~type;
  62.         this.dataManager.set(DATA_FLAGS, flags);
  63.     }**/
  64.    
  65.     //private static final DataParameter<Integer> DATA_FLAGS=EntityDataManager.<Integer>createKey(EntityNPC.class, DataSerializers.VARINT);
  66.     private static final DataParameter<String> DATA_TEXTURE=EntityDataManager.<String>createKey(EntityNPC.class, DataSerializers.STRING);
  67.     private static final DataParameter<Integer> DATA_SUN_MODE=EntityDataManager.<Integer>createKey(EntityNPC.class, DataSerializers.VARINT);
  68.     private static final DataParameter<String> DATA_DEATH_SOUND=EntityDataManager.<String>createKey(EntityNPC.class, DataSerializers.STRING);
  69.     private static final DataParameter<String> DATA_HIT_SOUND=EntityDataManager.<String>createKey(EntityNPC.class, DataSerializers.STRING);
  70.     private static final DataParameter<Integer> DATA_LOOK_MODE=EntityDataManager.<Integer>createKey(EntityNPC.class, DataSerializers.VARINT);
  71.     private static final DataParameter<Float> DATA_LOOK_RANGE=EntityDataManager.<Float>createKey(EntityNPC.class, DataSerializers.FLOAT);
  72.     private static final DataParameter<Integer> DATA_WALK_MODE=EntityDataManager.<Integer>createKey(EntityNPC.class, DataSerializers.VARINT);
  73.     private static final DataParameter<Integer> DATA_ATTACK=EntityDataManager.<Integer>createKey(EntityNPC.class, DataSerializers.VARINT);
  74.     private static final DataParameter<Boolean> DATA_FIRE_IMMUNE=EntityDataManager.<Boolean>createKey(EntityNPC.class, DataSerializers.BOOLEAN);
  75.     private static final DataParameter<Boolean> DATA_CAN_BREATHE=EntityDataManager.<Boolean>createKey(EntityNPC.class, DataSerializers.BOOLEAN);
  76.     private static final DataParameter<Boolean> DATA_FALL_DAMAGE=EntityDataManager.<Boolean>createKey(EntityNPC.class, DataSerializers.BOOLEAN);
  77.     private static final DataParameter<Boolean> DATA_CAN_SWIM=EntityDataManager.<Boolean>createKey(EntityNPC.class, DataSerializers.BOOLEAN);
  78.    
  79.     private int interactlevel=0;
  80.     private EntityAISwitchable swimAI;
  81.     private EntityAISwitchable fleeSun;
  82.     private EntityAISwitchable restrictSun;
  83.     private EntityAIWatchClosestAdvanced lookPlayer;
  84.     private EntityAISwitchable lookIdle;
  85.     private EntityAISwitchable wander;
  86.     private EntityAITargetSwitchable revenge;
  87.     private EntityAITargetSwitchable nearest;
  88.    
  89.     public InventoryBasic inventory;
  90.    
  91.     private double maxHealth;
  92.     private double movespeed;
  93.     private double attackspeed;
  94.     private double armor;
  95.     private double armortoughness;
  96.    
  97.     public EntityNPC(World world){
  98.         super(world);
  99.         this.setCustomNameTag("NPC");
  100.         this.setSize(1.0f, 2.0f);
  101.         this.setAlwaysRenderNameTag(true);
  102.         this.initInv();
  103.     }
  104.    
  105.     private void initInv() {
  106.         InventoryBasic inv=this.inventory;
  107.         this.inventory=new InventoryBasic("InventoryNPC", false, 12);
  108.         this.inventory.setCustomName(this.getName());
  109.  
  110.         if (inv!=null){
  111.             inv.removeInventoryChangeListener(this);
  112.             int i = Math.min(inv.getSizeInventory(), this.inventory.getSizeInventory());
  113.  
  114.             for (int j = 0; j < i; ++j){
  115.                 ItemStack itemstack=inv.getStackInSlot(j);
  116.  
  117.                 if (itemstack != null)
  118.                     this.inventory.setInventorySlotContents(j, itemstack.copy());
  119.             }
  120.         }
  121.  
  122.         this.inventory.addInventoryChangeListener(this);
  123.     }
  124.  
  125.     private void openGui(EntityPlayer player){
  126.         EntityPlayerMP playerMP=(EntityPlayerMP)player;
  127.  
  128.         playerMP.getNextWindowId();
  129.         PacketHandler.sendTo(new C01PacketOpenNPCGui(playerMP.currentWindowId, this.inventory.getDisplayName(), this.inventory.getSizeInventory(), this.getEntityId()), playerMP);
  130.         playerMP.openContainer = new ContainerNPC(playerMP.inventory, this.inventory, this, playerMP);
  131.         playerMP.openContainer.windowId = playerMP.currentWindowId;
  132.         playerMP.openContainer.addListener(playerMP);
  133.     }
  134.    
  135.     @SuppressWarnings({ "unchecked", "rawtypes" })
  136.     protected void initEntityAI() {
  137.         this.targetTasks.taskEntries.clear();
  138.         this.swimAI=new EntityAISwitchable(new EntityAISwimming(this), true);
  139.         this.fleeSun=new EntityAISwitchable(new EntityAIFleeSun(this, 1.0D), false);
  140.         this.restrictSun=new EntityAISwitchable(new EntityAIRestrictSun(this), false);
  141.         this.lookIdle=new EntityAISwitchable(new EntityAILookIdle(this), true);
  142.         this.lookPlayer=new EntityAIWatchClosestAdvanced(this, EntityPlayer.class, 5.0f, 1.0f, false);
  143.         this.wander=new EntityAISwitchable(new EntityAIWander(this, 1.0D, 60), false);
  144.         this.revenge=new EntityAITargetSwitchable(this, new EntityAIHurtByTarget(this, false), false);
  145.         this.nearest=new EntityAITargetSwitchable(this, new EntityAINearestAttackableTarget(this, EntityPlayer.class, true), false);
  146.         this.tasks.addTask(1, this.swimAI);
  147.         this.tasks.addTask(2, this.restrictSun);
  148.         this.tasks.addTask(3, new EntityAIAttackMelee(this, 1.2D, false));
  149.         this.tasks.addTask(3, this.fleeSun);
  150.         this.tasks.addTask(4, this.wander);
  151.         this.tasks.addTask(6, this.lookIdle);
  152.         this.tasks.addTask(6, this.lookPlayer);
  153.         this.targetTasks.addTask(0, this.revenge);
  154.         this.targetTasks.addTask(1, this.nearest);
  155.     }
  156.    
  157.     private void changeAI(EntityAIBase ai, boolean value){
  158.         if(ai instanceof EntityAISwitchable){
  159.             EntityAISwitchable eis=(EntityAISwitchable)ai;
  160.             if(eis.isActive()!=value)
  161.                 eis.setActive(value);
  162.         }else if(ai instanceof EntityAITargetSwitchable){
  163.             EntityAITargetSwitchable eits=(EntityAITargetSwitchable)ai;
  164.             if(eits.isActive()!=value)
  165.                 eits.setActive(value);
  166.         }
  167.     }
  168.    
  169.     protected void updateAITasks() {
  170.         this.changeAI(this.swimAI, this.dataManager.get(DATA_CAN_SWIM));
  171.         this.changeAI(this.fleeSun, this.dataManager.get(DATA_SUN_MODE)==2);
  172.         this.changeAI(this.restrictSun, this.dataManager.get(DATA_SUN_MODE)==2);
  173.         this.changeAI(this.lookIdle, this.dataManager.get(DATA_LOOK_MODE)==1||this.dataManager.get(DATA_LOOK_MODE)==2);
  174.         if(this.lookPlayer.isActive()!=(this.dataManager.get(DATA_LOOK_MODE)==2||this.dataManager.get(DATA_LOOK_MODE)==3))
  175.             this.lookPlayer.setActive(!this.lookPlayer.isActive());
  176.         if(this.lookPlayer.getFollowRange()!=this.dataManager.get(DATA_LOOK_RANGE))
  177.             this.lookPlayer.setFollowRange(this.dataManager.get(DATA_LOOK_RANGE));
  178.         this.changeAI(this.wander,this.dataManager.get(DATA_WALK_MODE)==1);
  179.         this.changeAI(this.revenge, this.dataManager.get(DATA_ATTACK)==1);
  180.         this.changeAI(this.nearest, this.dataManager.get(DATA_ATTACK)==2);
  181.     }
  182.    
  183.     public float getBlockPathWeight(BlockPos pos){
  184.         return 0.5F - this.worldObj.getLightBrightness(pos);
  185.     }
  186.    
  187.     public void fall(float distance, float damageMultiplier) {
  188.         if(this.dataManager.get(DATA_FALL_DAMAGE))
  189.             super.fall(distance, damageMultiplier);
  190.         else{}
  191.     }
  192.    
  193.     public boolean attackEntityAsMob(Entity entityIn){
  194.         return entityIn.attackEntityFrom(DamageSource.causeMobDamage(this), (float)((int)this.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).getAttributeValue()));
  195.     }
  196.    
  197.     public void onLivingUpdate() {
  198.         super.onLivingUpdate();
  199.         if (this.worldObj.isDaytime() && !this.worldObj.isRemote && (this.dataManager.get(DATA_SUN_MODE)==1||this.dataManager.get(DATA_SUN_MODE)==2))
  200.         {
  201.             float f = this.getBrightness(1.0F);
  202.             BlockPos blockpos = this.getRidingEntity() instanceof EntityBoat ? (new BlockPos(this.posX, (double)Math.round(this.posY), this.posZ)).up() : new BlockPos(this.posX, (double)Math.round(this.posY), this.posZ);
  203.  
  204.             if (f > 0.5F && this.rand.nextFloat() * 30.0F < (f - 0.4F) * 2.0F && this.worldObj.canSeeSky(blockpos))
  205.             {
  206.                 boolean flag = true;
  207.                 ItemStack itemstack = this.getItemStackFromSlot(EntityEquipmentSlot.HEAD);
  208.  
  209.                 if (itemstack != null)
  210.                 {
  211.                     if (itemstack.isItemStackDamageable())
  212.                     {
  213.                         itemstack.setItemDamage(itemstack.getItemDamage() + this.rand.nextInt(2));
  214.  
  215.                         if (itemstack.getItemDamage() >= itemstack.getMaxDamage())
  216.                         {
  217.                             this.renderBrokenItemStack(itemstack);
  218.                             this.setItemStackToSlot(EntityEquipmentSlot.HEAD, (ItemStack)null);
  219.                         }
  220.                     }
  221.  
  222.                     flag = false;
  223.                 }
  224.  
  225.                 if (flag)
  226.                 {
  227.                     this.setFire(8);
  228.                 }
  229.             }
  230.         }
  231.     }
  232.    
  233.     public void applyEntityAttributes() {
  234.         this.getAttributeMap().registerAttribute(SharedMonsterAttributes.MAX_HEALTH);
  235.         this.getAttributeMap().registerAttribute(SharedMonsterAttributes.KNOCKBACK_RESISTANCE);
  236.         this.getAttributeMap().registerAttribute(SharedMonsterAttributes.MOVEMENT_SPEED);
  237.         this.getAttributeMap().registerAttribute(SharedMonsterAttributes.ARMOR);
  238.         this.getAttributeMap().registerAttribute(SharedMonsterAttributes.ARMOR_TOUGHNESS);
  239.         this.getAttributeMap().registerAttribute(SharedMonsterAttributes.FOLLOW_RANGE).setBaseValue(15.0D);
  240.         this.getAttributeMap().registerAttribute(SharedMonsterAttributes.ATTACK_SPEED);
  241.         this.getAttributeMap().registerAttribute(SharedMonsterAttributes.ATTACK_DAMAGE);
  242.     }
  243.    
  244.     public void updateEntityAttributes() {
  245.         this.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(this.maxHealth);
  246.         this.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).setBaseValue(this.movespeed);
  247.         this.getEntityAttribute(SharedMonsterAttributes.ATTACK_SPEED).setBaseValue(this.attackspeed);
  248.         this.getEntityAttribute(SharedMonsterAttributes.ARMOR).setBaseValue(this.armor);
  249.         this.getEntityAttribute(SharedMonsterAttributes.ARMOR_TOUGHNESS).setBaseValue(this.armortoughness);
  250.     }
  251.    
  252.     public SoundEvent getDeathSound() {
  253.         return new SoundEvent(new ResourceLocation("mapres",this.dataManager.get(DATA_DEATH_SOUND)));
  254.     }
  255.    
  256.     public SoundEvent getHurtSound() {
  257.         return new SoundEvent(new ResourceLocation("mapres",this.dataManager.get(DATA_HIT_SOUND)));
  258.     }
  259.    
  260.     public void entityInit() {
  261.         super.entityInit();
  262.         //this.dataManager.register(DATA_FLAGS, 0);
  263.         this.dataManager.register(DATA_TEXTURE, "steve");
  264.         this.dataManager.register(DATA_FIRE_IMMUNE, false);
  265.         this.dataManager.register(DATA_CAN_BREATHE, false);
  266.         this.dataManager.register(DATA_SUN_MODE, 0);
  267.         this.dataManager.register(DATA_FALL_DAMAGE, true);
  268.         this.dataManager.register(DATA_DEATH_SOUND, "playerDeath");
  269.         this.dataManager.register(DATA_HIT_SOUND, "playerHit");
  270.         this.dataManager.register(DATA_CAN_SWIM, true);
  271.         this.dataManager.register(DATA_LOOK_MODE, 0);
  272.         this.dataManager.register(DATA_LOOK_RANGE, 5.0F);
  273.         this.dataManager.register(DATA_WALK_MODE, 0);
  274.         this.dataManager.register(DATA_ATTACK, 0);
  275.     }
  276.  
  277.     public boolean isAIDisabled() {
  278.         return false;
  279.     }
  280.    
  281.     public boolean isFireImmune(){
  282.         return this.dataManager.get(DATA_FIRE_IMMUNE);
  283.     }
  284.    
  285.     public boolean canBreatheUnderwater() {
  286.         return this.dataManager.get(DATA_CAN_BREATHE);
  287.     }
  288.    
  289.     public boolean takesFallDamage(){
  290.         return this.dataManager.get(DATA_FALL_DAMAGE);
  291.     }
  292.    
  293.     public int burnsInSun(){
  294.         return this.dataManager.get(DATA_SUN_MODE);
  295.     }
  296.    
  297.     public void readEntityFromNBT(NBTTagCompound compound) {
  298.         super.readEntityFromNBT(compound);
  299.         this.dataManager.set(DATA_TEXTURE, compound.getString("tex"));
  300.         this.dataManager.set(DATA_FIRE_IMMUNE, compound.getBoolean("fireimm"));
  301.         this.dataManager.set(DATA_CAN_BREATHE, compound.getBoolean("canbreathe"));
  302.         this.dataManager.set(DATA_SUN_MODE, compound.getInteger("sunburn"));
  303.         this.dataManager.set(DATA_FALL_DAMAGE, compound.getBoolean("falldmg"));
  304.         this.dataManager.set(DATA_DEATH_SOUND, compound.getString("deathSound"));
  305.         this.dataManager.set(DATA_HIT_SOUND, compound.getString("hitSound"));
  306.         this.dataManager.set(DATA_CAN_SWIM, compound.getBoolean("canSwim"));
  307.         this.dataManager.set(DATA_LOOK_MODE, compound.getInteger("lookMode"));
  308.         this.dataManager.set(DATA_LOOK_RANGE, compound.getFloat("watchRange"));
  309.         this.dataManager.set(DATA_WALK_MODE, compound.getInteger("walkMode"));
  310.         this.dataManager.set(DATA_ATTACK, compound.getInteger("revenge"));
  311.         this.interactlevel=compound.getInteger("ilevel");
  312.         this.maxHealth=compound.getDouble("maxhealth");
  313.         this.movespeed=compound.getDouble("movespeed");
  314.         this.attackspeed=compound.getDouble("attackspeed");
  315.         this.armor=compound.getDouble("armor");
  316.         this.armortoughness=compound.getDouble("armort");
  317.         this.updateEntityAttributes();
  318.         this.setHealth(compound.getFloat("currHealth"));
  319.         this.isImmuneToFire=this.dataManager.get(DATA_FIRE_IMMUNE);
  320.  
  321.         NBTTagList nbttaglist = compound.getTagList("Items", 10);
  322.         this.initInv();
  323.  
  324.         for (int i = 0; i < nbttaglist.tagCount(); ++i){
  325.             NBTTagCompound nbttagcompound = nbttaglist.getCompoundTagAt(i);
  326.             this.inventory.setInventorySlotContents(i, ItemStack.loadItemStackFromNBT(nbttagcompound));
  327.         }
  328.     }
  329.    
  330.     public void writeEntityToNBT(NBTTagCompound compound) {
  331.         super.writeEntityToNBT(compound);
  332.         compound.setString("tex", this.dataManager.get(DATA_TEXTURE));
  333.         compound.setBoolean("fireimm", this.dataManager.get(DATA_FIRE_IMMUNE));
  334.         compound.setBoolean("canbreathe", this.dataManager.get(DATA_CAN_BREATHE));
  335.         compound.setInteger("sunburn", this.dataManager.get(DATA_SUN_MODE));
  336.         compound.setBoolean("falldmg", this.dataManager.get(DATA_FALL_DAMAGE));
  337.         compound.setString("deathSound", this.dataManager.get(DATA_DEATH_SOUND));
  338.         compound.setString("hitSound", this.dataManager.get(DATA_HIT_SOUND));
  339.         compound.setBoolean("canSwim", this.dataManager.get(DATA_CAN_SWIM));
  340.         compound.setInteger("lookMode", this.dataManager.get(DATA_LOOK_MODE));
  341.         compound.setFloat("watchRange", this.dataManager.get(DATA_LOOK_RANGE));
  342.         compound.setInteger("walkMode", this.dataManager.get(DATA_WALK_MODE));
  343.         compound.setInteger("revenge", this.dataManager.get(DATA_ATTACK));
  344.         compound.setInteger("ilevel", this.interactlevel);
  345.         compound.setDouble("maxhealth", this.maxHealth);
  346.         compound.setDouble("movespeed", this.movespeed);
  347.         compound.setDouble("attackspeed", this.attackspeed);
  348.         compound.setDouble("armor", this.armor);
  349.         compound.setDouble("armort", this.armortoughness);
  350.         compound.setFloat("currHealth", this.getHealth());
  351.  
  352.         NBTTagList nbttaglist = new NBTTagList();
  353.  
  354.         for (int i = 0; i < this.inventory.getSizeInventory(); ++i)
  355.         {
  356.             ItemStack itemstack=this.inventory.getStackInSlot(i);
  357.  
  358.             if (itemstack != null)
  359.             {
  360.                 NBTTagCompound nbttagcompound = new NBTTagCompound();
  361.                 itemstack.writeToNBT(nbttagcompound);
  362.                 nbttaglist.appendTag(nbttagcompound);
  363.             }
  364.         }
  365.  
  366.         compound.setTag("Items", nbttaglist);
  367.     }
  368.    
  369.     protected boolean processInteract(EntityPlayer player, EnumHand hand, ItemStack stack) {
  370.         if(player.getHeldItemMainhand()!=null){
  371.             if(player.getHeldItemMainhand().getItem()==PEItems.itemNPCWand){
  372.                 if(!this.worldObj.isRemote){
  373.                     this.inventory.setCustomName(this.getName());
  374.                     player.openGui(PixelEngine.INSTANCE, PEGuiHandler.NPCGUI, this.worldObj, this.getEntityId(), 0, 0);
  375.                     //this.openGui(player);
  376.                 }
  377.             }
  378.         }
  379.         //TODO interaction behaviour
  380.         return super.processInteract(player, hand, stack);
  381.     }
  382.    
  383.     //______________________________________________________________________________________________________
  384.     //
  385.     //-----------------------------------------Getters & Setters--------------------------------------------
  386.     //______________________________________________________________________________________________________
  387.    
  388.     public void setName(String name){
  389.         this.setCustomNameTag(name);
  390.     }
  391.    
  392.     public void setTexture(String tex){
  393.         this.dataManager.set(DATA_TEXTURE, tex);
  394.     }
  395.    
  396.     public String getTexture(){
  397.         return this.dataManager.get(DATA_TEXTURE);
  398.     }
  399.    
  400.     public void setMaxHealth(double hearts){
  401.         this.maxHealth=hearts;
  402.         this.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(hearts);
  403.         this.setHealth((float)hearts);
  404.     }
  405.    
  406.     public void setDeathSound(String sound){
  407.         this.dataManager.set(DATA_DEATH_SOUND, sound);
  408.     }
  409.    
  410.     public void setHitSound(String sound){
  411.         this.dataManager.set(DATA_HIT_SOUND, sound);
  412.     }
  413.    
  414.     public String getDeathsSound(){
  415.         return this.dataManager.get(DATA_DEATH_SOUND);
  416.     }
  417.    
  418.     public String getHitSound(){
  419.         return this.dataManager.get(DATA_HIT_SOUND);
  420.     }
  421.    
  422.     public void setMoveSpeed(double speed){
  423.         this.movespeed=speed;
  424.         this.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).setBaseValue(speed);
  425.     }
  426.    
  427.     public final float getMoveSpeed(){
  428.         return (float)this.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).getAttributeValue();
  429.     }
  430.    
  431.     public void isAttackable(boolean attackable){
  432.         this.setEntityInvulnerable(!attackable);
  433.     }
  434.    
  435.     public void setAttackSpeed(double speed){
  436.         this.attackspeed=speed;
  437.         this.getEntityAttribute(SharedMonsterAttributes.ATTACK_SPEED).setBaseValue(speed);
  438.     }
  439.    
  440.     public final float getAttackSpeed(){
  441.         return (float)this.getEntityAttribute(SharedMonsterAttributes.ATTACK_SPEED).getAttributeValue();
  442.     }
  443.    
  444.     public void setArmor(double armor){
  445.         this.armor=armor;
  446.         this.getEntityAttribute(SharedMonsterAttributes.ARMOR).setBaseValue(armor);
  447.     }
  448.    
  449.     public final float getArmor(){
  450.         return (float)this.getEntityAttribute(SharedMonsterAttributes.ARMOR).getAttributeValue();
  451.     }
  452.    
  453.     public void setArmorToughness(double toughness){
  454.         this.armortoughness=toughness;
  455.         this.getEntityAttribute(SharedMonsterAttributes.ARMOR_TOUGHNESS).setBaseValue(toughness);
  456.     }
  457.    
  458.     public final float getArmorToughness(){
  459.         return (float)this.getEntityAttribute(SharedMonsterAttributes.ARMOR_TOUGHNESS).getAttributeValue();
  460.     }
  461.    
  462.     public void setImmuneToFire(boolean immune){
  463.         this.dataManager.set(DATA_FIRE_IMMUNE, immune);
  464.         this.isImmuneToFire=immune;
  465.     }
  466.    
  467.     public void canDrown(boolean drown){
  468.         this.dataManager.set(DATA_CAN_BREATHE, !drown);
  469.     }
  470.    
  471.     public void canBurnInSun(int mode){
  472.         this.dataManager.set(DATA_SUN_MODE, mode);
  473.     }
  474.    
  475.     public void setTakesFallDamage(boolean damage){
  476.         this.dataManager.set(DATA_FALL_DAMAGE, damage);
  477.     }
  478.    
  479.     public void renderName(boolean render){
  480.         this.setAlwaysRenderNameTag(render);
  481.     }
  482.    
  483.     public boolean canSwim(){
  484.         return this.dataManager.get(DATA_CAN_SWIM);
  485.     }
  486.    
  487.     public void setCanSwim(boolean canSwim){
  488.         this.dataManager.set(DATA_CAN_SWIM, canSwim);
  489.     }
  490.    
  491.     public void setLookMode(int lookMode){
  492.         this.dataManager.set(DATA_LOOK_MODE, lookMode);
  493.     }
  494.    
  495.     public String getName()
  496.     {
  497.         return this.hasCustomName() ? this.getCustomNameTag() : "NPC";
  498.     }
  499.    
  500.     public int getLookMode(){
  501.         return this.dataManager.get(DATA_LOOK_MODE);
  502.     }
  503.    
  504.     public void setWatchRange(float range){
  505.         this.dataManager.set(DATA_LOOK_RANGE, range);
  506.     }
  507.    
  508.     public float getWatchRange(){
  509.         return this.dataManager.get(DATA_LOOK_RANGE);
  510.     }
  511.    
  512.     public void setWalkMode(int mode){
  513.         this.dataManager.set(DATA_WALK_MODE, mode);
  514.     }
  515.    
  516.     public int getWalkMode(){
  517.         return this.dataManager.get(DATA_WALK_MODE);
  518.     }
  519.    
  520.     public int getAttackMode(){
  521.         return this.dataManager.get(DATA_ATTACK);
  522.     }
  523.    
  524.     public void setAttackMode(int mode){
  525.         this.dataManager.set(DATA_ATTACK,mode);
  526.         this.setAttackTarget(null);
  527.         this.setRevengeTarget(null);
  528.         this.setLastAttacker(null);
  529.     }
  530.    
  531.     public void onInventoryChanged(InventoryBasic invBasic) {
  532.         if(invBasic!=null){
  533.             for(int slot=0; slot<4; slot++){
  534.                 ItemStack stack=invBasic.getStackInSlot(slot);
  535.                 if(stack!=null){
  536.                     EntityEquipmentSlot equip=EntityLiving.getSlotForItemStack(stack);
  537.                     this.setItemStackToSlot(equip, stack);
  538.                 }
  539.             }
  540.             ItemStack offhandItem=invBasic.getStackInSlot(4);
  541.             ItemStack mainhandItem=invBasic.getStackInSlot(5);
  542.             if(offhandItem!=null)
  543.                 this.setHeldItem(EnumHand.OFF_HAND, offhandItem);
  544.             if(mainhandItem!=null)
  545.                 this.setHeldItem(EnumHand.MAIN_HAND, mainhandItem);
  546.         }
  547.     }
  548. }
Advertisement
Add Comment
Please, Sign In to add comment