forked from TheBrokenRail/EnergonRelics
48 lines
1.6 KiB
Java
48 lines
1.6 KiB
Java
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.util.math.MathHelper;
|
|
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 (int) (((float) light) * MathHelper.cos(Objects.requireNonNull(getWorld()).getSkyAngleRadians(1f)));
|
|
}
|
|
|
|
@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<EnergyTickable> startTick() {
|
|
setEnergy(getDisplayEnergy());
|
|
return super.startTick();
|
|
}
|
|
}
|