Skip to content

Conversation

@dmchurch
Copy link

@dmchurch dmchurch commented Apr 3, 2025

This adds a new integer property Slot to the BlockPos class, with the following behavior:

  • Defaults to -1, defined as the constant BlockPos.SlotDontCare
  • pos.Equals(other) now checks that Slot properties match
  • pos.GetHashCode() includes the Slot value in the hash
  • Any mutator method (Set, West, etc) will reset the Slot property to SlotDontCare
  • Directly changing any of the BlockPos position fields from external code (by any value from -15..15) will cause the Slot property to self-reset to SlotDontCare
  • Copy and CopyAndCorrectDimension will copy the Slot value
  • The indexer signature now treats index 4 as the Slot property
  • Two new slot-aware constructor signatures: BlockPos(int x, int y, int z, int dim, int slot) and BlockPos(Vec3i vec, int dim, int slot)
  • One new mutator: public BlockPos SetSlot(int slot)
  • Protobuf serialization serializes the Slot property as tag 4, but only if it is not currently set to the default SlotDontCare
  • Byte-serialization (ToBytes() and CreateFromBytes()) do not preserve the slot value (only x/y/z/dimension) as those methods are only used for particles, which don't need to know about slots
  • ToString() includes the slot value in the output if the value is not SlotDontCare

This should have no impact on the game at present, as there isn't any code that reads or writes the Slot property; all BlockPos instances will grow by 4 bytes in size, but that seems incredibly unlikely to change anything.

Uses position-hashing to ensure that any direct public modification of
BlockPos fields will result in the `Slot` property resetting itself to
the default value of `SlotDontCare`, which will cause it to be omitted
from the protobuf-serialized form due to the DefaultValue attribute.
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