diff --git a/common/src/main/java/me/shedaniel/architectury/extensions/ItemExtension.java b/common/src/main/java/me/shedaniel/architectury/extensions/ItemExtension.java new file mode 100644 index 00000000..a28a2945 --- /dev/null +++ b/common/src/main/java/me/shedaniel/architectury/extensions/ItemExtension.java @@ -0,0 +1,33 @@ +/* + * This file is part of architectury. + * Copyright (C) 2020, 2021 shedaniel + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +package me.shedaniel.architectury.extensions; + +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; + +public interface ItemExtension { + /** + * Invoked every tick when this item is equipped. + * + * @param stack the item stack of the armor + * @param player the player wearing the armor + */ + void tickArmor(ItemStack stack, Player player); +} diff --git a/common/src/main/java/me/shedaniel/architectury/registry/entity/EntityRenderers.java b/common/src/main/java/me/shedaniel/architectury/registry/entity/EntityRenderers.java index 336d3dc4..97cf471f 100644 --- a/common/src/main/java/me/shedaniel/architectury/registry/entity/EntityRenderers.java +++ b/common/src/main/java/me/shedaniel/architectury/registry/entity/EntityRenderers.java @@ -1,3 +1,22 @@ +/* + * This file is part of architectury. + * Copyright (C) 2020, 2021 shedaniel + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + package me.shedaniel.architectury.registry.entity; import me.shedaniel.architectury.annotations.ExpectPlatform; diff --git a/fabric/src/main/java/me/shedaniel/architectury/hooks/fabric/EntityHooksImpl.java b/fabric/src/main/java/me/shedaniel/architectury/hooks/fabric/EntityHooksImpl.java index 39739848..0cd8781b 100644 --- a/fabric/src/main/java/me/shedaniel/architectury/hooks/fabric/EntityHooksImpl.java +++ b/fabric/src/main/java/me/shedaniel/architectury/hooks/fabric/EntityHooksImpl.java @@ -30,12 +30,12 @@ public class EntityHooksImpl { @Nullable public static Entity fromCollision(CollisionContext ctx) { - return ((CollisionContextExtension) ctx).getEntity(); + return ((CollisionContextExtension) ctx).arch$getEntity(); } public interface CollisionContextExtension { @Nullable - default Entity getEntity() { + default Entity arch$getEntity() { return null; } } diff --git a/fabric/src/main/java/me/shedaniel/architectury/mixin/fabric/MixinCollisionContext.java b/fabric/src/main/java/me/shedaniel/architectury/mixin/fabric/MixinCollisionContext.java index cb79fb48..b0ac92ed 100644 --- a/fabric/src/main/java/me/shedaniel/architectury/mixin/fabric/MixinCollisionContext.java +++ b/fabric/src/main/java/me/shedaniel/architectury/mixin/fabric/MixinCollisionContext.java @@ -1,3 +1,22 @@ +/* + * This file is part of architectury. + * Copyright (C) 2020, 2021 shedaniel + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + package me.shedaniel.architectury.mixin.fabric; import me.shedaniel.architectury.hooks.fabric.EntityHooksImpl; diff --git a/fabric/src/main/java/me/shedaniel/architectury/mixin/fabric/MixinEntityCollisionContext.java b/fabric/src/main/java/me/shedaniel/architectury/mixin/fabric/MixinEntityCollisionContext.java index ed51c31c..ca38d210 100644 --- a/fabric/src/main/java/me/shedaniel/architectury/mixin/fabric/MixinEntityCollisionContext.java +++ b/fabric/src/main/java/me/shedaniel/architectury/mixin/fabric/MixinEntityCollisionContext.java @@ -1,3 +1,22 @@ +/* + * This file is part of architectury. + * Copyright (C) 2020, 2021 shedaniel + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + package me.shedaniel.architectury.mixin.fabric; import me.shedaniel.architectury.hooks.fabric.EntityHooksImpl; @@ -25,7 +44,7 @@ public abstract class MixinEntityCollisionContext implements CollisionContext, E @Nullable @Override - public Entity getEntity() { + public Entity arch$getEntity() { return entity; } diff --git a/fabric/src/main/java/me/shedaniel/architectury/mixin/fabric/MixinInventory.java b/fabric/src/main/java/me/shedaniel/architectury/mixin/fabric/MixinInventory.java new file mode 100644 index 00000000..098fd955 --- /dev/null +++ b/fabric/src/main/java/me/shedaniel/architectury/mixin/fabric/MixinInventory.java @@ -0,0 +1,52 @@ +/* + * This file is part of architectury. + * Copyright (C) 2020, 2021 shedaniel + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +package me.shedaniel.architectury.mixin.fabric; + +import me.shedaniel.architectury.extensions.ItemExtension; +import net.minecraft.core.NonNullList; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(Inventory.class) +public class MixinInventory { + @Shadow + @Final + public NonNullList armor; + + @Shadow + @Final + public Player player; + + @Inject(method = "tick", at = @At("RETURN")) + private void updateItems(CallbackInfo ci) { + for (ItemStack stack : armor) { + if (stack.getItem() instanceof ItemExtension) { + ((ItemExtension) stack.getItem()).tickArmor(stack, player); + } + } + } +} diff --git a/fabric/src/main/java/me/shedaniel/architectury/registry/entity/fabric/EntityRenderersImpl.java b/fabric/src/main/java/me/shedaniel/architectury/registry/entity/fabric/EntityRenderersImpl.java index 96830f6c..20eec624 100644 --- a/fabric/src/main/java/me/shedaniel/architectury/registry/entity/fabric/EntityRenderersImpl.java +++ b/fabric/src/main/java/me/shedaniel/architectury/registry/entity/fabric/EntityRenderersImpl.java @@ -1,3 +1,22 @@ +/* + * This file is part of architectury. + * Copyright (C) 2020, 2021 shedaniel + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + package me.shedaniel.architectury.registry.entity.fabric; import net.fabricmc.fabric.api.client.rendereregistry.v1.EntityRendererRegistry; diff --git a/fabric/src/main/resources/architectury.mixins.json b/fabric/src/main/resources/architectury.mixins.json index f7607c32..4f3433e6 100644 --- a/fabric/src/main/resources/architectury.mixins.json +++ b/fabric/src/main/resources/architectury.mixins.json @@ -1,48 +1,31 @@ { - "required": true, - "package": "me.shedaniel.architectury.mixin.fabric", - "plugin": "me.shedaniel.architectury.plugin.fabric.ArchitecturyMixinPlugin", - "compatibilityLevel": "JAVA_8", - "minVersion": "0.7.11", - "client": [ - "client.MixinClientLevel", - "client.MixinClientPacketListener", - "client.MixinDebugScreenOverlay", - "client.MixinEffectInstance", - "client.MixinGameRenderer", - "client.MixinIntegratedServer", - "client.MixinKeyboardHandler", - "client.MixinMinecraft", - "client.MixinMouseHandler", - "client.MixinMultiPlayerGameMode", - "client.MixinScreen", - "client.MixinTextureAtlas" - ], - "mixins": [ - "ExplosionPreInvoker", - "LivingDeathInvoker", - "MixinBlockEntityExtension", - "MixinBlockItem", - "MixinCollisionContext", - "MixinCommands", - "MixinDedicatedServer", - "MixinEntityCollisionContext", - "MixinExplosion", - "MixinFurnaceResultSlot", - "MixinItemEntity", - "MixinLivingEntity", - "MixinPlayer", - "MixinPlayerAdvancements", - "MixinPlayerList", - "MixinResultSlot", - "MixinServerGamePacketListenerImpl", - "MixinServerLevel", - "MixinServerPlayer", - "MixinServerPlayerGameMode", - "PlayerAttackInvoker" - ], - "injectors": { - "maxShiftBy": 5, - "defaultRequire": 1 + "required": true, + "package": "me.shedaniel.architectury.mixin.fabric", + "plugin": "me.shedaniel.architectury.plugin.fabric.ArchitecturyMixinPlugin", + "compatibilityLevel": "JAVA_8", + "minVersion": "0.7.11", + "client": [ + "client.MixinClientLevel", + "client.MixinClientPacketListener", + "client.MixinDebugScreenOverlay", + "client.MixinEffectInstance", + "client.MixinGameRenderer", + "client.MixinIntegratedServer", + "client.MixinKeyboardHandler", + "client.MixinMinecraft", + "client.MixinMouseHandler", + "client.MixinMultiPlayerGameMode", + "client.MixinScreen", + "client.MixinTextureAtlas" + ], + "mixins": [ + "ExplosionPreInvoker", "LivingDeathInvoker", "MixinBlockEntityExtension", "MixinBlockItem", "MixinCollisionContext", "MixinCommands", + "MixinDedicatedServer", "MixinEntityCollisionContext", "MixinExplosion", "MixinFurnaceResultSlot", "MixinInventory", "MixinItemEntity", "MixinLivingEntity", + "MixinPlayer", "MixinPlayerAdvancements", "MixinPlayerList", "MixinResultSlot", "MixinServerGamePacketListenerImpl", "MixinServerLevel", + "MixinServerPlayer", "MixinServerPlayerGameMode", "PlayerAttackInvoker" + ], + "injectors": { + "maxShiftBy": 5, + "defaultRequire": 1 } } diff --git a/forge/src/main/java/me/shedaniel/architectury/mixin/forge/MixinItemExtension.java b/forge/src/main/java/me/shedaniel/architectury/mixin/forge/MixinItemExtension.java new file mode 100644 index 00000000..8bbd20c5 --- /dev/null +++ b/forge/src/main/java/me/shedaniel/architectury/mixin/forge/MixinItemExtension.java @@ -0,0 +1,35 @@ +/* + * This file is part of architectury. + * Copyright (C) 2020, 2021 shedaniel + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +package me.shedaniel.architectury.mixin.forge; + +import me.shedaniel.architectury.extensions.ItemExtension; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.Level; +import net.minecraftforge.common.extensions.IForgeItem; +import org.spongepowered.asm.mixin.Mixin; + +@Mixin(ItemExtension.class) +public interface MixinItemExtension extends IForgeItem { + @Override + default void onArmorTick(ItemStack stack, Level world, Player player) { + ((ItemExtension) this).tickArmor(stack, player); + } +} diff --git a/forge/src/main/java/me/shedaniel/architectury/registry/entity/forge/EntityRenderersImpl.java b/forge/src/main/java/me/shedaniel/architectury/registry/entity/forge/EntityRenderersImpl.java index 8be995d3..a2401130 100644 --- a/forge/src/main/java/me/shedaniel/architectury/registry/entity/forge/EntityRenderersImpl.java +++ b/forge/src/main/java/me/shedaniel/architectury/registry/entity/forge/EntityRenderersImpl.java @@ -1,3 +1,22 @@ +/* + * This file is part of architectury. + * Copyright (C) 2020, 2021 shedaniel + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + package me.shedaniel.architectury.registry.entity.forge; import net.minecraft.client.renderer.entity.EntityRenderDispatcher; diff --git a/forge/src/main/resources/architectury.mixins.json b/forge/src/main/resources/architectury.mixins.json index 383b59e3..277733fc 100644 --- a/forge/src/main/resources/architectury.mixins.json +++ b/forge/src/main/resources/architectury.mixins.json @@ -7,8 +7,9 @@ "client": [ ], "mixins": [ - "BiomeGenerationSettingsBuilderAccessor", "MixinRegistryEntry", "MixinBlockEntity", "MixinBlockEntityExtension", - "MobSpawnSettingsBuilderAccessor", "GameRulesAccessor", "GameRulesAccessor$BooleanValue", "GameRulesAccessor$BooleanValueSimple", "GameRulesAccessor$IntegerValue", "GameRulesAccessor$IntegerValueSimple" + "BiomeGenerationSettingsBuilderAccessor", "GameRulesAccessor", "GameRulesAccessor$BooleanValue", "GameRulesAccessor$BooleanValueSimple", + "GameRulesAccessor$IntegerValue", "GameRulesAccessor$IntegerValueSimple", "MixinBlockEntity", "MixinBlockEntityExtension", "MixinItemExtension", + "MixinRegistryEntry", "MobSpawnSettingsBuilderAccessor" ], "injectors": { "defaultRequire": 1