Lootr Internals - LootrMinecraft/Lootr GitHub Wiki

Lootr consists of a number of individual pieces, regardless of which mod loader it uses.

Common Code

Config

Lootr has its own configuration. [In progress]

Blocks

Lootr creates several blocks that act as alternatives for vanilla blocks:

  1. Lootr Chest [Complete]
  2. Lootr Trapped Chest [Complete?]
  3. Lootr Barrel [Complete]
  4. Lootr Shulker Box [Complete?]
  5. Trophy [Complete?]

These are used as replacements for vanilla blocks when suitable.

Block Entities

Lootr creates several block entities for its alternate blocks:

  1. Lootr Chest Block Entity [Complete]
  2. Lootr Trapped Chest Block Entity [Complete]
  3. Lootr Barrel Block Entity [Complete]
  4. Lootr Shulker Box Block Entity [Complete]

Entities

Lootr creates one entity as an alternative to the vanilla minecart-with-chest:

  1. Lootr Minecart-with-Chest [Complete]

Events

Lootr uses a number of events to handle some replacement functionality.

Break Events

Break Events are intercepted and Lootr prevents its own containers from being destroyed unless the entity performing the break is sneaking.

When configured, all breaking is prevented unless the player doing so is sneaking while in creative mode.

[Required]

Entity Events

The EntityJoinedWorldEvent is used to capture information about vanilla minecarts-with-chest being spawned.

As this event can occur asynchronously during world generation, the information from these events is passed into the EntityTicker.

This event is canceled to prevent a vanilla minecart-with-chest from being spawned, where relevant.

[Complete]

Chunk Events

Chunk Events track whenever chunks are fully loaded, storing dimension and chunkpos values.

This information is stored in a synchronized fashion, allowing for the TileTicker to determine if a replacement should go ahead or not.

Note: As of 1.18, getBlockState and setBlock now cause up to 25 chunks to be loaded in a 5x5 area. Replacements are deferred until those chunks have been registered as loaded when fully generated to prevent the main thread from becoming blocked waiting on world generation.

[Complete]

Items

Lootr creates the following block items:

  • Lootr Chest Block Item [Complete]
  • Lootr Shulker Block Item [Complete]

These specific block items are used when rendering chests and trapped chests and shulker boxes in inventories and GUIs.

Networking

The following network packets are curated by Lootr:

  1. Close Cart
  2. Open Cart

These packets are specifically sent from the server to the client whenever a player opens a Lootr Minecart-with-Chest and ensures that they properly render with the correct color: gold for unopened, blue for opened.

[Complete]

Utility

Three sets of utility functions exist.

ChestUtil

The code in this section is used whenever a player interacts with a Lootr container.

This either handles containers being marked as unopened, or handles the actual functionality of containers being opened, including fetching the relevant menu for the specific player for the specific container.

In addition, this code handles refreshing and decaying containers.

[Complete]

StructureUtil

This code should be deprecated in favor of ConfiguredStructureFeature<?, ?> tags.

Currently it is used to determine whether the location of a container that is being replaced is within the confines of any structure.

[Required]

Data Storage

This code provides access to all of the ChestData instances, along with all scores, statistics, advancements, refreshing and decaying containers.

[Complete]

Server Code

Commands

Lootr creates the lootr command.

[Required]

Data

Lootr has three separate "types" of SavedData:

  1. Advancement data, which stores whether or not an advancement has been granted to a player for opening a specific chest.
  2. Ticking data, which is used both to store information about decaying chests, as well as storing information about refreshing chests.
  3. Chest data, which is used to store the data for each individual container.

Note: ChestData functions as follows:

  1. ChestData is created for each container based off of its Universally Unique Identifier (UUID).
  2. Each ChestData contains a correlative map consisting of a player's UUID, along with the SpecialChestInventory instance that contains whatever items the player has stored.

Note: ChestData uses subdirectories within the world's data folder:

  1. Subfolder data/lootr contains the ScoreData, AdvancementData, as well as the ticking and refreshing data.
  2. Subfolder data/lootr/X contains all directories relating to containers whose UUID start with the character X
  3. Subfolder data/lootr/X/XY contains all serialized ChestData files relating to containers whose UUID start with the characters XY.

This system ensures that the data folder is never filled and that the lootr subfolder will only ever contain a maximum of 46 (A through Z, 0 through 9) subdirectories. This should ensure that accessing Lootr's data never causes "overflow" or "only displaying first X entries" that some browser-based control panels use.

[Complete]

Entity Ticker

The Entity Ticker contains essential information to spawn Lootr Minecarts-with-Chest. This process takes place at the end of the server tick to ensure that crashes do not occur.

The Entity Ticker is synchronized to ensure thread safety.

[Complete]

Tile Ticker

The Tile Ticker contains essential information used to replace relevant containers with their Lootr equivalents.

The Tile Ticker is synchronzied to ensure thread safety, both in adding new entries, as well as when performing replacements. This synchronization ensures that world generation threads do not become blocked waiting on the main thread to process, and that the main thread does not become blocked waiting on world generation threads to process.

[Complete]

Mixins

Lootr for Forge for 1.18.2 uses the following mixins:

  1. MixinCatSitOnBlockGoal
  2. MixinLevel
  3. MixinLevelChunk

MixinCatSitOnBlockGoal causes cats to treat Lootr chests as they would a vanilla chest.

The other two mixins are specifically focus on the addBlockEntity method, and use the information provided to this method to populate the TileTicker.

[Complete]

Client Code

Block Entity Renderers

  1. Lootr Chest Block Entity Renderer [Complete]
  2. Lootr Shulker Box Block Entity Renderer [Complete]

Baked Models

  1. Lootr Barrel Baked Model [Complete]

Entity Renderers

  1. Lootr Minecart-with-Chest Renderer [Complete]

Item Renderers

  1. Lootr Chest Item Renderer [Complete]
  2. Lootr Shulker Box Item Renderer [Complete]
⚠️ **GitHub.com Fallback** ⚠️