forked from TheBrokenRail/EnergonRelics
45 lines
1.3 KiB
Java
45 lines
1.3 KiB
Java
|
package com.thebrokenrail.energonrelics.block.entity;
|
||
|
|
||
|
import com.thebrokenrail.energonrelics.Config;
|
||
|
import com.thebrokenrail.energonrelics.energy.helper.EnergyGeneratorBlockEntity;
|
||
|
import net.minecraft.block.entity.BlockEntityType;
|
||
|
import net.minecraft.util.math.Direction;
|
||
|
import net.minecraft.world.LightType;
|
||
|
|
||
|
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) Config.SOLAR_PANEL_MAX_ENERGY_OUTPUT * ((float) light / 15f));
|
||
|
} else {
|
||
|
return 0;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
protected void serverTick() {
|
||
|
setEnergy(getDisplayEnergy());
|
||
|
super.serverTick();
|
||
|
}
|
||
|
}
|