Jump to content

Adding shaped recipes, a progress bar, and a fuel gauge to a custom furnace


edymondo

Recommended Posts

FOLLOW ON PROBLEM IS AT MESSAGE NO. 8

 

i am attempting to add seven slots more than i currently have into my furnace, however i also need to have a power bar (much like an mfe electricity bar in ic2) and the progress bar. I had it working with 2 slots, however the game now crashes if i try to open it. I dont know how to fix the problem, however i would be very thankful if somebody could help me, here are the relevant classes, and lastly (I hope) i dont know how to set up a recipe with this many slots in my infuser.:

 

Recipe

 

(this is what i want it to be)

custom item, custom item, custom item

iron ingot, diamond, iron ingot

custom item, custom item, custom item

 

package net.mymod.mod.crafting;

import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.mymod.mod.mymod;

public class AngellicInfuserRecipes {

public AngellicInfuserRecipes() {

}

public static ItemStack getMashingResult(Item item, Item item2) {
	return getOutput(item, item2);
}

public static ItemStack getOutput(Item item, Item item2) {
	//Recipe One
	if (item == mymod.itemPowderedOrder && item2 == Items.diamond || item == Items.diamond && item2 == mymod.itemPowderedOrder) {
		return new ItemStack(mymod.itemAngelicIngot);
	}

	return null;
}

}

 

 

Gui Handler

 

package net.mymod.Handler;

import cpw.mods.fml.common.network.IGuiHandler;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.mymod.mod.mymod;
import net.mymod.mod.TileEntity.TileEntityAngellicInfuser;
import net.mymod.mod.container.ContainerAngellicInfuser;
import net.mymod.mod.gui.guiAngelicInfuser;


public class GUIHandler implements IGuiHandler {

@Override
public Object getServerGuiElement(int ID, EntityPlayer player, World world,	int x, int y, int z) {
	TileEntity entity = world.getTileEntity(x, y, z);

	if(entity != null) {
		switch(ID) {

		case mymod.guiIdAngelicInfuser:
			if (entity instanceof TileEntityAngellicInfuser) {
				return new ContainerAngellicInfuser(player.inventory, (TileEntityAngellicInfuser) entity);
			}

		}
	}
	return null;

}

@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world,	int x, int y, int z) {
	TileEntity entity = world.getTileEntity(x, y, z);

	if(entity != null) {
		switch(ID) {
		case mymod.guiIdAngelicInfuser:
			if (entity instanceof TileEntityAngellicInfuser) {
				return new guiAngelicInfuser(player.inventory, (TileEntityAngellicInfuser) entity);
			}

		}
	}
	return null;

}



}		

 

Main Modding Class

 

package net.mymod.mod;


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.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.Item.ToolMaterial;
import net.minecraft.item.ItemArmor.ArmorMaterial;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.util.EnumHelper;
import net.mymod.Handler.CraftingHandler;
import net.mymod.Handler.GUIHandler;
import net.mymod.mod.TileEntity.TileEntityAngellicInfuser;
import net.mymod.mod.WorldGen.mymodWorldGen;
import net.mymod.mod.armor.AngelArmor;
import net.mymod.mod.armor.DemonArmor;
import net.mymod.mod.blocks.AltarCore;
import net.mymod.mod.blocks.AngellicInfuser;
import net.mymod.mod.blocks.AngellicOre;
import net.mymod.mod.blocks.DemonicOre;
import net.mymod.mod.items.AngelBlade;
import net.mymod.mod.items.AngelicIngot;
import net.mymod.mod.items.AngellicAxe;
import net.mymod.mod.items.AngellicHoe;
import net.mymod.mod.items.AngellicPickaxe;
import net.mymod.mod.items.AngellicSpade;
import net.mymod.mod.items.ChaosDust;
import net.mymod.mod.items.DemonicAxe;
import net.mymod.mod.items.DemonicHoe;
import net.mymod.mod.items.DemonicMace;
import net.mymod.mod.items.DemonicPickaxe;
import net.mymod.mod.items.DemonicSpade;
import net.mymod.mod.items.InfusedStick;
import net.mymod.mod.items.PowderedOrder;

@Mod(modid = mymod.modid, version = mymod.version)
public class mymod {
public static final String modid = "mymod";
public static final String version = "Alpha 0.1";

mymodWorldGen eventWorldGen = new mymodWorldGen();

public static CreativeTabs SatangelicaTab;

//tool material

public static ToolMaterial AngelMaterial = EnumHelper.addToolMaterial("AngelMaterial", 3, 3000, 10.0f, 10.0f, 39); 
public static ToolMaterial DemonMaterial = EnumHelper.addToolMaterial("DemonMaterial", 3, 2000, 13.0f, 12.0f, 20);

//armor material

public static ArmorMaterial AngelArmor = EnumHelper.addArmorMaterial("AngelArmor", 10, new int[] {5, 8, 6, 5}, 40);
public static ArmorMaterial DemonArmor = EnumHelper.addArmorMaterial("DemonArmor", 10, new int[] {4, 7, 5, 4}, 27);

@Instance(modid)
public static mymod instance;

//blocks

public static Block blockAltarCore;

//ores

public static Block oreAngellicOre;
public static Block oreDemonicOre;

//items

public static Item itemInfusedStick;

//ingots

public static Item itemAngelicIngot;

//dusts

public static Item itemChaosDust;
public static Item itemPowderedOrder;

//tools

public static Item itemAngelBlade;
public static Item itemAngellicPickaxe;
public static Item itemAngellicAxe;
public static Item itemAngellicSpade;
public static Item itemAngellicHoe;

public static Item itemDemonicMace;
public static Item itemDemonicPickaxe;
public static Item itemDemonicHoe;
public static Item itemDemonicSpade;
public static Item itemDemonicAxe;

//armor

public static int armorAngelHelmId; 
public static int armorAngelChestplateId;
public static int armorAngelLeggingsId;
public static int armorAngelBootsId;

public static int armorDemonHelmId;
public static int armorDemonChestplateId;
public static int armorDemonLeggingsId;
public static int armorDemonBootsId;

//armor (items)

public static Item armorAngelHelm;
public static Item armorAngelChestplate;
public static Item armorAngelLeggings;
public static Item armorAngelBoots;

public static Item armorDemonHelm;
public static Item armorDemonChestplate;
public static Item armorDemonLeggings;
public static Item armorDemonBoots;

//Dual input furnace

public static Block blockAngellicInfuserIdle;
public static Block blockAngellicInfuserActive;
public static final int guiIdAngelicInfuser = 1;

@EventHandler
public void PreInit(FMLPreInitializationEvent preEvent){

SatangelicaTab = new CreativeTabs("mymod") {
	@SideOnly(Side.CLIENT)
	public Item getTabIconItem() {
	return Item.getItemFromBlock(mymod.blockAltarCore);
	}
};
//blocks

blockAltarCore = new AltarCore(Material.rock).setBlockName("Altar Core");	
GameRegistry.registerBlock(blockAltarCore, "Altar Core");

//ores

oreAngellicOre = new AngellicOre(Material.rock).setBlockName("Angellic Ore");	
GameRegistry.registerBlock(oreAngellicOre, "Angellic Ore");
oreDemonicOre = new DemonicOre(Material.rock).setBlockName("Demonic Ore");	
GameRegistry.registerBlock(oreDemonicOre, "Demonic Ore");

//items	

itemInfusedStick  = new InfusedStick().setUnlocalizedName("Infused Stick"); 
GameRegistry.registerItem(itemInfusedStick, "Infused Stick");

//ingots
itemAngelicIngot = new AngelicIngot().setUnlocalizedName("Angelic Ingot");
GameRegistry.registerItem(itemAngelicIngot, "Angelic Ingot");

//dusts
itemChaosDust = new ChaosDust().setUnlocalizedName("Chaos Dust");
GameRegistry.registerItem(itemChaosDust, "Chaos Dust");
itemPowderedOrder = new PowderedOrder().setUnlocalizedName("Powdered Order");
GameRegistry.registerItem(itemPowderedOrder, "PowderedOrder");

//tools

itemAngelBlade = new AngelBlade(AngelMaterial).setUnlocalizedName("Angel Blade");
GameRegistry.registerItem(itemAngelBlade, "Angel Blade");
itemAngellicPickaxe = new AngellicPickaxe(AngelMaterial).setUnlocalizedName("Angellic Pickaxe");
GameRegistry.registerItem(itemAngellicPickaxe, "Angellic Pickaxe");
itemAngellicAxe = new AngellicAxe(AngelMaterial).setUnlocalizedName("Angellic Axe");
GameRegistry.registerItem(itemAngellicAxe, "Angellic Axe");
itemAngellicSpade = new AngellicSpade(AngelMaterial).setUnlocalizedName("Angellic Spade");
GameRegistry.registerItem(itemAngellicSpade, "Angellic Spade");
itemAngellicHoe = new AngellicHoe(AngelMaterial).setUnlocalizedName("Angellic Hoe");
GameRegistry.registerItem(itemAngellicHoe, "Angellic Hoe ");

itemDemonicMace = new DemonicMace(DemonMaterial).setUnlocalizedName("Demonic Mace");
GameRegistry.registerItem(itemDemonicMace, "Demonic Mace");
itemDemonicHoe = new DemonicHoe(DemonMaterial).setUnlocalizedName("Demonic Hoe");
GameRegistry.registerItem(itemDemonicHoe, "Demonic Hoe");
itemDemonicAxe = new DemonicAxe(DemonMaterial).setUnlocalizedName("Demonic Axe");
GameRegistry.registerItem(itemDemonicAxe, "Demonic Axe");
itemDemonicSpade = new DemonicSpade(DemonMaterial).setUnlocalizedName("Demonic Spade");
GameRegistry.registerItem(itemDemonicSpade, "Demonic Spade");
itemDemonicPickaxe = new DemonicPickaxe(DemonMaterial).setUnlocalizedName("Demonic Pickaxe");
GameRegistry.registerItem(itemDemonicPickaxe, "Demonic Pickaxe");

//armor

armorAngelHelm = new AngelArmor(AngelArmor, armorAngelHelmId, 0).setUnlocalizedName("Angel Helm"); 
GameRegistry.registerItem(armorAngelHelm, "Angel Helm");
armorAngelChestplate = new AngelArmor(AngelArmor, armorAngelChestplateId, 1).setUnlocalizedName("Angel Chestplate");
GameRegistry.registerItem(armorAngelChestplate, "Angel Chestplate");
armorAngelLeggings = new AngelArmor(AngelArmor, armorAngelLeggingsId, 2).setUnlocalizedName("Angel Leggings");
GameRegistry.registerItem(armorAngelLeggings, "Angel Leggings");
armorAngelBoots = new AngelArmor(AngelArmor, armorAngelBootsId, 3).setUnlocalizedName("Angel Boots"); 
GameRegistry.registerItem(armorAngelBoots, "Angel Boots");

armorDemonHelm = new DemonArmor(DemonArmor, armorDemonHelmId, 0).setUnlocalizedName("Demon Helm");
GameRegistry.registerItem(armorDemonHelm, "Demon Helm");
armorDemonChestplate = new DemonArmor(DemonArmor, armorDemonChestplateId, 1).setUnlocalizedName("Demon Chestplate");
GameRegistry.registerItem(armorDemonChestplate, "Demon Chestplate");
armorDemonLeggings = new DemonArmor(DemonArmor, armorDemonLeggingsId, 2).setUnlocalizedName("DemonLeggings");
GameRegistry.registerItem(armorDemonLeggings, "Demon Leggings");
armorDemonBoots = new DemonArmor(DemonArmor, armorDemonBootsId, 3).setUnlocalizedName("Demon Boots");
GameRegistry.registerItem(armorDemonBoots, "Demon Boots");

//Angelic Infuser

blockAngellicInfuserIdle = new AngellicInfuser(false).setBlockName("Angellic Infuser Idle").setCreativeTab(mymod.SatangelicaTab).setHardness(3.5F);
GameRegistry.registerBlock(blockAngellicInfuserIdle, "Angellic Infuser Idle");

blockAngellicInfuserActive = new AngellicInfuser(true).setBlockName("Angellic Infuser Active").setHardness(3.5F);
GameRegistry.registerBlock(blockAngellicInfuserActive, "Angellic Infuser Active");





//spawn



};

@EventHandler
public void Init(FMLInitializationEvent event){

//Gui Handler

FMLCommonHandler.instance().bus().register(new CraftingHandler());
NetworkRegistry.INSTANCE.registerGuiHandler(this, new GUIHandler());

GameRegistry.registerTileEntity(TileEntityAngellicInfuser.class, "AngellicInfuser");


//Recipes
GameRegistry.addRecipe(new ItemStack(blockAltarCore), new Object[]{"SIS", "SIS", "SIS", 'S', Blocks.stone, 'I', mymod.itemInfusedStick});
    GameRegistry.addRecipe(new ItemStack(itemInfusedStick), new Object []{ "CSO", "OSC", "CSO", 'C', mymod.itemChaosDust, 'S', Items.stick, 'O', mymod.itemPowderedOrder});


GameRegistry.addSmelting(oreAngellicOre, new ItemStack(itemPowderedOrder, 3), 5);
GameRegistry.addSmelting(oreDemonicOre, new ItemStack(itemChaosDust, 3), 5);

GameRegistry.registerTileEntity(TileEntityAngellicInfuser.class, "TEAngellicInfuser");


}


@EventHandler
public void PostInit(FMLPostInitializationEvent postEvent){

}
}

 

