Added the OnHopperPullingItem and OnHopperPushingItem hooks.
Requested in FS 412, slightly modified the params.
This commit is contained in:
parent
d97b4463c6
commit
dd60f55bcc
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
** Lua binding: AllToLua
|
** Lua binding: AllToLua
|
||||||
** Generated automatically by tolua++-1.0.92 on 08/09/13 14:50:49.
|
** Generated automatically by tolua++-1.0.92 on 08/11/13 14:53:45.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __cplusplus
|
#ifndef __cplusplus
|
||||||
@ -16909,7 +16909,8 @@ static int tolua_AllToLua_cItemGrid_HowManyCanFit00(lua_State* tolua_S)
|
|||||||
if (
|
if (
|
||||||
!tolua_isusertype(tolua_S,1,"cItemGrid",0,&tolua_err) ||
|
!tolua_isusertype(tolua_S,1,"cItemGrid",0,&tolua_err) ||
|
||||||
(tolua_isvaluenil(tolua_S,2,&tolua_err) || !tolua_isusertype(tolua_S,2,"const cItem",0,&tolua_err)) ||
|
(tolua_isvaluenil(tolua_S,2,&tolua_err) || !tolua_isusertype(tolua_S,2,"const cItem",0,&tolua_err)) ||
|
||||||
!tolua_isnoobj(tolua_S,3,&tolua_err)
|
!tolua_isboolean(tolua_S,3,1,&tolua_err) ||
|
||||||
|
!tolua_isnoobj(tolua_S,4,&tolua_err)
|
||||||
)
|
)
|
||||||
goto tolua_lerror;
|
goto tolua_lerror;
|
||||||
else
|
else
|
||||||
@ -16917,11 +16918,12 @@ static int tolua_AllToLua_cItemGrid_HowManyCanFit00(lua_State* tolua_S)
|
|||||||
{
|
{
|
||||||
cItemGrid* self = (cItemGrid*) tolua_tousertype(tolua_S,1,0);
|
cItemGrid* self = (cItemGrid*) tolua_tousertype(tolua_S,1,0);
|
||||||
const cItem* a_ItemStack = ((const cItem*) tolua_tousertype(tolua_S,2,0));
|
const cItem* a_ItemStack = ((const cItem*) tolua_tousertype(tolua_S,2,0));
|
||||||
|
bool a_AllowNewStacks = ((bool) tolua_toboolean(tolua_S,3,true));
|
||||||
#ifndef TOLUA_RELEASE
|
#ifndef TOLUA_RELEASE
|
||||||
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'HowManyCanFit'", NULL);
|
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'HowManyCanFit'", NULL);
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
int tolua_ret = (int) self->HowManyCanFit(*a_ItemStack);
|
int tolua_ret = (int) self->HowManyCanFit(*a_ItemStack,a_AllowNewStacks);
|
||||||
tolua_pushnumber(tolua_S,(lua_Number)tolua_ret);
|
tolua_pushnumber(tolua_S,(lua_Number)tolua_ret);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -29331,8 +29333,8 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S)
|
|||||||
tolua_constant(tolua_S,"esBed",esBed);
|
tolua_constant(tolua_S,"esBed",esBed);
|
||||||
tolua_constant(tolua_S,"esEnderCrystal",esEnderCrystal);
|
tolua_constant(tolua_S,"esEnderCrystal",esEnderCrystal);
|
||||||
tolua_constant(tolua_S,"esGhastFireball",esGhastFireball);
|
tolua_constant(tolua_S,"esGhastFireball",esGhastFireball);
|
||||||
tolua_constant(tolua_S,"esWitherSkullBlue",esWitherSkullBlue);
|
|
||||||
tolua_constant(tolua_S,"esWitherSkullBlack",esWitherSkullBlack);
|
tolua_constant(tolua_S,"esWitherSkullBlack",esWitherSkullBlack);
|
||||||
|
tolua_constant(tolua_S,"esWitherSkullBlue",esWitherSkullBlue);
|
||||||
tolua_constant(tolua_S,"esWitherBirth",esWitherBirth);
|
tolua_constant(tolua_S,"esWitherBirth",esWitherBirth);
|
||||||
tolua_constant(tolua_S,"esPlugin",esPlugin);
|
tolua_constant(tolua_S,"esPlugin",esPlugin);
|
||||||
tolua_function(tolua_S,"BlockStringToType",tolua_AllToLua_BlockStringToType00);
|
tolua_function(tolua_S,"BlockStringToType",tolua_AllToLua_BlockStringToType00);
|
||||||
@ -29718,8 +29720,11 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S)
|
|||||||
tolua_constant(tolua_S,"HOOK_EXPLODED",cPluginManager::HOOK_EXPLODED);
|
tolua_constant(tolua_S,"HOOK_EXPLODED",cPluginManager::HOOK_EXPLODED);
|
||||||
tolua_constant(tolua_S,"HOOK_EXPLODING",cPluginManager::HOOK_EXPLODING);
|
tolua_constant(tolua_S,"HOOK_EXPLODING",cPluginManager::HOOK_EXPLODING);
|
||||||
tolua_constant(tolua_S,"HOOK_HANDSHAKE",cPluginManager::HOOK_HANDSHAKE);
|
tolua_constant(tolua_S,"HOOK_HANDSHAKE",cPluginManager::HOOK_HANDSHAKE);
|
||||||
|
tolua_constant(tolua_S,"HOOK_HOPPER_PULLING_ITEM",cPluginManager::HOOK_HOPPER_PULLING_ITEM);
|
||||||
|
tolua_constant(tolua_S,"HOOK_HOPPER_PUSHING_ITEM",cPluginManager::HOOK_HOPPER_PUSHING_ITEM);
|
||||||
tolua_constant(tolua_S,"HOOK_KILLING",cPluginManager::HOOK_KILLING);
|
tolua_constant(tolua_S,"HOOK_KILLING",cPluginManager::HOOK_KILLING);
|
||||||
tolua_constant(tolua_S,"HOOK_LOGIN",cPluginManager::HOOK_LOGIN);
|
tolua_constant(tolua_S,"HOOK_LOGIN",cPluginManager::HOOK_LOGIN);
|
||||||
|
tolua_constant(tolua_S,"HOOK_PLAYER_ANIMATION",cPluginManager::HOOK_PLAYER_ANIMATION);
|
||||||
tolua_constant(tolua_S,"HOOK_PLAYER_BREAKING_BLOCK",cPluginManager::HOOK_PLAYER_BREAKING_BLOCK);
|
tolua_constant(tolua_S,"HOOK_PLAYER_BREAKING_BLOCK",cPluginManager::HOOK_PLAYER_BREAKING_BLOCK);
|
||||||
tolua_constant(tolua_S,"HOOK_PLAYER_BROKEN_BLOCK",cPluginManager::HOOK_PLAYER_BROKEN_BLOCK);
|
tolua_constant(tolua_S,"HOOK_PLAYER_BROKEN_BLOCK",cPluginManager::HOOK_PLAYER_BROKEN_BLOCK);
|
||||||
tolua_constant(tolua_S,"HOOK_PLAYER_EATING",cPluginManager::HOOK_PLAYER_EATING);
|
tolua_constant(tolua_S,"HOOK_PLAYER_EATING",cPluginManager::HOOK_PLAYER_EATING);
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
** Lua binding: AllToLua
|
** Lua binding: AllToLua
|
||||||
** Generated automatically by tolua++-1.0.92 on 08/09/13 14:50:49.
|
** Generated automatically by tolua++-1.0.92 on 08/11/13 14:53:46.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Exported function */
|
/* Exported function */
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
#include "HopperEntity.h"
|
#include "HopperEntity.h"
|
||||||
#include "../Chunk.h"
|
#include "../Chunk.h"
|
||||||
#include "../Player.h"
|
#include "../Player.h"
|
||||||
|
#include "../PluginManager.h"
|
||||||
#include "ChestEntity.h"
|
#include "ChestEntity.h"
|
||||||
#include "DropSpenserEntity.h"
|
#include "DropSpenserEntity.h"
|
||||||
#include "FurnaceEntity.h"
|
#include "FurnaceEntity.h"
|
||||||
@ -162,12 +163,26 @@ bool cHopperEntity::MoveItemsIn(cChunk & a_Chunk, Int64 a_CurrentTick)
|
|||||||
bool res = false;
|
bool res = false;
|
||||||
switch (a_Chunk.GetBlock(m_RelX, m_PosY + 1, m_RelZ))
|
switch (a_Chunk.GetBlock(m_RelX, m_PosY + 1, m_RelZ))
|
||||||
{
|
{
|
||||||
case E_BLOCK_CHEST: res = MoveItemsFromChest(a_Chunk); break;
|
case E_BLOCK_CHEST:
|
||||||
case E_BLOCK_FURNACE: res = MoveItemsFromFurnace(a_Chunk); break;
|
{
|
||||||
|
// Chests have special handling because of double-chests
|
||||||
|
res = MoveItemsFromChest(a_Chunk);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case E_BLOCK_LIT_FURNACE:
|
||||||
|
case E_BLOCK_FURNACE:
|
||||||
|
{
|
||||||
|
// Furnaces have special handling because only the output and leftover fuel buckets shall be moved
|
||||||
|
res = MoveItemsFromFurnace(a_Chunk);
|
||||||
|
break;
|
||||||
|
}
|
||||||
case E_BLOCK_DISPENSER:
|
case E_BLOCK_DISPENSER:
|
||||||
case E_BLOCK_DROPPER: res = MoveItemsFromGrid(((cDropSpenserEntity *)a_Chunk.GetBlockEntity(m_PosX, m_PosY + 1, m_PosZ))->GetContents()); break;
|
case E_BLOCK_DROPPER:
|
||||||
case E_BLOCK_HOPPER: res = MoveItemsFromGrid(((cHopperEntity *) a_Chunk.GetBlockEntity(m_PosX, m_PosY + 1, m_PosZ))->GetContents()); break;
|
case E_BLOCK_HOPPER:
|
||||||
case E_BLOCK_LIT_FURNACE: res = MoveItemsFromFurnace(a_Chunk); break;
|
{
|
||||||
|
res = MoveItemsFromGrid(*(cBlockEntityWithItems *)a_Chunk.GetBlockEntity(m_PosX, m_PosY + 1, m_PosZ));
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the item has been moved, reset the last tick:
|
// If the item has been moved, reset the last tick:
|
||||||
@ -230,12 +245,26 @@ bool cHopperEntity::MoveItemsOut(cChunk & a_Chunk, Int64 a_CurrentTick)
|
|||||||
bool res = false;
|
bool res = false;
|
||||||
switch (DestChunk->GetBlock(rx, by, rz))
|
switch (DestChunk->GetBlock(rx, by, rz))
|
||||||
{
|
{
|
||||||
case E_BLOCK_CHEST: res = MoveItemsToChest(*DestChunk, bx, by, bz); break;
|
case E_BLOCK_CHEST:
|
||||||
case E_BLOCK_FURNACE: res = MoveItemsToFurnace(*DestChunk, bx, by, bz, Meta); break;
|
{
|
||||||
|
// Chests have special handling because of double-chests
|
||||||
|
res = MoveItemsToChest(*DestChunk, bx, by, bz);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case E_BLOCK_LIT_FURNACE:
|
||||||
|
case E_BLOCK_FURNACE:
|
||||||
|
{
|
||||||
|
// Furnaces have special handling because of the direction-to-slot relation
|
||||||
|
res = MoveItemsToFurnace(*DestChunk, bx, by, bz, Meta);
|
||||||
|
break;
|
||||||
|
}
|
||||||
case E_BLOCK_DISPENSER:
|
case E_BLOCK_DISPENSER:
|
||||||
case E_BLOCK_DROPPER: res = MoveItemsToGrid(((cDropSpenserEntity *)DestChunk->GetBlockEntity(bx, by, bz))->GetContents()); break;
|
case E_BLOCK_DROPPER:
|
||||||
case E_BLOCK_HOPPER: res = MoveItemsToGrid(((cHopperEntity *) DestChunk->GetBlockEntity(bx, by, bz))->GetContents()); break;
|
case E_BLOCK_HOPPER:
|
||||||
case E_BLOCK_LIT_FURNACE: res = MoveItemsToFurnace(*DestChunk, bx, by, bz, Meta); break;
|
{
|
||||||
|
res = MoveItemsToGrid(*(cBlockEntityWithItems *)DestChunk->GetBlockEntity(bx, by, bz));
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the item has been moved, reset the last tick:
|
// If the item has been moved, reset the last tick:
|
||||||
@ -254,7 +283,7 @@ bool cHopperEntity::MoveItemsOut(cChunk & a_Chunk, Int64 a_CurrentTick)
|
|||||||
/// Moves items from a chest (dblchest) above the hopper into this hopper. Returns true if contents have changed.
|
/// Moves items from a chest (dblchest) above the hopper into this hopper. Returns true if contents have changed.
|
||||||
bool cHopperEntity::MoveItemsFromChest(cChunk & a_Chunk)
|
bool cHopperEntity::MoveItemsFromChest(cChunk & a_Chunk)
|
||||||
{
|
{
|
||||||
if (MoveItemsFromGrid(((cChestEntity *)a_Chunk.GetBlockEntity(m_PosX, m_PosY + 1, m_PosZ))->GetContents()))
|
if (MoveItemsFromGrid(*(cChestEntity *)a_Chunk.GetBlockEntity(m_PosX, m_PosY + 1, m_PosZ)))
|
||||||
{
|
{
|
||||||
// Moved the item from the chest directly above the hopper
|
// Moved the item from the chest directly above the hopper
|
||||||
return true;
|
return true;
|
||||||
@ -284,7 +313,7 @@ bool cHopperEntity::MoveItemsFromChest(cChunk & a_Chunk)
|
|||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (MoveItemsFromGrid(((cChestEntity *)Neighbor->GetBlockEntity(x, m_PosY, z))->GetContents()))
|
if (MoveItemsFromGrid(*(cChestEntity *)Neighbor->GetBlockEntity(x, m_PosY, z)))
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -306,7 +335,7 @@ bool cHopperEntity::MoveItemsFromFurnace(cChunk & a_Chunk)
|
|||||||
ASSERT(Furnace != NULL);
|
ASSERT(Furnace != NULL);
|
||||||
|
|
||||||
// Try move from the output slot:
|
// Try move from the output slot:
|
||||||
if (MoveItemsFromSlot(Furnace->GetOutputSlot(), true))
|
if (MoveItemsFromSlot(*Furnace, cFurnaceEntity::fsOutput, true))
|
||||||
{
|
{
|
||||||
cItem NewOutput(Furnace->GetOutputSlot());
|
cItem NewOutput(Furnace->GetOutputSlot());
|
||||||
Furnace->SetOutputSlot(NewOutput.AddCount(-1));
|
Furnace->SetOutputSlot(NewOutput.AddCount(-1));
|
||||||
@ -316,7 +345,7 @@ bool cHopperEntity::MoveItemsFromFurnace(cChunk & a_Chunk)
|
|||||||
// No output moved, check if we can move an empty bucket out of the fuel slot:
|
// No output moved, check if we can move an empty bucket out of the fuel slot:
|
||||||
if (Furnace->GetFuelSlot().m_ItemType == E_ITEM_BUCKET)
|
if (Furnace->GetFuelSlot().m_ItemType == E_ITEM_BUCKET)
|
||||||
{
|
{
|
||||||
if (MoveItemsFromSlot(Furnace->GetFuelSlot(), true))
|
if (MoveItemsFromSlot(*Furnace, cFurnaceEntity::fsFuel, true))
|
||||||
{
|
{
|
||||||
Furnace->SetFuelSlot(cItem());
|
Furnace->SetFuelSlot(cItem());
|
||||||
return true;
|
return true;
|
||||||
@ -331,21 +360,21 @@ bool cHopperEntity::MoveItemsFromFurnace(cChunk & a_Chunk)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// Moves items from the specified ItemGrid into this hopper. Returns true if contents have changed.
|
bool cHopperEntity::MoveItemsFromGrid(cBlockEntityWithItems & a_Entity)
|
||||||
bool cHopperEntity::MoveItemsFromGrid(cItemGrid & a_Grid)
|
|
||||||
{
|
{
|
||||||
int NumSlots = a_Grid.GetNumSlots();
|
cItemGrid & Grid = a_Entity.GetContents();
|
||||||
|
int NumSlots = Grid.GetNumSlots();
|
||||||
|
|
||||||
// First try adding items of types already in the hopper:
|
// First try adding items of types already in the hopper:
|
||||||
for (int i = 0; i < NumSlots; i++)
|
for (int i = 0; i < NumSlots; i++)
|
||||||
{
|
{
|
||||||
if (a_Grid.IsSlotEmpty(i))
|
if (Grid.IsSlotEmpty(i))
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (MoveItemsFromSlot(a_Grid.GetSlot(i), false))
|
if (MoveItemsFromSlot(a_Entity, i, false))
|
||||||
{
|
{
|
||||||
a_Grid.ChangeSlotCount(i, -1);
|
Grid.ChangeSlotCount(i, -1);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -353,13 +382,13 @@ bool cHopperEntity::MoveItemsFromGrid(cItemGrid & a_Grid)
|
|||||||
// No already existing stack can be topped up, try again with allowing new stacks:
|
// No already existing stack can be topped up, try again with allowing new stacks:
|
||||||
for (int i = 0; i < NumSlots; i++)
|
for (int i = 0; i < NumSlots; i++)
|
||||||
{
|
{
|
||||||
if (a_Grid.IsSlotEmpty(i))
|
if (Grid.IsSlotEmpty(i))
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (MoveItemsFromSlot(a_Grid.GetSlot(i), true))
|
if (MoveItemsFromSlot(a_Entity, i, true))
|
||||||
{
|
{
|
||||||
a_Grid.ChangeSlotCount(i, -1);
|
Grid.ChangeSlotCount(i, -1);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -370,13 +399,36 @@ bool cHopperEntity::MoveItemsFromGrid(cItemGrid & a_Grid)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// Moves one of the specified itemstack into this hopper. Returns true if contents have changed. Doesn't change the itemstack.
|
/// Moves one piece of the specified a_Entity's slot itemstack into this hopper. Returns true if contents have changed. Doesn't change the itemstack.
|
||||||
bool cHopperEntity::MoveItemsFromSlot(const cItem & a_ItemStack, bool a_AllowNewStacks)
|
bool cHopperEntity::MoveItemsFromSlot(cBlockEntityWithItems & a_Entity, int a_SlotNum, bool a_AllowNewStacks)
|
||||||
{
|
{
|
||||||
cItem One(a_ItemStack.CopyOne());
|
cItem One(a_Entity.GetSlot(a_SlotNum).CopyOne());
|
||||||
if (m_Contents.AddItem(One, a_AllowNewStacks) > 0)
|
for (int i = 0; i < ContentsWidth * ContentsHeight; i++)
|
||||||
{
|
{
|
||||||
return true;
|
if (m_Contents.IsSlotEmpty(i))
|
||||||
|
{
|
||||||
|
if (a_AllowNewStacks)
|
||||||
|
{
|
||||||
|
if (cPluginManager::Get()->CallHookHopperPullingItem(*m_World, *this, i, a_Entity, a_SlotNum))
|
||||||
|
{
|
||||||
|
// Plugin disagrees with the move
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m_Contents.SetSlot(i, One);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if (m_Contents.GetSlot(i).IsStackableWith(One))
|
||||||
|
{
|
||||||
|
if (cPluginManager::Get()->CallHookHopperPullingItem(*m_World, *this, i, a_Entity, a_SlotNum))
|
||||||
|
{
|
||||||
|
// Plugin disagrees with the move
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_Contents.ChangeSlotCount(i, 1);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -389,7 +441,7 @@ bool cHopperEntity::MoveItemsFromSlot(const cItem & a_ItemStack, bool a_AllowNew
|
|||||||
bool cHopperEntity::MoveItemsToChest(cChunk & a_Chunk, int a_BlockX, int a_BlockY, int a_BlockZ)
|
bool cHopperEntity::MoveItemsToChest(cChunk & a_Chunk, int a_BlockX, int a_BlockY, int a_BlockZ)
|
||||||
{
|
{
|
||||||
// Try the chest directly connected to the hopper:
|
// Try the chest directly connected to the hopper:
|
||||||
if (MoveItemsToGrid(((cChestEntity *)a_Chunk.GetBlockEntity(a_BlockX, a_BlockY, a_BlockZ))->GetContents()))
|
if (MoveItemsToGrid(*(cChestEntity *)a_Chunk.GetBlockEntity(a_BlockX, a_BlockY, a_BlockZ)))
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -418,7 +470,7 @@ bool cHopperEntity::MoveItemsToChest(cChunk & a_Chunk, int a_BlockX, int a_Block
|
|||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (MoveItemsToGrid(((cChestEntity *)Neighbor->GetBlockEntity(a_BlockX, a_BlockY, a_BlockZ))->GetContents()))
|
if (MoveItemsToGrid(*(cChestEntity *)Neighbor->GetBlockEntity(a_BlockX, a_BlockY, a_BlockZ)))
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -440,12 +492,12 @@ bool cHopperEntity::MoveItemsToFurnace(cChunk & a_Chunk, int a_BlockX, int a_Blo
|
|||||||
if (a_HopperMeta == E_META_HOPPER_FACING_YM)
|
if (a_HopperMeta == E_META_HOPPER_FACING_YM)
|
||||||
{
|
{
|
||||||
// Feed the input slot of the furnace
|
// Feed the input slot of the furnace
|
||||||
return MoveItemsToSlot(Furnace->GetContents(), cFurnaceEntity::fsInput);
|
return MoveItemsToSlot(*Furnace, cFurnaceEntity::fsInput);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Feed the fuel slot of the furnace
|
// Feed the fuel slot of the furnace
|
||||||
return MoveItemsToSlot(Furnace->GetContents(), cFurnaceEntity::fsFuel);
|
return MoveItemsToSlot(*Furnace, cFurnaceEntity::fsFuel);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -454,22 +506,14 @@ bool cHopperEntity::MoveItemsToFurnace(cChunk & a_Chunk, int a_BlockX, int a_Blo
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// Moves items to the specified ItemGrid. Returns true if contents have changed
|
bool cHopperEntity::MoveItemsToGrid(cBlockEntityWithItems & a_Entity)
|
||||||
bool cHopperEntity::MoveItemsToGrid(cItemGrid & a_ItemGrid)
|
|
||||||
{
|
{
|
||||||
// Iterate through our slots, try to move from each one:
|
// Iterate through our slots, try to move from each one:
|
||||||
for (int i = 0; i < ContentsWidth * ContentsHeight; i++)
|
int NumSlots = a_Entity.GetContents().GetNumSlots();
|
||||||
|
for (int i = 0; i < NumSlots; i++)
|
||||||
{
|
{
|
||||||
const cItem & SrcItem = m_Contents.GetSlot(i);
|
if (MoveItemsToSlot(a_Entity, i))
|
||||||
if (SrcItem.IsEmpty())
|
|
||||||
{
|
{
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
cItem ToAdd = SrcItem.CopyOne();
|
|
||||||
if (a_ItemGrid.AddItem(ToAdd) > 0)
|
|
||||||
{
|
|
||||||
m_Contents.ChangeSlotCount(i, -1);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -480,17 +524,22 @@ bool cHopperEntity::MoveItemsToGrid(cItemGrid & a_ItemGrid)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// Moves one piece to the specified ItemGrid's slot. Returns true if contents have changed.
|
bool cHopperEntity::MoveItemsToSlot(cBlockEntityWithItems & a_Entity, int a_DstSlotNum)
|
||||||
bool cHopperEntity::MoveItemsToSlot(cItemGrid & a_ItemGrid, int a_DestSlotNum)
|
|
||||||
{
|
{
|
||||||
if (a_ItemGrid.IsSlotEmpty(a_DestSlotNum))
|
cItemGrid & Grid = a_Entity.GetContents();
|
||||||
|
if (Grid.IsSlotEmpty(a_DstSlotNum))
|
||||||
{
|
{
|
||||||
// The slot is empty, move the first non-empty slot from our contents:
|
// The slot is empty, move the first non-empty slot from our contents:
|
||||||
for (int i = 0; i < ContentsWidth * ContentsHeight; i++)
|
for (int i = 0; i < ContentsWidth * ContentsHeight; i++)
|
||||||
{
|
{
|
||||||
if (!m_Contents.IsSlotEmpty(i))
|
if (!m_Contents.IsSlotEmpty(i))
|
||||||
{
|
{
|
||||||
a_ItemGrid.SetSlot(a_DestSlotNum, m_Contents.GetSlot(i).CopyOne());
|
if (cPluginManager::Get()->CallHookHopperPushingItem(*m_World, *this, i, a_Entity, a_DstSlotNum))
|
||||||
|
{
|
||||||
|
// A plugin disagrees with the move
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Grid.SetSlot(a_DstSlotNum, m_Contents.GetSlot(i).CopyOne());
|
||||||
m_Contents.ChangeSlotCount(i, -1);
|
m_Contents.ChangeSlotCount(i, -1);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -500,7 +549,7 @@ bool cHopperEntity::MoveItemsToSlot(cItemGrid & a_ItemGrid, int a_DestSlotNum)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// The slot is taken, try to top it up:
|
// The slot is taken, try to top it up:
|
||||||
const cItem & DestSlot = a_ItemGrid.GetSlot(a_DestSlotNum);
|
const cItem & DestSlot = Grid.GetSlot(a_DstSlotNum);
|
||||||
if (DestSlot.IsFullStack())
|
if (DestSlot.IsFullStack())
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
@ -509,7 +558,12 @@ bool cHopperEntity::MoveItemsToSlot(cItemGrid & a_ItemGrid, int a_DestSlotNum)
|
|||||||
{
|
{
|
||||||
if (m_Contents.GetSlot(i).IsStackableWith(DestSlot))
|
if (m_Contents.GetSlot(i).IsStackableWith(DestSlot))
|
||||||
{
|
{
|
||||||
a_ItemGrid.ChangeSlotCount(a_DestSlotNum, 1);
|
if (cPluginManager::Get()->CallHookHopperPushingItem(*m_World, *this, i, a_Entity, a_DstSlotNum))
|
||||||
|
{
|
||||||
|
// A plugin disagrees with the move
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Grid.ChangeSlotCount(a_DstSlotNum, 1);
|
||||||
m_Contents.ChangeSlotCount(i, -1);
|
m_Contents.ChangeSlotCount(i, -1);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -78,11 +78,11 @@ protected:
|
|||||||
/// Moves items from a furnace above the hopper into this hopper. Returns true if contents have changed.
|
/// Moves items from a furnace above the hopper into this hopper. Returns true if contents have changed.
|
||||||
bool MoveItemsFromFurnace(cChunk & a_Chunk);
|
bool MoveItemsFromFurnace(cChunk & a_Chunk);
|
||||||
|
|
||||||
/// Moves items from the specified ItemGrid into this hopper. Returns true if contents have changed.
|
/// Moves items from the specified a_Entity's Contents into this hopper. Returns true if contents have changed.
|
||||||
bool MoveItemsFromGrid(cItemGrid & a_Grid);
|
bool MoveItemsFromGrid(cBlockEntityWithItems & a_Entity);
|
||||||
|
|
||||||
/// Moves one piece from the specified itemstack into this hopper. Returns true if contents have changed. Doesn't change the itemstack.
|
/// Moves one piece from the specified itemstack into this hopper. Returns true if contents have changed. Doesn't change the itemstack.
|
||||||
bool MoveItemsFromSlot(const cItem & a_ItemStack, bool a_AllowNewStacks);
|
bool MoveItemsFromSlot(cBlockEntityWithItems & a_Entity, int a_SrcSlotNum, bool a_AllowNewStacks);
|
||||||
|
|
||||||
/// Moves items to the chest at the specified coords. Returns true if contents have changed
|
/// Moves items to the chest at the specified coords. Returns true if contents have changed
|
||||||
bool MoveItemsToChest(cChunk & a_Chunk, int a_BlockX, int a_BlockY, int a_BlockZ);
|
bool MoveItemsToChest(cChunk & a_Chunk, int a_BlockX, int a_BlockY, int a_BlockZ);
|
||||||
@ -91,10 +91,10 @@ protected:
|
|||||||
bool MoveItemsToFurnace(cChunk & a_Chunk, int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_HopperMeta);
|
bool MoveItemsToFurnace(cChunk & a_Chunk, int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_HopperMeta);
|
||||||
|
|
||||||
/// Moves items to the specified ItemGrid. Returns true if contents have changed
|
/// Moves items to the specified ItemGrid. Returns true if contents have changed
|
||||||
bool MoveItemsToGrid(cItemGrid & a_ItemGrid);
|
bool MoveItemsToGrid(cBlockEntityWithItems & a_Entity);
|
||||||
|
|
||||||
/// Moves one piece to the specified ItemGrid's slot. Returns true if contents have changed.
|
/// Moves one piece to the specified entity's contents' slot. Returns true if contents have changed.
|
||||||
bool MoveItemsToSlot(cItemGrid & a_ItemGrid, int a_DestSlotNum);
|
bool MoveItemsToSlot(cBlockEntityWithItems & a_Entity, int a_DstSlotNum);
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
|
|
||||||
|
@ -677,6 +677,32 @@ void cLuaState::Push(void * a_Ptr)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void cLuaState::Push(cHopperEntity * a_Hopper)
|
||||||
|
{
|
||||||
|
ASSERT(IsValid());
|
||||||
|
ASSERT(m_NumCurrentFunctionArgs >= 0); // A function must be pushed to stack first
|
||||||
|
|
||||||
|
tolua_pushusertype(m_LuaState, a_Hopper, "cHopperEntity");
|
||||||
|
m_NumCurrentFunctionArgs += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void cLuaState::Push(cBlockEntity * a_BlockEntity)
|
||||||
|
{
|
||||||
|
ASSERT(IsValid());
|
||||||
|
ASSERT(m_NumCurrentFunctionArgs >= 0); // A function must be pushed to stack first
|
||||||
|
|
||||||
|
tolua_pushusertype(m_LuaState, a_BlockEntity, "cBlockEntity");
|
||||||
|
m_NumCurrentFunctionArgs += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void cLuaState::GetReturn(int a_StackPos, bool & a_ReturnedVal)
|
void cLuaState::GetReturn(int a_StackPos, bool & a_ReturnedVal)
|
||||||
{
|
{
|
||||||
a_ReturnedVal = (tolua_toboolean(m_LuaState, a_StackPos, a_ReturnedVal ? 1 : 0) > 0);
|
a_ReturnedVal = (tolua_toboolean(m_LuaState, a_StackPos, a_ReturnedVal ? 1 : 0) > 0);
|
||||||
|
@ -53,6 +53,8 @@ struct HTTPTemplateRequest;
|
|||||||
class cTNTEntity;
|
class cTNTEntity;
|
||||||
class cCreeper;
|
class cCreeper;
|
||||||
class Vector3i;
|
class Vector3i;
|
||||||
|
class cHopperEntity;
|
||||||
|
class cBlockEntity;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -178,6 +180,8 @@ public:
|
|||||||
void Push(cCreeper * a_Creeper);
|
void Push(cCreeper * a_Creeper);
|
||||||
void Push(Vector3i * a_Vector);
|
void Push(Vector3i * a_Vector);
|
||||||
void Push(void * a_Ptr);
|
void Push(void * a_Ptr);
|
||||||
|
void Push(cHopperEntity * a_Hopper);
|
||||||
|
void Push(cBlockEntity * a_BlockEntity);
|
||||||
|
|
||||||
/// Call any 0-param 0-return Lua function in a single line:
|
/// Call any 0-param 0-return Lua function in a single line:
|
||||||
template <typename FnT>
|
template <typename FnT>
|
||||||
|
@ -61,6 +61,8 @@ public:
|
|||||||
virtual bool OnExploded (cWorld & a_World, double a_ExplosionSize, bool a_CanCauseFire, double a_X, double a_Y, double a_Z, eExplosionSource a_Source, void * a_SourceData) = 0;
|
virtual bool OnExploded (cWorld & a_World, double a_ExplosionSize, bool a_CanCauseFire, double a_X, double a_Y, double a_Z, eExplosionSource a_Source, void * a_SourceData) = 0;
|
||||||
virtual bool OnExploding (cWorld & a_World, double & a_ExplosionSize, bool & a_CanCauseFire, double a_X, double a_Y, double a_Z, eExplosionSource a_Source, void * a_SourceData) = 0;
|
virtual bool OnExploding (cWorld & a_World, double & a_ExplosionSize, bool & a_CanCauseFire, double a_X, double a_Y, double a_Z, eExplosionSource a_Source, void * a_SourceData) = 0;
|
||||||
virtual bool OnHandshake (cClientHandle * a_Client, const AString & a_Username) = 0;
|
virtual bool OnHandshake (cClientHandle * a_Client, const AString & a_Username) = 0;
|
||||||
|
virtual bool OnHopperPullingItem (cWorld & a_World, cHopperEntity & a_Hopper, int a_DstSlotNum, cBlockEntityWithItems & a_SrcEntity, int a_SrcSlotNum) = 0;
|
||||||
|
virtual bool OnHopperPushingItem (cWorld & a_World, cHopperEntity & a_Hopper, int a_SrcSlotNum, cBlockEntityWithItems & a_DstEntity, int a_DstSlotNum) = 0;
|
||||||
virtual bool OnKilling (cEntity & a_Victim, cEntity * a_Killer) = 0;
|
virtual bool OnKilling (cEntity & a_Victim, cEntity * a_Killer) = 0;
|
||||||
virtual bool OnLogin (cClientHandle * a_Client, int a_ProtocolVersion, const AString & a_Username) = 0;
|
virtual bool OnLogin (cClientHandle * a_Client, int a_ProtocolVersion, const AString & a_Username) = 0;
|
||||||
virtual bool OnPlayerAnimation (cPlayer & a_Player, int a_Animation) = 0;
|
virtual bool OnPlayerAnimation (cPlayer & a_Player, int a_Animation) = 0;
|
||||||
|
@ -326,6 +326,30 @@ bool cPlugin_NewLua::OnHandshake(cClientHandle * a_Client, const AString & a_Use
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
bool cPlugin_NewLua::OnHopperPullingItem(cWorld & a_World, cHopperEntity & a_Hopper, int a_DstSlotNum, cBlockEntityWithItems & a_SrcEntity, int a_SrcSlotNum)
|
||||||
|
{
|
||||||
|
cCSLock Lock(m_CriticalSection);
|
||||||
|
bool res = false;
|
||||||
|
m_LuaState.Call(GetHookFnName(cPluginManager::HOOK_HOPPER_PULLING_ITEM), &a_World, &a_Hopper, a_DstSlotNum, &a_SrcEntity, a_SrcSlotNum, cLuaState::Return, res);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
bool cPlugin_NewLua::OnHopperPushingItem(cWorld & a_World, cHopperEntity & a_Hopper, int a_SrcSlotNum, cBlockEntityWithItems & a_DstEntity, int a_DstSlotNum)
|
||||||
|
{
|
||||||
|
cCSLock Lock(m_CriticalSection);
|
||||||
|
bool res = false;
|
||||||
|
m_LuaState.Call(GetHookFnName(cPluginManager::HOOK_HOPPER_PUSHING_ITEM), &a_World, &a_Hopper, a_SrcSlotNum, &a_DstEntity, a_DstSlotNum, cLuaState::Return, res);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool cPlugin_NewLua::OnKilling(cEntity & a_Victim, cEntity * a_Killer)
|
bool cPlugin_NewLua::OnKilling(cEntity & a_Victim, cEntity * a_Killer)
|
||||||
{
|
{
|
||||||
cCSLock Lock(m_CriticalSection);
|
cCSLock Lock(m_CriticalSection);
|
||||||
|
@ -57,6 +57,8 @@ public:
|
|||||||
virtual bool OnExploded (cWorld & a_World, double a_ExplosionSize, bool a_CanCauseFire, double a_X, double a_Y, double a_Z, eExplosionSource a_Source, void * a_SourceData) override;
|
virtual bool OnExploded (cWorld & a_World, double a_ExplosionSize, bool a_CanCauseFire, double a_X, double a_Y, double a_Z, eExplosionSource a_Source, void * a_SourceData) override;
|
||||||
virtual bool OnExploding (cWorld & a_World, double & a_ExplosionSize, bool & a_CanCauseFire, double a_X, double a_Y, double a_Z, eExplosionSource a_Source, void * a_SourceData) override;
|
virtual bool OnExploding (cWorld & a_World, double & a_ExplosionSize, bool & a_CanCauseFire, double a_X, double a_Y, double a_Z, eExplosionSource a_Source, void * a_SourceData) override;
|
||||||
virtual bool OnHandshake (cClientHandle * a_Client, const AString & a_Username) override;
|
virtual bool OnHandshake (cClientHandle * a_Client, const AString & a_Username) override;
|
||||||
|
virtual bool OnHopperPullingItem (cWorld & a_World, cHopperEntity & a_Hopper, int a_DstSlotNum, cBlockEntityWithItems & a_SrcEntity, int a_SrcSlotNum) override;
|
||||||
|
virtual bool OnHopperPushingItem (cWorld & a_World, cHopperEntity & a_Hopper, int a_SrcSlotNum, cBlockEntityWithItems & a_DstEntity, int a_DstSlotNum) override;
|
||||||
virtual bool OnKilling (cEntity & a_Victim, cEntity * a_Killer) override;
|
virtual bool OnKilling (cEntity & a_Victim, cEntity * a_Killer) override;
|
||||||
virtual bool OnLogin (cClientHandle * a_Client, int a_ProtocolVersion, const AString & a_Username) override;
|
virtual bool OnLogin (cClientHandle * a_Client, int a_ProtocolVersion, const AString & a_Username) override;
|
||||||
virtual bool OnPlayerAnimation (cPlayer & a_Player, int a_Animation) override;
|
virtual bool OnPlayerAnimation (cPlayer & a_Player, int a_Animation) override;
|
||||||
|
@ -489,6 +489,48 @@ bool cPluginManager::CallHookHandshake(cClientHandle * a_ClientHandle, const ASt
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
bool cPluginManager::CallHookHopperPullingItem(cWorld & a_World, cHopperEntity & a_Hopper, int a_DstSlotNum, cBlockEntityWithItems & a_SrcEntity, int a_SrcSlotNum)
|
||||||
|
{
|
||||||
|
HookMap::iterator Plugins = m_Hooks.find(HOOK_HOPPER_PULLING_ITEM);
|
||||||
|
if (Plugins == m_Hooks.end())
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
|
||||||
|
{
|
||||||
|
if ((*itr)->OnHopperPullingItem(a_World, a_Hopper, a_DstSlotNum, a_SrcEntity, a_SrcSlotNum))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
bool cPluginManager::CallHookHopperPushingItem(cWorld & a_World, cHopperEntity & a_Hopper, int a_SrcSlotNum, cBlockEntityWithItems & a_DstEntity, int a_DstSlotNum)
|
||||||
|
{
|
||||||
|
HookMap::iterator Plugins = m_Hooks.find(HOOK_HOPPER_PUSHING_ITEM);
|
||||||
|
if (Plugins == m_Hooks.end())
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
|
||||||
|
{
|
||||||
|
if ((*itr)->OnHopperPushingItem(a_World, a_Hopper, a_SrcSlotNum, a_DstEntity, a_DstSlotNum))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool cPluginManager::CallHookKilling(cEntity & a_Victim, cEntity * a_Killer)
|
bool cPluginManager::CallHookKilling(cEntity & a_Victim, cEntity * a_Killer)
|
||||||
{
|
{
|
||||||
HookMap::iterator Plugins = m_Hooks.find(HOOK_KILLING);
|
HookMap::iterator Plugins = m_Hooks.find(HOOK_KILLING);
|
||||||
|
@ -38,6 +38,12 @@ class cPawn;
|
|||||||
// fwd: CommandOutput.h
|
// fwd: CommandOutput.h
|
||||||
class cCommandOutputCallback;
|
class cCommandOutputCallback;
|
||||||
|
|
||||||
|
// fwd: BlockEntities/HopperEntity.h
|
||||||
|
class cHopperEntity;
|
||||||
|
|
||||||
|
// fwd: BlockEntities/BlockEntityWithItems.h
|
||||||
|
class cBlockEntityWithItems;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -66,6 +72,8 @@ public: // tolua_export
|
|||||||
HOOK_EXPLODED,
|
HOOK_EXPLODED,
|
||||||
HOOK_EXPLODING,
|
HOOK_EXPLODING,
|
||||||
HOOK_HANDSHAKE,
|
HOOK_HANDSHAKE,
|
||||||
|
HOOK_HOPPER_PULLING_ITEM,
|
||||||
|
HOOK_HOPPER_PUSHING_ITEM,
|
||||||
HOOK_KILLING,
|
HOOK_KILLING,
|
||||||
HOOK_LOGIN,
|
HOOK_LOGIN,
|
||||||
HOOK_PLAYER_ANIMATION,
|
HOOK_PLAYER_ANIMATION,
|
||||||
@ -143,6 +151,8 @@ public: // tolua_export
|
|||||||
bool CallHookExploded (cWorld & a_World, double a_ExplosionSize, bool a_CanCauseFire, double a_X, double a_Y, double a_Z, eExplosionSource a_Source, void * a_SourceData);
|
bool CallHookExploded (cWorld & a_World, double a_ExplosionSize, bool a_CanCauseFire, double a_X, double a_Y, double a_Z, eExplosionSource a_Source, void * a_SourceData);
|
||||||
bool CallHookExploding (cWorld & a_World, double & a_ExplosionSize, bool & a_CanCauseFire, double a_X, double a_Y, double a_Z, eExplosionSource a_Source, void * a_SourceData);
|
bool CallHookExploding (cWorld & a_World, double & a_ExplosionSize, bool & a_CanCauseFire, double a_X, double a_Y, double a_Z, eExplosionSource a_Source, void * a_SourceData);
|
||||||
bool CallHookHandshake (cClientHandle * a_ClientHandle, const AString & a_Username);
|
bool CallHookHandshake (cClientHandle * a_ClientHandle, const AString & a_Username);
|
||||||
|
bool CallHookHopperPullingItem (cWorld & a_World, cHopperEntity & a_Hopper, int a_DstSlotNum, cBlockEntityWithItems & a_SrcEntity, int a_SrcSlotNum);
|
||||||
|
bool CallHookHopperPushingItem (cWorld & a_World, cHopperEntity & a_Hopper, int a_SrcSlotNum, cBlockEntityWithItems & a_DstEntity, int a_DstSlotNum);
|
||||||
bool CallHookKilling (cEntity & a_Victim, cEntity * a_Killer);
|
bool CallHookKilling (cEntity & a_Victim, cEntity * a_Killer);
|
||||||
bool CallHookLogin (cClientHandle * a_Client, int a_ProtocolVersion, const AString & a_Username);
|
bool CallHookLogin (cClientHandle * a_Client, int a_ProtocolVersion, const AString & a_Username);
|
||||||
bool CallHookPlayerAnimation (cPlayer & a_Player, int a_Animation);
|
bool CallHookPlayerAnimation (cPlayer & a_Player, int a_Animation);
|
||||||
|
Loading…
Reference in New Issue
Block a user