Search in sources :

Example 1 with DimensionStorage

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

the class DimensionEditorTileEntity method safeDeleteDimension.

private void safeDeleteDimension(int id, ItemStack dimensionTab) {
    World w = DimensionManager.getWorld(id);
    if (w != null) {
        // Dimension is still loaded. Do nothing.
        Broadcaster.broadcast(getWorld(), pos.getX(), pos.getY(), pos.getZ(), "Dimension cannot be deleted. It is still in use!", 10);
        return;
    }
    RfToolsDimensionManager dimensionManager = RfToolsDimensionManager.getDimensionManager(getWorld());
    DimensionInformation information = dimensionManager.getDimensionInformation(id);
    if (information.getOwner() == null) {
        Broadcaster.broadcast(getWorld(), pos.getX(), pos.getY(), pos.getZ(), "You cannot delete a dimension without an owner!", 10);
        return;
    }
    if (getOwnerUUID() == null) {
        Broadcaster.broadcast(getWorld(), pos.getX(), pos.getY(), pos.getZ(), "This machine has no proper owner and cannot delete dimensions!", 10);
        return;
    }
    if (!getOwnerUUID().equals(information.getOwner())) {
        Broadcaster.broadcast(getWorld(), pos.getX(), pos.getY(), pos.getZ(), "This machine's owner differs from the dimensions owner!", 10);
        return;
    }
    RFToolsDim.teleportationManager.removeReceiverDestinations(getWorld(), id);
    dimensionManager.removeDimension(id);
    dimensionManager.reclaimId(id);
    dimensionManager.save(getWorld());
    DimensionStorage dimensionStorage = DimensionStorage.getDimensionStorage(getWorld());
    dimensionStorage.removeDimension(id);
    dimensionStorage.save(getWorld());
    if (GeneralConfiguration.dimensionFolderIsDeletedWithSafeDel) {
        File rootDirectory = DimensionManager.getCurrentSaveRootDirectory();
        try {
            FileUtils.deleteDirectory(new File(rootDirectory.getPath() + File.separator + "RFTOOLS" + id));
            Broadcaster.broadcast(getWorld(), pos.getX(), pos.getY(), pos.getZ(), "Dimension deleted and dimension folder succesfully wiped!", 10);
        } catch (IOException e) {
            Broadcaster.broadcast(getWorld(), pos.getX(), pos.getY(), pos.getZ(), "Dimension deleted but dimension folder could not be completely wiped!", 10);
        }
    } else {
        Broadcaster.broadcast(getWorld(), pos.getX(), pos.getY(), pos.getZ(), "Dimension deleted. Please remove the dimension folder from disk!", 10);
    }
    dimensionTab.getTagCompound().removeTag("id");
    int tickCost = dimensionTab.getTagCompound().getInteger("tickCost");
    dimensionTab.getTagCompound().setInteger("ticksLeft", tickCost);
}
Also used : DimensionStorage(mcjty.rftoolsdim.dimensions.DimensionStorage) IOException(java.io.IOException) World(net.minecraft.world.World) DimensionInformation(mcjty.rftoolsdim.dimensions.DimensionInformation) File(java.io.File) RfToolsDimensionManager(mcjty.rftoolsdim.dimensions.RfToolsDimensionManager)

Example 2 with DimensionStorage

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

the class ReturnEnergyHelper method setEnergyLevel.

public static void setEnergyLevel(PacketReturnEnergy message) {
    World world = MinecraftTools.getWorld(Minecraft.getMinecraft());
    DimensionStorage dimensionStorage = DimensionStorage.getDimensionStorage(world);
    dimensionStorage.setEnergyLevel(message.getId(), message.getEnergy());
}
Also used : DimensionStorage(mcjty.rftoolsdim.dimensions.DimensionStorage) World(net.minecraft.world.World)

Example 3 with DimensionStorage

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

the class DimensionBuilderTileEntity method maintainDimensionTick.

private void maintainDimensionTick(NBTTagCompound tagCompound) {
    int id = tagCompound.getInteger("id");
    if (id != 0) {
        DimensionStorage dimensionStorage = DimensionStorage.getDimensionStorage(getWorld());
        int rf;
        if (isCheaterDimension(tagCompound)) {
            rf = MachineConfiguration.BUILDER_MAXENERGY;
        } else {
            rf = getEnergyStored(EnumFacing.DOWN);
        }
        int energy = dimensionStorage.getEnergyLevel(id);
        // Max energy the dimension can still get.
        int maxEnergy = PowerConfiguration.MAX_DIMENSION_POWER - energy;
        if (rf > maxEnergy) {
            rf = maxEnergy;
        }
        counter--;
        if (counter < 0) {
            counter = 20;
            if (Logging.debugMode) {
                Logging.log("#################### id:" + id + ", rf:" + rf + ", energy:" + energy + ", max:" + maxEnergy);
            }
        }
        if (!isCheaterDimension(tagCompound)) {
            consumeEnergy(rf);
        }
        dimensionStorage.setEnergyLevel(id, energy + rf);
        dimensionStorage.save(getWorld());
    }
}
Also used : DimensionStorage(mcjty.rftoolsdim.dimensions.DimensionStorage)

