2021-09-05 01:40:40 +02:00
|
|
|
package com.jozufozu.flywheel.light;
|
|
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.WeakHashMap;
|
|
|
|
|
2021-09-15 08:45:29 +02:00
|
|
|
import net.minecraft.core.BlockPos;
|
|
|
|
import net.minecraft.world.level.BlockAndTintGetter;
|
|
|
|
import net.minecraft.world.level.LightLayer;
|
2021-09-05 01:40:40 +02:00
|
|
|
|
|
|
|
public class BasicProvider implements LightProvider {
|
|
|
|
|
2021-09-15 08:45:29 +02:00
|
|
|
private static final Map<BlockAndTintGetter, BasicProvider> wrappers = new WeakHashMap<>();
|
2021-09-05 01:40:40 +02:00
|
|
|
|
2021-09-15 08:45:29 +02:00
|
|
|
public static BasicProvider get(BlockAndTintGetter world) {
|
2021-09-05 01:40:40 +02:00
|
|
|
return wrappers.computeIfAbsent(world, BasicProvider::new);
|
|
|
|
}
|
|
|
|
|
2021-09-15 08:45:29 +02:00
|
|
|
private final BlockPos.MutableBlockPos pos = new BlockPos.MutableBlockPos();
|
2021-09-05 01:40:40 +02:00
|
|
|
|
2021-09-15 08:45:29 +02:00
|
|
|
private final BlockAndTintGetter reader;
|
2021-09-05 01:40:40 +02:00
|
|
|
|
2021-09-15 08:45:29 +02:00
|
|
|
public BasicProvider(BlockAndTintGetter reader) {
|
2021-09-05 01:40:40 +02:00
|
|
|
this.reader = reader;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-09-15 08:45:29 +02:00
|
|
|
public int getLight(LightLayer type, int x, int y, int z) {
|
2021-09-05 01:40:40 +02:00
|
|
|
return reader.getBrightness(type, pos.set(x, y, z));
|
|
|
|
}
|
|
|
|
}
|