ImmersiveMC

ImmersiveMC

2M Downloads

Group Together Server-Side Immersive Parts

hammy275 opened this issue ยท 2 comments

commented

ImmersiveHandler

To make room for an eventual API and just to keep all of the storage retrieval for all immersives from being forced to be written in one file, we're also going to refactor all the server-side parts of immersive handling. A new interface, ImmersiveHandler will exist, with these required methods:

HandlerStorage makeInventoryContents(ServerPlayer player, BlockPos pos): Given the player and block position, returns a HandlerStorage containing all data that needs to be transmitted to the client (including block position!).

HandlerStorage getEmptyHandler(): Gets an empty HandlerStorage to be used client side to call decode() on. After calling decode(), it's then passed to processStorageFromNetwork() as described below.

void swap(int slot, InteractionHand hand, BlockPos pos, ServerPlayer player, PlacementMode mode): Handles swapping the item between the player and the immersive they're interacting with. Will all be pre-existing code moved out of Swap.java.

boolean usesWorldStorage(): Whether this immersive uses world storage or not, since that info is needed.

boolean isValidBlock(BlockPos blockPos, BlockState blockState, BlockEntity blockEntity, Level level): Whether a given block matches with this immersive. This will replace ImmersiveCheckers and CheckerFunction, as everything in there should just use this function on these objects instead.

boolean enabledInServerConfig(): Whether this immersive is enabled in the config using server-side logic (check ActiveConfig.FILE).

ResourceLocation getId(): A unique ID that identifies a given ImmersiveHandler implementation. This is used so when decoding, the correct decoding implementation is used.

As one would imagine, the above replaces Swap, ImmersiveCheckers and CheckerFunction.

HandlerStorage

Additionally, the interface HandlerStorage will also be made, containing the following:

void encode(FriendlyByteBuf buffer): Writes the contents of this storage into a buffer.

void decode(FriendlyByteBuf buffer): Reads the contents of a buffer into this storage.

Other Changes

  • AbstractImmersive will have its processStorageFromNetwork function replaced to take a HandlerStorage instead. This should be the only way data makes it to a client immersive now!

All of these objects will be kept in common/immersive/.

commented

Ended up finding and fixing a regression from 1.5.0 Alpha 1 where we don't grab the config value for the chiseled bookshelf, so it always remains disabled.

commented

This is now done!