Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Blooode

Members
  • Posts

    4
  • Joined

  • Last visited

Posts posted by Blooode

  1. 10 hours ago, Luis_ST said:

    you will need:

    • a custom block (your crafting table block)
    • a custom WorkbenchContainer, you need to overwrite the stillValid method and if you want you can change some vanilla logic

     

    I have block, container and gui. But what I need to do my custom recipes in it?

  2. I made a block with working inventory. In my crafting table vanilla crafts and custom crafts are working, but i can't create my own recipe type with custom crafts for only this crafting table. Help pls :)

    public class BasicArmorTable extends Block {
    	
    	public BasicArmorTable(String name)
        {
            super(Material.WOOD);
            setUnlocalizedName(name);
    		setRegistryName(name);
    		setHardness(9.0F);
    		setHarvestLevel("axe", 1);
    		setResistance(5.0F);
    		setSoundType(SoundType.WOOD);     
            
            BlockInit.BLOCKS.add(this);
    		ItemInit.ITEMS.add(new ItemBlock(this).setRegistryName(this.getRegistryName()));
        }
    
    	 @Override
    		public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    			
    			if(!worldIn.isRemote) {
    				
    				//playerIn.displayGui(new BasicArmorTable.InterfaceCraftingTable(worldIn, pos));
    				playerIn.openGui(Main.instance, Reference.GUI_BASIC_ARMOR_TABLE , worldIn, pos.getX(), pos.getY(), pos.getZ());
    				//playerIn.addStat(BasicArmorTableStat.BASIC_ARMOR_TABLE_INTERACTION);
    			}
    			
    			return true;
    		}
    	 
    	 /*public static class InterfaceCraftingTable implements IInteractionObject
         {
             private final World world;
             private final BlockPos position;
    
             public InterfaceCraftingTable(World worldIn, BlockPos pos)
             {
                 this.world = worldIn;
                 this.position = pos;
             }
    
             public String getName()
             {
                 return "basic_armor_table";
             }
    
             public boolean hasCustomName()
             {
                 return false;
             }
    
             public ITextComponent getDisplayName()
             {
                 return new TextComponentTranslation(BlockInit.BASIC_ARMOR_TABLE.getUnlocalizedName() + ".name", new Object[0]);
             }
    
             public Container createContainer(InventoryPlayer playerInventory, EntityPlayer playerIn)
             {
                 return new ContainerWorkbench(playerInventory, this.world, this.position);
             }
    
             public String getGuiID()
             {
                 return "me:gui_basic_armor_table";
             }
         }*/
    }
    public class BasicArmorTableCraftingManager
    {
    	private static final CraftingManager instance = new CraftingManager();
        private static final Logger LOGGER = LogManager.getLogger();
        private static int nextAvailableId;
        public static final RegistryNamespaced<ResourceLocation, IRecipe> REGISTRY = net.minecraftforge.registries.GameData.getWrapper(IRecipe.class);
    
        public static final CraftingManager getInstance() {
        	
        	return instance;
        }
        
        public static boolean init()
        {
            try
            {
                /*register("armordye", new RecipesArmorDyes());
                register("bookcloning", new RecipeBookCloning());
                register("mapcloning", new RecipesMapCloning());
                register("mapextending", new RecipesMapExtending());
                register("fireworks", new RecipeFireworks());
                register("repairitem", new RecipeRepairItem());
                register("tippedarrow", new RecipeTippedArrow());
                register("bannerduplicate", new RecipesBanners.RecipeDuplicatePattern());
                register("banneraddpattern", new RecipesBanners.RecipeAddPattern());
                register("shielddecoration", new ShieldRecipes.Decoration());
                register("shulkerboxcoloring", new ShulkerBoxRecipes.ShulkerBoxColoring());*/
                return parseJsonRecipes();
            }
            catch (Throwable var1)
            {
                return false;
            }
        }
    
        private static boolean parseJsonRecipes()
        {
            FileSystem filesystem = null;
            Gson gson = (new GsonBuilder()).setPrettyPrinting().disableHtmlEscaping().create();
            boolean flag1;
    
            try
            {
                URL url = BasicArmorTableCraftingManager.class.getResource("/assets/.mcassetsroot");
    
                if (url != null)
                {
                    URI uri = url.toURI();
                    Path path;
    
                    if ("file".equals(uri.getScheme()))
                    {
                        path = Paths.get(BasicArmorTableCraftingManager.class.getResource("/assets/me/recipes").toURI());
                    }
                    else
                    {
                        if (!"jar".equals(uri.getScheme()))
                        {
                            LOGGER.error("Unsupported scheme " + uri + " trying to list all recipes");
                            boolean flag2 = false;
                            return flag2;
                        }
    
                        filesystem = FileSystems.newFileSystem(uri, Collections.emptyMap());
                        path = filesystem.getPath("/assets/me/recipes");
                    }
    
                    Iterator<Path> iterator = Files.walk(path).iterator();
    
                    while (iterator.hasNext())
                    {
                        Path path1 = iterator.next();
    
                        if ("json".equals(FilenameUtils.getExtension(path1.toString())))
                        {
                            Path path2 = path.relativize(path1);
                            String s = FilenameUtils.removeExtension(path2.toString()).replaceAll("\\\\", "/");
                            ResourceLocation resourcelocation = new ResourceLocation(s);
                            BufferedReader bufferedreader = null;
    
                            try
                            {
                                boolean flag;
    
                                try
                                {
                                    bufferedreader = Files.newBufferedReader(path1);
                                    register(s, parseRecipeJson((JsonObject)JsonUtils.fromJson(gson, bufferedreader, JsonObject.class)));
                                }
                                catch (JsonParseException jsonparseexception)
                                {
                                    LOGGER.error("Parsing error loading recipe " + resourcelocation, (Throwable)jsonparseexception);
                                    flag = false;
                                    return flag;
                                }
                                catch (IOException ioexception)
                                {
                                    LOGGER.error("Couldn't read recipe " + resourcelocation + " from " + path1, (Throwable)ioexception);
                                    flag = false;
                                    return flag;
                                }
                            }
                            finally
                            {
                                IOUtils.closeQuietly((Reader)bufferedreader);
                            }
                        }
                    }
    
                    return true;
                }
    
                LOGGER.error("Couldn't find .mcassetsroot");
                flag1 = false;
            }
            catch (IOException | URISyntaxException urisyntaxexception)
            {
                LOGGER.error("Couldn't get a list of all recipe files", (Throwable)urisyntaxexception);
                flag1 = false;
                return flag1;
            }
            finally
            {
                IOUtils.closeQuietly((Closeable)filesystem);
            }
    
            return flag1;
        }
    
        private static IRecipe parseRecipeJson(JsonObject p_193376_0_)
        {
            String s = JsonUtils.getString(p_193376_0_, "type");
    
            if ("basic_armor_table_shaped".equals(s))
            {
                return BasicArmorTableShapedRecipe.deserialize(p_193376_0_);
            }
            /*else if ("crafting_shapeless".equals(s))
            {
                return ShapelessRecipes.deserialize(p_193376_0_);
            }*/
            else
            {
                throw new JsonSyntaxException("Invalid or unsupported recipe type '" + s + "'");
            }
        }
    
        //Forge: Made private use GameData/Registry events!
        private static void register(String name, IRecipe recipe)
        {
            register(new ResourceLocation(name), recipe);
        }
    
        //Forge: Made private use GameData/Registry events!
        private static void register(ResourceLocation name, IRecipe recipe)
        {
            if (REGISTRY.containsKey(name))
            {
                throw new IllegalStateException("Duplicate recipe ignored with ID " + name);
            }
            else
            {
                REGISTRY.register(nextAvailableId++, name, recipe);
            }
        }
    
        /**
         * Retrieves an ItemStack that has multiple recipes for it.
         */
        public static ItemStack findMatchingResult(InventoryCrafting craftMatrix, World worldIn)
        {
            for (IRecipe irecipe : REGISTRY)
            {
                if (irecipe.matches(craftMatrix, worldIn))
                {
                    return irecipe.getCraftingResult(craftMatrix);
                }
            }
    
            return ItemStack.EMPTY;
        }
    
        @Nullable
        public static IRecipe findMatchingRecipe(InventoryCrafting craftMatrix, World worldIn)
        {
            for (IRecipe irecipe : REGISTRY)
            {
                if (irecipe.matches(craftMatrix, worldIn))
                {
                    return irecipe;
                }
            }
    
            return null;
        }
        
        @Nullable
        public static IRecipe findBasicArmorTableRecipe(InventoryCrafting craftMatrix, World worldIn)
        {
            for (IRecipe irecipe : REGISTRY)
            {
                if (irecipe.matches(craftMatrix, worldIn))
                {
                    return irecipe;
                }
            }
    
            return null;
        }
        
        public static ItemStack getBasicArmorTableCraftingResult(InventoryCrafting matrix, World world) {
            for (IRecipe recipe : REGISTRY) {
                if (recipe.matches(matrix, world)) {
                    return recipe.getCraftingResult(matrix);
                }
            }
            return ItemStack.EMPTY;
        }
    
        public static NonNullList<ItemStack> getRemainingItems(InventoryCrafting craftMatrix, World worldIn)
        {
            for (IRecipe irecipe : REGISTRY)
            {
                if (irecipe.matches(craftMatrix, worldIn))
                {
                    return irecipe.getRemainingItems(craftMatrix);
                }
            }
    
            NonNullList<ItemStack> nonnulllist = NonNullList.<ItemStack>withSize(craftMatrix.getSizeInventory(), ItemStack.EMPTY);
    
            for (int i = 0; i < nonnulllist.size(); ++i)
            {
                nonnulllist.set(i, craftMatrix.getStackInSlot(i));
            }
    
            return nonnulllist;
        }
    
        @Nullable
        public static IRecipe getRecipe(ResourceLocation name)
        {
            return REGISTRY.getObject(name);
        }
    
        @Deprecated //DO NOT USE THIS
        public static int getIDForRecipe(IRecipe recipe)
        {
            return REGISTRY.getIDForObject(recipe);
        }
    
        @Deprecated //DO NOT USE THIS
        @Nullable
        public static IRecipe getRecipeById(int id)
        {
            return REGISTRY.getObjectById(id);
        }
    }
    public class BasicArmorTableCraftResult extends InventoryCraftResult {
    
    	 private final NonNullList<ItemStack> stackResult = NonNullList.<ItemStack>withSize(1, ItemStack.EMPTY);
    
        @Override
        public ItemStack getStackInSlot(int par1) {
            return stackResult.get(0);
        }
        
        public int getSizeInventory()
        {
            return 1;
        }
        
        public boolean isEmpty()
        {
            for (ItemStack itemstack : this.stackResult)
            {
                if (!itemstack.isEmpty())
                {
                    return false;
                }
            }
    
            return true;
        }
    
        @Override
        public ItemStack decrStackSize(int par1, int par2) {
        	return ItemStackHelper.getAndRemove(this.stackResult, 0);
        }
        
        public ItemStack removeStackFromSlot(int index)
        {
            return ItemStackHelper.getAndRemove(this.stackResult, 0);
        }
    
        @Override
        public void setInventorySlotContents(int par1, ItemStack par2ItemStack) {
            stackResult.set(0, par2ItemStack);
        }
    
    }
    public class BasicArmorTableShapedRecipe extends net.minecraftforge.registries.IForgeRegistryEntry.Impl<IRecipe> implements net.minecraftforge.common.crafting.IShapedRecipe
    {
        public final int recipeWidth;
        public final int recipeHeight;
        public final NonNullList<Ingredient> recipeItems;
        private final ItemStack recipeOutput;
        private final String group;
    
        public BasicArmorTableShapedRecipe(String group, int width, int height, NonNullList<Ingredient> ingredients, ItemStack result)
        {
            this.group = group;
            this.recipeWidth = width;
            this.recipeHeight = height;
            this.recipeItems = ingredients;
            this.recipeOutput = result;
        }
    
        public String getGroup()
        {
            return this.group;
        }
    
        public ItemStack getRecipeOutput()
        {
            return this.recipeOutput;
        }
    
        public NonNullList<ItemStack> getRemainingItems(InventoryCrafting inv)
        {
            NonNullList<ItemStack> nonnulllist = NonNullList.<ItemStack>withSize(inv.getSizeInventory(), ItemStack.EMPTY);
    
            for (int i = 0; i < nonnulllist.size(); ++i)
            {
                ItemStack itemstack = inv.getStackInSlot(i);
    
                nonnulllist.set(i, net.minecraftforge.common.ForgeHooks.getContainerItem(itemstack));
            }
    
            return nonnulllist;
        }
    
        public NonNullList<Ingredient> getIngredients()
        {
            return this.recipeItems;
        }
    
        /**
         * Used to determine if this recipe can fit in a grid of the given width/height
         */
        public boolean canFit(int width, int height)
        {
            return width >= 5 && height >= 5;
        }
    
        /**
         * Used to check if a recipe matches current crafting inventory
         */
        public boolean matches(InventoryCrafting inv, World worldIn)
        {
            for (int i = 0; i <= inv.getWidth() - this.recipeWidth; ++i)
            {
                for (int j = 0; j <= inv.getHeight() - this.recipeHeight; ++j)
                {
                    if (this.checkMatch(inv, i, j, true))
                    {
                        return true;
                    }
    
                    if (this.checkMatch(inv, i, j, false))
                    {
                        return true;
                    }
                }
            }
    
            return false;
        }
    
        /**
         * Checks if the region of a crafting inventory is match for the recipe.
         */
        private boolean checkMatch(InventoryCrafting p_77573_1_, int p_77573_2_, int p_77573_3_, boolean p_77573_4_)
        {
            for (int i = 0; i < p_77573_1_.getWidth(); ++i)
            {
                for (int j = 0; j < p_77573_1_.getHeight(); ++j)
                {
                    int k = i - p_77573_2_;
                    int l = j - p_77573_3_;
                    Ingredient ingredient = Ingredient.EMPTY;
    
                    if (k >= 0 && l >= 0 && k < this.recipeWidth && l < this.recipeHeight)
                    {
                        if (p_77573_4_)
                        {
                            ingredient = this.recipeItems.get(this.recipeWidth - k - 1 + l * this.recipeWidth);
                        }
                        else
                        {
                            ingredient = this.recipeItems.get(k + l * this.recipeWidth);
                        }
                    }
    
                    if (!ingredient.apply(p_77573_1_.getStackInRowAndColumn(i, j)))
                    {
                        return false;
                    }
                }
            }
    
            return true;
        }
    
        /**
         * Returns an Item that is the result of this recipe
         */
        public ItemStack getCraftingResult(InventoryCrafting inv)
        {
            return this.getRecipeOutput().copy();
        }
    
        public int getWidth()
        {
            return this.recipeWidth;
        }
    
        public int getHeight()
        {
            return this.recipeHeight;
        }
    
        public static BasicArmorTableShapedRecipe deserialize(JsonObject p_193362_0_)
        {
            String s = JsonUtils.getString(p_193362_0_, "group", "");
            Map<String, Ingredient> map = deserializeKey(JsonUtils.getJsonObject(p_193362_0_, "key"));
            String[] astring = shrink(patternFromJson(JsonUtils.getJsonArray(p_193362_0_, "pattern")));
            int i = astring[0].length();
            int j = astring.length;
            NonNullList<Ingredient> nonnulllist = deserializeIngredients(astring, map, i, j);
            ItemStack itemstack = deserializeItem(JsonUtils.getJsonObject(p_193362_0_, "result"), true);
            return new BasicArmorTableShapedRecipe(s, i, j, nonnulllist, itemstack);
        }
    
        private static NonNullList<Ingredient> deserializeIngredients(String[] p_192402_0_, Map<String, Ingredient> p_192402_1_, int p_192402_2_, int p_192402_3_)
        {
            NonNullList<Ingredient> nonnulllist = NonNullList.<Ingredient>withSize(p_192402_2_ * p_192402_3_, Ingredient.EMPTY);
            Set<String> set = Sets.newHashSet(p_192402_1_.keySet());
            set.remove(" ");
    
            for (int i = 0; i < p_192402_0_.length; ++i)
            {
                for (int j = 0; j < p_192402_0_[i].length(); ++j)
                {
                    String s = p_192402_0_[i].substring(j, j + 1);
                    Ingredient ingredient = p_192402_1_.get(s);
    
                    if (ingredient == null)
                    {
                        throw new JsonSyntaxException("Pattern references symbol '" + s + "' but it's not defined in the key");
                    }
    
                    set.remove(s);
                    nonnulllist.set(j + p_192402_2_ * i, ingredient);
                }
            }
    
            if (!set.isEmpty())
            {
                throw new JsonSyntaxException("Key defines symbols that aren't used in pattern: " + set);
            }
            else
            {
                return nonnulllist;
            }
        }
    
        @VisibleForTesting
        static String[] shrink(String... p_194134_0_)
        {
            int i = Integer.MAX_VALUE;
            int j = 0;
            int k = 0;
            int l = 0;
    
            for (int i1 = 0; i1 < p_194134_0_.length; ++i1)
            {
                String s = p_194134_0_[i1];
                i = Math.min(i, firstNonSpace(s));
                int j1 = lastNonSpace(s);
                j = Math.max(j, j1);
    
                if (j1 < 0)
                {
                    if (k == i1)
                    {
                        ++k;
                    }
    
                    ++l;
                }
                else
                {
                    l = 0;
                }
            }
    
            if (p_194134_0_.length == l)
            {
                return new String[0];
            }
            else
            {
                String[] astring = new String[p_194134_0_.length - l - k];
    
                for (int k1 = 0; k1 < astring.length; ++k1)
                {
                    astring[k1] = p_194134_0_[k1 + k].substring(i, j + 1);
                }
    
                return astring;
            }
        }
    
        private static int firstNonSpace(String str)
        {
            int i;
    
            for (i = 0; i < str.length() && str.charAt(i) == ' '; ++i)
            {
                ;
            }
    
            return i;
        }
    
        private static int lastNonSpace(String str)
        {
            int i;
    
            for (i = str.length() - 1; i >= 0 && str.charAt(i) == ' '; --i)
            {
                ;
            }
    
            return i;
        }
    
        private static String[] patternFromJson(JsonArray p_192407_0_)
        {
            String[] astring = new String[p_192407_0_.size()];
    
            if (astring.length > 5)
            {
                throw new JsonSyntaxException("Invalid pattern: too many rows, 5 is maximum");
            }
            else if (astring.length == 0)
            {
                throw new JsonSyntaxException("Invalid pattern: empty pattern not allowed");
            }
            else
            {
                for (int i = 0; i < astring.length; ++i)
                {
                    String s = JsonUtils.getString(p_192407_0_.get(i), "pattern[" + i + "]");
    
                    if (s.length() > 5)
                    {
                        throw new JsonSyntaxException("Invalid pattern: too many columns, 5 is maximum");
                    }
    
                    if (i > 0 && astring[0].length() != s.length())
                    {
                        throw new JsonSyntaxException("Invalid pattern: each row must be the same width");
                    }
    
                    astring[i] = s;
                }
    
                return astring;
            }
        }
    
        private static Map<String, Ingredient> deserializeKey(JsonObject p_192408_0_)
        {
            Map<String, Ingredient> map = Maps.<String, Ingredient>newHashMap();
    
            for (Entry<String, JsonElement> entry : p_192408_0_.entrySet())
            {
                if (((String)entry.getKey()).length() != 1)
                {
                    throw new JsonSyntaxException("Invalid key entry: '" + (String)entry.getKey() + "' is an invalid symbol (must be 1 character only).");
                }
    
                if (" ".equals(entry.getKey()))
                {
                    throw new JsonSyntaxException("Invalid key entry: ' ' is a reserved symbol.");
                }
    
                map.put(entry.getKey(), deserializeIngredient(entry.getValue()));
            }
    
            map.put(" ", Ingredient.EMPTY);
            return map;
        }
    
        public static Ingredient deserializeIngredient(@Nullable JsonElement p_193361_0_)
        {
            if (p_193361_0_ != null && !p_193361_0_.isJsonNull())
            {
                if (p_193361_0_.isJsonObject())
                {
                    return Ingredient.fromStacks(deserializeItem(p_193361_0_.getAsJsonObject(), false));
                }
                else if (!p_193361_0_.isJsonArray())
                {
                    throw new JsonSyntaxException("Expected item to be object or array of objects");
                }
                else
                {
                    JsonArray jsonarray = p_193361_0_.getAsJsonArray();
    
                    if (jsonarray.size() == 0)
                    {
                        throw new JsonSyntaxException("Item array cannot be empty, at least one item must be defined");
                    }
                    else
                    {
                        ItemStack[] aitemstack = new ItemStack[jsonarray.size()];
    
                        for (int i = 0; i < jsonarray.size(); ++i)
                        {
                            aitemstack[i] = deserializeItem(JsonUtils.getJsonObject(jsonarray.get(i), "item"), false);
                        }
    
                        return Ingredient.fromStacks(aitemstack);
                    }
                }
            }
            else
            {
                throw new JsonSyntaxException("Item cannot be null");
            }
        }
    
        public static ItemStack deserializeItem(JsonObject p_192405_0_, boolean useCount)
        {
            String s = JsonUtils.getString(p_192405_0_, "item");
            Item item = Item.REGISTRY.getObject(new ResourceLocation(s));
    
            if (item == null)
            {
                throw new JsonSyntaxException("Unknown item '" + s + "'");
            }
            else if (item.getHasSubtypes() && !p_192405_0_.has("data"))
            {
                throw new JsonParseException("Missing data for item '" + s + "'");
            }
            else
            {
                int i = JsonUtils.getInt(p_192405_0_, "data", 0);
                int j = useCount ? JsonUtils.getInt(p_192405_0_, "count", 1) : 1;
                return new ItemStack(item, j, i);
            }
        }
    
        //================================================ FORGE START ================================================
        @Override
        public int getRecipeWidth()
        {
            return this.getWidth();
        }
        @Override
        public int getRecipeHeight()
        {
            return this.getHeight();
        }
    }
    public class ContainerBasicArmorTable extends Container {
    	
    	public InventoryCrafting craftMatrix;
    	public BasicArmorTableCraftResult craftResult;
    	private World worldObj;
    	private final BlockPos pos;
        private final EntityPlayer player;
    	
    	public ContainerBasicArmorTable(InventoryPlayer invPlayer, World world, BlockPos posIn) {
    		craftMatrix = new InventoryCrafting(this, 5, 5);
    		craftResult = new BasicArmorTableCraftResult();
    		worldObj = world;
    		pos = posIn;
    		player = invPlayer.player;
    		
    		this.addSlotToContainer(new SlotCrafting(invPlayer.player, craftMatrix, craftResult, 0, 131, 36));
    		
    		for (int i = 0; i < 5; i++) {
    			for (int k = 0; k < 5; k++) {
    				this.addSlotToContainer(new Slot(craftMatrix, k + i * 5, 4 + k * 18, 3 + i * 18));
    			}
    		}
    		
    		for (int i = 0; i < 3; i++) {
    			for (int k = 0; k < 9; k++) {
    				this.addSlotToContainer(new Slot(invPlayer, k + i * 9 + 9, 8 + k * 18, 94 + i * 18));
    			}
    		}
    		
    		for (int i = 0; i < 9; i++) {
    			this.addSlotToContainer(new Slot(invPlayer, i, 8 + i * 18, 148));
    		}
    		
    		onCraftMatrixChanged(craftMatrix);
    	}
    	
    	public ItemStack transferStackInSlot(EntityPlayer playerIn, int index)
        {
            ItemStack itemstack = ItemStack.EMPTY;
            Slot slot = this.inventorySlots.get(index);
    
            if (slot != null && slot.getHasStack())
            {
                ItemStack itemstack1 = slot.getStack();
                itemstack = itemstack1.copy();
    
                if (index == 0)
                {
                    itemstack1.getItem().onCreated(itemstack1, this.worldObj, playerIn);
    
                    if (!this.mergeItemStack(itemstack1, 10, 46, true))
                    {
                        return ItemStack.EMPTY;
                    }
    
                    slot.onSlotChange(itemstack1, itemstack);
                }
                else if (index >= 10 && index < 37)
                {
                    if (!this.mergeItemStack(itemstack1, 37, 46, false))
                    {
                        return ItemStack.EMPTY;
                    }
                }
                else if (index >= 37 && index < 46)
                {
                    if (!this.mergeItemStack(itemstack1, 10, 37, false))
                    {
                        return ItemStack.EMPTY;
                    }
                }
                else if (!this.mergeItemStack(itemstack1, 10, 46, false))
                {
                    return ItemStack.EMPTY;
                }
    
                if (itemstack1.isEmpty())
                {
                    slot.putStack(ItemStack.EMPTY);
                }
                else
                {
                    slot.onSlotChanged();
                }
    
                if (itemstack1.getCount() == itemstack.getCount())
                {
                    return ItemStack.EMPTY;
                }
    
                ItemStack itemstack2 = slot.onTake(playerIn, itemstack1);
    
                if (index == 0)
                {
                    playerIn.dropItem(itemstack2, false);
                }
            }
    
            return itemstack;
        }
    	
    	public void slotChangedCraftingGrid(World worldObj2, EntityPlayer player2, InventoryCrafting craftMatrix2, InventoryCraftResult craftResult2) {
    
    		if (!worldObj2.isRemote)
            {
                EntityPlayerMP entityplayermp = (EntityPlayerMP)player2;
                ItemStack itemstack = ItemStack.EMPTY;
                IRecipe irecipe = BasicArmorTableCraftingManager.findMatchingRecipe(craftMatrix2, worldObj2);
    
                if (irecipe != null && (irecipe.isDynamic() || !worldObj2.getGameRules().getBoolean("doLimitedCrafting")))
                {
                    craftResult2.setRecipeUsed(irecipe);
                    itemstack = irecipe.getCraftingResult(craftMatrix2);
                }
    
                craftResult2.setInventorySlotContents(0, itemstack);
                entityplayermp.connection.sendPacket(new SPacketSetSlot(this.windowId, 0, itemstack));
            }
    	}
    	
    	 @Override
    	    public void onCraftMatrixChanged(IInventory matrix) {
    		 //craftResult.setInventorySlotContents(0, BasicArmorTableCraftingManager.getBasicArmorTableCraftingResult(craftMatrix, worldObj));
    		 this.slotChangedCraftingGrid(this.worldObj, this.player, this.craftMatrix, this.craftResult);
    	    }
    
    	public boolean canInteractWith(EntityPlayer playerIn)
        {
            if (this.worldObj.getBlockState(pos).getBlock() != BlockInit.BASIC_ARMOR_TABLE)
            {
                return false;
            }
            else
            {
                return playerIn.getDistanceSq((double)this.pos.getX() + 0.5D, (double)this.pos.getY() + 0.5D, (double)this.pos.getZ() + 0.5D) <= 64.0D;
            }
        }
    
    	public void onContainerClosed(EntityPlayer playerIn)
        {
            super.onContainerClosed(playerIn);
    
            if (!this.worldObj.isRemote)
            {
                this.clearContainer(playerIn, this.worldObj, this.craftMatrix);
            }
        }
    }
    public class GuiBasicArmorTable extends GuiContainer {
    	
    	public static final ResourceLocation bground = new ResourceLocation(Reference.MODID + ":" + "textures/gui/gui_basic_armor_table.png");
    
    	public GuiBasicArmorTable(InventoryPlayer invPlayer, World worl, BlockPos pos) {
    		super(new ContainerBasicArmorTable(invPlayer, worl, pos));
    		
    		this.xSize = 176;
    		this.ySize = 166;
    	}
    
    	public void onGuiClosed() {
    		super.onGuiClosed();
    	}
    	
    	protected void drawGuiContainerForegroundLayer(int i, int j) {
    		this.fontRenderer.drawString("Basic Armor Table", this.xSize / 2 - this.fontRenderer.getStringWidth("Basic Armor Table") / 2, 6, 8777777);
    		this.fontRenderer.drawString(I18n.format("container.inventory", new Object[0]), 8, this.ySize - 96 + 2, 8777777);
    	}
    	
    	@Override
    	protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
    		
    		GlStateManager.color(1F, 1F, 1F, 1F);
    		
    		mc.getMinecraft().getTextureManager().bindTexture(bground);
    		drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize);
    	}
    }
    public abstract class Recipe5x5Base extends IForgeRegistryEntry.Impl<IMERecipe> implements IMERecipe {
    
        @Override
        public boolean canFit(int width, int height) {
            return width >= 5 && height >= 5;
        }
    }
    public interface IMERecipe extends IForgeRegistryEntry<IMERecipe> {
    
        boolean matches(InventoryCrafting inventory, World world);
    
        default ItemStack getCraftingResult(InventoryCrafting inventory) {
            return getRecipeOutput();
        }
    
        boolean canFit(int width, int height);
    
        ItemStack getRecipeOutput();
    
        default NonNullList<ItemStack> getRemainingItems(InventoryCrafting inv) {
            return ForgeHooks.defaultRecipeGetRemainingItems(inv);
        }
    
        default NonNullList<Ingredient> getIngredients() {
            return NonNullList.create();
        }
    
        /**
         * If this recipe is shaped.
         * Used for JEI ingredient layout.
         * Used for CraftTweaker recipe removal.
         *
         * @return true or false, default false.
         */
        default boolean isShapedRecipe() {
            return true;
        }
    
        /**
         * Gets the width for this recipe.
         * Only supported on shaped recipes.
         * Throws an UnsupportedOperationException if isShapedRecipe returns false.
         *
         * @return the width.
         */
        default int getWidth() {
            return 5;
        }
    
        /**
         * Gets the height for this recipe.
         * Only supported on shaped recipes.
         * Throws an UnsupportedOperationException if isShapedRecipe returns false.
         *
         * @return the height.
         */
        default int getHeight() {
            return 5;
        }
    }
    {
        "type": "me:basic_armor_table_shaped",
        "result":
        {
            "item": "minecraft:due",
            "data": 4,
            "count": 2
        },    
        "pattern":
        [
            "     ",
            "     ",
            "ABBBA",
            "     ",
            "     "
        ],
        
        "key":
        {
            "A":
            {
                "type": "minecraft:due",
                "data": 0
            },
            
            "B":
            {
                "type": "minecraft:dye",
                "data": 12
            }
        }          
    }

     

×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.