调整电池写法
This commit is contained in:
parent
dcf4f69d01
commit
4f2824958e
1 changed files with 5 additions and 22 deletions
|
@ -2,13 +2,10 @@ package com.atsuishio.superbwarfare.item;
|
|||
|
||||
import com.atsuishio.superbwarfare.capability.energy.ItemEnergyProvider;
|
||||
import com.atsuishio.superbwarfare.client.tooltip.component.CellImageComponent;
|
||||
import com.atsuishio.superbwarfare.init.ModItems;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.inventory.tooltip.TooltipComponent;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraftforge.common.capabilities.ForgeCapabilities;
|
||||
import net.minecraftforge.common.capabilities.ICapabilityProvider;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
@ -20,13 +17,12 @@ import java.util.function.Supplier;
|
|||
public class BatteryItem extends Item {
|
||||
|
||||
private final Supplier<Integer> energyCapacity;
|
||||
|
||||
public static int MAX_ENERGY = 0;
|
||||
public int maxEnergy;
|
||||
|
||||
public BatteryItem(int maxEnergy, Properties properties) {
|
||||
super(new Properties().stacksTo(1));
|
||||
super(properties.stacksTo(1));
|
||||
this.maxEnergy = maxEnergy;
|
||||
this.energyCapacity = () -> maxEnergy;
|
||||
MAX_ENERGY = maxEnergy;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -39,7 +35,7 @@ public class BatteryItem extends Item {
|
|||
pStack.getCapability(ForgeCapabilities.ENERGY).ifPresent(
|
||||
e -> energy.set(e.getEnergyStored())
|
||||
);
|
||||
return energy.get() != MAX_ENERGY;
|
||||
return energy.get() != maxEnergy;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -49,7 +45,7 @@ public class BatteryItem extends Item {
|
|||
e -> energy.set(e.getEnergyStored())
|
||||
);
|
||||
|
||||
return Math.round((float) energy.get() * 13.0F / MAX_ENERGY);
|
||||
return Math.round((float) energy.get() * 13.0F / maxEnergy);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -62,19 +58,6 @@ public class BatteryItem extends Item {
|
|||
return 0xFFFF00;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void inventoryTick(ItemStack stack, Level world, Entity entity, int slot, boolean selected) {
|
||||
super.inventoryTick(stack, world, entity, slot, selected);
|
||||
}
|
||||
|
||||
public static ItemStack getGunInstance() {
|
||||
ItemStack stack = new ItemStack(ModItems.TASER.get());
|
||||
stack.getCapability(ForgeCapabilities.ENERGY).ifPresent(
|
||||
energy -> energy.receiveEnergy(MAX_ENERGY, false)
|
||||
);
|
||||
return stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Optional<TooltipComponent> getTooltipImage(@NotNull ItemStack pStack) {
|
||||
return Optional.of(new CellImageComponent(pStack));
|
||||
|
|
Loading…
Add table
Reference in a new issue