Skip to content

Commit

Permalink
saver casting (#10630)
Browse files Browse the repository at this point in the history
Don't cast without double checking to prevent crash with mods that do weird stuff
Fix not sitting
  • Loading branch information
Raycoms committed Feb 2, 2025
1 parent 36758c5 commit 9684391
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,29 +165,36 @@ public BlockState updateShape(
return super.updateShape(state, dir, neighbourState, level, pos, neighbourPos);
}

final BlockEntity here = level.getBlockEntity(pos);
if (!(here instanceof TileEntityRack hereRack))
{
return super.updateShape(state, dir, neighbourState, level, pos, neighbourPos);
}

if (neighbourState.getBlock() != this)
{
// Reset to single
if (state.getValue(VARIANT).isDoubleVariant() && pos.relative(state.getValue(FACING)).equals(neighbourPos))
{
return state.setValue(VARIANT, ((TileEntityRack) level.getBlockEntity(pos)).isEmpty() ? RackType.EMPTY : RackType.FULL);
return state.setValue(VARIANT, hereRack.isEmpty() ? RackType.EMPTY : RackType.FULL);
}

return super.updateShape(state, dir, neighbourState, level, pos, neighbourPos);
}


// Connect two
if (!state.getValue(VARIANT).isDoubleVariant() && !neighbourState.getValue(VARIANT).isDoubleVariant())
{
final BlockEntity here = level.getBlockEntity(pos);

final BlockEntity neighbour = level.getBlockEntity(neighbourPos);

if (!(here instanceof TileEntityRack) || !(neighbour instanceof TileEntityRack))
if (!(neighbour instanceof TileEntityRack neighborRack))
{
return super.updateShape(state, dir, neighbourState, level, pos, neighbourPos);
}

boolean isEmpty = ((TileEntityRack) here).isEmpty() && ((TileEntityRack) neighbour).isEmpty();
boolean isEmpty = hereRack.isEmpty() && neighborRack.isEmpty();

level.setBlock(neighbourPos,
neighbourState.setValue(FACING, BY_NORMAL.get(neighbourPos.subtract(pos).asLong()).getOpposite()).setValue(VARIANT, RackType.NO_RENDER),
Expand All @@ -201,7 +208,7 @@ public BlockState updateShape(
{
if (!neighbourState.getValue(FACING).equals(state.getValue(FACING).getOpposite()) || !neighbourState.getValue(VARIANT).isDoubleVariant())
{
return state.setValue(VARIANT, ((TileEntityRack) level.getBlockEntity(pos)).isEmpty() ? RackType.EMPTY : RackType.FULL);
return state.setValue(VARIANT, hereRack.isEmpty() ? RackType.EMPTY : RackType.FULL);
}

if (neighbourState.getValue(VARIANT) != RackType.NO_RENDER && state.getValue(VARIANT) != RackType.NO_RENDER)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,11 @@ public static void sitDown(final BlockPos pos, final Mob entity, final int maxLi
minY = 0;
}

entity.getNavigation().stop();
sittingEntity.setPos(pos.getX() + 0.5, (pos.getY() + minY) - entity.getBbHeight() / 2, pos.getZ() + 0.5);
sittingEntity.setMaxLifeTime(maxLifeTime);
sittingEntity.setSittingPos(pos);
entity.level.addFreshEntity(sittingEntity);
entity.startRiding(sittingEntity);
entity.getNavigation().stop();
}
}

0 comments on commit 9684391

Please sign in to comment.