Posted March 26, 20205 yr Hello everyone, in my mod I need to do some action when selected by entity using ISelectionContext and EntitySelectionContext I try to do it with getShape but it is not called when the player is selecting the block and when the voxels appear. Is there a another way to do this as i just wanted the block to detect the player when it is in front of the block?
March 26, 20205 yr Hi The DrawHighlightEvent might help you, if you only want to do this on the client side. It is the event called when Minecraft draws the box around the block or entity you're currently looking at. If you need it on the server side, you could perhaps perform a raytrace yourself on the server, say in a PlayerTick event. I'm not 100% sure that will work because I'm not certain that the server knows which way the player is facing. If not, and your server needs to know, you could use the DrawHighlightEvent and send a custom packet to the Server every time a new block is highlighted. Easier: if you don't care whether the player is looking at the block, just whether the player is near to the block, then you could use the PlayerTick event and check within a radius of the player to see if there are any of your block nearby. -TGG
March 26, 20205 yr 20 minutes ago, TheGreyGhost said: Hi The DrawHighlightEvent might help you, if you only want to do this on the client side. It is the event called when Minecraft draws the box around the block or entity you're currently looking at. If you need it on the server side, you could perhaps perform a raytrace yourself on the server, say in a PlayerTick event. I'm not 100% sure that will work because I'm not certain that the server knows which way the player is facing. If not, and your server needs to know, you could use the DrawHighlightEvent and send a custom packet to the Server every time a new block is highlighted. Easier: if you don't care whether the player is looking at the block, just whether the player is near to the block, then you could use the PlayerTick event and check within a radius of the player to see if there are any of your block nearby. -TGG Good idea with the raytrace, 1.13 and above implemented a new ray-casting system with command blocks, if you can do this with commands, Im sure its easily possible with mods too. *shrug*
March 27, 20205 yr Author Ok this function looks interesting but in fact I don't know how to implement the event and what I really want to avoid is using method IEntityReader#getClosestPlayer because it is searching amongst all player and this is done in each tick which will lower the speed of minecraft
March 27, 20205 yr If it's your own block, you can override Block#getShape: @Override public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) { if(context instanceof EntitySelectionContext) { Entity e = context.getEntity(); if (e != null) { // Perform your logic } } return super.getShape(state, worldIn, pos, context); } Edited March 27, 20205 yr by Alpvax misspelling
March 27, 20205 yr Author AlpVax are you sure this works ? because I try it in my mod (without condition on context and entity) and it did not work...
March 29, 20205 yr What exactly are you trying to do? I use that method to conditionally highlight sub segments of my block (by returning a different voxelshape).
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.