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