diff --git a/CLA.md b/CLA.md
new file mode 100644
index 00000000..d54b7aa2
--- /dev/null
+++ b/CLA.md
@@ -0,0 +1,37 @@
+# LDTTeam CLA
+
+Thank you for your interest in contributing to the ldtteam organization (the "Organization"). In order to clarify the intellectual property license granted with Contributions from any person or entity, the Organization must have a Contributor License Agreement ("CLA") on file that has been signed by each Contributor, indicating agreement to the license terms below. This license is for your protection as a Contributor as well as the protection of the Organization and its users; it does not change your rights to use your own Contributions for any other purpose.
+
+Please read this document carefully before signing and keep a copy for your records.
+
+You accept and agree to the following terms and conditions for Your present and future Contributions submitted to the Organization. Except for the license granted herein to the Organization and recipients of software distributed by the Organization, You reserve all right, title, and interest in and to Your Contributions.
+
+### Section 1. Definitions.
+ * "You" (or "Your") shall mean the copyright owner or legal entity authorized by the copyright owner that is making this Agreement with the Organization. For legal entities, the entity making a Contribution and all other entities that control, are controlled by, or are under common control with that entity are considered to be a single Contributor.
+
+ For the purposes of this definition, "control" means **(i)** the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or **(ii)** ownership of fifty percent (50%) or more of the outstanding shares, or **(iii)** beneficial ownership of such entity.
+
+ * "Contribution" shall mean any original work of authorship, including any modifications or additions to an existing work, that is intentionally submitted by You to the Organization for inclusion in, or documentation of, any of the products owned or managed by the Organization (the "Work").
+
+ For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Organization or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Organization for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by You as "Not a Contribution."
+
+### Section 2. Grant of Copyright License.
+Subject to the terms and conditions of this Agreement, You hereby grant to the Organization and to recipients of software distributed by the Organization a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare derivative works of, publicly display, publicly perform, sublicense, and distribute Your Contributions and such derivative works.
+
+### Section 3. Grant of Patent License.
+Subject to the terms and conditions of this Agreement, You hereby grant to the Organization and to recipients of software distributed by the Organization a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by You that are necessarily infringed by Your Contribution(s) alone or by combination of Your Contribution(s) with the Work to which such Contribution(s) was submitted. If any entity institutes patent litigation against You or any other entity (including a cross-claim or counterclaim in a lawsuit) alleging that your Contribution, or the Work to which you have contributed, constitutes direct or contributory patent infringement, then any patent licenses granted to that entity under this Agreement for that Contribution or Work shall terminate as of the date such litigation is filed.
+
+### Section 4.
+You represent that you are legally entitled to grant the above license. If your employer(s) has rights to intellectual property that you create that includes your Contributions, you represent that you have received permission to make Contributions on behalf of that employer, that your employer has waived such rights for your Contributions to the Organization, or that your employer has executed a separate Corporate CLA with the Organization.
+
+### Section 5.
+You represent that each of Your Contributions is Your original creation (see [section 7](#section-7) for submissions on behalf of others). You represent that Your Contribution submissions include complete details of any third-party license or other restriction (including, but not limited to, related patents and trademarks) of which you are personally aware and which are associated with any part of Your Contributions.
+
+### Section 6.
+You are not expected to provide support for Your Contributions, except to the extent You desire to provide support. You may provide support for free, for a fee, or not at all. Unless required by applicable law or agreed to in writing, You provide Your Contributions on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON- INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE.
+
+### Section 7.
+Should You wish to submit work that is not Your original creation, You may submit it to the Organization separately from any Contribution, identifying the complete details of its source and of any license or other restriction (including, but not limited to, related patents, trademarks, and license agreements) of which you are personally aware, and conspicuously marking the work as _"Submitted on behalf of a third-party: [named here]"_.
+
+### Section 8.
+You agree to notify the Organization of any facts or circumstances of which you become aware that would make these representations inaccurate in any respect.
diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md
new file mode 100644
index 00000000..62e571f0
--- /dev/null
+++ b/CODE_OF_CONDUCT.md
@@ -0,0 +1,76 @@
+# Contributor Covenant Code of Conduct
+
+## Our Pledge
+
+In the interest of fostering an open and welcoming environment, we as
+contributors and maintainers pledge to making participation in our project and
+our community a harassment-free experience for everyone, regardless of age, body
+size, disability, ethnicity, sex characteristics, gender identity and expression,
+level of experience, education, socio-economic status, nationality, personal
+appearance, race, religion, or sexual identity and orientation.
+
+## Our Standards
+
+Examples of behavior that contributes to creating a positive environment
+include:
+
+* Using welcoming and inclusive language
+* Being respectful of differing viewpoints and experiences
+* Gracefully accepting constructive criticism
+* Focusing on what is best for the community
+* Showing empathy towards other community members
+
+Examples of unacceptable behavior by participants include:
+
+* The use of sexualized language or imagery and unwelcome sexual attention or
+ advances
+* Trolling, insulting/derogatory comments, and personal or political attacks
+* Public or private harassment
+* Publishing others' private information, such as a physical or electronic
+ address, without explicit permission
+* Other conduct which could reasonably be considered inappropriate in a
+ professional setting
+
+## Our Responsibilities
+
+Project maintainers are responsible for clarifying the standards of acceptable
+behavior and are expected to take appropriate and fair corrective action in
+response to any instances of unacceptable behavior.
+
+Project maintainers have the right and responsibility to remove, edit, or
+reject comments, commits, code, wiki edits, issues, and other contributions
+that are not aligned to this Code of Conduct, or to ban temporarily or
+permanently any contributor for other behaviors that they deem inappropriate,
+threatening, offensive, or harmful.
+
+## Scope
+
+This Code of Conduct applies both within project spaces and in public spaces
+when an individual is representing the project or its community. Examples of
+representing a project or community include using an official project e-mail
+address, posting via an official social media account, or acting as an appointed
+representative at an online or offline event. Representation of a project may be
+further defined and clarified by project maintainers.
+
+## Enforcement
+
+Instances of abusive, harassing, or otherwise unacceptable behavior may be
+reported by contacting the project team at http://discord.minecolonies.com. All
+complaints will be reviewed and investigated and will result in a response that
+is deemed necessary and appropriate to the circumstances. The project team is
+obligated to maintain confidentiality with regard to the reporter of an incident.
+Further details of specific enforcement policies may be posted separately.
+
+Project maintainers who do not follow or enforce the Code of Conduct in good
+faith may face temporary or permanent repercussions as determined by other
+members of the project's leadership.
+
+## Attribution
+
+This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
+available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
+
+[homepage]: https://www.contributor-covenant.org
+
+For answers to common questions about this code of conduct, see
+https://www.contributor-covenant.org/faq
\ No newline at end of file
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 00000000..70566f2d
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,674 @@
+GNU GENERAL PUBLIC LICENSE
+ Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc.
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The GNU General Public License is a free, copyleft license for
+software and other kinds of works.
+
+ The licenses for most software and other practical works are designed
+to take away your freedom to share and change the works. By contrast,
+the GNU General Public License is intended to guarantee your freedom to
+share and change all versions of a program--to make sure it remains free
+software for all its users. We, the Free Software Foundation, use the
+GNU General Public License for most of our software; it applies also to
+any other work released this way by its authors. You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+them if you wish), that you receive source code or can get it if you
+want it, that you can change the software or use pieces of it in new
+free programs, and that you know you can do these things.
+
+ To protect your rights, we need to prevent others from denying you
+these rights or asking you to surrender the rights. Therefore, you have
+certain responsibilities if you distribute copies of the software, or if
+you modify it: responsibilities to respect the freedom of others.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must pass on to the recipients the same
+freedoms that you received. You must make sure that they, too, receive
+or can get the source code. And you must show them these terms so they
+know their rights.
+
+ Developers that use the GNU GPL protect your rights with two steps:
+(1) assert copyright on the software, and (2) offer you this License
+giving you legal permission to copy, distribute and/or modify it.
+
+ For the developers' and authors' protection, the GPL clearly explains
+that there is no warranty for this free software. For both users' and
+authors' sake, the GPL requires that modified versions be marked as
+changed, so that their problems will not be attributed erroneously to
+authors of previous versions.
+
+ Some devices are designed to deny users access to install or run
+modified versions of the software inside them, although the manufacturer
+can do so. This is fundamentally incompatible with the aim of
+protecting users' freedom to change the software. The systematic
+pattern of such abuse occurs in the area of products for individuals to
+use, which is precisely where it is most unacceptable. Therefore, we
+have designed this version of the GPL to prohibit the practice for those
+products. If such problems arise substantially in other domains, we
+stand ready to extend this provision to those domains in future versions
+of the GPL, as needed to protect the freedom of users.
+
+ Finally, every program is threatened constantly by software patents.
+States should not allow patents to restrict development and use of
+software on general-purpose computers, but in those that do, we wish to
+avoid the special danger that patents applied to a free program could
+make it effectively proprietary. To prevent this, the GPL assures that
+patents cannot be used to render the program non-free.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ TERMS AND CONDITIONS
+
+ 0. Definitions.
+
+ "This License" refers to version 3 of the GNU General Public License.
+
+ "Copyright" also means copyright-like laws that apply to other kinds of
+works, such as semiconductor masks.
+
+ "The Program" refers to any copyrightable work licensed under this
+License. Each licensee is addressed as "you". "Licensees" and
+"recipients" may be individuals or organizations.
+
+ To "modify" a work means to copy from or adapt all or part of the work
+in a fashion requiring copyright permission, other than the making of an
+exact copy. The resulting work is called a "modified version" of the
+earlier work or a work "based on" the earlier work.
+
+ A "covered work" means either the unmodified Program or a work based
+on the Program.
+
+ To "propagate" a work means to do anything with it that, without
+permission, would make you directly or secondarily liable for
+infringement under applicable copyright law, except executing it on a
+computer or modifying a private copy. Propagation includes copying,
+distribution (with or without modification), making available to the
+public, and in some countries other activities as well.
+
+ To "convey" a work means any kind of propagation that enables other
+parties to make or receive copies. Mere interaction with a user through
+a computer network, with no transfer of a copy, is not conveying.
+
+ An interactive user interface displays "Appropriate Legal Notices"
+to the extent that it includes a convenient and prominently visible
+feature that (1) displays an appropriate copyright notice, and (2)
+tells the user that there is no warranty for the work (except to the
+extent that warranties are provided), that licensees may convey the
+work under this License, and how to view a copy of this License. If
+the interface presents a list of user commands or options, such as a
+menu, a prominent item in the list meets this criterion.
+
+ 1. Source Code.
+
+ The "source code" for a work means the preferred form of the work
+for making modifications to it. "Object code" means any non-source
+form of a work.
+
+ A "Standard Interface" means an interface that either is an official
+standard defined by a recognized standards body, or, in the case of
+interfaces specified for a particular programming language, one that
+is widely used among developers working in that language.
+
+ The "System Libraries" of an executable work include anything, other
+than the work as a whole, that (a) is included in the normal form of
+packaging a Major Component, but which is not part of that Major
+Component, and (b) serves only to enable use of the work with that
+Major Component, or to implement a Standard Interface for which an
+implementation is available to the public in source code form. A
+"Major Component", in this context, means a major essential component
+(kernel, window system, and so on) of the specific operating system
+(if any) on which the executable work runs, or a compiler used to
+produce the work, or an object code interpreter used to run it.
+
+ The "Corresponding Source" for a work in object code form means all
+the source code needed to generate, install, and (for an executable
+work) run the object code and to modify the work, including scripts to
+control those activities. However, it does not include the work's
+System Libraries, or general-purpose tools or generally available free
+programs which are used unmodified in performing those activities but
+which are not part of the work. For example, Corresponding Source
+includes interface definition files associated with source files for
+the work, and the source code for shared libraries and dynamically
+linked subprograms that the work is specifically designed to require,
+such as by intimate data communication or control flow between those
+subprograms and other parts of the work.
+
+ The Corresponding Source need not include anything that users
+can regenerate automatically from other parts of the Corresponding
+Source.
+
+ The Corresponding Source for a work in source code form is that
+same work.
+
+ 2. Basic Permissions.
+
+ All rights granted under this License are granted for the term of
+copyright on the Program, and are irrevocable provided the stated
+conditions are met. This License explicitly affirms your unlimited
+permission to run the unmodified Program. The output from running a
+covered work is covered by this License only if the output, given its
+content, constitutes a covered work. This License acknowledges your
+rights of fair use or other equivalent, as provided by copyright law.
+
+ You may make, run and propagate covered works that you do not
+convey, without conditions so long as your license otherwise remains
+in force. You may convey covered works to others for the sole purpose
+of having them make modifications exclusively for you, or provide you
+with facilities for running those works, provided that you comply with
+the terms of this License in conveying all material for which you do
+not control copyright. Those thus making or running the covered works
+for you must do so exclusively on your behalf, under your direction
+and control, on terms that prohibit them from making any copies of
+your copyrighted material outside their relationship with you.
+
+ Conveying under any other circumstances is permitted solely under
+the conditions stated below. Sublicensing is not allowed; section 10
+makes it unnecessary.
+
+ 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
+
+ No covered work shall be deemed part of an effective technological
+measure under any applicable law fulfilling obligations under article
+11 of the WIPO copyright treaty adopted on 20 December 1996, or
+similar laws prohibiting or restricting circumvention of such
+measures.
+
+ When you convey a covered work, you waive any legal power to forbid
+circumvention of technological measures to the extent such circumvention
+is effected by exercising rights under this License with respect to
+the covered work, and you disclaim any intention to limit operation or
+modification of the work as a means of enforcing, against the work's
+users, your or third parties' legal rights to forbid circumvention of
+technological measures.
+
+ 4. Conveying Verbatim Copies.
+
+ You may convey verbatim copies of the Program's source code as you
+receive it, in any medium, provided that you conspicuously and
+appropriately publish on each copy an appropriate copyright notice;
+keep intact all notices stating that this License and any
+non-permissive terms added in accord with section 7 apply to the code;
+keep intact all notices of the absence of any warranty; and give all
+recipients a copy of this License along with the Program.
+
+ You may charge any price or no price for each copy that you convey,
+and you may offer support or warranty protection for a fee.
+
+ 5. Conveying Modified Source Versions.
+
+ You may convey a work based on the Program, or the modifications to
+produce it from the Program, in the form of source code under the
+terms of section 4, provided that you also meet all of these conditions:
+
+ a) The work must carry prominent notices stating that you modified
+ it, and giving a relevant date.
+
+ b) The work must carry prominent notices stating that it is
+ released under this License and any conditions added under section
+ 7. This requirement modifies the requirement in section 4 to
+ "keep intact all notices".
+
+ c) You must license the entire work, as a whole, under this
+ License to anyone who comes into possession of a copy. This
+ License will therefore apply, along with any applicable section 7
+ additional terms, to the whole of the work, and all its parts,
+ regardless of how they are packaged. This License gives no
+ permission to license the work in any other way, but it does not
+ invalidate such permission if you have separately received it.
+
+ d) If the work has interactive user interfaces, each must display
+ Appropriate Legal Notices; however, if the Program has interactive
+ interfaces that do not display Appropriate Legal Notices, your
+ work need not make them do so.
+
+ A compilation of a covered work with other separate and independent
+works, which are not by their nature extensions of the covered work,
+and which are not combined with it such as to form a larger program,
+in or on a volume of a storage or distribution medium, is called an
+"aggregate" if the compilation and its resulting copyright are not
+used to limit the access or legal rights of the compilation's users
+beyond what the individual works permit. Inclusion of a covered work
+in an aggregate does not cause this License to apply to the other
+parts of the aggregate.
+
+ 6. Conveying Non-Source Forms.
+
+ You may convey a covered work in object code form under the terms
+of sections 4 and 5, provided that you also convey the
+machine-readable Corresponding Source under the terms of this License,
+in one of these ways:
+
+ a) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by the
+ Corresponding Source fixed on a durable physical medium
+ customarily used for software interchange.
+
+ b) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by a
+ written offer, valid for at least three years and valid for as
+ long as you offer spare parts or customer support for that product
+ model, to give anyone who possesses the object code either (1) a
+ copy of the Corresponding Source for all the software in the
+ product that is covered by this License, on a durable physical
+ medium customarily used for software interchange, for a price no
+ more than your reasonable cost of physically performing this
+ conveying of source, or (2) access to copy the
+ Corresponding Source from a network server at no charge.
+
+ c) Convey individual copies of the object code with a copy of the
+ written offer to provide the Corresponding Source. This
+ alternative is allowed only occasionally and noncommercially, and
+ only if you received the object code with such an offer, in accord
+ with subsection 6b.
+
+ d) Convey the object code by offering access from a designated
+ place (gratis or for a charge), and offer equivalent access to the
+ Corresponding Source in the same way through the same place at no
+ further charge. You need not require recipients to copy the
+ Corresponding Source along with the object code. If the place to
+ copy the object code is a network server, the Corresponding Source
+ may be on a different server (operated by you or a third party)
+ that supports equivalent copying facilities, provided you maintain
+ clear directions next to the object code saying where to find the
+ Corresponding Source. Regardless of what server hosts the
+ Corresponding Source, you remain obligated to ensure that it is
+ available for as long as needed to satisfy these requirements.
+
+ e) Convey the object code using peer-to-peer transmission, provided
+ you inform other peers where the object code and Corresponding
+ Source of the work are being offered to the general public at no
+ charge under subsection 6d.
+
+ A separable portion of the object code, whose source code is excluded
+from the Corresponding Source as a System Library, need not be
+included in conveying the object code work.
+
+ A "User Product" is either (1) a "consumer product", which means any
+tangible personal property which is normally used for personal, family,
+or household purposes, or (2) anything designed or sold for incorporation
+into a dwelling. In determining whether a product is a consumer product,
+doubtful cases shall be resolved in favor of coverage. For a particular
+product received by a particular user, "normally used" refers to a
+typical or common use of that class of product, regardless of the status
+of the particular user or of the way in which the particular user
+actually uses, or expects or is expected to use, the product. A product
+is a consumer product regardless of whether the product has substantial
+commercial, industrial or non-consumer uses, unless such uses represent
+the only significant mode of use of the product.
+
+ "Installation Information" for a User Product means any methods,
+procedures, authorization keys, or other information required to install
+and execute modified versions of a covered work in that User Product from
+a modified version of its Corresponding Source. The information must
+suffice to ensure that the continued functioning of the modified object
+code is in no case prevented or interfered with solely because
+modification has been made.
+
+ If you convey an object code work under this section in, or with, or
+specifically for use in, a User Product, and the conveying occurs as
+part of a transaction in which the right of possession and use of the
+User Product is transferred to the recipient in perpetuity or for a
+fixed term (regardless of how the transaction is characterized), the
+Corresponding Source conveyed under this section must be accompanied
+by the Installation Information. But this requirement does not apply
+if neither you nor any third party retains the ability to install
+modified object code on the User Product (for example, the work has
+been installed in ROM).
+
+ The requirement to provide Installation Information does not include a
+requirement to continue to provide support service, warranty, or updates
+for a work that has been modified or installed by the recipient, or for
+the User Product in which it has been modified or installed. Access to a
+network may be denied when the modification itself materially and
+adversely affects the operation of the network or violates the rules and
+protocols for communication across the network.
+
+ Corresponding Source conveyed, and Installation Information provided,
+in accord with this section must be in a format that is publicly
+documented (and with an implementation available to the public in
+source code form), and must require no special password or key for
+unpacking, reading or copying.
+
+ 7. Additional Terms.
+
+ "Additional permissions" are terms that supplement the terms of this
+License by making exceptions from one or more of its conditions.
+Additional permissions that are applicable to the entire Program shall
+be treated as though they were included in this License, to the extent
+that they are valid under applicable law. If additional permissions
+apply only to part of the Program, that part may be used separately
+under those permissions, but the entire Program remains governed by
+this License without regard to the additional permissions.
+
+ When you convey a copy of a covered work, you may at your option
+remove any additional permissions from that copy, or from any part of
+it. (Additional permissions may be written to require their own
+removal in certain cases when you modify the work.) You may place
+additional permissions on material, added by you to a covered work,
+for which you have or can give appropriate copyright permission.
+
+ Notwithstanding any other provision of this License, for material you
+add to a covered work, you may (if authorized by the copyright holders of
+that material) supplement the terms of this License with terms:
+
+ a) Disclaiming warranty or limiting liability differently from the
+ terms of sections 15 and 16 of this License; or
+
+ b) Requiring preservation of specified reasonable legal notices or
+ author attributions in that material or in the Appropriate Legal
+ Notices displayed by works containing it; or
+
+ c) Prohibiting misrepresentation of the origin of that material, or
+ requiring that modified versions of such material be marked in
+ reasonable ways as different from the original version; or
+
+ d) Limiting the use for publicity purposes of names of licensors or
+ authors of the material; or
+
+ e) Declining to grant rights under trademark law for use of some
+ trade names, trademarks, or service marks; or
+
+ f) Requiring indemnification of licensors and authors of that
+ material by anyone who conveys the material (or modified versions of
+ it) with contractual assumptions of liability to the recipient, for
+ any liability that these contractual assumptions directly impose on
+ those licensors and authors.
+
+ All other non-permissive additional terms are considered "further
+restrictions" within the meaning of section 10. If the Program as you
+received it, or any part of it, contains a notice stating that it is
+governed by this License along with a term that is a further
+restriction, you may remove that term. If a license document contains
+a further restriction but permits relicensing or conveying under this
+License, you may add to a covered work material governed by the terms
+of that license document, provided that the further restriction does
+not survive such relicensing or conveying.
+
+ If you add terms to a covered work in accord with this section, you
+must place, in the relevant source files, a statement of the
+additional terms that apply to those files, or a notice indicating
+where to find the applicable terms.
+
+ Additional terms, permissive or non-permissive, may be stated in the
+form of a separately written license, or stated as exceptions;
+the above requirements apply either way.
+
+ 8. Termination.
+
+ You may not propagate or modify a covered work except as expressly
+provided under this License. Any attempt otherwise to propagate or
+modify it is void, and will automatically terminate your rights under
+this License (including any patent licenses granted under the third
+paragraph of section 11).
+
+ However, if you cease all violation of this License, then your
+license from a particular copyright holder is reinstated (a)
+provisionally, unless and until the copyright holder explicitly and
+finally terminates your license, and (b) permanently, if the copyright
+holder fails to notify you of the violation by some reasonable means
+prior to 60 days after the cessation.
+
+ Moreover, your license from a particular copyright holder is
+reinstated permanently if the copyright holder notifies you of the
+violation by some reasonable means, this is the first time you have
+received notice of violation of this License (for any work) from that
+copyright holder, and you cure the violation prior to 30 days after
+your receipt of the notice.
+
+ Termination of your rights under this section does not terminate the
+licenses of parties who have received copies or rights from you under
+this License. If your rights have been terminated and not permanently
+reinstated, you do not qualify to receive new licenses for the same
+material under section 10.
+
+ 9. Acceptance Not Required for Having Copies.
+
+ You are not required to accept this License in order to receive or
+run a copy of the Program. Ancillary propagation of a covered work
+occurring solely as a consequence of using peer-to-peer transmission
+to receive a copy likewise does not require acceptance. However,
+nothing other than this License grants you permission to propagate or
+modify any covered work. These actions infringe copyright if you do
+not accept this License. Therefore, by modifying or propagating a
+covered work, you indicate your acceptance of this License to do so.
+
+ 10. Automatic Licensing of Downstream Recipients.
+
+ Each time you convey a covered work, the recipient automatically
+receives a license from the original licensors, to run, modify and
+propagate that work, subject to this License. You are not responsible
+for enforcing compliance by third parties with this License.
+
+ An "entity transaction" is a transaction transferring control of an
+organization, or substantially all assets of one, or subdividing an
+organization, or merging organizations. If propagation of a covered
+work results from an entity transaction, each party to that
+transaction who receives a copy of the work also receives whatever
+licenses to the work the party's predecessor in interest had or could
+give under the previous paragraph, plus a right to possession of the
+Corresponding Source of the work from the predecessor in interest, if
+the predecessor has it or can get it with reasonable efforts.
+
+ You may not impose any further restrictions on the exercise of the
+rights granted or affirmed under this License. For example, you may
+not impose a license fee, royalty, or other charge for exercise of
+rights granted under this License, and you may not initiate litigation
+(including a cross-claim or counterclaim in a lawsuit) alleging that
+any patent claim is infringed by making, using, selling, offering for
+sale, or importing the Program or any portion of it.
+
+ 11. Patents.
+
+ A "contributor" is a copyright holder who authorizes use under this
+License of the Program or a work on which the Program is based. The
+work thus licensed is called the contributor's "contributor version".
+
+ A contributor's "essential patent claims" are all patent claims
+owned or controlled by the contributor, whether already acquired or
+hereafter acquired, that would be infringed by some manner, permitted
+by this License, of making, using, or selling its contributor version,
+but do not include claims that would be infringed only as a
+consequence of further modification of the contributor version. For
+purposes of this definition, "control" includes the right to grant
+patent sublicenses in a manner consistent with the requirements of
+this License.
+
+ Each contributor grants you a non-exclusive, worldwide, royalty-free
+patent license under the contributor's essential patent claims, to
+make, use, sell, offer for sale, import and otherwise run, modify and
+propagate the contents of its contributor version.
+
+ In the following three paragraphs, a "patent license" is any express
+agreement or commitment, however denominated, not to enforce a patent
+(such as an express permission to practice a patent or covenant not to
+sue for patent infringement). To "grant" such a patent license to a
+party means to make such an agreement or commitment not to enforce a
+patent against the party.
+
+ If you convey a covered work, knowingly relying on a patent license,
+and the Corresponding Source of the work is not available for anyone
+to copy, free of charge and under the terms of this License, through a
+publicly available network server or other readily accessible means,
+then you must either (1) cause the Corresponding Source to be so
+available, or (2) arrange to deprive yourself of the benefit of the
+patent license for this particular work, or (3) arrange, in a manner
+consistent with the requirements of this License, to extend the patent
+license to downstream recipients. "Knowingly relying" means you have
+actual knowledge that, but for the patent license, your conveying the
+covered work in a country, or your recipient's use of the covered work
+in a country, would infringe one or more identifiable patents in that
+country that you have reason to believe are valid.
+
+ If, pursuant to or in connection with a single transaction or
+arrangement, you convey, or propagate by procuring conveyance of, a
+covered work, and grant a patent license to some of the parties
+receiving the covered work authorizing them to use, propagate, modify
+or convey a specific copy of the covered work, then the patent license
+you grant is automatically extended to all recipients of the covered
+work and works based on it.
+
+ A patent license is "discriminatory" if it does not include within
+the scope of its coverage, prohibits the exercise of, or is
+conditioned on the non-exercise of one or more of the rights that are
+specifically granted under this License. You may not convey a covered
+work if you are a party to an arrangement with a third party that is
+in the business of distributing software, under which you make payment
+to the third party based on the extent of your activity of conveying
+the work, and under which the third party grants, to any of the
+parties who would receive the covered work from you, a discriminatory
+patent license (a) in connection with copies of the covered work
+conveyed by you (or copies made from those copies), or (b) primarily
+for and in connection with specific products or compilations that
+contain the covered work, unless you entered into that arrangement,
+or that patent license was granted, prior to 28 March 2007.
+
+ Nothing in this License shall be construed as excluding or limiting
+any implied license or other defenses to infringement that may
+otherwise be available to you under applicable patent law.
+
+ 12. No Surrender of Others' Freedom.
+
+ If conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot convey a
+covered work so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you may
+not convey it at all. For example, if you agree to terms that obligate you
+to collect a royalty for further conveying from those to whom you convey
+the Program, the only way you could satisfy both those terms and this
+License would be to refrain entirely from conveying the Program.
+
+ 13. Use with the GNU Affero General Public License.
+
+ Notwithstanding any other provision of this License, you have
+permission to link or combine any covered work with a work licensed
+under version 3 of the GNU Affero General Public License into a single
+combined work, and to convey the resulting work. The terms of this
+License will continue to apply to the part which is the covered work,
+but the special requirements of the GNU Affero General Public License,
+section 13, concerning interaction through a network will apply to the
+combination as such.
+
+ 14. Revised Versions of this License.
+
+ The Free Software Foundation may publish revised and/or new versions of
+the GNU 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
+Program specifies that a certain numbered version of the GNU General
+Public License "or any later version" applies to it, you have the
+option of following the terms and conditions either of that numbered
+version or of any later version published by the Free Software
+Foundation. If the Program does not specify a version number of the
+GNU General Public License, you may choose any version ever published
+by the Free Software Foundation.
+
+ If the Program specifies that a proxy can decide which future
+versions of the GNU General Public License can be used, that proxy's
+public statement of acceptance of a version permanently authorizes you
+to choose that version for the Program.
+
+ Later license versions may give you additional or different
+permissions. However, no additional obligations are imposed on any
+author or copyright holder as a result of your choosing to follow a
+later version.
+
+ 15. Disclaimer of Warranty.
+
+ THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
+APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
+HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
+OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
+IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
+ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+ 16. Limitation of Liability.
+
+ IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
+THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
+GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
+USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
+DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
+PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
+EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGES.
+
+ 17. Interpretation of Sections 15 and 16.
+
+ If the disclaimer of warranty and limitation of liability provided
+above cannot be given local legal effect according to their terms,
+reviewing courts shall apply local law that most closely approximates
+an absolute waiver of all civil liability in connection with the
+Program, unless a warranty or assumption of liability accompanies a
+copy of the Program in return for a fee.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+state the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+ {one line to give the program's name and a brief idea of what it does.}
+ Copyright (C) {year} {name of author}
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see .
+
+Also add information on how to contact you by electronic and paper mail.
+
+ If the program does terminal interaction, make it output a short
+notice like this when it starts in an interactive mode:
+
+ {project} Copyright (C) {year} {fullname}
+ This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License. Of course, your program's commands
+might be different; for a GUI interface, you would use an "about box".
+
+ You should also get your employer (if you work as a programmer) or school,
+if any, to sign a "copyright disclaimer" for the program, if necessary.
+For more information on this, and how to apply and follow the GNU GPL, see
+.
+
+ The GNU General Public License does not permit incorporating your program
+into proprietary programs. If your program is a subroutine library, you
+may consider it more useful to permit linking proprietary applications with
+the library. If this is what you want to do, use the GNU Lesser General
+Public License instead of this License. But first, please read
+.
\ No newline at end of file
diff --git a/README.md b/README.md
new file mode 100644
index 00000000..4aa3d4f1
--- /dev/null
+++ b/README.md
@@ -0,0 +1,4 @@
+### BlockUI
+
+An XML based UI management system for minecraft.
+Defines the structure for the UI inside an XML while providing a backing "Window" class that is used to handle callbacks and data supply.
diff --git a/build.gradle b/build.gradle
new file mode 100644
index 00000000..9e30c595
--- /dev/null
+++ b/build.gradle
@@ -0,0 +1,17 @@
+buildscript {
+ repositories {
+ maven { url = 'https://files.minecraftforge.net/maven' }
+ mavenLocal()
+ mavenCentral()
+ maven {
+ url "https://plugins.gradle.org/m2/"
+ }
+ }
+ dependencies {
+ classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '5.1.+', changing: true
+ }
+}
+
+//apply from: 'https://raw.githubusercontent.com/ldtteam/OperaPublicaCreator/main/gradle/mod.gradle'
+apply from: 'D:\\Java\\Modding\\OperaPublicaCreator\\gradle\\mod.gradle'
+project.getLogger().lifecycle("Loaded remote build.gradle with version: " + project.modVersion)
\ No newline at end of file
diff --git a/gradle.properties b/gradle.properties
new file mode 100644
index 00000000..071f0f98
--- /dev/null
+++ b/gradle.properties
@@ -0,0 +1,34 @@
+org.gradle.jvmargs=-Xmx3G
+org.gradle.daemon=false
+
+modId=blockui
+modGroup=com.ldtteam
+modVersion=0.0.1-LOCAL
+modBaseName=blockui
+
+javaVersion=16
+useJavaToolChains=true
+
+#The currently running forge.
+forgeVersion=37.0.7
+#The minimal needed forge, as marked in metadata and curseforge.
+forgeMinVersion=37.0.7
+
+#The version for forge (dependency)
+exactMinecraftVersion=1.17.1
+#The main version on curseforge
+minecraftVersion=1.17.1
+#Comma seperated list of mc versions, which are marked as compatible on curseforge
+additionalMinecraftVersions=1.17.1
+
+mappingsChannel=official
+mappingsVersion=1.17.1
+
+githubUrl=https://github.com/ldtteam/BlockUI
+gitUrl=https://github.com/ldtteam/BlockUI.git
+gitConnectUrl=https://github.com/ldtteam/BlockUI.git
+projectUrl=https://github.com/ldtteam/BlockUI
+
+useDefaultTestSystem=false
+runtimeSourceSets=test;main
+projectHasApi=false
\ No newline at end of file
diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar
new file mode 100644
index 00000000..7454180f
Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
new file mode 100644
index 00000000..05679dc3
--- /dev/null
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -0,0 +1,5 @@
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+distributionUrl=https\://services.gradle.org/distributions/gradle-7.1.1-bin.zip
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
diff --git a/gradlew b/gradlew
new file mode 100644
index 00000000..744e882e
--- /dev/null
+++ b/gradlew
@@ -0,0 +1,185 @@
+#!/usr/bin/env sh
+
+#
+# Copyright 2015 the original author or authors.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+##############################################################################
+##
+## Gradle start up script for UN*X
+##
+##############################################################################
+
+# Attempt to set APP_HOME
+# Resolve links: $0 may be a link
+PRG="$0"
+# Need this for relative symlinks.
+while [ -h "$PRG" ] ; do
+ ls=`ls -ld "$PRG"`
+ link=`expr "$ls" : '.*-> \(.*\)$'`
+ if expr "$link" : '/.*' > /dev/null; then
+ PRG="$link"
+ else
+ PRG=`dirname "$PRG"`"/$link"
+ fi
+done
+SAVED="`pwd`"
+cd "`dirname \"$PRG\"`/" >/dev/null
+APP_HOME="`pwd -P`"
+cd "$SAVED" >/dev/null
+
+APP_NAME="Gradle"
+APP_BASE_NAME=`basename "$0"`
+
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
+
+# Use the maximum available, or set MAX_FD != -1 to use that value.
+MAX_FD="maximum"
+
+warn () {
+ echo "$*"
+}
+
+die () {
+ echo
+ echo "$*"
+ echo
+ exit 1
+}
+
+# OS specific support (must be 'true' or 'false').
+cygwin=false
+msys=false
+darwin=false
+nonstop=false
+case "`uname`" in
+ CYGWIN* )
+ cygwin=true
+ ;;
+ Darwin* )
+ darwin=true
+ ;;
+ MSYS* | MINGW* )
+ msys=true
+ ;;
+ NONSTOP* )
+ nonstop=true
+ ;;
+esac
+
+CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
+
+
+# Determine the Java command to use to start the JVM.
+if [ -n "$JAVA_HOME" ] ; then
+ if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+ # IBM's JDK on AIX uses strange locations for the executables
+ JAVACMD="$JAVA_HOME/jre/sh/java"
+ else
+ JAVACMD="$JAVA_HOME/bin/java"
+ fi
+ if [ ! -x "$JAVACMD" ] ; then
+ die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+ fi
+else
+ JAVACMD="java"
+ which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+fi
+
+# Increase the maximum file descriptors if we can.
+if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
+ MAX_FD_LIMIT=`ulimit -H -n`
+ if [ $? -eq 0 ] ; then
+ if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
+ MAX_FD="$MAX_FD_LIMIT"
+ fi
+ ulimit -n $MAX_FD
+ if [ $? -ne 0 ] ; then
+ warn "Could not set maximum file descriptor limit: $MAX_FD"
+ fi
+ else
+ warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
+ fi
+fi
+
+# For Darwin, add options to specify how the application appears in the dock
+if $darwin; then
+ GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
+fi
+
+# For Cygwin or MSYS, switch paths to Windows format before running java
+if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
+ APP_HOME=`cygpath --path --mixed "$APP_HOME"`
+ CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
+
+ JAVACMD=`cygpath --unix "$JAVACMD"`
+
+ # We build the pattern for arguments to be converted via cygpath
+ ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
+ SEP=""
+ for dir in $ROOTDIRSRAW ; do
+ ROOTDIRS="$ROOTDIRS$SEP$dir"
+ SEP="|"
+ done
+ OURCYGPATTERN="(^($ROOTDIRS))"
+ # Add a user-defined pattern to the cygpath arguments
+ if [ "$GRADLE_CYGPATTERN" != "" ] ; then
+ OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
+ fi
+ # Now convert the arguments - kludge to limit ourselves to /bin/sh
+ i=0
+ for arg in "$@" ; do
+ CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
+ CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
+
+ if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
+ eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
+ else
+ eval `echo args$i`="\"$arg\""
+ fi
+ i=`expr $i + 1`
+ done
+ case $i in
+ 0) set -- ;;
+ 1) set -- "$args0" ;;
+ 2) set -- "$args0" "$args1" ;;
+ 3) set -- "$args0" "$args1" "$args2" ;;
+ 4) set -- "$args0" "$args1" "$args2" "$args3" ;;
+ 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
+ 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
+ 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
+ 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
+ 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
+ esac
+fi
+
+# Escape application args
+save () {
+ for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
+ echo " "
+}
+APP_ARGS=`save "$@"`
+
+# Collect all arguments for the java command, following the shell quoting and substitution rules
+eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
+
+exec "$JAVACMD" "$@"
diff --git a/gradlew.bat b/gradlew.bat
new file mode 100644
index 00000000..107acd32
--- /dev/null
+++ b/gradlew.bat
@@ -0,0 +1,89 @@
+@rem
+@rem Copyright 2015 the original author or authors.
+@rem
+@rem Licensed under the Apache License, Version 2.0 (the "License");
+@rem you may not use this file except in compliance with the License.
+@rem You may obtain a copy of the License at
+@rem
+@rem https://www.apache.org/licenses/LICENSE-2.0
+@rem
+@rem Unless required by applicable law or agreed to in writing, software
+@rem distributed under the License is distributed on an "AS IS" BASIS,
+@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+@rem See the License for the specific language governing permissions and
+@rem limitations under the License.
+@rem
+
+@if "%DEBUG%" == "" @echo off
+@rem ##########################################################################
+@rem
+@rem Gradle startup script for Windows
+@rem
+@rem ##########################################################################
+
+@rem Set local scope for the variables with windows NT shell
+if "%OS%"=="Windows_NT" setlocal
+
+set DIRNAME=%~dp0
+if "%DIRNAME%" == "" set DIRNAME=.
+set APP_BASE_NAME=%~n0
+set APP_HOME=%DIRNAME%
+
+@rem Resolve any "." and ".." in APP_HOME to make it shorter.
+for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
+
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
+
+@rem Find java.exe
+if defined JAVA_HOME goto findJavaFromJavaHome
+
+set JAVA_EXE=java.exe
+%JAVA_EXE% -version >NUL 2>&1
+if "%ERRORLEVEL%" == "0" goto execute
+
+echo.
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:findJavaFromJavaHome
+set JAVA_HOME=%JAVA_HOME:"=%
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe
+
+if exist "%JAVA_EXE%" goto execute
+
+echo.
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:execute
+@rem Setup the command line
+
+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
+
+
+@rem Execute Gradle
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
+
+:end
+@rem End local scope for the variables with windows NT shell
+if "%ERRORLEVEL%"=="0" goto mainEnd
+
+:fail
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
+rem the _cmd.exe /c_ return code!
+if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
+exit /b 1
+
+:mainEnd
+if "%OS%"=="Windows_NT" endlocal
+
+:omega
diff --git a/src/main/java/com/ldtteam/blockui/Alignment.java b/src/main/java/com/ldtteam/blockui/Alignment.java
new file mode 100644
index 00000000..c5492077
--- /dev/null
+++ b/src/main/java/com/ldtteam/blockui/Alignment.java
@@ -0,0 +1,55 @@
+package com.ldtteam.blockui;
+
+/**
+ * Alignment enum which can be used to different levels of alignment.
+ */
+public enum Alignment
+{
+ // RelativePosition determines how the x,y coordinates of an item are relative
+ // to the position of the parent. Corner to matching corner
+ // E.g, TopLeft x,y is from top left corner of parent to top left of item
+ // while BOTTOM_RIGHT is from bottom right corner of parent to bottom right of item
+ // Do not use negative values; BOTTOM_RIGHT(10,10) is 10 pixels inset left and up.
+ TOP_LEFT("top left"),
+ TOP_MIDDLE("top horizontal"),
+ TOP_RIGHT("top right"),
+ MIDDLE_LEFT("vertical left"),
+ MIDDLE("vertical horizontal"),
+ MIDDLE_RIGHT("vertical right"),
+ BOTTOM_LEFT("bottom left"),
+ BOTTOM_MIDDLE("bottom horizontal"),
+ BOTTOM_RIGHT("bottom right");
+
+ private final boolean rightAligned;
+ private final boolean bottomAligned;
+ private final boolean horizontalCentered;
+ private final boolean verticalCentered;
+
+ Alignment(final String attributes)
+ {
+ rightAligned = attributes.contains("right");
+ bottomAligned = attributes.contains("bottom");
+ horizontalCentered = attributes.contains("horizontal");
+ verticalCentered = attributes.contains("vertical");
+ }
+
+ public boolean isRightAligned()
+ {
+ return rightAligned;
+ }
+
+ public boolean isBottomAligned()
+ {
+ return bottomAligned;
+ }
+
+ public boolean isHorizontalCentered()
+ {
+ return horizontalCentered;
+ }
+
+ public boolean isVerticalCentered()
+ {
+ return verticalCentered;
+ }
+}
diff --git a/src/main/java/com/ldtteam/blockui/BOScreen.java b/src/main/java/com/ldtteam/blockui/BOScreen.java
new file mode 100644
index 00000000..83a7c32c
--- /dev/null
+++ b/src/main/java/com/ldtteam/blockui/BOScreen.java
@@ -0,0 +1,288 @@
+package com.ldtteam.blockui;
+
+import com.ldtteam.blockui.views.Window;
+import com.mojang.blaze3d.vertex.PoseStack;
+import com.mojang.blaze3d.systems.RenderSystem;
+import com.mojang.math.Matrix4f;
+import net.minecraft.client.Minecraft;
+import net.minecraft.client.gui.screens.Screen;
+import net.minecraft.util.BitStorage;
+import net.minecraft.network.chat.TextComponent;
+import org.lwjgl.glfw.GLFW;
+
+/**
+ * Wraps MineCrafts GuiScreen for BlockOut's Window.
+ */
+public class BOScreen extends Screen
+{
+ protected double renderScale = 1.0d;
+ protected double mcScale = 1.0d;
+ protected Window window;
+ protected double x = 0;
+ protected double y = 0;
+ public static boolean isMouseLeftDown = false;
+ protected boolean isOpen = false;
+ private static final BitStorage ACCEPTED_KEY_PRESSED_MAP = new BitStorage(1, GLFW.GLFW_KEY_LAST + 1);
+
+ static
+ {
+ ACCEPTED_KEY_PRESSED_MAP.set(GLFW.GLFW_KEY_A, 1);
+ ACCEPTED_KEY_PRESSED_MAP.set(GLFW.GLFW_KEY_C, 1);
+ ACCEPTED_KEY_PRESSED_MAP.set(GLFW.GLFW_KEY_V, 1);
+ ACCEPTED_KEY_PRESSED_MAP.set(GLFW.GLFW_KEY_X, 1);
+ ACCEPTED_KEY_PRESSED_MAP.set(GLFW.GLFW_KEY_ESCAPE, 1);
+ ACCEPTED_KEY_PRESSED_MAP.set(GLFW.GLFW_KEY_ENTER, 1);
+ ACCEPTED_KEY_PRESSED_MAP.set(GLFW.GLFW_KEY_TAB, 1);
+ ACCEPTED_KEY_PRESSED_MAP.set(GLFW.GLFW_KEY_BACKSPACE, 1);
+ ACCEPTED_KEY_PRESSED_MAP.set(GLFW.GLFW_KEY_INSERT, 1);
+ ACCEPTED_KEY_PRESSED_MAP.set(GLFW.GLFW_KEY_DELETE, 1);
+ ACCEPTED_KEY_PRESSED_MAP.set(GLFW.GLFW_KEY_RIGHT, 1);
+ ACCEPTED_KEY_PRESSED_MAP.set(GLFW.GLFW_KEY_LEFT, 1);
+ ACCEPTED_KEY_PRESSED_MAP.set(GLFW.GLFW_KEY_DOWN, 1);
+ ACCEPTED_KEY_PRESSED_MAP.set(GLFW.GLFW_KEY_UP, 1);
+ ACCEPTED_KEY_PRESSED_MAP.set(GLFW.GLFW_KEY_PAGE_UP, 1);
+ ACCEPTED_KEY_PRESSED_MAP.set(GLFW.GLFW_KEY_PAGE_DOWN, 1);
+ ACCEPTED_KEY_PRESSED_MAP.set(GLFW.GLFW_KEY_HOME, 1);
+ ACCEPTED_KEY_PRESSED_MAP.set(GLFW.GLFW_KEY_END, 1);
+ ACCEPTED_KEY_PRESSED_MAP.set(GLFW.GLFW_KEY_CAPS_LOCK, 0);
+ ACCEPTED_KEY_PRESSED_MAP.set(GLFW.GLFW_KEY_SCROLL_LOCK, 0);
+ ACCEPTED_KEY_PRESSED_MAP.set(GLFW.GLFW_KEY_NUM_LOCK, 0);
+ ACCEPTED_KEY_PRESSED_MAP.set(GLFW.GLFW_KEY_PRINT_SCREEN, 0);
+ ACCEPTED_KEY_PRESSED_MAP.set(GLFW.GLFW_KEY_PAUSE, 0);
+ ACCEPTED_KEY_PRESSED_MAP.set(GLFW.GLFW_KEY_F1, 1);
+ ACCEPTED_KEY_PRESSED_MAP.set(GLFW.GLFW_KEY_F2, 1);
+ ACCEPTED_KEY_PRESSED_MAP.set(GLFW.GLFW_KEY_F3, 1);
+ ACCEPTED_KEY_PRESSED_MAP.set(GLFW.GLFW_KEY_F4, 1);
+ ACCEPTED_KEY_PRESSED_MAP.set(GLFW.GLFW_KEY_F5, 1);
+ ACCEPTED_KEY_PRESSED_MAP.set(GLFW.GLFW_KEY_F6, 1);
+ ACCEPTED_KEY_PRESSED_MAP.set(GLFW.GLFW_KEY_F7, 1);
+ ACCEPTED_KEY_PRESSED_MAP.set(GLFW.GLFW_KEY_F8, 1);
+ ACCEPTED_KEY_PRESSED_MAP.set(GLFW.GLFW_KEY_F9, 1);
+ ACCEPTED_KEY_PRESSED_MAP.set(GLFW.GLFW_KEY_F10, 1);
+ ACCEPTED_KEY_PRESSED_MAP.set(GLFW.GLFW_KEY_F11, 1);
+ ACCEPTED_KEY_PRESSED_MAP.set(GLFW.GLFW_KEY_F12, 1);
+ ACCEPTED_KEY_PRESSED_MAP.set(GLFW.GLFW_KEY_F13, 0);
+ ACCEPTED_KEY_PRESSED_MAP.set(GLFW.GLFW_KEY_F14, 0);
+ ACCEPTED_KEY_PRESSED_MAP.set(GLFW.GLFW_KEY_F15, 0);
+ ACCEPTED_KEY_PRESSED_MAP.set(GLFW.GLFW_KEY_F16, 0);
+ ACCEPTED_KEY_PRESSED_MAP.set(GLFW.GLFW_KEY_F17, 0);
+ ACCEPTED_KEY_PRESSED_MAP.set(GLFW.GLFW_KEY_F18, 0);
+ ACCEPTED_KEY_PRESSED_MAP.set(GLFW.GLFW_KEY_F19, 0);
+ ACCEPTED_KEY_PRESSED_MAP.set(GLFW.GLFW_KEY_F20, 0);
+ ACCEPTED_KEY_PRESSED_MAP.set(GLFW.GLFW_KEY_F21, 0);
+ ACCEPTED_KEY_PRESSED_MAP.set(GLFW.GLFW_KEY_F22, 0);
+ ACCEPTED_KEY_PRESSED_MAP.set(GLFW.GLFW_KEY_F23, 0);
+ ACCEPTED_KEY_PRESSED_MAP.set(GLFW.GLFW_KEY_F24, 0);
+ ACCEPTED_KEY_PRESSED_MAP.set(GLFW.GLFW_KEY_F25, 0);
+ ACCEPTED_KEY_PRESSED_MAP.set(GLFW.GLFW_KEY_KP_0, 0);
+ ACCEPTED_KEY_PRESSED_MAP.set(GLFW.GLFW_KEY_KP_1, 0);
+ ACCEPTED_KEY_PRESSED_MAP.set(GLFW.GLFW_KEY_KP_2, 0);
+ ACCEPTED_KEY_PRESSED_MAP.set(GLFW.GLFW_KEY_KP_3, 0);
+ ACCEPTED_KEY_PRESSED_MAP.set(GLFW.GLFW_KEY_KP_4, 0);
+ ACCEPTED_KEY_PRESSED_MAP.set(GLFW.GLFW_KEY_KP_5, 0);
+ ACCEPTED_KEY_PRESSED_MAP.set(GLFW.GLFW_KEY_KP_6, 0);
+ ACCEPTED_KEY_PRESSED_MAP.set(GLFW.GLFW_KEY_KP_7, 0);
+ ACCEPTED_KEY_PRESSED_MAP.set(GLFW.GLFW_KEY_KP_8, 0);
+ ACCEPTED_KEY_PRESSED_MAP.set(GLFW.GLFW_KEY_KP_9, 0);
+ ACCEPTED_KEY_PRESSED_MAP.set(GLFW.GLFW_KEY_KP_DECIMAL, 0);
+ ACCEPTED_KEY_PRESSED_MAP.set(GLFW.GLFW_KEY_KP_DIVIDE, 0);
+ ACCEPTED_KEY_PRESSED_MAP.set(GLFW.GLFW_KEY_KP_MULTIPLY, 0);
+ ACCEPTED_KEY_PRESSED_MAP.set(GLFW.GLFW_KEY_KP_SUBTRACT, 0);
+ ACCEPTED_KEY_PRESSED_MAP.set(GLFW.GLFW_KEY_KP_ADD, 0);
+ ACCEPTED_KEY_PRESSED_MAP.set(GLFW.GLFW_KEY_KP_ENTER, 1);
+ ACCEPTED_KEY_PRESSED_MAP.set(GLFW.GLFW_KEY_KP_EQUAL, 0);
+ ACCEPTED_KEY_PRESSED_MAP.set(GLFW.GLFW_KEY_LEFT_SHIFT, 0);
+ ACCEPTED_KEY_PRESSED_MAP.set(GLFW.GLFW_KEY_LEFT_CONTROL, 0);
+ ACCEPTED_KEY_PRESSED_MAP.set(GLFW.GLFW_KEY_LEFT_ALT, 0);
+ ACCEPTED_KEY_PRESSED_MAP.set(GLFW.GLFW_KEY_LEFT_SUPER, 0);
+ ACCEPTED_KEY_PRESSED_MAP.set(GLFW.GLFW_KEY_RIGHT_SHIFT, 0);
+ ACCEPTED_KEY_PRESSED_MAP.set(GLFW.GLFW_KEY_RIGHT_CONTROL, 0);
+ ACCEPTED_KEY_PRESSED_MAP.set(GLFW.GLFW_KEY_RIGHT_ALT, 0);
+ ACCEPTED_KEY_PRESSED_MAP.set(GLFW.GLFW_KEY_RIGHT_SUPER, 0);
+ ACCEPTED_KEY_PRESSED_MAP.set(GLFW.GLFW_KEY_MENU, 1);
+ }
+
+ /**
+ * Create a GuiScreen from a BlockOut window.
+ *
+ * @param w blockout window.
+ */
+ public BOScreen(final Window w)
+ {
+ super(new TextComponent("Blockout GUI"));
+ window = w;
+ }
+
+ @Override
+ public void render(final PoseStack ms, final int mx, final int my, final float f)
+ {
+ if (minecraft == null || !isOpen) // should never happen though
+ {
+ return;
+ }
+
+ final double fbWidth = minecraft.getWindow().getWidth();
+ final double fbHeight = minecraft.getWindow().getHeight();
+ final double guiWidth = Math.max(fbWidth, 320.0d);
+ final double guiHeight = Math.max(fbHeight, 240.0d);
+
+ final float renderZlevel = MatrixUtils.getLastMatrixTranslateZ(ms);
+ final float oldZ = minecraft.getItemRenderer().blitOffset;
+ minecraft.getItemRenderer().blitOffset = renderZlevel;
+
+ mcScale = minecraft.getWindow().getGuiScale();
+ renderScale = window.getRenderType().calcRenderScale(minecraft.getWindow(), window);
+
+ if (window.hasLightbox())
+ {
+ width = (int) fbWidth;
+ height = (int) fbHeight;
+ super.renderBackground(ms);
+ }
+
+ width = window.getWidth();
+ height = window.getHeight();
+ x = Math.floor((guiWidth - width * renderScale) / 2.0d);
+ y = Math.floor((guiHeight - height * renderScale) / 2.0d);
+
+ // replace vanilla projection
+ Matrix4f ourOrtho = Matrix4f.orthographic(0.0F, (float)fbWidth, 0.0F, (float)fbHeight, 1000.0F, 3000.0F);
+ RenderSystem.setProjectionMatrix(ourOrtho);
+
+ final PoseStack newMs = new PoseStack();
+ newMs.translate(x, y, renderZlevel);
+ newMs.scale((float) renderScale, (float) renderScale, 1.0f);
+ window.draw(newMs, calcRelativeX(mx), calcRelativeY(my));
+ window.drawLast(newMs, calcRelativeX(mx), calcRelativeY(my));
+ newMs.popPose();
+
+ // restore vanilla state
+ Matrix4f theirOrtho = Matrix4f.orthographic(0.0F, (float)((double)Minecraft.getInstance().getWindow().getWidth() / Minecraft.getInstance().getWindow().getGuiScale()), 0.0F, (float)((double)Minecraft.getInstance().getWindow().getHeight() / Minecraft.getInstance().getWindow().getGuiScale()), 1000.0F, 3000.0F);
+ RenderSystem.setProjectionMatrix(theirOrtho);
+
+ minecraft.getItemRenderer().blitOffset = oldZ;
+ }
+
+ @Override
+ public boolean keyPressed(final int key, final int scanCode, final int modifiers)
+ {
+ // keys without printable representation
+ if (key >= 0 && key <= GLFW.GLFW_KEY_LAST)
+ {
+ return ACCEPTED_KEY_PRESSED_MAP.get(key) == 0 || window.onKeyTyped('\0', key);
+ }
+ return false;
+ }
+
+ @Override
+ public boolean charTyped(final char ch, final int key)
+ {
+ return window.onKeyTyped(ch, key);
+ }
+
+ @Override
+ public boolean mouseClicked(final double mxIn, final double myIn, final int keyCode)
+ {
+ final double mx = calcRelativeX(mxIn);
+ final double my = calcRelativeY(myIn);
+ if (keyCode == GLFW.GLFW_MOUSE_BUTTON_LEFT)
+ {
+ // Adjust coordinate to origin of window
+ isMouseLeftDown = true;
+ return window.click(mx, my);
+ }
+ else if (keyCode == GLFW.GLFW_MOUSE_BUTTON_RIGHT)
+ {
+ return window.rightClick(mx, my);
+ }
+ return false;
+ }
+
+ @Override
+ public boolean mouseScrolled(final double mx, final double my, final double scrollDiff)
+ {
+ if (scrollDiff != 0)
+ {
+ return window.scrollInput(scrollDiff * 10, calcRelativeX(mx), calcRelativeY(my));
+ }
+ return false;
+ }
+
+ @Override
+ public boolean mouseDragged(final double xIn, final double yIn, final int speed, final double deltaX, final double deltaY)
+ {
+ return window.onMouseDrag(calcRelativeX(xIn), calcRelativeY(yIn), speed, deltaX, deltaY);
+ }
+
+ @Override
+ public boolean mouseReleased(final double mxIn, final double myIn, final int keyCode)
+ {
+ if (keyCode == GLFW.GLFW_MOUSE_BUTTON_LEFT)
+ {
+ // Adjust coordinate to origin of window
+ isMouseLeftDown = false;
+ return window.onMouseReleased(calcRelativeX(mxIn), calcRelativeY(myIn));
+ }
+ return false;
+ }
+
+ @Override
+ public void init()
+ {
+ minecraft.keyboardHandler.setSendRepeatsToGui(true);
+ //TODO: Disable crosshair. Might not be possible anymore or might need an event
+ }
+
+ @Override
+ public void tick()
+ {
+ if (minecraft != null)
+ {
+ if (!isOpen)
+ {
+ window.onOpened();
+ isOpen = true;
+ }
+ else
+ {
+ window.onUpdate();
+
+ if (!minecraft.player.isAlive() || minecraft.player.dead)
+ {
+ minecraft.player.closeContainer();
+ }
+ }
+ }
+ }
+
+ @Override
+ public void removed()
+ {
+ window.onClosed();
+ Window.clearFocus();
+ minecraft.keyboardHandler.setSendRepeatsToGui(false);
+ //TODO: See Above (init)
+ }
+
+ @Override
+ public boolean isPauseScreen()
+ {
+ return window.doesWindowPauseGame();
+ }
+
+ /**
+ * Converts X from event to unscaled and unscrolled X for child in relative (top-left) coordinates.
+ */
+ private double calcRelativeX(final double xIn)
+ {
+ return (xIn * mcScale - x) / renderScale;
+ }
+
+ /**
+ * Converts Y from event to unscaled and unscrolled Y for child in relative (top-left) coordinates.
+ */
+ private double calcRelativeY(final double yIn)
+ {
+ return (yIn * mcScale - y) / renderScale;
+ }
+}
diff --git a/src/main/java/com/ldtteam/blockui/Color.java b/src/main/java/com/ldtteam/blockui/Color.java
new file mode 100644
index 00000000..6236a470
--- /dev/null
+++ b/src/main/java/com/ldtteam/blockui/Color.java
@@ -0,0 +1,112 @@
+package com.ldtteam.blockui;
+
+import net.minecraft.util.Mth;
+
+import javax.annotation.Nullable;
+import java.util.HashMap;
+import java.util.Locale;
+import java.util.Map;
+import java.util.regex.Matcher;
+
+/**
+ * Color utility methods.
+ */
+public final class Color
+{
+ private static final Map nameToColorMap = new HashMap<>();
+ static
+ {
+ // Would love to load these from a file
+ nameToColorMap.put("aqua", 0x00FFFF);
+ nameToColorMap.put("black", 0x000000);
+ nameToColorMap.put("blue", 0x0000FF);
+ nameToColorMap.put("cyan", 0x00FFFF);
+ nameToColorMap.put("fuchsia", 0xFF00FF);
+ nameToColorMap.put("green", 0x008000);
+ nameToColorMap.put("ivory", 0xFFFFF0);
+ nameToColorMap.put("lime", 0x00FF00);
+ nameToColorMap.put("magenta", 0xFF00FF);
+ nameToColorMap.put("orange", 0xFFA500);
+ nameToColorMap.put("orangered", 0xFF4500);
+ nameToColorMap.put("purple", 0x800080);
+ nameToColorMap.put("red", 0xFF0000);
+ nameToColorMap.put("white", 0xFFFFFF);
+ nameToColorMap.put("yellow", 0xFFFF00);
+ nameToColorMap.put("gray", 0x808080);
+ nameToColorMap.put("darkgray", 0xA9A9A9);
+ nameToColorMap.put("dimgray", 0x696969);
+ nameToColorMap.put("lightgray", 0xD3D3D3);
+ nameToColorMap.put("slategray", 0x708090);
+ nameToColorMap.put("darkgreen", 0x006400);
+ }
+
+ private Color()
+ {
+ // Hides default constructor.
+ }
+
+ /**
+ * Parses a color or returns the default
+ * @param color a string representation of the color, in rgba, hex, or int
+ * @param def the fallback value
+ * @return the parsed or defaulted color integer
+ */
+ public static int parse(String color, int def)
+ {
+ Integer result = Parsers.COLOR.apply(color);
+ return result != null ? result : def;
+ }
+
+ /**
+ * Get a color integer from its name.
+ *
+ * @param name name of the color.
+ * @param def default to use if the name doesn't exist.
+ * @return the color as an integer.
+ */
+ public static int getByName(final String name, final int def)
+ {
+ final Integer i = nameToColorMap.get(name.toLowerCase(Locale.ENGLISH));
+ return i != null ? i : def;
+ }
+
+ /**
+ * Get a color integer from its name.
+ *
+ * @param name name of the color.
+ * @return the color as an integer.
+ */
+ @Nullable
+ public static Integer getByName(final String name)
+ {
+ return nameToColorMap.get(name.toLowerCase(Locale.ENGLISH));
+ }
+
+ /**
+ * Get the int from rgba.
+ * @param r the red value from 0-255.
+ * @param g the green value from 0-255.
+ * @param b the blue value from 0-255.
+ * @param a the transparency value from 0-255.
+ * @return the accumulated int.
+ */
+ public static int rgbaToInt(final int r, final int g, final int b, final int a)
+ {
+ return ((a & 0xff) << 24) | ((r & 0xff) << 16) | ((g & 0xff) << 8) | (b & 0xff);
+ }
+
+ public static int rgbaToInt(Matcher m)
+ {
+ final int r = Mth.clamp(Integer.parseInt(m.group(1)), 0, 255);
+ final int g = Mth.clamp(Integer.parseInt(m.group(2)), 0, 255);
+ final int b = Mth.clamp(Integer.parseInt(m.group(3)), 0, 255);
+ final int a = Mth.clamp((int)Double.parseDouble(m.group(4))*255,0,255);
+
+ return (a << 24) | (r << 16) | (g << 8) | b;
+ }
+
+ public static net.minecraft.network.chat.TextColor toVanilla(final int color)
+ {
+ return net.minecraft.network.chat.TextColor.fromRgb(color);
+ }
+}
diff --git a/src/main/java/com/ldtteam/blockui/Loader.java b/src/main/java/com/ldtteam/blockui/Loader.java
new file mode 100644
index 00000000..434d04e4
--- /dev/null
+++ b/src/main/java/com/ldtteam/blockui/Loader.java
@@ -0,0 +1,291 @@
+package com.ldtteam.blockui;
+
+import com.ldtteam.blockui.controls.*;
+import com.ldtteam.blockui.views.*;
+import net.minecraft.client.Minecraft;
+import net.minecraft.resources.ResourceLocation;
+import net.minecraft.util.Tuple;
+import net.minecraftforge.api.distmarker.Dist;
+import net.minecraftforge.fml.DistExecutor;
+import org.w3c.dom.Document;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+import javax.annotation.Nullable;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.StringReader;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.function.Function;
+
+/**
+ * Utilities to load xml files.
+ */
+public final class Loader
+{
+ private static final DocumentBuilderFactory DOCUMENT_BUILDER_FACTORY = DocumentBuilderFactory.newInstance();
+
+ private static final Map> paneFactories = new HashMap<>();
+ static
+ {
+ register("view", View::new);
+ register("group", Group::new);
+ register("scrollgroup", ScrollingGroup::new);
+ register("list", ScrollingList::new);
+ register("text", Text::new);
+ register("button", Button::construct);
+ register("buttonimage", Button::construct); // TODO: remove, but we don't want to deal with xml changes now
+ register("toggle", ToggleButton::new);
+ register("label", Text::new); // TODO: remove, but we don't want to deal with xml changes now
+ register("input", TextFieldVanilla::new);
+ register("image", Image::new);
+ register("imagerepeat", ImageRepeatable::new);
+ register("box", Box::new);
+ register("itemicon", ItemIcon::new);
+ register("switch", SwitchView::new);
+ register("dropdown", DropDownList::new);
+ register("overlay", OverlayView::new);
+ register("gradient", Gradient::new);
+ register("zoomdragview", ZoomDragView::new);
+ }
+
+ public static int MAX_CACHE_SIZE = 100;
+
+ /** A map to store the parsed documents. Retains data based on a priority */
+ private static final Map> parsedCache = Collections.synchronizedMap(new HashMap>()
+ {
+ @Override
+ public Tuple get(final Object o)
+ {
+ Tuple me = super.get(o);
+ this.replace((ResourceLocation) o, new Tuple<>(me.getA()+1,me.getB()));
+ return me;
+ }
+ });
+
+ private Loader()
+ {
+ // Hides default constructor.
+ }
+
+ /**
+ * registers an element definition class so it can be used in
+ * gui definition files
+ * @param name the tag name of the element in the definition file
+ * @param factoryMethod the constructor/method to create the element Pane
+ */
+ public static void register(final String name, final Function factoryMethod)
+ {
+ final ResourceLocation key = new ResourceLocation(name);
+
+ if (paneFactories.containsKey(key))
+ {
+ throw new IllegalArgumentException("Duplicate pane type '" + name + "' when registering Pane class method.");
+ }
+
+ paneFactories.put(key, factoryMethod);
+ }
+
+ /**
+ * Uses the loaded parameters to construct a new Pane tree
+ * @param params the parameters for the new pane and its children
+ * @return the created Pane
+ */
+ private static Pane createFromPaneParams(final PaneParams params)
+ {
+ final ResourceLocation paneType = new ResourceLocation(params.getType());
+
+ if (paneFactories.containsKey(paneType))
+ {
+ return paneFactories.get(paneType).apply(params);
+ }
+
+ if (paneFactories.containsKey(new ResourceLocation(paneType.getPath())))
+ {
+ Log.getLogger().warn("Namespace override for " + paneType.getPath() + " not found. Using default.");
+ return paneFactories.get(new ResourceLocation(paneType.getPath())).apply(params);
+ }
+
+ Log.getLogger().error("There is no factory method for " + paneType.getPath());
+ return null;
+ }
+
+ /**
+ * Create a pane from its xml parameters.
+ *
+ * @param params xml parameters.
+ * @param parent parent view.
+ * @return the new pane.
+ */
+ public static Pane createFromPaneParams(final PaneParams params, final View parent)
+ {
+ if ("layout".equalsIgnoreCase(params.getType()))
+ {
+ params.getResource("source", r -> createFromXMLFile(r, parent));
+ return null;
+ }
+
+ if (parent instanceof Window && params.getType().equals("window"))
+ {
+ ((Window) parent).loadParams(params);
+ parent.parseChildren(params);
+ return parent;
+ }
+ else if (parent instanceof View && params.getType().equals("window")) // layout
+ {
+ parent.parseChildren(params);
+ return parent;
+ }
+ else
+ {
+ params.setParentView(parent);
+ final Pane pane = createFromPaneParams(params);
+
+ if (pane != null)
+ {
+ pane.putInside(parent);
+ pane.parseChildren(params);
+ }
+ return pane;
+ }
+ }
+
+ /**
+ * Parse an XML Document into contents for a View.
+ *
+ * @param doc xml document.
+ * @param parent parent view.
+ */
+ private static PaneParams createFromDocument(@Nullable final Document doc, final View parent)
+ {
+ if (doc == null) return null;
+
+ doc.getDocumentElement().normalize();
+
+ final PaneParams root = new PaneParams(doc.getDocumentElement());
+ createFromPaneParams(root, parent);
+ return root;
+ }
+
+ /**
+ * Parse XML from an InputSource into contents for a View.
+ *
+ * @param input xml file.
+ */
+ private static Document parseXML(final InputSource input)
+ {
+ try
+ {
+ final DocumentBuilder dBuilder = DOCUMENT_BUILDER_FACTORY.newDocumentBuilder();
+ final Document doc = dBuilder.parse(input);
+ input.getByteStream().close();
+
+ return doc;
+ }
+ catch (final ParserConfigurationException | SAXException | IOException exc)
+ {
+ Log.getLogger().error("Exception when parsing XML.", exc);
+ }
+
+ return null;
+ }
+
+ /**
+ * Parse an XML String into contents for a View.
+ *
+ * @param xmlString the xml data.
+ * @param parent parent view.
+ */
+ public static void createFromXML(final String xmlString, final View parent)
+ {
+ createFromDocument(parseXML(new InputSource(new StringReader(xmlString))), parent);
+ }
+
+ /**
+ * Parse XML contains in a ResourceLocation into contents for a Window.
+ *
+ * @param filename the xml file.
+ * @param parent parent view.
+ */
+ public static void createFromXMLFile(final String filename, final View parent)
+ {
+ createFromXMLFile(new ResourceLocation(filename), parent);
+ }
+
+ /**
+ * Parse XML contains in a ResourceLocation into contents for a Window.
+ *
+ * @param resource xml as a {@link ResourceLocation}.
+ * @param parent parent view.
+ */
+ public static void createFromXMLFile(final ResourceLocation resource, final View parent)
+ {
+ if (parsedCache.containsKey(resource))
+ {
+ createFromPaneParams(parsedCache.get(resource).getB(), parent);
+ }
+ else
+ {
+ Document doc = parseXML(new InputSource(createInputStream(resource)));
+ addToCache(resource, createFromDocument(doc, parent));
+ }
+ }
+
+ /**
+ * Create an InputStream from a ResourceLocation.
+ *
+ * @param res ResourceLocation to get an InputStream from.
+ * @return the InputStream created from the ResourceLocation.
+ */
+ private static InputStream createInputStream(final ResourceLocation res)
+ {
+ try
+ {
+ InputStream is = DistExecutor.unsafeCallWhenOn(Dist.CLIENT, () -> () -> Minecraft.getInstance().getResourceManager().getResource(res).getInputStream());
+ if (is == null)
+ {
+ is = DistExecutor
+ .unsafeCallWhenOn(Dist.DEDICATED_SERVER, () -> () -> Loader.class.getResourceAsStream(String.format("/assets/%s/%s", res.getNamespace(), res.getPath())));
+ }
+ return is;
+ }
+ catch (final RuntimeException e)
+ {
+ Log.getLogger().error("IOException Loader.java", e.getCause());
+ }
+ return null;
+ }
+
+ // ------ Cache Handling ------
+
+ /**
+ * Adds a new parsed document to the cache.
+ * If the cache is full, the least accessed document is removed.
+ * @param loc the resource for the gui definition file
+ * @param doc the processed document
+ */
+ public static void addToCache(ResourceLocation loc, PaneParams doc)
+ {
+ if (parsedCache.size() >= MAX_CACHE_SIZE)
+ {
+ parsedCache.remove(
+ parsedCache.entrySet().stream()
+ .min((a,b) -> Math.min(a.getValue().getA(), b.getValue().getA())).get().getKey());
+ }
+
+ parsedCache.put(loc, new Tuple<>(1, doc));
+ }
+
+ /**
+ * Clear the cache of parsed window parameters
+ */
+ public static void cleanParsedCache()
+ {
+ parsedCache.clear();
+ }
+}
diff --git a/src/main/java/com/ldtteam/blockui/Log.java b/src/main/java/com/ldtteam/blockui/Log.java
new file mode 100644
index 00000000..64e6229d
--- /dev/null
+++ b/src/main/java/com/ldtteam/blockui/Log.java
@@ -0,0 +1,37 @@
+package com.ldtteam.blockui;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+/**
+ * Logging utility class.
+ */
+public final class Log
+{
+ /**
+ * Mod logger.
+ */
+ private static Logger logger = null;
+
+ /**
+ * Private constructor to hide the public one.
+ */
+ private Log()
+ {
+ // Hides implicit constructor.
+ }
+
+ /**
+ * Getter for the blockout Logger.
+ *
+ * @return the logger.
+ */
+ public static Logger getLogger()
+ {
+ if (logger == null)
+ {
+ Log.logger = LogManager.getLogger();
+ }
+ return logger;
+ }
+}
diff --git a/src/main/java/com/ldtteam/blockui/MatrixUtils.java b/src/main/java/com/ldtteam/blockui/MatrixUtils.java
new file mode 100644
index 00000000..b9b77b16
--- /dev/null
+++ b/src/main/java/com/ldtteam/blockui/MatrixUtils.java
@@ -0,0 +1,90 @@
+package com.ldtteam.blockui;
+
+import com.mojang.blaze3d.vertex.PoseStack;
+import net.minecraft.util.Mth;
+import com.mojang.math.Matrix4f;
+
+/**
+ * Helpful util methods when using Matrixes
+ */
+public class MatrixUtils
+{
+ /**
+ * Private constructor to hide the public one.
+ */
+ private MatrixUtils()
+ {
+ }
+
+ /**
+ * @return last matrix X translate value
+ */
+ public static int getLastMatrixTranslateXasInt(final PoseStack matrixStack)
+ {
+ return Mth.floor(getLastMatrixTranslateX(matrixStack));
+ }
+
+ /**
+ * @return last matrix Y translate value
+ */
+ public static int getLastMatrixTranslateYasInt(final PoseStack matrixStack)
+ {
+ return Mth.floor(getLastMatrixTranslateY(matrixStack));
+ }
+
+ /**
+ * @return last matrix Z translate value
+ */
+ public static int getLastMatrixTranslateZasInt(final PoseStack matrixStack)
+ {
+ return Mth.floor(getLastMatrixTranslateZ(matrixStack));
+ }
+
+ /**
+ * @return last matrix X translate value
+ */
+ public static float getLastMatrixTranslateX(final PoseStack matrixStack)
+ {
+ return getMatrixTranslateX(matrixStack.last().pose());
+ }
+
+ /**
+ * @return last matrix Y translate value
+ */
+ public static float getLastMatrixTranslateY(final PoseStack matrixStack)
+ {
+ return getMatrixTranslateY(matrixStack.last().pose());
+ }
+
+ /**
+ * @return last matrix Z translate value
+ */
+ public static float getLastMatrixTranslateZ(final PoseStack matrixStack)
+ {
+ return getMatrixTranslateZ(matrixStack.last().pose());
+ }
+
+ /**
+ * @return matrix X translate value
+ */
+ public static float getMatrixTranslateX(final Matrix4f matrix)
+ {
+ return matrix.m03;
+ }
+
+ /**
+ * @return matrix Y translate value
+ */
+ public static float getMatrixTranslateY(final Matrix4f matrix)
+ {
+ return matrix.m13;
+ }
+
+ /**
+ * @return matrix Z translate value
+ */
+ public static float getMatrixTranslateZ(final Matrix4f matrix)
+ {
+ return matrix.m23;
+ }
+}
diff --git a/src/main/java/com/ldtteam/blockui/MouseEventCallback.java b/src/main/java/com/ldtteam/blockui/MouseEventCallback.java
new file mode 100644
index 00000000..7ee04914
--- /dev/null
+++ b/src/main/java/com/ldtteam/blockui/MouseEventCallback.java
@@ -0,0 +1,16 @@
+package com.ldtteam.blockui;
+
+/**
+ * Generic mouse event callback interface
+ */
+@FunctionalInterface
+public interface MouseEventCallback
+{
+ /**
+ * @param pane event acceptor
+ * @param mx mouse x relative to parent top-left corner
+ * @param my mouse y relative to parent top-left corner
+ * @return true if event was used or propagation needs to be stopped
+ */
+ boolean accept(Pane pane, double mx, double my);
+}
diff --git a/src/main/java/com/ldtteam/blockui/Pane.java b/src/main/java/com/ldtteam/blockui/Pane.java
new file mode 100644
index 00000000..518dd252
--- /dev/null
+++ b/src/main/java/com/ldtteam/blockui/Pane.java
@@ -0,0 +1,1006 @@
+package com.ldtteam.blockui;
+
+import com.ldtteam.blockui.controls.AbstractTextBuilder.TooltipBuilder;
+import com.ldtteam.blockui.views.View;
+import com.ldtteam.blockui.views.Window;
+import com.mojang.blaze3d.vertex.*;
+import com.mojang.blaze3d.systems.RenderSystem;
+import net.minecraft.client.Minecraft;
+import net.minecraft.client.gui.GuiComponent;
+import net.minecraft.util.FormattedCharSequence;
+import net.minecraft.util.Mth;
+import com.mojang.math.Matrix4f;
+import com.mojang.math.Vector4f;
+import net.minecraft.network.chat.MutableComponent;
+import net.minecraft.network.chat.Component;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.ArrayList;
+import java.util.Deque;
+import java.util.List;
+import java.util.Objects;
+import java.util.concurrent.ConcurrentLinkedDeque;
+
+/**
+ * A Pane is the root of all UI objects.
+ */
+public class Pane extends GuiComponent
+{
+ private static final Deque scissorsInfoStack = new ConcurrentLinkedDeque<>();
+ protected static Pane lastClickedPane;
+ protected static Pane focus;
+ protected Pane onHover;
+ protected static boolean debugging = false;
+ protected Minecraft mc = Minecraft.getInstance();
+ // Attributes
+ protected String id = "";
+ protected int x = 0;
+ protected int y = 0;
+ protected int width = 0;
+ protected int height = 0;
+ protected Alignment alignment = Alignment.TOP_LEFT;
+ protected boolean visible = true;
+ protected boolean enabled = true;
+ protected String onHoverId = "";
+ // Runtime
+ protected Window window;
+ protected View parent;
+ /**
+ * Should be only used during drawing methods. Outside drawing scope value may be outdated.
+ */
+ protected boolean wasCursorInPane = false;
+ private List toolTipLines = new ArrayList<>();
+
+ /**
+ * Default constructor.
+ */
+ public Pane()
+ {
+ super();
+ // Required for panes.
+ }
+
+ /**
+ * Constructs a Pane from PaneParams.
+ *
+ * @param params Params for the Pane.
+ */
+ public Pane(final PaneParams params)
+ {
+ super();
+ id = params.getString("id", id);
+
+ params.getScaledInteger("size", params.getParentWidth(), params.getParentHeight(), a -> {
+ width = a.get(0);
+ height = a.get(1);
+ });
+
+ params.getScaledInteger("pos", params.getParentView().x, params.getParentView().y, a -> {
+ x = a.get(0);
+ y = a.get(1);
+ });
+
+ alignment = params.getEnum("align", Alignment.class, alignment);
+ visible = params.getBoolean("visible", visible);
+ enabled = params.getBoolean("enabled", enabled);
+ onHoverId = params.getString("onHoverId", onHoverId);
+ toolTipLines = params.getMultilineText("tooltip", toolTipLines);
+ }
+
+ /**
+ * Returns the currently focused Pane.
+ *
+ * @return the currently focused Pane.
+ */
+ public static synchronized Pane getFocus()
+ {
+ return focus;
+ }
+
+ /**
+ * Clear the currently focused Pane.
+ */
+ public static void clearFocus()
+ {
+ setFocus(null);
+ }
+
+ /**
+ * Override to respond to the Pane losing focus.
+ */
+ public void onFocusLost()
+ {
+ // Can be overloaded
+ }
+
+ /**
+ * Override to respond to the Pane becoming the current focus.
+ */
+ public void onFocus()
+ {
+ // Can be overloaded
+ }
+
+ /**
+ * Parse the children of the pane.
+ *
+ * @param params the parameter.
+ */
+ public void parseChildren(final PaneParams params)
+ {
+ // Can be overloaded
+ }
+
+ // ID
+
+ public final String getID()
+ {
+ return id;
+ }
+
+ public final void setID(final String id)
+ {
+ this.id = id;
+ }
+
+ /**
+ * Set the size of a pane.
+ *
+ * @param w the width.
+ * @param h the height.
+ */
+ public void setSize(final int w, final int h)
+ {
+ width = w;
+ height = h;
+ }
+
+ /**
+ * Set the position of the pane.
+ *
+ * @param newX the new x.
+ * @param newY the new y.
+ */
+ public void setPosition(final int newX, final int newY)
+ {
+ x = newX;
+ y = newY;
+ }
+
+ /**
+ * Move the pane by x and y to a place.
+ *
+ * @param dx the x.
+ * @param dy the y.
+ */
+ public void moveBy(final int dx, final int dy)
+ {
+ x += dx;
+ y += dy;
+ }
+
+ public Alignment getAlignment()
+ {
+ return alignment;
+ }
+
+ public void setAlignment(final Alignment alignment)
+ {
+ this.alignment = alignment;
+ }
+
+ // Visibility
+
+ public boolean isVisible()
+ {
+ return visible;
+ }
+
+ public void setVisible(final boolean v)
+ {
+ visible = v;
+ }
+
+ /**
+ * Show this pane.
+ */
+ public void show()
+ {
+ setVisible(true);
+ }
+
+ /**
+ * Hide this pane.
+ */
+ public void hide()
+ {
+ setVisible(false);
+ }
+
+ // Enabling
+
+ public boolean isEnabled()
+ {
+ return enabled;
+ }
+
+ public void setEnabled(final boolean e)
+ {
+ enabled = e;
+ }
+
+ /**
+ * Enable this pane.
+ */
+ public void enable()
+ {
+ setEnabled(true);
+ }
+
+ /**
+ * Disable this pane.
+ */
+ public void disable()
+ {
+ setEnabled(false);
+ }
+
+ /**
+ * Enable and show this pane.
+ */
+ public void on()
+ {
+ setEnabled(true);
+ setVisible(true);
+ }
+
+ /**
+ * Disable and hide this pane.
+ */
+ public void off()
+ {
+ setEnabled(false);
+ setVisible(false);
+ }
+
+ /**
+ * Set Focus to this Pane.
+ */
+ public final void setFocus()
+ {
+ setFocus(this);
+ }
+
+ /**
+ * Return {@code true} if this Pane is the current focus.
+ *
+ * @return {@code true} if this Pane is the current focus.
+ */
+ public final synchronized boolean isFocus()
+ {
+ return focus == this;
+ }
+
+ /**
+ * Set the currently focused Pane.
+ *
+ * @param f Pane to focus, or nil.
+ */
+ public static synchronized void setFocus(final Pane f)
+ {
+ if (focus != null)
+ {
+ focus.onFocusLost();
+ }
+
+ focus = f;
+
+ if (focus != null)
+ {
+ focus.onFocus();
+ }
+ }
+
+ /**
+ * Draw the current Pane if visible.
+ *
+ * @param mx mouse x.
+ * @param my mouse y.
+ */
+ public void draw(final PoseStack ms, final double mx, final double my)
+ {
+ wasCursorInPane = isPointInPane(mx, my);
+ handleHover();
+
+ if (visible)
+ {
+ drawSelf(ms, mx, my);
+ if (debugging)
+ {
+ final int color = wasCursorInPane ? 0xFF00FF00 : 0xFF0000FF;
+
+ Render.drawOutlineRect(ms, x, y, getWidth(), getHeight(), color);
+
+ if (wasCursorInPane && !id.isEmpty())
+ {
+ final int stringWidth = mc.font.width(id);
+ mc.font.draw(ms, id, x + getWidth() - stringWidth, y + getHeight() - mc.font.lineHeight, color);
+ }
+ }
+ }
+ }
+
+ /**
+ * Draw something after finishing drawing the GUI.
+ *
+ * @param mx mouse x.
+ * @param my mouse y.
+ */
+ public void drawLast(final PoseStack ms, final double mx, final double my)
+ {
+ if (visible)
+ {
+ drawSelfLast(ms, mx, my);
+ }
+ }
+
+ /**
+ * Draw self. The graphics port is already relative to the appropriate location.
+ *
+ * Override this to actually draw.
+ *
+ * @param mx Mouse x (relative to parent).
+ * @param my Mouse y (relative to parent).
+ */
+ public void drawSelf(final PoseStack ms, final double mx, final double my)
+ {
+ // Can be overloaded
+ }
+
+ /**
+ * Draw self last. The graphics port is already relative to the appropriate location.
+ *
+ * Override this to actually draw last.
+ *
+ * @param mx Mouse x (relative to parent).
+ * @param my Mouse y (relative to parent).
+ */
+ public void drawSelfLast(final PoseStack ms, final double mx, final double my)
+ {
+ // Can be overloaded
+ }
+
+ /**
+ * Is a point relative to the parent's origin within the pane?
+ *
+ * @param mx point x.
+ * @param my point y.
+ * @return true if the point is in the pane.
+ */
+ public boolean isPointInPane(final double mx, final double my)
+ {
+ return isVisible() && mx >= x && mx < (x + width) && my >= y && my < (y + height);
+ }
+
+ /**
+ * Was the cursor in pane during draw method?
+ *
+ * @return true if the cursor was in pane, false otherwise
+ */
+ public boolean wasCursorInPane()
+ {
+ return wasCursorInPane;
+ }
+
+ // Dimensions
+ public int getWidth()
+ {
+ return width;
+ }
+
+ // Drawing
+
+ public int getHeight()
+ {
+ return height;
+ }
+
+ /**
+ * Returns the first Pane (depth-first search) of a given ID. if it matches the specified type. Performs a depth-first search on the hierarchy of Panes and Views.
+ *
+ * @param idIn ID of Pane to find.
+ * @param type Class of the desired Pane type.
+ * @param The type of pane returned.
+ * @return a Pane of the given ID, if it matches the specified type.
+ */
+ public final T findPaneOfTypeByID(final String idIn, final Class type)
+ {
+ @Nullable
+ final Pane p = findPaneByID(idIn);
+ try
+ {
+ return type.cast(p);
+ }
+ catch (final ClassCastException e)
+ {
+ throw new IllegalArgumentException(String.format("No pane with id %s and type %s was found.", idIn, type), e);
+ }
+ }
+
+ /**
+ * Returns the first Pane (depth-first search) of a given type.
+ *
+ * @param type Class of the desired Pane type.
+ * @param The type of pane returned.
+ * @return a Pane of the given type if found, null otherwise.
+ */
+ public final T findFirstPaneByType(final Class type)
+ {
+ return findPaneByType(type);
+ }
+
+ // ----------Subpanes-------------//
+
+ /**
+ * Returns the first Pane of a given ID. Performs a depth-first search on the hierarchy of Panes and Views.
+ *
+ * @param idIn ID of Pane to find.
+ * @return a Pane of the given ID.
+ */
+ @Nullable
+ public Pane findPaneByID(final String idIn)
+ {
+ return id.equals(idIn) ? this : null;
+ }
+
+ /**
+ * Returns the first Pane of a given type. Performs a depth-first search on the hierarchy of Panes and Views.
+ *
+ * @param type type of Pane to find.
+ * @return a Pane of the given type.
+ */
+ @Nullable
+ public T findPaneByType(final Class type)
+ {
+ return this.getClass().equals(type) ? type.cast(this) : null;
+ }
+
+ /**
+ * Return the Pane that contains this one.
+ *
+ * @return the Pane that contains this one
+ */
+ public final View getParent()
+ {
+ return parent;
+ }
+
+ /**
+ * Return the Window that this Pane ultimately belongs to.
+ *
+ * @return the Window that this Pane belongs to.
+ */
+ public final Window getWindow()
+ {
+ return window;
+ }
+
+ public void setWindow(final Window w)
+ {
+ window = w;
+
+ // can't gen tooltip from xml until first window is set
+ if (!toolTipLines.isEmpty())
+ {
+ final TooltipBuilder ttBuilder = PaneBuilders.tooltipBuilder().hoverPane(this);
+ toolTipLines.forEach(ttBuilder::appendNL);
+ toolTipLines.clear(); // do not regen it when window has changed (unlikely to happen) cuz onHover might have changed
+ onHover = ttBuilder.build();
+ }
+
+ setHoverPane(onHover); // renew hover mount
+ }
+
+ /**
+ * Put this Pane inside a View. Only Views and subclasses can contain Panes.
+ *
+ * @param newParent the View to put this Pane into, or null to remove from Parents.
+ */
+ public void putInside(final View newParent)
+ {
+ if (parent != null)
+ {
+ parent.removeChild(this);
+ }
+
+ parent = newParent;
+
+ if (parent != null)
+ {
+ parent.addChild(this);
+
+ // Allow views to expand zero-widths
+ setSize(width, height);
+ }
+ }
+
+ public boolean isClickable()
+ {
+ return visible && enabled;
+ }
+
+ // ----------Mouse-------------//
+
+ /**
+ * Process a mouse down on the Pane.
+ *
+ * It is advised that only containers of other panes override this method.
+ *
+ * @param mx mouse X coordinate, relative to parent's top-left.
+ * @param my mouse Y coordinate, relative to parent's top-left.
+ * @return true if event was used or propagation needs to be stopped
+ */
+ public boolean click(final double mx, final double my)
+ {
+ setLastClickedPane(this);
+ return handleClick(mx - x, my - y);
+ }
+
+ /**
+ * Process a rightclick mouse down on the Pane.
+ *
+ * It is advised that only containers of other panes override this method.
+ *
+ * @param mx mouse X coordinate, relative to parent's top-left.
+ * @param my mouse Y coordinate, relative to parent's top-left.
+ * @return true if event was used or propagation needs to be stopped
+ */
+ public boolean rightClick(final double mx, final double my)
+ {
+ setLastClickedPane(this);
+ return handleRightClick(mx - x, my - y);
+ }
+
+ /**
+ * Set a pane as the last clicked pane.
+ *
+ * @param pane pane to set.
+ */
+ private static synchronized void setLastClickedPane(final Pane pane)
+ {
+ lastClickedPane = pane;
+ }
+
+ /**
+ * Process a click on the Pane.
+ *
+ * Override this to process the actual click.
+ *
+ * @param mx mouse X coordinate, relative to Pane's top-left.
+ * @param my mouse Y coordinate, relative to Pane's top-left.
+ * @return true if event was used or propagation needs to be stopped
+ */
+ public boolean handleClick(final double mx, final double my)
+ {
+ // Can be overloaded
+ return false;
+ }
+
+ /**
+ * Process a right click on the Pane.
+ *
+ * Override this to process the actual click.
+ *
+ * @param mx mouse X coordinate, relative to Pane's top-left.
+ * @param my mouse Y coordinate, relative to Pane's top-left.
+ * @return true if event was used or propagation needs to be stopped
+ */
+ public boolean handleRightClick(final double mx, final double my)
+ {
+ // Can be overloaded
+ return false;
+ }
+
+ /**
+ * Check if a pane can handle clicks.
+ *
+ * @param mx int x position.
+ * @param my int y position.
+ * @return true if so.
+ */
+ public boolean canHandleClick(final double mx, final double my)
+ {
+ return visible && enabled && isPointInPane(mx, my);
+ }
+
+ /**
+ * Called when a key is pressed.
+ *
+ * @param ch the character
+ * @param key the key
+ * @return true if event was used or propagation needs to be stopped
+ */
+ public boolean onKeyTyped(final char ch, final int key)
+ {
+ return false;
+ }
+
+ /**
+ * On update. Can be overloaded.
+ */
+ public void onUpdate()
+ {
+ // Can be overloaded
+ }
+
+ protected synchronized void scissorsStart(final PoseStack ms, final int contentWidth, final int contentHeight)
+ {
+ final int fbWidth = mc.getWindow().getWidth();
+ final int fbHeight = mc.getWindow().getHeight();
+
+ final Vector4f start = new Vector4f(x, y, 0.0f, 1.0f);
+ final Vector4f end = new Vector4f(x + width, y + height, 0.0f, 1.0f);
+ start.transform(ms.last().pose());
+ end.transform(ms.last().pose());
+
+ int scissorsXstart = Mth.clamp((int) Math.floor(start.x()), 0, fbWidth);
+ int scissorsXend = Mth.clamp((int) Math.floor(end.x()), 0, fbWidth);
+
+ int scissorsYstart = Mth.clamp((int) Math.floor(start.y()), 0, fbHeight);
+ int scissorsYend = Mth.clamp((int) Math.floor(end.y()), 0, fbHeight);
+
+ // negate bottom top (opengl things)
+ final int temp = scissorsYstart;
+ scissorsYstart = fbHeight - scissorsYend;
+ scissorsYend = fbHeight - temp;
+
+ if (!scissorsInfoStack.isEmpty())
+ {
+ final ScissorsInfo parentInfo = scissorsInfoStack.peek();
+
+ scissorsXstart = Math.max(scissorsXstart, parentInfo.xStart);
+ scissorsXend = Math.max(scissorsXstart, Math.min(parentInfo.xEnd, scissorsXend));
+
+ scissorsYstart = Math.max(scissorsYstart, parentInfo.yStart);
+ scissorsYend = Math.max(scissorsYstart, Math.min(parentInfo.yEnd, scissorsYend));
+ }
+
+ final ScissorsInfo info = new ScissorsInfo(scissorsXstart, scissorsXend, scissorsYstart, scissorsYend, window.getScreen().width, window.getScreen().height);
+ scissorsInfoStack.push(info);
+ window.getScreen().width = contentWidth;
+ window.getScreen().height = contentHeight;
+
+ RenderSystem.enableScissor(scissorsXstart, scissorsYstart, scissorsXend - scissorsXstart, scissorsYend - scissorsYstart);
+ }
+
+ /**
+ * X position.
+ *
+ * @return the int x.
+ */
+ public int getX()
+ {
+ return x;
+ }
+
+ /**
+ * Y position.
+ *
+ * @return the int y.
+ */
+ public int getY()
+ {
+ return y;
+ }
+
+ protected synchronized void scissorsEnd(final PoseStack ms)
+ {
+ final ScissorsInfo popped = scissorsInfoStack.pop();
+ if (debugging)
+ {
+ final int color = 0xffff0000;
+ final int w = popped.xEnd - popped.xStart;
+ final int h = popped.yEnd - popped.yStart;
+
+ final int yStart = mc.getWindow().getHeight() - popped.yEnd;
+
+ ms.pushPose();
+ ms.last().pose().setIdentity();
+ Render.drawOutlineRect(ms, popped.xStart, yStart, w, h, color, 2.0f);
+
+ final String scId = "scissor_" + (id.isEmpty() ? this.toString() : id);
+ final int scale = (int) mc.getWindow().getGuiScale();
+ final int stringWidth = mc.font.width(scId);
+ ms.scale(scale, scale, 1.0f);
+ mc.font.draw(ms,
+ scId,
+ (popped.xStart + w) / scale - stringWidth,
+ (yStart + h) / scale - mc.font.lineHeight,
+ color);
+ ms.popPose();
+ }
+
+ window.getScreen().width = popped.oldGuiWidth;
+ window.getScreen().height = popped.oldGuiHeight;
+
+ if (!scissorsInfoStack.isEmpty())
+ {
+ final ScissorsInfo info = scissorsInfoStack.peek();
+ RenderSystem.enableScissor(info.xStart, info.yStart, info.xEnd - info.xStart, info.yEnd - info.yStart);
+ }
+ else
+ {
+ RenderSystem.disableScissor();
+ }
+ }
+
+ /**
+ * Wheel input.
+ *
+ * @param wheel minus for down, plus for up.
+ * @param mx mouse x
+ * @param my mouse y
+ * @return true if event was used or propagation needs to be stopped
+ */
+ public boolean scrollInput(final double wheel, final double mx, final double my)
+ {
+ // Can be overwritten by child classes
+ return false;
+ }
+
+ /**
+ * Set the parent of the child.
+ *
+ * @param view the parent view.
+ */
+ public void setParentView(final View view)
+ {
+ this.parent = view;
+ }
+
+ private static class ScissorsInfo
+ {
+ private final int xStart;
+ private final int yStart;
+ private final int xEnd;
+ private final int yEnd;
+ private final int oldGuiWidth;
+ private final int oldGuiHeight;
+
+ ScissorsInfo(final int xStart, final int xEnd, final int yStart, final int yEnd, final int oldGuiWidth, final int oldGuiHeight)
+ {
+ this.xStart = xStart;
+ this.xEnd = xEnd;
+ this.yStart = yStart;
+ this.yEnd = yEnd;
+ this.oldGuiWidth = oldGuiWidth;
+ this.oldGuiHeight = oldGuiHeight;
+ }
+ }
+
+ /**
+ * Handle onHover element, element must be visible.
+ */
+ protected void handleHover()
+ {
+ if (onHover == null && !onHoverId.isEmpty())
+ {
+ onHover = window.findPaneByID(onHoverId); // do not use setHoverPane, here onHover is defined in xml
+ Objects.requireNonNull(onHover, String.format("Hover pane \"%s\" for \"%s\" was not found.", onHoverId, id));
+ }
+
+ if (onHover == null)
+ {
+ return;
+ }
+
+ if (this.wasCursorInPane && !onHover.isVisible() && onHover.isEnabled())
+ {
+ onHover.show();
+ }
+ // if onHover was already drawn then we good
+ // else we have to wait for next frame
+ else if (!onHover.wasCursorInPane && !this.wasCursorInPane && onHover.isVisible())
+ {
+ onHover.hide();
+ }
+ }
+
+ /**
+ * Overrides current hover pane with given pane.
+ * Old hover is removed from window of this pane.
+ * New hover is added (as last child) to window of this pane.
+ *
+ * @param hoverPane new hover pane
+ * @return old hover pane
+ */
+ public Pane setHoverPane(final Pane hoverPane)
+ {
+ if (onHover != null)
+ {
+ // gc
+ onHover.putInside(null);
+ }
+
+ final Pane oldHover = onHover;
+ this.onHover = hoverPane;
+
+ if (onHover != null)
+ {
+ onHover.putInside(window);
+ }
+
+ return oldHover;
+ }
+
+ public Pane getHoverPane()
+ {
+ return onHover;
+ }
+
+ @Deprecated
+ protected int drawString(final PoseStack ms, final String text, final float x, final float y, final int color, final boolean shadow)
+ {
+ if (shadow)
+ {
+ return mc.font.drawShadow(ms, text, x, y, color);
+ }
+ else
+ {
+ return mc.font.draw(ms, text, x, y, color);
+ }
+ }
+
+ protected int drawString(final PoseStack ms, final Component text, final float x, final float y, final int color, final boolean shadow)
+ {
+ if (shadow)
+ {
+ return mc.font.drawShadow(ms, text, x, y, color);
+ }
+ else
+ {
+ return mc.font.draw(ms, text, x, y, color);
+ }
+ }
+
+ protected int drawString(final PoseStack ms, final FormattedCharSequence text, final float x, final float y, final int color, final boolean shadow)
+ {
+ if (shadow)
+ {
+ return mc.font.drawShadow(ms, text, x, y, color);
+ }
+ else
+ {
+ return mc.font.draw(ms, text, x, y, color);
+ }
+ }
+
+ /**
+ * Mouse drag.
+ *
+ * @param mx mouse start x
+ * @param my mouse start y
+ * @param speed drag speed
+ * @param deltaX relative x
+ * @param deltaY relative y
+ * @return true if event was used or propagation needs to be stopped
+ */
+ public boolean onMouseDrag(final double mx, final double my, final int speed, final double deltaX, final double deltaY)
+ {
+ return false;
+ }
+
+ /**
+ * Draws texture without scaling so one texel is one pixel, using repeatable texture center.
+ *
+ * @param ms MatrixStack
+ * @param x start target coords [pixels]
+ * @param y start target coords [pixels]
+ * @param width target rendering box [pixels]
+ * @param height target rendering box [pixels]
+ * @param u texture start offset [texels]
+ * @param v texture start offset [texels]
+ * @param uWidth texture rendering box [texels]
+ * @param vHeight texture rendering box [texels]
+ * @param textureWidth texture file size [texels]
+ * @param textureHeight texture file size [texels]
+ * @param uRepeat offset relative to u, v [texels], smaller than uWidth
+ * @param vRepeat offset relative to u, v [texels], smaller than vHeight
+ * @param repeatWidth size of repeatable box in texture [texels], smaller than or equal uWidth - uRepeat
+ * @param repeatHeight size of repeatable box in texture [texels], smaller than or equal vHeight - vRepeat
+ */
+ protected static void blitRepeatable(final PoseStack ms,
+ final int x, final int y,
+ final int width, final int height,
+ final int u, final int v,
+ final int uWidth, final int vHeight,
+ final int textureWidth, final int textureHeight,
+ final int uRepeat, final int vRepeat,
+ final int repeatWidth, final int repeatHeight)
+ {
+ if (uRepeat < 0 || vRepeat < 0 || uRepeat >= uWidth || vRepeat >= vHeight || repeatWidth < 1 || repeatHeight < 1
+ || repeatWidth > uWidth - uRepeat || repeatHeight > vHeight - vRepeat)
+ {
+ throw new IllegalArgumentException("Repeatable box is outside of texture box");
+ }
+
+ final int repeatCountX = Math.max(1, Math.max(0, width - (uWidth - repeatWidth)) / repeatWidth);
+ final int repeatCountY = Math.max(1, Math.max(0, height - (vHeight - repeatHeight)) / repeatHeight);
+
+ final Matrix4f mat = ms.last().pose();
+ final BufferBuilder buffer = Tesselator.getInstance().getBuilder();
+ buffer.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX);
+
+ // main
+ for (int i = 0; i < repeatCountX; i++)
+ {
+ final int uAdjust = i == 0 ? 0 : uRepeat;
+ final int xStart = x + uAdjust + i * repeatWidth;
+ final int w = Math.min(repeatWidth + uRepeat - uAdjust, width - (uWidth - uRepeat - repeatWidth));
+ final float minU = (float) (u + uAdjust) / textureWidth;
+ final float maxU = (float) (u + uAdjust + w) / textureWidth;
+
+ for (int j = 0; j < repeatCountY; j++)
+ {
+ final int vAdjust = j == 0 ? 0 : vRepeat;
+ final int yStart = y + vAdjust + j * repeatHeight;
+ final int h = Math.min(repeatHeight + vRepeat - vAdjust, height - (vHeight - vRepeat - repeatHeight));
+ final float minV = (float) (v + vAdjust) / textureHeight;
+ final float maxV = (float) (v + vAdjust + h) / textureHeight;
+
+ buffer.vertex(mat, xStart, yStart + h, 0).uv(minU, maxV).endVertex();
+ buffer.vertex(mat, xStart + w, yStart + h, 0).uv(maxU, maxV).endVertex();
+ buffer.vertex(mat, xStart + w, yStart, 0).uv(maxU, minV).endVertex();
+ buffer.vertex(mat, xStart, yStart, 0).uv(minU, minV).endVertex();
+ }
+ }
+
+ final int xEnd = x + Math.min(uRepeat + repeatCountX * repeatWidth, width - (uWidth - uRepeat - repeatWidth));
+ final int yEnd = y + Math.min(vRepeat + repeatCountY * repeatHeight, height - (vHeight - vRepeat - repeatHeight));
+ final int uLeft = width - (xEnd - x);
+ final int vLeft = height - (yEnd - y);
+ final float restMinU = (float) (u + uWidth - uLeft) / textureWidth;
+ final float restMaxU = (float) (u + uWidth) / textureWidth;
+ final float restMinV = (float) (v + vHeight - vLeft) / textureHeight;
+ final float restMaxV = (float) (v + vHeight) / textureHeight;
+
+ // bot border
+ for (int i = 0; i < repeatCountX; i++)
+ {
+ final int uAdjust = i == 0 ? 0 : uRepeat;
+ final int xStart = x + uAdjust + i * repeatWidth;
+ final int w = Math.min(repeatWidth + uRepeat - uAdjust, width - uLeft);
+ final float minU = (float) (u + uAdjust) / textureWidth;
+ final float maxU = (float) (u + uAdjust + w) / textureWidth;
+
+ buffer.vertex(mat, xStart, yEnd + vLeft, 0).uv(minU, restMaxV).endVertex();
+ buffer.vertex(mat, xStart + w, yEnd + vLeft, 0).uv(maxU, restMaxV).endVertex();
+ buffer.vertex(mat, xStart + w, yEnd, 0).uv(maxU, restMinV).endVertex();
+ buffer.vertex(mat, xStart, yEnd, 0).uv(minU, restMinV).endVertex();
+ }
+
+ // left border
+ for (int j = 0; j < repeatCountY; j++)
+ {
+ final int vAdjust = j == 0 ? 0 : vRepeat;
+ final int yStart = y + vAdjust + j * repeatHeight;
+ final int h = Math.min(repeatHeight + vRepeat - vAdjust, height - vLeft);
+ float minV = (float) (v + vAdjust) / textureHeight;
+ float maxV = (float) (v + vAdjust + h) / textureHeight;
+
+ buffer.vertex(mat, xEnd, yStart + h, 0).uv(restMinU, maxV).endVertex();
+ buffer.vertex(mat, xEnd + uLeft, yStart + h, 0).uv(restMaxU, maxV).endVertex();
+ buffer.vertex(mat, xEnd + uLeft, yStart, 0).uv(restMaxU, minV).endVertex();
+ buffer.vertex(mat, xEnd, yStart, 0).uv(restMinU, minV).endVertex();
+ }
+
+ // bot left corner
+ buffer.vertex(mat, xEnd, yEnd + vLeft, 0).uv(restMinU, restMaxV).endVertex();
+ buffer.vertex(mat, xEnd + uLeft, yEnd + vLeft, 0).uv(restMaxU, restMaxV).endVertex();
+ buffer.vertex(mat, xEnd + uLeft, yEnd, 0).uv(restMaxU, restMinV).endVertex();
+ buffer.vertex(mat, xEnd, yEnd, 0).uv(restMinU, restMinV).endVertex();
+
+ buffer.end();
+ BufferUploader.end(buffer);
+ }
+}
diff --git a/src/main/java/com/ldtteam/blockui/PaneBuilders.java b/src/main/java/com/ldtteam/blockui/PaneBuilders.java
new file mode 100644
index 00000000..a6b7223c
--- /dev/null
+++ b/src/main/java/com/ldtteam/blockui/PaneBuilders.java
@@ -0,0 +1,31 @@
+package com.ldtteam.blockui;
+
+import com.ldtteam.blockui.controls.AbstractTextBuilder.TextBuilder;
+import com.ldtteam.blockui.controls.AbstractTextBuilder.TooltipBuilder;
+
+public final class PaneBuilders
+{
+ private PaneBuilders()
+ {
+ // utility class
+ }
+
+ /**
+ * Tooltip element builder.
+ * Don't forget to set hoverPane.
+ *
+ * @see TooltipBuilder#hoverPane(Pane)
+ */
+ public static TooltipBuilder tooltipBuilder()
+ {
+ return new TooltipBuilder();
+ }
+
+ /**
+ * Text element builder.
+ */
+ public static TextBuilder textBuilder()
+ {
+ return new TextBuilder();
+ }
+}
diff --git a/src/main/java/com/ldtteam/blockui/PaneParams.java b/src/main/java/com/ldtteam/blockui/PaneParams.java
new file mode 100644
index 00000000..55a925f5
--- /dev/null
+++ b/src/main/java/com/ldtteam/blockui/PaneParams.java
@@ -0,0 +1,349 @@
+package com.ldtteam.blockui;
+
+import com.ldtteam.blockui.views.View;
+import net.minecraft.resources.ResourceLocation;
+import net.minecraft.network.chat.MutableComponent;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+
+import javax.annotation.Nullable;
+import java.util.*;
+import java.util.function.Consumer;
+import java.util.function.Function;
+
+/**
+ * Special parameters for the panes.
+ */
+public class PaneParams
+{
+ private final Map propertyCache = new HashMap<>();
+ private final List children;
+ private final Node node;
+ private View parentView;
+
+ /**
+ * Instantiates the pane parameters.
+ *
+ * @param n the node.
+ */
+ public PaneParams(final Node n)
+ {
+ node = n;
+ children = new ArrayList<>(node.getChildNodes().getLength());
+ }
+
+ public String getType()
+ {
+ return node.getNodeName();
+ }
+
+ public View getParentView()
+ {
+ return parentView;
+ }
+
+ public void setParentView(final View parent)
+ {
+ parentView = parent;
+ }
+
+ public int getParentWidth()
+ {
+ return parentView != null ? parentView.getInteriorWidth() : 0;
+ }
+
+ public int getParentHeight()
+ {
+ return parentView != null ? parentView.getInteriorHeight() : 0;
+ }
+
+ public List getChildren()
+ {
+ if (!children.isEmpty()) return children;
+
+ Node child = node.getFirstChild();
+ while (child != null)
+ {
+ if (child.getNodeType() == Node.ELEMENT_NODE)
+ {
+ children.add(new PaneParams(child));
+ }
+ child = child.getNextSibling();
+ }
+
+ return children;
+ }
+
+ public String getText()
+ {
+ return node.getTextContent().trim();
+ }
+
+ private Node getAttribute(final String name)
+ {
+ return node.getAttributes().getNamedItem(name);
+ }
+
+ public boolean hasAttribute(final String name)
+ {
+ return node.getAttributes().getNamedItem(name) != null;
+ }
+
+ /**
+ * Finds an attribute by name from the XML node
+ * and parses it using the provided parser method
+ * @param name the attribute name to search for
+ * @param parser the parser to convert the attribute to its property
+ * @param def the default value if none can be found
+ * @param the type of value to work with
+ * @return the parsed value
+ */
+ @SuppressWarnings("unchecked")
+ public T getProperty(String name, Function parser, T def)
+ {
+ T result = null;
+
+ if (propertyCache.containsKey(name))
+ {
+ try
+ {
+ result = (T) propertyCache.get(name);
+ return result != null ? result : def;
+ }
+ catch (ClassCastException cce)
+ {
+ Log.getLogger().warn("Invalid property: previous value of key does not match type.");
+ }
+ }
+
+ final Node attr = getAttribute(name);
+ if (attr != null) result = parser.apply(attr.getNodeValue());
+
+ propertyCache.put(name, result);
+ return result != null ? result : def;
+ }
+
+ /**
+ * Get the string attribute.
+ *
+ * @param name the name to search.
+ * @return the attribute.
+ */
+ @Nullable
+ public String getString(final String name)
+ {
+ return getString(name, null);
+ }
+
+ /**
+ * Get the String attribute from the name and revert to the default if not present.
+ *
+ * @param name the name.
+ * @param def the default value if none can be found
+ * @return the String.
+ */
+ public String getString(final String name, final String def)
+ {
+ return getProperty(name, String::toString, def);
+ }
+
+ /**
+ * Get the resource location from the name
+ * @param name the attribute name
+ * @param def the default value to fallback to
+ * @return the parsed resource location
+ */
+ public ResourceLocation getResource(final String name, final String def)
+ {
+ return getProperty(name, Parsers.RESOURCE, new ResourceLocation(def));
+ }
+
+ /**
+ * Get the resource location from the name and load it
+ * @param name the attribute name
+ * @param loader a method to act upon the resource if it is not blank or null
+ * @return the parsed resource location (or null if it couldn't be parsed)
+ */
+ @Nullable
+ public ResourceLocation getResource(final String name, final Consumer loader)
+ {
+ ResourceLocation rl = getResource(name, "");
+ if (!rl.getPath().isEmpty())
+ {
+ loader.accept(rl);
+ return rl;
+ }
+ return null;
+ }
+
+ /**
+ * Get the text content with potential newlines from the name.
+ *
+ * @param name the name
+ * @return the parsed and localized list
+ */
+ public List getMultilineText(final String name)
+ {
+ return getMultilineText(name, Collections.emptyList());
+ }
+
+ /**
+ * Get the text content with potential newlines from the name and revert to the default if not present.
+ *
+ * @param name the name
+ * @param def the default value if none can be found
+ * @return the parsed and localized list
+ */
+ public List getMultilineText(final String name, List def)
+ {
+ return getProperty(name, Parsers.MULTILINE, def);
+ }
+
+ /**
+ * Get the localized String attribute from the name and revert to the default if not present.
+ *
+ * @param name the name.
+ * @param def the default value if none can be found
+ * @return the localized text component.
+ */
+ public MutableComponent getTextComponent(final String name, final MutableComponent def)
+ {
+ return getProperty(name, Parsers.TEXT, def);
+ }
+
+ /**
+ * Get the integer attribute from name and revert to the default if not present.
+ *
+ * @param name the name.
+ * @param def the default value if none can be found
+ * @return the int.
+ */
+ public int getInteger(final String name, final int def)
+ {
+ return getProperty(name, Parsers.INT, def);
+ }
+
+ /**
+ * Get the float attribute from name and revert to the default if not present.
+ *
+ * @param name the name.
+ * @param def the default value if none can be found
+ * @return the float.
+ */
+ public float getFloat(final String name, final float def)
+ {
+ return getProperty(name, Parsers.FLOAT, def);
+ }
+
+ /**
+ * Get the double attribute from name and revert to the default if not present.
+ *
+ * @param name the name.
+ * @param def the default value if none can be found
+ * @return the double.
+ */
+ public double getDouble(final String name, final double def)
+ {
+ return getProperty(name, Parsers.DOUBLE, def);
+ }
+
+ /**
+ * Get the boolean attribute from name and revert to the default if not present.
+ *
+ * @param name the name.
+ * @param def the default value if none can be found
+ * @return the boolean.
+ */
+ public boolean getBoolean(final String name, final boolean def)
+ {
+ return getProperty(name, Parsers.BOOLEAN, def);
+ }
+
+ /**
+ * Get the boolean attribute from name and class and revert to the default if not present.
+ *
+ * @param name the name.
+ * @param clazz the class.
+ * @param def the default value if none can be found
+ * @param the type of class.
+ * @return the enum attribute.
+ */
+ public > T getEnum(final String name, final Class clazz, final T def)
+ {
+ return getProperty(name, Parsers.ENUM(clazz), def);
+ }
+
+ /**
+ * Get the scalable integer attribute from name and revert to the default if not present.
+ *
+ * @param name the name
+ * @param scale the total value to be a fraction of
+ * @param def the default value if none can be found
+ * @return the parsed value
+ */
+ private int getScaledInteger(String name, final int scale, final int def)
+ {
+ return getProperty(name, Parsers.SCALED(scale), def);
+ }
+
+ /**
+ * Parses two scalable values and processes them through an applicant
+ *
+ * @param name the attribute name to search for
+ * @param scaleX the first fraction total
+ * @param scaleY the second fraction total
+ * @param applier the method to utilise the result values
+ */
+ public void getScaledInteger(final String name, final int scaleX, final int scaleY, Consumer> applier)
+ {
+ List results = Parsers.SCALED(scaleX, scaleY).apply(getString(name));
+ if (results != null) applier.accept(results);
+ }
+
+ /**
+ * Get the color attribute from name and revert to the default if not present.
+ *
+ * @param name the name.
+ * @param def the default value if none can be found
+ * @return int color value.
+ */
+ public int getColor(final String name, final int def)
+ {
+ return getProperty(name, Parsers.COLOR, def);
+ }
+
+ /**
+ * Fetches a property and runs the result through a given method.
+ * Commonly used for shorthand properties.
+ * @param name the name of the attribute to retrieve
+ * @param parser the parser applied to each part
+ * @param parts the maximum number of parts to fill to if less are given
+ * @param applier the method to utilise the parsed values
+ * @param the type of each part
+ */
+ public void applyShorthand(String name, Function parser, int parts, Consumer> applier)
+ {
+ List results = Parsers.shorthand(parser, parts).apply(getString(name));
+ if (results != null) applier.accept(results);
+ }
+
+ /**
+ * Checks if any of attribute names are present and return first found, else return default.
+ *
+ * @param def the default value if none can be found
+ * @param attributes attributes names to check
+ * @return first found attribute or default
+ */
+ public String hasAnyAttribute(final String def, final String... attributes)
+ {
+ final NamedNodeMap nodeMap = node.getAttributes();
+ for (final String attr : attributes)
+ {
+ if (nodeMap.getNamedItem(attr) != null) // inlined hasAttribute
+ {
+ return attr;
+ }
+ }
+ return def;
+ }
+}
diff --git a/src/main/java/com/ldtteam/blockui/Parsers.java b/src/main/java/com/ldtteam/blockui/Parsers.java
new file mode 100644
index 00000000..52d46e2c
--- /dev/null
+++ b/src/main/java/com/ldtteam/blockui/Parsers.java
@@ -0,0 +1,182 @@
+package com.ldtteam.blockui;
+
+import net.minecraft.client.resources.language.I18n;
+import net.minecraft.resources.ResourceLocation;
+import net.minecraft.util.Mth;
+import net.minecraft.network.chat.MutableComponent;
+import net.minecraft.network.chat.TextComponent;
+import net.minecraftforge.fmllegacy.ForgeI18n;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.function.Function;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+
+import static com.ldtteam.blockui.Log.getLogger;
+
+public final class Parsers
+{
+ private Parsers() { /* prevent construction */ }
+
+ public static final Pattern PERCENTAGE_PATTERN = Pattern.compile("([-+]?\\d+)(%|px)?", Pattern.CASE_INSENSITIVE);
+ public static final Pattern RGBA_PATTERN = Pattern.compile("rgba?\\(\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)\\s*(?:,\\s*([01]\\.\\d+)\\s*)?\\)", Pattern.CASE_INSENSITIVE);
+ public static final Pattern HEXADECIMAL_PATTERN = Pattern.compile("#([0-9A-F]{6,8})", Pattern.CASE_INSENSITIVE);
+
+ // Primitives
+ public static Function BOOLEAN = v -> v == null || !v.isEmpty() && !v.equals("disabled") && Boolean.parseBoolean(v);
+ public static Function INT = Integer::parseInt;
+ public static Function FLOAT = Float::parseFloat;
+ public static Function DOUBLE = Double::parseDouble;
+
+ /** Parses a resource location, include shorthand tricks */
+ public static Function RESOURCE = ResourceLocation::new;
+
+ /** Parses a potentially translatable portion of text as a component */
+ private static Function RAW_TEXT = v -> {
+ String result = v == null ? "" : v;
+ Matcher m = Pattern.compile("\\$[({](\\S+)[})]").matcher(result);
+
+ while (m.find())
+ {
+ String translated = I18n.get(m.group(1));
+ if (translated.equals(m.group(1)))
+ {
+ translated = "MISSING: " + m.group(1);
+ }
+ result = result.replace(m.group(0), translated);
+ }
+
+ return result;
+ };
+
+ /** Parses a potentially translatable portion of text as a component */
+ public static Function TEXT = v -> {
+ String result = RAW_TEXT.apply(v);
+ return result == null ? null : new TextComponent(result);
+ };
+
+ /** Applies the TEXT parser across multiple lines */
+ public static Function> MULTILINE = v -> Arrays
+ .stream(Parsers.RAW_TEXT.apply(v).split("(\\\\n|\\n)"))
+ .map(TextComponent::new)
+ .collect(Collectors.toList());
+
+ /** Parses a color from hex, rgba, name, or pure value */
+ public static Function COLOR = v -> {
+ Matcher m = HEXADECIMAL_PATTERN.matcher(v);
+ if (m.find()) return Integer.parseInt(m.group(), 16);
+
+ m = RGBA_PATTERN.matcher(v);
+ if (m.find()) return Color.rgbaToInt(m);
+
+ try
+ {
+ return Integer.parseUnsignedInt(v);
+ }
+ catch (final NumberFormatException ex)
+ {
+ return Color.getByName(v);
+ }
+ };
+
+ /**
+ * Parses a number, which may potentially be marked as a percentage of the given total
+ * @param total the number that the parsed value may be a percentage of
+ */
+ public static Function SCALED(int total) {
+ return v -> {
+ try
+ {
+ Matcher m = PERCENTAGE_PATTERN.matcher(v);
+ if (!m.find()) return null;
+
+ int value = Integer.parseInt(m.group(1));
+ return m.group(2) != null && m.group(2).equals("%")
+ ? total * Mth.clamp(value, 0, 100) / 100
+ : value;
+ }
+ catch (final NumberFormatException | IndexOutOfBoundsException | IllegalStateException ex)
+ {
+ getLogger().warn(ex);
+ }
+
+ return null;
+ };
+ }
+
+ /**
+ * Parses multiple numbers, where each may be a percentage of a given total
+ * @param totals a list of totals that correlate with the position in the shorthand string
+ */
+ public static Function> SCALED(int... totals)
+ {
+ return v -> {
+ final List results = new ArrayList<>(totals.length);
+
+ if (v == null) return null;
+
+ String[] values = v.split("\\s*[,\\s]\\s*");
+ for (int i = 0; i < totals.length; i++)
+ {
+ int index = values.length > i ? i : Math.min(i % 2, values.length-1);
+ results.add(Parsers.SCALED(totals[i]).apply( values[index]));
+ }
+
+ return results;
+ };
+ }
+
+ /**
+ * Supply an enumeration class and this will parse it
+ * @param clazz the enum class to parse against
+ * @param they enum class type
+ */
+ public static > Function ENUM(Class clazz)
+ {
+ return v -> {
+ try
+ {
+ return Enum.valueOf(clazz, v);
+ }
+ catch (IllegalArgumentException | NullPointerException e)
+ {
+ Log.getLogger().warn("Attempt to access non-existent enumeration '"+v+"'.");
+ }
+ return null;
+ };
+ }
+
+ /**
+ * A function factory to create a shorthand parser that will determine the number of parts
+ * in a string and fill it out to the given number of parts
+ * @param parser the parser to used for each individual part
+ * @param parts the max number of parts that the result will have
+ * @param describes the type of each parsed value
+ */
+ public static Function> shorthand(Function parser, int parts)
+ {
+ return v -> {
+ final List results = new ArrayList<>(parts);
+
+ if (v == null) return null;
+
+ for (final String segment : v.split("\\s*[,\\s]\\s*"))
+ {
+ results.add(parser.apply(segment));
+ }
+
+ while (results.size() < parts)
+ {
+ // Will duplicate in pairs, so a 4-part property defined
+ // from "2 8" will become "2 8 2 8"
+ // useful for syncing vertical and horizontal for each edge
+ results.add(results.get(Math.max(0, results.size() - 2)));
+ }
+
+ return results;
+ };
+ }
+}
diff --git a/src/main/java/com/ldtteam/blockui/README.md b/src/main/java/com/ldtteam/blockui/README.md
new file mode 100644
index 00000000..82b145b2
--- /dev/null
+++ b/src/main/java/com/ldtteam/blockui/README.md
@@ -0,0 +1,280 @@
+About BlockOut
+--------------
+BlockOut is a data-driven GUI library for Minecraft.
+
+BlockOut uses a hierarchical structure, consisting of a root Window, which contains one or more Panes and Views. Views
+are a type of Pane which can contain other Panes (and Views).
+
+Position coordinates in BlockOut are relative, where a Pane's x,y position is relative to the top-left of the parent
+View. There are various means of declaring the size and position of a Pane.
+
+***
+
+Usage
+-----
+
+### Installation
+Simply drop com.blockout into the source of the mod to start using it.
+
+
+### Code
+To display a Window, instantiate a Window (or subclass), then call:
+
+ yourWindow.open();
+
+The Window constructor takes a Resource Location path to the Layout file to use for the Window.
+
+If a Window requires no special code, you can directly instantiate `com.blockout.views.Window`. Otherwise, create a
+Java class that extends com.blockout.views.Window. Override Window methods to add additional behavior, such as click
+handling.
+
+If your Window subclass implements com.blockout.controls.ButtonHandler, it will automatically receive button events via
+the `onButtonClicked()`
+
+
+### Layout Files
+While you can programmatically create a BlockOut layout, the easiest method is to use a BlockOut layout files, which is
+an XML file that describes the layout of the Window.
+
+
+### Localization
+Text in Layout files is automatically localized. All text that is displayed to the user is parsed for tokens of the
+format "$(identifier)" and replaced with matching localized text.
+
+For example, if you have the following localized string in the language assest file:
+
+`com.yourmod.gui.string=Oranges`
+
+then a button defined in a layout file as:
+
+``
+
+the button will display the text "100 Oranges".
+
+
+***
+
+Layout File Definition
+----------------------
+BlockOut Layout Files are XML files. There are two root elements supported: `` and ``.
+
+A Window must reference an XML file that uses a `` root element, while files with a `` root element are
+for embedding via inclusion with the child element.
+
+``
+
+BlockOut XML files can inherit from other files, or embed them.
+
+The `xmlns:xsi` and `xsi:noNamespaceSchemaLocation` attributes are supported for either root element, and are optional,
+but their use allows you to point to the xsd file for editor validation purposes.
+
+#### Resource Location Paths
+Resource Location paths use the format: _modid_:path/under/mod/assets
+
+For example: "yourMod:gui/windows/myWindow.xml"
+
+is a path to the file: assets/yourMod/gui/windows/myWindow.xml
+
+
+#### Supported Colors
+When a color can be specified, the following formats are supported:
+
+* `CSS Hex Format:` #00aabbcc
+* `CSS RGB and RGBA formats:` rgb(255,0,0) and rgba(255,0,0,0.3)
+* `Integer:` 1632768
+* `Name:` aqua, black, blue, cyan, fuchsia, green, ivory, lime, magenta, orange, orangered, purple, red, white, yellow,
+ gray, darkgray, dimgray, lightgray, slategray
+
+
+#### Common Attributes
+These attributes are supported by all Pane types except the two root elements ( and )
+
+**Generic Attributes**
+
+* `id="{id}"` String identifier, for use by the code to access specific elements
+* `visible="{true|false}"` (Default=true) Visibility of a pane, allow a visual element to start hidden
+* `enabled="{true|false}"` (Default=true) Disabled panes do not receive clicks and may render differently
+* `style="{style}"` If additional styles have been registered for a Pane type, this will switch the
+ style of the Pane
+
+***
+**Size Attributes**
+
+* `size="{width} {height}"` Size pair defining the width and height of the Pane
+* `width="{width}"` Width only
+* `height="{height}"` Height only
+
+__width__ and __height__ values from these attributes may either be a number (e.g, "100" or "100px") or a percentage
+(e.g, "10%"). Percentage is treated as a percent of the parent's width or height, respectively.
+
+A negative __width__ or __height__ is treated as 100% of the parent's width or height, minus the absolute value.
+For example, if the parent is 80x200 pixels, and the pane has a specified size of "-25 -30%" it will have a size of
+55x140: 80-25 x 200-60.
+
+If you use a `size` attribute, do not use a `width` or `height` attribute.
+
+***
+**Positioning**
+
+* `align="{align}"` (Default=TopLeft) Alignment
+* `pos="{x} {y}"` Position pair defining the x and y offset of the Pane within its parent
+* `x="{x}"` x position only
+* `y="{y}"` y position only
+
+__x__ and __y__ values follow the same rules as __width__ and __height__ regarding the numerical values, percentages,
+and negative values.
+
+If you use a `pos` attribute, do not use an `x` or `y` attribute.
+
+`align` can be one of the following: TopLeft, TopMiddle, TopRight, MiddleLeft, Middle, MiddleRight, BottomLeft,
+BottomMiddle, BottomRight
+
+In the case of *Bottom* and *Right* alignment modes, positioning functions like CSS padding in 'relative' mode, such
+that the __x__ and __y__ position values are reversed - in a *Bottom* alignment mode, a positive __y__ will move the
+Pane up. Likewise, in the case of *Right* alignment modes, the __x__ attribute is reversed and moves the Pane left
+instead of right. These rules also apply in the case of text alignment and offset.
+
+***
+#### Window root element ``
+Root element for Window layout files. Does not support the Common attributes.
+
+Window elements can contain any non-root element.
+
+* `size="{width} {height}"` See 'Size Attributes' under Common Attributes above. Percentages are not supported.
+* `width="{width}"`
+* `height="{height}"`
+* `pause="true|false"` (Default=true) Pause the game when the Window is displayed
+* `lightbox="true|false"` (Default=true) Show a dimmed lightbox (like stock GUI)
+
+The default (and maximum) Window size is 420x240.
+
+***
+#### Layout root element ``
+Root element for embeddable layout files. Layout root elements have no attributes, and exist only as a container.
+
+Layout (root) elements can contain any non-root element.
+
+***
+#### View ``
+Views are simple containers, and can contain any non-root element.
+
+Child elements of Views (including Windows) that are entirely outside the View's bounds will not be rendered or receive
+clicks.
+
+* `padding="{pad}"` The usable interior of the View is reduced by the padding on all sides, and elements
+ are offset by the padding in both directions.
+
+***
+#### Group ``
+An automatically Y-sorted list of child elements.
+
+Child elements are automatically re-positioned to be sorted vertically, in the order they appear in the layout file.
+
+* `spacing="{spacing}"` Y-gap between elements
+
+***
+#### List View ``
+A scrolling list, using identical rows. Features a scroll-bar when the list cannot fit within the bounds of the Pane.
+
+Only the first child element defined in the file (and all of it's children) will be used, as the definition for the
+layout of the row.
+
+List views need code support, to provide a ScrollingList.DataProvider which defines the number of rows in the list, and
+handles setting up Panes in individual row elements.
+
+* `spacing="{spacing}"` Y-gap between row elements
+
+***
+#### Box ``
+A View which draws a box around it's border.
+
+* `color="{color}"` Color of the line; see 'Supported Colors', above
+* `linewidth="{width}"` Width of the line, in pixels
+
+***
+#### Switch View ``
+A View which only shows one direct child Pane/View at a time, with code support for switching between them.
+
+* `default="{id}"` Initial visible child pane. If none is specified, defaults to the first child.
+
+***
+#### Button `