修改RPG实体类型
This commit is contained in:
parent
10d91c16b7
commit
70a9195361
3 changed files with 45 additions and 96 deletions
|
@ -2,7 +2,9 @@ package net.mcreator.target.entity;
|
|||
|
||||
import net.mcreator.target.headshot.BoundingBoxManager;
|
||||
import net.mcreator.target.headshot.IHeadshotBox;
|
||||
import net.mcreator.target.init.TargetModDamageTypes;
|
||||
import net.mcreator.target.init.TargetModEntities;
|
||||
import net.mcreator.target.init.TargetModItems;
|
||||
import net.mcreator.target.init.TargetModSounds;
|
||||
import net.mcreator.target.network.TargetModVariables;
|
||||
import net.mcreator.target.tools.ParticleTool;
|
||||
|
@ -11,78 +13,44 @@ import net.minecraft.network.protocol.Packet;
|
|||
import net.minecraft.network.protocol.game.ClientGamePacketListener;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.util.RandomSource;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.entity.projectile.AbstractArrow;
|
||||
import net.minecraft.world.entity.projectile.ItemSupplier;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.entity.projectile.ThrowableItemProjectile;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.phys.AABB;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
import net.minecraft.world.phys.EntityHitResult;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.minecraftforge.network.NetworkHooks;
|
||||
import net.minecraftforge.network.PlayMessages;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
// TODO 父类改为Projectile
|
||||
@OnlyIn(value = Dist.CLIENT, _interface = ItemSupplier.class)
|
||||
public class RpgRocketEntity extends AbstractArrow implements ItemSupplier {
|
||||
public static final ItemStack PROJECTILE_ITEM = new ItemStack(Blocks.AIR);
|
||||
|
||||
public RpgRocketEntity(PlayMessages.SpawnEntity packet, Level world) {
|
||||
super(TargetModEntities.RPG_ROCKET.get(), world);
|
||||
}
|
||||
public class RpgRocketEntity extends ThrowableItemProjectile {
|
||||
private float damage = 150f;
|
||||
|
||||
public RpgRocketEntity(EntityType<? extends RpgRocketEntity> type, Level world) {
|
||||
super(type, world);
|
||||
}
|
||||
|
||||
public RpgRocketEntity(EntityType<? extends RpgRocketEntity> type, double x, double y, double z, Level world) {
|
||||
super(type, x, y, z, world);
|
||||
}
|
||||
|
||||
public RpgRocketEntity(EntityType<? extends RpgRocketEntity> type, LivingEntity entity, Level world) {
|
||||
super(type, entity, world);
|
||||
}
|
||||
|
||||
public RpgRocketEntity(LivingEntity entity, Level level, float damage) {
|
||||
super(TargetModEntities.RPG_ROCKET.get(), entity, level);
|
||||
this.damage = damage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Packet<ClientGamePacketListener> getAddEntityPacket() {
|
||||
return NetworkHooks.getEntitySpawningPacket(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public ItemStack getItem() {
|
||||
return PROJECTILE_ITEM;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ItemStack getPickupItem() {
|
||||
return PROJECTILE_ITEM;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doPostHurtEffects(LivingEntity entity) {
|
||||
super.doPostHurtEffects(entity);
|
||||
entity.setArrowCount(entity.getArrowCount() - 1);
|
||||
}
|
||||
|
||||
public static RpgRocketEntity shoot(Level world, LivingEntity entity, RandomSource random, float power, double damage, int knockback) {
|
||||
RpgRocketEntity entityArrow = new RpgRocketEntity(TargetModEntities.RPG_ROCKET.get(), entity, world);
|
||||
entityArrow.shoot(entity.getViewVector(1).x, entity.getViewVector(1).y, entity.getViewVector(1).z, power * 2, 0);
|
||||
entityArrow.setSilent(true);
|
||||
entityArrow.setCritArrow(false);
|
||||
entityArrow.setBaseDamage(damage);
|
||||
entityArrow.setKnockback(knockback);
|
||||
world.addFreshEntity(entityArrow);
|
||||
return entityArrow;
|
||||
protected Item getDefaultItem() {
|
||||
return TargetModItems.ROCKET.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -104,7 +72,6 @@ public class RpgRocketEntity extends AbstractArrow implements ItemSupplier {
|
|||
if (!entity.level().isClientSide()) {
|
||||
ParticleTool.spawnMediumExplosionParticles(this.level(), this.position());
|
||||
}
|
||||
|
||||
this.discard();
|
||||
}
|
||||
}
|
||||
|
@ -112,6 +79,7 @@ public class RpgRocketEntity extends AbstractArrow implements ItemSupplier {
|
|||
if (entity instanceof LivingEntity) {
|
||||
entity.invulnerableTime = 0;
|
||||
}
|
||||
|
||||
AABB boundingBox = entity.getBoundingBox();
|
||||
Vec3 startVec = this.position();
|
||||
Vec3 endVec = startVec.add(this.getDeltaMovement());
|
||||
|
@ -134,7 +102,6 @@ public class RpgRocketEntity extends AbstractArrow implements ItemSupplier {
|
|||
}
|
||||
if (headshot) {
|
||||
if (this.getOwner() instanceof LivingEntity living) {
|
||||
setBaseDamage(getBaseDamage() * 5);
|
||||
living.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
||||
capability.headIndicator = 25;
|
||||
capability.syncPlayerVariables(living);
|
||||
|
@ -147,7 +114,13 @@ public class RpgRocketEntity extends AbstractArrow implements ItemSupplier {
|
|||
}
|
||||
}
|
||||
}
|
||||
super.onHitEntity(result);
|
||||
|
||||
if (headshot) {
|
||||
entity.hurt(TargetModDamageTypes.causeGunFireHeadshotDamage(this.level().registryAccess(), this.getOwner()), this.damage * 5f);
|
||||
} else {
|
||||
entity.hurt(TargetModDamageTypes.causeGunFireDamage(this.level().registryAccess(), this.getOwner()), this.damage);
|
||||
}
|
||||
|
||||
this.discard();
|
||||
}
|
||||
|
||||
|
@ -163,22 +136,23 @@ public class RpgRocketEntity extends AbstractArrow implements ItemSupplier {
|
|||
if (this.getPersistentData().getInt("time") > 0) {
|
||||
if (this.level() instanceof ServerLevel level) {
|
||||
level.explode(this, this.getX(), this.getY(), this.getZ(), 6, Level.ExplosionInteraction.NONE);
|
||||
ParticleTool.spawnMediumExplosionParticles(this.level(), this.position());
|
||||
}
|
||||
}
|
||||
|
||||
this.discard();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
super.tick();
|
||||
|
||||
this.getPersistentData().putInt("time", (1 + this.getPersistentData().getInt("time")));
|
||||
double life = this.getPersistentData().getInt("time");
|
||||
if (life == 4) {
|
||||
if (this.tickCount == 4) {
|
||||
if (!this.level().isClientSide() && this.level() instanceof ServerLevel serverLevel) {
|
||||
ParticleTool.sendParticle(serverLevel, ParticleTypes.CAMPFIRE_COSY_SMOKE, this.getX(), this.getY(), this.getZ(), 50, 0.8, 0.8, 0.8, 0.01, true);
|
||||
}
|
||||
}
|
||||
if (life >= 4) {
|
||||
if (this.tickCount > 4) {
|
||||
this.setDeltaMovement(new Vec3((1.04 * this.getDeltaMovement().x()), (1.04 * this.getDeltaMovement().y() - 0.02), (1.04 * this.getDeltaMovement().z())));
|
||||
|
||||
if (!this.level().isClientSide() && this.level() instanceof ServerLevel serverLevel) {
|
||||
|
@ -186,20 +160,11 @@ public class RpgRocketEntity extends AbstractArrow implements ItemSupplier {
|
|||
ParticleTool.sendParticle(serverLevel, ParticleTypes.CAMPFIRE_COSY_SMOKE, this.getX(), this.getY(), this.getZ(), 2, 0, 0, 0, 0, true);
|
||||
}
|
||||
}
|
||||
if (life >= 90) {
|
||||
|
||||
if (this.tickCount >= 90) {
|
||||
if (!this.level().isClientSide()) {
|
||||
ParticleTool.spawnMediumExplosionParticles(this.level(), this.position());
|
||||
}
|
||||
if (!this.level().isClientSide())
|
||||
this.discard();
|
||||
}
|
||||
if (this.inGround) {
|
||||
if (!this.level().isClientSide()) {
|
||||
ParticleTool.spawnMediumExplosionParticles(this.level(), this.position());
|
||||
}
|
||||
this.discard();
|
||||
}
|
||||
if (this.tickCount > 100) {
|
||||
this.discard();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ public class TargetModEntities {
|
|||
public static final RegistryObject<EntityType<TargetEntity>> TARGET = register("target",
|
||||
EntityType.Builder.<TargetEntity>of(TargetEntity::new, MobCategory.CREATURE).setShouldReceiveVelocityUpdates(true).setTrackingRange(64).setUpdateInterval(3).setCustomClientFactory(TargetEntity::new).fireImmune().sized(0.875f, 2f));
|
||||
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).setShouldReceiveVelocityUpdates(true).setTrackingRange(64).setUpdateInterval(1).sized(0.5f, 0.5f));
|
||||
public static final RegistryObject<EntityType<MortarShellEntity>> MORTAR_SHELL = register("projectile_mortar_shell",
|
||||
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",
|
||||
|
@ -49,13 +49,7 @@ public class TargetModEntities {
|
|||
|
||||
@SubscribeEvent
|
||||
public static void init(FMLCommonSetupEvent event) {
|
||||
event.enqueueWork(() -> {
|
||||
Target1Entity.init();
|
||||
MortarEntity.init();
|
||||
SenpaiEntity.init();
|
||||
ClaymoreEntity.init();
|
||||
TargetEntity.init();
|
||||
});
|
||||
event.enqueueWork(SenpaiEntity::init);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
|
|
|
@ -2,7 +2,6 @@ package net.mcreator.target.procedures;
|
|||
|
||||
import net.mcreator.target.entity.RpgRocketEntity;
|
||||
import net.mcreator.target.init.TargetModAttributes;
|
||||
import net.mcreator.target.init.TargetModEntities;
|
||||
import net.mcreator.target.init.TargetModItems;
|
||||
import net.mcreator.target.init.TargetModSounds;
|
||||
import net.mcreator.target.network.TargetModVariables;
|
||||
|
@ -11,17 +10,18 @@ import net.minecraft.commands.CommandSourceStack;
|
|||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
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.item.ItemStack;
|
||||
import net.minecraft.world.level.Level;
|
||||
|
||||
// TODO 内联这个类
|
||||
public class RpgFireProcedure {
|
||||
public static void execute(Player player) {
|
||||
if (player.isSpectator()) return;
|
||||
if (player.isSpectator()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Level level = player.level();
|
||||
ItemStack mainHandItem = player.getMainHandItem();
|
||||
CompoundTag tag = mainHandItem.getOrCreateTag();
|
||||
|
||||
|
@ -34,13 +34,13 @@ public class RpgFireProcedure {
|
|||
capability.syncPlayerVariables(player);
|
||||
});
|
||||
|
||||
Level projectileLevel = player.level();
|
||||
if (!projectileLevel.isClientSide()) {
|
||||
Projectile projectile = getArrow(player, projectileLevel, tag);
|
||||
projectile.setPos(player.getX(), player.getEyeY() - 0.1, player.getZ());
|
||||
projectile.shoot(player.getLookAngle().x, player.getLookAngle().y, player.getLookAngle().z, (float) tag.getDouble("velocity"),
|
||||
|
||||
if (!level.isClientSide()) {
|
||||
RpgRocketEntity rocketEntity = new RpgRocketEntity(player, level, (float) tag.getDouble("damage"));
|
||||
rocketEntity.setPos(player.getX(), player.getEyeY() - 0.1, player.getZ());
|
||||
rocketEntity.shoot(player.getLookAngle().x, player.getLookAngle().y, player.getLookAngle().z, (float) tag.getDouble("velocity"),
|
||||
(float) player.getAttribute(TargetModAttributes.SPREAD.get()).getBaseValue());
|
||||
projectileLevel.addFreshEntity(projectile);
|
||||
level.addFreshEntity(rocketEntity);
|
||||
}
|
||||
|
||||
if (player.getServer() != null) {
|
||||
|
@ -50,32 +50,22 @@ public class RpgFireProcedure {
|
|||
("particle minecraft:cloud" + (" " + (player.getX() + 1.8 * player.getLookAngle().x)) + (" " + (player.getY() + player.getBbHeight() - 0.1 + 1.8 * player.getLookAngle().y))
|
||||
+ (" " + (player.getZ() + 1.8 * player.getLookAngle().z)) + " 0.4 0.4 0.4 0.005 30 force @s"));
|
||||
}
|
||||
|
||||
if (tag.getInt("ammo") == 1) {
|
||||
tag.putDouble("empty", 1);
|
||||
}
|
||||
|
||||
player.getCooldowns().addCooldown(mainHandItem.getItem(), 10);
|
||||
|
||||
if (!player.level().isClientSide() && player.getServer() != null) {
|
||||
player.level().playSound(null, player.blockPosition(), TargetModSounds.RPG_FIRE_1P.get(), SoundSource.PLAYERS, 2, 1);
|
||||
player.level().playSound(null, player.blockPosition(), TargetModSounds.RPG_FIRE_3P.get(), SoundSource.PLAYERS, 4, 1);
|
||||
player.level().playSound(null, player.blockPosition(), TargetModSounds.RPG_FAR.get(), SoundSource.PLAYERS, 8, 1);
|
||||
player.level().playSound(null, player.blockPosition(), TargetModSounds.RPG_VERYFAR.get(), SoundSource.PLAYERS, 16, 1);
|
||||
}
|
||||
|
||||
tag.putInt("fire_animation", 2);
|
||||
tag.putInt("ammo", tag.getInt("ammo") - 1);
|
||||
}
|
||||
}
|
||||
|
||||
private static Projectile getArrow(Player player, Level projectileLevel, CompoundTag tag) {
|
||||
return new Object() {
|
||||
public Projectile getArrow(Level level, Entity shooter, float damage, int knockback) {
|
||||
AbstractArrow entityToSpawn = new RpgRocketEntity(TargetModEntities.RPG_ROCKET.get(), level);
|
||||
entityToSpawn.setOwner(shooter);
|
||||
entityToSpawn.setBaseDamage(damage);
|
||||
entityToSpawn.setKnockback(knockback);
|
||||
entityToSpawn.setSilent(true);
|
||||
return entityToSpawn;
|
||||
}
|
||||
}.getArrow(projectileLevel, player, (float) ((tag.getDouble("damage") / tag.getDouble("velocity")) * (1 + 0.05 * tag.getInt("level"))), 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue