Water handling in android capability
This commit is contained in:
parent
316c30abb8
commit
a6e00d22e8
src/main/java/ru/dbotthepony/mc/otm
@ -5,6 +5,7 @@ import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.food.FoodData;
|
||||
import net.minecraftforge.client.event.InputUpdateEvent;
|
||||
import net.minecraftforge.common.util.LazyOptional;
|
||||
import net.minecraftforge.event.AttachCapabilitiesEvent;
|
||||
import net.minecraftforge.event.entity.player.PlayerEvent;
|
||||
@ -132,6 +133,36 @@ public class AndroidCapabilityPlayer extends AndroidCapability {
|
||||
});
|
||||
}
|
||||
|
||||
private int last_jump_ticks = 20;
|
||||
|
||||
@SubscribeEvent
|
||||
public static void inputEvent(InputUpdateEvent event) {
|
||||
var ply = event.getPlayer();
|
||||
var input = event.getMovementInput();
|
||||
|
||||
ply.getCapability(MatteryCapability.ANDROID).ifPresent(_cap -> {
|
||||
if (!(_cap instanceof AndroidCapabilityPlayer cap))
|
||||
return;
|
||||
|
||||
if (ply.getAbilities().mayfly) {
|
||||
cap.last_jump_ticks = 20;
|
||||
} else {
|
||||
if (ply.isInWater()) {
|
||||
if (ply.isOnGround()) {
|
||||
cap.last_jump_ticks = 20;
|
||||
}
|
||||
|
||||
if (cap.last_jump_ticks <= 0) {
|
||||
event.getMovementInput().jumping = false;
|
||||
event.getMovementInput().up = false;
|
||||
} else {
|
||||
cap.last_jump_ticks--;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private final Player ply;
|
||||
|
||||
public AndroidCapabilityPlayer(Player ent) {
|
||||
@ -154,6 +185,9 @@ public class AndroidCapabilityPlayer extends AndroidCapability {
|
||||
// TODO: Maybe passive drain?
|
||||
// extractEnergyInner(BigDecimal.valueOf(new Random().nextDouble()), false);
|
||||
|
||||
if (ply.getAirSupply() < ply.getMaxAirSupply())
|
||||
ply.setAirSupply(ply.getMaxAirSupply());
|
||||
|
||||
FoodData stats = ply.getFoodData();
|
||||
|
||||
if (stats.needsFood()) {
|
||||
|
@ -26,7 +26,7 @@ public class AndroidGui {
|
||||
|
||||
@SubscribeEvent
|
||||
public void onLayerRenderEvent(RenderGameOverlayEvent.PreLayer event) {
|
||||
if (event.getOverlay() != ForgeIngameGui.FOOD_LEVEL_ELEMENT)
|
||||
if (event.getOverlay() != ForgeIngameGui.FOOD_LEVEL_ELEMENT && event.getOverlay() != ForgeIngameGui.AIR_LEVEL_ELEMENT)
|
||||
return;
|
||||
|
||||
LocalPlayer ply = mc.player;
|
||||
@ -55,6 +55,10 @@ public class AndroidGui {
|
||||
event.setCanceled(true);
|
||||
last_state = android;
|
||||
|
||||
if (event.getOverlay() == ForgeIngameGui.AIR_LEVEL_ELEMENT) {
|
||||
return;
|
||||
}
|
||||
|
||||
float level;
|
||||
|
||||
if (android.getMaxBatteryLevel().compareTo(BigDecimal.ZERO) == 0) {
|
||||
|
Loading…
Reference in New Issue
Block a user