2021-03-29 10:15:59 +02:00
|
|
|
package appeng.tile.legacy;
|
|
|
|
|
|
|
|
import appeng.api.config.Actionable;
|
|
|
|
import appeng.me.GridAccessException;
|
|
|
|
import appeng.tile.grid.AENetworkPowerTile;
|
|
|
|
import appeng.tile.inventory.AppEngInternalInventory;
|
|
|
|
import appeng.tile.inventory.InvOperation;
|
|
|
|
import net.minecraft.inventory.IInventory;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraftforge.common.util.ForgeDirection;
|
|
|
|
|
|
|
|
public class TileLegacyController extends AENetworkPowerTile {
|
2022-12-02 17:40:47 +01:00
|
|
|
private static final IInventory NULL_INVENTORY = new AppEngInternalInventory(null, 0);
|
2021-03-29 10:15:59 +02:00
|
|
|
private static final int[] ACCESSIBLE_SLOTS_BY_SIDE = {};
|
|
|
|
|
2021-04-03 12:02:52 +02:00
|
|
|
public TileLegacyController() { //TODO Fix power storage
|
2022-12-02 17:40:47 +01:00
|
|
|
this.setInternalMaxPower(10000);
|
|
|
|
this.setInternalPublicPowerStorage(true);
|
2021-04-03 12:02:52 +02:00
|
|
|
this.getProxy().setIdlePowerUsage(6.0);
|
2021-03-29 10:15:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IInventory getInternalInventory() {
|
|
|
|
return NULL_INVENTORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2022-12-02 17:40:47 +01:00
|
|
|
public void onChangeInventory(
|
|
|
|
IInventory inv, int slot, InvOperation mc, ItemStack removed, ItemStack added
|
|
|
|
) {}
|
2021-03-29 10:15:59 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public int[] getAccessibleSlotsBySide(ForgeDirection whichSide) {
|
|
|
|
return ACCESSIBLE_SLOTS_BY_SIDE;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2022-12-02 17:40:47 +01:00
|
|
|
protected double getFunnelPowerDemand(final double maxReceived) {
|
2021-04-03 12:02:52 +02:00
|
|
|
updateMeta();
|
2022-12-02 17:40:47 +01:00
|
|
|
try {
|
|
|
|
return this.getProxy().getEnergy().getEnergyDemand(10000);
|
|
|
|
} catch (final GridAccessException e) {
|
2021-03-29 10:15:59 +02:00
|
|
|
// no grid? use local...
|
2022-12-02 17:40:47 +01:00
|
|
|
return super.getFunnelPowerDemand(maxReceived);
|
2021-03-29 10:15:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2022-12-02 17:40:47 +01:00
|
|
|
protected double funnelPowerIntoStorage(final double power, final Actionable mode) {
|
2021-04-03 12:02:52 +02:00
|
|
|
updateMeta();
|
2022-12-02 17:40:47 +01:00
|
|
|
try {
|
|
|
|
final double ret = this.getProxy().getEnergy().injectPower(power, mode);
|
|
|
|
if (mode == Actionable.SIMULATE) {
|
2021-03-29 10:15:59 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
return 0;
|
2022-12-02 17:40:47 +01:00
|
|
|
} catch (final GridAccessException e) {
|
2021-03-29 10:15:59 +02:00
|
|
|
// no grid? use local...
|
2022-12-02 17:40:47 +01:00
|
|
|
return super.funnelPowerIntoStorage(power, mode);
|
2021-03-29 10:15:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-03 12:02:52 +02:00
|
|
|
public void updateMeta() {
|
2022-12-02 17:40:47 +01:00
|
|
|
int meta = (int
|
|
|
|
) Math.ceil((5.0 * this.getInternalCurrentPower() / this.getInternalMaxPower()));
|
2021-04-03 12:02:52 +02:00
|
|
|
if (meta < 0) {
|
|
|
|
meta = 0;
|
|
|
|
} else if (meta > 5) {
|
|
|
|
meta = 5;
|
|
|
|
}
|
|
|
|
if (getProxy().isActive() && getInternalCurrentPower() == 0.0) {
|
|
|
|
meta = 6;
|
|
|
|
}
|
2022-12-02 17:40:47 +01:00
|
|
|
this.worldObj.setBlockMetadataWithNotify(
|
|
|
|
this.xCoord, this.yCoord, this.zCoord, meta, 2
|
|
|
|
);
|
2021-04-03 12:02:52 +02:00
|
|
|
}
|
2021-03-29 10:15:59 +02:00
|
|
|
}
|