Search in sources :

Example 1 with RfToolsDimensionManager

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

the class RealizedDimensionTab method clOnItemRightClick.

@Override
protected ActionResult<ItemStack> clOnItemRightClick(World world, EntityPlayer player, EnumHand hand) {
    ItemStack stack = player.getHeldItem(hand);
    if ((!world.isRemote) && player.isSneaking()) {
        NBTTagCompound tagCompound = stack.getTagCompound();
        Logging.message(player, tagCompound.getString("descriptionString"));
        int id = tagCompound.getInteger("id");
        if (id != 0) {
            RfToolsDimensionManager dimensionManager = RfToolsDimensionManager.getDimensionManager(world);
            DimensionInformation information = dimensionManager.getDimensionInformation(id);
            if (information != null) {
                information.dump(player);
            }
        }
    }
    return new ActionResult<>(EnumActionResult.SUCCESS, stack);
}
Also used : ActionResult(net.minecraft.util.ActionResult) EnumActionResult(net.minecraft.util.EnumActionResult) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack) DimensionInformation(mcjty.rftoolsdim.dimensions.DimensionInformation) RfToolsDimensionManager(mcjty.rftoolsdim.dimensions.RfToolsDimensionManager)

Example 2 with RfToolsDimensionManager

use of mcjty.rftoolsdim.dimensions.RfToolsDimensionManager 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 3 with RfToolsDimensionManager

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

the class DimensionEditorTileEntity method update.

@Override
public void update() {
    if (getWorld().isRemote) {
        return;
    }
    ItemStack injectableItemStack = validateInjectableItemStack();
    if (injectableItemStack.isEmpty()) {
        return;
    }
    ItemStack dimensionItemStack = validateDimensionItemStack();
    if (dimensionItemStack.isEmpty()) {
        return;
    }
    if (ticksLeft == -1) {
        // We were not injecting. Start now.
        RfToolsDimensionManager dimensionManager = RfToolsDimensionManager.getDimensionManager(getWorld());
        int id = dimensionItemStack.getTagCompound().getInteger("id");
        if (dimensionManager.getDimensionInformation(id).isCheater()) {
            ticksCost = 1;
            rfPerTick = 0;
        } else if (isMatterReceiver(injectableItemStack)) {
            ticksCost = DimletCosts.baseDimensionTickCost + 1000;
            rfPerTick = DimletCosts.baseDimensionCreationCost + 200;
        } else if (isTNT(injectableItemStack)) {
            ticksCost = 600;
            rfPerTick = 10;
        } else {
            DimletKey key = KnownDimletConfiguration.getDimletKey(injectableItemStack);
            Settings settings = KnownDimletConfiguration.getSettings(key);
            if (DimletObjectMapping.getSpecial(key) == SpecialType.SPECIAL_CHEATER) {
                ticksCost = 1;
                rfPerTick = 0;
            } else {
                ticksCost = DimletCosts.baseDimensionTickCost + settings.getTickCost();
                rfPerTick = DimletCosts.baseDimensionCreationCost + settings.getCreateCost();
            }
        }
        ticksLeft = ticksCost;
    } else {
        int rf = getEnergyStored();
        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(getWorld());
                NBTTagCompound tagCompound = dimensionItemStack.getTagCompound();
                int id = tagCompound.getInteger("id");
                if (isMatterReceiver(injectableItemStack)) {
                    World dimWorld = RfToolsDimensionManager.getWorldForDimension(getWorld(), id);
                    int y = findGoodReceiverLocation(dimWorld);
                    if (y == -1) {
                        y = dimWorld.getHeight() / 2;
                    }
                    Item item = injectableItemStack.getItem();
                    if (item instanceof ItemBlock) {
                        ItemBlock itemBlock = (ItemBlock) item;
                        IBlockState state = itemBlock.getBlock().getStateFromMeta(itemBlock.getMetadata(injectableItemStack));
                        BlockPos pos = new BlockPos(8, y, 8);
                        dimWorld.setBlockState(pos, state, 2);
                        Block block = dimWorld.getBlockState(pos).getBlock();
                        // @todo @@@@@@@@@@@@@@ check if right?
                        block.onBlockActivated(dimWorld, pos, state, FakePlayerFactory.getMinecraft((WorldServer) dimWorld), EnumHand.MAIN_HAND, EnumFacing.DOWN, 0.0F, 0.0F, 0.0F);
                        // block.onBlockPlaced(dimWorld, pos, EnumFacing.DOWN, 0, 0, 0, 0, null);
                        block.onBlockPlacedBy(dimWorld, pos, state, null, injectableItemStack);
                        dimWorld.setBlockToAir(pos.up());
                        dimWorld.setBlockToAir(pos.up(2));
                    }
                } else if (isTNT(injectableItemStack)) {
                    safeDeleteDimension(id, dimensionItemStack);
                } else {
                    DimletKey key = KnownDimletConfiguration.getDimletKey(injectableItemStack);
                    DimensionInformation information = dimensionManager.getDimensionInformation(id);
                    information.injectDimlet(key);
                    dimensionManager.save(getWorld());
                }
                inventoryHelper.decrStackSize(DimensionEditorContainer.SLOT_INJECTINPUT, 1);
                stopInjecting();
            }
        }
    }
    markDirty();
    setState();
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) WorldServer(net.minecraft.world.WorldServer) DimletKey(mcjty.rftoolsdim.dimensions.dimlets.DimletKey) World(net.minecraft.world.World) ItemBlock(net.minecraft.item.ItemBlock) RfToolsDimensionManager(mcjty.rftoolsdim.dimensions.RfToolsDimensionManager) Item(net.minecraft.item.Item) Block(net.minecraft.block.Block) ItemBlock(net.minecraft.item.ItemBlock) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) DimensionInformation(mcjty.rftoolsdim.dimensions.DimensionInformation) Settings(mcjty.rftoolsdim.config.Settings)