Block Class

 

package net.mymod.mod.blocks;

import java.util.Random;

import cpw.mods.fml.common.network.internal.FMLNetworkHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
import net.mymod.mod.mymod;
import net.mymod.mod.TileEntity.TileEntityAngellicInfuser;

public class AngellicInfuser extends BlockContainer {

private Random rand;
private final boolean isActive;
private static boolean keepInventory = true;

@SideOnly(Side.CLIENT)
private IIcon iconFront;

public AngellicInfuser(boolean blockState) {
	super(Material.iron);
	rand = new Random();
	isActive = blockState;

}

@SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister iconRegister) {
	this.blockIcon = iconRegister.registerIcon(mymod.modid + ":" + "Angellic Infuser Side");
	this.iconFront = iconRegister.registerIcon(mymod.modid + ":" + (this.isActive ? "Angellic Infuser Front Active" : "Angellic Infuser Front Idle"));
}

@SideOnly(Side.CLIENT)
public IIcon getIcon(int side, int metadata) {
	return metadata == 0 && side == 3 ? this.iconFront : (side == metadata ? this.iconFront : this.blockIcon);
}

public void onBlockAdded(World world, int x, int y, int z) {
	super.onBlockAdded(world, x, y, z);
	this.setDefaultDirection(world, x, y, z);
}

    private void setDefaultDirection(World world, int x, int y, int z)
    {
    	if(!world.isRemote){
		Block block1 = world.getBlock(x, y, z - 1);
		Block block2 = world.getBlock(x, y, z + 1);
		Block block3 = world.getBlock(x - 1, y, z);
		Block block4 = world.getBlock(x + 1, y, z);

		byte b0 = 3;

		if(block1.func_149730_j() && !block2.func_149730_j()){
			b0 = 3;
		}

		if(block2.func_149730_j() && !block1.func_149730_j()){
			b0 = 2;
		}

		if(block3.func_149730_j() && !block4.func_149730_j()){
			b0 = 5;
		}

		if(block4.func_149730_j() && !block3.func_149730_j()){
			b0 = 4;
		}

		world.setBlockMetadataWithNotify(x, y, x, b0, 2);
	}
    }
    
    public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entityPlayer, ItemStack itemstack) {
    	int i = MathHelper.floor_double((double)(entityPlayer.rotationYaw * 4.0F / 360F) + 0.5D) & 3;
    	
    	if (i == 0) {
    		world.setBlockMetadataWithNotify(x, y, z, 2, 2);
    	}
    	
    	if (i == 1) {
    		world.setBlockMetadataWithNotify(x, y, z, 5, 2);
    	}
    	
    	if (i == 2) {
    		world.setBlockMetadataWithNotify(x, y, z, 3, 2);
    	}
    	
    	if (i == 3) {
    		world.setBlockMetadataWithNotify(x, y, z, 4, 2);
    	}
    	
    	if(itemstack.hasDisplayName()) {
    		//((TileEntityIngotMasher)world.getTileEntity(x, y, z)).setCustomName(itemstack.getDisplayName());
    	}
    }
    
    public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) {
    	if (world.isRemote) {
    		return true;
    	}else if (!player.isSneaking()) {
    		TileEntityAngellicInfuser entity = (TileEntityAngellicInfuser) world.getTileEntity(x, y, z);
    		if (entity != null) {
    			FMLNetworkHandler.openGui(player, mymod.instance, mymod.guiIdAngelicInfuser, world, x, y, z);
    		}
    		return true;
    	}else{
    		return false;
    	}
    }
    
