update powerbanks
This commit is contained in:
parent
5970fcdbef
commit
ea3d71bab7
27
powerbanks/CHANGELOG.md
Normal file
27
powerbanks/CHANGELOG.md
Normal file
@ -0,0 +1,27 @@
|
||||
# Changelog
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
|
||||
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
## [1.0.1] - 2020-04-05
|
||||
|
||||
### Changed
|
||||
|
||||
- Switched to using `technic.pretty_num` instead of `technic.EU_string` for compatibility.
|
||||
- Small changes to README to improve readability.
|
||||
- Node now drops empty powerbank instead of nothing if it gets dug (though this should never happen normally).
|
||||
|
||||
### Fixed
|
||||
|
||||
- Duplication bug with nodes that take the wielded itemstack on right-click (such as `xdecor` item frames).
|
||||
|
||||
## 1.0.0 - 2019-12-14
|
||||
|
||||
- Initial versioned release.
|
||||
|
||||
[Unreleased]: https://github.com/OgelGames/powerbanks/compare/v1.0.1...HEAD
|
||||
[1.0.1]: https://github.com/OgelGames/powerbanks/compare/v1.0.0...v1.0.1
|
@ -1,6 +1,6 @@
|
||||
## License
|
||||
|
||||
Except for the exceptions stated below, all code is licensed under the [MIT License](LICENSE.md#mit-license), with textures licensed under the [CC BY-SA 4.0 License](LICENSE.md#cc-by-sa-40-license).
|
||||
Except for the exceptions stated below, all code is licensed under the [MIT License](LICENSE.md#mit-license), with all textures, models, sounds, and other media licensed under the [CC BY-SA 4.0 License](LICENSE.md#cc-by-sa-40-license).
|
||||
|
||||
## Exceptions
|
||||
|
||||
@ -8,11 +8,15 @@ For [powerbanks_base.png](textures/powerbanks_base.png), which is renamed from s
|
||||
|
||||
- CC-BY-SA 3.0 UNPORTED. Created by DOOMED
|
||||
|
||||
## Notes
|
||||
|
||||
-
|
||||
|
||||
## MIT License
|
||||
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2019 OgelGames
|
||||
Copyright (c) 2019-2020 OgelGames
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -1,6 +1,6 @@
|
||||
# powerbanks
|
||||
# Powerbanks [powerbanks]
|
||||
|
||||
[![Build Status](https://travis-ci.org/OgelGames/powerbanks.svg?branch=master)](https://travis-ci.org/OgelGames/powerbanks)
|
||||
[![Build](https://github.com/OgelGames/powerbanks/workflows/Build/badge.svg)](https://github.com/OgelGames/powerbanks/actions)
|
||||
[![License](https://img.shields.io/badge/License-MIT%20and%20CC%20BY--SA%204.0-green.svg)](LICENSE.md)
|
||||
[![Feedback](https://img.shields.io/badge/Feedback-Minetest%20Forum-lightgrey.svg)](https://forum.minetest.net/viewtopic.php?t=23791)
|
||||
[![Download](https://img.shields.io/badge/Download-ContentDB-blue.svg)](https://content.minetest.net/packages/OgelGames/powerbanks)
|
||||
@ -76,16 +76,18 @@ Currently there are three different powerbanks:
|
||||
|
||||
## Dependencies
|
||||
|
||||
Currently this mod only depends on the default and [technic](https://github.com/minetest-mods/technic) mods.
|
||||
**Required**
|
||||
|
||||
- `default` (included in [Minetest Game](https://github.com/minetest/minetest_game))
|
||||
|
||||
- [`technic`](https://github.com/minetest-mods/technic)
|
||||
|
||||
## Installation
|
||||
|
||||
To install this mod, simply download it using one of the methods below, and place it in one of [Minetest's mod folders](https://dev.minetest.net/Installing_Mods).
|
||||
Download the [master branch](https://github.com/OgelGames/powerbanks/archive/master.zip) or the [latest release](https://github.com/OgelGames/powerbanks/releases), or clone the repository using Git or the [GitHub Desktop](https://desktop.github.com/) app, and follow [these instructions](https://dev.minetest.net/Installing_Mods).
|
||||
|
||||
- Clone the Git repository using `git clone https://github.com/OgelGames/powerbanks.git` or the [GitHub Desktop](https://desktop.github.com/) app.
|
||||
- Download the Git repository as a ZIP file: https://github.com/OgelGames/powerbanks/archive/master.zip
|
||||
- Download the latest stable release: https://github.com/OgelGames/powerbanks/releases
|
||||
Alternatively, you can download and install the mod from [ContentDB](https://content.minetest.net/packages/OgelGames/powerbanks) from the online content tab in Minetest.
|
||||
|
||||
## License
|
||||
|
||||
Except for the exceptions stated in [LICENSE.md](LICENSE.md#exceptions), all code is licensed under the [MIT License](LICENSE.md#mit-license), with textures licensed under the [CC BY-SA 4.0 License](LICENSE.md#cc-by-sa-40-license).
|
||||
Except for any exceptions stated in [LICENSE.md](LICENSE.md#exceptions), all code is licensed under the [MIT License](LICENSE.md#mit-license), with all textures, models, sounds, and other media licensed under the [CC BY-SA 4.0 License](LICENSE.md#cc-by-sa-40-license).
|
||||
|
@ -38,22 +38,20 @@ local function update_formspec(pos, charge, data)
|
||||
|
||||
local new_formspec = base_formspec..
|
||||
"label[0,0;Powerbank Mk"..data.mark.."]"..
|
||||
"label[5.4,2.25;Power Remaining: "..technic.EU_string(charge).."]"..
|
||||
"label[5.4,2.25;Power Remaining: "..technic.pretty_num(charge).."EU]"..
|
||||
"box[5.45,1.25;"..(fraction * 2.12)..",0.8;"..color.."]"
|
||||
|
||||
minetest.get_meta(pos):set_string("formspec", new_formspec)
|
||||
end
|
||||
|
||||
local function update_infotext(pos, is_charging, data)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local current_charge = technic.EU_string(meta:get_int("charge"))
|
||||
local max_charge = technic.EU_string(data.max_charge)
|
||||
|
||||
local status = "Idle"
|
||||
if is_charging then
|
||||
status = "Charging"
|
||||
end
|
||||
local current_charge = technic.pretty_num(meta:get_int("charge")).."EU"
|
||||
local max_charge = technic.pretty_num(data.max_charge).."EU"
|
||||
local status = is_charging and "Charging" or "Idle"
|
||||
|
||||
local infotext = "Powerbank Mk"..data.mark..": "..current_charge.." / "..max_charge.." "..status
|
||||
|
||||
meta:set_string("infotext", infotext)
|
||||
end
|
||||
|
||||
@ -85,7 +83,7 @@ local function do_charging(pos, charge_step, data)
|
||||
for i = 1, inv:get_size("main") do
|
||||
local stack = inv:get_stack("main", i)
|
||||
local item_fully_charged
|
||||
if (not stack:is_empty()) and (current_charge > 0) then
|
||||
if current_charge > 0 and not stack:is_empty()then
|
||||
stack, current_charge, item_fully_charged = charge_item(stack, current_charge, charge_step)
|
||||
inv:set_stack("main", i, stack)
|
||||
|
||||
@ -99,24 +97,17 @@ local function do_charging(pos, charge_step, data)
|
||||
update_infotext(pos, still_charging, data)
|
||||
update_formspec(pos, current_charge, data)
|
||||
|
||||
return still_charging and (current_charge > 0)
|
||||
return still_charging and current_charge > 0
|
||||
end
|
||||
|
||||
local function create_itemstack(metadata, is_node, data)
|
||||
if not metadata.charge then
|
||||
metadata.charge = 0
|
||||
end
|
||||
local extension = ""
|
||||
if is_node then
|
||||
extension = "_node"
|
||||
end
|
||||
local itemstack = ItemStack({
|
||||
name = "powerbanks:powerbank_mk"..data.mark..extension,
|
||||
name = "powerbanks:powerbank_mk"..data.mark..(is_node and "_node" or ""),
|
||||
count = 1,
|
||||
metadata = minetest.serialize({charge = metadata.charge})
|
||||
metadata = minetest.serialize({charge = metadata.charge or 0})
|
||||
})
|
||||
if not is_node then
|
||||
technic.set_RE_wear(itemstack, metadata.charge, data.max_charge)
|
||||
technic.set_RE_wear(itemstack, metadata.charge or 0, data.max_charge)
|
||||
end
|
||||
return itemstack
|
||||
end
|
||||
@ -134,7 +125,7 @@ local function register_powerbank(data)
|
||||
},
|
||||
groups = {not_in_creative_inventory = 1},
|
||||
is_ground_content = false,
|
||||
drop = "",
|
||||
drop = "powerbanks:powerbank_mk"..data.mark,
|
||||
diggable = false,
|
||||
can_dig = function(pos, digger)
|
||||
return false
|
||||
@ -227,18 +218,27 @@ local function register_powerbank(data)
|
||||
wear_represents = "technic_RE_charge",
|
||||
on_refill = technic.refill_RE_charge,
|
||||
on_place = function(itemstack, placer, pointed_thing)
|
||||
-- check for on_rightclick
|
||||
if pointed_thing.type == "node" and placer and not placer:get_player_control().sneak then
|
||||
local node = minetest.get_node(pointed_thing.under)
|
||||
local def = minetest.registered_nodes[node.name]
|
||||
if def and def.on_rightclick then
|
||||
return def.on_rightclick(pointed_thing.under, node, placer, itemstack, pointed_thing) or itemstack, false
|
||||
end
|
||||
end
|
||||
|
||||
-- create fake itemstack of node to place
|
||||
local item_meta = minetest.deserialize(itemstack:get_metadata()) or {}
|
||||
local node_itemstack = create_itemstack(item_meta, true, data)
|
||||
|
||||
-- place node like player
|
||||
local _, placed = minetest.item_place(node_itemstack, placer, pointed_thing)
|
||||
local new_itemstack, placed = minetest.item_place_node(node_itemstack, placer, pointed_thing)
|
||||
|
||||
-- remove powerbank from inventory if placed
|
||||
if placed then
|
||||
if placed or new_itemstack:is_empty() then
|
||||
itemstack:clear()
|
||||
end
|
||||
return itemstack
|
||||
return itemstack, placed
|
||||
end
|
||||
})
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user