Skip to content

Commit

Permalink
Merge pull request #11 from Jab125/1.18
Browse files Browse the repository at this point in the history
Create snake game
  • Loading branch information
Jab125 committed Jul 14, 2022
2 parents 9b8c072 + 2112f02 commit bde82ca
Show file tree
Hide file tree
Showing 5 changed files with 396 additions and 2 deletions.
5 changes: 4 additions & 1 deletion common/src/main/java/com/ultreon/devices/Devices.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import com.ultreon.devices.programs.example.ExampleApp;
import com.ultreon.devices.programs.example.task.TaskNotificationTest;
import com.ultreon.devices.programs.gitweb.GitWebApp;
import com.ultreon.devices.programs.snake.SnakeApp;
import com.ultreon.devices.programs.system.*;
import com.ultreon.devices.programs.system.task.*;
import com.ultreon.devices.util.ArchUtils;
Expand Down Expand Up @@ -174,6 +175,8 @@ private static void registerApplications() {
ApplicationManager.registerApplication(new ResourceLocation(Reference.MOD_ID, "boat_racers"), BoatRacersApp.class);
ApplicationManager.registerApplication(new ResourceLocation(Reference.MOD_ID, "mine_bay"), MineBayApp.class);

ApplicationManager.registerApplication(new ResourceLocation(Reference.MOD_ID, "snake"), SnakeApp.class);

// Core
TaskManager.registerTask(TaskUpdateApplicationData.class);
TaskManager.registerTask(TaskPrint.class);
Expand Down Expand Up @@ -307,7 +310,7 @@ public static void setAllowedApps(List<AppInfo> allowedApps) {
@Nullable
public static Application registerApplication(ResourceLocation identifier, Class<? extends Application> clazz) {
if ("minecraft".equals(identifier.getNamespace())) {
throw new IllegalArgumentException("Invalid identifier namespace");
throw new IllegalArgumentException("Identifier cannot be \"minecraft\"!");
}

if (allowedApps == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public Button(int left, int top, int buttonWidth, int buttonHeight, String text,
this.setIcon(iconResource, iconU, iconV, iconWidth, iconHeight);
}

private static int getTextWidth(String text) {
public static int getTextWidth(String text) {
boolean flag = Minecraft.getInstance().options.forceUnicodeFont;
Minecraft.getInstance().options.forceUnicodeFont = false;
Font fontRenderer = Minecraft.getInstance().font;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.ultreon.devices.programs.snake;

import com.mojang.blaze3d.vertex.PoseStack;
import com.ultreon.devices.api.app.Application;
import com.ultreon.devices.api.app.Component;
import com.ultreon.devices.api.app.Dialog;
import com.ultreon.devices.api.app.Layout;
import com.ultreon.devices.api.app.component.Button;
import com.ultreon.devices.api.app.component.Label;
import com.ultreon.devices.api.app.component.Text;
import com.ultreon.devices.core.Laptop;
import com.ultreon.devices.programs.snake.layout.SnakeLayout;
import com.ultreon.devices.programs.system.AppStore;
import net.minecraft.client.Minecraft;
import net.minecraft.nbt.CompoundTag;
import org.jetbrains.annotations.Nullable;

import static com.ultreon.devices.api.app.component.Button.getTextWidth;

public class SnakeApp extends Application {
public Layout titleScreen;
public SnakeLayout gameLayout;
@Override
public void init(@Nullable CompoundTag intent) {
this.titleScreen = new Layout(200, 100);
var startButton = new Button(30, 70, "Start");
startButton.setClickListener(((mouseX, mouseY, mouseButton) -> {
this.gameLayout = new SnakeLayout(this);
this.setCurrentLayout(this.gameLayout);
}));
var titleText = new Label("Snake", 10, 10);
titleText.setScale(2);

titleScreen.addComponent(titleText);
titleScreen.addComponent(startButton);
setCurrentLayout(titleScreen);
}

@Override
public void render(PoseStack pose, Laptop laptop, Minecraft mc, int x, int y, int mouseX, int mouseY, boolean active, float partialTicks) {
super.render(pose, laptop, mc, x, y, mouseX, mouseY, active, partialTicks);
// for (Component component : this.titleScreen.components) {
// System.out.println(component + "lt: " + component.left + ", " + component.top);
// }
}

@Override
public void load(CompoundTag tag) {

}

@Override
public void save(CompoundTag tag) {

}
}

0 comments on commit bde82ca

Please sign in to comment.