Spawn in EndCrystals to Spawn in EnderDragon

Discussion in 'Spigot Plugin Development' started by Xsm0deus, May 26, 2018.

  1. I've tried spawning in EndCrystals at the location where a player would place them to get the enderdragon spawn in sequence but it doesn't do anything, is there a specific way to do this?
     
  2. Just Spawn an Ender Dragon
     
  3. no
     
    • Funny Funny x 1
  4. FYI: The point is to get the spawn in sequence
     
  5. NMS is the way
     
  6. Never used NMS before
     
  7. Yea I've had this problem before... the way i fixed my situation was...
    You give permission to place the endercrystal above the bedrock block (World Guard).
    1: Create 4 1x1 Regions.
    2: define the regions.
    3: let certain ranks place them.
    really simple.
     
  8. Don't want people to place them, thats the issue
     
  9. I think ender crystals are considered as entities just summon them
     
  10. Spigot version 1.12.2 has them in creative also they are craft-able to the player.
    even if you are using an older version you would summon them, then place a block near them to trigger them.
     
  11. Done that already, they spawn in where they're suppose to but doesn't start the dragon fight
     
  12. The reason placing the end crystals pragmatically doesn't work is the dragon gets spawned in the usage of placing the item in the world.

    Code (Java):
    public EnumInteractionResult a(EntityHuman entityhuman, World world, BlockPosition blockposition, EnumHand enumhand, EnumDirection enumdirection, float f, float f1, float f2) {
        IBlockData iblockdata = world.getType(blockposition);

        if (iblockdata.getBlock() != Blocks.OBSIDIAN && iblockdata.getBlock() != Blocks.BEDROCK) {
            return EnumInteractionResult.FAIL;
        } else {
            BlockPosition blockposition1 = blockposition.up();
            ItemStack itemstack = entityhuman.b(enumhand);

            if (!entityhuman.a(blockposition1, enumdirection, itemstack)) {
                return EnumInteractionResult.FAIL;
            } else {
                BlockPosition blockposition2 = blockposition1.up();
                boolean flag = !world.isEmpty(blockposition1) && !world.getType(blockposition1).getBlock().a((IBlockAccess) world, blockposition1);

                flag |= !world.isEmpty(blockposition2) && !world.getType(blockposition2).getBlock().a((IBlockAccess) world, blockposition2);
                if (flag) {
                    return EnumInteractionResult.FAIL;
                } else {
                    double d0 = (double) blockposition1.getX();
                    double d1 = (double) blockposition1.getY();
                    double d2 = (double) blockposition1.getZ();
                    List list = world.getEntities((Entity) null, new AxisAlignedBB(d0, d1, d2, d0 + 1.0D, d1 + 2.0D, d2 + 1.0D));

                    if (!list.isEmpty()) {
                        return EnumInteractionResult.FAIL;
                    } else {
                        if (!world.isClientSide) {
                            EntityEnderCrystal entityendercrystal = new EntityEnderCrystal(world, (double) ((float) blockposition.getX() + 0.5F), (double) (blockposition.getY() + 1), (double) ((float) blockposition.getZ() + 0.5F));

                            entityendercrystal.setShowingBottom(false);
                            world.addEntity(entityendercrystal);
                            if (world.worldProvider instanceof WorldProviderTheEnd) {
                                EnderDragonBattle enderdragonbattle = ((WorldProviderTheEnd) world.worldProvider).t();

                                enderdragonbattle.e();
                            }
                        }

                        itemstack.subtract(1);
                        return EnumInteractionResult.SUCCESS;
                    }
                }
            }
        }
    }
    This is the method that gets triggered when a player uses the end crystal item (aka, right clicks the ground while holding it). Notice it is checking for surrounding end crystals already placed. If it finds this is the 4th on placed is spawns the dragon with enderdragonbattle.e()

    Using this knowledge you can easily summon the dragon (battle) yourself using NMS.

    Also, as a side note: For readbility's sake you can cross reference NMS to MCP by using the Forge source code. Here is the exact same method, but looking at Forge's source which is far more readable:

    Code (Java):
    public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
    {
        IBlockState iblockstate = worldIn.getBlockState(pos);

        if (iblockstate.getBlock() != Blocks.OBSIDIAN && iblockstate.getBlock() != Blocks.BEDROCK)
        {
            return EnumActionResult.FAIL;
        }
        else
        {
            BlockPos blockpos = pos.up();
            ItemStack itemstack = player.getHeldItem(hand);

            if (!player.canPlayerEdit(blockpos, facing, itemstack))
            {
                return EnumActionResult.FAIL;
            }
            else
            {
                BlockPos blockpos1 = blockpos.up();
                boolean flag = !worldIn.isAirBlock(blockpos) && !worldIn.getBlockState(blockpos).getBlock().isReplaceable(worldIn, blockpos);
                flag = flag | (!worldIn.isAirBlock(blockpos1) && !worldIn.getBlockState(blockpos1).getBlock().isReplaceable(worldIn, blockpos1));

                if (flag)
                {
                    return EnumActionResult.FAIL;
                }
                else
                {
                    double d0 = (double)blockpos.getX();
                    double d1 = (double)blockpos.getY();
                    double d2 = (double)blockpos.getZ();
                    List<Entity> list = worldIn.getEntitiesWithinAABBExcludingEntity((Entity)null, new AxisAlignedBB(d0, d1, d2, d0 + 1.0D, d1 + 2.0D, d2 + 1.0D));

                    if (!list.isEmpty())
                    {
                        return EnumActionResult.FAIL;
                    }
                    else
                    {
                        if (!worldIn.isRemote)
                        {
                            EntityEnderCrystal entityendercrystal = new EntityEnderCrystal(worldIn, (double)((float)pos.getX() + 0.5F), (double)(pos.getY() + 1), (double)((float)pos.getZ() + 0.5F));
                            entityendercrystal.setShowBottom(false);
                            worldIn.spawnEntity(entityendercrystal);

                            if (worldIn.provider instanceof WorldProviderEnd)
                            {
                                DragonFightManager dragonfightmanager = ((WorldProviderEnd)worldIn.provider).getDragonFightManager();
                                dragonfightmanager.respawnDragon();
                            }
                        }

                        itemstack.shrink(1);
                        return EnumActionResult.SUCCESS;
                    }
                }
            }
        }
    }
     
  13. can't I just do something like

    Code (Text):
    if (world.worldProvider instanceof WorldProviderTheEnd) {
                                EnderDragonBattle enderdragonbattle = ((WorldProviderTheEnd) world.worldProvider).t();

                                enderdragonbattle.e();
                            }
     
  14. That don't work btw world.worldProvider doesn't work.
    I don't know