Skip to content

Commit

Permalink
Implement sleeping time tweak, closes #241
Browse files Browse the repository at this point in the history
  • Loading branch information
ACGaming committed Jul 22, 2023
1 parent 83dc6d6 commit dafd2c3
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 9 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
![Available for MC 1.12.2](https://img.shields.io/badge/Available%20for-MC%201.12.2-3498db.svg?labelColor=34495e&style=for-the-badge)
![License LGPL-3.0](https://img.shields.io/github/license/ACGaming/UniversalTweaks?labelColor=34495e&color=3498db&style=for-the-badge)
[![Stars](https://img.shields.io/github/stars/ACGaming/UniversalTweaks?labelColor=34495e&color=3498db&style=for-the-badge)](https://github.com/ACGaming/UniversalTweaks/stargazers)
[![Superseded Mods](https://img.shields.io/badge/Superseded%20Mods-84-3498db.svg?labelColor=34495e&style=for-the-badge)](https://legacy.curseforge.com/minecraft/mc-mods/universal-tweaks/relations/dependencies?filter-related-dependencies=5)
[![Superseded Mods](https://img.shields.io/badge/Superseded%20Mods-89-3498db.svg?labelColor=34495e&style=for-the-badge)](https://legacy.curseforge.com/minecraft/mc-mods/universal-tweaks/relations/dependencies?filter-related-dependencies=5)

# UNIVERSAL TWEAKS

Expand Down Expand Up @@ -49,7 +49,7 @@ All changes are toggleable via the config file.
* **Help:** Replaces the help command, sorts and reports broken commands
* **Hopper Bounding Box:** Slims down the hopper bounding box for easier access of nearby blocks
* **Hopper Insert Safety Check:** Prevents crashes when the destination tile entity becomes unavailable during the item insert process
* **Horse Falling:** Modifies falling logic of horse, listening to LivingFallEvent and taking jump boost into account
* **Horse Falling:** Modifies falling logic of horses, listening to LivingFallEvent and taking jump boost into account
* **Item Frame Void:** Prevents voiding held items when right + left-clicking on an item frame simultaneously
* **Ladder Flying Slowdown:** Disables climbing movement when flying
* **Locale:** Prevents various crashes with Turkish locale
Expand Down Expand Up @@ -157,6 +157,7 @@ All changes are toggleable via the config file.
* **Shield Parry:** Allows parrying of projectiles with shields
* **Skip Credits:** Skips the credits screen after the player goes through the end podium portal
* **Skip Missing Registry Entries Screen:** Automatically confirms the 'Missing Registry Entries' screen on world load
* **Sleeping Time:** Determines at which time of day sleeping is allowed in ticks (0 - 24000)
* **Smooth Scrolling:** Adds smooth scrolling to every in-game list
* **Spawn Caps:** Sets maximum spawning limits for different entity types
* **Super Hot Torch:** Enables one-time ignition of entities by hitting them with a torch
Expand Down
24 changes: 20 additions & 4 deletions src/main/java/mod/acgaming/universaltweaks/config/UTConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,10 @@ public static class TweaksEntitiesCategory
@Config.Name("Rally Health")
public final RallyHealthCategory RALLY_HEALTH = new RallyHealthCategory();

@Config.LangKey("cfg.universaltweaks.tweaks.entities.sleeping")
@Config.Name("Sleeping")
public final SleepingCategory SLEEPING = new SleepingCategory();

@Config.LangKey("cfg.universaltweaks.tweaks.entities.spawncaps")
@Config.Name("Spawn Caps")
public final SpawnCapsCategory SPAWN_CAPS = new SpawnCapsCategory();
Expand Down Expand Up @@ -657,10 +661,6 @@ public static class TweaksEntitiesCategory
@Config.Comment("Disables creepers dropping music discs when slain by skeletons")
public boolean utCreeperMusicDiscsToggle = false;

@Config.Name("Disable Sleeping")
@Config.Comment("Disables skipping night by using a bed while making it still able to set spawn")
public boolean utSleepingToggle = false;

@Config.RequiresMcRestart
@Config.Name("Disable Wither Targeting AI")
@Config.Comment("Disables withers targeting animals")
Expand Down Expand Up @@ -914,6 +914,22 @@ public static class RallyHealthCategory
public boolean utRallyHealthSound = false;
}

public static class SleepingCategory
{
@Config.Name("Disable Sleeping")
@Config.Comment("Disables skipping night by using a bed while making it still able to set spawn")
public boolean utDisableSleepingToggle = false;

@Config.Name("Sleeping Time")
@Config.RangeInt(min = -1, max = 23999)
@Config.Comment
({
"Determines at which time of day sleeping is allowed in ticks (0 - 23999)",
"-1 for vanilla default"
})
public int utSleepingTime = -1;
}

public static class SpawnCapsCategory
{
@Config.RequiresMcRestart
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraftforge.event.entity.player.PlayerSleepInBedEvent;
import net.minecraftforge.event.entity.player.SleepingTimeCheckEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.eventhandler.Event;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

import mod.acgaming.universaltweaks.UniversalTweaks;
Expand All @@ -18,9 +20,9 @@
public class UTSleeping
{
@SubscribeEvent
public static void utSleeping(PlayerSleepInBedEvent event)
public static void utDisableSleeping(PlayerSleepInBedEvent event)
{
if (!UTConfig.TWEAKS_ENTITIES.utSleepingToggle || (event.getEntityPlayer()).world.isRemote) return;
if (!UTConfig.TWEAKS_ENTITIES.SLEEPING.utDisableSleepingToggle || (event.getEntityPlayer()).world.isRemote) return;
if (event.getEntityPlayer().isPlayerSleeping() || !event.getEntityPlayer().isEntityAlive()) return;
if (!(event.getEntityPlayer()).world.provider.canRespawnHere() || (event.getEntityPlayer()).world.isDaytime())
{
Expand All @@ -30,10 +32,19 @@ public static void utSleeping(PlayerSleepInBedEvent event)
double yOff = 5.0D;
List<?> list = (event.getEntityPlayer()).world.getEntitiesWithinAABB(EntityMob.class, new AxisAlignedBB(event.getPos().getX() - xOff, event.getPos().getY() - yOff, event.getPos().getZ() - xOff, event.getPos().getX() + xOff, event.getPos().getY() + yOff, event.getPos().getZ() + xOff));
if (!list.isEmpty()) return;
if (UTConfig.DEBUG.utDebugToggle) UniversalTweaks.LOGGER.debug("UTSleeping ::: Player sleep in bed event");
if (UTConfig.DEBUG.utDebugToggle) UniversalTweaks.LOGGER.debug("UTDisableSleeping ::: Player sleep in bed event");
event.setResult(EntityPlayer.SleepResult.OTHER_PROBLEM);
if (event.getEntityPlayer().isRiding()) event.getEntityPlayer().dismountRidingEntity();
event.getEntityPlayer().setSpawnChunk(event.getPos(), false, (event.getEntityPlayer()).dimension);
event.getEntityPlayer().sendStatusMessage(new TextComponentTranslation("msg.universaltweaks.sleep.spawnpoint"), true);
}

@SubscribeEvent
public static void utSleepingTime(SleepingTimeCheckEvent event)
{
if (UTConfig.TWEAKS_ENTITIES.SLEEPING.utSleepingTime < 0) return;
if (UTConfig.DEBUG.utDebugToggle) UniversalTweaks.LOGGER.debug("UTSleepingTime ::: Sleeping time check event");
if (event.getEntityPlayer().getEntityWorld().getWorldTime() >= UTConfig.TWEAKS_ENTITIES.SLEEPING.utSleepingTime) event.setResult(Event.Result.ALLOW);
else event.setResult(Event.Result.DENY);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public static List<String> obsoleteModsMessage()
if (Loader.isModLoaded("attributefix") && UTConfig.TWEAKS_ENTITIES.ATTRIBUTES.utAttributesToggle) messages.add("AttributeFix");
if (Loader.isModLoaded("bannerpatch") && UTConfig.BUGFIXES_BLOCKS.utBannerBoundingBoxToggle) messages.add("BannerPatch");
if (Loader.isModLoaded("bedbreakbegone") && UTConfig.TWEAKS_BLOCKS.utBedObstructionToggle) messages.add("BedBreakBegone");
if (Loader.isModLoaded("bedfix") && UTConfig.TWEAKS_ENTITIES.SLEEPING.utSleepingTime != -1) messages.add("BedFix");
if (Loader.isModLoaded("bedsaynosleep") && UTConfig.TWEAKS_ENTITIES.SLEEPING.utDisableSleepingToggle) messages.add("Sleepn't");
if (Loader.isModLoaded("betterburning") && (UTConfig.TWEAKS_ENTITIES.BETTER_BURNING.utBBArrowsToggle || UTConfig.TWEAKS_ENTITIES.BETTER_BURNING.utBBCookedToggle || UTConfig.TWEAKS_ENTITIES.BETTER_BURNING.utBBExtinguishToggle || UTConfig.TWEAKS_ENTITIES.BETTER_BURNING.utBBOverlayToggle || UTConfig.TWEAKS_ENTITIES.BETTER_BURNING.utBBSpreadingToggle)) messages.add("Better Burning");
if (Loader.isModLoaded("betterplacement") && UTConfig.TWEAKS_BLOCKS.BETTER_PLACEMENT.utBetterPlacementToggle) messages.add("Better Placement");
if (Loader.isModLoaded("biggerpacketsplz") && UTConfig.BUGFIXES_MISC.utPacketSize > 0x200000) messages.add("Bigger Packets Please");
Expand Down Expand Up @@ -64,6 +66,7 @@ public static List<String> obsoleteModsMessage()
if (Loader.isModLoaded("horsefallfix") && UTConfig.BUGFIXES_ENTITIES.utHorseFallingToggle) messages.add("HorseFallFix");
if (Loader.isModLoaded("horsestandstill") && UTConfig.TWEAKS_ENTITIES.utSaddledWanderingToggle) messages.add("Stupid Horse Stand Still");
if (Loader.isModLoaded("ikwid") && UTConfig.TWEAKS_MISC.TOAST_CONTROL.utToastControlTutorialToggle) messages.add("I Know What I'm Doing");
if (Loader.isModLoaded("insomniac") && UTConfig.TWEAKS_ENTITIES.SLEEPING.utDisableSleepingToggle) messages.add("Insomniac");
if (Loader.isModLoaded("inventoryspam") && UTConfig.TWEAKS_MISC.PICKUP_NOTIFICATION.utPickupNotificationToggle) messages.add("Inventory Spam");
if (Loader.isModLoaded("leafdecay") && UTConfig.TWEAKS_BLOCKS.utLeafDecayToggle) messages.add("Leaf Decay Accelerator");
if (Loader.isModLoaded("letmedespawn") && UTConfig.TWEAKS_ENTITIES.utMobDespawnToggle) messages.add("Let Me Despawn");
Expand All @@ -76,6 +79,7 @@ public static List<String> obsoleteModsMessage()
if (Loader.isModLoaded("nanfix") && UTConfig.BUGFIXES_ENTITIES.utEntityNaNToggle) messages.add("NaN Entity Health Fix");
if (Loader.isModLoaded("nanpolice") && UTConfig.BUGFIXES_ENTITIES.utEntityNaNToggle) messages.add("NaNPolice");
if (Loader.isModLoaded("nobounce") && UTConfig.MOD_INTEGRATION.THAUMCRAFT.utTCStableThaumometerToggle) messages.add("Stable Thaumometer");
if (Loader.isModLoaded("nodoze") && UTConfig.TWEAKS_ENTITIES.SLEEPING.utDisableSleepingToggle) messages.add("No Doze");
if (Loader.isModLoaded("nonvflash") && UTConfig.TWEAKS_MISC.utNightVisionFlashToggle) messages.add("No Night Vision Flashing");
if (Loader.isModLoaded("nopotionshift") && UTConfig.TWEAKS_MISC.utPotionShiftToggle) messages.add("No Potion Shift");
if (Loader.isModLoaded("noprecipebook") && UTConfig.TWEAKS_MISC.utRecipeBookToggle) messages.add("Nop Recipe Book");
Expand All @@ -90,6 +94,7 @@ public static List<String> obsoleteModsMessage()
if (Loader.isModLoaded("rallyhealth") && UTConfig.TWEAKS_ENTITIES.RALLY_HEALTH.utRallyHealthToggle) messages.add("Rally Health");
if (Loader.isModLoaded("salwayseat") && UTConfig.TWEAKS_ITEMS.utAlwaysEatToggle) messages.add("AlwaysEat");
if (Loader.isModLoaded("savemystronghold") && UTConfig.TWEAKS_WORLD.utStrongholdToggle) messages.add("Save My Stronghold!");
if (Loader.isModLoaded("sleepsooner") && UTConfig.TWEAKS_ENTITIES.SLEEPING.utSleepingTime != -1) messages.add("Sleep Sooner");
if (Loader.isModLoaded("smooth-scrolling-everywhere") && UTConfig.TWEAKS_MISC.SMOOTH_SCROLLING.utSmoothScrollingToggle) messages.add("Smooth Scrolling Everywhere");
if (Loader.isModLoaded("stepupfix") && UTConfig.TWEAKS_ENTITIES.utAutoJumpToggle) messages.add("StepupFixer");
if (Loader.isModLoaded("stg") && UTConfig.TWEAKS_MISC.SWING_THROUGH_GRASS.utSwingThroughGrassToggle) messages.add("SwingThroughGrass");
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/assets/universaltweaks/lang/en_us.lang
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ cfg.universaltweaks.tweaks.entities.easybreeding=Easy Breeding
cfg.universaltweaks.tweaks.entities.nogolems=No Golems
cfg.universaltweaks.tweaks.entities.playerspeed=Player Speed
cfg.universaltweaks.tweaks.entities.rallyhealth=Rally Health
cfg.universaltweaks.tweaks.entities.sleeping=Sleeping
cfg.universaltweaks.tweaks.entities.spawncaps=Spawn Caps
cfg.universaltweaks.tweaks.entities.undeadhorses=Undead Horses
cfg.universaltweaks.tweaks.entities.waterfalldamage=Water Fall Damage
Expand Down

0 comments on commit dafd2c3

Please sign in to comment.