Skip to content

Commit

Permalink
将ItemModelShaperMixin放置在fabric端,对forge端另作修改
Browse files Browse the repository at this point in the history
  • Loading branch information
Gu-ZT committed Oct 17, 2023
1 parent 41665a7 commit 7df0f11
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"mixins": [],
"client": [
"BlockModelShaperMixin",
"ItemModelShaperMixin",
"LanguageMixin",
"LevelRendererMixin"
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.dubhe.chinesefestivals.mixins;
package dev.dubhe.chinesefestivals.fabric.mixins;

import dev.dubhe.chinesefestivals.ChineseFestivals;
import dev.dubhe.chinesefestivals.festivals.Festivals;
Expand Down
3 changes: 2 additions & 1 deletion fabric/src/main/resources/chinesefestivals.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"mixins": [
],
"client": [
"CommandsMixin"
"CommandsMixin",
"ItemModelShaperMixin"
],
"injectors": {
"defaultRequire": 1
Expand Down
2 changes: 1 addition & 1 deletion forge/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ architectury {

loom {
forge {
mixinConfig "chinesefestivals-common.mixins.json"
mixinConfig "chinesefestivals.mixins.json,chinesefestivals-common.mixins.json"
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package dev.dubhe.chinesefestivals.forge.mixins;

import dev.dubhe.chinesefestivals.ChineseFestivals;
import dev.dubhe.chinesefestivals.festivals.Festivals;
import dev.dubhe.chinesefestivals.festivals.IFestival;
import net.minecraft.client.renderer.ItemModelShaper;
import net.minecraft.client.resources.model.BakedModel;
import net.minecraft.client.resources.model.ModelManager;
import net.minecraft.core.Holder;
import net.minecraft.world.item.Item;
import net.minecraftforge.client.model.ForgeItemModelShaper;
import net.minecraftforge.registries.ForgeRegistries;
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.CallbackInfoReturnable;

import java.util.Map;
import java.util.function.Supplier;

@Mixin(ForgeItemModelShaper.class)
public abstract class ForgeItemModelShaperMixin extends ItemModelShaper {
@Shadow(remap = false)
@Final
private Map<Holder.Reference<Item>, BakedModel> models;

public ForgeItemModelShaperMixin(ModelManager arg) {
super(arg);
}

@Inject(method = "getItemModel", remap = false, at = @At("HEAD"), cancellable = true)
private void getItemModel(Item item, CallbackInfoReturnable<BakedModel> cir) {
ChineseFestivals.LOGGER.info("test");
for (IFestival festival : Festivals.FESTIVALS) {
if (festival.isNow()) {
Supplier<Item> item1 = festival.getItemReplace().getOrDefault(item, null);
if (item1 != null) {
cir.setReturnValue(this.models.get(ForgeRegistries.ITEMS.getDelegateOrThrow(item1.get())));
return;
}
}
}
}
}
13 changes: 13 additions & 0 deletions forge/src/main/resources/chinesefestivals.mixins.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"required": true,
"minVersion": "0.8",
"package": "dev.dubhe.chinesefestivals.forge.mixins",
"compatibilityLevel": "JAVA_17",
"mixins": [],
"client": [
"ForgeItemModelShaperMixin"
],
"injectors": {
"defaultRequire": 1
}
}

0 comments on commit 7df0f11

Please sign in to comment.