实现子弹模组的穿甲效果,添加银弹

This commit is contained in:
17146 2024-08-08 14:57:47 +08:00
parent f55d171b7f
commit c07cb1d545
7 changed files with 138 additions and 79 deletions

View file

@ -32,6 +32,7 @@ import net.minecraft.world.effect.MobEffects;
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.MobType;
import net.minecraft.world.entity.monster.Monster; import net.minecraft.world.entity.monster.Monster;
import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.ClipContext; import net.minecraft.world.level.ClipContext;
@ -82,6 +83,7 @@ public class ProjectileEntity extends Entity implements IEntityAdditionalSpawnDa
private boolean beast = false; private boolean beast = false;
private boolean zoom = false; private boolean zoom = false;
private float bypassArmorRate = 0.0f; private float bypassArmorRate = 0.0f;
private float undeadMultiple = 1.0f;
public ProjectileEntity(EntityType<? extends ProjectileEntity> p_i50159_1_, Level p_i50159_2_) { public ProjectileEntity(EntityType<? extends ProjectileEntity> p_i50159_1_, Level p_i50159_2_) {
super(p_i50159_1_, p_i50159_2_); super(p_i50159_1_, p_i50159_2_);
@ -95,46 +97,6 @@ public class ProjectileEntity extends Entity implements IEntityAdditionalSpawnDa
super(ModEntities.PROJECTILE.get(), world); super(ModEntities.PROJECTILE.get(), world);
} }
public ProjectileEntity shooter(LivingEntity shooter) {
this.shooter = shooter;
return this;
}
public ProjectileEntity damage(float damage) {
this.damage = damage;
return this;
}
public ProjectileEntity headShot(float headShot) {
this.headShot = headShot;
return this;
}
public ProjectileEntity monsterMultiple(int monsterMultiple) {
this.monsterMultiple = monsterMultiple;
return this;
}
public ProjectileEntity legShot(float legShot) {
this.legShot = legShot;
return this;
}
public ProjectileEntity beast() {
this.beast = true;
return this;
}
public ProjectileEntity zoom(boolean zoom) {
this.zoom = zoom;
return this;
}
public ProjectileEntity bypassArmorRate(float bypassArmorRate) {
this.bypassArmorRate = bypassArmorRate;
return this;
}
@Nullable @Nullable
protected EntityResult findEntityOnPath(Vec3 startVec, Vec3 endVec) { protected EntityResult findEntityOnPath(Vec3 startVec, Vec3 endVec) {
Vec3 hitVec = null; Vec3 hitVec = null;
@ -237,7 +199,7 @@ public class ProjectileEntity extends Entity implements IEntityAdditionalSpawnDa
|| entity instanceof Mle1934Entity || entity instanceof Mle1934Entity
|| entity instanceof Mk42Entity || entity instanceof Mk42Entity
|| entity instanceof DroneEntity || entity instanceof DroneEntity
)) { )) {
headshot = true; headshot = true;
} }
if (hitBoxPos.y < (0.33 * BodyHeight) && !(entity instanceof ClaymoreEntity if (hitBoxPos.y < (0.33 * BodyHeight) && !(entity instanceof ClaymoreEntity
@ -414,6 +376,14 @@ public class ProjectileEntity extends Entity implements IEntityAdditionalSpawnDa
return; return;
} }
if (entity instanceof Monster) {
this.damage *= mMultiple;
}
if (entity instanceof LivingEntity living && living.getMobType() == MobType.UNDEAD) {
this.damage *= this.undeadMultiple;
}
if (headshot) { if (headshot) {
if (!this.shooter.level().isClientSide() && this.shooter instanceof ServerPlayer player) { if (!this.shooter.level().isClientSide() && this.shooter instanceof ServerPlayer player) {
var holder = Holder.direct(ModSounds.HEADSHOT.get()); var holder = Holder.direct(ModSounds.HEADSHOT.get());
@ -421,33 +391,8 @@ public class ProjectileEntity extends Entity implements IEntityAdditionalSpawnDa
ModUtils.PACKET_HANDLER.send(PacketDistributor.PLAYER.with(() -> player), new ClientIndicatorMessage(1, 5)); ModUtils.PACKET_HANDLER.send(PacketDistributor.PLAYER.with(() -> player), new ClientIndicatorMessage(1, 5));
} }
if (entity instanceof Monster monster) {
performDamage(monster, this.damage * mMultiple, true);
} else {
performDamage(entity, this.damage, true);
}
} else if (legShot) {
if (!this.shooter.level().isClientSide() && this.shooter instanceof ServerPlayer player) {
var holder = Holder.direct(ModSounds.INDICATION.get());
player.connection.send(new ClientboundSoundPacket(holder, SoundSource.PLAYERS, player.getX(), player.getY(), player.getZ(), 1f, 1f, player.level().random.nextLong()));
ModUtils.PACKET_HANDLER.send(PacketDistributor.PLAYER.with(() -> player), new ClientIndicatorMessage(0, 5)); performDamage(entity, this.damage, true);
}
if (entity instanceof Monster monster) {
performDamage(monster, this.damage * mMultiple * this.legShot, false);
} else {
performDamage(entity, this.damage * this.legShot, false);
}
if (entity instanceof LivingEntity living) {
if (living instanceof Player player && player.isCreative()) {
return;
}
if (!living.level().isClientSide()) {
living.addEffect(new MobEffectInstance(MobEffects.MOVEMENT_SLOWDOWN, 20, 2, false, false));
}
}
} else { } else {
if (!this.shooter.level().isClientSide() && this.shooter instanceof ServerPlayer player) { if (!this.shooter.level().isClientSide() && this.shooter instanceof ServerPlayer player) {
var holder = Holder.direct(ModSounds.INDICATION.get()); var holder = Holder.direct(ModSounds.INDICATION.get());
@ -456,11 +401,19 @@ public class ProjectileEntity extends Entity implements IEntityAdditionalSpawnDa
ModUtils.PACKET_HANDLER.send(PacketDistributor.PLAYER.with(() -> player), new ClientIndicatorMessage(0, 5)); ModUtils.PACKET_HANDLER.send(PacketDistributor.PLAYER.with(() -> player), new ClientIndicatorMessage(0, 5));
} }
if (entity instanceof Monster monster) { if (legShot) {
performDamage(monster, this.damage * mMultiple, false); if (entity instanceof LivingEntity living) {
} else { if (living instanceof Player player && player.isCreative()) {
performDamage(entity, this.damage, false); return;
}
if (!living.level().isClientSide()) {
living.addEffect(new MobEffectInstance(MobEffects.MOVEMENT_SLOWDOWN, 20, 2, false, false));
}
}
this.damage *= this.legShot;
} }
performDamage(entity, this.damage, false);
} }
this.discard(); this.discard();
} }
@ -673,4 +626,52 @@ public class ProjectileEntity extends Entity implements IEntityAdditionalSpawnDa
public boolean isZoom() { public boolean isZoom() {
return this.zoom; return this.zoom;
} }
/**
* Builders
*/
public ProjectileEntity shooter(LivingEntity shooter) {
this.shooter = shooter;
return this;
}
public ProjectileEntity damage(float damage) {
this.damage = damage;
return this;
}
public ProjectileEntity headShot(float headShot) {
this.headShot = headShot;
return this;
}
public ProjectileEntity monsterMultiple(int monsterMultiple) {
this.monsterMultiple = monsterMultiple;
return this;
}
public ProjectileEntity legShot(float legShot) {
this.legShot = legShot;
return this;
}
public ProjectileEntity beast() {
this.beast = true;
return this;
}
public ProjectileEntity zoom(boolean zoom) {
this.zoom = zoom;
return this;
}
public ProjectileEntity bypassArmorRate(float bypassArmorRate) {
this.bypassArmorRate = bypassArmorRate;
return this;
}
public ProjectileEntity undeadMultiple(float undeadMultiple) {
this.undeadMultiple = undeadMultiple;
return this;
}
} }

