From ff75272607ff85de56d0794e50dda3588ce7d5e2 Mon Sep 17 00:00:00 2001 From: Trytoon Date: Sat, 12 Aug 2023 13:17:52 +0200 Subject: [PATCH 01/10] Added Buffers (item and power) --- .../enderio/blockstates/item_buffer.json | 19 +++ .../enderio/blockstates/omni_buffer.json | 19 +++ .../enderio/blockstates/power_buffer.json | 19 +++ .../resources/assets/enderio/lang/en_ud.json | 3 + .../resources/assets/enderio/lang/en_us.json | 3 + .../enderio/models/block/item_buffer.json | 23 +++ .../models/block/item_buffer_combined.json | 16 ++ .../models/block/item_buffer_front_on.json | 6 + .../enderio/models/block/item_buffer_on.json | 26 +++ .../models/block/omni_buffer_combined.json | 16 ++ .../models/block/power_buffer_combined.json | 16 ++ .../enderio/models/item/item_buffer.json | 3 + .../enderio/models/item/omni_buffer.json | 3 + .../enderio/models/item/power_buffer.json | 3 + .../recipes/misc/item_buffer.json | 33 ++++ .../recipes/misc/omni_buffer.json | 35 ++++ .../recipes/misc/power_buffer.json | 35 ++++ .../loot_tables/blocks/item_buffer.json | 29 ++++ .../loot_tables/blocks/omni_buffer.json | 29 ++++ .../loot_tables/blocks/power_buffer.json | 29 ++++ .../data/enderio/recipes/item_buffer.json | 24 +++ .../data/enderio/recipes/omni_buffer.json | 15 ++ .../data/enderio/recipes/power_buffer.json | 21 +++ .../tags/blocks/mineable/pickaxe.json | 3 + .../tags/blocks/needs_iron_tool.json | 3 + .../client/gui/screen/ItemBufferScreen.java | 37 +++++ .../client/gui/screen/OmniBufferScreen.java | 86 ++++++++++ .../client/gui/screen/PowerBufferScreen.java | 90 ++++++++++ .../gui/widget/EnergyTextboxWidget.java | 124 ++++++++++++++ .../blockentity/ItemBufferBlockEntity.java | 32 ++++ .../blockentity/OmniBufferBlockEntity.java | 34 ++++ .../blockentity/PowerBufferBlockEntity.java | 157 ++++++++++++++++++ .../base/PoweredMachineBlockEntity.java | 2 +- .../common/config/common/EnergyConfig.java | 7 + .../common/init/MachineBlockEntities.java | 7 + .../machines/common/init/MachineBlocks.java | 8 + .../machines/common/init/MachineMenus.java | 4 + .../machines/common/menu/ItemBufferMenu.java | 35 ++++ .../machines/common/menu/OmniBufferMenu.java | 37 +++++ .../machines/common/menu/PowerBufferMenu.java | 31 ++++ .../data/recipes/MachineRecipeProvider.java | 28 ++++ .../enderio/models/block/item_buffer.json | 12 ++ .../enderio/models/block/omni_buffer.json | 12 ++ .../enderio/models/block/power_buffer.json | 12 ++ .../enderio/textures/block/item_buffer.png | Bin 0 -> 749 bytes .../enderio/textures/block/omni_buffer.png | Bin 0 -> 1435 bytes .../enderio/textures/block/power_buffer.png | Bin 0 -> 1327 bytes .../enderio/textures/block/item_buffer.png | Bin 0 -> 749 bytes .../enderio/textures/block/power_buffer.png | Bin 0 -> 1327 bytes .../enderio/textures/gui/buffer_full.png | Bin 1897 -> 0 bytes .../enderio/textures/gui/item_buffer.png | Bin 0 -> 1239 bytes .../enderio/textures/gui/omni_buffer.png | Bin 0 -> 1368 bytes .../enderio/textures/gui/power_buffer.png | Bin 0 -> 1265 bytes 53 files changed, 1185 insertions(+), 1 deletion(-) create mode 100644 src/generated/resources/assets/enderio/blockstates/item_buffer.json create mode 100644 src/generated/resources/assets/enderio/blockstates/omni_buffer.json create mode 100644 src/generated/resources/assets/enderio/blockstates/power_buffer.json create mode 100644 src/generated/resources/assets/enderio/models/block/item_buffer.json create mode 100644 src/generated/resources/assets/enderio/models/block/item_buffer_combined.json create mode 100644 src/generated/resources/assets/enderio/models/block/item_buffer_front_on.json create mode 100644 src/generated/resources/assets/enderio/models/block/item_buffer_on.json create mode 100644 src/generated/resources/assets/enderio/models/block/omni_buffer_combined.json create mode 100644 src/generated/resources/assets/enderio/models/block/power_buffer_combined.json create mode 100644 src/generated/resources/assets/enderio/models/item/item_buffer.json create mode 100644 src/generated/resources/assets/enderio/models/item/omni_buffer.json create mode 100644 src/generated/resources/assets/enderio/models/item/power_buffer.json create mode 100644 src/generated/resources/data/enderio/advancements/recipes/misc/item_buffer.json create mode 100644 src/generated/resources/data/enderio/advancements/recipes/misc/omni_buffer.json create mode 100644 src/generated/resources/data/enderio/advancements/recipes/misc/power_buffer.json create mode 100644 src/generated/resources/data/enderio/loot_tables/blocks/item_buffer.json create mode 100644 src/generated/resources/data/enderio/loot_tables/blocks/omni_buffer.json create mode 100644 src/generated/resources/data/enderio/loot_tables/blocks/power_buffer.json create mode 100644 src/generated/resources/data/enderio/recipes/item_buffer.json create mode 100644 src/generated/resources/data/enderio/recipes/omni_buffer.json create mode 100644 src/generated/resources/data/enderio/recipes/power_buffer.json create mode 100644 src/machines/java/com/enderio/machines/client/gui/screen/ItemBufferScreen.java create mode 100644 src/machines/java/com/enderio/machines/client/gui/screen/OmniBufferScreen.java create mode 100644 src/machines/java/com/enderio/machines/client/gui/screen/PowerBufferScreen.java create mode 100644 src/machines/java/com/enderio/machines/client/gui/widget/EnergyTextboxWidget.java create mode 100644 src/machines/java/com/enderio/machines/common/blockentity/ItemBufferBlockEntity.java create mode 100644 src/machines/java/com/enderio/machines/common/blockentity/OmniBufferBlockEntity.java create mode 100644 src/machines/java/com/enderio/machines/common/blockentity/PowerBufferBlockEntity.java create mode 100644 src/machines/java/com/enderio/machines/common/menu/ItemBufferMenu.java create mode 100644 src/machines/java/com/enderio/machines/common/menu/OmniBufferMenu.java create mode 100644 src/machines/java/com/enderio/machines/common/menu/PowerBufferMenu.java create mode 100644 src/machines/resources/assets/enderio/models/block/item_buffer.json create mode 100644 src/machines/resources/assets/enderio/models/block/omni_buffer.json create mode 100644 src/machines/resources/assets/enderio/models/block/power_buffer.json create mode 100644 src/machines/resources/assets/enderio/textures/block/item_buffer.png create mode 100644 src/machines/resources/assets/enderio/textures/block/omni_buffer.png create mode 100644 src/machines/resources/assets/enderio/textures/block/power_buffer.png create mode 100644 src/main/resources/assets/enderio/textures/block/item_buffer.png create mode 100644 src/main/resources/assets/enderio/textures/block/power_buffer.png delete mode 100644 src/main/resources/assets/enderio/textures/gui/buffer_full.png create mode 100644 src/main/resources/assets/enderio/textures/gui/item_buffer.png create mode 100644 src/main/resources/assets/enderio/textures/gui/omni_buffer.png create mode 100644 src/main/resources/assets/enderio/textures/gui/power_buffer.png diff --git a/src/generated/resources/assets/enderio/blockstates/item_buffer.json b/src/generated/resources/assets/enderio/blockstates/item_buffer.json new file mode 100644 index 0000000000..b06c5d3dd9 --- /dev/null +++ b/src/generated/resources/assets/enderio/blockstates/item_buffer.json @@ -0,0 +1,19 @@ +{ + "variants": { + "facing=east": { + "model": "enderio:block/item_buffer_combined", + "y": 90 + }, + "facing=north": { + "model": "enderio:block/item_buffer_combined" + }, + "facing=south": { + "model": "enderio:block/item_buffer_combined", + "y": 180 + }, + "facing=west": { + "model": "enderio:block/item_buffer_combined", + "y": 270 + } + } +} \ No newline at end of file diff --git a/src/generated/resources/assets/enderio/blockstates/omni_buffer.json b/src/generated/resources/assets/enderio/blockstates/omni_buffer.json new file mode 100644 index 0000000000..605c1e83f4 --- /dev/null +++ b/src/generated/resources/assets/enderio/blockstates/omni_buffer.json @@ -0,0 +1,19 @@ +{ + "variants": { + "facing=east": { + "model": "enderio:block/omni_buffer_combined", + "y": 90 + }, + "facing=north": { + "model": "enderio:block/omni_buffer_combined" + }, + "facing=south": { + "model": "enderio:block/omni_buffer_combined", + "y": 180 + }, + "facing=west": { + "model": "enderio:block/omni_buffer_combined", + "y": 270 + } + } +} \ No newline at end of file diff --git a/src/generated/resources/assets/enderio/blockstates/power_buffer.json b/src/generated/resources/assets/enderio/blockstates/power_buffer.json new file mode 100644 index 0000000000..e04775ab63 --- /dev/null +++ b/src/generated/resources/assets/enderio/blockstates/power_buffer.json @@ -0,0 +1,19 @@ +{ + "variants": { + "facing=east": { + "model": "enderio:block/power_buffer_combined", + "y": 90 + }, + "facing=north": { + "model": "enderio:block/power_buffer_combined" + }, + "facing=south": { + "model": "enderio:block/power_buffer_combined", + "y": 180 + }, + "facing=west": { + "model": "enderio:block/power_buffer_combined", + "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 54ae62999d..6862f05185 100644 --- a/src/generated/resources/assets/enderio/lang/en_ud.json +++ b/src/generated/resources/assets/enderio/lang/en_ud.json @@ -139,11 +139,13 @@ "block.enderio.hootch": "ɥɔʇooH", "block.enderio.impulse_hopper": "ɹǝddoH ǝsןndɯI", "block.enderio.industrial_insulation_block": "uoıʇɐןnsuI ןɐıɹʇsnpuI", + "block.enderio.item_buffer": "ɹǝɟɟnᗺ ɯǝʇI", "block.enderio.light": "ʇɥbıꞀ", "block.enderio.light_inverted": "pǝʇɹǝʌuI ʇɥbıꞀ", "block.enderio.light_node": "ǝpoN ʇɥbıꞀ", "block.enderio.liquid_sunshine": "ǝuıɥsunS pınbıꞀ", "block.enderio.nutrient_distillation": "uoıʇɐןןıʇsıᗡ ʇuǝıɹʇnN", + "block.enderio.omni_buffer": "ɹǝɟɟnᗺ ıuɯO", "block.enderio.painted_crafting_table": "ǝןqɐ⟘ buıʇɟɐɹƆ pǝʇuıɐԀ", "block.enderio.painted_fence": "ǝɔuǝℲ pǝʇuıɐԀ", "block.enderio.painted_fence_gate": "ǝʇɐ⅁ ǝɔuǝℲ pǝʇuıɐԀ", @@ -155,6 +157,7 @@ "block.enderio.painted_trapdoor": "ɹoopdɐɹ⟘ pǝʇuıɐԀ", "block.enderio.painted_wooden_pressure_plate": "ǝʇɐןԀ ǝɹnssǝɹԀ uǝpooM pǝʇuıɐԀ", "block.enderio.painting_machine": "ǝuıɥɔɐW buıʇuıɐԀ", + "block.enderio.power_buffer": "ɹǝɟɟnᗺ ɹǝʍoԀ", "block.enderio.powered_light": "ʇɥbıꞀ pǝɹǝʍoԀ", "block.enderio.powered_light_inverted": "pǝʇɹǝʌuI ʇɥbıꞀ pǝɹǝʍoԀ", "block.enderio.powered_light_inverted_wireless": "ssǝןǝɹıM pǝʇɹǝʌuI ʇɥbıꞀ pǝɹǝʍoԀ", diff --git a/src/generated/resources/assets/enderio/lang/en_us.json b/src/generated/resources/assets/enderio/lang/en_us.json index bf07fb6dac..0ba1ff9e73 100644 --- a/src/generated/resources/assets/enderio/lang/en_us.json +++ b/src/generated/resources/assets/enderio/lang/en_us.json @@ -139,11 +139,13 @@ "block.enderio.hootch": "Hootch", "block.enderio.impulse_hopper": "Impulse Hopper", "block.enderio.industrial_insulation_block": "Industrial Insulation", + "block.enderio.item_buffer": "Item Buffer", "block.enderio.light": "Light", "block.enderio.light_inverted": "Light Inverted", "block.enderio.light_node": "Light Node", "block.enderio.liquid_sunshine": "Liquid Sunshine", "block.enderio.nutrient_distillation": "Nutrient Distillation", + "block.enderio.omni_buffer": "Omni Buffer", "block.enderio.painted_crafting_table": "Painted Crafting Table", "block.enderio.painted_fence": "Painted Fence", "block.enderio.painted_fence_gate": "Painted Fence Gate", @@ -155,6 +157,7 @@ "block.enderio.painted_trapdoor": "Painted Trapdoor", "block.enderio.painted_wooden_pressure_plate": "Painted Wooden Pressure Plate", "block.enderio.painting_machine": "Painting Machine", + "block.enderio.power_buffer": "Power Buffer", "block.enderio.powered_light": "Powered Light", "block.enderio.powered_light_inverted": "Powered Light Inverted", "block.enderio.powered_light_inverted_wireless": "Powered Light Inverted Wireless", diff --git a/src/generated/resources/assets/enderio/models/block/item_buffer.json b/src/generated/resources/assets/enderio/models/block/item_buffer.json new file mode 100644 index 0000000000..ec85aabc80 --- /dev/null +++ b/src/generated/resources/assets/enderio/models/block/item_buffer.json @@ -0,0 +1,23 @@ +{ + "parent": "minecraft:block/block", + "children": { + "frame": { + "parent": "enderio:block/machine_frame" + }, + "front": { + "parent": "enderio:block/item_buffer_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/block/item_buffer_combined.json b/src/generated/resources/assets/enderio/models/block/item_buffer_combined.json new file mode 100644 index 0000000000..872883ab51 --- /dev/null +++ b/src/generated/resources/assets/enderio/models/block/item_buffer_combined.json @@ -0,0 +1,16 @@ +{ + "parent": "minecraft:block/block", + "children": { + "machine": { + "parent": "enderio:block/item_buffer" + }, + "overlay": { + "parent": "enderio:block/io_overlay" + } + }, + "item_render_order": [ + "machine", + "overlay" + ], + "loader": "forge:composite" +} \ No newline at end of file diff --git a/src/generated/resources/assets/enderio/models/block/item_buffer_front_on.json b/src/generated/resources/assets/enderio/models/block/item_buffer_front_on.json new file mode 100644 index 0000000000..375b385cc1 --- /dev/null +++ b/src/generated/resources/assets/enderio/models/block/item_buffer_front_on.json @@ -0,0 +1,6 @@ +{ + "parent": "enderio:block/item_buffer_front", + "textures": { + "front": "enderio:block/item_buffer_front_on" + } +} \ No newline at end of file diff --git a/src/generated/resources/assets/enderio/models/block/item_buffer_on.json b/src/generated/resources/assets/enderio/models/block/item_buffer_on.json new file mode 100644 index 0000000000..eeba28c2a7 --- /dev/null +++ b/src/generated/resources/assets/enderio/models/block/item_buffer_on.json @@ -0,0 +1,26 @@ +{ + "parent": "minecraft:block/block", + "children": { + "frame": { + "parent": "enderio:block/machine_frame" + }, + "front": { + "parent": "enderio:block/item_buffer_front", + "textures": { + "front": "enderio:block/item_buffer_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/assets/enderio/models/block/omni_buffer_combined.json b/src/generated/resources/assets/enderio/models/block/omni_buffer_combined.json new file mode 100644 index 0000000000..6b385f5c2b --- /dev/null +++ b/src/generated/resources/assets/enderio/models/block/omni_buffer_combined.json @@ -0,0 +1,16 @@ +{ + "parent": "minecraft:block/block", + "children": { + "machine": { + "parent": "enderio:block/omni_buffer" + }, + "overlay": { + "parent": "enderio:block/io_overlay" + } + }, + "item_render_order": [ + "machine", + "overlay" + ], + "loader": "forge:composite" +} \ No newline at end of file diff --git a/src/generated/resources/assets/enderio/models/block/power_buffer_combined.json b/src/generated/resources/assets/enderio/models/block/power_buffer_combined.json new file mode 100644 index 0000000000..43ee0b7276 --- /dev/null +++ b/src/generated/resources/assets/enderio/models/block/power_buffer_combined.json @@ -0,0 +1,16 @@ +{ + "parent": "minecraft:block/block", + "children": { + "machine": { + "parent": "enderio:block/power_buffer" + }, + "overlay": { + "parent": "enderio:block/io_overlay" + } + }, + "item_render_order": [ + "machine", + "overlay" + ], + "loader": "forge:composite" +} \ No newline at end of file diff --git a/src/generated/resources/assets/enderio/models/item/item_buffer.json b/src/generated/resources/assets/enderio/models/item/item_buffer.json new file mode 100644 index 0000000000..44a6f071af --- /dev/null +++ b/src/generated/resources/assets/enderio/models/item/item_buffer.json @@ -0,0 +1,3 @@ +{ + "parent": "enderio:block/item_buffer" +} \ No newline at end of file diff --git a/src/generated/resources/assets/enderio/models/item/omni_buffer.json b/src/generated/resources/assets/enderio/models/item/omni_buffer.json new file mode 100644 index 0000000000..c825356684 --- /dev/null +++ b/src/generated/resources/assets/enderio/models/item/omni_buffer.json @@ -0,0 +1,3 @@ +{ + "parent": "enderio:block/omni_buffer" +} \ No newline at end of file diff --git a/src/generated/resources/assets/enderio/models/item/power_buffer.json b/src/generated/resources/assets/enderio/models/item/power_buffer.json new file mode 100644 index 0000000000..b2805b3878 --- /dev/null +++ b/src/generated/resources/assets/enderio/models/item/power_buffer.json @@ -0,0 +1,3 @@ +{ + "parent": "enderio:block/power_buffer" +} \ No newline at end of file diff --git a/src/generated/resources/data/enderio/advancements/recipes/misc/item_buffer.json b/src/generated/resources/data/enderio/advancements/recipes/misc/item_buffer.json new file mode 100644 index 0000000000..0255edd5bb --- /dev/null +++ b/src/generated/resources/data/enderio/advancements/recipes/misc/item_buffer.json @@ -0,0 +1,33 @@ +{ + "parent": "minecraft:recipes/root", + "criteria": { + "has_ingredient": { + "conditions": { + "items": [ + { + "tag": "forge:ingots/iron" + } + ] + }, + "trigger": "minecraft:inventory_changed" + }, + "has_the_recipe": { + "conditions": { + "recipe": "enderio:item_buffer" + }, + "trigger": "minecraft:recipe_unlocked" + } + }, + "requirements": [ + [ + "has_ingredient", + "has_the_recipe" + ] + ], + "rewards": { + "recipes": [ + "enderio:item_buffer" + ] + }, + "sends_telemetry_event": false +} \ No newline at end of file diff --git a/src/generated/resources/data/enderio/advancements/recipes/misc/omni_buffer.json b/src/generated/resources/data/enderio/advancements/recipes/misc/omni_buffer.json new file mode 100644 index 0000000000..84968bed90 --- /dev/null +++ b/src/generated/resources/data/enderio/advancements/recipes/misc/omni_buffer.json @@ -0,0 +1,35 @@ +{ + "parent": "minecraft:recipes/root", + "criteria": { + "has_ingredient": { + "conditions": { + "items": [ + { + "items": [ + "enderio:power_buffer" + ] + } + ] + }, + "trigger": "minecraft:inventory_changed" + }, + "has_the_recipe": { + "conditions": { + "recipe": "enderio:omni_buffer" + }, + "trigger": "minecraft:recipe_unlocked" + } + }, + "requirements": [ + [ + "has_ingredient", + "has_the_recipe" + ] + ], + "rewards": { + "recipes": [ + "enderio:omni_buffer" + ] + }, + "sends_telemetry_event": false +} \ No newline at end of file diff --git a/src/generated/resources/data/enderio/advancements/recipes/misc/power_buffer.json b/src/generated/resources/data/enderio/advancements/recipes/misc/power_buffer.json new file mode 100644 index 0000000000..ac24832a3c --- /dev/null +++ b/src/generated/resources/data/enderio/advancements/recipes/misc/power_buffer.json @@ -0,0 +1,35 @@ +{ + "parent": "minecraft:recipes/root", + "criteria": { + "has_ingredient": { + "conditions": { + "items": [ + { + "items": [ + "enderio:void_chassis" + ] + } + ] + }, + "trigger": "minecraft:inventory_changed" + }, + "has_the_recipe": { + "conditions": { + "recipe": "enderio:power_buffer" + }, + "trigger": "minecraft:recipe_unlocked" + } + }, + "requirements": [ + [ + "has_ingredient", + "has_the_recipe" + ] + ], + "rewards": { + "recipes": [ + "enderio:power_buffer" + ] + }, + "sends_telemetry_event": false +} \ No newline at end of file diff --git a/src/generated/resources/data/enderio/loot_tables/blocks/item_buffer.json b/src/generated/resources/data/enderio/loot_tables/blocks/item_buffer.json new file mode 100644 index 0000000000..3575088c5d --- /dev/null +++ b/src/generated/resources/data/enderio/loot_tables/blocks/item_buffer.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:item_buffer" + } + ], + "rolls": 1.0 + } + ], + "random_sequence": "enderio:blocks/item_buffer" +} \ No newline at end of file diff --git a/src/generated/resources/data/enderio/loot_tables/blocks/omni_buffer.json b/src/generated/resources/data/enderio/loot_tables/blocks/omni_buffer.json new file mode 100644 index 0000000000..1a60e0b310 --- /dev/null +++ b/src/generated/resources/data/enderio/loot_tables/blocks/omni_buffer.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:omni_buffer" + } + ], + "rolls": 1.0 + } + ], + "random_sequence": "enderio:blocks/omni_buffer" +} \ No newline at end of file diff --git a/src/generated/resources/data/enderio/loot_tables/blocks/power_buffer.json b/src/generated/resources/data/enderio/loot_tables/blocks/power_buffer.json new file mode 100644 index 0000000000..a42a38036e --- /dev/null +++ b/src/generated/resources/data/enderio/loot_tables/blocks/power_buffer.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:power_buffer" + } + ], + "rolls": 1.0 + } + ], + "random_sequence": "enderio:blocks/power_buffer" +} \ No newline at end of file diff --git a/src/generated/resources/data/enderio/recipes/item_buffer.json b/src/generated/resources/data/enderio/recipes/item_buffer.json new file mode 100644 index 0000000000..6c4fcc85ed --- /dev/null +++ b/src/generated/resources/data/enderio/recipes/item_buffer.json @@ -0,0 +1,24 @@ +{ + "type": "minecraft:crafting_shaped", + "category": "misc", + "key": { + "A": { + "item": "enderio:copper_alloy_ingot" + }, + "C": { + "tag": "forge:chests" + }, + "I": { + "tag": "forge:ingots/iron" + } + }, + "pattern": [ + "IAI", + "ACA", + "IAI" + ], + "result": { + "item": "enderio:item_buffer" + }, + "show_notification": true +} \ No newline at end of file diff --git a/src/generated/resources/data/enderio/recipes/omni_buffer.json b/src/generated/resources/data/enderio/recipes/omni_buffer.json new file mode 100644 index 0000000000..3eba8d7968 --- /dev/null +++ b/src/generated/resources/data/enderio/recipes/omni_buffer.json @@ -0,0 +1,15 @@ +{ + "type": "minecraft:crafting_shapeless", + "category": "misc", + "ingredients": [ + { + "item": "enderio:power_buffer" + }, + { + "item": "enderio:item_buffer" + } + ], + "result": { + "item": "enderio:omni_buffer" + } +} \ No newline at end of file diff --git a/src/generated/resources/data/enderio/recipes/power_buffer.json b/src/generated/resources/data/enderio/recipes/power_buffer.json new file mode 100644 index 0000000000..232435821d --- /dev/null +++ b/src/generated/resources/data/enderio/recipes/power_buffer.json @@ -0,0 +1,21 @@ +{ + "type": "minecraft:crafting_shaped", + "category": "misc", + "key": { + "A": { + "item": "enderio:copper_alloy_ingot" + }, + "C": { + "item": "enderio:void_chassis" + } + }, + "pattern": [ + " A ", + "ACA", + " A " + ], + "result": { + "item": "enderio:power_buffer" + }, + "show_notification": true +} \ No newline at end of file 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 3027e7460a..158fc9fd34 100644 --- a/src/generated/resources/data/minecraft/tags/blocks/mineable/pickaxe.json +++ b/src/generated/resources/data/minecraft/tags/blocks/mineable/pickaxe.json @@ -42,6 +42,9 @@ "enderio:alloy_smelter", "enderio:painting_machine", "enderio:wired_charger", + "enderio:item_buffer", + "enderio:power_buffer", + "enderio:omni_buffer", "enderio:stirling_generator", "enderio:sag_mill", "enderio:slice_and_splice", 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 a7e24fbdce..138c3ee22c 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 @@ -13,6 +13,9 @@ "enderio:alloy_smelter", "enderio:painting_machine", "enderio:wired_charger", + "enderio:item_buffer", + "enderio:power_buffer", + "enderio:omni_buffer", "enderio:stirling_generator", "enderio:sag_mill", "enderio:slice_and_splice", diff --git a/src/machines/java/com/enderio/machines/client/gui/screen/ItemBufferScreen.java b/src/machines/java/com/enderio/machines/client/gui/screen/ItemBufferScreen.java new file mode 100644 index 0000000000..5519cadbb2 --- /dev/null +++ b/src/machines/java/com/enderio/machines/client/gui/screen/ItemBufferScreen.java @@ -0,0 +1,37 @@ +package com.enderio.machines.client.gui.screen; + +import com.enderio.EnderIO; +import com.enderio.api.misc.Vector2i; +import com.enderio.core.client.gui.screen.EIOScreen; +import com.enderio.machines.client.gui.widget.EnergyTextboxWidget; +import com.enderio.machines.client.gui.widget.ioconfig.IOConfigButton; +import com.enderio.machines.common.menu.ItemBufferMenu; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.entity.player.Inventory; + +public class ItemBufferScreen extends EIOScreen { + + private static final ResourceLocation BG_TEXTURE = EnderIO.loc("textures/gui/item_buffer.png"); + EnergyTextboxWidget widget; + public ItemBufferScreen(ItemBufferMenu pMenu, Inventory pPlayerInventory, Component pTitle) { + super(pMenu, pPlayerInventory, pTitle); + } + + @Override + protected void init() { + super.init(); + + addRenderableWidget(new IOConfigButton<>(this, leftPos + imageWidth - 8 - 12, topPos + 6, 16, 16, menu, this::addRenderableWidget, font)); + } + + @Override + public ResourceLocation getBackgroundImage() { + return BG_TEXTURE; + } + + @Override + protected Vector2i getBackgroundImageSize() { + return new Vector2i(175, 166); + } +} diff --git a/src/machines/java/com/enderio/machines/client/gui/screen/OmniBufferScreen.java b/src/machines/java/com/enderio/machines/client/gui/screen/OmniBufferScreen.java new file mode 100644 index 0000000000..c02a0a804a --- /dev/null +++ b/src/machines/java/com/enderio/machines/client/gui/screen/OmniBufferScreen.java @@ -0,0 +1,86 @@ +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.CapacitorEnergyWidget; +import com.enderio.machines.client.gui.widget.EnergyTextboxWidget; +import com.enderio.machines.client.gui.widget.ioconfig.IOConfigButton; +import com.enderio.machines.common.blockentity.PowerBufferBlockEntity; +import com.enderio.machines.common.menu.OmniBufferMenu; +import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.entity.player.Inventory; + +public class OmniBufferScreen extends EIOScreen { + + private static final ResourceLocation BG_TEXTURE = EnderIO.loc("textures/gui/omni_buffer.png"); + private EnergyTextboxWidget input; + private EnergyTextboxWidget output; + + public OmniBufferScreen(OmniBufferMenu pMenu, Inventory pPlayerInventory, Component pTitle) { + super(pMenu, pPlayerInventory, pTitle); + } + + @Override + protected void init() { + super.init(); + + addRenderableOnly(addRenderableOnly(new CapacitorEnergyWidget(this, getMenu().getBlockEntity()::getEnergyStorage, getMenu().getBlockEntity()::isCapacitorInstalled, 16 + 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)); + + input = new EnergyTextboxWidget(this, () -> this.getMenu().getBlockEntity().getEnergyStorage().getMaxEnergyUse(), this.font, leftPos + 33, topPos + 18, 49, this.font.lineHeight + 2, Component.empty()); + input.setValue(input.formatEnergy(Integer.toString(this.getMenu().getBlockEntity().getMaxInput()))); + addRenderableWidget(input); + + output = new EnergyTextboxWidget(this, () -> this.getMenu().getBlockEntity().getEnergyStorage().getMaxEnergyUse(), this.font, leftPos + 33, topPos + 48, 49, this.font.lineHeight + 2, Component.empty()); + output.setValue(output.formatEnergy(Integer.toString(this.getMenu().getBlockEntity().getMaxOutput()))); + addRenderableWidget(output); + + } + + @Override + public ResourceLocation getBackgroundImage() { + return BG_TEXTURE; + } + + @Override + protected Vector2i getBackgroundImageSize() { + return new Vector2i(175, 166); + } + + @Override + public void render(GuiGraphics guiGraphics, int pMouseX, int pMouseY, float pPartialTicks) { + super.render(guiGraphics, pMouseX, pMouseY, pPartialTicks); + PowerBufferBlockEntity be = this.getMenu().getBlockEntity(); + guiGraphics.drawString(font, "Input:", leftPos + 33, topPos + 18 - font.lineHeight - 2, 1, false); + guiGraphics.drawString(font, "Output:", leftPos + 33, topPos + 48 - font.lineHeight - 2, 1, false); + } + + + //Reset values if no capacitor, else display the value stored in the power buffer + @Override + protected void containerTick() { + super.containerTick(); + PowerBufferBlockEntity be = this.getMenu().getBlockEntity(); + if (be != null) { + if (be.requiresCapacitor() && be.isCapacitorInstalled()) { + be.setMaxInput(input.getInteger()); + be.setMaxOutput(output.getInteger()); + } else { + be.setMaxInput(0); + input.setValue("0"); + + be.setMaxOutput(0); + output.setValue("0"); + } + } + } +} diff --git a/src/machines/java/com/enderio/machines/client/gui/screen/PowerBufferScreen.java b/src/machines/java/com/enderio/machines/client/gui/screen/PowerBufferScreen.java new file mode 100644 index 0000000000..1b32be3f33 --- /dev/null +++ b/src/machines/java/com/enderio/machines/client/gui/screen/PowerBufferScreen.java @@ -0,0 +1,90 @@ +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.CapacitorEnergyWidget; +import com.enderio.machines.client.gui.widget.EnergyTextboxWidget; +import com.enderio.machines.client.gui.widget.ioconfig.IOConfigButton; +import com.enderio.machines.common.blockentity.PowerBufferBlockEntity; +import com.enderio.machines.common.menu.PowerBufferMenu; +import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.entity.player.Inventory; + +public class PowerBufferScreen extends EIOScreen { + + private static final ResourceLocation BG_TEXTURE = EnderIO.loc("textures/gui/power_buffer.png"); + private EnergyTextboxWidget input; + private EnergyTextboxWidget output; + + public PowerBufferScreen(PowerBufferMenu pMenu, Inventory pPlayerInventory, Component pTitle) { + super(pMenu, pPlayerInventory, pTitle); + } + + @Override + protected void init() { + super.init(); + + addRenderableOnly(addRenderableOnly(new CapacitorEnergyWidget(this, getMenu().getBlockEntity()::getEnergyStorage, getMenu().getBlockEntity()::isCapacitorInstalled, 16 + 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)); + + input = new EnergyTextboxWidget(this, () -> this.getMenu().getBlockEntity().getEnergyStorage().getMaxEnergyUse(), this.font, leftPos + 40, topPos + 18, 95, this.font.lineHeight + 2, Component.empty()); + input.setValue(Integer.toString(this.getMenu().getBlockEntity().getMaxInput())); + addRenderableWidget(input); + + output = new EnergyTextboxWidget(this, () -> this.getMenu().getBlockEntity().getEnergyStorage().getMaxEnergyUse(), this.font, leftPos + 40, topPos + 48, 95, this.font.lineHeight + 2, Component.empty()); + output.setValue(output.formatEnergy(Integer.toString(this.getMenu().getBlockEntity().getMaxOutput()))); + addRenderableWidget(output); + + } + + @Override + public ResourceLocation getBackgroundImage() { + return BG_TEXTURE; + } + + @Override + protected Vector2i getBackgroundImageSize() { + return new Vector2i(175, 166); + } + + @Override + public void render(GuiGraphics guiGraphics, int pMouseX, int pMouseY, float pPartialTicks) { + super.render(guiGraphics, pMouseX, pMouseY, pPartialTicks); + PowerBufferBlockEntity be = this.getMenu().getBlockEntity(); + guiGraphics.drawString(font, "Input:", leftPos + 33, topPos + 18 - font.lineHeight - 2, 1, false); + guiGraphics.drawString(font, "Output:", leftPos + 33, topPos + 48 - font.lineHeight - 2, 1, false); + } + + + //Reset values if no capacitor, else display the value stored in the power buffer + //There is probably a better way of setting the energy is the block entity + @Override + protected void containerTick() { + super.containerTick(); + PowerBufferBlockEntity be = this.getMenu().getBlockEntity(); + if (be != null) { + if (be.requiresCapacitor() && be.isCapacitorInstalled()) { + if (!input.isFocused()) + be.setMaxInput(input.getInteger()); + + if (!output.isFocused()) + be.setMaxOutput(output.getInteger()); + } else { + be.setMaxInput(0); + input.setValue("0"); + + be.setMaxOutput(0); + output.setValue("0"); + } + } + } +} diff --git a/src/machines/java/com/enderio/machines/client/gui/widget/EnergyTextboxWidget.java b/src/machines/java/com/enderio/machines/client/gui/widget/EnergyTextboxWidget.java new file mode 100644 index 0000000000..a8c2423cd0 --- /dev/null +++ b/src/machines/java/com/enderio/machines/client/gui/widget/EnergyTextboxWidget.java @@ -0,0 +1,124 @@ +package com.enderio.machines.client.gui.widget; + +import net.minecraft.client.gui.Font; +import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.gui.components.EditBox; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.network.chat.Component; +import java.text.DecimalFormat; +import java.text.NumberFormat; +import java.util.Locale; +import java.util.function.Supplier; + +public class EnergyTextboxWidget extends EditBox { + private final Supplier maxEnergy; + + protected final Screen displayOn; + + public EnergyTextboxWidget(Screen displayOn, Supplier maxEnergy, Font font, int x, int y, int width, int height, Component message) { + super(font, x, y, width, height, message); + this.maxEnergy = maxEnergy; + this.displayOn = displayOn; + setCanLoseFocus(true); + } + + //Input only accepts digits (0, 1, ..., 9) + @Override + public boolean charTyped(char codePoint, int modifiers) { + + if (codePoint >= 48 && codePoint <= 57) { + int cursorPos = getCursorPosition() + 1; + boolean res = super.charTyped(codePoint, modifiers); + setValue(formatEnergy(getValue())); + moveCursorTo(cursorPos); + + return res; + } + + return false; + } + + @Override + public boolean keyPressed(int keyCode, int scanCode, int modifiers) { + boolean res = super.keyPressed(keyCode, scanCode, modifiers); + + if (keyCode == 259) { + int cursorPos = getCursorPosition(); + setValue(formatEnergy(getValue())); + + if (getValue().equals("0")) { + moveCursorTo(1); + } else { + moveCursorTo(cursorPos); + } + } + + return res; + } + + @Override + public boolean mouseClicked(double mouseX, double mouseY, int button) { + + if (mouseX >= getX() && mouseX <= getX() + width && mouseY >= getY() && mouseY <= getY() + height) { + super.mouseClicked(mouseX, mouseY, button); + + //Clear content on right click + if (button == 1) { + setValue("0"); + moveCursorTo(1); + } + + return true; + } else { + setFocused(false); + return false; + } + } + + public String formatEnergy(String value) { + + if (value.isEmpty()) { + return "0"; + } + + int energy = 0; + value = value.replace(",", ""); + + try { + energy = Integer.parseInt(value); + energy = Math.min(energy, maxEnergy.get()); + } catch(Exception e) { + energy = 0; + } + + try { + DecimalFormat decimalFormat = (DecimalFormat) NumberFormat.getInstance(Locale.ROOT); + decimalFormat.applyPattern("#,###"); + return decimalFormat.format(energy); + } catch (NumberFormatException e) { + return "0"; + } + } + + public int getInteger() { + String integer = getValue().replace(",", ""); + + try { + return Integer.parseInt(integer); + } catch(Exception e) { + return 0; + } + } + + @Override + public void renderWidget(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick) { + super.renderWidget(guiGraphics, mouseX, mouseY, partialTick); + renderToolTip(guiGraphics, mouseX, mouseY); + } + + public void renderToolTip(GuiGraphics guiGraphics, int mouseX, int mouseY) { + if (mouseX >= getX() && mouseX <= getX() + width && mouseY >= getY() && mouseY <= getY() + height && !isFocused()) { + guiGraphics.renderTooltip(displayOn.getMinecraft().font, Component.literal(formatEnergy(getValue()) +"/" +formatEnergy(Integer.toString(maxEnergy.get())) +" µI"), mouseX, mouseY); + } + } +} diff --git a/src/machines/java/com/enderio/machines/common/blockentity/ItemBufferBlockEntity.java b/src/machines/java/com/enderio/machines/common/blockentity/ItemBufferBlockEntity.java new file mode 100644 index 0000000000..7e6616b3a4 --- /dev/null +++ b/src/machines/java/com/enderio/machines/common/blockentity/ItemBufferBlockEntity.java @@ -0,0 +1,32 @@ +package com.enderio.machines.common.blockentity; + +import com.enderio.machines.common.blockentity.base.MachineBlockEntity; +import com.enderio.machines.common.io.item.MachineInventoryLayout; +import com.enderio.machines.common.menu.ItemBufferMenu; +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.level.block.entity.BlockEntityType; +import net.minecraft.world.level.block.state.BlockState; +import org.jetbrains.annotations.Nullable; + +public class ItemBufferBlockEntity extends MachineBlockEntity { + public ItemBufferBlockEntity(BlockEntityType type, BlockPos worldPosition, BlockState blockState) { + super(type, worldPosition, blockState); + } + + @Override + public @Nullable MachineInventoryLayout getInventoryLayout() { + return MachineInventoryLayout.builder() + .inputSlot(9) + .build(); + } + + @Nullable + @Override + public AbstractContainerMenu createMenu(int containerId, Inventory playerInventory, Player player) { + return new ItemBufferMenu(this, playerInventory, containerId); + } + +} diff --git a/src/machines/java/com/enderio/machines/common/blockentity/OmniBufferBlockEntity.java b/src/machines/java/com/enderio/machines/common/blockentity/OmniBufferBlockEntity.java new file mode 100644 index 0000000000..71be38e39b --- /dev/null +++ b/src/machines/java/com/enderio/machines/common/blockentity/OmniBufferBlockEntity.java @@ -0,0 +1,34 @@ +package com.enderio.machines.common.blockentity; + +import com.enderio.machines.common.io.item.MachineInventoryLayout; +import com.enderio.machines.common.menu.OmniBufferMenu; +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.level.block.entity.BlockEntityType; +import net.minecraft.world.level.block.state.BlockState; +import org.jetbrains.annotations.Nullable; + + +//The Omni Buffer is basically a PowerBuffer in which we added 9 items slots +public class OmniBufferBlockEntity extends PowerBufferBlockEntity { + + public OmniBufferBlockEntity(BlockEntityType type, BlockPos worldPosition, BlockState blockState) { + super(type, worldPosition, blockState); + } + + @Override + public @Nullable MachineInventoryLayout getInventoryLayout() { + return MachineInventoryLayout + .builder() + .inputSlot(9) + .capacitor() + .build(); + } + + @Override + public @Nullable AbstractContainerMenu createMenu(int containerId, Inventory playerInventory, Player player) { + return new OmniBufferMenu(this, playerInventory, containerId); + } +} diff --git a/src/machines/java/com/enderio/machines/common/blockentity/PowerBufferBlockEntity.java b/src/machines/java/com/enderio/machines/common/blockentity/PowerBufferBlockEntity.java new file mode 100644 index 0000000000..067c2fe856 --- /dev/null +++ b/src/machines/java/com/enderio/machines/common/blockentity/PowerBufferBlockEntity.java @@ -0,0 +1,157 @@ +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.network.slot.IntegerNetworkDataSlot; +import com.enderio.machines.common.blockentity.base.PoweredMachineBlockEntity; +import com.enderio.machines.common.config.MachinesConfig; +import com.enderio.machines.common.io.energy.MachineEnergyStorage; +import com.enderio.machines.common.io.item.MachineInventoryLayout; +import com.enderio.machines.common.menu.PowerBufferMenu; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.AbstractContainerMenu; +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; +import java.util.function.Supplier; + +public class PowerBufferBlockEntity extends PoweredMachineBlockEntity { + int maxInput = 0; + protected IntegerNetworkDataSlot inputDataSlot; + private final String NBT_INPUT = "BufferMaxInput"; + + int maxOutput = 0; + protected IntegerNetworkDataSlot outputDataSlot; + private final String NBT_OUTPUT = "BufferMaxOutput"; + + + //todo: energy balancing + public static final QuadraticScalable CAPACITY = new QuadraticScalable(CapacitorModifier.ENERGY_CAPACITY, MachinesConfig.COMMON.ENERGY.POWER_BUFFER_CAPACITY); + public static final QuadraticScalable USAGE = new QuadraticScalable(CapacitorModifier.ENERGY_USE, MachinesConfig.COMMON.ENERGY.POWER_BUFFER_USAGE); + + public PowerBufferBlockEntity(BlockEntityType type, BlockPos worldPosition, BlockState blockState) { + super(EnergyIOMode.Both, CAPACITY, USAGE, type, worldPosition, blockState); + + //Networing in modding is very fun :) + inputDataSlot = new IntegerNetworkDataSlot(() -> maxInput, input -> maxInput = input); + outputDataSlot = new IntegerNetworkDataSlot(() -> maxOutput, output -> maxOutput = output); + addDataSlot(inputDataSlot); + addDataSlot(outputDataSlot); + } + + @Override + public @Nullable MachineInventoryLayout getInventoryLayout() { + return MachineInventoryLayout + .builder() + .capacitor() + .build(); + } + + @Override + protected boolean isActive() { + return false; + } + + @Nullable + @Override + public AbstractContainerMenu createMenu(int containerId, Inventory playerInventory, Player player) { + return new PowerBufferMenu(this, playerInventory, containerId); + } + + public void setMaxOutput(int maxOutput) { + this.maxOutput = maxOutput; + clientUpdateSlot(outputDataSlot, maxOutput); + } + + public void setMaxInput(int maxInput) { + this.maxInput = maxInput; + clientUpdateSlot(inputDataSlot, maxInput); + } + + public int getMaxInput() { + return maxInput; + } + + public int getMaxOutput() { + return maxOutput; + } + + //Override method to be able to configure power output ! + //By default, it tries to push as much power as it can. + @Override + public void pushEnergy() { + if (!getExposedEnergyStorage().getIOMode().canOutput()) + return; + + for (Direction side : Direction.values()) { + + if (!shouldPushEnergyTo(side)) + continue; + + getCapability(ForgeCapabilities.ENERGY, side).resolve().ifPresent(selfHandler -> { + Optional otherHandler = getNeighbouringCapability(ForgeCapabilities.ENERGY, side).resolve(); + if (otherHandler.isPresent()) { + + // If the other handler can receive power transmit ours and there is enough energy stored + if (otherHandler.get().canReceive() && getExposedEnergyStorage().getEnergyStored() - maxOutput >= 0) { + + int received = otherHandler.get().receiveEnergy(maxOutput, false); + // Consume that energy from our buffer. + getExposedEnergyStorage().extractEnergy(received, false); + } + } + }); + } + } + + @Override + protected MachineEnergyStorage createEnergyStorage(EnergyIOMode energyIOMode, Supplier capacity, Supplier usageRate) { + return new MachineEnergyStorage(getIOConfig(), energyIOMode, capacity, usageRate) { + + //Redstone control should be applied to the buffer + + @Override + public boolean canExtract() { + return super.canExtract() && canAct(); + } + + @Override + public boolean canReceive() { + return super.canReceive() && canAct(); + } + + @Override + public int receiveEnergy(int maxReceive, boolean simulate) { + int energyReceived = Math.min(getMaxEnergyStored() - getEnergyStored(), Math.min(getMaxInput(), maxReceive)); + if (!simulate) { + addEnergy(energyReceived); + } + return energyReceived; + } + }; + } + + @Override + public void saveAdditional(CompoundTag pTag) { + super.saveAdditional(pTag); + pTag.putInt(NBT_INPUT, maxInput); + pTag.putInt(NBT_OUTPUT, maxOutput); + } + + @Override + public void load(CompoundTag pTag) { + super.load(pTag); + maxInput = pTag.getInt(NBT_INPUT); + maxOutput = pTag.getInt(NBT_OUTPUT); + } +} diff --git a/src/machines/java/com/enderio/machines/common/blockentity/base/PoweredMachineBlockEntity.java b/src/machines/java/com/enderio/machines/common/blockentity/base/PoweredMachineBlockEntity.java index 62cdec3578..260ea724dd 100644 --- a/src/machines/java/com/enderio/machines/common/blockentity/base/PoweredMachineBlockEntity.java +++ b/src/machines/java/com/enderio/machines/common/blockentity/base/PoweredMachineBlockEntity.java @@ -148,7 +148,7 @@ public MachineEnergyStorage createExposedEnergyStorage() { /** * Push energy out to neighboring blocks. */ - private void pushEnergy() { + protected void pushEnergy() { // Don't bother if our energy storage cannot output ever. if (!getExposedEnergyStorage().getIOMode().canOutput()) return; 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 38e0553a6a..439931bb3c 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 @@ -33,6 +33,8 @@ public class EnergyConfig { public final ForgeConfigSpec.ConfigValue VIBRANT_CAPACITOR_BANK_CAPACITY; public final ForgeConfigSpec.ConfigValue WIRED_CHARGER_CAPACITY; public final ForgeConfigSpec.ConfigValue WIRED_CHARGER_USAGE; + public final ForgeConfigSpec.ConfigValue POWER_BUFFER_CAPACITY; + public final ForgeConfigSpec.ConfigValue POWER_BUFFER_USAGE; public EnergyConfig(ForgeConfigSpec.Builder builder) { builder.push("energy"); @@ -113,6 +115,11 @@ public EnergyConfig(ForgeConfigSpec.Builder builder) { WIRED_CHARGER_USAGE = builder.comment("The base energy consumption in uI/t.").defineInRange("usage", 64, 1, Integer.MAX_VALUE); builder.pop(); + builder.push("powerBuffer"); + POWER_BUFFER_CAPACITY = builder.comment("The base energy capacity in uI.").defineInRange("capacity", 100_000, 1, Integer.MAX_VALUE); + POWER_BUFFER_USAGE = builder.comment("The base energy consumption in uI/t.").defineInRange("usage", 1_000, 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 ecf5f3e1a6..1b9df269ba 100644 --- a/src/machines/java/com/enderio/machines/common/init/MachineBlockEntities.java +++ b/src/machines/java/com/enderio/machines/common/init/MachineBlockEntities.java @@ -2,6 +2,9 @@ import com.enderio.EnderIO; import com.enderio.machines.common.blockentity.*; +import com.enderio.machines.common.blockentity.ItemBufferBlockEntity; +import com.enderio.machines.common.blockentity.OmniBufferBlockEntity; +import com.enderio.machines.common.blockentity.PowerBufferBlockEntity; import com.enderio.machines.common.blockentity.capacitorbank.CapacitorBankBlockEntity; import com.enderio.machines.common.blockentity.capacitorbank.CapacitorTier; import com.enderio.machines.common.blockentity.solar.SolarPanelBlockEntity; @@ -64,6 +67,10 @@ public class MachineBlockEntities { public static final BlockEntityEntry POWERED_SPAWNER = register("powered_spawner", PoweredSpawnerBlockEntity::new, MachineBlocks.POWERED_SPAWNER); + public static final BlockEntityEntry ITEM_BUFFER = register("item_buffer", ItemBufferBlockEntity::new, MachineBlocks.ITEM_BUFFER); + public static final BlockEntityEntry POWER_BUFFER = register("power_buffer", PowerBufferBlockEntity::new, MachineBlocks.POWER_BUFFER); + public static final BlockEntityEntry OMNI_BUFFER = register("omni_buffer", OmniBufferBlockEntity::new, MachineBlocks.OMNI_BUFFER); + public static final Map> SOLAR_PANELS = Util.make(() -> { Map> map = new HashMap<>(); for (SolarPanelTier tier : SolarPanelTier.values()) { 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 92c90726f9..b33d4173da 100644 --- a/src/machines/java/com/enderio/machines/common/init/MachineBlocks.java +++ b/src/machines/java/com/enderio/machines/common/init/MachineBlocks.java @@ -97,6 +97,14 @@ public class MachineBlocks { public static final BlockEntry WIRED_CHARGER = machine("wired_charger", () -> MachineBlockEntities.WIRED_CHARGER) .register(); + public static final BlockEntry ITEM_BUFFER = machine("item_buffer", () -> MachineBlockEntities.ITEM_BUFFER) + .register(); + + public static final BlockEntry POWER_BUFFER = machine("power_buffer", () -> MachineBlockEntities.POWER_BUFFER) + .register(); + public static final BlockEntry OMNI_BUFFER = machine("omni_buffer", () -> MachineBlockEntities.OMNI_BUFFER) + .register(); + public static final BlockEntry CREATIVE_POWER = REGISTRATE .block("creative_power", props -> new MachineBlock(props, MachineBlockEntities.CREATIVE_POWER)) .item() 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 53b840b5bd..992f954a70 100644 --- a/src/machines/java/com/enderio/machines/common/init/MachineMenus.java +++ b/src/machines/java/com/enderio/machines/common/init/MachineMenus.java @@ -2,6 +2,7 @@ import com.enderio.EnderIO; import com.enderio.machines.client.gui.screen.*; +import com.enderio.machines.common.io.item.MultiSlotAccess; import com.enderio.machines.common.menu.*; import com.tterrag.registrate.Registrate; import com.tterrag.registrate.util.entry.MenuEntry; @@ -32,6 +33,9 @@ private MachineMenus() {} public static final MenuEntry TRAVEL_ANCHOR = REGISTRATE .menu("travel_anchor", TravelAnchorMenu::factory, () -> TravelAnchorScreen::new) .register(); + public static final MenuEntry ITEM_BUFFER = REGISTRATE.menu("item_buffer", ItemBufferMenu::factory, () -> ItemBufferScreen::new).register(); + public static final MenuEntry POWER_BUFFER = REGISTRATE.menu("power_buffer", PowerBufferMenu::factory, () -> PowerBufferScreen::new).register(); + public static final MenuEntry OMNI_BUFFER = REGISTRATE.menu("omni_buffer", OmniBufferMenu::factory, () -> OmniBufferScreen::new).register(); public static void register() {} } diff --git a/src/machines/java/com/enderio/machines/common/menu/ItemBufferMenu.java b/src/machines/java/com/enderio/machines/common/menu/ItemBufferMenu.java new file mode 100644 index 0000000000..2316172350 --- /dev/null +++ b/src/machines/java/com/enderio/machines/common/menu/ItemBufferMenu.java @@ -0,0 +1,35 @@ +package com.enderio.machines.common.menu; + +import com.enderio.machines.common.blockentity.ItemBufferBlockEntity; +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 ItemBufferMenu extends MachineMenu { + + public ItemBufferMenu(ItemBufferBlockEntity blockEntity, Inventory inventory, int pContainerId) { + super(blockEntity, inventory, MachineMenus.ITEM_BUFFER.get(), pContainerId); + + for (int j = 0; j < 3; ++j) { + for (int k = 0; k < 3; ++k) { + this.addSlot(new MachineSlot(blockEntity.getInventory(), k + j * 3, 62 + k * 18, 17 + j * 18)); + } + } + + addInventorySlots(8,84); + } + + public static ItemBufferMenu factory(@Nullable MenuType pMenuType, int pContainerId, Inventory inventory, FriendlyByteBuf buf) { + BlockEntity entity = inventory.player.level().getBlockEntity(buf.readBlockPos()); + + if (entity instanceof ItemBufferBlockEntity castBlockEntity) + return new ItemBufferMenu(castBlockEntity, inventory, pContainerId); + LogManager.getLogger().warn("couldn't find BlockEntity"); + + return new ItemBufferMenu(null, inventory, pContainerId); + } +} diff --git a/src/machines/java/com/enderio/machines/common/menu/OmniBufferMenu.java b/src/machines/java/com/enderio/machines/common/menu/OmniBufferMenu.java new file mode 100644 index 0000000000..3a3d547c14 --- /dev/null +++ b/src/machines/java/com/enderio/machines/common/menu/OmniBufferMenu.java @@ -0,0 +1,37 @@ +package com.enderio.machines.common.menu; + +import com.enderio.machines.common.blockentity.OmniBufferBlockEntity; +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 OmniBufferMenu extends MachineMenu { + + public OmniBufferMenu(OmniBufferBlockEntity blockEntity, Inventory inventory, int pContainerId) { + super(blockEntity, inventory, MachineMenus.OMNI_BUFFER.get(), pContainerId); + + addSlot(new MachineSlot(blockEntity.getInventory(), blockEntity.getCapacitorSlot(), 12, 60)); + + for (int j = 0; j < 3; ++j) { + for (int k = 0; k < 3; ++k) { + this.addSlot(new MachineSlot(blockEntity.getInventory(), k + j * 3, 90 + k * 18, 14 + j * 18)); + } + } + + addInventorySlots(8,84); + } + + public static OmniBufferMenu factory(@Nullable MenuType pMenuType, int pContainerId, Inventory inventory, FriendlyByteBuf buf) { + BlockEntity entity = inventory.player.level().getBlockEntity(buf.readBlockPos()); + + if (entity instanceof OmniBufferBlockEntity castBlockEntity) + return new OmniBufferMenu(castBlockEntity, inventory, pContainerId); + LogManager.getLogger().warn("couldn't find BlockEntity"); + + return new OmniBufferMenu(null, inventory, pContainerId); + } +} diff --git a/src/machines/java/com/enderio/machines/common/menu/PowerBufferMenu.java b/src/machines/java/com/enderio/machines/common/menu/PowerBufferMenu.java new file mode 100644 index 0000000000..4ea29074b9 --- /dev/null +++ b/src/machines/java/com/enderio/machines/common/menu/PowerBufferMenu.java @@ -0,0 +1,31 @@ +package com.enderio.machines.common.menu; + +import com.enderio.machines.common.blockentity.PowerBufferBlockEntity; +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 PowerBufferMenu extends MachineMenu { + + public PowerBufferMenu(PowerBufferBlockEntity blockEntity, Inventory inventory, int pContainerId) { + super(blockEntity, inventory, MachineMenus.POWER_BUFFER.get(), pContainerId); + + addSlot(new MachineSlot(blockEntity.getInventory(), blockEntity.getCapacitorSlot(), 12, 60)); + + addInventorySlots(8,84); + } + + public static PowerBufferMenu factory(@Nullable MenuType pMenuType, int pContainerId, Inventory inventory, FriendlyByteBuf buf) { + BlockEntity entity = inventory.player.level().getBlockEntity(buf.readBlockPos()); + + if (entity instanceof PowerBufferBlockEntity castBlockEntity) + return new PowerBufferMenu(castBlockEntity, inventory, pContainerId); + LogManager.getLogger().warn("couldn't find BlockEntity"); + + return new PowerBufferMenu(null, inventory, pContainerId); + } +} 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 609f6160bf..17cfc2d7fd 100644 --- a/src/machines/java/com/enderio/machines/data/recipes/MachineRecipeProvider.java +++ b/src/machines/java/com/enderio/machines/data/recipes/MachineRecipeProvider.java @@ -216,6 +216,34 @@ protected void buildRecipes(Consumer finishedRecipeConsumer) { .unlockedBy("has_ingredient", InventoryChangeTrigger.TriggerInstance.hasItems(EIOBlocks.VOID_CHASSIS.get())) .save(finishedRecipeConsumer); + ShapedRecipeBuilder + .shaped(RecipeCategory.MISC, MachineBlocks.ITEM_BUFFER.get()) + .define('I', Tags.Items.INGOTS_IRON) + .define('C', Tags.Items.CHESTS) + .define('A', EIOItems.COPPER_ALLOY_INGOT.get()) + .pattern("IAI") + .pattern("ACA") + .pattern("IAI") + .unlockedBy("has_ingredient", InventoryChangeTrigger.TriggerInstance.hasItems(ItemPredicate.Builder.item().of(Tags.Items.INGOTS_IRON).build())) + .save(finishedRecipeConsumer); + + ShapedRecipeBuilder + .shaped(RecipeCategory.MISC, MachineBlocks.POWER_BUFFER.get()) + .define('C', EIOBlocks.VOID_CHASSIS.get()) + .define('A', EIOItems.COPPER_ALLOY_INGOT.get()) + .pattern(" A ") + .pattern("ACA") + .pattern(" A ") + .unlockedBy("has_ingredient", InventoryChangeTrigger.TriggerInstance.hasItems(EIOBlocks.VOID_CHASSIS.get())) + .save(finishedRecipeConsumer); + + ShapelessRecipeBuilder + .shapeless(RecipeCategory.MISC, MachineBlocks.OMNI_BUFFER.get()) + .requires( MachineBlocks.POWER_BUFFER.get()) + .requires( MachineBlocks.ITEM_BUFFER.get()) + .unlockedBy("has_ingredient", InventoryChangeTrigger.TriggerInstance.hasItems(MachineBlocks.POWER_BUFFER.get())) + .save(finishedRecipeConsumer); + ShapedEntityStorageRecipeBuilder .shaped(RecipeCategory.MISC, MachineBlocks.POWERED_SPAWNER) .define('I', EIOItems.SOULARIUM_INGOT) //TODO Maybe also soulchains? diff --git a/src/machines/resources/assets/enderio/models/block/item_buffer.json b/src/machines/resources/assets/enderio/models/block/item_buffer.json new file mode 100644 index 0000000000..bcfed5a744 --- /dev/null +++ b/src/machines/resources/assets/enderio/models/block/item_buffer.json @@ -0,0 +1,12 @@ +{ + "parent": "minecraft:block/cube", + "textures": { + "down": "enderio:block/item_buffer", + "east": "enderio:block/item_buffer", + "north": "enderio:block/item_buffer", + "particle": "enderio:block/item_buffer", + "south": "enderio:block/item_buffer", + "up": "enderio:block/item_buffer", + "west": "enderio:block/item_buffer" + } +} \ No newline at end of file diff --git a/src/machines/resources/assets/enderio/models/block/omni_buffer.json b/src/machines/resources/assets/enderio/models/block/omni_buffer.json new file mode 100644 index 0000000000..6f2416c5eb --- /dev/null +++ b/src/machines/resources/assets/enderio/models/block/omni_buffer.json @@ -0,0 +1,12 @@ +{ + "parent": "minecraft:block/cube", + "textures": { + "down": "enderio:block/omni_buffer", + "east": "enderio:block/omni_buffer", + "north": "enderio:block/omni_buffer", + "particle": "enderio:block/omni_buffer", + "south": "enderio:block/omni_buffer", + "up": "enderio:block/omni_buffer", + "west": "enderio:block/omni_buffer" + } +} \ No newline at end of file diff --git a/src/machines/resources/assets/enderio/models/block/power_buffer.json b/src/machines/resources/assets/enderio/models/block/power_buffer.json new file mode 100644 index 0000000000..7872bafc03 --- /dev/null +++ b/src/machines/resources/assets/enderio/models/block/power_buffer.json @@ -0,0 +1,12 @@ +{ + "parent": "minecraft:block/cube", + "textures": { + "down": "enderio:block/power_buffer", + "east": "enderio:block/power_buffer", + "north": "enderio:block/power_buffer", + "particle": "enderio:block/power_buffer", + "south": "enderio:block/power_buffer", + "up": "enderio:block/power_buffer", + "west": "enderio:block/power_buffer" + } +} \ No newline at end of file diff --git a/src/machines/resources/assets/enderio/textures/block/item_buffer.png b/src/machines/resources/assets/enderio/textures/block/item_buffer.png new file mode 100644 index 0000000000000000000000000000000000000000..0a477b781da3a1ac35923fb88b32402c7fd33a16 GIT binary patch literal 749 zcmVkb0zubv%yMTJw%W)(WH=u>II_kuVILou@!PTXiU*oNQ*EtWAzS8N8@`s zSSrsIUAOUAEtjIp@FOvBZm|*+5nX@Ei%7E+7Oh$wQwtW5mgY;L#RRb&7QN@-r z{rCJAU4xem&hu__20R!|CjM^!OlH4FG3B^X^pU;1?A4-VJf?Y?I{D$@f%1oKhip!w z^33LQpIyv@{t;;8ep!+4#EDvzZ&qLsS+vf#XLw*0t!s`DR{F0+VHEBwIH*Me33@pX za^SG15S*$-m-C?eqKS}cccvEE`Z^vYcX!9%gI;Qp1aPiMp^!&wk;MCTH4lLDnp*Ui zT?KxU#MB*?MRBwi3A}ovd*bseItG5fb`c~%z&M(|1YWrTlhJV&uw90v?=?e51`k>; zRZUZBTkF`DO$S9H-)?>VVQ$~5nkx8u&6T8Sl_Kw1?w>=fn4OM~dCR%SJlA0F8*Un0 f1$syDM}PqULa*r3(m>vN00000NkvXXu0mjfA{A#I literal 0 HcmV?d00001 diff --git a/src/machines/resources/assets/enderio/textures/block/omni_buffer.png b/src/machines/resources/assets/enderio/textures/block/omni_buffer.png new file mode 100644 index 0000000000000000000000000000000000000000..d9cd23b0f82a1f69d2d15817383e132966c70152 GIT binary patch literal 1435 zcmV;M1!Ve(P)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGi!vFvd!vV){sAK>D02y>eSaefwW^{L9 za%BK;VQFr3E^cLXAT%y8E;2FkAZe8V00j$4L_t(YOSRT(Z`)KD2XMZ}Xq&c4X*W>W zw6d+YT$b30oy2i$$Iiu$muuU!NtdKax^!)`OV^@_F}5LrhF~BrlMoV@!HbCsArR9f zkhqAUNqaR3@p|F|@OMr$nk7X@+oYc&>!kJHIp;Z#&of7yPOz~ISQ$4=(lkuF-7x8< z4H#tH6EtO@Trg>T)%wde&GB){1qZEGc=`cW+?Qp1;V=Z_8i;xvf|?4P8U^yLH)3EF z85l`?h!zEKH?>9t0S?*i@bm+0EDKyT0vgm`!!_Vo9|vnJD?zCJaV0}1y{r;hr( zV52AqrIJ7^G96a>EtZFJE6cfh&8H}^Ye3JyK+oV{FFsBGD`4Nq=-z!VzVQ71k-ei` z0_;972yqQaK%d!cYCaAwl$jae6FRUV(GUzW!Jw$?K+7RyjP0Lz>A>XJ==j0W@$7On zTdVjL1xVp`2{4(>1H;1uBO|7vp`8Ing){@;VSrnat%vBTG1t_XbK;=0OMuPm1zwGU zlk-Eb+1x)e(my=hXR#=m42U{vSEG3zoD2h^rh?1(1&VtrNKf&8n?R2TQpHlDSY#y$ ztZp~71+bC;rXkDVb3=H1B$4{rEx@gW*+?wli13aWZ;$zH;cU5@E|%K@rWppv_F)A9 zdIkqD`@I$mmRizv;B^f=!5}cGU7i;;4H#MBBC6(@Q(UQ-CmnXBGsQ~sc!>nGrl?Cm zzo~a{0FU2eHn#xU)8tD zq0<%l?0ju4TduVSI2^#K=xge3t%6Ju#bYo)9)ed@@XOIqJhPR&d^Yh~BYyE*>WUFi ztdeq=plNul04}V``po6rwF@&>&u6Y)$iAIF(a1a!FlMuYTNZ(Aw9a1CS*D?c4uOa& zCuZNwU%xc>{-xOuUe8@G)XyNm>GJ`3m30Z|>_z_(prmr|m2bSY_}PccU%XTJys&aM zT|$8W-vF}6I|Djs;j7B2t-^_u4xi8A z^&Ym{p-Vt#FKPws*aswl59`rP{>Iu5pVn`ExqkbT>UY&MFE7^D+5(QaTtHrUyY`}H zW7t`yfoL=ki}7Ji%@l4ne*XIOueV?Q?PlYba$|F$x?Fy#bLQ@LX zYtRZHM=P%^1NrC9RzaqSY%XK=qfssr0Vy>TpD&kIH_GdqrS;9?$NF_RuAO98pQjJJdvu8)WgxHF+tK7YI4tl5w(( pq%D)%k&(kq2d1atDF;kX{{t20%|8Px#1ZP1_K>z@;j|==^1poj532;bRa{vGi!vFvd!vV){sAK>D02y>eSaefwW^{L9 za%BK;VQFr3E^cLXAT%y8E;2FkAZe8V00f^&L_t(YOSRV9iyKuO2XOxtANtT%SzEfc z-CHirTr!hnGP83}W-^;(CfOvLY?Ew~ZMM6c?xnj@thKG6RJ`G(AcB|bLvayNECmHG zSSj?WAU+rW0Kc;*R3i&6rVF2k;Y^tCEZk|He#!v;uc zE2-OdVgB2#2Vbq<-|5}^dh`Cmg{?}f%lw4;Q#OQ*?pMivy=oXIsN2L#guC11=`nvLbn=IT~sb*p}UZLZOE=g#8ken2=3 zLj{OAS9i{e#!=0hHh)+ru6K-f|Z9B{zY)L(G4{ViyUdoch2002ovPDHLkV1lv>WQG6$ literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/enderio/textures/block/item_buffer.png b/src/main/resources/assets/enderio/textures/block/item_buffer.png new file mode 100644 index 0000000000000000000000000000000000000000..0a477b781da3a1ac35923fb88b32402c7fd33a16 GIT binary patch literal 749 zcmVkb0zubv%yMTJw%W)(WH=u>II_kuVILou@!PTXiU*oNQ*EtWAzS8N8@`s zSSrsIUAOUAEtjIp@FOvBZm|*+5nX@Ei%7E+7Oh$wQwtW5mgY;L#RRb&7QN@-r z{rCJAU4xem&hu__20R!|CjM^!OlH4FG3B^X^pU;1?A4-VJf?Y?I{D$@f%1oKhip!w z^33LQpIyv@{t;;8ep!+4#EDvzZ&qLsS+vf#XLw*0t!s`DR{F0+VHEBwIH*Me33@pX za^SG15S*$-m-C?eqKS}cccvEE`Z^vYcX!9%gI;Qp1aPiMp^!&wk;MCTH4lLDnp*Ui zT?KxU#MB*?MRBwi3A}ovd*bseItG5fb`c~%z&M(|1YWrTlhJV&uw90v?=?e51`k>; zRZUZBTkF`DO$S9H-)?>VVQ$~5nkx8u&6T8Sl_Kw1?w>=fn4OM~dCR%SJlA0F8*Un0 f1$syDM}PqULa*r3(m>vN00000NkvXXu0mjfA{A#I literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/enderio/textures/block/power_buffer.png b/src/main/resources/assets/enderio/textures/block/power_buffer.png new file mode 100644 index 0000000000000000000000000000000000000000..c1ac1870d883134883c01c6f8c228cf312b4d41d GIT binary patch literal 1327 zcmV+~1Px#1ZP1_K>z@;j|==^1poj532;bRa{vGi!vFvd!vV){sAK>D02y>eSaefwW^{L9 za%BK;VQFr3E^cLXAT%y8E;2FkAZe8V00f^&L_t(YOSRV9iyKuO2XOxtANtT%SzEfc z-CHirTr!hnGP83}W-^;(CfOvLY?Ew~ZMM6c?xnj@thKG6RJ`G(AcB|bLvayNECmHG zSSj?WAU+rW0Kc;*R3i&6rVF2k;Y^tCEZk|He#!v;uc zE2-OdVgB2#2Vbq<-|5}^dh`Cmg{?}f%lw4;Q#OQ*?pMivy=oXIsN2L#guC11=`nvLbn=IT~sb*p}UZLZOE=g#8ken2=3 zLj{OAS9i{e#!=0hHh)+ru6K-f|Z9B{zY)L(G4{ViyUdoch2002ovPDHLkV1lv>WQG6$ literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/enderio/textures/gui/buffer_full.png b/src/main/resources/assets/enderio/textures/gui/buffer_full.png deleted file mode 100644 index d7d2a3a2d2145c01ca88c01a716244064dca81a8..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1897 zcmeAS@N?(olHy`uVBq!ia0y~yU<5K58911MRQ8&P5Fo{p?&#~tz_78O`%fY(0|PTd zfKP}kP~61dt{?4unj7H7^ zkH}&M2ENT8%=ozIPA~%l(`Qc?$B>G+x3^wr-FA>*OFa5cGxw5=%>DmMS532xJK5MI zu)FcA^wXZ;AGYf*oaZ^fRxX+H&&3 z<c}7N-gztPp4h)Rv`s+Ly>i#6GG>3p+IEF_zW%0-3J`6SnIJBz*t(>C>;WS6|=1Oq%|K?a#lT z&wu`W`SRoS{^Li?6Mpg3{I1LU#nMtIyr+)Y;^^d@HP#I8c1Hny*TC@Ro+HSY-(z(d z86N1Lcpmn5uVwMNhhEtXb?I?YU%9`nj}Zj93*?3!@3T08TEP04a(-8TULTXmb71G` zn8TZ8K_PsNVNd4LHvP}rL?P;d9{as+8dN=pg2V2~bE33+87<0ZW>;)GJSTeVC8-AU zwO2l*-rEKW7?5+A3hrM8g(cWNmW=XA!P!d<9ppjQ-YMU@j$zK;bEY=;Q_ro9%H%!Z zKRf8Ke8%lCh+?1%VV(jT_13RAd#wrE3uQ)@6KprOGf1>&-p|WoFyMQ0*ZJ!FdM1ln zo?S1CE}Ld=NR8(_(BsRHmcwL_EZiVDo8in2mV{$!48~@RGd2#GRJ6qbi+{|vXO(OB Rs{8=gaGtJyF6*2UngBC@X9NHM diff --git a/src/main/resources/assets/enderio/textures/gui/item_buffer.png b/src/main/resources/assets/enderio/textures/gui/item_buffer.png new file mode 100644 index 0000000000000000000000000000000000000000..392adc7630a40c4d83f5b8eb4d4524b92414f522 GIT binary patch literal 1239 zcmeAS@N?(olHy`uVBq!ia0y~yU<5K5893O0R7}x|G$6%U;1OBOz`(Z|gc%`7D zG_Usm!N-wLKR%ty({OzAnc(c!1Cb10_`|zmG@s7Z|B%8UqX)EFh=Df|a2G zq?-eXQ5hgna=?LJhddT028KHvPuvt37!GJRgp*?o0X+f`^BEl&1b~5ql|qD=2heZ8 z5cFWUA>Oe3U(dF=TkF5cFo-jKIP%{-KmBbrAJ8&ukcDr6fxLm4f$;zz&`@ij(YOSF z{sL)&=>oDgFgM&~tax=k<96il^z)1l+!U;V!2tBTbsQspvtYJ??FX9#B;dw3G-t9i zFccWPWdH^2s*R7`6wH}+t~}N!-MEM8$Lf``>w&Td-U7Ao?T`iPW8BWnz+my93@E^U z2k6FxOm;@#h4hE)%J6t)(*BX;=GSEd25^ez%$oN<@6liaV&VRc@ z^v2YLN!kbD8D;L5r|bt}7%shU*LFQGUZKQb+wQgRk2JFaC&MHLsuL&M6&M|a7*uFN mF#HfuVenvTAeLBSUCp?^>*{6IU1EKpp!9V0b6Mw<&;$TzK=b7Q literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/enderio/textures/gui/omni_buffer.png b/src/main/resources/assets/enderio/textures/gui/omni_buffer.png new file mode 100644 index 0000000000000000000000000000000000000000..63b0e884a9c2faa910f0761726a1291384d2ee5a GIT binary patch literal 1368 zcmeAS@N?(olHy`uVBq!ia0y~yU<5K5893O0R7}x|G$6%U;1OBOz`(Z|gc%~Q*O}gXsZEEh+5QmJ}%R+@VPO55|Zfq>G zuiNM6g1Z6T0*9P}=KcL6uD^ceo;{WBYzIzf8?9gWTH%8x!=uAfgYvdUeXV5f=V>^s z%D~{j#K53}ol4<2P_(mV<+j|-b{p2)El)phuvM0UVSzoz`BQ%{A6 z!=BH-Q$Q{-W_AEkEI^FO0Lh?$I~-5k6tIUdF!UXo7(`q@zMn6|kjCavQ@nrnVQq#p z3=Kch_QkDVxbF47(@%wFEvwY{w|&(rxqo~tEDe&iOcpYHiM#K%J^mNEOh6G1 zTmnF)KqUxWK;{ibhj$Ej{6k@8(T;~IFU2`VLbp~%44y-+pw|DE~u!Qg?&vh)!4ZuX^0hIr;(A=Kk z7;D1E-w(Z3KIgSjVlZs?y7xztS%H&b5(CwVlg<;UZz$BILJT%6Bsu!!?7Ivhk9>0` SR_MO~1;3}OpUXO@geCy_%R*ZK literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/enderio/textures/gui/power_buffer.png b/src/main/resources/assets/enderio/textures/gui/power_buffer.png new file mode 100644 index 0000000000000000000000000000000000000000..c7b74337c7c1177ec5c7e7c239c543b5c026a13b GIT binary patch literal 1265 zcmeAS@N?(olHy`uVBq!ia0y~yU<5K5893O0R7}x|G$6%U;1OBOz`(Z|gc%+Rj>tknSwZGq`iJ)f8wcPvnwW!^i}>DkoGx0_fOYA)TF(J@_B=UnUI z{}VR<^@!Tw$)U)&?d5Ozm~~5I^6qsqKPb|DR%Iin^kE&t5pnTnZwf3*?i>(iKk(3r zfrWv^fx!VgWhT*ZH_!aU-@5Vw!3I+{g?o3_SClt0a4>K*Ffr9GU&IYpPL~IRAUYF5>tXZ z$j@(p(ZSIm3km zMH$G?H#TAlsx#f(__)(So|oawL|_U91yTbr2sjw#apfEjZv2?*V7-sGgSfCk_D6Fj z$QcK>0BuBZ^^7u>1Hp~9U$6BoXR20_s8E>!%NYk|=hZRJFk?7*9+>0K@!BLZD7AB$ z|8HXkIz|Dgh=GYJ3~@#lV197`l_u0;Fn&-X+IcmX#3x_gH}keeb33pMWAJqKb6Mw< G&;$T Date: Sun, 13 Aug 2023 21:55:09 +0200 Subject: [PATCH 02/10] Fixed buffers not being able to push items --- .../machines/common/blockentity/ItemBufferBlockEntity.java | 2 +- .../machines/common/blockentity/OmniBufferBlockEntity.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/machines/java/com/enderio/machines/common/blockentity/ItemBufferBlockEntity.java b/src/machines/java/com/enderio/machines/common/blockentity/ItemBufferBlockEntity.java index 7e6616b3a4..0bfd95b3b3 100644 --- a/src/machines/java/com/enderio/machines/common/blockentity/ItemBufferBlockEntity.java +++ b/src/machines/java/com/enderio/machines/common/blockentity/ItemBufferBlockEntity.java @@ -19,7 +19,7 @@ public ItemBufferBlockEntity(BlockEntityType type, BlockPos worldPosition, Bl @Override public @Nullable MachineInventoryLayout getInventoryLayout() { return MachineInventoryLayout.builder() - .inputSlot(9) + .storageSlot(9) .build(); } diff --git a/src/machines/java/com/enderio/machines/common/blockentity/OmniBufferBlockEntity.java b/src/machines/java/com/enderio/machines/common/blockentity/OmniBufferBlockEntity.java index 71be38e39b..98b3e0d8fe 100644 --- a/src/machines/java/com/enderio/machines/common/blockentity/OmniBufferBlockEntity.java +++ b/src/machines/java/com/enderio/machines/common/blockentity/OmniBufferBlockEntity.java @@ -22,7 +22,7 @@ public OmniBufferBlockEntity(BlockEntityType type, BlockPos worldPosition, Bl public @Nullable MachineInventoryLayout getInventoryLayout() { return MachineInventoryLayout .builder() - .inputSlot(9) + .storageSlot(9) .capacitor() .build(); } From 43150b87fb473cc420782e87836779b1a849677a Mon Sep 17 00:00:00 2001 From: Trytoon Date: Mon, 14 Aug 2023 13:14:30 +0200 Subject: [PATCH 03/10] Implemented requested changes + moved I/O update code to the be --- .../java/com/enderio/core/CoreNBTKeys.java | 8 ++++ .../enderio/core/common/util/NumberUtils.java | 23 +++++++++ .../resources/assets/enderio/lang/en_ud.json | 2 + .../resources/assets/enderio/lang/en_us.json | 2 + .../enderio/models/block/item_buffer.json | 23 --------- .../models/block/item_buffer_front_on.json | 6 --- .../enderio/models/block/item_buffer_on.json | 26 ---------- .../client/gui/screen/OmniBufferScreen.java | 22 +++------ .../client/gui/screen/PowerBufferScreen.java | 25 +++------- .../gui/widget/EnergyTextboxWidget.java | 13 +---- .../blockentity/PowerBufferBlockEntity.java | 45 +++++++++++++----- .../com/enderio/base/common/lang/EIOLang.java | 6 ++- .../enderio/textures/block/item_buffer.png | Bin 749 -> 0 bytes .../enderio/textures/block/power_buffer.png | Bin 1327 -> 0 bytes 14 files changed, 90 insertions(+), 111 deletions(-) create mode 100644 src/core/java/com/enderio/core/common/util/NumberUtils.java delete mode 100644 src/generated/resources/assets/enderio/models/block/item_buffer.json delete mode 100644 src/generated/resources/assets/enderio/models/block/item_buffer_front_on.json delete mode 100644 src/generated/resources/assets/enderio/models/block/item_buffer_on.json delete mode 100644 src/main/resources/assets/enderio/textures/block/item_buffer.png delete mode 100644 src/main/resources/assets/enderio/textures/block/power_buffer.png diff --git a/src/core/java/com/enderio/core/CoreNBTKeys.java b/src/core/java/com/enderio/core/CoreNBTKeys.java index 2529f90c64..fd1c4718fe 100644 --- a/src/core/java/com/enderio/core/CoreNBTKeys.java +++ b/src/core/java/com/enderio/core/CoreNBTKeys.java @@ -39,4 +39,12 @@ public class CoreNBTKeys { public static final String ANCHOR_VISIBILITY = "AnchorVisibility"; //endregion + + //region Buffer data + + public static final String BUFFER_MAX_INPUT = "BufferMaxInput"; + + public static final String BUFFER_MAX_OUTPUT = "BufferMaxOutput"; + + //endregion } diff --git a/src/core/java/com/enderio/core/common/util/NumberUtils.java b/src/core/java/com/enderio/core/common/util/NumberUtils.java new file mode 100644 index 0000000000..50be9d0891 --- /dev/null +++ b/src/core/java/com/enderio/core/common/util/NumberUtils.java @@ -0,0 +1,23 @@ +package com.enderio.core.common.util; + +public class NumberUtils { + + public static int getInteger(String value) { + String integerValue = value.replaceAll("[., ]", ""); + + try { + return Integer.parseInt(integerValue); + } catch(Exception e) { + return 0; + } + } + + public static long getLong(String value) { + String longValue = value.replaceAll("[., ]", ""); + try { + return Long.parseLong(longValue); + } catch(Exception e) { + return 0; + } + } +} diff --git a/src/generated/resources/assets/enderio/lang/en_ud.json b/src/generated/resources/assets/enderio/lang/en_ud.json index 6862f05185..94eb4a2d2d 100644 --- a/src/generated/resources/assets/enderio/lang/en_ud.json +++ b/src/generated/resources/assets/enderio/lang/en_ud.json @@ -254,6 +254,7 @@ "gui.enderio.fluid_conduit.change_fluid1": ":pınןℲ pǝʞɔoꞀ", "gui.enderio.fluid_conduit.change_fluid2": "¡ʇǝsǝɹ oʇ ʞɔıןƆ", "gui.enderio.fluid_conduit.change_fluid3": "%s :pınןℲ", + "gui.enderio.input": "ʇnduI", "gui.enderio.ioconfig": "uoıʇɐɹnbıɟuoƆ OI", "gui.enderio.ioconfig.both": "ןןnԀ / ɥsnԀ", "gui.enderio.ioconfig.disabled": "pǝןqɐsıᗡ", @@ -263,6 +264,7 @@ "gui.enderio.ioconfig.push": "ɥsnԀ", "gui.enderio.nocap.desc": "¡ʞɹoʍ uɐɔ ǝuıɥɔɐɯ sıɥʇ \n os ɹoʇıɔɐdɐɔ ʎuɐ ʇɹǝsuI", "gui.enderio.nocap.title": "buıssıW ɹoʇıɔɐdɐƆ", + "gui.enderio.output": "ʇndʇnO", "gui.enderio.progress": "%s%% ssǝɹboɹԀ", "gui.enderio.range": "ǝbuɐᴚ", "gui.enderio.range.hide": "ǝbuɐᴚ ǝpıH", diff --git a/src/generated/resources/assets/enderio/lang/en_us.json b/src/generated/resources/assets/enderio/lang/en_us.json index 0ba1ff9e73..7c1e0c5e11 100644 --- a/src/generated/resources/assets/enderio/lang/en_us.json +++ b/src/generated/resources/assets/enderio/lang/en_us.json @@ -254,6 +254,7 @@ "gui.enderio.fluid_conduit.change_fluid1": "Locked Fluid:", "gui.enderio.fluid_conduit.change_fluid2": "Click to reset!", "gui.enderio.fluid_conduit.change_fluid3": "Fluid: %s", + "gui.enderio.input": "Input", "gui.enderio.ioconfig": "IO Configuration", "gui.enderio.ioconfig.both": "Push / Pull", "gui.enderio.ioconfig.disabled": "Disabled", @@ -263,6 +264,7 @@ "gui.enderio.ioconfig.push": "Push", "gui.enderio.nocap.desc": "Insert any capacitor so \n this machine can work!", "gui.enderio.nocap.title": "Capacitor Missing", + "gui.enderio.output": "Output", "gui.enderio.progress": "Progress %s%%", "gui.enderio.range": "Range", "gui.enderio.range.hide": "Hide Range", diff --git a/src/generated/resources/assets/enderio/models/block/item_buffer.json b/src/generated/resources/assets/enderio/models/block/item_buffer.json deleted file mode 100644 index ec85aabc80..0000000000 --- a/src/generated/resources/assets/enderio/models/block/item_buffer.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "parent": "minecraft:block/block", - "children": { - "frame": { - "parent": "enderio:block/machine_frame" - }, - "front": { - "parent": "enderio:block/item_buffer_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/block/item_buffer_front_on.json b/src/generated/resources/assets/enderio/models/block/item_buffer_front_on.json deleted file mode 100644 index 375b385cc1..0000000000 --- a/src/generated/resources/assets/enderio/models/block/item_buffer_front_on.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "parent": "enderio:block/item_buffer_front", - "textures": { - "front": "enderio:block/item_buffer_front_on" - } -} \ No newline at end of file diff --git a/src/generated/resources/assets/enderio/models/block/item_buffer_on.json b/src/generated/resources/assets/enderio/models/block/item_buffer_on.json deleted file mode 100644 index eeba28c2a7..0000000000 --- a/src/generated/resources/assets/enderio/models/block/item_buffer_on.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "parent": "minecraft:block/block", - "children": { - "frame": { - "parent": "enderio:block/machine_frame" - }, - "front": { - "parent": "enderio:block/item_buffer_front", - "textures": { - "front": "enderio:block/item_buffer_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/machines/java/com/enderio/machines/client/gui/screen/OmniBufferScreen.java b/src/machines/java/com/enderio/machines/client/gui/screen/OmniBufferScreen.java index c02a0a804a..6fd4a0f6de 100644 --- a/src/machines/java/com/enderio/machines/client/gui/screen/OmniBufferScreen.java +++ b/src/machines/java/com/enderio/machines/client/gui/screen/OmniBufferScreen.java @@ -37,10 +37,12 @@ protected void init() { addRenderableWidget(new IOConfigButton<>(this, leftPos + imageWidth - 6 - 16, topPos + 22, 16, 16, menu, this::addRenderableWidget, font)); input = new EnergyTextboxWidget(this, () -> this.getMenu().getBlockEntity().getEnergyStorage().getMaxEnergyUse(), this.font, leftPos + 33, topPos + 18, 49, this.font.lineHeight + 2, Component.empty()); - input.setValue(input.formatEnergy(Integer.toString(this.getMenu().getBlockEntity().getMaxInput()))); + input.setResponder(getMenu().getBlockEntity()::setMaxInput); + input.setValue(Integer.toString(this.getMenu().getBlockEntity().getMaxInput())); addRenderableWidget(input); output = new EnergyTextboxWidget(this, () -> this.getMenu().getBlockEntity().getEnergyStorage().getMaxEnergyUse(), this.font, leftPos + 33, topPos + 48, 49, this.font.lineHeight + 2, Component.empty()); + output.setResponder(getMenu().getBlockEntity()::setMaxOutput); output.setValue(output.formatEnergy(Integer.toString(this.getMenu().getBlockEntity().getMaxOutput()))); addRenderableWidget(output); @@ -60,27 +62,17 @@ protected Vector2i getBackgroundImageSize() { public void render(GuiGraphics guiGraphics, int pMouseX, int pMouseY, float pPartialTicks) { super.render(guiGraphics, pMouseX, pMouseY, pPartialTicks); PowerBufferBlockEntity be = this.getMenu().getBlockEntity(); - guiGraphics.drawString(font, "Input:", leftPos + 33, topPos + 18 - font.lineHeight - 2, 1, false); - guiGraphics.drawString(font, "Output:", leftPos + 33, topPos + 48 - font.lineHeight - 2, 1, false); + guiGraphics.drawString(font, EIOLang.INPUT.getString() + ":", leftPos + 33, topPos + 18 - font.lineHeight - 2, 1, false); + guiGraphics.drawString(font, EIOLang.OUTPUT.getString() + ":", leftPos + 33, topPos + 48 - font.lineHeight - 2, 1, false); } - - //Reset values if no capacitor, else display the value stored in the power buffer @Override protected void containerTick() { super.containerTick(); PowerBufferBlockEntity be = this.getMenu().getBlockEntity(); if (be != null) { - if (be.requiresCapacitor() && be.isCapacitorInstalled()) { - be.setMaxInput(input.getInteger()); - be.setMaxOutput(output.getInteger()); - } else { - be.setMaxInput(0); - input.setValue("0"); - - be.setMaxOutput(0); - output.setValue("0"); - } + input.setValue(input.formatEnergy(Integer.toString(be.getMaxInput()))); + output.setValue(output.formatEnergy(Integer.toString(be.getMaxOutput()))); } } } diff --git a/src/machines/java/com/enderio/machines/client/gui/screen/PowerBufferScreen.java b/src/machines/java/com/enderio/machines/client/gui/screen/PowerBufferScreen.java index 1b32be3f33..c4ebbc6c2d 100644 --- a/src/machines/java/com/enderio/machines/client/gui/screen/PowerBufferScreen.java +++ b/src/machines/java/com/enderio/machines/client/gui/screen/PowerBufferScreen.java @@ -37,10 +37,12 @@ protected void init() { addRenderableWidget(new IOConfigButton<>(this, leftPos + imageWidth - 6 - 16, topPos + 22, 16, 16, menu, this::addRenderableWidget, font)); input = new EnergyTextboxWidget(this, () -> this.getMenu().getBlockEntity().getEnergyStorage().getMaxEnergyUse(), this.font, leftPos + 40, topPos + 18, 95, this.font.lineHeight + 2, Component.empty()); + input.setResponder(getMenu().getBlockEntity()::setMaxInput); input.setValue(Integer.toString(this.getMenu().getBlockEntity().getMaxInput())); addRenderableWidget(input); output = new EnergyTextboxWidget(this, () -> this.getMenu().getBlockEntity().getEnergyStorage().getMaxEnergyUse(), this.font, leftPos + 40, topPos + 48, 95, this.font.lineHeight + 2, Component.empty()); + output.setResponder(getMenu().getBlockEntity()::setMaxOutput); output.setValue(output.formatEnergy(Integer.toString(this.getMenu().getBlockEntity().getMaxOutput()))); addRenderableWidget(output); @@ -60,31 +62,18 @@ protected Vector2i getBackgroundImageSize() { public void render(GuiGraphics guiGraphics, int pMouseX, int pMouseY, float pPartialTicks) { super.render(guiGraphics, pMouseX, pMouseY, pPartialTicks); PowerBufferBlockEntity be = this.getMenu().getBlockEntity(); - guiGraphics.drawString(font, "Input:", leftPos + 33, topPos + 18 - font.lineHeight - 2, 1, false); - guiGraphics.drawString(font, "Output:", leftPos + 33, topPos + 48 - font.lineHeight - 2, 1, false); + guiGraphics.drawString(font, EIOLang.INPUT.getString() +":", leftPos + 40, topPos + 18 - font.lineHeight - 2, 1, false); + guiGraphics.drawString(font, EIOLang.OUTPUT.getString() +":", leftPos + 40, topPos + 48 - font.lineHeight - 2, 1, false); } - - //Reset values if no capacitor, else display the value stored in the power buffer - //There is probably a better way of setting the energy is the block entity + //Syncronize the block entity values with what is displayed to the player @Override protected void containerTick() { super.containerTick(); PowerBufferBlockEntity be = this.getMenu().getBlockEntity(); if (be != null) { - if (be.requiresCapacitor() && be.isCapacitorInstalled()) { - if (!input.isFocused()) - be.setMaxInput(input.getInteger()); - - if (!output.isFocused()) - be.setMaxOutput(output.getInteger()); - } else { - be.setMaxInput(0); - input.setValue("0"); - - be.setMaxOutput(0); - output.setValue("0"); - } + input.setValue(input.formatEnergy(Integer.toString(be.getMaxInput()))); + output.setValue(output.formatEnergy(Integer.toString(be.getMaxOutput()))); } } } diff --git a/src/machines/java/com/enderio/machines/client/gui/widget/EnergyTextboxWidget.java b/src/machines/java/com/enderio/machines/client/gui/widget/EnergyTextboxWidget.java index a8c2423cd0..185f757b90 100644 --- a/src/machines/java/com/enderio/machines/client/gui/widget/EnergyTextboxWidget.java +++ b/src/machines/java/com/enderio/machines/client/gui/widget/EnergyTextboxWidget.java @@ -5,6 +5,7 @@ import net.minecraft.client.gui.components.EditBox; import net.minecraft.client.gui.screens.Screen; import net.minecraft.network.chat.Component; + import java.text.DecimalFormat; import java.text.NumberFormat; import java.util.Locale; @@ -99,16 +100,6 @@ public String formatEnergy(String value) { return "0"; } } - - public int getInteger() { - String integer = getValue().replace(",", ""); - - try { - return Integer.parseInt(integer); - } catch(Exception e) { - return 0; - } - } @Override public void renderWidget(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick) { @@ -117,7 +108,7 @@ public void renderWidget(GuiGraphics guiGraphics, int mouseX, int mouseY, float } public void renderToolTip(GuiGraphics guiGraphics, int mouseX, int mouseY) { - if (mouseX >= getX() && mouseX <= getX() + width && mouseY >= getY() && mouseY <= getY() + height && !isFocused()) { + if (mouseX >= getX() && mouseX <= getX() + width && mouseY >= getY() && mouseY <= getY() + height && !isFocused() && maxEnergy.get() != 0) { guiGraphics.renderTooltip(displayOn.getMinecraft().font, Component.literal(formatEnergy(getValue()) +"/" +formatEnergy(Integer.toString(maxEnergy.get())) +" µI"), mouseX, mouseY); } } diff --git a/src/machines/java/com/enderio/machines/common/blockentity/PowerBufferBlockEntity.java b/src/machines/java/com/enderio/machines/common/blockentity/PowerBufferBlockEntity.java index 067c2fe856..6248c1fdb2 100644 --- a/src/machines/java/com/enderio/machines/common/blockentity/PowerBufferBlockEntity.java +++ b/src/machines/java/com/enderio/machines/common/blockentity/PowerBufferBlockEntity.java @@ -1,9 +1,12 @@ package com.enderio.machines.common.blockentity; +import com.enderio.EnderIO; import com.enderio.api.capacitor.CapacitorModifier; import com.enderio.api.capacitor.QuadraticScalable; import com.enderio.api.io.energy.EnergyIOMode; +import com.enderio.core.CoreNBTKeys; import com.enderio.core.common.network.slot.IntegerNetworkDataSlot; +import com.enderio.core.common.util.NumberUtils; import com.enderio.machines.common.blockentity.base.PoweredMachineBlockEntity; import com.enderio.machines.common.config.MachinesConfig; import com.enderio.machines.common.io.energy.MachineEnergyStorage; @@ -28,11 +31,9 @@ public class PowerBufferBlockEntity extends PoweredMachineBlockEntity { int maxInput = 0; protected IntegerNetworkDataSlot inputDataSlot; - private final String NBT_INPUT = "BufferMaxInput"; int maxOutput = 0; protected IntegerNetworkDataSlot outputDataSlot; - private final String NBT_OUTPUT = "BufferMaxOutput"; //todo: energy balancing @@ -67,14 +68,14 @@ protected boolean isActive() { public AbstractContainerMenu createMenu(int containerId, Inventory playerInventory, Player player) { return new PowerBufferMenu(this, playerInventory, containerId); } - - public void setMaxOutput(int maxOutput) { - this.maxOutput = maxOutput; + + public void setMaxOutput(String pMaxOutput) { + this.maxOutput = NumberUtils.getInteger(pMaxOutput); clientUpdateSlot(outputDataSlot, maxOutput); } - public void setMaxInput(int maxInput) { - this.maxInput = maxInput; + public void setMaxInput(String pMaxInput) { + this.maxInput = NumberUtils.getInteger(pMaxInput); clientUpdateSlot(inputDataSlot, maxInput); } @@ -114,6 +115,11 @@ public void pushEnergy() { } } + @Override + protected boolean shouldPushEnergyTo(Direction direction) { + return getIOConfig().getMode(direction).canPush(); + } + @Override protected MachineEnergyStorage createEnergyStorage(EnergyIOMode energyIOMode, Supplier capacity, Supplier usageRate) { return new MachineEnergyStorage(getIOConfig(), energyIOMode, capacity, usageRate) { @@ -144,14 +150,31 @@ public int receiveEnergy(int maxReceive, boolean simulate) { @Override public void saveAdditional(CompoundTag pTag) { super.saveAdditional(pTag); - pTag.putInt(NBT_INPUT, maxInput); - pTag.putInt(NBT_OUTPUT, maxOutput); + pTag.putInt(CoreNBTKeys.BUFFER_MAX_INPUT, maxInput); + pTag.putInt(CoreNBTKeys.BUFFER_MAX_OUTPUT, maxOutput); } @Override public void load(CompoundTag pTag) { super.load(pTag); - maxInput = pTag.getInt(NBT_INPUT); - maxOutput = pTag.getInt(NBT_OUTPUT); + maxInput = pTag.getInt(CoreNBTKeys.BUFFER_MAX_INPUT); + maxOutput = pTag.getInt(CoreNBTKeys.BUFFER_MAX_OUTPUT); } + + //Reset values if capacitor is added/removed and transmit it to the textbox + +// @Override +// protected void onInventoryContentsChanged(int slot) { +// super.onInventoryContentsChanged(slot); +// MachineInventoryLayout inventoryLayout = getInventoryLayout(); +// if (inventoryLayout != null && inventoryLayout.getCapacitorSlot() == slot) { +// if (requiresCapacitor() && isCapacitorInstalled()) { +// setMaxInput(getEnergyStorage().getMaxEnergyUse()); +// setMaxOutput(getEnergyStorage().getMaxEnergyUse()); +// } else { +// setMaxInput(0); +// setMaxOutput(0); +// } +// } +// } } diff --git a/src/main/java/com/enderio/base/common/lang/EIOLang.java b/src/main/java/com/enderio/base/common/lang/EIOLang.java index bc8791068c..62bb6b557f 100644 --- a/src/main/java/com/enderio/base/common/lang/EIOLang.java +++ b/src/main/java/com/enderio/base/common/lang/EIOLang.java @@ -61,9 +61,13 @@ public class EIOLang { public static final Component FLUID_CONDUIT_CHANGE_FLUID1 = REGISTRATE.addLang("gui", EnderIO.loc("fluid_conduit.change_fluid1"), "Locked Fluid:"); public static final Component FLUID_CONDUIT_CHANGE_FLUID2 = REGISTRATE.addLang("gui", EnderIO.loc("fluid_conduit.change_fluid2"), "Click to reset!"); public static final MutableComponent FLUID_CONDUIT_CHANGE_FLUID3 = REGISTRATE.addLang("gui", EnderIO.loc("fluid_conduit.change_fluid3"), "Fluid: %s"); - public static final MutableComponent TANK_EMPTY_STRING = REGISTRATE.addLang("tooltip", EnderIO.loc("fluid_tank.tank_empty_tooltip"), "Empty tank"); public static final MutableComponent FLUID_TANK_TOOLTIP = REGISTRATE.addLang("tooltip", EnderIO.loc("fluid_tank.tank_tooltip"), "%d/%d mb of %s");//[amount]/[capacity] mb of [FluidName] + + public static final Component INPUT = REGISTRATE.addLang("gui", EnderIO.loc("input"), "Input"); + + public static final Component OUTPUT = REGISTRATE.addLang("gui", EnderIO.loc("output"), "Output"); + // endregion // region Dark Steel diff --git a/src/main/resources/assets/enderio/textures/block/item_buffer.png b/src/main/resources/assets/enderio/textures/block/item_buffer.png deleted file mode 100644 index 0a477b781da3a1ac35923fb88b32402c7fd33a16..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 749 zcmVkb0zubv%yMTJw%W)(WH=u>II_kuVILou@!PTXiU*oNQ*EtWAzS8N8@`s zSSrsIUAOUAEtjIp@FOvBZm|*+5nX@Ei%7E+7Oh$wQwtW5mgY;L#RRb&7QN@-r z{rCJAU4xem&hu__20R!|CjM^!OlH4FG3B^X^pU;1?A4-VJf?Y?I{D$@f%1oKhip!w z^33LQpIyv@{t;;8ep!+4#EDvzZ&qLsS+vf#XLw*0t!s`DR{F0+VHEBwIH*Me33@pX za^SG15S*$-m-C?eqKS}cccvEE`Z^vYcX!9%gI;Qp1aPiMp^!&wk;MCTH4lLDnp*Ui zT?KxU#MB*?MRBwi3A}ovd*bseItG5fb`c~%z&M(|1YWrTlhJV&uw90v?=?e51`k>; zRZUZBTkF`DO$S9H-)?>VVQ$~5nkx8u&6T8Sl_Kw1?w>=fn4OM~dCR%SJlA0F8*Un0 f1$syDM}PqULa*r3(m>vN00000NkvXXu0mjfA{A#I diff --git a/src/main/resources/assets/enderio/textures/block/power_buffer.png b/src/main/resources/assets/enderio/textures/block/power_buffer.png deleted file mode 100644 index c1ac1870d883134883c01c6f8c228cf312b4d41d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1327 zcmV+~1Px#1ZP1_K>z@;j|==^1poj532;bRa{vGi!vFvd!vV){sAK>D02y>eSaefwW^{L9 za%BK;VQFr3E^cLXAT%y8E;2FkAZe8V00f^&L_t(YOSRV9iyKuO2XOxtANtT%SzEfc z-CHirTr!hnGP83}W-^;(CfOvLY?Ew~ZMM6c?xnj@thKG6RJ`G(AcB|bLvayNECmHG zSSj?WAU+rW0Kc;*R3i&6rVF2k;Y^tCEZk|He#!v;uc zE2-OdVgB2#2Vbq<-|5}^dh`Cmg{?}f%lw4;Q#OQ*?pMivy=oXIsN2L#guC11=`nvLbn=IT~sb*p}UZLZOE=g#8ken2=3 zLj{OAS9i{e#!=0hHh)+ru6K-f|Z9B{zY)L(G4{ViyUdoch2002ovPDHLkV1lv>WQG6$ From a83c9c6f38509e3d88e19b3a1095fa790944434b Mon Sep 17 00:00:00 2001 From: mystchonky Date: Mon, 14 Aug 2023 21:46:38 +0530 Subject: [PATCH 04/10] switch editBox triggers --- .../client/gui/screen/OmniBufferScreen.java | 22 ++++++++++++------ .../client/gui/screen/PowerBufferScreen.java | 23 ++++++++++++------- .../blockentity/PowerBufferBlockEntity.java | 11 ++++----- 3 files changed, 34 insertions(+), 22 deletions(-) diff --git a/src/machines/java/com/enderio/machines/client/gui/screen/OmniBufferScreen.java b/src/machines/java/com/enderio/machines/client/gui/screen/OmniBufferScreen.java index 6fd4a0f6de..d81651c516 100644 --- a/src/machines/java/com/enderio/machines/client/gui/screen/OmniBufferScreen.java +++ b/src/machines/java/com/enderio/machines/client/gui/screen/OmniBufferScreen.java @@ -5,6 +5,7 @@ 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.core.common.util.NumberUtils; import com.enderio.machines.client.gui.widget.CapacitorEnergyWidget; import com.enderio.machines.client.gui.widget.EnergyTextboxWidget; import com.enderio.machines.client.gui.widget.ioconfig.IOConfigButton; @@ -37,13 +38,13 @@ protected void init() { addRenderableWidget(new IOConfigButton<>(this, leftPos + imageWidth - 6 - 16, topPos + 22, 16, 16, menu, this::addRenderableWidget, font)); input = new EnergyTextboxWidget(this, () -> this.getMenu().getBlockEntity().getEnergyStorage().getMaxEnergyUse(), this.font, leftPos + 33, topPos + 18, 49, this.font.lineHeight + 2, Component.empty()); - input.setResponder(getMenu().getBlockEntity()::setMaxInput); input.setValue(Integer.toString(this.getMenu().getBlockEntity().getMaxInput())); + input.setResponder(this::updateInput); addRenderableWidget(input); output = new EnergyTextboxWidget(this, () -> this.getMenu().getBlockEntity().getEnergyStorage().getMaxEnergyUse(), this.font, leftPos + 33, topPos + 48, 49, this.font.lineHeight + 2, Component.empty()); - output.setResponder(getMenu().getBlockEntity()::setMaxOutput); output.setValue(output.formatEnergy(Integer.toString(this.getMenu().getBlockEntity().getMaxOutput()))); + output.setResponder(this::updateOutput); addRenderableWidget(output); } @@ -66,13 +67,20 @@ public void render(GuiGraphics guiGraphics, int pMouseX, int pMouseY, float pPar guiGraphics.drawString(font, EIOLang.OUTPUT.getString() + ":", leftPos + 33, topPos + 48 - font.lineHeight - 2, 1, false); } - @Override - protected void containerTick() { - super.containerTick(); + private void updateInput(String val){ + int amount = NumberUtils.getInteger(val); + PowerBufferBlockEntity be = this.getMenu().getBlockEntity(); + if (be != null) { + amount = Math.max(0, Math.min(amount, be.getEnergyStorage().getMaxEnergyUse())); + be.setMaxInput(amount); + } + } + private void updateOutput(String val){ + int amount = NumberUtils.getInteger(val); PowerBufferBlockEntity be = this.getMenu().getBlockEntity(); if (be != null) { - input.setValue(input.formatEnergy(Integer.toString(be.getMaxInput()))); - output.setValue(output.formatEnergy(Integer.toString(be.getMaxOutput()))); + amount = Math.max(0, Math.min(amount, be.getEnergyStorage().getMaxEnergyUse())); + be.setMaxOutput(amount); } } } diff --git a/src/machines/java/com/enderio/machines/client/gui/screen/PowerBufferScreen.java b/src/machines/java/com/enderio/machines/client/gui/screen/PowerBufferScreen.java index c4ebbc6c2d..6744018ada 100644 --- a/src/machines/java/com/enderio/machines/client/gui/screen/PowerBufferScreen.java +++ b/src/machines/java/com/enderio/machines/client/gui/screen/PowerBufferScreen.java @@ -5,6 +5,7 @@ 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.core.common.util.NumberUtils; import com.enderio.machines.client.gui.widget.CapacitorEnergyWidget; import com.enderio.machines.client.gui.widget.EnergyTextboxWidget; import com.enderio.machines.client.gui.widget.ioconfig.IOConfigButton; @@ -37,13 +38,13 @@ protected void init() { addRenderableWidget(new IOConfigButton<>(this, leftPos + imageWidth - 6 - 16, topPos + 22, 16, 16, menu, this::addRenderableWidget, font)); input = new EnergyTextboxWidget(this, () -> this.getMenu().getBlockEntity().getEnergyStorage().getMaxEnergyUse(), this.font, leftPos + 40, topPos + 18, 95, this.font.lineHeight + 2, Component.empty()); - input.setResponder(getMenu().getBlockEntity()::setMaxInput); input.setValue(Integer.toString(this.getMenu().getBlockEntity().getMaxInput())); + input.setResponder(this::updateInput); addRenderableWidget(input); output = new EnergyTextboxWidget(this, () -> this.getMenu().getBlockEntity().getEnergyStorage().getMaxEnergyUse(), this.font, leftPos + 40, topPos + 48, 95, this.font.lineHeight + 2, Component.empty()); - output.setResponder(getMenu().getBlockEntity()::setMaxOutput); output.setValue(output.formatEnergy(Integer.toString(this.getMenu().getBlockEntity().getMaxOutput()))); + output.setResponder(this::updateOutput); addRenderableWidget(output); } @@ -66,14 +67,20 @@ public void render(GuiGraphics guiGraphics, int pMouseX, int pMouseY, float pPar guiGraphics.drawString(font, EIOLang.OUTPUT.getString() +":", leftPos + 40, topPos + 48 - font.lineHeight - 2, 1, false); } - //Syncronize the block entity values with what is displayed to the player - @Override - protected void containerTick() { - super.containerTick(); + private void updateInput(String val){ + int amount = NumberUtils.getInteger(val); + PowerBufferBlockEntity be = this.getMenu().getBlockEntity(); + if (be != null) { + amount = Math.max(0, Math.min(amount, be.getEnergyStorage().getMaxEnergyUse())); + be.setMaxInput(amount); + } + } + private void updateOutput(String val){ + int amount = NumberUtils.getInteger(val); PowerBufferBlockEntity be = this.getMenu().getBlockEntity(); if (be != null) { - input.setValue(input.formatEnergy(Integer.toString(be.getMaxInput()))); - output.setValue(output.formatEnergy(Integer.toString(be.getMaxOutput()))); + amount = Math.max(0, Math.min(amount, be.getEnergyStorage().getMaxEnergyUse())); + be.setMaxOutput(amount); } } } diff --git a/src/machines/java/com/enderio/machines/common/blockentity/PowerBufferBlockEntity.java b/src/machines/java/com/enderio/machines/common/blockentity/PowerBufferBlockEntity.java index 6248c1fdb2..d54449b9fd 100644 --- a/src/machines/java/com/enderio/machines/common/blockentity/PowerBufferBlockEntity.java +++ b/src/machines/java/com/enderio/machines/common/blockentity/PowerBufferBlockEntity.java @@ -1,12 +1,10 @@ package com.enderio.machines.common.blockentity; -import com.enderio.EnderIO; import com.enderio.api.capacitor.CapacitorModifier; import com.enderio.api.capacitor.QuadraticScalable; import com.enderio.api.io.energy.EnergyIOMode; import com.enderio.core.CoreNBTKeys; import com.enderio.core.common.network.slot.IntegerNetworkDataSlot; -import com.enderio.core.common.util.NumberUtils; import com.enderio.machines.common.blockentity.base.PoweredMachineBlockEntity; import com.enderio.machines.common.config.MachinesConfig; import com.enderio.machines.common.io.energy.MachineEnergyStorage; @@ -22,7 +20,6 @@ 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; @@ -69,13 +66,13 @@ public AbstractContainerMenu createMenu(int containerId, Inventory playerInvento return new PowerBufferMenu(this, playerInventory, containerId); } - public void setMaxOutput(String pMaxOutput) { - this.maxOutput = NumberUtils.getInteger(pMaxOutput); + public void setMaxOutput(int pMaxOutput) { + this.maxOutput = pMaxOutput; clientUpdateSlot(outputDataSlot, maxOutput); } - public void setMaxInput(String pMaxInput) { - this.maxInput = NumberUtils.getInteger(pMaxInput); + public void setMaxInput(int pMaxInput) { + this.maxInput = pMaxInput; clientUpdateSlot(inputDataSlot, maxInput); } From 1bb42c430ce53cfbd0e2ee1ca4b8ee3ed13b4550 Mon Sep 17 00:00:00 2001 From: ferriarnus <61201275+ferriarnus@users.noreply.github.com> Date: Mon, 14 Aug 2023 21:16:41 +0200 Subject: [PATCH 05/10] change syncing and only update on change focus --- .../client/gui/screen/OmniBufferScreen.java | 7 ++- .../client/gui/screen/PowerBufferScreen.java | 7 ++- .../gui/widget/EnergyTextboxWidget.java | 47 ++++++++++++------- .../blockentity/PowerBufferBlockEntity.java | 36 ++++---------- 4 files changed, 45 insertions(+), 52 deletions(-) diff --git a/src/machines/java/com/enderio/machines/client/gui/screen/OmniBufferScreen.java b/src/machines/java/com/enderio/machines/client/gui/screen/OmniBufferScreen.java index d81651c516..e74104e835 100644 --- a/src/machines/java/com/enderio/machines/client/gui/screen/OmniBufferScreen.java +++ b/src/machines/java/com/enderio/machines/client/gui/screen/OmniBufferScreen.java @@ -38,13 +38,13 @@ protected void init() { addRenderableWidget(new IOConfigButton<>(this, leftPos + imageWidth - 6 - 16, topPos + 22, 16, 16, menu, this::addRenderableWidget, font)); input = new EnergyTextboxWidget(this, () -> this.getMenu().getBlockEntity().getEnergyStorage().getMaxEnergyUse(), this.font, leftPos + 33, topPos + 18, 49, this.font.lineHeight + 2, Component.empty()); - input.setValue(Integer.toString(this.getMenu().getBlockEntity().getMaxInput())); - input.setResponder(this::updateInput); + input.setValue(input.formatEnergy(Integer.toString(this.getMenu().getBlockEntity().getMaxInput()))); + input.OnFocusStoppedResponder(this::updateInput); addRenderableWidget(input); output = new EnergyTextboxWidget(this, () -> this.getMenu().getBlockEntity().getEnergyStorage().getMaxEnergyUse(), this.font, leftPos + 33, topPos + 48, 49, this.font.lineHeight + 2, Component.empty()); output.setValue(output.formatEnergy(Integer.toString(this.getMenu().getBlockEntity().getMaxOutput()))); - output.setResponder(this::updateOutput); + output.OnFocusStoppedResponder(this::updateOutput); addRenderableWidget(output); } @@ -62,7 +62,6 @@ protected Vector2i getBackgroundImageSize() { @Override public void render(GuiGraphics guiGraphics, int pMouseX, int pMouseY, float pPartialTicks) { super.render(guiGraphics, pMouseX, pMouseY, pPartialTicks); - PowerBufferBlockEntity be = this.getMenu().getBlockEntity(); guiGraphics.drawString(font, EIOLang.INPUT.getString() + ":", leftPos + 33, topPos + 18 - font.lineHeight - 2, 1, false); guiGraphics.drawString(font, EIOLang.OUTPUT.getString() + ":", leftPos + 33, topPos + 48 - font.lineHeight - 2, 1, false); } diff --git a/src/machines/java/com/enderio/machines/client/gui/screen/PowerBufferScreen.java b/src/machines/java/com/enderio/machines/client/gui/screen/PowerBufferScreen.java index 6744018ada..b2912ee19e 100644 --- a/src/machines/java/com/enderio/machines/client/gui/screen/PowerBufferScreen.java +++ b/src/machines/java/com/enderio/machines/client/gui/screen/PowerBufferScreen.java @@ -38,13 +38,13 @@ protected void init() { addRenderableWidget(new IOConfigButton<>(this, leftPos + imageWidth - 6 - 16, topPos + 22, 16, 16, menu, this::addRenderableWidget, font)); input = new EnergyTextboxWidget(this, () -> this.getMenu().getBlockEntity().getEnergyStorage().getMaxEnergyUse(), this.font, leftPos + 40, topPos + 18, 95, this.font.lineHeight + 2, Component.empty()); - input.setValue(Integer.toString(this.getMenu().getBlockEntity().getMaxInput())); - input.setResponder(this::updateInput); + input.setValue(input.formatEnergy(Integer.toString(this.getMenu().getBlockEntity().getMaxInput()))); + input.OnFocusStoppedResponder(this::updateInput); addRenderableWidget(input); output = new EnergyTextboxWidget(this, () -> this.getMenu().getBlockEntity().getEnergyStorage().getMaxEnergyUse(), this.font, leftPos + 40, topPos + 48, 95, this.font.lineHeight + 2, Component.empty()); output.setValue(output.formatEnergy(Integer.toString(this.getMenu().getBlockEntity().getMaxOutput()))); - output.setResponder(this::updateOutput); + output.OnFocusStoppedResponder(this::updateOutput); addRenderableWidget(output); } @@ -62,7 +62,6 @@ protected Vector2i getBackgroundImageSize() { @Override public void render(GuiGraphics guiGraphics, int pMouseX, int pMouseY, float pPartialTicks) { super.render(guiGraphics, pMouseX, pMouseY, pPartialTicks); - PowerBufferBlockEntity be = this.getMenu().getBlockEntity(); guiGraphics.drawString(font, EIOLang.INPUT.getString() +":", leftPos + 40, topPos + 18 - font.lineHeight - 2, 1, false); guiGraphics.drawString(font, EIOLang.OUTPUT.getString() +":", leftPos + 40, topPos + 48 - font.lineHeight - 2, 1, false); } diff --git a/src/machines/java/com/enderio/machines/client/gui/widget/EnergyTextboxWidget.java b/src/machines/java/com/enderio/machines/client/gui/widget/EnergyTextboxWidget.java index 185f757b90..2492cbed63 100644 --- a/src/machines/java/com/enderio/machines/client/gui/widget/EnergyTextboxWidget.java +++ b/src/machines/java/com/enderio/machines/client/gui/widget/EnergyTextboxWidget.java @@ -5,17 +5,19 @@ import net.minecraft.client.gui.components.EditBox; import net.minecraft.client.gui.screens.Screen; import net.minecraft.network.chat.Component; +import org.jetbrains.annotations.Nullable; import java.text.DecimalFormat; -import java.text.NumberFormat; -import java.util.Locale; +import java.util.function.Consumer; import java.util.function.Supplier; public class EnergyTextboxWidget extends EditBox { private final Supplier maxEnergy; protected final Screen displayOn; - + @Nullable + private Consumer focusResponder; + public EnergyTextboxWidget(Screen displayOn, Supplier maxEnergy, Font font, int x, int y, int width, int height, Component message) { super(font, x, y, width, height, message); this.maxEnergy = maxEnergy; @@ -26,7 +28,6 @@ public EnergyTextboxWidget(Screen displayOn, Supplier maxEnergy, Font f //Input only accepts digits (0, 1, ..., 9) @Override public boolean charTyped(char codePoint, int modifiers) { - if (codePoint >= 48 && codePoint <= 57) { int cursorPos = getCursorPosition() + 1; boolean res = super.charTyped(codePoint, modifiers); @@ -35,7 +36,6 @@ public boolean charTyped(char codePoint, int modifiers) { return res; } - return false; } @@ -46,12 +46,7 @@ public boolean keyPressed(int keyCode, int scanCode, int modifiers) { if (keyCode == 259) { int cursorPos = getCursorPosition(); setValue(formatEnergy(getValue())); - - if (getValue().equals("0")) { - moveCursorTo(1); - } else { - moveCursorTo(cursorPos); - } + moveCursorTo(cursorPos); } return res; @@ -59,30 +54,29 @@ public boolean keyPressed(int keyCode, int scanCode, int modifiers) { @Override public boolean mouseClicked(double mouseX, double mouseY, int button) { - if (mouseX >= getX() && mouseX <= getX() + width && mouseY >= getY() && mouseY <= getY() + height) { super.mouseClicked(mouseX, mouseY, button); //Clear content on right click if (button == 1) { - setValue("0"); moveCursorTo(1); } - return true; } else { + if (getValue().isEmpty()) { + setValue("0"); + } setFocused(false); return false; } } public String formatEnergy(String value) { - if (value.isEmpty()) { - return "0"; + return ""; } - int energy = 0; + int energy; value = value.replace(",", ""); try { @@ -93,7 +87,7 @@ public String formatEnergy(String value) { } try { - DecimalFormat decimalFormat = (DecimalFormat) NumberFormat.getInstance(Locale.ROOT); + DecimalFormat decimalFormat = new DecimalFormat(); decimalFormat.applyPattern("#,###"); return decimalFormat.format(energy); } catch (NumberFormatException e) { @@ -112,4 +106,21 @@ public void renderToolTip(GuiGraphics guiGraphics, int mouseX, int mouseY) { guiGraphics.renderTooltip(displayOn.getMinecraft().font, Component.literal(formatEnergy(getValue()) +"/" +formatEnergy(Integer.toString(maxEnergy.get())) +" µI"), mouseX, mouseY); } } + + public void OnFocusStoppedResponder(Consumer responder) { + this.focusResponder = responder; + } + + @Override + public void setValue(String text) { + super.setValue(text); + } + + @Override + public void setFocused(boolean focused) { + if (!focused && focusResponder != null) { + focusResponder.accept(getValue()); + } + super.setFocused(focused); + } } diff --git a/src/machines/java/com/enderio/machines/common/blockentity/PowerBufferBlockEntity.java b/src/machines/java/com/enderio/machines/common/blockentity/PowerBufferBlockEntity.java index d54449b9fd..8516ed598d 100644 --- a/src/machines/java/com/enderio/machines/common/blockentity/PowerBufferBlockEntity.java +++ b/src/machines/java/com/enderio/machines/common/blockentity/PowerBufferBlockEntity.java @@ -40,9 +40,8 @@ public class PowerBufferBlockEntity extends PoweredMachineBlockEntity { public PowerBufferBlockEntity(BlockEntityType type, BlockPos worldPosition, BlockState blockState) { super(EnergyIOMode.Both, CAPACITY, USAGE, type, worldPosition, blockState); - //Networing in modding is very fun :) - inputDataSlot = new IntegerNetworkDataSlot(() -> maxInput, input -> maxInput = input); - outputDataSlot = new IntegerNetworkDataSlot(() -> maxOutput, output -> maxOutput = output); + inputDataSlot = new IntegerNetworkDataSlot(this::getMaxInput, input -> maxInput = input); + outputDataSlot = new IntegerNetworkDataSlot(this::getMaxOutput, output -> maxOutput = output); addDataSlot(inputDataSlot); addDataSlot(outputDataSlot); } @@ -67,13 +66,15 @@ public AbstractContainerMenu createMenu(int containerId, Inventory playerInvento } public void setMaxOutput(int pMaxOutput) { - this.maxOutput = pMaxOutput; - clientUpdateSlot(outputDataSlot, maxOutput); + if (level != null && level.isClientSide) { + clientUpdateSlot(outputDataSlot, pMaxOutput); + } else this.maxOutput = pMaxOutput; } public void setMaxInput(int pMaxInput) { - this.maxInput = pMaxInput; - clientUpdateSlot(inputDataSlot, maxInput); + if (level != null && level.isClientSide) { + clientUpdateSlot(inputDataSlot, pMaxInput); + } else this.maxInput = pMaxInput; } public int getMaxInput() { @@ -101,9 +102,9 @@ public void pushEnergy() { if (otherHandler.isPresent()) { // If the other handler can receive power transmit ours and there is enough energy stored - if (otherHandler.get().canReceive() && getExposedEnergyStorage().getEnergyStored() - maxOutput >= 0) { + if (otherHandler.get().canReceive() && getExposedEnergyStorage().getEnergyStored() - getMaxOutput() >= 0) { - int received = otherHandler.get().receiveEnergy(maxOutput, false); + int received = otherHandler.get().receiveEnergy(getMaxOutput(), false); // Consume that energy from our buffer. getExposedEnergyStorage().extractEnergy(received, false); } @@ -157,21 +158,4 @@ public void load(CompoundTag pTag) { maxInput = pTag.getInt(CoreNBTKeys.BUFFER_MAX_INPUT); maxOutput = pTag.getInt(CoreNBTKeys.BUFFER_MAX_OUTPUT); } - - //Reset values if capacitor is added/removed and transmit it to the textbox - -// @Override -// protected void onInventoryContentsChanged(int slot) { -// super.onInventoryContentsChanged(slot); -// MachineInventoryLayout inventoryLayout = getInventoryLayout(); -// if (inventoryLayout != null && inventoryLayout.getCapacitorSlot() == slot) { -// if (requiresCapacitor() && isCapacitorInstalled()) { -// setMaxInput(getEnergyStorage().getMaxEnergyUse()); -// setMaxOutput(getEnergyStorage().getMaxEnergyUse()); -// } else { -// setMaxInput(0); -// setMaxOutput(0); -// } -// } -// } } From 583c2af75777fde03758be45816e8a9421a8aded Mon Sep 17 00:00:00 2001 From: ferriarnus <61201275+ferriarnus@users.noreply.github.com> Date: Thu, 17 Aug 2023 18:21:44 +0200 Subject: [PATCH 06/10] small tweaks --- .../machines/client/gui/screen/OmniBufferScreen.java | 4 ++-- .../machines/client/gui/screen/PowerBufferScreen.java | 4 ++-- .../machines/client/gui/widget/EnergyTextboxWidget.java | 9 ++++++--- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/machines/java/com/enderio/machines/client/gui/screen/OmniBufferScreen.java b/src/machines/java/com/enderio/machines/client/gui/screen/OmniBufferScreen.java index e74104e835..97a718bd7e 100644 --- a/src/machines/java/com/enderio/machines/client/gui/screen/OmniBufferScreen.java +++ b/src/machines/java/com/enderio/machines/client/gui/screen/OmniBufferScreen.java @@ -38,12 +38,12 @@ protected void init() { addRenderableWidget(new IOConfigButton<>(this, leftPos + imageWidth - 6 - 16, topPos + 22, 16, 16, menu, this::addRenderableWidget, font)); input = new EnergyTextboxWidget(this, () -> this.getMenu().getBlockEntity().getEnergyStorage().getMaxEnergyUse(), this.font, leftPos + 33, topPos + 18, 49, this.font.lineHeight + 2, Component.empty()); - input.setValue(input.formatEnergy(Integer.toString(this.getMenu().getBlockEntity().getMaxInput()))); + input.setValue(Integer.toString(this.getMenu().getBlockEntity().getMaxInput())); input.OnFocusStoppedResponder(this::updateInput); addRenderableWidget(input); output = new EnergyTextboxWidget(this, () -> this.getMenu().getBlockEntity().getEnergyStorage().getMaxEnergyUse(), this.font, leftPos + 33, topPos + 48, 49, this.font.lineHeight + 2, Component.empty()); - output.setValue(output.formatEnergy(Integer.toString(this.getMenu().getBlockEntity().getMaxOutput()))); + output.setValue(Integer.toString(this.getMenu().getBlockEntity().getMaxOutput())); output.OnFocusStoppedResponder(this::updateOutput); addRenderableWidget(output); diff --git a/src/machines/java/com/enderio/machines/client/gui/screen/PowerBufferScreen.java b/src/machines/java/com/enderio/machines/client/gui/screen/PowerBufferScreen.java index b2912ee19e..2aee281b96 100644 --- a/src/machines/java/com/enderio/machines/client/gui/screen/PowerBufferScreen.java +++ b/src/machines/java/com/enderio/machines/client/gui/screen/PowerBufferScreen.java @@ -38,12 +38,12 @@ protected void init() { addRenderableWidget(new IOConfigButton<>(this, leftPos + imageWidth - 6 - 16, topPos + 22, 16, 16, menu, this::addRenderableWidget, font)); input = new EnergyTextboxWidget(this, () -> this.getMenu().getBlockEntity().getEnergyStorage().getMaxEnergyUse(), this.font, leftPos + 40, topPos + 18, 95, this.font.lineHeight + 2, Component.empty()); - input.setValue(input.formatEnergy(Integer.toString(this.getMenu().getBlockEntity().getMaxInput()))); + input.setValue(Integer.toString(this.getMenu().getBlockEntity().getMaxInput())); input.OnFocusStoppedResponder(this::updateInput); addRenderableWidget(input); output = new EnergyTextboxWidget(this, () -> this.getMenu().getBlockEntity().getEnergyStorage().getMaxEnergyUse(), this.font, leftPos + 40, topPos + 48, 95, this.font.lineHeight + 2, Component.empty()); - output.setValue(output.formatEnergy(Integer.toString(this.getMenu().getBlockEntity().getMaxOutput()))); + output.setValue(Integer.toString(this.getMenu().getBlockEntity().getMaxOutput())); output.OnFocusStoppedResponder(this::updateOutput); addRenderableWidget(output); diff --git a/src/machines/java/com/enderio/machines/client/gui/widget/EnergyTextboxWidget.java b/src/machines/java/com/enderio/machines/client/gui/widget/EnergyTextboxWidget.java index 2492cbed63..8eff76a4b2 100644 --- a/src/machines/java/com/enderio/machines/client/gui/widget/EnergyTextboxWidget.java +++ b/src/machines/java/com/enderio/machines/client/gui/widget/EnergyTextboxWidget.java @@ -31,7 +31,7 @@ public boolean charTyped(char codePoint, int modifiers) { if (codePoint >= 48 && codePoint <= 57) { int cursorPos = getCursorPosition() + 1; boolean res = super.charTyped(codePoint, modifiers); - setValue(formatEnergy(getValue())); + setValue(getValue()); moveCursorTo(cursorPos); return res; @@ -103,7 +103,7 @@ public void renderWidget(GuiGraphics guiGraphics, int mouseX, int mouseY, float public void renderToolTip(GuiGraphics guiGraphics, int mouseX, int mouseY) { if (mouseX >= getX() && mouseX <= getX() + width && mouseY >= getY() && mouseY <= getY() + height && !isFocused() && maxEnergy.get() != 0) { - guiGraphics.renderTooltip(displayOn.getMinecraft().font, Component.literal(formatEnergy(getValue()) +"/" +formatEnergy(Integer.toString(maxEnergy.get())) +" µI"), mouseX, mouseY); + guiGraphics.renderTooltip(displayOn.getMinecraft().font, Component.literal(getValue() +"/" + maxEnergy.get() +" µI"), mouseX, mouseY); } } @@ -113,12 +113,15 @@ public void OnFocusStoppedResponder(Consumer responder) { @Override public void setValue(String text) { - super.setValue(text); + super.setValue(formatEnergy(text)); } @Override public void setFocused(boolean focused) { if (!focused && focusResponder != null) { + if (getValue().isEmpty()) { + setValue("0"); + } focusResponder.accept(getValue()); } super.setFocused(focused); From 82eb60f511e6283f01bd5760d9ba21fc4af58f53 Mon Sep 17 00:00:00 2001 From: Trytoon Date: Mon, 25 Dec 2023 18:49:31 +0100 Subject: [PATCH 07/10] fixed textboxes resetting when resizing screen --- .../client/gui/screen/OmniBufferScreen.java | 14 ++++---- .../client/gui/screen/PowerBufferScreen.java | 19 ++++++----- .../gui/widget/EnergyTextboxWidget.java | 7 +++- .../blockentity/PowerBufferBlockEntity.java | 33 +++++++++++++++++-- 4 files changed, 55 insertions(+), 18 deletions(-) diff --git a/src/machines/java/com/enderio/machines/client/gui/screen/OmniBufferScreen.java b/src/machines/java/com/enderio/machines/client/gui/screen/OmniBufferScreen.java index 97a718bd7e..d24f3694e3 100644 --- a/src/machines/java/com/enderio/machines/client/gui/screen/OmniBufferScreen.java +++ b/src/machines/java/com/enderio/machines/client/gui/screen/OmniBufferScreen.java @@ -37,15 +37,17 @@ protected void init() { addRenderableWidget(new IOConfigButton<>(this, leftPos + imageWidth - 6 - 16, topPos + 22, 16, 16, menu, this::addRenderableWidget, font)); - input = new EnergyTextboxWidget(this, () -> this.getMenu().getBlockEntity().getEnergyStorage().getMaxEnergyUse(), this.font, leftPos + 33, topPos + 18, 49, this.font.lineHeight + 2, Component.empty()); - input.setValue(Integer.toString(this.getMenu().getBlockEntity().getMaxInput())); + input = new EnergyTextboxWidget(this, () -> this.getMenu().getBlockEntity().getEnergyStorage().getMaxEnergyUse(), this.font, leftPos + 33, topPos + 18, 49, this.font.lineHeight + 2, Component.literal("PBInputBox")); + input.setResponder(this.getMenu().getBlockEntity()::setMaxInputText); + input.setValue(getMenu().getBlockEntity().getMaxInputText()); input.OnFocusStoppedResponder(this::updateInput); - addRenderableWidget(input); + addRenderableOnly(addRenderableWidget(input)); - output = new EnergyTextboxWidget(this, () -> this.getMenu().getBlockEntity().getEnergyStorage().getMaxEnergyUse(), this.font, leftPos + 33, topPos + 48, 49, this.font.lineHeight + 2, Component.empty()); - output.setValue(Integer.toString(this.getMenu().getBlockEntity().getMaxOutput())); + output = new EnergyTextboxWidget(this, () -> this.getMenu().getBlockEntity().getEnergyStorage().getMaxEnergyUse(), this.font, leftPos + 33, topPos + 48, 49, this.font.lineHeight + 2, Component.literal("PBOutputBox")); + output.setResponder(this.getMenu().getBlockEntity()::setMaxOutputText); + output.setValue(getMenu().getBlockEntity().getMaxOutputText()); output.OnFocusStoppedResponder(this::updateOutput); - addRenderableWidget(output); + addRenderableOnly(addRenderableWidget(output)); } diff --git a/src/machines/java/com/enderio/machines/client/gui/screen/PowerBufferScreen.java b/src/machines/java/com/enderio/machines/client/gui/screen/PowerBufferScreen.java index 2aee281b96..63469d7caa 100644 --- a/src/machines/java/com/enderio/machines/client/gui/screen/PowerBufferScreen.java +++ b/src/machines/java/com/enderio/machines/client/gui/screen/PowerBufferScreen.java @@ -37,16 +37,17 @@ protected void init() { addRenderableWidget(new IOConfigButton<>(this, leftPos + imageWidth - 6 - 16, topPos + 22, 16, 16, menu, this::addRenderableWidget, font)); - input = new EnergyTextboxWidget(this, () -> this.getMenu().getBlockEntity().getEnergyStorage().getMaxEnergyUse(), this.font, leftPos + 40, topPos + 18, 95, this.font.lineHeight + 2, Component.empty()); - input.setValue(Integer.toString(this.getMenu().getBlockEntity().getMaxInput())); + input = new EnergyTextboxWidget(this, () -> this.getMenu().getBlockEntity().getEnergyStorage().getMaxEnergyUse(), this.font, leftPos + 40, topPos + 18, 95, this.font.lineHeight + 2, Component.literal("PBInputBox")); + input.setResponder(this.getMenu().getBlockEntity()::setMaxInputText); + input.setValue(getMenu().getBlockEntity().getMaxInputText()); input.OnFocusStoppedResponder(this::updateInput); - addRenderableWidget(input); + addRenderableOnly(addRenderableWidget(input)); - output = new EnergyTextboxWidget(this, () -> this.getMenu().getBlockEntity().getEnergyStorage().getMaxEnergyUse(), this.font, leftPos + 40, topPos + 48, 95, this.font.lineHeight + 2, Component.empty()); - output.setValue(Integer.toString(this.getMenu().getBlockEntity().getMaxOutput())); + output = new EnergyTextboxWidget(this, () -> this.getMenu().getBlockEntity().getEnergyStorage().getMaxEnergyUse(), this.font, leftPos + 40, topPos + 48, 95, this.font.lineHeight + 2, Component.literal("PBOutputBox")); + output.setResponder(this.getMenu().getBlockEntity()::setMaxOutputText); + output.setValue(getMenu().getBlockEntity().getMaxOutputText()); output.OnFocusStoppedResponder(this::updateOutput); - addRenderableWidget(output); - + addRenderableOnly(addRenderableWidget(output)); } @Override @@ -66,7 +67,7 @@ public void render(GuiGraphics guiGraphics, int pMouseX, int pMouseY, float pPar guiGraphics.drawString(font, EIOLang.OUTPUT.getString() +":", leftPos + 40, topPos + 48 - font.lineHeight - 2, 1, false); } - private void updateInput(String val){ + private void updateInput(String val) { int amount = NumberUtils.getInteger(val); PowerBufferBlockEntity be = this.getMenu().getBlockEntity(); if (be != null) { @@ -74,7 +75,7 @@ private void updateInput(String val){ be.setMaxInput(amount); } } - private void updateOutput(String val){ + private void updateOutput(String val) { int amount = NumberUtils.getInteger(val); PowerBufferBlockEntity be = this.getMenu().getBlockEntity(); if (be != null) { diff --git a/src/machines/java/com/enderio/machines/client/gui/widget/EnergyTextboxWidget.java b/src/machines/java/com/enderio/machines/client/gui/widget/EnergyTextboxWidget.java index 8eff76a4b2..075e542a12 100644 --- a/src/machines/java/com/enderio/machines/client/gui/widget/EnergyTextboxWidget.java +++ b/src/machines/java/com/enderio/machines/client/gui/widget/EnergyTextboxWidget.java @@ -8,6 +8,8 @@ import org.jetbrains.annotations.Nullable; import java.text.DecimalFormat; +import java.text.NumberFormat; +import java.util.Locale; import java.util.function.Consumer; import java.util.function.Supplier; @@ -49,6 +51,8 @@ public boolean keyPressed(int keyCode, int scanCode, int modifiers) { moveCursorTo(cursorPos); } + moveCursorTo(getValue().length()); + return res; } @@ -60,6 +64,7 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) { //Clear content on right click if (button == 1) { moveCursorTo(1); + setValue("0"); } return true; } else { @@ -87,7 +92,7 @@ public String formatEnergy(String value) { } try { - DecimalFormat decimalFormat = new DecimalFormat(); + DecimalFormat decimalFormat = (DecimalFormat) NumberFormat.getInstance(Locale.ROOT); decimalFormat.applyPattern("#,###"); return decimalFormat.format(energy); } catch (NumberFormatException e) { diff --git a/src/machines/java/com/enderio/machines/common/blockentity/PowerBufferBlockEntity.java b/src/machines/java/com/enderio/machines/common/blockentity/PowerBufferBlockEntity.java index 8516ed598d..384c38322e 100644 --- a/src/machines/java/com/enderio/machines/common/blockentity/PowerBufferBlockEntity.java +++ b/src/machines/java/com/enderio/machines/common/blockentity/PowerBufferBlockEntity.java @@ -5,6 +5,7 @@ import com.enderio.api.io.energy.EnergyIOMode; import com.enderio.core.CoreNBTKeys; import com.enderio.core.common.network.slot.IntegerNetworkDataSlot; +import com.enderio.core.common.network.slot.StringNetworkDataSlot; import com.enderio.machines.common.blockentity.base.PoweredMachineBlockEntity; import com.enderio.machines.common.config.MachinesConfig; import com.enderio.machines.common.io.energy.MachineEnergyStorage; @@ -32,6 +33,11 @@ public class PowerBufferBlockEntity extends PoweredMachineBlockEntity { int maxOutput = 0; protected IntegerNetworkDataSlot outputDataSlot; + // Stores textbox value beofre being converted to energy value + protected StringNetworkDataSlot inputTextDataSlot; + String inputTextValue = "0"; + protected StringNetworkDataSlot outputTextDataSlot; + String outputTextValue = "0"; //todo: energy balancing public static final QuadraticScalable CAPACITY = new QuadraticScalable(CapacitorModifier.ENERGY_CAPACITY, MachinesConfig.COMMON.ENERGY.POWER_BUFFER_CAPACITY); @@ -44,6 +50,11 @@ public PowerBufferBlockEntity(BlockEntityType type, BlockPos worldPosition, B outputDataSlot = new IntegerNetworkDataSlot(this::getMaxOutput, output -> maxOutput = output); addDataSlot(inputDataSlot); addDataSlot(outputDataSlot); + + inputTextDataSlot = new StringNetworkDataSlot(this::getMaxInputText, input -> inputTextValue = input); + outputTextDataSlot = new StringNetworkDataSlot(this::getMaxOutputText, output -> outputTextValue = output); + addDataSlot(inputTextDataSlot); + addDataSlot(outputTextDataSlot); } @Override @@ -77,6 +88,26 @@ public void setMaxInput(int pMaxInput) { } else this.maxInput = pMaxInput; } + public void setMaxInputText(String maxInputText) { + if (level != null && level.isClientSide) { + clientUpdateSlot(inputTextDataSlot, maxInputText); + } this.inputTextValue = maxInputText; + } + + public void setMaxOutputText(String maxOutputText) { + if (level != null && level.isClientSide) { + clientUpdateSlot(outputTextDataSlot, maxOutputText); + } this.outputTextValue = maxOutputText; + } + + public String getMaxInputText() { + return this.inputTextValue; + } + + public String getMaxOutputText() { + return this.outputTextValue; + } + public int getMaxInput() { return maxInput; } @@ -122,8 +153,6 @@ protected boolean shouldPushEnergyTo(Direction direction) { protected MachineEnergyStorage createEnergyStorage(EnergyIOMode energyIOMode, Supplier capacity, Supplier usageRate) { return new MachineEnergyStorage(getIOConfig(), energyIOMode, capacity, usageRate) { - //Redstone control should be applied to the buffer - @Override public boolean canExtract() { return super.canExtract() && canAct(); From c2c38963cc92cbc342da39f3c328a041afceef8b Mon Sep 17 00:00:00 2001 From: Trytoon Date: Mon, 25 Dec 2023 19:45:21 +0100 Subject: [PATCH 08/10] fixed UI... now it should compile too :) --- .../enderio/machines/client/gui/screen/OmniBufferScreen.java | 2 +- .../enderio/machines/client/gui/screen/PowerBufferScreen.java | 2 +- .../enderio/machines/data/recipes/MachineRecipeProvider.java | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/machines/java/com/enderio/machines/client/gui/screen/OmniBufferScreen.java b/src/machines/java/com/enderio/machines/client/gui/screen/OmniBufferScreen.java index d24f3694e3..cf72cd0516 100644 --- a/src/machines/java/com/enderio/machines/client/gui/screen/OmniBufferScreen.java +++ b/src/machines/java/com/enderio/machines/client/gui/screen/OmniBufferScreen.java @@ -35,7 +35,7 @@ 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)); + addRenderableWidget(new IOConfigButton<>(this, leftPos + imageWidth - 8 - 12, topPos + 22, 16, 16, menu, this::addRenderableWidget, font)); input = new EnergyTextboxWidget(this, () -> this.getMenu().getBlockEntity().getEnergyStorage().getMaxEnergyUse(), this.font, leftPos + 33, topPos + 18, 49, this.font.lineHeight + 2, Component.literal("PBInputBox")); input.setResponder(this.getMenu().getBlockEntity()::setMaxInputText); diff --git a/src/machines/java/com/enderio/machines/client/gui/screen/PowerBufferScreen.java b/src/machines/java/com/enderio/machines/client/gui/screen/PowerBufferScreen.java index 63469d7caa..cf76d3ad13 100644 --- a/src/machines/java/com/enderio/machines/client/gui/screen/PowerBufferScreen.java +++ b/src/machines/java/com/enderio/machines/client/gui/screen/PowerBufferScreen.java @@ -35,7 +35,7 @@ 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)); + addRenderableWidget(new IOConfigButton<>(this, leftPos + imageWidth - 8 - 12, topPos + 22, 16, 16, menu, this::addRenderableWidget, font)); input = new EnergyTextboxWidget(this, () -> this.getMenu().getBlockEntity().getEnergyStorage().getMaxEnergyUse(), this.font, leftPos + 40, topPos + 18, 95, this.font.lineHeight + 2, Component.literal("PBInputBox")); input.setResponder(this.getMenu().getBlockEntity()::setMaxInputText); 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 1199e603fe..d5863933fa 100644 --- a/src/machines/java/com/enderio/machines/data/recipes/MachineRecipeProvider.java +++ b/src/machines/java/com/enderio/machines/data/recipes/MachineRecipeProvider.java @@ -16,6 +16,7 @@ import net.minecraft.data.recipes.RecipeCategory; import net.minecraft.data.recipes.RecipeProvider; import net.minecraft.data.recipes.ShapedRecipeBuilder; +import net.minecraft.data.recipes.ShapelessRecipeBuilder; import net.minecraft.world.item.Items; import net.minecraft.world.level.block.Blocks; import net.minecraftforge.common.Tags; From 7c4622ba9ef7704f0118fc4bdc5353c47cb728b8 Mon Sep 17 00:00:00 2001 From: Trytoon Date: Mon, 25 Dec 2023 20:14:20 +0100 Subject: [PATCH 09/10] I forgot datagen --- .../resources/assets/enderio/lang/en_ud.json | 4 ++-- .../resources/assets/enderio/lang/en_us.json | 4 ++-- .../models/block/item_buffer_combined.json | 5 ++++- .../models/block/omni_buffer_combined.json | 5 ++++- .../models/block/power_buffer_combined.json | 5 ++++- .../enderio/models/block/item_buffer.json | 16 ++++++++-------- .../enderio/models/block/omni_buffer.json | 16 ++++++++-------- .../enderio/models/block/power_buffer.json | 16 ++++++++-------- .../{item_buffer.png => item_buffer_front.png} | Bin .../{omni_buffer.png => omni_buffer_front.png} | Bin ...{power_buffer.png => power_buffer_front.png} | Bin 11 files changed, 40 insertions(+), 31 deletions(-) rename src/machines/resources/assets/enderio/textures/block/{item_buffer.png => item_buffer_front.png} (100%) rename src/machines/resources/assets/enderio/textures/block/{omni_buffer.png => omni_buffer_front.png} (100%) rename src/machines/resources/assets/enderio/textures/block/{power_buffer.png => power_buffer_front.png} (100%) diff --git a/src/generated/resources/assets/enderio/lang/en_ud.json b/src/generated/resources/assets/enderio/lang/en_ud.json index ddedee7d03..5265ae7c75 100644 --- a/src/generated/resources/assets/enderio/lang/en_ud.json +++ b/src/generated/resources/assets/enderio/lang/en_ud.json @@ -267,10 +267,10 @@ "gui.enderio.fluid_conduit.change_fluid1": ":pınןℲ pǝʞɔoꞀ", "gui.enderio.fluid_conduit.change_fluid2": "¡ʇǝsǝɹ oʇ ʞɔıןƆ", "gui.enderio.fluid_conduit.change_fluid3": "%s :pınןℲ", - "gui.enderio.input": "ʇnduI", "gui.enderio.full_power": "ןןnɟ sı ǝbɐɹoʇs ʎbɹǝuǝ ǝɥ⟘", "gui.enderio.full_tank": "ןןnɟ sı ʞuɐʇ ǝɥ⟘", "gui.enderio.idle": "ʞɹoʍ oʇ ʎpɐǝɹ sı ǝuıɥɔɐɯ ǝɥ⟘", + "gui.enderio.input": "ʇnduI", "gui.enderio.input_empty": "ʇnduı ǝɥʇ uı ɯǝʇı ou sı ǝɹǝɥ⟘", "gui.enderio.ioconfig": "uoıʇɐɹnbıɟuoƆ OI", "gui.enderio.ioconfig.both": "ןןnԀ / ɥsnԀ", @@ -494,4 +494,4 @@ "tooltip.enderio.photovoltaic_cell.advanced3": " :ʇndʇnO xɐW", "tooltip.enderio.photovoltaic_cell.main": "¡ɹǝʍoԀ ɹɐןoS", "tooltip.enderio.soul_vial.health": "%s/%s :ɥʇןɐǝH" -} +} \ No newline at end of file diff --git a/src/generated/resources/assets/enderio/lang/en_us.json b/src/generated/resources/assets/enderio/lang/en_us.json index 57abccc39c..4f4b8e1d77 100644 --- a/src/generated/resources/assets/enderio/lang/en_us.json +++ b/src/generated/resources/assets/enderio/lang/en_us.json @@ -267,10 +267,10 @@ "gui.enderio.fluid_conduit.change_fluid1": "Locked Fluid:", "gui.enderio.fluid_conduit.change_fluid2": "Click to reset!", "gui.enderio.fluid_conduit.change_fluid3": "Fluid: %s", - "gui.enderio.input": "Input", "gui.enderio.full_power": "The energy storage is full", "gui.enderio.full_tank": "The tank is full", "gui.enderio.idle": "The machine is ready to work", + "gui.enderio.input": "Input", "gui.enderio.input_empty": "There is no item in the input", "gui.enderio.ioconfig": "IO Configuration", "gui.enderio.ioconfig.both": "Push / Pull", @@ -494,4 +494,4 @@ "tooltip.enderio.photovoltaic_cell.advanced3": "Max Output: ", "tooltip.enderio.photovoltaic_cell.main": "Solar Power!", "tooltip.enderio.soul_vial.health": "Health: %s/%s" -} +} \ No newline at end of file diff --git a/src/generated/resources/assets/enderio/models/block/item_buffer_combined.json b/src/generated/resources/assets/enderio/models/block/item_buffer_combined.json index 872883ab51..1c8fb7694c 100644 --- a/src/generated/resources/assets/enderio/models/block/item_buffer_combined.json +++ b/src/generated/resources/assets/enderio/models/block/item_buffer_combined.json @@ -12,5 +12,8 @@ "machine", "overlay" ], - "loader": "forge:composite" + "loader": "forge:composite", + "textures": { + "particle": "enderio:block/item_buffer_front" + } } \ No newline at end of file diff --git a/src/generated/resources/assets/enderio/models/block/omni_buffer_combined.json b/src/generated/resources/assets/enderio/models/block/omni_buffer_combined.json index 6b385f5c2b..7a8d797fc7 100644 --- a/src/generated/resources/assets/enderio/models/block/omni_buffer_combined.json +++ b/src/generated/resources/assets/enderio/models/block/omni_buffer_combined.json @@ -12,5 +12,8 @@ "machine", "overlay" ], - "loader": "forge:composite" + "loader": "forge:composite", + "textures": { + "particle": "enderio:block/omni_buffer_front" + } } \ No newline at end of file diff --git a/src/generated/resources/assets/enderio/models/block/power_buffer_combined.json b/src/generated/resources/assets/enderio/models/block/power_buffer_combined.json index 43ee0b7276..9aff10b0c9 100644 --- a/src/generated/resources/assets/enderio/models/block/power_buffer_combined.json +++ b/src/generated/resources/assets/enderio/models/block/power_buffer_combined.json @@ -12,5 +12,8 @@ "machine", "overlay" ], - "loader": "forge:composite" + "loader": "forge:composite", + "textures": { + "particle": "enderio:block/power_buffer_front" + } } \ No newline at end of file diff --git a/src/machines/resources/assets/enderio/models/block/item_buffer.json b/src/machines/resources/assets/enderio/models/block/item_buffer.json index bcfed5a744..dbbc390bef 100644 --- a/src/machines/resources/assets/enderio/models/block/item_buffer.json +++ b/src/machines/resources/assets/enderio/models/block/item_buffer.json @@ -1,12 +1,12 @@ { "parent": "minecraft:block/cube", "textures": { - "down": "enderio:block/item_buffer", - "east": "enderio:block/item_buffer", - "north": "enderio:block/item_buffer", - "particle": "enderio:block/item_buffer", - "south": "enderio:block/item_buffer", - "up": "enderio:block/item_buffer", - "west": "enderio:block/item_buffer" + "down": "enderio:block/item_buffer_front", + "east": "enderio:block/item_buffer_front", + "north": "enderio:block/item_buffer_front", + "particle": "enderio:block/item_buffer_front", + "south": "enderio:block/item_buffer_front", + "up": "enderio:block/item_buffer_front", + "west": "enderio:block/item_buffer_front" } -} \ No newline at end of file +} diff --git a/src/machines/resources/assets/enderio/models/block/omni_buffer.json b/src/machines/resources/assets/enderio/models/block/omni_buffer.json index 6f2416c5eb..12d7aeb815 100644 --- a/src/machines/resources/assets/enderio/models/block/omni_buffer.json +++ b/src/machines/resources/assets/enderio/models/block/omni_buffer.json @@ -1,12 +1,12 @@ { "parent": "minecraft:block/cube", "textures": { - "down": "enderio:block/omni_buffer", - "east": "enderio:block/omni_buffer", - "north": "enderio:block/omni_buffer", - "particle": "enderio:block/omni_buffer", - "south": "enderio:block/omni_buffer", - "up": "enderio:block/omni_buffer", - "west": "enderio:block/omni_buffer" + "down": "enderio:block/omni_buffer_front", + "east": "enderio:block/omni_buffer_front", + "north": "enderio:block/omni_buffer_front", + "particle": "enderio:block/omni_buffer_front", + "south": "enderio:block/omni_buffer_front", + "up": "enderio:block/omni_buffer_front", + "west": "enderio:block/omni_buffer_front" } -} \ No newline at end of file +} diff --git a/src/machines/resources/assets/enderio/models/block/power_buffer.json b/src/machines/resources/assets/enderio/models/block/power_buffer.json index 7872bafc03..0fce52a059 100644 --- a/src/machines/resources/assets/enderio/models/block/power_buffer.json +++ b/src/machines/resources/assets/enderio/models/block/power_buffer.json @@ -1,12 +1,12 @@ { "parent": "minecraft:block/cube", "textures": { - "down": "enderio:block/power_buffer", - "east": "enderio:block/power_buffer", - "north": "enderio:block/power_buffer", - "particle": "enderio:block/power_buffer", - "south": "enderio:block/power_buffer", - "up": "enderio:block/power_buffer", - "west": "enderio:block/power_buffer" + "down": "enderio:block/power_buffer_front", + "east": "enderio:block/power_buffer_front", + "north": "enderio:block/power_buffer_front", + "particle": "enderio:block/power_buffer_front", + "south": "enderio:block/power_buffer_front", + "up": "enderio:block/power_buffer_front", + "west": "enderio:block/power_buffer_front" } -} \ No newline at end of file +} diff --git a/src/machines/resources/assets/enderio/textures/block/item_buffer.png b/src/machines/resources/assets/enderio/textures/block/item_buffer_front.png similarity index 100% rename from src/machines/resources/assets/enderio/textures/block/item_buffer.png rename to src/machines/resources/assets/enderio/textures/block/item_buffer_front.png diff --git a/src/machines/resources/assets/enderio/textures/block/omni_buffer.png b/src/machines/resources/assets/enderio/textures/block/omni_buffer_front.png similarity index 100% rename from src/machines/resources/assets/enderio/textures/block/omni_buffer.png rename to src/machines/resources/assets/enderio/textures/block/omni_buffer_front.png diff --git a/src/machines/resources/assets/enderio/textures/block/power_buffer.png b/src/machines/resources/assets/enderio/textures/block/power_buffer_front.png similarity index 100% rename from src/machines/resources/assets/enderio/textures/block/power_buffer.png rename to src/machines/resources/assets/enderio/textures/block/power_buffer_front.png From 081177eda48f363148444442dd6673e7df826753 Mon Sep 17 00:00:00 2001 From: Trytoon Date: Mon, 1 Jan 2024 14:38:50 +0100 Subject: [PATCH 10/10] made buffer output energy equally between sides --- .../enderio/core/common/util/NumberUtils.java | 12 +++ .../client/gui/screen/OmniBufferScreen.java | 21 +++-- .../client/gui/screen/PowerBufferScreen.java | 22 +++-- .../gui/widget/EnergyTextboxWidget.java | 2 +- .../blockentity/PowerBufferBlockEntity.java | 82 +++++++++++++++---- 5 files changed, 112 insertions(+), 27 deletions(-) diff --git a/src/core/java/com/enderio/core/common/util/NumberUtils.java b/src/core/java/com/enderio/core/common/util/NumberUtils.java index 50be9d0891..d18546fce9 100644 --- a/src/core/java/com/enderio/core/common/util/NumberUtils.java +++ b/src/core/java/com/enderio/core/common/util/NumberUtils.java @@ -20,4 +20,16 @@ public static long getLong(String value) { return 0; } } + + public static String formatWithPrefix(int number) { + if (number < 100_000) { + return Long.toString(number); + } else if (number < 1_000_000) { + return String.format("%.1fk", number / 1_000.0); + } else if (number < 1_000_000_000) { + return String.format("%.3fM", number / 1_000_000.0); + } else { + return String.format("%.3fB", number / 1_000_000_000.0); + } + } } diff --git a/src/machines/java/com/enderio/machines/client/gui/screen/OmniBufferScreen.java b/src/machines/java/com/enderio/machines/client/gui/screen/OmniBufferScreen.java index cf72cd0516..08b19c026f 100644 --- a/src/machines/java/com/enderio/machines/client/gui/screen/OmniBufferScreen.java +++ b/src/machines/java/com/enderio/machines/client/gui/screen/OmniBufferScreen.java @@ -16,6 +16,8 @@ import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.player.Inventory; +import java.util.Objects; + public class OmniBufferScreen extends EIOScreen { private static final ResourceLocation BG_TEXTURE = EnderIO.loc("textures/gui/omni_buffer.png"); @@ -39,13 +41,13 @@ protected void init() { input = new EnergyTextboxWidget(this, () -> this.getMenu().getBlockEntity().getEnergyStorage().getMaxEnergyUse(), this.font, leftPos + 33, topPos + 18, 49, this.font.lineHeight + 2, Component.literal("PBInputBox")); input.setResponder(this.getMenu().getBlockEntity()::setMaxInputText); - input.setValue(getMenu().getBlockEntity().getMaxInputText()); + input.setValue(input.formatEnergy(""+getMenu().getBlockEntity().getMaxInput())); input.OnFocusStoppedResponder(this::updateInput); addRenderableOnly(addRenderableWidget(input)); - output = new EnergyTextboxWidget(this, () -> this.getMenu().getBlockEntity().getEnergyStorage().getMaxEnergyUse(), this.font, leftPos + 33, topPos + 48, 49, this.font.lineHeight + 2, Component.literal("PBOutputBox")); + output = new EnergyTextboxWidget(this, () -> this.getMenu().getBlockEntity().getEnergyStorage().getMaxEnergyUse(), this.font, leftPos + 33, topPos + 52, 49, this.font.lineHeight + 2, Component.literal("PBOutputBox")); output.setResponder(this.getMenu().getBlockEntity()::setMaxOutputText); - output.setValue(getMenu().getBlockEntity().getMaxOutputText()); + output.setValue(output.formatEnergy(""+getMenu().getBlockEntity().getMaxOutput())); output.OnFocusStoppedResponder(this::updateOutput); addRenderableOnly(addRenderableWidget(output)); @@ -64,8 +66,17 @@ protected Vector2i getBackgroundImageSize() { @Override public void render(GuiGraphics guiGraphics, int pMouseX, int pMouseY, float pPartialTicks) { super.render(guiGraphics, pMouseX, pMouseY, pPartialTicks); - guiGraphics.drawString(font, EIOLang.INPUT.getString() + ":", leftPos + 33, topPos + 18 - font.lineHeight - 2, 1, false); - guiGraphics.drawString(font, EIOLang.OUTPUT.getString() + ":", leftPos + 33, topPos + 48 - font.lineHeight - 2, 1, false); + guiGraphics.drawString(font, EIOLang.INPUT.getString(), leftPos + 33, topPos + 18 - font.lineHeight - 2, 1, false); + guiGraphics.drawString(font, EIOLang.OUTPUT.getString(), leftPos + 33, topPos + 52 - font.lineHeight - 2, 1, false); + + String maxIO = "Max: " + NumberUtils.formatWithPrefix(Objects.requireNonNull(getMenu().getBlockEntity()).getEnergyStorage().getMaxEnergyUse()); + guiGraphics.drawString(font, maxIO, leftPos + 33 + 49 - font.width(maxIO), topPos + 18 + font.lineHeight + 4, 0xff8b8b8b, false); + guiGraphics.drawString(font, maxIO, leftPos + 33 + 49 - font.width(maxIO), topPos + 52 + font.lineHeight + 4, 0xff8b8b8b, false); + + if (!this.getMenu().getBlockEntity().isCapacitorInstalled()) { + input.setValue("0"); + output.setValue("0"); + } } private void updateInput(String val){ diff --git a/src/machines/java/com/enderio/machines/client/gui/screen/PowerBufferScreen.java b/src/machines/java/com/enderio/machines/client/gui/screen/PowerBufferScreen.java index cf76d3ad13..064dfd19cf 100644 --- a/src/machines/java/com/enderio/machines/client/gui/screen/PowerBufferScreen.java +++ b/src/machines/java/com/enderio/machines/client/gui/screen/PowerBufferScreen.java @@ -16,6 +16,8 @@ import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.player.Inventory; +import java.util.Objects; + public class PowerBufferScreen extends EIOScreen { private static final ResourceLocation BG_TEXTURE = EnderIO.loc("textures/gui/power_buffer.png"); @@ -39,13 +41,13 @@ protected void init() { input = new EnergyTextboxWidget(this, () -> this.getMenu().getBlockEntity().getEnergyStorage().getMaxEnergyUse(), this.font, leftPos + 40, topPos + 18, 95, this.font.lineHeight + 2, Component.literal("PBInputBox")); input.setResponder(this.getMenu().getBlockEntity()::setMaxInputText); - input.setValue(getMenu().getBlockEntity().getMaxInputText()); + input.setValue(input.formatEnergy(""+getMenu().getBlockEntity().getMaxInput())); input.OnFocusStoppedResponder(this::updateInput); addRenderableOnly(addRenderableWidget(input)); - output = new EnergyTextboxWidget(this, () -> this.getMenu().getBlockEntity().getEnergyStorage().getMaxEnergyUse(), this.font, leftPos + 40, topPos + 48, 95, this.font.lineHeight + 2, Component.literal("PBOutputBox")); + output = new EnergyTextboxWidget(this, () -> this.getMenu().getBlockEntity().getEnergyStorage().getMaxEnergyUse(), this.font, leftPos + 40, topPos + 52, 95, this.font.lineHeight + 2, Component.literal("PBOutputBox")); output.setResponder(this.getMenu().getBlockEntity()::setMaxOutputText); - output.setValue(getMenu().getBlockEntity().getMaxOutputText()); + output.setValue(output.formatEnergy(""+getMenu().getBlockEntity().getMaxOutput())); output.OnFocusStoppedResponder(this::updateOutput); addRenderableOnly(addRenderableWidget(output)); } @@ -63,8 +65,18 @@ protected Vector2i getBackgroundImageSize() { @Override public void render(GuiGraphics guiGraphics, int pMouseX, int pMouseY, float pPartialTicks) { super.render(guiGraphics, pMouseX, pMouseY, pPartialTicks); - guiGraphics.drawString(font, EIOLang.INPUT.getString() +":", leftPos + 40, topPos + 18 - font.lineHeight - 2, 1, false); - guiGraphics.drawString(font, EIOLang.OUTPUT.getString() +":", leftPos + 40, topPos + 48 - font.lineHeight - 2, 1, false); + guiGraphics.drawString(font, EIOLang.INPUT.getString(), leftPos + 40, topPos + 18 - font.lineHeight - 2, 1, false); + guiGraphics.drawString(font, EIOLang.OUTPUT.getString(), leftPos + 40, topPos + 52 - font.lineHeight - 2, 1, false); + + String maxIO = "Max: " + NumberUtils.formatWithPrefix(Objects.requireNonNull(getMenu().getBlockEntity()).getEnergyStorage().getMaxEnergyUse()); + + guiGraphics.drawString(font, maxIO, leftPos + 40 + 95 - font.width(maxIO), topPos + 18 + font.lineHeight + 4, 0xff8b8b8b, false); + guiGraphics.drawString(font, maxIO, leftPos + 40 + 95 - font.width(maxIO), topPos + 52 + font.lineHeight + 4, 0xff8b8b8b, false); + + if (!this.getMenu().getBlockEntity().isCapacitorInstalled()) { + input.setValue("0"); + output.setValue("0"); + } } private void updateInput(String val) { diff --git a/src/machines/java/com/enderio/machines/client/gui/widget/EnergyTextboxWidget.java b/src/machines/java/com/enderio/machines/client/gui/widget/EnergyTextboxWidget.java index 075e542a12..7f5089ff14 100644 --- a/src/machines/java/com/enderio/machines/client/gui/widget/EnergyTextboxWidget.java +++ b/src/machines/java/com/enderio/machines/client/gui/widget/EnergyTextboxWidget.java @@ -108,7 +108,7 @@ public void renderWidget(GuiGraphics guiGraphics, int mouseX, int mouseY, float public void renderToolTip(GuiGraphics guiGraphics, int mouseX, int mouseY) { if (mouseX >= getX() && mouseX <= getX() + width && mouseY >= getY() && mouseY <= getY() + height && !isFocused() && maxEnergy.get() != 0) { - guiGraphics.renderTooltip(displayOn.getMinecraft().font, Component.literal(getValue() +"/" + maxEnergy.get() +" µI"), mouseX, mouseY); + guiGraphics.renderTooltip(displayOn.getMinecraft().font, Component.literal(getValue() +"/" + maxEnergy.get() +" µI/t"), mouseX, mouseY); } } diff --git a/src/machines/java/com/enderio/machines/common/blockentity/PowerBufferBlockEntity.java b/src/machines/java/com/enderio/machines/common/blockentity/PowerBufferBlockEntity.java index 384c38322e..d76fe5e84f 100644 --- a/src/machines/java/com/enderio/machines/common/blockentity/PowerBufferBlockEntity.java +++ b/src/machines/java/com/enderio/machines/common/blockentity/PowerBufferBlockEntity.java @@ -23,6 +23,8 @@ import net.minecraftforge.energy.IEnergyStorage; import org.jetbrains.annotations.Nullable; +import java.util.ArrayList; +import java.util.List; import java.util.Optional; import java.util.function.Supplier; @@ -33,7 +35,7 @@ public class PowerBufferBlockEntity extends PoweredMachineBlockEntity { int maxOutput = 0; protected IntegerNetworkDataSlot outputDataSlot; - // Stores textbox value beofre being converted to energy value + // Stores textbox value before being converted to energy value protected StringNetworkDataSlot inputTextDataSlot; String inputTextValue = "0"; protected StringNetworkDataSlot outputTextDataSlot; @@ -116,32 +118,67 @@ public int getMaxOutput() { return maxOutput; } - //Override method to be able to configure power output ! - //By default, it tries to push as much power as it can. - @Override - public void pushEnergy() { - if (!getExposedEnergyStorage().getIOMode().canOutput()) - return; + public List getDirections(boolean input) { + List dirs = new ArrayList<>(); + + if (!getExposedEnergyStorage().getIOMode().canOutput() && !input) + return new ArrayList<>(); for (Direction side : Direction.values()) { - - if (!shouldPushEnergyTo(side)) + + if (!shouldPushEnergyTo(side) && !input) continue; getCapability(ForgeCapabilities.ENERGY, side).resolve().ifPresent(selfHandler -> { Optional otherHandler = getNeighbouringCapability(ForgeCapabilities.ENERGY, side).resolve(); if (otherHandler.isPresent()) { - // If the other handler can receive power transmit ours and there is enough energy stored - if (otherHandler.get().canReceive() && getExposedEnergyStorage().getEnergyStored() - getMaxOutput() >= 0) { - - int received = otherHandler.get().receiveEnergy(getMaxOutput(), false); - // Consume that energy from our buffer. - getExposedEnergyStorage().extractEnergy(received, false); + if (input) { + if (otherHandler.get().canExtract()) { + dirs.add(side); + } + } else { + if (otherHandler.get().canReceive()) { + dirs.add(side); + } } } }); } + return dirs; + } + + //Distributes energy equally between sides (maxEnergy / number of sides) + @Override + public void pushEnergy() { + if (!getExposedEnergyStorage().getIOMode().canOutput()) + return; + + + List directions = getDirections(false); + int energyPerSide = directions.size() > 0 ? (int)getMaxOutput()/directions.size() : 0; + + for (int i = 0; i < directions.size(); i++) { + + //if last iteration, add remaining energy (for odd number of sides) + if (i == directions.size() -1 ) { + energyPerSide = energyPerSide + (getMaxOutput() - (energyPerSide * directions.size())); + } + + Direction side = directions.get(i); + Optional otherHandler = getNeighbouringCapability(ForgeCapabilities.ENERGY, side).resolve(); + + if (otherHandler.isPresent()) { + + // If the other handler can receive power transmit ours + if (otherHandler.get().canReceive() && getExposedEnergyStorage().getEnergyStored() >= 0) { + + int received = otherHandler.get().receiveEnergy(Math.min(energyPerSide, getExposedEnergyStorage().getEnergyStored()), false); + // Consume that energy from our buffer. + getExposedEnergyStorage().extractEnergy(received, false); + } + } + } } @Override @@ -153,6 +190,9 @@ protected boolean shouldPushEnergyTo(Direction direction) { protected MachineEnergyStorage createEnergyStorage(EnergyIOMode energyIOMode, Supplier capacity, Supplier usageRate) { return new MachineEnergyStorage(getIOConfig(), energyIOMode, capacity, usageRate) { + //helps to distribute energy input + int sideReceived = 0; + @Override public boolean canExtract() { return super.canExtract() && canAct(); @@ -165,10 +205,20 @@ public boolean canReceive() { @Override public int receiveEnergy(int maxReceive, boolean simulate) { - int energyReceived = Math.min(getMaxEnergyStored() - getEnergyStored(), Math.min(getMaxInput(), maxReceive)); + List dirs = getDirections(true); + int energyToReceive = getMaxInput() / dirs.size(); + + if (sideReceived == 0) { + energyToReceive += getMaxInput() % dirs.size(); + } + + int energyReceived = Math.min(getMaxEnergyStored() - getEnergyStored(), Math.min(energyToReceive, maxReceive)); + if (!simulate) { addEnergy(energyReceived); + sideReceived = (sideReceived + 1) % dirs.size(); } + return energyReceived; } };