use of io.xol.chunkstories.client.net.ServerConnection in project chunkstories by Hugobros3.
the class Lwjgl3ClientInputsManager method onInputPressed.
public boolean onInputPressed(Input input) {
if (input.equals("fullscreen")) {
gameWindow.toggleFullscreen();
return true;
}
// System.out.println("Input pressed "+input.getName());
// Try the client-side event press
ClientInputPressedEvent event = new ClientInputPressedEvent(gameWindow.getClient(), input);
ClientPluginManager cpm = gameWindow.getClient().getPluginManager();
if (cpm != null) {
cpm.fireEvent(event);
if (event.isCancelled())
return false;
}
// Try the GUI handling
Layer layer = gameWindow.getLayer();
if (layer.handleInput(input))
return true;
// System.out.println("wasn't handled");
final LocalPlayer player = Client.getInstance().getPlayer();
if (player == null)
return false;
final EntityControllable entityControlled = player.getControlledEntity();
// There has to be a controlled entity for sending inputs to make sense.
if (entityControlled == null)
return false;
// Send input to server
World world = entityControlled.getWorld();
if (world instanceof WorldClientRemote) {
// MouseScroll inputs are strictly client-side
if (!(input instanceof MouseScroll)) {
ServerConnection connection = ((WorldClientRemote) entityControlled.getWorld()).getConnection();
PacketInput packet = new PacketInput(world);
packet.input = input;
packet.isPressed = true;
connection.pushPacket(packet);
}
return entityControlled.onControllerInput(input, Client.getInstance().getPlayer());
} else {
PlayerInputPressedEvent event2 = new PlayerInputPressedEvent(Client.getInstance().getPlayer(), input);
cpm.fireEvent(event2);
if (event2.isCancelled())
return false;
// entity.handleInteraction(input, entity.getControllerComponent().getController());
}
// Handle interaction locally
return entityControlled.onControllerInput(input, Client.getInstance().getPlayer());
}
use of io.xol.chunkstories.client.net.ServerConnection in project chunkstories by Hugobros3.
the class Lwjgl3ClientInputsManager method onInputReleased.
@Override
public boolean onInputReleased(Input input) {
ClientInputReleasedEvent event = new ClientInputReleasedEvent(gameWindow.getClient(), input);
ClientPluginManager cpm = gameWindow.getClient().getPluginManager();
if (cpm != null) {
cpm.fireEvent(event);
}
final LocalPlayer player = Client.getInstance().getPlayer();
if (player == null)
return false;
final EntityControllable entityControlled = player.getControlledEntity();
// There has to be a controlled entity for sending inputs to make sense.
if (entityControlled == null)
return false;
// Send input to server
World world = entityControlled.getWorld();
if (world instanceof WorldClientRemote) {
ServerConnection connection = ((WorldClientRemote) entityControlled.getWorld()).getConnection();
PacketInput packet = new PacketInput(world);
packet.input = input;
packet.isPressed = false;
connection.pushPacket(packet);
return true;
} else {
PlayerInputReleasedEvent event2 = new PlayerInputReleasedEvent(Client.getInstance().getPlayer(), input);
cpm.fireEvent(event2);
return true;
}
}
Aggregations