Search in sources :

Example 6 with DimensionStorage

use of mcjty.rftoolsdim.dimensions.DimensionStorage in project RFToolsDimensions by McJty.

the class DimensionMonitorItem method clOnItemRightClick.

@Override
protected ActionResult<ItemStack> clOnItemRightClick(World world, EntityPlayer player, EnumHand hand) {
    ItemStack stack = player.getHeldItem(hand);
    if (!world.isRemote) {
        int id = player.getEntityWorld().provider.getDimension();
        RfToolsDimensionManager dimensionManager = RfToolsDimensionManager.getDimensionManager(player.getEntityWorld());
        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, TextFormatting.BLUE + "Name: " + name + " (Id " + id + ")" + TextFormatting.YELLOW + "    Power: " + power + " RF");
            if (player.isSneaking()) {
                Logging.message(player, TextFormatting.RED + "Description: " + dimensionInformation.getDescriptor().getDescriptionString());
                System.out.println("Description:  = " + dimensionInformation.getDescriptor().getDescriptionString());
            }
        }
        return new ActionResult<>(EnumActionResult.SUCCESS, stack);
    }
    return new ActionResult<>(EnumActionResult.SUCCESS, stack);
}
Also used : DimensionStorage(mcjty.rftoolsdim.dimensions.DimensionStorage) ActionResult(net.minecraft.util.ActionResult) EnumActionResult(net.minecraft.util.EnumActionResult) ItemStack(net.minecraft.item.ItemStack) DimensionInformation(mcjty.rftoolsdim.dimensions.DimensionInformation) RfToolsDimensionManager(mcjty.rftoolsdim.dimensions.RfToolsDimensionManager)

Example 7 with DimensionStorage

use of mcjty.rftoolsdim.dimensions.DimensionStorage in project RFToolsDimensions by McJty.

the class CmdSafeDelete method execute.

@Override
public void execute(ICommandSender sender, String[] args) {
    if (!(GeneralConfiguration.playersCanDeleteDimensions || CompatCommandBase.canUseCommand(sender, 3, getCommand()))) {
        ChatTools.addChatMessage(sender, new TextComponentString(TextFormatting.RED + "You have no permission to execute this command!"));
        return;
    }
    if (args.length < 2) {
        ChatTools.addChatMessage(sender, new TextComponentString(TextFormatting.RED + "The dimension parameter is missing!"));
        return;
    } else if (args.length > 2) {
        ChatTools.addChatMessage(sender, new TextComponentString(TextFormatting.RED + "Too many parameters!"));
        return;
    }
    int dim = fetchInt(sender, args, 1, 0);
    World world = sender.getEntityWorld();
    RfToolsDimensionManager dimensionManager = RfToolsDimensionManager.getDimensionManager(world);
    if (dimensionManager.getDimensionDescriptor(dim) == null) {
        ChatTools.addChatMessage(sender, new TextComponentString(TextFormatting.RED + "Not an RFTools dimension!"));
        return;
    }
    World w = DimensionManager.getWorld(dim);
    if (w != null) {
        ChatTools.addChatMessage(sender, new TextComponentString(TextFormatting.RED + "Dimension is still in use!"));
        return;
    }
    if (!CompatCommandBase.canUseCommand(sender, 3, "safedel")) {
        DimensionInformation information = dimensionManager.getDimensionInformation(dim);
        if (information.getOwner() == null) {
            ChatTools.addChatMessage(sender, new TextComponentString(TextFormatting.RED + "This dimension has no owner. You cannot delete it!"));
            return;
        }
        if (!(sender instanceof EntityPlayerMP)) {
            ChatTools.addChatMessage(sender, new TextComponentString(TextFormatting.RED + "This command must be run as a player!"));
            return;
        }
        EntityPlayerMP entityPlayerMP = (EntityPlayerMP) sender;
        if (!information.getOwner().equals(entityPlayerMP.getGameProfile().getId())) {
            ChatTools.addChatMessage(sender, new TextComponentString(TextFormatting.RED + "You are not the owner of this dimension. You cannot delete it!"));
            return;
        }
    }
    RFToolsDim.teleportationManager.removeReceiverDestinations(world, dim);
    dimensionManager.removeDimension(dim);
    dimensionManager.reclaimId(dim);
    dimensionManager.save(world);
    DimensionStorage dimensionStorage = DimensionStorage.getDimensionStorage(world);
    dimensionStorage.removeDimension(dim);
    dimensionStorage.save(world);
    if (GeneralConfiguration.dimensionFolderIsDeletedWithSafeDel) {
        File rootDirectory = DimensionManager.getCurrentSaveRootDirectory();
        try {
            FileUtils.deleteDirectory(new File(rootDirectory.getPath() + File.separator + "RFTOOLS" + dim));
            ChatTools.addChatMessage(sender, new TextComponentString("Dimension deleted and dimension folder succesfully wiped!"));
        } catch (IOException e) {
            ChatTools.addChatMessage(sender, new TextComponentString(TextFormatting.RED + "Dimension deleted but dimension folder could not be completely wiped!"));
        }
    } else {
        ChatTools.addChatMessage(sender, new TextComponentString("Dimension deleted. Please remove the dimension folder from disk!"));
    }
}
Also used : DimensionStorage(mcjty.rftoolsdim.dimensions.DimensionStorage) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) IOException(java.io.IOException) World(net.minecraft.world.World) DimensionInformation(mcjty.rftoolsdim.dimensions.DimensionInformation) File(java.io.File) RfToolsDimensionManager(mcjty.rftoolsdim.dimensions.RfToolsDimensionManager) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 8 with DimensionStorage

use of mcjty.rftoolsdim.dimensions.DimensionStorage in project RFToolsDimensions by McJty.

