net.minecraftforge.common.ForgeChunkManager Java Examples
The following examples show how to use
net.minecraftforge.common.ForgeChunkManager.
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: ChunkLoading.java From enderutilities with GNU Lesser General Public License v3.0 | 6 votes |
public boolean loadChunkForcedWithTicket(Ticket ticket, int dimension, int chunkX, int chunkZ, int unloadDelay) { if (ticket == null) { EnderUtilities.logger.warn("loadChunkForcedWithTicket(): ticket == null"); return false; } ForgeChunkManager.forceChunk(ticket, new ChunkPos(chunkX, chunkZ)); if (unloadDelay > 0) { //System.out.println("loadChunkForcedWithTicket() adding timeout: " + unloadDelay); this.addChunkTimeout(ticket, dimension, chunkX, chunkZ, unloadDelay); } return this.loadChunkWithoutForce(dimension, chunkX, chunkZ); }
Example #2
Source File: ChunkLoading.java From enderutilities with GNU Lesser General Public License v3.0 | 6 votes |
@Override public void ticketsLoaded(List<Ticket> tickets, World world) { for (Ticket ticket : tickets) { //System.out.println("void ticketsLoaded(): looping tickets"); if (ticket != null) { for (ChunkPos chunk : ticket.getChunkList()) { //System.out.println("void ticketsLoaded(): forcing chunk: " + chunk + " in dimension: " + ticket.world.provider.getDimensionId()); ForgeChunkManager.forceChunk(ticket, chunk); } } } }
Example #3
Source File: TicketMap.java From MyTown2 with The Unlicense | 6 votes |
@Override public ForgeChunkManager.Ticket get(Object key) { if (key instanceof Integer) { if (super.get(key) == null) { World world = DimensionManager.getWorld((Integer) key); if (world == null) { return null; } ForgeChunkManager.Ticket ticket = ForgeChunkManager.requestTicket(MyTown.instance, world, ForgeChunkManager.Type.NORMAL); ticket.getModData().setString("townName", town.getName()); ticket.getModData().setTag("chunkCoords", new NBTTagList()); put((Integer) key, ticket); return ticket; } else { return super.get(key); } } return null; }
Example #4
Source File: TicketMap.java From MyTown2 with The Unlicense | 6 votes |
public void chunkUnload(TownBlock block) { ForgeChunkManager.Ticket ticket = get(block.getDim()); ForgeChunkManager.unforceChunk(ticket, block.toChunkCoords()); NBTTagList list = ticket.getModData().getTagList("chunkCoords", Constants.NBT.TAG_COMPOUND); for (int i = 0; i < list.tagCount(); i++) { NBTTagCompound chunkNBT = list.getCompoundTagAt(i); int x = chunkNBT.getInteger("x"); int z = chunkNBT.getInteger("z"); if (x == block.getX() && z == block.getZ()) { list.removeTag(i); break; } } }
Example #5
Source File: ChunkLoaderManager.java From ChickenChunks with MIT License | 6 votes |
protected void addChunk(DimChunkCoord coord) { if (heldChunks.containsKey(coord)) return; Stack<Ticket> freeTickets = ticketsWithSpace.get(coord.dimension); if (freeTickets == null) ticketsWithSpace.put(coord.dimension, freeTickets = new Stack<Ticket>()); Ticket ticket; if (freeTickets.isEmpty()) freeTickets.push(ticket = createTicket(coord.dimension)); else ticket = freeTickets.peek(); ForgeChunkManager.forceChunk(ticket, coord.getChunkCoord()); heldChunks.put(coord, ticket); if (ticket.getChunkList().size() == ticket.getChunkListDepth() && !freeTickets.isEmpty()) freeTickets.pop(); }
Example #6
Source File: PlayerChunkViewerTracker.java From ChickenChunks with MIT License | 6 votes |
@SuppressWarnings("unchecked") public void loadDimension(WorldServer world) { PacketCustom packet = new PacketCustom(channel, 2).compress(); int dim = CommonUtils.getDimension(world); packet.writeInt(dim); List<Chunk> allchunks = world.theChunkProviderServer.loadedChunks; packet.writeInt(allchunks.size()); for(Chunk chunk : allchunks) { packet.writeInt(chunk.xPosition); packet.writeInt(chunk.zPosition); } Map<Ticket, Collection<ChunkCoordIntPair>> tickets = ForgeChunkManager.getPersistentChunksFor(world).inverse().asMap(); packet.writeInt(tickets.size()); for(Entry<Ticket, Collection<ChunkCoordIntPair>> entry : tickets.entrySet()) writeTicketToPacket(packet, entry.getKey(), entry.getValue()); packet.sendToPlayer(owner); }
Example #7
Source File: SatelliteLaser.java From AdvancedRocketry with MIT License | 5 votes |
public void deactivateLaser() { if(laser != null) { laser.setDead(); laser = null; } if(ticketLaser != null) ForgeChunkManager.releaseTicket(ticketLaser); finished = false; }
Example #8
Source File: CommonProxy.java From enderutilities with GNU Lesser General Public License v3.0 | 5 votes |
public void registerEventHandlers() { MinecraftForge.EVENT_BUS.register(new AnvilUpdateEventHandler()); MinecraftForge.EVENT_BUS.register(new BlockEventHandler()); MinecraftForge.EVENT_BUS.register(new EntityEventHandler()); MinecraftForge.EVENT_BUS.register(new ItemPickupEventHandler()); MinecraftForge.EVENT_BUS.register(new LivingDropsEventHandler()); MinecraftForge.EVENT_BUS.register(new PlayerEventHandler()); MinecraftForge.EVENT_BUS.register(new WorldEventHandler()); MinecraftForge.EVENT_BUS.register(new TickHandler()); MinecraftForge.EVENT_BUS.register(this); ForgeChunkManager.setForcedChunkLoadingCallback(EnderUtilities.instance, new ChunkLoading()); }
Example #9
Source File: ChunkLoaderManager.java From ChickenChunks with MIT License | 5 votes |
/** * By doing this you are delegating all chunks from your mod to be handled by yours truly. */ public static void registerMod(Object mod) { ModContainer container = Loader.instance().getModObjectList().inverse().get(mod); if (container == null) throw new NullPointerException("Mod container not found for: " + mod); mods.put(mod, container); ForgeChunkManager.setForcedChunkLoadingCallback(mod, new DummyLoadingCallback()); }
Example #10
Source File: ChunkLoading.java From enderutilities with GNU Lesser General Public License v3.0 | 5 votes |
public void tickChunkTimeouts() { DimChunkCoordTimeout dcct; Iterator<Map.Entry<String, DimChunkCoordTimeout>> iterator = this.timeOuts.entrySet().iterator(); //int j = 0; // FIXME debug while (iterator.hasNext()) { dcct = iterator.next().getValue(); //System.out.printf("tickChunkTimeouts(): loop %d, timeout: %d\n", j++, dcct.timeout); if (dcct != null && (this.playerTickets.containsValue(dcct.ticket) || this.modTickets.containsValue(dcct.ticket))) { if (dcct.tick() == 0) { //System.out.printf("tickChunkTimeouts(): unforcing, dim: %d, %s\n", dcct.dimension, dcct.chunkCoords.toString()); ForgeChunkManager.unforceChunk(dcct.ticket, dcct.chunkCoords); if (dcct.ticket != null && dcct.ticket.getChunkList().size() == 0) { this.removeTicket(dcct.ticket); ForgeChunkManager.releaseTicket(dcct.ticket); } iterator.remove(); } } // If this chunk doesn't have a valid ticket anymore, just remove the entry else { //System.out.println("tickChunkTimeouts(): invalid ticket, removing timeout entry"); iterator.remove(); } } }
Example #11
Source File: MyTownDatasource.java From MyTown2 with The Unlicense | 5 votes |
protected boolean loadTowns() { try { PreparedStatement loadTownsStatement = prepare("SELECT * FROM " + prefix + "Towns", true); ResultSet rs = loadTownsStatement.executeQuery(); while (rs.next()) { Town town; if (rs.getBoolean("isAdminTown")) { town = new AdminTown(rs.getString("name")); } else { town = new Town(rs.getString("name")); } town.setSpawn(new Teleport(rs.getInt("spawnDim"), rs.getFloat("spawnX"), rs.getFloat("spawnY"), rs.getFloat("spawnZ"), rs.getFloat("cameraYaw"), rs.getFloat("cameraPitch"))); town.townBlocksContainer.setExtraBlocks(rs.getInt("extraBlocks")); town.townBlocksContainer.setExtraFarClaims(rs.getInt("extraFarClaims")); town.plotsContainer.setMaxPlots(rs.getInt("maxPlots")); for (ForgeChunkManager.Ticket ticket : MyTownLoadingCallback.tickets) { if (ticket.getModData().getString("townName").equals(town.getName())) { town.ticketMap.put(ticket.world.provider.dimensionId, ticket); } } MyTownUniverse.instance.addTown(town); } } catch (SQLException e) { LOG.error("Failed to load Towns!"); LOG.error(ExceptionUtils.getStackTrace(e)); return false; } return true; }
Example #12
Source File: BaseVehicleEntity.java From CommunityMod with GNU Lesser General Public License v2.1 | 5 votes |
public BaseVehicleEntity(World worldIn) { super(worldIn); storage = new ShipStorage(getOffset(), worldIn); Ticket tic = ForgeChunkManager.requestTicket(CommunityMod.INSTANCE, DimensionManager.getWorld(StorageDimReg.storageDimensionType.getId()), Type.NORMAL); loadTicket = tic; }
Example #13
Source File: ChunkLoaderManager.java From ChickenChunks with MIT License | 5 votes |
protected void remChunk(DimChunkCoord coord) { Ticket ticket = heldChunks.remove(coord); if (ticket == null) return; ForgeChunkManager.unforceChunk(ticket, coord.getChunkCoord()); if (ticket.getChunkList().size() == ticket.getChunkListDepth() - 1) { Stack<Ticket> freeTickets = ticketsWithSpace.get(coord.dimension); if (freeTickets == null) ticketsWithSpace.put(coord.dimension, freeTickets = new Stack<Ticket>()); freeTickets.push(ticket); } }
Example #14
Source File: SatelliteLaser.java From AdvancedRocketry with MIT License | 5 votes |
/** * creates the laser and begins mining. This can * fail if the chunk cannot be force loaded * @param world world to spawn the laser into * @param x x coord * @param z z coord * @return whether creating the laser is successful */ public boolean activateLaser(World world, int x, int z) { ticketLaser = ForgeChunkManager.requestTicket(AdvancedRocketry.instance, world, Type.NORMAL); if(ticketLaser != null) { ForgeChunkManager.forceChunk(ticketLaser, new ChunkPos(x >> 4, z >> 4)); int y = 64; if(world.getChunkFromChunkCoords(x >> 4, z >> 4).isLoaded()) { int current = 0; for(int i = 0; i < 9; i++) { current = world.getTopSolidOrLiquidBlock(new BlockPos(x + (i % 3) - 1, 0xFF, z + (i / 3) - 1)).getY(); if(current > y) y = current; } if(y < 1) y = 255; } else y = 255; laser = new EntityLaserNode(world, x, y, z); laser.forceSpawn = true; world.spawnEntity(laser); return true; } return false; }
Example #15
Source File: TileSpaceLaser.java From AdvancedRocketry with MIT License | 5 votes |
/** * Checks to see if the situation for firing the laser exists... and changes the state accordingly */ public void checkCanRun() { //Laser requires lense, redstone power, not be jammed, and be in orbit and energy to function if(world.isBlockIndirectlyGettingPowered(getPos()) == 0 || !isAllowedToRun()) { if(laserSat.isAlive()) { laserSat.deactivateLaser(); } setRunning(false); } else if(!laserSat.isAlive() && !finished && !laserSat.getJammed() && world.isBlockIndirectlyGettingPowered(getPos()) > 0 && canMachineSeeEarth()) { //Laser will be on at this point int orbitDimId = ((WorldProviderSpace)this.world.provider).getDimensionProperties(getPos()).getParentPlanet(); if(orbitDimId == SpaceObjectManager.WARPDIMID) return; WorldServer orbitWorld = DimensionManager.getWorld(orbitDimId); if(orbitWorld == null) { DimensionManager.initDimension(orbitDimId); orbitWorld = DimensionManager.getWorld(orbitDimId); if(orbitWorld == null) return; } if(ticket == null) { ticket = ForgeChunkManager.requestTicket(AdvancedRocketry.instance, this.world, Type.NORMAL); if(ticket != null) ForgeChunkManager.forceChunk(ticket, new ChunkPos(getPos().getX() / 16 - (getPos().getX() < 0 ? 1 : 0), getPos().getZ() / 16 - (getPos().getZ() < 0 ? 1 : 0))); } setRunning(laserSat.activateLaser(orbitWorld, laserX, laserZ)); } if(!this.world.isRemote) PacketHandler.sendToNearby(new PacketMachine(this, (byte)12), 128, pos, this.world.provider.getDimension()); }
Example #16
Source File: TicketMap.java From MyTown2 with The Unlicense | 5 votes |
public void chunkLoad(TownBlock block) { ForgeChunkManager.Ticket ticket = get(block.getDim()); NBTTagList list = ticket.getModData().getTagList("chunkCoords", Constants.NBT.TAG_COMPOUND); list.appendTag(block.toChunkPos().toNBTTagCompound()); ForgeChunkManager.forceChunk(ticket, block.toChunkCoords()); }
Example #17
Source File: TileRailgun.java From AdvancedRocketry with MIT License | 5 votes |
@Override public void onLoad() { if(ticket == null) { ticket = ForgeChunkManager.requestTicket(AdvancedRocketry.instance, this.world, Type.NORMAL); if(ticket != null) ForgeChunkManager.forceChunk(ticket, new ChunkPos(getPos().getX() / 16 - (getPos().getX() < 0 ? 1 : 0), getPos().getZ() / 16 - (getPos().getZ() < 0 ? 1 : 0))); } }
Example #18
Source File: TicketMap.java From MyTown2 with The Unlicense | 5 votes |
public int getChunkloadedAmount() { int size = 0; for (ForgeChunkManager.Ticket ticket : values()) { size += ticket.getChunkList().size(); } return size; }
Example #19
Source File: ChunkLoadManager.java From Signals with GNU General Public License v3.0 | 5 votes |
public boolean update(){ if(ticket.getEntity() == null || ticket.getEntity().isDead) { Log.warning("No or dead cart for chunkloading ticket found! Disposing..."); dispose(); return true; } ChunkPos newPos = new ChunkPos(ticket.getEntity().chunkCoordX, ticket.getEntity().chunkCoordZ); if(!newPos.equals(curPos)) { // When the cart changed from chunk //Select a 3x3 area centered around the cart. Set<ChunkPos> newForced = new HashSet<>(); for(int x = newPos.x - 1; x <= newPos.x + 1; x++) { for(int z = newPos.z - 1; z <= newPos.z + 1; z++) { newForced.add(new ChunkPos(x, z)); } } //Unforce chunks we don't need anymore curForced.stream().filter(pos -> !newForced.contains(pos)).forEach(pos -> { ForgeChunkManager.unforceChunk(ticket, pos); }); //Force new chunks newForced.stream().filter(pos -> !curForced.contains(pos)).forEach(pos -> { ForgeChunkManager.forceChunk(ticket, pos); }); curForced = newForced; } return false; }
Example #20
Source File: ChunkLoadManager.java From Signals with GNU General Public License v3.0 | 5 votes |
public boolean markAsChunkLoader(String chunkloadingPlayer, EntityMinecart cart){ Ticket ticket = ForgeChunkManager.requestPlayerTicket(Signals.instance, chunkloadingPlayer, cart.world, Type.ENTITY); if(ticket != null) { ticket.bindEntity(cart); add(ticket); return true; } else { return false; } }
Example #21
Source File: BlockyEntities.java From CommunityMod with GNU Lesser General Public License v2.1 | 5 votes |
@Override public void onPreInit(FMLPreInitializationEvent event) { PacketHandler.registerMessages("hyperstellar"); EntityRegistry.registerModEntity(new ResourceLocation(CommunityGlobals.MOD_ID, "BaseVehicle"), BaseVehicleEntity.class, "BaseVehicle", 45, CommunityMod.INSTANCE, 64, 3, true); if (!ForgeChunkManager.getConfig().hasCategory(CommunityGlobals.MOD_ID)) { ForgeChunkManager.getConfig().get(CommunityGlobals.MOD_ID, "maximumChunksPerTicket", MaxRocketSize / 16) .setMinValue(0); ForgeChunkManager.getConfig().get(CommunityGlobals.MOD_ID, "maximumTicketCount", 10000).setMinValue(0); ForgeChunkManager.getConfig().save(); } HDataSerializers.register(); }
Example #22
Source File: MyTownLoadingCallback.java From MyTown2 with The Unlicense | 5 votes |
@Override public void ticketsLoaded(List<ForgeChunkManager.Ticket> tickets, World world) { for (ForgeChunkManager.Ticket ticket : tickets) { NBTTagList list = ticket.getModData().getTagList("chunkCoords", Constants.NBT.TAG_COMPOUND); for (int i = 0; i < list.tagCount(); i++) { NBTTagCompound chunkNBT = list.getCompoundTagAt(i); ForgeChunkManager.forceChunk(ticket, new ChunkCoordIntPair(chunkNBT.getInteger("x"), chunkNBT.getInteger("z"))); } } MyTownLoadingCallback.tickets.addAll(tickets); }
Example #23
Source File: ChunkLoaderManager.java From ChickenChunks with MIT License | 4 votes |
public boolean canForceNewChunks(int required, int dim) { return required + numLoadedChunks() < getPlayerChunkLimit(username) && required < ForgeChunkManager.ticketCountAvailableFor(username) * ForgeChunkManager.getMaxChunkDepthFor("ChickenChunks"); }
Example #24
Source File: TicketMap.java From MyTown2 with The Unlicense | 4 votes |
public void releaseTickets() { for (ForgeChunkManager.Ticket ticket : values()) { ForgeChunkManager.releaseTicket(ticket); } }
Example #25
Source File: MyTown.java From MyTown2 with The Unlicense | 4 votes |
/** * Registers all handlers (Event handlers) */ private void registerHandlers() { FMLCommonHandler.instance().bus().register(new SafemodeHandler()); Ticker playerTracker = new Ticker(); FMLCommonHandler.instance().bus().register(playerTracker); MinecraftForge.EVENT_BUS.register(playerTracker); FMLCommonHandler.instance().bus().register(VisualsHandler.instance); FMLCommonHandler.instance().bus().register(ProtectionHandlers.instance); MinecraftForge.EVENT_BUS.register(ProtectionHandlers.instance); MinecraftForge.EVENT_BUS.register(ExtraEventsHandler.getInstance()); ForgeChunkManager.setForcedChunkLoadingCallback(this, new MyTownLoadingCallback()); }
Example #26
Source File: ChunkLoaderManager.java From ChickenChunks with MIT License | 4 votes |
@Override protected Ticket createTicket(int dimension) { return ForgeChunkManager.requestTicket(mod, DimensionManager.getWorld(dimension), Type.NORMAL); }
Example #27
Source File: ChunkLoaderManager.java From ChickenChunks with MIT License | 4 votes |
@Override public boolean canForceNewChunks(int required, int dim) { return required < ForgeChunkManager.ticketCountAvailableFor(mod, DimensionManager.getWorld(dim)) * ForgeChunkManager.getMaxChunkDepthFor(container.getModId()); }
Example #28
Source File: ChunkLoaderManager.java From ChickenChunks with MIT License | 4 votes |
@Override public Ticket createTicket(int dimension) { return ForgeChunkManager.requestPlayerTicket(ChickenChunks.instance, username, DimensionManager.getWorld(dimension), Type.NORMAL); }
Example #29
Source File: TileSpaceLaser.java From AdvancedRocketry with MIT License | 4 votes |
public void onDestroy() { if(laserSat != null) { laserSat.deactivateLaser(); } ForgeChunkManager.releaseTicket(ticket); }
Example #30
Source File: TileRailgun.java From AdvancedRocketry with MIT License | 4 votes |
@Override public void invalidate() { super.invalidate(); ForgeChunkManager.releaseTicket(ticket); }