内联迫击炮右键过程

This commit is contained in:
Light_Quanta 2024-05-16 01:50:21 +08:00
parent bcbef8560f
commit b7eca6ae7d
No known key found for this signature in database
GPG key ID: 11A39A1B8C890959
2 changed files with 70 additions and 113 deletions

View file

@ -1,9 +1,16 @@
package net.mcreator.target.entity; package net.mcreator.target.entity;
import io.netty.buffer.Unpooled;
import net.mcreator.target.TargetMod;
import net.mcreator.target.init.TargetModEntities; import net.mcreator.target.init.TargetModEntities;
import net.mcreator.target.init.TargetModItems; import net.mcreator.target.init.TargetModItems;
import net.mcreator.target.procedures.MortarYouJiShiTiShiProcedure; import net.mcreator.target.init.TargetModSounds;
import net.mcreator.target.world.inventory.MortarGUIMenu;
import net.minecraft.core.BlockPos;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.chat.Component;
import net.minecraft.network.protocol.Packet; import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.ClientGamePacketListener; import net.minecraft.network.protocol.game.ClientGamePacketListener;
import net.minecraft.network.syncher.EntityDataAccessor; import net.minecraft.network.syncher.EntityDataAccessor;
@ -11,18 +18,24 @@ import net.minecraft.network.syncher.EntityDataSerializers;
import net.minecraft.network.syncher.SynchedEntityData; import net.minecraft.network.syncher.SynchedEntityData;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.sounds.SoundEvent; import net.minecraft.sounds.SoundEvent;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.DifficultyInstance; import net.minecraft.world.DifficultyInstance;
import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult; import net.minecraft.world.InteractionResult;
import net.minecraft.world.MenuProvider;
import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.damagesource.DamageTypes; import net.minecraft.world.damagesource.DamageTypes;
import net.minecraft.world.entity.*; import net.minecraft.world.entity.*;
import net.minecraft.world.entity.ai.attributes.AttributeSupplier; import net.minecraft.world.entity.ai.attributes.AttributeSupplier;
import net.minecraft.world.entity.ai.attributes.Attributes; import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.world.entity.item.ItemEntity; import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.projectile.AbstractArrow;
import net.minecraft.world.entity.projectile.ThrownPotion; import net.minecraft.world.entity.projectile.ThrownPotion;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.world.level.ServerLevelAccessor; import net.minecraft.world.level.ServerLevelAccessor;
@ -160,18 +173,66 @@ public class MortarEntity extends PathfinderMob implements GeoEntity, AnimatedEn
} }
@Override @Override
public InteractionResult mobInteract(Player sourceentity, InteractionHand hand) { public InteractionResult mobInteract(Player player, InteractionHand hand) {
ItemStack itemstack = sourceentity.getItemInHand(hand); super.mobInteract(player, hand);
InteractionResult retval = InteractionResult.sidedSuccess(this.level().isClientSide());
super.mobInteract(sourceentity, hand);
double x = this.getX(); double x = this.getX();
double y = this.getY(); double y = this.getY();
double z = this.getZ(); double z = this.getZ();
Entity entity = this;
Level world = this.level();
MortarYouJiShiTiShiProcedure.execute(world, x, y, z, entity, sourceentity); ItemStack mainHandItem = player.getMainHandItem();
return retval; if (mainHandItem.getItem() == ItemStack.EMPTY.getItem()) {
if (player.isShiftKeyDown()) {
this.setYRot(player.getYRot());
this.setXRot(this.getXRot());
this.setYBodyRot(this.getYRot());
this.setYHeadRot(this.getYRot());
this.yRotO = this.getYRot();
this.xRotO = this.getXRot();
this.yBodyRotO = this.getYRot();
this.yHeadRotO = this.getYRot();
} else if (player instanceof ServerPlayer serverPlayer) {
NetworkHooks.openScreen(serverPlayer, new MenuProvider() {
@Override
public Component getDisplayName() {
return Component.literal("MortarGUI");
}
@Override
public AbstractContainerMenu createMenu(int id, Inventory inventory, Player player) {
return new MortarGUIMenu(id, inventory, new FriendlyByteBuf(Unpooled.buffer()).writeBlockPos(BlockPos.containing(x, y, z)));
}
}, BlockPos.containing(x, y, z));
}
}
if (mainHandItem.getItem() == TargetModItems.MORTAR_SHELLS.get() && !player.getCooldowns().isOnCooldown(TargetModItems.MORTAR_SHELLS.get())) {
player.getCooldowns().addCooldown(TargetModItems.MORTAR_SHELLS.get(), 30);
if (!player.isCreative()) {
player.getInventory().clearOrCountMatchingItems(p -> TargetModItems.MORTAR_SHELLS.get() == p.getItem(), 1, player.inventoryMenu.getCraftSlots());
}
if (!this.level().isClientSide()) {
this.level().playSound(null, this.getX(), this.getY(), this.getZ(), TargetModSounds.MORTAR_LOAD.get(), SoundSource.PLAYERS, 1f, 1f);
this.level().playSound(null, this.getX(), this.getY(), this.getZ(), TargetModSounds.MORTAR_FIRE.get(), SoundSource.PLAYERS, 8f, 1f);
this.level().playSound(null, this.getX(), this.getY(), this.getZ(), TargetModSounds.MORTAR_DISTANT.get(), SoundSource.PLAYERS, 32f, 1f);
}
TargetMod.queueServerWork(20, () -> {
Level level = this.level();
if (level instanceof ServerLevel server) {
AbstractArrow entityToSpawn = new MortarShellEntity(TargetModEntities.MORTAR_SHELL.get(), level);
entityToSpawn.setOwner(player);
entityToSpawn.setBaseDamage(100);
entityToSpawn.setKnockback(0);
entityToSpawn.setSilent(true);
entityToSpawn.setPos(this.getX(), this.getEyeY() - 0.1, this.getZ());
entityToSpawn.shoot(this.getLookAngle().x, this.getLookAngle().y, this.getLookAngle().z, 8, (float) 0.5);
level.addFreshEntity(entityToSpawn);
server.sendParticles(ParticleTypes.CAMPFIRE_COSY_SMOKE, (this.getX() + 2.2 * this.getLookAngle().x), (this.getY() + 0.1 + 2.2 * this.getLookAngle().y), (this.getZ() + 2.2 * this.getLookAngle().z), 40, 0.4, 0.4, 0.4,
0.015);
}
});
}
return InteractionResult.sidedSuccess(this.level().isClientSide());
} }
@Override @Override

