Search in sources :

Example 11 with DimensionDescriptor

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

the class PacketSyncDimensionInfo method fromBytes.

@Override
public void fromBytes(ByteBuf buf) {
    int size = buf.readInt();
    dimensions = new HashMap<Integer, DimensionDescriptor>();
    for (int i = 0; i < size; i++) {
        int id = buf.readInt();
        PacketBuffer buffer = new PacketBuffer(buf);
        NBTTagCompound tagCompound;
        try {
            tagCompound = PacketBufferTools.readCompoundTag(buffer);
        } catch (IOException e) {
            e.printStackTrace();
            return;
        }
        DimensionDescriptor descriptor = new DimensionDescriptor(tagCompound);
        dimensions.put(id, descriptor);
    }
    size = buf.readInt();
    dimensionInformation = new HashMap<Integer, DimensionInformation>();
    for (int i = 0; i < size; i++) {
        int id = buf.readInt();
        String name = NetworkTools.readString(buf);
        DimensionInformation dimInfo = new DimensionInformation(name, dimensions.get(id), buf);
        dimensionInformation.put(id, dimInfo);
    }
}
Also used : DimensionDescriptor(mcjty.rftoolsdim.dimensions.description.DimensionDescriptor) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IOException(java.io.IOException) DimensionInformation(mcjty.rftoolsdim.dimensions.DimensionInformation) PacketBuffer(net.minecraft.network.PacketBuffer)

Example 12 with DimensionDescriptor

use of mcjty.rftoolsdim.dimensions.description.DimensionDescriptor in project RFToolsDimensions 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<>();
    long forcedSeed = 0;
    for (int i = 0; i < DimensionEnscriberContainer.SIZE_DIMLETS; i++) {
        ItemStack stack = inventoryHelper.getStackInSlot(i + DimensionEnscriberContainer.SLOT_DIMLETS);
        if (ItemStackTools.isValid(stack)) {
            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 + DimensionEnscriberContainer.SLOT_DIMLETS, ItemStackTools.getEmptyStack());
    }
    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 13 with DimensionDescriptor

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

the class DimensionEnscriberTileEntity 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(DimensionEnscriberContainer.SLOT_TAB, realizedTab);
    markDirty();
}
Also used : DimensionDescriptor(mcjty.rftoolsdim.dimensions.description.DimensionDescriptor) ItemStack(net.minecraft.item.ItemStack)

Example 14 with DimensionDescriptor

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

the class DimensionTickEvent method serverTick.

private void serverTick(World entityWorld, boolean doEffects) {
    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);
            if (!information.isCheater()) {
                WorldServer world = DimensionManager.getWorld(id);
                // Power handling.
                if ((world != null && world.getChunkProvider().getLoadedChunkCount() > 0) || information.getProbeCounter() == 0) {
                    handlePower(doEffects, dimensionStorage, entry, id, information);
                }
                // Special effect handling.
                if (world != null && !world.playerEntities.isEmpty()) {
                    handleRandomEffects(world, information);
                }
            }
        }
        dimensionStorage.save(entityWorld);
    }
}
Also used : DimensionDescriptor(mcjty.rftoolsdim.dimensions.description.DimensionDescriptor) WorldServer(net.minecraft.world.WorldServer)

Example 15 with DimensionDescriptor

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

the class RfToolsDimensionManager method writeToNBT.

@Override
public NBTTagCompound writeToNBT(NBTTagCompound tagCompound) {
    NBTTagList lst = new NBTTagList();
    for (Map.Entry<Integer, DimensionDescriptor> me : dimensions.entrySet()) {
        NBTTagCompound tc = new NBTTagCompound();
        Integer id = me.getKey();
        tc.setInteger("id", id);
        me.getValue().writeToNBT(tc);
        DimensionInformation dimensionInfo = dimensionInformation.get(id);
        dimensionInfo.writeToNBT(tc);
        lst.appendTag(tc);
    }
    tagCompound.setTag("dimensions", lst);
    List<Integer> ids = new ArrayList<Integer>(reclaimedIds);
    int[] lstIds = new int[ids.size()];
    for (int i = 0; i < ids.size(); i++) {
        lstIds[i] = ids.get(i);
    }
    tagCompound.setIntArray("reclaimedIds", lstIds);
    return tagCompound;
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) DimensionDescriptor(mcjty.rftoolsdim.dimensions.description.DimensionDescriptor) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ClassInheritanceMultiMap(net.minecraft.util.ClassInheritanceMultiMap)

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