use of mcjty.rftoolsdim.dimensions.description.DimensionDescriptor in project RFToolsDimensions by McJty.
the class DimensionBuilderTileEntity method createDimensionTick.
private int createDimensionTick(NBTTagCompound tagCompound, int ticksLeft) {
if (GeneralConfiguration.dimensionBuilderNeedsOwner) {
if (getOwnerUUID() == null) {
// No valid owner so we don't build the dimension.
errorMode = ERROR_NOOWNER;
return ticksLeft;
}
if (GeneralConfiguration.maxDimensionsPerPlayer >= 0) {
int tickCost = tagCompound.getInteger("tickCost");
if (ticksLeft == tickCost || ticksLeft < 5) {
// Check if we are allow to make the dimension.
RfToolsDimensionManager manager = RfToolsDimensionManager.getDimensionManager(getWorld());
int cnt = manager.countOwnedDimensions(getOwnerUUID());
if (cnt >= GeneralConfiguration.maxDimensionsPerPlayer) {
errorMode = ERROR_TOOMANYDIMENSIONS;
return ticksLeft;
}
}
}
}
errorMode = OK;
int createCost = tagCompound.getInteger("rfCreateCost");
createCost = (int) (createCost * (2.0f - getInfusedFactor()) / 2.0f);
if (isCheaterDimension(tagCompound) || (getEnergyStored() >= createCost)) {
if (isCheaterDimension(tagCompound)) {
ticksLeft = 0;
} else {
consumeEnergy(createCost);
ticksLeft--;
if (random.nextFloat() < getInfusedFactor()) {
// Randomly reduce another tick if the device is infused.
ticksLeft--;
if (ticksLeft < 0) {
ticksLeft = 0;
}
}
}
tagCompound.setInteger("ticksLeft", ticksLeft);
if (ticksLeft <= 0) {
RfToolsDimensionManager manager = RfToolsDimensionManager.getDimensionManager(getWorld());
DimensionDescriptor descriptor = new DimensionDescriptor(tagCompound);
String name = tagCompound.getString("name");
int id = manager.createNewDimension(getWorld(), descriptor, name, getOwnerName(), getOwnerUUID());
tagCompound.setInteger("id", id);
}
}
return ticksLeft;
}
use of mcjty.rftoolsdim.dimensions.description.DimensionDescriptor in project RFToolsDimensions by McJty.
the class EssencePainterTileEntity method storeDimlets.
private void storeDimlets(EntityPlayerMP player) {
if (GeneralConfiguration.ownerDimletsNeeded) {
if (checkOwnerDimlet()) {
Logging.warn(player, "You need an owner dimlet to make a dimension!");
return;
}
}
DimensionDescriptor descriptor = convertToDimensionDescriptor();
ItemStack realizedTab = createRealizedTab(descriptor, getWorld());
inventoryHelper.setStackInSlot(EssencePainterContainer.SLOT_TAB, realizedTab);
markDirty();
}
use of mcjty.rftoolsdim.dimensions.description.DimensionDescriptor in project RFToolsDimensions by McJty.
the class EssencePainterTileEntity method convertToDimensionDescriptor.
/**
* Convert the dimlets in the inventory to a dimension descriptor.
*/
private DimensionDescriptor convertToDimensionDescriptor() {
List<DimletKey> descriptors = new ArrayList<>();
long forcedSeed = 0;
for (int i = 0; i < EssencePainterContainer.SIZE_DIMLETS; i++) {
ItemStack stack = inventoryHelper.getStackInSlot(i + EssencePainterContainer.SLOT_DIMLETS);
if (!stack.isEmpty()) {
DimletKey key = KnownDimletConfiguration.getDimletKey(stack);
Settings settings = KnownDimletConfiguration.getSettings(key);
if (settings != 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 + EssencePainterContainer.SLOT_DIMLETS, ItemStack.EMPTY);
}
return new DimensionDescriptor(descriptors, forcedSeed);
}
use of mcjty.rftoolsdim.dimensions.description.DimensionDescriptor in project RFToolsDimensions by McJty.
the class RfToolsDimensionManager method removeDimension.
public void removeDimension(int id) {
DimensionDescriptor descriptor = dimensions.get(id);
dimensions.remove(id);
dimensionToID.remove(descriptor);
dimensionInformation.remove(id);
if (DimensionManager.isDimensionRegistered(id)) {
DimensionManager.unregisterDimension(id);
}
}
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 (EntityPlayer player : world.playerEntities) {
// Check if this player has a valid PFG but don't consume energy.
int cost = 0;
if (PowerConfiguration.dimensionDifficulty != -1) {
DimensionInformation information = ((GenericWorldProvider) world.provider).getDimensionInformation();
cost = information.getActualRfCost();
if (cost == 0) {
DimensionDescriptor descriptor = information.getDescriptor();
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<Entity> 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();
}
Aggregations