Skip to content

Commit

Permalink
Block rendering works... but not really
Browse files Browse the repository at this point in the history
  • Loading branch information
QPCrummer committed Jan 6, 2025
1 parent 08add01 commit 461e8d7
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 52 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ dependencies {
modImplementation include("xyz.nucleoid:server-translations-api:2.4.0+1.21.2-rc1")
modImplementation include("eu.pb4:polymer-blocks:${project.polymer_version}")
modImplementation include("eu.pb4:polymer-resource-pack:${project.polymer_version}")
modImplementation include("eu.pb4:polymer-resource-pack-extras:${project.polymer_version}")
implementation include('com.google.code.gson:gson:2.11.0')
modApi "maven.modrinth:unruled-api:${project.unruled_version}"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
package com.github.certifiedtater.lifesteal.block;

import com.github.certifiedtater.lifesteal.Lifesteal;
import com.github.certifiedtater.lifesteal.items.DeepslateHeartOreItem;
import com.github.certifiedtater.lifesteal.items.HeartOreItem;
import eu.pb4.polymer.blocks.api.BlockModelType;
import eu.pb4.polymer.core.api.block.SimplePolymerBlock;
import eu.pb4.polymer.core.api.item.PolymerBlockItem;
import net.minecraft.block.AbstractBlock;
import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
import net.minecraft.item.BlockItem;
import net.minecraft.item.Item;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
Expand All @@ -20,23 +13,18 @@

public class ModBlocks {
public static void registerBlocks() {
registerBlocksAndItems("deepslate_heart_ore", AbstractBlock.Settings.copy(Blocks.DEEPSLATE_DIAMOND_ORE).requiresTool()
.strength(6.0f, 6.0f).sounds(BlockSoundGroup.DEEPSLATE), Blocks.DEEPSLATE_REDSTONE_ORE);

registerBlocksAndItems("heart_ore", AbstractBlock.Settings.copy(Blocks.DIAMOND_ORE).requiresTool()
.strength(6.0f, 6.0f).sounds(BlockSoundGroup.STONE), Blocks.REDSTONE_ORE);
register("block/deepslate_heart_ore", Blocks.DEEPSLATE_REDSTONE_ORE, BlockSoundGroup.DEEPSLATE);
register("block/heart_ore", Blocks.REDSTONE_ORE, BlockSoundGroup.STONE);
}

public static void registerBlocksAndItems(String id, AbstractBlock.Settings settings, Block visibleBlock) {
Identifier identifier = Identifier.of(Lifesteal.MOD_ID, id);
RegistryKey<Block> blockKey = RegistryKey.of(RegistryKeys.BLOCK, identifier);
RegistryKey<Item> itemKey = RegistryKey.of(RegistryKeys.ITEM, identifier);

settings.registryKey(blockKey);
Block block = new SimplePolymerTexturedBlock(settings, visibleBlock, identifier);
BlockItem item = new PolymerBlockItem(block, new Item.Settings().useBlockPrefixedTranslationKey().registryKey(itemKey), visibleBlock.asItem(), true);
public static void register(String modelId, Block modelBlock, BlockSoundGroup soundGroup) {
var id = Identifier.of(Lifesteal.MOD_ID, modelId);
var block = Registry.register(Registries.BLOCK, id,
new SimplePolymerTexturedBlock(Block.Settings.copy(Blocks.DIAMOND_ORE).requiresTool()
.strength(6.0f, 6.0f).sounds(soundGroup).registryKey(RegistryKey.of(RegistryKeys.BLOCK, id)), modelId));

Registry.register(Registries.BLOCK, blockKey, block);
Registry.register(Registries.ITEM, itemKey, item);
Registry.register(Registries.ITEM, id, new SimplePolymerTexturedBlockItem(new Item.Settings()
.registryKey(RegistryKey.of(RegistryKeys.ITEM, id)),
block, modelId, modelBlock.asItem()));
}
}
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
package com.github.certifiedtater.lifesteal.block;

import com.github.certifiedtater.lifesteal.Lifesteal;
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 eu.pb4.polymer.core.api.block.SimplePolymerBlock;
import eu.pb4.polymer.resourcepack.api.PolymerResourcePackUtils;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.util.Identifier;
import xyz.nucleoid.packettweaker.PacketContext;

public class SimplePolymerTexturedBlock extends SimplePolymerBlock implements PolymerTexturedBlock {
private final Identifier id;
public SimplePolymerTexturedBlock(Settings settings, Block polymerBlock, Identifier identifier) {
super(settings, polymerBlock);
this.id = identifier;
public class SimplePolymerTexturedBlock extends Block implements PolymerTexturedBlock {
private final BlockState polymerBlockState;

public SimplePolymerTexturedBlock(Settings settings, String modelId) {
super(settings);

this.polymerBlockState = PolymerBlockResourceUtils.requestBlock(
BlockModelType.FULL_BLOCK,
PolymerBlockModel.of(Identifier.of(Lifesteal.MOD_ID, modelId)));

}

@Override
public BlockState getPolymerBlockState(BlockState state, PacketContext context) {
if (PolymerResourcePackUtils.hasMainPack(context)) {
return PolymerBlockResourceUtils.requestBlock(BlockModelType.FULL_BLOCK, PolymerBlockModel.of(Identifier.of(id.getNamespace(), "block/" + id.getPath())));
} else {
return super.getPolymerBlockState(state, context);
}
return this.polymerBlockState;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.github.certifiedtater.lifesteal.block;

import eu.pb4.polymer.resourcepack.extras.api.ResourcePackExtras;
import com.github.certifiedtater.lifesteal.Lifesteal;
import eu.pb4.polymer.core.api.item.PolymerItem;
import net.minecraft.block.Block;
import net.minecraft.item.BlockItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Identifier;
import org.jetbrains.annotations.Nullable;
import xyz.nucleoid.packettweaker.PacketContext;

public class SimplePolymerTexturedBlockItem extends BlockItem implements PolymerItem {
private final Identifier polymerModel;
private final Item polymerItem;
public SimplePolymerTexturedBlockItem(Settings settings, Block block, String modelId, Item polymerItem) {
super(block, settings);
this.polymerModel = ResourcePackExtras.bridgeModel(Identifier.of(Lifesteal.MOD_ID, modelId));
this.polymerItem = polymerItem;
}

@Override
public Item getPolymerItem(ItemStack itemStack, PacketContext player) {
return this.polymerItem;
}

@Override
public @Nullable Identifier getPolymerItemModel(ItemStack stack, PacketContext context) {
return this.polymerModel;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"variants": {
"": {
"model": "lifesteal:block/deepslate_heart_ore"
}
}
{
"variants": {
"": {
"model": "lifesteal:block/deepslate_heart_ore"
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"variants": {
"": {
"model": "lifesteal:block/heart_ore"
}
}
{
"variants": {
"": {
"model": "lifesteal:block/heart_ore"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"targets": [
{
"state": {
"Name": "lifesteal:heart_ore"
"Name": "lifesteal:block/heart_ore"
},
"target": {
"predicate_type": "minecraft:tag_match",
Expand All @@ -15,7 +15,7 @@
},
{
"state": {
"Name": "lifesteal:deepslate_heart_ore"
"Name": "lifesteal:block/deepslate_heart_ore"
},
"target": {
"predicate_type": "minecraft:tag_match",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"replace": false,
"values": [
"lifesteal:heart_ore",
"lifesteal:deepslate_heart_ore"
"lifesteal:block/heart_ore",
"lifesteal:block/deepslate_heart_ore"
]
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"replace": false,
"values": [
"lifesteal:heart_ore",
"lifesteal:deepslate_heart_ore"
"lifesteal:block/heart_ore",
"lifesteal:block/deepslate_heart_ore"
]
}

0 comments on commit 461e8d7

Please sign in to comment.