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

Creating custom crafting table 1.12.2


Recommended Posts

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
        }
    }          
}

 

Link to post
Share on other sites
Guest
This topic is now closed to further replies.


  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • Hello There! The finale is FINALLY here of this really wholesome video series! In this one we switch some things up and we surprise my one friend with a MINECRAFT ACCOUNT! Then we get back to the usual stuff where we surprise the ones who have Java Minecraft with their statues and everything! Sadly this little series was cut short because of the server shutting down but it was fun nonetheless! If you are looking for a wholesome/good vibe video series this is the one for you! I hope you all enjoy this video and if you did don't forget to like and sub for more!  
    • My forge 1.12.2 shows up in launcher and the tap shows up when I launches at the bottom of my screen. The game itself doesn't pop up on my screen. When launching forge again, it will just say that a game is already there. Can someone please help me solve this problem? I have already tried searching for multiple instances of minecraft using task manager, finding nothing. 
    • After looking through a ton of functions, I found the issue was that my entity was extending MonsterEntity, which extends MobEntity, which creates a GroundPathNavigator, which has a rules for canUpdatePath that include "this.mob.isOnGround()". My entity is a flying entity. Whoops. Solution was to simply override the createNavigation function, where I simply "return new FlyingPathNavigator(this, world);". Everything works fine now.
    • do you already have a custom recipe implemented? if not, you'll a class that'l hold the recipe and check for matches, the recipe inventory and the recipe serializer   then it's up to you to write the logic in your container. you can use of the world's recipe manager to see if a recipe inventory matches any recipe
    • I'm trying to write an AI Goal for an entity to move towards its target on each tick (with quite a few restrictions on when, which is why I need a new goal). It seemed to be working when I also added a WaterAvoidingRandomWalkingGoal, but I don't want the entity to move around randomly anymore, so I removed that. My code overrides the canUse function to determine whether or not it should start moving towards the target, and that ends with creating a path to the target, which always returns NULL, so nothing happens. Here's the relevant functions: public FloatingEyesGoal(EntityFloatingEyes e, double speed) { this.entity = e; this.random = e.getRandom(); this.speed = speed; this.setFlags(EnumSet.of(Flag.LOOK, Flag.MOVE, Flag.TARGET)); this.entity.getNavigation().setCanFloat(true); } @Override public boolean canUse() { LivingEntity target = this.entity.getTarget(); if (target == null || !target.isAlive() || !isFacingTargetBack()) return false; setTargetPos(target); this.path = this.entity.getNavigation().createPath(target, 0); // Logging this.path == null prints "true", and this.entity.getNavigation() == null prints "false" return this.path != null || isInRange(target); } @Override public boolean canContinueToUse() { LivingEntity target = this.entity.getTarget(); if (target == null || !target.isAlive() || !isFacingTargetBack()) return false; return !this.entity.getNavigation().isDone(); } @Override public void start() { this.entity.getNavigation().moveTo(this.path, this.speed); this.entity.setAggressive(true); this.ticksToMove = 0; } @Override public void stop() { LivingEntity target = this.entity.getTarget(); if (!EntityPredicates.NO_CREATIVE_OR_SPECTATOR.test(target)) { this.entity.setTarget(null); } this.entity.setAggressive(false); this.entity.getNavigation().stop(); this.targetPosX = 0.0D; this.targetPosY = 0.0D; this.targetPosZ = 0.0D; } @Override public void tick() { // Look at target LivingEntity target = this.entity.getTarget(); this.entity.getLookControl().setLookAt(target, 32.0F, 32.0F); setTargetPos(target); final double distance = this.entity.distanceToSqr(this.targetPosX, this.targetPosY, this.targetPosZ); this.ticksToMove--; LilSpooks.LOGGER.info(this.ticksToMove); if (this.ticksToMove <= 0 && this.entity.getSensing().canSee(target) && target.distanceToSqr(this.targetPosX, this.targetPosY, this.targetPosZ) >= 1.0D) { this.ticksToMove = 5 + this.random.nextInt(8); // Add extra time if eyes can't move to hopefully wait enough to try again (1 second). this.path = this.entity.getNavigation().createPath(new BlockPos(this.targetPosX, this.targetPosY, this.targetPosZ), 0); // Logging this.path == null returns "true" here as well if (!this.entity.getNavigation().moveTo(this.path, this.speed)) { this.ticksToMove += 20; } } this.attackTick = Math.max(this.attackTick - 1, 0); this.attemptAttack(target, distance); } protected void setTargetPos(LivingEntity target) { this.targetPosX = target.getX(); this.targetPosY = target.getBoundingBox().minY; this.targetPosZ = target.getZ(); } I have tried multiple ways of invoking createPath, I tried setting the moveControl of the entity with the goal to a new FlyingMovementController, and I've looked at how the createPath function works (though I can't figure out how to do a live debugging session, so I couldn't set a breakpoint at that code which would tell me exactly what causes it to be null). I tried my best to work through this for a few hours but I can't seem to figure it out. Any help is appreciated.
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

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