add cauldron, make tea and coffee craftable

This commit is contained in:
darkrose 2015-06-06 06:41:42 +10:00
parent 4ce8d3ef83
commit 3a0330580a
14 changed files with 358 additions and 2 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 785 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 506 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 292 B

View File

@ -256,6 +256,16 @@ void setURecipe(u16 input, u16 result)
};
setRecipe(r,result,1);
}
// seven input in a U yields one result
void setDeepURecipe(u16 input, u16 result)
{
u16 r[9] = {
input, CONTENT_IGNORE, input,
input, CONTENT_IGNORE, input,
input, input, input
};
setRecipe(r,result,1);
}
// three input in a horizontal row yields one result
void setRow1Recipe(u16 input, u16 result)
{

View File

@ -206,6 +206,8 @@ namespace crafting {
void setVRecipe(u16 input, u16 result, u16 count=1);
// five input in a u yields one result
void setURecipe(u16 input, u16 result);
// seven input in a U yields one result
void setDeepURecipe(u16 input, u16 result);
// three input in a horizontal row yields one result
void setRow1Recipe(u16 input, u16 result);
// three input in a horizontal row yields two result

View File

@ -1365,6 +1365,7 @@ void content_craftitem_init()
f->texture = "steel_bottle.png";
f->name = "tea_drink";
f->description = wgettext("Tea");
f->stackable = false;
f->drop_count = 1;
f->consumable = true;
f->hunger_effect = 3;
@ -1372,6 +1373,7 @@ void content_craftitem_init()
f->cold_effect = 300;
f->energy_effect = 10;
f->onuse_replace_item = CONTENT_CRAFTITEM_STEEL_BOTTLE;
crafting::set1over1Recipe(CONTENT_CRAFTITEM_TEA_LEAVES,CONTENT_CRAFTITEM_STEEL_BOTTLE_WATER,CONTENT_CRAFTITEM_TEA);
lists::add("creative",i);
i = CONTENT_CRAFTITEM_COFFEE_BEANS;
@ -1393,6 +1395,7 @@ void content_craftitem_init()
f->texture = "steel_bottle.png";
f->name = "coffee_drink";
f->description = wgettext("Coffee");
f->stackable = false;
f->drop_count = 1;
f->consumable = true;
f->hunger_effect = 2;
@ -1400,6 +1403,7 @@ void content_craftitem_init()
f->cold_effect = 10;
f->energy_effect = 300;
f->onuse_replace_item = CONTENT_CRAFTITEM_STEEL_BOTTLE;
crafting::set1over1Recipe(CONTENT_CRAFTITEM_COFFEE_BEANS,CONTENT_CRAFTITEM_STEEL_BOTTLE_WATER,CONTENT_CRAFTITEM_COFFEE);
lists::add("creative",i);
i = CONTENT_CRAFTITEM_STEEL_BOTTLE;
@ -1419,4 +1423,33 @@ void content_craftitem_init()
}
lists::add("craftguide",i);
lists::add("creative",i);
i = CONTENT_CRAFTITEM_GLASS_BOTTLE_WATER;
f = &g_content_craftitem_features[i];
f->content = i;
f->texture = "drink_water.png^glass_bottle.png";
f->name = "water_drink";
f->description = wgettext("Bottle of Water");
f->stackable = false;
f->drop_count = 1;
f->consumable = true;
f->hunger_effect = 1;
f->health_effect = 1;
f->onuse_replace_item = CONTENT_CRAFTITEM_GLASS_BOTTLE;
lists::add("creative",i);
i = CONTENT_CRAFTITEM_STEEL_BOTTLE_WATER;
f = &g_content_craftitem_features[i];
f->content = i;
f->texture = "steel_bottle.png";
f->name = "hotwater_drink";
f->description = wgettext("Bottle of Hot Water");
f->stackable = false;
f->drop_count = 1;
f->consumable = true;
f->hunger_effect = 1;
f->health_effect = 1;
f->cold_effect = 5;
f->onuse_replace_item = CONTENT_CRAFTITEM_STEEL_BOTTLE;
lists::add("creative",i);
}

View File

@ -211,5 +211,7 @@ CraftItemFeatures & content_craftitem_features(std::string subname);
#define CONTENT_CRAFTITEM_COFFEE_BEANS (CONTENT_CRAFTITEM_MASK | 0x7A)
#define CONTENT_CRAFTITEM_COFFEE (CONTENT_CRAFTITEM_MASK | 0x7B)
#define CONTENT_CRAFTITEM_STEEL_BOTTLE (CONTENT_CRAFTITEM_MASK | 0x7C)
#define CONTENT_CRAFTITEM_STEEL_BOTTLE_WATER (CONTENT_CRAFTITEM_MASK | 0x7D)
#define CONTENT_CRAFTITEM_GLASS_BOTTLE_WATER (CONTENT_CRAFTITEM_MASK | 0x7E)
#endif

