This commit is contained in:
Taylor Shuler 2014-05-11 20:47:41 +00:00
commit 593e683966
63 changed files with 8225 additions and 2680 deletions

7
.gitignore vendored
View File

@ -1,7 +1,14 @@
# Ignore Eclipse related things
build/
.classpath
.project
.gradle/
.settings/
eclipse/
bin/
repo/
# Ignore OS cache files and directories
*.DS_Store
_MACOSX
Thumbs.db

28
CREDITS-fml.txt Normal file
View File

@ -0,0 +1,28 @@
This is Forge Mod Loader.
You can find the source code at all times at https://github.com/MinecraftForge/FML
This minecraft mod is a clean open source implementation of a mod loader for minecraft servers
and minecraft clients.
The code is authored by cpw.
It began by partially implementing an API defined by the client side ModLoader, authored by Risugami.
http://www.minecraftforum.net/topic/75440-
This support has been dropped as of Minecraft release 1.7, as Risugami no longer maintains ModLoader.
It also contains suggestions and hints and generous helpings of code from LexManos, author of MinecraftForge.
http://www.minecraftforge.net/
Additionally, it contains an implementation of topological sort based on that
published at http://keithschwarz.com/interesting/code/?dir=topological-sort
It also contains code from the Maven project for performing versioned dependency
resolution. http://maven.apache.org/
It also contains a partial repackaging of the javaxdelta library from http://sourceforge.net/projects/javaxdelta/
with credit to it's authors.
Forge Mod Loader downloads components from the Minecraft Coder Pack
(http://mcp.ocean-labs.de/index.php/Main_Page) with kind permission from the MCP team.

491
LICENSE-fml.txt Normal file
View File

@ -0,0 +1,491 @@
This minecraft mod, Forge Mod Loader, including all parts herein except as noted below,
is licensed under the GNU LGPL v2.1 or later.
Homepage: https://github.com/MinecraftForge/FML
This software includes portions from the Apache Maven project at
http://maven.apache.org/ specifically the ComparableVersion.java code. It is
included based on guidelines at
http://www.softwarefreedom.org/resources/2007/gpl-non-gpl-collaboration.html
with notices intact. The only change is a non-functional change of package name.
This software contains a partial repackaging of javaxdelta, a BSD licensed program for generating
binary differences and applying them, sourced from the subversion at http://sourceforge.net/projects/javaxdelta/
authored by genman, heikok, pivot.
The only changes are to replace some Trove collection types with standard Java collections, and repackaged.
=== MCP Data ===
This software includes data from the Minecraft Coder Pack (MCP), with kind permission
from them. The license to MCP data is not transitive - distribution of this data by
third parties requires independent licensing from the MCP team. This data is not
redistributable without permission from the MCP team.
=== Sharing ===
I grant permission for some parts of FML to be redistributed outside the terms of the LGPL, for the benefit of
the minecraft modding community. All contributions to these parts should be licensed under the same additional grant.
-- Runtime patcher --
License is granted to redistribute the runtime patcher code (common/cpw/mods/fml/patcher and subdirectories) under
any alternative open source license as classified by the OSI (http://opensource.org/licenses)
-- ASM transformers --
License is granted to redistribute the ASM transformer code (common/cpw/mods/fml/common/asm/ and subdirectories)
under any alternative open source license as classified by the OSI (http://opensource.org/licenses)
========
GNU LESSER GENERAL PUBLIC LICENSE
Version 2.1, February 1999
Copyright (C) 1991, 1999 Free Software Foundation, Inc.
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
Licenses are intended to guarantee your freedom to share and change
free software--to make sure the software is free for all its users.
This license, the Lesser General Public License, applies to some
specially designated software packages--typically libraries--of the
Free Software Foundation and other authors who decide to use it. You
can use it too, but we suggest you first think carefully about whether
this license or the ordinary General Public License is the better
strategy to use in any particular case, based on the explanations below.
When we speak of free software, we are referring to freedom of use,
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 this service if you wish); that you receive source code or can get
it if you want it; that you can change the software and use pieces of
it in new free programs; and that you are informed that you can do
these things.
To protect your rights, we need to make restrictions that forbid
distributors to deny you these rights or to ask you to surrender these
rights. These restrictions translate to certain responsibilities for
you if you distribute copies of the library or if you modify it.
For example, if you distribute copies of the library, whether gratis
or for a fee, you must give the recipients all the rights that we gave
you. You must make sure that they, too, receive or can get the source
code. If you link other code with the library, you must provide
complete object files to the recipients, so that they can relink them
with the library after making changes to the library and recompiling
it. And you must show them these terms so they know their rights.
We protect your rights with a two-step method: (1) we copyright the
library, and (2) we offer you this license, which gives you legal
permission to copy, distribute and/or modify the library.
To protect each distributor, we want to make it very clear that
there is no warranty for the free library. Also, if the library is
modified by someone else and passed on, the recipients should know
that what they have is not the original version, so that the original
author's reputation will not be affected by problems that might be
introduced by others.
Finally, software patents pose a constant threat to the existence of
any free program. We wish to make sure that a company cannot
effectively restrict the users of a free program by obtaining a
restrictive license from a patent holder. Therefore, we insist that
any patent license obtained for a version of the library must be
consistent with the full freedom of use specified in this license.
Most GNU software, including some libraries, is covered by the
ordinary GNU General Public License. This license, the GNU Lesser
General Public License, applies to certain designated libraries, and
is quite different from the ordinary General Public License. We use
this license for certain libraries in order to permit linking those
libraries into non-free programs.
When a program is linked with a library, whether statically or using
a shared library, the combination of the two is legally speaking a
combined work, a derivative of the original library. The ordinary
General Public License therefore permits such linking only if the
entire combination fits its criteria of freedom. The Lesser General
Public License permits more lax criteria for linking other code with
the library.
We call this license the "Lesser" General Public License because it
does Less to protect the user's freedom than the ordinary General
Public License. It also provides other free software developers Less
of an advantage over competing non-free programs. These disadvantages
are the reason we use the ordinary General Public License for many
libraries. However, the Lesser license provides advantages in certain
special circumstances.
For example, on rare occasions, there may be a special need to
encourage the widest possible use of a certain library, so that it becomes
a de-facto standard. To achieve this, non-free programs must be
allowed to use the library. A more frequent case is that a free
library does the same job as widely used non-free libraries. In this
case, there is little to gain by limiting the free library to free
software only, so we use the Lesser General Public License.
In other cases, permission to use a particular library in non-free
programs enables a greater number of people to use a large body of
free software. For example, permission to use the GNU C Library in
non-free programs enables many more people to use the whole GNU
operating system, as well as its variant, the GNU/Linux operating
system.
Although the Lesser General Public License is Less protective of the
users' freedom, it does ensure that the user of a program that is
linked with the Library has the freedom and the wherewithal to run
that program using a modified version of the Library.
The precise terms and conditions for copying, distribution and
modification follow. Pay close attention to the difference between a
"work based on the library" and a "work that uses the library". The
former contains code derived from the library, whereas the latter must
be combined with the library in order to run.
GNU LESSER GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License Agreement applies to any software library or other
program which contains a notice placed by the copyright holder or
other authorized party saying it may be distributed under the terms of
this Lesser General Public License (also called "this License").
Each licensee is addressed as "you".
A "library" means a collection of software functions and/or data
prepared so as to be conveniently linked with application programs
(which use some of those functions and data) to form executables.
The "Library", below, refers to any such software library or work
which has been distributed under these terms. A "work based on the
Library" means either the Library or any derivative work under
copyright law: that is to say, a work containing the Library or a
portion of it, either verbatim or with modifications and/or translated
straightforwardly into another language. (Hereinafter, translation is
included without limitation in the term "modification".)
"Source code" for a work means the preferred form of the work for
making modifications to it. For a library, complete source code means
all the source code for all modules it contains, plus any associated
interface definition files, plus the scripts used to control compilation
and installation of the library.
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running a program using the Library is not restricted, and output from
such a program is covered only if its contents constitute a work based
on the Library (independent of the use of the Library in a tool for
writing it). Whether that is true depends on what the Library does
and what the program that uses the Library does.
1. You may copy and distribute verbatim copies of the Library's
complete source code as you receive it, in any medium, provided that
you conspicuously and appropriately publish on each copy an
appropriate copyright notice and disclaimer of warranty; keep intact
all the notices that refer to this License and to the absence of any
warranty; and distribute a copy of this License along with the
Library.
You may charge a fee for the physical act of transferring a copy,
and you may at your option offer warranty protection in exchange for a
fee.
2. You may modify your copy or copies of the Library or any portion
of it, thus forming a work based on the Library, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) The modified work must itself be a software library.
b) You must cause the files modified to carry prominent notices
stating that you changed the files and the date of any change.
c) You must cause the whole of the work to be licensed at no
charge to all third parties under the terms of this License.
d) If a facility in the modified Library refers to a function or a
table of data to be supplied by an application program that uses
the facility, other than as an argument passed when the facility
is invoked, then you must make a good faith effort to ensure that,
in the event an application does not supply such function or
table, the facility still operates, and performs whatever part of
its purpose remains meaningful.
(For example, a function in a library to compute square roots has
a purpose that is entirely well-defined independent of the
application. Therefore, Subsection 2d requires that any
application-supplied function or table used by this function must
be optional: if the application does not supply it, the square
root function must still compute square roots.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Library,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Library, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote
it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Library.
In addition, mere aggregation of another work not based on the Library
with the Library (or with a work based on the Library) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may opt to apply the terms of the ordinary GNU General Public
License instead of this License to a given copy of the Library. To do
this, you must alter all the notices that refer to this License, so
that they refer to the ordinary GNU General Public License, version 2,
instead of to this License. (If a newer version than version 2 of the
ordinary GNU General Public License has appeared, then you can specify
that version instead if you wish.) Do not make any other change in
these notices.
Once this change is made in a given copy, it is irreversible for
that copy, so the ordinary GNU General Public License applies to all
subsequent copies and derivative works made from that copy.
This option is useful when you wish to copy part of the code of
the Library into a program that is not a library.
4. You may copy and distribute the Library (or a portion or
derivative of it, under Section 2) in object code or executable form
under the terms of Sections 1 and 2 above provided that you accompany
it with the complete corresponding machine-readable source code, which
must be distributed under the terms of Sections 1 and 2 above on a
medium customarily used for software interchange.
If distribution of object code is made by offering access to copy
from a designated place, then offering equivalent access to copy the
source code from the same place satisfies the requirement to
distribute the source code, even though third parties are not
compelled to copy the source along with the object code.
5. A program that contains no derivative of any portion of the
Library, but is designed to work with the Library by being compiled or
linked with it, is called a "work that uses the Library". Such a
work, in isolation, is not a derivative work of the Library, and
therefore falls outside the scope of this License.
However, linking a "work that uses the Library" with the Library
creates an executable that is a derivative of the Library (because it
contains portions of the Library), rather than a "work that uses the
library". The executable is therefore covered by this License.
Section 6 states terms for distribution of such executables.
When a "work that uses the Library" uses material from a header file
that is part of the Library, the object code for the work may be a
derivative work of the Library even though the source code is not.
Whether this is true is especially significant if the work can be
linked without the Library, or if the work is itself a library. The
threshold for this to be true is not precisely defined by law.
If such an object file uses only numerical parameters, data
structure layouts and accessors, and small macros and small inline
functions (ten lines or less in length), then the use of the object
file is unrestricted, regardless of whether it is legally a derivative
work. (Executables containing this object code plus portions of the
Library will still fall under Section 6.)
Otherwise, if the work is a derivative of the Library, you may
distribute the object code for the work under the terms of Section 6.
Any executables containing that work also fall under Section 6,
whether or not they are linked directly with the Library itself.
6. As an exception to the Sections above, you may also combine or
link a "work that uses the Library" with the Library to produce a
work containing portions of the Library, and distribute that work
under terms of your choice, provided that the terms permit
modification of the work for the customer's own use and reverse
engineering for debugging such modifications.
You must give prominent notice with each copy of the work that the
Library is used in it and that the Library and its use are covered by
this License. You must supply a copy of this License. If the work
during execution displays copyright notices, you must include the
copyright notice for the Library among them, as well as a reference
directing the user to the copy of this License. Also, you must do one
of these things:
a) Accompany the work with the complete corresponding
machine-readable source code for the Library including whatever
changes were used in the work (which must be distributed under
Sections 1 and 2 above); and, if the work is an executable linked
with the Library, with the complete machine-readable "work that
uses the Library", as object code and/or source code, so that the
user can modify the Library and then relink to produce a modified
executable containing the modified Library. (It is understood
that the user who changes the contents of definitions files in the
Library will not necessarily be able to recompile the application
to use the modified definitions.)
b) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (1) uses at run time a
copy of the library already present on the user's computer system,
rather than copying library functions into the executable, and (2)
will operate properly with a modified version of the library, if
the user installs one, as long as the modified version is
interface-compatible with the version that the work was made with.
c) Accompany the work with a written offer, valid for at
least three years, to give the same user the materials
specified in Subsection 6a, above, for a charge no more
than the cost of performing this distribution.
d) If distribution of the work is made by offering access to copy
from a designated place, offer equivalent access to copy the above
specified materials from the same place.
e) Verify that the user has already received a copy of these
materials or that you have already sent this user a copy.
For an executable, the required form of the "work that uses the
Library" must include any data and utility programs needed for
reproducing the executable from it. However, as a special exception,
the materials to be distributed need not include anything that is
normally distributed (in either source or binary form) with the major
components (compiler, kernel, and so on) of the operating system on
which the executable runs, unless that component itself accompanies
the executable.
It may happen that this requirement contradicts the license
restrictions of other proprietary libraries that do not normally
accompany the operating system. Such a contradiction means you cannot
use both them and the Library together in an executable that you
distribute.
7. You may place library facilities that are a work based on the
Library side-by-side in a single library together with other library
facilities not covered by this License, and distribute such a combined
library, provided that the separate distribution of the work based on
the Library and of the other library facilities is otherwise
permitted, and provided that you do these two things:
a) Accompany the combined library with a copy of the same work
based on the Library, uncombined with any other library
facilities. This must be distributed under the terms of the
Sections above.
b) Give prominent notice with the combined library of the fact
that part of it is a work based on the Library, and explaining
where to find the accompanying uncombined form of the same work.
8. You may not copy, modify, sublicense, link with, or distribute
the Library except as expressly provided under this License. Any
attempt otherwise to copy, modify, sublicense, link with, or
distribute the Library is void, and will automatically terminate your
rights under this License. However, parties who have received copies,
or rights, from you under this License will not have their licenses
terminated so long as such parties remain in full compliance.
9. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Library or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Library (or any work based on the
Library), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Library or works based on it.
10. Each time you redistribute the Library (or any work based on the
Library), the recipient automatically receives a license from the
original licensor to copy, distribute, link with or modify the Library
subject to these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties with
this License.
11. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
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
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Library at all. For example, if a patent
license would not permit royalty-free redistribution of the Library by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Library.
If any portion of this section is held invalid or unenforceable under any
particular circumstance, the balance of the section is intended to apply,
and the section as a whole is intended to apply in other circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
12. If the distribution and/or use of the Library is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Library under this License may add
an explicit geographical distribution limitation excluding those countries,
so that distribution is permitted only in or among countries not thus
excluded. In such case, this License incorporates the limitation as if
written in the body of this License.
13. The Free Software Foundation may publish revised and/or new
versions of the Lesser General Public License from time to time.
Such new versions will be similar in spirit to the present version,
but may differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the Library
specifies a version number of this License which applies to it and
"any later version", you have the option of following the terms and
conditions either of that version or of any later version published by
the Free Software Foundation. If the Library does not specify a
license version number, you may choose any version ever published by
the Free Software Foundation.
14. If you wish to incorporate parts of the Library into other free
programs whose distribution conditions are incompatible with these,
write to the author to ask for permission. For software which is
copyrighted by the Free Software Foundation, write to the Free
Software Foundation; we sometimes make exceptions for this. Our
decision will be guided by the two goals of preserving the free status
of all derivatives of our free software and of promoting the sharing
and reuse of software generally.
NO WARRANTY
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
OTHER PARTIES PROVIDE THE LIBRARY "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
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
AND/OR REDISTRIBUTE THE LIBRARY 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
LIBRARY (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 LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
DAMAGES.
END OF TERMS AND CONDITIONS

5
LICENSE.txt Normal file
View File

@ -0,0 +1,5 @@
Copyright (c) 2012-2014 cpw.
All rights reserved. This program and the accompanying materials
are made available under the terms of the GNU Public License v3.0
which accompanies this distribution, and is available at
http://www.gnu.org/licenses/gpl.html

View File

@ -0,0 +1,26 @@
* Eloraam *
* FlowerChild *
* Hawkye *
* MALfunction84 *
Submitted the sleep handler code for his mod (Somnia) and others to use.
* Scokeev9 *
Gave permission for ScotTools API to be integrated into MCF, and also supported the Forge by converting his mods to use it.
ScotTools Background: ScotTools was an API that enabled modders to add blocks to harvesting levels (and many other ease-of-use features to create new tools), and the first tool API that used block material for block breaking efficiency which allowed blocks from mods that didn't use ScotTools API to break with the correct speed.
* SpaceToad *
* LexManos *
* cpw *
* Minecraft Coder Pack (MCP) *
Forge Mod Loader and Minecraft Forge have permission to distribute and automatically download components of MCP and distribute MCP data files.
This permission is not transitive and others wishing to redistribute the Minecraft Forge source independently should seek permission of MCP or
remove the MCP data files and request their users to download MCP separately.

View File

@ -0,0 +1,70 @@
Minecraft Forge Public Licence
==============================
Version 1.0
0. Definitions
--------------
Minecraft: Denotes a copy of the Minecraft game licensed by Mojang AB
User: Anybody that interract with the software in one of the following ways:
- play
- decompile
- recompile or compile
- modify
Minecraft Forge: The Minecraft Forge code, in source form, class file form, as
obtained in a standalone fashion or as part of a wider distribution.
Dependency: Code required to have Minecraft Forge working properly. That can
include dependencies required to compile the code as well as modifications in
the Minecraft sources that are required to have Minecraft Forge working.
1. Scope
--------
The present license is granted to any user of Minecraft Forge, for all files included
unless stated otherwise in the file itself. As a prerequisite, a user of Minecraft
Forge must own a legally aquired copy of Minecraft.
2. Play rights
--------------
The user of Minecraft Forge is allowed to install the software on a client or
a server and to play it without restriction.
3. Modification rights
----------------------
The user has the right to decompile the source code, look at either the
decompiled version or the original source code, and to modify it.
4. Derivation rights
--------------------
The user has the rights to derive code from Minecraft Forge, that is to say to
write code that either extends Minecraft Forge class and interfaces,
instantiate the objects declared or calls the functions. This code is known as
"derived" code, and can be licensed with conditions different from Minecraft
Forge.
5. Distribution rights
----------------------
The user of Minecraft Forge is allowed to redistribute Minecraft Forge in
partially, in totallity, or included in a distribution. When distributing
binaries or class files, the user must provide means to obtain the sources of
the distributed version of Minecraft Forge at no costs. This includes the
files as well as any dependency that the code may rely on, including patches to
minecraft original sources.
Modification of Minecraft Forge as well as dependencies, including patches to
minecraft original sources, has to remain under the terms of the present
license.
The right to distribute Minecraft Forge does not extend to the right to distribute
MCP data files included within Minecraft Forge. These are the property of the MCP
project and should be removed from any customized distribution of Minecraft Forge
or permission sought separately from the MCP team.

View File

@ -1,10 +1,14 @@
ironchest
=========
# IronChest
A Minecraft mod that adds expansive metal chests!
Iron Chest minecraft mod
GPL v3 licensed mod originally by cpw, maintained currently by ProgWML6.
a GPL v3 licensed mod by cpw
For downloads, head over here: http://files.minecraftforge.net/IronChests2/
Currently Maintained by ProgWML6
## Source installation information for modders
See http://files.minecraftforge.net/IronChests2/ for downloads
### Standalone source installation
Run 'gradlew setupDevWorkspace' to create a gradle environment primed with FML.
Run 'gradlew eclipse' or 'gradlew idea' to create an IDE workspace of your choice.
Refer to ForgeGradle for more information about the gradle environment.
Note: On Linux you run './gradlew.sh' instead of 'gradlew', and optionally on OSX 'bash gradlew' instead of 'gradlew'

View File

@ -1,4 +1,3 @@
// This sets us up for building a forge project - you need all of these
buildscript {
repositories {
mavenCentral()
@ -12,40 +11,28 @@ buildscript {
}
}
dependencies {
classpath 'net.minecraftforge.gradle:ForgeGradle:1.1-SNAPSHOT'
classpath 'net.minecraftforge.gradle:ForgeGradle:1.2-SNAPSHOT'
}
}
// Apply the forge plugin - this adds all the magic for automatically obfuscating, deobfuscating etc
apply plugin: 'forge'
// This is a simple flatdir repository for "uploadArchives" when you don't have a remote repo to target
repositories {
flatDir {
name "fileRepo"
dirs "repo"
}
}
// IronChest uses git tagging to mark major versions. This sets up the project version to that version data
def versionInfo = getGitVersion()
version = "${versionInfo['IronChest.version']}"
version = "1.0"
group= "com.yourname.modid" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = "modid"
// This is our group. I'm cpw.mods
group= "cpw.mods" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
// This is our actual project within the group. Note: FML has "fml" here. But this is ironchest.
archivesBaseName = "ironchest"
// Setup the forge minecraft plugin data. Specify the preferred forge/minecraft version here
minecraft {
version = "1.7.2-10.12.0.1024"
version = "1.7.2-10.12.1.1060"
assetDir = "eclipse/assets"
}
// This wrangles the resources for the jar files- stuff like textures and languages
processResources
{
// we're omitting the .xcf files - they're development only
exclude '**/*.xcf'
// we only want to do search/replace stuff in mcmod.info, nothing else
// this will ensure that this task is redone when the versions change.
inputs.property "version", project.version
inputs.property "mcversion", project.minecraft.version
// replace stuff in mcmod.info, nothing else
from(sourceSets.main.resources.srcDirs) {
include 'mcmod.info'
@ -57,140 +44,4 @@ processResources
from(sourceSets.main.resources.srcDirs) {
exclude 'mcmod.info'
}
// generate version.properties file from the git version data earlier
doLast {
def propsFile = new File(destinationDir, 'version.properties')
def properties = new Properties()
properties.putAll(versionInfo)
properties['IronChest.build.mcversion'] = project.minecraft.version
properties.store(propsFile.newWriter(), null)
}
}
// this sets our output jar to have a 'tag' of 'universal' on it
// It also adds the minecraft version in a custom version name
// The result is files named <projectname>-<mcversion>-<version>-universal.jar
jar {
classifier = 'universal'
version = "${project.minecraft.version}-${project.version}"
}
println "FISHBUM ${jar.version}"
// Add in a source jar for people, should they desire to download such a thing
task sourceJar(type: Jar) {
from sourceSets.main.allSource
classifier = 'src'
version = "${project.minecraft.version}-${project.version}"
}
// Add in an mcp named jar, for those who wish to run in a development environment (assuming mcp naming matches)
task deobfJar(type: Jar) {
from sourceSets.main.output
classifier = 'deobf'
version = "${project.minecraft.version}-${project.version}"
}
// Tell the artifact system about our extra jars
artifacts {
archives sourceJar, deobfJar
}
// Configure an upload task. this is setup for uploading to files.minecraftforge.net. There are other examples around
uploadArchives {
dependsOn 'reobf'
repositories {
if (project.hasProperty("filesmaven")) {
logger.info('Publishing to files server')
mavenDeployer {
configuration = configurations.deployJars
repository(url: project.filesmaven.url) {
authentication(userName: project.filesmaven.username, privateKey: project.filesmaven.key)
}
// This is just the pom data for the maven repo
pom {
groupId = project.group
// Force the maven upload to use the <mcversion>-<version> syntax preferred at files
version = "${project.minecraft.version}-${project.version}"
artifactId = project.archivesBaseName
project {
name project.archivesBaseName
packaging 'jar'
description 'IronChest'
url 'https://github.com/cpw/IronChest'
scm {
url 'https://github.com/progwml6/IronChest'
connection 'scm:git:git://github.com/progwml6/IronChest.git'
developerConnection 'scm:git:git@github.com:progwml6/IronChest.git'
}
issueManagement {
system 'github'
url 'https://github.com/progwml6/IronChest/issues'
}
licenses {
license {
name 'GNU Public License (GPL), Version 3.0'
url 'http://www.gnu.org/licenses/gpl-3.0.txt'
distribution 'repo'
}
}
developers {
developer {
id 'cpw'
name 'cpw'
roles { role 'developer' }
}
}
}
}
}
} else {
logger.info('Publishing to repo folder')
mavenDeployer {
pom.version = "${project.minecraft.version}-${project.version}"
repository(url: 'file://localhost/' + project.file('repo').getAbsolutePath())
}
}
}
}
// This is a special task for pulling the version information from git and the environment (for BUILD_NUMBER)
def getGitVersion()
{
def out = [:]
// call git command.
def outStream = new ByteArrayOutputStream()
def result = exec {
executable = 'git'
args = [ 'describe', '--long', "--match=[^(jenkins)]*"]
standardOutput = outStream
}
def fullVersion = outStream.toString().trim()
def matcher = fullVersion =~ /(\d+).(\d+)-(\d+)-(.*)/
def maj = matcher[0][1]
def min = matcher[0][2]
def rev = matcher[0][3]
def bn = System.getenv("BUILD_NUMBER") ?: "1"
out['IronChest.build.major.number'] = maj.toString()
out['IronChest.build.minor.number'] = min.toString()
out['IronChest.build.revision.number'] = rev.toString()
out['IronChest.build.githash'] = matcher[0][4].toString()
out['IronChest.build.number' ] = bn.toString()
out['IronChest.version' ] = "${maj}.${min}.${rev}.${bn}".toString()
return out
}

196
build.old.gradle Normal file
View File

@ -0,0 +1,196 @@
// This sets us up for building a forge project - you need all of these
buildscript {
repositories {
mavenCentral()
maven {
name = "forge"
url = "http://files.minecraftforge.net/maven"
}
maven {
name = "sonatype"
url = "https://oss.sonatype.org/content/repositories/snapshots/"
}
}
dependencies {
classpath 'net.minecraftforge.gradle:ForgeGradle:1.1-SNAPSHOT'
}
}
// Apply the forge plugin - this adds all the magic for automatically obfuscating, deobfuscating etc
apply plugin: 'forge'
// This is a simple flatdir repository for "uploadArchives" when you don't have a remote repo to target
repositories {
flatDir {
name "fileRepo"
dirs "repo"
}
}
// IronChest uses git tagging to mark major versions. This sets up the project version to that version data
def versionInfo = getGitVersion()
version = "${versionInfo['IronChest.version']}"
// This is our group. I'm cpw.mods
group= "cpw.mods" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
// This is our actual project within the group. Note: FML has "fml" here. But this is ironchest.
archivesBaseName = "ironchest"
// Setup the forge minecraft plugin data. Specify the preferred forge/minecraft version here
minecraft {
version = "1.7.2-10.12.0.1024"
}
// This wrangles the resources for the jar files- stuff like textures and languages
processResources
{
// we're omitting the .xcf files - they're development only
exclude '**/*.xcf'
// we only want to do search/replace stuff in mcmod.info, nothing else
from(sourceSets.main.resources.srcDirs) {
include 'mcmod.info'
// replace version and mcversion
expand 'version':project.version, 'mcversion':project.minecraft.version
}
// copy everything else, thats not the mcmod.info
from(sourceSets.main.resources.srcDirs) {
exclude 'mcmod.info'
}
// generate version.properties file from the git version data earlier
doLast {
def propsFile = new File(destinationDir, 'version.properties')
def properties = new Properties()
properties.putAll(versionInfo)
properties['IronChest.build.mcversion'] = project.minecraft.version
properties.store(propsFile.newWriter(), null)
}
}
// this sets our output jar to have a 'tag' of 'universal' on it
// It also adds the minecraft version in a custom version name
// The result is files named <projectname>-<mcversion>-<version>-universal.jar
jar {
classifier = 'universal'
version = "${project.minecraft.version}-${project.version}"
}
println "FISHBUM ${jar.version}"
// Add in a source jar for people, should they desire to download such a thing
task sourceJar(type: Jar) {
from sourceSets.main.allSource
classifier = 'src'
version = "${project.minecraft.version}-${project.version}"
}
// Add in an mcp named jar, for those who wish to run in a development environment (assuming mcp naming matches)
task deobfJar(type: Jar) {
from sourceSets.main.output
classifier = 'deobf'
version = "${project.minecraft.version}-${project.version}"
}
// Tell the artifact system about our extra jars
artifacts {
archives sourceJar, deobfJar
}
// Configure an upload task. this is setup for uploading to files.minecraftforge.net. There are other examples around
uploadArchives {
dependsOn 'reobf'
repositories {
if (project.hasProperty("filesmaven")) {
logger.info('Publishing to files server')
mavenDeployer {
configuration = configurations.deployJars
repository(url: project.filesmaven.url) {
authentication(userName: project.filesmaven.username, privateKey: project.filesmaven.key)
}
// This is just the pom data for the maven repo
pom {
groupId = project.group
// Force the maven upload to use the <mcversion>-<version> syntax preferred at files
version = "${project.minecraft.version}-${project.version}"
artifactId = project.archivesBaseName
project {
name project.archivesBaseName
packaging 'jar'
description 'IronChest'
url 'https://github.com/cpw/IronChest'
scm {
url 'https://github.com/progwml6/IronChest'
connection 'scm:git:git://github.com/progwml6/IronChest.git'
developerConnection 'scm:git:git@github.com:progwml6/IronChest.git'
}
issueManagement {
system 'github'
url 'https://github.com/progwml6/IronChest/issues'
}
licenses {
license {
name 'GNU Public License (GPL), Version 3.0'
url 'http://www.gnu.org/licenses/gpl-3.0.txt'
distribution 'repo'
}
}
developers {
developer {
id 'cpw'
name 'cpw'
roles { role 'developer' }
}
}
}
}
}
} else {
logger.info('Publishing to repo folder')
mavenDeployer {
pom.version = "${project.minecraft.version}-${project.version}"
repository(url: 'file://localhost/' + project.file('repo').getAbsolutePath())
}
}
}
}
// This is a special task for pulling the version information from git and the environment (for BUILD_NUMBER)
def getGitVersion()
{
def out = [:]
// call git command.
def outStream = new ByteArrayOutputStream()
def result = exec {
executable = 'git'
args = [ 'describe', '--long', "--match=[^(jenkins)]*"]
standardOutput = outStream
}
def fullVersion = outStream.toString().trim()
def matcher = fullVersion =~ /(\d+).(\d+)-(\d+)-(.*)/
def maj = matcher[0][1]
def min = matcher[0][2]
def rev = matcher[0][3]
def bn = System.getenv("BUILD_NUMBER") ?: "1"
out['IronChest.build.major.number'] = maj.toString()
out['IronChest.build.minor.number'] = min.toString()
out['IronChest.build.revision.number'] = rev.toString()
out['IronChest.build.githash'] = matcher[0][4].toString()
out['IronChest.build.number' ] = bn.toString()
out['IronChest.version' ] = "${maj}.${min}.${rev}.${bn}".toString()
return out
}

File diff suppressed because it is too large Load Diff

Binary file not shown.

View File

@ -1,6 +1,6 @@
#Tue Oct 29 18:00:54 CDT 2013
#Wed Mar 26 13:33:58 CDT 2014
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=http\://services.gradle.org/distributions/gradle-1.8-bin.zip
distributionUrl=http\://services.gradle.org/distributions/gradle-1.11-bin.zip

View File

@ -0,0 +1,41 @@
package cpw.ironchest.client;
import net.minecraft.client.renderer.tileentity.TileEntityRendererChestHelper;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import cpw.ironchest.client.gui.GuiIronChest;
import cpw.ironchest.client.renderers.tile.IronChestRenderHelper;
import cpw.ironchest.client.renderers.tile.TileEntityIronChestRenderer;
import cpw.ironchest.common.CommonProxy;
import cpw.ironchest.common.lib.IronChestType;
import cpw.ironchest.common.tiles.TileEntityIronChest;
import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.client.registry.ClientRegistry;
public class ClientProxy extends CommonProxy {
@Override
public void registerRenderInformation() {
TileEntityRendererChestHelper.instance = new IronChestRenderHelper();
}
@Override
public void registerTileEntitySpecialRenderer(IronChestType typ) {
ClientRegistry.bindTileEntitySpecialRenderer(typ.clazz, new TileEntityIronChestRenderer());
}
@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
TileEntity te = world.getTileEntity(x, y, z);
if (te != null && te instanceof TileEntityIronChest) {
return GuiIronChest.GUI.buildGUI(IronChestType.values()[ID], player.inventory, (TileEntityIronChest) te);
} else {
return null;
}
}
@Override
public World getClientWorld() {
return FMLClientHandler.instance().getClient().theWorld;
}
}

View File

@ -0,0 +1,81 @@
package cpw.ironchest.client.gui;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.GL11;
import cpw.ironchest.common.containers.ContainerIronChest;
import cpw.ironchest.common.lib.IronChestType;
import cpw.ironchest.common.tiles.TileEntityIronChest;
public class GuiIronChest extends GuiContainer {
public enum ResourceList {
IRON(new ResourceLocation("ironchest", "textures/gui/ironcontainer.png")),
COPPER(new ResourceLocation("ironchest", "textures/gui/coppercontainer.png")),
SILVER(new ResourceLocation("ironchest", "textures/gui/silvercontainer.png")),
GOLD(new ResourceLocation("ironchest", "textures/gui/goldcontainer.png")),
DIAMOND(new ResourceLocation("ironchest", "textures/gui/diamondcontainer.png")),
DIRT(new ResourceLocation("ironchest", "textures/gui/dirtcontainer.png"));
public final ResourceLocation location;
private ResourceList(ResourceLocation loc) {
this.location = loc;
}
}
public enum GUI {
IRON(184, 202, ResourceList.IRON, IronChestType.IRON),
GOLD(184, 256, ResourceList.GOLD, IronChestType.GOLD),
DIAMOND(238, 256, ResourceList.DIAMOND, IronChestType.DIAMOND),
COPPER(184, 184, ResourceList.COPPER, IronChestType.COPPER),
SILVER(184, 238, ResourceList.SILVER, IronChestType.SILVER),
CRYSTAL(238, 256, ResourceList.DIAMOND, IronChestType.CRYSTAL),
OBSIDIAN(238, 256, ResourceList.DIAMOND, IronChestType.OBSIDIAN),
DIRTCHEST9000(184, 184, ResourceList.DIRT, IronChestType.DIRTCHEST9000);
private int xSize, ySize;
private ResourceList guiResourceList;
private IronChestType mainType;
private GUI(int xSize, int ySize, ResourceList guiResourceList, IronChestType mainType) {
this.xSize = xSize;
this.ySize = ySize;
this.guiResourceList = guiResourceList;
this.mainType = mainType;
}
protected Container makeContainer(IInventory player, IInventory chest) {
return new ContainerIronChest(player, chest, mainType, xSize, ySize);
}
public static GuiIronChest buildGUI(IronChestType type, IInventory playerInventory, TileEntityIronChest chestInventory) {
return new GuiIronChest(values()[chestInventory.getType().ordinal()], playerInventory, chestInventory);
}
}
public int getRowLength() {
return type.mainType.getRowLength();
}
private GUI type;
private GuiIronChest(GUI type, IInventory player, IInventory chest) {
super(type.makeContainer(player, chest));
this.type = type;
this.xSize = type.xSize;
this.ySize = type.ySize;
this.allowUserInput = false;
}
@Override
protected void drawGuiContainerBackgroundLayer(float f, int i, int j) {
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
this.mc.getTextureManager().bindTexture(type.guiResourceList.location);
int x = (width - xSize) / 2;
int y = (height - ySize) / 2;
drawTexturedModalRect(x, y, 0, 0, xSize, ySize);
}
}

View File

@ -0,0 +1,31 @@
package cpw.ironchest.client.renderers.tile;
import java.util.Map;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.tileentity.TileEntityRendererChestHelper;
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
import com.google.common.collect.Maps;
import cpw.ironchest.common.IronChest;
import cpw.ironchest.common.lib.IronChestType;
import cpw.ironchest.common.tiles.TileEntityIronChest;
public class IronChestRenderHelper extends TileEntityRendererChestHelper {
private Map<Integer, TileEntityIronChest> itemRenders = Maps.newHashMap();
public IronChestRenderHelper() {
for (IronChestType typ : IronChestType.values())
itemRenders.put(typ.ordinal(), (TileEntityIronChest) IronChest.ironChestBlock.createTileEntity(null, typ.ordinal()));
}
@Override
public void renderChest(Block block, int i, float f) {
if (block == IronChest.ironChestBlock) {
TileEntityRendererDispatcher.instance.renderTileEntityAt(itemRenders.get(i), 0.0D, 0.0D, 0.0D, 0.0F);
} else {
super.renderChest(block, i, f);
}
}
}

View File

@ -0,0 +1,159 @@
package cpw.ironchest.client.renderers.tile;
import static org.lwjgl.opengl.GL11.glColor4f;
import static org.lwjgl.opengl.GL11.glDisable;
import static org.lwjgl.opengl.GL11.glEnable;
import static org.lwjgl.opengl.GL11.glPopMatrix;
import static org.lwjgl.opengl.GL11.glPushMatrix;
import static org.lwjgl.opengl.GL11.glRotatef;
import static org.lwjgl.opengl.GL11.glScalef;
import static org.lwjgl.opengl.GL11.glTranslatef;
import java.util.Map;
import java.util.Random;
import net.minecraft.client.model.ModelChest;
import net.minecraft.client.renderer.entity.RenderItem;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMap.Builder;
import com.google.common.primitives.SignedBytes;
import cpw.ironchest.common.lib.IronChestType;
import cpw.ironchest.common.tiles.TileEntityIronChest;
public class TileEntityIronChestRenderer extends TileEntitySpecialRenderer {
private ModelChest model;
private static Map<IronChestType, ResourceLocation> locations;
static {
Builder<IronChestType, ResourceLocation> builder = ImmutableMap.<IronChestType, ResourceLocation> builder();
for (IronChestType typ : IronChestType.values())
builder.put(typ, new ResourceLocation("ironchest", "textures/model/" + typ.getModelTexture()));
locations = builder.build();
}
private Random random;
private RenderItem itemRenderer;
private static float[][] shifts = { { 0.3F, 0.45F, 0.3F }, { 0.7F, 0.45F, 0.3F }, { 0.3F, 0.45F, 0.7F }, { 0.7F, 0.45F, 0.7F }, { 0.3F, 0.1F, 0.3F }, { 0.7F, 0.1F, 0.3F }, { 0.3F, 0.1F, 0.7F }, { 0.7F, 0.1F, 0.7F }, { 0.5F, 0.32F, 0.5F }, };
public TileEntityIronChestRenderer() {
model = new ModelChest();
random = new Random();
itemRenderer = new RenderItem() {
@Override
public byte getMiniBlockCount(ItemStack stack, byte original) {
return SignedBytes.saturatedCast(Math.min(stack.stackSize / 32, 15) + 1);
}
@Override
public byte getMiniItemCount(ItemStack stack, byte original) {
return SignedBytes.saturatedCast(Math.min(stack.stackSize / 32, 7) + 1);
}
@Override
public boolean shouldBob() {
return false;
}
@Override
public boolean shouldSpreadItems() {
return false;
}
};
itemRenderer.setRenderManager(RenderManager.instance);
}
public void render(TileEntityIronChest tile, double x, double y, double z, float partialTick) {
if (tile == null) {
return;
}
int facing = 3;
IronChestType type = tile.getType();
if (tile != null && tile.hasWorldObj()) {
facing = tile.getFacing();
type = tile.getType();
int typ = tile.getWorldObj().getBlockMetadata(tile.xCoord, tile.yCoord, tile.zCoord);
type = IronChestType.values()[typ];
}
bindTexture(locations.get(type));
glPushMatrix();
glEnable(32826);
glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
glTranslatef((float) x, (float) y + 1.0F, (float) z + 1.0F);
glScalef(1.0F, -1F, -1F);
glTranslatef(0.5F, 0.5F, 0.5F);
int k = 0;
if (facing == 2) {
k = 180;
}
if (facing == 3) {
k = 0;
}
if (facing == 4) {
k = 90;
}
if (facing == 5) {
k = -90;
}
glRotatef(k, 0.0F, 1.0F, 0.0F);
glTranslatef(-0.5F, -0.5F, -0.5F);
float lidangle = tile.prevLidAngle + (tile.lidAngle - tile.prevLidAngle) * partialTick;
lidangle = 1.0F - lidangle;
lidangle = 1.0F - lidangle * lidangle * lidangle;
model.chestLid.rotateAngleX = -((lidangle * 3.141593F) / 2.0F);
model.renderAll();
glDisable(32826);
glPopMatrix();
glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
if (type.isTransparent() && tile.getDistanceFrom(this.field_147501_a.field_147560_j, this.field_147501_a.field_147561_k, this.field_147501_a.field_147558_l) < 128d) {
random.setSeed(254L);
float shiftX, shiftY, shiftZ, blockScale = 0.70F;
int shift = 0;
if (tile.getTopItemStacks()[1] == null) {
shift = 8;
blockScale = 0.85F;
}
glPushMatrix();
glDisable(2896);
glTranslatef((float) x, (float) y, (float) z);
EntityItem customitem = new EntityItem(field_147501_a.field_147550_f);
customitem.hoverStart = 0f;
for (ItemStack item : tile.getTopItemStacks()) {
if (shift > shifts.length) {
break;
}
if (item == null) {
shift++;
continue;
}
shiftX = shifts[shift][0];
shiftY = shifts[shift][1];
shiftZ = shifts[shift][2];
shift++;
glPushMatrix();
glTranslatef(shiftX, shiftY, shiftZ);
glRotatef((float) (360.0 * (double) (System.currentTimeMillis() & 0x3FFFL) / (double) 0x3FFFL), 0.0F, 1.0F, 0.0F);
glScalef(blockScale, blockScale, blockScale);
customitem.setEntityItemStack(item);
itemRenderer.doRender(customitem, 0, 0, 0, 0, 0);
glPopMatrix();
}
glEnable(2896);
glPopMatrix();
glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
}
}
@Override
public void renderTileEntityAt(TileEntity tileentity, double x, double y, double z, float partialTick) {
render((TileEntityIronChest) tileentity, x, y, z, partialTick);
}
}

View File

@ -0,0 +1,35 @@
package cpw.ironchest.common;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import cpw.ironchest.common.containers.ContainerIronChest;
import cpw.ironchest.common.lib.IronChestType;
import cpw.ironchest.common.tiles.TileEntityIronChest;
import cpw.mods.fml.common.network.IGuiHandler;
public class CommonProxy implements IGuiHandler {
public void registerRenderInformation() {}
public void registerTileEntitySpecialRenderer(IronChestType typ) {}
@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
return null;
}
@Override
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int X, int Y, int Z) {
TileEntity te = world.getTileEntity(X, Y, Z);
if (te != null && te instanceof TileEntityIronChest) {
TileEntityIronChest icte = (TileEntityIronChest) te;
return new ContainerIronChest(player.inventory, icte, icte.getType(), 0, 0);
} else {
return null;
}
}
public World getClientWorld() {
return null;
}
}

