更新版本号0.1.1 -> 0.1.2
添加LevelHelper
This commit is contained in:
parent
87bffc5fc9
commit
b5513dbc39
|
|
@ -33,7 +33,7 @@ mod_name=3944Realms 's Lib Mod
|
|||
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
|
||||
mod_license=MIT
|
||||
# The mod version. See https://semver.org/
|
||||
mod_version=0.1.1
|
||||
mod_version=0.1.2
|
||||
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
|
||||
# This should match the base package used for the mod sources.
|
||||
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html
|
||||
|
|
|
|||
|
|
@ -1,21 +1,19 @@
|
|||
package top.r3944realms.lib39.core.event;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.resources.model.BakedModel;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.client.multiplayer.ClientLevel;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.client.event.EntityRenderersEvent;
|
||||
import net.minecraftforge.client.event.ModelEvent;
|
||||
import net.minecraftforge.client.event.RegisterShadersEvent;
|
||||
import net.minecraftforge.event.level.LevelEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import top.r3944realms.lib39.Lib39;
|
||||
import top.r3944realms.lib39.client.model.DollModel;
|
||||
import top.r3944realms.lib39.client.renderer.block.DollBlockEntityRenderer;
|
||||
import top.r3944realms.lib39.client.shader.Lib39Shaders;
|
||||
import top.r3944realms.lib39.content.register.Lib39BlockEntities;
|
||||
|
||||
import java.util.Map;
|
||||
import top.r3944realms.lib39.util.ILevelHelper;
|
||||
|
||||
/**
|
||||
* The type Client handler.
|
||||
|
|
@ -61,5 +59,20 @@ public class ClientEventHandler {
|
|||
/**
|
||||
* The type Game.
|
||||
*/
|
||||
public static class Game extends ClientEventHandler {}
|
||||
@net.minecraftforge.fml.common.Mod.EventBusSubscriber(value = Dist.CLIENT, bus = net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus.FORGE, modid = Lib39.MOD_ID)
|
||||
public static class Game extends ClientEventHandler {
|
||||
@SubscribeEvent
|
||||
public static void registerLayerDefinitions(LevelEvent.Load event) {
|
||||
if (event.getLevel() != null && event.getLevel() instanceof ClientLevel level) {
|
||||
ILevelHelper.LevelHelper.CLIENT.setLevel(level);
|
||||
}
|
||||
}
|
||||
@SubscribeEvent
|
||||
public static void registerLayerDefinitions(LevelEvent.Unload event) {
|
||||
if (event.getLevel() != null && event.getLevel() instanceof ClientLevel level) {
|
||||
ILevelHelper.LevelHelper.CLIENT.setLevel(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -80,7 +80,6 @@ public class CommonEventHandler {
|
|||
public static SyncData2Manager getSyncData2Manager() {
|
||||
return syncData2Manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* On world load.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -1,5 +1,12 @@
|
|||
package top.r3944realms.lib39.core.event;
|
||||
|
||||
import net.minecraft.client.multiplayer.ClientLevel;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.event.level.LevelEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import top.r3944realms.lib39.Lib39;
|
||||
import top.r3944realms.lib39.util.ILevelHelper;
|
||||
|
||||
/**
|
||||
* The type Server handler.
|
||||
*/
|
||||
|
|
@ -12,5 +19,19 @@ public class ServerEventHandler {
|
|||
/**
|
||||
* The type Game.
|
||||
*/
|
||||
public static class Game extends ServerEventHandler {}
|
||||
@net.minecraftforge.fml.common.Mod.EventBusSubscriber(value = Dist.DEDICATED_SERVER, bus = net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus.MOD, modid = Lib39.MOD_ID)
|
||||
public static class Game extends ServerEventHandler {
|
||||
@SubscribeEvent
|
||||
public static void registerLayerDefinitions(LevelEvent.Load event) {
|
||||
if (event.getLevel() != null && event.getLevel() instanceof ClientLevel level) {
|
||||
ILevelHelper.LevelHelper.CLIENT.setLevel(level);
|
||||
}
|
||||
}
|
||||
@SubscribeEvent
|
||||
public static void registerLayerDefinitions(LevelEvent.Unload event) {
|
||||
if (event.getLevel() != null && event.getLevel() instanceof ClientLevel level) {
|
||||
ILevelHelper.LevelHelper.CLIENT.setLevel(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
32
src/main/java/top/r3944realms/lib39/util/ILevelHelper.java
Normal file
32
src/main/java/top/r3944realms/lib39/util/ILevelHelper.java
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
package top.r3944realms.lib39.util;
|
||||
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.LevelAccessor;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public interface ILevelHelper {
|
||||
Level getLevel();
|
||||
enum LevelHelper implements ILevelHelper {
|
||||
SERVER,
|
||||
CLIENT;
|
||||
Level level;
|
||||
@Override
|
||||
@Nullable
|
||||
public Level getLevel() {
|
||||
return level;
|
||||
}
|
||||
@ApiStatus.Internal
|
||||
public void setLevel(Level level) {
|
||||
this.level = level;
|
||||
}
|
||||
}
|
||||
@Nullable
|
||||
default Level getServerLevel() {
|
||||
return LevelHelper.SERVER.getServerLevel();
|
||||
}
|
||||
@Nullable
|
||||
default Level getClientLevel() {
|
||||
return LevelHelper.CLIENT.getClientLevel();
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user