内联跳板弹射过程
This commit is contained in:
parent
c10572883c
commit
e05b946bcc
2 changed files with 35 additions and 71 deletions
|
@ -1,9 +1,12 @@
|
||||||
package net.mcreator.target.block;
|
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.BlockPos;
|
||||||
import net.minecraft.core.Direction;
|
import net.minecraft.core.Direction;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
|
import net.minecraft.sounds.SoundSource;
|
||||||
import net.minecraft.world.entity.Entity;
|
import net.minecraft.world.entity.Entity;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.item.TooltipFlag;
|
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.DirectionProperty;
|
||||||
import net.minecraft.world.level.block.state.properties.NoteBlockInstrument;
|
import net.minecraft.world.level.block.state.properties.NoteBlockInstrument;
|
||||||
import net.minecraft.world.level.storage.loot.LootParams;
|
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.CollisionContext;
|
||||||
import net.minecraft.world.phys.shapes.Shapes;
|
import net.minecraft.world.phys.shapes.Shapes;
|
||||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||||
|
@ -93,8 +97,35 @@ public class JumppadBlockBlock extends Block {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void entityInside(BlockState blockstate, Level world, BlockPos pos, Entity entity) {
|
public void entityInside(BlockState blockstate, Level level, BlockPos pos, Entity entity) {
|
||||||
super.entityInside(blockstate, world, pos, entity);
|
super.entityInside(blockstate, level, pos, entity);
|
||||||
JumppadBlockShiTiZaiFangKuaiZhongPengZhuangShiProcedure.execute(world, pos.getX(), pos.getY(), pos.getZ(), 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);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Add table
Reference in a new issue