Skip to content

Commit

Permalink
localizations
Browse files Browse the repository at this point in the history
  • Loading branch information
KrLite committed Mar 10, 2024
1 parent 7d919e5 commit 13b4f9c
Show file tree
Hide file tree
Showing 16 changed files with 205 additions and 171 deletions.
4 changes: 2 additions & 2 deletions src/main/java/net/krlite/knowledges/KnowledgesClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import net.minecraft.network.PacketByteBuf;
import net.minecraft.text.MutableText;
import net.minecraft.text.Text;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Identifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -162,6 +161,7 @@ public void onInitializeClient() {
.forEach(tag -> TAGS.register(namespace, tag));
});

if (CONFIG.global.autoTidiesUp) tidyUpConfig();
CONFIG_HOLDER.save();

if (!COMPONENTS.asMap().isEmpty()) {
Expand Down Expand Up @@ -193,7 +193,7 @@ public void onInitializeClient() {
}));
}

public static void tidyUp() {
public static void tidyUpConfig() {
COMPONENTS.tidyUp();
DATA.tidyUp();
TAGS.tidyUp();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ public interface WithPartialPath extends WithPath {

@Override
default @NotNull String path() {
return currentPath() + "." + partialPath();
return currentPath() + "/" + partialPath();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import net.minecraft.nbt.NbtCompound;

public interface AdditionalTag<R extends Representable<?>, T> extends WithPath {
boolean shouldApply(T t);
boolean isApplicableTo(T t);

Class<R> targetRepresentableClass();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void register(Object object, BooleanListEntry entry) {
.setShouldTabsSmoothScroll(true)
.setShouldListSmoothScroll(true)
.setSavingRunnable(() -> {
if (KnowledgesClient.CONFIG.global.autoTidiesUp) KnowledgesClient.tidyUp();
if (KnowledgesClient.CONFIG.global.autoTidiesUp) KnowledgesClient.tidyUpConfig();
KnowledgesClient.CONFIG_HOLDER.save();
});
private final ConfigEntryBuilder entryBuilder = configBuilder.entryBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
public abstract class AbstractBlockInfoComponentData implements Data<BlockInfoComponent>, WithPartialPath {
@Override
public @NotNull String currentPath() {
return "info.block";
return "info/block";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
public abstract class AbstractEntityInfoComponentData implements Data<EntityInfoComponent>, WithPartialPath {
@Override
public @NotNull String currentPath() {
return "info.entity";
return "info/entity";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
public abstract class AbstractBlockInformationData extends AbstractBlockInfoComponentData implements BlockInfoComponent.BlockInformationInvoker.Protocol {
@Override
public @NotNull String currentPath() {
return super.currentPath() + ".block_information";
return super.currentPath() + "/block_information";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import net.krlite.knowledges.api.tag.caster.NbtBooleanCaster;
import net.krlite.knowledges.api.tag.caster.NbtByteCaster;
import net.krlite.knowledges.impl.data.info.block.AbstractBlockInformationData;
import net.krlite.knowledges.impl.tag.block.BeehiveAdditionalTag;
import net.krlite.knowledges.impl.tag.block.BeehiveTag;
import net.minecraft.block.BeehiveBlock;
import net.minecraft.block.Blocks;
import net.minecraft.block.entity.BeehiveBlockEntity;
Expand All @@ -17,7 +17,6 @@

import java.util.Optional;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Predicate;

public class BeehiveBlockInformationData extends AbstractBlockInformationData {
@Override
Expand All @@ -33,13 +32,13 @@ public Optional<MutableText> blockInformation(BlockRepresentable representable)
);

final AtomicReference<MutableText> beeCountText = new AtomicReference<>(Text.empty());
((NbtByteCaster) BeehiveAdditionalTag.Protocol.BEES_BYTE.caster()).get(data).ifPresent(beeCount -> {
((NbtByteCaster) BeehiveTag.Protocol.BEES_BYTE.caster()).get(data).ifPresent(beeCount -> {
beeCountText.set(beeCount == 0 ? localize("bee_count", "empty") : Text.translatable(
localizationKey("bee_count"),
beeCount
));
});
((NbtBooleanCaster) BeehiveAdditionalTag.Protocol.FULL_BOOLEAN.caster()).get(data).ifPresent(full -> {
((NbtBooleanCaster) BeehiveTag.Protocol.FULL_BOOLEAN.caster()).get(data).ifPresent(full -> {
if (full) beeCountText.set(localize("bee_count", "full"));
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
public abstract class AbstractEntityDescriptionData extends AbstractEntityInfoComponentData implements EntityInfoComponent.EntityDescriptionInvoker.Protocol {
@Override
public @NotNull String currentPath() {
return super.currentPath() + ".entity_description";
return super.currentPath() + "/entity_description";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
public abstract class AbstractEntityInformationData extends AbstractEntityInfoComponentData implements EntityInfoComponent.EntityInformationInvoker.Protocol {
@Override
public @NotNull String currentPath() {
return super.currentPath() + ".entity_information";
return super.currentPath() + "/entity_information";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import net.krlite.knowledges.api.entrypoint.TagProvider;
import net.krlite.knowledges.api.tag.AdditionalTag;
import net.krlite.knowledges.impl.tag.block.BeehiveAdditionalTag;
import net.krlite.knowledges.impl.tag.block.BeehiveTag;
import org.jetbrains.annotations.NotNull;

import java.util.List;
Expand All @@ -11,7 +11,7 @@ public class KnowledgesTagProvider implements TagProvider {
@Override
public @NotNull List<Class<? extends AdditionalTag<?, ?>>> provide() {
return List.of(
BeehiveAdditionalTag.class
BeehiveTag.class
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
import net.minecraft.nbt.NbtCompound;
import org.jetbrains.annotations.NotNull;

public class BeehiveAdditionalTag implements AdditionalBlockTag {
public enum Protocol implements TagProtocol<BeehiveAdditionalTag, Protocol> {
public class BeehiveTag implements AdditionalBlockTag {
public enum Protocol implements TagProtocol<BeehiveTag, Protocol> {
BEES_BYTE(new NbtByteCaster("Bees")),
FULL_BOOLEAN(new NbtBooleanCaster("Full"));

Expand All @@ -32,7 +32,7 @@ public NbtCaster<?> caster() {
}

@Override
public boolean shouldApply(Block block) {
public boolean isApplicableTo(Block block) {
System.out.println(block);
return block instanceof BeehiveBlock;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package net.krlite.knowledges.impl.tag.entity;

import net.krlite.knowledges.api.representable.EntityRepresentable;
import net.krlite.knowledges.api.tag.AdditionalEntityTag;
import net.minecraft.entity.Entity;
import net.minecraft.entity.Ownable;
import net.minecraft.entity.passive.TameableEntity;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.server.MinecraftServer;
import net.minecraft.world.World;
import org.jetbrains.annotations.NotNull;

import java.util.UUID;

public class AnimalOwnerTag implements AdditionalEntityTag {
@Override
public boolean isApplicableTo(Entity entity) {
return true;
}

@Override
public void append(NbtCompound data, EntityRepresentable representable) {
MinecraftServer server = representable.world().getServer();
Entity entity = representable.entity();
if (server != null && server.isHost(representable.player().getGameProfile()) && entity instanceof TameableEntity)
return;

if (entity instanceof Ownable ownable && ownable.getOwner() != null) {
UUID owner = ownable.getOwner().getUuid();
}
}

@Override
public @NotNull String path() {
return "animal_owner";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ protected String localizationPrefix() {

public List<AdditionalBlockTag> byBlock(Block block) {
return ofSpecifiedType(AdditionalBlockTag.class).stream()
.filter(t -> t.shouldApply(block))
.filter(t -> t.isApplicableTo(block))
.toList();
}

public List<AdditionalEntityTag> byEntity(Entity entity) {
return ofSpecifiedType(AdditionalEntityTag.class).stream()
.filter(t -> t.shouldApply(entity))
.filter(t -> t.isApplicableTo(entity))
.toList();
}
}
Loading

0 comments on commit 13b4f9c

Please sign in to comment.