Basic support for thrown items - eggs, snowballs and ender pearls.
They can be thrown, but they don't do anything on impact. Also they don't save to nor load from MCA.
This commit is contained in:
parent
88f3fe7f00
commit
d7a5287000
@ -2347,6 +2347,10 @@
|
||||
RelativePath="..\source\items\ItemSword.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\source\Items\ItemThrowable.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\source\items\ItemWood.h"
|
||||
>
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
** Lua binding: AllToLua
|
||||
** Generated automatically by tolua++-1.0.92 on 08/30/13 17:24:30.
|
||||
** Generated automatically by tolua++-1.0.92 on 08/30/13 18:03:04.
|
||||
*/
|
||||
|
||||
#ifndef __cplusplus
|
||||
@ -203,63 +203,66 @@ static int tolua_collect_Vector3d (lua_State* tolua_S)
|
||||
/* function to register type */
|
||||
static void tolua_reg_types (lua_State* tolua_S)
|
||||
{
|
||||
tolua_usertype(tolua_S,"cThrownEnderPearlEntity");
|
||||
tolua_usertype(tolua_S,"TakeDamageInfo");
|
||||
tolua_usertype(tolua_S,"cServer");
|
||||
tolua_usertype(tolua_S,"cPluginManager");
|
||||
tolua_usertype(tolua_S,"cMonster");
|
||||
tolua_usertype(tolua_S,"cCraftingGrid");
|
||||
tolua_usertype(tolua_S,"cCraftingRecipe");
|
||||
tolua_usertype(tolua_S,"cPlugin");
|
||||
tolua_usertype(tolua_S,"cMonster");
|
||||
tolua_usertype(tolua_S,"cWindow");
|
||||
tolua_usertype(tolua_S,"cStringMap");
|
||||
tolua_usertype(tolua_S,"cItemGrid");
|
||||
tolua_usertype(tolua_S,"cBlockArea");
|
||||
tolua_usertype(tolua_S,"cEnchantments");
|
||||
tolua_usertype(tolua_S,"cLuaWindow");
|
||||
tolua_usertype(tolua_S,"cInventory");
|
||||
tolua_usertype(tolua_S,"cServer");
|
||||
tolua_usertype(tolua_S,"cRoot");
|
||||
tolua_usertype(tolua_S,"cWindow");
|
||||
tolua_usertype(tolua_S,"cCuboid");
|
||||
tolua_usertype(tolua_S,"std::vector<cIniFile::key>");
|
||||
tolua_usertype(tolua_S,"cCraftingGrid");
|
||||
tolua_usertype(tolua_S,"cGroup");
|
||||
tolua_usertype(tolua_S,"cPickup");
|
||||
tolua_usertype(tolua_S,"std::vector<std::string>");
|
||||
tolua_usertype(tolua_S,"cGroup");
|
||||
tolua_usertype(tolua_S,"cTracer");
|
||||
tolua_usertype(tolua_S,"cClientHandle");
|
||||
tolua_usertype(tolua_S,"cChunkDesc");
|
||||
tolua_usertype(tolua_S,"cFurnaceRecipe");
|
||||
tolua_usertype(tolua_S,"cTracer");
|
||||
tolua_usertype(tolua_S,"cChatColor");
|
||||
tolua_usertype(tolua_S,"cCuboid");
|
||||
tolua_usertype(tolua_S,"Vector3i");
|
||||
tolua_usertype(tolua_S,"cWorld");
|
||||
tolua_usertype(tolua_S,"cEntity");
|
||||
tolua_usertype(tolua_S,"cChatColor");
|
||||
tolua_usertype(tolua_S,"cThrownSnowballEntity");
|
||||
tolua_usertype(tolua_S,"cWebAdmin");
|
||||
tolua_usertype(tolua_S,"cCraftingRecipes");
|
||||
tolua_usertype(tolua_S,"cItems");
|
||||
tolua_usertype(tolua_S,"cWebPlugin");
|
||||
tolua_usertype(tolua_S,"cItem");
|
||||
tolua_usertype(tolua_S,"Vector3f");
|
||||
tolua_usertype(tolua_S,"cArrowEntity");
|
||||
tolua_usertype(tolua_S,"cDropSpenserEntity");
|
||||
tolua_usertype(tolua_S,"cWebPlugin");
|
||||
tolua_usertype(tolua_S,"cWebAdmin");
|
||||
tolua_usertype(tolua_S,"sWebAdminPage");
|
||||
tolua_usertype(tolua_S,"HTTPFormData");
|
||||
tolua_usertype(tolua_S,"cChestEntity");
|
||||
tolua_usertype(tolua_S,"cDispenserEntity");
|
||||
tolua_usertype(tolua_S,"sWebAdminPage");
|
||||
tolua_usertype(tolua_S,"HTTPRequest");
|
||||
tolua_usertype(tolua_S,"cBlockEntity");
|
||||
tolua_usertype(tolua_S,"cItemGrid::cListener");
|
||||
tolua_usertype(tolua_S,"HTTPTemplateRequest");
|
||||
tolua_usertype(tolua_S,"HTTPRequest");
|
||||
tolua_usertype(tolua_S,"HTTPFormData");
|
||||
tolua_usertype(tolua_S,"cFurnaceEntity");
|
||||
tolua_usertype(tolua_S,"cDropperEntity");
|
||||
tolua_usertype(tolua_S,"cLineBlockTracer");
|
||||
tolua_usertype(tolua_S,"cPluginManager");
|
||||
tolua_usertype(tolua_S,"cIniFile");
|
||||
tolua_usertype(tolua_S,"cPluginLua");
|
||||
tolua_usertype(tolua_S,"cBlockEntityWithItems");
|
||||
tolua_usertype(tolua_S,"cLineBlockTracer");
|
||||
tolua_usertype(tolua_S,"cCriticalSection");
|
||||
tolua_usertype(tolua_S,"cIniFile");
|
||||
tolua_usertype(tolua_S,"cEntity");
|
||||
tolua_usertype(tolua_S,"cListeners");
|
||||
tolua_usertype(tolua_S,"cPawn");
|
||||
tolua_usertype(tolua_S,"cPlayer");
|
||||
tolua_usertype(tolua_S,"cThrownEggEntity");
|
||||
tolua_usertype(tolua_S,"cGroupManager");
|
||||
tolua_usertype(tolua_S,"cBlockEntityWindowOwner");
|
||||
tolua_usertype(tolua_S,"cCriticalSection");
|
||||
tolua_usertype(tolua_S,"cInventory");
|
||||
tolua_usertype(tolua_S,"cProjectileEntity");
|
||||
tolua_usertype(tolua_S,"cPluginLua");
|
||||
tolua_usertype(tolua_S,"cItems");
|
||||
tolua_usertype(tolua_S,"cWorld");
|
||||
tolua_usertype(tolua_S,"cPlayer");
|
||||
tolua_usertype(tolua_S,"Vector3d");
|
||||
}
|
||||
|
||||
@ -28689,6 +28692,15 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S)
|
||||
tolua_function(tolua_S,"SetDamageCoeff",tolua_AllToLua_cArrowEntity_SetDamageCoeff00);
|
||||
tolua_function(tolua_S,"CanPickup",tolua_AllToLua_cArrowEntity_CanPickup00);
|
||||
tolua_endmodule(tolua_S);
|
||||
tolua_cclass(tolua_S,"cThrownEggEntity","cThrownEggEntity","cProjectileEntity",NULL);
|
||||
tolua_beginmodule(tolua_S,"cThrownEggEntity");
|
||||
tolua_endmodule(tolua_S);
|
||||
tolua_cclass(tolua_S,"cThrownEnderPearlEntity","cThrownEnderPearlEntity","cProjectileEntity",NULL);
|
||||
tolua_beginmodule(tolua_S,"cThrownEnderPearlEntity");
|
||||
tolua_endmodule(tolua_S);
|
||||
tolua_cclass(tolua_S,"cThrownSnowballEntity","cThrownSnowballEntity","cProjectileEntity",NULL);
|
||||
tolua_beginmodule(tolua_S,"cThrownSnowballEntity");
|
||||
tolua_endmodule(tolua_S);
|
||||
tolua_cclass(tolua_S,"cPluginManager","cPluginManager","",NULL);
|
||||
tolua_beginmodule(tolua_S,"cPluginManager");
|
||||
tolua_constant(tolua_S,"HOOK_BLOCK_TO_PICKUPS",cPluginManager::HOOK_BLOCK_TO_PICKUPS);
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
** Lua binding: AllToLua
|
||||
** Generated automatically by tolua++-1.0.92 on 08/30/13 17:24:30.
|
||||
** Generated automatically by tolua++-1.0.92 on 08/30/13 18:03:05.
|
||||
*/
|
||||
|
||||
/* Exported function */
|
||||
|
@ -101,11 +101,14 @@ cProjectileEntity * cProjectileEntity::Create(eKind a_Kind, cEntity * a_Creator,
|
||||
|
||||
switch (a_Kind)
|
||||
{
|
||||
case pkArrow: return new cArrowEntity(a_Creator, a_X, a_Y, a_Z, Speed);
|
||||
case pkArrow: return new cArrowEntity (a_Creator, a_X, a_Y, a_Z, Speed);
|
||||
case pkEgg: return new cThrownEggEntity (a_Creator, a_X, a_Y, a_Z, Speed);
|
||||
case pkEnderPearl: return new cThrownEnderPearlEntity(a_Creator, a_X, a_Y, a_Z, Speed);
|
||||
case pkSnowball: return new cThrownSnowballEntity (a_Creator, a_X, a_Y, a_Z, Speed);
|
||||
// TODO: the rest
|
||||
}
|
||||
|
||||
LOGWARNING("%s: Unknown kind: %d", __FUNCTION__, a_Kind);
|
||||
LOGWARNING("%s: Unknown projectile kind: %d", __FUNCTION__, a_Kind);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -210,10 +213,20 @@ void cProjectileEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk)
|
||||
|
||||
|
||||
|
||||
void cProjectileEntity::SpawnOn(cClientHandle & a_Client)
|
||||
{
|
||||
// Default spawning - use the projectile kind to spawn an object:
|
||||
a_Client.SendSpawnObject(*this, m_ProjectileKind, 0, 0, 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// cArrowEntity:
|
||||
|
||||
cArrowEntity::cArrowEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d a_Speed) :
|
||||
cArrowEntity::cArrowEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed) :
|
||||
super(pkArrow, a_Creator, a_X, a_Y, a_Z, 0.5, 0.5),
|
||||
m_PickupState(psNoPickup),
|
||||
m_DamageCoeff(2)
|
||||
@ -264,3 +277,75 @@ void cArrowEntity::SpawnOn(cClientHandle & a_Client)
|
||||
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// cThrownEggEntity:
|
||||
|
||||
cThrownEggEntity::cThrownEggEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed) :
|
||||
super(pkEgg, a_Creator, a_X, a_Y, a_Z, 0.25, 0.25)
|
||||
{
|
||||
SetSpeed(a_Speed);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cThrownEggEntity::OnHitSolidBlock(int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace)
|
||||
{
|
||||
// TODO: Random-spawn a chicken or four
|
||||
|
||||
Destroy();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// cThrownEnderPearlEntity :
|
||||
|
||||
cThrownEnderPearlEntity::cThrownEnderPearlEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed) :
|
||||
super(pkEnderPearl, a_Creator, a_X, a_Y, a_Z, 0.25, 0.25)
|
||||
{
|
||||
SetSpeed(a_Speed);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cThrownEnderPearlEntity::OnHitSolidBlock(int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace)
|
||||
{
|
||||
// TODO: Teleport the creator here, make them take 5 damage
|
||||
|
||||
Destroy();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// cThrownSnowballEntity :
|
||||
|
||||
cThrownSnowballEntity::cThrownSnowballEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed) :
|
||||
super(pkSnowball, a_Creator, a_X, a_Y, a_Z, 0.25, 0.25)
|
||||
{
|
||||
SetSpeed(a_Speed);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cThrownSnowballEntity::OnHitSolidBlock(int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace)
|
||||
{
|
||||
// TODO: Apply damage to certain mobs (blaze etc.) and anger all mobs
|
||||
|
||||
Destroy();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -78,6 +78,7 @@ protected:
|
||||
// cEntity overrides:
|
||||
virtual void Tick(float a_Dt, cChunk & a_Chunk) override;
|
||||
virtual void HandlePhysics(float a_Dt, cChunk & a_Chunk) override;
|
||||
virtual void SpawnOn(cClientHandle & a_Client) override;
|
||||
|
||||
// tolua_begin
|
||||
} ;
|
||||
@ -105,7 +106,7 @@ public:
|
||||
CLASS_PROTODEF(cArrowEntity);
|
||||
|
||||
/// Creates a new arrow with psNoPickup state and default damage modifier coeff
|
||||
cArrowEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d a_Speed);
|
||||
cArrowEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed);
|
||||
|
||||
/// Creates a new arrow as shot by a player, initializes it from the player object
|
||||
cArrowEntity(cPlayer & a_Player, double a_Force);
|
||||
@ -137,12 +138,100 @@ protected:
|
||||
/// The coefficient applied to the damage that the arrow will deal, based on the bow enchantment. 2.0 for normal arrow
|
||||
double m_DamageCoeff;
|
||||
|
||||
// cEntity overrides:
|
||||
// cProjectileEntity overrides:
|
||||
virtual void SpawnOn(cClientHandle & a_Client) override;
|
||||
|
||||
// tolua_begin
|
||||
} ;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class cThrownEggEntity :
|
||||
public cProjectileEntity
|
||||
{
|
||||
typedef cProjectileEntity super;
|
||||
|
||||
public:
|
||||
|
||||
// tolua_end
|
||||
|
||||
CLASS_PROTODEF(cThrownEggEntity);
|
||||
|
||||
cThrownEggEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed);
|
||||
|
||||
protected:
|
||||
|
||||
// tolua_end
|
||||
|
||||
// cProjectileEntity overrides:
|
||||
virtual void OnHitSolidBlock(int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace) override;
|
||||
|
||||
// tolua_begin
|
||||
|
||||
} ;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class cThrownEnderPearlEntity :
|
||||
public cProjectileEntity
|
||||
{
|
||||
typedef cProjectileEntity super;
|
||||
|
||||
public:
|
||||
|
||||
// tolua_end
|
||||
|
||||
CLASS_PROTODEF(cThrownEnderPearlEntity);
|
||||
|
||||
cThrownEnderPearlEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed);
|
||||
|
||||
protected:
|
||||
|
||||
// tolua_end
|
||||
|
||||
// cProjectileEntity overrides:
|
||||
virtual void OnHitSolidBlock(int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace) override;
|
||||
|
||||
// tolua_begin
|
||||
|
||||
} ;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class cThrownSnowballEntity :
|
||||
public cProjectileEntity
|
||||
{
|
||||
typedef cProjectileEntity super;
|
||||
|
||||
public:
|
||||
|
||||
// tolua_end
|
||||
|
||||
CLASS_PROTODEF(cThrownSnowballEntity);
|
||||
|
||||
cThrownSnowballEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed);
|
||||
|
||||
protected:
|
||||
|
||||
// tolua_end
|
||||
|
||||
// cProjectileEntity overrides:
|
||||
virtual void OnHitSolidBlock(int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace) override;
|
||||
|
||||
// tolua_begin
|
||||
|
||||
} ;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// tolua_end
|
||||
|
||||
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include "ItemLighter.h"
|
||||
#include "ItemMinecart.h"
|
||||
#include "ItemPickaxe.h"
|
||||
#include "ItemThrowable.h"
|
||||
#include "ItemRedstoneDust.h"
|
||||
#include "ItemRedstoneRepeater.h"
|
||||
#include "ItemSapling.h"
|
||||
@ -88,12 +89,15 @@ cItemHandler *cItemHandler::CreateItemHandler(int a_ItemType)
|
||||
case E_ITEM_BREWING_STAND: return new cItemBrewingStandHandler(a_ItemType);
|
||||
case E_ITEM_CAULDRON: return new cItemCauldronHandler(a_ItemType);
|
||||
case E_ITEM_DYE: return new cItemDyeHandler(a_ItemType);
|
||||
case E_ITEM_EGG: return new cItemEggHandler();
|
||||
case E_ITEM_ENDER_PEARL: return new cItemEnderPearlHandler();
|
||||
case E_ITEM_FLINT_AND_STEEL: return new cItemLighterHandler(a_ItemType);
|
||||
case E_ITEM_FLOWER_POT: return new cItemFlowerPotHandler(a_ItemType);
|
||||
case E_ITEM_REDSTONE_DUST: return new cItemRedstoneDustHandler(a_ItemType);
|
||||
case E_ITEM_REDSTONE_REPEATER: return new cItemRedstoneRepeaterHandler(a_ItemType);
|
||||
case E_ITEM_SHEARS: return new cItemShearsHandler(a_ItemType);
|
||||
case E_ITEM_SIGN: return new cItemSignHandler(a_ItemType);
|
||||
case E_ITEM_SNOWBALL: return new cItemSnowballHandler();
|
||||
case E_ITEM_SPAWN_EGG: return new cItemSpawnEggHandler(a_ItemType);
|
||||
case E_ITEM_SUGARCANE: return new cItemSugarcaneHandler(a_ItemType);
|
||||
|
||||
|
90
source/Items/ItemThrowable.h
Normal file
90
source/Items/ItemThrowable.h
Normal file
@ -0,0 +1,90 @@
|
||||
|
||||
// ItemThrowable.h
|
||||
|
||||
// Declares the itemhandlers for throwable items: eggs, snowballs and ender pearls
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class cItemThrowableHandler :
|
||||
public cItemHandler
|
||||
{
|
||||
typedef cItemHandler super;
|
||||
public:
|
||||
cItemThrowableHandler(int a_ItemType, cProjectileEntity::eKind a_ProjectileKind, double a_SpeedCoeff) :
|
||||
super(a_ItemType),
|
||||
m_ProjectileKind(a_ProjectileKind),
|
||||
m_SpeedCoeff(a_SpeedCoeff)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Dir) override
|
||||
{
|
||||
Vector3d Pos = a_Player->GetThrowStartPos();
|
||||
Vector3d Speed = a_Player->GetLookVector() * m_SpeedCoeff;
|
||||
a_World->CreateProjectile(Pos.x, Pos.y, Pos.z, m_ProjectileKind, a_Player, &Speed);
|
||||
return true;
|
||||
}
|
||||
|
||||
protected:
|
||||
cProjectileEntity::eKind m_ProjectileKind;
|
||||
double m_SpeedCoeff;
|
||||
} ;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class cItemEggHandler :
|
||||
public cItemThrowableHandler
|
||||
{
|
||||
typedef cItemThrowableHandler super;
|
||||
public:
|
||||
cItemEggHandler(void) :
|
||||
super(E_ITEM_EGG, cProjectileEntity::pkEgg, 30)
|
||||
{
|
||||
}
|
||||
} ;
|
||||
|
||||
|
||||
|
||||
|
||||
class cItemSnowballHandler :
|
||||
public cItemThrowableHandler
|
||||
{
|
||||
typedef cItemThrowableHandler super;
|
||||
|
||||
public:
|
||||
cItemSnowballHandler(void) :
|
||||
super(E_ITEM_SNOWBALL, cProjectileEntity::pkSnowball, 30)
|
||||
{
|
||||
}
|
||||
} ;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class cItemEnderPearlHandler :
|
||||
public cItemThrowableHandler
|
||||
{
|
||||
typedef cItemThrowableHandler super;
|
||||
|
||||
public:
|
||||
cItemEnderPearlHandler(void) :
|
||||
super(E_ITEM_ENDER_PEARL, cProjectileEntity::pkEnderPearl, 30)
|
||||
{
|
||||
}
|
||||
} ;
|
||||
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user