Skip to content

Commit

Permalink
fix crash on server involving gui elements
Browse files Browse the repository at this point in the history
replaced deploy sh script with gradle impl / travis tweaks
update gradle wrapper to 2.0
fix link in readme
  • Loading branch information
LepkoQQ committed Jul 18, 2014
1 parent c3e1ab1 commit 0e2108c
Show file tree
Hide file tree
Showing 14 changed files with 150 additions and 97 deletions.
19 changes: 11 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
language: java

before_install:
- chmod +x gradlew
- chmod +x upload_files_travis.sh

install: ./gradlew setupCIWorkspace -S
script: ./gradlew build -S

env:
global:
- "TERM=dumb"
- secure: "ix4lQlBHo9C0g1cPUMjERmoS888V3rIuIPPpJKwREEDpckTslk59QgwNAi+u7P0qGOufVtHWECPirE5Yrg+qU135k5Rt9K21OEY/bXryHlOVBFuf2VHXe23tBdhBDw0uVFg8NSmMP/V0YdHbSyVdVa0VEouJgnsTPT7TOIcReIQ="
- secure: "h1LPgMdaWDq1CktbfOKJuP5xWhhaglq0muolya6F12EWt7gA4uaua9ufCaoDfsHLvuFbkLDzfQdhKIvytOntpcqcYpkQHxicgvJiABB1FRG1QTOy9HIdVqhwmJ17gpfFOejmk31aQ/g2qIT3O4dzQHeDEnhYScDNpDbETC1Wk58="

after_success: ./upload_files_travis.sh
before_install:
- chmod +x gradlew

install:
- ./gradlew setupCIWorkspace -S

script:
- ./gradlew build -S

after_success:
- ./gradlew uploadArchives -S
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ I also plan to extend its functionality and usefulness by implementing new featu
If you have a mod that Easy Crafting is not working properly with, please submit an issue (and/or a pull request to fix it) and the accompanying crash report (if there is one).

