aboutsummaryrefslogtreecommitdiff
path: root/advtrains_luaautomation/operation_panel.lua
blob: d0dd567805b21cd336544efa6db9d4496884d316 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

local function on_punch(pos, player)
	atlatc.interrupt.add(0, pos, {type="punch", punch=true})
end


minetest.register_node("advtrains_luaautomation:oppanel", {
	drawtype = "normal",
	tiles={"atlatc_oppanel.png"},
	description = "LuaAutomation operation panel",
	groups = {
		cracky = 1,
		save_in_nodedb=1,
	},
	after_place_node = atlatc.active.after_place_node,
	after_dig_node = atlatc.active.after_dig_node,
	on_receive_fields = atlatc.active.on_receive_fields,
	on_punch = on_punch,
	luaautomation = {
		fire_event=atlatc.active.run_in_env
	},
	digiline = {
		receptor = {},
		effector = {
			action = atlatc.active.on_digiline_receive
		},
	},
})
='n140' href='#n140'>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
/*
Minetest
Copyright (C) 2010-2020 Minetest core development team

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 "serverinventorymgr.h"
#include "map.h"
#include "nodemetadata.h"
#include "player_sao.h"
#include "remoteplayer.h"
#include "server.h"
#include "serverenvironment.h"

ServerInventoryManager::ServerInventoryManager() : InventoryManager()
{
}

ServerInventoryManager::~ServerInventoryManager()
{
	// Delete detached inventories
	for (auto &detached_inventory : m_detached_inventories) {
		delete detached_inventory.second.inventory;
	}
}

Inventory *ServerInventoryManager::getInventory(const InventoryLocation &loc)
{
	switch (loc.type) {
	case InventoryLocation::UNDEFINED:
	case InventoryLocation::CURRENT_PLAYER:
		break;
	case InventoryLocation::PLAYER: {
		RemotePlayer *player = m_env->getPlayer(loc.name.c_str());
		if (!player)
			return NULL;
		PlayerSAO *playersao = player->getPlayerSAO();
		if (!playersao)
			return NULL;
		return playersao->getInventory();
	} break;
	case InventoryLocation::NODEMETA: {
		NodeMetadata *meta = m_env->getMap().getNodeMetadata(loc.p);
		if (!meta)
			return NULL;
		return meta->getInventory();
	} break;
	case InventoryLocation::DETACHED: {
		auto it = m_detached_inventories.find(loc.name);
		if (it == m_detached_inventories.end())
			return nullptr;
		return it->second.inventory;
	} break;
	default:
		sanity_check(false); // abort
		break;
	}
	return NULL;
}

void ServerInventoryManager::setInventoryModified(const InventoryLocation &loc)
{
	switch (loc.type) {
	case InventoryLocation::UNDEFINED:
		break;
	case InventoryLocation::PLAYER: {

		RemotePlayer *player = m_env->getPlayer(loc.name.c_str());

		if (!player)
			return;

		player->setModified(true);
		player->inventory.setModified(true);
		// Updates are sent in ServerEnvironment::step()
	} break;
	case InventoryLocation::NODEMETA: {
		MapEditEvent event;
		event.type = MEET_BLOCK_NODE_METADATA_CHANGED;