Oh joy of updating to 1.6

This is going to take a lot of time to get working 100%
This commit is contained in:
DarkGuardsman 2013-07-09 13:10:09 -04:00
parent 30161f90f1
commit 485ca799d8
16 changed files with 372 additions and 768 deletions

View file

@ -12,7 +12,9 @@ public enum PowerSystems
{
this.id = id;
}
public static float BC3_RATIO = 100;
public static float TO_BC_RATIO = 1 / BC3_RATIO;
private static boolean init = false;
private static Boolean[] loaded;

View file

@ -4,19 +4,15 @@ import net.minecraft.block.Block;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.liquids.ILiquid;
import net.minecraftforge.liquids.LiquidContainerRegistry;
import net.minecraftforge.liquids.LiquidDictionary;
import net.minecraftforge.liquids.LiquidStack;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.IFluidBlock;
import universalelectricity.core.vector.Vector3;
public class FluidHelper
{
/**
* The default built in flow rate of the liquid threw the pipes. Will correct this later to use
* a visc value instead of flow value so that the size of the pipe can play a factor in flow
*/
public static int getDefaultFlowRate(LiquidStack stack)
/** The default built in flow rate of the liquid threw the pipes. Will correct this later to use
* a visc value instead of flow value so that the size of the pipe can play a factor in flow */
public static int getDefaultFlowRate(FluidStack stack)
{
if (stack != null)
{
@ -48,13 +44,11 @@ public class FluidHelper
return 500;
}
/**
* Creates a new LiquidStack using the sample stack
/** Creates a new LiquidStack using the sample stack
*
* @param stack - liquidLiquid being used to create the stack
* @param vol - amount or volume of the stack
* @return a new @LiquidStack
*/
* @return a new @LiquidStack */
public static LiquidStack getStack(LiquidStack stack, int vol)
{
if (stack == null)
@ -64,9 +58,7 @@ public class FluidHelper
return new LiquidStack(stack.itemID, vol, stack.itemMeta);
}
/**
* Consumes one item of a the ItemStack
*/
/** Consumes one item of a the ItemStack */
public static ItemStack consumeItem(ItemStack stack)
{
if (stack.stackSize == 1)
@ -87,12 +79,10 @@ public class FluidHelper
}
}
/**
* gets the blockID/ItemID of the Still liquid
/** gets the blockID/ItemID of the Still liquid
*
* @param id - blockID
* @return will return -1 if its not a valid liquid Block
*/
* @return will return -1 if its not a valid liquid Block */
public static int getLiquidId(int id)
{
if (id == Block.waterStill.blockID || id == Block.waterMoving.blockID)
@ -103,9 +93,9 @@ public class FluidHelper
{
return Block.lavaStill.blockID;
}
else if (Block.blocksList[id] instanceof ILiquid)
else if (Block.blocksList[id] instanceof IFluidBlock)
{
return ((ILiquid) Block.blocksList[id]).stillLiquidId();
return ((IFluidBlock) Block.blocksList[id]).getFluid().getBlockID();
}
else
{
@ -113,11 +103,9 @@ public class FluidHelper
}
}
/**
* gets the liquidStack of the block
/** gets the liquidStack of the block
*
* @param id - block's ID
*/
* @param id - block's ID */
public static LiquidStack getLiquidFromBlockId(int id)
{
if (id == Block.waterStill.blockID || id == Block.waterMoving.blockID)
@ -143,9 +131,7 @@ public class FluidHelper
return null;
}
/**
* Is the location a liquid source block
*/
/** Is the location a liquid source block */
public static boolean isSourceBlock(World world, Vector3 vec)
{
LiquidStack liquid = FluidHelper.getLiquidFromBlockId(vec.getBlockID(world));
@ -156,9 +142,7 @@ public class FluidHelper
return false;
}
/**
* Gets the number of source liquids blocks around the locaiton
*/
/** Gets the number of source liquids blocks around the locaiton */
public static int getConnectedSources(World world, Vector3 vec)
{
int sources = 0;
@ -173,9 +157,7 @@ public class FluidHelper
return sources;
}
/**
* Gets the number of liquid fillable blocks around the location
*/
/** Gets the number of liquid fillable blocks around the location */
public static int getConnectedFillables(World world, Vector3 vec)
{
int sources = 0;

View file

@ -1,6 +1,10 @@
package dark.core.hydraulic.helpers;
import net.minecraftforge.event.ForgeSubscribe;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidRegistry.FluidRegisterEvent;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.liquids.LiquidDictionary;
import net.minecraftforge.liquids.LiquidDictionary.LiquidRegisterEvent;
import net.minecraftforge.liquids.LiquidStack;
@ -12,44 +16,43 @@ import dark.core.api.ColorCode;
public class FluidRestrictionHandler
{
private static BiMap<ColorCode, LiquidStack> restrictedStacks = HashBiMap.create();
private static BiMap<ColorCode, Fluid> restrictedStacks = HashBiMap.create();
static
{
/* ADD DEFAULT LIQUIDS */
restrictedStacks.put(ColorCode.BLUE, LiquidDictionary.getCanonicalLiquid("Water"));
restrictedStacks.put(ColorCode.RED, LiquidDictionary.getCanonicalLiquid("Lava"));
restrictedStacks.put(ColorCode.BLUE, FluidRegistry.getFluid("Water"));
restrictedStacks.put(ColorCode.RED, FluidRegistry.getFluid("Lava"));
}
@ForgeSubscribe
public void onLiquidRegistered(LiquidRegisterEvent event)
public void onLiquidRegistered(FluidRegisterEvent event)
{
if (event != null && event.Name != null)
if (event != null && event.fluidName != null)
{
if (event.Name.equalsIgnoreCase("Fuel") && !restrictedStacks.containsKey(ColorCode.YELLOW))
Fluid fluid = FluidRegistry.getFluid(event.fluidName);
if (event.fluidName.equalsIgnoreCase("Fuel") && !restrictedStacks.containsKey(ColorCode.YELLOW))
{
restrictedStacks.put(ColorCode.YELLOW, event.Liquid);
restrictedStacks.put(ColorCode.YELLOW, fluid);
}
else if (event.Name.equalsIgnoreCase("Oil") && !restrictedStacks.containsKey(ColorCode.BLACK))
else if (event.fluidName.equalsIgnoreCase("Oil") && !restrictedStacks.containsKey(ColorCode.BLACK))
{
restrictedStacks.put(ColorCode.BLACK, event.Liquid);
restrictedStacks.put(ColorCode.BLACK, fluid);
}
else if (event.Name.equalsIgnoreCase("Milk") && !restrictedStacks.containsKey(ColorCode.WHITE))
else if (event.fluidName.equalsIgnoreCase("Milk") && !restrictedStacks.containsKey(ColorCode.WHITE))
{
restrictedStacks.put(ColorCode.WHITE, event.Liquid);
restrictedStacks.put(ColorCode.WHITE, fluid);
}
}
}
/**
* Checks too see if a color has a restricted stack
*/
/** Checks too see if a color has a restricted stack */
public static boolean hasRestrictedStack(int meta)
{
return restrictedStacks.containsKey(ColorCode.get(meta));
}
public static boolean hasRestrictedStack(LiquidStack stack)
public static boolean hasRestrictedStack(Fluid stack)
{
if (stack == null)
{
@ -58,24 +61,20 @@ public class FluidRestrictionHandler
return restrictedStacks.inverse().containsKey(stack);
}
/**
* gets the liquid stack that is restricted to this color
*
*/
public static LiquidStack getStackForColor(ColorCode color)
/** gets the liquid stack that is restricted to this color */
public static Fluid getStackForColor(ColorCode color)
{
return restrictedStacks.get(color);
}
/**
* checks to see if the liquidStack is valid for the given color
*/
public static boolean isValidLiquid(ColorCode color, LiquidStack stack)
/** checks to see if the liquidStack is valid for the given color */
public static boolean isValidLiquid(ColorCode color, Fluid stack)
{
if (stack == null)
{
return false;
}
if(!FluidRestrictionHandler.hasRestrictedStack(color.ordinal()))
if (!FluidRestrictionHandler.hasRestrictedStack(color.ordinal()))
{
return true;
}

View file

@ -13,6 +13,7 @@ import net.minecraft.block.Block;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.entity.Render;
import net.minecraft.client.resources.ResourceLocation;
import net.minecraft.entity.Entity;
import net.minecraft.util.Icon;
import net.minecraft.world.IBlockAccess;
@ -72,7 +73,8 @@ public class RenderEntityBlock extends Render
World world = entity.worldObj;
BlockInterface util = new BlockInterface();
util.texture = entity.texture;
loadTexture("/terrain.png");
ResourceLocation name = new ResourceLocation("minecraft:terrain.png");
func_110776_a(name);
for (int iBase = 0; iBase < entity.iSize; ++iBase)
{
@ -218,4 +220,10 @@ public class RenderEntityBlock extends Render
tessellator.draw();
}
}
@Override
protected ResourceLocation func_110775_a(Entity entity)
{
return null;
}
}

View file

@ -1,55 +0,0 @@
package dark.core.hydraulic.helpers;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.liquids.ITankContainer;
import net.minecraftforge.liquids.LiquidStack;
import universalelectricity.core.vector.Vector3;
import universalelectricity.core.vector.VectorHelper;
/**
* Used to help with draining and filling of a tank
*
* @author DarkGuardsman
*/
public class TankHelper
{
/**
* Fills all ITankContainers around the point
*
* @return amount filled into the tank, use this to drain the source of the stack
*/
public static int fillArround(World world, Vector3 center, LiquidStack stack)
{
if (stack == null || stack.amount <= 0 || center.y < 6 || center.y > 255)
{
return 0;
}
int fill = 0;
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS)
{
fill += TankHelper.fillDirection(world, center, stack, direction);
}
return fill;
}
/**
* Fills a ITankContainer in one direction from a point in the world
*
* @return amount filled into the tank, use this to drain the source of the stack
*/
public static int fillDirection(World world, Vector3 center, LiquidStack stack, ForgeDirection direction)
{
if (stack == null || stack.amount <= 0 || center.y < 6 || center.y > 255)
{
return 0;
}
TileEntity entity = VectorHelper.getTileEntityFromSide(world, center, direction);
if (entity instanceof ITankContainer && ((ITankContainer) entity).fill(direction.getOpposite(), stack, false) > 0)
{
return ((ITankContainer) entity).fill(direction.getOpposite(), stack, true);
}
return 0;
}
}

View file

@ -1,327 +0,0 @@
package dark.core.tile.network;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import net.minecraft.tileentity.TileEntity;
import universalelectricity.core.block.IConductor;
import universalelectricity.core.block.IConnectionProvider;
import universalelectricity.core.electricity.ElectricityPack;
import universalelectricity.core.electricity.IElectricityNetwork;
import cpw.mods.fml.common.FMLLog;
import dark.core.api.INetworkPart;
public class NetworkPowerTiles extends NetworkTileEntities implements IElectricityNetwork
{
protected final HashMap<TileEntity, ElectricityPack> producers = new HashMap<TileEntity, ElectricityPack>();
protected final HashMap<TileEntity, ElectricityPack> consumers = new HashMap<TileEntity, ElectricityPack>();
protected double wattStored = 0.0;
public NetworkPowerTiles(INetworkPart... conductors)
{
super(conductors);
}
@Override
public NetworkTileEntities newInstance()
{
return new NetworkPowerTiles();
}
@Override
public void startProducing(TileEntity tileEntity, ElectricityPack electricityPack)
{
if (tileEntity != null && electricityPack.getWatts() > 0)
{
this.producers.put(tileEntity, electricityPack);
}
}
@Override
public void startProducing(TileEntity tileEntity, double amperes, double voltage)
{
this.startProducing(tileEntity, new ElectricityPack(amperes, voltage));
}
@Override
public boolean isProducing(TileEntity tileEntity)
{
return this.producers.containsKey(tileEntity);
}
/** Sets this tile entity to stop producing energy in this network. */
@Override
public void stopProducing(TileEntity tileEntity)
{
this.producers.remove(tileEntity);
}
/** Sets this tile entity to start producing energy in this network. */
@Override
public void startRequesting(TileEntity tileEntity, ElectricityPack electricityPack)
{
if (tileEntity != null && electricityPack.getWatts() > 0)
{
this.consumers.put(tileEntity, electricityPack);
}
}
@Override
public void startRequesting(TileEntity tileEntity, double amperes, double voltage)
{
this.startRequesting(tileEntity, new ElectricityPack(amperes, voltage));
}
@Override
public boolean isRequesting(TileEntity tileEntity)
{
return this.consumers.containsKey(tileEntity);
}
/** Sets this tile entity to stop producing energy in this network. */
@Override
public void stopRequesting(TileEntity tileEntity)
{
this.consumers.remove(tileEntity);
}
/** @param ignoreTiles The TileEntities to ignore during this calculation. Null will make it not
* ignore any.
* @return The electricity produced in this electricity network */
@Override
public ElectricityPack getProduced(TileEntity... ignoreTiles)
{
ElectricityPack totalElectricity = new ElectricityPack(0, 0);
Iterator it = this.producers.entrySet().iterator();
loop:
while (it.hasNext())
{
Map.Entry pairs = (Map.Entry) it.next();
if (pairs != null)
{
TileEntity tileEntity = (TileEntity) pairs.getKey();
if (tileEntity == null)
{
it.remove();
continue;
}
if (tileEntity.isInvalid())
{
it.remove();
continue;
}
if (tileEntity.worldObj.getBlockTileEntity(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord) != tileEntity)
{
it.remove();
continue;
}
if (ignoreTiles != null)
{
for (TileEntity ignoreTile : ignoreTiles)
{
if (tileEntity == ignoreTile)
{
continue loop;
}
}
}
ElectricityPack pack = (ElectricityPack) pairs.getValue();
if (pairs.getKey() != null && pairs.getValue() != null && pack != null)
{
totalElectricity = ElectricityPack.getFromWatts(totalElectricity.getWatts() + pack.getWatts(), Math.max(totalElectricity.voltage, pack.voltage));
}
}
}
return totalElectricity;
}
/** @return How much electricity this network needs. */
@Override
public ElectricityPack getRequest(TileEntity... ignoreTiles)
{
return this.getRequestWithoutReduction();
}
public double getMemberRequest()
{
return 0;
}
public double getMaxBattery()
{
return Math.min(this.getRequest().getWatts(), this.networkMember.size() * 10) * 2;
}
public double getCurrentBattery()
{
return this.wattStored;
}
@Override
public ElectricityPack getRequestWithoutReduction()
{
ElectricityPack totalElectricity = new ElectricityPack(0, 0);
Iterator it = this.consumers.entrySet().iterator();
while (it.hasNext())
{
Map.Entry pairs = (Map.Entry) it.next();
if (pairs != null)
{
TileEntity tileEntity = (TileEntity) pairs.getKey();
if (tileEntity == null)
{
it.remove();
continue;
}
if (tileEntity.isInvalid())
{
it.remove();
continue;
}
if (tileEntity.worldObj.getBlockTileEntity(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord) != tileEntity)
{
it.remove();
continue;
}
ElectricityPack pack = (ElectricityPack) pairs.getValue();
if (pack != null)
{
totalElectricity = ElectricityPack.getFromWatts(totalElectricity.getWatts() + pack.getWatts(), Math.max(totalElectricity.voltage, pack.voltage));
}
}
}
return totalElectricity;
}
/** @param tileEntity
* @return The electricity being input into this tile entity. */
@Override
public ElectricityPack consumeElectricity(TileEntity tileEntity)
{
ElectricityPack totalElectricity = new ElectricityPack(0, 0);
try
{
ElectricityPack tileRequest = this.consumers.get(tileEntity);
if (this.consumers.containsKey(tileEntity) && tileRequest != null)
{
if (this.wattStored - this.getMemberRequest() >= tileRequest.getWatts())
{
this.wattStored -= tileRequest.getWatts();
return tileRequest;
}
// Calculate the electricity this TileEntity is receiving in percentage.
totalElectricity = this.getProduced();
if (totalElectricity.getWatts() > 0)
{
ElectricityPack totalRequest = this.getRequestWithoutReduction();
totalElectricity.amperes *= (tileRequest.amperes / totalRequest.amperes);
return totalElectricity;
}
}
}
catch (Exception e)
{
FMLLog.severe("Failed to consume electricity!");
e.printStackTrace();
}
return totalElectricity;
}
@Override
public HashMap<TileEntity, ElectricityPack> getProducers()
{
return this.producers;
}
@Override
public List<TileEntity> getProviders()
{
List<TileEntity> providers = new ArrayList<TileEntity>();
providers.addAll(this.producers.keySet());
return providers;
}
@Override
public HashMap<TileEntity, ElectricityPack> getConsumers()
{
return this.consumers;
}
@Override
public List<TileEntity> getReceivers()
{
List<TileEntity> receivers = new ArrayList<TileEntity>();
receivers.addAll(this.consumers.keySet());
return receivers;
}
@Override
public double getTotalResistance()
{
return 0.001;
}
@Override
public double getLowestCurrentCapacity()
{
return 10000;
}
@Override
public Set<IConductor> getConductors()
{
return new HashSet<IConductor>();
}
@Override
public void mergeConnection(IElectricityNetwork network)
{
}
@Override
public void splitNetwork(IConnectionProvider splitPoint)
{
}
@Override
public void cleanUpConductors()
{
}
@Override
public void refreshConductors()
{
}
}

View file

@ -8,6 +8,7 @@ import java.util.List;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
import universalelectricity.core.grid.IGridNetwork;
import universalelectricity.core.path.Pathfinder;
import universalelectricity.core.vector.Vector3;
import universalelectricity.core.vector.VectorHelper;
@ -67,11 +68,10 @@ public abstract class NetworkTileEntities
{
return this.networkMember.contains(ent);
}
/** Removes a tileEntity from any of the valid lists */
public void removeEntity(TileEntity ent)
public boolean removeTile(TileEntity ent)
{
this.networkMember.remove(ent);
return this.networkMember.remove(ent);
}
/** Cleans the list of networkMembers and remove those that no longer belong */
@ -257,7 +257,7 @@ public abstract class NetworkTileEntities
if (checkTile instanceof INetworkPart && ((INetworkPart) checkTile).getTileNetwork() != null)
{
((INetworkPart) checkTile).getTileNetwork().removeEntity(tileEntity);
((INetworkPart) checkTile).getTileNetwork().removeTile(tileEntity);
}
}
}

