Crushy McCrushRecipeFace

This commit is contained in:
Flanks255 2021-10-24 11:49:48 -05:00
parent 93fdf5a674
commit 9b11bf3245
8 changed files with 211 additions and 67 deletions

View file

@ -19,6 +19,7 @@ import de.ellpeck.actuallyadditions.api.laser.ILaserRelayConnectionHandler;
import de.ellpeck.actuallyadditions.api.lens.Lens; import de.ellpeck.actuallyadditions.api.lens.Lens;
import de.ellpeck.actuallyadditions.api.lens.LensConversion; import de.ellpeck.actuallyadditions.api.lens.LensConversion;
import de.ellpeck.actuallyadditions.api.recipe.*; import de.ellpeck.actuallyadditions.api.recipe.*;
import de.ellpeck.actuallyadditions.mod.crafting.CrushingRecipe;
import de.ellpeck.actuallyadditions.mod.crafting.EmpowererRecipe; import de.ellpeck.actuallyadditions.mod.crafting.EmpowererRecipe;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
@ -38,7 +39,7 @@ public final class ActuallyAdditionsAPI {
public static final String API_ID = MOD_ID + "api"; public static final String API_ID = MOD_ID + "api";
public static final String API_VERSION = "34"; public static final String API_VERSION = "34";
public static final List<CrusherRecipe> CRUSHER_RECIPES = new ArrayList<>(); public static final List<CrushingRecipe> CRUSHER_RECIPES = new ArrayList<>();
public static final List<BallOfFurReturn> BALL_OF_FUR_RETURN_ITEMS = new ArrayList<>(); public static final List<BallOfFurReturn> BALL_OF_FUR_RETURN_ITEMS = new ArrayList<>();
// public static final List<TreasureChestLoot> TREASURE_CHEST_LOOT = new ArrayList<>(); // public static final List<TreasureChestLoot> TREASURE_CHEST_LOOT = new ArrayList<>();
public static final List<LensConversionRecipe> RECONSTRUCTOR_LENS_CONVERSION_RECIPES = new ArrayList<>(); public static final List<LensConversionRecipe> RECONSTRUCTOR_LENS_CONVERSION_RECIPES = new ArrayList<>();
@ -133,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 CrusherRecipe(Ingredient.of(input), outputOne, outputTwo.isEmpty() CRUSHER_RECIPES.add(new CrushingRecipe(Ingredient.of(input), outputOne, outputTwo.isEmpty()
? ItemStack.EMPTY ? ItemStack.EMPTY
: outputTwo, outputTwoChance)); : outputTwo, outputTwoChance));
} }
@ -147,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 CrusherRecipe(input, outputOne, outputTwo.isEmpty() CRUSHER_RECIPES.add(new CrushingRecipe(input, outputOne, outputTwo.isEmpty()
? ItemStack.EMPTY ? ItemStack.EMPTY
: outputTwo, outputTwoChance)); : outputTwo, outputTwoChance));
} }

View file

@ -1,55 +0,0 @@
/*
* This file ("CrusherRecipe.java") is part of the Actually Additions mod for Minecraft.
* It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at
* http://ellpeck.de/actaddlicense
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
* © 2015-2017 Ellpeck
*/
package de.ellpeck.actuallyadditions.api.recipe;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.Ingredient;
public class CrusherRecipe {
protected Ingredient input;
protected ItemStack outputOne;
protected ItemStack outputTwo;
protected int outputChance;
@Deprecated
public CrusherRecipe(ItemStack input, ItemStack outputOne, ItemStack outputTwo, int outputChance) {
this(Ingredient.of(input), outputOne, outputTwo, outputChance);
}
public CrusherRecipe(Ingredient input, ItemStack outputOne, ItemStack outputTwo, int outputChance) {
this.input = input;
this.outputOne = outputOne;
this.outputTwo = outputTwo;
this.outputChance = outputChance;
}
public boolean matches(ItemStack stack) {
return this.input.test(stack);
}
public ItemStack getOutputOne() {
return this.outputOne;
}
public ItemStack getOutputTwo() {
return this.outputTwo;
}
public int getSecondChance() {
return this.outputChance;
}
public Ingredient getInput() {
return this.input;
}
}

View file

@ -32,6 +32,7 @@ public class ActuallyAdditionsData {
generator.addProvider(new LaserRecipeGenerator(generator)); generator.addProvider(new LaserRecipeGenerator(generator));
generator.addProvider(new EmpoweringRecipeGenerator(generator)); generator.addProvider(new EmpoweringRecipeGenerator(generator));
generator.addProvider(new CrushingRecipeGenerator(generator));
} }
} }
} }