View File

@ -0,0 +1,61 @@
package cpw.ironchest.common;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraftforge.common.MinecraftForge;
import cpw.ironchest.common.blocks.BlockIronChest;
import cpw.ironchest.common.blocks.BlockIronChestItem;
import cpw.ironchest.common.lib.ChestChangerType;
import cpw.ironchest.common.lib.IronChestType;
import cpw.ironchest.common.lib.network.PacketHandler;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@Mod(modid = IronChest.modid, name = IronChest.name, dependencies = "required-after:Forge@[7.0,);required-after:FML@[5.0.5,)")
public class IronChest {
public static final String modid = "IronChest", name = "Iron Chests";
public static BlockIronChest ironChestBlock;
public static CreativeTabs tabIronChest = new CreativeTabs(modid) {
@Override
@SideOnly(Side.CLIENT)
public Item getTabIconItem() {
return Item.getItemFromBlock(ironChestBlock);
}
};
@SidedProxy(clientSide = "cpw.ironchest.client.ClientProxy", serverSide = "cpw.ironchest.CommonProxy")
public static CommonProxy proxy;
@Instance(modid)
public static IronChest instance;
@EventHandler
public void load(FMLInitializationEvent e) {
ChestChangerType.buildItems();
ironChestBlock = new BlockIronChest();
GameRegistry.registerBlock(ironChestBlock, BlockIronChestItem.class, "BlockIronChest");
for (IronChestType typ : IronChestType.values()) {
GameRegistry.registerTileEntityWithAlternatives(typ.clazz, "IronChest." + typ.name(), typ.name());
proxy.registerTileEntitySpecialRenderer(typ);
}
IronChestType.registerBlocksAndRecipes(ironChestBlock);
ChestChangerType.generateRecipes();
PacketHandler.INSTANCE.ordinal();
NetworkRegistry.INSTANCE.registerGuiHandler(instance, proxy);
proxy.registerRenderInformation();
MinecraftForge.EVENT_BUS.register(this);
}
}