View file

@ -1,104 +0,0 @@
package net.mcreator.target.procedures;
import io.netty.buffer.Unpooled;
import net.mcreator.target.TargetMod;
import net.mcreator.target.entity.MortarShellEntity;
import net.mcreator.target.init.TargetModEntities;
import net.mcreator.target.init.TargetModItems;
import net.mcreator.target.world.inventory.MortarGUIMenu;
import net.minecraft.commands.CommandSource;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.core.BlockPos;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.MenuProvider;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.projectile.AbstractArrow;
import net.minecraft.world.entity.projectile.Projectile;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor;
import net.minecraftforge.network.NetworkHooks;
public class MortarYouJiShiTiShiProcedure {
public static void execute(LevelAccessor world, double x, double y, double z, Entity entity, Entity sourceentity) {
if (entity == null || sourceentity == null)
return;
if ((sourceentity instanceof LivingEntity _livEnt ? _livEnt.getMainHandItem() : ItemStack.EMPTY).getItem() == ItemStack.EMPTY.getItem()) {
if (sourceentity.isShiftKeyDown()) {
entity.setYRot(sourceentity.getYRot());
entity.setXRot(entity.getXRot());
entity.setYBodyRot(entity.getYRot());
entity.setYHeadRot(entity.getYRot());
entity.yRotO = entity.getYRot();
entity.xRotO = entity.getXRot();
if (entity instanceof LivingEntity _entity) {
_entity.yBodyRotO = _entity.getYRot();
_entity.yHeadRotO = _entity.getYRot();
}
} else {
if (sourceentity instanceof ServerPlayer _ent) {
BlockPos _bpos = BlockPos.containing(x, y, z);
NetworkHooks.openScreen(_ent, new MenuProvider() {
@Override
public Component getDisplayName() {
return Component.literal("MortarGUI");
}
@Override
public AbstractContainerMenu createMenu(int id, Inventory inventory, Player player) {
return new MortarGUIMenu(id, inventory, new FriendlyByteBuf(Unpooled.buffer()).writeBlockPos(_bpos));
}
}, _bpos);
}
}
}
if ((sourceentity instanceof LivingEntity _livEnt ? _livEnt.getMainHandItem() : ItemStack.EMPTY).getItem() == TargetModItems.MORTAR_SHELLS.get()
&& !(sourceentity instanceof Player _plrCldCheck10 && _plrCldCheck10.getCooldowns().isOnCooldown(TargetModItems.MORTAR_SHELLS.get()))) {
if (sourceentity instanceof Player player) {
player.getCooldowns().addCooldown(TargetModItems.MORTAR_SHELLS.get(), 30);
if (!player.isCreative()) {
ItemStack _stktoremove = new ItemStack(TargetModItems.MORTAR_SHELLS.get());
player.getInventory().clearOrCountMatchingItems(p -> _stktoremove.getItem() == p.getItem(), 1, player.inventoryMenu.getCraftSlots());
}
}
if (!entity.level().isClientSide() && entity.getServer() != null) {
entity.getServer().getCommands().performPrefixedCommand(new CommandSourceStack(CommandSource.NULL, entity.position(), entity.getRotationVector(), entity.level() instanceof ServerLevel ? (ServerLevel) entity.level() : null, 4,
entity.getName().getString(), entity.getDisplayName(), entity.level().getServer(), entity), "playsound target:mortar_load player @a ~ ~ ~ 1 1");
entity.getServer().getCommands().performPrefixedCommand(new CommandSourceStack(CommandSource.NULL, entity.position(), entity.getRotationVector(), entity.level() instanceof ServerLevel ? (ServerLevel) entity.level() : null, 4,
entity.getName().getString(), entity.getDisplayName(), entity.level().getServer(), entity), "playsound target:mortar_fire player @a ~ ~ ~ 8 1");
entity.getServer().getCommands().performPrefixedCommand(new CommandSourceStack(CommandSource.NULL, entity.position(), entity.getRotationVector(), entity.level() instanceof ServerLevel ? (ServerLevel) entity.level() : null, 4,
entity.getName().getString(), entity.getDisplayName(), entity.level().getServer(), entity), "playsound target:mortar_distant player @a ~ ~ ~ 32 1");
}
TargetMod.queueServerWork(20, () -> {
Level projectileLevel = entity.level();
if (!projectileLevel.isClientSide()) {
Projectile _entityToSpawn = new Object() {
public Projectile getArrow(Level level, Entity shooter, float damage, int knockback) {
AbstractArrow entityToSpawn = new MortarShellEntity(TargetModEntities.MORTAR_SHELL.get(), level);
entityToSpawn.setOwner(shooter);
entityToSpawn.setBaseDamage(damage);
entityToSpawn.setKnockback(knockback);
entityToSpawn.setSilent(true);
return entityToSpawn;
}
}.getArrow(projectileLevel, sourceentity, 100, 0);
_entityToSpawn.setPos(entity.getX(), entity.getEyeY() - 0.1, entity.getZ());
_entityToSpawn.shoot(entity.getLookAngle().x, entity.getLookAngle().y, entity.getLookAngle().z, 8, (float) 0.5);
projectileLevel.addFreshEntity(_entityToSpawn);
}
if (world instanceof ServerLevel _level)
_level.sendParticles(ParticleTypes.CAMPFIRE_COSY_SMOKE, (entity.getX() + 2.2 * entity.getLookAngle().x), (entity.getY() + 0.1 + 2.2 * entity.getLookAngle().y), (entity.getZ() + 2.2 * entity.getLookAngle().z), 40, 0.4, 0.4, 0.4,
0.015);
});
}
}
}