diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/mounted/MinecartContraptionItem.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/mounted/MinecartContraptionItem.java index 50bd66123..794ed4858 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/mounted/MinecartContraptionItem.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/mounted/MinecartContraptionItem.java @@ -5,12 +5,17 @@ import java.util.List; import javax.annotation.Nullable; +import org.apache.commons.lang3.tuple.MutablePair; + import com.google.common.io.ByteArrayDataOutput; import com.google.common.io.ByteStreams; import com.simibubi.create.AllItems; +import com.simibubi.create.AllMovementBehaviours; +import com.simibubi.create.content.contraptions.components.actors.PortableStorageInterfaceMovement; import com.simibubi.create.content.contraptions.components.deployer.DeployerFakePlayer; import com.simibubi.create.content.contraptions.components.structureMovement.AbstractContraptionEntity; import com.simibubi.create.content.contraptions.components.structureMovement.Contraption; +import com.simibubi.create.content.contraptions.components.structureMovement.MovementContext; import com.simibubi.create.content.contraptions.components.structureMovement.OrientedContraptionEntity; import com.simibubi.create.foundation.advancement.AllAdvancements; import com.simibubi.create.foundation.config.ContraptionMovementSetting; @@ -41,6 +46,7 @@ import net.minecraft.world.level.block.BaseRailBlock; import net.minecraft.world.level.block.DispenserBlock; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.properties.RailShape; +import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate.StructureBlockInfo; import net.minecraft.world.level.material.Material; import net.minecraftforge.event.entity.player.PlayerInteractEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; @@ -218,11 +224,13 @@ public class MinecartContraptionItem extends Item { List passengers = cart.getPassengers(); if (passengers.isEmpty() || !(passengers.get(0) instanceof OrientedContraptionEntity)) return; - OrientedContraptionEntity contraption = (OrientedContraptionEntity) passengers.get(0); + OrientedContraptionEntity oce = (OrientedContraptionEntity) passengers.get(0); + Contraption contraption = oce.getContraption(); - if(ContraptionMovementSetting.isNoPickup(contraption.getContraption().getBlocks().values())) { + if (ContraptionMovementSetting.isNoPickup(contraption.getBlocks() + .values())) { player.displayClientMessage(Lang.translateDirect("contraption.minecart_contraption_illegal_pickup") - .withStyle(ChatFormatting.RED), true); + .withStyle(ChatFormatting.RED), true); return; } @@ -232,7 +240,13 @@ public class MinecartContraptionItem extends Item { return; } - ItemStack generatedStack = create(type, contraption).setHoverName(entity.getCustomName()); + contraption.stop(event.getWorld()); + + for (MutablePair pair : contraption.getActors()) + if (AllMovementBehaviours.getBehaviour(pair.left.state)instanceof PortableStorageInterfaceMovement psim) + psim.reset(pair.right); + + ItemStack generatedStack = create(type, oce).setHoverName(entity.getCustomName()); try { ByteArrayDataOutput dataOutput = ByteStreams.newDataOutput(); @@ -249,13 +263,13 @@ public class MinecartContraptionItem extends Item { return; } - if (contraption.getContraption() - .getBlocks() + if (contraption.getBlocks() .size() > 200) AllAdvancements.CART_PICKUP.awardTo(player); - - player.getInventory().placeItemBackInInventory(generatedStack); - contraption.discard(); + + player.getInventory() + .placeItemBackInInventory(generatedStack); + oce.discard(); entity.discard(); event.setCancellationResult(InteractionResult.SUCCESS); event.setCanceled(true);