This commit is contained in:
Aidan C. Brady 2013-12-02 11:42:21 -05:00
commit e38cf10ef6
45 changed files with 2681 additions and 54 deletions

View file

@ -28,6 +28,12 @@
<get src="https://www.dropbox.com/s/6lsq0qk00h38ktm/NotEnoughItems-dev-latest.jar?dl=1"
dest="${dir.mcp}/lib/NEI-dev.jar"/>
<get src="https://www.dropbox.com/s/qedjhg8gf1fuk8t/CodeChickenLib-dev-latest.jar?dl=1"
dest="${dir.mcp}/lib/CCLib-dev.jar"/>
<get src="http://files.minecraftforge.net/ForgeMultipart/ForgeMultipart-dev-1.6.4-1.0.0.212.jar"
dest="${dir.mcp}/lib/ForgeMultipart-dev.jar"/>
<copy todir="${dir.mcp}/src/minecraft">

View file

@ -251,7 +251,7 @@ public class Mekanism
public static double FROM_IC2;
public static double FROM_BC;
public static double FROM_TE;
public static double FROM_UE = 1000;
public static double FROM_UE = 1/TO_UE;
//Usage Configuration
public static double enrichmentChamberUsage;

View file

@ -305,6 +305,29 @@ public final class CableUtils
IStrictEnergyAcceptor acceptor = (IStrictEnergyAcceptor)tileEntity;
sendingEnergy -= (sendingEnergy - acceptor.transferEnergyToAcceptor(side.getOpposite(), sendingEnergy));
}
else if(tileEntity instanceof IConductor)
{
ForgeDirection outputDirection = side;
float provide = from.getProvide(outputDirection);
if(provide > 0)
{
IElectricityNetwork outputNetwork = ElectricityHelper.getNetworkFromTileEntity(tileEntity, outputDirection);
if(outputNetwork != null)
{
ElectricityPack request = outputNetwork.getRequest(from);
if(request.getWatts() > 0)
{
float ueSend = (float)(sendingEnergy*Mekanism.TO_UE);
ElectricityPack sendPack = ElectricityPack.min(ElectricityPack.getFromWatts(ueSend, from.getVoltage()), ElectricityPack.getFromWatts(provide, from.getVoltage()));
float rejectedPower = outputNetwork.produce(sendPack, from);
sendingEnergy -= (sendPack.getWatts() - rejectedPower)*Mekanism.FROM_UE;
}
}
}
}
else if(tileEntity instanceof IEnergyHandler)
{
IEnergyHandler handler = (IEnergyHandler)tileEntity;
@ -334,29 +357,6 @@ public final class CableUtils
sendingEnergy -= sent;
}
}
else if(tileEntity instanceof IConductor)
{
ForgeDirection outputDirection = side;
float provide = from.getProvide(outputDirection);
if(provide > 0)
{
IElectricityNetwork outputNetwork = ElectricityHelper.getNetworkFromTileEntity(tileEntity, outputDirection);
if(outputNetwork != null)
{
ElectricityPack request = outputNetwork.getRequest(from);
if(request.getWatts() > 0)
{
float ueSend = (float)(sendingEnergy*Mekanism.TO_UE);
ElectricityPack sendPack = ElectricityPack.min(ElectricityPack.getFromWatts(ueSend, from.getVoltage()), ElectricityPack.getFromWatts(provide, from.getVoltage()));
float rejectedPower = outputNetwork.produce(sendPack, from);
sendingEnergy -= (sendPack.getWatts() - rejectedPower)*Mekanism.FROM_UE;
}
}
}
}
return sendingEnergy;
}

View file

@ -7,11 +7,13 @@ import mekanism.induction.client.render.RenderBattery;
import mekanism.induction.client.render.RenderEMContractor;
import mekanism.induction.client.render.RenderMultimeter;
import mekanism.induction.client.render.RenderTesla;
import mekanism.induction.client.render.RenderWire;
import mekanism.induction.common.InductionCommonProxy;
import mekanism.induction.common.tileentity.TileEntityBattery;
import mekanism.induction.common.tileentity.TileEntityEMContractor;
import mekanism.induction.common.tileentity.TileEntityMultimeter;
import mekanism.induction.common.tileentity.TileEntityTesla;
import mekanism.induction.common.tileentity.TileEntityWire;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
@ -42,6 +44,7 @@ public class InductionClientProxy extends InductionCommonProxy
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityMultimeter.class, new RenderMultimeter());
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityEMContractor.class, new RenderEMContractor());
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityBattery.class, new RenderBattery());
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityWire.class, new RenderWire());
}
@Override
@ -61,6 +64,25 @@ public class InductionClientProxy extends InductionCommonProxy
return null;
}
@Override
public boolean isPaused()
{
if (FMLClientHandler.instance().getClient().isSingleplayer() && !FMLClientHandler.instance().getClient().getIntegratedServer().getPublic())
{
GuiScreen screen = FMLClientHandler.instance().getClient().currentScreen;
if (screen != null)
{
if (screen.doesGuiPauseGame())
{
return true;
}
}
}
return false;
}
@Override
public boolean isFancy()
{

View file

@ -4,11 +4,9 @@ import mekanism.common.Mekanism;
import mekanism.common.util.MekanismUtils;
import mekanism.common.util.MekanismUtils.ResourceType;
import mekanism.induction.client.model.ModelEMContractor;
import mekanism.induction.common.MekanismInduction;
import mekanism.induction.common.tileentity.TileEntityEMContractor;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.GL11;
@ -26,7 +24,7 @@ public class RenderEMContractor extends TileEntitySpecialRenderer
GL11.glRotatef(180F, 0.0F, 0.0F, 1.0F);
GL11.glRotatef(90F, 0.0F, 1.0F, 0.0F);
switch(((TileEntityEMContractor) t).getFacing())
switch (((TileEntityEMContractor) t).getFacing())
{
case DOWN:
GL11.glRotatef(180, 0, 0, 1);
@ -52,19 +50,21 @@ public class RenderEMContractor extends TileEntitySpecialRenderer
break;
}
if(((TileEntityEMContractor)t).suck)
if (((TileEntityEMContractor) t).suck)
{
bindTexture(MekanismUtils.getResource(ResourceType.RENDER, "ElectromagneticContractor.png"));
}
else {
else
{
bindTexture(MekanismUtils.getResource(ResourceType.RENDER, "ElectromagneticContractorOn.png"));
}
if(((TileEntityEMContractor)t).canFunction() && !Mekanism.proxy.isPaused())
if (((TileEntityEMContractor) t).canFunction() && !Mekanism.proxy.isPaused())
{
MODEL_SPIN.render(0.0625f);
}
else {
else
{
model.render(0.0625f);
}

View file

@ -0,0 +1,211 @@
package mekanism.induction.client.render;
import java.nio.FloatBuffer;
import java.util.Map;
import mekanism.induction.common.MekanismInduction;
import mekanism.induction.common.wire.PartConductor;
import mekanism.induction.common.wire.PartWire;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.util.Icon;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.ForgeDirection;
import org.lwjgl.BufferUtils;
import org.lwjgl.opengl.GL11;
import universalelectricity.core.vector.Vector3;
import codechicken.lib.colour.Colour;
import codechicken.lib.colour.ColourRGBA;
import codechicken.lib.lighting.LightModel;
import codechicken.lib.render.CCModel;
import codechicken.lib.render.CCRenderState;
import codechicken.lib.render.ColourMultiplier;
import codechicken.lib.render.IconTransformation;
import codechicken.lib.render.TextureUtils;
import codechicken.lib.vec.Matrix4;
import codechicken.lib.vec.Rotation;
import codechicken.lib.vec.Transformation;
import codechicken.lib.vec.Translation;
import codechicken.lib.vec.VariableTransformation;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
/**
*
* @author unpairedbracket
*
*/
@SideOnly(Side.CLIENT)
public class RenderPartWire
{
private static final ResourceLocation WIRE_SHINE = new ResourceLocation(MekanismInduction.DOMAIN, MekanismInduction.MODEL_TEXTURE_DIRECTORY + "white.png");
public static final Map<String, CCModel> models;
public static final Map<String, CCModel> shinyModels;
public static Icon wireIcon;
public static Icon insulationIcon;
public static Icon breakIcon;
public static FloatBuffer location = BufferUtils.createFloatBuffer(4);
public static FloatBuffer specular = BufferUtils.createFloatBuffer(4);
public static FloatBuffer zero = BufferUtils.createFloatBuffer(4);
public static FloatBuffer defaultAmbient = BufferUtils.createFloatBuffer(4);
public static final RenderPartWire INSTANCE = new RenderPartWire();
static
{
models = CCModel.parseObjModels(new ResourceLocation("resonantinduction", "models/wire.obj"), 7, new InvertX());
for (CCModel c : models.values())
{
c.apply(new Translation(.5, 0, .5));
c.computeLighting(LightModel.standardLightModel);
c.shrinkUVs(0.0005);
}
shinyModels = CCModel.parseObjModels(new ResourceLocation("resonantinduction", "models/wireShine.obj"), 7, new InvertX());
for (CCModel c : shinyModels.values())
{
c.apply(new Translation(.5, 0, .5));
c.computeLighting(LightModel.standardLightModel);
c.shrinkUVs(0.0005);
}
loadBuffer(location, 0, 0, 0, 1);
loadBuffer(specular, 1, 1, 1, 1);
loadBuffer(zero, 0, 0, 0, 0);
loadBuffer(defaultAmbient, 0.4F, 0.4F, 0.4F, 1);
GL11.glLightModel(GL11.GL_LIGHT_MODEL_AMBIENT, zero);
GL11.glLight(GL11.GL_LIGHT3, GL11.GL_SPECULAR, specular);
GL11.glMaterial(GL11.GL_FRONT, GL11.GL_SPECULAR, specular);
GL11.glMaterial(GL11.GL_FRONT, GL11.GL_AMBIENT, zero);
GL11.glMaterial(GL11.GL_FRONT, GL11.GL_DIFFUSE, zero);
GL11.glMaterialf(GL11.GL_FRONT, GL11.GL_SHININESS, 128f);
}
public static void loadBuffer(FloatBuffer buffer, float... src)
{
buffer.clear();
buffer.put(src);
buffer.flip();
}
public void renderShine(PartWire wire, double x, double y, double z, float f)
{
if (wire != null)
{
GL11.glPushMatrix();
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_COLOR, GL11.GL_ONE_MINUS_SRC_COLOR);
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glDisable(GL11.GL_LIGHT0);
GL11.glDisable(GL11.GL_LIGHT1);
GL11.glEnable(GL11.GL_LIGHT3);
GL11.glLight(GL11.GL_LIGHT3, GL11.GL_POSITION, location);
GL11.glTranslatef((float) x, (float) y, (float) z);
GL11.glLightModel(GL11.GL_LIGHT_MODEL_AMBIENT, zero);
CCRenderState.reset();
CCRenderState.useNormals(true);
CCRenderState.changeTexture(WIRE_SHINE);
CCRenderState.startDrawing(7);
renderSideShine(ForgeDirection.UNKNOWN, wire);
byte renderSides = wire.getAllCurrentConnections();
for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS)
{
if (PartConductor.connectionMapContainsSide(renderSides, side))
renderSideShine(side, wire);
}
CCRenderState.draw();
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glEnable(GL11.GL_LIGHT0);
GL11.glEnable(GL11.GL_LIGHT1);
GL11.glDisable(GL11.GL_LIGHT3);
GL11.glLightModel(GL11.GL_LIGHT_MODEL_AMBIENT, defaultAmbient);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glPopMatrix();
}
}
public static void registerIcons(IconRegister iconReg)
{
wireIcon = iconReg.registerIcon(MekanismInduction.PREFIX + MekanismInduction.MODEL_TEXTURE_DIRECTORY + "Wire");
insulationIcon = iconReg.registerIcon(MekanismInduction.PREFIX + MekanismInduction.MODEL_TEXTURE_DIRECTORY + "Insulation" + (MekanismInduction.LO_FI_INSULATION ? "Tiny" : ""));
breakIcon = iconReg.registerIcon(MekanismInduction.PREFIX + "wire");
}
public void renderStatic(PartWire wire)
{
TextureUtils.bindAtlas(0);
CCRenderState.reset();
CCRenderState.useModelColours(true);
CCRenderState.setBrightness(wire.world(), wire.x(), wire.y(), wire.z());
renderSide(ForgeDirection.UNKNOWN, wire);
byte renderSides = wire.getAllCurrentConnections();
for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS)
{
if (PartConductor.connectionMapContainsSide(renderSides, side))
renderSide(side, wire);
}
}
public void renderSide(ForgeDirection side, PartWire wire)
{
String name = side.name().toLowerCase();
name = name.equals("unknown") ? "center" : name;
Vector3 materialColour = wire.getMaterial().color;
Colour colour = new ColourRGBA(materialColour.x, materialColour.y, materialColour.z, 1);
renderPart(wireIcon, models.get(name), wire.x(), wire.y(), wire.z(), colour);
if (wire.isInsulated())
{
Vector3 vecColour = MekanismInduction.DYE_COLORS[wire.dyeID];
Colour insulationColour = new ColourRGBA(vecColour.x, vecColour.y, vecColour.z, 1);
renderPart(insulationIcon, models.get(name + "Insulation"), wire.x(), wire.y(), wire.z(), insulationColour);
}
}
public void renderSideShine(ForgeDirection side, PartWire wire)
{
String name = side.name().toLowerCase();
name = name.equals("unknown") ? "center" : name;
Vector3 materialColour = wire.getMaterial().color;
renderPartShine(shinyModels.get(name));
}
public void renderPart(Icon icon, CCModel cc, double x, double y, double z, Colour colour)
{
cc.render(0, cc.verts.length, Rotation.sideOrientation(0, Rotation.rotationTo(0, 2)).at(codechicken.lib.vec.Vector3.center).with(new Translation(x, y, z)), new IconTransformation(icon), new ColourMultiplier(colour));
}
public void renderPartShine(CCModel cc)
{
cc.render(null, 0, 0);
}
public static class InvertX extends VariableTransformation
{
public InvertX()
{
super(new Matrix4(1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1));
}
@Override
public Transformation inverse()
{
return this;
}
@Override
public void apply(codechicken.lib.vec.Vector3 vec)
{
vec.x = -vec.x;
}
}
}

View file

@ -0,0 +1,136 @@
package mekanism.induction.client.render;
import mekanism.induction.client.model.ModelInsulation;
import mekanism.induction.client.model.ModelWire;
import mekanism.induction.common.MekanismInduction;
import mekanism.induction.common.tileentity.TileEntityWire;
import mekanism.induction.common.wire.EnumWireMaterial;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.GL11;
import universalelectricity.core.vector.Vector3;
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
{
private static final ResourceLocation WIRE_TEXTURE = new ResourceLocation(MekanismInduction.DOMAIN, "textures/blocks/" + MekanismInduction.MODEL_TEXTURE_DIRECTORY + "WireSimple.png");
private static final ResourceLocation INSULATION_TEXTURE = new ResourceLocation(MekanismInduction.DOMAIN, "textures/blocks/" + MekanismInduction.MODEL_TEXTURE_DIRECTORY + "InsulationSimple.png");
public static final ModelWire WIRE_MODEL = new ModelWire();
public static final ModelInsulation INSULATION_MODEL = new ModelInsulation();
public void renderModelAt(TileEntityWire tileEntity, double x, double y, double z, float f)
{
if (tileEntity != null)
{
GL11.glPushMatrix();
GL11.glTranslatef((float) x + 0.5F, (float) y + 1.5F, (float) z + 0.5F);
GL11.glScalef(1, -1, -1);
EnumWireMaterial material = tileEntity.getMaterial();
// Texture file
FMLClientHandler.instance().getClient().renderEngine.bindTexture(WIRE_TEXTURE);
GL11.glColor4d(material.color.x, material.color.y, material.color.z, 1);
tileEntity.adjacentConnections = null;
TileEntity[] adjacentConnections = tileEntity.getAdjacentConnections();
if (adjacentConnections != null)
{
if (adjacentConnections[0] != null)
{
WIRE_MODEL.renderBottom();
}
if (adjacentConnections[1] != null)
{
WIRE_MODEL.renderTop();
}
if (adjacentConnections[2] != null)
{
WIRE_MODEL.renderBack();
}
if (adjacentConnections[3] != null)
{
WIRE_MODEL.renderFront();
}
if (adjacentConnections[4] != null)
{
WIRE_MODEL.renderLeft();
}
if (adjacentConnections[5] != null)
{
WIRE_MODEL.renderRight();
}
}
WIRE_MODEL.renderMiddle();
if (tileEntity.isInsulated)
{
// Texture file
FMLClientHandler.instance().getClient().renderEngine.bindTexture(INSULATION_TEXTURE);
Vector3 insulationColor = MekanismInduction.DYE_COLORS[tileEntity.dyeID];
GL11.glColor4d(insulationColor.x, insulationColor.y, insulationColor.z, 1);
if (adjacentConnections != null)
{
if (adjacentConnections[0] != null)
{
INSULATION_MODEL.renderBottom(0.0625f);
}
if (adjacentConnections[1] != null)
{
INSULATION_MODEL.renderTop(0.0625f);
}
if (adjacentConnections[2] != null)
{
INSULATION_MODEL.renderBack(0.0625f);
}
if (adjacentConnections[3] != null)
{
INSULATION_MODEL.renderFront(0.0625f);
}
if (adjacentConnections[4] != null)
{
INSULATION_MODEL.renderLeft(0.0625f);
}
if (adjacentConnections[5] != null)
{
INSULATION_MODEL.renderRight(0.0625f);
}
}
INSULATION_MODEL.renderMiddle(0.0625f);
}
GL11.glPopMatrix();
}
}
@Override
public void renderTileEntityAt(TileEntity tileEntity, double var2, double var4, double var6, float var8)
{
this.renderModelAt((TileEntityWire) tileEntity, var2, var4, var6, var8);
}
}

View file

