Finish on Iron furnace

Added Jei support to Iron Furnace
This commit is contained in:
gigabit101 2016-03-06 19:59:39 +00:00
parent 961e821402
commit 90f5d77a41
9 changed files with 493 additions and 6 deletions

View file

@ -9,6 +9,7 @@ import techreborn.Core;
import techreborn.client.GuiHandler;
import techreborn.client.TechRebornCreativeTab;
import techreborn.tiles.TileAlloyFurnace;
import techreborn.tiles.TileIronFurnace;
public class BlockIronFurnace extends BlockMachineBase implements IRotationTexture {
@ -20,13 +21,13 @@ public class BlockIronFurnace extends BlockMachineBase implements IRotationTextu
@Override
public TileEntity createNewTileEntity(World world, int p_149915_2_) {
return null;
return new TileIronFurnace();
}
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) {
// if (!player.isSneaking())
// player.openGui(Core.INSTANCE, GuiHandler.alloyFurnaceID, world, x, y, z);
if (!player.isSneaking())
player.openGui(Core.INSTANCE, GuiHandler.ironFurnace, world, x, y, z);
return true;
}

View file

@ -28,6 +28,7 @@ import techreborn.client.container.ContainerImplosionCompressor;
import techreborn.client.container.ContainerIndustrialElectrolyzer;
import techreborn.client.container.ContainerIndustrialGrinder;
import techreborn.client.container.ContainerIndustrialSawmill;
import techreborn.client.container.ContainerIronFurnace;
import techreborn.client.container.ContainerLesu;
import techreborn.client.container.ContainerMatterFabricator;
import techreborn.client.container.ContainerQuantumChest;
@ -60,6 +61,7 @@ import techreborn.client.gui.GuiImplosionCompressor;
import techreborn.client.gui.GuiIndustrialElectrolyzer;
import techreborn.client.gui.GuiIndustrialGrinder;
import techreborn.client.gui.GuiIndustrialSawmill;
import techreborn.client.gui.GuiIronFurnace;
import techreborn.client.gui.GuiLesu;
import techreborn.client.gui.GuiMatterFabricator;
import techreborn.client.gui.GuiQuantumChest;
@ -83,6 +85,7 @@ import techreborn.tiles.TileImplosionCompressor;
import techreborn.tiles.TileIndustrialElectrolyzer;
import techreborn.tiles.TileIndustrialGrinder;
import techreborn.tiles.TileIndustrialSawmill;
import techreborn.tiles.TileIronFurnace;
import techreborn.tiles.TileMatterFabricator;
import techreborn.tiles.TileQuantumChest;
import techreborn.tiles.TileQuantumTank;
@ -136,6 +139,7 @@ public class GuiHandler implements IGuiHandler {
public static final int extractorID = 33;
public static final int compressorID = 34;
public static final int electricFurnaceID = 35;
public static final int ironFurnace = 36;
@Override
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
@ -226,9 +230,9 @@ public class GuiHandler implements IGuiHandler {
return new ContainerCompressor((TileCompressor) world.getTileEntity(new BlockPos(x, y, z)), player);
}else if (ID == electricFurnaceID) {
return new ContainerElectricFurnace((TileElectricFurnace) world.getTileEntity(new BlockPos(x, y, z)), player);
}else if (ID == ironFurnace) {
return new ContainerIronFurnace((TileIronFurnace) world.getTileEntity(new BlockPos(x, y, z)), player);
}
return null;
}
@ -322,7 +326,10 @@ public class GuiHandler implements IGuiHandler {
return new GuiCompressor(player, (TileCompressor) world.getTileEntity(new BlockPos(x, y, z)));
}else if (ID == electricFurnaceID) {
return new GuiElectricFurnace(player, (TileElectricFurnace) world.getTileEntity(new BlockPos(x, y, z)));
}else if (ID == ironFurnace) {
return new GuiIronFurnace(player, (TileIronFurnace) world.getTileEntity(new BlockPos(x, y, z)));
}
return null;
}
}

View file