View File

@ -0,0 +1,280 @@
package cpw.ironchest.common.blocks;
import static net.minecraftforge.common.util.ForgeDirection.DOWN;
import static net.minecraftforge.common.util.ForgeDirection.UP;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.passive.EntityOcelot;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.IIcon;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import com.google.common.collect.Lists;
import cpw.ironchest.common.IronChest;
import cpw.ironchest.common.lib.IronChestType;
import cpw.ironchest.common.tiles.TileEntityIronChest;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class BlockIronChest extends BlockContainer {
private Random random = new Random();
public BlockIronChest() {
super(Material.iron);
setBlockName("IronChest");
setHardness(3.0F);
setBlockBounds(0.0625F, 0F, 0.0625F, 0.9375F, 0.875F, 0.9375F);
setCreativeTab(IronChest.tabIronChest);
}
/**
* Overridden by {@link #createTileEntity(World, int)}
*/
@Override
public TileEntity createNewTileEntity(World w, int i) {
return null;
}
@Override
public boolean isOpaqueCube() {
return false;
}
@Override
public boolean renderAsNormalBlock() {
return false;
}
@Override
public int getRenderType() {
return 22;
}
@Override
public TileEntity createTileEntity(World world, int metadata) {
return IronChestType.makeEntity(metadata);
}
@Override
@SideOnly(Side.CLIENT)
public IIcon getIcon(int i, int j) {
if (j < IronChestType.values().length) {
IronChestType type = IronChestType.values()[j];
return type.getIcon(i);
}
return null;
}
@Override
public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int metadata, int fortune) {
ArrayList<ItemStack> items = Lists.newArrayList();
ItemStack stack = new ItemStack(this, 1, metadata);
IronChestType.values()[IronChestType.validateMeta(metadata)].adornItemDrop(stack);
items.add(stack);
return items;
}
@Override
public boolean onBlockActivated(World world, int i, int j, int k, EntityPlayer player, int i1, float f1, float f2, float f3) {
if (world.isRemote)
return true;
else {
IInventory iinventory = chestInventory(world, i, j, k);
if (iinventory != null)
player.openGui(IronChest.instance, ((TileEntityIronChest) world.getTileEntity(i, j, k)).getType().ordinal(), world, i, j, k);
return true;
}
}
public IInventory chestInventory(World world, int i, int j, int k) {
TileEntity object = (TileEntityIronChest) world.getTileEntity(i, j, k);
if (object == null) {
return null;
} else if (world.isSideSolid(i, j + 1, k, DOWN)) {
return null;
} else if (isOcelotOnChest(world, i, j, k)) {
return null;
} else if (world.getBlock(i - 1, j, k) == this && (world.isSideSolid(i - 1, j + 1, k, DOWN) || isOcelotOnChest(world, i - 1, j, k))) {
return null;
} else if (world.getBlock(i + 1, j, k) == this && (world.isSideSolid(i + 1, j + 1, k, DOWN) || isOcelotOnChest(world, i + 1, j, k))) {
return null;
} else if (world.getBlock(i, j, k - 1) == this && (world.isSideSolid(i, j + 1, k - 1, DOWN) || isOcelotOnChest(world, i, j, k - 1))) {
return null;
} else if (world.getBlock(i, j, k + 1) == this && (world.isSideSolid(i, j + 1, k + 1, DOWN) || isOcelotOnChest(world, i, j, k + 1))) {
return null;
} else
return (IInventory) object;
}
private static boolean isOcelotOnChest(World world, int i, int j, int k) {
Iterator iterator = world.getEntitiesWithinAABB(EntityOcelot.class, AxisAlignedBB.getAABBPool().getAABB((double) i, (double) (j + 1), (double) k, (double) (i + 1), (double) (j + 2), (double) (k + 1))).iterator();
EntityOcelot entityocelot1;
do {
if (!iterator.hasNext())
return false;
EntityOcelot entityocelot = (EntityOcelot) iterator.next();
entityocelot1 = (EntityOcelot) entityocelot;
} while (!entityocelot1.isSitting());
return true;
}
@Override
public void onBlockAdded(World world, int i, int j, int k) {
super.onBlockAdded(world, i, j, k);
world.markBlockForUpdate(i, j, k);
}
@Override
public void onBlockPlacedBy(World world, int i, int j, int k, EntityLivingBase entityliving, ItemStack itemStack) {
byte chestFacing = 0;
int facing = MathHelper.floor_double((double) ((entityliving.rotationYaw * 4F) / 360F) + 0.5D) & 3;
if (facing == 0) {
chestFacing = 2;
}
if (facing == 1) {
chestFacing = 5;
}
if (facing == 2) {
chestFacing = 3;
}
if (facing == 3) {
chestFacing = 4;
}
TileEntity te = world.getTileEntity(i, j, k);
if (te != null && te instanceof TileEntityIronChest) {
TileEntityIronChest teic = (TileEntityIronChest) te;
teic.wasPlaced(entityliving, itemStack);
teic.setFacing(chestFacing);
world.markBlockForUpdate(i, j, k);
}
}
@Override
public int damageDropped(int i) {
return i;
}
@Override
public void breakBlock(World world, int i, int j, int k, Block b, int l) {
TileEntityIronChest te = (TileEntityIronChest) world.getTileEntity(i, j, k);
if (te != null) {
te.removeAdornments();
dropContent(0, te, world, te.xCoord, te.yCoord, te.zCoord);
}
super.breakBlock(world, i, j, k, b, l);
}
public void dropContent(int newSize, IInventory chest, World world, int xCoord, int yCoord, int zCoord) {
for (int l = newSize; l < chest.getSizeInventory(); l++) {
ItemStack itemstack = chest.getStackInSlot(l);
if (itemstack == null) {
continue;
}
float f = random.nextFloat() * 0.8F + 0.1F;
float f1 = random.nextFloat() * 0.8F + 0.1F;
float f2 = random.nextFloat() * 0.8F + 0.1F;
while (itemstack.stackSize > 0) {
int i1 = random.nextInt(21) + 10;
if (i1 > itemstack.stackSize) {
i1 = itemstack.stackSize;
}
itemstack.stackSize -= i1;
EntityItem entityitem = new EntityItem(world, (float) xCoord + f, (float) yCoord + (newSize > 0 ? 1 : 0) + f1, (float) zCoord + f2, new ItemStack(itemstack.getItem(), i1, itemstack.getItemDamage()));
float f3 = 0.05F;
entityitem.motionX = (float) random.nextGaussian() * f3;
entityitem.motionY = (float) random.nextGaussian() * f3 + 0.2F;
entityitem.motionZ = (float) random.nextGaussian() * f3;
if (itemstack.hasTagCompound()) {
entityitem.getEntityItem().setTagCompound((NBTTagCompound) itemstack.getTagCompound().copy());
}
world.spawnEntityInWorld(entityitem);
}
}
}
@Override
@SideOnly(Side.CLIENT)
public void getSubBlocks(Item par1, CreativeTabs par2CreativeTabs, List par3List) {
for (IronChestType type : IronChestType.values()) {
if (type.isValidForCreativeMode()) {
par3List.add(new ItemStack(this, 1, type.ordinal()));
}
}
}
@Override
public float getExplosionResistance(Entity par1Entity, World world, int x, int y, int z, double explosionX, double explosionY, double explosionZ) {
TileEntity te = world.getTileEntity(x, y, z);
if (te instanceof TileEntityIronChest) {
TileEntityIronChest teic = (TileEntityIronChest) te;
if (teic.getType().isExplosionResistant()) {
return 10000F;
}
}
return super.getExplosionResistance(par1Entity, world, x, y, z, explosionX, explosionY, explosionZ);
}
@Override
public int getComparatorInputOverride(World world, int i, int j, int k, int l) {
return Container.calcRedstoneFromInventory((TileEntityIronChest) world.getTileEntity(i, j, k));
}
@Override
@SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister par1IconRegister) {
for (IronChestType typ : IronChestType.values()) {
typ.makeIcons(par1IconRegister);
}
}
private static final ForgeDirection[] validRotationAxes = new ForgeDirection[] { UP, DOWN };
@Override
public ForgeDirection[] getValidRotations(World world, int x, int y, int z) {
return validRotationAxes;
}
@Override
public boolean rotateBlock(World worldObj, int x, int y, int z, ForgeDirection axis) {
if (worldObj.isRemote) {
return false;
}
if (axis == UP || axis == DOWN) {
TileEntity tileEntity = worldObj.getTileEntity(x, y, z);
if (tileEntity instanceof TileEntityIronChest) {
TileEntityIronChest icte = (TileEntityIronChest) tileEntity;
icte.rotateAround(axis);
}
return true;
}
return false;
}
}

View File

@ -0,0 +1,24 @@
package cpw.ironchest.common.blocks;
import cpw.ironchest.common.lib.IronChestType;
import net.minecraft.block.Block;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
public class BlockIronChestItem extends ItemBlock {
public BlockIronChestItem(Block block) {
super(block);
setMaxDamage(0);
setHasSubtypes(true);
}
@Override
public int getMetadata(int i) {
return IronChestType.validateMeta(i);
}
@Override
public String getUnlocalizedName(ItemStack itemstack) {
return "tile.ironchest:" + IronChestType.values()[itemstack.getItemDamage()].name();
}
}

View File

@ -0,0 +1,87 @@
package cpw.ironchest.common.containers;
import cpw.ironchest.common.lib.IronChestType;
import invtweaks.api.container.ChestContainer;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
@ChestContainer(isLargeChest = true)
public class ContainerIronChest extends Container {
private IronChestType type;
private EntityPlayer player;
private IInventory chest;
public ContainerIronChest(IInventory playerInventory, IInventory chestInventory, IronChestType type, int xSize, int ySize) {
chest = chestInventory;
player = ((InventoryPlayer) playerInventory).player;
this.type = type;
chestInventory.openInventory();
layoutContainer(playerInventory, chestInventory, type, xSize, ySize);
}
@Override
public boolean canInteractWith(EntityPlayer player) {
return chest.isUseableByPlayer(player);
}
@Override
public ItemStack transferStackInSlot(EntityPlayer p, int i) {
ItemStack itemstack = null;
Slot slot = (Slot) inventorySlots.get(i);
if (slot != null && slot.getHasStack()) {
ItemStack itemstack1 = slot.getStack();
itemstack = itemstack1.copy();
if (i < type.size) {
if (!mergeItemStack(itemstack1, type.size, inventorySlots.size(), true)) {
return null;
}
} else if (!type.acceptsStack(itemstack1)) {
return null;
} else if (!mergeItemStack(itemstack1, 0, type.size, false)) {
return null;
}
if (itemstack1.stackSize == 0) {
slot.putStack(null);
} else {
slot.onSlotChanged();
}
}
return itemstack;
}
@Override
public void onContainerClosed(EntityPlayer entityplayer) {
super.onContainerClosed(entityplayer);
chest.closeInventory();
}
protected void layoutContainer(IInventory playerInventory, IInventory chestInventory, IronChestType type, int xSize, int ySize) {
if (type == IronChestType.DIRTCHEST9000) {
addSlotToContainer(type.makeSlot(chestInventory, 0, 12 + 4 * 18, 8 + 2 * 18));
} else
for (int chestRow = 0; chestRow < type.getRowCount(); chestRow++)
for (int chestCol = 0; chestCol < type.getRowLength(); chestCol++)
addSlotToContainer(type.makeSlot(chestInventory, chestCol + chestRow * type.getRowLength(), 12 + chestCol * 18, 8 + chestRow * 18));
int leftCol = (xSize - 162) / 2 + 1;
for (int playerInvRow = 0; playerInvRow < 3; playerInvRow++)
for (int playerInvCol = 0; playerInvCol < 9; playerInvCol++)
addSlotToContainer(new Slot(playerInventory, playerInvCol + playerInvRow * 9 + 9, leftCol + playerInvCol * 18, ySize - (4 - playerInvRow) * 18 - 10));
for (int hotbarSlot = 0; hotbarSlot < 9; hotbarSlot++)
addSlotToContainer(new Slot(playerInventory, hotbarSlot, leftCol + hotbarSlot * 18, ySize - 24));
}
public EntityPlayer getPlayer() {
return player;
}
@ChestContainer.RowSizeCallback
public int getNumColumns() {
return type.getRowLength();
}
}

View File

@ -0,0 +1,20 @@
package cpw.ironchest.common.containers;
import cpw.ironchest.common.lib.IronChestType;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
public class ValidatingSlot extends Slot {
private IronChestType type;
public ValidatingSlot(IInventory inv, int i, int j, int k, IronChestType type) {
super(inv, i, j, k);
this.type = type;
}
@Override
public boolean isItemValid(ItemStack is) {
return type.acceptsStack(is);
}
}

View File

@ -0,0 +1,89 @@
package cpw.ironchest.common.items;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityChest;
import net.minecraft.world.World;
import cpw.ironchest.common.IronChest;
import cpw.ironchest.common.blocks.BlockIronChest;
import cpw.ironchest.common.lib.ChestChangerType;
import cpw.ironchest.common.lib.IronChestType;
import cpw.ironchest.common.tiles.TileEntityIronChest;
import cpw.mods.fml.common.ObfuscationReflectionHelper;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class ItemChestChanger extends Item {
private ChestChangerType type;
public ItemChestChanger(ChestChangerType type) {
super();
setMaxStackSize(1);
this.type = type;
setUnlocalizedName("ironchest:" + type.name());
setCreativeTab(IronChest.tabIronChest);
}
@Override
@SideOnly(Side.CLIENT)
public void registerIcons(IIconRegister par1IconRegister) {
this.itemIcon = par1IconRegister.registerIcon("ironchest:" + type.itemName);
}
@Override
public boolean onItemUseFirst(ItemStack stack, EntityPlayer player, World world, int X, int Y, int Z, int side, float hitX, float hitY, float hitZ) {
if (world.isRemote)
return false;
TileEntity te = world.getTileEntity(X, Y, Z);
TileEntityIronChest newchest;
if (te != null && te instanceof TileEntityIronChest) {
TileEntityIronChest ironchest = (TileEntityIronChest) te;
newchest = ironchest.applyUpgradeItem(this);
if (newchest == null) {
return false;
}
} else if (te != null && te instanceof TileEntityChest) {
TileEntityChest tec = (TileEntityChest) te;
if (tec.numPlayersUsing > 0) {
return false;
}
if (!getType().canUpgrade(IronChestType.WOOD)) {
return false;
}
// force the old tileentity out of the world so that adjacent chests can update
newchest = IronChestType.makeEntity(getTargetChestOrdinal(IronChestType.WOOD.ordinal()));
int newSize = newchest.chestContents.length;
ItemStack[] chestContents = ObfuscationReflectionHelper.getPrivateValue(TileEntityChest.class, tec, 0);
System.arraycopy(chestContents, 0, newchest.chestContents, 0, Math.min(newSize, chestContents.length));
BlockIronChest block = IronChest.ironChestBlock;
block.dropContent(newSize, tec, world, tec.xCoord, tec.yCoord, tec.zCoord);
newchest.setFacing((byte) tec.getBlockMetadata());
newchest.sortTopStacks();
for (int i = 0; i < Math.min(newSize, chestContents.length); i++) {
chestContents[i] = null;
}
world.setBlock(X, Y, Z, Blocks.air, 0, 3); // clear the old block out
tec.updateContainingBlockInfo(); // reset neighboring block knowledge
tec.checkForAdjacentChests(); // update neighboring blocks
world.setBlock(X, Y, Z, block, newchest.getType().ordinal(), 3); // add in the iron chest
} else {
return false;
}
world.setTileEntity(X, Y, Z, newchest);
world.setBlockMetadataWithNotify(X, Y, Z, newchest.getType().ordinal(), 3);
stack.stackSize = 0;
return true;
}
public int getTargetChestOrdinal(int sourceOrdinal) {
return type.getTarget();
}
public ChestChangerType getType() {
return type;
}
}

