Update to 1.20.1
This commit is contained in:
@@ -4,19 +4,29 @@ import com.google.common.collect.Maps;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonObject;
|
||||
import net.fabricmc.fabric.api.item.v1.FabricItemSettings;
|
||||
import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents;
|
||||
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
||||
import net.fabricmc.fabric.api.registry.FlammableBlockRegistry;
|
||||
import net.fabricmc.fabric.mixin.object.builder.AbstractBlockSettingsAccessor;
|
||||
import net.minecraft.block.*;
|
||||
import net.minecraft.block.AbstractBlock;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.MapColor;
|
||||
import net.minecraft.block.enums.Instrument;
|
||||
import net.minecraft.block.piston.PistonBehavior;
|
||||
import net.minecraft.entity.EntityType;
|
||||
import net.minecraft.item.BlockItem;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemGroup;
|
||||
import net.minecraft.registry.Registries;
|
||||
import net.minecraft.registry.Registry;
|
||||
import net.minecraft.registry.RegistryKey;
|
||||
import net.minecraft.sound.BlockSoundGroup;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.JsonHelper;
|
||||
import net.minecraft.util.Pair;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.BlockView;
|
||||
import org.apache.logging.log4j.Level;
|
||||
|
||||
import java.util.Map;
|
||||
@@ -36,8 +46,8 @@ public class BlockResourceLoader extends GenericManualResourceLoader<Pair<Block,
|
||||
|
||||
@Override
|
||||
protected void register(Identifier id, Pair<Block, Item> thing) {
|
||||
Registry.register(Registry.BLOCK, id, thing.getLeft());
|
||||
Registry.register(Registry.ITEM, id, thing.getRight());
|
||||
Registry.register(Registries.BLOCK, id, thing.getLeft());
|
||||
Registry.register(Registries.ITEM, id, thing.getRight());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -49,219 +59,338 @@ public class BlockResourceLoader extends GenericManualResourceLoader<Pair<Block,
|
||||
@Override
|
||||
protected Pair<Block, Item> deserialize(Pair<Identifier, JsonObject> e) {
|
||||
JsonObject jo = e.getRight();
|
||||
Material material;
|
||||
if(JsonHelper.hasString(jo, "material")){
|
||||
String materialString = JsonHelper.getString(jo, "material");
|
||||
material = getMaterial(materialString);
|
||||
} else if (JsonHelper.getObject(jo,"material", null)!=null){
|
||||
// get material information
|
||||
JsonObject jmo = JsonHelper.getObject(jo, "material");
|
||||
MaterialSettingsPojo mspj = GSON.fromJson(jmo, MaterialSettingsPojo.class);
|
||||
//build material
|
||||
material = getSettings(mspj);
|
||||
} else {
|
||||
material = Material.SOIL;
|
||||
}
|
||||
|
||||
// get block information
|
||||
BlockSettingsPojo bspj = GSON.fromJson(jo, BlockSettingsPojo.class);
|
||||
|
||||
// move block information in Block.Settings (!!hacky!!)
|
||||
Block.Settings bs = getSettings(material, bspj);
|
||||
Block.Settings bs = getSettings(bspj);
|
||||
|
||||
// parse item group
|
||||
String group = JsonHelper.getString(jo, "itemGroup", "misc");
|
||||
ItemGroup g = ItemResourceLoader.findGroup(group);
|
||||
RegistryKey<ItemGroup> g = ItemResourceLoader.findGroup(group);
|
||||
//create block and corresponding item
|
||||
Block resB = new Block(bs);
|
||||
Item resI = new BlockItem(resB, new Item.Settings().group(g));
|
||||
Item resI = new BlockItem(resB, new FabricItemSettings());
|
||||
ItemGroupEvents.modifyEntriesEvent(g).register(content -> content.add(resI));
|
||||
|
||||
int burnChance = JsonHelper.getInt(jo,"burnChance", -1);
|
||||
int spreadChance = JsonHelper.getInt(jo,"spreadChance", -1);
|
||||
if(burnChance!=-1 && spreadChance!=-1){
|
||||
int burnChance = JsonHelper.getInt(jo, "burnChance", -1);
|
||||
int spreadChance = JsonHelper.getInt(jo, "spreadChance", -1);
|
||||
if (burnChance != -1 && spreadChance != -1) {
|
||||
FlammableBlockRegistry.getDefaultInstance().add(resB, spreadChance, burnChance);
|
||||
}
|
||||
return new Pair<>(resB, resI);
|
||||
}
|
||||
|
||||
private Material getSettings(MaterialSettingsPojo mspj) {
|
||||
return new Material(
|
||||
getMaterialColor(mspj.materialColor),
|
||||
mspj.liquid,
|
||||
mspj.solid,
|
||||
mspj.blocksMovement,
|
||||
mspj.blocksLight,
|
||||
mspj.breakByHand,
|
||||
mspj.burnable,
|
||||
getPistonBehavior(mspj.pistonBehavior));
|
||||
private Block.Settings getSettings(BlockSettingsPojo bspj) {
|
||||
FabricBlockSettings fabricBlockSettings = FabricBlockSettings.create();
|
||||
|
||||
fabricBlockSettings
|
||||
.collidable(bspj.collidable)
|
||||
.slipperiness(bspj.slipperiness)
|
||||
.velocityMultiplier(bspj.slowDownMultiplier)
|
||||
.jumpVelocityMultiplier(bspj.jumpVelocityMultiplier)
|
||||
.sounds(getSoundGroup(bspj.soundGroup))
|
||||
.drops(getDropTableId(bspj.dropTableId))
|
||||
.mapColor(getMapColor(bspj.mapColor))
|
||||
.allowsSpawning(bspj.allowsSpawning ? BlockResourceLoader::always : BlockResourceLoader::never)
|
||||
.solidBlock(bspj.solidBlock ? BlockResourceLoader::always : BlockResourceLoader::never)
|
||||
.suffocates(bspj.suffocates ? BlockResourceLoader::always : BlockResourceLoader::never)
|
||||
.blockVision(bspj.blockVision ? BlockResourceLoader::always : BlockResourceLoader::never)
|
||||
.postProcess(bspj.postProcess ? BlockResourceLoader::always : BlockResourceLoader::never)
|
||||
.emissiveLighting(bspj.emissiveLighting ? BlockResourceLoader::always : BlockResourceLoader::never)
|
||||
.hardness(bspj.hardness)
|
||||
.resistance(bspj.explosionResistance)
|
||||
.offset(getOffset(bspj.modelOffset))
|
||||
.pistonBehavior(getPistonBehavior(bspj.pistonBehavior))
|
||||
.instrument(getInstrument(bspj.instrument))
|
||||
.luminance(bspj.lightLevel);
|
||||
if (bspj.burnable) {
|
||||
fabricBlockSettings.burnable();
|
||||
}
|
||||
//not supported for now
|
||||
//fabricBlockSettings.liquid()
|
||||
if (bspj.solidBlock) {
|
||||
fabricBlockSettings.solid();
|
||||
} else {
|
||||
fabricBlockSettings.notSolid();
|
||||
}
|
||||
if (bspj.replaceable) {
|
||||
fabricBlockSettings.replaceable();
|
||||
}
|
||||
//not supported for now
|
||||
//fabricBlockSettings.air()
|
||||
|
||||
if (bspj.noBlockBreakParticles) {
|
||||
fabricBlockSettings.noBlockBreakParticles();
|
||||
}
|
||||
if (bspj.requiresTool) {
|
||||
fabricBlockSettings.requiresTool();
|
||||
|
||||
}
|
||||
if (bspj.breaksInstantly) {
|
||||
fabricBlockSettings.breakInstantly();
|
||||
}
|
||||
|
||||
if (!bspj.opaque) {
|
||||
fabricBlockSettings.nonOpaque();
|
||||
}
|
||||
|
||||
return fabricBlockSettings;
|
||||
}
|
||||
|
||||
private Instrument getInstrument(String instrument) {
|
||||
switch (instrument.toUpperCase()) {
|
||||
case "HARP":
|
||||
return Instrument.HARP;
|
||||
case "BASEDRUM":
|
||||
return Instrument.BASEDRUM;
|
||||
case "SNARE":
|
||||
return Instrument.SNARE;
|
||||
case "HAT":
|
||||
return Instrument.HAT;
|
||||
case "BASS":
|
||||
return Instrument.BASS;
|
||||
case "FLUTE":
|
||||
return Instrument.FLUTE;
|
||||
case "BELL":
|
||||
return Instrument.BELL;
|
||||
case "GUITAR":
|
||||
return Instrument.GUITAR;
|
||||
case "CHIME":
|
||||
return Instrument.CHIME;
|
||||
case "XYLOPHONE":
|
||||
return Instrument.XYLOPHONE;
|
||||
case "IRON_XYLOPHONE":
|
||||
return Instrument.IRON_XYLOPHONE;
|
||||
case "COW_BELL":
|
||||
return Instrument.COW_BELL;
|
||||
case "DIDGERIDOO":
|
||||
return Instrument.DIDGERIDOO;
|
||||
case "BIT":
|
||||
return Instrument.BIT;
|
||||
case "BANJO":
|
||||
return Instrument.BANJO;
|
||||
case "PLING":
|
||||
return Instrument.PLING;
|
||||
case "ZOMBIE":
|
||||
return Instrument.ZOMBIE;
|
||||
case "SKELETON":
|
||||
return Instrument.SKELETON;
|
||||
case "CREEPER":
|
||||
return Instrument.CREEPER;
|
||||
case "DRAGON":
|
||||
return Instrument.DRAGON;
|
||||
case "WITHER_SKELETON":
|
||||
return Instrument.WITHER_SKELETON;
|
||||
case "PIGLIN":
|
||||
return Instrument.PIGLIN;
|
||||
case "CUSTOM_HEAD":
|
||||
return Instrument.CUSTOM_HEAD;
|
||||
default:
|
||||
log(Level.WARN, "Instrument " + instrument + " not found, using harp");
|
||||
return Instrument.HARP;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private AbstractBlock.OffsetType getOffset(String modelOffset) {
|
||||
switch (modelOffset.toUpperCase()) {
|
||||
case "NONE":
|
||||
return AbstractBlock.OffsetType.NONE;
|
||||
case "XZ":
|
||||
return AbstractBlock.OffsetType.XZ;
|
||||
case "XYZ":
|
||||
return AbstractBlock.OffsetType.XYZ;
|
||||
default:
|
||||
log(Level.WARN, "ModelOffset " + modelOffset + " not found, using none");
|
||||
return AbstractBlock.OffsetType.NONE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static boolean always(BlockState blockState, BlockView blockView, BlockPos blockPos) {
|
||||
return true;
|
||||
}
|
||||
|
||||
private static boolean never(BlockState blockState, BlockView blockView, BlockPos blockPos) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* A shortcut to always return {@code false} in a typed context predicate with an
|
||||
* {@link EntityType}, used like {@code settings.allowSpawning(Blocks::never)}.
|
||||
*/
|
||||
private static Boolean never(BlockState state, BlockView world, BlockPos pos, EntityType<?> type) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* A shortcut to always return {@code true} in a typed context predicate with an
|
||||
* {@link EntityType}, used like {@code settings.allowSpawning(Blocks::always)}.
|
||||
*/
|
||||
private static Boolean always(BlockState state, BlockView world, BlockPos pos, EntityType<?> type) {
|
||||
return true;
|
||||
}
|
||||
|
||||
private PistonBehavior getPistonBehavior(String pistonBehavior) {
|
||||
switch (pistonBehavior.toUpperCase()) {
|
||||
case "NORMAL":
|
||||
case "NORMAL" -> {
|
||||
return PistonBehavior.NORMAL;
|
||||
case "DESTROY":
|
||||
}
|
||||
case "DESTROY" -> {
|
||||
return PistonBehavior.DESTROY;
|
||||
case "BLOCK":
|
||||
}
|
||||
case "BLOCK" -> {
|
||||
return PistonBehavior.BLOCK;
|
||||
case "IGNORE":
|
||||
}
|
||||
case "IGNORE" -> {
|
||||
return PistonBehavior.IGNORE;
|
||||
case "PUSH_ONLY":
|
||||
}
|
||||
case "PUSH_ONLY" -> {
|
||||
return PistonBehavior.PUSH_ONLY;
|
||||
default:
|
||||
}
|
||||
default -> {
|
||||
log(Level.WARN, "Piston Behavior " + pistonBehavior + " not found, using normal");
|
||||
return PistonBehavior.NORMAL;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private MaterialColor getMaterialColor(String color) {
|
||||
|
||||
private MapColor getMapColor(String color) {
|
||||
switch (color.toUpperCase()) {
|
||||
case "AIR":
|
||||
case "CLEAR":
|
||||
return MaterialColor.CLEAR;
|
||||
case "GRASS":
|
||||
return MaterialColor.GRASS;
|
||||
case "SAND":
|
||||
return MaterialColor.SAND;
|
||||
case "WEB":
|
||||
return MaterialColor.WEB;
|
||||
case "LAVA":
|
||||
return MaterialColor.LAVA;
|
||||
case "ICE":
|
||||
return MaterialColor.ICE;
|
||||
case "IRON":
|
||||
return MaterialColor.IRON;
|
||||
case "FOLIAGE":
|
||||
return MaterialColor.FOLIAGE;
|
||||
return MapColor.CLEAR;
|
||||
case "PALE_GREEN":
|
||||
return MapColor.PALE_GREEN;
|
||||
case "PALE_YELLOW":
|
||||
return MapColor.PALE_YELLOW;
|
||||
case "WHITE_GRAY":
|
||||
return MapColor.WHITE_GRAY;
|
||||
case "BRIGHT_RED":
|
||||
return MapColor.BRIGHT_RED;
|
||||
case "PALE_PURPLE":
|
||||
return MapColor.PALE_PURPLE;
|
||||
case "IRON_GRAY":
|
||||
return MapColor.IRON_GRAY;
|
||||
case "DARK_GREEN":
|
||||
return MapColor.DARK_GREEN;
|
||||
case "WHITE":
|
||||
return MaterialColor.WHITE;
|
||||
case "CLAY":
|
||||
return MaterialColor.CLAY;
|
||||
case "DIRT":
|
||||
return MaterialColor.DIRT;
|
||||
case "STONE":
|
||||
return MaterialColor.STONE;
|
||||
case "WATER":
|
||||
return MaterialColor.WATER;
|
||||
case "WOOD":
|
||||
return MaterialColor.WOOD;
|
||||
case "QUARTZ":
|
||||
return MaterialColor.QUARTZ;
|
||||
return MapColor.WHITE;
|
||||
case "LIGHT_BLUE_GRAY":
|
||||
return MapColor.LIGHT_BLUE_GRAY;
|
||||
case "DIRT_BROWN":
|
||||
return MapColor.DIRT_BROWN;
|
||||
case "STONE_GRAY":
|
||||
return MapColor.STONE_GRAY;
|
||||
case "WATER_BLUE":
|
||||
return MapColor.WATER_BLUE;
|
||||
case "OAK_TAN":
|
||||
return MapColor.OAK_TAN;
|
||||
case "OFF_WHITE":
|
||||
return MapColor.OFF_WHITE;
|
||||
case "ORANGE":
|
||||
return MaterialColor.ORANGE;
|
||||
return MapColor.ORANGE;
|
||||
case "MAGENTA":
|
||||
return MaterialColor.MAGENTA;
|
||||
return MapColor.MAGENTA;
|
||||
case "LIGHT_BLUE":
|
||||
return MaterialColor.LIGHT_BLUE;
|
||||
return MapColor.LIGHT_BLUE;
|
||||
case "YELLOW":
|
||||
return MaterialColor.YELLOW;
|
||||
return MapColor.YELLOW;
|
||||
case "LIME":
|
||||
return MaterialColor.LIME;
|
||||
return MapColor.LIME;
|
||||
case "PINK":
|
||||
return MaterialColor.PINK;
|
||||
return MapColor.PINK;
|
||||
case "GRAY":
|
||||
return MaterialColor.GRAY;
|
||||
return MapColor.GRAY;
|
||||
case "LIGHT_GRAY":
|
||||
return MaterialColor.LIGHT_GRAY;
|
||||
return MapColor.LIGHT_GRAY;
|
||||
case "CYAN":
|
||||
return MaterialColor.CYAN;
|
||||
return MapColor.CYAN;
|
||||
case "PURPLE":
|
||||
return MaterialColor.PURPLE;
|
||||
return MapColor.PURPLE;
|
||||
case "BLUE":
|
||||
return MaterialColor.BLUE;
|
||||
return MapColor.BLUE;
|
||||
case "BROWN":
|
||||
return MaterialColor.BROWN;
|
||||
return MapColor.BROWN;
|
||||
case "GREEN":
|
||||
return MaterialColor.GREEN;
|
||||
return MapColor.GREEN;
|
||||
case "RED":
|
||||
return MaterialColor.RED;
|
||||
return MapColor.RED;
|
||||
case "BLACK":
|
||||
return MaterialColor.BLACK;
|
||||
return MapColor.BLACK;
|
||||
case "GOLD":
|
||||
return MaterialColor.GOLD;
|
||||
case "DIAMOND":
|
||||
return MaterialColor.DIAMOND;
|
||||
case "LAPIS":
|
||||
return MaterialColor.LAPIS;
|
||||
case "EMERALD":
|
||||
return MaterialColor.EMERALD;
|
||||
case "SPRUCE":
|
||||
return MaterialColor.SPRUCE;
|
||||
case "NETHER":
|
||||
return MaterialColor.NETHER;
|
||||
case "WHITE_TERRACOTTA":
|
||||
return MaterialColor.WHITE_TERRACOTTA;
|
||||
case "ORANGE_TERRACOTTA":
|
||||
return MaterialColor.ORANGE_TERRACOTTA;
|
||||
case "MAGENTA_TERRACOTTA":
|
||||
return MaterialColor.MAGENTA_TERRACOTTA;
|
||||
case "LIGHT_BLUE_TERRACOTTA":
|
||||
return MaterialColor.LIGHT_BLUE_TERRACOTTA;
|
||||
case "YELLOW_TERRACOTTA":
|
||||
return MaterialColor.YELLOW_TERRACOTTA;
|
||||
case "LIME_TERRACOTTA":
|
||||
return MaterialColor.LIME_TERRACOTTA;
|
||||
case "PINK_TERRACOTTA":
|
||||
return MaterialColor.PINK_TERRACOTTA;
|
||||
case "GRAY_TERRACOTTA":
|
||||
return MaterialColor.GRAY_TERRACOTTA;
|
||||
case "LIGHT_GRAY_TERRACOTTA":
|
||||
return MaterialColor.LIGHT_GRAY_TERRACOTTA;
|
||||
case "CYAN_TERRACOTTA":
|
||||
return MaterialColor.CYAN_TERRACOTTA;
|
||||
case "PURPLE_TERRACOTTA":
|
||||
return MaterialColor.PURPLE_TERRACOTTA;
|
||||
case "BLUE_TERRACOTTA":
|
||||
return MaterialColor.BLUE_TERRACOTTA;
|
||||
case "BROWN_TERRACOTTA":
|
||||
return MaterialColor.BROWN_TERRACOTTA;
|
||||
case "GREEN_TERRACOTTA":
|
||||
return MaterialColor.GREEN_TERRACOTTA;
|
||||
case "RED_TERRACOTTA":
|
||||
return MaterialColor.RED_TERRACOTTA;
|
||||
case "BLACK_TERRACOTTA":
|
||||
return MaterialColor.BLACK_TERRACOTTA;
|
||||
case "CRIMSON_NYLIUM":
|
||||
return MaterialColor.field_25702;
|
||||
case "CRIMSON_WOOD":
|
||||
return MaterialColor.field_25703;
|
||||
case "CRIMSON_HYPHAE":
|
||||
return MaterialColor.field_25704;
|
||||
case "WARPED_NYLIUM":
|
||||
return MaterialColor.field_25705;
|
||||
case "WARPED_WOOD":
|
||||
return MaterialColor.field_25706;
|
||||
case "WARPED_HYPHAE":
|
||||
return MaterialColor.field_25707;
|
||||
case "WARPED_WART_BLOCK":
|
||||
return MaterialColor.field_25708;
|
||||
return MapColor.GOLD;
|
||||
case "DIAMOND_BLUE":
|
||||
return MapColor.DIAMOND_BLUE;
|
||||
case "LAPIS_BLUE":
|
||||
return MapColor.LAPIS_BLUE;
|
||||
case "EMERALD_GREEN":
|
||||
return MapColor.EMERALD_GREEN;
|
||||
case "SPRUCE_BROWN":
|
||||
return MapColor.SPRUCE_BROWN;
|
||||
case "DARK_RED":
|
||||
return MapColor.DARK_RED;
|
||||
case "TERRACOTTA_WHITE":
|
||||
return MapColor.TERRACOTTA_WHITE;
|
||||
case "TERRACOTTA_ORANGE":
|
||||
return MapColor.TERRACOTTA_ORANGE;
|
||||
case "TERRACOTTA_MAGENTA":
|
||||
return MapColor.TERRACOTTA_MAGENTA;
|
||||
case "TERRACOTTA_LIGHT_BLUE":
|
||||
return MapColor.TERRACOTTA_LIGHT_BLUE;
|
||||
case "TERRACOTTA_YELLOW":
|
||||
return MapColor.TERRACOTTA_YELLOW;
|
||||
case "TERRACOTTA_LIME":
|
||||
return MapColor.TERRACOTTA_LIME;
|
||||
case "TERRACOTTA_PINK":
|
||||
return MapColor.TERRACOTTA_PINK;
|
||||
case "TERRACOTTA_GRAY":
|
||||
return MapColor.TERRACOTTA_GRAY;
|
||||
case "TERRACOTTA_LIGHT_GRAY":
|
||||
return MapColor.TERRACOTTA_LIGHT_GRAY;
|
||||
case "TERRACOTTA_CYAN":
|
||||
return MapColor.TERRACOTTA_CYAN;
|
||||
case "TERRACOTTA_PURPLE":
|
||||
return MapColor.TERRACOTTA_PURPLE;
|
||||
case "TERRACOTTA_BLUE":
|
||||
return MapColor.TERRACOTTA_BLUE;
|
||||
case "TERRACOTTA_BROWN":
|
||||
return MapColor.TERRACOTTA_BROWN;
|
||||
case "TERRACOTTA_GREEN":
|
||||
return MapColor.TERRACOTTA_GREEN;
|
||||
case "TERRACOTTA_RED":
|
||||
return MapColor.TERRACOTTA_RED;
|
||||
case "TERRACOTTA_BLACK":
|
||||
return MapColor.TERRACOTTA_BLACK;
|
||||
case "DULL_RED":
|
||||
return MapColor.DULL_RED;
|
||||
case "DULL_PINK":
|
||||
return MapColor.DULL_PINK;
|
||||
case "DARK_CRIMSON":
|
||||
return MapColor.DARK_CRIMSON;
|
||||
case "TEAL":
|
||||
return MapColor.TEAL;
|
||||
case "DARK_AQUA":
|
||||
return MapColor.DARK_AQUA;
|
||||
case "DARK_DULL_PINK":
|
||||
return MapColor.DARK_DULL_PINK;
|
||||
case "BRIGHT_TEAL":
|
||||
return MapColor.BRIGHT_TEAL;
|
||||
case "DEEPSLATE_GRAY":
|
||||
return MapColor.DEEPSLATE_GRAY;
|
||||
case "RAW_IRON_PINK":
|
||||
return MapColor.RAW_IRON_PINK;
|
||||
case "LICHEN_GREEN":
|
||||
return MapColor.LICHEN_GREEN;
|
||||
|
||||
default:
|
||||
log(Level.WARN, "MapColor " + color + " not found, using pink");
|
||||
return MaterialColor.PINK;
|
||||
return MapColor.PINK;
|
||||
}
|
||||
}
|
||||
|
||||
private Block.Settings getSettings(Material material, BlockSettingsPojo bspj) {
|
||||
FabricBlockSettings fabricBlockSettings = FabricBlockSettings.of(material, material.getColor());
|
||||
AbstractBlockSettingsAccessor bs = (AbstractBlockSettingsAccessor) fabricBlockSettings;
|
||||
bs.setMaterial(material);
|
||||
bs.setMaterialColorFactory(ignored -> material.getColor());
|
||||
bs.setCollidable(bspj.collidable);
|
||||
fabricBlockSettings.sounds(getSoundGroup(bspj.soundGroup));
|
||||
bs.setLuminanceFunction(ignored -> bspj.lightLevel);
|
||||
bs.setResistance(bspj.explosionResistance);
|
||||
bs.setHardness(bspj.hardness);
|
||||
fabricBlockSettings.slipperiness(bspj.slipperiness);
|
||||
fabricBlockSettings.velocityMultiplier(bspj.slowDownMultiplier);
|
||||
fabricBlockSettings.jumpVelocityMultiplier(bspj.jumpVelocityMultiplier);
|
||||
bs.setLootTableId(getDropTableId(bspj.dropTableId));
|
||||
bs.setOpaque(bspj.opaque);
|
||||
return fabricBlockSettings;
|
||||
}
|
||||
|
||||
private Identifier getDropTableId(String s) {
|
||||
if (s == null)
|
||||
return null;
|
||||
@@ -275,6 +404,8 @@ public class BlockResourceLoader extends GenericManualResourceLoader<Pair<Block,
|
||||
|
||||
private BlockSoundGroup getSoundGroup(String s) {
|
||||
switch (s.toUpperCase()) {
|
||||
case "INTENTIONALLY_EMPTY":
|
||||
return BlockSoundGroup.INTENTIONALLY_EMPTY;
|
||||
case "WOOD":
|
||||
return BlockSoundGroup.WOOD;
|
||||
case "GRAVEL":
|
||||
@@ -295,6 +426,8 @@ public class BlockResourceLoader extends GenericManualResourceLoader<Pair<Block,
|
||||
return BlockSoundGroup.SAND;
|
||||
case "SNOW":
|
||||
return BlockSoundGroup.SNOW;
|
||||
case "POWDER_SNOW":
|
||||
return BlockSoundGroup.POWDER_SNOW;
|
||||
case "LADDER":
|
||||
return BlockSoundGroup.LADDER;
|
||||
case "ANVIL":
|
||||
@@ -369,117 +502,119 @@ public class BlockResourceLoader extends GenericManualResourceLoader<Pair<Block,
|
||||
return BlockSoundGroup.NETHER_GOLD_ORE;
|
||||
case "GILDED_BLACKSTONE":
|
||||
return BlockSoundGroup.GILDED_BLACKSTONE;
|
||||
case "CANDLE":
|
||||
return BlockSoundGroup.CANDLE;
|
||||
case "AMETHYST_BLOCK":
|
||||
return BlockSoundGroup.AMETHYST_BLOCK;
|
||||
case "AMETHYST_CLUSTER":
|
||||
return BlockSoundGroup.AMETHYST_CLUSTER;
|
||||
case "SMALL_AMETHYST_BUD":
|
||||
return BlockSoundGroup.SMALL_AMETHYST_BUD;
|
||||
case "MEDIUM_AMETHYST_BUD":
|
||||
return BlockSoundGroup.MEDIUM_AMETHYST_BUD;
|
||||
case "LARGE_AMETHYST_BUD":
|
||||
return BlockSoundGroup.LARGE_AMETHYST_BUD;
|
||||
case "TUFF":
|
||||
return BlockSoundGroup.TUFF;
|
||||
case "CALCITE":
|
||||
return BlockSoundGroup.CALCITE;
|
||||
case "DRIPSTONE_BLOCK":
|
||||
return BlockSoundGroup.DRIPSTONE_BLOCK;
|
||||
case "POINTED_DRIPSTONE":
|
||||
return BlockSoundGroup.POINTED_DRIPSTONE;
|
||||
case "COPPER":
|
||||
return BlockSoundGroup.COPPER;
|
||||
case "CAVE_VINES":
|
||||
return BlockSoundGroup.CAVE_VINES;
|
||||
case "SPORE_BLOSSOM":
|
||||
return BlockSoundGroup.SPORE_BLOSSOM;
|
||||
case "AZALEA":
|
||||
return BlockSoundGroup.AZALEA;
|
||||
case "FLOWERING_AZALEA":
|
||||
return BlockSoundGroup.FLOWERING_AZALEA;
|
||||
case "MOSS_CARPET":
|
||||
return BlockSoundGroup.MOSS_CARPET;
|
||||
case "PINK_PETALS":
|
||||
return BlockSoundGroup.PINK_PETALS;
|
||||
case "MOSS_BLOCK":
|
||||
return BlockSoundGroup.MOSS_BLOCK;
|
||||
case "BIG_DRIPLEAF":
|
||||
return BlockSoundGroup.BIG_DRIPLEAF;
|
||||
case "SMALL_DRIPLEAF":
|
||||
return BlockSoundGroup.SMALL_DRIPLEAF;
|
||||
case "ROOTED_DIRT":
|
||||
return BlockSoundGroup.ROOTED_DIRT;
|
||||
case "HANGING_ROOTS":
|
||||
return BlockSoundGroup.HANGING_ROOTS;
|
||||
case "AZALEA_LEAVES":
|
||||
return BlockSoundGroup.AZALEA_LEAVES;
|
||||
case "SCULK_SENSOR":
|
||||
return BlockSoundGroup.SCULK_SENSOR;
|
||||
case "SCULK_CATALYST":
|
||||
return BlockSoundGroup.SCULK_CATALYST;
|
||||
case "SCULK":
|
||||
return BlockSoundGroup.SCULK;
|
||||
case "SCULK_VEIN":
|
||||
return BlockSoundGroup.SCULK_VEIN;
|
||||
case "SCULK_SHRIEKER":
|
||||
return BlockSoundGroup.SCULK_SHRIEKER;
|
||||
case "GLOW_LICHEN":
|
||||
return BlockSoundGroup.GLOW_LICHEN;
|
||||
case "DEEPSLATE":
|
||||
return BlockSoundGroup.DEEPSLATE;
|
||||
case "DEEPSLATE_BRICKS":
|
||||
return BlockSoundGroup.DEEPSLATE_BRICKS;
|
||||
case "DEEPSLATE_TILES":
|
||||
return BlockSoundGroup.DEEPSLATE_TILES;
|
||||
case "POLISHED_DEEPSLATE":
|
||||
return BlockSoundGroup.POLISHED_DEEPSLATE;
|
||||
case "FROGLIGHT":
|
||||
return BlockSoundGroup.FROGLIGHT;
|
||||
case "FROGSPAWN":
|
||||
return BlockSoundGroup.FROGSPAWN;
|
||||
case "MANGROVE_ROOTS":
|
||||
return BlockSoundGroup.MANGROVE_ROOTS;
|
||||
case "MUDDY_MANGROVE_ROOTS":
|
||||
return BlockSoundGroup.MUDDY_MANGROVE_ROOTS;
|
||||
case "MUD":
|
||||
return BlockSoundGroup.MUD;
|
||||
case "MUD_BRICKS":
|
||||
return BlockSoundGroup.MUD_BRICKS;
|
||||
case "PACKED_MUD":
|
||||
return BlockSoundGroup.PACKED_MUD;
|
||||
case "HANGING_SIGN":
|
||||
return BlockSoundGroup.HANGING_SIGN;
|
||||
case "NETHER_WOOD_HANGING_SIGN":
|
||||
return BlockSoundGroup.NETHER_WOOD_HANGING_SIGN;
|
||||
case "BAMBOO_WOOD_HANGING_SIGN":
|
||||
return BlockSoundGroup.BAMBOO_WOOD_HANGING_SIGN;
|
||||
case "BAMBOO_WOOD":
|
||||
return BlockSoundGroup.BAMBOO_WOOD;
|
||||
case "NETHER_WOOD":
|
||||
return BlockSoundGroup.NETHER_WOOD;
|
||||
case "CHERRY_WOOD":
|
||||
return BlockSoundGroup.CHERRY_WOOD;
|
||||
case "CHERRY_SAPLING":
|
||||
return BlockSoundGroup.CHERRY_SAPLING;
|
||||
case "CHERRY_LEAVES":
|
||||
return BlockSoundGroup.CHERRY_LEAVES;
|
||||
case "CHERRY_WOOD_HANGING_SIGN":
|
||||
return BlockSoundGroup.CHERRY_WOOD_HANGING_SIGN;
|
||||
case "CHISELED_BOOKSHELF":
|
||||
return BlockSoundGroup.CHISELED_BOOKSHELF;
|
||||
case "SUSPICIOUS_SAND":
|
||||
return BlockSoundGroup.SUSPICIOUS_SAND;
|
||||
case "SUSPICIOUS_GRAVEL":
|
||||
return BlockSoundGroup.SUSPICIOUS_GRAVEL;
|
||||
case "DECORATED_POT":
|
||||
return BlockSoundGroup.DECORATED_POT;
|
||||
case "DECORATED_POT_SHATTER":
|
||||
return BlockSoundGroup.DECORATED_POT_SHATTER;
|
||||
default:
|
||||
log(Level.WARN, "Sound group " + s + " not found, using stone");
|
||||
return BlockSoundGroup.STONE;
|
||||
}
|
||||
}
|
||||
|
||||
private Material getMaterial(String s) {
|
||||
switch (s.toUpperCase()) {
|
||||
case "AIR":
|
||||
return Material.AIR;
|
||||
case "STRUCTURE_VOID":
|
||||
return Material.STRUCTURE_VOID;
|
||||
case "PORTAL":
|
||||
return Material.PORTAL;
|
||||
case "CARPET":
|
||||
return Material.CARPET;
|
||||
case "PLANT":
|
||||
return Material.PLANT;
|
||||
case "UNDERWATER_PLANT":
|
||||
return Material.UNDERWATER_PLANT;
|
||||
case "REPLACEABLE_PLANT":
|
||||
return Material.REPLACEABLE_PLANT;
|
||||
case "NETHER_SHOOTS":
|
||||
return Material.NETHER_SHOOTS;
|
||||
case "REPLACEABLE_UNDERWATER_PLANT":
|
||||
case "SEAGRASS":
|
||||
return Material.REPLACEABLE_UNDERWATER_PLANT;
|
||||
case "WATER":
|
||||
return Material.WATER;
|
||||
case "BUBBLE_COLUMN":
|
||||
return Material.BUBBLE_COLUMN;
|
||||
case "LAVA":
|
||||
return Material.LAVA;
|
||||
case "SNOW_LAYER":
|
||||
case "SNOW":
|
||||
return Material.SNOW_LAYER;
|
||||
case "FIRE":
|
||||
return Material.FIRE;
|
||||
case "SUPPORTED":
|
||||
case "PART":
|
||||
return Material.SUPPORTED;
|
||||
case "COBWEB":
|
||||
return Material.COBWEB;
|
||||
case "REDSTONE_LAMP":
|
||||
return Material.REDSTONE_LAMP;
|
||||
case "ORGANIC_PRODUCT":
|
||||
case "CLAY":
|
||||
return Material.ORGANIC_PRODUCT;
|
||||
case "SOIL":
|
||||
case "EARTH":
|
||||
return Material.SOIL;
|
||||
case "SOLID_ORGANIC":
|
||||
case "ORGANIC":
|
||||
return Material.SOLID_ORGANIC;
|
||||
case "DENSE_ICE":
|
||||
case "PACKED_ICE":
|
||||
return Material.DENSE_ICE;
|
||||
case "AGGREGATE":
|
||||
case "SAND":
|
||||
return Material.AGGREGATE;
|
||||
case "SPONGE":
|
||||
return Material.SPONGE;
|
||||
case "SHULKER_BOX":
|
||||
return Material.SHULKER_BOX;
|
||||
case "WOOD":
|
||||
return Material.WOOD;
|
||||
case "NETHER_WOOD":
|
||||
return Material.NETHER_WOOD;
|
||||
case "BAMBOO_SAPLING":
|
||||
return Material.BAMBOO_SAPLING;
|
||||
case "BAMBOO":
|
||||
return Material.BAMBOO;
|
||||
case "WOOL":
|
||||
return Material.WOOL;
|
||||
case "TNT":
|
||||
return Material.TNT;
|
||||
case "LEAVES":
|
||||
return Material.LEAVES;
|
||||
case "GLASS":
|
||||
return Material.GLASS;
|
||||
case "ICE":
|
||||
return Material.ICE;
|
||||
case "CACTUS":
|
||||
return Material.CACTUS;
|
||||
case "STONE":
|
||||
return Material.STONE;
|
||||
case "METAL":
|
||||
return Material.METAL;
|
||||
case "SNOW_BLOCK":
|
||||
return Material.SNOW_BLOCK;
|
||||
case "REPAIR_STATION":
|
||||
case "ANVIL":
|
||||
return Material.REPAIR_STATION;
|
||||
case "BARRIER":
|
||||
return Material.BARRIER;
|
||||
case "PISTON":
|
||||
return Material.PISTON;
|
||||
case "UNUSED_PLANT":
|
||||
return Material.UNUSED_PLANT;
|
||||
case "GOURD":
|
||||
case "PUMPKIN":
|
||||
return Material.GOURD;
|
||||
case "EGG":
|
||||
return Material.EGG;
|
||||
case "CAKE":
|
||||
return Material.CAKE;
|
||||
default:
|
||||
log(Level.WARN, "Material " + s + " not found, using stone");
|
||||
return Material.STONE;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -11,5 +11,19 @@ public class BlockSettingsPojo {
|
||||
public float slowDownMultiplier = 1.0F;
|
||||
public float jumpVelocityMultiplier = 1.0F;
|
||||
public boolean opaque = true;
|
||||
public boolean allowsSpawning = true;
|
||||
public boolean solidBlock = true;
|
||||
public boolean suffocates = true;
|
||||
public boolean blockVision = true;
|
||||
public boolean postProcess = false;
|
||||
public boolean emissiveLighting = false;
|
||||
public String modelOffset = "none";
|
||||
public String pistonBehavior = "normal";
|
||||
public String instrument = "harp";
|
||||
public boolean burnable = false;
|
||||
public boolean replaceable = false;
|
||||
public boolean noBlockBreakParticles = false;
|
||||
public boolean requiresTool = false;
|
||||
public boolean breaksInstantly = false;
|
||||
String mapColor = "stone";
|
||||
}
|
||||
|
||||
@@ -1,33 +1,24 @@
|
||||
package quimufu.simple_creator;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParseException;
|
||||
import me.shedaniel.autoconfig.AutoConfig;
|
||||
import net.fabricmc.fabric.impl.resource.loader.ModResourcePackCreator;
|
||||
import net.minecraft.resource.*;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.JsonHelper;
|
||||
import net.minecraft.util.Pair;
|
||||
import org.apache.logging.log4j.Level;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import static net.minecraft.resource.ResourcePackSource.method_29486;
|
||||
import static quimufu.simple_creator.SimpleCreatorMod.log;
|
||||
|
||||
public abstract class GenericManualResourceLoader<T> {
|
||||
private Gson GSON;
|
||||
private String dataType;
|
||||
private SimpleCreatorConfig config;
|
||||
private final Gson gson;
|
||||
private final String dataType;
|
||||
|
||||
GenericManualResourceLoader(Gson gson, String dt) {
|
||||
GSON = gson;
|
||||
this.gson = gson;
|
||||
dataType = dt;
|
||||
}
|
||||
|
||||
@@ -51,73 +42,91 @@ public abstract class GenericManualResourceLoader<T> {
|
||||
protected abstract void save(Identifier id, T item);
|
||||
|
||||
public void load() {
|
||||
config = AutoConfig.getConfigHolder(SimpleCreatorConfig.class).getConfig();
|
||||
ResourcePackManager resourcePackManager;
|
||||
if (!config.enableTestThings) {
|
||||
resourcePackManager =
|
||||
new ResourcePackManager(ResourcePackProfile::new,
|
||||
new VanillaDataPackProvider(),
|
||||
new FileResourcePackProvider(new File("./datapacks"), method_29486("pack.source.global")));
|
||||
} else {
|
||||
resourcePackManager =
|
||||
new ResourcePackManager(ResourcePackProfile::new,
|
||||
new VanillaDataPackProvider(),
|
||||
new FileResourcePackProvider(new File("./datapacks"), method_29486("pack.source.global")),
|
||||
new ModResourcePackCreator(ResourceType.SERVER_DATA));
|
||||
}
|
||||
resourcePackManager.scanPacks();
|
||||
List<ResourcePackProfile> ep = Lists.newArrayList(resourcePackManager.getEnabledProfiles());
|
||||
for (ResourcePackProfile rpp : resourcePackManager.getProfiles()) {
|
||||
if (!ep.contains(rpp)) {
|
||||
rpp.getInitialPosition().insert(ep, rpp, resourcePackProfile -> resourcePackProfile, false);
|
||||
}
|
||||
}
|
||||
resourcePackManager.setEnabledProfiles(ep.stream().map(ResourcePackProfile::getName).collect(Collectors.toList()));
|
||||
|
||||
if (true) {
|
||||
createFromResource("simple_creator/blocks/test_block.json");
|
||||
createFromResource("simple_creator/items/test_item.json");
|
||||
}
|
||||
File location = new File("./simplyCreated");
|
||||
|
||||
if (!location.exists() && !location.mkdirs()) {
|
||||
throw new IllegalStateException("Couldn't create dir: " + location);
|
||||
}
|
||||
|
||||
if (!location.isDirectory()) {
|
||||
throw new IllegalStateException("Not a dir: " + location);
|
||||
}
|
||||
|
||||
File[] modIds = location.listFiles();
|
||||
ArrayList<Pair<Identifier, JsonObject>> itemJsonList = new ArrayList<>();
|
||||
HashMap<Identifier, JsonObject> itemJsonMap = Maps.newHashMap();
|
||||
for (ResourcePackProfile rpp : resourcePackManager.getEnabledProfiles()) {
|
||||
ResourcePack rp = rpp.createResourcePack();
|
||||
log(Level.INFO, "Loading ResourcePack " + rp.getName());
|
||||
for (String ns : rp.getNamespaces(ResourceType.SERVER_DATA)) {
|
||||
log(Level.INFO, "Loading namespace " + ns);
|
||||
Collection<Identifier> resources = rp.findResources(ResourceType.SERVER_DATA, ns, dataType, 5, s -> s.endsWith(".json"));
|
||||
for (Identifier id : resources) {
|
||||
if (config.extendedLogging)
|
||||
log(Level.INFO, "found: " + id.toString() + " in Pack: " + rp.getName());
|
||||
Identifier idNice = new Identifier(id.getNamespace(), getName(id));
|
||||
try {
|
||||
InputStream is = rp.open(ResourceType.SERVER_DATA, id);
|
||||
Reader r = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8));
|
||||
JsonObject jo = JsonHelper.deserialize(GSON, r, JsonObject.class);
|
||||
if (jo != null)
|
||||
if (jo.entrySet().isEmpty()) {
|
||||
itemJsonMap.remove(idNice);
|
||||
if (config.extendedLogging)
|
||||
log(Level.INFO, "deleting " + idNice + " because of an empty override in " + rp.getName());
|
||||
} else {
|
||||
itemJsonMap.put(idNice, jo);
|
||||
if (config.extendedLogging)
|
||||
log(Level.INFO, "adding " + idNice + " from " + rp.getName());
|
||||
}
|
||||
if(modIds == null){
|
||||
log(Level.INFO, "No files found at " + location + " quitting!");
|
||||
return;
|
||||
}
|
||||
for (File mod : modIds) {
|
||||
if (!mod.isDirectory()) {
|
||||
continue;
|
||||
}
|
||||
String modId = mod.getName();
|
||||
|
||||
File entryDir = new File(mod + "/" + dataType);
|
||||
if (entryDir.isDirectory()) {
|
||||
File[] entries = entryDir.listFiles();
|
||||
if(entries == null){
|
||||
log(Level.INFO, "No files found at " + entryDir + " skipping!");
|
||||
continue;
|
||||
}
|
||||
|
||||
for (File entryJson : entries) {
|
||||
String blockJsonName = entryJson.getName();
|
||||
if(!blockJsonName.endsWith(".json")){
|
||||
log(Level.INFO, "Non json found at " + entryJson + " ignoring!");
|
||||
continue;
|
||||
}
|
||||
String entryName = blockJsonName.substring(0,blockJsonName.length()-5);
|
||||
Identifier identifier = new Identifier(modId, entryName);
|
||||
|
||||
try (Reader reader = new FileReader(entryJson)) {
|
||||
JsonObject jsonObject = gson.fromJson(reader, JsonObject.class);
|
||||
itemJsonList.add(new Pair<>(identifier, jsonObject));
|
||||
} catch (IOException e) {
|
||||
log(Level.ERROR, "error loading " + id + " " + e.getMessage());
|
||||
} catch (JsonParseException e) {
|
||||
log(Level.ERROR, "error parsing json for " + id + " " + e.getMessage());
|
||||
log(Level.INFO, "Could not parse " + entryJson + " ignoring!");
|
||||
e.printStackTrace();
|
||||
log(Level.INFO, e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (Map.Entry<Identifier, JsonObject> e : itemJsonMap.entrySet()) {
|
||||
itemJsonList.add(new Pair<>(e.getKey(), e.getValue()));
|
||||
}
|
||||
|
||||
loadItems(itemJsonList);
|
||||
|
||||
}
|
||||
|
||||
private String getName(Identifier id) {
|
||||
String path = id.getPath();
|
||||
int startLength = dataType.length() + 1;
|
||||
int endLength = ".json".length();
|
||||
return path.substring(startLength, path.length() - endLength);
|
||||
private static void createFromResource(String path) {
|
||||
try (InputStream blocks = ClassLoader.getSystemClassLoader().getResourceAsStream("data/" + path)) {
|
||||
|
||||
File file = new File("./simplyCreated/" + path);
|
||||
if (!file.exists() && blocks != null) {
|
||||
|
||||
File parent = file.getParentFile();
|
||||
if (parent != null && !parent.exists() && !parent.mkdirs()) {
|
||||
throw new IllegalStateException("Couldn't create dir: " + parent);
|
||||
}
|
||||
if (!file.createNewFile()) {
|
||||
throw new IllegalStateException("Couldn't create file: " + file);
|
||||
}
|
||||
|
||||
try (FileOutputStream out = new FileOutputStream(file)) {
|
||||
//copy stream
|
||||
byte[] buffer = new byte[1024];
|
||||
int bytesRead;
|
||||
while ((bytesRead = blocks.read(buffer)) != -1) {
|
||||
out.write(buffer, 0, bytesRead);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,20 +2,26 @@ package quimufu.simple_creator;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.gson.*;
|
||||
import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents;
|
||||
import net.minecraft.entity.effect.StatusEffect;
|
||||
import net.minecraft.entity.effect.StatusEffectInstance;
|
||||
import net.minecraft.item.FoodComponent;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemGroup;
|
||||
import net.minecraft.item.ItemGroups;
|
||||
import net.minecraft.registry.Registries;
|
||||
import net.minecraft.registry.Registry;
|
||||
import net.minecraft.registry.RegistryKey;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.JsonHelper;
|
||||
import net.minecraft.util.Pair;
|
||||
import net.minecraft.util.Rarity;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import org.apache.logging.log4j.Level;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static quimufu.simple_creator.SimpleCreatorMod.log;
|
||||
|
||||
@@ -30,13 +36,13 @@ public class ItemResourceLoader extends GenericManualResourceLoader<Item> {
|
||||
|
||||
@Override
|
||||
protected void register(Identifier id, Item thing) {
|
||||
Registry.register(Registry.ITEM, id, thing);
|
||||
Registry.register(Registries.ITEM, id, thing);
|
||||
}
|
||||
|
||||
public Item deserialize(Pair<Identifier, JsonObject> e) {
|
||||
JsonObject jo = e.getRight();
|
||||
String group = JsonHelper.getString(jo, "group", "misc");
|
||||
ItemGroup g = findGroup(group);
|
||||
RegistryKey<ItemGroup> g = findGroup(group);
|
||||
int durability = JsonHelper.getInt(jo, "durability", 0);
|
||||
byte stackSize = JsonHelper.getByte(jo, "stackSize", (byte) 1);
|
||||
boolean isFood = JsonHelper.hasElement(jo, "food");
|
||||
@@ -44,7 +50,6 @@ public class ItemResourceLoader extends GenericManualResourceLoader<Item> {
|
||||
|
||||
|
||||
Item.Settings settings = new Item.Settings();
|
||||
settings.group(g);
|
||||
if (isFood) {
|
||||
if (durability != 0) {
|
||||
log(Level.WARN, "durability does not work with food");
|
||||
@@ -65,7 +70,12 @@ public class ItemResourceLoader extends GenericManualResourceLoader<Item> {
|
||||
}
|
||||
}
|
||||
settings.rarity(findRarity(rarity));
|
||||
return new Item(settings);
|
||||
|
||||
|
||||
Item item = new Item(settings);
|
||||
ItemGroupEvents.modifyEntriesEvent(g).register(content -> content.add(item));
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -104,7 +114,7 @@ public class ItemResourceLoader extends GenericManualResourceLoader<Item> {
|
||||
String effect = JsonHelper.getString(jo, "effect");
|
||||
Identifier ei = Identifier.tryParse(effect);
|
||||
if (ei != null) {
|
||||
StatusEffect se = Registry.STATUS_EFFECT.get(ei);
|
||||
StatusEffect se = Registries.STATUS_EFFECT.get(ei);
|
||||
if (se != null) {
|
||||
type = se;
|
||||
} else {
|
||||
@@ -134,15 +144,21 @@ public class ItemResourceLoader extends GenericManualResourceLoader<Item> {
|
||||
return Rarity.COMMON;
|
||||
}
|
||||
|
||||
public static ItemGroup findGroup(String filter) {
|
||||
for (ItemGroup g : ItemGroup.GROUPS) {
|
||||
if (g.getName().equalsIgnoreCase(filter)) {
|
||||
return g;
|
||||
}
|
||||
public static RegistryKey<ItemGroup> findGroup(String filter) {
|
||||
Identifier identifier = Identifier.tryParse(filter);
|
||||
ItemGroup itemGroup = Registries.ITEM_GROUP.get(identifier);
|
||||
Optional<RegistryKey<ItemGroup>> optionalRegistryKey = Registries.ITEM_GROUP.getKey(itemGroup);
|
||||
if (optionalRegistryKey.isPresent()) {
|
||||
return optionalRegistryKey.get();
|
||||
}
|
||||
log(Level.WARN, "Item Group " + filter + " not found, using misc");
|
||||
log(Level.INFO, "Valid groups:" + Arrays.stream(ItemGroup.GROUPS).map(ItemGroup::getName));
|
||||
return ItemGroup.MISC;
|
||||
log(Level.WARN, "Item Group " + filter + " not found, using minecraft:building_blocks");
|
||||
|
||||
log(Level.INFO, "Valid groups:" + Registries.ITEM_GROUP.getKeys()
|
||||
.stream()
|
||||
.map(RegistryKey::getValue)
|
||||
.map(Identifier::toString)
|
||||
.collect(Collectors.joining(",")));
|
||||
return ItemGroups.BUILDING_BLOCKS;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
package quimufu.simple_creator;
|
||||
|
||||
import net.minecraft.block.MaterialColor;
|
||||
import net.minecraft.block.piston.PistonBehavior;
|
||||
|
||||
public class MaterialSettingsPojo {
|
||||
String materialColor = "PINK";
|
||||
String pistonBehavior = "normal";
|
||||
boolean blocksMovement = true;
|
||||
boolean burnable = false;
|
||||
boolean breakByHand = true;
|
||||
boolean liquid = false;
|
||||
boolean solid = true;
|
||||
boolean blocksLight = true;
|
||||
}
|
||||
@@ -1,10 +1,19 @@
|
||||
package quimufu.simple_creator;
|
||||
|
||||
import me.shedaniel.autoconfig.ConfigData;
|
||||
import me.shedaniel.autoconfig.annotation.Config;
|
||||
import com.google.common.base.CaseFormat;
|
||||
import de.siphalor.tweed4.annotated.AConfigEntry;
|
||||
import de.siphalor.tweed4.annotated.ATweedConfig;
|
||||
import de.siphalor.tweed4.config.ConfigEnvironment;
|
||||
import de.siphalor.tweed4.config.ConfigScope;
|
||||
|
||||
@Config(name = "simple_creator")
|
||||
public class SimpleCreatorConfig implements ConfigData {
|
||||
public boolean enableTestThings = false;
|
||||
public boolean extendedLogging = false;
|
||||
|
||||
@ATweedConfig(serializer = "tweed4:hjson", scope = ConfigScope.GAME, environment = ConfigEnvironment.UNIVERSAL, tailors = {"tweed4:lang_json_descriptions", "tweed4:coat", "tweed4:json_schema"}, casing = CaseFormat.LOWER_HYPHEN)
|
||||
//@ClothData(modid = "tweed4_testmod")
|
||||
public class SimpleCreatorConfig {
|
||||
|
||||
@AConfigEntry(name = "enableTestThings", comment = "Enables included test Blocks and Items")
|
||||
public static boolean enableTestThings = false;
|
||||
|
||||
|
||||
public static boolean extendedLogging = false;
|
||||
}
|
||||
|
||||
@@ -1,16 +1,10 @@
|
||||
package quimufu.simple_creator;
|
||||
|
||||
import me.shedaniel.autoconfig.AutoConfig;
|
||||
import me.shedaniel.autoconfig.serializer.GsonConfigSerializer;
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
import org.apache.logging.log4j.Level;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
//import net.minecraft.block.Material;
|
||||
|
||||
//import java.lang.reflect.Field;
|
||||
|
||||
public class SimpleCreatorMod implements ModInitializer {
|
||||
|
||||
public static Logger LOGGER = LogManager.getLogger();
|
||||
@@ -23,28 +17,6 @@ public class SimpleCreatorMod implements ModInitializer {
|
||||
@Override
|
||||
public void onInitialize() {
|
||||
log(Level.INFO, "Initializing");
|
||||
AutoConfig.register(SimpleCreatorConfig.class, GsonConfigSerializer::new);
|
||||
// for(Material m : Material.class.getEnumConstants()){
|
||||
// log(Level.INFO, String.valueOf(m.getColor().color));
|
||||
// }
|
||||
// for (Field f : Material.class.getDeclaredFields()) {
|
||||
// log(Level.INFO, f.getName());
|
||||
// try {
|
||||
// Material m = ((Material) f.get(Material.class));
|
||||
// log(Level.INFO, "pistonBehavior: " + m.getPistonBehavior().name());
|
||||
// log(Level.INFO, "blocksMovement: " + m.blocksMovement());
|
||||
// log(Level.INFO, "burnable: " + m.isBurnable());
|
||||
// log(Level.INFO, "breakByHand: " + m.canBreakByHand());
|
||||
// log(Level.INFO, "liquid: " + m.isLiquid());
|
||||
// log(Level.INFO, "replaceable: " + m.isReplaceable());
|
||||
// log(Level.INFO, "solid: " + m.isSolid());
|
||||
// log(Level.INFO, "blocksLight: " + m.blocksLight());
|
||||
// log(Level.INFO, "");
|
||||
// log(Level.INFO, "");
|
||||
//
|
||||
// } catch (IllegalAccessException ignored) {
|
||||
// }
|
||||
// }
|
||||
irl.load();
|
||||
brl.load();
|
||||
}
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
package quimufu.simple_creator;
|
||||
|
||||
|
||||
import com.terraformersmc.modmenu.api.ConfigScreenFactory;
|
||||
import com.terraformersmc.modmenu.api.ModMenuApi;
|
||||
import me.shedaniel.autoconfig.AutoConfig;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
|
||||
public class SimpleCreatorModMenuIntegration implements ModMenuApi {
|
||||
|
||||
@Override
|
||||
public ConfigScreenFactory<?> getModConfigScreenFactory() {
|
||||
return this::getScreen;
|
||||
}
|
||||
|
||||
private Screen getScreen(Screen parent) {
|
||||
return AutoConfig.getConfigScreen(SimpleCreatorConfig.class, parent).get();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -18,8 +18,8 @@
|
||||
],
|
||||
"client": [],
|
||||
"server": [],
|
||||
"modmenu": [
|
||||
"quimufu.simple_creator.SimpleCreatorModMenuIntegration"
|
||||
"tweed4:config": [
|
||||
"quimufu.simple_creator.SimpleCreatorConfig"
|
||||
]
|
||||
},
|
||||
"mixins": [],
|
||||
|
||||
Reference in New Issue
Block a user