added entity API pose and fixed #180
This commit is contained in:
1 parent
57d841ab10
commit
9da1f087fd
4 files changed
+107
-30
No files matched your search
@@ -4,6 +4,8 @@ import carpet.CarpetSettings;
|
||||
import carpet.fakes.WorldInterface;
|
||||
import carpet.utils.SpawnReporter;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.FenceGateBlock;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityCategory;
|
||||
import net.minecraft.entity.EntityData;
|
||||
@@ -13,6 +15,7 @@ import net.minecraft.entity.mob.MobEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.tag.BlockTags;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Box;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
@@ -45,30 +48,78 @@ public class SpawnHelperMixin
|
||||
// various configurations, but solid and 'passable' blocks, like air, water grass, etc.
|
||||
// checking if in the BB of the entity are only passable blocks is very cheap and covers most cases
|
||||
// in case something more complex happens - we default to full block collision check
|
||||
if (CarpetSettings.lagFreeSpawning)
|
||||
if (!CarpetSettings.lagFreeSpawning)
|
||||
{
|
||||
BlockPos.Mutable blockpos = new BlockPos.Mutable();
|
||||
int minX = MathHelper.floor(bb.x1);
|
||||
int maxX = MathHelper.ceil(bb.x2);
|
||||
int minY = MathHelper.floor(bb.y1);
|
||||
int maxY = MathHelper.ceil(bb.y2);
|
||||
int minZ = MathHelper.floor(bb.z1);
|
||||
int maxZ = MathHelper.ceil(bb.z2);
|
||||
for (int y = minY; y < maxY; y++)
|
||||
for (int x = minX; x < maxX; x++)
|
||||
for (int z = minZ; z < maxZ; z++)
|
||||
return world.doesNotCollide(bb);
|
||||
}
|
||||
int minX = MathHelper.floor(bb.x1);
|
||||
int minY = MathHelper.floor(bb.y1);
|
||||
int minZ = MathHelper.floor(bb.z1);
|
||||
int maxY = MathHelper.ceil(bb.y2)-1;
|
||||
BlockPos.Mutable blockpos = new BlockPos.Mutable();
|
||||
if (bb.getXLength() <= 1) // small mobs
|
||||
{
|
||||
for (int y=minY; y <= maxY; y++)
|
||||
{
|
||||
blockpos.set(minX,y,minZ);
|
||||
VoxelShape box = world.getBlockState(blockpos).getCollisionShape(world, blockpos);
|
||||
if (box != VoxelShapes.empty())
|
||||
{
|
||||
if (box == VoxelShapes.fullCube())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
blockpos.set(x, y, z);
|
||||
VoxelShape box = world.getBlockState(blockpos).getCollisionShape(world, blockpos);
|
||||
if ( box == VoxelShapes.empty())
|
||||
continue;
|
||||
if (Block.isShapeFullCube(box))
|
||||
return false;
|
||||
return world.doesNotCollide(bb);
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return world.doesNotCollide(bb);
|
||||
// this code is only applied for mobs larger than 1 block in footprint
|
||||
int maxX = MathHelper.ceil(bb.x2)-1;
|
||||
int maxZ = MathHelper.ceil(bb.z2)-1;
|
||||
for (int y = minY; y <= maxY; y++)
|
||||
for (int x = minX; x <= maxX; x++)
|
||||
for (int z = minZ; z <= maxZ; z++)
|
||||
{
|
||||
blockpos.set(x, y, z);
|
||||
VoxelShape box = world.getBlockState(blockpos).getCollisionShape(world, blockpos);
|
||||
if (box != VoxelShapes.empty())
|
||||
{
|
||||
if (box == VoxelShapes.fullCube())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return world.doesNotCollide(bb);
|
||||
}
|
||||
}
|
||||
}
|
||||
int min_below = minY - 1;
|
||||
// we need to check blocks below for extended hitbox and in that case call
|
||||
// only applies to 'large mobs', slimes, spiders, magmacubes, ghasts, etc.
|
||||
for (int x = minX; x <= maxX; x++)
|
||||
{
|
||||
for (int z = minZ; z <= maxZ; z++)
|
||||
{
|
||||
blockpos.set(x, min_below, z);
|
||||
BlockState state = world.getBlockState(blockpos);
|
||||
Block block = state.getBlock();
|
||||
if (
|
||||
block.matches(BlockTags.FENCES) ||
|
||||
block.matches(BlockTags.WALLS) ||
|
||||
((block instanceof FenceGateBlock) && !state.get(FenceGateBlock.OPEN))
|
||||
)
|
||||
{
|
||||
if (x == minX || x == maxX || z == minZ || z == maxZ) return world.doesNotCollide(bb);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Redirect(method = "spawnEntitiesInChunk", at = @At(
|
||||
|
||||
@@ -33,7 +33,6 @@ import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.predicate.entity.EntityPredicates;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
import net.minecraft.server.integrated.IntegratedServer;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.text.LiteralText;
|
||||
@@ -53,8 +52,8 @@ import java.util.Collection;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Predicate;
|
||||
@@ -274,6 +273,7 @@ public class EntityValue extends Value
|
||||
}
|
||||
return Value.NULL;
|
||||
});
|
||||
put("pose", (e, a) -> new StringValue(e.getPose().name().toLowerCase(Locale.ROOT)));
|
||||
put("sneaking", (e, a) -> e.isSneaking()?Value.TRUE:Value.FALSE);
|
||||
put("sprinting", (e, a) -> e.isSprinting()?Value.TRUE:Value.FALSE);
|
||||
put("swimming", (e, a) -> e.isSwimming()?Value.TRUE:Value.FALSE);
|
||||
|
||||
Reference in new issue
Block a user