允许创造模式充电站作为物品提供能量
This commit is contained in:
parent
6980e692d0
commit
cba1cf967c
2 changed files with 31 additions and 1 deletions
|
@ -254,7 +254,7 @@ public class ModItems {
|
|||
public static final RegistryObject<Item> REFORGING_TABLE = block(ModBlocks.REFORGING_TABLE);
|
||||
public static final RegistryObject<Item> CHARGING_STATION = block(ModBlocks.CHARGING_STATION);
|
||||
public static final RegistryObject<Item> CREATIVE_CHARGING_STATION = BLOCKS.register("creative_charging_station",
|
||||
() -> new BlockItem(ModBlocks.CREATIVE_CHARGING_STATION.get(), new Item.Properties().rarity(Rarity.EPIC)));
|
||||
() -> new CreativeChargingStationBlockItem(ModBlocks.CREATIVE_CHARGING_STATION.get(), new Item.Properties().rarity(Rarity.EPIC)));
|
||||
public static final RegistryObject<Item> LEAD_BLOCK = block(ModBlocks.LEAD_BLOCK);
|
||||
public static final RegistryObject<Item> STEEL_BLOCK = block(ModBlocks.STEEL_BLOCK);
|
||||
public static final RegistryObject<Item> TUNGSTEN_BLOCK = block(ModBlocks.TUNGSTEN_BLOCK);
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
package com.atsuishio.superbwarfare.item;
|
||||
|
||||
import com.atsuishio.superbwarfare.capability.energy.ItemEnergyProvider;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.item.BlockItem;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraftforge.common.capabilities.ForgeCapabilities;
|
||||
import net.minecraftforge.common.capabilities.ICapabilityProvider;
|
||||
|
||||
public class CreativeChargingStationBlockItem extends BlockItem {
|
||||
public CreativeChargingStationBlockItem(Block pBlock, Properties pProperties) {
|
||||
super(pBlock, pProperties);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICapabilityProvider initCapabilities(ItemStack stack, CompoundTag tag) {
|
||||
return new ItemEnergyProvider(stack, 2147483647);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void inventoryTick(ItemStack pStack, Level pLevel, Entity pEntity, int pSlotId, boolean pIsSelected) {
|
||||
pStack.getCapability(ForgeCapabilities.ENERGY).ifPresent(energy ->
|
||||
energy.receiveEnergy(2147483647 - energy.getEnergyStored(), false)
|
||||
);
|
||||
super.inventoryTick(pStack, pLevel, pEntity, pSlotId, pIsSelected);
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue