Jump to content

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


Recommended Posts

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
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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 

Link to comment
Share on other sites

  • 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...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • the mods are crashing and I'm not sure why so heres everything  crash log https://pastebin.com/RxLKbMNR  L2 Library (12library) has failed to load correctly java.lang.NoClassDefFoundError: org/antarcticgardens/newage/content/energiser/EnergiserBlock L2 Screen Tracker (12screentracker) has failed to load correctly java.lang.NoClassDefFoundError: Could not initialize class dev.xkmc.12library.base.L2Registrate Create: Interiors (interiors) has failed to load correctly java.lang.NoClassDefFoundError: Could not initialize class com.tterrag.registrate.AbstractRegistrate L2 Damage Tracker (12damagetracker) has failed to load correctly java.lang.NoClassDefFoundError: Could not initialize class dev.xkmc.l2library.base.L2Registrate Create Enchantment Industry (create_enchantment_industry) has failed to load correctly java.lang.NoClassDefFoundError: Could not initialize class com.simibubi.create.foundation.data.Createfiegistrate Create Crafts & Additions (createaddition) has failed to load correctly java.lang.NoClassDefFoundError: Could not initialize class com.simibubi.create.foundation.data.CreateRegistrate Create Slice & Dice (sliceanddice) has failed to load correctly java.lang.NoClassDefFoundError: Could not initialize class com.simibubi.create.foundation.data.CreateRegistrate L2 Tabs (12tabs) has failed to load correctly java.lang.NoClassDefFoundError: Could not initialize class dev.xkmc.l2library.base.L2Registrate Modular Golems (modulargolems) has failed to load correctly java.lang.NoClassDefFoundError: Could not initialize class dev.xkmc.l2library.base.L2Registrate Create: Steam 'n' FRails (railways) has failed to load correctly java.lang.NoClassDefFoundError : Could not initialize class com.simibubi.create.foundation.data.Createfregistrate Cuisine Delight (cuisinedelight) has failed to load correctly java.lang.NoClassDefFoundError: Could not initialize class dev.xkmc.12library.base.L2Registrate Create (create) has failed to load correctly java.lang.NoClassDefFoundError: Could not initialize class com.simibubi.create.Create Guardian Beam Defense (creategbd) has failed to load correctly java.lang.NoClassDefFoundError: Could not initialize class com.simibubi.create.foundation.data.CreateRegistrate L2 Item Selector (12itemselector) has failed to load correctly java.lang.NoClassDefFoundError: Could not initialize class dev.xkmc.l2library.base.L2Registrate
    • hey there, I have been using Forge for years without any problems, but for some time now I have been getting this error message when I click on “Installer” under the downloads. This happens on all versions. I have tried various things but have not gotten any results. If anyone has a solution, I would be very grateful!
    • I don't have mcreator installed.
    • the session has expired, what if the modified LAN Server displays the same screen after logging in as after logging in to the premium server from a non-premium account? Minecraft Forge 1.20.1 CurseForge. I also use Mod LAN World Plug n Play
    • Hello There! In today's video I will be showing you guys the Minecraft and Google Collaboration they are doing for the 15th anniversary for Minecraft! If you guys wanna try this out for yourself go to google and type in "Minecraft"!  
  • Topics

×
×
  • Create New...

Important Information

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