Skip to content

Conversation

tal5
Copy link
Member

@tal5 tal5 commented Jul 29, 2025

Fixes several showfake-related issues on Discord (1, 2, 3, 4).

Changes

  • PacketHandlers now throw Throwable instead of Exception (for MethodHandles).
  • Cleaned up FakeBlockHelper's reflection (MethodHandles, direct field name instead of first type in a few places, etc.).
  • FakeBlockHelper now has a Map<Material, BlockEntityType<?>> MATERIAL_BLOCK_ENTITY_TYPES, for faking block entities.
  • In general cleaned up some naming to be clearer, and added comments to explain the logic where needed.
  • Replaced some direct bit shifts / other operations with Mojang's equivalent methods, makes it a lot clearer what's actually going on imo (and for seeing which ones are the same and which ones are different at a glance).
  • Removed a redundant parameter from FakeBlockHelper#copyPacketPaperPatch.
  • handleMapChunkPacket now takes in the FakeBlock.FakeBlockMap, for some faster lookups.
  • handleMapChunkPacket now throws instead of having everything in a try.
  • Removed some seemingly redundant copying in handleMapChunkPacket, like copying the chunk packet data and block entities list separately - the entire packet is being copied, so the chunk data and block entities within it are already copied.
  • The initial block entities loop in handleMapChunkPacket now just removes all block entities that are on the same block as a fake block, to be replaced later.
  • handleMapChunkPacket now keeps track of light data as well, and modifies it for relevant blocks to match surrounding light levels.
  • Removed the PALETTEDCONTAINER_CTOR reflection, as the remapping issue seems to be fixed now.
  • If the fake material is of a block entity, it now creates a new one and puts it into the packet's block entity list.
  • If needed (I.e. the block isn't solid, etc.), it now uses the new FakeBlockHelper#getEstimatedLightLevel to estimate a fake block's light level and apply it to the packet's light data.
  • Split up the packet handlers in FakeBlocksPacketHandlers, and cleaned them up a little.
  • Fixed weird copying in processSectionBlocksUpdatePacket - instead of copying the entire packet, then copying the content arrays, it now copies just the block states array, modifies it, and constructors a new section blocks update packet directly; it also uses MethodHandles now.

Additions

  • FakeBlockHelper#getEstimatedLightLevel - estimates a block's light level by trying to get on block in each direction around the source block, and:
    1. Getting it from the original light data for the section the source block is in.
    2. Getting it from different sections' light data in the same chunk
    3. Making a list of blocks to lookup light data in (all cached by section to minimize amount of lighting data grabs), that's only checked after it tries every possible way to check within the packet's data.
    4. Short-circuiting if it finds 15 (max light level).
  • A couple of util methods on FakeBlockHelper to help with the light data estimation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant