Seriously clean up loads of unnecessary item classes and add more configs

This commit is contained in:
Prospector 2020-01-12 21:20:42 -08:00
parent c4dcc8d870
commit 04a1c789c4
30 changed files with 433 additions and 1111 deletions

View file

@ -0,0 +1,103 @@
/*
* This file is part of TechReborn, licensed under the MIT License (MIT).
*
* Copyright (c) 2020 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;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.entity.LivingEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemPropertyGetter;
import net.minecraft.item.ItemStack;
import net.minecraft.util.DefaultedList;
import net.minecraft.util.Identifier;
import net.minecraft.world.World;
import reborncore.common.powerSystem.PowerSystem;
import reborncore.common.util.ItemDurabilityExtensions;
import reborncore.common.util.ItemUtils;
import team.reborn.energy.Energy;
import team.reborn.energy.EnergyHolder;
import team.reborn.energy.EnergyTier;
import techreborn.TechReborn;
import techreborn.utils.InitUtils;
import javax.annotation.Nullable;
public class BatteryItem extends Item implements EnergyHolder, ItemDurabilityExtensions {
private final int maxEnergy;
private final EnergyTier tier;
public BatteryItem(int maxEnergy, EnergyTier tier) {
super(new Item.Settings().group(TechReborn.ITEMGROUP).maxCount(1).maxDamageIfAbsent(1));
this.maxEnergy = maxEnergy;
this.tier = tier;
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() && Energy.of(stack).getEnergy() == 0) {
return 1.0F;
}
return 0.0F;
}
});
}
// Item
@Override
public double getDurability(ItemStack stack) {
return 1 - ItemUtils.getPowerForDurabilityBar(stack);
}
@Override
public boolean showDurability(ItemStack stack) {
return true;
}
@Override
public int getDurabilityColor(ItemStack stack) {
return PowerSystem.getDisplayPower().colour;
}
@Override
public void appendStacks(ItemGroup group, DefaultedList<ItemStack> stacks) {
if (!isIn(group)) {
return;
}
InitUtils.initPoweredItems(this, stacks);
}
// EnergyHolder
@Override
public double getMaxStoredPower() {
return maxEnergy;
}
@Override
public EnergyTier getTier() {
return tier;
}
}