From 4456b6d1cb264832d995b67ce11919cf471cffd9 Mon Sep 17 00:00:00 2001 From: ninjaguardian <110734253+ninjaguardian@users.noreply.github.com> Date: Mon, 10 Aug 2026 16:42:40 -0500 Subject: [PATCH] Refactor IFallingFruit and fix bonk translation --- .../blocks/fruit/IFallingFruit.java | 47 ++++++++++--------- .../assets/dtaddon_lib/lang/en_us.json | 2 +- 2 files changed, 27 insertions(+), 22 deletions(-) diff --git a/src/main/java/com/dtteam/dtaddon_lib/blocks/fruit/IFallingFruit.java b/src/main/java/com/dtteam/dtaddon_lib/blocks/fruit/IFallingFruit.java index 8b03215..70fab2f 100644 --- a/src/main/java/com/dtteam/dtaddon_lib/blocks/fruit/IFallingFruit.java +++ b/src/main/java/com/dtteam/dtaddon_lib/blocks/fruit/IFallingFruit.java @@ -1,7 +1,6 @@ package com.dtteam.dtaddon_lib.blocks.fruit; import com.dtteam.dtaddon_lib.init.DTAddonLibRegistries; -import com.google.common.collect.Lists; import net.minecraft.core.BlockPos; import net.minecraft.server.level.ServerLevel; import net.minecraft.sounds.SoundSource; @@ -16,11 +15,8 @@ import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.FallingBlock; import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.phys.Vec3; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; -import java.util.List; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; public interface IFallingFruit { @@ -56,31 +52,40 @@ default boolean doFall(BlockState state, Level world, BlockPos pos){ return false; } - default FallingBlockEntity getFallingEntity (Level world, BlockPos pos, BlockState state){ - return new FallingBlockEntity(world, (double)pos.getX() + 0.5D, pos.getY(), (double)pos.getZ() + 0.5D, state){ + default FallingBlockEntity getFallingEntity(Level world, @NotNull BlockPos pos, BlockState state) { + return new FallingBlockEntity(world, (double)pos.getX() + 0.5D, pos.getY(), (double)pos.getZ() + 0.5D, state) { @Override - public boolean causeFallDamage(double pFallDistance, float pMultiplier, DamageSource pSource) { + public boolean causeFallDamage(double pFallDistance, float pMultiplier, @NotNull DamageSource pSource) { int i = (int)Math.ceil(pFallDistance - 1.0F); - if (i > 0) { - List list = Lists.newArrayList(level().getEntities(this, this.getBoundingBox())); - for(Entity entity : list) { - if (entity instanceof LivingEntity){ - entity.hurt(getDamageSource(level()), - (float)Math.min(Math.floor((float)i * IFallingFruit.fallDamageAmount), IFallingFruit.fallDamageMax) * pMultiplier); - level().playSound(null, pos, - DTAddonLibRegistries.FRUIT_BONK.get(), SoundSource.BLOCKS, - 1.0F, 1.0F); - } + if (i <= 0) { + return false; + } + + //noinspection resource + if (!(level() instanceof ServerLevel serverLevel)) { + return false; + } + + for (Entity entity : serverLevel.getEntities(this, this.getBoundingBox())) { + if (!(entity instanceof LivingEntity)) { + continue; } + + entity.hurtServer(serverLevel, getDamageSource(serverLevel), + (float)Math.min(Math.floor((float)i * IFallingFruit.fallDamageAmount), IFallingFruit.fallDamageMax) * pMultiplier); + serverLevel.playSound(null, getX(), getY(), getZ(), + DTAddonLibRegistries.FRUIT_BONK.get(), SoundSource.BLOCKS, + 1.0F, 1.0F); } + return false; } @Nullable @Override - public ItemEntity spawnAtLocation(ServerLevel pLevel, @Nonnull ItemStack pStack, float pOffsetY) { - return super.spawnAtLocation(pLevel, getDropOnFallItems( this), pOffsetY); + public ItemEntity spawnAtLocation(@NotNull ServerLevel pLevel, @NotNull ItemStack pStack, float pOffsetY) { + return super.spawnAtLocation(pLevel, getDropOnFallItems(this), pOffsetY); } }; } diff --git a/src/main/resources/assets/dtaddon_lib/lang/en_us.json b/src/main/resources/assets/dtaddon_lib/lang/en_us.json index de1c859..024db32 100644 --- a/src/main/resources/assets/dtaddon_lib/lang/en_us.json +++ b/src/main/resources/assets/dtaddon_lib/lang/en_us.json @@ -1,5 +1,5 @@ { - "subtitle.dtaddon_lib.falling_fruit.bonk": "Player bonked by fruit", + "subtitle.dtaddon_lib.falling_fruit.bonk": "Entity bonked by fruit", "block.dtaddon_lib.large_rooty_water":"Large Water Roots", "block.dtaddon_lib.big_oak_branch": "Big Oak Tree",