mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-12-22 19:39:24 +01:00
Ball of Fur Recipe Factory
This commit is contained in:
parent
26b021a5e9
commit
2c57a7641a
3 changed files with 111 additions and 0 deletions
|
@ -0,0 +1,45 @@
|
|||
package de.ellpeck.actuallyadditions.common.recipes;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.IRecipeSerializer;
|
||||
import net.minecraft.item.crafting.IRecipeType;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
public class BallOfFurRecipe implements IDummyRecipe {
|
||||
|
||||
public static final IRecipeType<BallOfFurRecipe> BALL_OF_FUR_RECIPE_TYPE = IRecipeType.register("actuallyadditions:ball_of_fur");
|
||||
|
||||
private final ResourceLocation recipeId;
|
||||
|
||||
private final ItemStack returnItem;
|
||||
private final int chance;
|
||||
|
||||
public BallOfFurRecipe(ResourceLocation recipeId, ItemStack returnItem, int chance){
|
||||
this.recipeId = recipeId;
|
||||
this.returnItem = returnItem;
|
||||
this.chance = chance;
|
||||
}
|
||||
|
||||
public ItemStack getReturnItem(){
|
||||
return this.returnItem;
|
||||
}
|
||||
|
||||
public int getChance(){
|
||||
return this.chance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation getId(){
|
||||
return this.recipeId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IRecipeSerializer<?> getSerializer(){
|
||||
return BallOfFurRecipeFactory.INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IRecipeType<?> getType(){
|
||||
return BALL_OF_FUR_RECIPE_TYPE;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
package de.ellpeck.actuallyadditions.common.recipes;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParseException;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.IRecipeSerializer;
|
||||
import net.minecraft.item.crafting.ShapedRecipe;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.registries.ForgeRegistryEntry;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class BallOfFurRecipeFactory extends ForgeRegistryEntry<IRecipeSerializer<?>> implements IRecipeSerializer<BallOfFurRecipe> {
|
||||
|
||||
public static final BallOfFurRecipeFactory INSTANCE = IRecipeSerializer.register("actuallyadditions:ball_of_fur", new BallOfFurRecipeFactory());
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public BallOfFurRecipe read(@Nonnull ResourceLocation recipeId, @Nonnull JsonObject json){
|
||||
ItemStack stack;
|
||||
int chance;
|
||||
|
||||
if(json.has("stack")){
|
||||
JsonElement stackJsonElement = json.get("stack");
|
||||
if(stackJsonElement.isJsonObject()){
|
||||
stack = ShapedRecipe.deserializeItem(stackJsonElement.getAsJsonObject());
|
||||
} else {
|
||||
throw new JsonParseException("BallOfFurRecipe stack has to be a json object!");
|
||||
}
|
||||
} else {
|
||||
throw new JsonParseException("BallOfFurRecipe has no json stack object!");
|
||||
}
|
||||
|
||||
if(json.has("chance")){
|
||||
JsonElement chanceJsonElement = json.get("chance");
|
||||
if(chanceJsonElement.isJsonPrimitive()){
|
||||
chance = chanceJsonElement.getAsInt();
|
||||
} else {
|
||||
throw new JsonParseException("BallOfFurRecipe chance is not a json integer!");
|
||||
}
|
||||
} else {
|
||||
throw new JsonParseException("BallOfFurRecipe has no chance integer!");
|
||||
}
|
||||
|
||||
return new BallOfFurRecipe(recipeId, stack, chance);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public BallOfFurRecipe read(@Nonnull ResourceLocation recipeId, @Nonnull PacketBuffer buffer){
|
||||
ItemStack stack = buffer.readItemStack();
|
||||
int chance = buffer.readInt();
|
||||
return new BallOfFurRecipe(recipeId, stack, chance);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@Nonnull PacketBuffer buffer, @Nonnull BallOfFurRecipe recipe){
|
||||
buffer.writeItemStack(recipe.getReturnItem());
|
||||
buffer.writeInt(recipe.getChance());
|
||||
}
|
||||
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
{
|
||||
"recipes": {
|
||||
"atomic_reconstructor": "de.ellpeck.actuallyadditions.recipes.AtomicReconstructorRecipeFactory",
|
||||
"ball_of_fur": "de.ellpeck.actuallyadditions.recipes.BallOfFurRecipeFactory",
|
||||
"coffee_machine_ingredient": "de.ellpeck.actuallyadditions.recipes.CoffeeMachineIngredientFactory"
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue