Search in sources :

Example 26 with RfToolsDimensionManager

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

the class MatterTransmitterTileEntity method checkReceiverStatus.

// Server side only
private int checkReceiverStatus() {
    TeleportDestination destination = getTeleportDestination();
    if (destination == null) {
        return TeleportationTools.STATUS_WARN;
    }
    int dimension = destination.getDimension();
    RfToolsDimensionManager dimensionManager = RfToolsDimensionManager.getDimensionManager(worldObj);
    if (dimensionManager.getDimensionInformation(dimension) != null) {
        // This is an RFTools dimension. Check power.
        DimensionStorage dimensionStorage = DimensionStorage.getDimensionStorage(worldObj);
        int energyLevel = dimensionStorage.getEnergyLevel(dimension);
        if (energyLevel < DimletConfiguration.DIMPOWER_WARN_TP) {
            return TeleportationTools.STATUS_WARN;
        }
    }
    World w = DimensionManager.getWorld(dimension);
    // By default we will not check if the dimension is not loaded. Can be changed in config.
    if (w == null) {
        if (TeleportConfiguration.matterTransmitterLoadWorld == -1) {
            return TeleportationTools.STATUS_UNKNOWN;
        } else {
            w = MinecraftServer.getServer().worldServerForDimension(dimension);
            checkReceiverStatusCounter = TeleportConfiguration.matterTransmitterLoadWorld;
        }
    }
    Coordinate c = destination.getCoordinate();
    boolean exists = w.getChunkProvider().chunkExists(c.getX() >> 4, c.getZ() >> 4);
    if (!exists) {
        if (TeleportConfiguration.matterTransmitterLoadChunk == -1) {
            return TeleportationTools.STATUS_UNKNOWN;
        } else {
            checkReceiverStatusCounter = TeleportConfiguration.matterTransmitterLoadChunk;
        }
    }
    TileEntity tileEntity = w.getTileEntity(c.getX(), c.getY(), c.getZ());
    if (!(tileEntity instanceof MatterReceiverTileEntity)) {
        return TeleportationTools.STATUS_WARN;
    }
    MatterReceiverTileEntity matterReceiverTileEntity = (MatterReceiverTileEntity) tileEntity;
    int status = matterReceiverTileEntity.checkStatus();
    return (status == DialingDeviceTileEntity.DIAL_OK) ? TeleportationTools.STATUS_OK : TeleportationTools.STATUS_WARN;
}
Also used : GenericEnergyReceiverTileEntity(mcjty.lib.entity.GenericEnergyReceiverTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) DimensionStorage(mcjty.rftools.dimension.DimensionStorage) GlobalCoordinate(mcjty.lib.varia.GlobalCoordinate) Coordinate(mcjty.lib.varia.Coordinate) World(net.minecraft.world.World) RfToolsDimensionManager(mcjty.rftools.dimension.RfToolsDimensionManager)

Example 27 with RfToolsDimensionManager

use of mcjty.rftools.dimension.RfToolsDimensionManager in project RFTools 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.dimensionId;
        String dimName = world.provider.getDimensionName();
        sender.addChatMessage(new ChatComponentText("    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()) {
            sender.addChatMessage(new ChatComponentText("    RfTools: id:" + id + ", " + dimName + " (power " + energy + ") (owner " + ownerName + ")"));
        } else {
            sender.addChatMessage(new ChatComponentText("    RfTools: id:" + id + ", " + dimName + " (power " + energy + ")"));
        }
    }
}
Also used : DimensionStorage(mcjty.rftools.dimension.DimensionStorage) DimensionDescriptor(mcjty.rftools.dimension.description.DimensionDescriptor) WorldServer(net.minecraft.world.WorldServer) ChatComponentText(net.minecraft.util.ChatComponentText) Map(java.util.Map) DimensionInformation(mcjty.rftools.dimension.DimensionInformation) RfToolsDimensionManager(mcjty.rftools.dimension.RfToolsDimensionManager)

Example 28 with RfToolsDimensionManager

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

the class ActivityProbeBlock method onBlockPlaced.

