From b026dc30349054ff9312834adb9a95ffb8ed8303 Mon Sep 17 00:00:00 2001 From: "luksor111@gmail.com" Date: Wed, 26 Dec 2012 18:15:11 +0000 Subject: Dispensers can spawn mobs git-svn-id: http://mc-server.googlecode.com/svn/trunk@1106 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/DispenserEntity.cpp | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/source/DispenserEntity.cpp b/source/DispenserEntity.cpp index 45f9d58f3..09a847900 100644 --- a/source/DispenserEntity.cpp +++ b/source/DispenserEntity.cpp @@ -101,8 +101,9 @@ void cDispenserEntity::Dispense() if(SlotsCnt > 0) { MTRand r1; - cItem Drop = m_Items[OccupiedSlots[r1.randInt() % SlotsCnt]]; - switch( m_Items[OccupiedSlots[r1.randInt() % SlotsCnt]].m_ItemType ) + char RandomSlot = r1.randInt() % SlotsCnt; + cItem Drop = m_Items[OccupiedSlots[RandomSlot]]; + switch( m_Items[OccupiedSlots[RandomSlot]].m_ItemType ) { case E_ITEM_BUCKET: { @@ -110,19 +111,19 @@ void cDispenserEntity::Dispense() if( DispBlock == E_BLOCK_STATIONARY_WATER ) { m_World->SetBlock( Disp_X, Disp_Y, Disp_Z, E_BLOCK_AIR, 0 ); - m_Items[OccupiedSlots[r1.randInt() % SlotsCnt]].m_ItemType = E_ITEM_WATER_BUCKET; + m_Items[OccupiedSlots[RandomSlot]].m_ItemType = E_ITEM_WATER_BUCKET; } else if( DispBlock == E_BLOCK_STATIONARY_LAVA ) { m_World->SetBlock( Disp_X, Disp_Y, Disp_Z, E_BLOCK_AIR, 0 ); - m_Items[OccupiedSlots[r1.randInt() % SlotsCnt]].m_ItemType = E_ITEM_LAVA_BUCKET; + m_Items[OccupiedSlots[RandomSlot]].m_ItemType = E_ITEM_LAVA_BUCKET; } else { cItems Pickups; Pickups.push_back(cItem(Drop.m_ItemType, 1, Drop.m_ItemHealth)); m_World->SpawnItemPickups(Pickups, Disp_X, Disp_Y, Disp_Z); - m_Items[OccupiedSlots[r1.randInt() % SlotsCnt]].m_ItemCount--; + m_Items[OccupiedSlots[RandomSlot]].m_ItemCount--; } break; } @@ -132,14 +133,14 @@ void cDispenserEntity::Dispense() if( DispBlock == E_BLOCK_AIR || IsBlockLiquid(DispBlock) || cFluidSimulator::CanWashAway(DispBlock) ) { m_World->SetBlock( Disp_X, Disp_Y, Disp_Z, E_BLOCK_STATIONARY_WATER, 0 ); - m_Items[OccupiedSlots[r1.randInt() % SlotsCnt]].m_ItemType = E_ITEM_BUCKET; + m_Items[OccupiedSlots[RandomSlot]].m_ItemType = E_ITEM_BUCKET; } else { cItems Pickups; Pickups.push_back(cItem(Drop.m_ItemType, 1, Drop.m_ItemHealth)); m_World->SpawnItemPickups(Pickups, Disp_X, Disp_Y, Disp_Z); - m_Items[OccupiedSlots[r1.randInt() % SlotsCnt]].m_ItemCount--; + m_Items[OccupiedSlots[RandomSlot]].m_ItemCount--; } break; } @@ -149,14 +150,22 @@ void cDispenserEntity::Dispense() if( DispBlock == E_BLOCK_AIR || IsBlockLiquid(DispBlock) || cFluidSimulator::CanWashAway(DispBlock) ) { m_World->SetBlock( Disp_X, Disp_Y, Disp_Z, E_BLOCK_STATIONARY_LAVA, 0 ); - m_Items[OccupiedSlots[r1.randInt() % SlotsCnt]].m_ItemType = E_ITEM_BUCKET; + m_Items[OccupiedSlots[RandomSlot]].m_ItemType = E_ITEM_BUCKET; } else { cItems Pickups; Pickups.push_back(cItem(Drop.m_ItemType, 1, Drop.m_ItemHealth)); m_World->SpawnItemPickups(Pickups, Disp_X, Disp_Y, Disp_Z); - m_Items[OccupiedSlots[r1.randInt() % SlotsCnt]].m_ItemCount--; + m_Items[OccupiedSlots[RandomSlot]].m_ItemCount--; + } + break; + } + case E_ITEM_SPAWN_EGG: + { + if (m_World->SpawnMob(Disp_X + 0.5, Disp_Y, Disp_Z + 0.5, m_Items[OccupiedSlots[RandomSlot]].m_ItemDamage) >= 0) + { + m_Items[OccupiedSlots[RandomSlot]].m_ItemCount--; } break; } @@ -165,7 +174,7 @@ void cDispenserEntity::Dispense() cItems Pickups; Pickups.push_back(cItem(Drop.m_ItemType, 1, Drop.m_ItemHealth)); m_World->SpawnItemPickups(Pickups, Disp_X, Disp_Y, Disp_Z); - m_Items[OccupiedSlots[r1.randInt() % SlotsCnt]].m_ItemCount--; + m_Items[OccupiedSlots[RandomSlot]].m_ItemCount--; break; } } -- cgit v1.2.3