View file

@ -0,0 +1,25 @@
package de.ellpeck.actuallyadditions.data;
import com.google.gson.JsonObject;
import net.minecraft.data.DataGenerator;
import net.minecraft.data.DirectoryCache;
import net.minecraft.data.IFinishedRecipe;
import net.minecraft.data.RecipeProvider;
import java.nio.file.Path;
import java.util.function.Consumer;
public class CrushingRecipeGenerator extends RecipeProvider {
public CrushingRecipeGenerator(DataGenerator p_i48262_1_) {
super(p_i48262_1_);
}
@Override
protected void saveAdvancement(DirectoryCache p_208310_1_, JsonObject p_208310_2_, Path p_208310_3_) {
}
@Override
protected void buildShapelessRecipes(Consumer<IFinishedRecipe> p_200404_1_) {
}
}

View file

@ -11,9 +11,9 @@
package de.ellpeck.actuallyadditions.mod.booklet.page; package de.ellpeck.actuallyadditions.mod.booklet.page;
import de.ellpeck.actuallyadditions.api.booklet.internal.GuiBookletBase; import de.ellpeck.actuallyadditions.api.booklet.internal.GuiBookletBase;
import de.ellpeck.actuallyadditions.api.recipe.CrusherRecipe;
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
import de.ellpeck.actuallyadditions.mod.booklet.gui.GuiBooklet; import de.ellpeck.actuallyadditions.mod.booklet.gui.GuiBooklet;
import de.ellpeck.actuallyadditions.mod.crafting.CrushingRecipe;
import de.ellpeck.actuallyadditions.mod.util.StackUtil; import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import de.ellpeck.actuallyadditions.mod.util.StringUtil; import de.ellpeck.actuallyadditions.mod.util.StringUtil;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
@ -25,12 +25,12 @@ import java.util.List;
public class PageCrusherRecipe extends BookletPage { public class PageCrusherRecipe extends BookletPage {
private final CrusherRecipe recipe; private final CrushingRecipe recipe;
private int counter = 0; private int counter = 0;
private int rotate = 0; private int rotate = 0;
private final ItemStack[] stacks; private final ItemStack[] stacks;
public PageCrusherRecipe(int localizationKey, CrusherRecipe recipe) { public PageCrusherRecipe(int localizationKey, CrushingRecipe recipe) {
super(localizationKey); super(localizationKey);
this.recipe = recipe; this.recipe = recipe;
this.stacks = recipe.getInput().getItems(); this.stacks = recipe.getInput().getItems();

View file

@ -18,13 +18,14 @@ public class ActuallyRecipes {
public static final RegistryObject<IRecipeSerializer<?>> KEEP_DATA_SHAPED_RECIPE = SERIALIZERS.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 final RegistryObject<IRecipeSerializer<?>> LASER_RECIPE = SERIALIZERS.register(LaserRecipe.NAME, LaserRecipe.Serializer::new);
public static final RegistryObject<IRecipeSerializer<?>> EMPOWERING_RECIPE = SERIALIZERS.register(EmpowererRecipe.NAME, EmpowererRecipe.Serializer::new); public static final RegistryObject<IRecipeSerializer<?>> EMPOWERING_RECIPE = SERIALIZERS.register(EmpowererRecipe.NAME, EmpowererRecipe.Serializer::new);
public static final RegistryObject<IRecipeSerializer<?>> CRUSHING_RECIPE = SERIALIZERS.register(CrushingRecipe.NAME, CrushingRecipe.Serializer::new);
public static class Types { public static class Types {
public static final IRecipeType<LaserRecipe> LASER = IRecipeType.register(ActuallyAdditions.MODID + ":laser"); public static final IRecipeType<LaserRecipe> LASER = IRecipeType.register(ActuallyAdditions.MODID + ":laser");
public static final IRecipeType<EmpowererRecipe> EMPOWERING = IRecipeType.register(ActuallyAdditions.MODID + ":empower"); public static final IRecipeType<EmpowererRecipe> EMPOWERING = IRecipeType.register(ActuallyAdditions.MODID + ":empower");
//public static final IRecipeType<CrushingRecipe> CRUSHING = IRecipeType.register(ActuallyAdditions.MODID + ":crush"); public static final IRecipeType<CrushingRecipe> CRUSHING = IRecipeType.register(ActuallyAdditions.MODID + ":crushing");
//public static final IRecipeType<SolidFuelRecipe> SOLIDFUEL = IRecipeType.register(ActuallyAdditions.MODID + ":solid_fuel"); //public static final IRecipeType<SolidFuelRecipe> SOLIDFUEL = IRecipeType.register(ActuallyAdditions.MODID + ":solid_fuel");
//public static final IRecipeType<LiquidFuelRecipe> LIQUIDFUEL = IRecipeType.register(ActuallyAdditions.MODID + ":liquid_fuel"); //public static final IRecipeType<LiquidFuelRecipe> LIQUIDFUEL = IRecipeType.register(ActuallyAdditions.MODID + ":liquid_fuel");
//public static final IRecipeType<PressingRecipe> PRESSING = IRecipeType.register(ActuallyAdditions.MODID + ":pressing"); //public static final IRecipeType<PressingRecipe> PRESSING = IRecipeType.register(ActuallyAdditions.MODID + ":pressing");

View file

@ -0,0 +1,173 @@
package de.ellpeck.actuallyadditions.mod.crafting;
import com.google.gson.JsonObject;
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
import net.minecraft.data.IFinishedRecipe;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
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.util.IItemProvider;
import net.minecraft.util.JSONUtils;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import net.minecraftforge.registries.ForgeRegistryEntry;
import javax.annotation.Nullable;
public class CrushingRecipe implements IRecipe<IInventory> {
public static String NAME = "crushing";
private ResourceLocation id;
protected Ingredient input;
protected ItemStack outputOne;
protected ItemStack outputTwo;
protected int outputChance;
public CrushingRecipe(ResourceLocation id, Ingredient input, ItemStack outputOne, ItemStack outputTwo, int outputChance) {
this.id = id;
this.input = input;
this.outputOne = outputOne;
this.outputTwo = outputTwo;
this.outputChance = outputChance;
}
public CrushingRecipe(Ingredient input, ItemStack outputOne, ItemStack outputTwo, int outputChance) {
this.id = new ResourceLocation(ActuallyAdditions.MODID, input.getItems()[0].getItem().getRegistryName().getPath() + "_crushing");
this.input = input;
this.outputOne = outputOne;
this.outputTwo = outputTwo;
this.outputChance = outputChance;
}
@Override
public boolean matches(IInventory pInv, World pLevel) {
return input.test(pInv.getItem(0));
}
@Override
public ItemStack assemble(IInventory pInv) {
return ItemStack.EMPTY;
}
@Override
public boolean canCraftInDimensions(int pWidth, int pHeight) {
return true;
}
@Override
public ItemStack getResultItem() {
return outputOne;
}
@Override
public ResourceLocation getId() {
return id;
}
@Override
public IRecipeSerializer<?> getSerializer() {
return ActuallyRecipes.CRUSHING_RECIPE.get();
}
@Override
public IRecipeType<?> getType() {
return ActuallyRecipes.Types.CRUSHING;
}
public ItemStack getOutputOne() {
return this.outputOne;
}
public ItemStack getOutputTwo() {
return this.outputTwo;
}
public int getSecondChance() {
return this.outputChance;
}
public Ingredient getInput() {
return this.input;
}
public static class Serializer extends ForgeRegistryEntry<IRecipeSerializer<?>> implements IRecipeSerializer<CrushingRecipe> {
@Override
public CrushingRecipe fromJson(ResourceLocation pRecipeId, JsonObject pJson) {
Ingredient ingredient = Ingredient.fromJson(JSONUtils.getAsJsonObject(pJson, "input"));
ItemStack output1 = new ItemStack(JSONUtils.getAsItem(pJson, "output_one"));
ItemStack output2 = new ItemStack(JSONUtils.getAsItem(pJson, "output_two"));
int chance = JSONUtils.getAsInt(pJson, "second_chance");
return new CrushingRecipe(pRecipeId, ingredient, output1, output2, chance);
}
@Nullable
@Override
public CrushingRecipe fromNetwork(ResourceLocation pRecipeId, PacketBuffer pBuffer) {
Ingredient ingredient = Ingredient.fromNetwork(pBuffer);
ItemStack output1 = pBuffer.readItem();
ItemStack output2 = pBuffer.readItem();
int chance = pBuffer.readInt();
return new CrushingRecipe(pRecipeId, ingredient, output1, output2, chance);
}
@Override
public void toNetwork(PacketBuffer pBuffer, CrushingRecipe pRecipe) {
pRecipe.input.toNetwork(pBuffer);
pBuffer.writeItem(pRecipe.outputOne);
pBuffer.writeItem(pRecipe.outputTwo);
pBuffer.writeInt(pRecipe.outputChance);
}
}
public static class FinishedRecipe implements IFinishedRecipe {
private ResourceLocation id;
protected Ingredient input;
protected IItemProvider outputOne;
protected IItemProvider outputTwo;
protected int outputChance;
public FinishedRecipe(ResourceLocation id, Ingredient input, IItemProvider outputOne, IItemProvider outputTwo, int outputChance) {
this.id = id;
this.input = input;
this.outputOne = outputOne;
this.outputTwo = outputTwo;
this.outputChance = outputChance;
}
@Override
public void serializeRecipeData(JsonObject pJson) {
pJson.add("input", input.toJson());
pJson.addProperty("output_one", outputOne.asItem().getRegistryName().toString());
pJson.addProperty("output_two", outputTwo.asItem().getRegistryName().toString());
pJson.addProperty("second_chance", outputChance);
}
@Override
public ResourceLocation getId() {
return id;
}
@Override
public IRecipeSerializer<?> getType() {
return ActuallyRecipes.CRUSHING_RECIPE.get();
}
@Nullable
@Override
public JsonObject serializeAdvancement() {
return null;
}
@Nullable
@Override
public ResourceLocation getAdvancementId() {
return null;
}
}
}

View file

@ -10,9 +10,8 @@
package de.ellpeck.actuallyadditions.mod.tile; package de.ellpeck.actuallyadditions.mod.tile;
import de.ellpeck.actuallyadditions.api.recipe.CrusherRecipe;
import de.ellpeck.actuallyadditions.mod.blocks.ActuallyBlocks; import de.ellpeck.actuallyadditions.mod.blocks.ActuallyBlocks;
import de.ellpeck.actuallyadditions.mod.blocks.BlockPoweredFurnace; import de.ellpeck.actuallyadditions.mod.crafting.CrushingRecipe;
import de.ellpeck.actuallyadditions.mod.inventory.ContainerGrinder; import de.ellpeck.actuallyadditions.mod.inventory.ContainerGrinder;
import de.ellpeck.actuallyadditions.mod.misc.SoundHandler; import de.ellpeck.actuallyadditions.mod.misc.SoundHandler;
import de.ellpeck.actuallyadditions.mod.network.gui.IButtonReactor; import de.ellpeck.actuallyadditions.mod.network.gui.IButtonReactor;
@ -20,7 +19,6 @@ import de.ellpeck.actuallyadditions.mod.recipe.CrusherRecipeRegistry;
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IAcceptor; import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IAcceptor;
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IRemover; import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IRemover;
import de.ellpeck.actuallyadditions.mod.util.StackUtil; import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import de.ellpeck.actuallyadditions.mod.util.Util;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory; import net.minecraft.entity.player.PlayerInventory;
@ -189,7 +187,7 @@ public class TileEntityCrusher extends TileEntityInventoryBase implements IButto
public boolean canCrushOn(int theInput, int theFirstOutput, int theSecondOutput) { public boolean canCrushOn(int theInput, int theFirstOutput, int theSecondOutput) {
if (StackUtil.isValid(this.inv.getStackInSlot(theInput))) { if (StackUtil.isValid(this.inv.getStackInSlot(theInput))) {
CrusherRecipe recipe = CrusherRecipeRegistry.getRecipeFromInput(this.inv.getStackInSlot(theInput)); CrushingRecipe recipe = CrusherRecipeRegistry.getRecipeFromInput(this.inv.getStackInSlot(theInput));
if (recipe == null) { if (recipe == null) {
return false; return false;
} }
@ -219,7 +217,7 @@ public class TileEntityCrusher extends TileEntityInventoryBase implements IButto
} }
public void finishCrushing(int theInput, int theFirstOutput, int theSecondOutput) { public void finishCrushing(int theInput, int theFirstOutput, int theSecondOutput) {
CrusherRecipe recipe = CrusherRecipeRegistry.getRecipeFromInput(this.inv.getStackInSlot(theInput)); CrushingRecipe recipe = CrusherRecipeRegistry.getRecipeFromInput(this.inv.getStackInSlot(theInput));
if (recipe == null) { if (recipe == null) {
return; return;
} }