add: progressive sleep
add: possibility on LongNightEvent
This commit is contained in:
8 files changed
+107
-6
No files matched your search
@@ -7,7 +7,11 @@ import net.minecraft.world.World;
|
||||
|
||||
public class SFRandomEventRegistry extends SimpleRandomEventRegistry {
|
||||
public SFRandomEventRegistry() {
|
||||
registerEvent(LongNightEvent::new, World.OVERWORLD, world -> !LongNightEvent.isRunning() && world.getTimeOfDay() % 18000 == 0); // At midnight
|
||||
registerEvent(DawnAfterLongNightEvent::new, World.OVERWORLD, world -> world.getTimeOfDay() % 22200 == 0); // At dawn
|
||||
registerEvent(LongNightEvent::new, World.OVERWORLD
|
||||
, world -> !LongNightEvent.isRunning()
|
||||
&& world.getTimeOfDay() % 24000 == 18000
|
||||
&& world.getRandom().nextBetween(0,100) < 15); // At midnight
|
||||
registerEvent(DawnAfterLongNightEvent::new, World.OVERWORLD
|
||||
, world -> world.getTimeOfDay() % 22200 == 0); // At dawn
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,7 @@ public class DawnAfterLongNightEvent extends RandomEvent {
|
||||
if (LongNightEvent.justExpirencedLongNight) {
|
||||
LongNightEvent.justExpirencedLongNight = false;
|
||||
world.getServer().getPlayerManager().broadcast(
|
||||
Text.literal("珍惜太阳正是永夜的意义。")
|
||||
Text.literal("\"月亮\"离开了。")
|
||||
.withColor(new Color(235, 91, 0).getRGB())
|
||||
.append(Text.literal("(永夜事件结束)").withColor(Colors.LIGHT_GRAY))
|
||||
, false);
|
||||
|
||||
@@ -3,6 +3,7 @@ package io.ib67.sfcraft.event.longnight;
|
||||
import io.ib67.sfcraft.SFCraft;
|
||||
import io.ib67.sfcraft.event.RandomEvent;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Colors;
|
||||
import net.minecraft.world.GameRules;
|
||||
@@ -18,8 +19,9 @@ public class LongNightEvent extends RandomEvent {
|
||||
|
||||
@Override
|
||||
public int start() {
|
||||
var pm = world.getServer().getPlayerManager();
|
||||
isAtLongNight = true;
|
||||
world.getServer().getPlayerManager().broadcast(Text.literal("月亮停滞在空中...").withColor(Colors.BLUE), false);
|
||||
pm.broadcast(Text.literal("月亮停滞在空中...").withColor(Colors.BLUE), false);
|
||||
this.doDaylightCycle = world.getGameRules().getBoolean(GameRules.DO_DAYLIGHT_CYCLE);
|
||||
this.doTraderSpawning = world.getGameRules().getBoolean(GameRules.DO_TRADER_SPAWNING);
|
||||
world.getGameRules().get(GameRules.DO_DAYLIGHT_CYCLE).set(false, world.getServer());
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
package io.ib67.sfcraft.mixin.server;
|
||||
|
||||
import io.ib67.sfcraft.mixin.server.bridge.ServerWorldBridge;
|
||||
import net.minecraft.block.AbstractFurnaceBlock;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.BlockWithEntity;
|
||||
import net.minecraft.block.entity.AbstractFurnaceBlockEntity;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.block.entity.BlockEntityTicker;
|
||||
import net.minecraft.block.entity.BlockEntityType;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.GameRules;
|
||||
import net.minecraft.world.World;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Overwrite;
|
||||
|
||||
@Mixin(AbstractFurnaceBlock.class)
|
||||
public abstract class AbstractFurnaceBlockMixin extends BlockWithEntity {
|
||||
protected AbstractFurnaceBlockMixin(Settings settings) {
|
||||
super(settings);
|
||||
}
|
||||
|
||||
/**
|
||||
* @author icybear
|
||||
* @reason to replace their ticker
|
||||
*/
|
||||
@Overwrite
|
||||
public static <T extends BlockEntity> @Nullable BlockEntityTicker<T> validateTicker(
|
||||
World world, BlockEntityType<T> givenType, BlockEntityType<? extends AbstractFurnaceBlockEntity> expectedType
|
||||
) {
|
||||
return world.isClient ? null : BlockWithEntity.validateTicker(givenType, expectedType, AbstractFurnaceBlockMixin::tickMultiple);
|
||||
}
|
||||
|
||||
private static void tickMultiple(World world, BlockPos pos, BlockState state, AbstractFurnaceBlockEntity blockEntity) {
|
||||
AbstractFurnaceBlockEntity.tick(world, pos, state, blockEntity);
|
||||
int i = world.getGameRules().getInt(GameRules.PLAYERS_SLEEPING_PERCENTAGE);
|
||||
if (((ServerWorldBridge) world).getSleepManager().canSkipNight(i)) {
|
||||
AbstractFurnaceBlockEntity.tick(world, pos, state, blockEntity); //todo: config support?
|
||||
AbstractFurnaceBlockEntity.tick(world, pos, state, blockEntity);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -22,7 +22,9 @@ public class PlayerEntityMixin {
|
||||
|
||||
@Inject(method = "trySleep", at = @At("HEAD"), cancellable = true)
|
||||
public void onSleep(BlockPos pos, CallbackInfoReturnable<Either<PlayerEntity.SleepFailureReason, Unit>> cir) {
|
||||
if (cir.isCancellable())
|
||||
cir.setReturnValue(SFCraft.getInstance().getListener().onPlayerSleep((ServerPlayerEntity) (Object) this, pos));
|
||||
var result = SFCraft.getInstance().getListener().onPlayerSleep((ServerPlayerEntity) (Object) this, pos);
|
||||
if(result.left().isPresent()){
|
||||
cir.setReturnValue(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package io.ib67.sfcraft.mixin.server;
|
||||
|
||||
import io.ib67.sfcraft.mixin.server.bridge.ServerWorldBridge;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.world.GameRules;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.*;
|
||||
|
||||
@Mixin(ServerWorld.class)
|
||||
public abstract class ServerWorldMixin {
|
||||
@ModifyArg(method = "tickTime", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/world/ServerWorld;setTimeOfDay(J)V"))
|
||||
public long setTimeOfDay(long timeOfDay) {
|
||||
int i = ((ServerWorld) (Object) this).getGameRules().getInt(GameRules.PLAYERS_SLEEPING_PERCENTAGE);
|
||||
if (((ServerWorldBridge) this).getSleepManager().canSkipNight(i)) {
|
||||
return timeOfDay + 10;
|
||||
}
|
||||
return timeOfDay;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package io.ib67.sfcraft.mixin.server;
|
||||
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.SleepManager;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mixin(SleepManager.class)
|
||||
public abstract class SleepManagerMixin {
|
||||
@Inject(method = "canResetTime", at = @At("HEAD"), cancellable = true)
|
||||
public void canResetTime(int percentage, List<ServerPlayerEntity> players, CallbackInfoReturnable<Boolean> cir) {
|
||||
if (players.isEmpty()) {
|
||||
cir.setReturnValue(false);
|
||||
return;
|
||||
}
|
||||
var world = players.get(0).getServerWorld();
|
||||
if (world.getTimeOfDay() % 24000 >= 12544) {
|
||||
if(!world.isRaining()){
|
||||
cir.setReturnValue(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,9 @@
|
||||
"client": [
|
||||
],
|
||||
"server": [
|
||||
"server.bridge.ServerWorldBridge",
|
||||
"server.SleepManagerMixin",
|
||||
"server.ServerWorldMixin",
|
||||
"server.AbstractFurnaceBlockMixin",
|
||||
"server.ServerHandshakeNetworkHandlerMixin",
|
||||
"server.LegacyQueryHandlerMixin",
|
||||
|
||||
Reference in new issue
Block a user