Slight cleanup. Energy packs uses transfer rates from tier.

This commit is contained in:
drcrazy 2020-01-13 13:53:36 +03:00
parent 04a1c789c4
commit b9c8a1a215
7 changed files with 52 additions and 78 deletions

View file

@ -247,17 +247,11 @@ public class TechRebornConfig {
@Config(config = "items", category = "power", key = "rockCutterCost", comment = "Energy Cost for Rock Cutter (FE)") @Config(config = "items", category = "power", key = "rockCutterCost", comment = "Energy Cost for Rock Cutter (FE)")
public static int rockCutterCost = 500; public static int rockCutterCost = 500;
@Config(config = "items", category = "power", key = "lapotronPackCharge", comment = "Energy Capacity for Lapotron Pack (FE)") @Config(config = "items", category = "power", key = "lapotronPackCharge", comment = "Energy Capacity for Lapotron Pack")
public static int lapotronPackCharge = 400_000_000; public static int lapotronPackCharge = 100_000_000;
@Config(config = "items", category = "power", key = "lapotronPackTransferRate", comment = "Transfer Rate for Lapotron Pack (FE)") @Config(config = "items", category = "power", key = "LithiumBatpackCharge", comment = "Energy Capacity for Lithium Batpack")
public static int lapotronPackTransferRate = 100_000; public static int lithiumBatpackCharge = 600_000;
@Config(config = "items", category = "power", key = "LithiumBatpackCharge", comment = "Energy Capacity for Lithium Batpack (FE)")
public static int lithiumBatpackCharge = 8_000_000;
@Config(config = "items", category = "power", key = "lithiumBatpackTransferRate", comment = "Transfer Rate for Lithium Batpack (FE)")
public static int lithiumBatpackTransferRate = 2_000;
@Config(config = "items", category = "power", key = "redCellBatteryMaxCharge", comment = "Energy Capacity for Red Cell Battery (FE)") @Config(config = "items", category = "power", key = "redCellBatteryMaxCharge", comment = "Energy Capacity for Red Cell Battery (FE)")
public static int redCellBatteryMaxCharge = 40_000; public static int redCellBatteryMaxCharge = 40_000;

View file

@ -167,11 +167,11 @@ public class ModRegistry {
// Battery // Battery
RebornRegistry.registerItem(TRContent.RED_CELL_BATTERY = InitUtils.setup(new BatteryItem(TechRebornConfig.redCellBatteryMaxCharge, EnergyTier.LOW), "red_cell_battery")); RebornRegistry.registerItem(TRContent.RED_CELL_BATTERY = InitUtils.setup(new BatteryItem(TechRebornConfig.redCellBatteryMaxCharge, EnergyTier.LOW), "red_cell_battery"));
RebornRegistry.registerItem(TRContent.LITHIUM_ION_BATTERY = InitUtils.setup(new BatteryItem(TechRebornConfig.lithiumIonBatteryMaxCharge, EnergyTier.HIGH), "lithium_ion_battery")); RebornRegistry.registerItem(TRContent.LITHIUM_ION_BATTERY = InitUtils.setup(new BatteryItem(TechRebornConfig.lithiumIonBatteryMaxCharge, EnergyTier.HIGH), "lithium_ion_battery"));
RebornRegistry.registerItem(TRContent.LITHIUM_ION_BATPACK = InitUtils.setup(new BatpackItem(TechRebornConfig.lithiumBatpackCharge, TechRebornConfig.lithiumBatpackTransferRate, TRArmorMaterials.LITHIUM_BATPACK, EnergyTier.HIGH), "lithium_ion_batpack")); RebornRegistry.registerItem(TRContent.LITHIUM_ION_BATPACK = InitUtils.setup(new BatpackItem(TechRebornConfig.lithiumBatpackCharge, TRArmorMaterials.LITHIUM_BATPACK, EnergyTier.MEDIUM), "lithium_ion_batpack"));
RebornRegistry.registerItem(TRContent.ENERGY_CRYSTAL = InitUtils.setup(new BatteryItem(TechRebornConfig.energyCrystalMaxCharge, EnergyTier.HIGH), "energy_crystal")); RebornRegistry.registerItem(TRContent.ENERGY_CRYSTAL = InitUtils.setup(new BatteryItem(TechRebornConfig.energyCrystalMaxCharge, EnergyTier.HIGH), "energy_crystal"));
RebornRegistry.registerItem(TRContent.LAPOTRON_CRYSTAL = InitUtils.setup(new BatteryItem(TechRebornConfig.lapotronCrystalMaxCharge, EnergyTier.EXTREME), "lapotron_crystal")); RebornRegistry.registerItem(TRContent.LAPOTRON_CRYSTAL = InitUtils.setup(new BatteryItem(TechRebornConfig.lapotronCrystalMaxCharge, EnergyTier.EXTREME), "lapotron_crystal"));
RebornRegistry.registerItem(TRContent.LAPOTRONIC_ORB = InitUtils.setup(new BatteryItem(TechRebornConfig.lapotronicOrbMaxCharge, EnergyTier.EXTREME), "lapotronic_orb")); RebornRegistry.registerItem(TRContent.LAPOTRONIC_ORB = InitUtils.setup(new BatteryItem(TechRebornConfig.lapotronicOrbMaxCharge, EnergyTier.EXTREME), "lapotronic_orb"));
RebornRegistry.registerItem(TRContent.LAPOTRONIC_ORBPACK = InitUtils.setup(new BatpackItem(TechRebornConfig.lapotronPackCharge, TechRebornConfig.lapotronPackTransferRate, TRArmorMaterials.LAPOTRONIC_ORBPACK, EnergyTier.EXTREME), "lapotronic_orbpack")); RebornRegistry.registerItem(TRContent.LAPOTRONIC_ORBPACK = InitUtils.setup(new BatpackItem(TechRebornConfig.lapotronPackCharge, TRArmorMaterials.LAPOTRONIC_ORBPACK, EnergyTier.INSANE), "lapotronic_orbpack"));
// Tools // Tools
RebornRegistry.registerItem(TRContent.TREE_TAP = InitUtils.setup(new TreeTapItem(), "treetap")); RebornRegistry.registerItem(TRContent.TREE_TAP = InitUtils.setup(new TreeTapItem(), "treetap"));

View file

@ -24,16 +24,11 @@
package techreborn.items; 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.Item;
import net.minecraft.item.ItemGroup; import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemPropertyGetter;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.DefaultedList; import net.minecraft.util.DefaultedList;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import net.minecraft.world.World;
import reborncore.common.powerSystem.PowerSystem; import reborncore.common.powerSystem.PowerSystem;
import reborncore.common.util.ItemDurabilityExtensions; import reborncore.common.util.ItemDurabilityExtensions;
import reborncore.common.util.ItemUtils; import reborncore.common.util.ItemUtils;
@ -43,8 +38,6 @@ import team.reborn.energy.EnergyTier;
import techreborn.TechReborn; import techreborn.TechReborn;
import techreborn.utils.InitUtils; import techreborn.utils.InitUtils;
import javax.annotation.Nullable;
public class BatteryItem extends Item implements EnergyHolder, ItemDurabilityExtensions { public class BatteryItem extends Item implements EnergyHolder, ItemDurabilityExtensions {
private final int maxEnergy; private final int maxEnergy;
@ -54,15 +47,11 @@ public class BatteryItem extends Item implements EnergyHolder, ItemDurabilityExt
super(new Item.Settings().group(TechReborn.ITEMGROUP).maxCount(1).maxDamageIfAbsent(1)); super(new Item.Settings().group(TechReborn.ITEMGROUP).maxCount(1).maxDamageIfAbsent(1));
this.maxEnergy = maxEnergy; this.maxEnergy = maxEnergy;
this.tier = tier; this.tier = tier;
this.addPropertyGetter(new Identifier("techreborn:empty"), new ItemPropertyGetter() { this.addPropertyGetter(new Identifier("techreborn:empty"), (stack, worldIn, entityIn) -> {
@Override if (!stack.isEmpty() && Energy.of(stack).getEnergy() == 0) {
@Environment(EnvType.CLIENT) return 1.0F;
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;
} }
return 0.0F;
}); });
} }

View file

@ -26,17 +26,13 @@ package techreborn.items;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.minecraft.text.LiteralText;
import net.minecraft.util.Formatting;
import net.minecraft.client.item.TooltipContext; import net.minecraft.client.item.TooltipContext;
import reborncore.common.util.StringUtils;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemPropertyGetter;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemUsageContext; import net.minecraft.item.ItemUsageContext;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.text.LiteralText;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import net.minecraft.util.*; import net.minecraft.util.*;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
@ -45,6 +41,7 @@ import net.minecraft.world.World;
import net.minecraft.world.dimension.DimensionType; import net.minecraft.world.dimension.DimensionType;
import reborncore.client.hud.StackInfoElement; import reborncore.client.hud.StackInfoElement;
import reborncore.common.util.ChatUtils; import reborncore.common.util.ChatUtils;
import reborncore.common.util.StringUtils;
import techreborn.TechReborn; import techreborn.TechReborn;
import techreborn.init.TRContent; import techreborn.init.TRContent;
import techreborn.utils.MessageIDs; import techreborn.utils.MessageIDs;
@ -56,16 +53,12 @@ public class FrequencyTransmitterItem extends Item {
public FrequencyTransmitterItem() { public FrequencyTransmitterItem() {
super(new Item.Settings().group(TechReborn.ITEMGROUP).maxCount(1)); super(new Item.Settings().group(TechReborn.ITEMGROUP).maxCount(1));
this.addPropertyGetter(new Identifier("techreborn", "coords"), new ItemPropertyGetter() { this.addPropertyGetter(new Identifier("techreborn", "coords"), (stack, worldIn, entityIn) -> {
@Override if (!stack.isEmpty() && stack.hasTag() && stack.getTag() != null && stack.getTag().contains("x")
@Environment(EnvType.CLIENT) && stack.getTag().contains("y") && stack.getTag().contains("z") && stack.getTag().contains("dim")) {
public float call(ItemStack stack, @Nullable World worldIn, @Nullable LivingEntity entityIn) { return 1.0F;
if (!stack.isEmpty() && stack.hasTag() && stack.getTag() != null && stack.getTag().contains("x")
&& stack.getTag().contains("y") && stack.getTag().contains("z") && stack.getTag().contains("dim")) {
return 1.0F;
}
return 0.0F;
} }
return 0.0F;
}); });
} }
@ -76,10 +69,10 @@ public class FrequencyTransmitterItem extends Item {
ItemStack stack = context.getStack(); ItemStack stack = context.getStack();
stack.setTag(new CompoundTag()); stack.setTag(new CompoundTag());
stack.getTag().putInt("x", pos.getX()); stack.getOrCreateTag().putInt("x", pos.getX());
stack.getTag().putInt("y", pos.getY()); stack.getOrCreateTag().putInt("y", pos.getY());
stack.getTag().putInt("z", pos.getZ()); stack.getOrCreateTag().putInt("z", pos.getZ());
stack.getTag().putInt("dim", world.getDimension().getType().getRawId()); stack.getOrCreateTag().putInt("dim", world.getDimension().getType().getRawId());
if (!world.isClient) { if (!world.isClient) {
ChatUtils.sendNoSpamMessages(MessageIDs.freqTransmitterID, new LiteralText( ChatUtils.sendNoSpamMessages(MessageIDs.freqTransmitterID, new LiteralText(

View file

@ -47,17 +47,15 @@ import techreborn.utils.InitUtils;
public class BatpackItem extends ArmorItem implements EnergyHolder, ItemDurabilityExtensions { public class BatpackItem extends ArmorItem implements EnergyHolder, ItemDurabilityExtensions {
public final int maxCharge; public final int maxCharge;
public final int transferLimit;
public final EnergyTier tier; public final EnergyTier tier;
public BatpackItem(int maxCharge, int transferLimit, ArmorMaterial material, EnergyTier tier) { public BatpackItem(int maxCharge, ArmorMaterial material, EnergyTier tier) {
super(material, EquipmentSlot.CHEST, new Settings().group(TechReborn.ITEMGROUP).maxCount(1).maxDamage(-1)); super(material, EquipmentSlot.CHEST, new Settings().group(TechReborn.ITEMGROUP).maxCount(1).maxDamage(-1));
this.maxCharge = maxCharge; this.maxCharge = maxCharge;
this.transferLimit = transferLimit;
this.tier = tier; this.tier = tier;
} }
public static void distributePowerToInventory(World world, PlayerEntity player, ItemStack itemStack, int maxSend) { private void distributePowerToInventory(World world, PlayerEntity player, ItemStack itemStack, int maxOutput) {
if (world.isClient || !Energy.valid(itemStack)) { if (world.isClient || !Energy.valid(itemStack)) {
return; return;
} }
@ -66,7 +64,7 @@ public class BatpackItem extends ArmorItem implements EnergyHolder, ItemDurabili
if (Energy.valid(player.inventory.getInvStack(i))) { if (Energy.valid(player.inventory.getInvStack(i))) {
Energy.of(itemStack) Energy.of(itemStack)
.into(Energy.of(player.inventory.getInvStack(i))) .into(Energy.of(player.inventory.getInvStack(i)))
.move(); .move(maxOutput);
} }
} }
} }
@ -75,7 +73,7 @@ public class BatpackItem extends ArmorItem implements EnergyHolder, ItemDurabili
@Override @Override
public void inventoryTick(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) { public void inventoryTick(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) {
if (entityIn instanceof PlayerEntity) { if (entityIn instanceof PlayerEntity) {
distributePowerToInventory(worldIn, (PlayerEntity) entityIn, stack, (int) transferLimit); distributePowerToInventory(worldIn, (PlayerEntity) entityIn, stack, tier.getMaxOutput());
} }
} }
@ -84,26 +82,11 @@ public class BatpackItem extends ArmorItem implements EnergyHolder, ItemDurabili
return false; return false;
} }
@Override
public double getDurability(ItemStack stack) {
return 1 - ItemUtils.getPowerForDurabilityBar(stack);
}
@Override
public boolean showDurability(ItemStack stack) {
return true;
}
@Override @Override
public boolean isEnchantable(ItemStack stack) { public boolean isEnchantable(ItemStack stack) {
return true; return true;
} }
@Override
public int getDurabilityColor(ItemStack stack) {
return PowerSystem.getDisplayPower().colour;
}
@Environment(EnvType.CLIENT) @Environment(EnvType.CLIENT)
@Override @Override
public void appendStacks(ItemGroup group, DefaultedList<ItemStack> itemList) { public void appendStacks(ItemGroup group, DefaultedList<ItemStack> itemList) {
@ -124,4 +107,19 @@ public class BatpackItem extends ArmorItem implements EnergyHolder, ItemDurabili
return tier; return tier;
} }
// ItemDurabilityExtensions
@Override
public int getDurabilityColor(ItemStack stack) {
return PowerSystem.getDisplayPower().colour;
}
@Override
public boolean showDurability(ItemStack stack) {
return true;
}
@Override
public double getDurability(ItemStack stack) {
return 1 - ItemUtils.getPowerForDurabilityBar(stack);
}
} }

View file

@ -55,9 +55,7 @@ public class PaintingToolItem extends Item {
context.getWorld().playSound(player, context.getBlockPos(), SoundEvents.BLOCK_WOOL_PLACE, SoundCategory.BLOCKS, 0.6F, 1.0F); context.getWorld().playSound(player, context.getBlockPos(), SoundEvents.BLOCK_WOOL_PLACE, SoundCategory.BLOCKS, 0.6F, 1.0F);
if (!context.getWorld().isClient) { if (!context.getWorld().isClient) {
context.getStack().damage(1, player, playerCb -> { context.getStack().damage(1, player, playerCb -> playerCb.sendToolBreakStatus(context.getHand()));
playerCb.sendToolBreakStatus(context.getHand());
});
} }
return ActionResult.SUCCESS; return ActionResult.SUCCESS;

View file

@ -52,11 +52,22 @@ public class ElectricTreetapItem extends Item implements EnergyHolder, ItemDurab
super(new Item.Settings().group(TechReborn.ITEMGROUP).maxCount(1).maxDamage(-1)); super(new Item.Settings().group(TechReborn.ITEMGROUP).maxCount(1).maxDamage(-1));
} }
// Item
@Override @Override
public boolean isDamageable() { public boolean isDamageable() {
return false; return false;
} }
@Environment(EnvType.CLIENT)
@Override
public void appendStacks(ItemGroup group, DefaultedList<ItemStack> stacks) {
if (!isIn(group)) {
return;
}
InitUtils.initPoweredItems(this, stacks);
}
// ItemDurabilityExtensions
@Override @Override
public double getDurability(ItemStack stack) { public double getDurability(ItemStack stack) {
return 1 - ItemUtils.getPowerForDurabilityBar(stack); return 1 - ItemUtils.getPowerForDurabilityBar(stack);
@ -72,15 +83,6 @@ public class ElectricTreetapItem extends Item implements EnergyHolder, ItemDurab
return PowerSystem.getDisplayPower().colour; return PowerSystem.getDisplayPower().colour;
} }
@Environment(EnvType.CLIENT)
@Override
public void appendStacks(ItemGroup group, DefaultedList<ItemStack> stacks) {
if (!isIn(group)) {
return;
}
InitUtils.initPoweredItems(this, stacks);
}
// EnergyHolder // EnergyHolder
@Override @Override
public double getMaxStoredPower() { public double getMaxStoredPower() {