diff --git a/.gitignore b/.gitignore
new file mode 100644
index 00000000..040cf24e
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,46 @@
+# CMake
+cmake-build-*/
+
+# File-based project format
+*.iws
+
+# IntelliJ
+out/
+
+# JIRA plugin
+atlassian-ide-plugin.xml
+
+# Crashlytics plugin (for Android Studio and IntelliJ)
+com_crashlytics_export_strings.xml
+crashlytics.properties
+crashlytics-build.properties
+fabric.properties
+
+### Gradle template
+.gradle
+/build/
+
+# Ignore Gradle GUI config
+gradle-app.setting
+
+# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
+!gradle-wrapper.jar
+
+# Cache of project
+.gradletasknamecache
+
+# We don't need those .rej files
+*.rej
+
+### Kettle
+/projects/
+/bin/
+
+### IDEs
+/.idea/
+.classpath
+.project
+/.settings/
+classes/
+
+run/
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
new file mode 100644
index 00000000..bbf0343e
--- /dev/null
+++ b/.gitlab-ci.yml
@@ -0,0 +1,42 @@
+image: openjdk:8-jdk
+
+stages:
+- setup
+- test
+- build
+
+before_script:
+# - echo `pwd` # debug
+# - echo "$CI_BUILD_NAME, $CI_BUILD_REF_NAME $CI_BUILD_STAGE" # debug
+- export GRADLE_USER_HOME=`pwd`/.gradle
+- git submodule sync --recursive
+- git submodule update --init --recursive
+
+cache:
+ paths:
+ - .gradle/wrapper
+ - .gradle/caches
+
+setup:
+ stage: setup
+ script:
+ - chmod +x gradlew && ./gradlew setup
+ - mv src/main/java/org* projects/Kettle/src/main/java
+
+test:
+ stage: test
+ script:
+ - chmod +x gradlew && ./gradlew check
+
+build:
+ stage: build
+ script:
+ - chmod +x gradlew && ./gradlew build githubRelease
+ only:
+ - master
+ artifacts:
+ paths:
+ - build/distributions/*.jar
+
+after_script:
+- echo "End CI"
diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 00000000..12f3481f
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,4 @@
+[submodule "forge"]
+ path = forge
+ url = https://github.com/MinecraftForge/MinecraftForge.git
+ branch = 1.12.x
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 00000000..3b1aa60e
--- /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.
+
+ Kettle
+ Copyright (C) 2019 Kettle Foundation
+
+ 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:
+
+ Kettle Copyright (C) 2019 Kettle Foundation
+ 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
+.
diff --git a/README.md b/README.md
new file mode 100644
index 00000000..fff6b4b9
--- /dev/null
+++ b/README.md
@@ -0,0 +1,47 @@
+
+
+# Magma
+
+ [](https://ci.hexeption.co.uk)
+
+### What's Magma?
+
+Magma next generation in hybrid servers.
+
+Kettle is based on Forge and Paper builds, meaning it can run both Craftbukkit/Spigot/Paper-based plugins and forge-based mods.
+
+We hope to eliminate all issues with craftbukkit forge servers. In the end, we envision a seamless, low lag Kettle experience with support for new 1.12+ versions of Minecraft.
+
+## Deployment
+
+### Installation
+
+1. Download the recommended builds from the [**Releases** section](https://github.com/KettleFoundation/Kettle/releases)
+ 1. Download Beta builds from the [**CI**](https://ci.hexeption.co.uk/job/Magma/)
+2. Make a new folder for the server
+3. Move the jar to the folder
+4. Run the jar
+
+### Building the sources
+
+All builds are available in `build/distributions`
+
+- Clone the Project
+ - You can use GitHub Desktop/GitKraken or clone using the terminal
+ - `git clone https://github.com/KettleFoundation/Kettle`
+ - Next you are gonna want to clone the submodule
+ - `git submodule update --init --recursive`
+- Building
+ - First you want to setup the project
+ - `./gradlew setup`
+ - After you have setup the project you are going to want to run the build
+ - `./gradlew build`
+ - Now go and get a drink this may take some time
+
+## Chat
+
+You are welcome to visit Kettle Discord server [here](https://discord.gg/RqDjbcM).
+
+## Unstable/Test builds
+
+For unstable/test builds you can check the [__CI__](https://ci.hexeption.co.uk/job/Magma)
\ No newline at end of file
diff --git a/build.gradle b/build.gradle
new file mode 100644
index 00000000..d25e35cc
--- /dev/null
+++ b/build.gradle
@@ -0,0 +1,253 @@
+buildscript {
+ repositories {
+ mavenLocal()
+ mavenCentral()
+ maven {
+ name = "forge"
+ url = "https://files.minecraftforge.net/maven"
+ }
+ maven {
+ name = "sonatype"
+ url = "https://oss.sonatype.org/content/repositories/snapshots/"
+ }
+ maven {
+ url "https://jcenter.bintray.com"
+ }
+ maven {
+ url "https://plugins.gradle.org/m2/"
+ }
+ }
+ dependencies {
+ classpath 'net.minecraftforge.gradle:ForgeGradle:2.3+'
+ classpath 'net.nemerosa:versioning:2.7.1'
+ classpath "gradle.plugin.com.github.breadmoirai:github-release:2.2.4"
+ }
+}
+
+apply plugin: 'java'
+apply plugin: 'maven'
+apply plugin: "idea"
+apply plugin: 'net.minecraftforge.gradle.patcher'
+apply plugin: 'net.minecraftforge.gradle.launch4j'
+apply plugin: 'net.nemerosa.versioning'
+apply plugin: "com.github.breadmoirai.github-release"
+
+group 'kettlefoundation'
+version 'git-' + versioning.info.branch + "-" + versioning.info.build
+
+repositories {
+ clear()
+ mavenCentral()
+ maven {
+ name = "forge"
+ url = "https://files.minecraftforge.net/maven"
+ }
+ maven {
+ name = "sonatype"
+ url = "https://oss.sonatype.org/content/repositories/snapshots/"
+ }
+ maven {
+ name 'minecraft'
+ url 'https://libraries.minecraft.net/'
+ }
+ maven {
+ name 'maven'
+ url 'https://mvnrepository.com/artifact/'
+ }
+ maven {
+ name 'KettleFoundation'
+ url 'https://repo.hexeption.co.uk/artifactory/Kettle/'
+ }
+ flatDir {
+ dirs 'src/main/resources'
+ }
+}
+
+configurations{
+ compile.extendsFrom exported
+ libraries
+}
+
+dependencies {
+ testCompile group: 'junit', name: 'junit', version: '4.12'
+ compile(group: 'bukkit', name: 'bukkit', version: '1.12.2-R0.1')
+}
+
+jar{
+ into('lib') {
+ from configurations.libraries
+ }
+ exclude "**/configurations/**"
+ exclude "**/META-INF/**"
+ exclude "log4j2.xml"
+}
+
+minecraft {
+ version = "1.12.2"
+ mappings = "snapshot_nodoc_20171003"
+ workspaceDir = "projects"
+ versionJson = "jsons/1.12.2-dev.json"
+ buildUserdev = true
+ buildInstaller = false
+ installerVersion = "1.5"
+
+ def common = {
+ patchPrefixOriginal "../src-base/minecraft"
+ patchPrefixChanged "../src-work/minecraft"
+ mainClassServer "net.minecraft.launchwrapper.Launch"
+ tweakClassServer "net.minecraftforge.fml.common.launcher.FMLServerTweaker"
+ }
+
+ projects {
+ forge {
+ rootDir "forge/"
+ patchDir "forge/patches/minecraft/"
+ patchAfter "clean"
+ genPatchesFrom "clean"
+ genMcpPatches = false
+ applyMcpPatches = false
+ s2sKeepImports = true
+ with common
+ }
+
+ kettle {
+ rootDir "."
+ patchDir "patches/"
+ patchAfter "forge"
+ genPatchesFrom "forge"
+ genMcpPatches = true
+ applyMcpPatches = true
+ s2sKeepImports = true
+ with common
+ }
+ }
+}
+
+sourceCompatibility = 1.8
+tasks.generateXmlConfig.dependsOn installer
+tasks.compileJava.enabled = false
+tasks.build.dependsOn 'launch4j'
+tasks.reobfuscate.setProperty("extraSrg",["PK: org/bukkit/craftbukkit org/bukkit/craftbukkit/v1_12_R1"])
+
+installer {
+ classifier = 'installer'
+ from "forge/src/main/resources/forge_logo.png"
+ rename "forge_logo\\.png", "big_logo.png"
+}
+
+launch4j {
+ jar = installer.archivePath.canonicalPath
+ outfile = file("build/distributions/${project.name}-${project.version}-installer-win.exe").canonicalPath
+ icon = file('icon.ico').canonicalPath
+ manifest = file('l4jManifest.xml').canonicalPath
+ jreMinVersion = '1.8.0'
+ initialHeapPercent = 5
+ maxHeapPercent = 100
+}
+
+tasks.withType(JavaCompile) {
+ options.encoding = 'UTF-8'
+}
+
+task signUniversal(type: SignJar, dependsOn: 'outputJar') {
+ onlyIf {
+ project.hasProperty('jarsigner')
+ }
+
+ def jarsigner = [:]
+
+ if (project.hasProperty('jarsigner'))
+ jarsigner = project.jarsigner
+
+ alias = 'forge'
+ exclude "paulscode/**"
+ storePass = jarsigner.storepass
+ keyPass = jarsigner.keypass
+ keyStore = jarsigner.keystore
+ inputFile = outputJar.archivePath
+ outputFile = outputJar.archivePath
+}
+build.dependsOn signUniversal
+installer.dependsOn signUniversal
+
+outputJar {
+ classifier = 'universal'
+
+ manifest.attributes([
+ "Implementation-Title": "Kettle",
+ "Implementation-Version": version,
+ "Main-Class": "net.minecraftforge.fml.relauncher.ServerLaunchWrapper",
+ "TweakClass": "net.minecraftforge.fml.common.launcher.FMLTweaker",
+ "Class-Path": getServerClasspath(file("jsons/1.12.2-rel.json"))
+ ])
+}
+
+processJson {
+ releaseJson = "jsons/1.12.2-rel.json"
+ addReplacements([
+ "@minecraft_version@": project.minecraft.version,
+ "@version@": project.version,
+ "@project@": "kettle",
+ "@artifact@": "kf:kettle:${project.version}",
+ "@universal_jar@": { outputJar.archiveName },
+ "@timestamp@": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"),
+ ])
+}
+
+extractForgeSources {
+ exclude "**/SideOnly.java", "**/Side.java"
+}
+
+genGradleProjects {
+ addCompileDep "junit:junit:4.12"
+ addCompileDep "bukkit:bukkit:1.12.2-R0.1"
+ addRepo("KettleFoundation", "https://repo.hexeption.co.uk/artifactory/Kettle/")
+}
+
+import groovy.json.JsonSlurper
+
+import java.util.stream.Collectors
+
+String getServerClasspath(File file) {
+ def node = new JsonSlurper().parse(file)
+ def out = new StringBuilder()
+ node.versionInfo.libraries.each { lib ->
+ if (lib.serverreq)
+ {
+ def split = lib.name.split(':')
+ def group = split[0].replace('.', '/')
+ def artifact = split[1]
+ def version = split[2]
+ out += "libraries/$group/$artifact/$version/$artifact-${version}.jar "
+ }
+ }
+ out += "minecraft_server.1.12.2.jar"
+ return out.toString()
+}
+
+githubRelease {
+ if(System.getenv("GITHUB_TOKEN") != null){
+ token System.getenv("GITHUB_TOKEN")
+ }else{
+ token ""
+ }
+ owner "KettleFoundation"
+ repo "Kettle"
+ releaseName "Kettle Dev " + versioning.info.branch + "-" + versioning.info.build
+ body {
+ """\
+## Setup Info
+Don't forget to download [Minecraft Server 1.12.2](https://launcher.mojang.com/mc/game/1.12.2/server/886945bfb2b978778c3a0288fd7fab09d315b25f/server.jar)
+
+(Rename it to `minecraft_server.1.12.2.jar`)
+
+${(changelog().call().readLines().stream().map { "- $it" }.collect(Collectors.joining('\n', '## Changelog\n', '')))}
+ """
+ }
+ prerelease true
+ draft true
+ releaseAssets = [
+ fileTree("build/distributions/").filter { it.name.endsWith("jar") || it.name.endsWith("zip") },
+ fileTree("/release/").filter { it.name.endsWith("zip") }
+ ]
+}
\ No newline at end of file
diff --git a/forge b/forge
new file mode 160000
index 00000000..8c046513
--- /dev/null
+++ b/forge
@@ -0,0 +1 @@
+Subproject commit 8c04651301d86edc02ac10a15af243869c87ac51
diff --git a/gradle.properties b/gradle.properties
new file mode 100644
index 00000000..d2f86115
--- /dev/null
+++ b/gradle.properties
@@ -0,0 +1,4 @@
+org.gradle.daemon=true
+org.gradle.parallel=true
+org.gradle.configureondemand=true
+org.gradle.jvmargs=-Xmx3g -XX:MaxPermSize=2048m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar
new file mode 100644
index 00000000..1948b907
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..0de4674c
--- /dev/null
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -0,0 +1,6 @@
+#Tue Feb 12 08:55:53 GMT 2019
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
+distributionUrl=https\://services.gradle.org/distributions/gradle-5.1-all.zip
diff --git a/gradlew b/gradlew
new file mode 100644
index 00000000..cccdd3d5
--- /dev/null
+++ b/gradlew
@@ -0,0 +1,172 @@
+#!/usr/bin/env sh
+
+##############################################################################
+##
+## 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=""
+
+# 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
+ ;;
+ 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, switch paths to Windows format before running java
+if $cygwin ; 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=$((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"
+
+# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
+if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
+ cd "$(dirname "$0")"
+fi
+
+exec "$JAVACMD" "$@"
diff --git a/gradlew.bat b/gradlew.bat
new file mode 100644
index 00000000..f9553162
--- /dev/null
+++ b/gradlew.bat
@@ -0,0 +1,84 @@
+@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 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=
+
+@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 init
+
+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 init
+
+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
+
+:init
+@rem Get command-line arguments, handling Windows variants
+
+if not "%OS%" == "Windows_NT" goto win9xME_args
+
+:win9xME_args
+@rem Slurp the command line arguments.
+set CMD_LINE_ARGS=
+set _SKIP=2
+
+:win9xME_args_slurp
+if "x%~1" == "x" goto execute
+
+set CMD_LINE_ARGS=%*
+
+: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 %CMD_LINE_ARGS%
+
+: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/jsons/1.12.2-dev.json b/jsons/1.12.2-dev.json
new file mode 100644
index 00000000..0bbda81c
--- /dev/null
+++ b/jsons/1.12.2-dev.json
@@ -0,0 +1,147 @@
+{
+ "id": "@minecraft_version@-@project@@version@",
+ "time": "@timestamp@",
+ "releaseTime": "1960-01-01T00:00:00-0700",
+ "type": "release",
+ "inheritsFrom": "1.12.2",
+ "minecraftArguments": "--version FML_DEV --tweakClass net.minecraftforge.fml.common.launcher.FMLTweaker",
+ "libraries": [
+ {
+ "name": "net.minecraft:launchwrapper:1.12"
+ },
+ {
+ "name": "org.jline:jline:3.5.1",
+ "children": ["sources"],
+ "url" : "http://repo.maven.apache.org/maven2"
+ },
+ {
+ "name": "jline:jline:2.13",
+ "children": ["sources"],
+ "url" : "http://repo.maven.apache.org/maven2"
+ },
+ {
+ "name": "com.google.code.findbugs:jsr305:1.3.9",
+ "children": ["sources"],
+ "url" : "http://repo.maven.apache.org/maven2"
+ },
+ {
+ "name": "org.ow2.asm:asm-debug-all:5.2",
+ "children" : ["sources"],
+ "url" : "http://repo.maven.apache.org/maven2"
+ },
+ {
+ "name": "com.typesafe.akka:akka-actor_2.11:2.3.3",
+ "children" : ["sources"],
+ "url" : "http://repo.maven.apache.org/maven2"
+ },
+ {
+ "name": "com.typesafe:config:1.2.1",
+ "children" : ["sources"],
+ "url" : "http://repo.maven.apache.org/maven2"
+ },
+ {
+ "name": "org.scala-lang:scala-actors-migration_2.11:1.1.0",
+ "children" : ["sources"],
+ "url" : "http://repo.maven.apache.org/maven2"
+ },
+ {
+ "name": "org.scala-lang:scala-compiler:2.11.1",
+ "children" : ["sources"],
+ "url" : "http://repo.maven.apache.org/maven2"
+ },
+ {
+ "name": "org.scala-lang.plugins:scala-continuations-library_2.11:1.0.2",
+ "children" : ["sources"],
+ "url" : "http://repo.maven.apache.org/maven2"
+ },
+ {
+ "name": "org.scala-lang.plugins:scala-continuations-plugin_2.11.1:1.0.2",
+ "children" : ["sources"],
+ "url" : "http://repo.maven.apache.org/maven2"
+ },
+ {
+ "name": "org.scala-lang:scala-library:2.11.1",
+ "children" : ["sources"],
+ "url" : "http://repo.maven.apache.org/maven2"
+ },
+ {
+ "name": "org.scala-lang.modules:scala-parser-combinators_2.11:1.0.1",
+ "children" : ["sources"],
+ "url" : "http://repo.maven.apache.org/maven2"
+ },
+ {
+ "name": "org.scala-lang:scala-reflect:2.11.1",
+ "children" : ["sources"],
+ "url" : "http://repo.maven.apache.org/maven2"
+ },
+ {
+ "name": "org.scala-lang.modules:scala-swing_2.11:1.0.1",
+ "children" : ["sources"],
+ "url" : "http://repo.maven.apache.org/maven2"
+ },
+ {
+ "name": "org.scala-lang.modules:scala-xml_2.11:1.0.2",
+ "children" : ["sources"],
+ "url" : "http://repo.maven.apache.org/maven2"
+ },
+ {
+ "name" : "com.googlecode.json-simple:json-simple:1.1.1",
+ "children" : ["sources"],
+ "url" : "http://repo.maven.apache.org/maven2"
+ },
+ {
+ "name" : "org.yaml:snakeyaml:1.23",
+ "children" : ["sources"],
+ "url" : "http://repo.maven.apache.org/maven2"
+ },
+ {
+ "name": "lzma:lzma:0.0.1"
+ },
+ {
+ "name": "java3d:vecmath:1.5.2"
+ },
+ {
+ "name": "net.sf.trove4j:trove4j:3.0.3"
+ },
+ {
+ "name": "org.xerial:sqlite-jdbc:3.21.0.1",
+ "children" : ["sources"],
+ "url" : "http://repo.maven.apache.org/maven2"
+ },
+ {
+ "name": "mysql:mysql-connector-java:5.1.46",
+ "children" : ["sources"],
+ "url" : "http://repo.maven.apache.org/maven2"
+ },
+ {
+ "name": "net.md-5:SpecialSource:1.8.5",
+ "children" : ["sources"],
+ "url" : "https://hub.spigotmc.org/nexus/content/groups/public/"
+ },
+ {
+ "name": "net.md-5:bungeecord-chat:1.12-SNAPSHOT",
+ "children" : ["sources"],
+ "url" : "https://hub.spigotmc.org/nexus/content/groups/public/"
+ },
+ {
+ "name": "org.apache.commons:commons-lang3:3.5",
+ "children" : ["sources"],
+ "url" : "http://repo.maven.apache.org/maven2"
+ },
+ {
+ "name": "commons-lang:commons-lang:2.6",
+ "children" : ["sources"],
+ "url" : "http://repo.maven.apache.org/maven2"
+ },
+ {
+ "name": "co.aikar:fastutil-lite:1.0",
+ "children" : ["sources"],
+ "url" : "https://papermc.io/repo/repository/maven-public/"
+ },
+ {
+ "name": "org.apache.maven:maven-artifact:3.5.3",
+ "children" : ["sources"],
+ "url" : "http://repo.maven.apache.org/maven2"
+ }
+ ]
+}
diff --git a/jsons/1.12.2-rel.json b/jsons/1.12.2-rel.json
new file mode 100644
index 00000000..426195d0
--- /dev/null
+++ b/jsons/1.12.2-rel.json
@@ -0,0 +1,217 @@
+{
+"install": {
+ "profileName": "@project@",
+ "target":"@minecraft_version@-@project@@version@",
+ "path":"@artifact@",
+ "version":"@project@ @version@",
+ "filePath":"@universal_jar@",
+ "welcome":"Welcome to the simple @project@ installer.",
+ "minecraft":"@minecraft_version@",
+ "mirrorList" : "http://files.minecraftforge.net/mirror-brand.list",
+ "logo":"/big_logo.png",
+ "modList":"none"
+},
+"versionInfo": {
+ "id": "@minecraft_version@-@project@@version@",
+ "time": "@timestamp@",
+ "releaseTime": "1960-01-01T00:00:00-0700",
+ "type": "release",
+ "minecraftArguments": "--username ${auth_player_name} --version ${version_name} --gameDir ${game_directory} --assetsDir ${assets_root} --assetIndex ${assets_index_name} --uuid ${auth_uuid} --accessToken ${auth_access_token} --userType ${user_type} --tweakClass net.minecraftforge.fml.common.launcher.FMLTweaker --versionType Forge",
+ "mainClass": "net.minecraft.launchwrapper.Launch",
+ "inheritsFrom": "1.12.2",
+ "jar": "1.12.2",
+ "logging": {},
+ "libraries": [
+ {
+ "name": "@artifact@",
+ "url": "http://files.minecraftforge.net/maven/"
+ },
+ {
+ "name": "net.minecraft:launchwrapper:1.12",
+ "serverreq":true
+ },
+ {
+ "name": "org.ow2.asm:asm-all:5.2",
+ "url" : "http://files.minecraftforge.net/maven/",
+ "checksums" : [ "2ea49e08b876bbd33e0a7ce75c8f371d29e1f10a" ],
+ "serverreq":true,
+ "clientreq":true
+ },
+ {
+ "name": "org.jline:jline:3.5.1",
+ "url" : "http://files.minecraftforge.net/maven/",
+ "checksums" : [ "51800e9d7a13608894a5a28eed0f5c7fa2f300fb" ],
+ "serverreq":true,
+ "clientreq":false
+ },
+ {
+ "name": "net.java.dev.jna:jna:4.4.0",
+ "serverreq":true,
+ "clientreq":false
+ },
+ {
+ "name": "com.typesafe.akka:akka-actor_2.11:2.3.3",
+ "url" : "http://files.minecraftforge.net/maven/",
+ "checksums" : [ "ed62e9fc709ca0f2ff1a3220daa8b70a2870078e", "25a86ccfdb6f6dfe08971f4825d0a01be83a6f2e" ],
+ "serverreq":true,
+ "clientreq":true
+ },
+ {
+ "name": "com.typesafe:config:1.2.1",
+ "url" : "http://files.minecraftforge.net/maven/",
+ "checksums" : [ "f771f71fdae3df231bcd54d5ca2d57f0bf93f467", "7d7bc36df0989d72f2d5d057309675777acc528b" ],
+ "serverreq":true,
+ "clientreq":true
+ },
+ {
+ "name": "org.scala-lang:scala-actors-migration_2.11:1.1.0",
+ "url" : "http://files.minecraftforge.net/maven/",
+ "checksums" : [ "dfa8bc42b181d5b9f1a5dd147f8ae308b893eb6f", "8c9aaeeb68487ca519411a14068e1b4d69739207" ],
+ "serverreq":true,
+ "clientreq":true
+ },
+ {
+ "name": "org.scala-lang:scala-compiler:2.11.1",
+ "url" : "http://files.minecraftforge.net/maven/",
+ "checksums" : [ "56ea2e6c025e0821f28d73ca271218b8dd04926a", "1444992390544ba3780867a13ff696a89d7d1639" ],
+ "serverreq":true,
+ "clientreq":true
+ },
+ {
+ "name": "org.scala-lang.plugins:scala-continuations-library_2.11:1.0.2",
+ "url" : "http://files.minecraftforge.net/maven/",
+ "checksums" : [ "87213338cd5a153a7712cb574c0ddd2edfee0386", "0b4c1bf8d48993f138d6e10c0c144e50acfff581" ],
+ "serverreq":true,
+ "clientreq":true
+ },
+ {
+ "name": "org.scala-lang.plugins:scala-continuations-plugin_2.11.1:1.0.2",
+ "url" : "http://files.minecraftforge.net/maven/",
+ "checksums" : [ "1f7371605d4ba42aa26d3443440c0083c587b4e9", "1ea655dda4504ae0a367327e2340cd3beaee6c73" ],
+ "serverreq":true,
+ "clientreq":true
+ },
+ {
+ "name": "org.scala-lang:scala-library:2.11.1",
+ "url" : "http://files.minecraftforge.net/maven/",
+ "checksums" : [ "0e11da23da3eabab9f4777b9220e60d44c1aab6a", "1e4df76e835201c6eabd43adca89ab11f225f134" ],
+ "serverreq":true,
+ "clientreq":true
+ },
+ {
+ "name": "org.scala-lang:scala-parser-combinators_2.11:1.0.1",
+ "url" : "http://files.minecraftforge.net/maven/",
+ "checksums" : [ "f05d7345bf5a58924f2837c6c1f4d73a938e1ff0", "a1cbbcbde1dcc614f4253ed1aa0b320bc78d8f1d" ],
+ "serverreq":true,
+ "clientreq":true
+ },
+ {
+ "name": "org.scala-lang:scala-reflect:2.11.1",
+ "url" : "http://files.minecraftforge.net/maven/",
+ "checksums" : [ "6580347e61cc7f8e802941e7fde40fa83b8badeb", "91ce0f0be20f4a536321724b4b3bbc6530ddcd88" ],
+ "serverreq":true,
+ "clientreq":true
+ },
+ {
+ "name": "org.scala-lang:scala-swing_2.11:1.0.1",
+ "url" : "http://files.minecraftforge.net/maven/",
+ "checksums" : [ "b1cdd92bd47b1e1837139c1c53020e86bb9112ae", "d77152691dcf5bbdb00529af37aa7d3d887b3e63" ],
+ "serverreq":true,
+ "clientreq":true
+ },
+ {
+ "name": "org.scala-lang:scala-xml_2.11:1.0.2",
+ "url" : "http://files.minecraftforge.net/maven/",
+ "checksums" : [ "7a80ec00aec122fba7cd4e0d4cdd87ff7e4cb6d0", "62736b01689d56b6d09a0164b7ef9da2b0b9633d" ],
+ "serverreq":true,
+ "clientreq":true
+ },
+ {
+ "name" : "com.googlecode.json-simple:json-simple:1.1.1",
+ "url" : "http://repo.maven.apache.org/maven2",
+ "serverreq":true,
+ "clientreq":true
+ },
+ {
+ "name" : "org.yaml:snakeyaml:1.23",
+ "url" : "http://repo.maven.apache.org/maven2",
+ "serverreq":true,
+ "clientreq":true
+ },
+ {
+ "name": "lzma:lzma:0.0.1",
+ "serverreq":true
+ },
+ {
+ "name": "net.sf.jopt-simple:jopt-simple:5.0.3",
+ "serverreq":true
+ },
+ {
+ "name": "java3d:vecmath:1.5.2",
+ "clientreq":true,
+ "serverreq":true
+ },
+ {
+ "name": "net.sf.trove4j:trove4j:3.0.3",
+ "clientreq":true,
+ "serverreq":true
+ },
+ {
+ "name": "mysql:mysql-connector-java:5.1.46",
+ "url" : "http://repo.maven.apache.org/maven2",
+ "clientreq":true,
+ "serverreq":true
+ },
+ {
+ "name": "org.xerial:sqlite-jdbc:3.21.0.1",
+ "url" : "http://repo.maven.apache.org/maven2",
+ "clientreq":true,
+ "serverreq":true
+ },
+ {
+ "name": "org.apache.commons:commons-lang3:3.5",
+ "url" : "http://repo.maven.apache.org/maven2",
+ "clientreq":true,
+ "serverreq":true
+ },
+ {
+ "name": "commons-lang:commons-lang:2.6",
+ "url" : "http://repo.maven.apache.org/maven2",
+ "clientreq":true,
+ "serverreq":true
+ },
+ {
+ "name": "net.md-5:SpecialSource:1.8.5",
+ "url" : "https://hub.spigotmc.org/nexus/content/groups/public/",
+ "clientreq":true,
+ "serverreq":true
+ },
+ {
+ "name": "jline:jline:2.13",
+ "url" : "http://repo.maven.apache.org/maven2",
+ "clientreq":true,
+ "serverreq":true
+ },
+ {
+ "name": "net.md-5:bungeecord-chat:1.12-SNAPSHOT",
+ "url" : "https://hub.spigotmc.org/nexus/content/groups/public/",
+ "clientreq":true,
+ "serverreq":true
+ },
+ {
+ "name": "co.aikar:fastutil-lite:1.0",
+ "url" : "https://papermc.io/repo/repository/maven-public/",
+ "clientreq":true,
+ "serverreq":true
+ },
+ {
+ "name": "org.apache.maven:maven-artifact:3.5.3",
+ "url" : "http://files.minecraftforge.net/maven/",
+ "clientreq":true,
+ "serverreq":true
+ }
+ ]
+},
+"optionals": [
+]
+}
diff --git a/jsons/1.12.2.json b/jsons/1.12.2.json
new file mode 100644
index 00000000..dbe4d3f4
--- /dev/null
+++ b/jsons/1.12.2.json
@@ -0,0 +1 @@
+{"assetIndex": {"id": "1.12", "sha1": "1584b57c1a0b5e593fad1f5b8f78536ca640547b", "size": 143138, "totalSize": 129336389, "url": "https://launchermeta.mojang.com/v1/packages/1584b57c1a0b5e593fad1f5b8f78536ca640547b/1.12.json"}, "assets": "1.12", "downloads": {"client": {"sha1": "0f275bc1547d01fa5f56ba34bdc87d981ee12daf", "size": 10180113, "url": "https://launcher.mojang.com/v1/objects/0f275bc1547d01fa5f56ba34bdc87d981ee12daf/client.jar"}, "server": {"sha1": "886945bfb2b978778c3a0288fd7fab09d315b25f", "size": 30222121, "url": "https://launcher.mojang.com/v1/objects/886945bfb2b978778c3a0288fd7fab09d315b25f/server.jar"}}, "id": "1.12.2", "libraries": [{"downloads": {"artifact": {"path": "com/mojang/patchy/1.1/patchy-1.1.jar", "sha1": "aef610b34a1be37fa851825f12372b78424d8903", "size": 15817, "url": "https://libraries.minecraft.net/com/mojang/patchy/1.1/patchy-1.1.jar"}}, "name": "com.mojang:patchy:1.1"}, {"downloads": {"artifact": {"path": "oshi-project/oshi-core/1.1/oshi-core-1.1.jar", "sha1": "9ddf7b048a8d701be231c0f4f95fd986198fd2d8", "size": 30973, "url": "https://libraries.minecraft.net/oshi-project/oshi-core/1.1/oshi-core-1.1.jar"}}, "name": "oshi-project:oshi-core:1.1"}, {"downloads": {"artifact": {"path": "net/java/dev/jna/jna/4.4.0/jna-4.4.0.jar", "sha1": "cb208278274bf12ebdb56c61bd7407e6f774d65a", "size": 1091208, "url": "https://libraries.minecraft.net/net/java/dev/jna/jna/4.4.0/jna-4.4.0.jar"}}, "name": "net.java.dev.jna:jna:4.4.0"}, {"downloads": {"artifact": {"path": "net/java/dev/jna/platform/3.4.0/platform-3.4.0.jar", "sha1": "e3f70017be8100d3d6923f50b3d2ee17714e9c13", "size": 913436, "url": "https://libraries.minecraft.net/net/java/dev/jna/platform/3.4.0/platform-3.4.0.jar"}}, "name": "net.java.dev.jna:platform:3.4.0"}, {"downloads": {"artifact": {"path": "com/ibm/icu/icu4j-core-mojang/51.2/icu4j-core-mojang-51.2.jar", "sha1": "63d216a9311cca6be337c1e458e587f99d382b84", "size": 1634692, "url": "https://libraries.minecraft.net/com/ibm/icu/icu4j-core-mojang/51.2/icu4j-core-mojang-51.2.jar"}}, "name": "com.ibm.icu:icu4j-core-mojang:51.2"}, {"downloads": {"artifact": {"path": "net/sf/jopt-simple/jopt-simple/5.0.3/jopt-simple-5.0.3.jar", "sha1": "cdd846cfc4e0f7eefafc02c0f5dce32b9303aa2a", "size": 78175, "url": "https://libraries.minecraft.net/net/sf/jopt-simple/jopt-simple/5.0.3/jopt-simple-5.0.3.jar"}}, "name": "net.sf.jopt-simple:jopt-simple:5.0.3"}, {"downloads": {"artifact": {"path": "com/paulscode/codecjorbis/20101023/codecjorbis-20101023.jar", "sha1": "c73b5636faf089d9f00e8732a829577de25237ee", "size": 103871, "url": "https://libraries.minecraft.net/com/paulscode/codecjorbis/20101023/codecjorbis-20101023.jar"}}, "name": "com.paulscode:codecjorbis:20101023"}, {"downloads": {"artifact": {"path": "com/paulscode/codecwav/20101023/codecwav-20101023.jar", "sha1": "12f031cfe88fef5c1dd36c563c0a3a69bd7261da", "size": 5618, "url": "https://libraries.minecraft.net/com/paulscode/codecwav/20101023/codecwav-20101023.jar"}}, "name": "com.paulscode:codecwav:20101023"}, {"downloads": {"artifact": {"path": "com/paulscode/libraryjavasound/20101123/libraryjavasound-20101123.jar", "sha1": "5c5e304366f75f9eaa2e8cca546a1fb6109348b3", "size": 21679, "url": "https://libraries.minecraft.net/com/paulscode/libraryjavasound/20101123/libraryjavasound-20101123.jar"}}, "name": "com.paulscode:libraryjavasound:20101123"}, {"downloads": {"artifact": {"path": "com/paulscode/librarylwjglopenal/20100824/librarylwjglopenal-20100824.jar", "sha1": "73e80d0794c39665aec3f62eee88ca91676674ef", "size": 18981, "url": "https://libraries.minecraft.net/com/paulscode/librarylwjglopenal/20100824/librarylwjglopenal-20100824.jar"}}, "name": "com.paulscode:librarylwjglopenal:20100824"}, {"downloads": {"artifact": {"path": "com/paulscode/soundsystem/20120107/soundsystem-20120107.jar", "sha1": "419c05fe9be71f792b2d76cfc9b67f1ed0fec7f6", "size": 65020, "url": "https://libraries.minecraft.net/com/paulscode/soundsystem/20120107/soundsystem-20120107.jar"}}, "name": "com.paulscode:soundsystem:20120107"}, {"downloads": {"artifact": {"path": "io/netty/netty-all/4.1.9.Final/netty-all-4.1.9.Final.jar", "sha1": "0097860965d6a0a6b98e7f569f3f966727b8db75", "size": 3511093, "url": "https://libraries.minecraft.net/io/netty/netty-all/4.1.9.Final/netty-all-4.1.9.Final.jar"}}, "name": "io.netty:netty-all:4.1.9.Final"}, {"downloads": {"artifact": {"path": "com/google/guava/guava/21.0/guava-21.0.jar", "sha1": "3a3d111be1be1b745edfa7d91678a12d7ed38709", "size": 2521113, "url": "https://libraries.minecraft.net/com/google/guava/guava/21.0/guava-21.0.jar"}}, "name": "com.google.guava:guava:21.0"}, {"downloads": {"artifact": {"path": "org/apache/commons/commons-lang3/3.5/commons-lang3-3.5.jar", "sha1": "6c6c702c89bfff3cd9e80b04d668c5e190d588c6", "size": 479881, "url": "https://libraries.minecraft.net/org/apache/commons/commons-lang3/3.5/commons-lang3-3.5.jar"}}, "name": "org.apache.commons:commons-lang3:3.5"}, {"downloads": {"artifact": {"path": "commons-io/commons-io/2.5/commons-io-2.5.jar", "sha1": "2852e6e05fbb95076fc091f6d1780f1f8fe35e0f", "size": 208700, "url": "https://libraries.minecraft.net/commons-io/commons-io/2.5/commons-io-2.5.jar"}}, "name": "commons-io:commons-io:2.5"}, {"downloads": {"artifact": {"path": "commons-codec/commons-codec/1.10/commons-codec-1.10.jar", "sha1": "4b95f4897fa13f2cd904aee711aeafc0c5295cd8", "size": 284184, "url": "https://libraries.minecraft.net/commons-codec/commons-codec/1.10/commons-codec-1.10.jar"}}, "name": "commons-codec:commons-codec:1.10"}, {"downloads": {"artifact": {"path": "net/java/jinput/jinput/2.0.5/jinput-2.0.5.jar", "sha1": "39c7796b469a600f72380316f6b1f11db6c2c7c4", "size": 208338, "url": "https://libraries.minecraft.net/net/java/jinput/jinput/2.0.5/jinput-2.0.5.jar"}}, "name": "net.java.jinput:jinput:2.0.5"}, {"downloads": {"artifact": {"path": "net/java/jutils/jutils/1.0.0/jutils-1.0.0.jar", "sha1": "e12fe1fda814bd348c1579329c86943d2cd3c6a6", "size": 7508, "url": "https://libraries.minecraft.net/net/java/jutils/jutils/1.0.0/jutils-1.0.0.jar"}}, "name": "net.java.jutils:jutils:1.0.0"}, {"downloads": {"artifact": {"path": "com/google/code/gson/gson/2.8.0/gson-2.8.0.jar", "sha1": "c4ba5371a29ac9b2ad6129b1d39ea38750043eff", "size": 231952, "url": "https://libraries.minecraft.net/com/google/code/gson/gson/2.8.0/gson-2.8.0.jar"}}, "name": "com.google.code.gson:gson:2.8.0"}, {"downloads": {"artifact": {"path": "com/mojang/authlib/1.5.25/authlib-1.5.25.jar", "sha1": "9834cdf236c22e84b946bba989e2f94ef5897c3c", "size": 65621, "url": "https://libraries.minecraft.net/com/mojang/authlib/1.5.25/authlib-1.5.25.jar"}}, "name": "com.mojang:authlib:1.5.25"}, {"downloads": {"artifact": {"path": "com/mojang/realms/1.10.22/realms-1.10.22.jar", "sha1": "bd0dccebdf3744c75f1ca20063f16e8f7d5e663f", "size": 7135057, "url": "https://libraries.minecraft.net/com/mojang/realms/1.10.22/realms-1.10.22.jar"}}, "name": "com.mojang:realms:1.10.22"}, {"downloads": {"artifact": {"path": "org/apache/commons/commons-compress/1.8.1/commons-compress-1.8.1.jar", "sha1": "a698750c16740fd5b3871425f4cb3bbaa87f529d", "size": 365552, "url": "https://libraries.minecraft.net/org/apache/commons/commons-compress/1.8.1/commons-compress-1.8.1.jar"}}, "name": "org.apache.commons:commons-compress:1.8.1"}, {"downloads": {"artifact": {"path": "org/apache/httpcomponents/httpclient/4.3.3/httpclient-4.3.3.jar", "sha1": "18f4247ff4572a074444572cee34647c43e7c9c7", "size": 589512, "url": "https://libraries.minecraft.net/org/apache/httpcomponents/httpclient/4.3.3/httpclient-4.3.3.jar"}}, "name": "org.apache.httpcomponents:httpclient:4.3.3"}, {"downloads": {"artifact": {"path": "commons-logging/commons-logging/1.1.3/commons-logging-1.1.3.jar", "sha1": "f6f66e966c70a83ffbdb6f17a0919eaf7c8aca7f", "size": 62050, "url": "https://libraries.minecraft.net/commons-logging/commons-logging/1.1.3/commons-logging-1.1.3.jar"}}, "name": "commons-logging:commons-logging:1.1.3"}, {"downloads": {"artifact": {"path": "org/apache/httpcomponents/httpcore/4.3.2/httpcore-4.3.2.jar", "sha1": "31fbbff1ddbf98f3aa7377c94d33b0447c646b6e", "size": 282269, "url": "https://libraries.minecraft.net/org/apache/httpcomponents/httpcore/4.3.2/httpcore-4.3.2.jar"}}, "name": "org.apache.httpcomponents:httpcore:4.3.2"}, {"downloads": {"artifact": {"path": "it/unimi/dsi/fastutil/7.1.0/fastutil-7.1.0.jar", "sha1": "9835253257524c1be7ab50c057aa2d418fb72082", "size": 17655579, "url": "https://libraries.minecraft.net/it/unimi/dsi/fastutil/7.1.0/fastutil-7.1.0.jar"}}, "name": "it.unimi.dsi:fastutil:7.1.0"}, {"downloads": {"artifact": {"path": "org/apache/logging/log4j/log4j-api/2.8.1/log4j-api-2.8.1.jar", "sha1": "e801d13612e22cad62a3f4f3fe7fdbe6334a8e72", "size": 228859, "url": "https://libraries.minecraft.net/org/apache/logging/log4j/log4j-api/2.8.1/log4j-api-2.8.1.jar"}}, "name": "org.apache.logging.log4j:log4j-api:2.8.1"}, {"downloads": {"artifact": {"path": "org/apache/logging/log4j/log4j-core/2.8.1/log4j-core-2.8.1.jar", "sha1": "4ac28ff2f1ddf05dae3043a190451e8c46b73c31", "size": 1402925, "url": "https://libraries.minecraft.net/org/apache/logging/log4j/log4j-core/2.8.1/log4j-core-2.8.1.jar"}}, "name": "org.apache.logging.log4j:log4j-core:2.8.1"}, {"downloads": {"artifact": {"path": "org/lwjgl/lwjgl/lwjgl/2.9.4-nightly-20150209/lwjgl-2.9.4-nightly-20150209.jar", "sha1": "697517568c68e78ae0b4544145af031c81082dfe", "size": 1047168, "url": "https://libraries.minecraft.net/org/lwjgl/lwjgl/lwjgl/2.9.4-nightly-20150209/lwjgl-2.9.4-nightly-20150209.jar"}}, "name": "org.lwjgl.lwjgl:lwjgl:2.9.4-nightly-20150209", "rules": [{"action": "allow"}, {"action": "disallow", "os": {"name": "osx"}}]}, {"downloads": {"artifact": {"path": "org/lwjgl/lwjgl/lwjgl_util/2.9.4-nightly-20150209/lwjgl_util-2.9.4-nightly-20150209.jar", "sha1": "d51a7c040a721d13efdfbd34f8b257b2df882ad0", "size": 173887, "url": "https://libraries.minecraft.net/org/lwjgl/lwjgl/lwjgl_util/2.9.4-nightly-20150209/lwjgl_util-2.9.4-nightly-20150209.jar"}}, "name": "org.lwjgl.lwjgl:lwjgl_util:2.9.4-nightly-20150209", "rules": [{"action": "allow"}, {"action": "disallow", "os": {"name": "osx"}}]}, {"downloads": {"artifact": {"path": "org/lwjgl/lwjgl/lwjgl-platform/2.9.4-nightly-20150209/lwjgl-platform-2.9.4-nightly-20150209.jar", "sha1": "b04f3ee8f5e43fa3b162981b50bb72fe1acabb33", "size": 22, "url": "https://libraries.minecraft.net/org/lwjgl/lwjgl/lwjgl-platform/2.9.4-nightly-20150209/lwjgl-platform-2.9.4-nightly-20150209.jar"}, "classifiers": {"natives-linux": {"path": "org/lwjgl/lwjgl/lwjgl-platform/2.9.4-nightly-20150209/lwjgl-platform-2.9.4-nightly-20150209-natives-linux.jar", "sha1": "931074f46c795d2f7b30ed6395df5715cfd7675b", "size": 578680, "url": "https://libraries.minecraft.net/org/lwjgl/lwjgl/lwjgl-platform/2.9.4-nightly-20150209/lwjgl-platform-2.9.4-nightly-20150209-natives-linux.jar"}, "natives-osx": {"path": "org/lwjgl/lwjgl/lwjgl-platform/2.9.4-nightly-20150209/lwjgl-platform-2.9.4-nightly-20150209-natives-osx.jar", "sha1": "bcab850f8f487c3f4c4dbabde778bb82bd1a40ed", "size": 426822, "url": "https://libraries.minecraft.net/org/lwjgl/lwjgl/lwjgl-platform/2.9.4-nightly-20150209/lwjgl-platform-2.9.4-nightly-20150209-natives-osx.jar"}, "natives-windows": {"path": "org/lwjgl/lwjgl/lwjgl-platform/2.9.4-nightly-20150209/lwjgl-platform-2.9.4-nightly-20150209-natives-windows.jar", "sha1": "b84d5102b9dbfabfeb5e43c7e2828d98a7fc80e0", "size": 613748, "url": "https://libraries.minecraft.net/org/lwjgl/lwjgl/lwjgl-platform/2.9.4-nightly-20150209/lwjgl-platform-2.9.4-nightly-20150209-natives-windows.jar"}}}, "extract": {"exclude": ["META-INF/"]}, "name": "org.lwjgl.lwjgl:lwjgl-platform:2.9.4-nightly-20150209", "natives": {"linux": "natives-linux", "osx": "natives-osx", "windows": "natives-windows"}, "rules": [{"action": "allow"}, {"action": "disallow", "os": {"name": "osx"}}]}, {"downloads": {"artifact": {"path": "org/lwjgl/lwjgl/lwjgl/2.9.2-nightly-20140822/lwjgl-2.9.2-nightly-20140822.jar", "sha1": "7707204c9ffa5d91662de95f0a224e2f721b22af", "size": 1045632, "url": "https://libraries.minecraft.net/org/lwjgl/lwjgl/lwjgl/2.9.2-nightly-20140822/lwjgl-2.9.2-nightly-20140822.jar"}}, "name": "org.lwjgl.lwjgl:lwjgl:2.9.2-nightly-20140822", "rules": [{"action": "allow", "os": {"name": "osx"}}]}, {"downloads": {"artifact": {"path": "org/lwjgl/lwjgl/lwjgl_util/2.9.2-nightly-20140822/lwjgl_util-2.9.2-nightly-20140822.jar", "sha1": "f0e612c840a7639c1f77f68d72a28dae2f0c8490", "size": 173887, "url": "https://libraries.minecraft.net/org/lwjgl/lwjgl/lwjgl_util/2.9.2-nightly-20140822/lwjgl_util-2.9.2-nightly-20140822.jar"}}, "name": "org.lwjgl.lwjgl:lwjgl_util:2.9.2-nightly-20140822", "rules": [{"action": "allow", "os": {"name": "osx"}}]}, {"downloads": {"classifiers": {"natives-linux": {"path": "org/lwjgl/lwjgl/lwjgl-platform/2.9.2-nightly-20140822/lwjgl-platform-2.9.2-nightly-20140822-natives-linux.jar", "sha1": "d898a33b5d0a6ef3fed3a4ead506566dce6720a5", "size": 578539, "url": "https://libraries.minecraft.net/org/lwjgl/lwjgl/lwjgl-platform/2.9.2-nightly-20140822/lwjgl-platform-2.9.2-nightly-20140822-natives-linux.jar"}, "natives-osx": {"path": "org/lwjgl/lwjgl/lwjgl-platform/2.9.2-nightly-20140822/lwjgl-platform-2.9.2-nightly-20140822-natives-osx.jar", "sha1": "79f5ce2fea02e77fe47a3c745219167a542121d7", "size": 468116, "url": "https://libraries.minecraft.net/org/lwjgl/lwjgl/lwjgl-platform/2.9.2-nightly-20140822/lwjgl-platform-2.9.2-nightly-20140822-natives-osx.jar"}, "natives-windows": {"path": "org/lwjgl/lwjgl/lwjgl-platform/2.9.2-nightly-20140822/lwjgl-platform-2.9.2-nightly-20140822-natives-windows.jar", "sha1": "78b2a55ce4dc29c6b3ec4df8ca165eba05f9b341", "size": 613680, "url": "https://libraries.minecraft.net/org/lwjgl/lwjgl/lwjgl-platform/2.9.2-nightly-20140822/lwjgl-platform-2.9.2-nightly-20140822-natives-windows.jar"}}}, "extract": {"exclude": ["META-INF/"]}, "name": "org.lwjgl.lwjgl:lwjgl-platform:2.9.2-nightly-20140822", "natives": {"linux": "natives-linux", "osx": "natives-osx", "windows": "natives-windows"}, "rules": [{"action": "allow", "os": {"name": "osx"}}]}, {"downloads": {"classifiers": {"natives-linux": {"path": "net/java/jinput/jinput-platform/2.0.5/jinput-platform-2.0.5-natives-linux.jar", "sha1": "7ff832a6eb9ab6a767f1ade2b548092d0fa64795", "size": 10362, "url": "https://libraries.minecraft.net/net/java/jinput/jinput-platform/2.0.5/jinput-platform-2.0.5-natives-linux.jar"}, "natives-osx": {"path": "net/java/jinput/jinput-platform/2.0.5/jinput-platform-2.0.5-natives-osx.jar", "sha1": "53f9c919f34d2ca9de8c51fc4e1e8282029a9232", "size": 12186, "url": "https://libraries.minecraft.net/net/java/jinput/jinput-platform/2.0.5/jinput-platform-2.0.5-natives-osx.jar"}, "natives-windows": {"path": "net/java/jinput/jinput-platform/2.0.5/jinput-platform-2.0.5-natives-windows.jar", "sha1": "385ee093e01f587f30ee1c8a2ee7d408fd732e16", "size": 155179, "url": "https://libraries.minecraft.net/net/java/jinput/jinput-platform/2.0.5/jinput-platform-2.0.5-natives-windows.jar"}}}, "extract": {"exclude": ["META-INF/"]}, "name": "net.java.jinput:jinput-platform:2.0.5", "natives": {"linux": "natives-linux", "osx": "natives-osx", "windows": "natives-windows"}}, {"downloads": {"artifact": {"path": "com/mojang/text2speech/1.10.3/text2speech-1.10.3.jar", "sha1": "48fd510879dff266c3815947de66e3d4809f8668", "size": 11055, "url": "https://libraries.minecraft.net/com/mojang/text2speech/1.10.3/text2speech-1.10.3.jar"}}, "name": "com.mojang:text2speech:1.10.3"}, {"downloads": {"artifact": {"path": "com/mojang/text2speech/1.10.3/text2speech-1.10.3.jar", "sha1": "48fd510879dff266c3815947de66e3d4809f8668", "size": 11055, "url": "https://libraries.minecraft.net/com/mojang/text2speech/1.10.3/text2speech-1.10.3.jar"}, "classifiers": {"natives-linux": {"path": "com/mojang/text2speech/1.10.3/text2speech-1.10.3-natives-linux.jar", "sha1": "ab7896aec3b3dd272b06194357f2d98f832c0cfc", "size": 7833, "url": "https://libraries.minecraft.net/com/mojang/text2speech/1.10.3/text2speech-1.10.3-natives-linux.jar"}, "natives-windows": {"path": "com/mojang/text2speech/1.10.3/text2speech-1.10.3-natives-windows.jar", "sha1": "84a4b856389cc4f485275b1f63497a95a857a443", "size": 81217, "url": "https://libraries.minecraft.net/com/mojang/text2speech/1.10.3/text2speech-1.10.3-natives-windows.jar"}, "sources": {"path": "com/mojang/text2speech/1.10.3/text2speech-1.10.3-sources.jar", "sha1": "404339fe43d1011ee046a249b0ec7ae9ce04a834", "size": 4632, "url": "https://libraries.minecraft.net/com/mojang/text2speech/1.10.3/text2speech-1.10.3-sources.jar"}}}, "extract": {"exclude": ["META-INF/"]}, "name": "com.mojang:text2speech:1.10.3", "natives": {"linux": "natives-linux", "windows": "natives-windows"}}, {"downloads": {"artifact": {"path": "ca/weblite/java-objc-bridge/1.0.0/java-objc-bridge-1.0.0.jar", "sha1": "6ef160c3133a78de015830860197602ca1c855d3", "size": 40502, "url": "https://libraries.minecraft.net/ca/weblite/java-objc-bridge/1.0.0/java-objc-bridge-1.0.0.jar"}, "classifiers": {"javadoc": {"path": "ca/weblite/java-objc-bridge/1.0.0/java-objc-bridge-1.0.0-javadoc.jar", "sha1": "fb0092f22cb4fe8e631452f577b7a238778abf2a", "size": 174060, "url": "https://libraries.minecraft.net/ca/weblite/java-objc-bridge/1.0.0/java-objc-bridge-1.0.0-javadoc.jar"}, "natives-osx": {"path": "ca/weblite/java-objc-bridge/1.0.0/java-objc-bridge-1.0.0-natives-osx.jar", "sha1": "08befab4894d55875f33c3d300f4f71e6e828f64", "size": 5629, "url": "https://libraries.minecraft.net/ca/weblite/java-objc-bridge/1.0.0/java-objc-bridge-1.0.0-natives-osx.jar"}, "sources": {"path": "ca/weblite/java-objc-bridge/1.0.0/java-objc-bridge-1.0.0-sources.jar", "sha1": "865837a198189aee737019561ece842827f24278", "size": 43283, "url": "https://libraries.minecraft.net/ca/weblite/java-objc-bridge/1.0.0/java-objc-bridge-1.0.0-sources.jar"}}}, "extract": {"exclude": ["META-INF/"]}, "name": "ca.weblite:java-objc-bridge:1.0.0", "natives": {"osx": "natives-osx"}, "rules": [{"action": "allow", "os": {"name": "osx"}}]}, {"downloads": {"artifact": {"path": "ca/weblite/java-objc-bridge/1.0.0/java-objc-bridge-1.0.0.jar", "sha1": "6ef160c3133a78de015830860197602ca1c855d3", "size": 40502, "url": "https://libraries.minecraft.net/ca/weblite/java-objc-bridge/1.0.0/java-objc-bridge-1.0.0.jar"}}, "name": "ca.weblite:java-objc-bridge:1.0.0", "rules": [{"action": "allow", "os": {"name": "osx"}}]}], "logging": {"client": {"argument": "-Dlog4j.configurationFile=${path}", "file": {"id": "client-1.12.xml", "sha1": "ef4f57b922df243d0cef096efe808c72db042149", "size": 877, "url": "https://launcher.mojang.com/v1/objects/ef4f57b922df243d0cef096efe808c72db042149/client-1.12.xml"}, "type": "log4j2-xml"}}, "mainClass": "net.minecraft.client.main.Main", "minecraftArguments": "--username ${auth_player_name} --version ${version_name} --gameDir ${game_directory} --assetsDir ${assets_root} --assetIndex ${assets_index_name} --uuid ${auth_uuid} --accessToken ${auth_access_token} --userType ${user_type} --versionType ${version_type}", "minimumLauncherVersion": 18, "releaseTime": "2017-09-18T08:39:46+00:00", "time": "2017-09-18T08:39:46+00:00", "type": "release"}
diff --git a/patches/net/minecraft/advancements/Advancement.java.patch b/patches/net/minecraft/advancements/Advancement.java.patch
new file mode 100644
index 00000000..c8e619fb
--- /dev/null
+++ b/patches/net/minecraft/advancements/Advancement.java.patch
@@ -0,0 +1,54 @@
+--- ../src-base/minecraft/net/minecraft/advancements/Advancement.java
++++ ../src-work/minecraft/net/minecraft/advancements/Advancement.java
+@@ -32,6 +32,7 @@
+ private final String[][] requirements;
+ private final Set children = Sets.newLinkedHashSet();
+ private final ITextComponent displayText;
++ public final org.bukkit.advancement.Advancement bukkit = new org.bukkit.craftbukkit.advancement.CraftAdvancement(this);
+
+ public Advancement(ResourceLocation id, @Nullable Advancement parentIn, @Nullable DisplayInfo displayIn, AdvancementRewards rewardsIn, Map criteriaIn, String[][] requirementsIn)
+ {
+@@ -68,9 +69,9 @@
+ }
+ }
+
+- public Advancement.Builder copy()
++ public Builder copy()
+ {
+- return new Advancement.Builder(this.parent == null ? null : this.parent.getId(), this.display, this.rewards, this.criteria, this.requirements);
++ return new Builder(this.parent == null ? null : this.parent.getId(), this.display, this.rewards, this.criteria, this.requirements);
+ }
+
+ @Nullable
+@@ -230,7 +231,7 @@
+ return "Task Advancement{parentId=" + this.parentId + ", display=" + this.display + ", rewards=" + this.rewards + ", criteria=" + this.criteria + ", requirements=" + Arrays.deepToString(this.requirements) + '}';
+ }
+
+- public static Advancement.Builder deserialize(JsonObject json, JsonDeserializationContext context)
++ public static Builder deserialize(JsonObject json, JsonDeserializationContext context)
+ {
+ ResourceLocation resourcelocation = json.has("parent") ? new ResourceLocation(JsonUtils.getString(json, "parent")) : null;
+ DisplayInfo displayinfo = json.has("display") ? DisplayInfo.deserialize(JsonUtils.getJsonObject(json, "display"), context) : null;
+@@ -303,11 +304,11 @@
+ }
+ }
+
+- return new Advancement.Builder(resourcelocation, displayinfo, advancementrewards, map, astring);
++ return new Builder(resourcelocation, displayinfo, advancementrewards, map, astring);
+ }
+ }
+
+- public static Advancement.Builder readFrom(PacketBuffer buf) throws IOException
++ public static Builder readFrom(PacketBuffer buf) throws IOException
+ {
+ ResourceLocation resourcelocation = buf.readBoolean() ? buf.readResourceLocation() : null;
+ DisplayInfo displayinfo = buf.readBoolean() ? DisplayInfo.read(buf) : null;
+@@ -324,7 +325,7 @@
+ }
+ }
+
+- return new Advancement.Builder(resourcelocation, displayinfo, AdvancementRewards.EMPTY, map, astring);
++ return new Builder(resourcelocation, displayinfo, AdvancementRewards.EMPTY, map, astring);
+ }
+ }
+ }
diff --git a/patches/net/minecraft/advancements/AdvancementManager.java.patch b/patches/net/minecraft/advancements/AdvancementManager.java.patch
new file mode 100644
index 00000000..cf4463aa
--- /dev/null
+++ b/patches/net/minecraft/advancements/AdvancementManager.java.patch
@@ -0,0 +1,26 @@
+--- ../src-base/minecraft/net/minecraft/advancements/AdvancementManager.java
++++ ../src-work/minecraft/net/minecraft/advancements/AdvancementManager.java
+@@ -50,8 +50,8 @@
+ return Advancement.Builder.deserialize(jsonobject, p_deserialize_3_);
+ }
+ }).registerTypeAdapter(AdvancementRewards.class, new AdvancementRewards.Deserializer()).registerTypeHierarchyAdapter(ITextComponent.class, new ITextComponent.Serializer()).registerTypeHierarchyAdapter(Style.class, new Style.Serializer()).registerTypeAdapterFactory(new EnumTypeAdapterFactory()).create();
+- private static final AdvancementList ADVANCEMENT_LIST = new AdvancementList();
+- private final File advancementsDir;
++ public static final AdvancementList ADVANCEMENT_LIST = new AdvancementList();
++ public final File advancementsDir;
+ private boolean hasErrored;
+
+ public AdvancementManager(@Nullable File advancementsDirIn)
+@@ -173,7 +173,11 @@
+ Path path2 = path.relativize(path1);
+ String s = FilenameUtils.removeExtension(path2.toString()).replaceAll("\\\\", "/");
+ ResourceLocation resourcelocation = new ResourceLocation("minecraft", s);
+-
++ // Spigot start
++ if (org.spigotmc.SpigotConfig.disabledAdvancements != null && (org.spigotmc.SpigotConfig.disabledAdvancements.contains("*") || org.spigotmc.SpigotConfig.disabledAdvancements.contains(resourcelocation.toString()))) {
++ continue;
++ }
++ // Spigot end
+ if (!map.containsKey(resourcelocation))
+ {
+ BufferedReader bufferedreader = null;
diff --git a/patches/net/minecraft/advancements/AdvancementRewards.java.patch b/patches/net/minecraft/advancements/AdvancementRewards.java.patch
new file mode 100644
index 00000000..66bb9a54
--- /dev/null
+++ b/patches/net/minecraft/advancements/AdvancementRewards.java.patch
@@ -0,0 +1,116 @@
+--- ../src-base/minecraft/net/minecraft/advancements/AdvancementRewards.java
++++ ../src-work/minecraft/net/minecraft/advancements/AdvancementRewards.java
+@@ -89,56 +89,67 @@
+
+ if (functionobject != null)
+ {
+- ICommandSender icommandsender = new ICommandSender()
+- {
+- public String getName()
+- {
+- return player.getName();
+- }
+- public ITextComponent getDisplayName()
+- {
+- return player.getDisplayName();
+- }
+- public void sendMessage(ITextComponent component)
+- {
+- }
+- public boolean canUseCommand(int permLevel, String commandName)
+- {
+- return permLevel <= 2;
+- }
+- public BlockPos getPosition()
+- {
+- return player.getPosition();
+- }
+- public Vec3d getPositionVector()
+- {
+- return player.getPositionVector();
+- }
+- public World getEntityWorld()
+- {
+- return player.world;
+- }
+- public Entity getCommandSenderEntity()
+- {
+- return player;
+- }
+- public boolean sendCommandFeedback()
+- {
+- return minecraftserver.worlds[0].getGameRules().getBoolean("commandBlockOutput");
+- }
+- public void setCommandStat(CommandResultStats.Type type, int amount)
+- {
+- player.setCommandStat(type, amount);
+- }
+- public MinecraftServer getServer()
+- {
+- return player.getServer();
+- }
+- };
++ ICommandSender icommandsender = new AdvancementCommandListener(player, minecraftserver);
++
+ minecraftserver.getFunctionManager().execute(functionobject, icommandsender);
+ }
++
+ }
+
++ public static class AdvancementCommandListener implements ICommandSender {
++
++ private final EntityPlayerMP player;
++ private final MinecraftServer minecraftserver;
++
++ public AdvancementCommandListener(EntityPlayerMP entityplayer, MinecraftServer minecraftserver) {
++ this.player = entityplayer;
++ this.minecraftserver = minecraftserver;
++ }
++
++ public String getName() {
++ return player.getName();
++ }
++
++ public ITextComponent getDisplayName() {
++ return player.getDisplayName();
++ }
++
++ public void sendMessage(ITextComponent component) {
++ }
++
++ public boolean canUseCommand(int permLevel, String commandName) {
++ return permLevel <= 2;
++ }
++
++ public BlockPos getPosition() {
++ return player.getPosition();
++ }
++
++ public Vec3d getPositionVector() {
++ return player.getPositionVector();
++ }
++
++ public World getEntityWorld() {
++ return player.world;
++ }
++
++ public Entity getCommandSenderEntity() {
++ return player;
++ }
++
++ public boolean sendCommandFeedback() {
++ return minecraftserver.worlds[0].getGameRules().getBoolean("commandBlockOutput");
++ }
++
++ public void setCommandStat(CommandResultStats.Type type, int amount) {
++ player.setCommandStat(type, amount);
++ }
++
++ public MinecraftServer getServer() {
++ return player.getServer();
++ }
++ }
++
+ public String toString()
+ {
+ return "AdvancementRewards{experience=" + this.experience + ", loot=" + Arrays.toString((Object[])this.loot) + ", recipes=" + Arrays.toString((Object[])this.recipes) + ", function=" + this.function + '}';
diff --git a/patches/net/minecraft/advancements/FunctionManager.java.patch b/patches/net/minecraft/advancements/FunctionManager.java.patch
new file mode 100644
index 00000000..fb6abcd4
--- /dev/null
+++ b/patches/net/minecraft/advancements/FunctionManager.java.patch
@@ -0,0 +1,82 @@
+--- ../src-base/minecraft/net/minecraft/advancements/FunctionManager.java
++++ ../src-work/minecraft/net/minecraft/advancements/FunctionManager.java
+@@ -27,10 +27,13 @@
+ private final Map functions = Maps.newHashMap();
+ private String currentGameLoopFunctionId = "-";
+ private FunctionObject gameLoopFunction;
+- private final ArrayDeque commandQueue = new ArrayDeque();
++ private final ArrayDeque commandQueue = new ArrayDeque();
+ private boolean isExecuting = false;
+- private final ICommandSender gameLoopFunctionSender = new ICommandSender()
+- {
++ private final ICommandSender gameLoopFunctionSender = new CustomFunctionListener();
++
++ public class CustomFunctionListener implements ICommandSender {
++
++ public org.bukkit.command.CommandSender sender = new org.bukkit.craftbukkit.command.CraftFunctionCommandSender(this);
+ public String getName()
+ {
+ return FunctionManager.this.currentGameLoopFunctionId;
+@@ -101,7 +104,7 @@
+ {
+ if (this.commandQueue.size() < i)
+ {
+- this.commandQueue.addFirst(new FunctionManager.QueuedCommand(this, sender, new FunctionObject.FunctionEntry(function)));
++ this.commandQueue.addFirst(new QueuedCommand(this, sender, new FunctionObject.FunctionEntry(function)));
+ }
+
+ return 0;
+@@ -118,7 +121,7 @@
+
+ for (int k = afunctionobject$entry.length - 1; k >= 0; --k)
+ {
+- this.commandQueue.push(new FunctionManager.QueuedCommand(this, sender, afunctionobject$entry[k]));
++ this.commandQueue.push(new QueuedCommand(this, sender, afunctionobject$entry[k]));
+ }
+
+ while (true)
+@@ -192,26 +195,26 @@
+ }
+
+ public static class QueuedCommand
++ {
++ private final FunctionManager functionManager;
++ private final ICommandSender sender;
++ private final FunctionObject.Entry entry;
++
++ public QueuedCommand(FunctionManager functionManagerIn, ICommandSender senderIn, FunctionObject.Entry entryIn)
+ {
+- private final FunctionManager functionManager;
+- private final ICommandSender sender;
+- private final FunctionObject.Entry entry;
++ this.functionManager = functionManagerIn;
++ this.sender = senderIn;
++ this.entry = entryIn;
++ }
+
+- public QueuedCommand(FunctionManager functionManagerIn, ICommandSender senderIn, FunctionObject.Entry entryIn)
+- {
+- this.functionManager = functionManagerIn;
+- this.sender = senderIn;
+- this.entry = entryIn;
+- }
++ public void execute(ArrayDeque commandQueue, int maxCommandChainLength)
++ {
++ this.entry.execute(this.functionManager, this.sender, commandQueue, maxCommandChainLength);
++ }
+
+- public void execute(ArrayDeque commandQueue, int maxCommandChainLength)
+- {
+- this.entry.execute(this.functionManager, this.sender, commandQueue, maxCommandChainLength);
+- }
+-
+- public String toString()
+- {
+- return this.entry.toString();
+- }
++ public String toString()
++ {
++ return this.entry.toString();
+ }
++ }
+ }
diff --git a/patches/net/minecraft/advancements/PlayerAdvancements.java.patch b/patches/net/minecraft/advancements/PlayerAdvancements.java.patch
new file mode 100644
index 00000000..e969a4b1
--- /dev/null
+++ b/patches/net/minecraft/advancements/PlayerAdvancements.java.patch
@@ -0,0 +1,52 @@
+--- ../src-base/minecraft/net/minecraft/advancements/PlayerAdvancements.java
++++ ../src-work/minecraft/net/minecraft/advancements/PlayerAdvancements.java
+@@ -16,7 +16,6 @@
+ import java.util.Map;
+ import java.util.Set;
+ import java.util.Map.Entry;
+-import java.util.function.Function;
+ import java.util.stream.Collectors;
+ import java.util.stream.Stream;
+ import javax.annotation.Nullable;
+@@ -29,6 +28,7 @@
+ import net.minecraft.util.text.TextComponentTranslation;
+ import org.apache.logging.log4j.LogManager;
+ import org.apache.logging.log4j.Logger;
++import org.spigotmc.SpigotConfig;
+
+ public class PlayerAdvancements
+ {
+@@ -142,8 +142,12 @@
+
+ if (advancement == null)
+ {
++ // CraftBukkit start
++ if (entry.getKey().toString().equals("minecraft")) {
+ LOGGER.warn("Ignored advancement '" + entry.getKey() + "' in progress file " + this.progressFile + " - it doesn't exist anymore?");
+ }
++ // CraftBukkit end
++ }
+ else
+ {
+ this.startProgress(advancement, entry.getValue());
+@@ -167,6 +171,12 @@
+
+ public void save()
+ {
++ // Spigot start
++ if (SpigotConfig.disableAdvancementSaving) {
++ return;
++ }
++ // Spigot end
++
+ Map map = Maps.newHashMap();
+
+ for (Entry entry : this.progress.entrySet())
+@@ -211,6 +221,7 @@
+
+ if (!flag1 && advancementprogress.isDone())
+ {
++ this.player.world.getServer().getPluginManager().callEvent(new org.bukkit.event.player.PlayerAdvancementDoneEvent(this.player.getBukkitEntity(), p_192750_1_.bukkit)); // CraftBukkit
+ p_192750_1_.getRewards().apply(this.player);
+
+ if (p_192750_1_.getDisplay() != null && p_192750_1_.getDisplay().shouldAnnounceToChat() && this.player.world.getGameRules().getBoolean("announceAdvancements"))
diff --git a/patches/net/minecraft/block/Block.java.patch b/patches/net/minecraft/block/Block.java.patch
new file mode 100644
index 00000000..72e75d49
--- /dev/null
+++ b/patches/net/minecraft/block/Block.java.patch
@@ -0,0 +1,342 @@
+--- ../src-base/minecraft/net/minecraft/block/Block.java
++++ ../src-work/minecraft/net/minecraft/block/Block.java
+@@ -1,10 +1,7 @@
+ package net.minecraft.block;
+
+-import com.google.common.collect.Sets;
+-import com.google.common.collect.UnmodifiableIterator;
+ import java.util.List;
+ import java.util.Random;
+-import java.util.Set;
+ import javax.annotation.Nullable;
+ import net.minecraft.block.material.EnumPushReaction;
+ import net.minecraft.block.material.MapColor;
+@@ -21,6 +18,7 @@
+ import net.minecraft.entity.item.EntityItem;
+ import net.minecraft.entity.item.EntityXPOrb;
+ import net.minecraft.entity.player.EntityPlayer;
++import net.minecraft.entity.player.EntityPlayerMP;
+ import net.minecraft.init.Blocks;
+ import net.minecraft.init.Enchantments;
+ import net.minecraft.init.Items;
+@@ -573,7 +571,8 @@
+
+ for (ItemStack drop : drops)
+ {
+- if (worldIn.rand.nextFloat() <= chance)
++ // CraftBukkit - <= to < to allow for plugins to completely disable block drops from explosions
++ if (worldIn.rand.nextFloat() < chance)
+ {
+ spawnAsEntity(worldIn, pos, drop);
+ }
+@@ -596,12 +595,27 @@
+ double d2 = (double)(worldIn.rand.nextFloat() * 0.5F) + 0.25D;
+ EntityItem entityitem = new EntityItem(worldIn, (double)pos.getX() + d0, (double)pos.getY() + d1, (double)pos.getZ() + d2, stack);
+ entityitem.setDefaultPickupDelay();
+- worldIn.spawnEntity(entityitem);
++ if (worldIn.captureDrops != null) {
++ worldIn.captureDrops.add(entityitem);
++ } else {
++ worldIn.spawnEntity(entityitem);
++ }
+ }
+ }
+
++ // CraftBukkit start
++ public int getExpDrop(World world, IBlockState state, int enchantmentLevel) {
++ return 0;
++ }
++ // CraftBukkit end
++
+ public void dropXpOnBlockBreak(World worldIn, BlockPos pos, int amount)
+ {
++ dropXpOnBlockBreak(worldIn, pos, amount, null);
++ }
++
++ public void dropXpOnBlockBreak(World worldIn, BlockPos pos, int amount, EntityPlayerMP player)
++ {
+ if (!worldIn.isRemote && worldIn.getGameRules().getBoolean("doTileDrops"))
+ {
+ while (amount > 0)
+@@ -714,7 +728,7 @@
+
+ if (this.canSilkHarvest(worldIn, pos, state, player) && EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, stack) > 0)
+ {
+- java.util.List items = new java.util.ArrayList();
++ List items = new java.util.ArrayList();
+ ItemStack itemstack = this.getSilkTouchDrop(state);
+
+ if (!itemstack.isEmpty())
+@@ -915,24 +929,24 @@
+ return this.defaultBlockState;
+ }
+
+- public Block.EnumOffsetType getOffsetType()
++ public EnumOffsetType getOffsetType()
+ {
+- return Block.EnumOffsetType.NONE;
++ return EnumOffsetType.NONE;
+ }
+
+ @Deprecated
+ public Vec3d getOffset(IBlockState state, IBlockAccess worldIn, BlockPos pos)
+ {
+- Block.EnumOffsetType block$enumoffsettype = this.getOffsetType();
++ EnumOffsetType block$enumoffsettype = this.getOffsetType();
+
+- if (block$enumoffsettype == Block.EnumOffsetType.NONE)
++ if (block$enumoffsettype == EnumOffsetType.NONE)
+ {
+ return Vec3d.ZERO;
+ }
+ else
+ {
+ long i = MathHelper.getCoordinateRandom(pos.getX(), 0, pos.getZ());
+- return new Vec3d(((double)((float)(i >> 16 & 15L) / 15.0F) - 0.5D) * 0.5D, block$enumoffsettype == Block.EnumOffsetType.XYZ ? ((double)((float)(i >> 20 & 15L) / 15.0F) - 1.0D) * 0.2D : 0.0D, ((double)((float)(i >> 24 & 15L) / 15.0F) - 0.5D) * 0.5D);
++ return new Vec3d(((double)((float)(i >> 16 & 15L) / 15.0F) - 0.5D) * 0.5D, block$enumoffsettype == EnumOffsetType.XYZ ? ((double)((float)(i >> 20 & 15L) / 15.0F) - 1.0D) * 0.2D : 0.0D, ((double)((float)(i >> 24 & 15L) / 15.0F) - 0.5D) * 0.5D);
+ }
+ }
+
+@@ -956,7 +970,7 @@
+ //For ForgeInternal use Only!
+ protected ThreadLocal harvesters = new ThreadLocal();
+ private ThreadLocal silk_check_state = new ThreadLocal();
+- protected static java.util.Random RANDOM = new java.util.Random(); // Useful for random things without a seed.
++ protected static Random RANDOM = new Random(); // Useful for random things without a seed.
+
+ /**
+ * Gets the slipperiness at the given location at the given state. Normally
+@@ -1176,7 +1190,7 @@
+ public boolean removedByPlayer(IBlockState state, World world, BlockPos pos, EntityPlayer player, boolean willHarvest)
+ {
+ this.onBlockHarvested(world, pos, state, player);
+- return world.setBlockState(pos, net.minecraft.init.Blocks.AIR.getDefaultState(), world.isRemote ? 11 : 3);
++ return world.setBlockState(pos, Blocks.AIR.getDefaultState(), world.isRemote ? 11 : 3);
+ }
+
+ /**
+@@ -1190,7 +1204,7 @@
+ */
+ public int getFlammability(IBlockAccess world, BlockPos pos, EnumFacing face)
+ {
+- return net.minecraft.init.Blocks.FIRE.getFlammability(this);
++ return Blocks.FIRE.getFlammability(this);
+ }
+
+ /**
+@@ -1218,7 +1232,7 @@
+ */
+ public int getFireSpreadSpeed(IBlockAccess world, BlockPos pos, EnumFacing face)
+ {
+- return net.minecraft.init.Blocks.FIRE.getEncouragement(this);
++ return Blocks.FIRE.getEncouragement(this);
+ }
+
+ /**
+@@ -1370,7 +1384,7 @@
+ */
+ public boolean isBed(IBlockState state, IBlockAccess world, BlockPos pos, @Nullable Entity player)
+ {
+- return this == net.minecraft.init.Blocks.BED;
++ return this == Blocks.BED;
+ }
+
+ /**
+@@ -1564,18 +1578,13 @@
+ */
+ public boolean canPlaceTorchOnTop(IBlockState state, IBlockAccess world, BlockPos pos)
+ {
+- if (this == Blocks.END_GATEWAY || this == Blocks.LIT_PUMPKIN)
++ if (state.isTopSolid() || state.getBlockFaceShape(world, pos, EnumFacing.UP) == BlockFaceShape.SOLID)
+ {
+- return false;
++ return this != Blocks.END_GATEWAY && this != Blocks.LIT_PUMPKIN;
+ }
+- else if (state.isTopSolid() || this instanceof BlockFence || this == Blocks.GLASS || this == Blocks.COBBLESTONE_WALL || this == Blocks.STAINED_GLASS)
+- {
+- return true;
+- }
+ else
+ {
+- BlockFaceShape shape = state.getBlockFaceShape(world, pos, EnumFacing.UP);
+- return (shape == BlockFaceShape.SOLID || shape == BlockFaceShape.CENTER || shape == BlockFaceShape.CENTER_BIG) && !isExceptionBlockForAttaching(this);
++ return this instanceof BlockFence || this == Blocks.GLASS || this == Blocks.COBBLESTONE_WALL || this == Blocks.STAINED_GLASS;
+ }
+ }
+
+@@ -1693,12 +1702,12 @@
+ IBlockState plant = plantable.getPlant(world, pos.offset(direction));
+ net.minecraftforge.common.EnumPlantType plantType = plantable.getPlantType(world, pos.offset(direction));
+
+- if (plant.getBlock() == net.minecraft.init.Blocks.CACTUS)
++ if (plant.getBlock() == Blocks.CACTUS)
+ {
+- return this == net.minecraft.init.Blocks.CACTUS || this == net.minecraft.init.Blocks.SAND;
++ return this == Blocks.CACTUS || this == Blocks.SAND;
+ }
+
+- if (plant.getBlock() == net.minecraft.init.Blocks.REEDS && this == net.minecraft.init.Blocks.REEDS)
++ if (plant.getBlock() == Blocks.REEDS && this == Blocks.REEDS)
+ {
+ return true;
+ }
+@@ -1710,14 +1719,14 @@
+
+ switch (plantType)
+ {
+- case Desert: return this == net.minecraft.init.Blocks.SAND || this == net.minecraft.init.Blocks.HARDENED_CLAY || this == net.minecraft.init.Blocks.STAINED_HARDENED_CLAY;
+- case Nether: return this == net.minecraft.init.Blocks.SOUL_SAND;
+- case Crop: return this == net.minecraft.init.Blocks.FARMLAND;
++ case Desert: return this == Blocks.SAND || this == Blocks.HARDENED_CLAY || this == Blocks.STAINED_HARDENED_CLAY;
++ case Nether: return this == Blocks.SOUL_SAND;
++ case Crop: return this == Blocks.FARMLAND;
+ case Cave: return state.isSideSolid(world, pos, EnumFacing.UP);
+- case Plains: return this == net.minecraft.init.Blocks.GRASS || this == net.minecraft.init.Blocks.DIRT || this == net.minecraft.init.Blocks.FARMLAND;
++ case Plains: return this == Blocks.GRASS || this == Blocks.DIRT || this == Blocks.FARMLAND;
+ case Water: return state.getMaterial() == Material.WATER && state.getValue(BlockLiquid.LEVEL) == 0;
+ case Beach:
+- boolean isBeach = this == net.minecraft.init.Blocks.GRASS || this == net.minecraft.init.Blocks.DIRT || this == net.minecraft.init.Blocks.SAND;
++ boolean isBeach = this == Blocks.GRASS || this == Blocks.DIRT || this == Blocks.SAND;
+ boolean hasWater = (world.getBlockState(pos.east()).getMaterial() == Material.WATER ||
+ world.getBlockState(pos.west()).getMaterial() == Material.WATER ||
+ world.getBlockState(pos.north()).getMaterial() == Material.WATER ||
+@@ -1744,9 +1753,9 @@
+ */
+ public void onPlantGrow(IBlockState state, World world, BlockPos pos, BlockPos source)
+ {
+- if (this == net.minecraft.init.Blocks.GRASS || this == net.minecraft.init.Blocks.FARMLAND)
++ if (this == Blocks.GRASS || this == Blocks.FARMLAND)
+ {
+- world.setBlockState(pos, net.minecraft.init.Blocks.DIRT.getDefaultState(), 2);
++ world.setBlockState(pos, Blocks.DIRT.getDefaultState(), 2);
+ }
+ }
+
+@@ -1761,7 +1770,7 @@
+ */
+ public boolean isFertile(World world, BlockPos pos)
+ {
+- if (this == net.minecraft.init.Blocks.FARMLAND)
++ if (this == Blocks.FARMLAND)
+ {
+ return ((Integer)world.getBlockState(pos).getValue(BlockFarmland.MOISTURE)) > 0;
+ }
+@@ -1799,17 +1808,17 @@
+ {
+ if (entity instanceof net.minecraft.entity.boss.EntityDragon)
+ {
+- return this != net.minecraft.init.Blocks.BARRIER &&
+- this != net.minecraft.init.Blocks.OBSIDIAN &&
+- this != net.minecraft.init.Blocks.END_STONE &&
+- this != net.minecraft.init.Blocks.BEDROCK &&
+- this != net.minecraft.init.Blocks.END_PORTAL &&
+- this != net.minecraft.init.Blocks.END_PORTAL_FRAME &&
+- this != net.minecraft.init.Blocks.COMMAND_BLOCK &&
+- this != net.minecraft.init.Blocks.REPEATING_COMMAND_BLOCK &&
+- this != net.minecraft.init.Blocks.CHAIN_COMMAND_BLOCK &&
+- this != net.minecraft.init.Blocks.IRON_BARS &&
+- this != net.minecraft.init.Blocks.END_GATEWAY;
++ return this != Blocks.BARRIER &&
++ this != Blocks.OBSIDIAN &&
++ this != Blocks.END_STONE &&
++ this != Blocks.BEDROCK &&
++ this != Blocks.END_PORTAL &&
++ this != Blocks.END_PORTAL_FRAME &&
++ this != Blocks.COMMAND_BLOCK &&
++ this != Blocks.REPEATING_COMMAND_BLOCK &&
++ this != Blocks.CHAIN_COMMAND_BLOCK &&
++ this != Blocks.IRON_BARS &&
++ this != Blocks.END_GATEWAY;
+ }
+ else if ((entity instanceof net.minecraft.entity.boss.EntityWither) ||
+ (entity instanceof net.minecraft.entity.projectile.EntityWitherSkull))
+@@ -1830,7 +1839,7 @@
+ */
+ public boolean isBeaconBase(IBlockAccess worldObj, BlockPos pos, BlockPos beacon)
+ {
+- return this == net.minecraft.init.Blocks.EMERALD_BLOCK || this == net.minecraft.init.Blocks.GOLD_BLOCK || this == net.minecraft.init.Blocks.DIAMOND_BLOCK || this == net.minecraft.init.Blocks.IRON_BLOCK;
++ return this == Blocks.EMERALD_BLOCK || this == Blocks.GOLD_BLOCK || this == Blocks.DIAMOND_BLOCK || this == Blocks.IRON_BLOCK;
+ }
+
+ /**
+@@ -1918,7 +1927,7 @@
+ */
+ public float getEnchantPowerBonus(World world, BlockPos pos)
+ {
+- return this == net.minecraft.init.Blocks.BOOKSHELF ? 1 : 0;
++ return this == Blocks.BOOKSHELF ? 1 : 0;
+ }
+
+ /**
+@@ -1930,14 +1939,14 @@
+ * @return If the recoloring was successful
+ */
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+- public boolean recolorBlock(World world, BlockPos pos, EnumFacing side, net.minecraft.item.EnumDyeColor color)
++ public boolean recolorBlock(World world, BlockPos pos, EnumFacing side, EnumDyeColor color)
+ {
+ IBlockState state = world.getBlockState(pos);
+ for (IProperty prop : state.getProperties().keySet())
+ {
+- if (prop.getName().equals("color") && prop.getValueClass() == net.minecraft.item.EnumDyeColor.class)
++ if (prop.getName().equals("color") && prop.getValueClass() == EnumDyeColor.class)
+ {
+- net.minecraft.item.EnumDyeColor current = (net.minecraft.item.EnumDyeColor)state.getValue(prop);
++ EnumDyeColor current = (EnumDyeColor)state.getValue(prop);
+ if (current != color && prop.getAllowedValues().contains(color))
+ {
+ world.setBlockState(pos, state.withProperty(prop, color));
+@@ -2074,7 +2083,7 @@
+ */
+ public boolean isToolEffective(String type, IBlockState state)
+ {
+- if ("pickaxe".equals(type) && (this == net.minecraft.init.Blocks.REDSTONE_ORE || this == net.minecraft.init.Blocks.LIT_REDSTONE_ORE || this == net.minecraft.init.Blocks.OBSIDIAN))
++ if ("pickaxe".equals(type) && (this == Blocks.REDSTONE_ORE || this == Blocks.LIT_REDSTONE_ORE || this == Blocks.OBSIDIAN))
+ return false;
+ return type != null && type.equals(getHarvestTool(state));
+ }
+@@ -2286,23 +2295,15 @@
+ return false;
+ }
+
+- /** @deprecated use {@link #getAiPathNodeType(IBlockState, IBlockAccess, BlockPos, net.minecraft.entity.EntityLiving)} */
+- @Nullable
+- @Deprecated // TODO: remove
+- public net.minecraft.pathfinding.PathNodeType getAiPathNodeType(IBlockState state, IBlockAccess world, BlockPos pos)
+- {
+- return isBurning(world, pos) ? net.minecraft.pathfinding.PathNodeType.DAMAGE_FIRE : null;
+- }
+-
+ /**
+ * Get the {@code PathNodeType} for this block. Return {@code null} for vanilla behavior.
+ *
+ * @return the PathNodeType
+ */
+ @Nullable
+- public net.minecraft.pathfinding.PathNodeType getAiPathNodeType(IBlockState state, IBlockAccess world, BlockPos pos, @Nullable net.minecraft.entity.EntityLiving entity)
++ public net.minecraft.pathfinding.PathNodeType getAiPathNodeType(IBlockState state, IBlockAccess world, BlockPos pos)
+ {
+- return getAiPathNodeType(state, world, pos);
++ return isBurning(world, pos) ? net.minecraft.pathfinding.PathNodeType.DAMAGE_FIRE : null;
+ }
+
+ /**
+@@ -2642,6 +2643,18 @@
+ registerBlock(id, new ResourceLocation(textualID), block_);
+ }
+
++ // Spigot start
++ public static float range(float min, float value, float max) {
++ if (value < min) {
++ return min;
++ }
++ if (value > max) {
++ return max;
++ }
++ return value;
++ }
++ // Spigot end
++
+ public static enum EnumOffsetType
+ {
+ NONE,
diff --git a/patches/net/minecraft/block/BlockBasePressurePlate.java.patch b/patches/net/minecraft/block/BlockBasePressurePlate.java.patch
new file mode 100644
index 00000000..a22da055
--- /dev/null
+++ b/patches/net/minecraft/block/BlockBasePressurePlate.java.patch
@@ -0,0 +1,28 @@
+--- ../src-base/minecraft/net/minecraft/block/BlockBasePressurePlate.java
++++ ../src-work/minecraft/net/minecraft/block/BlockBasePressurePlate.java
+@@ -14,6 +14,7 @@
+ import net.minecraft.util.math.BlockPos;
+ import net.minecraft.world.IBlockAccess;
+ import net.minecraft.world.World;
++import org.bukkit.event.block.BlockRedstoneEvent;
+
+ public abstract class BlockBasePressurePlate extends Block
+ {
+@@ -125,6 +126,17 @@
+ boolean flag = oldRedstoneStrength > 0;
+ boolean flag1 = i > 0;
+
++ org.bukkit.World bworld = worldIn.getWorld();
++ org.bukkit.plugin.PluginManager manager = worldIn.getServer().getPluginManager();
++
++ if (flag != flag1) {
++ BlockRedstoneEvent eventRedstone = new BlockRedstoneEvent(bworld.getBlockAt(pos.getX(), pos.getY(), pos.getZ()), oldRedstoneStrength, i);
++ manager.callEvent(eventRedstone);
++
++ flag1 = eventRedstone.getNewCurrent() > 0;
++ i = eventRedstone.getNewCurrent();
++ }
++
+ if (oldRedstoneStrength != i)
+ {
+ state = this.setRedstoneStrength(state, i);
diff --git a/patches/net/minecraft/block/BlockBush.java.patch b/patches/net/minecraft/block/BlockBush.java.patch
new file mode 100644
index 00000000..a6bb3822
--- /dev/null
+++ b/patches/net/minecraft/block/BlockBush.java.patch
@@ -0,0 +1,30 @@
+--- ../src-base/minecraft/net/minecraft/block/BlockBush.java
++++ ../src-work/minecraft/net/minecraft/block/BlockBush.java
+@@ -41,7 +41,7 @@
+ public boolean canPlaceBlockAt(World worldIn, BlockPos pos)
+ {
+ IBlockState soil = worldIn.getBlockState(pos.down());
+- return super.canPlaceBlockAt(worldIn, pos) && soil.getBlock().canSustainPlant(soil, worldIn, pos.down(), net.minecraft.util.EnumFacing.UP, this);
++ return super.canPlaceBlockAt(worldIn, pos) && soil.getBlock().canSustainPlant(soil, worldIn, pos.down(), EnumFacing.UP, this);
+ }
+
+ protected boolean canSustainBush(IBlockState state)
+@@ -64,6 +64,9 @@
+ {
+ if (!this.canBlockStay(worldIn, pos, state))
+ {
++ if (org.bukkit.craftbukkit.event.CraftEventFactory.callBlockPhysicsEvent(worldIn, pos).isCancelled()) {
++ return;
++ }
+ this.dropBlockAsItem(worldIn, pos, state, 0);
+ worldIn.setBlockState(pos, Blocks.AIR.getDefaultState(), 3);
+ }
+@@ -74,7 +77,7 @@
+ if (state.getBlock() == this) //Forge: This function is called during world gen and placement, before this block is set, so if we are not 'here' then assume it's the pre-check.
+ {
+ IBlockState soil = worldIn.getBlockState(pos.down());
+- return soil.getBlock().canSustainPlant(soil, worldIn, pos.down(), net.minecraft.util.EnumFacing.UP, this);
++ return soil.getBlock().canSustainPlant(soil, worldIn, pos.down(), EnumFacing.UP, this);
+ }
+ return this.canSustainBush(worldIn.getBlockState(pos.down()));
+ }
diff --git a/patches/net/minecraft/block/BlockButton.java.patch b/patches/net/minecraft/block/BlockButton.java.patch
new file mode 100644
index 00000000..b0b0aaeb
--- /dev/null
+++ b/patches/net/minecraft/block/BlockButton.java.patch
@@ -0,0 +1,107 @@
+--- ../src-base/minecraft/net/minecraft/block/BlockButton.java
++++ ../src-work/minecraft/net/minecraft/block/BlockButton.java
+@@ -14,7 +14,6 @@
+ import net.minecraft.entity.EntityLivingBase;
+ import net.minecraft.entity.player.EntityPlayer;
+ import net.minecraft.entity.projectile.EntityArrow;
+-import net.minecraft.init.Blocks;
+ import net.minecraft.util.EnumFacing;
+ import net.minecraft.util.EnumHand;
+ import net.minecraft.util.Mirror;
+@@ -23,6 +22,8 @@
+ import net.minecraft.util.math.BlockPos;
+ import net.minecraft.world.IBlockAccess;
+ import net.minecraft.world.World;
++import org.bukkit.event.block.BlockRedstoneEvent;
++import org.bukkit.event.entity.EntityInteractEvent;
+
+ public abstract class BlockButton extends BlockDirectional
+ {
+@@ -165,6 +166,17 @@
+ }
+ else
+ {
++ boolean powered = ((Boolean) state.getValue(POWERED));
++ org.bukkit.block.Block block = worldIn.getWorld().getBlockAt(pos.getX(), pos.getY(), pos.getZ());
++ int old = (powered) ? 15 : 0;
++ int current = (!powered) ? 15 : 0;
++
++ BlockRedstoneEvent eventRedstone = new BlockRedstoneEvent(block, old, current);
++ worldIn.getServer().getPluginManager().callEvent(eventRedstone);
++
++ if ((eventRedstone.getNewCurrent() > 0) != (!powered)) {
++ return true;
++ }
+ worldIn.setBlockState(pos, state.withProperty(POWERED, Boolean.valueOf(true)), 3);
+ worldIn.markBlockRangeForRenderUpdate(pos, pos);
+ this.playClickSound(playerIn, worldIn, pos);
+@@ -226,6 +238,14 @@
+ }
+ else
+ {
++ org.bukkit.block.Block block = worldIn.getWorld().getBlockAt(pos.getX(), pos.getY(), pos.getZ());
++
++ BlockRedstoneEvent eventRedstone = new BlockRedstoneEvent(block, 15, 0);
++ worldIn.getServer().getPluginManager().callEvent(eventRedstone);
++
++ if (eventRedstone.getNewCurrent() > 0) {
++ return;
++ }
+ worldIn.setBlockState(pos, state.withProperty(POWERED, Boolean.valueOf(false)));
+ this.notifyNeighbors(worldIn, pos, (EnumFacing)state.getValue(FACING));
+ this.playReleaseSound(worldIn, pos);
+@@ -255,8 +275,39 @@
+ boolean flag = !list.isEmpty();
+ boolean flag1 = ((Boolean)state.getValue(POWERED)).booleanValue();
+
++ // CraftBukkit start - Call interact event when arrows turn on wooden buttons
++ if (flag1 != flag && flag) {
++ org.bukkit.block.Block block = worldIn.getWorld().getBlockAt(pos.getX(), pos.getY(), pos.getZ());
++ boolean allowed = false;
++
++ // If all of the events are cancelled block the button press, else allow
++ for (Object object : list) {
++ if (object != null) {
++ EntityInteractEvent event = new EntityInteractEvent(((Entity) object).getBukkitEntity(), block);
++ worldIn.getServer().getPluginManager().callEvent(event);
++
++ if (!event.isCancelled()) {
++ allowed = true;
++ break;
++ }
++ }
++ }
++
++ if (!allowed) {
++ return;
++ }
++ }
++
+ if (flag && !flag1)
+ {
++ org.bukkit.block.Block block = worldIn.getWorld().getBlockAt(pos.getX(), pos.getY(), pos.getZ());
++
++ BlockRedstoneEvent eventRedstone = new BlockRedstoneEvent(block, 0, 15);
++ worldIn.getServer().getPluginManager().callEvent(eventRedstone);
++
++ if (eventRedstone.getNewCurrent() <= 0) {
++ return;
++ }
+ worldIn.setBlockState(pos, state.withProperty(POWERED, Boolean.valueOf(true)));
+ this.notifyNeighbors(worldIn, pos, (EnumFacing)state.getValue(FACING));
+ worldIn.markBlockRangeForRenderUpdate(pos, pos);
+@@ -265,6 +316,14 @@
+
+ if (!flag && flag1)
+ {
++ org.bukkit.block.Block block = worldIn.getWorld().getBlockAt(pos.getX(), pos.getY(), pos.getZ());
++
++ BlockRedstoneEvent eventRedstone = new BlockRedstoneEvent(block, 15, 0);
++ worldIn.getServer().getPluginManager().callEvent(eventRedstone);
++
++ if (eventRedstone.getNewCurrent() > 0) {
++ return;
++ }
+ worldIn.setBlockState(pos, state.withProperty(POWERED, Boolean.valueOf(false)));
+ this.notifyNeighbors(worldIn, pos, (EnumFacing)state.getValue(FACING));
+ worldIn.markBlockRangeForRenderUpdate(pos, pos);
diff --git a/patches/net/minecraft/block/BlockCactus.java.patch b/patches/net/minecraft/block/BlockCactus.java.patch
new file mode 100644
index 00000000..fb9070b9
--- /dev/null
+++ b/patches/net/minecraft/block/BlockCactus.java.patch
@@ -0,0 +1,34 @@
+--- ../src-base/minecraft/net/minecraft/block/BlockCactus.java
++++ ../src-work/minecraft/net/minecraft/block/BlockCactus.java
+@@ -19,6 +19,7 @@
+ import net.minecraft.world.World;
+ import net.minecraftforge.fml.relauncher.Side;
+ import net.minecraftforge.fml.relauncher.SideOnly;
++import org.bukkit.craftbukkit.event.CraftEventFactory;
+
+ public class BlockCactus extends Block implements net.minecraftforge.common.IPlantable
+ {
+@@ -54,10 +55,11 @@
+
+ if(net.minecraftforge.common.ForgeHooks.onCropsGrowPre(worldIn, blockpos, state, true))
+ {
+- if (j == 15)
++ if (j >= (byte)Block.range(3.0f, 100.0f / worldIn.spigotConfig.cactusModifier * 15.0f + 0.5f, 15.0f)) // Spigot
+ {
+- worldIn.setBlockState(blockpos, this.getDefaultState());
++ // worldIn.setBlockState(blockpos, this.getDefaultState());
+ IBlockState iblockstate = state.withProperty(AGE, Integer.valueOf(0));
++ CraftEventFactory.handleBlockGrowEvent(worldIn, blockpos.getX(), blockpos.getY(), blockpos.getZ(), this, 0);
+ worldIn.setBlockState(pos, iblockstate, 4);
+ iblockstate.neighborChanged(worldIn, blockpos, this, pos);
+ }
+@@ -123,7 +125,9 @@
+
+ public void onEntityCollidedWithBlock(World worldIn, BlockPos pos, IBlockState state, Entity entityIn)
+ {
++ CraftEventFactory.blockDamage = worldIn.getWorld().getBlockAt(pos.getX(), pos.getY(), pos.getZ());
+ entityIn.attackEntityFrom(DamageSource.CACTUS, 1.0F);
++ CraftEventFactory.blockDamage = null;
+ }
+
+ public IBlockState getStateFromMeta(int meta)
diff --git a/patches/net/minecraft/block/BlockCake.java.patch b/patches/net/minecraft/block/BlockCake.java.patch
new file mode 100644
index 00000000..d168b176
--- /dev/null
+++ b/patches/net/minecraft/block/BlockCake.java.patch
@@ -0,0 +1,28 @@
+--- ../src-base/minecraft/net/minecraft/block/BlockCake.java
++++ ../src-work/minecraft/net/minecraft/block/BlockCake.java
+@@ -8,6 +8,7 @@
+ import net.minecraft.block.state.BlockStateContainer;
+ import net.minecraft.block.state.IBlockState;
+ import net.minecraft.entity.player.EntityPlayer;
++import net.minecraft.entity.player.EntityPlayerMP;
+ import net.minecraft.init.Items;
+ import net.minecraft.item.Item;
+ import net.minecraft.item.ItemStack;
+@@ -71,7 +72,17 @@
+ else
+ {
+ player.addStat(StatList.CAKE_SLICES_EATEN);
++ // Kettle Restore CraftBukkit changes for AppleCore recognition
+ player.getFoodStats().addStats(2, 0.1F);
++ int oldFoodLevel = player.getFoodStats().foodLevel;
++
++ org.bukkit.event.entity.FoodLevelChangeEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callFoodLevelChangeEvent(player, 2 + oldFoodLevel);
++
++ if (!event.isCancelled()) {
++ player.getFoodStats().addStats(event.getFoodLevel() - oldFoodLevel, 0.1F);
++ }
++
++ ((EntityPlayerMP) player).getBukkitEntity().sendHealthUpdate();
+ int i = ((Integer)state.getValue(BITES)).intValue();
+
+ if (i < 6)
diff --git a/patches/net/minecraft/block/BlockCauldron.java.patch b/patches/net/minecraft/block/BlockCauldron.java.patch
new file mode 100644
index 00000000..6a3b5c78
--- /dev/null
+++ b/patches/net/minecraft/block/BlockCauldron.java.patch
@@ -0,0 +1,171 @@
+--- ../src-base/minecraft/net/minecraft/block/BlockCauldron.java
++++ ../src-work/minecraft/net/minecraft/block/BlockCauldron.java
+@@ -31,6 +31,7 @@
+ import net.minecraft.util.math.MathHelper;
+ import net.minecraft.world.IBlockAccess;
+ import net.minecraft.world.World;
++import org.bukkit.event.block.CauldronLevelChangeEvent;
+
+ public class BlockCauldron extends Block
+ {
+@@ -78,8 +79,11 @@
+
+ if (!worldIn.isRemote && entityIn.isBurning() && i > 0 && entityIn.getEntityBoundingBox().minY <= (double)f)
+ {
++ if (!this.changeLevel(worldIn, pos, state, i - 1, entityIn, CauldronLevelChangeEvent.ChangeReason.EXTINGUISH)) {
++ return;
++ }
+ entityIn.extinguish();
+- this.setWaterLevel(worldIn, pos, state, i - 1);
++// this.setWaterLevel(worldIn, pos, state, i - 1);
+ }
+ }
+
+@@ -100,13 +104,16 @@
+ {
+ if (i < 3 && !worldIn.isRemote)
+ {
++ if (!this.changeLevel(worldIn, pos, state, 3, playerIn, CauldronLevelChangeEvent.ChangeReason.BUCKET_EMPTY)) {
++ return true;
++ }
+ if (!playerIn.capabilities.isCreativeMode)
+ {
+ playerIn.setHeldItem(hand, new ItemStack(Items.BUCKET));
+ }
+
+ playerIn.addStat(StatList.CAULDRON_FILLED);
+- this.setWaterLevel(worldIn, pos, state, 3);
++// this.setWaterLevel(worldIn, pos, state, 3);
+ worldIn.playSound((EntityPlayer)null, pos, SoundEvents.ITEM_BUCKET_EMPTY, SoundCategory.BLOCKS, 1.0F, 1.0F);
+ }
+
+@@ -116,6 +123,9 @@
+ {
+ if (i == 3 && !worldIn.isRemote)
+ {
++ if (!this.changeLevel(worldIn, pos, state, 0, playerIn, CauldronLevelChangeEvent.ChangeReason.BUCKET_FILL)) {
++ return true;
++ }
+ if (!playerIn.capabilities.isCreativeMode)
+ {
+ itemstack.shrink(1);
+@@ -131,7 +141,7 @@
+ }
+
+ playerIn.addStat(StatList.CAULDRON_USED);
+- this.setWaterLevel(worldIn, pos, state, 0);
++// this.setWaterLevel(worldIn, pos, state, 0);
+ worldIn.playSound((EntityPlayer)null, pos, SoundEvents.ITEM_BUCKET_FILL, SoundCategory.BLOCKS, 1.0F, 1.0F);
+ }
+
+@@ -141,6 +151,9 @@
+ {
+ if (i > 0 && !worldIn.isRemote)
+ {
++ if (!this.changeLevel(worldIn, pos, state, i - 1, playerIn, CauldronLevelChangeEvent.ChangeReason.BOTTLE_FILL)) {
++ return true;
++ }
+ if (!playerIn.capabilities.isCreativeMode)
+ {
+ ItemStack itemstack3 = PotionUtils.addPotionToItemStack(new ItemStack(Items.POTIONITEM), PotionTypes.WATER);
+@@ -162,7 +175,7 @@
+ }
+
+ worldIn.playSound((EntityPlayer)null, pos, SoundEvents.ITEM_BOTTLE_FILL, SoundCategory.BLOCKS, 1.0F, 1.0F);
+- this.setWaterLevel(worldIn, pos, state, i - 1);
++// this.setWaterLevel(worldIn, pos, state, i - 1);
+ }
+
+ return true;
+@@ -171,6 +184,9 @@
+ {
+ if (i < 3 && !worldIn.isRemote)
+ {
++ if (!this.changeLevel(worldIn, pos, state, i + 1, playerIn, CauldronLevelChangeEvent.ChangeReason.BOTTLE_EMPTY)) {
++ return true;
++ }
+ if (!playerIn.capabilities.isCreativeMode)
+ {
+ ItemStack itemstack2 = new ItemStack(Items.GLASS_BOTTLE);
+@@ -184,7 +200,7 @@
+ }
+
+ worldIn.playSound((EntityPlayer)null, pos, SoundEvents.ITEM_BOTTLE_EMPTY, SoundCategory.BLOCKS, 1.0F, 1.0F);
+- this.setWaterLevel(worldIn, pos, state, i + 1);
++// this.setWaterLevel(worldIn, pos, state, i + 1);
+ }
+
+ return true;
+@@ -197,8 +213,11 @@
+
+ if (itemarmor.getArmorMaterial() == ItemArmor.ArmorMaterial.LEATHER && itemarmor.hasColor(itemstack) && !worldIn.isRemote)
+ {
++ if (!this.changeLevel(worldIn, pos, state, i - 1, playerIn, CauldronLevelChangeEvent.ChangeReason.ARMOR_WASH)) {
++ return true;
++ }
+ itemarmor.removeColor(itemstack);
+- this.setWaterLevel(worldIn, pos, state, i - 1);
++// this.setWaterLevel(worldIn, pos, state, i - 1);
+ playerIn.addStat(StatList.ARMOR_CLEANED);
+ return true;
+ }
+@@ -208,6 +227,9 @@
+ {
+ if (TileEntityBanner.getPatterns(itemstack) > 0 && !worldIn.isRemote)
+ {
++ if (!this.changeLevel(worldIn, pos, state, i - 1, playerIn, CauldronLevelChangeEvent.ChangeReason.BANNER_WASH)) {
++ return true;
++ }
+ ItemStack itemstack1 = itemstack.copy();
+ itemstack1.setCount(1);
+ TileEntityBanner.removeBannerData(itemstack1);
+@@ -216,7 +238,7 @@
+ if (!playerIn.capabilities.isCreativeMode)
+ {
+ itemstack.shrink(1);
+- this.setWaterLevel(worldIn, pos, state, i - 1);
++// this.setWaterLevel(worldIn, pos, state, i - 1);
+ }
+
+ if (itemstack.isEmpty())
+@@ -245,10 +267,29 @@
+
+ public void setWaterLevel(World worldIn, BlockPos pos, IBlockState state, int level)
+ {
+- worldIn.setBlockState(pos, state.withProperty(LEVEL, Integer.valueOf(MathHelper.clamp(level, 0, 3))), 2);
+- worldIn.updateComparatorOutputLevel(pos, this);
++ this.changeLevel(worldIn, pos, state, level, null, CauldronLevelChangeEvent.ChangeReason.UNKNOWN);
+ }
+
++ public void changeLevel(World world, BlockPos blockposition, IBlockState iblockdata, int i) {
++ this.changeLevel(world, blockposition, iblockdata, i, null, CauldronLevelChangeEvent.ChangeReason.UNKNOWN);
++ }
++
++ private boolean changeLevel(World world, BlockPos blockposition, IBlockState iblockdata, int i, Entity entity, CauldronLevelChangeEvent.ChangeReason reason) {
++ int newLevel = Integer.valueOf(MathHelper.clamp(i, 0, 3));
++ CauldronLevelChangeEvent event = new CauldronLevelChangeEvent(
++ world.getWorld().getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ()),
++ (entity == null) ? null : entity.getBukkitEntity(), reason, iblockdata.getValue(BlockCauldron.LEVEL), newLevel
++ );
++ world.getServer().getPluginManager().callEvent(event);
++ if (event.isCancelled()) {
++ return false;
++ }
++ world.setBlockState(blockposition, iblockdata.withProperty(BlockCauldron.LEVEL, event.getNewLevel()), 2);
++ world.updateComparatorOutputLevel(blockposition, this);
++ world.updateComparatorOutputLevel(blockposition, this);
++ return true;
++ }
++
+ public void fillWithRain(World worldIn, BlockPos pos)
+ {
+ if (worldIn.rand.nextInt(20) == 1)
+@@ -261,7 +302,7 @@
+
+ if (((Integer)iblockstate.getValue(LEVEL)).intValue() < 3)
+ {
+- worldIn.setBlockState(pos, iblockstate.cycleProperty(LEVEL), 2);
++ this.changeLevel(worldIn, pos, iblockstate.cycleProperty(LEVEL), 2);
+ }
+ }
+ }
diff --git a/patches/net/minecraft/block/BlockChorusFlower.java.patch b/patches/net/minecraft/block/BlockChorusFlower.java.patch
new file mode 100644
index 00000000..b610b1c4
--- /dev/null
+++ b/patches/net/minecraft/block/BlockChorusFlower.java.patch
@@ -0,0 +1,85 @@
+--- ../src-base/minecraft/net/minecraft/block/BlockChorusFlower.java
++++ ../src-work/minecraft/net/minecraft/block/BlockChorusFlower.java
+@@ -23,6 +23,7 @@
+ import net.minecraft.world.World;
+ import net.minecraftforge.fml.relauncher.Side;
+ import net.minecraftforge.fml.relauncher.SideOnly;
++import org.bukkit.craftbukkit.event.CraftEventFactory;
+
+ public class BlockChorusFlower extends Block
+ {
+@@ -106,8 +107,18 @@
+
+ if (flag && areAllNeighborsEmpty(worldIn, blockpos, (EnumFacing)null) && worldIn.isAirBlock(pos.up(2)))
+ {
+- worldIn.setBlockState(pos, Blocks.CHORUS_PLANT.getDefaultState(), 2);
+- this.placeGrownFlower(worldIn, blockpos, i);
++// worldIn.setBlockState(pos, Blocks.CHORUS_PLANT.getDefaultState(), 2);
++// this.placeGrownFlower(worldIn, blockpos, i);
++ BlockPos target = blockpos;
++ if (CraftEventFactory.handleBlockSpreadEvent(
++ worldIn.getWorld().getBlockAt(target.getX(), target.getY(), target.getZ()),
++ worldIn.getWorld().getBlockAt(pos.getX(), pos.getY(), pos.getZ()),
++ this,
++ getMetaFromState(this.getDefaultState().withProperty(BlockChorusFlower.AGE, Integer.valueOf(i)))
++ )) {
++ worldIn.setBlockState(pos, Blocks.CHORUS_PLANT.getDefaultState(), 2);
++ worldIn.playEvent(1033, pos, 0);
++ }
+ }
+ else if (i < 4)
+ {
+@@ -126,7 +137,17 @@
+
+ if (worldIn.isAirBlock(blockpos1) && worldIn.isAirBlock(blockpos1.down()) && areAllNeighborsEmpty(worldIn, blockpos1, enumfacing.getOpposite()))
+ {
+- this.placeGrownFlower(worldIn, blockpos1, i + 1);
++// this.placeGrownFlower(worldIn, blockpos1, i + 1);
++ BlockPos target = blockpos1;
++ if (CraftEventFactory.handleBlockSpreadEvent(
++ worldIn.getWorld().getBlockAt(target.getX(), target.getY(), target.getZ()),
++ worldIn.getWorld().getBlockAt(pos.getX(), pos.getY(), pos.getZ()),
++ this,
++ getMetaFromState(this.getDefaultState().withProperty(BlockChorusFlower.AGE, Integer.valueOf(i + 1)))
++ )) {
++ worldIn.playEvent(1033, pos, 0);
++ flag2 = true;
++ }
+ flag2 = true;
+ }
+ }
+@@ -137,12 +158,32 @@
+ }
+ else
+ {
+- this.placeDeadFlower(worldIn, pos);
++// this.placeDeadFlower(worldIn, pos);
++ if (CraftEventFactory.handleBlockGrowEvent(
++ worldIn,
++ pos.getX(),
++ pos.getY(),
++ pos.getZ(),
++ this,
++ getMetaFromState(state.withProperty(BlockChorusFlower.AGE, Integer.valueOf(5)))
++ )) {
++ worldIn.playEvent(1034, pos, 0);
++ }
+ }
+ }
+ else if (i == 4)
+ {
+- this.placeDeadFlower(worldIn, pos);
++// this.placeDeadFlower(worldIn, pos);
++ if (CraftEventFactory.handleBlockGrowEvent(
++ worldIn,
++ pos.getX(),
++ pos.getY(),
++ pos.getZ(),
++ this,
++ getMetaFromState(state.withProperty(BlockChorusFlower.AGE, Integer.valueOf(5)))
++ )) {
++ worldIn.playEvent(1034, pos, 0);
++ }
+ }
+ net.minecraftforge.common.ForgeHooks.onCropsGrowPost(worldIn, pos, state, worldIn.getBlockState(pos));
+ }
diff --git a/patches/net/minecraft/block/BlockCocoa.java.patch b/patches/net/minecraft/block/BlockCocoa.java.patch
new file mode 100644
index 00000000..360cec67
--- /dev/null
+++ b/patches/net/minecraft/block/BlockCocoa.java.patch
@@ -0,0 +1,33 @@
+--- ../src-base/minecraft/net/minecraft/block/BlockCocoa.java
++++ ../src-work/minecraft/net/minecraft/block/BlockCocoa.java
+@@ -22,6 +22,7 @@
+ import net.minecraft.world.World;
+ import net.minecraftforge.fml.relauncher.Side;
+ import net.minecraftforge.fml.relauncher.SideOnly;
++import org.bukkit.craftbukkit.event.CraftEventFactory;
+
+ public class BlockCocoa extends BlockHorizontal implements IGrowable
+ {
+@@ -48,9 +49,10 @@
+ {
+ int i = ((Integer)state.getValue(AGE)).intValue();
+
+- if (i < 2 && net.minecraftforge.common.ForgeHooks.onCropsGrowPre(worldIn, pos, state, rand.nextInt(5) == 0))
++ if (i < 2 && net.minecraftforge.common.ForgeHooks.onCropsGrowPre(worldIn, pos, state, rand.nextInt(Math.max(1, (int)(100.0f / worldIn.spigotConfig.cocoaModifier) * 5)) == 0)) // Spigot
+ {
+- worldIn.setBlockState(pos, state.withProperty(AGE, Integer.valueOf(i + 1)), 2);
++ IBlockState data = state.withProperty(AGE, i + 1);
++ CraftEventFactory.handleBlockGrowEvent(worldIn, pos.getX(), pos.getY(), pos.getZ(), this, getMetaFromState(data));
+ net.minecraftforge.common.ForgeHooks.onCropsGrowPost(worldIn, pos, state, worldIn.getBlockState(pos));
+ }
+ }
+@@ -171,7 +173,8 @@
+
+ public void grow(World worldIn, Random rand, BlockPos pos, IBlockState state)
+ {
+- worldIn.setBlockState(pos, state.withProperty(AGE, Integer.valueOf(((Integer)state.getValue(AGE)).intValue() + 1)), 2);
++ IBlockState data = state.withProperty(AGE, state.getValue(AGE) + 1);
++ CraftEventFactory.handleBlockGrowEvent(worldIn, pos.getX(), pos.getY(), pos.getZ(), this, getMetaFromState(data));
+ }
+
+ @SideOnly(Side.CLIENT)
diff --git a/patches/net/minecraft/block/BlockCommandBlock.java.patch b/patches/net/minecraft/block/BlockCommandBlock.java.patch
new file mode 100644
index 00000000..43538ae7
--- /dev/null
+++ b/patches/net/minecraft/block/BlockCommandBlock.java.patch
@@ -0,0 +1,24 @@
+--- ../src-base/minecraft/net/minecraft/block/BlockCommandBlock.java
++++ ../src-work/minecraft/net/minecraft/block/BlockCommandBlock.java
+@@ -27,6 +27,7 @@
+ import net.minecraft.world.World;
+ import org.apache.logging.log4j.LogManager;
+ import org.apache.logging.log4j.Logger;
++import org.bukkit.event.block.BlockRedstoneEvent;
+
+ public class BlockCommandBlock extends BlockContainer
+ {
+@@ -58,6 +59,13 @@
+ TileEntityCommandBlock tileentitycommandblock = (TileEntityCommandBlock)tileentity;
+ boolean flag = worldIn.isBlockPowered(pos);
+ boolean flag1 = tileentitycommandblock.isPowered();
++ org.bukkit.block.Block bukkitBlock = worldIn.getWorld().getBlockAt(pos.getX(), pos.getY(), pos.getZ());
++ int old = flag1 ? 15 : 0;
++ int current = flag ? 15 : 0;
++
++ BlockRedstoneEvent eventRedstone = new BlockRedstoneEvent(bukkitBlock, old, current);
++ worldIn.getServer().getPluginManager().callEvent(eventRedstone);
++ flag = eventRedstone.getNewCurrent() > 0;
+ tileentitycommandblock.setPowered(flag);
+
+ if (!flag1 && !tileentitycommandblock.isAuto() && tileentitycommandblock.getMode() != TileEntityCommandBlock.Mode.SEQUENCE)
diff --git a/patches/net/minecraft/block/BlockConcretePowder.java.patch b/patches/net/minecraft/block/BlockConcretePowder.java.patch
new file mode 100644
index 00000000..bdd3d9c3
--- /dev/null
+++ b/patches/net/minecraft/block/BlockConcretePowder.java.patch
@@ -0,0 +1,23 @@
+--- ../src-base/minecraft/net/minecraft/block/BlockConcretePowder.java
++++ ../src-work/minecraft/net/minecraft/block/BlockConcretePowder.java
+@@ -29,9 +29,8 @@
+
+ public void onEndFalling(World worldIn, BlockPos pos, IBlockState p_176502_3_, IBlockState p_176502_4_)
+ {
+- if (p_176502_4_.getMaterial().isLiquid())
+- {
+- worldIn.setBlockState(pos, Blocks.CONCRETE.getDefaultState().withProperty(BlockColored.COLOR, p_176502_3_.getValue(COLOR)), 3);
++ if (p_176502_4_.getMaterial().isLiquid() && worldIn.getBlockState(pos).getBlock() != Blocks.CONCRETE) { // CraftBukkit - don't double concrete
++ org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockFormEvent(worldIn, pos, Blocks.CONCRETE.getDefaultState().withProperty(BlockColored.COLOR, p_176502_3_.getValue(BlockConcretePowder.COLOR)), null); // CraftBukkit
+ }
+ }
+
+@@ -55,7 +54,7 @@
+
+ if (flag)
+ {
+- worldIn.setBlockState(pos, Blocks.CONCRETE.getDefaultState().withProperty(BlockColored.COLOR, state.getValue(COLOR)), 3);
++ org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockFormEvent(worldIn, pos, Blocks.CONCRETE.getDefaultState().withProperty(BlockColored.COLOR, state.getValue(BlockConcretePowder.COLOR)), null);
+ }
+
+ return flag;
diff --git a/patches/net/minecraft/block/BlockCrops.java.patch b/patches/net/minecraft/block/BlockCrops.java.patch
new file mode 100644
index 00000000..a6cfdd52
--- /dev/null
+++ b/patches/net/minecraft/block/BlockCrops.java.patch
@@ -0,0 +1,30 @@
+--- ../src-base/minecraft/net/minecraft/block/BlockCrops.java
++++ ../src-work/minecraft/net/minecraft/block/BlockCrops.java
+@@ -15,6 +15,7 @@
+ import net.minecraft.util.math.MathHelper;
+ import net.minecraft.world.IBlockAccess;
+ import net.minecraft.world.World;
++import org.bukkit.craftbukkit.event.CraftEventFactory;
+
+ public class BlockCrops extends BlockBush implements IGrowable
+ {
+@@ -81,7 +82,8 @@
+
+ if(net.minecraftforge.common.ForgeHooks.onCropsGrowPre(worldIn, pos, state, rand.nextInt((int)(25.0F / f) + 1) == 0))
+ {
+- worldIn.setBlockState(pos, this.withAge(i + 1), 2);
++ IBlockState data = this.withAge(i + 1);
++ CraftEventFactory.handleBlockGrowEvent(worldIn, pos.getX(), pos.getY(), pos.getZ(), this, getMetaFromState(data));
+ net.minecraftforge.common.ForgeHooks.onCropsGrowPost(worldIn, pos, state, worldIn.getBlockState(pos));
+ }
+ }
+@@ -98,7 +100,8 @@
+ i = j;
+ }
+
+- worldIn.setBlockState(pos, this.withAge(i), 2);
++ IBlockState data = this.withAge(i);
++ CraftEventFactory.handleBlockGrowEvent(worldIn, pos.getX(), pos.getY(), pos.getZ(), this, getMetaFromState(data));
+ }
+
+ protected int getBonemealAgeIncrease(World worldIn)
diff --git a/patches/net/minecraft/block/BlockDaylightDetector.java.patch b/patches/net/minecraft/block/BlockDaylightDetector.java.patch
new file mode 100644
index 00000000..28facfca
--- /dev/null
+++ b/patches/net/minecraft/block/BlockDaylightDetector.java.patch
@@ -0,0 +1,10 @@
+--- ../src-base/minecraft/net/minecraft/block/BlockDaylightDetector.java
++++ ../src-work/minecraft/net/minecraft/block/BlockDaylightDetector.java
+@@ -76,6 +76,7 @@
+
+ if (((Integer)iblockstate.getValue(POWER)).intValue() != i)
+ {
++ i = org.bukkit.craftbukkit.event.CraftEventFactory.callRedstoneChange(worldIn, pos.getX(), pos.getY(), pos.getZ(), iblockstate.getValue(POWER), i).getNewCurrent();
+ worldIn.setBlockState(pos, iblockstate.withProperty(POWER, Integer.valueOf(i)), 3);
+ }
+ }
diff --git a/patches/net/minecraft/block/BlockDispenser.java.patch b/patches/net/minecraft/block/BlockDispenser.java.patch
new file mode 100644
index 00000000..77fcec6a
--- /dev/null
+++ b/patches/net/minecraft/block/BlockDispenser.java.patch
@@ -0,0 +1,11 @@
+--- ../src-base/minecraft/net/minecraft/block/BlockDispenser.java
++++ ../src-work/minecraft/net/minecraft/block/BlockDispenser.java
+@@ -120,7 +120,7 @@
+ }
+ }
+
+- protected void dispense(World worldIn, BlockPos pos)
++ public void dispense(World worldIn, BlockPos pos)
+ {
+ BlockSourceImpl blocksourceimpl = new BlockSourceImpl(worldIn, pos);
+ TileEntityDispenser tileentitydispenser = (TileEntityDispenser)blocksourceimpl.getBlockTileEntity();
diff --git a/patches/net/minecraft/block/BlockDoor.java.patch b/patches/net/minecraft/block/BlockDoor.java.patch
new file mode 100644
index 00000000..c6ad3a7b
--- /dev/null
+++ b/patches/net/minecraft/block/BlockDoor.java.patch
@@ -0,0 +1,164 @@
+--- ../src-base/minecraft/net/minecraft/block/BlockDoor.java
++++ ../src-work/minecraft/net/minecraft/block/BlockDoor.java
+@@ -29,14 +29,15 @@
+ import net.minecraft.world.World;
+ import net.minecraftforge.fml.relauncher.Side;
+ import net.minecraftforge.fml.relauncher.SideOnly;
++import org.bukkit.event.block.BlockRedstoneEvent;
+
+ public class BlockDoor extends Block
+ {
+ public static final PropertyDirection FACING = BlockHorizontal.FACING;
+ public static final PropertyBool OPEN = PropertyBool.create("open");
+- public static final PropertyEnum HINGE = PropertyEnum.create("hinge", BlockDoor.EnumHingePosition.class);
++ public static final PropertyEnum HINGE = PropertyEnum.create("hinge", EnumHingePosition.class);
+ public static final PropertyBool POWERED = PropertyBool.create("powered");
+- public static final PropertyEnum HALF = PropertyEnum.create("half", BlockDoor.EnumDoorHalf.class);
++ public static final PropertyEnum HALF = PropertyEnum.create("half", EnumDoorHalf.class);
+ protected static final AxisAlignedBB SOUTH_AABB = new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 1.0D, 0.1875D);
+ protected static final AxisAlignedBB NORTH_AABB = new AxisAlignedBB(0.0D, 0.0D, 0.8125D, 1.0D, 1.0D, 1.0D);
+ protected static final AxisAlignedBB WEST_AABB = new AxisAlignedBB(0.8125D, 0.0D, 0.0D, 1.0D, 1.0D, 1.0D);
+@@ -45,7 +46,7 @@
+ protected BlockDoor(Material materialIn)
+ {
+ super(materialIn);
+- this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH).withProperty(OPEN, Boolean.valueOf(false)).withProperty(HINGE, BlockDoor.EnumHingePosition.LEFT).withProperty(POWERED, Boolean.valueOf(false)).withProperty(HALF, BlockDoor.EnumDoorHalf.LOWER));
++ this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH).withProperty(OPEN, Boolean.valueOf(false)).withProperty(HINGE, EnumHingePosition.LEFT).withProperty(POWERED, Boolean.valueOf(false)).withProperty(HALF, EnumDoorHalf.LOWER));
+ }
+
+ public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos)
+@@ -53,7 +54,7 @@
+ state = state.getActualState(source, pos);
+ EnumFacing enumfacing = (EnumFacing)state.getValue(FACING);
+ boolean flag = !((Boolean)state.getValue(OPEN)).booleanValue();
+- boolean flag1 = state.getValue(HINGE) == BlockDoor.EnumHingePosition.RIGHT;
++ boolean flag1 = state.getValue(HINGE) == EnumHingePosition.RIGHT;
+
+ switch (enumfacing)
+ {
+@@ -139,7 +140,7 @@
+ }
+ else
+ {
+- BlockPos blockpos = state.getValue(HALF) == BlockDoor.EnumDoorHalf.LOWER ? pos : pos.down();
++ BlockPos blockpos = state.getValue(HALF) == EnumDoorHalf.LOWER ? pos : pos.down();
+ IBlockState iblockstate = pos.equals(blockpos) ? state : worldIn.getBlockState(blockpos);
+
+ if (iblockstate.getBlock() != this)
+@@ -163,7 +164,7 @@
+
+ if (iblockstate.getBlock() == this)
+ {
+- BlockPos blockpos = iblockstate.getValue(HALF) == BlockDoor.EnumDoorHalf.LOWER ? pos : pos.down();
++ BlockPos blockpos = iblockstate.getValue(HALF) == EnumDoorHalf.LOWER ? pos : pos.down();
+ IBlockState iblockstate1 = pos == blockpos ? iblockstate : worldIn.getBlockState(blockpos);
+
+ if (iblockstate1.getBlock() == this && ((Boolean)iblockstate1.getValue(OPEN)).booleanValue() != open)
+@@ -177,7 +178,7 @@
+
+ public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos)
+ {
+- if (state.getValue(HALF) == BlockDoor.EnumDoorHalf.UPPER)
++ if (state.getValue(HALF) == EnumDoorHalf.UPPER)
+ {
+ BlockPos blockpos = pos.down();
+ IBlockState iblockstate = worldIn.getBlockState(blockpos);
+@@ -223,17 +224,27 @@
+ }
+ else
+ {
+- boolean flag = worldIn.isBlockPowered(pos) || worldIn.isBlockPowered(blockpos1);
++ org.bukkit.World bworld = worldIn.getWorld();
++ org.bukkit.block.Block bukkitBlock = bworld.getBlockAt(pos.getX(), pos.getY(), pos.getZ());
++ org.bukkit.block.Block blockTop = bworld.getBlockAt(blockpos1.getX(), blockpos1.getY(), blockpos1.getZ());
+
+- if (blockIn != this && (flag || blockIn.getDefaultState().canProvidePower()) && flag != ((Boolean)iblockstate1.getValue(POWERED)).booleanValue())
+- {
+- worldIn.setBlockState(blockpos1, iblockstate1.withProperty(POWERED, Boolean.valueOf(flag)), 2);
++ int power = bukkitBlock.getBlockPower();
++ int powerTop = blockTop.getBlockPower();
++ if (powerTop > power) power = powerTop;
++ int oldPower = iblockstate1.getValue(BlockDoor.POWERED) ? 15 : 0;
+
+- if (flag != ((Boolean)state.getValue(OPEN)).booleanValue())
++ if (oldPower == 0 ^ power == 0) {
++ BlockRedstoneEvent eventRedstone = new BlockRedstoneEvent(bukkitBlock, oldPower, power);
++ worldIn.getServer().getPluginManager().callEvent(eventRedstone);
++
++ boolean flag2 = eventRedstone.getNewCurrent() > 0;
++ worldIn.setBlockState(blockpos1, iblockstate1.withProperty(POWERED, Boolean.valueOf(flag2)), 2);
++
++ if (flag2 != state.getValue(OPEN))
+ {
+- worldIn.setBlockState(pos, state.withProperty(OPEN, Boolean.valueOf(flag)), 2);
++ worldIn.setBlockState(pos, state.withProperty(OPEN, Boolean.valueOf(flag2)), 2);
+ worldIn.markBlockRangeForRenderUpdate(pos, pos);
+- worldIn.playEvent((EntityPlayer)null, flag ? this.getOpenSound() : this.getCloseSound(), pos, 0);
++ worldIn.playEvent(null, flag2 ? this.getOpenSound() : this.getCloseSound(), pos, 0);
+ }
+ }
+ }
+@@ -242,7 +253,7 @@
+
+ public Item getItemDropped(IBlockState state, Random rand, int fortune)
+ {
+- return state.getValue(HALF) == BlockDoor.EnumDoorHalf.UPPER ? Items.AIR : this.getItem();
++ return state.getValue(HALF) == EnumDoorHalf.UPPER ? Items.AIR : this.getItem();
+ }
+
+ public boolean canPlaceBlockAt(World worldIn, BlockPos pos)
+@@ -317,12 +328,12 @@
+ BlockPos blockpos = pos.down();
+ BlockPos blockpos1 = pos.up();
+
+- if (player.capabilities.isCreativeMode && state.getValue(HALF) == BlockDoor.EnumDoorHalf.UPPER && worldIn.getBlockState(blockpos).getBlock() == this)
++ if (player.capabilities.isCreativeMode && state.getValue(HALF) == EnumDoorHalf.UPPER && worldIn.getBlockState(blockpos).getBlock() == this)
+ {
+ worldIn.setBlockToAir(blockpos);
+ }
+
+- if (state.getValue(HALF) == BlockDoor.EnumDoorHalf.LOWER && worldIn.getBlockState(blockpos1).getBlock() == this)
++ if (state.getValue(HALF) == EnumDoorHalf.LOWER && worldIn.getBlockState(blockpos1).getBlock() == this)
+ {
+ if (player.capabilities.isCreativeMode)
+ {
+@@ -341,7 +352,7 @@
+
+ public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos)
+ {
+- if (state.getValue(HALF) == BlockDoor.EnumDoorHalf.LOWER)
++ if (state.getValue(HALF) == EnumDoorHalf.LOWER)
+ {
+ IBlockState iblockstate = worldIn.getBlockState(pos.up());
+
+@@ -365,7 +376,7 @@
+
+ public IBlockState withRotation(IBlockState state, Rotation rot)
+ {
+- return state.getValue(HALF) != BlockDoor.EnumDoorHalf.LOWER ? state : state.withProperty(FACING, rot.rotate((EnumFacing)state.getValue(FACING)));
++ return state.getValue(HALF) != EnumDoorHalf.LOWER ? state : state.withProperty(FACING, rot.rotate((EnumFacing)state.getValue(FACING)));
+ }
+
+ public IBlockState withMirror(IBlockState state, Mirror mirrorIn)
+@@ -375,18 +386,18 @@
+
+ public IBlockState getStateFromMeta(int meta)
+ {
+- return (meta & 8) > 0 ? this.getDefaultState().withProperty(HALF, BlockDoor.EnumDoorHalf.UPPER).withProperty(HINGE, (meta & 1) > 0 ? BlockDoor.EnumHingePosition.RIGHT : BlockDoor.EnumHingePosition.LEFT).withProperty(POWERED, Boolean.valueOf((meta & 2) > 0)) : this.getDefaultState().withProperty(HALF, BlockDoor.EnumDoorHalf.LOWER).withProperty(FACING, EnumFacing.getHorizontal(meta & 3).rotateYCCW()).withProperty(OPEN, Boolean.valueOf((meta & 4) > 0));
++ return (meta & 8) > 0 ? this.getDefaultState().withProperty(HALF, EnumDoorHalf.UPPER).withProperty(HINGE, (meta & 1) > 0 ? EnumHingePosition.RIGHT : EnumHingePosition.LEFT).withProperty(POWERED, Boolean.valueOf((meta & 2) > 0)) : this.getDefaultState().withProperty(HALF, EnumDoorHalf.LOWER).withProperty(FACING, EnumFacing.getHorizontal(meta & 3).rotateYCCW()).withProperty(OPEN, Boolean.valueOf((meta & 4) > 0));
+ }
+
+ public int getMetaFromState(IBlockState state)
+ {
+ int i = 0;
+
+- if (state.getValue(HALF) == BlockDoor.EnumDoorHalf.UPPER)
++ if (state.getValue(HALF) == EnumDoorHalf.UPPER)
+ {
+ i = i | 8;
+
+- if (state.getValue(HINGE) == BlockDoor.EnumHingePosition.RIGHT)
++ if (state.getValue(HINGE) == EnumHingePosition.RIGHT)
+ {
+ i |= 1;
+ }
diff --git a/patches/net/minecraft/block/BlockDoublePlant.java.patch b/patches/net/minecraft/block/BlockDoublePlant.java.patch
new file mode 100644
index 00000000..0748a837
--- /dev/null
+++ b/patches/net/minecraft/block/BlockDoublePlant.java.patch
@@ -0,0 +1,240 @@
+--- ../src-base/minecraft/net/minecraft/block/BlockDoublePlant.java
++++ ../src-work/minecraft/net/minecraft/block/BlockDoublePlant.java
+@@ -24,16 +24,18 @@
+ import net.minecraft.world.IBlockAccess;
+ import net.minecraft.world.World;
+
++import net.minecraft.block.Block.EnumOffsetType;
++
+ public class BlockDoublePlant extends BlockBush implements IGrowable, net.minecraftforge.common.IShearable
+ {
+- public static final PropertyEnum VARIANT = PropertyEnum.create("variant", BlockDoublePlant.EnumPlantType.class);
+- public static final PropertyEnum HALF = PropertyEnum.create("half", BlockDoublePlant.EnumBlockHalf.class);
++ public static final PropertyEnum VARIANT = PropertyEnum.create("variant", EnumPlantType.class);
++ public static final PropertyEnum HALF = PropertyEnum.create("half", EnumBlockHalf.class);
+ public static final PropertyEnum FACING = BlockHorizontal.FACING;
+
+ public BlockDoublePlant()
+ {
+ super(Material.VINE);
+- this.setDefaultState(this.blockState.getBaseState().withProperty(VARIANT, BlockDoublePlant.EnumPlantType.SUNFLOWER).withProperty(HALF, BlockDoublePlant.EnumBlockHalf.LOWER).withProperty(FACING, EnumFacing.NORTH));
++ this.setDefaultState(this.blockState.getBaseState().withProperty(VARIANT, EnumPlantType.SUNFLOWER).withProperty(HALF, EnumBlockHalf.LOWER).withProperty(FACING, EnumFacing.NORTH));
+ this.setHardness(0.0F);
+ this.setSoundType(SoundType.PLANT);
+ this.setUnlocalizedName("doublePlant");
+@@ -44,16 +46,16 @@
+ return FULL_BLOCK_AABB;
+ }
+
+- private BlockDoublePlant.EnumPlantType getType(IBlockAccess blockAccess, BlockPos pos, IBlockState state)
++ private EnumPlantType getType(IBlockAccess blockAccess, BlockPos pos, IBlockState state)
+ {
+ if (state.getBlock() == this)
+ {
+ state = state.getActualState(blockAccess, pos);
+- return (BlockDoublePlant.EnumPlantType)state.getValue(VARIANT);
++ return (EnumPlantType)state.getValue(VARIANT);
+ }
+ else
+ {
+- return BlockDoublePlant.EnumPlantType.FERN;
++ return EnumPlantType.FERN;
+ }
+ }
+
+@@ -72,8 +74,8 @@
+ }
+ else
+ {
+- BlockDoublePlant.EnumPlantType blockdoubleplant$enumplanttype = (BlockDoublePlant.EnumPlantType)iblockstate.getActualState(worldIn, pos).getValue(VARIANT);
+- return blockdoubleplant$enumplanttype == BlockDoublePlant.EnumPlantType.FERN || blockdoubleplant$enumplanttype == BlockDoublePlant.EnumPlantType.GRASS;
++ EnumPlantType blockdoubleplant$enumplanttype = (EnumPlantType)iblockstate.getActualState(worldIn, pos).getValue(VARIANT);
++ return blockdoubleplant$enumplanttype == EnumPlantType.FERN || blockdoubleplant$enumplanttype == EnumPlantType.GRASS;
+ }
+ }
+
+@@ -81,7 +83,10 @@
+ {
+ if (!this.canBlockStay(worldIn, pos, state))
+ {
+- boolean flag = state.getValue(HALF) == BlockDoublePlant.EnumBlockHalf.UPPER;
++ if (org.bukkit.craftbukkit.event.CraftEventFactory.callBlockPhysicsEvent(worldIn, pos).isCancelled()) {
++ return;
++ }
++ boolean flag = state.getValue(HALF) == EnumBlockHalf.UPPER;
+ BlockPos blockpos = flag ? pos : pos.up();
+ BlockPos blockpos1 = flag ? pos.down() : pos;
+ Block block = (Block)(flag ? this : worldIn.getBlockState(blockpos).getBlock());
+@@ -104,7 +109,7 @@
+ public boolean canBlockStay(World worldIn, BlockPos pos, IBlockState state)
+ {
+ if (state.getBlock() != this) return super.canBlockStay(worldIn, pos, state); //Forge: This function is called during world gen and placement, before this block is set, so if we are not 'here' then assume it's the pre-check.
+- if (state.getValue(HALF) == BlockDoublePlant.EnumBlockHalf.UPPER)
++ if (state.getValue(HALF) == EnumBlockHalf.UPPER)
+ {
+ return worldIn.getBlockState(pos.down()).getBlock() == this;
+ }
+@@ -117,19 +122,19 @@
+
+ public Item getItemDropped(IBlockState state, Random rand, int fortune)
+ {
+- if (state.getValue(HALF) == BlockDoublePlant.EnumBlockHalf.UPPER)
++ if (state.getValue(HALF) == EnumBlockHalf.UPPER)
+ {
+ return Items.AIR;
+ }
+ else
+ {
+- BlockDoublePlant.EnumPlantType blockdoubleplant$enumplanttype = (BlockDoublePlant.EnumPlantType)state.getValue(VARIANT);
++ EnumPlantType blockdoubleplant$enumplanttype = (EnumPlantType)state.getValue(VARIANT);
+
+- if (blockdoubleplant$enumplanttype == BlockDoublePlant.EnumPlantType.FERN)
++ if (blockdoubleplant$enumplanttype == EnumPlantType.FERN)
+ {
+ return Items.AIR;
+ }
+- else if (blockdoubleplant$enumplanttype == BlockDoublePlant.EnumPlantType.GRASS)
++ else if (blockdoubleplant$enumplanttype == EnumPlantType.GRASS)
+ {
+ return rand.nextInt(8) == 0 ? Items.WHEAT_SEEDS : Items.AIR;
+ }
+@@ -142,18 +147,18 @@
+
+ public int damageDropped(IBlockState state)
+ {
+- return state.getValue(HALF) != BlockDoublePlant.EnumBlockHalf.UPPER && state.getValue(VARIANT) != BlockDoublePlant.EnumPlantType.GRASS ? ((BlockDoublePlant.EnumPlantType)state.getValue(VARIANT)).getMeta() : 0;
++ return state.getValue(HALF) != EnumBlockHalf.UPPER && state.getValue(VARIANT) != EnumPlantType.GRASS ? ((EnumPlantType)state.getValue(VARIANT)).getMeta() : 0;
+ }
+
+- public void placeAt(World worldIn, BlockPos lowerPos, BlockDoublePlant.EnumPlantType variant, int flags)
++ public void placeAt(World worldIn, BlockPos lowerPos, EnumPlantType variant, int flags)
+ {
+- worldIn.setBlockState(lowerPos, this.getDefaultState().withProperty(HALF, BlockDoublePlant.EnumBlockHalf.LOWER).withProperty(VARIANT, variant), flags);
+- worldIn.setBlockState(lowerPos.up(), this.getDefaultState().withProperty(HALF, BlockDoublePlant.EnumBlockHalf.UPPER), flags);
++ worldIn.setBlockState(lowerPos, this.getDefaultState().withProperty(HALF, EnumBlockHalf.LOWER).withProperty(VARIANT, variant), flags);
++ worldIn.setBlockState(lowerPos.up(), this.getDefaultState().withProperty(HALF, EnumBlockHalf.UPPER), flags);
+ }
+
+ public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack)
+ {
+- worldIn.setBlockState(pos.up(), this.getDefaultState().withProperty(HALF, BlockDoublePlant.EnumBlockHalf.UPPER), 2);
++ worldIn.setBlockState(pos.up(), this.getDefaultState().withProperty(HALF, EnumBlockHalf.UPPER), 2);
+ }
+
+ public void harvestBlock(World worldIn, EntityPlayer player, BlockPos pos, IBlockState state, @Nullable TileEntity te, ItemStack stack)
+@@ -165,7 +170,7 @@
+
+ public void onBlockHarvested(World worldIn, BlockPos pos, IBlockState state, EntityPlayer player)
+ {
+- if (state.getValue(HALF) == BlockDoublePlant.EnumBlockHalf.UPPER)
++ if (state.getValue(HALF) == EnumBlockHalf.UPPER)
+ {
+ if (worldIn.getBlockState(pos.down()).getBlock() == this)
+ {
+@@ -176,9 +181,9 @@
+ else
+ {
+ IBlockState iblockstate = worldIn.getBlockState(pos.down());
+- BlockDoublePlant.EnumPlantType blockdoubleplant$enumplanttype = (BlockDoublePlant.EnumPlantType)iblockstate.getValue(VARIANT);
++ EnumPlantType blockdoubleplant$enumplanttype = (EnumPlantType)iblockstate.getValue(VARIANT);
+
+- if (blockdoubleplant$enumplanttype != BlockDoublePlant.EnumPlantType.FERN && blockdoubleplant$enumplanttype != BlockDoublePlant.EnumPlantType.GRASS)
++ if (blockdoubleplant$enumplanttype != EnumPlantType.FERN && blockdoubleplant$enumplanttype != EnumPlantType.GRASS)
+ {
+ worldIn.destroyBlock(pos.down(), true);
+ }
+@@ -208,9 +213,9 @@
+
+ private boolean onHarvest(World worldIn, BlockPos pos, IBlockState state, EntityPlayer player)
+ {
+- BlockDoublePlant.EnumPlantType blockdoubleplant$enumplanttype = (BlockDoublePlant.EnumPlantType)state.getValue(VARIANT);
++ EnumPlantType blockdoubleplant$enumplanttype = (EnumPlantType)state.getValue(VARIANT);
+
+- if (blockdoubleplant$enumplanttype != BlockDoublePlant.EnumPlantType.FERN && blockdoubleplant$enumplanttype != BlockDoublePlant.EnumPlantType.GRASS)
++ if (blockdoubleplant$enumplanttype != EnumPlantType.FERN && blockdoubleplant$enumplanttype != EnumPlantType.GRASS)
+ {
+ return false;
+ }
+@@ -223,7 +228,7 @@
+
+ public void getSubBlocks(CreativeTabs itemIn, NonNullList items)
+ {
+- for (BlockDoublePlant.EnumPlantType blockdoubleplant$enumplanttype : BlockDoublePlant.EnumPlantType.values())
++ for (EnumPlantType blockdoubleplant$enumplanttype : EnumPlantType.values())
+ {
+ items.add(new ItemStack(this, 1, blockdoubleplant$enumplanttype.getMeta()));
+ }
+@@ -236,8 +241,8 @@
+
+ public boolean canGrow(World worldIn, BlockPos pos, IBlockState state, boolean isClient)
+ {
+- BlockDoublePlant.EnumPlantType blockdoubleplant$enumplanttype = this.getType(worldIn, pos, state);
+- return blockdoubleplant$enumplanttype != BlockDoublePlant.EnumPlantType.GRASS && blockdoubleplant$enumplanttype != BlockDoublePlant.EnumPlantType.FERN;
++ EnumPlantType blockdoubleplant$enumplanttype = this.getType(worldIn, pos, state);
++ return blockdoubleplant$enumplanttype != EnumPlantType.GRASS && blockdoubleplant$enumplanttype != EnumPlantType.FERN;
+ }
+
+ public boolean canUseBonemeal(World worldIn, Random rand, BlockPos pos, IBlockState state)
+@@ -252,12 +257,12 @@
+
+ public IBlockState getStateFromMeta(int meta)
+ {
+- return (meta & 8) > 0 ? this.getDefaultState().withProperty(HALF, BlockDoublePlant.EnumBlockHalf.UPPER) : this.getDefaultState().withProperty(HALF, BlockDoublePlant.EnumBlockHalf.LOWER).withProperty(VARIANT, BlockDoublePlant.EnumPlantType.byMetadata(meta & 7));
++ return (meta & 8) > 0 ? this.getDefaultState().withProperty(HALF, EnumBlockHalf.UPPER) : this.getDefaultState().withProperty(HALF, EnumBlockHalf.LOWER).withProperty(VARIANT, EnumPlantType.byMetadata(meta & 7));
+ }
+
+ public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos)
+ {
+- if (state.getValue(HALF) == BlockDoublePlant.EnumBlockHalf.UPPER)
++ if (state.getValue(HALF) == EnumBlockHalf.UPPER)
+ {
+ IBlockState iblockstate = worldIn.getBlockState(pos.down());
+
+@@ -272,7 +277,7 @@
+
+ public int getMetaFromState(IBlockState state)
+ {
+- return state.getValue(HALF) == BlockDoublePlant.EnumBlockHalf.UPPER ? 8 | ((EnumFacing)state.getValue(FACING)).getHorizontalIndex() : ((BlockDoublePlant.EnumPlantType)state.getValue(VARIANT)).getMeta();
++ return state.getValue(HALF) == EnumBlockHalf.UPPER ? 8 | ((EnumFacing)state.getValue(FACING)).getHorizontalIndex() : ((EnumPlantType)state.getValue(VARIANT)).getMeta();
+ }
+
+ protected BlockStateContainer createBlockState()
+@@ -280,9 +285,9 @@
+ return new BlockStateContainer(this, new IProperty[] {HALF, VARIANT, FACING});
+ }
+
+- public Block.EnumOffsetType getOffsetType()
++ public EnumOffsetType getOffsetType()
+ {
+- return Block.EnumOffsetType.XZ;
++ return EnumOffsetType.XZ;
+ }
+
+ @Override
+@@ -328,7 +333,7 @@
+ ROSE(4, "double_rose", "rose"),
+ PAEONIA(5, "paeonia");
+
+- private static final BlockDoublePlant.EnumPlantType[] META_LOOKUP = new BlockDoublePlant.EnumPlantType[values().length];
++ private static final EnumPlantType[] META_LOOKUP = new EnumPlantType[values().length];
+ private final int meta;
+ private final String name;
+ private final String unlocalizedName;
+@@ -355,7 +360,7 @@
+ return this.name;
+ }
+
+- public static BlockDoublePlant.EnumPlantType byMetadata(int meta)
++ public static EnumPlantType byMetadata(int meta)
+ {
+ if (meta < 0 || meta >= META_LOOKUP.length)
+ {
+@@ -377,7 +382,7 @@
+
+ static
+ {
+- for (BlockDoublePlant.EnumPlantType blockdoubleplant$enumplanttype : values())
++ for (EnumPlantType blockdoubleplant$enumplanttype : values())
+ {
+ META_LOOKUP[blockdoubleplant$enumplanttype.getMeta()] = blockdoubleplant$enumplanttype;
+ }
diff --git a/patches/net/minecraft/block/BlockDragonEgg.java.patch b/patches/net/minecraft/block/BlockDragonEgg.java.patch
new file mode 100644
index 00000000..98f28f7d
--- /dev/null
+++ b/patches/net/minecraft/block/BlockDragonEgg.java.patch
@@ -0,0 +1,36 @@
+--- ../src-base/minecraft/net/minecraft/block/BlockDragonEgg.java
++++ ../src-work/minecraft/net/minecraft/block/BlockDragonEgg.java
+@@ -16,6 +16,7 @@
+ import net.minecraft.world.World;
+ import net.minecraftforge.fml.relauncher.Side;
+ import net.minecraftforge.fml.relauncher.SideOnly;
++import org.bukkit.event.block.BlockFromToEvent;
+
+ public class BlockDragonEgg extends Block
+ {
+@@ -68,7 +69,7 @@
+
+ if (blockpos.getY() > 0)
+ {
+- worldIn.setBlockState(blockpos, this.getDefaultState(), 2);
++ worldIn.setBlockState(blockpos.up(), this.getDefaultState(), 2); // Paper MC-94186 Fix dragon egg falling in lazy chunks
+ }
+ }
+ }
+@@ -97,6 +98,16 @@
+
+ if (worldIn.isAirBlock(blockpos))
+ {
++ org.bukkit.block.Block from = worldIn.getWorld().getBlockAt(pos.getX(), pos.getY(), pos.getZ());
++ org.bukkit.block.Block to = worldIn.getWorld().getBlockAt(blockpos.getX(), blockpos.getY(), blockpos.getZ());
++ BlockFromToEvent event = new BlockFromToEvent(from, to);
++ org.bukkit.Bukkit.getPluginManager().callEvent(event);
++
++ if (event.isCancelled()) {
++ return;
++ }
++
++ blockpos = new BlockPos(event.getToBlock().getX(), event.getToBlock().getY(), event.getToBlock().getZ());
+ if (worldIn.isRemote)
+ {
+ for (int j = 0; j < 128; ++j)
diff --git a/patches/net/minecraft/block/BlockDropper.java.patch b/patches/net/minecraft/block/BlockDropper.java.patch
new file mode 100644
index 00000000..217ad4ad
--- /dev/null
+++ b/patches/net/minecraft/block/BlockDropper.java.patch
@@ -0,0 +1,53 @@
+--- ../src-base/minecraft/net/minecraft/block/BlockDropper.java
++++ ../src-work/minecraft/net/minecraft/block/BlockDropper.java
+@@ -3,6 +3,7 @@
+ import net.minecraft.dispenser.BehaviorDefaultDispenseItem;
+ import net.minecraft.dispenser.IBehaviorDispenseItem;
+ import net.minecraft.inventory.IInventory;
++import net.minecraft.inventory.InventoryLargeChest;
+ import net.minecraft.item.ItemStack;
+ import net.minecraft.tileentity.TileEntity;
+ import net.minecraft.tileentity.TileEntityDispenser;
+@@ -11,6 +12,8 @@
+ import net.minecraft.util.EnumFacing;
+ import net.minecraft.util.math.BlockPos;
+ import net.minecraft.world.World;
++import org.bukkit.craftbukkit.inventory.CraftItemStack;
++import org.bukkit.event.inventory.InventoryMoveItemEvent;
+
+ public class BlockDropper extends BlockDispenser
+ {
+@@ -26,7 +29,7 @@
+ return new TileEntityDropper();
+ }
+
+- protected void dispense(World worldIn, BlockPos pos)
++ public void dispense(World worldIn, BlockPos pos)
+ {
+ BlockSourceImpl blocksourceimpl = new BlockSourceImpl(worldIn, pos);
+ TileEntityDispenser tileentitydispenser = (TileEntityDispenser)blocksourceimpl.getBlockTileEntity();
+@@ -56,9 +59,22 @@
+ }
+ else
+ {
+- itemstack1 = TileEntityHopper.putStackInInventoryAllSlots(tileentitydispenser, iinventory, itemstack.copy().splitStack(1), enumfacing.getOpposite());
++ CraftItemStack oitemstack = CraftItemStack.asCraftMirror(itemstack.copy().splitStack(1));
++ org.bukkit.inventory.Inventory destinationInventory;
++ // Have to special case large chests as they work oddly
++ if (iinventory instanceof InventoryLargeChest) {
++ destinationInventory = new org.bukkit.craftbukkit.inventory.CraftInventoryDoubleChest((InventoryLargeChest) iinventory);
++ } else {
++ destinationInventory = iinventory.getOwner().getInventory();
++ }
+
+- if (itemstack1.isEmpty())
++ InventoryMoveItemEvent event = new InventoryMoveItemEvent(tileentitydispenser.getOwner().getInventory(), oitemstack.clone(), destinationInventory, true);
++ worldIn.getServer().getPluginManager().callEvent(event);
++ if (event.isCancelled()) {
++ return;
++ }
++ itemstack1 = TileEntityHopper.putStackInInventoryAllSlots(tileentitydispenser, iinventory, CraftItemStack.asNMSCopy(event.getItem()), enumfacing.getOpposite());
++ if (event.getItem().equals(oitemstack) && itemstack1.isEmpty())
+ {
+ itemstack1 = itemstack.copy();
+ itemstack1.shrink(1);
diff --git a/patches/net/minecraft/block/BlockDynamicLiquid.java.patch b/patches/net/minecraft/block/BlockDynamicLiquid.java.patch
new file mode 100644
index 00000000..0e966c15
--- /dev/null
+++ b/patches/net/minecraft/block/BlockDynamicLiquid.java.patch
@@ -0,0 +1,68 @@
+--- ../src-base/minecraft/net/minecraft/block/BlockDynamicLiquid.java
++++ ../src-work/minecraft/net/minecraft/block/BlockDynamicLiquid.java
+@@ -9,6 +9,8 @@
+ import net.minecraft.util.EnumFacing;
+ import net.minecraft.util.math.BlockPos;
+ import net.minecraft.world.World;
++import org.bukkit.block.BlockFace;
++import org.bukkit.event.block.BlockFromToEvent;
+
+ public class BlockDynamicLiquid extends BlockLiquid
+ {
+@@ -82,7 +84,7 @@
+ }
+ }
+
+- if (this.blockMaterial == Material.LAVA && i < 8 && i1 < 8 && i1 > i && rand.nextInt(4) != 0)
++ if (this.blockMaterial == Material.LAVA && i < 8 && i1 < 8 && i1 > i && rand.nextInt(4) != 0) // Paper
+ {
+ k *= 4;
+ }
+@@ -113,14 +115,22 @@
+ this.placeStaticBlock(worldIn, pos, state);
+ }
+
++ org.bukkit.block.Block source = worldIn.getWorld().getBlockAt(pos.getX(), pos.getY(), pos.getZ());
+ IBlockState iblockstate1 = worldIn.getBlockState(pos.down());
+
+ if (this.canFlowInto(worldIn, pos.down(), iblockstate1))
+ {
++ BlockFromToEvent event = new BlockFromToEvent(source, BlockFace.DOWN);
++ worldIn.getServer().getPluginManager().callEvent(event);
++
++ if (event.isCancelled()) {
++ return;
++ }
+ if (this.blockMaterial == Material.LAVA && worldIn.getBlockState(pos.down()).getMaterial() == Material.WATER)
+ {
+- worldIn.setBlockState(pos.down(), net.minecraftforge.event.ForgeEventFactory.fireFluidPlaceBlockEvent(worldIn, pos.down(), pos, Blocks.STONE.getDefaultState()));
+- this.triggerMixEffects(worldIn, pos.down());
++ if (org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockFormEvent(worldIn, pos.down(), net.minecraftforge.event.ForgeEventFactory.fireFluidPlaceBlockEvent(worldIn, pos.down(), pos, Blocks.STONE.getDefaultState()), null)) {
++ this.triggerMixEffects(worldIn, pos.down());
++ }
+ return;
+ }
+
+@@ -150,14 +160,20 @@
+
+ for (EnumFacing enumfacing1 : set)
+ {
+- this.tryFlowInto(worldIn, pos.offset(enumfacing1), worldIn.getBlockState(pos.offset(enumfacing1)), k1);
++ // CraftBukkit start
++ BlockFromToEvent event = new BlockFromToEvent(source, org.bukkit.craftbukkit.block.CraftBlock.notchToBlockFace(enumfacing1));
++ worldIn.getServer().getPluginManager().callEvent(event);
++
++ if (!event.isCancelled()) {
++ this.tryFlowInto(worldIn, pos.offset(enumfacing1), worldIn.getBlockState(pos.offset(enumfacing1)), k1);
++ }
+ }
+ }
+ }
+
+ private void tryFlowInto(World worldIn, BlockPos pos, IBlockState state, int level)
+ {
+- if (this.canFlowInto(worldIn, pos, state))
++ if (worldIn.isBlockLoaded(pos) && this.canFlowInto(worldIn, pos, state)) // CraftBukkit - add isLoaded check
+ {
+ if (state.getMaterial() != Material.AIR)
+ {
diff --git a/patches/net/minecraft/block/BlockEndPortal.java.patch b/patches/net/minecraft/block/BlockEndPortal.java.patch
new file mode 100644
index 00000000..5415c351
--- /dev/null
+++ b/patches/net/minecraft/block/BlockEndPortal.java.patch
@@ -0,0 +1,19 @@
+--- ../src-base/minecraft/net/minecraft/block/BlockEndPortal.java
++++ ../src-work/minecraft/net/minecraft/block/BlockEndPortal.java
+@@ -19,6 +19,7 @@
+ import net.minecraft.world.World;
+ import net.minecraftforge.fml.relauncher.Side;
+ import net.minecraftforge.fml.relauncher.SideOnly;
++import org.bukkit.event.entity.EntityPortalEnterEvent;
+
+ public class BlockEndPortal extends BlockContainer
+ {
+@@ -69,6 +70,8 @@
+ {
+ if (!worldIn.isRemote && !entityIn.isRiding() && !entityIn.isBeingRidden() && entityIn.isNonBoss() && entityIn.getEntityBoundingBox().intersects(state.getBoundingBox(worldIn, pos).offset(pos)))
+ {
++ EntityPortalEnterEvent event = new EntityPortalEnterEvent(entityIn.getBukkitEntity(), new org.bukkit.Location(worldIn.getWorld(), pos.getX(), pos.getY(), pos.getZ()));
++ worldIn.getServer().getPluginManager().callEvent(event);
+ entityIn.changeDimension(1);
+ }
+ }
diff --git a/patches/net/minecraft/block/BlockFarmland.java.patch b/patches/net/minecraft/block/BlockFarmland.java.patch
new file mode 100644
index 00000000..4668c3c7
--- /dev/null
+++ b/patches/net/minecraft/block/BlockFarmland.java.patch
@@ -0,0 +1,67 @@
+--- ../src-base/minecraft/net/minecraft/block/BlockFarmland.java
++++ ../src-work/minecraft/net/minecraft/block/BlockFarmland.java
+@@ -19,6 +19,8 @@
+ import net.minecraft.world.World;
+ import net.minecraftforge.fml.relauncher.Side;
+ import net.minecraftforge.fml.relauncher.SideOnly;
++import org.bukkit.craftbukkit.event.CraftEventFactory;
++import org.bukkit.event.entity.EntityInteractEvent;
+
+ public class BlockFarmland extends Block
+ {
+@@ -72,16 +74,36 @@
+
+ public void onFallenUpon(World worldIn, BlockPos pos, Entity entityIn, float fallDistance)
+ {
++ super.onFallenUpon(worldIn, pos, entityIn, fallDistance); // CraftBukkit - moved here as game rules / events shouldn't affect fall damage.
+ if (net.minecraftforge.common.ForgeHooks.onFarmlandTrample(worldIn, pos, Blocks.DIRT.getDefaultState(), fallDistance, entityIn)) // Forge: Move logic to Entity#canTrample
+ {
++ org.bukkit.event.Cancellable cancellable;
++ if (entityIn instanceof EntityPlayer) {
++ cancellable = CraftEventFactory.callPlayerInteractEvent((EntityPlayer) entityIn, org.bukkit.event.block.Action.PHYSICAL, pos, null, null, null);
++ } else {
++ cancellable = new EntityInteractEvent(entityIn.getBukkitEntity(), worldIn.getWorld().getBlockAt(pos.getX(), pos.getY(), pos.getZ()));
++ worldIn.getServer().getPluginManager().callEvent((EntityInteractEvent) cancellable);
++ }
++
++ if (cancellable.isCancelled()) {
++ return;
++ }
++
++ if (CraftEventFactory.callEntityChangeBlockEvent(entityIn, pos, Blocks.DIRT, 0).isCancelled()) {
++ return;
++ }
+ turnToDirt(worldIn, pos);
+ }
+
+- super.onFallenUpon(worldIn, pos, entityIn, fallDistance);
++// super.onFallenUpon(worldIn, pos, entityIn, fallDistance); // CraftBukkit - moved up
+ }
+
+ protected static void turnToDirt(World p_190970_0_, BlockPos worldIn)
+ {
++ org.bukkit.block.Block block = p_190970_0_.getWorld().getBlockAt(worldIn.getX(), worldIn.getY(), worldIn.getZ());
++ if (CraftEventFactory.callBlockFadeEvent(block, Blocks.DIRT).isCancelled()) {
++ return;
++ }
+ p_190970_0_.setBlockState(worldIn, Blocks.DIRT.getDefaultState());
+ AxisAlignedBB axisalignedbb = field_194405_c.offset(worldIn);
+
+@@ -95,7 +117,7 @@
+ private boolean hasCrops(World worldIn, BlockPos pos)
+ {
+ Block block = worldIn.getBlockState(pos.up()).getBlock();
+- return block instanceof net.minecraftforge.common.IPlantable && canSustainPlant(worldIn.getBlockState(pos), worldIn, pos, net.minecraft.util.EnumFacing.UP, (net.minecraftforge.common.IPlantable)block);
++ return block instanceof net.minecraftforge.common.IPlantable && canSustainPlant(worldIn.getBlockState(pos), worldIn, pos, EnumFacing.UP, (net.minecraftforge.common.IPlantable)block);
+ }
+
+ private boolean hasWater(World worldIn, BlockPos pos)
+@@ -108,7 +130,7 @@
+ }
+ }
+
+- return net.minecraftforge.common.FarmlandWaterManager.hasBlockWaterTicket(worldIn, pos);
++ return false;
+ }
+
+ public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos)
diff --git a/patches/net/minecraft/block/BlockFire.java.patch b/patches/net/minecraft/block/BlockFire.java.patch
new file mode 100644
index 00000000..96963068
--- /dev/null
+++ b/patches/net/minecraft/block/BlockFire.java.patch
@@ -0,0 +1,186 @@
+--- ../src-base/minecraft/net/minecraft/block/BlockFire.java
++++ ../src-work/minecraft/net/minecraft/block/BlockFire.java
+@@ -22,9 +22,11 @@
+ import net.minecraft.util.math.BlockPos;
+ import net.minecraft.world.IBlockAccess;
+ import net.minecraft.world.World;
+-import net.minecraft.world.WorldProviderEnd;
+ import net.minecraftforge.fml.relauncher.Side;
+ import net.minecraftforge.fml.relauncher.SideOnly;
++import org.bukkit.craftbukkit.event.CraftEventFactory;
++import org.bukkit.event.block.BlockBurnEvent;
++import org.bukkit.event.block.BlockSpreadEvent;
+
+ public class BlockFire extends Block
+ {
+@@ -138,7 +140,7 @@
+ if (!worldIn.isAreaLoaded(pos, 2)) return; // Forge: prevent loading unloaded chunks when spreading fire
+ if (!this.canPlaceBlockAt(worldIn, pos))
+ {
+- worldIn.setBlockToAir(pos);
++ fireExtinguished(worldIn, pos); // CraftBukkit - invalid place location
+ }
+
+ Block block = worldIn.getBlockState(pos.down()).getBlock();
+@@ -148,7 +150,7 @@
+
+ if (!flag && worldIn.isRaining() && this.canDie(worldIn, pos) && rand.nextFloat() < 0.2F + (float)i * 0.03F)
+ {
+- worldIn.setBlockToAir(pos);
++ fireExtinguished(worldIn, pos); // CraftBukkit - extinguished by rain
+ }
+ else
+ {
+@@ -166,7 +168,7 @@
+ {
+ if (!worldIn.getBlockState(pos.down()).isSideSolid(worldIn, pos.down(), EnumFacing.UP) || i > 3)
+ {
+- worldIn.setBlockToAir(pos);
++ fireExtinguished(worldIn, pos);
+ }
+
+ return;
+@@ -174,7 +176,7 @@
+
+ if (!this.canCatchFire(worldIn, pos.down(), EnumFacing.UP) && i == 15 && rand.nextInt(4) == 0)
+ {
+- worldIn.setBlockToAir(pos);
++ fireExtinguished(worldIn, pos);
+ return;
+ }
+ }
+@@ -187,12 +189,14 @@
+ j = -50;
+ }
+
+- this.tryCatchFire(worldIn, pos.east(), 300 + j, rand, i, EnumFacing.WEST);
+- this.tryCatchFire(worldIn, pos.west(), 300 + j, rand, i, EnumFacing.EAST);
+- this.tryCatchFire(worldIn, pos.down(), 250 + j, rand, i, EnumFacing.UP);
+- this.tryCatchFire(worldIn, pos.up(), 250 + j, rand, i, EnumFacing.DOWN);
+- this.tryCatchFire(worldIn, pos.north(), 300 + j, rand, i, EnumFacing.SOUTH);
+- this.tryCatchFire(worldIn, pos.south(), 300 + j, rand, i, EnumFacing.NORTH);
++ // CraftBukkit start - add source blockposition to burn calls
++ this.tryCatchFire(worldIn, pos.east(), 300 + j, rand, i, EnumFacing.WEST, pos);
++ this.tryCatchFire(worldIn, pos.west(), 300 + j, rand, i, EnumFacing.EAST, pos);
++ this.tryCatchFire(worldIn, pos.down(), 250 + j, rand, i, EnumFacing.UP, pos);
++ this.tryCatchFire(worldIn, pos.up(), 250 + j, rand, i, EnumFacing.DOWN, pos);
++ this.tryCatchFire(worldIn, pos.north(), 300 + j, rand, i, EnumFacing.SOUTH, pos);
++ this.tryCatchFire(worldIn, pos.south(), 300 + j, rand, i, EnumFacing.NORTH, pos);
++ // CraftBukkit end
+
+ for (int k = -1; k <= 1; ++k)
+ {
+@@ -210,6 +214,7 @@
+ }
+
+ BlockPos blockpos = pos.add(k, i1, l);
++ if (!worldIn.isBlockLoaded(blockpos)) continue; // Paper
+ int k1 = this.getNeighborEncouragement(worldIn, blockpos);
+
+ if (k1 > 0)
+@@ -230,7 +235,26 @@
+ i2 = 15;
+ }
+
+- worldIn.setBlockState(blockpos, state.withProperty(AGE, Integer.valueOf(i2)), 3);
++ // CraftBukkit start - Call to stop spread of fire
++ if (worldIn.getBlockState(blockpos) != Blocks.FIRE) {
++ if (CraftEventFactory.callBlockIgniteEvent(worldIn, blockpos.getX(), blockpos.getY(), blockpos.getZ(), pos.getX(), pos.getY(), pos.getZ()).isCancelled()) {
++ continue;
++ }
++
++ org.bukkit.Server server = worldIn.getServer();
++ org.bukkit.World bworld = worldIn.getWorld();
++ org.bukkit.block.BlockState blockState = bworld.getBlockAt(blockpos.getX(), blockpos.getY(), blockpos.getZ()).getState();
++ blockState.setTypeId(Block.getIdFromBlock(this));
++ blockState.setData(new org.bukkit.material.MaterialData(Block.getIdFromBlock(this), (byte) l1));
++
++ BlockSpreadEvent spreadEvent = new BlockSpreadEvent(blockState.getBlock(), bworld.getBlockAt(pos.getX(), pos.getY(), pos.getZ()), blockState);
++ server.getPluginManager().callEvent(spreadEvent);
++
++ if (!spreadEvent.isCancelled()) {
++ blockState.update(true);
++ }
++ }
++ // CraftBukkit end
+ }
+ }
+ }
+@@ -302,6 +326,48 @@
+ }
+ }
+
++ // Atom: Create a new method, instead of the method modification above for sanity
++ private void tryCatchFire(World worldIn, BlockPos pos, int chance, Random random, int age, EnumFacing face, BlockPos sourcePos)
++ {
++ final IBlockState iblockstate = worldIn.getBlockState(pos);
++ if (iblockstate == null) return;
++ int i = worldIn.getBlockState(pos).getBlock().getFlammability(worldIn, pos, face);
++
++ if (random.nextInt(chance) < i)
++ {
++ org.bukkit.block.Block theBlock = worldIn.getWorld().getBlockAt(pos.getX(), pos.getY(), pos.getZ());
++ org.bukkit.block.Block sourceBlock = worldIn.getWorld().getBlockAt(sourcePos.getX(), sourcePos.getY(), sourcePos.getZ());
++
++ BlockBurnEvent event = new BlockBurnEvent(theBlock, sourceBlock);
++ worldIn.getServer().getPluginManager().callEvent(event);
++
++ if (event.isCancelled()) {
++ return;
++ }
++
++ if (random.nextInt(age + 10) < 5 && !worldIn.isRainingAt(pos))
++ {
++ int j = age + random.nextInt(5) / 4;
++
++ if (j > 15)
++ {
++ j = 15;
++ }
++
++ worldIn.setBlockState(pos, this.getDefaultState().withProperty(AGE, Integer.valueOf(j)), 3);
++ }
++ else
++ {
++ worldIn.setBlockToAir(pos);
++ }
++
++ if (iblockstate.getBlock() == Blocks.TNT)
++ {
++ Blocks.TNT.onBlockDestroyedByPlayer(worldIn, pos, iblockstate.withProperty(BlockTNT.EXPLODE, Boolean.valueOf(true)));
++ }
++ }
++ }
++
+ private boolean canNeighborCatchFire(World worldIn, BlockPos pos)
+ {
+ for (EnumFacing enumfacing : EnumFacing.values())
+@@ -354,7 +420,7 @@
+ {
+ if (!worldIn.getBlockState(pos.down()).isTopSolid() && !this.canNeighborCatchFire(worldIn, pos))
+ {
+- worldIn.setBlockToAir(pos);
++ fireExtinguished(worldIn, pos); // CraftBukkit - fuel block gone
+ }
+ }
+
+@@ -364,7 +430,7 @@
+ {
+ if (!worldIn.getBlockState(pos.down()).isTopSolid() && !this.canNeighborCatchFire(worldIn, pos))
+ {
+- worldIn.setBlockToAir(pos);
++ fireExtinguished(worldIn, pos); // CraftBukkit - fuel block broke
+ }
+ else
+ {
+@@ -495,4 +561,10 @@
+ {
+ return BlockFaceShape.UNDEFINED;
+ }
++
++ private void fireExtinguished(World world, BlockPos position) {
++ if (!CraftEventFactory.callBlockFadeEvent(world.getWorld().getBlockAt(position.getX(), position.getY(), position.getZ()), Blocks.AIR).isCancelled()) {
++ world.setBlockToAir(position);
++ }
++ }
+ }
diff --git a/patches/net/minecraft/block/BlockGrass.java.patch b/patches/net/minecraft/block/BlockGrass.java.patch
new file mode 100644
index 00000000..8001a5b1
--- /dev/null
+++ b/patches/net/minecraft/block/BlockGrass.java.patch
@@ -0,0 +1,90 @@
+--- ../src-base/minecraft/net/minecraft/block/BlockGrass.java
++++ ../src-work/minecraft/net/minecraft/block/BlockGrass.java
+@@ -15,6 +15,11 @@
+ import net.minecraft.world.World;
+ import net.minecraftforge.fml.relauncher.Side;
+ import net.minecraftforge.fml.relauncher.SideOnly;
++import org.bukkit.block.BlockState;
++import org.bukkit.craftbukkit.event.CraftEventFactory;
++import org.bukkit.craftbukkit.util.CraftMagicNumbers;
++import org.bukkit.event.block.BlockFadeEvent;
++import org.bukkit.event.block.BlockSpreadEvent;
+
+ public class BlockGrass extends Block implements IGrowable
+ {
+@@ -38,30 +43,58 @@
+ {
+ if (!worldIn.isRemote)
+ {
++ int lightLevel = -1; // Paper
+ if (!worldIn.isAreaLoaded(pos, 3)) return; // Forge: prevent loading unloaded chunks when checking neighbor's light and spreading
+- if (worldIn.getLightFromNeighbors(pos.up()) < 4 && worldIn.getBlockState(pos.up()).getLightOpacity(worldIn, pos.up()) > 2)
++ if (worldIn.getBlockState(pos.up()).getLightOpacity(worldIn, pos.up()) > 2 && (lightLevel = worldIn.getLightFromNeighbors(pos.up())) < 4 )
+ {
+- worldIn.setBlockState(pos, Blocks.DIRT.getDefaultState());
++ org.bukkit.World bworld = worldIn.getWorld();
++ BlockState blockState = bworld.getBlockAt(pos.getX(), pos.getY(), pos.getZ()).getState();
++ blockState.setType(CraftMagicNumbers.getMaterial(Blocks.DIRT));
++
++ BlockFadeEvent event = new BlockFadeEvent(blockState.getBlock(), blockState);
++ worldIn.getServer().getPluginManager().callEvent(event);
++
++ if (!event.isCancelled()) {
++ blockState.update(true);
++ }
+ }
+ else
+ {
+- if (worldIn.getLightFromNeighbors(pos.up()) >= 9)
++ // Paper start
++ // If light was calculated above, reuse it, else grab it
++ if (lightLevel == -1) {
++ lightLevel = worldIn.getLightFromNeighbors(pos.up());
++ }
++ if (lightLevel >= 9)
+ {
++ // Paper end
+ for (int i = 0; i < 4; ++i)
+ {
+ BlockPos blockpos = pos.add(rand.nextInt(3) - 1, rand.nextInt(5) - 3, rand.nextInt(3) - 1);
+
+- if (blockpos.getY() >= 0 && blockpos.getY() < 256 && !worldIn.isBlockLoaded(blockpos))
++ IBlockState iblockstate2 = worldIn.getBlockState(blockpos); // Paper - moved up
++ if (iblockstate2 == null)
+ {
+ return;
+ }
+
+ IBlockState iblockstate = worldIn.getBlockState(blockpos.up());
+- IBlockState iblockstate1 = worldIn.getBlockState(blockpos);
++ //IBlockState iblockstate1 = worldIn.getBlockState(blockpos); // Paper - moved up
+
+- if (iblockstate1.getBlock() == Blocks.DIRT && iblockstate1.getValue(BlockDirt.VARIANT) == BlockDirt.DirtType.DIRT && worldIn.getLightFromNeighbors(blockpos.up()) >= 4 && iblockstate.getLightOpacity(worldIn, pos.up()) <= 2)
++ // Paper - move last check before isLightLevel to avoid unneeded light checks
++ if (iblockstate2.getBlock() == Blocks.DIRT && iblockstate2.getValue(BlockDirt.VARIANT) == BlockDirt.DirtType.DIRT && iblockstate.getLightOpacity(worldIn, pos.up()) <= 2 && worldIn.isLightLevel(blockpos.up(), 4))
+ {
+- worldIn.setBlockState(blockpos, Blocks.GRASS.getDefaultState());
++// worldIn.setBlockState(blockpos, Blocks.GRASS.getDefaultState());
++ org.bukkit.World bworld = worldIn.getWorld();
++ BlockState blockState = bworld.getBlockAt(blockpos.getX(), blockpos.getY(), blockpos.getZ()).getState();
++ blockState.setType(CraftMagicNumbers.getMaterial(Blocks.GRASS));
++
++ BlockSpreadEvent event = new BlockSpreadEvent(blockState.getBlock(), bworld.getBlockAt(pos.getX(), pos.getY(), pos.getZ()), blockState);
++ worldIn.getServer().getPluginManager().callEvent(event);
++
++ if (!event.isCancelled()) {
++ blockState.update(true);
++ }
+ }
+ }
+ }
+@@ -109,7 +142,8 @@
+
+ if (Blocks.TALLGRASS.canBlockStay(worldIn, blockpos1, iblockstate1))
+ {
+- worldIn.setBlockState(blockpos1, iblockstate1, 3);
++// worldIn.setBlockState(blockpos1, iblockstate1, 3);
++ CraftEventFactory.handleBlockGrowEvent(worldIn, blockpos1.getX(), blockpos1.getY(), blockpos1.getZ(), iblockstate1.getBlock(), iblockstate1.getBlock().getMetaFromState(iblockstate1));
+ }
+ }
+ }
diff --git a/patches/net/minecraft/block/BlockIce.java.patch b/patches/net/minecraft/block/BlockIce.java.patch
new file mode 100644
index 00000000..83339cdb
--- /dev/null
+++ b/patches/net/minecraft/block/BlockIce.java.patch
@@ -0,0 +1,12 @@
+--- ../src-base/minecraft/net/minecraft/block/BlockIce.java
++++ ../src-work/minecraft/net/minecraft/block/BlockIce.java
+@@ -86,6 +86,9 @@
+
+ protected void turnIntoWater(World worldIn, BlockPos pos)
+ {
++ if (org.bukkit.craftbukkit.event.CraftEventFactory.callBlockFadeEvent(worldIn.getWorld().getBlockAt(pos.getX(), pos.getY(), pos.getZ()), worldIn.provider.doesWaterVaporize() ? Blocks.AIR : Blocks.WATER).isCancelled()) {
++ return;
++ }
+ if (worldIn.provider.doesWaterVaporize())
+ {
+ worldIn.setBlockToAir(pos);
diff --git a/patches/net/minecraft/block/BlockJukebox.java.patch b/patches/net/minecraft/block/BlockJukebox.java.patch
new file mode 100644
index 00000000..22d8f7de
--- /dev/null
+++ b/patches/net/minecraft/block/BlockJukebox.java.patch
@@ -0,0 +1,23 @@
+--- ../src-base/minecraft/net/minecraft/block/BlockJukebox.java
++++ ../src-work/minecraft/net/minecraft/block/BlockJukebox.java
+@@ -66,7 +66,7 @@
+ }
+ }
+
+- private void dropRecord(World worldIn, BlockPos pos, IBlockState state)
++ public void dropRecord(World worldIn, BlockPos pos, IBlockState state)
+ {
+ if (!worldIn.isRemote)
+ {
+@@ -193,6 +193,11 @@
+
+ public void setRecord(ItemStack recordStack)
+ {
++ // CraftBukkit start - There can only be one
++ if (!recordStack.isEmpty()) {
++ recordStack.setCount(1);
++ }
++ // CraftBukkit end
+ this.record = recordStack;
+ this.markDirty();
+ }
diff --git a/patches/net/minecraft/block/BlockLeaves.java.patch b/patches/net/minecraft/block/BlockLeaves.java.patch
new file mode 100644
index 00000000..1dfcacf0
--- /dev/null
+++ b/patches/net/minecraft/block/BlockLeaves.java.patch
@@ -0,0 +1,23 @@
+--- ../src-base/minecraft/net/minecraft/block/BlockLeaves.java
++++ ../src-work/minecraft/net/minecraft/block/BlockLeaves.java
+@@ -16,6 +16,7 @@
+ import net.minecraft.world.World;
+ import net.minecraftforge.fml.relauncher.Side;
+ import net.minecraftforge.fml.relauncher.SideOnly;
++import org.bukkit.event.block.LeavesDecayEvent;
+
+ public abstract class BlockLeaves extends Block implements net.minecraftforge.common.IShearable
+ {
+@@ -178,6 +179,12 @@
+
+ private void destroy(World worldIn, BlockPos pos)
+ {
++ LeavesDecayEvent event = new LeavesDecayEvent(worldIn.getWorld().getBlockAt(pos.getX(), pos.getY(), pos.getZ()));
++ worldIn.getServer().getPluginManager().callEvent(event);
++
++ if (event.isCancelled() || worldIn.getBlockState(pos).getBlock() != this) {
++ return;
++ }
+ this.dropBlockAsItem(worldIn, pos, worldIn.getBlockState(pos), 0);
+ worldIn.setBlockToAir(pos);
+ }
diff --git a/patches/net/minecraft/block/BlockLever.java.patch b/patches/net/minecraft/block/BlockLever.java.patch
new file mode 100644
index 00000000..be12b8a4
--- /dev/null
+++ b/patches/net/minecraft/block/BlockLever.java.patch
@@ -0,0 +1,257 @@
+--- ../src-base/minecraft/net/minecraft/block/BlockLever.java
++++ ../src-work/minecraft/net/minecraft/block/BlockLever.java
+@@ -22,10 +22,11 @@
+ import net.minecraft.util.math.BlockPos;
+ import net.minecraft.world.IBlockAccess;
+ import net.minecraft.world.World;
++import org.bukkit.event.block.BlockRedstoneEvent;
+
+ public class BlockLever extends Block
+ {
+- public static final PropertyEnum FACING = PropertyEnum.create("facing", BlockLever.EnumOrientation.class);
++ public static final PropertyEnum FACING = PropertyEnum.create("facing", EnumOrientation.class);
+ public static final PropertyBool POWERED = PropertyBool.create("powered");
+ protected static final AxisAlignedBB LEVER_NORTH_AABB = new AxisAlignedBB(0.3125D, 0.20000000298023224D, 0.625D, 0.6875D, 0.800000011920929D, 1.0D);
+ protected static final AxisAlignedBB LEVER_SOUTH_AABB = new AxisAlignedBB(0.3125D, 0.20000000298023224D, 0.0D, 0.6875D, 0.800000011920929D, 0.375D);
+@@ -37,7 +38,7 @@
+ protected BlockLever()
+ {
+ super(Material.CIRCUITS);
+- this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, BlockLever.EnumOrientation.NORTH).withProperty(POWERED, Boolean.valueOf(false)));
++ this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumOrientation.NORTH).withProperty(POWERED, Boolean.valueOf(false)));
+ this.setCreativeTab(CreativeTabs.REDSTONE);
+ }
+
+@@ -86,7 +87,7 @@
+
+ if (canAttachTo(worldIn, pos, facing))
+ {
+- return iblockstate.withProperty(FACING, BlockLever.EnumOrientation.forFacings(facing, placer.getHorizontalFacing()));
++ return iblockstate.withProperty(FACING, EnumOrientation.forFacings(facing, placer.getHorizontalFacing()));
+ }
+ else
+ {
+@@ -94,13 +95,13 @@
+ {
+ if (enumfacing != facing && canAttachTo(worldIn, pos, enumfacing))
+ {
+- return iblockstate.withProperty(FACING, BlockLever.EnumOrientation.forFacings(enumfacing, placer.getHorizontalFacing()));
++ return iblockstate.withProperty(FACING, EnumOrientation.forFacings(enumfacing, placer.getHorizontalFacing()));
+ }
+ }
+
+ if (worldIn.getBlockState(pos.down()).isTopSolid())
+ {
+- return iblockstate.withProperty(FACING, BlockLever.EnumOrientation.forFacings(EnumFacing.UP, placer.getHorizontalFacing()));
++ return iblockstate.withProperty(FACING, EnumOrientation.forFacings(EnumFacing.UP, placer.getHorizontalFacing()));
+ }
+ else
+ {
+@@ -111,7 +112,7 @@
+
+ public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos)
+ {
+- if (this.checkCanSurvive(worldIn, pos, state) && !canAttachTo(worldIn, pos, ((BlockLever.EnumOrientation)state.getValue(FACING)).getFacing()))
++ if (this.checkCanSurvive(worldIn, pos, state) && !canAttachTo(worldIn, pos, ((EnumOrientation)state.getValue(FACING)).getFacing()))
+ {
+ this.dropBlockAsItem(worldIn, pos, state, 0);
+ worldIn.setBlockToAir(pos);
+@@ -134,7 +135,7 @@
+
+ public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos)
+ {
+- switch ((BlockLever.EnumOrientation)state.getValue(FACING))
++ switch ((EnumOrientation)state.getValue(FACING))
+ {
+ case EAST:
+ default:
+@@ -162,12 +163,23 @@
+ }
+ else
+ {
++ boolean powered = state.getValue(POWERED);
++ org.bukkit.block.Block block = worldIn.getWorld().getBlockAt(pos.getX(), pos.getY(), pos.getZ());
++ int old = (powered) ? 15 : 0;
++ int current = (!powered) ? 15 : 0;
++
++ BlockRedstoneEvent eventRedstone = new BlockRedstoneEvent(block, old, current);
++ worldIn.getServer().getPluginManager().callEvent(eventRedstone);
++
++ if ((eventRedstone.getNewCurrent() > 0) == powered) {
++ return true;
++ }
+ state = state.cycleProperty(POWERED);
+ worldIn.setBlockState(pos, state, 3);
+ float f = ((Boolean)state.getValue(POWERED)).booleanValue() ? 0.6F : 0.5F;
+ worldIn.playSound((EntityPlayer)null, pos, SoundEvents.BLOCK_LEVER_CLICK, SoundCategory.BLOCKS, 0.3F, f);
+ worldIn.notifyNeighborsOfStateChange(pos, this, false);
+- EnumFacing enumfacing = ((BlockLever.EnumOrientation)state.getValue(FACING)).getFacing();
++ EnumFacing enumfacing = ((EnumOrientation)state.getValue(FACING)).getFacing();
+ worldIn.notifyNeighborsOfStateChange(pos.offset(enumfacing.getOpposite()), this, false);
+ return true;
+ }
+@@ -178,7 +190,7 @@
+ if (((Boolean)state.getValue(POWERED)).booleanValue())
+ {
+ worldIn.notifyNeighborsOfStateChange(pos, this, false);
+- EnumFacing enumfacing = ((BlockLever.EnumOrientation)state.getValue(FACING)).getFacing();
++ EnumFacing enumfacing = ((EnumOrientation)state.getValue(FACING)).getFacing();
+ worldIn.notifyNeighborsOfStateChange(pos.offset(enumfacing.getOpposite()), this, false);
+ }
+
+@@ -198,7 +210,7 @@
+ }
+ else
+ {
+- return ((BlockLever.EnumOrientation)blockState.getValue(FACING)).getFacing() == side ? 15 : 0;
++ return ((EnumOrientation)blockState.getValue(FACING)).getFacing() == side ? 15 : 0;
+ }
+ }
+
+@@ -209,13 +221,13 @@
+
+ public IBlockState getStateFromMeta(int meta)
+ {
+- return this.getDefaultState().withProperty(FACING, BlockLever.EnumOrientation.byMetadata(meta & 7)).withProperty(POWERED, Boolean.valueOf((meta & 8) > 0));
++ return this.getDefaultState().withProperty(FACING, EnumOrientation.byMetadata(meta & 7)).withProperty(POWERED, Boolean.valueOf((meta & 8) > 0));
+ }
+
+ public int getMetaFromState(IBlockState state)
+ {
+ int i = 0;
+- i = i | ((BlockLever.EnumOrientation)state.getValue(FACING)).getMetadata();
++ i = i | ((EnumOrientation)state.getValue(FACING)).getMetadata();
+
+ if (((Boolean)state.getValue(POWERED)).booleanValue())
+ {
+@@ -231,62 +243,62 @@
+ {
+ case CLOCKWISE_180:
+
+- switch ((BlockLever.EnumOrientation)state.getValue(FACING))
++ switch ((EnumOrientation)state.getValue(FACING))
+ {
+ case EAST:
+- return state.withProperty(FACING, BlockLever.EnumOrientation.WEST);
++ return state.withProperty(FACING, EnumOrientation.WEST);
+ case WEST:
+- return state.withProperty(FACING, BlockLever.EnumOrientation.EAST);
++ return state.withProperty(FACING, EnumOrientation.EAST);
+ case SOUTH:
+- return state.withProperty(FACING, BlockLever.EnumOrientation.NORTH);
++ return state.withProperty(FACING, EnumOrientation.NORTH);
+ case NORTH:
+- return state.withProperty(FACING, BlockLever.EnumOrientation.SOUTH);
++ return state.withProperty(FACING, EnumOrientation.SOUTH);
+ default:
+ return state;
+ }
+
+ case COUNTERCLOCKWISE_90:
+
+- switch ((BlockLever.EnumOrientation)state.getValue(FACING))
++ switch ((EnumOrientation)state.getValue(FACING))
+ {
+ case EAST:
+- return state.withProperty(FACING, BlockLever.EnumOrientation.NORTH);
++ return state.withProperty(FACING, EnumOrientation.NORTH);
+ case WEST:
+- return state.withProperty(FACING, BlockLever.EnumOrientation.SOUTH);
++ return state.withProperty(FACING, EnumOrientation.SOUTH);
+ case SOUTH:
+- return state.withProperty(FACING, BlockLever.EnumOrientation.EAST);
++ return state.withProperty(FACING, EnumOrientation.EAST);
+ case NORTH:
+- return state.withProperty(FACING, BlockLever.EnumOrientation.WEST);
++ return state.withProperty(FACING, EnumOrientation.WEST);
+ case UP_Z:
+- return state.withProperty(FACING, BlockLever.EnumOrientation.UP_X);
++ return state.withProperty(FACING, EnumOrientation.UP_X);
+ case UP_X:
+- return state.withProperty(FACING, BlockLever.EnumOrientation.UP_Z);
++ return state.withProperty(FACING, EnumOrientation.UP_Z);
+ case DOWN_X:
+- return state.withProperty(FACING, BlockLever.EnumOrientation.DOWN_Z);
++ return state.withProperty(FACING, EnumOrientation.DOWN_Z);
+ case DOWN_Z:
+- return state.withProperty(FACING, BlockLever.EnumOrientation.DOWN_X);
++ return state.withProperty(FACING, EnumOrientation.DOWN_X);
+ }
+
+ case CLOCKWISE_90:
+
+- switch ((BlockLever.EnumOrientation)state.getValue(FACING))
++ switch ((EnumOrientation)state.getValue(FACING))
+ {
+ case EAST:
+- return state.withProperty(FACING, BlockLever.EnumOrientation.SOUTH);
++ return state.withProperty(FACING, EnumOrientation.SOUTH);
+ case WEST:
+- return state.withProperty(FACING, BlockLever.EnumOrientation.NORTH);
++ return state.withProperty(FACING, EnumOrientation.NORTH);
+ case SOUTH:
+- return state.withProperty(FACING, BlockLever.EnumOrientation.WEST);
++ return state.withProperty(FACING, EnumOrientation.WEST);
+ case NORTH:
+- return state.withProperty(FACING, BlockLever.EnumOrientation.EAST);
++ return state.withProperty(FACING, EnumOrientation.EAST);
+ case UP_Z:
+- return state.withProperty(FACING, BlockLever.EnumOrientation.UP_X);
++ return state.withProperty(FACING, EnumOrientation.UP_X);
+ case UP_X:
+- return state.withProperty(FACING, BlockLever.EnumOrientation.UP_Z);
++ return state.withProperty(FACING, EnumOrientation.UP_Z);
+ case DOWN_X:
+- return state.withProperty(FACING, BlockLever.EnumOrientation.DOWN_Z);
++ return state.withProperty(FACING, EnumOrientation.DOWN_Z);
+ case DOWN_Z:
+- return state.withProperty(FACING, BlockLever.EnumOrientation.DOWN_X);
++ return state.withProperty(FACING, EnumOrientation.DOWN_X);
+ }
+
+ default:
+@@ -296,7 +308,7 @@
+
+ public IBlockState withMirror(IBlockState state, Mirror mirrorIn)
+ {
+- return state.withRotation(mirrorIn.toRotation(((BlockLever.EnumOrientation)state.getValue(FACING)).getFacing()));
++ return state.withRotation(mirrorIn.toRotation(((EnumOrientation)state.getValue(FACING)).getFacing()));
+ }
+
+ protected BlockStateContainer createBlockState()
+@@ -320,7 +332,7 @@
+ UP_X(6, "up_x", EnumFacing.UP),
+ DOWN_Z(7, "down_z", EnumFacing.DOWN);
+
+- private static final BlockLever.EnumOrientation[] META_LOOKUP = new BlockLever.EnumOrientation[values().length];
++ private static final EnumOrientation[] META_LOOKUP = new EnumOrientation[values().length];
+ private final int meta;
+ private final String name;
+ private final EnumFacing facing;
+@@ -347,7 +359,7 @@
+ return this.name;
+ }
+
+- public static BlockLever.EnumOrientation byMetadata(int meta)
++ public static EnumOrientation byMetadata(int meta)
+ {
+ if (meta < 0 || meta >= META_LOOKUP.length)
+ {
+@@ -357,7 +369,7 @@
+ return META_LOOKUP[meta];
+ }
+
+- public static BlockLever.EnumOrientation forFacings(EnumFacing clickedSide, EnumFacing entityFacing)
++ public static EnumOrientation forFacings(EnumFacing clickedSide, EnumFacing entityFacing)
+ {
+ switch (clickedSide)
+ {
+@@ -405,7 +417,7 @@
+
+ static
+ {
+- for (BlockLever.EnumOrientation blocklever$enumorientation : values())
++ for (EnumOrientation blocklever$enumorientation : values())
+ {
+ META_LOOKUP[blocklever$enumorientation.getMetadata()] = blocklever$enumorientation;
+ }
diff --git a/patches/net/minecraft/block/BlockLilyPad.java.patch b/patches/net/minecraft/block/BlockLilyPad.java.patch
new file mode 100644
index 00000000..a69a237c
--- /dev/null
+++ b/patches/net/minecraft/block/BlockLilyPad.java.patch
@@ -0,0 +1,11 @@
+--- ../src-base/minecraft/net/minecraft/block/BlockLilyPad.java
++++ ../src-work/minecraft/net/minecraft/block/BlockLilyPad.java
+@@ -34,7 +34,7 @@
+ {
+ super.onEntityCollidedWithBlock(worldIn, pos, state, entityIn);
+
+- if (entityIn instanceof EntityBoat)
++ if (entityIn instanceof EntityBoat && !org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent(entityIn, pos, Blocks.AIR, 0).isCancelled())
+ {
+ worldIn.destroyBlock(new BlockPos(pos), true);
+ }
diff --git a/patches/net/minecraft/block/BlockLiquid.java.patch b/patches/net/minecraft/block/BlockLiquid.java.patch
new file mode 100644
index 00000000..51b1bfbc
--- /dev/null
+++ b/patches/net/minecraft/block/BlockLiquid.java.patch
@@ -0,0 +1,23 @@
+--- ../src-base/minecraft/net/minecraft/block/BlockLiquid.java
++++ ../src-work/minecraft/net/minecraft/block/BlockLiquid.java
+@@ -285,14 +285,18 @@
+ if (integer.intValue() == 0)
+ {
+ worldIn.setBlockState(pos, net.minecraftforge.event.ForgeEventFactory.fireFluidPlaceBlockEvent(worldIn, pos, pos, Blocks.OBSIDIAN.getDefaultState()));
+- this.triggerMixEffects(worldIn, pos);
++ if (org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockFormEvent(worldIn, pos, Blocks.OBSIDIAN.getDefaultState(), null)) {
++ this.triggerMixEffects(worldIn, pos);
++ }
+ return true;
+ }
+
+ if (integer.intValue() <= 4)
+ {
+ worldIn.setBlockState(pos, net.minecraftforge.event.ForgeEventFactory.fireFluidPlaceBlockEvent(worldIn, pos, pos, Blocks.COBBLESTONE.getDefaultState()));
+- this.triggerMixEffects(worldIn, pos);
++ if (org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockFormEvent(worldIn, pos, Blocks.COBBLESTONE.getDefaultState(), null)) {
++ this.triggerMixEffects(worldIn, pos);
++ }
+ return true;
+ }
+ }
diff --git a/patches/net/minecraft/block/BlockMagma.java.patch b/patches/net/minecraft/block/BlockMagma.java.patch
new file mode 100644
index 00000000..19cffe8d
--- /dev/null
+++ b/patches/net/minecraft/block/BlockMagma.java.patch
@@ -0,0 +1,12 @@
+--- ../src-base/minecraft/net/minecraft/block/BlockMagma.java
++++ ../src-work/minecraft/net/minecraft/block/BlockMagma.java
+@@ -40,7 +40,9 @@
+ {
+ if (!entityIn.isImmuneToFire() && entityIn instanceof EntityLivingBase && !EnchantmentHelper.hasFrostWalkerEnchantment((EntityLivingBase)entityIn))
+ {
++ org.bukkit.craftbukkit.event.CraftEventFactory.blockDamage = worldIn.getWorld().getBlockAt(pos.getX(), pos.getY(), pos.getZ());
+ entityIn.attackEntityFrom(DamageSource.HOT_FLOOR, 1.0F);
++ org.bukkit.craftbukkit.event.CraftEventFactory.blockDamage = null;
+ }
+
+ super.onEntityWalk(worldIn, pos, entityIn);
diff --git a/patches/net/minecraft/block/BlockMushroom.java.patch b/patches/net/minecraft/block/BlockMushroom.java.patch
new file mode 100644
index 00000000..b4e8c32d
--- /dev/null
+++ b/patches/net/minecraft/block/BlockMushroom.java.patch
@@ -0,0 +1,54 @@
+--- ../src-base/minecraft/net/minecraft/block/BlockMushroom.java
++++ ../src-work/minecraft/net/minecraft/block/BlockMushroom.java
+@@ -9,6 +9,9 @@
+ import net.minecraft.world.World;
+ import net.minecraft.world.gen.feature.WorldGenBigMushroom;
+ import net.minecraft.world.gen.feature.WorldGenerator;
++import org.bukkit.TreeType;
++import org.bukkit.block.BlockState;
++import org.bukkit.event.block.BlockSpreadEvent;
+
+ public class BlockMushroom extends BlockBush implements IGrowable
+ {
+@@ -26,7 +29,8 @@
+
+ public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
+ {
+- if (rand.nextInt(25) == 0)
++ final int sourceX = pos.getX(), sourceY = pos.getY(), sourceZ = pos.getZ();
++ if (rand.nextInt(Math.max(1, (int)(100.0f / worldIn.spigotConfig.mushroomModifier) * 25)) == 0) //Spigot
+ {
+ int i = 5;
+ int j = 4;
+@@ -58,7 +62,17 @@
+
+ if (worldIn.isAirBlock(blockpos1) && this.canBlockStay(worldIn, blockpos1, this.getDefaultState()))
+ {
+- worldIn.setBlockState(blockpos1, this.getDefaultState(), 2);
++// worldIn.setBlockState(blockpos1, this.getDefaultState(), 2);
++ org.bukkit.World bworld = worldIn.getWorld();
++ BlockState blockState = bworld.getBlockAt(blockpos1.getX(), blockpos1.getY(), blockpos1.getZ()).getState();
++ blockState.setType(org.bukkit.craftbukkit.util.CraftMagicNumbers.getMaterial(this)); // nms: this.id, 0, 2
++
++ BlockSpreadEvent event = new BlockSpreadEvent(blockState.getBlock(), bworld.getBlockAt(sourceX, sourceY, sourceZ), blockState);
++ worldIn.getServer().getPluginManager().callEvent(event);
++
++ if (!event.isCancelled()) {
++ blockState.update(true);
++ }
+ }
+ }
+ }
+@@ -105,10 +119,12 @@
+
+ if (this == Blocks.BROWN_MUSHROOM)
+ {
++ BlockSapling.treeType = TreeType.BROWN_MUSHROOM;
+ worldgenerator = new WorldGenBigMushroom(Blocks.BROWN_MUSHROOM_BLOCK);
+ }
+ else if (this == Blocks.RED_MUSHROOM)
+ {
++ BlockSapling.treeType = TreeType.RED_MUSHROOM;
+ worldgenerator = new WorldGenBigMushroom(Blocks.RED_MUSHROOM_BLOCK);
+ }
+
diff --git a/patches/net/minecraft/block/BlockMycelium.java.patch b/patches/net/minecraft/block/BlockMycelium.java.patch
new file mode 100644
index 00000000..a4dbc573
--- /dev/null
+++ b/patches/net/minecraft/block/BlockMycelium.java.patch
@@ -0,0 +1,51 @@
+--- ../src-base/minecraft/net/minecraft/block/BlockMycelium.java
++++ ../src-work/minecraft/net/minecraft/block/BlockMycelium.java
+@@ -16,6 +16,10 @@
+ import net.minecraft.world.World;
+ import net.minecraftforge.fml.relauncher.Side;
+ import net.minecraftforge.fml.relauncher.SideOnly;
++import org.bukkit.block.BlockState;
++import org.bukkit.craftbukkit.util.CraftMagicNumbers;
++import org.bukkit.event.block.BlockFadeEvent;
++import org.bukkit.event.block.BlockSpreadEvent;
+
+ public class BlockMycelium extends Block
+ {
+@@ -42,7 +46,17 @@
+ if (!worldIn.isAreaLoaded(pos, 2)) return; // Forge: prevent loading unloaded chunks when checking neighbor's light and spreading
+ if (worldIn.getLightFromNeighbors(pos.up()) < 4 && worldIn.getBlockState(pos.up()).getLightOpacity(worldIn, pos.up()) > 2)
+ {
+- worldIn.setBlockState(pos, Blocks.DIRT.getDefaultState().withProperty(BlockDirt.VARIANT, BlockDirt.DirtType.DIRT));
++// worldIn.setBlockState(pos, Blocks.DIRT.getDefaultState().withProperty(BlockDirt.VARIANT, BlockDirt.DirtType.DIRT));
++ org.bukkit.World bworld = worldIn.getWorld();
++ BlockState blockState = bworld.getBlockAt(pos.getX(), pos.getY(), pos.getZ()).getState();
++ blockState.setType(CraftMagicNumbers.getMaterial(Blocks.DIRT));
++
++ BlockFadeEvent event = new BlockFadeEvent(blockState.getBlock(), blockState);
++ worldIn.getServer().getPluginManager().callEvent(event);
++
++ if (!event.isCancelled()) {
++ blockState.update(true);
++ }
+ }
+ else
+ {
+@@ -56,7 +70,17 @@
+
+ if (iblockstate.getBlock() == Blocks.DIRT && iblockstate.getValue(BlockDirt.VARIANT) == BlockDirt.DirtType.DIRT && worldIn.getLightFromNeighbors(blockpos.up()) >= 4 && iblockstate1.getLightOpacity(worldIn, blockpos.up()) <= 2)
+ {
+- worldIn.setBlockState(blockpos, this.getDefaultState());
++// worldIn.setBlockState(blockpos, this.getDefaultState());
++ org.bukkit.World bworld = worldIn.getWorld();
++ BlockState blockState = bworld.getBlockAt(blockpos.getX(), blockpos.getY(), blockpos.getZ()).getState();
++ blockState.setType(CraftMagicNumbers.getMaterial(this));
++
++ BlockSpreadEvent event = new BlockSpreadEvent(blockState.getBlock(), bworld.getBlockAt(pos.getX(), pos.getY(), pos.getZ()), blockState);
++ worldIn.getServer().getPluginManager().callEvent(event);
++
++ if (!event.isCancelled()) {
++ blockState.update(true);
++ }
+ }
+ }
+ }
diff --git a/patches/net/minecraft/block/BlockNetherWart.java.patch b/patches/net/minecraft/block/BlockNetherWart.java.patch
new file mode 100644
index 00000000..2b41af38
--- /dev/null
+++ b/patches/net/minecraft/block/BlockNetherWart.java.patch
@@ -0,0 +1,16 @@
+--- ../src-base/minecraft/net/minecraft/block/BlockNetherWart.java
++++ ../src-work/minecraft/net/minecraft/block/BlockNetherWart.java
+@@ -49,10 +49,11 @@
+ {
+ int i = ((Integer)state.getValue(AGE)).intValue();
+
+- if (i < 3 && net.minecraftforge.common.ForgeHooks.onCropsGrowPre(worldIn, pos, state, rand.nextInt(10) == 0))
++ if (i < 3 && net.minecraftforge.common.ForgeHooks.onCropsGrowPre(worldIn, pos, state, rand.nextInt(Math.max(1, (int)(100.0f / worldIn.spigotConfig.wartModifier) * 10)) == 0)) // Spigot
+ {
+ IBlockState newState = state.withProperty(AGE, Integer.valueOf(i + 1));
+- worldIn.setBlockState(pos, newState, 2);
++// worldIn.setBlockState(pos, newState, 2);
++ org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockGrowEvent(worldIn, pos.getX(), pos.getY(), pos.getZ(), this, getMetaFromState(newState));
+ net.minecraftforge.common.ForgeHooks.onCropsGrowPost(worldIn, pos, state, newState);
+ }
+
diff --git a/patches/net/minecraft/block/BlockObserver.java.patch b/patches/net/minecraft/block/BlockObserver.java.patch
new file mode 100644
index 00000000..0c196a4b
--- /dev/null
+++ b/patches/net/minecraft/block/BlockObserver.java.patch
@@ -0,0 +1,31 @@
+--- ../src-base/minecraft/net/minecraft/block/BlockObserver.java
++++ ../src-work/minecraft/net/minecraft/block/BlockObserver.java
+@@ -14,6 +14,7 @@
+ import net.minecraft.util.math.BlockPos;
+ import net.minecraft.world.IBlockAccess;
+ import net.minecraft.world.World;
++import org.bukkit.craftbukkit.event.CraftEventFactory;
+
+ public class BlockObserver extends BlockDirectional
+ {
+@@ -45,10 +46,20 @@
+ {
+ if (((Boolean)state.getValue(POWERED)).booleanValue())
+ {
++ // Paper start
++ if (CraftEventFactory.callRedstoneChange(worldIn, pos.getX(), pos.getY(), pos.getZ(), 15, 0).getNewCurrent() != 0) {
++ return;
++ }
++ // Paper end
+ worldIn.setBlockState(pos, state.withProperty(POWERED, Boolean.valueOf(false)), 2);
+ }
+ else
+ {
++ // Paper start
++ if (CraftEventFactory.callRedstoneChange(worldIn, pos.getX(), pos.getY(), pos.getZ(), 0, 15).getNewCurrent() != 15) {
++ return;
++ }
++ // Paper end
+ worldIn.setBlockState(pos, state.withProperty(POWERED, Boolean.valueOf(true)), 2);
+ worldIn.scheduleUpdate(pos, this, 2);
+ }
diff --git a/patches/net/minecraft/block/BlockPistonBase.java.patch b/patches/net/minecraft/block/BlockPistonBase.java.patch
new file mode 100644
index 00000000..9e7b618c
--- /dev/null
+++ b/patches/net/minecraft/block/BlockPistonBase.java.patch
@@ -0,0 +1,96 @@
+--- ../src-base/minecraft/net/minecraft/block/BlockPistonBase.java
++++ ../src-work/minecraft/net/minecraft/block/BlockPistonBase.java
+@@ -1,6 +1,9 @@
+ package net.minecraft.block;
+
++import com.google.common.collect.ImmutableList;
+ import com.google.common.collect.Lists;
++
++import java.util.AbstractList;
+ import java.util.List;
+ import javax.annotation.Nullable;
+ import net.minecraft.block.material.EnumPushReaction;
+@@ -28,6 +31,9 @@
+ import net.minecraft.util.math.BlockPos;
+ import net.minecraft.world.IBlockAccess;
+ import net.minecraft.world.World;
++import org.bukkit.craftbukkit.block.CraftBlock;
++import org.bukkit.event.block.BlockPistonExtendEvent;
++import org.bukkit.event.block.BlockPistonRetractEvent;
+
+ public class BlockPistonBase extends BlockDirectional
+ {
+@@ -142,6 +148,15 @@
+ }
+ else if (!flag && ((Boolean)state.getValue(EXTENDED)).booleanValue())
+ {
++ if (!this.isSticky) {
++ org.bukkit.block.Block block = worldIn.getWorld().getBlockAt(pos.getX(), pos.getY(), pos.getZ());
++ BlockPistonRetractEvent event = new BlockPistonRetractEvent(block, ImmutableList.of(), CraftBlock.notchToBlockFace(enumfacing));
++ worldIn.getServer().getPluginManager().callEvent(event);
++
++ if (event.isCancelled()) {
++ return;
++ }
++ }
+ worldIn.addBlockEvent(pos, this, 1, enumfacing.getIndex());
+ }
+ }
+@@ -241,7 +256,8 @@
+ }
+ }
+
+- if (!flag1 && !iblockstate.getBlock().isAir(iblockstate, worldIn, blockpos) && canPush(iblockstate, worldIn, blockpos, enumfacing.getOpposite(), false, enumfacing) && (iblockstate.getMobilityFlag() == EnumPushReaction.NORMAL || block == Blocks.PISTON || block == Blocks.STICKY_PISTON))
++ // CraftBukkit - remove '!iblockstate.getBlock().isAir(iblockstate, worldIn, blockpos)' condition
++ if (!flag1 && canPush(iblockstate, worldIn, blockpos, enumfacing.getOpposite(), false, enumfacing) && (iblockstate.getMobilityFlag() == EnumPushReaction.NORMAL || block == Blocks.PISTON || block == Blocks.STICKY_PISTON))
+ {
+ this.doMove(worldIn, pos, enumfacing, false);
+ }
+@@ -349,6 +365,47 @@
+ IBlockState[] aiblockstate = new IBlockState[k];
+ EnumFacing enumfacing = extending ? direction : direction.getOpposite();
+
++ final org.bukkit.block.Block bblock = worldIn.getWorld().getBlockAt(pos.getX(), pos.getY(), pos.getZ());
++
++ final List moved = blockpistonstructurehelper.getBlocksToMove();
++ final List broken = blockpistonstructurehelper.getBlocksToDestroy();
++
++ List blocks = new AbstractList() {
++
++ @Override
++ public int size() {
++ return moved.size() + broken.size();
++ }
++
++ @Override
++ public org.bukkit.block.Block get(int index) {
++ if (index >= size() || index < 0) {
++ throw new ArrayIndexOutOfBoundsException(index);
++ }
++ BlockPos pos = index < moved.size() ? moved.get(index) : broken.get(index - moved.size());
++ return bblock.getWorld().getBlockAt(pos.getX(), pos.getY(), pos.getZ());
++ }
++ };
++ org.bukkit.event.block.BlockPistonEvent event;
++ if (extending) {
++ event = new BlockPistonExtendEvent(bblock, blocks, CraftBlock.notchToBlockFace(enumfacing));
++ } else {
++ event = new BlockPistonRetractEvent(bblock, blocks, CraftBlock.notchToBlockFace(enumfacing));
++ }
++ worldIn.getServer().getPluginManager().callEvent(event);
++
++ if (event.isCancelled()) {
++ for (BlockPos b : broken) {
++ worldIn.notifyBlockUpdate(b, Blocks.AIR.getDefaultState(), worldIn.getBlockState(b), 3);
++ }
++ for (BlockPos b : moved) {
++ worldIn.notifyBlockUpdate(b, Blocks.AIR.getDefaultState(), worldIn.getBlockState(b), 3);
++ b = b.offset(enumfacing);
++ worldIn.notifyBlockUpdate(b, Blocks.AIR.getDefaultState(), worldIn.getBlockState(b), 3);
++ }
++ return false;
++ }
++
+ for (int j = list2.size() - 1; j >= 0; --j)
+ {
+ BlockPos blockpos1 = list2.get(j);
diff --git a/patches/net/minecraft/block/BlockPortal.java.patch b/patches/net/minecraft/block/BlockPortal.java.patch
new file mode 100644
index 00000000..ee1b0a75
--- /dev/null
+++ b/patches/net/minecraft/block/BlockPortal.java.patch
@@ -0,0 +1,188 @@
+--- ../src-base/minecraft/net/minecraft/block/BlockPortal.java
++++ ../src-work/minecraft/net/minecraft/block/BlockPortal.java
+@@ -29,6 +29,8 @@
+ import net.minecraft.world.World;
+ import net.minecraftforge.fml.relauncher.Side;
+ import net.minecraftforge.fml.relauncher.SideOnly;
++import org.bukkit.event.entity.EntityPortalEnterEvent;
++import org.bukkit.event.world.PortalCreateEvent;
+
+ public class BlockPortal extends BlockBreakable
+ {
+@@ -62,7 +64,7 @@
+ {
+ super.updateTick(worldIn, pos, state, rand);
+
+- if (worldIn.provider.isSurfaceWorld() && worldIn.getGameRules().getBoolean("doMobSpawning") && rand.nextInt(2000) < worldIn.getDifficulty().getDifficultyId())
++ if (worldIn.spigotConfig.enableZombiePigmenPortalSpawns && worldIn.provider.isSurfaceWorld() && worldIn.getGameRules().getBoolean("doMobSpawning") && rand.nextInt(2000) < worldIn.getDifficulty().getDifficultyId()) // Spigot
+ {
+ int i = pos.getY();
+ BlockPos blockpos;
+@@ -74,7 +76,7 @@
+
+ if (i > 0 && !worldIn.getBlockState(blockpos.up()).isNormalCube())
+ {
+- Entity entity = ItemMonsterPlacer.spawnCreature(worldIn, EntityList.getKey(EntityPigZombie.class), (double)blockpos.getX() + 0.5D, (double)blockpos.getY() + 1.1D, (double)blockpos.getZ() + 0.5D);
++ Entity entity = ItemMonsterPlacer.spawnCreature(worldIn, EntityList.getKey(EntityPigZombie.class), (double)blockpos.getX() + 0.5D, (double)blockpos.getY() + 1.1D, (double)blockpos.getZ() + 0.5D, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.NETHER_PORTAL);
+
+ if (entity != null)
+ {
+@@ -109,21 +111,21 @@
+
+ public boolean trySpawnPortal(World worldIn, BlockPos pos)
+ {
+- BlockPortal.Size blockportal$size = new BlockPortal.Size(worldIn, pos, EnumFacing.Axis.X);
++ Size blockportal$size = new Size(worldIn, pos, EnumFacing.Axis.X);
+
+- if (blockportal$size.isValid() && blockportal$size.portalBlockCount == 0 && !net.minecraftforge.event.ForgeEventFactory.onTrySpawnPortal(worldIn, pos, blockportal$size))
++ if (blockportal$size.isValid() && blockportal$size.portalBlockCount == 0 && !net.minecraftforge.event.ForgeEventFactory.onTrySpawnPortal(worldIn,pos,blockportal$size))
+ {
+- blockportal$size.placePortalBlocks();
+- return true;
++ return blockportal$size.placePortalBlocksCB();
++// return true;
+ }
+ else
+ {
+- BlockPortal.Size blockportal$size1 = new BlockPortal.Size(worldIn, pos, EnumFacing.Axis.Z);
++ Size blockportal$size1 = new Size(worldIn, pos, EnumFacing.Axis.Z);
+
+- if (blockportal$size1.isValid() && blockportal$size1.portalBlockCount == 0 && !net.minecraftforge.event.ForgeEventFactory.onTrySpawnPortal(worldIn, pos, blockportal$size1))
++ if (blockportal$size1.isValid() && blockportal$size1.portalBlockCount == 0 && !net.minecraftforge.event.ForgeEventFactory.onTrySpawnPortal(worldIn,pos,blockportal$size1))
+ {
+- blockportal$size1.placePortalBlocks();
+- return true;
++ return blockportal$size1.placePortalBlocksCB();
++// return true;
+ }
+ else
+ {
+@@ -138,7 +140,7 @@
+
+ if (enumfacing$axis == EnumFacing.Axis.X)
+ {
+- BlockPortal.Size blockportal$size = new BlockPortal.Size(worldIn, pos, EnumFacing.Axis.X);
++ Size blockportal$size = new Size(worldIn, pos, EnumFacing.Axis.X);
+
+ if (!blockportal$size.isValid() || blockportal$size.portalBlockCount < blockportal$size.width * blockportal$size.height)
+ {
+@@ -147,7 +149,7 @@
+ }
+ else if (enumfacing$axis == EnumFacing.Axis.Z)
+ {
+- BlockPortal.Size blockportal$size1 = new BlockPortal.Size(worldIn, pos, EnumFacing.Axis.Z);
++ Size blockportal$size1 = new Size(worldIn, pos, EnumFacing.Axis.Z);
+
+ if (!blockportal$size1.isValid() || blockportal$size1.portalBlockCount < blockportal$size1.width * blockportal$size1.height)
+ {
+@@ -216,6 +218,8 @@
+ {
+ if (!entityIn.isRiding() && !entityIn.isBeingRidden() && entityIn.isNonBoss())
+ {
++ EntityPortalEnterEvent event = new EntityPortalEnterEvent(entityIn.getBukkitEntity(), new org.bukkit.Location(worldIn.getWorld(), pos.getX(), pos.getY(), pos.getZ()));
++ worldIn.getServer().getPluginManager().callEvent(event);
+ entityIn.setPortal(pos);
+ }
+ }
+@@ -304,13 +308,13 @@
+ public BlockPattern.PatternHelper createPatternHelper(World worldIn, BlockPos p_181089_2_)
+ {
+ EnumFacing.Axis enumfacing$axis = EnumFacing.Axis.Z;
+- BlockPortal.Size blockportal$size = new BlockPortal.Size(worldIn, p_181089_2_, EnumFacing.Axis.X);
++ Size blockportal$size = new Size(worldIn, p_181089_2_, EnumFacing.Axis.X);
+ LoadingCache loadingcache = BlockPattern.createLoadingCache(worldIn, true);
+
+ if (!blockportal$size.isValid())
+ {
+ enumfacing$axis = EnumFacing.Axis.X;
+- blockportal$size = new BlockPortal.Size(worldIn, p_181089_2_, EnumFacing.Axis.Z);
++ blockportal$size = new Size(worldIn, p_181089_2_, EnumFacing.Axis.Z);
+ }
+
+ if (!blockportal$size.isValid())
+@@ -370,6 +374,7 @@
+ private BlockPos bottomLeft;
+ private int height;
+ private int width;
++ java.util.Collection blocks = new java.util.HashSet();
+
+ public Size(World worldIn, BlockPos p_i45694_2_, EnumFacing.Axis p_i45694_3_)
+ {
+@@ -442,6 +447,8 @@
+
+ protected int calculatePortalHeight()
+ {
++ this.blocks.clear();
++ org.bukkit.World bworld = this.world.getWorld();
+ label56:
+
+ for (this.height = 0; this.height < 21; ++this.height)
+@@ -468,6 +475,9 @@
+ if (block != Blocks.OBSIDIAN)
+ {
+ break label56;
++ } else {
++ BlockPos pos = blockpos.offset(this.leftDir);
++ blocks.add(bworld.getBlockAt(pos.getX(), pos.getY(), pos.getZ()));
+ }
+ }
+ else if (i == this.width - 1)
+@@ -477,6 +487,9 @@
+ if (block != Blocks.OBSIDIAN)
+ {
+ break label56;
++ } else {
++ BlockPos pos = blockpos.offset(this.rightDir);
++ blocks.add(bworld.getBlockAt(pos.getX(), pos.getY(), pos.getZ()));
+ }
+ }
+ }
+@@ -488,6 +501,9 @@
+ {
+ this.height = 0;
+ break;
++ } else {
++ BlockPos pos = this.bottomLeft.offset(this.rightDir, j).up(this.height);
++ blocks.add(bworld.getBlockAt(pos.getX(), pos.getY(), pos.getZ()));
+ }
+ }
+
+@@ -526,5 +542,38 @@
+ }
+ }
+ }
++
++ public boolean placePortalBlocksCB()
++ {
++ org.bukkit.World bworld = this.world.getWorld();
++
++ // Copy below for loop
++ for (int i = 0; i < this.width; ++i) {
++ BlockPos blockposition = this.bottomLeft.offset(this.rightDir, i);
++
++ for (int j = 0; j < this.height; ++j) {
++ BlockPos pos = blockposition.up(j);
++ blocks.add(bworld.getBlockAt(pos.getX(), pos.getY(), pos.getZ()));
++ }
++ }
++
++ PortalCreateEvent event = new PortalCreateEvent(blocks, bworld, PortalCreateEvent.CreateReason.FIRE);
++ this.world.getServer().getPluginManager().callEvent(event);
++
++ if (event.isCancelled()) {
++ return false;
++ }
++ for (int i = 0; i < this.width; ++i)
++ {
++ BlockPos blockpos = this.bottomLeft.offset(this.rightDir, i);
++
++ for (int j = 0; j < this.height; ++j)
++ {
++ this.world.setBlockState(blockpos.up(j), Blocks.PORTAL.getDefaultState().withProperty(BlockPortal.AXIS, this.axis), 2);
++ }
++ }
++
++ return true;
++ }
+ }
+ }
diff --git a/patches/net/minecraft/block/BlockPressurePlate.java.patch b/patches/net/minecraft/block/BlockPressurePlate.java.patch
new file mode 100644
index 00000000..4da9c700
--- /dev/null
+++ b/patches/net/minecraft/block/BlockPressurePlate.java.patch
@@ -0,0 +1,44 @@
+--- ../src-base/minecraft/net/minecraft/block/BlockPressurePlate.java
++++ ../src-work/minecraft/net/minecraft/block/BlockPressurePlate.java
+@@ -14,13 +14,14 @@
+ import net.minecraft.util.math.AxisAlignedBB;
+ import net.minecraft.util.math.BlockPos;
+ import net.minecraft.world.World;
++import org.bukkit.event.entity.EntityInteractEvent;
+
+ public class BlockPressurePlate extends BlockBasePressurePlate
+ {
+ public static final PropertyBool POWERED = PropertyBool.create("powered");
+- private final BlockPressurePlate.Sensitivity sensitivity;
++ private final Sensitivity sensitivity;
+
+- protected BlockPressurePlate(Material materialIn, BlockPressurePlate.Sensitivity sensitivityIn)
++ protected BlockPressurePlate(Material materialIn, Sensitivity sensitivityIn)
+ {
+ super(materialIn);
+ this.setDefaultState(this.blockState.getBaseState().withProperty(POWERED, Boolean.valueOf(false)));
+@@ -82,6 +83,24 @@
+ {
+ for (Entity entity : list)
+ {
++ if (this.getRedstoneStrength(worldIn.getBlockState(pos)) == 0) {
++ org.bukkit.World bworld = worldIn.getWorld();
++ org.bukkit.plugin.PluginManager manager = worldIn.getServer().getPluginManager();
++ org.bukkit.event.Cancellable cancellable;
++
++ if (entity instanceof EntityPlayer) {
++ cancellable = org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerInteractEvent((EntityPlayer) entity, org.bukkit.event.block.Action.PHYSICAL, pos, null, null, null);
++ } else {
++ cancellable = new EntityInteractEvent(entity.getBukkitEntity(), bworld.getBlockAt(pos.getX(), pos.getY(), pos.getZ()));
++ manager.callEvent((EntityInteractEvent) cancellable);
++ }
++
++ // We only want to block turning the plate on if all events are cancelled
++ if (cancellable.isCancelled()) {
++ continue;
++ }
++ }
++
+ if (!entity.doesEntityNotTriggerPressurePlate())
+ {
+ return 15;
diff --git a/patches/net/minecraft/block/BlockPressurePlateWeighted.java.patch b/patches/net/minecraft/block/BlockPressurePlateWeighted.java.patch
new file mode 100644
index 00000000..33677720
--- /dev/null
+++ b/patches/net/minecraft/block/BlockPressurePlateWeighted.java.patch
@@ -0,0 +1,42 @@
+--- ../src-base/minecraft/net/minecraft/block/BlockPressurePlateWeighted.java
++++ ../src-work/minecraft/net/minecraft/block/BlockPressurePlateWeighted.java
+@@ -13,6 +13,7 @@
+ import net.minecraft.util.math.BlockPos;
+ import net.minecraft.util.math.MathHelper;
+ import net.minecraft.world.World;
++import org.bukkit.event.entity.EntityInteractEvent;
+
+ public class BlockPressurePlateWeighted extends BlockBasePressurePlate
+ {
+@@ -33,8 +34,30 @@
+
+ protected int computeRedstoneStrength(World worldIn, BlockPos pos)
+ {
+- int i = Math.min(worldIn.getEntitiesWithinAABB(Entity.class, PRESSURE_AABB.offset(pos)).size(), this.maxWeight);
++// int i = Math.min(worldIn.getEntitiesWithinAABB(Entity.class, PRESSURE_AABB.offset(pos)).size(), this.maxWeight);
++ int i = 0;
++ java.util.Iterator iterator = worldIn.getEntitiesWithinAABB(Entity.class, BlockPressurePlateWeighted.PRESSURE_AABB.offset(pos)).iterator();
+
++ while (iterator.hasNext()) {
++ Entity entity = (Entity) iterator.next();
++
++ org.bukkit.event.Cancellable cancellable;
++
++ if (entity instanceof EntityPlayer) {
++ cancellable = org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerInteractEvent((EntityPlayer) entity, org.bukkit.event.block.Action.PHYSICAL, pos, null, null, null);
++ } else {
++ cancellable = new EntityInteractEvent(entity.getBukkitEntity(), worldIn.getWorld().getBlockAt(pos.getX(), pos.getY(), pos.getZ()));
++ worldIn.getServer().getPluginManager().callEvent((EntityInteractEvent) cancellable);
++ }
++
++ // We only want to block turning the plate on if all events are cancelled
++ if (!cancellable.isCancelled()) {
++ i++;
++ }
++ }
++
++ i = Math.min(i, this.maxWeight);
++
+ if (i > 0)
+ {
+ float f = (float)Math.min(this.maxWeight, i) / (float)this.maxWeight;
diff --git a/patches/net/minecraft/block/BlockPumpkin.java.patch b/patches/net/minecraft/block/BlockPumpkin.java.patch
new file mode 100644
index 00000000..0b4c49c8
--- /dev/null
+++ b/patches/net/minecraft/block/BlockPumpkin.java.patch
@@ -0,0 +1,111 @@
+--- ../src-base/minecraft/net/minecraft/block/BlockPumpkin.java
++++ ../src-work/minecraft/net/minecraft/block/BlockPumpkin.java
+@@ -25,6 +25,8 @@
+ import net.minecraft.util.Rotation;
+ import net.minecraft.util.math.BlockPos;
+ import net.minecraft.world.World;
++import org.bukkit.craftbukkit.util.BlockStateListPopulator;
++import org.bukkit.event.entity.CreatureSpawnEvent;
+
+ public class BlockPumpkin extends BlockHorizontal
+ {
+@@ -62,34 +64,35 @@
+ private void trySpawnGolem(World worldIn, BlockPos pos)
+ {
+ BlockPattern.PatternHelper blockpattern$patternhelper = this.getSnowmanPattern().match(worldIn, pos);
+-
++ BlockStateListPopulator blockList = new BlockStateListPopulator(worldIn.getWorld());
+ if (blockpattern$patternhelper != null)
+ {
+ for (int i = 0; i < this.getSnowmanPattern().getThumbLength(); ++i)
+ {
+ BlockWorldState blockworldstate = blockpattern$patternhelper.translateOffset(0, i, 0);
+- worldIn.setBlockState(blockworldstate.getPos(), Blocks.AIR.getDefaultState(), 2);
++// worldIn.setBlockState(blockworldstate.getPos(), Blocks.AIR.getDefaultState(), 2);
++ BlockPos pos1 = blockworldstate.getPos();
++ blockList.setTypeId(pos1.getX(), pos1.getY(), pos1.getZ(), 0);
+ }
+
+ EntitySnowman entitysnowman = new EntitySnowman(worldIn);
+ BlockPos blockpos1 = blockpattern$patternhelper.translateOffset(0, 2, 0).getPos();
+ entitysnowman.setLocationAndAngles((double)blockpos1.getX() + 0.5D, (double)blockpos1.getY() + 0.05D, (double)blockpos1.getZ() + 0.5D, 0.0F, 0.0F);
+- worldIn.spawnEntity(entitysnowman);
++ if (worldIn.spawnEntity(entitysnowman, CreatureSpawnEvent.SpawnReason.BUILD_SNOWMAN)) {
++ blockList.updateList();
+
+- for (EntityPlayerMP entityplayermp : worldIn.getEntitiesWithinAABB(EntityPlayerMP.class, entitysnowman.getEntityBoundingBox().grow(5.0D)))
+- {
+- CriteriaTriggers.SUMMONED_ENTITY.trigger(entityplayermp, entitysnowman);
+- }
++ for (EntityPlayerMP entityplayermp : worldIn.getEntitiesWithinAABB(EntityPlayerMP.class, entitysnowman.getEntityBoundingBox().grow(5.0D))) {
++ CriteriaTriggers.SUMMONED_ENTITY.trigger(entityplayermp, entitysnowman);
++ }
+
+- for (int l = 0; l < 120; ++l)
+- {
+- worldIn.spawnParticle(EnumParticleTypes.SNOW_SHOVEL, (double)blockpos1.getX() + worldIn.rand.nextDouble(), (double)blockpos1.getY() + worldIn.rand.nextDouble() * 2.5D, (double)blockpos1.getZ() + worldIn.rand.nextDouble(), 0.0D, 0.0D, 0.0D);
+- }
++ for (int l = 0; l < 120; ++l) {
++ worldIn.spawnParticle(EnumParticleTypes.SNOW_SHOVEL, (double) blockpos1.getX() + worldIn.rand.nextDouble(), (double) blockpos1.getY() + worldIn.rand.nextDouble() * 2.5D, (double) blockpos1.getZ() + worldIn.rand.nextDouble(), 0.0D, 0.0D, 0.0D);
++ }
+
+- for (int i1 = 0; i1 < this.getSnowmanPattern().getThumbLength(); ++i1)
+- {
+- BlockWorldState blockworldstate2 = blockpattern$patternhelper.translateOffset(0, i1, 0);
+- worldIn.notifyNeighborsRespectDebug(blockworldstate2.getPos(), Blocks.AIR, false);
++ for (int i1 = 0; i1 < this.getSnowmanPattern().getThumbLength(); ++i1) {
++ BlockWorldState blockworldstate2 = blockpattern$patternhelper.translateOffset(0, i1, 0);
++ worldIn.notifyNeighborsRespectDebug(blockworldstate2.getPos(), Blocks.AIR, false);
++ }
+ }
+ }
+ else
+@@ -102,7 +105,9 @@
+ {
+ for (int k = 0; k < this.getGolemPattern().getThumbLength(); ++k)
+ {
+- worldIn.setBlockState(blockpattern$patternhelper.translateOffset(j, k, 0).getPos(), Blocks.AIR.getDefaultState(), 2);
++// worldIn.setBlockState(blockpattern$patternhelper.translateOffset(j, k, 0).getPos(), Blocks.AIR.getDefaultState(), 2);
++ BlockPos pos2 = blockpattern$patternhelper.translateOffset(j, k, 0).getPos();
++ blockList.setTypeId(pos2.getX(), pos2.getY(), pos2.getZ(), 0);
+ }
+ }
+
+@@ -110,24 +115,22 @@
+ EntityIronGolem entityirongolem = new EntityIronGolem(worldIn);
+ entityirongolem.setPlayerCreated(true);
+ entityirongolem.setLocationAndAngles((double)blockpos.getX() + 0.5D, (double)blockpos.getY() + 0.05D, (double)blockpos.getZ() + 0.5D, 0.0F, 0.0F);
+- worldIn.spawnEntity(entityirongolem);
++ if (worldIn.spawnEntity(entityirongolem, CreatureSpawnEvent.SpawnReason.BUILD_IRONGOLEM)) {
++ blockList.updateList();
+
+- for (EntityPlayerMP entityplayermp1 : worldIn.getEntitiesWithinAABB(EntityPlayerMP.class, entityirongolem.getEntityBoundingBox().grow(5.0D)))
+- {
+- CriteriaTriggers.SUMMONED_ENTITY.trigger(entityplayermp1, entityirongolem);
+- }
++ for (EntityPlayerMP entityplayermp1 : worldIn.getEntitiesWithinAABB(EntityPlayerMP.class, entityirongolem.getEntityBoundingBox().grow(5.0D))) {
++ CriteriaTriggers.SUMMONED_ENTITY.trigger(entityplayermp1, entityirongolem);
++ }
+
+- for (int j1 = 0; j1 < 120; ++j1)
+- {
+- worldIn.spawnParticle(EnumParticleTypes.SNOWBALL, (double)blockpos.getX() + worldIn.rand.nextDouble(), (double)blockpos.getY() + worldIn.rand.nextDouble() * 3.9D, (double)blockpos.getZ() + worldIn.rand.nextDouble(), 0.0D, 0.0D, 0.0D);
+- }
++ for (int j1 = 0; j1 < 120; ++j1) {
++ worldIn.spawnParticle(EnumParticleTypes.SNOWBALL, (double) blockpos.getX() + worldIn.rand.nextDouble(), (double) blockpos.getY() + worldIn.rand.nextDouble() * 3.9D, (double) blockpos.getZ() + worldIn.rand.nextDouble(), 0.0D, 0.0D, 0.0D);
++ }
+
+- for (int k1 = 0; k1 < this.getGolemPattern().getPalmLength(); ++k1)
+- {
+- for (int l1 = 0; l1 < this.getGolemPattern().getThumbLength(); ++l1)
+- {
+- BlockWorldState blockworldstate1 = blockpattern$patternhelper.translateOffset(k1, l1, 0);
+- worldIn.notifyNeighborsRespectDebug(blockworldstate1.getPos(), Blocks.AIR, false);
++ for (int k1 = 0; k1 < this.getGolemPattern().getPalmLength(); ++k1) {
++ for (int l1 = 0; l1 < this.getGolemPattern().getThumbLength(); ++l1) {
++ BlockWorldState blockworldstate1 = blockpattern$patternhelper.translateOffset(k1, l1, 0);
++ worldIn.notifyNeighborsRespectDebug(blockworldstate1.getPos(), Blocks.AIR, false);
++ }
+ }
+ }
+ }
diff --git a/patches/net/minecraft/block/BlockRailDetector.java.patch b/patches/net/minecraft/block/BlockRailDetector.java.patch
new file mode 100644
index 00000000..6f4786d2
--- /dev/null
+++ b/patches/net/minecraft/block/BlockRailDetector.java.patch
@@ -0,0 +1,250 @@
+--- ../src-base/minecraft/net/minecraft/block/BlockRailDetector.java
++++ ../src-work/minecraft/net/minecraft/block/BlockRailDetector.java
+@@ -22,14 +22,18 @@
+ import net.minecraft.util.math.BlockPos;
+ import net.minecraft.world.IBlockAccess;
+ import net.minecraft.world.World;
++import org.bukkit.event.block.BlockRedstoneEvent;
+
++import net.minecraft.block.BlockRailBase.EnumRailDirection;
++import net.minecraft.block.BlockRailBase.Rail;
++
+ public class BlockRailDetector extends BlockRailBase
+ {
+- public static final PropertyEnum SHAPE = PropertyEnum.create("shape", BlockRailBase.EnumRailDirection.class, new Predicate()
++ public static final PropertyEnum SHAPE = PropertyEnum.create("shape", EnumRailDirection.class, new Predicate()
+ {
+- public boolean apply(@Nullable BlockRailBase.EnumRailDirection p_apply_1_)
++ public boolean apply(@Nullable EnumRailDirection p_apply_1_)
+ {
+- return p_apply_1_ != BlockRailBase.EnumRailDirection.NORTH_EAST && p_apply_1_ != BlockRailBase.EnumRailDirection.NORTH_WEST && p_apply_1_ != BlockRailBase.EnumRailDirection.SOUTH_EAST && p_apply_1_ != BlockRailBase.EnumRailDirection.SOUTH_WEST;
++ return p_apply_1_ != EnumRailDirection.NORTH_EAST && p_apply_1_ != EnumRailDirection.NORTH_WEST && p_apply_1_ != EnumRailDirection.SOUTH_EAST && p_apply_1_ != EnumRailDirection.SOUTH_WEST;
+ }
+ });
+ public static final PropertyBool POWERED = PropertyBool.create("powered");
+@@ -37,7 +41,7 @@
+ public BlockRailDetector()
+ {
+ super(true);
+- this.setDefaultState(this.blockState.getBaseState().withProperty(POWERED, Boolean.valueOf(false)).withProperty(SHAPE, BlockRailBase.EnumRailDirection.NORTH_SOUTH));
++ this.setDefaultState(this.blockState.getBaseState().withProperty(POWERED, Boolean.valueOf(false)).withProperty(SHAPE, EnumRailDirection.NORTH_SOUTH));
+ this.setTickRandomly(true);
+ }
+
+@@ -102,6 +106,13 @@
+ flag1 = true;
+ }
+
++ if (flag != flag1) {
++ org.bukkit.block.Block block = worldIn.getWorld().getBlockAt(pos.getX(), pos.getY(), pos.getZ());
++ BlockRedstoneEvent eventRedstone = new BlockRedstoneEvent(block, flag ? 15 : 0, flag1 ? 15 : 0);
++ worldIn.getServer().getPluginManager().callEvent(eventRedstone);
++ flag1 = eventRedstone.getNewCurrent() > 0;
++ }
++
+ if (flag1 && !flag)
+ {
+ worldIn.setBlockState(pos, state.withProperty(POWERED, Boolean.valueOf(true)), 3);
+@@ -130,7 +141,7 @@
+
+ protected void updateConnectedRails(World worldIn, BlockPos pos, IBlockState state, boolean powered)
+ {
+- BlockRailBase.Rail blockrailbase$rail = new BlockRailBase.Rail(worldIn, pos, state);
++ Rail blockrailbase$rail = new Rail(worldIn, pos, state);
+
+ for (BlockPos blockpos : blockrailbase$rail.getConnectedRails())
+ {
+@@ -149,7 +160,7 @@
+ this.updatePoweredState(worldIn, pos, state);
+ }
+
+- public IProperty getShapeProperty()
++ public IProperty getShapeProperty()
+ {
+ return SHAPE;
+ }
+@@ -197,13 +208,13 @@
+
+ public IBlockState getStateFromMeta(int meta)
+ {
+- return this.getDefaultState().withProperty(SHAPE, BlockRailBase.EnumRailDirection.byMetadata(meta & 7)).withProperty(POWERED, Boolean.valueOf((meta & 8) > 0));
++ return this.getDefaultState().withProperty(SHAPE, EnumRailDirection.byMetadata(meta & 7)).withProperty(POWERED, Boolean.valueOf((meta & 8) > 0));
+ }
+
+ public int getMetaFromState(IBlockState state)
+ {
+ int i = 0;
+- i = i | ((BlockRailBase.EnumRailDirection)state.getValue(SHAPE)).getMetadata();
++ i = i | ((EnumRailDirection)state.getValue(SHAPE)).getMetadata();
+
+ if (((Boolean)state.getValue(POWERED)).booleanValue())
+ {
+@@ -220,76 +231,76 @@
+ {
+ case CLOCKWISE_180:
+
+- switch ((BlockRailBase.EnumRailDirection)state.getValue(SHAPE))
++ switch ((EnumRailDirection)state.getValue(SHAPE))
+ {
+ case ASCENDING_EAST:
+- return state.withProperty(SHAPE, BlockRailBase.EnumRailDirection.ASCENDING_WEST);
++ return state.withProperty(SHAPE, EnumRailDirection.ASCENDING_WEST);
+ case ASCENDING_WEST:
+- return state.withProperty(SHAPE, BlockRailBase.EnumRailDirection.ASCENDING_EAST);
++ return state.withProperty(SHAPE, EnumRailDirection.ASCENDING_EAST);
+ case ASCENDING_NORTH:
+- return state.withProperty(SHAPE, BlockRailBase.EnumRailDirection.ASCENDING_SOUTH);
++ return state.withProperty(SHAPE, EnumRailDirection.ASCENDING_SOUTH);
+ case ASCENDING_SOUTH:
+- return state.withProperty(SHAPE, BlockRailBase.EnumRailDirection.ASCENDING_NORTH);
++ return state.withProperty(SHAPE, EnumRailDirection.ASCENDING_NORTH);
+ case SOUTH_EAST:
+- return state.withProperty(SHAPE, BlockRailBase.EnumRailDirection.NORTH_WEST);
++ return state.withProperty(SHAPE, EnumRailDirection.NORTH_WEST);
+ case SOUTH_WEST:
+- return state.withProperty(SHAPE, BlockRailBase.EnumRailDirection.NORTH_EAST);
++ return state.withProperty(SHAPE, EnumRailDirection.NORTH_EAST);
+ case NORTH_WEST:
+- return state.withProperty(SHAPE, BlockRailBase.EnumRailDirection.SOUTH_EAST);
++ return state.withProperty(SHAPE, EnumRailDirection.SOUTH_EAST);
+ case NORTH_EAST:
+- return state.withProperty(SHAPE, BlockRailBase.EnumRailDirection.SOUTH_WEST);
++ return state.withProperty(SHAPE, EnumRailDirection.SOUTH_WEST);
+ }
+
+ case COUNTERCLOCKWISE_90:
+
+- switch ((BlockRailBase.EnumRailDirection)state.getValue(SHAPE))
++ switch ((EnumRailDirection)state.getValue(SHAPE))
+ {
+ case ASCENDING_EAST:
+- return state.withProperty(SHAPE, BlockRailBase.EnumRailDirection.ASCENDING_NORTH);
++ return state.withProperty(SHAPE, EnumRailDirection.ASCENDING_NORTH);
+ case ASCENDING_WEST:
+- return state.withProperty(SHAPE, BlockRailBase.EnumRailDirection.ASCENDING_SOUTH);
++ return state.withProperty(SHAPE, EnumRailDirection.ASCENDING_SOUTH);
+ case ASCENDING_NORTH:
+- return state.withProperty(SHAPE, BlockRailBase.EnumRailDirection.ASCENDING_WEST);
++ return state.withProperty(SHAPE, EnumRailDirection.ASCENDING_WEST);
+ case ASCENDING_SOUTH:
+- return state.withProperty(SHAPE, BlockRailBase.EnumRailDirection.ASCENDING_EAST);
++ return state.withProperty(SHAPE, EnumRailDirection.ASCENDING_EAST);
+ case SOUTH_EAST:
+- return state.withProperty(SHAPE, BlockRailBase.EnumRailDirection.NORTH_EAST);
++ return state.withProperty(SHAPE, EnumRailDirection.NORTH_EAST);
+ case SOUTH_WEST:
+- return state.withProperty(SHAPE, BlockRailBase.EnumRailDirection.SOUTH_EAST);
++ return state.withProperty(SHAPE, EnumRailDirection.SOUTH_EAST);
+ case NORTH_WEST:
+- return state.withProperty(SHAPE, BlockRailBase.EnumRailDirection.SOUTH_WEST);
++ return state.withProperty(SHAPE, EnumRailDirection.SOUTH_WEST);
+ case NORTH_EAST:
+- return state.withProperty(SHAPE, BlockRailBase.EnumRailDirection.NORTH_WEST);
++ return state.withProperty(SHAPE, EnumRailDirection.NORTH_WEST);
+ case NORTH_SOUTH:
+- return state.withProperty(SHAPE, BlockRailBase.EnumRailDirection.EAST_WEST);
++ return state.withProperty(SHAPE, EnumRailDirection.EAST_WEST);
+ case EAST_WEST:
+- return state.withProperty(SHAPE, BlockRailBase.EnumRailDirection.NORTH_SOUTH);
++ return state.withProperty(SHAPE, EnumRailDirection.NORTH_SOUTH);
+ }
+
+ case CLOCKWISE_90:
+
+- switch ((BlockRailBase.EnumRailDirection)state.getValue(SHAPE))
++ switch ((EnumRailDirection)state.getValue(SHAPE))
+ {
+ case ASCENDING_EAST:
+- return state.withProperty(SHAPE, BlockRailBase.EnumRailDirection.ASCENDING_SOUTH);
++ return state.withProperty(SHAPE, EnumRailDirection.ASCENDING_SOUTH);
+ case ASCENDING_WEST:
+- return state.withProperty(SHAPE, BlockRailBase.EnumRailDirection.ASCENDING_NORTH);
++ return state.withProperty(SHAPE, EnumRailDirection.ASCENDING_NORTH);
+ case ASCENDING_NORTH:
+- return state.withProperty(SHAPE, BlockRailBase.EnumRailDirection.ASCENDING_EAST);
++ return state.withProperty(SHAPE, EnumRailDirection.ASCENDING_EAST);
+ case ASCENDING_SOUTH:
+- return state.withProperty(SHAPE, BlockRailBase.EnumRailDirection.ASCENDING_WEST);
++ return state.withProperty(SHAPE, EnumRailDirection.ASCENDING_WEST);
+ case SOUTH_EAST:
+- return state.withProperty(SHAPE, BlockRailBase.EnumRailDirection.SOUTH_WEST);
++ return state.withProperty(SHAPE, EnumRailDirection.SOUTH_WEST);
+ case SOUTH_WEST:
+- return state.withProperty(SHAPE, BlockRailBase.EnumRailDirection.NORTH_WEST);
++ return state.withProperty(SHAPE, EnumRailDirection.NORTH_WEST);
+ case NORTH_WEST:
+- return state.withProperty(SHAPE, BlockRailBase.EnumRailDirection.NORTH_EAST);
++ return state.withProperty(SHAPE, EnumRailDirection.NORTH_EAST);
+ case NORTH_EAST:
+- return state.withProperty(SHAPE, BlockRailBase.EnumRailDirection.SOUTH_EAST);
++ return state.withProperty(SHAPE, EnumRailDirection.SOUTH_EAST);
+ case NORTH_SOUTH:
+- return state.withProperty(SHAPE, BlockRailBase.EnumRailDirection.EAST_WEST);
++ return state.withProperty(SHAPE, EnumRailDirection.EAST_WEST);
+ case EAST_WEST:
+- return state.withProperty(SHAPE, BlockRailBase.EnumRailDirection.NORTH_SOUTH);
++ return state.withProperty(SHAPE, EnumRailDirection.NORTH_SOUTH);
+ }
+
+ default:
+@@ -300,7 +311,7 @@
+ @SuppressWarnings("incomplete-switch")
+ public IBlockState withMirror(IBlockState state, Mirror mirrorIn)
+ {
+- BlockRailBase.EnumRailDirection blockrailbase$enumraildirection = (BlockRailBase.EnumRailDirection)state.getValue(SHAPE);
++ EnumRailDirection blockrailbase$enumraildirection = (EnumRailDirection)state.getValue(SHAPE);
+
+ switch (mirrorIn)
+ {
+@@ -309,17 +320,17 @@
+ switch (blockrailbase$enumraildirection)
+ {
+ case ASCENDING_NORTH:
+- return state.withProperty(SHAPE, BlockRailBase.EnumRailDirection.ASCENDING_SOUTH);
++ return state.withProperty(SHAPE, EnumRailDirection.ASCENDING_SOUTH);
+ case ASCENDING_SOUTH:
+- return state.withProperty(SHAPE, BlockRailBase.EnumRailDirection.ASCENDING_NORTH);
++ return state.withProperty(SHAPE, EnumRailDirection.ASCENDING_NORTH);
+ case SOUTH_EAST:
+- return state.withProperty(SHAPE, BlockRailBase.EnumRailDirection.NORTH_EAST);
++ return state.withProperty(SHAPE, EnumRailDirection.NORTH_EAST);
+ case SOUTH_WEST:
+- return state.withProperty(SHAPE, BlockRailBase.EnumRailDirection.NORTH_WEST);
++ return state.withProperty(SHAPE, EnumRailDirection.NORTH_WEST);
+ case NORTH_WEST:
+- return state.withProperty(SHAPE, BlockRailBase.EnumRailDirection.SOUTH_WEST);
++ return state.withProperty(SHAPE, EnumRailDirection.SOUTH_WEST);
+ case NORTH_EAST:
+- return state.withProperty(SHAPE, BlockRailBase.EnumRailDirection.SOUTH_EAST);
++ return state.withProperty(SHAPE, EnumRailDirection.SOUTH_EAST);
+ default:
+ return super.withMirror(state, mirrorIn);
+ }
+@@ -329,21 +340,21 @@
+ switch (blockrailbase$enumraildirection)
+ {
+ case ASCENDING_EAST:
+- return state.withProperty(SHAPE, BlockRailBase.EnumRailDirection.ASCENDING_WEST);
++ return state.withProperty(SHAPE, EnumRailDirection.ASCENDING_WEST);
+ case ASCENDING_WEST:
+- return state.withProperty(SHAPE, BlockRailBase.EnumRailDirection.ASCENDING_EAST);
++ return state.withProperty(SHAPE, EnumRailDirection.ASCENDING_EAST);
+ case ASCENDING_NORTH:
+ case ASCENDING_SOUTH:
+ default:
+ break;
+ case SOUTH_EAST:
+- return state.withProperty(SHAPE, BlockRailBase.EnumRailDirection.SOUTH_WEST);
++ return state.withProperty(SHAPE, EnumRailDirection.SOUTH_WEST);
+ case SOUTH_WEST:
+- return state.withProperty(SHAPE, BlockRailBase.EnumRailDirection.SOUTH_EAST);
++ return state.withProperty(SHAPE, EnumRailDirection.SOUTH_EAST);
+ case NORTH_WEST:
+- return state.withProperty(SHAPE, BlockRailBase.EnumRailDirection.NORTH_EAST);
++ return state.withProperty(SHAPE, EnumRailDirection.NORTH_EAST);
+ case NORTH_EAST:
+- return state.withProperty(SHAPE, BlockRailBase.EnumRailDirection.NORTH_WEST);
++ return state.withProperty(SHAPE, EnumRailDirection.NORTH_WEST);
+ }
+ }
+
diff --git a/patches/net/minecraft/block/BlockRailPowered.java.patch b/patches/net/minecraft/block/BlockRailPowered.java.patch
new file mode 100644
index 00000000..23179db4
--- /dev/null
+++ b/patches/net/minecraft/block/BlockRailPowered.java.patch
@@ -0,0 +1,310 @@
+--- ../src-base/minecraft/net/minecraft/block/BlockRailPowered.java
++++ ../src-work/minecraft/net/minecraft/block/BlockRailPowered.java
+@@ -11,14 +11,17 @@
+ import net.minecraft.util.Rotation;
+ import net.minecraft.util.math.BlockPos;
+ import net.minecraft.world.World;
++import org.bukkit.craftbukkit.event.CraftEventFactory;
+
++import net.minecraft.block.BlockRailBase.EnumRailDirection;
++
+ public class BlockRailPowered extends BlockRailBase
+ {
+- public static final PropertyEnum SHAPE = PropertyEnum.create("shape", BlockRailBase.EnumRailDirection.class, new Predicate()
++ public static final PropertyEnum SHAPE = PropertyEnum.create("shape", EnumRailDirection.class, new Predicate()
+ {
+- public boolean apply(@Nullable BlockRailBase.EnumRailDirection p_apply_1_)
++ public boolean apply(@Nullable EnumRailDirection p_apply_1_)
+ {
+- return p_apply_1_ != BlockRailBase.EnumRailDirection.NORTH_EAST && p_apply_1_ != BlockRailBase.EnumRailDirection.NORTH_WEST && p_apply_1_ != BlockRailBase.EnumRailDirection.SOUTH_EAST && p_apply_1_ != BlockRailBase.EnumRailDirection.SOUTH_WEST;
++ return p_apply_1_ != EnumRailDirection.NORTH_EAST && p_apply_1_ != EnumRailDirection.NORTH_WEST && p_apply_1_ != EnumRailDirection.SOUTH_EAST && p_apply_1_ != EnumRailDirection.SOUTH_WEST;
+ }
+ });
+ public static final PropertyBool POWERED = PropertyBool.create("powered");
+@@ -34,7 +37,7 @@
+ {
+ super(true);
+ this.isActivator = isActivator;
+- this.setDefaultState(this.blockState.getBaseState().withProperty(SHAPE, BlockRailBase.EnumRailDirection.NORTH_SOUTH).withProperty(POWERED, Boolean.valueOf(false)));
++ this.setDefaultState(this.blockState.getBaseState().withProperty(SHAPE, EnumRailDirection.NORTH_SOUTH).withProperty(POWERED, Boolean.valueOf(false)));
+ }
+
+ @SuppressWarnings("incomplete-switch")
+@@ -50,7 +53,7 @@
+ int j = pos.getY();
+ int k = pos.getZ();
+ boolean flag = true;
+- BlockRailBase.EnumRailDirection blockrailbase$enumraildirection = (BlockRailBase.EnumRailDirection)state.getValue(SHAPE);
++ EnumRailDirection blockrailbase$enumraildirection = (EnumRailDirection)state.getValue(SHAPE);
+
+ switch (blockrailbase$enumraildirection)
+ {
+@@ -91,7 +94,7 @@
+ flag = false;
+ }
+
+- blockrailbase$enumraildirection = BlockRailBase.EnumRailDirection.EAST_WEST;
++ blockrailbase$enumraildirection = EnumRailDirection.EAST_WEST;
+ break;
+ case ASCENDING_WEST:
+
+@@ -106,7 +109,7 @@
+ ++i;
+ }
+
+- blockrailbase$enumraildirection = BlockRailBase.EnumRailDirection.EAST_WEST;
++ blockrailbase$enumraildirection = EnumRailDirection.EAST_WEST;
+ break;
+ case ASCENDING_NORTH:
+
+@@ -121,7 +124,7 @@
+ flag = false;
+ }
+
+- blockrailbase$enumraildirection = BlockRailBase.EnumRailDirection.NORTH_SOUTH;
++ blockrailbase$enumraildirection = EnumRailDirection.NORTH_SOUTH;
+ break;
+ case ASCENDING_SOUTH:
+
+@@ -136,7 +139,7 @@
+ --k;
+ }
+
+- blockrailbase$enumraildirection = BlockRailBase.EnumRailDirection.NORTH_SOUTH;
++ blockrailbase$enumraildirection = EnumRailDirection.NORTH_SOUTH;
+ }
+
+ if (this.isSameRailWithPower(worldIn, new BlockPos(i, j, k), p_176566_4_, p_176566_5_, blockrailbase$enumraildirection))
+@@ -150,7 +153,7 @@
+ }
+ }
+
+- protected boolean isSameRailWithPower(World worldIn, BlockPos pos, boolean p_176567_3_, int distance, BlockRailBase.EnumRailDirection p_176567_5_)
++ protected boolean isSameRailWithPower(World worldIn, BlockPos pos, boolean p_176567_3_, int distance, EnumRailDirection p_176567_5_)
+ {
+ IBlockState iblockstate = worldIn.getBlockState(pos);
+
+@@ -160,11 +163,11 @@
+ }
+ else
+ {
+- BlockRailBase.EnumRailDirection blockrailbase$enumraildirection = (BlockRailBase.EnumRailDirection)iblockstate.getValue(SHAPE);
++ EnumRailDirection blockrailbase$enumraildirection = (EnumRailDirection)iblockstate.getValue(SHAPE);
+
+- if (p_176567_5_ != BlockRailBase.EnumRailDirection.EAST_WEST || blockrailbase$enumraildirection != BlockRailBase.EnumRailDirection.NORTH_SOUTH && blockrailbase$enumraildirection != BlockRailBase.EnumRailDirection.ASCENDING_NORTH && blockrailbase$enumraildirection != BlockRailBase.EnumRailDirection.ASCENDING_SOUTH)
++ if (p_176567_5_ != EnumRailDirection.EAST_WEST || blockrailbase$enumraildirection != EnumRailDirection.NORTH_SOUTH && blockrailbase$enumraildirection != EnumRailDirection.ASCENDING_NORTH && blockrailbase$enumraildirection != EnumRailDirection.ASCENDING_SOUTH)
+ {
+- if (p_176567_5_ != BlockRailBase.EnumRailDirection.NORTH_SOUTH || blockrailbase$enumraildirection != BlockRailBase.EnumRailDirection.EAST_WEST && blockrailbase$enumraildirection != BlockRailBase.EnumRailDirection.ASCENDING_EAST && blockrailbase$enumraildirection != BlockRailBase.EnumRailDirection.ASCENDING_WEST)
++ if (p_176567_5_ != EnumRailDirection.NORTH_SOUTH || blockrailbase$enumraildirection != EnumRailDirection.EAST_WEST && blockrailbase$enumraildirection != EnumRailDirection.ASCENDING_EAST && blockrailbase$enumraildirection != EnumRailDirection.ASCENDING_WEST)
+ {
+ if (((Boolean)iblockstate.getValue(POWERED)).booleanValue())
+ {
+@@ -194,30 +197,35 @@
+
+ if (flag1 != flag)
+ {
++ int power = state.getValue(POWERED) ? 15 : 0;
++ int newPower = CraftEventFactory.callRedstoneChange(worldIn, pos.getX(), pos.getY(), pos.getZ(), power, 15 - power).getNewCurrent();
++ if (newPower == power) {
++ return;
++ }
+ worldIn.setBlockState(pos, state.withProperty(POWERED, Boolean.valueOf(flag1)), 3);
+ worldIn.notifyNeighborsOfStateChange(pos.down(), this, false);
+
+- if (((BlockRailBase.EnumRailDirection)state.getValue(SHAPE)).isAscending())
++ if (((EnumRailDirection)state.getValue(SHAPE)).isAscending())
+ {
+ worldIn.notifyNeighborsOfStateChange(pos.up(), this, false);
+ }
+ }
+ }
+
+- public IProperty getShapeProperty()
++ public IProperty getShapeProperty()
+ {
+ return SHAPE;
+ }
+
+ public IBlockState getStateFromMeta(int meta)
+ {
+- return this.getDefaultState().withProperty(SHAPE, BlockRailBase.EnumRailDirection.byMetadata(meta & 7)).withProperty(POWERED, Boolean.valueOf((meta & 8) > 0));
++ return this.getDefaultState().withProperty(SHAPE, EnumRailDirection.byMetadata(meta & 7)).withProperty(POWERED, Boolean.valueOf((meta & 8) > 0));
+ }
+
+ public int getMetaFromState(IBlockState state)
+ {
+ int i = 0;
+- i = i | ((BlockRailBase.EnumRailDirection)state.getValue(SHAPE)).getMetadata();
++ i = i | ((EnumRailDirection)state.getValue(SHAPE)).getMetadata();
+
+ if (((Boolean)state.getValue(POWERED)).booleanValue())
+ {
+@@ -234,76 +242,76 @@
+ {
+ case CLOCKWISE_180:
+
+- switch ((BlockRailBase.EnumRailDirection)state.getValue(SHAPE))
++ switch ((EnumRailDirection)state.getValue(SHAPE))
+ {
+ case ASCENDING_EAST:
+- return state.withProperty(SHAPE, BlockRailBase.EnumRailDirection.ASCENDING_WEST);
++ return state.withProperty(SHAPE, EnumRailDirection.ASCENDING_WEST);
+ case ASCENDING_WEST:
+- return state.withProperty(SHAPE, BlockRailBase.EnumRailDirection.ASCENDING_EAST);
++ return state.withProperty(SHAPE, EnumRailDirection.ASCENDING_EAST);
+ case ASCENDING_NORTH:
+- return state.withProperty(SHAPE, BlockRailBase.EnumRailDirection.ASCENDING_SOUTH);
++ return state.withProperty(SHAPE, EnumRailDirection.ASCENDING_SOUTH);
+ case ASCENDING_SOUTH:
+- return state.withProperty(SHAPE, BlockRailBase.EnumRailDirection.ASCENDING_NORTH);
++ return state.withProperty(SHAPE, EnumRailDirection.ASCENDING_NORTH);
+ case SOUTH_EAST:
+- return state.withProperty(SHAPE, BlockRailBase.EnumRailDirection.NORTH_WEST);
++ return state.withProperty(SHAPE, EnumRailDirection.NORTH_WEST);
+ case SOUTH_WEST:
+- return state.withProperty(SHAPE, BlockRailBase.EnumRailDirection.NORTH_EAST);
++ return state.withProperty(SHAPE, EnumRailDirection.NORTH_EAST);
+ case NORTH_WEST:
+- return state.withProperty(SHAPE, BlockRailBase.EnumRailDirection.SOUTH_EAST);
++ return state.withProperty(SHAPE, EnumRailDirection.SOUTH_EAST);
+ case NORTH_EAST:
+- return state.withProperty(SHAPE, BlockRailBase.EnumRailDirection.SOUTH_WEST);
++ return state.withProperty(SHAPE, EnumRailDirection.SOUTH_WEST);
+ }
+
+ case COUNTERCLOCKWISE_90:
+
+- switch ((BlockRailBase.EnumRailDirection)state.getValue(SHAPE))
++ switch ((EnumRailDirection)state.getValue(SHAPE))
+ {
+ case NORTH_SOUTH:
+- return state.withProperty(SHAPE, BlockRailBase.EnumRailDirection.EAST_WEST);
++ return state.withProperty(SHAPE, EnumRailDirection.EAST_WEST);
+ case EAST_WEST:
+- return state.withProperty(SHAPE, BlockRailBase.EnumRailDirection.NORTH_SOUTH);
++ return state.withProperty(SHAPE, EnumRailDirection.NORTH_SOUTH);
+ case ASCENDING_EAST:
+- return state.withProperty(SHAPE, BlockRailBase.EnumRailDirection.ASCENDING_NORTH);
++ return state.withProperty(SHAPE, EnumRailDirection.ASCENDING_NORTH);
+ case ASCENDING_WEST:
+- return state.withProperty(SHAPE, BlockRailBase.EnumRailDirection.ASCENDING_SOUTH);
++ return state.withProperty(SHAPE, EnumRailDirection.ASCENDING_SOUTH);
+ case ASCENDING_NORTH:
+- return state.withProperty(SHAPE, BlockRailBase.EnumRailDirection.ASCENDING_WEST);
++ return state.withProperty(SHAPE, EnumRailDirection.ASCENDING_WEST);
+ case ASCENDING_SOUTH:
+- return state.withProperty(SHAPE, BlockRailBase.EnumRailDirection.ASCENDING_EAST);
++ return state.withProperty(SHAPE, EnumRailDirection.ASCENDING_EAST);
+ case SOUTH_EAST:
+- return state.withProperty(SHAPE, BlockRailBase.EnumRailDirection.NORTH_EAST);
++ return state.withProperty(SHAPE, EnumRailDirection.NORTH_EAST);
+ case SOUTH_WEST:
+- return state.withProperty(SHAPE, BlockRailBase.EnumRailDirection.SOUTH_EAST);
++ return state.withProperty(SHAPE, EnumRailDirection.SOUTH_EAST);
+ case NORTH_WEST:
+- return state.withProperty(SHAPE, BlockRailBase.EnumRailDirection.SOUTH_WEST);
++ return state.withProperty(SHAPE, EnumRailDirection.SOUTH_WEST);
+ case NORTH_EAST:
+- return state.withProperty(SHAPE, BlockRailBase.EnumRailDirection.NORTH_WEST);
++ return state.withProperty(SHAPE, EnumRailDirection.NORTH_WEST);
+ }
+
+ case CLOCKWISE_90:
+
+- switch ((BlockRailBase.EnumRailDirection)state.getValue(SHAPE))
++ switch ((EnumRailDirection)state.getValue(SHAPE))
+ {
+ case NORTH_SOUTH:
+- return state.withProperty(SHAPE, BlockRailBase.EnumRailDirection.EAST_WEST);
++ return state.withProperty(SHAPE, EnumRailDirection.EAST_WEST);
+ case EAST_WEST:
+- return state.withProperty(SHAPE, BlockRailBase.EnumRailDirection.NORTH_SOUTH);
++ return state.withProperty(SHAPE, EnumRailDirection.NORTH_SOUTH);
+ case ASCENDING_EAST:
+- return state.withProperty(SHAPE, BlockRailBase.EnumRailDirection.ASCENDING_SOUTH);
++ return state.withProperty(SHAPE, EnumRailDirection.ASCENDING_SOUTH);
+ case ASCENDING_WEST:
+- return state.withProperty(SHAPE, BlockRailBase.EnumRailDirection.ASCENDING_NORTH);
++ return state.withProperty(SHAPE, EnumRailDirection.ASCENDING_NORTH);
+ case ASCENDING_NORTH:
+- return state.withProperty(SHAPE, BlockRailBase.EnumRailDirection.ASCENDING_EAST);
++ return state.withProperty(SHAPE, EnumRailDirection.ASCENDING_EAST);
+ case ASCENDING_SOUTH:
+- return state.withProperty(SHAPE, BlockRailBase.EnumRailDirection.ASCENDING_WEST);
++ return state.withProperty(SHAPE, EnumRailDirection.ASCENDING_WEST);
+ case SOUTH_EAST:
+- return state.withProperty(SHAPE, BlockRailBase.EnumRailDirection.SOUTH_WEST);
++ return state.withProperty(SHAPE, EnumRailDirection.SOUTH_WEST);
+ case SOUTH_WEST:
+- return state.withProperty(SHAPE, BlockRailBase.EnumRailDirection.NORTH_WEST);
++ return state.withProperty(SHAPE, EnumRailDirection.NORTH_WEST);
+ case NORTH_WEST:
+- return state.withProperty(SHAPE, BlockRailBase.EnumRailDirection.NORTH_EAST);
++ return state.withProperty(SHAPE, EnumRailDirection.NORTH_EAST);
+ case NORTH_EAST:
+- return state.withProperty(SHAPE, BlockRailBase.EnumRailDirection.SOUTH_EAST);
++ return state.withProperty(SHAPE, EnumRailDirection.SOUTH_EAST);
+ }
+
+ default:
+@@ -314,7 +322,7 @@
+ @SuppressWarnings("incomplete-switch")
+ public IBlockState withMirror(IBlockState state, Mirror mirrorIn)
+ {
+- BlockRailBase.EnumRailDirection blockrailbase$enumraildirection = (BlockRailBase.EnumRailDirection)state.getValue(SHAPE);
++ EnumRailDirection blockrailbase$enumraildirection = (EnumRailDirection)state.getValue(SHAPE);
+
+ switch (mirrorIn)
+ {
+@@ -323,17 +331,17 @@
+ switch (blockrailbase$enumraildirection)
+ {
+ case ASCENDING_NORTH:
+- return state.withProperty(SHAPE, BlockRailBase.EnumRailDirection.ASCENDING_SOUTH);
++ return state.withProperty(SHAPE, EnumRailDirection.ASCENDING_SOUTH);
+ case ASCENDING_SOUTH:
+- return state.withProperty(SHAPE, BlockRailBase.EnumRailDirection.ASCENDING_NORTH);
++ return state.withProperty(SHAPE, EnumRailDirection.ASCENDING_NORTH);
+ case SOUTH_EAST:
+- return state.withProperty(SHAPE, BlockRailBase.EnumRailDirection.NORTH_EAST);
++ return state.withProperty(SHAPE, EnumRailDirection.NORTH_EAST);
+ case SOUTH_WEST:
+- return state.withProperty(SHAPE, BlockRailBase.EnumRailDirection.NORTH_WEST);
++ return state.withProperty(SHAPE, EnumRailDirection.NORTH_WEST);
+ case NORTH_WEST:
+- return state.withProperty(SHAPE, BlockRailBase.EnumRailDirection.SOUTH_WEST);
++ return state.withProperty(SHAPE, EnumRailDirection.SOUTH_WEST);
+ case NORTH_EAST:
+- return state.withProperty(SHAPE, BlockRailBase.EnumRailDirection.SOUTH_EAST);
++ return state.withProperty(SHAPE, EnumRailDirection.SOUTH_EAST);
+ default:
+ return super.withMirror(state, mirrorIn);
+ }
+@@ -343,21 +351,21 @@
+ switch (blockrailbase$enumraildirection)
+ {
+ case ASCENDING_EAST:
+- return state.withProperty(SHAPE, BlockRailBase.EnumRailDirection.ASCENDING_WEST);
++ return state.withProperty(SHAPE, EnumRailDirection.ASCENDING_WEST);
+ case ASCENDING_WEST:
+- return state.withProperty(SHAPE, BlockRailBase.EnumRailDirection.ASCENDING_EAST);
++ return state.withProperty(SHAPE, EnumRailDirection.ASCENDING_EAST);
+ case ASCENDING_NORTH:
+ case ASCENDING_SOUTH:
+ default:
+ break;
+ case SOUTH_EAST:
+- return state.withProperty(SHAPE, BlockRailBase.EnumRailDirection.SOUTH_WEST);
++ return state.withProperty(SHAPE, EnumRailDirection.SOUTH_WEST);
+ case SOUTH_WEST:
+- return state.withProperty(SHAPE, BlockRailBase.EnumRailDirection.SOUTH_EAST);
++ return state.withProperty(SHAPE, EnumRailDirection.SOUTH_EAST);
+ case NORTH_WEST:
+- return state.withProperty(SHAPE, BlockRailBase.EnumRailDirection.NORTH_EAST);
++ return state.withProperty(SHAPE, EnumRailDirection.NORTH_EAST);
+ case NORTH_EAST:
+- return state.withProperty(SHAPE, BlockRailBase.EnumRailDirection.NORTH_WEST);
++ return state.withProperty(SHAPE, EnumRailDirection.NORTH_WEST);
+ }
+ }
+
diff --git a/patches/net/minecraft/block/BlockRedstoneDiode.java.patch b/patches/net/minecraft/block/BlockRedstoneDiode.java.patch
new file mode 100644
index 00000000..52b01c27
--- /dev/null
+++ b/patches/net/minecraft/block/BlockRedstoneDiode.java.patch
@@ -0,0 +1,27 @@
+--- ../src-base/minecraft/net/minecraft/block/BlockRedstoneDiode.java
++++ ../src-work/minecraft/net/minecraft/block/BlockRedstoneDiode.java
+@@ -15,6 +15,7 @@
+ import net.minecraft.world.World;
+ import net.minecraftforge.fml.relauncher.Side;
+ import net.minecraftforge.fml.relauncher.SideOnly;
++import org.bukkit.craftbukkit.event.CraftEventFactory;
+
+ public abstract class BlockRedstoneDiode extends BlockHorizontal
+ {
+@@ -61,10 +62,16 @@
+
+ if (this.isRepeaterPowered && !flag)
+ {
++ if (CraftEventFactory.callRedstoneChange(worldIn, pos.getX(), pos.getY(), pos.getZ(), 15, 0).getNewCurrent() != 0) {
++ return;
++ }
+ worldIn.setBlockState(pos, this.getUnpoweredState(state), 2);
+ }
+ else if (!this.isRepeaterPowered)
+ {
++ if (CraftEventFactory.callRedstoneChange(worldIn, pos.getX(), pos.getY(), pos.getZ(), 0, 15).getNewCurrent() != 15) {
++ return;
++ }
+ worldIn.setBlockState(pos, this.getPoweredState(state), 2);
+
+ if (!flag)
diff --git a/patches/net/minecraft/block/BlockRedstoneLight.java.patch b/patches/net/minecraft/block/BlockRedstoneLight.java.patch
new file mode 100644
index 00000000..1b9241c1
--- /dev/null
+++ b/patches/net/minecraft/block/BlockRedstoneLight.java.patch
@@ -0,0 +1,47 @@
+--- ../src-base/minecraft/net/minecraft/block/BlockRedstoneLight.java
++++ ../src-work/minecraft/net/minecraft/block/BlockRedstoneLight.java
+@@ -8,6 +8,7 @@
+ import net.minecraft.item.ItemStack;
+ import net.minecraft.util.math.BlockPos;
+ import net.minecraft.world.World;
++import org.bukkit.craftbukkit.event.CraftEventFactory;
+
+ public class BlockRedstoneLight extends Block
+ {
+@@ -30,10 +31,16 @@
+ {
+ if (this.isOn && !worldIn.isBlockPowered(pos))
+ {
++ if (CraftEventFactory.callRedstoneChange(worldIn, pos.getX(), pos.getY(), pos.getZ(), 15, 0).getNewCurrent() != 0) {
++ return;
++ }
+ worldIn.setBlockState(pos, Blocks.REDSTONE_LAMP.getDefaultState(), 2);
+ }
+ else if (!this.isOn && worldIn.isBlockPowered(pos))
+ {
++ if (CraftEventFactory.callRedstoneChange(worldIn, pos.getX(), pos.getY(), pos.getZ(), 0, 15).getNewCurrent() != 15) {
++ return;
++ }
+ worldIn.setBlockState(pos, Blocks.LIT_REDSTONE_LAMP.getDefaultState(), 2);
+ }
+ }
+@@ -49,6 +56,9 @@
+ }
+ else if (!this.isOn && worldIn.isBlockPowered(pos))
+ {
++ if (CraftEventFactory.callRedstoneChange(worldIn, pos.getX(), pos.getY(), pos.getZ(), 0, 15).getNewCurrent() != 15) {
++ return;
++ }
+ worldIn.setBlockState(pos, Blocks.LIT_REDSTONE_LAMP.getDefaultState(), 2);
+ }
+ }
+@@ -60,6 +70,9 @@
+ {
+ if (this.isOn && !worldIn.isBlockPowered(pos))
+ {
++ if (CraftEventFactory.callRedstoneChange(worldIn, pos.getX(), pos.getY(), pos.getZ(), 15, 0).getNewCurrent() != 0) {
++ return;
++ }
+ worldIn.setBlockState(pos, Blocks.REDSTONE_LAMP.getDefaultState(), 2);
+ }
+ }
diff --git a/patches/net/minecraft/block/BlockRedstoneOre.java.patch b/patches/net/minecraft/block/BlockRedstoneOre.java.patch
new file mode 100644
index 00000000..014618b4
--- /dev/null
+++ b/patches/net/minecraft/block/BlockRedstoneOre.java.patch
@@ -0,0 +1,76 @@
+--- ../src-base/minecraft/net/minecraft/block/BlockRedstoneOre.java
++++ ../src-work/minecraft/net/minecraft/block/BlockRedstoneOre.java
+@@ -16,6 +16,8 @@
+ import net.minecraft.world.World;
+ import net.minecraftforge.fml.relauncher.Side;
+ import net.minecraftforge.fml.relauncher.SideOnly;
++import org.bukkit.craftbukkit.event.CraftEventFactory;
++import org.bukkit.event.entity.EntityInteractEvent;
+
+ public class BlockRedstoneOre extends Block
+ {
+@@ -40,19 +42,33 @@
+
+ public void onBlockClicked(World worldIn, BlockPos pos, EntityPlayer playerIn)
+ {
+- this.activate(worldIn, pos);
++ this.activate(worldIn, pos, playerIn); // CraftBukkit - add playerIn
+ super.onBlockClicked(worldIn, pos, playerIn);
+ }
+
+ public void onEntityWalk(World worldIn, BlockPos pos, Entity entityIn)
+ {
+- this.activate(worldIn, pos);
+- super.onEntityWalk(worldIn, pos, entityIn);
++// this.activate(worldIn, pos);
++// super.onEntityWalk(worldIn, pos, entityIn);
++ if (entityIn instanceof EntityPlayer) {
++ org.bukkit.event.player.PlayerInteractEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerInteractEvent((EntityPlayer) entityIn, org.bukkit.event.block.Action.PHYSICAL, pos, null, null, null);
++ if (!event.isCancelled()) {
++ this.activate(worldIn, pos, entityIn); // add entity
++ super.onEntityWalk(worldIn, pos, entityIn);
++ }
++ } else {
++ EntityInteractEvent event = new EntityInteractEvent(entityIn.getBukkitEntity(), worldIn.getWorld().getBlockAt(pos.getX(), pos.getY(), pos.getZ()));
++ worldIn.getServer().getPluginManager().callEvent(event);
++ if (!event.isCancelled()) {
++ this.activate(worldIn, pos, entityIn); // add entity
++ super.onEntityWalk(worldIn, pos, entityIn);
++ }
++ }
+ }
+
+ public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
+ {
+- this.activate(worldIn, pos);
++ this.activate(worldIn, pos, playerIn); // CraftBukkit - add playerIn
+ return super.onBlockActivated(worldIn, pos, state, playerIn, hand, facing, hitX, hitY, hitZ);
+ }
+
+@@ -66,10 +82,26 @@
+ }
+ }
+
++ private void activate(World worldIn, BlockPos pos, Entity entity)
++ {
++ this.spawnParticles(worldIn, pos);
++
++ if (this == Blocks.REDSTONE_ORE)
++ {
++ if (CraftEventFactory.callEntityChangeBlockEvent(entity, pos, Blocks.LIT_REDSTONE_ORE, 0).isCancelled()) {
++ return;
++ }
++ worldIn.setBlockState(pos, Blocks.LIT_REDSTONE_ORE.getDefaultState());
++ }
++ }
++
+ public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
+ {
+ if (this == Blocks.LIT_REDSTONE_ORE)
+ {
++ if (CraftEventFactory.callBlockFadeEvent(worldIn.getWorld().getBlockAt(pos.getX(), pos.getY(), pos.getZ()), Blocks.REDSTONE_ORE).isCancelled()) {
++ return;
++ }
+ worldIn.setBlockState(pos, Blocks.REDSTONE_ORE.getDefaultState());
+ }
+ }
diff --git a/patches/net/minecraft/block/BlockRedstoneTorch.java.patch b/patches/net/minecraft/block/BlockRedstoneTorch.java.patch
new file mode 100644
index 00000000..4fa3aa9a
--- /dev/null
+++ b/patches/net/minecraft/block/BlockRedstoneTorch.java.patch
@@ -0,0 +1,109 @@
+--- ../src-base/minecraft/net/minecraft/block/BlockRedstoneTorch.java
++++ ../src-work/minecraft/net/minecraft/block/BlockRedstoneTorch.java
+@@ -20,10 +20,11 @@
+ import net.minecraft.world.World;
+ import net.minecraftforge.fml.relauncher.Side;
+ import net.minecraftforge.fml.relauncher.SideOnly;
++import org.bukkit.event.block.BlockRedstoneEvent;
+
+ public class BlockRedstoneTorch extends BlockTorch
+ {
+- private static final Map> toggles = new java.util.WeakHashMap>(); // FORGE - fix vanilla MC-101233
++ private static final Map> toggles = new java.util.WeakHashMap>(); // FORGE - fix vanilla MC-101233
+ private final boolean isOn;
+
+ private boolean isBurnedOut(World worldIn, BlockPos pos, boolean turnOff)
+@@ -33,18 +34,18 @@
+ toggles.put(worldIn, Lists.newArrayList());
+ }
+
+- List list = (List)toggles.get(worldIn);
++ List list = (List)toggles.get(worldIn);
+
+ if (turnOff)
+ {
+- list.add(new BlockRedstoneTorch.Toggle(pos, worldIn.getTotalWorldTime()));
++ list.add(new Toggle(pos, worldIn.getTotalWorldTime()));
+ }
+
+ int i = 0;
+
+ for (int j = 0; j < list.size(); ++j)
+ {
+- BlockRedstoneTorch.Toggle blockredstonetorch$toggle = list.get(j);
++ Toggle blockredstonetorch$toggle = list.get(j);
+
+ if (blockredstonetorch$toggle.pos.equals(pos))
+ {
+@@ -109,20 +110,46 @@
+ {
+ }
+
++ private long last = 0L;
+ public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
+ {
++ if (System.currentTimeMillis() - last <= -1)
++ {
++ return;
++ }
++ last = System.currentTimeMillis();
+ boolean flag = this.shouldBeOff(worldIn, pos, state);
+ List list = (List)toggles.get(worldIn);
+
+- while (list != null && !list.isEmpty() && worldIn.getTotalWorldTime() - (list.get(0)).time > 60L)
+- {
+- list.remove(0);
++ // Paper start
++ if (list != null) {
++ int index = 0;
++ while (index < list.size() && worldIn.getTotalWorldTime() - list.get(index).getTime() > 60L) {
++ index++;
++ }
++ if (index > 0) {
++ list.subList(0, index).clear();
+ }
++ }
++ // Paper end
+
++ org.bukkit.plugin.PluginManager manager = worldIn.getServer().getPluginManager();
++ org.bukkit.block.Block block = worldIn.getWorld().getBlockAt(pos.getX(), pos.getY(), pos.getZ());
++ int oldCurrent = this.isOn ? 15 : 0;
++
++ BlockRedstoneEvent event = new BlockRedstoneEvent(block, oldCurrent, oldCurrent);
++
+ if (this.isOn)
+ {
+ if (flag)
+ {
++ if (oldCurrent != 0) {
++ event.setNewCurrent(0);
++ manager.callEvent(event);
++ if (event.getNewCurrent() != 0) {
++ return;
++ }
++ }
+ worldIn.setBlockState(pos, Blocks.UNLIT_REDSTONE_TORCH.getDefaultState().withProperty(FACING, state.getValue(FACING)), 3);
+
+ if (this.isBurnedOut(worldIn, pos, true))
+@@ -143,6 +170,13 @@
+ }
+ else if (!flag && !this.isBurnedOut(worldIn, pos, false))
+ {
++ if (oldCurrent != 15) {
++ event.setNewCurrent(15);
++ manager.callEvent(event);
++ if (event.getNewCurrent() != 15) {
++ return;
++ }
++ }
+ worldIn.setBlockState(pos, Blocks.REDSTONE_TORCH.getDefaultState().withProperty(FACING, state.getValue(FACING)), 3);
+ }
+ }
+@@ -210,6 +244,7 @@
+ {
+ BlockPos pos;
+ long time;
++ final long getTime() { return this.time; } // Paper - OBFHELPER;
+
+ public Toggle(BlockPos pos, long time)
+ {
diff --git a/patches/net/minecraft/block/BlockRedstoneWire.java.patch b/patches/net/minecraft/block/BlockRedstoneWire.java.patch
new file mode 100644
index 00000000..7d6902e1
--- /dev/null
+++ b/patches/net/minecraft/block/BlockRedstoneWire.java.patch
@@ -0,0 +1,99 @@
+--- ../src-base/minecraft/net/minecraft/block/BlockRedstoneWire.java
++++ ../src-work/minecraft/net/minecraft/block/BlockRedstoneWire.java
+@@ -31,13 +31,14 @@
+ import net.minecraft.world.World;
+ import net.minecraftforge.fml.relauncher.Side;
+ import net.minecraftforge.fml.relauncher.SideOnly;
++import org.bukkit.event.block.BlockRedstoneEvent;
+
+ public class BlockRedstoneWire extends Block
+ {
+- public static final PropertyEnum NORTH = PropertyEnum.create("north", BlockRedstoneWire.EnumAttachPosition.class);
+- public static final PropertyEnum EAST = PropertyEnum.create("east", BlockRedstoneWire.EnumAttachPosition.class);
+- public static final PropertyEnum SOUTH = PropertyEnum.create("south", BlockRedstoneWire.EnumAttachPosition.class);
+- public static final PropertyEnum WEST = PropertyEnum.create("west", BlockRedstoneWire.EnumAttachPosition.class);
++ public static final PropertyEnum NORTH = PropertyEnum.create("north", EnumAttachPosition.class);
++ public static final PropertyEnum EAST = PropertyEnum.create("east", EnumAttachPosition.class);
++ public static final PropertyEnum SOUTH = PropertyEnum.create("south", EnumAttachPosition.class);
++ public static final PropertyEnum WEST = PropertyEnum.create("west", EnumAttachPosition.class);
+ public static final PropertyInteger POWER = PropertyInteger.create("power", 0, 15);
+ protected static final AxisAlignedBB[] REDSTONE_WIRE_AABB = new AxisAlignedBB[] {new AxisAlignedBB(0.1875D, 0.0D, 0.1875D, 0.8125D, 0.0625D, 0.8125D), new AxisAlignedBB(0.1875D, 0.0D, 0.1875D, 0.8125D, 0.0625D, 1.0D), new AxisAlignedBB(0.0D, 0.0D, 0.1875D, 0.8125D, 0.0625D, 0.8125D), new AxisAlignedBB(0.0D, 0.0D, 0.1875D, 0.8125D, 0.0625D, 1.0D), new AxisAlignedBB(0.1875D, 0.0D, 0.0D, 0.8125D, 0.0625D, 0.8125D), new AxisAlignedBB(0.1875D, 0.0D, 0.0D, 0.8125D, 0.0625D, 1.0D), new AxisAlignedBB(0.0D, 0.0D, 0.0D, 0.8125D, 0.0625D, 0.8125D), new AxisAlignedBB(0.0D, 0.0D, 0.0D, 0.8125D, 0.0625D, 1.0D), new AxisAlignedBB(0.1875D, 0.0D, 0.1875D, 1.0D, 0.0625D, 0.8125D), new AxisAlignedBB(0.1875D, 0.0D, 0.1875D, 1.0D, 0.0625D, 1.0D), new AxisAlignedBB(0.0D, 0.0D, 0.1875D, 1.0D, 0.0625D, 0.8125D), new AxisAlignedBB(0.0D, 0.0D, 0.1875D, 1.0D, 0.0625D, 1.0D), new AxisAlignedBB(0.1875D, 0.0D, 0.0D, 1.0D, 0.0625D, 0.8125D), new AxisAlignedBB(0.1875D, 0.0D, 0.0D, 1.0D, 0.0625D, 1.0D), new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 0.0625D, 0.8125D), new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 0.0625D, 1.0D)};
+ private boolean canProvidePower = true;
+@@ -46,7 +47,7 @@
+ public BlockRedstoneWire()
+ {
+ super(Material.CIRCUITS);
+- this.setDefaultState(this.blockState.getBaseState().withProperty(NORTH, BlockRedstoneWire.EnumAttachPosition.NONE).withProperty(EAST, BlockRedstoneWire.EnumAttachPosition.NONE).withProperty(SOUTH, BlockRedstoneWire.EnumAttachPosition.NONE).withProperty(WEST, BlockRedstoneWire.EnumAttachPosition.NONE).withProperty(POWER, Integer.valueOf(0)));
++ this.setDefaultState(this.blockState.getBaseState().withProperty(NORTH, EnumAttachPosition.NONE).withProperty(EAST, EnumAttachPosition.NONE).withProperty(SOUTH, EnumAttachPosition.NONE).withProperty(WEST, EnumAttachPosition.NONE).withProperty(POWER, Integer.valueOf(0)));
+ }
+
+ public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos)
+@@ -57,10 +58,10 @@
+ private static int getAABBIndex(IBlockState state)
+ {
+ int i = 0;
+- boolean flag = state.getValue(NORTH) != BlockRedstoneWire.EnumAttachPosition.NONE;
+- boolean flag1 = state.getValue(EAST) != BlockRedstoneWire.EnumAttachPosition.NONE;
+- boolean flag2 = state.getValue(SOUTH) != BlockRedstoneWire.EnumAttachPosition.NONE;
+- boolean flag3 = state.getValue(WEST) != BlockRedstoneWire.EnumAttachPosition.NONE;
++ boolean flag = state.getValue(NORTH) != EnumAttachPosition.NONE;
++ boolean flag1 = state.getValue(EAST) != EnumAttachPosition.NONE;
++ boolean flag2 = state.getValue(SOUTH) != EnumAttachPosition.NONE;
++ boolean flag3 = state.getValue(WEST) != EnumAttachPosition.NONE;
+
+ if (flag || flag2 && !flag && !flag1 && !flag3)
+ {
+@@ -94,7 +95,7 @@
+ return state;
+ }
+
+- private BlockRedstoneWire.EnumAttachPosition getAttachPosition(IBlockAccess worldIn, BlockPos pos, EnumFacing direction)
++ private EnumAttachPosition getAttachPosition(IBlockAccess worldIn, BlockPos pos, EnumFacing direction)
+ {
+ BlockPos blockpos = pos.offset(direction);
+ IBlockState iblockstate = worldIn.getBlockState(pos.offset(direction));
+@@ -111,18 +112,18 @@
+ {
+ if (iblockstate.isBlockNormalCube())
+ {
+- return BlockRedstoneWire.EnumAttachPosition.UP;
++ return EnumAttachPosition.UP;
+ }
+
+- return BlockRedstoneWire.EnumAttachPosition.SIDE;
++ return EnumAttachPosition.SIDE;
+ }
+ }
+
+- return BlockRedstoneWire.EnumAttachPosition.NONE;
++ return EnumAttachPosition.NONE;
+ }
+ else
+ {
+- return BlockRedstoneWire.EnumAttachPosition.SIDE;
++ return EnumAttachPosition.SIDE;
+ }
+ }
+
+@@ -220,6 +221,12 @@
+ j = k;
+ }
+
++ if (i != j) {
++ BlockRedstoneEvent event = new BlockRedstoneEvent(worldIn.getWorld().getBlockAt(pos1.getX(), pos1.getY(), pos1.getZ()), i, j);
++ worldIn.getServer().getPluginManager().callEvent(event);
++ j = event.getNewCurrent();
++ }
++
+ if (i != j)
+ {
+ state = state.withProperty(POWER, Integer.valueOf(j));
+@@ -319,7 +326,7 @@
+ }
+ }
+
+- private int getMaxCurrentStrength(World worldIn, BlockPos pos, int strength)
++ public int getMaxCurrentStrength(World worldIn, BlockPos pos, int strength)
+ {
+ if (worldIn.getBlockState(pos).getBlock() != this)
+ {
diff --git a/patches/net/minecraft/block/BlockReed.java.patch b/patches/net/minecraft/block/BlockReed.java.patch
new file mode 100644
index 00000000..6bd01c9e
--- /dev/null
+++ b/patches/net/minecraft/block/BlockReed.java.patch
@@ -0,0 +1,16 @@
+--- ../src-base/minecraft/net/minecraft/block/BlockReed.java
++++ ../src-work/minecraft/net/minecraft/block/BlockReed.java
+@@ -57,9 +57,11 @@
+
+ if(net.minecraftforge.common.ForgeHooks.onCropsGrowPre(worldIn, pos, state, true))
+ {
+- if (j == 15)
++ if (j >= (byte)Block.range(3.0f, 100.0f / worldIn.spigotConfig.caneModifier * 15.0f + 0.5f, 15.0f)) // Spigot
+ {
+- worldIn.setBlockState(pos.up(), this.getDefaultState());
++// worldIn.setBlockState(pos.up(), this.getDefaultState());
++ BlockPos upPos = pos.up();
++ org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockGrowEvent(worldIn, upPos.getX(), upPos.getY(), upPos.getZ(), this, 0);
+ worldIn.setBlockState(pos, state.withProperty(AGE, Integer.valueOf(0)), 4);
+ }
+ else
diff --git a/patches/net/minecraft/block/BlockSapling.java.patch b/patches/net/minecraft/block/BlockSapling.java.patch
new file mode 100644
index 00000000..87ee9ca7
--- /dev/null
+++ b/patches/net/minecraft/block/BlockSapling.java.patch
@@ -0,0 +1,132 @@
+--- ../src-base/minecraft/net/minecraft/block/BlockSapling.java
++++ ../src-work/minecraft/net/minecraft/block/BlockSapling.java
+@@ -1,5 +1,6 @@
+ package net.minecraft.block;
+
++import java.util.List;
+ import java.util.Random;
+ import net.minecraft.block.properties.IProperty;
+ import net.minecraft.block.properties.PropertyEnum;
+@@ -24,12 +25,17 @@
+ import net.minecraft.world.gen.feature.WorldGenTaiga2;
+ import net.minecraft.world.gen.feature.WorldGenTrees;
+ import net.minecraft.world.gen.feature.WorldGenerator;
++import org.bukkit.Location;
++import org.bukkit.TreeType;
++import org.bukkit.block.BlockState;
++import org.bukkit.event.world.StructureGrowEvent;
+
+ public class BlockSapling extends BlockBush implements IGrowable
+ {
+ public static final PropertyEnum TYPE = PropertyEnum.create("type", BlockPlanks.EnumType.class);
+ public static final PropertyInteger STAGE = PropertyInteger.create("stage", 0, 1);
+ protected static final AxisAlignedBB SAPLING_AABB = new AxisAlignedBB(0.09999999403953552D, 0.0D, 0.09999999403953552D, 0.8999999761581421D, 0.800000011920929D, 0.8999999761581421D);
++ public static TreeType treeType; // CraftBukkit
+
+ protected BlockSapling()
+ {
+@@ -54,9 +60,31 @@
+ super.updateTick(worldIn, pos, state, rand);
+
+ if (!worldIn.isAreaLoaded(pos, 1)) return; // Forge: prevent loading unloaded chunks when checking neighbor's light
+- if (worldIn.getLightFromNeighbors(pos.up()) >= 9 && rand.nextInt(7) == 0)
+- {
++ if (worldIn.isLightLevel(pos.up(), 9) && rand.nextInt(Math.max(2, (int)(100.0f / worldIn.spigotConfig.saplingModifier * 7.0f + 0.5f))) == 0) {
++ worldIn.captureTreeGeneration = true;
+ this.grow(worldIn, pos, state, rand);
++ worldIn.captureTreeGeneration = false;
++ if (worldIn.capturedBlockSnapshots.size() > 0) {
++ TreeType treeType = BlockSapling.treeType;
++ BlockSapling.treeType = null;
++ Location location = new Location(worldIn.getWorld(), pos.getX(), pos.getY(), pos.getZ());
++ List blocks = (List) worldIn.capturedBlockSnapshots.clone();
++ List blockstates = new java.util.ArrayList();
++ for (net.minecraftforge.common.util.BlockSnapshot snapshot : blocks) {
++ blockstates.add(new org.bukkit.craftbukkit.block.CraftBlockState(snapshot));
++ }
++ worldIn.capturedBlockSnapshots.clear();
++ StructureGrowEvent event = null;
++ if (treeType != null) {
++ event = new StructureGrowEvent(location, treeType, false, null, blockstates);
++ org.bukkit.Bukkit.getPluginManager().callEvent(event);
++ }
++ if (event == null || !event.isCancelled()) {
++ for (BlockState blockstate : blockstates) {
++ blockstate.update(true);
++ }
++ }
++ }
+ }
+ }
+ }
+@@ -76,7 +104,17 @@
+ public void generateTree(World worldIn, BlockPos pos, IBlockState state, Random rand)
+ {
+ if (!net.minecraftforge.event.terraingen.TerrainGen.saplingGrowTree(worldIn, rand, pos)) return;
+- WorldGenerator worldgenerator = (WorldGenerator)(rand.nextInt(10) == 0 ? new WorldGenBigTree(true) : new WorldGenTrees(true));
++ // CraftBukkit start - Turn ternary operator into if statement to set treeType
++ // WorldGenerator worldgenerator = (WorldGenerator)(rand.nextInt(10) == 0 ? new WorldGenBigTree(true) : new WorldGenTrees(true));
++ WorldGenerator worldgenerator;
++ if (rand.nextInt(10) == 0) {
++ treeType = TreeType.BIG_TREE;
++ worldgenerator = new WorldGenBigTree(true);
++ } else {
++ treeType = TreeType.TREE;
++ worldgenerator = new WorldGenTrees(true);
++ }
++ // CraftBukkit end
+ int i = 0;
+ int j = 0;
+ boolean flag = false;
+@@ -92,6 +130,7 @@
+ {
+ if (this.isTwoByTwoOfType(worldIn, pos, i, j, BlockPlanks.EnumType.SPRUCE))
+ {
++ treeType = TreeType.MEGA_REDWOOD; // CraftBukkit
+ worldgenerator = new WorldGenMegaPineTree(false, rand.nextBoolean());
+ flag = true;
+ break label68;
+@@ -103,11 +142,13 @@
+ {
+ i = 0;
+ j = 0;
++ treeType = TreeType.REDWOOD; // CraftBukkit
+ worldgenerator = new WorldGenTaiga2(true);
+ }
+
+ break;
+ case BIRCH:
++ treeType = TreeType.BIRCH; // CraftBukkit
+ worldgenerator = new WorldGenBirchTree(true, false);
+ break;
+ case JUNGLE:
+@@ -121,6 +162,7 @@
+ {
+ if (this.isTwoByTwoOfType(worldIn, pos, i, j, BlockPlanks.EnumType.JUNGLE))
+ {
++ treeType = TreeType.JUNGLE; // CraftBukkit
+ worldgenerator = new WorldGenMegaJungle(true, 10, 20, iblockstate, iblockstate1);
+ flag = true;
+ break label82;
+@@ -132,11 +174,13 @@
+ {
+ i = 0;
+ j = 0;
++ treeType = TreeType.SMALL_JUNGLE; // CraftBukkit
+ worldgenerator = new WorldGenTrees(true, 4 + rand.nextInt(7), iblockstate, iblockstate1, false);
+ }
+
+ break;
+ case ACACIA:
++ treeType = TreeType.ACACIA; // CraftBukkit
+ worldgenerator = new WorldGenSavannaTree(true);
+ break;
+ case DARK_OAK:
+@@ -148,6 +192,7 @@
+ {
+ if (this.isTwoByTwoOfType(worldIn, pos, i, j, BlockPlanks.EnumType.DARK_OAK))
+ {
++ treeType = TreeType.DARK_OAK; // CraftBukkit
+ worldgenerator = new WorldGenCanopyTree(true);
+ flag = true;
+ break label96;
diff --git a/patches/net/minecraft/block/BlockShulkerBox.java.patch b/patches/net/minecraft/block/BlockShulkerBox.java.patch
new file mode 100644
index 00000000..52e23de6
--- /dev/null
+++ b/patches/net/minecraft/block/BlockShulkerBox.java.patch
@@ -0,0 +1,30 @@
+--- ../src-base/minecraft/net/minecraft/block/BlockShulkerBox.java
++++ ../src-work/minecraft/net/minecraft/block/BlockShulkerBox.java
+@@ -44,7 +44,7 @@
+ public class BlockShulkerBox extends BlockContainer
+ {
+ public static final PropertyEnum FACING = PropertyDirection.create("facing");
+- private final EnumDyeColor color;
++ public final EnumDyeColor color;
+
+ public BlockShulkerBox(EnumDyeColor colorIn)
+ {
+@@ -162,7 +162,7 @@
+
+ public void dropBlockAsItemWithChance(World worldIn, BlockPos pos, IBlockState state, float chance, int fortune)
+ {
+- }
++ }
+
+ public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack)
+ {
+@@ -201,8 +201,8 @@
+
+ spawnAsEntity(worldIn, pos, itemstack);
+ }
+-
+ worldIn.updateComparatorOutputLevel(pos, state.getBlock());
++ tileentityshulkerbox.clear(); // Paper - This was intended to be called in Vanilla (is checked in the if statement above if has been called) - Fixes dupe issues
+ }
+
+ super.breakBlock(worldIn, pos, state);
diff --git a/patches/net/minecraft/block/BlockSilverfish.java.patch b/patches/net/minecraft/block/BlockSilverfish.java.patch
new file mode 100644
index 00000000..252fb218
--- /dev/null
+++ b/patches/net/minecraft/block/BlockSilverfish.java.patch
@@ -0,0 +1,19 @@
+--- ../src-base/minecraft/net/minecraft/block/BlockSilverfish.java
++++ ../src-work/minecraft/net/minecraft/block/BlockSilverfish.java
+@@ -14,6 +14,7 @@
+ import net.minecraft.util.NonNullList;
+ import net.minecraft.util.math.BlockPos;
+ import net.minecraft.world.World;
++import org.bukkit.event.entity.CreatureSpawnEvent;
+
+ public class BlockSilverfish extends Block
+ {
+@@ -63,7 +64,7 @@
+ {
+ EntitySilverfish entitysilverfish = new EntitySilverfish(worldIn);
+ entitysilverfish.setLocationAndAngles((double)pos.getX() + 0.5D, (double)pos.getY(), (double)pos.getZ() + 0.5D, 0.0F, 0.0F);
+- worldIn.spawnEntity(entitysilverfish);
++ worldIn.spawnEntity(entitysilverfish, CreatureSpawnEvent.SpawnReason.SILVERFISH_BLOCK); // CraftBukkit - add SpawnReason
+ entitysilverfish.spawnExplosionParticle();
+ }
+ }
diff --git a/patches/net/minecraft/block/BlockSkull.java.patch b/patches/net/minecraft/block/BlockSkull.java.patch
new file mode 100644
index 00000000..ded3ed70
--- /dev/null
+++ b/patches/net/minecraft/block/BlockSkull.java.patch
@@ -0,0 +1,138 @@
+--- ../src-base/minecraft/net/minecraft/block/BlockSkull.java
++++ ../src-work/minecraft/net/minecraft/block/BlockSkull.java
+@@ -40,6 +40,8 @@
+ import net.minecraft.world.World;
+ import net.minecraftforge.fml.relauncher.Side;
+ import net.minecraftforge.fml.relauncher.SideOnly;
++import org.bukkit.craftbukkit.util.BlockStateListPopulator;
++import org.bukkit.event.entity.CreatureSpawnEvent;
+
+ public class BlockSkull extends BlockContainer
+ {
+@@ -128,6 +130,30 @@
+ return new ItemStack(Items.SKULL, 1, i);
+ }
+
++ // CraftBukkit start - Special case dropping so we can get info from the tile entity
++ @Override
++ public void dropBlockAsItemWithChance(World worldIn, BlockPos pos, IBlockState state, float chance, int fortune) {
++ if (worldIn.rand.nextFloat() < chance) {
++ TileEntity tileentity = worldIn.getTileEntity(pos);
++
++ if (tileentity instanceof TileEntitySkull) {
++ TileEntitySkull tileentityskull = (TileEntitySkull) tileentity;
++ ItemStack itemstack = this.getItem(worldIn, pos, state);
++
++ if (tileentityskull.getSkullType() == 3 && tileentityskull.getPlayerProfile() != null) {
++ itemstack.setTagCompound(new NBTTagCompound());
++ NBTTagCompound nbttagcompound = new NBTTagCompound();
++
++ NBTUtil.writeGameProfile(nbttagcompound, tileentityskull.getPlayerProfile());
++ itemstack.getTagCompound().setTag("SkullOwner", nbttagcompound);
++ }
++
++ spawnAsEntity(worldIn, pos, itemstack);
++ }
++ }
++ }
++ // CraftBukkit end
++
+ public void onBlockHarvested(World worldIn, BlockPos pos, IBlockState state, EntityPlayer player)
+ {
+ if (player.capabilities.isCreativeMode)
+@@ -135,7 +161,7 @@
+ state = state.withProperty(NODROP, Boolean.valueOf(true));
+ worldIn.setBlockState(pos, state, 4);
+ }
+- this.dropBlockAsItem(worldIn, pos, state, 0);
++ // this.dropBlockAsItem(worldIn, pos, state, 0); Kettle - prevents doubled and creative mode drops
+
+ super.onBlockHarvested(worldIn, pos, state, player);
+ }
+@@ -147,7 +173,9 @@
+ public void getDrops(net.minecraft.util.NonNullList drops, IBlockAccess worldIn, BlockPos pos, IBlockState state, int fortune)
+ {
+ {
+- if (!((Boolean)state.getValue(NODROP)).booleanValue())
++ // CraftBukkit start - Drop item in code above, not here
++ // if (!((Boolean)state.getValue(NODROP)).booleanValue())
++ if (false)
+ {
+ TileEntity tileentity = worldIn.getTileEntity(pos);
+
+@@ -189,6 +217,7 @@
+
+ public void checkWitherSpawn(World worldIn, BlockPos pos, TileEntitySkull te)
+ {
++ if (worldIn.captureBlockSnapshots) return;
+ if (te.getSkullType() == 1 && pos.getY() >= 2 && worldIn.getDifficulty() != EnumDifficulty.PEACEFUL && !worldIn.isRemote)
+ {
+ BlockPattern blockpattern = this.getWitherPattern();
+@@ -196,10 +225,14 @@
+
+ if (blockpattern$patternhelper != null)
+ {
++ BlockStateListPopulator blockList = new BlockStateListPopulator(worldIn.getWorld());
+ for (int i = 0; i < 3; ++i)
+ {
+ BlockWorldState blockworldstate = blockpattern$patternhelper.translateOffset(i, 0, 0);
+- worldIn.setBlockState(blockworldstate.getPos(), blockworldstate.getBlockState().withProperty(NODROP, Boolean.valueOf(true)), 2);
++ BlockPos pos1 = blockworldstate.getPos();
++ IBlockState data = blockworldstate.getBlockState().withProperty(BlockSkull.NODROP, true);
++ blockList.setTypeAndData(pos1.getX(), pos1.getY(), pos1.getZ(), data.getBlock(), data.getBlock().getMetaFromState(data), 2);
++// worldIn.setBlockState(blockworldstate.getPos(), blockworldstate.getBlockState().withProperty(NODROP, Boolean.valueOf(true)), 2);
+ }
+
+ for (int j = 0; j < blockpattern.getPalmLength(); ++j)
+@@ -207,7 +240,10 @@
+ for (int k = 0; k < blockpattern.getThumbLength(); ++k)
+ {
+ BlockWorldState blockworldstate1 = blockpattern$patternhelper.translateOffset(j, k, 0);
+- worldIn.setBlockState(blockworldstate1.getPos(), Blocks.AIR.getDefaultState(), 2);
++ BlockPos pos1 = blockworldstate1.getPos();
++ blockList.setTypeAndData(pos1.getX(), pos1.getY(), pos1.getZ(), Blocks.AIR, 0, 2);
++// worldIn.setBlockState(blockworldstate1.getPos(), Blocks.AIR.getDefaultState(), 2);
++
+ }
+ }
+
+@@ -217,25 +253,24 @@
+ entitywither.setLocationAndAngles((double)blockpos1.getX() + 0.5D, (double)blockpos1.getY() + 0.55D, (double)blockpos1.getZ() + 0.5D, blockpattern$patternhelper.getForwards().getAxis() == EnumFacing.Axis.X ? 0.0F : 90.0F, 0.0F);
+ entitywither.renderYawOffset = blockpattern$patternhelper.getForwards().getAxis() == EnumFacing.Axis.X ? 0.0F : 90.0F;
+ entitywither.ignite();
++ if (worldIn.spawnEntity(entitywither, CreatureSpawnEvent.SpawnReason.BUILD_WITHER)) {
++ blockList.updateList();
+
+- for (EntityPlayerMP entityplayermp : worldIn.getEntitiesWithinAABB(EntityPlayerMP.class, entitywither.getEntityBoundingBox().grow(50.0D)))
+- {
+- CriteriaTriggers.SUMMONED_ENTITY.trigger(entityplayermp, entitywither);
+- }
++ for (EntityPlayerMP entityplayermp : worldIn.getEntitiesWithinAABB(EntityPlayerMP.class, entitywither.getEntityBoundingBox().grow(50.0D))) {
++ CriteriaTriggers.SUMMONED_ENTITY.trigger(entityplayermp, entitywither);
++ }
+
+- worldIn.spawnEntity(entitywither);
++// worldIn.spawnEntity(entitywither);
+
+- for (int l = 0; l < 120; ++l)
+- {
+- worldIn.spawnParticle(EnumParticleTypes.SNOWBALL, (double)blockpos.getX() + worldIn.rand.nextDouble(), (double)(blockpos.getY() - 2) + worldIn.rand.nextDouble() * 3.9D, (double)blockpos.getZ() + worldIn.rand.nextDouble(), 0.0D, 0.0D, 0.0D);
+- }
++ for (int l = 0; l < 120; ++l) {
++ worldIn.spawnParticle(EnumParticleTypes.SNOWBALL, (double) blockpos.getX() + worldIn.rand.nextDouble(), (double) (blockpos.getY() - 2) + worldIn.rand.nextDouble() * 3.9D, (double) blockpos.getZ() + worldIn.rand.nextDouble(), 0.0D, 0.0D, 0.0D);
++ }
+
+- for (int i1 = 0; i1 < blockpattern.getPalmLength(); ++i1)
+- {
+- for (int j1 = 0; j1 < blockpattern.getThumbLength(); ++j1)
+- {
+- BlockWorldState blockworldstate2 = blockpattern$patternhelper.translateOffset(i1, j1, 0);
+- worldIn.notifyNeighborsRespectDebug(blockworldstate2.getPos(), Blocks.AIR, false);
++ for (int i1 = 0; i1 < blockpattern.getPalmLength(); ++i1) {
++ for (int j1 = 0; j1 < blockpattern.getThumbLength(); ++j1) {
++ BlockWorldState blockworldstate2 = blockpattern$patternhelper.translateOffset(i1, j1, 0);
++ worldIn.notifyNeighborsRespectDebug(blockworldstate2.getPos(), Blocks.AIR, false);
++ }
+ }
+ }
+ }
diff --git a/patches/net/minecraft/block/BlockSnow.java.patch b/patches/net/minecraft/block/BlockSnow.java.patch
new file mode 100644
index 00000000..8854bc69
--- /dev/null
+++ b/patches/net/minecraft/block/BlockSnow.java.patch
@@ -0,0 +1,12 @@
+--- ../src-base/minecraft/net/minecraft/block/BlockSnow.java
++++ ../src-work/minecraft/net/minecraft/block/BlockSnow.java
+@@ -131,6 +131,9 @@
+ {
+ if (worldIn.getLightFor(EnumSkyBlock.BLOCK, pos) > 11)
+ {
++ if (org.bukkit.craftbukkit.event.CraftEventFactory.callBlockFadeEvent(worldIn.getWorld().getBlockAt(pos.getX(), pos.getY(), pos.getZ()), Blocks.AIR).isCancelled()) {
++ return;
++ }
+ worldIn.setBlockToAir(pos);
+ }
+ }
diff --git a/patches/net/minecraft/block/BlockSnowBlock.java.patch b/patches/net/minecraft/block/BlockSnowBlock.java.patch
new file mode 100644
index 00000000..58be1bbb
--- /dev/null
+++ b/patches/net/minecraft/block/BlockSnowBlock.java.patch
@@ -0,0 +1,20 @@
+--- ../src-base/minecraft/net/minecraft/block/BlockSnowBlock.java
++++ ../src-work/minecraft/net/minecraft/block/BlockSnowBlock.java
+@@ -4,6 +4,7 @@
+ import net.minecraft.block.material.Material;
+ import net.minecraft.block.state.IBlockState;
+ import net.minecraft.creativetab.CreativeTabs;
++import net.minecraft.init.Blocks;
+ import net.minecraft.init.Items;
+ import net.minecraft.item.Item;
+ import net.minecraft.util.math.BlockPos;
+@@ -33,6 +34,9 @@
+ {
+ if (worldIn.getLightFor(EnumSkyBlock.BLOCK, pos) > 11)
+ {
++ if (org.bukkit.craftbukkit.event.CraftEventFactory.callBlockFadeEvent(worldIn.getWorld().getBlockAt(pos.getX(), pos.getY(), pos.getZ()), Blocks.AIR).isCancelled()) {
++ return;
++ }
+ this.dropBlockAsItem(worldIn, pos, worldIn.getBlockState(pos), 0);
+ worldIn.setBlockToAir(pos);
+ }
diff --git a/patches/net/minecraft/block/BlockStaticLiquid.java.patch b/patches/net/minecraft/block/BlockStaticLiquid.java.patch
new file mode 100644
index 00000000..0176c84b
--- /dev/null
+++ b/patches/net/minecraft/block/BlockStaticLiquid.java.patch
@@ -0,0 +1,37 @@
+--- ../src-base/minecraft/net/minecraft/block/BlockStaticLiquid.java
++++ ../src-work/minecraft/net/minecraft/block/BlockStaticLiquid.java
+@@ -7,6 +7,7 @@
+ import net.minecraft.util.EnumFacing;
+ import net.minecraft.util.math.BlockPos;
+ import net.minecraft.world.World;
++import org.bukkit.craftbukkit.event.CraftEventFactory;
+
+ public class BlockStaticLiquid extends BlockLiquid
+ {
+@@ -63,6 +64,11 @@
+ {
+ if (this.isSurroundingBlockFlammable(worldIn, blockpos))
+ {
++ if (worldIn.getBlockState(blockpos) != Blocks.FIRE) {
++ if (CraftEventFactory.callBlockIgniteEvent(worldIn, blockpos.getX(), blockpos.getY(), blockpos.getZ(), pos.getX(), pos.getY(), pos.getZ()).isCancelled()) {
++ continue;
++ }
++ }
+ worldIn.setBlockState(blockpos, net.minecraftforge.event.ForgeEventFactory.fireFluidPlaceBlockEvent(worldIn, blockpos, pos, Blocks.FIRE.getDefaultState()));
+ return;
+ }
+@@ -86,6 +92,14 @@
+
+ if (worldIn.isAirBlock(blockpos1.up()) && this.getCanBlockBurn(worldIn, blockpos1))
+ {
++ // CraftBukkit start - Prevent lava putting something on fire
++ BlockPos up = blockpos1.up();
++ if (worldIn.getBlockState(up) != Blocks.FIRE) {
++ if (CraftEventFactory.callBlockIgniteEvent(worldIn, up.getX(), up.getY(), up.getZ(), pos.getX(), pos.getY(), pos.getZ()).isCancelled()) {
++ continue;
++ }
++ }
++ // CraftBukkit end
+ worldIn.setBlockState(blockpos1.up(), net.minecraftforge.event.ForgeEventFactory.fireFluidPlaceBlockEvent(worldIn, blockpos1.up(), pos, Blocks.FIRE.getDefaultState()));
+ }
+ }
diff --git a/patches/net/minecraft/block/BlockStem.java.patch b/patches/net/minecraft/block/BlockStem.java.patch
new file mode 100644
index 00000000..9ceef8b8
--- /dev/null
+++ b/patches/net/minecraft/block/BlockStem.java.patch
@@ -0,0 +1,49 @@
+--- ../src-base/minecraft/net/minecraft/block/BlockStem.java
++++ ../src-work/minecraft/net/minecraft/block/BlockStem.java
+@@ -19,6 +19,7 @@
+ import net.minecraft.util.math.MathHelper;
+ import net.minecraft.world.IBlockAccess;
+ import net.minecraft.world.World;
++import org.bukkit.craftbukkit.event.CraftEventFactory;
+
+ public class BlockStem extends BlockBush implements IGrowable
+ {
+@@ -67,7 +68,7 @@
+ super.updateTick(worldIn, pos, state, rand);
+
+ if (!worldIn.isAreaLoaded(pos, 1)) return; // Forge: prevent loading unloaded chunks when checking neighbor's light
+- if (worldIn.getLightFromNeighbors(pos.up()) >= 9)
++ if (worldIn.isLightLevel(pos.up(), 9)) // Paper
+ {
+ float f = BlockCrops.getGrowthChance(this, worldIn, pos);
+
+@@ -78,7 +79,8 @@
+ if (i < 7)
+ {
+ IBlockState newState = state.withProperty(AGE, Integer.valueOf(i + 1));
+- worldIn.setBlockState(pos, newState, 2);
++ CraftEventFactory.handleBlockGrowEvent(worldIn, pos.getX(), pos.getY(), pos.getZ(), this, getMetaFromState(newState));
++// worldIn.setBlockState(pos, newState, 2);
+ }
+ else
+ {
+@@ -96,7 +98,8 @@
+
+ if (worldIn.isAirBlock(pos) && (block.canSustainPlant(soil, worldIn, pos.down(), EnumFacing.UP, this) || block == Blocks.DIRT || block == Blocks.GRASS))
+ {
+- worldIn.setBlockState(pos, this.crop.getDefaultState());
++ CraftEventFactory.handleBlockGrowEvent(worldIn, pos.getX(), pos.getY(), pos.getZ(), this.crop, 0);
++// worldIn.setBlockState(pos, this.crop.getDefaultState());
+ }
+ }
+ net.minecraftforge.common.ForgeHooks.onCropsGrowPost(worldIn, pos, state, worldIn.getBlockState(pos));
+@@ -107,7 +110,8 @@
+ public void growStem(World worldIn, BlockPos pos, IBlockState state)
+ {
+ int i = ((Integer)state.getValue(AGE)).intValue() + MathHelper.getInt(worldIn.rand, 2, 5);
+- worldIn.setBlockState(pos, state.withProperty(AGE, Integer.valueOf(Math.min(7, i))), 2);
++ CraftEventFactory.handleBlockGrowEvent(worldIn, pos.getX(), pos.getY(), pos.getZ(), this, Math.min(7, i));
++// worldIn.setBlockState(pos, state.withProperty(AGE, Integer.valueOf(Math.min(7, i))), 2);
+ }
+
+ public void dropBlockAsItemWithChance(World worldIn, BlockPos pos, IBlockState state, float chance, int fortune)
diff --git a/patches/net/minecraft/block/BlockTNT.java.patch b/patches/net/minecraft/block/BlockTNT.java.patch
new file mode 100644
index 00000000..78a0b751
--- /dev/null
+++ b/patches/net/minecraft/block/BlockTNT.java.patch
@@ -0,0 +1,12 @@
+--- ../src-base/minecraft/net/minecraft/block/BlockTNT.java
++++ ../src-work/minecraft/net/minecraft/block/BlockTNT.java
+@@ -115,6 +115,9 @@
+
+ if (entityarrow.isBurning())
+ {
++ if (org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent(entityarrow, pos, Blocks.AIR, 0).isCancelled()) {
++ return;
++ }
+ this.explode(worldIn, pos, worldIn.getBlockState(pos).withProperty(EXPLODE, Boolean.valueOf(true)), entityarrow.shootingEntity instanceof EntityLivingBase ? (EntityLivingBase)entityarrow.shootingEntity : null);
+ worldIn.setBlockToAir(pos);
+ }
diff --git a/patches/net/minecraft/block/BlockTrapDoor.java.patch b/patches/net/minecraft/block/BlockTrapDoor.java.patch
new file mode 100644
index 00000000..2c36476f
--- /dev/null
+++ b/patches/net/minecraft/block/BlockTrapDoor.java.patch
@@ -0,0 +1,29 @@
+--- ../src-base/minecraft/net/minecraft/block/BlockTrapDoor.java
++++ ../src-work/minecraft/net/minecraft/block/BlockTrapDoor.java
+@@ -24,6 +24,7 @@
+ import net.minecraft.world.World;
+ import net.minecraftforge.fml.relauncher.Side;
+ import net.minecraftforge.fml.relauncher.SideOnly;
++import org.bukkit.event.block.BlockRedstoneEvent;
+
+ public class BlockTrapDoor extends Block
+ {
+@@ -130,6 +131,18 @@
+
+ if (flag || blockIn.getDefaultState().canProvidePower())
+ {
++ org.bukkit.World bworld = worldIn.getWorld();
++ org.bukkit.block.Block bblock = bworld.getBlockAt(pos.getX(), pos.getY(), pos.getZ());
++
++ int power = bblock.getBlockPower();
++ int oldPower = state.getValue(OPEN) ? 15 : 0;
++
++ if (oldPower == 0 ^ power == 0 || blockIn.getDefaultState().hasComparatorInputOverride()) {
++ BlockRedstoneEvent eventRedstone = new BlockRedstoneEvent(bblock, oldPower, power);
++ worldIn.getServer().getPluginManager().callEvent(eventRedstone);
++ flag = eventRedstone.getNewCurrent() > 0;
++ }
++
+ boolean flag1 = ((Boolean)state.getValue(OPEN)).booleanValue();
+
+ if (flag1 != flag)
diff --git a/patches/net/minecraft/block/BlockTripWire.java.patch b/patches/net/minecraft/block/BlockTripWire.java.patch
new file mode 100644
index 00000000..aea16c54
--- /dev/null
+++ b/patches/net/minecraft/block/BlockTripWire.java.patch
@@ -0,0 +1,51 @@
+--- ../src-base/minecraft/net/minecraft/block/BlockTripWire.java
++++ ../src-work/minecraft/net/minecraft/block/BlockTripWire.java
+@@ -25,6 +25,7 @@
+ import net.minecraft.world.World;
+ import net.minecraftforge.fml.relauncher.Side;
+ import net.minecraftforge.fml.relauncher.SideOnly;
++import org.bukkit.event.entity.EntityInteractEvent;
+
+ public class BlockTripWire extends Block
+ {
+@@ -181,6 +182,40 @@
+ }
+ }
+
++ // CraftBukkit start - Call interact even when triggering connected tripwire
++ if (flag != flag1 && flag1 && iblockstate.getValue(ATTACHED)) {
++ org.bukkit.World bworld = worldIn.getWorld();
++ org.bukkit.plugin.PluginManager manager = worldIn.getServer().getPluginManager();
++ org.bukkit.block.Block block = bworld.getBlockAt(pos.getX(), pos.getY(), pos.getZ());
++ boolean allowed = false;
++
++ // If all of the events are cancelled block the tripwire trigger, else allow
++ for (Object object : list) {
++ if (object != null) {
++ org.bukkit.event.Cancellable cancellable;
++
++ if (object instanceof EntityPlayer) {
++ cancellable = org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerInteractEvent((EntityPlayer) object, org.bukkit.event.block.Action.PHYSICAL, pos, null, null, null);
++ } else if (object instanceof Entity) {
++ cancellable = new EntityInteractEvent(((Entity) object).getBukkitEntity(), block);
++ manager.callEvent((EntityInteractEvent) cancellable);
++ } else {
++ continue;
++ }
++
++ if (!cancellable.isCancelled()) {
++ allowed = true;
++ break;
++ }
++ }
++ }
++
++ if (!allowed) {
++ return;
++ }
++ }
++ // CraftBukkit end
++
+ if (flag1 != flag)
+ {
+ iblockstate = iblockstate.withProperty(POWERED, Boolean.valueOf(flag1));
diff --git a/patches/net/minecraft/block/BlockTripWireHook.java.patch b/patches/net/minecraft/block/BlockTripWireHook.java.patch
new file mode 100644
index 00000000..a87e5089
--- /dev/null
+++ b/patches/net/minecraft/block/BlockTripWireHook.java.patch
@@ -0,0 +1,26 @@
+--- ../src-base/minecraft/net/minecraft/block/BlockTripWireHook.java
++++ ../src-work/minecraft/net/minecraft/block/BlockTripWireHook.java
+@@ -27,6 +27,7 @@
+ import net.minecraft.world.World;
+ import net.minecraftforge.fml.relauncher.Side;
+ import net.minecraftforge.fml.relauncher.SideOnly;
++import org.bukkit.event.block.BlockRedstoneEvent;
+
+ public class BlockTripWireHook extends Block
+ {
+@@ -197,6 +198,15 @@
+ this.playSound(worldIn, blockpos1, flag2, flag3, flag, flag1);
+ }
+
++ org.bukkit.block.Block block = worldIn.getWorld().getBlockAt(pos.getX(), pos.getY(), pos.getZ());
++
++ BlockRedstoneEvent eventRedstone = new BlockRedstoneEvent(block, 15, 0);
++ worldIn.getServer().getPluginManager().callEvent(eventRedstone);
++
++ if (eventRedstone.getNewCurrent() > 0) {
++ return;
++ }
++
+ this.playSound(worldIn, pos, flag2, flag3, flag, flag1);
+
+ if (!p_176260_4_)
diff --git a/patches/net/minecraft/block/BlockVine.java.patch b/patches/net/minecraft/block/BlockVine.java.patch
new file mode 100644
index 00000000..9bee4334
--- /dev/null
+++ b/patches/net/minecraft/block/BlockVine.java.patch
@@ -0,0 +1,79 @@
+--- ../src-base/minecraft/net/minecraft/block/BlockVine.java
++++ ../src-work/minecraft/net/minecraft/block/BlockVine.java
+@@ -27,6 +27,7 @@
+ import net.minecraft.world.World;
+ import net.minecraftforge.fml.relauncher.Side;
+ import net.minecraftforge.fml.relauncher.SideOnly;
++import org.bukkit.craftbukkit.event.CraftEventFactory;
+
+ public class BlockVine extends Block implements net.minecraftforge.common.IShearable
+ {
+@@ -185,7 +186,7 @@
+ {
+ if (!worldIn.isRemote)
+ {
+- if (worldIn.rand.nextInt(4) == 0 && worldIn.isAreaLoaded(pos, 4)) // Forge: check area to prevent loading unloaded chunks
++ if (worldIn.rand.nextInt(Math.max(1, (int)(100.0f / worldIn.spigotConfig.vineModifier) * 4)) == 0 && worldIn.isAreaLoaded(pos, 4)) // Forge: check area to prevent loading unloaded chunks // Spigot
+ {
+ int i = 4;
+ int j = 5;
+@@ -233,7 +234,11 @@
+
+ if (((Boolean)iblockstate2.getValue(NORTH)).booleanValue() || ((Boolean)iblockstate2.getValue(EAST)).booleanValue() || ((Boolean)iblockstate2.getValue(SOUTH)).booleanValue() || ((Boolean)iblockstate2.getValue(WEST)).booleanValue())
+ {
+- worldIn.setBlockState(blockpos2, iblockstate2, 2);
++// worldIn.setBlockState(blockpos2, iblockstate2, 2);
++ BlockPos target = blockpos2;
++ org.bukkit.block.Block source = worldIn.getWorld().getBlockAt(pos.getX(), pos.getY(), pos.getZ());
++ org.bukkit.block.Block block = worldIn.getWorld().getBlockAt(target.getX(), target.getY(), target.getZ());
++ CraftEventFactory.handleBlockSpreadEvent(block, source, this, getMetaFromState(iblockstate2));
+ }
+ }
+ else if (enumfacing1.getAxis().isHorizontal() && !((Boolean)state.getValue(getPropertyFor(enumfacing1))).booleanValue())
+@@ -253,21 +258,30 @@
+ BlockPos blockpos = blockpos4.offset(enumfacing3);
+ BlockPos blockpos1 = blockpos4.offset(enumfacing4);
+
++ org.bukkit.block.Block source = worldIn.getWorld().getBlockAt(pos.getX(), pos.getY(), pos.getZ());
++ org.bukkit.block.Block bukkitBlock = worldIn.getWorld().getBlockAt(blockpos4.getX(), blockpos4.getY(), blockpos4.getZ());
++
+ if (flag1 && this.canAttachTo(worldIn, blockpos.offset(enumfacing3), enumfacing3))
+ {
+- worldIn.setBlockState(blockpos4, this.getDefaultState().withProperty(getPropertyFor(enumfacing3), Boolean.valueOf(true)), 2);
++// worldIn.setBlockState(blockpos4, this.getDefaultState().withProperty(getPropertyFor(enumfacing3), Boolean.valueOf(true)), 2);
++ CraftEventFactory.handleBlockSpreadEvent(bukkitBlock, source, this, getMetaFromState(this.getDefaultState().withProperty(getPropertyFor(enumfacing3), true)));
+ }
+ else if (flag2 && this.canAttachTo(worldIn, blockpos1.offset(enumfacing4), enumfacing4))
+ {
+- worldIn.setBlockState(blockpos4, this.getDefaultState().withProperty(getPropertyFor(enumfacing4), Boolean.valueOf(true)), 2);
++// worldIn.setBlockState(blockpos4, this.getDefaultState().withProperty(getPropertyFor(enumfacing4), Boolean.valueOf(true)), 2);
++ CraftEventFactory.handleBlockSpreadEvent(bukkitBlock, source, this, getMetaFromState(this.getDefaultState().withProperty(getPropertyFor(enumfacing4), true)));
+ }
+ else if (flag1 && worldIn.isAirBlock(blockpos) && this.canAttachTo(worldIn, blockpos, enumfacing1))
+ {
+- worldIn.setBlockState(blockpos, this.getDefaultState().withProperty(getPropertyFor(enumfacing1.getOpposite()), Boolean.valueOf(true)), 2);
++// worldIn.setBlockState(blockpos, this.getDefaultState().withProperty(getPropertyFor(enumfacing1.getOpposite()), Boolean.valueOf(true)), 2);
++ bukkitBlock = worldIn.getWorld().getBlockAt(blockpos.getX(), blockpos.getY(), blockpos.getZ());
++ CraftEventFactory.handleBlockSpreadEvent(bukkitBlock, source, this, getMetaFromState(this.getDefaultState().withProperty(getPropertyFor(enumfacing1.getOpposite()), true)));
+ }
+ else if (flag2 && worldIn.isAirBlock(blockpos1) && this.canAttachTo(worldIn, blockpos1, enumfacing1))
+ {
+- worldIn.setBlockState(blockpos1, this.getDefaultState().withProperty(getPropertyFor(enumfacing1.getOpposite()), Boolean.valueOf(true)), 2);
++// worldIn.setBlockState(blockpos1, this.getDefaultState().withProperty(getPropertyFor(enumfacing1.getOpposite()), Boolean.valueOf(true)), 2);
++ bukkitBlock = worldIn.getWorld().getBlockAt(blockpos1.getX(), blockpos1.getY(), blockpos1.getZ());
++ CraftEventFactory.handleBlockSpreadEvent(bukkitBlock, source, this, getMetaFromState(this.getDefaultState().withProperty(getPropertyFor(enumfacing1.getOpposite()), true)));
+ }
+ }
+ else if (iblockstate3.getBlockFaceShape(worldIn, blockpos4, enumfacing1) == BlockFaceShape.SOLID)
+@@ -298,7 +312,10 @@
+
+ if (((Boolean)iblockstate1.getValue(NORTH)).booleanValue() || ((Boolean)iblockstate1.getValue(EAST)).booleanValue() || ((Boolean)iblockstate1.getValue(SOUTH)).booleanValue() || ((Boolean)iblockstate1.getValue(WEST)).booleanValue())
+ {
+- worldIn.setBlockState(blockpos3, iblockstate1, 2);
++// worldIn.setBlockState(blockpos3, iblockstate1, 2);
++ org.bukkit.block.Block source = worldIn.getWorld().getBlockAt(pos.getX(), pos.getY(), pos.getZ());
++ org.bukkit.block.Block bukkitBlock = worldIn.getWorld().getBlockAt(blockpos3.getX(), blockpos3.getY(), blockpos3.getZ());
++ CraftEventFactory.handleBlockSpreadEvent(bukkitBlock, source, this, getMetaFromState(iblockstate1));
+ }
+ }
+ else if (block == this)
diff --git a/patches/net/minecraft/client/gui/GuiIngame.java.patch b/patches/net/minecraft/client/gui/GuiIngame.java.patch
new file mode 100644
index 00000000..620abd72
--- /dev/null
+++ b/patches/net/minecraft/client/gui/GuiIngame.java.patch
@@ -0,0 +1,11 @@
+--- ../src-base/minecraft/net/minecraft/client/gui/GuiIngame.java
++++ ../src-work/minecraft/net/minecraft/client/gui/GuiIngame.java
+@@ -499,7 +499,7 @@
+ // FORGE - Move status icon check down from above so renderHUDEffect will still be called without a status icon
+ if (potion.hasStatusIcon())
+ this.drawTexturedModalRect(k + 3, l + 3, i1 % 8 * 18, 198 + i1 / 8 * 18, 18, 18);
+- potion.renderHUDEffect(potioneffect, this, k, l, this.zLevel, f);
++ potion.renderHUDEffect(k, l, potioneffect, mc, f);
+ }
+ }
+ }
diff --git a/patches/net/minecraft/client/gui/inventory/GuiContainerCreative.java.patch b/patches/net/minecraft/client/gui/inventory/GuiContainerCreative.java.patch
new file mode 100644
index 00000000..2a1c20be
--- /dev/null
+++ b/patches/net/minecraft/client/gui/inventory/GuiContainerCreative.java.patch
@@ -0,0 +1,22 @@
+--- ../src-base/minecraft/net/minecraft/client/gui/inventory/GuiContainerCreative.java
++++ ../src-work/minecraft/net/minecraft/client/gui/inventory/GuiContainerCreative.java
+@@ -40,6 +40,7 @@
+ import net.minecraft.util.text.TextFormatting;
+ import net.minecraftforge.fml.relauncher.Side;
+ import net.minecraftforge.fml.relauncher.SideOnly;
++import org.bukkit.inventory.InventoryView;
+ import org.lwjgl.input.Keyboard;
+ import org.lwjgl.input.Mouse;
+
+@@ -1042,6 +1043,11 @@
+ return this.itemList.size() > 45;
+ }
+
++ @Override
++ public InventoryView getBukkitView() {
++ return null;
++ }
++
+ public ItemStack transferStackInSlot(EntityPlayer playerIn, int index)
+ {
+ if (index >= this.inventorySlots.size() - 9 && index < this.inventorySlots.size())
diff --git a/patches/net/minecraft/client/multiplayer/WorldClient.java.patch b/patches/net/minecraft/client/multiplayer/WorldClient.java.patch
new file mode 100644
index 00000000..5abd6904
--- /dev/null
+++ b/patches/net/minecraft/client/multiplayer/WorldClient.java.patch
@@ -0,0 +1,11 @@
+--- ../src-base/minecraft/net/minecraft/client/multiplayer/WorldClient.java
++++ ../src-work/minecraft/net/minecraft/client/multiplayer/WorldClient.java
+@@ -115,7 +115,7 @@
+ return this.clientChunkProvider;
+ }
+
+- protected boolean isChunkLoaded(int x, int z, boolean allowEmpty)
++ public boolean isChunkLoaded(int x, int z, boolean allowEmpty)
+ {
+ return allowEmpty || !this.getChunkProvider().provideChunk(x, z).isEmpty();
+ }
diff --git a/patches/net/minecraft/client/renderer/InventoryEffectRenderer.java.patch b/patches/net/minecraft/client/renderer/InventoryEffectRenderer.java.patch
new file mode 100644
index 00000000..dea71d5d
--- /dev/null
+++ b/patches/net/minecraft/client/renderer/InventoryEffectRenderer.java.patch
@@ -0,0 +1,11 @@
+--- ../src-base/minecraft/net/minecraft/client/renderer/InventoryEffectRenderer.java
++++ ../src-work/minecraft/net/minecraft/client/renderer/InventoryEffectRenderer.java
+@@ -88,7 +88,7 @@
+ this.drawTexturedModalRect(i + 6, j + 7, 0 + i1 % 8 * 18, 198 + i1 / 8 * 18, 18, 18);
+ }
+
+- potion.renderInventoryEffect(potioneffect, this, i, j, this.zLevel);
++ potion.renderInventoryEffect(i, j, potioneffect, mc);
+ if (!potion.shouldRenderInvText(potioneffect)) { j += l; continue; }
+ String s1 = I18n.format(potion.getName());
+
diff --git a/patches/net/minecraft/command/CommandDebug.java.patch b/patches/net/minecraft/command/CommandDebug.java.patch
new file mode 100644
index 00000000..815946d4
--- /dev/null
+++ b/patches/net/minecraft/command/CommandDebug.java.patch
@@ -0,0 +1,25 @@
+--- ../src-base/minecraft/net/minecraft/command/CommandDebug.java
++++ ../src-work/minecraft/net/minecraft/command/CommandDebug.java
+@@ -13,6 +13,7 @@
+ import net.minecraft.profiler.Profiler;
+ import net.minecraft.server.MinecraftServer;
+ import net.minecraft.util.math.BlockPos;
++import net.minecraft.util.text.TextComponentString;
+ import org.apache.commons.io.IOUtils;
+ import org.apache.logging.log4j.LogManager;
+ import org.apache.logging.log4j.Logger;
+@@ -40,6 +41,14 @@
+
+ public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
+ {
++ // CraftBukkit start - only allow use when enabled (so that no blank profile results occur)
++ if (!server.profiler.ENABLED) {
++ sender.sendMessage(new TextComponentString("Vanilla debug profiling is disabled."));
++ sender.sendMessage(new TextComponentString("To enable, restart the server with `-DenableDebugMethodProfiler=true' before `-jar'."));
++ sender.sendMessage(new TextComponentString("Use `/timings' for plugin timings."));
++ return;
++ }
++ // CraftBukkit end
+ if (args.length < 1)
+ {
+ throw new WrongUsageException("commands.debug.usage", new Object[0]);
diff --git a/patches/net/minecraft/command/CommandExecuteAt.java.patch b/patches/net/minecraft/command/CommandExecuteAt.java.patch
new file mode 100644
index 00000000..e1ac958c
--- /dev/null
+++ b/patches/net/minecraft/command/CommandExecuteAt.java.patch
@@ -0,0 +1,34 @@
+--- ../src-base/minecraft/net/minecraft/command/CommandExecuteAt.java
++++ ../src-work/minecraft/net/minecraft/command/CommandExecuteAt.java
+@@ -7,9 +7,11 @@
+ import net.minecraft.block.state.IBlockState;
+ import net.minecraft.entity.Entity;
+ import net.minecraft.server.MinecraftServer;
++import net.minecraft.tileentity.CommandBlockBaseLogic;
+ import net.minecraft.util.math.BlockPos;
+ import net.minecraft.util.math.Vec3d;
+ import net.minecraft.world.World;
++import org.bukkit.craftbukkit.command.ProxiedNativeCommandSender;
+
+ public class CommandExecuteAt extends CommandBase
+ {
+@@ -78,7 +80,8 @@
+
+ try
+ {
+- int j = icommandmanager.executeCommand(icommandsender, s);
++ org.bukkit.command.CommandSender bukkitSender = CommandBlockBaseLogic.unwrapSender(sender);
++ int j = CommandBlockBaseLogic.executeCommand(icommandsender, new ProxiedNativeCommandSender(icommandsender, bukkitSender, entity.getBukkitEntity()), s);
+
+ if (j < 1)
+ {
+@@ -87,6 +90,9 @@
+ }
+ catch (Throwable var23)
+ {
++ if (var23 instanceof CommandException) {
++ throw (CommandException) var23;
++ }
+ throw new CommandException("commands.execute.failed", new Object[] {s, entity.getName()});
+ }
+ }
diff --git a/patches/net/minecraft/command/CommandGameMode.java.patch b/patches/net/minecraft/command/CommandGameMode.java.patch
new file mode 100644
index 00000000..044a187c
--- /dev/null
+++ b/patches/net/minecraft/command/CommandGameMode.java.patch
@@ -0,0 +1,27 @@
+--- ../src-base/minecraft/net/minecraft/command/CommandGameMode.java
++++ ../src-work/minecraft/net/minecraft/command/CommandGameMode.java
+@@ -4,9 +4,11 @@
+ import java.util.List;
+ import javax.annotation.Nullable;
+ import net.minecraft.entity.player.EntityPlayer;
++import net.minecraft.entity.player.EntityPlayerMP;
+ import net.minecraft.server.MinecraftServer;
+ import net.minecraft.util.math.BlockPos;
+ import net.minecraft.util.text.ITextComponent;
++import net.minecraft.util.text.TextComponentString;
+ import net.minecraft.util.text.TextComponentTranslation;
+ import net.minecraft.world.GameType;
+ import net.minecraft.world.WorldSettings;
+@@ -39,6 +41,12 @@
+ GameType gametype = this.getGameModeFromCommand(sender, args[0]);
+ EntityPlayer entityplayer = args.length >= 2 ? getPlayer(server, sender, args[1]) : getCommandSenderAsPlayer(sender);
+ entityplayer.setGameType(gametype);
++ // CraftBukkit start - handle event cancelling the change
++ if (((EntityPlayerMP) entityplayer).interactionManager.getGameType() != gametype) {
++ sender.sendMessage(new TextComponentString("Failed to set the gamemode of '" + entityplayer.getName() + "'"));
++ return;
++ }
++ // CraftBukkit end
+ ITextComponent itextcomponent = new TextComponentTranslation("gameMode." + gametype.getName(), new Object[0]);
+
+ if (sender.getEntityWorld().getGameRules().getBoolean("sendCommandFeedback"))
diff --git a/patches/net/minecraft/command/CommandGameRule.java.patch b/patches/net/minecraft/command/CommandGameRule.java.patch
new file mode 100644
index 00000000..6245e46b
--- /dev/null
+++ b/patches/net/minecraft/command/CommandGameRule.java.patch
@@ -0,0 +1,11 @@
+--- ../src-base/minecraft/net/minecraft/command/CommandGameRule.java
++++ ../src-work/minecraft/net/minecraft/command/CommandGameRule.java
+@@ -29,7 +29,7 @@
+
+ public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
+ {
+- GameRules gamerules = this.getOverWorldGameRules(server);
++ GameRules gamerules = sender.getEntityWorld().getGameRules(); // CraftBukkit - Use current world
+ String s = args.length > 0 ? args[0] : "";
+ String s1 = args.length > 1 ? buildString(args, 1) : "";
+
diff --git a/patches/net/minecraft/command/CommandHandler.java.patch b/patches/net/minecraft/command/CommandHandler.java.patch
new file mode 100644
index 00000000..c993cb64
--- /dev/null
+++ b/patches/net/minecraft/command/CommandHandler.java.patch
@@ -0,0 +1,94 @@
+--- ../src-base/minecraft/net/minecraft/command/CommandHandler.java
++++ ../src-work/minecraft/net/minecraft/command/CommandHandler.java
+@@ -3,12 +3,6 @@
+ import com.google.common.collect.Lists;
+ import com.google.common.collect.Maps;
+ import com.google.common.collect.Sets;
+-import java.util.Collections;
+-import java.util.List;
+-import java.util.Map;
+-import java.util.Set;
+-import java.util.Map.Entry;
+-import javax.annotation.Nullable;
+ import net.minecraft.entity.Entity;
+ import net.minecraft.server.MinecraftServer;
+ import net.minecraft.util.math.BlockPos;
+@@ -16,7 +10,16 @@
+ import net.minecraft.util.text.TextFormatting;
+ import org.apache.logging.log4j.LogManager;
+ import org.apache.logging.log4j.Logger;
++import org.bukkit.craftbukkit.command.CraftSimpleCommandMap;
++import org.bukkit.craftbukkit.command.ModCustomCommand;
+
++import javax.annotation.Nullable;
++import java.util.Collections;
++import java.util.List;
++import java.util.Map;
++import java.util.Map.Entry;
++import java.util.Set;
++
+ public abstract class CommandHandler implements ICommandManager
+ {
+ private static final Logger LOGGER = LogManager.getLogger();
+@@ -27,10 +30,10 @@
+ {
+ rawCommand = rawCommand.trim();
+
+- if (rawCommand.startsWith("/"))
+- {
+- rawCommand = rawCommand.substring(1);
+- }
++// if (rawCommand.startsWith("/"))
++// {
++// rawCommand = rawCommand.substring(1);
++// }
+
+ String[] astring = rawCommand.split(" ");
+ String s = astring[0];
+@@ -144,9 +147,8 @@
+
+ protected abstract MinecraftServer getServer();
+
+- public ICommand registerCommand(ICommand command)
+- {
+- this.commandMap.put(command.getName(), command);
++ public ICommand registerCommand(ICommand command) {
++ /*this.commandMap.put(command.getName(), command);
+ this.commandSet.add(command);
+
+ for (String s : command.getAliases())
+@@ -159,6 +161,34 @@
+ }
+ }
+
++ return command;*/
++ // register commands with permission nodes, defaulting to class name
++ return registerCommand(command, command.getClass().getName());
++ }
++
++ private ICommand registerCommand(String permissionGroup, ICommand command) {
++ return registerCommand(command, permissionGroup + "." + command.getName());
++ }
++
++ public ICommand registerCommand(ICommand command, String permissionNode) {
++ this.commandMap.put(command.getName(), command);
++ this.commandSet.add(command);
++ // register vanilla commands with Bukkit to support permissions.
++ CraftSimpleCommandMap commandMap = MinecraftServer.getServerCB().server.getCraftCommandMap();
++ ModCustomCommand customCommand = new ModCustomCommand(command.getName());
++ customCommand.setPermission(permissionNode);
++ List list = command.getAliases();
++ if (list != null) customCommand.setAliases(list);
++ commandMap.register(command.getName(), customCommand);
++ LogManager.getLogger().info("Registered command " + command.getName() + " with permission node " + permissionNode);
++ if (list != null) {
++ for (String s : list) {
++ ICommand icommand = (ICommand)this.commandMap.get(s);
++ if (icommand == null || !icommand.getName().equals(s)) {
++ this.commandMap.put(s, command);
++ }
++ }
++ }
+ return command;
+ }
+
diff --git a/patches/net/minecraft/command/CommandSenderWrapper.java.patch b/patches/net/minecraft/command/CommandSenderWrapper.java.patch
new file mode 100644
index 00000000..c93a7e65
--- /dev/null
+++ b/patches/net/minecraft/command/CommandSenderWrapper.java.patch
@@ -0,0 +1,11 @@
+--- ../src-base/minecraft/net/minecraft/command/CommandSenderWrapper.java
++++ ../src-work/minecraft/net/minecraft/command/CommandSenderWrapper.java
+@@ -11,7 +11,7 @@
+
+ public class CommandSenderWrapper implements ICommandSender
+ {
+- private final ICommandSender delegate;
++ public final ICommandSender delegate;
+ @Nullable
+ private final Vec3d positionVector;
+ @Nullable
diff --git a/patches/net/minecraft/command/CommandSpreadPlayers.java.patch b/patches/net/minecraft/command/CommandSpreadPlayers.java.patch
new file mode 100644
index 00000000..86a7896f
--- /dev/null
+++ b/patches/net/minecraft/command/CommandSpreadPlayers.java.patch
@@ -0,0 +1,49 @@
+--- ../src-base/minecraft/net/minecraft/command/CommandSpreadPlayers.java
++++ ../src-work/minecraft/net/minecraft/command/CommandSpreadPlayers.java
+@@ -10,6 +10,7 @@
+ import java.util.Set;
+ import javax.annotation.Nullable;
+ import net.minecraft.block.material.Material;
++import net.minecraft.block.state.IBlockState;
+ import net.minecraft.entity.Entity;
+ import net.minecraft.entity.player.EntityPlayer;
+ import net.minecraft.scoreboard.Team;
+@@ -18,6 +19,7 @@
+ import net.minecraft.util.math.MathHelper;
+ import net.minecraft.util.text.TextComponentTranslation;
+ import net.minecraft.world.World;
++import net.minecraft.world.gen.ChunkProviderServer;
+
+ public class CommandSpreadPlayers extends CommandBase
+ {
+@@ -356,7 +358,7 @@
+ {
+ blockpos = blockpos.down();
+
+- if (worldIn.getBlockState(blockpos).getMaterial() != Material.AIR)
++ if (getBlockState(worldIn, blockpos).getMaterial() != Material.AIR)
+ {
+ return blockpos.getY() + 1;
+ }
+@@ -372,7 +374,7 @@
+ while (blockpos.getY() > 0)
+ {
+ blockpos = blockpos.down();
+- Material material = worldIn.getBlockState(blockpos).getMaterial();
++ Material material = getBlockState(worldIn, blockpos).getMaterial();
+
+ if (material != Material.AIR)
+ {
+@@ -388,5 +390,12 @@
+ this.x = MathHelper.nextDouble(rand, p_111097_2_, p_111097_6_);
+ this.z = MathHelper.nextDouble(rand, p_111097_4_, p_111097_8_);
+ }
++
++ // CraftBukkit start - add a version of getBlockState which force loads chunks
++ private static IBlockState getBlockState(World world, BlockPos position) {
++ ((ChunkProviderServer) world.getChunkProvider()).loadChunk(position.getX() >> 4, position.getZ() >> 4);
++ return world.getBlockState(position);
++ }
++ // CraftBukkit end
+ }
+ }
diff --git a/patches/net/minecraft/command/CommandTP.java.patch b/patches/net/minecraft/command/CommandTP.java.patch
new file mode 100644
index 00000000..4faa0ab2
--- /dev/null
+++ b/patches/net/minecraft/command/CommandTP.java.patch
@@ -0,0 +1,42 @@
+--- ../src-base/minecraft/net/minecraft/command/CommandTP.java
++++ ../src-work/minecraft/net/minecraft/command/CommandTP.java
+@@ -74,25 +74,12 @@
+ {
+ Entity entity1 = getEntity(server, sender, args[args.length - 1]);
+
+- if (entity1.world != entity.world)
+- {
+- throw new CommandException("commands.tp.notSameDimension", new Object[0]);
++ // CraftBukkit Start
++ // Use Bukkit teleport method in all cases. It has cross dimensional handling, events
++ if (entity.getBukkitEntity().teleport(entity.getBukkitEntity(), org.bukkit.event.player.PlayerTeleportEvent.TeleportCause.COMMAND)) {
++ notifyCommandListener(sender, (ICommand) this, "commands.tp.success", new Object[] { entity.getName(), entity.getName()});
++ // CraftBukkit End
+ }
+- else
+- {
+- entity.dismountRidingEntity();
+-
+- if (entity instanceof EntityPlayerMP)
+- {
+- ((EntityPlayerMP)entity).connection.setPlayerLocation(entity1.posX, entity1.posY, entity1.posZ, entity1.rotationYaw, entity1.rotationPitch);
+- }
+- else
+- {
+- entity.setLocationAndAngles(entity1.posX, entity1.posY, entity1.posZ, entity1.rotationYaw, entity1.rotationPitch);
+- }
+-
+- notifyCommandListener(sender, this, "commands.tp.success", new Object[] {entity.getName(), entity1.getName()});
+- }
+ }
+ }
+ }
+@@ -143,7 +130,7 @@
+ }
+
+ teleportingEntity.dismountRidingEntity();
+- ((EntityPlayerMP)teleportingEntity).connection.setPlayerLocation(argX.getAmount(), argY.getAmount(), argZ.getAmount(), f, f1, set);
++ ((EntityPlayerMP)teleportingEntity).connection.setPlayerLocation(argX.getAmount(), argY.getAmount(), argZ.getAmount(), f, f1, set, org.bukkit.event.player.PlayerTeleportEvent.TeleportCause.COMMAND);
+ teleportingEntity.setRotationYawHead(f);
+ }
+ else
diff --git a/patches/net/minecraft/command/FunctionObject.java.patch b/patches/net/minecraft/command/FunctionObject.java.patch
new file mode 100644
index 00000000..fd0e6fa6
--- /dev/null
+++ b/patches/net/minecraft/command/FunctionObject.java.patch
@@ -0,0 +1,26 @@
+--- ../src-base/minecraft/net/minecraft/command/FunctionObject.java
++++ ../src-work/minecraft/net/minecraft/command/FunctionObject.java
+@@ -5,6 +5,7 @@
+ import java.util.List;
+ import javax.annotation.Nullable;
+ import net.minecraft.advancements.FunctionManager;
++import net.minecraft.tileentity.CommandBlockBaseLogic;
+ import net.minecraft.util.ResourceLocation;
+
+ public class FunctionObject
+@@ -108,7 +109,14 @@
+
+ public void execute(FunctionManager functionManagerIn, ICommandSender sender, ArrayDeque commandQueue, int maxCommandChainLength)
+ {
+- functionManagerIn.getCommandManager().executeCommand(sender, this.command);
++// functionManagerIn.getCommandManager().executeCommand(sender, this.command);
++ org.bukkit.command.CommandSender bukkitSender;
++ if (sender instanceof FunctionManager.CustomFunctionListener) {
++ bukkitSender = ((FunctionManager.CustomFunctionListener) sender).sender;
++ } else {
++ bukkitSender = CommandBlockBaseLogic.unwrapSender(sender);
++ }
++ CommandBlockBaseLogic.executeSafely(sender, bukkitSender, this.command);
+ }
+
+ public String toString()
diff --git a/patches/net/minecraft/command/ICommandManager.java.patch b/patches/net/minecraft/command/ICommandManager.java.patch
new file mode 100644
index 00000000..8a25c1ba
--- /dev/null
+++ b/patches/net/minecraft/command/ICommandManager.java.patch
@@ -0,0 +1,9 @@
+--- ../src-base/minecraft/net/minecraft/command/ICommandManager.java
++++ ../src-work/minecraft/net/minecraft/command/ICommandManager.java
+@@ -14,4 +14,6 @@
+ List getPossibleCommands(ICommandSender sender);
+
+ Map getCommands();
++
++
+ }
diff --git a/patches/net/minecraft/command/ServerCommandManager.java.patch b/patches/net/minecraft/command/ServerCommandManager.java.patch
new file mode 100644
index 00000000..e7a5f747
--- /dev/null
+++ b/patches/net/minecraft/command/ServerCommandManager.java.patch
@@ -0,0 +1,32 @@
+--- ../src-base/minecraft/net/minecraft/command/ServerCommandManager.java
++++ ../src-work/minecraft/net/minecraft/command/ServerCommandManager.java
+@@ -40,6 +40,10 @@
+ public ServerCommandManager(MinecraftServer serverIn)
+ {
+ this.server = serverIn;
++ CommandBase.setCommandListener(this);
++ }
++
++ public void registerVanillaCommands() {
+ this.registerCommand(new CommandTime());
+ this.registerCommand(new CommandGameMode());
+ this.registerCommand(new CommandDifficulty());
+@@ -89,8 +93,7 @@
+ this.registerCommand(new CommandLocate());
+ this.registerCommand(new CommandReload());
+ this.registerCommand(new CommandFunction());
+-
+- if (serverIn.isDedicatedServer())
++ if (server.isDedicatedServer())
+ {
+ this.registerCommand(new CommandOp());
+ this.registerCommand(new CommandDeOp());
+@@ -147,7 +150,7 @@
+ }
+ }
+
+- if (sender != minecraftserver && minecraftserver.worlds[0].getGameRules().getBoolean("logAdminCommands"))
++ if (sender != minecraftserver && minecraftserver.worlds[0].getGameRules().getBoolean("logAdminCommands") && !org.spigotmc.SpigotConfig.silentCommandBlocks) // Spigot
+ {
+ minecraftserver.sendMessage(itextcomponent);
+ }
diff --git a/patches/net/minecraft/command/server/CommandTeleport.java.patch b/patches/net/minecraft/command/server/CommandTeleport.java.patch
new file mode 100644
index 00000000..79fc2e0b
--- /dev/null
+++ b/patches/net/minecraft/command/server/CommandTeleport.java.patch
@@ -0,0 +1,11 @@
+--- ../src-base/minecraft/net/minecraft/command/server/CommandTeleport.java
++++ ../src-work/minecraft/net/minecraft/command/server/CommandTeleport.java
+@@ -91,7 +91,7 @@
+ }
+
+ teleportingEntity.dismountRidingEntity();
+- ((EntityPlayerMP)teleportingEntity).connection.setPlayerLocation(argX.getResult(), argY.getResult(), argZ.getResult(), f, f1, set);
++ ((EntityPlayerMP)teleportingEntity).connection.setPlayerLocation(argX.getResult(), argY.getResult(), argZ.getResult(), f, f1, set, org.bukkit.event.player.PlayerTeleportEvent.TeleportCause.COMMAND);
+ teleportingEntity.setRotationYawHead(f);
+ }
+ else
diff --git a/patches/net/minecraft/dispenser/BehaviorDefaultDispenseItem.java.patch b/patches/net/minecraft/dispenser/BehaviorDefaultDispenseItem.java.patch
new file mode 100644
index 00000000..1c45a202
--- /dev/null
+++ b/patches/net/minecraft/dispenser/BehaviorDefaultDispenseItem.java.patch
@@ -0,0 +1,88 @@
+--- ../src-base/minecraft/net/minecraft/dispenser/BehaviorDefaultDispenseItem.java
++++ ../src-work/minecraft/net/minecraft/dispenser/BehaviorDefaultDispenseItem.java
+@@ -5,6 +5,8 @@
+ import net.minecraft.item.ItemStack;
+ import net.minecraft.util.EnumFacing;
+ import net.minecraft.world.World;
++import org.bukkit.craftbukkit.inventory.CraftItemStack;
++import org.bukkit.event.block.BlockDispenseEvent;
+
+ public class BehaviorDefaultDispenseItem implements IBehaviorDispenseItem
+ {
+@@ -21,7 +23,11 @@
+ EnumFacing enumfacing = (EnumFacing)source.getBlockState().getValue(BlockDispenser.FACING);
+ IPosition iposition = BlockDispenser.getDispensePosition(source);
+ ItemStack itemstack = stack.splitStack(1);
+- doDispense(source.getWorld(), itemstack, 6, enumfacing, iposition);
++ // CraftBukkit start
++ if (!doDispense(source.getWorld(), itemstack, 6, enumfacing, source)) {
++ itemstack.grow(1);
++ }
++ // CraftBukkit end
+ return stack;
+ }
+
+@@ -51,6 +57,63 @@
+ worldIn.spawnEntity(entityitem);
+ }
+
++ // CraftBukkit start - void -> boolean return, IPosition -> ISourceBlock last argument
++ public static boolean doDispense(World worldIn, ItemStack stack, int speed, EnumFacing facing, IBlockSource source)
++ {
++ IPosition position = BlockDispenser.getDispensePosition(source);
++ double d0 = position.getX();
++ double d1 = position.getY();
++ double d2 = position.getZ();
++
++ if (facing.getAxis() == EnumFacing.Axis.Y)
++ {
++ d1 = d1 - 0.125D;
++ }
++ else
++ {
++ d1 = d1 - 0.15625D;
++ }
++
++ EntityItem entityitem = new EntityItem(worldIn, d0, d1, d2, stack);
++ double d3 = worldIn.rand.nextDouble() * 0.1D + 0.2D;
++ entityitem.motionX = (double)facing.getFrontOffsetX() * d3;
++ entityitem.motionY = 0.20000000298023224D;
++ entityitem.motionZ = (double)facing.getFrontOffsetZ() * d3;
++ entityitem.motionX += worldIn.rand.nextGaussian() * 0.007499999832361937D * (double)speed;
++ entityitem.motionY += worldIn.rand.nextGaussian() * 0.007499999832361937D * (double)speed;
++ entityitem.motionZ += worldIn.rand.nextGaussian() * 0.007499999832361937D * (double)speed;
++
++ org.bukkit.block.Block block = worldIn.getWorld().getBlockAt(source.getBlockPos().getX(), source.getBlockPos().getY(), source.getBlockPos().getZ());
++ CraftItemStack craftItem = CraftItemStack.asCraftMirror(stack);
++
++ BlockDispenseEvent event = new BlockDispenseEvent(block, craftItem.clone(), new org.bukkit.util.Vector(entityitem.motionX, entityitem.motionY, entityitem.motionZ));
++ worldIn.getServer().getPluginManager().callEvent(event);
++
++ if (event.isCancelled()) {
++ return false;
++ }
++
++ entityitem.setItem(CraftItemStack.asNMSCopy(event.getItem()));
++ entityitem.motionX = event.getVelocity().getX();
++ entityitem.motionY = event.getVelocity().getY();
++ entityitem.motionZ = event.getVelocity().getZ();
++
++ if (!event.getItem().getType().equals(craftItem.getType())) {
++ // Chain to handler for new item
++ ItemStack eventStack = CraftItemStack.asNMSCopy(event.getItem());
++ IBehaviorDispenseItem idispensebehavior = BlockDispenser.DISPENSE_BEHAVIOR_REGISTRY.getObject(eventStack.getItem());
++ if (idispensebehavior != IBehaviorDispenseItem.DEFAULT_BEHAVIOR && idispensebehavior.getClass() != BehaviorDefaultDispenseItem.class) {
++ idispensebehavior.dispense(source, eventStack);
++ } else {
++ worldIn.spawnEntity(entityitem);
++ }
++ return false;
++ }
++ worldIn.spawnEntity(entityitem);
++ return true;
++ }
++ // CraftBukkit end
++
+ protected void playDispenseSound(IBlockSource source)
+ {
+ source.getWorld().playEvent(1000, source.getBlockPos(), 0);
diff --git a/patches/net/minecraft/dispenser/BehaviorProjectileDispense.java.patch b/patches/net/minecraft/dispenser/BehaviorProjectileDispense.java.patch
new file mode 100644
index 00000000..3b598c33
--- /dev/null
+++ b/patches/net/minecraft/dispenser/BehaviorProjectileDispense.java.patch
@@ -0,0 +1,50 @@
+--- ../src-base/minecraft/net/minecraft/dispenser/BehaviorProjectileDispense.java
++++ ../src-work/minecraft/net/minecraft/dispenser/BehaviorProjectileDispense.java
+@@ -6,6 +6,8 @@
+ import net.minecraft.item.ItemStack;
+ import net.minecraft.util.EnumFacing;
+ import net.minecraft.world.World;
++import org.bukkit.craftbukkit.inventory.CraftItemStack;
++import org.bukkit.event.block.BlockDispenseEvent;
+
+ public abstract class BehaviorProjectileDispense extends BehaviorDefaultDispenseItem
+ {
+@@ -15,9 +17,36 @@
+ IPosition iposition = BlockDispenser.getDispensePosition(source);
+ EnumFacing enumfacing = (EnumFacing)source.getBlockState().getValue(BlockDispenser.FACING);
+ IProjectile iprojectile = this.getProjectileEntity(world, iposition, stack);
+- iprojectile.shoot((double)enumfacing.getFrontOffsetX(), (double)((float)enumfacing.getFrontOffsetY() + 0.1F), (double)enumfacing.getFrontOffsetZ(), this.getProjectileVelocity(), this.getProjectileInaccuracy());
++// iprojectile.shoot((double)enumfacing.getFrontOffsetX(), (double)((float)enumfacing.getFrontOffsetY() + 0.1F), (double)enumfacing.getFrontOffsetZ(), this.getProjectileVelocity(), this.getProjectileInaccuracy());
++ // CraftBukkit start
++ ItemStack itemstack1 = stack.splitStack(1);
++ org.bukkit.block.Block block = world.getWorld().getBlockAt(source.getBlockPos().getX(), source.getBlockPos().getY(), source.getBlockPos().getZ());
++ CraftItemStack craftItem = CraftItemStack.asCraftMirror(itemstack1);
++
++ BlockDispenseEvent event = new BlockDispenseEvent(block, craftItem.clone(), new org.bukkit.util.Vector((double) enumfacing.getFrontOffsetX(), (double) ((float) enumfacing.getFrontOffsetY() + 0.1F), (double) enumfacing.getFrontOffsetZ()));
++ world.getServer().getPluginManager().callEvent(event);
++
++ if (event.isCancelled()) {
++ stack.grow(1);
++ return stack;
++ }
++
++ if (!event.getItem().equals(craftItem)) {
++ stack.grow(1);
++ // Chain to handler for new item
++ ItemStack eventStack = CraftItemStack.asNMSCopy(event.getItem());
++ IBehaviorDispenseItem idispensebehavior = BlockDispenser.DISPENSE_BEHAVIOR_REGISTRY.getObject(eventStack.getItem());
++ if (idispensebehavior != IBehaviorDispenseItem.DEFAULT_BEHAVIOR && idispensebehavior != this) {
++ idispensebehavior.dispense(source, eventStack);
++ return stack;
++ }
++ }
++
++ iprojectile.shoot(event.getVelocity().getX(), event.getVelocity().getY(), event.getVelocity().getZ(), this.getProjectileVelocity(), this.getProjectileInaccuracy());
++ ((Entity) iprojectile).projectileSource = new org.bukkit.craftbukkit.projectiles.CraftBlockProjectileSource(source.getBlockTileEntity());
++ // CraftBukkit end
+ world.spawnEntity((Entity)iprojectile);
+- stack.shrink(1);
++// stack.shrink(1); // CraftBukkit - Handled during event processing
+ return stack;
+ }
+
diff --git a/patches/net/minecraft/enchantment/Enchantment.java.patch b/patches/net/minecraft/enchantment/Enchantment.java.patch
new file mode 100644
index 00000000..564efa1c
--- /dev/null
+++ b/patches/net/minecraft/enchantment/Enchantment.java.patch
@@ -0,0 +1,69 @@
+--- ../src-base/minecraft/net/minecraft/enchantment/Enchantment.java
++++ ../src-work/minecraft/net/minecraft/enchantment/Enchantment.java
+@@ -178,36 +178,36 @@
+ public static void registerEnchantments()
+ {
+ EntityEquipmentSlot[] aentityequipmentslot = new EntityEquipmentSlot[] {EntityEquipmentSlot.HEAD, EntityEquipmentSlot.CHEST, EntityEquipmentSlot.LEGS, EntityEquipmentSlot.FEET};
+- REGISTRY.register(0, new ResourceLocation("protection"), new EnchantmentProtection(Enchantment.Rarity.COMMON, EnchantmentProtection.Type.ALL, aentityequipmentslot));
+- REGISTRY.register(1, new ResourceLocation("fire_protection"), new EnchantmentProtection(Enchantment.Rarity.UNCOMMON, EnchantmentProtection.Type.FIRE, aentityequipmentslot));
+- REGISTRY.register(2, new ResourceLocation("feather_falling"), new EnchantmentProtection(Enchantment.Rarity.UNCOMMON, EnchantmentProtection.Type.FALL, aentityequipmentslot));
+- REGISTRY.register(3, new ResourceLocation("blast_protection"), new EnchantmentProtection(Enchantment.Rarity.RARE, EnchantmentProtection.Type.EXPLOSION, aentityequipmentslot));
+- REGISTRY.register(4, new ResourceLocation("projectile_protection"), new EnchantmentProtection(Enchantment.Rarity.UNCOMMON, EnchantmentProtection.Type.PROJECTILE, aentityequipmentslot));
+- REGISTRY.register(5, new ResourceLocation("respiration"), new EnchantmentOxygen(Enchantment.Rarity.RARE, aentityequipmentslot));
+- REGISTRY.register(6, new ResourceLocation("aqua_affinity"), new EnchantmentWaterWorker(Enchantment.Rarity.RARE, aentityequipmentslot));
+- REGISTRY.register(7, new ResourceLocation("thorns"), new EnchantmentThorns(Enchantment.Rarity.VERY_RARE, aentityequipmentslot));
+- REGISTRY.register(8, new ResourceLocation("depth_strider"), new EnchantmentWaterWalker(Enchantment.Rarity.RARE, aentityequipmentslot));
+- REGISTRY.register(9, new ResourceLocation("frost_walker"), new EnchantmentFrostWalker(Enchantment.Rarity.RARE, new EntityEquipmentSlot[] {EntityEquipmentSlot.FEET}));
+- REGISTRY.register(10, new ResourceLocation("binding_curse"), new EnchantmentBindingCurse(Enchantment.Rarity.VERY_RARE, aentityequipmentslot));
+- REGISTRY.register(16, new ResourceLocation("sharpness"), new EnchantmentDamage(Enchantment.Rarity.COMMON, 0, new EntityEquipmentSlot[] {EntityEquipmentSlot.MAINHAND}));
+- REGISTRY.register(17, new ResourceLocation("smite"), new EnchantmentDamage(Enchantment.Rarity.UNCOMMON, 1, new EntityEquipmentSlot[] {EntityEquipmentSlot.MAINHAND}));
+- REGISTRY.register(18, new ResourceLocation("bane_of_arthropods"), new EnchantmentDamage(Enchantment.Rarity.UNCOMMON, 2, new EntityEquipmentSlot[] {EntityEquipmentSlot.MAINHAND}));
+- REGISTRY.register(19, new ResourceLocation("knockback"), new EnchantmentKnockback(Enchantment.Rarity.UNCOMMON, new EntityEquipmentSlot[] {EntityEquipmentSlot.MAINHAND}));
+- REGISTRY.register(20, new ResourceLocation("fire_aspect"), new EnchantmentFireAspect(Enchantment.Rarity.RARE, new EntityEquipmentSlot[] {EntityEquipmentSlot.MAINHAND}));
+- REGISTRY.register(21, new ResourceLocation("looting"), new EnchantmentLootBonus(Enchantment.Rarity.RARE, EnumEnchantmentType.WEAPON, new EntityEquipmentSlot[] {EntityEquipmentSlot.MAINHAND}));
+- REGISTRY.register(22, new ResourceLocation("sweeping"), new EnchantmentSweepingEdge(Enchantment.Rarity.RARE, new EntityEquipmentSlot[] {EntityEquipmentSlot.MAINHAND}));
+- REGISTRY.register(32, new ResourceLocation("efficiency"), new EnchantmentDigging(Enchantment.Rarity.COMMON, new EntityEquipmentSlot[] {EntityEquipmentSlot.MAINHAND}));
+- REGISTRY.register(33, new ResourceLocation("silk_touch"), new EnchantmentUntouching(Enchantment.Rarity.VERY_RARE, new EntityEquipmentSlot[] {EntityEquipmentSlot.MAINHAND}));
+- REGISTRY.register(34, new ResourceLocation("unbreaking"), new EnchantmentDurability(Enchantment.Rarity.UNCOMMON, new EntityEquipmentSlot[] {EntityEquipmentSlot.MAINHAND}));
+- REGISTRY.register(35, new ResourceLocation("fortune"), new EnchantmentLootBonus(Enchantment.Rarity.RARE, EnumEnchantmentType.DIGGER, new EntityEquipmentSlot[] {EntityEquipmentSlot.MAINHAND}));
+- REGISTRY.register(48, new ResourceLocation("power"), new EnchantmentArrowDamage(Enchantment.Rarity.COMMON, new EntityEquipmentSlot[] {EntityEquipmentSlot.MAINHAND}));
+- REGISTRY.register(49, new ResourceLocation("punch"), new EnchantmentArrowKnockback(Enchantment.Rarity.RARE, new EntityEquipmentSlot[] {EntityEquipmentSlot.MAINHAND}));
+- REGISTRY.register(50, new ResourceLocation("flame"), new EnchantmentArrowFire(Enchantment.Rarity.RARE, new EntityEquipmentSlot[] {EntityEquipmentSlot.MAINHAND}));
+- REGISTRY.register(51, new ResourceLocation("infinity"), new EnchantmentArrowInfinite(Enchantment.Rarity.VERY_RARE, new EntityEquipmentSlot[] {EntityEquipmentSlot.MAINHAND}));
+- REGISTRY.register(61, new ResourceLocation("luck_of_the_sea"), new EnchantmentLootBonus(Enchantment.Rarity.RARE, EnumEnchantmentType.FISHING_ROD, new EntityEquipmentSlot[] {EntityEquipmentSlot.MAINHAND}));
+- REGISTRY.register(62, new ResourceLocation("lure"), new EnchantmentFishingSpeed(Enchantment.Rarity.RARE, EnumEnchantmentType.FISHING_ROD, new EntityEquipmentSlot[] {EntityEquipmentSlot.MAINHAND}));
+- REGISTRY.register(70, new ResourceLocation("mending"), new EnchantmentMending(Enchantment.Rarity.RARE, EntityEquipmentSlot.values()));
+- REGISTRY.register(71, new ResourceLocation("vanishing_curse"), new EnchantmentVanishingCurse(Enchantment.Rarity.VERY_RARE, EntityEquipmentSlot.values()));
++ REGISTRY.register(0, new ResourceLocation("protection"), new EnchantmentProtection(Rarity.COMMON, EnchantmentProtection.Type.ALL, aentityequipmentslot));
++ REGISTRY.register(1, new ResourceLocation("fire_protection"), new EnchantmentProtection(Rarity.UNCOMMON, EnchantmentProtection.Type.FIRE, aentityequipmentslot));
++ REGISTRY.register(2, new ResourceLocation("feather_falling"), new EnchantmentProtection(Rarity.UNCOMMON, EnchantmentProtection.Type.FALL, aentityequipmentslot));
++ REGISTRY.register(3, new ResourceLocation("blast_protection"), new EnchantmentProtection(Rarity.RARE, EnchantmentProtection.Type.EXPLOSION, aentityequipmentslot));
++ REGISTRY.register(4, new ResourceLocation("projectile_protection"), new EnchantmentProtection(Rarity.UNCOMMON, EnchantmentProtection.Type.PROJECTILE, aentityequipmentslot));
++ REGISTRY.register(5, new ResourceLocation("respiration"), new EnchantmentOxygen(Rarity.RARE, aentityequipmentslot));
++ REGISTRY.register(6, new ResourceLocation("aqua_affinity"), new EnchantmentWaterWorker(Rarity.RARE, aentityequipmentslot));
++ REGISTRY.register(7, new ResourceLocation("thorns"), new EnchantmentThorns(Rarity.VERY_RARE, aentityequipmentslot));
++ REGISTRY.register(8, new ResourceLocation("depth_strider"), new EnchantmentWaterWalker(Rarity.RARE, aentityequipmentslot));
++ REGISTRY.register(9, new ResourceLocation("frost_walker"), new EnchantmentFrostWalker(Rarity.RARE, new EntityEquipmentSlot[] {EntityEquipmentSlot.FEET}));
++ REGISTRY.register(10, new ResourceLocation("binding_curse"), new EnchantmentBindingCurse(Rarity.VERY_RARE, aentityequipmentslot));
++ REGISTRY.register(16, new ResourceLocation("sharpness"), new EnchantmentDamage(Rarity.COMMON, 0, new EntityEquipmentSlot[] {EntityEquipmentSlot.MAINHAND}));
++ REGISTRY.register(17, new ResourceLocation("smite"), new EnchantmentDamage(Rarity.UNCOMMON, 1, new EntityEquipmentSlot[] {EntityEquipmentSlot.MAINHAND}));
++ REGISTRY.register(18, new ResourceLocation("bane_of_arthropods"), new EnchantmentDamage(Rarity.UNCOMMON, 2, new EntityEquipmentSlot[] {EntityEquipmentSlot.MAINHAND}));
++ REGISTRY.register(19, new ResourceLocation("knockback"), new EnchantmentKnockback(Rarity.UNCOMMON, new EntityEquipmentSlot[] {EntityEquipmentSlot.MAINHAND}));
++ REGISTRY.register(20, new ResourceLocation("fire_aspect"), new EnchantmentFireAspect(Rarity.RARE, new EntityEquipmentSlot[] {EntityEquipmentSlot.MAINHAND}));
++ REGISTRY.register(21, new ResourceLocation("looting"), new EnchantmentLootBonus(Rarity.RARE, EnumEnchantmentType.WEAPON, new EntityEquipmentSlot[] {EntityEquipmentSlot.MAINHAND}));
++ REGISTRY.register(22, new ResourceLocation("sweeping"), new EnchantmentSweepingEdge(Rarity.RARE, new EntityEquipmentSlot[] {EntityEquipmentSlot.MAINHAND}));
++ REGISTRY.register(32, new ResourceLocation("efficiency"), new EnchantmentDigging(Rarity.COMMON, new EntityEquipmentSlot[] {EntityEquipmentSlot.MAINHAND}));
++ REGISTRY.register(33, new ResourceLocation("silk_touch"), new EnchantmentUntouching(Rarity.VERY_RARE, new EntityEquipmentSlot[] {EntityEquipmentSlot.MAINHAND}));
++ REGISTRY.register(34, new ResourceLocation("unbreaking"), new EnchantmentDurability(Rarity.UNCOMMON, new EntityEquipmentSlot[] {EntityEquipmentSlot.MAINHAND}));
++ REGISTRY.register(35, new ResourceLocation("fortune"), new EnchantmentLootBonus(Rarity.RARE, EnumEnchantmentType.DIGGER, new EntityEquipmentSlot[] {EntityEquipmentSlot.MAINHAND}));
++ REGISTRY.register(48, new ResourceLocation("power"), new EnchantmentArrowDamage(Rarity.COMMON, new EntityEquipmentSlot[] {EntityEquipmentSlot.MAINHAND}));
++ REGISTRY.register(49, new ResourceLocation("punch"), new EnchantmentArrowKnockback(Rarity.RARE, new EntityEquipmentSlot[] {EntityEquipmentSlot.MAINHAND}));
++ REGISTRY.register(50, new ResourceLocation("flame"), new EnchantmentArrowFire(Rarity.RARE, new EntityEquipmentSlot[] {EntityEquipmentSlot.MAINHAND}));
++ REGISTRY.register(51, new ResourceLocation("infinity"), new EnchantmentArrowInfinite(Rarity.VERY_RARE, new EntityEquipmentSlot[] {EntityEquipmentSlot.MAINHAND}));
++ REGISTRY.register(61, new ResourceLocation("luck_of_the_sea"), new EnchantmentLootBonus(Rarity.RARE, EnumEnchantmentType.FISHING_ROD, new EntityEquipmentSlot[] {EntityEquipmentSlot.MAINHAND}));
++ REGISTRY.register(62, new ResourceLocation("lure"), new EnchantmentFishingSpeed(Rarity.RARE, EnumEnchantmentType.FISHING_ROD, new EntityEquipmentSlot[] {EntityEquipmentSlot.MAINHAND}));
++ REGISTRY.register(70, new ResourceLocation("mending"), new EnchantmentMending(Rarity.RARE, EntityEquipmentSlot.values()));
++ REGISTRY.register(71, new ResourceLocation("vanishing_curse"), new EnchantmentVanishingCurse(Rarity.VERY_RARE, EntityEquipmentSlot.values()));
+ }
+
+ public static enum Rarity
diff --git a/patches/net/minecraft/enchantment/EnchantmentFrostWalker.java.patch b/patches/net/minecraft/enchantment/EnchantmentFrostWalker.java.patch
new file mode 100644
index 00000000..908964c9
--- /dev/null
+++ b/patches/net/minecraft/enchantment/EnchantmentFrostWalker.java.patch
@@ -0,0 +1,21 @@
+--- ../src-base/minecraft/net/minecraft/enchantment/EnchantmentFrostWalker.java
++++ ../src-work/minecraft/net/minecraft/enchantment/EnchantmentFrostWalker.java
+@@ -59,10 +59,15 @@
+ {
+ IBlockState iblockstate1 = worldIn.getBlockState(blockpos$mutableblockpos1);
+
+- if (iblockstate1.getMaterial() == Material.WATER && (iblockstate1.getBlock() == net.minecraft.init.Blocks.WATER || iblockstate1.getBlock() == net.minecraft.init.Blocks.FLOWING_WATER) && ((Integer)iblockstate1.getValue(BlockLiquid.LEVEL)).intValue() == 0 && worldIn.mayPlace(Blocks.FROSTED_ICE, blockpos$mutableblockpos1, false, EnumFacing.DOWN, (Entity)null))
++ if (iblockstate1.getMaterial() == Material.WATER && (iblockstate1.getBlock() == Blocks.WATER || iblockstate1.getBlock() == Blocks.FLOWING_WATER) && ((Integer)iblockstate1.getValue(BlockLiquid.LEVEL)).intValue() == 0 && worldIn.mayPlace(Blocks.FROSTED_ICE, blockpos$mutableblockpos1, false, EnumFacing.DOWN, (Entity)null))
+ {
+- worldIn.setBlockState(blockpos$mutableblockpos1, Blocks.FROSTED_ICE.getDefaultState());
+- worldIn.scheduleUpdate(blockpos$mutableblockpos1.toImmutable(), Blocks.FROSTED_ICE, MathHelper.getInt(living.getRNG(), 60, 120));
++ // CraftBukkit Start - Call EntityBlockFormEvent for Frost Walker
++ if (org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockFormEvent(worldIn, blockpos$mutableblockpos1, Blocks.FROSTED_ICE.getDefaultState(), living)) {
++ worldIn.scheduleUpdate(blockpos$mutableblockpos1.toImmutable(), Blocks.FROSTED_ICE, MathHelper.getInt(living.getRNG(), 60, 120));
++ }
++ // CraftBukkit End
++// worldIn.setBlockState(blockpos$mutableblockpos1, Blocks.FROSTED_ICE.getDefaultState());
++// worldIn.scheduleUpdate(blockpos$mutableblockpos1.toImmutable(), Blocks.FROSTED_ICE, MathHelper.getInt(living.getRNG(), 60, 120));
+ }
+ }
+ }
diff --git a/patches/net/minecraft/entity/Entity.java.patch b/patches/net/minecraft/entity/Entity.java.patch
new file mode 100644
index 00000000..2d3cd55e
--- /dev/null
+++ b/patches/net/minecraft/entity/Entity.java.patch
@@ -0,0 +1,1023 @@
+--- ../src-base/minecraft/net/minecraft/entity/Entity.java
++++ ../src-work/minecraft/net/minecraft/entity/Entity.java
+@@ -15,7 +15,6 @@
+ import net.minecraft.block.Block;
+ import net.minecraft.block.BlockFence;
+ import net.minecraft.block.BlockFenceGate;
+-import net.minecraft.block.BlockLiquid;
+ import net.minecraft.block.BlockWall;
+ import net.minecraft.block.SoundType;
+ import net.minecraft.block.material.EnumPushReaction;
+@@ -32,6 +31,7 @@
+ import net.minecraft.entity.effect.EntityLightningBolt;
+ import net.minecraft.entity.item.EntityBoat;
+ import net.minecraft.entity.item.EntityItem;
++import net.minecraft.entity.passive.EntityTameable;
+ import net.minecraft.entity.player.EntityPlayer;
+ import net.minecraft.entity.player.EntityPlayerMP;
+ import net.minecraft.init.Blocks;
+@@ -77,26 +77,63 @@
+ import net.minecraft.util.text.event.HoverEvent;
+ import net.minecraft.util.text.translation.I18n;
+ import net.minecraft.world.Explosion;
+-import net.minecraft.world.Teleporter;
+ import net.minecraft.world.World;
+ import net.minecraft.world.WorldServer;
+ import net.minecraftforge.fml.relauncher.Side;
+ import net.minecraftforge.fml.relauncher.SideOnly;
+ import org.apache.logging.log4j.LogManager;
+ import org.apache.logging.log4j.Logger;
++import org.bukkit.Bukkit;
++import org.bukkit.Location;
++import org.bukkit.Server;
++import org.bukkit.TravelAgent;
++import org.bukkit.block.BlockFace;
++import org.bukkit.craftbukkit.CraftWorld;
++import org.bukkit.craftbukkit.entity.CraftEntity;
++import org.bukkit.craftbukkit.entity.CraftPlayer;
++import org.bukkit.craftbukkit.event.CraftEventFactory;
++import org.bukkit.entity.Hanging;
++import org.bukkit.entity.LivingEntity;
++import org.bukkit.entity.Vehicle;
++import org.spigotmc.CustomTimingsHandler; // Spigot
++import org.bukkit.event.entity.EntityAirChangeEvent;
++import org.bukkit.event.entity.EntityCombustByEntityEvent;
++import org.bukkit.event.entity.EntityCombustEvent;
++import org.bukkit.event.entity.EntityPortalEvent;
++import org.bukkit.event.hanging.HangingBreakByEntityEvent;
++import org.bukkit.event.vehicle.VehicleBlockCollisionEvent;
++import org.bukkit.event.vehicle.VehicleEnterEvent;
++import org.bukkit.event.vehicle.VehicleExitEvent;
++import org.bukkit.plugin.PluginManager;
+
+ public abstract class Entity implements ICommandSender, net.minecraftforge.common.capabilities.ICapabilitySerializable
+ {
++ // CraftBukkit start
++ private static final int CURRENT_LEVEL = 2;
++ static boolean isLevelAtLeast(NBTTagCompound tag, int level) {
++ return tag.hasKey("Bukkit.updateLevel") && tag.getInteger("Bukkit.updateLevel") >= level;
++ }
++
++ protected CraftEntity bukkitEntity;
++ EntityTrackerEntry trackedEntity; // Paper
++ public CraftEntity getBukkitEntity() {
++ if (bukkitEntity == null) {
++ bukkitEntity = CraftEntity.getEntity(world.getServer(), this);
++ }
++ return bukkitEntity;
++ }
++ // CraftBukikt end
+ private static final Logger LOGGER = LogManager.getLogger();
+ private static final List EMPTY_EQUIPMENT = Collections.emptyList();
+ private static final AxisAlignedBB ZERO_AABB = new AxisAlignedBB(0.0D, 0.0D, 0.0D, 0.0D, 0.0D, 0.0D);
+ private static double renderDistanceWeight = 1.0D;
+- private static int nextEntityID;
++ private static int nextEntityID = 1; // Paper - MC-111480 - ID 0 is treated as special for DataWatchers, start 1
+ private int entityId;
+ public boolean preventEntitySpawning;
+- private final List riddenByEntities;
++ public final List riddenByEntities; // Spigot
+ protected int rideCooldown;
+ private Entity ridingEntity;
++ public void setVehicle(Entity entity) { this.ridingEntity = entity; } // Paper // OBFHELPER
+ public boolean forceSpawn;
+ public World world;
+ public double prevPosX;
+@@ -137,8 +174,8 @@
+ public float entityCollisionReduction;
+ protected Random rand;
+ public int ticksExisted;
+- private int fire;
+- protected boolean inWater;
++ public int fire;
++ public boolean inWater;
+ public int hurtResistantTime;
+ protected boolean firstUpdate;
+ protected boolean isImmuneToFire;
+@@ -172,7 +209,7 @@
+ protected UUID entityUniqueID;
+ protected String cachedUniqueIdString;
+ private final CommandResultStats cmdResultStats;
+- protected boolean glowing;
++ public boolean glowing;
+ private final Set tags;
+ private boolean isPositionDirty;
+ private final double[] pistonDeltas;
+@@ -182,6 +219,24 @@
+ */
+ public boolean updateBlocked;
+
++ // CraftBukkit start
++ public boolean valid;
++ public org.bukkit.projectiles.ProjectileSource projectileSource; // For projectiles only
++ public boolean forceExplosionKnockback; // SPIGOT-949
++
++ public float getBukkitYaw() {
++ return this.rotationYaw;
++ }
++ // CraftBukkit end
++
++ // Spigot start
++ public final byte activationType = org.spigotmc.ActivationRange.initializeEntityActivationType(this);
++ public final boolean defaultActivationState;
++ public long activatedTick = Integer.MIN_VALUE;
++ public boolean fromMobSpawner;
++ public void inactiveTick() { }
++ // Spigot end
++
+ public Entity(World worldIn)
+ {
+ this.entityId = nextEntityID++;
+@@ -205,7 +260,12 @@
+ if (worldIn != null)
+ {
+ this.dimension = worldIn.provider.getDimension();
++ // Spigot start
++ this.defaultActivationState = org.spigotmc.ActivationRange.initializeEntityActivationState(this, world.spigotConfig);
++ } else {
++ this.defaultActivationState = false;
+ }
++ // Spigot end
+
+ this.dataManager = new EntityDataManager(this);
+ this.dataManager.register(FLAGS, Byte.valueOf((byte)0));
+@@ -215,15 +275,17 @@
+ this.dataManager.register(SILENT, Boolean.valueOf(false));
+ this.dataManager.register(NO_GRAVITY, Boolean.valueOf(false));
+ this.entityInit();
+- net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.entity.EntityEvent.EntityConstructing(this));
+- capabilities = net.minecraftforge.event.ForgeEventFactory.gatherCapabilities(this);
++ if(!(this instanceof EntityPlayer)) { // Kettle - move to EntityPlayer
++ net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.entity.EntityEvent.EntityConstructing(this));
++ capabilities = net.minecraftforge.event.ForgeEventFactory.gatherCapabilities(this);
++ }
+ }
+
+ /** Forge: Used to store custom data for each entity. */
+ private NBTTagCompound customEntityData;
+ public boolean captureDrops = false;
+ public java.util.ArrayList capturedDrops = new java.util.ArrayList();
+- private net.minecraftforge.common.capabilities.CapabilityDispatcher capabilities;
++ public net.minecraftforge.common.capabilities.CapabilityDispatcher capabilities; // Kettle - private -> public
+
+ public int getEntityId()
+ {
+@@ -345,8 +407,35 @@
+ }
+ }
+
+- protected void setRotation(float yaw, float pitch)
++ public void setRotation(float yaw, float pitch)
+ {
++ // CraftBukkit start - yaw was sometimes set to NaN, so we need to set it back to 0
++ if (Float.isNaN(yaw)) {
++ yaw = 0;
++ }
++
++ if (yaw == Float.POSITIVE_INFINITY || yaw == Float.NEGATIVE_INFINITY) {
++ if (this instanceof EntityPlayer) {
++ this.world.getServer().getLogger().warning(this.getName() + " was caught trying to crash the server with an invalid yaw");
++ ((CraftPlayer) this.getBukkitEntity()).kickPlayer("Nope");
++ }
++ yaw = 0;
++ }
++
++ // pitch was sometimes set to NaN, so we need to set it back to 0
++ if (Float.isNaN(pitch)) {
++ pitch = 0;
++ }
++
++ if (pitch == Float.POSITIVE_INFINITY || pitch == Float.NEGATIVE_INFINITY) {
++ if (this instanceof EntityPlayer) {
++ this.world.getServer().getLogger().warning(this.getName() + " was caught trying to crash the server with an invalid pitch");
++ ((CraftPlayer) this.getBukkitEntity()).kickPlayer("Nope");
++ }
++ pitch = 0;
++ }
++ // CraftBukkit end
++
+ this.rotationYaw = yaw % 360.0F;
+ this.rotationPitch = pitch % 360.0F;
+ }
+@@ -389,72 +478,40 @@
+ this.onEntityUpdate();
+ }
+
+- public void onEntityUpdate()
+- {
+- this.world.profiler.startSection("entityBaseTick");
+-
+- if (this.isRiding() && this.getRidingEntity().isDead)
+- {
+- this.dismountRidingEntity();
+- }
+-
+- if (this.rideCooldown > 0)
+- {
+- --this.rideCooldown;
+- }
+-
+- this.prevDistanceWalkedModified = this.distanceWalkedModified;
+- this.prevPosX = this.posX;
+- this.prevPosY = this.posY;
+- this.prevPosZ = this.posZ;
+- this.prevRotationPitch = this.rotationPitch;
+- this.prevRotationYaw = this.rotationYaw;
+-
+- if (!this.world.isRemote && this.world instanceof WorldServer)
+- {
++ public void postTick() {
++ // No clean way to break out of ticking once the entity has been copied to a new world, so instead we move the portalling later in the tick cycle
++ if (!this.world.isRemote && this.world instanceof WorldServer) {
+ this.world.profiler.startSection("portal");
+-
+- if (this.inPortal)
+- {
++ if (this.inPortal) {
+ MinecraftServer minecraftserver = this.world.getMinecraftServer();
+
+- if (minecraftserver.getAllowNether())
+- {
+- if (!this.isRiding())
+- {
++ if (true || minecraftserver.getAllowNether()) { // CraftBukkit
++ if (!this.isRiding()) {
+ int i = this.getMaxInPortalTime();
+
+- if (this.portalCounter++ >= i)
+- {
++ if (this.portalCounter++ >= i) {
+ this.portalCounter = i;
+ this.timeUntilPortal = this.getPortalCooldown();
+- int j;
++ byte b0;
+
+- if (this.world.provider.getDimensionType().getId() == -1)
+- {
+- j = 0;
++ if (this.world.provider.getDimensionType().getId() == -1) {
++ b0 = 0;
++ } else {
++ b0 = -1;
+ }
+- else
+- {
+- j = -1;
+- }
+
+- this.changeDimension(j);
++ this.changeDimension(b0);
+ }
+ }
+
+ this.inPortal = false;
+ }
+- }
+- else
+- {
+- if (this.portalCounter > 0)
+- {
++ } else {
++ if (this.portalCounter > 0) {
+ this.portalCounter -= 4;
+ }
+
+- if (this.portalCounter < 0)
+- {
++ if (this.portalCounter < 0) {
+ this.portalCounter = 0;
+ }
+ }
+@@ -462,7 +519,28 @@
+ this.decrementTimeUntilPortal();
+ this.world.profiler.endSection();
+ }
++ }
+
++ public void onEntityUpdate()
++ {
++ this.world.profiler.startSection("entityBaseTick");
++
++ if (this.isRiding() && this.getRidingEntity().isDead)
++ {
++ this.dismountRidingEntity();
++ }
++
++ if (this.rideCooldown > 0)
++ {
++ --this.rideCooldown;
++ }
++
++ this.prevDistanceWalkedModified = this.distanceWalkedModified;
++ this.prevPosX = this.posX;
++ this.prevPosY = this.posY;
++ this.prevPosZ = this.posZ;
++ this.prevRotationPitch = this.rotationPitch;
++ this.prevRotationYaw = this.rotationYaw;
+ this.spawnRunningParticles();
+ this.handleWaterMovement();
+
+@@ -530,6 +608,26 @@
+ if (!this.isImmuneToFire)
+ {
+ this.attackEntityFrom(DamageSource.LAVA, 4.0F);
++ // CraftBukkit start - Fallen in lava TODO: this event spams!
++ if (this instanceof EntityLiving) {
++ if (fire <= 0) {
++ // not on fire yet
++ // TODO: shouldn't be sending null for the block
++ org.bukkit.block.Block damager = null; // ((WorldServer) this.l).getWorld().getBlockAt(i, j, k);
++ org.bukkit.entity.Entity damagee = this.getBukkitEntity();
++ EntityCombustEvent combustEvent = new org.bukkit.event.entity.EntityCombustByBlockEvent(damager, damagee, 15);
++ this.world.getServer().getPluginManager().callEvent(combustEvent);
++
++ if (!combustEvent.isCancelled()) {
++ this.setFire(combustEvent.getDuration());
++ }
++ } else {
++ // This will be called every single tick the entity is in lava, so don't throw an event
++ this.setFire(15);
++ }
++ return;
++ }
++ // CraftBukkit end - we also don't throw an event unless the object in lava is living, to save on some event calls
+ this.setFire(15);
+ }
+ }
+@@ -579,6 +677,26 @@
+ }
+ else
+ {
++ // CraftBukkit start - Don't do anything if we aren't moving
++ // We need to do this regardless of whether or not we are moving thanks to portals
++ double d2 = x;
++ double d3 = y;
++ double d4 = z;
++
++ try {
++ this.doBlockCollisions();
++ } catch (Throwable throwable) {
++ CrashReport crashreport = CrashReport.makeCrashReport(throwable, "Checking entity block collision");
++ CrashReportCategory crashreportsystemdetails = crashreport.makeCategory("Entity being checked for collision");
++
++ this.addEntityCrashInfo(crashreportsystemdetails);
++ throw new ReportedException(crashreport);
++ }
++ // Check if we're moving
++ if (x == 0 && y == 0 && z == 0 && this.isBeingRidden() && this.isRiding()) {
++ return;
++ }
++ // CraftBukkit end
+ if (type == MoverType.PISTON)
+ {
+ long i = this.world.getTotalWorldTime();
+@@ -648,10 +766,6 @@
+ this.motionZ = 0.0D;
+ }
+
+- double d2 = x;
+- double d3 = y;
+- double d4 = z;
+-
+ if ((type == MoverType.SELF || type == MoverType.PLAYER) && this.onGround && this.isSneaking() && this instanceof EntityPlayer)
+ {
+ for (double d5 = 0.05D; x != 0.0D && this.world.getCollisionBoxes(this, this.getEntityBoundingBox().offset(x, (double)(-this.stepHeight), 0.0D)).isEmpty(); d2 = x)
+@@ -912,6 +1026,26 @@
+ block.onLanded(this.world, this);
+ }
+
++ if (collidedHorizontally && getBukkitEntity() instanceof Vehicle) {
++ Vehicle vehicle = (Vehicle) this.getBukkitEntity();
++ org.bukkit.block.Block bl = this.world.getWorld().getBlockAt(MathHelper.floor(this.posX), MathHelper.floor(this.posY), MathHelper.floor(this.posZ));
++
++ if (d2 > x) {
++ bl = bl.getRelative(BlockFace.EAST);
++ } else if (d2 < x) {
++ bl = bl.getRelative(BlockFace.WEST);
++ } else if (d4 > z) {
++ bl = bl.getRelative(BlockFace.SOUTH);
++ } else if (d4 < z) {
++ bl = bl.getRelative(BlockFace.NORTH);
++ }
++
++ if (bl.getType() != org.bukkit.Material.AIR) {
++ VehicleBlockCollisionEvent event = new VehicleBlockCollisionEvent(vehicle, bl);
++ world.getServer().getPluginManager().callEvent(event);
++ }
++ }
++
+ if (this.canTriggerWalking() && (!this.onGround || !this.isSneaking() || !(this instanceof EntityPlayer)) && !this.isRiding())
+ {
+ double d15 = this.posX - d10;
+@@ -958,7 +1092,8 @@
+ this.nextFlap = this.playFlySound(this.distanceWalkedOnStepModified);
+ }
+ }
+-
++ // Move to the top of the method
++ /*
+ try
+ {
+ this.doBlockCollisions();
+@@ -970,6 +1105,7 @@
+ this.addEntityCrashInfo(crashreportcategory);
+ throw new ReportedException(crashreport);
+ }
++ */
+
+ boolean flag1 = this.isWet();
+
+@@ -983,7 +1119,13 @@
+
+ if (this.fire == 0)
+ {
+- this.setFire(8);
++// this.setFire(8);
++ EntityCombustEvent event = new org.bukkit.event.entity.EntityCombustByBlockEvent(null, getBukkitEntity(), 8);
++ world.getServer().getPluginManager().callEvent(event);
++
++ if (!event.isCancelled()) {
++ this.setFire(event.getDuration());
++ }
+ }
+ }
+ }
+@@ -1008,7 +1150,7 @@
+ this.posX = (axisalignedbb.minX + axisalignedbb.maxX) / 2.0D;
+ this.posY = axisalignedbb.minY;
+ this.posZ = (axisalignedbb.minZ + axisalignedbb.maxZ) / 2.0D;
+- if (this.isAddedToWorld() && !this.world.isRemote) this.world.updateEntityWithOptionalForce(this, false); // Forge - Process chunk registration after moving.
++ if (this.isAddedToWorld && !this.world.isRemote) this.world.updateEntityWithOptionalForce(this, false); // Forge - Process chunk registration after moving.
+ }
+
+ protected SoundEvent getSwimSound()
+@@ -1041,9 +1183,14 @@
+
+ try
+ {
+- iblockstate.getBlock().onEntityCollidedWithBlock(this.world, blockpos$pooledmutableblockpos2, iblockstate, this);
++ if (iblockstate != null) {
++ Block block = iblockstate.getBlock();
++ if (block != null) {
++ block.onEntityCollidedWithBlock(this.world, blockpos$pooledmutableblockpos2, iblockstate, this);
++ }
+ this.onInsideBlock(iblockstate);
+ }
++ }
+ catch (Throwable throwable)
+ {
+ CrashReport crashreport = CrashReport.makeCrashReport(throwable, "Colliding entity with block");
+@@ -1154,6 +1301,14 @@
+ }
+ }
+
++ protected void dealFireDamage(float amount)
++ {
++ if (!this.isImmuneToFire)
++ {
++ this.attackEntityFrom(DamageSource.IN_FIRE, (float)amount);
++ }
++ }
++
+ public final boolean isImmuneToFire()
+ {
+ return this.isImmuneToFire;
+@@ -1274,10 +1429,10 @@
+ IBlockState iblockstate = this.world.getBlockState(blockpos);
+
+ if(!iblockstate.getBlock().addRunningEffects(iblockstate, world, blockpos, this))
+- if (iblockstate.getRenderType() != EnumBlockRenderType.INVISIBLE)
+- {
+- this.world.spawnParticle(EnumParticleTypes.BLOCK_CRACK, this.posX + ((double)this.rand.nextFloat() - 0.5D) * (double)this.width, this.getEntityBoundingBox().minY + 0.1D, this.posZ + ((double)this.rand.nextFloat() - 0.5D) * (double)this.width, -this.motionX * 4.0D, 1.5D, -this.motionZ * 4.0D, Block.getStateId(iblockstate));
+- }
++ if (iblockstate.getRenderType() != EnumBlockRenderType.INVISIBLE)
++ {
++ this.world.spawnParticle(EnumParticleTypes.BLOCK_CRACK, this.posX + ((double)this.rand.nextFloat() - 0.5D) * (double)this.width, this.getEntityBoundingBox().minY + 0.1D, this.posZ + ((double)this.rand.nextFloat() - 0.5D) * (double)this.width, -this.motionX * 4.0D, 1.5D, -this.motionZ * 4.0D, Block.getStateId(iblockstate));
++ }
+ }
+
+ public boolean isInsideOfMaterial(Material materialIn)
+@@ -1369,6 +1524,11 @@
+
+ public void setWorld(World worldIn)
+ {
++ if (world == null) {
++ setDead();
++ this.world = ((CraftWorld) Bukkit.getServer().getWorlds().get(0)).getHandle();
++ return;
++ }
+ this.world = worldIn;
+ }
+
+@@ -1687,6 +1847,16 @@
+ {
+ compound.setTag("Pos", this.newDoubleNBTList(this.posX, this.posY, this.posZ));
+ compound.setTag("Motion", this.newDoubleNBTList(this.motionX, this.motionY, this.motionZ));
++ // CraftBukkit start - Checking for NaN pitch/yaw and resetting to zero
++ // TODO: make sure this is the best way to address this.
++ if (Float.isNaN(this.rotationYaw)) {
++ this.rotationYaw = 0;
++ }
++
++ if (Float.isNaN(this.rotationPitch)) {
++ this.rotationPitch = 0;
++ }
++ // CraftBukkit end
+ compound.setTag("Rotation", this.newFloatNBTList(this.rotationYaw, this.rotationPitch));
+ compound.setFloat("FallDistance", this.fallDistance);
+ compound.setShort("Fire", (short)this.fire);
+@@ -1696,7 +1866,12 @@
+ compound.setBoolean("Invulnerable", this.invulnerable);
+ compound.setInteger("PortalCooldown", this.timeUntilPortal);
+ compound.setUniqueId("UUID", this.getUniqueID());
+-
++ // CraftBukkit start
++ // PAIL: Check above UUID reads 1.8 properly, ie: UUIDMost / UUIDLeast
++ compound.setLong("WorldUUIDLeast", this.world.getSaveHandler().getUUID().getLeastSignificantBits());
++ compound.setLong("WorldUUIDMost", this.world.getSaveHandler().getUUID().getMostSignificantBits());
++ compound.setInteger("Bukkit.updateLevel", CURRENT_LEVEL);
++ // CraftBukkit end
+ if (this.hasCustomName())
+ {
+ compound.setString("CustomName", this.getCustomNameTag());
+@@ -1784,21 +1959,6 @@
+ this.motionY = nbttaglist2.getDoubleAt(1);
+ this.motionZ = nbttaglist2.getDoubleAt(2);
+
+- if (Math.abs(this.motionX) > 10.0D)
+- {
+- this.motionX = 0.0D;
+- }
+-
+- if (Math.abs(this.motionY) > 10.0D)
+- {
+- this.motionY = 0.0D;
+- }
+-
+- if (Math.abs(this.motionZ) > 10.0D)
+- {
+- this.motionZ = 0.0D;
+- }
+-
+ this.posX = nbttaglist.getDoubleAt(0);
+ this.posY = nbttaglist.getDoubleAt(1);
+ this.posZ = nbttaglist.getDoubleAt(2);
+@@ -1869,6 +2029,50 @@
+ {
+ this.setPosition(this.posX, this.posY, this.posZ);
+ }
++
++ if (this instanceof EntityLiving) {
++ EntityLiving entity = (EntityLiving) this;
++
++ // Reset the persistence for tamed animals
++ if (entity instanceof EntityTameable && !isLevelAtLeast(compound, 2) && !compound.getBoolean("PersistenceRequired")) {
++ ((EntityLiving) entity).persistenceRequired = !(entity).canDespawn();
++ }
++ }
++ double limit = getBukkitEntity() instanceof Vehicle ? 100.0D : 10.0D;
++ if (Math.abs(this.motionX) > limit) {
++ this.motionX = 0.0D;
++ }
++
++ if (Math.abs(this.motionY) > limit) {
++ this.motionY = 0.0D;
++ }
++
++ if (Math.abs(this.motionZ) > limit) {
++ this.motionZ = 0.0D;
++ }
++
++ // Reset world
++ if (this instanceof EntityPlayer) {
++ Server server = Bukkit.getServer();
++ org.bukkit.World bworld = null;
++
++ // TODO: Remove World related checks, replaced with WorldUID
++ String worldName = compound.getString("world");
++
++ if (compound.hasKey("WorldUUIDMost") && compound.hasKey("WorldUUIDLeast")) {
++ UUID uid = new UUID(compound.getLong("WorldUUIDMost"), compound.getLong("WorldUUIDLeast"));
++ bworld = server.getWorld(uid);
++ } else {
++ bworld = server.getWorld(worldName);
++ }
++
++ if (bworld == null) {
++ EntityPlayer entityPlayer = (EntityPlayer) this;
++ bworld = ((org.bukkit.craftbukkit.CraftServer) server).getServer().getWorldServer(entityPlayer.dimension).getWorld();
++ }
++
++ setWorld(bworld == null? null : ((CraftWorld) bworld).getHandle());
++ }
+ }
+ catch (Throwable throwable)
+ {
+@@ -1885,7 +2089,7 @@
+ }
+
+ @Nullable
+- protected final String getEntityString()
++ public final String getEntityString()
+ {
+ ResourceLocation resourcelocation = EntityList.getKey(this);
+ return resourcelocation == null ? null : resourcelocation.toString();
+@@ -1945,7 +2149,9 @@
+ if (captureDrops)
+ this.capturedDrops.add(entityitem);
+ else
+- this.world.spawnEntity(entityitem);
++ {
++ this.world.spawnEntity(entityitem);
++ }
+ return entityitem;
+ }
+ }
+@@ -2013,7 +2219,7 @@
+ this.motionY = 0.0D;
+ this.motionZ = 0.0D;
+ if(!updateBlocked)
+- this.onUpdate();
++ this.onUpdate();
+
+ if (this.isRiding())
+ {
+@@ -2110,6 +2316,29 @@
+ }
+ else
+ {
++ com.google.common.base.Preconditions.checkState(!passenger.riddenByEntities.contains(this), "Circular entity riding! %s %s", this, passenger);
++
++ CraftEntity craft = (CraftEntity) passenger.getBukkitEntity().getVehicle();
++ Entity orig = craft == null ? null : craft.getHandle();
++ if (getBukkitEntity() instanceof Vehicle && passenger.getBukkitEntity() instanceof LivingEntity && passenger.world.isChunkLoaded((int) passenger.posX >> 4, (int) passenger.posZ >> 4, false)) { // Boolean not used
++ VehicleEnterEvent event = new VehicleEnterEvent(
++ (Vehicle) getBukkitEntity(),
++ passenger.getBukkitEntity()
++ );
++ Bukkit.getPluginManager().callEvent(event);
++ CraftEntity craftn = (CraftEntity) passenger.getBukkitEntity().getVehicle();
++ Entity n = craftn == null ? null : craftn.getHandle();
++ if (event.isCancelled() || n != orig) {
++ return;
++ }
++ }
++ // Spigot start
++ org.spigotmc.event.entity.EntityMountEvent event = new org.spigotmc.event.entity.EntityMountEvent(passenger.getBukkitEntity(), this.getBukkitEntity());
++ Bukkit.getPluginManager().callEvent(event);
++ if (event.isCancelled()) {
++ return;
++ }
++ // Spigot end
+ if (!this.world.isRemote && passenger instanceof EntityPlayer && !(this.getControllingPassenger() instanceof EntityPlayer))
+ {
+ this.riddenByEntities.add(0, passenger);
+@@ -2129,6 +2358,27 @@
+ }
+ else
+ {
++ passenger.setVehicle(this); // Paper - Set the vehicle back for the event
++ CraftEntity craft = (CraftEntity) passenger.getBukkitEntity().getVehicle();
++ Entity orig = craft == null ? null : craft.getHandle();
++ if (getBukkitEntity() instanceof Vehicle && passenger.getBukkitEntity() instanceof LivingEntity) {
++ VehicleExitEvent event = new VehicleExitEvent(
++ (Vehicle) getBukkitEntity(),
++ (LivingEntity) passenger.getBukkitEntity()
++ );
++ Bukkit.getPluginManager().callEvent(event);
++ CraftEntity craftn = (CraftEntity) passenger.getBukkitEntity().getVehicle();
++ Entity n = craftn == null ? null : craftn.getHandle();
++ if (event.isCancelled() || n != orig) {
++ return;
++ }
++ }
++ // Paper start - make EntityDismountEvent cancellable
++ if (!new org.spigotmc.event.entity.EntityDismountEvent(passenger.getBukkitEntity(), this.getBukkitEntity()).callEvent()) {
++ return;
++ }
++ passenger.setVehicle(null);
++ // Paper end
+ this.riddenByEntities.remove(passenger);
+ passenger.rideCooldown = 60;
+ }
+@@ -2325,12 +2575,12 @@
+ this.setFlag(5, invisible);
+ }
+
+- protected boolean getFlag(int flag)
++ public boolean getFlag(int flag)
+ {
+ return (((Byte)this.dataManager.get(FLAGS)).byteValue() & 1 << flag) != 0;
+ }
+
+- protected void setFlag(int flag, boolean set)
++ public void setFlag(int flag, boolean set)
+ {
+ byte b0 = ((Byte)this.dataManager.get(FLAGS)).byteValue();
+
+@@ -2351,17 +2601,52 @@
+
+ public void setAir(int air)
+ {
+- this.dataManager.set(AIR, Integer.valueOf(air));
++// this.dataManager.set(AIR, Integer.valueOf(air));
++ EntityAirChangeEvent event = new EntityAirChangeEvent(this.getBukkitEntity(), air);
++ event.getEntity().getServer().getPluginManager().callEvent(event);
++ if (event.isCancelled()) {
++ return;
++ }
++ this.dataManager.set(Entity.AIR, event.getAmount());
+ }
+
+- public void onStruckByLightning(EntityLightningBolt lightningBolt)
++ public void onStruckByLightning(@Nullable EntityLightningBolt lightningBolt)
+ {
++ if (lightningBolt == null) lightningBolt = new EntityLightningBolt(this.world, this.posX, this.posY, this.posZ, true);
++ final org.bukkit.entity.Entity thisBukkitEntity = this.getBukkitEntity();
++ final org.bukkit.entity.Entity stormBukkitEntity = lightningBolt.getBukkitEntity();
++ final PluginManager pluginManager = Bukkit.getPluginManager();
++
++ if (thisBukkitEntity instanceof Hanging) {
++ HangingBreakByEntityEvent hangingEvent = new HangingBreakByEntityEvent((Hanging) thisBukkitEntity, stormBukkitEntity);
++ pluginManager.callEvent(hangingEvent);
++
++ if (hangingEvent.isCancelled()) {
++ return;
++ }
++ }
++
++ if (this.isImmuneToFire) {
++ return;
++ }
++ CraftEventFactory.entityDamage = lightningBolt;
++ if (!this.attackEntityFrom(DamageSource.LIGHTNING_BOLT, 5.0F)) {
++ CraftEventFactory.entityDamage = null;
++ return;
++ }
+ this.attackEntityFrom(DamageSource.LIGHTNING_BOLT, 5.0F);
+ ++this.fire;
+
+ if (this.fire == 0)
+ {
+- this.setFire(8);
++ // this.setFire(8);
++ // CraftBukkit start - Call a combust event when lightning strikes
++ EntityCombustByEntityEvent entityCombustEvent = new EntityCombustByEntityEvent(stormBukkitEntity, thisBukkitEntity, 8);
++ pluginManager.callEvent(entityCombustEvent);
++ if (!entityCombustEvent.isCancelled()) {
++ this.setFire(entityCombustEvent.getDuration());
++ }
++ // CraftBukkit end
+ }
+ }
+
+@@ -2502,7 +2787,7 @@
+
+ public String toString()
+ {
+- return String.format("%s['%s'/%d, l='%s', x=%.2f, y=%.2f, z=%.2f]", this.getClass().getSimpleName(), this.getName(), this.entityId, this.world == null ? "~NULL~" : this.world.getWorldInfo().getWorldName(), this.posX, this.posY, this.posZ);
++ return String.format("%s[\'%s\'/%d, uuid=\'%s\', l=\'%s\', x=%.2f, y=%.2f, z=%.2f, cx=%d, cd=%d, tl=%d, v=%b, d=%b]", new Object[] { this.getClass().getSimpleName(), this.getName(), Integer.valueOf(this.entityId), this.getUniqueID().toString(), this.world == null ? "~NULL~" : this.world.getWorldInfo().getWorldName(), Double.valueOf(this.posX), Double.valueOf(this.posY), Double.valueOf(this.posZ), chunkCoordX, chunkCoordZ, this.ticksExisted, this.valid, this.isDead}); // Paper - add more information
+ }
+
+ public boolean isEntityInvulnerable(DamageSource source)
+@@ -2540,7 +2825,7 @@
+ public Entity changeDimension(int dimensionIn)
+ {
+ if (this.world.isRemote || this.isDead) return null;
+- return changeDimension(dimensionIn, this.getServer().getWorld(dimensionIn).getDefaultTeleporter());
++ return changeDimension(dimensionIn, this.getServer().getWorldServer(dimensionIn).getDefaultTeleporter());
+ }
+
+ @Nullable // Forge: Entities that require custom handling should override this method, not the other
+@@ -2551,53 +2836,67 @@
+ if (!net.minecraftforge.common.ForgeHooks.onTravelToDimension(this, dimensionIn)) return null;
+ this.world.profiler.startSection("changeDimension");
+ MinecraftServer minecraftserver = this.getServer();
+- int i = this.dimension;
+- WorldServer worldserver = minecraftserver.getWorld(i);
+- WorldServer worldserver1 = minecraftserver.getWorld(dimensionIn);
+- this.dimension = dimensionIn;
+-
+- if (i == 1 && dimensionIn == 1 && teleporter.isVanilla())
+- {
+- worldserver1 = minecraftserver.getWorld(0);
+- this.dimension = 0;
++ // CraftBukkit start - Move logic into new function "teleportTo(Location,boolean)"
++ // int i = this.dimension;
++ // WorldServer worldserver = minecraftserver.getWorld(i);
++ // WorldServer worldserver1 = minecraftserver.getWorld(dimensionIn);
++ WorldServer exitWorld = null;
++ if (this.dimension < CraftWorld.CUSTOM_DIMENSION_OFFSET) { // Plugins must specify exit from custom Bukkit worlds
++ // Only target existing worlds (compensate for allow-nether/allow-end as false)
++ for (WorldServer world : minecraftserver.worlds) {
++ if (world.dimension == dimensionIn) {
++ exitWorld = world;
++ }
++ }
+ }
+
+- this.world.removeEntity(this);
+- this.isDead = false;
+- this.world.profiler.startSection("reposition");
+- BlockPos blockpos;
+-
+- if (dimensionIn == 1 && teleporter.isVanilla())
+- {
+- blockpos = worldserver1.getSpawnCoordinate();
++ BlockPos blockposition = null; // PAIL: CHECK
++ Location enter = this.getBukkitEntity().getLocation();
++ Location exit;
++ if (exitWorld != null) {
++ if (blockposition != null) {
++ exit = new Location(exitWorld.getWorld(), blockposition.getX(), blockposition.getY(), blockposition.getZ());
++ } else {
++ exit = minecraftserver.getPlayerList().calculateTarget(enter, minecraftserver.getWorld(dimensionIn));
++ }
+ }
+- else
+- {
+- double moveFactor = worldserver.provider.getMovementFactor() / worldserver1.provider.getMovementFactor();
+- double d0 = MathHelper.clamp(this.posX * moveFactor, worldserver1.getWorldBorder().minX() + 16.0D, worldserver1.getWorldBorder().maxX() - 16.0D);
+- double d1 = MathHelper.clamp(this.posZ * moveFactor, worldserver1.getWorldBorder().minZ() + 16.0D, worldserver1.getWorldBorder().maxZ() - 16.0D);
+- double d2 = 8.0D;
++ else {
++ exit = null;
++ }
++ boolean useTravelAgent = exitWorld != null && !(this.dimension == 1 && exitWorld.dimension == 1); // don't use agent for custom worlds or return from THE_END
+
+- if (false && dimensionIn == -1)
+- {
+- d0 = MathHelper.clamp(d0 / 8.0D, worldserver1.getWorldBorder().minX() + 16.0D, worldserver1.getWorldBorder().maxX() - 16.0D);
+- d1 = MathHelper.clamp(d1 / 8.0D, worldserver1.getWorldBorder().minZ() + 16.0D, worldserver1.getWorldBorder().maxZ() - 16.0D);
+- }
+- else if (false && dimensionIn == 0)
+- {
+- d0 = MathHelper.clamp(d0 * 8.0D, worldserver1.getWorldBorder().minX() + 16.0D, worldserver1.getWorldBorder().maxX() - 16.0D);
+- d1 = MathHelper.clamp(d1 * 8.0D, worldserver1.getWorldBorder().minZ() + 16.0D, worldserver1.getWorldBorder().maxZ() - 16.0D);
+- }
++ TravelAgent agent = exit != null ? (TravelAgent) ((CraftWorld) exit.getWorld()).getHandle().getDefaultTeleporter() : org.bukkit.craftbukkit.CraftTravelAgent.DEFAULT; // return arbitrary TA to compensate for implementation dependent plugins
++ boolean oldCanCreate = agent.getCanCreatePortal();
++ agent.setCanCreatePortal(false); // General entities cannot create portals
+
+- d0 = (double)MathHelper.clamp((int)d0, -29999872, 29999872);
+- d1 = (double)MathHelper.clamp((int)d1, -29999872, 29999872);
+- float f = this.rotationYaw;
+- this.setLocationAndAngles(d0, this.posY, d1, 90.0F, 0.0F);
+- teleporter.placeEntity(worldserver1, this, f);
+- blockpos = new BlockPos(this);
++ EntityPortalEvent event = new EntityPortalEvent(this.getBukkitEntity(), enter, exit, agent);
++ event.useTravelAgent(useTravelAgent);
++ event.getEntity().getServer().getPluginManager().callEvent(event);
++ if (event.isCancelled() || event.getTo() == null || event.getTo().getWorld() == null || !this.isEntityAlive()) {
++ agent.setCanCreatePortal(oldCanCreate);
++ return null;
+ }
++ exit = event.useTravelAgent() ? event.getPortalTravelAgent().findOrCreate(event.getTo()) : event.getTo();
++ agent.setCanCreatePortal(oldCanCreate);
+
+- worldserver.updateEntityWithOptionalForce(this, false);
++ // Need to make sure the profiler state is reset afterwards (but we still want to time the call)
++ Entity entity = this.teleportTo(exit, true);
++ this.world.profiler.endSection();
++ return entity;
++ }
++ return null;
++ }
++
++ public Entity teleportTo(Location exit, boolean portal) {
++ if (true) { // Paper
++ WorldServer worldserver = ((CraftWorld) getBukkitEntity().getLocation().getWorld()).getHandle();
++ WorldServer worldserver1 = ((CraftWorld) exit.getWorld()).getHandle();
++ int i = worldserver1.dimension;
++ this.dimension = i;
++ this.world.removeEntity(this); // Paper - Fully remove entity, can't have dupes in the UUID map
++ this.isDead = false;
++ this.world.profiler.startSection("reposition");
++ worldserver1.getMinecraftServer().getPlayerList().repositionEntity(this, exit, portal);
+ this.world.profiler.endStartSection("reloading");
+ Entity entity = EntityList.newEntity(this.getClass(), worldserver1);
+
+@@ -2605,28 +2904,26 @@
+ {
+ entity.copyDataFromOld(this);
+
+- if (i == 1 && dimensionIn == 1 && teleporter.isVanilla())
+- {
+- BlockPos blockpos1 = worldserver1.getTopSolidOrLiquidBlock(worldserver1.getSpawnPoint());
+- entity.moveToBlockPosAndAngles(blockpos1, entity.rotationYaw, entity.rotationPitch);
+- }
+- else
+- {
+- entity.moveToBlockPosAndAngles(blockpos, entity.rotationYaw, entity.rotationPitch);
+- }
+-
+ boolean flag = entity.forceSpawn;
+ entity.forceSpawn = true;
+ worldserver1.spawnEntity(entity);
+ entity.forceSpawn = flag;
+ worldserver1.updateEntityWithOptionalForce(entity, false);
++ // CraftBukkit start - Forward the CraftEntity to the new entity
++ this.getBukkitEntity().setHandle(entity);
++ entity.bukkitEntity = this.getBukkitEntity();
++
++ if (this instanceof EntityLiving) {
++ ((EntityLiving) this).clearLeashed(true, false); // Unleash to prevent duping of leads.
++ }
++ // CraftBukkit end
+ }
+
+ this.isDead = true;
+ this.world.profiler.endSection();
+ worldserver.resetUpdateEntityTick();
+ worldserver1.resetUpdateEntityTick();
+- this.world.profiler.endSection();
++ // this.world.profiler.endSection(); // CraftBukkit: Moved up to keep balanced
+ return entity;
+ }
+ else
+@@ -2755,6 +3052,11 @@
+
+ public void setCustomNameTag(String name)
+ {
++ // CraftBukkit start - Add a sane limit for name length
++ if (name.length() > 256) {
++ name = name.substring(0, 256);
++ }
++ // CraftBukkit end
+ this.dataManager.set(CUSTOM_NAME, name);
+ }
+
+@@ -2838,7 +3140,25 @@
+
+ public void setEntityBoundingBox(AxisAlignedBB bb)
+ {
+- this.boundingBox = bb;
++// this.boundingBox = bb;
++ double a = bb.minX,
++ b = bb.minY,
++ c = bb.minZ,
++ d = bb.maxX,
++ e = bb.maxY,
++ f = bb.maxZ;
++ double len = bb.maxX - bb.minX;
++ if (len < 0) d = a;
++ if (len > 64) d = a + 64.0;
++
++ len = bb.maxY - bb.minY;
++ if (len < 0) e = b;
++ if (len > 64) e = b + 64.0;
++
++ len = bb.maxZ - bb.minZ;
++ if (len < 0) f = c;
++ if (len > 64) f = c + 64.0;
++ this.boundingBox = new AxisAlignedBB(a, b, c, d, e, f);
+ }
+
+ public float getEyeHeight()
+@@ -2870,6 +3190,11 @@
+ return true;
+ }
+
++ public boolean canUseCommand(int permLevel, String commandName, String perm)
++ {
++ return true;
++ }
++
+ public BlockPos getPosition()
+ {
+ return new BlockPos(this.posX, this.posY + 0.5D, this.posZ);
+@@ -3030,7 +3355,7 @@
+ {
+ return ((net.minecraft.entity.item.EntityMinecart)this).getCartItem();
+ }
+- else if (this instanceof net.minecraft.entity.item.EntityBoat)
++ else if (this instanceof EntityBoat)
+ {
+ return new ItemStack(((EntityBoat)this).getItemBoat());
+ }
+@@ -3109,14 +3434,14 @@
+ }
+
+ @Override
+- public boolean hasCapability(net.minecraftforge.common.capabilities.Capability> capability, @Nullable net.minecraft.util.EnumFacing facing)
++ public boolean hasCapability(net.minecraftforge.common.capabilities.Capability> capability, @Nullable EnumFacing facing)
+ {
+ return capabilities != null && capabilities.hasCapability(capability, facing);
+ }
+
+ @Override
+ @Nullable
+- public T getCapability(net.minecraftforge.common.capabilities.Capability capability, @Nullable net.minecraft.util.EnumFacing facing)
++ public T getCapability(net.minecraftforge.common.capabilities.Capability capability, @Nullable EnumFacing facing)
+ {
+ return capabilities == null ? null : capabilities.getCapability(capability, facing);
+ }
+@@ -3319,7 +3644,7 @@
+ return SoundCategory.NEUTRAL;
+ }
+
+- protected int getFireImmuneTicks()
++ public int getFireImmuneTicks()
+ {
+ return 1;
+ }
diff --git a/patches/net/minecraft/entity/EntityAgeable.java.patch b/patches/net/minecraft/entity/EntityAgeable.java.patch
new file mode 100644
index 00000000..8accf990
--- /dev/null
+++ b/patches/net/minecraft/entity/EntityAgeable.java.patch
@@ -0,0 +1,70 @@
+--- ../src-base/minecraft/net/minecraft/entity/EntityAgeable.java
++++ ../src-work/minecraft/net/minecraft/entity/EntityAgeable.java
+@@ -22,6 +22,33 @@
+ private float ageWidth = -1.0F;
+ private float ageHeight;
+
++ public boolean ageLocked;
++
++ // Spigot start
++ @Override
++ public void inactiveTick()
++ {
++ super.inactiveTick();
++ if ( this.world.isRemote || this.ageLocked )
++ { // CraftBukkit
++ this.setScaleForAge( this.isChild() );
++ } else
++ {
++ int i = this.getGrowingAge();
++
++ if ( i < 0 )
++ {
++ ++i;
++ this.setGrowingAge( i );
++ } else if ( i > 0 )
++ {
++ --i;
++ this.setGrowingAge( i );
++ }
++ }
++ }
++ // Spigot end
++
+ public EntityAgeable(World worldIn)
+ {
+ super(worldIn);
+@@ -48,7 +75,7 @@
+ {
+ entityageable.setGrowingAge(-24000);
+ entityageable.setLocationAndAngles(this.posX, this.posY, this.posZ, 0.0F, 0.0F);
+- this.world.spawnEntity(entityageable);
++ this.world.spawnEntity(entityageable, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.SPAWNER_EGG);
+
+ if (itemstack.hasDisplayName())
+ {
+@@ -154,6 +181,7 @@
+ super.writeEntityToNBT(compound);
+ compound.setInteger("Age", this.getGrowingAge());
+ compound.setInteger("ForcedAge", this.forcedAge);
++ compound.setBoolean("AgeLocked", this.ageLocked);
+ }
+
+ public void readEntityFromNBT(NBTTagCompound compound)
+@@ -161,6 +189,7 @@
+ super.readEntityFromNBT(compound);
+ this.setGrowingAge(compound.getInteger("Age"));
+ this.forcedAge = compound.getInteger("ForcedAge");
++ this.ageLocked = compound.getBoolean("AgeLocked");
+ }
+
+ public void notifyDataManagerChange(DataParameter> key)
+@@ -177,7 +206,7 @@
+ {
+ super.onLivingUpdate();
+
+- if (this.world.isRemote)
++ if (this.world.isRemote || ageLocked)
+ {
+ if (this.forcedAgeTimer > 0)
+ {
diff --git a/patches/net/minecraft/entity/EntityAreaEffectCloud.java.patch b/patches/net/minecraft/entity/EntityAreaEffectCloud.java.patch
new file mode 100644
index 00000000..bf28ad98
--- /dev/null
+++ b/patches/net/minecraft/entity/EntityAreaEffectCloud.java.patch
@@ -0,0 +1,126 @@
+--- ../src-base/minecraft/net/minecraft/entity/EntityAreaEffectCloud.java
++++ ../src-work/minecraft/net/minecraft/entity/EntityAreaEffectCloud.java
+@@ -2,10 +2,7 @@
+
+ import com.google.common.collect.Lists;
+ import com.google.common.collect.Maps;
+-import java.util.Iterator;
+-import java.util.List;
+-import java.util.Map;
+-import java.util.UUID;
++import java.util.*;
+ import java.util.Map.Entry;
+ import javax.annotation.Nullable;
+ import net.minecraft.block.material.EnumPushReaction;
+@@ -23,6 +20,8 @@
+ import net.minecraft.util.math.MathHelper;
+ import net.minecraft.world.World;
+ import net.minecraft.world.WorldServer;
++import org.bukkit.craftbukkit.entity.CraftLivingEntity;
++import org.bukkit.entity.LivingEntity;
+
+ public class EntityAreaEffectCloud extends Entity
+ {
+@@ -33,15 +32,15 @@
+ private static final DataParameter PARTICLE_PARAM_1 = EntityDataManager.createKey(EntityAreaEffectCloud.class, DataSerializers.VARINT);
+ private static final DataParameter PARTICLE_PARAM_2 = EntityDataManager.createKey(EntityAreaEffectCloud.class, DataSerializers.VARINT);
+ private PotionType potion;
+- private final List effects;
++ public final List effects;
+ private final Map reapplicationDelayMap;
+ private int duration;
+- private int waitTime;
+- private int reapplicationDelay;
++ public int waitTime;
++ public int reapplicationDelay;
+ private boolean colorSet;
+- private int durationOnUse;
+- private float radiusOnUse;
+- private float radiusPerTick;
++ public int durationOnUse;
++ public float radiusOnUse;
++ public float radiusPerTick;
+ private EntityLivingBase owner;
+ private UUID ownerUniqueId;
+
+@@ -126,6 +125,23 @@
+ }
+ }
+
++ // CraftBukkit start accessor methods
++ public void refreshEffects() {
++ if (!this.colorSet) {
++ this.getDataManager().set(EntityAreaEffectCloud.COLOR, PotionUtils.getPotionColorFromEffectList(PotionUtils.mergeEffects(this.potion, (Collection) this.effects)));
++ }
++ }
++
++ public String getType() {
++ return (PotionType.REGISTRY.getNameForObject(this.potion)).toString();
++ }
++
++ public void setType(String string) {
++ setPotion(PotionType.REGISTRY.getObject(new ResourceLocation(string)));
++ }
++ // CraftBukkit end
++
++
+ public int getColor()
+ {
+ return ((Integer)this.getDataManager().get(COLOR)).intValue();
+@@ -192,7 +208,12 @@
+ super.onUpdate();
+ boolean flag = this.shouldIgnoreRadius();
+ float f = this.getRadius();
+-
++ // Paper start - fix MC-114618
++ if (f < 0.5F) {
++ this.setDead();
++ return;
++ }
++ // Paper end
+ if (this.world.isRemote)
+ {
+ EnumParticleTypes enumparticletypes = this.getParticle();
+@@ -284,11 +305,13 @@
+ {
+ f += this.radiusPerTick;
+
+- if (f < 0.5F)
+- {
+- this.setDead();
+- return;
+- }
++ // Paper start - moved up - fix MC-114618
++ //if (f < 0.5F)
++ //{
++ // this.setDead();
++ // return;
++ //}
++ // Paper end
+
+ this.setRadius(f);
+ }
+@@ -326,6 +349,7 @@
+
+ if (!list.isEmpty())
+ {
++ List entities = new ArrayList<>();
+ for (EntityLivingBase entitylivingbase : list)
+ {
+ if (!this.reapplicationDelayMap.containsKey(entitylivingbase) && entitylivingbase.canBeHitWithPotion())
+@@ -336,6 +360,15 @@
+
+ if (d2 <= (double)(f * f))
+ {
++ entities.add((LivingEntity) entitylivingbase.getBukkitEntity());
++ }
++ }
++ }
++ org.bukkit.event.entity.AreaEffectCloudApplyEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callAreaEffectCloudApplyEvent(this, entities);
++ if (true) { // Preserve NMS spacing and bracket count for smallest diff
++ for (LivingEntity entity : event.getAffectedEntities()) {
++ if (entity instanceof CraftLivingEntity) {
++ EntityLivingBase entitylivingbase = ((CraftLivingEntity) entity).getHandle();
+ this.reapplicationDelayMap.put(entitylivingbase, Integer.valueOf(this.ticksExisted + this.reapplicationDelay));
+
+ for (PotionEffect potioneffect : potions)
diff --git a/patches/net/minecraft/entity/EntityCreature.java.patch b/patches/net/minecraft/entity/EntityCreature.java.patch
new file mode 100644
index 00000000..a659e8f1
--- /dev/null
+++ b/patches/net/minecraft/entity/EntityCreature.java.patch
@@ -0,0 +1,26 @@
+--- ../src-base/minecraft/net/minecraft/entity/EntityCreature.java
++++ ../src-work/minecraft/net/minecraft/entity/EntityCreature.java
+@@ -7,6 +7,7 @@
+ import net.minecraft.util.math.BlockPos;
+ import net.minecraft.util.math.Vec3d;
+ import net.minecraft.world.World;
++import org.bukkit.event.entity.EntityUnleashEvent;
+
+ public abstract class EntityCreature extends EntityLiving
+ {
+@@ -93,6 +94,7 @@
+ {
+ if (f > 10.0F)
+ {
++ this.world.getServer().getPluginManager().callEvent(new EntityUnleashEvent(this.getBukkitEntity(), EntityUnleashEvent.UnleashReason.DISTANCE));
+ this.clearLeashed(true, true);
+ }
+
+@@ -103,6 +105,7 @@
+
+ if (f > 10.0F)
+ {
++ this.world.getServer().getPluginManager().callEvent(new EntityUnleashEvent(this.getBukkitEntity(), EntityUnleashEvent.UnleashReason.DISTANCE));
+ this.clearLeashed(true, true);
+ this.tasks.disableControlFlag(1);
+ }
diff --git a/patches/net/minecraft/entity/EntityHanging.java.patch b/patches/net/minecraft/entity/EntityHanging.java.patch
new file mode 100644
index 00000000..f8e90ed8
--- /dev/null
+++ b/patches/net/minecraft/entity/EntityHanging.java.patch
@@ -0,0 +1,207 @@
+--- ../src-base/minecraft/net/minecraft/entity/EntityHanging.java
++++ ../src-work/minecraft/net/minecraft/entity/EntityHanging.java
+@@ -3,6 +3,7 @@
+ import com.google.common.base.Predicate;
+ import javax.annotation.Nullable;
+ import net.minecraft.block.BlockRedstoneDiode;
++import net.minecraft.block.material.Material;
+ import net.minecraft.block.state.IBlockState;
+ import net.minecraft.entity.effect.EntityLightningBolt;
+ import net.minecraft.entity.item.EntityItem;
+@@ -18,6 +19,9 @@
+ import net.minecraft.util.math.MathHelper;
+ import net.minecraft.world.World;
+ import org.apache.commons.lang3.Validate;
++import org.bukkit.entity.Hanging;
++import org.bukkit.event.hanging.HangingBreakByEntityEvent;
++import org.bukkit.event.hanging.HangingBreakEvent;
+
+ public abstract class EntityHanging extends Entity
+ {
+@@ -29,7 +33,7 @@
+ }
+ };
+ private int tickCounter1;
+- protected BlockPos hangingPosition;
++ public BlockPos hangingPosition;
+ @Nullable
+ public EnumFacing facingDirection;
+
+@@ -49,7 +53,7 @@
+ {
+ }
+
+- protected void updateFacingWithBoundingBox(EnumFacing facingDirectionIn)
++ public void updateFacingWithBoundingBox(EnumFacing facingDirectionIn)
+ {
+ Validate.notNull(facingDirectionIn);
+ Validate.isTrue(facingDirectionIn.getAxis().isHorizontal());
+@@ -63,42 +67,50 @@
+ {
+ if (this.facingDirection != null)
+ {
+- double d0 = (double)this.hangingPosition.getX() + 0.5D;
+- double d1 = (double)this.hangingPosition.getY() + 0.5D;
+- double d2 = (double)this.hangingPosition.getZ() + 0.5D;
+- double d3 = 0.46875D;
+- double d4 = this.offs(this.getWidthPixels());
+- double d5 = this.offs(this.getHeightPixels());
+- d0 = d0 - (double)this.facingDirection.getFrontOffsetX() * 0.46875D;
+- d2 = d2 - (double)this.facingDirection.getFrontOffsetZ() * 0.46875D;
+- d1 = d1 + d5;
+- EnumFacing enumfacing = this.facingDirection.rotateYCCW();
+- d0 = d0 + d4 * (double)enumfacing.getFrontOffsetX();
+- d2 = d2 + d4 * (double)enumfacing.getFrontOffsetZ();
+- this.posX = d0;
+- this.posY = d1;
+- this.posZ = d2;
+- double d6 = (double)this.getWidthPixels();
+- double d7 = (double)this.getHeightPixels();
+- double d8 = (double)this.getWidthPixels();
++ // CraftBukkit start code moved in to calculateBoundingBox
++ this.setEntityBoundingBox(calculateBoundingBox(this, this.hangingPosition, this.facingDirection, this.getWidthPixels(), this.getHeightPixels()));
++ // CraftBukkit end
++ }
++ }
+
+- if (this.facingDirection.getAxis() == EnumFacing.Axis.Z)
+- {
+- d8 = 1.0D;
+- }
+- else
+- {
+- d6 = 1.0D;
+- }
++ // CraftBukkit start - break out BB calc into own method
++ public static AxisAlignedBB calculateBoundingBox(Entity entity, BlockPos blockPosition, EnumFacing direction, int width, int height) {
++ double d0 = (double) blockPosition.getX() + 0.5D;
++ double d1 = (double) blockPosition.getY() + 0.5D;
++ double d2 = (double) blockPosition.getZ() + 0.5D;
++ double d3 = 0.46875D;
++ double d4 = offs(width);
++ double d5 = offs(height);
+
+- d6 = d6 / 32.0D;
+- d7 = d7 / 32.0D;
+- d8 = d8 / 32.0D;
+- this.setEntityBoundingBox(new AxisAlignedBB(d0 - d6, d1 - d7, d2 - d8, d0 + d6, d1 + d7, d2 + d8));
++ d0 -= (double) direction.getFrontOffsetX() * 0.46875D;
++ d2 -= (double) direction.getFrontOffsetZ() * 0.46875D;
++ d1 += d5;
++ EnumFacing enumdirection = direction.rotateYCCW();
++
++ d0 += d4 * (double) enumdirection.getFrontOffsetX();
++ d2 += d4 * (double) enumdirection.getFrontOffsetZ();
++ if (entity != null) {
++ entity.posX = d0;
++ entity.posY = d1;
++ entity.posZ = d2;
+ }
++ double d6 = (double) width;
++ double d7 = (double) height;
++ double d8 = (double) width;
++
++ if (direction.getAxis() == EnumFacing.Axis.Z) {
++ d8 = 1.0D;
++ } else {
++ d6 = 1.0D;
++ }
++
++ d6 /= 32.0D;
++ d7 /= 32.0D;
++ d8 /= 32.0D;
++ return new AxisAlignedBB(d0 - d6, d1 - d7, d2 - d8, d0 + d6, d1 + d7, d2 + d8);
+ }
+
+- private double offs(int p_190202_1_)
++ private static double offs(int p_190202_1_) // CraftBukkit - static
+ {
+ return p_190202_1_ % 32 == 0 ? 0.5D : 0.0D;
+ }
+@@ -109,12 +121,30 @@
+ this.prevPosY = this.posY;
+ this.prevPosZ = this.posZ;
+
+- if (this.tickCounter1++ == 100 && !this.world.isRemote)
++ if (this.tickCounter1++ == this.world.spigotConfig.hangingTickFrequency && !this.world.isRemote) // Spigot
+ {
+ this.tickCounter1 = 0;
+
+ if (!this.isDead && !this.onValidSurface())
+ {
++ // CraftBukkit start - fire break events
++ Material material = this.world.getBlockState(new BlockPos(this)).getMaterial();
++ HangingBreakEvent.RemoveCause cause;
++
++ if (!material.equals(Material.AIR)) {
++ // TODO: This feels insufficient to catch 100% of suffocation cases
++ cause = HangingBreakEvent.RemoveCause.OBSTRUCTION;
++ } else {
++ cause = HangingBreakEvent.RemoveCause.PHYSICS;
++ }
++
++ HangingBreakEvent event = new HangingBreakEvent((Hanging) this.getBukkitEntity(), cause);
++ this.world.getServer().getPluginManager().callEvent(event);
++
++ if (isDead || event.isCancelled()) {
++ return;
++ }
++ // CraftBukkit end
+ this.setDead();
+ this.onBroken((Entity)null);
+ }
+@@ -183,6 +213,20 @@
+ {
+ if (!this.isDead && !this.world.isRemote)
+ {
++ // CraftBukkit start - fire break events
++ HangingBreakEvent event = new HangingBreakEvent((Hanging) this.getBukkitEntity(), HangingBreakEvent.RemoveCause.DEFAULT);
++ if (source.getTrueSource() != null) {
++ event = new HangingBreakByEntityEvent((Hanging) this.getBukkitEntity(), source.getTrueSource() == null ? null : source.getTrueSource().getBukkitEntity(), source.isExplosion() ? HangingBreakEvent.RemoveCause.EXPLOSION : HangingBreakEvent.RemoveCause.ENTITY);
++ } else if (source.isExplosion()) {
++ event = new HangingBreakEvent((Hanging) this.getBukkitEntity(), HangingBreakEvent.RemoveCause.EXPLOSION);
++ }
++
++ this.world.getServer().getPluginManager().callEvent(event);
++
++ if (this.isDead || event.isCancelled()) {
++ return true;
++ }
++ // CraftBukkit end
+ this.setDead();
+ this.markVelocityChanged();
+ this.onBroken(source.getTrueSource());
+@@ -196,6 +240,15 @@
+ {
+ if (!this.world.isRemote && !this.isDead && x * x + y * y + z * z > 0.0D)
+ {
++ // CraftBukkit start - fire break events
++ // TODO - Does this need its own cause? Seems to only be triggered by pistons
++ HangingBreakEvent event = new HangingBreakEvent((Hanging) this.getBukkitEntity(), HangingBreakEvent.RemoveCause.PHYSICS);
++ this.world.getServer().getPluginManager().callEvent(event);
++
++ if (this.isDead || event.isCancelled()) {
++ return;
++ }
++ // CraftBukkit end
+ this.setDead();
+ this.onBroken((Entity)null);
+ }
+@@ -203,7 +256,7 @@
+
+ public void addVelocity(double x, double y, double z)
+ {
+- if (!this.world.isRemote && !this.isDead && x * x + y * y + z * z > 0.0D)
++ if (false && !this.world.isRemote && !this.isDead && x * x + y * y + z * z > 0.0D) // CraftBukkit - not needed
+ {
+ this.setDead();
+ this.onBroken((Entity)null);
+@@ -296,7 +349,7 @@
+ return this.getRotatedYaw(transformMirror.toRotation(this.facingDirection));
+ }
+
+- public void onStruckByLightning(EntityLightningBolt lightningBolt)
++ public void onStruckByLightning(@Nullable EntityLightningBolt lightningBolt)
+ {
+ }
+ }
diff --git a/patches/net/minecraft/entity/EntityLeashKnot.java.patch b/patches/net/minecraft/entity/EntityLeashKnot.java.patch
new file mode 100644
index 00000000..077b9ffc
--- /dev/null
+++ b/patches/net/minecraft/entity/EntityLeashKnot.java.patch
@@ -0,0 +1,63 @@
+--- ../src-base/minecraft/net/minecraft/entity/EntityLeashKnot.java
++++ ../src-work/minecraft/net/minecraft/entity/EntityLeashKnot.java
+@@ -4,8 +4,10 @@
+ import javax.annotation.Nullable;
+ import net.minecraft.block.BlockFence;
+ import net.minecraft.entity.player.EntityPlayer;
++import net.minecraft.entity.player.EntityPlayerMP;
+ import net.minecraft.init.SoundEvents;
+ import net.minecraft.nbt.NBTTagCompound;
++import net.minecraft.network.play.server.SPacketEntityAttach;
+ import net.minecraft.util.EnumFacing;
+ import net.minecraft.util.EnumHand;
+ import net.minecraft.util.math.AxisAlignedBB;
+@@ -14,6 +16,7 @@
+ import net.minecraft.world.World;
+ import net.minecraftforge.fml.relauncher.Side;
+ import net.minecraftforge.fml.relauncher.SideOnly;
++import org.bukkit.craftbukkit.event.CraftEventFactory;
+
+ public class EntityLeashKnot extends EntityHanging
+ {
+@@ -105,6 +108,12 @@
+ {
+ if (entityliving.getLeashed() && entityliving.getLeashHolder() == player)
+ {
++ // CraftBukkit start
++ if (CraftEventFactory.callPlayerLeashEntityEvent(entityliving, this, player).isCancelled()) {
++ ((EntityPlayerMP) player).connection.sendPacket(new SPacketEntityAttach(entityliving, entityliving.getLeashHolder()));
++ continue;
++ }
++ // CraftBukkit end
+ entityliving.setLeashHolder(this, true);
+ flag = true;
+ }
+@@ -112,17 +121,23 @@
+
+ if (!flag)
+ {
+- this.setDead();
+-
+- if (player.capabilities.isCreativeMode)
+- {
++ // CraftBukkit start - Move below
++ if (true || player.capabilities.isCreativeMode) { // CraftBukkit - Process for non-creative as well
++ boolean die = true;
+ for (EntityLiving entityliving1 : list)
+ {
+ if (entityliving1.getLeashed() && entityliving1.getLeashHolder() == this)
+ {
+- entityliving1.clearLeashed(true, false);
++ if (CraftEventFactory.callPlayerUnleashEntityEvent(entityliving1, player).isCancelled()) {
++ die = false;
++ continue;
++ }
++ entityliving1.clearLeashed(true, !player.capabilities.isCreativeMode); // false -> survival mode boolean
+ }
+ }
++ if (die) {
++ this.setDead();
++ }
+ }
+ }
+
diff --git a/patches/net/minecraft/entity/EntityLiving.java.patch b/patches/net/minecraft/entity/EntityLiving.java.patch
new file mode 100644
index 00000000..45c7200d
--- /dev/null
+++ b/patches/net/minecraft/entity/EntityLiving.java.patch
@@ -0,0 +1,290 @@
+--- ../src-base/minecraft/net/minecraft/entity/EntityLiving.java
++++ ../src-work/minecraft/net/minecraft/entity/EntityLiving.java
+@@ -8,25 +8,18 @@
+ import javax.annotation.Nullable;
+ import net.minecraft.block.state.IBlockState;
+ import net.minecraft.enchantment.EnchantmentHelper;
+-import net.minecraft.entity.ai.EntityAITasks;
+-import net.minecraft.entity.ai.EntityJumpHelper;
+-import net.minecraft.entity.ai.EntityLookHelper;
+-import net.minecraft.entity.ai.EntityMoveHelper;
+-import net.minecraft.entity.ai.EntitySenses;
++import net.minecraft.entity.ai.*;
+ import net.minecraft.entity.ai.attributes.AttributeModifier;
+ import net.minecraft.entity.item.EntityBoat;
+ import net.minecraft.entity.item.EntityItem;
+ import net.minecraft.entity.monster.EntityGhast;
+ import net.minecraft.entity.monster.IMob;
+ import net.minecraft.entity.player.EntityPlayer;
++import net.minecraft.entity.player.EntityPlayerMP;
+ import net.minecraft.init.Blocks;
+ import net.minecraft.init.Items;
+ import net.minecraft.inventory.EntityEquipmentSlot;
+-import net.minecraft.item.Item;
+-import net.minecraft.item.ItemArmor;
+-import net.minecraft.item.ItemBow;
+-import net.minecraft.item.ItemStack;
+-import net.minecraft.item.ItemSword;
++import net.minecraft.item.*;
+ import net.minecraft.nbt.NBTTagCompound;
+ import net.minecraft.nbt.NBTTagFloat;
+ import net.minecraft.nbt.NBTTagList;
+@@ -37,13 +30,7 @@
+ import net.minecraft.pathfinding.PathNavigate;
+ import net.minecraft.pathfinding.PathNavigateGround;
+ import net.minecraft.pathfinding.PathNodeType;
+-import net.minecraft.util.DamageSource;
+-import net.minecraft.util.EnumHand;
+-import net.minecraft.util.EnumHandSide;
+-import net.minecraft.util.EnumParticleTypes;
+-import net.minecraft.util.NonNullList;
+-import net.minecraft.util.ResourceLocation;
+-import net.minecraft.util.SoundEvent;
++import net.minecraft.util.*;
+ import net.minecraft.util.datafix.DataFixer;
+ import net.minecraft.util.datafix.FixTypes;
+ import net.minecraft.util.datafix.walkers.ItemStackDataLists;
+@@ -57,6 +44,13 @@
+ import net.minecraft.world.storage.loot.LootTable;
+ import net.minecraftforge.fml.relauncher.Side;
+ import net.minecraftforge.fml.relauncher.SideOnly;
++import org.bukkit.craftbukkit.entity.CraftLivingEntity;
++import org.bukkit.craftbukkit.event.CraftEventFactory;
++import org.bukkit.entity.LivingEntity;
++import org.bukkit.event.entity.EntityPickupItemEvent;
++import org.bukkit.event.entity.EntityTargetEvent;
++import org.bukkit.event.entity.EntityTargetLivingEntityEvent;
++import org.bukkit.event.entity.EntityUnleashEvent;
+
+ public abstract class EntityLiving extends EntityLivingBase
+ {
+@@ -68,16 +62,15 @@
+ protected EntityJumpHelper jumpHelper;
+ private final EntityBodyHelper bodyHelper;
+ protected PathNavigate navigator;
+- public final EntityAITasks tasks;
+- public final EntityAITasks targetTasks;
++ public EntityAITasks tasks;
++ public EntityAITasks targetTasks;
+ private EntityLivingBase attackTarget;
+ private final EntitySenses senses;
+ private final NonNullList inventoryHands = NonNullList.withSize(2, ItemStack.EMPTY);
+- protected float[] inventoryHandsDropChances = new float[2];
++ public float[] inventoryHandsDropChances = new float[2];
+ private final NonNullList inventoryArmor = NonNullList.withSize(4, ItemStack.EMPTY);
+- protected float[] inventoryArmorDropChances = new float[4];
+- private boolean canPickUpLoot;
+- private boolean persistenceRequired;
++ public float[] inventoryArmorDropChances = new float[4];
++ public boolean persistenceRequired;
+ private final Map mapPathPriority = Maps.newEnumMap(PathNodeType.class);
+ private ResourceLocation deathLootTable;
+ private long deathLootTableSeed;
+@@ -103,6 +96,10 @@
+ {
+ this.initEntityAI();
+ }
++
++ // CraftBukkit start - default persistance to type's persistance value
++ this.persistenceRequired = !canDespawn();
++ // CraftBukkit end
+ }
+
+ protected void initEntityAI()
+@@ -171,8 +168,37 @@
+ {
+ this.attackTarget = entitylivingbaseIn;
+ net.minecraftforge.common.ForgeHooks.onLivingSetAttackTarget(this, entitylivingbaseIn);
++ // CraftBukkit start - fire event
++ setAttackTarget(entitylivingbaseIn, EntityTargetEvent.TargetReason.UNKNOWN, true);
+ }
+
++ public boolean setAttackTarget(@Nullable EntityLivingBase entityliving, EntityTargetEvent.TargetReason reason, boolean fireEvent) {
++ if (getAttackTarget() == entityliving) return false;
++ if (fireEvent) {
++ if (reason == EntityTargetEvent.TargetReason.UNKNOWN && getAttackTarget() != null && entityliving == null) {
++ reason = getAttackTarget().isEntityAlive() ? EntityTargetEvent.TargetReason.FORGOT_TARGET : EntityTargetEvent.TargetReason.TARGET_DIED;
++ }
++ CraftLivingEntity ctarget = null;
++ if (entityliving != null) {
++ ctarget = (CraftLivingEntity) entityliving.getBukkitEntity();
++ }
++ EntityTargetLivingEntityEvent event = new EntityTargetLivingEntityEvent(this.getBukkitEntity(), ctarget, reason);
++ world.getServer().getPluginManager().callEvent(event);
++ if (event.isCancelled()) {
++ return false;
++ }
++
++ if (event.getTarget() != null) {
++ entityliving = ((CraftLivingEntity) event.getTarget()).getHandle();
++ } else {
++ entityliving = null;
++ }
++ }
++ this.attackTarget = entityliving;
++ return true;
++ // CraftBukkit end
++ }
++
+ public boolean canAttackClass(Class extends EntityLivingBase > cls)
+ {
+ return cls != EntityGhast.class;
+@@ -355,7 +381,7 @@
+ public void writeEntityToNBT(NBTTagCompound compound)
+ {
+ super.writeEntityToNBT(compound);
+- compound.setBoolean("CanPickUpLoot", this.canPickUpLoot());
++ compound.setBoolean("CanPickUpLoot", this.thisisatestof());
+ compound.setBoolean("PersistenceRequired", this.persistenceRequired);
+ NBTTagList nbttaglist = new NBTTagList();
+
+@@ -447,12 +473,21 @@
+ {
+ super.readEntityFromNBT(compound);
+
++ // CraftBukkit start - If looting or persistence is false only use it if it was set after we started using it
+ if (compound.hasKey("CanPickUpLoot", 1))
+ {
+- this.setCanPickUpLoot(compound.getBoolean("CanPickUpLoot"));
++ // this.idkwhyreyoudoingthis(compound.getBoolean("CanPickUpLoot"));
++ boolean data = compound.getBoolean("CanPickUpLoot");
++ if (isLevelAtLeast(compound, 1) || data) {
++ this.idkwhyreyoudoingthis(data);
++ }
+ }
+
+- this.persistenceRequired = compound.getBoolean("PersistenceRequired");
++ // this.persistenceRequired = compound.getBoolean("PersistenceRequired");
++ boolean data = compound.getBoolean("PersistenceRequired");
++ if (isLevelAtLeast(compound, 1) || data) {
++ this.persistenceRequired = data;
++ }
+
+ if (compound.hasKey("ArmorItems", 9))
+ {
+@@ -577,7 +612,7 @@
+ super.onLivingUpdate();
+ this.world.profiler.startSection("looting");
+
+- if (!this.world.isRemote && this.canPickUpLoot() && !this.dead && net.minecraftforge.event.ForgeEventFactory.getMobGriefingEvent(this.world, this))
++ if (!this.world.isRemote && this.thisisatestof() && !this.dead && net.minecraftforge.event.ForgeEventFactory.getMobGriefingEvent(this.world, this))
+ {
+ for (EntityItem entityitem : this.world.getEntitiesWithinAABB(EntityItem.class, this.getEntityBoundingBox().grow(1.0D, 0.0D, 1.0D)))
+ {
+@@ -653,8 +688,14 @@
+ }
+ }
+
+- if (flag && this.canEquipItem(itemstack))
+- {
++ // if (flag && this.canEquipItem(itemstack)) {
++ boolean canPickup = flag && this.canEquipItem(itemstack);
++
++ EntityPickupItemEvent entityEvent = new EntityPickupItemEvent((LivingEntity) getBukkitEntity(), (org.bukkit.entity.Item) itemEntity.getBukkitEntity(), 0);
++ entityEvent.setCancelled(!canPickup);
++ this.world.getServer().getPluginManager().callEvent(entityEvent);
++ canPickup = !entityEvent.isCancelled();
++ if (canPickup) {
+ double d0;
+
+ switch (entityequipmentslot.getSlotType())
+@@ -696,7 +737,7 @@
+ return true;
+ }
+
+- protected boolean canDespawn()
++ public boolean canDespawn()
+ {
+ return true;
+ }
+@@ -730,12 +771,12 @@
+ double d2 = entity.posZ - this.posZ;
+ double d3 = d0 * d0 + d1 * d1 + d2 * d2;
+
+- if (this.canDespawn() && d3 > 16384.0D)
++ if (/*this.canDespawn() && */d3 > 16384.0D) // CraftBukkit - remove canDespawn() check
+ {
+ this.setDead();
+ }
+
+- if (this.idleTime > 600 && this.rand.nextInt(800) == 0 && d3 > 1024.0D && this.canDespawn())
++ if (this.idleTime > 600 && this.rand.nextInt(800) == 0 && d3 > 1024.0D/* && this.canDespawn()*/) // CraftBukkit - remove canDespawn() check
+ {
+ this.setDead();
+ }
+@@ -753,6 +794,12 @@
+ this.world.profiler.startSection("checkDespawn");
+ this.despawnEntity();
+ this.world.profiler.endSection();
++ // Spigot Start
++ if (this.fromMobSpawner)
++ {
++ return;
++ }
++ // Spigot End
+ this.world.profiler.startSection("sensing");
+ this.senses.clearSensingCache();
+ this.world.profiler.endSection();
+@@ -1190,14 +1237,14 @@
+ }
+ }
+
+- public boolean canPickUpLoot()
++ public boolean thisisatestof()
+ {
+- return this.canPickUpLoot;
++ return thisisatest;
+ }
+
+- public void setCanPickUpLoot(boolean canPickup)
++ public void idkwhyreyoudoingthis(boolean canPickup)
+ {
+- this.canPickUpLoot = canPickup;
++ thisisatest = canPickup;
+ }
+
+ public boolean isNoDespawnRequired()
+@@ -1209,6 +1256,10 @@
+ {
+ if (this.getLeashed() && this.getLeashHolder() == player)
+ {
++ if (CraftEventFactory.callPlayerUnleashEntityEvent(this, player).isCancelled()) {
++ ((EntityPlayerMP) player).connection.sendPacket(new SPacketEntityAttach(this, this.getLeashHolder()));
++ return false;
++ }
+ this.clearLeashed(true, !player.capabilities.isCreativeMode);
+ return true;
+ }
+@@ -1218,6 +1269,10 @@
+
+ if (itemstack.getItem() == Items.LEAD && this.canBeLeashedTo(player))
+ {
++ if (CraftEventFactory.callPlayerLeashEntityEvent(this, player, player).isCancelled()) {
++ ((EntityPlayerMP) player).connection.sendPacket(new SPacketEntityAttach(this, this.getLeashHolder()));
++ return false;
++ }
+ this.setLeashHolder(player, true);
+ itemstack.shrink(1);
+ return true;
+@@ -1245,11 +1300,13 @@
+ {
+ if (!this.isEntityAlive())
+ {
++ this.world.getServer().getPluginManager().callEvent(new EntityUnleashEvent(this.getBukkitEntity(), EntityUnleashEvent.UnleashReason.PLAYER_UNLEASH));
+ this.clearLeashed(true, true);
+ }
+
+ if (this.leashHolder == null || this.leashHolder.isDead)
+ {
++ this.world.getServer().getPluginManager().callEvent(new EntityUnleashEvent(this.getBukkitEntity(), EntityUnleashEvent.UnleashReason.HOLDER_GONE));
+ this.clearLeashed(true, true);
+ }
+ }
+@@ -1348,6 +1405,7 @@
+ }
+ else
+ {
++ this.world.getServer().getPluginManager().callEvent(new EntityUnleashEvent(this.getBukkitEntity(), EntityUnleashEvent.UnleashReason.UNKNOWN));
+ this.clearLeashed(false, true);
+ }
+ }
diff --git a/patches/net/minecraft/entity/EntityLivingBase.java.patch b/patches/net/minecraft/entity/EntityLivingBase.java.patch
new file mode 100644
index 00000000..f78d4922
--- /dev/null
+++ b/patches/net/minecraft/entity/EntityLivingBase.java.patch
@@ -0,0 +1,875 @@
+--- ../src-base/minecraft/net/minecraft/entity/EntityLivingBase.java
++++ ../src-work/minecraft/net/minecraft/entity/EntityLivingBase.java
+@@ -1,7 +1,11 @@
+ package net.minecraft.entity;
+
++import com.google.common.base.Function;
+ import com.google.common.base.Objects;
++import com.google.common.collect.Lists;
+ import com.google.common.collect.Maps;
++
++import java.util.ArrayList;
+ import java.util.Collection;
+ import java.util.ConcurrentModificationException;
+ import java.util.Iterator;
+@@ -19,6 +23,7 @@
+ import net.minecraft.block.state.IBlockState;
+ import net.minecraft.enchantment.EnchantmentFrostWalker;
+ import net.minecraft.enchantment.EnchantmentHelper;
++import net.minecraft.entity.ai.EntityAISit;
+ import net.minecraft.entity.ai.attributes.AbstractAttributeMap;
+ import net.minecraft.entity.ai.attributes.AttributeMap;
+ import net.minecraft.entity.ai.attributes.AttributeModifier;
+@@ -28,7 +33,8 @@
+ import net.minecraft.entity.item.EntityItem;
+ import net.minecraft.entity.item.EntityXPOrb;
+ import net.minecraft.entity.passive.AbstractHorse;
+-import net.minecraft.entity.passive.EntityWolf;
++import net.minecraft.entity.passive.EntityAnimal;
++import net.minecraft.entity.passive.EntityTameable;
+ import net.minecraft.entity.player.EntityPlayer;
+ import net.minecraft.entity.player.EntityPlayerMP;
+ import net.minecraft.entity.projectile.EntityArrow;
+@@ -43,7 +49,10 @@
+ import net.minecraft.item.ItemArmor;
+ import net.minecraft.item.ItemElytra;
+ import net.minecraft.item.ItemStack;
++import net.minecraft.nbt.NBTBase;
+ import net.minecraft.nbt.NBTTagCompound;
++import net.minecraft.nbt.NBTTagFloat;
++import net.minecraft.nbt.NBTTagInt;
+ import net.minecraft.nbt.NBTTagList;
+ import net.minecraft.network.datasync.DataParameter;
+ import net.minecraft.network.datasync.DataSerializers;
+@@ -76,21 +85,32 @@
+ import net.minecraftforge.fml.relauncher.SideOnly;
+ import org.apache.logging.log4j.LogManager;
+ import org.apache.logging.log4j.Logger;
++import org.bukkit.Location;
++import org.bukkit.craftbukkit.attribute.CraftAttributeMap;
++import org.bukkit.craftbukkit.event.CraftEventFactory;
++import org.bukkit.craftbukkit.inventory.CraftItemStack;
++import org.bukkit.entity.LivingEntity;
++import org.bukkit.entity.Player;
++import org.bukkit.event.entity.EntityDamageEvent;
++import org.bukkit.event.entity.EntityRegainHealthEvent;
++import org.bukkit.event.entity.EntityResurrectEvent;
++import org.bukkit.event.entity.EntityTeleportEvent;
++import org.bukkit.event.player.PlayerItemConsumeEvent;
+
+ public abstract class EntityLivingBase extends Entity
+ {
+ private static final Logger LOGGER = LogManager.getLogger();
+ private static final UUID SPRINTING_SPEED_BOOST_ID = UUID.fromString("662A6B8D-DA3E-4C1C-8813-96EA6097278D");
+ private static final AttributeModifier SPRINTING_SPEED_BOOST = (new AttributeModifier(SPRINTING_SPEED_BOOST_ID, "Sprinting speed boost", 0.30000001192092896D, 2)).setSaved(false);
+- public static final net.minecraft.entity.ai.attributes.IAttribute SWIM_SPEED = new net.minecraft.entity.ai.attributes.RangedAttribute(null, "forge.swimSpeed", 1.0D, 0.0D, 1024.0D).setShouldWatch(true);
++ public static final IAttribute SWIM_SPEED = new net.minecraft.entity.ai.attributes.RangedAttribute(null, "forge.swimSpeed", 1.0D, 0.0D, 1024.0D).setShouldWatch(true);
+ protected static final DataParameter HAND_STATES = EntityDataManager.createKey(EntityLivingBase.class, DataSerializers.BYTE);
+- private static final DataParameter HEALTH = EntityDataManager.createKey(EntityLivingBase.class, DataSerializers.FLOAT);
++ public static final DataParameter HEALTH = EntityDataManager.createKey(EntityLivingBase.class, DataSerializers.FLOAT);
+ private static final DataParameter POTION_EFFECTS = EntityDataManager.createKey(EntityLivingBase.class, DataSerializers.VARINT);
+ private static final DataParameter HIDE_PARTICLES = EntityDataManager.createKey(EntityLivingBase.class, DataSerializers.BOOLEAN);
+ private static final DataParameter ARROW_COUNT_IN_ENTITY = EntityDataManager.createKey(EntityLivingBase.class, DataSerializers.VARINT);
+ private AbstractAttributeMap attributeMap;
+- private final CombatTracker _combatTracker = new CombatTracker(this);
+- private final Map activePotionsMap = Maps.newHashMap();
++ public CombatTracker _combatTracker = new CombatTracker(this);
++ public final Map activePotionsMap = Maps.newHashMap(); // Spigot
+ private final NonNullList handInventory = NonNullList.withSize(2, ItemStack.EMPTY);
+ private final NonNullList armorArray = NonNullList.withSize(4, ItemStack.EMPTY);
+ public boolean isSwingInProgress;
+@@ -117,7 +137,7 @@
+ public float rotationYawHead;
+ public float prevRotationYawHead;
+ public float jumpMovementFactor = 0.02F;
+- protected EntityPlayer attackingPlayer;
++ public EntityPlayer attackingPlayer;
+ protected int recentlyHit;
+ protected boolean dead;
+ protected int idleTime;
+@@ -127,7 +147,7 @@
+ protected float prevMovedDistance;
+ protected float unused180;
+ protected int scoreValue;
+- protected float lastDamage;
++ public float lastDamage;
+ protected boolean isJumping;
+ public float moveStrafing;
+ public float moveVertical;
+@@ -139,9 +159,9 @@
+ protected double interpTargetZ;
+ protected double interpTargetYaw;
+ protected double interpTargetPitch;
+- private boolean potionsNeedUpdate = true;
+- private EntityLivingBase revengeTarget;
+- private int revengeTimer;
++ public boolean potionsNeedUpdate = true;
++ public EntityLivingBase revengeTarget;
++ public int revengeTimer;
+ private EntityLivingBase lastAttackedEntity;
+ private int lastAttackedEntityTime;
+ private float landMovementFactor;
+@@ -154,6 +174,23 @@
+ private DamageSource lastDamageSource;
+ private long lastDamageStamp;
+
++ // CraftBukkit start
++ public int expToDrop;
++ public int maxAirTicks = 300;
++ public ArrayList drops = new ArrayList<>();
++ public org.bukkit.craftbukkit.attribute.CraftAttributeMap craftAttributes;
++ public boolean collides = true;
++ public boolean thisisatest;
++ // CraftBukkit end
++
++ // Spigot start
++ public void inactiveTick()
++ {
++ super.inactiveTick();
++ ++this.idleTime; // Above all the floats
++ }
++ // Spigot end
++
+ public void onKillCommand()
+ {
+ this.attackEntityFrom(DamageSource.OUT_OF_WORLD, Float.MAX_VALUE);
+@@ -163,7 +200,9 @@
+ {
+ super(worldIn);
+ this.applyEntityAttributes();
+- this.setHealth(this.getMaxHealth());
++ // CraftBukkit - setHealth(getMaxHealth()) inlined and simplified to skip the instanceof check for EntityPlayer, as getBukkitEntity() is not initialized in constructor
++ // this.setHealth(this.getMaxHealth());
++ this.dataManager.set(EntityLiving.HEALTH, (float) this.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).getAttributeValue());
+ this.preventEntitySpawning = true;
+ this.randomUnused1 = (float)((Math.random() + 1.0D) * 0.009999999776482582D);
+ this.setPosition(this.posX, this.posY, this.posZ);
+@@ -207,8 +246,17 @@
+ {
+ double d0 = Math.min((double)(0.2F + f / 15.0F), 2.5D);
+ int i = (int)(150.0D * d0);
+- if (!state.getBlock().addLandingEffects(state, (WorldServer)this.world, pos, state, this, i))
+- ((WorldServer)this.world).spawnParticle(EnumParticleTypes.BLOCK_DUST, this.posX, this.posY, this.posZ, i, 0.0D, 0.0D, 0.0D, 0.15000000596046448D, Block.getStateId(state));
++ if (!state.getBlock().addLandingEffects(state, (WorldServer)this.world, pos, state, this, i)) {
++ // ((WorldServer) this.world).spawnParticle(EnumParticleTypes.BLOCK_DUST, this.posX, this.posY, this.posZ, i, 0.0D, 0.0D, 0.0D, 0.15000000596046448D, Block.getStateId(state));
++ // TODO: Is it correct to perform this code inside this if-statement?
++ // CraftBukkit start - visiblity api
++ if (this instanceof EntityPlayer) {
++ ((WorldServer) this.world).sendParticles((EntityPlayerMP) this, EnumParticleTypes.BLOCK_DUST, false, this.posX, this.posY, this.posZ, i, 0.0D, 0.0D, 0.0D, 0.15000000596046448D, new int[]{Block.getStateId(state)});
++ } else {
++ ((WorldServer) this.world).spawnParticle(EnumParticleTypes.BLOCK_DUST, this.posX, this.posY, this.posZ, i, 0.0D, 0.0D, 0.0D, 0.15000000596046448D, new int[]{Block.getStateId(state)});
++ }
++ // CraftBukkit end
++ }
+ }
+ }
+
+@@ -258,9 +306,13 @@
+
+ if (this.isEntityAlive())
+ {
+- if (!this.isInsideOfMaterial(Material.WATER))
+- {
+- this.setAir(300);
++ if (!this.isInsideOfMaterial(Material.WATER)) {
++ // this.setAir(300);
++ // CraftBukkit start - Only set if needed to work around a DataWatcher inefficiency
++ if (this.getAir() != 300) {
++ this.setAir(maxAirTicks);
++ }
++ // CraftBukkit end
+ }
+ else
+ {
+@@ -359,6 +411,18 @@
+ this.world.profiler.endSection();
+ }
+
++ // CraftBukkit start
++ public int getExpReward() {
++ int exp = this.getExperiencePoints(this.attackingPlayer);
++
++ if (!this.world.isRemote && (this.recentlyHit > 0 || this.isPlayer()) && this.canDropLoot() && this.world.getGameRules().getBoolean("doMobLoot")) {
++ return exp;
++ } else {
++ return 0;
++ }
++ }
++ // CraftBukkit end
++
+ protected void frostWalk(BlockPos pos)
+ {
+ int i = EnchantmentHelper.getMaxEnchantmentLevel(Enchantments.FROST_WALKER, this);
+@@ -378,11 +442,10 @@
+ {
+ ++this.deathTime;
+
+- if (this.deathTime == 20)
++ if (this.deathTime >= 20 && !this.isDead) // CraftBukkit - (this.deathTime == 20) -> (this.deathTime >= 20 && !this.isDead)
+ {
+- if (!this.world.isRemote && (this.isPlayer() || this.recentlyHit > 0 && this.canDropLoot() && this.world.getGameRules().getBoolean("doMobLoot")))
+- {
+- int i = this.getExperiencePoints(this.attackingPlayer);
++ // if (!this.world.isRemote && (this.isPlayer() || this.recentlyHit > 0 && this.canDropLoot() && this.world.getGameRules().getBoolean("doMobLoot"))) {
++ int i = this.expToDrop;
+ i = net.minecraftforge.event.ForgeEventFactory.getExperienceDrop(this, this.attackingPlayer, i);
+ while (i > 0)
+ {
+@@ -390,7 +453,7 @@
+ i -= j;
+ this.world.spawnEntity(new EntityXPOrb(this.world, this.posX, this.posY, this.posZ, j));
+ }
+- }
++ this.expToDrop = 0;
+
+ this.setDead();
+
+@@ -445,6 +508,7 @@
+ {
+ this.revengeTarget = livingBase;
+ this.revengeTimer = this.ticksExisted;
++ net.minecraftforge.common.ForgeHooks.onLivingSetAttackTarget(this, livingBase);
+ }
+
+ public EntityLivingBase getLastAttackedEntity()
+@@ -566,6 +630,17 @@
+ }
+ }
+
++ // CraftBukkit start
++ if (compound.hasKey("Bukkit.MaxHealth")) {
++ NBTBase nbtbase = compound.getTag("Bukkit.MaxHealth");
++ if (nbtbase.getId() == 5) {
++ this.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(((NBTTagFloat) nbtbase).getDouble());
++ } else if (nbtbase.getId() == 3) {
++ this.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(((NBTTagInt) nbtbase).getDouble());
++ }
++ }
++ // CraftBukkit end
++
+ if (compound.hasKey("Health", 99))
+ {
+ this.setHealth(compound.getFloat("Health"));
+@@ -592,9 +667,15 @@
+ }
+ }
+
++ // CraftBukkit start
++ private boolean isTickingEffects = false;
++ private List