diff --git a/common/mekanism/api/AdvancedInput.java b/common/mekanism/api/AdvancedInput.java new file mode 100644 index 000000000..189398ebe --- /dev/null +++ b/common/mekanism/api/AdvancedInput.java @@ -0,0 +1,28 @@ +package mekanism.api; + +import mekanism.api.gas.Gas; +import mekanism.common.util.StackUtils; +import net.minecraft.item.ItemStack; + +public class AdvancedInput +{ + public ItemStack itemStack; + + public Gas gasType; + + public AdvancedInput(ItemStack item, Gas gas) + { + itemStack = item; + gasType = gas; + } + + public boolean isValid() + { + return itemStack != null && gasType != null; + } + + public boolean matches(AdvancedInput input) + { + return StackUtils.equalsWildcard(itemStack, input.itemStack) && input.itemStack.stackSize >= itemStack.stackSize; + } +} diff --git a/common/mekanism/client/nei/AdvancedMachineRecipeHandler.java b/common/mekanism/client/nei/AdvancedMachineRecipeHandler.java index 15503cf92..f21ba93db 100644 --- a/common/mekanism/client/nei/AdvancedMachineRecipeHandler.java +++ b/common/mekanism/client/nei/AdvancedMachineRecipeHandler.java @@ -3,18 +3,28 @@ package mekanism.client.nei; import static codechicken.core.gui.GuiDraw.changeTexture; import static codechicken.core.gui.GuiDraw.drawTexturedModalRect; +import java.awt.Point; import java.awt.Rectangle; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Set; +import mekanism.api.AdvancedInput; +import mekanism.api.gas.GasStack; +import mekanism.client.nei.ChemicalInfuserRecipeHandler.CachedIORecipe; +import mekanism.common.ObfuscatedNames; +import mekanism.common.util.MekanismUtils; +import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.item.ItemStack; import org.lwjgl.opengl.GL11; +import codechicken.core.gui.GuiDraw; +import codechicken.nei.NEIClientConfig; import codechicken.nei.NEIServerUtils; import codechicken.nei.PositionedStack; +import codechicken.nei.recipe.GuiRecipe; import codechicken.nei.recipe.TemplateRecipeHandler; public abstract class AdvancedMachineRecipeHandler extends BaseRecipeHandler @@ -23,7 +33,7 @@ public abstract class AdvancedMachineRecipeHandler extends BaseRecipeHandler public abstract String getRecipeId(); - public abstract Set> getRecipes(); + public abstract Set> getRecipes(); public abstract List getFuelStacks(); @@ -88,6 +98,24 @@ public abstract class AdvancedMachineRecipeHandler extends BaseRecipeHandler } } } + + @Override + public void loadUsageRecipes(String inputId, Object... ingredients) + { + if(inputId.equals("gas") && ingredients.length == 1 && ingredients[0] instanceof GasStack) + { + for(Map.Entry irecipe : getRecipes()) + { + if(irecipe.getKey().gasType == ((GasStack)ingredients[0]).getGas()) + { + arecipes.add(new CachedIORecipe(irecipe, getFuelStacks())); + } + } + } + else { + super.loadUsageRecipes(inputId, ingredients); + } + } @Override public void loadUsageRecipes(ItemStack ingredient) @@ -100,18 +128,107 @@ public abstract class AdvancedMachineRecipeHandler extends BaseRecipeHandler } } } + + @Override + public List handleTooltip(GuiRecipe gui, List currenttip, int recipe) + { + Point point = GuiDraw.getMousePosition(); + + int xAxis = point.x-(Integer)MekanismUtils.getPrivateValue(gui, GuiContainer.class, ObfuscatedNames.GuiContainer_guiLeft); + int yAxis = point.y-(Integer)MekanismUtils.getPrivateValue(gui, GuiContainer.class, ObfuscatedNames.GuiContainer_guiTop); + + if(xAxis >= 61 && xAxis <= 67 && yAxis >= 37+13 && yAxis <= 49+13) + { + currenttip.add(((CachedIORecipe)arecipes.get(recipe)).input.gasType.getLocalizedName()); + } + + return super.handleTooltip(gui, currenttip, recipe); + } + + @Override + public boolean keyTyped(GuiRecipe gui, char keyChar, int keyCode, int recipe) + { + Point point = GuiDraw.getMousePosition(); + + int xAxis = point.x-(Integer)MekanismUtils.getPrivateValue(gui, GuiContainer.class, ObfuscatedNames.GuiContainer_guiLeft); + int yAxis = point.y-(Integer)MekanismUtils.getPrivateValue(gui, GuiContainer.class, ObfuscatedNames.GuiContainer_guiTop); + + GasStack stack = null; + + if(xAxis >= 61 && xAxis <= 67 && yAxis >= 37+13 && yAxis <= 49+13) + { + stack = new GasStack(((CachedIORecipe)arecipes.get(recipe)).input.gasType, 1); + } + + if(stack != null) + { + if(keyCode == NEIClientConfig.getKeyBinding("gui.recipe")) + { + if(doGasLookup(stack, false)) + { + return true; + } + } + else if(keyCode == NEIClientConfig.getKeyBinding("gui.usage")) + { + if(doGasLookup(stack, true)) + { + return true; + } + } + } + + return super.keyTyped(gui, keyChar, keyCode, recipe); + } + + @Override + public boolean mouseClicked(GuiRecipe gui, int button, int recipe) + { + Point point = GuiDraw.getMousePosition(); + + int xAxis = point.x - (Integer)MekanismUtils.getPrivateValue(gui, GuiContainer.class, ObfuscatedNames.GuiContainer_guiLeft); + int yAxis = point.y - (Integer)MekanismUtils.getPrivateValue(gui, GuiContainer.class, ObfuscatedNames.GuiContainer_guiTop); + + GasStack stack = null; + + if(xAxis >= 61 && xAxis <= 67 && yAxis >= 37+13 && yAxis <= 49+13) + { + stack = new GasStack(((CachedIORecipe)arecipes.get(recipe)).input.gasType, 1); + } + + if(stack != null) + { + if(button == 0) + { + if(doGasLookup(stack, false)) + { + return true; + } + } + else if(button == 1) + { + if(doGasLookup(stack, true)) + { + return true; + } + } + } + + return super.mouseClicked(gui, button, recipe); + } public class CachedIORecipe extends TemplateRecipeHandler.CachedRecipe { public List fuelStacks; - public PositionedStack inputStack; + public AdvancedInput input; + public PositionedStack outputStack; @Override public PositionedStack getIngredient() { - return inputStack; + return new PositionedStack(input.itemStack, 40, 12); } @Override @@ -126,17 +243,16 @@ public abstract class AdvancedMachineRecipeHandler extends BaseRecipeHandler return new PositionedStack(fuelStacks.get(cycleticks/40 % fuelStacks.size()), 40, 48); } - public CachedIORecipe(ItemStack input, ItemStack output, List fuels) + public CachedIORecipe(AdvancedInput adv, ItemStack output, List fuels) { - super(); - inputStack = new PositionedStack(input, 40, 12); + input = adv; outputStack = new PositionedStack(output, 100, 30); fuelStacks = fuels; } public CachedIORecipe(Map.Entry recipe, List fuels) { - this((ItemStack)recipe.getKey(), (ItemStack)recipe.getValue(), fuels); + this((AdvancedInput)recipe.getKey(), (ItemStack)recipe.getValue(), fuels); } } } diff --git a/common/mekanism/common/block/BlockBasic.java b/common/mekanism/common/block/BlockBasic.java index a0ce68782..cfc2da54f 100644 --- a/common/mekanism/common/block/BlockBasic.java +++ b/common/mekanism/common/block/BlockBasic.java @@ -430,6 +430,24 @@ public class BlockBasic extends Block } } } + else if(blockID == Mekanism.basicBlock2ID) + { + if(world.isRemote) + { + return true; + } + + if(metadata == 0) + { + TileEntitySalinationTank tank = (TileEntitySalinationTank)world.getBlockTileEntity(x, y, z); + + if(!entityplayer.isSneaking()) + { + entityplayer.openGui(Mekanism.instance, 33, world, x, y, z); + return true; + } + } + } return false; } diff --git a/common/mekanism/common/entity/EntityBalloon.java b/common/mekanism/common/entity/EntityBalloon.java index 515f0d19e..4d3f86038 100644 --- a/common/mekanism/common/entity/EntityBalloon.java +++ b/common/mekanism/common/entity/EntityBalloon.java @@ -19,6 +19,8 @@ import com.google.common.io.ByteArrayDataInput; import com.google.common.io.ByteArrayDataOutput; import cpw.mods.fml.common.registry.IEntityAdditionalSpawnData; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; public class EntityBalloon extends Entity implements IEntityAdditionalSpawnData { @@ -257,18 +259,24 @@ public class EntityBalloon extends Entity implements IEntityAdditionalSpawnData for(int i = 0; i < 10; i++) { try { - Pos3D pos = new Pos3D(posX + (rand.nextFloat()*.6 - 0.3), posY - 0.8 + (rand.nextFloat()*.6 - 0.3), posZ + (rand.nextFloat()*.6 - 0.3)); - - EntityFX fx = new EntityReddustFX(worldObj, pos.xPos, pos.yPos, pos.zPos, 1, 0, 0, 0); - fx.setRBGColorF(color.getColor(0), color.getColor(1), color.getColor(2)); - - Minecraft.getMinecraft().effectRenderer.addEffect(fx); - } catch(Exception e) {} + doParticle(); + } catch(Throwable t) {} } } setDead(); } + + @SideOnly(Side.CLIENT) + private void doParticle() + { + Pos3D pos = new Pos3D(posX + (rand.nextFloat()*.6 - 0.3), posY - 0.8 + (rand.nextFloat()*.6 - 0.3), posZ + (rand.nextFloat()*.6 - 0.3)); + + EntityFX fx = new EntityReddustFX(worldObj, pos.xPos, pos.yPos, pos.zPos, 1, 0, 0, 0); + fx.setRBGColorF(color.getColor(0), color.getColor(1), color.getColor(2)); + + Minecraft.getMinecraft().effectRenderer.addEffect(fx); + } @Override public boolean canBePushed() diff --git a/common/mekanism/common/recipe/RecipeHandler.java b/common/mekanism/common/recipe/RecipeHandler.java index 51c99e414..45eab6f26 100644 --- a/common/mekanism/common/recipe/RecipeHandler.java +++ b/common/mekanism/common/recipe/RecipeHandler.java @@ -3,8 +3,10 @@ package mekanism.common.recipe; import java.util.HashMap; import java.util.Map; +import mekanism.api.AdvancedInput; import mekanism.api.ChanceOutput; import mekanism.api.ChemicalPair; +import mekanism.api.gas.GasRegistry; import mekanism.api.gas.GasStack; import mekanism.api.gas.GasTank; import mekanism.api.infuse.InfusionInput; @@ -44,7 +46,7 @@ public final class RecipeHandler */ public static void addOsmiumCompressorRecipe(ItemStack input, ItemStack output) { - Recipe.OSMIUM_COMPRESSOR.put(input, output); + Recipe.OSMIUM_COMPRESSOR.put(new AdvancedInput(input, GasRegistry.getGas("liquidOsmium")), output); } /** @@ -54,7 +56,7 @@ public final class RecipeHandler */ public static void addCombinerRecipe(ItemStack input, ItemStack output) { - Recipe.COMBINER.put(input, output); + Recipe.COMBINER.put(new AdvancedInput(input, GasRegistry.getGas("liquidStone")), output); } /** @@ -74,7 +76,7 @@ public final class RecipeHandler */ public static void addPurificationChamberRecipe(ItemStack input, ItemStack output) { - Recipe.PURIFICATION_CHAMBER.put(input, output); + Recipe.PURIFICATION_CHAMBER.put(new AdvancedInput(input, GasRegistry.getGas("oxygen")), output); } /** @@ -114,7 +116,7 @@ public final class RecipeHandler */ public static void addChemicalInjectionChamberRecipe(ItemStack input, ItemStack output) { - Recipe.CHEMICAL_INJECTION_CHAMBER.put(input, output); + Recipe.CHEMICAL_INJECTION_CHAMBER.put(new AdvancedInput(input, GasRegistry.getGas("sulfuricAcid")), output); } /** @@ -295,6 +297,33 @@ public final class RecipeHandler return null; } + /** + * Gets the output ItemStack of the AdvancedInput in the parameters. + * @param itemstack - input AdvancedInput + * @param stackDecrease - whether or not to decrease the input slot's stack size + * @param recipes - Map of recipes + * @return output ItemStack + */ + public static ItemStack getOutput(AdvancedInput input, boolean stackDecrease, Map recipes) + { + if(input != null && input.isValid()) + { + for(Map.Entry entry : recipes.entrySet()) + { + if(entry.getKey().matches(input)) + { + if(stackDecrease) + { + input.itemStack.stackSize -= entry.getKey().itemStack.stackSize; + } + + return entry.getValue().copy(); + } + } + } + + return null; + } /** * Gets the output ItemStack of the ItemStack in the parameters. @@ -351,14 +380,14 @@ public final class RecipeHandler public static enum Recipe { ENRICHMENT_CHAMBER(new HashMap()), - OSMIUM_COMPRESSOR(new HashMap()), - COMBINER(new HashMap()), + OSMIUM_COMPRESSOR(new HashMap()), + COMBINER(new HashMap()), CRUSHER(new HashMap()), - PURIFICATION_CHAMBER(new HashMap()), + PURIFICATION_CHAMBER(new HashMap()), METALLURGIC_INFUSER(new HashMap()), CHEMICAL_INFUSER(new HashMap()), CHEMICAL_OXIDIZER(new HashMap()), - CHEMICAL_INJECTION_CHAMBER(new HashMap()), + CHEMICAL_INJECTION_CHAMBER(new HashMap()), ELECTROLYTIC_SEPARATOR(new HashMap()), PRECISION_SAWMILL(new HashMap()); diff --git a/common/mekanism/common/tile/TileEntityAdvancedElectricMachine.java b/common/mekanism/common/tile/TileEntityAdvancedElectricMachine.java index 54c8d8f33..8722d3bc8 100644 --- a/common/mekanism/common/tile/TileEntityAdvancedElectricMachine.java +++ b/common/mekanism/common/tile/TileEntityAdvancedElectricMachine.java @@ -2,6 +2,7 @@ package mekanism.common.tile; import java.util.ArrayList; +import mekanism.api.AdvancedInput; import mekanism.api.EnumColor; import mekanism.api.gas.Gas; import mekanism.api.gas.GasStack; @@ -146,7 +147,7 @@ public abstract class TileEntityAdvancedElectricMachine extends TileEntityBasicM @Override public boolean isItemValidForSlot(int slotID, ItemStack itemstack) { - if(slotID == 2) + if(slotID == 2 || gasTank.getGas() == null) { return false; } @@ -156,7 +157,7 @@ public abstract class TileEntityAdvancedElectricMachine extends TileEntityBasicM } else if(slotID == 0) { - return RecipeHandler.getOutput(itemstack, false, getRecipes()) != null; + return RecipeHandler.getOutput(new AdvancedInput(itemstack, gasTank.getGas().getGas()), false, getRecipes()) != null; } else if(slotID == 3) { @@ -173,7 +174,7 @@ public abstract class TileEntityAdvancedElectricMachine extends TileEntityBasicM @Override public void operate() { - ItemStack itemstack = RecipeHandler.getOutput(inventory[0], true, getRecipes()); + ItemStack itemstack = RecipeHandler.getOutput(new AdvancedInput(inventory[0], gasTank.getGas().getGas()), true, getRecipes()); if(inventory[0].stackSize <= 0) { @@ -195,12 +196,12 @@ public abstract class TileEntityAdvancedElectricMachine extends TileEntityBasicM @Override public boolean canOperate() { - if(inventory[0] == null) + if(inventory[0] == null || gasTank.getGas() == null) { return false; } - ItemStack itemstack = RecipeHandler.getOutput(inventory[0], false, getRecipes()); + ItemStack itemstack = RecipeHandler.getOutput(new AdvancedInput(inventory[0], gasTank.getGas().getGas()), false, getRecipes()); if(itemstack == null) {