### Official Builds
Official builds of the mod can be found [here](http://lepko.net/minecraft/).
Official builds of the mod can be found [here](http://mods.lepko.net/).

Official Minecraft Forum thread [here](http://www.minecraftforum.net/topic/1558714-).

Expand Down
79 changes: 58 additions & 21 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,60 +14,97 @@ buildscript {
classpath "net.minecraftforge.gradle:ForgeGradle:1.2-SNAPSHOT"
}
}

// *** Load ForgeGradle
apply plugin: "forge"

def buildNumber = (System.getenv("TRAVIS_BUILD_NUMBER") ?: "X")
version = "1.7.2-2.0.0." + buildNumber
// *** Load Build Config
file("build.properties").withReader {
def prop = new Properties()
prop.load(it)
project.ext.config = new ConfigSlurper().parse(prop)
}

// *** Load Environment Variables
ext.build_number = "${System.getenv("TRAVIS_BUILD_NUMBER") ?: "X"}"

// *** Configure
version = "${config.version_mc}-${config.version}.${build_number}"
group = "${config.package}"
archivesBaseName = "${config.filename}"

group= "net.lepko.easycrafting"
archivesBaseName = "EasyCrafting"
// *** Print Information
println "~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
println "~ version = ${version}"
println "~ forge = ${config.version_mc}-${config.version_forge}"
println "~~~~~~~~~~~~~~~~~~~~~~~~~~~~"

minecraft {
version = "1.7.2-10.12.2.1128"
version = "${config.version_mc}-${config.version_forge}"

if (file("../run").exists()) {
assetDir = "../run/assets"
if (file("../run").exists()) {
runDir = "../run"
} else {
assetDir = "run/assets"
runDir = "run"
}
}

dependencies {
//compile "com.mod-buildcraft:buildcraft:6.0.8:dev" // adds buildcraft to the dev env
}

processResources
{
processResources {
// this will ensure that this task is redone when the versions change.
inputs.property "version", project.version
inputs.property "version", project.version
inputs.property "mcversion", project.minecraft.version

// replace stuff in mcmod.info, nothing else
// expand variables
from(sourceSets.main.resources.srcDirs) {
include "mcmod.info"
include "**/*.properties"
include "**/*.info"

// replace version and mcversion
expand "version":project.version, "mcversion":project.minecraft.version
expand "version": project.version, "mcversion": project.minecraft.version
}

// copy everything else, thats not the mcmod.info
// copy everything else
from(sourceSets.main.resources.srcDirs) {
exclude "mcmod.info"
exclude "**/*.properties"
exclude "**/*.info"
}
}

// *** Additional Jars
task sourceJar(type: Jar) {
from sourceSets.main.allSource
classifier = 'src'
classifier = "src"
}

// Add in an mcp named jar, for those who wish to run in a development environment (assuming mcp naming matches)
task devJar(type: Jar) {
from sourceSets.main.output
classifier = 'dev'
classifier = "dev"
}

artifacts {
archives sourceJar, devJar
}

// *** Deploy Jars
configurations {
deployJars
}

dependencies {
deployJars "org.apache.maven.wagon:wagon-ftp:2.2"
}

uploadArchives {
onlyIf {
System.getenv("FTP_USER") != null && System.getenv("FTP_PASSWORD") != null &&
System.getenv("TRAVIS_BRANCH") == "master" && System.getenv("TRAVIS_PULL_REQUEST") == "false"
}
repositories.mavenDeployer {
configuration = configurations.deployJars
repository(url: "${config.ftp_location}"){
authentication(userName: "${System.getenv("FTP_USER")}", password: "${System.getenv("FTP_PASSWORD")}")
}
}
}
10 changes: 10 additions & 0 deletions build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package=net.lepko.easycrafting
filename=EasyCrafting

version=2.0.0

version_mc=1.7.10
version_forge=10.13.0.1186

#ftp_location=ftp://localhost/maven/
ftp_location=ftp://lepko.net/domains/lepko.net/public_html/mods/maven/
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Mon May 19 17:03:50 CEST 2014
#Fri Jul 18 12:50:06 CEST 2014
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-1.12-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.0-bin.zip
6 changes: 6 additions & 0 deletions src/main/java/net/lepko/easycrafting/EasyCrafting.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
@Mod(modid = Ref.MOD_ID, useMetadata = true)
public class EasyCrafting {

//TODO: block.shouldCheckWeakPower()
//block.onNeighbourTileChange()
//RIGHT CLICK SEARCH BAR DELETES ALL TEXT
//CREDIT ElementalRobot50 for Auto Crafting Table textures


@Instance(Ref.MOD_ID)
public static EasyCrafting INSTANCE;

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/net/lepko/easycrafting/Ref.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.apache.logging.log4j.Logger;

import java.util.Locale;
import java.util.UUID;

public final class Ref {

Expand All @@ -27,7 +28,7 @@ private Ref() {}
@SidedProxy(clientSide = "net.lepko.easycrafting.core.proxy.ProxyClient", serverSide = "net.lepko.easycrafting.core.proxy.Proxy")
public static Proxy PROXY;

public static GameProfile GAME_PROFILE = new GameProfile("easycrafting.fake.player.profile", "[" + Ref.MOD_ID + "]");
public static GameProfile GAME_PROFILE = new GameProfile(UUID.nameUUIDFromBytes("easycrafting.fake.player.profile".getBytes()), "[" + Ref.MOD_ID + "]");

public static void init() {
MOD_NAME = Loader.instance().activeModContainer().getName();
Expand Down
52 changes: 7 additions & 45 deletions src/main/java/net/lepko/easycrafting/core/GuiHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,70 +3,32 @@
import cpw.mods.fml.common.network.IGuiHandler;
import cpw.mods.fml.common.network.internal.FMLNetworkHandler;
import net.lepko.easycrafting.EasyCrafting;
import net.lepko.easycrafting.Ref;
import net.lepko.easycrafting.core.block.TileEntityAutoCrafting;
import net.lepko.easycrafting.core.block.TileEntityEasyCrafting;
import net.lepko.easycrafting.core.inventory.ContainerAutoCrafting;
import net.lepko.easycrafting.core.inventory.ContainerEasyCrafting;
import net.lepko.easycrafting.core.inventory.gui.GuiAutoCrafting;
import net.lepko.easycrafting.core.inventory.gui.GuiEasyCrafting;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.lepko.easycrafting.core.inventory.gui.IGuiTile;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;

public enum GuiHandler implements IGuiHandler {
INSTANCE;

public static enum GuiType {
EASYCRAFTING(0, TileEntityEasyCrafting.class, ContainerEasyCrafting.class, GuiEasyCrafting.class),
AUTOCRAFTING(1, TileEntityAutoCrafting.class, ContainerAutoCrafting.class, GuiAutoCrafting.class);

public final int id;
public final Class<? extends TileEntity> teClass;
public final Class<? extends Container> containerClass;
public final Class<? extends GuiContainer> guiClass;

GuiType(int id, Class<? extends TileEntity> teClass, Class<? extends Container> containerClass, Class<? extends GuiContainer> guiClass) {
this.id = id;
this.teClass = teClass;
this.containerClass = containerClass;
this.guiClass = guiClass;
}
}

public static void openGui(GuiType gui, EntityPlayer player, World world, int x, int y, int z) {
FMLNetworkHandler.openGui(player, EasyCrafting.INSTANCE, gui.id, world, x, y, z);
public static void openGui(EntityPlayer player, World world, int x, int y, int z) {
FMLNetworkHandler.openGui(player, EasyCrafting.INSTANCE, 0, world, x, y, z);
}

@Override
public Object getServerGuiElement(int guiID, EntityPlayer player, World world, int x, int y, int z) {
TileEntity te = world.getTileEntity(x, y, z);
try {
for (GuiType gui : GuiType.values()) {
if (gui.id == guiID && gui.teClass.isInstance(te)) {
return gui.containerClass.getConstructor(InventoryPlayer.class, gui.teClass).newInstance(player.inventory, te);
}
}
} catch (Throwable t) {
Ref.LOGGER.warn("Bad gui container! id:" + guiID + " teClass:" + (te == null ? "null" : te.getClass().getName()), t);
if (te instanceof IGuiTile) {
return ((IGuiTile) te).getServerGuiElement(player, te);
}
return null;
}

@Override
public Object getClientGuiElement(int guiID, EntityPlayer player, World world, int x, int y, int z) {
TileEntity te = world.getTileEntity(x, y, z);
try {
for (GuiType gui : GuiType.values()) {
if (gui.id == guiID && gui.teClass.isInstance(te)) {
return gui.guiClass.getConstructor(InventoryPlayer.class, gui.teClass).newInstance(player.inventory, te);
}
}
} catch (Throwable t) {
Ref.LOGGER.warn("Bad gui! id:" + guiID + " teClass:" + (te == null ? "null" : te.getClass().getName()), t);
if (te instanceof IGuiTile) {
return ((IGuiTile) te).getClientGuiElement(player, te);
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import cpw.mods.fml.relauncher.SideOnly;
import net.lepko.easycrafting.Ref;
import net.lepko.easycrafting.core.GuiHandler;
import net.lepko.easycrafting.core.inventory.gui.IGuiTile;
import net.lepko.easycrafting.core.recipe.RecipeManager;
import net.lepko.easycrafting.core.util.InventoryUtils;
import net.minecraft.block.Block;
Expand Down Expand Up @@ -92,11 +93,10 @@ public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer p

if (te instanceof TileEntityEasyCrafting) {
RecipeManager.scanRecipes();
GuiHandler.openGui(GuiHandler.GuiType.EASYCRAFTING, player, world, x, y, z);
return true;
}
if (te instanceof TileEntityAutoCrafting) {
GuiHandler.openGui(GuiHandler.GuiType.AUTOCRAFTING, player, world, x, y, z);

if (te instanceof IGuiTile) {
GuiHandler.openGui(player, world, x, y, z);
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import cpw.mods.fml.common.FMLCommonHandler;
import net.lepko.easycrafting.Ref;
import net.lepko.easycrafting.core.inventory.ContainerAutoCrafting;
import net.lepko.easycrafting.core.inventory.gui.GuiAutoCrafting;
import net.lepko.easycrafting.core.inventory.gui.IGuiTile;
import net.lepko.easycrafting.core.util.InventoryUtils;
import net.lepko.easycrafting.core.util.StackUtils;
import net.minecraft.entity.player.EntityPlayer;
Expand All @@ -22,7 +25,7 @@
import java.util.List;
import java.util.Locale;

public class TileEntityAutoCrafting extends TileEntity implements ISidedInventory {
public class TileEntityAutoCrafting extends TileEntity implements ISidedInventory, IGuiTile {

private static class FakeContainer extends Container {
private FakeContainer() {
Expand Down Expand Up @@ -349,4 +352,20 @@ public boolean canInsertItem(int slotIndex, ItemStack stack, int side) {
public boolean canExtractItem(int slotIndex, ItemStack stack, int side) {
return slotIndex >= 18 && slotIndex < inventory.length;
}

@Override
public Object getServerGuiElement(EntityPlayer player, TileEntity tileEntity) {
if (tileEntity instanceof TileEntityAutoCrafting) {
return new ContainerAutoCrafting(player.inventory, ((TileEntityAutoCrafting) tileEntity));
}
return null;
}

@Override
public Object getClientGuiElement(EntityPlayer player, TileEntity tileEntity) {
if (tileEntity instanceof TileEntityAutoCrafting) {
return new GuiAutoCrafting(player.inventory, ((TileEntityAutoCrafting) tileEntity));
}
return null;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package net.lepko.easycrafting.core.block;

import net.lepko.easycrafting.core.inventory.ContainerEasyCrafting;
import net.lepko.easycrafting.core.inventory.gui.GuiEasyCrafting;
import net.lepko.easycrafting.core.inventory.gui.IGuiTile;
import net.lepko.easycrafting.core.util.InventoryUtils;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
Expand All @@ -8,7 +11,7 @@
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.Constants;

public class TileEntityEasyCrafting extends TileEntity implements IInventory {
public class TileEntityEasyCrafting extends TileEntity implements IInventory, IGuiTile {

private ItemStack[] inventory;

Expand Down Expand Up @@ -89,4 +92,20 @@ public boolean isItemValidForSlot(int slotIndex, ItemStack itemstack) {
}
return false;
}

@Override
public Object getServerGuiElement(EntityPlayer player, TileEntity tileEntity) {
if (tileEntity instanceof TileEntityEasyCrafting) {
return new ContainerEasyCrafting(player.inventory, ((TileEntityEasyCrafting) tileEntity));
}
return null;
}

@Override
public Object getClientGuiElement(EntityPlayer player, TileEntity tileEntity) {
if (tileEntity instanceof TileEntityEasyCrafting) {
return new GuiEasyCrafting(player.inventory, ((TileEntityEasyCrafting) tileEntity));
}
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package net.lepko.easycrafting.core.inventory.gui;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;

public interface IGuiTile {
Object getServerGuiElement(EntityPlayer player, TileEntity tileEntity);
Object getClientGuiElement(EntityPlayer player, TileEntity tileEntity);
}
Loading

0 comments on commit 0e2108c

Please sign in to comment.