mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-22 15:18:34 +01:00
Some more recipe work, crushing recipe might be done?
This commit is contained in:
parent
9b11bf3245
commit
a0b8a83194
6 changed files with 131 additions and 57 deletions
|
@ -134,7 +134,7 @@ public final class ActuallyAdditionsAPI {
|
||||||
* @param outputTwoChance The chance of the second output (0 won't occur at all, 100 will all the time)
|
* @param outputTwoChance The chance of the second output (0 won't occur at all, 100 will all the time)
|
||||||
*/
|
*/
|
||||||
public static void addCrusherRecipe(ItemStack input, ItemStack outputOne, ItemStack outputTwo, int outputTwoChance) {
|
public static void addCrusherRecipe(ItemStack input, ItemStack outputOne, ItemStack outputTwo, int outputTwoChance) {
|
||||||
CRUSHER_RECIPES.add(new CrushingRecipe(Ingredient.of(input), outputOne, outputTwo.isEmpty()
|
CRUSHER_RECIPES.add(new CrushingRecipe(Ingredient.of(input), outputOne, 1.0f, outputTwo.isEmpty()
|
||||||
? ItemStack.EMPTY
|
? ItemStack.EMPTY
|
||||||
: outputTwo, outputTwoChance));
|
: outputTwo, outputTwoChance));
|
||||||
}
|
}
|
||||||
|
@ -148,7 +148,7 @@ public final class ActuallyAdditionsAPI {
|
||||||
* @param outputTwoChance The chance of the second output (0 won't occur at all, 100 will all the time)
|
* @param outputTwoChance The chance of the second output (0 won't occur at all, 100 will all the time)
|
||||||
*/
|
*/
|
||||||
public static void addCrusherRecipe(Ingredient input, ItemStack outputOne, ItemStack outputTwo, int outputTwoChance) {
|
public static void addCrusherRecipe(Ingredient input, ItemStack outputOne, ItemStack outputTwo, int outputTwoChance) {
|
||||||
CRUSHER_RECIPES.add(new CrushingRecipe(input, outputOne, outputTwo.isEmpty()
|
CRUSHER_RECIPES.add(new CrushingRecipe(input, outputOne, 1.0f, outputTwo.isEmpty()
|
||||||
? ItemStack.EMPTY
|
? ItemStack.EMPTY
|
||||||
: outputTwo, outputTwoChance));
|
: outputTwo, outputTwoChance));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,17 @@
|
||||||
package de.ellpeck.actuallyadditions.data;
|
package de.ellpeck.actuallyadditions.data;
|
||||||
|
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
|
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
|
||||||
|
import de.ellpeck.actuallyadditions.mod.crafting.CrushingRecipe;
|
||||||
import net.minecraft.data.DataGenerator;
|
import net.minecraft.data.DataGenerator;
|
||||||
import net.minecraft.data.DirectoryCache;
|
import net.minecraft.data.DirectoryCache;
|
||||||
import net.minecraft.data.IFinishedRecipe;
|
import net.minecraft.data.IFinishedRecipe;
|
||||||
import net.minecraft.data.RecipeProvider;
|
import net.minecraft.data.RecipeProvider;
|
||||||
|
import net.minecraft.item.Items;
|
||||||
|
import net.minecraft.item.crafting.Ingredient;
|
||||||
|
import net.minecraft.util.ResourceLocation;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
@ -15,11 +21,12 @@ public class CrushingRecipeGenerator extends RecipeProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void saveAdvancement(DirectoryCache p_208310_1_, JsonObject p_208310_2_, Path p_208310_3_) {
|
protected void saveAdvancement(@Nonnull DirectoryCache p_208310_1_, @Nonnull JsonObject p_208310_2_, @Nonnull Path p_208310_3_) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void buildShapelessRecipes(Consumer<IFinishedRecipe> p_200404_1_) {
|
protected void buildShapelessRecipes(Consumer<IFinishedRecipe> consumer) {
|
||||||
|
consumer.accept(new CrushingRecipe.FinishedRecipe(new ResourceLocation(ActuallyAdditions.MODID, "bone_crusher"),
|
||||||
|
Ingredient.of(Items.BONE), Items.BONE_MEAL, 6, 1.0f , Items.AIR, 0, 0.0f));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package de.ellpeck.actuallyadditions.mod.crafting;
|
package de.ellpeck.actuallyadditions.mod.crafting;
|
||||||
|
|
||||||
|
import com.google.gson.JsonArray;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
|
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
|
||||||
import net.minecraft.data.IFinishedRecipe;
|
import net.minecraft.data.IFinishedRecipe;
|
||||||
|
@ -16,39 +17,44 @@ import net.minecraft.util.ResourceLocation;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.registries.ForgeRegistryEntry;
|
import net.minecraftforge.registries.ForgeRegistryEntry;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
public class CrushingRecipe implements IRecipe<IInventory> {
|
public class CrushingRecipe implements IRecipe<IInventory> {
|
||||||
public static String NAME = "crushing";
|
public static String NAME = "crushing";
|
||||||
private ResourceLocation id;
|
private final ResourceLocation id;
|
||||||
protected Ingredient input;
|
protected Ingredient input;
|
||||||
protected ItemStack outputOne;
|
protected ItemStack outputOne;
|
||||||
protected ItemStack outputTwo;
|
protected ItemStack outputTwo;
|
||||||
protected int outputChance;
|
protected float chance1;
|
||||||
|
protected float chance2;
|
||||||
|
|
||||||
public CrushingRecipe(ResourceLocation id, Ingredient input, ItemStack outputOne, ItemStack outputTwo, int outputChance) {
|
public CrushingRecipe(ResourceLocation id, Ingredient input, ItemStack outputOne, float chance1, ItemStack outputTwo, float chance2) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.input = input;
|
this.input = input;
|
||||||
this.outputOne = outputOne;
|
this.outputOne = outputOne;
|
||||||
this.outputTwo = outputTwo;
|
this.outputTwo = outputTwo;
|
||||||
this.outputChance = outputChance;
|
this.chance1 = chance1;
|
||||||
|
this.chance2 = chance2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CrushingRecipe(Ingredient input, ItemStack outputOne, ItemStack outputTwo, int outputChance) {
|
public CrushingRecipe(Ingredient input, ItemStack outputOne, float chance1, ItemStack outputTwo, float chance2) {
|
||||||
this.id = new ResourceLocation(ActuallyAdditions.MODID, input.getItems()[0].getItem().getRegistryName().getPath() + "_crushing");
|
this.id = new ResourceLocation(ActuallyAdditions.MODID, input.getItems()[0].getItem().getRegistryName().getPath() + "_crushing");
|
||||||
this.input = input;
|
this.input = input;
|
||||||
this.outputOne = outputOne;
|
this.outputOne = outputOne;
|
||||||
this.outputTwo = outputTwo;
|
this.outputTwo = outputTwo;
|
||||||
this.outputChance = outputChance;
|
this.chance1 = chance1;
|
||||||
|
this.chance2 = chance2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean matches(IInventory pInv, World pLevel) {
|
public boolean matches(IInventory pInv, @Nonnull World pLevel) {
|
||||||
return input.test(pInv.getItem(0));
|
return input.test(pInv.getItem(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack assemble(IInventory pInv) {
|
@Nonnull
|
||||||
|
public ItemStack assemble(@Nonnull IInventory pInv) {
|
||||||
return ItemStack.EMPTY;
|
return ItemStack.EMPTY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,21 +64,25 @@ public class CrushingRecipe implements IRecipe<IInventory> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Nonnull
|
||||||
public ItemStack getResultItem() {
|
public ItemStack getResultItem() {
|
||||||
return outputOne;
|
return outputOne;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Nonnull
|
||||||
public ResourceLocation getId() {
|
public ResourceLocation getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Nonnull
|
||||||
public IRecipeSerializer<?> getSerializer() {
|
public IRecipeSerializer<?> getSerializer() {
|
||||||
return ActuallyRecipes.CRUSHING_RECIPE.get();
|
return ActuallyRecipes.CRUSHING_RECIPE.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Nonnull
|
||||||
public IRecipeType<?> getType() {
|
public IRecipeType<?> getType() {
|
||||||
return ActuallyRecipes.Types.CRUSHING;
|
return ActuallyRecipes.Types.CRUSHING;
|
||||||
}
|
}
|
||||||
|
@ -85,8 +95,11 @@ public class CrushingRecipe implements IRecipe<IInventory> {
|
||||||
return this.outputTwo;
|
return this.outputTwo;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getSecondChance() {
|
public float getFirstChance() {
|
||||||
return this.outputChance;
|
return this.chance1;
|
||||||
|
}
|
||||||
|
public float getSecondChance() {
|
||||||
|
return this.chance2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Ingredient getInput() {
|
public Ingredient getInput() {
|
||||||
|
@ -96,64 +109,96 @@ public class CrushingRecipe implements IRecipe<IInventory> {
|
||||||
public static class Serializer extends ForgeRegistryEntry<IRecipeSerializer<?>> implements IRecipeSerializer<CrushingRecipe> {
|
public static class Serializer extends ForgeRegistryEntry<IRecipeSerializer<?>> implements IRecipeSerializer<CrushingRecipe> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CrushingRecipe fromJson(ResourceLocation pRecipeId, JsonObject pJson) {
|
@Nonnull
|
||||||
Ingredient ingredient = Ingredient.fromJson(JSONUtils.getAsJsonObject(pJson, "input"));
|
public CrushingRecipe fromJson(@Nonnull ResourceLocation pRecipeId, @Nonnull JsonObject pJson) {
|
||||||
ItemStack output1 = new ItemStack(JSONUtils.getAsItem(pJson, "output_one"));
|
Ingredient ingredient = Ingredient.fromJson(JSONUtils.getAsJsonObject(pJson, "ingredient"));
|
||||||
ItemStack output2 = new ItemStack(JSONUtils.getAsItem(pJson, "output_two"));
|
|
||||||
int chance = JSONUtils.getAsInt(pJson, "second_chance");
|
|
||||||
|
|
||||||
return new CrushingRecipe(pRecipeId, ingredient, output1, output2, chance);
|
JsonArray resultList = JSONUtils.getAsJsonObject(pJson, "result").getAsJsonArray();
|
||||||
|
if (resultList.size() < 1)
|
||||||
|
throw new IllegalStateException(pRecipeId.toString() + ": Recipe must contain at least 1 result item");
|
||||||
|
|
||||||
|
ItemStack output1 = new ItemStack(JSONUtils.getAsItem(resultList.get(0).getAsJsonObject(), "item"));
|
||||||
|
float chance1 = JSONUtils.getAsFloat(resultList.get(0).getAsJsonObject(), "chance");
|
||||||
|
|
||||||
|
ItemStack output2 = ItemStack.EMPTY;
|
||||||
|
float chance2 = 1.0f;
|
||||||
|
if (resultList.size() > 1) {
|
||||||
|
output2 = new ItemStack(JSONUtils.getAsItem(resultList.get(1).getAsJsonObject(), "item"));
|
||||||
|
chance2 = JSONUtils.getAsFloat(resultList.get(1).getAsJsonObject(), "chance");
|
||||||
|
}
|
||||||
|
|
||||||
|
return new CrushingRecipe(pRecipeId, ingredient, output1, chance1, output2, chance2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
|
||||||
@Override
|
@Override
|
||||||
public CrushingRecipe fromNetwork(ResourceLocation pRecipeId, PacketBuffer pBuffer) {
|
public CrushingRecipe fromNetwork(@Nonnull ResourceLocation pRecipeId, @Nonnull PacketBuffer pBuffer) {
|
||||||
Ingredient ingredient = Ingredient.fromNetwork(pBuffer);
|
Ingredient ingredient = Ingredient.fromNetwork(pBuffer);
|
||||||
ItemStack output1 = pBuffer.readItem();
|
ItemStack output1 = pBuffer.readItem();
|
||||||
ItemStack output2 = pBuffer.readItem();
|
ItemStack output2 = pBuffer.readItem();
|
||||||
int chance = pBuffer.readInt();
|
float chance1 = pBuffer.readFloat();
|
||||||
|
float chance2 = pBuffer.readFloat();
|
||||||
|
|
||||||
return new CrushingRecipe(pRecipeId, ingredient, output1, output2, chance);
|
return new CrushingRecipe(pRecipeId, ingredient, output1, chance1, output2, chance2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void toNetwork(PacketBuffer pBuffer, CrushingRecipe pRecipe) {
|
public void toNetwork(@Nonnull PacketBuffer pBuffer, CrushingRecipe pRecipe) {
|
||||||
pRecipe.input.toNetwork(pBuffer);
|
pRecipe.input.toNetwork(pBuffer);
|
||||||
pBuffer.writeItem(pRecipe.outputOne);
|
pBuffer.writeItem(pRecipe.outputOne);
|
||||||
pBuffer.writeItem(pRecipe.outputTwo);
|
pBuffer.writeItem(pRecipe.outputTwo);
|
||||||
pBuffer.writeInt(pRecipe.outputChance);
|
pBuffer.writeFloat(pRecipe.chance1);
|
||||||
|
pBuffer.writeFloat(pRecipe.chance2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class FinishedRecipe implements IFinishedRecipe {
|
public static class FinishedRecipe implements IFinishedRecipe {
|
||||||
private ResourceLocation id;
|
private final ResourceLocation id;
|
||||||
protected Ingredient input;
|
protected Ingredient input;
|
||||||
protected IItemProvider outputOne;
|
protected IItemProvider outputOne;
|
||||||
|
protected int countOne;
|
||||||
|
protected float outputChance1;
|
||||||
protected IItemProvider outputTwo;
|
protected IItemProvider outputTwo;
|
||||||
protected int outputChance;
|
protected int countTwo;
|
||||||
|
protected float outputChance2;
|
||||||
|
|
||||||
public FinishedRecipe(ResourceLocation id, Ingredient input, IItemProvider outputOne, IItemProvider outputTwo, int outputChance) {
|
public FinishedRecipe(ResourceLocation id, Ingredient input, IItemProvider outputOne, int countOne, float outputChance1, IItemProvider outputTwo, int countTwo, float outputChance2) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
|
this.countOne = countOne;
|
||||||
|
this.countTwo = countTwo;
|
||||||
this.input = input;
|
this.input = input;
|
||||||
this.outputOne = outputOne;
|
this.outputOne = outputOne;
|
||||||
this.outputTwo = outputTwo;
|
this.outputTwo = outputTwo;
|
||||||
this.outputChance = outputChance;
|
this.outputChance1 = outputChance1;
|
||||||
|
this.outputChance2 = outputChance2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void serializeRecipeData(JsonObject pJson) {
|
public void serializeRecipeData(JsonObject pJson) {
|
||||||
pJson.add("input", input.toJson());
|
pJson.add("ingredient", input.toJson());
|
||||||
pJson.addProperty("output_one", outputOne.asItem().getRegistryName().toString());
|
|
||||||
pJson.addProperty("output_two", outputTwo.asItem().getRegistryName().toString());
|
JsonObject result1 = new JsonObject();
|
||||||
pJson.addProperty("second_chance", outputChance);
|
result1.addProperty("item", outputOne.asItem().getRegistryName().toString());
|
||||||
|
result1.addProperty("chance", outputChance1);
|
||||||
|
|
||||||
|
JsonObject result2 = new JsonObject();
|
||||||
|
result1.addProperty("item", outputTwo.asItem().getRegistryName().toString());
|
||||||
|
result1.addProperty("chance", outputChance2);
|
||||||
|
|
||||||
|
JsonArray resultList = new JsonArray();
|
||||||
|
resultList.add(result1);
|
||||||
|
resultList.add(result2);
|
||||||
|
|
||||||
|
pJson.add("result", resultList);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Nonnull
|
||||||
public ResourceLocation getId() {
|
public ResourceLocation getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Nonnull
|
||||||
public IRecipeSerializer<?> getType() {
|
public IRecipeSerializer<?> getType() {
|
||||||
return ActuallyRecipes.CRUSHING_RECIPE.get();
|
return ActuallyRecipes.CRUSHING_RECIPE.get();
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,13 +15,14 @@ import net.minecraft.util.ResourceLocation;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.registries.ForgeRegistryEntry;
|
import net.minecraftforge.registries.ForgeRegistryEntry;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class EmpowererRecipe implements IRecipe<IInventory> {
|
public class EmpowererRecipe implements IRecipe<IInventory> {
|
||||||
public static String NAME = "empowering";
|
public static String NAME = "empowering";
|
||||||
private ResourceLocation id;
|
private final ResourceLocation id;
|
||||||
protected final Ingredient input;
|
protected final Ingredient input;
|
||||||
protected final ItemStack output;
|
protected final ItemStack output;
|
||||||
|
|
||||||
|
@ -73,12 +74,13 @@ public class EmpowererRecipe implements IRecipe<IInventory> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean matches(IInventory pInv, World pLevel) {
|
public boolean matches(@Nonnull IInventory pInv, @Nonnull World pLevel) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack assemble(IInventory pInv) {
|
@Nonnull
|
||||||
|
public ItemStack assemble(@Nonnull IInventory pInv) {
|
||||||
return output.copy();
|
return output.copy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,21 +90,25 @@ public class EmpowererRecipe implements IRecipe<IInventory> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Nonnull
|
||||||
public ItemStack getResultItem() {
|
public ItemStack getResultItem() {
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Nonnull
|
||||||
public ResourceLocation getId() {
|
public ResourceLocation getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Nonnull
|
||||||
public IRecipeSerializer<?> getSerializer() {
|
public IRecipeSerializer<?> getSerializer() {
|
||||||
return ActuallyRecipes.EMPOWERING_RECIPE.get();
|
return ActuallyRecipes.EMPOWERING_RECIPE.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Nonnull
|
||||||
public IRecipeType<?> getType() {
|
public IRecipeType<?> getType() {
|
||||||
return ActuallyRecipes.Types.EMPOWERING;
|
return ActuallyRecipes.Types.EMPOWERING;
|
||||||
}
|
}
|
||||||
|
@ -145,8 +151,8 @@ public class EmpowererRecipe implements IRecipe<IInventory> {
|
||||||
|
|
||||||
public static class Serializer extends ForgeRegistryEntry<IRecipeSerializer<?>> implements IRecipeSerializer<EmpowererRecipe> {
|
public static class Serializer extends ForgeRegistryEntry<IRecipeSerializer<?>> implements IRecipeSerializer<EmpowererRecipe> {
|
||||||
@Override
|
@Override
|
||||||
public EmpowererRecipe fromJson(ResourceLocation pRecipeId, JsonObject pJson) {
|
@Nonnull
|
||||||
ItemStack result = new ItemStack(JSONUtils.getAsItem(pJson, "result"));
|
public EmpowererRecipe fromJson(@Nonnull ResourceLocation pRecipeId, @Nonnull JsonObject pJson) {
|
||||||
Ingredient base = Ingredient.fromJson(JSONUtils.getAsJsonObject(pJson, "base"));
|
Ingredient base = Ingredient.fromJson(JSONUtils.getAsJsonObject(pJson, "base"));
|
||||||
Ingredient mod1 = Ingredient.fromJson(JSONUtils.getAsJsonObject(pJson, "modifier1"));
|
Ingredient mod1 = Ingredient.fromJson(JSONUtils.getAsJsonObject(pJson, "modifier1"));
|
||||||
Ingredient mod2 = Ingredient.fromJson(JSONUtils.getAsJsonObject(pJson, "modifier2"));
|
Ingredient mod2 = Ingredient.fromJson(JSONUtils.getAsJsonObject(pJson, "modifier2"));
|
||||||
|
@ -155,13 +161,15 @@ public class EmpowererRecipe implements IRecipe<IInventory> {
|
||||||
int energy = JSONUtils.getAsInt(pJson, "energy");
|
int energy = JSONUtils.getAsInt(pJson, "energy");
|
||||||
int color = JSONUtils.getAsInt(pJson, "color");
|
int color = JSONUtils.getAsInt(pJson, "color");
|
||||||
int time = JSONUtils.getAsInt(pJson, "time");
|
int time = JSONUtils.getAsInt(pJson, "time");
|
||||||
|
JsonObject resultObject = JSONUtils.getAsJsonObject(pJson, "result");
|
||||||
|
ItemStack result = new ItemStack(JSONUtils.getAsItem(resultObject, "item"));
|
||||||
|
|
||||||
return new EmpowererRecipe(pRecipeId, result, base, mod1, mod2, mod3, mod4, energy, color, time);
|
return new EmpowererRecipe(pRecipeId, result, base, mod1, mod2, mod3, mod4, energy, color, time);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public EmpowererRecipe fromNetwork(ResourceLocation pRecipeId, PacketBuffer pBuffer) {
|
public EmpowererRecipe fromNetwork(@Nonnull ResourceLocation pRecipeId, PacketBuffer pBuffer) {
|
||||||
ItemStack result = pBuffer.readItem();
|
ItemStack result = pBuffer.readItem();
|
||||||
Ingredient input = Ingredient.fromNetwork(pBuffer);
|
Ingredient input = Ingredient.fromNetwork(pBuffer);
|
||||||
Ingredient mod1 = Ingredient.fromNetwork(pBuffer);
|
Ingredient mod1 = Ingredient.fromNetwork(pBuffer);
|
||||||
|
@ -190,16 +198,16 @@ public class EmpowererRecipe implements IRecipe<IInventory> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class FinishedRecipe implements IFinishedRecipe {
|
public static class FinishedRecipe implements IFinishedRecipe {
|
||||||
private ResourceLocation id;
|
private final ResourceLocation id;
|
||||||
private Ingredient base;
|
private final Ingredient base;
|
||||||
private Ingredient mod1;
|
private final Ingredient mod1;
|
||||||
private Ingredient mod2;
|
private final Ingredient mod2;
|
||||||
private Ingredient mod3;
|
private final Ingredient mod3;
|
||||||
private Ingredient mod4;
|
private final Ingredient mod4;
|
||||||
private int energy;
|
private final int energy;
|
||||||
private int color;
|
private final int color;
|
||||||
private int time;
|
private final int time;
|
||||||
private IItemProvider output;
|
private final IItemProvider output;
|
||||||
|
|
||||||
public FinishedRecipe(ResourceLocation id, IItemProvider output, Ingredient input, Ingredient modifier1, Ingredient modifier2, Ingredient modifier3, Ingredient modifier4, int energyPerStand, int particleColor, int time) {
|
public FinishedRecipe(ResourceLocation id, IItemProvider output, Ingredient input, Ingredient modifier1, Ingredient modifier2, Ingredient modifier3, Ingredient modifier4, int energyPerStand, int particleColor, int time) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
|
@ -224,15 +232,21 @@ public class EmpowererRecipe implements IRecipe<IInventory> {
|
||||||
pJson.addProperty("energy", energy);
|
pJson.addProperty("energy", energy);
|
||||||
pJson.addProperty("time", time);
|
pJson.addProperty("time", time);
|
||||||
pJson.addProperty("color", color);
|
pJson.addProperty("color", color);
|
||||||
pJson.addProperty("result", output.asItem().getRegistryName().toString());
|
|
||||||
|
JsonObject resultObject = new JsonObject();
|
||||||
|
resultObject.addProperty("item", output.asItem().getRegistryName().toString());
|
||||||
|
|
||||||
|
pJson.add("result", resultObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Nonnull
|
||||||
public ResourceLocation getId() {
|
public ResourceLocation getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Nonnull
|
||||||
public IRecipeSerializer<?> getType() {
|
public IRecipeSerializer<?> getType() {
|
||||||
return ActuallyRecipes.EMPOWERING_RECIPE.get();
|
return ActuallyRecipes.EMPOWERING_RECIPE.get();
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,10 @@ import com.google.gson.JsonObject;
|
||||||
import net.minecraft.data.IFinishedRecipe;
|
import net.minecraft.data.IFinishedRecipe;
|
||||||
import net.minecraft.inventory.IInventory;
|
import net.minecraft.inventory.IInventory;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.item.crafting.*;
|
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.network.PacketBuffer;
|
||||||
import net.minecraft.util.IItemProvider;
|
import net.minecraft.util.IItemProvider;
|
||||||
import net.minecraft.util.JSONUtils;
|
import net.minecraft.util.JSONUtils;
|
||||||
|
@ -80,7 +83,8 @@ public class LaserRecipe implements IRecipe<IInventory> {
|
||||||
public LaserRecipe fromJson(ResourceLocation pRecipeId, JsonObject pJson) {
|
public LaserRecipe fromJson(ResourceLocation pRecipeId, JsonObject pJson) {
|
||||||
Ingredient ingredient = Ingredient.fromJson(JSONUtils.getAsJsonObject(pJson, "ingredient"));
|
Ingredient ingredient = Ingredient.fromJson(JSONUtils.getAsJsonObject(pJson, "ingredient"));
|
||||||
int energy = JSONUtils.getAsInt(pJson, "energy");
|
int energy = JSONUtils.getAsInt(pJson, "energy");
|
||||||
ItemStack result = new ItemStack(JSONUtils.getAsItem(pJson, "result"));
|
JsonObject resultObject = JSONUtils.getAsJsonObject(pJson, "result");
|
||||||
|
ItemStack result = new ItemStack(JSONUtils.getAsItem(resultObject, "item"));
|
||||||
|
|
||||||
return new LaserRecipe(pRecipeId, result, ingredient, energy);
|
return new LaserRecipe(pRecipeId, result, ingredient, energy);
|
||||||
}
|
}
|
||||||
|
@ -117,9 +121,13 @@ public class LaserRecipe implements IRecipe<IInventory> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void serializeRecipeData(JsonObject pJson) {
|
public void serializeRecipeData(JsonObject pJson) {
|
||||||
pJson.add("input", itemIngredient.toJson());
|
pJson.add("ingredient", itemIngredient.toJson());
|
||||||
pJson.addProperty("energy", energy);
|
pJson.addProperty("energy", energy);
|
||||||
pJson.addProperty("output", output.asItem().getRegistryName().toString());
|
|
||||||
|
JsonObject resultObject = new JsonObject();
|
||||||
|
resultObject.addProperty("item", output.asItem().getRegistryName().toString());
|
||||||
|
|
||||||
|
pJson.add("result", resultObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -242,7 +242,7 @@ public class TileEntityCrusher extends TileEntityInventoryBase implements IButto
|
||||||
outputTwo.setDamage(0);
|
outputTwo.setDamage(0);
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
int rand = this.level.random.nextInt(100) + 1;
|
float rand = this.level.random.nextFloat();
|
||||||
if (rand <= recipe.getSecondChance()) {
|
if (rand <= recipe.getSecondChance()) {
|
||||||
if (!StackUtil.isValid(this.inv.getStackInSlot(theSecondOutput))) {
|
if (!StackUtil.isValid(this.inv.getStackInSlot(theSecondOutput))) {
|
||||||
this.inv.setStackInSlot(theSecondOutput, outputTwo.copy());
|
this.inv.setStackInSlot(theSecondOutput, outputTwo.copy());
|
||||||
|
|
Loading…
Reference in a new issue