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