Recycling broken tools

User avatar
Hamlet
Member
 
Posts: 625
Joined: Sat Jul 29, 2017 21:09
Location: Lombardy, Italy
GitHub: h4ml3t
IRC: H4mlet

Recycling broken tools

by Hamlet » Fri Sep 27, 2019 17:13

I was thinking that when a tool breaks it should be replaced someway by raw materials that could be reused.

Example:
Wooden pick breaks -> it turns into wood sticks/pieces
Steel pick breaks -> it turns into raw metal and wood sticks/pieces

Of course it should not be a 1:1 conversion, the raw materials should always be less than the amount used to craft the tool.
Example: steel pick = 3 steel ingots + 2 sticks -> Breaks and turns into -> 2 raw steel pieces and 1 stick

So you could smelt the raw metal into a new ingot, etc.

This should add to realism and allow to reuse "precious" materials.

A quick search on the mods forums didn't gave me any results besides Steel, a mod from 2013.

Anyone interested in developing a mod which implements this concept?
 

User avatar
duane
Member
 
Posts: 1591
Joined: Wed Aug 19, 2015 19:11
Location: Oklahoma City
GitHub: duane-r

Re: Recycling broken tools

by duane » Sat Sep 28, 2019 06:07

That sounds cool, but it would change play balance a lot. I'd be worried that there wouldn't be enough effort involved in making armor or other more complicated constructions (assuming you applied it everywhere). And some items already have repair recipes, so this would be a bit redundant for them.

Also, most of the time when I break a pick, my inventory is full or nearly full. You might want to drop the scrap items.
Believe in people and you don't need to believe anything else.
 

User avatar
Hamlet
Member
 
Posts: 625
Joined: Sat Jul 29, 2017 21:09
Location: Lombardy, Italy
GitHub: h4ml3t
IRC: H4mlet

Re: Recycling broken tools

by Hamlet » Sat Sep 28, 2019 09:56

duane wrote:That sounds cool, but it would change play balance a lot. I'd be worried that there wouldn't be enough effort involved in making armor or other more complicated constructions (assuming you applied it everywhere).


Good point, but also consider that actually the gameplay is not that balanced for other reasons: NewPlayer joins SomeServer, he starts digging a tunnel going downwards until he finds iron, then he digs deeper until he finds mese and diamonds. Rather soon he has a full diamond armor/weapons/tool set.
That kind of "player" usually is just a griefer, which later just spends his time picking on regular players - usually with iron armors and tools - killing them again and again.
So, yeah: NewPlayer now would just have to recycle metal scraps instead than digging tunnels. Alas! From my point of view it does not change things that much: smart asses and griefers will keep doing their stuff anyway.

duane wrote:And some items already have repair recipes, so this would be a bit redundant for them.


The only repair recipes I know of, require crafting a new tool to be used as patch on the worn tool. E.g. worn pickaxe + less worn pickaxe = almost brand new pickaxe.
Thus you actually need 6 steel ingots for 2 pickaxes, that's different from recycling metal scraps from a broken pickaxe, i.e. getting - some - materials from your previous tool instead than having to search for - all of - them.

duane wrote:Also, most of the time when I break a pick, my inventory is full or nearly full. You might want to drop the scrap items.


That's another good point.
Such a mod should have at least two settings:
1 - percentage of scrap material to be dropped; 100%, 50%, etc.
2 - where to place the scrap items; inventory, drop on ground, both.
 

ThorfinnS
Member
 
Posts: 188
Joined: Mon Feb 25, 2019 22:05
GitHub: ThorfinnS

Re: Recycling broken tools

by ThorfinnS » Sun Sep 29, 2019 22:59

