diff --git a/common/src/main/java/net/anvilcraft/anvillib/AnvilLib.java b/common/src/main/java/net/anvilcraft/anvillib/AnvilLib.java index dd0bfd5..a96814b 100644 --- a/common/src/main/java/net/anvilcraft/anvillib/AnvilLib.java +++ b/common/src/main/java/net/anvilcraft/anvillib/AnvilLib.java @@ -18,5 +18,4 @@ public class AnvilLib { public static void initializeClient() { Bus.MAIN.register(new ClientEventHandler()); } - } diff --git a/common/src/main/java/net/anvilcraft/anvillib/cosmetics/ClientEventHandler.java b/common/src/main/java/net/anvilcraft/anvillib/cosmetics/ClientEventHandler.java index 0379e2c..2982abb 100644 --- a/common/src/main/java/net/anvilcraft/anvillib/cosmetics/ClientEventHandler.java +++ b/common/src/main/java/net/anvilcraft/anvillib/cosmetics/ClientEventHandler.java @@ -15,9 +15,9 @@ import net.minecraft.client.render.entity.PlayerEntityRenderer; import net.minecraft.entity.player.PlayerEntity; public class ClientEventHandler implements IEventBusRegisterable { - private void onAddLayers(AddEntityRenderLayersEvent ev) { - for (Entry> skin : ev.skinMap().entrySet()) + for (Entry> skin : + ev.skinMap().entrySet()) if (skin.getValue() instanceof PlayerEntityRenderer render) render.addFeature(new CosmeticFeatureRenderer(render, skin.getKey())); } @@ -28,7 +28,9 @@ public class ClientEventHandler implements IEventBusRegisterable { URI playerBase = new URI("https://api.tilera.xyz/anvillib/data/players/"); URI cosmeticBase = new URI("https://api.tilera.xyz/anvillib/data/cosmetics/"); URI capeBase = new URI("https://api.tilera.xyz/anvillib/data/capes/"); - CosmeticsManager.registerProvider(new RemoteCosmeticProvider(playerBase, cosmeticBase, capeBase, cacheDir)); + CosmeticsManager.registerProvider( + new RemoteCosmeticProvider(playerBase, cosmeticBase, capeBase, cacheDir) + ); } catch (Exception e) { AnvilLib.LOGGER.error(e); } diff --git a/common/src/main/java/net/anvilcraft/anvillib/cosmetics/CosmeticArmorRenderer.java b/common/src/main/java/net/anvilcraft/anvillib/cosmetics/CosmeticArmorRenderer.java index 5c5ab61..91d3277 100644 --- a/common/src/main/java/net/anvilcraft/anvillib/cosmetics/CosmeticArmorRenderer.java +++ b/common/src/main/java/net/anvilcraft/anvillib/cosmetics/CosmeticArmorRenderer.java @@ -113,7 +113,9 @@ public class CosmeticArmorRenderer extends BipedEntityModel poseStack.scale(-1, -1, 1); double currentTick = entityLiving.age; // TODO: Custom frametime/animation speed - currentFrame = ((int)(currentTick * 1.0F)) % this.getCurrentCosmetic().getTotalFrames();; + currentFrame + = ((int) (currentTick * 1.0F)) % this.getCurrentCosmetic().getTotalFrames(); + ; //this.dispatchedMat = poseStack.last().pose().copy(); this.dispatchedMat = poseStack.peek().getPositionMatrix().copy(); @@ -406,20 +408,46 @@ public class CosmeticArmorRenderer extends BipedEntityModel } public float calcVOffset(float v) { - float totalFrames = (float)this.getCurrentCosmetic().getTotalFrames(); - float currentTextureOffset = (float)currentFrame / totalFrames; - return (v / totalFrames) + currentTextureOffset; - } + float totalFrames = (float) this.getCurrentCosmetic().getTotalFrames(); + float currentTextureOffset = (float) currentFrame / totalFrames; + return (v / totalFrames) + currentTextureOffset; + } - @Override - public void createVerticesOfQuad(GeoQuad quad, Matrix4f poseState, Vec3f normal, VertexConsumer buffer, - int packedLight, int packedOverlay, float red, float green, float blue, float alpha) { - for (GeoVertex vertex : quad.vertices) { - Vector4f vector4f = new Vector4f(vertex.position.getX(), vertex.position.getY(), vertex.position.getZ(), 1); + @Override + public void createVerticesOfQuad( + GeoQuad quad, + Matrix4f poseState, + Vec3f normal, + VertexConsumer buffer, + int packedLight, + int packedOverlay, + float red, + float green, + float blue, + float alpha + ) { + for (GeoVertex vertex : quad.vertices) { + Vector4f vector4f = new Vector4f( + vertex.position.getX(), vertex.position.getY(), vertex.position.getZ(), 1 + ); - vector4f.transform(poseState); - buffer.vertex(vector4f.getX(), vector4f.getY(), vector4f.getZ(), red, green, blue, alpha, vertex.textureU, - calcVOffset(vertex.textureV), packedOverlay, packedLight, normal.getX(), normal.getY(), normal.getZ()); - } - } + vector4f.transform(poseState); + buffer.vertex( + vector4f.getX(), + vector4f.getY(), + vector4f.getZ(), + red, + green, + blue, + alpha, + vertex.textureU, + calcVOffset(vertex.textureV), + packedOverlay, + packedLight, + normal.getX(), + normal.getY(), + normal.getZ() + ); + } + } } diff --git a/common/src/main/java/net/anvilcraft/anvillib/cosmetics/CosmeticFeatureRenderer.java b/common/src/main/java/net/anvilcraft/anvillib/cosmetics/CosmeticFeatureRenderer.java index 1073fbb..67bb795 100644 --- a/common/src/main/java/net/anvilcraft/anvillib/cosmetics/CosmeticFeatureRenderer.java +++ b/common/src/main/java/net/anvilcraft/anvillib/cosmetics/CosmeticFeatureRenderer.java @@ -43,7 +43,8 @@ public class CosmeticFeatureRenderer extends ArmorFeatureRenderer< float netHeadYaw, float headPitch ) { - if (player.isInvisible()) return; + if (player.isInvisible()) + return; for (ICosmetic c : CosmeticsManager.getCosmeticsForPlayer(player.getUuid())) { if (c.readyToRender()) this.renderCosmetic(matrix, buffer, player, light, c, partialTicks); diff --git a/common/src/main/java/net/anvilcraft/anvillib/cosmetics/CosmeticItem.java b/common/src/main/java/net/anvilcraft/anvillib/cosmetics/CosmeticItem.java index 6aa3b57..e7c1faf 100644 --- a/common/src/main/java/net/anvilcraft/anvillib/cosmetics/CosmeticItem.java +++ b/common/src/main/java/net/anvilcraft/anvillib/cosmetics/CosmeticItem.java @@ -17,7 +17,9 @@ public class CosmeticItem implements IAnimatable { public CosmeticItem(ICosmetic cosmetic) { this.cosmetic = cosmetic; if (cosmetic.getIdleAnimationName() != null) { - this.animationBuilder.addAnimation(cosmetic.getIdleAnimationName(), EDefaultLoopTypes.LOOP); + this.animationBuilder.addAnimation( + cosmetic.getIdleAnimationName(), EDefaultLoopTypes.LOOP + ); } } diff --git a/common/src/main/java/net/anvilcraft/anvillib/cosmetics/CosmeticModel.java b/common/src/main/java/net/anvilcraft/anvillib/cosmetics/CosmeticModel.java index a3fed3d..2681a1f 100644 --- a/common/src/main/java/net/anvilcraft/anvillib/cosmetics/CosmeticModel.java +++ b/common/src/main/java/net/anvilcraft/anvillib/cosmetics/CosmeticModel.java @@ -28,20 +28,22 @@ public class CosmeticModel extends AnimatedGeoModel { } @Override - public Animation getAnimation(String name, IAnimatable animatable) { - Identifier location = ((CosmeticItem)animatable).getCosmetic().getAnimationFileLocation(); - AnimationFile animation = CosmeticsManager.getAnimations(location); + public Animation getAnimation(String name, IAnimatable animatable) { + Identifier location + = ((CosmeticItem) animatable).getCosmetic().getAnimationFileLocation(); + AnimationFile animation = CosmeticsManager.getAnimations(location); if (animation == null) { animation = GeckoLibCache.getInstance().getAnimations().get(location); } - - if (animation == null) { - throw new GeckoLibException(location, - "Could not find animation file. Please double check name."); - } - return animation.getAnimation(name); - } + if (animation == null) { + throw new GeckoLibException( + location, "Could not find animation file. Please double check name." + ); + } + + return animation.getAnimation(name); + } @Override public GeoModel getModel(Identifier location) { @@ -50,16 +52,16 @@ public class CosmeticModel extends AnimatedGeoModel { model = GeckoLibCache.getInstance().getGeoModels().get(location); } - AnimatedGeoModelAccessor accessor = (AnimatedGeoModelAccessor)this; + AnimatedGeoModelAccessor accessor = (AnimatedGeoModelAccessor) this; if (model != accessor.getCurrentModel()) { - accessor.getAnimationProcessor().clearModelRendererList(); - accessor.setCurrentModel(model); + accessor.getAnimationProcessor().clearModelRendererList(); + accessor.setCurrentModel(model); - for (GeoBone bone : model.topLevelBones) { - registerBone(bone); - } - } + for (GeoBone bone : model.topLevelBones) { + registerBone(bone); + } + } - return model; + return model; } } diff --git a/common/src/main/java/net/anvilcraft/anvillib/cosmetics/CosmeticParts.java b/common/src/main/java/net/anvilcraft/anvillib/cosmetics/CosmeticParts.java index 7c66d6c..5323ec7 100644 --- a/common/src/main/java/net/anvilcraft/anvillib/cosmetics/CosmeticParts.java +++ b/common/src/main/java/net/anvilcraft/anvillib/cosmetics/CosmeticParts.java @@ -20,13 +20,12 @@ public class CosmeticParts { public final String rightArmName = "arm_right"; public final String rightLegName = "leg_right"; - public CosmeticParts() { - - } + public CosmeticParts() {} public CosmeticParts(GeoModel model) { Optional maybeRoot = model.getBone("root"); - if (maybeRoot.isEmpty()) return; + if (maybeRoot.isEmpty()) + return; GeoBone root = maybeRoot.get(); for (GeoBone bone : root.childBones) { switch (bone.name) { @@ -51,5 +50,4 @@ public class CosmeticParts { } } } - } diff --git a/common/src/main/java/net/anvilcraft/anvillib/cosmetics/CosmeticsManager.java b/common/src/main/java/net/anvilcraft/anvillib/cosmetics/CosmeticsManager.java index 51dd6a0..7fb7bd3 100644 --- a/common/src/main/java/net/anvilcraft/anvillib/cosmetics/CosmeticsManager.java +++ b/common/src/main/java/net/anvilcraft/anvillib/cosmetics/CosmeticsManager.java @@ -19,7 +19,8 @@ public class CosmeticsManager { private static Map capeCache = new HashMap<>(); private static Set activePlayers = new HashSet<>(); private static Map cachedModels = new ConcurrentHashMap<>(); - private static Map cachedAnimations = new ConcurrentHashMap<>(); + private static Map cachedAnimations + = new ConcurrentHashMap<>(); private static void refresh() { boolean doRefresh = false; @@ -43,7 +44,8 @@ public class CosmeticsManager { provider.addCosmetics(player, (cosmetic) -> cosmetics.add(cosmetic)); if (!capeCache.containsKey(player)) { Identifier cape = provider.getCape(player); - if (cape != null) capeCache.put(player, cape); + if (cape != null) + capeCache.put(player, cape); } } } @@ -81,5 +83,4 @@ public class CosmeticsManager { public static void loadAnimations(Identifier id, AnimationFile animations) { cachedAnimations.put(id, animations); } - } diff --git a/common/src/main/java/net/anvilcraft/anvillib/cosmetics/ICosmetic.java b/common/src/main/java/net/anvilcraft/anvillib/cosmetics/ICosmetic.java index 3232bcc..cb179cb 100644 --- a/common/src/main/java/net/anvilcraft/anvillib/cosmetics/ICosmetic.java +++ b/common/src/main/java/net/anvilcraft/anvillib/cosmetics/ICosmetic.java @@ -46,5 +46,4 @@ public interface ICosmetic { default int getTotalFrames() { return 1; } - } diff --git a/common/src/main/java/net/anvilcraft/anvillib/cosmetics/remote/RemoteCosmetic.java b/common/src/main/java/net/anvilcraft/anvillib/cosmetics/remote/RemoteCosmetic.java index beb2a1b..87f4940 100644 --- a/common/src/main/java/net/anvilcraft/anvillib/cosmetics/remote/RemoteCosmetic.java +++ b/common/src/main/java/net/anvilcraft/anvillib/cosmetics/remote/RemoteCosmetic.java @@ -10,7 +10,6 @@ import software.bernie.geckolib3.file.AnimationFile; import software.bernie.geckolib3.geo.render.built.GeoModel; public class RemoteCosmetic implements ICosmetic { - private Identifier id; private boolean loadedModel = false; private boolean loadedTexture = false; @@ -24,9 +23,9 @@ public class RemoteCosmetic implements ICosmetic { public RemoteCosmetic(String id) { this.id = new Identifier("anvillib", id); - this.modelLocation = new Identifier("anvillib", "models/remote/"+id); - this.textureLocation = new Identifier("anvillib", "textures/remote/"+id); - this.animationsLocation = new Identifier("anvillib", "animations/remote/"+id); + this.modelLocation = new Identifier("anvillib", "models/remote/" + id); + this.textureLocation = new Identifier("anvillib", "textures/remote/" + id); + this.animationsLocation = new Identifier("anvillib", "animations/remote/" + id); } @Override @@ -114,5 +113,4 @@ public class RemoteCosmetic implements ICosmetic { public int getTotalFrames() { return this.frameCount; } - } diff --git a/common/src/main/java/net/anvilcraft/anvillib/cosmetics/remote/RemoteCosmeticProvider.java b/common/src/main/java/net/anvilcraft/anvillib/cosmetics/remote/RemoteCosmeticProvider.java index 836a6ee..f32c4a2 100644 --- a/common/src/main/java/net/anvilcraft/anvillib/cosmetics/remote/RemoteCosmeticProvider.java +++ b/common/src/main/java/net/anvilcraft/anvillib/cosmetics/remote/RemoteCosmeticProvider.java @@ -22,7 +22,6 @@ import net.minecraft.util.Identifier; import net.minecraft.util.Util; public class RemoteCosmeticProvider implements ICosmeticProvider { - public static RemoteCosmeticProvider INSTANCE = null; public final Map cosmetics = new ConcurrentHashMap<>(); @@ -38,7 +37,9 @@ public class RemoteCosmeticProvider implements ICosmeticProvider { public final URI capeBase; private final File cacheDir; - public RemoteCosmeticProvider(URI playerBase, URI cosmeticBase, URI capeBase, File cacheDir) { + public RemoteCosmeticProvider( + URI playerBase, URI cosmeticBase, URI capeBase, File cacheDir + ) { this.playerBase = playerBase; this.cosmeticBase = cosmeticBase; this.capeBase = capeBase; @@ -55,7 +56,9 @@ public class RemoteCosmeticProvider implements ICosmeticProvider { this.dirty = false; if (playerCosmetics.containsKey(player)) { for (String id : playerCosmetics.get(player)) { - if (!this.cosmetics.containsKey(id) || !this.cosmetics.get(id).readyToRender()) continue; + if (!this.cosmetics.containsKey(id) + || !this.cosmetics.get(id).readyToRender()) + continue; cosmeticAdder.accept(this.cosmetics.get(id)); } } else { @@ -69,13 +72,14 @@ public class RemoteCosmeticProvider implements ICosmeticProvider { @Override public Identifier getCape(UUID player) { - if (!this.playerCapes.containsKey(player)) return null; + if (!this.playerCapes.containsKey(player)) + return null; String cape = this.playerCapes.get(player); return this.capes.getOrDefault(cape, null); } public void markDirty() { - synchronized(this) { + synchronized (this) { this.dirty = true; } } @@ -87,26 +91,31 @@ public class RemoteCosmeticProvider implements ICosmeticProvider { } public void loadCosmetic(String id) throws MalformedURLException { - if (this.cosmetics.containsKey(id) || this.knownCosmetics.containsKey(id)) return; + if (this.cosmetics.containsKey(id) || this.knownCosmetics.containsKey(id)) + return; this.knownCosmetics.put(id, true); URI url = cosmeticBase.resolve(id); Util.getMainWorkerExecutor().execute(new CosmeticLoaderThread(url, this)); } public void loadAssets(CosmeticData data, RemoteCosmetic cosmetic) { - Util.getMainWorkerExecutor().execute(new CosmeticAssetsLoaderThread(cosmetic, data, this.cacheDir, this)); + Util.getMainWorkerExecutor().execute( + new CosmeticAssetsLoaderThread(cosmetic, data, this.cacheDir, this) + ); } public void loadCape(String id) throws MalformedURLException { - if (this.capes.containsKey(id) || this.knownCapes.containsKey(id)) return; + if (this.capes.containsKey(id) || this.knownCapes.containsKey(id)) + return; this.knownCapes.put(id, true); URI url = capeBase.resolve(id); - Util.getMainWorkerExecutor().execute(new CapeLoaderThread(id, url, this.cacheDir, this)); + Util.getMainWorkerExecutor().execute( + new CapeLoaderThread(id, url, this.cacheDir, this) + ); } public void failCosmeticLoading(String id) { AnvilLib.LOGGER.error("Cosmetic loading failed: {}", id); this.cosmetics.remove(id); } - } diff --git a/common/src/main/java/net/anvilcraft/anvillib/cosmetics/remote/model/AnimationData.java b/common/src/main/java/net/anvilcraft/anvillib/cosmetics/remote/model/AnimationData.java index 642d171..474ca03 100644 --- a/common/src/main/java/net/anvilcraft/anvillib/cosmetics/remote/model/AnimationData.java +++ b/common/src/main/java/net/anvilcraft/anvillib/cosmetics/remote/model/AnimationData.java @@ -4,11 +4,9 @@ import com.google.gson.annotations.Expose; import com.google.gson.annotations.SerializedName; public class AnimationData { - @Expose public String url; @Expose @SerializedName("idle_animation") public String idleAnimation; - } diff --git a/common/src/main/java/net/anvilcraft/anvillib/cosmetics/remote/model/CosmeticData.java b/common/src/main/java/net/anvilcraft/anvillib/cosmetics/remote/model/CosmeticData.java index b383818..252997e 100644 --- a/common/src/main/java/net/anvilcraft/anvillib/cosmetics/remote/model/CosmeticData.java +++ b/common/src/main/java/net/anvilcraft/anvillib/cosmetics/remote/model/CosmeticData.java @@ -4,7 +4,6 @@ import com.google.gson.annotations.Expose; import com.google.gson.annotations.SerializedName; public class CosmeticData { - @Expose public String id; @Expose @@ -16,5 +15,4 @@ public class CosmeticData { @Expose @SerializedName("texture_data") public TextureData textureData; - } diff --git a/common/src/main/java/net/anvilcraft/anvillib/cosmetics/remote/model/PlayerData.java b/common/src/main/java/net/anvilcraft/anvillib/cosmetics/remote/model/PlayerData.java index 9be6aef..a263651 100644 --- a/common/src/main/java/net/anvilcraft/anvillib/cosmetics/remote/model/PlayerData.java +++ b/common/src/main/java/net/anvilcraft/anvillib/cosmetics/remote/model/PlayerData.java @@ -6,12 +6,10 @@ import java.util.UUID; import com.google.gson.annotations.Expose; public class PlayerData { - @Expose public UUID uuid; @Expose public List cosmetics; @Expose public String cape; - } diff --git a/common/src/main/java/net/anvilcraft/anvillib/cosmetics/remote/model/TextureData.java b/common/src/main/java/net/anvilcraft/anvillib/cosmetics/remote/model/TextureData.java index 347702c..13df323 100644 --- a/common/src/main/java/net/anvilcraft/anvillib/cosmetics/remote/model/TextureData.java +++ b/common/src/main/java/net/anvilcraft/anvillib/cosmetics/remote/model/TextureData.java @@ -4,11 +4,9 @@ import com.google.gson.annotations.Expose; import com.google.gson.annotations.SerializedName; public class TextureData { - @Expose public String url; @Expose @SerializedName("total_frames") public int frameCount; - } diff --git a/common/src/main/java/net/anvilcraft/anvillib/cosmetics/remote/thread/CapeLoaderThread.java b/common/src/main/java/net/anvilcraft/anvillib/cosmetics/remote/thread/CapeLoaderThread.java index b4dbbdb..6272344 100644 --- a/common/src/main/java/net/anvilcraft/anvillib/cosmetics/remote/thread/CapeLoaderThread.java +++ b/common/src/main/java/net/anvilcraft/anvillib/cosmetics/remote/thread/CapeLoaderThread.java @@ -17,14 +17,16 @@ import net.minecraft.client.texture.TextureManager; import net.minecraft.util.Identifier; public class CapeLoaderThread extends FileDownloaderThread { - private String id; private File cacheDir; private URI url; private RemoteCosmeticProvider provider; - private TextureManager textureManager = MinecraftClient.getInstance().getTextureManager(); + private TextureManager textureManager + = MinecraftClient.getInstance().getTextureManager(); - public CapeLoaderThread(String id, URI url, File cacheDir, RemoteCosmeticProvider provider) { + public CapeLoaderThread( + String id, URI url, File cacheDir, RemoteCosmeticProvider provider + ) { super("0.2.0"); this.id = id; this.url = url; @@ -42,17 +44,22 @@ public class CapeLoaderThread extends FileDownloaderThread { AnvilLib.LOGGER.error("Can't load cape: {}", id, e); return; } - Identifier location = new Identifier("anvillib", "textures/cape/"+data.id); + Identifier location = new Identifier("anvillib", "textures/cape/" + data.id); String hash = Hashing.sha1().hashUnencodedChars(data.id).toString(); - AbstractTexture texture = this.textureManager.getOrDefault(location, MissingSprite.getMissingSpriteTexture()); + AbstractTexture texture = this.textureManager.getOrDefault( + location, MissingSprite.getMissingSpriteTexture() + ); if (texture == MissingSprite.getMissingSpriteTexture()) { - File file = new File(this.cacheDir, hash.length() > 2 ? hash.substring(0, 2) : "xx"); + File file = new File( + this.cacheDir, hash.length() > 2 ? hash.substring(0, 2) : "xx" + ); File file2 = new File(file, hash); - texture = new PlayerSkinTexture(file2, data.url, new Identifier("textures/block/dirt.png"), false, null); + texture = new PlayerSkinTexture( + file2, data.url, new Identifier("textures/block/dirt.png"), false, null + ); this.textureManager.registerTexture(location, texture); } this.provider.capes.put(data.id, location); this.provider.markDirty(); } - } diff --git a/common/src/main/java/net/anvilcraft/anvillib/cosmetics/remote/thread/CosmeticAssetsLoaderThread.java b/common/src/main/java/net/anvilcraft/anvillib/cosmetics/remote/thread/CosmeticAssetsLoaderThread.java index e161980..9b98b81 100644 --- a/common/src/main/java/net/anvilcraft/anvillib/cosmetics/remote/thread/CosmeticAssetsLoaderThread.java +++ b/common/src/main/java/net/anvilcraft/anvillib/cosmetics/remote/thread/CosmeticAssetsLoaderThread.java @@ -36,15 +36,20 @@ import software.bernie.geckolib3.geo.render.built.GeoModel; import software.bernie.geckolib3.util.json.JsonAnimationUtils; public class CosmeticAssetsLoaderThread extends FileDownloaderThread { - private RemoteCosmetic cosmetic; private CosmeticData data; private MolangParser parser = new MolangParser(); - private TextureManager textureManager = MinecraftClient.getInstance().getTextureManager(); + private TextureManager textureManager + = MinecraftClient.getInstance().getTextureManager(); private File cacheDir; private RemoteCosmeticProvider provider; - public CosmeticAssetsLoaderThread(RemoteCosmetic cosmetic, CosmeticData data, File cacheDir, RemoteCosmeticProvider provider) { + public CosmeticAssetsLoaderThread( + RemoteCosmetic cosmetic, + CosmeticData data, + File cacheDir, + RemoteCosmeticProvider provider + ) { super("0.2.0"); this.cosmetic = cosmetic; this.data = data; @@ -71,7 +76,9 @@ public class CosmeticAssetsLoaderThread extends FileDownloaderThread { JsonObject data = this.loadJson(url, JsonObject.class); animations = this.buildAnimationFile(data); } catch (IOException | URISyntaxException | NullPointerException e) { - AnvilLib.LOGGER.error("Could not load animation: {}", this.data.animationData.url, e); + AnvilLib.LOGGER.error( + "Could not load animation: {}", this.data.animationData.url, e + ); } this.cosmetic.loadAnimations(animations, anim); } @@ -79,12 +86,20 @@ public class CosmeticAssetsLoaderThread extends FileDownloaderThread { @SuppressWarnings("deprecation") private void loadTexture(TextureData data) { String hash = Hashing.sha1().hashUnencodedChars(this.data.id).toString(); - AbstractTexture texture = this.textureManager.getOrDefault(this.cosmetic.getTextureLocation(), MissingSprite.getMissingSpriteTexture()); + AbstractTexture texture = this.textureManager.getOrDefault( + this.cosmetic.getTextureLocation(), MissingSprite.getMissingSpriteTexture() + ); if (texture == MissingSprite.getMissingSpriteTexture()) { - File file = new File(this.cacheDir, hash.length() > 2 ? hash.substring(0, 2) : "xx"); + File file = new File( + this.cacheDir, hash.length() > 2 ? hash.substring(0, 2) : "xx" + ); File file2 = new File(file, hash); - texture = new PlayerSkinTexture(file2, data.url, new Identifier("textures/block/dirt.png"), false, null); - this.textureManager.registerTexture(this.cosmetic.getTextureLocation(), texture); + texture = new PlayerSkinTexture( + file2, data.url, new Identifier("textures/block/dirt.png"), false, null + ); + this.textureManager.registerTexture( + this.cosmetic.getTextureLocation(), texture + ); } this.cosmetic.loadTexture(data); } @@ -95,7 +110,9 @@ public class CosmeticAssetsLoaderThread extends FileDownloaderThread { String data = Objects.requireNonNull(this.getStringForURL(uri)); GeoModel model = this.buildModel(data); this.cosmetic.loadModel(model); - } catch (NullPointerException | URISyntaxException | IOException | GeckoLibException e) { + } catch ( + NullPointerException | URISyntaxException | IOException | GeckoLibException e + ) { AnvilLib.LOGGER.error("Can't load remote model: {}", url, e); this.handleFailure(); } @@ -107,29 +124,33 @@ public class CosmeticAssetsLoaderThread extends FileDownloaderThread { private AnimationFile buildAnimationFile(JsonObject json) { AnimationFile animationFile = new AnimationFile(); - for (Map.Entry entry : JsonAnimationUtils.getAnimations(json)) { - String animationName = entry.getKey(); - Animation animation; - try { - animation = JsonAnimationUtils.deserializeJsonToAnimation( - JsonAnimationUtils.getAnimation(json, animationName), parser); - animationFile.putAnimation(animationName, animation); - } catch (Exception e) { - AnvilLib.LOGGER.error("Could not load animation: {}", animationName, e); - throw new RuntimeException(e); - } - } - return animationFile; + for (Map.Entry entry : + JsonAnimationUtils.getAnimations(json)) { + String animationName = entry.getKey(); + Animation animation; + try { + animation = JsonAnimationUtils.deserializeJsonToAnimation( + JsonAnimationUtils.getAnimation(json, animationName), parser + ); + animationFile.putAnimation(animationName, animation); + } catch (Exception e) { + AnvilLib.LOGGER.error("Could not load animation: {}", animationName, e); + throw new RuntimeException(e); + } + } + return animationFile; } private GeoModel buildModel(String json) throws IOException { Identifier location = this.cosmetic.getModelLocation(); RawGeoModel rawModel = Converter.fromJsonString(json); - if (rawModel.getFormatVersion() != FormatVersion.VERSION_1_12_0) { - throw new GeckoLibException(location, "Wrong geometry json version, expected 1.12.0"); - } - RawGeometryTree rawGeometryTree = RawGeometryTree.parseHierarchy(rawModel); - return GeoBuilder.getGeoBuilder(location.getNamespace()).constructGeoModel(rawGeometryTree); + if (rawModel.getFormatVersion() != FormatVersion.VERSION_1_12_0) { + throw new GeckoLibException( + location, "Wrong geometry json version, expected 1.12.0" + ); + } + RawGeometryTree rawGeometryTree = RawGeometryTree.parseHierarchy(rawModel); + return GeoBuilder.getGeoBuilder(location.getNamespace()) + .constructGeoModel(rawGeometryTree); } - } diff --git a/common/src/main/java/net/anvilcraft/anvillib/cosmetics/remote/thread/CosmeticLoaderThread.java b/common/src/main/java/net/anvilcraft/anvillib/cosmetics/remote/thread/CosmeticLoaderThread.java index a39523e..af6a227 100644 --- a/common/src/main/java/net/anvilcraft/anvillib/cosmetics/remote/thread/CosmeticLoaderThread.java +++ b/common/src/main/java/net/anvilcraft/anvillib/cosmetics/remote/thread/CosmeticLoaderThread.java @@ -9,9 +9,8 @@ import net.anvilcraft.anvillib.cosmetics.remote.RemoteCosmeticProvider; import net.anvilcraft.anvillib.cosmetics.remote.model.CosmeticData; public class CosmeticLoaderThread extends FileDownloaderThread { - private URI url; - private RemoteCosmeticProvider provider; + private RemoteCosmeticProvider provider; public CosmeticLoaderThread(URI url, RemoteCosmeticProvider provider) { super("0.2.0"); @@ -23,7 +22,8 @@ public class CosmeticLoaderThread extends FileDownloaderThread { public void run() { try { CosmeticData data = this.loadJson(url, CosmeticData.class); - if (data == null) throw new IOException("Cosmetic not found"); + if (data == null) + throw new IOException("Cosmetic not found"); RemoteCosmetic cosmetic = new RemoteCosmetic(data.id); this.provider.cosmetics.put(data.id, cosmetic); this.provider.loadAssets(data, cosmetic); @@ -31,5 +31,4 @@ public class CosmeticLoaderThread extends FileDownloaderThread { AnvilLib.LOGGER.error("Can't load cosmetic", e); } } - } diff --git a/common/src/main/java/net/anvilcraft/anvillib/cosmetics/remote/thread/FileDownloaderThread.java b/common/src/main/java/net/anvilcraft/anvillib/cosmetics/remote/thread/FileDownloaderThread.java index 470e3ca..4c8c48a 100644 --- a/common/src/main/java/net/anvilcraft/anvillib/cosmetics/remote/thread/FileDownloaderThread.java +++ b/common/src/main/java/net/anvilcraft/anvillib/cosmetics/remote/thread/FileDownloaderThread.java @@ -16,7 +16,6 @@ import com.google.gson.JsonSyntaxException; import net.anvilcraft.anvillib.AnvilLib; public abstract class FileDownloaderThread implements Runnable { - protected Gson gson = new GsonBuilder().create(); protected HttpClient client = HttpClient.newBuilder().build(); protected final String version; @@ -39,9 +38,10 @@ public abstract class FileDownloaderThread implements Runnable { HttpRequest req = this.buildRequest(url); InputStream is = null; try { - HttpResponse res = client.send(req, HttpResponse.BodyHandlers.ofInputStream()); + HttpResponse res + = client.send(req, HttpResponse.BodyHandlers.ofInputStream()); if (res.statusCode() == 200) { - is = res.body(); + is = res.body(); } else if (res.statusCode() != 404) { AnvilLib.LOGGER.error("Unexpected status code: {}", res.statusCode()); } @@ -55,9 +55,10 @@ public abstract class FileDownloaderThread implements Runnable { HttpRequest req = this.buildRequest(url); String is = null; try { - HttpResponse res = client.send(req, HttpResponse.BodyHandlers.ofString()); + HttpResponse res + = client.send(req, HttpResponse.BodyHandlers.ofString()); if (res.statusCode() == 200) { - is = res.body(); + is = res.body(); } else if (res.statusCode() != 404) { AnvilLib.LOGGER.error("Unexpected status code: {}", res.statusCode()); } @@ -69,15 +70,15 @@ public abstract class FileDownloaderThread implements Runnable { public T loadJson(URI url, Class type) throws IOException { InputStream stream = this.getStreamForURL(url); - if (stream == null) return null; + if (stream == null) + return null; try { T json = this.gson.fromJson(new InputStreamReader(stream), type); return json; - } catch(JsonSyntaxException | JsonIOException e) { + } catch (JsonSyntaxException | JsonIOException e) { throw new IOException(e); } finally { stream.close(); } } - } diff --git a/common/src/main/java/net/anvilcraft/anvillib/cosmetics/remote/thread/PlayerCosmeticLoaderThread.java b/common/src/main/java/net/anvilcraft/anvillib/cosmetics/remote/thread/PlayerCosmeticLoaderThread.java index b016984..8984f84 100644 --- a/common/src/main/java/net/anvilcraft/anvillib/cosmetics/remote/thread/PlayerCosmeticLoaderThread.java +++ b/common/src/main/java/net/anvilcraft/anvillib/cosmetics/remote/thread/PlayerCosmeticLoaderThread.java @@ -6,8 +6,7 @@ import java.net.URI; import net.anvilcraft.anvillib.cosmetics.remote.RemoteCosmeticProvider; import net.anvilcraft.anvillib.cosmetics.remote.model.PlayerData; -public class PlayerCosmeticLoaderThread extends FileDownloaderThread{ - +public class PlayerCosmeticLoaderThread extends FileDownloaderThread { private URI config; private RemoteCosmeticProvider provider; @@ -21,7 +20,8 @@ public class PlayerCosmeticLoaderThread extends FileDownloaderThread{ public void run() { try { PlayerData player = this.loadJson(config, PlayerData.class); - if (player == null) return; + if (player == null) + return; for (String id : player.cosmetics) { this.provider.loadCosmetic(id); this.provider.playerCosmetics.get(player.uuid).add(id); @@ -34,5 +34,4 @@ public class PlayerCosmeticLoaderThread extends FileDownloaderThread{ e.printStackTrace(); } } - } diff --git a/common/src/main/java/net/anvilcraft/anvillib/mixin/accessor/AnimatedGeoModelAccessor.java b/common/src/main/java/net/anvilcraft/anvillib/mixin/accessor/AnimatedGeoModelAccessor.java index cb0f31b..61ae72c 100644 --- a/common/src/main/java/net/anvilcraft/anvillib/mixin/accessor/AnimatedGeoModelAccessor.java +++ b/common/src/main/java/net/anvilcraft/anvillib/mixin/accessor/AnimatedGeoModelAccessor.java @@ -9,7 +9,6 @@ import software.bernie.geckolib3.model.AnimatedGeoModel; @Mixin(AnimatedGeoModel.class) public interface AnimatedGeoModelAccessor { - @Accessor(remap = false) AnimationProcessor getAnimationProcessor(); @@ -18,5 +17,4 @@ public interface AnimatedGeoModelAccessor { @Accessor(remap = false) void setCurrentModel(GeoModel model); - } diff --git a/common/src/main/java/net/anvilcraft/anvillib/mixin/client/AbstractClientPlayerEntityMixin.java b/common/src/main/java/net/anvilcraft/anvillib/mixin/client/AbstractClientPlayerEntityMixin.java index 526e26d..e24565a 100644 --- a/common/src/main/java/net/anvilcraft/anvillib/mixin/client/AbstractClientPlayerEntityMixin.java +++ b/common/src/main/java/net/anvilcraft/anvillib/mixin/client/AbstractClientPlayerEntityMixin.java @@ -14,10 +14,11 @@ import net.minecraft.world.World; @Mixin(AbstractClientPlayerEntity.class) public abstract class AbstractClientPlayerEntityMixin extends PlayerEntity { - private static Identifier ELYTRA = new Identifier("textures/entity/elytra.png"); - public AbstractClientPlayerEntityMixin(World world, BlockPos pos, float yaw, GameProfile profile) { + public AbstractClientPlayerEntityMixin( + World world, BlockPos pos, float yaw, GameProfile profile + ) { super(world, pos, yaw, profile); } diff --git a/common/src/main/java/net/anvilcraft/anvillib/mixin/client/MinecraftClientMixin.java b/common/src/main/java/net/anvilcraft/anvillib/mixin/client/MinecraftClientMixin.java index 8dec090..d4374e3 100644 --- a/common/src/main/java/net/anvilcraft/anvillib/mixin/client/MinecraftClientMixin.java +++ b/common/src/main/java/net/anvilcraft/anvillib/mixin/client/MinecraftClientMixin.java @@ -12,7 +12,7 @@ import net.minecraft.client.RunArgs; @Mixin(MinecraftClient.class) public class MinecraftClientMixin { @Inject(at = @At("RETURN"), method = "") - public void init(RunArgs args, CallbackInfo info) { - ClientEventHandler.registerRemoteCosmetics(args.directories.assetDir); - } + public void init(RunArgs args, CallbackInfo info) { + ClientEventHandler.registerRemoteCosmetics(args.directories.assetDir); + } } diff --git a/common/src/main/java/net/anvilcraft/anvillib/worldgen/AdvancedStructurePoolFeatureConfig.java b/common/src/main/java/net/anvilcraft/anvillib/worldgen/AdvancedStructurePoolFeatureConfig.java index b9371c4..e9bc9a8 100644 --- a/common/src/main/java/net/anvilcraft/anvillib/worldgen/AdvancedStructurePoolFeatureConfig.java +++ b/common/src/main/java/net/anvilcraft/anvillib/worldgen/AdvancedStructurePoolFeatureConfig.java @@ -8,27 +8,28 @@ import net.minecraft.util.registry.RegistryEntry; import net.minecraft.world.gen.feature.StructurePoolFeatureConfig; public class AdvancedStructurePoolFeatureConfig extends StructurePoolFeatureConfig { - public static final Codec CODEC = RecordCodecBuilder.create( - (instance) -> { - return instance - .group( - StructurePool.REGISTRY_CODEC.fieldOf("start_pool") - .forGetter( - (self) -> ((AdvancedStructurePoolFeatureConfig) self).getStartPool() - ), - Codec.intRange(0, 7).fieldOf("size").forGetter( - (self) -> ((AdvancedStructurePoolFeatureConfig) self).getSize() - ), - Codec.INT.fieldOf("max_distance_from_center") - .forGetter( - (self) - -> ((AdvancedStructurePoolFeatureConfig) self) - .maxDistanceFromCenter - ) - ) - .apply(instance, AdvancedStructurePoolFeatureConfig::new); - } - ); + public static final Codec CODEC + = RecordCodecBuilder.create((instance) -> { + return instance + .group( + StructurePool.REGISTRY_CODEC.fieldOf("start_pool") + .forGetter( + (self) + -> ((AdvancedStructurePoolFeatureConfig) self) + .getStartPool() + ), + Codec.intRange(0, 7).fieldOf("size").forGetter( + (self) -> ((AdvancedStructurePoolFeatureConfig) self).getSize() + ), + Codec.INT.fieldOf("max_distance_from_center") + .forGetter( + (self) + -> ((AdvancedStructurePoolFeatureConfig) self) + .maxDistanceFromCenter + ) + ) + .apply(instance, AdvancedStructurePoolFeatureConfig::new); + }); public final int maxDistanceFromCenter;