/* * This file is part of TechReborn, licensed under the MIT License (MIT). * * Copyright (c) 2018 TechReborn * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ package techreborn.items.battery; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.entity.LivingEntity; import net.minecraft.item.Item; import net.minecraft.item.ItemPropertyGetter; import net.minecraft.item.ItemStack; import net.minecraft.util.Identifier; import net.minecraft.world.World; import reborncore.api.power.IEnergyItemInfo; import reborncore.common.powerSystem.ItemPowerManager; import reborncore.common.powerSystem.PowerSystem; import reborncore.common.util.ItemDurabilityExtensions; import reborncore.common.util.ItemUtils; import techreborn.TechReborn; import javax.annotation.Nullable; public class ItemBattery extends Item implements IEnergyItemInfo, ItemDurabilityExtensions { int maxEnergy = 0; int maxTransfer = 0; public ItemBattery(int maxEnergy, int maxTransfer) { super(new Item.Settings().group(TechReborn.ITEMGROUP).maxCount(1).maxDamageIfAbsent(1)); this.maxEnergy = maxEnergy; this.maxTransfer = maxTransfer; this.addPropertyGetter(new Identifier("techreborn:empty"), new ItemPropertyGetter() { @Override @Environment(EnvType.CLIENT) public float call(ItemStack stack, @Nullable World worldIn, @Nullable LivingEntity entityIn) { if (!stack.isEmpty() && new ItemPowerManager(stack).getEnergyStored() == 0) { return 1.0F; } return 0.0F; } }); } // Item @Override public double getDurabilityForDisplay(ItemStack stack) { return 1 - ItemUtils.getPowerForDurabilityBar(stack); } @Override public boolean showDurabilityBar(ItemStack stack) { return true; } @Override public int getRGBDurabilityForDisplay(ItemStack stack) { return PowerSystem.getDisplayPower().colour; } // IEnergyItemInfo @Override public int getCapacity() { return maxEnergy; } @Override public int getMaxInput() { return maxTransfer; } @Override public int getMaxOutput() { return maxTransfer; } }