Telekinetics

- Fixed Movement Behaviours not resetting state when minecart contraptions are picked up
This commit is contained in:
simibubi 2022-09-22 19:00:26 +02:00
parent 59452a44ac
commit d117637df1

View File

@ -5,12 +5,17 @@ import java.util.List;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import org.apache.commons.lang3.tuple.MutablePair;
import com.google.common.io.ByteArrayDataOutput; import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams; import com.google.common.io.ByteStreams;
import com.simibubi.create.AllItems; 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.deployer.DeployerFakePlayer;
import com.simibubi.create.content.contraptions.components.structureMovement.AbstractContraptionEntity; 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.Contraption;
import com.simibubi.create.content.contraptions.components.structureMovement.MovementContext;
import com.simibubi.create.content.contraptions.components.structureMovement.OrientedContraptionEntity; import com.simibubi.create.content.contraptions.components.structureMovement.OrientedContraptionEntity;
import com.simibubi.create.foundation.advancement.AllAdvancements; import com.simibubi.create.foundation.advancement.AllAdvancements;
import com.simibubi.create.foundation.config.ContraptionMovementSetting; 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.DispenserBlock;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.RailShape; 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.minecraft.world.level.material.Material;
import net.minecraftforge.event.entity.player.PlayerInteractEvent; import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.eventbus.api.SubscribeEvent;
@ -218,11 +224,13 @@ public class MinecartContraptionItem extends Item {
List<Entity> passengers = cart.getPassengers(); List<Entity> passengers = cart.getPassengers();
if (passengers.isEmpty() || !(passengers.get(0) instanceof OrientedContraptionEntity)) if (passengers.isEmpty() || !(passengers.get(0) instanceof OrientedContraptionEntity))
return; 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") player.displayClientMessage(Lang.translateDirect("contraption.minecart_contraption_illegal_pickup")
.withStyle(ChatFormatting.RED), true); .withStyle(ChatFormatting.RED), true);
return; return;
} }
@ -232,7 +240,13 @@ public class MinecartContraptionItem extends Item {
return; return;
} }
ItemStack generatedStack = create(type, contraption).setHoverName(entity.getCustomName()); contraption.stop(event.getWorld());
for (MutablePair<StructureBlockInfo, MovementContext> 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 { try {
ByteArrayDataOutput dataOutput = ByteStreams.newDataOutput(); ByteArrayDataOutput dataOutput = ByteStreams.newDataOutput();
@ -249,13 +263,13 @@ public class MinecartContraptionItem extends Item {
return; return;
} }
if (contraption.getContraption() if (contraption.getBlocks()
.getBlocks()
.size() > 200) .size() > 200)
AllAdvancements.CART_PICKUP.awardTo(player); AllAdvancements.CART_PICKUP.awardTo(player);
player.getInventory().placeItemBackInInventory(generatedStack); player.getInventory()
contraption.discard(); .placeItemBackInInventory(generatedStack);
oce.discard();
entity.discard(); entity.discard();
event.setCancellationResult(InteractionResult.SUCCESS); event.setCancellationResult(InteractionResult.SUCCESS);
event.setCanceled(true); event.setCanceled(true);