实现子弹模组的穿甲效果,添加银弹
This commit is contained in:
parent
f55d171b7f
commit
c07cb1d545
7 changed files with 138 additions and 79 deletions
|
@ -32,6 +32,7 @@ import net.minecraft.world.effect.MobEffects;
|
|||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.entity.MobType;
|
||||
import net.minecraft.world.entity.monster.Monster;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.level.ClipContext;
|
||||
|
@ -82,6 +83,7 @@ public class ProjectileEntity extends Entity implements IEntityAdditionalSpawnDa
|
|||
private boolean beast = false;
|
||||
private boolean zoom = false;
|
||||
private float bypassArmorRate = 0.0f;
|
||||
private float undeadMultiple = 1.0f;
|
||||
|
||||
public ProjectileEntity(EntityType<? extends ProjectileEntity> p_i50159_1_, Level 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);
|
||||
}
|
||||
|
||||
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
|
||||
protected EntityResult findEntityOnPath(Vec3 startVec, Vec3 endVec) {
|
||||
Vec3 hitVec = null;
|
||||
|
@ -414,6 +376,14 @@ public class ProjectileEntity extends Entity implements IEntityAdditionalSpawnDa
|
|||
return;
|
||||
}
|
||||
|
||||
if (entity instanceof Monster) {
|
||||
this.damage *= mMultiple;
|
||||
}
|
||||
|
||||
if (entity instanceof LivingEntity living && living.getMobType() == MobType.UNDEAD) {
|
||||
this.damage *= this.undeadMultiple;
|
||||
}
|
||||
|
||||
if (headshot) {
|
||||
if (!this.shooter.level().isClientSide() && this.shooter instanceof ServerPlayer player) {
|
||||
var holder = Holder.direct(ModSounds.HEADSHOT.get());
|
||||
|
@ -421,12 +391,9 @@ public class ProjectileEntity extends Entity implements IEntityAdditionalSpawnDa
|
|||
|
||||
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) {
|
||||
} else {
|
||||
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()));
|
||||
|
@ -434,12 +401,7 @@ public class ProjectileEntity extends Entity implements IEntityAdditionalSpawnDa
|
|||
ModUtils.PACKET_HANDLER.send(PacketDistributor.PLAYER.with(() -> player), new ClientIndicatorMessage(0, 5));
|
||||
}
|
||||
|
||||
if (entity instanceof Monster monster) {
|
||||
performDamage(monster, this.damage * mMultiple * this.legShot, false);
|
||||
} else {
|
||||
performDamage(entity, this.damage * this.legShot, false);
|
||||
}
|
||||
|
||||
if (legShot) {
|
||||
if (entity instanceof LivingEntity living) {
|
||||
if (living instanceof Player player && player.isCreative()) {
|
||||
return;
|
||||
|
@ -448,20 +410,11 @@ public class ProjectileEntity extends Entity implements IEntityAdditionalSpawnDa
|
|||
living.addEffect(new MobEffectInstance(MobEffects.MOVEMENT_SLOWDOWN, 20, 2, false, false));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
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));
|
||||
this.damage *= this.legShot;
|
||||
}
|
||||
|
||||
if (entity instanceof Monster monster) {
|
||||
performDamage(monster, this.damage * mMultiple, false);
|
||||
} else {
|
||||
performDamage(entity, this.damage, false);
|
||||
}
|
||||
}
|
||||
this.discard();
|
||||
}
|
||||
|
||||
|
@ -673,4 +626,52 @@ public class ProjectileEntity extends Entity implements IEntityAdditionalSpawnDa
|
|||
public boolean isZoom() {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,11 +3,11 @@ package net.mcreator.superbwarfare.event;
|
|||
import net.mcreator.superbwarfare.ModUtils;
|
||||
import net.mcreator.superbwarfare.entity.ProjectileEntity;
|
||||
import net.mcreator.superbwarfare.event.modevent.ReloadEvent;
|
||||
import net.mcreator.superbwarfare.init.ModEnchantments;
|
||||
import net.mcreator.superbwarfare.init.ModItems;
|
||||
import net.mcreator.superbwarfare.init.ModSounds;
|
||||
import net.mcreator.superbwarfare.init.ModTags;
|
||||
import net.mcreator.superbwarfare.init.*;
|
||||
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.GunsTool;
|
||||
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.sounds.SoundEvent;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
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 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;
|
||||
double spread = heldItem.getOrCreateTag().getDouble("spread");
|
||||
double zoomSpread = heldItem.getOrCreateTag().getDouble("zoomSpread");
|
||||
|
@ -355,13 +362,17 @@ public class GunEventHandler {
|
|||
.damage(damage)
|
||||
.headShot(headshot)
|
||||
.zoom(zoom)
|
||||
.bypassArmorRate(bypassArmorRate);
|
||||
.bypassArmorRate(bypassArmorRate)
|
||||
.monsterMultiple(monsterMultiple);
|
||||
|
||||
if (heldItem.getOrCreateTag().getBoolean("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.shoot(player.getLookAngle().x, player.getLookAngle().y + 0.0005f, player.getLookAngle().z, 1 * (float) heldItem.getOrCreateTag().getDouble("velocity"),
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package net.mcreator.superbwarfare.init;
|
||||
|
||||
import net.mcreator.superbwarfare.ModUtils;
|
||||
import net.mcreator.superbwarfare.perk.AmmoPerk;
|
||||
import net.mcreator.superbwarfare.perk.Perk;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
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 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> 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> 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> MONSTER_HUNTER = PERKS.register("monster_hunter", () -> new Perk("monster_hunter", Perk.Type.DAMAGE));
|
||||
}
|
||||
|
|
16
src/main/java/net/mcreator/superbwarfare/perk/AmmoPerk.java
Normal file
16
src/main/java/net/mcreator/superbwarfare/perk/AmmoPerk.java
Normal 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);
|
||||
}
|
||||
}
|
|
@ -83,4 +83,27 @@ public class PerkHelper {
|
|||
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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -184,6 +184,8 @@
|
|||
"des.superbwarfare.gutshot_straight": "Aiming down sights increases body shot damage",
|
||||
"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",
|
||||
"item.superbwarfare.silver_bullet": "Silver Bullet",
|
||||
"des.superbwarfare.silver_bullet": "Causes extra damage to undead entities",
|
||||
|
||||
"perk.superbwarfare.tips": "[Perks]",
|
||||
"perk.superbwarfare.slot": "Type: ",
|
||||
|
|
|
@ -184,6 +184,8 @@
|
|||
"des.superbwarfare.gutshot_straight": "瞄准时增加身体射击伤害",
|
||||
"item.superbwarfare.fourth_times_charm": "事不过四",
|
||||
"des.superbwarfare.fourth_times_charm": "快速精准命中目标会向弹匣中返还两枚弹药",
|
||||
"item.superbwarfare.silver_bullet": "银弹",
|
||||
"des.superbwarfare.silver_bullet": "对亡灵生物造成额外伤害",
|
||||
|
||||
"perk.superbwarfare.tips": "[武器模组]",
|
||||
"perk.superbwarfare.slot": "类型: ",
|
||||
|
|
Loading…
Add table
Reference in a new issue