Skip to content

Commit

Permalink
MagicLib 0.8.593+
Browse files Browse the repository at this point in the history
Signed-off-by: Hendrix-Shen <[email protected]>
  • Loading branch information
Hendrix-Shen committed Aug 9, 2024
1 parent 28b655d commit fea26a2
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 27 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ mod.version=4.0
## Annotation processor
dependencies.lombok_version=1.18.34
## MagicLib
dependencies.magiclib_dependency=0.8.576
dependencies.magiclib_version=0.8.585-beta
dependencies.magiclib_dependency=0.8.596
dependencies.magiclib_version=0.8.596-beta

# Gradle Plugins
architectury_loom_version=1.7-SNAPSHOT
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/plusls/MasaGadget/game/Configs.java
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,8 @@ public static void init() {
PcaSyncProtocol.syncEntity(entity.getId());
}

InfoUtil.displayChatMessage(ComponentUtil.tr("masa_gadget_mod.message.syncAllEntityDataSuccess")
.withStyle(ChatFormatting.GREEN).get());
InfoUtil.displayChatMessage(ComponentUtil.trCompat("masa_gadget_mod.message.syncAllEntityDataSuccess")
.withStyle(ChatFormatting.GREEN));
return true;
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import lombok.Getter;
import net.minecraft.client.Minecraft;
import net.minecraft.core.Position;
import net.minecraft.network.chat.Component;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.monster.ZombieVillager;
Expand Down Expand Up @@ -67,7 +68,11 @@ public void postRenderLevel(Level level, RenderContext renderContext, float part
TextRenderer renderer = TextRenderer.create();

if (Configs.renderNextRestockTime.getBooleanValue()) {
renderer.addLine(VillagerNextRestockTimeInfo.getInfo(villager));
Component info = VillagerNextRestockTimeInfo.getInfo(villager);

if (info != null) {
renderer.addLine(info);
}
}

if (Configs.renderTradeEnchantedBook.getBooleanValue()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class VillageTradeEnchantedBookInfo {
}

if (!Minecraft.getInstance().hasSingleplayerServer() && !PcaSyncProtocol.enable) {
return Lists.newArrayList(ComponentUtil.tr("masa_gadget_mod.message.no_data").withStyle(ChatFormatting.YELLOW).get());
return Lists.newArrayList(ComponentUtil.tr("masa_gadget_mod.message.no_data").withStyle(ChatFormatting.YELLOW));
}

List<Component> ret = Lists.newArrayList();
Expand Down Expand Up @@ -121,7 +121,7 @@ public class VillageTradeEnchantedBookInfo {
//#else
//$$ ret.add(((BaseComponent) entry.getKey().getFullname(entry.getValue())).withStyle(enchantment_level_color));
//#endif
ret.add(ComponentUtil.simple(String.format("%d(%d-%d)", cost, minCost, maxCost)).withStyle(cast_color).get());
ret.add(ComponentUtil.simple(String.format("%d(%d-%d)", cost, minCost, maxCost)).withStyle(cast_color));
}

break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,17 @@
import top.hendrixshen.magiclib.util.minecraft.ComponentUtil;

public class VillagerNextRestockTimeInfo {
public static @NotNull Component getInfo(@NotNull Villager villager) {
public static Component getInfo(@NotNull Villager villager) {
long nextRestockTime;
long nextWorkTime;
long timeOfDay = villager.getLevel().getDayTime() % 24000;

if (villager.getVillagerData().getProfession() != VillagerProfession.LIBRARIAN) {
return null;
}

if (!Minecraft.getInstance().hasSingleplayerServer() && !PcaSyncProtocol.enable) {
return ComponentUtil.tr("masa_gadget_mod.message.no_data").withStyle(ChatFormatting.YELLOW).get();
return ComponentUtil.tr("masa_gadget_mod.message.no_data").withStyle(ChatFormatting.YELLOW);
}

if (timeOfDay >= 2000 && timeOfDay <= 9000) {
Expand Down Expand Up @@ -52,10 +56,10 @@ public class VillagerNextRestockTimeInfo {
}

if (nextRestockTime == 0) {
return ComponentUtil.simple("OK").withStyle(ChatFormatting.GREEN).get();
return ComponentUtil.simple("OK").withStyle(ChatFormatting.GREEN);
}

return ComponentUtil.simple(String.format("%d", nextRestockTime)).get();
return ComponentUtil.simple(String.format("%d", nextRestockTime));
}

// 因为刁民的需要补货的函数,会检查当前货物是否被消耗,从使用的角度只需要关心当前货物是否用完
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
public class ZombieVillagerConvertTimeInfo {
public static @NotNull Component getInfo(ZombieVillager zombieVillager) {
if (!Minecraft.getInstance().hasSingleplayerServer() && !PcaSyncProtocol.enable) {
return ComponentUtil.tr("masa_gadget_mod.message.no_data").withStyle(ChatFormatting.YELLOW).get();
return ComponentUtil.tr("masa_gadget_mod.message.no_data").withStyle(ChatFormatting.YELLOW);
}

int villagerConversionTime = ((AccessorZombieVillager) zombieVillager).masa_gadget_mod$$getVillagerConversionTime();

if (villagerConversionTime > 0) {
return ComponentUtil.simple(String.format("%d", villagerConversionTime)).get();
return ComponentUtil.simple(String.format("%d", villagerConversionTime));
}

return ComponentUtil.simple("-1").get();
return ComponentUtil.simple("-1");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void postRenderLevel(Level entity, RenderContext renderContext, float par
if (pos.isPresent() && blockEntity instanceof ComparatorBlockEntity) {
TextRenderer.create()
.text(ComponentUtil.simple(((ComparatorBlockEntity) blockEntity).getOutputSignal())
.withStyle(ChatFormatting.GREEN).get())
.withStyle(ChatFormatting.GREEN))
.atCenter(pos.get())
.seeThrough()
.render();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ private void syncVillagerData(byte status, CallbackInfo ci) {

@Inject(method = "tick", at = @At("RETURN"))
private void syncConvertingData(CallbackInfo ci) {
if (EntityCompat.of(this).getLevelCompat().get().get().isClientSide() && this.isAlive() && this.isConverting()) {
if (EntityCompat.of(this).getLevel().isClientSide() && this.isAlive() && this.isConverting()) {
int i = this.getConversionProgress();
this.villagerConversionTime -= i;

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/plusls/MasaGadget/util/PcaSyncProtocol.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public static void updateEntityHandler(
}

PlayerCompat playerCompat = PlayerCompat.of(player);
LevelCompat levelCompat = playerCompat.getLevel();
LevelCompat levelCompat = playerCompat.getLevelCompat();
Level level = levelCompat.get();

if (!levelCompat.getDimensionLocation().equals(
Expand Down Expand Up @@ -274,7 +274,7 @@ public static void updateBlockEntityHandler(
return;
}

LevelCompat levelCompat = PlayerCompat.of(player).getLevel();
LevelCompat levelCompat = PlayerCompat.of(player).getLevelCompat();
Level level = levelCompat.get();

if (!levelCompat.getDimensionLocation().equals(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.jetbrains.annotations.Nullable;
import top.hendrixshen.magiclib.MagicLib;
import top.hendrixshen.magiclib.api.compat.minecraft.network.chat.ComponentCompat;
import top.hendrixshen.magiclib.api.compat.minecraft.network.chat.MutableComponentCompat;
import top.hendrixshen.magiclib.api.compat.minecraft.resources.ResourceLocationCompat;
import top.hendrixshen.magiclib.api.compat.minecraft.world.level.LevelCompat;
import top.hendrixshen.magiclib.util.minecraft.ComponentUtil;
Expand All @@ -46,16 +47,16 @@ private static ShapeDespawnSphere getShapeDespawnSphere() {
if (ret == null) {
ret = (ShapeDespawnSphere) shapeBase;
} else {
InfoUtil.displayChatMessage(ComponentUtil.tr("masa_gadget_mod.message.onlySupportOneDespawnShape")
.withStyle(ChatFormatting.RED).get());
InfoUtil.displayChatMessage(ComponentUtil.trCompat("masa_gadget_mod.message.onlySupportOneDespawnShape")
.withStyle(ChatFormatting.RED));
return null;
}
}
}

if (ret == null) {
InfoUtil.displayChatMessage(ComponentUtil.tr("masa_gadget_mod.message.canNotFindDespawnShape")
.withStyle(ChatFormatting.RED).get());
InfoUtil.displayChatMessage(ComponentUtil.trCompat("masa_gadget_mod.message.canNotFindDespawnShape")
.withStyle(ChatFormatting.RED));
}

return ret;
Expand Down Expand Up @@ -155,21 +156,21 @@ public static void search() {
}
}

ComponentCompat text;
MutableComponentCompat text;

if (spawnPos == null) {
text = ComponentUtil.tr("masa_gadget_mod.message.noBlockCanSpawn")
text = ComponentUtil.trCompat("masa_gadget_mod.message.noBlockCanSpawn")
.withStyle(ChatFormatting.GREEN);
} else {
// for ommc parser
text = ComponentUtil.tr("masa_gadget_mod.message.spawnPos", spawnPos.getX(), spawnPos.getY(), spawnPos.getZ());
text = ComponentUtil.trCompat("masa_gadget_mod.message.spawnPos", spawnPos.getX(), spawnPos.getY(), spawnPos.getZ());

if (MagicLib.getInstance().getCurrentPlatform().isModLoaded(ModId.oh_my_minecraft_client)) {
InfoUtil.sendCommand(String.format("highlightWaypoint %d %d %d", spawnPos.getX(), spawnPos.getY(), spawnPos.getZ()));
}
}

InfoUtil.displayChatMessage(text.get());
InfoUtil.displayChatMessage(text);
}

private static double squaredDistanceTo(int x, int y, int z, Vec3 vec3d) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/plusls/MasaGadget/util/SyncUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static Entity syncEntityDataFromIntegratedServer(Entity entity) {

ServerLevel level = server.getLevel(
//#if MC > 11502
entityCompat.getLevel().get().dimension()
entityCompat.getLevel().dimension()
//#else
//$$ entity.dimension
//#endif
Expand Down

0 comments on commit fea26a2

Please sign in to comment.