Search in sources :

Example 1 with DimensionDescriptor

use of mcjty.rftools.dimension.description.DimensionDescriptor in project RFTools by McJty.

the class DimensionEnscriberTileEntity method convertToDimensionDescriptor.

/**
 * Convert the dimlets in the inventory to a dimension descriptor.
 */
private DimensionDescriptor convertToDimensionDescriptor() {
    List<DimletKey> descriptors = new ArrayList<DimletKey>();
    long forcedSeed = 0;
    for (int i = 0; i < DimensionEnscriberContainer.SIZE_DIMLETS; i++) {
        ItemStack stack = inventoryHelper.getStackInSlot(i + DimensionEnscriberContainer.SLOT_DIMLETS);
        if (stack != null && stack.stackSize > 0) {
            DimletKey key = KnownDimletConfiguration.getDimletKey(stack, worldObj);
            DimletEntry entry = KnownDimletConfiguration.getEntry(key);
            if (entry != null) {
                // Make sure the dimlet is not blacklisted.
                descriptors.add(key);
                NBTTagCompound tagCompound = stack.getTagCompound();
                if (tagCompound != null && tagCompound.getLong("forcedSeed") != 0) {
                    forcedSeed = tagCompound.getLong("forcedSeed");
                }
            }
        }
        inventoryHelper.setStackInSlot(i + DimensionEnscriberContainer.SLOT_DIMLETS, null);
    }
    return new DimensionDescriptor(descriptors, forcedSeed);
}
Also used : DimensionDescriptor(mcjty.rftools.dimension.description.DimensionDescriptor) ArrayList(java.util.ArrayList) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack)

Example 2 with DimensionDescriptor

use of mcjty.rftools.dimension.description.DimensionDescriptor in project RFTools by McJty.

the class DimensionEnscriberTileEntity method storeDimlets.

private void storeDimlets(EntityPlayerMP player) {
    if (DimletConfiguration.ownerDimletsNeeded) {
        if (checkOwnerDimlet()) {
            Logging.warn(player, "You need an owner dimlet to make a dimension!");
            return;
        }
    }
    DimensionDescriptor descriptor = convertToDimensionDescriptor();
    ItemStack realizedTab = createRealizedTab(descriptor, worldObj);
    inventoryHelper.setStackInSlot(DimensionEnscriberContainer.SLOT_TAB, realizedTab);
    markDirty();
}
Also used : DimensionDescriptor(mcjty.rftools.dimension.description.DimensionDescriptor) ItemStack(net.minecraft.item.ItemStack)

Example 3 with DimensionDescriptor

use of mcjty.rftools.dimension.description.DimensionDescriptor in project RFTools by McJty.

the class DimensionTickEvent method serverTick.

private void serverTick(boolean doEffects) {
    World entityWorld = MinecraftServer.getServer().getEntityWorld();
    RfToolsDimensionManager dimensionManager = RfToolsDimensionManager.getDimensionManager(entityWorld);
    if (!dimensionManager.getDimensions().isEmpty()) {
        DimensionStorage dimensionStorage = DimensionStorage.getDimensionStorage(entityWorld);
        for (Map.Entry<Integer, DimensionDescriptor> entry : dimensionManager.getDimensions().entrySet()) {
            Integer id = entry.getKey();
            // If there is an activity probe we only drain power if the dimension is loaded (a player is there or a chunkloader)
            DimensionInformation information = dimensionManager.getDimensionInformation(id);
            WorldServer world = DimensionManager.getWorld(id);
            // Power handling.
            if (world != null || information.getProbeCounter() == 0) {
                handlePower(doEffects, dimensionStorage, entry, id, information);
            }
            // Special effect handling.
            if (world != null && !world.playerEntities.isEmpty()) {
                handleRandomEffects(world, information);
            }
        }
        dimensionStorage.save(entityWorld);
    }
}
Also used : DimensionDescriptor(mcjty.rftools.dimension.description.DimensionDescriptor) WorldServer(net.minecraft.world.WorldServer) World(net.minecraft.world.World)

Example 4 with DimensionDescriptor

use of mcjty.rftools.dimension.description.DimensionDescriptor in project RFTools by McJty.

the class RfToolsDimensionManager method freezeDimension.

/**
 * Freeze a dimension: avoid ticking all tile entities and remove all
 * active entities (they are still there but will not do anything).
 * Entities that are within range of a player having a PFG will be kept
 * active (but not tile entities).
 */
