shedaniel преди 4 години
родител
ревизия
27addc91d9

+ 33 - 0
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);
+}

+ 19 - 0
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;

+ 2 - 2
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;
         }
     }

+ 19 - 0
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;

+ 20 - 1
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;
     }
     

+ 52 - 0
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<ItemStack> 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);
+            }
+        }
+    }
+}

+ 19 - 0
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;

+ 28 - 45
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
   }
 }

+ 35 - 0
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);
+    }
+}

+ 19 - 0
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;

+ 3 - 2
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