View File

@ -181,8 +181,8 @@ MapNode mapnode_translate_to_internal(MapNode n_from, u8 version);
#define CONTENT_COUCH_INNER_BLACK 0x863
#define CONTENT_COUCH_OUTER_BLACK 0x864
#define CONTENT_COUCH_CHAIR_BLACK 0x865
// FREE 866-87F
#define CONTENT_CAULDRON 0x866
// FREE 867-87F
#define CONTENT_FLAG 0x870
#define CONTENT_FLAG_BLUE 0x871
#define CONTENT_FLAG_GREEN 0x872

View File

@ -1950,4 +1950,25 @@ void content_mapnode_special(bool repeat)
f->suffocation_per_second = 0;
if (f->initial_metadata == NULL)
f->initial_metadata = new ParcelNodeMetadata();
i = CONTENT_CAULDRON;
f = &content_features(i);
f->description = wgettext("Cauldron");
f->setAllTextures("cauldron_outer.png");
f->setAllMetaTextures("cauldron_inner.png");
f->setMetaTexture(0,"water.png");
f->draw_type = CDT_NODEBOX_META;
f->type = CMT_STONE;
f->hardness = 3.0;
f->solidness = 0;
f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
content_nodebox_cauldron(f);
f->setInventoryTextureNodeBox(i,"cauldron_outer.png", "cauldron_outer.png", "cauldron_outer.png");
if (f->initial_metadata == NULL)
f->initial_metadata = new CauldronNodeMetadata();
crafting::setDeepURecipe(CONTENT_CRAFTITEM_STEEL_INGOT,CONTENT_CAULDRON);
f->pressure_type = CST_SOLID;
lists::add("craftguide",i);
lists::add("creative",i);
f->suffocation_per_second = 0;
}

View File

@ -1487,3 +1487,34 @@ void content_nodebox_parcel(ContentFeatures *f)
v3s16(0,-10,0),v3f(0,0,0),-0.0625*BS,-0.1875*BS,-0.0625*BS,0.,-0.125*BS,0.125*BS
));
}
void content_nodebox_cauldron(ContentFeatures *f)
{
f->setNodeBox(NodeBox(
-0.375*BS,-0.125*BS,-0.375*BS,0.375*BS,-0.0625*BS,0.375*BS
));
f->addNodeBox(NodeBox(
-0.4375*BS,-0.5*BS,-0.4375*BS,-0.3125*BS,-0.125*BS,-0.3125*BS
));
f->addNodeBox(NodeBox(
0.3125*BS,-0.5*BS,-0.4375*BS,0.4375*BS,-0.125*BS,-0.3125*BS
));
f->addNodeBox(NodeBox(
-0.4375*BS,-0.5*BS,0.3125*BS,-0.3125*BS,-0.125*BS,0.4375*BS
));
f->addNodeBox(NodeBox(
0.3125*BS,-0.5*BS,0.3125*BS,0.4375*BS,-0.125*BS,0.4375*BS
));
f->addNodeBox(NodeBox(
-0.4375*BS,-0.125*BS,-0.4375*BS,-0.375*BS,0.5*BS,0.4375*BS
));
f->addNodeBox(NodeBox(
0.375*BS,-0.125*BS,-0.4375*BS,0.4375*BS,0.5*BS,0.4375*BS
));
f->addNodeBox(NodeBox(
-0.375*BS,-0.125*BS,0.375*BS,0.375*BS,0.5*BS,0.4375*BS
));
f->addNodeBox(NodeBox(
-0.375*BS,-0.125*BS,-0.4375*BS,0.375*BS,0.5*BS,-0.375*BS
));
}

View File

@ -66,5 +66,6 @@ void content_nodebox_youngtree(ContentFeatures *f);
void content_nodebox_flag(ContentFeatures *f);
void content_nodebox_flower_pot(ContentFeatures *f);
void content_nodebox_parcel(ContentFeatures *f);
void content_nodebox_cauldron(ContentFeatures *f);
#endif

View File

