use of io.xol.chunkstories.api.client.LocalPlayer in project chunkstories-core by Hugobros3.
the class ItemFirearm method tickInHand.
/**
* Should be called when the owner has this item selected
*
* @param owner
*/
@Override
public void tickInHand(Entity owner, ItemPile itemPile) {
if (owner instanceof EntityControllable && ((EntityControllable) owner).getController() != null) {
EntityControllable owner2 = ((EntityControllable) owner);
Controller controller = owner2.getController();
// For now only client-side players can trigger shooting actions
if (controller instanceof LocalPlayer) {
if (!((LocalPlayer) controller).hasFocus())
return;
LocalPlayer LocalPlayer = (LocalPlayer) controller;
if (LocalPlayer.getInputsManager().getInputByName("mouse.left").isPressed()) {
// Check for bullet presence (or creative mode)
boolean bulletPresence = (owner instanceof EntityCreative && ((EntityCreative) owner).isCreativeMode()) || checkBullet(itemPile);
if (!bulletPresence && !wasTriggerPressedLastTick) {
// Play sounds
if (LocalPlayer != null)
LocalPlayer.getSoundManager().playSoundEffect("sounds/dogez/weapon/default/dry.ogg", Mode.NORMAL, owner.getLocation(), 1.0f, 1.0f, 1f, (float) soundRange);
// Dry.ogg
// return;
} else if ((automatic || !wasTriggerPressedLastTick) && (System.currentTimeMillis() - lastShot) / 1000.0d > 1.0 / (rpm / 60.0)) {
// Fire virtual input
// ClientInputPressedEvent event = new ClientInputPressedEvent(controller.getInputsManager().getInputByName("shootGun"));
// Client.getInstance().getPluginManager().fireEvent(event);
LocalPlayer.getInputsManager().onInputPressed(controller.getInputsManager().getInputByName("shootGun"));
lastShot = System.currentTimeMillis();
}
}
isScoped = this.isScopedWeapon() && controller.getInputsManager().getInputByName("mouse.right").isPressed();
wasTriggerPressedLastTick = controller.getInputsManager().getInputByName("mouse.left").isPressed();
}
}
}
use of io.xol.chunkstories.api.client.LocalPlayer in project chunkstories-core by Hugobros3.
the class ParticleLightningStrike method getRenderer.
@Override
public ParticleTypeRenderer getRenderer(ParticlesRenderer particlesRenderer) {
return new ParticleTypeRenderer(particlesRenderer) {
@Override
public void forEach_Rendering(RenderingInterface renderingContext, ParticleData data) {
Content content = ParticleLightningStrike.this.getType().store().parent();
if (content instanceof ClientContent) {
ClientContent clientContent = (ClientContent) content;
LocalPlayer player = clientContent.getContext().getPlayer();
Entity entity = player.getControlledEntity();
if (entity != null) {
Location loc = entity.getLocation();
data.set((float) (double) data.x(), (float) (double) loc.y() + 1024, (float) (double) data.z());
}
}
renderingContext.getLightsRenderer().queueLight(new Light(new Vector3f(226 / 255f, 255 / 255f, 226 / 255f).mul((float) (1f + Math.random())), new Vector3f((float) data.x(), (float) data.y(), (float) data.z()), 102004f + (float) Math.random() * 5f));
}
@Override
public void destroy() {
}
};
}
use of io.xol.chunkstories.api.client.LocalPlayer 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.api.client.LocalPlayer 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;
}
}
use of io.xol.chunkstories.api.client.LocalPlayer in project chunkstories-api by Hugobros3.
the class EntityComponentController method pull.
@Override
public void pull(StreamSource from, DataInputStream dis) throws IOException {
long controllerUUID = 0;
boolean isControllerNotNull = dis.readBoolean();
if (isControllerNotNull)
controllerUUID = dis.readLong();
// This is strictly illegal, only remotely connected client worlds will accept such requests
if (!(entity.getWorld() instanceof WorldClientNetworkedRemote)) {
// Terminate connections immediately
if (from instanceof Player)
((Player) from).disconnect("Illegal controller set attempt, terminating client connection for " + from);
return;
}
LocalPlayer player = ((ClientInterface) entity.getWorld().getGameContext()).getPlayer();
assert player != null;
if (isControllerNotNull) {
// long controllerUUID = dis.readLong();
long clientUUID = player.getUUID();
System.out.println("Entity " + entity + " is now in control of " + controllerUUID + " me=" + clientUUID);
// This update tells us we are now in control of this entity
if (clientUUID == controllerUUID) {
EntityControllable controlledEntity = (EntityControllable) entity;
// TODO sort out local hosted worlds properly ?
// Client.getInstance().getServerConnection().subscribe(entity);
controller = player;
player.setControlledEntity(controlledEntity);
System.out.println("The client is now in control of entity " + controlledEntity);
} else {
// If we receive a different UUID than ours in a EntityComponent change, it means that we don't control it anymore and someone else does.
if (player.getControlledEntity() != null && player.getControlledEntity().equals(entity)) {
player.setControlledEntity(null);
// Client.getInstance().getServerConnection().unsubscribe(entity);
controller = null;
System.out.println("Lost control of entity " + entity + " to " + controllerUUID);
}
}
} else {
// If we receive a different UUID than ours in a EntityComponent change, it means that we don't control it anymore and someone else does.
if (player.getControlledEntity() != null && player.getControlledEntity().equals(entity)) {
player.setControlledEntity(null);
// Client.getInstance().getServerConnection().unsubscribe(entity);
controller = null;
System.out.println("Lost control of entity " + entity);
}
}
}
Aggregations