From 147c2ff9fa0d66f2f063da3e0f3e94ddfc9d5245 Mon Sep 17 00:00:00 2001 From: simibubi <31564874+simibubi@users.noreply.github.com> Date: Wed, 27 Apr 2022 12:50:02 +0200 Subject: [PATCH] Gotta glue fast - Super glue is now applied through selecting areas of blocks --- src/generated/resources/.cache/cache | 32 ++-- .../resources/assets/create/lang/en_us.json | 9 + .../assets/create/lang/unfinished/de_de.json | 11 +- .../assets/create/lang/unfinished/es_cl.json | 11 +- .../assets/create/lang/unfinished/es_es.json | 11 +- .../assets/create/lang/unfinished/fr_fr.json | 11 +- .../assets/create/lang/unfinished/it_it.json | 11 +- .../assets/create/lang/unfinished/ja_jp.json | 11 +- .../assets/create/lang/unfinished/ko_kr.json | 11 +- .../assets/create/lang/unfinished/nl_nl.json | 11 +- .../assets/create/lang/unfinished/pl_pl.json | 11 +- .../assets/create/lang/unfinished/pt_br.json | 11 +- .../assets/create/lang/unfinished/pt_pt.json | 11 +- .../assets/create/lang/unfinished/ro_ro.json | 11 +- .../assets/create/lang/unfinished/ru_ru.json | 11 +- .../assets/create/lang/unfinished/zh_cn.json | 11 +- .../assets/create/lang/unfinished/zh_tw.json | 11 +- src/main/java/com/simibubi/create/Create.java | 2 + .../com/simibubi/create/CreateClient.java | 2 + .../structureMovement/glue/GlueQueue.java | 42 ++++ .../glue/SuperGlueEntity.java | 2 +- .../structureMovement/glue/SuperGlueItem.java | 27 ++- .../glue/SuperGlueSelectionHandler.java | 179 ++++++++++++++++++ .../glue/SuperGlueSelectionHelper.java | 106 +++++++++++ .../glue/SuperGlueSelectionPacket.java | 70 +++++++ .../simibubi/create/events/ClientEvents.java | 1 + .../simibubi/create/events/CommonEvents.java | 1 + .../simibubi/create/events/InputEvents.java | 13 +- .../foundation/networking/AllPackets.java | 2 + .../create/foundation/utility/Lang.java | 6 +- .../assets/create/lang/default/interface.json | 9 + 31 files changed, 630 insertions(+), 38 deletions(-) create mode 100644 src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/glue/GlueQueue.java create mode 100644 src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/glue/SuperGlueSelectionHandler.java create mode 100644 src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/glue/SuperGlueSelectionHelper.java create mode 100644 src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/glue/SuperGlueSelectionPacket.java diff --git a/src/generated/resources/.cache/cache b/src/generated/resources/.cache/cache index b092f8338..4438cf566 100644 --- a/src/generated/resources/.cache/cache +++ b/src/generated/resources/.cache/cache @@ -543,22 +543,22 @@ bf2b0310500213ff853c748c236eb5d01f61658e assets/create/blockstates/yellow_toolbo 7f39521b211441f5c3e06d60c5978cebe16cacfb assets/create/blockstates/zinc_block.json b7181bcd8182b2f17088e5aa881f374c9c65470c assets/create/blockstates/zinc_ore.json 7fbb25c577025ff61388c54c43401d8bb80723dd assets/create/lang/en_ud.json -7e435e07260a70aaed229404bd8404a8d2f4146d assets/create/lang/en_us.json -a07abc26a0f35dc516bb2ea0dfe372f35d74a2b9 assets/create/lang/unfinished/de_de.json -e1df1ec44c3b3fc33bf519c474f9296fdf124f5b assets/create/lang/unfinished/es_cl.json -12353413a397b287924a2f72acbdf61a58a145eb assets/create/lang/unfinished/es_es.json -11dd818781023f97b86a197f26f09b859d189ce6 assets/create/lang/unfinished/fr_fr.json -f503be711b19278b05a54cf16077a72787b09bd7 assets/create/lang/unfinished/it_it.json -4bae3ae77ddcf5a0284731b1816e035f6fe58253 assets/create/lang/unfinished/ja_jp.json -e421c88c3aa465136414a60c1af71fd31a6a31b8 assets/create/lang/unfinished/ko_kr.json -548acc508ae8b106501d4c0617447559f6ccdb9a assets/create/lang/unfinished/nl_nl.json -792d1859b3d850136d5757bec2c648764b3b90e2 assets/create/lang/unfinished/pl_pl.json -94d7667331e4bea254b21bb799703dcf8229516e assets/create/lang/unfinished/pt_br.json -3dc867a8a1c2a061e25bf3e4ca3e035cbb8a32f3 assets/create/lang/unfinished/pt_pt.json -4f24b259987998bd606096d83c13b26cdd7e0acc assets/create/lang/unfinished/ro_ro.json -a0709243bbdd2846b47f8388f7654314e0d2b357 assets/create/lang/unfinished/ru_ru.json -dcf1c00ffcd040619092d16e1bb5bd389482379d assets/create/lang/unfinished/zh_cn.json -7a0670419615f5a0f312e2516f6baec2f1be84f8 assets/create/lang/unfinished/zh_tw.json +21bf73628fbf1f4e3a496f3ae1b0511193f42ddc assets/create/lang/en_us.json +b8e107ed495ab72b5ee2e5d150d10bb6f9738ef2 assets/create/lang/unfinished/de_de.json +130c39194325888e3b7d8b0fe8186cc1064558b8 assets/create/lang/unfinished/es_cl.json +fcba07a025fb54f1de46953eaa182bd422ce8b07 assets/create/lang/unfinished/es_es.json +ff2a7df3eb9555df959761654bec0df7adc14a06 assets/create/lang/unfinished/fr_fr.json +1bbaf5201cbe698bdcb946168992f1a6c59a5b5c assets/create/lang/unfinished/it_it.json +62f5f1eb810e76911ddf26af4bd14ac9ff22205e assets/create/lang/unfinished/ja_jp.json +f9788d8bdd53e4b1ddaff505eeb5ff783ac6037d assets/create/lang/unfinished/ko_kr.json +afa72a4a1bc4d3aac3ee1960713c1ee7006d0d4d assets/create/lang/unfinished/nl_nl.json +d8c932f13fde024184ab121def7d4c14195e87a0 assets/create/lang/unfinished/pl_pl.json +e65c509495f72c872a3517b40f1cba3e81b2eb4a assets/create/lang/unfinished/pt_br.json +e3757ef8da2b88d3c83e6974c2d9ef36d1548121 assets/create/lang/unfinished/pt_pt.json +1313ea94854c11e4b55fe2a2cf143c5a548ec58d assets/create/lang/unfinished/ro_ro.json +7bc26d8d8b2162615513fba5dd4f48cf787f3f45 assets/create/lang/unfinished/ru_ru.json +2e704ec8d4cfb767cf22b7c154677e374f7377c9 assets/create/lang/unfinished/zh_cn.json +c6dba4495d3a03c2ea196c59c085f90ff9452b51 assets/create/lang/unfinished/zh_tw.json 487a511a01b2a4531fb672f917922312db78f958 assets/create/models/block/acacia_window.json b48060cba1a382f373a05bf0039054053eccf076 assets/create/models/block/acacia_window_pane_noside.json 3066db1bf03cffa1a9c7fbacf47ae586632f4eb3 assets/create/models/block/acacia_window_pane_noside_alt.json diff --git a/src/generated/resources/assets/create/lang/en_us.json b/src/generated/resources/assets/create/lang/en_us.json index 56bb38db7..3a6969647 100644 --- a/src/generated/resources/assets/create/lang/en_us.json +++ b/src/generated/resources/assets/create/lang/en_us.json @@ -1527,6 +1527,15 @@ "create.flap_display.cycles.instant": " ; ", "create.flap_display.cycles.pixel": "█;▒", + "create.super_glue.too_far": "Selected area is too big", + "create.super_glue.cannot_reach": "Selected blocks must be connected", + "create.super_glue.click_to_confirm": "Click again to confirm", + "create.super_glue.click_to_discard": "Sneak-click to discard selection", + "create.super_glue.first_pos": "First position selected", + "create.super_glue.abort": "Selection discarded", + "create.super_glue.not_enough": "Not enough glue in inventory", + "create.super_glue.sucess": "Applying Glue...", + "create.gui.config.overlay1": "Hi :)", "create.gui.config.overlay2": "This is a sample overlay", "create.gui.config.overlay3": "Click or drag with your mouse", diff --git a/src/generated/resources/assets/create/lang/unfinished/de_de.json b/src/generated/resources/assets/create/lang/unfinished/de_de.json index 9a06b39a1..b194b7637 100644 --- a/src/generated/resources/assets/create/lang/unfinished/de_de.json +++ b/src/generated/resources/assets/create/lang/unfinished/de_de.json @@ -1,5 +1,5 @@ { - "_": "Missing Localizations: 1528", + "_": "Missing Localizations: 1536", "_": "->------------------------] Game Elements [------------------------<-", @@ -1528,6 +1528,15 @@ "create.flap_display.cycles.instant": "UNLOCALIZED: ; ", "create.flap_display.cycles.pixel": "UNLOCALIZED: █;▒", + "create.super_glue.too_far": "UNLOCALIZED: Selected area is too big", + "create.super_glue.cannot_reach": "UNLOCALIZED: Selected blocks must be connected", + "create.super_glue.click_to_confirm": "UNLOCALIZED: Click again to confirm", + "create.super_glue.click_to_discard": "UNLOCALIZED: Sneak-click to discard selection", + "create.super_glue.first_pos": "UNLOCALIZED: First position selected", + "create.super_glue.abort": "UNLOCALIZED: Selection discarded", + "create.super_glue.not_enough": "UNLOCALIZED: Not enough glue in inventory", + "create.super_glue.sucess": "UNLOCALIZED: Applying Glue...", + "create.gui.config.overlay1": "Hi :)", "create.gui.config.overlay2": "Dies ist ein Beispiel Overlay", "create.gui.config.overlay3": "Klicke oder ziehe mit deiner Maus", diff --git a/src/generated/resources/assets/create/lang/unfinished/es_cl.json b/src/generated/resources/assets/create/lang/unfinished/es_cl.json index c52536050..ebc522724 100644 --- a/src/generated/resources/assets/create/lang/unfinished/es_cl.json +++ b/src/generated/resources/assets/create/lang/unfinished/es_cl.json @@ -1,5 +1,5 @@ { - "_": "Missing Localizations: 539", + "_": "Missing Localizations: 547", "_": "->------------------------] Game Elements [------------------------<-", @@ -1528,6 +1528,15 @@ "create.flap_display.cycles.instant": "UNLOCALIZED: ; ", "create.flap_display.cycles.pixel": "UNLOCALIZED: █;▒", + "create.super_glue.too_far": "UNLOCALIZED: Selected area is too big", + "create.super_glue.cannot_reach": "UNLOCALIZED: Selected blocks must be connected", + "create.super_glue.click_to_confirm": "UNLOCALIZED: Click again to confirm", + "create.super_glue.click_to_discard": "UNLOCALIZED: Sneak-click to discard selection", + "create.super_glue.first_pos": "UNLOCALIZED: First position selected", + "create.super_glue.abort": "UNLOCALIZED: Selection discarded", + "create.super_glue.not_enough": "UNLOCALIZED: Not enough glue in inventory", + "create.super_glue.sucess": "UNLOCALIZED: Applying Glue...", + "create.gui.config.overlay1": "Hola :)", "create.gui.config.overlay2": "Este es un overlay de ejemplo", "create.gui.config.overlay3": "Haz clic o arrastra con el mouse", diff --git a/src/generated/resources/assets/create/lang/unfinished/es_es.json b/src/generated/resources/assets/create/lang/unfinished/es_es.json index a44ee63f2..04aacb5f4 100644 --- a/src/generated/resources/assets/create/lang/unfinished/es_es.json +++ b/src/generated/resources/assets/create/lang/unfinished/es_es.json @@ -1,5 +1,5 @@ { - "_": "Missing Localizations: 210", + "_": "Missing Localizations: 218", "_": "->------------------------] Game Elements [------------------------<-", @@ -1528,6 +1528,15 @@ "create.flap_display.cycles.instant": "UNLOCALIZED: ; ", "create.flap_display.cycles.pixel": "UNLOCALIZED: █;▒", + "create.super_glue.too_far": "UNLOCALIZED: Selected area is too big", + "create.super_glue.cannot_reach": "UNLOCALIZED: Selected blocks must be connected", + "create.super_glue.click_to_confirm": "UNLOCALIZED: Click again to confirm", + "create.super_glue.click_to_discard": "UNLOCALIZED: Sneak-click to discard selection", + "create.super_glue.first_pos": "UNLOCALIZED: First position selected", + "create.super_glue.abort": "UNLOCALIZED: Selection discarded", + "create.super_glue.not_enough": "UNLOCALIZED: Not enough glue in inventory", + "create.super_glue.sucess": "UNLOCALIZED: Applying Glue...", + "create.gui.config.overlay1": "Hola :)", "create.gui.config.overlay2": "Esta es una muestra de la superposición", "create.gui.config.overlay3": "Haga clic o arrastre con el ratón", diff --git a/src/generated/resources/assets/create/lang/unfinished/fr_fr.json b/src/generated/resources/assets/create/lang/unfinished/fr_fr.json index 7072e81d3..47b5ead3c 100644 --- a/src/generated/resources/assets/create/lang/unfinished/fr_fr.json +++ b/src/generated/resources/assets/create/lang/unfinished/fr_fr.json @@ -1,5 +1,5 @@ { - "_": "Missing Localizations: 1790", + "_": "Missing Localizations: 1798", "_": "->------------------------] Game Elements [------------------------<-", @@ -1528,6 +1528,15 @@ "create.flap_display.cycles.instant": "UNLOCALIZED: ; ", "create.flap_display.cycles.pixel": "UNLOCALIZED: █;▒", + "create.super_glue.too_far": "UNLOCALIZED: Selected area is too big", + "create.super_glue.cannot_reach": "UNLOCALIZED: Selected blocks must be connected", + "create.super_glue.click_to_confirm": "UNLOCALIZED: Click again to confirm", + "create.super_glue.click_to_discard": "UNLOCALIZED: Sneak-click to discard selection", + "create.super_glue.first_pos": "UNLOCALIZED: First position selected", + "create.super_glue.abort": "UNLOCALIZED: Selection discarded", + "create.super_glue.not_enough": "UNLOCALIZED: Not enough glue in inventory", + "create.super_glue.sucess": "UNLOCALIZED: Applying Glue...", + "create.gui.config.overlay1": "UNLOCALIZED: Hi :)", "create.gui.config.overlay2": "UNLOCALIZED: This is a sample overlay", "create.gui.config.overlay3": "UNLOCALIZED: Click or drag with your mouse", diff --git a/src/generated/resources/assets/create/lang/unfinished/it_it.json b/src/generated/resources/assets/create/lang/unfinished/it_it.json index c8ba5bf94..7e4da414d 100644 --- a/src/generated/resources/assets/create/lang/unfinished/it_it.json +++ b/src/generated/resources/assets/create/lang/unfinished/it_it.json @@ -1,5 +1,5 @@ { - "_": "Missing Localizations: 1479", + "_": "Missing Localizations: 1487", "_": "->------------------------] Game Elements [------------------------<-", @@ -1528,6 +1528,15 @@ "create.flap_display.cycles.instant": "UNLOCALIZED: ; ", "create.flap_display.cycles.pixel": "UNLOCALIZED: █;▒", + "create.super_glue.too_far": "UNLOCALIZED: Selected area is too big", + "create.super_glue.cannot_reach": "UNLOCALIZED: Selected blocks must be connected", + "create.super_glue.click_to_confirm": "UNLOCALIZED: Click again to confirm", + "create.super_glue.click_to_discard": "UNLOCALIZED: Sneak-click to discard selection", + "create.super_glue.first_pos": "UNLOCALIZED: First position selected", + "create.super_glue.abort": "UNLOCALIZED: Selection discarded", + "create.super_glue.not_enough": "UNLOCALIZED: Not enough glue in inventory", + "create.super_glue.sucess": "UNLOCALIZED: Applying Glue...", + "create.gui.config.overlay1": "Ciao :)", "create.gui.config.overlay2": "Questo overlay è di esempio", "create.gui.config.overlay3": "Cliccalo o trascinalo col mouse", diff --git a/src/generated/resources/assets/create/lang/unfinished/ja_jp.json b/src/generated/resources/assets/create/lang/unfinished/ja_jp.json index da34a83bf..b22346151 100644 --- a/src/generated/resources/assets/create/lang/unfinished/ja_jp.json +++ b/src/generated/resources/assets/create/lang/unfinished/ja_jp.json @@ -1,5 +1,5 @@ { - "_": "Missing Localizations: 205", + "_": "Missing Localizations: 213", "_": "->------------------------] Game Elements [------------------------<-", @@ -1528,6 +1528,15 @@ "create.flap_display.cycles.instant": "UNLOCALIZED: ; ", "create.flap_display.cycles.pixel": "UNLOCALIZED: █;▒", + "create.super_glue.too_far": "UNLOCALIZED: Selected area is too big", + "create.super_glue.cannot_reach": "UNLOCALIZED: Selected blocks must be connected", + "create.super_glue.click_to_confirm": "UNLOCALIZED: Click again to confirm", + "create.super_glue.click_to_discard": "UNLOCALIZED: Sneak-click to discard selection", + "create.super_glue.first_pos": "UNLOCALIZED: First position selected", + "create.super_glue.abort": "UNLOCALIZED: Selection discarded", + "create.super_glue.not_enough": "UNLOCALIZED: Not enough glue in inventory", + "create.super_glue.sucess": "UNLOCALIZED: Applying Glue...", + "create.gui.config.overlay1": "やぁ(・∀・)", "create.gui.config.overlay2": "これはオーバーレイのサンプルです", "create.gui.config.overlay3": "マウスでクリックまたはドラッグしてください", diff --git a/src/generated/resources/assets/create/lang/unfinished/ko_kr.json b/src/generated/resources/assets/create/lang/unfinished/ko_kr.json index ef1439563..bb1750335 100644 --- a/src/generated/resources/assets/create/lang/unfinished/ko_kr.json +++ b/src/generated/resources/assets/create/lang/unfinished/ko_kr.json @@ -1,5 +1,5 @@ { - "_": "Missing Localizations: 205", + "_": "Missing Localizations: 213", "_": "->------------------------] Game Elements [------------------------<-", @@ -1528,6 +1528,15 @@ "create.flap_display.cycles.instant": "UNLOCALIZED: ; ", "create.flap_display.cycles.pixel": "UNLOCALIZED: █;▒", + "create.super_glue.too_far": "UNLOCALIZED: Selected area is too big", + "create.super_glue.cannot_reach": "UNLOCALIZED: Selected blocks must be connected", + "create.super_glue.click_to_confirm": "UNLOCALIZED: Click again to confirm", + "create.super_glue.click_to_discard": "UNLOCALIZED: Sneak-click to discard selection", + "create.super_glue.first_pos": "UNLOCALIZED: First position selected", + "create.super_glue.abort": "UNLOCALIZED: Selection discarded", + "create.super_glue.not_enough": "UNLOCALIZED: Not enough glue in inventory", + "create.super_glue.sucess": "UNLOCALIZED: Applying Glue...", + "create.gui.config.overlay1": "Hi :)", "create.gui.config.overlay2": "This is a sample overlay", "create.gui.config.overlay3": "Click or drag with your mouse", diff --git a/src/generated/resources/assets/create/lang/unfinished/nl_nl.json b/src/generated/resources/assets/create/lang/unfinished/nl_nl.json index d00f0bd6f..0c1e7c14d 100644 --- a/src/generated/resources/assets/create/lang/unfinished/nl_nl.json +++ b/src/generated/resources/assets/create/lang/unfinished/nl_nl.json @@ -1,5 +1,5 @@ { - "_": "Missing Localizations: 2143", + "_": "Missing Localizations: 2151", "_": "->------------------------] Game Elements [------------------------<-", @@ -1528,6 +1528,15 @@ "create.flap_display.cycles.instant": "UNLOCALIZED: ; ", "create.flap_display.cycles.pixel": "UNLOCALIZED: █;▒", + "create.super_glue.too_far": "UNLOCALIZED: Selected area is too big", + "create.super_glue.cannot_reach": "UNLOCALIZED: Selected blocks must be connected", + "create.super_glue.click_to_confirm": "UNLOCALIZED: Click again to confirm", + "create.super_glue.click_to_discard": "UNLOCALIZED: Sneak-click to discard selection", + "create.super_glue.first_pos": "UNLOCALIZED: First position selected", + "create.super_glue.abort": "UNLOCALIZED: Selection discarded", + "create.super_glue.not_enough": "UNLOCALIZED: Not enough glue in inventory", + "create.super_glue.sucess": "UNLOCALIZED: Applying Glue...", + "create.gui.config.overlay1": "UNLOCALIZED: Hi :)", "create.gui.config.overlay2": "UNLOCALIZED: This is a sample overlay", "create.gui.config.overlay3": "UNLOCALIZED: Click or drag with your mouse", diff --git a/src/generated/resources/assets/create/lang/unfinished/pl_pl.json b/src/generated/resources/assets/create/lang/unfinished/pl_pl.json index b733b4836..b7bedd453 100644 --- a/src/generated/resources/assets/create/lang/unfinished/pl_pl.json +++ b/src/generated/resources/assets/create/lang/unfinished/pl_pl.json @@ -1,5 +1,5 @@ { - "_": "Missing Localizations: 578", + "_": "Missing Localizations: 586", "_": "->------------------------] Game Elements [------------------------<-", @@ -1528,6 +1528,15 @@ "create.flap_display.cycles.instant": "UNLOCALIZED: ; ", "create.flap_display.cycles.pixel": "UNLOCALIZED: █;▒", + "create.super_glue.too_far": "UNLOCALIZED: Selected area is too big", + "create.super_glue.cannot_reach": "UNLOCALIZED: Selected blocks must be connected", + "create.super_glue.click_to_confirm": "UNLOCALIZED: Click again to confirm", + "create.super_glue.click_to_discard": "UNLOCALIZED: Sneak-click to discard selection", + "create.super_glue.first_pos": "UNLOCALIZED: First position selected", + "create.super_glue.abort": "UNLOCALIZED: Selection discarded", + "create.super_glue.not_enough": "UNLOCALIZED: Not enough glue in inventory", + "create.super_glue.sucess": "UNLOCALIZED: Applying Glue...", + "create.gui.config.overlay1": "Cześć :)", "create.gui.config.overlay2": "To jest przykładowa nakładka", "create.gui.config.overlay3": "Kliknij lub przeciągnij myszką", diff --git a/src/generated/resources/assets/create/lang/unfinished/pt_br.json b/src/generated/resources/assets/create/lang/unfinished/pt_br.json index 0679e0339..934c96364 100644 --- a/src/generated/resources/assets/create/lang/unfinished/pt_br.json +++ b/src/generated/resources/assets/create/lang/unfinished/pt_br.json @@ -1,5 +1,5 @@ { - "_": "Missing Localizations: 1390", + "_": "Missing Localizations: 1398", "_": "->------------------------] Game Elements [------------------------<-", @@ -1528,6 +1528,15 @@ "create.flap_display.cycles.instant": "UNLOCALIZED: ; ", "create.flap_display.cycles.pixel": "UNLOCALIZED: █;▒", + "create.super_glue.too_far": "UNLOCALIZED: Selected area is too big", + "create.super_glue.cannot_reach": "UNLOCALIZED: Selected blocks must be connected", + "create.super_glue.click_to_confirm": "UNLOCALIZED: Click again to confirm", + "create.super_glue.click_to_discard": "UNLOCALIZED: Sneak-click to discard selection", + "create.super_glue.first_pos": "UNLOCALIZED: First position selected", + "create.super_glue.abort": "UNLOCALIZED: Selection discarded", + "create.super_glue.not_enough": "UNLOCALIZED: Not enough glue in inventory", + "create.super_glue.sucess": "UNLOCALIZED: Applying Glue...", + "create.gui.config.overlay1": "UNLOCALIZED: Hi :)", "create.gui.config.overlay2": "UNLOCALIZED: This is a sample overlay", "create.gui.config.overlay3": "UNLOCALIZED: Click or drag with your mouse", diff --git a/src/generated/resources/assets/create/lang/unfinished/pt_pt.json b/src/generated/resources/assets/create/lang/unfinished/pt_pt.json index 7ec0893cf..8db619305 100644 --- a/src/generated/resources/assets/create/lang/unfinished/pt_pt.json +++ b/src/generated/resources/assets/create/lang/unfinished/pt_pt.json @@ -1,5 +1,5 @@ { - "_": "Missing Localizations: 1762", + "_": "Missing Localizations: 1770", "_": "->------------------------] Game Elements [------------------------<-", @@ -1528,6 +1528,15 @@ "create.flap_display.cycles.instant": "UNLOCALIZED: ; ", "create.flap_display.cycles.pixel": "UNLOCALIZED: █;▒", + "create.super_glue.too_far": "UNLOCALIZED: Selected area is too big", + "create.super_glue.cannot_reach": "UNLOCALIZED: Selected blocks must be connected", + "create.super_glue.click_to_confirm": "UNLOCALIZED: Click again to confirm", + "create.super_glue.click_to_discard": "UNLOCALIZED: Sneak-click to discard selection", + "create.super_glue.first_pos": "UNLOCALIZED: First position selected", + "create.super_glue.abort": "UNLOCALIZED: Selection discarded", + "create.super_glue.not_enough": "UNLOCALIZED: Not enough glue in inventory", + "create.super_glue.sucess": "UNLOCALIZED: Applying Glue...", + "create.gui.config.overlay1": "UNLOCALIZED: Hi :)", "create.gui.config.overlay2": "UNLOCALIZED: This is a sample overlay", "create.gui.config.overlay3": "UNLOCALIZED: Click or drag with your mouse", diff --git a/src/generated/resources/assets/create/lang/unfinished/ro_ro.json b/src/generated/resources/assets/create/lang/unfinished/ro_ro.json index c5e9629cd..1709a0df7 100644 --- a/src/generated/resources/assets/create/lang/unfinished/ro_ro.json +++ b/src/generated/resources/assets/create/lang/unfinished/ro_ro.json @@ -1,5 +1,5 @@ { - "_": "Missing Localizations: 206", + "_": "Missing Localizations: 214", "_": "->------------------------] Game Elements [------------------------<-", @@ -1528,6 +1528,15 @@ "create.flap_display.cycles.instant": "UNLOCALIZED: ; ", "create.flap_display.cycles.pixel": "UNLOCALIZED: █;▒", + "create.super_glue.too_far": "UNLOCALIZED: Selected area is too big", + "create.super_glue.cannot_reach": "UNLOCALIZED: Selected blocks must be connected", + "create.super_glue.click_to_confirm": "UNLOCALIZED: Click again to confirm", + "create.super_glue.click_to_discard": "UNLOCALIZED: Sneak-click to discard selection", + "create.super_glue.first_pos": "UNLOCALIZED: First position selected", + "create.super_glue.abort": "UNLOCALIZED: Selection discarded", + "create.super_glue.not_enough": "UNLOCALIZED: Not enough glue in inventory", + "create.super_glue.sucess": "UNLOCALIZED: Applying Glue...", + "create.gui.config.overlay1": "Hi :)", "create.gui.config.overlay2": "This is a sample overlay", "create.gui.config.overlay3": "Click or drag with your mouse", diff --git a/src/generated/resources/assets/create/lang/unfinished/ru_ru.json b/src/generated/resources/assets/create/lang/unfinished/ru_ru.json index ce5f0fbc0..a31e16450 100644 --- a/src/generated/resources/assets/create/lang/unfinished/ru_ru.json +++ b/src/generated/resources/assets/create/lang/unfinished/ru_ru.json @@ -1,5 +1,5 @@ { - "_": "Missing Localizations: 583", + "_": "Missing Localizations: 591", "_": "->------------------------] Game Elements [------------------------<-", @@ -1528,6 +1528,15 @@ "create.flap_display.cycles.instant": "UNLOCALIZED: ; ", "create.flap_display.cycles.pixel": "UNLOCALIZED: █;▒", + "create.super_glue.too_far": "UNLOCALIZED: Selected area is too big", + "create.super_glue.cannot_reach": "UNLOCALIZED: Selected blocks must be connected", + "create.super_glue.click_to_confirm": "UNLOCALIZED: Click again to confirm", + "create.super_glue.click_to_discard": "UNLOCALIZED: Sneak-click to discard selection", + "create.super_glue.first_pos": "UNLOCALIZED: First position selected", + "create.super_glue.abort": "UNLOCALIZED: Selection discarded", + "create.super_glue.not_enough": "UNLOCALIZED: Not enough glue in inventory", + "create.super_glue.sucess": "UNLOCALIZED: Applying Glue...", + "create.gui.config.overlay1": "Привет :)", "create.gui.config.overlay2": "Это образец оверлея", "create.gui.config.overlay3": "Кликни и тащи с помощью мыши", diff --git a/src/generated/resources/assets/create/lang/unfinished/zh_cn.json b/src/generated/resources/assets/create/lang/unfinished/zh_cn.json index b603f4b16..7390464e0 100644 --- a/src/generated/resources/assets/create/lang/unfinished/zh_cn.json +++ b/src/generated/resources/assets/create/lang/unfinished/zh_cn.json @@ -1,5 +1,5 @@ { - "_": "Missing Localizations: 205", + "_": "Missing Localizations: 213", "_": "->------------------------] Game Elements [------------------------<-", @@ -1528,6 +1528,15 @@ "create.flap_display.cycles.instant": "UNLOCALIZED: ; ", "create.flap_display.cycles.pixel": "UNLOCALIZED: █;▒", + "create.super_glue.too_far": "UNLOCALIZED: Selected area is too big", + "create.super_glue.cannot_reach": "UNLOCALIZED: Selected blocks must be connected", + "create.super_glue.click_to_confirm": "UNLOCALIZED: Click again to confirm", + "create.super_glue.click_to_discard": "UNLOCALIZED: Sneak-click to discard selection", + "create.super_glue.first_pos": "UNLOCALIZED: First position selected", + "create.super_glue.abort": "UNLOCALIZED: Selection discarded", + "create.super_glue.not_enough": "UNLOCALIZED: Not enough glue in inventory", + "create.super_glue.sucess": "UNLOCALIZED: Applying Glue...", + "create.gui.config.overlay1": "Hi :)", "create.gui.config.overlay2": "这是一个实例层", "create.gui.config.overlay3": "点击拖拽你的鼠标", diff --git a/src/generated/resources/assets/create/lang/unfinished/zh_tw.json b/src/generated/resources/assets/create/lang/unfinished/zh_tw.json index 0b1c51737..f09af56c8 100644 --- a/src/generated/resources/assets/create/lang/unfinished/zh_tw.json +++ b/src/generated/resources/assets/create/lang/unfinished/zh_tw.json @@ -1,5 +1,5 @@ { - "_": "Missing Localizations: 597", + "_": "Missing Localizations: 605", "_": "->------------------------] Game Elements [------------------------<-", @@ -1528,6 +1528,15 @@ "create.flap_display.cycles.instant": "UNLOCALIZED: ; ", "create.flap_display.cycles.pixel": "UNLOCALIZED: █;▒", + "create.super_glue.too_far": "UNLOCALIZED: Selected area is too big", + "create.super_glue.cannot_reach": "UNLOCALIZED: Selected blocks must be connected", + "create.super_glue.click_to_confirm": "UNLOCALIZED: Click again to confirm", + "create.super_glue.click_to_discard": "UNLOCALIZED: Sneak-click to discard selection", + "create.super_glue.first_pos": "UNLOCALIZED: First position selected", + "create.super_glue.abort": "UNLOCALIZED: Selection discarded", + "create.super_glue.not_enough": "UNLOCALIZED: Not enough glue in inventory", + "create.super_glue.sucess": "UNLOCALIZED: Applying Glue...", + "create.gui.config.overlay1": "嗨 :)", "create.gui.config.overlay2": "這是一個實例層", "create.gui.config.overlay3": "點擊拖拽你的滑鼠", diff --git a/src/main/java/com/simibubi/create/Create.java b/src/main/java/com/simibubi/create/Create.java index fa35898f1..3dbe5ba3a 100644 --- a/src/main/java/com/simibubi/create/Create.java +++ b/src/main/java/com/simibubi/create/Create.java @@ -11,6 +11,7 @@ import com.simibubi.create.api.behaviour.BlockSpoutingBehaviour; import com.simibubi.create.content.CreateItemGroup; import com.simibubi.create.content.contraptions.TorquePropagator; import com.simibubi.create.content.contraptions.components.flywheel.engine.FurnaceEngineInteractions; +import com.simibubi.create.content.contraptions.components.structureMovement.glue.GlueQueue; import com.simibubi.create.content.curiosities.weapons.BuiltinPotatoProjectileTypes; import com.simibubi.create.content.logistics.RedstoneLinkNetworkHandler; import com.simibubi.create.content.logistics.block.data.AllDataGathererBehaviours; @@ -76,6 +77,7 @@ public class Create { public static final TorquePropagator TORQUE_PROPAGATOR = new TorquePropagator(); public static final GlobalRailwayManager RAILWAYS = new GlobalRailwayManager(); public static final ServerLagger LAGGER = new ServerLagger(); + public static final GlueQueue GLUE_QUEUE = new GlueQueue(); public static final Random RANDOM = new Random(); private static final NonNullSupplier REGISTRATE = CreateRegistrate.lazy(ID); diff --git a/src/main/java/com/simibubi/create/CreateClient.java b/src/main/java/com/simibubi/create/CreateClient.java index 29f74b151..4d04b9c97 100644 --- a/src/main/java/com/simibubi/create/CreateClient.java +++ b/src/main/java/com/simibubi/create/CreateClient.java @@ -1,6 +1,7 @@ package com.simibubi.create; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; +import com.simibubi.create.content.contraptions.components.structureMovement.glue.SuperGlueSelectionHandler; import com.simibubi.create.content.contraptions.components.structureMovement.render.ContraptionRenderDispatcher; import com.simibubi.create.content.contraptions.components.structureMovement.render.SBBContraptionManager; import com.simibubi.create.content.contraptions.goggles.GoggleOverlayRenderer; @@ -54,6 +55,7 @@ public class CreateClient { public static final ClientSchematicLoader SCHEMATIC_SENDER = new ClientSchematicLoader(); public static final SchematicHandler SCHEMATIC_HANDLER = new SchematicHandler(); public static final SchematicAndQuillHandler SCHEMATIC_AND_QUILL_HANDLER = new SchematicAndQuillHandler(); + public static final SuperGlueSelectionHandler GLUE_HANDLER = new SuperGlueSelectionHandler(); public static final ZapperRenderHandler ZAPPER_RENDER_HANDLER = new ZapperRenderHandler(); public static final PotatoCannonRenderHandler POTATO_CANNON_RENDER_HANDLER = new PotatoCannonRenderHandler(); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/glue/GlueQueue.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/glue/GlueQueue.java new file mode 100644 index 000000000..5d71b43d3 --- /dev/null +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/glue/GlueQueue.java @@ -0,0 +1,42 @@ +package com.simibubi.create.content.contraptions.components.structureMovement.glue; + +import java.util.Collection; +import java.util.LinkedList; +import java.util.List; + +import com.simibubi.create.AllSoundEvents; +import com.simibubi.create.foundation.networking.AllPackets; +import com.simibubi.create.foundation.utility.BlockFace; +import com.simibubi.create.foundation.utility.WorldAttached; + +import net.minecraft.util.Mth; +import net.minecraft.world.level.Level; +import net.minecraftforge.network.PacketDistributor; + +public class GlueQueue { + + private WorldAttached> QUEUED_GLUE = new WorldAttached<>(level -> new LinkedList<>()); + + public void tick(Level level) { + List list = QUEUED_GLUE.get(level); + if (list.isEmpty()) + return; + BlockFace next = list.remove(0); + if (!level.isLoaded(next.getPos())) + return; + + SuperGlueEntity entity = new SuperGlueEntity(level, next.getPos(), next.getFace()); + level.addFreshEntity(entity); + AllSoundEvents.SLIME_ADDED.playFrom(entity, 0.125F, Mth.clamp(8f / (list.size() + 1), 0.75f, 1f)); + + AllPackets.channel.send(PacketDistributor.ALL.noArg(), + new GlueEffectPacket(entity.getHangingPosition(), entity.getFacingDirection() + .getOpposite(), false)); + } + + public void add(Level level, Collection entries) { + QUEUED_GLUE.get(level) + .addAll(entries); + } + +} diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/glue/SuperGlueEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/glue/SuperGlueEntity.java index 767c66f88..a063a53ff 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/glue/SuperGlueEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/glue/SuperGlueEntity.java @@ -181,7 +181,7 @@ public class SuperGlueEntity extends Entity BlockPos pos2 = hangingPosition.relative(getFacingDirection().getOpposite()); if (level.isOutsideBuildHeight(pos2)) return false; - if (!level.isAreaLoaded(pos, 0) || !level.isAreaLoaded(pos2, 0)) + if (!level.isLoaded(pos) || !level.isLoaded(pos2)) return true; if (!isValidFace(level, pos2, getFacingDirection()) && !isValidFace(level, pos, getFacingDirection().getOpposite())) diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/glue/SuperGlueItem.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/glue/SuperGlueItem.java index d32adf0ec..151a9024e 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/glue/SuperGlueItem.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/glue/SuperGlueItem.java @@ -1,5 +1,6 @@ package com.simibubi.create.content.contraptions.components.structureMovement.glue; +import com.simibubi.create.content.contraptions.components.structureMovement.chassis.AbstractChassisBlock; import com.simibubi.create.foundation.utility.VecHelper; import net.minecraft.core.BlockPos; @@ -16,12 +17,34 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; import net.minecraft.world.item.context.UseOnContext; import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.phys.Vec3; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; +import net.minecraftforge.event.entity.player.PlayerInteractEvent; +import net.minecraftforge.eventbus.api.Event.Result; +import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.fml.common.Mod.EventBusSubscriber; +@EventBusSubscriber public class SuperGlueItem extends Item { + @SubscribeEvent + public static void glueItemAlwaysPlacesWhenUsed(PlayerInteractEvent.RightClickBlock event) { + if (event.getHitVec() != null) { + BlockState blockState = event.getWorld() + .getBlockState(event.getHitVec() + .getBlockPos()); + if (blockState.getBlock()instanceof AbstractChassisBlock cb) + if (cb.getGlueableSide(blockState, event.getFace()) != null) + return; + } + + if (event.getItemStack() + .getItem() instanceof SuperGlueItem) + event.setUseBlock(Result.DENY); + } + public SuperGlueItem(Properties properties) { super(properties); } @@ -84,8 +107,8 @@ public class SuperGlueItem extends Item { Vec3 motion = offset.normalize() .scale(1 / 16f); if (fullBlock) - offset = new Vec3(Mth.clamp(offset.x, -.5, .5), Mth.clamp(offset.y, -.5, .5), - Mth.clamp(offset.z, -.5, .5)); + offset = + new Vec3(Mth.clamp(offset.x, -.5, .5), Mth.clamp(offset.y, -.5, .5), Mth.clamp(offset.z, -.5, .5)); Vec3 particlePos = facePos.add(offset); world.addParticle(new ItemParticleOption(ParticleTypes.ITEM, stack), particlePos.x, particlePos.y, particlePos.z, motion.x, motion.y, motion.z); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/glue/SuperGlueSelectionHandler.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/glue/SuperGlueSelectionHandler.java new file mode 100644 index 000000000..a5cca8d75 --- /dev/null +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/glue/SuperGlueSelectionHandler.java @@ -0,0 +1,179 @@ +package com.simibubi.create.content.contraptions.components.structureMovement.glue; + +import java.util.List; +import java.util.Set; + +import com.google.common.base.Objects; +import com.simibubi.create.AllSpecialTextures; +import com.simibubi.create.CreateClient; +import com.simibubi.create.content.contraptions.components.structureMovement.chassis.AbstractChassisBlock; +import com.simibubi.create.foundation.networking.AllPackets; +import com.simibubi.create.foundation.utility.BlockFace; +import com.simibubi.create.foundation.utility.Lang; +import com.simibubi.create.foundation.utility.Pair; +import com.simibubi.create.foundation.utility.outliner.Outline.OutlineParams; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.multiplayer.ClientLevel; +import net.minecraft.client.player.LocalPlayer; +import net.minecraft.core.BlockPos; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.phys.AABB; +import net.minecraft.world.phys.BlockHitResult; +import net.minecraft.world.phys.HitResult; +import net.minecraft.world.phys.HitResult.Type; + +public class SuperGlueSelectionHandler { + + private static final int SUCCESS = 0x68c586; + private static final int FAIL = 0xc5b548; + + private Object clusterOutlineSlot = new Object(); + private Object bbOutlineSlot = new Object(); + + private BlockPos firstPos; + private BlockPos hoveredPos; + private Set currentCluster; + private int glueRequired; + + public void tick() { + Minecraft mc = Minecraft.getInstance(); + LocalPlayer player = mc.player; + BlockPos hovered = null; + ItemStack stack = player.getMainHandItem(); + + if (!isGlue(stack)) { + if (firstPos != null) + discard(); + return; + } + + HitResult hitResult = mc.hitResult; + if (hitResult != null && hitResult.getType() == Type.BLOCK) + hovered = ((BlockHitResult) hitResult).getBlockPos(); + + if (hovered == null) { + hoveredPos = null; + return; + } + + if (firstPos != null && !firstPos.closerThan(hovered, 24)) { + Lang.sendStatus(player, FAIL, "super_glue.too_far"); + return; + } + + boolean cancel = player.isSteppingCarefully(); + if (cancel && firstPos == null) + return; + + AABB currentSelectionBox = getCurrentSelectionBox(); + + boolean unchanged = Objects.equal(hovered, hoveredPos); + + if (unchanged) { + if (currentCluster != null) { + boolean canReach = currentCluster.contains(hovered); + boolean canAfford = SuperGlueSelectionHelper.collectGlueFromInventory(player, glueRequired, true); + + if (!canReach) + Lang.sendStatus(player, FAIL, "super_glue.cannot_reach"); + else if (!canAfford) + Lang.sendStatus(player, FAIL, "super_glue.not_enough"); + else if (cancel) + Lang.sendStatus(player, FAIL, "super_glue.click_to_discard"); + else + Lang.sendStatus(player, SUCCESS, "super_glue.click_to_confirm"); + + CreateClient.OUTLINER.showCluster(clusterOutlineSlot, currentCluster) + .colored(canReach && canAfford && !cancel ? SUCCESS : FAIL) + .withFaceTextures(AllSpecialTextures.CHECKERED, AllSpecialTextures.HIGHLIGHT_CHECKERED) + .lineWidth(1 / 16f); + } + if (currentSelectionBox != null) { + OutlineParams params = + firstPos == null ? CreateClient.OUTLINER.showAABB(bbOutlineSlot, currentSelectionBox) + : CreateClient.OUTLINER.chaseAABB(bbOutlineSlot, currentSelectionBox); + params.colored(0x111111) + .disableNormals() + .lineWidth(1 / 128f); + } + return; + } + + hoveredPos = hovered; + + Pair, List> pair = + SuperGlueSelectionHelper.searchGlueGroup(mc.level, firstPos, hoveredPos); + + currentCluster = pair == null ? null : pair.getFirst(); + glueRequired = pair == null ? 0 + : pair.getSecond() + .size(); + } + + private boolean isGlue(ItemStack stack) { + return stack.getItem() instanceof SuperGlueItem; + } + + private AABB getCurrentSelectionBox() { + return firstPos == null || hoveredPos == null ? null : new AABB(firstPos, hoveredPos).expandTowards(1, 1, 1); + } + + public boolean onMouseInput() { + Minecraft mc = Minecraft.getInstance(); + LocalPlayer player = mc.player; + ClientLevel level = mc.level; + + if (!isGlue(player.getMainHandItem())) + return false; + + if (player.isSteppingCarefully()) { + if (firstPos != null) { + discard(); + return true; + } + return false; + } + + if (hoveredPos == null) + return false; + + if (mc.hitResult instanceof BlockHitResult bhr) { + BlockState blockState = level.getBlockState(hoveredPos); + if (blockState.getBlock()instanceof AbstractChassisBlock cb) + if (cb.getGlueableSide(blockState, bhr.getDirection()) != null) + return false; + } + + if (firstPos != null && currentCluster != null) { + boolean canReach = currentCluster.contains(hoveredPos); + boolean canAfford = SuperGlueSelectionHelper.collectGlueFromInventory(player, glueRequired, true); + + if (!canReach || !canAfford) + return true; + + confirm(); + return true; + } + + firstPos = hoveredPos; + Lang.sendStatus(player, "super_glue.first_pos"); + return true; + } + + public void discard() { + LocalPlayer player = Minecraft.getInstance().player; + currentCluster = null; + firstPos = null; + Lang.sendStatus(player, "super_glue.abort"); + } + + public void confirm() { + LocalPlayer player = Minecraft.getInstance().player; + AllPackets.channel.sendToServer(new SuperGlueSelectionPacket(firstPos, hoveredPos)); + discard(); + Lang.sendStatus(player, "super_glue.sucess"); + } + +} diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/glue/SuperGlueSelectionHelper.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/glue/SuperGlueSelectionHelper.java new file mode 100644 index 000000000..7c9e426f0 --- /dev/null +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/glue/SuperGlueSelectionHelper.java @@ -0,0 +1,106 @@ +package com.simibubi.create.content.contraptions.components.structureMovement.glue; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import com.simibubi.create.content.contraptions.components.structureMovement.BlockMovementChecks; +import com.simibubi.create.foundation.utility.BlockFace; +import com.simibubi.create.foundation.utility.Iterate; +import com.simibubi.create.foundation.utility.Pair; + +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.core.NonNullList; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.Level; +import net.minecraft.world.phys.AABB; +import net.minecraft.world.phys.Vec3; + +public class SuperGlueSelectionHelper { + + public static Pair, List> searchGlueGroup(Level level, BlockPos startPos, + BlockPos endPos) { + if (endPos == null || startPos == null) + return null; + + AABB bb = new AABB(startPos, endPos).expandTowards(1, 1, 1); + + List frontier = new ArrayList<>(); + Set visited = new HashSet<>(); + Set attached = new HashSet<>(); + List glue = new ArrayList<>(); + + visited.add(startPos); + frontier.add(startPos); + + while (!frontier.isEmpty()) { + BlockPos currentPos = frontier.remove(0); + attached.add(currentPos); + + Map gatheredGlue = SuperGlueHandler.gatherGlue(level, currentPos); + for (Direction d : Iterate.directions) { + BlockPos offset = currentPos.relative(d); + boolean gluePresent = gatheredGlue.containsKey(d); + boolean alreadySticky = SuperGlueEntity.isSideSticky(level, currentPos, d) + || SuperGlueEntity.isSideSticky(level, offset, d.getOpposite()); + + if (!alreadySticky && !gluePresent && !bb.contains(Vec3.atCenterOf(offset))) + continue; + if (!BlockMovementChecks.isMovementNecessary(level.getBlockState(offset), level, offset)) + continue; + if (!SuperGlueEntity.isValidFace(level, currentPos, d) + || !SuperGlueEntity.isValidFace(level, offset, d.getOpposite())) + continue; + + boolean glueNecessary = !gluePresent && !alreadySticky; + + if (visited.add(offset)) { + frontier.add(offset); + if (glueNecessary) + glue.add(new BlockFace(offset, d)); + } + } + } + + if (attached.size() < 2 && attached.contains(endPos)) + return null; + + return Pair.of(attached, glue); + } + + public static boolean collectGlueFromInventory(Player player, int requiredAmount, boolean simulate) { + if (player.getAbilities().instabuild) + return true; + if (requiredAmount == 0) + return true; + + NonNullList items = player.getInventory().items; + for (int i = -1; i < items.size(); i++) { + int slot = i == -1 ? player.getInventory().selected : i; + ItemStack stack = items.get(slot); + if (stack.isEmpty()) + continue; + if (!stack.isDamageableItem()) + continue; + if (!(stack.getItem() instanceof SuperGlueItem)) + continue; + + int charges = Math.min(requiredAmount, stack.getMaxDamage() - stack.getDamageValue()); + + if (!simulate) + stack.hurtAndBreak(charges, player, i == -1 ? SuperGlueItem::onBroken : $ -> { + }); + + requiredAmount -= charges; + if (requiredAmount <= 0) + return true; + } + + return false; + } + +} diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/glue/SuperGlueSelectionPacket.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/glue/SuperGlueSelectionPacket.java new file mode 100644 index 000000000..15420a95a --- /dev/null +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/glue/SuperGlueSelectionPacket.java @@ -0,0 +1,70 @@ +package com.simibubi.create.content.contraptions.components.structureMovement.glue; + +import java.util.List; +import java.util.Set; +import java.util.function.Supplier; + +import com.simibubi.create.Create; +import com.simibubi.create.foundation.networking.SimplePacketBase; +import com.simibubi.create.foundation.utility.BlockFace; +import com.simibubi.create.foundation.utility.Pair; + +import net.minecraft.core.BlockPos; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.phys.Vec3; +import net.minecraftforge.common.ForgeMod; +import net.minecraftforge.network.NetworkEvent.Context; + +public class SuperGlueSelectionPacket extends SimplePacketBase { + + private BlockPos from; + private BlockPos to; + + public SuperGlueSelectionPacket(BlockPos from, BlockPos to) { + this.from = from; + this.to = to; + } + + public SuperGlueSelectionPacket(FriendlyByteBuf buffer) { + from = buffer.readBlockPos(); + to = buffer.readBlockPos(); + } + + @Override + public void write(FriendlyByteBuf buffer) { + buffer.writeBlockPos(from); + buffer.writeBlockPos(to); + } + + @Override + public void handle(Supplier context) { + Context ctx = context.get(); + ctx.enqueueWork(() -> { + ServerPlayer player = ctx.getSender(); + + double range = player.getAttribute(ForgeMod.REACH_DISTANCE.get()) + .getValue() + 2; + if (player.distanceToSqr(Vec3.atCenterOf(to)) > range * range) + return; + if (!to.closerThan(from, 25)) + return; + + Pair, List> group = + SuperGlueSelectionHelper.searchGlueGroup(player.level, from, to); + if (group == null) + return; + if (!group.getFirst() + .contains(to)) + return; + List glue = group.getSecond(); + if (!SuperGlueSelectionHelper.collectGlueFromInventory(player, glue.size(), true)) + return; + + SuperGlueSelectionHelper.collectGlueFromInventory(player, glue.size(), false); + Create.GLUE_QUEUE.add(player.level, glue); + }); + ctx.setPacketHandled(true); + } + +} diff --git a/src/main/java/com/simibubi/create/events/ClientEvents.java b/src/main/java/com/simibubi/create/events/ClientEvents.java index 706312fc2..6876cb7ec 100644 --- a/src/main/java/com/simibubi/create/events/ClientEvents.java +++ b/src/main/java/com/simibubi/create/events/ClientEvents.java @@ -122,6 +122,7 @@ public class ClientEvents { CreateClient.SCHEMATIC_SENDER.tick(); CreateClient.SCHEMATIC_AND_QUILL_HANDLER.tick(); + CreateClient.GLUE_HANDLER.tick(); CreateClient.SCHEMATIC_HANDLER.tick(); CreateClient.ZAPPER_RENDER_HANDLER.tick(); CreateClient.POTATO_CANNON_RENDER_HANDLER.tick(); diff --git a/src/main/java/com/simibubi/create/events/CommonEvents.java b/src/main/java/com/simibubi/create/events/CommonEvents.java index 57582f7a0..720916cee 100644 --- a/src/main/java/com/simibubi/create/events/CommonEvents.java +++ b/src/main/java/com/simibubi/create/events/CommonEvents.java @@ -122,6 +122,7 @@ public class CommonEvents { LinkedControllerServerHandler.tick(world); ControlsServerHandler.tick(world); Create.RAILWAYS.tick(world); + Create.GLUE_QUEUE.tick(world); } @SubscribeEvent diff --git a/src/main/java/com/simibubi/create/events/InputEvents.java b/src/main/java/com/simibubi/create/events/InputEvents.java index 2b99dacc2..f17ef8bec 100644 --- a/src/main/java/com/simibubi/create/events/InputEvents.java +++ b/src/main/java/com/simibubi/create/events/InputEvents.java @@ -59,15 +59,22 @@ public class InputEvents { @SubscribeEvent public static void onClickInput(ClickInputEvent event) { - if (Minecraft.getInstance().screen != null) + Minecraft mc = Minecraft.getInstance(); + if (mc.screen != null) return; - + if (CurvedTrackInteraction.onClickInput(event)) { event.setCanceled(true); return; } - if (event.getKeyMapping() == Minecraft.getInstance().options.keyPickItem) { + if (event.getKeyMapping() == mc.options.keyUse) { + if (CreateClient.GLUE_HANDLER.onMouseInput()) + event.setCanceled(true); + return; + } + + if (event.getKeyMapping() == mc.options.keyPickItem) { if (ToolboxHandlerClient.onPickItem()) event.setCanceled(true); return; diff --git a/src/main/java/com/simibubi/create/foundation/networking/AllPackets.java b/src/main/java/com/simibubi/create/foundation/networking/AllPackets.java index 45ad7bdfb..3d88c566f 100644 --- a/src/main/java/com/simibubi/create/foundation/networking/AllPackets.java +++ b/src/main/java/com/simibubi/create/foundation/networking/AllPackets.java @@ -12,6 +12,7 @@ import com.simibubi.create.content.contraptions.components.structureMovement.Con import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionStallPacket; import com.simibubi.create.content.contraptions.components.structureMovement.gantry.GantryContraptionUpdatePacket; import com.simibubi.create.content.contraptions.components.structureMovement.glue.GlueEffectPacket; +import com.simibubi.create.content.contraptions.components.structureMovement.glue.SuperGlueSelectionPacket; import com.simibubi.create.content.contraptions.components.structureMovement.interaction.controls.ControlsInputPacket; import com.simibubi.create.content.contraptions.components.structureMovement.interaction.controls.ControlsStopControllingPacket; import com.simibubi.create.content.contraptions.components.structureMovement.sync.ClientMotionPacket; @@ -128,6 +129,7 @@ public enum AllPackets { DESTROY_CURVED_TRACK(CurvedTrackDestroyPacket.class, CurvedTrackDestroyPacket::new, PLAY_TO_SERVER), SELECT_CURVED_TRACK(CurvedTrackSelectionPacket.class, CurvedTrackSelectionPacket::new, PLAY_TO_SERVER), PLACE_CURVED_TRACK(PlaceExtendedCurvePacket.class, PlaceExtendedCurvePacket::new, PLAY_TO_SERVER), + GLUE_IN_AREA(SuperGlueSelectionPacket.class, SuperGlueSelectionPacket::new, PLAY_TO_SERVER), // Server to Client SYMMETRY_EFFECT(SymmetryEffectPacket.class, SymmetryEffectPacket::new, PLAY_TO_CLIENT), diff --git a/src/main/java/com/simibubi/create/foundation/utility/Lang.java b/src/main/java/com/simibubi/create/foundation/utility/Lang.java index df05c2320..80931eca7 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/Lang.java +++ b/src/main/java/com/simibubi/create/foundation/utility/Lang.java @@ -24,6 +24,10 @@ public class Lang { player.displayClientMessage(createTranslationTextComponent(key, args), true); } + public static void sendStatus(Player player, int color, String key, Object... args) { + player.displayClientMessage(createTranslationTextComponent(key, args).withStyle(p -> p.withColor(color)), true); + } + public static List translatedOptions(String prefix, String... keys) { List result = new ArrayList<>(keys.length); for (String key : keys) @@ -35,7 +39,7 @@ public class Lang { public static String asId(String name) { return name.toLowerCase(Locale.ROOT); } - + public static String nonPluralId(String name) { String asId = asId(name); return asId.endsWith("s") ? asId.substring(0, asId.length() - 1) : asId; diff --git a/src/main/resources/assets/create/lang/default/interface.json b/src/main/resources/assets/create/lang/default/interface.json index 02c30ede5..0d03e2e21 100644 --- a/src/main/resources/assets/create/lang/default/interface.json +++ b/src/main/resources/assets/create/lang/default/interface.json @@ -751,6 +751,15 @@ "create.flap_display.cycles.instant": " ; ", "create.flap_display.cycles.pixel": "\u2588;\u2592", + "create.super_glue.too_far": "Selected area is too big", + "create.super_glue.cannot_reach": "Selected blocks must be connected", + "create.super_glue.click_to_confirm": "Click again to confirm", + "create.super_glue.click_to_discard": "Sneak-click to discard selection", + "create.super_glue.first_pos": "First position selected", + "create.super_glue.abort": "Selection discarded", + "create.super_glue.not_enough": "Not enough glue in inventory", + "create.super_glue.sucess": "Applying Glue...", + "create.gui.config.overlay1": "Hi :)", "create.gui.config.overlay2": "This is a sample overlay", "create.gui.config.overlay3": "Click or drag with your mouse",