From 9a8ffa8acf647bd24cb2245d8d327592d752426a Mon Sep 17 00:00:00 2001 From: obneq Date: Sat, 28 Jul 2012 01:13:25 +0200 Subject: [PATCH] initial commit --- init.lua | 341 +++++++++++++++++++++++++++++++++++++++++ textures/black.png | Bin 0 -> 295 bytes textures/blue.png | Bin 0 -> 301 bytes textures/cyan.png | Bin 0 -> 301 bytes textures/darkgrey.png | Bin 0 -> 295 bytes textures/green.png | Bin 0 -> 301 bytes textures/lightgrey.png | Bin 0 -> 295 bytes textures/lime.png | Bin 0 -> 301 bytes textures/orange.png | Bin 0 -> 301 bytes textures/painted.png | Bin 0 -> 317 bytes textures/pink.png | Bin 0 -> 301 bytes textures/red.png | Bin 0 -> 301 bytes textures/violet.png | Bin 0 -> 301 bytes textures/white.png | Bin 0 -> 295 bytes textures/yellow.png | Bin 0 -> 301 bytes 15 files changed, 341 insertions(+) create mode 100644 init.lua create mode 100644 textures/black.png create mode 100644 textures/blue.png create mode 100644 textures/cyan.png create mode 100644 textures/darkgrey.png create mode 100644 textures/green.png create mode 100644 textures/lightgrey.png create mode 100644 textures/lime.png create mode 100644 textures/orange.png create mode 100644 textures/painted.png create mode 100644 textures/pink.png create mode 100644 textures/red.png create mode 100644 textures/violet.png create mode 100644 textures/white.png create mode 100644 textures/yellow.png diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..9d05084 --- /dev/null +++ b/init.lua @@ -0,0 +1,341 @@ +-- painting - in-game painting for minetest-c55 + +-- THIS MOD CODE AND TEXTURES LICENSED +-- <3 TO YOU <3 +-- UNDER TERMS OF GPL LICENSE + +-- 2012 obneq aka jin xi + +-- a picture is drawn using a node(box) to draw the supporting canvas +-- and an entity which has the painting as its texture. +-- this texture is created by minetest-c55's internal image +-- compositing engine (see tile.cpp). + +--dofile(minetest.get_modpath("painting").."/crafting.lua") + +textures = { + white = "white.png", yellow = "yellow.png", + orange = "orange.png", red = "red.png", + violet = "violet.png", blue = "blue.png", + green= " green.png", magenta = "pink.png", + cyan = "cyan.png", lightgrey = "lightgrey.png", + darkgrey = "darkgrey.png", black = "black.png" +} + +res = 16 +thickness = 0.1 + +-- picture node +picbox = { + type = "fixed", + fixed = { -0.5, -0.5, 0.5, 0.5, 0.5, 0.5 - thickness } +} + +picnode = { + description = 'pic', + tiles = { "white.png" }, + inventory_image = "painted.png", + drawtype = "nodebox", + sunlight_propagates = true, + paramtype = 'light', + paramtype2 = "facedir", + node_box = picbox, + selection_box = picbox, + groups = { snappy = 2, choppy = 2, oddly_breakable_by_hand = 2 }, + + --handle that right below, don't drop anything + drop = "", + + after_dig_node=function(pos, oldnode, oldmetadata, digger) + --find and remove the entity + local objects = minetest.env:get_objects_inside_radius(pos, 0.5) + for _, e in ipairs(objects) do + if e:get_luaentity().name == "painting:picent" then + e:remove() + end + end + + --put picture data back into inventory item + local data = oldmetadata.fields["painting:picturedata"] + local item = { name = "painting:paintedcanvas", count = 1, metadata = data } + digger:get_inventory():add_item("main", item) + end +} + +-- picture texture entity +picent = { + collisionbox = { 0,0,0,0,0,0 }, + visual = "upright_sprite", + textures = { "white.png" }, + + on_activate = function(self, staticdata) + local pos = self.object:getpos() + local meta = minetest.env:get_meta(pos) + local data = meta:get_string("painting:picturedata") + + if data then + self.object:set_properties({textures = { data }}) + end + end +} + +--paintedcanvas picture inventory item +paintedcanvas = { + inventory_image = "painted.png", + stack_max = 1, + + on_place = function(itemstack, placer, pointed_thing) + local data = itemstack:get_metadata() + local pos = pointed_thing.above + + --place node + local placerpos = placer:getpos() + local pos = pointed_thing.above + local dir = {x = pos.x - placerpos.x, y = pos.y - placerpos.y, z = pos.z - placerpos.z} + local fd = minetest.dir_to_facedir(dir) + + local pic = minetest.env:add_node(pos, { name = "painting:pic", + param2 = fd, + paramtype2 = 'none' }) + + local meta = minetest.env:get_meta(pos) + meta:set_string("painting:picturedata", data) + + --and entity + local dirs = {[0] = {x=0, z=1}, + [1] = {x=1, z=0}, + [2] = {x=0, z=-1}, + [3] = {x=-1, z=0}} + local dir=dirs[fd] + local off = 0.5-thickness-0.01 + + local np = { + x = pos.x+dir.x*off, + y = pos.y, + z = pos.z+dir.z*off} + + local p = minetest.env:add_entity(np, "painting:picent"):get_luaentity() + p.object:set_properties({textures = { data }}) + p.object:setyaw(math.pi*fd/-2) + + return ItemStack("") + end +} + +--canvas inventory item +canvas = { + inventory_image = "default_paper.png", + stack_max = 99, +} + +--canvas for drawing +canvasbox = { + type = "fixed", + fixed = { -0.5, -0.5, 0.0, 0.5, 0.5, thickness } +} + +canvasnode = { + description = 'canvas', + tiles = { "white.png" }, + inventory_image = "painted.png", + drawtype = "nodebox", + sunlight_propagates = true, + paramtype = 'light', + paramtype2 = "facedir", + node_box = canvasbox, + selection_box = canvasbox, + groups = { snappy = 2, choppy = 2, oddly_breakable_by_hand = 2 }, + + drop = "", + + can_dig = function () + return true + end, + + on_construct = function(pos) + local node = minetest.env:get_node(pos) + local fd = node.param2 + + for y = 0, res-1 do + for x = 0, res-1 do + local xstep = x/res + local off = 1/(res*2) + + local boff = 0.01-off + + local dirs2 = { + [0] = { x =-0.5 + off + xstep, z = 0 - boff }, + [1] = { x = 0 - boff, z = 0.5 - off - xstep }, + [2] = { x = 0.5 - off - xstep, z = 0 + boff }, + [3] = { x = 0 + boff, z =-0.5 + off + xstep }, + } + + local dir = dirs2[fd] + + local np = {x = pos.x + dir.x, + y = pos.y + (0.5-1/(res*2)) - y/res, + z = pos.z + dir.z} + + local p = "painting:pixel_"..grid[x][y] + p = minetest.env:add_entity(np, pix):get_luaentity() + p.object:setyaw(math.pi*fd/-2) + p.pos={x=x, y=y} + p.name="easel" + end + end + end, + + after_dig_node=function(pos, oldnode, oldmetadata, digger) + --this is the imagestring that creates the texture + local data = "[combine:"..res.."x"..res..":" + for y=0,res-1 do + for x=0, res-1 do + data = data..x..","..y.."="..grid[x][y]..".png:" + end + end + + local easel = { x = pos.x, y = pos.y - 1, z = pos.z } + minetest.env:get_meta(easel):set_int("has_canvas", 0) + + local item = { name = "painting:paintedcanvas", count = 1, metadata = data } + digger:get_inventory():add_item("main", item) + + --clean up pixels + initgrid() + for _, e in pairs(minetest.luaentities) do + if e.name == "easel" then + e.object:remove() + end + end + end +} + +-- easel +easelbox = { + type="fixed", + fixed = { + --feet + {-0.4, -0.5, -0.5, -0.3, -0.4, 0.5 }, + { 0.3, -0.5, -0.5, 0.4, -0.4, 0.5 }, + --legs + {-0.4, -0.4, 0.1, -0.3, 1.5, 0.2 }, + { 0.3, -0.4, 0.1, 0.4, 1.5, 0.2 }, + --shelf + {-0.5, 0.35, -0.3, 0.5, 0.45, 0.1 } + } +} + +easel = { + description = 'easel', + tiles = { "default_wood.png" }, + drawtype = "nodebox", + sunlight_propagates = true, + paramtype = 'light', + paramtype2 = "facedir", + node_box = easelbox, + selection_box = easelbox, + + groups = { snappy = 2, choppy = 2, oddly_breakable_by_hand = 2 }, + + on_punch = function(pos, node, player) + local wielded = player:get_wielded_item():get_name() + if wielded ~= 'painting:canvas' then + return + end + local meta = minetest.env:get_meta(pos) + local np = { x = pos.x, y = pos.y+1, z = pos.z } + + if minetest.env:get_node(np).name == "air" then + minetest.env:add_node(np, { name = "painting:canvasnode", + param2 = node["param2"], + paramtype2 = 'none' }) + end + + meta:set_int("has_canvas", 1) + local itemstack = ItemStack("painting:canvas") + player:get_inventory():remove_item("main", itemstack) + end, + + can_dig = function(pos,player) + local meta = minetest.env:get_meta(pos) + local inv = meta:get_inventory() + + if meta:get_int("has_canvas") == 0 then + return true + end + return false + end +} + +--pixel and brushes +local c = 1/(res*2) +local p = "white.png" + +pixel = { + physical = true, + collisionbox = { -c, -c, -c, c, c, c }, + visual = "cube", + textures = { p, p, p, p, p, p }, + visual_size = { x = 1/res, y = 1/res }, + automatic_rotate = false, + + on_punch = function(self, hitter) + local name = hitter:get_wielded_item():get_name() + name = string.split(name, "_")[2] + + grid[self.pos.x][self.pos.y]=name + + local p = textures[name] + if p then + self.object:set_properties({textures = { p, p, p, p, p, p }}) + end + end +} + +brush = { + description = "brush", + inventory_image = "default_tool_steelaxe.png", + wield_image = "", + wield_scale = {x=1,y=1,z=1}, + stack_max = 99, + liquids_pointable = false, + tool_capabilities = { + full_punch_interval = 1.0, + max_drop_level=0, + groupcaps={ + -- For example: + fleshy={times={[2]=0.80, [3]=0.40}, maxwear=0.05, maxlevel=1}, + snappy={times={[2]=0.80, [3]=0.40}, maxwear=0.05, maxlevel=1}, + choppy={times={[3]=0.90}, maxwear=0.05, maxlevel=0} + } + } +} + +minetest.register_entity("painting:picent", picent) +minetest.register_node("painting:pic", picnode) + +minetest.register_craftitem("painting:canvas", canvas) +minetest.register_craftitem("painting:paintedcanvas", paintedcanvas) +minetest.register_node("painting:canvasnode", canvasnode) + +minetest.register_node("painting:easel", easel) + +for color, texture in pairs(textures) do + minetest.register_entity("painting:pixel_"..color, pixel) + minetest.register_tool("painting:brush_"..color, brush) +end + +minetest.register_alias('easel', 'painting:easel') +minetest.register_alias('canvas', 'painting:canvas') + +function initgrid() + grid = {} + for x = 0, res-1 do + grid[x] = {} + for y = 0, res-1 do + grid[x][y] = "white" + end + end +end + +initgrid() diff --git a/textures/black.png b/textures/black.png new file mode 100644 index 0000000000000000000000000000000000000000..daa5f56b402c915348be4ed35848331eeebdcb48 GIT binary patch literal 295 zcmeAS@N?(olHy`uVBq!ia0vp^j3CUx0wlM}@Gt=>mUKs7M+SzC{oH>NSwWJ;LGDfr z>(0r%1acITJ%W507^>757#dm_7=8hT8eT9klo~KFyh>nTu$sZZAYL$MSD+10f+@+{ z-GzZ+Rj;xUkjGiz5n0T@z%2~Ij105pNPq;(3LMjcG}sXg$EU`>1#-AOT^vI=t|uq_ z;AdcDVq~~=Oy~?yShd78q9i4;B-JXpC>2OC7#SEE=^B{p8k&U|SXvnySQ(mW8yHy` k7+h4*OGVL;o1c=IR*74~g34((ff^V*UHx3vIVCg!0GvHTv;Y7A literal 0 HcmV?d00001 diff --git a/textures/blue.png b/textures/blue.png new file mode 100644 index 0000000000000000000000000000000000000000..1eb421797bddf96feaa83472980025adcce41b67 GIT binary patch literal 301 zcmeAS@N?(olHy`uVBq!ia0vp^j3CUx1|;Q0k8}blmUKs7M+SzC{oH>NSwWJ;LGDfr z>(0r%1acITJ%W507^>757#dm_7=8hT8eT9klo~KFyh>nTu$sZZAYL$MSD+10f-TA0 z-G$*l2rk&Wd@@jkv%n*=n1O*?7=#%aX3dcR36>Q&rUPlPLl}-vjeiT|@Orv9hHzX@ zPI&P1zdQr88WXpq$@~963DpwUh?11Vl2ohYqEsNoU}Ruuq-$WVYiJf?U}NSwWJ;LGDfr z>(0r%1acITJ%W507^>757#dm_7=8hT8eT9klo~KFyh>nTu$sZZAYL$MSD+10f-TA0 z-G$*l2rk&Wd@@jkv%n*=n1O*?7=#%aX3dcR36>Q&rUPlPLl}-vjeiT|@Orv9hHzX@ zPWbWvl|2LNRi>9}PZs(EB~(jXBT7;dOH!?pi&B9UgOP!uk*mUKs7M+SzC{oH>NSwWJ;LGDfr z>(0r%1acITJ%W507^>757#dm_7=8hT8eT9klo~KFyh>nTu$sZZAYL$MSD+10f+@+{ z-GzZ+Rj;xUkjGiz5n0T@z%2~Ij105pNPq;(3LMjcG}sXg$EU`>1#-AOT^vI=t|zbf z$Irm{gRwgQqUtfAuxg2GL`h0wNvc(HQ7VvPFfuSS(ls#GH8cw`u(UEZurf5$HZZa> kFu16qmx`hxH$NpatrE9}1(nlo0yQvry85}Sb4q9e07MK$AOHXW literal 0 HcmV?d00001 diff --git a/textures/green.png b/textures/green.png new file mode 100644 index 0000000000000000000000000000000000000000..1f965f98a3fd4c986e326a77d309162659d3770b GIT binary patch literal 301 zcmeAS@N?(olHy`uVBq!ia0vp^j3CUx1|;Q0k8}blmUKs7M+SzC{oH>NSwWJ;LGDfr z>(0r%1acITJ%W507^>757#dm_7=8hT8eT9klo~KFyh>nTu$sZZAYL$MSD+10f-TA0 z-33Sk!B6Mi^+1ZVz$3Dlfq`2Xgc%uT&5-~JmK8Xr18J~B7>-Yke+%UBdb&7gTe~DWM4foF7MQ literal 0 HcmV?d00001 diff --git a/textures/lightgrey.png b/textures/lightgrey.png new file mode 100644 index 0000000000000000000000000000000000000000..30baffe850b95b20910472cd10203c99577226cc GIT binary patch literal 295 zcmeAS@N?(olHy`uVBq!ia0vp^j3CUx0wlM}@Gt=>mUKs7M+SzC{oH>NSwWJ;LGDfr z>(0r%1acITJ%W507^>757#dm_7=8hT8eT9klo~KFyh>nTu$sZZAYL$MSD+10f+@+{ z-GzZ+Rj;xUkjGiz5n0T@z%2~Ij105pNPq;(3LMjcG}sXg$EU`>1#-AOT^vI=t|#C4 zF3-SJ$GFe)4DVl{uxg2GL`h0wNvc(HQ7VvPFfuSS(ls#GH8cw`u(UEZurf5$HZZa> kFu16qmx`hxH$NpatrE9}1(nlo0yQvry85}Sb4q9e06-!|7XSbN literal 0 HcmV?d00001 diff --git a/textures/lime.png b/textures/lime.png new file mode 100644 index 0000000000000000000000000000000000000000..9760cf618f4f436c69dcde12cbe595dd50c6b04f GIT binary patch literal 301 zcmeAS@N?(olHy`uVBq!ia0vp^j3CUx1|;Q0k8}blmUKs7M+SzC{oH>NSwWJ;LGDfr z>(0r%1acITJ%W507^>757#dm_7=8hT8eT9klo~KFyh>nTu$sZZAYL$MSD+10f-TA0 z-G$*l2rk&Wd@@jkv%n*=n1O*?7=#%aX3dcR36>Q&rUPlPLl}-vjeiT|@Orv9hHzX@ z_V_jbw>$$|GSfK|sRUb~gldUvL`h0wNvc(HQ7VvPFfuSS(ls#GH8cw`u(UEZurf5$ oHZZa>Fu16qmx`hxH$NpatrE9}1(nlo0yQvry85}Sb4q9e0BWa6oB#j- literal 0 HcmV?d00001 diff --git a/textures/orange.png b/textures/orange.png new file mode 100644 index 0000000000000000000000000000000000000000..e951ba3e782eef83b547c3bd7c9e653d335afb68 GIT binary patch literal 301 zcmeAS@N?(olHy`uVBq!ia0vp^j3CUx1|;Q0k8}blmUKs7M+SzC{oH>NSwWJ;LGDfr z>(0r%1acITJ%W507^>757#dm_7=8hT8eT9klo~KFyh>nTu$sZZAYL$MSD+10f-TA0 z-G$*l2rk&Wd@@jkv%n*=n1O*?7=#%aX3dcR36>Q&rUPlPLl}-vjeiT|@Orv9hHzX@ z{xSdX2YCiI7p81;jal=65~?Mx5hW>!C8<`)MX5lF!N|bSNY}tz*U&7)z|zXtz{=1} o+rY@mz~G{aUMh-)-29Zxv`X9>7F15V3Dm&g>FVdQ&MBb@0I+gOGynhq literal 0 HcmV?d00001 diff --git a/textures/painted.png b/textures/painted.png new file mode 100644 index 0000000000000000000000000000000000000000..c6eac7dddf25b41bce8f2d6b3c5d147e886d1177 GIT binary patch literal 317 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Ea{HEjtmSN`?>!lvI6;x#X;^) z4C~IxyaaL-l0AZa85pY67#JE_7#My5g&JNkFq9fFFuY1&V6d9Oz#v{QXIG#NP=YPV z+ueo1o*|Lp{ER=ZVPJUnh`DxA)De)QRZCnWN>UO_QmvAUQh^kM zk%6I+u7SC(ky(g=ft7)=m7#&QfsvJgfr#F8Llh0U`6-!cmAEye7VGx{H86O(`njxg HN@xNA{=!Zh literal 0 HcmV?d00001 diff --git a/textures/pink.png b/textures/pink.png new file mode 100644 index 0000000000000000000000000000000000000000..63a38b188b667355ebe2ed12cc81c7789eb04aee GIT binary patch literal 301 zcmeAS@N?(olHy`uVBq!ia0vp^j3CUx1|;Q0k8}blmUKs7M+SzC{oH>NSwWJ;LGDfr z>(0r%1acITJ%W507^>757#dm_7=8hT8eT9klo~KFyh>nTu$sZZAYL$MSD+10f-TA0 z-G$*l2rk&Wd@@jkv%n*=n1O*?7=#%aX3dcR36>Q&rUPlPLl}-vjeiT|@Orv9hHzX@ z{&D!je|rYDPfWivOeCU#5~?Mx5hW>!C8<`)MX5lF!N|bSNY}tz*U&7)z|zXtz{=1} o+rY@mz~G{aUMh-)-29Zxv`X9>7F15V3Dm&g>FVdQ&MBb@07AV>Y5)KL literal 0 HcmV?d00001 diff --git a/textures/red.png b/textures/red.png new file mode 100644 index 0000000000000000000000000000000000000000..26f57d272bdbd28f621d126ae279fdeb99a3d1e3 GIT binary patch literal 301 zcmeAS@N?(olHy`uVBq!ia0vp^j3CUx1|;Q0k8}blmUKs7M+SzC{oH>NSwWJ;LGDfr z>(0r%1acITJ%W507^>757#dm_7=8hT8eT9klo~KFyh>nTu$sZZAYL$MSD+10f-TA0 z-33Sk!B6Mi^+1ZVz$3Dlfq`2Xgc%uT&5-~JmK8Xr18J~B7>-Yke+%UBdb&7NSwWJ;LGDfr z>(0r%1acITJ%W507^>757#dm_7=8hT8eT9klo~KFyh>nTu$sZZAYL$MSD+10f-TA0 z-G$*l2rk&Wd@@jkv%n*=n1O*?7=#%aX3dcR36>Q&rUPlPLl}-vjeiT|@Orv9hHzX@ zev$O!zdQr07E`CY#wm~kR7+eVN>UO_QmvAUQh^kMk%6I+u7SC(p;?H5rIoRPm7$ro nfsvJg!9^9lR1^)l`6-!cmAEx5sGN2asDZ)L)z4*}Q$iB}>4QqS literal 0 HcmV?d00001 diff --git a/textures/white.png b/textures/white.png new file mode 100644 index 0000000000000000000000000000000000000000..de406e1578f6cf9db800996b00fda275e2326e22 GIT binary patch literal 295 zcmeAS@N?(olHy`uVBq!ia0vp^j3CUx0wlM}@Gt=>mUKs7M+SzC{oH>NSwWJ;LGDfr z>(0r%1acITJ%W507^>757#dm_7=8hT8eT9klo~KFyh>nTu$sZZAYL$MSD+10f+@+{ z-GzZ+Rj;xUkjGiz5n0T@z%2~Ij105pNPq;(3LMjcG}sXg$EU`>1#-AOT^vI=t|$Na zFVDct!1zBUw&*KRShd78q9i4;B-JXpC>2OC7#SEE=^B{p8k&U|SXvnySQ(mW8yHy` k7+h4*OGVL;o1c=IR*74~g34((ff^V*UHx3vIVCg!06P3d3;+NC literal 0 HcmV?d00001 diff --git a/textures/yellow.png b/textures/yellow.png new file mode 100644 index 0000000000000000000000000000000000000000..140cb7647f83531f13f4181da253267ac8972349 GIT binary patch literal 301 zcmeAS@N?(olHy`uVBq!ia0vp^j3CUx1|;Q0k8}blmUKs7M+SzC{oH>NSwWJ;LGDfr z>(0r%1acITJ%W507^>757#dm_7=8hT8eT9klo~KFyh>nTu$sZZAYL$MSD+10f-TA0 z-G$*l2rk&Wd@@jkv%n*=n1O*?7=#%aX3dcR36>Q&rUPlPLl}-vjeiT|@Orv9hHzX@ z{_(%@p*;ip1*Z3Ttu@nt5~?Mx5hW>!C8<`)MX5lF!N|bSNY}tz*U&7)z|zXtz{=1} o+rY@mz~G{aUMh-)-29Zxv`X9>7F15V3Dm&g>FVdQ&MBb@0CUGn;s5{u literal 0 HcmV?d00001