mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-12-15 20:13:41 +01:00
Collision pls
- Fixed inconsistent collision response to players respawned from near a contraption - Fixed an inverted condition from the refactor
This commit is contained in:
parent
e5c4b31458
commit
1961f9afdc
2 changed files with 21 additions and 10 deletions
|
@ -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<Entity> 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) {
|
||||
|
|
|
@ -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<List<WeakReference<AbstractContraptionEntity>>> loadedContraptions;
|
||||
public static WorldAttached<Map<Integer, WeakReference<AbstractContraptionEntity>>> loadedContraptions;
|
||||
static WorldAttached<List<AbstractContraptionEntity>> 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<WeakReference<AbstractContraptionEntity>> list = loadedContraptions.get(world);
|
||||
Map<Integer, WeakReference<AbstractContraptionEntity>> map = loadedContraptions.get(world);
|
||||
List<AbstractContraptionEntity> queued = queuedAdditions.get(world);
|
||||
|
||||
for (AbstractContraptionEntity contraptionEntity : queued)
|
||||
list.add(new WeakReference<>(contraptionEntity));
|
||||
map.put(contraptionEntity.getEntityId(), new WeakReference<>(contraptionEntity));
|
||||
queued.clear();
|
||||
|
||||
for (Iterator<WeakReference<AbstractContraptionEntity>> iterator = list.iterator(); iterator.hasNext();) {
|
||||
Collection<WeakReference<AbstractContraptionEntity>> values = map.values();
|
||||
for (Iterator<WeakReference<AbstractContraptionEntity>> iterator = values.iterator(); iterator.hasNext();) {
|
||||
WeakReference<AbstractContraptionEntity> weakReference = iterator.next();
|
||||
AbstractContraptionEntity contraptionEntity = weakReference.get();
|
||||
if (contraptionEntity == null || !contraptionEntity.isAlive()) {
|
||||
|
|
Loading…
Reference in a new issue