-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
106 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
src/mixin/java/mcp/mobius/waila/mixin/BeaconBlockEntityAccess.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/BeaconProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters