Fixed crash when disguising as certain types of blocks

This commit is contained in:
Sollace 2020-10-10 16:26:21 +02:00
parent 5c2e156392
commit f14ab56d54
3 changed files with 14 additions and 16 deletions

View file

@ -73,14 +73,14 @@ public class EntityBehaviour<T extends Entity> {
return Optional.empty(); return Optional.empty();
} }
float h = entity.getHeight() - 0.1F; float h = Math.max(0.001F, entity.getHeight() - 0.1F);
float w = entity.getWidth(); float w = Math.max(0.001F, entity.getWidth());
if (current.isPresent() && h == current.get().height && w == current.get().width) { if (current.isPresent() && h == current.get().height && w == current.get().width) {
return current; return current;
} }
return Optional.of(EntityDimensions.changing(entity.getHeight() - 0.1F, entity.getWidth())); return Optional.of(EntityDimensions.changing(h, w));
} }
public void copyBaseAttributes(LivingEntity from, Entity to) { public void copyBaseAttributes(LivingEntity from, Entity to) {

View file

@ -24,27 +24,17 @@ import net.minecraft.state.property.Properties;
import net.minecraft.tag.BlockTags; import net.minecraft.tag.BlockTags;
import net.minecraft.util.Tickable; import net.minecraft.util.Tickable;
import net.minecraft.util.math.Direction; import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Direction.Axis;
import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3d;
import net.minecraft.util.shape.VoxelShape;
public class FallingBlockBehaviour extends EntityBehaviour<FallingBlockEntity> { public class FallingBlockBehaviour extends EntityBehaviour<FallingBlockEntity> {
private static final Vec3d UP = Vec3d.of(Direction.UP.getVector()); private static final Vec3d UP = Vec3d.of(Direction.UP.getVector());
// private static final Optional<EntityDimensions> FULL_BLOCK = Optional.of(EntityDimensions.changing(0.6F, 0.9F)); private static final Optional<EntityDimensions> FULL_BLOCK = Optional.of(EntityDimensions.changing(0.6F, 0.9F));
@Override @Override
public Optional<EntityDimensions> getDimensions(FallingBlockEntity entity, Optional<EntityDimensions> current) { public Optional<EntityDimensions> getDimensions(FallingBlockEntity entity, Optional<EntityDimensions> current) {
return FULL_BLOCK;
VoxelShape shape = entity.getBlockState().getCollisionShape(entity.world, entity.getBlockPos());
float height = (float)shape.getMax(Axis.Y);
if (!current.isPresent() || current.get().height != height) {
return Optional.of(EntityDimensions.changing(0.6F, height));
}
return current;
} }
@Override @Override

View file

@ -4,6 +4,7 @@ import java.util.Optional;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import com.minelittlepony.unicopia.Unicopia;
import com.minelittlepony.unicopia.ability.magic.Spell; import com.minelittlepony.unicopia.ability.magic.Spell;
import net.minecraft.entity.EntityDimensions; import net.minecraft.entity.EntityDimensions;
@ -48,9 +49,16 @@ public final class PlayerDimensions {
flyingDimensions = EntityDimensions.changing(dimensions.width, dimensions.height / 2); flyingDimensions = EntityDimensions.changing(dimensions.width, dimensions.height / 2);
} }
return getPredicate() dimensions = getPredicate()
.flatMap(e -> e.getTargetDimensions(pony)) .flatMap(e -> e.getTargetDimensions(pony))
.orElseGet(() -> physics.isFlyingSurvival ? flyingDimensions : defaultDimensions); .orElseGet(() -> physics.isFlyingSurvival ? flyingDimensions : defaultDimensions);
if (dimensions.height < 0 || dimensions.width < 0) {
Unicopia.LOGGER.warn("Dim out was negative! Restoring original");
return defaultDimensions;
}
return dimensions;
} }
private float calculateTargetEyeHeight() { private float calculateTargetEyeHeight() {