Crafting Recipe help
#1
I'm an experienced LUA programmer, and I'm an experienced Minecraft player, I've never written a plugin for any kind of minecraft server. I've looked over the documentation and its pretty clear on some things, but I can't seem to find how to add new recipies in a plugin. Can anyone point me in the right direction?

What I've seen so far is to create the basic plugin code, and then create a cCraftingRecipe, but where do I put the cCraftingRecipe?

If someone has done this before and can post an example that would be extremely helpful.

I also need to know how to create new blocks and items. My goal is to create some kind of technology plugin similar to Applied Energistics and/or Mekanism.
Reply
Thanks given by:
#2
I've tried to use:
function Initialize(Plugin)
     	cPluginManager.AddHook(cPluginManager.HOOK_PRE_CRAFTING, OnPreCraft)

end

function OnPreCraft(Player, Grid, Recipe)
	local foundNil = false
	LOG("OPC->Reading Grid for first time")
	for x=1,3,1 do
		for y=1,3,1 do
			if Grid:GetItem(x,y) == nil then
				foundNil = true
			end
		end
	end
	LOG("OPC->Done reading Grid for first time")
end

Just that code alone produces this error:
Attempted to get an invalid item from a crafting grid: (3, 3), grid dimensions: (3, 3).

It gives it once for each location on the grid except for 2,2 where I place the first item

What am I doing wrong here?
Reply
Thanks given by:
#3
Apparently the index starts at 0 despite the fact that lua indexes start at 1. I'm now getting an error:
Lua engine: attempting to push a plain pointer, pushing nil instead. This indicates an unimplemented part of MCS bindings
Stack trace:
Stack trace end

Looks like you can create a custom crafting recipe by filling the recipe with created items

Recipe:SetIngredient(0,0,E_ITEM_Iron, 1, 0)

Then after setting all of the ingredient slots you set the result:

Recipe:SetResult(88, 1, 0)

Then you use a for loop to compare the Grid items to the recipe items:
		local count = 0
		for x=0,2,1 do
			for y=0,2,1 do
				if Grid:GetItem(x,y):IsSameType(Recipe:GetIngredient(x,y)) then
					count = count + 1
				end
			end
		end

Then you just return true if it matches and false if it doesn't.
Reply
Thanks given by:
#4
Sorry for the late reply. Yes, most of the API objects that contain arrays use 0-based indices, because the API is shared between C++ and Lua and is primarily C++.

Custom recipes are not implemented by "force-feeding" them to the server, but quite the opposite - the server asks each time a player changes the crafting grid, and a plugin may override the result of such crafting. So you need to use the HOOK_PRE_CRAFTING hook, and in it check the contents of the crafting grid (2nd param) against your recipe. If it matches, then modify the received Recipe object (3rd param) with your actual recipe and result. Note that you can use item counts in the recipe, and if the player uses such a recipe, the specified amount of items will be used out of the crafting grid (so you can actually make a recipe that takes 3 planks out of one slot for a single result).
Reply
Thanks given by:
#5
If you feel that the documentation is inaccurate or misleading, please do say so, we need feedback on the docs and yet no-one has ever said much. You can also make changes to the docs yourself - it is all handled by the APIDump plugin in the main server repository, just make a PullRequest on GitHub.
https://github.com/mc-server/MCServer/tr...ns/APIDump

We know that the documentation is lacking in general, but you know how it is with programmers writing docs, we are a lazy bunch, so unless someone kicks us to it, we won't do it Smile I've already tried many times to make people more aware of the need to write the docs.
Reply
Thanks given by:




Users browsing this thread: 1 Guest(s)