From 0863e851b67af13871c6ab6b66e0c147d4f14c80 Mon Sep 17 00:00:00 2001 From: Trytoon Date: Thu, 29 Jun 2023 09:46:01 +0200 Subject: [PATCH 1/4] Added the wired charger --- .../enderio/blockstates/wired_charger.json | 7 ++ .../resources/assets/enderio/lang/en_ud.json | 1 + .../resources/assets/enderio/lang/en_us.json | 1 + .../enderio/models/block/wired_charger.json | 23 ++++ .../enderio/models/item/wired_charger.json | 3 + .../recipes/misc/wired_charger.json | 35 ++++++ .../loot_tables/blocks/wired_charger.json | 29 +++++ .../data/enderio/recipes/wired_charger.json | 21 ++++ .../client/gui/screen/WiredChargerScreen.java | 43 ++++++++ .../blockentity/WiredChargerBlockEntity.java | 104 ++++++++++++++++++ .../common/init/MachineBlockEntities.java | 3 + .../machines/common/init/MachineBlocks.java | 7 ++ .../machines/common/init/MachineMenus.java | 1 + .../common/menu/WiredChargerMenu.java | 33 ++++++ .../models/block/wired_charger_front.json | 104 ++++++++++++++++++ .../textures/block/wired_charger_front.png | Bin 0 -> 1360 bytes 16 files changed, 415 insertions(+) create mode 100644 src/generated/resources/assets/enderio/blockstates/wired_charger.json create mode 100644 src/generated/resources/assets/enderio/models/block/wired_charger.json create mode 100644 src/generated/resources/assets/enderio/models/item/wired_charger.json create mode 100644 src/generated/resources/data/enderio/advancements/recipes/misc/wired_charger.json create mode 100644 src/generated/resources/data/enderio/loot_tables/blocks/wired_charger.json create mode 100644 src/generated/resources/data/enderio/recipes/wired_charger.json create mode 100644 src/machines/java/com/enderio/machines/client/gui/screen/WiredChargerScreen.java create mode 100644 src/machines/java/com/enderio/machines/common/blockentity/WiredChargerBlockEntity.java create mode 100644 src/machines/java/com/enderio/machines/common/menu/WiredChargerMenu.java create mode 100644 src/main/resources/assets/enderio/models/block/wired_charger_front.json create mode 100644 src/main/resources/assets/enderio/textures/block/wired_charger_front.png diff --git a/src/generated/resources/assets/enderio/blockstates/wired_charger.json b/src/generated/resources/assets/enderio/blockstates/wired_charger.json new file mode 100644 index 0000000000..d414613402 --- /dev/null +++ b/src/generated/resources/assets/enderio/blockstates/wired_charger.json @@ -0,0 +1,7 @@ +{ + "variants": { + "": { + "model": "enderio:block/wired_charger" + } + } +} \ No newline at end of file diff --git a/src/generated/resources/assets/enderio/lang/en_ud.json b/src/generated/resources/assets/enderio/lang/en_ud.json index 3bf7627150..8338341cac 100644 --- a/src/generated/resources/assets/enderio/lang/en_ud.json +++ b/src/generated/resources/assets/enderio/lang/en_ud.json @@ -806,6 +806,7 @@ "block.enderio.void_chassis": "sıssɐɥƆ pıoΛ", "block.enderio.xp_juice": "ǝɔınſ dX", "block.enderio.xp_vacuum": "ɯnnɔɐΛ dX", + "block.enderio.wired_charger": "ʌɹıǝW ɹǝɔɔɐƃ", "description.enderio.enchantment.auto_smelt": "pǝuıɯ sı ɹǝʌǝʇɐɥʍ sǝʇןǝɯs ʎןןɐɔıʇɐɯoʇnⱯ", "description.enderio.enchantment.repellent": "ɹǝɥʇɹɐɟ puɐ uǝʇɟo ǝɹoɯ ʇɹodǝןǝʇ sןǝʌǝן ɹǝɥbıH\nʎɐʍɐ sɹǝʞɔɐʇʇɐ ʇɹodǝןǝʇ oʇ ǝɔuɐɥƆ", "description.enderio.enchantment.shimmer": "˙ʍouʞ I\n˙ssǝןǝsn sı ʇı 'sǝʎ\n˙ǝɹoɯ buıɥʇoN\n˙ʎןןɐǝᴚ\n˙ןןɐ s,ʇɐɥ⟘\n˙pǝʇuɐɥɔuǝ sɐʍ ʇı ɟı sɐ ɹǝɯɯıɥs ɯǝʇı ǝɥʇ sǝʞɐW", diff --git a/src/generated/resources/assets/enderio/lang/en_us.json b/src/generated/resources/assets/enderio/lang/en_us.json index 00edb7bf2c..6fdfcab8cc 100644 --- a/src/generated/resources/assets/enderio/lang/en_us.json +++ b/src/generated/resources/assets/enderio/lang/en_us.json @@ -804,6 +804,7 @@ "block.enderio.vapor_of_levity": "Vapor Of Levity", "block.enderio.vibrant_alloy_block": "Vibrant Alloy Block", "block.enderio.void_chassis": "Void Chassis", + "block.enderio.wired_charger": "Wired Charger", "block.enderio.xp_juice": "Xp Juice", "block.enderio.xp_vacuum": "Xp Vacuum", "description.enderio.enchantment.auto_smelt": "Automatically smeltes whatever is mined", diff --git a/src/generated/resources/assets/enderio/models/block/wired_charger.json b/src/generated/resources/assets/enderio/models/block/wired_charger.json new file mode 100644 index 0000000000..f22ec8c61f --- /dev/null +++ b/src/generated/resources/assets/enderio/models/block/wired_charger.json @@ -0,0 +1,23 @@ +{ + "parent": "minecraft:block/block", + "children": { + "frame": { + "parent": "enderio:block/machine_frame" + }, + "front": { + "parent": "enderio:block/wired_charger_front" + }, + "overlay": { + "parent": "enderio:block/io_overlay" + } + }, + "item_render_order": [ + "frame", + "overlay", + "front" + ], + "loader": "forge:composite", + "textures": { + "particle": "enderio:block/machine_side" + } +} \ No newline at end of file diff --git a/src/generated/resources/assets/enderio/models/item/wired_charger.json b/src/generated/resources/assets/enderio/models/item/wired_charger.json new file mode 100644 index 0000000000..95cd1387f5 --- /dev/null +++ b/src/generated/resources/assets/enderio/models/item/wired_charger.json @@ -0,0 +1,3 @@ +{ + "parent": "enderio:block/wired_charger" +} \ No newline at end of file diff --git a/src/generated/resources/data/enderio/advancements/recipes/misc/wired_charger.json b/src/generated/resources/data/enderio/advancements/recipes/misc/wired_charger.json new file mode 100644 index 0000000000..ecf93d411a --- /dev/null +++ b/src/generated/resources/data/enderio/advancements/recipes/misc/wired_charger.json @@ -0,0 +1,35 @@ +{ + "parent": "minecraft:recipes/root", + "criteria": { + "has_ingredient": { + "conditions": { + "items": [ + { + "items": [ + "enderio:wired_charger" + ] + } + ] + }, + "trigger": "minecraft:inventory_changed" + }, + "has_the_recipe": { + "conditions": { + "recipe": "enderio:sag_mill" + }, + "trigger": "minecraft:recipe_unlocked" + } + }, + "requirements": [ + [ + "has_ingredient", + "has_the_recipe" + ] + ], + "rewards": { + "recipes": [ + "enderio:wired_charger" + ] + }, + "sends_telemetry_event": false +} \ No newline at end of file diff --git a/src/generated/resources/data/enderio/loot_tables/blocks/wired_charger.json b/src/generated/resources/data/enderio/loot_tables/blocks/wired_charger.json new file mode 100644 index 0000000000..4f28c00c59 --- /dev/null +++ b/src/generated/resources/data/enderio/loot_tables/blocks/wired_charger.json @@ -0,0 +1,29 @@ +{ + "type": "minecraft:block", + "pools": [ + { + "bonus_rolls": 0.0, + "entries": [ + { + "type": "minecraft:item", + "functions": [ + { + "function": "minecraft:copy_nbt", + "ops": [ + { + "op": "replace", + "source": "", + "target": "BlockEntityTag" + } + ], + "source": "block_entity" + } + ], + "name": "enderio:wired_charger" + } + ], + "rolls": 1.0 + } + ], + "random_sequence": "enderio:blocks/wired_charger" +} \ No newline at end of file diff --git a/src/generated/resources/data/enderio/recipes/wired_charger.json b/src/generated/resources/data/enderio/recipes/wired_charger.json new file mode 100644 index 0000000000..684a127f23 --- /dev/null +++ b/src/generated/resources/data/enderio/recipes/wired_charger.json @@ -0,0 +1,21 @@ +{ + "type": "minecraft:crafting_shaped", + "category": "misc", + "key": { + "E": { + "item": "enderio:electrical_steel_ingot" + }, + "V": { + "item": "enderio:void_chassis" + } + }, + "pattern": [ + "EEE", + "EVE", + "EEE" + ], + "result": { + "item": "enderio:wired_charger" + }, + "show_notification": true +} \ No newline at end of file diff --git a/src/machines/java/com/enderio/machines/client/gui/screen/WiredChargerScreen.java b/src/machines/java/com/enderio/machines/client/gui/screen/WiredChargerScreen.java new file mode 100644 index 0000000000..a106069426 --- /dev/null +++ b/src/machines/java/com/enderio/machines/client/gui/screen/WiredChargerScreen.java @@ -0,0 +1,43 @@ +package com.enderio.machines.client.gui.screen; + +import com.enderio.EnderIO; +import com.enderio.api.misc.Vector2i; +import com.enderio.base.common.lang.EIOLang; +import com.enderio.core.client.gui.screen.EIOScreen; +import com.enderio.core.client.gui.widgets.EnumIconWidget; +import com.enderio.machines.client.gui.widget.EnergyWidget; +import com.enderio.machines.client.gui.widget.ProgressWidget; +import com.enderio.machines.common.menu.WiredChargerMenu; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.entity.player.Inventory; + +public class WiredChargerScreen extends EIOScreen { + + private static final ResourceLocation BG_TEXTURE = EnderIO.loc("textures/gui/wired_charger.png"); + public WiredChargerScreen(WiredChargerMenu pMenu, Inventory pPlayerInventory, Component pTitle) { + super(pMenu, pPlayerInventory, pTitle); + } + + @Override + protected void init() { + super.init(); + + addRenderableOnly(new ProgressWidget.BottomUp(this, () -> menu.getBlockEntity().getProgress(), getGuiLeft() + 103, getGuiTop() + 18, 12, 36, 242, 1)); + + addRenderableOnly(new EnergyWidget(this, getMenu().getBlockEntity()::getEnergyStorage, 37 + leftPos, 14 + topPos, 9, 43)); + + addRenderableWidget(new EnumIconWidget<>(this, leftPos + imageWidth - 8 - 12, topPos + 6, () -> menu.getBlockEntity().getRedstoneControl(), + control -> menu.getBlockEntity().setRedstoneControl(control), EIOLang.REDSTONE_MODE)); + } + + @Override + public ResourceLocation getBackgroundImage() { + return BG_TEXTURE; + } + + @Override + protected Vector2i getBackgroundImageSize() { + return new Vector2i(195, 166); + } +} diff --git a/src/machines/java/com/enderio/machines/common/blockentity/WiredChargerBlockEntity.java b/src/machines/java/com/enderio/machines/common/blockentity/WiredChargerBlockEntity.java new file mode 100644 index 0000000000..481ecff00f --- /dev/null +++ b/src/machines/java/com/enderio/machines/common/blockentity/WiredChargerBlockEntity.java @@ -0,0 +1,104 @@ +package com.enderio.machines.common.blockentity; + +import com.enderio.api.capacitor.CapacitorModifier; +import com.enderio.api.capacitor.QuadraticScalable; +import com.enderio.api.io.energy.EnergyIOMode; +import com.enderio.core.common.sync.FloatDataSlot; +import com.enderio.core.common.sync.SyncMode; +import com.enderio.machines.common.blockentity.base.PoweredMachineEntity; +import com.enderio.machines.common.io.item.MachineInventoryLayout; +import com.enderio.machines.common.io.item.SingleSlotAccess; +import com.enderio.machines.common.menu.WiredChargerMenu; +import net.minecraft.core.BlockPos; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.block.entity.BlockEntityType; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraftforge.common.capabilities.ForgeCapabilities; +import net.minecraftforge.energy.IEnergyStorage; +import org.jetbrains.annotations.Nullable; + +import java.util.Optional; + +public class WiredChargerBlockEntity extends PoweredMachineEntity { + + public static final QuadraticScalable CAPACITY = new QuadraticScalable(CapacitorModifier.ENERGY_CAPACITY, () -> 100000f); + public static final QuadraticScalable TRANSFER = new QuadraticScalable(CapacitorModifier.ENERGY_TRANSFER, () -> 100000f); + public static final QuadraticScalable USAGE = new QuadraticScalable(CapacitorModifier.ENERGY_USE, () -> 100f); + + public static final SingleSlotAccess ITEM_TO_CHARGE = new SingleSlotAccess(); + + public static final SingleSlotAccess ITEM_CHARGED = new SingleSlotAccess(); + + private float progress = 0; + + public WiredChargerBlockEntity(BlockEntityType type, BlockPos worldPosition, BlockState blockState) { + super(EnergyIOMode.Input, CAPACITY, TRANSFER, USAGE, type, worldPosition, blockState); + addDataSlot(new FloatDataSlot(this::getProgress, p -> progress = p, SyncMode.GUI)); + } + + + @Override + public MachineInventoryLayout getInventoryLayout() { + return MachineInventoryLayout + .builder() + .capacitor() + .inputSlot((slot, stack) -> acceptItem(stack)) + .slotAccess(ITEM_TO_CHARGE) + .outputSlot() + .slotAccess(ITEM_CHARGED) + .build(); + } + + + @Nullable + @Override + public AbstractContainerMenu createMenu(int pContainerId, Inventory pPlayerInventory, Player pPlayer) { + return new WiredChargerMenu(this, pPlayerInventory, pContainerId); + } + + @Override + public void serverTick() { + super.serverTick(); + chargeItem(); + } + + + public boolean acceptItem(ItemStack item) { + Optional energyHandlerCap = item.getCapability(ForgeCapabilities.ENERGY).resolve(); + return energyHandlerCap.isPresent(); + } + + public void chargeItem() { + ItemStack inputItem = ITEM_TO_CHARGE.getItemStack(this); + ItemStack outputItem = ITEM_CHARGED.getItemStack(this); + if (!inputItem.isEmpty() && outputItem.isEmpty() && isCapacitorInstalled()) { + Optional energyHandlerCap = inputItem.getCapability(ForgeCapabilities.ENERGY).resolve(); + if (energyHandlerCap.isPresent()) { + IEnergyStorage itemEnergyStorage = energyHandlerCap.get(); + if (itemEnergyStorage.getEnergyStored() == itemEnergyStorage.getMaxEnergyStored()) { + ITEM_CHARGED.setStackInSlot(this, inputItem); + ITEM_TO_CHARGE.setStackInSlot(this, ItemStack.EMPTY); + } else { + // The energyExtracted per tick should increase if the charged item has more energy and with the tiers of the capacitor installed + int energyExtracted = itemEnergyStorage.getMaxEnergyStored() / (1000-this.energyStorage.getMaxEnergyUse()); + if (canAct() && this.energyStorage.getEnergyStored() >= energyExtracted) { + itemEnergyStorage.receiveEnergy(energyExtracted, false); + this.energyStorage.takeEnergy(energyExtracted); + this.progress = (float)itemEnergyStorage.getEnergyStored()/itemEnergyStorage.getMaxEnergyStored(); + } + } + } else { + this.progress = 0; + } + } else { + this.progress = 0; + } + } + + public float getProgress() { + return this.progress; + } +} diff --git a/src/machines/java/com/enderio/machines/common/init/MachineBlockEntities.java b/src/machines/java/com/enderio/machines/common/init/MachineBlockEntities.java index 462556f3f2..803e86136b 100644 --- a/src/machines/java/com/enderio/machines/common/init/MachineBlockEntities.java +++ b/src/machines/java/com/enderio/machines/common/init/MachineBlockEntities.java @@ -47,6 +47,9 @@ public class MachineBlockEntities { public static final BlockEntityEntry POWERED_SPAWNER = register("powered_spanwer", PoweredSpawnerBlockEntity::new, MachineBlocks.POWERED_SPAWNER); + public static final BlockEntityEntry WIRED_CHARGER = register("wired_charger", + WiredChargerBlockEntity::new, MachineBlocks.WIRED_CHARGER); + @SafeVarargs private static BlockEntityEntry register(String name, BlockEntityBuilder.BlockEntityFactory beFactory, NonNullSupplier... blocks) { diff --git a/src/machines/java/com/enderio/machines/common/init/MachineBlocks.java b/src/machines/java/com/enderio/machines/common/init/MachineBlocks.java index e391d71ff7..e3f12d4282 100644 --- a/src/machines/java/com/enderio/machines/common/init/MachineBlocks.java +++ b/src/machines/java/com/enderio/machines/common/init/MachineBlocks.java @@ -117,6 +117,13 @@ public class MachineBlocks { .build() .register(); + public static final BlockEntry WIRED_CHARGER = REGISTRATE + .block("wired_charger", props -> new MachineBlock(props, MachineBlockEntities.WIRED_CHARGER)) + .item() + .tab(EIOCreativeTabs.MACHINES) + .build() + .register(); + public static final BlockEntry STIRLING_GENERATOR = standardMachine("stirling_generator", () -> MachineBlockEntities.STIRLING_GENERATOR) .register(); diff --git a/src/machines/java/com/enderio/machines/common/init/MachineMenus.java b/src/machines/java/com/enderio/machines/common/init/MachineMenus.java index c0477e0812..249e7ac9ae 100644 --- a/src/machines/java/com/enderio/machines/common/init/MachineMenus.java +++ b/src/machines/java/com/enderio/machines/common/init/MachineMenus.java @@ -24,6 +24,7 @@ private MachineMenus() {} public static final MenuEntry VACUUM_CHEST = REGISTRATE.menu("vacuum_chest", VacuumChestMenu::factory, () -> VacuumChestScreen::new).register(); public static final MenuEntry XP_VACUUM = REGISTRATE.menu("xp_vacuum", XPVacuumMenu::factory, () -> XPVacuumScreen::new).register(); public static final MenuEntry CRAFTER = REGISTRATE.menu("crafter", CrafterMenu::factory, () -> CrafterScreen::new).register(); + public static final MenuEntry WIRED_CHARGER = REGISTRATE.menu("wired_charger", WiredChargerMenu::factory, () -> WiredChargerScreen::new).register(); public static void register() {} } diff --git a/src/machines/java/com/enderio/machines/common/menu/WiredChargerMenu.java b/src/machines/java/com/enderio/machines/common/menu/WiredChargerMenu.java new file mode 100644 index 0000000000..84cf4c7338 --- /dev/null +++ b/src/machines/java/com/enderio/machines/common/menu/WiredChargerMenu.java @@ -0,0 +1,33 @@ +package com.enderio.machines.common.menu; + +import com.enderio.machines.common.blockentity.WiredChargerBlockEntity; +import com.enderio.machines.common.init.MachineMenus; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.level.block.entity.BlockEntity; +import org.apache.logging.log4j.LogManager; +import org.jetbrains.annotations.Nullable; + +public class WiredChargerMenu extends MachineMenu{ + + public WiredChargerMenu(WiredChargerBlockEntity blockEntity, Inventory inventory, int pContainerId) { + super(blockEntity, inventory, MachineMenus.WIRED_CHARGER.get(), pContainerId); + + addSlot(new MachineSlot(blockEntity.getInventory(), blockEntity.getCapacitorSlot(), 33, 60)); + addSlot(new MachineSlot(blockEntity.getInventory(), WiredChargerBlockEntity.ITEM_TO_CHARGE, 75, 28)); + addSlot(new MachineSlot(blockEntity.getInventory(), WiredChargerBlockEntity.ITEM_CHARGED, 126, 28)); + + addInventorySlots(29,84); + } + + public static WiredChargerMenu factory(@Nullable MenuType pMenuType, int pContainerId, Inventory inventory, FriendlyByteBuf buf) { + BlockEntity entity = inventory.player.level().getBlockEntity(buf.readBlockPos()); + + if (entity instanceof WiredChargerBlockEntity castBlockEntity) + return new WiredChargerMenu(castBlockEntity, inventory, pContainerId); + LogManager.getLogger().warn("couldn't find BlockEntity"); + + return new WiredChargerMenu(null, inventory, pContainerId); + } +} diff --git a/src/main/resources/assets/enderio/models/block/wired_charger_front.json b/src/main/resources/assets/enderio/models/block/wired_charger_front.json new file mode 100644 index 0000000000..2a6fb0d9df --- /dev/null +++ b/src/main/resources/assets/enderio/models/block/wired_charger_front.json @@ -0,0 +1,104 @@ +{ + "credit": "Designed by HenryLoenwind with Cubik Studio - https://cubik.studio", + "textures": { + "0": "enderio:block/wired_charger_front", + "particle": "enderio:block/wired_charger_front" + }, + "elements": [ + { + "name": "Box1", + "from": [0.5, 0.5, 0], + "to": [15.5, 3, 0.5], + "faces": { + "north": {"uv": [0.5, 13, 15.5, 15.5], "texture": "#0"}, + "up": {"uv": [0.5, 13, 15.5, 14], "rotation": 180, "texture": "#0"} + } + }, + { + "name": "Box2", + "from": [0.5, 13, 0], + "to": [15.5, 15.5, 0.5], + "faces": { + "north": {"uv": [0.5, 0.5, 15.5, 3], "texture": "#0"}, + "down": {"uv": [0.5, 2, 15.5, 3], "rotation": 180, "texture": "#0"} + } + }, + { + "name": "Box3", + "from": [14, 3, 0], + "to": [15.5, 13, 0.5], + "faces": { + "north": {"uv": [0.5, 3, 2, 13], "texture": "#0"}, + "west": {"uv": [1, 3, 2, 13], "texture": "#0"} + } + }, + { + "name": "Box4", + "from": [0.5, 3, 0], + "to": [3, 13, 0.5], + "faces": { + "north": {"uv": [13, 3, 15.5, 13], "texture": "#0"}, + "east": {"uv": [14, 3, 13, 13], "texture": "#0"} + } + }, + { + "name": "Box5", + "from": [5, 3, 0], + "to": [7, 13, 0.5], + "faces": { + "north": {"uv": [9, 3, 11, 13], "texture": "#0"}, + "east": {"uv": [10, 3, 9, 13], "texture": "#0"}, + "west": {"uv": [11, 3, 10, 13], "texture": "#0"} + } + }, + { + "name": "Box6", + "from": [7, 5.5, 0], + "to": [14, 6.5, 0.5], + "faces": { + "north": {"uv": [2, 9.5, 9, 10.5], "texture": "#0"}, + "up": {"uv": [2, 10.5, 9, 9.5], "rotation": 180, "texture": "#0"}, + "down": {"uv": [2, 10.5, 9, 9.5], "rotation": 180, "texture": "#0"} + } + }, + { + "name": "Box6", + "from": [7, 9.5, 0], + "to": [14, 10.5, 0.5], + "faces": { + "north": {"uv": [2, 5.5, 9, 6.5], "texture": "#0"}, + "up": {"uv": [2, 6.5, 9, 5.5], "rotation": 180, "texture": "#0"}, + "down": {"uv": [2, 6.5, 9, 5.5], "rotation": 180, "texture": "#0"} + } + }, + { + "name": "Box8", + "from": [2.75, 2.75, 0.5], + "to": [5.25, 13.25, 3], + "faces": { + "north": {"uv": [10.75, 2.75, 13.25, 13.25], "texture": "#0"} + } + }, + { + "name": "Box9", + "from": [7, 3, 0.5], + "to": [14, 13, 0.6], + "faces": { + "north": {"uv": [2, 3, 9, 13], "texture": "#0"}, + "east": {"uv": [2, 3, 9, 13], "texture": "#0"}, + "south": {"uv": [2, 3, 9, 13], "texture": "#0"}, + "west": {"uv": [2, 3, 9, 13], "texture": "#0"}, + "up": {"uv": [2, 3, 9, 13], "texture": "#0"}, + "down": {"uv": [2, 3, 9, 13], "texture": "#0"} + } + } + ], + "groups": [ + { + "name": "group", + "origin": [0, 0, 0], + "color": 0, + "children": [0, 1, 2, 3, 4, 5, 6, 7, 8] + } + ] +} \ No newline at end of file diff --git a/src/main/resources/assets/enderio/textures/block/wired_charger_front.png b/src/main/resources/assets/enderio/textures/block/wired_charger_front.png new file mode 100644 index 0000000000000000000000000000000000000000..10e4c0e1960b354b65ade79709cf8c966729ca7b GIT binary patch literal 1360 zcmV-W1+V&vP)N2bZe?^J zG%heMGBNQWX_Wu~1kFiAK~zXfwU*m&+f*39`71!BYswIN*aj+_TH5uJ8%gXs7u%^F zJ5KDlaV~AsByH|(y0%#_Yf;4*-H<>-Fc6nY2#L$!VWL6^L^TN{E@EiXo+crlEB*jJ z`*TV%^@+Bhehz zC;&qqsHf*R1n@#A;JHHtu0R05f;`n8Pqu{F)r?R=0|-$d!s6*OXAa0L%w_5|zbFF7 zCOCh#=iK=hUwHn)*>gRI2poPNFcwpQj%GYUA9=u={)fD@TA+&FE?gv&#t7KyZo- zxb-&>$&ny2!UpVP#2}L>6yt@0m*)W+Ndj#GT8<)|3cEoGX>lE++?bJ$L=b!=#jsb3 zGERwgMp;KRU=OED)nuX6Ca_WzfZKM*~%L#Zz z9RcyIGq43!?`A#zwYkFq|X_FZ4A?Iv9PiX1cXQ^mfF;Ati@k%#I9dW z+|&hyD#5bA5J3P(63}5;P$zC=ZeN?YwUxScE&WbzzL9!N&}X*+q`(1YQJV3r5!gnt znciXv#Z`cjWFbEJR&Hl|>Vxgc58ue_{|RuCQGiPx;2~FB#offiqoRaV6=0(gM1LF~ zXT+G4%ziSr`*CG=r?&fE{_Dz>&HVgjr{C}N`34*gpiN-Dzr}(T$KtexISeH-1Z-H1 zq;hwbe*CPy_to;fPpjWoS6`W_FSQ9Sx!nMM@XTLZELd@j)*f>Qc6Bk42m@O>tjMYS z-NrB9to(NGwcqbHel0aNveg9-!+2==r~)`J7*SEuGe2xR{C4%hZsY!U>krCTHl{0e zqE$rEG&^Qi3X#4N3;v26}_c0%@`EC=PdGFABb)xYx&3mK2kjTy-&5TgufI zvz2-}TNt0twFz*NT{I0~p-_WLufXdV$1nEdF@U%O0Ud_+Ff=sa@_;=y3T~m4dGR_1 z0j-0_!yy8^qT-R)Z-CbgoP2EKM+rY5c)i7boJKsBF&*{{7+kbkffE*3t^Wc~;%k*Y STU?s}0000 Date: Thu, 29 Jun 2023 14:32:03 +0200 Subject: [PATCH 2/4] Wrapped with canAct method --- .../recipes/misc/wired_charger.json | 2 +- .../blockentity/WiredChargerBlockEntity.java | 57 ++++++++++--------- 2 files changed, 30 insertions(+), 29 deletions(-) diff --git a/src/generated/resources/data/enderio/advancements/recipes/misc/wired_charger.json b/src/generated/resources/data/enderio/advancements/recipes/misc/wired_charger.json index ecf93d411a..2d68db3155 100644 --- a/src/generated/resources/data/enderio/advancements/recipes/misc/wired_charger.json +++ b/src/generated/resources/data/enderio/advancements/recipes/misc/wired_charger.json @@ -15,7 +15,7 @@ }, "has_the_recipe": { "conditions": { - "recipe": "enderio:sag_mill" + "recipe": "enderio:wired_charger" }, "trigger": "minecraft:recipe_unlocked" } diff --git a/src/machines/java/com/enderio/machines/common/blockentity/WiredChargerBlockEntity.java b/src/machines/java/com/enderio/machines/common/blockentity/WiredChargerBlockEntity.java index 481ecff00f..c271c120e5 100644 --- a/src/machines/java/com/enderio/machines/common/blockentity/WiredChargerBlockEntity.java +++ b/src/machines/java/com/enderio/machines/common/blockentity/WiredChargerBlockEntity.java @@ -25,21 +25,18 @@ public class WiredChargerBlockEntity extends PoweredMachineEntity { public static final QuadraticScalable CAPACITY = new QuadraticScalable(CapacitorModifier.ENERGY_CAPACITY, () -> 100000f); - public static final QuadraticScalable TRANSFER = new QuadraticScalable(CapacitorModifier.ENERGY_TRANSFER, () -> 100000f); public static final QuadraticScalable USAGE = new QuadraticScalable(CapacitorModifier.ENERGY_USE, () -> 100f); public static final SingleSlotAccess ITEM_TO_CHARGE = new SingleSlotAccess(); - public static final SingleSlotAccess ITEM_CHARGED = new SingleSlotAccess(); private float progress = 0; public WiredChargerBlockEntity(BlockEntityType type, BlockPos worldPosition, BlockState blockState) { - super(EnergyIOMode.Input, CAPACITY, TRANSFER, USAGE, type, worldPosition, blockState); + super(EnergyIOMode.Input, CAPACITY, USAGE, type, worldPosition, blockState); addDataSlot(new FloatDataSlot(this::getProgress, p -> progress = p, SyncMode.GUI)); } - @Override public MachineInventoryLayout getInventoryLayout() { return MachineInventoryLayout @@ -52,7 +49,6 @@ public MachineInventoryLayout getInventoryLayout() { .build(); } - @Nullable @Override public AbstractContainerMenu createMenu(int pContainerId, Inventory pPlayerInventory, Player pPlayer) { @@ -62,39 +58,44 @@ public AbstractContainerMenu createMenu(int pContainerId, Inventory pPlayerInven @Override public void serverTick() { super.serverTick(); - chargeItem(); + if (canAct()) { + chargeItem(); + } else { + this.progress = 0; + } } - public boolean acceptItem(ItemStack item) { Optional energyHandlerCap = item.getCapability(ForgeCapabilities.ENERGY).resolve(); return energyHandlerCap.isPresent(); } - - public void chargeItem() { + + @Override + public boolean canAct() { ItemStack inputItem = ITEM_TO_CHARGE.getItemStack(this); ItemStack outputItem = ITEM_CHARGED.getItemStack(this); - if (!inputItem.isEmpty() && outputItem.isEmpty() && isCapacitorInstalled()) { - Optional energyHandlerCap = inputItem.getCapability(ForgeCapabilities.ENERGY).resolve(); - if (energyHandlerCap.isPresent()) { - IEnergyStorage itemEnergyStorage = energyHandlerCap.get(); - if (itemEnergyStorage.getEnergyStored() == itemEnergyStorage.getMaxEnergyStored()) { - ITEM_CHARGED.setStackInSlot(this, inputItem); - ITEM_TO_CHARGE.setStackInSlot(this, ItemStack.EMPTY); - } else { - // The energyExtracted per tick should increase if the charged item has more energy and with the tiers of the capacitor installed - int energyExtracted = itemEnergyStorage.getMaxEnergyStored() / (1000-this.energyStorage.getMaxEnergyUse()); - if (canAct() && this.energyStorage.getEnergyStored() >= energyExtracted) { - itemEnergyStorage.receiveEnergy(energyExtracted, false); - this.energyStorage.takeEnergy(energyExtracted); - this.progress = (float)itemEnergyStorage.getEnergyStored()/itemEnergyStorage.getMaxEnergyStored(); - } - } + return !inputItem.isEmpty() && outputItem.isEmpty() && acceptItem(inputItem) && super.canAct(); + } + + public void chargeItem() { + ItemStack chargeable = ITEM_TO_CHARGE.getItemStack(this); + Optional energyHandlerCap = chargeable.getCapability(ForgeCapabilities.ENERGY).resolve(); + + if (energyHandlerCap.isPresent()) { + IEnergyStorage itemEnergyStorage = energyHandlerCap.get(); + if (itemEnergyStorage.getEnergyStored() == itemEnergyStorage.getMaxEnergyStored()) { + ITEM_CHARGED.setStackInSlot(this, chargeable); + ITEM_TO_CHARGE.setStackInSlot(this, ItemStack.EMPTY); } else { - this.progress = 0; + // The energyExtracted per tick should increase if the charged item has more energy and with the tier of the capacitor installed + int energyExtracted = itemEnergyStorage.getMaxEnergyStored() / (1000-this.energyStorage.getMaxEnergyUse()); + + if (this.energyStorage.getEnergyStored() >= energyExtracted) { + itemEnergyStorage.receiveEnergy(energyExtracted, false); + this.energyStorage.takeEnergy(energyExtracted); + this.progress = (float)itemEnergyStorage.getEnergyStored()/itemEnergyStorage.getMaxEnergyStored(); + } } - } else { - this.progress = 0; } } From f1f178023e4a007c67e33d7057fa4556e0740bf6 Mon Sep 17 00:00:00 2001 From: Trytoon Date: Tue, 11 Jul 2023 12:20:51 +0200 Subject: [PATCH 3/4] Fixed the wired charger for the alpha version codebase --- CHANGELOG.md | 1 + .../enderio/blockstates/wired_charger.json | 35 ++++++++++++++++--- .../recipes/misc/wired_charger.json | 2 +- .../data/enderio/recipes/wired_charger.json | 10 +++--- .../client/gui/screen/WiredChargerScreen.java | 6 +++- .../blockentity/WiredChargerBlockEntity.java | 20 +++++++---- .../common/config/common/EnergyConfig.java | 7 ++++ .../common/init/MachineBlockEntities.java | 2 -- .../machines/common/init/MachineBlocks.java | 10 ++---- 9 files changed, 66 insertions(+), 27 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a386c0a9c8..4e087f1f72 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ ### Added - Better multismelting support for the alloy smelter +- Wired Charger ### Changed - Conduits are now placed in your inventory when shift right clicked with the Yeta Wrench diff --git a/src/generated/resources/assets/enderio/blockstates/wired_charger.json b/src/generated/resources/assets/enderio/blockstates/wired_charger.json index d414613402..ecf0ea0368 100644 --- a/src/generated/resources/assets/enderio/blockstates/wired_charger.json +++ b/src/generated/resources/assets/enderio/blockstates/wired_charger.json @@ -1,7 +1,34 @@ { - "variants": { - "": { - "model": "enderio:block/wired_charger" + "variants": { + "facing=east,powered=false": { + "model": "enderio:block/wired_charger", + "y": 90 + }, + "facing=east,powered=true": { + "model": "enderio:block/wired_charger", + "y": 90 + }, + "facing=north,powered=false": { + "model": "enderio:block/wired_charger" + }, + "facing=north,powered=true": { + "model": "enderio:block/wired_charger" + }, + "facing=south,powered=false": { + "model": "enderio:block/wired_charger", + "y": 180 + }, + "facing=south,powered=true": { + "model": "enderio:block/wired_charger", + "y": 180 + }, + "facing=west,powered=false": { + "model": "enderio:block/wired_charger", + "y": 270 + }, + "facing=west,powered=true": { + "model": "enderio:block/wired_charger", + "y": 270 + } } - } } \ No newline at end of file diff --git a/src/generated/resources/data/enderio/advancements/recipes/misc/wired_charger.json b/src/generated/resources/data/enderio/advancements/recipes/misc/wired_charger.json index 2d68db3155..5ee6fcdf03 100644 --- a/src/generated/resources/data/enderio/advancements/recipes/misc/wired_charger.json +++ b/src/generated/resources/data/enderio/advancements/recipes/misc/wired_charger.json @@ -6,7 +6,7 @@ "items": [ { "items": [ - "enderio:wired_charger" + "enderio:void_chassis" ] } ] diff --git a/src/generated/resources/data/enderio/recipes/wired_charger.json b/src/generated/resources/data/enderio/recipes/wired_charger.json index 684a127f23..bc0bf6a52b 100644 --- a/src/generated/resources/data/enderio/recipes/wired_charger.json +++ b/src/generated/resources/data/enderio/recipes/wired_charger.json @@ -2,17 +2,17 @@ "type": "minecraft:crafting_shaped", "category": "misc", "key": { - "E": { - "item": "enderio:electrical_steel_ingot" + "D": { + "item": "enderio:dark_steel_ingot" }, "V": { "item": "enderio:void_chassis" } }, "pattern": [ - "EEE", - "EVE", - "EEE" + "DDD", + "DVD", + "DDD" ], "result": { "item": "enderio:wired_charger" diff --git a/src/machines/java/com/enderio/machines/client/gui/screen/WiredChargerScreen.java b/src/machines/java/com/enderio/machines/client/gui/screen/WiredChargerScreen.java index a106069426..20e7ff84e6 100644 --- a/src/machines/java/com/enderio/machines/client/gui/screen/WiredChargerScreen.java +++ b/src/machines/java/com/enderio/machines/client/gui/screen/WiredChargerScreen.java @@ -5,8 +5,10 @@ import com.enderio.base.common.lang.EIOLang; import com.enderio.core.client.gui.screen.EIOScreen; import com.enderio.core.client.gui.widgets.EnumIconWidget; +import com.enderio.machines.client.gui.widget.CapacitorEnergyWidget; import com.enderio.machines.client.gui.widget.EnergyWidget; import com.enderio.machines.client.gui.widget.ProgressWidget; +import com.enderio.machines.client.gui.widget.ioconfig.IOConfigButton; import com.enderio.machines.common.menu.WiredChargerMenu; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; @@ -25,10 +27,12 @@ protected void init() { addRenderableOnly(new ProgressWidget.BottomUp(this, () -> menu.getBlockEntity().getProgress(), getGuiLeft() + 103, getGuiTop() + 18, 12, 36, 242, 1)); - addRenderableOnly(new EnergyWidget(this, getMenu().getBlockEntity()::getEnergyStorage, 37 + leftPos, 14 + topPos, 9, 43)); + addRenderableOnly(new CapacitorEnergyWidget(this, getMenu().getBlockEntity()::getEnergyStorage, menu.getBlockEntity()::isCapacitorInstalled, 37 + leftPos, 14 + topPos, 9, 42)); addRenderableWidget(new EnumIconWidget<>(this, leftPos + imageWidth - 8 - 12, topPos + 6, () -> menu.getBlockEntity().getRedstoneControl(), control -> menu.getBlockEntity().setRedstoneControl(control), EIOLang.REDSTONE_MODE)); + + addRenderableWidget(new IOConfigButton<>(this, leftPos + imageWidth - 6 - 16, topPos + 22, 16, 16, menu, this::addRenderableWidget, font)); } @Override diff --git a/src/machines/java/com/enderio/machines/common/blockentity/WiredChargerBlockEntity.java b/src/machines/java/com/enderio/machines/common/blockentity/WiredChargerBlockEntity.java index c271c120e5..45e1e3df36 100644 --- a/src/machines/java/com/enderio/machines/common/blockentity/WiredChargerBlockEntity.java +++ b/src/machines/java/com/enderio/machines/common/blockentity/WiredChargerBlockEntity.java @@ -3,9 +3,9 @@ import com.enderio.api.capacitor.CapacitorModifier; import com.enderio.api.capacitor.QuadraticScalable; import com.enderio.api.io.energy.EnergyIOMode; -import com.enderio.core.common.sync.FloatDataSlot; -import com.enderio.core.common.sync.SyncMode; -import com.enderio.machines.common.blockentity.base.PoweredMachineEntity; +import com.enderio.core.common.network.slot.FloatNetworkDataSlot; +import com.enderio.machines.common.blockentity.base.PoweredMachineBlockEntity; +import com.enderio.machines.common.config.MachinesConfig; import com.enderio.machines.common.io.item.MachineInventoryLayout; import com.enderio.machines.common.io.item.SingleSlotAccess; import com.enderio.machines.common.menu.WiredChargerMenu; @@ -22,10 +22,10 @@ import java.util.Optional; -public class WiredChargerBlockEntity extends PoweredMachineEntity { +public class WiredChargerBlockEntity extends PoweredMachineBlockEntity { - public static final QuadraticScalable CAPACITY = new QuadraticScalable(CapacitorModifier.ENERGY_CAPACITY, () -> 100000f); - public static final QuadraticScalable USAGE = new QuadraticScalable(CapacitorModifier.ENERGY_USE, () -> 100f); + public static final QuadraticScalable CAPACITY = new QuadraticScalable(CapacitorModifier.ENERGY_CAPACITY, MachinesConfig.COMMON.ENERGY.WIRED_CHARGER_CAPACITY); + public static final QuadraticScalable USAGE = new QuadraticScalable(CapacitorModifier.ENERGY_USE, MachinesConfig.COMMON.ENERGY.WIRED_CHARGER_USAGE); public static final SingleSlotAccess ITEM_TO_CHARGE = new SingleSlotAccess(); public static final SingleSlotAccess ITEM_CHARGED = new SingleSlotAccess(); @@ -34,7 +34,7 @@ public class WiredChargerBlockEntity extends PoweredMachineEntity { public WiredChargerBlockEntity(BlockEntityType type, BlockPos worldPosition, BlockState blockState) { super(EnergyIOMode.Input, CAPACITY, USAGE, type, worldPosition, blockState); - addDataSlot(new FloatDataSlot(this::getProgress, p -> progress = p, SyncMode.GUI)); + addDataSlot(new FloatNetworkDataSlot(this::getProgress, p -> progress = p)); } @Override @@ -65,6 +65,11 @@ public void serverTick() { } } + @Override + protected boolean isActive() { + return canAct(); + } + public boolean acceptItem(ItemStack item) { Optional energyHandlerCap = item.getCapability(ForgeCapabilities.ENERGY).resolve(); return energyHandlerCap.isPresent(); @@ -87,6 +92,7 @@ public void chargeItem() { ITEM_CHARGED.setStackInSlot(this, chargeable); ITEM_TO_CHARGE.setStackInSlot(this, ItemStack.EMPTY); } else { + //todo energy balancing // The energyExtracted per tick should increase if the charged item has more energy and with the tier of the capacitor installed int energyExtracted = itemEnergyStorage.getMaxEnergyStored() / (1000-this.energyStorage.getMaxEnergyUse()); diff --git a/src/machines/java/com/enderio/machines/common/config/common/EnergyConfig.java b/src/machines/java/com/enderio/machines/common/config/common/EnergyConfig.java index 9b17553d5f..bb27682cc7 100644 --- a/src/machines/java/com/enderio/machines/common/config/common/EnergyConfig.java +++ b/src/machines/java/com/enderio/machines/common/config/common/EnergyConfig.java @@ -27,6 +27,8 @@ public class EnergyConfig { public final ForgeConfigSpec.ConfigValue BASIC_SOLAR_PANEL_MAX_PRODUCTION; public final ForgeConfigSpec.ConfigValue ADVANCED_SOLAR_PANEL_MAX_PRODUCTION; public final ForgeConfigSpec.ConfigValue VIBRANT_SOLAR_PANEL_MAX_PRODUCTION; + public final ForgeConfigSpec.ConfigValue WIRED_CHARGER_CAPACITY; + public final ForgeConfigSpec.ConfigValue WIRED_CHARGER_USAGE; public EnergyConfig(ForgeConfigSpec.Builder builder) { builder.push("energy"); @@ -87,6 +89,11 @@ public EnergyConfig(ForgeConfigSpec.Builder builder) { VIBRANT_SOLAR_PANEL_MAX_PRODUCTION = builder.defineInRange("vibrant", 160, 1, Integer.MAX_VALUE); builder.pop(); + builder.push("wiredCharger"); + WIRED_CHARGER_CAPACITY = builder.comment("The base energy capacity in uI.").defineInRange("capacity", 100000, 1, Integer.MAX_VALUE); + WIRED_CHARGER_USAGE = builder.comment("The base energy consumption in uI/t.").defineInRange("usage", 100, 1, Integer.MAX_VALUE); + builder.pop(); + builder.pop(); } } diff --git a/src/machines/java/com/enderio/machines/common/init/MachineBlockEntities.java b/src/machines/java/com/enderio/machines/common/init/MachineBlockEntities.java index 0a6695df2e..b6062d646f 100644 --- a/src/machines/java/com/enderio/machines/common/init/MachineBlockEntities.java +++ b/src/machines/java/com/enderio/machines/common/init/MachineBlockEntities.java @@ -55,8 +55,6 @@ public class MachineBlockEntities { public static final BlockEntityEntry SOUL_BINDER = register("soul_binder", SoulBinderBlockEntity::new, MachineBlocks.SOUL_BINDER); - public static final BlockEntityEntry POWERED_SPAWNER = register("powered_spanwer", PoweredSpawnerBlockEntity::new, MachineBlocks.POWERED_SPAWNER); - public static final BlockEntityEntry WIRED_CHARGER = register("wired_charger", WiredChargerBlockEntity::new, MachineBlocks.WIRED_CHARGER); diff --git a/src/machines/java/com/enderio/machines/common/init/MachineBlocks.java b/src/machines/java/com/enderio/machines/common/init/MachineBlocks.java index df033d1c0e..7aff20f735 100644 --- a/src/machines/java/com/enderio/machines/common/init/MachineBlocks.java +++ b/src/machines/java/com/enderio/machines/common/init/MachineBlocks.java @@ -123,15 +123,11 @@ public class MachineBlocks { public static final BlockEntry PAINTING_MACHINE = standardMachine("painting_machine", () -> MachineBlockEntities.PAINTING_MACHINE) .register(); - public static final BlockEntry CREATIVE_POWER = REGISTRATE - .block("creative_power", props -> new MachineBlock(props, MachineBlockEntities.CREATIVE_POWER)) - .item() - .tab(EIOCreativeTabs.MACHINES) - .build() + public static final BlockEntry WIRED_CHARGER = standardMachine("wired_charger", () -> MachineBlockEntities.WIRED_CHARGER) .register(); - public static final BlockEntry WIRED_CHARGER = REGISTRATE - .block("wired_charger", props -> new MachineBlock(props, MachineBlockEntities.WIRED_CHARGER)) + public static final BlockEntry CREATIVE_POWER = REGISTRATE + .block("creative_power", props -> new MachineBlock(props, MachineBlockEntities.CREATIVE_POWER)) .item() .tab(EIOCreativeTabs.MACHINES) .build() From cc2e93174da79cca66d8f304e39263dcaa7059bf Mon Sep 17 00:00:00 2001 From: Trytoon Date: Thu, 13 Jul 2023 17:58:24 +0200 Subject: [PATCH 4/4] Added the armor display + some datagen + added insets to the IOConfigWidget --- .../enderio/core/common/menu/SyncedMenu.java | 34 ++++++++++ .../enderio/blockstates/wired_charger.json | 62 +++++++++---------- .../resources/assets/enderio/lang/en_ud.json | 9 +-- .../models/block/wired_charger_front_on.json | 6 ++ .../models/block/wired_charger_on.json | 26 ++++++++ .../data/enderio/recipes/wired_charger.json | 10 +-- .../tags/blocks/mineable/pickaxe.json | 1 + .../tags/blocks/needs_iron_tool.json | 1 + .../client/gui/screen/WiredChargerScreen.java | 5 +- .../blockentity/WiredChargerBlockEntity.java | 2 +- .../common/config/common/EnergyConfig.java | 2 +- .../common/menu/WiredChargerMenu.java | 14 ++++- .../data/recipes/MachineRecipeProvider.java | 15 +++++ 13 files changed, 138 insertions(+), 49 deletions(-) create mode 100644 src/generated/resources/assets/enderio/models/block/wired_charger_front_on.json create mode 100644 src/generated/resources/assets/enderio/models/block/wired_charger_on.json diff --git a/src/core/java/com/enderio/core/common/menu/SyncedMenu.java b/src/core/java/com/enderio/core/common/menu/SyncedMenu.java index e0f9959826..0d7cd9973a 100644 --- a/src/core/java/com/enderio/core/common/menu/SyncedMenu.java +++ b/src/core/java/com/enderio/core/common/menu/SyncedMenu.java @@ -1,15 +1,24 @@ package com.enderio.core.common.menu; import com.enderio.core.common.blockentity.EnderBlockEntity; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.entity.EquipmentSlot; import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.entity.player.Player; import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.inventory.InventoryMenu; import net.minecraft.world.inventory.MenuType; import net.minecraft.world.inventory.Slot; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.enchantment.EnchantmentHelper; import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.List; +import static net.minecraft.world.inventory.InventoryMenu.*; +import static net.minecraft.world.inventory.InventoryMenu.EMPTY_ARMOR_SLOT_HELMET; + public abstract class SyncedMenu extends AbstractContainerMenu { @Nullable @@ -18,6 +27,9 @@ public abstract class SyncedMenu extends AbstractCon private final List playerInventorySlots = new ArrayList<>(); private boolean playerInvVisible = true; + + private static final ResourceLocation[] ARMOR_SLOT_TEXTURES = new ResourceLocation[] { EMPTY_ARMOR_SLOT_BOOTS, EMPTY_ARMOR_SLOT_LEGGINGS, EMPTY_ARMOR_SLOT_CHESTPLATE, EMPTY_ARMOR_SLOT_HELMET }; + private static final EquipmentSlot[] EQUIPMENT_SLOTS = new EquipmentSlot[] { EquipmentSlot.HEAD, EquipmentSlot.CHEST, EquipmentSlot.LEGS, EquipmentSlot.FEET }; protected SyncedMenu(@Nullable T blockEntity, Inventory inventory, @Nullable MenuType pMenuType, int pContainerId) { super(pMenuType, pContainerId); this.blockEntity = blockEntity; @@ -48,6 +60,28 @@ public void addInventorySlots(int xPos, int yPos) { } } + public void addArmorSlots(int xPos, int Ypos) { + for (int i = 0; i < 4; i++) { + EquipmentSlot slot = EQUIPMENT_SLOTS[i]; + this.addSlot(new Slot(inventory, 36 + (3 - i), xPos, Ypos + i * 18) { + @Override + public int getMaxStackSize() { + return 1; + } + + @Override + public boolean mayPlace(ItemStack stack) { + return stack.canEquip(slot, inventory.player); + } + + @Override + public boolean mayPickup(Player player) { + ItemStack itemstack = this.getItem(); + return super.mayPickup(player) && !EnchantmentHelper.hasBindingCurse(itemstack); + } + }.setBackground(InventoryMenu.BLOCK_ATLAS, ARMOR_SLOT_TEXTURES[slot.getIndex()])); + } + } public boolean getPlayerInvVisible() { return playerInvVisible; diff --git a/src/generated/resources/assets/enderio/blockstates/wired_charger.json b/src/generated/resources/assets/enderio/blockstates/wired_charger.json index ecf0ea0368..0ba24b009a 100644 --- a/src/generated/resources/assets/enderio/blockstates/wired_charger.json +++ b/src/generated/resources/assets/enderio/blockstates/wired_charger.json @@ -1,34 +1,34 @@ { - "variants": { - "facing=east,powered=false": { - "model": "enderio:block/wired_charger", - "y": 90 - }, - "facing=east,powered=true": { - "model": "enderio:block/wired_charger", - "y": 90 - }, - "facing=north,powered=false": { - "model": "enderio:block/wired_charger" - }, - "facing=north,powered=true": { - "model": "enderio:block/wired_charger" - }, - "facing=south,powered=false": { - "model": "enderio:block/wired_charger", - "y": 180 - }, - "facing=south,powered=true": { - "model": "enderio:block/wired_charger", - "y": 180 - }, - "facing=west,powered=false": { - "model": "enderio:block/wired_charger", - "y": 270 - }, - "facing=west,powered=true": { - "model": "enderio:block/wired_charger", - "y": 270 - } + "variants": { + "facing=east,powered=false": { + "model": "enderio:block/wired_charger", + "y": 90 + }, + "facing=east,powered=true": { + "model": "enderio:block/wired_charger_on", + "y": 90 + }, + "facing=north,powered=false": { + "model": "enderio:block/wired_charger" + }, + "facing=north,powered=true": { + "model": "enderio:block/wired_charger_on" + }, + "facing=south,powered=false": { + "model": "enderio:block/wired_charger", + "y": 180 + }, + "facing=south,powered=true": { + "model": "enderio:block/wired_charger_on", + "y": 180 + }, + "facing=west,powered=false": { + "model": "enderio:block/wired_charger", + "y": 270 + }, + "facing=west,powered=true": { + "model": "enderio:block/wired_charger_on", + "y": 270 } + } } \ No newline at end of file diff --git a/src/generated/resources/assets/enderio/lang/en_ud.json b/src/generated/resources/assets/enderio/lang/en_ud.json index 2858798b32..6d0f5a3fbf 100644 --- a/src/generated/resources/assets/enderio/lang/en_ud.json +++ b/src/generated/resources/assets/enderio/lang/en_ud.json @@ -816,16 +816,9 @@ "block.enderio.vibrant_capacitor_bank": "ʞuɐᗺ ɹoʇıɔɐdɐƆ ʇuɐɹqıΛ", "block.enderio.vibrant_photovoltaic_cell": "ןןǝƆ ɔıɐʇןoʌoʇoɥԀ ʇuɐɹqıΛ", "block.enderio.void_chassis": "sıssɐɥƆ pıoΛ", + "block.enderio.wired_charger": "ɹǝbɹɐɥƆ pǝɹıM", "block.enderio.xp_juice": "ǝɔınſ dX", "block.enderio.xp_vacuum": "ɯnnɔɐΛ dX", - "block.enderio.wired_charger": "ʌɹıǝW ɹǝɔɔɐƃ", - "description.enderio.enchantment.auto_smelt": "pǝuıɯ sı ɹǝʌǝʇɐɥʍ sǝʇןǝɯs ʎןןɐɔıʇɐɯoʇnⱯ", - "description.enderio.enchantment.repellent": "ɹǝɥʇɹɐɟ puɐ uǝʇɟo ǝɹoɯ ʇɹodǝןǝʇ sןǝʌǝן ɹǝɥbıH\nʎɐʍɐ sɹǝʞɔɐʇʇɐ ʇɹodǝןǝʇ oʇ ǝɔuɐɥƆ", - "description.enderio.enchantment.shimmer": "˙ʍouʞ I\n˙ssǝןǝsn sı ʇı 'sǝʎ\n˙ǝɹoɯ buıɥʇoN\n˙ʎןןɐǝᴚ\n˙ןןɐ s,ʇɐɥ⟘\n˙pǝʇuɐɥɔuǝ sɐʍ ʇı ɟı sɐ ɹǝɯɯıɥs ɯǝʇı ǝɥʇ sǝʞɐW", - "description.enderio.enchantment.soulbound": "¡buıʞɹoʍ ɯoɹɟ sıɥʇ ʇuǝʌǝɹd puɐ pıdnʇs ǝɹɐ spoɯ ǝuoʇsǝʌɐɹb ʇsoW :ǝʇoN\n˙ɥʇɐǝp uo ʇsoן buıǝq ɯoɹɟ ɯǝʇı sʇuǝʌǝɹԀ", - "description.enderio.enchantment.withering_arrow": "˙sʍoq oʇ sǝıןddⱯ\nʇǝbɹɐʇ ǝɥʇ oʇ ɹǝɥʇıʍ sǝıןddⱯ", - "description.enderio.enchantment.withering_blade": "suodɐǝʍ pǝpɐןq oʇ sǝıןddⱯ\nʇǝbɹɐʇ ǝɥʇ oʇ ɹǝɥʇıʍ sǝıןddⱯ", - "description.enderio.enchantment.withering_bolt": "˙sʍoqssoɹɔ oʇ sǝıןddⱯ\nʇǝbɹɐʇ ǝɥʇ oʇ ɹǝɥʇıʍ sǝıןddⱯ", "description.enderio.enchantment.auto_smelt": "pǝuıɯ sı ɹǝʌǝʇɐɥʍ sʇןǝɯs ʎןןɐɔıʇɐɯoʇnⱯ", "description.enderio.enchantment.repellent1": "ʎɐʍɐ sɹǝʞɔɐʇʇɐ ʇɹodǝןǝʇ oʇ ǝɔuɐɥƆ", "description.enderio.enchantment.repellent2": "ɹǝɥʇɹɐɟ puɐ uǝʇɟo ǝɹoɯ ʇɹodǝןǝʇ sןǝʌǝן ɹǝɥbıH", diff --git a/src/generated/resources/assets/enderio/models/block/wired_charger_front_on.json b/src/generated/resources/assets/enderio/models/block/wired_charger_front_on.json new file mode 100644 index 0000000000..b897ebc1af --- /dev/null +++ b/src/generated/resources/assets/enderio/models/block/wired_charger_front_on.json @@ -0,0 +1,6 @@ +{ + "parent": "enderio:block/wired_charger_front", + "textures": { + "front": "enderio:block/wired_charger_front" + } +} \ No newline at end of file diff --git a/src/generated/resources/assets/enderio/models/block/wired_charger_on.json b/src/generated/resources/assets/enderio/models/block/wired_charger_on.json new file mode 100644 index 0000000000..717d92e9cf --- /dev/null +++ b/src/generated/resources/assets/enderio/models/block/wired_charger_on.json @@ -0,0 +1,26 @@ +{ + "parent": "minecraft:block/block", + "children": { + "frame": { + "parent": "enderio:block/machine_frame" + }, + "front": { + "parent": "enderio:block/wired_charger_front", + "textures": { + "front": "enderio:block/wired_charger_front_on" + } + }, + "overlay": { + "parent": "enderio:block/io_overlay" + } + }, + "item_render_order": [ + "frame", + "overlay", + "front" + ], + "loader": "forge:composite", + "textures": { + "particle": "enderio:block/machine_side" + } +} \ No newline at end of file diff --git a/src/generated/resources/data/enderio/recipes/wired_charger.json b/src/generated/resources/data/enderio/recipes/wired_charger.json index bc0bf6a52b..3fa20d1ac0 100644 --- a/src/generated/resources/data/enderio/recipes/wired_charger.json +++ b/src/generated/resources/data/enderio/recipes/wired_charger.json @@ -2,17 +2,17 @@ "type": "minecraft:crafting_shaped", "category": "misc", "key": { - "D": { - "item": "enderio:dark_steel_ingot" + "C": { + "item": "enderio:copper_alloy_ingot" }, "V": { "item": "enderio:void_chassis" } }, "pattern": [ - "DDD", - "DVD", - "DDD" + "CCC", + "CVC", + "CCC" ], "result": { "item": "enderio:wired_charger" diff --git a/src/generated/resources/data/minecraft/tags/blocks/mineable/pickaxe.json b/src/generated/resources/data/minecraft/tags/blocks/mineable/pickaxe.json index 3e54f2931c..021f91b3a5 100644 --- a/src/generated/resources/data/minecraft/tags/blocks/mineable/pickaxe.json +++ b/src/generated/resources/data/minecraft/tags/blocks/mineable/pickaxe.json @@ -38,6 +38,7 @@ "enderio:primitive_alloy_smelter", "enderio:alloy_smelter", "enderio:painting_machine", + "enderio:wired_charger", "enderio:stirling_generator", "enderio:sag_mill", "enderio:impulse_hopper", diff --git a/src/generated/resources/data/minecraft/tags/blocks/needs_iron_tool.json b/src/generated/resources/data/minecraft/tags/blocks/needs_iron_tool.json index ab7ab8dfb4..24941caed3 100644 --- a/src/generated/resources/data/minecraft/tags/blocks/needs_iron_tool.json +++ b/src/generated/resources/data/minecraft/tags/blocks/needs_iron_tool.json @@ -9,6 +9,7 @@ "enderio:primitive_alloy_smelter", "enderio:alloy_smelter", "enderio:painting_machine", + "enderio:wired_charger", "enderio:stirling_generator", "enderio:sag_mill", "enderio:impulse_hopper", diff --git a/src/machines/java/com/enderio/machines/client/gui/screen/WiredChargerScreen.java b/src/machines/java/com/enderio/machines/client/gui/screen/WiredChargerScreen.java index 20e7ff84e6..387cfaa6fc 100644 --- a/src/machines/java/com/enderio/machines/client/gui/screen/WiredChargerScreen.java +++ b/src/machines/java/com/enderio/machines/client/gui/screen/WiredChargerScreen.java @@ -32,7 +32,8 @@ protected void init() { addRenderableWidget(new EnumIconWidget<>(this, leftPos + imageWidth - 8 - 12, topPos + 6, () -> menu.getBlockEntity().getRedstoneControl(), control -> menu.getBlockEntity().setRedstoneControl(control), EIOLang.REDSTONE_MODE)); - addRenderableWidget(new IOConfigButton<>(this, leftPos + imageWidth - 6 - 16, topPos + 22, 16, 16, menu, this::addRenderableWidget, font)); + var inset = new IOConfigButton.Inset(21,0, 0, 0); + addRenderableWidget(new IOConfigButton<>(this, leftPos + imageWidth - 6 - 16, topPos + 22, 16, 16, menu, this::addRenderableWidget, font, inset)); } @Override @@ -42,6 +43,6 @@ public ResourceLocation getBackgroundImage() { @Override protected Vector2i getBackgroundImageSize() { - return new Vector2i(195, 166); + return new Vector2i(197, 166); } } diff --git a/src/machines/java/com/enderio/machines/common/blockentity/WiredChargerBlockEntity.java b/src/machines/java/com/enderio/machines/common/blockentity/WiredChargerBlockEntity.java index 45e1e3df36..6a492a6df6 100644 --- a/src/machines/java/com/enderio/machines/common/blockentity/WiredChargerBlockEntity.java +++ b/src/machines/java/com/enderio/machines/common/blockentity/WiredChargerBlockEntity.java @@ -94,7 +94,7 @@ public void chargeItem() { } else { //todo energy balancing // The energyExtracted per tick should increase if the charged item has more energy and with the tier of the capacitor installed - int energyExtracted = itemEnergyStorage.getMaxEnergyStored() / (1000-this.energyStorage.getMaxEnergyUse()); + int energyExtracted = itemEnergyStorage.getMaxEnergyStored() / ((int)getCapacitorData().getModifier(CapacitorModifier.ENERGY_USE)*333 -this.energyStorage.getMaxEnergyUse()); if (this.energyStorage.getEnergyStored() >= energyExtracted) { itemEnergyStorage.receiveEnergy(energyExtracted, false); diff --git a/src/machines/java/com/enderio/machines/common/config/common/EnergyConfig.java b/src/machines/java/com/enderio/machines/common/config/common/EnergyConfig.java index bb27682cc7..e16959c3ba 100644 --- a/src/machines/java/com/enderio/machines/common/config/common/EnergyConfig.java +++ b/src/machines/java/com/enderio/machines/common/config/common/EnergyConfig.java @@ -90,7 +90,7 @@ public EnergyConfig(ForgeConfigSpec.Builder builder) { builder.pop(); builder.push("wiredCharger"); - WIRED_CHARGER_CAPACITY = builder.comment("The base energy capacity in uI.").defineInRange("capacity", 100000, 1, Integer.MAX_VALUE); + WIRED_CHARGER_CAPACITY = builder.comment("The base energy capacity in uI.").defineInRange("capacity", 1000000, 1, Integer.MAX_VALUE); WIRED_CHARGER_USAGE = builder.comment("The base energy consumption in uI/t.").defineInRange("usage", 100, 1, Integer.MAX_VALUE); builder.pop(); diff --git a/src/machines/java/com/enderio/machines/common/menu/WiredChargerMenu.java b/src/machines/java/com/enderio/machines/common/menu/WiredChargerMenu.java index 84cf4c7338..4f8468466c 100644 --- a/src/machines/java/com/enderio/machines/common/menu/WiredChargerMenu.java +++ b/src/machines/java/com/enderio/machines/common/menu/WiredChargerMenu.java @@ -1,15 +1,22 @@ package com.enderio.machines.common.menu; +import com.enderio.EnderIO; import com.enderio.machines.common.blockentity.WiredChargerBlockEntity; import com.enderio.machines.common.init.MachineMenus; import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.world.entity.EquipmentSlot; import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.InventoryMenu; import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.inventory.Slot; +import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.entity.BlockEntity; import org.apache.logging.log4j.LogManager; import org.jetbrains.annotations.Nullable; -public class WiredChargerMenu extends MachineMenu{ + +public class WiredChargerMenu extends MachineMenu { public WiredChargerMenu(WiredChargerBlockEntity blockEntity, Inventory inventory, int pContainerId) { super(blockEntity, inventory, MachineMenus.WIRED_CHARGER.get(), pContainerId); @@ -19,6 +26,11 @@ public WiredChargerMenu(WiredChargerBlockEntity blockEntity, Inventory inventory addSlot(new MachineSlot(blockEntity.getInventory(), WiredChargerBlockEntity.ITEM_CHARGED, 126, 28)); addInventorySlots(29,84); + addArmorSlots(6,12); + + //Add offhand slot + addSlot(new Slot(inventory, 40, 6, 84) + .setBackground(InventoryMenu.BLOCK_ATLAS, InventoryMenu.EMPTY_ARMOR_SLOT_SHIELD)); } public static WiredChargerMenu factory(@Nullable MenuType pMenuType, int pContainerId, Inventory inventory, FriendlyByteBuf buf) { diff --git a/src/machines/java/com/enderio/machines/data/recipes/MachineRecipeProvider.java b/src/machines/java/com/enderio/machines/data/recipes/MachineRecipeProvider.java index ae63518264..c84c009c73 100644 --- a/src/machines/java/com/enderio/machines/data/recipes/MachineRecipeProvider.java +++ b/src/machines/java/com/enderio/machines/data/recipes/MachineRecipeProvider.java @@ -206,6 +206,16 @@ protected void buildRecipes(Consumer finishedRecipeConsumer) { .unlockedBy("has_ingredient", InventoryChangeTrigger.TriggerInstance.hasItems(EIOBlocks.ENSOULED_CHASSIS.get())) .save(finishedRecipeConsumer); + ShapedRecipeBuilder + .shaped(RecipeCategory.MISC, MachineBlocks.WIRED_CHARGER.get()) + .define('C', EIOItems.COPPER_ALLOY_INGOT.get()) + .define('V', EIOBlocks.VOID_CHASSIS.get()) + .pattern("CCC") + .pattern("CVC") + .pattern("CCC") + .unlockedBy("has_ingredient", InventoryChangeTrigger.TriggerInstance.hasItems(EIOBlocks.VOID_CHASSIS.get())) + .save(finishedRecipeConsumer); + ShapedEntityStorageRecipeBuilder .shaped(RecipeCategory.MISC, MachineBlocks.POWERED_SPAWNER) .define('I', EIOItems.SOULARIUM_INGOT) //TODO Maybe also soulchains? @@ -279,6 +289,7 @@ protected void buildRecipes(Consumer finishedRecipeConsumer) { .pattern("CDC") .unlockedBy("has_ingredient", InventoryChangeTrigger.TriggerInstance.hasItems(EIOItems.PHOTOVOLTAIC_PLATE.get())) .save(finishedRecipeConsumer); + ShapedRecipeBuilder .shaped(RecipeCategory.MISC, MachineBlocks.SOLAR_PANELS.get(SolarPanelTier.BASIC)) .define('E', EIOItems.ENERGETIC_ALLOY_INGOT) @@ -291,6 +302,7 @@ protected void buildRecipes(Consumer finishedRecipeConsumer) { .pattern("CDC") .unlockedBy("has_ingredient", InventoryChangeTrigger.TriggerInstance.hasItems(MachineBlocks.SOLAR_PANELS.get(SolarPanelTier.SIMPLE))) .save(finishedRecipeConsumer, EnderIO.loc(RecipeBuilder.getDefaultRecipeId(MachineBlocks.SOLAR_PANELS.get(SolarPanelTier.BASIC)).getPath() + "_upgrade")); + ShapedRecipeBuilder .shaped(RecipeCategory.MISC, MachineBlocks.SOLAR_PANELS.get(SolarPanelTier.ADVANCED)) .define('I', EIOItems.PULSATING_ALLOY_INGOT) @@ -303,6 +315,7 @@ protected void buildRecipes(Consumer finishedRecipeConsumer) { .pattern("CDC") .unlockedBy("has_ingredient", InventoryChangeTrigger.TriggerInstance.hasItems(EIOItems.PHOTOVOLTAIC_PLATE)) .save(finishedRecipeConsumer); + ShapedRecipeBuilder .shaped(RecipeCategory.MISC, MachineBlocks.SOLAR_PANELS.get(SolarPanelTier.ADVANCED)) .define('I', EIOItems.PULSATING_ALLOY_INGOT) @@ -316,6 +329,7 @@ protected void buildRecipes(Consumer finishedRecipeConsumer) { .pattern("CSC") .unlockedBy("has_ingredient", InventoryChangeTrigger.TriggerInstance.hasItems(MachineBlocks.SOLAR_PANELS.get(SolarPanelTier.BASIC))) .save(finishedRecipeConsumer, EnderIO.loc(RecipeBuilder.getDefaultRecipeId(MachineBlocks.SOLAR_PANELS.get(SolarPanelTier.ADVANCED)).getPath() + "_upgrade")); + ShapedRecipeBuilder .shaped(RecipeCategory.MISC, MachineBlocks.SOLAR_PANELS.get(SolarPanelTier.VIBRANT)) .define('I', EIOItems.VIBRANT_ALLOY_INGOT) @@ -328,6 +342,7 @@ protected void buildRecipes(Consumer finishedRecipeConsumer) { .pattern("CDC") .unlockedBy("has_ingredient", InventoryChangeTrigger.TriggerInstance.hasItems(EIOItems.PHOTOVOLTAIC_PLATE)) .save(finishedRecipeConsumer); + ShapedRecipeBuilder .shaped(RecipeCategory.MISC, MachineBlocks.SOLAR_PANELS.get(SolarPanelTier.VIBRANT)) .define('I', EIOItems.VIBRANT_ALLOY_INGOT)