View File

@ -0,0 +1,74 @@
package cpw.ironchest.common.lib;
import static cpw.ironchest.common.lib.IronChestType.COPPER;
import static cpw.ironchest.common.lib.IronChestType.CRYSTAL;
import static cpw.ironchest.common.lib.IronChestType.DIAMOND;
import static cpw.ironchest.common.lib.IronChestType.GOLD;
import static cpw.ironchest.common.lib.IronChestType.IRON;
import static cpw.ironchest.common.lib.IronChestType.OBSIDIAN;
import static cpw.ironchest.common.lib.IronChestType.SILVER;
import static cpw.ironchest.common.lib.IronChestType.WOOD;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import cpw.ironchest.common.items.ItemChestChanger;
import cpw.mods.fml.common.registry.GameRegistry;
public enum ChestChangerType {
IRONGOLD(IRON, GOLD, "ironGoldUpgrade", "Iron to Gold Chest Upgrade", "mmm", "msm", "mmm"),
GOLDDIAMOND(GOLD, DIAMOND, "goldDiamondUpgrade", "Gold to Diamond Chest Upgrade", "GGG", "msm", "GGG"),
COPPERSILVER(COPPER, SILVER, "copperSilverUpgrade", "Copper to Silver Chest Upgrade", "mmm", "msm", "mmm"),
SILVERGOLD(SILVER, GOLD, "silverGoldUpgrade", "Silver to Gold Chest Upgrade", "mGm", "GsG", "mGm"),
COPPERIRON(COPPER, IRON, "copperIronUpgrade", "Copper to Iron Chest Upgrade", "mGm", "GsG", "mGm"),
DIAMONDCRYSTAL(DIAMOND, CRYSTAL, "diamondCrystalUpgrade", "Diamond to Crystal Chest Upgrade", "GGG", "GOG", "GGG"),
WOODIRON(WOOD, IRON, "woodIronUpgrade", "Normal chest to Iron Chest Upgrade", "mmm", "msm", "mmm"),
WOODCOPPER(WOOD, COPPER, "woodCopperUpgrade", "Normal chest to Copper Chest Upgrade", "mmm", "msm", "mmm"),
DIAMONDOBSIDIAN(DIAMOND, OBSIDIAN, "diamondObsidianUpgrade", "Diamond to Obsidian Chest Upgrade", "mmm", "mGm", "mmm");
private IronChestType source, target;
public String itemName, descriptiveName, recipe[];
private ItemChestChanger item;
private ChestChangerType(IronChestType source, IronChestType target, String itemName, String descriptiveName, String... recipe) {
this.source = source;
this.target = target;
this.itemName = itemName;
this.descriptiveName = descriptiveName;
this.recipe = recipe;
}
public boolean canUpgrade(IronChestType from) {
return from == this.source;
}
public int getTarget() {
return this.target.ordinal();
}
public ItemChestChanger buildItem() {
item = new ItemChestChanger(this);
GameRegistry.registerItem(item, itemName);
return item;
}
public void addRecipes() {
for (String sourceMat : source.getMatList()) {
for (String targetMat : target.getMatList()) {
Object targetMaterial = IronChestType.translateOreName(targetMat);
Object sourceMaterial = IronChestType.translateOreName(sourceMat);
IronChestType.addRecipe(new ItemStack(item), recipe, 'm', targetMaterial, 's', sourceMaterial, 'G', Blocks.glass, 'O', Blocks.obsidian);
}
}
}
public static void buildItems() {
for (ChestChangerType type : values()) {
type.buildItem();
}
}
public static void generateRecipes() {
for (ChestChangerType item : values()) {
item.addRecipes();
}
}
}

View File