View file

@ -24,7 +24,7 @@ public class PlayerMsgHelper
for (EntityPlayer player : list)
{
player.sendChatToPlayer(sendMsg);
//player..sendChatToPlayer(sendMsg);
}
}
}

View file

@ -49,7 +49,7 @@ public class EntityTileDamage extends EntityLiving implements IEntityAdditionalS
}
@Override
public boolean attackEntityFrom(DamageSource source, int ammount)
public boolean attackEntityFrom(DamageSource source, float ammount)
{
if (this.host instanceof IHpTile)
{
@ -88,24 +88,6 @@ public class EntityTileDamage extends EntityLiving implements IEntityAdditionalS
return false;
}
@Override
public void addPotionEffect(PotionEffect par1PotionEffect)
{
if (this.isPotionApplicable(par1PotionEffect))
{
if (this.activePotionsMap.containsKey(Integer.valueOf(par1PotionEffect.getPotionID())))
{
((PotionEffect) this.activePotionsMap.get(Integer.valueOf(par1PotionEffect.getPotionID()))).combine(par1PotionEffect);
this.onChangedPotionEffect((PotionEffect) this.activePotionsMap.get(Integer.valueOf(par1PotionEffect.getPotionID())));
}
else
{
this.activePotionsMap.put(Integer.valueOf(par1PotionEffect.getPotionID()), par1PotionEffect);
this.onNewPotionEffect(par1PotionEffect);
}
}
}
@Override
public String getEntityName()
{
@ -234,10 +216,4 @@ public class EntityTileDamage extends EntityLiving implements IEntityAdditionalS
}
return false;
}
@Override
public int getMaxHealth()
{
return this.host != null && host instanceof IHpTile ? ((IHpTile) host).getMaxHealth() : 100;
}
}

