2020-07-13 20:37:21 +00:00
|
|
|
package com.thebrokenrail.energonrelics.block.entity;
|
|
|
|
|
2020-08-04 17:06:11 +00:00
|
|
|
import com.thebrokenrail.energonrelics.api.block.entity.helper.EnergyGeneratorBlockEntity;
|
2020-07-17 16:14:27 +00:00
|
|
|
import com.thebrokenrail.energonrelics.config.HardcodedConfig;
|
2020-08-04 17:06:11 +00:00
|
|
|
import com.thebrokenrail.energonrelics.api.energy.tick.EnergyTickable;
|
2020-07-13 20:37:21 +00:00
|
|
|
import net.minecraft.block.entity.BlockEntityType;
|
|
|
|
import net.minecraft.util.math.Direction;
|
|
|
|
import net.minecraft.world.LightType;
|
|
|
|
|
2020-07-24 17:25:50 +00:00
|
|
|
import java.util.List;
|
2020-07-13 20:37:21 +00:00
|
|
|
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();
|
2020-07-17 16:14:27 +00:00
|
|
|
return (long) ((float) HardcodedConfig.SOLAR_PANEL_MAX_ENERGY_OUTPUT * ((float) light / 15f));
|
2020-07-13 20:37:21 +00:00
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-07-26 22:31:05 +00:00
|
|
|
public List<EnergyTickable> startTick() {
|
2020-07-22 23:51:42 +00:00
|
|
|
setEnergy(getDisplayEnergy());
|
2020-07-24 17:25:50 +00:00
|
|
|
return super.startTick();
|
2020-07-13 20:37:21 +00:00
|
|
|
}
|
|
|
|
}
|