-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Registry sync v2 - Block Entity (#173)
- Loading branch information
1 parent
c89b8a8
commit 503a181
Showing
40 changed files
with
955 additions
and
13 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.10.2 | ||
maxVersionIncluded=1.10.2 |
76 changes: 76 additions & 0 deletions
76
...-v1/1.10.2/src/main/java/net/legacyfabric/fabric/mixin/block/entity/BlockEntityMixin.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,76 @@ | ||
/* | ||
* 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.block.entity; | ||
|
||
import java.util.Map; | ||
|
||
import org.spongepowered.asm.mixin.Final; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.Unique; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.ModifyArg; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
import net.minecraft.block.entity.BlockEntity; | ||
|
||
import net.legacyfabric.fabric.api.registry.v2.RegistryHelper; | ||
import net.legacyfabric.fabric.api.registry.v2.RegistryIds; | ||
import net.legacyfabric.fabric.api.registry.v2.registry.holder.FabricRegistry; | ||
import net.legacyfabric.fabric.api.util.Identifier; | ||
import net.legacyfabric.fabric.impl.block.entity.BlockEntityUtils; | ||
import net.legacyfabric.fabric.impl.registry.wrapper.MapFabricRegistryWrapper; | ||
|
||
@Mixin(BlockEntity.class) | ||
public class BlockEntityMixin { | ||
@Shadow | ||
@Final | ||
private static Map<String, Class<? extends BlockEntity>> stringClassMap; | ||
@Shadow | ||
@Final | ||
private static Map<Class<? extends BlockEntity>, String> classStringMap; | ||
@Unique | ||
private static FabricRegistry<Class<? extends BlockEntity>> BLOCK_ENTITY_TYPE_REGISTRY; | ||
|
||
@Inject(method = "<clinit>", at = @At("RETURN")) | ||
private static void registerRegistry(CallbackInfo ci) { | ||
BLOCK_ENTITY_TYPE_REGISTRY = new MapFabricRegistryWrapper<>( | ||
RegistryIds.BLOCK_ENTITY_TYPES, stringClassMap, classStringMap, | ||
identifier -> BlockEntityUtils.ID_TO_OLD.getOrDefault(identifier, identifier.toString()), | ||
string -> BlockEntityUtils.OLD_TO_ID.getOrDefault(string, new Identifier(string)) | ||
); | ||
|
||
RegistryHelper.addRegistry(RegistryIds.BLOCK_ENTITY_TYPES, BLOCK_ENTITY_TYPE_REGISTRY); | ||
} | ||
|
||
/* | ||
Previous version of LFAPI used to transform vanilla names to id. | ||
We don't do that anymore, so we still check for id versions to not break old saves. | ||
*/ | ||
@ModifyArg(method = "create", at = @At(value = "INVOKE", remap = false, target = "Ljava/util/Map;get(Ljava/lang/Object;)Ljava/lang/Object;")) | ||
private static Object fixOldSaves(Object oldKey) { | ||
Identifier asId = new Identifier(oldKey); | ||
|
||
if (BlockEntityUtils.ID_TO_OLD.containsKey(asId)) { | ||
return BlockEntityUtils.ID_TO_OLD.get(asId); | ||
} | ||
|
||
return oldKey; | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
legacy-fabric-block-entity-api-v1/1.10.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,44 @@ | ||
{ | ||
"schemaVersion": 1, | ||
"id": "legacy-fabric-block-entity-api-v1", | ||
"name": "Legacy Fabric Block Entity 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": "Block Entity utils", | ||
"entrypoints": { | ||
"preLaunch": [ | ||
] | ||
}, | ||
"mixins": [ | ||
"legacy-fabric-block-entity-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" | ||
} | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...ock-entity-api-v1/1.10.2/src/main/resources/legacy-fabric-block-entity-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,13 @@ | ||
{ | ||
"required": true, | ||
"package": "net.legacyfabric.fabric.mixin.block.entity", | ||
"compatibilityLevel": "JAVA_8", | ||
"injectors": { | ||
"defaultRequire": 1 | ||
}, | ||
"mixins": [ | ||
"BlockEntityMixin" | ||
], | ||
"client": [ | ||
] | ||
} |
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.11 | ||
maxVersionIncluded=1.12.2 |
46 changes: 46 additions & 0 deletions
46
...-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/block/entity/BlockEntityMixin.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,46 @@ | ||
/* | ||
* 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.block.entity; | ||
|
||
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; | ||
|
||
import net.minecraft.block.entity.BlockEntity; | ||
import net.minecraft.util.Identifier; | ||
import net.minecraft.util.registry.SimpleRegistry; | ||
|
||
import net.legacyfabric.fabric.api.registry.v2.RegistryHelper; | ||
import net.legacyfabric.fabric.api.registry.v2.RegistryIds; | ||
import net.legacyfabric.fabric.api.registry.v2.registry.registrable.DesynchronizeableRegistrable; | ||
|
||
@Mixin(BlockEntity.class) | ||
public class BlockEntityMixin { | ||
@Shadow | ||
@Final | ||
private static SimpleRegistry<Identifier, Class<? extends BlockEntity>> BLOCK_ENTITY; | ||
|
||
@Inject(method = "<clinit>", at = @At("RETURN")) | ||
private static void registerRegistry(CallbackInfo ci) { | ||
((DesynchronizeableRegistrable) BLOCK_ENTITY).fabric$setSynchronize(false); | ||
RegistryHelper.addRegistry(RegistryIds.BLOCK_ENTITY_TYPES, BLOCK_ENTITY); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
legacy-fabric-block-entity-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,44 @@ | ||
{ | ||
"schemaVersion": 1, | ||
"id": "legacy-fabric-block-entity-api-v1", | ||
"name": "Legacy Fabric Block Entity 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": "Block Entity utils", | ||
"entrypoints": { | ||
"preLaunch": [ | ||
] | ||
}, | ||
"mixins": [ | ||
"legacy-fabric-block-entity-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" | ||
} | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...ock-entity-api-v1/1.12.2/src/main/resources/legacy-fabric-block-entity-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,13 @@ | ||
{ | ||
"required": true, | ||
"package": "net.legacyfabric.fabric.mixin.block.entity", | ||
"compatibilityLevel": "JAVA_8", | ||
"injectors": { | ||
"defaultRequire": 1 | ||
}, | ||
"mixins": [ | ||
"BlockEntityMixin" | ||
], | ||
"client": [ | ||
] | ||
} |
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.9.4 |
76 changes: 76 additions & 0 deletions
76
...i-v1/1.8.9/src/main/java/net/legacyfabric/fabric/mixin/block/entity/BlockEntityMixin.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,76 @@ | ||
/* | ||
* 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.block.entity; | ||
|
||
import java.util.Map; | ||
|
||
import org.spongepowered.asm.mixin.Final; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.Unique; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.ModifyArg; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
import net.minecraft.block.entity.BlockEntity; | ||
|
||
import net.legacyfabric.fabric.api.registry.v2.RegistryHelper; | ||
import net.legacyfabric.fabric.api.registry.v2.RegistryIds; | ||
import net.legacyfabric.fabric.api.registry.v2.registry.holder.FabricRegistry; | ||
import net.legacyfabric.fabric.api.util.Identifier; | ||
import net.legacyfabric.fabric.impl.block.entity.BlockEntityUtils; | ||
import net.legacyfabric.fabric.impl.registry.wrapper.MapFabricRegistryWrapper; | ||
|
||
@Mixin(BlockEntity.class) | ||
public class BlockEntityMixin { | ||
@Shadow | ||
@Final | ||
private static Map<String, Class<? extends BlockEntity>> stringClassMap; | ||
@Shadow | ||
@Final | ||
private static Map<Class<? extends BlockEntity>, String> classStringMap; | ||
@Unique | ||
private static FabricRegistry<Class<? extends BlockEntity>> BLOCK_ENTITY_TYPE_REGISTRY; | ||
|
||
@Inject(method = "<clinit>", at = @At("RETURN")) | ||
private static void registerRegistry(CallbackInfo ci) { | ||
BLOCK_ENTITY_TYPE_REGISTRY = new MapFabricRegistryWrapper<>( | ||
RegistryIds.BLOCK_ENTITY_TYPES, stringClassMap, classStringMap, | ||
identifier -> BlockEntityUtils.ID_TO_OLD.getOrDefault(identifier, identifier.toString()), | ||
string -> BlockEntityUtils.OLD_TO_ID.getOrDefault(string, new Identifier(string)) | ||
); | ||
|
||
RegistryHelper.addRegistry(RegistryIds.BLOCK_ENTITY_TYPES, BLOCK_ENTITY_TYPE_REGISTRY); | ||
} | ||
|
||
/* | ||
Previous version of LFAPI used to transform vanilla names to id. | ||
We don't do that anymore, so we still check for id versions to not break old saves. | ||
*/ | ||
@ModifyArg(method = "createFromNbt", at = @At(value = "INVOKE", remap = false, target = "Ljava/util/Map;get(Ljava/lang/Object;)Ljava/lang/Object;")) | ||
private static Object fixOldSaves(Object oldKey) { | ||
Identifier asId = new Identifier(oldKey); | ||
|
||
if (BlockEntityUtils.ID_TO_OLD.containsKey(asId)) { | ||
return BlockEntityUtils.ID_TO_OLD.get(asId); | ||
} | ||
|
||
return oldKey; | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
legacy-fabric-block-entity-api-v1/1.8.9/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-block-entity-api-v1", | ||
"name": "Legacy Fabric Block Entity 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": "Block Entity utils", | ||
"entrypoints": { | ||
"preLaunch": [ | ||
] | ||
}, | ||
"mixins": [ | ||
"legacy-fabric-block-entity-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" | ||
} | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...lock-entity-api-v1/1.8.9/src/main/resources/legacy-fabric-block-entity-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,13 @@ | ||
{ | ||
"required": true, | ||
"package": "net.legacyfabric.fabric.mixin.block.entity", | ||
"compatibilityLevel": "JAVA_8", | ||
"injectors": { | ||
"defaultRequire": 1 | ||
}, | ||
"mixins": [ | ||
"BlockEntityMixin" | ||
], | ||
"client": [ | ||
] | ||
} |
Oops, something went wrong.