mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-12-27 23:47:38 +01:00
Merge pull request #2745 from FortressNebula/mc1.18/dev
Change the way CopperBlockSet generates block models + condition support for Mech. Crafting
This commit is contained in:
commit
2a3aa5955b
2 changed files with 45 additions and 5 deletions
|
@ -4,6 +4,7 @@ import java.util.EnumMap;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
import org.apache.commons.lang3.ArrayUtils;
|
import org.apache.commons.lang3.ArrayUtils;
|
||||||
|
@ -228,10 +229,18 @@ public class CopperBlockSet {
|
||||||
String path = block.getRegistryName()
|
String path = block.getRegistryName()
|
||||||
.getPath();
|
.getPath();
|
||||||
String baseLoc = ModelProvider.BLOCK_FOLDER + "/" + blocks.generalDirectory + getWeatherStatePrefix(state);
|
String baseLoc = ModelProvider.BLOCK_FOLDER + "/" + blocks.generalDirectory + getWeatherStatePrefix(state);
|
||||||
|
|
||||||
ResourceLocation texture = prov.modLoc(baseLoc + blocks.getName());
|
ResourceLocation texture = prov.modLoc(baseLoc + blocks.getName());
|
||||||
ResourceLocation endTexture = prov.modLoc(baseLoc + blocks.getEndTextureName());
|
if (Objects.equals(blocks.getName(), blocks.getEndTextureName())) {
|
||||||
prov.simpleBlock(block, prov.models()
|
// End texture and base texture are equal, so we should use cube_all.
|
||||||
.cubeColumn(path, texture, endTexture));
|
prov.simpleBlock(block, prov.models().cubeAll(path, texture));
|
||||||
|
} else {
|
||||||
|
// End texture and base texture aren't equal, so we should use cube_column.
|
||||||
|
ResourceLocation endTexture = prov.modLoc(baseLoc + blocks.getEndTextureName());
|
||||||
|
prov.simpleBlock(block, prov.models()
|
||||||
|
.cubeColumn(path, texture, endTexture));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.simibubi.create.foundation.data.recipe;
|
package com.simibubi.create.foundation.data.recipe;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
@ -15,6 +16,8 @@ import com.google.gson.JsonArray;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import com.simibubi.create.AllRecipeTypes;
|
import com.simibubi.create.AllRecipeTypes;
|
||||||
|
|
||||||
|
import com.simibubi.create.content.contraptions.processing.ProcessingRecipeBuilder;
|
||||||
|
|
||||||
import net.minecraft.data.recipes.FinishedRecipe;
|
import net.minecraft.data.recipes.FinishedRecipe;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.tags.SetTag;
|
import net.minecraft.tags.SetTag;
|
||||||
|
@ -22,6 +25,10 @@ import net.minecraft.world.item.Item;
|
||||||
import net.minecraft.world.item.crafting.Ingredient;
|
import net.minecraft.world.item.crafting.Ingredient;
|
||||||
import net.minecraft.world.item.crafting.RecipeSerializer;
|
import net.minecraft.world.item.crafting.RecipeSerializer;
|
||||||
import net.minecraft.world.level.ItemLike;
|
import net.minecraft.world.level.ItemLike;
|
||||||
|
import net.minecraftforge.common.crafting.CraftingHelper;
|
||||||
|
import net.minecraftforge.common.crafting.conditions.ICondition;
|
||||||
|
import net.minecraftforge.common.crafting.conditions.ModLoadedCondition;
|
||||||
|
import net.minecraftforge.common.crafting.conditions.NotCondition;
|
||||||
import net.minecraftforge.registries.ForgeRegistries;
|
import net.minecraftforge.registries.ForgeRegistries;
|
||||||
|
|
||||||
public class MechanicalCraftingRecipeBuilder {
|
public class MechanicalCraftingRecipeBuilder {
|
||||||
|
@ -31,11 +38,13 @@ public class MechanicalCraftingRecipeBuilder {
|
||||||
private final List<String> pattern = Lists.newArrayList();
|
private final List<String> pattern = Lists.newArrayList();
|
||||||
private final Map<Character, Ingredient> key = Maps.newLinkedHashMap();
|
private final Map<Character, Ingredient> key = Maps.newLinkedHashMap();
|
||||||
private boolean acceptMirrored;
|
private boolean acceptMirrored;
|
||||||
|
private List<ICondition> recipeConditions;
|
||||||
|
|
||||||
public MechanicalCraftingRecipeBuilder(ItemLike p_i48261_1_, int p_i48261_2_) {
|
public MechanicalCraftingRecipeBuilder(ItemLike p_i48261_1_, int p_i48261_2_) {
|
||||||
result = p_i48261_1_.asItem();
|
result = p_i48261_1_.asItem();
|
||||||
count = p_i48261_2_;
|
count = p_i48261_2_;
|
||||||
acceptMirrored = true;
|
acceptMirrored = true;
|
||||||
|
recipeConditions = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -127,7 +136,7 @@ public class MechanicalCraftingRecipeBuilder {
|
||||||
public void build(Consumer<FinishedRecipe> p_200467_1_, ResourceLocation p_200467_2_) {
|
public void build(Consumer<FinishedRecipe> p_200467_1_, ResourceLocation p_200467_2_) {
|
||||||
validate(p_200467_2_);
|
validate(p_200467_2_);
|
||||||
p_200467_1_
|
p_200467_1_
|
||||||
.accept(new MechanicalCraftingRecipeBuilder.Result(p_200467_2_, result, count, pattern, key, acceptMirrored));
|
.accept(new MechanicalCraftingRecipeBuilder.Result(p_200467_2_, result, count, pattern, key, acceptMirrored, recipeConditions));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -156,6 +165,19 @@ public class MechanicalCraftingRecipeBuilder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public MechanicalCraftingRecipeBuilder whenModLoaded(String modid) {
|
||||||
|
return withCondition(new ModLoadedCondition(modid));
|
||||||
|
}
|
||||||
|
|
||||||
|
public MechanicalCraftingRecipeBuilder whenModMissing(String modid) {
|
||||||
|
return withCondition(new NotCondition(new ModLoadedCondition(modid)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public MechanicalCraftingRecipeBuilder withCondition(ICondition condition) {
|
||||||
|
recipeConditions.add(condition);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public class Result implements FinishedRecipe {
|
public class Result implements FinishedRecipe {
|
||||||
private final ResourceLocation id;
|
private final ResourceLocation id;
|
||||||
private final Item result;
|
private final Item result;
|
||||||
|
@ -163,15 +185,17 @@ public class MechanicalCraftingRecipeBuilder {
|
||||||
private final List<String> pattern;
|
private final List<String> pattern;
|
||||||
private final Map<Character, Ingredient> key;
|
private final Map<Character, Ingredient> key;
|
||||||
private final boolean acceptMirrored;
|
private final boolean acceptMirrored;
|
||||||
|
private List<ICondition> recipeConditions;
|
||||||
|
|
||||||
public Result(ResourceLocation p_i48271_2_, Item p_i48271_3_, int p_i48271_4_, List<String> p_i48271_6_,
|
public Result(ResourceLocation p_i48271_2_, Item p_i48271_3_, int p_i48271_4_, List<String> p_i48271_6_,
|
||||||
Map<Character, Ingredient> p_i48271_7_, boolean asymmetrical) {
|
Map<Character, Ingredient> p_i48271_7_, boolean asymmetrical, List<ICondition> recipeConditions) {
|
||||||
this.id = p_i48271_2_;
|
this.id = p_i48271_2_;
|
||||||
this.result = p_i48271_3_;
|
this.result = p_i48271_3_;
|
||||||
this.count = p_i48271_4_;
|
this.count = p_i48271_4_;
|
||||||
this.pattern = p_i48271_6_;
|
this.pattern = p_i48271_6_;
|
||||||
this.key = p_i48271_7_;
|
this.key = p_i48271_7_;
|
||||||
this.acceptMirrored = asymmetrical;
|
this.acceptMirrored = asymmetrical;
|
||||||
|
this.recipeConditions = recipeConditions;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void serializeRecipeData(JsonObject p_218610_1_) {
|
public void serializeRecipeData(JsonObject p_218610_1_) {
|
||||||
|
@ -194,6 +218,13 @@ public class MechanicalCraftingRecipeBuilder {
|
||||||
|
|
||||||
p_218610_1_.add("result", jsonobject1);
|
p_218610_1_.add("result", jsonobject1);
|
||||||
p_218610_1_.addProperty("acceptMirrored", acceptMirrored);
|
p_218610_1_.addProperty("acceptMirrored", acceptMirrored);
|
||||||
|
|
||||||
|
if (recipeConditions.isEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
JsonArray conds = new JsonArray();
|
||||||
|
recipeConditions.forEach(c -> conds.add(CraftingHelper.serialize(c)));
|
||||||
|
p_218610_1_.add("conditions", conds);
|
||||||
}
|
}
|
||||||
|
|
||||||
public RecipeSerializer<?> getType() {
|
public RecipeSerializer<?> getType() {
|
||||||
|
|
Loading…
Reference in a new issue