|
15 | 15 | import com.simibubi.create.content.contraptions.behaviour.MovementContext;
|
16 | 16 | import com.simibubi.create.content.contraptions.elevator.ElevatorContraption;
|
17 | 17 | import com.simibubi.create.content.contraptions.elevator.ElevatorTargetFloorPacket;
|
| 18 | +import com.simibubi.create.content.trains.entity.Carriage; |
| 19 | +import com.simibubi.create.content.trains.entity.CarriageContraptionEntity; |
| 20 | +import com.simibubi.create.content.trains.entity.Train; |
18 | 21 |
|
19 | 22 | import net.minecraft.core.BlockPos;
|
| 23 | +import net.minecraft.tags.ItemTags; |
20 | 24 | import net.minecraft.world.InteractionHand;
|
21 | 25 | import net.minecraft.world.entity.player.Player;
|
22 | 26 | import net.minecraft.world.item.ItemStack;
|
23 | 27 | import net.minecraft.world.level.Level;
|
24 | 28 | import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate.StructureBlockInfo;
|
25 | 29 | import net.minecraft.world.phys.Vec3;
|
26 |
| - |
27 | 30 | import net.minecraftforge.network.PacketDistributor;
|
28 | 31 |
|
29 | 32 | public class ContraptionControlsMovingInteraction extends MovingInteractionBehaviour {
|
@@ -98,6 +101,24 @@ public boolean handlePlayerInteraction(Player player, InteractionHand activeHand
|
98 | 101 | AllSoundEvents.CONTROLLER_CLICK.play(player.level(), null,
|
99 | 102 | BlockPos.containing(contraptionEntity.toGlobalVector(Vec3.atCenterOf(localPos), 1)), 1, disable ? 0.8f : 1.5f);
|
100 | 103 |
|
| 104 | + if (!(contraptionEntity instanceof CarriageContraptionEntity cce)) |
| 105 | + return true; |
| 106 | + if (!filter.is(ItemTags.DOORS)) |
| 107 | + return true; |
| 108 | + |
| 109 | + // Special case: Doors are toggled on all carriages of a train |
| 110 | + Carriage carriage = cce.getCarriage(); |
| 111 | + Train train = carriage.train; |
| 112 | + for (Carriage c : train.carriages) { |
| 113 | + CarriageContraptionEntity anyAvailableEntity = c.anyAvailableEntity(); |
| 114 | + if (anyAvailableEntity == null) |
| 115 | + continue; |
| 116 | + Contraption cpt = anyAvailableEntity.getContraption(); |
| 117 | + cpt.setActorsActive(filter, !disable); |
| 118 | + ContraptionControlsBlockEntity.sendStatus(player, filter, !disable); |
| 119 | + send(anyAvailableEntity, filter, disable); |
| 120 | + } |
| 121 | + |
101 | 122 | return true;
|
102 | 123 | }
|
103 | 124 |
|
|
0 commit comments