commit e37de233401c0a5edeabb920d9148829cd3db94c Author: Azanor Date: Mon Mar 31 10:36:27 2014 +0200 Initial commit diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..412eeda --- /dev/null +++ b/.gitattributes @@ -0,0 +1,22 @@ +# Auto detect text files and perform LF normalization +* text=auto + +# Custom for Visual Studio +*.cs diff=csharp +*.sln merge=union +*.csproj merge=union +*.vbproj merge=union +*.fsproj merge=union +*.dbproj merge=union + +# Standard to msysgit +*.doc diff=astextplain +*.DOC diff=astextplain +*.docx diff=astextplain +*.DOCX diff=astextplain +*.dot diff=astextplain +*.DOT diff=astextplain +*.pdf diff=astextplain +*.PDF diff=astextplain +*.rtf diff=astextplain +*.RTF diff=astextplain diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7149cd6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,221 @@ +################# +## Custom +################# +build/ +eclipse/ + +################# +## Eclipse +################# + +*.pydevproject +.project +.metadata +bin/ +tmp/ +*.tmp +*.bak +*.swp +*~.nib +local.properties +.classpath +.settings/ +.loadpath + +# External tool builders +.externalToolBuilders/ + +# Locally stored "Eclipse launch configurations" +*.launch + +# CDT-specific +.cproject + +# PDT-specific +.buildpath + + +################# +## Visual Studio +################# + +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.sln.docstates + +# Build results + +[Dd]ebug/ +[Rr]elease/ +x64/ +build/ +[Bb]in/ +[Oo]bj/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +*_i.c +*_p.c +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.log +*.scc + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opensdf +*.sdf +*.cachefile + +# Visual Studio profiler +*.psess +*.vsp +*.vspx + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +*.ncrunch* +.*crunch*.local.xml + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.Publish.xml +*.pubxml + +# NuGet Packages Directory +## TODO: If you have NuGet Package Restore enabled, uncomment the next line +#packages/ + +# Windows Azure Build Output +csx +*.build.csdef + +# Windows Store app package directory +AppPackages/ + +# Others +sql/ +*.Cache +ClientBin/ +[Ss]tyle[Cc]op.* +~$* +*~ +*.dbmdl +*.[Pp]ublish.xml +*.pfx +*.publishsettings + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file to a newer +# Visual Studio version. Backup files are not needed, because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +App_Data/*.mdf +App_Data/*.ldf + +############# +## Windows detritus +############# + +# Windows image file caches +Thumbs.db +ehthumbs.db + +# Folder config file +Desktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Mac crap +.DS_Store + + +############# +## Python +############# + +*.py[co] + +# Packages +*.egg +*.egg-info +dist/ +build/ +eggs/ +parts/ +var/ +sdist/ +develop-eggs/ +.installed.cfg + +# Installer logs +pip-log.txt + +# Unit test / coverage reports +.coverage +.tox + +#Translations +*.mo + +#Mr Developer +.mr.developer.cfg diff --git a/.gradle/1.10/taskArtifacts/cache.properties b/.gradle/1.10/taskArtifacts/cache.properties new file mode 100644 index 0000000..824ce11 --- /dev/null +++ b/.gradle/1.10/taskArtifacts/cache.properties @@ -0,0 +1 @@ +#Mon Mar 31 07:47:27 CAT 2014 diff --git a/.gradle/1.10/taskArtifacts/cache.properties.lock b/.gradle/1.10/taskArtifacts/cache.properties.lock new file mode 100644 index 0000000..2994abb Binary files /dev/null and b/.gradle/1.10/taskArtifacts/cache.properties.lock differ diff --git a/.gradle/1.10/taskArtifacts/fileHashes.bin b/.gradle/1.10/taskArtifacts/fileHashes.bin new file mode 100644 index 0000000..fc14827 Binary files /dev/null and b/.gradle/1.10/taskArtifacts/fileHashes.bin differ diff --git a/.gradle/1.10/taskArtifacts/fileSnapshots.bin b/.gradle/1.10/taskArtifacts/fileSnapshots.bin new file mode 100644 index 0000000..a21bf55 Binary files /dev/null and b/.gradle/1.10/taskArtifacts/fileSnapshots.bin differ diff --git a/.gradle/1.10/taskArtifacts/outputFileStates.bin b/.gradle/1.10/taskArtifacts/outputFileStates.bin new file mode 100644 index 0000000..d8a0205 Binary files /dev/null and b/.gradle/1.10/taskArtifacts/outputFileStates.bin differ diff --git a/.gradle/1.10/taskArtifacts/taskArtifacts.bin b/.gradle/1.10/taskArtifacts/taskArtifacts.bin new file mode 100644 index 0000000..26e35c5 Binary files /dev/null and b/.gradle/1.10/taskArtifacts/taskArtifacts.bin differ diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..1182329 --- /dev/null +++ b/LICENSE @@ -0,0 +1,20 @@ +The MIT License (MIT) + +Copyright (c) 2013 Azanor + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..2a7c08f --- /dev/null +++ b/build.gradle @@ -0,0 +1,55 @@ +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 plugin: 'forge' + +version = "1.7.2-1.0.0.0" +group= "com.azanor.baubles" +archivesBaseName = "Baubles" + +minecraft { + version = "1.7.2-10.12.0.1046" + assetDir = "eclipse/assets" +} +processResources +{ + // 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' + } + + task deobfJar(type: Jar) { + from(sourceSets.main.output) { + classifier = 'deobf' + } + } + + artifacts { + archives deobfJar + } +} + + + diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..667288a Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..55f4524 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Tue Oct 29 18:00:54 CDT 2013 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=http\://services.gradle.org/distributions/gradle-1.10-bin.zip diff --git a/gradlew b/gradlew new file mode 100644 index 0000000..91a7e26 --- /dev/null +++ b/gradlew @@ -0,0 +1,164 @@ +#!/usr/bin/env bash + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn ( ) { + echo "$*" +} + +die ( ) { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; +esac + +# For Cygwin, ensure paths are in UNIX format before anything is touched. +if $cygwin ; then + [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` +fi + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >&- +APP_HOME="`pwd -P`" +cd "$SAVED" >&- + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules +function splitJvmOpts() { + JVM_OPTS=("$@") +} +eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS +JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" + +exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..8a0b282 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,90 @@ +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windowz variants + +if not "%OS%" == "Windows_NT" goto win9xME_args +if "%@eval[2+2]" == "4" goto 4NT_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* +goto execute + +:4NT_args +@rem Get arguments from the 4NT Shell from JP Software +set CMD_LINE_ARGS=%$ + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/rebuild.bat b/rebuild.bat new file mode 100644 index 0000000..a394027 --- /dev/null +++ b/rebuild.bat @@ -0,0 +1,2 @@ +gradlew setupDecompWorkspace +gradlew eclipse \ No newline at end of file diff --git a/src/main/java/baubles/api/BaubleType.java b/src/main/java/baubles/api/BaubleType.java new file mode 100644 index 0000000..22349ff --- /dev/null +++ b/src/main/java/baubles/api/BaubleType.java @@ -0,0 +1,7 @@ +package baubles.api; + +public enum BaubleType { + RING, + AMULET, + BELT +} diff --git a/src/main/java/baubles/api/BaublesApi.java b/src/main/java/baubles/api/BaublesApi.java new file mode 100644 index 0000000..92d620d --- /dev/null +++ b/src/main/java/baubles/api/BaublesApi.java @@ -0,0 +1,14 @@ +package baubles.api; + + + +/** + * @author Azanor + * + * + * + */ +public class BaublesApi { + + +} diff --git a/src/main/java/baubles/api/IBauble.java b/src/main/java/baubles/api/IBauble.java new file mode 100644 index 0000000..6c64adf --- /dev/null +++ b/src/main/java/baubles/api/IBauble.java @@ -0,0 +1,37 @@ +package baubles.api; + +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.item.ItemStack; + +/** + * + * @author Azanor + * + * This interface should be extended by items that can be worn in bauble slots + * + */ + +public interface IBauble { + + /** + * This method return the type of bauble this is. + * Type is used to determine the slots it can go into. + */ + public BaubleType getBaubleType(ItemStack itemstack); + + /** + * This method is called once per tick if the bauble is being worn by a player + */ + public void onWornTick(ItemStack itemstack, EntityLivingBase player); + + /** + * This method is called when the bauble is equipped by a player + */ + public void onEquipped(ItemStack itemstack, EntityLivingBase player); + + /** + * This method is called when the bauble is unequipped by a player + */ + public void onUnequipped(ItemStack itemstack, EntityLivingBase player); + +} diff --git a/src/main/java/baubles/client/ClientProxy.java b/src/main/java/baubles/client/ClientProxy.java new file mode 100644 index 0000000..98d4b8d --- /dev/null +++ b/src/main/java/baubles/client/ClientProxy.java @@ -0,0 +1,41 @@ + +package baubles.client; + +import net.minecraft.client.multiplayer.WorldClient; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.world.World; +import baubles.client.gui.GuiPlayerExpanded; +import baubles.common.Baubles; +import baubles.common.CommonProxy; +import baubles.common.event.KeyHandler; +import cpw.mods.fml.client.FMLClientHandler; +import cpw.mods.fml.common.FMLCommonHandler; + +public class ClientProxy extends CommonProxy { + + @Override + public void registerHandlers() {} + + @Override + public void registerKeyBindings() { + keyHandler = new KeyHandler(); + FMLCommonHandler.instance().bus().register(keyHandler); + } + + @Override + public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { + if (world instanceof WorldClient) { + switch (ID) { + case Baubles.GUI: return new GuiPlayerExpanded(player); + } + } + return null; + } + + @Override + public World getClientWorld() { + return FMLClientHandler.instance().getClient().theWorld; + } + + +} diff --git a/src/main/java/baubles/client/gui/GuiPlayerExpanded.java b/src/main/java/baubles/client/gui/GuiPlayerExpanded.java new file mode 100644 index 0000000..a503c28 --- /dev/null +++ b/src/main/java/baubles/client/gui/GuiPlayerExpanded.java @@ -0,0 +1,163 @@ +package baubles.client.gui; + +import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.gui.achievement.GuiAchievements; +import net.minecraft.client.gui.achievement.GuiStats; +import net.minecraft.client.gui.inventory.GuiContainerCreative; +import net.minecraft.client.renderer.InventoryEffectRenderer; +import net.minecraft.client.renderer.OpenGlHelper; +import net.minecraft.client.renderer.RenderHelper; +import net.minecraft.client.renderer.entity.RenderManager; +import net.minecraft.client.resources.I18n; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.ResourceLocation; + +import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL12; + +import baubles.common.Baubles; +import baubles.common.container.ContainerPlayerExpanded; + +public class GuiPlayerExpanded extends InventoryEffectRenderer { + + protected static final ResourceLocation background = + new ResourceLocation("baubles","textures/gui/expanded_inventory.png"); + + /** + * x size of the inventory window in pixels. Defined as float, passed as int + */ + private float xSizeFloat; + /** + * y size of the inventory window in pixels. Defined as float, passed as int. + */ + private float ySizeFloat; + + public GuiPlayerExpanded(EntityPlayer player) + { + super(new ContainerPlayerExpanded(player.inventory, !player.worldObj.isRemote, player)); + this.allowUserInput = true; + } + + /** + * Called from the main game loop to update the screen. + */ + @Override + public void updateScreen() + { + if (this.mc.playerController.isInCreativeMode()) + { + this.mc.displayGuiScreen(new GuiContainerCreative(this.mc.thePlayer)); + } + } + + /** + * Adds the buttons (and other controls) to the screen in question. + */ + @Override + public void initGui() + { + this.buttonList.clear(); + + if (this.mc.playerController.isInCreativeMode()) + { + this.mc.displayGuiScreen(new GuiContainerCreative(this.mc.thePlayer)); + } + else + { + super.initGui(); + } + } + + /** + * Draw the foreground layer for the GuiContainer (everything in front of the items) + */ + @Override + protected void drawGuiContainerForegroundLayer(int p_146979_1_, int p_146979_2_) + { + this.fontRendererObj.drawString(I18n.format("container.crafting", new Object[0]), 106, 16, 4210752); + } + + /** + * Draws the screen and all the components in it. + */ + @Override + public void drawScreen(int par1, int par2, float par3) + { + super.drawScreen(par1, par2, par3); + this.xSizeFloat = (float)par1; + this.ySizeFloat = (float)par2; + } + + @Override + protected void drawGuiContainerBackgroundLayer(float p_146976_1_, int p_146976_2_, int p_146976_3_) + { + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + this.mc.getTextureManager().bindTexture(background); + int k = this.guiLeft; + int l = this.guiTop; + this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize); + drawPlayerModel(k + 51, l + 75, 30, (float)(k + 51) - this.xSizeFloat, (float)(l + 75 - 50) - this.ySizeFloat, this.mc.thePlayer); + } + + public static void drawPlayerModel(int x, int y, int scale, float yaw, float pitch, EntityLivingBase playerdrawn) + { + GL11.glEnable(GL11.GL_COLOR_MATERIAL); + GL11.glPushMatrix(); + GL11.glTranslatef((float)x, (float)y, 50.0F); + GL11.glScalef((float)(-scale), (float)scale, (float)scale); + GL11.glRotatef(180.0F, 0.0F, 0.0F, 1.0F); + float f2 = playerdrawn.renderYawOffset; + float f3 = playerdrawn.rotationYaw; + float f4 = playerdrawn.rotationPitch; + float f5 = playerdrawn.prevRotationYawHead; + float f6 = playerdrawn.rotationYawHead; + GL11.glRotatef(135.0F, 0.0F, 1.0F, 0.0F); + RenderHelper.enableStandardItemLighting(); + GL11.glRotatef(-135.0F, 0.0F, 1.0F, 0.0F); + GL11.glRotatef(-((float)Math.atan((double)(pitch / 40.0F))) * 20.0F, 1.0F, 0.0F, 0.0F); + playerdrawn.renderYawOffset = (float)Math.atan((double)(yaw / 40.0F)) * 20.0F; + playerdrawn.rotationYaw = (float)Math.atan((double)(yaw / 40.0F)) * 40.0F; + playerdrawn.rotationPitch = -((float)Math.atan((double)(pitch / 40.0F))) * 20.0F; + playerdrawn.rotationYawHead = playerdrawn.rotationYaw; + playerdrawn.prevRotationYawHead = playerdrawn.rotationYaw; + GL11.glTranslatef(0.0F, playerdrawn.yOffset, 0.0F); + RenderManager.instance.playerViewY = 180.0F; + RenderManager.instance.renderEntityWithPosYaw(playerdrawn, 0.0D, 0.0D, 0.0D, 0.0F, 1.0F); + playerdrawn.renderYawOffset = f2; + playerdrawn.rotationYaw = f3; + playerdrawn.rotationPitch = f4; + playerdrawn.prevRotationYawHead = f5; + playerdrawn.rotationYawHead = f6; + GL11.glPopMatrix(); + RenderHelper.disableStandardItemLighting(); + GL11.glDisable(GL12.GL_RESCALE_NORMAL); + OpenGlHelper.setActiveTexture(OpenGlHelper.lightmapTexUnit); + GL11.glDisable(GL11.GL_TEXTURE_2D); + OpenGlHelper.setActiveTexture(OpenGlHelper.defaultTexUnit); + } + + @Override + protected void actionPerformed(GuiButton button) + { + if (button.id == 0) + { + this.mc.displayGuiScreen(new GuiAchievements(this, this.mc.thePlayer.getStatFileWriter())); + } + + if (button.id == 1) + { + this.mc.displayGuiScreen(new GuiStats(this, this.mc.thePlayer.getStatFileWriter())); + } + } + + @Override + protected void keyTyped(char par1, int par2) { + if (par2 == Baubles.proxy.keyHandler.key.getKeyCode()) + { + this.mc.thePlayer.closeScreen(); + } + super.keyTyped(par1, par2); + } + +} diff --git a/src/main/java/baubles/common/Baubles.java b/src/main/java/baubles/common/Baubles.java new file mode 100644 index 0000000..bc27891 --- /dev/null +++ b/src/main/java/baubles/common/Baubles.java @@ -0,0 +1,89 @@ +package baubles.common; + +import java.io.File; + +import net.minecraft.creativetab.CreativeTabs; +import net.minecraftforge.common.MinecraftForge; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import baubles.common.event.EventHandlerEntity; +import baubles.common.lib.CreativeTabBaubles; +import baubles.common.lib.PlayerHandler; +import baubles.common.network.EventHandlerNetwork; +import baubles.common.network.PacketPipeline; +import cpw.mods.fml.common.FMLCommonHandler; +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; + +@Mod(modid = Baubles.MODID, name = Baubles.MODNAME, version = Baubles.VERSION, dependencies="required-after:Forge@[10.12.0.1034,);") + +public class Baubles { + + public static final String MODID = "Baubles"; + public static final String MODNAME = "Baubles"; + public static final String VERSION = "1.0.0.0"; + + @SidedProxy(clientSide = "baubles.client.ClientProxy", serverSide = "baubles.common.CommonProxy") + public static CommonProxy proxy; + + @Instance(value=Baubles.MODID) + public static Baubles instance; + + + public EventHandlerNetwork networkEventHandler; + public EventHandlerEntity entityEventHandler; + public PlayerHandler playerHandler; + public File modDir; + + public static final PacketPipeline packetPipeline = new PacketPipeline(); + public static final Logger logger = LogManager.getLogger("Baubles"); + public static final int GUI = 0; + public static CreativeTabs tabBaubles = new CreativeTabBaubles(CreativeTabs.getNextID(), "baubles"); + + @EventHandler + public void preInit(FMLPreInitializationEvent event) { + event.getModMetadata().version = Baubles.VERSION; + modDir = event.getModConfigurationDirectory(); + + try { + Config.initialize(event.getSuggestedConfigurationFile()); + } catch (Exception e) { + Baubles.logger.error("BAUBLES has a problem loading it's configuration"); + } finally { + if (Config.config!=null) Config.save(); + } + + entityEventHandler = new EventHandlerEntity(); + playerHandler = new PlayerHandler(); + + MinecraftForge.EVENT_BUS.register(entityEventHandler); + FMLCommonHandler.instance().bus().register(new EventHandlerNetwork()); + proxy.registerHandlers(); + + ///////////////////// + + Config.save(); + } + + @EventHandler + public void init(FMLInitializationEvent evt) { + packetPipeline.initialise(); + NetworkRegistry.INSTANCE.registerGuiHandler(instance, proxy); + proxy.registerKeyBindings(); + } + + @EventHandler + public void postInit(FMLPostInitializationEvent evt) { + Config.initRecipe(); + packetPipeline.postInitialise(); + } + +} diff --git a/src/main/java/baubles/common/CommonProxy.java b/src/main/java/baubles/common/CommonProxy.java new file mode 100644 index 0000000..9349295 --- /dev/null +++ b/src/main/java/baubles/common/CommonProxy.java @@ -0,0 +1,39 @@ + +package baubles.common; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.world.World; +import baubles.common.container.ContainerPlayerExpanded; +import baubles.common.event.KeyHandler; +import cpw.mods.fml.common.network.IGuiHandler; + + + +public class CommonProxy implements IGuiHandler { + + public KeyHandler keyHandler; + + public void registerHandlers() {} + + + @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) { + switch (ID) { + case Baubles.GUI: return new ContainerPlayerExpanded(player.inventory, !world.isRemote, player); + } + return null; + } + + public World getClientWorld() { + return null; + } + + + public void registerKeyBindings() {} + +} diff --git a/src/main/java/baubles/common/Config.java b/src/main/java/baubles/common/Config.java new file mode 100644 index 0000000..a2cb226 --- /dev/null +++ b/src/main/java/baubles/common/Config.java @@ -0,0 +1,47 @@ +package baubles.common; + +import java.io.File; + +import net.minecraft.init.Items; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraftforge.common.config.Configuration; +import baubles.common.items.ItemRing; +import cpw.mods.fml.common.registry.GameRegistry; + + +public class Config { + + public static Configuration config; + public static Item itemRing; + + public static void initialize(File file) + { + config = new Configuration(file); + config.load(); + + itemRing =(new ItemRing()).setUnlocalizedName("Ring"); + GameRegistry.registerItem(itemRing, "Ring", Baubles.MODID); + + //save it + config.save(); + } + + + public static void save() + { + config.save(); + } + + public static void initRecipe() { + GameRegistry.addShapedRecipe( + new ItemStack(itemRing), new Object[] { + "PIP", "IPI", "PIP", + Character.valueOf('I'), new ItemStack(Items.iron_ingot), + Character.valueOf('P'), new ItemStack(Items.potionitem,1,8226)}); + } + + + + +} diff --git a/src/main/java/baubles/common/container/ContainerPlayerExpanded.java b/src/main/java/baubles/common/container/ContainerPlayerExpanded.java new file mode 100644 index 0000000..ecec711 --- /dev/null +++ b/src/main/java/baubles/common/container/ContainerPlayerExpanded.java @@ -0,0 +1,263 @@ +package baubles.common.container; + +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.InventoryCraftResult; +import net.minecraft.inventory.InventoryCrafting; +import net.minecraft.inventory.Slot; +import net.minecraft.inventory.SlotCrafting; +import net.minecraft.item.ItemArmor; +import net.minecraft.item.ItemStack; +import net.minecraft.item.crafting.CraftingManager; +import baubles.api.BaubleType; +import baubles.api.IBauble; +import baubles.common.Baubles; + +public class ContainerPlayerExpanded extends Container +{ + /** + * The crafting matrix inventory. + */ + public InventoryCrafting craftMatrix = new InventoryCrafting(this, 2, 2); + public IInventory craftResult = new InventoryCraftResult(); + public InventoryBaubles baubles; + /** + * Determines if inventory manipulation should be handled. + */ + public boolean isLocalWorld; + private final EntityPlayer thePlayer; + + public ContainerPlayerExpanded(InventoryPlayer playerInv, boolean par2, EntityPlayer player) + { + this.isLocalWorld = par2; + this.thePlayer = player; + baubles = new InventoryBaubles(player); + baubles.setEventHandler(this); + if (!player.worldObj.isRemote) { + baubles.stackList = Baubles.instance.playerHandler.getPlayerBaubles(player).stackList; + } + + this.addSlotToContainer(new SlotCrafting(playerInv.player, this.craftMatrix, this.craftResult, 0, 144, 36)); + int i; + int j; + + for (i = 0; i < 2; ++i) + { + for (j = 0; j < 2; ++j) + { + this.addSlotToContainer(new Slot(this.craftMatrix, j + i * 2, 106 + j * 18, 26 + i * 18)); + } + } + + for (i = 0; i < 4; ++i) + { + final int k = i; + this.addSlotToContainer(new Slot(playerInv, playerInv.getSizeInventory() - 1 - i, 8, 8 + i * 18) + { + @Override + public int getSlotStackLimit() { return 1; } + @Override + public boolean isItemValid(ItemStack par1ItemStack) + { + if (par1ItemStack == null) return false; + return par1ItemStack.getItem().isValidArmor(par1ItemStack, k, thePlayer); + } + }); + } + + this.addSlotToContainer(new SlotBauble(baubles,BaubleType.AMULET,0,80,8 + 0 * 18)); + this.addSlotToContainer(new SlotBauble(baubles,BaubleType.RING,1,80,8 + 1 * 18)); + this.addSlotToContainer(new SlotBauble(baubles,BaubleType.RING,2,80,8 + 2 * 18)); + this.addSlotToContainer(new SlotBauble(baubles,BaubleType.BELT,3,80,8 + 3 * 18)); + + for (i = 0; i < 3; ++i) + { + for (j = 0; j < 9; ++j) + { + this.addSlotToContainer(new Slot(playerInv, j + (i + 1) * 9, 8 + j * 18, 84 + i * 18)); + } + } + + for (i = 0; i < 9; ++i) + { + this.addSlotToContainer(new Slot(playerInv, i, 8 + i * 18, 142)); + } + + this.onCraftMatrixChanged(this.craftMatrix); + } + + /** + * Callback for when the crafting matrix is changed. + */ + @Override + public void onCraftMatrixChanged(IInventory par1IInventory) + { + this.craftResult.setInventorySlotContents(0, CraftingManager.getInstance().findMatchingRecipe(this.craftMatrix, this.thePlayer.worldObj)); + } + + /** + * Called when the container is closed. + */ + @Override + public void onContainerClosed(EntityPlayer player) + { + super.onContainerClosed(player); + + for (int i = 0; i < 4; ++i) + { + ItemStack itemstack = this.craftMatrix.getStackInSlotOnClosing(i); + + if (itemstack != null) + { + player.dropPlayerItemWithRandomChoice(itemstack, false); + } + } + + this.craftResult.setInventorySlotContents(0, (ItemStack)null); + if (!player.worldObj.isRemote) { + Baubles.instance.playerHandler.setPlayerBaubles(player, baubles); + Baubles.instance.playerHandler.updatePlayerBaubles(player); + } + } + + @Override + public boolean canInteractWith(EntityPlayer par1EntityPlayer) + { + return true; + } + + /** + * Called when a player shift-clicks on a slot. You must override this or you will crash when someone does that. + */ + @Override + public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par2) + { + ItemStack itemstack = null; + Slot slot = (Slot)this.inventorySlots.get(par2); + + if (slot != null && slot.getHasStack()) + { + ItemStack itemstack1 = slot.getStack(); + itemstack = itemstack1.copy(); + + if (par2 == 0) + { + if (!this.mergeItemStack(itemstack1, 9+4, 45+4, true)) + { + return null; + } + + slot.onSlotChange(itemstack1, itemstack); + } + else if (par2 >= 1 && par2 < 5) + { + if (!this.mergeItemStack(itemstack1, 9+4, 45+4, false)) + { + return null; + } + } + else if (par2 >= 5 && par2 < 9) + { + if (!this.mergeItemStack(itemstack1, 9+4, 45+4, false)) + { + return null; + } + } + else if (itemstack.getItem() instanceof ItemArmor && + !((Slot)this.inventorySlots.get(5 + ((ItemArmor)itemstack.getItem()).armorType)).getHasStack()) + { + int j = 5 + ((ItemArmor)itemstack.getItem()).armorType; + + if (!this.mergeItemStack(itemstack1, j, j + 1, false)) + { + return null; + } + } + else if (itemstack.getItem() instanceof IBauble && + ((IBauble)itemstack.getItem()).getBaubleType(itemstack)==BaubleType.AMULET && + !((Slot)this.inventorySlots.get(9)).getHasStack()) + { + int j = 9; + if (!this.mergeItemStack(itemstack1, j, j + 1, false)) + { + return null; + } + } + else if (itemstack.getItem() instanceof IBauble && + ((IBauble)itemstack.getItem()).getBaubleType(itemstack)==BaubleType.RING && + !((Slot)this.inventorySlots.get(10)).getHasStack()) + { + int j = 10; + if (!this.mergeItemStack(itemstack1, j, j + 1, false)) + { + return null; + } + } + else if (itemstack.getItem() instanceof IBauble && + ((IBauble)itemstack.getItem()).getBaubleType(itemstack)==BaubleType.RING && + !((Slot)this.inventorySlots.get(11)).getHasStack()) + { + int j = 11; + if (!this.mergeItemStack(itemstack1, j, j + 1, false)) + { + return null; + } + } + else if (itemstack.getItem() instanceof IBauble && + ((IBauble)itemstack.getItem()).getBaubleType(itemstack)==BaubleType.BELT && + !((Slot)this.inventorySlots.get(12)).getHasStack()) + { + int j = 12; + if (!this.mergeItemStack(itemstack1, j, j + 1, false)) + { + return null; + } + } + else if (par2 >= 9+4 && par2 < 36+4) + { + if (!this.mergeItemStack(itemstack1, 36+4, 45+4, false)) + { + return null; + } + } + else if (par2 >= 36+4 && par2 < 45+4) + { + if (!this.mergeItemStack(itemstack1, 9+4, 36+4, false)) + { + return null; + } + } + else if (!this.mergeItemStack(itemstack1, 9+4, 45+4, false)) + { + return null; + } + + if (itemstack1.stackSize == 0) + { + slot.putStack((ItemStack)null); + } + else + { + slot.onSlotChanged(); + } + + if (itemstack1.stackSize == itemstack.stackSize) + { + return null; + } + + slot.onPickupFromSlot(par1EntityPlayer, itemstack1); + } + + return itemstack; + } + + @Override + public boolean func_94530_a(ItemStack par1ItemStack, Slot par2Slot) + { + return par2Slot.inventory != this.craftResult && super.func_94530_a(par1ItemStack, par2Slot); + } + +} diff --git a/src/main/java/baubles/common/container/InventoryBaubles.java b/src/main/java/baubles/common/container/InventoryBaubles.java new file mode 100644 index 0000000..22c65c8 --- /dev/null +++ b/src/main/java/baubles/common/container/InventoryBaubles.java @@ -0,0 +1,220 @@ +package baubles.common.container; + +import java.lang.ref.WeakReference; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.Container; +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import baubles.api.BaubleType; +import baubles.api.IBauble; + +public class InventoryBaubles implements IInventory { + public ItemStack[] stackList; + private Container eventHandler; + public WeakReference player; + + public InventoryBaubles(EntityPlayer player) { + this.stackList = new ItemStack[4]; + this.player = new WeakReference(player); + } + + public Container getEventHandler() { + return eventHandler; + } + + public void setEventHandler(Container eventHandler) { + this.eventHandler = eventHandler; + } + + /** + * Returns the number of slots in the inventory. + */ + @Override + public int getSizeInventory() { + return this.stackList.length; + } + + /** + * Returns the stack in slot i + */ + @Override + public ItemStack getStackInSlot(int par1) { + return par1 >= this.getSizeInventory() ? null : this.stackList[par1]; + } + + /** + * Returns the name of the inventory + */ + @Override + public String getInventoryName() { + return ""; + } + + /** + * Returns if the inventory is named + */ + @Override + public boolean hasCustomInventoryName() { + return false; + } + + /** + * When some containers are closed they call this on each slot, then drop + * whatever it returns as an EntityItem - like when you close a workbench + * GUI. + */ + @Override + public ItemStack getStackInSlotOnClosing(int par1) { + if (this.stackList[par1] != null) { + ItemStack itemstack = this.stackList[par1]; + this.stackList[par1] = null; + return itemstack; + } else { + return null; + } + } + + /** + * Removes from an inventory slot (first arg) up to a specified number + * (second arg) of items and returns them in a new stack. + */ + @Override + public ItemStack decrStackSize(int par1, int par2) { + if (this.stackList[par1] != null) { + ItemStack itemstack; + + if (this.stackList[par1].stackSize <= par2) { + itemstack = this.stackList[par1]; + this.stackList[par1] = null; + + if (itemstack !=null && itemstack.getItem() instanceof IBauble) { + ((IBauble)itemstack.getItem()).onUnequipped(itemstack, player.get()); + } + + if (eventHandler!=null) this.eventHandler.onCraftMatrixChanged(this); + return itemstack; + } else { + itemstack = this.stackList[par1].splitStack(par2); + + if (this.stackList[par1].stackSize == 0) { + this.stackList[par1] = null; + } + + if (itemstack !=null && itemstack.getItem() instanceof IBauble) { + ((IBauble)itemstack.getItem()).onUnequipped(itemstack, player.get()); + } + if (eventHandler!=null) this.eventHandler.onCraftMatrixChanged(this); + return itemstack; + } + } else { + return null; + } + } + + /** + * Sets the given item stack to the specified slot in the inventory (can be + * crafting or armor sections). + */ + @Override + public void setInventorySlotContents(int par1, ItemStack stack) { + this.stackList[par1] = stack; + if (stack !=null && stack.getItem() instanceof IBauble) { + ((IBauble)stack.getItem()).onEquipped(stack, player.get()); + } + if (eventHandler!=null) this.eventHandler.onCraftMatrixChanged(this); + } + + /** + * Returns the maximum stack size for a inventory slot. + */ + @Override + public int getInventoryStackLimit() { + return 1; + } + + /** + * For tile entities, ensures the chunk containing the tile entity is saved + * to disk later - the game won't think it hasn't changed and skip it. + */ + @Override + public void markDirty() { } + + /** + * Do not make give this method the name canInteractWith because it clashes + * with Container + */ + @Override + public boolean isUseableByPlayer(EntityPlayer par1EntityPlayer) { + return true; + } + + @Override + public void openInventory() { + + } + + @Override + public void closeInventory() { + + } + + /** + * Returns true if automation is allowed to insert the given stack (ignoring + * stack size) into the given slot. + */ + @Override + public boolean isItemValidForSlot(int i, ItemStack stack) { + if (stack == null || !(stack.getItem() instanceof IBauble)) + return false; + if (i == 0 + && ((IBauble) stack.getItem()).getBaubleType(stack) == BaubleType.AMULET) + return true; + if ((i == 1 || i == 2) + && ((IBauble) stack.getItem()).getBaubleType(stack) == BaubleType.RING) + return true; + if (i == 3 + && ((IBauble) stack.getItem()).getBaubleType(stack) == BaubleType.BELT) + return true; + return false; + } + + public void saveNBT(EntityPlayer player) { + NBTTagCompound tags = player.getEntityData(); + NBTTagList tagList = new NBTTagList(); + NBTTagCompound invSlot; + for (int i = 0; i < this.stackList.length; ++i) { + if (this.stackList[i] != null) { + invSlot = new NBTTagCompound(); + invSlot.setByte("Slot", (byte) i); + this.stackList[i].writeToNBT(invSlot); + tagList.appendTag(invSlot); + } + } + tags.setTag("Baubles.Inventory", tagList); + } + + public void readNBT(EntityPlayer player) { + NBTTagCompound tags = player.getEntityData(); + NBTTagList tagList = tags.getTagList("Baubles.Inventory", 10); + for (int i = 0; i < tagList.tagCount(); ++i) { + NBTTagCompound nbttagcompound = (NBTTagCompound) tagList.getCompoundTagAt(i); + int j = nbttagcompound.getByte("Slot") & 255; + ItemStack itemstack = ItemStack.loadItemStackFromNBT(nbttagcompound); + if (itemstack != null) { + this.stackList[j] = itemstack; + } + } + } + + public void dropItems(EntityPlayer player) { + for (int i = 0; i < 4; ++i) { + if (this.stackList[i] != null) { + player.dropPlayerItemWithRandomChoice(this.stackList[i], true); + this.stackList[i] = null; + } + } + } +} \ No newline at end of file diff --git a/src/main/java/baubles/common/container/SlotBauble.java b/src/main/java/baubles/common/container/SlotBauble.java new file mode 100644 index 0000000..fcf47ba --- /dev/null +++ b/src/main/java/baubles/common/container/SlotBauble.java @@ -0,0 +1,38 @@ +package baubles.common.container; + +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; +import baubles.api.BaubleType; +import baubles.api.IBauble; + +public class SlotBauble extends Slot +{ + + BaubleType type; + + public SlotBauble(IInventory par2IInventory, BaubleType type, int par3, int par4, int par5) + { + super(par2IInventory, par3, par4, par5); + this.type = type; + } + + + /** + * Check if the stack is a valid item for this slot. Always true beside for the armor slots. + */ + @Override + public boolean isItemValid(ItemStack stack) + { + return stack!=null && stack.getItem() !=null && + stack.getItem() instanceof IBauble && + ((IBauble)stack.getItem()).getBaubleType(stack)==this.type; + } + + @Override + public int getSlotStackLimit() + { + return 1; + } + +} diff --git a/src/main/java/baubles/common/event/EventHandlerEntity.java b/src/main/java/baubles/common/event/EventHandlerEntity.java new file mode 100644 index 0000000..747e153 --- /dev/null +++ b/src/main/java/baubles/common/event/EventHandlerEntity.java @@ -0,0 +1,40 @@ +package baubles.common.event; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraftforge.event.entity.living.LivingDeathEvent; +import net.minecraftforge.event.entity.player.PlayerEvent; +import baubles.api.IBauble; +import baubles.common.Baubles; +import baubles.common.container.InventoryBaubles; +import cpw.mods.fml.common.eventhandler.SubscribeEvent; + +public class EventHandlerEntity { + + @SubscribeEvent + public void playerTick(PlayerEvent.LivingUpdateEvent event) { + + //player events + if (event.entity instanceof EntityPlayer) { + EntityPlayer player = (EntityPlayer)event.entity; + + InventoryBaubles baubles = Baubles.instance.playerHandler.getPlayerBaubles(player); + for (int a=0;a playerBaubles = new HashMap(); + + public InventoryBaubles getPlayerBaubles(EntityPlayer player) { + if (!playerBaubles.containsKey(player.getCommandSenderName())) { + InventoryBaubles inventory = new InventoryBaubles(player); + playerBaubles.put(player.getCommandSenderName(), inventory); + } + return playerBaubles.get(player.getCommandSenderName()); + } + + public void setPlayerBaubles(EntityPlayer player, InventoryBaubles inventory) { + playerBaubles.put(player.getCommandSenderName(), inventory); + } + + public void updatePlayerBaubles(EntityPlayer player) { + InventoryBaubles inventory = getPlayerBaubles(player); + inventory.saveNBT(player); + } + + public void loadPlayerBaubles(EntityPlayer player) { + NBTTagCompound data = player.getEntityData(); + if (!data.hasKey("Baubles")) { + data.setTag("Baubles", new NBTTagCompound()); + } + InventoryBaubles inventory = new InventoryBaubles(player); + inventory.readNBT(player); + playerBaubles.put(player.getCommandSenderName(), inventory); + updatePlayerBaubles(player); + } +} diff --git a/src/main/java/baubles/common/network/AbstractPacket.java b/src/main/java/baubles/common/network/AbstractPacket.java new file mode 100644 index 0000000..385ee27 --- /dev/null +++ b/src/main/java/baubles/common/network/AbstractPacket.java @@ -0,0 +1,43 @@ +package baubles.common.network; + +import io.netty.buffer.ByteBuf; +import io.netty.channel.ChannelHandlerContext; +import net.minecraft.entity.player.EntityPlayer; + + +/** + * AbstractPacket class. Should be the parent of all packets wishing to use the PacketPipeline. + * @author sirgingalot + */ +public abstract class AbstractPacket { + + /** + * Encode the packet data into the ByteBuf stream. Complex data sets may need specific data handlers (See @link{cpw.mods.fml.common.network.ByteBuffUtils}) + * + * @param ctx channel context + * @param buffer the buffer to encode into + */ + public abstract void encodeInto(ChannelHandlerContext ctx, ByteBuf buffer); + + /** + * Decode the packet data from the ByteBuf stream. Complex data sets may need specific data handlers (See @link{cpw.mods.fml.common.network.ByteBuffUtils}) + * + * @param ctx channel context + * @param buffer the buffer to decode from + */ + public abstract void decodeInto(ChannelHandlerContext ctx, ByteBuf buffer); + + /** + * Handle a packet on the client side. Note this occurs after decoding has completed. + * + * @param player the player reference + */ + public abstract void handleClientSide(EntityPlayer player); + + /** + * Handle a packet on the server side. Note this occurs after decoding has completed. + * + * @param player the player reference + */ + public abstract void handleServerSide(EntityPlayer player); +} diff --git a/src/main/java/baubles/common/network/EventHandlerNetwork.java b/src/main/java/baubles/common/network/EventHandlerNetwork.java new file mode 100644 index 0000000..2192412 --- /dev/null +++ b/src/main/java/baubles/common/network/EventHandlerNetwork.java @@ -0,0 +1,31 @@ +package baubles.common.network; + +import java.util.HashMap; + +import baubles.common.Baubles; +import cpw.mods.fml.common.FMLCommonHandler; +import cpw.mods.fml.common.eventhandler.SubscribeEvent; +import cpw.mods.fml.common.gameevent.PlayerEvent; +import cpw.mods.fml.relauncher.Side; + +public class EventHandlerNetwork { + + @SubscribeEvent + public void playerLoggedInEvent (PlayerEvent.PlayerLoggedInEvent event) { + Side side = FMLCommonHandler.instance().getEffectiveSide(); + if (side == Side.SERVER) { + Baubles.instance.playerHandler.loadPlayerBaubles(event.player); + } + } + + HashMap lastPlayerUpdate = new HashMap(); + + @SubscribeEvent + public void playerUpdateEvent (PlayerEvent event) { + Side side = FMLCommonHandler.instance().getEffectiveSide(); + if (side == Side.SERVER) { + Baubles.instance.playerHandler.updatePlayerBaubles(event.player); + } + } + +} diff --git a/src/main/java/baubles/common/network/PacketOpenBaublesInventory.java b/src/main/java/baubles/common/network/PacketOpenBaublesInventory.java new file mode 100644 index 0000000..f164534 --- /dev/null +++ b/src/main/java/baubles/common/network/PacketOpenBaublesInventory.java @@ -0,0 +1,29 @@ +package baubles.common.network; + +import io.netty.buffer.ByteBuf; +import io.netty.channel.ChannelHandlerContext; +import net.minecraft.entity.player.EntityPlayer; +import baubles.common.Baubles; + +public class PacketOpenBaublesInventory extends AbstractPacket { + + public PacketOpenBaublesInventory() {} + + public PacketOpenBaublesInventory(EntityPlayer player) {} + + @Override + public void encodeInto(ChannelHandlerContext ctx, ByteBuf buffer) {} + + @Override + public void decodeInto(ChannelHandlerContext ctx, ByteBuf buffer) {} + + @Override + public void handleClientSide(EntityPlayer player) {} + + @Override + public void handleServerSide(EntityPlayer player) { + player.openGui(Baubles.instance, Baubles.GUI, player.worldObj, (int)player.posX, (int)player.posY, (int)player.posZ); + } + + +} diff --git a/src/main/java/baubles/common/network/PacketPipeline.java b/src/main/java/baubles/common/network/PacketPipeline.java new file mode 100644 index 0000000..975fccc --- /dev/null +++ b/src/main/java/baubles/common/network/PacketPipeline.java @@ -0,0 +1,216 @@ +package baubles.common.network; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; +import io.netty.channel.ChannelHandler; +import io.netty.channel.ChannelHandlerContext; +import io.netty.handler.codec.MessageToMessageCodec; + +import java.util.Collections; +import java.util.Comparator; +import java.util.EnumMap; +import java.util.LinkedList; +import java.util.List; + +import net.minecraft.client.Minecraft; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.network.INetHandler; +import net.minecraft.network.NetHandlerPlayServer; +import cpw.mods.fml.common.FMLCommonHandler; +import cpw.mods.fml.common.network.FMLEmbeddedChannel; +import cpw.mods.fml.common.network.FMLOutboundHandler; +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; + +/** + * Packet pipeline class. Directs all registered packet data to be handled by the packets themselves. + * @author sirgingalot + * some code from: cpw + */ +@ChannelHandler.Sharable +public class PacketPipeline extends MessageToMessageCodec { + + private EnumMap channels; + private LinkedList> packets = new LinkedList>(); + private boolean isPostInitialised = false; + + /** + * Register your packet with the pipeline. Discriminators are automatically set. + * + * @param clazz the class to register + * + * @return whether registration was successful. Failure may occur if 256 packets have been registered or if the registry already contains this packet + */ + public boolean registerPacket(Class clazz) { + if (this.packets.size() > 256) { + // You should log here!! + return false; + } + + if (this.packets.contains(clazz)) { + // You should log here!! + return false; + } + + if (this.isPostInitialised) { + // You should log here!! + return false; + } + + this.packets.add(clazz); + return true; + } + + // In line encoding of the packet, including discriminator setting + @Override + protected void encode(ChannelHandlerContext ctx, AbstractPacket msg, List out) throws Exception { + ByteBuf buffer = Unpooled.buffer(); + Class clazz = msg.getClass(); + if (!this.packets.contains(msg.getClass())) { + throw new NullPointerException("No Packet Registered for: " + msg.getClass().getCanonicalName()); + } + + byte discriminator = (byte) this.packets.indexOf(clazz); + buffer.writeByte(discriminator); + msg.encodeInto(ctx, buffer); + FMLProxyPacket proxyPacket = new FMLProxyPacket(buffer.copy(), ctx.channel().attr(NetworkRegistry.FML_CHANNEL).get()); + out.add(proxyPacket); + } + + // In line decoding and handling of the packet + @Override + protected void decode(ChannelHandlerContext ctx, FMLProxyPacket msg, List out) throws Exception { + ByteBuf payload = msg.payload(); + byte discriminator = payload.readByte(); + Class clazz = this.packets.get(discriminator); + if (clazz == null) { + throw new NullPointerException("No packet registered for discriminator: " + discriminator); + } + + AbstractPacket pkt = clazz.newInstance(); + pkt.decodeInto(ctx, payload.slice()); + + EntityPlayer player; + switch (FMLCommonHandler.instance().getEffectiveSide()) { + case CLIENT: + player = this.getClientPlayer(); + pkt.handleClientSide(player); + break; + + case SERVER: + INetHandler netHandler = ctx.channel().attr(NetworkRegistry.NET_HANDLER).get(); + player = ((NetHandlerPlayServer) netHandler).playerEntity; + pkt.handleServerSide(player); + break; + + default: + } + + out.add(pkt); + } + + // Method to call from FMLInitializationEvent + public void initialise() { + this.channels = NetworkRegistry.INSTANCE.newChannel("BAUBLE", this); + + //packets + registerPacket(PacketOpenBaublesInventory.class); + + } + + // Method to call from FMLPostInitializationEvent + // Ensures that packet discriminators are common between server and client by using logical sorting + public void postInitialise() { + if (this.isPostInitialised) { + return; + } + + this.isPostInitialised = true; + Collections.sort(this.packets, new Comparator>() { + + @Override + public int compare(Class clazz1, Class clazz2) { + int com = String.CASE_INSENSITIVE_ORDER.compare(clazz1.getCanonicalName(), clazz2.getCanonicalName()); + if (com == 0) { + com = clazz1.getCanonicalName().compareTo(clazz2.getCanonicalName()); + } + + return com; + } + }); + } + + @SideOnly(Side.CLIENT) + private EntityPlayer getClientPlayer() { + return Minecraft.getMinecraft().thePlayer; + } + + /** + * Send this message to everyone. + *

