Package com.ldtteam.structurize.util
Class BlockUtils
java.lang.Object
com.ldtteam.structurize.util.BlockUtils
Utility class for all Block type checking.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final List<BiPredicate<net.minecraft.world.level.block.Block,net.minecraft.world.level.block.state.BlockState>> Predicated to determine if a block is free to place. -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanareBlockStatesEqual(net.minecraft.world.level.block.state.BlockState structureState, net.minecraft.world.level.block.state.BlockState worldState, Predicate<net.minecraft.world.level.block.state.BlockState> shallReplace, boolean fancy, BiPredicate<net.minecraft.world.level.block.state.BlockState, net.minecraft.world.level.block.state.BlockState> specialEqualRule, net.minecraft.nbt.CompoundTag tileEntityData, net.minecraft.world.level.block.entity.BlockEntity worldEntity) For structure placement, check if two blocks are alike or if action has to be taken.static booleancanBlockFloatInAir(net.minecraft.world.level.block.state.BlockState blockState) static booleancanBlockSurviveWithoutSupport(net.minecraft.world.level.block.Block block) static voidCheck or init the non solid blocks.static net.minecraft.world.level.block.state.BlockStatecopyFirstCommonBlockStateProperties(net.minecraft.world.level.block.state.BlockState target, net.minecraft.world.level.block.state.BlockState propertiesOrigin) Copies property values from propertiesOrigin into new blockstate made from target Block.static List<net.minecraft.world.item.ItemStack>getBlockDrops(net.minecraft.world.level.Level world, net.minecraft.core.BlockPos coords, int fortune, net.minecraft.world.item.ItemStack stack) Returns a list of drops possible mining a specific block with specific fortune level.static net.minecraft.world.level.block.state.BlockStategetBlockStateFromStack(net.minecraft.world.item.ItemStack stack) Get a blockState from an itemStack.static net.minecraft.world.level.block.state.BlockStategetBlockStateFromStack(net.minecraft.world.item.ItemStack stack, net.minecraft.world.level.block.state.BlockState def) Get a blockState from an itemStack.static net.minecraft.world.level.block.state.BlockStategetDefaultBlockForLevel(net.minecraft.world.level.Level level, net.minecraft.world.level.block.state.BlockState defaultValue) A simple check to fetch the default block for this dimensionstatic net.minecraft.world.level.block.state.BlockStategetFluidForDimension(net.minecraft.world.level.Level world) A simple check to fetch the default fluid block for this dimensionstatic net.minecraft.world.item.ItemStackgetItemStackFromBlockState(net.minecraft.world.level.block.state.BlockState blockState) Mimics pick block.static BlockUtils.SolidnessInfogetSolidInfo(net.minecraft.world.level.block.state.BlockState blockState) static net.minecraft.world.level.block.state.BlockStategetSubstitutionBlockAtWorld(net.minecraft.world.level.Level level, net.minecraft.core.BlockPos location, @Nullable Function<net.minecraft.core.BlockPos, net.minecraft.world.level.block.state.BlockState> virtualBlocks) Get the filler block at a certain location.static @Nullable net.minecraft.world.level.block.state.BlockStategetWorldgenBlock(net.minecraft.world.level.Level level, net.minecraft.core.BlockPos location, @Nullable Function<net.minecraft.core.BlockPos, net.minecraft.world.level.block.state.BlockState> virtualBlocks) Get the worldGen block for a certain location.static voidhandleCorrectBlockPlacement(net.minecraft.world.level.Level world, net.neoforged.neoforge.common.util.FakePlayer fakePlayer, net.minecraft.world.item.ItemStack itemStack, net.minecraft.world.level.block.state.BlockState blockState, net.minecraft.core.BlockPos here) Handle the placement of a specific block for a blockState at a certain position with a fakePlayer.static booleanisAnySolid(net.minecraft.world.level.block.state.BlockState blockState) static booleanisGoodFloorBlock(net.minecraft.world.level.block.state.BlockState blockState) static booleanisLiquidOnlyBlock(net.minecraft.world.level.block.Block block) static booleanisLiquidOnlyBlock(net.minecraft.world.level.block.state.BlockState blockState) static booleanisWater(net.minecraft.world.level.block.state.BlockState iBlockState) Checks if the block is water.static booleanisWeakSolidBlock(net.minecraft.world.level.block.state.BlockState blockState) static voidremoveFluid(net.minecraft.world.level.Level world, net.minecraft.core.BlockPos pos) Removes the fluid from the given position.
-
Field Details
-
FREE_TO_PLACE_BLOCKS
public static final List<BiPredicate<net.minecraft.world.level.block.Block,net.minecraft.world.level.block.state.BlockState>> FREE_TO_PLACE_BLOCKSPredicated to determine if a block is free to place.
-
-
Method Details
-
checkOrInit
public static void checkOrInit()Check or init the non solid blocks. -
getSubstitutionBlockAtWorld
public static net.minecraft.world.level.block.state.BlockState getSubstitutionBlockAtWorld(net.minecraft.world.level.Level level, net.minecraft.core.BlockPos location, @Nullable @Nullable Function<net.minecraft.core.BlockPos, net.minecraft.world.level.block.state.BlockState> virtualBlocks) Get the filler block at a certain location.- Parameters:
level- the world the block is in.location- the location it is at.virtualBlocks- if null use level instead for getting surrounding block states, fnc may should return null if virtual block is not available- Returns:
- the BlockState of the filler block.
-
getWorldgenBlock
@Nullable public static @Nullable net.minecraft.world.level.block.state.BlockState getWorldgenBlock(net.minecraft.world.level.Level level, net.minecraft.core.BlockPos location, @Nullable @Nullable Function<net.minecraft.core.BlockPos, net.minecraft.world.level.block.state.BlockState> virtualBlocks) Get the worldGen block for a certain location. Always gives DIRT for non vanilla worlds including blueprint.- Parameters:
level- the world the block is in.location- the real world location.virtualBlocks- if null use level instead for getting surrounding block states, fnc may should return null if virtual block is not available- Returns:
- the BlockState of the filler block.
- See Also:
-
for possible blockstates
-
isWater
public static boolean isWater(net.minecraft.world.level.block.state.BlockState iBlockState) Checks if the block is water.- Parameters:
iBlockState- block state to be checked.- Returns:
- true if is water.
-
areBlockStatesEqual
public static boolean areBlockStatesEqual(net.minecraft.world.level.block.state.BlockState structureState, net.minecraft.world.level.block.state.BlockState worldState, Predicate<net.minecraft.world.level.block.state.BlockState> shallReplace, boolean fancy, BiPredicate<net.minecraft.world.level.block.state.BlockState, net.minecraft.world.level.block.state.BlockState> specialEqualRule, net.minecraft.nbt.CompoundTag tileEntityData, net.minecraft.world.level.block.entity.BlockEntity worldEntity) For structure placement, check if two blocks are alike or if action has to be taken.- Parameters:
structureState- the first blockState.worldState- the second blockState.shallReplace- the not solid condition.fancy- if fancy paste.tileEntityData-worldEntity-- Returns:
- true if nothing has to be done.
-
getBlockStateFromStack
public static net.minecraft.world.level.block.state.BlockState getBlockStateFromStack(net.minecraft.world.item.ItemStack stack) Get a blockState from an itemStack.- Parameters:
stack- the stack to analyze.- Returns:
- the IBlockState.
-
getBlockStateFromStack
public static net.minecraft.world.level.block.state.BlockState getBlockStateFromStack(net.minecraft.world.item.ItemStack stack, net.minecraft.world.level.block.state.BlockState def) Get a blockState from an itemStack.- Parameters:
stack- the stack to analyze.def- default blockstate if stack is not transformable- Returns:
- the IBlockState.
-
getItemStackFromBlockState
public static net.minecraft.world.item.ItemStack getItemStackFromBlockState(net.minecraft.world.level.block.state.BlockState blockState) Mimics pick block.- Parameters:
blockState- the block and state we are creating an ItemStack for.- Returns:
- ItemStack fromt the BlockState.
-
handleCorrectBlockPlacement
public static void handleCorrectBlockPlacement(net.minecraft.world.level.Level world, net.neoforged.neoforge.common.util.FakePlayer fakePlayer, net.minecraft.world.item.ItemStack itemStack, net.minecraft.world.level.block.state.BlockState blockState, net.minecraft.core.BlockPos here) Handle the placement of a specific block for a blockState at a certain position with a fakePlayer.- Parameters:
world- the world object.fakePlayer- the fake player to place.itemStack- the describing itemStack.blockState- the blockState in the world.here- the position.
-
removeFluid
public static void removeFluid(net.minecraft.world.level.Level world, net.minecraft.core.BlockPos pos) Removes the fluid from the given position.- Parameters:
world- the world to remove the fluid from.pos- the position where to remove the fluid.
-
getFluidForDimension
public static net.minecraft.world.level.block.state.BlockState getFluidForDimension(net.minecraft.world.level.Level world) A simple check to fetch the default fluid block for this dimension- Parameters:
world- the world of the dimension- Returns:
- the default blockstate for the default fluid
-
getDefaultBlockForLevel
public static net.minecraft.world.level.block.state.BlockState getDefaultBlockForLevel(net.minecraft.world.level.Level level, net.minecraft.world.level.block.state.BlockState defaultValue) A simple check to fetch the default block for this dimension- Parameters:
level- the world of the dimensiondefaultValue- return this if unable to get default block for given level- Returns:
- the default blockstate
-
getBlockDrops
public static List<net.minecraft.world.item.ItemStack> getBlockDrops(net.minecraft.world.level.Level world, net.minecraft.core.BlockPos coords, int fortune, net.minecraft.world.item.ItemStack stack) Returns a list of drops possible mining a specific block with specific fortune level.- Parameters:
world- World the block is in.coords- Coordinates of the block.fortune- Level of fortune on the pickaxe.stack- the tool.- Returns:
- List of
ItemStackwith possible drops.
-
copyFirstCommonBlockStateProperties
public static net.minecraft.world.level.block.state.BlockState copyFirstCommonBlockStateProperties(net.minecraft.world.level.block.state.BlockState target, net.minecraft.world.level.block.state.BlockState propertiesOrigin) Copies property values from propertiesOrigin into new blockstate made from target Block. If source and target are not the same block find the first common superclass and use its properties.- Parameters:
target- properties destinationpropertiesOrigin- properties source- Returns:
- blockState of target block with properties of common super class or null if no common superclass found
-
canBlockFloatInAir
public static boolean canBlockFloatInAir(net.minecraft.world.level.block.state.BlockState blockState) - Returns:
- true iff block can exist without any support (cannot decay,
BlockBehaviour.canSurvive(BlockState, LevelReader, BlockPos)()} always return true)
-
isLiquidOnlyBlock
public static boolean isLiquidOnlyBlock(net.minecraft.world.level.block.state.BlockState blockState) - Returns:
- true iff block is any variant of any fluid (waterlogged etc doesnt count)
-
isLiquidOnlyBlock
public static boolean isLiquidOnlyBlock(net.minecraft.world.level.block.Block block) - Returns:
- true iff block is any variant of any fluid (waterlogged etc doesnt count)
-
isWeakSolidBlock
public static boolean isWeakSolidBlock(net.minecraft.world.level.block.state.BlockState blockState) - Returns:
- true iff block MAY require any support to exist (can decay/fall) and also MAY be support to floating blocks
-
canBlockSurviveWithoutSupport
public static boolean canBlockSurviveWithoutSupport(net.minecraft.world.level.block.Block block) -
isAnySolid
public static boolean isAnySolid(net.minecraft.world.level.block.state.BlockState blockState) -
isGoodFloorBlock
public static boolean isGoodFloorBlock(net.minecraft.world.level.block.state.BlockState blockState) -
getSolidInfo
public static BlockUtils.SolidnessInfo getSolidInfo(net.minecraft.world.level.block.state.BlockState blockState)
-