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);
}
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);
}
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;
}
Aggregations