Java Code Examples for net.minecraft.world.World#getChunkFromBlockCoords()

The following examples show how to use net.minecraft.world.World#getChunkFromBlockCoords() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GT_TileEntity_BioVat.java    From bartworks with MIT License 6 votes vote down vote up
private void check_Chunk() {
    World aWorld = this.getBaseMetaTileEntity().getWorld();
    if (!aWorld.isRemote) {

        for (Object tObject : aWorld.playerEntities) {
            if (!(tObject instanceof EntityPlayerMP)) {
                break;
            }
            EntityPlayerMP tPlayer = (EntityPlayerMP) tObject;
            Chunk tChunk = aWorld.getChunkFromBlockCoords(this.getBaseMetaTileEntity().getXCoord(), this.getBaseMetaTileEntity().getZCoord());
            if (tPlayer.getServerForPlayer().getPlayerManager().isPlayerWatchingChunk(tPlayer, tChunk.xPosition, tChunk.zPosition)) {
                if (!this.playerMPHashSet.contains(tPlayer)) {
                    this.playerMPHashSet.add(tPlayer);
                    this.sendAllRequiredRendererPackets();
                }
            } else {
                this.playerMPHashSet.remove(tPlayer);
            }

        }
    }
}
 
Example 2
Source File: BW_Network.java    From bartworks with MIT License 6 votes vote down vote up
public void sendPacketToAllPlayersInRange(World aWorld, @Nonnull GT_Packet aPacket, int aX, int aZ) {
    if (!aWorld.isRemote) {

        for (Object tObject : aWorld.playerEntities) {
            if (!(tObject instanceof EntityPlayerMP)) {
                break;
            }

            EntityPlayerMP tPlayer = (EntityPlayerMP) tObject;
            Chunk tChunk = aWorld.getChunkFromBlockCoords(aX, aZ);
            if (tPlayer.getServerForPlayer().getPlayerManager().isPlayerWatchingChunk(tPlayer, tChunk.xPosition, tChunk.zPosition)) {
                this.sendToPlayer(aPacket, tPlayer);
            }
        }
    }
}
 
Example 3
Source File: BiomeHandler.java    From AdvancedRocketry with MIT License 5 votes vote down vote up
public static void changeBiome(World world, int biomeId, BlockPos pos) {
	Chunk chunk = world.getChunkFromBlockCoords(pos);

	Biome biome = world.getBiome(pos);
	Biome biomeTo = Biome.getBiome(biomeId);
	
	if(biome == biomeTo)
		return;
	
	int y = 60;
	if(biome.topBlock != biomeTo.topBlock) {
		BlockPos yy = world.getHeight(pos);
		
		while(!world.getBlockState(yy.down()).isOpaqueCube() && yy.getY() > 0)
			yy = yy.down();
		
		if(world.getBlockState(yy.down()) == biome.topBlock)
			world.setBlockState(yy.down(), biomeTo.topBlock);
	}

	byte[] biomeArr = chunk.getBiomeArray();
	try {
		biomeArr[(pos.getX() & 15) + (pos.getZ() & 15)*16] = (byte)biomeId;
	} catch (IndexOutOfBoundsException e) {
		e.printStackTrace();
	}

	PacketHandler.sendToNearby(new PacketBiomeIDChange(chunk, world, new HashedBlockPosition(pos)), world.provider.getDimension(), pos, 256);
}
 
Example 4
Source File: SemiBlockManager.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
public ISemiBlock getSemiBlock(World world, int x, int y, int z){
    for(ISemiBlock semiBlock : addingBlocks) {
        if(semiBlock.getWorld() == world && semiBlock.getPos().equals(new ChunkPosition(x, y, z))) return semiBlock;
    }

    Chunk chunk = world.getChunkFromBlockCoords(x, z);
    Map<ChunkPosition, ISemiBlock> map = semiBlocks.get(chunk);
    if(map != null) {
        return map.get(new ChunkPosition(x, y, z));
    } else {
        return null;
    }
}
 