@Override
public TileEntity createNewTileEntity(World var1, int var2) {
	return new TileEntityAngellicInfuser();
}

public static void updateBlockState(boolean isMashing, World world, int xCoord, int yCoord, int zCoord) {

	int i = world.getBlockMetadata(xCoord, yCoord, zCoord);
	TileEntity entity = world.getTileEntity(xCoord, yCoord, zCoord);
	keepInventory = true;

	if (isMashing) {
		world.setBlock(xCoord, yCoord, zCoord, mymod.blockAngellicInfuserActive);
	}else{
		world.setBlock(xCoord, yCoord, zCoord, mymod.blockAngellicInfuserIdle);
	}

	keepInventory = false;
	world.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, i, 2);

	if (entity != null) {
		entity.validate();
		world.setTileEntity(xCoord, yCoord, zCoord, entity);
	}
}
}

 

Container Class

 

package net.mymod.mod.container;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.ICrafting;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.FurnaceRecipes;
import net.minecraft.tileentity.TileEntityFurnace;
import net.mymod.mod.slot.SlotAngellicInfuser;
import net.mymod.mod.TileEntity.TileEntityAngellicInfuser;

public class ContainerAngellicInfuser extends Container {

private TileEntityAngellicInfuser infuser;
private int dualCookTime;
private int dualPower;
private int lastItemBurnTime;

public ContainerAngellicInfuser(InventoryPlayer invPlayer, TileEntityAngellicInfuser teAngellicInfuser) {
	dualCookTime = 0;
	dualPower = 0;
	lastItemBurnTime = 0;

	infuser = teAngellicInfuser;

	this.addSlotToContainer(new Slot(teAngellicInfuser, 0, 49, 35));
	this.addSlotToContainer(new Slot(teAngellicInfuser, 1, 49, 17));
	this.addSlotToContainer(new Slot(teAngellicInfuser, 2, 7, 40));
	this.addSlotToContainer(new SlotAngellicInfuser(invPlayer.player, teAngellicInfuser, 3, 143, 34));
	this.addSlotToContainer(new Slot(teAngellicInfuser, 4, 49, 53));
	this.addSlotToContainer(new Slot(teAngellicInfuser, 5, 67, 17));
	this.addSlotToContainer(new Slot(teAngellicInfuser, 6, 67, 40));
	this.addSlotToContainer(new Slot(teAngellicInfuser, 7, 67, 53));
	this.addSlotToContainer(new Slot(teAngellicInfuser, 8, 85, 17));
	this.addSlotToContainer(new Slot(teAngellicInfuser, 9, 85, 40));
	this.addSlotToContainer(new Slot(teAngellicInfuser, 10, 85, 53));

	//Inventory
	for(int i = 0; i < 3; i++) {
		for(int j = 0; j < 9; j++) {
			this.addSlotToContainer(new Slot(invPlayer, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
		}
	}

	//ActionBar
	for(int i = 0; i < 9; i++) {
		this.addSlotToContainer(new Slot(invPlayer, i, 8 + i * 18, 142));
	}
}

public void addCraftingToCrafters (ICrafting crafting) {
	super.addCraftingToCrafters(crafting);
	crafting.sendProgressBarUpdate(this, 0, this.infuser.dualCookTime);
	crafting.sendProgressBarUpdate(this, 1, this.infuser.dualPower);
}

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 == 2)
            {
                if (!this.mergeItemStack(itemstack1, 3, 39, true))
                {
                    return null;
                }

                slot.onSlotChange(itemstack1, itemstack);
            }
            else if (par2 != 1 && par2 != 0)
            {
                if (FurnaceRecipes.smelting().getSmeltingResult(itemstack1) != null)
                {
                    if (!this.mergeItemStack(itemstack1, 0, 1, false))
                    {
                        return null;
                    }
                }
                else if (TileEntityFurnace.isItemFuel(itemstack1))
                {
                    if (!this.mergeItemStack(itemstack1, 1, 2, false))
                    {
                        return null;
                    }
                }
                else if (par2 >= 3 && par2 < 30)
                {
                    if (!this.mergeItemStack(itemstack1, 30, 39, false))
                    {
                        return null;
                    }
                }
                else if (par2 >= 30 && par2 < 39 && !this.mergeItemStack(itemstack1, 3, 30, false))
                {
                    return null;
                }
            }
            else if (!this.mergeItemStack(itemstack1, 3, 39, 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 canInteractWith(EntityPlayer player) {
	return infuser.isUseableByPlayer(player);
}
}

 

Gui

 

package net.mymod.mod.gui;

import org.lwjgl.opengl.GL11;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.util.ResourceLocation;
import net.mymod.mod.mymod;
import net.mymod.mod.container.ContainerAngellicInfuser;
import net.mymod.mod.TileEntity.TileEntityAngellicInfuser;

public class guiAngelicInfuser extends GuiContainer {

public ResourceLocation texture = new ResourceLocation(mymod.modid + ":" + "/textures/gui/Angelic Infuser GUI.png");
public TileEntityAngellicInfuser AngellicInfuser;

public guiAngelicInfuser(InventoryPlayer invPlayer, TileEntityAngellicInfuser teAngellicInfuser) {
	super(new ContainerAngellicInfuser(invPlayer, teAngellicInfuser));
	AngellicInfuser = teAngellicInfuser;

	this.xSize = 176;
	this.ySize = 166;
}

protected void drawGuiContainerForegroundLayer(int i, int j) {
	String name = this.AngellicInfuser.hasCustomInventoryName() ? this.AngellicInfuser.getInventoryName() : I18n.format(this.AngellicInfuser.getInventoryName());
	this.fontRendererObj.drawString(name, this.xSize / 2 - this.fontRendererObj.getStringWidth(name) / 2, 6, 4210752);
	this.fontRendererObj.drawString(I18n.format("container.ContainerAngellicInfuser"), 8, this.ySize - 96 + 5, 4210752);
}

@Override
    protected void drawGuiContainerBackgroundLayer(float f, int i, int j)
    {
        GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
        Minecraft.getMinecraft().getTextureManager().bindTexture(texture);
        drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize);

        if (AngellicInfuser.hasPower())
        {
            int i1 = AngellicInfuser.getPowerRemainingScaled(45);
            drawTexturedModalRect(guiLeft + 8, guiTop + 53 - i1, 176, 62 - i1, 16, i1);
        }

        int i1 = AngellicInfuser.getMasherProgressScaled(24);
        drawTexturedModalRect(guiLeft + 79, guiTop + 34, 176, 0, i1 + 1, 16);
    }

}

 

Slot

 

package net.mymod.mod.slot;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.mymod.mod.TileEntity.TileEntityAngellicInfuser;

public class SlotAngellicInfuser extends Slot {

public SlotAngellicInfuser(EntityPlayer player, IInventory iiventory, int i, int j, int k) {
	super(iiventory, i, j, k);
	// TODO Auto-generated constructor stub
}



}

 

Tile Entity

 

package net.mymod.mod.TileEntity;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntity;
import net.mymod.mod.mymod;
import net.mymod.mod.blocks.AngellicInfuser;
import net.mymod.mod.crafting.AngellicInfuserRecipes;

public class TileEntityAngellicInfuser extends TileEntity implements ISidedInventory {

private ItemStack slots[];

public int dualPower;
public int dualCookTime;
public static final int maxPower = 10000;
public static final int infusingSpeed = 100;

private static final int[] slots_top = new int[] {0, 1};
private static final int[] slots_bottom = new int[] {3};
private static final int[] slots_side = new int[] {2};

private String customName;

public TileEntityAngellicInfuser() {
	slots = new ItemStack[4];
}

@Override
public int getSizeInventory() {
	return slots.length;
}

@Override
public ItemStack getStackInSlot(int i) {
	return slots[i];
}

@Override
public ItemStack getStackInSlotOnClosing(int i) {
	if (slots[i] != null) {
		ItemStack itemstack = slots[i];
		slots[i] = null;
		return itemstack;
	}else{
		return null;
	}
}

@Override
public void setInventorySlotContents(int i, ItemStack itemstack) {
	slots[i] = itemstack;
	if (itemstack != null && itemstack.stackSize > getInventoryStackLimit()) {
		itemstack.stackSize = getInventoryStackLimit();
	}
}

@Override
public int[] getAccessibleSlotsFromSide(int i) {
	return i == 0 ? slots_bottom : (i == 1 ? slots_top : slots_side);
}




@Override
public int getInventoryStackLimit() {
	return 64;
}

@Override
public boolean isUseableByPlayer(EntityPlayer player) {
	if (worldObj.getTileEntity(xCoord, yCoord, zCoord) != this) {
		return false;
	}else{
		return player.getDistanceSq((double)xCoord + 0.5D, (double)yCoord + 0.5D, (double)zCoord + 0.5D) <= 64;
	}
}

public void openInventory() {}
public void closeInventory() {}

@Override
public boolean isItemValidForSlot(int i, ItemStack itemstack) {
	return i == 2 ? false : (i == 1 ? hasItemPower(itemstack) : true);
}

public boolean hasItemPower(ItemStack itemstack) {
	return getItemPower(itemstack) > 0;
}

private static int getItemPower (ItemStack itemstack) {
	if (itemstack == null) {
		return 0;
	}else{
		Item item = itemstack.getItem();

		if (item == mymod.itemPowderedOrder) return 50;

		return 0;
	}
}

public ItemStack decrStackSize(int i, int j) {
	if (slots[i] != null) {
		if (slots[i].stackSize <= j) {
			ItemStack itemstack = slots[i];
			slots[i] = null;
			return itemstack;
		}

		ItemStack itemstack1 = slots[i].splitStack(j);

		if (slots[i].stackSize == 0) {
			slots[i] = null;
		}

		return itemstack1;
	}else{
		return null;
	}
}

public void readFromNBT (NBTTagCompound nbt) {
	super.readFromNBT(nbt);
	NBTTagList list = nbt.getTagList("Items", 10);
	slots = new ItemStack[getSizeInventory()];

	for (int i = 0; i < list.tagCount(); i++) {
		NBTTagCompound nbt1 = (NBTTagCompound)list.getCompoundTagAt(i);
		byte b0 = nbt1.getByte("Slot");

		if (b0 >= 0 && b0 < slots.length) {
			slots[b0] = ItemStack.loadItemStackFromNBT(nbt1);
		}
	}

	dualPower = nbt.getShort("PowerTime");
	dualCookTime = nbt.getShort("CookTime");
}

public void writeToNBT(NBTTagCompound nbt) {
	super.writeToNBT(nbt);
	nbt.setShort("PowerTime", (short)dualPower);
	nbt.setShort("CookTime", (short)dualCookTime);
	NBTTagList list = new NBTTagList();

	for (int i = 0; i < slots.length; i++) {
		if (slots[i] != null) {
			NBTTagCompound nbt1 = new NBTTagCompound();
			nbt1.setByte("Slot", (byte)i);
			slots[i].writeToNBT(nbt1);
			list.appendTag(nbt1);
		}
	}

	nbt.setTag("Items", list);
}


@Override
public String getInventoryName() {
	return "container.AngellicInfuser";
}

@Override
public boolean canInsertItem(int var1, ItemStack itemstack, int var3) {
	return this.isItemValidForSlot(var1, itemstack);
}

@Override
public boolean canExtractItem(int i, ItemStack itemstack, int j) {
	return j != 0 || i != 1 || itemstack.getItem() == Items.bucket;
}

@Override
public boolean hasCustomInventoryName() {
	return this.customName != null && this.customName.length() > 0;
}

public int getMasherProgressScaled(int i) {
	return (dualCookTime * i) / this.infusingSpeed;
}

public int getPowerRemainingScaled(int i) {
	return (dualPower * i) / maxPower;
}

private boolean canMash() {

	if (slots[0] == null || slots[1] == null) {
		return false;
	}

	ItemStack itemstack = AngellicInfuserRecipes.getMashingResult(slots[0].getItem(), slots[1].getItem());

	if (itemstack == null) {
		return false;
	}

	if (slots[3] == null) {
		return true;
	}

	if (!slots[3].isItemEqual(itemstack)) {
		return false;
	}

	if (slots[3].stackSize < getInventoryStackLimit() && slots[3].stackSize < slots[3].getMaxStackSize()) {
		return true;
	}else{
		return slots[3].stackSize < itemstack.getMaxStackSize();
	}
}

private void mashItem() {
	if (canMash()) {
		ItemStack itemstack = AngellicInfuserRecipes.getMashingResult(slots[0].getItem(), slots[1].getItem());

		if (slots[3] == null) {
			slots[3] = itemstack.copy();
		}else if (slots[3].isItemEqual(itemstack)) {
			slots[3].stackSize += itemstack.stackSize;
		}

		for (int i = 0; i < 2; i++) {
			if (slots[i].stackSize <= 0) {
				slots[i] = new ItemStack(slots[i].getItem().setFull3D());
			}else{
				slots[i].stackSize--;
			}

			if (slots[i].stackSize <= 0){
				slots[i] = null;
			}
		}
	}
}

public boolean hasPower() {
	return dualPower > 0;
}

public boolean isMashing() {
	return this.dualCookTime > 0;
}

public void updateEntity() {
	boolean flag = this.hasPower();
	boolean flag1= false;

	if(hasPower() && this.isMashing()) {
		this.dualPower--;
	}

	if(!worldObj.isRemote) {
		if (this.hasItemPower(this.slots[2]) && this.dualPower < (this.maxPower - this.getItemPower(this.slots[2]))) {
			this.dualPower += getItemPower(this.slots[2]);

			if(this.slots[2] != null) {
				flag1 = true;

				this.slots[2].stackSize--;

				if(this.slots[2].stackSize == 0) {
					this.slots[2] = this.slots[2].getItem().getContainerItem(this.slots[2]);
				}
			}
		}

		if (hasPower() && canMash()) {
			dualCookTime++;

			if (this.dualCookTime == this.infusingSpeed) {
				this.dualCookTime = 0;
				this.mashItem();
				flag1 = true;
			}
		}else{
			dualCookTime = 0;
		}

		if (flag != this.isMashing()) {
			flag1 = true;
			AngellicInfuser.updateBlockState(this.isMashing(), this.worldObj, this.xCoord, this.yCoord, this.zCoord);
		}
	}

	if (flag1) {
		this.markDirty();
	}
    }

}

 

Thanks if anyone can help.

Link to comment
Share on other sites

~bump~

sorry if it seems like i'm nagging, but i really dont know how to fix it and need help as my entire mod revolves around this and another slightly different version of the same thing. I would really appreciate anyone who can fix this.

 

Link to comment
Share on other sites

public TileEntityAngellicInfuser() {
	slots = new ItemStack[4];
}

 

this.addSlotToContainer(new Slot(teAngellicInfuser, 0, 49, 35));
	this.addSlotToContainer(new Slot(teAngellicInfuser, 1, 49, 17));
	this.addSlotToContainer(new Slot(teAngellicInfuser, 2, 7, 40));
	this.addSlotToContainer(new SlotAngellicInfuser(invPlayer.player, teAngellicInfuser, 3, 143, 34)); //Is this intentional? looks broken to me.
	this.addSlotToContainer(new Slot(teAngellicInfuser, 4, 49, 53));
	this.addSlotToContainer(new Slot(teAngellicInfuser, 5, 67, 17));
	this.addSlotToContainer(new Slot(teAngellicInfuser, 6, 67, 40));
	this.addSlotToContainer(new Slot(teAngellicInfuser, 7, 67, 53));
	this.addSlotToContainer(new Slot(teAngellicInfuser, 8, 85, 17));
	this.addSlotToContainer(new Slot(teAngellicInfuser, 9, 85, 40));
	this.addSlotToContainer(new Slot(teAngellicInfuser, 10, 85, 53));

 

well the issue here is your container. In your tileEntity you setup 4 slots (0-3 this is done in the constructor posted first in this reply) then in your container you try to add 11 slots (0-10) in which you will get a crash once it reaches "this.addSlotToContainer(new Slot(teAngellicInfuser, 4, 49, 53));" that is if the line before it does crash it hard (placed comment next to offending code)

 

my guess is that it's crashing because index out of array. try adding 11 slots to your tileEntity instead of 4 and see how it goes.

Link to comment
Share on other sites

thanks,  but i still dont know how to make the recipes, i managed it for when i had 2 slots (thats why i had slot 3 as that) but when i did get into the gui,  there was a line down part of the gui and i cannot see why. Additionally, i still need the progress bar and the fuel bar to show.

 

http://s1273.photobucket.com/user/edy22174/library/?view=recent&page=1

both images are there

 

i know its wrong cause there is an error, but i dont know how to solve it, here is what i tried.

package net.mymod.mod.crafting;

import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.mymod.mod.mymod;

public class AngellicInfuserRecipes {

public AngellicInfuserRecipes() {

}

public static ItemStack getMashingResult(Item item, Item item2 item4 item5 item6 item7 item8 item9 item10) {
	return getOutput(item, item2, item4, item5, item6, item7, item8, item9, item10);
}

public static ItemStack getOutput(Item item, Item item2 item4 item5 item6 item7 item8 item9 item10) {
	//Recipe One
	if (item == mymod.itemPowderedOrder && item2 == mymod.itemPowderedOrder && item4 == mymod.itemPowderedOrder && item5 == Items.iron_ingot && item6 == Items.diamond && item7 == Items.iron_ingot && item8 == mymod.PowderedOrder && item9 == mymod.PowderedOrder && item10 == mymod.PowderedOrder) {
}
		return new ItemStack(mymod.itemAngelicIngot);
	return null;
}

}

 

(i should've seen that fix, it seems so simple now that its done)

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.