aboutsummaryrefslogtreecommitdiff
path: root/games/minimal/mods/default/textures/default_nc_back.png
blob: e479ace8306c8f856da9f8f99f40924ef67a8a9a (plain)
ofshex dumpascii
0000 89 50 4e 47 0d 0a 1a 0a 00 00 00 0d 49 48 44 52 00 00 00 10 00 00 00 10 08 03 00 00 00 28 2d 0f .PNG........IHDR.............(-.
0020 53 00 00 00 1e 50 4c 54 45 0a 0a 0a 32 0e 5e 43 43 43 80 80 80 88 47 88 c2 62 c2 c5 64 c5 ff 4d S....PLTE...2.^CCC....G..b..d..M
0040 a4 ff 80 ff ff bf 80 cf 9f ba 90 00 00 00 57 49 44 41 54 78 da 65 cf 51 0e c0 20 08 03 d0 4e 74 ..............WIDATx.e.Q......Nt
0060 c0 fd 2f 3c 11 59 5d d6 0f 13 5e 8a 51 5c 38 13 a3 7f 82 00 7b b3 20 e6 01 a4 24 a8 41 da 14 2d ../<.Y]...^.Q\8.....{.....$.A..-
0080 b0 09 b2 2a 84 16 15 82 8e ac 68 01 77 08 ed 04 0d c1 cd 15 a6 00 e8 66 1d d8 e0 79 41 3c ce 37 ...*......h.w..........f...yA<.7
00a0 88 f0 fc 7d ff 01 cb 2a 04 f0 a5 bd d4 20 00 00 00 00 49 45 4e 44 ae 42 60 82 ...}...*..........IEND.B`.
d='n70' href='#n70'>70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275
/*
Minetest
Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#include "cpp_api/s_item.h"
#include "cpp_api/s_internal.h"
#include "common/c_converter.h"
#include "common/c_content.h"
#include "lua_api/l_item.h"
#include "lua_api/l_inventory.h"
#include "server.h"
#include "log.h"
#include "util/pointedthing.h"
#include "inventory.h"
#include "inventorymanager.h"

#define WRAP_LUAERROR(e, detail) \
	LuaError(std::string(__FUNCTION__) + ": " + (e).what() + ". " detail)

bool ScriptApiItem::item_OnDrop(ItemStack &item,
		ServerActiveObject *dropper, v3f pos)
{
	SCRIPTAPI_PRECHECKHEADER

	int error_handler = PUSH_ERROR_HANDLER(L);

	// Push callback function on stack
	if (!getItemCallback(item.name.c_str(), "on_drop"))
		return false;

	// Call function
	LuaItemStack::create(L, item);
	objectrefGetOrCreate(L, dropper);
	pushFloatPos(L, pos);
	PCALL_RES(lua_pcall(L, 3, 1, error_handler));
	if (!lua_isnil(L, -1)) {
		try {
			item = read_item(L, -1, getServer()->idef());
		} catch (LuaError &e) {
			throw WRAP_LUAERROR(e, "item=" + item.name);
		}
	}
	lua_pop(L, 2);  // Pop item and error handler
	return true;
}

bool ScriptApiItem::item_OnPlace(Optional<ItemStack> &ret_item,
		ServerActiveObject *placer, const PointedThing &pointed)
{
	SCRIPTAPI_PRECHECKHEADER

	int error_handler = PUSH_ERROR_HANDLER(L);

	const ItemStack &item = *ret_item;
	// Push callback function on stack
	if (!getItemCallback(item.name.c_str(), "on_place"))
		return false;

	// Call function
	LuaItemStack::create(L, item);

	if (!placer)
		lua_pushnil(L);
	else
		objectrefGetOrCreate(L, placer);

	pushPointedThing(pointed);
	PCALL_RES(lua_pcall(L, 3, 1, error_handler));
	if (!lua_isnil(L, -1)) {
		try {
			ret_item = read_item(L, -1, getServer()->idef());
		} catch (LuaError &e) {
			throw WRAP_LUAERROR(e, "item=" + item.name);
		}
	} else {
		ret_item = nullopt;
	}
	lua_pop(L, 2);  // Pop item and error handler
	return true;
}

bool ScriptApiItem::item_OnUse(Optional<ItemStack> &ret_item,
		ServerActiveObject *user, const PointedThing &pointed)
{
	SCRIPTAPI_PRECHECKHEADER

	int error_handler = PUSH_ERROR_HANDLER(L);

	const ItemStack &item = *ret_item;
	// Push callback function on stack
	if (!getItemCallback(item.name.c_str(), "on_use"))
		return false;

	// Call function
	LuaItemStack::create(L, item);
	objectrefGetOrCreate(L, user);
	pushPointedThing(pointed);
	PCALL_RES(lua_pcall(L, 3, 1, error_handler));
	if(!lua_isnil(L, -1)) {
		try {
			ret_item = read_item(L, -1, getServer()->idef());
		} catch (LuaError &e) {
			throw WRAP_LUAERROR(e, "item=" + item.name);
		}
	} else {
		ret_item = nullopt;
	}
	lua_pop(L, 2);  // Pop item and error handler
	return true;
}

bool ScriptApiItem::item_OnSecondaryUse(Optional<ItemStack> &ret_item,
		ServerActiveObject *user, const PointedThing &pointed)
{
	SCRIPTAPI_PRECHECKHEADER

	int error_handler = PUSH_ERROR_HANDLER(L);

	const ItemStack &item = *ret_item;
	if (!getItemCallback(item.name.c_str(), "on_secondary_use"))
		return false;

	LuaItemStack::create(L, item);
	objectrefGetOrCreate(L, user);
	pushPointedThing(pointed);
	PCALL_RES(lua_pcall(L, 3, 1, error_handler));
	if (!lua_isnil(L, -1)) {
		try {
			ret_item = read_item(L, -1, getServer()->idef());
		} catch (LuaError &e) {
			throw WRAP_LUAERROR(e, "item=" + item.name);
		}
	} else {
		ret_item = nullopt;
	}
	lua_pop(L, 2);  // Pop item and error handler
	return true;
}

bool ScriptApiItem::item_OnCraft(ItemStack &item, ServerActiveObject *user,
		const InventoryList *old_craft_grid, const InventoryLocation &craft_inv)
{
	SCRIPTAPI_PRECHECKHEADER

	int error_handler = PUSH_ERROR_HANDLER(L);

	lua_getglobal(L, "core");
	lua_getfield(L, -1, "on_craft");
	LuaItemStack::create(L, item);
	objectrefGetOrCreate(L, user);

	// Push inventory list
	std::vector<ItemStack> items;
	for (u32 i = 0; i < old_craft_grid->getSize(); i++) {
		items.push_back(old_craft_grid->getItem(i));
	}
	push_items(L, items);

	InvRef::create(L, craft_inv);
	PCALL_RES(lua_pcall(L, 4, 1, error_handler));
	if (!lua_isnil(L, -1)) {
		try {
			item = read_item(L, -1, getServer()->idef());
		} catch (LuaError &e) {
			throw WRAP_LUAERROR(e, "item=" + item.name);
		}
	}
	lua_pop(L, 2);  // Pop item and error handler
	return true;
}

bool ScriptApiItem::item_CraftPredict(ItemStack &item, ServerActiveObject *user,
		const InventoryList *old_craft_grid, const InventoryLocation &craft_inv)
{
	SCRIPTAPI_PRECHECKHEADER