Superclass for energy armor

This commit is contained in:
drcrazy 2023-05-15 21:01:37 +03:00 committed by modmuss
parent c341d207f8
commit b1c10d50c1
5 changed files with 103 additions and 162 deletions

View file

@ -269,7 +269,7 @@ public class TechRebornConfig {
public static int lapotronicOrbMaxCharge = 100_000_000;
@Config(config = "items", category = "power", key = "cloakingDeviceCharge", comment = "Energy Capacity for Cloaking Device")
public static int cloakingDeviceCharge = 40_000_000;
public static long cloakingDeviceCharge = 40_000_000;
@Config(config = "items", category = "power", key = "clockingDeviceEnergyUsage", comment = "Cloaking device energy usage")
public static int cloakingDeviceCost = 10;

View file

@ -26,7 +26,6 @@ package techreborn.items.armor;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ArmorItem;
import net.minecraft.item.ArmorMaterial;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
@ -34,15 +33,10 @@ import reborncore.common.powerSystem.RcEnergyItem;
import reborncore.common.powerSystem.RcEnergyTier;
import reborncore.common.util.ItemUtils;
public class BatpackItem extends ArmorItem implements RcEnergyItem {
public class BatpackItem extends TREnergyArmourItem implements RcEnergyItem {
public final int maxCharge;
public final RcEnergyTier tier;
public BatpackItem(int maxCharge, ArmorMaterial material, RcEnergyTier tier) {
super(material, Type.CHESTPLATE, new Settings().maxCount(1).maxDamage(-1));
this.maxCharge = maxCharge;
this.tier = tier;
public BatpackItem(long maxCharge, ArmorMaterial material, RcEnergyTier tier) {
super(material, Type.CHESTPLATE, maxCharge, tier);
}
// Item
@ -52,43 +46,7 @@ public class BatpackItem extends ArmorItem implements RcEnergyItem {
return;
}
if (entityIn instanceof PlayerEntity) {
ItemUtils.distributePowerToInventory((PlayerEntity) entityIn, stack, tier.getMaxOutput());
ItemUtils.distributePowerToInventory((PlayerEntity) entityIn, stack, this.getTier().getMaxOutput());
}
}
@Override
public boolean isDamageable() {
return false;
}
@Override
public boolean isEnchantable(ItemStack stack) {
return true;
}
// EnergyHolder
@Override
public long getEnergyCapacity() {
return maxCharge;
}
@Override
public RcEnergyTier getTier() {
return tier;
}
@Override
public int getItemBarColor(ItemStack stack) {
return ItemUtils.getColorForDurabilityBar(stack);
}
@Override
public boolean isItemBarVisible(ItemStack stack) {
return true;
}
@Override
public int getItemBarStep(ItemStack stack) {
return ItemUtils.getPowerForDurabilityBar(stack);
}
}

View file

@ -25,70 +25,28 @@
package techreborn.items.armor;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import reborncore.api.items.ArmorBlockEntityTicker;
import reborncore.api.items.ArmorRemoveHandler;
import reborncore.common.powerSystem.RcEnergyItem;
import reborncore.common.powerSystem.RcEnergyTier;
import reborncore.common.util.ItemUtils;
import techreborn.config.TechRebornConfig;
import techreborn.init.TRArmorMaterials;
public class CloakingDeviceItem extends TRArmourItem implements RcEnergyItem, ArmorBlockEntityTicker, ArmorRemoveHandler {
public class CloakingDeviceItem extends TREnergyArmourItem implements ArmorBlockEntityTicker, ArmorRemoveHandler {
public static int maxCharge = TechRebornConfig.cloakingDeviceCharge;
public static int cost = TechRebornConfig.cloakingDeviceCost;
public static boolean isActive;
public static int cost = TechRebornConfig.cloakingDeviceCost;
// 40M FE capacity with 10k FE\t charge rate
// 40M FE capacity with 8k FE\t charge rate
public CloakingDeviceItem() {
super(TRArmorMaterials.CLOAKING_DEVICE, Type.CHESTPLATE, new Item.Settings().maxDamage(-1).maxCount(1));
super(TRArmorMaterials.CLOAKING_DEVICE, Type.CHESTPLATE, TechRebornConfig.cloakingDeviceCharge, RcEnergyTier.INSANE);
}
// TREnergyArmourItem
@Override
public boolean canRepair(ItemStack stack, ItemStack ingredient) {
return false;
}
public long getEnergyMaxOutput() { return 0; }
// ItemTRArmour
@Override
public int getItemBarStep(ItemStack stack) {
return ItemUtils.getPowerForDurabilityBar(stack);
}
@Override
public boolean isItemBarVisible(ItemStack stack) {
return true;
}
@Override
public boolean isEnchantable(ItemStack stack) {
return true;
}
@Override
public int getItemBarColor(ItemStack stack) {
return ItemUtils.getColorForDurabilityBar(stack);
}
// EnergyHolder
@Override
public long getEnergyCapacity() {
return maxCharge;
}
@Override
public RcEnergyTier getTier() {
return RcEnergyTier.INSANE;
}
@Override
public long getEnergyMaxOutput() {
return 0;
}
// ArmorTickable
// ArmorBlockEntityTicker
@Override
public void tickArmor(ItemStack stack, PlayerEntity playerEntity) {
if (tryUseEnergy(stack, cost)) {

View file

@ -36,16 +36,13 @@ import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.entity.effect.StatusEffects;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ArmorMaterial;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import reborncore.api.items.ArmorBlockEntityTicker;
import reborncore.api.items.ArmorRemoveHandler;
import reborncore.common.powerSystem.RcEnergyItem;
import reborncore.common.powerSystem.RcEnergyTier;
import reborncore.common.util.ItemUtils;
import techreborn.config.TechRebornConfig;
public class QuantumSuitItem extends TRArmourItem implements ArmorBlockEntityTicker, ArmorRemoveHandler, RcEnergyItem {
public class QuantumSuitItem extends TREnergyArmourItem implements ArmorBlockEntityTicker, ArmorRemoveHandler {
public final long flyCost = TechRebornConfig.quantumSuitFlyingCost;
public final long swimCost = TechRebornConfig.quantumSuitSwimmingCost;
@ -56,11 +53,21 @@ public class QuantumSuitItem extends TRArmourItem implements ArmorBlockEntityTic
public final boolean enableSprint = TechRebornConfig.quantumSuitEnableSprint;
public final boolean enableFlight = TechRebornConfig.quantumSuitEnableFlight;
public QuantumSuitItem(ArmorMaterial material, Type slot) {
super(material, slot, new Item.Settings().maxDamage(-1).maxCount(1));
super(material, slot, TechRebornConfig.quantumSuitCapacity, RcEnergyTier.INSANE);
}
// TREnergyArmourItem
@Override
public long getEnergyMaxOutput() { return 0; }
// ArmorItem
@Override
public Multimap<EntityAttribute, EntityAttributeModifier> getAttributeModifiers(EquipmentSlot slot) {
return HashMultimap.create();
}
// FabricItem
@Override
public Multimap<EntityAttribute, EntityAttributeModifier> getAttributeModifiers(ItemStack stack, EquipmentSlot equipmentSlot) {
var attributes = ArrayListMultimap.create(super.getAttributeModifiers(stack, getSlotType()));
@ -81,18 +88,17 @@ public class QuantumSuitItem extends TRArmourItem implements ArmorBlockEntityTic
return ImmutableMultimap.copyOf(attributes);
}
// ArmorBlockEntityTicker
@Override
public void tickArmor(ItemStack stack, PlayerEntity playerEntity) {
switch (this.getSlotType()) {
case HEAD:
if (playerEntity.isSubmergedInWater()) {
if (tryUseEnergy(stack, breathingCost)) {
playerEntity.addStatusEffect(new StatusEffectInstance(StatusEffects.WATER_BREATHING, 5, 1));
}
case HEAD -> {
if (playerEntity.isSubmergedInWater() && tryUseEnergy(stack, breathingCost)) {
playerEntity.addStatusEffect(new StatusEffectInstance(StatusEffects.WATER_BREATHING, 5, 1));
}
break;
case CHEST:
if (enableFlight){
}
case CHEST -> {
if (enableFlight) {
if (getStoredEnergy(stack) > flyCost) {
playerEntity.getAbilities().allowFlying = true;
if (playerEntity.getAbilities().flying) {
@ -104,32 +110,24 @@ public class QuantumSuitItem extends TRArmourItem implements ArmorBlockEntityTic
playerEntity.getAbilities().flying = false;
}
}
if (playerEntity.isOnFire() && getStoredEnergy(stack) > fireExtinguishCost) {
if (playerEntity.isOnFire() && tryUseEnergy(stack, fireExtinguishCost)) {
playerEntity.extinguish();
}
break;
case LEGS:
}
case LEGS -> {
if (playerEntity.isSprinting() && enableSprint) {
tryUseEnergy(stack, sprintingCost);
}
break;
case FEET:
if (playerEntity.isSwimming()) {
if (tryUseEnergy(stack, swimCost)) {
playerEntity.addStatusEffect(new StatusEffectInstance(StatusEffects.DOLPHINS_GRACE, 5, 1));
}
}
case FEET -> {
if (playerEntity.isSwimming() && tryUseEnergy(stack, swimCost)) {
playerEntity.addStatusEffect(new StatusEffectInstance(StatusEffects.DOLPHINS_GRACE, 5, 1));
}
break;
default:
}
}
}
@Override
public Multimap<EntityAttribute, EntityAttributeModifier> getAttributeModifiers(EquipmentSlot slot) {
return HashMultimap.create();
}
// ArmorRemoveHandler
@Override
public void onRemoved(PlayerEntity playerEntity) {
if (this.getSlotType() == EquipmentSlot.CHEST && enableFlight) {
@ -139,39 +137,4 @@ public class QuantumSuitItem extends TRArmourItem implements ArmorBlockEntityTic
}
}
}
@Override
public int getItemBarStep(ItemStack stack) {
return ItemUtils.getPowerForDurabilityBar(stack);
}
@Override
public boolean isItemBarVisible(ItemStack stack) {
return true;
}
@Override
public boolean isEnchantable(ItemStack stack) {
return true;
}
@Override
public int getItemBarColor(ItemStack stack) {
return ItemUtils.getColorForDurabilityBar(stack);
}
@Override
public boolean canRepair(ItemStack itemStack_1, ItemStack itemStack_2) {
return false;
}
@Override
public long getEnergyCapacity() {
return TechRebornConfig.quantumSuitCapacity;
}
@Override
public RcEnergyTier getTier() {
return RcEnergyTier.EXTREME;
}
}

View file

@ -0,0 +1,62 @@
package techreborn.items.armor;
import net.minecraft.item.ArmorMaterial;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import reborncore.common.powerSystem.RcEnergyItem;
import reborncore.common.powerSystem.RcEnergyTier;
import reborncore.common.util.ItemUtils;
public abstract class TREnergyArmourItem extends TRArmourItem implements RcEnergyItem {
public final long maxCharge;
private final RcEnergyTier energyTier;
public TREnergyArmourItem(ArmorMaterial material, Type slot, long maxCharge, RcEnergyTier energyTier) {
super(material, slot, new Item.Settings().maxDamage(-1).maxCount(1));
this.maxCharge = maxCharge;
this.energyTier = energyTier;
}
// ArmorItem
@Override
public boolean canRepair(ItemStack stack, ItemStack ingredient) {
return false;
}
// Item
@Override
public boolean isDamageable() {
return false;
}
@Override
public int getItemBarStep(ItemStack stack) {
return ItemUtils.getPowerForDurabilityBar(stack);
}
@Override
public boolean isItemBarVisible(ItemStack stack) {
return true;
}
@Override
public boolean isEnchantable(ItemStack stack) {
return true;
}
@Override
public int getItemBarColor(ItemStack stack) {
return ItemUtils.getColorForDurabilityBar(stack);
}
// RcEnergyItem
@Override
public long getEnergyCapacity() {
return maxCharge;
}
@Override
public RcEnergyTier getTier() {
return energyTier;
}
}