mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-22 07:13:28 +01:00
Added battery functionality, Added IActivates for toggle items, Added transfer support to CrystalFux Item
This commit is contained in:
parent
50d2343c8b
commit
de16d7f351
10 changed files with 163 additions and 16 deletions
|
@ -115,7 +115,7 @@ e2c81adfe240117fa0ce2e3dfcfd04f4e1034153 assets/actuallyadditions/blockstates/wh
|
||||||
3670535838b4c26d01afe7ee4807c53a6cbaba12 assets/actuallyadditions/blockstates/white_wall_block.json
|
3670535838b4c26d01afe7ee4807c53a6cbaba12 assets/actuallyadditions/blockstates/white_wall_block.json
|
||||||
78e89628e3c6e891f2994b2a1794672f69826516 assets/actuallyadditions/blockstates/wood_casing_block.json
|
78e89628e3c6e891f2994b2a1794672f69826516 assets/actuallyadditions/blockstates/wood_casing_block.json
|
||||||
207adf3d139369e983100a6002f6f77d36d40916 assets/actuallyadditions/blockstates/xp_solidifier_block.json
|
207adf3d139369e983100a6002f6f77d36d40916 assets/actuallyadditions/blockstates/xp_solidifier_block.json
|
||||||
d8850d66bfac1fdc09b7872f5602a4325cd82ba9 assets/actuallyadditions/lang/en_us.json
|
df3dba5195138437f46df032562fdca2cf335bfa assets/actuallyadditions/lang/en_us.json
|
||||||
8ce3f2af3288773fb581a3668c2cb90b64c9ee2f assets/actuallyadditions/models/block/advanced_item_laser_relay_block.json
|
8ce3f2af3288773fb581a3668c2cb90b64c9ee2f assets/actuallyadditions/models/block/advanced_item_laser_relay_block.json
|
||||||
de74eda6290d47ef2b26961693e537d7b8795a06 assets/actuallyadditions/models/block/atomic_reconstructor_block.json
|
de74eda6290d47ef2b26961693e537d7b8795a06 assets/actuallyadditions/models/block/atomic_reconstructor_block.json
|
||||||
16a76926a07fc8fa10e4a3949d15ad2ca6920bb8 assets/actuallyadditions/models/block/battery_box_block.json
|
16a76926a07fc8fa10e4a3949d15ad2ca6920bb8 assets/actuallyadditions/models/block/battery_box_block.json
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
{
|
{
|
||||||
"actuallyadditions.storage.crystal-flux": "%s/%s Crystal Flux",
|
"actuallyadditions.storage.crystal-flux": "%s/%s Crystal Flux",
|
||||||
|
"actuallyadditions.tooltip.battery.charge-help": "Sneak-right-click to toggle",
|
||||||
|
"actuallyadditions.tooltip.battery.charging": "Charging other item in inventory",
|
||||||
|
"actuallyadditions.tooltip.battery.not-charging": "Not charging other items in inventory",
|
||||||
"actuallyadditions.tooltip.booklet.manual.one": "Or \"Booklet\", if you will",
|
"actuallyadditions.tooltip.booklet.manual.one": "Or \"Booklet\", if you will",
|
||||||
"actuallyadditions.tooltip.booklet.manual.three": "Use while holding to open.",
|
"actuallyadditions.tooltip.booklet.manual.three": "Use while holding to open.",
|
||||||
"actuallyadditions.tooltip.booklet.manual.two": "This book guides you through all of the feature Actually Additions has to over.",
|
"actuallyadditions.tooltip.booklet.manual.two": "This book guides you through all of the feature Actually Additions has to over.",
|
||||||
|
@ -135,7 +138,7 @@
|
||||||
"item.actuallyadditions.basic_coil": "Basic Coil",
|
"item.actuallyadditions.basic_coil": "Basic Coil",
|
||||||
"item.actuallyadditions.bats_wing": "Bat's Wing",
|
"item.actuallyadditions.bats_wing": "Bat's Wing",
|
||||||
"item.actuallyadditions.black_crystal_shard": "Black Crystal Shard",
|
"item.actuallyadditions.black_crystal_shard": "Black Crystal Shard",
|
||||||
"item.actuallyadditions.black_quartz": "Black Quarts",
|
"item.actuallyadditions.black_quartz": "Black Quartz",
|
||||||
"item.actuallyadditions.blue_crystal_shard": "Blue Crystal Shard",
|
"item.actuallyadditions.blue_crystal_shard": "Blue Crystal Shard",
|
||||||
"item.actuallyadditions.booklet": "Actually Additions Manual",
|
"item.actuallyadditions.booklet": "Actually Additions Manual",
|
||||||
"item.actuallyadditions.bowl_of_water": "Bowl of Water",
|
"item.actuallyadditions.bowl_of_water": "Bowl of Water",
|
||||||
|
@ -290,7 +293,7 @@
|
||||||
"item.actuallyadditions.phantom_connector": "Phantom Connector",
|
"item.actuallyadditions.phantom_connector": "Phantom Connector",
|
||||||
"item.actuallyadditions.player_probe": "Player Probe",
|
"item.actuallyadditions.player_probe": "Player Probe",
|
||||||
"item.actuallyadditions.quadruple_battery": "Quadruple Battery",
|
"item.actuallyadditions.quadruple_battery": "Quadruple Battery",
|
||||||
"item.actuallyadditions.quartz_aiot": "Quartz AIOT",
|
"item.actuallyadditions.quartz_aiot": "Black Quartz AIOT",
|
||||||
"item.actuallyadditions.quartz_axe": "Quartz Axe",
|
"item.actuallyadditions.quartz_axe": "Quartz Axe",
|
||||||
"item.actuallyadditions.quartz_boots": "Quartz Boots",
|
"item.actuallyadditions.quartz_boots": "Quartz Boots",
|
||||||
"item.actuallyadditions.quartz_chest": "Quartz Chestplate",
|
"item.actuallyadditions.quartz_chest": "Quartz Chestplate",
|
||||||
|
|
|
@ -14,11 +14,20 @@ import javax.annotation.Nullable;
|
||||||
public class CrystalFluxProvider implements ICapabilityProvider {
|
public class CrystalFluxProvider implements ICapabilityProvider {
|
||||||
private ItemStack stack;
|
private ItemStack stack;
|
||||||
private int energy;
|
private int energy;
|
||||||
private LazyOptional<IEnergyStorage> capability = LazyOptional.of(() -> new CrystalFluxStorage(stack, energy));
|
private int transfer;
|
||||||
|
|
||||||
|
private LazyOptional<IEnergyStorage> capability = LazyOptional.of(() -> new CrystalFluxStorage(stack, energy, transfer));
|
||||||
|
|
||||||
public CrystalFluxProvider(ItemStack stack, int energy) {
|
public CrystalFluxProvider(ItemStack stack, int energy) {
|
||||||
this.stack = stack;
|
this.stack = stack;
|
||||||
this.energy = energy;
|
this.energy = energy;
|
||||||
|
this.transfer = Integer.MAX_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CrystalFluxProvider(ItemStack stack, int energy, int transfer) {
|
||||||
|
this.stack = stack;
|
||||||
|
this.energy = energy;
|
||||||
|
this.transfer = transfer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
|
|
|
@ -12,8 +12,8 @@ public class CrystalFluxStorage extends EnergyStorage {
|
||||||
public static final String NBT_TAG = "crystal-flux";
|
public static final String NBT_TAG = "crystal-flux";
|
||||||
private final ItemStack stack;
|
private final ItemStack stack;
|
||||||
|
|
||||||
public CrystalFluxStorage(ItemStack stack, int capacity) {
|
public CrystalFluxStorage(ItemStack stack, int capacity, int transfer) {
|
||||||
super(capacity, Integer.MAX_VALUE, Integer.MAX_VALUE);
|
super(capacity, transfer, transfer);
|
||||||
|
|
||||||
this.stack = stack;
|
this.stack = stack;
|
||||||
|
|
||||||
|
|
|
@ -2,10 +2,7 @@ package de.ellpeck.actuallyadditions.common.items;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import de.ellpeck.actuallyadditions.common.ActuallyAdditions;
|
import de.ellpeck.actuallyadditions.common.ActuallyAdditions;
|
||||||
import de.ellpeck.actuallyadditions.common.items.useables.AllInOneTool;
|
import de.ellpeck.actuallyadditions.common.items.useables.*;
|
||||||
import de.ellpeck.actuallyadditions.common.items.useables.LeafBlowerItem;
|
|
||||||
import de.ellpeck.actuallyadditions.common.items.useables.ManualItem;
|
|
||||||
import de.ellpeck.actuallyadditions.common.items.useables.TeleportStaffItem;
|
|
||||||
import de.ellpeck.actuallyadditions.common.materials.ArmorMaterials;
|
import de.ellpeck.actuallyadditions.common.materials.ArmorMaterials;
|
||||||
import de.ellpeck.actuallyadditions.common.materials.ToolMaterials;
|
import de.ellpeck.actuallyadditions.common.materials.ToolMaterials;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
|
@ -107,11 +104,14 @@ public final class ActuallyItems {
|
||||||
public static final RegistryObject<Item> LASER_WRENCH = ITEMS.register("laser_wrench", basicItem());
|
public static final RegistryObject<Item> LASER_WRENCH = ITEMS.register("laser_wrench", basicItem());
|
||||||
public static final RegistryObject<Item> TELEPORT_STAFF = ITEMS.register("teleport_staff", TeleportStaffItem::new);
|
public static final RegistryObject<Item> TELEPORT_STAFF = ITEMS.register("teleport_staff", TeleportStaffItem::new);
|
||||||
public static final RegistryObject<Item> WINGS_OF_THE_BATS = ITEMS.register("wings_of_the_bats", basicItem());
|
public static final RegistryObject<Item> WINGS_OF_THE_BATS = ITEMS.register("wings_of_the_bats", basicItem());
|
||||||
public static final RegistryObject<Item> SINGLE_BATTERY = ITEMS.register("single_battery", basicItem());
|
|
||||||
public static final RegistryObject<Item> DOUBLE_BATTERY = ITEMS.register("double_battery", basicItem());
|
// Batteries
|
||||||
public static final RegistryObject<Item> TRIPLE_BATTERY = ITEMS.register("triple_battery", basicItem());
|
public static final RegistryObject<Item> SINGLE_BATTERY = ITEMS.register("single_battery", () -> new BatteryItem(() -> 200000, 1000));
|
||||||
public static final RegistryObject<Item> QUADRUPLE_BATTERY = ITEMS.register("quadruple_battery", basicItem());
|
public static final RegistryObject<Item> DOUBLE_BATTERY = ITEMS.register("double_battery", () -> new BatteryItem(() -> 350000, 5000));
|
||||||
public static final RegistryObject<Item> QUINTUPLE_BATTERY = ITEMS.register("quintuple_battery", basicItem());
|
public static final RegistryObject<Item> TRIPLE_BATTERY = ITEMS.register("triple_battery", () -> new BatteryItem(() -> 600000, 10000));
|
||||||
|
public static final RegistryObject<Item> QUADRUPLE_BATTERY = ITEMS.register("quadruple_battery", () -> new BatteryItem(() -> 1000000, 30000));
|
||||||
|
public static final RegistryObject<Item> QUINTUPLE_BATTERY = ITEMS.register("quintuple_battery", () -> new BatteryItem(() -> 2000000, 100000));
|
||||||
|
|
||||||
public static final RegistryObject<Item> DRILL_MAIN = ITEMS.register("drill_light_blue", basicItem());
|
public static final RegistryObject<Item> DRILL_MAIN = ITEMS.register("drill_light_blue", basicItem());
|
||||||
public static final RegistryObject<Item> DRILL_BLACK = ITEMS.register("drill_black", basicItem());
|
public static final RegistryObject<Item> DRILL_BLACK = ITEMS.register("drill_black", basicItem());
|
||||||
public static final RegistryObject<Item> DRILL_BLUE = ITEMS.register("drill_blue", basicItem());
|
public static final RegistryObject<Item> DRILL_BLUE = ITEMS.register("drill_blue", basicItem());
|
||||||
|
|
|
@ -35,6 +35,7 @@ public abstract class CrystalFluxItem extends ActuallyItem {
|
||||||
alt ? NumberFormat.getIntegerInstance().format(value) : Help.compressedValue(value);
|
alt ? NumberFormat.getIntegerInstance().format(value) : Help.compressedValue(value);
|
||||||
|
|
||||||
private final Supplier<Integer> maxFlux;
|
private final Supplier<Integer> maxFlux;
|
||||||
|
private final int transfer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* We use a supplier here to allow for config values to be passed around so we are able to
|
* We use a supplier here to allow for config values to be passed around so we are able to
|
||||||
|
@ -46,12 +47,24 @@ public abstract class CrystalFluxItem extends ActuallyItem {
|
||||||
super(properties);
|
super(properties);
|
||||||
|
|
||||||
this.maxFlux = maxFlux;
|
this.maxFlux = maxFlux;
|
||||||
|
this.transfer = Integer.MAX_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allows for granular control over the transfer rate
|
||||||
|
* @param maxFlux max energy this item can store
|
||||||
|
* @param transfer max transfer rate for energy
|
||||||
|
*/
|
||||||
|
public CrystalFluxItem(Properties properties, Supplier<Integer> maxFlux, int transfer) {
|
||||||
|
super(properties);
|
||||||
|
this.maxFlux = maxFlux;
|
||||||
|
this.transfer = transfer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public ICapabilityProvider initCapabilities(ItemStack stack, @Nullable CompoundNBT nbt) {
|
public ICapabilityProvider initCapabilities(ItemStack stack, @Nullable CompoundNBT nbt) {
|
||||||
return new CrystalFluxProvider(stack, maxFlux.get());
|
return new CrystalFluxProvider(stack, maxFlux.get(), this.transfer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@OnlyIn(Dist.CLIENT)
|
@OnlyIn(Dist.CLIENT)
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
package de.ellpeck.actuallyadditions.common.items;
|
||||||
|
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
|
||||||
|
public interface IActivates {
|
||||||
|
String NBT_TAG = "is-enabled";
|
||||||
|
|
||||||
|
default boolean isEnabled(ItemStack stack) {
|
||||||
|
return stack.getOrCreateTag().getBoolean(NBT_TAG);
|
||||||
|
}
|
||||||
|
|
||||||
|
default void toggle(ItemStack stack) {
|
||||||
|
stack.getOrCreateTag().putBoolean(NBT_TAG, !isEnabled(stack));
|
||||||
|
}
|
||||||
|
|
||||||
|
default void manualToggle(ItemStack stack, boolean enabled) {
|
||||||
|
stack.getOrCreateTag().putBoolean(NBT_TAG, enabled);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,91 @@
|
||||||
|
package de.ellpeck.actuallyadditions.common.items.useables;
|
||||||
|
|
||||||
|
import de.ellpeck.actuallyadditions.common.items.CrystalFluxItem;
|
||||||
|
import de.ellpeck.actuallyadditions.common.items.IActivates;
|
||||||
|
import de.ellpeck.actuallyadditions.common.utilities.Help;
|
||||||
|
import net.minecraft.client.util.ITooltipFlag;
|
||||||
|
import net.minecraft.entity.Entity;
|
||||||
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.util.ActionResult;
|
||||||
|
import net.minecraft.util.Hand;
|
||||||
|
import net.minecraft.util.text.ITextComponent;
|
||||||
|
import net.minecraft.util.text.TextFormatting;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraftforge.energy.CapabilityEnergy;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
public class BatteryItem extends CrystalFluxItem implements IActivates {
|
||||||
|
public BatteryItem(Supplier<Integer> maxFlux, int transfer) {
|
||||||
|
super(baseProps().maxStackSize(1).setNoRepair().maxDamage(0), maxFlux, transfer);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void inventoryTick(ItemStack stack, World world, Entity entity, int itemSlot, boolean isSelected) {
|
||||||
|
if (world.isRemote || !(entity instanceof PlayerEntity) || !isEnabled(stack) || isSelected) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Don't run if we have no charge. Duh
|
||||||
|
if (stack.getCapability(CapabilityEnergy.ENERGY)
|
||||||
|
.map(e -> e.getEnergyStored() <= 0)
|
||||||
|
.orElse(true)
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
PlayerEntity player = (PlayerEntity) entity;
|
||||||
|
for(int i = 0; i < player.inventory.getSizeInventory(); i++) {
|
||||||
|
ItemStack slot = player.inventory.getStackInSlot(i);
|
||||||
|
|
||||||
|
// We don't care for weirdo stackable charging items, nor the same item as is charging others. Duh
|
||||||
|
if (slot.isEmpty() || slot.getCount() != 1 || slot.equals(stack)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
slot.getCapability(CapabilityEnergy.ENERGY).ifPresent(energy -> {
|
||||||
|
// Don't keep charging if empty
|
||||||
|
if (energy.getEnergyStored() >= energy.getMaxEnergyStored()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Find max power from the battery and use that to attempt to charge the other item
|
||||||
|
int maxExtractable = stack.getCapability(CapabilityEnergy.ENERGY).map(e -> e.extractEnergy(Integer.MAX_VALUE, true)).orElse(0);
|
||||||
|
int received = energy.receiveEnergy(maxExtractable, false);
|
||||||
|
|
||||||
|
if (received > 0) {
|
||||||
|
stack.getCapability(CapabilityEnergy.ENERGY).ifPresent(e -> e.extractEnergy(received, false));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ActionResult<ItemStack> onItemRightClick(World world, PlayerEntity player, Hand hand) {
|
||||||
|
if (!world.isRemote && player.isSneaking()) {
|
||||||
|
ItemStack heldItem = player.getHeldItem(hand);
|
||||||
|
|
||||||
|
toggle(heldItem);
|
||||||
|
return ActionResult.resultSuccess(heldItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
return super.onItemRightClick(world, player, hand);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addInformation(ItemStack stack, @Nullable World worldIn, List<ITextComponent> tooltip, ITooltipFlag flagIn) {
|
||||||
|
super.addInformation(stack, worldIn, tooltip, flagIn);
|
||||||
|
|
||||||
|
boolean enabled = isEnabled(stack);
|
||||||
|
tooltip.add(Help.trans(String.format("tooltip.battery.%s", enabled ? "charging" : "not-charging")).mergeStyle(enabled ? TextFormatting.GREEN : TextFormatting.GRAY));
|
||||||
|
tooltip.add(Help.trans("tooltip.battery.charge-help"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasEffect(ItemStack stack) {
|
||||||
|
return isEnabled(stack);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
@ParametersAreNonnullByDefault
|
||||||
|
@MethodsReturnNonnullByDefault
|
||||||
|
package de.ellpeck.actuallyadditions.common.items.useables;
|
||||||
|
|
||||||
|
import mcp.MethodsReturnNonnullByDefault;
|
||||||
|
|
||||||
|
import javax.annotation.ParametersAreNonnullByDefault;
|
|
@ -322,6 +322,11 @@ public class GeneratorLanguage extends LanguageProvider {
|
||||||
addPrefixed("tooltip.booklet.manual.two", "This book guides you through all of the feature Actually Additions has to over.");
|
addPrefixed("tooltip.booklet.manual.two", "This book guides you through all of the feature Actually Additions has to over.");
|
||||||
addPrefixed("tooltip.booklet.manual.three", "Use while holding to open.");
|
addPrefixed("tooltip.booklet.manual.three", "Use while holding to open.");
|
||||||
|
|
||||||
|
// Battery
|
||||||
|
addPrefixed("tooltip.battery.not-charging", "Not charging other items in inventory");
|
||||||
|
addPrefixed("tooltip.battery.charging", "Charging other item in inventory");
|
||||||
|
addPrefixed("tooltip.battery.charge-help", "Sneak-right-click to toggle");
|
||||||
|
|
||||||
// Storage
|
// Storage
|
||||||
addPrefixed("storage.crystal-flux", "%s/%s Crystal Flux");
|
addPrefixed("storage.crystal-flux", "%s/%s Crystal Flux");
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue