-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
119 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.hugman.lucky_block; | ||
|
||
import com.hugman.lucky_block.block.LuckyBlocks; | ||
import eu.pb4.polymer.resourcepack.api.PolymerResourcePackUtils; | ||
import net.fabricmc.api.ModInitializer; | ||
import net.minecraft.util.Identifier; | ||
|
||
public class LuckyBlockMod implements ModInitializer { | ||
private static final String MOD_ID = "lucky_block"; | ||
|
||
@Override | ||
public void onInitialize() { | ||
LuckyBlocks.register(); | ||
PolymerResourcePackUtils.addModAssets(MOD_ID); | ||
} | ||
|
||
public static Identifier id(String path) { | ||
return Identifier.of(MOD_ID, path); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/com/hugman/lucky_block/block/LuckyBlock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.hugman.lucky_block.block; | ||
|
||
import com.hugman.lucky_block.LuckyBlockMod; | ||
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 net.minecraft.block.Block; | ||
import net.minecraft.block.BlockState; | ||
import xyz.nucleoid.packettweaker.PacketContext; | ||
|
||
public class LuckyBlock extends SimplePolymerBlock implements PolymerTexturedBlock { | ||
public LuckyBlock(Settings settings, Block polymerBlock) { | ||
super(settings, polymerBlock); | ||
} | ||
|
||
@Override | ||
public BlockState getPolymerBlockState(BlockState state, PacketContext context) { | ||
return PolymerBlockResourceUtils.requestBlock(BlockModelType.FULL_BLOCK, PolymerBlockModel.of(LuckyBlockMod.id("lucky_block"))); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/com/hugman/lucky_block/block/LuckyBlockKeys.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.hugman.lucky_block.block; | ||
|
||
import com.hugman.lucky_block.LuckyBlockMod; | ||
import eu.pb4.polymer.core.api.block.PolymerBlock; | ||
import net.minecraft.block.AbstractBlock; | ||
import net.minecraft.block.Block; | ||
import net.minecraft.block.BlockState; | ||
import net.minecraft.block.Blocks; | ||
import net.minecraft.component.DataComponentTypes; | ||
import net.minecraft.component.type.ContainerComponent; | ||
import net.minecraft.item.BlockItem; | ||
import net.minecraft.item.Item; | ||
import net.minecraft.registry.Registries; | ||
import net.minecraft.registry.Registry; | ||
import net.minecraft.registry.RegistryKey; | ||
import net.minecraft.registry.RegistryKeys; | ||
import net.minecraft.util.Identifier; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.function.Function; | ||
|
||
public class LuckyBlockKeys { | ||
public static final RegistryKey<Block> LUCKY_BLOCK = of("lucky_block"); | ||
|
||
private static RegistryKey<Block> of(String path) { | ||
return RegistryKey.of(RegistryKeys.BLOCK, LuckyBlockMod.id(path)); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
src/main/java/com/hugman/lucky_block/block/LuckyBlocks.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.hugman.lucky_block.block; | ||
|
||
import com.hugman.lucky_block.LuckyBlockMod; | ||
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.core.api.block.PolymerBlock; | ||
import eu.pb4.polymer.core.api.item.PolymerBlockItem; | ||
import eu.pb4.polymer.core.api.utils.PolymerRegistry; | ||
import net.minecraft.block.AbstractBlock; | ||
import net.minecraft.block.Block; | ||
import net.minecraft.block.Blocks; | ||
import net.minecraft.component.DataComponentTypes; | ||
import net.minecraft.component.type.ContainerComponent; | ||
import net.minecraft.item.BlockItem; | ||
import net.minecraft.item.Item; | ||
import net.minecraft.registry.Registries; | ||
import net.minecraft.registry.Registry; | ||
import net.minecraft.registry.RegistryKey; | ||
import net.minecraft.registry.RegistryKeys; | ||
import net.minecraft.util.Identifier; | ||
|
||
import java.util.function.Function; | ||
|
||
public class LuckyBlocks { | ||
public static final LuckyBlock LUCKY_BLOCK = luckyBlock(LuckyBlockKeys.LUCKY_BLOCK, AbstractBlock.Settings.copy(Blocks.YELLOW_WOOL)); | ||
|
||
public static void register() { | ||
|
||
} | ||
|
||
private static <B extends Block & PolymerBlock> B noItem(RegistryKey<Block> key, Function<AbstractBlock.Settings, B> factory, AbstractBlock.Settings blockSettings) { | ||
B block = factory.apply(blockSettings.registryKey(key)); | ||
return Registry.register(Registries.BLOCK, key, block); | ||
} | ||
|
||
private static <B extends Block & PolymerBlock> B of(RegistryKey<Block> key, Function<AbstractBlock.Settings, B> factory, AbstractBlock.Settings blockSettings, Item.Settings itemSettings) { | ||
B block = noItem(key, factory, blockSettings); | ||
var itemRegistryKey = RegistryKey.of(RegistryKeys.ITEM, key.getValue()); | ||
Registry.register(Registries.ITEM, itemRegistryKey, new PolymerBlockItem(block, itemSettings.registryKey(itemRegistryKey).useBlockPrefixedTranslationKey())); | ||
return block; | ||
} | ||
|
||
private static LuckyBlock luckyBlock(RegistryKey<Block> key, AbstractBlock.Settings settings) { | ||
return of(key, s -> new LuckyBlock(s, Blocks.GOLD_BLOCK), settings, new Item.Settings().component(DataComponentTypes.CONTAINER, ContainerComponent.DEFAULT)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters