mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-01-09 08:50:29 +00:00
Populate item groups on server start
This commit is contained in:
parent
aa203802c6
commit
1215d93645
@ -21,6 +21,7 @@ import net.minecraft.server.dedicated.DedicatedServer;
|
|||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
import net.minecraft.server.packs.resources.PreparableReloadListener;
|
import net.minecraft.server.packs.resources.PreparableReloadListener;
|
||||||
import net.minecraft.world.entity.Entity;
|
import net.minecraft.world.entity.Entity;
|
||||||
|
import net.minecraft.world.item.CreativeModeTabs;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.level.chunk.LevelChunk;
|
import net.minecraft.world.level.chunk.LevelChunk;
|
||||||
import net.minecraft.world.level.storage.loot.BuiltInLootTables;
|
import net.minecraft.world.level.storage.loot.BuiltInLootTables;
|
||||||
@ -63,6 +64,12 @@ public final class CommonHooks {
|
|||||||
ComputerMBean.start(server);
|
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() {
|
public static void onServerStopped() {
|
||||||
resetState();
|
resetState();
|
||||||
}
|
}
|
||||||
|
@ -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"],
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -73,6 +73,7 @@ object TestHooks {
|
|||||||
private val testClasses = listOf(
|
private val testClasses = listOf(
|
||||||
Computer_Test::class.java,
|
Computer_Test::class.java,
|
||||||
CraftOs_Test::class.java,
|
CraftOs_Test::class.java,
|
||||||
|
Details_Test::class.java,
|
||||||
Disk_Drive_Test::class.java,
|
Disk_Drive_Test::class.java,
|
||||||
Inventory_Test::class.java,
|
Inventory_Test::class.java,
|
||||||
Loot_Test::class.java,
|
Loot_Test::class.java,
|
||||||
|
@ -82,6 +82,7 @@ public class ComputerCraft {
|
|||||||
|
|
||||||
// Register hooks
|
// Register hooks
|
||||||
ServerLifecycleEvents.SERVER_STARTING.register(CommonHooks::onServerStarting);
|
ServerLifecycleEvents.SERVER_STARTING.register(CommonHooks::onServerStarting);
|
||||||
|
ServerLifecycleEvents.SERVER_STARTED.register(CommonHooks::onServerStarted);
|
||||||
ServerLifecycleEvents.SERVER_STOPPED.register(s -> CommonHooks.onServerStopped());
|
ServerLifecycleEvents.SERVER_STOPPED.register(s -> CommonHooks.onServerStopped());
|
||||||
ServerLifecycleEvents.SYNC_DATA_PACK_CONTENTS.register((player, joined) -> PlatformHelper.get().sendToPlayer(new UpgradesLoadedMessage(), player));
|
ServerLifecycleEvents.SYNC_DATA_PACK_CONTENTS.register((player, joined) -> PlatformHelper.get().sendToPlayer(new UpgradesLoadedMessage(), player));
|
||||||
|
|
||||||
|
@ -29,6 +29,7 @@ import net.minecraftforge.event.*;
|
|||||||
import net.minecraftforge.event.entity.EntityJoinLevelEvent;
|
import net.minecraftforge.event.entity.EntityJoinLevelEvent;
|
||||||
import net.minecraftforge.event.entity.living.LivingDropsEvent;
|
import net.minecraftforge.event.entity.living.LivingDropsEvent;
|
||||||
import net.minecraftforge.event.level.ChunkWatchEvent;
|
import net.minecraftforge.event.level.ChunkWatchEvent;
|
||||||
|
import net.minecraftforge.event.server.ServerStartedEvent;
|
||||||
import net.minecraftforge.event.server.ServerStartingEvent;
|
import net.minecraftforge.event.server.ServerStartingEvent;
|
||||||
import net.minecraftforge.event.server.ServerStoppedEvent;
|
import net.minecraftforge.event.server.ServerStoppedEvent;
|
||||||
import net.minecraftforge.eventbus.api.EventPriority;
|
import net.minecraftforge.eventbus.api.EventPriority;
|
||||||
@ -58,6 +59,11 @@ public class ForgeCommonHooks {
|
|||||||
CommonHooks.onServerStarting(event.getServer());
|
CommonHooks.onServerStarting(event.getServer());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public static void onServerStarted(ServerStartedEvent event) {
|
||||||
|
CommonHooks.onServerStarted(event.getServer());
|
||||||
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public static void onServerStopped(ServerStoppedEvent event) {
|
public static void onServerStopped(ServerStoppedEvent event) {
|
||||||
CommonHooks.onServerStopped();
|
CommonHooks.onServerStopped();
|
||||||
|
Loading…
Reference in New Issue
Block a user