+ * Adapted from CPW's code in cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper + * + * @param message The message to send + */ + public void sendToAll(AbstractPacket message) { + this.channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.ALL); + this.channels.get(Side.SERVER).writeAndFlush(message); + } + + /** + * Send this message to the specified player. + *

+ * Adapted from CPW's code in cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper + * + * @param message The message to send + * @param player The player to send it to + */ + public void sendTo(AbstractPacket message, EntityPlayerMP player) { + this.channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.PLAYER); + this.channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(player); + this.channels.get(Side.SERVER).writeAndFlush(message); + } + + /** + * Send this message to everyone within a certain range of a point. + *

+ * Adapted from CPW's code in cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper + * + * @param message The message to send + * @param point The {@link cpw.mods.fml.common.network.NetworkRegistry.TargetPoint} around which to send + */ + public void sendToAllAround(AbstractPacket message, NetworkRegistry.TargetPoint point) { + this.channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.ALLAROUNDPOINT); + this.channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(point); + this.channels.get(Side.SERVER).writeAndFlush(message); + } + + /** + * Send this message to everyone within the supplied dimension. + *

+ * Adapted from CPW's code in cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper + * + * @param message The message to send + * @param dimensionId The dimension id to target + */ + public void sendToDimension(AbstractPacket message, int dimensionId) { + this.channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.DIMENSION); + this.channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(dimensionId); + this.channels.get(Side.SERVER).writeAndFlush(message); + } + + /** + * Send this message to the server. + *

+ * Adapted from CPW's code in cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper + * + * @param message The message to send + */ + public void sendToServer(AbstractPacket message) { + this.channels.get(Side.CLIENT).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.TOSERVER); + this.channels.get(Side.CLIENT).writeAndFlush(message); + } +} diff --git a/src/main/resources/assets/baubles/lang/en_US.lang b/src/main/resources/assets/baubles/lang/en_US.lang new file mode 100644 index 0000000..4769f8a --- /dev/null +++ b/src/main/resources/assets/baubles/lang/en_US.lang @@ -0,0 +1,8 @@ +# +# ITEMS +item.Ring.0.name=Miner's Ring +# +# GUI +# +# OTHER +itemGroup.baubles=Baubles diff --git a/src/main/resources/assets/baubles/textures/gui/expanded_inventory.png b/src/main/resources/assets/baubles/textures/gui/expanded_inventory.png new file mode 100644 index 0000000..8d1d29b Binary files /dev/null and b/src/main/resources/assets/baubles/textures/gui/expanded_inventory.png differ diff --git a/src/main/resources/assets/baubles/textures/items/ring.png b/src/main/resources/assets/baubles/textures/items/ring.png new file mode 100644 index 0000000..57e85d7 Binary files /dev/null and b/src/main/resources/assets/baubles/textures/items/ring.png differ diff --git a/src/main/resources/changelog.txt b/src/main/resources/changelog.txt new file mode 100644 index 0000000..0055422 --- /dev/null +++ b/src/main/resources/changelog.txt @@ -0,0 +1,2 @@ +1.0.0.0 +- \ No newline at end of file diff --git a/src/main/resources/mcmod.info b/src/main/resources/mcmod.info new file mode 100644 index 0000000..14faeae --- /dev/null +++ b/src/main/resources/mcmod.info @@ -0,0 +1,17 @@ +[ +{ + "modid": "Baubles", + "name": "Baubles", + "description": "Adding a touch of bling to Minecraft", + "version": "${version}", + "mcversion": "${mcversion}", + "logoFile": "BLogo.png", + "url": "http://www.minecraftforum.net/topic/838839-100-thaumcraft/", + "updateUrl": "", + "authors": ["Azanor"], + "credits": "", + "parent": "", + "screenshots": [], + "dependencies": [] +} +] \ No newline at end of file diff --git a/src/main/resources/pack.mcmeta b/src/main/resources/pack.mcmeta new file mode 100644 index 0000000..c1c2b30 --- /dev/null +++ b/src/main/resources/pack.mcmeta @@ -0,0 +1,6 @@ +{ + "pack": { + "pack_format": 1, + "description": "Resources used for Baubles + } +} \ No newline at end of file