package com.thebrokenrail.energonrelics.block.entity; import com.thebrokenrail.energonrelics.api.block.entity.helper.EnergyGeneratorBlockEntity; import com.thebrokenrail.energonrelics.config.HardcodedConfig; import com.thebrokenrail.energonrelics.api.energy.tick.EnergyTickable; import net.minecraft.block.entity.BlockEntityType; import net.minecraft.util.math.Direction; import net.minecraft.world.LightType; import java.util.List; import java.util.Objects; public class SolarPanelBlockEntity extends EnergyGeneratorBlockEntity { public SolarPanelBlockEntity(BlockEntityType type) { super(type); } private int getLight(Direction side) { assert getWorld() != null; return getWorld().getLightLevel(LightType.SKY, getPos().offset(side)) - getWorld().getAmbientDarkness(); } private int getLight() { int light = 0; for (Direction side : Direction.values()) { light = Math.max(light, getLight(side)); } return light; } @Override public long getDisplayEnergy() { if (hasWorld() && Objects.requireNonNull(getWorld()).getDimension().hasSkyLight()) { int light = getLight(); return (long) ((float) HardcodedConfig.SOLAR_PANEL_MAX_ENERGY_OUTPUT * ((float) light / 15f)); } else { return 0; } } @Override public List startTick() { setEnergy(getDisplayEnergy()); return super.startTick(); } }