Example 5
Source File: StaticUtils.java    From BigReactors with MIT License 5 votes vote down vote up
public static TileEntity getTileEntityUnsafe(World world, int x, int y, int z) {
	TileEntity te = null;
	
	Chunk chunk = world.getChunkFromBlockCoords(x, z);
	if(chunk != null) {
		te = chunk.getTileEntityUnsafe(x & 0x0F, y, z & 0x0F);
	}
	
	return te;
}
 
Example 6
Source File: EndstoneProtectorManager.java    From SkyblockAddons with MIT License 4 votes vote down vote up
public static void checkGolemStatus() {
    Minecraft mc = Minecraft.getMinecraft();
    SkyblockAddons main = SkyblockAddons.getInstance();

    if (mc.theWorld != null && (main.getUtils().getLocation() == Location.THE_END || main.getUtils().getLocation() == Location.DRAGONS_NEST) &&
            main.getConfigValues().isEnabled(Feature.ENDSTONE_PROTECTOR_DISPLAY)) {
        World world = mc.theWorld;

        Chunk chunk = world.getChunkFromBlockCoords(new BlockPos(-689, 5, -273)); // This is the original spawn.
        if (chunk == null || !chunk.isLoaded()) {
            canDetectSkull = false;
            return;
        }

        Stage newStage = Stage.detectStage();
        for (Entity entity : world.loadedEntityList) {
            if (entity instanceof EntityIronGolem) {
                newStage = Stage.GOLEM_ALIVE;
                break;
            }
        }

        canDetectSkull = true;
        if (minibossStage != newStage) {
            int timeTaken = (int) (System.currentTimeMillis()-lastWaveStart);
            String previousStage = (minibossStage == null ? "null" : minibossStage.name());

            String zealotsKilled = "N/A";
            if (minibossStage != null) {
                zealotsKilled = String.valueOf(zealotCount);
            }

            int totalSeconds = timeTaken/1000;
            int minutes = totalSeconds/60;
            int seconds = totalSeconds%60;

            main.getLogger().info("Endstone Protector stage updated from "+previousStage+" to "+newStage.name()+". " +
                    "Your zealot kill count was "+zealotsKilled+". This took "+minutes+"m "+seconds+"s.");

            if (minibossStage == Stage.GOLEM_ALIVE && newStage == Stage.NO_HEAD) {
                zealotCount = 0;
            }

            minibossStage = newStage;
            lastWaveStart = System.currentTimeMillis();
        }
    } else {
        canDetectSkull = false;
    }
}
 
Example 7
Source File: EntityTofuSlime.java    From TofuCraftReload with MIT License 4 votes vote down vote up
public static boolean isSpawnChunk(World world, double x, double z) {
    BlockPos blockpos = new BlockPos(MathHelper.floor(x), 0, MathHelper.floor(z));
    Chunk var1 = world.getChunkFromBlockCoords(blockpos);
    return var1.getRandomWithSeed(987234911L).nextInt(8) == 0;
}
 
Example 8
Source File: WorldOverlayRenderer.java    From NotEnoughItems with MIT License 4 votes vote down vote up
private static void renderMobSpawnOverlay(Entity entity) {
    if (mobOverlay == 0) {
        return;
    }

    boolean cms = Loader.instance().isModLoaded("customspawner");

    GlStateManager.disableTexture2D();
    GlStateManager.disableLighting();
    glLineWidth(1.5F);
    glBegin(GL_LINES);

    GlStateManager.color(1, 0, 0);

    World world = entity.world;
    int x1 = (int) entity.posX;
    int z1 = (int) entity.posZ;
    int y1 = (int) MathHelper.clip(entity.posY, 16, world.getHeight() - 16);

    for (int x = x1 - 16; x <= x1 + 16; x++) {
        for (int z = z1 - 16; z <= z1 + 16; z++) {
            BlockPos pos = new BlockPos(x, y1, z);
            Chunk chunk = world.getChunkFromBlockCoords(pos);
            Biome biome = world.getBiome(pos);
            if ((!cms && biome.getSpawnableList(EnumCreatureType.MONSTER).isEmpty()) || biome.getSpawningChance() <= 0) {
                continue;
            }

            for (int y = y1 - 16; y < y1 + 16; y++) {
                int spawnMode = getSpawnMode(chunk, x, y, z);
                if (spawnMode == 0) {
                    continue;
                }

                if (spawnMode == 1) {
                    GlStateManager.color(1, 1, 0);
                } else {
                    GlStateManager.color(1, 0, 0);
                }

                glVertex3d(x, y + 0.004, z);
                glVertex3d(x + 1, y + 0.004, z + 1);
                glVertex3d(x + 1, y + 0.004, z);
                glVertex3d(x, y + 0.004, z + 1);
            }
        }
    }

    glEnd();
    GlStateManager.enableLighting();
    GlStateManager.enableTexture2D();
}
 
