diff --git a/src/main/java/ru/betterend/blocks/BulbVineLanternColoredBlock.java b/src/main/java/ru/betterend/blocks/BulbVineLanternColoredBlock.java index cc72d55a..a1c7262f 100644 --- a/src/main/java/ru/betterend/blocks/BulbVineLanternColoredBlock.java +++ b/src/main/java/ru/betterend/blocks/BulbVineLanternColoredBlock.java @@ -4,6 +4,7 @@ import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.minecraft.client.color.block.BlockColorProvider; import net.minecraft.client.color.item.ItemColorProvider; import ru.betterend.interfaces.IColorProvider; +import ru.betterend.util.BlocksHelper; import ru.betterend.util.MHelper; public class BulbVineLanternColoredBlock extends BulbVineLanternBlock implements IColorProvider { @@ -26,7 +27,7 @@ public class BulbVineLanternColoredBlock extends BulbVineLanternBlock implements } private int getColor() { - int color = this.getDefaultMaterialColor().color; + int color = BlocksHelper.getBlockColor(this); int b = (color & 255); int g = ((color >> 8) & 255); int r = ((color >> 16) & 255); diff --git a/src/main/java/ru/betterend/blocks/HydraluxPetalColoredBlock.java b/src/main/java/ru/betterend/blocks/HydraluxPetalColoredBlock.java index 4cd1adb1..5e1a0eed 100644 --- a/src/main/java/ru/betterend/blocks/HydraluxPetalColoredBlock.java +++ b/src/main/java/ru/betterend/blocks/HydraluxPetalColoredBlock.java @@ -8,6 +8,7 @@ import net.minecraft.client.color.item.ItemColorProvider; import net.minecraft.util.Identifier; import ru.betterend.interfaces.IColorProvider; import ru.betterend.patterns.Patterns; +import ru.betterend.util.BlocksHelper; public class HydraluxPetalColoredBlock extends HydraluxPetalBlock implements IColorProvider { public HydraluxPetalColoredBlock(FabricBlockSettings settings) { @@ -17,14 +18,14 @@ public class HydraluxPetalColoredBlock extends HydraluxPetalBlock implements ICo @Override public BlockColorProvider getProvider() { return (state, world, pos, tintIndex) -> { - return this.getDefaultMaterialColor().color; + return BlocksHelper.getBlockColor(this); }; } @Override public ItemColorProvider getItemProvider() { return (stack, tintIndex) -> { - return this.getDefaultMaterialColor().color; + return BlocksHelper.getBlockColor(this); }; } diff --git a/src/main/java/ru/betterend/blocks/complex/ColoredMaterial.java b/src/main/java/ru/betterend/blocks/complex/ColoredMaterial.java index 33955b27..ab5e9dc9 100644 --- a/src/main/java/ru/betterend/blocks/complex/ColoredMaterial.java +++ b/src/main/java/ru/betterend/blocks/complex/ColoredMaterial.java @@ -7,32 +7,54 @@ import com.google.common.collect.Maps; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.minecraft.block.Block; +import net.minecraft.block.MaterialColor; import net.minecraft.item.DyeItem; +import net.minecraft.item.ItemConvertible; import net.minecraft.util.DyeColor; import net.minecraft.util.registry.Registry; import ru.betterend.recipe.builders.GridRecipe; import ru.betterend.registry.EndBlocks; +import ru.betterend.util.BlocksHelper; public class ColoredMaterial { - private final Map colors = Maps.newEnumMap(DyeColor.class); + private static final Map DYES = Maps.newHashMap(); + private static final Map COLORS = Maps.newHashMap(); + private final Map colors = Maps.newHashMap(); public ColoredMaterial(Function constructor, Block source, boolean craftEight) { + this(constructor, source, COLORS, DYES, craftEight); + } + + public ColoredMaterial(Function constructor, Block source, Map colors, Map dyes, boolean craftEight) { String id = Registry.BLOCK.getId(source).getPath(); - for (DyeColor color: DyeColor.values()) { - Block block = constructor.apply(FabricBlockSettings.copyOf(source).materialColor(color)); - String blockName = id + "_" + color.getName(); + colors.forEach((color, name) -> { + String blockName = id + "_" + name; + Block block = constructor.apply(FabricBlockSettings.copyOf(source).materialColor(MaterialColor.BLACK)); EndBlocks.registerBlock(blockName, block); if (craftEight) { - GridRecipe.make(blockName, block).setOutputCount(8).setShape("###", "#D#", "###").addMaterial('#', source).addMaterial('D', DyeItem.byColor(color)).build(); + GridRecipe.make(blockName, block).setOutputCount(8).setShape("###", "#D#", "###").addMaterial('#', source).addMaterial('D', dyes.get(color)).build(); } else { - GridRecipe.make(blockName, block).setList("#D").addMaterial('#', source).addMaterial('D', DyeItem.byColor(color)).build(); + GridRecipe.make(blockName, block).setList("#D").addMaterial('#', source).addMaterial('D', dyes.get(color)).build(); } - colors.put(color, block); - } - } + this.colors.put(color, block); + BlocksHelper.addBlockColor(block, color); + }); + } public Block getByColor(DyeColor color) { + return colors.get(color.getMaterialColor().color); + } + + public Block getByColor(int color) { return colors.get(color); } + + static { + for (DyeColor color: DyeColor.values()) { + int colorRGB = color.getMaterialColor().color; + COLORS.put(colorRGB, color.getName()); + DYES.put(colorRGB, DyeItem.byColor(color)); + } + } } diff --git a/src/main/java/ru/betterend/integration/FlamboyantRefabricatedIntegration.java b/src/main/java/ru/betterend/integration/FlamboyantRefabricatedIntegration.java new file mode 100644 index 00000000..09255141 --- /dev/null +++ b/src/main/java/ru/betterend/integration/FlamboyantRefabricatedIntegration.java @@ -0,0 +1,67 @@ +package ru.betterend.integration; + +import java.awt.Color; +import java.util.Map; + +import com.google.common.collect.Maps; + +import net.minecraft.item.ItemConvertible; +import ru.betterend.blocks.HydraluxPetalColoredBlock; +import ru.betterend.blocks.complex.ColoredMaterial; +import ru.betterend.registry.EndBlocks; +import ru.betterend.util.MHelper; + +public class FlamboyantRefabricatedIntegration extends ModIntegration { + public FlamboyantRefabricatedIntegration() { + super("flamboyant"); + } + + @Override + public void register() { + /*Class fDyeColor = getClass("com.github.EltrutCo.flamboyant.items.FDyeColor"); + Object[] values = getStaticFieldValue(fDyeColor, "VALUES"); + + if (values == null) { + return; + }*/ + + Map colors = Maps.newHashMap(); + Map dyes = Maps.newHashMap(); + /*for (Object val: values) { + Integer color = (Integer) getFieldValue(fDyeColor, "signColor", val); + String name = (String) getFieldValue(fDyeColor, "name", val); + if (color != null && name != null) { + colors.put(color, name); + System.out.println(name + " " + color + " " + new Color(color)); + dyes.put(color, getItem(name + "_dye")); + } + }*/ + + addColor("fead1d", "amber", colors, dyes); + addColor("bd9a5f", "beige", colors, dyes); + addColor("edeada", "cream", colors, dyes); + addColor("33430e", "dark_green", colors, dyes); + addColor("639920", "forest_green", colors, dyes); + addColor("f0618c", "hot_pink", colors, dyes); + addColor("491c7b", "indigo", colors, dyes); + addColor("65291b", "maroon", colors, dyes); + addColor("2c3969", "navy", colors, dyes); + addColor("827c17", "olive", colors, dyes); + addColor("7bc618", "pale_green", colors, dyes); + addColor("f4a4bd", "pale_pink", colors, dyes); + addColor("f8d45a", "pale_yellow", colors, dyes); + addColor("6bb1cf", "sky_blue", colors, dyes); + addColor("6e8c9c", "slate_gray", colors, dyes); + addColor("b02454", "violet", colors, dyes); + + new ColoredMaterial(HydraluxPetalColoredBlock::new, EndBlocks.HYDRALUX_PETAL_BLOCK, colors, dyes, true); + } + + private void addColor(String hex, String name, Map colors, Map dyes) { + int color = MHelper.color(hex); + colors.put(color, name); + dyes.put(color, getItem(name + "_dye")); + + System.out.println(name + " " + color + " " + new Color(color)); + } +} diff --git a/src/main/java/ru/betterend/integration/Integrations.java b/src/main/java/ru/betterend/integration/Integrations.java index e139c5df..6d7664f1 100644 --- a/src/main/java/ru/betterend/integration/Integrations.java +++ b/src/main/java/ru/betterend/integration/Integrations.java @@ -12,6 +12,7 @@ public class Integrations { public static final ModIntegration NOURISH = register(new NourishIntegration()); //public static final ModIntegration EXTRA_PIECES = register(new ExtraPiecesIntegration()); //public static final ModIntegration ADORN = register(new AdornIntegration()); + public static final ModIntegration FLAMBOYANT_REFABRICATED = register(new FlamboyantRefabricatedIntegration()); public static void register() { INTEGRATIONS.forEach((integration) -> { diff --git a/src/main/java/ru/betterend/integration/ModIntegration.java b/src/main/java/ru/betterend/integration/ModIntegration.java index 07074df6..60d8f80b 100644 --- a/src/main/java/ru/betterend/integration/ModIntegration.java +++ b/src/main/java/ru/betterend/integration/ModIntegration.java @@ -28,9 +28,9 @@ import ru.betterend.world.features.EndFeature; public abstract class ModIntegration { private final String modID; - public abstract void register(); + public void register() {} - public abstract void addBiomes(); + public void addBiomes() {} public ModIntegration(String modID) { this.modID = modID; @@ -43,6 +43,10 @@ public abstract class ModIntegration { public Block getBlock(String name) { return Registry.BLOCK.get(getID(name)); } + + public Item getItem(String name) { + return Registry.ITEM.get(getID(name)); + } public BlockState getDefaultState(String name) { return getBlock(name).getDefaultState(); diff --git a/src/main/java/ru/betterend/integration/NourishIntegration.java b/src/main/java/ru/betterend/integration/NourishIntegration.java index 3e700dbd..de54e081 100644 --- a/src/main/java/ru/betterend/integration/NourishIntegration.java +++ b/src/main/java/ru/betterend/integration/NourishIntegration.java @@ -22,7 +22,4 @@ public class NourishIntegration extends ModIntegration { TagHelper.addTag(protein, EndItems.END_FISH_RAW, EndItems.END_FISH_COOKED); TagHelper.addTag(sweets, EndItems.SHADOW_BERRY_JELLY, EndItems.SWEET_BERRY_JELLY); } - - @Override - public void addBiomes() {} } diff --git a/src/main/java/ru/betterend/util/BlocksHelper.java b/src/main/java/ru/betterend/util/BlocksHelper.java index 8c39751a..87371a24 100644 --- a/src/main/java/ru/betterend/util/BlocksHelper.java +++ b/src/main/java/ru/betterend/util/BlocksHelper.java @@ -2,9 +2,11 @@ package ru.betterend.util; import java.util.HashSet; import java.util.Iterator; +import java.util.Map; import java.util.Random; import java.util.Set; +import com.google.common.collect.Maps; import com.google.common.collect.Sets; import net.minecraft.block.Block; @@ -31,6 +33,7 @@ import ru.betterend.registry.EndTags; public class BlocksHelper { public static final BooleanProperty ROOTS = BooleanProperty.of("roots"); + private static final Map COLOR_BY_BLOCK = Maps.newHashMap(); public static final int FLAG_UPDATE_BLOCK = 1; public static final int FLAG_SEND_CLIENT_CHANGES = 2; @@ -60,6 +63,14 @@ public class BlocksHelper { new Vec3i(1, 0, -1), new Vec3i(1, 0, 0), new Vec3i(1, 0, 1), new Vec3i(1, 1, -1), new Vec3i(1, 1, 0), new Vec3i(1, 1, 1) }; + + public static void addBlockColor(Block block, int color) { + COLOR_BY_BLOCK.put(block, color); + } + + public static int getBlockColor(Block block) { + return COLOR_BY_BLOCK.getOrDefault(block, 0xFF000000); + } public static void setWithoutUpdate(WorldAccess world, BlockPos pos, BlockState state) { world.setBlockState(pos, state, SET_SILENT); diff --git a/src/main/java/ru/betterend/util/MHelper.java b/src/main/java/ru/betterend/util/MHelper.java index 1132dd22..3db1bc5d 100644 --- a/src/main/java/ru/betterend/util/MHelper.java +++ b/src/main/java/ru/betterend/util/MHelper.java @@ -15,6 +15,13 @@ public class MHelper { public static int color(int r, int g, int b) { return ALPHA | (r << 16) | (g << 8) | b; } + + public static int color(String hex) { + int r = Integer.parseInt(hex.substring(0, 2), 16); + int g = Integer.parseInt(hex.substring(2, 4), 16); + int b = Integer.parseInt(hex.substring(4, 6), 16); + return color(r, g, b); + } public static int randRange(int min, int max, Random random) { return min + random.nextInt(max - min + 1);