Guest User

Untitled

a guest
Aug 20th, 2022
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.66 KB | None | 0 0
  1.  
  2. /////////////////////Item class//////////////////////
  3. public class EntityStorageItem extends Item {
  4.  
  5.     public EntityStorageItem(Properties pProperties) {
  6.         super(pProperties);
  7.     }
  8.  
  9.     public InteractionResult useOn(UseOnContext pContext) {
  10.  
  11.         ItemStack is = pContext.getItemInHand();
  12.         CompoundTag tag = is.getTagElement("stored_entity");
  13.         BlockPos pos = pContext.getClickedPos();
  14.  
  15.         if(tag != null){
  16.  
  17.             Entity entity1 = EntityType.create(tag, pContext.getLevel()).get(); // method 1
  18.  
  19.             pContext.getLevel().addFreshEntity(entity1); // method 2
  20.  
  21.             entity1.moveTo(pContext.getPlayer().position());
  22.  
  23.             Entity entity = EntityType.loadEntityRecursive(tag, pContext.getLevel(), (p_138828_) -> {
  24.                 p_138828_.moveTo(pos.getX(), pos.getY(), pos.getZ(), p_138828_.getYRot(), p_138828_.getXRot());
  25.                 return p_138828_;
  26.             }); // method 3 from SummonCommand
  27.            
  28.         }
  29.         return InteractionResult.PASS;
  30.     }
  31. }
  32.  
  33. ////////////////////////Entity class (partial)/////////////////////////
  34. public class ExampleEntity extends Animal {
  35.  
  36.     @Override
  37.     public InteractionResult mobInteract(Player pPlayer, InteractionHand pHand){
  38.  
  39.         ItemStack items = pPlayer.getItemInHand(pHand);
  40.         Item item = items.getItem();
  41.  
  42.         if(item instanceof EntityStorageItem && pPlayer.isCrouching()){
  43.             CompoundTag tag = new CompoundTag();
  44.             this.save(tag);
  45.             items.addTagElement("stored_entity",tag);
  46.             //this.discard();
  47.  
  48.  
  49.         }
  50.  
  51.         return super.mobInteract(pPlayer, pHand);
  52.     }
  53.  
  54.  
  55. }
Advertisement
Add Comment
Please, Sign In to add comment