mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-14 23:57:35 +00:00
Add null checks to fix NPEs caused by custom head blocks from Polymer
This commit is contained in:
parent
77fa37ff82
commit
877c941e1f
4 changed files with 14 additions and 5 deletions
|
|
@ -141,7 +141,7 @@ public class SkullPlayerEntity extends PlayerEntity {
|
||||||
float rotation;
|
float rotation;
|
||||||
|
|
||||||
BlockState blockState = skull.getBlockState();
|
BlockState blockState = skull.getBlockState();
|
||||||
if (blockState.block() instanceof WallSkullBlock) {
|
if (blockState != null && blockState.block() instanceof WallSkullBlock) {
|
||||||
y += 0.25f;
|
y += 0.25f;
|
||||||
Direction direction = blockState.getValue(Properties.HORIZONTAL_FACING);
|
Direction direction = blockState.getValue(Properties.HORIZONTAL_FACING);
|
||||||
rotation = WallSkullBlock.getDegrees(direction);
|
rotation = WallSkullBlock.getDegrees(direction);
|
||||||
|
|
@ -152,7 +152,7 @@ public class SkullPlayerEntity extends PlayerEntity {
|
||||||
case EAST -> x -= 0.24f;
|
case EAST -> x -= 0.24f;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
rotation = (180f + (blockState.getValue(Properties.ROTATION_16) * 22.5f)) % 360;
|
rotation = (180f + (blockState != null ? blockState.getValue(Properties.ROTATION_16) * 22.5f : 0.0f)) % 360;
|
||||||
}
|
}
|
||||||
|
|
||||||
moveAbsolute(Vector3f.from(x, y, z), rotation, 0, rotation, true, true);
|
moveAbsolute(Vector3f.from(x, y, z), rotation, 0, rotation, true, true);
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,7 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
import org.cloudburstmc.math.vector.Vector3i;
|
import org.cloudburstmc.math.vector.Vector3i;
|
||||||
import org.geysermc.erosion.util.BlockPositionIterator;
|
import org.geysermc.erosion.util.BlockPositionIterator;
|
||||||
|
import org.geysermc.geyser.level.block.type.Block;
|
||||||
import org.geysermc.geyser.level.block.type.BlockState;
|
import org.geysermc.geyser.level.block.type.BlockState;
|
||||||
import org.geysermc.geyser.session.GeyserSession;
|
import org.geysermc.geyser.session.GeyserSession;
|
||||||
import org.geysermc.mcprotocollib.protocol.data.game.entity.player.GameMode;
|
import org.geysermc.mcprotocollib.protocol.data.game.entity.player.GameMode;
|
||||||
|
|
@ -64,7 +65,11 @@ public abstract class WorldManager {
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public BlockState blockAt(GeyserSession session, int x, int y, int z) {
|
public BlockState blockAt(GeyserSession session, int x, int y, int z) {
|
||||||
return BlockState.of(this.getBlockAt(session, x, y, z));
|
BlockState block = BlockState.of(this.getBlockAt(session, x, y, z));
|
||||||
|
if (block == null) {
|
||||||
|
return BlockState.of(Block.JAVA_AIR_ID);
|
||||||
|
}
|
||||||
|
return block;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -254,10 +254,10 @@ public class SkullCache {
|
||||||
CustomSkull customSkull = BlockRegistries.CUSTOM_SKULLS.get(skinHash);
|
CustomSkull customSkull = BlockRegistries.CUSTOM_SKULLS.get(skinHash);
|
||||||
if (customSkull != null) {
|
if (customSkull != null) {
|
||||||
CustomBlockState customBlockState;
|
CustomBlockState customBlockState;
|
||||||
if (blockState.block() instanceof WallSkullBlock) {
|
if (blockState != null && blockState.block() instanceof WallSkullBlock) {
|
||||||
customBlockState = customSkull.getWallBlockState(WallSkullBlock.getDegrees(blockState));
|
customBlockState = customSkull.getWallBlockState(WallSkullBlock.getDegrees(blockState));
|
||||||
} else {
|
} else {
|
||||||
customBlockState = customSkull.getFloorBlockState(blockState.getValue(Properties.ROTATION_16));
|
customBlockState = customSkull.getFloorBlockState(blockState != null ? blockState.getValue(Properties.ROTATION_16) : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
return session.getBlockMappings().getCustomBlockStateDefinitions().get(customBlockState);
|
return session.getBlockMappings().getCustomBlockStateDefinitions().get(customBlockState);
|
||||||
|
|
|
||||||
|
|
@ -53,6 +53,10 @@ public class SkullBlockEntityTranslator extends BlockEntityTranslator implements
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void translateTag(GeyserSession session, NbtMapBuilder bedrockNbt, NbtMap javaNbt, BlockState blockState) {
|
public void translateTag(GeyserSession session, NbtMapBuilder bedrockNbt, NbtMap javaNbt, BlockState blockState) {
|
||||||
|
if (blockState == null) {
|
||||||
|
bedrockNbt.putByte("SkullType", (byte) 0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
Integer rotation = blockState.getValue(Properties.ROTATION_16);
|
Integer rotation = blockState.getValue(Properties.ROTATION_16);
|
||||||
if (rotation != null) {
|
if (rotation != null) {
|
||||||
// Could be a wall skull block otherwise, which has rotation in its Bedrock state
|
// Could be a wall skull block otherwise, which has rotation in its Bedrock state
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue