Search in sources :

Example 1 with DimensionDescriptor

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;
}
Also used : DimensionDescriptor(mcjty.rftoolsdim.dimensions.description.DimensionDescriptor) RfToolsDimensionManager(mcjty.rftoolsdim.dimensions.RfToolsDimensionManager)

Example 2 with DimensionDescriptor

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();
}
Also used : DimensionDescriptor(mcjty.rftoolsdim.dimensions.description.DimensionDescriptor) ItemStack(net.minecraft.item.ItemStack)

Example 3 with DimensionDescriptor

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);
}
Also used : DimensionDescriptor(mcjty.rftoolsdim.dimensions.description.DimensionDescriptor) ArrayList(java.util.ArrayList) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) DimletKey(mcjty.rftoolsdim.dimensions.dimlets.DimletKey) ItemStack(net.minecraft.item.ItemStack) Settings(mcjty.rftoolsdim.config.Settings)

Example 4 with DimensionDescriptor

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);
    }
}
Also used : DimensionDescriptor(mcjty.rftoolsdim.dimensions.description.DimensionDescriptor)

Example 5 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 (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();
}
Also used : Entity(net.minecraft.entity.Entity) DimensionDescriptor(mcjty.rftoolsdim.dimensions.description.DimensionDescriptor) EntityPlayer(net.minecraft.entity.player.EntityPlayer) BlockPos(net.minecraft.util.math.BlockPos) GenericWorldProvider(mcjty.rftoolsdim.dimensions.world.GenericWorldProvider)

Aggregations

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