import com.google.common.base.Suppliers;
import com.google.common.collect.Maps;
+import dev.architectury.injectables.annotations.ExpectPlatform;
import it.unimi.dsi.fastutil.longs.Long2ByteMap;
import it.unimi.dsi.fastutil.longs.Long2ByteOpenHashMap;
import net.minecraft.client.Minecraft;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
+import net.minecraft.core.Holder;
import net.minecraft.tags.BlockTags;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
-import net.minecraft.world.entity.MobCategory;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LightLayer;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;
import org.apache.logging.log4j.LogManager;
+import sun.misc.Unsafe;
+import java.lang.reflect.Field;
import java.util.*;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
public final Set<CubicChunkPos> POS = Collections.synchronizedSet(new HashSet<>());
public final Set<CubicChunkPos> CALCULATING_POS = Collections.synchronizedSet(new HashSet<>());
public final Map<CubicChunkPos, Long2ByteMap> CHUNK_MAP = Maps.newConcurrentMap();
- private static final Supplier<EntityType<Entity>> TESTING_ENTITY_TYPE = Suppliers.memoize(() ->
- EntityType.Builder.createNothing(MobCategory.MONSTER).sized(0f, 0f).noSave().build(null));
+ private static final Supplier<EntityType<Entity>> TESTING_ENTITY_TYPE = Suppliers.memoize(() -> {
+ // get unsafe
+ try {
+ Field f = Unsafe.class.getDeclaredField("theUnsafe");
+ f.setAccessible(true);
+ Unsafe unsafe = (Unsafe) f.get(null);
+
+ // instantiate entity type
+ EntityType<Entity> type = (EntityType<Entity>) unsafe.allocateInstance(EntityType.class);
+ return type;
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ });
+
+ @ExpectPlatform
+ public static void populateEntityType(EntityType<Entity> type) {
+ throw new AssertionError();
+ }
public void queueChunk(CubicChunkPos pos) {
if (LightOverlay.enabled && LightOverlay.caching && !CALCULATING_POS.contains(pos)) {
chunkData.put(blockPos.asLong(), (byte) level);
}
} else {
- Biome biome = !LightOverlay.mushroom ? world.getBiome(blockPos) : null;
+ Holder<Biome> biome = !LightOverlay.mushroom ? world.getBiome(blockPos) : null;
byte type = getCrossType(blockPos, biome, downPos, world, block, sky, collisionContext);
if (type != LightOverlay.CROSS_NONE) {
chunkData.put(blockPos.asLong(), type);
chunkData.put(pos.asLong(), (byte) level);
}
} else {
- Biome biome = !LightOverlay.mushroom ? world.getBiome(pos) : null;
+ Holder<Biome> biome = !LightOverlay.mushroom ? world.getBiome(pos) : null;
byte type = getCrossType(pos, biome, down, chunk, block, sky, collisionContext);
if (type != LightOverlay.CROSS_NONE) {
chunkData.put(pos.asLong(), type);
}
}
- public byte getCrossType(BlockPos pos, Biome biome, BlockPos down, BlockGetter world, LayerLightEventListener block, LayerLightEventListener sky, CollisionContext entityContext) {
+ public byte getCrossType(BlockPos pos, Holder<Biome> biome, BlockPos down, BlockGetter world, LayerLightEventListener block, LayerLightEventListener sky, CollisionContext entityContext) {
BlockState blockBelowState = world.getBlockState(down);
BlockState blockUpperState = world.getBlockState(pos);
VoxelShape upperCollisionShape = blockUpperState.getCollisionShape(world, pos, entityContext);
// Check block state allow spawning (excludes bedrock and barriers automatically)
if (!blockBelowState.isValidSpawn(world, down, TESTING_ENTITY_TYPE.get()))
return LightOverlay.CROSS_NONE;
- if (!LightOverlay.mushroom && Biome.BiomeCategory.MUSHROOM == biome.getBiomeCategory())
+ if (!LightOverlay.mushroom && Biome.BiomeCategory.MUSHROOM == Biome.getBiomeCategory(biome))
return LightOverlay.CROSS_NONE;
int blockLightLevel = block.getLightValue(pos);
int skyLightLevel = sky.getLightValue(pos);
return LightOverlay.CROSS_NONE;
if (skyLightLevel > LightOverlay.higherCrossLevel)
return LightOverlay.higherCross;
- return LightOverlay.lowerCrossLevel >= 0 && blockLightLevel > LightOverlay.lowerCrossLevel ?
+ return LightOverlay.lowerCrossLevel >= 0 && blockLightLevel > LightOverlay.lowerCrossLevel ?
LightOverlay.lowerCross : LightOverlay.CROSS_RED;
}
accessible field net/minecraft/client/renderer/culling/Frustum camX D
accessible field net/minecraft/client/renderer/culling/Frustum camY D
accessible field net/minecraft/client/renderer/culling/Frustum camZ D
-accessible field net/minecraft/client/renderer/culling/Frustum frustumData [Lcom/mojang/math/Vector4f;
\ No newline at end of file
+accessible field net/minecraft/client/renderer/culling/Frustum frustumData [Lcom/mojang/math/Vector4f;
+accessible field net/minecraft/world/entity/EntityType factory Lnet/minecraft/world/entity/EntityType$EntityFactory;
+accessible field net/minecraft/world/entity/EntityType category Lnet/minecraft/world/entity/MobCategory;
+accessible field net/minecraft/world/entity/EntityType immuneTo Lcom/google/common/collect/ImmutableSet;
+accessible field net/minecraft/world/entity/EntityType dimensions Lnet/minecraft/world/entity/EntityDimensions;
+mutable field net/minecraft/world/entity/EntityType factory Lnet/minecraft/world/entity/EntityType$EntityFactory;
+mutable field net/minecraft/world/entity/EntityType category Lnet/minecraft/world/entity/MobCategory;
+mutable field net/minecraft/world/entity/EntityType immuneTo Lcom/google/common/collect/ImmutableSet;
+mutable field net/minecraft/world/entity/EntityType dimensions Lnet/minecraft/world/entity/EntityDimensions;
\ No newline at end of file