View file

@ -3,11 +3,11 @@ package net.mcreator.superbwarfare.event;
import net.mcreator.superbwarfare.ModUtils; import net.mcreator.superbwarfare.ModUtils;
import net.mcreator.superbwarfare.entity.ProjectileEntity; import net.mcreator.superbwarfare.entity.ProjectileEntity;
import net.mcreator.superbwarfare.event.modevent.ReloadEvent; import net.mcreator.superbwarfare.event.modevent.ReloadEvent;
import net.mcreator.superbwarfare.init.ModEnchantments; import net.mcreator.superbwarfare.init.*;
import net.mcreator.superbwarfare.init.ModItems;
import net.mcreator.superbwarfare.init.ModSounds;
import net.mcreator.superbwarfare.init.ModTags;
import net.mcreator.superbwarfare.network.ModVariables; import net.mcreator.superbwarfare.network.ModVariables;
import net.mcreator.superbwarfare.perk.AmmoPerk;
import net.mcreator.superbwarfare.perk.Perk;
import net.mcreator.superbwarfare.perk.PerkHelper;
import net.mcreator.superbwarfare.tools.GunInfo; import net.mcreator.superbwarfare.tools.GunInfo;
import net.mcreator.superbwarfare.tools.GunsTool; import net.mcreator.superbwarfare.tools.GunsTool;
import net.mcreator.superbwarfare.tools.ParticleTool; import net.mcreator.superbwarfare.tools.ParticleTool;
@ -19,6 +19,7 @@ import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.level.ServerPlayer;
import net.minecraft.sounds.SoundEvent; import net.minecraft.sounds.SoundEvent;
import net.minecraft.sounds.SoundSource; import net.minecraft.sounds.SoundSource;
import net.minecraft.util.Mth;
import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionHand;
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;
@ -346,6 +347,12 @@ public class GunEventHandler {
float damage = (float) (heldItem.getOrCreateTag().getDouble("damage") + heldItem.getOrCreateTag().getDouble("sentinelChargeDamage")) * (float) heldItem.getOrCreateTag().getDouble("levelDamageMultiple"); float damage = (float) (heldItem.getOrCreateTag().getDouble("damage") + heldItem.getOrCreateTag().getDouble("sentinelChargeDamage")) * (float) heldItem.getOrCreateTag().getDouble("levelDamageMultiple");
float bypassArmorRate = (float) heldItem.getOrCreateTag().getDouble("BypassesArmor"); float bypassArmorRate = (float) heldItem.getOrCreateTag().getDouble("BypassesArmor");
var perk = PerkHelper.getPerkByType(heldItem, Perk.Type.AMMO);
if (perk instanceof AmmoPerk ammoPerk) {
bypassArmorRate += ammoPerk.bypassArmorRate;
}
bypassArmorRate = Mth.clamp(bypassArmorRate, 0, 1);
boolean zoom = player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new ModVariables.PlayerVariables()).zooming; boolean zoom = player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new ModVariables.PlayerVariables()).zooming;
double spread = heldItem.getOrCreateTag().getDouble("spread"); double spread = heldItem.getOrCreateTag().getDouble("spread");
double zoomSpread = heldItem.getOrCreateTag().getDouble("zoomSpread"); double zoomSpread = heldItem.getOrCreateTag().getDouble("zoomSpread");
@ -355,17 +362,21 @@ public class GunEventHandler {
.damage(damage) .damage(damage)
.headShot(headshot) .headShot(headshot)
.zoom(zoom) .zoom(zoom)
.bypassArmorRate(bypassArmorRate); .bypassArmorRate(bypassArmorRate)
.monsterMultiple(monsterMultiple);
if (heldItem.getOrCreateTag().getBoolean("beast")) { if (heldItem.getOrCreateTag().getBoolean("beast")) {
projectile.beast(); projectile.beast();
} }
projectile.monsterMultiple(monsterMultiple); if (perk == ModPerks.SILVER_BULLET.get()) {
int level = PerkHelper.getItemPerkLevel(perk, heldItem);
projectile.undeadMultiple(1.0f + 0.5f * level);
}
projectile.setPos(player.getX() - 0.1 * player.getLookAngle().x, player.getEyeY() - 0.1 - 0.1 * player.getLookAngle().y, player.getZ() + -0.1 * player.getLookAngle().z); projectile.setPos(player.getX() - 0.1 * player.getLookAngle().x, player.getEyeY() - 0.1 - 0.1 * player.getLookAngle().y, player.getZ() + -0.1 * player.getLookAngle().z);
projectile.shoot(player.getLookAngle().x, player.getLookAngle().y + 0.0005f, player.getLookAngle().z, 1 * (float) heldItem.getOrCreateTag().getDouble("velocity"), projectile.shoot(player.getLookAngle().x, player.getLookAngle().y + 0.0005f, player.getLookAngle().z, 1 * (float) heldItem.getOrCreateTag().getDouble("velocity"),
(float) (zoom? zoomSpread : spread)); (float) (zoom ? zoomSpread : spread));
player.level().addFreshEntity(projectile); player.level().addFreshEntity(projectile);
} }
} }

