Revived advanced furnace

This commit is contained in:
Calclavia 2013-12-21 00:01:30 +08:00
parent 0240818f1d
commit a499f5781e
4 changed files with 131 additions and 121 deletions

@ -1 +1 @@
Subproject commit 14ab2d5b402c6a645d216cd2da1d7aaa2c6a742c
Subproject commit 015fabb450c50680f81bd25011799b78ab838605

View file

@ -38,7 +38,7 @@ import resonantinduction.multimeter.TileEntityMultimeter;
import resonantinduction.tesla.BlockTesla;
import resonantinduction.tesla.TileEntityTesla;
import resonantinduction.wire.EnumWireMaterial;
import resonantinduction.wire.ItemBlockWire;
import resonantinduction.wire.ItemPartWire;
import universalelectricity.api.vector.Vector3;
import universalelectricity.core.item.IItemElectric;
import basiccomponents.api.BasicRegistry;
@ -152,9 +152,7 @@ public class ResonantInduction
public static Block blockMultimeter;
public static Block blockEMContractor;
public static Block blockBattery;
/** Without Forge Multipart **/
private static Block blockWire;
public static Block blockAdvancedFurnaceIdle, blockAdvancedFurnaceBurning;
public static Block blockAdvancedFurnace;
/**
* Packets
@ -190,18 +188,7 @@ public class ResonantInduction
itemCapacitor = new ItemCapacitor(getNextItemID());
itemLinker = new ItemLinker(getNextItemID());
itemInfiniteCapacitor = new ItemInfiniteCapacitor(getNextItemID());
if (Loader.isModLoaded("ForgeMultipart"))
{
try
{
itemPartWire = (Item) Class.forName("resonantinduction.wire.multipart.ItemPartWire").getConstructor(Integer.TYPE).newInstance(getNextItemID());
}
catch (Exception e)
{
LOGGER.severe("Failed to load multipart wire.");
}
}
itemPartWire = new ItemPartWire(getNextItemID());
// Blocks
blockTesla = new BlockTesla(getNextBlockID());
@ -211,11 +198,9 @@ public class ResonantInduction
if (REPLACE_FURNACE)
{
blockAdvancedFurnaceIdle = BlockAdvancedFurnace.createNew(false);
blockAdvancedFurnaceBurning = BlockAdvancedFurnace.createNew(true);
GameRegistry.registerBlock(blockAdvancedFurnaceIdle, "ri_" + blockAdvancedFurnaceIdle.getUnlocalizedName());
GameRegistry.registerBlock(blockAdvancedFurnaceBurning, "ri_" + blockAdvancedFurnaceBurning.getUnlocalizedName() + "2");
GameRegistry.registerTileEntity(TileEntityAdvancedFurnace.class, blockAdvancedFurnaceIdle.getUnlocalizedName());
blockAdvancedFurnace = BlockAdvancedFurnace.createNew(false);
GameRegistry.registerBlock(blockAdvancedFurnace, "ri_" + blockAdvancedFurnace.getUnlocalizedName());
GameRegistry.registerTileEntity(TileEntityAdvancedFurnace.class, blockAdvancedFurnace.getUnlocalizedName());
}
CONFIGURATION.save();
@ -230,18 +215,12 @@ public class ResonantInduction
GameRegistry.registerBlock(blockEMContractor, ItemBlockContractor.class, blockEMContractor.getUnlocalizedName());
GameRegistry.registerBlock(blockBattery, blockBattery.getUnlocalizedName());
if (blockWire != null)
{
GameRegistry.registerBlock(blockWire, ItemBlockWire.class, blockWire.getUnlocalizedName());
}
// Tiles
GameRegistry.registerTileEntity(TileEntityTesla.class, blockTesla.getUnlocalizedName());
GameRegistry.registerTileEntity(TileEntityMultimeter.class, blockMultimeter.getUnlocalizedName());
GameRegistry.registerTileEntity(TileEntityEMContractor.class, blockEMContractor.getUnlocalizedName());
GameRegistry.registerTileEntity(TileEntityBattery.class, blockBattery.getUnlocalizedName());
ResonantInduction.proxy.registerRenderers();
/**
@ -249,19 +228,9 @@ public class ResonantInduction
*/
TabRI.ITEMSTACK = new ItemStack(blockBattery);
if (itemPartWire != null)
for (EnumWireMaterial material : EnumWireMaterial.values())
{
for (EnumWireMaterial material : EnumWireMaterial.values())
{
material.setWire(itemPartWire);
}
}
else
{
for (EnumWireMaterial material : EnumWireMaterial.values())
{
material.setWire(blockWire);
}
material.setWire(itemPartWire);
}
// Basic Components

View file

