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.
Set their velocities to -1 using this method, and set their jumping to -1 as well. http://bukkit.org/threads/tutorial-setting-entity-attributes.158065/
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.
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.
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...
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); } }
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?