View file

@ -1,6 +1,7 @@
package net.mcreator.superbwarfare.init; package net.mcreator.superbwarfare.init;
import net.mcreator.superbwarfare.ModUtils; import net.mcreator.superbwarfare.ModUtils;
import net.mcreator.superbwarfare.perk.AmmoPerk;
import net.mcreator.superbwarfare.perk.Perk; import net.mcreator.superbwarfare.perk.Perk;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.eventbus.api.SubscribeEvent;
@ -20,10 +21,13 @@ public class ModPerks {
public static final DeferredRegister<Perk> PERKS = DeferredRegister.create(new ResourceLocation(ModUtils.MODID, "perk"), ModUtils.MODID); public static final DeferredRegister<Perk> PERKS = DeferredRegister.create(new ResourceLocation(ModUtils.MODID, "perk"), ModUtils.MODID);
public static final RegistryObject<AmmoPerk> SILVER_BULLET = PERKS.register("silver_bullet", () -> new AmmoPerk("silver_bullet", Perk.Type.AMMO, 0.1f));
public static final RegistryObject<Perk> FOURTH_TIMES_CHARM = PERKS.register("fourth_times_charm", () -> new Perk("fourth_times_charm", Perk.Type.FUNCTIONAL)); public static final RegistryObject<Perk> FOURTH_TIMES_CHARM = PERKS.register("fourth_times_charm", () -> new Perk("fourth_times_charm", Perk.Type.FUNCTIONAL));
public static final RegistryObject<Perk> GUTSHOT_STRAIGHT = PERKS.register("gutshot_straight", () -> new Perk("gutshot_straight", Perk.Type.DAMAGE));
public static final RegistryObject<Perk> HEAL_CLIP = PERKS.register("heal_clip", () -> new Perk("heal_clip", Perk.Type.FUNCTIONAL)); public static final RegistryObject<Perk> HEAL_CLIP = PERKS.register("heal_clip", () -> new Perk("heal_clip", Perk.Type.FUNCTIONAL));
public static final RegistryObject<Perk> KILL_CLIP = PERKS.register("kill_clip", () -> new Perk("kill_clip", Perk.Type.DAMAGE)); public static final RegistryObject<Perk> KILL_CLIP = PERKS.register("kill_clip", () -> new Perk("kill_clip", Perk.Type.DAMAGE));
public static final RegistryObject<Perk> GUTSHOT_STRAIGHT = PERKS.register("gutshot_straight", () -> new Perk("gutshot_straight", Perk.Type.DAMAGE));
public static final RegistryObject<Perk> KILLING_TALLY = PERKS.register("killing_tally", () -> new Perk("killing_tally", Perk.Type.DAMAGE)); public static final RegistryObject<Perk> KILLING_TALLY = PERKS.register("killing_tally", () -> new Perk("killing_tally", Perk.Type.DAMAGE));
public static final RegistryObject<Perk> MONSTER_HUNTER = PERKS.register("monster_hunter", () -> new Perk("monster_hunter", Perk.Type.DAMAGE)); public static final RegistryObject<Perk> MONSTER_HUNTER = PERKS.register("monster_hunter", () -> new Perk("monster_hunter", Perk.Type.DAMAGE));
} }

