Java Code Examples for net.minecraftforge.common.ForgeChunkManager#Ticket

The following examples show how to use net.minecraftforge.common.ForgeChunkManager#Ticket . 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: TicketMap.java    From MyTown2 with The Unlicense 6 votes vote down vote up
@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 2
Source File: TicketMap.java    From MyTown2 with The Unlicense 6 votes vote down vote up
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 3
Source File: MyTownDatasource.java    From MyTown2 with The Unlicense 5 votes vote down vote up
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 4
Source File: TicketMap.java    From MyTown2 with The Unlicense 5 votes vote down vote up
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 5
Source File: TicketMap.java    From MyTown2 with The Unlicense 5 votes vote down vote up
public int getChunkloadedAmount() {
    int size = 0;
    for (ForgeChunkManager.Ticket ticket : values()) {
        size += ticket.getChunkList().size();
    }
    return size;
}
 
Example 6
Source File: MyTownLoadingCallback.java    From MyTown2 with The Unlicense 5 votes vote down vote up
@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 7
Source File: TicketMap.java    From MyTown2 with The Unlicense 4 votes vote down vote up
public void releaseTickets() {
    for (ForgeChunkManager.Ticket ticket : values()) {
        ForgeChunkManager.releaseTicket(ticket);
    }
}