@ -0,0 +1,207 @@
package cpw.ironchest.common.lib;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagByte;
import net.minecraft.util.IIcon;
import net.minecraftforge.oredict.ShapedOreRecipe;
import cpw.ironchest.common.blocks.BlockIronChest;
import cpw.ironchest.common.containers.ValidatingSlot;
import cpw.ironchest.common.tiles.TileEntityCopperChest;
import cpw.ironchest.common.tiles.TileEntityCrystalChest;
import cpw.ironchest.common.tiles.TileEntityDiamondChest;
import cpw.ironchest.common.tiles.TileEntityDirtChest;
import cpw.ironchest.common.tiles.TileEntityGoldChest;
import cpw.ironchest.common.tiles.TileEntityIronChest;
import cpw.ironchest.common.tiles.TileEntityObsidianChest;
import cpw.ironchest.common.tiles.TileEntitySilverChest;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public enum IronChestType {
IRON(54, 9, true, "Iron Chest", "ironchest.png", 0, Arrays.asList("ingotIron", "ingotRefinedIron"), TileEntityIronChest.class, "mmmmPmmmm", "mGmG3GmGm"),
GOLD(81, 9, true, "Gold Chest", "goldchest.png", 1, Arrays.asList("ingotGold"), TileEntityGoldChest.class, "mmmmPmmmm", "mGmG4GmGm"),
DIAMOND(108, 12, true, "Diamond Chest", "diamondchest.png", 2, Arrays.asList("gemDiamond"), TileEntityDiamondChest.class, "GGGmPmGGG", "GGGG4Gmmm"),
COPPER(45, 9, false, "Copper Chest", "copperchest.png", 3, Arrays.asList("ingotCopper"), TileEntityCopperChest.class, "mmmmCmmmm"),
SILVER(72, 9, false, "Silver Chest", "silverchest.png", 4, Arrays.asList("ingotSilver"), TileEntitySilverChest.class, "mmmm3mmmm", "mGmG0GmGm"),
CRYSTAL(108, 12, true, "Crystal Chest", "crystalchest.png", 5, Arrays.asList("blockGlass"), TileEntityCrystalChest.class, "GGGGPGGGG"),
OBSIDIAN(108, 12, false, "Obsidian Chest", "obsidianchest.png", 6, Arrays.asList("obsidian"), TileEntityObsidianChest.class, "mmmm2mmmm"),
DIRTCHEST9000(1, 1, false, "Dirt Chest 9000", "dirtchest.png", 7, Arrays.asList("dirt"), TileEntityDirtChest.class, Item.getItemFromBlock(Blocks.dirt), "mmmmCmmmm"),
WOOD(0, 0, false, "", "", -1, Arrays.asList("plankWood"), null);
public int size, rowLength, textureRow;
public String friendlyName, modelTexture, recipes[];
private boolean tieredChest;
public Class<? extends TileEntityIronChest> clazz;
private ArrayList<String> matList;
private Item itemFilter;
IronChestType(int size, int rowLength, boolean tieredChest, String friendlyName, String modelTexture, int textureRow, List<String> mats, Class<? extends TileEntityIronChest> clazz, String... recipes) {
this(size, rowLength, tieredChest, friendlyName, modelTexture, textureRow, mats, clazz, (Item) null, recipes);
}
IronChestType(int size, int rowLength, boolean tieredChest, String friendlyName, String modelTexture, int textureRow, List<String> mats, Class<? extends TileEntityIronChest> clazz, Item itemFilter, String... recipes) {
this.size = size;
this.rowLength = rowLength;
this.tieredChest = tieredChest;
this.friendlyName = friendlyName;
this.modelTexture = modelTexture;
this.textureRow = textureRow;
this.clazz = clazz;
this.itemFilter = itemFilter;
this.recipes = recipes;
this.matList = new ArrayList<String>();
matList.addAll(mats);
}
public String getModelTexture() {
return modelTexture;
}
public int getTextureRow() {
return textureRow;
}
public static TileEntityIronChest makeEntity(int metadata) {
int chesttype = validateMeta(metadata);
if (chesttype == metadata) {
try {
return values()[chesttype].clazz.newInstance();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
return null;
}
public static void registerBlocksAndRecipes(BlockIronChest blockResult) {
ItemStack previous = new ItemStack(Blocks.chest);
for (IronChestType typ : values()) {
generateRecipesForType(blockResult, previous, typ);
ItemStack chest = new ItemStack(blockResult, 1, typ.ordinal());
if (typ.isValidForCreativeMode())
GameRegistry.registerCustomItemStack(typ.friendlyName, chest);
if (typ.tieredChest)
previous = chest;
}
}
public static void generateRecipesForType(BlockIronChest blockResult, Object previousTier, IronChestType type) {
for (String recipe : type.recipes) {
String[] recipeSplit = new String[] { recipe.substring(0, 3), recipe.substring(3, 6), recipe.substring(6, 9) };
Object mainMaterial = null;
for (String mat : type.matList) {
mainMaterial = translateOreName(mat);
addRecipe(new ItemStack(blockResult, 1, type.ordinal()), recipeSplit, 'm', mainMaterial, 'P', previousTier, /* previous chest tier */ 'G', Blocks.glass, 'C', Blocks.chest,
'0', new ItemStack(blockResult, 1, 0), /* Iron Chest */
'1', new ItemStack(blockResult, 1, 1), /* Gold Chest */
'2', new ItemStack(blockResult, 1, 2), /* Diamond Chest */
'3', new ItemStack(blockResult, 1, 3), /* Copper Chest */
'4', new ItemStack(blockResult, 1, 4)/* Silver Chest */
);
}
}
}
public static Object translateOreName(String mat) {
if (mat == "ingotIron") {
return Items.iron_ingot;
} else if (mat == "ingotGold") {
return Items.gold_ingot;
} else if (mat == "gemDiamond") {
return Items.diamond;
} else if (mat == "blockGlass") {
return Blocks.glass;
} else if (mat == "obsidian") {
return Blocks.obsidian;
} else if (mat == "dirt") {
return Blocks.dirt;
}
return mat;
}
public static void addRecipe(ItemStack is, Object... parts) {
ShapedOreRecipe oreRecipe = new ShapedOreRecipe(is, parts);
GameRegistry.addRecipe(oreRecipe);
}
public int getRowCount() {
return size / rowLength;
}
public int getRowLength() {
return rowLength;
}
public boolean isTransparent() {
return this == CRYSTAL;
}
public List<String> getMatList() {
return matList;
}
public static int validateMeta(int i) {
if (i < values().length && values()[i].size > 0) {
return i;
} else {
return 0;
}
}
public boolean isValidForCreativeMode() {
return validateMeta(ordinal()) == ordinal();
}
public boolean isExplosionResistant() {
return this == OBSIDIAN;
}
@SideOnly(Side.CLIENT)
private IIcon[] icons;
@SideOnly(Side.CLIENT)
public void makeIcons(IIconRegister par1IconRegister) {
if (isValidForCreativeMode()) {
icons = new IIcon[3];
int i = 0;
for (String s : sideNames) {
icons[i++] = par1IconRegister.registerIcon(String.format("ironchest:%s_%s", name().toLowerCase(), s));
}
}
}
@SideOnly(Side.CLIENT)
public IIcon getIcon(int side) {
return icons[sideMapping[side]];
}
private static String[] sideNames = { "top", "front", "side" };
private static int[] sideMapping = { 0, 0, 2, 1, 2, 2, 2 };
public Slot makeSlot(IInventory chestInventory, int index, int x, int y) {
return new ValidatingSlot(chestInventory, index, x, y, this);
}
public boolean acceptsStack(ItemStack itemstack) {
return itemFilter == null || itemstack == null || itemstack.getItem() == itemFilter;
}
public void adornItemDrop(ItemStack item) {
if (this == DIRTCHEST9000) {
item.setTagInfo("dirtchest", new NBTTagByte((byte) 1));
}
}
}

View File

@ -0,0 +1,21 @@
package cpw.ironchest.common.lib;
import java.util.Properties;
public class Version {
private static String major, minor, rev, build, mcversion;
static void init(Properties properties) {
if (properties != null) {
major = properties.getProperty("IronChest.build.major.number");
minor = properties.getProperty("IronChest.build.minor.number");
rev = properties.getProperty("IronChest.build.revision.number");
build = properties.getProperty("IronChest.build.number");
mcversion = properties.getProperty("IronChest.build.mcversion");
}
}
public static String fullVersionString() {
return String.format("%s.%s.%s build %s", major, minor, rev, build);
}
}

View File

@ -0,0 +1,175 @@
package cpw.ironchest.common.lib.network;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import java.util.EnumMap;
import net.minecraft.network.Packet;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import cpw.ironchest.common.IronChest;
import cpw.ironchest.common.tiles.TileEntityIronChest;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.network.FMLEmbeddedChannel;
import cpw.mods.fml.common.network.FMLIndexedMessageToMessageCodec;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.network.internal.FMLProxyPacket;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
/**
* Handles the packet wrangling for IronChest
*
* @author cpw
*
*/
public enum PacketHandler {
INSTANCE;
/**
* Our channel "pair" from {@link NetworkRegistry}
*/
private EnumMap<Side, FMLEmbeddedChannel> channels;
/**
* Make our packet handler, and add an {@link IronChestCodec} always
*/
private PacketHandler() {
// request a channel pair for IronChest from the network registry
// Add the IronChestCodec as a member of both channel pipelines
this.channels = NetworkRegistry.INSTANCE.newChannel("IronChest", new IronChestCodec());
if (FMLCommonHandler.instance().getSide() == Side.CLIENT) {
addClientHandler();
}
}
/**
* This is only called on the client side - it adds an
* {@link IronChestMessageHandler} to the client side pipeline, since the
* only place we expect to <em>handle</em> messages is on the client.
*/
@SideOnly(Side.CLIENT)
private void addClientHandler() {
FMLEmbeddedChannel clientChannel = this.channels.get(Side.CLIENT);
// These two lines find the existing codec (Ironchestcodec) and insert
// our message handler after it in the pipeline
String codec = clientChannel.findChannelHandlerNameForType(IronChestCodec.class);
clientChannel.pipeline().addAfter(codec, "ClientHandler", new IronChestMessageHandler());
}
/**
* This class simply handles the {@link IronChestMessage} when it's received
* at the client side It can contain client only code, because it's only run
* on the client.
*
* @author cpw
*
*/
private static class IronChestMessageHandler extends SimpleChannelInboundHandler<IronChestMessage> {
@Override
protected void channelRead0(ChannelHandlerContext ctx, IronChestMessage msg) throws Exception {
World world = IronChest.proxy.getClientWorld();
TileEntity te = world.getTileEntity(msg.x, msg.y, msg.z);
if (te instanceof TileEntityIronChest) {
TileEntityIronChest icte = (TileEntityIronChest) te;
icte.setFacing(msg.facing);
icte.handlePacketData(msg.type, msg.items);
}
}
}
/**
* This is our "message". In fact, {@link FMLIndexedMessageToMessageCodec}
* can handle many messages on the same channel at once, using a
* discriminator byte. But for IronChest, we only need the one message, so
* we have just this.
*
* @author cpw
*
*/
public static class IronChestMessage {
int x, y, z, type, facing, items[];
}
/**
* This is the codec that automatically transforms the
* {@link FMLProxyPacket} which wraps the client and server custom payload
* packets into a message we care about.
*
* @author cpw
*
*/
private class IronChestCodec extends FMLIndexedMessageToMessageCodec<IronChestMessage> {
/**
* We register our discriminator bytes here. We only have the one type,
* so we only register one.
*/
public IronChestCodec() {
addDiscriminator(0, IronChestMessage.class);
}
@Override
public void encodeInto(ChannelHandlerContext ctx, IronChestMessage msg, ByteBuf target) throws Exception {
target.writeInt(msg.x);
target.writeInt(msg.y);
target.writeInt(msg.z);
int typeAndFacing = ((msg.type & 0x0F) | ((msg.facing & 0x0F) << 4)) & 0xFF;
target.writeByte(typeAndFacing);
target.writeBoolean(msg.items != null);
if (msg.items != null) {
int[] items = msg.items;
for (int j = 0; j < items.length; j++) {
int i = items[j];
target.writeInt(i);
}
}
}
@Override
public void decodeInto(ChannelHandlerContext ctx, ByteBuf dat, IronChestMessage msg) {
msg.x = dat.readInt();
msg.y = dat.readInt();
msg.z = dat.readInt();
int typDat = dat.readByte();
msg.type = (byte) (typDat & 0xf);
msg.facing = (byte) ((typDat >> 4) & 0xf);
boolean hasStacks = dat.readBoolean();
msg.items = new int[0];
if (hasStacks) {
msg.items = new int[24];
for (int i = 0; i < msg.items.length; i++) {
msg.items[i] = dat.readInt();
}
}
}
}
/**
* This is a utility method called to transform a packet from a custom
* packet into a "system packet". We're called from
* {@link TileEntity#getDescriptionPacket()} in this case, but there are
* others. All network packet methods in minecraft have been adapted to
* handle {@link FMLProxyPacket} but general purpose objects can't be
* handled sadly.
*
* This method uses the {@link IronChestCodec} to transform a custom packet
* {@link IronChestMessage} into an {@link FMLProxyPacket} by using the
* utility method {@link FMLEmbeddedChannel#generatePacketFrom(Object)} on
* the channel to do exactly that.
*
* @param tileEntityIronChest
* @return
*/
public static Packet getPacket(TileEntityIronChest tileEntityIronChest) {
IronChestMessage msg = new IronChestMessage();
msg.x = tileEntityIronChest.xCoord;
msg.y = tileEntityIronChest.yCoord;
msg.z = tileEntityIronChest.zCoord;
msg.type = tileEntityIronChest.getType().ordinal();
msg.facing = tileEntityIronChest.getFacing();
msg.items = tileEntityIronChest.buildIntDataList();
return INSTANCE.channels.get(Side.SERVER).generatePacketFrom(msg);
}
}

View File

@ -0,0 +1,9 @@
package cpw.ironchest.common.tiles;
import cpw.ironchest.common.lib.IronChestType;
public class TileEntityCopperChest extends TileEntityIronChest {
public TileEntityCopperChest() {
super(IronChestType.COPPER);
}
}

View File

@ -0,0 +1,9 @@
package cpw.ironchest.common.tiles;
import cpw.ironchest.common.lib.IronChestType;
public class TileEntityCrystalChest extends TileEntityIronChest {
public TileEntityCrystalChest() {
super(IronChestType.CRYSTAL);
}
}

View File

@ -0,0 +1,9 @@
package cpw.ironchest.common.tiles;
import cpw.ironchest.common.lib.IronChestType;
public class TileEntityDiamondChest extends TileEntityIronChest {
public TileEntityDiamondChest() {
super(IronChestType.DIAMOND);
}
}

View File

@ -0,0 +1,43 @@
package cpw.ironchest.common.tiles;
import cpw.ironchest.common.lib.IronChestType;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.nbt.NBTTagString;
import net.minecraft.util.StatCollector;
public class TileEntityDirtChest extends TileEntityIronChest {
private static ItemStack dirtChest9000GuideBook = new ItemStack(Items.written_book);
static {
dirtChest9000GuideBook.setTagInfo("author", new NBTTagString("cpw"));
dirtChest9000GuideBook.setTagInfo("title", new NBTTagString(StatCollector.translateToLocal("book.ironchest:dirtchest9000.title")));
NBTTagList pages = new NBTTagList();
pages.appendTag(new NBTTagString(StatCollector .translateToLocal("book.ironchest:dirtchest9000.page1")));
pages.appendTag(new NBTTagString(StatCollector .translateToLocal("book.ironchest:dirtchest9000.page2")));
pages.appendTag(new NBTTagString(StatCollector.translateToLocal("book.ironchest:dirtchest9000.page3")));
pages.appendTag(new NBTTagString(StatCollector.translateToLocal("book.ironchest:dirtchest9000.page4")));
pages.appendTag(new NBTTagString(StatCollector.translateToLocal("book.ironchest:dirtchest9000.page5")));
dirtChest9000GuideBook.setTagInfo("pages", pages);
}
public TileEntityDirtChest() {
super(IronChestType.DIRTCHEST9000);
}
@Override
public void wasPlaced(EntityLivingBase entityliving, ItemStack itemStack) {
if (!(itemStack.hasTagCompound() && itemStack.getTagCompound().getBoolean("dirtchest"))) {
setInventorySlotContents(0, dirtChest9000GuideBook.copy());
}
}
@Override
public void removeAdornments() {
if (chestContents[0] != null && chestContents[0].isItemEqual(dirtChest9000GuideBook)) {
chestContents[0] = null;
}
}
}

View File

@ -0,0 +1,9 @@
package cpw.ironchest.common.tiles;
import cpw.ironchest.common.lib.IronChestType;
public class TileEntityGoldChest extends TileEntityIronChest {
public TileEntityGoldChest() {
super(IronChestType.GOLD);
}
}

View File

@ -0,0 +1,397 @@
package cpw.ironchest.common.tiles;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import cpw.ironchest.common.IronChest;
import cpw.ironchest.common.blocks.BlockIronChest;
import cpw.ironchest.common.containers.ContainerIronChest;
import cpw.ironchest.common.items.ItemChestChanger;
import cpw.ironchest.common.lib.IronChestType;
import cpw.ironchest.common.lib.network.PacketHandler;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.network.Packet;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraftforge.common.util.Constants;
import net.minecraftforge.common.util.ForgeDirection;
public class TileEntityIronChest extends TileEntity implements IInventory {
private int ticksSinceSync = -1, numUsingPlayers, facing;
public float prevLidAngle, lidAngle;
private IronChestType type;
public ItemStack[] chestContents, topStacks;
private boolean inventoryTouched, hadStuff;
public TileEntityIronChest() {
this(IronChestType.IRON);
}
protected TileEntityIronChest(IronChestType type) {
super();
this.type = type;
chestContents = new ItemStack[getSizeInventory()];
topStacks = new ItemStack[8];
}
public ItemStack[] getContents() {
return chestContents;
}
@Override
public int getSizeInventory() {
return type.size;
}
public int getFacing() {
return facing;
}
@Override
public String getInventoryName() {
return type.name();
}
public IronChestType getType() {
return type;
}
@Override
public ItemStack getStackInSlot(int i) {
inventoryTouched = true;
return chestContents[i];
}
@Override
public void markDirty() {
super.markDirty();
sortTopStacks();
}
public void sortTopStacks() {
if (!type.isTransparent() || (worldObj != null && worldObj.isRemote)) {
return;
}
ItemStack[] tempCopy = new ItemStack[getSizeInventory()];
boolean hasStuff = false;
int compressedIdx = 0;
mainLoop: for (int i = 0; i < getSizeInventory(); i++) {
if (chestContents[i] != null) {
for (int j = 0; j < compressedIdx; j++) {
if (tempCopy[j].isItemEqual(chestContents[i])) {
tempCopy[j].stackSize += chestContents[i].stackSize;
continue mainLoop;
}
}
tempCopy[compressedIdx++] = chestContents[i].copy();
hasStuff = true;
}
}
if (!hasStuff && hadStuff) {
hadStuff = false;
for (int i = 0; i < topStacks.length; i++) {
topStacks[i] = null;
}
if (worldObj != null) {
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}
return;
}
hadStuff = true;
Arrays.sort(tempCopy, new Comparator<ItemStack>() {
@Override
public int compare(ItemStack o1, ItemStack o2) {
if (o1 == null) {
return 1;
} else if (o2 == null) {
return -1;
} else {
return o2.stackSize - o1.stackSize;
}
}
});
int p = 0;
for (int i = 0; i < tempCopy.length; i++) {
if (tempCopy[i] != null && tempCopy[i].stackSize > 0) {
topStacks[p++] = tempCopy[i];
if (p == topStacks.length) {
break;
}
}
}
for (int i = p; i < topStacks.length; i++) {
topStacks[i] = null;
}
if (worldObj != null) {
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}
}
@Override
public ItemStack decrStackSize(int i, int j) {
if (chestContents[i] != null) {
if (chestContents[i].stackSize <= j) {
ItemStack itemstack = chestContents[i];
chestContents[i] = null;
markDirty();
return itemstack;
}
ItemStack itemstack1 = chestContents[i].splitStack(j);
if (chestContents[i].stackSize == 0) {
chestContents[i] = null;
}
markDirty();
return itemstack1;
} else {
return null;
}
}
@Override
public void setInventorySlotContents(int i, ItemStack itemstack) {
chestContents[i] = itemstack;
if (itemstack != null && itemstack.stackSize > getInventoryStackLimit()) {
itemstack.stackSize = getInventoryStackLimit();
}
markDirty();
}
@Override
public void readFromNBT(NBTTagCompound nbt) {
super.readFromNBT(nbt);
NBTTagList nbttaglist = nbt.getTagList("Items", Constants.NBT.TAG_COMPOUND);
chestContents = new ItemStack[getSizeInventory()];
for (int i = 0; i < nbttaglist.tagCount(); i++) {
NBTTagCompound nbt1 = nbttaglist.getCompoundTagAt(i);
int j = nbt1.getByte("Slot") & 0xff;
if (j >= 0 && j < chestContents.length) {
chestContents[j] = ItemStack.loadItemStackFromNBT(nbt1);
}
}
facing = nbt.getByte("facing");
sortTopStacks();
}
@Override
public void writeToNBT(NBTTagCompound nbt) {
super.writeToNBT(nbt);
NBTTagList nbttaglist = new NBTTagList();
for (int i = 0; i < chestContents.length; i++) {
if (chestContents[i] != null) {
NBTTagCompound nbt1 = new NBTTagCompound();
nbt1.setByte("Slot", (byte) i);
chestContents[i].writeToNBT(nbt1);
nbttaglist.appendTag(nbt1);
}
}
nbt.setTag("Items", nbttaglist);
nbt.setByte("facing", (byte) facing);
}
@Override
public int getInventoryStackLimit() {
return 64;
}
@Override
public boolean isUseableByPlayer(final EntityPlayer player) {
return worldObj.getTileEntity(xCoord, yCoord, zCoord) == this && player.getDistanceSq(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5) <= 64.0;
}
@Override
public void updateEntity() {
super.updateEntity();
if (worldObj != null && !worldObj.isRemote && numUsingPlayers != 0 && (ticksSinceSync + xCoord + yCoord + zCoord) % 200 == 0) {
numUsingPlayers = 0;
float var1 = 5.0F;
List<EntityPlayer> playerlist = worldObj.getEntitiesWithinAABB(EntityPlayer.class, AxisAlignedBB.getAABBPool().getAABB((double) ((float) xCoord - var1), (double) ((float) yCoord - var1), (double) ((float) zCoord - var1), (double) ((float) (xCoord + 1) + var1), (double) ((float) (yCoord + 1) + var1), (double) ((float) (zCoord + 1) + var1)));
Iterator<EntityPlayer> player = playerlist.iterator();
while (player.hasNext()) {
if (player.next().openContainer instanceof ContainerIronChest) {
++numUsingPlayers;
}
}
}
if (worldObj != null && !worldObj.isRemote && ticksSinceSync < 0) {
worldObj.addBlockEvent(xCoord, yCoord, zCoord, IronChest.ironChestBlock, 3, ((numUsingPlayers << 3) & 0xF8) | (facing & 0x7));
}
if (!worldObj.isRemote && inventoryTouched) {
inventoryTouched = false;
sortTopStacks();
}
ticksSinceSync++;
prevLidAngle = lidAngle;
float f = 0.1F;
if (numUsingPlayers > 0 && lidAngle == 0.0F) {
double d = (double) xCoord + 0.5D;
double d1 = (double) zCoord + 0.5D;
worldObj.playSoundEffect(d, (double) yCoord + 0.5D, d1, "random.chestopen", 0.5F, worldObj.rand.nextFloat() * 0.1F + 0.9F);
}
if (numUsingPlayers == 0 && lidAngle > 0.0F || numUsingPlayers > 0
&& lidAngle < 1.0F) {
float f1 = lidAngle;
if (numUsingPlayers > 0) {
lidAngle += f;
} else {
lidAngle -= f;
}
if (lidAngle > 1.0F) {
lidAngle = 1.0F;
}
float f2 = 0.5F;
if (lidAngle < f2 && f1 >= f2) {
double d2 = (double) xCoord + 0.5D;
double d3 = (double) zCoord + 0.5D;
worldObj.playSoundEffect(d2, (double) yCoord + 0.5D, d3, "random.chestclosed", 0.5F, worldObj.rand.nextFloat() * 0.1F + 0.9F);
}
if (lidAngle < 0.0F) {
lidAngle = 0.0F;
}
}
}
@Override
public boolean receiveClientEvent(int i, int j) {
if (i == 1) {
numUsingPlayers = j;
return true;
} else {
return super.receiveClientEvent(i, j);
}
}
@Override
public void openInventory() {
++numUsingPlayers;
worldObj.addBlockEvent(xCoord, yCoord, zCoord, IronChest.ironChestBlock, 1, numUsingPlayers);
}
@Override
public void closeInventory() {
--numUsingPlayers;
worldObj.addBlockEvent(xCoord, yCoord, zCoord, IronChest.ironChestBlock, 1, numUsingPlayers);
}
public void setFacing(int facing2) {
facing = facing2;
}
public TileEntityIronChest applyUpgradeItem(ItemChestChanger itemChestChanger) {
if (numUsingPlayers > 0 || !itemChestChanger.getType().canUpgrade(getType())) {
return null;
}
TileEntityIronChest newEntity = IronChestType.makeEntity(itemChestChanger.getTargetChestOrdinal(getType().ordinal()));
int newSize = newEntity.chestContents.length;
System.arraycopy(chestContents, 0, newEntity.chestContents, 0, Math.min(newSize, chestContents.length));
BlockIronChest block = IronChest.ironChestBlock;
block.dropContent(newSize, this, worldObj, xCoord, yCoord, zCoord);
newEntity.setFacing(facing);
newEntity.sortTopStacks();
newEntity.ticksSinceSync = -1;
return newEntity;
}
public ItemStack[] getTopItemStacks() {
return topStacks;
}
public TileEntityIronChest updateFromMetadata(int l) {
if (worldObj != null && worldObj.isRemote) {
if (l != type.ordinal()) {
worldObj.setTileEntity(xCoord, yCoord, zCoord, IronChestType.makeEntity(l));
return (TileEntityIronChest) worldObj.getTileEntity(xCoord, yCoord, zCoord);
}
}
return this;
}
@Override
public Packet getDescriptionPacket() {
return PacketHandler.getPacket(this);
}
public void handlePacketData(int typeData, int[] intData) {
TileEntityIronChest chest = this;
if (type.ordinal() != typeData) {
chest = updateFromMetadata(typeData);
}
if (IronChestType.values()[typeData].isTransparent() && intData != null) {
int pos = 0;
if (intData.length < chest.topStacks.length * 3) {
return;
}
for (int i = 0; i < chest.topStacks.length; i++) {
if (intData[pos + 2] != 0) {
Item it = Item.getItemById(intData[pos]);
ItemStack is = new ItemStack(it, intData[pos + 2], intData[pos + 1]);
chest.topStacks[i] = is;
} else {
chest.topStacks[i] = null;
}
pos += 3;
}
}
}
public int[] buildIntDataList() {
if (type.isTransparent()) {
int[] sortList = new int[topStacks.length * 3];
int pos = 0;
for (ItemStack is : topStacks) {
if (is != null) {
sortList[pos++] = Item.getIdFromItem(is.getItem());
sortList[pos++] = is.getItemDamage();
sortList[pos++] = is.stackSize;
} else {
sortList[pos++] = 0;
sortList[pos++] = 0;
sortList[pos++] = 0;
}
}
return sortList;
}
return null;
}
@Override
public ItemStack getStackInSlotOnClosing(int par1) {
if (chestContents[par1] != null) {
ItemStack var2 = chestContents[par1];
chestContents[par1] = null;
return var2;
} else {
return null;
}
}
@Override
public boolean isItemValidForSlot(int i, ItemStack itemstack) {
return type.acceptsStack(itemstack);
}
@Override
public boolean hasCustomInventoryName() {
return false;
}
public void rotateAround(ForgeDirection axis) {
setFacing((byte) ForgeDirection.getOrientation(facing).getRotation(axis).ordinal());
worldObj.addBlockEvent(xCoord, yCoord, zCoord, IronChest.ironChestBlock, 2, getFacing());
}
public void wasPlaced(EntityLivingBase entityliving, ItemStack itemStack) {}
public void removeAdornments() {}
}

View File

@ -0,0 +1,9 @@
package cpw.ironchest.common.tiles;
import cpw.ironchest.common.lib.IronChestType;
public class TileEntityObsidianChest extends TileEntityIronChest {
public TileEntityObsidianChest() {
super(IronChestType.OBSIDIAN);
}
}

View File

@ -0,0 +1,9 @@
package cpw.ironchest.common.tiles;
import cpw.ironchest.common.lib.IronChestType;
public class TileEntitySilverChest extends TileEntityIronChest {
public TileEntitySilverChest() {
super(IronChestType.SILVER);
}
}

View File

@ -1,302 +0,0 @@
/*******************************************************************************
* Copyright (c) 2012 cpw.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html
*
* Contributors:
* cpw - initial API and implementation
******************************************************************************/
package cpw.mods.ironchest;
import static net.minecraftforge.common.util.ForgeDirection.DOWN;
import static net.minecraftforge.common.util.ForgeDirection.UP;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import com.google.common.collect.Lists;
import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class BlockIronChest extends BlockContainer {
private Random random;
@SideOnly(Side.CLIENT)
private IIcon[][] icons;
public BlockIronChest()
{
super(Material.iron);
setBlockName("IronChest");
setHardness(3.0F);
setBlockBounds(0.0625F, 0F, 0.0625F, 0.9375F, 0.875F, 0.9375F);
random = new Random();
setCreativeTab(CreativeTabs.tabDecorations);
}
/**
* Overridden by {@link #createTileEntity(World, int)}
*/
@Override
public TileEntity createNewTileEntity(World w, int i)
{
return null;
}
@Override
public boolean isOpaqueCube()
{
return false;
}
@Override
public boolean renderAsNormalBlock()
{
return false;
}
@Override
public int getRenderType()
{
return 22;
}
@Override
public TileEntity createTileEntity(World world, int metadata)
{
return IronChestType.makeEntity(metadata);
}
@SideOnly(Side.CLIENT)
@Override
public IIcon getIcon(int i, int j)
{
if (j < IronChestType.values().length)
{
IronChestType type = IronChestType.values()[j];
return type.getIcon(i);
}
return null;
}
@Override
public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int metadata, int fortune)
{
ArrayList<ItemStack> items = Lists.newArrayList();
ItemStack stack = new ItemStack(this,1,metadata);
IronChestType.values()[IronChestType.validateMeta(metadata)].adornItemDrop(stack);
items.add(stack);
return items;
}
@Override
public boolean onBlockActivated(World world, int i, int j, int k, EntityPlayer player, int i1, float f1, float f2, float f3)
{
TileEntity te = world.getTileEntity(i, j, k);
if (te == null || !(te instanceof TileEntityIronChest))
{
return true;
}
if (world.isSideSolid(i, j + 1, k, ForgeDirection.DOWN))
{
return true;
}
if (world.isRemote)
{
return true;
}
player.openGui(IronChest.instance, ((TileEntityIronChest) te).getType().ordinal(), world, i, j, k);
return true;
}
@Override
public void onBlockAdded(World world, int i, int j, int k)
{
super.onBlockAdded(world, i, j, k);
world.markBlockForUpdate(i, j, k);
}
@Override
public void onBlockPlacedBy(World world, int i, int j, int k, EntityLivingBase entityliving, ItemStack itemStack)
{
byte chestFacing = 0;
int facing = MathHelper.floor_double((double) ((entityliving.rotationYaw * 4F) / 360F) + 0.5D) & 3;
if (facing == 0)
{
chestFacing = 2;
}
if (facing == 1)
{
chestFacing = 5;
}
if (facing == 2)
{
chestFacing = 3;
}
if (facing == 3)
{
chestFacing = 4;
}
TileEntity te = world.getTileEntity(i, j, k);
if (te != null && te instanceof TileEntityIronChest)
{
TileEntityIronChest teic = (TileEntityIronChest) te;
teic.wasPlaced(entityliving, itemStack);
teic.setFacing(chestFacing);
world.markBlockForUpdate(i, j, k);
}
}
@Override
public int damageDropped(int i)
{
return i;
}
@Override
public void breakBlock(World world, int i, int j, int k, Block i1, int i2)
{
TileEntityIronChest tileentitychest = (TileEntityIronChest) world.getTileEntity(i, j, k);
if (tileentitychest != null)
{
tileentitychest.removeAdornments();
dropContent(0, tileentitychest, world, tileentitychest.xCoord, tileentitychest.yCoord, tileentitychest.zCoord);
}
super.breakBlock(world, i, j, k, i1, i2);
}
public void dropContent(int newSize, IInventory chest, World world, int xCoord, int yCoord, int zCoord)
{
for (int l = newSize; l < chest.getSizeInventory(); l++)
{
ItemStack itemstack = chest.getStackInSlot(l);
if (itemstack == null)
{
continue;
}
float f = random.nextFloat() * 0.8F + 0.1F;
float f1 = random.nextFloat() * 0.8F + 0.1F;
float f2 = random.nextFloat() * 0.8F + 0.1F;
while (itemstack.stackSize > 0)
{
int i1 = random.nextInt(21) + 10;
if (i1 > itemstack.stackSize)
{
i1 = itemstack.stackSize;
}
itemstack.stackSize -= i1;
EntityItem entityitem = new EntityItem(world, (float) xCoord + f, (float) yCoord + (newSize > 0 ? 1 : 0) + f1, (float) zCoord + f2,
new ItemStack(itemstack.getItem(), i1, itemstack.getItemDamage()));
float f3 = 0.05F;
entityitem.motionX = (float) random.nextGaussian() * f3;
entityitem.motionY = (float) random.nextGaussian() * f3 + 0.2F;
entityitem.motionZ = (float) random.nextGaussian() * f3;
if (itemstack.hasTagCompound())
{
entityitem.getEntityItem().setTagCompound((NBTTagCompound) itemstack.getTagCompound().copy());
}
world.spawnEntityInWorld(entityitem);
}
}
}
@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
@SideOnly(Side.CLIENT)
public void getSubBlocks(Item par1, CreativeTabs par2CreativeTabs, List par3List)
{
for (IronChestType type : IronChestType.values())
{
if (type.isValidForCreativeMode())
{
par3List.add(new ItemStack(this, 1, type.ordinal()));
}
}
}
@Override
public float getExplosionResistance(Entity par1Entity, World world, int x, int y, int z, double explosionX, double explosionY, double explosionZ)
{
TileEntity te = world.getTileEntity(x, y, z);
if (te instanceof TileEntityIronChest)
{
TileEntityIronChest teic = (TileEntityIronChest) te;
if (teic.getType().isExplosionResistant())
{
return 10000f;
}
}
return super.getExplosionResistance(par1Entity, world, x, y, z, explosionX, explosionY, explosionZ);
}
@Override
public int getComparatorInputOverride(World par1World, int par2, int par3, int par4, int par5)
{
return Container.calcRedstoneFromInventory((TileEntityIronChest) par1World.getTileEntity(par2, par3, par4));
}
@Override
@SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister par1IconRegister)
{
for (IronChestType typ: IronChestType.values())
{
typ.makeIcons(par1IconRegister);
}
}
private static final ForgeDirection[] validRotationAxes = new ForgeDirection[] { UP, DOWN };
@Override
public ForgeDirection[] getValidRotations(World worldObj, int x, int y, int z)
{
return validRotationAxes;
}
@Override
public boolean rotateBlock(World worldObj, int x, int y, int z, ForgeDirection axis)
{
if (worldObj.isRemote)
{
return false;
}
if (axis == UP || axis == DOWN)
{
TileEntity tileEntity = worldObj.getTileEntity(x, y, z);
if (tileEntity instanceof TileEntityIronChest) {
TileEntityIronChest icte = (TileEntityIronChest) tileEntity;
icte.rotateAround(axis);
}
return true;
}
return false;
}
}