@ -0,0 +1,58 @@
package techreborn.client.container;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Slot;
import net.minecraft.inventory.SlotFurnaceFuel;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import reborncore.client.gui.SlotOutput;
import reborncore.common.container.RebornContainer;
import techreborn.tiles.TileIronFurnace;
public class ContainerIronFurnace extends RebornContainer {
EntityPlayer player;
TileIronFurnace tile;
public int connectionStatus;
public ContainerIronFurnace(TileIronFurnace tileGrinder, EntityPlayer player) {
super();
tile = tileGrinder;
this.player = player;
// input
this.addSlotToContainer(new Slot(tileGrinder.inventory, 0, 56, 17));
this.addSlotToContainer(new SlotOutput(tileGrinder.inventory, 1, 116, 34));
//Fuel
this.addSlotToContainer(new SlotFurnaceFuel(tileGrinder.inventory, 2, 56, 53));
int i;
for (i = 0; i < 3; ++i) {
for (int j = 0; j < 9; ++j) {
this.addSlotToContainer(new Slot(player.inventory, j + i * 9
+ 9, 8 + j * 18, 84 + i * 18));
}
}
for (i = 0; i < 9; ++i) {
this.addSlotToContainer(new Slot(player.inventory, i, 8 + i * 18,
142));
}
}
@Override
public boolean canInteractWith(EntityPlayer player) {
return true;
}
@SideOnly(Side.CLIENT)
@Override
public void updateProgressBar(int id, int value) {
if (id == 10) {
this.connectionStatus = value;
}
}
}

View file

@ -0,0 +1,56 @@
package techreborn.client.gui;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector;
import techreborn.client.container.ContainerElectricFurnace;
import techreborn.client.container.ContainerIronFurnace;
import techreborn.tiles.TileIronFurnace;
import techreborn.tiles.teir1.TileElectricFurnace;
public class GuiIronFurnace extends GuiContainer {
public static final ResourceLocation texture = new ResourceLocation("minecraft", "textures/gui/container/furnace.png");
TileIronFurnace furnace;
ContainerIronFurnace containerGrinder;
public GuiIronFurnace(EntityPlayer player, TileIronFurnace tilegrinder) {
super(new ContainerIronFurnace(tilegrinder, player));
this.xSize = 176;
this.ySize = 167;
furnace = tilegrinder;
containerGrinder = (ContainerIronFurnace) this.inventorySlots;
}
@Override
protected void drawGuiContainerBackgroundLayer(float p_146976_1_, int p_146976_2_, int p_146976_3_) {
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
this.mc.getTextureManager().bindTexture(texture);
int k = (this.width - this.xSize) / 2;
int l = (this.height - this.ySize) / 2;
this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize);
int j = 0;
j = furnace.gaugeProgressScaled(24);
if (j > 0) {
this.drawTexturedModalRect(k + 78, l + 35, 176, 14, j + 1, 16);
}
j = furnace.gaugeFuelScaled(12);
if (j > 0) {
this.drawTexturedModalRect(k + 57, l + 36 + 12 - j, 176, 12 - j, 14, j + 2);
}
}
protected void drawGuiContainerForegroundLayer(int p_146979_1_, int p_146979_2_) {
String name = StatCollector.translateToLocal("tile.techreborn.ironfurnace.name");
this.fontRendererObj.drawString(name, this.xSize / 2 - this.fontRendererObj.getStringWidth(name) / 2, 6, 4210752);
this.fontRendererObj.drawString(I18n.format("container.inventory", new Object[0]), 8, this.ySize - 96 + 2, 4210752);
}
}

View file

