From b7eca6ae7d99ad4d264aff4a7c2a3df31c7ee485 Mon Sep 17 00:00:00 2001 From: Light_Quanta Date: Thu, 16 May 2024 01:50:21 +0800 Subject: [PATCH] =?UTF-8?q?=E5=86=85=E8=81=94=E8=BF=AB=E5=87=BB=E7=82=AE?= =?UTF-8?q?=E5=8F=B3=E9=94=AE=E8=BF=87=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mcreator/target/entity/MortarEntity.java | 79 +++++++++++-- .../MortarYouJiShiTiShiProcedure.java | 104 ------------------ 2 files changed, 70 insertions(+), 113 deletions(-) delete mode 100644 src/main/java/net/mcreator/target/procedures/MortarYouJiShiTiShiProcedure.java diff --git a/src/main/java/net/mcreator/target/entity/MortarEntity.java b/src/main/java/net/mcreator/target/entity/MortarEntity.java index 919d5e9f7..2c8819a77 100644 --- a/src/main/java/net/mcreator/target/entity/MortarEntity.java +++ b/src/main/java/net/mcreator/target/entity/MortarEntity.java @@ -1,9 +1,16 @@ 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.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.network.FriendlyByteBuf; +import net.minecraft.network.chat.Component; import net.minecraft.network.protocol.Packet; import net.minecraft.network.protocol.game.ClientGamePacketListener; 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.resources.ResourceLocation; import net.minecraft.server.level.ServerLevel; +import net.minecraft.server.level.ServerPlayer; import net.minecraft.sounds.SoundEvent; +import net.minecraft.sounds.SoundSource; import net.minecraft.world.DifficultyInstance; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; +import net.minecraft.world.MenuProvider; import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.damagesource.DamageTypes; import net.minecraft.world.entity.*; import net.minecraft.world.entity.ai.attributes.AttributeSupplier; import net.minecraft.world.entity.ai.attributes.Attributes; 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.projectile.AbstractArrow; import net.minecraft.world.entity.projectile.ThrownPotion; +import net.minecraft.world.inventory.AbstractContainerMenu; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; import net.minecraft.world.level.ServerLevelAccessor; @@ -160,18 +173,66 @@ public class MortarEntity extends PathfinderMob implements GeoEntity, AnimatedEn } @Override - public InteractionResult mobInteract(Player sourceentity, InteractionHand hand) { - ItemStack itemstack = sourceentity.getItemInHand(hand); - InteractionResult retval = InteractionResult.sidedSuccess(this.level().isClientSide()); - super.mobInteract(sourceentity, hand); + public InteractionResult mobInteract(Player player, InteractionHand hand) { + super.mobInteract(player, hand); double x = this.getX(); double y = this.getY(); double z = this.getZ(); - Entity entity = this; - Level world = this.level(); - MortarYouJiShiTiShiProcedure.execute(world, x, y, z, entity, sourceentity); - return retval; + ItemStack mainHandItem = player.getMainHandItem(); + 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 diff --git a/src/main/java/net/mcreator/target/procedures/MortarYouJiShiTiShiProcedure.java b/src/main/java/net/mcreator/target/procedures/MortarYouJiShiTiShiProcedure.java deleted file mode 100644 index 6284a45c0..000000000 --- a/src/main/java/net/mcreator/target/procedures/MortarYouJiShiTiShiProcedure.java +++ /dev/null @@ -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); - }); - } - } -}