View File

@ -1,94 +0,0 @@
/*******************************************************************************
* Copyright (c) 2012 cpw. All rights reserved. This program and the accompanying materials are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at http://www.gnu.org/licenses/gpl.html
*
* Contributors: cpw - initial API and implementation
******************************************************************************/
package cpw.mods.ironchest;
import static cpw.mods.ironchest.IronChestType.COPPER;
import static cpw.mods.ironchest.IronChestType.CRYSTAL;
import static cpw.mods.ironchest.IronChestType.DIAMOND;
import static cpw.mods.ironchest.IronChestType.GOLD;
import static cpw.mods.ironchest.IronChestType.IRON;
import static cpw.mods.ironchest.IronChestType.OBSIDIAN;
import static cpw.mods.ironchest.IronChestType.SILVER;
import static cpw.mods.ironchest.IronChestType.WOOD;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.config.Configuration;
import cpw.mods.fml.common.registry.GameRegistry;
public enum ChestChangerType {
IRONGOLD(IRON, GOLD, "ironGoldUpgrade", "Iron to Gold Chest Upgrade", "mmm", "msm", "mmm"),
GOLDDIAMOND(GOLD, DIAMOND, "goldDiamondUpgrade", "Gold to Diamond Chest Upgrade", "GGG", "msm", "GGG"),
COPPERSILVER(COPPER, SILVER, "copperSilverUpgrade", "Copper to Silver Chest Upgrade", "mmm", "msm", "mmm"),
SILVERGOLD(SILVER, GOLD, "silverGoldUpgrade", "Silver to Gold Chest Upgrade", "mGm", "GsG", "mGm"),
COPPERIRON(COPPER, IRON, "copperIronUpgrade", "Copper to Iron Chest Upgrade", "mGm", "GsG", "mGm"),
DIAMONDCRYSTAL(DIAMOND, CRYSTAL, "diamondCrystalUpgrade", "Diamond to Crystal Chest Upgrade", "GGG", "GOG", "GGG"),
WOODIRON(WOOD, IRON, "woodIronUpgrade", "Normal chest to Iron Chest Upgrade", "mmm", "msm", "mmm"),
WOODCOPPER(WOOD, COPPER, "woodCopperUpgrade", "Normal chest to Copper Chest Upgrade", "mmm", "msm", "mmm"),
DIAMONDOBSIDIAN(DIAMOND, OBSIDIAN, "diamondObsidianUpgrade", "Diamond to Obsidian Chest Upgrade", "mmm", "mGm", "mmm");
private IronChestType source;
private IronChestType target;
public String itemName;
public String descriptiveName;
private ItemChestChanger item;
private String[] recipe;
private ChestChangerType(IronChestType source, IronChestType target, String itemName, String descriptiveName, String... recipe)
{
this.source = source;
this.target = target;
this.itemName = itemName;
this.descriptiveName = descriptiveName;
this.recipe = recipe;
}
public boolean canUpgrade(IronChestType from)
{
return from == this.source;
}
public int getTarget()
{
return this.target.ordinal();
}
public ItemChestChanger buildItem(Configuration cfg)
{
item = new ItemChestChanger(this);
GameRegistry.registerItem(item, itemName);
return item;
}
public void addRecipes()
{
for (String sourceMat : source.getMatList())
{
for (String targetMat : target.getMatList())
{
Object targetMaterial = IronChestType.translateOreName(targetMat);
Object sourceMaterial = IronChestType.translateOreName(sourceMat);
IronChestType.addRecipe(new ItemStack(item), recipe, 'm', targetMaterial, 's', sourceMaterial, 'G', Blocks.glass, 'O', Blocks.obsidian);
}
}
}
public static void buildItems(Configuration cfg)
{
for (ChestChangerType type : values())
{
type.buildItem(cfg);
}
}
public static void generateRecipes()
{
for (ChestChangerType item : values())
{
item.addRecipes();
}
}
}

View File

@ -1,55 +0,0 @@
/*******************************************************************************
* Copyright (c) 2012 cpw.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html
*
* Contributors:
* cpw - initial API and implementation
******************************************************************************/
package cpw.mods.ironchest;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import cpw.mods.fml.common.network.IGuiHandler;
public class CommonProxy implements IGuiHandler {
public void registerRenderInformation()
{
}
public void registerTileEntitySpecialRenderer(IronChestType typ)
{
}
@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z)
{
return null;
}
@Override
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int X, int Y, int Z)
{
TileEntity te = world.getTileEntity(X, Y, Z);
if (te != null && te instanceof TileEntityIronChest)
{
TileEntityIronChest icte = (TileEntityIronChest) te;
return new ContainerIronChest(player.inventory, icte, icte.getType(), 0, 0);
}
else
{
return null;
}
}
public World getClientWorld()
{
return null;
}
}

View File

@ -1,125 +0,0 @@
/*******************************************************************************
* Copyright (c) 2012 cpw.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html
*
* Contributors:
* cpw - initial API and implementation
******************************************************************************/
package cpw.mods.ironchest;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import invtweaks.api.container.ChestContainer;
@ChestContainer(isLargeChest = true)
public class ContainerIronChest extends Container {
private IronChestType type;
private EntityPlayer player;
private IInventory chest;
public ContainerIronChest(IInventory playerInventory, IInventory chestInventory, IronChestType type, int xSize, int ySize)
{
chest = chestInventory;
player = ((InventoryPlayer) playerInventory).player;
this.type = type;
chestInventory.openInventory();
layoutContainer(playerInventory, chestInventory, type, xSize, ySize);
}
@Override
public boolean canInteractWith(EntityPlayer player)
{
return chest.isUseableByPlayer(player);
}
@Override
public ItemStack transferStackInSlot(EntityPlayer p, int i)
{
ItemStack itemstack = null;
Slot slot = (Slot) inventorySlots.get(i);
if (slot != null && slot.getHasStack())
{
ItemStack itemstack1 = slot.getStack();
itemstack = itemstack1.copy();
if (i < type.size)
{
if (!mergeItemStack(itemstack1, type.size, inventorySlots.size(), true))
{
return null;
}
}
else if (!type.acceptsStack(itemstack1))
{
return null;
}
else if (!mergeItemStack(itemstack1, 0, type.size, false))
{
return null;
}
if (itemstack1.stackSize == 0)
{
slot.putStack(null);
}
else
{
slot.onSlotChanged();
}
}
return itemstack;
}
@Override
public void onContainerClosed(EntityPlayer entityplayer)
{
super.onContainerClosed(entityplayer);
chest.closeInventory();
}
protected void layoutContainer(IInventory playerInventory, IInventory chestInventory, IronChestType type, int xSize, int ySize)
{
if (type == IronChestType.DIRTCHEST9000) {
addSlotToContainer(type.makeSlot(chestInventory, 0, 12 + 4 * 18, 8 + 2 * 18));
} else {
for (int chestRow = 0; chestRow < type.getRowCount(); chestRow++)
{
for (int chestCol = 0; chestCol < type.getRowLength(); chestCol++)
{
addSlotToContainer(type.makeSlot(chestInventory, chestCol + chestRow * type.getRowLength(), 12 + chestCol * 18, 8 + chestRow * 18));
}
}
}
int leftCol = (xSize - 162) / 2 + 1;
for (int playerInvRow = 0; playerInvRow < 3; playerInvRow++)
{
for (int playerInvCol = 0; playerInvCol < 9; playerInvCol++)
{
addSlotToContainer(new Slot(playerInventory, playerInvCol + playerInvRow * 9 + 9, leftCol + playerInvCol * 18, ySize - (4 - playerInvRow) * 18
- 10));
}
}
for (int hotbarSlot = 0; hotbarSlot < 9; hotbarSlot++)
{
addSlotToContainer(new Slot(playerInventory, hotbarSlot, leftCol + hotbarSlot * 18, ySize - 24));
}
}
public EntityPlayer getPlayer()
{
return player;
}
@ChestContainer.RowSizeCallback
public int getNumColumns() {
return type.getRowLength();
}
}

View File

@ -1,88 +0,0 @@
/*******************************************************************************
* Copyright (c) 2012 cpw.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html
*
* Contributors:
* cpw - initial API and implementation
******************************************************************************/
package cpw.mods.ironchest;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.config.Configuration;
import org.apache.logging.log4j.Level;
import cpw.mods.fml.common.FMLLog;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.registry.GameRegistry;
@Mod(modid = "IronChest", name = "Iron Chests", dependencies = "required-after:Forge@[7.0,);required-after:FML@[5.0.5,)")
public class IronChest {
public static BlockIronChest ironChestBlock;
@SidedProxy(clientSide = "cpw.mods.ironchest.client.ClientProxy", serverSide = "cpw.mods.ironchest.CommonProxy")
public static CommonProxy proxy;
@Instance("IronChest")
public static IronChest instance;
public static boolean CACHE_RENDER = true;
public static boolean OCELOTS_SITONCHESTS = true;
@EventHandler
public void preInit(FMLPreInitializationEvent event)
{
Version.init(event.getVersionProperties());
event.getModMetadata().version = Version.fullVersionString();
Configuration cfg = new Configuration(event.getSuggestedConfigurationFile());
try
{
cfg.load();
ChestChangerType.buildItems(cfg);
CACHE_RENDER = cfg.get(Configuration.CATEGORY_GENERAL, "cacheRenderingInformation", true).getBoolean(true);
OCELOTS_SITONCHESTS = cfg.get(Configuration.CATEGORY_GENERAL, "ocelotsSitOnChests", true).getBoolean(true);
}
catch (Exception e)
{
FMLLog.log(Level.ERROR, e, "IronChest has a problem loading its configuration");
}
finally
{
if (cfg.hasChanged())
cfg.save();
}
ironChestBlock = new BlockIronChest();
GameRegistry.registerBlock(ironChestBlock, ItemIronChest.class, "BlockIronChest");
PacketHandler.INSTANCE.ordinal();
}
@EventHandler
public void load(FMLInitializationEvent evt)
{
for (IronChestType typ : IronChestType.values())
{
GameRegistry.registerTileEntityWithAlternatives(typ.clazz, "IronChest."+typ.name(), typ.name());
proxy.registerTileEntitySpecialRenderer(typ);
}
IronChestType.registerBlocksAndRecipes(ironChestBlock);
ChestChangerType.generateRecipes();
NetworkRegistry.INSTANCE.registerGuiHandler(instance, proxy);
proxy.registerRenderInformation();
// if (OCELOTS_SITONCHESTS)
// {
// MinecraftForge.EVENT_BUS.register(new OcelotsSitOnChestsHandler());
// }
MinecraftForge.EVENT_BUS.register(this);
}
@EventHandler
public void modsLoaded(FMLPostInitializationEvent evt)
{
}
}

View File

@ -1,22 +0,0 @@
package cpw.mods.ironchest;
import net.minecraft.entity.ai.EntityAIOcelotSit;
import net.minecraft.entity.passive.EntityOcelot;
import net.minecraft.world.World;
public class IronChestAIOcelotSit extends EntityAIOcelotSit {
public IronChestAIOcelotSit(EntityOcelot par1EntityOcelot, float par2)
{
super(par1EntityOcelot, par2);
}
/* @Override
protected boolean func_151486_a(World world, int x, int y, int z)
{
if (world.getBlock(x, y, z) == IronChest.ironChestBlock)
{
return true;
}
return super.func_151486_a(world, x, y, z);
}
*/}

View File

@ -1,265 +0,0 @@
/*******************************************************************************
* Copyright (c) 2012 cpw.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html
*
* Contributors:
* cpw - initial API and implementation
******************************************************************************/
package cpw.mods.ironchest;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagByte;
import net.minecraft.util.IIcon;
import net.minecraftforge.oredict.ShapedOreRecipe;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public enum IronChestType {
IRON(54, 9, true, "Iron Chest", "ironchest.png", 0, Arrays.asList("ingotIron", "ingotRefinedIron"), TileEntityIronChest.class, "mmmmPmmmm", "mGmG3GmGm"),
GOLD(81, 9, true, "Gold Chest", "goldchest.png", 1, Arrays.asList("ingotGold"), TileEntityGoldChest.class, "mmmmPmmmm", "mGmG4GmGm"),
DIAMOND(108, 12, true, "Diamond Chest", "diamondchest.png", 2, Arrays.asList("gemDiamond"), TileEntityDiamondChest.class, "GGGmPmGGG", "GGGG4Gmmm"),
COPPER(45, 9, false, "Copper Chest", "copperchest.png", 3, Arrays.asList("ingotCopper"), TileEntityCopperChest.class, "mmmmCmmmm"),
SILVER(72, 9, false, "Silver Chest", "silverchest.png", 4, Arrays.asList("ingotSilver"), TileEntitySilverChest.class, "mmmm3mmmm", "mGmG0GmGm"),
CRYSTAL(108, 12, true, "Crystal Chest", "crystalchest.png", 5, Arrays.asList("blockGlass"), TileEntityCrystalChest.class, "GGGGPGGGG"),
OBSIDIAN(108, 12, false, "Obsidian Chest", "obsidianchest.png", 6, Arrays.asList("obsidian"), TileEntityObsidianChest.class, "mmmm2mmmm"),
DIRTCHEST9000(1, 1, false, "Dirt Chest 9000", "dirtchest.png",7,Arrays.asList("dirt"), TileEntityDirtChest.class,Item.getItemFromBlock(Blocks.dirt),"mmmmCmmmm"),
WOOD(0, 0, false, "", "", -1, Arrays.asList("plankWood"), null);
int size;
private int rowLength;
public String friendlyName;
private boolean tieredChest;
private String modelTexture;
private int textureRow;
public Class<? extends TileEntityIronChest> clazz;
private String[] recipes;
private ArrayList<String> matList;
private Item itemFilter;
IronChestType(int size, int rowLength, boolean tieredChest, String friendlyName, String modelTexture, int textureRow, List<String> mats,
Class<? extends TileEntityIronChest> clazz, String... recipes)
{
this(size, rowLength, tieredChest, friendlyName, modelTexture, textureRow, mats, clazz, (Item)null, recipes);
}
IronChestType(int size, int rowLength, boolean tieredChest, String friendlyName, String modelTexture, int textureRow, List<String> mats,
Class<? extends TileEntityIronChest> clazz, Item itemFilter, String... recipes)
{
this.size = size;
this.rowLength = rowLength;
this.tieredChest = tieredChest;
this.friendlyName = friendlyName;
this.modelTexture = modelTexture;
this.textureRow = textureRow;
this.clazz = clazz;
this.itemFilter = itemFilter;
this.recipes = recipes;
this.matList = new ArrayList<String>();
matList.addAll(mats);
}
public String getModelTexture()
{
return modelTexture;
}
public int getTextureRow()
{
return textureRow;
}
public static TileEntityIronChest makeEntity(int metadata)
{
// Compatibility
int chesttype = validateMeta(metadata);
if (chesttype == metadata)
{
try
{
TileEntityIronChest te = values()[chesttype].clazz.newInstance();
return te;
}
catch (InstantiationException e)
{
// unpossible
e.printStackTrace();
}
catch (IllegalAccessException e)
{
// unpossible
e.printStackTrace();
}
}
return null;
}
public static void registerTranslations()
{
}
public static void registerBlocksAndRecipes(BlockIronChest blockResult)
{
ItemStack previous = new ItemStack(Blocks.chest);
for (IronChestType typ : values())
{
generateRecipesForType(blockResult, previous, typ);
ItemStack chest = new ItemStack(blockResult, 1, typ.ordinal());
if (typ.isValidForCreativeMode()) GameRegistry.registerCustomItemStack(typ.friendlyName, chest);
if (typ.tieredChest) previous = chest;
}
}
public static void generateRecipesForType(BlockIronChest blockResult, Object previousTier, IronChestType type)
{
for (String recipe : type.recipes)
{
String[] recipeSplit = new String[] { recipe.substring(0, 3), recipe.substring(3, 6), recipe.substring(6, 9) };
Object mainMaterial = null;
for (String mat : type.matList)
{
mainMaterial = translateOreName(mat);
addRecipe(new ItemStack(blockResult, 1, type.ordinal()), recipeSplit,
'm', mainMaterial, 'P', previousTier, /* previous tier of chest */
'G', Blocks.glass, 'C', Blocks.chest,
'0', new ItemStack(blockResult, 1, 0), /* Iron Chest */
'1', new ItemStack(blockResult, 1, 1), /* Gold Chest */
'2', new ItemStack(blockResult, 1, 2), /* Diamond Chest */
'3', new ItemStack(blockResult, 1, 3), /* Copper Chest */
'4', new ItemStack(blockResult, 1, 4)/* Silver Chest */
);
}
}
}
public static Object translateOreName(String mat)
{
if (mat == "ingotIron")
{
return Items.iron_ingot;
}
else if (mat == "ingotGold")
{
return Items.gold_ingot;
}
else if (mat == "gemDiamond")
{
return Items.diamond;
}
else if (mat == "blockGlass")
{
return Blocks.glass;
}
else if (mat == "obsidian")
{
return Blocks.obsidian;
}
else if (mat == "dirt")
{
return Blocks.dirt;
}
return mat;
}
public static void addRecipe(ItemStack is, Object... parts)
{
ShapedOreRecipe oreRecipe = new ShapedOreRecipe(is, parts);
GameRegistry.addRecipe(oreRecipe);
}
public int getRowCount()
{
return size / rowLength;
}
public int getRowLength()
{
return rowLength;
}
public boolean isTransparent()
{
return this == CRYSTAL;
}
public List<String> getMatList()
{
return matList;
}
public static int validateMeta(int i)
{
if (i < values().length && values()[i].size > 0)
{
return i;
}
else
{
return 0;
}
}
public boolean isValidForCreativeMode()
{
return validateMeta(ordinal()) == ordinal();
}
public boolean isExplosionResistant()
{
return this == OBSIDIAN;
}
@SideOnly(Side.CLIENT)
private IIcon[] icons;
@SideOnly(Side.CLIENT)
public void makeIcons(IIconRegister par1IconRegister)
{
if (isValidForCreativeMode())
{
icons = new IIcon[3];
int i = 0;
for (String s : sideNames)
{
icons[i++] = par1IconRegister.registerIcon(String.format("ironchest:%s_%s",name().toLowerCase(),s));
}
}
}
@SideOnly(Side.CLIENT)
public IIcon getIcon(int side)
{
return icons[sideMapping[side]];
}
private static String[] sideNames = { "top", "front", "side" };
private static int[] sideMapping = { 0, 0, 2, 1, 2, 2, 2 };
public Slot makeSlot(IInventory chestInventory, int index, int x, int y)
{
return new ValidatingSlot(chestInventory, index, x, y, this);
}
public boolean acceptsStack(ItemStack itemstack)
{
return itemFilter == null || itemstack == null || itemstack.getItem() == itemFilter;
}
public void adornItemDrop(ItemStack item)
{
if (this == DIRTCHEST9000)
{
item.setTagInfo("dirtchest", new NBTTagByte((byte) 1));
}
}
}

View File