@ -4,7 +4,6 @@
package mekanism.induction.common;
import mekanism.common.Mekanism;
import mekanism.generators.common.MekanismGenerators;
import mekanism.induction.common.inventory.container.ContainerBattery;
import mekanism.induction.common.inventory.container.ContainerMultimeter;
import mekanism.induction.common.tileentity.TileEntityBattery;
@ -23,12 +22,10 @@ import cpw.mods.fml.common.network.IGuiHandler;
*/
public class InductionCommonProxy implements IGuiHandler
{
public void registerRenderers() {}
public void loadConfiguration()
public void registerRenderers()
{
Mekanism.configuration.load();
MekanismInduction.FURNACE_WATTAGE = (float)Mekanism.configuration.get(Configuration.CATEGORY_GENERAL, "Furnace Wattage Per Tick", MekanismInduction.FURNACE_WATTAGE).getDouble(MekanismInduction.FURNACE_WATTAGE);
MekanismInduction.FURNACE_WATTAGE = (float) Mekanism.configuration.get(Configuration.CATEGORY_GENERAL, "Furnace Wattage Per Tick", MekanismInduction.FURNACE_WATTAGE).getDouble(MekanismInduction.FURNACE_WATTAGE);
MekanismInduction.MAX_CONTRACTOR_DISTANCE = Mekanism.configuration.get(Configuration.CATEGORY_GENERAL, "Max EM Contractor Path", MekanismInduction.MAX_CONTRACTOR_DISTANCE).getInt(MekanismInduction.MAX_CONTRACTOR_DISTANCE);
TileEntityEMContractor.ACCELERATION = Mekanism.configuration.get(Configuration.CATEGORY_GENERAL, "Contractor Item Acceleration", TileEntityEMContractor.ACCELERATION).getDouble(TileEntityEMContractor.ACCELERATION);
@ -61,6 +58,11 @@ public class InductionCommonProxy implements IGuiHandler
return null;
}
public boolean isPaused()
{
return false;
}
public void renderElectricShock(World world, Vector3 start, Vector3 target, float r, float g, float b, boolean split)
{
@ -68,31 +70,33 @@ public class InductionCommonProxy implements IGuiHandler
public void renderElectricShock(World world, Vector3 start, Vector3 target, float r, float g, float b)
{
renderElectricShock(world, start, target, r, g, b, true);
this.renderElectricShock(world, start, target, r, g, b, true);
}
public void renderElectricShock(World world, Vector3 start, Vector3 target, Vector3 color)
{
renderElectricShock(world, start, target, (float) color.x, (float) color.y, (float) color.z);
this.renderElectricShock(world, start, target, (float) color.x, (float) color.y, (float) color.z);
}
public void renderElectricShock(World world, Vector3 start, Vector3 target, Vector3 color, boolean split)
{
renderElectricShock(world, start, target, (float) color.x, (float) color.y, (float) color.z, split);
this.renderElectricShock(world, start, target, (float) color.x, (float) color.y, (float) color.z, split);
}
public void renderElectricShock(World world, Vector3 start, Vector3 target)
{
renderElectricShock(world, start, target, true);
this.renderElectricShock(world, start, target, true);
}
public void renderElectricShock(World world, Vector3 start, Vector3 target, boolean b)
{
renderElectricShock(world, start, target, 0.55f, 0.7f, 1f, b);
this.renderElectricShock(world, start, target, 0.55f, 0.7f, 1f, b);
}
public boolean isFancy()
{
return false;
}
}

View file

@ -1,5 +1,9 @@
package mekanism.induction.common;
import ic2.api.item.Items;
import java.util.Map;
import mekanism.common.IModule;
import mekanism.common.Mekanism;
import mekanism.common.MekanismRecipe;
@ -10,21 +14,34 @@ import mekanism.induction.common.block.BlockBattery;
import mekanism.induction.common.block.BlockEMContractor;
import mekanism.induction.common.block.BlockMultimeter;
import mekanism.induction.common.block.BlockTesla;
import mekanism.induction.common.block.BlockWire;
import mekanism.induction.common.furnace.BlockAdvancedFurnace;
import mekanism.induction.common.furnace.TileEntityAdvancedFurnace;
import mekanism.induction.common.item.ItemBlockContractor;
import mekanism.induction.common.item.ItemBlockMultimeter;
import mekanism.induction.common.item.ItemBlockWire;
import mekanism.induction.common.tileentity.TileEntityBattery;
import mekanism.induction.common.tileentity.TileEntityEMContractor;
import mekanism.induction.common.tileentity.TileEntityMultimeter;
import mekanism.induction.common.tileentity.TileEntityTesla;
import mekanism.induction.common.tileentity.TileEntityWire;
import mekanism.induction.common.wire.EnumWireMaterial;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityFurnace;
import net.minecraftforge.common.Configuration;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.oredict.ShapedOreRecipe;
import net.minecraftforge.oredict.ShapelessOreRecipe;
import universalelectricity.compatibility.Compatibility;
import universalelectricity.core.vector.Vector3;
import cpw.mods.fml.common.Loader;
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.ObfuscationReflectionHelper;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
@ -33,7 +50,7 @@ import cpw.mods.fml.common.network.NetworkMod;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.registry.GameRegistry;
@Mod(modid = "MekanismInduction", name = "MekanismInduction", version = "5.6.0", dependencies = "required-after:Mekanism")
@Mod(modid = "MekanismInduction", name = "MekanismInduction", version = "5.6.0", dependencies = "required-after:Mekanism;after:MekanismGenerators;after:ForgeMultipart")
@NetworkMod(clientSideRequired = true, serverSideRequired = false)
public class MekanismInduction implements IModule
{
@ -46,8 +63,25 @@ public class MekanismInduction implements IModule
/** MekanismInduction version number */
public static Version versionNumber = new Version(5, 6, 0);
//Settings
public static float FURNACE_WATTAGE = 10;
/**
*/
public static final String DOMAIN = "mekanism";
public static final String PREFIX = DOMAIN + ":";
public static final String DIRECTORY = "/assets/" + DOMAIN + "/";
public static final String TEXTURE_DIRECTORY = "textures/";
public static final String GUI_DIRECTORY = "gui/";
public static final String BLOCK_TEXTURE_DIRECTORY = TEXTURE_DIRECTORY + "blocks/";
public static final String ITEM_TEXTURE_DIRECTORY = TEXTURE_DIRECTORY + "items/";
public static final String MODEL_TEXTURE_DIRECTORY = "render/";
/**
* Settings
*/
public static float FURNACE_WATTAGE = 0.5f;
public static boolean SOUND_FXS = true;
public static boolean LO_FI_INSULATION = false;
public static boolean SHINY_SILVER = true;
public static boolean ENABLE_ADVANCED_FURNACE = false;
/** Block ID by Jyzarc */
private static final int BLOCK_ID_PREFIX = 3200;
@ -68,11 +102,16 @@ public class MekanismInduction implements IModule
return NEXT_ITEM_ID++;
}
//Blocks
/** With Forge Multipart; Use EnumWireMaterial reference. **/
private static Item itemPartWire;
// Blocks
public static Block Tesla;
public static Block Multimeter;
public static Block ElectromagneticContractor;
public static Block Battery;
/** Without Forge Multipart **/
private static Block blockWire;
public static Block blockAdvancedFurnaceIdle, blockAdvancedFurnaceBurning;
public static final Vector3[] DYE_COLORS = new Vector3[] { new Vector3(), new Vector3(1, 0, 0), new Vector3(0, 0.608, 0.232), new Vector3(0.588, 0.294, 0), new Vector3(0, 0, 1), new Vector3(0.5, 0, 05), new Vector3(0, 1, 1), new Vector3(0.8, 0.8, 0.8), new Vector3(0.3, 0.3, 0.3), new Vector3(1, 0.412, 0.706), new Vector3(0.616, 1, 0), new Vector3(1, 1, 0), new Vector3(0.46f, 0.932, 1), new Vector3(0.5, 0.2, 0.5), new Vector3(0.7, 0.5, 0.1), new Vector3(1, 1, 1) };
@ -84,12 +123,64 @@ public class MekanismInduction implements IModule
MinecraftForge.EVENT_BUS.register(new MultimeterEventHandler());
Mekanism.configuration.load();
//Blocks
// Config
FURNACE_WATTAGE = (float) Mekanism.configuration.get(Configuration.CATEGORY_GENERAL, "Furnace Wattage", FURNACE_WATTAGE).getDouble(FURNACE_WATTAGE);
SOUND_FXS = Mekanism.configuration.get(Configuration.CATEGORY_GENERAL, "Tesla Sound FXs", SOUND_FXS).getBoolean(SOUND_FXS);
LO_FI_INSULATION = Mekanism.configuration.get(Configuration.CATEGORY_GENERAL, "Use lo-fi insulation texture", LO_FI_INSULATION).getBoolean(LO_FI_INSULATION);
SHINY_SILVER = Mekanism.configuration.get(Configuration.CATEGORY_GENERAL, "Shiny silver wires", SHINY_SILVER).getBoolean(SHINY_SILVER);
MAX_CONTRACTOR_DISTANCE = Mekanism.configuration.get(Configuration.CATEGORY_GENERAL, "Max EM Contractor Path", MAX_CONTRACTOR_DISTANCE).getInt(MAX_CONTRACTOR_DISTANCE);
// Enable advanced vanilla furnace with Mekanism Generators is NOT installed.
ENABLE_ADVANCED_FURNACE = Loader.isModLoaded("MekanismGenerators");
ENABLE_ADVANCED_FURNACE = Mekanism.configuration.get(Configuration.CATEGORY_GENERAL, "Enable Vanilla Electric Furnace", ENABLE_ADVANCED_FURNACE).getBoolean(ENABLE_ADVANCED_FURNACE);
TileEntityEMContractor.ACCELERATION = Mekanism.configuration.get(Configuration.CATEGORY_GENERAL, "Contractor Item Acceleration", TileEntityEMContractor.ACCELERATION).getDouble(TileEntityEMContractor.ACCELERATION);
TileEntityEMContractor.MAX_REACH = Mekanism.configuration.get(Configuration.CATEGORY_GENERAL, "Contractor Max Item Reach", TileEntityEMContractor.MAX_REACH).getInt(TileEntityEMContractor.MAX_REACH);
TileEntityEMContractor.MAX_SPEED = Mekanism.configuration.get(Configuration.CATEGORY_GENERAL, "Contractor Max Item Speed", TileEntityEMContractor.MAX_SPEED).getDouble(TileEntityEMContractor.MAX_SPEED);
TileEntityEMContractor.PUSH_DELAY = Mekanism.configuration.get(Configuration.CATEGORY_GENERAL, "Contractor Item Push Delay", TileEntityEMContractor.PUSH_DELAY).getInt(TileEntityEMContractor.PUSH_DELAY);
//Register Items
if (Loader.isModLoaded("ForgeMultipart"))
{
try
{
itemPartWire = (Item) Class.forName("mekanism.induction.common.wire.ItemPartWire").getDeclaredConstructor(Integer.TYPE).newInstance(getNextItemID());
Mekanism.logger.fine("Mekanism Induction multipart loaded.");
}
catch (Exception e)
{
Mekanism.logger.severe("Failed to load multipart wire.");
e.printStackTrace();
}
}
else
{
Mekanism.logger.fine("Mekanism Induction Multipart disabled due to Forge Multipart not found.");
}
// Blocks
Tesla = new BlockTesla(Mekanism.configuration.getBlock("Tesla", getNextBlockID()).getInt()).setUnlocalizedName("Tesla");
Multimeter = new BlockMultimeter(Mekanism.configuration.getBlock("Multimeter", getNextBlockID()).getInt()).setUnlocalizedName("Multimeter");
ElectromagneticContractor = new BlockEMContractor(Mekanism.configuration.getBlock("ElectromagneticContractor", getNextBlockID()).getInt()).setUnlocalizedName("ElectromagneticContractor");
Battery = new BlockBattery(Mekanism.configuration.getBlock("Battery", getNextBlockID()).getInt()).setUnlocalizedName("Battery");
if (itemPartWire == null)
{
blockWire = new BlockWire(getNextBlockID());
}
if (ENABLE_ADVANCED_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());
}
Mekanism.configuration.save();
GameRegistry.registerBlock(Tesla, "Tesla");
@ -97,13 +188,39 @@ public class MekanismInduction implements IModule
GameRegistry.registerBlock(ElectromagneticContractor, ItemBlockContractor.class, "ElectromagneticContractor");
GameRegistry.registerBlock(Battery, "Battery");
//Tiles
// Tiles
if (blockWire != null)
{
GameRegistry.registerBlock(blockWire, ItemBlockWire.class, blockWire.getUnlocalizedName());
}
// Tiles
GameRegistry.registerTileEntity(TileEntityTesla.class, "Tesla");
GameRegistry.registerTileEntity(TileEntityMultimeter.class, "Multimeter");
GameRegistry.registerTileEntity(TileEntityEMContractor.class, "ElectromagneticContractor");
GameRegistry.registerTileEntity(TileEntityBattery.class, "Battery");
if (blockWire != null)
{
GameRegistry.registerTileEntity(TileEntityWire.class, blockWire.getUnlocalizedName());
}
MekanismInduction.proxy.registerRenderers();
if (itemPartWire != null)
{
for (EnumWireMaterial material : EnumWireMaterial.values())
{
material.setWire(itemPartWire);
}
}
else
{
for (EnumWireMaterial material : EnumWireMaterial.values())
{
material.setWire(blockWire);
}
}
}
@EventHandler
@ -112,23 +229,98 @@ public class MekanismInduction implements IModule
// Add this module to the core list
Mekanism.modulesLoaded.add(this);
if (itemPartWire != null)
{
try
{
Class.forName("mekanism.induction.common.MultipartMI").newInstance();
}
catch (Exception e)
{
e.printStackTrace();
Mekanism.logger.severe("Failed to initiate Mekanism Induction multipart module.");
}
}
Compatibility.initiate();
}
@EventHandler
public void postInit(FMLPostInitializationEvent evt)
{
/**
* Recipes
*/
final ItemStack defaultWire = EnumWireMaterial.IRON.getWire();
/** Tesla - by Jyzarc */
GameRegistry.addRecipe(new MekanismRecipe(new ItemStack(Tesla), new Object[] {"WEW", " C ", " I ", 'W', Mekanism.EnrichedAlloy, 'E', Item.eyeOfEnder, 'C', Mekanism.EnergyTablet.getUnchargedItem(), 'I', new ItemStack(Mekanism.BasicBlock, 1, 8)}));
GameRegistry.addRecipe(new MekanismRecipe(new ItemStack(Tesla), new Object[] { "WEW", " C ", " I ", 'W', Mekanism.EnrichedAlloy, 'E', Item.eyeOfEnder, 'C', Mekanism.EnergyTablet.getUnchargedItem(), 'I', new ItemStack(Mekanism.BasicBlock, 1, 8) }));
/** Multimeter */
GameRegistry.addRecipe(new MekanismRecipe(new ItemStack(Multimeter), new Object[] {"WWW", "ICI", 'W', Mekanism.EnrichedAlloy, 'C', Mekanism.EnergyTablet.getUnchargedItem(), 'I', "ingotSteel"}));
GameRegistry.addRecipe(new MekanismRecipe(new ItemStack(Multimeter), new Object[] { "WWW", "ICI", 'W', Mekanism.EnrichedAlloy, 'C', "battery", 'I', "ingotSteel" }));
/** Battery */
GameRegistry.addRecipe(new MekanismRecipe(new ItemStack(Battery, 4), new Object[] {"RRR", "CIC", "RRR", 'R', Item.redstone, 'I', MekanismUtils.getEnergyCube(EnergyCubeTier.BASIC), 'C', "circuitBasic"}));
GameRegistry.addRecipe(new MekanismRecipe(new ItemStack(Battery, 4), new Object[] { "RRR", "CIC", "RRR", 'R', Item.redstone, 'I', MekanismUtils.getEnergyCube(EnergyCubeTier.BASIC), 'C', "circuitBasic" }));
/** EM Contractor */
GameRegistry.addRecipe(new MekanismRecipe(new ItemStack(ElectromagneticContractor), new Object[] {" I ", "GCG", "WWW", 'W', "ingotSteel", 'C', Mekanism.EnergyTablet.getUnchargedItem(), 'G', "ingotOsmium", 'I', "ingotSteel"}));
GameRegistry.addRecipe(new MekanismRecipe(new ItemStack(ElectromagneticContractor), new Object[] { " I ", "GCG", "WWW", 'W', "ingotSteel", 'C', Mekanism.EnergyTablet.getUnchargedItem(), 'G', "ingotOsmium", 'I', "ingotSteel" }));
/** Wires **/
GameRegistry.addRecipe(new ShapedOreRecipe(EnumWireMaterial.COPPER.getWire(3), "MMM", 'M', "ingotCopper"));
GameRegistry.addRecipe(new ShapedOreRecipe(EnumWireMaterial.TIN.getWire(3), "MMM", 'M', "ingotTin"));
GameRegistry.addRecipe(new ShapedOreRecipe(EnumWireMaterial.IRON.getWire(3), "MMM", 'M', Item.ingotIron));
GameRegistry.addRecipe(new ShapedOreRecipe(EnumWireMaterial.ALUMINUM.getWire(3), "MMM", 'M', "ingotAluminum"));
GameRegistry.addRecipe(new ShapedOreRecipe(EnumWireMaterial.SILVER.getWire(), "MMM", 'M', "ingotSilver"));
GameRegistry.addRecipe(new ShapedOreRecipe(EnumWireMaterial.SUPERCONDUCTOR.getWire(3), "MMM", 'M', "ingotSuperconductor"));
GameRegistry.addRecipe(new ShapedOreRecipe(EnumWireMaterial.SUPERCONDUCTOR.getWire(3), "MMM", "MEM", "MMM", 'M', Item.ingotGold, 'E', Item.eyeOfEnder));
/** Wire Compatiblity **/
if (Loader.isModLoaded("IC2"))
{
GameRegistry.addRecipe(new ShapelessOreRecipe(EnumWireMaterial.COPPER.getWire(), Items.getItem("copperCableItem")));
GameRegistry.addRecipe(new ShapelessOreRecipe(EnumWireMaterial.TIN.getWire(), Items.getItem("tinCableItem")));
GameRegistry.addRecipe(new ShapelessOreRecipe(EnumWireMaterial.IRON.getWire(), Items.getItem("ironCableItem")));
GameRegistry.addRecipe(new ShapelessOreRecipe(EnumWireMaterial.SUPERCONDUCTOR.getWire(), Items.getItem("glassFiberCableItem")));
}
if (Loader.isModLoaded("Mekanism"))
{
GameRegistry.addRecipe(new ShapelessOreRecipe(EnumWireMaterial.COPPER.getWire(), "universalCable"));
}
if (ENABLE_ADVANCED_FURNACE)
{
/** Inject new furnace tile class */
replaceTileEntity(TileEntityFurnace.class, TileEntityAdvancedFurnace.class);
}
}
public static void replaceTileEntity(Class<? extends TileEntity> findTile, Class<? extends TileEntity> replaceTile)
{
try
{
Map<String, Class> nameToClassMap = ObfuscationReflectionHelper.getPrivateValue(TileEntity.class, null, "field_" + "70326_a", "nameToClassMap", "a");
Map<Class, String> classToNameMap = ObfuscationReflectionHelper.getPrivateValue(TileEntity.class, null, "field_" + "70326_b", "classToNameMap", "b");
String findTileID = classToNameMap.get(findTile);
if (findTileID != null)
{
nameToClassMap.put(findTileID, replaceTile);
classToNameMap.put(replaceTile, findTileID);
classToNameMap.remove(findTile);
Mekanism.logger.fine("Replaced TileEntity: " + findTile);
}
else
{
Mekanism.logger.severe("Failed to replace TileEntity: " + findTile);
}
}
catch (Exception e)
{
Mekanism.logger.severe("Failed to replace TileEntity: " + findTile);
e.printStackTrace();
}
}
@Override

