1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-07-05 19:42:54 +00:00
Jonathan Coates 34b5ede326 Switch to Mojang mappings
ForgeGradle (probably sensibly) yells at me about doing this. However:
 - There's a reasonable number of mods doing this, which establishes
   some optimistic precedent.
 - The licence update in Aug 2020 now allows you to use them for
   "development purposes". I guess source code counts??
 - I'm fairly sure this is also compatible with the CCPL - there's an
   exception for Minecraft code.

The main motivation for this is to make the Fabric port a little
easier. Hopefully folks (maybe me in the future, we'll see) will no
longer have to deal with mapping hell when merging - only mod loader
hell.
2021-01-09 19:22:58 +00:00

81 lines
3.2 KiB
Java

/*
* This file is part of ComputerCraft - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2021. Do not distribute without permission.
* Send enquiries to dratcliffe@gmail.com
*/
package dan200.computercraft.shared.computer.recipe;
import com.google.gson.JsonObject;
import dan200.computercraft.shared.computer.core.ComputerFamily;
import dan200.computercraft.shared.util.BasicRecipeSerializer;
import dan200.computercraft.shared.util.RecipeUtil;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.Ingredient;
import net.minecraft.network.PacketBuffer;
import net.minecraft.util.JSONUtils;
import net.minecraft.util.NonNullList;
import net.minecraft.util.ResourceLocation;
import javax.annotation.Nonnull;
public abstract class ComputerFamilyRecipe extends ComputerConvertRecipe
{
private final ComputerFamily family;
public ComputerFamilyRecipe( ResourceLocation identifier, String group, int width, int height, NonNullList<Ingredient> ingredients, ItemStack result, ComputerFamily family )
{
super( identifier, group, width, height, ingredients, result );
this.family = family;
}
public ComputerFamily getFamily()
{
return family;
}
public abstract static class Serializer<T extends ComputerFamilyRecipe> extends BasicRecipeSerializer<T>
{
protected abstract T create( ResourceLocation identifier, String group, int width, int height, NonNullList<Ingredient> ingredients, ItemStack result, ComputerFamily family );
@Nonnull
@Override
public T fromJson( @Nonnull ResourceLocation identifier, @Nonnull JsonObject json )
{
String group = JSONUtils.getAsString( json, "group", "" );
ComputerFamily family = RecipeUtil.getFamily( json, "family" );
RecipeUtil.ShapedTemplate template = RecipeUtil.getTemplate( json );
ItemStack result = itemFromJson( JSONUtils.getAsJsonObject( json, "result" ) );
return create( identifier, group, template.width, template.height, template.ingredients, result, family );
}
@Nonnull
@Override
public T fromNetwork( @Nonnull ResourceLocation identifier, @Nonnull PacketBuffer buf )
{
int width = buf.readVarInt();
int height = buf.readVarInt();
String group = buf.readUtf( Short.MAX_VALUE );
NonNullList<Ingredient> ingredients = NonNullList.withSize( width * height, Ingredient.EMPTY );
for( int i = 0; i < ingredients.size(); i++ ) ingredients.set( i, Ingredient.fromNetwork( buf ) );
ItemStack result = buf.readItem();
ComputerFamily family = buf.readEnum( ComputerFamily.class );
return create( identifier, group, width, height, ingredients, result, family );
}
@Override
public void toNetwork( @Nonnull PacketBuffer buf, @Nonnull T recipe )
{
buf.writeVarInt( recipe.getWidth() );
buf.writeVarInt( recipe.getHeight() );
buf.writeUtf( recipe.getGroup() );
for( Ingredient ingredient : recipe.getIngredients() ) ingredient.toNetwork( buf );
buf.writeItem( recipe.getResultItem() );
buf.writeEnum( recipe.getFamily() );
}
}
}