Complete merge

This commit is contained in:
Aidan Brady 2013-12-05 22:39:54 -05:00
parent d36409f4b0
commit c282965fee
6 changed files with 7 additions and 1364 deletions

View file

@ -93,6 +93,7 @@ import mekanism.common.util.MekanismUtils;
import mekanism.common.util.MekanismUtils.ResourceType;
import mekanism.common.voice.VoiceServerManager;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
@ -177,6 +178,10 @@ public class Mekanism
/** A list of the usernames of players who have donated to Mekanism. */
public static List<String> donators = new ArrayList<String>();
public static KeySync keyMap = new KeySync();
public static Set<EntityPlayer> jetpackOn = new HashSet<EntityPlayer>();
public static Set<Object3D> ic2Registered = new HashSet<Object3D>();
@ -231,6 +236,8 @@ public class Mekanism
//General Configuration
public static boolean osmiumGenerationEnabled = true;
public static boolean copperGenerationEnabled = true;
public static boolean tinGenerationEnabled = true;
public static boolean disableBCBronzeCrafting = true;
public static boolean disableBCSteelCrafting = true;
public static boolean updateNotifications = true;

View file

@ -1,132 +0,0 @@
package mekanism.induction.client.render;
import mekanism.common.util.MekanismUtils;
import mekanism.common.util.MekanismUtils.ResourceType;
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;
@SideOnly(Side.CLIENT)
public class RenderWire extends TileEntitySpecialRenderer
{
private static final ResourceLocation WIRE_TEXTURE = MekanismUtils.getResource(ResourceType.TEXTURE_BLOCKS, "render/WireSimple.png");
private static final ResourceLocation INSULATION_TEXTURE = MekanismUtils.getResource(ResourceType.TEXTURE_BLOCKS, "render/InsulationSimple.png");
public static final ModelWire WIRE_MODEL = new ModelWire();
public static final ModelInsulation INSULATION_MODEL = new ModelInsulation();
@Override
public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float partialTick)
{
renderAModelAt((TileEntityWire)tileEntity, x, y, z, partialTick);
}
public void renderAModelAt(TileEntityWire tileEntity, double x, double y, double z, float partialTick)
{
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();
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)
{
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();
}
}
}

View file

