From 9577a2d0766c80f2061da5ec5e4a66f602ebdc47 Mon Sep 17 00:00:00 2001 From: Joachim Stolberg Date: Sat, 1 May 2021 19:57:25 +0200 Subject: [PATCH] Add cart pusher --- README.md | 7 ++++ api.lua | 2 +- doc.lua | 4 +- init.lua | 1 + locale/minecart.de.tr | 4 +- locale/template.txt | 4 +- nodelib.lua | 5 ++- pusher.lua | 68 +++++++++++++++++++++++++++++++ recording.lua | 2 + textures/minecart_pusher.png | Bin 0 -> 111 bytes textures/minecart_pusher_top.png | Bin 0 -> 126 bytes 11 files changed, 92 insertions(+), 5 deletions(-) create mode 100644 pusher.lua create mode 100644 textures/minecart_pusher.png create mode 100644 textures/minecart_pusher_top.png diff --git a/README.md b/README.md index cab0bb1..0a9f5c2 100644 --- a/README.md +++ b/README.md @@ -90,6 +90,13 @@ to/from Minecarts. To unload a Minecart place the hopper below the rail. To load the Minecart, place the hopper right next to the Minecart. +Cart Pusher +----------- + +Used to push a cart if the cart does not stop directly at a buffer. +The block has to be placed below the rail. + + Cart Speed / Speed Limit Signs ------------------------------ diff --git a/api.lua b/api.lua index e3c431e..c9d6c63 100644 --- a/api.lua +++ b/api.lua @@ -33,7 +33,7 @@ end function minecart.punch_cart(pos, param2, radius, punch_dir) local pos2, node = minecart.get_nodecart_nearby(pos, param2, radius) if pos2 then - minecart.start_nodecart(pos2, node.name) + minecart.start_nodecart(pos2, node.name, nil, punch_dir) return true end -- The entity check is needed for a cart with driver diff --git a/doc.lua b/doc.lua index 309baa9..4c476a5 100644 --- a/doc.lua +++ b/doc.lua @@ -3,7 +3,7 @@ Minecart ======== - Copyright (C) 2019-2020 Joachim Stolberg + Copyright (C) 2019-2021 Joachim Stolberg MIT See license.txt for more information @@ -45,6 +45,8 @@ local landmark_doc = S("Protect your rails with the Landmarks (one Landmark at l local hopper_doc = S("Used to load/unload Minecart. The Hopper can push/pull items to/from chests and drop/pickup items to/from Minecarts. To unload a Minecart place the hopper below the rail. To load the Minecart, place the hopper right next to the Minecart.") +local pusher_doc = S("Used to push a cart if the cart does not stop directly at a buffer. Block has to be placed below the rail.") + local speed_doc = S([[Limit the cart speed with speed limit signs. As before, the speed of the carts is also influenced by power rails. diff --git a/init.lua b/init.lua index 0b9e62a..b1e66b1 100644 --- a/init.lua +++ b/init.lua @@ -38,6 +38,7 @@ dofile(MP .. "/protection.lua") --dofile(MP .. "/tool.lua") # for debugging only dofile(MP .. "/signs.lua") dofile(MP .. "/terminal.lua") +dofile(MP .. "/pusher.lua") if minecart.hopper_enabled then dofile(MP .. "/hopper.lua") diff --git a/locale/minecart.de.tr b/locale/minecart.de.tr index 0a36ad7..4a3a622 100644 --- a/locale/minecart.de.tr +++ b/locale/minecart.de.tr @@ -19,14 +19,15 @@ Primary used to transport items. You can drop items into the Minecart and punch Used as buffer on both rail ends. Needed to be able to record the cart routes=Preckblöcke müssen an beiden Schienenenden platziert sein, so dass Aufzeichnungen der Strecke gemacht werden können. Protect your rails with the Landmarks (one Landmark at least every 16 blocks near the rail)=Schütze deine Schienen mit Hilfe der Meilensteine (ein Meilenstein mindestens alle 16 Blöcke der Strecke entlang) Used to load/unload Minecart. The Hopper can push/pull items to/from chests and drop/pickup items to/from Minecarts. To unload a Minecart place the hopper below the rail. To load the Minecart, place the hopper right next to the Minecart.=Um Wagen zu be- und entladen. Der Hopper kann Gegenstände aus Kisten Holen und legen, sowie diese in Wagen fallen lassen bzw. aus Wagen entnehmen. Um einen Wagen zu entladen, muss der Hopper unter die Schiene platziert werden. Um einen Wagen zu beladen, muss der Hopper direkt neben die Schiene platziert werden. +Used to push a cart if the cart does not stop directly at a buffer. Block has to be placed below the rail.=Wird verwendet, um einen Wagen anzuschieben, wenn der Wagen nicht direkt an einem Puffer anhält. Der Block muss unter der Schiene platziert werden. Minecart=Minecart Minecart, the lean railway transportation automation system=Minecart, das schlanke Schienentransport Automatisierungssystem Minecart Cart=Wagen Minecart Speed Signs=Geschwindigkeitsbegrenzungszeichen Limit the cart speed with speed limit signs.@n@nAs before, the speed of the carts is also influenced by power rails.@nBrake rails are irrelevant, the cart does not brake here.@nThe maximum speed is 8 m/s. This assumes a ratio of power rails@nto normal rails of 1 to 4 on a flat section of rail. A rail section is a@nseries of rail nodes without a change of direction. After every curve / kink,@nthe speed for the next section of the route is newly determined,@ntaking into account the swing of the cart. This means that a cart can@nroll over short rail sections without power rails.@n@nIn order to additionally brake the cart at certain points@n(at switches or in front of a buffer), speed limit signs can be placed@non the track. With these signs the speed can be reduced to 4, 2, or 1 m / s.@nThe "No speed limit" sign can be used to remove the speed limit.@n@nThe speed limit signs must be placed next to the track so that they can@nbe read from the cart. This allows different speeds in each direction of travel.=Begrenze die Geschwindigkeit der Wagen mit Geschwindigkeitsbegrenzungszeichen@n@nDie Geschwindigkeit der Carts wird wie bisher auch über "power rails" beeinflusst. "Brake rails" sind ohne Bedeutung, das Cart bremst hier nicht. Die maximale Geschwindigkeit beträgt 8 m/s. Dies setzt eine Verhältnis von "power rails" zu "normal rails" von 1 zu 4 auf einem ebenen Streckenabschnitt voraus. Ein Streckenabschnitt ist dabei ein Reihe von Schienenblöcken ohne Richtungsänderung. Nach jeder Kurve/Knick wird die Geschwindigkeit für den nächsten Streckenabschnitt neu bestimmt, wobei hier der Schwung des Carts mit berücksichtigt wird. So kann ein Cart auch über kurze Streckenabschnitt ohne "power rails" rollen.@n@nUm das Cart zusätzlich an bestimmten Stellen abzubremsen (an Weichen oder vor einen Puffer), können Geschwindigkeitsbegrenzungszeichen an der Strecke platziert werden. Durch diese Zeichen kann die Geschwindigkeit auf 4, 2, oder 1 m/s reduziert werden. Durch das Aufhebungszeichen kann die Geschwindigkeitsbegrenzung wieder aufgehoben werden.@n@nDie Geschwindigkeitsbegrenzungszeichen müssen so neben die Strecke platziert werden, dass sie vom Cart ablesbar sind. Dies erlaubt damit unterschiedliche Geschwindigkeiten pro Fahrtrichtung. Minecart Railway Buffer=Minecart Prellbock -Minecart Landmark=Minecart Meilenstein Minecart Hopper=Minecart Hopper +Minecart Landmark=Minecart Meilenstein Minecart (Sneak+Click to pick up)=Minecart (Shift+Klick zum Entfernen des Carts) Output cart state and position, or a list of carts, if no cart number is given.=Gibt Status und Position des Wagens, oder eine Liste aller Wagen aus, wenn keine Wagennummer angegeben ist. List of carts=Liste aller Wagen @@ -34,6 +35,7 @@ Enter cart number=Gebe Cart Nummer ein Save=Speichern [minecart] Area is protected!=[minecart] Bereich ist geschützt! Allow to dig/place rails in Minecart Landmark areas=Erlaubt dir, Schienen in Meilensteinbereichen zu setzen/zu entfernen +Cart Pusher=Wagen Anschieber left=links right=rechts straight=geradeaus diff --git a/locale/template.txt b/locale/template.txt index 009fcd4..4b4fcd6 100644 --- a/locale/template.txt +++ b/locale/template.txt @@ -19,14 +19,15 @@ Primary used to transport items. You can drop items into the Minecart and punch Used as buffer on both rail ends. Needed to be able to record the cart routes= Protect your rails with the Landmarks (one Landmark at least every 16 blocks near the rail)= Used to load/unload Minecart. The Hopper can push/pull items to/from chests and drop/pickup items to/from Minecarts. To unload a Minecart place the hopper below the rail. To load the Minecart, place the hopper right next to the Minecart.= +Used to push a cart if the cart does not stop directly at a buffer. Block has to be placed below the rail.= Minecart= Minecart, the lean railway transportation automation system= Minecart Cart= Minecart Speed Signs= Limit the cart speed with speed limit signs.@n@nAs before, the speed of the carts is also influenced by power rails.@nBrake rails are irrelevant, the cart does not brake here.@nThe maximum speed is 8 m/s. This assumes a ratio of power rails@nto normal rails of 1 to 4 on a flat section of rail. A rail section is a@nseries of rail nodes without a change of direction. After every curve / kink,@nthe speed for the next section of the route is newly determined,@ntaking into account the swing of the cart. This means that a cart can@nroll over short rail sections without power rails.@n@nIn order to additionally brake the cart at certain points@n(at switches or in front of a buffer), speed limit signs can be placed@non the track. With these signs the speed can be reduced to 4, 2, or 1 m / s.@nThe "No speed limit" sign can be used to remove the speed limit.@n@nThe speed limit signs must be placed next to the track so that they can@nbe read from the cart. This allows different speeds in each direction of travel.= Minecart Railway Buffer= -Minecart Landmark= Minecart Hopper= +Minecart Landmark= Minecart (Sneak+Click to pick up)= Output cart state and position, or a list of carts, if no cart number is given.= List of carts= @@ -34,6 +35,7 @@ Enter cart number= Save= [minecart] Area is protected!= Allow to dig/place rails in Minecart Landmark areas= +Cart Pusher= left= right= straight= diff --git a/nodelib.lua b/nodelib.lua index 674bdd4..efb540c 100644 --- a/nodelib.lua +++ b/nodelib.lua @@ -25,7 +25,7 @@ function minecart.get_nodecart_nearby(pos, param2, radius) end -- Convert node to entity and start cart -function minecart.start_nodecart(pos, node_name, puncher) +function minecart.start_nodecart(pos, node_name, puncher, punch_dir) local owner = M(pos):get_string("owner") local userID = M(pos):get_int("userID") -- check if valid cart @@ -45,6 +45,9 @@ function minecart.start_nodecart(pos, node_name, puncher) if puncher then local yaw = puncher:get_look_horizontal() entity.object:set_rotation({x = 0, y = yaw, z = 0}) + elseif punch_dir then + local yaw = minetest.dir_to_yaw(punch_dir) + entity.object:set_rotation({x = 0, y = yaw, z = 0}) end minecart.start_entitycart(entity, pos) end diff --git a/pusher.lua b/pusher.lua new file mode 100644 index 0000000..1d6687c --- /dev/null +++ b/pusher.lua @@ -0,0 +1,68 @@ +--[[ + + Minecart + ======== + + Copyright (C) 2019-2021 Joachim Stolberg + + MIT + See license.txt for more information + +]]-- + +-- for lazy programmers +local M = minetest.get_meta +local S = minecart.S +local CYCLE_TIME = 4 + +local function node_timer(pos) + local node = minetest.get_node(pos) + local dir = minetest.facedir_to_dir((node.param2) % 4) + print(minetest.pos_to_string(dir)) + minecart.punch_cart({x = pos.x, y = pos.y + 1, z = pos.z}, nil, 0.5, dir) + return true +end + + +local function after_dig_node(pos, oldnode, oldmetadata, digger) + techage.remove_node(pos, oldnode, oldmetadata) +end + +minetest.register_node("minecart:cart_pusher", { + description = S("Cart Pusher"), + drawtype = "nodebox", + node_box = { + type = "fixed", + fixed = { + {-8/16,-8/16,-8/16, 8/16, 8/16, 8/16}, + {-1/16, 8/16,-4/16, 1/16, 10/16, 4/16}, + }, + }, + tiles = { + -- up, down, right, left, back, front + "default_steel_block.png^minecart_pusher_top.png", + "default_steel_block.png", + "default_steel_block.png^minecart_pusher.png", + "default_steel_block.png^minecart_pusher.png", + "default_steel_block.png^minecart_pusher.png", + "default_steel_block.png^minecart_pusher.png", + }, + after_place_node = function(pos) + minetest.get_node_timer(pos):start(CYCLE_TIME) + end, + + on_timer = node_timer, + paramtype2 = "facedir", + groups = {choppy=2, cracky=2, crumbly=2}, + is_ground_content = true, + sounds = default.node_sound_metal_defaults(), +}) + +minetest.register_craft({ + output = "minecart:cart_pusher", + recipe = { + {"dye:black", "default:steel_ingot", "dye:yellow"}, + {"default:steel_ingot", "default:mese_crystal", "default:steel_ingot"}, + {"default:steel_ingot", "default:steel_ingot", "default:steel_ingot"}, + }, +}) diff --git a/recording.lua b/recording.lua index 47d3716..d516a47 100644 --- a/recording.lua +++ b/recording.lua @@ -155,6 +155,8 @@ function minecart.recording_junctions(self) self.ctrl = {left = true} elseif ctrl.right then self.ctrl = {right = true} + elseif ctrl.up or ctrl.down then + self.ctrl = nil end end if self.hud_time <= self.timebase then diff --git a/textures/minecart_pusher.png b/textures/minecart_pusher.png new file mode 100644 index 0000000000000000000000000000000000000000..12704ed6821d78e8b458bc31893f3583750c0586 GIT binary patch literal 111 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!93?!50ihlx9oB=)|uI>dsK<4i^%ttILegIjF zB|(0{3=Yq3qyaf1o-U3d9M_XQn3>vUIvjA|Y?#f&V6Dvlb7krOqd<8EPgg&ebxsLQ E087mr>Hq)$ literal 0 HcmV?d00001 diff --git a/textures/minecart_pusher_top.png b/textures/minecart_pusher_top.png new file mode 100644 index 0000000000000000000000000000000000000000..f0c4179545aacf476a6cce04486be0e3a5559a08 GIT binary patch literal 126 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!93?!50ihlx9JOMr-uI>ds{=U9I-tRZe{#}cB zfGoz6AirP+hi5m^fE)!+7sn8e>&XcTB?&;l%OJE!ktg859R`ⅆ%$nObop9*hK9A Sbu|LjGI+ZBxvX