Improve code formatting

This commit is contained in:
Stone_Red
2022-04-07 14:05:37 +02:00
parent c9d5b44f90
commit 2a107f029e
7 changed files with 39 additions and 47 deletions
@@ -5,10 +5,7 @@ import com.yes.yes.utils.*;
import com.yes.yes.world.Chunk;
import com.yes.yes.world.World;
import javafx.scene.Scene;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyCodeCombination;
import javafx.scene.input.KeyCombination;
import javafx.scene.input.KeyEvent;
import javafx.scene.input.*;
public class PlayerManager {
@@ -33,9 +30,15 @@ public class PlayerManager {
scene.widthProperty().addListener((e) -> loadAllOnScreen());
scene.heightProperty().addListener((e) -> loadAllOnScreen());
world.setOnMouseClicked((e) ->
{
Coordinate mouseCoordinate = new Coordinate((int) e.getX(), (int) e.getY());
world.setOnMouseClicked(this::ProcessClick);
world.setTranslateX(Integer.MAX_VALUE / -5000d);
world.setTranslateY(Integer.MAX_VALUE / -5000d);
loadAllOnScreen();
}
private void ProcessClick(MouseEvent mouse) {
Coordinate mouseCoordinate = new Coordinate((int) mouse.getX(), (int) mouse.getY());
Coordinate chunkCoordinate = Coordinate.WorldToChunkCoordinate(mouseCoordinate);
Coordinate blockCoordinate = Coordinate.WorldToChunkBlock(mouseCoordinate);
@@ -56,13 +59,6 @@ public class PlayerManager {
ex.printStackTrace();
}
}
);
world.setTranslateX(Integer.MAX_VALUE / -5000d);
world.setTranslateY(Integer.MAX_VALUE / -5000d);
loadAllOnScreen();
}
private void ProcessKeyPress(KeyEvent key) {
if (LEFT_KEY.match(key)) {
@@ -113,8 +109,7 @@ public class PlayerManager {
chunkPos = new Coordinate(chunkPosition.x, chunkPosition.y);
}
private void loadAllOnScreen()
{
private void loadAllOnScreen() {
Size loadedChunks = getAmountOfLoadedChunks();
Coordinate chunkPosition = getCurrentChunkPosition();
@@ -125,8 +120,7 @@ public class PlayerManager {
}
}
private Coordinate getCurrentChunkPosition()
{
private Coordinate getCurrentChunkPosition() {
double offset = Chunk.CHUNK_SIZE * Chunk.ENTITY_SIZE;
int chunkX = -(int) Math.floor((world.getTranslateX() + offset) / Chunk.CHUNK_SIZE / Chunk.ENTITY_SIZE);
@@ -135,8 +129,7 @@ public class PlayerManager {
return new Coordinate(chunkX, chunkY);
}
private Size getAmountOfLoadedChunks()
{
private Size getAmountOfLoadedChunks() {
int loadedChunksX = (int) Math.ceil(world.getScene().getWidth() / Chunk.CHUNK_SIZE / Chunk.ENTITY_SIZE) + 1;
int loadedChunksY = (int) Math.ceil(world.getScene().getHeight() / Chunk.CHUNK_SIZE / Chunk.ENTITY_SIZE) + 1;
@@ -6,11 +6,11 @@ import java.util.ArrayList;
import java.util.HashMap;
public class EntityRegistry {
private static final HashMap<String, RegistryEntry> entities = new HashMap<>();
private EntityRegistry() {
}
private static final HashMap<String, RegistryEntry> entities = new HashMap<>();
public static void register(RegistryEntry entry) throws AlreadyExistsException {
if (entities.containsKey(entry.getName())) {
throw new AlreadyExistsException("Name already registered");
@@ -4,11 +4,11 @@ import java.util.function.Consumer;
import java.util.function.Function;
public class GlobalEventHandler {
private static final EventHandler handler = new EventHandler();
private GlobalEventHandler() {
}
private static final EventHandler handler = new EventHandler();
public static <T> void addListener(String eventName, Consumer<T> function) {
handler.addListener(eventName, function);
}
@@ -13,7 +13,6 @@ public class Item extends javafx.scene.Group {
}
parts[layer][section] = part;
this.getChildren().add(part);
}
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.layout.VBox?>
<VBox spacing="20.0" xmlns:fx="http://javafx.com/fxml"
<VBox xmlns:fx="http://javafx.com/fxml" spacing="20.0"
fx:controller="com.yes.yes.MainController" fx:id="root">
</VBox>