Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Registry sync v2 - Block #172

Draft
wants to merge 49 commits into
base: feature/registry-sync-v2/main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
6ade139
Initial work on registry-sync-v2
thecatcore Mar 17, 2024
f482232
More progress on registry api v2
thecatcore Mar 23, 2024
c12dfb6
Initial work on item-api
thecatcore Mar 23, 2024
2b57a72
spotless apply
thecatcore Mar 24, 2024
d949960
Start working on new registry remapper
thecatcore Mar 24, 2024
0a6871b
Merge branch 'feature/registry-sync-v2/api' into feature/registry-syn…
thecatcore Mar 29, 2024
3002ffc
Rename some classes
thecatcore Apr 24, 2024
395e372
Rename some classes
thecatcore Apr 24, 2024
e117bec
Merge branch 'refs/heads/feature/registry-sync-v2/api' into feature/r…
thecatcore Apr 24, 2024
188ea3d
Merge branch 'refs/heads/main' into feature/registry-sync-v2/api
thecatcore May 5, 2024
09146c1
Merge branch 'refs/heads/feature/registry-sync-v2/api' into feature/r…
thecatcore May 5, 2024
3c6e7ee
Move registry related test mods to per version global test mods
thecatcore May 5, 2024
dec3757
Update loom and gradle
thecatcore May 5, 2024
6f5bf3b
Port remapping system to v2 and port to every supported version
thecatcore May 5, 2024
b533add
Ensure backward compatibility with registry-sync-api-v1
thecatcore May 5, 2024
9998e02
Merge branch 'refs/heads/feature/registry-sync-v2/api' into feature/r…
thecatcore May 5, 2024
f314ddd
Item registry is fully ported already
thecatcore May 5, 2024
7d4714c
Make it easier to set item texture in 1.7.10
thecatcore May 7, 2024
7649656
Fix item models being wrong after registry is remapped for 1.8+
thecatcore May 7, 2024
cbd3b5a
Disable Block testmods as Block registry is not ported yet
thecatcore May 7, 2024
648e610
Fix a few possible crashes when using registries
thecatcore May 7, 2024
b6cbf78
Add more useful methods to RegistryHelper
thecatcore May 7, 2024
b9d5671
Merge branch 'refs/heads/feature/registry-sync-v2/api' into feature/r…
thecatcore May 7, 2024
2bd406d
Fix style
thecatcore May 7, 2024
49679c5
Fix Item registry being registered before vanilla items initialisation
thecatcore May 8, 2024
2226ba6
Remove block related fixes from item modules
thecatcore May 8, 2024
e3850eb
New Block module
thecatcore May 8, 2024
f0259fa
Fix whether to use neighbour light for Modded blocks
thecatcore May 8, 2024
b2266b7
Make vanilla registries first assignable id 1 instead of 0
thecatcore May 8, 2024
f47b8e2
Some improvements and bug fixes.
thecatcore May 8, 2024
2ac36af
Create a default implementation of IdsHolder and SyncedRegistrableReg…
thecatcore May 8, 2024
5cb1492
Start working on wrapper for non-standard registry forms
thecatcore May 8, 2024
c44ee86
Clean up and fix style
thecatcore May 8, 2024
f44ba90
Merge branch 'refs/heads/feature/registry-sync-v2/api' into feature/r…
thecatcore May 8, 2024
a87e0f8
Clean up and fix style
thecatcore May 8, 2024
e7691fe
Merge branch 'refs/heads/feature/registry-sync-v2/item' into feature/…
thecatcore May 8, 2024
8d57426
Clean up and fix style
thecatcore May 8, 2024
10d7cbd
Fix missing events in MapRegistryWrapper
thecatcore May 8, 2024
4caee9f
Avoid using sysout
thecatcore May 8, 2024
da6916f
Allow Synchronized Registry to declare themselves not to be synchronized
thecatcore May 8, 2024
f0920b7
Merge branch 'refs/heads/feature/registry-sync-v2/api' into feature/r…
thecatcore May 8, 2024
5398991
Merge branch 'refs/heads/feature/registry-sync-v2/item' into feature/…
thecatcore May 8, 2024
b1ff8b8
Allow setting the min id possible of a registry
thecatcore Jun 6, 2024
b7a8575
Fix entry count in IdsHolder
thecatcore Jun 6, 2024
7e4d6fe
Merge branch 'refs/heads/feature/registry-sync-v2/api' into feature/r…
thecatcore Jun 6, 2024
85b0d28
Merge branch 'refs/heads/feature/registry-sync-v2/item' into feature/…
thecatcore Jun 6, 2024
d9996b3
Merge branch 'refs/heads/feature/registry-sync-v2/main' into feature/…
thecatcore Jul 6, 2024
12cd75d
Merge branch 'refs/heads/feature/registry-sync-v2/api' into feature/r…
thecatcore Jul 6, 2024
caa63a6
Merge branch 'refs/heads/feature/registry-sync-v2/item' into feature/…
thecatcore Jul 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,10 @@ allprojects {
useLegacyMixinAp = true
}

interfaceInjection {
enableDependencyInterfaceInjection = true
}

runs {
"testModClient$mcVersion" {
client()
Expand Down Expand Up @@ -451,7 +455,8 @@ def addPomMetadataInformation(Project project, MavenPom pom) {
def modJsonFile = project.file("src/main/resources/fabric.mod.json")

if (!modJsonFile.exists()) {
modJsonFile = project.file("src/client/resources/fabric.mod.json")
logger.error("Can't find fabric.mod.json at ${modJsonFile.toString()}!")
return;
}

def modJson = new JsonSlurper().parse(modJsonFile)
Expand Down
3 changes: 3 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,8 @@ legacy-fabric-logger-api-v1.version = 1.0.4
legacy-fabric-networking-api-v1.version = 2.0.2
legacy-fabric-permissions-api-v1.version = 1.1.0
legacy-fabric-registry-sync-api-v1.version = 2.2.0
legacy-fabric-registry-sync-api-v2.version = 1.0.0
legacy-fabric-item-api-v1.version = 1.0.0
legacy-fabric-block-api-v1.version = 1.0.0
legacy-fabric-rendering-api-v1.version = 1.0.0
legacy-fabric-resource-loader-v1.version = 2.2.1
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ public String toString() {
return this.namespace + ':' + this.path;
}

public String toTranslationKey() {
return this.namespace + "." + this.path;
}

public boolean equals(Object object) {
if (this == object) {
return true;
Expand Down
3 changes: 3 additions & 0 deletions legacy-fabric-block-api-v1/1.12.2/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
loom {
accessWidenerPath = file("src/main/resources/legacy-fabric-block-api-v1.accesswidener")
}
2 changes: 2 additions & 0 deletions legacy-fabric-block-api-v1/1.12.2/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minVersionIncluded=1.8
maxVersionIncluded=1.12.2
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* 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.block.versioned;

import java.util.Map;

import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.util.collection.IdList;

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.RegistryEntry;
import net.legacyfabric.fabric.api.registry.v2.registry.registrable.IdsHolder;
import net.legacyfabric.fabric.api.util.Identifier;
import net.legacyfabric.fabric.api.util.VersionUtils;
import net.legacyfabric.fabric.mixin.block.versioned.BlockAccessor;

public class BlockStateRemapper implements RegistryRemapCallback<Block> {
private static final boolean hasSpecialCase = VersionUtils.matches(">1.8.9");
private static final Identifier specialCaseId = new Identifier("tripwire");

@Override
public void callback(Map<Integer, RegistryEntry<Block>> changedIdsMap) {
IdsHolder<BlockState> newList = Block.BLOCK_STATES.fabric$new();

for (Block block : Block.REGISTRY) {
int blockRawId = RegistryHelper.getRawId(Block.REGISTRY, block);

if (changedIdsMap.containsKey(blockRawId)) {
blockRawId = changedIdsMap.get(blockRawId).getId();
}

Identifier blockId = RegistryHelper.getId(Block.REGISTRY, block);

if (blockId.equals(specialCaseId) && hasSpecialCase) {
for (int i = 0; i < 15; ++i) {
int blockStateId = blockRawId << 4 | i;
BlockState state = block.stateFromData(i);

newList.fabric$setValue(state, blockStateId);
}
} else {
for (BlockState state : block.getStateManager().getBlockStates()) {
int blockStateId = blockRawId << 4 | block.getData(state);

newList.fabric$setValue(state, blockStateId);
}
}
}

BlockAccessor.setBLOCK_STATES((IdList<BlockState>) newList);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* 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.block.versioned;

import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.SlabBlock;
import net.minecraft.block.StairsBlock;
import net.minecraft.block.material.Material;
import net.minecraft.item.BlockItem;
import net.minecraft.item.Item;

import net.fabricmc.loader.api.entrypoint.PreLaunchEntrypoint;

import net.legacyfabric.fabric.api.registry.v2.RegistryHelper;
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.Registry;
import net.legacyfabric.fabric.api.registry.v2.registry.holder.SyncedRegistry;
import net.legacyfabric.fabric.api.util.Identifier;
import net.legacyfabric.fabric.api.util.VersionUtils;
import net.legacyfabric.fabric.mixin.block.versioned.ItemAccessor;

public class EarlyInitializer implements PreLaunchEntrypoint {
private static final boolean checkGrass = VersionUtils.matches(">1.8.9");
@Override
public void onPreLaunch() {
RegistryInitializedEvent.event(RegistryIds.BLOCKS).register(EarlyInitializer::blockRegistryInit);
RegistryInitializedEvent.event(RegistryIds.ITEMS).register(EarlyInitializer::itemRegistryInit);
}

private static void blockRegistryInit(Registry<?> holder) {
SyncedRegistry<Block> registry = (SyncedRegistry<Block>) holder;

registry.fabric$getEntryAddedCallback().register((rawId, id, block) -> {
for (BlockState blockState : block.getStateManager().getBlockStates()) {
int i = rawId << 4 | block.getData(blockState);
Block.BLOCK_STATES.set(blockState, i);
}
});

registry.fabric$getRegistryRemapCallback().register(new BlockStateRemapper());

registry.fabric$getEntryAddedCallback().register((rawId, id, block) -> {
if (block.material == Material.AIR) {
block.useNeighbourLight = false;
} else {
boolean var12 = false;
boolean var13 = block instanceof StairsBlock;
boolean var14 = block instanceof SlabBlock;
boolean var15 = block == RegistryHelper.getValue(Item.REGISTRY, new Identifier("farmland"))
|| (checkGrass && block == RegistryHelper.getValue(Item.REGISTRY, new Identifier("grass_path")));
boolean var16 = block.transluscent;
boolean var17 = block.opacity == 0;

if (var13 || var14 || var15 || var16 || var17) {
var12 = true;
}

block.useNeighbourLight = var12;
}
});
}

private static void itemRegistryInit(Registry<?> holder) {
SyncedRegistry<Item> registry = (SyncedRegistry<Item>) holder;

registry.fabric$getEntryAddedCallback().register((rawId, id, item) -> {
if (item instanceof BlockItem) {
ItemAccessor.getBLOCK_ITEMS().put(((BlockItem) item).getBlock(), item);
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,18 @@
* limitations under the License.
*/

package net.legacyfabric.fabric.mixin.registry.sync;
package net.legacyfabric.fabric.mixin.block.versioned;

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.gen.Accessor;

import net.minecraft.block.Block;
import net.minecraft.item.Item;

import net.legacyfabric.fabric.impl.registry.sync.compat.ItemCompat;

@Mixin(Item.class)
public class ItemMixin implements ItemCompat {
@Shadow
@Final
private static Map<Block, Item> BLOCK_ITEMS;
import net.minecraft.block.BlockState;
import net.minecraft.util.collection.IdList;

@Override
public Map<Block, Item> getBLOCK_ITEMS() {
return BLOCK_ITEMS;
@Mixin(Block.class)
public interface BlockAccessor {
@Accessor
static void setBLOCK_STATES(IdList<BlockState> blockStates) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,30 @@
* limitations under the License.
*/

package net.legacyfabric.fabric.mixin.registry.sync.registry;
package net.legacyfabric.fabric.mixin.block.versioned;

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.Block;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.entity.effect.StatusEffect;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.BiDefaultedRegistry;

import net.legacyfabric.fabric.impl.registry.RegistryHelperImpl;
import net.legacyfabric.fabric.impl.registry.sync.remappers.BlockRegistryRemapper;
import net.legacyfabric.fabric.api.registry.v2.RegistryHelper;
import net.legacyfabric.fabric.api.registry.v2.RegistryIds;

@Mixin(Block.class)
public class BlockMixin {
@Inject(method = "setup", at = @At("RETURN"))
private static void initRegistryRemapper(CallbackInfo ci) {
RegistryHelperImpl.registerRegistryRemapper(BlockRegistryRemapper::new);

if (!RegistryHelperImpl.bootstrap) {
try {
Class.forName(StatusEffect.class.getName());
@Shadow
@Final
public static BiDefaultedRegistry<Identifier, Block> REGISTRY;

Class.forName(Enchantment.class.getName());
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
@Inject(method = "setup", at = @At("RETURN"))
private static void registerRegistry(CallbackInfo ci) {
RegistryHelper.addRegistry(RegistryIds.BLOCKS, REGISTRY);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,20 @@
* limitations under the License.
*/

package net.legacyfabric.fabric.mixin.registry.sync;
package net.legacyfabric.fabric.mixin.block.versioned;

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.gen.Accessor;

import net.minecraft.block.Block;
import net.minecraft.item.Item;

import net.legacyfabric.fabric.impl.registry.sync.compat.ItemCompat;

@Mixin(Item.class)
public class ItemMixin implements ItemCompat {
@Shadow
@Final
private static Map<Block, Item> BLOCK_ITEMS;

@Override
public Map<Block, Item> getBLOCK_ITEMS() {
return BLOCK_ITEMS;
public interface ItemAccessor {
@Accessor
static Map<Block, Item> getBLOCK_ITEMS() {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"schemaVersion": 1,
"id": "legacy-fabric-block-api-v1",
"name": "Legacy Fabric Block 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 utils",
"entrypoints": {
"preLaunch": [
"net.legacyfabric.fabric.impl.block.versioned.EarlyInitializer"
]
},
"mixins": [
"legacy-fabric-block-api-v1.mixins.json"
],
"accessWidener": "legacy-fabric-block-api-v1.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"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
accessWidener v2 named

accessible field net/minecraft/block/Block useNeighbourLight Z
accessible field net/minecraft/block/Block transluscent Z
accessible field net/minecraft/block/Block material Lnet/minecraft/block/material/Material;
accessible field net/minecraft/block/Block opacity I
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"required": true,
"package": "net.legacyfabric.fabric.mixin.block.versioned",
"compatibilityLevel": "JAVA_8",
"injectors": {
"defaultRequire": 1
},
"mixins": [
"BlockAccessor",
"BlockMixin",
"ItemAccessor"
],
"client": [
]
}
3 changes: 3 additions & 0 deletions legacy-fabric-block-api-v1/1.7.10/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
loom {
accessWidenerPath = file("src/main/resources/legacy-fabric-block-api-v1.accesswidener")
}
Loading
Loading