Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

[SOLVED][1.20.4] has someone figured out how to check if a block is solid ??

Featured Replies

Posted

the removing of the Material class has mess up bad mi code now have to many broken things after updating mi code to 1.20.4

this are mi pipes they conect each others but to have it right i have to made a custome BlockItem 
the thing its that i need to check the block im looking at 
if its some something like grass or wheat i need to ignore and replace whit mi pipe block
but if its something like leaves then it must respect it and set the pipe above or at the side 

in x < 1.9just check the material the target block is made of 

 

Spoiler
				
			
		    // ########## ########## ########## ##########
		    public static boolean is_a_solid_block(Level warudo, BlockPos pos) {
		        BlockState blkstate = warudo.getBlockState(pos);
		        return is_a_solid_block(blkstate);
		    }				
			    public static boolean is_a_solid_block(BlockState blkstate) {				
			        // Material pmat = warudo.getBlockState(pos).getMaterial();
		        Material pmat = blkstate.getMaterial();				
			        if ((pmat == Material.AIR) || (pmat == Material.PLANT) || (pmat == Material.LEAVES)
		                || (pmat == Material.REPLACEABLE_PLANT)) {
		            return false;
		        }				
			        if ((pmat == Material.SNOW) || (pmat == Material.WOOD) || (pmat == Material.NETHER_WOOD)
		                || (pmat == Material.TOP_SNOW)) {
		            return false;
		        }				
			        if ((pmat == Material.WATER) || (pmat == Material.WATER_PLANT) || (pmat == Material.REPLACEABLE_WATER_PLANT)
		                || (pmat == Material.REPLACEABLE_FIREPROOF_PLANT)) {
		            return false;
		        }				
			        if ((pmat == Material.LAVA) || (pmat == Material.FIRE) || (pmat == Material.GLASS) || (pmat == Material.BUILDABLE_GLASS )  ) {
		            return false;
		        }				
			        if ((pmat == Material.DECORATION) || (pmat == Material.CACTUS) || (pmat == Material.WEB)   ) {
		            return false;
		        }        
		        
		        return true;
		    }				
			

 in 1.20 cannot be done like this soo i was trying to make a list of solid blocks but is much work and also it don't have in account blocks from other mods  

 

 

