From 0094a0e105c7e024fbd7774e1aab84d2477b79aa Mon Sep 17 00:00:00 2001 From: NewJumper Date: Fri, 24 May 2024 14:57:34 -0500 Subject: [PATCH] decreased the chance for sculk snapper to drop books and limited the number of books it can drop (closes #310) --- .../deeperdarker/content/entities/SculkSnapper.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/kyanite/deeperdarker/content/entities/SculkSnapper.java b/src/main/java/com/kyanite/deeperdarker/content/entities/SculkSnapper.java index be4c52345..5ab1ea7ad 100644 --- a/src/main/java/com/kyanite/deeperdarker/content/entities/SculkSnapper.java +++ b/src/main/java/com/kyanite/deeperdarker/content/entities/SculkSnapper.java @@ -4,6 +4,7 @@ import net.minecraft.core.particles.ParticleTypes; import net.minecraft.server.level.ServerLevel; import net.minecraft.sounds.SoundEvent; +import net.minecraft.util.valueproviders.BiasedToBottomInt; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; import net.minecraft.world.damagesource.DamageSource; @@ -36,6 +37,7 @@ public class SculkSnapper extends TamableAnimal { public final AnimationState idleState = new AnimationState(); public final AnimationState attackState = new AnimationState(); public final AnimationState sitState = new AnimationState(); + private int droppedBooks; public SculkSnapper(EntityType pEntityType, Level pLevel) { super(pEntityType, pLevel); @@ -99,7 +101,7 @@ public void tick() { super.tick(); if(this.isTame() && this.getOwner() != null) { - if(this.getOwner().distanceTo(this) < 5 && this.random.nextFloat() < 0.0003f) { + if(droppedBooks < 16 && this.getOwner().distanceTo(this) < 5 && this.random.nextFloat() < 0.00025f) { List enchantments = new ArrayList<>(); ForgeRegistries.ENCHANTMENTS.forEach(enchant -> { if(!enchant.isCurse()) enchantments.add(enchant); @@ -108,8 +110,9 @@ public void tick() { Enchantment enchantment2 = enchantments.get(this.random.nextInt(enchantments.size())); ItemStack book = EnchantedBookItem.createForEnchantment(new EnchantmentInstance(enchantment1, this.random.nextInt(1, enchantment1.getMaxLevel() + 1))); - if(this.random.nextFloat() < 0.2f) EnchantedBookItem.addEnchantment(book, new EnchantmentInstance(enchantment2, 1)); - if(!book.isEmpty()) this.level().addFreshEntity(new ItemEntity(this.level(), this.blockPosition().getX(), this.blockPosition().getY(), this.blockPosition().getZ(), book)); + if(this.random.nextFloat() < 0.2f) EnchantedBookItem.addEnchantment(book, new EnchantmentInstance(enchantment2, BiasedToBottomInt.of(1, enchantment2.getMaxLevel()).sample(this.random))); + this.level().addFreshEntity(new ItemEntity(this.level(), this.blockPosition().getX(), this.blockPosition().getY(), this.blockPosition().getZ(), book)); + droppedBooks++; } }