mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-12-22 19:39:24 +01:00
Implemented LaserRecipe... Hopefully...
This commit is contained in:
parent
a881b81237
commit
26343b77c1
4 changed files with 199 additions and 3 deletions
|
@ -29,6 +29,8 @@ public class ActuallyAdditionsData {
|
|||
generator.addProvider(new ItemRecipeGenerator(generator));
|
||||
generator.addProvider(generatorBlockTags);
|
||||
generator.addProvider(new ItemTagsGenerator(generator, generatorBlockTags, helper));
|
||||
|
||||
generator.addProvider(new LaserRecipeGenerator(generator));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
package de.ellpeck.actuallyadditions.data;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
|
||||
import de.ellpeck.actuallyadditions.mod.blocks.ActuallyBlocks;
|
||||
import de.ellpeck.actuallyadditions.mod.crafting.LaserRecipe;
|
||||
import net.minecraft.data.DataGenerator;
|
||||
import net.minecraft.data.DirectoryCache;
|
||||
import net.minecraft.data.IFinishedRecipe;
|
||||
import net.minecraft.data.RecipeProvider;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.Ingredient;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.common.Tags;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class LaserRecipeGenerator extends RecipeProvider {
|
||||
public LaserRecipeGenerator(DataGenerator p_i48262_1_) {
|
||||
super(p_i48262_1_);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void saveAdvancement(DirectoryCache pCache, JsonObject pAdvancementJson, Path pPath) {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void buildShapelessRecipes(Consumer<IFinishedRecipe> consumer) {
|
||||
|
||||
|
||||
consumer.accept(new LaserRecipe.FinishedRecipe(new ResourceLocation(ActuallyAdditions.MODID, "laser_restonia_block"),
|
||||
Ingredient.of(Tags.Items.STORAGE_BLOCKS_REDSTONE), 400, new ItemStack(ActuallyBlocks.RESTONIA_CRYSTAL.getItem())));
|
||||
}
|
||||
}
|
|
@ -2,17 +2,29 @@ package de.ellpeck.actuallyadditions.mod.crafting;
|
|||
|
||||
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
|
||||
import net.minecraft.item.crafting.IRecipeSerializer;
|
||||
import net.minecraft.item.crafting.IRecipeType;
|
||||
import net.minecraftforge.eventbus.api.IEventBus;
|
||||
import net.minecraftforge.fml.RegistryObject;
|
||||
import net.minecraftforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
|
||||
public class ActuallyRecipes {
|
||||
public static final DeferredRegister<IRecipeSerializer<?>> RECIPE_TYPES = DeferredRegister.create(ForgeRegistries.RECIPE_SERIALIZERS, ActuallyAdditions.MODID);
|
||||
public static final DeferredRegister<IRecipeSerializer<?>> SERIALIZERS = DeferredRegister.create(ForgeRegistries.RECIPE_SERIALIZERS, ActuallyAdditions.MODID);
|
||||
|
||||
public static void init(IEventBus bus) {
|
||||
RECIPE_TYPES.register(bus);
|
||||
SERIALIZERS.register(bus);
|
||||
}
|
||||
|
||||
public static final RegistryObject<IRecipeSerializer<?>> KEEP_DATA_SHAPED_RECIPE = RECIPE_TYPES.register(RecipeKeepDataShaped.NAME, RecipeKeepDataShaped.Serializer::new);
|
||||
public static final RegistryObject<IRecipeSerializer<?>> KEEP_DATA_SHAPED_RECIPE = SERIALIZERS.register(RecipeKeepDataShaped.NAME, RecipeKeepDataShaped.Serializer::new);
|
||||
public static final RegistryObject<IRecipeSerializer<?>> LASER_RECIPE = SERIALIZERS.register(LaserRecipe.NAME, LaserRecipe.Serializer::new);
|
||||
|
||||
|
||||
|
||||
public static class Types {
|
||||
public static final IRecipeType<LaserRecipe> LASER = IRecipeType.register(ActuallyAdditions.MODID + ":laser");
|
||||
public static final IRecipeType<LaserRecipe> EMPOWERING = IRecipeType.register(ActuallyAdditions.MODID + ":empower");
|
||||
public static final IRecipeType<LaserRecipe> CRUSHING = IRecipeType.register(ActuallyAdditions.MODID + ":crush");
|
||||
public static final IRecipeType<LaserRecipe> COALGEN = IRecipeType.register(ActuallyAdditions.MODID + ":coal_power");
|
||||
public static final IRecipeType<LaserRecipe> OILGEN = IRecipeType.register(ActuallyAdditions.MODID + ":oil_power");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,147 @@
|
|||
package de.ellpeck.actuallyadditions.mod.crafting;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import net.minecraft.data.IFinishedRecipe;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.*;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.util.JSONUtils;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.registries.ForgeRegistryEntry;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
|
||||
public class LaserRecipe implements IRecipe<IInventory> {
|
||||
public static String NAME = "laser";
|
||||
private ItemStack result;
|
||||
private Ingredient itemIngredient;
|
||||
private int energy;
|
||||
private ResourceLocation id;
|
||||
|
||||
public LaserRecipe(ResourceLocation id, ItemStack result, Ingredient itemIngredient, int energy) {
|
||||
this.result = result;
|
||||
this.itemIngredient = itemIngredient;
|
||||
this.energy = energy;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public int getEnergy() {
|
||||
return energy;
|
||||
}
|
||||
|
||||
public boolean matches(ItemStack itemStack, int energyIn) {
|
||||
|
||||
return itemIngredient.test(itemStack) && (energyIn >= energy);
|
||||
}
|
||||
|
||||
//nah
|
||||
@Override
|
||||
public boolean matches(IInventory pInv, World pLevel) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack assemble(IInventory pInv) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canCraftInDimensions(int pWidth, int pHeight) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getResultItem() {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IRecipeSerializer<?> getSerializer() {
|
||||
return ActuallyRecipes.LASER_RECIPE.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IRecipeType<?> getType() {
|
||||
return ActuallyRecipes.Types.LASER;
|
||||
}
|
||||
|
||||
public static class Serializer extends ForgeRegistryEntry<IRecipeSerializer<?>> implements IRecipeSerializer<LaserRecipe> {
|
||||
|
||||
@Override
|
||||
public LaserRecipe fromJson(ResourceLocation pRecipeId, JsonObject pJson) {
|
||||
Ingredient ingredient = Ingredient.fromJson(JSONUtils.getAsJsonObject(pJson, "ingredient"));
|
||||
int energy = JSONUtils.getAsInt(pJson, "energy");
|
||||
ItemStack result = new ItemStack(JSONUtils.getAsItem(pJson, "result"));
|
||||
|
||||
return new LaserRecipe(pRecipeId, result, ingredient, energy);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public LaserRecipe fromNetwork(ResourceLocation pRecipeId, PacketBuffer pBuffer) {
|
||||
Ingredient ingredient = Ingredient.fromNetwork(pBuffer);
|
||||
int energy = pBuffer.readInt();
|
||||
ItemStack result = pBuffer.readItem();
|
||||
return new LaserRecipe(pRecipeId, result, ingredient, energy);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toNetwork(PacketBuffer pBuffer, LaserRecipe pRecipe) {
|
||||
pRecipe.itemIngredient.toNetwork(pBuffer);
|
||||
pBuffer.writeInt(pRecipe.energy);
|
||||
pBuffer.writeItem(pRecipe.result);
|
||||
}
|
||||
}
|
||||
|
||||
public static class FinishedRecipe implements IFinishedRecipe {
|
||||
private ResourceLocation id;
|
||||
private Ingredient itemIngredient;
|
||||
private int energy;
|
||||
private ItemStack output;
|
||||
|
||||
public FinishedRecipe(ResourceLocation id, Ingredient itemIngredient, int energy, ItemStack output) {
|
||||
this.id = id;
|
||||
this.itemIngredient = itemIngredient;
|
||||
this.energy = energy;
|
||||
this.output = output;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serializeRecipeData(JsonObject pJson) {
|
||||
pJson.add("input", itemIngredient.toJson());
|
||||
pJson.addProperty("energy", energy);
|
||||
pJson.addProperty("output", Registry.ITEM.getKey(output.getItem()).toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IRecipeSerializer<?> getType() {
|
||||
return ActuallyRecipes.LASER_RECIPE.get();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public JsonObject serializeAdvancement() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ResourceLocation getAdvancementId() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue