1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-12-12 11:10:29 +00:00

Move most recipe registration to JSON

We need this for 1.13+, so might as well get it over with.
This commit is contained in:
SquidDev 2018-12-27 12:16:11 +00:00
parent 26ba61097b
commit 618c534d81
13 changed files with 51 additions and 74 deletions

View File

@ -1,14 +1,15 @@
package dan200.computercraft.shared.common; package dan200.computercraft.shared.common;
import com.google.gson.JsonObject;
import dan200.computercraft.shared.util.Colour; import dan200.computercraft.shared.util.Colour;
import dan200.computercraft.shared.util.ColourTracker; import dan200.computercraft.shared.util.ColourTracker;
import dan200.computercraft.shared.util.ColourUtils; import dan200.computercraft.shared.util.ColourUtils;
import net.minecraft.inventory.InventoryCrafting; import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe; import net.minecraft.item.crafting.IRecipe;
import net.minecraft.util.NonNullList;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.ForgeHooks; import net.minecraftforge.common.crafting.IRecipeFactory;
import net.minecraftforge.common.crafting.JsonContext;
import net.minecraftforge.registries.IForgeRegistryEntry; import net.minecraftforge.registries.IForgeRegistryEntry;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
@ -98,16 +99,12 @@ public class ColourableRecipe extends IForgeRegistryEntry.Impl<IRecipe> implemen
return ItemStack.EMPTY; return ItemStack.EMPTY;
} }
@Nonnull public static class Factory implements IRecipeFactory
@Override
public NonNullList<ItemStack> getRemainingItems( @Nonnull InventoryCrafting inventoryCrafting )
{ {
NonNullList<ItemStack> results = NonNullList.withSize( inventoryCrafting.getSizeInventory(), ItemStack.EMPTY ); @Override
for( int i = 0; i < results.size(); i++ ) public IRecipe parse( JsonContext jsonContext, JsonObject jsonObject )
{ {
ItemStack stack = inventoryCrafting.getStackInSlot( i ); return new ColourableRecipe();
results.set( i, ForgeHooks.getContainerItem( stack ) );
} }
return results;
} }
} }

View File

@ -6,6 +6,7 @@
package dan200.computercraft.shared.media.recipes; package dan200.computercraft.shared.media.recipes;
import com.google.gson.JsonObject;
import dan200.computercraft.shared.media.items.ItemDiskLegacy; import dan200.computercraft.shared.media.items.ItemDiskLegacy;
import dan200.computercraft.shared.util.Colour; import dan200.computercraft.shared.util.Colour;
import dan200.computercraft.shared.util.ColourTracker; import dan200.computercraft.shared.util.ColourTracker;
@ -14,9 +15,9 @@ import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe; import net.minecraft.item.crafting.IRecipe;
import net.minecraft.item.crafting.Ingredient; import net.minecraft.item.crafting.Ingredient;
import net.minecraft.util.NonNullList;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.ForgeHooks; import net.minecraftforge.common.crafting.IRecipeFactory;
import net.minecraftforge.common.crafting.JsonContext;
import net.minecraftforge.oredict.OreIngredient; import net.minecraftforge.oredict.OreIngredient;
import net.minecraftforge.registries.IForgeRegistryEntry; import net.minecraftforge.registries.IForgeRegistryEntry;
@ -103,16 +104,12 @@ public class DiskRecipe extends IForgeRegistryEntry.Impl<IRecipe> implements IRe
return ItemDiskLegacy.createFromIDAndColour( -1, null, Colour.Blue.getHex() ); return ItemDiskLegacy.createFromIDAndColour( -1, null, Colour.Blue.getHex() );
} }
@Nonnull public static class Factory implements IRecipeFactory
@Override
public NonNullList<ItemStack> getRemainingItems( @Nonnull InventoryCrafting inventoryCrafting )
{ {
NonNullList<ItemStack> results = NonNullList.withSize( inventoryCrafting.getSizeInventory(), ItemStack.EMPTY ); @Override
for( int i = 0; i < results.size(); i++ ) public IRecipe parse( JsonContext jsonContext, JsonObject jsonObject )
{ {
ItemStack stack = inventoryCrafting.getStackInSlot( i ); return new DiskRecipe();
results.set( i, ForgeHooks.getContainerItem( stack ) );
} }
return results;
} }
} }