View file

@ -0,0 +1,37 @@
package mekanism.induction.common;
import mekanism.induction.common.wire.EnumWireMaterial;
import mekanism.induction.common.wire.PartWire;
import codechicken.multipart.MultiPartRegistry;
import codechicken.multipart.MultiPartRegistry.IPartFactory;
import codechicken.multipart.MultipartGenerator;
import codechicken.multipart.TMultiPart;
public class MultipartMI implements IPartFactory
{
public MultipartMI()
{
this.init();
}
@Override
public TMultiPart createPart(String name, boolean client)
{
if (name == "resonant_induction_wire")
return new PartWire(EnumWireMaterial.COPPER.ordinal());
return null;
}
public void init()
{
MultiPartRegistry.registerParts(this, new String[] { "resonant_induction_wire" });
MultipartGenerator.registerPassThroughInterface("universalelectricity.core.block.IConductor");
MultipartGenerator.registerPassThroughInterface("buildcraft.api.power.IPowerReceptor");
MultipartGenerator.registerPassThroughInterface("cofh.api.energy.IEnergyHandler");
MultipartGenerator.registerPassThroughInterface("mekanism.induction.common.wire.IInsulatedMaterial");
MultipartGenerator.registerPassThroughInterface("mekanism.induction.common.wire.IBlockableConnection");
MultipartGenerator.registerTrait("ic2.api.energy.tile.IEnergySink", "mekanism.induction.common.wire.TEnergySink");
}
}

View file

@ -0,0 +1,137 @@
package mekanism.induction.common.block;
import java.util.List;
import mekanism.common.Mekanism;
import mekanism.induction.common.MekanismInduction;
import mekanism.induction.common.tileentity.TileEntityWire;
import mekanism.induction.common.wire.EnumWireMaterial;
import net.minecraft.block.Block;
import net.minecraft.block.BlockColored;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import universalelectricity.prefab.block.BlockConductor;
/**
* A copper wire block that can change its collision bounds based on the connection.
*
* @author Calclavia, Aidancbrady
*/
public class BlockWire extends BlockConductor
{
public BlockWire(int id)
{
super(Mekanism.configuration.getBlock("wire", id).getInt(id), Material.cloth);
this.setUnlocalizedName(MekanismInduction.PREFIX + "wire");
this.setStepSound(soundClothFootstep);
this.setResistance(0.2F);
this.setHardness(0.1f);
this.setBlockBounds(0.3f, 0.3f, 0.3f, 0.7f, 0.7f, 0.7f);
this.setCreativeTab(CreativeTabs.tabRedstone);
Block.setBurnProperties(this.blockID, 30, 60);
this.setTextureName(MekanismInduction.PREFIX + "wire");
this.setCreativeTab(Mekanism.tabMekanism);
}
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int par6, float par7, float par8, float par9)
{
TileEntity t = world.getBlockTileEntity(x, y, z);
TileEntityWire tileEntity = (TileEntityWire) t;
if (entityPlayer.getCurrentEquippedItem() != null)
{
if (entityPlayer.getCurrentEquippedItem().itemID == Item.dyePowder.itemID)
{
tileEntity.setDye(entityPlayer.getCurrentEquippedItem().getItemDamage());
return true;
}
else if (entityPlayer.getCurrentEquippedItem().itemID == Block.cloth.blockID && !tileEntity.isInsulated)
{
tileEntity.setInsulated();
tileEntity.setDye(BlockColored.getDyeFromBlock(entityPlayer.getCurrentEquippedItem().getItemDamage()));
entityPlayer.inventory.decrStackSize(entityPlayer.inventory.currentItem, 1);
return true;
}
}
return false;
}
/**
* Is this block (a) opaque and (b) a full 1m cube? This determines whether or not to render the
* shared face of two adjacent blocks and also whether the player can attach torches, redstone
* wire, etc to this block.
*/
@Override
public boolean isOpaqueCube()
{
return false;
}
/**
* If this block doesn't render as an ordinary block it will return False (examples: signs,
* buttons, stairs, etc)
*/
@Override
public boolean renderAsNormalBlock()
{
return false;
}
/**
* The type of render function that is called for this block
*/
@Override
public int getRenderType()
{
return -1;
}
@Override
public TileEntity createNewTileEntity(World var1)
{
return new TileEntityWire();
}
@Override
public int damageDropped(int par1)
{
return par1;
}
@Override
public void getSubBlocks(int par1, CreativeTabs par2CreativeTabs, List par3List)
{
for (int i = 0; i < EnumWireMaterial.values().length; i++)
{
par3List.add(new ItemStack(par1, 1, i));
}
}
@Override
public void breakBlock(World world, int x, int y, int z, int par5, int par6)
{
TileEntity t = world.getBlockTileEntity(x, y, z);
/**
* Drop wool insulation if the wire is insulated.
*/
if (t instanceof TileEntityWire)
{
TileEntityWire tileEntity = (TileEntityWire) t;
if (tileEntity.isInsulated)
{
this.dropBlockAsItem_do(world, x, y, z, new ItemStack(Block.cloth, 1, BlockColored.getBlockFromDye(tileEntity.dyeID)));
}
}
super.breakBlock(world, x, y, z, par5, par6);
}
}

View file

@ -0,0 +1,59 @@
package mekanism.induction.common.furnace;
import net.minecraft.block.Block;
import net.minecraft.block.BlockFurnace;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
/**
* @author Calclavia
*
*/
public class BlockAdvancedFurnace extends BlockFurnace
{
protected BlockAdvancedFurnace(int id, boolean isBurning)
{
super(id, isBurning);
this.setHardness(3.5F);
this.setStepSound(soundStoneFootstep);
this.setUnlocalizedName("furnace");
if (isBurning)
{
this.setLightValue(0.875F);
}
else
{
this.setCreativeTab(CreativeTabs.tabDecorations);
}
}
public static BlockAdvancedFurnace createNew(boolean isBurning)
{
int id = Block.furnaceIdle.blockID;
if (isBurning)
{
id = Block.furnaceBurning.blockID;
}
Block.blocksList[id] = null;
Item.itemsList[id] = null;
return new BlockAdvancedFurnace(id, isBurning);
}
@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();
}
@Override
public TileEntity createNewTileEntity(World par1World)
{
return new TileEntityAdvancedFurnace();
}
}

View file