View file

@ -12,7 +12,7 @@ public interface IHpTile
* @param ammount - amount of damage
* @return
*/
public boolean onDamageTaken(DamageSource source, int ammount);
public boolean onDamageTaken(DamageSource source, float ammount);
/**
* Is this tile considered too still be alive. Allows for the tile to remain while being

View file

@ -6,6 +6,7 @@ import net.minecraft.client.Minecraft;
import net.minecraft.client.particle.EntityFX;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
@ -74,7 +75,7 @@ public class FXBeam extends EntityFX
/**
* Sets the particle age based on distance.
*/
EntityLiving renderentity = Minecraft.getMinecraft().renderViewEntity;
EntityLivingBase renderentity = Minecraft.getMinecraft().renderViewEntity;
int visibleDistance = 50;
if (!Minecraft.getMinecraft().gameSettings.fancyGraphics)

View file

@ -8,6 +8,7 @@ import java.util.Map.Entry;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiTextField;
import net.minecraft.client.resources.ResourceLocation;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.StringTranslate;
@ -49,7 +50,6 @@ public class GuiGlobalList extends GuiBase implements IScroll
public void initGui()
{
super.initGui();
StringTranslate var1 = StringTranslate.getInstance();
int width = (this.width - this.xSize) / 2;
int height = (this.height - this.ySize) / 2;
@ -130,7 +130,8 @@ public class GuiGlobalList extends GuiBase implements IScroll
@Override
protected void drawBackgroundLayer(int x, int y, float var1)
{
this.mc.renderEngine.bindTexture(DarkMain.GUI_DIRECTORY + "gui_access_base.png");
ResourceLocation name = new ResourceLocation(DarkMain.GUI_DIRECTORY + ":gui_access_base.png");
this.mc.renderEngine.func_110577_a(name);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
int containerWidth = (this.width - this.xSize) / 2;

View file

@ -0,0 +1,73 @@
package dark.library.machine;
import dark.core.PowerSystems;
import net.minecraftforge.common.ForgeDirection;
import universalelectricity.core.electricity.ElectricityPack;
import buildcraft.api.power.PowerProvider;
public class BcToUeProvider extends PowerProvider
{
public TileEntityElectricMachine tileEntity;
public BcToUeProvider(TileEntityElectricMachine tile)
{
tileEntity = tile;
}
@Override
public void receiveEnergy(float quantity, ForgeDirection from)
{
powerSources[from.ordinal()] = 2;
tileEntity.receiveElectricity(from, new ElectricityPack((PowerSystems.BC3_RATIO * quantity), tileEntity.getVoltage()), true);
}
@Override
public float useEnergy(float min, float max, boolean doUse)
{
float result = 0;
if (tileEntity.getEnergyStored() >= min)
{
if (tileEntity.getEnergyStored() <= max)
{
result = (float) tileEntity.getEnergyStored();
if (doUse)
{
tileEntity.setEnergyStored(0);
}
}
else
{
result = max;
if (doUse)
{
tileEntity.setEnergyStored(tileEntity.getEnergyStored() - max);
}
}
}
return result;
}
@Override
public float getEnergyStored()
{
return (float) this.tileEntity.getEnergyStored();
}
@Override
public int getMaxEnergyReceived()
{
return (int) Math.ceil(this.tileEntity.getMaxEnergyStored());
}
@Override
public int getMaxEnergyStored()
{
return (int) Math.ceil(this.tileEntity.getMaxEnergyStored());
}
}

View file

@ -0,0 +1,187 @@
package dark.library.machine;
import java.util.Random;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.ForgeDirection;
import universalelectricity.core.block.IDisableable;
import universalelectricity.core.block.IElectrical;
import universalelectricity.core.block.IElectricalStorage;
import universalelectricity.core.electricity.ElectricityPack;
import universalelectricity.prefab.tile.ElectricityHandler;
import universalelectricity.prefab.tile.TileEntityAdvanced;
import buildcraft.api.power.IPowerProvider;
import buildcraft.api.power.IPowerReceptor;
import dark.core.PowerSystems;
public abstract class TileEntityElectricMachine extends TileEntityAdvanced implements IDisableable, IElectrical, IElectricalStorage, IPowerReceptor
{
/** Internal Battery & Energy handler */
private ElectricityHandler electricityHandler;
/** Rool the dice and see what you get */
protected Random random = new Random();
/** Remaining ticks of time to remain disabled */
protected int ticksDisabled = 0;
/** Max energy storage limit */
protected int maxEnergy;
/** Energy needed to run per tick regardless of function */
protected int tickEnergy;
/** Should this machine run without power */
protected boolean runWithOutPower = false;
/** BuildCraft power provider? */
private IPowerProvider powerProvider;
public TileEntityElectricMachine(int maxEnergy, int tickEnergy)
{
this.maxEnergy = maxEnergy;
this.tickEnergy = tickEnergy;
}
@Override
public void updateEntity()
{
super.updateEntity();
if (this.ticksDisabled > 0)
{
this.ticksDisabled--;
this.whileDisable();
}
}
public ElectricityHandler ElectricHandler()
{
if (this.electricityHandler == null)
{
this.electricityHandler = new ElectricityHandler(this, 0, this.maxEnergy);
}
return this.electricityHandler;
}
@Override
public boolean canConnect(ForgeDirection direction)
{
return true;
}
@Override
public float receiveElectricity(ForgeDirection from, ElectricityPack receive, boolean doReceive)
{
if (this.runWithOutPower || receive == null || !this.canConnect(from))
{
return 0;
}
if (receive != null && receive.voltage > (Math.sqrt(2) * this.getVoltage()) && this.random.nextBoolean())
{
if (doReceive)
{
this.onDisable(20 + this.random.nextInt(100));
}
return 0;
}
return this.ElectricHandler().receiveElectricity(receive, doReceive);
}
@Override
public ElectricityPack provideElectricity(ForgeDirection from, ElectricityPack request, boolean doProvide)
{
if (from == ForgeDirection.UNKNOWN)
{
return this.electricityHandler.provideElectricity(request, doProvide);
}
return null;
}
@Override
public float getVoltage()
{
return 240;
}
@Override
public void setEnergyStored(float energy)
{
this.ElectricHandler().setEnergyStored(energy);
}
@Override
public float getEnergyStored()
{
return this.ElectricHandler().getEnergyStored();
}
@Override
public float getMaxEnergyStored()
{
return this.ElectricHandler().getMaxEnergyStored();
}
/** Called every tick while this tile entity is disabled. */
protected void whileDisable()
{
//TODO generate electric sparks
}
@Override
public void onDisable(int duration)
{
this.ticksDisabled = duration;
}
@Override
public boolean isDisabled()
{
return this.ticksDisabled > 0;
}
/** Buildcraft */
@Override
public void setPowerProvider(IPowerProvider provider)
{
this.powerProvider = provider;
}
@Override
public IPowerProvider getPowerProvider()
{
if (this.powerProvider == null)
{
this.powerProvider = new BcToUeProvider(this);
}
return this.powerProvider;
}
@Override
public void doWork()
{
}
@Override
public void readFromNBT(NBTTagCompound nbt)
{
super.readFromNBT(nbt);
this.ElectricHandler().readFromNBT(nbt);
this.ticksDisabled = nbt.getInteger("disabledTicks");
this.runWithOutPower = nbt.getBoolean("shouldPower");
if (nbt.hasKey("wattsReceived"))
{
this.ElectricHandler().setEnergyStored((float) nbt.getDouble("wattsReceived"));
}
}
@Override
public void writeToNBT(NBTTagCompound nbt)
{
super.writeToNBT(nbt);
this.ElectricHandler().writeToNBT(nbt);
nbt.setInteger("disabledTicks", this.ticksDisabled);
nbt.setBoolean("shouldPower", this.runWithOutPower);
}
}

View file

@ -1,316 +1,73 @@
package dark.library.machine;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.oredict.OreDictionary;
import universalelectricity.core.UniversalElectricity;
import universalelectricity.core.block.IConnector;
import universalelectricity.core.block.IVoltage;
import universalelectricity.core.electricity.ElectricityNetworkHelper;
import universalelectricity.core.electricity.ElectricityPack;
import universalelectricity.core.electricity.IElectricityNetwork;
import universalelectricity.core.vector.Vector3;
import universalelectricity.prefab.tile.TileEntityElectrical;
import buildcraft.api.power.IPowerProvider;
import buildcraft.api.power.IPowerReceptor;
import buildcraft.api.power.PowerFramework;
import buildcraft.api.power.PowerProvider;
import dark.core.PowerSystems;
import dark.core.api.INetworkPart;
public abstract class TileEntityRunnableMachine extends TileEntityElectrical implements IPowerReceptor, IConnector, IVoltage
public class TileEntityRunnableMachine extends TileEntityElectricMachine
{
/** Forge Ore Directory name of the item to toggle power */
public static String powerToggleItemID = "battery";
/** Should this machine run without power */
protected boolean runPowerless = false;
/** BuildCraft power provider? */
private IPowerProvider powerProvider;
public double prevWatts, wattsReceived = 0;
private PowerSystems[] powerList = new PowerSystems[] { PowerSystems.BUILDCRAFT, PowerSystems.MEKANISM };
@Override
public void updateEntity()
public TileEntityRunnableMachine(int tickEnergy)
{
super.updateEntity();
this.prevWatts = this.wattsReceived;
if (!this.worldObj.isRemote)
{
if (!this.isDisabled() && (this.runPowerless || PowerSystems.runPowerLess(powerList)) && this.wattsReceived < this.getBattery(ForgeDirection.UNKNOWN))
{
this.wattsReceived += Math.max(this.getBattery(ForgeDirection.UNKNOWN) - this.wattsReceived, 0);
}
else
{
this.doPowerUpdate();
}
}
super(tickEnergy * 2, tickEnergy);
}
/** Any updating for power. Called seperate from the main update method too allow for inf power
* without unneeded power drain */
public void doPowerUpdate()
/** Forge Ore Directory name of the item to toggle power */
public static String powerToggleItemID = "battery";
/** Power Systems this machine can support */
private PowerSystems[] powerList = new PowerSystems[] { PowerSystems.BUILDCRAFT, PowerSystems.MEKANISM };
/** Does this tile have power to run and do work */
public boolean canRun()
{
// UNIVERSAL ELECTRICITY UPDATE
if (!this.isDisabled())
boolean power = this.getEnergyStored() >= this.tickEnergy || this.runWithOutPower || PowerSystems.runPowerLess(powerList);
return !this.isDisabled() && power;
}
/** Called when a player activates the tile's block */
public boolean onPlayerActivated(EntityPlayer player)
{
if (player != null && player.capabilities.isCreativeMode)
{
ElectricityPack electricityPack = TileEntityRunnableMachine.consumeFromMultipleSides(this, this.getConsumingSides(), ElectricityPack.getFromWatts(this.getRequest(ForgeDirection.UNKNOWN), this.getVoltage()));
this.onReceive(ForgeDirection.UNKNOWN, electricityPack.voltage, electricityPack.amperes);
ItemStack itemStack = player.getHeldItem();
if (itemStack != null)
{
for (ItemStack stack : OreDictionary.getOres(TileEntityRunnableMachine.powerToggleItemID))
{
if (stack.isItemEqual(itemStack))
{
this.runWithOutPower = !this.runWithOutPower;
//player.sendChatToPlayer(chatmessagecomponent)
return true;
}
}
}
}
else
{
ElectricityNetworkHelper.consumeFromMultipleSides(this, new ElectricityPack(0, 0));
}
//TODO add other power systems
return false;
}
@Override
public float getRequest(ForgeDirection direction)
{
return Math.max(this.getMaxEnergyStored() - this.getEnergyStored(), 0);
}
@Override
public int powerRequest(ForgeDirection from)
{
if (this.canConnect(from) && !this.runPowerless)
if (this.canConnect(from) && !this.runWithOutPower)
{
return (int) Math.ceil(this.getRequest(from) * UniversalElectricity.TO_BC_RATIO);
return (int) Math.ceil(this.getRequest(from) * PowerSystems.TO_BC_RATIO);
}
return 0;
}
protected EnumSet<ForgeDirection> getConsumingSides()
{
return ElectricityNetworkHelper.getDirections(this);
}
/** Watts this tile want to receive each tick
**
* @param side - If side == UNKNOWN then either the method that called it doesn't use sides or
* it was called from inside the machine or by the power provider. Return request equal to that
* off all sides at the given time */
public abstract double getRequest(ForgeDirection side);
/** Called when this tile gets power. Should equal getRequest or power will be wasted
*
* @param voltage - E pressure
* @param amperes - E flow rate
* @param side - If side == UNKNOWN then either the method that called it doesn't use sides or
* it was called from inside the machine or by the power provider. Accept power as an internal
* amount */
public void onReceive(ForgeDirection side, double voltage, double amperes)
{
if (voltage > this.getVoltage())
{
this.onDisable(2);
return;
}
this.wattsReceived = Math.min(this.wattsReceived + (voltage * amperes), this.getBattery(side));
}
/** Amount of Watts the internal battery/cap can store.
*
* @param side - If side == UNKNOWN then either the method that called it doesn't use sides or
* it was called from inside the machine or by the power provider. Return amount of all sides in
* this case */
public double getBattery(ForgeDirection side)
{
return this.getRequest(side) * 2;
}
/** Amount of energy currently stored for use.
*
* @param side - If side == UNKNOWN then either the method that called it doesn't use sides or
* it was called from inside the machine or by the power provider. Return amount of all sides in
* this case */
public double getCurrentBattery(ForgeDirection side)
{
return this.wattsReceived;
}
/** Sets this machine to run without power only if the given stack match an ore directory name */
public void toggleInfPower(ItemStack item)
{
if (item != null)
{
for (ItemStack stack : OreDictionary.getOres(TileEntityRunnableMachine.powerToggleItemID))
{
if (stack.isItemEqual(item))
{
this.runPowerless = !this.runPowerless;
break;
}
}
}
}
@Override
public void readFromNBT(NBTTagCompound nbt)
public float getProvide(ForgeDirection direction)
{
super.readFromNBT(nbt);
this.wattsReceived = nbt.getDouble("wattsReceived");
this.runPowerless = nbt.getBoolean("shouldPower");
this.disabledTicks = nbt.getInteger("disabledTicks");
}
@Override
public void writeToNBT(NBTTagCompound nbt)
{
super.writeToNBT(nbt);
nbt.setDouble("wattsReceived", this.wattsReceived);
nbt.setBoolean("shouldPower", this.runPowerless);
nbt.setInteger("disabledTicks", this.disabledTicks);
}
public static ElectricityPack consumeFromMultipleSides(TileEntity tileEntity, EnumSet<ForgeDirection> approachingDirection, ElectricityPack requestPack)
{
ElectricityPack consumedPack = new ElectricityPack();
if (tileEntity != null && approachingDirection != null)
{
final List<IElectricityNetwork> connectedNetworks = getNetworksFromMultipleSides(tileEntity, approachingDirection);
if (connectedNetworks.size() > 0)
{
/** Requests an even amount of electricity from all sides. */
double wattsPerSide = (requestPack.getWatts() / connectedNetworks.size());
double voltage = requestPack.voltage;
/*TODO change this out to calculate if the network on each side can handle a larger request than another network to evenly distribute drain rather than asked the same of a network they may not be able to put out a larger amount*/
for (IElectricityNetwork network : connectedNetworks)
{
if (wattsPerSide > 0 && requestPack.getWatts() > 0)
{
network.startRequesting(tileEntity, wattsPerSide / voltage, voltage);
ElectricityPack receivedPack = network.consumeElectricity(tileEntity);
consumedPack = ElectricityPack.getFromWatts(consumedPack.getWatts() + receivedPack.getWatts(), Math.max(consumedPack.voltage, receivedPack.voltage));
}
else
{
network.stopRequesting(tileEntity);
}
}
}
}
return consumedPack;
}
public static List<IElectricityNetwork> getNetworksFromMultipleSides(TileEntity tileEntity, EnumSet<ForgeDirection> approachingDirection)
{
final List<IElectricityNetwork> connectedNetworks = new ArrayList<IElectricityNetwork>();
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS)
{
if (approachingDirection.contains(direction))
{
Vector3 position = new Vector3(tileEntity);
position.modifyPositionFromSide(direction);
TileEntity outputConductor = position.getTileEntity(tileEntity.worldObj);
IElectricityNetwork electricityNetwork = ElectricityNetworkHelper.getNetworkFromTileEntity(outputConductor, direction);
if (electricityNetwork != null && !connectedNetworks.contains(connectedNetworks))
{
if (tileEntity instanceof INetworkPart && outputConductor instanceof INetworkPart && ((INetworkPart) tileEntity).getTileNetwork().isPartOfNetwork(outputConductor))
{
continue;
}
connectedNetworks.add(electricityNetwork);
}
}
}
return connectedNetworks;
}
/** Buildcraft */
@Override
public void setPowerProvider(IPowerProvider provider)
{
this.powerProvider = provider;
}
@Override
public IPowerProvider getPowerProvider()
{
if (this.powerProvider == null)
{
this.powerProvider = new RunPowerProvider(this);
}
return this.powerProvider;
}
@Override
public void doWork()
{
}
class RunPowerProvider extends PowerProvider
{
public TileEntityRunnableMachine tileEntity;
public RunPowerProvider(TileEntityRunnableMachine tile)
{
tileEntity = tile;
}
@Override
public void receiveEnergy(float quantity, ForgeDirection from)
{
powerSources[from.ordinal()] = 2;
tileEntity.onReceive(ForgeDirection.UNKNOWN, tileEntity.getVoltage(), (UniversalElectricity.BC3_RATIO * quantity) / tileEntity.getVoltage());
}
@Override
public float useEnergy(float min, float max, boolean doUse)
{
float result = 0;
if (tileEntity.wattsReceived >= min)
{
if (tileEntity.wattsReceived <= max)
{
result = (float) tileEntity.wattsReceived;
if (doUse)
{
tileEntity.wattsReceived = 0;
}
}
else
{
result = max;
if (doUse)
{
tileEntity.wattsReceived -= max;
}
}
}
return result;
}
@Override
public float getEnergyStored()
{
return (float) this.tileEntity.getCurrentBattery(ForgeDirection.UNKNOWN);
}
@Override
public int getMaxEnergyReceived()
{
return (int) Math.ceil(this.tileEntity.getBattery(ForgeDirection.UNKNOWN));
}
@Override
public int getMaxEnergyStored()
{
return (int) Math.ceil(this.tileEntity.getBattery(ForgeDirection.UNKNOWN));
}
return 0;
}
}

View file

@ -16,10 +16,10 @@ public abstract class ContainerTerminal extends Container
}
@Override
public void onCraftGuiClosed(EntityPlayer par1EntityPlayer)
public void onContainerClosed(EntityPlayer par1EntityPlayer)
{
this.tileEntity.playersUsing.remove(par1EntityPlayer);
super.onCraftGuiClosed(par1EntityPlayer);
super.onContainerClosed(par1EntityPlayer);
}
@Override