View File

@ -6,14 +6,15 @@
package dan200.computercraft.shared.media.recipes; package dan200.computercraft.shared.media.recipes;
import com.google.gson.JsonObject;
import dan200.computercraft.shared.media.items.ItemPrintout; import dan200.computercraft.shared.media.items.ItemPrintout;
import net.minecraft.inventory.InventoryCrafting; import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe; import net.minecraft.item.crafting.IRecipe;
import net.minecraft.item.crafting.Ingredient; import net.minecraft.item.crafting.Ingredient;
import net.minecraft.util.NonNullList;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.ForgeHooks; import net.minecraftforge.common.crafting.IRecipeFactory;
import net.minecraftforge.common.crafting.JsonContext;
import net.minecraftforge.oredict.OreIngredient; import net.minecraftforge.oredict.OreIngredient;
import net.minecraftforge.registries.IForgeRegistryEntry; import net.minecraftforge.registries.IForgeRegistryEntry;
@ -158,16 +159,12 @@ public class PrintoutRecipe extends IForgeRegistryEntry.Impl<IRecipe> implements
return ItemStack.EMPTY; return ItemStack.EMPTY;
} }
@Nonnull public static class Factory implements IRecipeFactory
@Override
public NonNullList<ItemStack> getRemainingItems( @Nonnull InventoryCrafting inventoryCrafting )
{ {
NonNullList<ItemStack> results = NonNullList.withSize( inventoryCrafting.getSizeInventory(), ItemStack.EMPTY ); @Override
for( int i = 0; i < results.size(); i++ ) public IRecipe parse( JsonContext jsonContext, JsonObject jsonObject )
{ {
ItemStack stack = inventoryCrafting.getStackInSlot( i ); return new PrintoutRecipe();
results.set( i, ForgeHooks.getContainerItem( stack ) );
} }
return results;
} }
} }

View File

@ -6,6 +6,7 @@
package dan200.computercraft.shared.pocket.recipes; package dan200.computercraft.shared.pocket.recipes;
import com.google.gson.JsonObject;
import dan200.computercraft.ComputerCraft; import dan200.computercraft.ComputerCraft;
import dan200.computercraft.api.pocket.IPocketUpgrade; import dan200.computercraft.api.pocket.IPocketUpgrade;
import dan200.computercraft.shared.computer.core.ComputerFamily; import dan200.computercraft.shared.computer.core.ComputerFamily;
@ -14,9 +15,9 @@ import dan200.computercraft.shared.pocket.items.PocketComputerItemFactory;
import net.minecraft.inventory.InventoryCrafting; import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe; import net.minecraft.item.crafting.IRecipe;
import net.minecraft.util.NonNullList;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.ForgeHooks; import net.minecraftforge.common.crafting.IRecipeFactory;
import net.minecraftforge.common.crafting.JsonContext;
import net.minecraftforge.registries.IForgeRegistryEntry; import net.minecraftforge.registries.IForgeRegistryEntry;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
@ -126,16 +127,12 @@ public class PocketComputerUpgradeRecipe extends IForgeRegistryEntry.Impl<IRecip
return PocketComputerItemFactory.create( computerID, label, colour, family, upgrade ); return PocketComputerItemFactory.create( computerID, label, colour, family, upgrade );
} }
@Nonnull public static class Factory implements IRecipeFactory
@Override
public NonNullList<ItemStack> getRemainingItems( @Nonnull InventoryCrafting inventoryCrafting )
{ {
NonNullList<ItemStack> results = NonNullList.withSize( inventoryCrafting.getSizeInventory(), ItemStack.EMPTY ); @Override
for( int i = 0; i < results.size(); i++ ) public IRecipe parse( JsonContext jsonContext, JsonObject jsonObject )
{ {
ItemStack stack = inventoryCrafting.getStackInSlot( i ); return new PocketComputerUpgradeRecipe();
results.set( i, ForgeHooks.getContainerItem( stack ) );
} }
return results;
} }
} }

