Java Code Examples for net.minecraft.util.math.ChunkPos#asLong()
The following examples show how to use
net.minecraft.util.math.ChunkPos#asLong() .
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: SchematicWorldRenderingNotifier.java From litematica with GNU Lesser General Public License v3.0 | 6 votes |
public static void markSchematicChunkForRenderUpdate(SubChunkPos chunkPos) { World world = SchematicWorldHandler.getSchematicWorld(); if (world != null) { Long2ObjectMap<Chunk> schematicChunks = ((IMixinChunkProviderClient) (Object) world.getChunkProvider()).getLoadedChunks(); Long2ObjectMap<Chunk> clientChunks = ((IMixinChunkProviderClient) (Object) Minecraft.getMinecraft().world.getChunkProvider()).getLoadedChunks(); long key = ChunkPos.asLong(chunkPos.getX(), chunkPos.getZ()); if (schematicChunks.containsKey(key) && clientChunks.containsKey(key)) { RenderGlobal rg = LitematicaRenderer.getInstance().getWorldRenderer(); rg.markBlockRangeForRenderUpdate((chunkPos.getX() << 4) - 1, (chunkPos.getY() << 4) - 1, (chunkPos.getZ() << 4) - 1, (chunkPos.getX() << 4) + 1, (chunkPos.getY() << 4) + 1, (chunkPos.getZ() << 4) + 1); } } }
Example 2
Source File: SchematicWorldRenderingNotifier.java From litematica with GNU Lesser General Public License v3.0 | 6 votes |
public static void markSchematicChunksForRenderUpdate(ChunkPos chunkPos) { World world = SchematicWorldHandler.getSchematicWorld(); if (world != null) { Long2ObjectMap<Chunk> schematicChunks = ((IMixinChunkProviderClient) (Object) world.getChunkProvider()).getLoadedChunks(); Long2ObjectMap<Chunk> clientChunks = ((IMixinChunkProviderClient) (Object) Minecraft.getMinecraft().world.getChunkProvider()).getLoadedChunks(); long key = ChunkPos.asLong(chunkPos.x, chunkPos.z); if (schematicChunks.containsKey(key) && clientChunks.containsKey(key)) { RenderGlobal rg = LitematicaRenderer.getInstance().getWorldRenderer(); rg.markBlockRangeForRenderUpdate((chunkPos.x << 4) - 1, 0, (chunkPos.z << 4) - 1, (chunkPos.x << 4) + 1, 255, (chunkPos.z << 4) + 1); } } }
Example 3
Source File: SchematicWorldRenderingNotifier.java From litematica with GNU Lesser General Public License v3.0 | 6 votes |
public static void markSchematicChunkForRenderUpdate(BlockPos pos) { World world = SchematicWorldHandler.getSchematicWorld(); if (world != null) { Long2ObjectMap<Chunk> schematicChunks = ((IMixinChunkProviderClient) (Object) world.getChunkProvider()).getLoadedChunks(); Long2ObjectMap<Chunk> clientChunks = ((IMixinChunkProviderClient) (Object) Minecraft.getMinecraft().world.getChunkProvider()).getLoadedChunks(); long key = ChunkPos.asLong(pos.getX() >> 4, pos.getZ() >> 4); if (schematicChunks.containsKey(key) && clientChunks.containsKey(key)) { RenderGlobal rg = LitematicaRenderer.getInstance().getWorldRenderer(); rg.markBlockRangeForRenderUpdate(pos.getX() - 1, pos.getY() - 1, pos.getZ() - 1,pos.getX() + 1, pos.getY() + 1, pos.getZ() + 1); } } }
Example 4
Source File: ShipData.java From Valkyrien-Skies with Apache License 2.0 | 6 votes |
/** * @return Every Chunk that this entity owns/claims represented as a long; for indexing * purposes */ private static Set<Long> getChunkLongs(PhysicsWrapperEntity entity) { Set<Long> chunkLongs = new HashSet<>(); VSChunkClaim ownedChunks = entity.getPhysicsObject().getOwnedChunks(); int centerX = ownedChunks.getCenterX(); int centerZ = ownedChunks.getCenterZ(); int radius = ownedChunks.getRadius(); for (int x = centerX - radius; x <= centerX + radius; x++) { for (int z = centerZ - radius; z <= centerZ + radius; z++) { long chunkPos = ChunkPos.asLong(x, z); chunkLongs.add(chunkPos); } } return chunkLongs; }
Example 5
Source File: DummyChunkProvider.java From GregTech with GNU Lesser General Public License v3.0 | 5 votes |
@Override public Chunk provideChunk(int x, int z) { long chunkKey = ChunkPos.asLong(x, z); if (loadedChunks.containsKey(chunkKey)) return loadedChunks.get(chunkKey); Chunk chunk = new Chunk(world, x, z); loadedChunks.put(chunkKey, chunk); return chunk; }
Example 6
Source File: CraftWorld.java From Kettle with GNU General Public License v3.0 | 5 votes |
public boolean regenerateChunk(int x, int z) { if (!unloadChunk0(x, z, false)) { return false; } final long chunkKey = ChunkPos.asLong(x, z); world.getChunkProvider().droppedChunksSet.remove(chunkKey); net.minecraft.world.chunk.Chunk chunk = null; chunk = world.getChunkProvider().chunkGenerator.generateChunk(x, z); PlayerChunkMapEntry playerChunk = world.getPlayerChunkMap().getEntry(x, z); if (playerChunk != null) { playerChunk.chunk = chunk; } if (chunk != null) { world.getChunkProvider().id2ChunkMap.put(chunkKey, chunk); chunk.onLoad(); chunk.populateCB(world.getChunkProvider(), world.getChunkProvider().chunkGenerator, true); refreshChunk(x, z); } return chunk != null; }
Example 7
Source File: PhysicsParticleManager.java From Valkyrien-Skies with Apache License 2.0 | 5 votes |
private boolean canParticlePassThrough(World world, BlockPos pos) { ChunkProviderServer serverProvider = (ChunkProviderServer) world.getChunkProvider(); // If the chunk isn't loaded, then no problem ignore it. long chunkKey = ChunkPos.asLong(pos.getX() >> 4, pos.getZ() >> 4); if (!serverProvider.loadedChunks.containsKey(chunkKey)) { this.isParticleDead = true; return true; } IBlockState collisionState = serverProvider.loadedChunks.get(chunkKey) .getBlockState(pos); // Otherwise we have to bypass the world blockstate get because sponge has some protection on it. // System.out.println("oof"); return collisionState.getBlock().isPassable(world, pos); }
Example 8
Source File: SpongeQueue_1_11.java From FastAsyncWorldedit with GNU General Public License v3.0 | 4 votes |
public boolean regenerateChunk(net.minecraft.world.World world, int x, int z) { IChunkProvider provider = world.getChunkProvider(); if (!(provider instanceof ChunkProviderServer)) { return false; } BlockFalling.fallInstantly = true; try { ChunkProviderServer chunkServer = (ChunkProviderServer) provider; IChunkGenerator gen = (IChunkGenerator) fieldChunkGenerator.get(chunkServer); long pos = ChunkPos.asLong(x, z); Chunk mcChunk; if (chunkServer.chunkExists(x, z)) { mcChunk = chunkServer.loadChunk(x, z); mcChunk.onChunkUnload(); } PlayerChunkMap playerManager = ((WorldServer) getWorld()).getPlayerChunkMap(); List<EntityPlayerMP> oldWatchers = null; if (chunkServer.chunkExists(x, z)) { mcChunk = chunkServer.loadChunk(x, z); PlayerChunkMapEntry entry = playerManager.getEntry(x, z); if (entry != null) { Field fieldPlayers = PlayerChunkMapEntry.class.getDeclaredField("field_187283_c"); fieldPlayers.setAccessible(true); oldWatchers = (List<EntityPlayerMP>) fieldPlayers.get(entry); playerManager.removeEntry(entry); } mcChunk.onChunkUnload(); } try { Field droppedChunksSetField = chunkServer.getClass().getDeclaredField("field_73248_b"); droppedChunksSetField.setAccessible(true); Set droppedChunksSet = (Set) droppedChunksSetField.get(chunkServer); droppedChunksSet.remove(pos); } catch (Throwable e) { MainUtil.handleError(e); } Long2ObjectMap<Chunk> id2ChunkMap = (Long2ObjectMap<Chunk>) fieldId2ChunkMap.get(chunkServer); id2ChunkMap.remove(pos); mcChunk = gen.provideChunk(x, z); id2ChunkMap.put(pos, mcChunk); if (mcChunk != null) { mcChunk.onChunkLoad(); mcChunk.populateChunk(chunkServer, gen); } if (oldWatchers != null) { for (EntityPlayerMP player : oldWatchers) { playerManager.addPlayer(player); } } return true; } catch (Throwable t) { MainUtil.handleError(t); return false; } finally { BlockFalling.fallInstantly = false; } }
Example 9
Source File: SpongeQueue_1_12.java From FastAsyncWorldedit with GNU General Public License v3.0 | 4 votes |
public boolean regenerateChunk(net.minecraft.world.World world, int x, int z) { IChunkProvider provider = world.getChunkProvider(); if (!(provider instanceof ChunkProviderServer)) { return false; } BlockFalling.fallInstantly = true; try { ChunkProviderServer chunkServer = (ChunkProviderServer) provider; IChunkGenerator gen = (IChunkGenerator) fieldChunkGenerator.get(chunkServer); long pos = ChunkPos.asLong(x, z); Chunk mcChunk; if (chunkServer.chunkExists(x, z)) { mcChunk = chunkServer.loadChunk(x, z); mcChunk.onUnload(); } PlayerChunkMap playerManager = ((WorldServer) getWorld()).getPlayerChunkMap(); List<EntityPlayerMP> oldWatchers = null; if (chunkServer.chunkExists(x, z)) { mcChunk = chunkServer.loadChunk(x, z); PlayerChunkMapEntry entry = playerManager.getEntry(x, z); if (entry != null) { Field fieldPlayers = PlayerChunkMapEntry.class.getDeclaredField("field_187283_c"); fieldPlayers.setAccessible(true); oldWatchers = (List<EntityPlayerMP>) fieldPlayers.get(entry); playerManager.removeEntry(entry); } mcChunk.onUnload(); } try { Field droppedChunksSetField = chunkServer.getClass().getDeclaredField("field_73248_b"); droppedChunksSetField.setAccessible(true); Set droppedChunksSet = (Set) droppedChunksSetField.get(chunkServer); droppedChunksSet.remove(pos); } catch (Throwable e) { MainUtil.handleError(e); } Long2ObjectMap<Chunk> id2ChunkMap = (Long2ObjectMap<Chunk>) fieldId2ChunkMap.get(chunkServer); id2ChunkMap.remove(pos); mcChunk = gen.generateChunk(x, z); id2ChunkMap.put(pos, mcChunk); if (mcChunk != null) { mcChunk.onLoad(); mcChunk.populate(chunkServer, gen); } if (oldWatchers != null) { for (EntityPlayerMP player : oldWatchers) { playerManager.addPlayer(player); } } return true; } catch (Throwable t) { MainUtil.handleError(t); return false; } finally { BlockFalling.fallInstantly = false; } }
Example 10
Source File: ForgeQueue_All.java From FastAsyncWorldedit with GNU General Public License v3.0 | 4 votes |
public boolean regenerateChunk(World world, int x, int z) { IChunkProvider provider = world.getChunkProvider(); if (!(provider instanceof ChunkProviderServer)) { return false; } BlockFalling.fallInstantly = true; try { ChunkProviderServer chunkServer = (ChunkProviderServer) provider; IChunkGenerator gen = (IChunkGenerator) fieldChunkGenerator.get(chunkServer); long pos = ChunkPos.asLong(x, z); Chunk mcChunk; if (chunkServer.chunkExists(x, z)) { mcChunk = chunkServer.loadChunk(x, z); mcChunk.onUnload(); } PlayerChunkMap playerManager = ((WorldServer) getWorld()).getPlayerChunkMap(); List<EntityPlayerMP> oldWatchers = null; if (chunkServer.chunkExists(x, z)) { mcChunk = chunkServer.loadChunk(x, z); PlayerChunkMapEntry entry = playerManager.getEntry(x, z); if (entry != null) { Field fieldPlayers = PlayerChunkMapEntry.class.getDeclaredField("field_187283_c"); fieldPlayers.setAccessible(true); oldWatchers = (List<EntityPlayerMP>) fieldPlayers.get(entry); playerManager.removeEntry(entry); } mcChunk.onUnload(); } try { Field droppedChunksSetField = chunkServer.getClass().getDeclaredField("field_73248_b"); droppedChunksSetField.setAccessible(true); Set droppedChunksSet = (Set) droppedChunksSetField.get(chunkServer); droppedChunksSet.remove(pos); } catch (Throwable e) { MainUtil.handleError(e); } Long2ObjectMap<Chunk> id2ChunkMap = chunkServer.id2ChunkMap; id2ChunkMap.remove(pos); mcChunk = gen.generateChunk(x, z); id2ChunkMap.put(pos, mcChunk); if (mcChunk != null) { mcChunk.onLoad(); mcChunk.populate(chunkServer, gen); } if (oldWatchers != null) { for (EntityPlayerMP player : oldWatchers) { playerManager.addPlayer(player); } } return true; } catch (Throwable t) { MainUtil.handleError(t); return false; } finally { BlockFalling.fallInstantly = false; } }
Example 11
Source File: ForgeQueue_All.java From FastAsyncWorldedit with GNU General Public License v3.0 | 4 votes |
public boolean regenerateChunk(World world, int x, int z) { IChunkProvider provider = world.getChunkProvider(); if (!(provider instanceof ChunkProviderServer)) { return false; } BlockFalling.fallInstantly = true; try { ChunkProviderServer chunkServer = (ChunkProviderServer) provider; IChunkGenerator gen = chunkServer.chunkGenerator; long pos = ChunkPos.asLong(x, z); Chunk mcChunk; if (chunkServer.chunkExists(x, z)) { mcChunk = chunkServer.loadChunk(x, z); mcChunk.onChunkUnload(); } PlayerChunkMap playerManager = ((WorldServer) getWorld()).getPlayerChunkMap(); List<EntityPlayerMP> oldWatchers = null; if (chunkServer.chunkExists(x, z)) { mcChunk = chunkServer.loadChunk(x, z); PlayerChunkMapEntry entry = playerManager.getEntry(x, z); if (entry != null) { Field fieldPlayers = PlayerChunkMapEntry.class.getDeclaredField("field_187283_c"); fieldPlayers.setAccessible(true); oldWatchers = (List<EntityPlayerMP>) fieldPlayers.get(entry); playerManager.removeEntry(entry); } mcChunk.onChunkUnload(); } try { Field droppedChunksSetField = chunkServer.getClass().getDeclaredField("field_73248_b"); droppedChunksSetField.setAccessible(true); Set droppedChunksSet = (Set) droppedChunksSetField.get(chunkServer); droppedChunksSet.remove(pos); } catch (Throwable e) { MainUtil.handleError(e); } chunkServer.id2ChunkMap.remove(pos); mcChunk = gen.provideChunk(x, z); chunkServer.id2ChunkMap.put(pos, mcChunk); if (mcChunk != null) { mcChunk.onChunkLoad(); mcChunk.populateChunk(chunkServer, chunkServer.chunkGenerator); } if (oldWatchers != null) { for (EntityPlayerMP player : oldWatchers) { playerManager.addPlayer(player); } } return true; } catch (Throwable t) { MainUtil.handleError(t); return false; } finally { BlockFalling.fallInstantly = false; } }
Example 12
Source File: TeleporterPaths.java From TFC2 with GNU General Public License v3.0 | 4 votes |
@Override public boolean placeInExistingPortal(Entity entityIn, float rotationYaw) { boolean flag = true; int playerX = MathHelper.floor(entityIn.posX); int playerZ = MathHelper.floor(entityIn.posZ); boolean shouldAddPortalPosition = true; boolean foundPortal = false; BlockPos object = new BlockPos(entityIn); long k = ChunkPos.asLong(playerX, playerZ); IslandMap islandMap = Core.getMapForWorld(worldServerInstance, entityIn.getPosition()); Center closest = islandMap.getClosestCenter(new Point((playerX*8) % 4096,(playerZ*8) % 4096)); //Check if we already have a portal position cached here if (this.destinationCoordinateCache.containsKey(k)) { Teleporter.PortalPosition portalposition = (Teleporter.PortalPosition)this.destinationCoordinateCache.get(k); object = portalposition; portalposition.lastUpdateTime = this.worldServerInstance.getTotalWorldTime(); shouldAddPortalPosition = false; } else //If not then we do a simple search for the closest portal block { object = this.findPortal(new BlockPos(entityIn)); } //If we found a portal location then we need to move the player to it if (object != null) { if (shouldAddPortalPosition) { this.destinationCoordinateCache.put(k, new Teleporter.PortalPosition((BlockPos)object, this.worldServerInstance.getTotalWorldTime())); //this.destinationCoordinateKeys.add(Long.valueOf(k)); } EnumFacing enumfacing = null; BlockPos pos = object; PortalAttribute attr = (PortalAttribute) closest.getAttribute(Attribute.Portal); if(this.checkRoomForPlayer(pos.north())) pos = pos.north(); else if(this.checkRoomForPlayer(pos.south())) pos = pos.south(); else if(this.checkRoomForPlayer(pos.east())) pos = pos.east(); else if(this.checkRoomForPlayer(pos.west())) pos = pos.west(); entityIn.setLocationAndAngles(pos.getX()+0.5, pos.getY()+0.5, pos.getZ()+0.5, rotationYaw, entityIn.rotationPitch); return true; } else { return false; } }