继续重制部分功能perk
This commit is contained in:
parent
90e76d7c92
commit
995a043731
9 changed files with 92 additions and 47 deletions
|
@ -577,7 +577,6 @@ public class LivingEventHandler {
|
|||
DamageSource source = event.getSource();
|
||||
Entity sourceEntity = source.getEntity();
|
||||
if (!(sourceEntity instanceof Player player)) return;
|
||||
ItemStack mainHandItem = player.getMainHandItem();
|
||||
|
||||
// 创生物收集掉落物
|
||||
if (player.getVehicle() instanceof ContainerMobileVehicleEntity containerMobileVehicleEntity && source.is(ModDamageTypes.VEHICLE_STRIKE)) {
|
||||
|
@ -596,22 +595,6 @@ public class LivingEventHandler {
|
|||
});
|
||||
|
||||
drops.removeAll(removed);
|
||||
return;
|
||||
}
|
||||
|
||||
// 磁吸Perk
|
||||
if (mainHandItem.getItem() instanceof GunItem
|
||||
&& GunData.from(mainHandItem).perk.has(ModPerks.POWERFUL_ATTRACTION.get())
|
||||
&& (DamageTypeTool.isGunDamage(source) || DamageTypeTool.isExplosionDamage(source))
|
||||
) {
|
||||
var drops = event.getDrops();
|
||||
drops.forEach(itemEntity -> {
|
||||
ItemStack item = itemEntity.getItem();
|
||||
if (!player.addItem(item)) {
|
||||
player.drop(item, false);
|
||||
}
|
||||
});
|
||||
event.setCanceled(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -623,18 +606,6 @@ public class LivingEventHandler {
|
|||
if (player.getVehicle() instanceof ArmedVehicleEntity) {
|
||||
player.giveExperiencePoints(event.getDroppedExperience());
|
||||
event.setCanceled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (!(stack.getItem() instanceof GunItem)) return;
|
||||
var data = GunData.from(stack);
|
||||
|
||||
int level = data.perk.getLevel(ModPerks.POWERFUL_ATTRACTION);
|
||||
if (level > 0) {
|
||||
player.giveExperiencePoints((int) (event.getDroppedExperience() * (0.8f + 0.2f * level)));
|
||||
|
||||
event.setCanceled(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,10 +4,7 @@ import com.atsuishio.superbwarfare.Mod;
|
|||
import com.atsuishio.superbwarfare.perk.AmmoPerk;
|
||||
import com.atsuishio.superbwarfare.perk.Perk;
|
||||
import com.atsuishio.superbwarfare.perk.damage.*;
|
||||
import com.atsuishio.superbwarfare.perk.functional.FieldDoctor;
|
||||
import com.atsuishio.superbwarfare.perk.functional.FourthTimesCharm;
|
||||
import com.atsuishio.superbwarfare.perk.functional.HealClip;
|
||||
import com.atsuishio.superbwarfare.perk.functional.Subsistence;
|
||||
import com.atsuishio.superbwarfare.perk.functional.*;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.world.effect.MobEffects;
|
||||
import net.neoforged.bus.api.IEventBus;
|
||||
|
@ -61,9 +58,9 @@ public class ModPerks {
|
|||
public static final DeferredHolder<Perk, Perk> FOURTH_TIMES_CHARM = FUNC_PERKS.register("fourth_times_charm", FourthTimesCharm::new);
|
||||
public static final DeferredHolder<Perk, Perk> SUBSISTENCE = FUNC_PERKS.register("subsistence", Subsistence::new);
|
||||
public static final DeferredHolder<Perk, Perk> FIELD_DOCTOR = FUNC_PERKS.register("field_doctor", FieldDoctor::new);
|
||||
public static final DeferredHolder<Perk, Perk> REGENERATION = FUNC_PERKS.register("regeneration", () -> new Perk("regeneration", Perk.Type.FUNCTIONAL));
|
||||
public static final DeferredHolder<Perk, Perk> REGENERATION = FUNC_PERKS.register("regeneration", Regeneration::new);
|
||||
public static final DeferredHolder<Perk, Perk> TURBO_CHARGER = FUNC_PERKS.register("turbo_charger", () -> new Perk("turbo_charger", Perk.Type.FUNCTIONAL));
|
||||
public static final DeferredHolder<Perk, Perk> POWERFUL_ATTRACTION = FUNC_PERKS.register("powerful_attraction", () -> new Perk("powerful_attraction", Perk.Type.FUNCTIONAL));
|
||||
public static final DeferredHolder<Perk, Perk> POWERFUL_ATTRACTION = FUNC_PERKS.register("powerful_attraction", PowerfulAttraction::new);
|
||||
public static final DeferredHolder<Perk, Perk> INTELLIGENT_CHIP = FUNC_PERKS.register("intelligent_chip", () -> new Perk("intelligent_chip", Perk.Type.FUNCTIONAL));
|
||||
|
||||
/**
|
||||
|
|
|
@ -188,7 +188,7 @@ public class SecondaryCataclysm extends GunItem implements GeoItem, EnergyStorag
|
|||
|
||||
@Override
|
||||
public boolean canApplyPerk(Perk perk) {
|
||||
return PerkHelper.LAUNCHER_PERKS.test(perk) || perk == ModPerks.MICRO_MISSILE.get();
|
||||
return PerkHelper.LAUNCHER_PERKS.test(perk) || perk == ModPerks.MICRO_MISSILE.get() || perk == ModPerks.REGENERATION.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -5,6 +5,7 @@ import com.atsuishio.superbwarfare.client.renderer.item.SentinelItemRenderer;
|
|||
import com.atsuishio.superbwarfare.client.tooltip.component.SentinelImageComponent;
|
||||
import com.atsuishio.superbwarfare.event.ClientEventHandler;
|
||||
import com.atsuishio.superbwarfare.init.ModEnumExtensions;
|
||||
import com.atsuishio.superbwarfare.init.ModPerks;
|
||||
import com.atsuishio.superbwarfare.init.ModSounds;
|
||||
import com.atsuishio.superbwarfare.item.EnergyStorageItem;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunItem;
|
||||
|
@ -173,7 +174,7 @@ public class SentinelItem extends GunItem implements GeoItem, EnergyStorageItem
|
|||
|
||||
@Override
|
||||
public boolean canApplyPerk(Perk perk) {
|
||||
return PerkHelper.SNIPER_RIFLE_PERKS.test(perk) || PerkHelper.MAGAZINE_PERKS.test(perk);
|
||||
return PerkHelper.SNIPER_RIFLE_PERKS.test(perk) || PerkHelper.MAGAZINE_PERKS.test(perk) || perk == ModPerks.REGENERATION.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -116,18 +116,11 @@ public class TaserItem extends GunItem implements GeoItem, EnergyStorageItem {
|
|||
@ParametersAreNonnullByDefault
|
||||
public void inventoryTick(ItemStack stack, Level world, Entity entity, int slot, boolean selected) {
|
||||
super.inventoryTick(stack, world, entity, slot, selected);
|
||||
var data = GunData.from(stack);
|
||||
|
||||
int perkLevel = data.perk.getLevel(ModPerks.REGENERATION);
|
||||
|
||||
var stackStorage = stack.getCapability(Capabilities.EnergyStorage.ITEM);
|
||||
if (stackStorage != null) {
|
||||
stackStorage.receiveEnergy(perkLevel, false);
|
||||
}
|
||||
|
||||
if (entity instanceof Player player) {
|
||||
for (var cell : player.getInventory().items) {
|
||||
if (cell.is(ModItems.CELL.get())) {
|
||||
var stackStorage = stack.getCapability(Capabilities.EnergyStorage.ITEM);
|
||||
if (stackStorage == null) continue;
|
||||
int stackMaxEnergy = stackStorage.getMaxEnergyStored();
|
||||
int stackEnergy = stackStorage.getEnergyStored();
|
||||
|
|
|
@ -0,0 +1,58 @@
|
|||
package com.atsuishio.superbwarfare.perk.functional;
|
||||
|
||||
import com.atsuishio.superbwarfare.init.ModPerks;
|
||||
import com.atsuishio.superbwarfare.item.gun.GunItem;
|
||||
import com.atsuishio.superbwarfare.item.gun.data.GunData;
|
||||
import com.atsuishio.superbwarfare.perk.Perk;
|
||||
import com.atsuishio.superbwarfare.tools.DamageTypeTool;
|
||||
import net.minecraft.world.damagesource.DamageSource;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.neoforged.bus.api.SubscribeEvent;
|
||||
import net.neoforged.fml.common.EventBusSubscriber;
|
||||
import net.neoforged.neoforge.event.entity.living.LivingDropsEvent;
|
||||
import net.neoforged.neoforge.event.entity.living.LivingExperienceDropEvent;
|
||||
|
||||
@EventBusSubscriber(bus = EventBusSubscriber.Bus.GAME)
|
||||
public class PowerfulAttraction extends Perk {
|
||||
|
||||
public PowerfulAttraction() {
|
||||
super("powerful_attraction", Perk.Type.FUNCTIONAL);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onLivingDrops(LivingDropsEvent event) {
|
||||
DamageSource source = event.getSource();
|
||||
Entity sourceEntity = source.getEntity();
|
||||
if (!(sourceEntity instanceof Player player)) return;
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
|
||||
if (stack.getItem() instanceof GunItem && GunData.from(stack).perk.getLevel(ModPerks.POWERFUL_ATTRACTION) > 0
|
||||
&& (DamageTypeTool.isGunDamage(source) || DamageTypeTool.isExplosionDamage(source))) {
|
||||
var drops = event.getDrops();
|
||||
drops.forEach(itemEntity -> {
|
||||
ItemStack item = itemEntity.getItem();
|
||||
if (!player.addItem(item)) {
|
||||
player.drop(item, false);
|
||||
}
|
||||
});
|
||||
event.setCanceled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onLivingExperienceDrop(LivingExperienceDropEvent event) {
|
||||
Player player = event.getAttackingPlayer();
|
||||
if (player == null) return;
|
||||
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (!(stack.getItem() instanceof GunItem)) return;
|
||||
|
||||
int level = GunData.from(stack).perk.getLevel(ModPerks.POWERFUL_ATTRACTION);
|
||||
if (level > 0) {
|
||||
player.giveExperiencePoints((int) (event.getDroppedExperience() * (0.8f + 0.2f * level)));
|
||||
event.setCanceled(true);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package com.atsuishio.superbwarfare.perk.functional;
|
||||
|
||||
import com.atsuishio.superbwarfare.item.gun.data.GunData;
|
||||
import com.atsuishio.superbwarfare.perk.Perk;
|
||||
import com.atsuishio.superbwarfare.perk.PerkInstance;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.neoforged.neoforge.capabilities.Capabilities;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class Regeneration extends Perk {
|
||||
|
||||
public Regeneration() {
|
||||
super("regeneration", Perk.Type.FUNCTIONAL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick(GunData data, PerkInstance instance, @Nullable LivingEntity living) {
|
||||
ItemStack stack = data.stack;
|
||||
var cap = stack.getCapability(Capabilities.EnergyStorage.ITEM);
|
||||
if (cap != null) {
|
||||
cap.receiveEnergy((int) (instance.level() * cap.getMaxEnergyStored() / 2000d), false);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -331,7 +331,7 @@
|
|||
"item.superbwarfare.field_doctor": "Field Doctor",
|
||||
"des.superbwarfare.field_doctor": "Bullets will heal allies whilst firing from the hip.",
|
||||
"item.superbwarfare.regeneration": "Regeneration",
|
||||
"des.superbwarfare.regeneration": "Taser will restore energy automatically.",
|
||||
"des.superbwarfare.regeneration": "Energy weapons will restore energy automatically.",
|
||||
"item.superbwarfare.turbo_charger": "Turbocharger",
|
||||
"des.superbwarfare.turbo_charger": "Reduces wind-up time for compatible weapons",
|
||||
"item.superbwarfare.powerful_attraction": "Powerful Attraction",
|
||||
|
|
|
@ -330,7 +330,7 @@
|
|||
"item.superbwarfare.field_doctor": "役医师",
|
||||
"des.superbwarfare.field_doctor": "腰射时发射的子弹可以治疗队友",
|
||||
"item.superbwarfare.regeneration": "再生",
|
||||
"des.superbwarfare.regeneration": "泰瑟枪会缓慢自动回复能量",
|
||||
"des.superbwarfare.regeneration": "能量武器会缓慢自动回复能量",
|
||||
"item.superbwarfare.turbo_charger": "涡轮增压器",
|
||||
"des.superbwarfare.turbo_charger": "装配后减少武器自动射击所需的缓冲时间",
|
||||
"item.superbwarfare.powerful_attraction": "强力吸引",
|
||||
|
|
Loading…
Add table
Reference in a new issue