Skip to content

Commit

Permalink
Fix background missing
Browse files Browse the repository at this point in the history
  • Loading branch information
Patbox committed Dec 22, 2024
1 parent 94b8c41 commit 4bb12a1
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 3 deletions.
25 changes: 25 additions & 0 deletions src/main/java/io/github/haykam821/consolebox/game/GameCanvas.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -69,6 +70,9 @@ private static CanvasImage readImage(String path) {
private final GamePalette palette;
private final CombinedPlayerCanvas canvas;

@Nullable
private CanvasIcon mouse = null;

private final WasmFunctions.Consumer0 startCallback;
private WasmFunctions.Consumer0 updateCallback;
private final AudioController audioController;
Expand Down Expand Up @@ -354,6 +358,8 @@ public void render() {
index += 2;
}
}
/*this.canvas.set(Short.reverseBytes(this.memory.getBuffer().getShort(0x001a)) + DRAW_OFFSET_X,
Short.reverseBytes(this.memory.getBuffer().getShort(0x001c)) + DRAW_OFFSET_Y, CanvasColor.RED_HIGH);*/
}

public void updateGamepad(int id, boolean forward, boolean left, boolean backward, boolean right, boolean isSneaking, boolean isJumping) {
Expand All @@ -362,6 +368,25 @@ public void updateGamepad(int id, boolean forward, boolean left, boolean backwar
}
}

public void updateMousePosition(int id, int mouseX, int mouseY) {
synchronized (this) {
//if (this.mouse == null) {
//// this.mouse = this.canvas.createIcon(MapDecorationTypes.PLAYER, (mouseX + DRAW_OFFSET_X) * 2, (mouseY + DRAW_OFFSET_Y) * 2, (byte) 0, null);
//} else {
// this.mouse.move((mouseX + DRAW_OFFSET_X) * 2, (mouseY + DRAW_OFFSET_Y) * 2, this.mouse.getRotation());
// System.out.println((mouseX + DRAW_OFFSET_X) * 2);
// System.out.println((mouseY + DRAW_OFFSET_Y) * 2);
//}
this.memory.updateMousePosition(id, mouseX, mouseY);
}
}

public void updateMouseState(int id, boolean leftClick, boolean rightClick, boolean middleClick) {
synchronized (this) {
this.memory.updateMouseState(id, leftClick, rightClick, middleClick);
}
}

public void tick(long lastTime) {
synchronized (this) {
try {
Expand Down
31 changes: 28 additions & 3 deletions src/main/java/io/github/haykam821/consolebox/game/GameMemory.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
import io.github.kawamuray.wasmtime.Memory;
import io.github.kawamuray.wasmtime.MemoryType;
import io.github.kawamuray.wasmtime.Store;
import net.minecraft.entity.passive.MuleEntity;
import net.minecraft.network.packet.s2c.play.UpdateSelectedSlotS2CPacket;
import net.minecraft.server.network.ServerPlayerEntity;

public final class GameMemory {
private static final int PALETTE_ADDRESS = 0x0004;
Expand Down Expand Up @@ -138,6 +135,34 @@ public void updateGamepad(int id, boolean forward, boolean left, boolean backwar
this.buffer.put(GAMEPADS_ADDRESS + id, gamepad);
}

public void updateMousePosition(int id, int mouseX, int mouseY) {
if (id != 0) {
return;
}
this.buffer.putShort(MOUSE_X_ADDRESS, Short.reverseBytes((short) mouseX));
this.buffer.putShort(MOUSE_Y_ADDRESS, Short.reverseBytes((short) mouseY));
}

public void updateMouseState(int id, boolean leftClick, boolean rightClick, boolean mouseMiddle) {
if (id != 0) {
return;
}
byte buttons = 0;

if (leftClick) {
buttons |= 1;
}

if (rightClick) {
buttons |= 2;
}

if (mouseMiddle) {
buttons |= 4;
}
this.buffer.put(MOUSE_BUTTONS_ADDRESS, buttons);
}

private void initializeMemory() {
this.buffer.putInt(PALETTE_ADDRESS, 0xCFF8E000); // Dark green
this.buffer.putInt(PALETTE_ADDRESS + 4, 0x6CC08600); // Light green
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 4bb12a1

Please sign in to comment.