Solved Please delete

Discussion in 'Spigot Plugin Development' started by sistem21, Jun 12, 2016.

  1. Hi guys, today i was working on a plugin which gives players the ability of ride PolarBears of minecraft 1.10.
    I've worked with nms to make players control the bears, overriding the method g(float f, float f1) of the class EntityLiving.
    The problem is that when i right click a bear, the server crashes.
    Here is the code:
    Code (mainclass (Unknown Language)):
    package me.sistem21.potatobears;

    import java.lang.reflect.Field;
    import java.lang.reflect.Method;
    import java.util.Map;

    import net.minecraft.server.v1_10_R1.EntityTypes;

    import org.bukkit.Bukkit;
    import org.bukkit.entity.Player;
    import org.bukkit.entity.PolarBear;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerInteractEntityEvent;

    public class PotatoBears extends JavaPlugin implements Listener {

       public void onEnable() {
         Bukkit.getServer().getPluginManager().registerEvents(this, this);

       public void on(PlayerInteractEntityEvent e) {
         Player p = e.getPlayer();
         if (e.getRightClicked() instanceof PolarBear) {
           PolarBear bear = (PolarBear) e.getRightClicked();
       public static void registerBear(){
      try {
      final Field idMapField = EntityTypes.class.getDeclaredField("e");
      Map<Integer, Class<?>> idMap = (Map<Integer, Class<?>>) idMapField.get(null);
      final Field nameMapField = EntityTypes.class.getDeclaredField("c");
      Map<String, Class<?>> nameMap = (Map<String, Class<?>>) nameMapField.get(null);
      final Method a = EntityTypes.class.getDeclaredMethod("a", Class.class, String.class, Integer.TYPE);
      a.invoke(null, CustomEntityPolarBear.class, "PolarBear", 102);
      } catch (Throwable t) {

    Code (custombearclass (Unknown Language)):

    package me.sistem21.potatobears;

    import java.lang.reflect.Field;

    import net.minecraft.server.v1_10_R1.Entity;
    import net.minecraft.server.v1_10_R1.EntityHuman;
    import net.minecraft.server.v1_10_R1.EntityLiving;
    import net.minecraft.server.v1_10_R1.EntityPolarBear;
    import net.minecraft.server.v1_10_R1.GenericAttributes;
    import net.minecraft.server.v1_10_R1.World;

    public class CustomEntityPolarBear extends EntityPolarBear {

       public CustomEntityPolarBear(World world) {

       public void g(float f, float f1) {
         EntityLiving entityLiving = (EntityLiving);
         if (entityLiving == null) {
           for (Entity e : this.passengers) {
             if (e instanceof EntityHuman) {
               entityLiving = (EntityLiving) e;

           if (entityLiving == null) {
             this.P = 0.5F;
             super.g(f, f1);

         float yaw = entityLiving.yaw;
         this.yaw = yaw;
         this.lastYaw = yaw;
         this.pitch = entityLiving.pitch * 0.5F;
         this.setYawPitch(this.yaw, this.pitch);
         float yaw2 = this.yaw;
         this.aO = yaw2;
         this.aQ = yaw2;

         f = * 0.5F;
         f1 =;
         if (f1 <= 0.0F) {
           f1 *= 0.25F;

         this.g(f, f1);

         Field jump = null;
      try {
      jump = EntityLiving.class.getDeclaredField("aW");
      } catch (NoSuchFieldException e1) {
      } catch (SecurityException e1) {
      if (jump != null && this.onGround) {
      try {
      if (jump.getBoolean(entityLiving)) {
      double jumpHeight = 0.5D;
      this.motY = jumpHeight;
      } catch (IllegalAccessException e) {

    And here is the crash report:
    ---- Minecraft Crash Report ----
    // You're mean.

    Time: 12/06/16 11.41
    Description: Ticking entity

    java.lang.StackOverflowError: Ticking entity
    at java.util.HashMap.hash(Unknown Source)
    at java.util.HashMap.get(Unknown Source)
    at net.minecraft.server.v1_10_R1.AttributeMapBase.a(SourceFile:17)
    at net.minecraft.server.v1_10_R1.AttributeMapServer.e(SourceFile:16)
    at net.minecraft.server.v1_10_R1.AttributeMapServer.a(SourceFile:10)
    at net.minecraft.server.v1_10_R1.EntityLiving.getAttributeInstance(
    at me.sistem21.potatobears.CustomEntityPolarBear.g(
    at me.sistem21.potatobears.CustomEntityPolarBear.g(
    at me.sistem21.potatobears.CustomEntityPolarBear.g(

    Entity's Vehicle: ~~ERROR~~ NullPointerException: null
    at net.minecraft.server.v1_10_R1.World.tickEntities(
    at net.minecraft.server.v1_10_R1.WorldServer.tickEntities(
    at net.minecraft.server.v1_10_R1.MinecraftServer.D(
    at net.minecraft.server.v1_10_R1.DedicatedServer.D(
    at net.minecraft.server.v1_10_R1.MinecraftServer.C(
    at Source)

    This is the line 52:
    Code (Text):
    this.g(f, f1);

    Sorry for my shoddy english, i'm italian ;)
    #1 sistem21, Jun 12, 2016
    Last edited: Jun 12, 2016
  2. you really shouldn't do that if you have a problem even if you solve it by yourself you should paste here how you fixed it so you can help people who might have your problem. And also don't change the title the thread won't be deleted
    • Like Like x 1
  3. i9hdkill

    i9hdkill Retired Moderator
    Retired Supporter

    Please post your solution, so others can profit from your solution aswell.
    • Agree Agree x 2