Example 9
Source File: OilGeneratorFix.java    From NewHorizonsCoreMod with GNU General Public License v3.0 4 votes vote down vote up
private int getTopBlock( World pWorld, int pLocX, int pLocZ )
{
  Chunk tChunk = pWorld.getChunkFromBlockCoords( pLocX, pLocZ );
  int y = tChunk.getTopFilledSegment() + 15;

  int trimmedX = pLocX & 0xF;
  int trimmedZ = pLocZ & 0xF;
  for( ; y > 0; y-- )
  {
    Block tBlock = tChunk.getBlock( trimmedX, y, trimmedZ );

    if( !tBlock.isAir( pWorld, pLocX, y, pLocZ ) )
    {

      if(tBlock instanceof BlockStaticLiquid)
      {
        return y;
      }

      if(tBlock instanceof BlockFluidBase)
      {
        return y;
      }

      if(tBlock instanceof IFluidBlock)
      {
        return y;
      }

      if( tBlock.getMaterial().blocksMovement() )
      {

        if( !( tBlock instanceof BlockFlower ) )
        {

          return y - 1;
        }
      }
    }
  }
  return -1;
}
 
Example 10
Source File: WorldGenLargeCrystal.java    From AdvancedRocketry with MIT License 4 votes vote down vote up
public void setBlockState(World world, BlockPos pos, IBlockState state) {
	Chunk chunk = world.getChunkFromBlockCoords(pos);
	chunk.setBlockState(pos, state);
}
 
Example 11
Source File: WorldOverlayRenderer.java    From NotEnoughItems with MIT License 4 votes vote down vote up
private static void renderMobSpawnOverlay(Entity entity) {
    if (mobOverlay == 0)
        return;

    GlStateManager.disableTexture2D();
    GlStateManager.disableLighting();
    glLineWidth(1.5F);
    glBegin(GL_LINES);

    GlStateManager.color(1, 0, 0);

    World world = entity.worldObj;
    int x1 = (int) entity.posX;
    int z1 = (int) entity.posZ;
    int y1 = (int) MathHelper.clip(entity.posY, 16, world.getHeight() - 16);

    for (int x = x1 - 16; x <= x1 + 16; x++)
        for (int z = z1 - 16; z <= z1 + 16; z++) {
            BlockPos pos = new BlockPos(x, y1, z);
            Chunk chunk = world.getChunkFromBlockCoords(pos);
            BiomeGenBase biome = world.getBiomeGenForCoords(pos);
            if (biome.getSpawnableList(EnumCreatureType.MONSTER).isEmpty() || biome.getSpawningChance() <= 0)
                continue;

            for (int y = y1 - 16; y < y1 + 16; y++) {
                int spawnMode = getSpawnMode(chunk, x, y, z);
                if (spawnMode == 0)
                    continue;

                if (spawnMode == 1)
                    GlStateManager.color(1, 1, 0);
                else
                    GlStateManager.color(1, 0, 0);

                glVertex3d(x, y + 0.004, z);
                glVertex3d(x + 1, y + 0.004, z + 1);
                glVertex3d(x + 1, y + 0.004, z);
                glVertex3d(x, y + 0.004, z + 1);
            }
        }

    glEnd();
    GlStateManager.enableLighting();
    GlStateManager.enableTexture2D();
}