Flamboyant Refabricated Integration (WIP)

This commit is contained in:
paulevsGitch 2021-03-24 22:25:34 +03:00
parent a2ca5fe3df
commit b933b0e522
9 changed files with 128 additions and 17 deletions

View file

@ -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);

View file

@ -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);
};
}

View file

@ -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<DyeColor, Block> colors = Maps.newEnumMap(DyeColor.class);
private static final Map<Integer, ItemConvertible> DYES = Maps.newHashMap();
private static final Map<Integer, String> COLORS = Maps.newHashMap();
private final Map<Integer, Block> colors = Maps.newHashMap();
public ColoredMaterial(Function<FabricBlockSettings, Block> constructor, Block source, boolean craftEight) {
this(constructor, source, COLORS, DYES, craftEight);
}
public ColoredMaterial(Function<FabricBlockSettings, Block> constructor, Block source, Map<Integer, String> colors, Map<Integer, ItemConvertible> 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));
}
}
}

View file

@ -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<Integer, String> colors = Maps.newHashMap();
Map<Integer, ItemConvertible> 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<Integer, String> colors, Map<Integer, ItemConvertible> dyes) {
int color = MHelper.color(hex);
colors.put(color, name);
dyes.put(color, getItem(name + "_dye"));
System.out.println(name + " " + color + " " + new Color(color));
}
}

View file

@ -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) -> {

View file

@ -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();

View file

@ -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() {}
}

View file

@ -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<Block, Integer> 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);

View file

@ -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);