@ -0,0 +1,246 @@
package mekanism.induction.common.furnace;
import mekanism.induction.common.MekanismInduction;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.FurnaceRecipes;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityFurnace;
import net.minecraftforge.common.ForgeDirection;
import universalelectricity.core.block.IConductor;
import universalelectricity.core.block.IElectrical;
import universalelectricity.core.electricity.ElectricityHelper;
import universalelectricity.core.electricity.ElectricityPack;
import universalelectricity.core.grid.IElectricityNetwork;
import universalelectricity.core.vector.Vector3;
import universalelectricity.core.vector.VectorHelper;
/**
* Meant to replace the furnace class.
*
* @author Calclavia
*
*/
public class TileEntityAdvancedFurnace extends TileEntityFurnace implements IElectrical
{
private static final float WATTAGE = 5;
private boolean doProduce = false;
private boolean init = true;
private float energyBuffer = 0;
@Override
public void updateEntity()
{
if (this.init)
{
this.checkProduce();
this.init = false;
}
if (this.energyBuffer >= MekanismInduction.FURNACE_WATTAGE / 20)
{
this.furnaceCookTime++;
if (this.furnaceCookTime == 200)
{
this.furnaceCookTime = 0;
this.smeltItem();
this.onInventoryChanged();
}
this.energyBuffer = 0;
}
else
{
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.produceUE(direction);
}
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();
}
}
}
}
}
}
/**
* Checks if the furnace should produce power.
*/
public void checkProduce()
{
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS)
{
TileEntity tileEntity = new Vector3(this).modifyPositionFromSide(direction).getTileEntity(this.worldObj);
if (tileEntity instanceof IConductor)
{
this.doProduce = true;
return;
}
}
this.doProduce = false;
}
public void refreshConductors()
{
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS)
{
TileEntity tileEntity = new Vector3(this).modifyPositionFromSide(direction).getTileEntity(this.worldObj);
if (tileEntity instanceof IConductor)
{
((IConductor) tileEntity).refresh();
}
}
}
/**
* Produces UE power towards a specific direction.
*
* @param outputDirection - The output direction.
*/
public boolean produceUE(ForgeDirection outputDirection)
{
if (!this.worldObj.isRemote && outputDirection != null && outputDirection != ForgeDirection.UNKNOWN)
{
float provide = this.getProvide(outputDirection);
if (provide > 0)
{
TileEntity outputTile = VectorHelper.getConnectorFromSide(this.worldObj, new Vector3(this), outputDirection);
IElectricityNetwork outputNetwork = ElectricityHelper.getNetworkFromTileEntity(outputTile, outputDirection);
if (outputNetwork != null)
{
ElectricityPack powerRequest = outputNetwork.getRequest(this);
if (powerRequest.getWatts() > 0)
{
ElectricityPack sendPack = ElectricityPack.getFromWatts(provide, this.getVoltage());
float rejectedPower = outputNetwork.produce(sendPack, this);
this.provideElectricity(outputDirection.getOpposite(), ElectricityPack.getFromWatts(sendPack.getWatts() - rejectedPower, this.getVoltage()), true);
}
return true;
}
}
}
return false;
}
@Override
public boolean canConnect(ForgeDirection direction)
{
return true;
}
private boolean canSmelt()
{
if (this.getStackInSlot(0) == null)
{
return false;
}
else
{
ItemStack itemstack = FurnaceRecipes.smelting().getSmeltingResult(this.getStackInSlot(0));
if (itemstack == null)
return false;
if (this.getStackInSlot(2) == null)
return true;
if (!this.getStackInSlot(2).isItemEqual(itemstack))
return false;
int result = getStackInSlot(2).stackSize + itemstack.stackSize;
return (result <= getInventoryStackLimit() && result <= itemstack.getMaxStackSize());
}
}
@Override
public float receiveElectricity(ForgeDirection from, ElectricityPack receive, boolean doReceive)
{
if (doReceive)
{
this.energyBuffer += receive.getWatts();
return 0;
}
return receive.getWatts();
}
@Override
public ElectricityPack provideElectricity(ForgeDirection from, ElectricityPack request, boolean doProvide)
{
return ElectricityPack.getFromWatts(MekanismInduction.FURNACE_WATTAGE / 20, this.getVoltage());
}
@Override
public float getRequest(ForgeDirection direction)
{
if (this.canSmelt() && this.getStackInSlot(1) == null && this.furnaceBurnTime == 0)
{
return MekanismInduction.FURNACE_WATTAGE / 20;
}
return 0;
}
@Override
public float getProvide(ForgeDirection direction)
{
if (this.furnaceBurnTime > 0)
{
return MekanismInduction.FURNACE_WATTAGE / 20;
}
return 0;
}
@Override
public float getVoltage()
{
return 0.12f;
}
}

View file

@ -0,0 +1,62 @@
package mekanism.induction.common.item;
import java.util.List;
import mekanism.induction.common.wire.EnumWireMaterial;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Icon;
import universalelectricity.core.electricity.ElectricityDisplay;
import universalelectricity.core.electricity.ElectricityDisplay.ElectricUnit;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class ItemBlockWire extends ItemBlock
{
private Icon[] icons = new Icon[EnumWireMaterial.values().length];
public ItemBlockWire(int id)
{
super(id);
this.setHasSubtypes(true);
this.setMaxDamage(0);
}
@Override
public int getMetadata(int damage)
{
return damage;
}
@Override
public String getUnlocalizedName(ItemStack itemStack)
{
return this.getUnlocalizedName() + "." + EnumWireMaterial.values()[itemStack.getItemDamage()].name().toLowerCase();
}
@Override
public void addInformation(ItemStack itemstack, EntityPlayer player, List par3List, boolean par4)
{
par3List.add("Resistance: " + ElectricityDisplay.getDisplay(EnumWireMaterial.values()[itemstack.getItemDamage()].resistance, ElectricUnit.RESISTANCE));
par3List.add("Max Amperage: " + ElectricityDisplay.getDisplay(EnumWireMaterial.values()[itemstack.getItemDamage()].maxAmps, ElectricUnit.AMPERE));
}
@Override
@SideOnly(Side.CLIENT)
public void registerIcons(IconRegister iconRegister)
{
for (int i = 0; i < EnumWireMaterial.values().length; i++)
{
this.icons[i] = iconRegister.registerIcon(this.getUnlocalizedName(new ItemStack(this.itemID, 1, i)).replaceAll("tile.", ""));
}
}
@Override
@SideOnly(Side.CLIENT)
public Icon getIconFromDamage(int meta)
{
return this.icons[meta];
}
}

View file

@ -0,0 +1,206 @@
package mekanism.induction.common.tileentity;
import java.util.ArrayList;
import mekanism.common.ITileNetwork;
import mekanism.induction.common.wire.EnumWireMaterial;
import mekanism.induction.common.wire.IInsulatedMaterial;
import mekanism.induction.common.wire.IInsulation;
import mekanism.induction.common.wire.IWireMaterial;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;
import universalelectricity.compatibility.Compatibility;
import universalelectricity.compatibility.TileEntityUniversalConductor;
import universalelectricity.core.block.INetworkProvider;
import universalelectricity.core.vector.Vector3;
import universalelectricity.core.vector.VectorHelper;
import buildcraft.api.power.PowerHandler;
import com.google.common.io.ByteArrayDataInput;
public class TileEntityWire extends TileEntityUniversalConductor implements ITileNetwork, IInsulatedMaterial
{
public static final int DEFAULT_COLOR = 16;
public int dyeID = DEFAULT_COLOR;
public boolean isInsulated = false;
@Override
public boolean canConnect(ForgeDirection direction)
{
if (this.worldObj.isBlockIndirectlyGettingPowered(this.xCoord, this.yCoord, this.zCoord))
{
return false;
}
Vector3 connectPos = new Vector3(this).modifyPositionFromSide(direction);
TileEntity connectTile = connectPos.getTileEntity(this.worldObj);
if (connectTile instanceof IWireMaterial)
{
IWireMaterial wireTile = (IWireMaterial) connectTile;
if (wireTile.getMaterial() != this.getMaterial())
{
return false;
}
}
if (this.isInsulated() && connectTile instanceof IInsulation)
{
IInsulation insulatedTile = (IInsulation) connectTile;
if ((insulatedTile.isInsulated() && insulatedTile.getInsulationColor() != this.getInsulationColor() && this.getInsulationColor() != DEFAULT_COLOR && insulatedTile.getInsulationColor() != DEFAULT_COLOR))
{
return false;
}
}
return true;
}
@Override
public void refresh()
{
if (!this.worldObj.isRemote)
{
this.adjacentConnections = null;
for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS)
{
if (this.canConnect(side.getOpposite()))
{
TileEntity tileEntity = VectorHelper.getConnectorFromSide(this.worldObj, new Vector3(this), side);
if (tileEntity != null)
{
if (tileEntity instanceof INetworkProvider)
{
this.getNetwork().merge(((INetworkProvider) tileEntity).getNetwork());
}
}
}
}
this.getNetwork().refresh();
}
}
@Override
public float getResistance()
{
return getMaterial().resistance;
}
@Override
public float getCurrentCapacity()
{
return getMaterial().maxAmps;
}
@Override
public EnumWireMaterial getMaterial()
{
return EnumWireMaterial.values()[this.getTypeID()];
}
public int getTypeID()
{
return this.worldObj.getBlockMetadata(this.xCoord, this.yCoord, this.zCoord);
}
/**
* @param dyeID
*/
public void setDye(int dyeID)
{
this.dyeID = dyeID;
this.refresh();
this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord);
}
public void setInsulated()
{
this.isInsulated = true;
this.refresh();
this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord);
}
@Override
public ArrayList getNetworkedData(ArrayList data)
{
data.add(isInsulated);
data.add(dyeID);
return data;
}
@Override
public void handlePacketData(ByteArrayDataInput input)
{
try
{
this.isInsulated = input.readBoolean();
this.dyeID = input.readInt();
}
catch (Exception e)
{
e.printStackTrace();
}
}
/**
* Reads a tile entity from NBT.
*/
@Override
public void readFromNBT(NBTTagCompound nbt)
{
super.readFromNBT(nbt);
this.dyeID = nbt.getInteger("dyeID");
this.isInsulated = nbt.getBoolean("isInsulated");
}
/**
* Writes a tile entity to NBT.
*/
@Override
public void writeToNBT(NBTTagCompound nbt)
{
super.writeToNBT(nbt);
nbt.setInteger("dyeID", this.dyeID);
nbt.setBoolean("isInsulated", this.isInsulated);
}
@Override
public void doWork(PowerHandler workProvider)
{
this.buildcraftBuffer = Compatibility.BC3_RATIO * 25 * this.getMaterial().maxAmps;
this.powerHandler.configure(0, this.buildcraftBuffer, this.buildcraftBuffer, this.buildcraftBuffer * 2);
super.doWork(workProvider);
}
@Override
public boolean isInsulated()
{
return isInsulated;
}
@Override
public void setInsulated(boolean insulated)
{
if (insulated && !isInsulated())
setInsulated();
}
@Override
public int getInsulationColor()
{
return dyeID;
}
@Override
public void setInsulationColor(int dyeID)
{
setDye(dyeID);
}
}

View file

@ -0,0 +1,69 @@
package mekanism.induction.common.wire;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
import universalelectricity.core.vector.Vector3;
/**
* An enumerator for different wire materials. The metadata of the wire determines the type of the
* wire.
*
* @author Calclavia
*
*/
public enum EnumWireMaterial
{
COPPER(12.5f, 3, 2, new Vector3(184, 115, 51)), TIN(13, 2, 0.5f, new Vector3(132, 132, 130)),
IRON(0.1f, 2, 4, new Vector3(97, 102, 105)),
ALUMINUM(0.025f, 6, 0.15f, new Vector3(215, 205, 181)),
SILVER(0.005f, 1, 2, new Vector3(192, 192, 192)),
SUPERCONDUCTOR(0, 8, Float.MAX_VALUE, new Vector3(212, 175, 55));
public final float resistance;
public final float damage;
public final float maxAmps;
public final Vector3 color;
private ItemStack wire;
EnumWireMaterial(float resistance, float electrocutionDamage, float maxAmps, Vector3 color)
{
this.resistance = resistance;
this.damage = electrocutionDamage;
this.maxAmps = maxAmps;
this.color = color.scale(1D / 255D);
}
public ItemStack getWire()
{
return this.getWire(1);
}
public ItemStack getWire(int amount)
{
ItemStack returnStack = this.wire.copy();
returnStack.stackSize = amount;
return returnStack;
}
public void setWire(ItemStack item)
{
if (this.wire == null)
{
this.wire = item;
OreDictionary.registerOre(this.name().toLowerCase() + "Wire", this.wire);
}
}
public void setWire(Item item)
{
this.setWire(new ItemStack(item, 1, this.ordinal()));
}
public void setWire(Block block)
{
this.setWire(new ItemStack(block, 1, this.ordinal()));
}
}

