### Add Polymer Blocks Dependencies to Gradle Build Source: https://polymer.pb4.eu/latest/polymer-blocks/getting-started This snippet shows how to configure your Gradle build file to include the Polymer Core, Polymer Blocks, and Polymer Resource Pack modules. Ensure you replace `[TAG]` with the appropriate version number. This setup is crucial for enabling textured block support. ```gradle 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]") } ``` -------------------------------- ### Add Polymer Core Dependency (Gradle) Source: https://polymer.pb4.eu/latest/polymer-core/getting-started This snippet shows how to add the Polymer Core library to your project's build.gradle file. It includes the necessary Maven repository and the dependency declaration for `polymer-core`. Ensure you replace `[TAG]` with the latest version. ```gradle 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://polymer.pb4.eu/latest/user/resource-pack-hosting Enables the AutoHost module for basic server setups. Requires Polymer 0.7.1+1.20.4 or newer. After enabling, the server will automatically generate and host resource packs on startup. ```json { "enabled": true } ``` -------------------------------- ### Add Polymer Resource Pack Dependency (Gradle) Source: https://polymer.pb4.eu/latest/polymer-resource-pack/getting-started This snippet shows how to add the Polymer resource pack module as a dependency in your Gradle build file. It includes configuring the necessary Maven repository and declaring the `modImplementation` dependency. Ensure you replace `[TAG]` with the appropriate version. ```gradle repositories { maven { url 'https://maven.nucleoid.xyz' } // You should have it } dependencies { modImplementation include("eu.pb4:polymer-resource-pack:[TAG]") } ``` -------------------------------- ### Add Polymer Networking Dependency (Gradle) Source: https://polymer.pb4.eu/latest/polymer-networking/getting-started This snippet shows how to add the Polymer networking module to your project's dependencies using Gradle. It specifies the Maven repository and the dependency declaration, requiring you to replace `[TAG]` with the desired version. ```gradle repositories { maven { url 'https://maven.nucleoid.xyz' } // You should have it } dependencies { modImplementation include("eu.pb4:polymer-networking:[TAG]") } ``` -------------------------------- ### Add Polymer Virtual Entity Dependency (Gradle) Source: https://polymer.pb4.eu/latest/polymer-virtual-entity/getting-started This snippet shows how to add the Polymer virtual entity module to your project's dependencies using Gradle. It includes configuring the Maven repository and declaring the module dependency. Ensure you replace `[TAG]` with the latest version. ```gradle repositories { maven { url 'https://maven.nucleoid.xyz' } // You should have it } dependencies { modImplementation include("eu.pb4:polymer-virtual-entity:[TAG]") } ``` -------------------------------- ### Configure AutoHost for Proxy Setups in Polymer Source: https://polymer.pb4.eu/latest/user/resource-pack-hosting Configures the AutoHost module for servers behind a proxy. Requires Polymer 0.7.1+1.20.4 or newer. The `forced_address` should be set to the external address and port accessible by the proxy. ```json { "enabled": true, "forced_address": "http://serveraddress.net:port" } ``` -------------------------------- ### Check Player Resource Pack Status (Java) Source: https://polymer.pb4.eu/latest/polymer-resource-pack/basics Checks if a player has the resource pack enabled by calling `PolymerResourcePackUtils.hasPack(ServerPlayerEntity player)`. This method returns a boolean indicating whether the player has the pack. The example demonstrates conditionally setting an `Identifier` based on the player's pack status. ```java Identifier font; if (PolymerResourcePackUtils.hasPack(player)) { font = Identifier.of("mymod", "myfont"); } else { font = Identifier.of("minecraft", "default"); } ``` -------------------------------- ### Get Client-Safe BlockState Representation with Polymer Source: https://polymer.pb4.eu/latest/polymer-core/blocks This method retrieves a client-friendly representation of a block state. It ensures the returned block state is safe for client-side use, defaulting to air if an error occurs. ```java PolymerBlockUtils.getBlockStateSafely(PolymerBlock block, BlockState blockState, PacketContext context); ``` -------------------------------- ### Get Modded Item/Block/Entity for Compatible Client - Java Source: https://polymer.pb4.eu/latest/polymer-core/client-side This Java code snippet demonstrates how to return a modded object for clients that support it, falling back to a vanilla object if the client does not support the modded version. It checks the supported version of a packet using `PolymerServerNetworking.getSupportedVersion`. ```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; }} ``` -------------------------------- ### Generate Resource Pack Command Source: https://polymer.pb4.eu/latest/polymer-resource-pack/basics Generates the resource pack by executing the `/polymer generate-pack` command in-game. The generated resource pack will be saved as `polymer/resourcepack.zip` in the server's directory. ```text /polymer generate-pack ``` -------------------------------- ### Create and Configure TextDisplayElement Source: https://polymer.pb4.eu/latest/polymer-virtual-entity/basics Demonstrates the creation of a TextDisplayElement, setting its text content, adjusting its offset, and adding it to an ElementHolder for visibility. This API requires an ElementHolder to make virtual elements visible on the client. ```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); ``` -------------------------------- ### Implement PolymerItem Interface for Custom Items Source: https://polymer.pb4.eu/latest/polymer-core/items To create custom items in Polymer, they must implement the `PolymerItem` interface. This interface provides defaulted methods for managing client-side visuals. Basic implementations like `SimplePolymerItem`, `PolymerSpawnEggItem`, `PolymerBlockItem`, and `PolymerHeadBlockItem` are available for common use cases. ```java public interface PolymerItem { // Defaulted methods for client-side visual manipulation } ``` -------------------------------- ### Configure AutoHost with Custom Port in Polymer Source: https://polymer.pb4.eu/latest/user/resource-pack-hosting Sets up AutoHost with a custom port and external address. Requires Polymer 0.4.8+1.19.4 or newer. Ensure the `external_address` is accessible externally and the port is not in use. ```json { "enabled": true, "type": "polymer:http_server", "settings": { "port": 25567, "external_address": "http://localhost:25567/" } } ``` -------------------------------- ### Defining and Requesting Polymer Block Models Source: https://polymer.pb4.eu/latest/polymer-blocks/basics This snippet demonstrates how to define a block model using `PolymerBlockModel.of()` and then request it using `PolymerBlockResourceUtils.requestBlock()`. The returned blockstate is then used in a `PolymerTexturedBlock`. It also shows how to check for available blockstates. ```java import net.minecraft.block.BlockState; import org.betterx.bettercore.blocks.data.PolymerBlockModel; import org.betterx.bettercore.blocks.data.PolymerBlockResourceUtils; import org.betterx.bettercore.blocks.data.BlockModelType; // ... inside your PolymerTexturedBlock implementation ... @Override public BlockState getPolymerBlockState(BlockState state) { PolymerBlockModel model = PolymerBlockModel.of("your_namespace:block/your_block_model"); BlockState blockState = PolymerBlockResourceUtils.requestBlock(BlockModelType.FULL_BLOCK, model); if (blockState == null) { // Handle running out of blockstates return state; // Or some default state } return blockState; } // To check remaining blocks: int remainingBlocks = PolymerBlockResourceUtils.getBlocksLeft(BlockModelType.FULL_BLOCK); ``` -------------------------------- ### Create Server-Side Item Groups with PolymerItemGroupUtils Source: https://polymer.pb4.eu/latest/polymer-core/items Server-side Item Groups can be created using `PolymerItemGroupUtils.builder()`. These groups are synced with Polymer-compatible clients and can be registered using `PolymerItemGroupUtils.registerPolymerItemGroup(Identifier id, ItemGroup group)`. ```java Identifier groupId = new Identifier("your_mod_id", "my_item_group"); ItemGroup myItemGroup = PolymerItemGroupUtils.builder(new ItemStack(Items.DIAMOND)) .add(Items.IRON_INGOT) .build(); PolymerItemGroupUtils.registerPolymerItemGroup(groupId, myItemGroup); ``` -------------------------------- ### Create and Manage ElementHolder Source: https://polymer.pb4.eu/latest/polymer-virtual-entity/basics Illustrates the process of creating an ElementHolder, adding multiple VirtualElements to it, and subsequently removing one. ElementHolders manage the ticking and sending of VirtualElement groups 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://polymer.pb4.eu/latest/polymer-resource-pack/basics Marks a mod as an asset source for the resource pack by calling `PolymerResourcePackUtils.addModAssets(String modid)`. This method returns true if the mod ID is valid. It should ideally be called during mod initialization. Alternatively, assets can be added manually using `ResourcePackBuilder.addData(String path, byte[] data)` by listening to the `PolymerResourcePackUtils.RESOURCE_PACK_CREATION_EVENT`. ```java boolean success = PolymerResourcePackUtils.addModAssets("mymod"); // Or for manual addition: // Event.listen(PolymerResourcePackUtils.RESOURCE_PACK_CREATION_EVENT, (ResourcePackBuilder builder) -> { // builder.addData("assets/path/to/file.png", fileData); // }); ``` -------------------------------- ### Force Items Through Polymer with ITEM_CHECK Event Source: https://polymer.pb4.eu/latest/polymer-core/items To ensure specific items are processed by Polymer's client-side item creation, register an event handler for the `PolymerItemUtils.ITEM_CHECK` event. This allows conditional processing based on item properties. ```java PolymerItemUtils.ITEM_CHECK.register( (itemStack) -> { return itemStack.hasNbt() && itemStack.getNbt().contains("Test", NbtElement.STRING_TYPE); } ); ``` -------------------------------- ### Select Base Item Type with getPolymerItem Source: https://polymer.pb4.eu/latest/polymer-core/items The `getPolymerItem` method determines the base item type for a given `ItemStack` and `PacketContext`. It cannot return null and can point to other `PolymerItem` instances. Ensure 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; } ``` -------------------------------- ### Mark Resource Pack as Required (Java) Source: https://polymer.pb4.eu/latest/polymer-resource-pack/basics Marks the resource pack as required using `PolymerResourcePackUtil.markAsRequired()`. Polymer itself does not provide utilities for sending packs; this is expected to be handled by other mods or vanilla mechanisms. This setting primarily affects the resource pack on the client. ```java PolymerResourcePackUtil.markAsRequired(); ``` -------------------------------- ### Force Server-Side Mining Calculation with Polymer.js Source: https://polymer.pb4.eu/latest/polymer-core/items Enforces server-side calculation of item mining speed using the SERVER_SIDE_MINING_CHECK event. This ensures consistent mining behavior regardless of client-side modifications. The event handler determines if server-side calculation should be applied. ```java PolymerBlockUtils.SERVER_SIDE_MINING_CHECK.register( (player, pos, blockState) -> { var itemStack = player.getMainHandStack(); return EnchantmentHelper.getLevel(MyEnchanments.SLOW_MINING, itemStack) > 0; } ); ``` -------------------------------- ### Requesting an Empty Blockstate for Display Entities Source: https://polymer.pb4.eu/latest/polymer-blocks/basics This snippet shows how to request an empty blockstate using `PolymerBlockResourceUtils.requestEmpty()`. This is useful for creating custom blocks that are rendered using display entities, though it's noted that display entities have a higher performance impact. ```java import net.minecraft.block.BlockState; import org.betterx.bettercore.blocks.data.PolymerBlockResourceUtils; import org.betterx.bettercore.blocks.data.BlockModelType; // ... inside your PolymerTexturedBlock implementation ... @Override public BlockState getPolymerBlockState(BlockState state) { BlockState emptyBlockState = PolymerBlockResourceUtils.requestEmpty(BlockModelType.FULL_BLOCK); if (emptyBlockState == null) { // Handle potential issues, though requestEmpty is less likely to fail return state; } return emptyBlockState; } ``` -------------------------------- ### Send Additional Data for Custom Block Rendering with Polymer Source: https://polymer.pb4.eu/latest/polymer-core/blocks This method is used to send additional data for custom client-side rendering, such as for signs, heads, or companion mod features. It's ideally used for packet transmission. ```java @Override public void onPolymerBlockSend(BlockState blockState, BlockPos.Mutable pos, PacketContext.NotNullWithPlayer context) { player.networkHandler.sendPacket(this.getPolymerHeadPacket(blockState, pos.toImmutable())); } ``` -------------------------------- ### Set Player Head Skin Value with PolymerHeadBlock Source: https://polymer.pb4.eu/latest/polymer-core/blocks When using PolymerHeadBlock, override this method to provide the texture value for a player head. The value can be generated using external tools like mineskin.org. ```java @Override public String getPolymerSkinValue(BlockState state, BlockPos pos, PacketContext.NotNullWithPlayer context) { return "ewogICJ0aW1lc3RhbXAiIDogMTYxNzk3NjcxOTAzNSwKICAicHJvZmlsZUlkIiA6ICJlZDUzZGQ4MTRmOWQ0YTNjYjRlYjY1MWRjYmE3N2U2NiIsCiAgInByb2ZpbGVOYW1lIiA6ICI0MTQxNDE0MWgiLAogICJzaWduYXR1cmVSZXF1aXJlZCIgOiB0cnVlLAogICJ0ZXh0dXJlcyIgOiB7CiAgICAgICJTS0lOIiA6IHsKICAgICAgICAidXJsIiA6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNTczNTE0YTIzMjQ1ZjE1ZGJhZDVmYjRlNjIyMTYzMDIwODY0Y2NlNGMxNWQ1NmRlM2FkYjkwZmE1YTcxMzdmZCIKICAgIH0KICB9Cn0"; } ``` -------------------------------- ### Override getPolymerItemModel for Custom Item Models Source: https://polymer.pb4.eu/latest/polymer-core/items To gain finer control over an item's model, override the `getPolymerItemModel` method. By default, Polymer uses the `item_model` component set in `Item.Settings`, unless overridden by the `ItemStack`. ```java public Identifier getPolymerItemModel(ItemStack itemStack, PacketContext context) { // Custom model logic here return new Identifier("your_mod_id", "models/item/custom_model"); } ``` -------------------------------- ### Modify Client Item Appearance with Polymer.js Source: https://polymer.pb4.eu/latest/polymer-core/items Allows modification of client-side item stacks using the ITEM_MODIFICATION_EVENT. This can be used to hide enchantments or change item names and appearances based on NBT tags. Ensure correct NBT handling to avoid issues. ```java PolymerItemUtils.ITEM_MODIFICATION_EVENT.register( (original, client, context) -> { if (original.hasNbt() && original.getNbt().getBoolean("HideEnchantments")) { client.getNbt().remove("Enchantments"); } return client; } ); PolymerItemUtils.ITEM_MODIFICATION_EVENT.register( (original, client, context) -> { if (original.hasNbt() && original.getNbt().contains("Test", NbtElement.STRING_TYPE)) { ItemStack out = new ItemStack(Items.DIAMOND_SWORD, client.getCount()); out.setNbt(client.getNbt()); out.setCustomName(new LiteralText("TEST VALUE: " + original.getNbt().getString("Test")).formatted(Formatting.WHITE)); return out; } return client; } ); ``` -------------------------------- ### Manipulate ItemStack with modifyBasePolymerItemStack Source: https://polymer.pb4.eu/latest/polymer-core/items The `modifyBasePolymerItemStack` method allows for manipulation of the `ItemStack` that is sent to the client. Only the `out` `ItemStack` can be modified; the `stack` `ItemStack` (server-side default) should not be altered. ```java public void modifyBasePolymerItemStack(ItemStack out, ItemStack stack, PacketContext context) { // Modify the 'out' ItemStack for client-side representation out.getOrCreateNbt().putString("custom_tag", "value"); } ``` -------------------------------- ### Modify Held Items for Entities with Polymer Source: https://polymer.pb4.eu/latest/polymer-core/entities Implement getPolymerVisibleEquipment to customize the items an entity appears to be holding. This method allows for replacing or adding items to specific equipment slots, such as replacing a helmet with a Wither Skeleton Skull. ```java @Override public List> getPolymerVisibleEquipment(List> items, ServerPlayerEntities player) { var list = new ArrayList>(map.size()); for (var entry : items) { if (entry.getKey() == EquipmentSlot.HEAD) { continue; } else { list.add(Pair.of(entry.getKey(), entry.getValue())); } } list.add(new Pair<>(EquipmentSlot.HEAD, new ItemStack(Items.WITHER_SKELETON_SKULL))); return list; } ``` -------------------------------- ### Attach ElementHolder with Ticking EntityAttachment Source: https://polymer.pb4.eu/latest/polymer-virtual-entity/basics Shows how to attach an ElementHolder to an entity using EntityAttachment.ofTicking, which automatically handles the ticking of the attached elements. This is one of the built-in HolderAttachments for connecting ElementHolders to their position and ticking. ```javascript var holder = new ElementHolder(); /* ... */ EntityAttachment.ofTicking(holder, player); ``` -------------------------------- ### Override Block Type with Polymer Source: https://polymer.pb4.eu/latest/polymer-core/blocks This method allows you to specify a different base block type for your Polymer block. It must return a non-null Block instance. Be cautious when returning configurable blocks, ensuring proper validation. ```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; } ``` -------------------------------- ### Modify Client-Side and Collision BlockStates with Polymer Source: https://polymer.pb4.eu/latest/polymer-core/blocks Override this method to change the block state visible on the client and used for server-side collisions. You can return other PolymerBlock states, but nesting is limited to 32 levels. ```java @Override public BlockState getPolymerBlockState(BlockState state, PacketContext context) { return Blocks.FURNACE.getDefaultState() .with(AbstractFurnaceBlock.FACING, state.get(AbstractFurnaceBlock.FACING)) .with(AbstractFurnaceBlock.LIT, !state.get(AbstractFurnaceBlock.LIT)); } ``` -------------------------------- ### Register BlockEntityType to Exclude from Client with Polymer Source: https://polymer.pb4.eu/latest/polymer-core/blocks To prevent a BlockEntity from being sent to the client, register its BlockEntityType using this utility method. This ensures that only server-side data is processed. ```java PolymerBlockUtils.registerBlockEntity(BlockEntityType types); ``` -------------------------------- ### Change Entity Visual Type with Polymer Source: https://polymer.pb4.eu/latest/polymer-core/entities Override the getPolymerEntityType method to specify the visual representation of an entity on the client side. This method must return a valid EntityType and cannot be null. It's crucial for defining how the entity appears to players. ```java @Override public EntityType getPolymerEntityType(PacketContext context) { return EntityType.ZOMBIE; } ``` -------------------------------- ### Modify Client-Side Data Trackers with Polymer Source: https://polymer.pb4.eu/latest/polymer-core/entities Use the modifyRawTrackedData method to directly alter DataTracker values sent to the client. This provides granular control over entity appearance and behavior, but requires careful handling to avoid client-side errors by ensuring DataTracker.Entry types exist on the client. ```java @Override public void modifyRawTrackedData(List> data, ServerPlayerEntity player, boolean initial) { data.add(DataTracker.SerializedEntry.of(VillagerEntityAccessor.getVillagerData(), new VillagerData(VillagerType.JUNGLE, VillagerProfession.FARMER, 3);)); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.