Add tag based tooltip for devices that need reboot after being installed/removed. Closes #21.
This commit is contained in:
@@ -48,7 +48,8 @@ public final class Constants {
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
public static final String DESCRIPTION_SUFFIX = ".desc";
|
||||
public static final String TOOLTIP_DESCRIPTION_SUFFIX = ".desc";
|
||||
public static final String TOOLTIP_DEVICE_NEEDS_REBOOT = "tooltip.oc2.device_needs_reboot";
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
@@ -27,18 +27,21 @@ public final class Main {
|
||||
Ceres.initialize();
|
||||
Sedna.initialize();
|
||||
Serializers.initialize();
|
||||
|
||||
Config.initialize();
|
||||
|
||||
ItemTags.initialize();
|
||||
BlockTags.initialize();
|
||||
Items.initialize();
|
||||
Blocks.initialize();
|
||||
TileEntities.initialize();
|
||||
Entities.initialize();
|
||||
Containers.initialize();
|
||||
|
||||
Providers.initialize();
|
||||
DeviceTypes.initialize();
|
||||
BaseBlockDevices.initialize();
|
||||
Firmwares.initialize();
|
||||
BlockTags.initialize();
|
||||
ItemTags.initialize();
|
||||
|
||||
FMLJavaModLoadingContext.get().getModEventBus().register(CommonSetup.class);
|
||||
DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> FMLJavaModLoadingContext.get().getModEventBus().register(ClientSetup.class));
|
||||
|
||||
@@ -9,9 +9,13 @@ public final class BlockTags {
|
||||
public static final Tags.IOptionalNamedTag<Block> DEVICES = tag("devices");
|
||||
public static final Tags.IOptionalNamedTag<Block> CABLES = tag("cables");
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
public static void initialize() {
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
private static Tags.IOptionalNamedTag<Block> tag(final String name) {
|
||||
return net.minecraft.tags.BlockTags.createOptional(new ResourceLocation(API.MOD_ID, name));
|
||||
}
|
||||
|
||||
@@ -17,9 +17,15 @@ public final class ItemTags {
|
||||
|
||||
public static final Tags.IOptionalNamedTag<Item> WRENCHES = tag("wrenches");
|
||||
|
||||
public static final Tags.IOptionalNamedTag<Item> DEVICE_NEEDS_REBOOT = tag("device_needs_reboot");
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
public static void initialize() {
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
private static Tags.IOptionalNamedTag<Item> tag(final String name) {
|
||||
return net.minecraft.tags.ItemTags.createOptional(new ResourceLocation(API.MOD_ID, name));
|
||||
}
|
||||
|
||||
@@ -4,9 +4,12 @@ import it.unimi.dsi.fastutil.ints.IntArrayList;
|
||||
import it.unimi.dsi.fastutil.ints.IntList;
|
||||
import li.cil.oc2.api.bus.device.DeviceType;
|
||||
import li.cil.oc2.common.Constants;
|
||||
import li.cil.oc2.common.tags.ItemTags;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.nbt.ListNBT;
|
||||
import net.minecraft.tags.ITag;
|
||||
import net.minecraft.util.text.*;
|
||||
import net.minecraftforge.registries.ForgeRegistry;
|
||||
import net.minecraftforge.registries.RegistryManager;
|
||||
@@ -22,12 +25,25 @@ public final class TooltipUtils {
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
public static void tryAddDescription(final ItemStack stack, final List<ITextComponent> tooltip) {
|
||||
final String translationKey = stack.getTranslationKey() + Constants.DESCRIPTION_SUFFIX;
|
||||
if (stack.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
final String translationKey = stack.getTranslationKey() + Constants.TOOLTIP_DESCRIPTION_SUFFIX;
|
||||
final LanguageMap languagemap = LanguageMap.getInstance();
|
||||
if (languagemap.func_230506_b_(translationKey)) {
|
||||
final TranslationTextComponent description = new TranslationTextComponent(translationKey);
|
||||
tooltip.add(new StringTextComponent("").modifyStyle(s -> s.setColor(Color.fromTextFormatting(TextFormatting.GRAY))).append(description));
|
||||
}
|
||||
|
||||
// Tooltips get queried very early in Minecraft initialization, meaning tags may not
|
||||
// have been initialized. Trying to directly use our tag would lead to an exception
|
||||
// in that case, so we do the detour through the collection instead.
|
||||
final ITag<Item> tag = net.minecraft.tags.ItemTags.getCollection().get(ItemTags.DEVICE_NEEDS_REBOOT.getName());
|
||||
if (tag != null && tag.contains(stack.getItem())) {
|
||||
tooltip.add(new StringTextComponent("").modifyStyle(s -> s.setColor(Color.fromTextFormatting(TextFormatting.YELLOW)))
|
||||
.append(new TranslationTextComponent(Constants.TOOLTIP_DEVICE_NEEDS_REBOOT)));
|
||||
}
|
||||
}
|
||||
|
||||
public static void addTileEntityInventoryInformation(final ItemStack stack, final List<ITextComponent> tooltip) {
|
||||
|
||||
@@ -19,8 +19,9 @@ public final class ModItemTagsProvider extends ItemTagsProvider {
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
protected void registerTags() {
|
||||
copy(BlockTags.DEVICES, DEVICES);
|
||||
copy(BlockTags.CABLES, CABLES);
|
||||
|
||||
copy(BlockTags.DEVICES, DEVICES);
|
||||
getOrCreateBuilder(DEVICES).addTags(
|
||||
DEVICES_MEMORY,
|
||||
DEVICES_HARD_DRIVE,
|
||||
@@ -45,6 +46,14 @@ public final class ModItemTagsProvider extends ItemTagsProvider {
|
||||
Items.INVENTORY_OPERATIONS_MODULE.get(),
|
||||
Items.BLOCK_OPERATIONS_MODULE.get()
|
||||
);
|
||||
|
||||
getOrCreateBuilder(WRENCHES).add(Items.WRENCH_ITEM.get());
|
||||
|
||||
getOrCreateBuilder(DEVICE_NEEDS_REBOOT).add(
|
||||
Items.MEMORY_ITEM.get(),
|
||||
Items.HARD_DRIVE_ITEM.get(),
|
||||
Items.FLASH_MEMORY_ITEM.get(),
|
||||
Items.NETWORK_INTERFACE_CARD_ITEM.get()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,5 +55,7 @@
|
||||
|
||||
"message.oc2.connector.error.full": "Cannot attach more cables.",
|
||||
"message.oc2.connector.error.too_far": "Distance between connectors is too large.",
|
||||
"message.oc2.connector.error.obstructed": "No clear line of sight between connectors."
|
||||
"message.oc2.connector.error.obstructed": "No clear line of sight between connectors.",
|
||||
|
||||
"tooltip.oc2.device_needs_reboot": "Requires reboot"
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"replace": false,
|
||||
"values": [
|
||||
"oc2:memory",
|
||||
"oc2:hard_drive",
|
||||
"oc2:flash_memory",
|
||||
"oc2:network_interface_card"
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user