diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionCollider.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionCollider.java index f4f86d75f..0343a8e6b 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionCollider.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionCollider.java @@ -28,7 +28,6 @@ import net.minecraft.block.BlockState; import net.minecraft.block.CocoaBlock; import net.minecraft.client.entity.player.ClientPlayerEntity; import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityType; import net.minecraft.entity.item.ItemEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.ServerPlayerEntity; @@ -74,12 +73,21 @@ public class ContraptionCollider { Vec3d centerOfBlock = VecHelper.CENTER_OF_ORIGIN; ContraptionRotationState rotation = null; - for (Entity entity : world.getEntitiesWithinAABB((EntityType) null, bounds.grow(2) - .expand(0, 32, 0), contraptionEntity::canCollideWith)) { + // After death, multiple refs to the client player may show up in the area + boolean skipClientPlayer = false; + + List entitiesWithinAABB = world.getEntitiesWithinAABB(Entity.class, bounds.grow(2) + .expand(0, 32, 0), contraptionEntity::canCollideWith); + for (Entity entity : entitiesWithinAABB) { PlayerType playerType = getPlayerType(entity); if (playerType == PlayerType.REMOTE) continue; + if (playerType == PlayerType.CLIENT) + if (skipClientPlayer) + continue; + else + skipClientPlayer = true; // Init matrix if (rotation == null) @@ -130,7 +138,7 @@ public class ContraptionCollider { .forEach(shape -> shape.toBoundingBoxList() .forEach(bbs::add)); - boolean doHorizontalPass = rotation.hasVerticalRotation(); + boolean doHorizontalPass = !rotation.hasVerticalRotation(); for (boolean horizontalPass : Iterate.trueAndFalse) { for (AxisAlignedBB bb : bbs) { diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionHandler.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionHandler.java index 47b43ae4a..21664ce2e 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionHandler.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionHandler.java @@ -1,9 +1,11 @@ package com.simibubi.create.content.contraptions.components.structureMovement; import java.lang.ref.WeakReference; -import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; import java.util.Iterator; import java.util.List; +import java.util.Map; import com.simibubi.create.foundation.utility.VecHelper; import com.simibubi.create.foundation.utility.WorldAttached; @@ -21,23 +23,24 @@ public class ContraptionHandler { /* Global map of loaded contraptions */ - public static WorldAttached>> loadedContraptions; + public static WorldAttached>> loadedContraptions; static WorldAttached> queuedAdditions; static { - loadedContraptions = new WorldAttached<>(ArrayList::new); + loadedContraptions = new WorldAttached<>(HashMap::new); queuedAdditions = new WorldAttached<>(() -> ObjectLists.synchronize(new ObjectArrayList<>())); } public static void tick(World world) { - List> list = loadedContraptions.get(world); + Map> map = loadedContraptions.get(world); List queued = queuedAdditions.get(world); for (AbstractContraptionEntity contraptionEntity : queued) - list.add(new WeakReference<>(contraptionEntity)); + map.put(contraptionEntity.getEntityId(), new WeakReference<>(contraptionEntity)); queued.clear(); - for (Iterator> iterator = list.iterator(); iterator.hasNext();) { + Collection> values = map.values(); + for (Iterator> iterator = values.iterator(); iterator.hasNext();) { WeakReference weakReference = iterator.next(); AbstractContraptionEntity contraptionEntity = weakReference.get(); if (contraptionEntity == null || !contraptionEntity.isAlive()) {