Skip to content

Commit

Permalink
Filter blocks suggested for portals
Browse files Browse the repository at this point in the history
  • Loading branch information
Unreal852 committed Aug 11, 2024
1 parent 9ff33df commit 6745df4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,32 @@ import com.mojang.brigadier.context.CommandContext
import com.mojang.brigadier.suggestion.SuggestionProvider
import com.mojang.brigadier.suggestion.Suggestions
import com.mojang.brigadier.suggestion.SuggestionsBuilder
import net.minecraft.block.Blocks
import fr.unreal852.quantum.utils.Extensions.isIn
import net.minecraft.block.BlockWithEntity
import net.minecraft.block.PlantBlock
import net.minecraft.registry.Registries
import net.minecraft.registry.tag.BlockTags
import net.minecraft.server.command.ServerCommandSource
import java.util.concurrent.CompletableFuture

class BlocksSuggestionProvider : SuggestionProvider<ServerCommandSource> {

override fun getSuggestions(context: CommandContext<ServerCommandSource>, builder: SuggestionsBuilder): CompletableFuture<Suggestions> {
for (block in Registries.BLOCK) {
val blockState = block.defaultState

if(blockState.isOpaque)
if (block is BlockWithEntity || block is PlantBlock)
continue

if (blockState.isIn(
BlockTags.AIR, BlockTags.DOORS, BlockTags.BUTTONS, BlockTags.ALL_SIGNS, BlockTags.SLABS, BlockTags.STAIRS,
BlockTags.BEDS, BlockTags.BANNERS, BlockTags.RAILS, BlockTags.TRAPDOORS,
BlockTags.PRESSURE_PLATES, BlockTags.FENCES, BlockTags.FENCE_GATES, BlockTags.SAPLINGS, BlockTags.WOOL_CARPETS
)
)
continue

if (block != Blocks.AIR) {
builder.suggest(Registries.BLOCK.getEntry(block).idAsString)
}
builder.suggest(blockState.registryEntry.idAsString)
}

return builder.buildFuture()
Expand Down
13 changes: 12 additions & 1 deletion src/main/java/fr/unreal852/quantum/utils/Extensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
package fr.unreal852.quantum.utils

import fr.unreal852.quantum.Quantum
import fr.unreal852.quantum.world.QuantumWorldData
import fr.unreal852.quantum.state.QuantumWorldStorage
import fr.unreal852.quantum.world.QuantumWorldData
import net.minecraft.block.Block
import net.minecraft.block.BlockState
import net.minecraft.entity.player.PlayerEntity
import net.minecraft.nbt.NbtCompound
import net.minecraft.registry.RegistryKey
import net.minecraft.registry.RegistryKeys
import net.minecraft.registry.tag.TagKey
import net.minecraft.server.MinecraftServer
import net.minecraft.server.world.ServerWorld
import net.minecraft.util.Identifier
Expand Down Expand Up @@ -59,4 +62,12 @@ object Extensions {
.setGenerator(dimensionWorld.chunkManager.chunkGenerator)
return this
}

fun BlockState.isIn(vararg tags: TagKey<Block>): Boolean {
for (tag in tags) {
if (this.isIn(tag))
return true
}
return false
}
}

0 comments on commit 6745df4

Please sign in to comment.