### Entity Render State Example Source: https://github.com/neoforged/.github/blob/main/primers/26.1/index.md Example of an `EntityRenderState` that holds a `BlockModelRenderState` for rendering. ```java // Entity example public class ExampleRenderState extends EntityRenderState { // Hold the render state. public final BlockModelRenderState exampleBlock = new BlockModelRenderState(); } ``` -------------------------------- ### Block Entity Render State Example Source: https://github.com/neoforged/.github/blob/main/primers/26.1/index.md Example of a `BlockEntityRenderState` that holds a `BlockModelRenderState` for rendering. ```java // BlockEntity example public class ExampleRenderState extends BlockEntityRenderState { // Hold the render state. public final BlockModelRenderState exampleBlock = new BlockModelRenderState(); } ``` -------------------------------- ### Entity Renderer Example Source: https://github.com/neoforged/.github/blob/main/primers/26.1/index.md Implementation of an `EntityRenderer` that updates and submits a block model. Requires `BlockDisplayContext` and `BlockModelResolver`. ```java public class ExampleRenderer extends EntityRenderer { // The display context for the entity renderer. public static final BlockDisplayContext BLOCK_DISPLAY_CONTEXT = BlockDisplayContext.create(); private final BlockModelResolver blockResolver; public ExampleRenderer(EntityRendererProvider.Context ctx) { super(ctx); // Get the model resolver. this.blockResolver = ctx.getBlockModelResolver(); } @Override public void extractRenderState(ExampleEntity entity, ExampleRenderState state, float partialTick) { super.extractRenderState(entity, state, partialTick); // Update the model state. this.blockResolver.update(state.exampleBlock, Blocks.DIRT.defaultBlockState(), BLOCK_DISPLAY_CONTEXT); } @Override public void submit(ExampleRenderState state, PoseStack pose, SubmitNodeCollector collector, CameraRenderState camera) { super.submit(state, pose, collector, camera); // Submit the model state for rendering. ``` -------------------------------- ### Register and Interact with World Clocks in Java Source: https://context7.com/neoforged/.github/llms.txt Register a WorldClock ResourceKey and ClockTimeMarker. Examples show how to read, manipulate, and query clock states on the server and client. ```java public static final ResourceKey MY_CLOCK = ResourceKey.create(Registries.WORLD_CLOCK, Identifier.fromNamespaceAndPath("examplemod", "my_clock")); ``` ```java public static final ResourceKey NOON_MARKER = ResourceKey.create(Registries.CLOCK_TIME_MARKER, Identifier.fromNamespaceAndPath("examplemod", "noon")); ``` ```java Holder.Reference clockRef = level.registryAccess().getOrThrow(MY_CLOCK); long ticks = level.clockManager().getTotalTicks(clockRef); ``` ```java ServerClockManager clockManager = serverLevel.clockManager(); clockManager.setTotalTicks(clockRef, 0L); // reset clockManager.addTicks(clockRef, 500L); // advance by 500 ticks clockManager.setPaused(clockRef, true); // pause ``` ```java boolean isNoon = clockManager.isAtTimeMarker(clockRef, NOON_MARKER); boolean skipped = clockManager.skipToTimeMarker(clockRef, NOON_MARKER); ``` ```java long overworldTime = level.getOverworldClockTime(); // equivalent to old getDayTime() ``` -------------------------------- ### Create PermissionCheck Source: https://context7.com/neoforged/.github/llms.txt Create a PermissionCheck instance, which is used to verify if a user meets specific permission requirements. This example requires a HasExamplePermission with a state of 1. ```java // Create a PermissionCheck for use in commands public static final PermissionCheck CHECK_STATE_ONE = new PermissionCheck.Require(new HasExamplePermission(1)); ``` -------------------------------- ### Configure Depth and Color Targets for Render Pipeline Source: https://github.com/neoforged/.github/blob/main/primers/26.1/index.md Example of building a `RenderPipeline` with custom depth stencil and color target states. Use `ColorTargetState` to define color writing masks and blending functions, and `DepthStencilState` to configure depth testing and writing. ```java public static final RenderPipeline EXAMPLE_PIPELINE = RenderPipeline.builder() .withLocation(ResourceLocation.fromNamespaceAndPath("examplemod", "pipeline/example")) .withVertexShader(ResourceLocation.fromNamespaceAndPath("examplemod", "example")) .withFragmentShader(ResourceLocation.fromNamespaceAndPath("examplemod", "example")) .withVertexFormat(DefaultVertexFormat.POSITION_TEX_COLOR, VertexFormat.Mode.QUADS) .withShaderDefine("ALPHA_CUTOUT", 0.5) .withSampler("Sampler0") .withUniform("ModelOffset", UniformType.VEC3) .withUniform("CustomUniform", UniformType.INT) .withPolygonMode(PolygonMode.FILL) .withCull(false) // Sets the color target when writing the buffer data. .withColorTargetState(new ColorTargetState( // Specifies the functions to use when blending two colors with alphas together. // Made up of the `SourceFactor` and `DestFactor`. // First two are for RGB, the last two are for alphas. // If the optional is empty, then blending is disabled. Optional.of(BlendFunction.TRANSLUCENT), // The mask determining what colors to write to the buffer. // Represented as a four bit value // 0001 - Write the red channel.. // 0010 - Write the green channel. // 0100 - Write the blue channel. // 1000 - Write the alpha channel. ColorTargetState.WRITE_RED | ColorTargetState.WRITE_GREEN | ColorTargetState.WRITE_BLUE | ColorTargetState.WRITE_ALPHA )) // Sets the depth stencil when writing the buffer data. .withDepthStencilState(new DepthStencilState( // Sets the depth test function to use when rendering objects at varying // distances from the camera. // Values: // - ALWAYS_PASS (GL_ALWAYS) // - LESS_THAN (GL_LESS) // - LESS_THAN_OR_EQUAL (GL_LEQUAL) // - EQUAL (GL_EQUAL) // - NOT_EQUAL (GL_NOTEQUAL) // - GREATER_THAN_OR_EQUAL (GL_GEQUAL) // - GREATER_THAN (GL_GREATER) // - NEVER_PASS (GL_NEVER) CompareOp.LESS_THAN_OR_EQUAL, // Whether to mask writing values to the depth buffer false, // The scale factor used to calculate the depth values for the polygon. 0f, // The unit offset used to calculate the depth values for the polygon. 0f )) .build() ; ``` -------------------------------- ### Registering a Custom RecipeSerializer Record Source: https://github.com/neoforged/.github/blob/main/primers/26.1/index.md Example of how to instantiate and register a new RecipeSerializer as a record, providing MapCodec and StreamCodec for serialization and deserialization. ```java public static final RecipeSerializer EXAMPLE_RECIPE = new RecipeSerializer<>( // The map codec for reading the recipe to/from disk. MapCodec.unit(INSTANCE), // The stream codec for reading the recipe to/from the network. StreamCodec.unit(INSTANCE) ); ``` -------------------------------- ### Block Entity Renderer Example Source: https://github.com/neoforged/.github/blob/main/primers/26.1/index.md Implementation of a `BlockEntityRenderer` that updates and submits a block model. Requires `BlockDisplayContext` and `BlockModelResolver`. ```java public class ExampleRenderer implements BlockEntityRenderer { // The display context for use in the block entity renderer. public static final BlockDisplayContext BLOCK_DISPLAY_CONTEXT = BlockDisplayContext.create(); private final BlockModelResolver blockResolver; public ExampleRenderer(BlockEntityRendererProvider.Context ctx) { super(ctx); // Get the model resolver. this.blockResolver = ctx.blockModelResolver(); } @Override public void extractRenderState(ExampleBlockEntity blockEntity, ExampleRenderState state, float partialTick, Vec3 cameraPosition, ModelFeatureRenderer.CrumblingOverlay breakProgress) { super.extractRenderState(blockEntity, state, partialTick, cameraPosition, breakProgress); // Update the model state. this.blockResolver.update(state.exampleBlock, Blocks.DIRT.defaultBlockState(), BLOCK_DISPLAY_CONTEXT); } @Override public void submit(ExampleRenderState state, PoseStack pose, SubmitNodeCollector collector, CameraRenderState camera) { super.submit(state, pose, collector, camera); // Submit the model state for rendering. state.exampleBlock.submit( // The current pose stack, pose, // The node collector. collector, // The light coordinates. state.lightCoords, // The overlay coordinates. OverlayTexture.NO_OVERLAY, // The outline color. 0 ); } } ``` -------------------------------- ### Java 25 Constructor and Deobfuscation Example Source: https://context7.com/neoforged/.github/llms.txt Demonstrates Java 25's ability to place statements before super() in constructors and the use of official deobfuscated names for vanilla classes like Identifier. ```java public class MyBlock extends Block { public MyBlock(Properties props) { // Statement before super() is now legal in Java 25 (JEP 447) var computed = computeDefaultProperties(props); super(computed); } } // Vanilla classes now use official deobfuscated names // Old (mapped): ResourceLocation -> now official: Identifier // net.minecraft.resources.ResourceLocation -> net.minecraft.resources.Identifier Identifier id = Identifier.fromNamespaceAndPath("examplemod", "my_block"); ``` -------------------------------- ### Implement Custom RecipeBuilder with ItemStackTemplate Source: https://github.com/neoforged/.github/blob/main/primers/26.1/index.md Example of how to implement a custom RecipeBuilder using ItemStackTemplate for the recipe result. This approach allows for custom recipes that do not export an Item. ```java public class ExampleRecipeBuilder implements RecipeBuilder { // The result of the recipe private final ItemStackTemplate result; public ExampleRecipeBuilder(ItemStackTemplate result) { this.result = result; } @Override public ResourceKey> defaultId() { // Get the default recipe id from the result return RecipeBuilder.getDefaultRecipeId(this.result); } // Implement everything else below // ... } ``` -------------------------------- ### Define Permission Data Object Source: https://context7.com/neoforged/.github/llms.txt Create a Permission object, which is a data holder. This example defines a permission for users with MODERATORS command level. ```java // Define a Permission (data object) public static final Permission COMMANDS_MODERATOR = new Permission.HasCommandLevel(PermissionLevel.MODERATORS); ``` -------------------------------- ### Implement LootItemFunction with MapCodec Source: https://github.com/neoforged/.github/blob/main/primers/26.1/index.md Example of implementing LootItemFunction by directly using a MapCodec for registry objects. The `codec()` method replaces `getType()` and returns the registry object. ```java public record NoopItemFunction() implements LootItemFunction { public static final NoopItemFunction INSTANCE = new NoopItemFunction(); // The map codec used as the registry object public static final MapCodec MAP_CODEC = MapCodec.unit(INSTANCE); // Replaces getType @Override public MapCodec codec() { // Return the registry object return MAP_CODEC; } } // Register the map codec to the appropriate registry Registry.register(BuiltInRegistries.LOOT_FUNCTION_TYPE, Identifier.fromNamespaceAndPath("examplemod", "noop"), NoopItemFunction.MAP_CODEC); ``` -------------------------------- ### Query Saved Data from Server Instance Source: https://github.com/neoforged/.github/blob/main/primers/26.1/index.md Access and compute SavedData instances from the MinecraftServer's data storage. Use computeIfAbsent to get an existing instance or create a new one if it doesn't exist. ```java // Given a MinecraftServer server ExampleData data = server.getDataStorage().computeIfAbsent(ExampleData.TYPE); ``` -------------------------------- ### Create Custom RenderSetup Source: https://context7.com/neoforged/.github/llms.txt Define a custom RenderSetup to replace the old CompositeState and RenderStateShard system. RenderSetup configures rendering pipelines, textures, and output targets. ```java // Creating a custom RenderSetup (replaces CompositeState + RenderStateShard) public static final RenderSetup EXAMPLE_SETUP = RenderSetup.builder( RenderPipelines.ITEM_ENTITY_TRANSLUCENT_CULL ) .withTexture( "Sampler0", Identifier.withDefaultNamespace("textures/entity/wolf/wolf_armor_crackiness_low.png"), () -> RenderSystem.getSamplerCache().getClampToEdge(FilterMode.NEAREST) ) .useLightmap() .useOverlay() .setOutputTarget(OutputTarget.MAIN_TARGET) .createRenderSetup(); ``` -------------------------------- ### Raid#getBannerComponentPatch Source: https://github.com/neoforged/.github/blob/main/primers/26.1/index.md Gets the components of the banner pattern. ```APIDOC ## Raid#getBannerComponentPatch ### Description Gets the components of the banner pattern. ### Method N/A (Method) ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ``` -------------------------------- ### MinecraftServer Methods Source: https://github.com/neoforged/.github/blob/main/primers/26.1/index.md Server-side functionalities including game rules and disk space warnings. ```APIDOC ## MinecraftServer ### Description Server-side functionalities including game rules and disk space warnings. ### Constants - `DEFAULT_GAME_RULES`: The supplied default game rules for a server. ### Methods - `warnOnLowDiskSpace()`: Sends a warning if the disk space is below 64 MiB. - `sendLowDiskSpaceWarning()`: Sends a warning for low disk space. - `shutdownStdout()`: Closes the stdout stream. ``` -------------------------------- ### BlockBehaviour$PostProcess Source: https://github.com/neoforged/.github/blob/main/primers/26.1/index.md An interface that gets the position to mark for post-processing. ```APIDOC ## BlockBehaviour$PostProcess ### Description An interface that gets the position to mark for post-processing. ### Method N/A (Interface) ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ``` -------------------------------- ### Raid#getOminousBannerTemplate Source: https://github.com/neoforged/.github/blob/main/primers/26.1/index.md Gets the stack template for the omnious banner. ```APIDOC ## Raid#getOminousBannerTemplate ### Description Gets the stack template for the omnious banner. ### Method N/A (Method) ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ``` -------------------------------- ### Using the ItemInstance Interface Source: https://github.com/neoforged/.github/blob/main/primers/26.1/index.md Shows how both ItemStack and ItemStackTemplate implement the ItemInstance interface, allowing for common access methods. Use ItemInstance when mutability does not matter. ```java // Both are item instances ItemInstance stack = new ItemStack(Items.APPLE); ItemInstance template = new ItemStackTemplate(Items.APPLE); // Get the holder or check something Holder item = stack.typeHolder(); template.is(Items.APPLE); // Get the number of items in the stack or template int stackCount = stack.count(); int templateCount = template.count(); // Get the component values Identifier stackModel = stack.get(DataComponents.ITEM_MODEL); Identifier templateModel = template.get(DataComponents.ITEM_MODEL); ``` -------------------------------- ### SlotRanges#MOB_INVENTORY_SLOT_OFFSET Source: https://github.com/neoforged/.github/blob/main/primers/26.1/index.md The start index of a mob's inventory. ```APIDOC ## SlotRanges#MOB_INVENTORY_SLOT_OFFSET ### Description The start index of a mob's inventory. ### Method N/A (Field) ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ``` -------------------------------- ### TreeGrower#getMinimumHeight Source: https://github.com/neoforged/.github/blob/main/primers/26.1/index.md If present, gets the base height of the trunk placer. ```APIDOC ## TreeGrower#getMinimumHeight ### Description If present, gets the base height of the trunk placer. ### Method N/A (Method) ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ``` -------------------------------- ### Create GpuSampler via SamplerCache Source: https://context7.com/neoforged/.github/llms.txt Use SamplerCache to create GpuSampler instances, which abstract OpenGL sampler state. This is the preferred method for obtaining samplers. ```java // Creating a GpuSampler via the SamplerCache (preferred) GpuSampler sampler = RenderSystem.getSamplerCache().getSampler( AddressMode.CLAMP_TO_EDGE, // U address mode AddressMode.CLAMP_TO_EDGE, // V address mode FilterMode.LINEAR, // Minification filter FilterMode.NEAREST, // Magnification filter false // Use max LOD of 1000 instead of 0 ); ``` -------------------------------- ### NeutralMob#getTargetUnchecked Source: https://github.com/neoforged/.github/blob/main/primers/26.1/index.md Gets the raw target without checking if its valid. ```APIDOC ## NeutralMob#getTargetUnchecked ### Description Gets the raw target without checking if its valid. ### Method N/A (Method) ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ``` -------------------------------- ### net.minecraft.client.gui.screens.worldselection.EditWorldScreen#conditionallyMakeBackupAndShowToast Source: https://github.com/neoforged/.github/blob/main/primers/26.1/index.md Creates a backup and shows a toast only if the provided boolean is true; otherwise, returns a false future. ```APIDOC ## EditWorldScreen#conditionallyMakeBackupAndShowToast ### Description Only makes the backup and shows a toast if the passed in `boolean` is true; otherwise, returns a `false` future. ### Method `conditionallyMakeBackupAndShowToast` ### Class net.minecraft.client.gui.screens.worldselection.EditWorldScreen ``` -------------------------------- ### Mob#getTargetUnchecked Source: https://github.com/neoforged/.github/blob/main/primers/26.1/index.md Gets the raw target without checking if its valid. ```APIDOC ## Mob#getTargetUnchecked ### Description Gets the raw target without checking if its valid. ### Method N/A (Method) ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ``` -------------------------------- ### Util#allOfEnumExcept Source: https://github.com/neoforged/.github/blob/main/primers/26.1/index.md Gets the set of all enums except the provided value. ```APIDOC ## Util#allOfEnumExcept ### Description Gets the set of all enums except the provided value. ### Method N/A (Static method or utility function) ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ``` -------------------------------- ### GameTestInstance Source: https://github.com/neoforged/.github/blob/main/primers/26.1/index.md Padding information for game tests. ```APIDOC ## GameTestInstance ### Description Padding information for game tests. ### Fields - `padding`: The number of blocks spaced around each game test. ``` -------------------------------- ### ARGB#gray Source: https://github.com/neoforged/.github/blob/main/primers/26.1/index.md Gets a grayscale color based on the given brightness. ```APIDOC ## ARGB#gray ### Description Gets a grayscale color based on the given brightness. ### Method N/A (Static method or utility function) ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ``` -------------------------------- ### AttributeType#toFloat Source: https://github.com/neoforged/.github/blob/main/primers/26.1/index.md Gets the attribute value as a `float`, or throws an exception if not defined. ```APIDOC ## AttributeType#toFloat ### Description Gets the attribute value as a `float`, or throws an exception if not defined. ### Method N/A (Method) ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ``` -------------------------------- ### net.minecraft.client.gui.components.debug.DebugEntryLookingAt#getHitResult Source: https://github.com/neoforged/.github/blob/main/primers/26.1/index.md Gets the hit result from the camera entity's perspective. ```APIDOC ## DebugEntryLookingAt#getHitResult ### Description Gets the hit result of the camera entity. ### Method `getHitResult` ### Class net.minecraft.client.gui.components.debug.DebugEntryLookingAt ``` -------------------------------- ### Implement makeBrain Method in Java Source: https://github.com/neoforged/.github/blob/main/primers/26.1/index.md This code demonstrates how to implement the `makeBrain` method in a `LivingEntity` subclass. It utilizes a pre-defined `Brain.Provider` to construct the entity's brain, deserializing any previously packed brain data. This method is crucial for initializing an entity's AI state upon loading. ```java @Override protected Brain.Provider makeBrain(Brain.Packed packedBrain) { // Make the brain, populating any previous memories return BRAIN_PROVIDER.makeBrain(this, packedBrain); } ``` -------------------------------- ### net.minecraft.data.BlockFamilies Source: https://github.com/neoforged/.github/blob/main/primers/26.1/index.md Defines block families, including a family for end stone variants and a method to get a family by its base block. ```APIDOC ## BlockFamilies ### Description Defines block families, including a family for end stone variants and a method to get a family by its base block. ### Class net.minecraft.data.BlockFamilies ### Constants/Methods - `END_STONE` - A family for end stone variants. - `getFamily` - Gets the family for the base block, when present. ``` -------------------------------- ### Define and Bake a FluidModel - Java Source: https://github.com/neoforged/.github/blob/main/primers/26.1/index.md Create an unbaked FluidModel with textures and tint, then bake it using a MaterialBaker. This model is then associated with a Fluid. ```java FluidModel.Unbaked exampleFluidModel = new FluidModel.Unbaked( // The texture for the still fluid. new Material( // The relative identifier for the texture. // Points to `assets/examplemod/textures/block/example_fluid_still.png` Identifier.fromNamespaceAndPath("examplemod", "block/example_fluid_still"), // When true, sets all faces using this texture key to // always have a transparent pixel. true ), // The texture for the flowing fluid. new Material(Identifier.fromNamespaceAndPath("examplemod", "block/example_fluid_flowing")), // If not null, the texture for the overlay when the side of the fluid is // occluded by a `HalfTransparentBlock` or `LeavesBlock`. null, // If not null, the tint source to apply to the fluid's texture when in // the world. null ); // Assume we have access to the `MaterialBaker` materials. FluidModel exampleBakedFluidModel = exampleFluidModel.bake( // The baker to grab the atlas sprites for the materials. materials, // A supplied debug name to properly report which models have // missing textures. () -> "examplemod:example_fluid_model" ); fluidModels.put( // The fluid the model should be used by. EXAMPLE_FLUID, // The baked fluid model. exampleBakedFluidModel ); fluidModels.put(EXAMPLE_FLUID_FLOWING, exampleBakedFluidModel); ``` -------------------------------- ### Bind Texture with Sampler in RenderPass Source: https://context7.com/neoforged/.github/llms.txt Demonstrates binding a texture with a specific sampler within a RenderPass. Ensure the RenderPass is properly managed using a try-with-resources statement. ```java // Binding texture with sampler in a RenderPass try (RenderPass pass = RenderSystem.getDevice().createCommandEncoder().createRenderPass( frameBuffer, OptionalInt.empty() )) { pass.bindTexture("Sampler0", myTextureView, sampler); // draw calls... } ``` -------------------------------- ### Create an ItemStackTemplate Source: https://github.com/neoforged/.github/blob/main/primers/26.1/index.md Demonstrates creating an immutable ItemStackTemplate with specific item, count, and data components. Use this when immutability is required, such as in advancements or recipes. ```java ItemStackTemplate apple = new ItemStackTemplate( // The item of the stack Items.APPLE.builtInRegistryHolder(), // The number of items held 5, // The components applied to the stack DataComponentPatch.builder() .set(DataComponents.ITEM_NAME, Component.literal("Apple?")) .build() ); // Turn the template into a stack ItemStack stack = apple.create(); // Creating a template from a non-empty stack ItemStackTemplate fromStack = ItemStackTemplate.fromNonEmptyStack(stack); ``` -------------------------------- ### Define PermissionSet Interface Source: https://context7.com/neoforged/.github/llms.txt Define an interface for PermissionSet, which represents the permissions a user possesses. This example includes a default hasPermission implementation that checks against HasExamplePermission. ```java // Define a PermissionSet (what a user actually has) public interface ExamplePermissionSet extends PermissionSet { int state(); @Override default boolean hasPermission(Permission permission) { if (permission instanceof HasExamplePermission p) { return this.state() >= p.state(); } return false; } } ``` -------------------------------- ### net.minecraft.client.Minecraft#sendLowDiskSpaceWarning Source: https://github.com/neoforged/.github/blob/main/primers/26.1/index.md Sends a system toast to warn the player about low disk space. ```APIDOC ## Minecraft#sendLowDiskSpaceWarning ### Description Sends a system toast for low disk space. ### Method `sendLowDiskSpaceWarning` ### Class net.minecraft.client.Minecraft ``` -------------------------------- ### Register Custom Config Screen in NeoForge Source: https://context7.com/neoforged/.github/llms.txt Mods can easily opt into a built-in NeoForge Config GUI by subscribing to the RegisterConfigurationScreensEvent and providing a screen factory. ```java // 1. Built-in NeoForge Config GUI — mods can now opt in easily // In your mod's main class or event handler: @SubscribeEvent public static void onRegisterConfigScreen(RegisterConfigurationScreensEvent event) { event.register(MyMod.MOD_ID, (parent) -> new MyConfigScreen(parent)); } ``` -------------------------------- ### Villager Trade with Merchant Predicate Source: https://github.com/neoforged/.github/blob/main/primers/26.1/index.md Use 'merchant_predicate' to define conditions for specific villager types to offer trades. This example checks if the villager is of the 'desert' variant. ```json // For some villager trade 'examplemod:villager_type_item' // JSON at 'data/examplemod/villager_trade/villager_type_item.json' { // ... "merchant_predicate": { // Check the entity. "condition": "minecraft:entity_properties", "entity": "this", "predicate": { "predicates": { // Villager type must be desert for this trade to be chosen. "minecraft:villager/variant": "minecraft:desert" } } }, // ... } ``` -------------------------------- ### net.minecraft.core.dispenser.SpawnEggItemBehavior Source: https://github.com/neoforged/.github/blob/main/primers/26.1/index.md The specific behavior for dispensing spawn eggs from a dispenser. ```APIDOC ## SpawnEggItemBehavior ### Description The dispenser behavior for spawn eggs. ### Class net.minecraft.core.dispenser.SpawnEggItemBehavior ``` -------------------------------- ### Query World Clock State Source: https://github.com/neoforged/.github/blob/main/primers/26.1/index.md Access the `ClockManager` via `Level#clockManager` or `MinecraftServer#clockManager` to get the total ticks passed for a registered world clock. ```java // For some Level level // Assume we have some ResourceKey EXAMPLE_CLOCK // Get the clock reference Holder.Reference clock = level.registryAccess().getOrThrow(EXAMPLE_CLOCK); // Query the clock time long ticksPassed = level.clockManager().getTotalTicks(clock); ``` -------------------------------- ### Create RenderType from RenderSetup Source: https://context7.com/neoforged/.github/llms.txt Generate a RenderType using a predefined RenderSetup. RenderTypes define the rendering characteristics for specific objects or effects. ```java // Creating a RenderType from the RenderSetup public static final RenderType EXAMPLE_TYPE = RenderType.create( "examplemod:example_type", EXAMPLE_SETUP ); ``` -------------------------------- ### Create an Item with the DYE Component Source: https://github.com/neoforged/.github/blob/main/primers/26.1/index.md Use `Item$Properties#component` to add the `DYE` data component to an item, specifying its color. ```java public static final Item EXAMPLE_DYE = new Item(new Item.Properties().component( DataComponents.DYE, DyeColor.WHITE )); ``` -------------------------------- ### Validate Children with Context Source: https://github.com/neoforged/.github/blob/main/primers/26.1/index.md Iterate through child objects and use `ctx.forIndexedField` to get specific context for each child, then report problems using the child's context. ```java public void validate(ValidationContext ctx) { for (int i = 0; i < this.children.size(); i++) { // Get specific context for child in list var childCtx = ctx.forIndexedField("children", i); // Check if a specific condition is validated. if (this.foo() != this.bar()) { // If not, report that there is an issue. childCtx.reportProblem(() -> "'Foo' does not equal 'bar'."); } } } ``` -------------------------------- ### GameTestHelper Methods Source: https://github.com/neoforged/.github/blob/main/primers/26.1/index.md Provides utility methods for interacting with the game test framework. ```APIDOC ## GameTestHelper ### Description Provides utility methods for interacting with the game test framework. ### Methods - `getBoundsWithPadding(padding: Int)`: Gets the bounding box of the test area with the specified padding. - `runBeforeTestEnd(runnable: Runnable)`: Runs the runnable at one tick before the test ends. - `despawnItem(pos: BlockPos, distance: Double)`: Despawns all item entities within the distance of the position. - `discard()`: Discards the entity. - `setTime(time: Long)`: Sets the time of the dimension's default clock. - `placeBlock(pos: BlockPos, direction: Direction, block: BlockState)`: Places the given block at the relative position and direction. ``` -------------------------------- ### Trade Configuration Options Source: https://github.com/neoforged/.github/blob/main/primers/26.1/index.md Configure trade behavior, including whether additional costs increase the number of 'wants' items required and specific trade options. ```json { "include_additional_cost_component": true, "only_compatible": false, "options": "#minecraft:trades/desert_common" } ``` -------------------------------- ### Java Villager Trade for Treasure Map Source: https://github.com/neoforged/.github/blob/main/primers/26.1/index.md Defines a villager trade for a treasure map using Java. This setup specifies the emerald cost, the type of structure to find, map decoration, and trade limits. ```java public static final VillagerTrades.ItemListing EMERALD_TO_TREASURE_MAP = new VillagerTrades.TreasureMapForEmeralds( // The number of emeralds the trader wants. 8, // A tag containing a list of treasure structures to find the nearest of. StructureTags.ON_TAIGA_VILLAGE_MAPS, // The translation key of the map name. "filled_map.village_taiga", // The icon used to decorate the treasure location found on the map. MapDecorationTypes.TAIGA_VILLAGE, // The maximum number of times the trade can be made // before restock. 12, // The amount of experience given for the trade. 5 ); ``` -------------------------------- ### ServerPlayer Methods Source: https://github.com/neoforged/.github/blob/main/primers/26.1/index.md Methods for ServerPlayer related to sending messages and handling spawn protection. ```APIDOC ## ServerPlayer ### Description Methods for ServerPlayer related to sending messages and handling spawn protection. ### Methods - `sendBuildLimitMessage()`: Sends an overlay message if the player cannot build anymore in the corresponding Y direction. - `sendSpawnProtectionMessage()`: Sends an overlay message if the player cannot modify the terrain due to spawn protection. ``` -------------------------------- ### Initialize and Call Validator Source: https://github.com/neoforged/.github/blob/main/primers/26.1/index.md Create a `ProblemCollector` and `ValidationContext`, then call the `validate` method on the `Validatable` object. ```java // For some Validatable validatable // Let's assume we have access to the HolderGetter.Provider provider. // The parameter itself is optional if not available. // Create the problem collector and validation context. // The context params should only include the ones that are being provided. ProblemReporter reporter = new ProblemCollector.Collector(); ValidationContext ctx = new ValidationContext(reporter, LootContextParamSets.ALL_PARAMS, provider); // Call the validator validatable.validate(ctx); ``` -------------------------------- ### GameTestSequence Source: https://github.com/neoforged/.github/blob/main/primers/26.1/index.md Sequence for running game tests with delays. ```APIDOC ## GameTestSequence ### Description Sequence for running game tests with delays. ### Methods - `thenWaitAtLeast(ticks: Int, runnable: Runnable)`: Waits for at least the specified number of ticks before running the runnable. ``` -------------------------------- ### net.minecraft.client.gui.screens.WorldOptionsScreen Source: https://github.com/neoforged/.github/blob/main/primers/26.1/index.md A screen dedicated to displaying and modifying the options for the current world. ```APIDOC ## WorldOptionsScreen ### Description A screen containing the options for the current world the player is in. ### Class net.minecraft.client.gui.screens.WorldOptionsScreen ``` -------------------------------- ### NbtContents Source: https://github.com/neoforged/.github/blob/main/primers/26.1/index.md Codec for NBT paths. ```APIDOC ## NbtContents ### Description Codec for NBT paths. ### Constants - `NBT_PATH_CODEC`: A `CompilableString` codec wrapped around a `NbtPathArgument$NbtPath`. ```