Le mods est fonctionnel en 1.20.1 sur Forge
This commit is contained in:
@@ -0,0 +1,59 @@
|
|||||||
|
{
|
||||||
|
"mod_elements": [
|
||||||
|
{
|
||||||
|
"name": "DoMobSpawningAtNight",
|
||||||
|
"type": "gamerule",
|
||||||
|
"compiles": true,
|
||||||
|
"locked_code": false,
|
||||||
|
"registry_name": "do_mob_spawning_at_night",
|
||||||
|
"metadata": {
|
||||||
|
"files": [],
|
||||||
|
"type": "logic"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "SurfaceSpawnController",
|
||||||
|
"type": "code",
|
||||||
|
"compiles": true,
|
||||||
|
"locked_code": true,
|
||||||
|
"registry_name": "surface_spawn_controller",
|
||||||
|
"metadata": {
|
||||||
|
"files": [
|
||||||
|
"src/main/java/net/mcreator/domobspawningatnight/SurfaceSpawnController.java"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"variable_elements": [],
|
||||||
|
"sound_elements": [],
|
||||||
|
"tag_elements": {},
|
||||||
|
"tab_element_order": {},
|
||||||
|
"language_map": {
|
||||||
|
"en_us": {
|
||||||
|
"gamerule.doMobSpawningAtNight.description": "Reduit fortement le spawn de mobs la nuit tombés ",
|
||||||
|
"gamerule.doMobSpawningAtNight": "doReduceMobSpawningAtNight"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"foldersRoot": {
|
||||||
|
"name": "~",
|
||||||
|
"children": []
|
||||||
|
},
|
||||||
|
"workspaceSettings": {
|
||||||
|
"modid": "domobspawningatnight",
|
||||||
|
"modName": "do Mob Spawning At Night",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "Empeche les mobs de spawn a la surface via une gamerule est activé de base",
|
||||||
|
"author": "felden.r, MCreator",
|
||||||
|
"websiteURL": "https://mcreator.net",
|
||||||
|
"license": "Not specified",
|
||||||
|
"serverSideOnly": false,
|
||||||
|
"requiredMods": [],
|
||||||
|
"dependencies": [],
|
||||||
|
"dependants": [],
|
||||||
|
"mcreatorDependencies": [],
|
||||||
|
"currentGenerator": "forge-1.20.1",
|
||||||
|
"credits": "Libre de modification",
|
||||||
|
"modElementsPackage": "net.mcreator.domobspawningatnight"
|
||||||
|
},
|
||||||
|
"mcreatorVersion": 202400452410
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"_fv": 73,
|
||||||
|
"_type": "gamerule",
|
||||||
|
"definition": {
|
||||||
|
"type": "Logic",
|
||||||
|
"displayName": "doReduceMobSpawningAtNight",
|
||||||
|
"description": "Reduit fortement le spawn de mobs la nuit tombés ",
|
||||||
|
"category": "MOBS",
|
||||||
|
"defaultValueLogic": true,
|
||||||
|
"defaultValueNumber": 0
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
org.gradle.jvmargs=-Xmx3G
|
||||||
|
org.gradle.daemon=false
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
pluginManagement {
|
||||||
|
repositories {
|
||||||
|
gradlePluginPortal()
|
||||||
|
maven {
|
||||||
|
name = 'MinecraftForge'
|
||||||
|
url = 'https://maven.minecraftforge.net/'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
plugins {
|
||||||
|
id 'org.gradle.toolchains.foojay-resolver-convention' version '0.7.0'
|
||||||
|
}
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
package net.mcreator.domobspawningatnight;
|
||||||
|
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
|
||||||
|
import net.minecraftforge.network.simple.SimpleChannel;
|
||||||
|
import net.minecraftforge.network.NetworkRegistry;
|
||||||
|
import net.minecraftforge.network.NetworkEvent;
|
||||||
|
import net.minecraftforge.fml.util.thread.SidedThreadGroups;
|
||||||
|
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||||
|
import net.minecraftforge.fml.common.Mod;
|
||||||
|
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||||
|
import net.minecraftforge.eventbus.api.IEventBus;
|
||||||
|
import net.minecraftforge.event.TickEvent;
|
||||||
|
import net.minecraftforge.common.MinecraftForge;
|
||||||
|
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
|
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
import java.util.function.Function;
|
||||||
|
import java.util.function.BiConsumer;
|
||||||
|
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.AbstractMap;
|
||||||
|
|
||||||
|
@Mod("domobspawningatnight")
|
||||||
|
public class DomobspawningatnightMod {
|
||||||
|
public static final Logger LOGGER = LogManager.getLogger(DomobspawningatnightMod.class);
|
||||||
|
public static final String MODID = "domobspawningatnight";
|
||||||
|
|
||||||
|
public DomobspawningatnightMod() {
|
||||||
|
// Start of user code block mod constructor
|
||||||
|
// End of user code block mod constructor
|
||||||
|
MinecraftForge.EVENT_BUS.register(this);
|
||||||
|
IEventBus bus = FMLJavaModLoadingContext.get().getModEventBus();
|
||||||
|
|
||||||
|
// Start of user code block mod init
|
||||||
|
// End of user code block mod init
|
||||||
|
}
|
||||||
|
|
||||||
|
// Start of user code block mod methods
|
||||||
|
// End of user code block mod methods
|
||||||
|
private static final String PROTOCOL_VERSION = "1";
|
||||||
|
public static final SimpleChannel PACKET_HANDLER = NetworkRegistry.newSimpleChannel(new ResourceLocation(MODID, MODID), () -> PROTOCOL_VERSION, PROTOCOL_VERSION::equals, PROTOCOL_VERSION::equals);
|
||||||
|
private static int messageID = 0;
|
||||||
|
|
||||||
|
public static <T> void addNetworkMessage(Class<T> messageType, BiConsumer<T, FriendlyByteBuf> encoder, Function<FriendlyByteBuf, T> decoder, BiConsumer<T, Supplier<NetworkEvent.Context>> messageConsumer) {
|
||||||
|
PACKET_HANDLER.registerMessage(messageID, messageType, encoder, decoder, messageConsumer);
|
||||||
|
messageID++;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final Collection<AbstractMap.SimpleEntry<Runnable, Integer>> workQueue = new ConcurrentLinkedQueue<>();
|
||||||
|
|
||||||
|
public static void queueServerWork(int tick, Runnable action) {
|
||||||
|
if (Thread.currentThread().getThreadGroup() == SidedThreadGroups.SERVER)
|
||||||
|
workQueue.add(new AbstractMap.SimpleEntry<>(action, tick));
|
||||||
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public void tick(TickEvent.ServerTickEvent event) {
|
||||||
|
if (event.phase == TickEvent.Phase.END) {
|
||||||
|
List<AbstractMap.SimpleEntry<Runnable, Integer>> actions = new ArrayList<>();
|
||||||
|
workQueue.forEach(work -> {
|
||||||
|
work.setValue(work.getValue() - 1);
|
||||||
|
if (work.getValue() == 0)
|
||||||
|
actions.add(work);
|
||||||
|
});
|
||||||
|
actions.forEach(e -> e.getKey().run());
|
||||||
|
workQueue.removeAll(actions);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,119 @@
|
|||||||
|
package net.mcreator.domobspawningatnight.core;
|
||||||
|
|
||||||
|
import net.mcreator.domobspawningatnight.init.DomobspawningatnightModGameRules;
|
||||||
|
import net.minecraft.ChatFormatting;
|
||||||
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.network.chat.Component;
|
||||||
|
import net.minecraft.server.MinecraftServer;
|
||||||
|
import net.minecraft.server.level.ServerLevel;
|
||||||
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
|
import net.minecraft.world.entity.Mob;
|
||||||
|
import net.minecraft.world.entity.MobCategory;
|
||||||
|
import net.minecraft.world.entity.MobSpawnType;
|
||||||
|
import net.minecraft.world.level.LightLayer;
|
||||||
|
import net.minecraftforge.event.TickEvent;
|
||||||
|
import net.minecraftforge.event.entity.living.MobSpawnEvent;
|
||||||
|
import net.minecraftforge.eventbus.api.Event.Result;
|
||||||
|
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||||
|
import net.minecraftforge.fml.common.Mod;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Mod.EventBusSubscriber
|
||||||
|
public class SurfaceSpawnController {
|
||||||
|
|
||||||
|
private static final Map<ServerLevel, Integer> MOON_PHASE_TRACKER = new HashMap<>();
|
||||||
|
private static final int MOON_CHECK_INTERVAL = 200; // Toutes les 10 secondes
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public static void onMobSpawnCheck(MobSpawnEvent.PositionCheck event) {
|
||||||
|
if (!(event.getLevel() instanceof ServerLevel level)) return;
|
||||||
|
if (!(event.getEntity() instanceof Mob)) return;
|
||||||
|
Mob mob = (Mob) event.getEntity();
|
||||||
|
|
||||||
|
if (!level.getGameRules().getBoolean(DomobspawningatnightModGameRules.DO_MOB_SPAWNING_AT_NIGHT)) return;
|
||||||
|
|
||||||
|
BlockPos spawnPos = mob.blockPosition();
|
||||||
|
SpawnContext context = new SpawnContext(
|
||||||
|
level.getDayTime() % 24000,
|
||||||
|
level.getMoonPhase(),
|
||||||
|
spawnPos,
|
||||||
|
level.getSeaLevel(),
|
||||||
|
level.canSeeSky(spawnPos),
|
||||||
|
level.getBrightness(LightLayer.SKY, spawnPos)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (isValidHostileSpawn(mob, event.getSpawnType()) && shouldBlockSpawn(context)) {
|
||||||
|
event.setResult(Result.DENY);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public static void onServerTick(TickEvent.ServerTickEvent event) {
|
||||||
|
if (event.phase == TickEvent.Phase.END && event.getServer().getTickCount() % MOON_CHECK_INTERVAL == 0) {
|
||||||
|
checkFullMoonTransition(event.getServer());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void checkFullMoonTransition(MinecraftServer server) {
|
||||||
|
for (ServerLevel level : server.getAllLevels()) {
|
||||||
|
int currentPhase = level.getMoonPhase();
|
||||||
|
Integer lastPhase = MOON_PHASE_TRACKER.get(level);
|
||||||
|
|
||||||
|
if (lastPhase == null || currentPhase != lastPhase) {
|
||||||
|
handleMoonPhaseChange(level, currentPhase, lastPhase);
|
||||||
|
MOON_PHASE_TRACKER.put(level, currentPhase);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void handleMoonPhaseChange(ServerLevel level, int newPhase, Integer oldPhase) {
|
||||||
|
if (newPhase == 0 && (oldPhase == null || oldPhase != 0)) {
|
||||||
|
broadcastFullMoonWarning(level.getServer());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void broadcastFullMoonWarning(MinecraftServer server) {
|
||||||
|
Component warning = Component.literal("The full moon is shining! Hostile creatures roam free!")
|
||||||
|
.withStyle(ChatFormatting.DARK_RED, ChatFormatting.ITALIC);
|
||||||
|
|
||||||
|
for (ServerPlayer player : server.getPlayerList().getPlayers()) {
|
||||||
|
player.sendSystemMessage(warning, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isValidHostileSpawn(Mob mob, MobSpawnType spawnType) {
|
||||||
|
return mob.getType().getCategory() == MobCategory.MONSTER &&
|
||||||
|
spawnType == MobSpawnType.NATURAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean shouldBlockSpawn(SpawnContext context) {
|
||||||
|
return isNightTime(context.time) &&
|
||||||
|
isExposedSurface(context) &&
|
||||||
|
!isFullMoon(context.moonPhase);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isNightTime(long worldTime) {
|
||||||
|
return worldTime >= 13000 && worldTime < 23000;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isFullMoon(int moonPhase) {
|
||||||
|
return moonPhase == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isExposedSurface(SpawnContext context) {
|
||||||
|
return context.hasSkyAccess &&
|
||||||
|
context.position.getY() >= context.seaLevel &&
|
||||||
|
context.skyLight >= 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
private record SpawnContext(
|
||||||
|
long time,
|
||||||
|
int moonPhase,
|
||||||
|
BlockPos position,
|
||||||
|
int seaLevel,
|
||||||
|
boolean hasSkyAccess,
|
||||||
|
int skyLight
|
||||||
|
) {}
|
||||||
|
}
|
||||||
+14
@@ -0,0 +1,14 @@
|
|||||||
|
|
||||||
|
/*
|
||||||
|
* MCreator note: This file will be REGENERATED on each build.
|
||||||
|
*/
|
||||||
|
package net.mcreator.domobspawningatnight.init;
|
||||||
|
|
||||||
|
import net.minecraftforge.fml.common.Mod;
|
||||||
|
|
||||||
|
import net.minecraft.world.level.GameRules;
|
||||||
|
|
||||||
|
@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD)
|
||||||
|
public class DomobspawningatnightModGameRules {
|
||||||
|
public static final GameRules.Key<GameRules.BooleanValue> DO_MOB_SPAWNING_AT_NIGHT = GameRules.register("doMobSpawningAtNight", GameRules.Category.MOBS, GameRules.BooleanValue.create(true));
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
modLoader="javafml"
|
||||||
|
loaderVersion="[47,)"
|
||||||
|
license="Not specified"
|
||||||
|
|
||||||
|
[[mods]]
|
||||||
|
modId="domobspawningatnight"
|
||||||
|
version="1.0.0"
|
||||||
|
displayName="do Mob Spawning At Night"
|
||||||
|
displayURL="https://mcreator.net"
|
||||||
|
credits="Libre de modification"
|
||||||
|
authors="felden.r, MCreator"
|
||||||
|
description="Empeche les mobs de spawn a la surface via une gamerule est activ\u00E9 de base"
|
||||||
|
|
||||||
|
# Start of user code block mod configuration
|
||||||
|
# End of user code block mod configuration
|
||||||
|
|
||||||
|
[[dependencies.domobspawningatnight]]
|
||||||
|
modId="minecraft"
|
||||||
|
mandatory=true
|
||||||
|
versionRange="[1.20.1]"
|
||||||
|
ordering="AFTER"
|
||||||
|
side="BOTH"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Start of user code block dependencies configuration
|
||||||
|
# End of user code block dependencies configuration
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"gamerule.doMobSpawningAtNight.description": "Reduit fortement le spawn de mobs la nuit tombés ",
|
||||||
|
"gamerule.doMobSpawningAtNight": "doReduceMobSpawningAtNight"
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"pack": {
|
||||||
|
"pack_format": 15,
|
||||||
|
"description": "Empeche les mobs de spawn a la surface via une gamerule est activé de base"
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user