View file

@ -0,0 +1,8 @@
package mekanism.induction.common.wire;
import net.minecraftforge.common.ForgeDirection;
public interface IBlockableConnection
{
public boolean isBlockedOnSide(ForgeDirection side);
}

View file

@ -0,0 +1,6 @@
package mekanism.induction.common.wire;
public interface IInsulatedMaterial extends IInsulation, IWireMaterial
{
}

View file

@ -0,0 +1,12 @@
package mekanism.induction.common.wire;
public interface IInsulation
{
public boolean isInsulated();
public void setInsulated(boolean insulated);
public int getInsulationColor();
public void setInsulationColor(int dyeID);
}

View file

@ -0,0 +1,6 @@
package mekanism.induction.common.wire;
public interface IWireMaterial
{
public EnumWireMaterial getMaterial();
}

View file

@ -0,0 +1,103 @@
package mekanism.induction.common.wire;
import java.util.List;
import mekanism.common.Mekanism;
import mekanism.induction.client.render.RenderPartWire;
import mekanism.induction.common.MekanismInduction;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Icon;
import net.minecraft.world.World;
import net.minecraftforge.common.Configuration;
import universalelectricity.core.electricity.ElectricityDisplay;
import universalelectricity.core.electricity.ElectricityDisplay.ElectricUnit;
import codechicken.lib.vec.BlockCoord;
import codechicken.lib.vec.Vector3;
import codechicken.multipart.JItemMultiPart;
import codechicken.multipart.TMultiPart;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class ItemPartWire extends JItemMultiPart
{
private Icon[] icons = new Icon[EnumWireMaterial.values().length];
public ItemPartWire(int id)
{
super(Mekanism.configuration.get(Configuration.CATEGORY_ITEM, "wireMultipart", id).getInt(id));
this.setUnlocalizedName(MekanismInduction.PREFIX + "wire");
this.setCreativeTab(Mekanism.tabMekanism);
this.setHasSubtypes(true);
this.setMaxDamage(0);
}
@Override
public TMultiPart newPart(ItemStack arg0, EntityPlayer arg1, World arg2, BlockCoord arg3, int arg4, Vector3 arg5)
{
return new PartWire(this.getDamage(arg0));
}
@Override
public String getUnlocalizedName()
{
return super.getUnlocalizedName().replace("item", "tile");
}
@Override
public int getMetadata(int damage)
{
return damage;
}
@Override
public String getUnlocalizedName(ItemStack itemStack)
{
return this.getUnlocalizedName() + "." + EnumWireMaterial.values()[itemStack.getItemDamage()].name().toLowerCase();
}
@Override
public void addInformation(ItemStack itemstack, EntityPlayer player, List par3List, boolean par4)
{
par3List.add("Resistance: " + ElectricityDisplay.getDisplay(EnumWireMaterial.values()[itemstack.getItemDamage()].resistance, ElectricUnit.RESISTANCE));
par3List.add("Max Amperage: " + ElectricityDisplay.getDisplay(EnumWireMaterial.values()[itemstack.getItemDamage()].maxAmps, ElectricUnit.AMPERE));
}
@Override
@SideOnly(Side.CLIENT)
public void registerIcons(IconRegister iconRegister)
{
for (int i = 0; i < EnumWireMaterial.values().length; i++)
{
this.icons[i] = iconRegister.registerIcon(this.getUnlocalizedName(new ItemStack(this.itemID, 1, i)).replaceAll("tile.", ""));
}
RenderPartWire.registerIcons(iconRegister);
}
@Override
@SideOnly(Side.CLIENT)
public Icon getIconFromDamage(int meta)
{
return this.icons[meta];
}
@Override
public void getSubItems(int itemID, CreativeTabs tab, List listToAddTo)
{
for (EnumWireMaterial mat : EnumWireMaterial.values())
{
listToAddTo.add(new ItemStack(itemID, 1, mat.ordinal()));
}
}
@Override
@SideOnly(Side.CLIENT)
public int getSpriteNumber()
{
return 0;
}
}

View file

@ -0,0 +1,39 @@
package mekanism.induction.common.wire;
import net.minecraft.block.Block;
import codechicken.multipart.TMultiPart;
import codechicken.multipart.handler.MultipartProxy;
public abstract class PartAdvanced extends TMultiPart
{
protected long ticks = 0;
@Override
public void update()
{
if (this.ticks == 0)
{
this.initiate();
}
if (this.ticks >= Long.MAX_VALUE)
{
this.ticks = 1;
}
this.ticks++;
}
@Override
public void onAdded()
{
world().notifyBlocksOfNeighborChange(x(), y(), z(), ((Block) MultipartProxy.block()).blockID);
}
/**
* Called on the TileEntity's first tick.
*/
public void initiate()
{
}
}

View file

@ -0,0 +1,243 @@
package mekanism.induction.common.wire;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;
import universalelectricity.core.block.IConductor;
import universalelectricity.core.block.IConnector;
import universalelectricity.core.block.INetworkProvider;
import universalelectricity.core.electricity.NetworkLoader;
import universalelectricity.core.grid.IElectricityNetwork;
import universalelectricity.core.vector.Vector3;
import universalelectricity.core.vector.VectorHelper;
import codechicken.multipart.TileMultipart;
public abstract class PartConductor extends PartAdvanced implements IConductor
{
private IElectricityNetwork network;
public TileEntity[] adjacentConnections = null;
public byte currentWireConnections = 0x00;
public byte currentAcceptorConnections = 0x00;
public byte getAllCurrentConnections()
{
return (byte) (currentWireConnections | currentAcceptorConnections);
}
public static boolean connectionMapContainsSide(byte connections, ForgeDirection side)
{
byte tester = (byte) (1 << side.ordinal());
return ((connections & tester) > 0);
}
@Override
public void bind(TileMultipart t)
{
if (tile() != null && network != null)
{
this.getNetwork().getConductors().remove(tile());
super.bind(t);
this.getNetwork().getConductors().add((IConductor) tile());
}
else
{
super.bind(t);
}
}
@Override
public void preRemove()
{
if (!this.world().isRemote && this.tile() instanceof IConductor)
{
this.getNetwork().split((IConductor) this.tile());
}
super.preRemove();
}
@Override
public boolean doesTick()
{
return false;
}
@Override
public IElectricityNetwork getNetwork()
{
if (this.network == null && this.tile() instanceof IConductor)
{
this.setNetwork(NetworkLoader.getNewNetwork((IConductor) this.tile()));
}
return this.network;
}
public boolean canConnectBothSides(TileEntity tile, ForgeDirection side)
{
boolean notPrevented = !this.isConnectionPrevented(tile, side);
if (tile instanceof IConnector)
{
notPrevented &= ((IConnector) tile).canConnect(side.getOpposite());
}
return notPrevented;
}
@Override
public void setNetwork(IElectricityNetwork network)
{
this.network = network;
}
/**
* Override if there are ways of preventing a connection
*
* @param tile The TileEntity on the given side
* @param side The side we're checking
* @return Whether we're preventing connections on given side or to given tileEntity
*/
public boolean isConnectionPrevented(TileEntity tile, ForgeDirection side)
{
return false;
}
public byte getPossibleWireConnections()
{
byte connections = 0x00;
for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS)
{
TileEntity tileEntity = VectorHelper.getTileEntityFromSide(this.world(), new Vector3(tile()), side);
if (tileEntity instanceof INetworkProvider && this.canConnectBothSides(tileEntity, side))
connections |= 1 << side.ordinal();
}
return connections;
}
public byte getPossibleAcceptorConnections()
{
byte connections = 0x00;
for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS)
{
TileEntity tileEntity = VectorHelper.getTileEntityFromSide(this.world(), new Vector3(tile()), side);
if (this.isValidAcceptor(tileEntity) && this.canConnectBothSides(tileEntity, side))
connections |= 1 << side.ordinal();
}
return connections;
}
/**
* Override if there are different kinds of acceptor possible
*/
public boolean isValidAcceptor(TileEntity tile)
{
return tile instanceof IConnector;
}
@Override
public void refresh()
{
if (!this.world().isRemote)
{
this.adjacentConnections = null;
byte possibleWireConnections = getPossibleWireConnections();
byte possibleAcceptorConnections = getPossibleAcceptorConnections();
if (possibleWireConnections != currentWireConnections)
{
byte or = (byte) (possibleWireConnections | currentWireConnections);
if (or != possibleWireConnections) // Connections have been removed
{
this.getNetwork().split((IConductor) tile());
this.setNetwork(null);
}
for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS)
{
if (connectionMapContainsSide(possibleWireConnections, side))
{
TileEntity tileEntity = VectorHelper.getConnectorFromSide(this.world(), new Vector3(tile()), side);
if (tileEntity instanceof INetworkProvider)
{
this.getNetwork().merge(((INetworkProvider) tileEntity).getNetwork());
}
}
}
this.currentWireConnections = possibleWireConnections;
}
this.currentAcceptorConnections = possibleAcceptorConnections;
this.getNetwork().refresh();
this.sendDescUpdate();
}
this.tile().markRender();
}
/**
* Should include connections that are in the current connection maps even if those connections
* aren't allowed any more. This is so that networks split correctly.
*/
@Override
public TileEntity[] getAdjacentConnections()
{
if (this.adjacentConnections == null)
{
this.adjacentConnections = new TileEntity[6];
for (byte i = 0; i < 6; i++)
{
ForgeDirection side = ForgeDirection.getOrientation(i);
TileEntity tileEntity = VectorHelper.getTileEntityFromSide(this.world(), new Vector3(tile()), side);
if (isCurrentlyConnected(side))
{
adjacentConnections[i] = tileEntity;
}
}
}
return this.adjacentConnections;
}
public boolean isCurrentlyConnected(ForgeDirection side)
{
return connectionMapContainsSide(this.getAllCurrentConnections(), side);
}
/**
* Shouldn't need to be overridden. Override connectionPrevented instead
*/
@Override
public boolean canConnect(ForgeDirection direction)
{
Vector3 connectPos = new Vector3(tile()).modifyPositionFromSide(direction);
TileEntity connectTile = connectPos.getTileEntity(this.world());
return !isConnectionPrevented(connectTile, direction);
}
@Override
public void onAdded()
{
super.onAdded();
this.refresh();
}
@Override
public void onChunkLoad()
{
super.onChunkLoad();
this.refresh();
}
@Override
public void onNeighborChanged()
{
super.onNeighborChanged();
this.refresh();
}
}

View file

