Skip to content

Commit

Permalink
decreased the chance for sculk snapper to drop books and limited the …
Browse files Browse the repository at this point in the history
…number of books it can drop

(closes #310)
  • Loading branch information
NewJumper committed May 24, 2024
1 parent 2122ba2 commit 0094a0e
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<? extends TamableAnimal> pEntityType, Level pLevel) {
super(pEntityType, pLevel);
Expand Down Expand Up @@ -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<Enchantment> enchantments = new ArrayList<>();
ForgeRegistries.ENCHANTMENTS.forEach(enchant -> {
if(!enchant.isCurse()) enchantments.add(enchant);
Expand All @@ -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++;
}
}

Expand Down

1 comment on commit 0094a0e

@Fyoncle
Copy link

@Fyoncle Fyoncle commented on 0094a0e Jul 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No for fabric 1.20.1?

Please sign in to comment.