1+ package net .adeptstack .Mixin ;
2+
3+ import com .simibubi .create .AllSoundEvents ;
4+ import com .simibubi .create .content .contraptions .AbstractContraptionEntity ;
5+ import com .simibubi .create .content .contraptions .Contraption ;
6+ import com .simibubi .create .content .contraptions .actors .contraptionControls .ContraptionControlsBlockEntity ;
7+ import com .simibubi .create .content .contraptions .actors .contraptionControls .ContraptionControlsMovingInteraction ;
8+ import com .simibubi .create .content .contraptions .behaviour .MovementContext ;
9+ import com .simibubi .create .content .trains .entity .Carriage ;
10+ import com .simibubi .create .content .trains .entity .CarriageContraptionEntity ;
11+ import com .simibubi .create .content .trains .entity .Train ;
12+ import net .minecraft .core .BlockPos ;
13+ import net .minecraft .tags .ItemTags ;
14+ import net .minecraft .world .InteractionHand ;
15+ import net .minecraft .world .entity .player .Player ;
16+ import net .minecraft .world .item .ItemStack ;
17+ import net .minecraft .world .level .levelgen .structure .templatesystem .StructureTemplate .StructureBlockInfo ;
18+ import net .minecraft .world .phys .Vec3 ;
19+ import org .apache .commons .lang3 .tuple .MutablePair ;
20+ import org .spongepowered .asm .mixin .Mixin ;
21+ import org .spongepowered .asm .mixin .Shadow ;
22+ import org .spongepowered .asm .mixin .injection .At ;
23+ import org .spongepowered .asm .mixin .injection .Inject ;
24+ import org .spongepowered .asm .mixin .injection .callback .CallbackInfoReturnable ;
25+ import org .spongepowered .asm .mixin .injection .callback .LocalCapture ;
26+
27+ @ Mixin (ContraptionControlsMovingInteraction .class )
28+ public class ContraptionControlsMovingInteractionMixin {
29+
30+ @ Shadow (remap = false )
31+ private void send (AbstractContraptionEntity contraptionEntity , ItemStack filter , boolean disable ) { throw new AssertionError (); }
32+
33+ @ Inject (method = "handlePlayerInteraction" , remap = false , at = @ At (value = "TAIL" ), locals = LocalCapture .CAPTURE_FAILHARD )
34+ private void customHandlePlayerInteraction (Player player , InteractionHand activeHand , BlockPos localPos ,
35+ AbstractContraptionEntity contraptionEntity , CallbackInfoReturnable <Boolean > cir ,
36+ Contraption contraption , MutablePair <StructureBlockInfo , MovementContext > actor ,
37+ MovementContext ctx , ItemStack filter , boolean disable ) {
38+ if (contraptionEntity instanceof CarriageContraptionEntity cce && filter .is (ItemTags .DOORS )) {
39+ Carriage carriage = cce .getCarriage ();
40+ Train train = carriage .train ;
41+ for (Carriage c : train .carriages ) {
42+ Contraption cpt = c .anyAvailableEntity ().getContraption ();
43+
44+ cpt .setActorsActive (filter , !disable );
45+ ContraptionControlsBlockEntity .sendStatus (player , filter , !disable );
46+ send (cpt .entity , filter , disable );
47+
48+ AllSoundEvents .CONTROLLER_CLICK .play (player .level (), null , BlockPos .containing (contraptionEntity .toGlobalVector (Vec3 .atCenterOf (localPos ), 1 )), 1 , disable ? 0.8f : 1.5f );
49+ }
50+ }
51+ }
52+ }
0 commit comments