Added CoffeeMachineIngredient and CoffeeMachineIngredientFactory

This commit is contained in:
canitzp 2020-09-18 07:56:55 +02:00
parent 829cc788c7
commit 615bde1cb8
6 changed files with 160 additions and 7 deletions

View File

@ -14,6 +14,8 @@ import net.minecraft.block.BlockState;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.Ingredient;
import net.minecraftforge.registries.IForgeRegistry;
import net.minecraftforge.registries.RegistryBuilder;
import java.util.ArrayList;
import java.util.HashMap;
@ -25,7 +27,9 @@ public final class ActuallyAdditionsAPI {
public static final String MOD_ID = "actuallyadditions";
public static final String API_ID = MOD_ID + "api";
public static final String API_VERSION = "34";
public static final IForgeRegistry<Lens> LENS_REGISTRY = new RegistryBuilder<Lens>().disableSync().disableSaving().disableOverrides().create();
public static final List<CrusherRecipe> CRUSHER_RECIPES = new ArrayList<>();
public static final List<BallOfFurReturn> BALL_OF_FUR_RETURN_ITEMS = new ArrayList<>();
public static final List<TreasureChestLoot> TREASURE_CHEST_LOOT = new ArrayList<>();

View File

@ -65,8 +65,6 @@ public class ActuallyAdditions {
public static final Logger LOGGER = LogManager.getLogger(MODID);
public static ActuallyAdditions INSTANCE;
public static final IForgeRegistry<Lens> LENS_REGISTRY = new RegistryBuilder<Lens>().disableSync().disableSaving().disableOverrides().create();
public static boolean commonCapsLoaded = false;

View File

@ -1,5 +1,6 @@
package de.ellpeck.actuallyadditions.common.items.lens;
import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI;
import de.ellpeck.actuallyadditions.api.lens.Lens;
import de.ellpeck.actuallyadditions.api.lens.LensConversion;
import de.ellpeck.actuallyadditions.common.ActuallyAdditions;
@ -8,7 +9,7 @@ import net.minecraftforge.registries.DeferredRegister;
public final class Lenses {
public static final DeferredRegister<Lens> LENSES = DeferredRegister.create(ActuallyAdditions.LENS_REGISTRY, ActuallyAdditions.MODID);
public static final DeferredRegister<Lens> LENSES = DeferredRegister.create(ActuallyAdditionsAPI.LENS_REGISTRY, ActuallyAdditions.MODID);
public static final RegistryObject<LensConversion> LENS_CONVERSION = LENSES.register("conversion", LensConversion::new);
public static final RegistryObject<LensDetonation> LENS_DETONATION = LENSES.register("detonation", LensDetonation::new);
@ -19,5 +20,4 @@ public final class Lenses {
public static final RegistryObject<LensDisenchanting> LENS_DISENCHANTING = LENSES.register("disenchanting", LensDisenchanting::new);
public static final RegistryObject<LensMining> LENS_MINING = LENSES.register("mining", LensMining::new);
}
}

View File

@ -0,0 +1,51 @@
package de.ellpeck.actuallyadditions.recipes;
import net.minecraft.item.crafting.IRecipeSerializer;
import net.minecraft.item.crafting.IRecipeType;
import net.minecraft.item.crafting.Ingredient;
import net.minecraft.potion.EffectInstance;
import net.minecraft.util.ResourceLocation;
public class CoffeeMachineIngredient implements IDummyRecipe{
public static final IRecipeType<CoffeeMachineIngredient> COFFEE_MACHINE_RECIPE_TYPE = IRecipeType.register("actuallyadditions:coffee_machine");
protected final ResourceLocation recipeId;
protected final Ingredient input;
protected final int maxAmplifier;
protected final EffectInstance[] effects;
public CoffeeMachineIngredient(ResourceLocation recipeId, Ingredient input, int maxAmplifier, EffectInstance[] effects){
this.recipeId = recipeId;
this.input = input;
this.maxAmplifier = maxAmplifier;
this.effects = effects;
}
public Ingredient getInput(){
return input;
}
public int getMaxAmplifier(){
return maxAmplifier;
}
public EffectInstance[] getEffects(){
return effects;
}
@Override
public ResourceLocation getId(){
return this.recipeId;
}
@Override
public IRecipeSerializer<?> getSerializer(){
return CoffeeMachineIngredientFactory.INSTANCE;
}
@Override
public IRecipeType<?> getType(){
return COFFEE_MACHINE_RECIPE_TYPE;
}
}

View File

@ -0,0 +1,99 @@
package de.ellpeck.actuallyadditions.recipes;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonSyntaxException;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.minecraft.item.crafting.IRecipeSerializer;
import net.minecraft.item.crafting.Ingredient;
import net.minecraft.nbt.*;
import net.minecraft.network.PacketBuffer;
import net.minecraft.potion.EffectInstance;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.util.Constants;
import net.minecraftforge.registries.ForgeRegistryEntry;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;
public class CoffeeMachineIngredientFactory extends ForgeRegistryEntry<IRecipeSerializer<?>> implements IRecipeSerializer<CoffeeMachineIngredient> {
public static final CoffeeMachineIngredientFactory INSTANCE = IRecipeSerializer.register("actuallyadditions:coffee_machine", new CoffeeMachineIngredientFactory());
@Override
public CoffeeMachineIngredient read(ResourceLocation recipeId, JsonObject json){
Ingredient input = null;
EffectInstance[] effects = new EffectInstance[0];
int maxAmplifier = 0;
if(json.has("input")){
input = Ingredient.deserialize(json.get("input"));
}
if(json.has("effects")){
if(json.get("effects").isJsonArray()){
List<EffectInstance> effectInstances = new ArrayList<>();
for(JsonElement element : json.get("effects").getAsJsonArray()){
if(element.isJsonObject()){
try{
CompoundNBT tagFromJson = JsonToNBT.getTagFromJson(element.toString());
effectInstances.add(EffectInstance.read(tagFromJson));
} catch(CommandSyntaxException e){
throw new JsonSyntaxException("Can't deserialize Potion Effect from json for recipe!", e);
}
}
}
if(!effectInstances.isEmpty()){
effects = effectInstances.toArray(new EffectInstance[0]);
} else {
throw new JsonSyntaxException("No Potion effects assigned for recipe!");
}
}
}
if(json.has("max_amplifier") && json.get("max_amplifier").isJsonPrimitive()){
maxAmplifier = json.get("max_amplifier").getAsInt();
}
if(input != null && effects.length > 0){
return new CoffeeMachineIngredient(recipeId, input, maxAmplifier, effects);
} else {
return null;
}
}
@Nullable
@Override
public CoffeeMachineIngredient read(ResourceLocation recipeId, PacketBuffer buffer){
Ingredient input = Ingredient.read(buffer);
CompoundNBT nbt = buffer.readCompoundTag();
int maxAmplifier = buffer.readVarInt();
List<EffectInstance> effectsList = new ArrayList<>();
ListNBT effectsNBTList = nbt.getList("effectsList", Constants.NBT.TAG_COMPOUND);
for(INBT inbt : effectsNBTList){
EffectInstance effect = EffectInstance.read((CompoundNBT) inbt);
effectsList.add(effect);
}
return new CoffeeMachineIngredient(recipeId, input, maxAmplifier, effectsList.toArray(new EffectInstance[0]));
}
@Override
public void write(PacketBuffer buffer, CoffeeMachineIngredient recipe){
recipe.getInput().write(buffer);
ListNBT effectsList = new ListNBT();
for(EffectInstance effect : recipe.getEffects()){
CompoundNBT effectTag = new CompoundNBT();
effect.write(effectTag);
effectsList.add(effectTag);
}
CompoundNBT nbt = new CompoundNBT();
nbt.put("effectsList", effectsList);
buffer.writeCompoundTag(nbt);
buffer.writeVarInt(recipe.getMaxAmplifier());
}
}

View File

@ -1,5 +1,6 @@
{
"recipes": {
"atomic_reconstructor": "de.ellpeck.actuallyadditions.recipes.AtomicReconstructorRecipeFactory"
"atomic_reconstructor": "de.ellpeck.actuallyadditions.recipes.AtomicReconstructorRecipeFactory",
"coffee_machine_ingredient": "de.ellpeck.actuallyadditions.recipes.CoffeeMachineIngredientFactory"
}
}