/* * This file is part of TechReborn, licensed under the MIT License (MIT). * * Copyright (c) 2017 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.minecraft.entity.EntityLivingBase; import net.minecraft.item.IItemPropertyGetter; import net.minecraft.item.ItemStack; import net.minecraft.util.ResourceLocation; import net.minecraft.world.World; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; import reborncore.api.power.IEnergyItemInfo; import reborncore.common.powerSystem.PoweredItem; import techreborn.items.ItemTRNoDestroy; import javax.annotation.Nullable; public class ItemBattery extends ItemTRNoDestroy implements IEnergyItemInfo { String name; int maxEnergy = 0; int maxTransfer = 0; int tier = 0; public ItemBattery(String name, int maxEnergy, int maxTransfer, int tier) { super(); setMaxStackSize(1); setMaxDamage(1); setUnlocalizedName("techreborn." + name); this.name = name; this.maxEnergy = maxEnergy; this.maxTransfer = maxTransfer; this.tier = tier; this.addPropertyOverride(new ResourceLocation("techreborn:empty"), new IItemPropertyGetter() { @SideOnly(Side.CLIENT) public float apply(ItemStack stack, @Nullable World worldIn, @Nullable EntityLivingBase entityIn) { if (stack != ItemStack.EMPTY && PoweredItem.getEnergy(stack) == 0.0) { return 1.0F; } return 0.0F; } }); } @Override public double getMaxPower(ItemStack stack) { return maxEnergy; } @Override public boolean canAcceptEnergy(ItemStack stack) { return true; } @Override public boolean canProvideEnergy(ItemStack stack) { return true; } @Override public double getMaxTransfer(ItemStack stack) { return maxTransfer; } @Override public int getStackTier(ItemStack stack) { return tier; } }