Color changing, round 1.

This commit is contained in:
Flanks255 2022-08-03 16:48:00 -05:00
parent 48a2734161
commit f5f154b898
24 changed files with 379 additions and 4 deletions

View file

@ -589,6 +589,22 @@ c9fc3f11f3bf5a928ea9f5900c344461d61fe9e5 data/actuallyadditions/recipes/black_qu
7dc02da1ff58eb4ff48e305437d4857c31cbd5c9 data/actuallyadditions/recipes/chiseled_black_quartz_slab.json
bf1b5de98f29c2dabe25a143c8e63d2c0cd6ea72 data/actuallyadditions/recipes/chiseled_black_quartz_stair.json
9d779585266046738b4bcf7447b918ec09b65f95 data/actuallyadditions/recipes/chiseled_black_quartz_wall.json
4c0d56c3a6db66bbeb74cb72ecedfbb115448d83 data/actuallyadditions/recipes/colorchange/black_wool.json
5c698c51d21723c8a13e329673a4c8d703da359d data/actuallyadditions/recipes/colorchange/blue_wool.json
818ab2ea65a94fa5ff8db6c5a5d106eec32816fd data/actuallyadditions/recipes/colorchange/brown_wool.json
37168cf7f51bdd26a1cb74d5fc3eccd835f7f566 data/actuallyadditions/recipes/colorchange/cyan_wool.json
e6fa0fd781c0deb18997b92237a097df2bfa14b7 data/actuallyadditions/recipes/colorchange/gray_wool.json
efb6a3385546c7c6b74e45f33d40dcdbfe7ad23a data/actuallyadditions/recipes/colorchange/green_wool.json
915d5ea71aa02d991a194574a085e7e41e733803 data/actuallyadditions/recipes/colorchange/light_blue_wool.json
9f5a91dc8b31444492fc77dcd2405375db1ba378 data/actuallyadditions/recipes/colorchange/light_gray_wool.json
41e623b3c6730f283a17ab9b293c3dbfb6688a4b data/actuallyadditions/recipes/colorchange/lime_wool.json
5754feb7b97b2e5bed1a44d6b6121d0e6b6d411c data/actuallyadditions/recipes/colorchange/magenta_wool.json
5d34d7ba1302af791ca85fd2f023470328e604b6 data/actuallyadditions/recipes/colorchange/orange_wool.json
e3bf0e1777bd2d495162411424fd7aadcb72c96d data/actuallyadditions/recipes/colorchange/pink_wool.json
0ceb76358bfbc1e289e1d076683870978071a929 data/actuallyadditions/recipes/colorchange/purple_wool.json
a7fdacc3fe3040376fec72cb64efb48305044c6d data/actuallyadditions/recipes/colorchange/red_wool.json
48142b653fd55f8cb373541d590d96c94fe182db data/actuallyadditions/recipes/colorchange/white_wool.json
ca4f8d37d115eac5889542b04d1c01cd2e0cde43 data/actuallyadditions/recipes/colorchange/yellow_wool.json
160466dfd10fafc2ae4b4130ca35220d4c2d2342 data/actuallyadditions/recipes/crate_keeper.json
b76b843a60a1c456a11d3bb932a93ab3753d6f58 data/actuallyadditions/recipes/crushing/bone_crusher.json
293cecfa94d22e62bd817a3964e82dca4479d44d data/actuallyadditions/recipes/diamond_aiot.json

View file

@ -0,0 +1,9 @@
{
"type": "actuallyadditions:color_change",
"ingredient": {
"item": "minecraft:red_wool"
},
"result": {
"item": "minecraft:black_wool"
}
}

View file

@ -0,0 +1,9 @@
{
"type": "actuallyadditions:color_change",
"ingredient": {
"item": "minecraft:purple_wool"
},
"result": {
"item": "minecraft:blue_wool"
}
}

View file

@ -0,0 +1,9 @@
{
"type": "actuallyadditions:color_change",
"ingredient": {
"item": "minecraft:blue_wool"
},
"result": {
"item": "minecraft:brown_wool"
}
}