@ -0,0 +1,264 @@
package mekanism.induction.common.wire;
import ic2.api.energy.event.EnergyTileLoadEvent;
import ic2.api.energy.event.EnergyTileUnloadEvent;
import ic2.api.energy.tile.IEnergySink;
import ic2.api.energy.tile.IEnergyTile;
import java.util.HashSet;
import java.util.Set;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.common.MinecraftForge;
import universalelectricity.compatibility.Compatibility;
import universalelectricity.core.electricity.ElectricityPack;
import universalelectricity.core.vector.Vector3;
import universalelectricity.core.vector.VectorHelper;
import buildcraft.api.power.IPowerReceptor;
import buildcraft.api.power.PowerHandler;
import buildcraft.api.power.PowerHandler.PowerReceiver;
import buildcraft.api.power.PowerHandler.Type;
import cofh.api.energy.IEnergyHandler;
public abstract class PartUniversalConductor extends PartConductor implements IEnergySink, IPowerReceptor, IEnergyHandler
{
protected boolean isAddedToEnergyNet;
public PowerHandler powerHandler;
public float buildcraftBuffer = Compatibility.BC3_RATIO * 50;
public PartUniversalConductor()
{
this.powerHandler = new PowerHandler(this, Type.PIPE);
this.powerHandler.configure(0, this.buildcraftBuffer, this.buildcraftBuffer, this.buildcraftBuffer * 2);
this.powerHandler.configurePowerPerdition(0, 0);
}
@Override
public boolean isValidAcceptor(TileEntity tile)
{
if (tile instanceof IEnergyTile)
{
return true;
}
else if (tile instanceof IPowerReceptor)
{
return true;
}
else if (tile instanceof IEnergyHandler)
{
return true;
}
return super.isValidAcceptor(tile);
}
@Override
public boolean isConnectionPrevented(TileEntity tile, ForgeDirection side)
{
if (tile instanceof IEnergyHandler)
{
return !((IEnergyHandler) tile).canInterface(side);
}
return super.isConnectionPrevented(tile, side);
}
@Override
public void onWorldJoin()
{
super.onWorldJoin();
if (!this.world().isRemote)
{
if (!this.isAddedToEnergyNet)
{
this.initIC();
}
}
}
@Override
public void onAdded()
{
super.onAdded();
if (!this.world().isRemote)
{
if (!this.isAddedToEnergyNet)
{
this.initIC();
}
}
}
@Override
public void onChunkLoad()
{
super.onChunkLoad();
if (!this.world().isRemote)
{
if (!this.isAddedToEnergyNet)
{
this.initIC();
}
}
}
@Override
public void onWorldSeparate()
{
this.unloadTileIC2();
super.onWorldSeparate();
}
@Override
public void onChunkUnload()
{
this.unloadTileIC2();
super.onChunkUnload();
}
@Override
public void onRemoved()
{
}
@Override
public void preRemove()
{
this.unloadTileIC2();
super.preRemove();
}
protected void initIC()
{
if (Compatibility.isIndustrialCraft2Loaded())
{
MinecraftForge.EVENT_BUS.post(new EnergyTileLoadEvent((IEnergyTile) tile()));
}
this.isAddedToEnergyNet = true;
}
private void unloadTileIC2()
{
if (this.isAddedToEnergyNet && this.world() != null)
{
if (Compatibility.isIndustrialCraft2Loaded())
{
MinecraftForge.EVENT_BUS.post(new EnergyTileUnloadEvent((IEnergyTile) tile()));
}
this.isAddedToEnergyNet = false;
}
}
@Override
public double demandedEnergyUnits()
{
if (this.getNetwork() == null)
{
return 0.0;
}
return this.getNetwork().getRequest(tile()).getWatts() * Compatibility.TO_IC2_RATIO;
}
@Override
public double injectEnergyUnits(ForgeDirection directionFrom, double amount)
{
TileEntity tile = VectorHelper.getTileEntityFromSide(this.world(), new Vector3(tile()), directionFrom);
ElectricityPack pack = ElectricityPack.getFromWatts((float) (amount * Compatibility.IC2_RATIO), 120);
return this.getNetwork().produce(pack, tile(), tile) * Compatibility.TO_IC2_RATIO;
}
@Override
public int getMaxSafeInput()
{
return Integer.MAX_VALUE;
}
@Override
public boolean acceptsEnergyFrom(TileEntity emitter, ForgeDirection direction)
{
return true;
}
/**
* BuildCraft functions
*/
@Override
public PowerReceiver getPowerReceiver(ForgeDirection side)
{
return this.powerHandler.getPowerReceiver();
}
@Override
public void doWork(PowerHandler workProvider)
{
Set<TileEntity> ignoreTiles = new HashSet<TileEntity>();
ignoreTiles.add(tile());
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS)
{
TileEntity tile = new Vector3(tile()).modifyPositionFromSide(direction).getTileEntity(this.world());
ignoreTiles.add(tile);
}
ElectricityPack pack = ElectricityPack.getFromWatts(workProvider.useEnergy(0, this.getNetwork().getRequest(tile()).getWatts() * Compatibility.TO_BC_RATIO, true) * Compatibility.BC3_RATIO, 120);
this.getNetwork().produce(pack, ignoreTiles.toArray(new TileEntity[0]));
}
@Override
public World getWorld()
{
return world();
}
/**
* Thermal Expansion Functions
*/
@Override
public int receiveEnergy(ForgeDirection from, int maxReceive, boolean simulate)
{
ElectricityPack pack = ElectricityPack.getFromWatts(maxReceive * Compatibility.TE_RATIO, 1);
float request = this.getMaxEnergyStored(from);
if (!simulate)
{
if (request > 0)
{
return (int) (maxReceive - (this.getNetwork().produce(pack, new Vector3(tile()).modifyPositionFromSide(from).getTileEntity(this.world())) * Compatibility.TO_TE_RATIO));
}
return 0;
}
return (int) Math.min(maxReceive, request * Compatibility.TO_TE_RATIO);
}
@Override
public int extractEnergy(ForgeDirection from, int maxExtract, boolean simulate)
{
return 0;
}
@Override
public boolean canInterface(ForgeDirection from)
{
return true;
}
@Override
public int getEnergyStored(ForgeDirection from)
{
return 0;
}
@Override
public int getMaxEnergyStored(ForgeDirection from)
{
return (int) (this.getNetwork().getRequest(new Vector3(tile()).modifyPositionFromSide(from).getTileEntity(this.world())).getWatts() * Compatibility.TO_TE_RATIO);
}
}

View file