Example 4 with RfToolsDimensionManager

use of mcjty.rftoolsdim.dimensions.RfToolsDimensionManager 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 5 with RfToolsDimensionManager

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

the class ActivityProbeBlock method getStateForPlacement.

@Override
public IBlockState getStateForPlacement(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer) {
    IBlockState state = super.getStateForPlacement(world, pos, facing, hitX, hitY, hitZ, meta, placer);
    if (!world.isRemote) {
        RfToolsDimensionManager dimensionManager = RfToolsDimensionManager.getDimensionManager(world);
        DimensionInformation information = dimensionManager.getDimensionInformation(world.provider.getDimension());
        if (information != null) {
            information.addProbe();
        }
        dimensionManager.save(world);
    }
    return state;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) DimensionInformation(mcjty.rftoolsdim.dimensions.DimensionInformation) RfToolsDimensionManager(mcjty.rftoolsdim.dimensions.RfToolsDimensionManager)

Aggregations

RfToolsDimensionManager (mcjty.rftoolsdim.dimensions.RfToolsDimensionManager)41 DimensionInformation (mcjty.rftoolsdim.dimensions.DimensionInformation)29 World (net.minecraft.world.World)13 DimensionStorage (mcjty.rftoolsdim.dimensions.DimensionStorage)11 ItemStack (net.minecraft.item.ItemStack)10 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)8 ChatComponentText (net.minecraft.util.ChatComponentText)7 IBlockState (net.minecraft.block.state.IBlockState)6 EntityPlayer (net.minecraft.entity.player.EntityPlayer)5 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)5 DimensionDescriptor (mcjty.rftoolsdim.dimensions.description.DimensionDescriptor)4 ActionResult (net.minecraft.util.ActionResult)4 EnumActionResult (net.minecraft.util.EnumActionResult)4 PacketGetDimensionEnergy (mcjty.rftoolsdim.network.PacketGetDimensionEnergy)3 Block (net.minecraft.block.Block)3 BlockPos (net.minecraft.util.BlockPos)3 File (java.io.File)2 IOException (java.io.IOException)2 DimletKey (mcjty.rftoolsdim.dimensions.dimlets.DimletKey)2 IMob (net.minecraft.entity.monster.IMob)2