mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-12-26 06:57:51 +01:00
Telekinetics
- Fixed Movement Behaviours not resetting state when minecart contraptions are picked up
This commit is contained in:
parent
59452a44ac
commit
d117637df1
1 changed files with 23 additions and 9 deletions
|
@ -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,9 +224,11 @@ public class MinecartContraptionItem extends Item {
|
|||
List<Entity> 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);
|
||||
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<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 {
|
||||
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);
|
||||
|
|
Loading…
Reference in a new issue