diff --git a/gradle.properties b/gradle.properties index 6d2d37ee..244c1d5a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -12,7 +12,7 @@ fabric_version=0.97.6+1.20.6 maven_group = eu.pb4 -mod_version = 0.8.1-dev +mod_version = 0.8.1 minecraft_version_supported = ">=1.20.5-" diff --git a/polymer-common/src/main/java/eu/pb4/polymer/common/impl/entity/InternalEntityHelpers.java b/polymer-common/src/main/java/eu/pb4/polymer/common/impl/entity/InternalEntityHelpers.java index cf1af673..7bea26aa 100644 --- a/polymer-common/src/main/java/eu/pb4/polymer/common/impl/entity/InternalEntityHelpers.java +++ b/polymer-common/src/main/java/eu/pb4/polymer/common/impl/entity/InternalEntityHelpers.java @@ -31,9 +31,10 @@ public class InternalEntityHelpers { private static final Map, @Nullable Entity> EXAMPLE_ENTITIES = new HashMap<>(); private static final Map, DataTracker.Entry[]> TRACKED_DATA = new Object2ObjectOpenCustomHashMap<>(CommonImplUtils.IDENTITY_HASH); - static { + private static PlayerEntity createPlayer() { + PlayerEntity player = null; try { - EXAMPLE_ENTITIES.put(EntityType.PLAYER, new PlayerEntity(FakeWorld.INSTANCE_UNSAFE, BlockPos.ORIGIN, 0, new GameProfile(Util.NIL_UUID, "TinyPotato")) { + player = new PlayerEntity(FakeWorld.INSTANCE_UNSAFE, BlockPos.ORIGIN, 0, new GameProfile(Util.NIL_UUID, "TinyPotato")) { @Override public boolean isSpectator() { return false; @@ -43,13 +44,13 @@ public boolean isSpectator() { public boolean isCreative() { return false; } - }); + }; } catch (Throwable e) { if (CommonImpl.LOG_MORE_ERRORS) { CommonImpl.LOGGER.error("Failed add player like entity! Trying with alternative method", e); } try { - EXAMPLE_ENTITIES.put(EntityType.PLAYER, new PlayerEntity(FakeWorld.INSTANCE_REGULAR, BlockPos.ORIGIN, 0, new GameProfile(Util.NIL_UUID, "TinyPotato")) { + player = new PlayerEntity(FakeWorld.INSTANCE_REGULAR, BlockPos.ORIGIN, 0, new GameProfile(Util.NIL_UUID, "TinyPotato")) { @Override public boolean isSpectator() { return false; @@ -59,14 +60,16 @@ public boolean isSpectator() { public boolean isCreative() { return false; } - }); + }; } catch (Throwable e2) { if (CommonImpl.LOG_MORE_ERRORS) { CommonImpl.LOGGER.error("Failed add player like entity!", e2); } } } - } + EXAMPLE_ENTITIES.put(EntityType.PLAYER, player); + return player; + }; public static DataTracker.Entry[] getExampleTrackedDataOfEntityType(EntityType type) { var val = TRACKED_DATA.get(type); @@ -107,6 +110,10 @@ public static Entity getEntity(EntityType type) { Entity entity = EXAMPLE_ENTITIES.get(type); if (entity == null) { + if (type == EntityType.PLAYER) { + return createPlayer(); + } + try { entity = type.create(FakeWorld.INSTANCE_UNSAFE); } catch (Throwable e) { @@ -118,10 +125,10 @@ public static Entity getEntity(EntityType type) { CommonImpl.LOGGER.warn(String.format( "Couldn't create template entity of %s... Defaulting to empty. %s", id, - id != null && id.getNamespace().equals("minecraft") ? "This might cause problems!" : "Don't worry, this shouldn't cause problems!" + id.getNamespace().equals("minecraft") ? "This might cause problems!" : "Don't worry, this shouldn't cause problems!" )); - if (id != null && id.getNamespace().equals("minecraft")) { + if (id.getNamespace().equals("minecraft")) { CommonImpl.LOGGER.warn("First error:"); e.printStackTrace(); CommonImpl.LOGGER.warn("Second error:"); diff --git a/polymer-core/src/main/java/eu/pb4/polymer/core/impl/client/compat/CompatUtils.java b/polymer-core/src/main/java/eu/pb4/polymer/core/impl/client/compat/CompatUtils.java index 741fa083..00c5ba55 100644 --- a/polymer-core/src/main/java/eu/pb4/polymer/core/impl/client/compat/CompatUtils.java +++ b/polymer-core/src/main/java/eu/pb4/polymer/core/impl/client/compat/CompatUtils.java @@ -23,7 +23,7 @@ public static boolean areSamePolymerType(ItemStack a, ItemStack b) { return Objects.equals(getItemId(a.getItem(), a.get(DataComponentTypes.CUSTOM_DATA)), getItemId(b.getItem(), b.get(DataComponentTypes.CUSTOM_DATA))); } - public static boolean areSamePolymerType(Item ai, NbtComponent a, Item bi, NbtComponent b) { + public static boolean areSamePolymerType(Object ai, NbtComponent a, Object bi, NbtComponent b) { return Objects.equals(getItemId(ai, a), getItemId(bi, b)); } @@ -66,11 +66,11 @@ public static Object getKey(@Nullable NbtComponent component) { return Registries.ITEM.get(id); } - private static Identifier getItemId(Item item, @Nullable NbtComponent nbtComponent) { + private static Identifier getItemId(Object item, @Nullable NbtComponent nbtComponent) { var id = PolymerItemUtils.getServerIdentifier(nbtComponent); - if (id == null) { - return item.getRegistryEntry().registryKey().getValue(); + if (id == null && item instanceof Item item1) { + return item1.getRegistryEntry().registryKey().getValue(); } return id; diff --git a/polymer-core/src/main/java/eu/pb4/polymer/core/mixin/client/compat/emi_EmiStackMixin.java b/polymer-core/src/main/java/eu/pb4/polymer/core/mixin/client/compat/emi_EmiStackMixin.java index 791aedd0..a0706b0e 100644 --- a/polymer-core/src/main/java/eu/pb4/polymer/core/mixin/client/compat/emi_EmiStackMixin.java +++ b/polymer-core/src/main/java/eu/pb4/polymer/core/mixin/client/compat/emi_EmiStackMixin.java @@ -6,7 +6,11 @@ import eu.pb4.polymer.core.impl.client.compat.CompatUtils; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; +import net.minecraft.component.ComponentChanges; +import net.minecraft.component.DataComponentType; +import net.minecraft.component.DataComponentTypes; import net.minecraft.item.ItemStack; +import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Pseudo; import org.spongepowered.asm.mixin.Shadow; @@ -21,16 +25,22 @@ public abstract class emi_EmiStackMixin { @Shadow public abstract ItemStack getItemStack(); + @Shadow public abstract Object getKey(); + + @Shadow public abstract @Nullable T get(DataComponentType type); + @Inject(method = "isEqual(Ldev/emi/emi/api/stack/EmiStack;)Z", at = @At("HEAD"), cancellable = true, remap = false, require = 0) private void polymer$areEqual(EmiStack stack, CallbackInfoReturnable cir) { - if (!CompatUtils.areSamePolymerType(stack.getItemStack(), this.getItemStack())) { + if (!CompatUtils.areSamePolymerType(null, stack.get(DataComponentTypes.CUSTOM_DATA), + null, this.get(DataComponentTypes.CUSTOM_DATA))) { cir.setReturnValue(false); } } @Inject(method = "isEqual(Ldev/emi/emi/api/stack/EmiStack;Ldev/emi/emi/api/stack/Comparison;)Z", at = @At("HEAD"), cancellable = true, remap = false, require = 0) private void polymer$areEqual2(EmiStack stack, Comparison comparison, CallbackInfoReturnable cir) { - if (!CompatUtils.areSamePolymerType(stack.getItemStack(), this.getItemStack())) { + if (!CompatUtils.areSamePolymerType(null, stack.get(DataComponentTypes.CUSTOM_DATA), + null, this.get(DataComponentTypes.CUSTOM_DATA))) { cir.setReturnValue(false); } } diff --git a/polymer-core/src/main/java/eu/pb4/polymer/core/mixin/client/rendering/AbstractInventoryScreenMixin.java b/polymer-core/src/main/java/eu/pb4/polymer/core/mixin/client/rendering/AbstractInventoryScreenMixin.java deleted file mode 100644 index c791cf44..00000000 --- a/polymer-core/src/main/java/eu/pb4/polymer/core/mixin/client/rendering/AbstractInventoryScreenMixin.java +++ /dev/null @@ -1,22 +0,0 @@ -package eu.pb4.polymer.core.mixin.client.rendering; - -import eu.pb4.polymer.core.impl.PolymerImpl; -import net.minecraft.client.gui.screen.ingame.AbstractInventoryScreen; -import net.minecraft.entity.effect.StatusEffectInstance; -import net.minecraft.entity.effect.StatusEffects; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.ModifyVariable; - -import java.util.Collection; - -@Mixin(AbstractInventoryScreen.class) -public class AbstractInventoryScreenMixin { - @ModifyVariable(method = "drawStatusEffects", at = @At("STORE"), ordinal = 0) - private Collection polymer_removeEffect(Collection value) { - if (PolymerImpl.CHANGING_QOL_CLIENT) { - value.removeIf((x) -> x.getEffectType() == StatusEffects.MINING_FATIGUE && x.getAmplifier() == -1); - } - return value; - } -} diff --git a/polymer-core/src/main/resources/polymer-core.mixins.json b/polymer-core/src/main/resources/polymer-core.mixins.json index 8e2de8e7..6108c385 100644 --- a/polymer-core/src/main/resources/polymer-core.mixins.json +++ b/polymer-core/src/main/resources/polymer-core.mixins.json @@ -107,7 +107,6 @@ "client.item.ItemGroupMixin", "client.item.ItemGroupsMixin", "client.item.ItemStackMixin", - "client.rendering.AbstractInventoryScreenMixin", "client.rendering.BlockModelsMixin", "client.rendering.BuiltinModelItemRendererMixin", "client.rendering.EntityRenderDispatcherMixin", diff --git a/polymer-core/src/testmod/java/eu/pb4/polymertest/mixin/ServerPlayNetworkHandlerMixin.java b/polymer-core/src/testmod/java/eu/pb4/polymertest/mixin/ServerPlayNetworkHandlerMixin.java index 98d1130f..62998f28 100644 --- a/polymer-core/src/testmod/java/eu/pb4/polymertest/mixin/ServerPlayNetworkHandlerMixin.java +++ b/polymer-core/src/testmod/java/eu/pb4/polymertest/mixin/ServerPlayNetworkHandlerMixin.java @@ -2,6 +2,7 @@ import net.minecraft.entity.Entity; import net.minecraft.network.ClientConnection; +import net.minecraft.network.packet.c2s.play.HandSwingC2SPacket; import net.minecraft.network.packet.c2s.play.PlayerInputC2SPacket; import net.minecraft.network.packet.s2c.play.EntityPassengersSetS2CPacket; import net.minecraft.server.MinecraftServer; @@ -44,4 +45,9 @@ private void sendPassengers(CallbackInfo ci) { this.lastPassengers = list; } } + + @Inject(method = "onHandSwing", at = @At("TAIL")) + private void onSwing(HandSwingC2SPacket packet, CallbackInfo ci) { + //this.player.sendMessage(Text.literal("Swing!")); + } } diff --git a/polymer-resource-pack/src/main/java/eu/pb4/polymer/resourcepack/api/PolymerArmorModel.java b/polymer-resource-pack/src/main/java/eu/pb4/polymer/resourcepack/api/PolymerArmorModel.java index b1508cd6..02224b36 100644 --- a/polymer-resource-pack/src/main/java/eu/pb4/polymer/resourcepack/api/PolymerArmorModel.java +++ b/polymer-resource-pack/src/main/java/eu/pb4/polymer/resourcepack/api/PolymerArmorModel.java @@ -1,13 +1,21 @@ package eu.pb4.polymer.resourcepack.api; +import net.minecraft.item.ArmorMaterial; import net.minecraft.util.Identifier; import org.jetbrains.annotations.ApiStatus; +import java.util.List; + /** * Represents information about armor texture */ @ApiStatus.NonExtendable -public interface PolymerArmorModel{ +public interface PolymerArmorModel { int color(); - Identifier modelPath(); + Identifier modelId(); + List layers(); + @Deprecated + default Identifier modelPath() { + return modelId(); + } } diff --git a/polymer-resource-pack/src/main/java/eu/pb4/polymer/resourcepack/api/PolymerResourcePackUtils.java b/polymer-resource-pack/src/main/java/eu/pb4/polymer/resourcepack/api/PolymerResourcePackUtils.java index 6b89b053..5f4c21f9 100644 --- a/polymer-resource-pack/src/main/java/eu/pb4/polymer/resourcepack/api/PolymerResourcePackUtils.java +++ b/polymer-resource-pack/src/main/java/eu/pb4/polymer/resourcepack/api/PolymerResourcePackUtils.java @@ -7,7 +7,9 @@ import eu.pb4.polymer.resourcepack.impl.compat.polymc.PolyMcHelpers; import eu.pb4.polymer.resourcepack.impl.generation.DefaultRPBuilder; import net.fabricmc.loader.api.FabricLoader; +import net.minecraft.item.ArmorMaterial; import net.minecraft.item.Item; +import net.minecraft.registry.entry.RegistryEntry; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.util.Identifier; import org.jetbrains.annotations.Nullable; @@ -55,6 +57,15 @@ public static PolymerModelData requestModel(Item vanillaItem, Identifier modelPa public static PolymerArmorModel requestArmor(Identifier modelPath) { return INSTANCE.requestArmor(modelPath); } + /** + * This method can be used to register custom model data for items + * + * @param material ArmorMaterial to generate + * @return PolymerArmorModel with data about this model + */ + public static PolymerArmorModel requestArmor(RegistryEntry material) { + return INSTANCE.requestArmor(material); + } /** * Adds mod with provided mod id as a source of assets @@ -66,7 +77,7 @@ public static boolean addModAssets(String modId) { } /** - * Adds mod with provided mod id as a source of assets + * Adds mod with provided mod id as a source of assets, without actually copying them to the resource pack * * @param modId Id of mods used as a source */ diff --git a/polymer-resource-pack/src/main/java/eu/pb4/polymer/resourcepack/api/ResourcePackCreator.java b/polymer-resource-pack/src/main/java/eu/pb4/polymer/resourcepack/api/ResourcePackCreator.java index 2acc1e4f..33b716fc 100644 --- a/polymer-resource-pack/src/main/java/eu/pb4/polymer/resourcepack/api/ResourcePackCreator.java +++ b/polymer-resource-pack/src/main/java/eu/pb4/polymer/resourcepack/api/ResourcePackCreator.java @@ -9,6 +9,7 @@ import eu.pb4.polymer.resourcepack.impl.generation.DefaultRPBuilder; import eu.pb4.polymer.resourcepack.impl.generation.PolymerArmorModelImpl; import eu.pb4.polymer.resourcepack.impl.generation.PolymerModelDataImpl; +import eu.pb4.polymer.resourcepack.mixin.LayerAccessor; import it.unimi.dsi.fastutil.ints.IntOpenHashSet; import it.unimi.dsi.fastutil.ints.IntSet; import it.unimi.dsi.fastutil.objects.Object2IntMap; @@ -16,7 +17,9 @@ import it.unimi.dsi.fastutil.objects.Object2ObjectOpenCustomHashMap; import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import net.minecraft.SharedConstants; +import net.minecraft.item.ArmorMaterial; import net.minecraft.item.Item; +import net.minecraft.registry.entry.RegistryEntry; import net.minecraft.text.Text; import net.minecraft.text.TextCodecs; import net.minecraft.util.Identifier; @@ -49,7 +52,7 @@ public final class ResourcePackCreator { private int armorColor = 0; private Text packDescription = null; private byte[] packIcon = null; - private Set sourcePaths = new HashSet<>(); + private final Set sourcePaths = new HashSet<>(); public static ResourcePackCreator create() { return new ResourcePackCreator(0); @@ -122,13 +125,28 @@ public PolymerArmorModel requestArmor(Identifier modelPath) { } else { this.armorColor++; int color = 0xFFFFFF - armorColor * 2 + 1; - var model = new PolymerArmorModelImpl(color, modelPath); + var model = new PolymerArmorModelImpl(color, modelPath, List.of(new ArmorMaterial.Layer(modelPath))); this.armorModelMap.put(modelPath, model); this.takenArmorColors.add(color); return model; } } + /** + * This method can be used to register custom model data for items + * + * @param material ArmorMaterial + * @return PolymerArmorModel with data about this model + */ + public PolymerArmorModel requestArmor(RegistryEntry material) { + if (material.value().layers().isEmpty()) { + CommonImpl.LOGGER.warn("Armor Material '{}' has no layers!", material.getIdAsString()); + return PolymerArmorModelImpl.EMPTY; + } else if (material.value().layers().size() > 1) { + CommonImpl.LOGGER.warn("Multi-layer Armor Materials aren't supported yet! Provided material: '{}'", material.getIdAsString()); + } + return requestArmor(((LayerAccessor) (Object) material.value().layers().get(0)).getId()); + } /** * Adds mod with provided mod id as a source of assets @@ -181,6 +199,26 @@ public List getModelsFor(Item item) { return Collections.unmodifiableList(items.getOrDefault(item, Collections.emptyList())); } + /** + * Gets an unmodifiable list of models for all items + * This can be useful if you need to extract this list and parse it yourself. + * + * @return An unmodifiable list of models + */ + public Map> getAllItemModels() { + return Collections.unmodifiableMap(items); + } + + /** + * Gets an unmodifiable list of models for all items + * This can be useful if you need to extract this list and parse it yourself. + * + * @return An unmodifiable list of models + */ + public Map getAllArmorModels() { + return Collections.unmodifiableMap(this.armorModelMap); + } + /** * Sets pack description * diff --git a/polymer-resource-pack/src/main/java/eu/pb4/polymer/resourcepack/impl/generation/PolymerArmorModelImpl.java b/polymer-resource-pack/src/main/java/eu/pb4/polymer/resourcepack/impl/generation/PolymerArmorModelImpl.java index 8901da0c..affe8f01 100644 --- a/polymer-resource-pack/src/main/java/eu/pb4/polymer/resourcepack/impl/generation/PolymerArmorModelImpl.java +++ b/polymer-resource-pack/src/main/java/eu/pb4/polymer/resourcepack/impl/generation/PolymerArmorModelImpl.java @@ -1,7 +1,11 @@ package eu.pb4.polymer.resourcepack.impl.generation; import eu.pb4.polymer.resourcepack.api.PolymerArmorModel; +import net.minecraft.item.ArmorMaterial; import net.minecraft.util.Identifier; -public record PolymerArmorModelImpl(int color, Identifier modelPath) implements PolymerArmorModel { +import java.util.List; + +public record PolymerArmorModelImpl(int color, Identifier modelId, List layers) implements PolymerArmorModel { + public static final PolymerArmorModel EMPTY = new PolymerArmorModelImpl(-1, new Identifier("empty"), List.of()); } diff --git a/polymer-resource-pack/src/main/java/eu/pb4/polymer/resourcepack/mixin/LayerAccessor.java b/polymer-resource-pack/src/main/java/eu/pb4/polymer/resourcepack/mixin/LayerAccessor.java new file mode 100644 index 00000000..f9a36c29 --- /dev/null +++ b/polymer-resource-pack/src/main/java/eu/pb4/polymer/resourcepack/mixin/LayerAccessor.java @@ -0,0 +1,12 @@ +package eu.pb4.polymer.resourcepack.mixin; + +import net.minecraft.item.ArmorMaterial; +import net.minecraft.util.Identifier; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +@Mixin(ArmorMaterial.Layer.class) +public interface LayerAccessor { + @Accessor + Identifier getId(); +} diff --git a/polymer-resource-pack/src/main/resources/polymer-resource-pack.mixins.json b/polymer-resource-pack/src/main/resources/polymer-resource-pack.mixins.json index 40198435..963f7f8a 100644 --- a/polymer-resource-pack/src/main/resources/polymer-resource-pack.mixins.json +++ b/polymer-resource-pack/src/main/resources/polymer-resource-pack.mixins.json @@ -5,12 +5,13 @@ "compatibilityLevel": "JAVA_21", "plugin": "eu.pb4.polymer.resourcepack.mixin.PolymerResourcePackMixinConfigPlugin", "mixins": [ + "LayerAccessor", "compat.polymc.polymc_ArmorColorManagerMixin", "compat.polymc.polymc_FancyPantsItemPolyMixin" ], "client": [ - "client.MinecraftClientMixin", "client.ArmorFeatureRendererAccessor", + "client.MinecraftClientMixin", "client.ResourcePackManagerMixin", "client.compat.armor_ArmorFeatureRendererMixin" ],