summaryrefslogtreecommitdiff
path: root/lode_stylus.lua
blob: 823e3c8057827adda5b92484703b2b7f31efbdde (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
--[[

	NB More Concrete - Adds more concrete types to NodeCore
	Copyright (C) 2024, 2025 NameNotQuality

	This file is part of NB More Concrete.

	NB More Concrete is free software: you can redistribute it and/or modify
	it under the terms of the GNU Affero General Public License as published
	by the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	NB More Concrete is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
	GNU Affero General Public License for more details.

	You should have received a copy of the GNU Affero General Public License
	along with NB More Concrete. If not, see <https://www.gnu.org/licenses/>.



	This file includes modified code from the files `stylus.lua` and 'patterns.lua'
	from the `mods/nc_concrete` directory and 'metallurgy.lua' and 'tongs.lua' from the 'mods/nc_lode'
	directory of the NodeCore Project, hosted on https://gitlab.com/sztest/nodecore.
	The NodeCore Project's license notice is below.


	Copyright (C)2018-2024 Aaron Suen <[email protected]>
	Portions Copyright (C)2019-2020 LoneWolfHT <[email protected]>
	Portions Copyright (C)2019 Magik Eh
	Portions Copyright (C)2019-2021 GreenXenith
	Portions Copyright (C)2019-2024 Dmitriy Tillyaev (Kimapr) <[email protected]>
	Portions Copyright (C)2019 Elkien
	Portions Copyright (C)2020 WintersKnight94 <[email protected]>
	Portions Copyright (C)2019 Avicennia G
	Portions Copyright (C)2022 MisterE <[email protected]>
	Portions Copyright (C)2022 Giuseppe Bilotta <[email protected]>
	Portions Copyright (C)2020 Yaman Qalieh <[email protected]>
	Portions Copyright (C)2022 NoComment


	Permission is hereby granted, free of charge, to any person obtaining
	a copy of this software and associated documentation files (the
	"Software"), to deal in the Software without restriction, including
	without limitation the rights to use, copy, modify, merge, publish,
	distribute, sublicense, and/or sell copies of the Software, and to
	permit persons to whom the Software is furnished to do so, subject
	to the following conditions:

	The above copyright notice and this permission notice shall be included
	in all copies or substantial portions of the Software.

	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
	KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
	WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
	NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
	LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
	OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
	WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

--]]

-- LUALOCALS! > ----------------------------
local nc,       core, tonumber
    = nodecore, core, tonumber
-- LUALOCALS! < ----------------------------


-- Modname
local mn = core.get_current_modname()


-- Translations function.
-- Not only for translations that I may do one day,
-- but now mainly to remove the 'translation formed late' warning
local S = core.get_translator(mn)


---------->	New concrete patterns
-- Global table
nb_more_concrete = {}
---	Annealed


-- NO Mkreg
--nb_more_concrete.register_annealed_patterns = {}
nb_more_concrete.annealed_patterns = {}--nodecore.mkreg()

-- Register the patterns table
--
--
-- normally the registered_patterns table in nc would look like:
-- the table -> 1,2,3,4,5,6,7,8,9
-- 1 -> name="blank", description="Blank",
--	-- Note 9's next points to 1 -- Pointers in lua? Actually, not really...
--	next=the 2 somehow, pattern_tile="nc_concrete_etched.png^[mask:nc_concrete_pattern_BLANK.png"
--	blank=true -- Extra variable <----\
--nc.register_concrete_patterns({"Blank", blank=true}) -- 1st same as default (blank)

-- Let's create a function to make a table like that
-- table - the table to add patterns to (e.g. nb_more_concrete.annealed_patterns)
-- add - table with desc and extra variables to add to `table` (e.g. {description = "Blank", blank = true)
--[[btw, not sure if these should be global, but I made them so anyway]]--
function nb_more_concrete.register_patterns(table, add)
	-- Get next index
	local length = #table + 1
	-- Make the variables
	table[length] = add
	table[length].name = table[length].description:lower() -- name
	table[length].pattern_tile="nc_concrete_etched.png^[mask:nb_more_concrete_pattern_" .. table[length].name .. ".png"
	-- the 'next' variable is going to be handled in the next function
end -- register_patterns


-- Finishes by creating the 'next' variables in the table,
-- so table[index].next = table[index+1]
-- table - same as earlier, the table to do the operation on (e.g. nb_more_concrete.annealed_patterns)
function nb_more_concrete.register_patterns_finish(table)
	for i,pattern in ipairs(table) do
		-- if i < table length, next = next table index
		-- else, most likely at 9th index, it points to 1
		pattern.next = table[ (i<#table) and (i+1) or 1 ]
	end
end -- register_patterns_finish


-- Liberties is a mod which defines some patts too, one of which, Crossy, suprisingly
-- turned out to be the same as the Gifty one below.
-- So I'll alias them to skip installing one uselessly by checking for this variable
-- which will show if it's enabled
if (core.get_modpath("lc_liberties")) then
	nb_more_concrete.liberated = true
end
-- Now, let's define the patterns
-- NC's patterns for reference, in order:
-- Bricky, Vermy, Hashy, Bindy, Verty, Horzy, Boxy, Iceboxy
--
-- Oh my goodness
-- What a wall of text! <- Written when this was an actual nice wall of text btw, now it has this if etc.
nb_more_concrete.register_patterns(nb_more_concrete.annealed_patterns,{description = "Blank", blank=true})
nb_more_concrete.register_patterns(nb_more_concrete.annealed_patterns,{description = "Liny", paramtype2="facedir"})
if (nb_more_concrete.liberated) then -- Alias gifty to crossy, this gets checked for later to not define gifty anymore
	nb_more_concrete.register_patterns(nb_more_concrete.annealed_patterns,{description = "Gifty", alias="crossy"})
else 				-- liberties could've gotten uninstalled, so let's alias its crosses back to Santa
	nb_more_concrete.register_patterns(nb_more_concrete.annealed_patterns,{description = "Gifty", aliased="crossy"})
end -- Note in the crafts later there's no check for alias variable, just once for "crossy" instead manually added
nb_more_concrete.register_patterns(nb_more_concrete.annealed_patterns,{description = "Tily"})
nb_more_concrete.register_patterns(nb_more_concrete.annealed_patterns,{description = "Quady"})
nb_more_concrete.register_patterns(nb_more_concrete.annealed_patterns,{description = "Checkery"})
nb_more_concrete.register_patterns(nb_more_concrete.annealed_patterns,{description = "Celly"})
nb_more_concrete.register_patterns(nb_more_concrete.annealed_patterns,{description = "Diamondy"})
nb_more_concrete.register_patterns(nb_more_concrete.annealed_patterns,{description = "Circly"})
nb_more_concrete.register_patterns_finish(nb_more_concrete.annealed_patterns)
-- It works!

---	Tempered (for now same as annealed)
--nb_more_concrete.tempered_patterns=nb_more_concrete.annealed_patterns
---	Later probably also lux annealed and lux tempered (but /probably/ not boost lux and hot lode versions)




---------->	Stylus definition

-- Create the stylus
-- Definition defined locally at first for checks later
local shape = "stylus" -- First arg to func
--local stylus_def
local stylish_def = {
	type = "tool",
	description = "## Lode Stylus", -- '##' means temper/state desc,
	tool_wears_to = "nc_lode:prill_#", -- while a '#' means temper name
	inventory_image = "nc_lode_#.png^[mask:nb_more_concrete_stylus.png",

	stack_max = 1,
	light_source = 3,

	tool_capabilities = nc.toolcaps({
			scratchy = 4 -- Normally stone tool or hot lode group = 3, annealed lode = 4, tempered = 5
	}),
	groups = { -- nb_lode_stylus group for crafts
		nb_lode_stylus = 1
	},
	-- Change toolcaps depending on temper
	bytemper = function (item,def)
		if (item.name == "tempered") then
			def.tool_capabilities = nc.toolcaps({scratchy=5})
		elseif (item.name == "hot") then -- Hot doesn't actually melt everything and scratch=9999
			def.tool_capabilities = nc.toolcaps({scratchy=3})
		end
		-- Create nb_scratchy groups for crafts later
		--[[ This tool_capabilities table looks like this:
		punch_attack_uses = 0
		opts = {
			scratchy = 3
			uses = 1
		}
		groupcaps = {
			scratchy = {
				uses = 135
				times[1,2,3] = some numbers
			}
		} --]]
		-- Let's copy those scratchies to nb_scratchies
		def.tool_capabilities.opts.nb_scratchy = def.tool_capabilities.opts.scratchy
		def.tool_capabilities.groupcaps.nb_scratchy = def.tool_capabilities.groupcaps.scratchy
		-- Now the stylus will have nb_scratchy value identical to normal scratchy, /alongside/ scratchy

	end,

	-- Description naming based on pattern
	-- (The stylus's desc normally has its name and then next line has the set pattern)
	on_stack_touchtip = function(stack, desc)
		-- Set patterns (later is gonna be set dependant on anneal/temper state)
		local patterns = nb_more_concrete.annealed_patterns
		-- Get pattern
		local patt = stack:get_meta():get_string("pattern")
		if not patt --[[or patt == ""--]] then
		return desc end
		-- Add to desc
		-- First, check for crossy alias, so name can be changed to crossy instead
		if (nb_more_concrete.liberated and patt=="gifty") then
			return desc .. "\n" .. "Crossy"
		end
		for _, def in pairs(patterns) do
			-- If patt is correct
			if patt == def.name and def.description then
				return desc .. "\n" .. S(def.description) -- Only translations 4 now 4 no warnings
			end
		end
		return desc
	end,

}
-- NC versions older than a load of gibberish:
-- 5002ea97bd9ab058bb11d7f639612f5a894020c9
-- (03379146-5002ea97?)
-- have a bug:
-- nc.register_lode doesn't work if your mod isn't
-- called 'nc_lode', since else it errors out saying
-- that the prefix is supposed to be 'your modname:'
-- or ':' instead.
--
-- It was fixed after I've reported it by newly prefixing
-- it with ':', but some may not be able to update yet.
-- If the version is older than that, I will
-- define and call the function from newer NC.

-- To check the new... newe... newesty? newy? NEWNESS, it
-- is possible to decipher nc.version (nc.releasedate
-- doesn't work), as I realised the 1st number always
-- increases. (https://content.luanti.org/packages/Warr1024/nodecore/releases/)
-- So let's compare it to 03379146........
nb_more_concrete.nc_new=false
local version_num = nc.version
if version_num then -- Here set new to true if it passes the check
	-- Get digit(%d)s(+) before the - and compare it as num
	version_num = version_num:match("%d+")
	if (tonumber(version_num) >= 3379146) then
		nb_more_concrete.nc_new=true
	end
end

-- Register the lode stylus
if (nb_more_concrete.nc_new) then
	nc.register_lode("stylus", stylish_def)
else -- Define the function from NC
	local tempers = {
		{
			name = "hot",
			desc = "Glowing",
			sound = "annealed",
			glow = true,
			mapcolor = {r = 131, g = 23, b = 18},
		},
		{
			name = "annealed",
			desc = "Annealed",
			sound = "annealed",
			mapcolor = {r = 47, g = 36, b = 32},
		},
		{
			name = "tempered",
			desc = "Tempered",
			sound = "tempered",
			mapcolor = {r = 57, g = 39, b = 35},
		}
	}
	--local function register_lode(shape, rawdef)
	stylish_def.groups = stylish_def.groups or {}
	for _, temper in pairs(tempers) do
		local def = nc.underride({}, stylish_def)
		def.groups = nc.underride({}, def.groups)
		def = nc.underride(def, {
				description = temper.desc .. " Lode " .. shape,
				name = (shape .. "_" .. temper.name):lower():gsub(" ", "_"),
				groups = {
				cracky = 3,
					metallic = 1,
				falling_node = temper.name == "hot" and 1 or nil,
					falling_mapgen_ignore = temper.name == "hot"
					and 1 or nil,
				["lode_temper_" .. temper.name] = 1
				},
				["lode_temper_" .. temper.name] = true,
				lode_alt_hot = "nc_lode:" .. shape:lower() .. "_hot",
				lode_alt_annealed = "nc_lode:" .. shape:lower() .. "_annealed",
				lode_alt_tempered = "nc_lode:" .. shape:lower() .. "_tempered",
				sounds = nc.sounds("nc_lode_" .. temper.sound),
				mapcolor = temper.mapcolor,
		})
		def.lode_temper_cool = (not def.lode_temper_hot) or nil
		if not temper.glow then
			def.light_source = nil
		else
			def.groups.falling_node = 1
			def.groups.falling_mapgen_ignore = 1
			def.groups.damage_pickup = 1
			def.groups.damage_radiant = 1
		end

		if def.tiles then
			local t = {}
			for k, v in pairs(def.tiles) do
				t[k] = v:gsub("#", temper.name)
			end
			def.tiles = t
		end
		for k, v in pairs(def) do
			if type(v) == "string" then
				def[k] = v:gsub("##", temper.desc):gsub("#", temper.name)
			end
		end

		if def.bytemper then def.bytemper(temper, def) end

		--if not def.skip_register then
		-- The fix
		local fullname = ":nc_lode:" .. def.name
		core.register_item(fullname, def)
		--[[if def.type == "node" then
			nc.register_cook_abm({
					nodenames = {fullname},
					neighbors = (not temper.glow) and {"group:flame"} or nil
				})
		end--]]
	end
end
	--end

---------->	Common lode crafts (create/recycle) and special patt aism

-- Instead of re-defining the heating/cooling and tong-carrying mechanics,
-- let's make just 1 aism to replace a stylus with no pattern with one set.
-- This seems to be a very nice and simple solution, but it has a side effect:
-- the stylus is visibly changing to another pattern. I don't think it's that
-- bad though.
nc.register_aism({
	label = "nb lode stylus pattern set",
	interval = 1,
	chance = 1,
	itemnames = {"group:nb_lode_stylus"},
	action = function(stack, data)
		-- Check if change of patt is required
		local oldpatt = stack:get_meta():get_string("pattern")
		if (not oldpatt or oldpatt=="") then
			-- Set patt
			local patterns=nb_more_concrete.annealed_patterns -- later set dependant on temper
			stack:get_meta():set_string("pattern", nc.pickrand(patterns).name)
		end
		return stack
	end
})


-- Craft the stylus on anvil
nc.register_lode_anvil_recipe(-2, function(state)
	return {
		label = "anvil making lode stylus",

		action = "pummel",
		toolgroups = {thumpy = 3},

		normal = {y = 1},
		indexkeys = {"nc_lode:prill_" .. state},

		nodes = {
			{match = "nc_lode:prill_" .. state, replace = "air"},
			{y = -1, match = "nc_lode:bar_" .. state, replace = "air"},
			--{y = -2, match = "nc_lode:block_tempered"}
		},
		items={
			"nc_lode:stylus_" .. state
		}}
		-- Spawn stylus with a pattern set
		--[[ Doesn't work, the function doesn't chain this properly into its own 'after' (I should report this probably)
		after = function(pos)
			--pos.y = pos.y - 1-- decrement
			-- Set item to then modify
			local item = ItemStack("nc_lode:stylus_" .. state)
			-- Patterns
			local patterns = nb_more_concrete.annealed_patterns
			-- Modify meta for pattern
			item:get_meta():set_string("pattern",
				-- Pick randomly a pattern
				--patterns[math.random(9)].name)
				nc.pickrand(patterns).name)
			-- Return it at the pos
			return nc.item_eject(pos, item)
		end} -- return --]]
	end -- function(state)
)

-- Recycle recipe
nc.register_craft({
	label = "recycle lode stylus",

	action = "pummel",
	toolgroups = {choppy = 3},

	indexkeys = {"nc_lode:stylus_hot"},
	nodes = {
		{match="nc_lode:stylus_hot", replace="air"}
	},
	items = {
		{name = "nc_lode:prill_hot"},
		{name = "nc_lode:bar_hot"}
	}
})


---------->	Define new set and pliant concretes

-- All concretes are visible in the nc.registered_concrete_etchables table:
-- the table -> 1,2,3...
-- 2 -> basename = "nc_concrete:sandstone", name = "concrete_sandstone",
--	pliant_tile = "^(nc_concrete_pliant.png^[opacity:40)", solid -> n o t h i n g,
--	pattern_opacity = 80, pliant_opacity = 40 -- extras
--	pattern_invert = false -- not explicitly defined in 2, extra
--	pliant ->
--		drop_in_place = "nc_concrete:render_wet_source",
--		silktouch = false,
--		sounds = {stuffs for sounds},
--		groups = {
--			toolgroups like cracky or choppy
--			rock, smoothstone,stone = 0
--			concrete_etchable = 1
--		}
--
-- Based on this data, we will need to create: for each concrete: 8 pliant and 8 set versions of it.
-- Below is the magic (based on NC)

--- Helper functions
-- Add/apply spec to each tile
local function applytile(tiles, spec)
	if not spec then return tiles end
	-- New table, totally not a salamander
	local newt = {} -- It will hold the specced tiles
	for k, tile in pairs(tiles) do
		if type(spec) == "function" then
			-- Spec modifies tile
			newt[k] = spec(tile)
		else -- Cat v with spec
			newt[k] = tile .. spec
		end
	end
	return newt
end

-- Create the pattern tile
local function patttile(etch, patt)
	--if patt.blank then return function(...) return ... end end -- useless for blank already defined
	return function(tile) -- tile^(etchy.png^[invert:rgb^[opacity:64)
		return tile .. "^(" .. patt.pattern_tile
		.. (etch.pattern_invert and "^[invert:rgb" or "")
		.. "^[opacity:" .. (etch.pattern_opacity or 64) .. ")"
	end
end

-- Default def.groups[group] to 1 if not defined
-- (if def.groups[group index] is not defined, set it to 1)
local function defaultgroup(def, group)
	local groups = {}
	if def.groups then -- Asign to groups[] via key = value pairs
		for k, v in pairs(def.groups) do groups[k] = v end
	end
	-- group is explicitly set on if undefined
	groups[group] = groups[group] or 1
	def.groups = groups
end


-- Main function called
-- Register the etched pliant and set concrete
local function regetched(basenode, etch, patt)
	-- Alias to a working concrete instead of defining another, e.g. Gifty -> Crossy of Liberties
	-- patt.aliased in case other mod got uninstalled to alias its blocks back to us
	if (patt.alias or patt.aliased) then
		-- Dry
		local pattname = mn  .. ":" .. etch.name .. "_" .. patt.name --	     mn:othermn_concrete_etchy
		local toname="nc_concrete:" .. etch.name .. "_" .. (patt.alias or patt.aliased) -- nc_concrete:othermn_concrete_aliasy
		-- Ply
		local plyname =  pattname .. "_ply"
		local ply_toname = toname .. "_ply"
		-- Do the aliasing
		-- This requires anti-aliasing to be off... (No)
		if (patt.alias) then
			core.register_alias(pattname, toname)
			core.register_alias(plyname, ply_toname)
			return -- Only here
		else -- patt.aliased -v
			core.register_alias(toname, pattname)
			core.register_alias(ply_toname, plyname)
		end -- (saila.ttap) fi
	end -- (desaila.ttap...
	-- Blank is already defined as nc_concrete:concrete_blank_ply by NC
	if (patt.blank) then return end
	basenode = nc.underride({}, basenode)
	-- Remove from basenode
	basenode.after_dig_node = nil
	basenode.node_dig_prediction = nil
	basenode.alternate_loose = nil
	basenode.silktouch = nil
	basenode.strata = nil
	-- Concrete block name used later
	local pattname = mn .. ":" .. etch.name .. "_" .. patt.name -- mn:othermn_concrete_etchy
	-- Pliant name, same as pattname but with _ply
	local plyname = pattname .. "_ply" -- mn:othermn_concrete_etchy_ply
	-- Pliant block
	if not core.registered_nodes[plyname] then
		local def = {} -- Final def, to which we add
		nc.underride(def, etch.pliant)
		nc.underride(def, etch)
		nc.underride(def, patt)
		nc.underride(def, basenode)

		def.tiles = applytile(def.tiles, patttile(etch, patt))
		def.tiles = applytile(def.tiles, etch.pliant_tile)

		def.name = nil -- Name already done at the end of this ifnot in core.register_node
		def.description = patt.description .. -- Etchy Pliant Concrete
			" Pliant " .. basenode.description

		def.pattern_def = patt
		def.etch_def = etch

			--if not patt.blank then
		defaultgroup(def, mn .. "_pattern_" .. patt.name)
			--end
		defaultgroup(def, mn .. "_pliant")
		--[[if def.paramtype2 == "4dir" then -- unused
			def.on_rightclick = function(pos, node) -- Rotate upon rightclick
				node.param2 = (node.param2 + 1) % 4 -- Capped param2 at 3
				nc.set_loud(pos, node)
			end
		end--]]
		if (def.paramtype2=="facedir") then
			-- I wanted to implement clockwise rotation on any side of a block,
			-- but I have little idea how to get the selected side.
			-- For now, let's use NC's rotation_on_rightclick
			def.on_rightclick=nc.rotation_on_rightclick
			def.groups.nc_api_rotate_under=1 -- required to work
		end -- facedir
		-- Add extra nb group, used mainly for pliant cure ABM
		def.groups.nb_concrete_etchable = 1
		-- It replaces the nc one
		def.groups.concrete_etchable = nil
		-- This way, the ABM for pliant concrete curing will not break the game
		-- (it is made to handle only 'nc_concrete:' prefixed nodes)

		core.register_node(":" .. plyname, def)
	end
		--if not patt.blank then
	-- Set block
	if not core.registered_nodes[pattname] then
		local def = {} -- Final def like earlier
		nc.underride(def, etch.solid)
		nc.underride(def, etch)
		nc.underride(def, patt)
		nc.underride(def, basenode)

		def.tiles = applytile(def.tiles, patttile(etch, patt))
		def.name = nil
		def.description = patt.description .. " " ..
			basenode.description -- Etchy Concrete

		def.pattern_def = patt
		def.etch_def = etch

		defaultgroup(def, mn .. "_pattern_" .. patt.name)
		defaultgroup(def, mn .. "_etched")

		core.register_node(":" .. pattname, def)
	end
		--end
end

---


-- Now: Who are you gonna call?
-- Etchbusters!..?
-- Why would you bust my etch...
--
-- Etchmakers!

-- (here I call the functions to make the concretes)

--local mudgroups = {...

	--local function buildpatterns()
-- Make sure patt.name and patt.pattern_tile are defined
for _, patt in pairs(nb_more_concrete.annealed_patterns) do
	--nc.translate_inform(patt.description)
	patt.name = patt.name or string:gsub(string:lower(patt.description),
		"%W", "_")
	patt.pattern_tile = patt.pattern_tile or "nc_concrete_etched.png^[mask:" .. mn
			.. "_pattern_" .. patt.name .. ".png" -- ..^[mask:mn_pattern_etchy.png
end
-- For every concrete, modify etchable correctly
-- Already done by NC
--[[for _, etch in pairs(nc.registered_concrete_etchables) do
	...
end--]]
for _, etch in pairs(nc.registered_concrete_etchables) do
	local basenode = core.registered_nodes[etch.basename]
	if basenode then -- For every etchable, register its etched version
		for _, patt in pairs(nb_more_concrete.annealed_patterns) do
			regetched(basenode, etch, patt)
		end
	end
end
	--end


---------->	Stylus crafts and ABMs
--- Help functions
-- Get pattern_def and etch_def of node.
local function getdefs(node)
	local def = core.registered_items[node.name] or {}
	-- If the pattern_def is blank, it will return nc's pattern list, which breaks the recipe
	-- (Returned can only be the nb list in general; should I add a universal check for it?
	-- 		This is probably sufficient though (and universal - works same in stone (stylus) craft))
	if (def.pattern_def.blank) then
		return nb_more_concrete.annealed_patterns[1], def.etch_def
	end
	return def.pattern_def, def.etch_def
end

-- Make pliant node make noise and rotate if paramtype2 is set
local function setply(pos, nodename, player)
	local node = {name = nodename}
	if core.registered_nodes[node.name].paramtype2 == "4dir"
					and player then
		node.param2 = core.dir_to_fourdir(
			player:get_look_dir())
	end
	nc.set_loud(pos, node)
end
---

-- Etch with the new lode stylus craft
--
-- Function to register craft for both
-- concrete_etchable and nb_concrete_etchable groups
--
-- label - e.g. "annealed lode stylus etch" (to differentiate between nb and nc craft)
-- indexkey - e.g. "group:concrete_etchable"
-- match - e.g. {groups = {concrete_etchable = true}}
local function register_this_lodely_craft(label, indexkey, match)

nc.register_craft({
	label = label,
	action = "pummel",
	--wield =
	toolgroups = {nb_scratchy = 1},
	priority = 2, -- So it doesn't conflict with stone stylus etch crafts
	indexkeys = {indexkey},
	nodes = {
		{
			match = match
		}
	},
	after = function(pos, data)
		-- Get pattdef, etchdef
		local pattdef, etchdef = getdefs(core.get_node(pos))
		if not (pattdef and etchdef) then return end
		-- Here we cannot have nc patterns, if crossy comes up
		if (nb_more_concrete.liberated and
			pattdef.name == "crossy") then pattdef = nb_more_concrete.annealed_patterns[3] end

		-- Helper variable for making pliant block name
		local setpref = mn .. ":" .. etchdef.name .. "_" -- mn:othermn_chromete_

		-- Get wielded stylus
		local wield = data.wield
		if (not wield) or wield:is_empty() then return end
		-- Wielded stylus's pattern
		local wieldpatt = wield:get_meta():get_string("pattern")
		-- Check for blank to change block to nc_concrete:
		if (wieldpatt == "blank") then
			setpref = "nc_concrete:" .. etchdef.name .. "_"
		end
		-- If wielded pattern isn't equal to block's pattern
		if wieldpatt and wieldpatt ~= "" and wieldpatt ~= pattdef.name then
			-- Set the pliant block and return
			setply(pos, setpref .. wieldpatt .. "_ply", data.crafter) -- mn:chromete_etchy_ply
			return
		end

		-- Now we know that next pattern will be set for stylus and block instead
		-- Get next pattern
		local nxpatt = pattdef.next.name
		-- Check for blank like earlier
		if (nxpatt == "blank") then
			setpref = "nc_concrete:" .. etchdef.name .. "_"
		else -- In case earlier was blank, set back
			setpref = mn .. ":" .. etchdef.name .. "_"
		end
		-- So it can be set on pliant
		setply(pos, setpref .. nxpatt .. "_ply", data.crafter)
		-- And set as next pattern for stylus
		wield:get_meta():set_string("pattern", nxpatt)
		if data.crafter then
			-- Discovery
			nc.player_discover(data.crafter, "stylus train")
			data.crafter:set_wielded_item(data.wield)
		-- Same, but for hinged pressers instead
		elseif data.presstoolpos then
			nc.witness(pos, "stylus train")
			nc.stack_set(data.presstoolpos, wield)
		end
	end
})

end -- register_this_lodely_craft
register_this_lodely_craft("lode stylus etch (nc)",    "group:concrete_etchable", -----------------------------\
									{groups = {   concrete_etchable = true}}) -- For nc
register_this_lodely_craft("lode stylus etch (nb)", "group:nb_concrete_etchable", -----------------------------\
									{groups = {nb_concrete_etchable = true}}) -- For nb

-- The original stylus also needs to be able to write on
-- 				nb_concrete_etchables
--
-- Here's the original craft, but for the nb group
nc.register_craft({
	label = "stylus etch (nb)",
	action = "pummel",
	toolgroups = {scratchy = 1},
	--wield = "nc_concrete:stylus",
	indexkeys = {"group:nb_concrete_etchable"},
	nodes = {
		{
			match = {groups = {nb_concrete_etchable = true}}
		}
	},
	after = function(pos, data)
		local pattdef, etchdef = getdefs(core.get_node(pos))
		if not (pattdef and etchdef) then return end

		local setpref = "nc_concrete:" .. etchdef.name .. "_"

		local wield = data.wield
		if (not wield) or wield:is_empty() then return end
		local wieldpatt = wield:get_meta():get_string("pattern")
		if wieldpatt and wieldpatt ~= "" and wieldpatt ~= pattdef.name then
			setply(pos, setpref .. wieldpatt .. "_ply", data.crafter)
			return
		end

		local nxpatt = pattdef.next.name
		setply(pos, setpref .. nxpatt .. "_ply", data.crafter)
		wield:get_meta():set_string("pattern", nxpatt)
		if data.crafter then
			nc.player_discover(data.crafter, "stylus train")
			data.crafter:set_wielded_item(data.wield)
		elseif data.presstoolpos then
			nc.witness(pos, "stylus train")
			nc.stack_set(data.presstoolpos, wield)
		end
	end
})
--- Pliant concrete cure ABM
-- The NC pliant cure ABM doesn't work for our pliants,
-- since it only works with "nc_concrete:" concretes.
-- Here's an ABM that works (from NC)
nc.register_soaking_abm({
	label = "pliable nb concrete cure",
	interval = 1,
	nodenames = {"group:nb_concrete_etchable"},
	fieldname = "nb_plycuring",
	arealoaded = 1,
	soakrate = function(pos)
		if core.find_node_near(pos, -- Water not allowing for cure
			1, {"group:concrete_flow", "group:water"}) then
			return false
		end	-- Fire speeding up cure
		local found = nc.find_nodes_around(pos, "group:igniter", 1)
		return #found + 1
	end,

	soakcheck = function(data, pos, node)
		if data.total < 100 then -- Create smoke during curing
			nc.smokefx(pos, 1, data.rate)
			return
		end
		-- Get the final cured node
		local pattdef, etchdef = getdefs(core.get_node(pos))	-- Fixed |
		if not (pattdef and etchdef) then return end		-- bit   V
		local curename = mn .. ":" .. etchdef.name .. "_" .. pattdef.name -- nb_more_concrete:mn_concrete_etchy
		if pattdef.blank then curename = etchdef.basename end

		nc.smokeburst(pos)
		nc.dynamic_shade_add(pos, 1)
		--
		nc.set_loud(pos, {name = curename, param2 = node.param2})
		nc.witness(pos, "cure pliant concrete")
		return false
	end
}) -- END