@ -48,6 +48,7 @@ import techreborn.client.gui.GuiImplosionCompressor;
import techreborn.client.gui.GuiIndustrialElectrolyzer;
import techreborn.client.gui.GuiIndustrialGrinder;
import techreborn.client.gui.GuiIndustrialSawmill;
import techreborn.client.gui.GuiIronFurnace;
import techreborn.client.gui.GuiRollingMachine;
import techreborn.client.gui.GuiVacuumFreezer;
import techreborn.compat.jei.alloySmelter.AlloySmelterRecipeCategory;
@ -158,6 +159,7 @@ public class TechRebornJeiPlugin extends BlankModPlugin {
registry.addRecipeClickArea(GuiGrinder.class, 78, 36, 24, 16, RecipeCategoryUids.GRINDER);
registry.addRecipeClickArea(GuiExtractor.class, 78, 36, 24, 16, RecipeCategoryUids.EXTRACTOR);
registry.addRecipeClickArea(GuiCompressor.class, 78, 36, 24, 16, RecipeCategoryUids.COMPRESSOR);
registry.addRecipeClickArea(GuiIronFurnace.class, 78, 36, 24, 16, VanillaRecipeCategoryUid.SMELTING, VanillaRecipeCategoryUid.FUEL);
IRecipeTransferRegistry recipeTransferRegistry = registry.getRecipeTransferRegistry();

View file

@ -368,7 +368,7 @@ public class ModBlocks {
ironFurnace = new BlockIronFurnace();
GameRegistry.registerBlock(ironFurnace, "ironfurnace");
GameRegistry.registerTileEntity(TileIronFurnace.class, "TileIronFurnaceTR");
registerOreDict();
Core.logHelper.info("TechReborns Blocks Loaded");
}

View file

@ -198,6 +198,15 @@ public class ModRecipes {
'A', "ingot" + name.substring(0, 1).toUpperCase() + name.substring(1));
}
CraftingHelper.addShapedOreRecipe(new ItemStack(ModBlocks.ironFurnace),
"III", "IXI", "III",
'I', "ingotIron");
CraftingHelper.addShapedOreRecipe(new ItemStack(ModBlocks.ironFurnace),
"XIX", "IXI", "IFI",
'I', "ingotIron",
'F', Blocks.furnace);
CraftingHelper.addShapedOreRecipe(ItemParts.getPartByName("electronicCircuit"),
"WWW", "SRS", "WWW",
'R', ItemIngots.getIngotByName("refinediron"),

View file

@ -0,0 +1,353 @@
package techreborn.tiles;
import ic2.api.tile.IWrenchable;
import net.minecraft.block.Block;
import net.minecraft.block.BlockFurnace;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemHoe;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemSword;
import net.minecraft.item.ItemTool;
import net.minecraft.item.crafting.FurnaceRecipes;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.IChatComponent;
import net.minecraft.util.MathHelper;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import reborncore.common.blocks.BlockMachineBase;
import reborncore.common.tile.TileMachineBase;
import reborncore.common.util.Inventory;
import reborncore.common.util.ItemUtils;
import techreborn.api.recipe.IBaseRecipeType;
import techreborn.api.recipe.RecipeHandler;
import techreborn.init.ModBlocks;
import techreborn.lib.Reference;
public class TileIronFurnace extends TileMachineBase implements IInventory {
public int tickTime;
public Inventory inventory = new Inventory(3, "TileIronFurnace", 64, this);
int input1 = 0;
int output = 1;
int fuelslot = 2;
boolean active = false;
public int fuel;
public int fuelGague;
public int progress;
public int fuelScale = 200;
byte direction;
private static final int[] slots_top = new int[] { 0 };
private static final int[] slots_bottom = new int[] { 2, 1 };
private static final int[] slots_sides = new int[] { 1 };
public int gaugeProgressScaled (int scale)
{
return (progress * scale) / fuelScale;
}
public int gaugeFuelScaled (int scale)
{
if (fuelGague == 0)
{
fuelGague = fuel;
if (fuelGague == 0)
{
fuelGague = fuelScale;
}
}
return (fuel * scale) / fuelGague;
}
@Override
public void updateEntity ()
{
boolean burning = isBurning();
boolean updateInventory = false;
if (fuel <= 0 && canSmelt())
{
fuel = fuelGague = (int) (getItemBurnTime(getStackInSlot(fuelslot)));
if (fuel > 0)
{
if (getStackInSlot(fuelslot).getItem().hasContainerItem()) // Fuel slot
{
setInventorySlotContents(fuelslot, new ItemStack(getStackInSlot(fuelslot).getItem().getContainerItem()));
}
else if(getStackInSlot(fuelslot).stackSize > 1)
{
decrStackSize(fuelslot, 1);
}
else if (getStackInSlot(fuelslot).stackSize == 1)
{
setInventorySlotContents(fuelslot, null);
}
updateInventory = true;
}
}
if (isBurning() && canSmelt())
{
updateState();
progress++;
if (progress >= fuelScale)
{
progress = 0;
cookItems();
updateInventory = true;
}
}
else
{
progress = 0;
updateState();
}
if (fuel > 0)
{
fuel--;
}
if (burning != isBurning())
{
this.active = true;
updateInventory = true;
}
if (updateInventory)
{
markDirty();
}
}
public void cookItems ()
{
if (this.canSmelt())
{
ItemStack itemstack = FurnaceRecipes.instance().getSmeltingResult(getStackInSlot(input1));
if (getStackInSlot(output) == null)
{
setInventorySlotContents(output, itemstack.copy());
}
else if (getStackInSlot(output).isItemEqual(itemstack))
{
getStackInSlot(output).stackSize += itemstack.stackSize;
}
if(getStackInSlot(input1).stackSize > 1)
{
this.decrStackSize(input1, 1);
}
else
{
setInventorySlotContents(input1, null);
}
}
}
public boolean canSmelt ()
{
if (getStackInSlot(input1) == null)
{
return false;
}
else
{
ItemStack itemstack = FurnaceRecipes.instance().getSmeltingResult(getStackInSlot(input1));
if (itemstack == null)
return false;
if (getStackInSlot(output) == null)
return true;
if (!getStackInSlot(output).isItemEqual(itemstack))
return false;
int result = getStackInSlot(output).stackSize + itemstack.stackSize;
return (result <= getInventoryStackLimit() && result <= itemstack.getMaxStackSize());
}
}
public boolean isBurning ()
{
return fuel > 0;
}
public ItemStack getResultFor (ItemStack stack)
{
ItemStack result = FurnaceRecipes.instance().getSmeltingResult(stack);
if (result != null)
{
return result.copy();
}
return null;
}
public static int getItemBurnTime (ItemStack stack)
{
if (stack == null)
{
return 0;
}
else
{
Item item = stack.getItem();
if (stack.getItem() instanceof ItemBlock && Block.getBlockFromItem(item) != null)
{
Block block = Block.getBlockFromItem(item);
if (block == Blocks.wooden_slab)
{
return 150;
}
if (block == Blocks.log)
{
return 1200;
}
if (block.getMaterial() == Material.wood)
{
return 300;
}
if (block == Blocks.coal_block)
{
return 16000;
}
}
if (item instanceof ItemTool && ((ItemTool) item).getToolMaterialName().equals("WOOD"))
return 200;
if (item instanceof ItemSword && ((ItemSword) item).getToolMaterialName().equals("WOOD"))
return 200;
if (item instanceof ItemHoe && ((ItemHoe) item).getMaterialName().equals("WOOD"))
return 200;
if (item == Items.stick)
return 100;
if (item == Items.coal)
return 1600;
if (item == Items.lava_bucket)
return 20000;
if (item == new ItemStack(Blocks.sapling).getItem())
return 100;
if (item == Items.blaze_rod)
return 2400;
return GameRegistry.getFuelValue(stack);
}
}
public void updateState(){
IBlockState blockState = worldObj.getBlockState(pos);
if(blockState.getBlock() instanceof BlockMachineBase){
BlockMachineBase blockMachineBase = (BlockMachineBase) blockState.getBlock();
if(blockState.getValue(BlockMachineBase.ACTIVE) != progress > 0)
blockMachineBase.setActive(progress > 0, worldObj, pos);
}
}
@Override
public void readFromNBT(NBTTagCompound tagCompound) {
super.readFromNBT(tagCompound);
inventory.readFromNBT(tagCompound);
}
@Override
public void writeToNBT(NBTTagCompound tagCompound) {
super.writeToNBT(tagCompound);
inventory.writeToNBT(tagCompound);
}
@Override
public int getSizeInventory() {
return inventory.getSizeInventory();
}
@Override
public ItemStack getStackInSlot(int slot) {
return inventory.getStackInSlot(slot);
}
@Override
public ItemStack decrStackSize(int slot, int amount) {
return inventory.decrStackSize(slot, amount);
}
@Override
public ItemStack removeStackFromSlot(int slot) {
return inventory.removeStackFromSlot(slot);
}
@Override
public void setInventorySlotContents(int slot, ItemStack stack) {
inventory.setInventorySlotContents(slot, stack);
}
@Override
public int getInventoryStackLimit() {
return inventory.getInventoryStackLimit();
}
@Override
public boolean isUseableByPlayer(EntityPlayer player) {
return inventory.isUseableByPlayer(player);
}
@Override
public boolean isItemValidForSlot(int slot, ItemStack stack) {
return inventory.isItemValidForSlot(slot, stack);
}
@Override
public void openInventory(EntityPlayer player) {
inventory.openInventory(player);
}
@Override
public void closeInventory(EntityPlayer player) {
inventory.closeInventory(player);
}
@Override
public int getField(int id) {
return inventory.getField(id);
}
@Override
public void setField(int id, int value) {
inventory.setField(id, value);
}
@Override
public int getFieldCount() {
return inventory.getFieldCount();
}
@Override
public void clear() {
inventory.clear();
}
@Override
public String getName() {
return inventory.getName();
}
@Override
public boolean hasCustomName() {
return inventory.hasCustomName();
}
@Override
public IChatComponent getDisplayName() {
return inventory.getDisplayName();
}
}

View file

@ -67,6 +67,7 @@ tile.techreborn.storage2.tin.name=Tin Block
tile.techreborn.solarpanel.name=Solar panel
tile.techreborn.watermill.name=Water Mill
tile.techreborn.windmill.name=Wind Mill
tile.techreborn.ironfurnace.name=Iron Furnace
#Blocks
tile.techreborn.rubberlog.name=Rubber Wood