View file

@ -0,0 +1,16 @@
package net.mcreator.superbwarfare.perk;
import net.minecraft.util.Mth;
public class AmmoPerk extends Perk {
public float bypassArmorRate = 0.0f;
public AmmoPerk(String descriptionId, Type type) {
super(descriptionId, type);
}
public AmmoPerk(String descriptionId, Type type, float bypassArmorRate) {
super(descriptionId, type);
this.bypassArmorRate = Mth.clamp(bypassArmorRate, -1, 1);
}
}

View file

@ -83,4 +83,27 @@ public class PerkHelper {
setPerk(stack, perk, 1); setPerk(stack, perk, 1);
} }
@Nullable
public static Perk getPerkByType(ItemStack stack, Perk.Type type) {
var tag = stack.getTag();
if (tag == null) {
return null;
}
var tagPerk = tag.getCompound(TAG_PERK);
if (!tagPerk.contains(type.getName())) {
return null;
}
return ModPerks.PERKS.getEntries().stream()
.filter(p -> makeId(p.getId()).equals(tagPerk.getCompound(type.getName()).getString(TAG_PERK_ID)))
.findFirst()
.map(RegistryObject::get)
.orElse(null);
}
public static String makeId(ResourceLocation resourceLocation) {
return resourceLocation.getNamespace() + ":" + resourceLocation.getPath();
}
} }