public static void freezeDimension(World world) {
    // First find all players that have a valid PFG.
    List<Coordinate> pfgList = new ArrayList<Coordinate>();
    int radius = DimletConfiguration.phasedFieldGeneratorRange;
    if (radius > 0) {
        for (Object ent : world.playerEntities) {
            EntityPlayer player = (EntityPlayer) ent;
            // Check if this player has a valid PFG but don't consume energy.
            int cost = 0;
            if (DimletConfiguration.dimensionDifficulty != -1) {
                RfToolsDimensionManager dimensionManager = RfToolsDimensionManager.getDimensionManager(world);
                DimensionInformation information = dimensionManager.getDimensionInformation(world.provider.dimensionId);
                cost = information.getActualRfCost();
                if (cost == 0) {
                    DimensionDescriptor descriptor = dimensionManager.getDimensionDescriptor(world.provider.dimensionId);
                    cost = descriptor.getRfMaintainCost();
                }
            }
            if (checkValidPhasedFieldGenerator(player, false, cost)) {
                pfgList.add(new Coordinate((int) player.posX, (int) player.posY, (int) player.posZ));
            }
        }
    }
    // If there are players with a valid PFG then we check if there are entities we want to keep.
    List tokeep = new ArrayList();
    // We want to keep all players for sure.
    tokeep.addAll(world.playerEntities);
    // Add all entities that are within range of a PFG.
    for (Coordinate coordinate : pfgList) {
        getEntitiesInSphere(world, coordinate, radius, tokeep);
    }
    world.loadedEntityList.clear();
    world.loadedEntityList.addAll(tokeep);
    world.loadedTileEntityList.clear();
}
Also used : Coordinate(mcjty.lib.varia.Coordinate) DimensionDescriptor(mcjty.rftools.dimension.description.DimensionDescriptor) EntityPlayer(net.minecraft.entity.player.EntityPlayer) NBTTagList(net.minecraft.nbt.NBTTagList)

Example 5 with DimensionDescriptor

use of mcjty.rftools.dimension.description.DimensionDescriptor in project RFTools by McJty.

the class RfToolsDimensionManager method syncFromServer.

public void syncFromServer(Map<Integer, DimensionDescriptor> dims, Map<Integer, DimensionInformation> dimInfo) {
    Logging.log("RfToolsDimensionManager.syncFromServer");
    if (dims.isEmpty() || dimInfo.isEmpty()) {
        Logging.log("Dimension information from server is empty.");
    }
    for (Map.Entry<Integer, DimensionDescriptor> entry : dims.entrySet()) {
        int id = entry.getKey();
        DimensionDescriptor descriptor = entry.getValue();
        if (dimensions.containsKey(id)) {
            dimensionToID.remove(dimensions.get(id));
        }
        dimensions.put(id, descriptor);
        dimensionToID.put(descriptor, id);
    }
    for (Map.Entry<Integer, DimensionInformation> entry : dimInfo.entrySet()) {
        int id = entry.getKey();
        DimensionInformation info = entry.getValue();
        dimensionInformation.put(id, info);
    }
}
Also used : DimensionDescriptor(mcjty.rftools.dimension.description.DimensionDescriptor)

Aggregations

DimensionDescriptor (mcjty.rftools.dimension.description.DimensionDescriptor)15 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)6 RfToolsDimensionManager (mcjty.rftools.dimension.RfToolsDimensionManager)5 DimensionInformation (mcjty.rftools.dimension.DimensionInformation)4 ItemStack (net.minecraft.item.ItemStack)4 Map (java.util.Map)3 EntityPlayer (net.minecraft.entity.player.EntityPlayer)3 NBTTagList (net.minecraft.nbt.NBTTagList)3 ChatComponentText (net.minecraft.util.ChatComponentText)3 World (net.minecraft.world.World)3 IOException (java.io.IOException)2 Coordinate (mcjty.lib.varia.Coordinate)2 PacketBuffer (net.minecraft.network.PacketBuffer)2 WorldServer (net.minecraft.world.WorldServer)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 UUID (java.util.UUID)1 TeleportDestination (mcjty.rftools.blocks.teleporter.TeleportDestination)1 TeleportDestinationClientInfo (mcjty.rftools.blocks.teleporter.TeleportDestinationClientInfo)1 DimensionStorage (mcjty.rftools.dimension.DimensionStorage)1