Skip to content

Commit

Permalink
Merge pull request #2 from RappyLabyAddons/feat/update
Browse files Browse the repository at this point in the history
Add support for `1.20.2`
  • Loading branch information
RappyTV authored Sep 27, 2023
2 parents 850615b + 10b041d commit 208cce4
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 9 deletions.
7 changes: 4 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ labyMod {
displayName = "Head Owner"
author = "RappyTV"
description = "Shows the owner or head type of the head you're looking at"
minecraftVersion = "1.8<1.20.1"
version = System.getenv().getOrDefault("VERSION", "1.0.1")
minecraftVersion = "1.8<1.20.2"
version = System.getenv().getOrDefault("VERSION", "1.0.2")
}

minecraft {
Expand All @@ -30,7 +30,8 @@ labyMod {
"1.19.2",
"1.19.3",
"1.19.4",
"1.20.1"
"1.20.1",
"1.20.2"
) { version, provider ->
configureRun(provider, version)
}
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/resources/assets/headowner/i18n/de_de.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"zombie": "Zombiekopf",
"player": "Spielerkopf",
"creeper": "Creeperkopf",
"dragon": "Drachenkopf"
"dragon": "Drachenkopf",
"piglin": "Piglinkopf"
},
"messages": {
"copyFormat": "Kopf Typ: %s, Spielername: %s, UUID: %s, Texturenwert: %s",
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/resources/assets/headowner/i18n/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"zombie": "Zombie Head",
"player": "Player Head",
"creeper": "Creeper Head",
"dragon": "Dragon Head"
"dragon": "Dragon Head",
"piglin": "Piglin Head"
},
"messages": {
"copyFormat": "Skull type: %s, Username: %s, UUID: %s, Texture value: %s",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ private String getSkullTypeName() {
case PLAYER -> I18n.translate("headowner.types.player");
case CREEPER -> I18n.translate("headowner.types.creeper");
case DRAGON -> I18n.translate("headowner.types.dragon");
default -> null;
case PIGLIN -> I18n.translate("headowner.types.piglin");
};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ private String getSkullTypeName() {
case PLAYER -> I18n.translate("headowner.types.player");
case CREEPER -> I18n.translate("headowner.types.creeper");
case DRAGON -> I18n.translate("headowner.types.dragon");
default -> null;
case PIGLIN -> I18n.translate("headowner.types.piglin");
};
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
package com.rappytv.headowner.v1_20_2;

import com.mojang.authlib.GameProfile;
import com.mojang.authlib.properties.Property;
import com.rappytv.headowner.api.ISkullApi;
import com.rappytv.headowner.config.HeadOwnerConfig;
import java.util.UUID;
import net.labymod.api.client.gui.screen.key.Key;
import net.labymod.api.models.Implements;
import net.labymod.api.util.I18n;
import net.minecraft.client.Minecraft;
import net.minecraft.world.level.block.SkullBlock;
import net.minecraft.world.level.block.SkullBlock.Types;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.SkullBlockEntity;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.HitResult;

@Implements(ISkullApi.class)
public class SkullApiImpl implements ISkullApi {

@Override
public String getDisplay(HeadOwnerConfig config) {
return new Skull(Skull.getBlockLooking(config.distance())).getDisplay(config.copyKey());
}

@Override
public String getCopy(HeadOwnerConfig config) {
return new Skull(Skull.getBlockLooking(config.distance())).getCopy();
}

public static class Skull {

private Types type = null;
private String username;
private UUID uuid;
private String value;

public Skull(BlockEntity blockEntity) {
if(!(blockEntity instanceof SkullBlockEntity skullBlockEntity))
return;

this.type = (Types) ((SkullBlock) skullBlockEntity.getBlockState().getBlock()).getType();
GameProfile owner = skullBlockEntity.getOwnerProfile();

if(owner != null) {
this.username = owner.getName();
this.uuid = owner.getId();

for (Property property : owner.getProperties().get("textures"))
this.value = property.value();
}
}

public static BlockEntity getBlockLooking(int distance) {
try {
Minecraft minecraft = Minecraft.getInstance();
if(minecraft.player == null) return null;
HitResult hitResult = minecraft.player.pick(distance, 0F, false);

if(minecraft.level == null) return null;

return minecraft.level.getBlockEntity(((BlockHitResult) hitResult).getBlockPos());
} catch (Exception e) {
e.printStackTrace();
return null;
}
}

public String getDisplay(Key key) {
if(this.username != null)
return this.username;

if(this.value != null) {
if(key != Key.NONE)
return I18n.translate("headowner.messages.unknownHeadKey", key.getName());

return I18n.translate("headowner.messages.unknownHead");
}

return getSkullTypeName();
}

public String getCopy() {
String uuid = this.uuid == null ? I18n.translate("headowner.messages.unknown") : this.uuid.toString();
String username = this.username == null ? I18n.translate("headowner.messages.unknown") : this.username;
String value = this.value == null ? I18n.translate("headowner.messages.unknown") : this.value;
String type = getSkullTypeName();


return I18n.translate("headowner.messages.copyFormat", type, username, uuid, value);
}

private String getSkullTypeName() {
if(this.type == null) return null;
return switch (this.type) {
case SKELETON -> I18n.translate("headowner.types.skeleton");
case WITHER_SKELETON -> I18n.translate("headowner.types.wither_skeleton");
case ZOMBIE -> I18n.translate("headowner.types.zombie");
case PLAYER -> I18n.translate("headowner.types.player");
case CREEPER -> I18n.translate("headowner.types.creeper");
case DRAGON -> I18n.translate("headowner.types.dragon");
case PIGLIN -> I18n.translate("headowner.types.piglin");
};
}
}
}
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Shows the owner or head type of the head you're looking at
### Installation
1. Press `Win` + `R`
2. Paste this into the window that popped up: `%appdata%/.minecraft/LabyMod-neo/addons` and press enter
3. It should open your Labymod addon directory; Paste the [HeadOwner.jar](https://github.com/RappyLabyAddons/HeadOwner/releases/download/v1.0.1/HeadOwner.jar) in there.
3. It should open your Labymod addon directory; Paste the [HeadOwner.jar](https://github.com/RappyLabyAddons/HeadOwner/releases/latest/download/HeadOwner.jar) in there.
4. Launch your Labymod client.

If you have any problems with the addon/have update ideas, feel free to
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
rootProject.name = "HeadOwner"

pluginManagement {
val labyGradlePluginVersion = "0.3.28"
val labyGradlePluginVersion = "0.3.29"
plugins {
id("net.labymod.gradle") version (labyGradlePluginVersion)
}
Expand Down

0 comments on commit 208cce4

Please sign in to comment.