ActuallyAdditions/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/AABlockItem.java

54 lines
1.9 KiB
Java
Raw Normal View History

package de.ellpeck.actuallyadditions.mod.blocks;
2024-03-02 21:23:08 +01:00
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.ItemNameBlockItem;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
2022-10-15 01:58:04 +02:00
import javax.annotation.Nullable;
import java.text.NumberFormat;
import java.util.List;
public class AABlockItem extends BlockItem {
public AABlockItem(Block blockIn, Properties builder) {
super(blockIn, builder);
}
2022-01-08 19:54:43 +01:00
2024-03-02 21:23:08 +01:00
public static class AASeedItem extends ItemNameBlockItem {
2022-01-08 19:54:43 +01:00
public AASeedItem(Block block, Properties properties) {
super(block, properties);
}
@Override
public String getDescriptionId() {
return this.getOrCreateDescriptionId();
}
}
2022-10-15 01:58:04 +02:00
public static class BlockEntityEnergyItem extends AABlockItem {
public BlockEntityEnergyItem(Block blockIn, Properties builder) {
super(blockIn, builder);
}
@Override
2024-03-02 21:23:08 +01:00
public void appendHoverText(ItemStack pStack, @Nullable Level pLevel, List<Component> pTooltip, TooltipFlag pFlag) {
2022-10-15 01:58:04 +02:00
super.appendHoverText(pStack, pLevel, pTooltip, pFlag);
if (pStack.hasTag() && pStack.getTag().contains("BlockEntityTag")) {
2024-03-02 21:23:08 +01:00
CompoundTag BET = pStack.getTag().getCompound("BlockEntityTag");
2022-10-15 01:58:04 +02:00
int energy = 0;
if (BET.contains("Energy")) {
energy = BET.getInt("Energy");
}
NumberFormat format = NumberFormat.getInstance();
2024-03-02 21:23:08 +01:00
pTooltip.add(new TranslatableComponent("misc.actuallyadditions.power_single", format.format(energy)));
2022-10-15 01:58:04 +02:00
}
}
}
}