3 Commits

Author SHA1 Message Date
49dcd970a0 Fix setting name typo. 2013-06-02 18:35:16 -04:00
ddcdc74fd3 Merge pull request #103 from Novatux/globalstep
Change mesecons signals so that they update effectors only after a globalstep
2013-06-02 09:08:20 -07:00
62a8ae240c Change mesecons signals so that they update effectors only after a globalstep, configurable to be on/off 2013-06-01 19:06:31 +02:00
198 changed files with 1024 additions and 2277 deletions

View File

@ -1,532 +0,0 @@
The LGPLv3 applies to all code in this project.
The CC-BY-SA-3.0 license applies to textures and any other content in this project which is not source code.
=================================================================
GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
This version of the GNU Lesser General Public License incorporates
the terms and conditions of version 3 of the GNU General Public
License, supplemented by the additional permissions listed below.
0. Additional Definitions.
As used herein, "this License" refers to version 3 of the GNU Lesser
General Public License, and the "GNU GPL" refers to version 3 of the GNU
General Public License.
"The Library" refers to a covered work governed by this License,
other than an Application or a Combined Work as defined below.
An "Application" is any work that makes use of an interface provided
by the Library, but which is not otherwise based on the Library.
Defining a subclass of a class defined by the Library is deemed a mode
of using an interface provided by the Library.
A "Combined Work" is a work produced by combining or linking an
Application with the Library. The particular version of the Library
with which the Combined Work was made is also called the "Linked
Version".
The "Minimal Corresponding Source" for a Combined Work means the
Corresponding Source for the Combined Work, excluding any source code
for portions of the Combined Work that, considered in isolation, are
based on the Application, and not on the Linked Version.
The "Corresponding Application Code" for a Combined Work means the
object code and/or source code for the Application, including any data
and utility programs needed for reproducing the Combined Work from the
Application, but excluding the System Libraries of the Combined Work.
1. Exception to Section 3 of the GNU GPL.
You may convey a covered work under sections 3 and 4 of this License
without being bound by section 3 of the GNU GPL.
2. Conveying Modified Versions.
If you modify a copy of the Library, and, in your modifications, a
facility refers to a function or data to be supplied by an Application
that uses the facility (other than as an argument passed when the
facility is invoked), then you may convey a copy of the modified
version:
a) under this License, provided that you make a good faith effort to
ensure that, in the event an Application does not supply the
function or data, the facility still operates, and performs
whatever part of its purpose remains meaningful, or
b) under the GNU GPL, with none of the additional permissions of
this License applicable to that copy.
3. Object Code Incorporating Material from Library Header Files.
The object code form of an Application may incorporate material from
a header file that is part of the Library. You may convey such object
code under terms of your choice, provided that, if the incorporated
material is not limited to numerical parameters, data structure
layouts and accessors, or small macros, inline functions and templates
(ten or fewer lines in length), you do both of the following:
a) Give prominent notice with each copy of the object code that the
Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the object code with a copy of the GNU GPL and this license
document.
4. Combined Works.
You may convey a Combined Work under terms of your choice that,
taken together, effectively do not restrict modification of the
portions of the Library contained in the Combined Work and reverse
engineering for debugging such modifications, if you also do each of
the following:
a) Give prominent notice with each copy of the Combined Work that
the Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the Combined Work with a copy of the GNU GPL and this license
document.
c) For a Combined Work that displays copyright notices during
execution, include the copyright notice for the Library among
these notices, as well as a reference directing the user to the
copies of the GNU GPL and this license document.
d) Do one of the following:
0) Convey the Minimal Corresponding Source under the terms of this
License, and the Corresponding Application Code in a form
suitable for, and under terms that permit, the user to
recombine or relink the Application with a modified version of
the Linked Version to produce a modified Combined Work, in the
manner specified by section 6 of the GNU GPL for conveying
Corresponding Source.
1) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (a) uses at run time
a copy of the Library already present on the user's computer
system, and (b) will operate properly with a modified version
of the Library that is interface-compatible with the Linked
Version.
e) Provide Installation Information, but only if you would otherwise
be required to provide such information under section 6 of the
GNU GPL, and only to the extent that such information is
necessary to install and execute a modified version of the
Combined Work produced by recombining or relinking the
Application with a modified version of the Linked Version. (If
you use option 4d0, the Installation Information must accompany
the Minimal Corresponding Source and Corresponding Application
Code. If you use option 4d1, you must provide the Installation
Information in the manner specified by section 6 of the GNU GPL
for conveying Corresponding Source.)
5. Combined Libraries.
You may place library facilities that are a work based on the
Library side by side in a single library together with other library
facilities that are not Applications and are not covered by this
License, and convey such a combined library under terms of your
choice, if you do both of the following:
a) Accompany the combined library with a copy of the same work based
on the Library, uncombined with any other library facilities,
conveyed under the terms of this License.
b) Give prominent notice with the combined library that part of it
is a work based on the Library, and explaining where to find the
accompanying uncombined form of the same work.
6. Revised Versions of the GNU Lesser General Public License.
The Free Software Foundation may publish revised and/or new versions
of the GNU Lesser General Public License from time to time. Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the
Library as you received it specifies that a certain numbered version
of the GNU Lesser General Public License "or any later version"
applies to it, you have the option of following the terms and
conditions either of that published version or of any later version
published by the Free Software Foundation. If the Library as you
received it does not specify a version number of the GNU Lesser
General Public License, you may choose any version of the GNU Lesser
General Public License ever published by the Free Software Foundation.
If the Library as you received it specifies that a proxy can decide
whether future versions of the GNU Lesser General Public License shall
apply, that proxy's public statement of acceptance of any version is
permanent authorization for you to choose that version for the
Library.
=================================================================
Creative Commons Legal Code
Attribution-ShareAlike 3.0 Unported
CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
LEGAL SERVICES. DISTRIBUTION OF THIS LICENSE DOES NOT CREATE AN
ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
REGARDING THE INFORMATION PROVIDED, AND DISCLAIMS LIABILITY FOR
DAMAGES RESULTING FROM ITS USE.
License
THE WORK (AS DEFINED BELOW) IS PROVIDED UNDER THE TERMS OF THIS CREATIVE
COMMONS PUBLIC LICENSE ("CCPL" OR "LICENSE"). THE WORK IS PROTECTED BY
COPYRIGHT AND/OR OTHER APPLICABLE LAW. ANY USE OF THE WORK OTHER THAN AS
AUTHORIZED UNDER THIS LICENSE OR COPYRIGHT LAW IS PROHIBITED.
BY EXERCISING ANY RIGHTS TO THE WORK PROVIDED HERE, YOU ACCEPT AND AGREE
TO BE BOUND BY THE TERMS OF THIS LICENSE. TO THE EXTENT THIS LICENSE MAY
BE CONSIDERED TO BE A CONTRACT, THE LICENSOR GRANTS YOU THE RIGHTS
CONTAINED HERE IN CONSIDERATION OF YOUR ACCEPTANCE OF SUCH TERMS AND
CONDITIONS.
1. Definitions
a. "Adaptation" means a work based upon the Work, or upon the Work and
other pre-existing works, such as a translation, adaptation,
derivative work, arrangement of music or other alterations of a
literary or artistic work, or phonogram or performance and includes
cinematographic adaptations or any other form in which the Work may be
recast, transformed, or adapted including in any form recognizably
derived from the original, except that a work that constitutes a
Collection will not be considered an Adaptation for the purpose of
this License. For the avoidance of doubt, where the Work is a musical
work, performance or phonogram, the synchronization of the Work in
timed-relation with a moving image ("synching") will be considered an
Adaptation for the purpose of this License.
b. "Collection" means a collection of literary or artistic works, such as
encyclopedias and anthologies, or performances, phonograms or
broadcasts, or other works or subject matter other than works listed
in Section 1(f) below, which, by reason of the selection and
arrangement of their contents, constitute intellectual creations, in
which the Work is included in its entirety in unmodified form along
with one or more other contributions, each constituting separate and
independent works in themselves, which together are assembled into a
collective whole. A work that constitutes a Collection will not be
considered an Adaptation (as defined below) for the purposes of this
License.
c. "Creative Commons Compatible License" means a license that is listed
at http://creativecommons.org/compatiblelicenses that has been
approved by Creative Commons as being essentially equivalent to this
License, including, at a minimum, because that license: (i) contains
terms that have the same purpose, meaning and effect as the License
Elements of this License; and, (ii) explicitly permits the relicensing
of adaptations of works made available under that license under this
License or a Creative Commons jurisdiction license with the same
License Elements as this License.
d. "Distribute" means to make available to the public the original and
copies of the Work or Adaptation, as appropriate, through sale or
other transfer of ownership.
e. "License Elements" means the following high-level license attributes
as selected by Licensor and indicated in the title of this License:
Attribution, ShareAlike.
f. "Licensor" means the individual, individuals, entity or entities that
offer(s) the Work under the terms of this License.
g. "Original Author" means, in the case of a literary or artistic work,
the individual, individuals, entity or entities who created the Work
or if no individual or entity can be identified, the publisher; and in
addition (i) in the case of a performance the actors, singers,
musicians, dancers, and other persons who act, sing, deliver, declaim,
play in, interpret or otherwise perform literary or artistic works or
expressions of folklore; (ii) in the case of a phonogram the producer
being the person or legal entity who first fixes the sounds of a
performance or other sounds; and, (iii) in the case of broadcasts, the
organization that transmits the broadcast.
h. "Work" means the literary and/or artistic work offered under the terms
of this License including without limitation any production in the
literary, scientific and artistic domain, whatever may be the mode or
form of its expression including digital form, such as a book,
pamphlet and other writing; a lecture, address, sermon or other work
of the same nature; a dramatic or dramatico-musical work; a
choreographic work or entertainment in dumb show; a musical
composition with or without words; a cinematographic work to which are
assimilated works expressed by a process analogous to cinematography;
a work of drawing, painting, architecture, sculpture, engraving or
lithography; a photographic work to which are assimilated works
expressed by a process analogous to photography; a work of applied
art; an illustration, map, plan, sketch or three-dimensional work
relative to geography, topography, architecture or science; a
performance; a broadcast; a phonogram; a compilation of data to the
extent it is protected as a copyrightable work; or a work performed by
a variety or circus performer to the extent it is not otherwise
considered a literary or artistic work.
i. "You" means an individual or entity exercising rights under this
License who has not previously violated the terms of this License with
respect to the Work, or who has received express permission from the
Licensor to exercise rights under this License despite a previous
violation.
j. "Publicly Perform" means to perform public recitations of the Work and
to communicate to the public those public recitations, by any means or
process, including by wire or wireless means or public digital
performances; to make available to the public Works in such a way that
members of the public may access these Works from a place and at a
place individually chosen by them; to perform the Work to the public
by any means or process and the communication to the public of the
performances of the Work, including by public digital performance; to
broadcast and rebroadcast the Work by any means including signs,
sounds or images.
k. "Reproduce" means to make copies of the Work by any means including
without limitation by sound or visual recordings and the right of
fixation and reproducing fixations of the Work, including storage of a
protected performance or phonogram in digital form or other electronic
medium.
2. Fair Dealing Rights. Nothing in this License is intended to reduce,
limit, or restrict any uses free from copyright or rights arising from
limitations or exceptions that are provided for in connection with the
copyright protection under copyright law or other applicable laws.
3. License Grant. Subject to the terms and conditions of this License,
Licensor hereby grants You a worldwide, royalty-free, non-exclusive,
perpetual (for the duration of the applicable copyright) license to
exercise the rights in the Work as stated below:
a. to Reproduce the Work, to incorporate the Work into one or more
Collections, and to Reproduce the Work as incorporated in the
Collections;
b. to create and Reproduce Adaptations provided that any such Adaptation,
including any translation in any medium, takes reasonable steps to
clearly label, demarcate or otherwise identify that changes were made
to the original Work. For example, a translation could be marked "The
original work was translated from English to Spanish," or a
modification could indicate "The original work has been modified.";
c. to Distribute and Publicly Perform the Work including as incorporated
in Collections; and,
d. to Distribute and Publicly Perform Adaptations.
e. For the avoidance of doubt:
i. Non-waivable Compulsory License Schemes. In those jurisdictions in
which the right to collect royalties through any statutory or
compulsory licensing scheme cannot be waived, the Licensor
reserves the exclusive right to collect such royalties for any
exercise by You of the rights granted under this License;
ii. Waivable Compulsory License Schemes. In those jurisdictions in
which the right to collect royalties through any statutory or
compulsory licensing scheme can be waived, the Licensor waives the
exclusive right to collect such royalties for any exercise by You
of the rights granted under this License; and,
iii. Voluntary License Schemes. The Licensor waives the right to
collect royalties, whether individually or, in the event that the
Licensor is a member of a collecting society that administers
voluntary licensing schemes, via that society, from any exercise
by You of the rights granted under this License.
The above rights may be exercised in all media and formats whether now
known or hereafter devised. The above rights include the right to make
such modifications as are technically necessary to exercise the rights in
other media and formats. Subject to Section 8(f), all rights not expressly
granted by Licensor are hereby reserved.
4. Restrictions. The license granted in Section 3 above is expressly made
subject to and limited by the following restrictions:
a. You may Distribute or Publicly Perform the Work only under the terms
of this License. You must include a copy of, or the Uniform Resource
Identifier (URI) for, this License with every copy of the Work You
Distribute or Publicly Perform. You may not offer or impose any terms
on the Work that restrict the terms of this License or the ability of
the recipient of the Work to exercise the rights granted to that
recipient under the terms of the License. You may not sublicense the
Work. You must keep intact all notices that refer to this License and
to the disclaimer of warranties with every copy of the Work You
Distribute or Publicly Perform. When You Distribute or Publicly
Perform the Work, You may not impose any effective technological
measures on the Work that restrict the ability of a recipient of the
Work from You to exercise the rights granted to that recipient under
the terms of the License. This Section 4(a) applies to the Work as
incorporated in a Collection, but this does not require the Collection
apart from the Work itself to be made subject to the terms of this
License. If You create a Collection, upon notice from any Licensor You
must, to the extent practicable, remove from the Collection any credit
as required by Section 4(c), as requested. If You create an
Adaptation, upon notice from any Licensor You must, to the extent
practicable, remove from the Adaptation any credit as required by
Section 4(c), as requested.
b. You may Distribute or Publicly Perform an Adaptation only under the
terms of: (i) this License; (ii) a later version of this License with
the same License Elements as this License; (iii) a Creative Commons
jurisdiction license (either this or a later license version) that
contains the same License Elements as this License (e.g.,
Attribution-ShareAlike 3.0 US)); (iv) a Creative Commons Compatible
License. If you license the Adaptation under one of the licenses
mentioned in (iv), you must comply with the terms of that license. If
you license the Adaptation under the terms of any of the licenses
mentioned in (i), (ii) or (iii) (the "Applicable License"), you must
comply with the terms of the Applicable License generally and the
following provisions: (I) You must include a copy of, or the URI for,
the Applicable License with every copy of each Adaptation You
Distribute or Publicly Perform; (II) You may not offer or impose any
terms on the Adaptation that restrict the terms of the Applicable
License or the ability of the recipient of the Adaptation to exercise
the rights granted to that recipient under the terms of the Applicable
License; (III) You must keep intact all notices that refer to the
Applicable License and to the disclaimer of warranties with every copy
of the Work as included in the Adaptation You Distribute or Publicly
Perform; (IV) when You Distribute or Publicly Perform the Adaptation,
You may not impose any effective technological measures on the
Adaptation that restrict the ability of a recipient of the Adaptation
from You to exercise the rights granted to that recipient under the
terms of the Applicable License. This Section 4(b) applies to the
Adaptation as incorporated in a Collection, but this does not require
the Collection apart from the Adaptation itself to be made subject to
the terms of the Applicable License.
c. If You Distribute, or Publicly Perform the Work or any Adaptations or
Collections, You must, unless a request has been made pursuant to
Section 4(a), keep intact all copyright notices for the Work and
provide, reasonable to the medium or means You are utilizing: (i) the
name of the Original Author (or pseudonym, if applicable) if supplied,
and/or if the Original Author and/or Licensor designate another party
or parties (e.g., a sponsor institute, publishing entity, journal) for
attribution ("Attribution Parties") in Licensor's copyright notice,
terms of service or by other reasonable means, the name of such party
or parties; (ii) the title of the Work if supplied; (iii) to the
extent reasonably practicable, the URI, if any, that Licensor
specifies to be associated with the Work, unless such URI does not
refer to the copyright notice or licensing information for the Work;
and (iv) , consistent with Ssection 3(b), in the case of an
Adaptation, a credit identifying the use of the Work in the Adaptation
(e.g., "French translation of the Work by Original Author," or
"Screenplay based on original Work by Original Author"). The credit
required by this Section 4(c) may be implemented in any reasonable
manner; provided, however, that in the case of a Adaptation or
Collection, at a minimum such credit will appear, if a credit for all
contributing authors of the Adaptation or Collection appears, then as
part of these credits and in a manner at least as prominent as the
credits for the other contributing authors. For the avoidance of
doubt, You may only use the credit required by this Section for the
purpose of attribution in the manner set out above and, by exercising
Your rights under this License, You may not implicitly or explicitly
assert or imply any connection with, sponsorship or endorsement by the
Original Author, Licensor and/or Attribution Parties, as appropriate,
of You or Your use of the Work, without the separate, express prior
written permission of the Original Author, Licensor and/or Attribution
Parties.
d. Except as otherwise agreed in writing by the Licensor or as may be
otherwise permitted by applicable law, if You Reproduce, Distribute or
Publicly Perform the Work either by itself or as part of any
Adaptations or Collections, You must not distort, mutilate, modify or
take other derogatory action in relation to the Work which would be
prejudicial to the Original Author's honor or reputation. Licensor
agrees that in those jurisdictions (e.g. Japan), in which any exercise
of the right granted in Section 3(b) of this License (the right to
make Adaptations) would be deemed to be a distortion, mutilation,
modification or other derogatory action prejudicial to the Original
Author's honor and reputation, the Licensor will waive or not assert,
as appropriate, this Section, to the fullest extent permitted by the
applicable national law, to enable You to reasonably exercise Your
right under Section 3(b) of this License (right to make Adaptations)
but not otherwise.
5. Representations, Warranties and Disclaimer
UNLESS OTHERWISE MUTUALLY AGREED TO BY THE PARTIES IN WRITING, LICENSOR
OFFERS THE WORK AS-IS AND MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY
KIND CONCERNING THE WORK, EXPRESS, IMPLIED, STATUTORY OR OTHERWISE,
INCLUDING, WITHOUT LIMITATION, WARRANTIES OF TITLE, MERCHANTIBILITY,
FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT, OR THE ABSENCE OF
LATENT OR OTHER DEFECTS, ACCURACY, OR THE PRESENCE OF ABSENCE OF ERRORS,
WHETHER OR NOT DISCOVERABLE. SOME JURISDICTIONS DO NOT ALLOW THE EXCLUSION
OF IMPLIED WARRANTIES, SO SUCH EXCLUSION MAY NOT APPLY TO YOU.
6. Limitation on Liability. EXCEPT TO THE EXTENT REQUIRED BY APPLICABLE
LAW, IN NO EVENT WILL LICENSOR BE LIABLE TO YOU ON ANY LEGAL THEORY FOR
ANY SPECIAL, INCIDENTAL, CONSEQUENTIAL, PUNITIVE OR EXEMPLARY DAMAGES
ARISING OUT OF THIS LICENSE OR THE USE OF THE WORK, EVEN IF LICENSOR HAS
BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
7. Termination
a. This License and the rights granted hereunder will terminate
automatically upon any breach by You of the terms of this License.
Individuals or entities who have received Adaptations or Collections
from You under this License, however, will not have their licenses
terminated provided such individuals or entities remain in full
compliance with those licenses. Sections 1, 2, 5, 6, 7, and 8 will
survive any termination of this License.
b. Subject to the above terms and conditions, the license granted here is
perpetual (for the duration of the applicable copyright in the Work).
Notwithstanding the above, Licensor reserves the right to release the
Work under different license terms or to stop distributing the Work at
any time; provided, however that any such election will not serve to
withdraw this License (or any other license that has been, or is
required to be, granted under the terms of this License), and this
License will continue in full force and effect unless terminated as
stated above.
8. Miscellaneous
a. Each time You Distribute or Publicly Perform the Work or a Collection,
the Licensor offers to the recipient a license to the Work on the same
terms and conditions as the license granted to You under this License.
b. Each time You Distribute or Publicly Perform an Adaptation, Licensor
offers to the recipient a license to the original Work on the same
terms and conditions as the license granted to You under this License.
c. If any provision of this License is invalid or unenforceable under
applicable law, it shall not affect the validity or enforceability of
the remainder of the terms of this License, and without further action
by the parties to this agreement, such provision shall be reformed to
the minimum extent necessary to make such provision valid and
enforceable.
d. No term or provision of this License shall be deemed waived and no
breach consented to unless such waiver or consent shall be in writing
and signed by the party to be charged with such waiver or consent.
e. This License constitutes the entire agreement between the parties with
respect to the Work licensed here. There are no understandings,
agreements or representations with respect to the Work not specified
here. Licensor shall not be bound by any additional provisions that
may appear in any communication from You. This License may not be
modified without the mutual written agreement of the Licensor and You.
f. The rights granted under, and the subject matter referenced, in this
License were drafted utilizing the terminology of the Berne Convention
for the Protection of Literary and Artistic Works (as amended on
September 28, 1979), the Rome Convention of 1961, the WIPO Copyright
Treaty of 1996, the WIPO Performances and Phonograms Treaty of 1996
and the Universal Copyright Convention (as revised on July 24, 1971).
These rights and subject matter take effect in the relevant
jurisdiction in which the License terms are sought to be enforced
according to the corresponding provisions of the implementation of
those treaty provisions in the applicable national law. If the
standard suite of rights granted under applicable copyright law
includes additional rights not granted under this License, such
additional rights are deemed to be included in the License; this
License is not intended to restrict the license of any rights under
applicable law.
Creative Commons Notice
Creative Commons is not a party to this License, and makes no warranty
whatsoever in connection with the Work. Creative Commons will not be
liable to You or any party on any legal theory for any damages
whatsoever, including without limitation any general, special,
incidental or consequential damages arising in connection to this
license. Notwithstanding the foregoing two (2) sentences, if Creative
Commons has expressly identified itself as the Licensor hereunder, it
shall have all rights and obligations of Licensor.
Except for the limited purpose of indicating to the public that the
Work is licensed under the CCPL, Creative Commons does not authorize
the use by either party of the trademark "Creative Commons" or any
related trademark or logo of Creative Commons without the prior
written consent of Creative Commons. Any permitted use will be in
compliance with Creative Commons' then-current trademark usage
guidelines, as may be published on its website or otherwise made
available upon request from time to time. For the avoidance of doubt,
this trademark restriction does not form part of the License.
Creative Commons may be contacted at http://creativecommons.org/.

View File

@ -52,26 +52,24 @@ Who wrote it anyways?
These awesome people made Mesecons possible! These awesome people made Mesecons possible!
| Contributor | Contribution | | Contributor | Contribution |
| --------------- | -------------------------------- | | --------------- | ---------------------------------- |
| Jat15 | Various tweaks. | | Jat15 | Various tweaks. |
| Jeija | **Main developer! Everything.** | | Jeija | **Main developer! Everything.** |
| Jordach | Noteblock sounds. | | Jordach | Noteblock sounds. |
| khonkhortistan | Code, recipes, textures. | | khonkhortistan | Coding, recipes, textures. |
| Kotolegokot | Nodeboxes for items. | | Kotolegokot | Nodeboxes for items. |
| minerd247 | Textures. | | minerd247 | Textures. |
| Nore/Novatux | Code. |
| RealBadAngel | Fixes, improvements. | | RealBadAngel | Fixes, improvements. |
| sfan5 | Code, recipes, textures. | | sfan5 | Coding, recipes, textures. |
| suzenako | Piston sounds. | | Uberi/Temperest | Coding, textures, documentation. |
| Uberi/Temperest | Code, textures, documentation. | | VanessaE | Coding, recipes, textures, design. |
| VanessaE | Code, recipes, textures, design. |
| Whiskers75 | Logic gates implementation. | | Whiskers75 | Logic gates implementation. |
There are also a whole bunch of other people helping with everything from code to testing and feedback. Mesecons would also not be possible without their help! There are also a whole bunch of other people helping with everything from code to testing and feedback. Mesecons would also not be possible without their help!
Alright, how can I use it? Alright, how can I use it?
-------------------------- --------------------------
All textures in this project are licensed under the CC-BY-SA 3.0 (Creative Commons Attribution-ShareAlike 3.0 Generic). That means you can distribute and remix them as much as you want to, under the condition that you give credit to the authors and the project, and that if you remix and release them, they must be under the same or similar license to this one. All textures in this project are licensed under the CC-BY-SA 2.0 (Creative Commons Attribution-ShareAlike 2.0 Generic). That means you can distribute and remix them as much as you want to, under the condition that you give credit to the authors and the project, and that if you remix and release them, they must be under the same or similar license to this one.
All code in this project is licensed under the LGPL version 3 or later. That means you have unlimited freedom to distribute and modify the work however you see fit, provided that if you decide to distribute it or any modified versions of it, you must also use the same license. The LGPL also grants the additional freedom to write extensions for the software and distribute them without the extensions being subject to the terms of the LGPL, although the software itself retains its license. All code in this project is licensed under the LGPL version 3 or later. That means you have unlimited freedom to distribute and modify the work however you see fit, provided that if you decide to distribute it or any modified versions of it, you must also use the same license. The LGPL also grants the additional freedom to write extensions for the software and distribute them without the extensions being subject to the terms of the LGPL, although the software itself retains its license.

View File

