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();
}
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);
}
}
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());
}
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!"));
}
}
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 + ")"));
}
}
}
Aggregations