1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-11-19 08:14:52 +00:00

Populate item groups on server start

This commit is contained in:
Jonathan Coates 2022-12-31 17:49:57 +00:00
parent aa203802c6
commit 1215d93645
No known key found for this signature in database
GPG Key ID: B9E431FF07C98D06
5 changed files with 43 additions and 0 deletions

View File

@ -21,6 +21,7 @@ import net.minecraft.server.dedicated.DedicatedServer;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.packs.resources.PreparableReloadListener;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.item.CreativeModeTabs;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.chunk.LevelChunk;
import net.minecraft.world.level.storage.loot.BuiltInLootTables;
@ -63,6 +64,12 @@ public final class CommonHooks {
ComputerMBean.start(server);
}
public static void onServerStarted(MinecraftServer server) {
// ItemDetails requires creative tabs to be populated, however by default this is done lazily on the client and
// not at all on the server! We instead do this once on server startup.
CreativeModeTabs.tryRebuildTabContents(server.getWorldData().enabledFeatures(), false);
}
public static void onServerStopped() {
resetState();
}

View File

@ -0,0 +1,28 @@
package dan200.computercraft.gametest
import dan200.computercraft.api.detail.VanillaDetailRegistries
import dan200.computercraft.gametest.api.Structures
import dan200.computercraft.gametest.api.sequence
import net.minecraft.gametest.framework.GameTest
import net.minecraft.gametest.framework.GameTestHelper
import net.minecraft.world.item.ItemStack
import net.minecraft.world.item.Items
import org.junit.jupiter.api.Assertions.assertEquals
class Details_Test {
@GameTest(template = Structures.DEFAULT)
fun Has_item_groups(helper: GameTestHelper) = helper.sequence {
thenExecute {
val details = VanillaDetailRegistries.ITEM_STACK.getDetails(ItemStack(Items.DIRT))
assertEquals(
listOf(
mapOf(
"displayName" to "Natural Blocks",
"id" to "minecraft:natural",
),
),
details["itemGroups"],
)
}
}
}

View File

@ -73,6 +73,7 @@ object TestHooks {
private val testClasses = listOf(
Computer_Test::class.java,
CraftOs_Test::class.java,
Details_Test::class.java,
Disk_Drive_Test::class.java,
Inventory_Test::class.java,
Loot_Test::class.java,

View File

@ -82,6 +82,7 @@ public class ComputerCraft {
// Register hooks
ServerLifecycleEvents.SERVER_STARTING.register(CommonHooks::onServerStarting);
ServerLifecycleEvents.SERVER_STARTED.register(CommonHooks::onServerStarted);
ServerLifecycleEvents.SERVER_STOPPED.register(s -> CommonHooks.onServerStopped());
ServerLifecycleEvents.SYNC_DATA_PACK_CONTENTS.register((player, joined) -> PlatformHelper.get().sendToPlayer(new UpgradesLoadedMessage(), player));

View File

@ -29,6 +29,7 @@ import net.minecraftforge.event.*;
import net.minecraftforge.event.entity.EntityJoinLevelEvent;
import net.minecraftforge.event.entity.living.LivingDropsEvent;
import net.minecraftforge.event.level.ChunkWatchEvent;
import net.minecraftforge.event.server.ServerStartedEvent;
import net.minecraftforge.event.server.ServerStartingEvent;
import net.minecraftforge.event.server.ServerStoppedEvent;
import net.minecraftforge.eventbus.api.EventPriority;
@ -58,6 +59,11 @@ public class ForgeCommonHooks {
CommonHooks.onServerStarting(event.getServer());
}
@SubscribeEvent
public static void onServerStarted(ServerStartedEvent event) {
CommonHooks.onServerStarted(event.getServer());
}
@SubscribeEvent
public static void onServerStopped(ServerStoppedEvent event) {
CommonHooks.onServerStopped();