@ -1,114 +0,0 @@
mesecon.queue.actions={} -- contains all ActionQueue actions
function mesecon.queue:add_function(name, func)
mesecon.queue.funcs[name] = func
end
-- If add_action with twice the same overwritecheck and same position are called, the first one is overwritten
-- use overwritecheck nil to never overwrite, but just add the event to the queue
-- priority specifies the order actions are executed within one globalstep, highest first
-- should be between 0 and 1
function mesecon.queue:add_action(pos, func, params, time, overwritecheck, priority)
-- Create Action Table:
time = time or 0 -- time <= 0 --> execute, time > 0 --> wait time until execution
priority = priority or 1
local action = { pos=mesecon:tablecopy(pos),
func=func,
params=mesecon:tablecopy(params),
time=time,
owcheck=(overwritecheck and mesecon:tablecopy(overwritecheck)) or nil,
priority=priority}
local toremove = nil
-- Otherwise, add the action to the queue
if overwritecheck then -- check if old action has to be overwritten / removed:
for i, ac in ipairs(mesecon.queue.actions) do
if(mesecon:cmpPos(pos, ac.pos)
and mesecon:cmpAny(overwritecheck, ac.owcheck)) then
toremove = i
break
end
end
end
if (toremove ~= nil) then
table.remove(mesecon.queue.actions, toremove)
end
table.insert(mesecon.queue.actions, action)
end
-- execute the stored functions on a globalstep
-- if however, the pos of a function is not loaded (get_node_or_nil == nil), do NOT execute the function
-- this makes sure that resuming mesecons circuits when restarting minetest works fine
-- However, even that does not work in some cases, that's why we delay the time the globalsteps
-- start to be execute by 5 seconds
local get_highest_priority = function (actions)
local highestp = -1, highesti
for i, ac in ipairs(actions) do
if ac.priority > highestp then
highestp = ac.priority
highesti = i
end
end
return highesti
end
local m_time = 0
minetest.register_globalstep(function (dtime)
m_time = m_time + dtime
if (m_time < MESECONS_RESUMETIME) then return end -- don't even try if server has not been running for XY seconds
local actions = mesecon:tablecopy(mesecon.queue.actions)
local actions_now={}
mesecon.queue.actions = {}
-- sort actions into two categories:
-- those toexecute now (actions_now) and those to execute later (mesecon.queue.actions)
for i, ac in ipairs(actions) do
if ac.time > 0 then
ac.time = ac.time - dtime -- executed later
table.insert(mesecon.queue.actions, ac)
else
table.insert(actions_now, ac)
end
end
while(#actions_now > 0) do -- execute highest priorities first, until all are executed
local hp = get_highest_priority(actions_now)
mesecon.queue:execute(actions_now[hp])
table.remove(actions_now, hp)
end
end)
function mesecon.queue:execute(action)
mesecon.queue.funcs[action.func](action.pos, unpack(action.params))
end
-- Store and read the ActionQueue to / from a file
-- so that upcoming actions are remembered when the game
-- is restarted
local wpath = minetest.get_worldpath()
local function file2table(filename)
local f = io.open(filename, "r")
if f==nil then return {} end
local t = f:read("*all")
f:close()
if t=="" or t==nil then return {} end
return minetest.deserialize(t)
end
local function table2file(filename, table)
local f = io.open(filename, "w")
f:write(minetest.serialize(table))
f:close()
end
mesecon.queue.actions = file2table(wpath.."/mesecon_actionqueue")
minetest.register_on_shutdown(function()
mesecon.queue.actions = table2file(wpath.."/mesecon_actionqueue", mesecon.queue.actions)
end)

View File

@ -39,10 +39,19 @@
-- } -- }
--} --}
-- PUBLIC VARIABLES -- PUBLIC VARIABLES
mesecon={} -- contains all functions and all global variables mesecon={} -- contains all functions and all global variables
mesecon.queue={} -- contains the ActionQueue mesecon.actions_on={} -- Saves registered function callbacks for mesecon on | DEPRECATED
mesecon.queue.funcs={} -- contains all ActionQueue functions mesecon.actions_off={} -- Saves registered function callbacks for mesecon off | DEPRECATED
mesecon.actions_change={} -- Saves registered function callbacks for mesecon change | DEPRECATED
mesecon.receptors={} -- saves all information about receptors | DEPRECATED
mesecon.effectors={} -- saves all information about effectors | DEPRECATED
mesecon.conductors={} -- saves all information about conductors | DEPRECATED
mesecon.to_update = {}
mesecon.r_to_update = {}
-- Settings -- Settings
dofile(minetest.get_modpath("mesecons").."/settings.lua") dofile(minetest.get_modpath("mesecons").."/settings.lua")
@ -56,10 +65,6 @@ dofile(minetest.get_modpath("mesecons").."/presets.lua");
-- mostly things that make the source look cleaner -- mostly things that make the source look cleaner
dofile(minetest.get_modpath("mesecons").."/util.lua"); dofile(minetest.get_modpath("mesecons").."/util.lua");
-- The ActionQueue
-- Saves all the actions that have to be execute in the future
dofile(minetest.get_modpath("mesecons").."/actionqueue.lua");
-- Internal stuff -- Internal stuff
-- This is the most important file -- This is the most important file
-- it handles signal transmission and basically everything else -- it handles signal transmission and basically everything else
@ -75,60 +80,42 @@ dofile(minetest.get_modpath("mesecons").."/legacy.lua");
-- API -- API
-- these are the only functions you need to remember -- these are the only functions you need to remember
mesecon.queue:add_function("receptor_on", function (pos, rules) function mesecon:receptor_on_i(pos, rules)
rules = rules or mesecon.rules.default rules = rules or mesecon.rules.default
-- if area (any of the rule targets) is not loaded, keep trying and call this again later for _, rule in ipairs(rules) do
for _, rule in ipairs(mesecon:flattenrules(rules)) do
local np = mesecon:addPosRule(pos, rule) local np = mesecon:addPosRule(pos, rule)
-- if area is not loaded, keep trying local link, rulename = mesecon:rules_link(pos, np, rules)
if minetest.get_node_or_nil(np) == nil then if link then
mesecon.queue:add_action(pos, "receptor_on", {rules}, nil, rules)
return
end
end
-- execute action
for _, rule in ipairs(mesecon:flattenrules(rules)) do
local np = mesecon:addPosRule(pos, rule)
local rulenames = mesecon:rules_link_rule_all(pos, rule)
for _, rulename in ipairs(rulenames) do
mesecon:turnon(np, rulename) mesecon:turnon(np, rulename)
end end
end end
end) end
function mesecon:receptor_on(pos, rules) function mesecon:receptor_on(pos, rules)
mesecon.queue:add_action(pos, "receptor_on", {rules}, nil, rules) rules = rules or mesecon.rules.default
mesecon.r_to_update[#mesecon.r_to_update+1]={pos=pos, rules=rules, action="on"}
end end
mesecon.queue:add_function("receptor_off", function (pos, rules) function mesecon:receptor_off_i(pos, rules)
rules = rules or mesecon.rules.default rules = rules or mesecon.rules.default
-- if area (any of the rule targets) is not loaded, keep trying and call this again later for _, rule in ipairs(rules) do
for _, rule in ipairs(mesecon:flattenrules(rules)) do
local np = mesecon:addPosRule(pos, rule) local np = mesecon:addPosRule(pos, rule)
if minetest.get_node_or_nil(np) == nil then local link, rulename = mesecon:rules_link(pos, np, rules)
mesecon.queue:add_action(pos, "receptor_off", {rules}, nil, rules) if link then
return if not mesecon:connected_to_receptor(np) then
end
end
for _, rule in ipairs(mesecon:flattenrules(rules)) do
local np = mesecon:addPosRule(pos, rule)
local rulenames = mesecon:rules_link_rule_all(pos, rule)
for _, rulename in ipairs(rulenames) do
if not mesecon:connected_to_receptor(np, mesecon:invertRule(rule)) then
mesecon:turnoff(np, rulename) mesecon:turnoff(np, rulename)
else else
mesecon:changesignal(np, minetest.get_node(np), rulename, mesecon.state.off, 2) mesecon:changesignal(np, minetest.env:get_node(np), rulename, mesecon.state.off)
end
end end
end end
end end
end)
function mesecon:receptor_off(pos, rules) function mesecon:receptor_off(pos, rules)
mesecon.queue:add_action(pos, "receptor_off", {rules}, nil, rules) rules = rules or mesecon.rules.default
mesecon.r_to_update[#mesecon.r_to_update+1]={pos=pos, rules=rules, action="off"}
end end

View File

@ -22,9 +22,9 @@
-- mesecon:effector_get_rules(node) --> Returns the input rules of the effector (mesecon.rules.default if none specified) -- mesecon:effector_get_rules(node) --> Returns the input rules of the effector (mesecon.rules.default if none specified)
-- SIGNALS -- SIGNALS
-- mesecon:activate(pos, node, recdepth) --> Activates the effector node at the specific pos (calls nodedef.mesecons.effector.action_on), higher recdepths are executed later -- mesecon:activate(pos, node) --> Activates the effector node at the specific pos (calls nodedef.mesecons.effector.action_on)
-- mesecon:deactivate(pos, node, recdepth) --> Deactivates the effector node at the specific pos (calls nodedef.mesecons.effector.action_off), " -- mesecon:deactivate(pos, node) --> Deactivates the effector node at the specific pos (calls nodedef.mesecons.effector.action_off)
-- mesecon:changesignal(pos, node, rulename, newstate) --> Changes the effector node at the specific pos (calls nodedef.mesecons.effector.action_change), " -- mesecon:changesignal(pos, node, rulename, newstate) --> Changes the effector node at the specific pos (calls nodedef.mesecons.effector.action_change)
-- RULES -- RULES
-- mesecon:add_rules(name, rules) | deprecated? --> Saves rules table by name -- mesecon:add_rules(name, rules) | deprecated? --> Saves rules table by name
@ -32,17 +32,17 @@
-- CONDUCTORS -- CONDUCTORS
-- mesecon:is_conductor(nodename) --> Returns true if nodename is a conductor -- mesecon:is_conductor(nodename) --> Returns true if nodename is a conductor
-- mesecon:is_conductor_on(node) --> Returns true if node is a conductor with state = mesecon.state.on -- mesecon:is_conductor_on(nodename) --> Returns true if nodename is a conductor with state = mesecon.state.on
-- mesecon:is_conductor_off(node) --> Returns true if node is a conductor with state = mesecon.state.off -- mesecon:is_conductor_off(nodename) --> Returns true if nodename is a conductor with state = mesecon.state.off
-- mesecon:get_conductor_on(node_off) --> Returns the onstate nodename of the conductor -- mesecon:get_conductor_on(offstate) --> Returns the onstate nodename of the conductor with the name offstate
-- mesecon:get_conductor_off(node_on) --> Returns the offstate nodename of the conductor -- mesecon:get_conductor_off(onstate) --> Returns the offstate nodename of the conductor with the name onstate
-- mesecon:conductor_get_rules(node) --> Returns the input+output rules of a conductor (mesecon.rules.default if none specified) -- mesecon:conductor_get_rules(node) --> Returns the input+output rules of a conductor (mesecon.rules.default if none specified)
-- HIGH-LEVEL Internals -- HIGH-LEVEL Internals
-- mesecon:is_power_on(pos) --> Returns true if pos emits power in any way -- mesecon:is_power_on(pos) --> Returns true if pos emits power in any way
-- mesecon:is_power_off(pos) --> Returns true if pos does not emit power in any way -- mesecon:is_power_off(pos) --> Returns true if pos does not emit power in any way
-- mesecon:turnon(pos, rulename) --> Returns true whatever there is at pos. Calls itself for connected nodes (if pos is a conductor) --> recursive, the rulename is the name of the input rule that caused calling turnon; Uses third parameter recdepth internally to determine how far away the current node is from the initial pos as it uses recursion -- mesecon:turnon(pos, rulename) --> Returns true whatever there is at pos. Calls itself for connected nodes (if pos is a conductor) --> recursive, the rulename is the name of the input rule that caused calling turnon
-- mesecon:turnoff(pos, rulename) --> Turns off whatever there is at pos. Calls itself for connected nodes (if pos is a conductor) --> recursive, the rulename is the name of the input rule that caused calling turnoff; Uses third parameter recdepth internally to determine how far away the current node is from the initial pos as it uses recursion -- mesecon:turnoff(pos, rulename) --> Turns off whatever there is at pos. Calls itself for connected nodes (if pos is a conductor) --> recursive, the rulename is the name of the input rule that caused calling turnoff
-- mesecon:connected_to_receptor(pos) --> Returns true if pos is connected to a receptor directly or via conductors; calls itself if pos is a conductor --> recursive -- mesecon:connected_to_receptor(pos) --> Returns true if pos is connected to a receptor directly or via conductors; calls itself if pos is a conductor --> recursive
-- mesecon:rules_link(output, input, dug_outputrules) --> Returns true if outputposition + outputrules = inputposition and inputposition + inputrules = outputposition (if the two positions connect) -- mesecon:rules_link(output, input, dug_outputrules) --> Returns true if outputposition + outputrules = inputposition and inputposition + inputrules = outputposition (if the two positions connect)
-- mesecon:rules_link_anydir(outp., inp., d_outpr.) --> Same as rules mesecon:rules_link but also returns true if output and input are swapped -- mesecon:rules_link_anydir(outp., inp., d_outpr.) --> Same as rules mesecon:rules_link but also returns true if output and input are swapped
@ -177,76 +177,117 @@ function mesecon:effector_get_rules(node)
return mesecon.rules.default return mesecon.rules.default
end end
-- ####################### --Signals
-- # Signals (effectors) #
-- #######################
-- Activation:
mesecon.queue:add_function("activate", function (pos, rulename)
node = minetest.get_node(pos)
effector = mesecon:get_effector(node.name)
function mesecon:activate(pos, node, rulename)
if rulename == nil then
for _,rule in ipairs(mesecon:effector_get_rules(node)) do
mesecon:activate(pos, node, rule)
end
return
end
if MESECONS_GLOBALSTEP then
add_action(pos, "on", rulename)
else
local effector = mesecon:get_effector(node.name)
if effector and effector.action_on then if effector and effector.action_on then
effector.action_on (pos, node, rulename) effector.action_on (pos, node, rulename)
end end
end) end
end
function mesecon:activate(pos, node, rulename, recdepth) function mesecon:deactivate(pos, node, rulename)
if rulename == nil then if rulename == nil then
for _,rule in ipairs(mesecon:effector_get_rules(node)) do for _,rule in ipairs(mesecon:effector_get_rules(node)) do
mesecon:activate(pos, node, rule, recdepth + 1) mesecon:deactivate(pos, node, rule)
end end
return return
end end
mesecon.queue:add_action(pos, "activate", {rulename}, nil, rulename, 1 / recdepth) if MESECONS_GLOBALSTEP then
end add_action(pos, "off", rulename)
else
local effector = mesecon:get_effector(node.name)
-- Deactivation
mesecon.queue:add_function("deactivate", function (pos, rulename)
node = minetest.get_node(pos)
effector = mesecon:get_effector(node.name)
if effector and effector.action_off then if effector and effector.action_off then
effector.action_off (pos, node, rulename) effector.action_off (pos, node, rulename)
end end
end) end
end
function mesecon:deactivate(pos, node, rulename, recdepth) function mesecon:changesignal(pos, node, rulename, newstate)
newstate = newstate or "on"
--rulename = rulename or mesecon.rules.default
if rulename == nil then if rulename == nil then
for _,rule in ipairs(mesecon:effector_get_rules(node)) do for _,rule in ipairs(mesecon:effector_get_rules(node)) do
mesecon:deactivate(pos, node, rule, recdepth + 1) mesecon:changesignal(pos, node, rule, newstate)
end end
return return
end end
mesecon.queue:add_action(pos, "deactivate", {rulename}, nil, rulename, 1 / recdepth) if MESECONS_GLOBALSTEP then
end add_action(pos, "c"..newstate, rulename)
else
local effector = mesecon:get_effector(node.name)
-- Change
mesecon.queue:add_function("change", function (pos, rulename, changetype)
node = minetest.get_node(pos)
effector = mesecon:get_effector(node.name)
if effector and effector.action_change then if effector and effector.action_change then
effector.action_change(pos, node, rulename, changetype) effector.action_change (pos, node, rulename, newstate)
end end
end)
function mesecon:changesignal(pos, node, rulename, newstate, recdepth)
if rulename == nil then
for _,rule in ipairs(mesecon:effector_get_rules(node)) do
mesecon:changesignal(pos, node, rule, newstate, recdepth + 1)
end end
return
end end
mesecon.queue:add_action(pos, "change", {rulename, newstate}, nil, rulename, 1 / recdepth) function execute_actions(dtime)
local nactions = mesecon.to_update
mesecon.to_update = {}
for _,i in ipairs(nactions) do
node = minetest.env:get_node(i.pos)
effector = mesecon:get_effector(node.name)
if i.action == "on" then
if effector and effector.action_on then
effector.action_on(i.pos, node, i.rname)
end
elseif i.action == "off" then
if effector and effector.action_off then
effector.action_off(i.pos, node, i.rname)
end
elseif i.action == "con" then
if effector and effector.action_change then
effector.action_change(i.pos, node, i.rname, "on")
end
elseif i.action == "coff" then
if effector and effector.action_change then
effector.action_change(i.pos, node, i.rname, "off")
end
end
end
local nactions = mesecon.r_to_update
mesecon.r_to_update = {}
for _,i in ipairs(nactions) do
if i.action == "on" then
mesecon:receptor_on_i(i.pos, i.rules)
else
mesecon:receptor_off_i(i.pos,i.rules)
end
end
end end
-- ######### minetest.register_globalstep(execute_actions)
-- # Rules # "Database" for rulenames
-- ######### function add_action(pos, action, rname)
for _,i in ipairs(mesecon.to_update) do
if i.pos.x == pos.x and i.pos.y == pos.y and i.pos.z == pos.z and i.rname.x == rname.x and i.rname.y == rname.y and i.rname.z == rname.z then
if (i.action == "on" and action == "on") or (i.action == "off" and action == "off") then
--nothing
elseif i.action == "coff" and action == "on" then i.action = "on"
elseif i.action == "con" and action == "off" then i.action = "off"
else
if action == "on" or action == "con" then i.action = "con" end
if action == "off" or action == "coff" then i.action = "coff" end
end
break
end
end
mesecon.to_update[#mesecon.to_update+1] = {pos = pos, action = action, rname = rname}
end
--Rules
function mesecon:add_rules(name, rules) function mesecon:add_rules(name, rules)
mesecon.rules[name] = rules mesecon.rules[name] = rules
@ -258,38 +299,18 @@ end
-- Conductors -- Conductors
function mesecon:is_conductor_on(node, rulename) function mesecon:is_conductor_on(nodename)
local conductor = mesecon:get_conductor(node.name) local conductor = mesecon:get_conductor(nodename)
if conductor then if conductor and conductor.state == mesecon.state.on then
if conductor.state then return true
return conductor.state == mesecon.state.on
end
if conductor.states then
if not rulename then
return mesecon:getstate(node.name, conductor.states) ~= 1
end
local bit = mesecon:rule2bit(rulename, mesecon:conductor_get_rules(node))
local binstate = mesecon:getbinstate(node.name, conductor.states)
return mesecon:get_bit(binstate, bit)
end
end end
return false return false
end end
function mesecon:is_conductor_off(node, rulename) function mesecon:is_conductor_off(nodename)
local conductor = mesecon:get_conductor(node.name) local conductor = mesecon:get_conductor(nodename)
if conductor then if conductor and conductor.state == mesecon.state.off then
if conductor.state then return true
return conductor.state == mesecon.state.off
end
if conductor.states then
if not rulename then
return mesecon:getstate(node.name, conductor.states) == 1
end
local bit = mesecon:rule2bit(rulename, mesecon:conductor_get_rules(node))
local binstate = mesecon:getbinstate(node.name, conductor.states)
return not mesecon:get_bit(binstate, bit)
end
end end
return false return false
end end
@ -302,36 +323,20 @@ function mesecon:is_conductor(nodename)
return false return false
end end
function mesecon:get_conductor_on(node_off, rulename) function mesecon:get_conductor_on(offstate)
local conductor = mesecon:get_conductor(node_off.name) local conductor = mesecon:get_conductor(offstate)
if conductor then if conductor then
if conductor.onstate then
return conductor.onstate return conductor.onstate
end end
if conductor.states then return false
local bit = mesecon:rule2bit(rulename, mesecon:conductor_get_rules(node_off))
local binstate = mesecon:getbinstate(node_off.name, conductor.states)
binstate = mesecon:set_bit(binstate, bit, "1")
return conductor.states[tonumber(binstate,2)+1]
end
end
return offstate
end end
function mesecon:get_conductor_off(node_on, rulename) function mesecon:get_conductor_off(onstate)
local conductor = mesecon:get_conductor(node_on.name) local conductor = mesecon:get_conductor(onstate)
if conductor then if conductor then
if conductor.offstate then
return conductor.offstate return conductor.offstate
end end
if conductor.states then return false
local bit = mesecon:rule2bit(rulename, mesecon:conductor_get_rules(node_on))
local binstate = mesecon:getbinstate(node_on.name, conductor.states)
binstate = mesecon:set_bit(binstate, bit, "0")
return conductor.states[tonumber(binstate,2)+1]
end
end
return onstate
end end
function mesecon:conductor_get_rules(node) function mesecon:conductor_get_rules(node)
@ -349,126 +354,81 @@ end
-- some more general high-level stuff -- some more general high-level stuff
function mesecon:is_power_on(pos, rulename) function mesecon:is_power_on(pos)
local node = minetest.get_node(pos) local node = minetest.env:get_node(pos)
if mesecon:is_conductor_on(node, rulename) or mesecon:is_receptor_on(node.name) then if mesecon:is_conductor_on(node.name) or mesecon:is_receptor_on(node.name) then
return true return true
end end
return false return false
end end
function mesecon:is_power_off(pos, rulename) function mesecon:is_power_off(pos)
local node = minetest.get_node(pos) local node = minetest.env:get_node(pos)
if mesecon:is_conductor_off(node, rulename) or mesecon:is_receptor_off(node.name) then if mesecon:is_conductor_off(node.name) or mesecon:is_receptor_off(node.name) then
return true return true
end end
return false return false
end end
function mesecon:turnon(pos, rulename, recdepth) function mesecon:turnon(pos, rulename)
recdepth = recdepth or 2 local node = minetest.env:get_node(pos)
local node = minetest.get_node(pos)
if(node.name == "ignore") then if mesecon:is_conductor_off(node.name) then
-- try turning on later again
mesecon.queue:add_action(
pos, "turnon", {rulename, recdepth + 1}, nil, true)
end
if mesecon:is_conductor_off(node, rulename) then
local rules = mesecon:conductor_get_rules(node) local rules = mesecon:conductor_get_rules(node)
minetest.env:add_node(pos, {name = mesecon:get_conductor_on(node.name), param2 = node.param2})
if not rulename then for _, rule in ipairs(rules) do
for _, rule in ipairs(mesecon:flattenrules(rules)) do
if mesecon:connected_to_receptor(pos, rule) then
mesecon:turnon(pos, rule, recdepth + 1)
end
end
return
end
minetest.swap_node(pos, {name = mesecon:get_conductor_on(node, rulename), param2 = node.param2})
for _, rule in ipairs(mesecon:rule2meta(rulename, rules)) do
local np = mesecon:addPosRule(pos, rule) local np = mesecon:addPosRule(pos, rule)
if(minetest.get_node(np).name == "ignore") then local link, rulename = mesecon:rules_link(pos, np)
-- try turning on later again
mesecon.queue:add_action(
np, "turnon", {rulename, recdepth + 1}, nil, true)
else
local rulenames = mesecon:rules_link_rule_all(pos, rule)
for _, rulename in ipairs(rulenames) do if link then
mesecon:turnon(np, rulename, recdepth + 1) mesecon:turnon(np, rulename)
end
end end
end end
elseif mesecon:is_effector(node.name) then elseif mesecon:is_effector(node.name) then
mesecon:changesignal(pos, node, rulename, mesecon.state.on, recdepth) mesecon:changesignal(pos, node, rulename, mesecon.state.on)
if mesecon:is_effector_off(node.name) then if mesecon:is_effector_off(node.name) then
mesecon:activate(pos, node, rulename, recdepth) mesecon:activate(pos, node, rulename)
end end
end end
end end
mesecon.queue:add_function("turnon", function (pos, rulename, recdepth) function mesecon:turnoff(pos, rulename)
mesecon:turnon(pos, rulename, recdepth) local node = minetest.env:get_node(pos)
end)
function mesecon:turnoff(pos, rulename, recdepth) if mesecon:is_conductor_on(node.name) then
recdepth = recdepth or 2
local node = minetest.get_node(pos)
if(node.name == "ignore") then
-- try turning on later again
mesecon.queue:add_action(
pos, "turnoff", {rulename, recdepth + 1}, nil, true)
end
if mesecon:is_conductor_on(node, rulename) then
local rules = mesecon:conductor_get_rules(node) local rules = mesecon:conductor_get_rules(node)
minetest.swap_node(pos, {name = mesecon:get_conductor_off(node, rulename), param2 = node.param2}) minetest.env:add_node(pos, {name = mesecon:get_conductor_off(node.name), param2 = node.param2})
for _, rule in ipairs(mesecon:rule2meta(rulename, rules)) do for _, rule in ipairs(rules) do
local np = mesecon:addPosRule(pos, rule) local np = mesecon:addPosRule(pos, rule)
if(minetest.get_node(np).name == "ignore") then local link, rulename = mesecon:rules_link(pos, np)
-- try turning on later again
mesecon.queue:add_action(
np, "turnoff", {rulename, recdepth + 1}, nil, true)
else
local rulenames = mesecon:rules_link_rule_all(pos, rule)
for _, rulename in ipairs(rulenames) do if link then
mesecon:turnoff(np, rulename, recdepth + 1) mesecon:turnoff(np, rulename)
end
end end
end end
elseif mesecon:is_effector(node.name) then elseif mesecon:is_effector(node.name) then
mesecon:changesignal(pos, node, rulename, mesecon.state.off, recdepth) mesecon:changesignal(pos, node, rulename, mesecon.state.off)
if mesecon:is_effector_on(node.name) if mesecon:is_effector_on(node.name)
and not mesecon:is_powered(pos) then and not mesecon:is_powered(pos) then
mesecon:deactivate(pos, node, rulename, recdepth + 1) mesecon:deactivate(pos, node, rulename)
end end
end end
end end
mesecon.queue:add_function("turnoff", function (pos, rulename, recdepth)
mesecon:turnoff(pos, rulename, recdepth)
end)
function mesecon:connected_to_receptor(pos)
function mesecon:connected_to_receptor(pos, rulename) local node = minetest.env:get_node(pos)
local node = minetest.get_node(pos)
-- Check if conductors around are connected -- Check if conductors around are connected
local rules = mesecon:get_any_inputrules(node) local rules = mesecon:get_any_inputrules(node)
if not rules then return false end if not rules then return false end
for _, rule in ipairs(mesecon:rule2meta(rulename, rules)) do for _, rule in ipairs(rules) do
local rulenames = mesecon:rules_link_rule_all_inverted(pos, rule) local np = mesecon:addPosRule(pos, rule)
for _, rname in ipairs(rulenames) do if mesecon:rules_link(np, pos) then
local np = mesecon:addPosRule(pos, rname) if mesecon:find_receptor_on(np, {}) then
if mesecon:find_receptor_on(np, {}, mesecon:invertRule(rname)) then
return true return true
end end
end end
@ -477,66 +437,53 @@ function mesecon:connected_to_receptor(pos, rulename)
return false return false
end end
function mesecon:find_receptor_on(pos, checked, rulename) function mesecon:find_receptor_on(pos, checked)
local node = minetest.get_node(pos)
if mesecon:is_receptor_on(node.name) then
-- add current position to checked
table.insert(checked, {x=pos.x, y=pos.y, z=pos.z})
return true
end
if mesecon:is_conductor(node.name) then
local rules = mesecon:conductor_get_rules(node)
local metaindex = mesecon:rule2metaindex(rulename, rules)
-- find out if node has already been checked (to prevent from endless loop)
for _, cp in ipairs(checked) do
if mesecon:cmpPos(cp, pos) and cp.metaindex == metaindex then
return false, checked
end
end
-- add current position to checked
table.insert(checked, {x=pos.x, y=pos.y, z=pos.z, metaindex = metaindex})
for _, rule in ipairs(mesecon:rule2meta(rulename, rules)) do
local rulenames = mesecon:rules_link_rule_all_inverted(pos, rule)
for _, rname in ipairs(rulenames) do
local np = mesecon:addPosRule(pos, rname)
if mesecon:find_receptor_on(np, checked, mesecon:invertRule(rname)) then
return true
end
end
end
else
-- find out if node has already been checked (to prevent from endless loop) -- find out if node has already been checked (to prevent from endless loop)
for _, cp in ipairs(checked) do for _, cp in ipairs(checked) do
if mesecon:cmpPos(cp, pos) then if mesecon:cmpPos(cp, pos) then
return false, checked return false, checked
end end
end end
-- add current position to checked
table.insert(checked, {x=pos.x, y=pos.y, z=pos.z}) table.insert(checked, {x=pos.x, y=pos.y, z=pos.z})
local node = minetest.env:get_node(pos)
if mesecon:is_receptor_on(node.name) then
return true
end
if mesecon:is_conductor(node.name) then
local rules = mesecon:conductor_get_rules(node)
for _, rule in ipairs(rules) do
local np = mesecon:addPosRule(pos, rule)
if mesecon:rules_link(np, pos) then
if mesecon:find_receptor_on(np, checked) then
return true
end
end
end
end end
return false return false
end end
function mesecon:rules_link(output, input, dug_outputrules) --output/input are positions (outputrules optional, used if node has been dug), second return value: the name of the affected input rule function mesecon:rules_link(output, input, dug_outputrules) --output/input are positions (outputrules optional, used if node has been dug), second return value: the name of the affected input rule
local outputnode = minetest.get_node(output) local outputnode = minetest.env:get_node(output)
local inputnode = minetest.get_node(input) local inputnode = minetest.env:get_node(input)
local outputrules = dug_outputrules or mesecon:get_any_outputrules (outputnode) local outputrules = dug_outputrules or mesecon:get_any_outputrules (outputnode)
local inputrules = mesecon:get_any_inputrules (inputnode) local inputrules = mesecon:get_any_inputrules (inputnode)
if not outputrules or not inputrules then if not outputrules or not inputrules then
return return
end end
for _, outputrule in ipairs(mesecon:flattenrules(outputrules)) do for _, outputrule in ipairs(outputrules) do
-- Check if output sends to input -- Check if output sends to input
if mesecon:cmpPos(mesecon:addPosRule(output, outputrule), input) then if mesecon:cmpPos(mesecon:addPosRule(output, outputrule), input) then
for _, inputrule in ipairs(mesecon:flattenrules(inputrules)) do for _, inputrule in ipairs(inputrules) do
-- Check if input accepts from output -- Check if input accepts from output
if mesecon:cmpPos(mesecon:addPosRule(input, inputrule), output) then if mesecon:cmpPos(mesecon:addPosRule(input, inputrule), output) then
if inputrule.sx == nil or outputrule.sx == nil or mesecon:cmpSpecial(inputrule, outputrule) then return true, inputrule.name
return true, inputrule
end
end end
end end
end end
@ -544,76 +491,24 @@ function mesecon:rules_link(output, input, dug_outputrules) --output/input are p
return false return false
end end
function mesecon:rules_link_rule_all(output, rule) --output/input are positions (outputrules optional, used if node has been dug), second return value: affected input rules
local input = mesecon:addPosRule(output, rule)
local inputnode = minetest.get_node(input)
local inputrules = mesecon:get_any_inputrules (inputnode)
if not inputrules then
return {}
end
local rules = {}
for _, inputrule in ipairs(mesecon:flattenrules(inputrules)) do
-- Check if input accepts from output
if mesecon:cmpPos(mesecon:addPosRule(input, inputrule), output) then
if inputrule.sx == nil or rule.sx == nil or mesecon:cmpSpecial(inputrule, rule) then
rules[#rules+1] = inputrule
end
end
end
return rules
end
function mesecon:rules_link_rule_all_inverted(input, rule)
--local irule = mesecon:invertRule(rule)
local output = mesecon:addPosRule(input, rule)
local outputnode = minetest.get_node(output)
local outputrules = mesecon:get_any_outputrules (outputnode)
if not outputrules then
return {}
end
local rules = {}
for _, outputrule in ipairs(mesecon:flattenrules(outputrules)) do
if mesecon:cmpPos(mesecon:addPosRule(output, outputrule), input) then
if outputrule.sx == nil or rule.sx == nil or mesecon:cmpSpecial(outputrule, rule) then
rules[#rules+1] = mesecon:invertRule(outputrule)
end
end
end
return rules
end
function mesecon:rules_link_anydir(pos1, pos2) function mesecon:rules_link_anydir(pos1, pos2)
return mesecon:rules_link(pos1, pos2) or mesecon:rules_link(pos2, pos1) return mesecon:rules_link(pos1, pos2) or mesecon:rules_link(pos2, pos1)
end end
function mesecon:is_powered(pos, rule) function mesecon:is_powered(pos)
local node = minetest.get_node(pos) local node = minetest.env:get_node(pos)
local rules = mesecon:get_any_inputrules(node) local rules = mesecon:get_any_inputrules(node)
if not rules then return false end if not rules then return false end
if not rule then for _, rule in ipairs(rules) do
for _, rule in ipairs(mesecon:flattenrules(rules)) do local np = mesecon:addPosRule(pos, rule)
local rulenames = mesecon:rules_link_rule_all_inverted(pos, rule) local nn = minetest.env:get_node(np)
for _, rname in ipairs(rulenames) do
local np = mesecon:addPosRule(pos, rname) if (mesecon:is_conductor_on (nn.name) or mesecon:is_receptor_on (nn.name))
local nn = minetest.get_node(np) and mesecon:rules_link(np, pos) then
if (mesecon:is_conductor_on (nn, mesecon:invertRule(rname)) or mesecon:is_receptor_on (nn.name)) then
return true return true
end end
end end
end
else
local rulenames = mesecon:rules_link_rule_all_inverted(pos, rule)
for _, rname in ipairs(rulenames) do
local np = mesecon:addPosRule(pos, rname)
local nn = minetest.get_node(np)
if (mesecon:is_conductor_on (nn, mesecon:invertRule(rname)) or mesecon:is_receptor_on (nn.name)) then
return true
end
end
end
return false return false
end end
@ -622,83 +517,43 @@ end
function mesecon:rotate_rules_right(rules) function mesecon:rotate_rules_right(rules)
local nr = {} local nr = {}
for i, rule in ipairs(rules) do for i, rule in ipairs(rules) do
if rule.sx then
table.insert(nr, {
x = -rule.z,
y = rule.y,
z = rule.x,
sx = -rule.sz,
sy = rule.sy,
sz = rule.sx})
else
table.insert(nr, { table.insert(nr, {
x = -rule.z, x = -rule.z,
y = rule.y, y = rule.y,
z = rule.x}) z = rule.x})
end end
end
return nr return nr
end end
function mesecon:rotate_rules_left(rules) function mesecon:rotate_rules_left(rules)
local nr = {} local nr = {}
for i, rule in ipairs(rules) do for i, rule in ipairs(rules) do
if rule.sx then
table.insert(nr, {
x = rule.z,
y = rule.y,
z = -rule.x,
sx = rule.sz,
sy = rule.sy,
sz = -rule.sx})
else
table.insert(nr, { table.insert(nr, {
x = rule.z, x = rule.z,
y = rule.y, y = rule.y,
z = -rule.x}) z = -rule.x})
end end
end
return nr return nr
end end
function mesecon:rotate_rules_down(rules) function mesecon:rotate_rules_down(rules)
local nr = {} local nr = {}
for i, rule in ipairs(rules) do for i, rule in ipairs(rules) do
if rule.sx then
table.insert(nr, {
x = -rule.y,
y = rule.x,
z = rule.z,
sx = -rule.sy,
sy = rule.sx,
sz = rule.sz})
else
table.insert(nr, { table.insert(nr, {
x = -rule.y, x = -rule.y,
y = rule.x, y = rule.x,
z = rule.z}) z = rule.z})
end end
end
return nr return nr
end end
function mesecon:rotate_rules_up(rules) function mesecon:rotate_rules_up(rules)
local nr = {} local nr = {}
for i, rule in ipairs(rules) do for i, rule in ipairs(rules) do
if rule.sx then
table.insert(nr, {
x = rule.y,
y = -rule.x,
z = rule.z,
sx = rule.sy,
sy = -rule.sx,
sz = rule.sz})
else
table.insert(nr, { table.insert(nr, {
x = rule.y, x = rule.y,
y = -rule.x, y = -rule.x,
z = rule.z}) z = rule.z})
end end
end
return nr return nr
end end

View File

@ -1,32 +0,0 @@
minetest.swap_node = minetest.swap_node or function(pos, node)
local data = minetest.get_meta(pos):to_table()
minetest.add_node(pos, node)
minetest.get_meta(pos):from_table(data)
end
local rules = {}
rules.a = {x = -1, y = 0, z = 0, name="A"}
rules.b = {x = 0, y = 0, z = 1, name="B"}
rules.c = {x = 1, y = 0, z = 0, name="C"}
rules.d = {x = 0, y = 0, z = -1, name="D"}
function legacy_update_ports(pos)
local meta = minetest.get_meta(pos)
L = {
a = mesecon:is_power_on(mesecon:addPosRule(pos, rules.a),
mesecon:invertRule(rules.a)) and
mesecon:rules_link(mesecon:addPosRule(pos, rules.a), pos),
b = mesecon:is_power_on(mesecon:addPosRule(pos, rules.b),
mesecon:invertRule(rules.b)) and
mesecon:rules_link(mesecon:addPosRule(pos, rules.b), pos),
c = mesecon:is_power_on(mesecon:addPosRule(pos, rules.c),
mesecon:invertRule(rules.c)) and
mesecon:rules_link(mesecon:addPosRule(pos, rules.c), pos),
d = mesecon:is_power_on(mesecon:addPosRule(pos, rules.d),
mesecon:invertRule(rules.d)) and
mesecon:rules_link(mesecon:addPosRule(pos, rules.d), pos),
}
local n = (L.a and 1 or 0) + (L.b and 2 or 0) + (L.c and 4 or 0) + (L.d and 8 or 0) + 1
meta:set_int("real_portstates", n)
return L
end

View File

@ -1,38 +1,23 @@
-- Dig and place services
mesecon.on_placenode = function (pos, node) mesecon.on_placenode = function (pos, node)
-- Receptors: Send on signal when active
if mesecon:is_receptor_on(node.name) then if mesecon:is_receptor_on(node.name) then
mesecon:receptor_on(pos, mesecon:receptor_get_rules(node)) mesecon:receptor_on(pos, mesecon:receptor_get_rules(node))
end elseif mesecon:is_powered(pos) then
-- Conductors: Send turnon signal when powered or replace by respective offstate conductor
-- if placed conductor is an onstate one
if mesecon:is_conductor(node.name) then if mesecon:is_conductor(node.name) then
if mesecon:is_powered(pos) then
-- also call receptor_on if itself is powered already, so that neighboring
-- conductors will be activated (when pushing an on-conductor with a piston)
mesecon:turnon (pos) mesecon:turnon (pos)
mesecon:receptor_on (pos, mesecon:conductor_get_rules(node)) mesecon:receptor_on (pos, mesecon:conductor_get_rules(node))
elseif mesecon:is_conductor_off(node.name) then
minetest.swap_node(pos, {name = mesecon:get_conductor_off(node)})
end
end
-- Effectors: Send changesignal and activate or deactivate
if mesecon:is_effector(node.name) then
if mesecon:is_powered(pos) then
mesecon:changesignal(pos, node, mesecon:effector_get_rules(node), "on", 1)
mesecon:activate(pos, node, nil, 1)
else else
mesecon:changesignal(pos, node, mesecon:effector_get_rules(node), "off", 1) mesecon:changesignal(pos, node, mesecon:effector_get_rules(node), "on")
mesecon:deactivate(pos, node, nil, 1) mesecon:activate(pos, node)
end end
elseif mesecon:is_conductor_on(node.name) then
mesecon:swap_node(pos, mesecon:get_conductor_off(node.name))
elseif mesecon:is_effector_on (node.name) then
mesecon:deactivate(pos, node)
end end
end end
mesecon.on_dignode = function (pos, node) mesecon.on_dignode = function (pos, node)
if mesecon:is_conductor_on(node) then if mesecon:is_conductor_on(node.name) then
mesecon:receptor_off(pos, mesecon:conductor_get_rules(node)) mesecon:receptor_off(pos, mesecon:conductor_get_rules(node))
elseif mesecon:is_receptor_on(node.name) then elseif mesecon:is_receptor_on(node.name) then
mesecon:receptor_off(pos, mesecon:receptor_get_rules(node)) mesecon:receptor_off(pos, mesecon:receptor_get_rules(node))
@ -41,36 +26,3 @@ end
minetest.register_on_placenode(mesecon.on_placenode) minetest.register_on_placenode(mesecon.on_placenode)
minetest.register_on_dignode(mesecon.on_dignode) minetest.register_on_dignode(mesecon.on_dignode)
-- Overheating service for fast circuits
-- returns true if heat is too high
mesecon.do_overheat = function(pos)
local meta = minetest.get_meta(pos)
local heat = meta:get_int("heat") or 0
heat = heat + 1
meta:set_int("heat", heat)
if heat < OVERHEAT_MAX then
mesecon.queue:add_action(pos, "cooldown", {}, 1, nil, 0)
else
return true
end
return false
end
mesecon.queue:add_function("cooldown", function (pos)
if minetest.get_item_group(minetest.get_node(pos).name, "overheat") == 0 then
return -- node has been moved, this one does not use overheating - ignore
end
local meta = minetest.get_meta(pos)
local heat = meta:get_int("heat")
if (heat > 0) then
meta:set_int("heat", heat - 1)
end
end)

View File

@ -5,8 +5,5 @@ PRESSURE_PLATE_INTERVAL = 0.1
OBJECT_DETECTOR_RADIUS = 6 OBJECT_DETECTOR_RADIUS = 6
PISTON_MAXIMUM_PUSH = 15 PISTON_MAXIMUM_PUSH = 15
MOVESTONE_MAXIMUM_PUSH = 100 MOVESTONE_MAXIMUM_PUSH = 100
MESECONS_RESUMETIME = 4 -- time to wait when starting the server before MESECONS_GLOBALSTEP = true -- true = receptors/effectors won't be updated
-- processing the ActionQueue, don't set this too low -- until next globalstep, decreases server load
OVERHEAT_MAX = 20 -- maximum heat of any component that directly sends an output
-- signal when the input changes (e.g. luacontroller, gates)
-- Unit: actions per second, checks are every 1 second

View File

@ -1,160 +1,19 @@
function mesecon:swap_node(pos, name)
local node = minetest.env:get_node(pos)
local data = minetest.env:get_meta(pos):to_table()
node.name = name
minetest.env:add_node(pos, node)
minetest.env:get_meta(pos):from_table(data)
end
function mesecon:move_node(pos, newpos) function mesecon:move_node(pos, newpos)
local node = minetest.get_node(pos) local node = minetest.env:get_node(pos)
local meta = minetest.get_meta(pos):to_table() local meta = minetest.env:get_meta(pos):to_table()
minetest.remove_node(pos) minetest.env:remove_node(pos)
minetest.add_node(newpos, node) minetest.env:add_node(newpos, node)
minetest.get_meta(pos):from_table(meta) minetest.env:get_meta(pos):from_table(meta)
end end
--[[ new functions:
mesecon:flattenrules(allrules)
mesecon:rule2bit(findrule, allrules)
mesecon:rule2meta(findrule, allrules)
dec2bin(n)
mesecon:getstate(nodename, states)
mesecon:getbinstate(nodename, states)
mesecon:get_bit(binary, bit)
mesecon:set_bit(binary, bit, value)
mesecon:invertRule(r)
--]]
function mesecon:flattenrules(allrules)
--[[
{
{
{xyz},
{xyz},
},
{
{xyz},
{xyz},
},
}
--]]
if allrules[1] and
allrules[1].x then
return allrules
end
local shallowrules = {}
for _, metarule in ipairs( allrules) do
for _, rule in ipairs(metarule ) do
table.insert(shallowrules, rule)
end
end
return shallowrules
--[[
{
{xyz},
{xyz},
{xyz},
{xyz},
}
--]]
end
function mesecon:rule2bit(findrule, allrules)
--get the bit of the metarule the rule is in, or bit 1
if (allrules[1] and
allrules[1].x) or
not findrule then
return 1
end
for m,metarule in ipairs( allrules) do
for _, rule in ipairs(metarule ) do
if mesecon:cmpPos(findrule, rule) and mesecon:cmpSpecial(findrule, rule) then
return m
end
end
end
end
function mesecon:rule2metaindex(findrule, allrules)
--get the metarule the rule is in, or allrules
if allrules[1].x then
return nil
end
if not(findrule) then
return mesecon:flattenrules(allrules)
end
for m, metarule in ipairs( allrules) do
for _, rule in ipairs(metarule ) do
if mesecon:cmpPos(findrule, rule) and mesecon:cmpSpecial(findrule, rule) then
return m
end
end
end
end
function mesecon:rule2meta(findrule, allrules)
local index = mesecon:rule2metaindex(findrule, allrules)
if index == nil then
if allrules[1].x then
return allrules
else
return {}
end
end
return allrules[index]
end
if convert_base then
print(
"base2dec is tonumber(num,base1)\n"..
"commonlib needs dec2base(num,base2)\n"..
"and it needs base2base(num,base1,base2),\n"..
"which is dec2base(tonumber(num,base1),base2)"
)
else
function dec2bin(n)
local x, y = math.floor(n / 2), n % 2
if (n > 1) then
return dec2bin(x)..y
else
return ""..y
end
end
end
function mesecon:getstate(nodename, states)
for state, name in ipairs(states) do
if name == nodename then
return state
end
end
error(nodename.." doesn't mention itself in "..dump(states))
end
function mesecon:getbinstate(nodename, states)
return dec2bin(mesecon:getstate(nodename, states)-1)
end
function mesecon:get_bit(binary,bit)
bit = bit or 1
local c = binary:len()-(bit-1)
return binary:sub(c,c) == "1"
end
function mesecon:set_bit(binary,bit,value)
if value == "1" then
if not mesecon:get_bit(binary,bit) then
return dec2bin(tonumber(binary,2)+math.pow(2,bit-1))
end
elseif value == "0" then
if mesecon:get_bit(binary,bit) then
return dec2bin(tonumber(binary,2)-math.pow(2,bit-1))
end
end
return binary
end
function mesecon:invertRule(r)
return {x = -r.x, y = -r.y, z = -r.z, sx = r.sx, sy = r.sy, sz = r.sz}
end
function mesecon:addPosRule(p, r) function mesecon:addPosRule(p, r)
return {x = p.x + r.x, y = p.y + r.y, z = p.z + r.z} return {x = p.x + r.x, y = p.y + r.y, z = p.z + r.z}
@ -164,12 +23,7 @@ function mesecon:cmpPos(p1, p2)
return (p1.x == p2.x and p1.y == p2.y and p1.z == p2.z) return (p1.x == p2.x and p1.y == p2.y and p1.z == p2.z)
end end
function mesecon:cmpSpecial(r1, r2)
return (r1.sx == r2.sx and r1.sy == r2.sy and r1.sz == r2.sz)
end
function mesecon:tablecopy(table) -- deep table copy function mesecon:tablecopy(table) -- deep table copy
if type(table) ~= "table" then return table end -- no need to copy
local newtable = {} local newtable = {}
for idx, item in pairs(table) do for idx, item in pairs(table) do
@ -182,14 +36,3 @@ function mesecon:tablecopy(table) -- deep table copy
return newtable return newtable
end end
function mesecon:cmpAny(t1, t2)
if type(t1) ~= type(t2) then return false end
if type(t1) ~= "table" and type(t2) ~= "table" then return t1 == t2 end
for i, e in pairs(t1) do
if not mesecon:cmpAny(e, t2[i]) then return false end
end
return true
end

View File

@ -207,7 +207,7 @@ function mesecon:update_autoconnect(pos, secondcall, replace_old)
mesecon:update_autoconnect(zmympos, true) mesecon:update_autoconnect(zmympos, true)
end end
nodename = minetest.get_node(pos).name nodename = minetest.env:get_node(pos).name
if string.find(nodename, "mesecons:wire_") == nil and not replace_old then return nil end if string.find(nodename, "mesecons:wire_") == nil and not replace_old then return nil end
if mesecon:rules_link_anydir(pos, xppos) then xp = 1 else xp = 0 end if mesecon:rules_link_anydir(pos, xppos) then xp = 1 else xp = 0 end
@ -235,13 +235,14 @@ function mesecon:update_autoconnect(pos, secondcall, replace_old)
if string.find(nodename, "_off") ~= nil then if string.find(nodename, "_off") ~= nil then
minetest.set_node(pos, {name = "mesecons:wire_"..nodeid.."_off"}) minetest.env:set_node(pos, {name = "mesecons:wire_"..nodeid.."_off"})
else else
minetest.set_node(pos, {name = "mesecons:wire_"..nodeid.."_on" }) minetest.env:set_node(pos, {name = "mesecons:wire_"..nodeid.."_on" })
end end
end end
if not minetest.registered_nodes["default:stone_with_mese"] then --before MESE update, use old recipes if minetest.registered_nodes["default:stone_with_mese"] == nil then
minetest.register_craft({ minetest.register_craft({
output = "mesecons:wire_00000000_off 18", output = "mesecons:wire_00000000_off 18",
recipe = { recipe = {

View File

@ -1,25 +1,4 @@
-- The BLINKY_PLANT -- The BLINKY_PLANT
minetest.register_node("mesecons_blinkyplant:blinky_plant", {
drawtype = "plantlike",
visual_scale = 1,
tiles = {"jeija_blinky_plant_off.png"},
inventory_image = "jeija_blinky_plant_off.png",
walkable = false,
groups = {dig_immediate=3, not_in_creative_inventory=1},
drop="mesecons_blinkyplant:blinky_plant_off 1",
description="Deactivated Blinky Plant",
sounds = default.node_sound_leaves_defaults(),
selection_box = {
type = "fixed",
fixed = {-0.3, -0.5, -0.3, 0.3, -0.5+0.7, 0.3},
},
mesecons = {receptor = {
state = mesecon.state.off
}},
on_rightclick = function(pos, node, clicker)
minetest.set_node(pos, {name="mesecons_blinkyplant:blinky_plant_off"})
end
})
minetest.register_node("mesecons_blinkyplant:blinky_plant_off", { minetest.register_node("mesecons_blinkyplant:blinky_plant_off", {
drawtype = "plantlike", drawtype = "plantlike",
@ -37,10 +16,7 @@ minetest.register_node("mesecons_blinkyplant:blinky_plant_off", {
}, },
mesecons = {receptor = { mesecons = {receptor = {
state = mesecon.state.off state = mesecon.state.off
}}, }}
on_rightclick = function(pos, node, clicker)
minetest.set_node(pos, {name="mesecons_blinkyplant:blinky_plant"})
end
}) })
minetest.register_node("mesecons_blinkyplant:blinky_plant_on", { minetest.register_node("mesecons_blinkyplant:blinky_plant_on", {
@ -61,11 +37,7 @@ minetest.register_node("mesecons_blinkyplant:blinky_plant_on", {
}, },
mesecons = {receptor = { mesecons = {receptor = {
state = mesecon.state.on state = mesecon.state.on
}}, }}
on_rightclick = function(pos, node, clicker)
minetest.set_node(pos, {name = "mesecons_blinkyplant:blinky_plant"})
mesecon:receptor_off(pos)
end
}) })
minetest.register_craft({ minetest.register_craft({
@ -82,8 +54,8 @@ minetest.register_abm(
interval = BLINKY_PLANT_INTERVAL, interval = BLINKY_PLANT_INTERVAL,
chance = 1, chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider) action = function(pos, node, active_object_count, active_object_count_wider)
--minetest.remove_node(pos) --minetest.env:remove_node(pos)
minetest.add_node(pos, {name="mesecons_blinkyplant:blinky_plant_on"}) minetest.env:add_node(pos, {name="mesecons_blinkyplant:blinky_plant_on"})
nodeupdate(pos) nodeupdate(pos)
mesecon:receptor_on(pos) mesecon:receptor_on(pos)
end, end,
@ -94,8 +66,8 @@ minetest.register_abm({
interval = BLINKY_PLANT_INTERVAL, interval = BLINKY_PLANT_INTERVAL,
chance = 1, chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider) action = function(pos, node, active_object_count, active_object_count_wider)
--minetest.remove_node(pos) --minetest.env:remove_node(pos)
minetest.add_node(pos, {name="mesecons_blinkyplant:blinky_plant_off"}) minetest.env:add_node(pos, {name="mesecons_blinkyplant:blinky_plant_off"})
nodeupdate(pos) nodeupdate(pos)
mesecon:receptor_off(pos) mesecon:receptor_off(pos)
end, end,

View File

@ -3,9 +3,9 @@
-- and then turns off again -- and then turns off again
mesecon.button_turnoff = function (pos) mesecon.button_turnoff = function (pos)
local node = minetest.get_node(pos) local node = minetest.env:get_node(pos)
if node.name=="mesecons_button:button_on" then --has not been dug if node.name=="mesecons_button:button_on" then --has not been dug
minetest.swap_node(pos, {name = "mesecons_button:button_off", param2=node.param2}) mesecon:swap_node(pos, "mesecons_button:button_off")
minetest.sound_play("mesecons_button_pop", {pos=pos}) minetest.sound_play("mesecons_button_pop", {pos=pos})
local rules = mesecon.rules.buttonlike_get(node) local rules = mesecon.rules.buttonlike_get(node)
mesecon:receptor_off(pos, rules) mesecon:receptor_off(pos, rules)
@ -41,7 +41,7 @@ minetest.register_node("mesecons_button:button_off", {
groups = {dig_immediate=2, mesecon_needs_receiver = 1}, groups = {dig_immediate=2, mesecon_needs_receiver = 1},
description = "Button", description = "Button",
on_punch = function (pos, node) on_punch = function (pos, node)
minetest.swap_node(pos, {name = "mesecons_button:button_on", param2=node.param2}) mesecon:swap_node(pos, "mesecons_button:button_on")
mesecon:receptor_on(pos, mesecon.rules.buttonlike_get(node)) mesecon:receptor_on(pos, mesecon.rules.buttonlike_get(node))
minetest.sound_play("mesecons_button_push", {pos=pos}) minetest.sound_play("mesecons_button_push", {pos=pos})
minetest.after(1, mesecon.button_turnoff, pos) minetest.after(1, mesecon.button_turnoff, pos)

View File

@ -16,13 +16,21 @@ minetest.register_chatcommand("tell", {
minetest.chat_send_player(name, "Invalid usage: " .. param) minetest.chat_send_player(name, "Invalid usage: " .. param)
return return
end end
if not minetest.get_player_by_name(target) then if not minetest.env:get_player_by_name(target) then
minetest.chat_send_player(name, "Invalid target: " .. target) minetest.chat_send_player(name, "Invalid target: " .. target)
end end
minetest.chat_send_player(target, name .. " whispers: " .. message, false) minetest.chat_send_player(target, name .. " whispers: " .. message, false)
end end
}) })
minetest.register_chatcommand("tellme", {
params = "<text>",
description = "Say <text> to yourself",
func = function(name, param)
minetest.chat_send_player(name, param, false)
end
})
minetest.register_chatcommand("hp", { minetest.register_chatcommand("hp", {
params = "<name> <value>", params = "<name> <value>",
description = "Set health of <name> to <value> hitpoints", description = "Set health of <name> to <value> hitpoints",
@ -33,7 +41,7 @@ minetest.register_chatcommand("hp", {
minetest.chat_send_player(name, "Invalid usage: " .. param) minetest.chat_send_player(name, "Invalid usage: " .. param)
return return
end end
local player = minetest.get_player_by_name(target) local player = minetest.env:get_player_by_name(target)
if player then if player then
player:set_hp(value) player:set_hp(value)
else else
@ -42,13 +50,16 @@ minetest.register_chatcommand("hp", {
end end
}) })
local function initialize_data(meta) local initialize_data = function(meta, player, command, param)
local commands = meta:get_string("commands")
meta:set_string("formspec", meta:set_string("formspec",
"invsize[9,5;]" .. "invsize[9,6;]" ..
"textarea[0.5,0.5;8.5,4;commands;Commands;"..commands.."]" .. "field[1,1;7.5,1;player;Player;" .. player .. "]" ..
"label[1,3.8;@nearest, @farthest, and @random are replaced by the respective player names]" .. "button[1.3,2;2,1;nearest;Nearest]" ..
"button_exit[3.3,4.5;2,1;submit;Submit]") "button[3.3,2;2,1;farthest;Farthest]" ..
"button[5.3,2;2,1;random;Random]" ..
"field[1,4;2,1;command;Command;" .. command .. "]" ..
"field[3,4;5.5,1;param;Parameter;" .. param .. "]" ..
"button_exit[3.3,5;2,1;submit;Submit]")
local owner = meta:get_string("owner") local owner = meta:get_string("owner")
if owner == "" then if owner == "" then
owner = "not owned" owner = "not owned"
@ -57,113 +68,108 @@ local function initialize_data(meta)
end end
meta:set_string("infotext", "Command Block\n" .. meta:set_string("infotext", "Command Block\n" ..
"(" .. owner .. ")\n" .. "(" .. owner .. ")\n" ..
"Commands: "..commands) "Command: /" .. command .. " " .. param)
end end
local function construct(pos) local construct = function(pos)
local meta = minetest.get_meta(pos) local meta = minetest.env:get_meta(pos)
meta:set_string("commands", "tell @nearest Commandblock unconfigured") meta:set_string("player", "@nearest")
meta:set_string("command", "time")
meta:set_string("param", "7000")
meta:set_string("owner", "") meta:set_string("owner", "")
initialize_data(meta) initialize_data(meta, "@nearest", "time", "7000")
end end
local function after_place(pos, placer) local after_place = function(pos, placer)
if placer then if placer then
local meta = minetest.get_meta(pos) local meta = minetest.env:get_meta(pos)
meta:set_string("owner", placer:get_player_name()) meta:set_string("owner", placer:get_player_name())
initialize_data(meta) initialize_data(meta, "@nearest", "time", "7000")
end end
end end
local function receive_fields(pos, formname, fields, sender) local receive_fields = function(pos, formname, fields, sender)
if fields.quit then local meta = minetest.env:get_meta(pos)
return if fields.nearest then
end initialize_data(meta, "@nearest", fields.command, fields.param)
local meta = minetest.get_meta(pos) elseif fields.farthest then
local owner = meta:get_string("owner") initialize_data(meta, "@farthest", fields.command, fields.param)
if owner ~= "" and sender:get_player_name() ~= owner then elseif fields.random then
return initialize_data(meta, "@random", fields.command, fields.param)
end else --fields.submit or pressed enter
meta:set_string("commands", fields.commands) meta:set_string("player", fields.player)
meta:set_string("command", fields.command)
meta:set_string("param", fields.param)
initialize_data(meta) initialize_data(meta, fields.player, fields.command, fields.param)
end
end end
local function resolve_commands(commands, pos) local resolve_player = function(name, pos)
local nearest, farthest = nil, nil local get_distance = function(pos1, pos2)
local min_distance, max_distance = math.huge, -1 return math.sqrt((pos1.x - pos2.x) ^ 2 + (pos1.y - pos2.y) ^ 2 + (pos1.z - pos2.z) ^ 2)
local players = minetest.get_connected_players() end
for index, player in pairs(players) do
local distance = vector.distance(pos, player:getpos()) if name == "@nearest" then
local min_distance = math.huge
for index, player in ipairs(minetest.get_connected_players()) do
local distance = get_distance(pos, player:getpos())
if distance < min_distance then if distance < min_distance then
min_distance = distance min_distance = distance
nearest = player:get_player_name() name = player:get_player_name()
end end
end
elseif name == "@farthest" then
local max_distance = -1
for index, player in ipairs(minetest.get_connected_players()) do
local distance = get_distance(pos, player:getpos())
if distance > max_distance then if distance > max_distance then
max_distance = distance max_distance = distance
farthest = player:get_player_name() name = player:get_player_name()
end end
end end
local random = players[math.random(#players)]:get_player_name() elseif name == "@random" then
commands = commands:gsub("@nearest", nearest) local players = minetest.get_connected_players()
commands = commands:gsub("@farthest", farthest) local player = players[math.random(#players)]
commands = commands:gsub("@random", random) name = player:get_player_name()
return commands end
return name
end end
local function commandblock_action_on(pos, node) local commandblock_action_on = function(pos, node)
if node.name ~= "mesecons_commandblock:commandblock_off" then if node.name ~= "mesecons_commandblock:commandblock_off" then
return return
end end
minetest.swap_node(pos, {name = "mesecons_commandblock:commandblock_on"}) mesecon:swap_node(pos, "mesecons_commandblock:commandblock_on")
local meta = minetest.get_meta(pos) local meta = minetest.env:get_meta(pos)
local command = minetest.chatcommands[meta:get_string("command")]
if command == nil then
return
end
local owner = meta:get_string("owner") local owner = meta:get_string("owner")
if owner == "" then if owner == "" then
return return
end end
local has_privs, missing_privs = minetest.check_player_privs(owner, command.privs)
local commands = resolve_commands(meta:get_string("commands"), pos)
for _, command in pairs(commands:split("\n")) do
local pos = command:find(" ")
local cmd, param = command, ""
if pos then
cmd = command:sub(1, pos - 1)
param = command:sub(pos + 1)
end
local cmddef = minetest.chatcommands[cmd]
if not cmddef then
minetest.chat_send_player(owner, "The command "..cmd.." does not exist")
return
end
local has_privs, missing_privs = minetest.check_player_privs(owner, cmddef.privs)
if not has_privs then if not has_privs then
minetest.chat_send_player(owner, "You don't have permission " minetest.chat_send_player(owner, "You don't have permission to run this command (missing privileges: "..table.concat(missing_privs, ", ")..")")
.."to run "..cmd
.." (missing privileges: "
..table.concat(missing_privs, ", ")..")")
return return
end end
cmddef.func(owner, param) local player = resolve_player(meta:get_string("player"), pos)
end command.func(player, meta:get_string("param"))
end end
local function commandblock_action_off(pos, node) local commandblock_action_off = function(pos, node)
if node.name == "mesecons_commandblock:commandblock_on" then if node.name == "mesecons_commandblock:commandblock_on" then
minetest.swap_node(pos, {name = "mesecons_commandblock:commandblock_off"}) mesecon:swap_node(pos, "mesecons_commandblock:commandblock_off")
end end
end end
local function can_dig(pos, player)
local meta = minetest.get_meta(pos)
local owner = meta:get_string("owner")
return owner == "" or owner == player:get_player_name()
end
minetest.register_node("mesecons_commandblock:commandblock_off", { minetest.register_node("mesecons_commandblock:commandblock_off", {
description = "Command Block", description = "Command Block",
tiles = {"jeija_commandblock_off.png"}, tiles = {"jeija_commandblock_off.png"},
@ -172,7 +178,10 @@ minetest.register_node("mesecons_commandblock:commandblock_off", {
on_construct = construct, on_construct = construct,
after_place_node = after_place, after_place_node = after_place,
on_receive_fields = receive_fields, on_receive_fields = receive_fields,
can_dig = can_dig, can_dig = function(pos,player)
local owner = minetest.env:get_meta(pos):get_string("owner")
return owner == "" or owner == player:get_player_name()
end,
sounds = default.node_sound_stone_defaults(), sounds = default.node_sound_stone_defaults(),
mesecons = {effector = { mesecons = {effector = {
action_on = commandblock_action_on action_on = commandblock_action_on
@ -187,7 +196,10 @@ minetest.register_node("mesecons_commandblock:commandblock_on", {
on_construct = construct, on_construct = construct,
after_place_node = after_place, after_place_node = after_place,
on_receive_fields = receive_fields, on_receive_fields = receive_fields,
can_dig = can_dig, can_dig = function(pos,player)
local owner = minetest.env:get_meta(pos):get_string("owner")
return owner == "" or owner == player:get_player_name()
end,
sounds = default.node_sound_stone_defaults(), sounds = default.node_sound_stone_defaults(),
mesecons = {effector = { mesecons = {effector = {
action_off = commandblock_action_off action_off = commandblock_action_off

View File

@ -1,2 +1,2 @@
doors
mesecons mesecons
doors

View File

@ -0,0 +1,167 @@
doors = {}
-- Registers a door - REDEFINITION ONLY | DOORS MOD MUST HAVE BEEN LOADED BEFORE
-- name: The name of the door
-- def: a table with the folowing fields:
-- description
-- inventory_image
-- groups
-- tiles_bottom: the tiles of the bottom part of the door {front, side}
-- tiles_top: the tiles of the bottom part of the door {front, side}
-- If the following fields are not defined the default values are used
-- node_box_bottom
-- node_box_top
-- selection_box_bottom
-- selection_box_top
-- only_placer_can_open: if true only the player who placed the door can
-- open it
function doors:register_door(name, def)
def.groups.not_in_creative_inventory = 1
local box = {{-0.5, -0.5, -0.5, 0.5, 0.5, -0.5+1.5/16}}
if not def.node_box_bottom then
def.node_box_bottom = box
end
if not def.node_box_top then
def.node_box_top = box
end
if not def.selection_box_bottom then
def.selection_box_bottom= box
end
if not def.selection_box_top then
def.selection_box_top = box
end
local tt = def.tiles_top
local tb = def.tiles_bottom
local function after_dig_node(pos, name)
if minetest.env:get_node(pos).name == name then
minetest.env:remove_node(pos)
end
end
local function on_rightclick(pos, dir, check_name, replace, replace_dir, params)
pos.y = pos.y+dir
if not minetest.env:get_node(pos).name == check_name then
return
end
local p2 = minetest.env:get_node(pos).param2
p2 = params[p2+1]
local meta = minetest.env:get_meta(pos):to_table()
minetest.env:set_node(pos, {name=replace_dir, param2=p2})
minetest.env:get_meta(pos):from_table(meta)
pos.y = pos.y-dir
meta = minetest.env:get_meta(pos):to_table()
minetest.env:set_node(pos, {name=replace, param2=p2})
minetest.env:get_meta(pos):from_table(meta)
end
local function on_mesecons_signal_open (pos, node)
on_rightclick(pos, 1, name.."_t_1", name.."_b_2", name.."_t_2", {1,2,3,0})
end
local function on_mesecons_signal_close (pos, node)
on_rightclick(pos, 1, name.."_t_2", name.."_b_1", name.."_t_1", {3,0,1,2})
end
local function check_player_priv(pos, player)
if not def.only_placer_can_open then
return true
end
local meta = minetest.env:get_meta(pos)
local pn = player:get_player_name()
return meta:get_string("doors_owner") == pn
end
minetest.register_node(":"..name.."_b_1", {
tiles = {tb[2], tb[2], tb[2], tb[2], tb[1], tb[1].."^[transformfx"},
paramtype = "light",
paramtype2 = "facedir",
drop = name,
drawtype = "nodebox",
node_box = {
type = "fixed",
fixed = def.node_box_bottom
},
selection_box = {
type = "fixed",
fixed = def.selection_box_bottom
},
groups = def.groups,
after_dig_node = function(pos, oldnode, oldmetadata, digger)
pos.y = pos.y+1
after_dig_node(pos, name.."_t_1")
end,
on_rightclick = function(pos, node, puncher)
if check_player_priv(pos, puncher) then
on_rightclick(pos, 1, name.."_t_1", name.."_b_2", name.."_t_2", {1,2,3,0})
end
end,
mesecons = {effector = {
action_on = on_mesecons_signal_open
}},
can_dig = check_player_priv,
})
minetest.register_node(":"..name.."_b_2", {
tiles = {tb[2], tb[2], tb[2], tb[2], tb[1].."^[transformfx", tb[1]},
paramtype = "light",
paramtype2 = "facedir",
drop = name,
drawtype = "nodebox",
node_box = {
type = "fixed",
fixed = def.node_box_bottom
},
selection_box = {
type = "fixed",
fixed = def.selection_box_bottom
},
groups = def.groups,
after_dig_node = function(pos, oldnode, oldmetadata, digger)
pos.y = pos.y+1
after_dig_node(pos, name.."_t_2")
end,
on_rightclick = function(pos, node, puncher)
if check_player_priv(pos, puncher) then
on_rightclick(pos, 1, name.."_t_2", name.."_b_1", name.."_t_1", {3,0,1,2})
end
end,
mesecons = {effector = {
action_off = on_mesecons_signal_close
}},
can_dig = check_player_priv,
})
end
doors:register_door("doors:door_wood", {
description = "Wooden Door",
inventory_image = "door_wood.png",
groups = {snappy=1,choppy=2,oddly_breakable_by_hand=2,flammable=2,door=1},
tiles_bottom = {"door_wood_b.png", "door_brown.png"},
tiles_top = {"door_wood_a.png", "door_brown.png"},
sounds = default.node_sound_wood_defaults(),
})
doors:register_door("doors:door_steel", {
description = "Steel Door",
inventory_image = "door_steel.png",
groups = {snappy=1,bendy=2,cracky=1,melty=2,level=2,door=1},
tiles_bottom = {"door_steel_b.png", "door_grey.png"},
tiles_top = {"door_steel_a.png", "door_grey.png"},
only_placer_can_open = true,
sounds = default.node_sound_stone_defaults(),
})

View File

@ -17,18 +17,28 @@ end
-- Functions that are called after the delay time -- Functions that are called after the delay time
local delayer_turnon = function(params)
local rules = delayer_get_output_rules(params.node)
mesecon:receptor_on(params.pos, rules)
end
local delayer_turnoff = function(params)
local rules = delayer_get_output_rules(params.node)
mesecon:receptor_off(params.pos, rules)
end
local delayer_activate = function(pos, node) local delayer_activate = function(pos, node)
local def = minetest.registered_nodes[node.name] local def = minetest.registered_nodes[node.name]
local time = def.delayer_time local time = def.delayer_time
minetest.swap_node(pos, {name = def.delayer_onstate, param2=node.param2}) mesecon:swap_node(pos, def.delayer_onstate)
mesecon.queue:add_action(pos, "receptor_on", {delayer_get_output_rules(node)}, time, nil) minetest.after(time, delayer_turnon , {pos = pos, node = node})
end end
local delayer_deactivate = function(pos, node) local delayer_deactivate = function(pos, node)
local def = minetest.registered_nodes[node.name] local def = minetest.registered_nodes[node.name]
local time = def.delayer_time local time = def.delayer_time
minetest.swap_node(pos, {name = def.delayer_offstate, param2=node.param2}) mesecon:swap_node(pos, def.delayer_offstate)
mesecon.queue:add_action(pos, "receptor_off", {delayer_get_output_rules(node)}, time, nil) minetest.after(time, delayer_turnoff, {pos = pos, node = node})
end end
-- Register the 2 (states) x 4 (delay times) delayers -- Register the 2 (states) x 4 (delay times) delayers
@ -89,13 +99,13 @@ minetest.register_node("mesecons_delayer:delayer_off_"..tostring(i), {
drop = 'mesecons_delayer:delayer_off_1', drop = 'mesecons_delayer:delayer_off_1',
on_punch = function (pos, node) on_punch = function (pos, node)
if node.name=="mesecons_delayer:delayer_off_1" then if node.name=="mesecons_delayer:delayer_off_1" then
minetest.swap_node(pos, {name = "mesecons_delayer:delayer_off_2", param2=node.param2}) mesecon:swap_node(pos,"mesecons_delayer:delayer_off_2")
elseif node.name=="mesecons_delayer:delayer_off_2" then elseif node.name=="mesecons_delayer:delayer_off_2" then
minetest.swap_node(pos, {name = "mesecons_delayer:delayer_off_3", param2=node.param2}) mesecon:swap_node(pos,"mesecons_delayer:delayer_off_3")
elseif node.name=="mesecons_delayer:delayer_off_3" then elseif node.name=="mesecons_delayer:delayer_off_3" then
minetest.swap_node(pos, {name = "mesecons_delayer:delayer_off_4", param2=node.param2}) mesecon:swap_node(pos,"mesecons_delayer:delayer_off_4")
elseif node.name=="mesecons_delayer:delayer_off_4" then elseif node.name=="mesecons_delayer:delayer_off_4" then
minetest.swap_node(pos, {name = "mesecons_delayer:delayer_off_1", param2=node.param2}) mesecon:swap_node(pos,"mesecons_delayer:delayer_off_1")
end end
end, end,
delayer_time = delaytime, delayer_time = delaytime,
@ -144,13 +154,13 @@ minetest.register_node("mesecons_delayer:delayer_on_"..tostring(i), {
drop = 'mesecons_delayer:delayer_off_1', drop = 'mesecons_delayer:delayer_off_1',
on_punch = function (pos, node) on_punch = function (pos, node)
if node.name=="mesecons_delayer:delayer_on_1" then if node.name=="mesecons_delayer:delayer_on_1" then
minetest.swap_node(pos, {name = "mesecons_delayer:delayer_on_2", param2=node.param2}) mesecon:swap_node(pos,"mesecons_delayer:delayer_on_2")
elseif node.name=="mesecons_delayer:delayer_on_2" then elseif node.name=="mesecons_delayer:delayer_on_2" then
minetest.swap_node(pos, {name = "mesecons_delayer:delayer_on_3", param2=node.param2}) mesecon:swap_node(pos,"mesecons_delayer:delayer_on_3")
elseif node.name=="mesecons_delayer:delayer_on_3" then elseif node.name=="mesecons_delayer:delayer_on_3" then
minetest.swap_node(pos, {name = "mesecons_delayer:delayer_on_4", param2=node.param2}) mesecon:swap_node(pos,"mesecons_delayer:delayer_on_4")
elseif node.name=="mesecons_delayer:delayer_on_4" then elseif node.name=="mesecons_delayer:delayer_on_4" then
minetest.swap_node(pos, {name = "mesecons_delayer:delayer_on_1", param2=node.param2}) mesecon:swap_node(pos,"mesecons_delayer:delayer_on_1")
end end
end, end,
delayer_time = delaytime, delayer_time = delaytime,

View File

@ -3,17 +3,14 @@
-- The radius can be specified in mesecons/settings.lua -- The radius can be specified in mesecons/settings.lua
local object_detector_make_formspec = function (pos) local object_detector_make_formspec = function (pos)
local meta = minetest.get_meta(pos) local meta = minetest.env:get_meta(pos)
meta:set_string("formspec", "size[9,2.5]" .. meta:set_string("formspec", "size[9,2.5]" ..
"field[0.3, 0;9,2;scanname;Name of player to scan for (empty for any):;${scanname}]".. "field[0.3, 0;9,2;scanname;Name of player to scan for (empty for any):;${scanname}]"..
"field[0.3,1.5;4,2;digiline_channel;Digiline Channel (optional):;${digiline_channel}]".. "field[0.3,1.5;4,2;digiline_channel;Digiline Channel (optional):;${digiline_channel}]")
"button_exit[7,0.75;2,3;;Save]")
end end
local object_detector_on_receive_fields = function (pos, formname, fields) local object_detector_on_receive_fields = function (pos, formname, fields)
if not fields.scanname or not fields.digiline_channel then return end; local meta = minetest.env:get_meta(pos)
local meta = minetest.get_meta(pos)
meta:set_string("scanname", fields.scanname) meta:set_string("scanname", fields.scanname)
meta:set_string("digiline_channel", fields.digiline_channel) meta:set_string("digiline_channel", fields.digiline_channel)
object_detector_make_formspec(pos) object_detector_make_formspec(pos)
@ -21,10 +18,10 @@ end
-- returns true if player was found, false if not -- returns true if player was found, false if not
local object_detector_scan = function (pos) local object_detector_scan = function (pos)
local objs = minetest.get_objects_inside_radius(pos, OBJECT_DETECTOR_RADIUS) local objs = minetest.env:get_objects_inside_radius(pos, OBJECT_DETECTOR_RADIUS)
for k, obj in pairs(objs) do for k, obj in pairs(objs) do
local isname = obj:get_player_name() -- "" is returned if it is not a player; "" ~= nil! local isname = obj:get_player_name() -- "" is returned if it is not a player; "" ~= nil!
local scanname = minetest.get_meta(pos):get_string("scanname") local scanname = minetest.env:get_meta(pos):get_string("scanname")
if (isname == scanname and isname ~= "") or (isname ~= "" and scanname == "") then -- player with scanname found or not scanname specified if (isname == scanname and isname ~= "") or (isname ~= "" and scanname == "") then -- player with scanname found or not scanname specified
return true return true
end end
@ -36,7 +33,7 @@ end
object_detector_digiline = { object_detector_digiline = {
effector = { effector = {
action = function (pos, node, channel, msg) action = function (pos, node, channel, msg)
local meta = minetest.get_meta(pos) local meta = minetest.env:get_meta(pos)
local active_channel = meta:get_string("digiline_channel") local active_channel = meta:get_string("digiline_channel")
if channel == active_channel then if channel == active_channel then
meta:set_string("scanname", msg) meta:set_string("scanname", msg)
@ -91,7 +88,7 @@ minetest.register_abm(
chance = 1, chance = 1,
action = function(pos) action = function(pos)
if object_detector_scan(pos) then if object_detector_scan(pos) then
minetest.swap_node(pos, {name = "mesecons_detector:object_detector_on"}) mesecon:swap_node(pos, "mesecons_detector:object_detector_on")
mesecon:receptor_on(pos) mesecon:receptor_on(pos)
end end
end, end,
@ -103,7 +100,7 @@ minetest.register_abm(
chance = 1, chance = 1,
action = function(pos) action = function(pos)
if not object_detector_scan(pos) then if not object_detector_scan(pos) then
minetest.swap_node(pos, {name = "mesecons_detector:object_detector_off"}) mesecon:swap_node(pos, "mesecons_detector:object_detector_off")
mesecon:receptor_off(pos) mesecon:receptor_off(pos)
end end
end, end,

View File

@ -1,130 +0,0 @@
local other_state_node = {}
for _, material in ipairs({
{ id = "wood", desc = "Wooden", color = "brown" },
{ id = "steel", desc = "Steel", color = "grey" },
}) do
doors:register_door("mesecons_doors:op_door_"..material.id, {
description = "Mesecon-operated "..material.desc.." Door",
inventory_image = minetest.registered_items["doors:door_"..material.id].inventory_image,
groups = minetest.registered_nodes["doors:door_"..material.id.."_b_1"].groups,
tiles_bottom = {"door_"..material.id.."_b.png", "door_"..material.color..".png"},
tiles_top = {"door_"..material.id.."_a.png", "door_"..material.color..".png"},
})
local groups_plus_mesecon = { mesecon = 2 }
for k, v in pairs(minetest.registered_nodes["doors:door_"..material.id.."_b_1"].groups) do
groups_plus_mesecon[k] = v
end
doors:register_door("mesecons_doors:sig_door_"..material.id, {
description = "Mesecon-signalling "..material.desc.." Door",
inventory_image = minetest.registered_items["doors:door_"..material.id].inventory_image,
groups = groups_plus_mesecon,
tiles_bottom = {"door_"..material.id.."_b.png", "door_"..material.color..".png"},
tiles_top = {"door_"..material.id.."_a.png", "door_"..material.color..".png"},
})
for _, thishalf in ipairs({ "t", "b" }) do
local otherhalf = thishalf == "t" and "b" or "t"
local otherdir = thishalf == "t" and -1 or 1
for orientation = 1, 2 do
local thissuffix = material.id.."_"..thishalf.."_"..orientation
local othersuffix = material.id.."_"..otherhalf.."_"..orientation
local thisopname = "mesecons_doors:op_door_"..thissuffix
local otheropname = "mesecons_doors:op_door_"..othersuffix
local oponr = minetest.registered_nodes[thisopname].on_rightclick
local function handle_mesecon_signal (thispos, thisnode, signal)
local thismeta = minetest.get_meta(thispos)
if signal == thismeta:get_int("sigstate") then return end
thismeta:set_int("sigstate", signal)
local otherpos = { x = thispos.x, y = thispos.y + otherdir, z = thispos.z }
if minetest.get_node(otherpos).name ~= otheropname then return end
local othermeta = minetest.get_meta(otherpos)
local newdoorstate = math.max(thismeta:get_int("sigstate"), othermeta:get_int("sigstate"))
if newdoorstate == thismeta:get_int("doorstate") then return end
oponr(thispos, thisnode, nil)
thismeta:set_int("doorstate", newdoorstate)
othermeta:set_int("doorstate", newdoorstate)
end
minetest.override_item(thisopname, {
on_construct = function (pos)
if mesecon:is_powered(pos) then
local node = minetest.get_node(pos)
mesecon:changesignal(pos, node, mesecon:effector_get_rules(node), "on", 1)
mesecon:activate(pos, node, nil, 1)
end
end,
on_rightclick = function (pos, node, clicker) end,
mesecons = {
effector = {
action_on = function (pos, node)
handle_mesecon_signal(pos, node, 1)
end,
action_off = function (pos, node)
handle_mesecon_signal(pos, node, 0)
end,
},
},
})
local thissigname = "mesecons_doors:sig_door_"..thissuffix
local othersigname = "mesecons_doors:sig_door_"..othersuffix
local sigonr = minetest.registered_nodes[thissigname].on_rightclick
minetest.override_item(thissigname, {
on_rightclick = function (thispos, thisnode, clicker)
local otherpos = { x = thispos.x, y = thispos.y + otherdir, z = thispos.z }
print("open: otherpos.name="..minetest.get_node(otherpos).name..", othersigname="..othersigname)
if minetest.get_node(otherpos).name ~= othersigname then return end
sigonr(thispos, thisnode, clicker)
for _, pos in ipairs({ thispos, otherpos }) do
local node = minetest.get_node(pos)
node.name = other_state_node[node.name]
minetest.swap_node(pos, node)
mesecon:receptor_on(pos)
end
end,
mesecons = { receptor = { state = mesecon.state.off } },
})
other_state_node[thissigname] = thissigname.."_on"
local ondef = {}
for k, v in pairs(minetest.registered_nodes[thissigname]) do
ondef[k] = v
end
ondef.on_rightclick = function (thispos, thisnode, clicker)
local otherpos = { x = thispos.x, y = thispos.y + otherdir, z = thispos.z }
print("close: otherpos.name="..minetest.get_node(otherpos).name..", othersigname="..othersigname)
if minetest.get_node(otherpos).name ~= othersigname.."_on" then return end
for _, pos in ipairs({ thispos, otherpos }) do
local node = minetest.get_node(pos)
node.name = other_state_node[node.name]
minetest.swap_node(pos, node)
mesecon:receptor_off(pos)
end
sigonr(thispos, thisnode, clicker)
end
ondef.mesecons = { receptor = { state = mesecon.state.on } }
ondef.after_destruct = function (thispos, thisnode)
local otherpos = { x = thispos.x, y = thispos.y + otherdir, z = thispos.z }
if minetest.get_node(otherpos).name == othersigname.."_on" then
minetest.remove_node(otherpos)
mesecon:receptor_off(otherpos)
end
end
other_state_node[thissigname.."_on"] = thissigname
ondef.mesecon_other_state_node = thissigname
minetest.register_node(thissigname.."_on", ondef)
end
end
minetest.register_craft({
output = "mesecons_doors:op_door_"..material.id,
recipe = {
{ "group:mesecon_conductor_craftable", "", "" },
{ "", "doors:door_"..material.id, "group:mesecon_conductor_craftable" },
{ "group:mesecon_conductor_craftable", "", "" },
},
})
minetest.register_craft({
output = "mesecons_doors:sig_door_"..material.id,
recipe = {
{ "", "", "group:mesecon_conductor_craftable" },
{ "group:mesecon_conductor_craftable", "doors:door_"..material.id, "" },
{ "", "", "group:mesecon_conductor_craftable" },
},
})
end

View File

@ -0,0 +1,49 @@
-- CODE NOT ACTIVE
local crossing_get_rules = function(node)
--TODO: calculate the real port states and use rules to link to them only if
end
minetest.register_node("mesecons_extrawires:crossing_on", {
drawtype = "nodebox",
tiles = {"jeija_insulated_wire_sides_on.png"},
paramtype = "light",
walkable = false,
stack_max = 99,
selection_box = {type="fixed", fixed={-16/32-0.0001, -18/32, -16/32-0.001, 16/32+0.001, -5/32, 16/32+0.001}},
node_box = {
type = "fixed",
fixed = {
{ -16/32-0.001, -17/32, -3/32, 16/32+0.001, -13/32, 3/32 },
{ -3/32, -17/32, -16/32-0.001, 3/32, -13/32, -6/32 },
{ -3/32, -13/32, -9/32, 3/32, -6/32, -6/32 },
{ -3/32, -9/32, -9/32, 3/32, -6/32, 9/32 },
{ -3/32, -13/32, 6/32, 3/32, -6/32, 9/32 },
{ -3/32, -17/32, 6/32, 3/32, -13/32, 16/32+0.001 },
},
},
groups = {dig_immediate=3, mesecon=3, mesecon_conductor_craftable=1, not_in_creative_inventory=1},
mesecons = {
receptor = {
state = mesecon.state.on,
rules = crossing_get_rules,
}
},
})
minetest.register_craft({
type = "shapeless",
output = "mesecons_extrawires:crossing",
recipe = {
"mesecons_insulated:insulated_off",
"mesecons_insulated:insulated_off",
},
})
minetest.register_craft({
type = "shapeless",
output = "mesecons_insulated:insulated_off 2",
recipe = {
"mesecons_extrawires:crossing",
},
})

View File

@ -1,176 +0,0 @@
function crossover_get_rules(node)
return {
{--first wire
{x=-1,y=0,z=0},
{x=1,y=0,z=0},
},
{--second wire
{x=0,y=0,z=-1},
{x=0,y=0,z=1},
},
}
end
local crossover_states = {
"mesecons_extrawires:crossover_off",
"mesecons_extrawires:crossover_01",
"mesecons_extrawires:crossover_10",
"mesecons_extrawires:crossover_on",
}
minetest.register_node("mesecons_extrawires:crossover_off", {
description = "Insulated Crossover",
drawtype = "nodebox",
tiles = {
"jeija_insulated_wire_crossing_tb_off.png",
"jeija_insulated_wire_crossing_tb_off.png",
"jeija_insulated_wire_ends_off.png"
},
paramtype = "light",
walkable = false,
stack_max = 99,
selection_box = {type="fixed", fixed={-16/32-0.0001, -18/32, -16/32-0.001, 16/32+0.001, -5/32, 16/32+0.001}},
node_box = {
type = "fixed",
fixed = {
{ -16/32-0.001, -17/32, -3/32, 16/32+0.001, -13/32, 3/32 },
{ -3/32, -17/32, -16/32-0.001, 3/32, -13/32, -6/32 },
{ -3/32, -13/32, -9/32, 3/32, -6/32, -6/32 },
{ -3/32, -9/32, -9/32, 3/32, -6/32, 9/32 },
{ -3/32, -13/32, 6/32, 3/32, -6/32, 9/32 },
{ -3/32, -17/32, 6/32, 3/32, -13/32, 16/32+0.001 },
},
},
groups = {dig_immediate=3, mesecon=3, mesecon_conductor_craftable=1},
mesecons = {
conductor = {
states = crossover_states,
rules = crossover_get_rules(),
}
},
})
minetest.register_node("mesecons_extrawires:crossover_01", {
description = "You hacker you!",
drop = "mesecons_extrawires:crossover_off",
drawtype = "nodebox",
tiles = {
"jeija_insulated_wire_crossing_tb_01.png",
"jeija_insulated_wire_crossing_tb_01.png",
"jeija_insulated_wire_ends_01x.png",
"jeija_insulated_wire_ends_01x.png",
"jeija_insulated_wire_ends_01z.png",
"jeija_insulated_wire_ends_01z.png"
},
paramtype = "light",
walkable = false,
stack_max = 99,
selection_box = {type="fixed", fixed={-16/32-0.0001, -18/32, -16/32-0.001, 16/32+0.001, -5/32, 16/32+0.001}},
node_box = {
type = "fixed",
fixed = {
{ -16/32-0.001, -17/32, -3/32, 16/32+0.001, -13/32, 3/32 },
{ -3/32, -17/32, -16/32-0.001, 3/32, -13/32, -6/32 },
{ -3/32, -13/32, -9/32, 3/32, -6/32, -6/32 },
{ -3/32, -9/32, -9/32, 3/32, -6/32, 9/32 },
{ -3/32, -13/32, 6/32, 3/32, -6/32, 9/32 },
{ -3/32, -17/32, 6/32, 3/32, -13/32, 16/32+0.001 },
},
},
groups = {dig_immediate=3, mesecon=3, not_in_creative_inventory=1},
mesecons = {
conductor = {
states = crossover_states,
rules = crossover_get_rules(),
}
},
})
minetest.register_node("mesecons_extrawires:crossover_10", {
description = "You hacker you!",
drop = "mesecons_extrawires:crossover_off",
drawtype = "nodebox",
tiles = {
"jeija_insulated_wire_crossing_tb_10.png",
"jeija_insulated_wire_crossing_tb_10.png",
"jeija_insulated_wire_ends_10x.png",
"jeija_insulated_wire_ends_10x.png",
"jeija_insulated_wire_ends_10z.png",
"jeija_insulated_wire_ends_10z.png"
},
paramtype = "light",
walkable = false,
stack_max = 99,
selection_box = {type="fixed", fixed={-16/32-0.0001, -18/32, -16/32-0.001, 16/32+0.001, -5/32, 16/32+0.001}},
node_box = {
type = "fixed",
fixed = {
{ -16/32-0.001, -17/32, -3/32, 16/32+0.001, -13/32, 3/32 },
{ -3/32, -17/32, -16/32-0.001, 3/32, -13/32, -6/32 },
{ -3/32, -13/32, -9/32, 3/32, -6/32, -6/32 },
{ -3/32, -9/32, -9/32, 3/32, -6/32, 9/32 },
{ -3/32, -13/32, 6/32, 3/32, -6/32, 9/32 },
{ -3/32, -17/32, 6/32, 3/32, -13/32, 16/32+0.001 },
},
},
groups = {dig_immediate=3, mesecon=3, not_in_creative_inventory=1},
mesecons = {
conductor = {
states = crossover_states,
rules = crossover_get_rules(),
}
},
})
minetest.register_node("mesecons_extrawires:crossover_on", {
description = "You hacker you!",
drop = "mesecons_extrawires:crossover_off",
drawtype = "nodebox",
tiles = {
"jeija_insulated_wire_crossing_tb_on.png",
"jeija_insulated_wire_crossing_tb_on.png",
"jeija_insulated_wire_ends_on.png",
"jeija_insulated_wire_ends_on.png",
"jeija_insulated_wire_ends_on.png",
"jeija_insulated_wire_ends_on.png"
},
paramtype = "light",
walkable = false,
stack_max = 99,
selection_box = {type="fixed", fixed={-16/32-0.0001, -18/32, -16/32-0.001, 16/32+0.001, -5/32, 16/32+0.001}},
node_box = {
type = "fixed",
fixed = {
{ -16/32-0.001, -17/32, -3/32, 16/32+0.001, -13/32, 3/32 },
{ -3/32, -17/32, -16/32-0.001, 3/32, -13/32, -6/32 },
{ -3/32, -13/32, -9/32, 3/32, -6/32, -6/32 },
{ -3/32, -9/32, -9/32, 3/32, -6/32, 9/32 },
{ -3/32, -13/32, 6/32, 3/32, -6/32, 9/32 },
{ -3/32, -17/32, 6/32, 3/32, -13/32, 16/32+0.001 },
},
},
groups = {dig_immediate=3, mesecon=3, not_in_creative_inventory=1},
mesecons = {
conductor = {
states = crossover_states,
rules = crossover_get_rules(),
}
},
})
minetest.register_craft({
type = "shapeless",
output = "mesecons_extrawires:crossover_off",
recipe = {
"mesecons_insulated:insulated_off",
"mesecons_insulated:insulated_off",
},
})
minetest.register_craft({
type = "shapeless",
output = "mesecons_insulated:insulated_off 2",
recipe = {
"mesecons_extrawires:crossover_off",
},
})

View File

@ -1,2 +1 @@
default
mesecons mesecons

View File

@ -1,4 +1,5 @@
dofile(minetest.get_modpath("mesecons_extrawires").."/crossover.lua"); -- dofile(minetest.get_modpath("mesecons_extrawires").."/crossing.lua");
-- The crossing code is not active right now because it is hard to maintain
dofile(minetest.get_modpath("mesecons_extrawires").."/tjunction.lua"); dofile(minetest.get_modpath("mesecons_extrawires").."/tjunction.lua");
dofile(minetest.get_modpath("mesecons_extrawires").."/corner.lua"); dofile(minetest.get_modpath("mesecons_extrawires").."/corner.lua");
dofile(minetest.get_modpath("mesecons_extrawires").."/vertical.lua"); dofile(minetest.get_modpath("mesecons_extrawires").."/vertical.lua");

View File

@ -38,7 +38,7 @@ minetest.register_node("mesecons_extrawires:tjunction_on", {
sunlight_propagates = true, sunlight_propagates = true,
selection_box = tjunction_selectionbox, selection_box = tjunction_selectionbox,
node_box = tjunction_nodebox, node_box = tjunction_nodebox,
groups = {dig_immediate = 3, not_in_creative_inventory = 1}, groups = {dig_immediate = 3, mesecon_conductor_craftable=1, not_in_creative_inventory = 1},
drop = "mesecons_extrawires:tjunction_off", drop = "mesecons_extrawires:tjunction_off",
mesecons = {conductor = mesecons = {conductor =
{ {

View File

@ -1,68 +1,72 @@
local vertical_box = { local vbox = {
type = "fixed", type = "fixed",
fixed = {-1/16, -8/16, -1/16, 1/16, 8/16, 1/16} fixed = {-1/16, -.5, -1/16, 1/16, .5, 1/16}
} }
local top_box = { local tbox = {
type = "fixed", type = "fixed",
fixed = {{-8/16, -8/16, -8/16, 8/16, -7/16, 8/16}} fixed = {{-.5, -.5, -.5, .5, -.5 + 1/16, .5}}
} }
local bottom_box = { local bbox = {
type = "fixed", type = "fixed",
fixed = { fixed = {{ -.5, -.5 , -.5, .5, -.5+1/16, .5},
{-8/16, -8/16, -8/16, 8/16, -7/16, 8/16}, {-1/16, -.5+1/16, -1/16, 1/16, .5 , 1/16}}
{-1/16, -7/16, -1/16, 1/16, 8/16, 1/16},
}
} }
local vertical_rules = { local vrules =
{x=0, y=1, z=0}, {{x = 0, y = 1, z = 0},
{x=0, y=-1, z=0}, {x = 0, y =-1, z = 0}}
}
local top_rules = { local trules =
{x=1,y=0, z=0}, {{x = 1, y = 0, z = 0},
{x =-1, y = 0, z = 0}, {x =-1, y = 0, z = 0},
{x = 0, y = 0, z = 1}, {x = 0, y = 0, z = 1},
{x = 0, y = 0, z =-1}, {x = 0, y = 0, z =-1},
{x=0,y=-1, z=0}, {x = 0, y =-1, z = 0}}
}
local bottom_rules = { local brules =
{x=1, y=0, z=0}, {{x = 1, y = 0, z = 0},
{x =-1, y = 0, z = 0}, {x =-1, y = 0, z = 0},
{x = 0, y = 0, z = 1}, {x = 0, y = 0, z = 1},
{x = 0, y = 0, z =-1}, {x = 0, y = 0, z =-1},
{x=0, y=1, z=0}, {x = 0, y = 1, z = 0}}
}
local vertical_updatepos = function (pos) local vertical_updatepos = function (pos)
local node = minetest.get_node(pos) local node = minetest.env:get_node(pos)
if minetest.registered_nodes[node.name] and minetest.registered_nodes[node.name].is_vertical_conductor then if minetest.registered_nodes[node.name].is_vertical_conductor then
local node_above = minetest.get_node(mesecon:addPosRule(pos, vertical_rules[1])) local node_above = minetest.env:get_node(mesecon:addPosRule(pos, vrules[1]))
local node_below = minetest.get_node(mesecon:addPosRule(pos, vertical_rules[2])) local node_below = minetest.env:get_node(mesecon:addPosRule(pos, vrules[2]))
local namestate = minetest.registered_nodes[node.name].vertical_conductor_state local namestate = minetest.registered_nodes[node.name].vertical_conductor_state
local above = minetest.registered_nodes[node_above.name] and minetest.registered_nodes[node_above.name].is_vertical_conductor -- above and below: vertical mesecon
local below = minetest.registered_nodes[node_below.name] and minetest.registered_nodes[node_below.name].is_vertical_conductor if minetest.registered_nodes[node_above.name].is_vertical_conductor
and minetest.registered_nodes[node_below.name].is_vertical_conductor then
minetest.env:add_node (pos,
{name = "mesecons_extrawires:vertical_"..namestate})
if above and below then -- above and below: vertical mesecon -- above only: bottom
minetest.add_node(pos, {name = "mesecons_extrawires:vertical_" .. namestate}) elseif minetest.registered_nodes[node_above.name].is_vertical_conductor
elseif above and not below then -- above only: bottom and not minetest.registered_nodes[node_below.name].is_vertical_conductor then
minetest.add_node(pos, {name = "mesecons_extrawires:vertical_bottom_" .. namestate}) minetest.env:add_node (pos,
elseif not above and below then -- below only: top {name = "mesecons_extrawires:vertical_bottom_"..namestate})
minetest.add_node(pos, {name = "mesecons_extrawires:vertical_top_" .. namestate})
-- below only: top
elseif not minetest.registered_nodes[node_above.name].is_vertical_conductor
and minetest.registered_nodes[node_below.name].is_vertical_conductor then
minetest.env:add_node (pos,
{name = "mesecons_extrawires:vertical_top_"..namestate})
else -- no vertical wire above, no vertical wire below: use default wire else -- no vertical wire above, no vertical wire below: use default wire
minetest.add_node(pos, {name = "mesecons_extrawires:vertical_" .. namestate}) minetest.env:add_node (pos,
{name = "mesecons_extrawires:vertical_"..namestate})
end end
end end
end end
local vertical_update = function (pos, node) local vertical_update = function (pos, node)
vertical_updatepos(pos) -- this one vertical_updatepos(pos) -- this one
vertical_updatepos(mesecon:addPosRule(pos, vertical_rules[1])) -- above vertical_updatepos(mesecon:addPosRule(pos, vrules[1])) -- above
vertical_updatepos(mesecon:addPosRule(pos, vertical_rules[2])) -- below vertical_updatepos(mesecon:addPosRule(pos, vrules[2])) -- below
end end
-- Vertical wire -- Vertical wire
@ -74,18 +78,18 @@ minetest.register_node("mesecons_extrawires:vertical_on", {
paramtype = "light", paramtype = "light",
sunlight_propagates = true, sunlight_propagates = true,
groups = {dig_immediate = 3, not_in_creative_inventory = 1}, groups = {dig_immediate = 3, not_in_creative_inventory = 1},
selection_box = vertical_box, selection_box = vbox,
node_box = vertical_box, node_box = vbox,
is_vertical_conductor = true, is_vertical_conductor = true,
vertical_conductor_state = "on", vertical_conductor_state = "on",
mesecons = {conductor = { mesecons = {conductor = {
state = mesecon.state.on, state = mesecon.state.on,
offstate = "mesecons_extrawires:vertical_off", offstate = "mesecons_extrawires:vertical_off",
rules = vertical_rules, rules = vrules
}}, }},
drop = "mesecons_extrawires:vertical_off", drop = {"mesecons_extrawires:vertical_off"},
after_place_node = vertical_update, after_place_node = vertical_update,
after_dig_node = vertical_update, after_dig_node = vertical_update
}) })
minetest.register_node("mesecons_extrawires:vertical_off", { minetest.register_node("mesecons_extrawires:vertical_off", {
@ -96,17 +100,17 @@ minetest.register_node("mesecons_extrawires:vertical_off", {
paramtype = "light", paramtype = "light",
sunlight_propagates = true, sunlight_propagates = true,
groups = {dig_immediate = 3}, groups = {dig_immediate = 3},
selection_box = vertical_box, selection_box = vbox,
node_box = vertical_box, node_box = vbox,
is_vertical_conductor = true, is_vertical_conductor = true,
vertical_conductor_state = "off", vertical_conductor_state = "off",
mesecons = {conductor = { mesecons = {conductor = {
state = mesecon.state.off, state = mesecon.state.off,
onstate = "mesecons_extrawires:vertical_on", onstate = "mesecons_extrawires:vertical_on",
rules = vertical_rules, rules = vrules
}}, }},
after_place_node = vertical_update, after_place_node = vertical_update,
after_dig_node = vertical_update, after_dig_node = vertical_update
}) })
-- Vertical wire top -- Vertical wire top
@ -118,18 +122,18 @@ minetest.register_node("mesecons_extrawires:vertical_top_on", {
paramtype = "light", paramtype = "light",
sunlight_propagates = true, sunlight_propagates = true,
groups = {dig_immediate = 3, not_in_creative_inventory = 1}, groups = {dig_immediate = 3, not_in_creative_inventory = 1},
selection_box = top_box, selection_box = tbox,
node_box = top_box, node_box = tbox,
is_vertical_conductor = true, is_vertical_conductor = true,
vertical_conductor_state = "on", vertical_conductor_state = "on",
mesecons = {conductor = { mesecons = {conductor = {
state = mesecon.state.on, state = mesecon.state.on,
offstate = "mesecons_extrawires:vertical_top_off", offstate = "mesecons_extrawires:vertical_top_off",
rules = top_rules, rules = trules
}}, }},
drop = "mesecons_extrawires:vertical_off", drop = {"mesecons_extrawires:vertical_off"},
after_place_node = vertical_update, after_place_node = vertical_update,
after_dig_node = vertical_update, after_dig_node = vertical_update
}) })
minetest.register_node("mesecons_extrawires:vertical_top_off", { minetest.register_node("mesecons_extrawires:vertical_top_off", {
@ -140,18 +144,18 @@ minetest.register_node("mesecons_extrawires:vertical_top_off", {
paramtype = "light", paramtype = "light",
sunlight_propagates = true, sunlight_propagates = true,
groups = {dig_immediate = 3, not_in_creative_inventory = 1}, groups = {dig_immediate = 3, not_in_creative_inventory = 1},
selection_box = top_box, selection_box = tbox,
node_box = top_box, node_box = tbox,
is_vertical_conductor = true, is_vertical_conductor = true,
vertical_conductor_state = "off", vertical_conductor_state = "off",
mesecons = {conductor = { mesecons = {conductor = {
state = mesecon.state.off, state = mesecon.state.off,
onstate = "mesecons_extrawires:vertical_top_on", onstate = "mesecons_extrawires:vertical_top_on",
rules = top_rules, rules = trules
}}, }},
drop = "mesecons_extrawires:vertical_off", drop = {"mesecons_extrawires:vertical_off"},
after_place_node = vertical_update, after_place_node = vertical_update,
after_dig_node = vertical_update, after_dig_node = vertical_update
}) })
-- Vertical wire bottom -- Vertical wire bottom
@ -164,16 +168,16 @@ minetest.register_node("mesecons_extrawires:vertical_bottom_on", {
sunlight_propagates = true, sunlight_propagates = true,
vertical_conductor_state = "on", vertical_conductor_state = "on",
groups = {dig_immediate = 3, not_in_creative_inventory = 1}, groups = {dig_immediate = 3, not_in_creative_inventory = 1},
selection_box = bottom_box, selection_box = bbox,
node_box = bottom_box, node_box = bbox,
mesecons = {conductor = { mesecons = {conductor = {
state = mesecon.state.on, state = mesecon.state.on,
offstate = "mesecons_extrawires:vertical_bottom_off", offstate = "mesecons_extrawires:vertical_bottom_off",
rules = bottom_rules, rules = brules
}}, }},
drop = "mesecons_extrawires:vertical_off", drop = {"mesecons_extrawires:vertical_off"},
after_place_node = vertical_update, after_place_node = vertical_update,
after_dig_node = vertical_update, after_dig_node = vertical_update
}) })
minetest.register_node("mesecons_extrawires:vertical_bottom_off", { minetest.register_node("mesecons_extrawires:vertical_bottom_off", {
@ -184,18 +188,18 @@ minetest.register_node("mesecons_extrawires:vertical_bottom_off", {
paramtype = "light", paramtype = "light",
sunlight_propagates = true, sunlight_propagates = true,
groups = {dig_immediate = 3, not_in_creative_inventory = 1}, groups = {dig_immediate = 3, not_in_creative_inventory = 1},
selection_box = bottom_box, selection_box = bbox,
node_box = bottom_box, node_box = bbox,
is_vertical_conductor = true, is_vertical_conductor = true,
vertical_conductor_state = "off", vertical_conductor_state = "off",
mesecons = {conductor = { mesecons = {conductor = {
state = mesecon.state.off, state = mesecon.state.off,
onstate = "mesecons_extrawires:vertical_bottom_on", onstate = "mesecons_extrawires:vertical_bottom_on",
rules = bottom_rules, rules = brules
}}, }},
drop = "mesecons_extrawires:vertical_off", drop = {"mesecons_extrawires:vertical_off"},
after_place_node = vertical_update, after_place_node = vertical_update,
after_dig_node = vertical_update, after_dig_node = vertical_update
}) })
minetest.register_craft({ minetest.register_craft({

View File

@ -23,12 +23,11 @@ function gate_get_input_rules_twoinputs(node)
return gate_rotate_rules(node) return gate_rotate_rules(node)
end end
function update_gate(pos, node, rulename, newstate) function update_gate(pos)
yc_update_real_portstates(pos, node, rulename, newstate)
gate = get_gate(pos) gate = get_gate(pos)
L = rotate_ports( L = rotate_ports(
yc_get_real_portstates(pos), yc_get_real_portstates(pos),
minetest.get_node(pos).param2 minetest.env:get_node(pos).param2
) )
if gate == "diode" then if gate == "diode" then
set_gate(pos, L.a) set_gate(pos, L.a)
@ -45,41 +44,40 @@ end
function set_gate(pos, on) function set_gate(pos, on)
gate = get_gate(pos) gate = get_gate(pos)
local meta = minetest.get_meta(pos) local meta = minetest.env:get_meta(pos)
if on ~= gate_state(pos) then if on ~= gate_state(pos) then
if mesecon.do_overheat(pos) then yc_heat(meta)
minetest.after(0.5, yc_cool, meta)
if yc_overheat(meta) then
pop_gate(pos) pop_gate(pos)
else else
local node = minetest.get_node(pos)
if on then if on then
minetest.swap_node(pos, {name = "mesecons_gates:"..gate.."_on", param2=node.param2}) mesecon:swap_node(pos, "mesecons_gates:"..gate.."_on")
mesecon:receptor_on(pos, mesecon:receptor_on(pos,
gate_get_output_rules(node)) gate_get_output_rules(minetest.env:get_node(pos)))
else else
minetest.swap_node(pos, {name = "mesecons_gates:"..gate.."_off", param2=node.param2}) mesecon:swap_node(pos, "mesecons_gates:"..gate.."_off")
mesecon:receptor_off(pos, mesecon:receptor_off(pos,
gate_get_output_rules(node)) gate_get_output_rules(minetest.env:get_node(pos)))
end end
end end
end end
end end
function get_gate(pos) function get_gate(pos)
return minetest.registered_nodes[minetest.get_node(pos).name].mesecons_gate return minetest.registered_nodes[minetest.env:get_node(pos).name].mesecons_gate
end end
function gate_state(pos) function gate_state(pos)
name = minetest.get_node(pos).name name = minetest.env:get_node(pos).name
return string.find(name, "_on") ~= nil return string.find(name, "_on") ~= nil
end end
function pop_gate(pos) function pop_gate(pos)
gate = get_gate(pos) gate = get_gate(pos)
minetest.remove_node(pos) minetest.env:remove_node(pos)
minetest.after(0.2, function (pos) minetest.after(0.2, yc_overheat_off, pos)
mesecon:receptor_off(pos, mesecon.rules.flat) minetest.env:add_item(pos, "mesecons_gates:"..gate.."_off")
end , pos) -- wait for pending parsings
minetest.add_item(pos, "mesecons_gates:"..gate.."_off")
end end
function rotate_ports(L, param2) function rotate_ports(L, param2)
@ -114,13 +112,13 @@ for _, gate in ipairs(gates) do
drop = nodename.."_off" drop = nodename.."_off"
nodename = nodename.."_"..onoff nodename = nodename.."_"..onoff
description = "You hacker you!" description = "You hacker you!"
groups = {dig_immediate=2, not_in_creative_inventory=1, overheat = 1} groups = {dig_immediate=2, not_in_creative_inventory=1}
else else
onoff = "off" onoff = "off"
drop = nil drop = nil
nodename = nodename.."_"..onoff nodename = nodename.."_"..onoff
description = gate.name.." Gate" description = gate.name.." Gate"
groups = {dig_immediate=2, overheat = 1} groups = {dig_immediate=2}
end end
tiles = "jeija_microcontroller_bottom.png^".. tiles = "jeija_microcontroller_bottom.png^"..
@ -152,7 +150,8 @@ for _, gate in ipairs(gates) do
node_box = node_box, node_box = node_box,
walkable = true, walkable = true,
on_construct = function(pos) on_construct = function(pos)
local meta = minetest.get_meta(pos) local meta = minetest.env:get_meta(pos)
meta:set_int("heat", 0)
update_gate(pos) update_gate(pos)
end, end,
groups = groups, groups = groups,
@ -220,3 +219,4 @@ minetest.register_craft({
{'mesecons:mesecon', '', ''}, {'mesecons:mesecon', '', ''},
}, },
}) })

View File

@ -63,8 +63,8 @@ nodenames = {"mesecons_hydroturbine:hydro_turbine_off"},
chance = 1, chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider) action = function(pos, node, active_object_count, active_object_count_wider)
local waterpos={x=pos.x, y=pos.y+1, z=pos.z} local waterpos={x=pos.x, y=pos.y+1, z=pos.z}
if minetest.get_node(waterpos).name=="default:water_flowing" then if minetest.env:get_node(waterpos).name=="default:water_flowing" then
minetest.add_node(pos, {name="mesecons_hydroturbine:hydro_turbine_on"}) minetest.env:add_node(pos, {name="mesecons_hydroturbine:hydro_turbine_on"})
nodeupdate(pos) nodeupdate(pos)
mesecon:receptor_on(pos) mesecon:receptor_on(pos)
end end
@ -77,8 +77,8 @@ nodenames = {"mesecons_hydroturbine:hydro_turbine_on"},
chance = 1, chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider) action = function(pos, node, active_object_count, active_object_count_wider)
local waterpos={x=pos.x, y=pos.y+1, z=pos.z} local waterpos={x=pos.x, y=pos.y+1, z=pos.z}
if minetest.get_node(waterpos).name~="default:water_flowing" then if minetest.env:get_node(waterpos).name~="default:water_flowing" then
minetest.add_node(pos, {name="mesecons_hydroturbine:hydro_turbine_off"}) minetest.env:add_node(pos, {name="mesecons_hydroturbine:hydro_turbine_off"})
nodeupdate(pos) nodeupdate(pos)
mesecon:receptor_off(pos) mesecon:receptor_off(pos)
end end

Binary file not shown.

Before

Width:  |  Height:  |  Size: 305 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 270 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 293 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 209 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 246 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 252 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 238 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 261 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 142 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 126 B

View File

@ -25,7 +25,7 @@ minetest.register_node("mesecons_lamp:lamp_on", {
sounds = default.node_sound_glass_defaults(), sounds = default.node_sound_glass_defaults(),
mesecons = {effector = { mesecons = {effector = {
action_off = function (pos, node) action_off = function (pos, node)
minetest.swap_node(pos, {name = "mesecons_lamp:lamp_off", param2 = node.param2}) mesecon:swap_node(pos, "mesecons_lamp:lamp_off")
end end
}} }}
}) })
@ -46,7 +46,7 @@ minetest.register_node("mesecons_lamp:lamp_off", {
sounds = default.node_sound_glass_defaults(), sounds = default.node_sound_glass_defaults(),
mesecons = {effector = { mesecons = {effector = {
action_on = function (pos, node) action_on = function (pos, node)
minetest.swap_node(pos, {name = "mesecons_lamp:lamp_on", param2 = node.param2}) mesecon:swap_node(pos, "mesecons_lamp:lamp_on")
end end
}} }}
}) })

View File

@ -1,19 +1,3 @@
local lightstone_rules = {
{x=0, y=0, z=-1},
{x=1, y=0, z=0},
{x=-1, y=0, z=0},
{x=0, y=0, z=1},
{x=1, y=1, z=0},
{x=1, y=-1, z=0},
{x=-1, y=1, z=0},
{x=-1, y=-1, z=0},
{x=0, y=1, z=1},
{x=0, y=-1, z=1},
{x=0, y=1, z=-1},
{x=0, y=-1, z=-1},
{x=0, y=-1, z=0},
}
function mesecon:lightstone_add(name, base_item, texture_off, texture_on) function mesecon:lightstone_add(name, base_item, texture_off, texture_on)
minetest.register_node("mesecons_lightstone:lightstone_" .. name .. "_off", { minetest.register_node("mesecons_lightstone:lightstone_" .. name .. "_off", {
tiles = {texture_off}, tiles = {texture_off},
@ -21,10 +5,9 @@ function mesecon:lightstone_add(name, base_item, texture_off, texture_on)
description=name.." Lightstone", description=name.." Lightstone",
sounds = default.node_sound_stone_defaults(), sounds = default.node_sound_stone_defaults(),
mesecons = {effector = { mesecons = {effector = {
rules = lightstone_rules,
action_on = function (pos, node) action_on = function (pos, node)
minetest.swap_node(pos, {name = "mesecons_lightstone:lightstone_" .. name .. "_on", param2 = node.param2}) mesecon:swap_node(pos, "mesecons_lightstone:lightstone_" .. name .. "_on")
end, end
}} }}
}) })
minetest.register_node("mesecons_lightstone:lightstone_" .. name .. "_on", { minetest.register_node("mesecons_lightstone:lightstone_" .. name .. "_on", {
@ -34,10 +17,9 @@ function mesecon:lightstone_add(name, base_item, texture_off, texture_on)
light_source = LIGHT_MAX-2, light_source = LIGHT_MAX-2,
sounds = default.node_sound_stone_defaults(), sounds = default.node_sound_stone_defaults(),
mesecons = {effector = { mesecons = {effector = {
rules = lightstone_rules,
action_off = function (pos, node) action_off = function (pos, node)
minetest.swap_node(pos, {name = "mesecons_lightstone:lightstone_" .. name .. "_off", param2 = node.param2}) mesecon:swap_node(pos, "mesecons_lightstone:lightstone_" .. name .. "_off")
end, end
}} }}
}) })

View File

@ -31,46 +31,18 @@ rules.d = {x = 0, y = 0, z = -1, name="D"}
------------------ ------------------
-- These helpers are required to set the portstates of the luacontroller -- These helpers are required to set the portstates of the luacontroller
function lc_update_real_portstates(pos, rulename, newstate)
local meta = minetest.get_meta(pos)
if rulename == nil then
meta:set_int("real_portstates", 1)
return
end
local n = meta:get_int("real_portstates") - 1
if n < 0 then
legacy_update_ports(pos)
n = meta:get_int("real_portstates") - 1
end
local L = {}
for i = 1, 4 do
L[i] = n%2
n = math.floor(n/2)
end
if rulename.x == nil then
for _, rname in ipairs(rulename) do
local port = ({4, 1, nil, 3, 2})[rname.x+2*rname.z+3]
L[port] = (newstate == "on") and 1 or 0
end
else
local port = ({4, 1, nil, 3, 2})[rulename.x+2*rulename.z+3]
L[port] = (newstate == "on") and 1 or 0
end
meta:set_int("real_portstates", 1 + L[1] + 2*L[2] + 4*L[3] + 8*L[4])
end
local get_real_portstates = function(pos) -- determine if ports are powered (by itself or from outside) local get_real_portstates = function(pos) -- determine if ports are powered (by itself or from outside)
local meta = minetest.get_meta(pos) ports = {
local L = {} a = mesecon:is_power_on(mesecon:addPosRule(pos, rules.a))
local n = meta:get_int("real_portstates") - 1 and mesecon:rules_link(mesecon:addPosRule(pos, rules.a), pos),
if n < 0 then b = mesecon:is_power_on(mesecon:addPosRule(pos, rules.b))
return legacy_update_ports(pos) and mesecon:rules_link(mesecon:addPosRule(pos, rules.b), pos),
end c = mesecon:is_power_on(mesecon:addPosRule(pos, rules.c))
for _, index in ipairs({"a", "b", "c", "d"}) do and mesecon:rules_link(mesecon:addPosRule(pos, rules.c), pos),
L[index] = ((n%2) == 1) d = mesecon:is_power_on(mesecon:addPosRule(pos, rules.d))
n = math.floor(n/2) and mesecon:rules_link(mesecon:addPosRule(pos, rules.d), pos),
end }
return L return ports
end end
local merge_portstates = function (ports, vports) local merge_portstates = function (ports, vports)
@ -100,8 +72,7 @@ local setport = function (pos, rule, state)
end end
local action = function (pos, ports) local action = function (pos, ports)
local node = minetest.get_node(pos) local name = minetest.env:get_node(pos).name
local name = node.name
local vports = minetest.registered_nodes[name].virtual_portstates local vports = minetest.registered_nodes[name].virtual_portstates
local newname = generate_name(ports) local newname = generate_name(ports)
@ -109,7 +80,7 @@ local action = function (pos, ports)
local rules_on = {} local rules_on = {}
local rules_off = {} local rules_off = {}
minetest.swap_node(pos, {name = newname, param2 = node.param2}) mesecon:swap_node(pos, newname)
if ports.a ~= vports.a then setport(pos, rules.a, ports.a) end if ports.a ~= vports.a then setport(pos, rules.a, ports.a) end
if ports.b ~= vports.b then setport(pos, rules.b, ports.b) end if ports.b ~= vports.b then setport(pos, rules.b, ports.b) end
@ -122,6 +93,30 @@ end
-- Overheat stuff -- -- Overheat stuff --
-------------------- --------------------
local heat = function (meta) -- warm up
h = meta:get_int("heat")
if h ~= nil then
meta:set_int("heat", h + 1)
end
end
local cool = function (meta) -- cool down after a while
h = meta:get_int("heat")
if h ~= nil then
meta:set_int("heat", h - 1)
end
end
local overheat = function (meta) -- determine if too hot
h = meta:get_int("heat")
if h == nil then return true end -- if nil then overheat
if h > 20 then
return true
else
return false
end
end
local overheat_off = function(pos) local overheat_off = function(pos)
mesecon:receptor_off(pos, mesecon.rules.flat) mesecon:receptor_off(pos, mesecon.rules.flat)
end end
@ -132,7 +127,7 @@ end
local code_prohibited = function(code) local code_prohibited = function(code)
-- Clean code -- Clean code
local prohibited = {"while", "for", "repeat", "until", "function", "goto"} local prohibited = {"while", "for", "repeat", "until", "function"}
for _, p in ipairs(prohibited) do for _, p in ipairs(prohibited) do
if string.find(code, p) then if string.find(code, p) then
return "Prohibited command: "..p return "Prohibited command: "..p
@ -140,67 +135,53 @@ local code_prohibited = function(code)
end end
end end
local safe_print = function(param) local safeprint = function(param)
print(dump(param)) print(dump(param))
end end
deep_copy = function(original, visited) --deep copy that removes functions local interrupt = function(params)
visited = visited or {} lc_update(params.pos, {type="interrupt", iid = params.iid})
if visited[original] ~= nil then --already visited this node
return visited[original]
end end
if type(original) == 'table' then --nested table
local copy = {}
visited[original] = copy
for key, value in next, original, nil do
copy[deep_copy(key, visited)] = deep_copy(value, visited)
end
setmetatable(copy, deep_copy(getmetatable(original), visited))
return copy
elseif type(original) == 'function' then --ignore functions
return nil
else --by-value type
return original
end
end
local safe_serialize = function(value)
return minetest.serialize(deep_copy(value))
end
mesecon.queue:add_function("lc_interrupt", function (pos, iid, luac_id)
-- There is no luacontroller anymore / it has been reprogrammed / replaced
if (minetest.get_meta(pos):get_int("luac_id") ~= luac_id) then return end
lc_update(pos, {type="interrupt", iid = iid})
end)
local getinterrupt = function(pos) local getinterrupt = function(pos)
local interrupt = function (time, iid) -- iid = interrupt id local interrupt = function (time, iid) -- iid = interrupt id
if type(time) ~= "number" then return end if type(time) ~= "number" then return end
luac_id = minetest.get_meta(pos):get_int("luac_id") local iid = iid or math.random()
mesecon.queue:add_action(pos, "lc_interrupt", {iid, luac_id}, time, iid, 1) local meta = minetest.env:get_meta(pos)
local interrupts = minetest.deserialize(meta:get_string("lc_interrupts")) or {}
local found = false
for _, i in ipairs(interrupts) do
if minetest.serialize(i) == minetest.serialize(iid) then
found = true
break
end
end
if not found then
table.insert(interrupts, iid)
meta:set_string("lc_interrupts", minetest.serialize(interrupts))
end
minetest.after(time, interrupt, {pos=pos, iid = iid})
end end
return interrupt return interrupt
end end
local getdigiline_send = function (pos) local getdigiline_send = function (pos)
if not digiline then return end local digiline_send = function (channel, msg)
-- Send messages on next serverstep if digiline then
return function(channel, msg)
minetest.after(0, function()
digiline:receptor_send(pos, digiline.rules.default, channel, msg) digiline:receptor_send(pos, digiline.rules.default, channel, msg)
end)
end end
end end
return digiline_send
end
local create_environment = function(pos, mem, event) local create_environment = function(pos, mem, event)
-- Gather variables for the environment -- Gather variables for the environment
local vports = minetest.registered_nodes[minetest.get_node(pos).name].virtual_portstates local vports = minetest.registered_nodes[minetest.env:get_node(pos).name].virtual_portstates
vports = {a = vports.a, b = vports.b, c = vports.c, d = vports.d} vports = {a = vports.a, b = vports.b, c = vports.c, d = vports.d}
local rports = get_real_portstates(pos) local rports = get_real_portstates(pos)
return { return {
print = safe_print, print = safeprint,
pin = merge_portstates(vports, rports), pin = merge_portstates(vports, rports),
port = vports, port = vports,
interrupt = getinterrupt(pos), interrupt = getinterrupt(pos),
@ -208,8 +189,6 @@ local create_environment = function(pos, mem, event)
mem = mem, mem = mem,
tostring = tostring, tostring = tostring,
tonumber = tonumber, tonumber = tonumber,
heat = minetest.get_meta(pos):get_int("heat"),
heat_max = OVERHEAT_MAX,
string = { string = {
byte = string.byte, byte = string.byte,
char = string.char, char = string.char,
@ -219,7 +198,6 @@ local create_environment = function(pos, mem, event)
gsub = string.gsub, gsub = string.gsub,
len = string.len, len = string.len,
lower = string.lower, lower = string.lower,
upper = string.upper,
match = string.match, match = string.match,
rep = string.rep, rep = string.rep,
reverse = string.reverse, reverse = string.reverse,
@ -277,10 +255,13 @@ local create_sandbox = function (code, env)
return f return f
end end
local lc_overheat = function (pos, meta) local do_overheat = function (pos, meta)
if mesecon.do_overheat(pos) then -- if too hot -- Overheat protection
local node = minetest.get_node(pos) heat(meta)
minetest.swap_node(pos, {name = BASENAME.."_burnt", param2 = node.param2}) minetest.after(0.5, cool, meta)
if overheat(meta) then
mesecon:swap_node(pos, BASENAME.."_burnt")
minetest.env:get_meta(pos):set_string("lc_interrupts", "")
minetest.after(0.2, overheat_off, pos) -- wait for pending operations minetest.after(0.2, overheat_off, pos) -- wait for pending operations
return true return true
end end
@ -291,7 +272,20 @@ local load_memory = function(meta)
end end
local save_memory = function(meta, mem) local save_memory = function(meta, mem)
meta:set_string("lc_memory", safe_serialize(mem)) meta:set_string("lc_memory", minetest.serialize(mem))
end
local interrupt_allow = function (meta, event)
if event.type ~= "interrupt" then return true end
local interrupts = minetest.deserialize(meta:get_string("lc_interrupts")) or {}
for _, i in ipairs(interrupts) do
if minetest.serialize(i) == minetest.serialize(event.iid) then
return true
end
end
return false
end end
local ports_invalid = function (var) local ports_invalid = function (var)
@ -306,8 +300,9 @@ end
---------------------- ----------------------
lc_update = function (pos, event) lc_update = function (pos, event)
local meta = minetest.get_meta(pos) local meta = minetest.env:get_meta(pos)
if lc_overheat(pos) then return end if not interrupt_allow(meta, event) then return end
if do_overheat(pos, meta) then return end
-- load code & mem from memory -- load code & mem from memory
local mem = load_memory(meta) local mem = load_memory(meta)
@ -328,14 +323,21 @@ lc_update = function (pos, event)
save_memory(meta, mem) save_memory(meta, mem)
-- Actually set the ports -- Actually set the ports
action(pos, env.port) minetest.after(0, action, pos, env.port)
end end
local reset_meta = function(pos, code, errmsg) local reset_meta = function(pos, code, errmsg)
local meta = minetest.get_meta(pos) local meta = minetest.env:get_meta(pos)
meta:set_string("code", code) meta:set_string("code", code)
if minetest.formspec_escape then
code = minetest.formspec_escape(code or "") code = minetest.formspec_escape(code or "")
errmsg = minetest.formspec_escape(errmsg or "") errmsg = minetest.formspec_escape(errmsg or "")
else
code = string.gsub(code or "", "%[", "(") -- would otherwise
code = string.gsub(code, "%]", ")") -- corrupt formspec
errmsg = string.gsub(errmsg or "", "%[", "(") -- would otherwise
errmsg = string.gsub(errmsg, "%]", ")") -- corrupt formspec
end
meta:set_string("formspec", "size[10,8]".. meta:set_string("formspec", "size[10,8]"..
"background[-0.2,-0.25;10.4,8.75;jeija_luac_background.png]".. "background[-0.2,-0.25;10.4,8.75;jeija_luac_background.png]"..
"textarea[0.2,0.6;10.2,5;code;;"..code.."]".. "textarea[0.2,0.6;10.2,5;code;;"..code.."]"..
@ -343,21 +345,19 @@ local reset_meta = function(pos, code, errmsg)
"image_button_exit[9.72,-0.25;0.425,0.4;jeija_close_window.png;exit;]".. "image_button_exit[9.72,-0.25;0.425,0.4;jeija_close_window.png;exit;]"..
"label[0.1,5;"..errmsg.."]") "label[0.1,5;"..errmsg.."]")
meta:set_int("heat", 0) meta:set_int("heat", 0)
meta:set_int("luac_id", math.random(1, 1000000))
end end
local reset = function (pos) local reset = function (pos)
action(pos, {a=false, b=false, c=false, d=false}) minetest.env:get_meta(pos):set_string("lc_interrupts", "")
action(pos, {a=false, b=false, c=false, d=false}, true)
end end
-- ______ -- ______
-- | -- |
-- | -- | | |
-- | __ ___ _ __ _ _ -- |___| | __ ___ _ __ _ _
-- | | | | | |\ | | |_| | | | | |_ |_| -- | | | | |\ | | |_| | | | | |_ |_|
-- |___| |______ |__| | \| | | \ |__| |_ |_ |_ |\ -- | |______ |__| | \| | | \ |__| |_ |_ |_ |\
-- |
-- |
-- --
----------------------- -----------------------
@ -412,9 +412,9 @@ if d == 1 then
end end
if a + b + c + d ~= 0 then if a + b + c + d ~= 0 then
groups = {dig_immediate=2, not_in_creative_inventory=1, overheat = 1} groups = {dig_immediate=2, not_in_creative_inventory=1}
else else
groups = {dig_immediate=2, overheat = 1} groups = {dig_immediate=2}
end end
output_rules[cid] = {} output_rules[cid] = {}
@ -434,7 +434,6 @@ local mesecons = {
{ {
rules = input_rules[cid], rules = input_rules[cid],
action_change = function (pos, _, rulename, newstate) action_change = function (pos, _, rulename, newstate)
lc_update_real_portstates(pos, rulename, newstate)
lc_update(pos, {type=newstate, pin=rulename}) lc_update(pos, {type=newstate, pin=rulename})
end, end,
}, },
@ -466,21 +465,16 @@ minetest.register_node(nodename, {
node_box = nodebox, node_box = nodebox,
on_construct = reset_meta, on_construct = reset_meta,
on_receive_fields = function(pos, formname, fields) on_receive_fields = function(pos, formname, fields)
if not fields.program then
return
end
reset(pos) reset(pos)
reset_meta(pos, fields.code) reset_meta(pos, fields.code)
local err = lc_update(pos, {type="program"}) local err = lc_update(pos, {type="program"})
if err then if err then print(err) end
print(err)
reset_meta(pos, fields.code, err) reset_meta(pos, fields.code, err)
end
end, end,
on_timer = handle_timer,
sounds = default.node_sound_stone_defaults(), sounds = default.node_sound_stone_defaults(),
mesecons = mesecons, mesecons = mesecons,
digiline = digiline, digiline = digiline,
is_luacontroller = true,
virtual_portstates = { a = a == 1, -- virtual portstates are virtual_portstates = { a = a == 1, -- virtual portstates are
b = b == 1, -- the ports the the b = b == 1, -- the ports the the
c = c == 1, -- controller powers itself c = c == 1, -- controller powers itself
@ -488,28 +482,13 @@ minetest.register_node(nodename, {
after_dig_node = function (pos, node) after_dig_node = function (pos, node)
mesecon:receptor_off(pos, output_rules) mesecon:receptor_off(pos, output_rules)
end, end,
is_luacontroller = true,
}) })
end end
end end
end end
end end
------------------------------ --overheated luacontroller
-- overheated luacontroller --
------------------------------
local mesecons_burnt = {
effector =
{
rules = mesecon.rules.flat,
action_change = function (pos, _, rulename, newstate)
-- only update portstates when changes are triggered
lc_update_real_portstates(pos, rulename, newstate)
end
}
}
minetest.register_node(BASENAME .. "_burnt", { minetest.register_node(BASENAME .. "_burnt", {
drawtype = "nodebox", drawtype = "nodebox",
tiles = { tiles = {
@ -529,20 +508,15 @@ minetest.register_node(BASENAME .. "_burnt", {
node_box = nodebox, node_box = nodebox,
on_construct = reset_meta, on_construct = reset_meta,
on_receive_fields = function(pos, formname, fields) on_receive_fields = function(pos, formname, fields)
if fields.quit then
return
end
reset(pos) reset(pos)
reset_meta(pos, fields.code) reset_meta(pos, fields.code)
local err = lc_update(pos, {type="program"}) local err = lc_update(pos, {type="program"})
if err then if err then print(err) end
print(err)
reset_meta(pos, fields.code, err) reset_meta(pos, fields.code, err)
end
end, end,
sounds = default.node_sound_stone_defaults(), sounds = default.node_sound_stone_defaults(),
is_luacontroller = true,
virtual_portstates = {a = false, b = false, c = false, d = false}, virtual_portstates = {a = false, b = false, c = false, d = false},
mesecons = mesecons_burnt,
}) })
------------------------ ------------------------

View File

@ -19,9 +19,9 @@ if tostring(d) == "1" then
top = top.."^jeija_microcontroller_LED_D.png" top = top.."^jeija_microcontroller_LED_D.png"
end end
if tostring(d)..tostring(c)..tostring(b)..tostring(a) ~= "0000" then if tostring(d)..tostring(c)..tostring(b)..tostring(a) ~= "0000" then
groups = {dig_immediate=2, not_in_creative_inventory=1, mesecon = 3, overheat = 1} groups = {dig_immediate=2, not_in_creative_inventory=1, mesecon = 3}
else else
groups = {dig_immediate=2, mesecon = 3, overheat = 1} groups = {dig_immediate=2, mesecon = 3}
end end
local rules={} local rules={}
if (a == 1) then table.insert(rules, {x = -1, y = 0, z = 0}) end if (a == 1) then table.insert(rules, {x = -1, y = 0, z = 0}) end
@ -39,8 +39,7 @@ mesecon:add_rules(nodename, rules)
local mesecons = {effector = local mesecons = {effector =
{ {
rules = input_rules, rules = input_rules,
action_change = function (pos, node, rulename, newstate) action_change = function (pos, node, rulename)
yc_update_real_portstates(pos, node, rulename, newstate)
update_yc(pos) update_yc(pos)
end end
}} }}
@ -81,7 +80,7 @@ minetest.register_node(nodename, {
} }
}, },
on_construct = function(pos) on_construct = function(pos)
local meta = minetest.get_meta(pos) local meta = minetest.env:get_meta(pos)
meta:set_string("code", "") meta:set_string("code", "")
meta:set_string("formspec", "size[9,2.5]".. meta:set_string("formspec", "size[9,2.5]"..
"field[0.256,-0.2;9,2;code;Code:;]".. "field[0.256,-0.2;9,2;code;Code:;]"..
@ -93,12 +92,13 @@ minetest.register_node(nodename, {
"button[7.5,0.2;1.5,3;brsflop;RS-Flop]".. "button[7.5,0.2;1.5,3;brsflop;RS-Flop]"..
"button_exit[3.5,1;2,3;program;Program]") "button_exit[3.5,1;2,3;program;Program]")
meta:set_string("infotext", "Unprogrammed Microcontroller") meta:set_string("infotext", "Unprogrammed Microcontroller")
meta:set_int("heat", 0)
local r = "" local r = ""
for i=1, EEPROM_SIZE+1 do r=r.."0" end --Generate a string with EEPROM_SIZE*"0" for i=1, EEPROM_SIZE+1 do r=r.."0" end --Generate a string with EEPROM_SIZE*"0"
meta:set_string("eeprom", r) meta:set_string("eeprom", r)
end, end,
on_receive_fields = function(pos, formanme, fields, sender) on_receive_fields = function(pos, formanme, fields, sender)
local meta = minetest.get_meta(pos) local meta = minetest.env:get_meta(pos)
if fields.band then if fields.band then
fields.code = "sbi(C, A&B) :A and B are inputs, C is output" fields.code = "sbi(C, A&B) :A and B are inputs, C is output"
elseif fields.bxor then elseif fields.bxor then
@ -111,12 +111,12 @@ minetest.register_node(nodename, {
fields.code = "if(A)sbi(1,1);if(!A&#1)sbi(B,!B)sbi(1,0); if(C)off(B,1); :A is input, B is output (Q), C is reset, toggles with falling edge" fields.code = "if(A)sbi(1,1);if(!A&#1)sbi(B,!B)sbi(1,0); if(C)off(B,1); :A is input, B is output (Q), C is reset, toggles with falling edge"
elseif fields.brsflop then elseif fields.brsflop then
fields.code = "if(A)on(C);if(B)off(C); :A is S (Set), B is R (Reset), C is output (R dominates)" fields.code = "if(A)on(C);if(B)off(C); :A is S (Set), B is R (Reset), C is output (R dominates)"
end elseif fields.program or fields.code then --nothing
if fields.code == nil then return end else return nil end
meta:set_string("code", fields.code) meta:set_string("code", fields.code)
meta:set_string("formspec", "size[9,2.5]".. meta:set_string("formspec", "size[9,2.5]"..
"field[0.256,-0.2;9,2;code;Code:;"..minetest.formspec_escape(fields.code).."]".. "field[0.256,-0.2;9,2;code;Code:;"..fields.code.."]"..
"button[0 ,0.2;1.5,3;band;AND]".. "button[0 ,0.2;1.5,3;band;AND]"..
"button[1.5,0.2;1.5,3;bxor;XOR]".. "button[1.5,0.2;1.5,3;bxor;XOR]"..
"button[3 ,0.2;1.5,3;bnot;NOT]".. "button[3 ,0.2;1.5,3;bnot;NOT]"..
@ -151,7 +151,8 @@ minetest.register_craft({
function yc_reset(pos) function yc_reset(pos)
yc_action(pos, {a=false, b=false, c=false, d=false}) yc_action(pos, {a=false, b=false, c=false, d=false})
local meta = minetest.get_meta(pos) local meta = minetest.env:get_meta(pos)
meta:set_int("heat", 0)
meta:set_int("afterid", 0) meta:set_int("afterid", 0)
local r = "" local r = ""
for i=1, EEPROM_SIZE+1 do r=r.."0" end --Generate a string with EEPROM_SIZE*"0" for i=1, EEPROM_SIZE+1 do r=r.."0" end --Generate a string with EEPROM_SIZE*"0"
@ -159,14 +160,13 @@ function yc_reset(pos)
end end
function update_yc(pos) function update_yc(pos)
local meta = minetest.get_meta(pos) local meta = minetest.env:get_meta(pos)
yc_heat(meta)
if (mesecon.do_overheat(pos)) then minetest.after(0.5, yc_cool, meta)
minetest.remove_node(pos) if (yc_overheat(meta)) then
minetest.after(0.2, function (pos) minetest.env:remove_node(pos)
mesecon:receptor_off(pos, mesecon.rules.flat) minetest.after(0.2, yc_overheat_off, pos) --wait for pending parsings
end , pos) -- wait for pending parsings minetest.env:add_item(pos, "mesecons_microcontroller:microcontroller0000")
minetest.add_item(pos, "mesecons_microcontroller:microcontroller0000")
end end
local code = meta:get_string("code") local code = meta:get_string("code")
@ -195,7 +195,7 @@ function yc_code_remove_commentary(code)
end end
function yc_parsecode(code, pos) function yc_parsecode(code, pos)
local meta = minetest.get_meta(pos) local meta = minetest.env:get_meta(pos)
local endi = 1 local endi = 1
local Lreal = yc_get_real_portstates(pos) local Lreal = yc_get_real_portstates(pos)
local Lvirtual = yc_get_virtual_portstates(pos) local Lvirtual = yc_get_virtual_portstates(pos)
@ -243,7 +243,7 @@ function yc_parsecode(code, pos)
end end
if Lvirtual == nil then return nil end if Lvirtual == nil then return nil end
if eeprom == nil then return nil else if eeprom == nil then return nil else
minetest.get_meta(pos):set_string("eeprom", eeprom) end minetest.env:get_meta(pos):set_string("eeprom", eeprom) end
end end
yc_action(pos, Lvirtual) yc_action(pos, Lvirtual)
return true return true
@ -429,14 +429,14 @@ function yc_command_after(params, pos)
local code = string.sub(params[2], 2, #params[2] - 1) local code = string.sub(params[2], 2, #params[2] - 1)
local afterid = math.random(10000) local afterid = math.random(10000)
local meta = minetest.get_meta(pos) local meta = minetest.env:get_meta(pos)
meta:set_int("afterid", afterid) meta:set_int("afterid", afterid)
minetest.after(time, yc_command_after_execute, {pos = pos, code = code, afterid = afterid}) minetest.after(time, yc_command_after_execute, {pos = pos, code = code, afterid = afterid})
return true return true
end end
function yc_command_after_execute(params) function yc_command_after_execute(params)
local meta = minetest.get_meta(params.pos) local meta = minetest.env:get_meta(params.pos)
if meta:get_int("afterid") == params.afterid then --make sure the node has not been changed if meta:get_int("afterid") == params.afterid then --make sure the node has not been changed
if yc_parsecode(params.code, params.pos) == nil then if yc_parsecode(params.code, params.pos) == nil then
meta:set_string("infotext", "Code in after() not valid!") meta:set_string("infotext", "Code in after() not valid!")
@ -590,8 +590,7 @@ function yc_action(pos, L) --L-->Lvirtual
..tonumber(L.c and 1 or 0) ..tonumber(L.c and 1 or 0)
..tonumber(L.b and 1 or 0) ..tonumber(L.b and 1 or 0)
..tonumber(L.a and 1 or 0) ..tonumber(L.a and 1 or 0)
local node = minetest.get_node(pos) mesecon:swap_node(pos, name)
minetest.swap_node(pos, {name = name, param2 = node.param2})
yc_action_setports(pos, L, Lv) yc_action_setports(pos, L, Lv)
end end
@ -630,50 +629,22 @@ function yc_set_portstate(port, state, L)
return L return L
end end
function yc_update_real_portstates(pos, node, rulename, newstate) function yc_get_real_portstates(pos) -- port powered or not (by itself or from outside)?
local meta = minetest.get_meta(pos) rulesA = mesecon:get_rules("mesecons_microcontroller:microcontroller0001")
if rulename == nil then rulesB = mesecon:get_rules("mesecons_microcontroller:microcontroller0010")
meta:set_int("real_portstates", 1) rulesC = mesecon:get_rules("mesecons_microcontroller:microcontroller0100")
return rulesD = mesecon:get_rules("mesecons_microcontroller:microcontroller1000")
end L = {
local n = meta:get_int("real_portstates") - 1 a = mesecon:is_power_on({x=pos.x+rulesA[1].x, y=pos.y+rulesA[1].y, z=pos.z+rulesA[1].z}) and mesecon:rules_link({x=pos.x+rulesA[1].x, y=pos.y+rulesA[1].y, z=pos.z+rulesA[1].z}, pos),
if n < 0 then b = mesecon:is_power_on({x=pos.x+rulesB[1].x, y=pos.y+rulesB[1].y, z=pos.z+rulesB[1].z}) and mesecon:rules_link({x=pos.x+rulesB[1].x, y=pos.y+rulesB[1].y, z=pos.z+rulesB[1].z}, pos),
legacy_update_ports(pos) c = mesecon:is_power_on({x=pos.x+rulesC[1].x, y=pos.y+rulesC[1].y, z=pos.z+rulesC[1].z}) and mesecon:rules_link({x=pos.x+rulesC[1].x, y=pos.y+rulesC[1].y, z=pos.z+rulesC[1].z}, pos),
n = meta:get_int("real_portstates") - 1 d = mesecon:is_power_on({x=pos.x+rulesD[1].x, y=pos.y+rulesD[1].y, z=pos.z+rulesD[1].z}) and mesecon:rules_link({x=pos.x+rulesD[1].x, y=pos.y+rulesD[1].y, z=pos.z+rulesD[1].z}, pos)
end }
local L = {}
for i = 1, 4 do
L[i] = n%2
n = math.floor(n/2)
end
if rulename.x == nil then
for _, rname in ipairs(rulename) do
local port = ({4, 1, nil, 3, 2})[rname.x+2*rname.z+3]
L[port] = (newstate == "on") and 1 or 0
end
else
local port = ({4, 1, nil, 3, 2})[rulename.x+2*rulename.z+3]
L[port] = (newstate == "on") and 1 or 0
end
meta:set_int("real_portstates", 1 + L[1] + 2*L[2] + 4*L[3] + 8*L[4])
end
function yc_get_real_portstates(pos) -- determine if ports are powered (by itself or from outside)
local meta = minetest.get_meta(pos)
local L = {}
local n = meta:get_int("real_portstates") - 1
if n < 0 then
return legacy_update_ports(pos)
end
for _, index in ipairs({"a", "b", "c", "d"}) do
L[index] = ((n%2) == 1)
n = math.floor(n/2)
end
return L return L
end end
function yc_get_virtual_portstates(pos) -- portstates according to the name function yc_get_virtual_portstates(pos) -- portstates according to the name
name = minetest.get_node(pos).name name = minetest.env:get_node(pos).name
b, a = string.find(name, ":microcontroller") b, a = string.find(name, ":microcontroller")
if a == nil then return nil end if a == nil then return nil end
a = a + 1 a = a + 1
@ -694,3 +665,33 @@ function yc_merge_portstates(Lreal, Lvirtual)
if Lvirtual.d or Lreal.d then L.d = true end if Lvirtual.d or Lreal.d then L.d = true end
return L return L
end end
--"Overheat" protection
function yc_heat(meta)
h = meta:get_int("heat")
if h ~= nil then
meta:set_int("heat", h + 1)
end
end
function yc_cool(meta)
h = meta:get_int("heat")
if h ~= nil then
meta:set_int("heat", h - 1)
end
end
function yc_overheat(meta)
h = meta:get_int("heat")
if h == nil then return true end -- if nil the overheat
if h>30 then
return true
else
return false
end
end
function yc_overheat_off(pos)
rules = mesecon:get_rules("mesecons_microcontroller:microcontroller1111")
mesecon:receptor_off(pos, rules)
end

View File

@ -66,9 +66,9 @@ minetest.register_node("mesecons_movestones:movestone", {
action_on = function (pos, node) action_on = function (pos, node)
local direction=mesecon:get_movestone_direction(pos) local direction=mesecon:get_movestone_direction(pos)
if not direction then return end if not direction then return end
minetest.remove_node(pos) minetest.env:remove_node(pos)
mesecon:update_autoconnect(pos) mesecon:update_autoconnect(pos)
minetest.add_entity(pos, "mesecons_movestones:movestone_entity") minetest.env:add_entity(pos, "mesecons_movestones:movestone_entity")
end end
}} }}
}) })
@ -92,14 +92,12 @@ minetest.register_entity("mesecons_movestones:movestone_entity", {
local direction = mesecon:get_movestone_direction(pos) local direction = mesecon:get_movestone_direction(pos)
if not direction then -- no mesecon power if not direction then -- no mesecon power
--push only solid nodes local name = minetest.env:get_node(pos).name
local name = minetest.get_node(pos).name
if name ~= "air" and name ~= "ignore" if name ~= "air" and name ~= "ignore"
and ((not minetest.registered_nodes[name]) and minetest.registered_nodes[name].liquidtype == "none" then
or minetest.registered_nodes[name].liquidtype == "none") then
mesecon:mvps_push(pos, self.lastdir, MOVESTONE_MAXIMUM_PUSH) mesecon:mvps_push(pos, self.lastdir, MOVESTONE_MAXIMUM_PUSH)
end end
minetest.add_node(pos, {name="mesecons_movestones:movestone"}) minetest.env:add_node(pos, {name="mesecons_movestones:movestone"})
self.object:remove() self.object:remove()
return return
end end
@ -107,7 +105,7 @@ minetest.register_entity("mesecons_movestones:movestone_entity", {
local success, stack, oldstack = local success, stack, oldstack =
mesecon:mvps_push(pos, direction, MOVESTONE_MAXIMUM_PUSH) mesecon:mvps_push(pos, direction, MOVESTONE_MAXIMUM_PUSH)
if not success then -- Too large stack/stopper in the way if not success then -- Too large stack/stopper in the way
minetest.add_node(pos, {name="mesecons_movestones:movestone"}) minetest.env:add_node(pos, {name="mesecons_movestones:movestone"})
self.object:remove() self.object:remove()
return return
else else
@ -145,9 +143,9 @@ minetest.register_node("mesecons_movestones:sticky_movestone", {
action_on = function (pos, node) action_on = function (pos, node)
local direction=mesecon:get_movestone_direction(pos) local direction=mesecon:get_movestone_direction(pos)
if not direction then return end if not direction then return end
minetest.remove_node(pos) minetest.env:remove_node(pos)
mesecon:update_autoconnect(pos) mesecon:update_autoconnect(pos)
minetest.add_entity(pos, "mesecons_movestones:sticky_movestone_entity") minetest.env:add_entity(pos, "mesecons_movestones:sticky_movestone_entity")
end end
}} }}
}) })
@ -178,16 +176,14 @@ minetest.register_entity("mesecons_movestones:sticky_movestone_entity", {
local direction = mesecon:get_movestone_direction(pos) local direction = mesecon:get_movestone_direction(pos)
if not direction then -- no mesecon power if not direction then -- no mesecon power
--push only solid nodes local name = minetest.env:get_node(pos).name
local name = minetest.get_node(pos).name
if name ~= "air" and name ~= "ignore" if name ~= "air" and name ~= "ignore"
and ((not minetest.registered_nodes[name]) and minetest.registered_nodes[name].liquidtype == "none" then
or minetest.registered_nodes[name].liquidtype == "none") then
mesecon:mvps_push(pos, self.lastdir, MOVESTONE_MAXIMUM_PUSH) mesecon:mvps_push(pos, self.lastdir, MOVESTONE_MAXIMUM_PUSH)
--STICKY --STICKY
mesecon:mvps_pull_all(pos, self.lastdir) mesecon:mvps_pull_all(pos, self.lastdir)
end end
minetest.add_node(pos, {name="mesecons_movestones:sticky_movestone"}) minetest.env:add_node(pos, {name="mesecons_movestones:sticky_movestone"})
self.object:remove() self.object:remove()
return return
end end
@ -195,7 +191,7 @@ minetest.register_entity("mesecons_movestones:sticky_movestone_entity", {
local success, stack, oldstack = local success, stack, oldstack =
mesecon:mvps_push(pos, direction, MOVESTONE_MAXIMUM_PUSH) mesecon:mvps_push(pos, direction, MOVESTONE_MAXIMUM_PUSH)
if not success then -- Too large stack/stopper in the way if not success then -- Too large stack/stopper in the way
minetest.add_node(pos, {name="mesecons_movestones:sticky_movestone"}) minetest.env:add_node(pos, {name="mesecons_movestones:sticky_movestone"})
self.object:remove() self.object:remove()
return return
else else

View File

@ -2,7 +2,6 @@
mesecon.mvps_stoppers = {} mesecon.mvps_stoppers = {}
mesecon.mvps_unmov = {} mesecon.mvps_unmov = {}
mesecon.on_mvps_move = {}
function mesecon:is_mvps_stopper(node, pushdir, stack, stackid) function mesecon:is_mvps_stopper(node, pushdir, stack, stackid)
local get_stopper = mesecon.mvps_stoppers[node.name] local get_stopper = mesecon.mvps_stoppers[node.name]
@ -28,22 +27,11 @@ function mesecon:is_mvps_unmov(objectname)
return mesecon.mvps_unmov[objectname] return mesecon.mvps_unmov[objectname]
end end
-- Functions to be called on mvps movement
function mesecon:register_on_mvps_move(callback)
mesecon.on_mvps_move[#mesecon.on_mvps_move+1] = callback
end
local function on_mvps_move(moved_nodes)
for _, callback in ipairs(mesecon.on_mvps_move) do
callback(moved_nodes)
end
end
function mesecon:mvps_process_stack(stack) function mesecon:mvps_process_stack(stack)
-- update mesecons for placed nodes ( has to be done after all nodes have been added ) -- update mesecons for placed nodes ( has to be done after all nodes have been added )
for _, n in ipairs(stack) do for _, n in ipairs(stack) do
nodeupdate(n.pos) nodeupdate(n.pos)
mesecon.on_placenode(n.pos, minetest.get_node(n.pos)) mesecon.on_placenode(n.pos, minetest.env:get_node(n.pos))
mesecon:update_autoconnect(n.pos) mesecon:update_autoconnect(n.pos)
end end
end end
@ -53,15 +41,14 @@ function mesecon:mvps_get_stack(pos, dir, maximum)
local np = {x = pos.x, y = pos.y, z = pos.z} local np = {x = pos.x, y = pos.y, z = pos.z}
local nodes = {} local nodes = {}
while true do while true do
local nn = minetest.get_node_or_nil(np) local nn = minetest.env:get_node_or_nil(np)
if not nn or #nodes > maximum then if not nn or #nodes > maximum then
-- don't push at all, something is in the way (unloaded map or too many nodes) -- don't push at all, something is in the way (unloaded map or too many nodes)
return nil return nil
end end
if nn.name == "air" if nn.name == "air"
or (minetest.registered_nodes[nn.name] or minetest.registered_nodes[nn.name].liquidtype ~= "none" then --is liquid
and minetest.registered_nodes[nn.name].liquidtype ~= "none") then --is liquid
break break
end end
@ -85,8 +72,8 @@ function mesecon:mvps_push(pos, dir, maximum) -- pos: pos of mvps; dir: directio
-- remove all nodes -- remove all nodes
for _, n in ipairs(nodes) do for _, n in ipairs(nodes) do
n.meta = minetest.get_meta(n.pos):to_table() n.meta = minetest.env:get_meta(n.pos):to_table()
minetest.remove_node(n.pos) minetest.env:remove_node(n.pos)
end end
-- update mesecons for removed nodes ( has to be done after all nodes have been removed ) -- update mesecons for removed nodes ( has to be done after all nodes have been removed )
@ -98,98 +85,58 @@ function mesecon:mvps_push(pos, dir, maximum) -- pos: pos of mvps; dir: directio
-- add nodes -- add nodes
for _, n in ipairs(nodes) do for _, n in ipairs(nodes) do
np = mesecon:addPosRule(n.pos, dir) np = mesecon:addPosRule(n.pos, dir)
minetest.add_node(np, n.node) minetest.env:add_node(np, n.node)
minetest.get_meta(np):from_table(n.meta) minetest.env:get_meta(np):from_table(n.meta)
end end
local moved_nodes = {}
local oldstack = mesecon:tablecopy(nodes) local oldstack = mesecon:tablecopy(nodes)
for i in ipairs(nodes) do for i in ipairs(nodes) do
moved_nodes[i] = {}
moved_nodes[i].oldpos = nodes[i].pos
nodes[i].pos = mesecon:addPosRule(nodes[i].pos, dir) nodes[i].pos = mesecon:addPosRule(nodes[i].pos, dir)
moved_nodes[i].pos = nodes[i].pos
moved_nodes[i].node = nodes[i].node
moved_nodes[i].meta = nodes[i].meta
end end
on_mvps_move(moved_nodes)
return true, nodes, oldstack return true, nodes, oldstack
end end
mesecon:register_on_mvps_move(function(moved_nodes)
for _, n in ipairs(moved_nodes) do
mesecon.on_placenode(n.pos, n.node)
mesecon:update_autoconnect(n.pos)
end
end)
function mesecon:mvps_pull_single(pos, dir) -- pos: pos of mvps; direction: direction of pull (matches push direction for sticky pistons) function mesecon:mvps_pull_single(pos, dir) -- pos: pos of mvps; direction: direction of pull (matches push direction for sticky pistons)
np = mesecon:addPosRule(pos, dir) np = mesecon:addPosRule(pos, dir)
nn = minetest.get_node(np) nn = minetest.env:get_node(np)
if ((not minetest.registered_nodes[nn.name]) --unregistered node if minetest.registered_nodes[nn.name].liquidtype == "none"
or minetest.registered_nodes[nn.name].liquidtype == "none") --non-liquid node and not mesecon:is_mvps_stopper(nn, {x = -dir.x, y = -dir.y, z = -dir.z}, {{pos = np, node = nn}}, 1) then
and not mesecon:is_mvps_stopper(nn, {x = -dir.x, y = -dir.y, z = -dir.z}, {{pos = np, node = nn}}, 1) then --non-stopper node local meta = minetest.env:get_meta(np):to_table()
local meta = minetest.get_meta(np):to_table() minetest.env:remove_node(np)
minetest.remove_node(np) minetest.env:add_node(pos, nn)
minetest.add_node(pos, nn) minetest.env:get_meta(pos):from_table(meta)
minetest.get_meta(pos):from_table(meta)
nodeupdate(np) nodeupdate(np)
nodeupdate(pos) nodeupdate(pos)
mesecon.on_dignode(np, nn) mesecon.on_dignode(np, nn)
mesecon:update_autoconnect(np) mesecon:update_autoconnect(np)
on_mvps_move({{pos = pos, oldpos = np, node = nn, meta = meta}})
end end
return {{pos = np, node = {param2 = 0, name = "air"}}, {pos = pos, node = nn}} return {{pos = np, node = {param2 = 0, name = "air"}}, {pos = pos, node = nn}}
end end
function mesecon:mvps_pull_all(pos, direction) -- pos: pos of mvps; direction: direction of pull function mesecon:mvps_pull_all(pos, direction) -- pos: pos of mvps; direction: direction of pull
local lpos = {x=pos.x-direction.x, y=pos.y-direction.y, z=pos.z-direction.z} -- 1 away local lpos = {x=pos.x-direction.x, y=pos.y-direction.y, z=pos.z-direction.z} -- 1 away
local lnode = minetest.get_node(lpos) local lnode = minetest.env:get_node(lpos)
local lpos2 = {x=pos.x-direction.x*2, y=pos.y-direction.y*2, z=pos.z-direction.z*2} -- 2 away local lpos2 = {x=pos.x-direction.x*2, y=pos.y-direction.y*2, z=pos.z-direction.z*2} -- 2 away
local lnode2 = minetest.get_node(lpos2) local lnode2 = minetest.env:get_node(lpos2)
--avoid pulling solid nodes if lnode.name ~= "ignore" and lnode.name ~= "air" and minetest.registered_nodes[lnode.name].liquidtype == "none" then return end
if lnode.name ~= "ignore" if lnode2.name == "ignore" or lnode2.name == "air" or not(minetest.registered_nodes[lnode2.name].liquidtype == "none") then return end
and lnode.name ~= "air"
and ((not minetest.registered_nodes[lnode.name])
or minetest.registered_nodes[lnode.name].liquidtype == "none") then
return
end
--avoid pulling empty or liquid nodes
if lnode2.name == "ignore"
or lnode2.name == "air"
or (minetest.registered_nodes[lnode2.name]
and minetest.registered_nodes[lnode2.name].liquidtype ~= "none") then
return
end
local moved_nodes = {}
local oldpos = {x=lpos2.x+direction.x, y=lpos2.y+direction.y, z=lpos2.z+direction.z} local oldpos = {x=lpos2.x+direction.x, y=lpos2.y+direction.y, z=lpos2.z+direction.z}
repeat repeat
lnode2 = minetest.get_node(lpos2) lnode2 = minetest.env:get_node(lpos2)
local meta = minetest.get_meta(lnode2):to_table() minetest.env:add_node(oldpos, {name=lnode2.name})
minetest.add_node(oldpos, lnode2)
minetest.get_meta(oldpos):from_table(meta)
moved_nodes[#moved_nodes+1] = {pos = oldpos, oldpos = lnode2, node = lnode2, meta = meta}
nodeupdate(oldpos) nodeupdate(oldpos)
oldpos = {x=lpos2.x, y=lpos2.y, z=lpos2.z} oldpos = {x=lpos2.x, y=lpos2.y, z=lpos2.z}
lpos2.x = lpos2.x-direction.x lpos2.x = lpos2.x-direction.x
lpos2.y = lpos2.y-direction.y lpos2.y = lpos2.y-direction.y
lpos2.z = lpos2.z-direction.z lpos2.z = lpos2.z-direction.z
lnode = minetest.get_node(lpos2) lnode = minetest.env:get_node(lpos2)
until lnode.name == "air" until lnode.name=="air" or lnode.name=="ignore" or not(minetest.registered_nodes[lnode2.name].liquidtype == "none")
or lnode.name == "ignore" minetest.env:remove_node(oldpos)
or (minetest.registered_nodes[lnode.name]
and minetest.registered_nodes[lnode.name].liquidtype ~= "none")
minetest.remove_node(oldpos)
mesecon.on_dignode(oldpos, lnode2)
mesecon:update_autoconnect(oldpos)
on_mvps_move(moved_nodes)
end end
function mesecon:mvps_move_objects(pos, dir, nodestack) function mesecon:mvps_move_objects(pos, dir, nodestack)
@ -197,12 +144,12 @@ function mesecon:mvps_move_objects(pos, dir, nodestack)
-- Move object at tip of stack -- Move object at tip of stack
local pushpos = mesecon:addPosRule(pos, -- get pos at tip of stack local pushpos = mesecon:addPosRule(pos, -- get pos at tip of stack
{x = dir.x * #nodestack, {x = dir.x * (#nodestack),
y = dir.y * #nodestack, y = dir.y * (#nodestack),
z = dir.z * #nodestack}) z = dir.z * (#nodestack)})
local objects = minetest.get_objects_inside_radius(pushpos, 1) local objects = minetest.env:get_objects_inside_radius(pushpos, 1)
for _, obj in ipairs(objects) do for _, obj in ipairs(objects) do
table.insert(objects_to_move, obj) table.insert(objects_to_move, obj)
end end
@ -212,7 +159,7 @@ function mesecon:mvps_move_objects(pos, dir, nodestack)
-- If gravity positive and dir horizontal, push players standing on the stack -- If gravity positive and dir horizontal, push players standing on the stack
for _, n in ipairs(nodestack) do for _, n in ipairs(nodestack) do
local p_above = mesecon:addPosRule(n.pos, {x=0, y=1, z=0}) local p_above = mesecon:addPosRule(n.pos, {x=0, y=1, z=0})
local objects = minetest.get_objects_inside_radius(p_above, 1) local objects = minetest.env:get_objects_inside_radius(p_above, 1)
for _, obj in ipairs(objects) do for _, obj in ipairs(objects) do
table.insert(objects_to_move, obj) table.insert(objects_to_move, obj)
end end
@ -223,11 +170,8 @@ function mesecon:mvps_move_objects(pos, dir, nodestack)
local entity = obj:get_luaentity() local entity = obj:get_luaentity()
if not entity or not mesecon:is_mvps_unmov(entity.name) then if not entity or not mesecon:is_mvps_unmov(entity.name) then
local np = mesecon:addPosRule(obj:getpos(), dir) local np = mesecon:addPosRule(obj:getpos(), dir)
local nn = minetest.env:get_node(np)
--move only if destination is not solid if not minetest.registered_nodes[nn.name].walkable then
local nn = minetest.get_node(np)
if not ((not minetest.registered_nodes[nn.name])
or minetest.registered_nodes[nn.name].walkable) then
obj:setpos(np) obj:setpos(np)
end end
end end

View File

@ -6,12 +6,12 @@ minetest.register_node("mesecons_noteblock:noteblock", {
visual_scale = 1.3, visual_scale = 1.3,
paramtype="light", paramtype="light",
after_place_node = function(pos) after_place_node = function(pos)
minetest.add_node(pos, {name="mesecons_noteblock:noteblock", param2=0}) minetest.env:add_node(pos, {name="mesecons_noteblock:noteblock", param2=0})
end, end,
on_punch = function (pos, node) -- change sound when punched on_punch = function (pos, node) -- change sound when punched
local param2 = node.param2+1 local param2 = node.param2+1
if param2==12 then param2=0 end if param2==12 then param2=0 end
minetest.add_node(pos, {name = node.name, param2 = param2}) minetest.env:add_node(pos, {name = node.name, param2 = param2})
mesecon.noteblock_play(pos, param2) mesecon.noteblock_play(pos, param2)
end, end,
sounds = default.node_sound_wood_defaults(), sounds = default.node_sound_wood_defaults(),
@ -25,9 +25,9 @@ minetest.register_node("mesecons_noteblock:noteblock", {
minetest.register_craft({ minetest.register_craft({
output = "mesecons_noteblock:noteblock 1", output = "mesecons_noteblock:noteblock 1",
recipe = { recipe = {
{"group:wood", "group:wood", "group:wood"}, {"default:wood", "default:wood", "default:wood"},
{"group:mesecon_conductor_craftable", "default:steel_ingot", "group:mesecon_conductor_craftable"}, {"group:mesecon_conductor_craftable", "default:steel_ingot", "group:mesecon_conductor_craftable"},
{"group:wood", "group:wood", "group:wood"}, {"default:wood", "default:wood", "default:wood"},
} }
}) })
@ -58,7 +58,7 @@ mesecon.noteblock_play = function (pos, param2)
elseif param2==7 then elseif param2==7 then
soundname="mesecons_noteblock_gsharp" soundname="mesecons_noteblock_gsharp"
end end
local block_below_name = minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z}).name local block_below_name = minetest.env:get_node({x=pos.x, y=pos.y-1, z=pos.z}).name
if block_below_name == "default:glass" then if block_below_name == "default:glass" then
soundname="mesecons_noteblock_hihat" soundname="mesecons_noteblock_hihat"
end end

View File

@ -56,22 +56,16 @@ end
local piston_remove_pusher = function (pos, node) local piston_remove_pusher = function (pos, node)
pistonspec = minetest.registered_nodes[node.name].mesecons_piston pistonspec = minetest.registered_nodes[node.name].mesecons_piston
if pushername == pistonspec.pusher then --make sure there actually is a pusher (for compatibility reasons mainly)
return
end
dir = piston_get_direction(pistonspec.dir, node) dir = piston_get_direction(pistonspec.dir, node)
local pusherpos = mesecon:addPosRule(pos, dir) local pusherpos = mesecon:addPosRule(pos, dir)
local pushername = minetest.get_node(pusherpos).name local pushername = minetest.env:get_node(pusherpos).name
minetest.remove_node(pusherpos) if pushername == pistonspec.pusher then --make sure there actually is a pusher (for compatibility reasons mainly)
minetest.sound_play("piston_retract", { minetest.env:remove_node(pusherpos)
pos = pos,
max_hear_distance = 20,
gain = 0.3,
})
nodeupdate(pusherpos) nodeupdate(pusherpos)
end end
end
local piston_on = function (pos, node) local piston_on = function (pos, node)
local pistonspec = minetest.registered_nodes[node.name].mesecons_piston local pistonspec = minetest.registered_nodes[node.name].mesecons_piston
@ -80,13 +74,8 @@ local piston_on = function(pos, node)
local np = mesecon:addPosRule(pos, dir) local np = mesecon:addPosRule(pos, dir)
local success, stack, oldstack = mesecon:mvps_push(np, dir, PISTON_MAXIMUM_PUSH) local success, stack, oldstack = mesecon:mvps_push(np, dir, PISTON_MAXIMUM_PUSH)
if success then if success then
minetest.add_node(pos, {param2 = node.param2, name = pistonspec.onname}) minetest.env:add_node(pos, {param2 = node.param2, name = pistonspec.onname})
minetest.add_node(np, {param2 = node.param2, name = pistonspec.pusher}) minetest.env:add_node(np, {param2 = node.param2, name = pistonspec.pusher})
minetest.sound_play("piston_extend", {
pos = pos,
max_hear_distance = 20,
gain = 0.3,
})
mesecon:mvps_process_stack (stack) mesecon:mvps_process_stack (stack)
mesecon:mvps_move_objects (np, dir, oldstack) mesecon:mvps_move_objects (np, dir, oldstack)
end end
@ -94,7 +83,7 @@ end
local piston_off = function (pos, node) local piston_off = function (pos, node)
local pistonspec = minetest.registered_nodes[node.name].mesecons_piston local pistonspec = minetest.registered_nodes[node.name].mesecons_piston
minetest.add_node(pos, {param2 = node.param2, name = pistonspec.offname}) minetest.env:add_node(pos, {param2 = node.param2, name = pistonspec.offname})
piston_remove_pusher (pos, node) piston_remove_pusher (pos, node)
if pistonspec.sticky then if pistonspec.sticky then
@ -112,12 +101,12 @@ local piston_orientate = function(pos, placer)
-- placer pitch in degrees -- placer pitch in degrees
local pitch = placer:get_look_pitch() * (180 / math.pi) local pitch = placer:get_look_pitch() * (180 / math.pi)
local node = minetest.get_node(pos) local node = minetest.env:get_node(pos)
local pistonspec = minetest.registered_nodes[node.name].mesecons_piston local pistonspec = minetest.registered_nodes[node.name].mesecons_piston
if pitch > 55 then --looking upwards if pitch > 55 then --looking upwards
minetest.add_node(pos, {name=pistonspec.piston_down}) minetest.env:add_node(pos, {name=pistonspec.piston_down})
elseif pitch < -55 then --looking downwards elseif pitch < -55 then --looking downwards
minetest.add_node(pos, {name=pistonspec.piston_up}) minetest.env:add_node(pos, {name=pistonspec.piston_up})
end end
end end
@ -717,7 +706,7 @@ local piston_get_stopper = function (node, dir, stack, stackid)
pistonspec = minetest.registered_nodes[node.name].mesecons_piston pistonspec = minetest.registered_nodes[node.name].mesecons_piston
dir = piston_get_direction(pistonspec.dir, node) dir = piston_get_direction(pistonspec.dir, node)
local pusherpos = mesecon:addPosRule(stack[stackid].pos, dir) local pusherpos = mesecon:addPosRule(stack[stackid].pos, dir)
local pushernode = minetest.get_node(pusherpos) local pushernode = minetest.env:get_node(pusherpos)
if minetest.registered_nodes[node.name].mesecons_piston.pusher == pushernode.name then if minetest.registered_nodes[node.name].mesecons_piston.pusher == pushernode.name then
for _, s in ipairs(stack) do for _, s in ipairs(stack) do
@ -743,7 +732,7 @@ mesecon:register_mvps_stopper("mesecons_pistons:piston_down_sticky_on", piston_u
minetest.register_craft({ minetest.register_craft({
output = "mesecons_pistons:piston_normal_off 2", output = "mesecons_pistons:piston_normal_off 2",
recipe = { recipe = {
{"group:wood", "group:wood", "group:wood"}, {"default:wood", "default:wood", "default:wood"},
{"default:cobble", "default:steel_ingot", "default:cobble"}, {"default:cobble", "default:steel_ingot", "default:cobble"},
{"default:cobble", "group:mesecon_conductor_craftable", "default:cobble"}, {"default:cobble", "group:mesecon_conductor_craftable", "default:cobble"},
} }

View File

@ -9,18 +9,18 @@ local pp_box_on = {
} }
pp_on_timer = function (pos, elapsed) pp_on_timer = function (pos, elapsed)
local node = minetest.get_node(pos) local node = minetest.env:get_node(pos)
local ppspec = minetest.registered_nodes[node.name].pressureplate local ppspec = minetest.registered_nodes[node.name].pressureplate
-- This is a workaround for a strange bug that occurs when the server is started -- This is a workaround for a strange bug that occurs when the server is started
-- For some reason the first time on_timer is called, the pos is wrong -- For some reason the first time on_timer is called, the pos is wrong
if not ppspec then return end if not ppspec then return end
local objs = minetest.get_objects_inside_radius(pos, 1) local objs = minetest.env:get_objects_inside_radius(pos, 1)
local two_below = mesecon:addPosRule(pos, {x = 0, y = -2, z = 0}) local two_below = mesecon:addPosRule(pos, {x = 0, y = -2, z = 0})
if objs[1] == nil and node.name == ppspec.onstate then if objs[1] == nil and node.name == ppspec.onstate then
minetest.add_node(pos, {name = ppspec.offstate}) minetest.env:add_node(pos, {name = ppspec.offstate})
mesecon:receptor_off(pos) mesecon:receptor_off(pos)
-- force deactivation of mesecon two blocks below (hacky) -- force deactivation of mesecon two blocks below (hacky)
if not mesecon:connected_to_receptor(two_below) then if not mesecon:connected_to_receptor(two_below) then
@ -30,7 +30,7 @@ pp_on_timer = function (pos, elapsed)
for k, obj in pairs(objs) do for k, obj in pairs(objs) do
local objpos = obj:getpos() local objpos = obj:getpos()
if objpos.y > pos.y-1 and objpos.y < pos.y then if objpos.y > pos.y-1 and objpos.y < pos.y then
minetest.add_node(pos, {name=ppspec.onstate}) minetest.env:add_node(pos, {name=ppspec.onstate})
mesecon:receptor_on(pos) mesecon:receptor_on(pos)
-- force activation of mesecon two blocks below (hacky) -- force activation of mesecon two blocks below (hacky)
mesecon:turnon(two_below) mesecon:turnon(two_below)
@ -71,7 +71,7 @@ function mesecon:register_pressure_plate(offstate, onstate, description, texture
state = mesecon.state.off state = mesecon.state.off
}}, }},
on_construct = function(pos) on_construct = function(pos)
minetest.get_node_timer(pos):start(PRESSURE_PLATE_INTERVAL) minetest.env:get_node_timer(pos):start(PRESSURE_PLATE_INTERVAL)
end, end,
}) })
@ -90,7 +90,7 @@ function mesecon:register_pressure_plate(offstate, onstate, description, texture
state = mesecon.state.on state = mesecon.state.on
}}, }},
on_construct = function(pos) on_construct = function(pos)
minetest.get_node_timer(pos):start(PRESSURE_PLATE_INTERVAL) minetest.env:get_node_timer(pos):start(PRESSURE_PLATE_INTERVAL)
end, end,
after_dig_node = function(pos) after_dig_node = function(pos)
local two_below = mesecon:addPosRule(pos, {x = 0, y = -2, z = 0}) local two_below = mesecon:addPosRule(pos, {x = 0, y = -2, z = 0})
@ -114,7 +114,7 @@ mesecon:register_pressure_plate(
{"jeija_pressure_plate_wood_on.png","jeija_pressure_plate_wood_on.png","jeija_pressure_plate_wood_on_edges.png"}, {"jeija_pressure_plate_wood_on.png","jeija_pressure_plate_wood_on.png","jeija_pressure_plate_wood_on_edges.png"},
"jeija_pressure_plate_wood_wield.png", "jeija_pressure_plate_wood_wield.png",
"jeija_pressure_plate_wood_inv.png", "jeija_pressure_plate_wood_inv.png",
{{"group:wood", "group:wood"}}) {{"default:wood", "default:wood"}})
mesecon:register_pressure_plate( mesecon:register_pressure_plate(
"mesecons_pressureplates:pressure_plate_stone_off", "mesecons_pressureplates:pressure_plate_stone_off",

View File

@ -8,7 +8,7 @@ minetest.register_node("mesecons_random:removestone", {
sounds = default.node_sound_stone_defaults(), sounds = default.node_sound_stone_defaults(),
mesecons = {effector = { mesecons = {effector = {
action_on = function (pos, node) action_on = function (pos, node)
minetest.remove_node(pos) minetest.env:remove_node(pos)
mesecon:update_autoconnect(pos) mesecon:update_autoconnect(pos)
end end
}} }}
@ -68,8 +68,8 @@ minetest.register_node("mesecons_random:ghoststone_active", {
on_construct = function(pos) on_construct = function(pos)
--remove shadow --remove shadow
pos2 = {x = pos.x, y = pos.y + 1, z = pos.z} pos2 = {x = pos.x, y = pos.y + 1, z = pos.z}
if ( minetest.get_node(pos2).name == "air" ) then if ( minetest.env:get_node(pos2).name == "air" ) then
minetest.dig_node(pos2) minetest.env:dig_node(pos2)
end end
end end
}) })

View File

@ -91,7 +91,7 @@ mesecon:add_rules("receiver_pos_all", {
function mesecon:receiver_get_pos_from_rcpt(pos, param2) function mesecon:receiver_get_pos_from_rcpt(pos, param2)
local rules = mesecon:get_rules("receiver_pos") local rules = mesecon:get_rules("receiver_pos")
if param2 == nil then param2 = minetest.get_node(pos).param2 end if param2 == nil then param2 = minetest.env:get_node(pos).param2 end
if param2 == 2 then if param2 == 2 then
rules = mesecon:rotate_rules_left(rules) rules = mesecon:rotate_rules_left(rules)
elseif param2 == 3 then elseif param2 == 3 then
@ -107,17 +107,17 @@ function mesecon:receiver_get_pos_from_rcpt(pos, param2)
end end
function mesecon:receiver_place(rcpt_pos) function mesecon:receiver_place(rcpt_pos)
local node = minetest.get_node(rcpt_pos) local node = minetest.env:get_node(rcpt_pos)
local pos = mesecon:receiver_get_pos_from_rcpt(rcpt_pos, node.param2) local pos = mesecon:receiver_get_pos_from_rcpt(rcpt_pos, node.param2)
local nn = minetest.get_node(pos) local nn = minetest.env:get_node(pos)
if string.find(nn.name, "mesecons:wire_") ~= nil then if string.find(nn.name, "mesecons:wire_") ~= nil then
minetest.dig_node(pos) minetest.env:dig_node(pos)
if mesecon:is_power_on(rcpt_pos) then if mesecon:is_power_on(rcpt_pos) then
minetest.add_node(pos, {name = "mesecons_receiver:receiver_on", param2 = node.param2}) minetest.env:add_node(pos, {name = "mesecons_receiver:receiver_on", param2 = node.param2})
mesecon:receptor_on(pos, receiver_get_rules(node)) mesecon:receptor_on(pos, receiver_get_rules(node))
else else
minetest.add_node(pos, {name = "mesecons_receiver:receiver_off", param2 = node.param2}) minetest.env:add_node(pos, {name = "mesecons_receiver:receiver_off", param2 = node.param2})
end end
mesecon:update_autoconnect(pos) mesecon:update_autoconnect(pos)
end end
@ -125,11 +125,11 @@ end
function mesecon:receiver_remove(rcpt_pos, dugnode) function mesecon:receiver_remove(rcpt_pos, dugnode)
local pos = mesecon:receiver_get_pos_from_rcpt(rcpt_pos, dugnode.param2) local pos = mesecon:receiver_get_pos_from_rcpt(rcpt_pos, dugnode.param2)
local nn = minetest.get_node(pos) local nn = minetest.env:get_node(pos)
if string.find(nn.name, "mesecons_receiver:receiver_") ~=nil then if string.find(nn.name, "mesecons_receiver:receiver_") ~=nil then
minetest.dig_node(pos) minetest.env:dig_node(pos)
local node = {name = "mesecons:wire_00000000_off"} local node = {name = "mesecons:wire_00000000_off"}
minetest.add_node(pos, node) minetest.env:add_node(pos, node)
mesecon:update_autoconnect(pos) mesecon:update_autoconnect(pos)
mesecon.on_placenode(pos, node) mesecon.on_placenode(pos, node)
end end
@ -156,7 +156,7 @@ minetest.register_on_placenode(function (pos, node)
x = pos.x + rules[i].x, x = pos.x + rules[i].x,
y = pos.y + rules[i].y, y = pos.y + rules[i].y,
z = pos.z + rules[i].z} z = pos.z + rules[i].z}
if minetest.get_item_group(minetest.get_node(np).name, "mesecon_needs_receiver") == 1 then if minetest.get_item_group(minetest.env:get_node(np).name, "mesecon_needs_receiver") == 1 then
mesecon:receiver_place(np) mesecon:receiver_place(np)
end end
i = i + 1 i = i + 1

View File

@ -71,10 +71,10 @@ minetest.register_abm(
interval = 1, interval = 1,
chance = 1, chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider) action = function(pos, node, active_object_count, active_object_count_wider)
local light = minetest.get_node_light(pos, nil) local light = minetest.env:get_node_light(pos, nil)
if light >= 12 then if light >= 12 then
minetest.set_node(pos, {name="mesecons_solarpanel:solar_panel_on", param2=node.param2}) minetest.env:set_node(pos, {name="mesecons_solarpanel:solar_panel_on", param2=node.param2})
mesecon:receptor_on(pos) mesecon:receptor_on(pos)
end end
end, end,
@ -85,10 +85,10 @@ minetest.register_abm(
interval = 1, interval = 1,
chance = 1, chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider) action = function(pos, node, active_object_count, active_object_count_wider)
local light = minetest.get_node_light(pos, nil) local light = minetest.env:get_node_light(pos, nil)
if light < 12 then if light < 12 then
minetest.set_node(pos, {name="mesecons_solarpanel:solar_panel_off", param2=node.param2}) minetest.env:set_node(pos, {name="mesecons_solarpanel:solar_panel_off", param2=node.param2})
mesecon:receptor_off(pos) mesecon:receptor_off(pos)
end end
end, end,

View File

@ -10,7 +10,7 @@ minetest.register_node("mesecons_switch:mesecon_switch_off", {
state = mesecon.state.off state = mesecon.state.off
}}, }},
on_punch = function(pos, node) on_punch = function(pos, node)
minetest.swap_node(pos, {name = "mesecons_switch:mesecon_switch_on", param2 = node.param2}) mesecon:swap_node(pos, "mesecons_switch:mesecon_switch_on")
mesecon:receptor_on(pos) mesecon:receptor_on(pos)
minetest.sound_play("mesecons_switch", {pos=pos}) minetest.sound_play("mesecons_switch", {pos=pos})
end end
@ -26,7 +26,7 @@ minetest.register_node("mesecons_switch:mesecon_switch_on", {
state = mesecon.state.on state = mesecon.state.on
}}, }},
on_punch = function(pos, node) on_punch = function(pos, node)
minetest.swap_node(pos, {name = "mesecons_switch:mesecon_switch_off", param2 = node.param2}) mesecon:swap_node(pos, "mesecons_switch:mesecon_switch_off")
mesecon:receptor_off(pos) mesecon:receptor_off(pos)
minetest.sound_play("mesecons_switch", {pos=pos}) minetest.sound_play("mesecons_switch", {pos=pos})
end end

View File

@ -0,0 +1 @@
-- place texture packs for mesecons into the textures folder here

Binary file not shown.

After

Width:  |  Height:  |  Size: 497 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 418 B

View File

Before

Width:  |  Height:  |  Size: 454 B

After

Width:  |  Height:  |  Size: 454 B

View File

Before

Width:  |  Height:  |  Size: 463 B

After

Width:  |  Height:  |  Size: 463 B

View File

Before

Width:  |  Height:  |  Size: 323 B

After

Width:  |  Height:  |  Size: 323 B

View File

Before

Width:  |  Height:  |  Size: 282 B

After

Width:  |  Height:  |  Size: 282 B

View File

Before

Width:  |  Height:  |  Size: 278 B

After

Width:  |  Height:  |  Size: 278 B

View File

Before

Width:  |  Height:  |  Size: 592 B

After

Width:  |  Height:  |  Size: 592 B

View File

Before

Width:  |  Height:  |  Size: 233 B

After

Width:  |  Height:  |  Size: 233 B

View File

Before

Width:  |  Height:  |  Size: 231 B

After

Width:  |  Height:  |  Size: 231 B

View File

Before

Width:  |  Height:  |  Size: 251 B

After

Width:  |  Height:  |  Size: 251 B

View File

Before

Width:  |  Height:  |  Size: 241 B

After

Width:  |  Height:  |  Size: 241 B

View File

Before

Width:  |  Height:  |  Size: 195 B

After

Width:  |  Height:  |  Size: 195 B

View File

Before

Width:  |  Height:  |  Size: 195 B

After

Width:  |  Height:  |  Size: 195 B

View File

Before

Width:  |  Height:  |  Size: 245 B

After

Width:  |  Height:  |  Size: 245 B

View File

Before

Width:  |  Height:  |  Size: 743 B

After

Width:  |  Height:  |  Size: 743 B

View File

Before

Width:  |  Height:  |  Size: 777 B

After

Width:  |  Height:  |  Size: 777 B

View File

Before

Width:  |  Height:  |  Size: 487 B

After

Width:  |  Height:  |  Size: 487 B

View File

Before

Width:  |  Height:  |  Size: 835 B

After

Width:  |  Height:  |  Size: 835 B

View File

Before

Width:  |  Height:  |  Size: 817 B

After

Width:  |  Height:  |  Size: 817 B

View File

Before

Width:  |  Height:  |  Size: 253 B

After

Width:  |  Height:  |  Size: 253 B

View File

Before

Width:  |  Height:  |  Size: 196 B

After

Width:  |  Height:  |  Size: 196 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 173 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 166 B

View File

Before

Width:  |  Height:  |  Size: 200 B

After

Width:  |  Height:  |  Size: 200 B

View File

Before

Width:  |  Height:  |  Size: 169 B

After

Width:  |  Height:  |  Size: 169 B

View File

Before

Width:  |  Height:  |  Size: 260 B

After

Width:  |  Height:  |  Size: 260 B

View File

Before

Width:  |  Height:  |  Size: 545 B

After

Width:  |  Height:  |  Size: 545 B

View File

Before

Width:  |  Height:  |  Size: 447 B

After

Width:  |  Height:  |  Size: 447 B

View File

Before

Width:  |  Height:  |  Size: 667 B

After

Width:  |  Height:  |  Size: 667 B

View File

Before

Width:  |  Height:  |  Size: 452 B

After

Width:  |  Height:  |  Size: 452 B

View File

Before

Width:  |  Height:  |  Size: 662 B

After

Width:  |  Height:  |  Size: 662 B

View File

Before

Width:  |  Height:  |  Size: 446 B

After

Width:  |  Height:  |  Size: 446 B

View File

Before

Width:  |  Height:  |  Size: 705 B

After

Width:  |  Height:  |  Size: 705 B

View File

Before

Width:  |  Height:  |  Size: 408 B

After

Width:  |  Height:  |  Size: 408 B

View File

Before

Width:  |  Height:  |  Size: 650 B

After

Width:  |  Height:  |  Size: 650 B

View File

Before

Width:  |  Height:  |  Size: 291 B

After

Width:  |  Height:  |  Size: 291 B

View File

Before

Width:  |  Height:  |  Size: 486 B

After

Width:  |  Height:  |  Size: 486 B

View File

Before

Width:  |  Height:  |  Size: 2.0 KiB

After

Width:  |  Height:  |  Size: 2.0 KiB

View File

Before

Width:  |  Height:  |  Size: 4.2 KiB

After

Width:  |  Height:  |  Size: 4.2 KiB

View File

Before

Width:  |  Height:  |  Size: 3.5 KiB

After

Width:  |  Height:  |  Size: 3.5 KiB

View File

Before

Width:  |  Height:  |  Size: 3.5 KiB

After

Width:  |  Height:  |  Size: 3.5 KiB

View File

Before

Width:  |  Height:  |  Size: 3.5 KiB

After

Width:  |  Height:  |  Size: 3.5 KiB

View File

Before

Width:  |  Height:  |  Size: 3.5 KiB

After

Width:  |  Height:  |  Size: 3.5 KiB

Some files were not shown because too many files have changed in this diff Show More