@ -1,11 +1,18 @@
package resonantinduction.furnace;
import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.block.BlockFurnace;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Icon;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
/**
* @author Calclavia
@ -13,6 +20,13 @@ import net.minecraft.world.World;
*/
public class BlockAdvancedFurnace extends BlockFurnace
{
@SideOnly(Side.CLIENT)
private Icon furnaceIconTop;
@SideOnly(Side.CLIENT)
private Icon furnaceIconFront;
@SideOnly(Side.CLIENT)
private Icon furnaceIconFrontBurn;
protected BlockAdvancedFurnace(int id, boolean isBurning)
{
super(id, isBurning);
@ -44,11 +58,79 @@ public class BlockAdvancedFurnace extends BlockFurnace
return new BlockAdvancedFurnace(id, isBurning);
}
@Override
public void registerIcons(IconRegister par1IconRegister)
{
this.blockIcon = par1IconRegister.registerIcon("furnace_side");
this.furnaceIconFront = par1IconRegister.registerIcon("furnace_front_off");
this.furnaceIconFrontBurn = par1IconRegister.registerIcon("furnace_front_on");
this.furnaceIconTop = par1IconRegister.registerIcon("furnace_top");
}
@Override
public Icon getBlockTexture(IBlockAccess access, int x, int y, int z, int side)
{
TileEntity tileEntity = (TileEntityAdvancedFurnace) access.getBlockTileEntity(x, y, z);
int meta = access.getBlockMetadata(x, y, z);
if (((TileEntityAdvancedFurnace) tileEntity).isBurning())
{
return side == 1 ? this.furnaceIconTop : (side == 0 ? this.furnaceIconTop : (side != meta ? this.blockIcon : this.furnaceIconFrontBurn));
}
else
{
return side == 1 ? this.furnaceIconTop : (side == 0 ? this.furnaceIconTop : (side != meta ? this.blockIcon : this.furnaceIconFront));
}
}
@Override
public Icon getIcon(int side, int meta)
{
return side == 1 ? this.furnaceIconTop : (side == 0 ? this.furnaceIconTop : (side != 3 ? this.blockIcon : this.furnaceIconFront));
}
@Override
public void randomDisplayTick(World world, int x, int y, int z, Random par5Random)
{
TileEntity tileEntity = (TileEntityAdvancedFurnace) world.getBlockTileEntity(x, y, z);
if (((TileEntityAdvancedFurnace) tileEntity).isBurning())
{
int l = world.getBlockMetadata(x, y, z);
float f = (float) x + 0.5F;
float f1 = (float) y + 0.0F + par5Random.nextFloat() * 6.0F / 16.0F;
float f2 = (float) z + 0.5F;
float f3 = 0.52F;
float f4 = par5Random.nextFloat() * 0.6F - 0.3F;
if (l == 4)
{
world.spawnParticle("smoke", (double) (f - f3), (double) f1, (double) (f2 + f4), 0.0D, 0.0D, 0.0D);
world.spawnParticle("flame", (double) (f - f3), (double) f1, (double) (f2 + f4), 0.0D, 0.0D, 0.0D);
}
else if (l == 5)
{
world.spawnParticle("smoke", (double) (f + f3), (double) f1, (double) (f2 + f4), 0.0D, 0.0D, 0.0D);
world.spawnParticle("flame", (double) (f + f3), (double) f1, (double) (f2 + f4), 0.0D, 0.0D, 0.0D);
}
else if (l == 2)
{
world.spawnParticle("smoke", (double) (f + f4), (double) f1, (double) (f2 - f3), 0.0D, 0.0D, 0.0D);
world.spawnParticle("flame", (double) (f + f4), (double) f1, (double) (f2 - f3), 0.0D, 0.0D, 0.0D);
}
else if (l == 3)
{
world.spawnParticle("smoke", (double) (f + f4), (double) f1, (double) (f2 + f3), 0.0D, 0.0D, 0.0D);
world.spawnParticle("flame", (double) (f + f4), (double) f1, (double) (f2 + f3), 0.0D, 0.0D, 0.0D);
}
}
}
@Override
public void onNeighborBlockChange(World world, int x, int y, int z, int newID)
{
super.onNeighborBlockChange(world, x, y, z, newID);
((TileEntityAdvancedFurnace)world.getBlockTileEntity(x, y, z)).checkProduce();
((TileEntityAdvancedFurnace) world.getBlockTileEntity(x, y, z)).checkProduce();
}
@Override

View file

@ -10,11 +10,8 @@ import universalelectricity.api.UniversalClass;
import universalelectricity.api.electricity.IVoltage;
import universalelectricity.api.energy.IEnergyInterface;
import universalelectricity.api.vector.Vector3;
import universalelectricity.api.vector.VectorHelper;
import universalelectricity.core.block.IConductor;
import universalelectricity.core.electricity.ElectricityHelper;
import universalelectricity.core.electricity.ElectricityPack;
import universalelectricity.core.grid.IEnergyNetwork;
import calclavia.lib.prefab.block.EnergyStorage;
/**
* Meant to replace the furnace class.
@ -28,82 +25,55 @@ public class TileEntityAdvancedFurnace extends TileEntityFurnace implements IEne
private static final float WATTAGE = 5;
private boolean doProduce = false;
private boolean init = true;
private int energyBuffer = 0;
private EnergyStorage energy = new EnergyStorage(ResonantInduction.FURNACE_WATTAGE * 5);
@Override
public void updateEntity()
{
if (this.init)
{
this.checkProduce();
this.init = false;
}
boolean doSmeltingProcess = canSmelt() && this.getStackInSlot(1) == null && this.furnaceBurnTime == 0;
if (this.energyBuffer >= ResonantInduction.FURNACE_WATTAGE / 20)
if (doSmeltingProcess)
{
this.furnaceCookTime++;
if (this.furnaceCookTime == 200)
if (this.energy.checkExtract(ResonantInduction.FURNACE_WATTAGE / 20))
{
this.furnaceCookTime = 0;
this.smeltItem();
this.onInventoryChanged();
this.furnaceCookTime++;
if (this.furnaceCookTime == 200)
{
this.furnaceCookTime = 0;
this.smeltItem();
this.onInventoryChanged();
}
this.energy.extractEnergy(ResonantInduction.FURNACE_WATTAGE / 20, true);
}
}
else if (this.getStackInSlot(0) == null && TileEntityFurnace.getItemBurnTime(this.getStackInSlot(1)) > 0 && !this.energy.isFull())
{
boolean doBlockStateUpdate = this.furnaceBurnTime > 0;
if (this.furnaceBurnTime == 0)
{
int burnTime = TileEntityFurnace.getItemBurnTime(this.getStackInSlot(1));
this.decrStackSize(1, 1);
this.furnaceBurnTime = burnTime;
}
this.energyBuffer = 0;
if (this.furnaceBurnTime > 0)
{
this.energy.receiveEnergy(ResonantInduction.FURNACE_WATTAGE / 20, true);
}
if (doBlockStateUpdate != this.furnaceBurnTime > 0)
{
this.refreshConductors();
}
}
else
{
// TODO: Fix vanilla changing the blockID of this furnace.
super.updateEntity();
if (this.doProduce)
{
if (this.getStackInSlot(0) == null)
{
boolean hasRequest = false;
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS)
{
TileEntity tileEntity = new Vector3(this).modifyPositionFromSide(direction).getTileEntity(this.worldObj);
if (tileEntity instanceof IConductor)
{
if (((IConductor) tileEntity).getNetwork().getRequest(this).getWatts() > 0)
{
if (this.furnaceBurnTime > 0)
{
this.energyBuffer += ResonantInduction.FURNACE_WATTAGE / 20;
}
hasRequest = true;
break;
}
}
}
if (hasRequest)
{
/**
* Steal power from furnace.
*/
boolean doBlockStateUpdate = this.furnaceBurnTime > 0;
if (this.furnaceBurnTime == 0)
{
int burnTime = TileEntityFurnace.getItemBurnTime(this.getStackInSlot(1));
this.decrStackSize(1, 1);
this.furnaceBurnTime = burnTime;
}
if (doBlockStateUpdate != this.furnaceBurnTime > 0)
{
// BlockFurnace.updateFurnaceBlockState(this.furnaceBurnTime > 0,
// this.worldObj, this.xCoord, this.yCoord, this.zCoord);
this.refreshConductors();
}
}
}
}
}
}
@ -170,13 +140,7 @@ public class TileEntityAdvancedFurnace extends TileEntityFurnace implements IEne
{
if (this.canSmelt() && this.getStackInSlot(1) == null && this.furnaceBurnTime == 0)
{
if (doReceive)
{
this.energyBuffer += receive;
return receive;
}
return ResonantInduction.FURNACE_WATTAGE / 20;
return this.energy.receiveEnergy(receive, doReceive);
}
return 0;
@ -185,12 +149,7 @@ public class TileEntityAdvancedFurnace extends TileEntityFurnace implements IEne
@Override
public int onExtractEnergy(ForgeDirection from, int request, boolean doProvide)
{
if (this.furnaceBurnTime > 0)
{
return ResonantInduction.FURNACE_WATTAGE / 20;
}
return 0;
return this.energy.extractEnergy(request, doProvide);
}
@Override