Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attempt to add vanilla crop and tree sapling growability tooltip #245

Merged
merged 7 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/mcp/mobius/waila/config/PluginConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public int getInt(ResourceLocation key) {

@Override
public double getDouble(ResourceLocation key) {
return getValue(key, 0);
return getValue(key, 0.0);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
import net.minecraft.world.level.block.PowderSnowBlock;
import net.minecraft.world.level.block.RedStoneWireBlock;
import net.minecraft.world.level.block.RepeaterBlock;
import net.minecraft.world.level.block.SaplingBlock;
import net.minecraft.world.level.block.StemBlock;
import net.minecraft.world.level.block.SweetBerryBushBlock;
import net.minecraft.world.level.block.TrappedChestBlock;
Expand Down Expand Up @@ -162,12 +163,15 @@ public void register(IRegistrar registrar) {
registrar.addComponent(SpawnerProvider.INSTANCE, HEAD, SpawnerBlockEntity.class, 950);

registrar.addFeatureConfig(Options.CROP_PROGRESS, true);
registrar.addFeatureConfig(Options.CROP_GROWABLE, true);
registrar.addFeatureConfig(Options.TREE_GROWABLE, true);
registrar.addIcon(PlantProvider.INSTANCE, CropBlock.class);
registrar.addComponent(PlantProvider.INSTANCE, BODY, CropBlock.class);
registrar.addComponent(PlantProvider.INSTANCE, BODY, StemBlock.class);
registrar.addComponent(PlantProvider.INSTANCE, BODY, CocoaBlock.class);
registrar.addComponent(PlantProvider.INSTANCE, BODY, NetherWartBlock.class);
registrar.addComponent(PlantProvider.INSTANCE, BODY, SweetBerryBushBlock.class);
registrar.addComponent(PlantProvider.INSTANCE, BODY, SaplingBlock.class);

registrar.addFeatureConfig(Options.REDSTONE_LEVER, true);
registrar.addFeatureConfig(Options.REDSTONE_REPEATER, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public final class Options {
public static final ResourceLocation PET_HIDE_UNKNOWN_OWNER = rl("pet.hide_unknown_owner");
public static final ResourceLocation SPAWNER_TYPE = rl("spawner_type");
public static final ResourceLocation CROP_PROGRESS = rl("crop_progress");
public static final ResourceLocation CROP_GROWABLE = rl("crop_growable");
public static final ResourceLocation TREE_GROWABLE = rl("tree_growable");
public static final ResourceLocation REDSTONE_LEVER = rl("redstone.lever");
public static final ResourceLocation REDSTONE_REPEATER = rl("redstone.repeater");
public static final ResourceLocation REDSTONE_COMPARATOR = rl("redstone.comparator");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import mcp.mobius.waila.api.IBlockAccessor;
import mcp.mobius.waila.api.IBlockComponentProvider;
import mcp.mobius.waila.api.IModInfo;
import mcp.mobius.waila.api.IPluginConfig;
import mcp.mobius.waila.api.ITooltip;
import mcp.mobius.waila.api.ITooltipComponent;
Expand All @@ -13,6 +14,9 @@
import net.minecraft.world.item.Items;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.CropBlock;
import net.minecraft.world.level.block.MangrovePropaguleBlock;
import net.minecraft.world.level.block.SaplingBlock;
import net.minecraft.world.level.block.StemBlock;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import org.jetbrains.annotations.Nullable;

Expand All @@ -31,6 +35,27 @@ private static void addMaturityTooltip(ITooltip tooltip, float growthValue) {
}
}

private static void addGrowableTooltip(ITooltip tooltip, String translationKey, boolean growable) {
tooltip.addLine(new PairComponent(Component.translatable(translationKey),
growable ? Component.translatable(Tl.Tooltip.TRUE) : Component.translatable(Tl.Tooltip.FALSE)));
}

private static void addCropGrowableTooltip(ITooltip tooltip, IBlockAccessor accessor) {
var lightLevel = accessor.getWorld().getRawBrightness(accessor.getPosition(), 0);
addGrowableTooltip(tooltip, Tl.Tooltip.CROP_GROWABLE, lightLevel >= 9);
}

private static void addTreeGrowableTooltip(ITooltip tooltip, IBlockAccessor accessor) {
var lightLevel = accessor.getWorld().getRawBrightness(accessor.getPosition(), 0);
var growable = lightLevel >= 9;
if (accessor.getBlock() instanceof MangrovePropaguleBlock
&& accessor.getBlockState().getValue(MangrovePropaguleBlock.HANGING)) {
growable = false;
}

addGrowableTooltip(tooltip, Tl.Tooltip.TREE_GROWABLE, growable);
}

@Nullable
@Override
public ITooltipComponent getIcon(IBlockAccessor accessor, IPluginConfig config) {
Expand Down Expand Up @@ -58,6 +83,19 @@ public void appendBody(ITooltip tooltip, IBlockAccessor accessor, IPluginConfig
addMaturityTooltip(tooltip, accessor.getBlockState().getValue(BlockStateProperties.AGE_3) / 3.0F);
}
}

if (config.getBoolean(Options.CROP_GROWABLE)) {
if ((accessor.getBlock() instanceof CropBlock || accessor.getBlock() instanceof StemBlock)
&& IModInfo.get(accessor.getBlock()).getId().equals("minecraft")) {
addCropGrowableTooltip(tooltip, accessor);
}
}

if (config.getBoolean(Options.TREE_GROWABLE)) {
if (accessor.getBlock() instanceof SaplingBlock && IModInfo.get(accessor.getBlock()).getId().equals("minecraft")) {
addTreeGrowableTooltip(tooltip, accessor);
}
}
}

}
3 changes: 3 additions & 0 deletions src/resources/resources/assets/waila/lang/de_de.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"tooltip.waila.crop_growth" : "Gewachsen",
"tooltip.waila.crop_growable" : "Kann wachsen",
"tooltip.waila.crop_mature" : "Ausgewachsen",
"tooltip.waila.empty" : "Leer",
"tooltip.waila.delay" : "Verzögerung",
Expand All @@ -9,6 +10,8 @@
"tooltip.waila.state" : "Status",
"tooltip.waila.state_on" : "Ein",
"tooltip.waila.state_off" : "Aus",
"tooltip.waila.true" : "Wahr",
"tooltip.waila.false" : "Falsch",
"tooltip.waila.power" : "Stärke",
"tooltip.waila.sneak_for_details" : "Schleiche für Details",

Expand Down
6 changes: 6 additions & 0 deletions src/resources/resources/assets/waila/lang/en_us.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"tooltip.waila.crop_growth" : "Growth",
"tooltip.waila.crop_growable" : "Can Grow",
"tooltip.waila.tree_growable" : "Can Grow",
"tooltip.waila.crop_mature" : "Mature",
"tooltip.waila.empty" : "Empty",
"tooltip.waila.delay" : "Delay",
Expand All @@ -9,6 +11,8 @@
"tooltip.waila.state" : "State",
"tooltip.waila.state_on" : "On",
"tooltip.waila.state_off" : "Off",
"tooltip.waila.true" : "True",
"tooltip.waila.false" : "False",
"tooltip.waila.power" : "Power",
"tooltip.waila.sneak_for_details" : "Sneak for details",
"tooltip.waila.compost_level" : "Compost Level",
Expand Down Expand Up @@ -203,6 +207,8 @@
"config.waila.plugin_minecraft.override.vehicle_desc" : "Hide minecart, horse, and other mountable entities when mounted by the player",
"config.waila.plugin_minecraft.spawner_type" : "Show Spawner Type",
"config.waila.plugin_minecraft.crop_progress" : "Show Crop Progress",
"config.waila.plugin_minecraft.crop_growable" : "Show Crop Growability",
"config.waila.plugin_minecraft.tree_growable" : "Show Tree Growability",
"config.waila.plugin_minecraft.redstone" : "Redstone",
"config.waila.plugin_minecraft.redstone.lever" : "Show Lever State",
"config.waila.plugin_minecraft.redstone.repeater" : "Show Repeater Delay",
Expand Down
6 changes: 6 additions & 0 deletions src/resources/resources/assets/waila/lang/zh_cn.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"tooltip.waila.crop_growth" : "生长状态",
"tooltip.waila.crop_growable" : "可生长",
"tooltip.waila.tree_growable" : "可生长",
"tooltip.waila.crop_mature" : "成熟",
"tooltip.waila.empty" : "空",
"tooltip.waila.delay" : "延迟",
Expand All @@ -9,6 +11,8 @@
"tooltip.waila.state" : "状态",
"tooltip.waila.state_on" : "开",
"tooltip.waila.state_off" : "关",
"tooltip.waila.true" : "是",
"tooltip.waila.false" : "否",
"tooltip.waila.power" : "红石强度",
"tooltip.waila.sneak_for_details" : "潜行显示详情",
"tooltip.waila.compost_level" : "堆肥等级",
Expand Down Expand Up @@ -203,6 +207,8 @@
"config.waila.plugin_minecraft.override.vehicle_desc" : "搭乘矿车、马匹等可搭乘实体时,不显示详细信息",
"config.waila.plugin_minecraft.spawner_type" : "显示刷怪笼类型",
"config.waila.plugin_minecraft.crop_progress" : "显示作物生长进度",
"config.waila.plugin_minecraft.crop_growable" : "显示作物是否可生长",
"config.waila.plugin_minecraft.tree_growable" : "显示树木是否可生长",
"config.waila.plugin_minecraft.redstone" : "红石",
"config.waila.plugin_minecraft.redstone.lever" : "显示拉杆状态",
"config.waila.plugin_minecraft.redstone.repeater" : "显示中继器延迟",
Expand Down