CreateMod/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/Contraption.java

1417 lines
52 KiB
Java
Raw Normal View History

2020-05-23 14:02:38 +02:00
package com.simibubi.create.content.contraptions.components.structureMovement;
import static com.simibubi.create.content.contraptions.components.structureMovement.piston.MechanicalPistonBlock.isExtensionPole;
import static com.simibubi.create.content.contraptions.components.structureMovement.piston.MechanicalPistonBlock.isPistonHead;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Optional;
import java.util.Queue;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.function.BiConsumer;
import javax.annotation.Nullable;
import org.apache.commons.lang3.tuple.MutablePair;
import org.apache.commons.lang3.tuple.Pair;
import com.simibubi.create.AllBlockEntityTypes;
2020-05-22 20:12:53 +02:00
import com.simibubi.create.AllBlocks;
2021-11-02 06:18:30 +01:00
import com.simibubi.create.AllInteractionBehaviours;
import com.simibubi.create.AllMovementBehaviours;
import com.simibubi.create.content.contraptions.base.IRotate;
import com.simibubi.create.content.contraptions.base.KineticBlockEntity;
import com.simibubi.create.content.contraptions.components.actors.BlockBreakingMovementBehaviour;
import com.simibubi.create.content.contraptions.components.actors.HarvesterMovementBehaviour;
import com.simibubi.create.content.contraptions.components.actors.SeatBlock;
import com.simibubi.create.content.contraptions.components.actors.SeatEntity;
import com.simibubi.create.content.contraptions.components.actors.controls.ContraptionControlsMovement;
import com.simibubi.create.content.contraptions.components.steam.PoweredShaftBlockEntity;
import com.simibubi.create.content.contraptions.components.structureMovement.bearing.MechanicalBearingBlock;
import com.simibubi.create.content.contraptions.components.structureMovement.bearing.StabilizedContraption;
import com.simibubi.create.content.contraptions.components.structureMovement.bearing.WindmillBearingBlock;
import com.simibubi.create.content.contraptions.components.structureMovement.bearing.WindmillBearingBlockEntity;
2020-05-23 14:02:38 +02:00
import com.simibubi.create.content.contraptions.components.structureMovement.chassis.AbstractChassisBlock;
import com.simibubi.create.content.contraptions.components.structureMovement.chassis.ChassisBlockEntity;
import com.simibubi.create.content.contraptions.components.structureMovement.chassis.StickerBlock;
import com.simibubi.create.content.contraptions.components.structureMovement.gantry.GantryCarriageBlock;
2020-05-23 14:02:38 +02:00
import com.simibubi.create.content.contraptions.components.structureMovement.glue.SuperGlueEntity;
2022-02-01 01:14:21 +01:00
import com.simibubi.create.content.contraptions.components.structureMovement.interaction.controls.ControlsBlock;
2020-05-23 14:02:38 +02:00
import com.simibubi.create.content.contraptions.components.structureMovement.piston.MechanicalPistonBlock;
import com.simibubi.create.content.contraptions.components.structureMovement.piston.MechanicalPistonBlock.PistonState;
import com.simibubi.create.content.contraptions.components.structureMovement.piston.MechanicalPistonHeadBlock;
import com.simibubi.create.content.contraptions.components.structureMovement.piston.PistonExtensionPoleBlock;
2020-05-23 14:02:38 +02:00
import com.simibubi.create.content.contraptions.components.structureMovement.pulley.PulleyBlock;
import com.simibubi.create.content.contraptions.components.structureMovement.pulley.PulleyBlock.MagnetBlock;
import com.simibubi.create.content.contraptions.components.structureMovement.pulley.PulleyBlock.RopeBlock;
import com.simibubi.create.content.contraptions.components.structureMovement.pulley.PulleyBlockEntity;
import com.simibubi.create.content.contraptions.components.structureMovement.render.ContraptionLighter;
import com.simibubi.create.content.contraptions.components.structureMovement.render.EmptyLighter;
import com.simibubi.create.content.contraptions.fluids.tank.FluidTankBlockEntity;
import com.simibubi.create.content.contraptions.relays.advanced.GantryShaftBlock;
2020-05-23 14:02:38 +02:00
import com.simibubi.create.content.contraptions.relays.belt.BeltBlock;
import com.simibubi.create.content.contraptions.relays.elementary.ShaftBlock;
import com.simibubi.create.content.curiosities.deco.SlidingDoorBlock;
import com.simibubi.create.content.logistics.block.inventories.CreativeCrateBlockEntity;
2020-05-23 14:02:38 +02:00
import com.simibubi.create.content.logistics.block.redstone.RedstoneContactBlock;
import com.simibubi.create.content.logistics.block.vault.ItemVaultBlockEntity;
Squashed commit of the following: commit 053dd09df6c426ab5e570f42a1edb5df3d0fbd01 Merge: 6d1e1c71d ecc645eba Author: simibubi <31564874+simibubi@users.noreply.github.com> Date: Tue May 9 18:22:42 2023 +0200 Merge branch '1.18/api' of https://github.com/Layers-of-Railways/Create into pr/4692 commit ecc645eba7bfd5f86b9bfb16ee1236a5d6432d3d Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Tue May 9 11:24:11 2023 +0100 Implemented support for creating and removing individual blockstate models commit 6d1e1c71de7ce20f6fd9fc8ed4ed9bdd1072829a Author: simibubi <31564874+simibubi@users.noreply.github.com> Date: Tue May 9 12:16:54 2023 +0200 Less error logging when migrating old worlds commit 205e47352ec46f8e300167db69023c7938a52b58 Author: techno-sam <linux.techno.sam@gmail.com> Date: Mon May 8 21:02:19 2023 -0700 Fix up ItemOutline commit 6cf204f6afd12671060d198d5a09efe9cd04c7b5 Merge: fe049bc77 2e3c906ce Author: techno-sam <linux.techno.sam@gmail.com> Date: Mon May 8 20:28:56 2023 -0700 Merge remote-tracking branch 'upstream/mc1.18/dev' into 1.18/api # Conflicts: # src/main/java/com/simibubi/create/content/logistics/trains/entity/CarriageCouplingRenderer.java commit fe049bc771cc3a4dd91f5c91f098aa7448af6c8d Author: techno-sam <linux.techno.sam@gmail.com> Date: Mon May 8 20:26:16 2023 -0700 Revert "Revert "Rewrite outline buffering"" This reverts commit 726bfaf0 commit 435b4c1c16153e30740d6878cf1f676b7a442c19 Author: techno-sam <linux.techno.sam@gmail.com> Date: Mon May 8 20:20:23 2023 -0700 Clean up last bits of upside down rendering commit 662da6bab1f6ad96a4fa05c9ff8538080ac69ac2 Merge: 122fe77af d83285e8a Author: techno-sam <linux.techno.sam@gmail.com> Date: Mon May 8 20:16:32 2023 -0700 Merge remote-tracking branch 'origin/1.18/api' into 1.18/api # Conflicts: # src/main/java/com/simibubi/create/content/logistics/trains/StandardBogeyRenderer.java commit 122fe77afa2df18dde7afe0bc6aee536f33b18bd Author: techno-sam <linux.techno.sam@gmail.com> Date: Mon May 8 20:15:46 2023 -0700 Fix up upside down rendering commit d83285e8a4da5fcb6900c032e6bd8cd59f81bde8 Merge: 00e953a58 cdb0ad210 Author: techno-sam <77073745+techno-sam@users.noreply.github.com> Date: Sun May 7 07:02:18 2023 -0700 Merge pull request #3 from Layers-of-Railways/1.18/bogey-api Cleanup cycle groups and unused imports commit cdb0ad210b7c984b9fcfbecae8a2a0ebf052eb9d Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Sun May 7 10:15:47 2023 +0100 Fixed merge artifact commit 457d5f33ed05075dbd0ffc38c17d3135b494dc26 Merge: 4e4e227a3 00e953a58 Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Sun May 7 10:14:07 2023 +0100 Merge remote-tracking branch 'origin/1.18/api' into 1.18/api commit 00e953a585bd8e146b6304a19cebd174404ab1c3 Merge: 1e4d5504e a7a25896c Author: Rabbitminers <79579164+Rabbitminers@users.noreply.github.com> Date: Sun May 7 10:13:49 2023 +0100 Merge pull request #2 from Rabbitminers/mc1.18/dev Added Return Values and Small Cleanup commit a7a25896c1a5a0a353400ed329a46a461347553e Merge: 7622128be 1e4d5504e Author: Rabbitminers <79579164+Rabbitminers@users.noreply.github.com> Date: Sun May 7 10:13:40 2023 +0100 Merge branch '1.18/api' into mc1.18/dev commit 4e4e227a351cb7f70aa4476bebfad1c0e963b561 Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Sun May 7 10:10:30 2023 +0100 Cleanup to cycle groups commit aa94fc97d154dcdcaaaa5b4d5e8311af9470d38a Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Sun May 7 09:50:50 2023 +0100 Removed unused import of Railways commit 7622128bec17931ea4029792d62c645d0f354e5f Merge: 81eeadb85 d52065808 Author: Rabbitminers <79579164+Rabbitminers@users.noreply.github.com> Date: Sun May 7 09:11:59 2023 +0100 Merge branch 'Layers-of-Railways:mc1.18/dev' into mc1.18/dev commit 1e4d5504ee4fe32d655e08acbeb6c492b5e8bb0b Author: techno-sam <linux.techno.sam@gmail.com> Date: Sat May 6 18:03:39 2023 -0700 Don't revert non-buggy changes commit b306cf212471f2842311af071dc6b595cbf79216 Author: techno-sam <linux.techno.sam@gmail.com> Date: Sat May 6 18:00:59 2023 -0700 Take materials into consideration when trains pathfind commit fca02ae4bfade6f839533c11785cc3e56332f463 Author: techno-sam <linux.techno.sam@gmail.com> Date: Sat May 6 10:25:51 2023 -0700 Add materials to track graph commit 726bfaf0b5226a657b45ce4bd1aa365d891a27a4 Author: techno-sam <linux.techno.sam@gmail.com> Date: Fri May 5 21:16:49 2023 -0700 Revert "Rewrite outline buffering" This reverts commit d4106d545b0381c3bec304e727a136ea105a8468. commit 171897bed25ed8f7ad3999c8527bb649bb932c81 Author: techno-sam <linux.techno.sam@gmail.com> Date: Fri May 5 20:55:25 2023 -0700 Fix up style cycling commit cbd0cf20da482851f98f5312cbc40770a6c14f16 Author: techno-sam <linux.techno.sam@gmail.com> Date: Fri May 5 07:32:06 2023 -0700 clean up nether portal carriage handling commit d556f0887632664126a2e10cbb1c8fc6d37e2582 Author: techno-sam <linux.techno.sam@gmail.com> Date: Fri May 5 07:06:02 2023 -0700 upside down bogeys work in nether portals fixed coupling anchor offsets commit da26c0ccbf26b892013f6e365556eea6952009f2 Author: techno-sam <linux.techno.sam@gmail.com> Date: Thu May 4 09:32:53 2023 -0700 working on upside down bogeys in nether portals commit 81eeadb8532599d482f2259e58cedeaa602e8628 Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Mon May 1 16:15:28 2023 +0100 Small cleanup commit c7e9df973cf3d0dab15992d06e6a51985d305ba8 Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Mon May 1 16:13:51 2023 +0100 Fixed issue raised in #1 commit 2f285b6eb7341879899895b1c5bbadd0137abb83 Author: techno-sam <linux.techno.sam@gmail.com> Date: Mon May 1 08:13:27 2023 -0700 add data gen commit 206de013111a879de133f62846e4f10d7228ea0a Merge: e91753a33 6564f4fa7 Author: techno-sam <77073745+techno-sam@users.noreply.github.com> Date: Mon May 1 06:49:21 2023 -0700 Merge pull request #1 from Rabbitminers/mc1.18/dev Bogey API commit 6564f4fa730f71920552fd2ad6f2c8255df69995 Merge: e5d759582 e91753a33 Author: Rabbitminers <79579164+Rabbitminers@users.noreply.github.com> Date: Mon May 1 10:40:32 2023 +0100 Merge branch '1.18/api' into mc1.18/dev commit e5d759582279b3a761c7011174ec77119f4f4f93 Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Mon May 1 10:09:03 2023 +0100 Connected Custom Bogey Particle Types To CarriageParticles commit e91753a33cde6dbe0caaface45a7f377d75acbed Author: techno-sam <linux.techno.sam@gmail.com> Date: Sun Apr 30 19:51:26 2023 -0700 Fix up some problems commit 9815f1490f9d540986f85f49f297e2f014c312c4 Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Sun Apr 30 21:12:43 2023 +0100 Implemented default data when shifting styles commit da30e78815afd7906ea82a9fba293f202c036fa8 Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Sun Apr 30 21:12:14 2023 +0100 Added Particles To Bogey Style (And Respective Builder) commit 08c000b8ba302a1c14f7479e70445e2c6d360bc3 Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Sun Apr 30 21:01:19 2023 +0100 Added Backup Rendering If A Size Is Not Present commit 2b76e8d7b3b8d88355868ea31d4b6e3df11a7169 Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Sun Apr 30 21:00:40 2023 +0100 Added Common Renderer To Remove Function commit 411ec36f573a570284b2bda566d8a006550983e8 Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Sun Apr 30 20:59:50 2023 +0100 Added Display Name To Standard Bogey Style commit 112306d5d49db10176d091f1f2ece893afb274dd Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Sun Apr 30 20:59:30 2023 +0100 Displayed new style name when changing betweeen them commit 5634670b2750a2df5dfee6de3f93bc895391300d Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Sun Apr 30 20:06:00 2023 +0100 General Cleanup commit 0f7a8b7b24ef25c4266fc88f82995b609087904e Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Sun Apr 30 20:05:50 2023 +0100 Implemented Changes To Remaining Classes commit 8aedc00f963413ac0a02335bc9f914d45a82b4de Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Sun Apr 30 20:02:06 2023 +0100 Removed Bogey Style Handling From Registrate commit edf8079abf9750dc9f3ccf1aedf58fef80428385 Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Sun Apr 30 20:01:40 2023 +0100 Removed Unused Registry Handling commit 6a185c4e727ecf55183cb885b109c0f5c5319854 Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Sun Apr 30 20:01:16 2023 +0100 Refactored Bogey Sizes commit e10d07ddc3b70cfa6f4a210aa9a9e6bcc6200b7f Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Sun Apr 30 20:01:00 2023 +0100 Overhauled Bogey Style commit 74d98a2ad538e2b9d35fdfd2270a14597d29f957 Merge: e629d02f5 4ebcf8201 Author: techno-sam <77073745+techno-sam@users.noreply.github.com> Date: Sun Apr 23 07:16:33 2023 -0700 Merge branch 'Creators-of-Create:mc1.18/dev' into 1.18/api commit e629d02f505c7de2d786a126fe49168351f17124 Author: techno-sam <linux.techno.sam@gmail.com> Date: Sun Apr 9 07:18:22 2023 -0700 Track API Clean up code a bit commit d9ce6ce995128e64d079145b96273235c4fec783 Author: techno-sam <linux.techno.sam@gmail.com> Date: Sun Apr 9 07:14:46 2023 -0700 Track API? Fix placement commit 7fbf08ba54ce3397045a8acdd6b7be813009ee7b Author: techno-sam <linux.techno.sam@gmail.com> Date: Sat Apr 8 11:11:24 2023 -0700 Track API? Fix up some placement issues commit 35644f143426bc2cae1a63c4f09d7145a4e18983 Author: techno-sam <linux.techno.sam@gmail.com> Date: Sat Apr 8 08:11:13 2023 -0700 Track API maybe? Datagen Seems to be working commit f7c56b867a6afe52fa742f4d4c310db9788cc2ef Author: techno-sam <linux.techno.sam@gmail.com> Date: Thu Apr 6 21:24:31 2023 -0700 Track API maybe? Fix build - broken generic Not yet tested, but it is progress commit 2a59fd7e8ab91a6004abe4b92152a2a936a22c1b Author: techno-sam <linux.techno.sam@gmail.com> Date: Thu Apr 6 21:13:54 2023 -0700 Track API maybe? Not yet tested, but it is progress commit 5ba30d6a85dd2cfa49434cb55a25b258b02a9665 Merge: e4e5ac1c4 c2977bbff Author: techno-sam <77073745+techno-sam@users.noreply.github.com> Date: Thu Apr 6 17:10:39 2023 -0700 Merge branch 'Creators-of-Create:mc1.18/dev' into 1.18/api commit d52065808c5d250e6aec35878a5349be563c1d24 Merge: e4e5ac1c4 c2977bbff Author: techno-sam <77073745+techno-sam@users.noreply.github.com> Date: Thu Apr 6 17:10:26 2023 -0700 Merge branch 'Creators-of-Create:mc1.18/dev' into mc1.18/dev commit 53240bd42f08d839b233a3b75cb59aabb4648fb9 Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Mon Apr 3 21:42:29 2023 +0100 Corrected Bogey InteractionResult To Pass commit 69326e361ab7d982a577f1e864c772967ad9c134 Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Mon Apr 3 21:30:28 2023 +0100 Fixed Default Values When Used Styles Are Removed commit 4f176979de161c35d6c7b07744bf0b982490f49f Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Mon Apr 3 19:33:17 2023 +0100 Fixed Carriage Sounds (Again) commit 1e80af3303e5bf9f9179857944cc233b4be7ebaf Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Mon Apr 3 19:27:58 2023 +0100 Refactored Bogey Sizes To Seperate Class commit 129be61fee13e15e17c2e2a4ee0b08c9bc004846 Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Mon Apr 3 17:20:17 2023 +0100 Fixed Bogey Sound Loading commit 2543185a55a60197494850582ca45d729e463f40 Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Mon Apr 3 09:45:23 2023 +0100 Added Bogey Sound Customisation commit 1ad5ae95143f5240fcb83448a99a3924e6d96ce8 Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Mon Apr 3 00:44:53 2023 +0100 Added Size Transforms If Size Is Not Available For New Style commit 96566b161441928f2b419340796a27631e1aeb91 Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Sun Apr 2 23:02:02 2023 +0100 Moved Bogey Style Inside Of Bogey Data And Implemented Bogey Data Communication commit eedd98473807f1261c7d5edaf0a222c081b57e69 Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Sun Apr 2 16:53:55 2023 +0100 Fixed Large Bogey Size commit 68ca0974c6867e61980990a345634963079faf10 Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Sun Apr 2 16:47:58 2023 +0100 Implemented Style Cycling & Default Values commit a55ba4267a5fd01ec77e9d826a01f0157c3a1271 Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Sun Apr 2 16:46:15 2023 +0100 Implemented renderer instance creator commit 43523302c22d5da374d71c69499269eb8c98dadf Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Sun Apr 2 16:45:33 2023 +0100 Removed Unused Standard Bogey Instance commit 773e084422d5cba7e0c599c4e9e9199252e843a3 Merge: 0c0b5a1ed d1e1f7ec5 Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Sat Apr 1 18:50:15 2023 +0100 Merge remote-tracking branch 'origin/mc1.18/dev' into mc1.18/dev # Conflicts: # src/main/java/com/simibubi/create/AllBogeyStyles.java # src/main/java/com/simibubi/create/content/logistics/trains/BogeyTileEntityRenderer.java # src/main/java/com/simibubi/create/content/logistics/trains/entity/BogeyStyle.java # src/main/java/com/simibubi/create/content/logistics/trains/entity/CarriageContraptionEntityRenderer.java # src/main/java/com/simibubi/create/content/logistics/trains/entity/StandardBogeyInstance.java # src/main/java/com/simibubi/create/foundation/data/BogeyStyleBuilder.java commit 0c0b5a1ed65c5f425265b340772b1177a309c46d Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Sat Apr 1 18:39:58 2023 +0100 Linked Style Registry To Bogey Blocks commit 71f839ee51c4d609a19fe57632fb2e8fb0d2e5b7 Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Sat Apr 1 18:39:03 2023 +0100 Replaced size boolean with direct use of size enum commit 50ff0817045029c721a0a5e38956b3ecd228e52f Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Thu Mar 30 18:47:13 2023 +0100 Added Resource Location To NBT helper methods commit d1e1f7ec5abeb825a3170a8f6972ffae43d58381 Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Thu Mar 30 18:47:13 2023 +0100 Re-worked BogeyStyles commit da593fccb1cb95232290289775affd097153e30d Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Thu Mar 30 18:46:02 2023 +0100 Refactored IBogeyBlock to AbstractBogeyBlock and extracted relevant StandardBogeyBlock implementations commit 17432c911342b1d4937a8d2d22d50a58296639e6 Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Sat Mar 25 10:20:50 2023 +0000 Fixed Incorrect Registry Loading commit c7d899369a4ad1a9962ed18c2ab02f58c985f5ae Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Fri Mar 24 23:44:03 2023 +0000 Registered Registers commit 6d862290d71b24b1d841444fa21dcb44ecc0d6c7 Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Fri Mar 24 23:43:23 2023 +0000 Added BogeyStyleBuilder To Registrate commit 3dfb9e3b3b4b7cec3833b65838ce9523b0cf7666 Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Fri Mar 24 23:43:08 2023 +0000 Implemented AllBogeyStyles commit c9e71b462d00e138778f3064bfcc3549a6f28f22 Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Fri Mar 24 23:42:56 2023 +0000 Created BogeyStyleBuilder commit a90977d6429657ade13c889d90ec8cd733f176e9 Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Fri Mar 24 23:42:25 2023 +0000 Created AllRegistries and BogeyStyle Registry commit 154d455f3fbdef3000ad3e35e88b0909b66c69f8 Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Fri Mar 24 23:41:56 2023 +0000 Added BogeyStyle Wrapper commit dfb7640bfc9850604c4ce05ff56338a4e2bbe2fa Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Thu Mar 23 18:50:41 2023 +0000 Removed left over logging statement commit 9920536cc319897a89dc1fc974c67cd0975fbcfd Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Thu Mar 23 18:50:18 2023 +0000 Implemented Secondary Shaft To Large Renderer commit 6cd40cc6f982226f2bbb9e04e3b8241f9cc36cb5 Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Thu Mar 23 18:49:56 2023 +0000 Prevented Overwrite When Using Two BlockStates Of The Same Type With Different Properties commit 06fb901144de8d8df5b907e6261c76a018468f7d Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Thu Mar 23 18:39:11 2023 +0000 Implemented Common Rendering For StandardBogeyRenderer commit 435b0f826663284f6544c034217516e36a0687d8 Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Thu Mar 23 18:38:40 2023 +0000 Added Common Renderer commit 96a0623dab84d7062a0871ddacabf4342e568867 Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Thu Mar 23 18:38:29 2023 +0000 Implemented BlockState Models For Rendering commit 469d9d592b9aa925b26b1206a4ad03d73d422a92 Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Thu Mar 23 17:42:28 2023 +0000 Added Standard Bogey Instance (Might be redundant) commit 2661d260d8c21e57df751b17812d89919713120f Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Thu Mar 23 17:42:06 2023 +0000 Refactored Changes To Existing Methods commit 9ded16fbabb38e3415cc7b5452cbaea1bef98f61 Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Thu Mar 23 17:41:15 2023 +0000 Integrated BogeyRenderer To BogeyInstance (Also Corrected Rendering In Contraption) commit 4a82fcbca1002267fc70998e7ac9c22cd92de52e Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Thu Mar 23 17:40:13 2023 +0000 Implemented Changes To StandardBogeyBlock commit 7238fb93f3d0fed43b091f44fd30814e505c544c Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Thu Mar 23 17:39:51 2023 +0000 Added Renderer To IBogeyBlock commit ded4c1f613cb33ae29b6bf631eb49abd2ec037f4 Merge: 91727cc84 3c02fe6ec Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Wed Mar 22 17:03:37 2023 +0000 Merge remote-tracking branch 'origin/mc1.18/dev' into mc1.18/dev commit 91727cc84a12b2fd27b1ce6e0d67bd182e34880b Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Wed Mar 22 17:03:28 2023 +0000 Implemented Model Data Initializer to StandardBogeyRenderer commit 6d98a1f46942d319729c2d61451da462f4188167 Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Wed Mar 22 17:03:00 2023 +0000 Added Contraption Model Instance Initializer commit 3c02fe6ecc0c20f1c8ba6bd2ffd2334c2d9d9d73 Author: Rabbitminers <79579164+Rabbitminers@users.noreply.github.com> Date: Tue Mar 21 22:45:34 2023 +0000 Added missing render type check commit 6672c49649026e6a6f9a71d9a0bc9411016bcfce Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Tue Mar 21 22:37:36 2023 +0000 Re-created standard bogey with test api commit a8a9491fa07777218c7de3fe780ae17e05d5ac03 Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Tue Mar 21 22:34:54 2023 +0000 Implemented Proof Of Concept Generic Bogey Renderer commit e4e5ac1c40cadb708429018dc17439eca87ee74e Author: SpottyTheTurtle <69260662+SpottyTheTurtle@users.noreply.github.com> Date: Sat Mar 11 21:34:59 2023 +0000 init
2023-05-09 18:23:47 +02:00
import com.simibubi.create.content.logistics.trains.AbstractBogeyBlock;
import com.simibubi.create.foundation.blockEntity.IMultiBlockEntityContainer;
import com.simibubi.create.foundation.blockEntity.behaviour.filtering.FilteringBehaviour;
2020-05-23 14:02:38 +02:00
import com.simibubi.create.foundation.config.AllConfigs;
import com.simibubi.create.foundation.utility.BBHelper;
import com.simibubi.create.foundation.utility.BlockFace;
import com.simibubi.create.foundation.utility.BlockHelper;
import com.simibubi.create.foundation.utility.ICoordinate;
import com.simibubi.create.foundation.utility.Iterate;
import com.simibubi.create.foundation.utility.NBTHelper;
import com.simibubi.create.foundation.utility.NBTProcessors;
import com.simibubi.create.foundation.utility.UniqueLinkedList;
2021-11-02 06:18:30 +01:00
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.Direction.Axis;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.NbtUtils;
2021-11-02 06:18:30 +01:00
import net.minecraft.nbt.Tag;
import net.minecraft.network.protocol.game.DebugPackets;
2021-11-02 06:18:30 +01:00
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.ai.village.poi.PoiType;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
2021-11-02 06:18:30 +01:00
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.ButtonBlock;
import net.minecraft.world.level.block.ChestBlock;
import net.minecraft.world.level.block.DoorBlock;
2021-11-02 06:18:30 +01:00
import net.minecraft.world.level.block.PressurePlateBlock;
import net.minecraft.world.level.block.Rotation;
import net.minecraft.world.level.block.SimpleWaterloggedBlock;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.block.state.properties.ChestType;
import net.minecraft.world.level.block.state.properties.PistonType;
import net.minecraft.world.level.chunk.HashMapPalette;
import net.minecraft.world.level.levelgen.structure.BoundingBox;
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate.StructureBlockInfo;
2021-11-02 06:18:30 +01:00
import net.minecraft.world.level.material.FluidState;
import net.minecraft.world.level.material.Fluids;
import net.minecraft.world.level.material.PushReaction;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3;
2021-11-02 16:25:48 +01:00
import net.minecraft.world.phys.shapes.BooleanOp;
import net.minecraft.world.phys.shapes.CollisionContext;
2021-11-02 16:25:48 +01:00
import net.minecraft.world.phys.shapes.Shapes;
2021-11-02 06:18:30 +01:00
import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.client.model.data.IModelData;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.capability.IFluidHandler;
import net.minecraftforge.items.IItemHandlerModifiable;
import net.minecraftforge.items.wrapper.CombinedInvWrapper;
import net.minecraftforge.registries.GameData;
public abstract class Contraption {
public Optional<List<AABB>> simplifiedEntityColliders;
public AbstractContraptionEntity entity;
public AABB bounds;
public BlockPos anchor;
public boolean stalled;
public boolean hasUniversalCreativeCrate;
2022-10-03 00:31:42 +02:00
public boolean disassembled;
protected Map<BlockPos, StructureBlockInfo> blocks;
protected List<MutablePair<StructureBlockInfo, MovementContext>> actors;
protected Map<BlockPos, MovingInteractionBehaviour> interactors;
protected List<ItemStack> disabledActors;
protected List<AABB> superglue;
protected List<BlockPos> seats;
protected Map<UUID, Integer> seatMapping;
protected Map<UUID, BlockFace> stabilizedSubContraptions;
protected MountedStorageManager storage;
private Set<SuperGlueEntity> glueToRemove;
private Map<BlockPos, Entity> initialPassengers;
private List<BlockFace> pendingSubContraptions;
private CompletableFuture<Void> simplifiedEntityColliderProvider;
// Client
public Map<BlockPos, IModelData> modelData;
public Map<BlockPos, BlockEntity> presentBlockEntities;
public List<BlockEntity> maybeInstancedBlockEntities;
public List<BlockEntity> specialRenderedBlockEntities;
2021-03-20 21:16:20 +01:00
protected ContraptionWorld world;
public boolean deferInvalidate;
2021-03-20 21:16:20 +01:00
public Contraption() {
blocks = new HashMap<>();
seats = new ArrayList<>();
actors = new ArrayList<>();
disabledActors = new ArrayList<>();
modelData = new HashMap<>();
interactors = new HashMap<>();
superglue = new ArrayList<>();
seatMapping = new HashMap<>();
glueToRemove = new HashSet<>();
initialPassengers = new HashMap<>();
presentBlockEntities = new HashMap<>();
maybeInstancedBlockEntities = new ArrayList<>();
specialRenderedBlockEntities = new ArrayList<>();
pendingSubContraptions = new ArrayList<>();
stabilizedSubContraptions = new HashMap<>();
simplifiedEntityColliders = Optional.empty();
storage = new MountedStorageManager();
}
2021-03-20 21:16:20 +01:00
public ContraptionWorld getContraptionWorld() {
if (world == null)
2021-07-15 11:32:03 +02:00
world = new ContraptionWorld(entity.level, this);
2021-03-20 21:16:20 +01:00
return world;
}
public abstract boolean assemble(Level world, BlockPos pos) throws AssemblyException;
public abstract boolean canBeStabilized(Direction facing, BlockPos localPos);
protected abstract ContraptionType getType();
protected boolean customBlockPlacement(LevelAccessor world, BlockPos pos, BlockState state) {
return false;
}
protected boolean customBlockRemoval(LevelAccessor world, BlockPos pos, BlockState state) {
return false;
}
protected boolean addToInitialFrontier(Level world, BlockPos pos, Direction forcedDirection,
2021-02-11 17:47:55 +01:00
Queue<BlockPos> frontier) throws AssemblyException {
return true;
}
public static Contraption fromNBT(Level world, CompoundTag nbt, boolean spawnData) {
String type = nbt.getString("Type");
Contraption contraption = ContraptionType.fromType(type);
contraption.readNBT(world, nbt, spawnData);
contraption.world = new ContraptionWorld(world, contraption);
contraption.gatherBBsOffThread();
return contraption;
}
public boolean searchMovedStructure(Level world, BlockPos pos, @Nullable Direction forcedDirection)
throws AssemblyException {
initialPassengers.clear();
Queue<BlockPos> frontier = new UniqueLinkedList<>();
Set<BlockPos> visited = new HashSet<>();
anchor = pos;
if (bounds == null)
bounds = new AABB(BlockPos.ZERO);
if (!BlockMovementChecks.isBrittle(world.getBlockState(pos)))
frontier.add(pos);
if (!addToInitialFrontier(world, pos, forcedDirection, frontier))
return false;
for (int limit = 100000; limit > 0; limit--) {
if (frontier.isEmpty())
return true;
2021-01-30 14:09:04 +01:00
if (!moveBlock(world, forcedDirection, frontier, visited))
return false;
}
2021-02-11 17:47:55 +01:00
throw AssemblyException.structureTooLarge();
}
public void onEntityCreated(AbstractContraptionEntity entity) {
this.entity = entity;
// Create subcontraptions
for (BlockFace blockFace : pendingSubContraptions) {
Direction face = blockFace.getFace();
StabilizedContraption subContraption = new StabilizedContraption(face);
Level world = entity.level;
BlockPos pos = blockFace.getPos();
2021-01-30 19:12:31 +01:00
try {
if (!subContraption.assemble(world, pos))
continue;
} catch (AssemblyException e) {
continue;
2021-01-30 19:12:31 +01:00
}
subContraption.removeBlocksFromWorld(world, BlockPos.ZERO);
OrientedContraptionEntity movedContraption = OrientedContraptionEntity.create(world, subContraption, face);
BlockPos anchor = blockFace.getConnectedPos();
2021-07-15 11:32:03 +02:00
movedContraption.setPos(anchor.getX() + .5f, anchor.getY(), anchor.getZ() + .5f);
world.addFreshEntity(movedContraption);
stabilizedSubContraptions.put(movedContraption.getUUID(), new BlockFace(toLocalPos(pos), face));
}
storage.createHandlers();
gatherBBsOffThread();
}
public void onEntityRemoved(AbstractContraptionEntity entity) {
if (simplifiedEntityColliderProvider != null) {
simplifiedEntityColliderProvider.cancel(false);
simplifiedEntityColliderProvider = null;
}
}
public void onEntityInitialize(Level world, AbstractContraptionEntity contraptionEntity) {
2021-07-15 11:32:03 +02:00
if (world.isClientSide)
return;
2021-07-15 11:32:03 +02:00
for (OrientedContraptionEntity orientedCE : world.getEntitiesOfClass(OrientedContraptionEntity.class,
contraptionEntity.getBoundingBox()
2021-07-15 11:32:03 +02:00
.inflate(1)))
if (stabilizedSubContraptions.containsKey(orientedCE.getUUID()))
orientedCE.startRiding(contraptionEntity);
for (BlockPos seatPos : getSeats()) {
Entity passenger = initialPassengers.get(seatPos);
if (passenger == null)
continue;
int seatIndex = getSeats().indexOf(seatPos);
if (seatIndex == -1)
continue;
contraptionEntity.addSittingPassenger(passenger, seatIndex);
}
}
2021-01-30 19:12:31 +01:00
/** move the first block in frontier queue */
protected boolean moveBlock(Level world, @Nullable Direction forcedDirection, Queue<BlockPos> frontier,
2021-02-11 17:47:55 +01:00
Set<BlockPos> visited) throws AssemblyException {
2021-01-30 14:09:04 +01:00
BlockPos pos = frontier.poll();
if (pos == null)
return false;
visited.add(pos);
2021-11-02 06:18:30 +01:00
if (world.isOutsideBuildHeight(pos))
2021-01-30 19:12:31 +01:00
return true;
2021-07-15 11:32:03 +02:00
if (!world.isLoaded(pos))
2021-02-11 17:47:55 +01:00
throw AssemblyException.unloadedChunk(pos);
if (isAnchoringBlockAt(pos))
return true;
BlockState state = world.getBlockState(pos);
if (!BlockMovementChecks.isMovementNecessary(state, world, pos))
return true;
2021-01-30 14:09:04 +01:00
if (!movementAllowed(state, world, pos))
2021-01-30 19:12:31 +01:00
throw AssemblyException.unmovableBlock(pos, state);
if (state.getBlock() instanceof AbstractChassisBlock
&& !moveChassis(world, pos, forcedDirection, frontier, visited))
return false;
if (AllBlocks.BELT.has(state))
moveBelt(pos, frontier, visited, state);
if (AllBlocks.WINDMILL_BEARING.has(state) && world.getBlockEntity(pos)instanceof WindmillBearingBlockEntity wbte)
wbte.disassembleForMovement();
if (AllBlocks.GANTRY_CARRIAGE.has(state))
moveGantryPinion(world, pos, frontier, visited, state);
if (AllBlocks.GANTRY_SHAFT.has(state))
moveGantryShaft(world, pos, frontier, visited, state);
2021-07-15 11:32:03 +02:00
if (AllBlocks.STICKER.has(state) && state.getValue(StickerBlock.EXTENDED)) {
Direction offset = state.getValue(StickerBlock.FACING);
BlockPos attached = pos.relative(offset);
if (!visited.contains(attached)
&& !BlockMovementChecks.isNotSupportive(world.getBlockState(attached), offset.getOpposite()))
frontier.add(attached);
}
// Double Chest halves stick together
if (state.hasProperty(ChestBlock.TYPE) && state.hasProperty(ChestBlock.FACING)
&& state.getValue(ChestBlock.TYPE) != ChestType.SINGLE) {
Direction offset = ChestBlock.getConnectedDirection(state);
BlockPos attached = pos.relative(offset);
if (!visited.contains(attached))
frontier.add(attached);
}
2022-02-01 01:14:21 +01:00
// Bogeys tend to have sticky sides
Squashed commit of the following: commit 053dd09df6c426ab5e570f42a1edb5df3d0fbd01 Merge: 6d1e1c71d ecc645eba Author: simibubi <31564874+simibubi@users.noreply.github.com> Date: Tue May 9 18:22:42 2023 +0200 Merge branch '1.18/api' of https://github.com/Layers-of-Railways/Create into pr/4692 commit ecc645eba7bfd5f86b9bfb16ee1236a5d6432d3d Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Tue May 9 11:24:11 2023 +0100 Implemented support for creating and removing individual blockstate models commit 6d1e1c71de7ce20f6fd9fc8ed4ed9bdd1072829a Author: simibubi <31564874+simibubi@users.noreply.github.com> Date: Tue May 9 12:16:54 2023 +0200 Less error logging when migrating old worlds commit 205e47352ec46f8e300167db69023c7938a52b58 Author: techno-sam <linux.techno.sam@gmail.com> Date: Mon May 8 21:02:19 2023 -0700 Fix up ItemOutline commit 6cf204f6afd12671060d198d5a09efe9cd04c7b5 Merge: fe049bc77 2e3c906ce Author: techno-sam <linux.techno.sam@gmail.com> Date: Mon May 8 20:28:56 2023 -0700 Merge remote-tracking branch 'upstream/mc1.18/dev' into 1.18/api # Conflicts: # src/main/java/com/simibubi/create/content/logistics/trains/entity/CarriageCouplingRenderer.java commit fe049bc771cc3a4dd91f5c91f098aa7448af6c8d Author: techno-sam <linux.techno.sam@gmail.com> Date: Mon May 8 20:26:16 2023 -0700 Revert "Revert "Rewrite outline buffering"" This reverts commit 726bfaf0 commit 435b4c1c16153e30740d6878cf1f676b7a442c19 Author: techno-sam <linux.techno.sam@gmail.com> Date: Mon May 8 20:20:23 2023 -0700 Clean up last bits of upside down rendering commit 662da6bab1f6ad96a4fa05c9ff8538080ac69ac2 Merge: 122fe77af d83285e8a Author: techno-sam <linux.techno.sam@gmail.com> Date: Mon May 8 20:16:32 2023 -0700 Merge remote-tracking branch 'origin/1.18/api' into 1.18/api # Conflicts: # src/main/java/com/simibubi/create/content/logistics/trains/StandardBogeyRenderer.java commit 122fe77afa2df18dde7afe0bc6aee536f33b18bd Author: techno-sam <linux.techno.sam@gmail.com> Date: Mon May 8 20:15:46 2023 -0700 Fix up upside down rendering commit d83285e8a4da5fcb6900c032e6bd8cd59f81bde8 Merge: 00e953a58 cdb0ad210 Author: techno-sam <77073745+techno-sam@users.noreply.github.com> Date: Sun May 7 07:02:18 2023 -0700 Merge pull request #3 from Layers-of-Railways/1.18/bogey-api Cleanup cycle groups and unused imports commit cdb0ad210b7c984b9fcfbecae8a2a0ebf052eb9d Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Sun May 7 10:15:47 2023 +0100 Fixed merge artifact commit 457d5f33ed05075dbd0ffc38c17d3135b494dc26 Merge: 4e4e227a3 00e953a58 Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Sun May 7 10:14:07 2023 +0100 Merge remote-tracking branch 'origin/1.18/api' into 1.18/api commit 00e953a585bd8e146b6304a19cebd174404ab1c3 Merge: 1e4d5504e a7a25896c Author: Rabbitminers <79579164+Rabbitminers@users.noreply.github.com> Date: Sun May 7 10:13:49 2023 +0100 Merge pull request #2 from Rabbitminers/mc1.18/dev Added Return Values and Small Cleanup commit a7a25896c1a5a0a353400ed329a46a461347553e Merge: 7622128be 1e4d5504e Author: Rabbitminers <79579164+Rabbitminers@users.noreply.github.com> Date: Sun May 7 10:13:40 2023 +0100 Merge branch '1.18/api' into mc1.18/dev commit 4e4e227a351cb7f70aa4476bebfad1c0e963b561 Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Sun May 7 10:10:30 2023 +0100 Cleanup to cycle groups commit aa94fc97d154dcdcaaaa5b4d5e8311af9470d38a Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Sun May 7 09:50:50 2023 +0100 Removed unused import of Railways commit 7622128bec17931ea4029792d62c645d0f354e5f Merge: 81eeadb85 d52065808 Author: Rabbitminers <79579164+Rabbitminers@users.noreply.github.com> Date: Sun May 7 09:11:59 2023 +0100 Merge branch 'Layers-of-Railways:mc1.18/dev' into mc1.18/dev commit 1e4d5504ee4fe32d655e08acbeb6c492b5e8bb0b Author: techno-sam <linux.techno.sam@gmail.com> Date: Sat May 6 18:03:39 2023 -0700 Don't revert non-buggy changes commit b306cf212471f2842311af071dc6b595cbf79216 Author: techno-sam <linux.techno.sam@gmail.com> Date: Sat May 6 18:00:59 2023 -0700 Take materials into consideration when trains pathfind commit fca02ae4bfade6f839533c11785cc3e56332f463 Author: techno-sam <linux.techno.sam@gmail.com> Date: Sat May 6 10:25:51 2023 -0700 Add materials to track graph commit 726bfaf0b5226a657b45ce4bd1aa365d891a27a4 Author: techno-sam <linux.techno.sam@gmail.com> Date: Fri May 5 21:16:49 2023 -0700 Revert "Rewrite outline buffering" This reverts commit d4106d545b0381c3bec304e727a136ea105a8468. commit 171897bed25ed8f7ad3999c8527bb649bb932c81 Author: techno-sam <linux.techno.sam@gmail.com> Date: Fri May 5 20:55:25 2023 -0700 Fix up style cycling commit cbd0cf20da482851f98f5312cbc40770a6c14f16 Author: techno-sam <linux.techno.sam@gmail.com> Date: Fri May 5 07:32:06 2023 -0700 clean up nether portal carriage handling commit d556f0887632664126a2e10cbb1c8fc6d37e2582 Author: techno-sam <linux.techno.sam@gmail.com> Date: Fri May 5 07:06:02 2023 -0700 upside down bogeys work in nether portals fixed coupling anchor offsets commit da26c0ccbf26b892013f6e365556eea6952009f2 Author: techno-sam <linux.techno.sam@gmail.com> Date: Thu May 4 09:32:53 2023 -0700 working on upside down bogeys in nether portals commit 81eeadb8532599d482f2259e58cedeaa602e8628 Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Mon May 1 16:15:28 2023 +0100 Small cleanup commit c7e9df973cf3d0dab15992d06e6a51985d305ba8 Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Mon May 1 16:13:51 2023 +0100 Fixed issue raised in #1 commit 2f285b6eb7341879899895b1c5bbadd0137abb83 Author: techno-sam <linux.techno.sam@gmail.com> Date: Mon May 1 08:13:27 2023 -0700 add data gen commit 206de013111a879de133f62846e4f10d7228ea0a Merge: e91753a33 6564f4fa7 Author: techno-sam <77073745+techno-sam@users.noreply.github.com> Date: Mon May 1 06:49:21 2023 -0700 Merge pull request #1 from Rabbitminers/mc1.18/dev Bogey API commit 6564f4fa730f71920552fd2ad6f2c8255df69995 Merge: e5d759582 e91753a33 Author: Rabbitminers <79579164+Rabbitminers@users.noreply.github.com> Date: Mon May 1 10:40:32 2023 +0100 Merge branch '1.18/api' into mc1.18/dev commit e5d759582279b3a761c7011174ec77119f4f4f93 Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Mon May 1 10:09:03 2023 +0100 Connected Custom Bogey Particle Types To CarriageParticles commit e91753a33cde6dbe0caaface45a7f377d75acbed Author: techno-sam <linux.techno.sam@gmail.com> Date: Sun Apr 30 19:51:26 2023 -0700 Fix up some problems commit 9815f1490f9d540986f85f49f297e2f014c312c4 Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Sun Apr 30 21:12:43 2023 +0100 Implemented default data when shifting styles commit da30e78815afd7906ea82a9fba293f202c036fa8 Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Sun Apr 30 21:12:14 2023 +0100 Added Particles To Bogey Style (And Respective Builder) commit 08c000b8ba302a1c14f7479e70445e2c6d360bc3 Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Sun Apr 30 21:01:19 2023 +0100 Added Backup Rendering If A Size Is Not Present commit 2b76e8d7b3b8d88355868ea31d4b6e3df11a7169 Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Sun Apr 30 21:00:40 2023 +0100 Added Common Renderer To Remove Function commit 411ec36f573a570284b2bda566d8a006550983e8 Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Sun Apr 30 20:59:50 2023 +0100 Added Display Name To Standard Bogey Style commit 112306d5d49db10176d091f1f2ece893afb274dd Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Sun Apr 30 20:59:30 2023 +0100 Displayed new style name when changing betweeen them commit 5634670b2750a2df5dfee6de3f93bc895391300d Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Sun Apr 30 20:06:00 2023 +0100 General Cleanup commit 0f7a8b7b24ef25c4266fc88f82995b609087904e Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Sun Apr 30 20:05:50 2023 +0100 Implemented Changes To Remaining Classes commit 8aedc00f963413ac0a02335bc9f914d45a82b4de Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Sun Apr 30 20:02:06 2023 +0100 Removed Bogey Style Handling From Registrate commit edf8079abf9750dc9f3ccf1aedf58fef80428385 Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Sun Apr 30 20:01:40 2023 +0100 Removed Unused Registry Handling commit 6a185c4e727ecf55183cb885b109c0f5c5319854 Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Sun Apr 30 20:01:16 2023 +0100 Refactored Bogey Sizes commit e10d07ddc3b70cfa6f4a210aa9a9e6bcc6200b7f Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Sun Apr 30 20:01:00 2023 +0100 Overhauled Bogey Style commit 74d98a2ad538e2b9d35fdfd2270a14597d29f957 Merge: e629d02f5 4ebcf8201 Author: techno-sam <77073745+techno-sam@users.noreply.github.com> Date: Sun Apr 23 07:16:33 2023 -0700 Merge branch 'Creators-of-Create:mc1.18/dev' into 1.18/api commit e629d02f505c7de2d786a126fe49168351f17124 Author: techno-sam <linux.techno.sam@gmail.com> Date: Sun Apr 9 07:18:22 2023 -0700 Track API Clean up code a bit commit d9ce6ce995128e64d079145b96273235c4fec783 Author: techno-sam <linux.techno.sam@gmail.com> Date: Sun Apr 9 07:14:46 2023 -0700 Track API? Fix placement commit 7fbf08ba54ce3397045a8acdd6b7be813009ee7b Author: techno-sam <linux.techno.sam@gmail.com> Date: Sat Apr 8 11:11:24 2023 -0700 Track API? Fix up some placement issues commit 35644f143426bc2cae1a63c4f09d7145a4e18983 Author: techno-sam <linux.techno.sam@gmail.com> Date: Sat Apr 8 08:11:13 2023 -0700 Track API maybe? Datagen Seems to be working commit f7c56b867a6afe52fa742f4d4c310db9788cc2ef Author: techno-sam <linux.techno.sam@gmail.com> Date: Thu Apr 6 21:24:31 2023 -0700 Track API maybe? Fix build - broken generic Not yet tested, but it is progress commit 2a59fd7e8ab91a6004abe4b92152a2a936a22c1b Author: techno-sam <linux.techno.sam@gmail.com> Date: Thu Apr 6 21:13:54 2023 -0700 Track API maybe? Not yet tested, but it is progress commit 5ba30d6a85dd2cfa49434cb55a25b258b02a9665 Merge: e4e5ac1c4 c2977bbff Author: techno-sam <77073745+techno-sam@users.noreply.github.com> Date: Thu Apr 6 17:10:39 2023 -0700 Merge branch 'Creators-of-Create:mc1.18/dev' into 1.18/api commit d52065808c5d250e6aec35878a5349be563c1d24 Merge: e4e5ac1c4 c2977bbff Author: techno-sam <77073745+techno-sam@users.noreply.github.com> Date: Thu Apr 6 17:10:26 2023 -0700 Merge branch 'Creators-of-Create:mc1.18/dev' into mc1.18/dev commit 53240bd42f08d839b233a3b75cb59aabb4648fb9 Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Mon Apr 3 21:42:29 2023 +0100 Corrected Bogey InteractionResult To Pass commit 69326e361ab7d982a577f1e864c772967ad9c134 Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Mon Apr 3 21:30:28 2023 +0100 Fixed Default Values When Used Styles Are Removed commit 4f176979de161c35d6c7b07744bf0b982490f49f Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Mon Apr 3 19:33:17 2023 +0100 Fixed Carriage Sounds (Again) commit 1e80af3303e5bf9f9179857944cc233b4be7ebaf Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Mon Apr 3 19:27:58 2023 +0100 Refactored Bogey Sizes To Seperate Class commit 129be61fee13e15e17c2e2a4ee0b08c9bc004846 Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Mon Apr 3 17:20:17 2023 +0100 Fixed Bogey Sound Loading commit 2543185a55a60197494850582ca45d729e463f40 Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Mon Apr 3 09:45:23 2023 +0100 Added Bogey Sound Customisation commit 1ad5ae95143f5240fcb83448a99a3924e6d96ce8 Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Mon Apr 3 00:44:53 2023 +0100 Added Size Transforms If Size Is Not Available For New Style commit 96566b161441928f2b419340796a27631e1aeb91 Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Sun Apr 2 23:02:02 2023 +0100 Moved Bogey Style Inside Of Bogey Data And Implemented Bogey Data Communication commit eedd98473807f1261c7d5edaf0a222c081b57e69 Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Sun Apr 2 16:53:55 2023 +0100 Fixed Large Bogey Size commit 68ca0974c6867e61980990a345634963079faf10 Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Sun Apr 2 16:47:58 2023 +0100 Implemented Style Cycling & Default Values commit a55ba4267a5fd01ec77e9d826a01f0157c3a1271 Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Sun Apr 2 16:46:15 2023 +0100 Implemented renderer instance creator commit 43523302c22d5da374d71c69499269eb8c98dadf Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Sun Apr 2 16:45:33 2023 +0100 Removed Unused Standard Bogey Instance commit 773e084422d5cba7e0c599c4e9e9199252e843a3 Merge: 0c0b5a1ed d1e1f7ec5 Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Sat Apr 1 18:50:15 2023 +0100 Merge remote-tracking branch 'origin/mc1.18/dev' into mc1.18/dev # Conflicts: # src/main/java/com/simibubi/create/AllBogeyStyles.java # src/main/java/com/simibubi/create/content/logistics/trains/BogeyTileEntityRenderer.java # src/main/java/com/simibubi/create/content/logistics/trains/entity/BogeyStyle.java # src/main/java/com/simibubi/create/content/logistics/trains/entity/CarriageContraptionEntityRenderer.java # src/main/java/com/simibubi/create/content/logistics/trains/entity/StandardBogeyInstance.java # src/main/java/com/simibubi/create/foundation/data/BogeyStyleBuilder.java commit 0c0b5a1ed65c5f425265b340772b1177a309c46d Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Sat Apr 1 18:39:58 2023 +0100 Linked Style Registry To Bogey Blocks commit 71f839ee51c4d609a19fe57632fb2e8fb0d2e5b7 Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Sat Apr 1 18:39:03 2023 +0100 Replaced size boolean with direct use of size enum commit 50ff0817045029c721a0a5e38956b3ecd228e52f Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Thu Mar 30 18:47:13 2023 +0100 Added Resource Location To NBT helper methods commit d1e1f7ec5abeb825a3170a8f6972ffae43d58381 Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Thu Mar 30 18:47:13 2023 +0100 Re-worked BogeyStyles commit da593fccb1cb95232290289775affd097153e30d Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Thu Mar 30 18:46:02 2023 +0100 Refactored IBogeyBlock to AbstractBogeyBlock and extracted relevant StandardBogeyBlock implementations commit 17432c911342b1d4937a8d2d22d50a58296639e6 Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Sat Mar 25 10:20:50 2023 +0000 Fixed Incorrect Registry Loading commit c7d899369a4ad1a9962ed18c2ab02f58c985f5ae Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Fri Mar 24 23:44:03 2023 +0000 Registered Registers commit 6d862290d71b24b1d841444fa21dcb44ecc0d6c7 Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Fri Mar 24 23:43:23 2023 +0000 Added BogeyStyleBuilder To Registrate commit 3dfb9e3b3b4b7cec3833b65838ce9523b0cf7666 Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Fri Mar 24 23:43:08 2023 +0000 Implemented AllBogeyStyles commit c9e71b462d00e138778f3064bfcc3549a6f28f22 Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Fri Mar 24 23:42:56 2023 +0000 Created BogeyStyleBuilder commit a90977d6429657ade13c889d90ec8cd733f176e9 Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Fri Mar 24 23:42:25 2023 +0000 Created AllRegistries and BogeyStyle Registry commit 154d455f3fbdef3000ad3e35e88b0909b66c69f8 Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Fri Mar 24 23:41:56 2023 +0000 Added BogeyStyle Wrapper commit dfb7640bfc9850604c4ce05ff56338a4e2bbe2fa Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Thu Mar 23 18:50:41 2023 +0000 Removed left over logging statement commit 9920536cc319897a89dc1fc974c67cd0975fbcfd Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Thu Mar 23 18:50:18 2023 +0000 Implemented Secondary Shaft To Large Renderer commit 6cd40cc6f982226f2bbb9e04e3b8241f9cc36cb5 Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Thu Mar 23 18:49:56 2023 +0000 Prevented Overwrite When Using Two BlockStates Of The Same Type With Different Properties commit 06fb901144de8d8df5b907e6261c76a018468f7d Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Thu Mar 23 18:39:11 2023 +0000 Implemented Common Rendering For StandardBogeyRenderer commit 435b0f826663284f6544c034217516e36a0687d8 Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Thu Mar 23 18:38:40 2023 +0000 Added Common Renderer commit 96a0623dab84d7062a0871ddacabf4342e568867 Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Thu Mar 23 18:38:29 2023 +0000 Implemented BlockState Models For Rendering commit 469d9d592b9aa925b26b1206a4ad03d73d422a92 Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Thu Mar 23 17:42:28 2023 +0000 Added Standard Bogey Instance (Might be redundant) commit 2661d260d8c21e57df751b17812d89919713120f Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Thu Mar 23 17:42:06 2023 +0000 Refactored Changes To Existing Methods commit 9ded16fbabb38e3415cc7b5452cbaea1bef98f61 Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Thu Mar 23 17:41:15 2023 +0000 Integrated BogeyRenderer To BogeyInstance (Also Corrected Rendering In Contraption) commit 4a82fcbca1002267fc70998e7ac9c22cd92de52e Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Thu Mar 23 17:40:13 2023 +0000 Implemented Changes To StandardBogeyBlock commit 7238fb93f3d0fed43b091f44fd30814e505c544c Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Thu Mar 23 17:39:51 2023 +0000 Added Renderer To IBogeyBlock commit ded4c1f613cb33ae29b6bf631eb49abd2ec037f4 Merge: 91727cc84 3c02fe6ec Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Wed Mar 22 17:03:37 2023 +0000 Merge remote-tracking branch 'origin/mc1.18/dev' into mc1.18/dev commit 91727cc84a12b2fd27b1ce6e0d67bd182e34880b Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Wed Mar 22 17:03:28 2023 +0000 Implemented Model Data Initializer to StandardBogeyRenderer commit 6d98a1f46942d319729c2d61451da462f4188167 Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Wed Mar 22 17:03:00 2023 +0000 Added Contraption Model Instance Initializer commit 3c02fe6ecc0c20f1c8ba6bd2ffd2334c2d9d9d73 Author: Rabbitminers <79579164+Rabbitminers@users.noreply.github.com> Date: Tue Mar 21 22:45:34 2023 +0000 Added missing render type check commit 6672c49649026e6a6f9a71d9a0bc9411016bcfce Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Tue Mar 21 22:37:36 2023 +0000 Re-created standard bogey with test api commit a8a9491fa07777218c7de3fe780ae17e05d5ac03 Author: Rabbitminers <Rabbitminers2.0@gmail.com> Date: Tue Mar 21 22:34:54 2023 +0000 Implemented Proof Of Concept Generic Bogey Renderer commit e4e5ac1c40cadb708429018dc17439eca87ee74e Author: SpottyTheTurtle <69260662+SpottyTheTurtle@users.noreply.github.com> Date: Sat Mar 11 21:34:59 2023 +0000 init
2023-05-09 18:23:47 +02:00
if (state.getBlock()instanceof AbstractBogeyBlock<?> bogey)
2022-02-01 01:14:21 +01:00
for (Direction d : bogey.getStickySurfaces(world, pos, state))
if (!visited.contains(pos.relative(d)))
frontier.add(pos.relative(d));
// Bearings potentially create stabilized sub-contraptions
if (AllBlocks.MECHANICAL_BEARING.has(state))
moveBearing(pos, frontier, visited, state);
// WM Bearings attach their structure when moved
if (AllBlocks.WINDMILL_BEARING.has(state))
moveWindmillBearing(pos, frontier, visited, state);
// Seats transfer their passenger to the contraption
if (state.getBlock() instanceof SeatBlock)
moveSeat(world, pos);
// Pulleys drag their rope and their attached structure
if (state.getBlock() instanceof PulleyBlock)
movePulley(world, pos, frontier, visited);
// Pistons drag their attaches poles and extension
if (state.getBlock() instanceof MechanicalPistonBlock)
if (!moveMechanicalPiston(world, pos, frontier, visited, state))
return false;
if (isExtensionPole(state))
movePistonPole(world, pos, frontier, visited, state);
if (isPistonHead(state))
movePistonHead(world, pos, frontier, visited, state);
// Cart assemblers attach themselves
2021-07-15 11:32:03 +02:00
BlockPos posDown = pos.below();
2021-01-30 14:09:04 +01:00
BlockState stateBelow = world.getBlockState(posDown);
if (!visited.contains(posDown) && AllBlocks.CART_ASSEMBLER.has(stateBelow))
frontier.add(posDown);
// Slime blocks and super glue drag adjacent blocks if possible
2020-12-10 02:36:59 +01:00
for (Direction offset : Iterate.directions) {
2021-07-15 11:32:03 +02:00
BlockPos offsetPos = pos.relative(offset);
BlockState blockState = world.getBlockState(offsetPos);
if (isAnchoringBlockAt(offsetPos))
continue;
2021-01-30 14:09:04 +01:00
if (!movementAllowed(blockState, world, offsetPos)) {
if (offset == forcedDirection)
2021-01-30 19:12:31 +01:00
throw AssemblyException.unmovableBlock(pos, state);
continue;
}
boolean wasVisited = visited.contains(offsetPos);
boolean faceHasGlue = SuperGlueEntity.isGlued(world, pos, offset, glueToRemove);
boolean blockAttachedTowardsFace =
BlockMovementChecks.isBlockAttachedTowards(blockState, world, offsetPos, offset.getOpposite());
boolean brittle = BlockMovementChecks.isBrittle(blockState);
boolean canStick = !brittle && state.canStickTo(blockState) && blockState.canStickTo(state);
if (canStick) {
2021-07-15 11:32:03 +02:00
if (state.getPistonPushReaction() == PushReaction.PUSH_ONLY
|| blockState.getPistonPushReaction() == PushReaction.PUSH_ONLY) {
canStick = false;
}
if (BlockMovementChecks.isNotSupportive(state, offset)) {
canStick = false;
}
if (BlockMovementChecks.isNotSupportive(blockState, offset.getOpposite())) {
canStick = false;
}
}
if (!wasVisited && (canStick || blockAttachedTowardsFace || faceHasGlue
|| (offset == forcedDirection && !BlockMovementChecks.isNotSupportive(state, forcedDirection))))
frontier.add(offsetPos);
}
addBlock(pos, capture(world, pos));
if (blocks.size() <= AllConfigs.server().kinetics.maxBlocksMoved.get())
2021-01-30 19:12:31 +01:00
return true;
else
2021-02-11 17:47:55 +01:00
throw AssemblyException.structureTooLarge();
}
protected void movePistonHead(Level world, BlockPos pos, Queue<BlockPos> frontier, Set<BlockPos> visited,
BlockState state) {
2021-07-15 11:32:03 +02:00
Direction direction = state.getValue(MechanicalPistonHeadBlock.FACING);
BlockPos offset = pos.relative(direction.getOpposite());
if (!visited.contains(offset)) {
BlockState blockState = world.getBlockState(offset);
2021-07-15 11:32:03 +02:00
if (isExtensionPole(blockState) && blockState.getValue(PistonExtensionPoleBlock.FACING)
.getAxis() == direction.getAxis())
frontier.add(offset);
if (blockState.getBlock() instanceof MechanicalPistonBlock) {
2021-07-15 11:32:03 +02:00
Direction pistonFacing = blockState.getValue(MechanicalPistonBlock.FACING);
if (pistonFacing == direction
&& blockState.getValue(MechanicalPistonBlock.STATE) == PistonState.EXTENDED)
frontier.add(offset);
}
}
2021-07-15 11:32:03 +02:00
if (state.getValue(MechanicalPistonHeadBlock.TYPE) == PistonType.STICKY) {
BlockPos attached = pos.relative(direction);
if (!visited.contains(attached))
frontier.add(attached);
}
}
protected void movePistonPole(Level world, BlockPos pos, Queue<BlockPos> frontier, Set<BlockPos> visited,
BlockState state) {
2021-07-15 11:32:03 +02:00
for (Direction d : Iterate.directionsInAxis(state.getValue(PistonExtensionPoleBlock.FACING)
.getAxis())) {
2021-07-15 11:32:03 +02:00
BlockPos offset = pos.relative(d);
if (!visited.contains(offset)) {
BlockState blockState = world.getBlockState(offset);
2021-07-15 11:32:03 +02:00
if (isExtensionPole(blockState) && blockState.getValue(PistonExtensionPoleBlock.FACING)
.getAxis() == d.getAxis())
frontier.add(offset);
2021-07-15 11:32:03 +02:00
if (isPistonHead(blockState) && blockState.getValue(MechanicalPistonHeadBlock.FACING)
.getAxis() == d.getAxis())
frontier.add(offset);
if (blockState.getBlock() instanceof MechanicalPistonBlock) {
2021-07-15 11:32:03 +02:00
Direction pistonFacing = blockState.getValue(MechanicalPistonBlock.FACING);
if (pistonFacing == d || pistonFacing == d.getOpposite()
2021-07-15 11:32:03 +02:00
&& blockState.getValue(MechanicalPistonBlock.STATE) == PistonState.EXTENDED)
frontier.add(offset);
}
}
}
}
protected void moveGantryPinion(Level world, BlockPos pos, Queue<BlockPos> frontier, Set<BlockPos> visited,
BlockState state) {
2021-07-15 11:32:03 +02:00
BlockPos offset = pos.relative(state.getValue(GantryCarriageBlock.FACING));
if (!visited.contains(offset))
frontier.add(offset);
Axis rotationAxis = ((IRotate) state.getBlock()).getRotationAxis(state);
for (Direction d : Iterate.directionsInAxis(rotationAxis)) {
2021-07-15 11:32:03 +02:00
offset = pos.relative(d);
BlockState offsetState = world.getBlockState(offset);
2021-07-15 11:32:03 +02:00
if (AllBlocks.GANTRY_SHAFT.has(offsetState) && offsetState.getValue(GantryShaftBlock.FACING)
.getAxis() == d.getAxis())
if (!visited.contains(offset))
frontier.add(offset);
}
}
protected void moveGantryShaft(Level world, BlockPos pos, Queue<BlockPos> frontier, Set<BlockPos> visited,
BlockState state) {
for (Direction d : Iterate.directions) {
2021-07-15 11:32:03 +02:00
BlockPos offset = pos.relative(d);
if (!visited.contains(offset)) {
BlockState offsetState = world.getBlockState(offset);
2021-07-15 11:32:03 +02:00
Direction facing = state.getValue(GantryShaftBlock.FACING);
if (d.getAxis() == facing.getAxis() && AllBlocks.GANTRY_SHAFT.has(offsetState)
2021-07-15 11:32:03 +02:00
&& offsetState.getValue(GantryShaftBlock.FACING) == facing)
frontier.add(offset);
else if (AllBlocks.GANTRY_CARRIAGE.has(offsetState)
&& offsetState.getValue(GantryCarriageBlock.FACING) == d)
frontier.add(offset);
}
}
}
private void moveWindmillBearing(BlockPos pos, Queue<BlockPos> frontier, Set<BlockPos> visited, BlockState state) {
2021-07-15 11:32:03 +02:00
Direction facing = state.getValue(WindmillBearingBlock.FACING);
BlockPos offset = pos.relative(facing);
if (!visited.contains(offset))
frontier.add(offset);
}
2021-01-30 14:09:04 +01:00
private void moveBearing(BlockPos pos, Queue<BlockPos> frontier, Set<BlockPos> visited, BlockState state) {
2021-07-15 11:32:03 +02:00
Direction facing = state.getValue(MechanicalBearingBlock.FACING);
if (!canBeStabilized(facing, pos.subtract(anchor))) {
2021-07-15 11:32:03 +02:00
BlockPos offset = pos.relative(facing);
if (!visited.contains(offset))
frontier.add(offset);
return;
}
pendingSubContraptions.add(new BlockFace(pos, facing));
}
2021-01-30 14:09:04 +01:00
private void moveBelt(BlockPos pos, Queue<BlockPos> frontier, Set<BlockPos> visited, BlockState state) {
BlockPos nextPos = BeltBlock.nextSegmentPosition(state, pos, true);
BlockPos prevPos = BeltBlock.nextSegmentPosition(state, pos, false);
if (nextPos != null && !visited.contains(nextPos))
frontier.add(nextPos);
if (prevPos != null && !visited.contains(prevPos))
frontier.add(prevPos);
}
private void moveSeat(Level world, BlockPos pos) {
BlockPos local = toLocalPos(pos);
getSeats().add(local);
List<SeatEntity> seatsEntities = world.getEntitiesOfClass(SeatEntity.class, new AABB(pos));
if (!seatsEntities.isEmpty()) {
SeatEntity seat = seatsEntities.get(0);
List<Entity> passengers = seat.getPassengers();
if (!passengers.isEmpty())
initialPassengers.put(local, passengers.get(0));
}
}
private void movePulley(Level world, BlockPos pos, Queue<BlockPos> frontier, Set<BlockPos> visited) {
int limit = AllConfigs.server().kinetics.maxRopeLength.get();
BlockPos ropePos = pos;
while (limit-- >= 0) {
2021-07-15 11:32:03 +02:00
ropePos = ropePos.below();
if (!world.isLoaded(ropePos))
break;
BlockState ropeState = world.getBlockState(ropePos);
Block block = ropeState.getBlock();
if (!(block instanceof RopeBlock) && !(block instanceof MagnetBlock)) {
if (!visited.contains(ropePos))
frontier.add(ropePos);
break;
}
addBlock(ropePos, capture(world, ropePos));
}
}
private boolean moveMechanicalPiston(Level world, BlockPos pos, Queue<BlockPos> frontier, Set<BlockPos> visited,
BlockState state) throws AssemblyException {
2021-07-15 11:32:03 +02:00
Direction direction = state.getValue(MechanicalPistonBlock.FACING);
PistonState pistonState = state.getValue(MechanicalPistonBlock.STATE);
if (pistonState == PistonState.MOVING)
return false;
2021-07-15 11:32:03 +02:00
BlockPos offset = pos.relative(direction.getOpposite());
if (!visited.contains(offset)) {
BlockState poleState = world.getBlockState(offset);
2021-07-15 11:32:03 +02:00
if (AllBlocks.PISTON_EXTENSION_POLE.has(poleState) && poleState.getValue(PistonExtensionPoleBlock.FACING)
.getAxis() == direction.getAxis())
frontier.add(offset);
}
if (pistonState == PistonState.EXTENDED || MechanicalPistonBlock.isStickyPiston(state)) {
2021-07-15 11:32:03 +02:00
offset = pos.relative(direction);
if (!visited.contains(offset))
frontier.add(offset);
}
return true;
}
private boolean moveChassis(Level world, BlockPos pos, Direction movementDirection, Queue<BlockPos> frontier,
Set<BlockPos> visited) {
BlockEntity be = world.getBlockEntity(pos);
if (!(be instanceof ChassisBlockEntity))
return false;
ChassisBlockEntity chassis = (ChassisBlockEntity) be;
chassis.addAttachedChasses(frontier, visited);
List<BlockPos> includedBlockPositions = chassis.getIncludedBlockPositions(movementDirection, false);
if (includedBlockPositions == null)
return false;
for (BlockPos blockPos : includedBlockPositions)
if (!visited.contains(blockPos))
frontier.add(blockPos);
return true;
}
protected Pair<StructureBlockInfo, BlockEntity> capture(Level world, BlockPos pos) {
BlockState blockstate = world.getBlockState(pos);
if (AllBlocks.REDSTONE_CONTACT.has(blockstate))
2021-07-15 11:32:03 +02:00
blockstate = blockstate.setValue(RedstoneContactBlock.POWERED, true);
if (AllBlocks.POWERED_SHAFT.has(blockstate))
blockstate = BlockHelper.copyProperties(blockstate, AllBlocks.SHAFT.getDefaultState());
2023-05-13 12:37:52 +02:00
if (blockstate.getBlock() instanceof ControlsBlock && getType() == ContraptionType.CARRIAGE)
2022-02-01 01:14:21 +01:00
blockstate = blockstate.setValue(ControlsBlock.OPEN, true);
if (blockstate.hasProperty(SlidingDoorBlock.VISIBLE))
blockstate = blockstate.setValue(SlidingDoorBlock.VISIBLE, false);
if (blockstate.getBlock() instanceof ButtonBlock) {
blockstate = blockstate.setValue(ButtonBlock.POWERED, false);
world.scheduleTick(pos, blockstate.getBlock(), -1);
}
if (blockstate.getBlock() instanceof PressurePlateBlock) {
2021-07-15 11:32:03 +02:00
blockstate = blockstate.setValue(PressurePlateBlock.POWERED, false);
world.scheduleTick(pos, blockstate.getBlock(), -1);
}
CompoundTag compoundnbt = getBlockEntityNBT(world, pos);
BlockEntity blockEntity = world.getBlockEntity(pos);
if (blockEntity instanceof PoweredShaftBlockEntity)
blockEntity = AllBlockEntityTypes.BRACKETED_KINETIC.create(pos, blockstate);
return Pair.of(new StructureBlockInfo(pos, blockstate, compoundnbt), blockEntity);
}
protected void addBlock(BlockPos pos, Pair<StructureBlockInfo, BlockEntity> pair) {
StructureBlockInfo captured = pair.getKey();
BlockPos localPos = pos.subtract(anchor);
StructureBlockInfo structureBlockInfo = new StructureBlockInfo(localPos, captured.state, captured.nbt);
if (blocks.put(localPos, structureBlockInfo) != null)
return;
bounds = bounds.minmax(new AABB(localPos));
BlockEntity be = pair.getValue();
storage.addBlock(localPos, be);
if (AllMovementBehaviours.getBehaviour(captured.state) != null)
actors.add(MutablePair.of(structureBlockInfo, null));
MovingInteractionBehaviour interactionBehaviour = AllInteractionBehaviours.getBehaviour(captured.state);
if (interactionBehaviour != null)
interactors.put(localPos, interactionBehaviour);
if (be instanceof CreativeCrateBlockEntity
&& ((CreativeCrateBlockEntity) be).getBehaviour(FilteringBehaviour.TYPE)
.getFilter()
.isEmpty())
hasUniversalCreativeCrate = true;
}
@Nullable
protected CompoundTag getBlockEntityNBT(Level world, BlockPos pos) {
BlockEntity blockEntity = world.getBlockEntity(pos);
if (blockEntity == null)
return null;
CompoundTag nbt = blockEntity.saveWithFullMetadata();
nbt.remove("x");
nbt.remove("y");
nbt.remove("z");
if ((blockEntity instanceof FluidTankBlockEntity || blockEntity instanceof ItemVaultBlockEntity)
2021-11-10 21:07:47 +01:00
&& nbt.contains("Controller"))
nbt.put("Controller",
NbtUtils.writeBlockPos(toLocalPos(NbtUtils.readBlockPos(nbt.getCompound("Controller")))));
return nbt;
}
protected BlockPos toLocalPos(BlockPos globalPos) {
return globalPos.subtract(anchor);
}
protected boolean movementAllowed(BlockState state, Level world, BlockPos pos) {
return BlockMovementChecks.isMovementAllowed(state, world, pos);
}
protected boolean isAnchoringBlockAt(BlockPos pos) {
return pos.equals(anchor);
}
public void readNBT(Level world, CompoundTag nbt, boolean spawnData) {
blocks.clear();
presentBlockEntities.clear();
specialRenderedBlockEntities.clear();
Tag blocks = nbt.get("Blocks");
// used to differentiate between the 'old' and the paletted serialization
boolean usePalettedDeserialization =
blocks != null && blocks.getId() == 10 && ((CompoundTag) blocks).contains("Palette");
readBlocksCompound(blocks, world, usePalettedDeserialization);
actors.clear();
nbt.getList("Actors", 10)
.forEach(c -> {
CompoundTag comp = (CompoundTag) c;
StructureBlockInfo info = this.blocks.get(NbtUtils.readBlockPos(comp.getCompound("Pos")));
if (info == null)
return;
MovementContext context = MovementContext.readNBT(world, info, comp, this);
getActors().add(MutablePair.of(info, context));
});
disabledActors = NBTHelper.readItemList(nbt.getList("DisabledActors", Tag.TAG_COMPOUND));
for (ItemStack stack : disabledActors)
setActorsActive(stack, false);
superglue.clear();
NBTHelper.iterateCompoundList(nbt.getList("Superglue", Tag.TAG_COMPOUND),
c -> superglue.add(SuperGlueEntity.readBoundingBox(c)));
seats.clear();
NBTHelper.iterateCompoundList(nbt.getList("Seats", Tag.TAG_COMPOUND), c -> seats.add(NbtUtils.readBlockPos(c)));
seatMapping.clear();
NBTHelper.iterateCompoundList(nbt.getList("Passengers", Tag.TAG_COMPOUND),
c -> seatMapping.put(NbtUtils.loadUUID(NBTHelper.getINBT(c, "Id")), c.getInt("Seat")));
stabilizedSubContraptions.clear();
NBTHelper.iterateCompoundList(nbt.getList("SubContraptions", Tag.TAG_COMPOUND),
2021-07-15 11:32:03 +02:00
c -> stabilizedSubContraptions.put(c.getUUID("Id"), BlockFace.fromNBT(c.getCompound("Location"))));
interactors.clear();
NBTHelper.iterateCompoundList(nbt.getList("Interactors", Tag.TAG_COMPOUND), c -> {
BlockPos pos = NbtUtils.readBlockPos(c.getCompound("Pos"));
StructureBlockInfo structureBlockInfo = getBlocks().get(pos);
if (structureBlockInfo == null)
return;
MovingInteractionBehaviour behaviour = AllInteractionBehaviours.getBehaviour(structureBlockInfo.state);
if (behaviour != null)
interactors.put(pos, behaviour);
});
storage.read(nbt, presentBlockEntities, spawnData);
if (nbt.contains("BoundsFront"))
bounds = NBTHelper.readAABB(nbt.getList("BoundsFront", 5));
stalled = nbt.getBoolean("Stalled");
hasUniversalCreativeCrate = nbt.getBoolean("BottomlessSupply");
anchor = NbtUtils.readBlockPos(nbt.getCompound("Anchor"));
}
public CompoundTag writeNBT(boolean spawnPacket) {
CompoundTag nbt = new CompoundTag();
nbt.putString("Type", getType().id);
CompoundTag blocksNBT = writeBlocksCompound();
ListTag actorsNBT = new ListTag();
for (MutablePair<StructureBlockInfo, MovementContext> actor : getActors()) {
MovementBehaviour behaviour = AllMovementBehaviours.getBehaviour(actor.left.state);
if (behaviour == null)
continue;
CompoundTag compound = new CompoundTag();
compound.put("Pos", NbtUtils.writeBlockPos(actor.left.pos));
behaviour.writeExtraData(actor.right);
actor.right.writeToNBT(compound);
actorsNBT.add(compound);
}
ListTag disabledActorsNBT = NBTHelper.writeItemList(disabledActors);
ListTag superglueNBT = new ListTag();
if (!spawnPacket) {
for (AABB glueEntry : superglue) {
CompoundTag c = new CompoundTag();
SuperGlueEntity.writeBoundingBox(c, glueEntry);
superglueNBT.add(c);
}
}
(spawnPacket ? getStorageForSpawnPacket() : storage).write(nbt, spawnPacket);
ListTag interactorNBT = new ListTag();
for (BlockPos pos : interactors.keySet()) {
CompoundTag c = new CompoundTag();
c.put("Pos", NbtUtils.writeBlockPos(pos));
interactorNBT.add(c);
}
nbt.put("Seats", NBTHelper.writeCompoundList(getSeats(), NbtUtils::writeBlockPos));
nbt.put("Passengers", NBTHelper.writeCompoundList(getSeatMapping().entrySet(), e -> {
CompoundTag tag = new CompoundTag();
tag.put("Id", NbtUtils.createUUID(e.getKey()));
tag.putInt("Seat", e.getValue());
return tag;
}));
nbt.put("SubContraptions", NBTHelper.writeCompoundList(stabilizedSubContraptions.entrySet(), e -> {
CompoundTag tag = new CompoundTag();
2021-07-15 11:32:03 +02:00
tag.putUUID("Id", e.getKey());
tag.put("Location", e.getValue()
.serializeNBT());
return tag;
}));
nbt.put("Blocks", blocksNBT);
nbt.put("Actors", actorsNBT);
nbt.put("DisabledActors", disabledActorsNBT);
nbt.put("Interactors", interactorNBT);
nbt.put("Superglue", superglueNBT);
nbt.put("Anchor", NbtUtils.writeBlockPos(anchor));
nbt.putBoolean("Stalled", stalled);
nbt.putBoolean("BottomlessSupply", hasUniversalCreativeCrate);
if (bounds != null) {
ListTag bb = NBTHelper.writeAABB(bounds);
nbt.put("BoundsFront", bb);
}
return nbt;
}
protected MountedStorageManager getStorageForSpawnPacket() {
return storage;
}
private CompoundTag writeBlocksCompound() {
CompoundTag compound = new CompoundTag();
HashMapPalette<BlockState> palette = new HashMapPalette<>(GameData.getBlockStateIDMap(), 16, (i, s) -> {
throw new IllegalStateException("Palette Map index exceeded maximum");
});
ListTag blockList = new ListTag();
for (StructureBlockInfo block : this.blocks.values()) {
int id = palette.idFor(block.state);
CompoundTag c = new CompoundTag();
2021-07-15 11:32:03 +02:00
c.putLong("Pos", block.pos.asLong());
c.putInt("State", id);
if (block.nbt != null)
c.put("Data", block.nbt);
blockList.add(c);
}
ListTag paletteNBT = new ListTag();
for (int i = 0; i < palette.getSize(); ++i)
paletteNBT.add(NbtUtils.writeBlockState(palette.values.byId(i)));
compound.put("Palette", paletteNBT);
compound.put("BlockList", blockList);
return compound;
}
private void readBlocksCompound(Tag compound, Level world, boolean usePalettedDeserialization) {
HashMapPalette<BlockState> palette = null;
ListTag blockList;
if (usePalettedDeserialization) {
CompoundTag c = ((CompoundTag) compound);
palette = new HashMapPalette<>(GameData.getBlockStateIDMap(), 16, (i, s) -> {
throw new IllegalStateException("Palette Map index exceeded maximum");
});
ListTag list = c.getList("Palette", 10);
palette.values.clear();
for (int i = 0; i < list.size(); ++i)
palette.values.add(NbtUtils.readBlockState(list.getCompound(i)));
blockList = c.getList("BlockList", 10);
} else {
blockList = (ListTag) compound;
}
HashMapPalette<BlockState> finalPalette = palette;
blockList.forEach(e -> {
CompoundTag c = (CompoundTag) e;
2021-11-02 16:25:48 +01:00
StructureBlockInfo info =
usePalettedDeserialization ? readStructureBlockInfo(c, finalPalette) : legacyReadStructureBlockInfo(c);
this.blocks.put(info.pos, info);
if (!world.isClientSide)
return;
CompoundTag tag = info.nbt;
if (tag == null)
return;
tag.putInt("x", info.pos.getX());
tag.putInt("y", info.pos.getY());
tag.putInt("z", info.pos.getZ());
BlockEntity be = BlockEntity.loadStatic(info.pos, info.state, tag);
if (be == null)
return;
be.setLevel(world);
modelData.put(info.pos, be.getModelData());
if (be instanceof KineticBlockEntity kte)
kte.setSpeed(0);
be.getBlockState();
MovementBehaviour movementBehaviour = AllMovementBehaviours.getBehaviour(info.state);
if (movementBehaviour == null || !movementBehaviour.hasSpecialInstancedRendering())
maybeInstancedBlockEntities.add(be);
if (movementBehaviour != null && !movementBehaviour.renderAsNormalBlockEntity())
return;
presentBlockEntities.put(info.pos, be);
specialRenderedBlockEntities.add(be);
});
}
2021-11-02 16:25:48 +01:00
private static StructureBlockInfo readStructureBlockInfo(CompoundTag blockListEntry,
HashMapPalette<BlockState> palette) {
return new StructureBlockInfo(BlockPos.of(blockListEntry.getLong("Pos")),
2021-07-15 11:32:03 +02:00
Objects.requireNonNull(palette.valueFor(blockListEntry.getInt("State"))),
blockListEntry.contains("Data") ? blockListEntry.getCompound("Data") : null);
}
2021-11-02 16:25:48 +01:00
private static StructureBlockInfo legacyReadStructureBlockInfo(CompoundTag blockListEntry) {
return new StructureBlockInfo(NbtUtils.readBlockPos(blockListEntry.getCompound("Pos")),
NbtUtils.readBlockState(blockListEntry.getCompound("Block")),
blockListEntry.contains("Data") ? blockListEntry.getCompound("Data") : null);
}
public void removeBlocksFromWorld(Level world, BlockPos offset) {
storage.removeStorageFromWorld();
glueToRemove.forEach(glue -> {
superglue.add(glue.getBoundingBox()
.move(Vec3.atLowerCornerOf(offset.offset(anchor))
.scale(-1)));
glue.discard();
});
List<BoundingBox> minimisedGlue = new ArrayList<>();
for (int i = 0; i < superglue.size(); i++)
minimisedGlue.add(null);
for (boolean brittles : Iterate.trueAndFalse) {
for (Iterator<StructureBlockInfo> iterator = blocks.values()
.iterator(); iterator.hasNext();) {
StructureBlockInfo block = iterator.next();
if (brittles != BlockMovementChecks.isBrittle(block.state))
continue;
for (int i = 0; i < superglue.size(); i++) {
AABB aabb = superglue.get(i);
if (aabb == null
|| !aabb.contains(block.pos.getX() + .5, block.pos.getY() + .5, block.pos.getZ() + .5))
continue;
if (minimisedGlue.get(i) == null)
minimisedGlue.set(i, new BoundingBox(block.pos));
else
minimisedGlue.set(i, BBHelper.encapsulate(minimisedGlue.get(i), block.pos));
}
2021-07-15 11:32:03 +02:00
BlockPos add = block.pos.offset(anchor)
.offset(offset);
if (customBlockRemoval(world, add, block.state))
continue;
BlockState oldState = world.getBlockState(add);
Block blockIn = oldState.getBlock();
boolean blockMismatch = block.state.getBlock() != blockIn;
blockMismatch &= !AllBlocks.POWERED_SHAFT.is(blockIn) || !AllBlocks.SHAFT.has(block.state);
if (blockMismatch)
iterator.remove();
2021-07-15 11:32:03 +02:00
world.removeBlockEntity(add);
int flags = Block.UPDATE_MOVE_BY_PISTON | Block.UPDATE_SUPPRESS_DROPS | Block.UPDATE_KNOWN_SHAPE
| Block.UPDATE_CLIENTS | Block.UPDATE_IMMEDIATE;
if (blockIn instanceof SimpleWaterloggedBlock && oldState.hasProperty(BlockStateProperties.WATERLOGGED)
2021-07-15 11:32:03 +02:00
&& oldState.getValue(BlockStateProperties.WATERLOGGED)) {
world.setBlock(add, Blocks.WATER.defaultBlockState(), flags);
continue;
}
2021-07-15 11:32:03 +02:00
world.setBlock(add, Blocks.AIR.defaultBlockState(), flags);
}
}
superglue.clear();
for (BoundingBox box : minimisedGlue) {
if (box == null)
continue;
AABB bb = new AABB(box.minX(), box.minY(), box.minZ(), box.maxX() + 1, box.maxY() + 1, box.maxZ() + 1);
if (bb.getSize() > 1.01)
superglue.add(bb);
}
for (StructureBlockInfo block : blocks.values()) {
2021-07-15 11:32:03 +02:00
BlockPos add = block.pos.offset(anchor)
.offset(offset);
// if (!shouldUpdateAfterMovement(block))
// continue;
int flags = Block.UPDATE_MOVE_BY_PISTON | Block.UPDATE_ALL;
2021-07-15 11:32:03 +02:00
world.sendBlockUpdated(add, block.state, Blocks.AIR.defaultBlockState(), flags);
2021-11-02 16:25:48 +01:00
// when the blockstate is set to air, the block's POI data is removed, but
// markAndNotifyBlock tries to
// remove it again, so to prevent an error from being logged by double-removal
// we add the POI data back now
// (code copied from ServerWorld.onBlockStateChange)
ServerLevel serverWorld = (ServerLevel) world;
PoiType.forState(block.state)
.ifPresent(poiType -> {
world.getServer()
.execute(() -> {
serverWorld.getPoiManager()
.add(add, poiType);
DebugPackets.sendPoiAddedPacket(serverWorld, add);
});
});
world.markAndNotifyBlock(add, world.getChunkAt(add), block.state, Blocks.AIR.defaultBlockState(), flags,
512);
2021-07-15 11:32:03 +02:00
block.state.updateIndirectNeighbourShapes(world, add, flags & -2);
}
}
public void addBlocksToWorld(Level world, StructureTransform transform) {
2022-10-03 00:31:42 +02:00
if (disassembled)
return;
disassembled = true;
for (boolean nonBrittles : Iterate.trueAndFalse) {
for (StructureBlockInfo block : blocks.values()) {
if (nonBrittles == BlockMovementChecks.isBrittle(block.state))
continue;
BlockPos targetPos = transform.apply(block.pos);
BlockState state = transform.apply(block.state);
if (customBlockPlacement(world, targetPos, state))
continue;
if (nonBrittles)
2020-12-10 02:36:59 +01:00
for (Direction face : Iterate.directions)
state = state.updateShape(face, world.getBlockState(targetPos.relative(face)), world, targetPos,
targetPos.relative(face));
BlockState blockState = world.getBlockState(targetPos);
2021-07-15 11:32:03 +02:00
if (blockState.getDestroySpeed(world, targetPos) == -1 || (state.getCollisionShape(world, targetPos)
.isEmpty()
&& !blockState.getCollisionShape(world, targetPos)
.isEmpty())) {
if (targetPos.getY() == world.getMinBuildHeight())
2021-07-15 11:32:03 +02:00
targetPos = targetPos.above();
world.levelEvent(2001, targetPos, Block.getId(state));
Block.dropResources(state, world, targetPos, null);
continue;
}
2021-11-02 16:25:48 +01:00
if (state.getBlock() instanceof SimpleWaterloggedBlock
&& state.hasProperty(BlockStateProperties.WATERLOGGED)) {
2020-09-22 17:44:22 +02:00
FluidState FluidState = world.getFluidState(targetPos);
2021-07-15 11:32:03 +02:00
state = state.setValue(BlockStateProperties.WATERLOGGED, FluidState.getType() == Fluids.WATER);
}
world.destroyBlock(targetPos, true);
if (AllBlocks.SHAFT.has(state))
state = ShaftBlock.pickCorrectShaftType(state, world, targetPos);
if (state.hasProperty(SlidingDoorBlock.VISIBLE))
state = state.setValue(SlidingDoorBlock.VISIBLE, !state.getValue(SlidingDoorBlock.OPEN))
.setValue(SlidingDoorBlock.POWERED, false);
world.setBlock(targetPos, state, Block.UPDATE_MOVE_BY_PISTON | Block.UPDATE_ALL);
boolean verticalRotation = transform.rotationAxis == null || transform.rotationAxis.isHorizontal();
verticalRotation = verticalRotation && transform.rotation != Rotation.NONE;
if (verticalRotation) {
if (state.getBlock() instanceof RopeBlock || state.getBlock() instanceof MagnetBlock
|| state.getBlock() instanceof DoorBlock)
world.destroyBlock(targetPos, true);
}
BlockEntity blockEntity = world.getBlockEntity(targetPos);
CompoundTag tag = block.nbt;
if (blockEntity != null)
tag = NBTProcessors.process(blockEntity, tag, false);
if (blockEntity != null && tag != null) {
tag.putInt("x", targetPos.getX());
tag.putInt("y", targetPos.getY());
tag.putInt("z", targetPos.getZ());
if (verticalRotation && blockEntity instanceof PulleyBlockEntity) {
tag.remove("Offset");
tag.remove("InitialOffset");
}
if (blockEntity instanceof IMultiBlockEntityContainer && tag.contains("LastKnownPos"))
tag.put("LastKnownPos", NbtUtils.writeBlockPos(BlockPos.ZERO.below(Integer.MAX_VALUE - 1)));
blockEntity.load(tag);
storage.addStorageToWorld(block, blockEntity);
}
transform.apply(blockEntity);
}
}
for (StructureBlockInfo block : blocks.values()) {
if (!shouldUpdateAfterMovement(block))
continue;
BlockPos targetPos = transform.apply(block.pos);
world.markAndNotifyBlock(targetPos, world.getChunkAt(targetPos), block.state, block.state,
Block.UPDATE_MOVE_BY_PISTON | Block.UPDATE_ALL, 512);
}
for (AABB box : superglue) {
box = new AABB(transform.apply(new Vec3(box.minX, box.minY, box.minZ)),
transform.apply(new Vec3(box.maxX, box.maxY, box.maxZ)));
if (!world.isClientSide)
world.addFreshEntity(new SuperGlueEntity(world, box));
}
storage.clear();
}
public void addPassengersToWorld(Level world, StructureTransform transform, List<Entity> seatedEntities) {
for (Entity seatedEntity : seatedEntities) {
if (getSeatMapping().isEmpty())
continue;
2021-07-15 11:32:03 +02:00
Integer seatIndex = getSeatMapping().get(seatedEntity.getUUID());
if (seatIndex == null)
continue;
BlockPos seatPos = getSeats().get(seatIndex);
seatPos = transform.apply(seatPos);
if (!(world.getBlockState(seatPos)
.getBlock() instanceof SeatBlock))
continue;
if (SeatBlock.isSeatOccupied(world, seatPos))
continue;
SeatBlock.sitDown(world, seatPos, seatedEntity);
}
}
public void startMoving(Level world) {
disabledActors.clear();
for (MutablePair<StructureBlockInfo, MovementContext> pair : actors) {
MovementContext context = new MovementContext(world, pair.left, this);
MovementBehaviour behaviour = AllMovementBehaviours.getBehaviour(pair.left.state);
if (behaviour != null)
behaviour.startMoving(context);
pair.setRight(context);
if (behaviour instanceof ContraptionControlsMovement)
disableActorOnStart(context);
}
for (ItemStack stack : disabledActors)
setActorsActive(stack, false);
}
protected void disableActorOnStart(MovementContext context) {
if (!ContraptionControlsMovement.isDisabledInitially(context))
return;
ItemStack filter = ContraptionControlsMovement.getFilter(context);
if (filter == null)
return;
if (isActorTypeDisabled(filter))
return;
disabledActors.add(filter);
}
public boolean isActorTypeDisabled(ItemStack filter) {
return disabledActors.stream()
.anyMatch(i -> ContraptionControlsMovement.isSameFilter(i, filter));
}
public void setActorsActive(ItemStack referenceStack, boolean enable) {
for (MutablePair<StructureBlockInfo, MovementContext> pair : actors) {
MovementBehaviour behaviour = AllMovementBehaviours.getBehaviour(pair.left.state);
if (behaviour == null)
continue;
ItemStack behaviourStack = behaviour.canBeDisabledVia(pair.right);
if (behaviourStack == null)
continue;
if (!referenceStack.isEmpty() && !ContraptionControlsMovement.isSameFilter(referenceStack, behaviourStack))
continue;
pair.right.disabled = !enable;
if (!enable)
behaviour.onDisabledByControls(pair.right);
}
}
public List<ItemStack> getDisabledActors() {
return disabledActors;
}
public void stop(Level world) {
forEachActor(world, (behaviour, ctx) -> {
behaviour.stopMoving(ctx);
ctx.position = null;
ctx.motion = Vec3.ZERO;
ctx.relativeMotion = Vec3.ZERO;
ctx.rotation = v -> v;
});
}
public void forEachActor(Level world, BiConsumer<MovementBehaviour, MovementContext> callBack) {
for (MutablePair<StructureBlockInfo, MovementContext> pair : actors) {
MovementBehaviour behaviour = AllMovementBehaviours.getBehaviour(pair.getLeft().state);
if (behaviour == null)
continue;
callBack.accept(behaviour, pair.getRight());
}
}
protected boolean shouldUpdateAfterMovement(StructureBlockInfo info) {
if (PoiType.forState(info.state)
.isPresent())
return false;
if (info.state.getBlock() instanceof SlidingDoorBlock)
return false;
return true;
}
public void expandBoundsAroundAxis(Axis axis) {
Set<BlockPos> blocks = getBlocks().keySet();
int radius = (int) (Math.ceil(Math.sqrt(getRadius(blocks, axis))));
int maxX = radius + 2;
int maxY = radius + 2;
int maxZ = radius + 2;
int minX = -radius - 1;
int minY = -radius - 1;
int minZ = -radius - 1;
if (axis == Direction.Axis.X) {
maxX = (int) bounds.maxX;
minX = (int) bounds.minX;
} else if (axis == Direction.Axis.Y) {
maxY = (int) bounds.maxY;
minY = (int) bounds.minY;
} else if (axis == Direction.Axis.Z) {
maxZ = (int) bounds.maxZ;
minZ = (int) bounds.minZ;
}
bounds = new AABB(minX, minY, minZ, maxX, maxY, maxZ);
}
public Map<UUID, Integer> getSeatMapping() {
return seatMapping;
}
public BlockPos getSeatOf(UUID entityId) {
if (!getSeatMapping().containsKey(entityId))
return null;
int seatIndex = getSeatMapping().get(entityId);
if (seatIndex >= getSeats().size())
return null;
return getSeats().get(seatIndex);
}
public BlockPos getBearingPosOf(UUID subContraptionEntityId) {
if (stabilizedSubContraptions.containsKey(subContraptionEntityId))
return stabilizedSubContraptions.get(subContraptionEntityId)
.getConnectedPos();
return null;
}
public void setSeatMapping(Map<UUID, Integer> seatMapping) {
this.seatMapping = seatMapping;
}
public List<BlockPos> getSeats() {
return seats;
}
2021-11-02 16:25:48 +01:00
public Map<BlockPos, StructureBlockInfo> getBlocks() {
return blocks;
}
2021-11-02 16:25:48 +01:00
public List<MutablePair<StructureBlockInfo, MovementContext>> getActors() {
return actors;
}
@Nullable
public MutablePair<StructureBlockInfo, MovementContext> getActorAt(BlockPos localPos) {
for (MutablePair<StructureBlockInfo, MovementContext> pair : actors)
if (localPos.equals(pair.left.pos))
return pair;
return null;
}
public Map<BlockPos, MovingInteractionBehaviour> getInteractors() {
return interactors;
}
@OnlyIn(Dist.CLIENT)
public ContraptionLighter<?> makeLighter() {
// TODO: move lighters to registry
return new EmptyLighter(this);
}
public void invalidateColliders() {
simplifiedEntityColliders = Optional.empty();
gatherBBsOffThread();
}
private void gatherBBsOffThread() {
getContraptionWorld();
simplifiedEntityColliderProvider = CompletableFuture.supplyAsync(() -> {
2021-11-02 16:25:48 +01:00
VoxelShape combinedShape = Shapes.empty();
for (Entry<BlockPos, StructureBlockInfo> entry : blocks.entrySet()) {
StructureBlockInfo info = entry.getValue();
BlockPos localPos = entry.getKey();
VoxelShape collisionShape = info.state.getCollisionShape(world, localPos, CollisionContext.empty());
if (collisionShape.isEmpty())
continue;
2021-11-02 16:25:48 +01:00
combinedShape = Shapes.joinUnoptimized(combinedShape,
collisionShape.move(localPos.getX(), localPos.getY(), localPos.getZ()), BooleanOp.OR);
}
2021-07-15 11:32:03 +02:00
return combinedShape.optimize()
.toAabbs();
})
.thenAccept(r -> {
simplifiedEntityColliders = Optional.of(r);
simplifiedEntityColliderProvider = null;
});
}
public static float getRadius(Set<BlockPos> blocks, Direction.Axis axis) {
switch (axis) {
case X:
return getMaxDistSqr(blocks, BlockPos::getY, BlockPos::getZ);
case Y:
return getMaxDistSqr(blocks, BlockPos::getX, BlockPos::getZ);
case Z:
return getMaxDistSqr(blocks, BlockPos::getX, BlockPos::getY);
}
throw new IllegalStateException("Impossible axis");
}
public static float getMaxDistSqr(Set<BlockPos> blocks, ICoordinate one, ICoordinate other) {
float maxDistSq = -1;
for (BlockPos pos : blocks) {
float a = one.get(pos);
float b = other.get(pos);
float distSq = a * a + b * b;
if (distSq > maxDistSq)
maxDistSq = distSq;
}
return maxDistSq;
}
public IItemHandlerModifiable getSharedInventory() {
return storage.getItems();
}
public IItemHandlerModifiable getSharedFuelInventory() {
return storage.getFuelItems();
}
public IFluidHandler getSharedFluidTanks() {
return storage.getFluids();
}
public Collection<StructureBlockInfo> getRenderedBlocks() {
return blocks.values();
}
public Collection<BlockEntity> getSpecialRenderedTEs() {
return specialRenderedBlockEntities;
}
public boolean isHiddenInPortal(BlockPos localPos) {
return false;
}
public Optional<List<AABB>> getSimplifiedEntityColliders() {
return simplifiedEntityColliders;
}
public void handleContraptionFluidPacket(BlockPos localPos, FluidStack containedFluid) {
storage.updateContainedFluid(localPos, containedFluid);
}
public static class ContraptionInvWrapper extends CombinedInvWrapper {
protected final boolean isExternal;
public ContraptionInvWrapper(boolean isExternal, IItemHandlerModifiable... itemHandler) {
super(itemHandler);
this.isExternal = isExternal;
}
public ContraptionInvWrapper(IItemHandlerModifiable... itemHandler) {
this(false, itemHandler);
}
public boolean isSlotExternal(int slot) {
if (isExternal)
return true;
IItemHandlerModifiable handler = getHandlerFromIndex(getIndexForSlot(slot));
return handler instanceof ContraptionInvWrapper && ((ContraptionInvWrapper) handler).isSlotExternal(slot);
}
}
public void tickStorage(AbstractContraptionEntity entity) {
storage.entityTick(entity);
}
public boolean containsBlockBreakers() {
for (MutablePair<StructureBlockInfo, MovementContext> pair : actors) {
MovementBehaviour behaviour = AllMovementBehaviours.getBehaviour(pair.getLeft().state);
if (behaviour instanceof BlockBreakingMovementBehaviour || behaviour instanceof HarvesterMovementBehaviour)
return true;
}
return false;
}
}