Finished first cut of enchanter.

This commit is contained in:
CrazyPants committed 2014-07-17 14:51:06 +08:00
1 parent 9b8b41489f
commit 3d861551b8
13 files changed
+233 -12

No files matched your search

@@ -118,11 +118,29 @@ public class ClientProxy extends CommonProxy {
private DefaultConduitRenderer dcr = new DefaultConduitRenderer();
private ConduitBundleRenderer cbr;
private boolean checkedNei = false;
private boolean neiInstalled = false;
@Override
public World getClientWorld() {
return FMLClientHandler.instance().getClient().theWorld;
}
@Override
public boolean isNeiInstalled() {
if(checkedNei) {
return neiInstalled;
}
try{
Class.forName("crazypants.enderio.nei.EnchanterRecipeHandler");
neiInstalled = true;
} catch(Exception e) {
neiInstalled = false;
}
checkedNei = true;
return false;
}
@Override
public EntityPlayer getClientPlayer() {
@@ -34,4 +34,8 @@ public class CommonProxy {
public void load() {
}
public boolean isNeiInstalled() {
return false;
}
}
@@ -8,6 +8,7 @@ import net.minecraft.inventory.Slot;
import org.lwjgl.opengl.GL11;
import crazypants.enderio.EnderIO;
import crazypants.enderio.gui.IconButtonEIO;
import crazypants.enderio.gui.IconEIO;
import crazypants.enderio.gui.IoConfigRenderer.SelectedFace;
@@ -81,7 +82,7 @@ public abstract class GuiMachineBase extends GuiContainerBase {
}
protected boolean showRecipeButton() {
return true;
return EnderIO.proxy.isNeiInstalled();
}
public void renderSlotHighlights(IoMode mode) {
@@ -133,6 +133,10 @@ public class MachineRecipes {
GameRegistry
.addShapedRecipe(mJMonitor, "bmb", "bMb", "bcb", 'b', Blocks.stonebrick, 'e', Items.ender_eye, 'M', machineChassi, 'm', mJReader, 'p', powerConduit,
'r', redstoneConduit, 'c', capacitor);
//Enchanter
ItemStack enchanter = new ItemStack(EnderIO.blockEnchanter);
GameRegistry.addShapedRecipe(enchanter, "dbd", "sss", " s ", 'd', Items.diamond, 'b', Items.book, 's', darkSteel);
}
@@ -42,6 +42,10 @@ public class EnchanterRecipe {
public Enchantment getEnchantment() {
return enchantment;
}
public RecipeInput getInput() {
return input;
}
@@ -39,6 +39,9 @@ public class EnchanterRecipeManager {
return null;
}
public List<EnchanterRecipe> getRecipes() {
return recipes;
}
}
@@ -102,9 +102,6 @@ public class EnchanterRenderer implements ISimpleBlockRenderingHandler, IItemRen
}
}
boolean flip = facing == ForgeDirection.EAST.ordinal() || facing == ForgeDirection.WEST.ordinal();
// float xOff = flip ? 0 : 0.1f;
// float zOff = flip ? 0.1f : 0f;
float xOff = 0.1f;
float zOff = 0f;
@@ -4,6 +4,8 @@ import java.awt.Color;
import org.lwjgl.opengl.GL11;
import crazypants.enderio.EnderIO;
import crazypants.enderio.gui.IconEIO;
import crazypants.enderio.machine.vacuum.ContainerVacuumChest;
import crazypants.render.ColorUtil;
import crazypants.render.RenderUtil;
@@ -32,8 +34,11 @@ public class GuiEnchanter extends GuiContainer {
int sy = (height - ySize) / 2;
drawTexturedModalRect(sx, sy, 0, 0, this.xSize, this.ySize);
int curCost = te.getCurrentEnchantmentCost();
if(EnderIO.proxy.isNeiInstalled()) {
IconEIO.RECIPE.renderIcon(sx + 155, sy + 8, 16, 16, 0, true);
}
int curCost = te.getCurrentEnchantmentCost();
if(curCost > 0) {
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
@@ -168,10 +168,8 @@ public class TileEnchanter extends TileEntityEio implements ISidedInventory {
}
return new EnchantmentData(ench, Math.min(inv[1].stackSize, ench.getMaxLevel()));
}
public int getCurrentEnchantmentCost() {
EnchantmentData enchData = getCurrentEnchantment();
public static int getEnchantmentCost(EnchantmentData enchData) {
if(enchData == null) {
return 0;
}
@@ -181,10 +179,15 @@ public class TileEnchanter extends TileEntityEio implements ISidedInventory {
if(level > enchantment.getMaxLevel()) {
level = enchantment.getMaxLevel();
}
int costPerLevel = 0;
switch (enchantment.getWeight()) {
case 1:
costPerLevel = 8;
//Stops silk touch and infinity being too cheap
if(enchantment.getMaxLevel() == 1) {
level = 2;
}
break;
case 2:
costPerLevel = 4;
@@ -210,6 +213,10 @@ public class TileEnchanter extends TileEntityEio implements ISidedInventory {
return res;
}
public int getCurrentEnchantmentCost() {
return getEnchantmentCost(getCurrentEnchantment());
}
public void setOutput(ItemStack output) {
inv[inv.length - 1] = output;
markDirty();
@@ -0,0 +1,170 @@
package crazypants.enderio.nei;
import java.awt.Rectangle;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.resources.I18n;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentData;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import codechicken.nei.PositionedStack;
import codechicken.nei.recipe.TemplateRecipeHandler;
import crazypants.enderio.crafting.IEnderIoRecipe;
import crazypants.enderio.crafting.IRecipeInput;
import crazypants.enderio.crafting.IRecipeOutput;
import crazypants.enderio.crafting.RecipeReigistry;
import crazypants.enderio.machine.alloy.GuiAlloySmelter;
import crazypants.enderio.machine.enchanter.EnchanterRecipe;
import crazypants.enderio.machine.enchanter.EnchanterRecipeManager;
import crazypants.enderio.machine.enchanter.GuiEnchanter;
import crazypants.enderio.machine.enchanter.TileEnchanter;
import crazypants.enderio.machine.power.PowerDisplayUtil;
import crazypants.enderio.machine.recipe.RecipeInput;
import crazypants.enderio.nei.AlloySmelterRecipeHandler.AlloySmelterRecipe;
public class EnchanterRecipeHandler extends TemplateRecipeHandler {
@Override
public String getRecipeName() {
return "Enchanter";
}
@Override
public String getGuiTexture() {
return "enderio:textures/gui/enchanter.png";
}
@Override
public Class<? extends GuiContainer> getGuiClass() {
return GuiEnchanter.class;
}
@Override
public String getOverlayIdentifier() {
return "EIOEnchanter";
}
@Override
public void loadTransferRects() {
transferRects.add(new TemplateRecipeHandler.RecipeTransferRect(new Rectangle(149, -3, 16, 16), "EIOEnchanter", new Object[0]));
}
@Override
public void loadCraftingRecipes(ItemStack result) {
if(result == null || result.getItem() != Items.enchanted_book) {
return;
}
Map<Short, Short> enchants = EnchantmentHelper.getEnchantments(result);
List<EnchanterRecipe> recipes = EnchanterRecipeManager.getInstance().getRecipes();
for(Short id : enchants.keySet()) {
if(id != null && id >= 0 && id < Enchantment.enchantmentsList.length) {
Enchantment ench = Enchantment.enchantmentsList[id];
if(ench != null && ench.getName() != null) {
for (EnchanterRecipe recipe : recipes) {
if(recipe.isValid() && recipe.getEnchantment().getName().equals(ench.getName())) {
EnchantmentData enchantment = new EnchantmentData(recipe.getEnchantment(), 1);
ItemStack output = new ItemStack(Items.enchanted_book);
Items.enchanted_book.addEnchantment(output, enchantment);
EnchanterRecipeNEI rec = new EnchanterRecipeNEI(recipe.getInput(), output, enchantment);
arecipes.add(rec);
}
}
}
}
}
}
@Override
public void loadCraftingRecipes(String outputId, Object... results) {
if(outputId.equals("EIOEnchanter") && getClass() == EnchanterRecipeHandler.class) {
List<EnchanterRecipe> recipes = EnchanterRecipeManager.getInstance().getRecipes();
for (EnchanterRecipe recipe : recipes) {
if(recipe.isValid()) {
EnchantmentData enchantment = new EnchantmentData(recipe.getEnchantment(), 1);
ItemStack output = new ItemStack(Items.enchanted_book);
Items.enchanted_book.addEnchantment(output, enchantment);
EnchanterRecipeNEI rec = new EnchanterRecipeNEI(recipe.getInput(), output, enchantment);
arecipes.add(rec);
}
}
} else {
super.loadCraftingRecipes(outputId, results);
}
}
@Override
public void loadUsageRecipes(ItemStack ingredient) {
List<EnchanterRecipe> recipes = EnchanterRecipeManager.getInstance().getRecipes();
for (EnchanterRecipe recipe : recipes) {
if(recipe.isValid() && recipe.isInput(ingredient)) {
EnchantmentData enchantment = new EnchantmentData(recipe.getEnchantment(), 1);
ItemStack output = new ItemStack(Items.enchanted_book);
Items.enchanted_book.addEnchantment(output, enchantment);
EnchanterRecipeNEI rec = new EnchanterRecipeNEI(recipe.getInput(), output, enchantment);
arecipes.add(rec);
}
}
}
@Override
public void drawExtras(int recipeIndex) {
EnchanterRecipeNEI recipe = (EnchanterRecipeNEI) arecipes.get(recipeIndex);
int cost = TileEnchanter.getEnchantmentCost(recipe.enchData);
if(cost > 0) {
String s = I18n.format("container.repair.cost", new Object[] {Integer.valueOf(cost)});
FontRenderer fr = Minecraft.getMinecraft().fontRenderer;
int sw = fr.getStringWidth(s);
fr.drawStringWithShadow(s, 90 - (sw/2), 48, 8453920);
}
}
public List<ItemStack> getInputs(RecipeInput input) {
List<ItemStack> result = new ArrayList<ItemStack>();
result.add(input.getInput());
ItemStack[] equivs = input.getEquivelentInputs();
if(equivs != null && equivs.length > 0) {
result.addAll(Arrays.asList(equivs));
}
return result;
}
public class EnchanterRecipeNEI extends TemplateRecipeHandler.CachedRecipe {
private ArrayList<PositionedStack> input;
private PositionedStack output;
private EnchantmentData enchData;
@Override
public List<PositionedStack> getIngredients() {
return getCycledIngredients(cycleticks / 20, input);
}
@Override
public PositionedStack getResult() {
return output;
}
public EnchanterRecipeNEI(RecipeInput ingredient, ItemStack result, EnchantmentData enchData) {
input = new ArrayList<PositionedStack>();
input.add(new PositionedStack(new ItemStack(Items.writable_book), 22, 24));
input.add(new PositionedStack(getInputs(ingredient), 71, 24));
output = new PositionedStack(result, 129, 24);
this.enchData = enchData;
}
}
}
@@ -17,6 +17,9 @@ public class NEIEnderIOConfig implements IConfigureNEI {
API.registerRecipeHandler(new VatRecipeHandler());
API.registerUsageHandler(new VatRecipeHandler());
API.registerRecipeHandler(new EnchanterRecipeHandler());
API.registerUsageHandler(new EnchanterRecipeHandler());
API.hideItem(new ItemStack(EnderIO.blockConduitFacade));
API.hideItem(new ItemStack(EnderIO.itemEnderface));