Made wires treat furnaces as machines

This commit is contained in:
Calclavia 2013-08-12 20:47:42 +08:00
parent 78e520727d
commit 09244798f6
8 changed files with 219 additions and 76 deletions

View file

@ -13,8 +13,6 @@ import net.minecraftforge.oredict.ShapedOreRecipe;
import org.modstats.ModstatInfo;
import org.modstats.Modstats;
import basiccomponents.api.BasicRegistry;
import calclavia.lib.UniversalRecipes;
import resonantinduction.battery.BlockBattery;
import resonantinduction.battery.ItemCapacitor;
import resonantinduction.battery.TileEntityBattery;
@ -31,9 +29,12 @@ import resonantinduction.tesla.TileEntityTesla;
import resonantinduction.wire.BlockWire;
import resonantinduction.wire.EnumWire;
import resonantinduction.wire.ItemBlockWire;
import resonantinduction.wire.TileEntityTickWire;
import resonantinduction.wire.TileEntityWire;
import universalelectricity.core.item.IItemElectric;
import universalelectricity.prefab.TranslationHelper;
import basiccomponents.api.BasicRegistry;
import calclavia.lib.UniversalRecipes;
import cpw.mods.fml.common.FMLLog;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.Mod;
@ -47,7 +48,6 @@ import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.network.NetworkMod;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry;
/**
* @author Calclavia
@ -185,6 +185,7 @@ public class ResonantInduction
GameRegistry.registerTileEntity(TileEntityEMContractor.class, blockEMContractor.getUnlocalizedName());
GameRegistry.registerTileEntity(TileEntityBattery.class, blockBattery.getUnlocalizedName());
GameRegistry.registerTileEntity(TileEntityWire.class, blockWire.getUnlocalizedName());
GameRegistry.registerTileEntity(TileEntityTickWire.class, blockWire.getUnlocalizedName() + "2");
ResonantInduction.proxy.registerRenderers();

View file

@ -38,7 +38,7 @@ public class ItemCapacitor extends ItemUniversalElectric
@Override
public float getMaxElectricityStored(ItemStack theItem)
{
return 20;
return 500;
}
}

View file

@ -1,31 +1,24 @@
package resonantinduction.render;
import ic2.api.Direction;
import ic2.api.energy.tile.IEnergyAcceptor;
import ic2.api.energy.tile.IEnergyTile;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.ForgeDirection;
import org.lwjgl.opengl.GL11;
import resonantinduction.ResonantInduction;
import resonantinduction.model.ModelCopperWire;
import resonantinduction.wire.TileEntityWire;
import universalelectricity.compatibility.Compatibility;
import universalelectricity.core.block.IConnector;
import universalelectricity.core.vector.Vector3;
import universalelectricity.core.vector.VectorHelper;
import buildcraft.api.power.IPowerReceptor;
import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
/**
* TODO: Use ISBRH.
*
* @author Calclavia
*
*/
@SideOnly(Side.CLIENT)
public class RenderWire extends TileEntitySpecialRenderer
{
@ -40,78 +33,35 @@ public class RenderWire extends TileEntitySpecialRenderer
GL11.glTranslatef((float) x + 0.5F, (float) y + 1.5F, (float) z + 0.5F);
GL11.glScalef(1.0F, -1F, -1F);
List<TileEntity> adjecentConnections = new ArrayList<TileEntity>();
tileEntity.adjacentConnections = null;
TileEntity[] adjacentConnections = tileEntity.getAdjacentConnections();
for (byte i = 0; i < 6; i++)
{
ForgeDirection side = ForgeDirection.getOrientation(i);
TileEntity adjacentTile = VectorHelper.getTileEntityFromSide(tileEntity.worldObj, new Vector3(tileEntity), side);
if (adjacentTile instanceof IConnector)
{
if (((IConnector) adjacentTile).canConnect(side.getOpposite()))
{
adjecentConnections.add(adjacentTile);
}
else
{
adjecentConnections.add(null);
}
}
else if (Compatibility.isIndustrialCraft2Loaded() && adjacentTile instanceof IEnergyTile)
{
if (adjacentTile instanceof IEnergyAcceptor)
{
if (((IEnergyAcceptor) adjacentTile).acceptsEnergyFrom(tileEntity, Direction.values()[(i + 2) % 6].getInverse()))
{
adjecentConnections.add(adjacentTile);
}
else
{
adjecentConnections.add(null);
}
}
else
{
adjecentConnections.add(adjacentTile);
}
}
else if (Compatibility.isBuildcraftLoaded() && adjacentTile instanceof IPowerReceptor)
{
adjecentConnections.add(adjacentTile);
}
else
{
adjecentConnections.add(null);
}
}
if (adjecentConnections.toArray()[0] != null)
if (adjacentConnections[0] != null)
{
WIRE_MODEL.renderBottom();
}
if (adjecentConnections.toArray()[1] != null)
if (adjacentConnections[1] != null)
{
WIRE_MODEL.renderTop();
}
if (adjecentConnections.toArray()[2] != null)
if (adjacentConnections[2] != null)
{
WIRE_MODEL.renderBack();
}
if (adjecentConnections.toArray()[3] != null)
if (adjacentConnections[3] != null)
{
WIRE_MODEL.renderFront();
}
if (adjecentConnections.toArray()[4] != null)
if (adjacentConnections[4] != null)
{
WIRE_MODEL.renderLeft();
}
if (adjecentConnections.toArray()[5] != null)
if (adjacentConnections[5] != null)
{
WIRE_MODEL.renderRight();
}

View file

@ -587,13 +587,18 @@ public class TileEntityTesla extends TileEntityUniversalElectrical implements IT
@Override
public float getRequest(ForgeDirection direction)
{
return this.getMaxEnergyStored() - this.getEnergyStored();
if (direction != ForgeDirection.DOWN)
{
return this.getMaxEnergyStored() - this.getEnergyStored();
}
return 0;
}
@Override
public float getProvide(ForgeDirection direction)
{
if (direction != ForgeDirection.UP && direction != ForgeDirection.DOWN)
if (this.isController() && direction == ForgeDirection.DOWN)
{
return this.getEnergyStored();
}

View file

@ -66,7 +66,7 @@ public class BlockWire extends BlockConductor
@Override
public TileEntity createNewTileEntity(World var1)
{
return new TileEntityWire();
return new TileEntityTickWire();
}
@Override

View file

@ -10,14 +10,14 @@ package resonantinduction.wire;
public enum EnumWire
{
COPPER(0.0125f, 3, 200), TIN(0.01f, 2, 30), IRON(0.005f, 1, 300), ALUMINUM(0.025f, 8, 15),
SILVER(0.005f, 1, 300), SUPERCONDUCTOR(0, 5, Integer.MAX_VALUE);
COPPER(12.5f, 3, 2), TIN(10, 2, 0.5f), IRON(0.1f, 2, 4), ALUMINUM(0.025f, 6, 0.15f),
SILVER(0.005f, 1, 2), SUPERCONDUCTOR(0, 8, Float.MAX_VALUE);
public final float resistance;
public final int damage;
public final int maxAmps;
public final float damage;
public final float maxAmps;
EnumWire(float resistance, int electrocutionDamage, int maxAmps)
EnumWire(float resistance, float electrocutionDamage, float maxAmps)
{
this.resistance = resistance;
this.damage = electrocutionDamage;

View file

@ -0,0 +1,179 @@
package resonantinduction.wire;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map.Entry;
import net.minecraft.block.BlockFurnace;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityFurnace;
import net.minecraftforge.common.ForgeDirection;
import resonantinduction.ResonantInduction;
import universalelectricity.core.block.IElectrical;
import universalelectricity.core.electricity.ElectricityPack;
import universalelectricity.core.vector.Vector3;
import universalelectricity.core.vector.VectorHelper;
/**
* A version of the wire that has furnace interaction.
*
* @author Calclavia
*/
public class TileEntityTickWire extends TileEntityWire implements IElectrical
{
private HashMap<ForgeDirection, TileEntityFurnace> furnaces = new HashMap<ForgeDirection, TileEntityFurnace>();
private float energyBuffer;
private static final float FURNACE_VOLTAGE = 120;
@Override
public void updateEntity()
{
super.updateEntity();
if (this.getNetwork().getRequest().getWatts() > 0)
{
Iterator<Entry<ForgeDirection, TileEntityFurnace>> it = this.furnaces.entrySet().iterator();
while (it.hasNext())
{
Entry<ForgeDirection, TileEntityFurnace> entry = it.next();
ForgeDirection direction = entry.getKey();
TileEntityFurnace tileEntity = entry.getValue();
if (tileEntity.getStackInSlot(0) == null)
{
/**
* Steal power from furnace.
*/
boolean doBlockStateUpdate = tileEntity.furnaceBurnTime > 0;
if (tileEntity.furnaceBurnTime == 0)
{
int burnTime = TileEntityFurnace.getItemBurnTime(tileEntity.getStackInSlot(1));
if (burnTime > 0)
{
tileEntity.decrStackSize(1, 1);
tileEntity.furnaceBurnTime = burnTime;
}
}
else
{
this.getNetwork().produce(ElectricityPack.getFromWatts(ResonantInduction.FURNACE_WATTAGE, FURNACE_VOLTAGE));
}
if (doBlockStateUpdate != tileEntity.furnaceBurnTime > 0)
{
BlockFurnace.updateFurnaceBlockState(tileEntity.furnaceBurnTime > 0, tileEntity.worldObj, tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord);
}
}
}
}
}
@Override
public float receiveElectricity(ForgeDirection from, ElectricityPack receive, boolean doReceive)
{
this.energyBuffer += receive.getWatts();
/**
* Inject power to furnace.
*/
for (int i = 0; i < this.furnaces.size(); i++)
{
ForgeDirection direction = ForgeDirection.getOrientation(i);
TileEntity tileEntity = new Vector3(this).modifyPositionFromSide(direction).getTileEntity(this.worldObj);
if (tileEntity instanceof TileEntityFurnace)
{
TileEntityFurnace furnaceTile = (TileEntityFurnace) tileEntity;
boolean doBlockStateUpdate = furnaceTile.furnaceBurnTime > 0;
furnaceTile.furnaceBurnTime += 2;
if (doBlockStateUpdate != furnaceTile.furnaceBurnTime > 0)
{
BlockFurnace.updateFurnaceBlockState(furnaceTile.furnaceBurnTime > 0, furnaceTile.worldObj, furnaceTile.xCoord, furnaceTile.yCoord, furnaceTile.zCoord);
}
}
}
return receive.getWatts();
}
@Override
public void refresh()
{
super.refresh();
if (!this.worldObj.isRemote)
{
this.furnaces.clear();
for (int i = 0; i < 6; i++)
{
ForgeDirection direction = ForgeDirection.getOrientation(i);
TileEntity tileEntity = new Vector3(this).modifyPositionFromSide(direction).getTileEntity(this.worldObj);
if (tileEntity instanceof TileEntityFurnace)
{
this.furnaces.put(direction, (TileEntityFurnace) tileEntity);
}
}
}
}
/**
* Furnace Connection
*/
@Override
public TileEntity[] getAdjacentConnections()
{
super.getAdjacentConnections();
for (byte i = 0; i < 6; i++)
{
ForgeDirection side = ForgeDirection.getOrientation(i);
TileEntity tileEntity = VectorHelper.getTileEntityFromSide(this.worldObj, new Vector3(this), side);
if (tileEntity instanceof TileEntityFurnace)
{
this.adjacentConnections[i] = tileEntity;
}
}
return this.adjacentConnections;
}
@Override
public boolean canUpdate()
{
return true;
}
@Override
public ElectricityPack provideElectricity(ForgeDirection from, ElectricityPack request, boolean doProvide)
{
return new ElectricityPack();
}
@Override
public float getRequest(ForgeDirection direction)
{
return this.furnaces.size() > 0 ? ResonantInduction.FURNACE_WATTAGE : 0;
}
@Override
public float getProvide(ForgeDirection direction)
{
return 0;
}
@Override
public float getVoltage()
{
return FURNACE_VOLTAGE;
}
}

View file

@ -1,8 +1,16 @@
package resonantinduction.wire;
import java.util.HashSet;
import java.util.Set;
import net.minecraft.block.BlockFurnace;
import net.minecraft.item.crafting.FurnaceRecipes;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityFurnace;
import net.minecraftforge.common.ForgeDirection;
import resonantinduction.ResonantInduction;
import universalelectricity.compatibility.TileEntityUniversalConductor;
import universalelectricity.core.block.IConnector;
import universalelectricity.core.block.INetworkProvider;
import universalelectricity.core.vector.Vector3;
import universalelectricity.core.vector.VectorHelper;