generated from KessokuTeaTime/Example-Mod
-
Notifications
You must be signed in to change notification settings - Fork 0
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
17 changed files
with
222 additions
and
91 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
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 was deleted.
Oops, something went wrong.
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
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
38 changes: 38 additions & 0 deletions
38
.../knowledges/impl/data/info/entity/entitydescription/AnimalOwnerEntityDescriptionData.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,38 @@ | ||
package net.krlite.knowledges.impl.data.info.entity.entitydescription; | ||
|
||
import net.krlite.knowledges.KnowledgesClient; | ||
import net.krlite.knowledges.api.representable.EntityRepresentable; | ||
import net.krlite.knowledges.impl.data.info.entity.AbstractEntityDescriptionData; | ||
import net.krlite.knowledges.impl.tag.entity.AnimalOwnerTag; | ||
import net.minecraft.entity.Ownable; | ||
import net.minecraft.text.MutableText; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.Optional; | ||
import java.util.UUID; | ||
import java.util.function.Function; | ||
|
||
public class AnimalOwnerEntityDescriptionData extends AbstractEntityDescriptionData { | ||
@Override | ||
public Optional<MutableText> entityDescription(EntityRepresentable representable) { | ||
if (representable.entity() instanceof Ownable ownable && ownable.getOwner() != null) { | ||
final Function<String, MutableText> localization = name -> localize("owner", name); | ||
|
||
return AnimalOwnerTag.OWNER.get(representable.data()) | ||
.map(localization) | ||
.or(() -> { | ||
UUID ownerUuid = ownable.getOwner().getUuid(); | ||
return KnowledgesClient.CACHE_USERNAME.get(ownerUuid) | ||
.map(localization) | ||
.or(() -> Optional.of(localize("owner.none"))); | ||
}); | ||
} | ||
|
||
return Optional.empty(); | ||
} | ||
|
||
@Override | ||
public @NotNull String partialPath() { | ||
return "animal_owner"; | ||
} | ||
} |
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
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
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
19 changes: 19 additions & 0 deletions
19
src/main/java/net/krlite/knowledges/mixin/client/ClientWorldMixin.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,19 @@ | ||
package net.krlite.knowledges.mixin.client; | ||
|
||
import net.krlite.knowledges.KnowledgesClient; | ||
import net.minecraft.client.world.ClientWorld; | ||
import net.minecraft.entity.Entity; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
@Mixin(ClientWorld.class) | ||
public class ClientWorldMixin { | ||
@Inject(method = "addEntity", at = @At("HEAD")) | ||
private void addPlayer(Entity entity, CallbackInfo ci) { | ||
if (entity instanceof PlayerEntity player) | ||
KnowledgesClient.CACHE_USERNAME.put(player); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
src/main/java/net/krlite/knowledges/networking/ClientNetworking.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,41 @@ | ||
package net.krlite.knowledges.networking; | ||
|
||
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents; | ||
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; | ||
import net.fabricmc.fabric.api.networking.v1.PacketSender; | ||
import net.krlite.knowledges.KnowledgesClient; | ||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.client.network.ClientPlayNetworkHandler; | ||
import net.minecraft.nbt.NbtCompound; | ||
import net.minecraft.network.PacketByteBuf; | ||
|
||
public class ClientNetworking implements KnowledgesNetworking { | ||
@Override | ||
public void register() { | ||
ClientPlayNetworking.registerGlobalReceiver(KnowledgesNetworking.PACKET_RECEIVE_DATA, new ReceiveData()); | ||
ClientPlayNetworking.registerGlobalReceiver(KnowledgesNetworking.PACKET_SERVER_PING, new ServerPing()); | ||
ClientPlayConnectionEvents.DISCONNECT.register(new PlayerDisconnect()); | ||
} | ||
|
||
public static class ReceiveData implements ClientPlayNetworking.PlayChannelHandler { | ||
@Override | ||
public void receive(MinecraftClient client, ClientPlayNetworkHandler handler, PacketByteBuf buf, PacketSender responseSender) { | ||
NbtCompound compound = buf.readNbt(); | ||
client.execute(() -> KnowledgesClient.HUD.onReceiveData(compound)); | ||
} | ||
} | ||
|
||
public static class ServerPing implements ClientPlayNetworking.PlayChannelHandler { | ||
@Override | ||
public void receive(MinecraftClient client, ClientPlayNetworkHandler handler, PacketByteBuf buf, PacketSender responseSender) { | ||
client.execute(() -> KnowledgesClient.HUD.setConnectionStatus(true)); | ||
} | ||
} | ||
|
||
public static class PlayerDisconnect implements ClientPlayConnectionEvents.Disconnect { | ||
@Override | ||
public void onPlayDisconnect(ClientPlayNetworkHandler handler, MinecraftClient client) { | ||
KnowledgesClient.HUD.setConnectionStatus(false); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.