@ -1,115 +0,0 @@
/*******************************************************************************
* Copyright (c) 2012 cpw.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html
*
* Contributors:
* cpw - initial API and implementation
******************************************************************************/
package cpw.mods.ironchest;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityChest;
import net.minecraft.world.World;
import cpw.mods.fml.common.ObfuscationReflectionHelper;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class ItemChestChanger extends Item {
private ChestChangerType type;
public ItemChestChanger(ChestChangerType type)
{
super();
setMaxStackSize(1);
this.type = type;
setUnlocalizedName("ironchest:"+type.name());
setCreativeTab(CreativeTabs.tabMisc);
}
@Override
@SideOnly(Side.CLIENT)
public void registerIcons(IIconRegister par1IconRegister)
{
this.itemIcon = par1IconRegister.registerIcon("ironchest:"+type.itemName);
}
@Override
public boolean onItemUseFirst(ItemStack stack, EntityPlayer player, World world, int X, int Y, int Z, int side, float hitX, float hitY, float hitZ)
{
if (world.isRemote) return false;
TileEntity te = world.getTileEntity(X, Y, Z);
TileEntityIronChest newchest;
if (te != null && te instanceof TileEntityIronChest)
{
TileEntityIronChest ironchest = (TileEntityIronChest) te;
newchest = ironchest.applyUpgradeItem(this);
if (newchest == null)
{
return false;
}
}
else if (te != null && te instanceof TileEntityChest)
{
TileEntityChest tec = (TileEntityChest) te;
if (tec.numPlayersUsing > 0)
{
return false;
}
if (!getType().canUpgrade(IronChestType.WOOD))
{
return false;
}
// Force old TE out of the world so that adjacent chests can update
newchest = IronChestType.makeEntity(getTargetChestOrdinal(IronChestType.WOOD.ordinal()));
int newSize = newchest.chestContents.length;
ItemStack[] chestContents = ObfuscationReflectionHelper.getPrivateValue(TileEntityChest.class, tec, 0);
System.arraycopy(chestContents, 0, newchest.chestContents, 0, Math.min(newSize, chestContents.length));
BlockIronChest block = IronChest.ironChestBlock;
block.dropContent(newSize, tec, world, tec.xCoord, tec.yCoord, tec.zCoord);
newchest.setFacing((byte) tec.getBlockMetadata());
newchest.sortTopStacks();
for (int i = 0; i < Math.min(newSize, chestContents.length); i++)
{
chestContents[i] = null;
}
// Clear the old block out
world.setBlock(X, Y, Z, Blocks.air, 0, 3);
// Force the Chest TE to reset it's knowledge of neighbouring blocks
tec.updateContainingBlockInfo();
// Force the Chest TE to update any neighbours so they update next
// tick
tec.checkForAdjacentChests();
// And put in our block instead
world.setBlock(X, Y, Z, block, newchest.getType().ordinal(), 3);
}
else
{
return false;
}
world.setTileEntity(X, Y, Z, newchest);
world.setBlockMetadataWithNotify(X, Y, Z, newchest.getType().ordinal(), 3);
stack.stackSize = 0;
return true;
}
public int getTargetChestOrdinal(int sourceOrdinal)
{
return type.getTarget();
}
public ChestChangerType getType()
{
return type;
}
}

View File

@ -1,37 +0,0 @@
/*******************************************************************************
* Copyright (c) 2012 cpw.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html
*
* Contributors:
* cpw - initial API and implementation
******************************************************************************/
package cpw.mods.ironchest;
import net.minecraft.block.Block;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
public class ItemIronChest extends ItemBlock {
public ItemIronChest(Block block)
{
super(block);
setMaxDamage(0);
setHasSubtypes(true);
}
@Override
public int getMetadata(int i)
{
return IronChestType.validateMeta(i);
}
@Override
public String getUnlocalizedName(ItemStack itemstack)
{
return "tile.ironchest:"+IronChestType.values()[itemstack.getItemDamage()].name();
}
}

View File

@ -1,33 +0,0 @@
package cpw.mods.ironchest;
import net.minecraft.item.ItemStack;
public class MappableItemStackWrapper {
private ItemStack wrap;
public MappableItemStackWrapper(ItemStack toWrap)
{
wrap = toWrap;
}
@Override
public boolean equals(Object obj)
{
if (!(obj instanceof MappableItemStackWrapper)) return false;
MappableItemStackWrapper isw = (MappableItemStackWrapper) obj;
if (wrap.getHasSubtypes())
{
return isw.wrap.isItemEqual(wrap);
}
else
{
return isw.wrap == wrap;
}
}
@Override
public int hashCode()
{
return System.identityHashCode(wrap);
}
}

View File

@ -1,30 +0,0 @@
package cpw.mods.ironchest;
import java.util.List;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import net.minecraft.entity.ai.EntityAIOcelotSit;
import net.minecraft.entity.ai.EntityAITasks;
import net.minecraft.entity.passive.EntityOcelot;
import net.minecraftforge.event.entity.living.LivingEvent;
public class OcelotsSitOnChestsHandler {
@SubscribeEvent
public void changeSittingTaskForOcelots(LivingEvent.LivingUpdateEvent evt)
{
if (evt.entityLiving.ticksExisted < 5 && evt.entityLiving instanceof EntityOcelot)
{
EntityOcelot ocelot = (EntityOcelot) evt.entityLiving;
@SuppressWarnings("unchecked")
List<EntityAITasks.EntityAITaskEntry> tasks = ocelot.tasks.taskEntries;
for (int i = 0; i < tasks.size(); i++)
{
EntityAITasks.EntityAITaskEntry task = tasks.get(i);
if (task.priority == 6 && (task.action instanceof EntityAIOcelotSit) && !(task.action instanceof IronChestAIOcelotSit))
{
task.action = new IronChestAIOcelotSit(ocelot, 0.4F);
}
}
}
}
}

View File

@ -1,200 +0,0 @@
/*******************************************************************************
* Copyright (c) 2012 cpw.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html
*
* Contributors:
* cpw - initial API and implementation
******************************************************************************/
package cpw.mods.ironchest;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import java.util.EnumMap;
import net.minecraft.network.Packet;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.network.FMLEmbeddedChannel;
import cpw.mods.fml.common.network.FMLIndexedMessageToMessageCodec;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.network.internal.FMLProxyPacket;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
/**
* Handles the packet wrangling for IronChest
* @author cpw
*
*/
public enum PacketHandler {
INSTANCE;
/**
* Our channel "pair" from {@link NetworkRegistry}
*/
private EnumMap<Side, FMLEmbeddedChannel> channels;
/**
* Make our packet handler, and add an {@link IronChestCodec} always
*/
private PacketHandler()
{
// request a channel pair for IronChest from the network registry
// Add the IronChestCodec as a member of both channel pipelines
this.channels = NetworkRegistry.INSTANCE.newChannel("IronChest", new IronChestCodec());
if (FMLCommonHandler.instance().getSide() == Side.CLIENT)
{
addClientHandler();
}
}
/**
* This is only called on the client side - it adds an
* {@link IronChestMessageHandler} to the client side pipeline, since the
* only place we expect to <em>handle</em> messages is on the client.
*/
@SideOnly(Side.CLIENT)
private void addClientHandler() {
FMLEmbeddedChannel clientChannel = this.channels.get(Side.CLIENT);
// These two lines find the existing codec (Ironchestcodec) and insert our message handler after it
// in the pipeline
String codec = clientChannel.findChannelHandlerNameForType(IronChestCodec.class);
clientChannel.pipeline().addAfter(codec, "ClientHandler", new IronChestMessageHandler());
}
/**
* This class simply handles the {@link IronChestMessage} when it's received
* at the client side It can contain client only code, because it's only run
* on the client.
*
* @author cpw
*
*/
private static class IronChestMessageHandler extends SimpleChannelInboundHandler<IronChestMessage>
{
@Override
protected void channelRead0(ChannelHandlerContext ctx, IronChestMessage msg) throws Exception
{
World world = IronChest.proxy.getClientWorld();
TileEntity te = world.getTileEntity(msg.x, msg.y, msg.z);
if (te instanceof TileEntityIronChest)
{
TileEntityIronChest icte = (TileEntityIronChest) te;
icte.setFacing(msg.facing);
icte.handlePacketData(msg.type, msg.items);
}
}
}
/**
* This is our "message". In fact, {@link FMLIndexedMessageToMessageCodec}
* can handle many messages on the same channel at once, using a
* discriminator byte. But for IronChest, we only need the one message, so
* we have just this.
*
* @author cpw
*
*/
public static class IronChestMessage
{
int x;
int y;
int z;
int type;
int facing;
int[] items;
}
/**
* This is the codec that automatically transforms the
* {@link FMLProxyPacket} which wraps the client and server custom payload
* packets into a message we care about.
*
* @author cpw
*
*/
private class IronChestCodec extends FMLIndexedMessageToMessageCodec<IronChestMessage>
{
/**
* We register our discriminator bytes here. We only have the one type, so we only
* register one.
*/
public IronChestCodec()
{
addDiscriminator(0, IronChestMessage.class);
}
@Override
public void encodeInto(ChannelHandlerContext ctx, IronChestMessage msg, ByteBuf target) throws Exception
{
target.writeInt(msg.x);
target.writeInt(msg.y);
target.writeInt(msg.z);
int typeAndFacing = ((msg.type & 0x0F) | ((msg.facing & 0x0F) << 4)) & 0xFF;
target.writeByte(typeAndFacing);
target.writeBoolean(msg.items != null);
if (msg.items != null)
{
int[] items = msg.items;
for (int j = 0; j < items.length; j++)
{
int i = items[j];
target.writeInt(i);
}
}
}
@Override
public void decodeInto(ChannelHandlerContext ctx, ByteBuf dat, IronChestMessage msg)
{
msg.x = dat.readInt();
msg.y = dat.readInt();
msg.z = dat.readInt();
int typDat = dat.readByte();
msg.type = (byte)(typDat & 0xf);
msg.facing = (byte)((typDat >> 4) & 0xf);
boolean hasStacks = dat.readBoolean();
msg.items = new int[0];
if (hasStacks)
{
msg.items = new int[24];
for (int i = 0; i < msg.items.length; i++)
{
msg.items[i] = dat.readInt();
}
}
}
}
/**
* This is a utility method called to transform a packet from a custom
* packet into a "system packet". We're called from
* {@link TileEntity#getDescriptionPacket()} in this case, but there are
* others. All network packet methods in minecraft have been adapted to
* handle {@link FMLProxyPacket} but general purpose objects can't be
* handled sadly.
*
* This method uses the {@link IronChestCodec} to transform a custom packet
* {@link IronChestMessage} into an {@link FMLProxyPacket} by using the
* utility method {@link FMLEmbeddedChannel#generatePacketFrom(Object)} on
* the channel to do exactly that.
*
* @param tileEntityIronChest
* @return
*/
public static Packet getPacket(TileEntityIronChest tileEntityIronChest)
{
IronChestMessage msg = new IronChestMessage();
msg.x = tileEntityIronChest.xCoord;
msg.y = tileEntityIronChest.yCoord;
msg.z = tileEntityIronChest.zCoord;
msg.type = tileEntityIronChest.getType().ordinal();
msg.facing = tileEntityIronChest.getFacing();
msg.items = tileEntityIronChest.buildIntDataList();
return INSTANCE.channels.get(Side.SERVER).generatePacketFrom(msg);
}
}

View File

@ -1,19 +0,0 @@
/*******************************************************************************
* Copyright (c) 2012 cpw.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html
*
* Contributors:
* cpw - initial API and implementation
******************************************************************************/
package cpw.mods.ironchest;
public class TileEntityCopperChest extends TileEntityIronChest {
public TileEntityCopperChest()
{
super(IronChestType.COPPER);
}
}

View File

@ -1,18 +0,0 @@
/*******************************************************************************
* Copyright (c) 2012 cpw.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html
*
* Contributors:
* cpw - initial API and implementation
******************************************************************************/
package cpw.mods.ironchest;
public class TileEntityCrystalChest extends TileEntityIronChest {
public TileEntityCrystalChest()
{
super(IronChestType.CRYSTAL);
}
}

View File

@ -1,18 +0,0 @@
/*******************************************************************************
* Copyright (c) 2012 cpw.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html
*
* Contributors:
* cpw - initial API and implementation
******************************************************************************/
package cpw.mods.ironchest;
public class TileEntityDiamondChest extends TileEntityIronChest {
public TileEntityDiamondChest()
{
super(IronChestType.DIAMOND);
}
}

View File

@ -1,42 +0,0 @@
package cpw.mods.ironchest;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.nbt.NBTTagString;
import net.minecraft.util.StatCollector;
public class TileEntityDirtChest extends TileEntityIronChest {
private static ItemStack dirtChest9000GuideBook = new ItemStack(Items.written_book);
static {
dirtChest9000GuideBook.setTagInfo("author", new NBTTagString("cpw"));
dirtChest9000GuideBook.setTagInfo("title", new NBTTagString(StatCollector.translateToLocal("book.ironchest:dirtchest9000.title")));
NBTTagList pages = new NBTTagList();
pages.appendTag(new NBTTagString(StatCollector.translateToLocal("book.ironchest:dirtchest9000.page1")));
pages.appendTag(new NBTTagString(StatCollector.translateToLocal("book.ironchest:dirtchest9000.page2")));
pages.appendTag(new NBTTagString(StatCollector.translateToLocal("book.ironchest:dirtchest9000.page3")));
pages.appendTag(new NBTTagString(StatCollector.translateToLocal("book.ironchest:dirtchest9000.page4")));
pages.appendTag(new NBTTagString(StatCollector.translateToLocal("book.ironchest:dirtchest9000.page5")));
dirtChest9000GuideBook.setTagInfo("pages", pages);
}
public TileEntityDirtChest() {
super(IronChestType.DIRTCHEST9000);
}
@Override
public void wasPlaced(EntityLivingBase entityliving, ItemStack itemStack)
{
if (!(itemStack.hasTagCompound() && itemStack.getTagCompound().getBoolean("dirtchest"))) {
setInventorySlotContents(0, dirtChest9000GuideBook.copy());
}
}
@Override
public void removeAdornments()
{
if (chestContents[0] != null && chestContents[0].isItemEqual(dirtChest9000GuideBook)) {
chestContents[0] = null;
}
}
}

View File

@ -1,19 +0,0 @@
/*******************************************************************************
* Copyright (c) 2012 cpw.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html
*
* Contributors:
* cpw - initial API and implementation
******************************************************************************/
package cpw.mods.ironchest;
public class TileEntityGoldChest extends TileEntityIronChest {
public TileEntityGoldChest()
{
super(IronChestType.GOLD);
}
}

View File

@ -1,532 +0,0 @@
/*******************************************************************************
* Copyright (c) 2012 cpw.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html
*
* Contributors:
* cpw - initial API and implementation
******************************************************************************/
package cpw.mods.ironchest;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.network.Packet;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraftforge.common.util.Constants;
import net.minecraftforge.common.util.ForgeDirection;
public class TileEntityIronChest extends TileEntity implements IInventory {
private int ticksSinceSync = -1;
public float prevLidAngle;
public float lidAngle;
private int numUsingPlayers;
private IronChestType type;
public ItemStack[] chestContents;
private ItemStack[] topStacks;
private int facing;
private boolean inventoryTouched;
private boolean hadStuff;
public TileEntityIronChest()
{
this(IronChestType.IRON);
}
protected TileEntityIronChest(IronChestType type)
{
super();
this.type = type;
this.chestContents = new ItemStack[getSizeInventory()];
this.topStacks = new ItemStack[8];
}
public ItemStack[] getContents()
{
return chestContents;
}
@Override
public int getSizeInventory()
{
return type.size;
}
public int getFacing()
{
return this.facing;
}
@Override
public String getInventoryName()
{
return type.name();
}
public IronChestType getType()
{
return type;
}
@Override
public ItemStack getStackInSlot(int i)
{
inventoryTouched = true;
return chestContents[i];
}
@Override
public void markDirty()
{
super.markDirty();
sortTopStacks();
}
protected void sortTopStacks()
{
if (!type.isTransparent() || (worldObj != null && worldObj.isRemote))
{
return;
}
ItemStack[] tempCopy = new ItemStack[getSizeInventory()];
boolean hasStuff = false;
int compressedIdx = 0;
mainLoop: for (int i = 0; i < getSizeInventory(); i++)
{
if (chestContents[i] != null)
{
for (int j = 0; j < compressedIdx; j++)
{
if (tempCopy[j].isItemEqual(chestContents[i]))
{
tempCopy[j].stackSize += chestContents[i].stackSize;
continue mainLoop;
}
}
tempCopy[compressedIdx++] = chestContents[i].copy();
hasStuff = true;
}
}
if (!hasStuff && hadStuff)
{
hadStuff = false;
for (int i = 0; i < topStacks.length; i++)
{
topStacks[i] = null;
}
if (worldObj != null)
{
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}
return;
}
hadStuff = true;
Arrays.sort(tempCopy, new Comparator<ItemStack>() {
@Override
public int compare(ItemStack o1, ItemStack o2)
{
if (o1 == null)
{
return 1;
}
else if (o2 == null)
{
return -1;
}
else
{
return o2.stackSize - o1.stackSize;
}
}
});
int p = 0;
for (int i = 0; i < tempCopy.length; i++)
{
if (tempCopy[i] != null && tempCopy[i].stackSize > 0)
{
topStacks[p++] = tempCopy[i];
if (p == topStacks.length)
{
break;
}
}
}
for (int i = p; i < topStacks.length; i++)
{
topStacks[i] = null;
}
if (worldObj != null)
{
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}
}
@Override
public ItemStack decrStackSize(int i, int j)
{
if (chestContents[i] != null)
{
if (chestContents[i].stackSize <= j)
{
ItemStack itemstack = chestContents[i];
chestContents[i] = null;
markDirty();
return itemstack;
}
ItemStack itemstack1 = chestContents[i].splitStack(j);
if (chestContents[i].stackSize == 0)
{
chestContents[i] = null;
}
markDirty();
return itemstack1;
}
else
{
return null;
}
}
@Override
public void setInventorySlotContents(int i, ItemStack itemstack)
{
chestContents[i] = itemstack;
if (itemstack != null && itemstack.stackSize > getInventoryStackLimit())
{
itemstack.stackSize = getInventoryStackLimit();
}
markDirty();
}
@Override
public void readFromNBT(NBTTagCompound nbttagcompound)
{
super.readFromNBT(nbttagcompound);
NBTTagList nbttaglist = nbttagcompound.getTagList("Items", Constants.NBT.TAG_COMPOUND);
chestContents = new ItemStack[getSizeInventory()];
for (int i = 0; i < nbttaglist.tagCount(); i++)
{
NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i);
int j = nbttagcompound1.getByte("Slot") & 0xff;
if (j >= 0 && j < chestContents.length)
{
chestContents[j] = ItemStack.loadItemStackFromNBT(nbttagcompound1);
}
}
facing = nbttagcompound.getByte("facing");
sortTopStacks();
}
@Override
public void writeToNBT(NBTTagCompound nbttagcompound)
{
super.writeToNBT(nbttagcompound);
NBTTagList nbttaglist = new NBTTagList();
for (int i = 0; i < chestContents.length; i++)
{
if (chestContents[i] != null)
{
NBTTagCompound nbttagcompound1 = new NBTTagCompound();
nbttagcompound1.setByte("Slot", (byte) i);
chestContents[i].writeToNBT(nbttagcompound1);
nbttaglist.appendTag(nbttagcompound1);
}
}
nbttagcompound.setTag("Items", nbttaglist);
nbttagcompound.setByte("facing", (byte)facing);
}
@Override
public int getInventoryStackLimit()
{
return 64;
}
@Override
public boolean isUseableByPlayer(EntityPlayer entityplayer)
{
if (worldObj == null)
{
return true;
}
if (worldObj.getTileEntity(xCoord, yCoord, zCoord) != this)
{
return false;
}
return entityplayer.getDistanceSq((double) xCoord + 0.5D, (double) yCoord + 0.5D, (double) zCoord + 0.5D) <= 64D;
}
@Override
public void updateEntity()
{
super.updateEntity();
// Resynchronize clients with the server state
if (worldObj != null && !this.worldObj.isRemote && this.numUsingPlayers != 0 && (this.ticksSinceSync + this.xCoord + this.yCoord + this.zCoord) % 200 == 0)
{
this.numUsingPlayers = 0;
float var1 = 5.0F;
@SuppressWarnings("unchecked")
List<EntityPlayer> var2 = this.worldObj.getEntitiesWithinAABB(EntityPlayer.class, AxisAlignedBB.getAABBPool().getAABB((double)((float)this.xCoord - var1), (double)((float)this.yCoord - var1), (double)((float)this.zCoord - var1), (double)((float)(this.xCoord + 1) + var1), (double)((float)(this.yCoord + 1) + var1), (double)((float)(this.zCoord + 1) + var1)));
Iterator<EntityPlayer> var3 = var2.iterator();
while (var3.hasNext())
{
EntityPlayer var4 = var3.next();
if (var4.openContainer instanceof ContainerIronChest)
{
++this.numUsingPlayers;
}
}
}
if (worldObj != null && !worldObj.isRemote && ticksSinceSync < 0)
{
worldObj.addBlockEvent(xCoord, yCoord, zCoord, IronChest.ironChestBlock, 3, ((numUsingPlayers << 3) & 0xF8) | (facing & 0x7));
}
if (!worldObj.isRemote && inventoryTouched)
{
inventoryTouched = false;
sortTopStacks();
}
this.ticksSinceSync++;
prevLidAngle = lidAngle;
float f = 0.1F;
if (numUsingPlayers > 0 && lidAngle == 0.0F)
{
double d = (double) xCoord + 0.5D;
double d1 = (double) zCoord + 0.5D;
worldObj.playSoundEffect(d, (double) yCoord + 0.5D, d1, "random.chestopen", 0.5F, worldObj.rand.nextFloat() * 0.1F + 0.9F);
}
if (numUsingPlayers == 0 && lidAngle > 0.0F || numUsingPlayers > 0 && lidAngle < 1.0F)
{
float f1 = lidAngle;
if (numUsingPlayers > 0)
{
lidAngle += f;
}
else
{
lidAngle -= f;
}
if (lidAngle > 1.0F)
{
lidAngle = 1.0F;
}
float f2 = 0.5F;
if (lidAngle < f2 && f1 >= f2)
{
double d2 = (double) xCoord + 0.5D;
double d3 = (double) zCoord + 0.5D;
worldObj.playSoundEffect(d2, (double) yCoord + 0.5D, d3, "random.chestclosed", 0.5F, worldObj.rand.nextFloat() * 0.1F + 0.9F);
}
if (lidAngle < 0.0F)
{
lidAngle = 0.0F;
}
}
}
@Override
public boolean receiveClientEvent(int i, int j)
{
if (i == 1)
{
numUsingPlayers = j;
}
else if (i == 2)
{
facing = (byte) j;
}
else if (i == 3)
{
facing = (byte) (j & 0x7);
numUsingPlayers = (j & 0xF8) >> 3;
}
return true;
}
@Override
public void openInventory()
{
if (worldObj == null) return;
numUsingPlayers++;
worldObj.addBlockEvent(xCoord, yCoord, zCoord, IronChest.ironChestBlock, 1, numUsingPlayers);
}
@Override
public void closeInventory()
{
if (worldObj == null) return;
numUsingPlayers--;
worldObj.addBlockEvent(xCoord, yCoord, zCoord, IronChest.ironChestBlock, 1, numUsingPlayers);
}
public void setFacing(int facing2)
{
this.facing = facing2;
}
public TileEntityIronChest applyUpgradeItem(ItemChestChanger itemChestChanger)
{
if (numUsingPlayers > 0)
{
return null;
}
if (!itemChestChanger.getType().canUpgrade(this.getType()))
{
return null;
}
TileEntityIronChest newEntity = IronChestType.makeEntity(itemChestChanger.getTargetChestOrdinal(getType().ordinal()));
int newSize = newEntity.chestContents.length;
System.arraycopy(chestContents, 0, newEntity.chestContents, 0, Math.min(newSize, chestContents.length));
BlockIronChest block = IronChest.ironChestBlock;
block.dropContent(newSize, this, this.worldObj, this.xCoord, this.yCoord, this.zCoord);
newEntity.setFacing(facing);
newEntity.sortTopStacks();
newEntity.ticksSinceSync = -1;
return newEntity;
}
public ItemStack[] getTopItemStacks()
{
return topStacks;
}
public TileEntityIronChest updateFromMetadata(int l)
{
if (worldObj != null && worldObj.isRemote)
{
if (l != type.ordinal())
{
worldObj.setTileEntity(xCoord, yCoord, zCoord, IronChestType.makeEntity(l));
return (TileEntityIronChest) worldObj.getTileEntity(xCoord, yCoord, zCoord);
}
}
return this;
}
@Override
public Packet getDescriptionPacket()
{
return PacketHandler.getPacket(this);
}
public void handlePacketData(int typeData, int[] intData)
{
TileEntityIronChest chest = this;
if (this.type.ordinal() != typeData)
{
chest = updateFromMetadata(typeData);
}
if (IronChestType.values()[typeData].isTransparent() && intData != null)
{
int pos = 0;
if (intData.length < chest.topStacks.length * 3)
{
return;
}
for (int i = 0; i < chest.topStacks.length; i++)
{
if (intData[pos + 2] != 0)
{
Item it = Item.getItemById(intData[pos]);
ItemStack is = new ItemStack(it, intData[pos + 2], intData[pos + 1]);
chest.topStacks[i] = is;
}
else
{
chest.topStacks[i] = null;
}
pos += 3;
}
}
}
public int[] buildIntDataList()
{
if (type.isTransparent())
{
int[] sortList = new int[topStacks.length * 3];
int pos = 0;
for (ItemStack is : topStacks)
{
if (is != null)
{
sortList[pos++] = Item.getIdFromItem(is.getItem());
sortList[pos++] = is.getItemDamage();
sortList[pos++] = is.stackSize;
}
else
{
sortList[pos++] = 0;
sortList[pos++] = 0;
sortList[pos++] = 0;
}
}
return sortList;
}
return null;
}
@Override
public ItemStack getStackInSlotOnClosing(int par1)
{
if (this.chestContents[par1] != null)
{
ItemStack var2 = this.chestContents[par1];
this.chestContents[par1] = null;
return var2;
}
else
{
return null;
}
}
public void setMaxStackSize(int size)
{
}
@Override
public boolean isItemValidForSlot(int i, ItemStack itemstack)
{
return type.acceptsStack(itemstack);
}
@Override
public boolean hasCustomInventoryName()
{
return false;
}
void rotateAround(ForgeDirection axis)
{
setFacing((byte)ForgeDirection.getOrientation(facing).getRotation(axis).ordinal());
worldObj.addBlockEvent(this.xCoord, this.yCoord, this.zCoord, IronChest.ironChestBlock, 2, getFacing());
}
public void wasPlaced(EntityLivingBase entityliving, ItemStack itemStack)
{
}
public void removeAdornments()
{
}
}

