From 6492ec5952656a9dab251fa23d25387df1f87cdf Mon Sep 17 00:00:00 2001 From: Atsuihsio <842960157@qq.com> Date: Thu, 31 Oct 2024 12:33:30 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=9D=E8=AF=95=E4=BF=AE=E6=94=B9=E8=BF=AB?= =?UTF-8?q?=E5=87=BB=E7=82=AE=E4=B8=BA=E4=B8=80=E8=88=ACEntity?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../renderer/entity/MortarRenderer.java | 10 + .../superbwarfare/entity/MortarEntity.java | 248 ++++++++++-------- .../superbwarfare/init/ModEntities.java | 2 +- .../message/AdjustMortarAngleMessage.java | 8 +- 4 files changed, 153 insertions(+), 115 deletions(-) diff --git a/src/main/java/net/mcreator/superbwarfare/client/renderer/entity/MortarRenderer.java b/src/main/java/net/mcreator/superbwarfare/client/renderer/entity/MortarRenderer.java index b092ddcf9..e5d2a0589 100644 --- a/src/main/java/net/mcreator/superbwarfare/client/renderer/entity/MortarRenderer.java +++ b/src/main/java/net/mcreator/superbwarfare/client/renderer/entity/MortarRenderer.java @@ -2,6 +2,7 @@ package net.mcreator.superbwarfare.client.renderer.entity; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.VertexConsumer; +import com.mojang.math.Axis; import net.mcreator.superbwarfare.entity.MortarEntity; import net.mcreator.superbwarfare.entity.layer.MortarLayer; import net.mcreator.superbwarfare.entity.model.MortarModel; @@ -9,6 +10,7 @@ import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.entity.EntityRendererProvider; import net.minecraft.resources.ResourceLocation; +import net.minecraft.util.Mth; import software.bernie.geckolib.cache.object.BakedGeoModel; import software.bernie.geckolib.renderer.GeoEntityRenderer; @@ -33,6 +35,14 @@ public class MortarRenderer extends GeoEntityRenderer { super.preRender(poseStack, entity, model, bufferSource, buffer, isReRender, partialTick, packedLight, packedOverlay, red, green, blue, alpha); } + @Override + public void render(MortarEntity entityIn, float entityYaw, float partialTicks, PoseStack poseStack, MultiBufferSource bufferIn, int packedLightIn) { + poseStack.pushPose(); + poseStack.mulPose(Axis.YP.rotationDegrees(-Mth.lerp(partialTicks, entityIn.yRotO, entityIn.getYRot()))); + super.render(entityIn, entityYaw, partialTicks, poseStack, bufferIn, packedLightIn); + poseStack.popPose(); + } + @Override protected float getDeathMaxRotation(MortarEntity entityLivingBaseIn) { return 0.0F; diff --git a/src/main/java/net/mcreator/superbwarfare/entity/MortarEntity.java b/src/main/java/net/mcreator/superbwarfare/entity/MortarEntity.java index 9b2246714..e8eaaac81 100644 --- a/src/main/java/net/mcreator/superbwarfare/entity/MortarEntity.java +++ b/src/main/java/net/mcreator/superbwarfare/entity/MortarEntity.java @@ -8,13 +8,13 @@ import net.mcreator.superbwarfare.init.ModSounds; import net.minecraft.core.NonNullList; import net.minecraft.core.particles.ParticleTypes; import net.minecraft.nbt.CompoundTag; +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; import net.minecraft.network.syncher.EntityDataSerializers; import net.minecraft.network.syncher.SynchedEntityData; import net.minecraft.server.level.ServerLevel; -import net.minecraft.sounds.SoundEvent; import net.minecraft.sounds.SoundSource; import net.minecraft.util.Mth; import net.minecraft.world.InteractionHand; @@ -22,15 +22,11 @@ import net.minecraft.world.InteractionResult; 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.Player; import net.minecraft.world.entity.projectile.ThrownPotion; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; import net.minecraft.world.phys.Vec3; -import net.minecraftforge.items.ItemHandlerHelper; import net.minecraftforge.network.NetworkHooks; import net.minecraftforge.network.PlayMessages; import software.bernie.geckolib.animatable.GeoEntity; @@ -42,7 +38,7 @@ import software.bernie.geckolib.core.animation.RawAnimation; import software.bernie.geckolib.core.object.PlayState; import software.bernie.geckolib.util.GeckoLibUtil; -public class MortarEntity extends LivingEntity implements GeoEntity, AnimatedEntity { +public class MortarEntity extends Entity implements GeoEntity, AnimatedEntity { public static final EntityDataAccessor ANIMATION = SynchedEntityData.defineId(MortarEntity.class, EntityDataSerializers.STRING); public static final EntityDataAccessor FIRE_TIME = SynchedEntityData.defineId(MortarEntity.class, EntityDataSerializers.INT); public static final EntityDataAccessor PITCH = SynchedEntityData.defineId(MortarEntity.class, EntityDataSerializers.FLOAT); @@ -64,14 +60,14 @@ public class MortarEntity extends LivingEntity implements GeoEntity, AnimatedEnt @Override protected void defineSynchedData() { - super.defineSynchedData(); this.entityData.define(ANIMATION, "undefined"); this.entityData.define(FIRE_TIME, 0); this.entityData.define(PITCH, 70f); } + @Override - protected float getStandingEyeHeight(Pose poseIn, EntityDimensions sizeIn) { + protected float getEyeHeight(Pose pPose, EntityDimensions pSize) { return 0.2F; } @@ -80,35 +76,16 @@ public class MortarEntity extends LivingEntity implements GeoEntity, AnimatedEnt return NetworkHooks.getEntitySpawningPacket(this); } - @Override - public MobType getMobType() { - return super.getMobType(); - } - @Override public Iterable getArmorSlots() { return NonNullList.withSize(1, ItemStack.EMPTY); } - @Override - public ItemStack getItemBySlot(EquipmentSlot pSlot) { - return ItemStack.EMPTY; - } @Override public void setItemSlot(EquipmentSlot pSlot, ItemStack pStack) { } - @Override - public SoundEvent getHurtSound(DamageSource ds) { - return ModSounds.HIT.get(); - } - - @Override - public SoundEvent getDeathSound() { - return ModSounds.HIT.get(); - } - @Override public boolean hurt(DamageSource source, float amount) { if (source.is(DamageTypes.IN_FIRE)) @@ -136,14 +113,12 @@ public class MortarEntity extends LivingEntity implements GeoEntity, AnimatedEnt @Override public void addAdditionalSaveData(CompoundTag compound) { - super.addAdditionalSaveData(compound); compound.putInt("FireTime", this.entityData.get(FIRE_TIME)); compound.putFloat("Pitch", this.entityData.get(PITCH)); } @Override public void readAdditionalSaveData(CompoundTag compound) { - super.readAdditionalSaveData(compound); if (compound.contains("FireTime")) { this.entityData.set(FIRE_TIME, compound.getInt("FireTime")); } @@ -153,50 +128,96 @@ public class MortarEntity extends LivingEntity implements GeoEntity, AnimatedEnt } @Override - public InteractionResult interact(Player player, InteractionHand hand) { - ItemStack mainHandItem = player.getMainHandItem(); - if (player.isShiftKeyDown()) { - if (mainHandItem.getItem() == ModItems.CROWBAR.get()){ - this.discard(); - ItemHandlerHelper.giveItemToPlayer(player, new ItemStack(ModItems.MORTAR_DEPLOYER.get())); - } - 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(); - } - if (mainHandItem.getItem() == ModItems.MORTAR_SHELLS.get() && !player.isShiftKeyDown() && this.entityData.get(FIRE_TIME) == 0) { - this.entityData.set(FIRE_TIME, 25); + public InteractionResult interactAt(Player player, Vec3 pVec, InteractionHand pHand) { - if (!player.isCreative()) { - player.getInventory().clearOrCountMatchingItems(p -> ModItems.MORTAR_SHELLS.get() == p.getItem(), 1, player.inventoryMenu.getCraftSlots()); - } - if (!this.level().isClientSide()) { - this.level().playSound(null, this.getX(), this.getY(), this.getZ(), ModSounds.MORTAR_LOAD.get(), SoundSource.PLAYERS, 1f, 1f); - this.level().playSound(null, this.getX(), this.getY(), this.getZ(), ModSounds.MORTAR_FIRE.get(), SoundSource.PLAYERS, 8f, 1f); - this.level().playSound(null, this.getX(), this.getY(), this.getZ(), ModSounds.MORTAR_DISTANT.get(), SoundSource.PLAYERS, 32f, 1f); - } - ModUtils.queueServerWork(20, () -> { - Level level = this.level(); - if (level instanceof ServerLevel server) { - MortarShellEntity entityToSpawn = new MortarShellEntity(ModEntities.MORTAR_SHELL.get(), player, level); - entityToSpawn.setPos(this.getX(), this.getEyeY(), 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() + 3 * this.getLookAngle().x), (this.getY() + 0.1 + 3 * this.getLookAngle().y), (this.getZ() + 3 * this.getLookAngle().z), 8, 0.4, 0.4, 0.4, - 0.007); - server.sendParticles(ParticleTypes.CAMPFIRE_COSY_SMOKE, this.getX(), this.getY(), this.getZ(), 50, 2, 0.02, 2, 0.0005); + player.displayClientMessage(Component.literal("114"), true); + if (!this.level().isClientSide) { + ItemStack mainHandItem = player.getMainHandItem(); + if (mainHandItem.getItem() == ModItems.MORTAR_SHELLS.get() && !player.isShiftKeyDown() && this.entityData.get(FIRE_TIME) == 0) { + this.entityData.set(FIRE_TIME, 25); + + if (!player.isCreative()) { + player.getInventory().clearOrCountMatchingItems(p -> ModItems.MORTAR_SHELLS.get() == p.getItem(), 1, player.inventoryMenu.getCraftSlots()); } - }); + if (!this.level().isClientSide()) { + this.level().playSound(null, this.getX(), this.getY(), this.getZ(), ModSounds.MORTAR_LOAD.get(), SoundSource.PLAYERS, 1f, 1f); + this.level().playSound(null, this.getX(), this.getY(), this.getZ(), ModSounds.MORTAR_FIRE.get(), SoundSource.PLAYERS, 8f, 1f); + this.level().playSound(null, this.getX(), this.getY(), this.getZ(), ModSounds.MORTAR_DISTANT.get(), SoundSource.PLAYERS, 32f, 1f); + } + ModUtils.queueServerWork(20, () -> { + Level level = this.level(); + if (level instanceof ServerLevel server) { + MortarShellEntity entityToSpawn = new MortarShellEntity(ModEntities.MORTAR_SHELL.get(), player, level); + entityToSpawn.setPos(this.getX(), this.getEyeY(), 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() + 3 * this.getLookAngle().x), (this.getY() + 0.1 + 3 * this.getLookAngle().y), (this.getZ() + 3 * this.getLookAngle().z), 8, 0.4, 0.4, 0.4, + 0.007); + server.sendParticles(ParticleTypes.CAMPFIRE_COSY_SMOKE, this.getX(), this.getY(), this.getZ(), 50, 2, 0.02, 2, 0.0005); + } + }); + } } - - return InteractionResult.sidedSuccess(this.level().isClientSide()); + return InteractionResult.SUCCESS; +// return InteractionResult.sidedSuccess(this.level().isClientSide()); } +// @Override +// public InteractionResult interact(Player player, InteractionHand pHand) { +// super.interact(player, pHand); +// player.displayClientMessage(Component.literal("114"), true); +// if (!this.level().isClientSide) { +// ItemStack mainHandItem = player.getMainHandItem(); +// if (mainHandItem.getItem() == ModItems.MORTAR_SHELLS.get() && !player.isShiftKeyDown() && this.entityData.get(FIRE_TIME) == 0) { +// this.entityData.set(FIRE_TIME, 25); +// +// if (!player.isCreative()) { +// player.getInventory().clearOrCountMatchingItems(p -> ModItems.MORTAR_SHELLS.get() == p.getItem(), 1, player.inventoryMenu.getCraftSlots()); +// } +// if (!this.level().isClientSide()) { +// this.level().playSound(null, this.getX(), this.getY(), this.getZ(), ModSounds.MORTAR_LOAD.get(), SoundSource.PLAYERS, 1f, 1f); +// this.level().playSound(null, this.getX(), this.getY(), this.getZ(), ModSounds.MORTAR_FIRE.get(), SoundSource.PLAYERS, 8f, 1f); +// this.level().playSound(null, this.getX(), this.getY(), this.getZ(), ModSounds.MORTAR_DISTANT.get(), SoundSource.PLAYERS, 32f, 1f); +// } +// ModUtils.queueServerWork(20, () -> { +// Level level = this.level(); +// if (level instanceof ServerLevel server) { +// MortarShellEntity entityToSpawn = new MortarShellEntity(ModEntities.MORTAR_SHELL.get(), player, level); +// entityToSpawn.setPos(this.getX(), this.getEyeY(), 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() + 3 * this.getLookAngle().x), (this.getY() + 0.1 + 3 * this.getLookAngle().y), (this.getZ() + 3 * this.getLookAngle().z), 8, 0.4, 0.4, 0.4, +// 0.007); +// server.sendParticles(ParticleTypes.CAMPFIRE_COSY_SMOKE, this.getX(), this.getY(), this.getZ(), 50, 2, 0.02, 2, 0.0005); +// } +// }); +// } +// } +// return InteractionResult.sidedSuccess(this.level().isClientSide()); +// } + +// @Override +// public InteractionResult interact(Player player, InteractionHand hand) { +// ItemStack mainHandItem = player.getMainHandItem(); +// if (player.isShiftKeyDown()) { +// if (mainHandItem.getItem() == ModItems.CROWBAR.get()){ +// this.discard(); +// ItemHandlerHelper.giveItemToPlayer(player, new ItemStack(ModItems.MORTAR_DEPLOYER.get())); +// } +// 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(); +// } +// +// +// return InteractionResult.sidedSuccess(this.level().isClientSide()); +// } + @Override public void lerpTo(double x, double y, double z, float yaw, float pitch, int interpolationSteps, boolean interpolate) { serverYRot = yaw; @@ -204,10 +225,15 @@ public class MortarEntity extends LivingEntity implements GeoEntity, AnimatedEnt this.interpolationSteps = 10; } - @Override - public void travel(Vec3 dir) { - this.setXRot(-Mth.clamp((float) entityData.get(PITCH), 20, 89)); - } +// @Override +// protected void setRot(float pYRot, float pXRot) { +// super.setRot(pYRot, -Mth.clamp(entityData.get(PITCH), 20, 89)); +// } + + // @Override +// public void travel(Vec3 dir) { +// this.setXRot(-Mth.clamp((float) entityData.get(PITCH), 20, 89)); +// } @Override public void baseTick() { @@ -215,6 +241,8 @@ public class MortarEntity extends LivingEntity implements GeoEntity, AnimatedEnt if (this.entityData.get(FIRE_TIME) > 0) { this.entityData.set(FIRE_TIME, this.entityData.get(FIRE_TIME) - 1); } + this.setXRot(-Mth.clamp(entityData.get(PITCH), 20, 89)); + this.xRotO = this.getXRot(); this.refreshDimensions(); } @@ -223,28 +251,28 @@ public class MortarEntity extends LivingEntity implements GeoEntity, AnimatedEnt return false; } - @Override - public HumanoidArm getMainArm() { - return HumanoidArm.RIGHT; - } +// @Override +// public HumanoidArm getMainArm() { +// return HumanoidArm.RIGHT; +// } +// +// @Override +// protected void doPush(Entity entityIn) { +// } +// +// @Override +// protected void pushEntities() { +// } - @Override - protected void doPush(Entity entityIn) { - } - - @Override - protected void pushEntities() { - } - - public static AttributeSupplier.Builder createAttributes() { - return Mob.createMobAttributes() - .add(Attributes.MOVEMENT_SPEED, 0) - .add(Attributes.MAX_HEALTH, 100) - .add(Attributes.ARMOR, 0) - .add(Attributes.ATTACK_DAMAGE, 0) - .add(Attributes.FOLLOW_RANGE, 16) - .add(Attributes.KNOCKBACK_RESISTANCE, 1); - } +// public static AttributeSupplier.Builder createAttributes() { +// return Mob.createMobAttributes() +// .add(Attributes.MOVEMENT_SPEED, 0) +// .add(Attributes.MAX_HEALTH, 100) +// .add(Attributes.ARMOR, 0) +// .add(Attributes.ATTACK_DAMAGE, 0) +// .add(Attributes.FOLLOW_RANGE, 16) +// .add(Attributes.KNOCKBACK_RESISTANCE, 1); +// } private PlayState movementPredicate(AnimationState event) { if (this.animationProcedure.equals("empty")) { @@ -256,23 +284,23 @@ public class MortarEntity extends LivingEntity implements GeoEntity, AnimatedEnt return PlayState.STOP; } - @Override - protected void tickDeath() { - ++this.deathTime; - if (this.deathTime == 5) { - this.remove(MortarEntity.RemovalReason.KILLED); - this.dropExperience(); - if (this.level() instanceof ServerLevel level) { - var x = this.getX(); - var y = this.getY(); - var z = this.getZ(); - level.explode(null, x, y, z, 0, Level.ExplosionInteraction.NONE); - ItemEntity mortar = new ItemEntity(level, x, (y + 1), z, new ItemStack(ModItems.MORTAR_DEPLOYER.get())); - mortar.setPickUpDelay(10); - level.addFreshEntity(mortar); - } - } - } +// @Override +// protected void tickDeath() { +// ++this.deathTime; +// if (this.deathTime == 5) { +// this.remove(MortarEntity.RemovalReason.KILLED); +// this.dropExperience(); +// if (this.level() instanceof ServerLevel level) { +// var x = this.getX(); +// var y = this.getY(); +// var z = this.getZ(); +// level.explode(null, x, y, z, 0, Level.ExplosionInteraction.NONE); +// ItemEntity mortar = new ItemEntity(level, x, (y + 1), z, new ItemStack(ModItems.MORTAR_DEPLOYER.get())); +// mortar.setPickUpDelay(10); +// level.addFreshEntity(mortar); +// } +// } +// } @Override public Vec3 getDeltaMovement() { diff --git a/src/main/java/net/mcreator/superbwarfare/init/ModEntities.java b/src/main/java/net/mcreator/superbwarfare/init/ModEntities.java index 0f78782ef..b2ea9781d 100644 --- a/src/main/java/net/mcreator/superbwarfare/init/ModEntities.java +++ b/src/main/java/net/mcreator/superbwarfare/init/ModEntities.java @@ -70,7 +70,7 @@ public class ModEntities { @SubscribeEvent public static void registerAttributes(EntityAttributeCreationEvent event) { event.put(TARGET.get(), TargetEntity.createAttributes().build()); - event.put(MORTAR.get(), MortarEntity.createAttributes().build()); +// event.put(MORTAR.get(), MortarEntity.createAttributes().build()); event.put(SENPAI.get(), SenpaiEntity.createAttributes().build()); event.put(MK_42.get(), Mk42Entity.createAttributes().build()); event.put(DRONE.get(), DroneEntity.createAttributes().build()); diff --git a/src/main/java/net/mcreator/superbwarfare/network/message/AdjustMortarAngleMessage.java b/src/main/java/net/mcreator/superbwarfare/network/message/AdjustMortarAngleMessage.java index 8fc7ef115..c7b44c66d 100644 --- a/src/main/java/net/mcreator/superbwarfare/network/message/AdjustMortarAngleMessage.java +++ b/src/main/java/net/mcreator/superbwarfare/network/message/AdjustMortarAngleMessage.java @@ -1,6 +1,7 @@ package net.mcreator.superbwarfare.network.message; import net.mcreator.superbwarfare.client.gui.RangeHelper; +import net.mcreator.superbwarfare.entity.MortarEntity; import net.mcreator.superbwarfare.init.ModSounds; import net.mcreator.superbwarfare.tools.SoundTool; import net.mcreator.superbwarfare.tools.TraceTool; @@ -9,7 +10,6 @@ import net.minecraft.network.chat.Component; import net.minecraft.server.level.ServerPlayer; import net.minecraft.util.Mth; import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.LivingEntity; import net.minecraftforge.network.NetworkEvent; import java.util.function.Supplier; @@ -43,9 +43,9 @@ public class AdjustMortarAngleMessage { double angle = 0; - if (looking instanceof LivingEntity living){ - living.getEntityData().set(PITCH, (float)Mth.clamp(living.getEntityData().get(PITCH) + 0.5 * message.scroll,20,89)); - angle = living.getEntityData().get(PITCH); + if (looking instanceof MortarEntity mortar){ + mortar.getEntityData().set(PITCH, (float)Mth.clamp(mortar.getEntityData().get(PITCH) + 0.5 * message.scroll,20,89)); + angle = mortar.getEntityData().get(PITCH); } player.displayClientMessage(Component.literal("Angle:" + new java.text.DecimalFormat("##.##").format(angle) + " Range:" + new java.text.DecimalFormat("##.#").format((int) RangeHelper.getRange(angle)) + "M"), true);