Skip to content

Commit

Permalink
move to proxy
Browse files Browse the repository at this point in the history
KrLite committed Mar 9, 2024
1 parent 1e7f411 commit ffaa00b
Showing 6 changed files with 14 additions and 96 deletions.
3 changes: 2 additions & 1 deletion src/main/java/net/krlite/knowledges/KnowledgesCommon.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.krlite.knowledges;

import net.fabricmc.api.ModInitializer;
import net.krlite.knowledges.networking.KnowledgesNetworking;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@@ -10,6 +11,6 @@ public class KnowledgesCommon implements ModInitializer {

@Override
public void onInitialize() {

KnowledgesNetworking.register();
}
}
88 changes: 0 additions & 88 deletions src/main/java/net/krlite/knowledges/api/component/Knowledge.java
Original file line number Diff line number Diff line change
@@ -136,92 +136,4 @@ public static Optional<FluidState> crosshairFluidState() {
)));
}
}

@Deprecated
class Util {
@Deprecated
public static MutableText modName(String namespace) {
return Text.literal(FabricLoader.getInstance().getModContainer(namespace)
.map(ModContainer::getMetadata)
.map(ModMetadata::getName)
.orElse(""));
}

@Deprecated
public static String namespace(ItemStack itemStack) {
String namespace = Registries.ITEM.getId(itemStack.getItem()).getNamespace();

// Enchanted Book
if (itemStack.getItem() instanceof EnchantedBookItem) {
NbtList nbtList = EnchantedBookItem.getEnchantmentNbt(itemStack);
String enchantmentNamespace = null;

for (int i = 0; i < nbtList.size(); i++) {
Identifier id = Identifier.tryParse(nbtList.getCompound(i).getString("id"));
if (id != null) {
if (enchantmentNamespace == null) {
enchantmentNamespace = id.getNamespace();
} else if (!enchantmentNamespace.equals(id.getNamespace())) {
enchantmentNamespace = null;
break;
}
}
}

if (enchantmentNamespace != null) {
namespace = enchantmentNamespace;
}
}

// Potion and Tipped Arrow
if (itemStack.getItem() instanceof PotionItem || itemStack.getItem() instanceof TippedArrowItem) {
NbtCompound nbtCompound = itemStack.getNbt();
Potion potion = nbtCompound == null ? Potions.EMPTY : Potion.byId(nbtCompound.getString("Potion"));
namespace = Registries.POTION.getId(potion).getNamespace();
}

// Painting
if (itemStack.isOf(Items.PAINTING)) {
NbtCompound nbtCompound = itemStack.getNbt();
String paintingNamespace = null;

if (nbtCompound != null && nbtCompound.contains("EntityTag", 10)) {
NbtCompound entityTagCompound = nbtCompound.getCompound("EntityTag");

paintingNamespace = PaintingEntity.readVariantFromNbt(entityTagCompound)
.flatMap(RegistryEntry::getKey)
.map(RegistryKey::getRegistry)
.map(Identifier::getNamespace)
.orElse(null);
}

if (paintingNamespace != null) {
namespace = paintingNamespace;
}
}

return namespace;
}

@Deprecated
public static MutableText instrumentName(Instrument instrument) {
return KnowledgesClient.localize("instrument", instrument.asString());
}

@Deprecated
public static MutableText dateAndTime() {
if (MinecraftClient.getInstance().world == null) return Text.empty();

long time = MinecraftClient.getInstance().world.getTimeOfDay() + 24000 / 4; // Offset to morning
long day = time / 24000;
double percentage = (time % 24000) / 24000.0;

int hour = (int) (24 * percentage), minute = (int) (60 * ((percentage * 24) % 1));

return Text.translatable(
KnowledgesClient.localizationKey("util", "date_and_time"),
String.valueOf(day), String.format("%02d", hour), String.format("%02d", minute)
);
}
}
}
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@
import net.krlite.equator.visual.color.Palette;
import net.krlite.equator.visual.color.base.ColorStandard;
import net.krlite.knowledges.KnowledgesClient;
import net.krlite.knowledges.api.proxy.KnowledgeProxy;
import net.krlite.knowledges.impl.component.AbstractInfoComponent;
import net.krlite.knowledges.config.modmenu.KnowledgesConfigScreen;
import net.krlite.knowledges.api.data.DataInvoker;
@@ -89,7 +90,7 @@ public void render(@NotNull DrawContext context, @NotNull MinecraftClient client
boolean harvestable = hardness >= 0 && player.canHarvest(blockState);

String
namespace = Util.namespace(blockState.getBlock().asItem().getDefaultStack()),
namespace = KnowledgeProxy.getNamespace(blockState.getBlock().asItem().getDefaultStack()),
path = Registries.BLOCK.getId(blockState.getBlock()).getPath();

boolean resetBlockBreakingProgress = !Animation.Contextual.cancelledBlockBreaking() && Animation.Contextual.rawBlockBreakingProgress() < Animation.Ring.blockBreakingProgress();
@@ -104,7 +105,7 @@ public void render(@NotNull DrawContext context, @NotNull MinecraftClient client
// Titles
titles: {
Animation.Text.titleRight(blockName);
Animation.Text.titleLeft(Util.modName(namespace));
Animation.Text.titleLeft(KnowledgeProxy.getModName(namespace));
}

// Right Above
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@
import net.krlite.knowledges.api.component.Knowledge;
import net.krlite.knowledges.api.core.localization.EnumLocalizable;
import net.krlite.knowledges.Shortcuts;
import net.krlite.knowledges.api.proxy.KnowledgeProxy;
import net.krlite.knowledges.impl.data.info.block.AbstractBlockInformationData;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
@@ -26,7 +27,7 @@ public class NoteBlockInformationData extends AbstractBlockInformationData {
@Override
public Optional<MutableText> blockInformation(BlockState blockState, PlayerEntity player) {
if (blockState.isOf(Blocks.NOTE_BLOCK)) {
MutableText instrumentText = Knowledge.Util.instrumentName(blockState.get(NoteBlock.INSTRUMENT));
MutableText instrumentText = KnowledgeProxy.getInstrumentName(blockState.get(NoteBlock.INSTRUMENT));
MutableText noteText = KnowledgesClient.CONFIG.data.noteBlockInformation.musicalAlphabet.alphabet(
blockState.get(NoteBlock.NOTE),
KnowledgesClient.CONFIG.data.noteBlockInformation.noteModifier
@@ -36,7 +37,7 @@ public Optional<MutableText> blockInformation(BlockState blockState, PlayerEntit
}

if (player.getMainHandStack().isOf(Items.NOTE_BLOCK)) {
return Optional.of(Knowledge.Util.instrumentName(blockState.getInstrument()));
return Optional.of(KnowledgeProxy.getInstrumentName(blockState.getInstrument()));
}

return Optional.empty();
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@

import net.krlite.knowledges.api.component.Knowledge;
import net.krlite.knowledges.Shortcuts;
import net.krlite.knowledges.api.proxy.KnowledgeProxy;
import net.krlite.knowledges.impl.data.info.entity.AbstractEntityDescriptionData;
import net.krlite.knowledges.mixin.common.ItemStackInvoker;
import net.minecraft.enchantment.EnchantmentHelper;
@@ -83,7 +84,7 @@ public Optional<MutableText> entityDescription(Entity entity, PlayerEntity playe

// Description
if (heldItemStack.isOf(Items.CLOCK)) {
descriptionText = Knowledge.Util.dateAndTime();
descriptionText = KnowledgeProxy.getDateAndTime();
}

if (heldItemStack.getItem() instanceof MusicDiscItem musicDiscItem) {
Original file line number Diff line number Diff line change
@@ -6,6 +6,8 @@
import net.minecraft.util.hit.HitResult;
import net.minecraft.world.World;

import java.util.function.Supplier;

public class EmptyRepresentable extends KnowledgesRepresentable<HitResult> implements Representable<HitResult> {
public EmptyRepresentable(Builder builder) {
super(builder);
@@ -18,8 +20,8 @@ public HitResult.Type type() {

public static class Builder extends KnowledgesRepresentable.Builder<HitResult> implements Representable.Builder<HitResult, EmptyRepresentable, Builder> {
@Override
public Builder hitResult(HitResult hitResult) {
this.hitResultSupplier = hitResult;
public Builder hitResultSupplier(Supplier<HitResult> hitResultSupplier) {
this.hitResultSupplier = hitResultSupplier;
return this;
}

0 comments on commit ffaa00b

Please sign in to comment.