mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-26 08:48:34 +01:00
Fix the durability bar on charge-able items
This commit is contained in:
parent
350da9b2b0
commit
87f753a1cc
1 changed files with 15 additions and 5 deletions
|
@ -13,12 +13,16 @@ package de.ellpeck.actuallyadditions.mod.items.base;
|
||||||
import de.ellpeck.actuallyadditions.mod.attachments.ActuallyAttachments;
|
import de.ellpeck.actuallyadditions.mod.attachments.ActuallyAttachments;
|
||||||
import de.ellpeck.actuallyadditions.mod.items.ActuallyItems;
|
import de.ellpeck.actuallyadditions.mod.items.ActuallyItems;
|
||||||
import de.ellpeck.actuallyadditions.mod.tile.CustomEnergyStorage;
|
import de.ellpeck.actuallyadditions.mod.tile.CustomEnergyStorage;
|
||||||
|
import de.ellpeck.actuallyadditions.mod.util.AssetUtil;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
|
import net.minecraft.util.Mth;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.item.TooltipFlag;
|
import net.minecraft.world.item.TooltipFlag;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
import net.neoforged.api.distmarker.Dist;
|
import net.neoforged.api.distmarker.Dist;
|
||||||
import net.neoforged.api.distmarker.OnlyIn;
|
import net.neoforged.api.distmarker.OnlyIn;
|
||||||
|
import net.neoforged.fml.loading.FMLEnvironment;
|
||||||
import net.neoforged.neoforge.capabilities.Capabilities;
|
import net.neoforged.neoforge.capabilities.Capabilities;
|
||||||
import net.neoforged.neoforge.energy.IEnergyStorage;
|
import net.neoforged.neoforge.energy.IEnergyStorage;
|
||||||
|
|
||||||
|
@ -79,17 +83,23 @@ public abstract class ItemEnergy extends ItemBase {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getBarWidth(ItemStack stack) {
|
public int getBarWidth(ItemStack stack) {
|
||||||
if (stack.hasTag() && stack.getTag().contains("Energy")) {
|
if (stack.hasData(ActuallyAttachments.ENERGY_STORAGE)) {
|
||||||
return (int)(1 - (stack.getTag().getDouble("Energy") / this.maxPower));
|
CustomEnergyStorage storage = stack.getData(ActuallyAttachments.ENERGY_STORAGE);
|
||||||
|
return Math.round(13.0F - (float)storage.getEnergyStored() * 13.0F / storage.getMaxEnergyStored());
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getBarColor(ItemStack stack) {
|
public int getBarColor(ItemStack stack) {
|
||||||
//float[] color = AssetUtil.getWheelColor(player.level().getGameTime() % 256);
|
int defaultColor = super.getBarColor(stack);
|
||||||
//return MathHelper.color(color[0] / 255F, color[1] / 255F, color[2] / 255F);
|
if (FMLEnvironment.dist.isClient()) {
|
||||||
return super.getBarColor(stack);
|
Minecraft mc = Minecraft.getInstance();
|
||||||
|
if (mc.player == null) return defaultColor;
|
||||||
|
float[] color = AssetUtil.getWheelColor(mc.player.level().getGameTime() % 256);
|
||||||
|
return Mth.color(color[0] / 255F, color[1] / 255F, color[2] / 255F);
|
||||||
|
}
|
||||||
|
return defaultColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setEnergy(ItemStack stack, int energy) {
|
public void setEnergy(ItemStack stack, int energy) {
|
||||||
|
|
Loading…
Reference in a new issue