forked from KryptonCaptain/Et-Futurum
-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #537 from Yoghurt4C/webpadorupadorupadoru-1
- Loading branch information
Showing
8 changed files
with
134 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
src/main/java/ganymedes01/etfuturum/gamerule/PlayersSleepingPercentage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package ganymedes01.etfuturum.gamerule; | ||
|
||
import net.minecraft.entity.player.EntityPlayer; | ||
import net.minecraft.world.World; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class PlayersSleepingPercentage { | ||
public static final PlayersSleepingPercentage INSTANCE = new PlayersSleepingPercentage(); | ||
public static final String GAMERULE_NAME = "playersSleepingPercentage"; | ||
public static final String DEFAULT_VALUE = "100"; | ||
|
||
public int percentrillo = 100; | ||
public List<EntityPlayer> sleepyPlayers = new ArrayList<>(); | ||
|
||
public static void registerGamerule(World world) { | ||
if (!world.isRemote && !world.getGameRules().hasRule(GAMERULE_NAME)) { | ||
world.getGameRules().addGameRule(GAMERULE_NAME, DEFAULT_VALUE); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
...n/java/ganymedes01/etfuturum/mixins/early/playerssleepingpercentage/MixinWorldServer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package ganymedes01.etfuturum.mixins.early.playerssleepingpercentage; | ||
|
||
import ganymedes01.etfuturum.core.utils.Utils; | ||
import net.minecraft.entity.player.EntityPlayer; | ||
import net.minecraft.profiler.Profiler; | ||
import net.minecraft.util.ChatComponentTranslation; | ||
import net.minecraft.world.World; | ||
import net.minecraft.world.WorldProvider; | ||
import net.minecraft.world.WorldServer; | ||
import net.minecraft.world.WorldSettings; | ||
import net.minecraft.world.storage.ISaveHandler; | ||
import org.objectweb.asm.Opcodes; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.Redirect; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
import org.spongepowered.asm.mixin.injection.callback.LocalCapture; | ||
|
||
import java.util.Iterator; | ||
import java.util.List; | ||
|
||
import static ganymedes01.etfuturum.gamerule.PlayersSleepingPercentage.GAMERULE_NAME; | ||
import static ganymedes01.etfuturum.gamerule.PlayersSleepingPercentage.INSTANCE; | ||
|
||
@Mixin(WorldServer.class) | ||
public abstract class MixinWorldServer extends World { | ||
@Shadow | ||
private boolean allPlayersSleeping; | ||
|
||
public MixinWorldServer(ISaveHandler p_i45368_1_, String p_i45368_2_, WorldProvider p_i45368_3_, WorldSettings p_i45368_4_, Profiler p_i45368_5_) { | ||
super(p_i45368_1_, p_i45368_2_, p_i45368_3_, p_i45368_4_, p_i45368_5_); | ||
throw new ArithmeticException("2 + 2 = 5 ???"); | ||
} | ||
|
||
@Inject(method = "updateAllPlayersSleepingFlag", at = @At("HEAD"), cancellable = true) | ||
public void hhheheheheeh(CallbackInfo ctx) { | ||
INSTANCE.percentrillo = Integer.parseInt(this.getGameRules().getGameRuleStringValue(GAMERULE_NAME)); | ||
if (INSTANCE.percentrillo > 100) { | ||
this.allPlayersSleeping = false; | ||
ctx.cancel(/* /r/nosleep, vanilla behaviour */); | ||
} else if (INSTANCE.percentrillo < 100) { | ||
INSTANCE.sleepyPlayers.clear(); | ||
List<EntityPlayer> real = Utils.getListWithoutSpectators(this.playerEntities); | ||
int cap = (int) Math.ceil(real.size() * INSTANCE.percentrillo * 0.01f); | ||
for (EntityPlayer player : this.playerEntities) { | ||
if (player.isPlayerSleeping()) { | ||
INSTANCE.sleepyPlayers.add(player); | ||
if (INSTANCE.sleepyPlayers.size() >= cap) { | ||
this.allPlayersSleeping = true; | ||
break; | ||
} | ||
} | ||
} | ||
|
||
if (!INSTANCE.sleepyPlayers.isEmpty() && cap > 0) { | ||
for (EntityPlayer paypiggy : this.playerEntities) { | ||
paypiggy.addChatMessage(new ChatComponentTranslation("sleep.players_sleeping", INSTANCE.sleepyPlayers.size(), cap)); | ||
} | ||
} | ||
ctx.cancel(); | ||
} | ||
} | ||
|
||
@Redirect(method = "areAllPlayersAsleep", at = @At(value = "FIELD", target = "Lnet/minecraft/world/WorldServer;playerEntities:Ljava/util/List;", opcode = Opcodes.GETFIELD)) | ||
public List<EntityPlayer> baited(WorldServer instance) { | ||
return INSTANCE.sleepyPlayers; | ||
} | ||
|
||
@Inject(method = "areAllPlayersAsleep", at = @At(value = "INVOKE", target = "Ljava/util/List;iterator()Ljava/util/Iterator;"), cancellable = true) | ||
public void turbofast(CallbackInfoReturnable<Boolean> ctx) { | ||
if (INSTANCE.percentrillo < 1) ctx.setReturnValue(true); | ||
} | ||
|
||
@Inject(method = "wakeAllPlayers", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/EntityPlayer;wakeUpPlayer(ZZZ)V"), locals = LocalCapture.CAPTURE_FAILHARD) | ||
public void broadcast(CallbackInfo ctx, Iterator iterator, EntityPlayer player) { | ||
if (INSTANCE.percentrillo > 0 && INSTANCE.percentrillo < 101) { | ||
player.addChatMessage(new ChatComponentTranslation("sleep.skipping_night")); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters