I was trying to make my own type of TileEntity accept EU using IEnergySink.
I am using BasicSink. I got cables to connect, however the energy is not being directed to the TE.
Here is the Tile Entity:
Java: TileICEngine.java
package com.zeitheron.aps.intr.ic2.blocks.tiles;
import com.zeitheron.aps.InfoAR;
import com.zeitheron.hammercore.internal.capabilities.FEEnergyStorage;
import com.zeitheron.hammercore.tile.TileSyncableTickable;
import com.zeitheron.hammercore.utils.FrictionRotator;
import com.zeitheron.hammercore.utils.WorldUtil;
import ic2.api.energy.EnergyNet;
import ic2.api.energy.prefab.BasicSink;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.energy.CapabilityEnergy;
import net.minecraftforge.energy.IEnergyStorage;
public class TileICEngine extends TileSyncableTickable implements IEnergyStorage
{
public final FEEnergyStorage energy = new FEEnergyStorage(getFECapacity());
private boolean setup = false;
public ResourceLocation baseTexture = new ResourceLocation(InfoAR.MOD_ID, "textures/models/engines/base_esteam.png");
public double maxChargeEU = 0;
public double maxVoltage;
public int sinkTier;
public double euPerTick = 8;
public float pistonSpeed = .15F;
public BasicSink sink = createSink();
public EnumFacing getOrientation()
{
return WorldUtil.getFacing(world.getBlockState(pos));
}
public BasicSink createSink()
{
return new BasicSink(this, maxChargeEU, sinkTier);
}
public void setSinkTier(int sinkTier)
{
double euMax = EnergyNet.instance.getPowerFromTier(sinkTier);
this.maxVoltage = euMax;
this.euPerTick = euMax / 4;
this.sinkTier = sinkTier;
}
public int getFECapacity()
{
return (int) (euPerTick * 1000);
}
public FrictionRotator rotator = new FrictionRotator();
{
rotator.friction = .1F;
}
@Override
public boolean hasGui()
{
return true;
}
// TODO: Implement GUI stuff
@Override
public Object getClientGuiElement(EntityPlayer player)
{
return null;
}
@Override
public Object getServerGuiElement(EntityPlayer player)
{
return null;
}
public void doSetup()
{
sink.onLoad();
setup = true;
}
public boolean canWork()
{
return world.getRedstonePowerFromNeighbors(pos) > 0;
}
@Override
public void tick()
{
if(!setup)
doSetup();
sink.update();
rotator.update();
if(!canWork())
return;
doConversionLoop();
EnumFacing face = getOrientation();
TileEntity receptor = world.getTileEntity(pos.offset(face));
if(receptor != null)
{
IEnergyStorage storage = receptor.hasCapability(CapabilityEnergy.ENERGY, face.getOpposite()) ? receptor.getCapability(CapabilityEnergy.ENERGY, face.getOpposite()) : null;
boolean changed = false;
if(storage != null && storage.canReceive())
{
int io = energy.extractEnergy(storage.receiveEnergy(energy.getEnergyStored(), false), false);
if(io > 0)
changed = true;
}
if(changed && atTickRate(60))
sendChangesToNearby();
}
}
public void doConversionLoop()
{
if(!world.isRemote && sink.useEnergy(euPerTick))
{
energy.receiveEnergy((int) Math.floor(euPerTick * 4), false);
rotator.speedup(.2F);
if(atTickRate(10))
sendChangesToNearby();
}
}
@Override
public void invalidate()
{
sink.invalidate();
super.invalidate();
}
@Override
public void onChunkUnload()
{
sink.onChunkUnload();
}
@Override
public boolean hasCapability(Capability<?> capability, EnumFacing facing)
{
if(capability == CapabilityEnergy.ENERGY)
return facing == getOrientation();
return super.hasCapability(capability, facing);
}
@Override
public <T> T getCapability(Capability<T> capability, EnumFacing facing)
{
if(capability == CapabilityEnergy.ENERGY)
return (T) this;
return super.getCapability(capability, facing);
}
@Override
public void writeNBT(NBTTagCompound nbt)
{
sink.writeToNBT(nbt);
nbt.setTag("FE", energy.writeToNBT(new NBTTagCompound()));
nbt.setFloat("PDegree", rotator.degree);
nbt.setFloat("PSpeed", rotator.speed);
nbt.setFloat("PCSpeed", rotator.currentSpeed);
}
@Override
public void readNBT(NBTTagCompound nbt)
{
sink.readFromNBT(nbt);
energy.readFromNBT(nbt.getCompoundTag("FE"));
rotator.degree = nbt.getFloat("PDegree");
rotator.speed = nbt.getFloat("PSpeed");
rotator.currentSpeed = nbt.getFloat("PCSpeed");
}
@Override
public int receiveEnergy(int maxReceive, boolean simulate)
{
return 0;
}
@Override
public int extractEnergy(int maxExtract, boolean simulate)
{
return energy.extractEnergy(maxExtract, simulate);
}
@Override
public int getEnergyStored()
{
return energy.getEnergyStored();
}
@Override
public int getMaxEnergyStored()
{
return energy.getMaxEnergyStored();
}
@Override
public boolean canExtract()
{
return true;
}
@Override
public boolean canReceive()
{
return false;
}
}
Display More
I may later ask here if I would have problems with BasicSource