添加电池物品类
This commit is contained in:
parent
4e7fe67406
commit
bf721de4cc
7 changed files with 8 additions and 101 deletions
|
@ -171,8 +171,8 @@ public class ModItems {
|
||||||
public static final RegistryObject<Item> SCHEELITE = ITEMS.register("scheelite", () -> new Item(new Item.Properties()));
|
public static final RegistryObject<Item> SCHEELITE = ITEMS.register("scheelite", () -> new Item(new Item.Properties()));
|
||||||
public static final RegistryObject<Item> RAW_SILVER = ITEMS.register("raw_silver", () -> new Item(new Item.Properties()));
|
public static final RegistryObject<Item> RAW_SILVER = ITEMS.register("raw_silver", () -> new Item(new Item.Properties()));
|
||||||
public static final RegistryObject<Item> DOG_TAG = ITEMS.register("dog_tag", DogTag::new);
|
public static final RegistryObject<Item> DOG_TAG = ITEMS.register("dog_tag", DogTag::new);
|
||||||
public static final RegistryObject<Item> CELL = ITEMS.register("cell", Cell::new);
|
public static final RegistryObject<Item> CELL = ITEMS.register("cell", () -> new BatteryItem(24000, new Item.Properties()));
|
||||||
public static final RegistryObject<Item> BATTERY = ITEMS.register("battery", Battery::new);
|
public static final RegistryObject<Item> BATTERY = ITEMS.register("battery", () -> new BatteryItem(100000, new Item.Properties()));
|
||||||
public static final RegistryObject<Item> TRANSCRIPT = ITEMS.register("transcript", Transcript::new);
|
public static final RegistryObject<Item> TRANSCRIPT = ITEMS.register("transcript", Transcript::new);
|
||||||
public static final RegistryObject<Item> FIRING_PARAMETERS = ITEMS.register("firing_parameters", FiringParameters::new);
|
public static final RegistryObject<Item> FIRING_PARAMETERS = ITEMS.register("firing_parameters", FiringParameters::new);
|
||||||
|
|
||||||
|
|
|
@ -17,15 +17,16 @@ import java.util.Optional;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
public class Battery extends Item {
|
public class BatteryItem extends Item {
|
||||||
|
|
||||||
public static final int MAX_ENERGY = 100000;
|
|
||||||
|
|
||||||
private final Supplier<Integer> energyCapacity;
|
private final Supplier<Integer> energyCapacity;
|
||||||
|
|
||||||
public Battery() {
|
public static int MAX_ENERGY = 0;
|
||||||
|
|
||||||
|
public BatteryItem(int maxEnergy, Properties properties) {
|
||||||
super(new Properties().stacksTo(1));
|
super(new Properties().stacksTo(1));
|
||||||
this.energyCapacity = () -> MAX_ENERGY;
|
this.energyCapacity = () -> maxEnergy;
|
||||||
|
MAX_ENERGY = maxEnergy;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
|
@ -1,81 +0,0 @@
|
||||||
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;
|
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
|
||||||
import java.util.function.Supplier;
|
|
||||||
|
|
||||||
public class Cell extends Item {
|
|
||||||
|
|
||||||
public static final int MAX_ENERGY = 24000;
|
|
||||||
|
|
||||||
private final Supplier<Integer> energyCapacity;
|
|
||||||
|
|
||||||
public Cell() {
|
|
||||||
super(new Properties().stacksTo(1));
|
|
||||||
this.energyCapacity = () -> MAX_ENERGY;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isBarVisible(ItemStack pStack) {
|
|
||||||
if (!pStack.getCapability(ForgeCapabilities.ENERGY).isPresent()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
AtomicInteger energy = new AtomicInteger(0);
|
|
||||||
pStack.getCapability(ForgeCapabilities.ENERGY).ifPresent(
|
|
||||||
e -> energy.set(e.getEnergyStored())
|
|
||||||
);
|
|
||||||
return energy.get() != MAX_ENERGY;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getBarWidth(ItemStack pStack) {
|
|
||||||
AtomicInteger energy = new AtomicInteger(0);
|
|
||||||
pStack.getCapability(ForgeCapabilities.ENERGY).ifPresent(
|
|
||||||
e -> energy.set(e.getEnergyStored())
|
|
||||||
);
|
|
||||||
|
|
||||||
return Math.round((float) energy.get() * 13.0F / MAX_ENERGY);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ICapabilityProvider initCapabilities(ItemStack stack, CompoundTag tag) {
|
|
||||||
return new ItemEnergyProvider(stack, energyCapacity.get());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getBarColor(ItemStack pStack) {
|
|
||||||
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));
|
|
||||||
}
|
|
||||||
}
|
|
Binary file not shown.
After Width: | Height: | Size: 518 B |
Binary file not shown.
After Width: | Height: | Size: 480 B |
Binary file not shown.
After Width: | Height: | Size: 395 B |
|
@ -1,13 +0,0 @@
|
||||||
{
|
|
||||||
"type": "minecraft:crafting_shapeless",
|
|
||||||
"category":"misc",
|
|
||||||
"ingredients": [
|
|
||||||
{
|
|
||||||
"item":"superbwarfare:battery"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"result": {
|
|
||||||
"item": "superbwarfare:cell",
|
|
||||||
"count": 4
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Add table
Reference in a new issue