Hey guys, Today I am going to be telling you guys how to make your custom entities unmovable. This resource is mainly only to be used to stop other entities from pushing your custom entity. So, the first thing you're going to want to do is create your custom entity and make sure that you have registered it with the server (TeeePeee does this in his tutorial). I personally suggest following that tutorial as it's extremely detailed and walks you through every step of how to create your custom entity if you're new to NMS. Here is an example of what your entitys' class will look like. Code:java package net.subplex.TGRHavoc.VillagerSelect.Entities; public class CustomVillager extends EntityVillager { public CustomVillager(World world, int i) {super(world); this.setProfession(i);//Removes all pathfinders already registered in the villagertry{Field bField = PathfinderGoalSelector.class.getDeclaredField("b");bField.setAccessible(true);Field cField = PathfinderGoalSelector.class.getDeclaredField("c");cField.setAccessible(true); bField.set(goalSelector, new UnsafeList<PathfinderGoalSelector>());bField.set(targetSelector, new UnsafeList<PathfinderGoalSelector>());cField.set(goalSelector, new UnsafeList<PathfinderGoalSelector>());cField.set(targetSelector, new UnsafeList<PathfinderGoalSelector>()); }catch (Exception e){e.printStackTrace();}setUp();} public void setUp(){// Make the villager look at playersthis.goalSelector.a(10, new PathfinderGoalLookAtPlayer(this, EntityHuman.class, 8.0F));} @Overrideprotected void aC(){super.aC();// Make his walk speed 0 so he doesn't walk around on his ownthis.getAttributeInstance(GenericAttributes.d).setValue(0.0D);// Make his health to max a double can bethis.getAttributeInstance(GenericAttributes.a).setValue(Double.MAX_VALUE);// Make his knockback resistance max double can bethis.getAttributeInstance(GenericAttributes.c).setValue(Double.MAX_VALUE);}} Now all you have to do is override the Entity's move method and put nothing inside. It should look like: Code: @Override public void move(double d0, double d1, double d2){ } That's it! The entity should now stay in the same place. Even if you destroy the block beneath its feet (It'll look like it's teleporting but, I think that's due to how the client renders things). Hope this helps anyone out who is trying to make their entity unmovable I know it took me a while to figure this out.
Plugers11 I stop any damage to the villager by the "EntityDamageEntityEvent". You could probably find NMS code that gives the entity damage and override that.. Edit: This might be what you're looking for
Geekhellmc I know how to use this... I'm not noob like noob So go noob like noob and press like to noob
Is this meant to prevent entities from moving or being pushed, as you mentioned both ("Today I am ... custom entities unmovable. This source is ... entities from pushing your custom entity")? In the case of unpushable only I'd override 'g' or 'collide' (depending on the situation) and do fun stuff with those instead of canceling the entity's whole movement.
SuppaTim Both. I tried overriding the entities "collide" method before however, the entity could still be pushed. I even tried setting the variables "motX", "motY" and "motZ" to zero as I thought that they controlled the entities motion. Same happened with the "g" method.
So, to make the villager un-movable I would do this? Code:java @Overridepublic void move(double d0, double d1, double d2) { }
This is not working, when I spawn a villager with a spawn egg, it keeps moving, AND I can push it. My Custom Villager class: Code:java package me.macboinc1.stationarymobs; import java.lang.reflect.Field; import org.bukkit.craftbukkit.v1_7_R3.util.UnsafeList; import net.minecraft.server.v1_7_R3.EntityHuman;import net.minecraft.server.v1_7_R3.EntityVillager;import net.minecraft.server.v1_7_R3.GenericAttributes;import net.minecraft.server.v1_7_R3.PathfinderGoalLookAtPlayer;import net.minecraft.server.v1_7_R3.PathfinderGoalSelector;import net.minecraft.server.v1_7_R3.World; public class CustomVillager extends EntityVillager { public CustomVillager(World world, int i) {super(world); this.setProfession(i); try {Field bfield = PathfinderGoalSelector.class.getDeclaredField("b");bfield.setAccessible(true);Field cfield = PathfinderGoalSelector.class.getDeclaredField("c");cfield.setAccessible(true); bfield.set(goalSelector, new UnsafeList<PathfinderGoalSelector>());bfield.set(targetSelector, new UnsafeList<PathfinderGoalSelector>());cfield.set(goalSelector, new UnsafeList<PathfinderGoalSelector>());cfield.set(targetSelector, new UnsafeList<PathfinderGoalSelector>());} catch (Exception e) {e.printStackTrace();}setUp();} public void setUp() {this.goalSelector.a(10, new PathfinderGoalLookAtPlayer(this, EntityHuman.class, 8.0F));} @Overrideprotected void aC() {super.aC();this.getAttributeInstance(GenericAttributes.d).setValue(0.0D);this.getAttributeInstance(GenericAttributes.a).setValue(Double.MAX_VALUE);this.getAttributeInstance(GenericAttributes.c).setValue(Double.MAX_VALUE); } @Overridepublic void move(double d0, double d1, double d2) { } } My Main Class: Code:java package me.macboinc1.stationarymobs; import java.util.logging.Level; import org.bukkit.plugin.java.JavaPlugin; public class StationaryMobs extends JavaPlugin { public void onEnable() {getLogger().log(Level.INFO, "StationaryMobs has been initated!");} } What am I doing wrong?
How would I do that? ░░░░░░░░░░░░░░░░░░ ░░░░░░░░░░░░░░░░░░ ░░░░░░░░░░░░░░░░░░ ░░░░░░░░▓░░░░░░░░░ ░░░░░░░░▓░░░░░░░░░ ░░░░░░░░▓░░░░░░░░░ ░░░░░░░░▓░░░░░░░░░ ░░░░░░░░▓░░░░░░░░░ ░░░░░░░░▓░░░░░░░░░ ░░░░░░░░░░░░░░░░░░ ░░░░░░░░▓░░░░░░░░░
Read the tutorial I posted with the thread https://forums.bukkit.org/threads/nms-tutorial-how-to-override-default-minecraft-mobs.216788/
macboinc If you had read it you would know what to do.. Code:java public static void registerEntity(Class paramClass, String paramString, int paramInt) {try {((Map) getPrivateStatic(EntityTypes.class, "c")).put(paramString, paramClass);((Map) getPrivateStatic(EntityTypes.class, "d")).put(paramClass, paramString);((Map) getPrivateStatic(EntityTypes.class, "e")).put(Integer.valueOf(paramInt), paramClass);((Map) getPrivateStatic(EntityTypes.class, "f")).put(paramClass, Integer.valueOf(paramInt));((Map) getPrivateStatic(EntityTypes.class, "g")).put(paramString, Integer.valueOf(paramInt));} catch (Exception exc) {// Unable to register the new class.}} To register the entity do: registerEntity(nmsClass, MinecraftName, MinecarftID) where the nmsClass is you custom entity class, MinecraftName is the name of the entity (e.g. "Zombie") and MinecraftID is the entities ID. Then to unregister the entities do the same but instead of "nmsClass" use the entities actual class (e.g. EntityZombie.class). Edit: It's the same idea as what the tutorial says.
Honestly, this thread is filled with a bunch of trolls in my opinion. This is a valid, well written tutorial, and cites sources, so stop posting useless content:
-sigh- Again, this is all in the tutorial... Code:java private static Object getPrivateStatic(Class clazz, String f) throws Exception {Field field = clazz.getDeclaredField(f);field.setAccessible(true);return field.get(null);}