修改炮弹实体类型

This commit is contained in:
17146 2024-05-20 14:02:13 +08:00
parent 60c402cf21
commit 10d91c16b7
3 changed files with 21 additions and 42 deletions

View file

@ -34,7 +34,6 @@ 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.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.inventory.AbstractContainerMenu;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
@ -202,11 +201,7 @@ public class MortarEntity extends PathfinderMob implements GeoEntity, AnimatedEn
TargetMod.queueServerWork(20, () -> { TargetMod.queueServerWork(20, () -> {
Level level = this.level(); Level level = this.level();
if (level instanceof ServerLevel server) { if (level instanceof ServerLevel server) {
AbstractArrow entityToSpawn = new MortarShellEntity(TargetModEntities.MORTAR_SHELL.get(), level); MortarShellEntity entityToSpawn = new MortarShellEntity(TargetModEntities.MORTAR_SHELL.get(), player, level);
entityToSpawn.setOwner(player);
entityToSpawn.setBaseDamage(100);
entityToSpawn.setKnockback(0);
entityToSpawn.setSilent(true);
entityToSpawn.setPos(this.getX(), this.getEyeY(), this.getZ()); entityToSpawn.setPos(this.getX(), this.getEyeY(), this.getZ());
entityToSpawn.shoot(this.getLookAngle().x, this.getLookAngle().y, this.getLookAngle().z, 8, (float) 0.5); entityToSpawn.shoot(this.getLookAngle().x, this.getLookAngle().y, this.getLookAngle().z, 8, (float) 0.5);
level.addFreshEntity(entityToSpawn); level.addFreshEntity(entityToSpawn);

View file

@ -1,6 +1,6 @@
package net.mcreator.target.entity; package net.mcreator.target.entity;
import net.mcreator.target.init.TargetModEntities; import net.mcreator.target.init.TargetModItems;
import net.mcreator.target.tools.ParticleTool; import net.mcreator.target.tools.ParticleTool;
import net.minecraft.core.particles.ParticleTypes; import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.network.protocol.Packet; import net.minecraft.network.protocol.Packet;
@ -9,26 +9,15 @@ import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.projectile.AbstractArrow; import net.minecraft.world.entity.projectile.ThrowableItemProjectile;
import net.minecraft.world.entity.projectile.ItemSupplier; import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.EntityHitResult; import net.minecraft.world.phys.EntityHitResult;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.network.NetworkHooks; import net.minecraftforge.network.NetworkHooks;
import net.minecraftforge.network.PlayMessages;
// TODO 父类改为Projectile public class MortarShellEntity extends ThrowableItemProjectile {
@OnlyIn(value = Dist.CLIENT, _interface = ItemSupplier.class) private float damage = 100f;
public class MortarShellEntity extends AbstractArrow implements ItemSupplier {
public static final ItemStack PROJECTILE_ITEM = new ItemStack(Blocks.AIR);
public MortarShellEntity(PlayMessages.SpawnEntity packet, Level world) {
super(TargetModEntities.MORTAR_SHELL.get(), world);
}
public MortarShellEntity(EntityType<? extends MortarShellEntity> type, Level world) { public MortarShellEntity(EntityType<? extends MortarShellEntity> type, Level world) {
super(type, world); super(type, world);
@ -42,33 +31,28 @@ public class MortarShellEntity extends AbstractArrow implements ItemSupplier {
super(type, entity, world); super(type, entity, world);
} }
public MortarShellEntity(EntityType<? extends MortarShellEntity> type, LivingEntity entity, Level world, float damage) {
super(type, entity, world);
this.damage = damage;
}
@Override @Override
public Packet<ClientGamePacketListener> getAddEntityPacket() { public Packet<ClientGamePacketListener> getAddEntityPacket() {
return NetworkHooks.getEntitySpawningPacket(this); return NetworkHooks.getEntitySpawningPacket(this);
} }
@Override @Override
@OnlyIn(Dist.CLIENT) protected Item getDefaultItem() {
public ItemStack getItem() { return TargetModItems.MORTAR_SHELLS.get();
return PROJECTILE_ITEM;
} }
@Override
protected ItemStack getPickupItem() {
return PROJECTILE_ITEM;
}
@Override
protected void doPostHurtEffects(LivingEntity entity) {
super.doPostHurtEffects(entity);
entity.setArrowCount(entity.getArrowCount() - 1);
}
@Override @Override
public void onHitEntity(EntityHitResult entityHitResult) { public void onHitEntity(EntityHitResult entityHitResult) {
super.onHitEntity(entityHitResult);
Entity entity = entityHitResult.getEntity(); Entity entity = entityHitResult.getEntity();
entity.hurt(this.level().damageSources().thrown(this, this.getOwner()), this.damage);
if (this.level() instanceof ServerLevel level) { if (this.level() instanceof ServerLevel level) {
level.explode(this, (this.getX()), (this.getY()), (this.getZ()), 10, Level.ExplosionInteraction.NONE); level.explode(this, (this.getX()), (this.getY()), (this.getZ()), 10, Level.ExplosionInteraction.NONE);
if (!entity.level().isClientSide() && entity.getServer() != null) { if (!entity.level().isClientSide() && entity.getServer() != null) {
@ -81,9 +65,11 @@ public class MortarShellEntity extends AbstractArrow implements ItemSupplier {
@Override @Override
public void onHitBlock(BlockHitResult blockHitResult) { public void onHitBlock(BlockHitResult blockHitResult) {
super.onHitBlock(blockHitResult); super.onHitBlock(blockHitResult);
if (this.level() instanceof ServerLevel level) { if (!this.level().isClientSide() && this.level() instanceof ServerLevel level) {
level.explode(this, this.getX(), this.getY(), this.getZ(), 10, Level.ExplosionInteraction.NONE); level.explode(this, this.getX(), this.getY(), this.getZ(), 10, Level.ExplosionInteraction.NONE);
ParticleTool.spawnMediumExplosionParticles(this.level(), this.position());
} }
this.discard();
} }
@Override @Override
@ -93,10 +79,8 @@ public class MortarShellEntity extends AbstractArrow implements ItemSupplier {
ParticleTool.sendParticle(serverLevel, ParticleTypes.CAMPFIRE_COSY_SMOKE, this.getX(), this.getY(), this.getZ(), ParticleTool.sendParticle(serverLevel, ParticleTypes.CAMPFIRE_COSY_SMOKE, this.getX(), this.getY(), this.getZ(),
2, 0, 0, 0, 0.02, true); 2, 0, 0, 0, 0.02, true);
} }
if (this.inGround) { if (this.tickCount >= 600) {
if (!this.level().isClientSide() && this.getServer() != null) { this.level().explode(this, this.getX(), this.getY(), this.getZ(), 10, Level.ExplosionInteraction.NONE);
ParticleTool.spawnMediumExplosionParticles(this.level(), this.position());
}
this.discard(); this.discard();
} }
} }

View file

@ -36,7 +36,7 @@ public class TargetModEntities {
public static final RegistryObject<EntityType<RpgRocketEntity>> RPG_ROCKET = register("projectile_rpg_rocket", public static final RegistryObject<EntityType<RpgRocketEntity>> RPG_ROCKET = register("projectile_rpg_rocket",
EntityType.Builder.<RpgRocketEntity>of(RpgRocketEntity::new, MobCategory.MISC).setCustomClientFactory(RpgRocketEntity::new).setShouldReceiveVelocityUpdates(true).setTrackingRange(64).setUpdateInterval(1).sized(0.5f, 0.5f)); EntityType.Builder.<RpgRocketEntity>of(RpgRocketEntity::new, MobCategory.MISC).setCustomClientFactory(RpgRocketEntity::new).setShouldReceiveVelocityUpdates(true).setTrackingRange(64).setUpdateInterval(1).sized(0.5f, 0.5f));
public static final RegistryObject<EntityType<MortarShellEntity>> MORTAR_SHELL = register("projectile_mortar_shell", public static final RegistryObject<EntityType<MortarShellEntity>> MORTAR_SHELL = register("projectile_mortar_shell",
EntityType.Builder.<MortarShellEntity>of(MortarShellEntity::new, MobCategory.MISC).setCustomClientFactory(MortarShellEntity::new).setShouldReceiveVelocityUpdates(true).setTrackingRange(64).setUpdateInterval(1).sized(0.5f, 0.5f)); EntityType.Builder.<MortarShellEntity>of(MortarShellEntity::new, MobCategory.MISC).setShouldReceiveVelocityUpdates(true).setTrackingRange(64).setUpdateInterval(1).sized(0.5f, 0.5f));
public static final RegistryObject<EntityType<BocekArrowEntity>> BOCEK_ARROW = register("projectile_bocekarrow", public static final RegistryObject<EntityType<BocekArrowEntity>> BOCEK_ARROW = register("projectile_bocekarrow",
EntityType.Builder.<BocekArrowEntity>of(BocekArrowEntity::new, MobCategory.MISC).setCustomClientFactory(BocekArrowEntity::new).setShouldReceiveVelocityUpdates(true).setTrackingRange(64).setUpdateInterval(1).sized(0.5f, 0.5f)); EntityType.Builder.<BocekArrowEntity>of(BocekArrowEntity::new, MobCategory.MISC).setCustomClientFactory(BocekArrowEntity::new).setShouldReceiveVelocityUpdates(true).setTrackingRange(64).setUpdateInterval(1).sized(0.5f, 0.5f));
public static final RegistryObject<EntityType<ProjectileEntity>> PROJECTILE = register("projectile", public static final RegistryObject<EntityType<ProjectileEntity>> PROJECTILE = register("projectile",