View file

@ -184,6 +184,8 @@
"des.superbwarfare.gutshot_straight": "Aiming down sights increases body shot damage", "des.superbwarfare.gutshot_straight": "Aiming down sights increases body shot damage",
"item.superbwarfare.fourth_times_charm": "Fourth Time's The Charm", "item.superbwarfare.fourth_times_charm": "Fourth Time's The Charm",
"des.superbwarfare.fourth_times_charm": "Rapidly landing precision hits will return two rounds to the magazine", "des.superbwarfare.fourth_times_charm": "Rapidly landing precision hits will return two rounds to the magazine",
"item.superbwarfare.silver_bullet": "Silver Bullet",
"des.superbwarfare.silver_bullet": "Causes extra damage to undead entities",
"perk.superbwarfare.tips": "[Perks]", "perk.superbwarfare.tips": "[Perks]",
"perk.superbwarfare.slot": "Type: ", "perk.superbwarfare.slot": "Type: ",

View file

@ -184,6 +184,8 @@
"des.superbwarfare.gutshot_straight": "瞄准时增加身体射击伤害", "des.superbwarfare.gutshot_straight": "瞄准时增加身体射击伤害",
"item.superbwarfare.fourth_times_charm": "事不过四", "item.superbwarfare.fourth_times_charm": "事不过四",
"des.superbwarfare.fourth_times_charm": "快速精准命中目标会向弹匣中返还两枚弹药", "des.superbwarfare.fourth_times_charm": "快速精准命中目标会向弹匣中返还两枚弹药",
"item.superbwarfare.silver_bullet": "银弹",
"des.superbwarfare.silver_bullet": "对亡灵生物造成额外伤害",
"perk.superbwarfare.tips": "[武器模组]", "perk.superbwarfare.tips": "[武器模组]",
"perk.superbwarfare.slot": "类型: ", "perk.superbwarfare.slot": "类型: ",