use of reborncore.api.power.IEnergyInterfaceTile in project TechReborn by TechReborn.
the class ProbeProvider method addProbeInfo.
@Override
public void addProbeInfo(ProbeMode mode, IProbeInfo probeInfo, EntityPlayer player, World world, IBlockState blockState, IProbeHitData data) {
euStyle = new ProgressStyle().backgroundColor(0xFF8B8B8B).borderColor(0xFF373737).alternateFilledColor(PowerSystem.getDisplayPower().altColour).filledColor(PowerSystem.getDisplayPower().colour);
euStyle.suffix(" " + PowerSystem.getDisplayPower().abbreviation);
TileEntity tile = world.getTileEntity(data.getPos());
if (tile instanceof IListInfoProvider) {
List<String> strs = new ArrayList<>();
((IListInfoProvider) tile).addInfo(strs, true);
for (String string : strs) {
probeInfo.text(string);
}
}
if (tile instanceof IEnergyInterfaceTile) {
IEnergyInterfaceTile energy = (IEnergyInterfaceTile) tile;
if (PowerSystem.getDisplayPower() != PowerSystem.EnergySystem.EU) {
probeInfo.progress((int) energy.getEnergy() * RebornCoreConfig.euPerFU, (int) energy.getMaxPower() * RebornCoreConfig.euPerFU, euStyle);
} else {
probeInfo.progress((int) energy.getEnergy(), (int) energy.getMaxPower(), euStyle);
}
}
if (tile instanceof TileLegacyMachineBase && methodHandle_addStacks != null) {
TileLegacyMachineBase legacyMachineBase = (TileLegacyMachineBase) tile;
if (legacyMachineBase.getInventoryForTile().isPresent()) {
if (player.isSneaking()) {
probeInfo.text(I18n.translateToLocal("techreborn.tooltip.inventory"));
}
Inventory inventory = legacyMachineBase.getInventoryForTile().get();
if (!inventory.isEmpty()) {
List<ItemStack> stacks = Arrays.stream(inventory.contents).filter(stack -> !stack.isEmpty()).collect(Collectors.toList());
try {
methodHandle_addStacks.invoke(probeInfo, world, null, stacks, player.isSneaking());
} catch (Throwable throwable) {
throwable.printStackTrace();
}
}
}
if (!legacyMachineBase.upgradeInventory.isEmpty() && player.isSneaking()) {
probeInfo.horizontal();
probeInfo.text(I18n.translateToLocal("techreborn.tooltip.upgrades"));
List<ItemStack> stacks = Arrays.stream(legacyMachineBase.upgradeInventory.contents).filter(stack -> !stack.isEmpty()).collect(Collectors.toList());
try {
methodHandle_addStacks.invoke(probeInfo, world, null, stacks, player.isSneaking());
} catch (Throwable throwable) {
throwable.printStackTrace();
}
}
}
}
use of reborncore.api.power.IEnergyInterfaceTile in project RebornCore by TechReborn.
the class TilePowerAcceptor method update.
@Override
public void update() {
super.update();
if (!world.isRemote) {
Map<EnumFacing, TileEntity> acceptors = new HashMap<EnumFacing, TileEntity>();
if (getEnergy() > 0 && !world.isRemote) {
// Tesla or IC2 should handle this if enabled, so only do this without tesla
for (EnumFacing side : EnumFacing.values()) {
if (canProvideEnergy(side)) {
TileEntity tile = world.getTileEntity(pos.offset(side));
if (tile == null) {
continue;
} else {
acceptors.put(side, tile);
}
}
}
}
if (acceptors.size() > 0) {
double drain = useEnergy(Math.min(getEnergy(), getMaxOutput()), true);
double energyShare = drain / acceptors.size();
double remainingEnergy = drain;
if (energyShare > 0) {
for (Map.Entry<EnumFacing, TileEntity> entry : acceptors.entrySet()) {
EnumFacing side = entry.getKey();
TileEntity tile = entry.getValue();
if (tile instanceof IEnergyInterfaceTile) {
IEnergyInterfaceTile eFace = (IEnergyInterfaceTile) tile;
if (eFace.canAcceptEnergy(side.getOpposite())) {
if (handleTierWithPower() && eFace.getTier().ordinal() < getPushingTier().ordinal()) {
for (int j = 0; j < 2; ++j) {
double d3 = (double) pos.getX() + world.rand.nextDouble() + (side.getFrontOffsetX() / 2);
double d8 = (double) pos.getY() + world.rand.nextDouble() + 1;
double d13 = (double) pos.getZ() + world.rand.nextDouble() + (side.getFrontOffsetZ() / 2);
world.spawnParticle(EnumParticleTypes.SMOKE_LARGE, d3, d8, d13, 0.0D, 0.0D, 0.0D);
}
} else {
double filled = eFace.addEnergy(Math.min(energyShare, remainingEnergy), false);
remainingEnergy -= useEnergy(filled, false);
}
}
} else if (tile.hasCapability(CapabilityEnergy.ENERGY, side.getOpposite())) {
IEnergyStorage energyStorage = tile.getCapability(CapabilityEnergy.ENERGY, side.getOpposite());
if (forgePowerManager != null && energyStorage != null && energyStorage.canReceive() && this.canProvideEnergy(side)) {
int filled = energyStorage.receiveEnergy((int) Math.min(energyShare, remainingEnergy) * RebornCoreConfig.euPerFU, false);
remainingEnergy -= useEnergy(filled / RebornCoreConfig.euPerFU, false);
}
} else if (TeslaManager.isTeslaEnabled(getPowerConfig())) {
TeslaManager.manager.update(this);
}
}
}
}
if (RebornCoreConfig.isIC2Loaded && getPowerConfig().eu() && Info.isIc2Available()) {
onLoaded();
}
powerChange = getEnergy() - powerLastTick;
powerLastTick = getEnergy();
}
}
Aggregations