@ -1,279 +0,0 @@
/**
*
*/
package mekanism.induction.common.tileentity;
import ic2.api.tile.IEnergyStorage;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
import mekanism.api.Object3D;
import mekanism.common.ITileNetwork;
import mekanism.common.PacketHandler;
import mekanism.common.PacketHandler.Transmission;
import mekanism.common.network.PacketDataRequest;
import mekanism.common.network.PacketTileEntity;
import mekanism.induction.common.MekanismInduction;
import mekanism.induction.common.MultimeterEventHandler;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;
import universalelectricity.core.block.IConductor;
import universalelectricity.core.block.IConnector;
import universalelectricity.core.block.IElectricalStorage;
import universalelectricity.core.grid.IElectricityNetwork;
import universalelectricity.prefab.tile.IRotatable;
import universalelectricity.prefab.tile.TileEntityAdvanced;
import universalelectricity.prefab.tile.TileEntityElectrical;
import buildcraft.api.power.IPowerReceptor;
import cofh.api.energy.TileEnergyHandler;
import com.google.common.io.ByteArrayDataInput;
/**
* Block that detects power.
*
* @author Calclavia
*
*/
public class TileEntityMultimeter extends TileEntityAdvanced implements ITileNetwork, IConnector, IRotatable
{
public Set<EntityPlayer> playersUsing = new HashSet<EntityPlayer>();
public enum DetectMode
{
NONE("None"), LESS_THAN("Less Than"), LESS_THAN_EQUAL("Less Than or Equal"),
EQUAL("Equal"), GREATER_THAN("Greater Than or Equal"), GREATER_THAN_EQUAL("Greater Than");
public String display;
private DetectMode(String s)
{
display = s;
}
}
private DetectMode detectMode = DetectMode.NONE;
private float peakDetection;
private float energyLimit;
private float detectedEnergy;
private float detectedAverageEnergy;
public boolean redstoneOn;
@Override
public void updateEntity()
{
super.updateEntity();
if (!worldObj.isRemote)
{
if (ticks % 20 == 0)
{
float prevDetectedEnergy = detectedEnergy;
updateDetection(doGetDetectedEnergy());
boolean outputRedstone = false;
switch (detectMode)
{
default:
break;
case EQUAL:
outputRedstone = detectedEnergy == energyLimit;
break;
case GREATER_THAN:
outputRedstone = detectedEnergy > energyLimit;
break;
case GREATER_THAN_EQUAL:
outputRedstone = detectedEnergy >= energyLimit;
break;
case LESS_THAN:
outputRedstone = detectedEnergy < energyLimit;
break;
case LESS_THAN_EQUAL:
outputRedstone = detectedEnergy <= energyLimit;
break;
}
if (outputRedstone != redstoneOn)
{
redstoneOn = outputRedstone;
worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, MekanismInduction.Multimeter.blockID);
}
if (prevDetectedEnergy != detectedEnergy)
{
PacketHandler.sendPacket(Transmission.ALL_CLIENTS, new PacketTileEntity().setParams(Object3D.get(this), getNetworkedData(new ArrayList())));
}
}
}
if (!worldObj.isRemote)
{
for (EntityPlayer player : playersUsing)
{
PacketHandler.sendPacket(Transmission.SINGLE_CLIENT, new PacketTileEntity().setParams(Object3D.get(this), getNetworkedData(new ArrayList())), player);
}
}
}
@Override
public void handlePacketData(ByteArrayDataInput input)
{
switch (input.readByte())
{
default:
detectMode = DetectMode.values()[input.readByte()];
detectedEnergy = input.readFloat();
energyLimit = input.readFloat();
break;
case 2:
toggleMode();
break;
case 3:
energyLimit = input.readFloat();
break;
}
}
@Override
public ArrayList getNetworkedData(ArrayList data)
{
data.add((byte) 1);
data.add((byte) detectMode.ordinal());
data.add(detectedEnergy);
data.add(energyLimit);
return data;
}
@Override
public void validate()
{
super.validate();
if (worldObj.isRemote)
{
PacketHandler.sendPacket(Transmission.SERVER, new PacketDataRequest().setParams(Object3D.get(this)));
}
}
public float doGetDetectedEnergy()
{
ForgeDirection direction = getDirection();
TileEntity tileEntity = worldObj.getBlockTileEntity(xCoord + direction.offsetX, yCoord + direction.offsetY, zCoord + direction.offsetZ);
return getDetectedEnergy(direction.getOpposite(), tileEntity);
}
public static float getDetectedEnergy(ForgeDirection side, TileEntity tileEntity)
{
if (tileEntity instanceof TileEntityElectrical)
{
return ((TileEntityElectrical) tileEntity).getEnergyStored();
}
else if (tileEntity instanceof IElectricalStorage)
{
return ((IElectricalStorage) tileEntity).getEnergyStored();
}
else if (tileEntity instanceof IConductor)
{
IElectricityNetwork network = ((IConductor) tileEntity).getNetwork();
if (MultimeterEventHandler.getCache(tileEntity.worldObj).containsKey(network) && MultimeterEventHandler.getCache(tileEntity.worldObj).get(network) instanceof Float)
{
return MultimeterEventHandler.getCache(tileEntity.worldObj).get(network);
}
}
else if (tileEntity instanceof IEnergyStorage)
{
return ((IEnergyStorage) tileEntity).getStored();
}
else if (tileEntity instanceof TileEnergyHandler)
{
return ((TileEnergyHandler) tileEntity).getEnergyStored(side.getOpposite());
}
else if (tileEntity instanceof IPowerReceptor)
{
if (((IPowerReceptor) tileEntity).getPowerReceiver(side) != null)
{
return ((IPowerReceptor) tileEntity).getPowerReceiver(side).getEnergyStored();
}
}
return 0;
}
public void updateDetection(float detected)
{
detectedEnergy = detected;
detectedAverageEnergy = (detectedAverageEnergy + detectedEnergy) / 2;
peakDetection = Math.max(peakDetection, detectedEnergy);
}
public float getDetectedEnergy()
{
return detectedEnergy;
}
public float getAverageDetectedEnergy()
{
return detectedAverageEnergy;
}
public void toggleMode()
{
detectMode = DetectMode.values()[(detectMode.ordinal() + 1) % DetectMode.values().length];
}
@Override
public void readFromNBT(NBTTagCompound nbt)
{
super.readFromNBT(nbt);
detectMode = DetectMode.values()[nbt.getInteger("detectMode")];
energyLimit = nbt.getFloat("energyLimit");
}
@Override
public void writeToNBT(NBTTagCompound nbt)
{
super.writeToNBT(nbt);
nbt.setInteger("detectMode", detectMode.ordinal());
nbt.setFloat("energyLimit", energyLimit);
}
public DetectMode getMode()
{
return detectMode;
}
public float getLimit()
{
return energyLimit;
}
public float getPeak()
{
return peakDetection;
}
@Override
public boolean canConnect(ForgeDirection direction)
{
return direction == getDirection();
}
@Override
public ForgeDirection getDirection()
{
return ForgeDirection.getOrientation(worldObj.getBlockMetadata(xCoord, yCoord, zCoord));
}
@Override
public void setDirection(ForgeDirection direction)
{
worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, direction.ordinal(), 3);
}
}