@Override
public int onBlockPlaced(World world, int x, int y, int z, int side, float sx, float sy, float sz, int meta) {
    int rc = super.onBlockPlaced(world, x, y, z, side, sx, sy, sz, meta);
    if (!world.isRemote) {
        RfToolsDimensionManager dimensionManager = RfToolsDimensionManager.getDimensionManager(world);
        DimensionInformation information = dimensionManager.getDimensionInformation(world.provider.dimensionId);
        if (information != null) {
            information.addProbe();
        }
        dimensionManager.save(world);
    }
    return rc;
}
Also used : DimensionInformation(mcjty.rftools.dimension.DimensionInformation) RfToolsDimensionManager(mcjty.rftools.dimension.RfToolsDimensionManager)

Example 29 with RfToolsDimensionManager

use of mcjty.rftools.dimension.RfToolsDimensionManager in project RFTools 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(worldObj, xCoord, yCoord, zCoord, "Dimension cannot be deleted. It is still in use!", 10);
        return;
    }
    RfToolsDimensionManager dimensionManager = RfToolsDimensionManager.getDimensionManager(worldObj);
    DimensionInformation information = dimensionManager.getDimensionInformation(id);
    if (information.getOwner() == null) {
        Broadcaster.broadcast(worldObj, xCoord, yCoord, zCoord, "You cannot delete a dimension without an owner!", 10);
        return;
    }
    if (getOwnerUUID() == null) {
        Broadcaster.broadcast(worldObj, xCoord, yCoord, zCoord, "This machine has no proper owner and cannot delete dimensions!", 10);
        return;
    }
    if (!getOwnerUUID().equals(information.getOwner())) {
        Broadcaster.broadcast(worldObj, xCoord, yCoord, zCoord, "This machine's owner differs from the dimensions owner!", 10);
        return;
    }
    TeleportDestinations destinations = TeleportDestinations.getDestinations(worldObj);
    destinations.removeDestinationsInDimension(id);
    destinations.save(worldObj);
    dimensionManager.removeDimension(id);
    dimensionManager.reclaimId(id);
    dimensionManager.save(worldObj);
    DimensionStorage dimensionStorage = DimensionStorage.getDimensionStorage(worldObj);
    dimensionStorage.removeDimension(id);
    dimensionStorage.save(worldObj);
    if (DimletConfiguration.dimensionFolderIsDeletedWithSafeDel) {
        File rootDirectory = DimensionManager.getCurrentSaveRootDirectory();
        try {
            FileUtils.deleteDirectory(new File(rootDirectory.getPath() + File.separator + "DIM" + id));
            Broadcaster.broadcast(worldObj, xCoord, yCoord, zCoord, "Dimension deleted and dimension folder succesfully wiped!", 10);
        } catch (IOException e) {
            Broadcaster.broadcast(worldObj, xCoord, yCoord, zCoord, "Dimension deleted but dimension folder could not be completely wiped!", 10);
        }
    } else {
        Broadcaster.broadcast(worldObj, xCoord, yCoord, zCoord, "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.rftools.dimension.DimensionStorage) TeleportDestinations(mcjty.rftools.blocks.teleporter.TeleportDestinations) IOException(java.io.IOException) World(net.minecraft.world.World) DimensionInformation(mcjty.rftools.dimension.DimensionInformation) File(java.io.File) RfToolsDimensionManager(mcjty.rftools.dimension.RfToolsDimensionManager)

Example 30 with RfToolsDimensionManager

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

the class DimensionEditorTileEntity method checkStateServer.

@Override
protected void checkStateServer() {
    ItemStack injectableItemStack = validateInjectableItemStack();
    if (injectableItemStack == null) {
        return;
    }
    ItemStack dimensionItemStack = validateDimensionItemStack();
    if (dimensionItemStack == null) {
        return;
    }
    if (ticksLeft == -1) {
        // We were not injecting. Start now.
        if (isMatterReceiver(injectableItemStack)) {
            ticksCost = DimletCosts.baseDimensionTickCost + 1000;
            ticksLeft = ticksCost;
            rfPerTick = DimletCosts.baseDimensionCreationCost + 200;
        } else if (isTNT(injectableItemStack)) {
            ticksCost = 600;
            ticksLeft = ticksCost;
            rfPerTick = 10;
        } else {
            DimletKey key = KnownDimletConfiguration.getDimletKey(injectableItemStack, worldObj);
            DimletEntry dimletEntry = KnownDimletConfiguration.getEntry(key);
            ticksCost = DimletCosts.baseDimensionTickCost + dimletEntry.getTickCost();
            ticksLeft = ticksCost;
            rfPerTick = DimletCosts.baseDimensionCreationCost + dimletEntry.getRfCreateCost();
        }
    } else {
        int rf = getEnergyStored(ForgeDirection.DOWN);
        int rfpt = rfPerTick;
        rfpt = (int) (rfpt * (2.0f - getInfusedFactor()) / 2.0f);
        if (rf >= rfpt) {
            // Enough energy.
            consumeEnergy(rfpt);
            ticksLeft--;
            if (ticksLeft <= 0) {
                RfToolsDimensionManager dimensionManager = RfToolsDimensionManager.getDimensionManager(worldObj);
                ItemStack dimensionTab = validateDimensionItemStack();
                NBTTagCompound tagCompound = dimensionTab.getTagCompound();
                int id = tagCompound.getInteger("id");
                injectableItemStack = validateInjectableItemStack();
                if (isMatterReceiver(injectableItemStack)) {
                    World dimWorld = dimensionManager.getWorldForDimension(id);
                    int y = findGoodReceiverLocation(dimWorld);
                    if (y == -1) {
                        y = dimWorld.getHeight() / 2;
                    }
                    dimWorld.setBlock(8, y, 8, TeleporterSetup.matterReceiverBlock, 0, 2);
                    TeleporterSetup.matterReceiverBlock.onBlockPlaced(dimWorld, 8, y, 8, 0, 0, 0, 0, 0);
                    TeleporterSetup.matterReceiverBlock.onBlockPlacedBy(dimWorld, 8, y, 8, null, injectableItemStack);
                    dimWorld.setBlockToAir(8, y + 1, 8);
                    dimWorld.setBlockToAir(8, y + 2, 8);
                } else if (isTNT(injectableItemStack)) {
                    safeDeleteDimension(id, dimensionTab);
                } else {
                    DimletKey key = KnownDimletConfiguration.getDimletKey(injectableItemStack, worldObj);
                    DimensionInformation information = dimensionManager.getDimensionInformation(id);
                    information.injectDimlet(key);
                    dimensionManager.save(worldObj);
                }
                inventoryHelper.decrStackSize(DimensionEditorContainer.SLOT_INJECTINPUT, 1);
                stopInjecting();
            }
        }
    }
    markDirty();
    setState();
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack) World(net.minecraft.world.World) DimensionInformation(mcjty.rftools.dimension.DimensionInformation) RfToolsDimensionManager(mcjty.rftools.dimension.RfToolsDimensionManager)

Aggregations

RfToolsDimensionManager (mcjty.rftools.dimension.RfToolsDimensionManager)43 DimensionInformation (mcjty.rftools.dimension.DimensionInformation)29 World (net.minecraft.world.World)27 ChatComponentText (net.minecraft.util.ChatComponentText)16 DimensionStorage (mcjty.rftools.dimension.DimensionStorage)11 SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)9 EntityPlayer (net.minecraft.entity.player.EntityPlayer)6 DimensionDescriptor (mcjty.rftools.dimension.description.DimensionDescriptor)5 ItemStack (net.minecraft.item.ItemStack)5 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)5 File (java.io.File)3 Coordinate (mcjty.lib.varia.Coordinate)3 EffectType (mcjty.rftools.dimension.world.types.EffectType)3 IOException (java.io.IOException)2 Map (java.util.Map)2 GenericEnergyReceiverTileEntity (mcjty.lib.entity.GenericEnergyReceiverTileEntity)2 GlobalCoordinate (mcjty.lib.varia.GlobalCoordinate)2 TeleportDestinations (mcjty.rftools.blocks.teleporter.TeleportDestinations)2 IMob (net.minecraft.entity.monster.IMob)2 IAnimals (net.minecraft.entity.passive.IAnimals)2