Jump to content

[solved][1.19.2] events detecs when one of mi custome blocks is in the hand of the player


Recommended Posts

Posted (edited)

uhh im doing something complicated 

i made some panels blocks of various materials and glass also its just 1/4 of a full block and can have 6 directions that works nice but

 sometimes is a little hard to set the panel in the exact place i want it to be

 

too fix that i made an entity based on  abstract_arrow called "aligner_entity" for now is just a white gray texture.

this entity binds to the player and every 5 ticks detecs what the player looking at and updates its position|rotation to mach where a panel_block  would be placed if any  

the entity works nice and all 

#######################################################################

 

now i need to spawn the entity and bind it to the player any time the player hold one of mi blocks in its hand and also kill/discard the entity when player change to someting else 

soo i doo the event thing 

Spoiler
				
			package mercblk.event;				
			import mercblk.mercblk;
		import mercblk.blocks.BlockInit;
		import mercblk.blocks.panel.panel;
		import mercblk.entity.EntityInit;
		import mercblk.entity.red_hot_iron_entity;
		import mercblk.item.ItemInit;
		import net.minecraftforge.eventbus.api.SubscribeEvent;
		import net.minecraftforge.fml.common.Mod;
		import net.minecraft.world.entity.Entity;
		import net.minecraft.world.entity.item.ItemEntity;
		import net.minecraft.world.entity.player.Player;
		import net.minecraft.world.item.ItemStack;
		import net.minecraft.world.item.Items;
		import net.minecraft.world.level.Level;
		import net.minecraftforge.event.entity.item.ItemTossEvent;
		import net.minecraftforge.event.entity.living.LivingEquipmentChangeEvent;				
			@Mod.EventBusSubscriber(modid = mercblk.MOD_ID, bus = Mod.EventBusSubscriber.Bus.FORGE)
		public class modevents {				
			    // #################### #################### ####################
		    @SubscribeEvent
		    public static void on_toss(ItemTossEvent event) {				
			        Entity entity = event.getEntity();
		        Level warudo = entity.level;
		        if (entity instanceof ItemEntity) {
		            ItemEntity item_e = (ItemEntity) entity;
		            ItemStack itemstack = item_e.getItem();				
			            System.out.println("\n ItemTossEvent " + itemstack.getDisplayName().getString() + "\n");				
			            // #################### ####################
		            if (itemstack.getItem() == ItemInit.INGOT_IRON_RED_HOT.get() && !warudo.isClientSide) {				
			                try {
		                    red_hot_iron_entity w_entity = new red_hot_iron_entity(EntityInit.RED_HOT_IRON_ENTITY.get(), warudo,
		                            item_e);
		                    w_entity.setPos(item_e.getX(), item_e.getY(), item_e.getZ());
		                    warudo.addFreshEntity(w_entity);
		                } catch (Exception e) {
		                    System.out.println("Something went wrong." + e.toString());
		                }
		            }				
			            // #################### ####################
		            if (itemstack.getItem() == Items.EGG && !warudo.isClientSide) {
		                System.out.println("\n\n EGGGGGGG \n\n");				
			                try {
		                    ItemStack itemdrop = new ItemStack(Items.FEATHER, 1);				
			                    ItemEntity newdrop = new ItemEntity(warudo, (double) (entity.position().x),
		                            (double) (entity.position().y + 1.0F), (double) (entity.position().z), itemdrop);
		                    warudo.addFreshEntity(newdrop);
		                } catch (Exception e) {
		                    System.out.println("Something went wrong." + e.toString());
		                }
		            }				
			        }
		    }
		    
		    // #################### #################### ####################
		    @SubscribeEvent
		    public static void spawn_aligner_entity(LivingEquipmentChangeEvent event) {				
			        ItemStack itemstack = event.getTo(); //new selected item
		        //ItemStack itemstack = event.getFrom(); //old selected item 
		        Entity entity = event.getEntity();
		        Level warudo = entity.level;
		        if (entity instanceof Player) {
		            Player pe = (Player)entity;
		            System.out.println("\n User Change of item \n");				
			            // if (itemstack.getItem() == ItemInit.LANCE_STEEL.get() &&
		            // !warudo.isClientSide) {
		            //if (itemstack.getItem() instanceof panel.class && !warudo.isClientSide) 
		            {
		                
		                //if (itemstack.getItem() == BlockInit.MANHOLE_PANEL.get().asItem()) {                
		                
		                //System.out.println("\nEs una lanza\n");
		            }
		        }
		    }				
			
		}				
			

the LivingEquipmentChangeEvent event trigers everytime the player select an item in the hotbar 
the comented code its just experiments i been doing
 

sorry is hard to comunicate complex ideas in a non native languague 
the "if (itemstack.getItem() == BlockInit.MANHOLE_PANEL.get().asItem())"   works to detect mi block but i have like 120 it would be not resources wise to make a list and compare against all 120 blocks everytime the user select a diferent item in the hotbar 

   all mi blocks are made from 3 main classes 
panel.class

puerta.class

trampilla.class       //this one is instance of puerta soo it dont mathers   

 

if i try to made an 

"if (itemstack.getItem() instanceof panel && !warudo.isClientSide) " //

it says 

"incompatible conditional operand types item and panel" 

sounds logic coze one is an item object and the other is a block class 

 

#####################################

ya i need is to know if the item form the itemstack the LivingEquipmentChangeEvent gives me was made from the panel block class 

without having to compare to each all of mi blocks 

 

 

thanks for your time 

 

 

 

 

 

 

Edited by perromercenary00
solved
  • perromercenary00 changed the title to [solved][1.19.2] events detecs when one of mi custome blocks is in the hand of the player

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



×
×
  • Create New...

Important Information

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