mirror of
https://github.com/Thorfusion/Mekanism-Community-Edition.git
synced 2026-11-28 07:36:01 +00:00
*Shuffled remainder management in gas transmission. *Cleaned up acceptor code. *Fixed outputs. *Added Universal Cable! This cable works with IndustrialCraft, BuildCraft and Mekanism -- distributing with correct ratios. *Updated to Minecraft 1.5.1. *Prevented crashes in bounding blocks. *Bumped version to 5.5.0. *Better energy outputting code for generators and energy cubes. *Made pressurized tubes not require updates. *Fixed bounding block saving incorrect NBT data. *Fixed energy cube tier not updating. *New handy methods in MekanismUtils.
151 lines
3.6 KiB
Java
151 lines
3.6 KiB
Java
package mekanism.generators.common;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import universalelectricity.core.item.ElectricItemHelper;
|
|
|
|
import ic2.api.ElectricItem;
|
|
import ic2.api.IElectricItem;
|
|
import mekanism.common.Mekanism;
|
|
import mekanism.common.PacketHandler;
|
|
import mekanism.generators.common.BlockGenerator.GeneratorType;
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
import net.minecraft.item.ItemStack;
|
|
import net.minecraft.network.INetworkManager;
|
|
import net.minecraft.network.packet.Packet250CustomPayload;
|
|
import net.minecraftforge.common.ForgeDirection;
|
|
|
|
import com.google.common.io.ByteArrayDataInput;
|
|
|
|
import dan200.computer.api.IComputerAccess;
|
|
|
|
public class TileEntitySolarGenerator extends TileEntityGenerator
|
|
{
|
|
/** Whether or not this generator sees the sun. */
|
|
public boolean seesSun = false;
|
|
|
|
/** How fast this tile entity generates energy. */
|
|
public int GENERATION_RATE;
|
|
|
|
public TileEntitySolarGenerator()
|
|
{
|
|
super("Solar Generator", 96000, 80);
|
|
GENERATION_RATE = 40;
|
|
inventory = new ItemStack[1];
|
|
}
|
|
|
|
public TileEntitySolarGenerator(String name, int maxEnergy, int output, int generation)
|
|
{
|
|
super(name, maxEnergy, output);
|
|
GENERATION_RATE = generation;
|
|
inventory = new ItemStack[1];
|
|
}
|
|
|
|
@Override
|
|
public void handleSound() {}
|
|
|
|
@Override
|
|
public int getSizeInventorySide(ForgeDirection side)
|
|
{
|
|
return 1;
|
|
}
|
|
|
|
@Override
|
|
public boolean canSetFacing(int facing)
|
|
{
|
|
return facing != 0 && facing != 1;
|
|
}
|
|
|
|
@Override
|
|
public void onUpdate()
|
|
{
|
|
super.onUpdate();
|
|
|
|
if(inventory[0] != null && electricityStored > 0)
|
|
{
|
|
setJoules(getJoules() - ElectricItemHelper.chargeItem(inventory[0], getJoules(), getVoltage()));
|
|
|
|
if(Mekanism.hooks.IC2Loaded && inventory[0].getItem() instanceof IElectricItem)
|
|
{
|
|
double sent = ElectricItem.charge(inventory[0], (int)(electricityStored*Mekanism.TO_IC2), 3, false, false)*Mekanism.FROM_IC2;
|
|
setJoules(electricityStored - sent);
|
|
}
|
|
}
|
|
|
|
if(!worldObj.isRemote)
|
|
{
|
|
if(worldObj.isDaytime() && !worldObj.isRaining() && !worldObj.isThundering() && !worldObj.provider.hasNoSky && worldObj.canBlockSeeTheSky(xCoord, yCoord+1, zCoord))
|
|
{
|
|
seesSun = true;
|
|
}
|
|
else {
|
|
seesSun = false;
|
|
}
|
|
|
|
if(worldObj.getBlockId(xCoord, yCoord+1, zCoord) == MekanismGenerators.generatorID && worldObj.getBlockMetadata(xCoord, yCoord+1, zCoord) == GeneratorType.SOLAR_GENERATOR.meta)
|
|
{
|
|
seesSun = false;
|
|
}
|
|
}
|
|
|
|
if(canOperate())
|
|
{
|
|
setJoules(electricityStored + getEnvironmentBoost());
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public boolean canOperate()
|
|
{
|
|
return electricityStored < MAX_ELECTRICITY && seesSun;
|
|
}
|
|
|
|
@Override
|
|
public int getEnvironmentBoost()
|
|
{
|
|
return seesSun ? GENERATION_RATE : 0;
|
|
}
|
|
|
|
@Override
|
|
public String[] getMethodNames()
|
|
{
|
|
return new String[] {"getStored", "getOutput", "getMaxEnergy", "getEnergyNeeded", "getSeesSun"};
|
|
}
|
|
|
|
@Override
|
|
public Object[] callMethod(IComputerAccess computer, int method, Object[] arguments) throws Exception
|
|
{
|
|
switch(method)
|
|
{
|
|
case 0:
|
|
return new Object[] {electricityStored};
|
|
case 1:
|
|
return new Object[] {output};
|
|
case 2:
|
|
return new Object[] {MAX_ELECTRICITY};
|
|
case 3:
|
|
return new Object[] {(MAX_ELECTRICITY-electricityStored)};
|
|
case 4:
|
|
return new Object[] {seesSun};
|
|
default:
|
|
System.err.println("[Mekanism] Attempted to call unknown method with computer ID " + computer.getID());
|
|
return null;
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void handlePacketData(ByteArrayDataInput dataStream)
|
|
{
|
|
super.handlePacketData(dataStream);
|
|
seesSun = dataStream.readBoolean();
|
|
}
|
|
|
|
@Override
|
|
public ArrayList getNetworkedData(ArrayList data)
|
|
{
|
|
super.getNetworkedData(data);
|
|
data.add(seesSun);
|
|
return data;
|
|
}
|
|
}
|