Spoiler
				
			package mercmod.blockitems;
		
		import mercmod.blocks.classes.tubo;
		import mercmod.entity.EntityInit;
		import mercmod.entity.lance_entity;
		import mercmod.util.Postate;
		import mercmod.util.Target;
		import net.minecraft.advancements.CriteriaTriggers;
		import net.minecraft.core.BlockPos;
		import net.minecraft.nbt.CompoundTag;
		import net.minecraft.nbt.ListTag;
		import net.minecraft.network.chat.Component;
		import net.minecraft.server.MinecraftServer;
		import net.minecraft.server.level.ServerPlayer;
		import net.minecraft.sounds.SoundEvent;
		import net.minecraft.sounds.SoundEvents;
		import net.minecraft.sounds.SoundSource;
		import net.minecraft.world.InteractionHand;
		import net.minecraft.world.InteractionResult;
		import net.minecraft.world.InteractionResultHolder;
		import net.minecraft.world.entity.Entity;
		import net.minecraft.world.entity.LivingEntity;
		import net.minecraft.world.entity.item.ItemEntity;
		import net.minecraft.world.entity.player.Player;
		import net.minecraft.world.flag.FeatureFlagSet;
		import net.minecraft.world.item.*;
		import net.minecraft.world.item.context.BlockPlaceContext;
		import net.minecraft.world.item.context.UseOnContext;
		import net.minecraft.world.level.Level;
		import net.minecraft.world.level.block.Block;
		import net.minecraft.world.level.block.Blocks;
		import net.minecraft.world.level.block.ShulkerBoxBlock;
		import net.minecraft.world.level.block.SoundType;
		import net.minecraft.world.level.block.entity.BlockEntity;
		import net.minecraft.world.level.block.entity.BlockEntityType;
		import net.minecraft.world.level.block.state.BlockState;
		import net.minecraft.world.level.block.state.StateDefinition;
		import net.minecraft.world.level.block.state.properties.Property;
		import net.minecraft.world.level.gameevent.GameEvent;
		import net.minecraft.world.phys.Vec3;
		import net.minecraft.world.phys.shapes.CollisionContext;
		
		import javax.annotation.Nullable;
		import java.util.ArrayList;
		import java.util.List;
		import java.util.Map;
		
		public class tubo_blockitem extends BlockItem {
		public static final String BLOCK_ENTITY_TAG = "BlockEntityTag";
		public static final String BLOCK_STATE_TAG = "BlockStateTag";
		/** @deprecated */
		@Deprecated
		private final Block block;
		
		public tubo_blockitem(Block blk, Properties properties) {
		super(blk, properties);
		this.block = blk;
		}
		
		// ########## ########## ########## ##########
		@Override
		public InteractionResult useOn(UseOnContext p_40581_) {
		return InteractionResult.PASS;
		}
		
		// ########## ########## ########## ##########
		
		
		// ########## ########## ########## ##########
		@Override
		public InteractionResultHolder<ItemStack> use(Level warudo, Player pe, InteractionHand hand) {
		System.out.println("use()");
		ItemStack itemstack = pe.getItemInHand(hand);
		
		pe.startUsingItem(hand);
		return InteractionResultHolder.pass(pe.getItemInHand(hand));
		}
		
		
		// ########## ########## ########## ##########
		@Override
		public void releaseUsing(ItemStack itemstack, Level warudo, LivingEntity le, int time) {
		float ticks = (itemstack.getUseDuration() - le.getUseItemRemainingTicks());
		ticks = (ticks > 15.0F) ? 15.0F : ticks;
		
		//System.out.println("releaseUsing(" + time + "), " + ticks);
		
		float power = ticks / 15F;
		
		if (ticks >= 14F) {
		}
		
		float distancia = 6.0F;
		Target target = new Target( warudo, le, distancia );
		ArrayList<BlockPos> todos_los_blockes = target.get_todos_los_blockes();
		
		boolean find = false;
		int count = 0;
		BlockState dblkstate;
		BlockPos bpos = null;
		for(BlockPos dpos : todos_los_blockes ){
		target.particle(dpos.getCenter());
		dblkstate = warudo.getBlockState(dpos);
		if( dblkstate .getBlock() instanceof tubo ){
		break;
		}
		bpos = dpos;
		count ++;
		}
		System.out.println(count);
		
		if(bpos != null){
		warudo.setBlock(bpos, Blocks.GLASS.defaultBlockState(), 2);
		}
		
		
		//itemstack.shrink(1);
		
		}
		
		// ########## ########## ########## ##########
		@Override
		public int getUseDuration(ItemStack p_40680_) {
		return 200;
		}
		
		@Override
		public UseAnim getUseAnimation(ItemStack p_40678_) {
		return UseAnim.SPEAR;
		}
		
		
		
		
		
		// ########## ########## ########## ##########
		@Override
		public boolean onEntitySwing(ItemStack stack, LivingEntity le) {
		System.out.println("onEntitySwing");
		Level warudo = le.level();
		ItemStack main = le.getMainHandItem();
		ItemStack off = le.getOffhandItem();
		float swordlikebar = 0.0F;
		
		InteractionHand hand;
		
		// hand = (off == stack) ? InteractionHand.OFF_HAND : InteractionHand.MAIN_HAND;
		// ItemStack itemstack = pe.getItemInHand(hand);
		// le.startUsingItem(hand);
		// return InteractionResultHolder.pass(pe.getItemInHand(hand));
		
		
		return false;
		}
		// ########## ########## ########## ##########
		
		
		
		
		public FeatureFlagSet requiredFeatures() {
		return this.getBlock().requiredFeatures();
		}
		}				
			

 

 

 

 

Edited by perromercenary00
solved

1 hour ago, perromercenary00 said:

 in 1.20 cannot be done like this soo i was trying to make a list of solid blocks but is much work and also it don't have in account blocks from other mods  

You can use the BlockBehaviour.canBeReplaced() method

  • Author

no thats not 
 

// ########## ########## ########## ##########
@Override
public boolean canBeReplaced(BlockState p_56373_, BlockPlaceContext p_56374_) {
return false;
}

this is the check to select if wanna reset the block or put another on top of the block 
i need something to know  what is a block made of

 

  • Author

ya ya i get it

	boolean find = false;
int count = 0;
BlockState dblkstate;
BlockPos bpos = null;
BlockPos dpos = null;
for(BlockPos cursor : todos_los_blockes ){
dpos = cursor;
target.particle(cursor.getCenter());
dblkstate = warudo.getBlockState(cursor);

if( !dblkstate.canBeReplaced() ){  //<----------
//if( dblkstate .getBlock() instanceof tubo ){
find = true;
break;
}
bpos = cursor;
count ++;
}
	

for this case setting blocks i can know discrimaniting by the  canbereplaced tag 
 

 

thanks 

  • perromercenary00 changed the title to [SOLVED][1.20.4] has someone figured out how to check if a block is solid ??

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.