Search in sources :

Example 26 with DimensionInformation

use of mcjty.rftools.dimension.DimensionInformation in project RFTools by McJty.

the class DimensionEditorTileEntity method canDeleteDimension.

private ItemStack canDeleteDimension(ItemStack itemStack) {
    if (!DimletConfiguration.playersCanDeleteDimensions) {
        Broadcaster.broadcast(worldObj, xCoord, yCoord, zCoord, "Players cannot delete dimensions!", 10);
        return null;
    }
    if (!DimletConfiguration.editorCanDeleteDimensions) {
        Broadcaster.broadcast(worldObj, xCoord, yCoord, zCoord, "Dimension deletion with the editor is not enabled!", 10);
        return null;
    }
    ItemStack dimensionStack = inventoryHelper.getStackInSlot(DimensionEditorContainer.SLOT_DIMENSIONTARGET);
    if (dimensionStack == null || dimensionStack.stackSize == 0) {
        return null;
    }
    NBTTagCompound tagCompound = dimensionStack.getTagCompound();
    int id = tagCompound.getInteger("id");
    if (id == 0) {
        return null;
    }
    DimensionInformation information = RfToolsDimensionManager.getDimensionManager(worldObj).getDimensionInformation(id);
    if (getOwnerUUID() != null && getOwnerUUID().equals(information.getOwner())) {
        return itemStack;
    }
    Broadcaster.broadcast(worldObj, xCoord, yCoord, zCoord, "This machine's owner differs from the dimensions owner!", 10);
    return null;
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack) DimensionInformation(mcjty.rftools.dimension.DimensionInformation)

Example 27 with DimensionInformation

use of mcjty.rftools.dimension.DimensionInformation in project RFTools by McJty.

the class DimensionMonitorItem method onItemRightClick.

@Override
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) {
    if (!world.isRemote) {
        int id = player.worldObj.provider.dimensionId;
        RfToolsDimensionManager dimensionManager = RfToolsDimensionManager.getDimensionManager(player.worldObj);
        DimensionInformation dimensionInformation = dimensionManager.getDimensionInformation(id);
        if (dimensionInformation == null) {
            Logging.message(player, "Not an RFTools dimension!");
        } else {
            String name = dimensionInformation.getName();
            DimensionStorage storage = DimensionStorage.getDimensionStorage(player.getEntityWorld());
            int power = storage != null ? storage.getEnergyLevel(id) : 0;
            Logging.message(player, EnumChatFormatting.BLUE + "Name: " + name + " (Id " + id + ")" + EnumChatFormatting.YELLOW + "    Power: " + power + " RF");
            if (player.isSneaking()) {
                Logging.message(player, EnumChatFormatting.RED + "Description: " + dimensionInformation.getDescriptor().getDescriptionString());
                System.out.println("Description:  = " + dimensionInformation.getDescriptor().getDescriptionString());
            }
        }
        return stack;
    }
    return stack;
}
Also used : DimensionStorage(mcjty.rftools.dimension.DimensionStorage) DimensionInformation(mcjty.rftools.dimension.DimensionInformation) RfToolsDimensionManager(mcjty.rftools.dimension.RfToolsDimensionManager)

Example 28 with DimensionInformation

use of mcjty.rftools.dimension.DimensionInformation in project RFTools by McJty.

the class CmdSaveDims method execute.

@Override
public void execute(ICommandSender sender, String[] args) {
    if (args.length < 2) {
        sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "The directory parameters is missing!"));
        return;
    } else if (args.length > 2) {
        sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "Too many parameters!"));
        return;
    }
    String directory = fetchString(sender, args, 1, null);
    if (!directory.endsWith(File.separator)) {
        directory += File.separator;
    }
    if (!new File(directory).mkdirs()) {
        sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "Failed to create directory!"));
        return;
    }
    World world = sender.getEntityWorld();
    RfToolsDimensionManager dimensionManager = RfToolsDimensionManager.getDimensionManager(world);
    for (Integer dim : dimensionManager.getDimensions().keySet()) {
        DimensionInformation information = dimensionManager.getDimensionInformation(dim);
        if (information != null) {
            String filename = directory + "dimension" + dim;
            String error = information.buildJson(filename);
            if (error != null) {
                sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "Error: " + error));
            }
        }
    }
}
Also used : World(net.minecraft.world.World) ChatComponentText(net.minecraft.util.ChatComponentText) File(java.io.File) DimensionInformation(mcjty.rftools.dimension.DimensionInformation) RfToolsDimensionManager(mcjty.rftools.dimension.RfToolsDimensionManager)

Example 29 with DimensionInformation

use of mcjty.rftools.dimension.DimensionInformation in project RFTools 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 = buffer.readNBTTagCompoundFromBuffer();
        } 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.rftools.dimension.description.DimensionDescriptor) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IOException(java.io.IOException) DimensionInformation(mcjty.rftools.dimension.DimensionInformation) PacketBuffer(net.minecraft.network.PacketBuffer)

Example 30 with DimensionInformation

use of mcjty.rftools.dimension.DimensionInformation in project RFTools by McJty.

the class PacketSyncDimensionInfo method toBytes.

@Override
public void toBytes(ByteBuf buf) {
    buf.writeInt(dimensions.size());
    for (Map.Entry<Integer, DimensionDescriptor> me : dimensions.entrySet()) {
        buf.writeInt(me.getKey());
        NBTTagCompound tagCompound = new NBTTagCompound();
        me.getValue().writeToNBT(tagCompound);
        PacketBuffer buffer = new PacketBuffer(buf);
        try {
            buffer.writeNBTTagCompoundToBuffer(tagCompound);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    buf.writeInt(dimensionInformation.size());
    for (Map.Entry<Integer, DimensionInformation> me : dimensionInformation.entrySet()) {
        buf.writeInt(me.getKey());
        DimensionInformation dimInfo = me.getValue();
        NetworkTools.writeString(buf, dimInfo.getName());
        dimInfo.toBytes(buf);
    }
}
Also used : DimensionDescriptor(mcjty.rftools.dimension.description.DimensionDescriptor) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IOException(java.io.IOException) Map(java.util.Map) HashMap(java.util.HashMap) DimensionInformation(mcjty.rftools.dimension.DimensionInformation) PacketBuffer(net.minecraft.network.PacketBuffer)

Aggregations

DimensionInformation (mcjty.rftools.dimension.DimensionInformation)35 RfToolsDimensionManager (mcjty.rftools.dimension.RfToolsDimensionManager)29 World (net.minecraft.world.World)19 ChatComponentText (net.minecraft.util.ChatComponentText)13 DimensionStorage (mcjty.rftools.dimension.DimensionStorage)8 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)8 SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)5 IOException (java.io.IOException)4 DimensionDescriptor (mcjty.rftools.dimension.description.DimensionDescriptor)4 ItemStack (net.minecraft.item.ItemStack)4 File (java.io.File)3 EffectType (mcjty.rftools.dimension.world.types.EffectType)3 EntityPlayer (net.minecraft.entity.player.EntityPlayer)3 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)3 Map (java.util.Map)2 Coordinate (mcjty.lib.varia.Coordinate)2 GlobalCoordinate (mcjty.lib.varia.GlobalCoordinate)2 TeleportDestinations (mcjty.rftools.blocks.teleporter.TeleportDestinations)2 PacketGetDimensionEnergy (mcjty.rftools.dimension.network.PacketGetDimensionEnergy)2 IMob (net.minecraft.entity.monster.IMob)2