-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0524871
commit 7a0c24b
Showing
41 changed files
with
788 additions
and
34 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
Empty file.
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,2 @@ | ||
minVersionIncluded=1.8 | ||
maxVersionIncluded=1.12.2 |
42 changes: 42 additions & 0 deletions
42
...v1/1.12.2/src/main/java/net/legacyfabric/fabric/impl/item/versioned/EarlyInitializer.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,42 @@ | ||
/* | ||
* Copyright (c) 2020 - 2024 Legacy Fabric | ||
* Copyright (c) 2016 - 2022 FabricMC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package net.legacyfabric.fabric.impl.item.versioned; | ||
|
||
import net.minecraft.item.Item; | ||
|
||
import net.fabricmc.api.EnvType; | ||
import net.fabricmc.loader.api.FabricLoader; | ||
import net.fabricmc.loader.api.entrypoint.PreLaunchEntrypoint; | ||
|
||
import net.legacyfabric.fabric.api.registry.v2.RegistryIds; | ||
import net.legacyfabric.fabric.api.registry.v2.event.RegistryInitializedEvent; | ||
import net.legacyfabric.fabric.api.registry.v2.registry.holder.FabricRegistry; | ||
import net.legacyfabric.fabric.api.registry.v2.registry.holder.SyncedFabricRegistry; | ||
|
||
public class EarlyInitializer implements PreLaunchEntrypoint { | ||
@Override | ||
public void onPreLaunch() { | ||
RegistryInitializedEvent.event(RegistryIds.ITEMS).register(EarlyInitializer::itemRegistryInit); | ||
} | ||
|
||
private static void itemRegistryInit(FabricRegistry<?> holder) { | ||
SyncedFabricRegistry<Item> registry = (SyncedFabricRegistry<Item>) holder; | ||
|
||
if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) registry.fabric$getRegistryRemapCallback().register(new ItemModelsRemapper()); | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
.../1.12.2/src/main/java/net/legacyfabric/fabric/impl/item/versioned/ItemModelsRemapper.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,72 @@ | ||
/* | ||
* Copyright (c) 2020 - 2024 Legacy Fabric | ||
* Copyright (c) 2016 - 2022 FabricMC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package net.legacyfabric.fabric.impl.item.versioned; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.client.render.item.ItemModels; | ||
import net.minecraft.client.util.ModelIdentifier; | ||
import net.minecraft.item.Item; | ||
|
||
import net.legacyfabric.fabric.api.registry.v2.RegistryHelper; | ||
import net.legacyfabric.fabric.api.registry.v2.event.RegistryRemapCallback; | ||
import net.legacyfabric.fabric.api.registry.v2.registry.holder.FabricRegistryEntry; | ||
import net.legacyfabric.fabric.api.util.Identifier; | ||
import net.legacyfabric.fabric.mixin.item.versioned.ItemModelsAccessor; | ||
|
||
public class ItemModelsRemapper implements RegistryRemapCallback<Item> { | ||
private static final Map<Identifier, Map<Integer, ModelIdentifier>> modelIds = new HashMap<>(); | ||
|
||
public static void registerModelId(Identifier id, int metadata, ModelIdentifier modelId) { | ||
modelIds.computeIfAbsent(id, k -> new HashMap<>()) | ||
.put(metadata, modelId); | ||
} | ||
|
||
private int pack(int itemId, int metadata) { | ||
return itemId << 16 | metadata; | ||
} | ||
|
||
private ItemModels getModelRegistry() { | ||
return MinecraftClient.getInstance().getItemRenderer().getModels(); | ||
} | ||
|
||
@Override | ||
public void callback(Map<Integer, FabricRegistryEntry<Item>> changedIdsMap) { | ||
((ItemModelsAccessor) getModelRegistry()).getModelIds().clear(); | ||
|
||
for (Map.Entry<Identifier, Map<Integer, ModelIdentifier>> entry : modelIds.entrySet()) { | ||
Identifier itemId = entry.getKey(); | ||
|
||
Item item = RegistryHelper.<Item>getValue(Item.REGISTRY, itemId); | ||
int itemIndex = RegistryHelper.getRawId(Item.REGISTRY, item); | ||
|
||
if (changedIdsMap.containsKey(itemIndex)) { | ||
itemIndex = changedIdsMap.get(itemIndex).getId(); | ||
} | ||
|
||
for (Map.Entry<Integer, ModelIdentifier> modelIdEntry : entry.getValue().entrySet()) { | ||
((ItemModelsAccessor) getModelRegistry()).getModelIds() | ||
.put(pack(itemIndex, modelIdEntry.getKey()), modelIdEntry.getValue()); | ||
} | ||
} | ||
|
||
getModelRegistry().reloadModels(); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...1.12.2/src/main/java/net/legacyfabric/fabric/mixin/item/versioned/ItemModelsAccessor.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,32 @@ | ||
/* | ||
* Copyright (c) 2020 - 2024 Legacy Fabric | ||
* Copyright (c) 2016 - 2022 FabricMC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package net.legacyfabric.fabric.mixin.item.versioned; | ||
|
||
import java.util.Map; | ||
|
||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.gen.Accessor; | ||
|
||
import net.minecraft.client.render.item.ItemModels; | ||
import net.minecraft.client.util.ModelIdentifier; | ||
|
||
@Mixin(ItemModels.class) | ||
public interface ItemModelsAccessor { | ||
@Accessor | ||
Map<Integer, ModelIdentifier> getModelIds(); | ||
} |
41 changes: 41 additions & 0 deletions
41
...v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/item/versioned/ItemModelsMixin.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,41 @@ | ||
/* | ||
* Copyright (c) 2020 - 2024 Legacy Fabric | ||
* Copyright (c) 2016 - 2022 FabricMC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package net.legacyfabric.fabric.mixin.item.versioned; | ||
|
||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
import net.minecraft.client.render.item.ItemModels; | ||
import net.minecraft.client.util.ModelIdentifier; | ||
import net.minecraft.item.Item; | ||
|
||
import net.legacyfabric.fabric.api.registry.v2.RegistryHelper; | ||
import net.legacyfabric.fabric.api.util.Identifier; | ||
import net.legacyfabric.fabric.impl.item.versioned.ItemModelsRemapper; | ||
|
||
@Mixin(ItemModels.class) | ||
public class ItemModelsMixin { | ||
@Inject(method = "putModel", at = @At("RETURN")) | ||
private void lf$registerModelId(Item item, int metadata, ModelIdentifier id, CallbackInfo ci) { | ||
Identifier identifier = RegistryHelper.getId(Item.REGISTRY, item); | ||
|
||
if (identifier != null) ItemModelsRemapper.registerModelId(identifier, metadata, id); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
legacy-fabric-item-api-v1/1.12.2/src/main/resources/fabric.mod.json
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,45 @@ | ||
{ | ||
"schemaVersion": 1, | ||
"id": "legacy-fabric-item-api-v1", | ||
"name": "Legacy Fabric Item API (V1)", | ||
"version": "${version}", | ||
"environment": "*", | ||
"license": "Apache-2.0", | ||
"icon": "assets/legacy-fabric/icon.png", | ||
"contact": { | ||
"homepage": "https://legacyfabric.net/", | ||
"irc": "irc://irc.esper.net:6667/legacyfabric", | ||
"issues": "https://github.com/Legacy-Fabric/fabric/issues", | ||
"sources": "https://github.com/Legacy-Fabric/fabric" | ||
}, | ||
"authors": [ | ||
"Legacy-Fabric" | ||
], | ||
"depends": { | ||
"fabricloader": ">=0.4.0", | ||
"minecraft": "${minecraft_version}" | ||
}, | ||
"description": "Item utils", | ||
"entrypoints": { | ||
"preLaunch": [ | ||
"net.legacyfabric.fabric.impl.item.versioned.EarlyInitializer" | ||
] | ||
}, | ||
"mixins": [ | ||
"legacy-fabric-item-api-v1.mixins.json" | ||
], | ||
"custom": { | ||
"loom:injected_interfaces": { | ||
}, | ||
"modmenu": { | ||
"badges": [ "library" ], | ||
"parent": { | ||
"id": "legacy-fabric-api", | ||
"name": "Legacy Fabric API", | ||
"badges": [ "library" ], | ||
"description": "Core API module providing key hooks and inter-compatibility features for Minecraft 1.7.10-1.12.2.", | ||
"icon": "assets/legacy-fabric/icon.png" | ||
} | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
legacy-fabric-item-api-v1/1.12.2/src/main/resources/legacy-fabric-item-api-v1.mixins.json
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,14 @@ | ||
{ | ||
"required": true, | ||
"package": "net.legacyfabric.fabric.mixin.item", | ||
"compatibilityLevel": "JAVA_8", | ||
"injectors": { | ||
"defaultRequire": 1 | ||
}, | ||
"mixins": [ | ||
], | ||
"client": [ | ||
"versioned.ItemModelsAccessor", | ||
"versioned.ItemModelsMixin" | ||
] | ||
} |
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,3 @@ | ||
loom { | ||
accessWidenerPath = file("src/main/resources/legacy-fabric-item-api.accesswidener") | ||
} |
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,2 @@ | ||
minVersionIncluded=1.7 | ||
maxVersionIncluded=1.7.10 |
37 changes: 37 additions & 0 deletions
37
...v1/1.7.10/src/main/java/net/legacyfabric/fabric/impl/item/versioned/EarlyInitializer.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,37 @@ | ||
/* | ||
* Copyright (c) 2020 - 2024 Legacy Fabric | ||
* Copyright (c) 2016 - 2022 FabricMC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package net.legacyfabric.fabric.impl.item.versioned; | ||
|
||
import net.minecraft.item.Item; | ||
|
||
import net.fabricmc.loader.api.entrypoint.PreLaunchEntrypoint; | ||
|
||
import net.legacyfabric.fabric.api.registry.v2.RegistryIds; | ||
import net.legacyfabric.fabric.api.registry.v2.event.RegistryInitializedEvent; | ||
import net.legacyfabric.fabric.api.registry.v2.registry.holder.FabricRegistry; | ||
|
||
public class EarlyInitializer implements PreLaunchEntrypoint { | ||
@Override | ||
public void onPreLaunch() { | ||
RegistryInitializedEvent.event(RegistryIds.ITEMS).register(EarlyInitializer::itemRegistryInit); | ||
} | ||
|
||
private static void itemRegistryInit(FabricRegistry<?> holder) { | ||
FabricRegistry<Item> registry = (FabricRegistry<Item>) holder; | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
legacy-fabric-item-api-v1/1.7.10/src/main/resources/fabric.mod.json
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,44 @@ | ||
{ | ||
"schemaVersion": 1, | ||
"id": "legacy-fabric-item-api-v1", | ||
"name": "Legacy Fabric Item API (V1)", | ||
"version": "${version}", | ||
"environment": "*", | ||
"license": "Apache-2.0", | ||
"icon": "assets/legacy-fabric/icon.png", | ||
"contact": { | ||
"homepage": "https://legacyfabric.net/", | ||
"irc": "irc://irc.esper.net:6667/legacyfabric", | ||
"issues": "https://github.com/Legacy-Fabric/fabric/issues", | ||
"sources": "https://github.com/Legacy-Fabric/fabric" | ||
}, | ||
"authors": [ | ||
"Legacy-Fabric" | ||
], | ||
"depends": { | ||
"fabricloader": ">=0.4.0", | ||
"minecraft": "${minecraft_version}" | ||
}, | ||
"description": "Item utils", | ||
"entrypoints": { | ||
"preLaunch": [] | ||
}, | ||
"mixins": [ | ||
"legacy-fabric-item-api-v1.mixins.json" | ||
], | ||
"accessWidener": "legacy-fabric-item-api.accesswidener", | ||
"custom": { | ||
"loom:injected_interfaces": { | ||
}, | ||
"modmenu": { | ||
"badges": [ "library" ], | ||
"parent": { | ||
"id": "legacy-fabric-api", | ||
"name": "Legacy Fabric API", | ||
"badges": [ "library" ], | ||
"description": "Core API module providing key hooks and inter-compatibility features for Minecraft 1.7.10-1.12.2.", | ||
"icon": "assets/legacy-fabric/icon.png" | ||
} | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
legacy-fabric-item-api-v1/1.7.10/src/main/resources/legacy-fabric-item-api-v1.mixins.json
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,12 @@ | ||
{ | ||
"required": true, | ||
"package": "net.legacyfabric.fabric.mixin.item", | ||
"compatibilityLevel": "JAVA_8", | ||
"injectors": { | ||
"defaultRequire": 1 | ||
}, | ||
"mixins": [ | ||
], | ||
"client": [ | ||
] | ||
} |
3 changes: 3 additions & 0 deletions
3
legacy-fabric-item-api-v1/1.7.10/src/main/resources/legacy-fabric-item-api.accesswidener
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,3 @@ | ||
accessWidener v2 named | ||
|
||
transitive-accessible method net/minecraft/item/Item getFromId (Ljava/lang/String;)Lnet/minecraft/item/Item; |
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,6 @@ | ||
moduleDependencies(project, [ | ||
"legacy-fabric-api-base", | ||
"legacy-fabric-networking-api-v1", | ||
"legacy-fabric-resource-loader-v1", | ||
"legacy-fabric-registry-sync-api-v2" | ||
]) |
Empty file.
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,2 @@ | ||
minVersionIncluded=1.7 | ||
maxVersionIncluded=1.12.2 |
Oops, something went wrong.