@ -2383,6 +2383,191 @@ bool ClockNodeMetadata::step(float dtime, v3s16 pos, ServerEnvironment *env)
return true;
}
/*
CauldronNodeMetadata
*/
// Prototype
CauldronNodeMetadata proto_CauldronNodeMetadata;
CauldronNodeMetadata::CauldronNodeMetadata():
m_water_level(0),
m_water_heated(false),
m_water_hot(false),
m_fuel_time(0.0),
m_src_time(0.0),
m_cool_time(0.0)
{
NodeMetadata::registerType(typeId(), create);
m_inventory = new Inventory();
m_inventory->addList("fuel", 1);
}
CauldronNodeMetadata::~CauldronNodeMetadata()
{
delete m_inventory;
}
u16 CauldronNodeMetadata::typeId() const
{
return CONTENT_CAULDRON;
}
NodeMetadata* CauldronNodeMetadata::clone()
{
CauldronNodeMetadata *d = new CauldronNodeMetadata();
d->m_fuel_time = m_fuel_time;
d->m_src_time = m_src_time;
d->m_water_level = m_water_level;
d->m_water_heated = m_water_heated;
d->m_water_hot = m_water_hot;
*d->m_inventory = *m_inventory;
return d;
}
NodeMetadata* CauldronNodeMetadata::create(std::istream &is)
{
CauldronNodeMetadata *d = new CauldronNodeMetadata();
d->m_inventory->deSerialize(is);
int temp;
is>>temp;
d->m_fuel_time = (float)temp/10;
is>>temp;
d->m_src_time = (float)temp/10;
is>>temp;
d->m_water_level = temp;
is>>temp;
d->m_water_heated = !!temp;
is>>temp;
d->m_water_hot = !!temp;
return d;
}
void CauldronNodeMetadata::serializeBody(std::ostream &os)
{
m_inventory->serialize(os);
os<<itos(m_fuel_time*10)<<" ";
os<<itos(m_src_time*10)<<" ";
os<<itos(m_water_level)<<" ";
os<<itos(m_water_heated ? 1 : 0)<<" ";
os<<itos(m_water_hot ? 1 : 0)<<" ";
}
std::wstring CauldronNodeMetadata::infoText()
{
if (m_fuel_time)
return wgettext("Cauldron is active");
if (m_water_level) {
if (m_water_hot)
return wgettext("Cauldron is boiling");
if (m_water_heated)
return wgettext("Cauldron is cool");
}else{
return wgettext("Cauldron is empty");
}
return wgettext("Cauldron is out of fuel");
}
bool CauldronNodeMetadata::nodeRemovalDisabled()
{
/*
Disable removal if not empty
*/
InventoryList *list = m_inventory->getList("fuel");
if (list && list->getUsedSlots() > 0)
return true;
if (m_water_level)
return true;
return false;
}
void CauldronNodeMetadata::inventoryModified()
{
infostream<<"Cauldron inventory modification callback"<<std::endl;
}
bool CauldronNodeMetadata::step(float dtime, v3s16 pos, ServerEnvironment *env)
{
if (m_fuel_time > 0.0) {
if (!m_water_heated)
m_src_time += dtime;
m_fuel_time -= dtime;
}
bool should_heat = false;
if (m_water_level) {
if (m_water_hot) {
m_cool_time -= dtime;
if (m_cool_time <= 0.0)
m_water_hot = false;
}else if (!m_water_heated) {
m_cool_time = 120.0;
if (m_src_time < 2.0) {
should_heat = true;
}else{
m_water_hot = true;
m_water_heated = true;
m_src_time = 0.0;
}
}
}else{
m_water_hot = false;
m_water_heated = false;
}
if (should_heat && m_fuel_time <= 0.0) {
InventoryList *list = m_inventory->getList("fuel");
InventoryItem *fitem;
if (list && list->getUsedSlots() > 0 && (fitem = list->getItem(0)) != NULL && fitem->isFuel()) {
if ((fitem->getContent()&CONTENT_CRAFTITEM_MASK) == CONTENT_CRAFTITEM_MASK) {
m_fuel_time = ((CraftItem*)fitem)->getFuelTime();
}else if ((fitem->getContent()&CONTENT_TOOLITEM_MASK) == CONTENT_TOOLITEM_MASK) {
m_fuel_time = ((ToolItem*)fitem)->getFuelTime();
}else{
m_fuel_time = ((MaterialItem*)fitem)->getFuelTime();
}
content_t c = fitem->getContent();
list->decrementMaterials(1);
if (c == CONTENT_TOOLITEM_STEELBUCKET_LAVA)
list->addItem(0,new ToolItem(CONTENT_TOOLITEM_STEELBUCKET,0));
return true;
}
}
return false;
}
std::string CauldronNodeMetadata::getDrawSpecString()
{
return
std::string("size[8,7]"
"label[1,0.5;")+gettext("Add fuel, then punch to incinerate wielded item")+"]"
"label[3.5,1.5;Fuel]"
"list[current_name;fuel;4,1;1,1;]"
"list[current_player;main;0,3;8,4;]";
}
std::vector<NodeBox> CauldronNodeMetadata::getNodeBoxes(MapNode &n) {
std::vector<NodeBox> boxes;
boxes.clear();
if (m_fuel_time)
boxes.push_back(NodeBox(-0.125*BS,-0.5*BS,-0.125*BS,0.125*BS,-0.25*BS,0.125*BS));
if (m_water_level) {
switch (m_water_level) {
case 1:
boxes.push_back(NodeBox(-0.375*BS,-0.0625*BS,-0.375*BS,0.375*BS,0.0625*BS,0.375*BS));
break;
case 2:
boxes.push_back(NodeBox(-0.375*BS,-0.0625*BS,-0.375*BS,0.375*BS,0.1875*BS,0.375*BS));
break;
case 3:
boxes.push_back(NodeBox(-0.375*BS,-0.0625*BS,-0.375*BS,0.375*BS,0.3125*BS,0.375*BS));
break;
default:
boxes.push_back(NodeBox(-0.375*BS,-0.0625*BS,-0.375*BS,0.375*BS,0.4375*BS,0.375*BS));
break;
}
}
return transformNodeBox(n,boxes);
}
/*
CircuitNodeMetadata
*/

