Add reset recipe and stack-ability (#18)
only identical compasses can be stacked also needle needs to point in same direction adds runtime changeable option to use a stack for calibrating and jumping set ccompass.stack_max to 1 for previous behaviour adds recipe to reset compass
This commit is contained in:
parent
9845a89ec5
commit
4213e60d11
13
README.md
13
README.md
@ -15,6 +15,8 @@ This minetest mod adds a calibratable compass to the minetest. Original mod [her
|
||||
3. Now this compass leads you allways to this location. You can give it away to allow other users to find this place.
|
||||
4. Punch a teleport compatible node (by default mese block) to teleport back to the calibrated place
|
||||
|
||||
Depending on servers many aspects can be different, see below.
|
||||
|
||||
## For server owners:
|
||||
The mod support the next settings:
|
||||
|
||||
@ -29,7 +31,8 @@ The mod support the next settings:
|
||||
ccompass_nodes_over_target_allow_drawtypes: List of drawtypes to allow to be over target. Defaults are: airlike, flowingliquid, liquid, plantlike and plantlike_rooted
|
||||
ccompass_deny_climbable_target: Disabled by default -> allows climbable nodes to be over target. Set to true to not allow them.
|
||||
ccompass_allow_damage_target: Disabled by default -> will not teleport player into or over damaging nodes.
|
||||
|
||||
ccompass_stack_max: 1 by default. Sets maximum stack size, 1 to 65535
|
||||
ccompass_allow_using_stacks: Disabled by default -> calibrating and teleporting only works when single compass in hand. Setting to true, allows callibrating stacks to same location.
|
||||
|
||||
## For developers:
|
||||
1. It is possible to change compass settings from other mods by changing values in global table ccompass. So it is possible for example to add a waypoint node to the target-nodes by
|
||||
@ -44,6 +47,8 @@ The mod support the next settings:
|
||||
ccompass.nodes_over_target_allow_drawtypes["liquid"] = nil
|
||||
ccompass.allow_climbable_target = false
|
||||
ccompass.allow_damaging_target = true
|
||||
ccompass.allow_using_stacks = true
|
||||
ccompass.stack_max = 42
|
||||
```
|
||||
Also you can override ccompass.is_safe_target(target, nodename) for more granular checks.
|
||||
By default first nodes_over_target_allow is checked, then nodes_over_target_deny
|
||||
@ -63,7 +68,7 @@ more granular checks on what is under players feet.
|
||||
end,
|
||||
```
|
||||
|
||||
3. It is possible to create pre-calibrated compasses trough other mods. Just write the position to the Itemstack meta:
|
||||
3. It is possible to create pre-calibrated compasses through other mods. Just write the position to the Itemstack meta:
|
||||
|
||||
```
|
||||
stack:get_meta():set_string("target_pos", minetest.pos_to_string(pos))
|
||||
@ -88,3 +93,7 @@ more granular checks on what is under players feet.
|
||||
end
|
||||
```
|
||||
|
||||
5. Setting ccompass.stack_max to 1 restores behaviour prior to stackable feature.
|
||||
Or going the other way: set ccompass.stack_max to 777 and also set ccompass.allow_using_stacks to true.
|
||||
This would allow players to make a big number of copies at once.
|
||||
|
||||
|
24
init.lua
24
init.lua
@ -66,6 +66,10 @@ else
|
||||
}
|
||||
end
|
||||
|
||||
-- default to legacy behaviour
|
||||
ccompass.stack_max = tonumber(minetest.settings:get("ccompass_stack_max") or 1) or 1
|
||||
ccompass.allow_using_stacks = minetest.settings:get_bool("ccompass_allow_using_stacks")
|
||||
|
||||
if minetest.settings:get_bool("ccompass_aliasses") then
|
||||
minetest.register_alias("compass:0", "ccompass:0")
|
||||
minetest.register_alias("compass:1", "ccompass:1")
|
||||
@ -229,7 +233,7 @@ local function teleport_above(playername, target, counter)
|
||||
end
|
||||
end
|
||||
|
||||
-- get right image number for players compas
|
||||
-- get right image number for players compass
|
||||
local function get_compass_stack(player, stack)
|
||||
local target = get_destination(player, stack)
|
||||
local pos = player:get_pos()
|
||||
@ -245,7 +249,7 @@ local function get_compass_stack(player, stack)
|
||||
-- create new stack with metadata copied
|
||||
local metadata = stack:get_meta():to_table()
|
||||
|
||||
local newstack = ItemStack("ccompass:"..compass_image)
|
||||
local newstack = ItemStack("ccompass:"..compass_image.." "..stack:get_count())
|
||||
if metadata then
|
||||
newstack:get_meta():from_table(metadata)
|
||||
end
|
||||
@ -257,6 +261,11 @@ end
|
||||
|
||||
-- Calibrate compass on pointed_thing
|
||||
local function on_use_function(itemstack, player, pointed_thing)
|
||||
-- if using with a bunch together, need to check server preference
|
||||
if 1 ~= itemstack:get_count() and not ccompass.allow_using_stacks then
|
||||
minetest.chat_send_player(player:get_player_name(), "Use a single compass.")
|
||||
return
|
||||
end
|
||||
-- possible only on nodes
|
||||
if pointed_thing.type ~= "node" then --support nodes only for destination
|
||||
minetest.chat_send_player(player:get_player_name(), "Calibration can be done on nodes only")
|
||||
@ -357,13 +366,21 @@ for i = 0, 15 do
|
||||
if i > 0 then
|
||||
groups.not_in_creative_inventory = 1
|
||||
end
|
||||
minetest.register_tool("ccompass:"..i, {
|
||||
local itemname = "ccompass:"..i
|
||||
minetest.register_craftitem(itemname, {
|
||||
description = "Compass",
|
||||
inventory_image = image,
|
||||
wield_image = image,
|
||||
stack_max = ccompass.stack_max or 42,
|
||||
groups = groups,
|
||||
on_use = on_use_function,
|
||||
})
|
||||
-- reset recipe
|
||||
minetest.register_craft({
|
||||
type = "shapeless",
|
||||
output = "ccompass:0",
|
||||
recipe = { itemname }
|
||||
})
|
||||
end
|
||||
|
||||
minetest.register_craft({
|
||||
@ -374,3 +391,4 @@ minetest.register_craft({
|
||||
{'', 'default:steel_ingot', ''}
|
||||
}
|
||||
})
|
||||
|
||||
|
@ -33,3 +33,9 @@ ccompass_nodes_over_target_allow_drawtypes (Drawtypes of nodes allowed over targ
|
||||
# To allow this, change to true.
|
||||
ccompass_allow_damage_target (Enable to allow teleporting into damaging nodes) bool false
|
||||
|
||||
# Maximum size of compass stacks. Only identical and same direction pointing compasses can be stacked.
|
||||
# Defaults to 1
|
||||
ccompass_stack_max (Sets maximum stack size) 1 1 65535
|
||||
# Requires stack_max greater than 1. When true, allows a whole stack to be calibrated at the same time.
|
||||
ccompass_allow_using_stacks (Enable to allow callibrating stacks) bool false
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user