Example 4 with DimensionStorage

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

the class RealizedDimensionTab method addInformation.

@SideOnly(Side.CLIENT)
@Override
public void addInformation(ItemStack itemStack, EntityPlayer player, List<String> list, boolean whatIsThis) {
    super.addInformation(itemStack, player, list, whatIsThis);
    NBTTagCompound tagCompound = itemStack.getTagCompound();
    if (tagCompound != null) {
        String name = tagCompound.getString("name");
        int id = 0;
        if (name != null) {
            id = tagCompound.getInteger("id");
            if (id == 0) {
                list.add(TextFormatting.BLUE + "Name: " + name);
            } else {
                list.add(TextFormatting.BLUE + "Name: " + name + " (Id " + id + ")");
            }
        }
        String descriptionString = tagCompound.getString("descriptionString");
        constructDescriptionHelp(list, descriptionString);
        Integer ticksLeft = tagCompound.getInteger("ticksLeft");
        if (ticksLeft == 0) {
            DimensionInformation information = RfToolsDimensionManager.getDimensionManager(player.getEntityWorld()).getDimensionInformation(id);
            if (information == null) {
                list.add(TextFormatting.RED + "Dimension information Missing!");
            } else {
                list.add(TextFormatting.BLUE + "Dimension ready!");
                int maintainCost = tagCompound.getInteger("rfMaintainCost");
                int actualCost = information.getActualRfCost();
                if (actualCost == maintainCost || actualCost == 0) {
                    list.add(TextFormatting.YELLOW + "    Maintenance cost: " + maintainCost + " RF/tick");
                } else {
                    list.add(TextFormatting.YELLOW + "    Maintenance cost: " + actualCost + " RF/tick (Specified: " + maintainCost + " RF/tick)");
                }
                if (id != 0) {
                    if (System.currentTimeMillis() - lastTime > 500) {
                        lastTime = System.currentTimeMillis();
                        RFToolsDimMessages.INSTANCE.sendToServer(new PacketGetDimensionEnergy(id));
                    }
                    DimensionStorage storage = DimensionStorage.getDimensionStorage(player.getEntityWorld());
                    int power = storage.getEnergyLevel(id);
                    list.add(TextFormatting.YELLOW + "    Current power: " + power + " RF");
                }
            }
        } else {
            int createCost = tagCompound.getInteger("rfCreateCost");
            int maintainCost = tagCompound.getInteger("rfMaintainCost");
            int tickCost = tagCompound.getInteger("tickCost");
            int percentage = (tickCost - ticksLeft) * 100 / tickCost;
            list.add(TextFormatting.BLUE + "Dimension progress: " + percentage + "%");
            list.add(TextFormatting.YELLOW + "    Creation cost: " + createCost + " RF/tick");
            list.add(TextFormatting.YELLOW + "    Maintenance cost: " + maintainCost + " RF/tick");
            list.add(TextFormatting.YELLOW + "    Tick cost: " + tickCost + " ticks");
        }
    }
}
Also used : DimensionStorage(mcjty.rftoolsdim.dimensions.DimensionStorage) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) DimensionInformation(mcjty.rftoolsdim.dimensions.DimensionInformation) PacketGetDimensionEnergy(mcjty.rftoolsdim.network.PacketGetDimensionEnergy) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 5 with DimensionStorage

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

the class DimensionMonitorItem method initModel.

@Override
@SideOnly(Side.CLIENT)
public void initModel() {
    for (int i = 0; i <= 8; i++) {
        ResourceLocation registryName = getRegistryName();
        registryName = new ResourceLocation(registryName.getResourceDomain(), registryName.getResourcePath() + i);
        ModelBakery.registerItemVariants(this, new ModelResourceLocation(registryName, "inventory"));
    //            ModelBakery.addVariantName(this, getRegistryName() + i);
    }
    ModelLoader.setCustomMeshDefinition(this, new ItemMeshDefinition() {

        @Override
        public ModelResourceLocation getModelLocation(ItemStack stack) {
            WorldClient world = MinecraftTools.getWorld(Minecraft.getMinecraft());
            int id = world.provider.getDimension();
            DimensionStorage storage = DimensionStorage.getDimensionStorage(world);
            int energyLevel = storage.getEnergyLevel(id);
            int level = (9 * energyLevel) / PowerConfiguration.MAX_DIMENSION_POWER;
            if (level < 0) {
                level = 0;
            } else if (level > 8) {
                level = 8;
            }
            ResourceLocation registryName = getRegistryName();
            registryName = new ResourceLocation(registryName.getResourceDomain(), registryName.getResourcePath() + (8 - level));
            return new ModelResourceLocation(registryName, "inventory");
        }
    });
}
Also used : ItemMeshDefinition(net.minecraft.client.renderer.ItemMeshDefinition) DimensionStorage(mcjty.rftoolsdim.dimensions.DimensionStorage) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) ResourceLocation(net.minecraft.util.ResourceLocation) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) ItemStack(net.minecraft.item.ItemStack) WorldClient(net.minecraft.client.multiplayer.WorldClient) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

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