View File

@ -313,7 +313,6 @@ public abstract class CCTurtleProxyCommon implements ICCTurtleProxy
public void registerRecipes( RegistryEvent.Register<IRecipe> event ) public void registerRecipes( RegistryEvent.Register<IRecipe> event )
{ {
IForgeRegistry<IRecipe> registry = event.getRegistry(); IForgeRegistry<IRecipe> registry = event.getRegistry();
registry.register( new TurtleUpgradeRecipe().setRegistryName( new ResourceLocation( "computercraft:turtle" ) ) );
// Add a bunch of impostor recipes // Add a bunch of impostor recipes
// TODO: Figure out a way to do this in a "nice" way. // TODO: Figure out a way to do this in a "nice" way.

View File

@ -12,7 +12,6 @@ import dan200.computercraft.api.pocket.IPocketUpgrade;
import dan200.computercraft.core.computer.MainThread; import dan200.computercraft.core.computer.MainThread;
import dan200.computercraft.shared.command.CommandComputerCraft; import dan200.computercraft.shared.command.CommandComputerCraft;
import dan200.computercraft.shared.command.ContainerViewComputer; import dan200.computercraft.shared.command.ContainerViewComputer;
import dan200.computercraft.shared.common.ColourableRecipe;
import dan200.computercraft.shared.common.DefaultBundledRedstoneProvider; import dan200.computercraft.shared.common.DefaultBundledRedstoneProvider;
import dan200.computercraft.shared.common.TileGeneric; import dan200.computercraft.shared.common.TileGeneric;
import dan200.computercraft.shared.computer.blocks.BlockCommandComputer; import dan200.computercraft.shared.computer.blocks.BlockCommandComputer;
@ -31,7 +30,6 @@ import dan200.computercraft.shared.media.items.ItemDiskExpanded;
import dan200.computercraft.shared.media.items.ItemDiskLegacy; import dan200.computercraft.shared.media.items.ItemDiskLegacy;
import dan200.computercraft.shared.media.items.ItemPrintout; import dan200.computercraft.shared.media.items.ItemPrintout;
import dan200.computercraft.shared.media.items.ItemTreasureDisk; import dan200.computercraft.shared.media.items.ItemTreasureDisk;
import dan200.computercraft.shared.media.recipes.DiskRecipe;
import dan200.computercraft.shared.media.recipes.PrintoutRecipe; import dan200.computercraft.shared.media.recipes.PrintoutRecipe;
import dan200.computercraft.shared.network.ComputerCraftPacket; import dan200.computercraft.shared.network.ComputerCraftPacket;
import dan200.computercraft.shared.peripheral.commandblock.CommandBlockPeripheralProvider; import dan200.computercraft.shared.peripheral.commandblock.CommandBlockPeripheralProvider;
@ -57,7 +55,10 @@ import dan200.computercraft.shared.pocket.peripherals.PocketSpeaker;
import dan200.computercraft.shared.pocket.recipes.PocketComputerUpgradeRecipe; import dan200.computercraft.shared.pocket.recipes.PocketComputerUpgradeRecipe;
import dan200.computercraft.shared.turtle.blocks.TileTurtle; import dan200.computercraft.shared.turtle.blocks.TileTurtle;
import dan200.computercraft.shared.turtle.inventory.ContainerTurtle; import dan200.computercraft.shared.turtle.inventory.ContainerTurtle;
import dan200.computercraft.shared.util.*; import dan200.computercraft.shared.util.Colour;
import dan200.computercraft.shared.util.CreativeTabMain;
import dan200.computercraft.shared.util.ImpostorRecipe;
import dan200.computercraft.shared.util.ImpostorShapelessRecipe;
import dan200.computercraft.shared.wired.CapabilityWiredElement; import dan200.computercraft.shared.wired.CapabilityWiredElement;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.command.CommandHandler; import net.minecraft.command.CommandHandler;
@ -67,7 +68,6 @@ import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.Items; import net.minecraft.init.Items;
import net.minecraft.inventory.Container; import net.minecraft.inventory.Container;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemRecord;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe; import net.minecraft.item.crafting.IRecipe;
import net.minecraft.item.crafting.Ingredient; import net.minecraft.item.crafting.Ingredient;
@ -96,8 +96,6 @@ import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.registries.IForgeRegistry; import net.minecraftforge.registries.IForgeRegistry;
import pl.asie.charset.ModCharset; import pl.asie.charset.ModCharset;
import javax.annotation.Nonnull;
public abstract class ComputerCraftProxyCommon implements IComputerCraftProxy public abstract class ComputerCraftProxyCommon implements IComputerCraftProxy
{ {
@Override @Override
@ -268,12 +266,6 @@ public abstract class ComputerCraftProxyCommon implements IComputerCraftProxy
{ {
IForgeRegistry<IRecipe> registry = event.getRegistry(); IForgeRegistry<IRecipe> registry = event.getRegistry();
// Disk
registry.register( new DiskRecipe().setRegistryName( new ResourceLocation( "computercraft:disk" ) ) );
// Colourable items (turtles, disks)
registry.register( new ColourableRecipe().setRegistryName( new ResourceLocation( "computercraft:colour" ) ) );
// Impostor Disk recipes (to fool NEI) // Impostor Disk recipes (to fool NEI)
ItemStack paper = new ItemStack( Items.PAPER, 1 ); ItemStack paper = new ItemStack( Items.PAPER, 1 );
ItemStack redstone = new ItemStack( Items.REDSTONE, 1 ); ItemStack redstone = new ItemStack( Items.REDSTONE, 1 );
@ -305,12 +297,6 @@ public abstract class ComputerCraftProxyCommon implements IComputerCraftProxy
); );
} }
// Printout
registry.register( new PrintoutRecipe().setRegistryName( new ResourceLocation( "computercraft:printout" ) ) );
// Wireless Pocket Computer
registry.register( new PocketComputerUpgradeRecipe().setRegistryName( new ResourceLocation( "computercraft:pocket_computer_upgrade" ) ) );
// Impostor Pocket Computer recipes (to fool NEI) // Impostor Pocket Computer recipes (to fool NEI)
ItemStack pocketComputer = PocketComputerItemFactory.create( -1, null, -1, ComputerFamily.Normal, null ); ItemStack pocketComputer = PocketComputerItemFactory.create( -1, null, -1, ComputerFamily.Normal, null );
ItemStack advancedPocketComputer = PocketComputerItemFactory.create( -1, null, -1, ComputerFamily.Advanced, null ); ItemStack advancedPocketComputer = PocketComputerItemFactory.create( -1, null, -1, ComputerFamily.Advanced, null );

View File

@ -6,6 +6,7 @@
package dan200.computercraft.shared.turtle.recipes; package dan200.computercraft.shared.turtle.recipes;
import com.google.gson.JsonObject;
import dan200.computercraft.ComputerCraft; import dan200.computercraft.ComputerCraft;
import dan200.computercraft.api.turtle.ITurtleUpgrade; import dan200.computercraft.api.turtle.ITurtleUpgrade;
import dan200.computercraft.api.turtle.TurtleSide; import dan200.computercraft.api.turtle.TurtleSide;
@ -16,20 +17,16 @@ import dan200.computercraft.shared.turtle.items.TurtleItemFactory;
import net.minecraft.inventory.InventoryCrafting; import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe; import net.minecraft.item.crafting.IRecipe;
import net.minecraft.util.NonNullList;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.ForgeHooks; import net.minecraftforge.common.crafting.IRecipeFactory;
import net.minecraftforge.common.crafting.JsonContext;
import net.minecraftforge.registries.IForgeRegistryEntry; import net.minecraftforge.registries.IForgeRegistryEntry;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
public class TurtleUpgradeRecipe extends IForgeRegistryEntry.Impl<IRecipe> implements IRecipe public class TurtleUpgradeRecipe extends IForgeRegistryEntry.Impl<IRecipe> implements IRecipe
{ {
public TurtleUpgradeRecipe()
{
}
@Override @Override
public boolean canFit( int x, int y ) public boolean canFit( int x, int y )
{ {
@ -186,16 +183,12 @@ public class TurtleUpgradeRecipe extends IForgeRegistryEntry.Impl<IRecipe> imple
return TurtleItemFactory.create( computerID, label, colour, family, upgrades[0], upgrades[1], fuelLevel, overlay ); return TurtleItemFactory.create( computerID, label, colour, family, upgrades[0], upgrades[1], fuelLevel, overlay );
} }
@Nonnull public static class Factory implements IRecipeFactory
@Override
public NonNullList<ItemStack> getRemainingItems( @Nonnull InventoryCrafting inventoryCrafting )
{ {
NonNullList<ItemStack> results = NonNullList.withSize( inventoryCrafting.getSizeInventory(), ItemStack.EMPTY ); @Override
for( int i = 0; i < results.size(); i++ ) public IRecipe parse( JsonContext jsonContext, JsonObject jsonObject )
{ {
ItemStack stack = inventoryCrafting.getStackInSlot( i ); return new TurtleUpgradeRecipe();
results.set( i, ForgeHooks.getContainerItem( stack ) );
} }
return results;
} }
} }

View File

@ -2,8 +2,14 @@
"recipes": { "recipes": {
"impostor_shaped": "dan200.computercraft.shared.util.ImpostorRecipe$Factory", "impostor_shaped": "dan200.computercraft.shared.util.ImpostorRecipe$Factory",
"impostor_shapeless": "dan200.computercraft.shared.util.ImpostorShapelessRecipe$Factory", "impostor_shapeless": "dan200.computercraft.shared.util.ImpostorShapelessRecipe$Factory",
"colour": "dan200.computercraft.shared.common.ColourableRecipe$Factory",
"computer_upgrade": "dan200.computercraft.shared.computer.recipe.ComputerFamilyRecipe$Factory",
"disk": "dan200.computercraft.shared.media.recipes.DiskRecipe$Factory",
"pocket_computer_upgrade": "dan200.computercraft.shared.pocket.recipes.PocketComputerUpgradeRecipe$Factory",
"printout": "dan200.computercraft.shared.media.recipes.PrintoutRecipe$Factory",
"turtle": "dan200.computercraft.shared.turtle.recipes.TurtleRecipe$Factory", "turtle": "dan200.computercraft.shared.turtle.recipes.TurtleRecipe$Factory",
"computer_upgrade": "dan200.computercraft.shared.computer.recipe.ComputerFamilyRecipe$Factory" "turtle_upgrade": "dan200.computercraft.shared.turtle.recipes.TurtleUpgradeRecipe$Factory"
}, },
"ingredients": { "ingredients": {
"computer": "dan200.computercraft.shared.computer.recipe.ComputerIngredient$Factory" "computer": "dan200.computercraft.shared.computer.recipe.ComputerIngredient$Factory"

View File

@ -0,0 +1 @@
{ "type": "computercraft:colour" }

View File

@ -0,0 +1 @@
{ "type": "computercraft:disk" }

View File

@ -0,0 +1 @@
{ "type": "computercraft:pocket_computer_upgrade" }

View File

@ -0,0 +1 @@
{ "type": "computercraft:printout" }

View File

@ -0,0 +1 @@
{ "type": "computercraft:turtle_upgrade" }