From 431325d97328773acffe1132a92600721bcb1bd9 Mon Sep 17 00:00:00 2001 From: wdfaESfaef <2622389575@qq.com> Date: Sat, 27 Apr 2024 23:00:06 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=A0=91=E8=84=82=E5=9D=97?= =?UTF-8?q?=E5=85=B7=E6=9C=89=E7=B2=98=E6=80=A7=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dubhe/anvilcraft/block/ResinBlock.java | 80 +++++++++++++++++++ .../dev/dubhe/anvilcraft/init/ModBlocks.java | 4 +- .../fabric/PistonMovingBlockEntityMixin.java | 6 +- .../forge/PistonMovingBlockEntityMixin.java | 5 +- 4 files changed, 90 insertions(+), 5 deletions(-) create mode 100644 common/src/main/java/dev/dubhe/anvilcraft/block/ResinBlock.java diff --git a/common/src/main/java/dev/dubhe/anvilcraft/block/ResinBlock.java b/common/src/main/java/dev/dubhe/anvilcraft/block/ResinBlock.java new file mode 100644 index 000000000..c254df94b --- /dev/null +++ b/common/src/main/java/dev/dubhe/anvilcraft/block/ResinBlock.java @@ -0,0 +1,80 @@ +package dev.dubhe.anvilcraft.block; + +import net.minecraft.core.BlockPos; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.level.BlockGetter; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.HalfTransparentBlock; +import net.minecraft.world.level.block.state.BlockBehaviour; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.phys.Vec3; +import org.jetbrains.annotations.NotNull; + +public class ResinBlock extends HalfTransparentBlock { + public ResinBlock(BlockBehaviour.Properties properties) { + super(properties); + } + /** + * @param level 世界 + * @param state 方块状态 + * @param pos 位置 + * @param entity 实体 + * @param fallDistance 掉落距离 + */ + + public void fallOn(@NotNull Level level, + @NotNull BlockState state, + @NotNull BlockPos pos, + Entity entity, + float fallDistance + ) { + if (entity.isSuppressingBounce()) { + super.fallOn(level, state, pos, entity, fallDistance); + } else { + entity.causeFallDamage(fallDistance, 0.0F, level.damageSources().fall()); + } + + } + + + /** + * @param level 世界 + * @param entity 实体 + */ + + public void updateEntityAfterFallOn(@NotNull BlockGetter level, Entity entity) { + if (entity.isSuppressingBounce()) { + super.updateEntityAfterFallOn(level, entity); + } else { + this.bounceUp(entity); + } + + } + + private void bounceUp(Entity entity) { + Vec3 vec3 = entity.getDeltaMovement(); + if (vec3.y < 0.0) { + double d = entity instanceof LivingEntity ? 1.0 : 0.8; + entity.setDeltaMovement(vec3.x, -vec3.y * d, vec3.z); + } + + } + + /** + * @param level 世界 + * @param pos 位置 + * @param state 方块状态 + * @param entity 实体 + */ + + public void stepOn(@NotNull Level level, @NotNull BlockPos pos, @NotNull BlockState state, Entity entity) { + double d = Math.abs(entity.getDeltaMovement().y); + if (d < 0.1 && !entity.isSteppingCarefully()) { + double e = 0.4 + d * 0.2; + entity.setDeltaMovement(entity.getDeltaMovement().multiply(e, 1.0, e)); + } + + super.stepOn(level, pos, state, entity); + } +} \ No newline at end of file diff --git a/common/src/main/java/dev/dubhe/anvilcraft/init/ModBlocks.java b/common/src/main/java/dev/dubhe/anvilcraft/init/ModBlocks.java index f518c2805..9be6fd42f 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/init/ModBlocks.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/init/ModBlocks.java @@ -17,6 +17,7 @@ import dev.dubhe.anvilcraft.block.LavaCauldronBlock; import dev.dubhe.anvilcraft.block.MagnetBlock; import dev.dubhe.anvilcraft.block.PiezoelectricCrystalBlock; +import dev.dubhe.anvilcraft.block.ResinBlock; import dev.dubhe.anvilcraft.block.RoyalAnvilBlock; import dev.dubhe.anvilcraft.block.RoyalGrindstone; import dev.dubhe.anvilcraft.block.RoyalSmithingTableBlock; @@ -46,7 +47,6 @@ import net.minecraft.world.level.block.HalfTransparentBlock; import net.minecraft.world.level.block.LayeredCauldronBlock; import net.minecraft.world.level.block.SlabBlock; -import net.minecraft.world.level.block.SlimeBlock; import net.minecraft.world.level.block.SoundType; import net.minecraft.world.level.block.StairBlock; import net.minecraft.world.level.block.state.BlockBehaviour; @@ -411,7 +411,7 @@ public class ModBlocks { .save(provider)) .register(); public static final BlockEntry RESIN_BLOCK = REGISTRATE - .block("resin_block", SlimeBlock::new) + .block("resin_block", ResinBlock::new) .initialProperties(() -> Blocks.SLIME_BLOCK) .blockstate((ctx, provider) -> { }) diff --git a/fabric/src/main/java/dev/dubhe/anvilcraft/mixin/fabric/PistonMovingBlockEntityMixin.java b/fabric/src/main/java/dev/dubhe/anvilcraft/mixin/fabric/PistonMovingBlockEntityMixin.java index 8e05370b9..99afc95c1 100644 --- a/fabric/src/main/java/dev/dubhe/anvilcraft/mixin/fabric/PistonMovingBlockEntityMixin.java +++ b/fabric/src/main/java/dev/dubhe/anvilcraft/mixin/fabric/PistonMovingBlockEntityMixin.java @@ -1,5 +1,6 @@ package dev.dubhe.anvilcraft.mixin.fabric; +import dev.dubhe.anvilcraft.block.ResinBlock; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.SlimeBlock; @@ -18,7 +19,8 @@ abstract class PistonMovingBlockEntityMixin { target = "Lnet/minecraft/world/level/block/state/BlockState;is(Lnet/minecraft/world/level/block/Block;)Z" ) ) - private static boolean isElastic(BlockState instance, Block block) { - return instance.getBlock() instanceof SlimeBlock; + private static boolean isElastic(BlockState instance, Block b) { + Block block = instance.getBlock(); + return block instanceof SlimeBlock || block instanceof ResinBlock; } } diff --git a/forge/src/main/java/dev/dubhe/anvilcraft/mixin/forge/PistonMovingBlockEntityMixin.java b/forge/src/main/java/dev/dubhe/anvilcraft/mixin/forge/PistonMovingBlockEntityMixin.java index 39fa94e15..802860ab6 100644 --- a/forge/src/main/java/dev/dubhe/anvilcraft/mixin/forge/PistonMovingBlockEntityMixin.java +++ b/forge/src/main/java/dev/dubhe/anvilcraft/mixin/forge/PistonMovingBlockEntityMixin.java @@ -1,5 +1,7 @@ package dev.dubhe.anvilcraft.mixin.forge; +import dev.dubhe.anvilcraft.block.ResinBlock; +import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.SlimeBlock; import net.minecraft.world.level.block.piston.PistonMovingBlockEntity; import net.minecraft.world.level.block.state.BlockState; @@ -19,6 +21,7 @@ abstract class PistonMovingBlockEntityMixin { ) ) private static boolean isElastic(@NotNull BlockState instance) { - return instance.getBlock() instanceof SlimeBlock; + Block block = instance.getBlock(); + return block instanceof SlimeBlock || block instanceof ResinBlock; } }