Skip to content

getNormal: use each block's actual facing property instead of try/catch NORTH fallback (1.0.1 crash, 1.0.2 wrong normals) #4

Description

@jpmannon

Versions: CreateAeronauticsCopycatWing 1.0.2 (and 1.0.1), Minecraft 1.21.1, NeoForge 21.1.228, Create 6.0.10, Copycats+ 3.0.4, Create Aeronautics 1.2.1, Sable 1.2.2

Background: crash in 1.0.1

In 1.0.1, assembling any contraption containing a create:copycat_step crashed the server thread the moment the contraption entity initialized (and again every time the entity loaded):

java.lang.IllegalArgumentException: Cannot get property DirectionProperty{name=facing, clazz=class net.minecraft.core.Direction, values=[north, east, south, west, up, down]} as it does not exist in Block{create:copycat_step}
	at net.minecraft.world.level.block.state.StateHolder.getValue(StateHolder.java:97)
	at com.simibubi.create.content.decoration.copycat.CopycatStepBlock.sable$getNormal(CopycatStepBlock.java:519)
	at com.simibubi.create.content.contraptions.AbstractContraptionEntity.sable$buildProperties(AbstractContraptionEntity.java:3652)
	at com.simibubi.create.content.contraptions.AbstractContraptionEntity.handler$jcd000$sable$contraptionInitialize(AbstractContraptionEntity.java:3594)
	at com.simibubi.create.content.contraptions.AbstractContraptionEntity.tick(...)

Cause: MixinCopycatStepBlock.sable$getNormal reads BlockStateProperties.FACING (the 6-direction property), but CopycatStepBlock only has HORIZONTAL_FACING (4 directions). Same family as #1 (copycat_half_layer / axis) and #3 (copycat_slice / facing).

Remaining problem in 1.0.2

1.0.2 wraps the lookup in try/catch and returns Direction.NORTH on failure. That stops the crash, but for every block where the property lookup throws (step, slice, half layer, …) the wing normal is silently always NORTH regardless of how the block is placed, so lift is computed with the wrong orientation for 3 of 4 placements.

Suggested fix

Read the property each block actually has instead of relying on the exception fallback. For the step:

// CopycatStepBlock has HORIZONTAL_FACING + HALF
return blockState.getValue(BlockStateProperties.HORIZONTAL_FACING).getOpposite();

(or HALF-aware: return Direction.UP/DOWN based on BlockStateProperties.HALF if a vertical normal is more appropriate for step wings — author's call.)

I verified the HORIZONTAL_FACING variant in-game by patching the 1.0.1 jar: train contraptions with copycat steps assemble and run with no crash and orientation-dependent normals. Equivalent property fixes apply to the other copycat mixins touched in the 1.0.2 commit (slice, half layer, vertical step, etc. — each per its own state definition).

Thanks for the mod — happy to test a build.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions