mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-18 19:39:22 +00:00
New SleepFinishedTimeEvent allowing control of world time when waking up. (#6043)
This commit is contained in:
1 parent
ca28877fd5
commit
f9686cf098
3 files changed
+73
-6
No files matched your search
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user