View file

@ -0,0 +1,9 @@
{
"type": "actuallyadditions:color_change",
"ingredient": {
"item": "minecraft:light_gray_wool"
},
"result": {
"item": "minecraft:cyan_wool"
}
}

View file

@ -0,0 +1,9 @@
{
"type": "actuallyadditions:color_change",
"ingredient": {
"item": "minecraft:pink_wool"
},
"result": {
"item": "minecraft:gray_wool"
}
}

View file

@ -0,0 +1,9 @@
{
"type": "actuallyadditions:color_change",
"ingredient": {
"item": "minecraft:brown_wool"
},
"result": {
"item": "minecraft:green_wool"
}
}

View file

@ -0,0 +1,9 @@
{
"type": "actuallyadditions:color_change",
"ingredient": {
"item": "minecraft:magenta_wool"
},
"result": {
"item": "minecraft:light_blue_wool"
}
}

View file

@ -0,0 +1,9 @@
{
"type": "actuallyadditions:color_change",
"ingredient": {
"item": "minecraft:gray_wool"
},
"result": {
"item": "minecraft:light_gray_wool"
}
}

View file

@ -0,0 +1,9 @@
{
"type": "actuallyadditions:color_change",
"ingredient": {
"item": "minecraft:yellow_wool"
},
"result": {
"item": "minecraft:lime_wool"
}
}

View file

@ -0,0 +1,9 @@
{
"type": "actuallyadditions:color_change",
"ingredient": {
"item": "minecraft:orange_wool"
},
"result": {
"item": "minecraft:magenta_wool"
}
}

View file

@ -0,0 +1,9 @@
{
"type": "actuallyadditions:color_change",
"ingredient": {
"item": "minecraft:white_wool"
},
"result": {
"item": "minecraft:orange_wool"
}
}

View file

@ -0,0 +1,9 @@
{
"type": "actuallyadditions:color_change",
"ingredient": {
"item": "minecraft:lime_wool"
},
"result": {
"item": "minecraft:pink_wool"
}
}

View file

@ -0,0 +1,9 @@
{
"type": "actuallyadditions:color_change",
"ingredient": {
"item": "minecraft:cyan_wool"
},
"result": {
"item": "minecraft:purple_wool"
}
}

View file

@ -0,0 +1,9 @@
{
"type": "actuallyadditions:color_change",
"ingredient": {
"item": "minecraft:green_wool"
},
"result": {
"item": "minecraft:red_wool"
}
}

View file

@ -0,0 +1,9 @@
{
"type": "actuallyadditions:color_change",
"ingredient": {
"item": "minecraft:black_wool"
},
"result": {
"item": "minecraft:white_wool"
}
}

View file

@ -0,0 +1,9 @@
{
"type": "actuallyadditions:color_change",
"ingredient": {
"item": "minecraft:light_blue_wool"
},
"result": {
"item": "minecraft:yellow_wool"
}
}

View file

