diff --git a/src/main/java/net/mcreator/target/block/JumppadBlockBlock.java b/src/main/java/net/mcreator/target/block/JumppadBlockBlock.java index 0be9c94fa..23dc2613f 100644 --- a/src/main/java/net/mcreator/target/block/JumppadBlockBlock.java +++ b/src/main/java/net/mcreator/target/block/JumppadBlockBlock.java @@ -1,9 +1,12 @@ package net.mcreator.target.block; -import net.mcreator.target.procedures.JumppadBlockShiTiZaiFangKuaiZhongPengZhuangShiProcedure; +import net.mcreator.target.entity.Target1Entity; +import net.mcreator.target.init.TargetModSounds; +import net.mcreator.target.network.TargetModVariables; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.network.chat.Component; +import net.minecraft.sounds.SoundSource; import net.minecraft.world.entity.Entity; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.TooltipFlag; @@ -17,6 +20,7 @@ import net.minecraft.world.level.block.state.StateDefinition; import net.minecraft.world.level.block.state.properties.DirectionProperty; import net.minecraft.world.level.block.state.properties.NoteBlockInstrument; import net.minecraft.world.level.storage.loot.LootParams; +import net.minecraft.world.phys.Vec3; import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.Shapes; import net.minecraft.world.phys.shapes.VoxelShape; @@ -93,8 +97,35 @@ public class JumppadBlockBlock extends Block { } @Override - public void entityInside(BlockState blockstate, Level world, BlockPos pos, Entity entity) { - super.entityInside(blockstate, world, pos, entity); - JumppadBlockShiTiZaiFangKuaiZhongPengZhuangShiProcedure.execute(world, pos.getX(), pos.getY(), pos.getZ(), entity); + public void entityInside(BlockState blockstate, Level level, BlockPos pos, Entity entity) { + super.entityInside(blockstate, level, pos, entity); + + // 禁止套娃 + if (entity instanceof Target1Entity) return; + + boolean zooming = entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).map(c -> c.zooming).orElse(false); + + if (entity.isShiftKeyDown()) { + if (entity.onGround()) { + entity.setDeltaMovement(new Vec3(5 * entity.getLookAngle().x, 1.5, 5 * entity.getLookAngle().z)); + } else { + entity.setDeltaMovement(new Vec3(1.8 * entity.getLookAngle().x, 1.5, 1.8 * entity.getLookAngle().z)); + } + } else { + entity.setDeltaMovement(new Vec3(0.7 * entity.getDeltaMovement().x(), 1.7, 0.7 * entity.getDeltaMovement().z())); + } + + if (!zooming) entity.getPersistentData().putDouble("vy", 0.8); + + if (!level.isClientSide()) { + level.playSound(null, BlockPos.containing(pos.getX(), pos.getY(), pos.getZ()), TargetModSounds.JUMP.get(), SoundSource.BLOCKS, 1, 1); + } else { + level.playLocalSound(pos.getX(), pos.getY(), pos.getZ(), TargetModSounds.JUMP.get(), SoundSource.BLOCKS, 1, 1, false); + } + + entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> { + capability.playerDoubleJump = true; + capability.syncPlayerVariables(entity); + }); } } diff --git a/src/main/java/net/mcreator/target/procedures/JumppadBlockShiTiZaiFangKuaiZhongPengZhuangShiProcedure.java b/src/main/java/net/mcreator/target/procedures/JumppadBlockShiTiZaiFangKuaiZhongPengZhuangShiProcedure.java deleted file mode 100644 index c3aa28451..000000000 --- a/src/main/java/net/mcreator/target/procedures/JumppadBlockShiTiZaiFangKuaiZhongPengZhuangShiProcedure.java +++ /dev/null @@ -1,67 +0,0 @@ -package net.mcreator.target.procedures; - -import net.mcreator.target.entity.Target1Entity; -import net.mcreator.target.network.TargetModVariables; -import net.minecraft.core.BlockPos; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.sounds.SoundSource; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.LevelAccessor; -import net.minecraft.world.phys.Vec3; -import net.minecraftforge.registries.ForgeRegistries; - -public class JumppadBlockShiTiZaiFangKuaiZhongPengZhuangShiProcedure { - public static void execute(LevelAccessor world, double x, double y, double z, Entity entity) { - if (entity == null) - return; - if (!(entity instanceof Target1Entity)) { - if (entity.isShiftKeyDown()) { - if (entity.onGround()) { - entity.setDeltaMovement(new Vec3((5 * entity.getLookAngle().x), 1.5, (5 * entity.getLookAngle().z))); - if (!(entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).zooming) { - entity.getPersistentData().putDouble("vy", 0.8); - } - if (world instanceof Level _level) { - if (!_level.isClientSide()) { - _level.playSound(null, BlockPos.containing(x, y, z), ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation("target:jump")), SoundSource.BLOCKS, 1, 1); - } else { - _level.playLocalSound(x, y, z, ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation("target:jump")), SoundSource.BLOCKS, 1, 1, false); - } - } - } else { - entity.setDeltaMovement(new Vec3((1.8 * entity.getLookAngle().x), 1.5, (1.8 * entity.getLookAngle().z))); - if (!(entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).zooming) { - entity.getPersistentData().putDouble("vy", 0.8); - } - if (world instanceof Level _level) { - if (!_level.isClientSide()) { - _level.playSound(null, BlockPos.containing(x, y, z), ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation("target:jump")), SoundSource.BLOCKS, 1, 1); - } else { - _level.playLocalSound(x, y, z, ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation("target:jump")), SoundSource.BLOCKS, 1, 1, false); - } - } - } - } else { - entity.setDeltaMovement(new Vec3((0.7 * entity.getDeltaMovement().x()), 1.7, (0.7 * entity.getDeltaMovement().z()))); - if (!(entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).zooming) { - entity.getPersistentData().putDouble("vy", 0.8); - } - if (world instanceof Level _level) { - if (!_level.isClientSide()) { - _level.playSound(null, BlockPos.containing(x, y, z), ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation("target:jump")), SoundSource.BLOCKS, 1, 1); - } else { - _level.playLocalSound(x, y, z, ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation("target:jump")), SoundSource.BLOCKS, 1, 1, false); - } - } - } - { - boolean _setval = true; - entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> { - capability.playerDoubleJump = _setval; - capability.syncPlayerVariables(entity); - }); - } - } - } -}