View File

@ -529,6 +529,35 @@ private:
u16 m_time;
};
class CauldronNodeMetadata : public NodeMetadata
{
public:
CauldronNodeMetadata();
~CauldronNodeMetadata();
virtual u16 typeId() const;
virtual NodeMetadata* clone();
static NodeMetadata* create(std::istream &is);
virtual void serializeBody(std::ostream &os);
virtual std::wstring infoText();
virtual Inventory* getInventory() {return m_inventory;}
virtual void inventoryModified();
virtual bool step(float dtime, v3s16 pos, ServerEnvironment *env);
virtual bool nodeRemovalDisabled();
virtual std::string getDrawSpecString();
virtual std::vector<NodeBox> getNodeBoxes(MapNode &n);
u8 m_water_level;
bool m_water_heated;
bool m_water_hot;
private:
Inventory *m_inventory;
float m_fuel_time;
float m_src_time;
float m_cool_time;
};
class CircuitNodeMetadata : public NodeMetadata
{
public:

View File

@ -2879,6 +2879,48 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
meta->energise(energy,p_under,p_under,p_under);
}
}
}else if (selected_content == CONTENT_CAULDRON) {
CauldronNodeMetadata *cmeta = (CauldronNodeMetadata*)m_env.getMap().getNodeMetadata(p_under);
if (!cmeta)
return;
if (wielded_tool_features.type == TT_BUCKET) {
if (cmeta->m_water_level) {
}
}else if (wielded_tool_features.type == TT_SPECIAL) {
if (
!cmeta->m_water_level
&& wielded_tool_features.onplace_node == CONTENT_WATERSOURCE
&& wielded_tool_features.onplace_replace_item != CONTENT_IGNORE
) {
InventoryItem *itm = InventoryItem::create(wielded_tool_features.onplace_replace_item,1,0);
InventoryList *mlist = player->inventory.getList("main");
InventoryItem *old = mlist->changeItem(item_i,itm);
if (old)
delete old;
cmeta->m_water_level = 4;
SendInventory(player->peer_id);
}
}else if (wieldcontent == CONTENT_CRAFTITEM_STEEL_BOTTLE) {
if (cmeta->m_water_level && cmeta->m_water_hot && wielditem->getCount() == 1) {
InventoryItem *itm = InventoryItem::create(CONTENT_CRAFTITEM_STEEL_BOTTLE_WATER,1,0);
InventoryList *mlist = player->inventory.getList("main");
InventoryItem *old = mlist->changeItem(item_i,itm);
if (old)
delete old;
cmeta->m_water_level--;
SendInventory(player->peer_id);
}
}else if (wieldcontent == CONTENT_CRAFTITEM_GLASS_BOTTLE) {
if (cmeta->m_water_level && cmeta->m_water_heated && !cmeta->m_water_hot && wielditem->getCount() == 1) {
InventoryItem *itm = InventoryItem::create(CONTENT_CRAFTITEM_GLASS_BOTTLE_WATER,1,0);
InventoryList *mlist = player->inventory.getList("main");
InventoryItem *old = mlist->changeItem(item_i,itm);
if (old)
delete old;
cmeta->m_water_level--;
SendInventory(player->peer_id);
}
}
}else if (selected_content == CONTENT_INCINERATOR_ACTIVE) {
NodeMetadata *meta = m_env.getMap().getNodeMetadata(p_under);
if (!meta)