Skip to content

Commit

Permalink
Merge branch 'dev/snapshot' into dev/master
Browse files Browse the repository at this point in the history
  • Loading branch information
deirn committed Sep 16, 2023
2 parents 02ed673 + c449557 commit 33030a4
Show file tree
Hide file tree
Showing 48 changed files with 908 additions and 414 deletions.
12 changes: 6 additions & 6 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
org.gradle.jvmargs = -Xmx2G

minecraft = 1.20.1
minecraft = 1.20.2-pre2

archiveBaseName = wthit
group = mcp.mobius.waila
majorVersion = 8
majorVersion = 9

# [rei, jei, emi]
recipeViewer = none

badpackets = 0.4.1
badpackets = 0.5.0
rei = 12.0.622
jei = 1.20-14.0.0.4
emi = 1.0.2+1.19.4

fabricLoader = 0.14.19
fabricApi = 0.83.1+1.20.1
modMenu = 7.0.1
fabricLoader = 0.14.22
fabricApi = 0.88.3+1.20.2
modMenu = 7.2.1
trEnergy = 3.0.0

forge = 47.1.56
Expand Down
4 changes: 2 additions & 2 deletions platform/fabric/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ dependencies {

modCompileRuntime("net.fabricmc.fabric-api:fabric-api:${rootProp["fabricApi"]}")

modCompileRuntime("com.terraformersmc:modmenu:${rootProp["modMenu"]}")
modCompileOnly("com.terraformersmc:modmenu:${rootProp["modMenu"]}")

modCompileOnly("me.shedaniel:RoughlyEnoughItems-api-fabric:${rootProp["rei"]}")
modCompileOnly("dev.emi:emi-fabric:${rootProp["emi"]}")
Expand All @@ -23,7 +23,7 @@ dependencies {
// modRuntimeOnly("dev.architectury:architectury-fabric:${rootProp["architectury"]}")
// modRuntimeOnly("me.shedaniel.cloth:cloth-config-fabric:${rootProp["clothConfig"]}")

modRuntimeOnly("TechReborn:TechReborn-1.20:5.8.1")
// modRuntimeOnly("TechReborn:TechReborn-1.20:5.8.1")

when (rootProp["recipeViewer"]) {
"emi" -> modRuntimeOnly("dev.emi:emi:${rootProp["emi"]}")
Expand Down
8 changes: 4 additions & 4 deletions platform/fabric/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# CurseForge
cf.endpoint = minecraft.curseforge.com
cf.projectId = 440979
cf.releaseType = release
cf.gameVersion = 1.20, 1.20.1
cf.releaseType = beta
cf.gameVersion = 1.20.2-Snapshot
cf.loader = Fabric
cf.require = fabric-api, badpackets
cf.optional = modmenu, roughly-enough-items, jei, emi

# Modrinth
mr.projectId = 6AQIaxuO
mr.releaseType = release
mr.gameVersion = 1.20, 1.20.1
mr.releaseType = beta
mr.gameVersion = 1.20.2-pre2
mr.loader = fabric
mr.require = P7dR8mSH, ftdbN0KK
mr.optional = mOgUt4GM, nfn13YXA, fRiHVvU7
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.item.v1.ItemTooltipCallback;
import net.fabricmc.fabric.api.client.networking.v1.ClientConfigurationConnectionEvents;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents;
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
import net.fabricmc.fabric.api.resource.ResourceManagerHelper;
import net.minecraft.server.packs.PackType;

@SuppressWarnings("UnstableApiUsage")
public class FabricWailaClient extends WailaClient implements ClientModInitializer {

@Override
Expand All @@ -23,8 +25,11 @@ public void onInitializeClient() {
HudRenderCallback.EVENT.register(TooltipRenderer::render);
ClientTickEvents.END_CLIENT_TICK.register(client -> onClientTick());
ItemTooltipCallback.EVENT.register((stack, ctx, tooltip) -> onItemTooltip(stack, tooltip));
ClientPlayConnectionEvents.INIT.register((handler, client) -> client.execute(() -> onServerLogIn(handler.getConnection())));
ClientPlayConnectionEvents.DISCONNECT.register((handler, client) -> onServerLogout(handler.getConnection()));

ClientConfigurationConnectionEvents.INIT.register((handler, client) -> client.execute(WailaClient::onServerLogIn));
ClientConfigurationConnectionEvents.DISCONNECT.register((handler, client) -> client.execute(WailaClient::onServerLogout));
ClientPlayConnectionEvents.DISCONNECT.register((handler, client) -> client.execute(WailaClient::onServerLogout));

ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> new FabricClientCommand().register(dispatcher));

ResourceManagerHelper.get(PackType.CLIENT_RESOURCES).registerReloadListener(new FabricBuiltinThemeLoader());
Expand Down
8 changes: 4 additions & 4 deletions platform/fabric/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@
],

"depends" : {
"fabricloader": ">=0.14.17",
"fabric" : ">=0.83.0",
"minecraft" : ">=1.20",
"badpackets" : ">=0.4.1"
"fabricloader": ">=0.14.22",
"fabric" : ">=0.88.3",
"minecraft" : ">=1.20.2-0",
"badpackets" : ">=0.5-0"
},
"breaks" : {
"roughlyenoughitems": "<9.0.462"
Expand Down
4 changes: 2 additions & 2 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ fun platform(name: String) {

//platform("bukkit")
platform("fabric")
platform("forge")
//platform("forge")
platform("mojmap")
platform("textile")
platform("quilt")
//platform("quilt")
5 changes: 0 additions & 5 deletions src/api/java/mcp/mobius/waila/api/WailaHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,8 @@

import java.text.DecimalFormat;

import mcp.mobius.waila.api.__internal__.IApiService;
import net.minecraft.resources.ResourceLocation;

public final class WailaHelper {

public static final ResourceLocation GUI_ICONS_TEXTURE = IApiService.INSTANCE.getGuiIconsTexture();

public static String suffix(long value) {
if (value == Long.MIN_VALUE) return suffix(Long.MIN_VALUE + 1);
if (value < 0) return "-" + suffix(-value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
import org.jetbrains.annotations.ApiStatus;
import org.joml.Matrix4f;

/** @hidden */
/**
* @hidden
*/
@ApiStatus.Internal
public interface IApiService {

Expand Down Expand Up @@ -61,8 +63,6 @@ public interface IApiService {

Path getConfigDir();

ResourceLocation getGuiIconsTexture();

<T> IRegistryFilter.Builder<T> createRegistryFilterBuilder(ResourceKey<? extends Registry<T>> registryKey);

}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package mcp.mobius.waila.api.component;

import mcp.mobius.waila.api.ITooltipComponent;
import mcp.mobius.waila.api.WailaHelper;
import mcp.mobius.waila.api.__internal__.ApiSide;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth;

/**
Expand All @@ -12,6 +12,9 @@
@ApiSide.ClientOnly
public class ArmorComponent implements ITooltipComponent {

private static final ResourceLocation SPRITE_FULL = new ResourceLocation("hud/armor_full");
private static final ResourceLocation SPRITE_HALF = new ResourceLocation("hud/armor_half");

/**
* @param armor the armor points, 1 full icon represent 2 points
* @param maxPerLine the max icon per line until it get wrapped into multiple
Expand Down Expand Up @@ -46,9 +49,9 @@ public void render(GuiGraphics ctx, int x, int y, float delta) {
var iy = y + ((i / lineWidth) * 3);

if (i <= filled) {
ctx.blit(WailaHelper.GUI_ICONS_TEXTURE, ix, iy, 34, 9, 9, 9);
ctx.blitSprite(SPRITE_FULL, ix, iy, 9, 9);
} else if (i == half) {
ctx.blit(WailaHelper.GUI_ICONS_TEXTURE, ix, iy, 25, 9, 9, 9);
ctx.blitSprite(SPRITE_HALF, ix, iy, 9, 9);
}
}
}
Expand Down
14 changes: 10 additions & 4 deletions src/api/java/mcp/mobius/waila/api/component/HealthComponent.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package mcp.mobius.waila.api.component;

import mcp.mobius.waila.api.ITooltipComponent;
import mcp.mobius.waila.api.WailaHelper;
import mcp.mobius.waila.api.__internal__.ApiSide;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth;

/**
Expand All @@ -12,6 +12,12 @@
@ApiSide.ClientOnly
public class HealthComponent implements ITooltipComponent {

private static final ResourceLocation SPRITE_CONTAINER = new ResourceLocation("hud/heart/container");
private static final ResourceLocation SPRITE_NORMAL_FULL = new ResourceLocation("hud/heart/full");
private static final ResourceLocation SPRITE_NORMAL_HALF = new ResourceLocation("hud/heart/half");
private static final ResourceLocation SPRITE_ABSORBING_FULL = new ResourceLocation("hud/heart/absorbing_full");
private static final ResourceLocation SPRITE_ABSORBING_HALF = new ResourceLocation("hud/heart/absorbing_half");

/**
* @param health the health point, 1 full icon represent 2 hp
* @param maxHealth the max health point
Expand Down Expand Up @@ -49,11 +55,11 @@ public void render(GuiGraphics ctx, int x, int y, float delta) {
var ix = x + ((i % lineWidth) * 8);
var iy = y + ((i / lineWidth) * 3);

ctx.blit(WailaHelper.GUI_ICONS_TEXTURE, ix, iy, 16, 0, 9, 9);
ctx.blitSprite(SPRITE_CONTAINER, ix, iy, 9, 9);
if (i <= filled) {
ctx.blit(WailaHelper.GUI_ICONS_TEXTURE, ix, iy, absorption ? 160 : 52, 0, 9, 9);
ctx.blitSprite(absorption ? SPRITE_ABSORBING_FULL : SPRITE_NORMAL_FULL, ix, iy, 9, 9);
} else if (i == half) {
ctx.blit(WailaHelper.GUI_ICONS_TEXTURE, ix, iy, absorption ? 169 : 61, 0, 9, 9);
ctx.blitSprite(absorption ? SPRITE_ABSORBING_HALF : SPRITE_NORMAL_HALF, ix, iy, 9, 9);
}
}
}
Expand Down
35 changes: 35 additions & 0 deletions src/api/java/mcp/mobius/waila/api/component/SpriteComponent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package mcp.mobius.waila.api.component;

import mcp.mobius.waila.api.ITooltipComponent;
import mcp.mobius.waila.api.__internal__.ApiSide;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.resources.ResourceLocation;

@ApiSide.ClientOnly
public class SpriteComponent implements ITooltipComponent {

public SpriteComponent(ResourceLocation id, int width, int height) {
this.id = id;
this.width = width;
this.height = height;
}

private final ResourceLocation id;
private final int width, height;

@Override
public int getWidth() {
return width;
}

@Override
public int getHeight() {
return height;
}

@Override
public void render(GuiGraphics ctx, int x, int y, float delta) {
ctx.blitSprite(id, x, y, width, height);
}

}
5 changes: 2 additions & 3 deletions src/main/java/mcp/mobius/waila/WailaClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import mcp.mobius.waila.util.Log;
import net.minecraft.client.KeyMapping;
import net.minecraft.client.Minecraft;
import net.minecraft.network.Connection;
import net.minecraft.network.chat.Component;
import net.minecraft.world.item.ItemStack;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -101,13 +100,13 @@ protected static void onItemTooltip(ItemStack stack, List<Component> tooltip) {
}
}

protected static void onServerLogIn(Connection connection) {
protected static void onServerLogIn() {
Waila.BLACKLIST_CONFIG.invalidate();
PluginConfig.getSyncableConfigs().forEach(config ->
config.setServerValue(null));
}

protected static void onServerLogout(Connection connection) {
protected static void onServerLogout() {
RegistryFilter.attach(null);
Waila.BLACKLIST_CONFIG.invalidate();
PluginConfig.getSyncableConfigs().forEach(config ->
Expand Down
28 changes: 18 additions & 10 deletions src/main/java/mcp/mobius/waila/access/DataWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@
import java.util.function.Consumer;

import com.google.common.base.Preconditions;
import io.netty.buffer.Unpooled;
import lol.bai.badpackets.api.PacketSender;
import mcp.mobius.waila.api.IData;
import mcp.mobius.waila.api.IDataProvider;
import mcp.mobius.waila.api.IDataWriter;
import mcp.mobius.waila.network.Packets;
import mcp.mobius.waila.api.IServerAccessor;
import mcp.mobius.waila.config.PluginConfig;
import mcp.mobius.waila.network.play.s2c.TypedDataResponsePlayS2CPacket;
import mcp.mobius.waila.registry.Registrar;
import mcp.mobius.waila.util.ExceptionUtil;
import mcp.mobius.waila.util.TypeUtil;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerPlayer;

Expand All @@ -40,8 +41,6 @@ public CompoundTag reset() {

public void sendTypedPackets(PacketSender sender, ServerPlayer player) {
typed.forEach((type, data) -> {
var id = Registrar.INSTANCE.dataType2Id.get(type);

final var finished = new boolean[]{false};
for (var consumer : data) {
try {
Expand All @@ -53,10 +52,7 @@ public Result<IData> add(IData data) {
Preconditions.checkState(!added, "Called multiple times in the same closure");
Preconditions.checkNotNull(data, "Data is null");

var buf = new FriendlyByteBuf(Unpooled.buffer());
buf.writeResourceLocation(id);
data.write(buf);
sender.send(Packets.DATA_TYPED, buf);
sender.send(new TypedDataResponsePlayS2CPacket.Payload(data));

finished[0] = true;
added = true;
Expand All @@ -71,7 +67,7 @@ public Result<IData> block() {
}
});
} catch (Throwable t) {
if (ExceptionUtil.dump(t, consumer.getClass().toString() + "\nplayer " + player.getScoreboardName(), null)) {
if (ExceptionUtil.dump(t, consumer.getClass() + "\nplayer " + player.getScoreboardName(), null)) {
player.sendSystemMessage(Component.literal("Error on retrieving server data from provider " + consumer.getClass().getName()));
}

Expand All @@ -98,4 +94,16 @@ public <T extends IData> void add(Class<T> type, Consumer<Result<T>> consumer) {
.add(TypeUtil.uncheckedCast(consumer));
}

public <T> void tryAppendData(IDataProvider<T> provider, IServerAccessor<T> accessor) {
try {
provider.appendData(this, accessor, PluginConfig.SERVER);
} catch (Throwable t) {
var player = accessor.getPlayer();

if (ExceptionUtil.dump(t, provider.getClass() + "\nplayer " + player.getScoreboardName(), null)) {
player.sendSystemMessage(Component.literal("Error on retrieving server data from provider " + provider.getClass().getName()));
}
}
}

}
6 changes: 2 additions & 4 deletions src/main/java/mcp/mobius/waila/command/ServerCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@

import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.StringArgumentType;
import io.netty.buffer.Unpooled;
import lol.bai.badpackets.api.PacketSender;
import mcp.mobius.waila.Waila;
import mcp.mobius.waila.api.WailaConstants;
import mcp.mobius.waila.buildconst.Tl;
import mcp.mobius.waila.debug.DumpGenerator;
import mcp.mobius.waila.mixin.BaseContainerBlockEntityAccess;
import mcp.mobius.waila.network.Packets;
import mcp.mobius.waila.network.play.s2c.GenerateClientDumpPlayS2CPacket;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.commands.arguments.coordinates.BlockPosArgument;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.chat.ClickEvent;
import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerPlayer;
Expand All @@ -40,7 +38,7 @@ public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
source.sendSuccess(() -> Component.translatable(dedicated ? Tl.Command.SERVER_DUMP_SUCCESS : Tl.Command.LOCAL_DUMP_SUCCESS, pathComponent), false);
var entity = source.getEntity();
if (entity instanceof ServerPlayer player && !server.isSingleplayerOwner(player.getGameProfile())) {
PacketSender.s2c(player).send(Packets.GENERATE_CLIENT_DUMP, new FriendlyByteBuf(Unpooled.EMPTY_BUFFER));
PacketSender.s2c(player).send(new GenerateClientDumpPlayS2CPacket.Payload());
}
return 1;
} else {
Expand Down
Loading

0 comments on commit 33030a4

Please sign in to comment.