Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class EntityTameableSpider extends EntityHorse
- {
- private static final UUID ARMOR_MODIFIER_UUID = UUID.fromString("556E1665-8B10-40C8-8F9D-CF9B1667F295");
- private static final DataParameter<Byte> CLIMBING = EntityDataManager.<Byte>createKey(EntityTameableSpider.class, DataSerializers.BYTE);
- private static final DataParameter<Integer> SPIDER_ARMOR = EntityDataManager.<Integer>createKey(EntityTameableSpider.class, DataSerializers.VARINT);
- private static final DataParameter<ItemStack> SPIDER_ARMOR_STACK = EntityDataManager.<ItemStack>createKey(EntityTameableSpider.class, DataSerializers.ITEM_STACK);
- public EntityTameableSpider(World worldIn)
- {
- super(worldIn);
- this.setSize(1.4F, 0.9F);
- this.stepHeight = 1.0F;
- this.initHorseChest();
- }
- public SpiderArmorType getSpiderArmorType(ItemStack stack)
- {
- return SpiderArmorType.getByItem(stack.getItem());
- }
- @Override
- public void onUpdate()
- {
- super.onUpdate();
- if (!this.world.isRemote)
- {
- this.setBesideClimbableBlock(this.collidedHorizontally);
- }
- if (this.world.isRemote && this.dataManager.isDirty())
- {
- this.dataManager.setClean();
- }
- ItemStack armor = this.horseChest.getStackInSlot(1);
- if (isArmor(armor)) armor.getItem().onHorseArmorTick(world, this, armor);
- }
- @Override
- protected void initEntityAI()
- {
- this.tasks.addTask(0, new EntityAISwimming(this));
- this.tasks.addTask(1, new EntityAIPanic(this, 0.95D));
- this.tasks.addTask(1, new EntityAIRunAroundLikeCrazy(this, 0.95D));
- this.tasks.addTask(6, new EntityAIWanderAvoidWater(this, 0.8D));
- this.tasks.addTask(7, new EntityAIWatchClosest(this, EntityPlayer.class, 6.0F));
- this.tasks.addTask(8, new EntityAILookIdle(this));
- }
- protected PathNavigate createNavigator(World worldIn)
- {
- return new PathNavigateClimber(this, worldIn);
- }
- @Override
- protected void entityInit()
- {
- super.entityInit();
- this.dataManager.register(SPIDER_ARMOR, Integer.valueOf(SpiderArmorType.NONE.getOrdinal()));
- this.dataManager.register(SPIDER_ARMOR_STACK, ItemStack.EMPTY);
- this.dataManager.register(CLIMBING, Byte.valueOf((byte)0));
- }
- public boolean isOnLadder()
- {
- return this.isBesideClimbableBlock();
- }
- public void setInWeb() {}
- public EnumCreatureAttribute getCreatureAttribute()
- {
- return EnumCreatureAttribute.ARTHROPOD;
- }
- public boolean isPotionApplicable(PotionEffect potioneffectIn)
- {
- return potioneffectIn.getPotion() == MobEffects.POISON ? false : super.isPotionApplicable(potioneffectIn);
- }
- public boolean isBesideClimbableBlock()
- {
- return (((Byte)this.dataManager.get(CLIMBING)).byteValue() & 1) != 0;
- }
- public void setBesideClimbableBlock(boolean climbing)
- {
- byte b0 = ((Byte)this.dataManager.get(CLIMBING)).byteValue();
- if (climbing)
- {
- b0 = (byte)(b0 | 1);
- }
- else
- {
- b0 = (byte)(b0 & -2);
- }
- this.dataManager.set(CLIMBING, Byte.valueOf(b0));
- }
- @Override
- public void writeEntityToNBT(NBTTagCompound compound)
- {
- super.writeEntityToNBT(compound);
- if (!this.horseChest.getStackInSlot(1).isEmpty())
- {
- compound.setTag("ArmorItem", this.horseChest.getStackInSlot(1).writeToNBT(new NBTTagCompound()));
- }
- }
- @Override
- public void readEntityFromNBT(NBTTagCompound compound)
- {
- super.readEntityFromNBT(compound);
- if (compound.hasKey("ArmorItem", 10))
- {
- ItemStack itemstack = new ItemStack(compound.getCompoundTag("ArmorItem"));
- if (!itemstack.isEmpty() && isArmor(itemstack))
- {
- this.horseChest.setInventorySlotContents(1, itemstack);
- }
- }
- this.updateHorseSlots();
- }
- @Override
- public void setHorseVariant(int variant) {}
- @Override
- public int getHorseVariant()
- {
- return 0;
- }
- protected void updateHorseSlots()
- {
- super.updateHorseSlots();
- this.setSpiderArmorStack(this.horseChest.getStackInSlot(1));
- }
- public ItemStack getArmor()
- {
- return this.dataManager.get(SPIDER_ARMOR_STACK);
- }
- public void setSpiderArmorStack(ItemStack itemStackIn)
- {
- SpiderArmorType spiderArmorType = SpiderArmorType.getByItemStack(itemStackIn);
- this.dataManager.set(SPIDER_ARMOR, Integer.valueOf(spiderArmorType.getOrdinal()));
- this.dataManager.set(SPIDER_ARMOR_STACK, itemStackIn);
- if (!this.world.isRemote)
- {
- this.getEntityAttribute(SharedMonsterAttributes.ARMOR).removeModifier(ARMOR_MODIFIER_UUID);
- int i = spiderArmorType.getProtection();
- if (i != 0)
- {
- this.getEntityAttribute(SharedMonsterAttributes.ARMOR).applyModifier((new AttributeModifier(ARMOR_MODIFIER_UUID, "Spider armor bonus", (double)i, 0)).setSaved(false));
- }
- }
- }
- public SpiderArmorType getSpiderArmorType()
- {
- SpiderArmorType armor = SpiderArmorType.getByItemStack(this.dataManager.get(SPIDER_ARMOR_STACK));
- if (armor == SpiderArmorType.NONE) armor = SpiderArmorType.getByOrdinal(this.dataManager.get(SPIDER_ARMOR));
- return armor;
- }
- @Override
- public void onInventoryChanged(IInventory invBasic)
- {
- SpiderArmorType spiderArmorType = this.getSpiderArmorType();
- super.onInventoryChanged(invBasic);
- SpiderArmorType spiderArmorType1 = this.getSpiderArmorType();
- if (this.ticksExisted > 20 && spiderArmorType != spiderArmorType1 && spiderArmorType1 != SpiderArmorType.NONE)
- {
- this.playSound(SoundEvents.ENTITY_HORSE_ARMOR, 0.5F, 1.0F);
- }
- }
- @Override
- protected void playGallopSound(SoundType p_190680_1_) {}
- @Override
- protected void applyEntityAttributes()
- {
- super.applyEntityAttributes();
- this.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(16.0D);
- this.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).setBaseValue(this.getModifiedMovementSpeed());
- this.getEntityAttribute(JUMP_STRENGTH).setBaseValue(this.getModifiedJumpStrength());
- }
- @Override
- protected SoundEvent getAmbientSound()
- {
- return SoundEvents.ENTITY_SPIDER_AMBIENT;
- }
- @Override
- protected SoundEvent getHurtSound(DamageSource damageSourceIn)
- {
- return SoundEvents.ENTITY_SPIDER_HURT;
- }
- @Override
- protected SoundEvent getDeathSound()
- {
- return SoundEvents.ENTITY_SPIDER_DEATH;
- }
- @Override
- protected void playStepSound(BlockPos pos, Block blockIn)
- {
- this.playSound(SoundEvents.ENTITY_SPIDER_STEP, 0.15F, 1.0F);
- }
- @Override
- @Nullable
- protected ResourceLocation getLootTable()
- {
- return LootTableList.ENTITIES_SPIDER;
- }
- @Override
- protected SoundEvent getAngrySound()
- {
- super.getAngrySound();
- return null;
- }
- public boolean processInteract(EntityPlayer player, EnumHand hand)
- {
- ItemStack itemstack = player.getHeldItem(hand);
- if (this.isTame() && player.isSneaking())
- {
- this.openGUI(player);
- return true;
- }
- if (this.isBeingRidden())
- {
- return super.processInteract(player, hand);
- }
- if (!itemstack.isEmpty())
- {
- if (this.getHealth() < this.getMaxHealth() && itemstack.getItem() instanceof ItemFood && this.isTame())
- {
- ItemFood food = (ItemFood) itemstack.getItem();
- if (!player.capabilities.isCreativeMode)
- {
- itemstack.shrink(1);
- }
- for (int i = 0; i < 7; ++i)
- {
- double d0 = this.rand.nextGaussian() * 0.02D;
- double d1 = this.rand.nextGaussian() * 0.02D;
- double d2 = this.rand.nextGaussian() * 0.02D;
- this.world.spawnParticle(EnumParticleTypes.VILLAGER_HAPPY, this.posX + (double)(this.rand.nextFloat() * this.width * 2.0F) - (double)this.width, this.posY + 0.5D + (double)(this.rand.nextFloat() * this.height), this.posZ + (double)(this.rand.nextFloat() * this.width * 2.0F) - (double)this.width, d0, d1, d2);
- }
- this.heal(food.getHealAmount(itemstack));
- return true;
- }
- else if (!this.isTame() && itemstack.getItem() == Items.NETHER_WART)
- {
- if (!player.capabilities.isCreativeMode)
- {
- itemstack.shrink(1);
- }
- if (this.rand.nextInt(3) == 1)
- {
- this.setTamedBy(player);
- this.playTameEffect(true);
- }
- else
- {
- this.playTameEffect(false);
- }
- return true;
- }
- if (itemstack.interactWithEntity(player, this, hand))
- {
- return true;
- }
- boolean flag1 = SpiderArmorType.getByItemStack(itemstack) != SpiderArmorType.NONE;
- boolean flag2 = !this.isHorseSaddled() && itemstack.getItem() == Items.SADDLE;
- if (flag1 || flag2)
- {
- this.openGUI(player);
- return true;
- }
- }
- this.mountTo(player);
- return true;
- }
- @Override
- public void fall(float distance, float damageMultiplier)
- {
- int i = MathHelper.ceil((distance * 0.5F - 3.0F) * damageMultiplier);
- if (i > 0)
- {
- this.attackEntityFrom(DamageSource.FALL, (float)i);
- if (this.isBeingRidden())
- {
- for (Entity entity : this.getRecursivePassengers())
- {
- entity.attackEntityFrom(DamageSource.FALL, (float)i);
- }
- }
- IBlockState iblockstate = this.world.getBlockState(new BlockPos(this.posX, this.posY - 0.2D - (double)this.prevRotationYaw, this.posZ));
- Block block = iblockstate.getBlock();
- if (iblockstate.getMaterial() != Material.AIR && !this.isSilent())
- {
- SoundType soundtype = block.getSoundType();
- this.world.playSound((EntityPlayer)null, this.posX, this.posY, this.posZ, soundtype.getStepSound(), this.getSoundCategory(), soundtype.getVolume() * 0.5F, soundtype.getPitch() * 0.75F);
- }
- }
- }
- @Override
- public double getMountedYOffset()
- {
- return (double)(this.height * 0.5F);
- }
- @Override
- protected void mountTo(EntityPlayer player)
- {
- if (this.isTame())
- {
- player.rotationYaw = this.rotationYaw;
- player.rotationPitch = this.rotationPitch;
- this.setEatingHaystack(false);
- this.setRearing(false);
- if (!this.world.isRemote)
- {
- player.startRiding(this);
- }
- }
- }
- protected void playTameEffect(boolean play)
- {
- EnumParticleTypes enumparticletypes = EnumParticleTypes.HEART;
- if (!play)
- {
- enumparticletypes = EnumParticleTypes.SMOKE_NORMAL;
- }
- for (int i = 0; i < 7; ++i)
- {
- double d0 = this.rand.nextGaussian() * 0.02D;
- double d1 = this.rand.nextGaussian() * 0.02D;
- double d2 = this.rand.nextGaussian() * 0.02D;
- this.world.spawnParticle(enumparticletypes, this.posX + (double)(this.rand.nextFloat() * this.width * 2.0F) - (double)this.width, this.posY + 0.5D + (double)(this.rand.nextFloat() * this.height), this.posZ + (double)(this.rand.nextFloat() * this.width * 2.0F) - (double)this.width, d0, d1, d2);
- }
- }
- @Override
- protected boolean handleEating(EntityPlayer player, ItemStack stack)
- {
- return false;
- }
- @Override
- public void setRearing(boolean rearing) {}
- @Override
- public void setBreeding(boolean breeding) {}
- @Override
- public void setTemper(int temperIn) {}
- @Override
- @Nullable
- protected AbstractHorse getClosestHorse(Entity entityIn, double distance)
- {
- return null;
- }
- @Override
- public boolean canMateWith(EntityAnimal otherAnimal)
- {
- return false;
- }
- @Override
- public EntityAgeable createChild(EntityAgeable ageable)
- {
- return null;
- }
- public boolean wearsArmor()
- {
- return true;
- }
- @Override
- public boolean isArmor(ItemStack stack)
- {
- return SpiderArmorType.isSpiderArmor(stack);
- }
- @Override
- @Nullable
- public IEntityLivingData onInitialSpawn(DifficultyInstance difficulty, @Nullable IEntityLivingData livingdata)
- {
- livingdata = super.onInitialSpawn(difficulty, livingdata);
- return livingdata;
- }
- @Override
- public void setHorseArmorStack(ItemStack itemStackIn) {}
- @Override
- public HorseArmorType getHorseArmorType()
- {
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement