Skip to content

Commit

Permalink
Merge pull request #10 from RappyLabyAddons/dev
Browse files Browse the repository at this point in the history
Keep addon up-to-date, new icons, fix some stuff, support new versions
  • Loading branch information
RappyTV authored Aug 6, 2024
2 parents b073444 + acd4e31 commit f199815
Show file tree
Hide file tree
Showing 12 changed files with 355 additions and 18 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 17
- name: Set up JDK 21
uses: actions/setup-java@v3
with:
distribution: 'corretto'
java-version: '17'
java-version: '21'
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle
Expand Down
4 changes: 2 additions & 2 deletions api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ labyModProcessor {
}

java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
}
15 changes: 9 additions & 6 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
}

group = "org.example"
version = "1.0.0"
version = System.getenv().getOrDefault("VERSION", "1.0.6")

java.toolchain.languageVersion.set(JavaLanguageVersion.of(17))

Expand All @@ -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.4"
version = System.getenv().getOrDefault("VERSION", "1.0.5")
minecraftVersion = "1.8<1.21"
version = getVersion().toString()
}

minecraft {
Expand All @@ -32,7 +32,10 @@ labyMod {
"1.19.4",
"1.20.1",
"1.20.2",
"1.20.4"
"1.20.4",
"1.20.5",
"1.20.6",
"1.21"
) { version, provider ->
configureRun(provider, version)
}
Expand All @@ -45,7 +48,7 @@ labyMod {
}

addonDev {
snapshotRelease()
productionRelease()
}
}

Expand Down Expand Up @@ -75,7 +78,7 @@ fun configureRun(provider: net.labymod.gradle.core.minecraft.provider.VersionPro

provider.javaVersion = when (gameVersion) {
else -> {
JavaVersion.VERSION_17
JavaVersion.VERSION_21
}
}

Expand Down
4 changes: 2 additions & 2 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ labyModProcessor {
}

java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
package com.rappytv.headowner.widgets;

import com.rappytv.headowner.HeadOwnerAddon;
import net.labymod.api.Laby;
import net.labymod.api.client.gui.hud.binding.category.HudWidgetCategory;
import net.labymod.api.client.gui.hud.hudwidget.text.TextHudWidget;
import net.labymod.api.client.gui.hud.hudwidget.text.TextHudWidgetConfig;
import net.labymod.api.client.gui.hud.hudwidget.text.TextLine;
import net.labymod.api.client.gui.icon.Icon;
import net.labymod.api.client.resources.ResourceLocation;

public class HeadOwnerHudWidget extends TextHudWidget<TextHudWidgetConfig> {

private final HeadOwnerAddon addon;
private String name;
private String name = "";
private TextLine line;

public HeadOwnerHudWidget(HeadOwnerAddon addon) {
super("headowner");
this.addon = addon;
this.name = Laby.labyAPI().getName();
this.setIcon(Icon.texture(ResourceLocation.create(
"headowner",
"textures/widget.png"
)));
this.bindCategory(HudWidgetCategory.INGAME);
}

Expand All @@ -37,6 +41,6 @@ public void onTick(boolean isEditorContext) {

@Override
public boolean isVisibleInGame() {
return name != null && super.isVisibleInGame();
return name != null && !name.isBlank() && super.isVisibleInGame();
}
}
Binary file modified core/src/main/resources/assets/headowner/textures/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
package com.rappytv.headowner.v1_20_5;

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.item.component.ResolvableProfile;
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) {
Skull skull = new Skull(Skull.getBlockLooking(config.distance()));
if(skull.getSkullTypeName() == null) return null;
return skull.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();
ResolvableProfile owner = skullBlockEntity.getOwnerProfile();

if(owner != null && owner.isResolved()) {
GameProfile profile = owner.gameProfile();
this.username = profile.getName();
this.uuid = profile.getId();

for (Property property : owner.properties().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");
};
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
package com.rappytv.headowner.v1_20_6;

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.item.component.ResolvableProfile;
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) {
Skull skull = new Skull(Skull.getBlockLooking(config.distance()));
if(skull.getSkullTypeName() == null) return null;
return skull.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();
ResolvableProfile owner = skullBlockEntity.getOwnerProfile();

if(owner != null && owner.isResolved()) {
GameProfile profile = owner.gameProfile();
this.username = profile.getName();
this.uuid = profile.getId();

for (Property property : owner.properties().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");
};
}
}
}
Loading

0 comments on commit f199815

Please sign in to comment.