@ -0,0 +1,455 @@
package mekanism.induction.common.wire;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import mekanism.induction.client.render.RenderPartWire;
import mekanism.induction.common.MekanismInduction;
import net.minecraft.block.Block;
import net.minecraft.block.BlockColored;
import net.minecraft.client.particle.EffectRenderer;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemShears;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Icon;
import net.minecraft.util.MovingObjectPosition;
import net.minecraftforge.common.ForgeDirection;
import universalelectricity.compatibility.Compatibility;
import buildcraft.api.power.PowerHandler;
import codechicken.lib.data.MCDataInput;
import codechicken.lib.data.MCDataOutput;
import codechicken.lib.lighting.LazyLightMatrix;
import codechicken.lib.raytracer.IndexedCuboid6;
import codechicken.lib.render.CCRenderState;
import codechicken.lib.render.IconTransformation;
import codechicken.lib.render.RenderUtils;
import codechicken.lib.vec.Cuboid6;
import codechicken.lib.vec.Translation;
import codechicken.microblock.IHollowConnect;
import codechicken.multipart.IconHitEffects;
import codechicken.multipart.JIconHitEffects;
import codechicken.multipart.JNormalOcclusion;
import codechicken.multipart.NormalOcclusionTest;
import codechicken.multipart.PartMap;
import codechicken.multipart.TMultiPart;
import codechicken.multipart.TSlottedPart;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class PartWire extends PartUniversalConductor implements TSlottedPart, JNormalOcclusion, IHollowConnect, JIconHitEffects, IInsulatedMaterial, IBlockableConnection
{
public static final int DEFAULT_COLOR = 16;
public int dyeID = DEFAULT_COLOR;
public boolean isInsulated = false;
public static IndexedCuboid6[] sides = new IndexedCuboid6[7];
public static IndexedCuboid6[] insulatedSides = new IndexedCuboid6[7];
public EnumWireMaterial material = EnumWireMaterial.COPPER;
/** Client Side Connection Check */
private ForgeDirection testingSide;
static
{
sides[0] = new IndexedCuboid6(0, new Cuboid6(0.36, 0.000, 0.36, 0.64, 0.36, 0.64));
sides[1] = new IndexedCuboid6(1, new Cuboid6(0.36, 0.64, 0.36, 0.64, 1.000, 0.64));
sides[2] = new IndexedCuboid6(2, new Cuboid6(0.36, 0.36, 0.000, 0.64, 0.64, 0.36));
sides[3] = new IndexedCuboid6(3, new Cuboid6(0.36, 0.36, 0.64, 0.64, 0.64, 1.000));
sides[4] = new IndexedCuboid6(4, new Cuboid6(0.000, 0.36, 0.36, 0.36, 0.64, 0.64));
sides[5] = new IndexedCuboid6(5, new Cuboid6(0.64, 0.36, 0.36, 1.000, 0.64, 0.64));
sides[6] = new IndexedCuboid6(6, new Cuboid6(0.36, 0.36, 0.36, 0.64, 0.64, 0.64));
insulatedSides[0] = new IndexedCuboid6(0, new Cuboid6(0.3, 0.0, 0.3, 0.7, 0.3, 0.7));
insulatedSides[1] = new IndexedCuboid6(1, new Cuboid6(0.3, 0.7, 0.3, 0.7, 1.0, 0.7));
insulatedSides[2] = new IndexedCuboid6(2, new Cuboid6(0.3, 0.3, 0.0, 0.7, 0.7, 0.3));
insulatedSides[3] = new IndexedCuboid6(3, new Cuboid6(0.3, 0.3, 0.7, 0.7, 0.7, 1.0));
insulatedSides[4] = new IndexedCuboid6(4, new Cuboid6(0.0, 0.3, 0.3, 0.3, 0.7, 0.7));
insulatedSides[5] = new IndexedCuboid6(5, new Cuboid6(0.7, 0.3, 0.3, 1.0, 0.7, 0.7));
insulatedSides[6] = new IndexedCuboid6(6, new Cuboid6(0.3, 0.3, 0.3, 0.7, 0.7, 0.7));
}
public PartWire(int typeID)
{
this(EnumWireMaterial.values()[typeID]);
}
public PartWire(EnumWireMaterial type)
{
super();
this.material = type;
}
public PartWire()
{
super();
}
@Override
public boolean canConnect(ForgeDirection direction)
{
if (this.world().isBlockIndirectlyGettingPowered(this.x(), this.y(), this.z()))
{
return false;
}
return super.canConnect(direction);
}
@Override
public boolean isConnectionPrevented(TileEntity tile, ForgeDirection side)
{
if (tile instanceof IWireMaterial)
{
IWireMaterial wireTile = (IWireMaterial) tile;
if (wireTile.getMaterial() != this.getMaterial())
return true;
}
if (this.isInsulated() && tile instanceof IInsulation)
{
IInsulation insulatedTile = (IInsulation) tile;
if ((insulatedTile.isInsulated() && insulatedTile.getInsulationColor() != this.getInsulationColor() && this.getInsulationColor() != DEFAULT_COLOR && insulatedTile.getInsulationColor() != DEFAULT_COLOR))
return true;
}
return (this.isBlockedOnSide(side) || tile instanceof IBlockableConnection && ((IBlockableConnection) tile).isBlockedOnSide(side.getOpposite()));
}
@Override
public byte getPossibleWireConnections()
{
if (this.world().isBlockIndirectlyGettingPowered(this.x(), this.y(), this.z()))
{
return 0x00;
}
return super.getPossibleWireConnections();
}
@Override
public byte getPossibleAcceptorConnections()
{
if (this.world().isBlockIndirectlyGettingPowered(this.x(), this.y(), this.z()))
{
return 0x00;
}
return super.getPossibleAcceptorConnections();
}
@Override
public float getResistance()
{
return getMaterial().resistance;
}
@Override
public float getCurrentCapacity()
{
return getMaterial().maxAmps;
}
@Override
public EnumWireMaterial getMaterial()
{
return material;
}
public int getTypeID()
{
return material.ordinal();
}
public void setDye(int dyeID)
{
this.dyeID = dyeID;
this.refresh();
this.world().markBlockForUpdate(this.x(), this.y(), this.z());
}
public void setMaterialFromID(int id)
{
this.material = EnumWireMaterial.values()[id];
}
@Override
public void doWork(PowerHandler workProvider)
{
this.buildcraftBuffer = Compatibility.BC3_RATIO * 25 * Math.min(this.getMaterial().maxAmps, 100);
this.powerHandler.configure(0, this.buildcraftBuffer, this.buildcraftBuffer, this.buildcraftBuffer * 2);
super.doWork(workProvider);
}
@Override
public String getType()
{
return "resonant_induction_wire";
}
@Override
public boolean occlusionTest(TMultiPart other)
{
return NormalOcclusionTest.apply(this, other);
}
@Override
public Iterable<IndexedCuboid6> getSubParts()
{
Set<IndexedCuboid6> subParts = new HashSet<IndexedCuboid6>();
IndexedCuboid6[] currentSides = this.isInsulated() ? insulatedSides : sides;
if (tile() != null)
{
for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS)
{
int ord = side.ordinal();
if (connectionMapContainsSide(getAllCurrentConnections(), side) || side == this.testingSide)
subParts.add(currentSides[ord]);
}
}
subParts.add(currentSides[6]);
return subParts;
}
@Override
public Iterable<Cuboid6> getCollisionBoxes()
{
Set<Cuboid6> collisionBoxes = new HashSet<Cuboid6>();
collisionBoxes.addAll((Collection<? extends Cuboid6>) getSubParts());
return collisionBoxes;
}
@Override
public Iterable<ItemStack> getDrops()
{
List<ItemStack> drops = new ArrayList<ItemStack>();
drops.add(pickItem(null));
if (isInsulated)
drops.add(new ItemStack(Block.cloth, 1, BlockColored.getBlockFromDye(dyeID)));
return drops;
}
@Override
public float getStrength(MovingObjectPosition hit, EntityPlayer player)
{
return 10F;
}
@Override
@SideOnly(Side.CLIENT)
public void renderStatic(codechicken.lib.vec.Vector3 pos, LazyLightMatrix olm, int pass)
{
if (pass == 0)
RenderPartWire.INSTANCE.renderStatic(this);
}
@Override
@SideOnly(Side.CLIENT)
public void renderDynamic(codechicken.lib.vec.Vector3 pos, float frame, int pass)
{
if (MekanismInduction.SHINY_SILVER && this.getMaterial() == EnumWireMaterial.SILVER)
RenderPartWire.INSTANCE.renderShine(this, pos.x, pos.y, pos.z, frame);
}
@Override
public void drawBreaking(RenderBlocks renderBlocks)
{
CCRenderState.reset();
RenderUtils.renderBlock(sides[6], 0, new Translation(x(), y(), z()), new IconTransformation(renderBlocks.overrideBlockTexture), null);
}
@Override
public void readDesc(MCDataInput packet)
{
this.setMaterialFromID(packet.readInt());
this.dyeID = packet.readInt();
this.isInsulated = packet.readBoolean();
this.currentWireConnections = packet.readByte();
this.currentAcceptorConnections = packet.readByte();
if (tile() != null)
tile().markRender();
}
@Override
public void writeDesc(MCDataOutput packet)
{
packet.writeInt(this.getTypeID());
packet.writeInt(this.dyeID);
packet.writeBoolean(this.isInsulated);
packet.writeByte(this.currentWireConnections);
packet.writeByte(this.currentAcceptorConnections);
}
@Override
public void save(NBTTagCompound nbt)
{
super.save(nbt);
nbt.setInteger("typeID", this.getTypeID());
nbt.setInteger("dyeID", this.dyeID);
nbt.setBoolean("isInsulated", this.isInsulated);
}
@Override
public void load(NBTTagCompound nbt)
{
super.load(nbt);
this.setMaterialFromID(nbt.getInteger("typeID"));
this.dyeID = nbt.getInteger("dyeID");
this.isInsulated = nbt.getBoolean("isInsulated");
}
@Override
public ItemStack pickItem(MovingObjectPosition hit)
{
return EnumWireMaterial.values()[this.getTypeID()].getWire();
}
@Override
public boolean activate(EntityPlayer player, MovingObjectPosition part, ItemStack item)
{
if (item != null)
{
if (item.itemID == Item.dyePowder.itemID && isInsulated())
{
setDye(item.getItemDamage());
return true;
}
else if (item.itemID == Block.cloth.blockID)
{
if (isInsulated() && !world().isRemote)
{
this.tile().dropItems(Collections.singletonList(new ItemStack(Block.cloth, 1, BlockColored.getBlockFromDye(dyeID))));
}
this.setInsulated(BlockColored.getDyeFromBlock(item.getItemDamage()));
player.inventory.decrStackSize(player.inventory.currentItem, 1);
return true;
}
else if ((item.itemID == Item.shears.itemID || item.getItem() instanceof ItemShears) && this.isInsulated())
{
if (!this.world().isRemote)
{
this.tile().dropItems(Collections.singletonList(new ItemStack(Block.cloth, 1, BlockColored.getBlockFromDye(dyeID))));
}
this.setInsulated(false);
return true;
}
}
return false;
}
@Override
public Iterable<Cuboid6> getOcclusionBoxes()
{
return getCollisionBoxes();
}
@Override
public int getSlotMask()
{
return PartMap.CENTER.mask;
}
@Override
public int getHollowSize()
{
return this.isInsulated ? 8 : 6;
}
@Override
public boolean isInsulated()
{
return isInsulated;
}
@Override
public int getInsulationColor()
{
return isInsulated ? dyeID : -1;
}
@Override
public void setInsulationColor(int dyeID)
{
this.dyeID = dyeID;
this.refresh();
this.world().markBlockForUpdate(this.x(), this.y(), this.z());
}
@Override
public void setInsulated(boolean insulated)
{
this.isInsulated = insulated;
this.dyeID = DEFAULT_COLOR;
this.refresh();
this.world().markBlockForUpdate(this.x(), this.y(), this.z());
this.tile().notifyPartChange(this);
}
public void setInsulated(int dyeColour)
{
this.isInsulated = true;
this.dyeID = dyeColour;
this.refresh();
this.world().markBlockForUpdate(this.x(), this.y(), this.z());
this.tile().notifyPartChange(this);
}
public void setInsulated()
{
setInsulated(true);
}
@Override
public Cuboid6 getBounds()
{
return new Cuboid6(0.375, 0.375, 0.375, 0.625, 0.625, 0.625);
}
@Override
public Icon getBreakingIcon(Object subPart, int side)
{
return RenderPartWire.breakIcon;
}
@Override
public Icon getBrokenIcon(int side)
{
return RenderPartWire.breakIcon;
}
@Override
public void addHitEffects(MovingObjectPosition hit, EffectRenderer effectRenderer)
{
IconHitEffects.addHitEffects(this, hit, effectRenderer);
}
@Override
public void addDestroyEffects(EffectRenderer effectRenderer)
{
IconHitEffects.addDestroyEffects(this, effectRenderer, false);
}
@Override
public boolean isBlockedOnSide(ForgeDirection side)
{
TMultiPart blocker = tile().partMap(side.ordinal());
this.testingSide = side;
boolean expandable = NormalOcclusionTest.apply(this, blocker);
this.testingSide = null;
return !expandable;
}
@Override
public void onPartChanged(TMultiPart part)
{
this.refresh();
}
}

View file

@ -0,0 +1,92 @@
package mekanism.induction.common.wire;
import ic2.api.energy.tile.IEnergySink;
import java.util.HashSet;
import java.util.Set;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;
import codechicken.multipart.TMultiPart;
import codechicken.multipart.TileMultipart;
public class TEnergySink extends TileMultipart implements IEnergySink
{
public Set<IEnergySink> ic2Sinks = new HashSet<IEnergySink>();
@Override
public void copyFrom(TileMultipart that)
{
super.copyFrom(that);
if (that instanceof TEnergySink)
ic2Sinks = ((TEnergySink) that).ic2Sinks;
}
@Override
public void bindPart(TMultiPart part)
{
super.bindPart(part);
if (part instanceof IEnergySink)
ic2Sinks.add((IEnergySink) part);
}
@Override
public void partRemoved(TMultiPart part, int p)
{
super.partRemoved(part, p);
if (part instanceof IEnergySink)
ic2Sinks.remove(part);
}
@Override
public void clearParts()
{
super.clearParts();
ic2Sinks.clear();
}
@Override
public boolean acceptsEnergyFrom(TileEntity emitter, ForgeDirection direction)
{
for (IEnergySink sink : this.ic2Sinks)
{
if (sink.acceptsEnergyFrom(emitter, direction))
return true;
}
return false;
}
@Override
public double demandedEnergyUnits()
{
double demanded = 0;
for (IEnergySink sink : this.ic2Sinks)
{
demanded += sink.demandedEnergyUnits();
}
return demanded;
}
@Override
public double injectEnergyUnits(ForgeDirection directionFrom, double amount)
{
for (IEnergySink sink : this.ic2Sinks)
{
amount = sink.injectEnergyUnits(directionFrom, Math.min(amount, sink.demandedEnergyUnits()));
}
return amount;
}
@Override
public int getMaxSafeInput()
{
int safe = 0;
for (IEnergySink sink : this.ic2Sinks)
{
safe += sink.getMaxSafeInput();
}
return safe;
}
}

View file

@ -370,9 +370,9 @@ item.SteelShovel.name=Steel Shovel
item.SteelHoe.name=Steel Hoe
item.SteelSword.name=Steel Sword
//*********//
//INDUCTION//
//*********//
//*****//
//TOOLS//
//*****//
//Blocks
tile.Tesla.name=Tesla Coil
@ -380,9 +380,21 @@ tile.Multimeter.name=Multimeter
tile.ElectromagneticContractor.name=Electromagnetic Contractor
tile.Battery.name=Modular Battery
<<<<<<< HEAD
tile.mekanism:wire.copper.name=Copper Wire
tile.mekanism:wire.tin.name=Tin Wire
tile.mekanism:wire.iron.name=Iron Wire
tile.mekanism:wire.aluminum.name=Aluminum Wire
tile.mekanism:wire.silver.name=Silver Wire
tile.mekanism:wire.superconductor.name=Superconductor Wire
//Items
item.Linker.name=Electrostatic Linker
=======
//General text
text.contractor.success=Linked contractor successfully
text.tesla.success=Linked tesla successfully
>>>>>>> master
//Gui text
gui.heatGenerator.fuel=Fuel

View file

Before

Width:  |  Height:  |  Size: 5 KiB

After

Width:  |  Height:  |  Size: 5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.8 KiB

View file

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

View file

Before

Width:  |  Height:  |  Size: 702 B

After

Width:  |  Height:  |  Size: 702 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 933 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 269 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 224 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 269 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 225 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 224 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 269 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 224 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 269 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 225 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 224 B