添加电池满能量物品方法

This commit is contained in:
17146 2025-03-11 19:28:23 +08:00
parent 2b1d464a97
commit ce371f2e30
2 changed files with 12 additions and 0 deletions

View file

@ -2,6 +2,7 @@ package com.atsuishio.superbwarfare.init;
import com.atsuishio.superbwarfare.ModUtils; import com.atsuishio.superbwarfare.ModUtils;
import com.atsuishio.superbwarfare.item.ArmorPlate; import com.atsuishio.superbwarfare.item.ArmorPlate;
import com.atsuishio.superbwarfare.item.BatteryItem;
import com.atsuishio.superbwarfare.item.gun.handgun.*; import com.atsuishio.superbwarfare.item.gun.handgun.*;
import com.atsuishio.superbwarfare.item.gun.heavy.Ntw20Item; import com.atsuishio.superbwarfare.item.gun.heavy.Ntw20Item;
import com.atsuishio.superbwarfare.item.gun.launcher.JavelinItem; import com.atsuishio.superbwarfare.item.gun.launcher.JavelinItem;
@ -127,6 +128,9 @@ public class ModTabs {
if (registryObject.get() == ModItems.ARMOR_PLATE.get()) { if (registryObject.get() == ModItems.ARMOR_PLATE.get()) {
output.accept(ArmorPlate.getInfiniteInstance()); output.accept(ArmorPlate.getInfiniteInstance());
} }
if (registryObject.get() instanceof BatteryItem batteryItem) {
output.accept(batteryItem.makeFullEnergyStack());
}
} }
})) }))
.build()); .build());

View file

@ -62,4 +62,12 @@ public class BatteryItem extends Item {
public @NotNull Optional<TooltipComponent> getTooltipImage(@NotNull ItemStack pStack) { public @NotNull Optional<TooltipComponent> getTooltipImage(@NotNull ItemStack pStack) {
return Optional.of(new CellImageComponent(pStack)); return Optional.of(new CellImageComponent(pStack));
} }
public ItemStack makeFullEnergyStack() {
ItemStack stack = new ItemStack(this);
stack.getCapability(ForgeCapabilities.ENERGY).ifPresent(
e -> e.receiveEnergy(maxEnergy, false)
);
return stack;
}
} }