From 4af0959cc3f9412559f24584b7ec832293f5f4e7 Mon Sep 17 00:00:00 2001 From: deirn Date: Sat, 20 Jul 2024 01:26:34 +0700 Subject: [PATCH] check all nullables closes #273 (cherry picked from commit 66102f2929e44265d63953815e67e46ca55f2d50) --- .../mcp/mobius/waila/forge/ForgeApiService.java | 1 + .../mobius/waila/forge/ForgePluginLoader.java | 2 +- .../java/mcp/mobius/waila/neo/NeoApiService.java | 1 + .../neo/provider/EnergyCapabilityProvider.java | 1 + .../neo/provider/FluidCapabilityProvider.java | 1 + .../neo/provider/ItemCapabilityProvider.java | 1 + .../mcp/mobius/waila/access/ClientAccessor.java | 9 +++++---- .../mcp/mobius/waila/config/ConfigEntry.java | 4 ++-- .../mcp/mobius/waila/config/PluginConfig.java | 1 + .../mobius/waila/gui/hud/ComponentHandler.java | 16 ++++++++-------- .../mcp/mobius/waila/gui/hud/TooltipHandler.java | 2 ++ .../mobius/waila/gui/hud/TooltipRenderer.java | 1 + .../waila/gui/hud/theme/ThemeDefinition.java | 3 ++- .../mobius/waila/gui/hud/theme/ThemeType.java | 2 +- .../mobius/waila/gui/screen/CreditsScreen.java | 2 +- .../mcp/mobius/waila/gui/screen/HomeScreen.java | 5 +++-- .../waila/gui/screen/PluginToggleScreen.java | 2 +- .../waila/gui/screen/ThemeEditorScreen.java | 1 + .../waila/gui/screen/WailaConfigScreen.java | 2 +- .../waila/gui/widget/ConfigListWidget.java | 4 +++- .../waila/gui/widget/value/ConfigValue.java | 6 ++++-- .../waila/gui/widget/value/InputValue.java | 1 + .../mobius/waila/registry/InstanceRegistry.java | 3 ++- .../mcp/mobius/waila/registry/Registrar.java | 2 ++ .../mcp/mobius/waila/util/CachedSupplier.java | 4 +++- .../mcp/mobius/waila/util/ExceptionUtil.java | 3 ++- .../waila/plugin/extra/data/FluidDataImpl.java | 1 + .../plugin/extra/provider/DataProvider.java | 3 ++- .../plugin/vanilla/provider/BoatProvider.java | 4 +++- .../plugin/vanilla/provider/FurnaceProvider.java | 4 ++-- .../plugin/vanilla/provider/HorseProvider.java | 2 +- .../vanilla/provider/InfestedBlockProvider.java | 3 ++- .../vanilla/provider/PetOwnerProvider.java | 1 + .../plugin/vanilla/provider/SpawnerProvider.java | 5 ++++- .../vanilla/provider/TrappedChestProvider.java | 3 ++- 35 files changed, 70 insertions(+), 36 deletions(-) diff --git a/platform/forge/src/main/java/mcp/mobius/waila/forge/ForgeApiService.java b/platform/forge/src/main/java/mcp/mobius/waila/forge/ForgeApiService.java index 744ab64c5..34b9ef14a 100644 --- a/platform/forge/src/main/java/mcp/mobius/waila/forge/ForgeApiService.java +++ b/platform/forge/src/main/java/mcp/mobius/waila/forge/ForgeApiService.java @@ -15,6 +15,7 @@ public class ForgeApiService extends ApiService { @Override + @SuppressWarnings("DataFlowIssue") public IModInfo getModInfo(ItemStack stack) { return ModInfo.get(stack.getItem().getCreatorModId(stack)); } diff --git a/platform/forge/src/main/java/mcp/mobius/waila/forge/ForgePluginLoader.java b/platform/forge/src/main/java/mcp/mobius/waila/forge/ForgePluginLoader.java index bf8709cf1..c4c5e720d 100644 --- a/platform/forge/src/main/java/mcp/mobius/waila/forge/ForgePluginLoader.java +++ b/platform/forge/src/main/java/mcp/mobius/waila/forge/ForgePluginLoader.java @@ -34,7 +34,7 @@ protected void gatherPlugins() { var satisfied = true; for (var dep : required) { - satisfied &= ModList.get().isLoaded(dep); + satisfied = satisfied && ModList.get().isLoaded(dep); } if (side == IPluginInfo.Side.CLIENT && FMLLoader.getDist() != Dist.CLIENT) { diff --git a/platform/neo/src/main/java/mcp/mobius/waila/neo/NeoApiService.java b/platform/neo/src/main/java/mcp/mobius/waila/neo/NeoApiService.java index ea885da93..c6ad04f5f 100644 --- a/platform/neo/src/main/java/mcp/mobius/waila/neo/NeoApiService.java +++ b/platform/neo/src/main/java/mcp/mobius/waila/neo/NeoApiService.java @@ -15,6 +15,7 @@ public class NeoApiService extends ApiService { @Override + @SuppressWarnings("DataFlowIssue") public IModInfo getModInfo(ItemStack stack) { return ModInfo.get(stack.getItem().getCreatorModId(stack)); } diff --git a/platform/neo/src/plugin/java/mcp/mobius/waila/plugin/neo/provider/EnergyCapabilityProvider.java b/platform/neo/src/plugin/java/mcp/mobius/waila/plugin/neo/provider/EnergyCapabilityProvider.java index ce04d83b4..a4c5827d1 100644 --- a/platform/neo/src/plugin/java/mcp/mobius/waila/plugin/neo/provider/EnergyCapabilityProvider.java +++ b/platform/neo/src/plugin/java/mcp/mobius/waila/plugin/neo/provider/EnergyCapabilityProvider.java @@ -28,6 +28,7 @@ public void appendData(IDataWriter data, IServerAccessor accessor, var pos = target.getBlockPos(); if (cache == null || (cache.level() != world && !cache.pos().equals(pos))) { + //noinspection DataFlowIssue cache = BlockCapabilityCache.create(Capabilities.EnergyStorage.BLOCK, world, pos, null); } diff --git a/platform/neo/src/plugin/java/mcp/mobius/waila/plugin/neo/provider/FluidCapabilityProvider.java b/platform/neo/src/plugin/java/mcp/mobius/waila/plugin/neo/provider/FluidCapabilityProvider.java index 5878950c6..492e686ac 100644 --- a/platform/neo/src/plugin/java/mcp/mobius/waila/plugin/neo/provider/FluidCapabilityProvider.java +++ b/platform/neo/src/plugin/java/mcp/mobius/waila/plugin/neo/provider/FluidCapabilityProvider.java @@ -29,6 +29,7 @@ public void appendData(IDataWriter data, IServerAccessor accessor, var pos = target.getBlockPos(); if (cache == null || (cache.level() != world && !cache.pos().equals(pos))) { + //noinspection DataFlowIssue cache = BlockCapabilityCache.create(Capabilities.FluidHandler.BLOCK, world, pos, null); } diff --git a/platform/neo/src/plugin/java/mcp/mobius/waila/plugin/neo/provider/ItemCapabilityProvider.java b/platform/neo/src/plugin/java/mcp/mobius/waila/plugin/neo/provider/ItemCapabilityProvider.java index 65a81f3cd..996ed1e29 100644 --- a/platform/neo/src/plugin/java/mcp/mobius/waila/plugin/neo/provider/ItemCapabilityProvider.java +++ b/platform/neo/src/plugin/java/mcp/mobius/waila/plugin/neo/provider/ItemCapabilityProvider.java @@ -28,6 +28,7 @@ public void appendData(IDataWriter data, IServerAccessor accessor, var pos = target.getBlockPos(); if (cache == null || (cache.level() != world && !cache.pos().equals(pos))) { + //noinspection DataFlowIssue cache = BlockCapabilityCache.create(Capabilities.ItemHandler.BLOCK, world, pos, null); } diff --git a/src/main/java/mcp/mobius/waila/access/ClientAccessor.java b/src/main/java/mcp/mobius/waila/access/ClientAccessor.java index 6114d01af..1542ab9f1 100644 --- a/src/main/java/mcp/mobius/waila/access/ClientAccessor.java +++ b/src/main/java/mcp/mobius/waila/access/ClientAccessor.java @@ -21,6 +21,7 @@ import net.minecraft.world.phys.EntityHitResult; import net.minecraft.world.phys.HitResult; import net.minecraft.world.phys.Vec3; +import org.jetbrains.annotations.Nullable; public enum ClientAccessor implements ICommonAccessor, IBlockAccessor, IEntityAccessor { @@ -34,8 +35,8 @@ public enum ClientAccessor implements ICommonAccessor, IBlockAccessor, IEntityAc private BlockState state = Blocks.AIR.defaultBlockState(); private BlockPos pos = BlockPos.ZERO; private ResourceLocation blockRegistryName = BuiltInRegistries.ITEM.getDefaultKey(); - private BlockEntity blockEntity; - private Entity entity; + private @Nullable BlockEntity blockEntity; + private @Nullable Entity entity; private long timeLastUpdate = System.currentTimeMillis(); private ItemStack stack = ItemStack.EMPTY; private int updateId; @@ -77,7 +78,7 @@ public T getEntity() { return (T) this.entity; } - public void setEntity(Entity entity) { + public void setEntity(@Nullable Entity entity) { this.entity = entity; } @@ -138,7 +139,7 @@ public double getPartialFrame() { } @Override - public Direction getSide() { + public @Nullable Direction getSide() { return hitResult == null ? null : hitResult.getType() == HitResult.Type.ENTITY ? null : ((BlockHitResult) hitResult).getDirection(); } diff --git a/src/main/java/mcp/mobius/waila/config/ConfigEntry.java b/src/main/java/mcp/mobius/waila/config/ConfigEntry.java index e9884f7a9..2d9a82767 100644 --- a/src/main/java/mcp/mobius/waila/config/ConfigEntry.java +++ b/src/main/java/mcp/mobius/waila/config/ConfigEntry.java @@ -30,7 +30,7 @@ public class ConfigEntry { private final Type type; - private T serverValue; + private @Nullable T serverValue; private T localValue; private ConfigEntry(IPluginInfo origin, ResourceLocation id, T defaultValue, T clientOnlyValue, boolean serverRequired, boolean merged, Type type) { @@ -72,7 +72,7 @@ public T getLocalValue() { return localValue; } - public T getServerValue() { + public @Nullable T getServerValue() { return serverValue; } diff --git a/src/main/java/mcp/mobius/waila/config/PluginConfig.java b/src/main/java/mcp/mobius/waila/config/PluginConfig.java index bfcc02dd3..ca600e248 100644 --- a/src/main/java/mcp/mobius/waila/config/PluginConfig.java +++ b/src/main/java/mcp/mobius/waila/config/PluginConfig.java @@ -156,6 +156,7 @@ public String getString(ResourceLocation key) { } @Override + @SuppressWarnings("DataFlowIssue") public > T getEnum(ResourceLocation key) { return getValue(key, null); } diff --git a/src/main/java/mcp/mobius/waila/gui/hud/ComponentHandler.java b/src/main/java/mcp/mobius/waila/gui/hud/ComponentHandler.java index 41489fe00..3cab1c2c6 100644 --- a/src/main/java/mcp/mobius/waila/gui/hud/ComponentHandler.java +++ b/src/main/java/mcp/mobius/waila/gui/hud/ComponentHandler.java @@ -1,5 +1,7 @@ package mcp.mobius.waila.gui.hud; +import java.util.Objects; + import lol.bai.badpackets.api.PacketSender; import mcp.mobius.waila.Waila; import mcp.mobius.waila.access.ClientAccessor; @@ -16,11 +18,11 @@ import mcp.mobius.waila.util.ExceptionUtil; import net.minecraft.client.Minecraft; import net.minecraft.world.entity.Entity; -import net.minecraft.world.level.Level; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.EntityHitResult; import net.minecraft.world.phys.HitResult; +import org.jetbrains.annotations.Nullable; public class ComponentHandler { @@ -37,7 +39,7 @@ public static void requestBlockData(ClientAccessor accessor) { accessor.resetTimer(); accessor.setDataAccess(false); DataWriter.CLIENT.reset(); - var player = Minecraft.getInstance().player; + var player = accessor.getPlayer(); for (var entry : registrar.blockDataCtx.get(block)) { DataWriter.CLIENT.tryAppend(player, entry.instance(), accessor, PluginConfig.CLIENT, IBlockComponentProvider::appendDataContext); @@ -57,7 +59,7 @@ public static void gatherBlock(ClientAccessor accessor, Tooltip tooltip, Tooltip var blockEntity = accessor.getBlockEntity(); handleBlock(accessor, tooltip, block, position); - handleBlock(accessor, tooltip, blockEntity, position); + if (blockEntity != null) handleBlock(accessor, tooltip, blockEntity, position); } @SuppressWarnings("DuplicatedCode") @@ -90,7 +92,7 @@ public static void requestEntityData(Entity entity, ClientAccessor accessor) { accessor.resetTimer(); accessor.setDataAccess(false); DataWriter.CLIENT.reset(); - var player = Minecraft.getInstance().player; + var player = accessor.getPlayer(); for (var entry : registrar.entityDataCtx.get(entity)) { DataWriter.CLIENT.tryAppend(player, entry.instance(), accessor, PluginConfig.CLIENT, IEntityComponentProvider::appendDataContext); @@ -168,7 +170,7 @@ public static ITooltipComponent getIcon(HitResult target) { return EmptyComponent.INSTANCE; } - public static Entity getOverrideEntity(HitResult target) { + public static @Nullable Entity getOverrideEntity(HitResult target) { if (target == null || target.getType() != HitResult.Type.ENTITY) { return null; } @@ -190,9 +192,7 @@ public static Entity getOverrideEntity(HitResult target) { public static BlockState getOverrideBlock(HitResult target) { var registrar = Registrar.get(); - Level world = Minecraft.getInstance().level; - if (world == null) return null; - + var world = Objects.requireNonNull(Minecraft.getInstance().level); var pos = ((BlockHitResult) target).getBlockPos(); final var state = world.getBlockState(pos); diff --git a/src/main/java/mcp/mobius/waila/gui/hud/TooltipHandler.java b/src/main/java/mcp/mobius/waila/gui/hud/TooltipHandler.java index 34504fc4b..c225139a0 100644 --- a/src/main/java/mcp/mobius/waila/gui/hud/TooltipHandler.java +++ b/src/main/java/mcp/mobius/waila/gui/hud/TooltipHandler.java @@ -112,6 +112,8 @@ private static ProcessResult redirectTarget(HitResult target, TargetRedirector r private static ProcessResult processTarget(HitResult target, Minecraft client, Player player, Vec3 castOrigin, Vec3 castDirection, float pickRange, WailaConfig.General config) { var accessor = ClientAccessor.INSTANCE; + + //noinspection DataFlowIssue accessor.set(client.level, player, target, client.cameraEntity, castOrigin, castDirection, pickRange, client.getFrameTime()); TooltipRenderer.beginBuild(STATE); diff --git a/src/main/java/mcp/mobius/waila/gui/hud/TooltipRenderer.java b/src/main/java/mcp/mobius/waila/gui/hud/TooltipRenderer.java index 8b8588b49..8ae63dd98 100644 --- a/src/main/java/mcp/mobius/waila/gui/hud/TooltipRenderer.java +++ b/src/main/java/mcp/mobius/waila/gui/hud/TooltipRenderer.java @@ -176,6 +176,7 @@ public static Rectangle endBuild() { return RECT.get(); } + @SuppressWarnings("DataFlowIssue") public static void resetState() { state = null; } diff --git a/src/main/java/mcp/mobius/waila/gui/hud/theme/ThemeDefinition.java b/src/main/java/mcp/mobius/waila/gui/hud/theme/ThemeDefinition.java index cb87a3b01..ec6e5c613 100644 --- a/src/main/java/mcp/mobius/waila/gui/hud/theme/ThemeDefinition.java +++ b/src/main/java/mcp/mobius/waila/gui/hud/theme/ThemeDefinition.java @@ -18,10 +18,11 @@ import mcp.mobius.waila.registry.Registrar; import mcp.mobius.waila.util.TypeUtil; import net.minecraft.resources.ResourceLocation; +import org.jetbrains.annotations.Nullable; public final class ThemeDefinition { - private static Map> all; + private static @Nullable Map> all; public final ResourceLocation id; public final ThemeType type; diff --git a/src/main/java/mcp/mobius/waila/gui/hud/theme/ThemeType.java b/src/main/java/mcp/mobius/waila/gui/hud/theme/ThemeType.java index eef6e8f63..4bc4faf29 100644 --- a/src/main/java/mcp/mobius/waila/gui/hud/theme/ThemeType.java +++ b/src/main/java/mcp/mobius/waila/gui/hud/theme/ThemeType.java @@ -54,7 +54,7 @@ public ResourceLocation getId() { return Objects.requireNonNull(Registrar.get().themeTypes.inverse().get(this)); } - private ThemeType property(String name, Class type, V exampleValue, C context) { + private ThemeType property(String name, Class type, V exampleValue, @Nullable C context) { Preconditions.checkState(!built); Preconditions.checkArgument(!INVALID_NAMES.contains(name), INVALID_NAME_ERROR_MSG); properties.put(name, new Property<>(name, type, exampleValue, context)); diff --git a/src/main/java/mcp/mobius/waila/gui/screen/CreditsScreen.java b/src/main/java/mcp/mobius/waila/gui/screen/CreditsScreen.java index fd9e006f8..e4b768812 100644 --- a/src/main/java/mcp/mobius/waila/gui/screen/CreditsScreen.java +++ b/src/main/java/mcp/mobius/waila/gui/screen/CreditsScreen.java @@ -38,7 +38,7 @@ protected void init() { super.init(); try { - var credits = new Gson().fromJson(minecraft.getResourceManager().getResource(Waila.id("credits.json")).get().openAsReader(), CreditMap.class); + var credits = new Gson().fromJson(minecraft.getResourceManager().getResource(Waila.id("credits.json")).orElseThrow().openAsReader(), CreditMap.class); var listWidget = new ListWidget(minecraft, width, height - 64, 32, minecraft.font.lineHeight + 6); credits.forEach((key, category) -> { diff --git a/src/main/java/mcp/mobius/waila/gui/screen/HomeScreen.java b/src/main/java/mcp/mobius/waila/gui/screen/HomeScreen.java index 985785e52..184b57c22 100644 --- a/src/main/java/mcp/mobius/waila/gui/screen/HomeScreen.java +++ b/src/main/java/mcp/mobius/waila/gui/screen/HomeScreen.java @@ -7,14 +7,15 @@ import net.minecraft.network.chat.CommonComponents; import net.minecraft.network.chat.Component; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import static mcp.mobius.waila.util.DisplayUtil.createButton; public class HomeScreen extends YesIAmSureTheClientInstanceIsPresentByTheTimeIUseItScreen { - private final Screen parent; + private final @Nullable Screen parent; - public HomeScreen(Screen parent) { + public HomeScreen(@Nullable Screen parent) { super(Component.literal(WailaConstants.MOD_NAME)); this.parent = parent; diff --git a/src/main/java/mcp/mobius/waila/gui/screen/PluginToggleScreen.java b/src/main/java/mcp/mobius/waila/gui/screen/PluginToggleScreen.java index b188e1686..99573aaa8 100644 --- a/src/main/java/mcp/mobius/waila/gui/screen/PluginToggleScreen.java +++ b/src/main/java/mcp/mobius/waila/gui/screen/PluginToggleScreen.java @@ -69,7 +69,7 @@ public ConfigListWidget getOptions() { initialValues.put(id, enabled); updatedValues.put(id, enabled); - var toggle = new BooleanValue(null, enabled, null, val -> updatedValues.put(id, val.booleanValue())) { + var toggle = new BooleanValue("", enabled, null, val -> updatedValues.put(id, val.booleanValue())) { @Override public MutableComponent getTitle() { return Component.literal(plugin.getPluginId().toString()); diff --git a/src/main/java/mcp/mobius/waila/gui/screen/ThemeEditorScreen.java b/src/main/java/mcp/mobius/waila/gui/screen/ThemeEditorScreen.java index 112a9e183..a8efca3ed 100644 --- a/src/main/java/mcp/mobius/waila/gui/screen/ThemeEditorScreen.java +++ b/src/main/java/mcp/mobius/waila/gui/screen/ThemeEditorScreen.java @@ -153,6 +153,7 @@ private void addTypeProperties(ConfigListWidget options) { ConfigValue value; if (propType == int.class) { + //noinspection DataFlowIssue value = new IntInputValue(prop.getTlKey(), TypeUtil.uncheckedCast(templateValue), null, val -> attr.put(key, val), TypeUtil.uncheckedCast(prop.context)); } else if (propType == boolean.class) { value = new BooleanValue(prop.getTlKey(), TypeUtil.uncheckedCast(templateValue), null, val -> attr.put(key, val)); diff --git a/src/main/java/mcp/mobius/waila/gui/screen/WailaConfigScreen.java b/src/main/java/mcp/mobius/waila/gui/screen/WailaConfigScreen.java index 841e8290f..9bf5b6f0b 100644 --- a/src/main/java/mcp/mobius/waila/gui/screen/WailaConfigScreen.java +++ b/src/main/java/mcp/mobius/waila/gui/screen/WailaConfigScreen.java @@ -68,7 +68,7 @@ public class WailaConfigScreen extends ConfigScreen { private ThemeValue themeIdVal; - private KeyBindValue selectedKeyBind; + private @Nullable KeyBindValue selectedKeyBind; public WailaConfigScreen(Screen parent) { super(parent, Component.translatable(Tl.Gui.CONFIGURATION, WailaConstants.MOD_NAME), Waila.CONFIG::save, Waila.CONFIG::invalidate); diff --git a/src/main/java/mcp/mobius/waila/gui/widget/ConfigListWidget.java b/src/main/java/mcp/mobius/waila/gui/widget/ConfigListWidget.java index 1e689659e..357f54de4 100644 --- a/src/main/java/mcp/mobius/waila/gui/widget/ConfigListWidget.java +++ b/src/main/java/mcp/mobius/waila/gui/widget/ConfigListWidget.java @@ -32,7 +32,9 @@ public class ConfigListWidget extends ContainerObjectSelectionList implements IInstanceRegistry { @@ -29,7 +30,7 @@ public void add(Class key, T instance, int priority) { } @Override - public List> get(Object target) { + public List> get(@Nullable Object target) { if (target == null) { return ObjectLists.emptyList(); } diff --git a/src/main/java/mcp/mobius/waila/registry/Registrar.java b/src/main/java/mcp/mobius/waila/registry/Registrar.java index 4a7603da7..87acf292f 100644 --- a/src/main/java/mcp/mobius/waila/registry/Registrar.java +++ b/src/main/java/mcp/mobius/waila/registry/Registrar.java @@ -107,6 +107,7 @@ public void attach(@Nullable IPluginInfo plugin) { this.plugin = plugin; } + @SuppressWarnings("DataFlowIssue") private void addConfig(ResourceLocation key, T defaultValue, T clientOnlyValue, boolean serverRequired, boolean merged, ConfigEntry.Type type) { assertLock(); PluginConfig.addConfig(type.create(plugin, key, defaultValue, clientOnlyValue, serverRequired, merged)); @@ -455,6 +456,7 @@ private void assertPlugin() { Preconditions.checkNotNull(plugin, "Tried to register things outside the register method"); } + @SuppressWarnings("DataFlowIssue") private boolean skip() { assertPlugin(); return !plugin.isEnabled(); diff --git a/src/main/java/mcp/mobius/waila/util/CachedSupplier.java b/src/main/java/mcp/mobius/waila/util/CachedSupplier.java index f137a5d27..19a27468e 100644 --- a/src/main/java/mcp/mobius/waila/util/CachedSupplier.java +++ b/src/main/java/mcp/mobius/waila/util/CachedSupplier.java @@ -2,10 +2,12 @@ import java.util.function.Supplier; +import org.jetbrains.annotations.Nullable; + public class CachedSupplier implements Supplier { private final Supplier supplier; - private T value; + private @Nullable T value; public CachedSupplier(Supplier supplier) { this.supplier = supplier; diff --git a/src/main/java/mcp/mobius/waila/util/ExceptionUtil.java b/src/main/java/mcp/mobius/waila/util/ExceptionUtil.java index af7083d75..e08ec51ea 100644 --- a/src/main/java/mcp/mobius/waila/util/ExceptionUtil.java +++ b/src/main/java/mcp/mobius/waila/util/ExceptionUtil.java @@ -7,13 +7,14 @@ import net.minecraft.ChatFormatting; import net.minecraft.network.chat.Component; import org.apache.commons.lang3.exception.ExceptionUtils; +import org.jetbrains.annotations.Nullable; public final class ExceptionUtil { private static final Log LOG = Log.create(); private static final Set ERRORS = new HashSet<>(); - public static boolean dump(Throwable e, String errorName, ITooltip tooltip) { + public static boolean dump(Throwable e, String errorName, @Nullable ITooltip tooltip) { var log = ERRORS.add(errorName); if (log) { diff --git a/src/pluginExtra/java/mcp/mobius/waila/plugin/extra/data/FluidDataImpl.java b/src/pluginExtra/java/mcp/mobius/waila/plugin/extra/data/FluidDataImpl.java index 70add2f35..d18b9867b 100644 --- a/src/pluginExtra/java/mcp/mobius/waila/plugin/extra/data/FluidDataImpl.java +++ b/src/pluginExtra/java/mcp/mobius/waila/plugin/extra/data/FluidDataImpl.java @@ -57,6 +57,7 @@ protected void implAdd(Fluid fluid, @Nullable CompoundTag nbt, double stored, do } @Override + @SuppressWarnings("DataFlowIssue") protected PlatformTranslator translator() { return proxy; } diff --git a/src/pluginExtra/java/mcp/mobius/waila/plugin/extra/provider/DataProvider.java b/src/pluginExtra/java/mcp/mobius/waila/plugin/extra/provider/DataProvider.java index 7a176e806..76c6baf4c 100644 --- a/src/pluginExtra/java/mcp/mobius/waila/plugin/extra/provider/DataProvider.java +++ b/src/pluginExtra/java/mcp/mobius/waila/plugin/extra/provider/DataProvider.java @@ -100,7 +100,8 @@ public void appendBody(ITooltip tooltip, IBlockAccessor accessor, IPluginConfig var blockEntityType = Objects.requireNonNull(accessor.getBlockEntity()).getType(); if (blacklistConfig.get().getView().blockEntityFilter.matches(blockEntityType)) return; - appendBody(tooltip, accessor.getData(), config, BuiltInRegistries.BLOCK_ENTITY_TYPE.getKey(blockEntityType)); + var blockEntityId = Objects.requireNonNull(BuiltInRegistries.BLOCK_ENTITY_TYPE.getKey(blockEntityType)); + appendBody(tooltip, accessor.getData(), config, blockEntityId); } @Override diff --git a/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/BoatProvider.java b/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/BoatProvider.java index 1049c0717..2fcebb44d 100644 --- a/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/BoatProvider.java +++ b/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/BoatProvider.java @@ -26,7 +26,9 @@ public enum BoatProvider implements IEntityComponentProvider { @Override public void appendHead(ITooltip tooltip, IEntityAccessor accessor, IPluginConfig config) { - stack = accessor.getEntity().getPickResult(); + //noinspection DataFlowIssue + stack = accessor.getEntity().getPickResult(); + var formatter = IWailaConfig.get().getFormatter(); tooltip.setLine(WailaConstants.OBJECT_NAME_TAG, formatter.entityName(stack.getHoverName().getString())); diff --git a/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/FurnaceProvider.java b/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/FurnaceProvider.java index 879e0a976..b09723ea5 100644 --- a/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/FurnaceProvider.java +++ b/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/FurnaceProvider.java @@ -6,7 +6,7 @@ import mcp.mobius.waila.api.IServerAccessor; import mcp.mobius.waila.api.data.ProgressData; import mcp.mobius.waila.mixin.AbstractFurnaceBlockEntityAccess; -import net.minecraft.world.level.block.FurnaceBlock; +import net.minecraft.world.level.block.AbstractFurnaceBlock; import net.minecraft.world.level.block.entity.AbstractFurnaceBlockEntity; public enum FurnaceProvider implements IDataProvider { @@ -19,7 +19,7 @@ public void appendData(IDataWriter data, IServerAccessor 4.0f) if (config.getBoolean(Options.HORSE_SPEED)) { AbstractHorse horse = accessor.getEntity(); - var speed = horse.getAttribute(Attributes.MOVEMENT_SPEED).getBaseValue() * 42.157787584f; + var speed = horse.getAttributeBaseValue(Attributes.MOVEMENT_SPEED) * 42.157787584f; ChatFormatting format; if (speed < 7.0f) diff --git a/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/InfestedBlockProvider.java b/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/InfestedBlockProvider.java index b19839e93..6f0e0702a 100644 --- a/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/InfestedBlockProvider.java +++ b/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/InfestedBlockProvider.java @@ -6,13 +6,14 @@ import mcp.mobius.waila.plugin.vanilla.config.Options; import net.minecraft.world.level.block.InfestedBlock; import net.minecraft.world.level.block.state.BlockState; +import org.jetbrains.annotations.Nullable; public enum InfestedBlockProvider implements IBlockComponentProvider { INSTANCE; @Override - public BlockState getOverride(IBlockAccessor accessor, IPluginConfig config) { + public @Nullable BlockState getOverride(IBlockAccessor accessor, IPluginConfig config) { return config.getBoolean(Options.OVERRIDE_INFESTED) ? ((InfestedBlock) accessor.getBlock()).getHostBlock().defaultBlockState() : null; diff --git a/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/PetOwnerProvider.java b/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/PetOwnerProvider.java index 64ec6f554..0bc58f47d 100644 --- a/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/PetOwnerProvider.java +++ b/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/PetOwnerProvider.java @@ -46,6 +46,7 @@ public void appendBody(ITooltip tooltip, IEntityAccessor accessor, IPluginConfig OwnableEntity entity = accessor.getEntity(); var data = accessor.getData().raw(); var uuid = data.hasUUID("owner") ? data.getUUID("owner") : entity.getOwnerUUID(); + if (uuid == null) return; var name = LOADING; if (NAMES.containsKey(uuid)) { diff --git a/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/SpawnerProvider.java b/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/SpawnerProvider.java index 70a780866..60071efe6 100644 --- a/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/SpawnerProvider.java +++ b/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/SpawnerProvider.java @@ -19,8 +19,11 @@ public void appendHead(ITooltip tooltip, IBlockAccessor accessor, IPluginConfig SpawnerBlockEntity spawner = accessor.getBlockEntity(); var entity = spawner != null ? spawner.getSpawner().getOrCreateDisplayEntity(accessor.getWorld(), spawner.getBlockPos()) : null; if (entity != null) { + //noinspection DataFlowIssue + var name = entity.getDisplayName().getString(); + tooltip.setLine(WailaConstants.OBJECT_NAME_TAG, IWailaConfig.get().getFormatter().blockName( - accessor.getBlock().getName().getString() + " (" + entity.getDisplayName().getString() + ")")); + accessor.getBlock().getName().getString() + " (" + name + ")")); } } } diff --git a/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/TrappedChestProvider.java b/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/TrappedChestProvider.java index b5ecefd3e..47ec005ca 100644 --- a/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/TrappedChestProvider.java +++ b/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/TrappedChestProvider.java @@ -6,6 +6,7 @@ import mcp.mobius.waila.plugin.vanilla.config.Options; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.state.BlockState; +import org.jetbrains.annotations.Nullable; import static net.minecraft.world.level.block.ChestBlock.FACING; import static net.minecraft.world.level.block.ChestBlock.TYPE; @@ -16,7 +17,7 @@ public enum TrappedChestProvider implements IBlockComponentProvider { INSTANCE; @Override - public BlockState getOverride(IBlockAccessor accessor, IPluginConfig config) { + public @Nullable BlockState getOverride(IBlockAccessor accessor, IPluginConfig config) { if (config.getBoolean(Options.OVERRIDE_TRAPPED_CHEST)) { var state = accessor.getBlockState(); return Blocks.CHEST.defaultBlockState()