Search in sources :

Example 21 with DimensionInformation

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

the class BedControl method trySleep.

public static boolean trySleep(World world, EntityPlayer player, int x, int y, int z, int meta) {
    if (BlockBed.func_149976_c(meta)) {
        EntityPlayer entityplayer1 = null;
        for (Object playerEntity : world.playerEntities) {
            EntityPlayer entityplayer2 = (EntityPlayer) playerEntity;
            if (entityplayer2.isPlayerSleeping()) {
                ChunkCoordinates chunkcoordinates = entityplayer2.playerLocation;
                if (chunkcoordinates.posX == x && chunkcoordinates.posY == y && chunkcoordinates.posZ == z) {
                    entityplayer1 = entityplayer2;
                }
            }
        }
        if (entityplayer1 != null) {
            player.addChatComponentMessage(new ChatComponentTranslation("tile.bed.occupied"));
            return true;
        }
        BlockBed.func_149979_a(world, x, y, z, false);
    }
    EntityPlayer.EnumStatus enumstatus = player.sleepInBedAt(x, y, z);
    if (enumstatus == EntityPlayer.EnumStatus.OK) {
        BlockBed.func_149979_a(world, x, y, z, true);
        RfToolsDimensionManager manager = RfToolsDimensionManager.getDimensionManager(world);
        DimensionInformation information = manager.getDimensionInformation(world.provider.dimensionId);
        if (DimletConfiguration.respawnSameDim || (information != null && information.isRespawnHere())) {
            player.addChatComponentMessage(new ChatComponentText("Somehow this place feels more like home now."));
        }
        return true;
    } else {
        if (enumstatus == EntityPlayer.EnumStatus.NOT_POSSIBLE_NOW) {
            player.addChatComponentMessage(new ChatComponentTranslation("tile.bed.noSleep"));
        } else if (enumstatus == EntityPlayer.EnumStatus.NOT_SAFE) {
            player.addChatComponentMessage(new ChatComponentTranslation("tile.bed.notSafe"));
        }
        return true;
    }
}
Also used : ChatComponentTranslation(net.minecraft.util.ChatComponentTranslation) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ChunkCoordinates(net.minecraft.util.ChunkCoordinates) DimensionInformation(mcjty.rftools.dimension.DimensionInformation) ChatComponentText(net.minecraft.util.ChatComponentText) RfToolsDimensionManager(mcjty.rftools.dimension.RfToolsDimensionManager)

Example 22 with DimensionInformation

use of mcjty.rftools.dimension.DimensionInformation 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 23 with DimensionInformation

use of mcjty.rftools.dimension.DimensionInformation 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 24 with DimensionInformation

use of mcjty.rftools.dimension.DimensionInformation 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 25 with DimensionInformation

use of mcjty.rftools.dimension.DimensionInformation 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

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