Update code to work on dedicated servers
This commit is contained in:
parent
c66c64f87a
commit
38d34de609
@ -16,6 +16,7 @@ import ru.dbotthepony.mc.otm.capability.AndroidCapability;
|
||||
import ru.dbotthepony.mc.otm.capability.AndroidCapabilityPlayer;
|
||||
import ru.dbotthepony.mc.otm.capability.MatteryCapability;
|
||||
import ru.dbotthepony.mc.otm.client.AndroidGui;
|
||||
import ru.dbotthepony.mc.otm.client.EventHandler;
|
||||
import ru.dbotthepony.mc.otm.matter.MatterGrid;
|
||||
import ru.dbotthepony.mc.otm.matter.MatterRegistry;
|
||||
import ru.dbotthepony.mc.otm.network.MatteryNetworking;
|
||||
@ -84,6 +85,7 @@ public class OverdriveThatMatters {
|
||||
ANDROID_GUI = new AndroidGui();
|
||||
MinecraftForge.EVENT_BUS.register(ANDROID_GUI);
|
||||
MinecraftForge.EVENT_BUS.register(AndroidGui.class);
|
||||
MinecraftForge.EVENT_BUS.register(EventHandler.class);
|
||||
}
|
||||
|
||||
private void enqueueIMC(final InterModEnqueueEvent event) {
|
||||
|
@ -159,43 +159,7 @@ public class AndroidCapabilityPlayer extends AndroidCapability {
|
||||
});
|
||||
}
|
||||
|
||||
private int last_jump_ticks = 14;
|
||||
|
||||
@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 (cap.hasFeature(Registry.AndroidFeatures.AIR_BAGS))
|
||||
return;
|
||||
|
||||
if (ply.getAbilities().mayfly) {
|
||||
cap.last_jump_ticks = 14;
|
||||
} else {
|
||||
if (ply.isInWater()) {
|
||||
if (ply.isOnGround()) {
|
||||
cap.last_jump_ticks = 14;
|
||||
}
|
||||
|
||||
if (ply.isSwimming()) {
|
||||
ply.setSwimming(false);
|
||||
}
|
||||
|
||||
if (cap.last_jump_ticks <= 0) {
|
||||
event.getMovementInput().jumping = false;
|
||||
event.getMovementInput().up = false;
|
||||
} else {
|
||||
cap.last_jump_ticks--;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public int last_jump_ticks = 14;
|
||||
public final Player ply;
|
||||
|
||||
public AndroidCapabilityPlayer(Player ent) {
|
||||
|
44
src/main/java/ru/dbotthepony/mc/otm/client/EventHandler.java
Normal file
44
src/main/java/ru/dbotthepony/mc/otm/client/EventHandler.java
Normal file
@ -0,0 +1,44 @@
|
||||
package ru.dbotthepony.mc.otm.client;
|
||||
|
||||
import net.minecraftforge.client.event.InputUpdateEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import ru.dbotthepony.mc.otm.Registry;
|
||||
import ru.dbotthepony.mc.otm.capability.AndroidCapabilityPlayer;
|
||||
import ru.dbotthepony.mc.otm.capability.MatteryCapability;
|
||||
|
||||
public class EventHandler {
|
||||
@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 (cap.hasFeature(Registry.AndroidFeatures.AIR_BAGS))
|
||||
return;
|
||||
|
||||
if (ply.getAbilities().mayfly) {
|
||||
cap.last_jump_ticks = 14;
|
||||
} else {
|
||||
if (ply.isInWater()) {
|
||||
if (ply.isOnGround()) {
|
||||
cap.last_jump_ticks = 14;
|
||||
}
|
||||
|
||||
if (ply.isSwimming()) {
|
||||
ply.setSwimming(false);
|
||||
}
|
||||
|
||||
if (cap.last_jump_ticks <= 0) {
|
||||
event.getMovementInput().jumping = false;
|
||||
event.getMovementInput().up = false;
|
||||
} else {
|
||||
cap.last_jump_ticks--;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user