My kids (not mine, actually; I'm just running an after school program to help kids learn to code) implemented smelting of tools and 3d armor. Feel free to take whatever you like from it.

https://github.com/ThorfinnS/ts_tweaks

It's coded to make it easy to change if someone decided to make tools out of other metals. Or even new tools. So long as they went with standard naming conventions...
 

User avatar
Hamlet
Member
 
Posts: 625
Joined: Sat Jul 29, 2017 21:09
Location: Lombardy, Italy
GitHub: h4ml3t
IRC: H4mlet

Re: Recycling broken tools

by Hamlet » Mon Sep 30, 2019 08:45

ThorfinnS wrote:My kids (not mine, actually; I'm just running an after school program to help kids learn to code) implemented smelting of tools and 3d armor.


This is another interesting feature, thanks for sharing it: one could recycle their unused things for other uses instead of stashing them in some chest; e.g. "now that I've a diamond armor I could smelt that Iron/Bronze/etc. one to build something else".

I would only add a "cap" to the newly obtained materials, depending on the status of the input item; i.e. if I smelt a brand new chestplate (recipe requires: 8 metal ingots) I'll get 8 metal ingots, while if I smelt an half worn chestplate I'll get only half of them. Basically: the more worn the item is, the less recycled materials you will get.

Seems fair, doesn't it?
 

User avatar
duane
Member
 
Posts: 1591
Joined: Wed Aug 19, 2015 19:11
Location: Oklahoma City
GitHub: duane-r

Re: Recycling broken tools

by duane » Mon Sep 30, 2019 09:28

It would be really neat if the game had a field for what a tool becomes when it breaks, which if left as nil just results in the current behavior of its disappearing. Then you could easily specify broken versions of everything to recycle. It could have the same format as node drops...
Believe in people and you don't need to believe anything else.
 

User avatar
Hamlet
Member
 
Posts: 625
Joined: Sat Jul 29, 2017 21:09
Location: Lombardy, Italy
GitHub: h4ml3t
IRC: H4mlet

Re: Recycling broken tools

by Hamlet » Mon Sep 30, 2019 11:48

After reading the lua_api.txt, some testing with a wooden pick, and some snooping in other people's code - of course -, eventually I came up with this:

(To be placed at bottom of a "minetest.register_tool")

CC0
Code: Select all
--[[
   "Tools use a wear (damage) value ranging from 0 to 65535.
   The   value 0 is the default and is used for unworn tools.
   The values 1 to 65535 are used for worn tools, where a
   higher value stands for   a higher wear.
   Non-tools always have a wear value of 0."
   Source: lua_api.txt at line 1352 (Minetest v5.0.1)
--]]

after_use = function(itemstack, user, node, digparams)
   
   -- This adds the default wear amount.
   -- Source: lua_api.txt at line 5907 (Minetest v5.0.1)
   itemstack:add_wear(digparams.wear)
   
   -- If the tool isn't broken then return the updated item.
   if itemstack:get_wear() > 0 then
      --print(itemstack:get_wear())
      return itemstack
   
   -- If the tool is broken then replace it with something else.
   else
      --print(itemstack:get_wear())
      --Note: the above would return "0".
      itemstack:replace("default:dirt")
      return itemstack

   end
end


itemstack:replace() can be either an itemstring or a table (lua_api.txt at line 4949),
therefore one could define something like this:

Pseudocode (thank you BrunoMine for this):
Code: Select all
itemstack:replace({
   name = "mod_name:scrap_thing",
   count = random_amount,
   etc.
})


As Duane said, it would be nice if it was a builtin function, but as you can see it isn't that hard to achieve it in another way.

To sum up, an overrider for tools, to implement scrap materials; and craft recipes to smelt non-broken items.
 

ThorfinnS
Member
 
Posts: 188
Joined: Mon Feb 25, 2019 22:05
GitHub: ThorfinnS

Re: Recycling broken tools

by ThorfinnS » Mon Sep 30, 2019 14:08

Hamlet wrote:I would only add a "cap" to the newly obtained materials, depending on the status of the input item; i.e. if I smelt a brand new chestplate (recipe requires: 8 metal ingots) I'll get 8 metal ingots, while if I smelt an half worn chestplate I'll get only half of them. Basically: the more worn the item is, the less recycled materials you will get.

Seems fair, doesn't it?
Yeah. I suggested the same thing, and I was sure Sean put that in. I'll check this afternoon. Looks like what's online is not the latest version.

Take a look at toolranks, too. I've seen others tweak "after_use" in a way that makes tr hard to support. See unique ores and random ores.

[EDIT]
Thinking a little more on it, I think he just coded in a fraction recoverable. Just enter .7 in the settingytpes.txt for 70% smelt efficiency. The problem was that unique ores tools would have different wear potential than default metals, and that some unique ores were actually not ores but crystals more like diamond and mese, that he did not want to be smeltable.
[/EDIT]
 

User avatar
Hamlet
Member
 
Posts: 625
Joined: Sat Jul 29, 2017 21:09
Location: Lombardy, Italy
GitHub: h4ml3t
IRC: H4mlet

Re: Recycling broken tools

by Hamlet » Mon Sep 30, 2019 18:14

I'm working on it:

Image

:-)
I'm quite satisfied so far, soon I'll upload it on git.

Attached: alpha version.
Attachments
recycleage.zip
(5.89 KiB) Downloaded 1 time
recycleage.jpg
(54.59 KiB) Not downloaded yet
 

User avatar
Hamlet
Member
 
Posts: 625
Joined: Sat Jul 29, 2017 21:09
Location: Lombardy, Italy
GitHub: h4ml3t
IRC: H4mlet

Re: Recycling broken tools

by Hamlet » Sun Oct 27, 2019 15:56

So I've been thinking about how to actually apply the recycling concept to other items, i.e. not tools., e.g. armors.

The overall idea is not yet completely clear, but so far I think it's good enough; I'll use an example to explain it.

- We've got a steel chestplate that we do not use anymore, so we take it and place it into the crafting grid.
- The output slot will give us X metal scraps depending on a couple of factors:

1) How much worn the chestplate is.
2) If we are using the Anvil mod, which allows to repair anything that uses a "wear" field.