the class GenericWorldProvider method getRespawnDimension.

@Override
public int getRespawnDimension(EntityPlayerMP player) {
    getDimensionInformation();
    if (GeneralConfiguration.respawnSameDim || (dimensionInformation != null && dimensionInformation.isRespawnHere())) {
        DimensionStorage dimensionStorage = getStorage();
        int power = dimensionStorage.getEnergyLevel(getDimension());
        if (power < 1000) {
            return GeneralConfiguration.spawnDimension;
        } else {
            return getDimension();
        }
    }
    return GeneralConfiguration.spawnDimension;
}
Also used : DimensionStorage(mcjty.rftoolsdim.dimensions.DimensionStorage)

Example 9 with DimensionStorage

use of mcjty.rftoolsdim.dimensions.DimensionStorage in project RFToolsDimensions by McJty.

the class CmdListDimensions method execute.

@Override
public void execute(ICommandSender sender, String[] args) {
    WorldServer[] worlds = DimensionManager.getWorlds();
    for (WorldServer world : worlds) {
        int id = world.provider.getDimension();
        String dimName = world.provider.getDimensionType().getName();
        ChatTools.addChatMessage(sender, new TextComponentString("    Loaded: id:" + id + ", " + dimName));
    }
    RfToolsDimensionManager dimensionManager = RfToolsDimensionManager.getDimensionManager(sender.getEntityWorld());
    DimensionStorage dimensionStorage = DimensionStorage.getDimensionStorage(sender.getEntityWorld());
    for (Map.Entry<Integer, DimensionDescriptor> me : dimensionManager.getDimensions().entrySet()) {
        int id = me.getKey();
        DimensionInformation dimensionInformation = dimensionManager.getDimensionInformation(id);
        String dimName = dimensionInformation.getName();
        int energy = dimensionStorage.getEnergyLevel(id);
        String ownerName = dimensionInformation.getOwnerName();
        if (ownerName != null && !ownerName.isEmpty()) {
            ChatTools.addChatMessage(sender, new TextComponentString("    RfTools: id:" + id + ", " + dimName + " (power " + energy + ") (owner " + ownerName + ")"));
        } else {
            ChatTools.addChatMessage(sender, new TextComponentString("    RfTools: id:" + id + ", " + dimName + " (power " + energy + ")"));
        }
    }
}
Also used : DimensionStorage(mcjty.rftoolsdim.dimensions.DimensionStorage) DimensionDescriptor(mcjty.rftoolsdim.dimensions.description.DimensionDescriptor) WorldServer(net.minecraft.world.WorldServer) TextComponentString(net.minecraft.util.text.TextComponentString) Map(java.util.Map) DimensionInformation(mcjty.rftoolsdim.dimensions.DimensionInformation) RfToolsDimensionManager(mcjty.rftoolsdim.dimensions.RfToolsDimensionManager) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 10 with DimensionStorage

use of mcjty.rftoolsdim.dimensions.DimensionStorage in project RFToolsDimensions by McJty.

the class CmdSetPower method execute.

@Override
public void execute(ICommandSender sender, String[] args) {
    if (args.length > 2) {
        ChatTools.addChatMessage(sender, new TextComponentString(TextFormatting.RED + "Too many parameters!"));
        return;
    }
    int rf = fetchInt(sender, args, 1, PowerConfiguration.MAX_DIMENSION_POWER);
    World world = sender.getEntityWorld();
    int dim = world.provider.getDimension();
    RfToolsDimensionManager dimensionManager = RfToolsDimensionManager.getDimensionManager(world);
    DimensionInformation information = dimensionManager.getDimensionInformation(dim);
    if (information == null) {
        ChatTools.addChatMessage(sender, new TextComponentString(TextFormatting.RED + "Not an RFTools dimension!"));
        return;
    }
    DimensionStorage storage = DimensionStorage.getDimensionStorage(world);
    storage.setEnergyLevel(dim, rf);
    storage.save(world);
}
Also used : DimensionStorage(mcjty.rftoolsdim.dimensions.DimensionStorage) World(net.minecraft.world.World) DimensionInformation(mcjty.rftoolsdim.dimensions.DimensionInformation) RfToolsDimensionManager(mcjty.rftoolsdim.dimensions.RfToolsDimensionManager) TextComponentString(net.minecraft.util.text.TextComponentString)

Aggregations

DimensionStorage (mcjty.rftoolsdim.dimensions.DimensionStorage)13 DimensionInformation (mcjty.rftoolsdim.dimensions.DimensionInformation)8 RfToolsDimensionManager (mcjty.rftoolsdim.dimensions.RfToolsDimensionManager)7 World (net.minecraft.world.World)5 TextComponentString (net.minecraft.util.text.TextComponentString)3 File (java.io.File)2 IOException (java.io.IOException)2 PacketGetDimensionEnergy (mcjty.rftoolsdim.network.PacketGetDimensionEnergy)2 ItemStack (net.minecraft.item.ItemStack)2 BlockPos (net.minecraft.util.math.BlockPos)2 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)2 IEnergyConnection (cofh.api.energy.IEnergyConnection)1 Map (java.util.Map)1 GenericEnergyProviderTileEntity (mcjty.lib.entity.GenericEnergyProviderTileEntity)1 DimensionDescriptor (mcjty.rftoolsdim.dimensions.description.DimensionDescriptor)1 WorldClient (net.minecraft.client.multiplayer.WorldClient)1 ItemMeshDefinition (net.minecraft.client.renderer.ItemMeshDefinition)1 ModelResourceLocation (net.minecraft.client.renderer.block.model.ModelResourceLocation)1 EntityLivingBase (net.minecraft.entity.EntityLivingBase)1 IAttributeInstance (net.minecraft.entity.ai.attributes.IAttributeInstance)1