@ -46,6 +46,7 @@ public final class ActuallyAdditionsAPI {
public static final List<EmpowererRecipe> EMPOWERER_RECIPES = new ArrayList<>();
public static final Map<Item, IColorLensChanger> RECONSTRUCTOR_LENS_COLOR_CHANGERS = new HashMap<>();
public static final List<ColorChangeRecipe> COLOR_CHANGE_RECIPES = new ArrayList<>();
public static final List<SolidFuelRecipe> SOLID_FUEL_RECIPES = new ArrayList<>();
public static final List<LiquidFuelRecipe> LIQUID_FUEL_RECIPES = new ArrayList<>();
public static final List<PressingRecipe> PRESSING_RECIPES = new ArrayList<>();

View file

@ -30,6 +30,7 @@ public class ActuallyAdditionsData {
generator.addProvider(new ItemModelGenerator(generator, helper));
generator.addProvider(new LaserRecipeGenerator(generator));
generator.addProvider(new ColorChangeGenerator(generator));
generator.addProvider(new EmpoweringRecipeGenerator(generator));
generator.addProvider(new CrushingRecipeGenerator(generator));
generator.addProvider(new FuelRecipeGenerator(generator));

View file

@ -0,0 +1,62 @@
package de.ellpeck.actuallyadditions.data;
import com.google.gson.JsonObject;
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
import de.ellpeck.actuallyadditions.mod.crafting.ColorChangeRecipe;
import de.ellpeck.actuallyadditions.mod.crafting.LaserRecipe;
import net.minecraft.data.DataGenerator;
import net.minecraft.data.DirectoryCache;
import net.minecraft.data.IFinishedRecipe;
import net.minecraft.data.RecipeProvider;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.item.crafting.Ingredient;
import net.minecraft.util.IItemProvider;
import net.minecraft.util.ResourceLocation;
import javax.annotation.Nonnull;
import java.nio.file.Path;
import java.util.function.Consumer;
public class ColorChangeGenerator extends RecipeProvider {
public ColorChangeGenerator(DataGenerator p_i48262_1_) {
super(p_i48262_1_);
}
@Override
protected void saveAdvancement(@Nonnull DirectoryCache pCache, @Nonnull JsonObject pAdvancementJson, @Nonnull Path pPath) {
}
@Override
protected void buildShapelessRecipes(@Nonnull Consumer<IFinishedRecipe> consumer) {
//Wool
changeColor(consumer, Items.WHITE_WOOL, Items.BLACK_WOOL);
changeColor(consumer, Items.ORANGE_WOOL, Items.WHITE_WOOL);
changeColor(consumer, Items.MAGENTA_WOOL, Items.ORANGE_WOOL);
changeColor(consumer, Items.LIGHT_BLUE_WOOL, Items.MAGENTA_WOOL);
changeColor(consumer, Items.YELLOW_WOOL, Items.LIGHT_BLUE_WOOL);
changeColor(consumer, Items.LIME_WOOL, Items.YELLOW_WOOL);
changeColor(consumer, Items.PINK_WOOL, Items.LIME_WOOL);
changeColor(consumer, Items.GRAY_WOOL, Items.PINK_WOOL);
changeColor(consumer, Items.LIGHT_GRAY_WOOL, Items.GRAY_WOOL);
changeColor(consumer, Items.CYAN_WOOL, Items.LIGHT_GRAY_WOOL);
changeColor(consumer, Items.PURPLE_WOOL, Items.CYAN_WOOL);
changeColor(consumer, Items.BLUE_WOOL, Items.PURPLE_WOOL);
changeColor(consumer, Items.BROWN_WOOL, Items.BLUE_WOOL);
changeColor(consumer, Items.GREEN_WOOL, Items.BROWN_WOOL);
changeColor(consumer, Items.RED_WOOL, Items.GREEN_WOOL);
changeColor(consumer, Items.BLACK_WOOL, Items.RED_WOOL);
}
private void changeColor(Consumer<IFinishedRecipe> consumer, IItemProvider output, Ingredient input) {
consumer.accept(new ColorChangeRecipe.FinishedRecipe(new ResourceLocation(ActuallyAdditions.MODID, "colorchange/" + output.asItem().getRegistryName().getPath()),
input, output));
}
private void changeColor(Consumer<IFinishedRecipe> consumer, IItemProvider output, IItemProvider input) {
consumer.accept(new ColorChangeRecipe.FinishedRecipe(new ResourceLocation(ActuallyAdditions.MODID, "colorchange/" + output.asItem().getRegistryName().getPath()),
Ingredient.of(input), output));
}
private void changeColor(Consumer<IFinishedRecipe> consumer, IItemProvider output, ItemStack input) {
consumer.accept(new ColorChangeRecipe.FinishedRecipe(new ResourceLocation(ActuallyAdditions.MODID, "colorchange/" + output.asItem().getRegistryName().getPath()),
Ingredient.of(input), output));
}
}

View file

@ -23,6 +23,7 @@ public class ActuallyRecipes {
public static final RegistryObject<IRecipeSerializer<?>> LIQUID_FUEL_RECIPE = SERIALIZERS.register(LiquidFuelRecipe.NAME, LiquidFuelRecipe.Serializer::new);
public static final RegistryObject<IRecipeSerializer<?>> PRESSING_RECIPE = SERIALIZERS.register(PressingRecipe.NAME, PressingRecipe.Serializer::new);
public static final RegistryObject<IRecipeSerializer<?>> FERMENTING_RECIPE = SERIALIZERS.register(FermentingRecipe.NAME, FermentingRecipe.Serializer::new);
public static final RegistryObject<IRecipeSerializer<?>> COLOR_CHANGE_RECIPE = SERIALIZERS.register(ColorChangeRecipe.NAME, ColorChangeRecipe.Serializer::new);
@ -34,5 +35,6 @@ public class ActuallyRecipes {
public static final IRecipeType<LiquidFuelRecipe> LIQUID_FUEL = IRecipeType.register(ActuallyAdditions.MODID + ":liquid_fuel");
public static final IRecipeType<PressingRecipe> PRESSING = IRecipeType.register(ActuallyAdditions.MODID + ":pressing");
public static final IRecipeType<FermentingRecipe> FERMENTING = IRecipeType.register(ActuallyAdditions.MODID + ":fermenting");
public static final IRecipeType<ColorChangeRecipe> COLOR_CHANGE = IRecipeType.register(ActuallyAdditions.MODID + ":color_change");
}
}

View file

@ -0,0 +1,146 @@
package de.ellpeck.actuallyadditions.mod.crafting;
import com.google.gson.JsonObject;
import net.minecraft.data.IFinishedRecipe;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.item.crafting.IRecipeSerializer;
import net.minecraft.item.crafting.IRecipeType;
import net.minecraft.item.crafting.Ingredient;
import net.minecraft.network.PacketBuffer;
import net.minecraft.util.IItemProvider;
import net.minecraft.util.JSONUtils;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.ForgeRegistryEntry;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public class ColorChangeRecipe implements IRecipe<IInventory> {
public static final String NAME = "color_change";
private final Ingredient input;
private final ItemStack output;
private final ResourceLocation id;
public ColorChangeRecipe(ResourceLocation id, ItemStack output, Ingredient input) {
this.input = input;
this.output = output;
this.id = id;
}
@Override
public boolean matches(@Nonnull IInventory pInv, @Nonnull World pLevel) {
return input.test(pInv.getItem(0));
}
public boolean matches(ItemStack stack) {
return input.test(stack);
}
@Nonnull
@Override
public ItemStack assemble(@Nonnull IInventory pInv) {
return output.copy();
}
@Override
public boolean canCraftInDimensions(int pWidth, int pHeight) {
return false;
}
@Nonnull
@Override
public ItemStack getResultItem() {
return output.copy();
}
@Nonnull
@Override
public ResourceLocation getId() {
return id;
}
@Nonnull
@Override
public IRecipeSerializer<?> getSerializer() {
return ActuallyRecipes.COLOR_CHANGE_RECIPE.get();
}
@Override
public IRecipeType<?> getType() {
return ActuallyRecipes.Types.COLOR_CHANGE;
}
public static class Serializer extends ForgeRegistryEntry<IRecipeSerializer<?>> implements IRecipeSerializer<ColorChangeRecipe> {
@Override
public ColorChangeRecipe fromJson(@Nonnull ResourceLocation pRecipeId, @Nonnull JsonObject pJson) {
Ingredient ingredient = Ingredient.fromJson(JSONUtils.getAsJsonObject(pJson, "ingredient"));
JsonObject resultObject = JSONUtils.getAsJsonObject(pJson, "result");
ItemStack result = new ItemStack(JSONUtils.getAsItem(resultObject, "item"));
return new ColorChangeRecipe(pRecipeId, result, ingredient);
}
@Nullable
@Override
public ColorChangeRecipe fromNetwork(@Nonnull ResourceLocation pRecipeId, @Nonnull PacketBuffer pBuffer) {
Ingredient ingredient = Ingredient.fromNetwork(pBuffer);
ItemStack result = pBuffer.readItem();
return new ColorChangeRecipe(pRecipeId, result, ingredient);
}
@Override
public void toNetwork(@Nonnull PacketBuffer pBuffer, ColorChangeRecipe pRecipe) {
pRecipe.input.toNetwork(pBuffer);
pBuffer.writeItem(pRecipe.output);
}
}
public static class FinishedRecipe implements IFinishedRecipe {
private final ResourceLocation id;
private final Ingredient itemIngredient;
private final IItemProvider output;
public FinishedRecipe(ResourceLocation id, Ingredient itemIngredient, IItemProvider output) {
this.id = id;
this.itemIngredient = itemIngredient;
this.output = output;
}
@Override
public void serializeRecipeData(JsonObject pJson) {
pJson.add("ingredient", itemIngredient.toJson());
JsonObject resultObject = new JsonObject();
resultObject.addProperty("item", output.asItem().getRegistryName().toString());
pJson.add("result", resultObject);
}
@Override
public ResourceLocation getId() {
return id;
}
@Override
public IRecipeSerializer<?> getType() {
return ActuallyRecipes.COLOR_CHANGE_RECIPE.get();
}
@Nullable
@Override
public JsonObject serializeAdvancement() {
return null;
}
@Nullable
@Override
public ResourceLocation getAdvancementId() {
return null;
}
}
}

View file

@ -16,6 +16,7 @@ import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import net.minecraftforge.registries.ForgeRegistryEntry;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Optional;
@ -91,9 +92,8 @@ public class LaserRecipe implements IRecipe<IInventory> {
}
public static class Serializer extends ForgeRegistryEntry<IRecipeSerializer<?>> implements IRecipeSerializer<LaserRecipe> {
@Override
public LaserRecipe fromJson(ResourceLocation pRecipeId, JsonObject pJson) {
public LaserRecipe fromJson(@Nonnull ResourceLocation pRecipeId, @Nonnull JsonObject pJson) {
Ingredient ingredient = Ingredient.fromJson(JSONUtils.getAsJsonObject(pJson, "ingredient"));
int energy = JSONUtils.getAsInt(pJson, "energy");
JsonObject resultObject = JSONUtils.getAsJsonObject(pJson, "result");
@ -104,7 +104,7 @@ public class LaserRecipe implements IRecipe<IInventory> {
@Nullable
@Override
public LaserRecipe fromNetwork(ResourceLocation pRecipeId, PacketBuffer pBuffer) {
public LaserRecipe fromNetwork(@Nonnull ResourceLocation pRecipeId, @Nonnull PacketBuffer pBuffer) {
Ingredient ingredient = Ingredient.fromNetwork(pBuffer);
int energy = pBuffer.readInt();
ItemStack result = pBuffer.readItem();
@ -112,7 +112,7 @@ public class LaserRecipe implements IRecipe<IInventory> {
}
@Override
public void toNetwork(PacketBuffer pBuffer, LaserRecipe pRecipe) {
public void toNetwork(@Nonnull PacketBuffer pBuffer, LaserRecipe pRecipe) {
pRecipe.itemIngredient.toNetwork(pBuffer);
pBuffer.writeInt(pRecipe.energy);
pBuffer.writeItem(pRecipe.result);

View file

@ -38,5 +38,8 @@ public class ResourceReloader implements IResourceManagerReloadListener {
ActuallyAdditionsAPI.CONVERSION_LASER_RECIPES.clear();
ActuallyAdditionsAPI.CONVERSION_LASER_RECIPES.addAll(recipeManager.getAllRecipesFor(ActuallyRecipes.Types.LASER));
ActuallyAdditionsAPI.COLOR_CHANGE_RECIPES.clear();
ActuallyAdditionsAPI.COLOR_CHANGE_RECIPES.addAll(recipeManager.getAllRecipesFor(ActuallyRecipes.Types.COLOR_CHANGE));
}
}