enchantments pt3 / forge pt2 - PROTOCOL BUMP
This commit is contained in:
parent
7800b9161b
commit
5b5a422249
|
@ -1120,7 +1120,8 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
|
|||
u16 index = readU16(is);
|
||||
u16 type = readU16(is);
|
||||
u16 count = readU16(is);
|
||||
l->updateItem(index,type,count);
|
||||
u16 data = readU16(is);
|
||||
l->updateItem(index,type,count,data);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -29,12 +29,12 @@
|
|||
|
||||
#include "utility.h"
|
||||
|
||||
#define PROTOCOL_VERSION 9
|
||||
#define PROTOCOL_VERSION 10
|
||||
/* the last protocol version used by 0.3.x minetest-c55 clients */
|
||||
#define PROTOCOL_DOTTHREE 3
|
||||
/* this is the oldest protocol that we will allow to connect
|
||||
* even with strict_protocol_version_checking = false */
|
||||
#define PROTOCOL_OLDEST 7
|
||||
#define PROTOCOL_OLDEST 10
|
||||
|
||||
#define PROTOCOL_ID 0x4f457403
|
||||
|
||||
|
|
|
@ -1514,4 +1514,44 @@ void content_craftitem_init()
|
|||
f->name = "mithril_bound";
|
||||
f->description = wgettext("Mithril");
|
||||
lists::add("creative",i);
|
||||
|
||||
i = CONTENT_CRAFTITEM_RUBY;
|
||||
f = &g_content_craftitem_features[i];
|
||||
f->content = i;
|
||||
f->texture = "lump_of_ruby.png";
|
||||
f->name = "lump_of_ruby";
|
||||
f->description = wgettext("Ruby");
|
||||
lists::add("creative",i);
|
||||
|
||||
i = CONTENT_CRAFTITEM_TURQUOISE;
|
||||
f = &g_content_craftitem_features[i];
|
||||
f->content = i;
|
||||
f->texture = "lump_of_turquoise.png";
|
||||
f->name = "lump_of_turquiose";
|
||||
f->description = wgettext("Turquiose");
|
||||
lists::add("creative",i);
|
||||
|
||||
i = CONTENT_CRAFTITEM_AMETHYST;
|
||||
f = &g_content_craftitem_features[i];
|
||||
f->content = i;
|
||||
f->texture = "lump_of_amethyst.png";
|
||||
f->name = "lump_of_amethyst";
|
||||
f->description = wgettext("Amethyst");
|
||||
lists::add("creative",i);
|
||||
|
||||
i = CONTENT_CRAFTITEM_SAPPHIRE;
|
||||
f = &g_content_craftitem_features[i];
|
||||
f->content = i;
|
||||
f->texture = "lump_of_sapphire.png";
|
||||
f->name = "lump_of_sapphire";
|
||||
f->description = wgettext("Sapphire");
|
||||
lists::add("creative",i);
|
||||
|
||||
i = CONTENT_CRAFTITEM_SUNSTONE;
|
||||
f = &g_content_craftitem_features[i];
|
||||
f->content = i;
|
||||
f->texture = "lump_of_sunstone.png";
|
||||
f->name = "lump_of_sunstone";
|
||||
f->description = wgettext("Sunstone");
|
||||
lists::add("creative",i);
|
||||
}
|
||||
|
|
|
@ -226,5 +226,10 @@ CraftItemFeatures & content_craftitem_features(std::string subname);
|
|||
#define CONTENT_CRAFTITEM_MITHRIL_RAW (CONTENT_CRAFTITEM_MASK | 0x7F)
|
||||
#define CONTENT_CRAFTITEM_MITHRIL_UNBOUND (CONTENT_CRAFTITEM_MASK | 0x80)
|
||||
#define CONTENT_CRAFTITEM_MITHRIL (CONTENT_CRAFTITEM_MASK | 0x81)
|
||||
#define CONTENT_CRAFTITEM_RUBY (CONTENT_CRAFTITEM_MASK | 0x8)
|
||||
#define CONTENT_CRAFTITEM_TURQUOISE (CONTENT_CRAFTITEM_MASK | 0x8)
|
||||
#define CONTENT_CRAFTITEM_AMETHYST (CONTENT_CRAFTITEM_MASK | 0x8)
|
||||
#define CONTENT_CRAFTITEM_SAPPHIRE (CONTENT_CRAFTITEM_MASK | 0x8)
|
||||
#define CONTENT_CRAFTITEM_SUNSTONE (CONTENT_CRAFTITEM_MASK | 0x8)
|
||||
|
||||
#endif
|
||||
|
|
|
@ -2938,6 +2938,34 @@ bool ForgeNodeMetadata::step(float dtime, v3s16 pos, ServerEnvironment *env)
|
|||
if (n.getContent() == CONTENT_AIR) {
|
||||
bool show_flame = false;
|
||||
if (m_show_craft) {
|
||||
InventoryItem *items[9];
|
||||
bool has_enchanted = false;
|
||||
InventoryList *clist = m_inventory->getList("craft");
|
||||
InventoryList *rlist = m_inventory->getList("craftresult");
|
||||
if (!clist || !rlist)
|
||||
return false;
|
||||
|
||||
for (u16 i=0; i<9; i++) {
|
||||
items[i] = clist->getItem(i);
|
||||
if (
|
||||
!has_enchanted
|
||||
&& items[i]
|
||||
&& (items[i]->getContent()&CONTENT_CRAFTITEM_MASK) == CONTENT_CRAFTITEM_MASK
|
||||
&& items[i]->getData() > 0
|
||||
)
|
||||
has_enchanted = true;
|
||||
}
|
||||
|
||||
if (!has_enchanted)
|
||||
return false;
|
||||
|
||||
// Get result of crafting grid
|
||||
InventoryItem *result = crafting::getResult(items);
|
||||
if (!result)
|
||||
return false;
|
||||
if (rlist->itemFits(0,result))
|
||||
show_flame = true;
|
||||
delete result;
|
||||
}else{
|
||||
InventoryList *mlist = m_inventory->getList("mithril");
|
||||
InventoryList *glist = m_inventory->getList("gem");
|
||||
|
@ -2955,6 +2983,56 @@ bool ForgeNodeMetadata::step(float dtime, v3s16 pos, ServerEnvironment *env)
|
|||
}else if (n.getContent() == CONTENT_FORGE_FIRE) {
|
||||
env->getMap().removeNodeWithEvent(abv);
|
||||
if (m_show_craft) {
|
||||
InventoryItem *items[9];
|
||||
bool has_enchanted = false;
|
||||
InventoryList *clist = m_inventory->getList("craft");
|
||||
InventoryList *rlist = m_inventory->getList("craftresult");
|
||||
if (!clist || !rlist)
|
||||
return false;
|
||||
|
||||
for (u16 i=0; i<9; i++) {
|
||||
items[i] = clist->getItem(i);
|
||||
if (
|
||||
!has_enchanted
|
||||
&& items[i]
|
||||
&& (items[i]->getContent()&CONTENT_CRAFTITEM_MASK) == CONTENT_CRAFTITEM_MASK
|
||||
&& items[i]->getData() > 0
|
||||
)
|
||||
has_enchanted = true;
|
||||
}
|
||||
|
||||
if (!has_enchanted)
|
||||
return false;
|
||||
|
||||
// Get result of crafting grid
|
||||
InventoryItem *result = crafting::getResult(items);
|
||||
if (!result)
|
||||
return false;
|
||||
|
||||
{
|
||||
u16 data = 0;
|
||||
for (u16 i=0; i<9; i++) {
|
||||
if (
|
||||
items[i]
|
||||
&& (items[i]->getContent()&CONTENT_CRAFTITEM_MASK) == CONTENT_CRAFTITEM_MASK
|
||||
&& items[i]->getData() > 0
|
||||
) {
|
||||
printf("CRAFT: pre: %X %X\n",data,items[i]->getData());
|
||||
enchantment_set(&data,items[i]->getData());
|
||||
printf("CRAFT: post: %X %X\n",data,items[i]->getData());
|
||||
}
|
||||
}
|
||||
result->setData(data);
|
||||
}
|
||||
if (!rlist->itemFits(0,result)) {
|
||||
delete result;
|
||||
return false;
|
||||
}
|
||||
|
||||
rlist->addItem(result);
|
||||
clist->decrementMaterials(1);
|
||||
|
||||
return true;
|
||||
}else{
|
||||
InventoryList *mlist = m_inventory->getList("mithril");
|
||||
InventoryList *glist = m_inventory->getList("gem");
|
||||
|
@ -3006,18 +3084,29 @@ bool ForgeNodeMetadata::nodeRemovalDisabled()
|
|||
|
||||
return false;
|
||||
}
|
||||
bool ForgeNodeMetadata::receiveFields(std::string formname, std::map<std::string, std::string> fields, Player *player)
|
||||
{
|
||||
if (fields["craft"] != "") {
|
||||
m_show_craft = true;
|
||||
}else if (fields["enchant"] != "") {
|
||||
m_show_craft = false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
std::string ForgeNodeMetadata::getDrawSpecString()
|
||||
{
|
||||
if (m_show_craft)
|
||||
return std::string("size[8,8]")+
|
||||
"list[current_name;craft;2,0;3,3;]"
|
||||
"list[current_name;craftresult;6,1;1,1;]"
|
||||
"button[3,3.2;3,1;enchant;Show Enchanting]"
|
||||
"list[current_player;main;0,3.8;8,1;0,8;]"
|
||||
"list[current_player;main;0,5;8,3;8,-1;]";
|
||||
return std::string("size[8,8]")+
|
||||
"list[current_name;mithril;1,1;1,1;]"
|
||||
"list[current_name;gem;3,1;1,1;]"
|
||||
"list[current_name;craftresult;6,1;1,1;]"
|
||||
"button[3,3.2;3,1;craft;Show Crafting]"
|
||||
"list[current_player;main;0,3.8;8,1;0,8;]"
|
||||
"list[current_player;main;0,5;8,3;8,-1;]";
|
||||
}
|
||||
|
|
|
@ -604,6 +604,7 @@ public:
|
|||
virtual void inventoryModified();
|
||||
virtual bool step(float dtime, v3s16 pos, ServerEnvironment *env);
|
||||
virtual bool nodeRemovalDisabled();
|
||||
virtual bool receiveFields(std::string formname, std::map<std::string, std::string> fields, Player *player);
|
||||
virtual std::string getDrawSpecString();
|
||||
|
||||
private:
|
||||
|
|
|
@ -64,6 +64,7 @@ static void enchantment_init()
|
|||
f->mask = (1<<(i-1));
|
||||
f->overlay = "flame";
|
||||
f->name = L"Ignis";
|
||||
f->gem = CONTENT_CRAFTITEM_SUNSTONE;
|
||||
|
||||
i = ENCHANTMENT_DONTBREAK;
|
||||
f = &enchantments[i];
|
||||
|
@ -71,6 +72,7 @@ static void enchantment_init()
|
|||
f->mask = (1<<(i-1));
|
||||
f->overlay = "dontbreak";
|
||||
f->name = L"Indomitus";
|
||||
f->gem = CONTENT_CRAFTITEM_SAPPHIRE;
|
||||
|
||||
i = ENCHANTMENT_MORE;
|
||||
f = &enchantments[i];
|
||||
|
@ -78,6 +80,7 @@ static void enchantment_init()
|
|||
f->mask = (1<<(i-1));
|
||||
f->overlay = "more";
|
||||
f->name = L"Amplius";
|
||||
f->gem = CONTENT_CRAFTITEM_TURQUOISE;
|
||||
|
||||
i = ENCHANTMENT_FAST;
|
||||
f = &enchantments[i];
|
||||
|
@ -85,6 +88,7 @@ static void enchantment_init()
|
|||
f->mask = (1<<(i-1));
|
||||
f->overlay = "fast";
|
||||
f->name = L"Velox";
|
||||
f->gem = CONTENT_CRAFTITEM_AMETHYST;
|
||||
|
||||
i = ENCHANTMENT_LONGLASTING;
|
||||
f = &enchantments[i];
|
||||
|
@ -92,7 +96,7 @@ static void enchantment_init()
|
|||
f->mask = (1<<(i-1));
|
||||
f->overlay = "longlast";
|
||||
f->name = L"Aeterna";
|
||||
f->gem = CONTENT_CRAFTITEM_QUARTZ;
|
||||
f->gem = CONTENT_CRAFTITEM_RUBY;
|
||||
|
||||
enchantment_isinit = 1;
|
||||
}
|
||||
|
@ -158,7 +162,34 @@ bool enchantment_have(uint16_t data, uint16_t enchantment)
|
|||
|
||||
bool enchantment_set(uint16_t *data, uint16_t enchantment)
|
||||
{
|
||||
return false;
|
||||
uint16_t d;
|
||||
EnchantmentInfo info;
|
||||
if (!data)
|
||||
return false;
|
||||
|
||||
if (!enchantment_get(&enchantment,&info))
|
||||
return false;
|
||||
|
||||
d = *data;
|
||||
|
||||
if ((d&info.mask) == 0) {
|
||||
*data |= info.mask;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (info.type > 2) {
|
||||
u8 l = 0;
|
||||
d = (d>>(info.type-3));
|
||||
d &= 0x0003;
|
||||
l = d;
|
||||
*data &= ~(3<<(info.type-3));
|
||||
if (l < 3) {
|
||||
l++;
|
||||
*data |= (l<<(info.type-3));
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool enchantment_enchant(uint16_t *data, content_t item)
|
||||
|
|
|
@ -470,8 +470,6 @@ std::string ToolItem::getBasename() const
|
|||
|
||||
EnchantmentInfo info;
|
||||
u16 data = m_data;
|
||||
if (m_content == CONTENT_TOOLITEM_MITHRIL_PICK)
|
||||
data = (1<<15)|(1<<3);
|
||||
while (enchantment_get(&data,&info)) {
|
||||
std::string ol = toolitem_overlay(m_content,info.overlay);
|
||||
if (ol != "")
|
||||
|
@ -1010,7 +1008,7 @@ InventoryItem * InventoryList::addItem(u32 i, InventoryItem *newitem)
|
|||
}
|
||||
}
|
||||
|
||||
void InventoryList::updateItem(u32 i, content_t type, u16 wear_count)
|
||||
void InventoryList::updateItem(u32 i, content_t type, u16 wear_count, u16 data)
|
||||
{
|
||||
if (type == CONTENT_IGNORE) {
|
||||
if (m_items[i] != NULL)
|
||||
|
@ -1028,11 +1026,12 @@ void InventoryList::updateItem(u32 i, content_t type, u16 wear_count)
|
|||
}else{
|
||||
m_items[i]->setCount(wear_count);
|
||||
}
|
||||
m_items[i]->setData(data);
|
||||
return;
|
||||
}
|
||||
delete m_items[i];
|
||||
}
|
||||
m_items[i] = InventoryItem::create(type,wear_count,wear_count);
|
||||
m_items[i] = InventoryItem::create(type,wear_count,wear_count,data);
|
||||
}
|
||||
|
||||
bool InventoryList::itemFits(const u32 i, const InventoryItem *newitem)
|
||||
|
|
|
@ -515,22 +515,25 @@ private:
|
|||
class InventoryDiffData
|
||||
{
|
||||
public:
|
||||
InventoryDiffData(u32 i, content_t t, u16 c):
|
||||
InventoryDiffData(u32 i, content_t t, u16 c, u16 d):
|
||||
index(i),
|
||||
type(t),
|
||||
wear_count(c)
|
||||
wear_count(c),
|
||||
data(d)
|
||||
{
|
||||
}
|
||||
InventoryDiffData():
|
||||
index(0),
|
||||
type(CONTENT_IGNORE),
|
||||
wear_count(0)
|
||||
wear_count(0),
|
||||
data(0)
|
||||
{
|
||||
}
|
||||
|
||||
u32 index;
|
||||
content_t type;
|
||||
u16 wear_count;
|
||||
u16 data;
|
||||
};
|
||||
|
||||
class InventoryDiff
|
||||
|
@ -550,22 +553,22 @@ public:
|
|||
m_data.clear();
|
||||
}
|
||||
|
||||
void add(std::string list, u32 index, content_t type, u16 count_wear)
|
||||
void add(std::string list, u32 index, content_t type, u16 count_wear, u16 data)
|
||||
{
|
||||
m_data[list][index] = InventoryDiffData(index,type,count_wear);
|
||||
m_data[list][index] = InventoryDiffData(index,type,count_wear,data);
|
||||
}
|
||||
|
||||
void add(std::string list, u32 index, InventoryItem *item)
|
||||
{
|
||||
if (item == NULL) {
|
||||
add(list,index,CONTENT_IGNORE,0);
|
||||
add(list,index,CONTENT_IGNORE,0,0);
|
||||
}else if (
|
||||
(item->getContent()&CONTENT_TOOLITEM_MASK) == CONTENT_TOOLITEM_MASK
|
||||
|| (item->getContent()&CONTENT_CLOTHESITEM_MASK) == CONTENT_CLOTHESITEM_MASK
|
||||
) {
|
||||
add(list,index,item->getContent(),item->getWear());
|
||||
add(list,index,item->getContent(),item->getWear(),item->getData());
|
||||
}else{
|
||||
add(list,index,item->getContent(),item->getCount());
|
||||
add(list,index,item->getContent(),item->getCount(),item->getData());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -641,7 +644,7 @@ public:
|
|||
InventoryItem * addItem(u32 i, InventoryItem *newitem);
|
||||
|
||||
// Updates item type/count/wear
|
||||
void updateItem(u32 i, content_t type, u16 wear_count);
|
||||
void updateItem(u32 i, content_t type, u16 wear_count, u16 data);
|
||||
|
||||
// Checks whether the item could be added to the given slot
|
||||
bool itemFits(const u32 i, const InventoryItem *newitem);
|
||||
|
|
|
@ -4996,6 +4996,7 @@ void Server::SendInventory(u16 peer_id, bool full)
|
|||
writeU16(os,i->second.index);
|
||||
writeU16(os,i->second.type);
|
||||
writeU16(os,i->second.wear_count);
|
||||
writeU16(os,i->second.data);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue