mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-12-28 16:06:48 +01:00
Mechanicalacinahcem
- Added the option to prevent a Mechanical Crafting recipe from matching a vertically flipped arrangement
This commit is contained in:
parent
31c951be65
commit
b05506ad46
9 changed files with 88 additions and 20 deletions
|
@ -3377,11 +3377,11 @@ bbf64f7eb3868e354756e57348493e2b1ae6b0d9 data/create/recipes/limestone_cobblesto
|
|||
88fa2b1ab746d5e13a8afd6e7e7d80ad843e0016 data/create/recipes/limestone_cobblestone_wall_from_limestone_cobblestone_stonecutting.json
|
||||
327bb8a6535b60bb65d0dda9d5205e988bc82526 data/create/recipes/limestone_pillar.json
|
||||
c2e15ac0c9109bad3face6d13efc32d7116b4c25 data/create/recipes/limestone_pillar_from_limestone_stonecutting.json
|
||||
88173753ceaf121c5430bbf928a40e3c046dbfe0 data/create/recipes/mechanical_crafting/crushing_wheel.json
|
||||
14e322d4de8fae35d952274376497740bb3d5962 data/create/recipes/mechanical_crafting/extendo_grip.json
|
||||
de7fea84434753873dfa2b929d9b5f5f86ac6a5c data/create/recipes/mechanical_crafting/flywheel.json
|
||||
e491fd8a8873308270f9dc2a57ac8f2c70431dcc data/create/recipes/mechanical_crafting/furnace_engine.json
|
||||
8e5224d22b228f69473ca48ca0d874b34660b573 data/create/recipes/mechanical_crafting/potato_cannon.json
|
||||
66674d07de63aada0991d2fdff07e22e00450135 data/create/recipes/mechanical_crafting/crushing_wheel.json
|
||||
599f8b87c24c131350ba7ceb69a0c8b9829c62bc data/create/recipes/mechanical_crafting/extendo_grip.json
|
||||
f26ed47c10cc63613759b0f8ae4ef349000de60d data/create/recipes/mechanical_crafting/flywheel.json
|
||||
2dc00d6e4c159e06ab2a705e666e83e4238a7814 data/create/recipes/mechanical_crafting/furnace_engine.json
|
||||
b77911c169b6205a09001a09ca074eb2234f0d29 data/create/recipes/mechanical_crafting/potato_cannon.json
|
||||
98f877bf8f3f8a686fc6cf7479a0fba5744248ce data/create/recipes/milling/allium.json
|
||||
8c7e1cbc87c7ca7df2bf949957e89422fef8ad94 data/create/recipes/milling/aluminum_ore.json
|
||||
bcff4d30ae09a0729bce8b2dbde4ddd6719a998b data/create/recipes/milling/andesite.json
|
||||
|
|
|
@ -21,5 +21,6 @@
|
|||
"result": {
|
||||
"item": "create:crushing_wheel",
|
||||
"count": 2
|
||||
}
|
||||
},
|
||||
"acceptMirrored": false
|
||||
}
|
|
@ -23,5 +23,6 @@
|
|||
},
|
||||
"result": {
|
||||
"item": "create:extendo_grip"
|
||||
}
|
||||
},
|
||||
"acceptMirrored": false
|
||||
}
|
|
@ -15,5 +15,6 @@
|
|||
},
|
||||
"result": {
|
||||
"item": "create:flywheel"
|
||||
}
|
||||
},
|
||||
"acceptMirrored": true
|
||||
}
|
|
@ -26,5 +26,6 @@
|
|||
},
|
||||
"result": {
|
||||
"item": "create:furnace_engine"
|
||||
}
|
||||
},
|
||||
"acceptMirrored": true
|
||||
}
|
|
@ -20,5 +20,6 @@
|
|||
},
|
||||
"result": {
|
||||
"item": "create:potato_cannon"
|
||||
}
|
||||
},
|
||||
"acceptMirrored": true
|
||||
}
|
|
@ -10,25 +10,58 @@ import net.minecraft.item.crafting.IRecipeType;
|
|||
import net.minecraft.item.crafting.Ingredient;
|
||||
import net.minecraft.item.crafting.ShapedRecipe;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.util.JSONUtils;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class MechanicalCraftingRecipe extends ShapedRecipe {
|
||||
|
||||
private boolean acceptMirrored;
|
||||
|
||||
public MechanicalCraftingRecipe(ResourceLocation idIn, String groupIn, int recipeWidthIn, int recipeHeightIn,
|
||||
NonNullList<Ingredient> recipeItemsIn, ItemStack recipeOutputIn) {
|
||||
NonNullList<Ingredient> recipeItemsIn, ItemStack recipeOutputIn, boolean acceptMirrored) {
|
||||
super(idIn, groupIn, recipeWidthIn, recipeHeightIn, recipeItemsIn, recipeOutputIn);
|
||||
this.acceptMirrored = acceptMirrored;
|
||||
}
|
||||
|
||||
private static MechanicalCraftingRecipe fromShaped(ShapedRecipe recipe) {
|
||||
private static MechanicalCraftingRecipe fromShaped(ShapedRecipe recipe, boolean acceptMirrored) {
|
||||
return new MechanicalCraftingRecipe(recipe.getId(), recipe.getGroup(), recipe.getWidth(), recipe.getHeight(),
|
||||
recipe.getIngredients(), recipe.getResultItem());
|
||||
recipe.getIngredients(), recipe.getResultItem(), acceptMirrored);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(CraftingInventory inv, World worldIn) {
|
||||
return inv instanceof MechanicalCraftingInventory && super.matches(inv, worldIn);
|
||||
if (!(inv instanceof MechanicalCraftingInventory))
|
||||
return false;
|
||||
if (acceptsMirrored())
|
||||
return super.matches(inv, worldIn);
|
||||
|
||||
// From ShapedRecipe except the symmetry
|
||||
for (int i = 0; i <= inv.getWidth() - this.getWidth(); ++i)
|
||||
for (int j = 0; j <= inv.getHeight() - this.getHeight(); ++j)
|
||||
if (this.matchesSpecific(inv, i, j))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
// From ShapedRecipe
|
||||
private boolean matchesSpecific(CraftingInventory inv, int p_77573_2_, int p_77573_3_) {
|
||||
NonNullList<Ingredient> ingredients = getIngredients();
|
||||
int width = getWidth();
|
||||
int height = getHeight();
|
||||
for (int i = 0; i < inv.getWidth(); ++i) {
|
||||
for (int j = 0; j < inv.getHeight(); ++j) {
|
||||
int k = i - p_77573_2_;
|
||||
int l = j - p_77573_3_;
|
||||
Ingredient ingredient = Ingredient.EMPTY;
|
||||
if (k >= 0 && l >= 0 && k < width && l < height)
|
||||
ingredient = ingredients.get(k + l * width);
|
||||
if (!ingredient.test(inv.getItem(i + j * inv.getWidth())))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -46,16 +79,30 @@ public class MechanicalCraftingRecipe extends ShapedRecipe {
|
|||
return AllRecipeTypes.MECHANICAL_CRAFTING.getSerializer();
|
||||
}
|
||||
|
||||
public boolean acceptsMirrored() {
|
||||
return acceptMirrored;
|
||||
}
|
||||
|
||||
public static class Serializer extends ShapedRecipe.Serializer {
|
||||
|
||||
@Override
|
||||
public ShapedRecipe fromJson(ResourceLocation recipeId, JsonObject json) {
|
||||
return fromShaped(super.fromJson(recipeId, json));
|
||||
return fromShaped(super.fromJson(recipeId, json), JSONUtils.getAsBoolean(json, "acceptMirrored", true));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ShapedRecipe fromNetwork(ResourceLocation recipeId, PacketBuffer buffer) {
|
||||
return fromShaped(super.fromNetwork(recipeId, buffer));
|
||||
return fromShaped(super.fromNetwork(recipeId, buffer), buffer.readBoolean() && buffer.readBoolean());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toNetwork(PacketBuffer p_199427_1_, ShapedRecipe p_199427_2_) {
|
||||
super.toNetwork(p_199427_1_, p_199427_2_);
|
||||
if (p_199427_2_ instanceof MechanicalCraftingRecipe) {
|
||||
p_199427_1_.writeBoolean(true);
|
||||
p_199427_1_.writeBoolean(((MechanicalCraftingRecipe) p_199427_2_).acceptsMirrored());
|
||||
} else
|
||||
p_199427_1_.writeBoolean(false);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -30,10 +30,12 @@ public class MechanicalCraftingRecipeBuilder {
|
|||
private final int count;
|
||||
private final List<String> pattern = Lists.newArrayList();
|
||||
private final Map<Character, Ingredient> key = Maps.newLinkedHashMap();
|
||||
private boolean acceptMirrored;
|
||||
|
||||
public MechanicalCraftingRecipeBuilder(IItemProvider p_i48261_1_, int p_i48261_2_) {
|
||||
result = p_i48261_1_.asItem();
|
||||
count = p_i48261_2_;
|
||||
acceptMirrored = true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -91,6 +93,14 @@ public class MechanicalCraftingRecipeBuilder {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevents the crafters from matching a vertically flipped version of the recipe
|
||||
*/
|
||||
public MechanicalCraftingRecipeBuilder disallowMirrored() {
|
||||
acceptMirrored = false;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds this recipe into an {@link IFinishedRecipe}.
|
||||
*/
|
||||
|
@ -116,7 +126,8 @@ public class MechanicalCraftingRecipeBuilder {
|
|||
*/
|
||||
public void build(Consumer<IFinishedRecipe> p_200467_1_, ResourceLocation p_200467_2_) {
|
||||
validate(p_200467_2_);
|
||||
p_200467_1_.accept(new MechanicalCraftingRecipeBuilder.Result(p_200467_2_, result, count, pattern, key));
|
||||
p_200467_1_
|
||||
.accept(new MechanicalCraftingRecipeBuilder.Result(p_200467_2_, result, count, pattern, key, acceptMirrored));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -151,14 +162,16 @@ public class MechanicalCraftingRecipeBuilder {
|
|||
private final int count;
|
||||
private final List<String> pattern;
|
||||
private final Map<Character, Ingredient> key;
|
||||
private final boolean acceptMirrored;
|
||||
|
||||
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_) {
|
||||
Map<Character, Ingredient> p_i48271_7_, boolean asymmetrical) {
|
||||
this.id = p_i48271_2_;
|
||||
this.result = p_i48271_3_;
|
||||
this.count = p_i48271_4_;
|
||||
this.pattern = p_i48271_6_;
|
||||
this.key = p_i48271_7_;
|
||||
this.acceptMirrored = asymmetrical;
|
||||
}
|
||||
|
||||
public void serializeRecipeData(JsonObject p_218610_1_) {
|
||||
|
@ -180,6 +193,7 @@ public class MechanicalCraftingRecipeBuilder {
|
|||
jsonobject1.addProperty("count", this.count);
|
||||
|
||||
p_218610_1_.add("result", jsonobject1);
|
||||
p_218610_1_.addProperty("acceptMirrored", acceptMirrored);
|
||||
}
|
||||
|
||||
public IRecipeSerializer<?> getType() {
|
||||
|
|
|
@ -27,7 +27,8 @@ public class MechanicalCraftingRecipeGen extends CreateRecipeProvider {
|
|||
.patternLine("AAPAA")
|
||||
.patternLine("APSPA")
|
||||
.patternLine("AAPAA")
|
||||
.patternLine(" AAA ")),
|
||||
.patternLine(" AAA ")
|
||||
.disallowMirrored()),
|
||||
|
||||
EXTENDO_GRIP = create(AllItems.EXTENDO_GRIP::get).returns(1)
|
||||
.recipe(b -> b.key('L', Ingredient.of(I.brass()))
|
||||
|
@ -38,7 +39,8 @@ public class MechanicalCraftingRecipeGen extends CreateRecipeProvider {
|
|||
.patternLine(" R ")
|
||||
.patternLine("SSS")
|
||||
.patternLine("SSS")
|
||||
.patternLine(" H ")),
|
||||
.patternLine(" H ")
|
||||
.disallowMirrored()),
|
||||
|
||||
POTATO_CANNON = create(AllItems.POTATO_CANNON::get).returns(1)
|
||||
.recipe(b -> b.key('L', I.andesite())
|
||||
|
|
Loading…
Reference in a new issue