View file

@ -1,208 +0,0 @@
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(worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord))
{
return false;
}
Vector3 connectPos = new Vector3(this).modifyPositionFromSide(direction);
TileEntity connectTile = connectPos.getTileEntity(worldObj);
if(connectTile instanceof IWireMaterial)
{
IWireMaterial wireTile = (IWireMaterial) connectTile;
if(wireTile.getMaterial() != getMaterial())
{
return false;
}
}
if(isInsulated() && connectTile instanceof IInsulation)
{
IInsulation insulatedTile = (IInsulation) connectTile;
if((insulatedTile.isInsulated() && insulatedTile.getInsulationColor() != getInsulationColor() && getInsulationColor() != DEFAULT_COLOR && insulatedTile.getInsulationColor() != DEFAULT_COLOR))
{
return false;
}
}
return true;
}
@Override
public void refresh()
{
if(!worldObj.isRemote)
{
adjacentConnections = null;
for(ForgeDirection side : ForgeDirection.VALID_DIRECTIONS)
{
if(canConnect(side.getOpposite()))
{
TileEntity tileEntity = VectorHelper.getConnectorFromSide(worldObj, new Vector3(this), side);
if(tileEntity != null)
{
if(tileEntity instanceof INetworkProvider)
{
getNetwork().merge(((INetworkProvider)tileEntity).getNetwork());
}
}
}
}
getNetwork().refresh();
}
}
@Override
public float getResistance()
{
return getMaterial().resistance;
}
@Override
public float getCurrentCapacity()
{
return getMaterial().maxAmps;
}
@Override
public EnumWireMaterial getMaterial()
{
return EnumWireMaterial.values()[getTypeID()];
}
public int getTypeID()
{
return worldObj.getBlockMetadata(xCoord, yCoord, zCoord);
}
/**
* @param dyeID
*/
public void setDye(int dye)
{
dyeID = dye;
refresh();
worldObj.markBlockForRenderUpdate(xCoord, yCoord, zCoord);
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, getBlockType().blockID);
}
public void setInsulated()
{
isInsulated = true;
refresh();
worldObj.markBlockForRenderUpdate(xCoord, yCoord, zCoord);
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, getBlockType().blockID);
}
@Override
public ArrayList getNetworkedData(ArrayList data)
{
data.add(isInsulated);
data.add(dyeID);
return data;
}
@Override
public void handlePacketData(ByteArrayDataInput dataStream)
{
try {
isInsulated = dataStream.readBoolean();
dyeID = dataStream.readInt();
} catch(Exception e) {
e.printStackTrace();
}
}
@Override
public void readFromNBT(NBTTagCompound nbt)
{
super.readFromNBT(nbt);
dyeID = nbt.getInteger("dyeID");
isInsulated = nbt.getBoolean("isInsulated");
}
@Override
public void writeToNBT(NBTTagCompound nbt)
{
super.writeToNBT(nbt);
nbt.setInteger("dyeID", dyeID);
nbt.setBoolean("isInsulated", isInsulated);
}
@Override
public void doWork(PowerHandler workProvider)
{
buildcraftBuffer = Compatibility.BC3_RATIO * 25 * getMaterial().maxAmps;
powerHandler.configure(0, buildcraftBuffer, buildcraftBuffer, 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

@ -1,264 +0,0 @@
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()
{
powerHandler = new PowerHandler(this, Type.PIPE);
powerHandler.configure(0, buildcraftBuffer, buildcraftBuffer, buildcraftBuffer * 2);
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(!world().isRemote)
{
if(!isAddedToEnergyNet)
{
initIC();
}
}
}
@Override
public void onAdded()
{
super.onAdded();
if(!world().isRemote)
{
if(!isAddedToEnergyNet)
{
initIC();
}
}
}
@Override
public void onChunkLoad()
{
super.onChunkLoad();
if(!world().isRemote)
{
if(!isAddedToEnergyNet)
{
initIC();
}
}
}
@Override
public void onWorldSeparate()
{
unloadTileIC2();
super.onWorldSeparate();
}
@Override
public void onChunkUnload()
{
unloadTileIC2();
super.onChunkUnload();
}
@Override
public void onRemoved() {}
@Override
public void preRemove()
{
unloadTileIC2();
super.preRemove();
}
protected void initIC()
{
if(Compatibility.isIndustrialCraft2Loaded())
{
MinecraftForge.EVENT_BUS.post(new EnergyTileLoadEvent((IEnergyTile) tile()));
}
isAddedToEnergyNet = true;
}
private void unloadTileIC2()
{
if(isAddedToEnergyNet && world() != null)
{
if(Compatibility.isIndustrialCraft2Loaded())
{
MinecraftForge.EVENT_BUS.post(new EnergyTileUnloadEvent((IEnergyTile) tile()));
}
isAddedToEnergyNet = false;
}
}
@Override
public double demandedEnergyUnits()
{
if(getNetwork() == null)
{
return 0.0;
}
return getNetwork().getRequest(tile()).getWatts() * Compatibility.TO_IC2_RATIO;
}
@Override
public double injectEnergyUnits(ForgeDirection directionFrom, double amount)
{
TileEntity tile = VectorHelper.getTileEntityFromSide(world(), new Vector3(tile()), directionFrom);
ElectricityPack pack = ElectricityPack.getFromWatts((float) (amount * Compatibility.IC2_RATIO), 120);
return 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 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(world());
ignoreTiles.add(tile);
}
ElectricityPack pack = ElectricityPack.getFromWatts(workProvider.useEnergy(0, getNetwork().getRequest(tile()).getWatts() * Compatibility.TO_BC_RATIO, true) * Compatibility.BC3_RATIO, 120);
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 = getMaxEnergyStored(from);
if(!simulate)
{
if(request > 0)
{
return (int) (maxReceive - (getNetwork().produce(pack, new Vector3(tile()).modifyPositionFromSide(from).getTileEntity(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)Math.round(getNetwork().getRequest(new Vector3(tile()).modifyPositionFromSide(from).getTileEntity(world())).getWatts() * Compatibility.TO_TE_RATIO);
}
}

View file

@ -1,481 +0,0 @@
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();
material = type;
}
public PartWire()
{
super();
}
@Override
public boolean canConnect(ForgeDirection direction)
{
if(world().isBlockIndirectlyGettingPowered(x(), y(), 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() != getMaterial())
{
return true;
}
}
if(isInsulated() && tile instanceof IInsulation)
{
IInsulation insulatedTile = (IInsulation)tile;
if((insulatedTile.isInsulated() && insulatedTile.getInsulationColor() != getInsulationColor() && getInsulationColor() != DEFAULT_COLOR && insulatedTile.getInsulationColor() != DEFAULT_COLOR))
{
return true;
}
}
return (isBlockedOnSide(side) || tile instanceof IBlockableConnection && ((IBlockableConnection)tile).isBlockedOnSide(side.getOpposite()));
}
@Override
public byte getPossibleWireConnections()
{
if(world().isBlockIndirectlyGettingPowered(x(), y(), z()))
{
return 0x00;
}
return super.getPossibleWireConnections();
}
@Override
public byte getPossibleAcceptorConnections()
{
if(world().isBlockIndirectlyGettingPowered(x(), y(), 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 dye)
{
dyeID = dye;
refresh();
world().markBlockForUpdate(x(), y(), z());
tile().notifyPartChange(this);
}
public void setMaterialFromID(int id)
{
material = EnumWireMaterial.values()[id];
}
@Override
public void doWork(PowerHandler workProvider)
{
buildcraftBuffer = Compatibility.BC3_RATIO * 25 * Math.min(getMaterial().maxAmps, 100);
powerHandler.configure(0, buildcraftBuffer, buildcraftBuffer, 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 = isInsulated() ? insulatedSides : sides;
if(tile() != null)
{
for(ForgeDirection side : ForgeDirection.VALID_DIRECTIONS)
{
int ord = side.ordinal();
if(connectionMapContainsSide(getAllCurrentConnections(), side) || side == 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 && 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)
{
setMaterialFromID(packet.readInt());
dyeID = packet.readInt();
isInsulated = packet.readBoolean();
currentWireConnections = packet.readByte();
currentAcceptorConnections = packet.readByte();
if(tile() != null)
{
tile().markRender();
}
}
@Override
public void writeDesc(MCDataOutput packet)
{
packet.writeInt(getTypeID());
packet.writeInt(dyeID);
packet.writeBoolean(isInsulated);
packet.writeByte(currentWireConnections);
packet.writeByte(currentAcceptorConnections);
}
@Override
public void save(NBTTagCompound nbt)
{
super.save(nbt);
nbt.setInteger("typeID", getTypeID());
nbt.setInteger("dyeID", dyeID);
nbt.setBoolean("isInsulated", isInsulated);
}
@Override
public void load(NBTTagCompound nbt)
{
super.load(nbt);
setMaterialFromID(nbt.getInteger("typeID"));
dyeID = nbt.getInteger("dyeID");
isInsulated = nbt.getBoolean("isInsulated");
}
@Override
public ItemStack pickItem(MovingObjectPosition hit)
{
return EnumWireMaterial.values()[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)
{
tile().dropItems(Collections.singletonList(new ItemStack(Block.cloth, 1, BlockColored.getBlockFromDye(dyeID))));
}
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) && isInsulated())
{
if(!world().isRemote)
{
tile().dropItems(Collections.singletonList(new ItemStack(Block.cloth, 1, BlockColored.getBlockFromDye(dyeID))));
}
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 isInsulated ? 8 : 6;
}
@Override
public boolean isInsulated()
{
return isInsulated;
}
@Override
public int getInsulationColor()
{
return isInsulated ? dyeID : -1;
}
@Override
public void setInsulationColor(int dye)
{
dyeID = dye;
refresh();
world().markBlockForUpdate(x(), y(), z());
tile().notifyPartChange(this);
}
@Override
public void setInsulated(boolean insulated)
{
isInsulated = insulated;
dyeID = DEFAULT_COLOR;
refresh();
world().markBlockForUpdate(x(), y(), z());
tile().notifyPartChange(this);
}
public void setInsulated(int dyeColour)
{
isInsulated = true;
dyeID = dyeColour;
refresh();
world().markBlockForUpdate(x(), y(), z());
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());
testingSide = side;
boolean expandable = NormalOcclusionTest.apply(this, blocker);
testingSide = null;
return !expandable;
}
@Override
public void onPartChanged(TMultiPart part)
{
refresh();
}
}