New SleepFinishedTimeEvent allowing control of world time when waking up. (#6043)
This commit is contained in:
parent
ca28877fd5
commit
f9686cf098
3 changed files with 73 additions and 6 deletions
|
@ -73,15 +73,17 @@
|
|||
}
|
||||
|
||||
if (this.func_72912_H().func_76093_s() && this.func_175659_aa() != Difficulty.HARD) {
|
||||
@@ -280,7 +291,7 @@
|
||||
@@ -280,8 +291,8 @@
|
||||
})) {
|
||||
this.field_73068_P = false;
|
||||
if (this.func_82736_K().func_223586_b(GameRules.field_223607_j)) {
|
||||
- long l = this.field_72986_A.func_76073_f() + 24000L;
|
||||
- this.func_72877_b(l - l % 24000L);
|
||||
+ long l = this.func_72820_D() + 24000L;
|
||||
this.func_72877_b(l - l % 24000L);
|
||||
+ this.func_72877_b(net.minecraftforge.event.ForgeEventFactory.onSleepFinished(this, l - l % 24000L, this.func_72820_D()));
|
||||
}
|
||||
|
||||
this.field_217491_A.stream().filter(LivingEntity::func_70608_bn).forEach((p_217444_0_) -> {
|
||||
@@ -304,6 +315,7 @@
|
||||
|
||||
iprofiler.func_219895_b("portalForcer");
|
||||
|
|
|
@ -33,7 +33,6 @@ import net.minecraft.entity.MobEntity;
|
|||
import net.minecraft.entity.SpawnReason;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.EntityClassification;
|
||||
import net.minecraft.entity.merchant.IMerchant;
|
||||
import net.minecraft.entity.effect.LightningBoltEntity;
|
||||
import net.minecraft.entity.item.ItemEntity;
|
||||
import net.minecraft.entity.monster.ZombieEntity;
|
||||
|
@ -49,7 +48,6 @@ import net.minecraft.item.ItemStack;
|
|||
import net.minecraft.item.ItemUseContext;
|
||||
import net.minecraft.world.spawner.AbstractSpawner;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.DamageSource;
|
||||
import net.minecraft.util.ActionResultType;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.Hand;
|
||||
|
@ -70,8 +68,6 @@ import net.minecraft.world.World;
|
|||
import net.minecraft.world.server.ServerWorld;
|
||||
import net.minecraft.world.WorldSettings;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import net.minecraft.world.chunk.IChunk;
|
||||
import net.minecraft.world.gen.ChunkGenerator;
|
||||
import net.minecraft.world.storage.IPlayerFileData;
|
||||
import net.minecraft.world.storage.SaveHandler;
|
||||
import net.minecraft.world.storage.loot.LootTable;
|
||||
|
@ -128,6 +124,7 @@ import net.minecraftforge.event.world.ExplosionEvent;
|
|||
import net.minecraftforge.event.world.GetCollisionBoxesEvent;
|
||||
import net.minecraftforge.event.world.PistonEvent;
|
||||
import net.minecraftforge.event.world.SaplingGrowTreeEvent;
|
||||
import net.minecraftforge.event.world.SleepFinishedTimeEvent;
|
||||
import net.minecraftforge.event.world.WorldEvent;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import net.minecraftforge.eventbus.api.Event.Result;
|
||||
|
@ -699,4 +696,11 @@ public class ForgeEventFactory
|
|||
{
|
||||
return MinecraftForge.EVENT_BUS.post(new PistonEvent.Post(world, pos, direction, extending ? PistonEvent.PistonMoveType.EXTEND : PistonEvent.PistonMoveType.RETRACT));
|
||||
}
|
||||
|
||||
public static long onSleepFinished(ServerWorld world, long newTime, long minTime)
|
||||
{
|
||||
SleepFinishedTimeEvent event = new SleepFinishedTimeEvent(world, newTime, minTime);
|
||||
MinecraftForge.EVENT_BUS.post(event);
|
||||
return event.getNewTime();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
* Minecraft Forge
|
||||
* Copyright (c) 2016-2019.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation version 2.1
|
||||
* of the License.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package net.minecraftforge.event.world;
|
||||
|
||||
import net.minecraft.world.server.ServerWorld;
|
||||
|
||||
/**
|
||||
* This event is fired when all players are asleep and the time should be set to day.<br>
|
||||
*
|
||||
* setWakeUpTime(wakeUpTime) sets a new time that will be added to the dayTime.<br>
|
||||
*/
|
||||
public class SleepFinishedTimeEvent extends WorldEvent
|
||||
{
|
||||
private long newTime;
|
||||
private final long minTime;
|
||||
|
||||
public SleepFinishedTimeEvent(ServerWorld worldIn, long newTimeIn, long minTimeIn)
|
||||
{
|
||||
super(worldIn);
|
||||
this.newTime = newTimeIn;
|
||||
this.minTime = minTimeIn;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the new time
|
||||
*/
|
||||
public long getNewTime()
|
||||
{
|
||||
return newTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the new time which should be set when all players wake up
|
||||
* @param newTimeIn The new time at wakeup
|
||||
* @return {@code false} if newTimeIn was lower than current time
|
||||
*/
|
||||
public boolean setTimeAddition(long newTimeIn)
|
||||
{
|
||||
if (minTime > newTimeIn)
|
||||
return false;
|
||||
this.newTime = newTimeIn;
|
||||
return true;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue