Frozen Mobs

Discussion in 'Plugin Development' started by plisov, Apr 24, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    plisov

    I am trying to make a plugin where you run a command and it spawns a chicken or any other mob that is frozen and cannot move and twitch. Its just frozen. Something like this. 2015-04-24_23.27.06.png
     
  2. Offline

    Zombie_Striker

  3. Offline

    plisov

    Like this?
    Code:
     private static final UUID movementSpeedUID = UUID.fromString("206a89dc-ae78-4c4d-b42c-3b31db3f5a7c");
         
           @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
           public void onEntitySpawn(CreatureSpawnEvent event){
               LivingEntity entity = event.getEntity();
         
               if (entity.getType() == EntityType.VILLAGER){
                   EntityInsentient nmsEntity = (EntityInsentient) ((CraftLivingEntity) entity).getHandle();
                   AttributeInstance attributes = nmsEntity.getAttributeInstance(GenericAttributes.d);
           
                   AttributeModifier modifier = new AttributeModifier(movementSpeedUID, "<plugin_name> movement speed multiplier", -1d, -1);
           
                   attributes.b(modifier);
                   attributes.a(modifier);
               }
           }
    
    if so it doesn't work.
     
  4. Offline

    LetsTalkTnTHere

    You can:
    Add a slowness effect to it like the code below
    Teleport the mob to a location every amount of ticks
    Code:
    Villager myMob = (Villager) player.getWorld().spawnEntity(player.getLocation(), EntityType.VILLAGER);
    
    myMob.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, Integer.MAX_VALUE, 100));
    
    i think that'll work.
     
  5. Offline

    plisov

    He would still be able to move. He would be able to turn.
    Also you would see the slowness particles.
     
  6. Offline

    Zombie_Striker

    Code:
        public void setEntitySpeed(Entity e,double speed){
            LivingEntity entity = (LivingEntity) e;
           
            EntityInsentient nmsEntity = (EntityInsentient) ((CraftLivingEntity) entity).getHandle();
            AttributeInstance attributes = nmsEntity.getAttributeInstance(GenericAttributes.d);
            AttributeModifier modifier = new AttributeModifier(movementSpeedUID, "<plugin_name> movement speed multiplier", speed, 1);
            attributes.b(modifier);
            attributes.a(modifier);
        }
    
    
    //eslewhere
             setEntitySpeed(event.getEntity(), -10.0d);
    
    This works...
     
  7. Offline

    plisov

    Doesn't work. I think I'm putting it in wrong
    Code:
     private static final UUID movementSpeedUID = UUID.fromString("206a89dc-ae78-4c4d-b42c-3b31db3f5a7c");
         
        public void setEntitySpeed(Entity e,double speed){
               LivingEntity entity = (LivingEntity) e;
             
               EntityInsentient nmsEntity = (EntityInsentient) ((CraftLivingEntity) entity).getHandle();
               AttributeInstance attributes = nmsEntity.getAttributeInstance(GenericAttributes.d);
               AttributeModifier modifier = new AttributeModifier(movementSpeedUID, "<plugin_name> movement speed multiplier", speed, 1);
               attributes.b(modifier);
               attributes.a(modifier);
           }
         
           @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
           public void onEntitySpawn(CreatureSpawnEvent event){
               LivingEntity entity = event.getEntity();
         
               if (entity.getType() == EntityType.VILLAGER){
                   EntityInsentient nmsEntity = (EntityInsentient) ((CraftLivingEntity) entity).getHandle();
                   AttributeInstance attributes = nmsEntity.getAttributeInstance(GenericAttributes.d);
           
                   AttributeModifier modifier = new AttributeModifier(movementSpeedUID, "<plugin_name> movement speed multiplier", -1d, -1);
           
                   attributes.b(modifier);
                   attributes.a(modifier);
                   
               }
           }
    
     
  8. Offline

    Zombie_Striker

    Well, you're not actually calling the method and you still have the old, broken lines in you Spawn event.

    Are you new to Java, or did you just overlook that?
     
Thread Status:
Not open for further replies.

Share This Page