diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 36e4933e..a4cf193f 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,7 +1,7 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionSha256Sum=20f1b1176237254a6fc204d8434196fa11a4cfb387567519c61556e8710aed78 -distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip +distributionSha256Sum=6f74b601422d6d6fc4e1f9a1ab6522f642c2fdcbc15ae33ebd30ba3d7198e854 +distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.5-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/src/main/java/dev/galacticraft/machinelib/client/api/model/MachineTextureBase.java b/src/main/java/dev/galacticraft/machinelib/client/api/model/MachineTextureBase.java index e1bfcc07..89fc429d 100644 --- a/src/main/java/dev/galacticraft/machinelib/client/api/model/MachineTextureBase.java +++ b/src/main/java/dev/galacticraft/machinelib/client/api/model/MachineTextureBase.java @@ -24,10 +24,10 @@ import com.mojang.serialization.Codec; import com.mojang.serialization.codecs.RecordCodecBuilder; -import net.minecraft.client.renderer.texture.TextureAtlas; import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.client.resources.model.*; import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.inventory.InventoryMenu; import org.jetbrains.annotations.Nullable; import java.util.Collection; @@ -91,7 +91,7 @@ public record Bound(TextureAtlasSprite base, } private static Material mat(String namespace, String location) { - return new Material(TextureAtlas.LOCATION_BLOCKS, ResourceLocation.fromNamespaceAndPath(namespace, location)); + return new Material(InventoryMenu.BLOCK_ATLAS, ResourceLocation.fromNamespaceAndPath(namespace, location)); } private record TypedResourceSprites(Material input, Material output, Material both) { diff --git a/src/main/java/dev/galacticraft/machinelib/client/api/model/TextureProvider.java b/src/main/java/dev/galacticraft/machinelib/client/api/model/TextureProvider.java index 472ae351..afa4024f 100644 --- a/src/main/java/dev/galacticraft/machinelib/client/api/model/TextureProvider.java +++ b/src/main/java/dev/galacticraft/machinelib/client/api/model/TextureProvider.java @@ -27,11 +27,11 @@ import com.mojang.serialization.DataResult; import com.mojang.serialization.codecs.RecordCodecBuilder; import dev.galacticraft.machinelib.api.util.BlockFace; -import net.minecraft.client.renderer.texture.TextureAtlas; import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.client.resources.model.Material; import net.minecraft.data.models.model.TextureMapping; import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.inventory.InventoryMenu; import net.minecraft.world.level.block.Block; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -44,9 +44,9 @@ public record TextureProvider(@Nullable Material front, @Nullable Material back, @Nullable Material top, @Nullable Material bottom, @Nullable Material particle, @Nullable Material topOverride) { public static final Codec MATERIAL_CODEC = Codec.withAlternative( - ResourceLocation.CODEC.flatComapMap(tex -> new Material(TextureAtlas.LOCATION_BLOCKS, tex), mat -> mat.atlasLocation().equals(TextureAtlas.LOCATION_BLOCKS) ? DataResult.success(mat.texture()) : DataResult.error(() -> "not block", mat.texture())), + ResourceLocation.CODEC.flatComapMap(tex -> new Material(InventoryMenu.BLOCK_ATLAS, tex), mat -> mat.atlasLocation().equals(InventoryMenu.BLOCK_ATLAS) ? DataResult.success(mat.texture()) : DataResult.error(() -> "not block", mat.texture())), RecordCodecBuilder.create(instance -> instance.group( - ResourceLocation.CODEC.optionalFieldOf("atlas").xmap(t -> t.orElse(TextureAtlas.LOCATION_BLOCKS), l -> l.equals(TextureAtlas.LOCATION_BLOCKS) ? Optional.empty() : Optional.of(l)).forGetter(Material::atlasLocation), + ResourceLocation.CODEC.optionalFieldOf("atlas").xmap(t -> t.orElse(InventoryMenu.BLOCK_ATLAS), l -> l.equals(InventoryMenu.BLOCK_ATLAS) ? Optional.empty() : Optional.of(l)).forGetter(Material::atlasLocation), ResourceLocation.CODEC.fieldOf("texture").forGetter(Material::texture) ).apply(instance, Material::new)) ); @@ -100,11 +100,11 @@ public static TextureProvider all(Material material) { } public static TextureProvider all(ResourceLocation material) { - return TextureProvider.all(new Material(TextureAtlas.LOCATION_BLOCKS, material)); + return TextureProvider.all(new Material(InventoryMenu.BLOCK_ATLAS, material)); } public static TextureProvider all(String namespace, String path) { - return TextureProvider.all(new Material(TextureAtlas.LOCATION_BLOCKS, ResourceLocation.fromNamespaceAndPath(namespace, path))); + return TextureProvider.all(new Material(InventoryMenu.BLOCK_ATLAS, ResourceLocation.fromNamespaceAndPath(namespace, path))); } public static class Builder { @@ -173,43 +173,43 @@ public Builder sides(String texture) { } public Builder front(ResourceLocation texture) { - return this.front(new Material(TextureAtlas.LOCATION_BLOCKS, texture)); + return this.front(new Material(InventoryMenu.BLOCK_ATLAS, texture)); } public Builder back(ResourceLocation texture) { - return this.back(new Material(TextureAtlas.LOCATION_BLOCKS, texture)); + return this.back(new Material(InventoryMenu.BLOCK_ATLAS, texture)); } public Builder left(ResourceLocation texture) { - return this.left(new Material(TextureAtlas.LOCATION_BLOCKS, texture)); + return this.left(new Material(InventoryMenu.BLOCK_ATLAS, texture)); } public Builder right(ResourceLocation texture) { - return this.right(new Material(TextureAtlas.LOCATION_BLOCKS, texture)); + return this.right(new Material(InventoryMenu.BLOCK_ATLAS, texture)); } public Builder top(ResourceLocation texture) { - return this.top(new Material(TextureAtlas.LOCATION_BLOCKS, texture)); + return this.top(new Material(InventoryMenu.BLOCK_ATLAS, texture)); } public Builder bottom(ResourceLocation texture) { - return this.bottom(new Material(TextureAtlas.LOCATION_BLOCKS, texture)); + return this.bottom(new Material(InventoryMenu.BLOCK_ATLAS, texture)); } public Builder particle(ResourceLocation texture) { - return this.particle(new Material(TextureAtlas.LOCATION_BLOCKS, texture)); + return this.particle(new Material(InventoryMenu.BLOCK_ATLAS, texture)); } public Builder topOverride(ResourceLocation texture) { - return this.topOverride(new Material(TextureAtlas.LOCATION_BLOCKS, texture)); + return this.topOverride(new Material(InventoryMenu.BLOCK_ATLAS, texture)); } public Builder all(ResourceLocation texture) { - return this.all(new Material(TextureAtlas.LOCATION_BLOCKS, texture)); + return this.all(new Material(InventoryMenu.BLOCK_ATLAS, texture)); } public Builder sides(ResourceLocation texture) { - return this.sides(new Material(TextureAtlas.LOCATION_BLOCKS, texture)); + return this.sides(new Material(InventoryMenu.BLOCK_ATLAS, texture)); } public Builder front(Block texture) { diff --git a/src/main/java/dev/galacticraft/machinelib/impl/compat/waila/MachineLibWailaPlugin.java b/src/main/java/dev/galacticraft/machinelib/client/impl/compat/waila/MachineLibWailaClientPlugin.java similarity index 58% rename from src/main/java/dev/galacticraft/machinelib/impl/compat/waila/MachineLibWailaPlugin.java rename to src/main/java/dev/galacticraft/machinelib/client/impl/compat/waila/MachineLibWailaClientPlugin.java index d687f092..2f6d533f 100644 --- a/src/main/java/dev/galacticraft/machinelib/impl/compat/waila/MachineLibWailaPlugin.java +++ b/src/main/java/dev/galacticraft/machinelib/client/impl/compat/waila/MachineLibWailaClientPlugin.java @@ -20,41 +20,24 @@ * SOFTWARE. */ -package dev.galacticraft.machinelib.impl.compat.waila; +package dev.galacticraft.machinelib.client.impl.compat.waila; import com.mojang.authlib.GameProfile; import dev.galacticraft.machinelib.api.block.MachineBlock; -import dev.galacticraft.machinelib.api.block.entity.MachineBlockEntity; -import dev.galacticraft.machinelib.api.block.entity.RecipeMachineBlockEntity; import dev.galacticraft.machinelib.api.machine.configuration.RedstoneMode; import dev.galacticraft.machinelib.api.machine.configuration.SecuritySettings; import dev.galacticraft.machinelib.impl.Constant; import mcp.mobius.waila.api.*; -import mcp.mobius.waila.api.data.ProgressData; import net.minecraft.network.chat.Component; import net.minecraft.world.level.block.entity.SkullBlockEntity; import java.util.Optional; -public class MachineLibWailaPlugin implements IWailaPlugin { +@SuppressWarnings("unused") +public class MachineLibWailaClientPlugin implements IWailaClientPlugin { @Override - public void register(IRegistrar registrar) { - registrar.addBlockData((IDataProvider) (data, accessor, config) -> { - MachineBlockEntity machine = accessor.getTarget(); - data.raw().put("security", machine.getSecurity().createTag()); - data.raw().put("redstone", machine.getRedstoneMode().createTag()); - if (machine instanceof RecipeMachineBlockEntity recipeMachine) { - if (recipeMachine.getActiveRecipe() != null) { - data.add(ProgressData.TYPE, res -> { - res.add(ProgressData.ratio(recipeMachine.getProgressRatio()) - .input(recipeMachine.inputItemStacks()) - .output(recipeMachine.outputItemStacks())); - }); - } - } - }, MachineBlock.class); - - registrar.addComponent(new IBlockComponentProvider() { + public void register(IClientRegistrar registrar) { + registrar.body(new IBlockComponentProvider() { @Override public void appendBody(ITooltip tooltip, IBlockAccessor accessor, IPluginConfig config) { SecuritySettings security = new SecuritySettings(); @@ -63,12 +46,15 @@ public void appendBody(ITooltip tooltip, IBlockAccessor accessor, IPluginConfig tooltip.addLine(Component.translatable(Constant.TranslationKey.REDSTONE_MODE_TOOLTIP, redstone.getName()).setStyle(Constant.Text.RED_STYLE)); if (security.getOwner() != null) { - Optional profile = SkullBlockEntity.fetchGameProfile(security.getOwner()).getNow(null); - if (profile != null && profile.isPresent()) { - tooltip.addLine(Component.translatable(Constant.TranslationKey.OWNER_TOOLTIP, Component.literal(profile.get().getName()).setStyle(Constant.Text.WHITE_STYLE)).setStyle(Constant.Text.AQUA_STYLE)); - } + Optional profile = SkullBlockEntity.fetchGameProfile(security.getOwner()).getNow(Optional.empty()); + profile.ifPresent(gameProfile -> tooltip.addLine( + Component.translatable( + Constant.TranslationKey.OWNER_TOOLTIP, + Component.literal(gameProfile.getName()).setStyle(Constant.Text.WHITE_STYLE) + ).setStyle(Constant.Text.AQUA_STYLE) + )); } } - }, TooltipPosition.BODY, MachineBlock.class); + }, MachineBlock.class); } } diff --git a/src/main/java/dev/galacticraft/machinelib/impl/compat/waila/MachineLibWailaCommonPlugin.java b/src/main/java/dev/galacticraft/machinelib/impl/compat/waila/MachineLibWailaCommonPlugin.java new file mode 100644 index 00000000..5187905a --- /dev/null +++ b/src/main/java/dev/galacticraft/machinelib/impl/compat/waila/MachineLibWailaCommonPlugin.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2021-2026 Team Galacticraft + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package dev.galacticraft.machinelib.impl.compat.waila; + +import dev.galacticraft.machinelib.api.block.MachineBlock; +import dev.galacticraft.machinelib.api.block.entity.MachineBlockEntity; +import dev.galacticraft.machinelib.api.block.entity.RecipeMachineBlockEntity; +import mcp.mobius.waila.api.*; +import mcp.mobius.waila.api.data.ProgressData; + +@SuppressWarnings("unused") +public class MachineLibWailaCommonPlugin implements IWailaCommonPlugin { + @Override + public void register(ICommonRegistrar registrar) { + registrar.blockData((IDataProvider) (data, accessor, config) -> { + MachineBlockEntity machine = accessor.getTarget(); + data.raw().put("security", machine.getSecurity().createTag()); + data.raw().put("redstone", machine.getRedstoneMode().createTag()); + if (machine instanceof RecipeMachineBlockEntity recipeMachine) { + if (recipeMachine.getActiveRecipe() != null) { + data.add(ProgressData.TYPE, res -> + res.add(ProgressData.ratio(recipeMachine.getProgressRatio()) + .input(recipeMachine.inputItemStacks()) + .output(recipeMachine.outputItemStacks())) + ); + } + } + }, MachineBlock.class); + } +} diff --git a/src/main/resources/waila_plugins.json b/src/main/resources/waila_plugins.json index aeb8f067..327bb9c6 100644 --- a/src/main/resources/waila_plugins.json +++ b/src/main/resources/waila_plugins.json @@ -1,6 +1,9 @@ { "machinelib:plugin": { - "initializer": "dev.galacticraft.machinelib.impl.compat.waila.MachineLibWailaPlugin", + "entrypoints": { + "common": "dev.galacticraft.machinelib.impl.compat.waila.MachineLibWailaCommonPlugin", + "client": "dev.galacticraft.machinelib.client.impl.compat.waila.MachineLibWailaClientPlugin" + }, "side": "*" } } \ No newline at end of file