Search in sources :

Example 1 with MachineInformation

use of mcjty.lib.api.MachineInformation in project RFTools by McJty.

the class MachineInformationClientScreenModule method addOptionPanel.

private void addOptionPanel(Minecraft mc, Gui gui, final NBTTagCompound currentData, final IModuleGuiChanged moduleGuiChanged, Panel panel) {
    Panel optionPanel = new Panel(mc, gui).setLayout(new HorizontalLayout()).setDesiredHeight(16);
    final Map<String, Integer> choiceToIndex = new HashMap<>();
    final ChoiceLabel tagButton = new ChoiceLabel(mc, gui).setDesiredHeight(16).setDesiredWidth(80);
    optionPanel.addChild(tagButton);
    // int dim = currentData.getInteger("monitordim");
    int x = currentData.getInteger("monitorx");
    int y = currentData.getInteger("monitory");
    int z = currentData.getInteger("monitorz");
    TileEntity tileEntity = mc.world.getTileEntity(new BlockPos(x, y, z));
    if (tileEntity instanceof MachineInformation) {
        int current = currentData.getInteger("monitorTag");
        MachineInformation information = (MachineInformation) tileEntity;
        String currentTag = null;
        for (int i = 0; i < information.getTagCount(); i++) {
            String tag = information.getTagName(i);
            choiceToIndex.put(tag, i);
            tagButton.addChoices(tag);
            tagButton.setChoiceTooltip(tag, information.getTagDescription(i));
            if (current == i) {
                currentTag = tag;
            }
        }
        if (currentTag != null) {
            tagButton.setChoice(currentTag);
        }
    }
    tagButton.addChoiceEvent((parent, newChoice) -> {
        String choice = tagButton.getCurrentChoice();
        Integer index = choiceToIndex.get(choice);
        if (index != null) {
            currentData.setInteger("monitorTag", index);
        }
        moduleGuiChanged.updateData();
    });
    panel.addChild(optionPanel);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) MachineInformation(mcjty.lib.api.MachineInformation) HashMap(java.util.HashMap) BlockPos(net.minecraft.util.math.BlockPos) IModuleDataString(mcjty.rftools.api.screens.data.IModuleDataString) HorizontalLayout(mcjty.lib.gui.layout.HorizontalLayout)

Example 2 with MachineInformation

use of mcjty.lib.api.MachineInformation in project RFTools by McJty.

the class MachineInformationScreenModule method getData.

@Override
public IModuleDataString getData(IScreenDataHelper helper, World worldObj, long millis) {
    World world = DimensionManager.getWorld(dim);
    if (world == null) {
        return null;
    }
    if (!RFToolsTools.chunkLoaded(world, coordinate)) {
        return null;
    }
    TileEntity te = world.getTileEntity(coordinate);
    if (!(te instanceof MachineInformation)) {
        return null;
    }
    MachineInformation information = (MachineInformation) te;
    String info;
    if (tag < 0 || tag >= information.getTagCount()) {
        info = "[BAD TAG]";
    } else {
        info = information.getData(tag, millis);
    }
    return helper.createString(info);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) MachineInformation(mcjty.lib.api.MachineInformation) IModuleDataString(mcjty.rftools.api.screens.data.IModuleDataString) World(net.minecraft.world.World)

Example 3 with MachineInformation

use of mcjty.lib.api.MachineInformation in project RFTools by McJty.

the class MachineInformationModuleItem method onItemUse.

@Override
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    ItemStack stack = player.getHeldItem(hand);
    TileEntity te = world.getTileEntity(pos);
    NBTTagCompound tagCompound = stack.getTagCompound();
    if (tagCompound == null) {
        tagCompound = new NBTTagCompound();
    }
    if (te instanceof MachineInformation) {
        tagCompound.setInteger("monitordim", world.provider.getDimension());
        tagCompound.setInteger("monitorx", pos.getX());
        tagCompound.setInteger("monitory", pos.getY());
        tagCompound.setInteger("monitorz", pos.getZ());
        IBlockState state = player.getEntityWorld().getBlockState(pos);
        Block block = state.getBlock();
        String name = "<invalid>";
        if (block != null && !block.isAir(state, world, pos)) {
            name = BlockTools.getReadableName(world, pos);
        }
        tagCompound.setString("monitorname", name);
        if (world.isRemote) {
            Logging.message(player, "Machine Information module is set to block '" + name + "'");
        }
    } else {
        tagCompound.removeTag("monitordim");
        tagCompound.removeTag("monitorx");
        tagCompound.removeTag("monitory");
        tagCompound.removeTag("monitorz");
        tagCompound.removeTag("monitorname");
        if (world.isRemote) {
            Logging.message(player, "Machine Information module is cleared");
        }
    }
    stack.setTagCompound(tagCompound);
    return EnumActionResult.SUCCESS;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) MachineInformation(mcjty.lib.api.MachineInformation) IBlockState(net.minecraft.block.state.IBlockState) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Block(net.minecraft.block.Block) ItemStack(net.minecraft.item.ItemStack)

Aggregations

MachineInformation (mcjty.lib.api.MachineInformation)3 TileEntity (net.minecraft.tileentity.TileEntity)3 IModuleDataString (mcjty.rftools.api.screens.data.IModuleDataString)2 HashMap (java.util.HashMap)1 HorizontalLayout (mcjty.lib.gui.layout.HorizontalLayout)1 Block (net.minecraft.block.Block)1 IBlockState (net.minecraft.block.state.IBlockState)1 ItemStack (net.minecraft.item.ItemStack)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 BlockPos (net.minecraft.util.math.BlockPos)1 World (net.minecraft.world.World)1