### Add Polymer Core Dependency (Gradle) Source: https://github.com/patbox/polymer/blob/dev/1.21.11/docs/polymer-core/getting-started.md This snippet shows how to add the Polymer Core library to your project's dependencies using Gradle. It includes configuring the Maven repository and declaring the dependency. Ensure you replace '[TAG]' with the latest version. ```groovy repositories { maven { url 'https://maven.nucleoid.xyz' } // You should have it } dependencies { modImplementation include("eu.pb4:polymer-core:[TAG]") } ``` -------------------------------- ### Enable AutoHost in Polymer (Basic Setup) Source: https://github.com/patbox/polymer/blob/dev/1.21.11/docs/user/resource-pack-hosting.md Enables the AutoHost module for basic server setups. Requires Polymer 0.7.1+1.20.4 or newer. Modify the 'enabled' field in the auto-host.json configuration file. ```json { "enabled": true } ``` -------------------------------- ### Check Player Resource Pack Status (Java) Source: https://github.com/patbox/polymer/blob/dev/1.21.11/docs/polymer-resource-pack/basics.md Checks if a specific server player has the required resource pack installed. This is useful for conditionally applying features or resources based on player configuration. ```java Identifier font; if (PolymerResourcePackUtils.hasPack(player)) { font = Identifier.of("mymod", "myfont"); } else { font = Identifier.of("minecraft", "default"); } ``` -------------------------------- ### Example Language File Structure Source: https://github.com/patbox/polymer/blob/dev/1.21.11/docs/other/server-translation-api.md This is an example of a valid JSON language file used by the Server Translations API. It follows the standard Minecraft translation format, mapping keys to their translated string values for different game elements. ```json { "block.honeytech.pipe": "Pipe", "block.honeytech.item_extractor": "Item Extractor", "block.honeytech.trashcan": "Trash Can", "block.honeytech.cable": "Cable", "item.honeytech.diamond_dust": "Diamond Dust", "item.honeytech.raw_aluminium": "Raw Aluminium Ore", "item.honeytech.aluminium_ingot": "Aluminium Ingot", "item.honeytech.copper_wire": "Copper Wire", "item.honeytech.motor": "Motor", "gui.honeytech.show_recipes": "Show Recipes" } ``` -------------------------------- ### Create Custom Polymer Entities in Java Source: https://context7.com/patbox/polymer/llms.txt Implement the PolymerEntity interface to create custom server-side entities that are displayed as vanilla entity types on the client. This example demonstrates how to define the entity's appearance, customize its visible equipment, and modify its tracked data. ```java import eu.pb4.polymer.core.api.entity.PolymerEntity; import eu.pb4.polymer.core.api.entity.PolymerEntityUtils; import com.mojang.datafixers.util.Pair; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.EquipmentSlot; import net.minecraft.world.entity.PathfinderMob; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; import net.minecraft.server.level.ServerPlayer; import xyz.nucleoid.packettweaker.PacketContext; public class CustomMob extends PathfinderMob implements PolymerEntity { public CustomMob(EntityType type, Level world) { super(type, world); } @Override public EntityType getPolymerEntityType(PacketContext context) { return EntityType.ZOMBIE; // Appears as zombie to clients } @Override public List> getPolymerVisibleEquipment( List> items, ServerPlayer player) { // Customize visible equipment var list = new ArrayList<>(items); list.add(Pair.of(EquipmentSlot.HEAD, new ItemStack(Items.DIAMOND_HELMET))); return list; } @Override public void modifyRawTrackedData(List> data, ServerPlayer player, boolean initial) { // Modify entity data sent to client (e.g., villager profession) data.add(SynchedEntityData.DataValue.create( VillagerEntityAccessor.getVillagerData(), new VillagerData(VillagerType.PLAINS, VillagerProfession.FARMER, 3) )); } } // Registration - must register entity type as virtual public static final EntityType CUSTOM_MOB = Registry.register( BuiltInRegistries.ENTITY_TYPE, Identifier.fromNamespaceAndPath("mymod", "custom_mob"), EntityType.Builder.of(CustomMob::new, MobCategory.CREATURE).sized(0.75f, 1.8f).build() ); // In mod initializer - mark as polymer entity PolymerEntityUtils.registerType(CUSTOM_MOB); ``` -------------------------------- ### Add Polymer Virtual Entity Dependency (Groovy) Source: https://github.com/patbox/polymer/blob/dev/1.21.11/docs/polymer-virtual-entity/getting-started.md This snippet demonstrates how to add the Polymer virtual entity module to your project's dependencies using Groovy. It specifies the Maven repository and the dependency artifact, recommending checking the latest version from the provided Maven link. ```groovy repositories { maven { url 'https://maven.nucleoid.xyz' } // You should have it } dependencies { modImplementation include("eu.pb4:polymer-virtual-entity:[TAG]") } ``` -------------------------------- ### Create Custom Polymer Items Source: https://context7.com/patbox/polymer/llms.txt Implement the `PolymerItem` interface to create server-side items that appear as vanilla items to clients. Examples show a simple implementation using `SimplePolymerItem` and a custom implementation with dynamic client-side appearance based on stack size. ```java import eu.pb4.polymer.core.api.item.PolymerItem; import eu.pb4.polymer.core.api.item.SimplePolymerItem; import net.minecraft.world.item.Item; import net.minecraft.world.item.Items; import net.minecraft.world.item.ItemStack; import xyz.nucleoid.packettweaker.PacketContext; // Simple implementation using built-in class public class MyCustomItem extends SimplePolymerItem { public MyCustomItem(Properties settings) { super(settings, Items.DIAMOND); // Appears as diamond to clients } } // Custom implementation with dynamic client-side appearance public class DynamicItem extends Item implements PolymerItem { public DynamicItem(Properties settings) { super(settings); } @Override public Item getPolymerItem(ItemStack itemStack, PacketContext context) { // Show different items based on stack size return itemStack.getCount() > 32 ? Items.DIAMOND_BLOCK : Items.DIAMOND; } @Override public void modifyBasePolymerItemStack(ItemStack out, ItemStack stack, PacketContext context) { // Modify the client-side ItemStack (e.g., add custom name, lore) out.setHoverName(Component.literal("Custom Item").withStyle(ChatFormatting.GOLD)); } } // Registration in mod initializer public static final Item MY_ITEM = Registry.register( BuiltInRegistries.ITEM, Identifier.fromNamespaceAndPath("mymod", "custom_item"), new MyCustomItem(new Item.Properties().stacksTo(64)) ); ``` -------------------------------- ### Add Polymer Textured Blocks Module to Dependencies (Gradle) Source: https://github.com/patbox/polymer/blob/dev/1.21.11/docs/polymer-resource-pack/getting-started.md This snippet shows how to add the Polymer textured blocks module as a dependency in a Gradle project. It includes configuring the Maven repository and specifying the module implementation. Ensure you replace `[TAG]` with the correct version number. ```groovy repositories { maven { url 'https://maven.nucleoid.xyz' } // You should have it } dependencies { modImplementation include("eu.pb4:polymer-resource-pack:[TAG]") } ``` -------------------------------- ### Add Polymer Blocks Dependency (Gradle) Source: https://github.com/patbox/polymer/blob/dev/1.21.11/docs/polymer-blocks/getting-started.md This snippet shows how to add the Polymer Blocks module and its required dependencies (Polymer Core, Polymer Resource Pack) to your project using Gradle. It specifies the Maven repository and the dependency declarations. ```groovy repositories { maven { url 'https://maven.nucleoid.xyz' } // You should have it } dependencies { modImplementation include("eu.pb4:polymer-core:[TAG]") modImplementation include("eu.pb4:polymer-blocks:[TAG]") modImplementation include("eu.pb4:polymer-resource-pack:[TAG]") } ``` -------------------------------- ### Create Custom Polymer Blocks in Java Source: https://context7.com/patbox/polymer/llms.txt Implement the PolymerBlock interface to create custom server-side blocks with specific client-side appearances. This example shows a simple block that appears as stone and a more complex block that dynamically changes its appearance based on its state, mirroring a vanilla furnace. ```java import eu.pb4.polymer.core.api.block.PolymerBlock; import eu.pb4.polymer.core.api.block.SimplePolymerBlock; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.state.BlockState; import xyz.nucleoid.packettweaker.PacketContext; // Simple block using built-in class public class MyBlock extends SimplePolymerBlock { public MyBlock(Properties settings) { super(settings, Blocks.STONE); // Appears as stone to clients } } // Custom block with dynamic appearance based on state public class FurnaceStyleBlock extends Block implements PolymerBlock { public static final BooleanProperty LIT = Properties.LIT; public static final DirectionProperty FACING = Properties.HORIZONTAL_FACING; public FurnaceStyleBlock(Properties settings) { super(settings); this.registerDefaultState(this.stateDefinition.any() .setValue(LIT, false) .setValue(FACING, Direction.NORTH)); } @Override public BlockState getPolymerBlockState(BlockState state, PacketContext context) { // Mirror state to vanilla furnace with inverted lit property return Blocks.FURNACE.defaultBlockState() .setValue(AbstractFurnaceBlock.FACING, state.getValue(FACING)) .setValue(AbstractFurnaceBlock.LIT, !state.getValue(LIT)); } @Override protected void createBlockStateDefinition(StateDefinition.Builder builder) { builder.add(LIT, FACING); } } // Registration public static final Block MY_BLOCK = Registry.register( BuiltInRegistries.BLOCK, Identifier.fromNamespaceAndPath("mymod", "custom_block"), new MyBlock(BlockBehaviour.Properties.of().strength(2f).lightLevel(state -> 15)) ); ``` -------------------------------- ### Configure AutoHost for Proxy Setups in Polymer Source: https://github.com/patbox/polymer/blob/dev/1.21.11/docs/user/resource-pack-hosting.md Configures the AutoHost module for servers behind a proxy. Requires Polymer 0.7.1+1.20.4 or newer. Set the 'forced_address' field to your server's external address and port. ```json { "enabled": true, "forced_address": "http://server.net:25565" } ``` -------------------------------- ### Get Client-Safe BlockState with Polymer Source: https://github.com/patbox/polymer/blob/dev/1.21.11/docs/polymer-core/blocks.md Provides a method to safely retrieve a client-friendly representation of a block state using Polymer. This utility function is essential for ensuring that block states used on the client are valid and do not cause rendering issues, defaulting to air if an error occurs. ```java PolymerBlockUtils.getBlockStateSafely(PolymerBlock block, BlockState blockState, PacketContext context) ``` -------------------------------- ### Configure Auto-Host for Resource Packs (HTTP Server) Source: https://context7.com/patbox/polymer/llms.txt Configures automatic resource pack hosting using an HTTP server. This JSON configuration enables the feature, specifies the server type, and includes settings for port and external address. ```json { "enabled": true, "type": "polymer:http_server", "settings": { "port": 25567, "external_address": "http://your-server.com:25567/" }, "forced_address": "" } ``` -------------------------------- ### Configure Auto-Host for Resource Packs (Netty) Source: https://context7.com/patbox/polymer/llms.txt Configures automatic resource pack hosting using the Netty server type. This JSON configuration enables the auto-host feature and specifies the server type. ```json { "enabled": true, "type": "polymer:netty", "settings": {}, "forced_address": "" } ``` -------------------------------- ### Create and Modify TextDisplayElement Source: https://github.com/patbox/polymer/blob/dev/1.21.11/docs/polymer-virtual-entity/basics.md Demonstrates the creation of a TextDisplayElement, setting its text content, adjusting its offset, and adding it to an ElementHolder for visibility. This API simplifies the use of virtual entities with special visual properties. ```javascript var element = new TextDisplayElement(); // Changing entity-specific property element.setText(Text.literal("Hello world")); // Changing offset element.setOffset(new Vec3d(0, 5, 0)); // Adding to holder. More info below! holder.addElement(element); ``` -------------------------------- ### Configure Resource Pack Generation with Polymer Source: https://context7.com/patbox/polymer/llms.txt Manage resource pack generation and hosting for custom models and textures using PolymerResourcePackUtils. This includes registering mod assets, marking the pack as required, setting descriptions, and dynamically adding data. ```java import eu.pb4.polymer.resourcepack.api.PolymerResourcePackUtils; public class MyMod implements ModInitializer { @Override public void onInitialize() { // Register mod assets to be included in generated resource pack PolymerResourcePackUtils.addModAssets("mymod"); // Optionally make resource pack required PolymerResourcePackUtils.markAsRequired(); // Customize pack description PolymerResourcePackUtils.getInstance().setPackDescription( Component.literal("My Custom Pack").withStyle(ChatFormatting.GREEN) ); // Listen to resource pack creation for dynamic content PolymerResourcePackUtils.RESOURCE_PACK_CREATION_EVENT.register(builder -> { builder.addData("assets/mymod/textures/custom.png", imageBytes); }); } } // Check if player has resource pack loaded public void someMethod(ServerPlayer player) { if (PolymerResourcePackUtils.hasPack(player)) { // Player has resource pack - use custom font/models player.sendSystemMessage(Component.literal("Custom!") .withStyle(Style.EMPTY.withFont(Identifier.fromNamespaceAndPath("mymod", "custom")))); } else { // Player doesn't have pack - use fallback player.sendSystemMessage(Component.literal("Fallback")); } } ``` -------------------------------- ### Create Virtual Entities with Display Elements (Java) Source: https://context7.com/patbox/polymer/llms.txt Demonstrates how to create packet-based virtual entities using the polymer-virtual-entity module. It shows the creation of text, block, item, and interaction display elements, and how to attach them to chunks or entities. ```java import eu.pb4.polymer.virtualentity.api.ElementHolder; import eu.pb4.polymer.virtualentity.api.attachment.ChunkAttachment; import eu.pb4.polymer.virtualentity.api.attachment.EntityAttachment; import eu.pb4.polymer.virtualentity.api.elements.*; import net.minecraft.world.phys.Vec3; import net.minecraft.network.chat.Component; public class VirtualEntityExample { public void createHologram(ServerLevel world, Vec3 position) { // Create an element holder var holder = new ElementHolder(); // Create a text display element var textElement = new TextDisplayElement(); textElement.setText(Component.literal("Hello World!")); textElement.setOffset(new Vec3(0, 2, 0)); textElement.setBillboardMode(Display.BillboardConstraints.CENTER); holder.addElement(textElement); // Create a block display element var blockElement = new BlockDisplayElement(); blockElement.setBlockState(Blocks.DIAMOND_BLOCK.defaultBlockState()); blockElement.setOffset(new Vec3(0, 0, 0)); holder.addElement(blockElement); // Create an item display element var itemElement = new ItemDisplayElement(); itemElement.setItem(new ItemStack(Items.DIAMOND_SWORD)); itemElement.setOffset(new Vec3(0, 1, 0)); holder.addElement(itemElement); // Create an interaction element for click detection var interactionElement = new InteractionElement(); interactionElement.setSize(1.0f, 1.0f); holder.addElement(interactionElement); // Attach to chunk (persists while chunk is loaded) ChunkAttachment.ofTicking(holder, world, BlockPos.containing(position)); } public void attachToEntity(Entity entity) { var holder = new ElementHolder(); var nameTag = new TextDisplayElement(); nameTag.setText(Component.literal("Custom Name")); nameTag.setOffset(new Vec3(0, entity.getBbHeight() + 0.5, 0)); holder.addElement(nameTag); // Attach to entity (follows entity movement) EntityAttachment.ofTicking(holder, entity); } } ``` -------------------------------- ### Add Custom Data to Resource Pack (Java) Source: https://github.com/patbox/polymer/blob/dev/1.21.11/docs/polymer-resource-pack/basics.md Allows manual addition of custom data to the resource pack. This is achieved by listening to the PolymerResourcePackUtils.RESOURCE_PACK_CREATION_EVENT and using the ResourcePackBuilder.addData method. Note that a new builder is created each time the resource pack is generated. ```java PolymerResourcePackUtils.RESOURCE_PACK_CREATION_EVENT.register(builder -> { // Example: Adding a file named 'mymod:textures/block/my_block.png' byte[] fileData = ...; // Load your file data here builder.addData("mymod/textures/block/my_block.png", fileData); }); ``` -------------------------------- ### Create Custom Sound Events with Vanilla Fallback (Java) Source: https://context7.com/patbox/polymer/llms.txt Java code to create a custom sound event that plays a vanilla sound for players without resource packs. It utilizes Polymer's `PolymerSoundEvent` for seamless integration. ```java import eu.pb4.polymer.core.api.other.PolymerSoundEvent; import net.minecraft.sounds.SoundEvent; import net.minecraft.sounds.SoundEvents; public class CustomSounds { // Custom sound with vanilla fallback public static final SoundEvent CUSTOM_SOUND = new PolymerSoundEvent( PolymerResourcePackUtils.getMainUuid(), Identifier.fromNamespaceAndPath("mymod", "custom_sound"), 16, // range true, // use distance SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP // fallback for players without pack ); } ``` -------------------------------- ### Implement PolymerItem Interface for Custom Items Source: https://github.com/patbox/polymer/blob/dev/1.21.11/docs/polymer-core/items.md To create custom items with Polymer, your item class must implement the PolymerItem interface. This interface provides defaulted methods for client-side visual manipulation. Basic implementations like SimplePolymerItem, PolymerSpawnEggItem, PolymerBlockItem, and PolymerHeadBlockItem are available for common use cases. ```java public class CustomItem extends SimplePolymerItem { // ... } ``` -------------------------------- ### Mark Resource Pack as Required (Java) Source: https://github.com/patbox/polymer/blob/dev/1.21.11/docs/polymer-resource-pack/basics.md Marks the current resource pack as required for players. While Polymer itself doesn't handle pack distribution, this setting affects the client-side resource pack. It's recommended to keep packs optional if possible. ```java PolymerResourcePackUtils.markAsRequired(); ``` -------------------------------- ### Set Player Head Skin Value with PolymerHeadBlock Source: https://github.com/patbox/polymer/blob/dev/1.21.11/docs/polymer-core/blocks.md Illustrates how to set a custom skin value for blocks implementing the `PolymerHeadBlock` interface. This allows for dynamic player head skins to be displayed on blocks, using texture values obtained from external sources. ```java @Override public String getPolymerSkinValue(BlockState state, BlockPos pos, PacketContext.NotNullWithPlayer context) { return "ewogICJ0aW1lc3RhbXAiIDogMTYxNzk3NjcxOTAzNSwKICAicHJvZmlsZUlkIiA6ICJlZDUzZGQ4MTRmOWQ0YTNjYjRlYjY1MWRjYmE3N2U2NiIsCiAgInByb2ZpbGVOYW1lIiA6ICI0MTQxNDE0MWgiLAogICJzaWduYXR1cmVSZXF1aXJlZCIgOiB0cnVlLAogICJ0ZXh0dXJlcyIgOiB7CiAgICAgICJTS0lOIiA6IHsKICAgICAgICAidXJsIiA6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNTczNTE0YTIzMjQ1ZjE1ZGJhZDVmYjRlNjIyMTYzMDIwODY0Y2NlNGMxNWQ1NmRlM2FkYjkwZmE1YTcxMzdmZCIKICAgIH0KICB9Cn0"; } ``` -------------------------------- ### Create and Manage ElementHolder Source: https://github.com/patbox/polymer/blob/dev/1.21.11/docs/polymer-virtual-entity/basics.md Illustrates the creation of an ElementHolder, adding multiple VirtualElements to it, and subsequently removing one. ElementHolders manage the ticking and sending of VirtualElements and can be extended for dynamic element creation. ```javascript var holder = new ElementHolder(); var element1 = createElement(...); var element2 = createElement(...); var element3 = createElement(...); // Adding elements holder.addElement(element1); holder.addElement(element2); holder.addElement(element3); // Removing elements holder.removeElement(element3); /* Attach here */ ``` -------------------------------- ### Add Mod Assets to Resource Pack (Java) Source: https://github.com/patbox/polymer/blob/dev/1.21.11/docs/polymer-resource-pack/basics.md Marks a mod as an asset source for the resource pack. This method should ideally be called during your mod's initialization. It returns true if the modid is valid. ```java boolean success = PolymerResourcePackUtils.addModAssets(modid); // success will be true if modid is valid ``` -------------------------------- ### Creating a Polymer Block Source: https://github.com/patbox/polymer/blob/dev/1.21.11/docs/polymer-blocks/basics.md To create a custom block in Polymer, you need to implement the `PolymerTexturedBlock` interface. This interface acts as a marker for Polymer-specific blocks, differentiating them from regular Minecraft blocks. The core logic for block behavior and appearance is handled within this implementation. ```java public class MyCustomBlock extends PolymerTexturedBlock { // Implementation details for your custom block } ``` -------------------------------- ### Defining and Requesting a Polymer Block Model Source: https://github.com/patbox/polymer/blob/dev/1.21.11/docs/polymer-blocks/basics.md This process involves defining a block model using `PolymerBlockModel.of(...)` and then requesting it via `PolymerBlockResourceUtils.requestBlock(...)`. The returned blockstate is then used in your `PolymerTexturedBlock`. Ensure you register your assets using `PolymerRPUtils.addAssetSource(String modId)`. ```java PolymerBlockModel model = PolymerBlockModel.of(blockStateDefinition); BlockState blockState = PolymerBlockResourceUtils.requestBlock(BlockModelType.FULL_BLOCK, model); // Use the blockState in your PolymerTexturedBlock @Override public BlockState getPolymerBlockState(World world, BlockPos pos, BlockState state) { return blockState; } ``` -------------------------------- ### Configure AutoHost with Custom Port in Polymer Source: https://github.com/patbox/polymer/blob/dev/1.21.11/docs/user/resource-pack-hosting.md Sets up the AutoHost module to use a custom port and external address. Requires Polymer 0.4.8+1.19.4 or newer. Specify the port and external_address in the settings. ```json { "enabled": true, "type": "polymer:http_server", "settings": { "port": 25567, "external_address": "http://localhost:25567/" } } ``` -------------------------------- ### Create Server-Side Item Groups with PolymerItemGroupUtils Source: https://github.com/patbox/polymer/blob/dev/1.21.11/docs/polymer-core/items.md Polymer supports server-side Item Groups that synchronize with compatible clients. These groups also enable server-side Creative categories accessible via the `/polymer creative` command. Use `PolymerItemGroupUtils.builder()` to create and `PolymerItemGroupUtils.registerPolymerItemGroup()` to register them. ```java Identifier groupId = new Identifier("your_mod_id", "custom_group"); ItemGroup customGroup = PolymerItemGroupUtils.builder() .icon(() -> new ItemStack(Items.DIAMOND)) .entries((enabledFeatures, entries) -> { entries.add(Items.DIAMOND); }) .build(); PolymerItemGroupUtils.registerPolymerItemGroup(groupId, customGroup); ``` -------------------------------- ### Enable Server-Side Mining Calculation with PolymerBlockUtils Event Source: https://github.com/patbox/polymer/blob/dev/1.21.11/docs/polymer-core/items.md Enables server-side calculation of item mining speed by registering a listener for the PolymerBlockUtils.SERVER_SIDE_MINING_CHECK event. This is the default behavior for PolymerItems. The event handler determines if mining should be server-side calculated based on player and item conditions. ```java PolymerBlockUtils.SERVER_SIDE_MINING_CHECK.register( (player, pos, blockState) -> { var itemStack = player.getMainHandStack(); return EnchantmentHelper.getLevel(MyEnchanments.SLOW_MINING, itemStack) > 0; } ); ``` -------------------------------- ### Add Polymer Dependencies to Gradle Build Source: https://context7.com/patbox/polymer/llms.txt Configure your Gradle build file to include Polymer modules from the Nucleoid Maven repository. This involves adding the repository and specifying the desired Polymer modules as dependencies. ```groovy repositories { maven { url 'https://maven.nucleoid.xyz' } } dependencies { // Core module - required for basic functionality modImplementation include("eu.pb4:polymer-core:0.15.2+1.21.11") // Resource pack module - for custom textures and models modImplementation include("eu.pb4:polymer-resource-pack:0.15.2+1.21.11") // Textured blocks module - for custom block models modImplementation include("eu.pb4:polymer-blocks:0.15.2+1.21.11") // Virtual entity module - for packet-based display entities modImplementation include("eu.pb4:polymer-virtual-entity:0.15.2+1.21.11") // Networking module - for client-server communication modImplementation include("eu.pb4:polymer-networking:0.15.2+1.21.11") } ``` -------------------------------- ### Add Server Translations API Dependency (Pre-1.19.4 Versions) Source: https://github.com/patbox/polymer/blob/dev/1.21.11/docs/other/server-translation-api.md This code snippet demonstrates how to add the Server Translations API as a dependency in a Gradle project for Minecraft versions prior to 1.19.4. It specifies the correct Maven repository and dependency coordinates. ```groovy repositories { maven { url 'https://maven.nucleoid.xyz' } } dependencies { modImplementation include("fr.catcore:server-translations-api:[TAG]") } ``` -------------------------------- ### Force Items Through Polymer with ITEM_CHECK Event Source: https://github.com/patbox/polymer/blob/dev/1.21.11/docs/polymer-core/items.md To ensure vanilla or modded items are processed by Polymer's client-side item creation, register an event handler for the `PolymerItemUtils.ITEM_CHECK` event. This is done using `PolymerItemUtils.ITEM_CHECK.register()` with a lambda function that returns a boolean. ```java PolymerItemUtils.ITEM_CHECK.register( (itemStack) -> { return itemStack.hasNbt() && itemStack.getNbt().contains("Test", NbtElement.STRING_TYPE); } ); ``` -------------------------------- ### Select Base Item Type with getPolymerItem Source: https://github.com/patbox/polymer/blob/dev/1.21.11/docs/polymer-core/items.md The `getPolymerItem` method allows you to dynamically select the base item type based on the ItemStack and PacketContext. This method cannot return null and can point to other PolymerItem instances. Ensure proper validation if the selection is user-configurable. ```java @Override public Item getPolymerItem(ItemStack itemStack, PacketContext context) { return itemStack.getCount() > 32 ? Items.DIAMOND_BLOCK : Items.DIAMOND; } ``` -------------------------------- ### Register Custom Server-Side Item Groups (Java) Source: https://context7.com/patbox/polymer/llms.txt Explains how to create custom creative mode tabs using the Polymer module. These custom groups can be accessed via the `/polymer creative` command and allow for organized presentation of modded items. ```java import eu.pb4.polymer.core.api.item.PolymerItemGroupUtils; import net.minecraft.world.item.CreativeModeTab; public class ItemGroupSetup { public static final CreativeModeTab CUSTOM_GROUP = new CreativeModeTab.Builder(null, -1) .title(Component.translatable("mymod.itemgroup").withStyle(ChatFormatting.AQUA)) .icon(() -> new ItemStack(MY_CUSTOM_ITEM)) .displayItems((parameters, output) -> { output.accept(MY_CUSTOM_ITEM); output.accept(MY_CUSTOM_BLOCK_ITEM); output.accept(MY_CUSTOM_TOOL); }) .build(); public void register() { PolymerItemGroupUtils.registerPolymerItemGroup( Identifier.fromNamespaceAndPath("mymod", "custom_group"), CUSTOM_GROUP ); } } ``` -------------------------------- ### Add Server Translations API Dependency (Modern Versions) Source: https://github.com/patbox/polymer/blob/dev/1.21.11/docs/other/server-translation-api.md This code snippet shows how to add the Server Translations API as a dependency in a Gradle project for modern Minecraft versions. It includes repository configuration and the dependency declaration. ```groovy repositories { maven { url 'https://maven.nucleoid.xyz' } } dependencies { modImplementation include("xyz.nucleoid:server-translations-api:[TAG]") } ``` -------------------------------- ### Override Block Type with Polymer Source: https://github.com/patbox/polymer/blob/dev/1.21.11/docs/polymer-core/blocks.md Demonstrates how to override the default block type returned by Polymer, allowing for dynamic block selection based on game state or player properties. This method is crucial for implementing conditional block behaviors. ```java @Override public Block getPolymerBlock(BlockState state, PacketContext context) { return Blocks.BARRIER; } public Block getPolymerBlock(ServerPlayerEntity player, BlockState state) { return Something.isRedTeam(player) ? Blocks.RED_WOOL : Blocks.BLUE_WOOL; } ``` -------------------------------- ### Add Polymer Networking Dependency (Gradle) Source: https://github.com/patbox/polymer/blob/dev/1.21.11/docs/polymer-networking/getting-started.md This snippet shows how to add the Polymer networking module to your project's dependencies using Gradle. It includes specifying the Maven repository and the dependency itself. Ensure you replace `[TAG]` with the desired version. ```groovy repositories { maven { url 'https://maven.nucleoid.xyz' } // You should have it } dependencies { modImplementation include("eu.pb4:polymer-networking:[TAG]") } ``` -------------------------------- ### Requesting an Empty Blockstate for Display Entities Source: https://github.com/patbox/polymer/blob/dev/1.21.11/docs/polymer-blocks/basics.md An empty blockstate can be requested using `PolymerBlockResourceUtils.requestEmpty(BlockModelType type)`. This is useful for displaying custom blocks via display entities, but be aware of the potential performance impact on clients. Empty models are shared across mods. ```java BlockState emptyBlockState = PolymerBlockResourceUtils.requestEmpty(BlockModelType.FULL_BLOCK); // Use emptyBlockState with display entities ``` -------------------------------- ### Sync Modded Item/Block/Entity to Compatible Client (Java) Source: https://github.com/patbox/polymer/blob/dev/1.21.11/docs/polymer-core/client-side.md This code snippet demonstrates how to return server-side items/blocks for player-aware Polymer methods. It checks if the client supports a specific modded version using Polymer's networking handshake. If supported, it returns the modded object; otherwise, it falls back to a vanilla object. ```java SomeObject getPolymerX(PacketContext context) { if (PolymerServerNetworking.getSupportedVersion(player.networkHandler, PACKET_ID) > 0) { // Client state for modded return this; } else { // Client state for vanilla return VanillaObjects.SOMETHING; } } ``` -------------------------------- ### Register Server-Side Custom Statistics (Java) Source: https://context7.com/patbox/polymer/llms.txt Java code to register server-side statistics that track player actions using Polymer's `PolymerStat`. It includes a method to increment the custom statistic for a player. ```java import eu.pb4.polymer.core.api.other.PolymerStat; import net.minecraft.stats.StatFormatter; import net.minecraft.stats.Stats; public class CustomStats { public static final Identifier CUSTOM_STAT = PolymerStat.registerStat( Identifier.fromNamespaceAndPath("mymod", "custom_action"), StatFormatter.DEFAULT ); public void incrementStat(ServerPlayer player) { player.awardStat(CUSTOM_STAT); } } ``` -------------------------------- ### Create Player Head Blocks with PolymerHeadBlock Source: https://context7.com/patbox/polymer/llms.txt Implement the PolymerHeadBlock interface to create blocks that display custom textures using player head skins. This requires providing a skin value and optionally controlling block rotation. ```java import eu.pb4.polymer.core.api.block.PolymerHeadBlock; import net.minecraft.core.BlockPos; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.state.BlockState; import xyz.nucleoid.packettweaker.PacketContext; public class CustomHeadBlock extends Block implements PolymerHeadBlock { // Skin texture value from mineskin.org private static final String SKIN_VALUE = "ewogICJ0aW1lc3RhbXAiIDog..."; public CustomHeadBlock(Properties settings) { super(settings); } @Override public String getPolymerSkinValue(BlockState state, BlockPos pos, PacketContext.NotNullWithPlayer context) { return SKIN_VALUE; } @Override public BlockState getPolymerBlockState(BlockState state, PacketContext context) { // Control head rotation via BlockState return Blocks.PLAYER_HEAD.defaultBlockState() .setValue(SkullBlock.ROTATION, 0); } } ``` -------------------------------- ### Implement PolymerEntity Interface Source: https://github.com/patbox/polymer/blob/dev/1.21.11/docs/polymer-core/entities.md To create entities with Polymer, you need to implement the `PolymerEntity` interface in your entity's class. This interface provides defaulted methods for manipulating client-side visuals. You also need to register your entity type as virtual using `PolymerEntityUtils.registerType()`. ```java import com.example.YourEntity; import net.minecraft.entity.EntityType; import org.mtr.mod.PolymerEntityUtils; // In your mod initializer or entity registration class: PolymerEntityUtils.registerType(EntityType.ZOMBIE, EntityType.SKELETON); // Example registration ``` -------------------------------- ### Send Additional Data for Custom Block Rendering with Polymer Source: https://github.com/patbox/polymer/blob/dev/1.21.11/docs/polymer-core/blocks.md Details the process of sending extra data to the client for custom block rendering, such as for signs, heads, or companion mod integrations. This involves overriding the `onPolymerBlockSend` method to send custom packets. ```java @Override public void onPolymerBlockSend(BlockState blockState, BlockPos.Mutable pos, PacketContext.NotNullWithPlayer context) { player.networkHandler.sendPacket(this.getPolymerHeadPacket(blockState, pos.toImmutable())); } ``` -------------------------------- ### Create Textured Blocks with Polymer Blocks API Source: https://context7.com/patbox/polymer/llms.txt Utilize the polymer-blocks module to create blocks with custom model textures. This involves requesting a blockstate for a specified model and handling fallback states. ```java import eu.pb4.polymer.blocks.api.BlockModelType; import eu.pb4.polymer.blocks.api.PolymerBlockModel; import eu.pb4.polymer.blocks.api.PolymerBlockResourceUtils; import eu.pb4.polymer.blocks.api.PolymerTexturedBlock; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.state.BlockState; import xyz.nucleoid.packettweaker.PacketContext; public class TexturedBlock extends Block implements PolymerTexturedBlock { private final BlockState polymerState; public TexturedBlock(Properties settings) { super(settings); // Request a blockstate for the model this.polymerState = PolymerBlockResourceUtils.requestBlock( BlockModelType.FULL_BLOCK, PolymerBlockModel.of(Identifier.fromNamespaceAndPath("mymod", "block/custom_block")) ); } @Override public BlockState getPolymerBlockState(BlockState state, PacketContext context) { return this.polymerState != null ? this.polymerState : Blocks.STONE.defaultBlockState(); } } // Available BlockModelTypes and their limits: // - FULL_BLOCK (1149) - Noteblocks, full collision // - TRANSPARENT_BLOCK (52) - Leaf blocks, cutout textures // - FARMLAND_BLOCK (5) - Farmland-style blocks // - VINES_BLOCK (100) - Vine-style blocks // - TRIPWIRE_BLOCK (32) - Tripwire, allows transparency // - TOP_SLAB / BOTTOM_SLAB (5 each) - Slab blocks // - *_TRAPDOOR (20 each) - Trapdoor variants // - *_DOOR (160 each) - Door variants ``` -------------------------------- ### Attach ElementHolder to Entity with Ticking Source: https://github.com/patbox/polymer/blob/dev/1.21.11/docs/polymer-virtual-entity/basics.md Shows how to attach an ElementHolder to an entity using EntityAttachment.ofTicking, which automatically handles the ticking of the attached elements. This is a common way to make virtual entities persistent and visible in relation to a specific entity. ```javascript var holder = new ElementHolder(); /* ... */ EntityAttachment.ofTicking(holder, player); ```