View File

@ -1,9 +0,0 @@
package cpw.mods.ironchest;
public class TileEntityObsidianChest extends TileEntityIronChest {
public TileEntityObsidianChest()
{
super(IronChestType.OBSIDIAN);
}
}

View File

@ -1,18 +0,0 @@
/*******************************************************************************
* Copyright (c) 2012 cpw.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html
*
* Contributors:
* cpw - initial API and implementation
******************************************************************************/
package cpw.mods.ironchest;
public class TileEntitySilverChest extends TileEntityIronChest {
public TileEntitySilverChest()
{
super(IronChestType.SILVER);
}
}

View File

@ -1,21 +0,0 @@
package cpw.mods.ironchest;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
public class ValidatingSlot extends Slot {
private IronChestType type;
public ValidatingSlot(IInventory par1iInventory, int par2, int par3, int par4, IronChestType type)
{
super(par1iInventory, par2, par3, par4);
this.type = type;
}
@Override
public boolean isItemValid(ItemStack par1ItemStack)
{
return type.acceptsStack(par1ItemStack);
}
}

View File

@ -1,35 +0,0 @@
/*******************************************************************************
* Copyright (c) 2012 cpw. All rights reserved. This program and the accompanying materials are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at http://www.gnu.org/licenses/gpl.html
*
* Contributors: cpw - initial API and implementation
******************************************************************************/
package cpw.mods.ironchest;
import java.util.Properties;
public class Version {
private static String major;
private static String minor;
private static String rev;
private static String build;
@SuppressWarnings("unused")
private static String mcversion;
static void init(Properties properties)
{
if (properties != null)
{
major = properties.getProperty("IronChest.build.major.number");
minor = properties.getProperty("IronChest.build.minor.number");
rev = properties.getProperty("IronChest.build.revision.number");
build = properties.getProperty("IronChest.build.number");
mcversion = properties.getProperty("IronChest.build.mcversion");
}
}
public static String fullVersionString()
{
return String.format("%s.%s.%s build %s", major, minor, rev, build);
}
}

View File

@ -1,55 +0,0 @@
/*******************************************************************************
* Copyright (c) 2012 cpw.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html
*
* Contributors:
* cpw - initial API and implementation
******************************************************************************/
package cpw.mods.ironchest.client;
import net.minecraft.client.renderer.tileentity.TileEntityRendererChestHelper;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.client.registry.ClientRegistry;
import cpw.mods.ironchest.CommonProxy;
import cpw.mods.ironchest.IronChestType;
import cpw.mods.ironchest.TileEntityIronChest;
public class ClientProxy extends CommonProxy {
@Override
public void registerRenderInformation()
{
TileEntityRendererChestHelper.instance = new IronChestRenderHelper();
}
@Override
public void registerTileEntitySpecialRenderer(IronChestType typ)
{
ClientRegistry.bindTileEntitySpecialRenderer(typ.clazz, new TileEntityIronChestRenderer());
}
@Override
public World getClientWorld()
{
return FMLClientHandler.instance().getClient().theWorld;
}
@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z)
{
TileEntity te = world.getTileEntity(x, y, z);
if (te != null && te instanceof TileEntityIronChest)
{
return GUIChest.GUI.buildGUI(IronChestType.values()[ID], player.inventory, (TileEntityIronChest) te);
}
else
{
return null;
}
}
}

View File

@ -1,98 +0,0 @@
/*******************************************************************************
* Copyright (c) 2012 cpw.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html
*
* Contributors:
* cpw - initial API and implementation
******************************************************************************/
package cpw.mods.ironchest.client;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.GL11;
import cpw.mods.ironchest.ContainerIronChest;
import cpw.mods.ironchest.IronChestType;
import cpw.mods.ironchest.TileEntityIronChest;
public class GUIChest extends GuiContainer {
public enum ResourceList {
IRON(new ResourceLocation("ironchest", "textures/gui/ironcontainer.png")),
COPPER(new ResourceLocation("ironchest", "textures/gui/coppercontainer.png")),
SILVER(new ResourceLocation("ironchest", "textures/gui/silvercontainer.png")),
GOLD(new ResourceLocation("ironchest", "textures/gui/goldcontainer.png")),
DIAMOND(new ResourceLocation("ironchest", "textures/gui/diamondcontainer.png")),
DIRT(new ResourceLocation("ironchest", "textures/gui/dirtcontainer.png"));
public final ResourceLocation location;
private ResourceList(ResourceLocation loc) {
this.location = loc;
}
}
public enum GUI {
IRON(184, 202, ResourceList.IRON, IronChestType.IRON),
GOLD(184, 256, ResourceList.GOLD, IronChestType.GOLD),
DIAMOND(238, 256, ResourceList.DIAMOND, IronChestType.DIAMOND),
COPPER(184, 184, ResourceList.COPPER, IronChestType.COPPER),
SILVER(184, 238, ResourceList.SILVER, IronChestType.SILVER),
CRYSTAL(238, 256, ResourceList.DIAMOND, IronChestType.CRYSTAL),
OBSIDIAN(238, 256, ResourceList.DIAMOND, IronChestType.OBSIDIAN),
DIRTCHEST9000(184, 184, ResourceList.DIRT, IronChestType.DIRTCHEST9000);
private int xSize;
private int ySize;
private ResourceList guiResourceList;
private IronChestType mainType;
private GUI(int xSize, int ySize, ResourceList guiResourceList, IronChestType mainType)
{
this.xSize = xSize;
this.ySize = ySize;
this.guiResourceList = guiResourceList;
this.mainType = mainType;
}
protected Container makeContainer(IInventory player, IInventory chest)
{
return new ContainerIronChest(player, chest, mainType, xSize, ySize);
}
public static GUIChest buildGUI(IronChestType type, IInventory playerInventory, TileEntityIronChest chestInventory)
{
return new GUIChest(values()[chestInventory.getType().ordinal()], playerInventory, chestInventory);
}
}
public int getRowLength()
{
return type.mainType.getRowLength();
}
private GUI type;
private GUIChest(GUI type, IInventory player, IInventory chest)
{
super(type.makeContainer(player, chest));
this.type = type;
this.xSize = type.xSize;
this.ySize = type.ySize;
this.allowUserInput = false;
}
@Override
protected void drawGuiContainerBackgroundLayer(float f, int i, int j)
{
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
// new "bind tex"
this.mc.getTextureManager().bindTexture(type.guiResourceList.location);
int x = (width - xSize) / 2;
int y = (height - ySize) / 2;
drawTexturedModalRect(x, y, 0, 0, xSize, ySize);
}
}

View File

@ -1,45 +0,0 @@
/*******************************************************************************
* Copyright (c) 2012 cpw.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html
*
* Contributors:
* cpw - initial API and implementation
******************************************************************************/
package cpw.mods.ironchest.client;
import java.util.Map;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.tileentity.TileEntityRendererChestHelper;
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
import com.google.common.collect.Maps;
import cpw.mods.ironchest.IronChest;
import cpw.mods.ironchest.IronChestType;
import cpw.mods.ironchest.TileEntityIronChest;
public class IronChestRenderHelper extends TileEntityRendererChestHelper {
private Map<Integer, TileEntityIronChest> itemRenders = Maps.newHashMap();
public IronChestRenderHelper()
{
for (IronChestType typ : IronChestType.values())
{
itemRenders.put(typ.ordinal(), (TileEntityIronChest) IronChest.ironChestBlock.createTileEntity(null, typ.ordinal()));
}
}
@Override
public void renderChest(Block block, int i, float f)
{
if (block == IronChest.ironChestBlock)
{
TileEntityRendererDispatcher.instance.renderTileEntityAt(itemRenders.get(i), 0.0D, 0.0D, 0.0D, 0.0F);
}
else
{
super.renderChest(block, i, f);
}
}
}

View File

@ -1,181 +0,0 @@
/*******************************************************************************
* Copyright (c) 2012 cpw.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html
*
* Contributors:
* cpw - initial API and implementation
******************************************************************************/
package cpw.mods.ironchest.client;
import static org.lwjgl.opengl.GL11.glColor4f;
import static org.lwjgl.opengl.GL11.glDisable;
import static org.lwjgl.opengl.GL11.glEnable;
import static org.lwjgl.opengl.GL11.glPopMatrix;
import static org.lwjgl.opengl.GL11.glPushMatrix;
import static org.lwjgl.opengl.GL11.glRotatef;
import static org.lwjgl.opengl.GL11.glScalef;
import static org.lwjgl.opengl.GL11.glTranslatef;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import net.minecraft.client.model.ModelChest;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.client.renderer.entity.RenderItem;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMap.Builder;
import com.google.common.primitives.SignedBytes;
import cpw.mods.ironchest.IronChestType;
import cpw.mods.ironchest.MappableItemStackWrapper;
import cpw.mods.ironchest.TileEntityIronChest;
public class TileEntityIronChestRenderer extends TileEntitySpecialRenderer {
@SuppressWarnings("unused")
private static Map<MappableItemStackWrapper, Integer> renderList = new HashMap<MappableItemStackWrapper, Integer>();
private static Map<IronChestType, ResourceLocation> locations;
static {
Builder<IronChestType, ResourceLocation> builder = ImmutableMap.<IronChestType,ResourceLocation>builder();
for (IronChestType typ : IronChestType.values()) {
builder.put(typ, new ResourceLocation("ironchest","textures/model/"+typ.getModelTexture()));
}
locations = builder.build();
}
private Random random;
@SuppressWarnings("unused")
private RenderBlocks renderBlocks;
private RenderItem itemRenderer;
private static float[][] shifts = { { 0.3F, 0.45F, 0.3F }, { 0.7F, 0.45F, 0.3F }, { 0.3F, 0.45F, 0.7F }, { 0.7F, 0.45F, 0.7F }, { 0.3F, 0.1F, 0.3F },
{ 0.7F, 0.1F, 0.3F }, { 0.3F, 0.1F, 0.7F }, { 0.7F, 0.1F, 0.7F }, { 0.5F, 0.32F, 0.5F }, };
public TileEntityIronChestRenderer()
{
model = new ModelChest();
random = new Random();
renderBlocks = new RenderBlocks();
itemRenderer = new RenderItem() {
@Override
public byte getMiniBlockCount(ItemStack stack, byte original) {
return SignedBytes.saturatedCast(Math.min(stack.stackSize / 32, 15) + 1);
}
@Override
public byte getMiniItemCount(ItemStack stack, byte original) {
return SignedBytes.saturatedCast(Math.min(stack.stackSize / 32, 7) + 1);
}
@Override
public boolean shouldBob() {
return false;
}
@Override
public boolean shouldSpreadItems() {
return false;
}
};
itemRenderer.setRenderManager(RenderManager.instance);
}
public void render(TileEntityIronChest tile, double x, double y, double z, float partialTick) {
if (tile == null) {
return;
}
int facing = 3;
IronChestType type = tile.getType();
if (tile != null && tile.hasWorldObj()) {
facing = tile.getFacing();
type = tile.getType();
int typ = tile.getWorldObj().getBlockMetadata(tile.xCoord, tile.yCoord, tile.zCoord);
type = IronChestType.values()[typ];
}
bindTexture(locations.get(type));
glPushMatrix();
glEnable(32826 /* GL_RESCALE_NORMAL_EXT */);
glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
glTranslatef((float) x, (float) y + 1.0F, (float) z + 1.0F);
glScalef(1.0F, -1F, -1F);
glTranslatef(0.5F, 0.5F, 0.5F);
int k = 0;
if (facing == 2) {
k = 180;
}
if (facing == 3) {
k = 0;
}
if (facing == 4) {
k = 90;
}
if (facing == 5) {
k = -90;
}
glRotatef(k, 0.0F, 1.0F, 0.0F);
glTranslatef(-0.5F, -0.5F, -0.5F);
float lidangle = tile.prevLidAngle + (tile.lidAngle - tile.prevLidAngle) * partialTick;
lidangle = 1.0F - lidangle;
lidangle = 1.0F - lidangle * lidangle * lidangle;
model.chestLid.rotateAngleX = -((lidangle * 3.141593F) / 2.0F);
// Render the chest itself
model.renderAll();
glDisable(32826 /* GL_RESCALE_NORMAL_EXT */);
glPopMatrix();
glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
if (type.isTransparent() && tile.getDistanceFrom(this.field_147501_a.field_147560_j, this.field_147501_a.field_147561_k, this.field_147501_a.field_147558_l) < 128d) {
random.setSeed(254L);
float shiftX;
float shiftY;
float shiftZ;
int shift = 0;
float blockScale = 0.70F;
float timeD = (float) (360.0 * (double) (System.currentTimeMillis() & 0x3FFFL) / (double) 0x3FFFL);
if (tile.getTopItemStacks()[1] == null) {
shift = 8;
blockScale = 0.85F;
}
glPushMatrix();
glDisable(2896 /* GL_LIGHTING */);
glTranslatef((float) x, (float) y, (float) z);
EntityItem customitem = new EntityItem(field_147501_a.field_147550_f);
customitem.hoverStart = 0f;
for (ItemStack item : tile.getTopItemStacks()) {
if (shift > shifts.length) {
break;
}
if (item == null) {
shift++;
continue;
}
shiftX = shifts[shift][0];
shiftY = shifts[shift][1];
shiftZ = shifts[shift][2];
shift++;
glPushMatrix();
glTranslatef(shiftX, shiftY, shiftZ);
glRotatef(timeD, 0.0F, 1.0F, 0.0F);
glScalef(blockScale, blockScale, blockScale);
customitem.setEntityItemStack(item);
itemRenderer.doRender(customitem, 0, 0, 0, 0, 0);
glPopMatrix();
}
glEnable(2896 /* GL_LIGHTING */);
glPopMatrix();
glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
}
}
@Override
public void renderTileEntityAt(TileEntity tileentity, double x, double y, double z, float partialTick)
{
render((TileEntityIronChest) tileentity, x, y, z, partialTick);
}
private ModelChest model;
}

View File

@ -1,3 +1,5 @@
itemGroup.IronChest=Iron Chests
tile.ironchest:IRON.name=Iron Chest
tile.ironchest:GOLD.name=Gold Chest
tile.ironchest:DIAMOND.name=Diamond Chest