Skip to content

Commit

Permalink
add beacon effects tooltip
Browse files Browse the repository at this point in the history
  • Loading branch information
deirn committed Nov 23, 2023
1 parent 035c159 commit eb7b73c
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 0 deletions.
1 change: 1 addition & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,7 @@ ij_json_space_before_comma = false
ij_json_spaces_within_braces = false
ij_json_spaces_within_brackets = false
ij_json_wrap_long_lines = false
ij_json_property_alignment = align_on_colon

[{*.yaml, *.yml}]
indent_size = 2
Expand Down
20 changes: 20 additions & 0 deletions src/mixin/java/mcp/mobius/waila/mixin/BeaconBlockEntityAccess.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package mcp.mobius.waila.mixin;

import net.minecraft.world.effect.MobEffect;
import net.minecraft.world.level.block.entity.BeaconBlockEntity;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;

@Mixin(BeaconBlockEntity.class)
public interface BeaconBlockEntityAccess {

@Nullable
@Accessor("primaryPower")
MobEffect wthit_primaryPower();

@Nullable
@Accessor("secondaryPower")
MobEffect wthit_secondaryPower();

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import mcp.mobius.waila.plugin.vanilla.fluid.LavaDescriptor;
import mcp.mobius.waila.plugin.vanilla.fluid.WaterDescriptor;
import mcp.mobius.waila.plugin.vanilla.provider.BaseContainerProvider;
import mcp.mobius.waila.plugin.vanilla.provider.BeaconProvider;
import mcp.mobius.waila.plugin.vanilla.provider.BeehiveProvider;
import mcp.mobius.waila.plugin.vanilla.provider.BlockAttributesProvider;
import mcp.mobius.waila.plugin.vanilla.provider.BoatProvider;
Expand Down Expand Up @@ -72,6 +73,7 @@
import net.minecraft.world.level.block.TrappedChestBlock;
import net.minecraft.world.level.block.entity.AbstractFurnaceBlockEntity;
import net.minecraft.world.level.block.entity.BaseContainerBlockEntity;
import net.minecraft.world.level.block.entity.BeaconBlockEntity;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.ChiseledBookShelfBlockEntity;
import net.minecraft.world.level.block.entity.EnderChestBlockEntity;
Expand Down Expand Up @@ -114,11 +116,15 @@ public void register(IRegistrar registrar) {
registrar.addFeatureConfig(Options.ATTRIBUTE_HORSE_JUMP_HEIGHT, true);
registrar.addFeatureConfig(Options.ATTRIBUTE_HORSE_SPEED, true);
registrar.addFeatureConfig(Options.ATTRIBUTE_PANDA_GENES, true);
registrar.addFeatureConfig(Options.ATTRIBUTE_BEACON_EFFECTS, false);
registrar.addComponent(BlockAttributesProvider.INSTANCE, BODY, Block.class, 950);
registrar.addComponent(EntityAttributesProvider.INSTANCE, HEAD, Entity.class, 950);
registrar.addComponent(EntityAttributesProvider.INSTANCE, BODY, Entity.class, 950);
registrar.addComponent(HorseProvider.INSTANCE, BODY, AbstractHorse.class);
registrar.addComponent(PandaProvider.INSTANCE, BODY, Panda.class);
registrar.addComponent(BeaconProvider.INSTANCE, BODY, BeaconBlockEntity.class);
registrar.addDataType(BeaconProvider.DATA, BeaconProvider.Data.class, BeaconProvider.Data::new);
registrar.addBlockData(BeaconProvider.INSTANCE, BeaconBlockEntity.class);
registrar.addEntityData(EntityAttributesProvider.INSTANCE, Entity.class);

registrar.addFeatureConfig(Options.JUKEBOX_RECORD, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public final class Options {
public static final ResourceLocation ATTRIBUTE_HORSE_JUMP_HEIGHT = rl("attribute.horse_jump_height");
public static final ResourceLocation ATTRIBUTE_HORSE_SPEED = rl("attribute.horse_speed");
public static final ResourceLocation ATTRIBUTE_PANDA_GENES = rl("attribute.panda_genes");
public static final ResourceLocation ATTRIBUTE_BEACON_EFFECTS = rl("attribute.beacon_effects");
public static final ResourceLocation BOOK_BOOKSHELF = rl("book.bookshelf");
public static final ResourceLocation BOOK_WRITTEN = rl("book.written");
public static final ResourceLocation BOOK_ENCHANTMENT_DISPLAY_MODE = rl("book.enchantment");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package mcp.mobius.waila.plugin.vanilla.provider;

import mcp.mobius.waila.api.IBlockAccessor;
import mcp.mobius.waila.api.IBlockComponentProvider;
import mcp.mobius.waila.api.IData;
import mcp.mobius.waila.api.IDataProvider;
import mcp.mobius.waila.api.IDataWriter;
import mcp.mobius.waila.api.IPluginConfig;
import mcp.mobius.waila.api.IServerAccessor;
import mcp.mobius.waila.api.ITooltip;
import mcp.mobius.waila.mixin.BeaconBlockEntityAccess;
import mcp.mobius.waila.plugin.vanilla.config.Options;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.effect.MobEffect;
import net.minecraft.world.level.block.entity.BeaconBlockEntity;
import org.jetbrains.annotations.Nullable;

public enum BeaconProvider implements IBlockComponentProvider, IDataProvider<BeaconBlockEntity> {

INSTANCE;

public static final ResourceLocation DATA = new ResourceLocation("beacon");

private MutableComponent getText(MobEffect effect) {
return effect.getDisplayName().copy();
}

@Override
public void appendBody(ITooltip tooltip, IBlockAccessor accessor, IPluginConfig config) {
if (!config.getBoolean(Options.ATTRIBUTE_BEACON_EFFECTS)) return;

var data = accessor.getData().get(Data.class);
if (data == null) return;

if (data.primary != null) {
var text = getText(data.primary);
if (data.primary == data.secondary) text.append(" II");
tooltip.addLine(text);
}

if (data.secondary != null && data.primary != data.secondary) {
tooltip.addLine(getText(data.secondary));
}
}

@Override
public void appendData(IDataWriter data, IServerAccessor<BeaconBlockEntity> accessor, IPluginConfig config) {
if (config.getBoolean(Options.ATTRIBUTE_BEACON_EFFECTS)) data.add(Data.class, res -> {
var beacon = (BeaconBlockEntity & BeaconBlockEntityAccess) accessor.getTarget();
res.add(new Data(beacon.wthit_primaryPower(), beacon.wthit_secondaryPower()));
});
}

public record Data(
@Nullable MobEffect primary,
@Nullable MobEffect secondary
) implements IData {

public Data(FriendlyByteBuf buf) {
this(
buf.readNullable(b -> b.readById(BuiltInRegistries.MOB_EFFECT)),
buf.readNullable(b -> b.readById(BuiltInRegistries.MOB_EFFECT)));
}

@Override
public void write(FriendlyByteBuf buf) {
buf.writeNullable(primary, (b, m) -> b.writeId(BuiltInRegistries.MOB_EFFECT, m));
buf.writeNullable(secondary, (b, m) -> b.writeId(BuiltInRegistries.MOB_EFFECT, m));
}

}

}
1 change: 1 addition & 0 deletions src/resources/resources/assets/waila/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@
"config.waila.plugin_minecraft.attribute.horse_jump_height" : "Show Horse Jump Height",
"config.waila.plugin_minecraft.attribute.horse_speed" : "Show Horse Speed",
"config.waila.plugin_minecraft.attribute.panda_genes" : "Show Panda Genes",
"config.waila.plugin_minecraft.attribute.beacon_effects" : "Show Beacon Effects",
"config.waila.plugin_minecraft.book" : "Book",
"config.waila.plugin_minecraft.book.bookshelf" : "Show Chiseled Bookshelf Books",
"config.waila.plugin_minecraft.book.written" : "Show Written Book Author and Generation",
Expand Down
1 change: 1 addition & 0 deletions src/resources/resources/wthit.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"mixins" : [
"AbstractFurnaceBlockEntityAccess",
"BaseContainerBlockEntityAccess",
"BeaconBlockEntityAccess",
"ChiseledBookShelfBlockAccess",
"ChiseledBookShelfBlockEntityAccess",
"EntityAccess",
Expand Down

0 comments on commit eb7b73c

Please sign in to comment.