mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-09-03 19:07:56 +00:00
Merge branch 'mc-1.20.x' into mc-1.21.x
This commit is contained in:
@@ -14,6 +14,7 @@ import java.util.Map;
|
||||
*
|
||||
* @param <T> The type of object that this provider can provide details for.
|
||||
* @see DetailRegistry
|
||||
* @see dan200.computercraft.api.detail An overview of the detail system.
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface DetailProvider<T> {
|
||||
|
@@ -17,6 +17,7 @@ import java.util.Map;
|
||||
* also in this package.
|
||||
*
|
||||
* @param <T> The type of object that this registry provides details for.
|
||||
* @see dan200.computercraft.api.detail An overview of the detail system.
|
||||
*/
|
||||
@ApiStatus.NonExtendable
|
||||
public interface DetailRegistry<T> {
|
||||
|
@@ -17,6 +17,9 @@ public class VanillaDetailRegistries {
|
||||
* <p>
|
||||
* This instance's {@link DetailRegistry#getBasicDetails(Object)} is thread safe (assuming the stack is immutable)
|
||||
* and may be called from the computer thread.
|
||||
* <p>
|
||||
* This does not have special handling for {@linkplain ItemStack#isEmpty() empty item stacks}, and so the returned
|
||||
* details will be an empty stack of air. Callers should generally check for empty stacks before calling this.
|
||||
*/
|
||||
public static final DetailRegistry<ItemStack> ITEM_STACK = ComputerCraftAPIService.get().getItemStackDetailRegistry();
|
||||
|
||||
|
@@ -0,0 +1,48 @@
|
||||
// SPDX-FileCopyrightText: 2025 The CC: Tweaked Developers
|
||||
//
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
/**
|
||||
* The detail system provides a standard way for mods to return descriptions of common game objects, such as blocks or
|
||||
* items, as well as registering additional detail to be included in those descriptions.
|
||||
* <p>
|
||||
* For instance, the built-in {@code turtle.getItemDetail()} method uses
|
||||
* {@linkplain dan200.computercraft.api.detail.VanillaDetailRegistries#ITEM_STACK in order to provide information about}
|
||||
* the selected item:
|
||||
*
|
||||
* <pre class="language language-lua">{@code
|
||||
* local item = turtle.getItemDetail(nil, true)
|
||||
* --[[
|
||||
* item = {
|
||||
* name = "minecraft:wheat",
|
||||
* displayName = "Wheat",
|
||||
* count = 1,
|
||||
* maxCount = 64,
|
||||
* tags = {},
|
||||
* }
|
||||
* ]]
|
||||
* }</pre>
|
||||
*
|
||||
* <h2>Built-in detail providers</h2>
|
||||
* While you can define your own detail providers (perhaps for types from your own mod), CC comes with several built-in
|
||||
* detail registries for vanilla and mod-loader objects:
|
||||
*
|
||||
* <ul>
|
||||
* <li>{@link dan200.computercraft.api.detail.VanillaDetailRegistries}, for vanilla objects</li>
|
||||
* <li>{@code dan200.computercraft.api.detail.ForgeDetailRegistries} for Forge-specific objects</li>
|
||||
* <li>{@code dan200.computercraft.api.detail.FabricDetailRegistries} for Fabric-specific objects</li>
|
||||
* </ul>
|
||||
*
|
||||
* <h2>Example: Returning details from methods</h2>
|
||||
* Here we define a {@code getHeldItem()} method for pocket computers which finds the currently held item of the player
|
||||
* and returns it to the user using {@link dan200.computercraft.api.detail.VanillaDetailRegistries#ITEM_STACK} and
|
||||
* {@link dan200.computercraft.api.detail.DetailRegistry#getDetails(java.lang.Object)}.
|
||||
*
|
||||
* {@snippet class=com.example.examplemod.ExamplePocketPeripheral region=details}
|
||||
*
|
||||
* <h2>Example: Registering custom detail registries</h2>
|
||||
* Here we define a new detail provider for items that includes the nutrition and saturation values in the returned object.
|
||||
*
|
||||
* {@snippet class=com.example.examplemod.ExampleMod region=details}
|
||||
*/
|
||||
package dan200.computercraft.api.detail;
|
Reference in New Issue
Block a user