Search in sources :

Example 6 with DimensionDescriptor

use of mcjty.rftoolsdim.dimensions.description.DimensionDescriptor in project RFToolsDimensions 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<BlockPos> pfgList = new ArrayList<>();
    int radius = PowerConfiguration.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 (PowerConfiguration.dimensionDifficulty != -1) {
                RfToolsDimensionManager dimensionManager = RfToolsDimensionManager.getDimensionManager(world);
                DimensionInformation information = dimensionManager.getDimensionInformation(world.provider.getDimension());
                cost = information.getActualRfCost();
                if (cost == 0) {
                    DimensionDescriptor descriptor = dimensionManager.getDimensionDescriptor(world.provider.getDimension());
                    cost = descriptor.getRfMaintainCost();
                }
            }
            if (checkValidPhasedFieldGenerator(player, false, cost)) {
                pfgList.add(new BlockPos((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 (BlockPos coordinate : pfgList) {
        getEntitiesInSphere(world, coordinate, radius, tokeep);
    }
    world.loadedEntityList.clear();
    world.loadedEntityList.addAll(tokeep);
    world.loadedTileEntityList.clear();
}
Also used : DimensionDescriptor(mcjty.rftoolsdim.dimensions.description.DimensionDescriptor) EntityPlayer(net.minecraft.entity.player.EntityPlayer) BlockPos(net.minecraft.util.math.BlockPos) NBTTagList(net.minecraft.nbt.NBTTagList)

Example 7 with DimensionDescriptor

use of mcjty.rftoolsdim.dimensions.description.DimensionDescriptor in project RFToolsDimensions by McJty.

the class RfToolsDimensionManager method syncFromServer.

public void syncFromServer(Map<Integer, DimensionDescriptor> dims, Map<Integer, DimensionInformation> dimInfo) {
    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.rftoolsdim.dimensions.description.DimensionDescriptor) ClassInheritanceMultiMap(net.minecraft.util.ClassInheritanceMultiMap)

Example 8 with DimensionDescriptor

use of mcjty.rftoolsdim.dimensions.description.DimensionDescriptor in project RFToolsDimensions by McJty.

the class CmdCreateDimension method execute.

@Override
public void execute(ICommandSender sender, String[] args) {
    if (args.length < 3) {
        ChatTools.addChatMessage(sender, new TextComponentString(TextFormatting.RED + "The name and terrain parameters are missing!"));
        return;
    } else if (args.length > 3) {
        ChatTools.addChatMessage(sender, new TextComponentString(TextFormatting.RED + "Too many parameters!"));
        return;
    }
    String name = fetchString(sender, args, 1, "");
    String terrainName = fetchString(sender, args, 2, "Void");
    TerrainType terrainType = TerrainType.getTerrainById(terrainName);
    if (terrainType == null) {
        ChatTools.addChatMessage(sender, new TextComponentString(TextFormatting.RED + "Unknown terrain type!"));
        return;
    }
    if (!(sender instanceof EntityPlayer)) {
        ChatTools.addChatMessage(sender, new TextComponentString(TextFormatting.RED + "You must be a player to use this command!"));
        return;
    }
    EntityPlayer player = (EntityPlayer) sender;
    RfToolsDimensionManager dimensionManager = RfToolsDimensionManager.getDimensionManager(sender.getEntityWorld());
    List<DimletKey> descriptors = new ArrayList<>();
    descriptors.add(new DimletKey(DimletType.DIMLET_TERRAIN, terrainType.getId()));
    DimensionDescriptor descriptor = new DimensionDescriptor(descriptors, 0);
    int dim = 0;
    try {
        dim = dimensionManager.createNewDimension(sender.getEntityWorld(), descriptor, name, player.getDisplayName().toString(), player.getPersistentID());
    } catch (Exception e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }
    ChatTools.addChatMessage(sender, new TextComponentString(TextFormatting.GREEN + "Created dimension: " + dim));
    dimensionManager.save(sender.getEntityWorld());
}
Also used : DimensionDescriptor(mcjty.rftoolsdim.dimensions.description.DimensionDescriptor) ArrayList(java.util.ArrayList) EntityPlayer(net.minecraft.entity.player.EntityPlayer) TextComponentString(net.minecraft.util.text.TextComponentString) TerrainType(mcjty.rftoolsdim.dimensions.types.TerrainType) DimletKey(mcjty.rftoolsdim.dimensions.dimlets.DimletKey) RfToolsDimensionManager(mcjty.rftoolsdim.dimensions.RfToolsDimensionManager) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 9 with DimensionDescriptor

use of mcjty.rftoolsdim.dimensions.description.DimensionDescriptor in project RFToolsDimensions by McJty.

the class CmdCreateTab method execute.

@Override
public void execute(ICommandSender sender, String[] args) {
    if (args.length < 2) {
        ChatTools.addChatMessage(sender, new TextComponentString(TextFormatting.RED + "The dimension parameter is missing!"));
        return;
    } else if (args.length > 2) {
        ChatTools.addChatMessage(sender, new TextComponentString(TextFormatting.RED + "Too many parameters!"));
        return;
    }
    int dim = fetchInt(sender, args, 1, 0);
    World world = sender.getEntityWorld();
    RfToolsDimensionManager dimensionManager = RfToolsDimensionManager.getDimensionManager(world);
    DimensionDescriptor dimensionDescriptor = dimensionManager.getDimensionDescriptor(dim);
    if (dimensionDescriptor == null) {
        ChatTools.addChatMessage(sender, new TextComponentString(TextFormatting.RED + "Not an RFTools dimension!"));
        return;
    }
    if (sender instanceof EntityPlayer) {
        EntityPlayer player = (EntityPlayer) sender;
        ItemStack tab = DimensionEnscriberTileEntity.createRealizedTab(dimensionDescriptor, sender.getEntityWorld());
        InventoryHelper.mergeItemStack(player.inventory, false, tab, 0, 35, null);
    } else {
        ChatTools.addChatMessage(sender, new TextComponentString(TextFormatting.RED + "This command only works as a player!"));
    }
}
Also used : DimensionDescriptor(mcjty.rftoolsdim.dimensions.description.DimensionDescriptor) EntityPlayer(net.minecraft.entity.player.EntityPlayer) World(net.minecraft.world.World) ItemStack(net.minecraft.item.ItemStack) RfToolsDimensionManager(mcjty.rftoolsdim.dimensions.RfToolsDimensionManager) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 10 with DimensionDescriptor

use of mcjty.rftoolsdim.dimensions.description.DimensionDescriptor in project RFToolsDimensions by McJty.

the class CmdListDimensions method execute.

@Override
public void execute(ICommandSender sender, String[] args) {
    WorldServer[] worlds = DimensionManager.getWorlds();
    for (WorldServer world : worlds) {
        int id = world.provider.getDimension();
        String dimName = world.provider.getDimensionType().getName();
        ChatTools.addChatMessage(sender, new TextComponentString("    Loaded: id:" + id + ", " + dimName));
    }
    RfToolsDimensionManager dimensionManager = RfToolsDimensionManager.getDimensionManager(sender.getEntityWorld());
    DimensionStorage dimensionStorage = DimensionStorage.getDimensionStorage(sender.getEntityWorld());
    for (Map.Entry<Integer, DimensionDescriptor> me : dimensionManager.getDimensions().entrySet()) {
        int id = me.getKey();
        DimensionInformation dimensionInformation = dimensionManager.getDimensionInformation(id);
        String dimName = dimensionInformation.getName();
        int energy = dimensionStorage.getEnergyLevel(id);
        String ownerName = dimensionInformation.getOwnerName();
        if (ownerName != null && !ownerName.isEmpty()) {
            ChatTools.addChatMessage(sender, new TextComponentString("    RfTools: id:" + id + ", " + dimName + " (power " + energy + ") (owner " + ownerName + ")"));
        } else {
            ChatTools.addChatMessage(sender, new TextComponentString("    RfTools: id:" + id + ", " + dimName + " (power " + energy + ")"));
        }
    }
}
Also used : DimensionStorage(mcjty.rftoolsdim.dimensions.DimensionStorage) DimensionDescriptor(mcjty.rftoolsdim.dimensions.description.DimensionDescriptor) WorldServer(net.minecraft.world.WorldServer) TextComponentString(net.minecraft.util.text.TextComponentString) Map(java.util.Map) DimensionInformation(mcjty.rftoolsdim.dimensions.DimensionInformation) RfToolsDimensionManager(mcjty.rftoolsdim.dimensions.RfToolsDimensionManager) TextComponentString(net.minecraft.util.text.TextComponentString)

Aggregations

DimensionDescriptor (mcjty.rftoolsdim.dimensions.description.DimensionDescriptor)16 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)6 ItemStack (net.minecraft.item.ItemStack)5 RfToolsDimensionManager (mcjty.rftoolsdim.dimensions.RfToolsDimensionManager)4 ArrayList (java.util.ArrayList)3 DimensionInformation (mcjty.rftoolsdim.dimensions.DimensionInformation)3 DimletKey (mcjty.rftoolsdim.dimensions.dimlets.DimletKey)3 EntityPlayer (net.minecraft.entity.player.EntityPlayer)3 NBTTagList (net.minecraft.nbt.NBTTagList)3 TextComponentString (net.minecraft.util.text.TextComponentString)3 Map (java.util.Map)2 Settings (mcjty.rftoolsdim.config.Settings)2 PacketBuffer (net.minecraft.network.PacketBuffer)2 ClassInheritanceMultiMap (net.minecraft.util.ClassInheritanceMultiMap)2 WorldServer (net.minecraft.world.WorldServer)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 DimensionStorage (mcjty.rftoolsdim.dimensions.DimensionStorage)1 TerrainType (mcjty.rftoolsdim.dimensions.types.TerrainType)1 BlockPos (net.minecraft.util.math.BlockPos)1