generated from SmushyTaco/Example-Mod
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor staff model rendering (again)
- Loading branch information
Showing
14 changed files
with
284 additions
and
183 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
.../main/kotlin/opekope2/avm_staff/internal/fabric/item/model/UnbakedFabricStaffItemModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* AvM Staff Mod | ||
* Copyright (c) 2024 opekope2 | ||
* | ||
* This mod 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 mod 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 mod. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package opekope2.avm_staff.internal.fabric.item.model | ||
|
||
import net.fabricmc.api.EnvType | ||
import net.fabricmc.api.Environment | ||
import net.minecraft.client.render.model.BakedModel | ||
import net.minecraft.client.render.model.Baker | ||
import net.minecraft.client.render.model.ModelBakeSettings | ||
import net.minecraft.client.render.model.json.JsonUnbakedModel | ||
import net.minecraft.client.texture.MissingSprite | ||
import net.minecraft.client.texture.Sprite | ||
import net.minecraft.client.util.SpriteIdentifier | ||
import net.minecraft.util.Identifier | ||
import opekope2.avm_staff.api.item.model.IStaffItemBakedModel | ||
import opekope2.avm_staff.internal.item.model.UnbakedStaffItemModel | ||
import java.util.function.Function | ||
|
||
@Environment(EnvType.CLIENT) | ||
class UnbakedFabricStaffItemModel(private val original: JsonUnbakedModel) : UnbakedStaffItemModel(original) { | ||
override fun bake( | ||
baker: Baker, | ||
textureGetter: Function<SpriteIdentifier, Sprite>, | ||
rotationContainer: ModelBakeSettings, | ||
modelId: Identifier, | ||
itemModels: Map<Identifier, IStaffItemBakedModel> | ||
): BakedModel? { | ||
return BakedFabricStaffItemModel( | ||
original.bake(baker, textureGetter, rotationContainer, modelId) ?: return null, | ||
itemModels, | ||
baker.bake(MissingSprite.getMissingSpriteId(), rotationContainer)!! | ||
) | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
ForgeMod/src/main/java/opekope2/avm_staff/mixin/forge/ModelLoaderBakerImplMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* AvM Staff Mod | ||
* Copyright (c) 2016-2024 opekope2 | ||
* | ||
* This mod 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 mod 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 mod. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package opekope2.avm_staff.mixin.forge; | ||
|
||
import com.llamalad7.mixinextras.injector.wrapoperation.Operation; | ||
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; | ||
import net.minecraft.client.render.model.Baker; | ||
import net.minecraft.client.render.model.UnbakedModel; | ||
import net.minecraft.client.render.model.json.JsonUnbakedModel; | ||
import net.minecraft.util.Identifier; | ||
import opekope2.avm_staff.internal.forge.item.model.UnbakedForgeStaffItemModel; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Coerce; | ||
|
||
import static opekope2.avm_staff.util.Constants.MOD_ID; | ||
|
||
// Forge geometry loaders are way more difficult, than porting a Fabric mixin | ||
@Mixin(targets = "net/minecraft/client/render/model/ModelLoader$BakerImpl") | ||
public class ModelLoaderBakerImplMixin { | ||
// Change method to directly call Staff Mod instead of an exposed event | ||
// Ignore this error, IntelliJ/mcdev is not looking at the correct jar | ||
@WrapOperation( | ||
method = "bake(Lnet/minecraft/util/Identifier;Lnet/minecraft/client/render/model/ModelBakeSettings;Ljava/util/function/Function;)Lnet/minecraft/client/render/model/BakedModel;", | ||
at = @At( | ||
value = "INVOKE", | ||
target = "Lnet/minecraft/client/render/model/ModelLoader$BakerImpl;getOrLoadModel(Lnet/minecraft/util/Identifier;)Lnet/minecraft/client/render/model/UnbakedModel;" | ||
) | ||
) | ||
private UnbakedModel modifyUnbakedModel(@Coerce Baker thiz, Identifier id, Operation<UnbakedModel> original) { | ||
UnbakedModel model = original.call(thiz, id); | ||
if (!MOD_ID.equals(id.getNamespace())) return model; | ||
|
||
return switch (id.getPath()) { | ||
// TODO hardcoded paths | ||
case "staff", "item/staff_in_use" -> new UnbakedForgeStaffItemModel((JsonUnbakedModel) model); // FIXME | ||
default -> model; | ||
}; | ||
} | ||
|
||
// Remove unused mixins: invokeModifyAfterBake | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
...rc/main/kotlin/opekope2/avm_staff/internal/forge/item/model/UnbakedForgeStaffItemModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* AvM Staff Mod | ||
* Copyright (c) 2024 opekope2 | ||
* | ||
* This mod 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 mod 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 mod. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package opekope2.avm_staff.internal.forge.item.model | ||
|
||
import net.minecraft.client.render.model.BakedModel | ||
import net.minecraft.client.render.model.Baker | ||
import net.minecraft.client.render.model.ModelBakeSettings | ||
import net.minecraft.client.render.model.json.JsonUnbakedModel | ||
import net.minecraft.client.texture.MissingSprite | ||
import net.minecraft.client.texture.Sprite | ||
import net.minecraft.client.util.SpriteIdentifier | ||
import net.minecraft.util.Identifier | ||
import net.minecraftforge.api.distmarker.Dist | ||
import net.minecraftforge.api.distmarker.OnlyIn | ||
import opekope2.avm_staff.api.item.model.IStaffItemBakedModel | ||
import opekope2.avm_staff.internal.item.model.UnbakedStaffItemModel | ||
import java.util.function.Function | ||
|
||
@OnlyIn(Dist.CLIENT) | ||
class UnbakedForgeStaffItemModel(private val original: JsonUnbakedModel) : UnbakedStaffItemModel(original) { | ||
override fun bake( | ||
baker: Baker, | ||
textureGetter: Function<SpriteIdentifier, Sprite>, | ||
rotationContainer: ModelBakeSettings, | ||
modelId: Identifier, | ||
itemModels: Map<Identifier, IStaffItemBakedModel> | ||
): BakedModel? { | ||
return BakedForgeStaffItemModel( | ||
original.bake(baker, original, textureGetter, rotationContainer, modelId, true) ?: return null, | ||
itemModels, | ||
baker.bake(MissingSprite.getMissingSpriteId(), rotationContainer, textureGetter)!! | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 0 additions & 35 deletions
35
StaffMod/src/main/java/opekope2/avm_staff/mixin/BakedModelManagerMixin.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.