codechicken.core.CommonUtils Java Examples
The following examples show how to use
codechicken.core.CommonUtils.
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: 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 #2
Source File: ChunkLoaderManager.java From ChickenChunks with MIT License | 6 votes |
public void addChunkLoader(IChickenChunkLoader loader) { if (reviving) return; int dim = CommonUtils.getDimension(loader.getWorld()); if (dormant) { HashSet<BlockCoord> coords = dormantLoaders.get(dim); if (coords == null) dormantLoaders.put(dim, coords = new HashSet<BlockCoord>()); coords.add(loader.getPosition()); } else { forcedChunksByLoader.put(loader, new HashSet<ChunkCoordIntPair>()); forceChunks(loader, dim, loader.getChunks()); } setDirty(); }
Example #3
Source File: WRAddonProxy.java From WirelessRedstone with MIT License | 6 votes |
public void init() { WRCoreSPH.delegates.add(new WRAddonSPH()); FMLCommonHandler.instance().bus().register(new WRAddonEventHandler()); triangulator = register(new ItemWirelessTriangulator(), "triangulator"); remote = register(new ItemWirelessRemote(), "remote"); sniffer = register(new ItemWirelessSniffer(), "sniffer"); emptyWirelessMap = register(new ItemEmptyWirelessMap(), "empty_map"); wirelessMap = register(new ItemWirelessMap(), "map"); tracker = register(new ItemWirelessTracker(), "tracker"); rep = register(new ItemREP(), "rep"); psniffer = register(new ItemPrivateSniffer(), "psniffer"); CommonUtils.registerHandledEntity(EntityWirelessTracker.class, "WRTracker"); addRecipes(); }
Example #4
Source File: ChunkLoaderManager.java From ChickenChunks with MIT License | 6 votes |
public void updateChunkLoader(IChickenChunkLoader loader) { HashSet<ChunkCoordIntPair> loaderChunks = forcedChunksByLoader.get(loader); if (loaderChunks == null) { addChunkLoader(loader); return; } HashSet<ChunkCoordIntPair> oldChunks = new HashSet<ChunkCoordIntPair>(loaderChunks); HashSet<ChunkCoordIntPair> newChunks = new HashSet<ChunkCoordIntPair>(); for (ChunkCoordIntPair chunk : loader.getChunks()) if (!oldChunks.remove(chunk)) newChunks.add(chunk); int dim = CommonUtils.getDimension(loader.getWorld()); if (!oldChunks.isEmpty()) unforceChunks(loader, dim, oldChunks, false); if (!newChunks.isEmpty()) forceChunks(loader, dim, newChunks); }
Example #5
Source File: RedstoneEtherServer.java From WirelessRedstone with MIT License | 6 votes |
public void setTransmitter(World world, int x, int y, int z, int freq, boolean on) { if(freq == 0) { return; } BlockCoord node = new BlockCoord(x, y, z); int dimension = CommonUtils.getDimension(world); if(isNodeInAOEofJammer(node, dimension)) { jamNodeSometime(world, node, dimension, freq); } TXNodeInfo info = ethers.get(dimension).transmittingblocks.get(node); if(info == null) ethers.get(dimension).transmittingblocks.put(node, new TXNodeInfo(freq, on)); else info.on = on; freqarray[freq].setTransmitter(world, node, dimension, on); }
Example #6
Source File: ChunkLoaderManager.java From ChickenChunks with MIT License | 6 votes |
public void revive(World world) { HashSet<BlockCoord> coords = dormantLoaders.get(CommonUtils.getDimension(world)); if (coords == null) return; //addChunkLoader will add to the coord set if we are dormant ArrayList<BlockCoord> verifyCoords = new ArrayList<BlockCoord>(coords); coords.clear(); for (BlockCoord coord : verifyCoords) { reviving = true; TileEntity tile = world.getTileEntity(coord.x, coord.y, coord.z); reviving = false; if (tile instanceof IChickenChunkLoader) { ChunkLoaderManager.addChunkLoader((IChickenChunkLoader) tile); } } }
Example #7
Source File: RedstoneEtherServer.java From WirelessRedstone with MIT License | 6 votes |
public void verifyChunkTransmitters(World world, int chunkx, int chunkz) { int dimension = CommonUtils.getDimension(world); DimensionalEtherHash ether = ethers.get(dimension); int blockxmin = chunkx * 16; int blockxmax = blockxmin + 15; int blockzmin = chunkz * 16; int blockzmax = blockzmin + 15; ArrayList<BlockCoord> transmittingblocks = new ArrayList<BlockCoord>(ether.transmittingblocks.keySet()); for(BlockCoord node : transmittingblocks) { if(node.x >= blockxmin && node.x <= blockxmax && node.z >= blockzmin && node.z <= blockzmax) { TileEntity tile = RedstoneEther.getTile(world, node); int freq = ether.transmittingblocks.get(node).freq; if(tile == null || !(tile instanceof ITileWireless) || ((ITileWireless)tile).getFreq() != freq) { remTransmitter(world, node.x, node.y, node.z, freq); System.out.println("Removed Badly Synced node at:"+node.x+","+node.y+","+node.z+" on "+freq+" in dim"+dimension); } } } }
Example #8
Source File: WirelessBolt.java From WirelessRedstone with MIT License | 6 votes |
private void jamTile() { if (world.isRemote || target == null) return; RedstoneEtherServer ether = (RedstoneEtherServer) this.ether; if (canhittarget) { TileEntity tile = RedstoneEther.getTile(world, target); if (tile == null || !(tile instanceof ITileWireless)) { ether.unjamTile(world, target.x, target.y, target.z); return; } ITileWireless wirelesstile = (ITileWireless) tile; int freq = wirelesstile.getFreq(); if (freq == 0) { ether.unjamTile(world, target.x, target.y, target.z); return; } ether.jamNode(world, target, CommonUtils.getDimension(world), freq); wirelesstile.jamTile(); } else { ether.unjamTile(world, target.x, target.y, target.z); } }
Example #9
Source File: RedstoneEtherServer.java From WirelessRedstone with MIT License | 6 votes |
private void entityJamTest(World world) { if(world.getTotalWorldTime() % 10 != 0) return; int dimension = CommonUtils.getDimension(world); for(Iterator<BlockCoord> iterator = ethers.get(dimension).jammerset.iterator(); iterator.hasNext();) { BlockCoord jammer = iterator.next(); List<Entity> entitiesinrange = world.getEntitiesWithinAABBExcludingEntity(null, AxisAlignedBB.getBoundingBox(jammer.x-9.5, jammer.y-9.5, jammer.z-9.5, jammer.x+10.5, jammer.y+10.5, jammer.z+10.5)); for(Iterator<Entity> iterator2 = entitiesinrange.iterator(); iterator2.hasNext();) { Entity entity = iterator2.next(); if(!(entity instanceof EntityLivingBase)) continue; if(entity instanceof EntityPlayer) if(isPlayerJammed((EntityPlayer)entity)) continue; jamEntitySometime((EntityLivingBase) entity); } } }
Example #10
Source File: RedstoneEtherServer.java From WirelessRedstone with MIT License | 5 votes |
public void saveEther(World world) { int dimension = CommonUtils.getDimension(world); if(!ethers.containsKey(dimension)) return; for(RedstoneEtherFrequency freq : ethers.get(dimension).freqsToSave) freq.saveFreq(dimension); ethers.get(dimension).freqsToSave.clear(); SaveManager.getInstance(dimension).removeTrailingSectors(); SaveManager.saveDimensionHash(); }
Example #11
Source File: RedstoneEtherServer.java From WirelessRedstone with MIT License | 5 votes |
public void unjamTile(World world, int x, int y, int z) { BlockCoord node = new BlockCoord(x, y, z); int dimension = CommonUtils.getDimension(world); Integer timeout = ethers.get(dimension).jammednodes.remove(node); if(timeout != null && timeout >= 0)//tile was jammed { ITileWireless tile = (ITileWireless) getTile(world, node); tile.unjamTile(); } }
Example #12
Source File: RedstoneEtherServer.java From WirelessRedstone with MIT License | 5 votes |
public void jamNode(World world, int x, int y, int z, int freq) { if(freq == 0) return; jamNode(world, new BlockCoord(x, y, z), CommonUtils.getDimension(world), freq); }
Example #13
Source File: RedstoneEther.java From WirelessRedstone with MIT License | 5 votes |
public static void loadServerWorld(World world) { int dimension = CommonUtils.getDimension(world); if (serverEther == null) new RedstoneEtherServer().init(world); serverEther.addEther(world, dimension); }
Example #14
Source File: RedstoneEtherServer.java From WirelessRedstone with MIT License | 5 votes |
public void addJammer(World world, int x, int y, int z) { int dimension = CommonUtils.getDimension(world); BlockCoord jammer = new BlockCoord(x, y, z); ethers.get(dimension).jammerset.add(jammer); jamNodesInAOEOfJammer(world, jammer, dimension); }
Example #15
Source File: RedstoneEtherServer.java From WirelessRedstone with MIT License | 5 votes |
public void remReceiver(World world, int x, int y, int z, int freq) { if(freq == 0) return; int dimension = CommonUtils.getDimension(world); BlockCoord node = new BlockCoord(x, y, z); ethers.get(dimension).jammednodes.remove(node); ethers.get(dimension).recievingblocks.remove(node); freqarray[freq].remReceiver(world, node, dimension); }
Example #16
Source File: RedstoneEtherServer.java From WirelessRedstone with MIT License | 5 votes |
private void updateJammedNodes(World world) { int dimension = CommonUtils.getDimension(world); for(Iterator<BlockCoord> iterator = ethers.get(dimension).jammednodes.keySet().iterator(); iterator.hasNext();) { BlockCoord node = iterator.next(); int inactivetime = ethers.get(dimension).jammednodes.get(node); inactivetime--; if(inactivetime == 0 || inactivetime < 0 && inactivetime%jammerrandom == 0) { ITileWireless tile = (ITileWireless) getTile(world, node); if(tile == null) { iterator.remove(); continue; } BlockCoord jammer = getClosestJammer(node, dimension); ITileJammer jammertile = jammer == null ? null : (ITileJammer)getTile(world, jammer); if(jammertile == null) { iterator.remove(); tile.unjamTile(); continue; } jammertile.jamTile(tile); } if(inactivetime == 0)//so the node doesn't think it's unjammed inactivetime = jammertimeout; ethers.get(dimension).jammednodes.put(node, inactivetime); } }
Example #17
Source File: RedstoneEtherServer.java From WirelessRedstone with MIT License | 5 votes |
public void remTransmitter(World world, int x, int y, int z, int freq) { if(freq == 0) { return; } int dimension = CommonUtils.getDimension(world); BlockCoord node = new BlockCoord(x, y, z); ethers.get(dimension).jammednodes.remove(node); ethers.get(dimension).transmittingblocks.remove(node); freqarray[freq].remTransmitter(world, node, dimension); }
Example #18
Source File: RedstoneEtherServer.java From WirelessRedstone with MIT License | 5 votes |
public void addReceiver(World world, int x, int y, int z, int freq) { if(freq == 0) return; BlockCoord node = new BlockCoord(x, y, z); int dimension = CommonUtils.getDimension(world); if(isNodeInAOEofJammer(node, dimension)) { jamNodeSometime(world, node, dimension, freq); } ethers.get(dimension).recievingblocks.put(node, freq); freqarray[freq].addReceiver(world, node, dimension); }
Example #19
Source File: NEIModContainer.java From NotEnoughItems with MIT License | 5 votes |
@Subscribe public void init(FMLInitializationEvent event) { if (CommonUtils.isClient()) ClientHandler.init(); ServerHandler.init(); }
Example #20
Source File: DataDumper.java From NotEnoughItems with MIT License | 5 votes |
public void dumpFile() { try { File file = new File(CommonUtils.getMinecraftDir(), "dumps/" + getFileName(name.replaceFirst(".+\\.", ""))); if (!file.getParentFile().exists()) file.getParentFile().mkdirs(); if (!file.exists()) file.createNewFile(); dumpTo(file); NEIClientUtils.printChatMessage(dumpMessage(file)); } catch (Exception e) { NEIClientConfig.logger.error("Error dumping " + renderName() + " mode: " + getMode(), e); } }
Example #21
Source File: PlayerChunkViewerManager.java From ChickenChunks with MIT License | 5 votes |
@SuppressWarnings("unchecked") private void updateChunkChangeMap() { for(WorldServer world : DimensionManager.getWorlds()) { HashSet<ChunkCoordIntPair> allChunks = new HashSet<ChunkCoordIntPair>(); ArrayList<Chunk> loadedChunkCopy = new ArrayList<Chunk>(world.theChunkProviderServer.loadedChunks); for(Chunk chunk : loadedChunkCopy) allChunks.add(chunk.getChunkCoordIntPair()); lastLoadedChunkMap.put(CommonUtils.getDimension(world), allChunks); } }
Example #22
Source File: PlayerChunkViewerManager.java From ChickenChunks with MIT License | 5 votes |
public TicketChange(Ticket ticket, ChunkCoordIntPair chunk, boolean force) { this.ticket = ticket; this.dimension = CommonUtils.getDimension(ticket.world); this.chunk = chunk; this.force = force; }
Example #23
Source File: ChunkLoaderManager.java From ChickenChunks with MIT License | 5 votes |
@SuppressWarnings("unchecked") public static void cleanChunks(WorldServer world) { int dim = CommonUtils.getDimension(world); int viewdist = ServerUtils.mc().getConfigurationManager().getViewDistance(); HashSet<ChunkCoordIntPair> loadedChunks = new HashSet<ChunkCoordIntPair>(); for (EntityPlayer player : ServerUtils.getPlayersInDimension(dim)) { int playerChunkX = (int) player.posX >> 4; int playerChunkZ = (int) player.posZ >> 4; for (int cx = playerChunkX - viewdist; cx <= playerChunkX + viewdist; cx++) for (int cz = playerChunkZ - viewdist; cz <= playerChunkZ + viewdist; cz++) loadedChunks.add(new ChunkCoordIntPair(cx, cz)); } ImmutableSetMultimap<ChunkCoordIntPair, Ticket> persistantChunks = world.getPersistentChunks(); PlayerManager manager = world.getPlayerManager(); for (Chunk chunk : (List<Chunk>) world.theChunkProviderServer.loadedChunks) { ChunkCoordIntPair coord = chunk.getChunkCoordIntPair(); if (!loadedChunks.contains(coord) && !persistantChunks.containsKey(coord) && world.theChunkProviderServer.chunkExists(coord.chunkXPos, coord.chunkZPos)) { PlayerInstance instance = manager.getOrCreateChunkWatcher(coord.chunkXPos, coord.chunkZPos, false); if (instance == null) { world.theChunkProviderServer.unloadChunksIfNotNearSpawn(coord.chunkXPos, coord.chunkZPos); } else { while (instance.playersWatchingChunk.size() > 0) instance.removePlayer((EntityPlayerMP) instance.playersWatchingChunk.get(0)); } } } if (ServerUtils.getPlayersInDimension(dim).isEmpty() && world.getPersistentChunks().isEmpty() && !DimensionManager.shouldLoadSpawn(dim)) { DimensionManager.unloadWorld(dim); } }
Example #24
Source File: ChunkLoaderManager.java From ChickenChunks with MIT License | 5 votes |
public static boolean canLoaderAdd(IChickenChunkLoader loader, Collection<ChunkCoordIntPair> chunks) { String owner = loader.getOwner(); int dim = CommonUtils.getDimension(loader.getWorld()); if (owner != null) return getPlayerOrganiser(owner).canForceNewChunks(dim, chunks); return false; }
Example #25
Source File: ChunkLoaderManager.java From ChickenChunks with MIT License | 5 votes |
public static void addChunkLoader(IChickenChunkLoader loader) { int dim = CommonUtils.getDimension(loader.getWorld()); ChunkLoaderOrganiser organiser = getOrganiser(loader); if (organiser.canForceNewChunks(dim, loader.getChunks())) organiser.addChunkLoader(loader); else loader.deactivate(); }
Example #26
Source File: ChunkLoaderManager.java From ChickenChunks with MIT License | 5 votes |
public void devive() { if (dormant) return; for (IChickenChunkLoader loader : new ArrayList<IChickenChunkLoader>(forcedChunksByLoader.keySet())) { int dim = CommonUtils.getDimension(loader.getWorld()); HashSet<BlockCoord> coords = dormantLoaders.get(dim); if (coords == null) dormantLoaders.put(dim, coords = new HashSet<BlockCoord>()); coords.add(loader.getPosition()); remChunkLoader(loader); } dormant = true; }
Example #27
Source File: ChunkLoaderManager.java From ChickenChunks with MIT License | 5 votes |
public void remChunkLoader(IChickenChunkLoader loader) { int dim = CommonUtils.getDimension(loader.getWorld()); if (dormant) { HashSet<BlockCoord> coords = dormantLoaders.get(dim); if(coords != null) coords.remove(loader.getPosition()); } else { HashSet<ChunkCoordIntPair> chunks = forcedChunksByLoader.remove(loader); if (chunks == null) return; unforceChunks(loader, dim, chunks, true); } setDirty(); }
Example #28
Source File: EntityWirelessTracker.java From WirelessRedstone with MIT License | 4 votes |
@Override public int getDimension() { return CommonUtils.getDimension(worldObj); }
Example #29
Source File: RedstoneEtherServer.java From WirelessRedstone with MIT License | 4 votes |
public boolean isNodeJammed(World world, int x, int y, int z) { Integer timeout = ethers.get(CommonUtils.getDimension(world)).jammednodes.get(new BlockCoord(x, y, z)); return timeout != null && timeout > 0; }
Example #30
Source File: RedstoneEtherServer.java From WirelessRedstone with MIT License | 4 votes |
private void updateJammedEntities(World world) { int dimension = CommonUtils.getDimension(world); for(Iterator<EntityLivingBase> iterator = jammedentities.keySet().iterator(); iterator.hasNext();) { EntityLivingBase entity = iterator.next(); int inactivetime = jammedentities.get(entity); inactivetime--; if(entity == null || entity.isDead)//logged out or killed { iterator.remove(); continue; } if(inactivetime == 0//time for unjam or rejam || (inactivetime < 0 && inactivetime%jammerentitywait == 0)//time to jam from the sometime || (inactivetime > 0 && inactivetime%jammerentityretry == 0))//send another bolt after the retry time { BlockCoord jammer = getClosestJammer(Vector3.fromEntity(entity), dimension); ITileJammer jammertile = jammer == null ? null : (ITileJammer)getTile(world, jammer); if(jammertile == null) { if(inactivetime <= 0)//not a rejam test { iterator.remove(); jamEntity(entity, false); continue; } } else { jammertile.jamEntity(entity); } } if(inactivetime == 0)//so the node doesn't think it's unjammed { inactivetime = jammertimeout; } jammedentities.put(entity, inactivetime); } }