Fix MC-197259 - Modded blocks not present in debug world type. ()

Closes 

* Fix MC-197259 - Modded blocks not present in debug world type.

* Remove un-used method.
This commit is contained in:
modmuss50 2022-03-03 18:17:21 +00:00 committed by GitHub
parent 34b2a0ce93
commit ca4be9c944
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 70 additions and 0 deletions
fabric-registry-sync-v0/src/main
java/net/fabricmc/fabric
resources

View file

@ -16,11 +16,16 @@
package net.fabricmc.fabric.impl.registry.sync.trackers.vanilla;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.registry.Registry;
import net.fabricmc.fabric.api.event.registry.RegistryEntryAddedCallback;
import net.fabricmc.fabric.mixin.registry.sync.AccessorDebugChunkGenerator;
public final class BlockInitTracker implements RegistryEntryAddedCallback<Block> {
private final Registry<Block> registry;
@ -41,4 +46,17 @@ public final class BlockInitTracker implements RegistryEntryAddedCallback<Block>
object.getLootTableId();
}
public static void postFreeze() {
final List<BlockState> blockStateList = Registry.BLOCK.stream()
.flatMap((block) -> block.getStateManager().getStates().stream())
.toList();
final int xLength = MathHelper.ceil(MathHelper.sqrt(blockStateList.size()));
final int zLength = MathHelper.ceil(blockStateList.size() / (float) xLength);
AccessorDebugChunkGenerator.setBLOCK_STATES(blockStateList);
AccessorDebugChunkGenerator.setX_SIDE_LENGTH(xLength);
AccessorDebugChunkGenerator.setZ_SIDE_LENGTH(zLength);
}
}

View file

@ -0,0 +1,47 @@
/*
* Copyright (c) 2016, 2017, 2018, 2019 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.fabricmc.fabric.mixin.registry.sync;
import java.util.List;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Mutable;
import org.spongepowered.asm.mixin.gen.Accessor;
import net.minecraft.block.BlockState;
import net.minecraft.world.gen.chunk.DebugChunkGenerator;
@Mixin(DebugChunkGenerator.class)
public interface AccessorDebugChunkGenerator {
@Accessor
@Mutable
static void setBLOCK_STATES(List<BlockState> blockStates) {
throw new UnsupportedOperationException();
}
@Accessor
@Mutable
static void setX_SIDE_LENGTH(int length) {
throw new UnsupportedOperationException();
}
@Accessor
@Mutable
static void setZ_SIDE_LENGTH(int length) {
throw new UnsupportedOperationException();
}
}

View file

@ -28,6 +28,7 @@ import net.minecraft.server.MinecraftServer;
import net.minecraft.util.registry.Registry;
import net.fabricmc.api.EnvType;
import net.fabricmc.fabric.impl.registry.sync.trackers.vanilla.BlockInitTracker;
import net.fabricmc.loader.api.FabricLoader;
@Mixin(MinecraftServer.class)
@ -41,6 +42,7 @@ public class MixinMinecraftServer {
// Freeze the registries on the server
FABRIC_LOGGER.debug("Freezing registries");
Registry.freezeRegistries();
BlockInitTracker.postFreeze();
}
}
}

View file

@ -30,6 +30,7 @@ import net.minecraft.util.registry.Registry;
import net.fabricmc.fabric.impl.registry.sync.RegistrySyncManager;
import net.fabricmc.fabric.impl.registry.sync.RemapException;
import net.fabricmc.fabric.impl.registry.sync.trackers.vanilla.BlockInitTracker;
@Mixin(MinecraftClient.class)
public class MixinMinecraftClient {
@ -51,5 +52,6 @@ public class MixinMinecraftClient {
// Freeze the registries on the client
FABRIC_LOGGER.debug("Freezing registries");
Registry.freezeRegistries();
BlockInitTracker.postFreeze();
}
}

View file

@ -3,6 +3,7 @@
"package": "net.fabricmc.fabric.mixin.registry.sync",
"compatibilityLevel": "JAVA_16",
"mixins": [
"AccessorDebugChunkGenerator",
"AccessorLevelStorageSession",
"AccessorRegistry",
"MixinBootstrap",