diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/util/IMatteryLevel.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/util/LevelUtils.kt similarity index 56% rename from src/main/kotlin/ru/dbotthepony/mc/otm/util/IMatteryLevel.kt rename to src/main/kotlin/ru/dbotthepony/mc/otm/util/LevelUtils.kt index 064f954be..2ac097470 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/util/IMatteryLevel.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/util/LevelUtils.kt @@ -1,7 +1,42 @@ package ru.dbotthepony.mc.otm.util +import net.minecraft.core.BlockPos +import net.minecraft.core.SectionPos import net.minecraft.util.RandomSource +import net.minecraft.world.level.ChunkPos import net.minecraft.world.level.Level +import net.minecraft.world.level.LevelAccessor +import net.minecraft.world.level.block.Blocks +import net.minecraft.world.level.block.entity.BlockEntity +import net.minecraft.world.level.block.state.BlockState +import net.minecraft.world.level.chunk.ChunkSource +import net.minecraft.world.level.chunk.LevelChunk + +fun LevelAccessor.getBlockStateNow(pos: BlockPos): BlockState { + return getBlockStateNowOrNull(pos) ?: Blocks.AIR.defaultBlockState() +} + +fun LevelAccessor.getBlockStateNowOrNull(pos: BlockPos): BlockState? { + return chunkSource.getChunkNow( + SectionPos.blockToSectionCoord(pos.x), + SectionPos.blockToSectionCoord(pos.z) + )?.getBlockState(pos) +} + +fun LevelAccessor.getBlockEntityNow(pos: BlockPos): BlockEntity? { + return chunkSource.getChunkNow( + SectionPos.blockToSectionCoord(pos.x), + SectionPos.blockToSectionCoord(pos.z) + )?.getBlockEntity(pos) +} + +fun ChunkSource.getChunkNow(pos: BlockPos): LevelChunk? { + return getChunkNow(SectionPos.blockToSectionCoord(pos.x), SectionPos.blockToSectionCoord(pos.z)) +} + +fun ChunkSource.getChunkNow(pos: ChunkPos): LevelChunk? { + return getChunkNow(pos.x, pos.z) +} interface IMatteryLevel { val otmRandom: RandomSource? diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/util/Utils.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/util/Utils.kt index f18c09f9e..e35540c37 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/util/Utils.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/util/Utils.kt @@ -7,20 +7,15 @@ import com.github.benmanes.caffeine.cache.Cache import com.github.benmanes.caffeine.cache.Caffeine import com.github.benmanes.caffeine.cache.Scheduler import com.google.common.collect.ImmutableList -import com.google.common.collect.ImmutableMap -import com.google.common.collect.ImmutableMultimap -import com.google.common.collect.ImmutableSet import com.google.gson.JsonElement import com.google.gson.JsonObject import com.google.gson.JsonPrimitive -import it.unimi.dsi.fastutil.objects.ObjectComparators import net.minecraft.Util import net.minecraft.core.BlockPos import net.minecraft.core.Holder import net.minecraft.core.HolderLookup import net.minecraft.core.IdMap import net.minecraft.core.Registry -import net.minecraft.core.SectionPos import net.minecraft.core.registries.BuiltInRegistries import net.minecraft.network.FriendlyByteBuf import net.minecraft.network.RegistryFriendlyByteBuf @@ -38,17 +33,11 @@ import net.minecraft.world.item.component.ItemAttributeModifiers import net.minecraft.world.item.crafting.CraftingInput import net.minecraft.world.item.crafting.RecipeInput import net.minecraft.world.level.BlockGetter -import net.minecraft.world.level.ChunkPos import net.minecraft.world.level.Level -import net.minecraft.world.level.LevelAccessor import net.minecraft.world.level.block.Block -import net.minecraft.world.level.block.Blocks -import net.minecraft.world.level.block.entity.BlockEntity import net.minecraft.world.level.block.state.BlockState import net.minecraft.world.level.block.state.StateHolder import net.minecraft.world.level.block.state.properties.Property -import net.minecraft.world.level.chunk.ChunkSource -import net.minecraft.world.level.chunk.LevelChunk import net.minecraft.world.phys.Vec3 import net.neoforged.neoforge.fluids.FluidStack import net.neoforged.neoforge.items.IItemHandler @@ -63,7 +52,6 @@ import java.time.Duration import java.util.* import java.util.concurrent.Callable import java.util.concurrent.Future -import java.util.function.Consumer import java.util.function.Supplier import java.util.stream.Stream import java.util.stream.StreamSupport @@ -128,26 +116,6 @@ operator fun JsonObject.set(s: String, value: String) = add(s, JsonPrimitive(val operator fun JsonObject.set(s: String, value: Number) = add(s, JsonPrimitive(value)) operator fun JsonObject.set(s: String, value: Boolean) = add(s, JsonPrimitive(value)) -fun LevelAccessor.getBlockStateNow(pos: BlockPos): BlockState { - return getBlockStateNowOrNull(pos) ?: Blocks.AIR.defaultBlockState() -} - -fun LevelAccessor.getBlockStateNowOrNull(pos: BlockPos): BlockState? { - return chunkSource.getChunkNow(SectionPos.blockToSectionCoord(pos.x), SectionPos.blockToSectionCoord(pos.z))?.getBlockState(pos) -} - -fun LevelAccessor.getBlockEntityNow(pos: BlockPos): BlockEntity? { - return chunkSource.getChunkNow(SectionPos.blockToSectionCoord(pos.x), SectionPos.blockToSectionCoord(pos.z))?.getBlockEntity(pos) -} - -fun ChunkSource.getChunkNow(pos: BlockPos): LevelChunk? { - return getChunkNow(SectionPos.blockToSectionCoord(pos.x), SectionPos.blockToSectionCoord(pos.z)) -} - -fun ChunkSource.getChunkNow(pos: ChunkPos): LevelChunk? { - return getChunkNow(pos.x, pos.z) -} - inline val FluidStack.isNotEmpty get() = !isEmpty inline val ItemStack.isNotEmpty get() = !isEmpty