内联迫击炮部署过程

This commit is contained in:
Light_Quanta 2024-05-12 16:47:24 +08:00
parent 0101f5aeac
commit bd716ecdeb
No known key found for this signature in database
GPG key ID: 11A39A1B8C890959
2 changed files with 23 additions and 37 deletions

View file

@ -1,9 +1,13 @@
package net.mcreator.target.item; package net.mcreator.target.item;
import net.mcreator.target.procedures.RengchumortarProcedure; import net.mcreator.target.init.TargetModEntities;
import net.minecraft.core.BlockPos;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResultHolder; import net.minecraft.world.InteractionResultHolder;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.MobSpawnType;
import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item; import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
@ -24,9 +28,24 @@ public class MortarDeployerItem extends Item {
} }
@Override @Override
public InteractionResultHolder<ItemStack> use(Level world, Player entity, InteractionHand hand) { public InteractionResultHolder<ItemStack> use(Level world, Player player, InteractionHand hand) {
InteractionResultHolder<ItemStack> ar = super.use(world, entity, hand); InteractionResultHolder<ItemStack> ar = super.use(world, player, hand);
RengchumortarProcedure.execute(world, entity.getX(), entity.getY(), entity.getZ(), entity);
if (world instanceof ServerLevel level) {
Entity entityToSpawn = TargetModEntities.MORTAR.get().spawn(level, BlockPos.containing(player.getX() + 1.5 * player.getLookAngle().x, player.getY(), player.getZ() + 1.5 * player.getLookAngle().z), MobSpawnType.MOB_SUMMONED);
if (entityToSpawn != null) {
entityToSpawn.setYRot(player.getYRot());
entityToSpawn.setYBodyRot(player.getYRot());
entityToSpawn.setYHeadRot(player.getYRot());
entityToSpawn.setXRot(-70);
entityToSpawn.setDeltaMovement(0, 0, 0);
}
}
if (!player.isCreative()) {
player.getItemInHand(hand).shrink(1);
player.swing(InteractionHand.MAIN_HAND, true);
}
return ar; return ar;
} }
} }

View file

@ -1,33 +0,0 @@
package net.mcreator.target.procedures;
import net.mcreator.target.init.TargetModEntities;
import net.mcreator.target.init.TargetModItems;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.MobSpawnType;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.LevelAccessor;
public class RengchumortarProcedure {
public static void execute(LevelAccessor world, double x, double y, double z, Entity entity) {
if (entity == null) return;
if (world instanceof ServerLevel _level) {
Entity entityToSpawn = TargetModEntities.MORTAR.get().spawn(_level, BlockPos.containing(x + 1.5 * entity.getLookAngle().x, y, z + 1.5 * entity.getLookAngle().z), MobSpawnType.MOB_SUMMONED);
if (entityToSpawn != null) {
entityToSpawn.setYRot(entity.getYRot());
entityToSpawn.setYBodyRot(entity.getYRot());
entityToSpawn.setYHeadRot(entity.getYRot());
entityToSpawn.setXRot(-70);
entityToSpawn.setDeltaMovement(0, 0, 0);
}
}
if (entity instanceof Player player && !player.isCreative()) {
ItemStack _stktoremove = new ItemStack(TargetModItems.MORTAR_DEPLOYER.get());
player.getInventory().clearOrCountMatchingItems(p -> _stktoremove.getItem() == p.getItem(), 1, player.inventoryMenu.getCraftSlots());
player.swing(InteractionHand.MAIN_HAND, true);
}
}
}