添加炮弹伤害类型,修复穿甲弹
This commit is contained in:
parent
aa6118e27f
commit
b15a005b82
15 changed files with 85 additions and 34 deletions
|
@ -6,12 +6,9 @@ import net.mcreator.target.entity.DroneEntity;
|
||||||
import net.mcreator.target.init.TargetModItems;
|
import net.mcreator.target.init.TargetModItems;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.renderer.GameRenderer;
|
import net.minecraft.client.renderer.GameRenderer;
|
||||||
import net.minecraft.network.chat.Component;
|
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.level.ClipContext;
|
|
||||||
import net.minecraft.world.phys.Vec3;
|
|
||||||
import net.minecraftforge.api.distmarker.Dist;
|
import net.minecraftforge.api.distmarker.Dist;
|
||||||
import net.minecraftforge.client.event.RenderGuiEvent;
|
import net.minecraftforge.client.event.RenderGuiEvent;
|
||||||
import net.minecraftforge.eventbus.api.EventPriority;
|
import net.minecraftforge.eventbus.api.EventPriority;
|
||||||
|
@ -49,12 +46,16 @@ public class DroneUIOverlay {
|
||||||
double distance = player.distanceTo(entity);
|
double distance = player.distanceTo(entity);
|
||||||
int color = -1;
|
int color = -1;
|
||||||
|
|
||||||
// event.getGuiGraphics().drawString(Minecraft.getInstance().font, "MaxDistance:" + new DecimalFormat("##.#").format(MAX_DISTANCE) + "M", w / 2 + 10, h / 2 + 50, color, false);
|
|
||||||
|
|
||||||
if (distance > MAX_DISTANCE - 48) {
|
if (distance > MAX_DISTANCE - 48) {
|
||||||
event.getGuiGraphics().drawString(Minecraft.getInstance().font, "WARNING", w / 2 + -18, h / 2 + -47, -65536, false);
|
event.getGuiGraphics().drawString(Minecraft.getInstance().font, "WARNING", w / 2 + -18, h / 2 + -47, -65536, false);
|
||||||
color = -65536;
|
color = -65536;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
event.getGuiGraphics().drawString(Minecraft.getInstance().font, "Distance:" + new DecimalFormat("##.#").format(distance) + "M", w / 2 + 10, h / 2 + 33, color, false);
|
||||||
|
event.getGuiGraphics().drawString(Minecraft.getInstance().font, "Health:" + new DecimalFormat("##.#").format(entity.getHealth()) + "/" + new DecimalFormat("##").format(entity.getMaxHealth()), w / 2 - 77, h / 2 + 33, -1, false);
|
||||||
|
event.getGuiGraphics().drawString(Minecraft.getInstance().font, "AMMO:" + new DecimalFormat("##.#").format(entity.getEntityData().get(AMMO)) + " / 6", w / 2 + 12, h / 2 + -37, -1, false);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
RenderSystem.depthMask(true);
|
RenderSystem.depthMask(true);
|
||||||
|
|
|
@ -35,6 +35,7 @@ public class CannonShellEntity extends ThrowableItemProjectile {
|
||||||
private float fireProbability = 0;
|
private float fireProbability = 0;
|
||||||
private int fireTime = 0;
|
private int fireTime = 0;
|
||||||
private int durability = 40;
|
private int durability = 40;
|
||||||
|
private boolean firstHit = true;
|
||||||
|
|
||||||
public CannonShellEntity(EntityType<? extends CannonShellEntity> type, Level world) {
|
public CannonShellEntity(EntityType<? extends CannonShellEntity> type, Level world) {
|
||||||
super(type, world);
|
super(type, world);
|
||||||
|
@ -79,7 +80,7 @@ public class CannonShellEntity extends ThrowableItemProjectile {
|
||||||
@Override
|
@Override
|
||||||
public void onHitEntity(EntityHitResult entityHitResult) {
|
public void onHitEntity(EntityHitResult entityHitResult) {
|
||||||
Entity entity = entityHitResult.getEntity();
|
Entity entity = entityHitResult.getEntity();
|
||||||
entity.hurt(this.level().damageSources().thrown(this, this.getOwner()), this.damage);
|
entity.hurt(TargetModDamageTypes.causeCannonFireDamage(this.level().registryAccess(), this, this.getOwner()), this.damage);
|
||||||
entity.invulnerableTime = 0;
|
entity.invulnerableTime = 0;
|
||||||
|
|
||||||
if (this.getOwner() instanceof LivingEntity living) {
|
if (this.getOwner() instanceof LivingEntity living) {
|
||||||
|
@ -118,6 +119,11 @@ public class CannonShellEntity extends ThrowableItemProjectile {
|
||||||
int y = blockHitResult.getBlockPos().getY();
|
int y = blockHitResult.getBlockPos().getY();
|
||||||
int z = blockHitResult.getBlockPos().getZ();
|
int z = blockHitResult.getBlockPos().getZ();
|
||||||
|
|
||||||
|
if (this.firstHit) {
|
||||||
|
ParticleTool.cannonHitParticles(this.level(), this.position());
|
||||||
|
this.firstHit = false;
|
||||||
|
}
|
||||||
|
|
||||||
BlockState blockState = this.level().getBlockState(BlockPos.containing(x, y, z));
|
BlockState blockState = this.level().getBlockState(BlockPos.containing(x, y, z));
|
||||||
if (blockState.is(Blocks.BEDROCK) || blockState.is(Blocks.BARRIER)) {
|
if (blockState.is(Blocks.BEDROCK) || blockState.is(Blocks.BARRIER)) {
|
||||||
if (!this.level().isClientSide()) {
|
if (!this.level().isClientSide()) {
|
||||||
|
@ -130,6 +136,9 @@ public class CannonShellEntity extends ThrowableItemProjectile {
|
||||||
float hardness = this.level().getBlockState(BlockPos.containing(x, y, z)).getBlock().defaultDestroyTime();
|
float hardness = this.level().getBlockState(BlockPos.containing(x, y, z)).getBlock().defaultDestroyTime();
|
||||||
this.durability -= (int) hardness;
|
this.durability -= (int) hardness;
|
||||||
|
|
||||||
|
Vec3 vec = this.getDeltaMovement();
|
||||||
|
this.setDeltaMovement(vec.multiply(0.9, 0.9, 0.9));
|
||||||
|
|
||||||
if (blockState.is(TargetModBlocks.BARBED_WIRE.get()) || blockState.is(Blocks.NETHERITE_BLOCK)) {
|
if (blockState.is(TargetModBlocks.BARBED_WIRE.get()) || blockState.is(Blocks.NETHERITE_BLOCK)) {
|
||||||
this.durability -= 10;
|
this.durability -= 10;
|
||||||
}
|
}
|
||||||
|
@ -142,18 +151,19 @@ public class CannonShellEntity extends ThrowableItemProjectile {
|
||||||
this.durability -= 3;
|
this.durability -= 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vec3 vec = this.getDeltaMovement();
|
|
||||||
double vec_x = vec.x;
|
|
||||||
double vec_y = vec.y;
|
|
||||||
double vec_z = vec.z;
|
|
||||||
|
|
||||||
this.setDeltaMovement(vec_x - 0.02 * vec_x * hardness, vec_y - 0.02 * vec_y * hardness, vec_z - 0.02 * vec_z * hardness);
|
|
||||||
|
|
||||||
if (this.durability <= 0) {
|
if (this.durability <= 0) {
|
||||||
if (!this.level().isClientSide()) {
|
if (!this.level().isClientSide()) {
|
||||||
causeExplode();
|
causeExplode();
|
||||||
}
|
}
|
||||||
this.discard();
|
}
|
||||||
|
|
||||||
|
if (this.durability > 0) {
|
||||||
|
TargetMod.queueServerWork(1, () -> {
|
||||||
|
this.setDeltaMovement(vec.multiply(0.1, 0.1, 0.1));
|
||||||
|
if (!this.level().isClientSide()) {
|
||||||
|
causeExplode();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -168,7 +178,6 @@ public class CannonShellEntity extends ThrowableItemProjectile {
|
||||||
if (this.level() instanceof ServerLevel) {
|
if (this.level() instanceof ServerLevel) {
|
||||||
causeExplode();
|
causeExplode();
|
||||||
}
|
}
|
||||||
this.discard();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -189,6 +198,7 @@ public class CannonShellEntity extends ThrowableItemProjectile {
|
||||||
} else {
|
} else {
|
||||||
ParticleTool.spawnMediumExplosionParticles(this.level(), this.position());
|
ParticleTool.spawnMediumExplosionParticles(this.level(), this.position());
|
||||||
}
|
}
|
||||||
|
this.discard();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -79,13 +79,6 @@ public class GunGrenadeEntity extends ThrowableItemProjectile {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.tickCount > 0) {
|
|
||||||
if (this.level() instanceof ServerLevel) {
|
|
||||||
causeExplode();
|
|
||||||
this.discard();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (entity instanceof LivingEntity) {
|
if (entity instanceof LivingEntity) {
|
||||||
entity.invulnerableTime = 0;
|
entity.invulnerableTime = 0;
|
||||||
}
|
}
|
||||||
|
@ -137,6 +130,12 @@ public class GunGrenadeEntity extends ThrowableItemProjectile {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.tickCount > 0) {
|
||||||
|
if (this.level() instanceof ServerLevel) {
|
||||||
|
causeExplode();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.discard();
|
this.discard();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -60,7 +60,7 @@ public class MortarShellEntity extends ThrowableItemProjectile {
|
||||||
public void onHitEntity(EntityHitResult entityHitResult) {
|
public void onHitEntity(EntityHitResult entityHitResult) {
|
||||||
Entity entity = entityHitResult.getEntity();
|
Entity entity = entityHitResult.getEntity();
|
||||||
|
|
||||||
entity.hurt(this.level().damageSources().thrown(this, this.getOwner()), this.damage);
|
entity.hurt(TargetModDamageTypes.causeCannonFireDamage(this.level().registryAccess(), this, this.getOwner()), this.damage);
|
||||||
|
|
||||||
if (this.level() instanceof ServerLevel) {
|
if (this.level() instanceof ServerLevel) {
|
||||||
causeExplode();
|
causeExplode();
|
||||||
|
|
|
@ -79,13 +79,6 @@ public class RpgRocketEntity extends ThrowableItemProjectile {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.tickCount > 1) {
|
|
||||||
if (this.level() instanceof ServerLevel) {
|
|
||||||
causeExplode();
|
|
||||||
this.discard();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (entity instanceof LivingEntity) {
|
if (entity instanceof LivingEntity) {
|
||||||
entity.invulnerableTime = 0;
|
entity.invulnerableTime = 0;
|
||||||
}
|
}
|
||||||
|
@ -137,6 +130,12 @@ public class RpgRocketEntity extends ThrowableItemProjectile {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.tickCount > 1) {
|
||||||
|
if (this.level() instanceof ServerLevel) {
|
||||||
|
causeExplode();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.discard();
|
this.discard();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@ public class TargetModDamageTypes {
|
||||||
public static final ResourceKey<DamageType> BEAST = ResourceKey.create(Registries.DAMAGE_TYPE, new ResourceLocation(TargetMod.MODID, "beast"));
|
public static final ResourceKey<DamageType> BEAST = ResourceKey.create(Registries.DAMAGE_TYPE, new ResourceLocation(TargetMod.MODID, "beast"));
|
||||||
public static final ResourceKey<DamageType> SHOCK = ResourceKey.create(Registries.DAMAGE_TYPE, new ResourceLocation(TargetMod.MODID, "shock"));
|
public static final ResourceKey<DamageType> SHOCK = ResourceKey.create(Registries.DAMAGE_TYPE, new ResourceLocation(TargetMod.MODID, "shock"));
|
||||||
public static final ResourceKey<DamageType> PROJECTILE_BOOM = ResourceKey.create(Registries.DAMAGE_TYPE, new ResourceLocation(TargetMod.MODID, "projectile_boom"));
|
public static final ResourceKey<DamageType> PROJECTILE_BOOM = ResourceKey.create(Registries.DAMAGE_TYPE, new ResourceLocation(TargetMod.MODID, "projectile_boom"));
|
||||||
|
public static final ResourceKey<DamageType> CANNON_FIRE = ResourceKey.create(Registries.DAMAGE_TYPE, new ResourceLocation(TargetMod.MODID, "cannon_fire"));
|
||||||
|
|
||||||
public static DamageSource causeGunFireDamage(RegistryAccess registryAccess, @Nullable Entity directEntity, @Nullable Entity attacker) {
|
public static DamageSource causeGunFireDamage(RegistryAccess registryAccess, @Nullable Entity directEntity, @Nullable Entity attacker) {
|
||||||
return new DamageMessages(registryAccess.registry(Registries.DAMAGE_TYPE).get().getHolderOrThrow(GUN_FIRE), directEntity, attacker);
|
return new DamageMessages(registryAccess.registry(Registries.DAMAGE_TYPE).get().getHolderOrThrow(GUN_FIRE), directEntity, attacker);
|
||||||
|
@ -53,6 +54,10 @@ public class TargetModDamageTypes {
|
||||||
return new DamageMessages(registryAccess.registry(Registries.DAMAGE_TYPE).get().getHolderOrThrow(PROJECTILE_BOOM), directEntity, attacker);
|
return new DamageMessages(registryAccess.registry(Registries.DAMAGE_TYPE).get().getHolderOrThrow(PROJECTILE_BOOM), directEntity, attacker);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static DamageSource causeCannonFireDamage(RegistryAccess registryAccess, @Nullable Entity directEntity, @Nullable Entity attacker) {
|
||||||
|
return new DamageMessages(registryAccess.registry(Registries.DAMAGE_TYPE).get().getHolderOrThrow(CANNON_FIRE), directEntity, attacker);
|
||||||
|
}
|
||||||
|
|
||||||
private static class DamageMessages extends DamageSource {
|
private static class DamageMessages extends DamageSource {
|
||||||
public DamageMessages(Holder.Reference<DamageType> typeReference) {
|
public DamageMessages(Holder.Reference<DamageType> typeReference) {
|
||||||
super(typeReference);
|
super(typeReference);
|
||||||
|
|
|
@ -100,4 +100,17 @@ public class ParticleTool {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void cannonHitParticles(Level level, Vec3 pos) {
|
||||||
|
double x = pos.x;
|
||||||
|
double y = pos.y;
|
||||||
|
double z = pos.z;
|
||||||
|
|
||||||
|
if (level instanceof ServerLevel serverLevel) {
|
||||||
|
sendParticle(serverLevel, ParticleTypes.EXPLOSION, x, y, z, 2, 0.5, 0.5, 0.5, 1, true);
|
||||||
|
sendParticle(serverLevel, ParticleTypes.FLASH, x, y, z, 2, 0.2, 0.2, 0.2, 10, true);
|
||||||
|
sendParticle(serverLevel, TargetModParticleTypes.FIRE_STAR.get(), x, y, z, 40, 0, 0, 0, 1.5, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -177,6 +177,9 @@
|
||||||
"death.attack.projectile_boom": "%1$s blew up",
|
"death.attack.projectile_boom": "%1$s blew up",
|
||||||
"death.attack.projectile_boom.entity": "%1$s was blown up by %2$s",
|
"death.attack.projectile_boom.entity": "%1$s was blown up by %2$s",
|
||||||
"death.attack.projectile_boom.item": "%1$s was blown up by %2$s using %3$s",
|
"death.attack.projectile_boom.item": "%1$s was blown up by %2$s using %3$s",
|
||||||
|
"death.attack.cannon_fire": "%1$s was cracked by a shell",
|
||||||
|
"death.attack.cannon_fire.entity": "%1$s was cracked by %2$s",
|
||||||
|
"death.attack.cannon_fire.item": "%1$s was cracked by %2$s using %3$s",
|
||||||
|
|
||||||
"gui.target.gun_recycle_gui.tooltip_if_guns_level_10you_will_get": "If gun\u0027s level \u003e 10,you will get soul nuggets",
|
"gui.target.gun_recycle_gui.tooltip_if_guns_level_10you_will_get": "If gun\u0027s level \u003e 10,you will get soul nuggets",
|
||||||
"gui.target.gun_recycle_gui.button_dismantle": "Dismantle",
|
"gui.target.gun_recycle_gui.button_dismantle": "Dismantle",
|
||||||
|
|
|
@ -177,6 +177,9 @@
|
||||||
"death.attack.projectile_boom": "%1$s被轰上了天",
|
"death.attack.projectile_boom": "%1$s被轰上了天",
|
||||||
"death.attack.projectile_boom.entity": "%1$s被%2$s轰上了天",
|
"death.attack.projectile_boom.entity": "%1$s被%2$s轰上了天",
|
||||||
"death.attack.projectile_boom.item": "%1$s被%2$s用%3$s轰上了天",
|
"death.attack.projectile_boom.item": "%1$s被%2$s用%3$s轰上了天",
|
||||||
|
"death.attack.cannon_fire": "%1$s被炮弹打得四分五裂",
|
||||||
|
"death.attack.cannon_fire.entity": "%1$s被%2$s用炮弹打得四分五裂",
|
||||||
|
"death.attack.cannon_fire.item": "%1$s被%2$s用%3$s打得四分五裂",
|
||||||
|
|
||||||
"gui.target.gun_recycle_gui.tooltip_if_guns_level_10you_will_get": "如果枪械熟练度大于10级,你将会获得魂钢粒",
|
"gui.target.gun_recycle_gui.tooltip_if_guns_level_10you_will_get": "如果枪械熟练度大于10级,你将会获得魂钢粒",
|
||||||
"gui.target.gun_recycle_gui.button_dismantle": "拆解",
|
"gui.target.gun_recycle_gui.button_dismantle": "拆解",
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
{
|
{
|
||||||
"replace": false,
|
"replace": false,
|
||||||
"values": [
|
"values": [
|
||||||
"target:projectile_boom"
|
"target:projectile_boom",
|
||||||
|
"target:cannon_fire"
|
||||||
]
|
]
|
||||||
}
|
}
|
|
@ -3,6 +3,9 @@
|
||||||
"values": [
|
"values": [
|
||||||
"target:gunfire",
|
"target:gunfire",
|
||||||
"target:gunfire_headshot",
|
"target:gunfire_headshot",
|
||||||
"target:shock"
|
"target:arrow_in_knee",
|
||||||
|
"target:arrow_in_brain",
|
||||||
|
"target:shock",
|
||||||
|
"target:cannon_fire"
|
||||||
]
|
]
|
||||||
}
|
}
|
|
@ -3,6 +3,9 @@
|
||||||
"values": [
|
"values": [
|
||||||
"target:gunfire",
|
"target:gunfire",
|
||||||
"target:gunfire_headshot",
|
"target:gunfire_headshot",
|
||||||
"target:shock"
|
"target:arrow_in_knee",
|
||||||
|
"target:arrow_in_brain",
|
||||||
|
"target:shock",
|
||||||
|
"target:cannon_fire"
|
||||||
]
|
]
|
||||||
}
|
}
|
|
@ -3,6 +3,9 @@
|
||||||
"values": [
|
"values": [
|
||||||
"target:gunfire",
|
"target:gunfire",
|
||||||
"target:gunfire_headshot",
|
"target:gunfire_headshot",
|
||||||
"target:shock"
|
"target:arrow_in_knee",
|
||||||
|
"target:arrow_in_brain",
|
||||||
|
"target:shock",
|
||||||
|
"target:cannon_fire"
|
||||||
]
|
]
|
||||||
}
|
}
|
|
@ -3,6 +3,9 @@
|
||||||
"values": [
|
"values": [
|
||||||
"target:gunfire",
|
"target:gunfire",
|
||||||
"target:gunfire_headshot",
|
"target:gunfire_headshot",
|
||||||
"target:shock"
|
"target:arrow_in_knee",
|
||||||
|
"target:arrow_in_brain",
|
||||||
|
"target:shock",
|
||||||
|
"target:cannon_fire"
|
||||||
]
|
]
|
||||||
}
|
}
|
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"exhaustion": 0,
|
||||||
|
"message_id": "cannon_fire",
|
||||||
|
"scaling": "never"
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue