Skip to content

Commit

Permalink
example block and item
Browse files Browse the repository at this point in the history
  • Loading branch information
Soumeh committed Dec 7, 2024
1 parent b22cee4 commit aeb09c6
Show file tree
Hide file tree
Showing 18 changed files with 179 additions and 38 deletions.
13 changes: 13 additions & 0 deletions src/client/java/com/nuclearcrackhead/serverboss/SVBCRClient.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.nuclearcrackhead.serverboss;

import com.nuclearcrackhead.serverboss.registry.ModItemGroups;
import net.fabricmc.api.ClientModInitializer;

public class SVBCRClient implements ClientModInitializer {

@Override
public void onInitializeClient() {
ModItemGroups.init();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import net.fabricmc.fabric.api.datagen.v1.DataGeneratorEntrypoint;
import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator;

public class ServerbossCrossReferenceDataGenerator implements DataGeneratorEntrypoint {
public class SVBCRDatagen implements DataGeneratorEntrypoint {
@Override
public void onInitializeDataGenerator(FabricDataGenerator fabricDataGenerator) {

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.nuclearcrackhead.serverboss.registry;

import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents;
import net.minecraft.item.ItemGroups;

public class ModItemGroups {

public static void init() {
ItemGroupEvents.modifyEntriesEvent(ItemGroups.BUILDING_BLOCKS).register(entries -> {
entries.add(ModBlocks.EXAMPLE_BLOCK);
});
ItemGroupEvents.modifyEntriesEvent(ItemGroups.INGREDIENTS).register(entries -> {
entries.add(ModItems.EXAMPLE_ITEM);
});
}

}
25 changes: 25 additions & 0 deletions src/main/java/com/nuclearcrackhead/serverboss/SVBCR.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.nuclearcrackhead.serverboss;

import com.nuclearcrackhead.serverboss.registry.ModBlocks;
import com.nuclearcrackhead.serverboss.registry.ModItems;
import net.fabricmc.api.ModInitializer;

import net.minecraft.util.Identifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class SVBCR implements ModInitializer {

public static final String MOD_ID = "svbcr";
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);

public static Identifier of(String path) {
return Identifier.of(MOD_ID, path);
}

@Override
public void onInitialize() {
ModItems.init();
ModBlocks.init();
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.nuclearcrackhead.serverboss.content.block;

import net.minecraft.block.Block;

public class ExampleBlock extends Block {

public ExampleBlock(Settings settings) {
super(settings);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.nuclearcrackhead.serverboss.content.item;

import net.minecraft.item.Item;

public class ExampleItem extends Item {

public ExampleItem(Settings settings) {
super(settings);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.nuclearcrackhead.serverboss.registry;

import com.nuclearcrackhead.serverboss.SVBCR;
import com.nuclearcrackhead.serverboss.content.block.ExampleBlock;
import net.minecraft.block.AbstractBlock;
import net.minecraft.block.Block;
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 ModBlocks {

public static void init() {}


public static final Block EXAMPLE_BLOCK = register("example_block", ExampleBlock::new,
AbstractBlock.Settings.create()
);


public static Block register(String path, Function<AbstractBlock.Settings, Block> function, AbstractBlock.Settings settings) {
Identifier id = SVBCR.of(path);
RegistryKey<Block> blockKey = RegistryKey.of(RegistryKeys.BLOCK, id);
settings.registryKey(blockKey);
Block block = Registry.register(Registries.BLOCK, blockKey, function.apply(settings));

RegistryKey<Item> itemKey = RegistryKey.of(RegistryKeys.ITEM, id);
Item.Settings itemSettings = new Item.Settings()
.useBlockPrefixedTranslationKey()
.registryKey(itemKey);
Registry.register(Registries.ITEM, itemKey, new BlockItem(block, itemSettings));
return block;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.nuclearcrackhead.serverboss.registry;

import com.nuclearcrackhead.serverboss.SVBCR;
import com.nuclearcrackhead.serverboss.content.item.ExampleItem;
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 ModItems {

public static void init() {}


public static final Item EXAMPLE_ITEM = register("example_item", ExampleItem::new,
new Item.Settings()
);


public static Item register(String path, Function<Item.Settings, Item> function, Item.Settings settings) {
Identifier id = SVBCR.of(path);
RegistryKey<Item> key = RegistryKey.of(RegistryKeys.ITEM, id);
settings = settings.registryKey(key);
return Registry.register(Registries.ITEM, key, function.apply(settings));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"variants": {
"": {
"model": "svbcr:block/example_block"
}
}
}
4 changes: 4 additions & 0 deletions src/main/resources/assets/svbcr/lang/en_us.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"block.svbcr.example_block": "Example Block",
"item.svbcr.example_item": "Example Item"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "minecraft:block/cube_all",
"textures": {
"all": "svbcr:block/example_block"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"parent": "svbcr:block/example_block"
}
6 changes: 6 additions & 0 deletions src/main/resources/assets/svbcr/models/item/example_item.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "svbcr:item/example_item"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
"environment": "*",
"entrypoints": {
"main": [
"com.nuclearcrackhead.serverboss.ServerbossCrossReference"
"com.nuclearcrackhead.serverboss.SVBCR"
],
"client": [
"com.nuclearcrackhead.serverboss.ServerbossCrossReferenceClient"
"com.nuclearcrackhead.serverboss.SVBCRClient"
],
"fabric-datagen": [
"com.nuclearcrackhead.serverboss.ServerbossCrossReferenceDataGenerator"
"com.nuclearcrackhead.serverboss.SVBCRDatagen"
]
},
"mixins": [
Expand Down

0 comments on commit aeb09c6

Please sign in to comment.