If we are not using the Anvil mod, then the output slot will give a variable amount of metal scraps.
If we are using the Anvil mod, then the output amount will be fixed.

My reasoning has been:
An almost broken chestplate would realistically give less material than a brand new one; let's think of an almost broken one as thin as a paper sheet for simplicity's sake.
Thus the variable output amount.

On the other hand, repairing it with an anvil would require no new materials (i.e. almost no effort): we could grab the almost broken chestplate, repair it to "brand new" state and then recycle it getting the maximum amount of scrap metals.
This sounds like cheating to me.

So, to sum up things, I think I'll do as follows:
Create a global function (an API) for Re-Cycle Age allowing third party mod developers to make their items (not tools, things like armors) register a disassembling recipe.

Ideally something really simple like:
Code: Select all
recycleage.disassemble("modname:itemname", scrap_material, max_output)


The function will check if Anvil is installed, then depending on this it will proceed in two different ways:
- If Anvil is not installed it will use the argument "max output" to scale the amount of scrap metals to be given, depending on the item's wear.
- If Anvil is installed it will use "max_output" as it is.

Note: about the scaling factor, I still have to think about it.
I think I'll adjust it while testing the function, ideally its range should be something like: if the item is brand new then "max_output", if the item is about to break then just "1 metal scrap".

I'd like to hear your feedback, thoughts, etc. ... I could have forgot something or not having taken in due consideration something else.
Brainstorming is good, more brains == multiple core processors.
:)
 

ThorfinnS
Member
 
Posts: 188
Joined: Mon Feb 25, 2019 22:05
GitHub: ThorfinnS

Re: Recycling broken tools

by ThorfinnS » Sun Oct 27, 2019 19:45

Hamlet wrote:...repairing it with an anvil would require no new materials (i.e. almost no effort): we could grab the almost broken chestplate, repair it to "brand new" state and then recycle it getting the maximum amount of scrap metals.
This sounds like cheating to me.
The conclusion is that repairing is cheating.

Hamlet wrote:Ideally something really simple like:
Code: Select all
recycleage.disassemble("modname:itemname", scrap_material, max_output)
Think about things like steel ladders, where 15 ladder sections are crafted from 7 bars. We just chose to call it 2 sections merge into one ingot's worth of scrap. But there are other goofy recipes to consider as well.

Hamlet wrote:Note: about the scaling factor, I still have to think about it.
Ours is user-defined in settingtypes.txt, default to 0.7. Right now we are using max(1,int(0.7*input materials)) So 3d armor's boots returns 2, helm returns 3. Buckets return 2. Obviously, we had to use an intermediate step for the aforementioned steel ladders.
 

User avatar
Hamlet
Member
 
Posts: 625
Joined: Sat Jul 29, 2017 21:09
Location: Lombardy, Italy
GitHub: h4ml3t
IRC: H4mlet

Re: Recycling broken tools

by Hamlet » Sun Oct 27, 2019 20:53

ThorfinnS wrote:
Hamlet wrote:Ideally something really simple like:
Code: Select all
recycleage.disassemble("modname:itemname", scrap_material, max_output)
Think about things like steel ladders, where 15 ladder sections are crafted from 7 bars. We just chose to call it 2 sections merge into one ingot's worth of scrap. But there are other goofy recipes to consider as well.
Hamlet wrote:Note: about the scaling factor, I still have to think about it.
Ours is user-defined in settingtypes.txt, default to 0.7. Right now we are using max(1,int(0.7*input materials)) So 3d armor's boots returns 2, helm returns 3. Buckets return 2. Obviously, we had to use an intermediate step for the aforementioned steel ladders.


Thank you, notes taken, I'm working on it. It turns out it is a bit trickier than what I expected, but eventually I'll sort it out. :)

ThorfinnS wrote:
Hamlet wrote:...repairing it with an anvil would require no new materials (i.e. almost no effort): we could grab the almost broken chestplate, repair it to "brand new" state and then recycle it getting the maximum amount of scrap metals.
This sounds like cheating to me.
The conclusion is that repairing is cheating.


Well, since you bring up the topic...
Laughs out loud.
Ok, I wrote a textwall. Please don't take what follows personally, it's just my point of view on the actual situation (situation that I am trying to change at least for my gaming experience). :)

Method #1 - Minetest Game's default:
I've got a pickaxe, I smash it around, it loses pieces.
I take another pickaxe, I use it as patch for the former pickaxe.
I've got a less or more repaired pickaxe.

Method #2 - Anvil mod:
I've got a pickaxe, I smash it around, it loses pieces.
I put it on an anvil, I smash it with an hammer.
The hammer replaces the lost pieces of my pickaxe.

