cable block
This commit is contained in:
+7
-4
@@ -31,14 +31,17 @@ loom {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
// To change the versions see the gradle.properties file
|
// Minecraft version
|
||||||
minecraft "com.mojang:minecraft:${project.minecraft_version}"
|
minecraft "com.mojang:minecraft:${project.minecraft_version}"
|
||||||
mappings loom.officialMojangMappings()
|
|
||||||
|
// Yarn mappings
|
||||||
|
mappings "net.fabricmc:yarn:${project.minecraft_version}+build.2:v2"
|
||||||
|
|
||||||
|
// Fabric Loader
|
||||||
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
|
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
|
||||||
|
|
||||||
// Fabric API. This is technically optional, but you probably want it anyway.
|
// Fabric API
|
||||||
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
|
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
processResources {
|
processResources {
|
||||||
|
|||||||
@@ -0,0 +1,54 @@
|
|||||||
|
package dev.kleo.redstonerewired;
|
||||||
|
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents;
|
||||||
|
import net.minecraft.block.AbstractBlock;
|
||||||
|
import net.minecraft.block.Block;
|
||||||
|
import net.minecraft.item.BlockItem;
|
||||||
|
import net.minecraft.item.Item;
|
||||||
|
import net.minecraft.item.ItemGroups;
|
||||||
|
import net.minecraft.registry.Registries;
|
||||||
|
import net.minecraft.registry.Registry;
|
||||||
|
import net.minecraft.registry.RegistryKey;
|
||||||
|
import net.minecraft.registry.RegistryKeys;
|
||||||
|
import net.minecraft.sound.BlockSoundGroup;
|
||||||
|
import net.minecraft.util.Identifier;
|
||||||
|
|
||||||
|
public class ModBlocks {
|
||||||
|
private static Block register(String name, Function<AbstractBlock.Settings, Block> blockFactory,
|
||||||
|
AbstractBlock.Settings settings, boolean shouldRegisterItem) {
|
||||||
|
RegistryKey<Block> blockKey = keyOfBlock(name);
|
||||||
|
Block block = blockFactory.apply(settings.registryKey(blockKey));
|
||||||
|
|
||||||
|
if (shouldRegisterItem) {
|
||||||
|
RegistryKey<Item> itemKey = keyOfItem(name);
|
||||||
|
|
||||||
|
BlockItem blockItem = new BlockItem(block,
|
||||||
|
new Item.Settings().registryKey(itemKey).useBlockPrefixedTranslationKey());
|
||||||
|
Registry.register(Registries.ITEM, itemKey, blockItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Registry.register(Registries.BLOCK, blockKey, block);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static RegistryKey<Block> keyOfBlock(String name) {
|
||||||
|
return RegistryKey.of(RegistryKeys.BLOCK, Identifier.of(RedstoneRewired.MOD_ID, name));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static RegistryKey<Item> keyOfItem(String name) {
|
||||||
|
return RegistryKey.of(RegistryKeys.ITEM, Identifier.of(RedstoneRewired.MOD_ID, name));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final Block CABLE = register(
|
||||||
|
"cable",
|
||||||
|
Block::new,
|
||||||
|
AbstractBlock.Settings.create().sounds(BlockSoundGroup.COPPER),
|
||||||
|
true);
|
||||||
|
|
||||||
|
public static void initialize() {
|
||||||
|
ItemGroupEvents.modifyEntriesEvent(ItemGroups.REDSTONE).register((itemGroup) -> {
|
||||||
|
itemGroup.add(CABLE.asItem());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,18 +7,11 @@ import org.slf4j.LoggerFactory;
|
|||||||
|
|
||||||
public class RedstoneRewired implements ModInitializer {
|
public class RedstoneRewired implements ModInitializer {
|
||||||
public static final String MOD_ID = "redstone-rewired";
|
public static final String MOD_ID = "redstone-rewired";
|
||||||
|
|
||||||
// This logger is used to write text to the console and the log file.
|
|
||||||
// It is considered best practice to use your mod id as the logger's name.
|
|
||||||
// That way, it's clear which mod wrote info, warnings, and errors.
|
|
||||||
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
|
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onInitialize() {
|
public void onInitialize() {
|
||||||
// This code runs as soon as Minecraft is in a mod-load-ready state.
|
|
||||||
// However, some things (like resources) may still be uninitialized.
|
|
||||||
// Proceed with mild caution.
|
|
||||||
|
|
||||||
LOGGER.info("Hello Fabric world!");
|
LOGGER.info("Hello Fabric world!");
|
||||||
|
ModBlocks.initialize();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user