Better sleep conversion process
This commit is contained in:
parent
c9d3212a82
commit
9e1650c70d
@ -185,12 +185,14 @@ public class AndroidCapability implements ICapabilityProvider, IAndroidCapabilit
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
|
@SuppressWarnings("unused")
|
||||||
public static void onLivingTick(LivingEvent.LivingUpdateEvent event) {
|
public static void onLivingTick(LivingEvent.LivingUpdateEvent event) {
|
||||||
var ent = event.getEntity();
|
var ent = event.getEntity();
|
||||||
ent.getCapability(MatteryCapability.ANDROID).ifPresent(ent.level.isClientSide ? IAndroidCapability::tickClient : IAndroidCapability::tick);
|
ent.getCapability(MatteryCapability.ANDROID).ifPresent(ent.level.isClientSide ? IAndroidCapability::tickClient : IAndroidCapability::tick);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeEvent(priority = EventPriority.LOWEST)
|
@SubscribeEvent(priority = EventPriority.LOWEST)
|
||||||
|
@SuppressWarnings("unused")
|
||||||
public static void onHurtEvent(LivingHurtEvent event) {
|
public static void onHurtEvent(LivingHurtEvent event) {
|
||||||
if (event.isCanceled())
|
if (event.isCanceled())
|
||||||
return;
|
return;
|
||||||
|
@ -249,7 +249,21 @@ public class AndroidCapabilityPlayer extends AndroidCapability {
|
|||||||
|
|
||||||
public static final BigDecimal ENERGY_FOR_HUNGER_POINT = new BigDecimal(1000);
|
public static final BigDecimal ENERGY_FOR_HUNGER_POINT = new BigDecimal(1000);
|
||||||
|
|
||||||
private int sleep_ticks = 0;
|
public int sleep_ticks = 0;
|
||||||
|
public static final int SLEEP_TICKS_LIMIT = 80;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void tickInnerClientAlways() {
|
||||||
|
super.tickInnerClientAlways();
|
||||||
|
|
||||||
|
if (will_become_android) {
|
||||||
|
if (ent.isSleeping()) {
|
||||||
|
sleep_ticks++;
|
||||||
|
} else {
|
||||||
|
sleep_ticks = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void tickServerAlways() {
|
protected void tickServerAlways() {
|
||||||
@ -259,7 +273,7 @@ public class AndroidCapabilityPlayer extends AndroidCapability {
|
|||||||
if (ent.isSleeping()) {
|
if (ent.isSleeping()) {
|
||||||
sleep_ticks++;
|
sleep_ticks++;
|
||||||
|
|
||||||
if (sleep_ticks > 40) {
|
if (sleep_ticks > SLEEP_TICKS_LIMIT) {
|
||||||
becomeAndroid();
|
becomeAndroid();
|
||||||
sleep_ticks = 0;
|
sleep_ticks = 0;
|
||||||
|
|
||||||
|
@ -2,23 +2,33 @@ package ru.dbotthepony.mc.otm.client;
|
|||||||
|
|
||||||
import com.mojang.blaze3d.systems.RenderSystem;
|
import com.mojang.blaze3d.systems.RenderSystem;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.gui.components.Button;
|
||||||
import net.minecraft.client.gui.screens.DeathScreen;
|
import net.minecraft.client.gui.screens.DeathScreen;
|
||||||
|
import net.minecraft.client.gui.screens.InBedChatScreen;
|
||||||
|
import net.minecraft.client.gui.screens.Screen;
|
||||||
import net.minecraft.client.player.LocalPlayer;
|
import net.minecraft.client.player.LocalPlayer;
|
||||||
import net.minecraft.network.chat.TranslatableComponent;
|
import net.minecraft.network.chat.TranslatableComponent;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.world.effect.MobEffects;
|
import net.minecraft.world.effect.MobEffects;
|
||||||
import net.minecraft.world.entity.LivingEntity;
|
import net.minecraft.world.entity.LivingEntity;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
|
import net.minecraftforge.client.event.ScreenEvent;
|
||||||
import net.minecraftforge.client.event.ScreenOpenEvent;
|
import net.minecraftforge.client.event.ScreenOpenEvent;
|
||||||
import net.minecraftforge.client.event.RenderGameOverlayEvent;
|
import net.minecraftforge.client.event.RenderGameOverlayEvent;
|
||||||
import net.minecraftforge.client.gui.ForgeIngameGui;
|
import net.minecraftforge.client.gui.ForgeIngameGui;
|
||||||
|
import net.minecraftforge.event.TickEvent;
|
||||||
|
import net.minecraftforge.eventbus.api.EventPriority;
|
||||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
import ru.dbotthepony.mc.otm.OverdriveThatMatters;
|
import ru.dbotthepony.mc.otm.OverdriveThatMatters;
|
||||||
|
import ru.dbotthepony.mc.otm.capability.android.AndroidCapabilityPlayer;
|
||||||
import ru.dbotthepony.mc.otm.capability.android.IAndroidCapability;
|
import ru.dbotthepony.mc.otm.capability.android.IAndroidCapability;
|
||||||
import ru.dbotthepony.mc.otm.capability.MatteryCapability;
|
import ru.dbotthepony.mc.otm.capability.MatteryCapability;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
public class AndroidGui {
|
public class AndroidGui {
|
||||||
private static final Minecraft mc = Minecraft.getInstance();
|
private static final Minecraft mc = Minecraft.getInstance();
|
||||||
@ -26,23 +36,94 @@ public class AndroidGui {
|
|||||||
|
|
||||||
public static final ResourceLocation PLAYER_GUI_LOCATION = new ResourceLocation(OverdriveThatMatters.MOD_ID, "textures/gui/player_gui.png");
|
public static final ResourceLocation PLAYER_GUI_LOCATION = new ResourceLocation(OverdriveThatMatters.MOD_ID, "textures/gui/player_gui.png");
|
||||||
|
|
||||||
private IAndroidCapability last_state;
|
private AndroidCapabilityPlayer last_state;
|
||||||
|
|
||||||
@SubscribeEvent
|
private static int known_button_x = -1;
|
||||||
public static void onOpenGUI(ScreenOpenEvent event) {
|
private static int known_button_y = -1;
|
||||||
if (!(event.getScreen() instanceof DeathScreen screen))
|
private static Button known_button;
|
||||||
|
private static InBedChatScreen known_button_screen;
|
||||||
|
private static final Random button_shaker = new Random();
|
||||||
|
|
||||||
|
@SubscribeEvent(priority = EventPriority.NORMAL)
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public void onTick(ScreenEvent.DrawScreenEvent.Pre event) {
|
||||||
|
if (known_button_screen != null && known_button == null) {
|
||||||
|
for (var widget : known_button_screen.renderables) {
|
||||||
|
if (widget instanceof Button btn) {
|
||||||
|
known_button_x = btn.x;
|
||||||
|
known_button_y = btn.y;
|
||||||
|
known_button = btn;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (known_button == null) {
|
||||||
|
known_button_screen = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (known_button_screen != null && known_button_screen != mc.screen) {
|
||||||
|
known_button_x = -1;
|
||||||
|
known_button_y = -1;
|
||||||
|
known_button = null;
|
||||||
|
known_button_screen = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (known_button_screen == null || mc.player == null) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
mc.player.getCapability(MatteryCapability.ANDROID).ifPresent(cap -> {
|
||||||
|
if (!((AndroidCapabilityPlayer) cap).will_become_android) {
|
||||||
|
known_button.x = known_button_x;
|
||||||
|
known_button.y = known_button_y;
|
||||||
|
known_button_x = -1;
|
||||||
|
known_button_y = -1;
|
||||||
|
known_button = null;
|
||||||
|
known_button_screen = null;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int dispersion = (int) ((10.0 * Math.max(0, ((AndroidCapabilityPlayer) cap).sleep_ticks - 20)) / (AndroidCapabilityPlayer.SLEEP_TICKS_LIMIT - 20));
|
||||||
|
|
||||||
|
known_button.x = known_button_x - dispersion / 2 + (int) (button_shaker.nextDouble() * dispersion);
|
||||||
|
known_button.y = known_button_y - dispersion / 2 + (int) (button_shaker.nextDouble() * dispersion);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent(priority = EventPriority.LOWEST)
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public static void onOpenGUI(ScreenOpenEvent event) {
|
||||||
|
known_button_x = -1;
|
||||||
|
known_button_y = -1;
|
||||||
|
known_button = null;
|
||||||
|
known_button_screen = null;
|
||||||
|
|
||||||
if (mc.player == null)
|
if (mc.player == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
mc.player.getCapability(MatteryCapability.ANDROID).ifPresent(cap -> {
|
if (event.getScreen() instanceof DeathScreen screen) {
|
||||||
if (cap.isAndroid())
|
mc.player.getCapability(MatteryCapability.ANDROID).ifPresent(cap -> {
|
||||||
screen.title = new TranslatableComponent("otm.death_reason");
|
if (cap.isAndroid())
|
||||||
});
|
screen.title = new TranslatableComponent("otm.death_reason");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event.getScreen() instanceof InBedChatScreen screen) {
|
||||||
|
known_button_screen = screen;
|
||||||
|
|
||||||
|
mc.player.getCapability(MatteryCapability.ANDROID).ifPresent(cap -> {
|
||||||
|
if (((AndroidCapabilityPlayer) cap).will_become_android) {
|
||||||
|
known_button_screen = screen;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
private static final Logger LOGGER = LogManager.getLogger();
|
||||||
|
|
||||||
|
@SubscribeEvent(priority = EventPriority.HIGH)
|
||||||
|
@SuppressWarnings("unused")
|
||||||
public void onLayerRenderEvent(RenderGameOverlayEvent.PreLayer event) {
|
public void onLayerRenderEvent(RenderGameOverlayEvent.PreLayer event) {
|
||||||
if (event.getOverlay() != ForgeIngameGui.FOOD_LEVEL_ELEMENT && event.getOverlay() != ForgeIngameGui.AIR_LEVEL_ELEMENT)
|
if (event.getOverlay() != ForgeIngameGui.FOOD_LEVEL_ELEMENT && event.getOverlay() != ForgeIngameGui.AIR_LEVEL_ELEMENT)
|
||||||
return;
|
return;
|
||||||
@ -61,10 +142,10 @@ public class AndroidGui {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
Optional<IAndroidCapability> lazy = ply.getCapability(MatteryCapability.ANDROID).resolve();
|
Optional<IAndroidCapability> lazy = ply.getCapability(MatteryCapability.ANDROID).resolve();
|
||||||
IAndroidCapability android = null;
|
AndroidCapabilityPlayer android = null;
|
||||||
|
|
||||||
if (lazy.isPresent()) {
|
if (lazy.isPresent()) {
|
||||||
android = lazy.get();
|
android = (AndroidCapabilityPlayer) lazy.get();
|
||||||
} else if (!ply.isAlive()) {
|
} else if (!ply.isAlive()) {
|
||||||
android = last_state;
|
android = last_state;
|
||||||
}
|
}
|
||||||
|
@ -89,7 +89,7 @@ public class ItemPill extends Item {
|
|||||||
|
|
||||||
if (ply instanceof ServerPlayer)
|
if (ply instanceof ServerPlayer)
|
||||||
((AndroidCapabilityPlayer) resolver.get()).becomeAndroidSoft();
|
((AndroidCapabilityPlayer) resolver.get()).becomeAndroidSoft();
|
||||||
} else if (this.pill_type == PillType.BECOME_HUMANE && resolver.get().isAndroid()) {
|
} else if (this.pill_type == PillType.BECOME_HUMANE && ((AndroidCapabilityPlayer) resolver.get()).isEverAndroid()) {
|
||||||
if (!ply.getAbilities().instabuild)
|
if (!ply.getAbilities().instabuild)
|
||||||
stack.shrink(1);
|
stack.shrink(1);
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
"otm.pill.warning": "WARNING: This will INSTANTLY decommission you upon ingestion!",
|
"otm.pill.warning": "WARNING: This will INSTANTLY decommission you upon ingestion!",
|
||||||
"otm.pill.android": "Take this pill and lose what is holding you back.",
|
"otm.pill.android": "Take this pill and lose what is holding you back.",
|
||||||
"otm.pill.humane": "Take this pill and wake up in bed none the wiser.",
|
"otm.pill.humane": "Take this pill and wake up in bed none the wiser.",
|
||||||
"otm.pill.message": "You feel exhausted, but nothing happens?.. Maybe get a bed rest.",
|
"otm.pill.message": "Nothing happened, but you feel exhausted?.. Maybe get bed rest.",
|
||||||
"otm.pill.message_finish": "§kONE OF US ONE OF US ONE OF US ONE OF US ONE OF US",
|
"otm.pill.message_finish": "§kONE OF US ONE OF US ONE OF US ONE OF US ONE OF US",
|
||||||
|
|
||||||
"otm.gui.power.percentage_level": "Energy level: %s%%",
|
"otm.gui.power.percentage_level": "Energy level: %s%%",
|
||||||
|
Loading…
Reference in New Issue
Block a user