Skip to content

Commit c5fb66a

Browse files
committed
Please exit on the left
- Contraption controls with a door as their target now affect all carriages of a train #8289
1 parent ad1655a commit c5fb66a

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/main/java/com/simibubi/create/content/contraptions/actors/contraptionControls/ContraptionControlsMovingInteraction.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,18 @@
1515
import com.simibubi.create.content.contraptions.behaviour.MovementContext;
1616
import com.simibubi.create.content.contraptions.elevator.ElevatorContraption;
1717
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;
1821

1922
import net.minecraft.core.BlockPos;
23+
import net.minecraft.tags.ItemTags;
2024
import net.minecraft.world.InteractionHand;
2125
import net.minecraft.world.entity.player.Player;
2226
import net.minecraft.world.item.ItemStack;
2327
import net.minecraft.world.level.Level;
2428
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate.StructureBlockInfo;
2529
import net.minecraft.world.phys.Vec3;
26-
2730
import net.minecraftforge.network.PacketDistributor;
2831

2932
public class ContraptionControlsMovingInteraction extends MovingInteractionBehaviour {
@@ -98,6 +101,24 @@ public boolean handlePlayerInteraction(Player player, InteractionHand activeHand
98101
AllSoundEvents.CONTROLLER_CLICK.play(player.level(), null,
99102
BlockPos.containing(contraptionEntity.toGlobalVector(Vec3.atCenterOf(localPos), 1)), 1, disable ? 0.8f : 1.5f);
100103

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+
101122
return true;
102123
}
103124

0 commit comments

Comments
 (0)