In fact, the anvil has the ability of replacing lost matter.
Unless smashing a pickaxe on stone does not make it lose pieces.

It can repair one "Anvil Hammer" with another one (unless you toggle that option off), virtually making a couple of anvil hammers ethernal.
It could refill "Thirst" mod's steelcans, and it could regenerate wasted "Hardtorch" torches.
Probably it can recharge powered tools, like digging laser guns and alike.

Basically if <insert_name_here> has a "wear" rating, the anvil allows you to reset it.

My point is: if we were using it on a pencil, so used that one could barely hold it, the anvil would regrow it to its former dimension.

So, repairing is not cheating in itself: it depends on how one can do it.

This said, I've used the Anvil mod since the first days of my game (Hamlet's Quest), as I consider it a valid mod.

But in my opinion nowadays it should do what "Toolranks" is doing: tempering.
Hammering a metal beam tempers it, so why not?
Make it temper ingots from where people then can craft longer lasting tools.
The more time you spend hammering (experience gain), the stronger the tempering will be.

But I already hear someone saying: "I don't want to spend half my life hammering on a metal beam."

Well, to each one its own, isn't it?
I'm more the kind of hardcore gamer, I won't push my tastes on others, but I won't even pretend that what said above is realistic for a game.

[humor]Long Live to the Anvil, which grants ethernal tools only with a few hammer hits.[/humor]
:DDD
 

ThorfinnS
Member
 
Posts: 188
Joined: Mon Feb 25, 2019 22:05
GitHub: ThorfinnS

Re: Recycling broken tools

by ThorfinnS » Mon Oct 28, 2019 15:15

Hamlet wrote:I'm more the kind of hardcore gamer
Oh, well with that in mind, maybe a recycle furnace? Put stuff into it, add fuel, and it returns whole numbers of ingots? It allows you to melt down window grates, steel bars, any odd metals you find. Don't think I'd use it for creating alloys, but maybe. Otherwise, just use different counters to keep track of floating point residual of each metal.

If you are really hardcore, steel takes a lot more fuel to melt than copper, and the furnace is much more complex...
 

User avatar
Hamlet
Member
 
Posts: 625
Joined: Sat Jul 29, 2017 21:09
Location: Lombardy, Italy
GitHub: h4ml3t
IRC: H4mlet

Re: Recycling broken tools

by Hamlet » Mon Oct 28, 2019 16:29

ThorfinnS wrote:
Hamlet wrote:I'm more the kind of hardcore gamer
Oh, well with that in mind, maybe a recycle furnace? Put stuff into it, add fuel, and it returns whole numbers of ingots? It allows you to melt down window grates, steel bars, any odd metals you find. Don't think I'd use it for creating alloys, but maybe. Otherwise, just use different counters to keep track of floating point residual of each metal.

If you are really hardcore, steel takes a lot more fuel to melt than copper, and the furnace is much more complex...


Good points.
I'll break my answer in two parts.

Part 1

About realistic smelting/cooking times, I have few clues.
A quick research about metals' melting ponts gave me this list (Celsius and Fahrenheit degrees available): https://www.engineeringtoolbox.com/melt ... d_860.html

Now the tricky part is to arbitrarily define a "realistic" burning time.
Which fuel should be the "corner stone" for further proportions? A coal lump?
Or a wooden plank?

Next, accordingly to the aforementioned list gold has a melting point of 1063°C/1945°F - since we have gold lumps we could use it as second "corner stone" for our proportion.

Now, how many coal lumps for a gold lump?
Or in other words, how many seconds to smelt gold; i.e. when it is "cooked" we can say that we have reached the temperature of 1063°C/1945°F.

Once that we have defined this, defining the burning times of other metals/alloys is just a matter of proportions.


Part 2

About a smelter.
I don't know how to use node meta, nor formspecs.
It has been already done by MasterGollum: viewtopic.php?t=3546

I've never tried it.
There is also Real Minerals & Metals https://github.com/FaceDeer/real_minerals ported by FaceDeer from RealTest's system, which I believe uses real life alloys: https://github.com/sda97ghb/realtest/bl ... s/init.lua

If anyone is willing to help me by actually coding a smelter which uses that existing code, I will gladly accept: it is a task beyond my programming skills.

Now, though, we are going beyond recycling: we are re-defining Minetest Game's mechanics, toward simulation.

At this point, would it be worth to make another step further?
A grindstone to repair cutting tools (axes, swords, etc.).
An anvil to temper metals, for longer lasting tools' crafting.

Anyone who has ever played Morrowind, or Oblivion, or Skyrim will know what I mean.

I seriously doubt that the average player would be interested, but as a RPG player I would be interested. Anyone else out there?
 


Return to Modding Discussion



Who is online

Users browsing this forum: No registered users and 1 guest