├── .editorconfig ├── .github └── workflows │ └── gradle.yml ├── .gitignore ├── LICENSE ├── README.md ├── build.gradle ├── changelog.txt ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── jitpack.yml ├── level-version.md ├── settings.gradle └── src └── main ├── java └── io │ └── github │ └── overrun │ └── mc2d │ ├── Main.java │ ├── client │ ├── GameVersion.java │ ├── Keyboard.java │ ├── Mc2dClient.java │ ├── TextRenderer.java │ ├── TextureManager.java │ ├── gui │ │ ├── AbstractParentElement.java │ │ ├── Drawable.java │ │ ├── DrawableHelper.java │ │ ├── Element.java │ │ ├── ParentElement.java │ │ ├── screen │ │ │ ├── DirtScreen.java │ │ │ ├── Screen.java │ │ │ ├── TickableElement.java │ │ │ ├── TitleScreen.java │ │ │ ├── ingame │ │ │ │ ├── HandledScreen.java │ │ │ │ ├── ItemGroupsScreen.java │ │ │ │ └── PauseScreen.java │ │ │ └── world │ │ │ │ ├── LoadingWorldScreen.java │ │ │ │ └── SavingWorldScreen.java │ │ └── widget │ │ │ ├── AbstractButtonWidget.java │ │ │ ├── AbstractPressableButtonWidget.java │ │ │ └── ButtonWidget.java │ ├── model │ │ ├── BlockModelMgr.java │ │ ├── Cube.java │ │ ├── EntityModel.java │ │ ├── EntityModelMgr.java │ │ ├── PlayerEntityModel.java │ │ ├── Polygon.java │ │ └── Vertex.java │ ├── render │ │ ├── ItemRenderer.java │ │ └── VertexLayouts.java │ └── world │ │ ├── ClientChunk.java │ │ └── render │ │ └── WorldRenderer.java │ ├── event │ ├── Event.java │ └── KeyCallback.java │ ├── mod │ ├── Mod.java │ ├── ModInfoFile.java │ ├── ModInitializer.java │ ├── ModInstance.java │ └── ModLoader.java │ ├── screen │ ├── ItemGroupsScreenHandler.java │ ├── ScreenHandler.java │ ├── inv │ │ ├── IInventory.java │ │ ├── Inventories.java │ │ ├── ItemGroupsInventory.java │ │ └── PlayerInventory.java │ └── slot │ │ └── Slot.java │ ├── text │ ├── BaseText.java │ ├── IText.java │ ├── Style.java │ ├── StyledText.java │ └── TextColor.java │ ├── util │ ├── Colors.java │ ├── GlUtils.java │ ├── Identifier.java │ ├── ImageReader.java │ ├── Language.java │ ├── LoggerNamePatternSelector.java │ ├── NativeImage.java │ ├── Options.java │ ├── Utils.java │ ├── collect │ │ └── DefaultedList.java │ ├── registry │ │ ├── BaseRegistry.java │ │ ├── DefaultedRegistry.java │ │ ├── MappedRegistry.java │ │ ├── MutableRegistry.java │ │ ├── Registry.java │ │ └── ScreenHandlerRegistry.java │ └── shape │ │ ├── VoxelShape.java │ │ └── VoxelShapes.java │ └── world │ ├── Chunk.java │ ├── HitResult.java │ ├── IWorldFixer.java │ ├── IWorldListener.java │ ├── World.java │ ├── block │ ├── AirBlockType.java │ ├── BlockSettings.java │ ├── BlockType.java │ ├── Blocks.java │ └── LeavesBlockType.java │ ├── entity │ ├── Entity.java │ ├── EntityType.java │ ├── EntityTypeBuilder.java │ ├── EntityTypes.java │ ├── HumanEntity.java │ └── player │ │ └── PlayerEntity.java │ ├── ibt │ ├── BinaryTag.java │ ├── IBTType.java │ ├── IBTValue.java │ └── IBinaryTag.java │ └── item │ ├── BlockItemType.java │ ├── ItemConvertible.java │ ├── ItemGroup.java │ ├── ItemSettings.java │ ├── ItemStack.java │ ├── ItemType.java │ └── Items.java └── resources ├── assets └── mc2d │ ├── icon.png │ ├── lang │ ├── en_us.lang │ └── zh_cn.lang │ └── textures │ ├── block │ ├── bedrock.png │ ├── cobblestone.png │ ├── dirt.png │ ├── grass_block.png │ ├── oak_leaves.png │ ├── oak_log.png │ ├── oak_planks.png │ └── stone.png │ ├── entity │ └── player.png │ ├── font │ └── unifont_0.png │ └── gui │ ├── logo.png │ ├── options_background.png │ ├── tab_items.png │ ├── tabs.png │ └── widgets.png ├── log4j2.xml └── version.json /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | indent_size = 4 6 | indent_style = space 7 | trim_trailing_whitespace = true 8 | end_of_line = lf 9 | 10 | [*.md] 11 | trim_trailing_whitespace = false 12 | 13 | [{*.yml, *.json}] 14 | indent_size = 2 -------------------------------------------------------------------------------- /.github/workflows/gradle.yml: -------------------------------------------------------------------------------- 1 | # This workflow will build a Java project with Gradle 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle 3 | 4 | name: Java CI with Gradle 5 | 6 | on: [ push, pull_request ] 7 | 8 | jobs: 9 | build: 10 | strategy: 11 | matrix: 12 | java: [ 13 | 17 14 | ] 15 | os: [ ubuntu-latest, windows-latest ] 16 | runs-on: ${{ matrix.os }} 17 | steps: 18 | - uses: actions/checkout@v3 19 | - name: Set up JDK ${{ matrix.java }} 20 | uses: actions/setup-java@v3 21 | with: 22 | java-version: ${{ matrix.java }} 23 | distribution: 'temurin' 24 | - name: Grant execute permission for gradlew 25 | run: chmod +x gradlew 26 | - name: Build with Gradle 27 | uses: gradle/gradle-build-action@v2 28 | with: 29 | arguments: build distZip 30 | - name: capture build artifacts 31 | if: ${{ runner.os == 'Linux' && matrix.java == '17' }} 32 | uses: actions/upload-artifact@v3 33 | with: 34 | name: Artifacts 35 | path: build/libs/ 36 | - name: capture distribution 37 | if: ${{ runner.os == 'Linux' && matrix.java == '17' }} 38 | uses: actions/upload-artifact@v3 39 | with: 40 | name: Distribution 41 | path: build/distributions/ 42 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # gradle 2 | .gradle/ 3 | build/ 4 | 5 | # Ignore Gradle GUI config 6 | gradle-app.setting 7 | 8 | # Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) 9 | !gradle-wrapper.jar 10 | 11 | # Cache of project 12 | .gradletasknamecache 13 | 14 | # # Work around https://youtrack.jetbrains.com/issue/IDEA-116898 15 | # gradle/wrapper/gradle-wrapper.properties 16 | 17 | .idea/ 18 | out/ 19 | 20 | run/ 21 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020-2022 Overrun Organization 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Minecraft2D 2 | 3 | **THIS IS NOT AN OFFICIAL MINECRAFT PRODUCT. IT IS NOT APPROVED BY OR ASSOCIATED WITH MOJANG.** 4 | 5 | ![Java CI with Gradle](https://github.com/Over-Run/Minecraft2D/workflows/Java%20CI%20with%20Gradle/badge.svg) 6 | 7 | Minecraft2D is a 2D sandbox game using OpenGL. 8 | 9 | This game is also on [itch.io](https://squid233.itch.io/minecraft2d). 10 | 11 | ## Runtime Environment 12 | 13 | - Java: 17+ 14 | - OpenGL: 1.5+ 15 | 16 | ## Downloading 17 | 18 | > Due to the official website has refactored, the content this below are invalid. 19 | > 20 | > --- 21 | > 22 | > Minecraft2D 0.3.0 has shadowed all libraries, so you can use command `java -jar mc2d-0.3.0.jar` in terminal. 23 | > 24 | > Since 0.5.0, you must play game with the [launcher](https://over-run.github.io/mc2d/launcher/mc2d-launcher-0.1.0.jar). 25 | 26 | Since 0.6.0, game is distributed with the [Application Plugin](https://docs.gradle.org/current/userguide/application_plugin.html). 27 | 28 | ## Keybindings 29 | 30 | - Esc: Pause and save the world 31 | - A/Left Arrow: Move left 32 | - D/Right Arrow: Move right 33 | - Space/W/Up Arrow: Jump 34 | - Enter: Save the world 35 | - F3: Turn on/off the debug HUD 36 | - Z/Comma/Period (z/,/.): Change z mode 37 | - E: Open/close the inventory 38 | - G: Generate human entity 39 | 40 | ## Jvm Arguments 41 | 42 | - `-Dmc2d.log.disableAnsi=`: disable or enable ansi escaping (color, etc.) 43 | 44 | ## Links 45 | 46 | 游戏开发交流群 [![游戏开发交流](https://pub.idqqimg.com/wpa/images/group.png)](https://qm.qq.com/cgi-bin/qm/qr?k=efwa2cjVSs-S_UorWELGd45SPTJBTGV6&jump_from=webapi) 47 | 48 | 看看[Fandom Wiki](https://minecraft2d.fandom.com/zh/wiki/)! 49 | 50 | 在 [官方网站](https://over-run.github.io/minecraft2d-wiki/) (404) 上看我们的游戏! 51 | 52 | ## Other Edition 53 | 54 | - [Kotlin Edition](https://github.com/Over-Run/Minecraft2D-Kotlin/) (Deprecated) 55 | - [Python Edition](https://github.com/QWERTY770/Minecraft-2D-Python/) 56 | 57 | ## Minecraft2D & Minecraft 58 | 59 | Again. **THIS IS NOT AN OFFICIAL MINECRAFT PRODUCT. IT IS NOT APPROVED BY OR ASSOCIATED WITH MOJANG.** 60 | 61 | | | Minecraft2D | Minecraft | 62 | |--------------|-------------|-----------------| 63 | | Free | Y | N | 64 | | Java Version | 17+ (LTS) | 17+ (LTS) | 65 | | Mods | Y | Y(Non-Official) | 66 | | Multiplayer | N | Y | 67 | | I18n | Y | Y | 68 | 69 | ## Coming in Beta 70 | 71 | - Multiplayer test 72 | 73 | ## Coming in 1.0 (Release) 74 | 75 | - Multiplayer 76 | 77 | ## Coming in 2.0 (Future) 78 | 79 | - Use OpenGL 3.2 80 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'java' 3 | id 'idea' 4 | id 'maven-publish' 5 | id 'application' 6 | // id 'com.github.johnrengelman.shadow' version '6.1.0' 7 | } 8 | 9 | sourceCompatibility = targetCompatibility = JavaVersion.VERSION_17 10 | 11 | group 'io.github.over-run' 12 | archivesBaseName = 'mc2d' 13 | version '0.6.0-SNAPSHOT' 14 | 15 | repositories { 16 | mavenCentral() 17 | maven { url 'https://maven.aliyun.com/repository/central' } 18 | // temporary maven repositories 19 | maven { url 'https://s01.oss.sonatype.org/content/repositories/releases' } 20 | maven { url 'https://s01.oss.sonatype.org/content/repositories/snapshots' } 21 | } 22 | 23 | dependencies { 24 | implementation 'com.google.code.gson:gson:2.10' 25 | // implementation 'com.google.guava:guava:30.1-jre' 26 | implementation 'org.apache.logging.log4j:log4j-core:2.19.0' 27 | implementation 'org.apache.logging.log4j:log4j-slf4j18-impl:2.18.0' 28 | implementation 'org.joml:joml:1.10.5' 29 | implementation 'io.github.over-run:swgl-core:0.2.0-SNAPSHOT' 30 | compileOnly 'org.jetbrains:annotations:23.0.0' 31 | // Lwjgl runtime libraries 32 | for (String depend in ['', '-glfw', '-opengl', '-stb', '-jemalloc']) { 33 | for (String platform in [ 34 | 'linux-arm32', 'linux-arm64', 'linux', 35 | // 'macos-arm64', 'macos', 36 | 'windows-arm64', 'windows-x86', 'windows' 37 | ]) { 38 | runtimeOnly "org.lwjgl:lwjgl$depend::natives-$platform" 39 | } 40 | } 41 | } 42 | 43 | tasks.withType(JavaCompile) { 44 | options.encoding = 'UTF-8' 45 | } 46 | 47 | application { 48 | mainClass = 'io.github.overrun.mc2d.Main' 49 | } 50 | 51 | jar { 52 | from 'LICENSE' 53 | manifest.attributes('Main-Class': 'io.github.overrun.mc2d.Main', 54 | 'Specification-Title': 'mc2d', 55 | 'Specification-Vendor': 'Overrun Organization', 56 | 'Specification-Version': archiveVersion, 57 | 'Implementation-Title': 'Minecraft2D', 58 | 'Implementation-Vendor': 'Overrun Organization', 59 | 'Implementation-Version': archiveVersion, 60 | 'Multi-Release': true) 61 | } 62 | 63 | //shadowJar { 64 | // from 'LICENSE' 65 | //} 66 | 67 | task sourcesJar(type: Jar, dependsOn: classes) { 68 | archiveClassifier.set 'sources' 69 | from sourceSets.main.allSource, 'LICENSE' 70 | } 71 | 72 | task javadocJar(type: Jar, dependsOn: javadoc) { 73 | archiveClassifier.set 'javadoc' 74 | from javadoc, 'LICENSE' 75 | } 76 | 77 | publishing { 78 | publications { 79 | mavenJava(MavenPublication) { 80 | artifact(jar) { 81 | builtBy jar 82 | } 83 | artifact(sourcesJar) { 84 | builtBy sourcesJar 85 | } 86 | artifact(javadocJar) { 87 | builtBy javadocJar 88 | } 89 | } 90 | } 91 | repositories { 92 | mavenLocal() 93 | } 94 | } 95 | 96 | idea.module.inheritOutputDirs = true 97 | -------------------------------------------------------------------------------- /changelog.txt: -------------------------------------------------------------------------------- 1 | 0.6.0 2 | Changed: 3 | Update Gradle to 7.5.1 4 | Update LWJGL from 3.2.3 to 3.3.1 5 | Update LICENSE 6 | Use SWGL 7 | Removed: 8 | Removed FastUtil 9 | Issues addressed 10 | You can play game with OpenGL 3.0+ now!!! 11 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Over-Run/Minecraft2D/e56b400864d7cdc766f652a3863cfa2a8e40f270/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /jitpack.yml: -------------------------------------------------------------------------------- 1 | jdk: 2 | - openjdk17 3 | -------------------------------------------------------------------------------- /level-version.md: -------------------------------------------------------------------------------- 1 | # Level Versions 2 | 3 | If numbers are different, they are not compatible. 4 | If not compatible, The JVM will throw an exception!!! 5 | 6 | | version | level-version | 7 | |:-----------------:|:--------------------:| 8 | | 200913-pa-build.0 | -3271922479732447666 | 9 | | 200919-pa-build.0 | -465355383687602998 | 10 | | 200926-pa-build.0 | 1359564638753160278 | 11 | | 0.4.0 | 1 | 12 | | 0.5.0 | 2 | 13 | | 0.6.0 | 3 | 14 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | pluginManagement { 2 | repositories { 3 | mavenCentral() 4 | gradlePluginPortal() 5 | maven { url 'https://maven.aliyun.com/repository/public'} 6 | maven { url 'https://maven.aliyun.com/repository/gradle-plugin' } 7 | } 8 | } 9 | 10 | rootProject.name = 'Minecraft2D' 11 | -------------------------------------------------------------------------------- /src/main/java/io/github/overrun/mc2d/Main.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2020-2022 Overrun Organization 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package io.github.overrun.mc2d; 26 | 27 | import io.github.overrun.mc2d.client.GameVersion; 28 | import io.github.overrun.mc2d.client.Mc2dClient; 29 | import org.overrun.swgl.core.util.LogFactory9; 30 | import org.slf4j.Logger; 31 | 32 | /** 33 | * @author squid233 34 | * @since 2021/01/07 35 | */ 36 | public final class Main { 37 | // todo: mods and options screen 38 | 39 | private static final Logger logger = LogFactory9.getLogger(); 40 | 41 | public static void main(String[] args) { 42 | logger.info("Loading for game Minecraft2D {}", GameVersion.versionString()); 43 | try (var client = Mc2dClient.getInstance()) { 44 | client.init(); 45 | client.run(); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/io/github/overrun/mc2d/client/GameVersion.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2022 Overrun Organization 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package io.github.overrun.mc2d.client; 26 | 27 | import com.google.gson.Gson; 28 | import com.google.gson.GsonBuilder; 29 | import com.google.gson.TypeAdapter; 30 | import com.google.gson.stream.JsonReader; 31 | import com.google.gson.stream.JsonWriter; 32 | import org.overrun.swgl.core.util.LogFactory9; 33 | import org.slf4j.Logger; 34 | 35 | import java.io.IOException; 36 | import java.io.InputStreamReader; 37 | import java.nio.charset.StandardCharsets; 38 | import java.util.Objects; 39 | 40 | /** 41 | * The game version info. 42 | * 43 | * @author squid233 44 | * @since 0.6.0 45 | */ 46 | public final class GameVersion { 47 | private static final Logger logger = LogFactory9.getLogger(); 48 | private static final GameVersion INSTANCE; 49 | private static final Gson GSON = new GsonBuilder().registerTypeAdapter(GameVersion.class, new Serializer()).create(); 50 | private String versionString = null; 51 | private int versionNumber = 0; 52 | private long worldVersion = 0L; 53 | private int protocolVersion = 0; 54 | 55 | /** 56 | * The serializer. 57 | * 58 | * @author squid233 59 | * @since 0.6.0 60 | */ 61 | private static final class Serializer extends TypeAdapter { 62 | @Override 63 | public void write(JsonWriter out, GameVersion value) { 64 | throw new UnsupportedOperationException(); 65 | } 66 | 67 | @Override 68 | public GameVersion read(JsonReader in) throws IOException { 69 | var ver = new GameVersion(); 70 | in.beginObject(); 71 | while (in.hasNext()) { 72 | switch (in.nextName()) { 73 | case "versionString" -> ver.versionString = in.nextString(); 74 | case "versionNumber" -> ver.versionNumber = in.nextInt(); 75 | case "worldVersion" -> ver.worldVersion = in.nextLong(); 76 | case "protocolVersion" -> ver.protocolVersion = in.nextInt(); 77 | } 78 | } 79 | in.endObject(); 80 | return ver; 81 | } 82 | } 83 | 84 | static { 85 | GameVersion version; 86 | try (var reader = new InputStreamReader( 87 | Objects.requireNonNull(GameVersion.class.getClassLoader().getResourceAsStream("version.json")), 88 | StandardCharsets.UTF_8)) { 89 | version = GSON.fromJson(reader, GameVersion.class); 90 | } catch (Exception e) { 91 | logger.error("Error reading game version", e); 92 | version = new GameVersion(); 93 | } 94 | INSTANCE = version; 95 | } 96 | 97 | /** 98 | * Gets the version string. 99 | * 100 | * @return the version string 101 | */ 102 | public static String versionString() { 103 | return INSTANCE.versionString; 104 | } 105 | 106 | /** 107 | * Gets the version number. 108 | * 109 | * @return The version number, negative for snapshot; otherwise release. 110 | */ 111 | public static int versionNumber() { 112 | return INSTANCE.versionNumber; 113 | } 114 | 115 | /** 116 | * Gets the world version. 117 | * 118 | * @return the world version 119 | */ 120 | public static long worldVersion() { 121 | return INSTANCE.worldVersion; 122 | } 123 | 124 | /** 125 | * Gets the protocol version. 126 | * 127 | * @return the protocol version 128 | */ 129 | public static int protocolVersion() { 130 | return INSTANCE.protocolVersion; 131 | } 132 | } 133 | -------------------------------------------------------------------------------- /src/main/java/io/github/overrun/mc2d/client/Keyboard.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2020-2022 Overrun Organization 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package io.github.overrun.mc2d.client; 26 | 27 | import static org.lwjgl.glfw.GLFW.*; 28 | 29 | /** 30 | * @author squid233 31 | * @since 2021/01/31 32 | */ 33 | public final class Keyboard { 34 | public static boolean isKeyPress(int key) { 35 | return glfwGetKey(glfwGetCurrentContext(), key) == GLFW_PRESS; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/io/github/overrun/mc2d/client/gui/AbstractParentElement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2020-2022 Overrun Organization 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package io.github.overrun.mc2d.client.gui; 26 | 27 | /** 28 | * @author squid233 29 | * @since 2021/01/25 30 | */ 31 | public abstract class AbstractParentElement extends DrawableHelper implements ParentElement { } 32 | -------------------------------------------------------------------------------- /src/main/java/io/github/overrun/mc2d/client/gui/Drawable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2020-2022 Overrun Organization 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package io.github.overrun.mc2d.client.gui; 26 | 27 | /** 28 | * @author squid233 29 | * @since 2021/01/25 30 | */ 31 | public interface Drawable { 32 | void render(int mouseX, int mouseY, float delta); 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/io/github/overrun/mc2d/client/gui/Element.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2020-2022 Overrun Organization 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package io.github.overrun.mc2d.client.gui; 26 | 27 | /** 28 | * @author squid233 29 | * @since 2021/01/25 30 | */ 31 | public interface Element { 32 | default boolean mousePressed(int mouseX, int mouseY, int button) { 33 | return false; 34 | } 35 | 36 | default boolean keyPressed(int key, int scancode, int mods) { 37 | return false; 38 | } 39 | 40 | default boolean isMouseOver(int mouseX, int mouseY) { 41 | return false; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/io/github/overrun/mc2d/client/gui/ParentElement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2020-2022 Overrun Organization 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package io.github.overrun.mc2d.client.gui; 26 | 27 | import java.util.Iterator; 28 | import java.util.List; 29 | import java.util.Optional; 30 | 31 | /** 32 | * @author squid233 33 | * @since 2021/01/25 34 | */ 35 | public interface ParentElement extends Element { 36 | List children(); 37 | 38 | default Optional hoveredElement(int mouseX, int mouseY) { 39 | Iterator iterator = children().iterator(); 40 | Element element; 41 | do { 42 | if (!iterator.hasNext()) { 43 | return Optional.empty(); 44 | } 45 | element = iterator.next(); 46 | } while (!element.isMouseOver(mouseX, mouseY)); 47 | return Optional.of(element); 48 | } 49 | 50 | @Override 51 | default boolean mousePressed(int mouseX, int mouseY, int button) { 52 | Iterator iterator = children().iterator(); 53 | Element element; 54 | do { 55 | if (!iterator.hasNext()) { 56 | return false; 57 | } 58 | element = iterator.next(); 59 | } while (!element.mousePressed(mouseX, mouseY, button)); 60 | return true; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/io/github/overrun/mc2d/client/gui/screen/DirtScreen.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2020-2022 Overrun Organization 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package io.github.overrun.mc2d.client.gui.screen; 26 | 27 | import io.github.overrun.mc2d.text.IText; 28 | import io.github.overrun.mc2d.text.TextColor; 29 | 30 | /** 31 | * @author squid233 32 | * @since 2021/01/26 33 | */ 34 | public class DirtScreen extends Screen { 35 | protected DirtScreen(IText title) { 36 | super(title); 37 | } 38 | 39 | @Override 40 | public void render(int mouseX, int mouseY, float delta) { 41 | renderBackgroundTexture(); 42 | super.render(mouseX, mouseY, delta); 43 | drawCenteredText(textRenderer, title.withColor(TextColor.WHITE), width >> 1, 50); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/io/github/overrun/mc2d/client/gui/screen/TickableElement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2020-2022 Overrun Organization 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package io.github.overrun.mc2d.client.gui.screen; 26 | 27 | /** 28 | * @author squid233 29 | * @since 2021/01/26 30 | */ 31 | public interface TickableElement { 32 | void tick(); 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/io/github/overrun/mc2d/client/gui/screen/TitleScreen.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2020-2022 Overrun Organization 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package io.github.overrun.mc2d.client.gui.screen; 26 | 27 | import io.github.overrun.mc2d.client.Mc2dClient; 28 | import io.github.overrun.mc2d.client.gui.screen.world.LoadingWorldScreen; 29 | import io.github.overrun.mc2d.client.gui.widget.ButtonWidget; 30 | import io.github.overrun.mc2d.text.IText; 31 | import io.github.overrun.mc2d.util.Identifier; 32 | 33 | import static org.lwjgl.glfw.GLFW.glfwGetCurrentContext; 34 | import static org.lwjgl.glfw.GLFW.glfwSetWindowShouldClose; 35 | import static org.lwjgl.opengl.GL11.glColor4f; 36 | 37 | /** 38 | * @author squid233 39 | * @since 2021/01/25 40 | */ 41 | public final class TitleScreen extends Screen { 42 | public static final Identifier LOGO = new Identifier("textures/gui/logo.png"); 43 | 44 | public TitleScreen() { 45 | super(IText.EMPTY); 46 | } 47 | 48 | @Override 49 | public void init(Mc2dClient client, int width, int height) { 50 | super.init(client, width, height); 51 | addButton(new ButtonWidget((width - 200) / 2, 52 | (height - 20) / 2 - 25, 53 | 200, 54 | 20, 55 | IText.translatable("text.screen.singleplayer"), 56 | b -> client.openScreen(new LoadingWorldScreen()))); 57 | addButton(new ButtonWidget((width - 200) / 2, 58 | (height - 20) / 2, 59 | 200, 60 | 20, 61 | IText.translatable("text.screen.multiplayer"), 62 | b -> { 63 | })).active = false; 64 | addButton(new ButtonWidget((width - 200) / 2, 65 | (height - 20) / 2 + 25, 66 | 200, 67 | 20, 68 | IText.translatable("text.screen.mods"), 69 | b -> { 70 | })).active = false; 71 | addButton(new ButtonWidget((width - 200) / 2, 72 | (height - 20) / 2 + 50, 73 | 100, 74 | 20, 75 | IText.translatable("text.screen.options"), 76 | b -> { 77 | })).active = false; 78 | addButton(new ButtonWidget(width / 2, 79 | (height - 20) / 2 + 50, 80 | 100, 81 | 20, 82 | IText.translatable("text.screen.exit_game"), 83 | b -> glfwSetWindowShouldClose(glfwGetCurrentContext(), true))); 84 | } 85 | 86 | @Override 87 | public void render(int mouseX, int mouseY, float delta) { 88 | renderBackground(); 89 | super.render(mouseX, mouseY, delta); 90 | glColor4f(1, 1, 1, 1); 91 | client.getTextureManager().bindTexture(LOGO); 92 | drawTexture(width * .5 - 101, 15, 202, 42); 93 | textRenderer.draw(0, height - client.textRenderer.drawHeight(), Mc2dClient.VERSION_TEXT); 94 | } 95 | 96 | @Override 97 | public boolean shouldCloseOnEsc() { 98 | return false; 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /src/main/java/io/github/overrun/mc2d/client/gui/screen/ingame/PauseScreen.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2020-2022 Overrun Organization 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package io.github.overrun.mc2d.client.gui.screen.ingame; 26 | 27 | import io.github.overrun.mc2d.client.Mc2dClient; 28 | import io.github.overrun.mc2d.client.gui.screen.Screen; 29 | import io.github.overrun.mc2d.client.gui.screen.world.SavingWorldScreen; 30 | import io.github.overrun.mc2d.client.gui.widget.ButtonWidget; 31 | import io.github.overrun.mc2d.text.IText; 32 | import io.github.overrun.mc2d.text.Style; 33 | import io.github.overrun.mc2d.text.TextColor; 34 | 35 | /** 36 | * @author squid233 37 | * @since 2021/01/26 38 | */ 39 | public final class PauseScreen extends Screen { 40 | private final Screen parent; 41 | private final double orgTimescale; 42 | 43 | public PauseScreen(Screen parent, double orgTimescale) { 44 | super(IText.translatable("text.screen.title.pausing")); 45 | this.parent = parent; 46 | this.orgTimescale = orgTimescale; 47 | } 48 | 49 | @Override 50 | public void init(Mc2dClient client, int width, int height) { 51 | super.init(client, width, height); 52 | addButton(new ButtonWidget(width / 2 - 150, 53 | 80, 54 | 300, 55 | 20, 56 | IText.translatable("text.screen.back_to_game"), 57 | b -> onClose())); 58 | addButton(new ButtonWidget(width / 2 - 150, 59 | 110, 60 | 300, 61 | 20, 62 | IText.translatable("text.screen.save_and_back"), 63 | b -> client.openScreen(new SavingWorldScreen()))); 64 | } 65 | 66 | @Override 67 | public void onOpen() { 68 | super.onOpen(); 69 | if (client.world != null) { 70 | client.world.save(); 71 | } 72 | } 73 | 74 | @Override 75 | public void render(int mouseX, int mouseY, float delta) { 76 | renderBackground(); 77 | super.render(mouseX, mouseY, delta); 78 | drawCenteredText(textRenderer, title.setStyle(Style.EMPTY.withColor(TextColor.WHITE)), width / 2, 50); 79 | } 80 | 81 | @Override 82 | public void onClose() { 83 | super.onClose(); 84 | if (client.world != null) { 85 | client.world.timer.timescale = orgTimescale; 86 | } 87 | client.openScreen(parent); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /src/main/java/io/github/overrun/mc2d/client/gui/screen/world/LoadingWorldScreen.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2020-2022 Overrun Organization 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package io.github.overrun.mc2d.client.gui.screen.world; 26 | 27 | import io.github.overrun.mc2d.client.gui.screen.DirtScreen; 28 | import io.github.overrun.mc2d.client.world.render.WorldRenderer; 29 | import io.github.overrun.mc2d.text.IText; 30 | import io.github.overrun.mc2d.util.Utils; 31 | import io.github.overrun.mc2d.world.World; 32 | import io.github.overrun.mc2d.world.entity.EntityTypes; 33 | import io.github.overrun.mc2d.world.entity.player.PlayerEntity; 34 | import org.overrun.swgl.core.util.LogFactory9; 35 | import org.slf4j.Logger; 36 | 37 | /** 38 | * @author squid233 39 | * @since 2021/01/26 40 | */ 41 | public final class LoadingWorldScreen extends DirtScreen { 42 | private static final Logger logger = LogFactory9.getLogger(); 43 | 44 | public LoadingWorldScreen() { 45 | super(IText.translatable("text.screen.world.loading")); 46 | } 47 | 48 | @Override 49 | public void tick() { 50 | super.tick(); 51 | try { 52 | client.world = new World(256, 128); 53 | if (!client.world.load()) { 54 | client.world.genTerrain(); 55 | } else { 56 | client.player = (PlayerEntity) client.world.getEntity(PlayerEntity.generateUUID("Player0")); 57 | } 58 | // TODO: 2022/9/6 Username 59 | if (client.player == null) { 60 | client.player = Utils.also(client.world.spawnEntity(EntityTypes.PLAYER), e -> 61 | e.setUUID(PlayerEntity.generateUUID("Player0")) 62 | ); 63 | } 64 | client.player.setDisplayName("Player0"); 65 | client.worldRenderer = new WorldRenderer(client, client.world); 66 | client.world.addListener(client.worldRenderer); 67 | onClose(); 68 | } catch (Exception e) { 69 | client.world = null; 70 | logger.error("Exception occurred loading world!", e); 71 | } 72 | } 73 | 74 | @Override 75 | public void onClose() { 76 | super.onClose(); 77 | client.openScreen(null); 78 | } 79 | 80 | @Override 81 | public boolean shouldCloseOnEsc() { 82 | return false; 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/main/java/io/github/overrun/mc2d/client/gui/screen/world/SavingWorldScreen.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2020-2022 Overrun Organization 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package io.github.overrun.mc2d.client.gui.screen.world; 26 | 27 | import io.github.overrun.mc2d.client.gui.screen.DirtScreen; 28 | import io.github.overrun.mc2d.client.gui.screen.TitleScreen; 29 | import io.github.overrun.mc2d.text.IText; 30 | 31 | /** 32 | * @author squid233 33 | * @since 2021/01/26 34 | */ 35 | public final class SavingWorldScreen extends DirtScreen { 36 | public SavingWorldScreen() { 37 | super(IText.translatable("text.screen.world.saving")); 38 | } 39 | 40 | @Override 41 | public void tick() { 42 | super.tick(); 43 | if (client.world != null) { 44 | client.world.save(); 45 | } 46 | onClose(); 47 | } 48 | 49 | @Override 50 | public void onClose() { 51 | super.onClose(); 52 | client.openScreen(new TitleScreen()); 53 | client.world = null; 54 | client.worldRenderer.close(); 55 | client.worldRenderer = null; 56 | client.player = null; 57 | } 58 | 59 | @Override 60 | public boolean shouldCloseOnEsc() { 61 | return false; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/io/github/overrun/mc2d/client/gui/widget/AbstractPressableButtonWidget.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2020-2022 Overrun Organization 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package io.github.overrun.mc2d.client.gui.widget; 26 | 27 | import io.github.overrun.mc2d.text.IText; 28 | 29 | /** 30 | * @author squid233 31 | * @since 2021/01/25 32 | */ 33 | public abstract class AbstractPressableButtonWidget extends AbstractButtonWidget { 34 | public AbstractPressableButtonWidget(int x, int y, int width, int height, IText message) { 35 | super(x, y, width, height, message); 36 | } 37 | 38 | public abstract void onPress(); 39 | 40 | @Override 41 | public void onClick(int mouseX, int mouseY) { 42 | super.onClick(mouseX, mouseY); 43 | onPress(); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/io/github/overrun/mc2d/client/gui/widget/ButtonWidget.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2020-2022 Overrun Organization 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package io.github.overrun.mc2d.client.gui.widget; 26 | 27 | import io.github.overrun.mc2d.text.IText; 28 | 29 | /** 30 | * @author squid233 31 | * @since 2021/01/25 32 | */ 33 | public class ButtonWidget extends AbstractPressableButtonWidget { 34 | public static final TooltipSupplier EMPTY = (button, mouseX, mouseY) -> { 35 | }; 36 | protected final PressAction onPress; 37 | protected final TooltipSupplier tooltipSupplier; 38 | 39 | public ButtonWidget(int x, int y, int width, int height, IText message, PressAction onPress) { 40 | this(x, y, width, height, message, onPress, EMPTY); 41 | } 42 | 43 | public ButtonWidget(int x, int y, int width, int height, IText message, PressAction onPress, TooltipSupplier tooltipSupplier) { 44 | super(x, y, width, height, message); 45 | this.onPress = onPress; 46 | this.tooltipSupplier = tooltipSupplier; 47 | } 48 | 49 | @Override 50 | public void onPress() { 51 | onPress.onPress(this); 52 | } 53 | 54 | @Override 55 | public void renderButton(int mouseX, int mouseY) { 56 | super.renderButton(mouseX, mouseY); 57 | if (isHovered()) { 58 | renderToolTip(mouseX, mouseY); 59 | } 60 | } 61 | 62 | @Override 63 | public void renderToolTip(int mouseX, int mouseY) { 64 | super.renderToolTip(mouseX, mouseY); 65 | tooltipSupplier.onTooltip(this, mouseX, mouseY); 66 | } 67 | 68 | public interface TooltipSupplier { 69 | void onTooltip(ButtonWidget button, int mouseX, int mouseY); 70 | } 71 | 72 | public interface PressAction { 73 | void onPress(ButtonWidget button); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/main/java/io/github/overrun/mc2d/client/model/BlockModelMgr.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2022 Overrun Organization 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package io.github.overrun.mc2d.client.model; 26 | 27 | import io.github.overrun.mc2d.client.Mc2dClient; 28 | import io.github.overrun.mc2d.mod.ModLoader; 29 | import io.github.overrun.mc2d.util.Identifier; 30 | import io.github.overrun.mc2d.util.registry.BaseRegistry; 31 | import io.github.overrun.mc2d.util.registry.Registry; 32 | import io.github.overrun.mc2d.world.block.BlockType; 33 | import org.overrun.swgl.core.asset.tex.TextureParam; 34 | import org.overrun.swgl.core.asset.tex.atlas.SpriteInfo; 35 | import org.overrun.swgl.core.asset.tex.atlas.TextureAtlas; 36 | import org.overrun.swgl.core.io.IFileProvider; 37 | 38 | import java.util.ArrayList; 39 | import java.util.Comparator; 40 | import java.util.HashSet; 41 | import java.util.function.Function; 42 | 43 | import static org.lwjgl.opengl.GL11C.GL_NEAREST; 44 | 45 | /** 46 | * @author squid233 47 | * @since 0.6.0 48 | */ 49 | public class BlockModelMgr { 50 | private static final Comparator COMPARATOR = 51 | Comparator.comparingInt((SpriteInfo info) -> -info.height()).thenComparingInt(info -> -info.width()); 52 | public static final Identifier BLOCK_ATLAS = new Identifier("textures/block-atlas"); 53 | private static TextureAtlas blockAtlas; 54 | 55 | // public static final Identifier ITEM_ATLAS = new Identifier("textures/item-atlas"); 56 | // private static TextureAtlas itemAtlas; 57 | 58 | public static String blockTexture(Identifier id) { 59 | return "assets/" + id.getNamespace() + "/textures/" + id.getPath() + ".png"; 60 | } 61 | 62 | // public static String itemTexture(Identifier id) { 63 | // return "assets/" + id.getNamespace() + "/" + "textures/item/" + id.getPath() + ".png"; 64 | // } 65 | 66 | private static TextureAtlas loadAtlas(Function function, 67 | BaseRegistry registry, 68 | Identifier id) { 69 | var atlas = new TextureAtlas(0); 70 | var textures = new HashSet(); 71 | var infoList = new ArrayList(); 72 | for (var e : registry) { 73 | var tex = ((BlockType) e.getValue()).getTexture(); 74 | if (tex != null) { 75 | textures.add(tex); 76 | } 77 | } 78 | for (var tex : textures) { 79 | infoList.add(new SpriteInfo( 80 | function.apply(tex), 81 | tex.isVanilla() ? IFileProvider.ofCaller() : IFileProvider.of(ModLoader.getLoader(tex.getNamespace())), 82 | 16, 83 | 16) 84 | ); 85 | } 86 | infoList.sort(COMPARATOR); 87 | atlas.extraParam(new TextureParam().minFilter(GL_NEAREST).magFilter(GL_NEAREST)); 88 | atlas.load(infoList); 89 | Mc2dClient.getInstance().getTextureManager().addTexture(id, atlas.getId()); 90 | return atlas; 91 | } 92 | 93 | public static void loadAtlas() { 94 | blockAtlas = loadAtlas(BlockModelMgr::blockTexture, Registry.BLOCK, BLOCK_ATLAS); 95 | // itemAtlas = loadAtlas(BlockModelMgr::itemTexture, Registry.ITEM, ITEM_ATLAS); 96 | } 97 | 98 | public static TextureAtlas getBlockAtlas() { 99 | return blockAtlas; 100 | } 101 | 102 | // public static TextureAtlas getItemAtlas() { 103 | // return itemAtlas; 104 | // } 105 | } 106 | -------------------------------------------------------------------------------- /src/main/java/io/github/overrun/mc2d/client/model/Cube.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2022 Overrun Organization 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package io.github.overrun.mc2d.client.model; 26 | 27 | import static org.lwjgl.opengl.GL11.*; 28 | 29 | /** 30 | * @author squid233 31 | * @since 0.6.0 32 | */ 33 | public class Cube implements AutoCloseable { 34 | private final Polygon[] polygons; 35 | private boolean compiled = false; 36 | private int list; 37 | private double rotateZ; 38 | private double x, y, z; 39 | 40 | public Cube(Polygon... polygons) { 41 | this.polygons = polygons; 42 | } 43 | 44 | private void compile() { 45 | list = glGenLists(1); 46 | glNewList(list, GL_COMPILE); 47 | glBegin(GL_QUADS); 48 | for (var p : polygons) { 49 | p.render(); 50 | } 51 | glEnd(); 52 | glEndList(); 53 | } 54 | 55 | public void render() { 56 | if (!compiled) { 57 | compile(); 58 | compiled = true; 59 | } 60 | glPushMatrix(); 61 | glTranslated(x, y, z); 62 | glRotated(rotateZ, 0, 0, 1); 63 | glCallList(list); 64 | glPopMatrix(); 65 | } 66 | 67 | public Cube setPosition(double x, double y, double z) { 68 | this.x = x; 69 | this.y = y; 70 | this.z = z; 71 | return this; 72 | } 73 | 74 | public Cube setRotateZ(double ang) { 75 | return setRotateZDeg(Math.toDegrees(ang)); 76 | } 77 | 78 | public Cube setRotateZDeg(double ang) { 79 | rotateZ = ang; 80 | return this; 81 | } 82 | 83 | @Override 84 | public void close() { 85 | if (list != 0 && glIsList(list)) { 86 | glDeleteLists(list, 1); 87 | } 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /src/main/java/io/github/overrun/mc2d/client/model/EntityModel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2022 Overrun Organization 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package io.github.overrun.mc2d.client.model; 26 | 27 | /** 28 | * A entity model. 29 | * 30 | * @author squid233 31 | * @since 0.6.0 32 | */ 33 | public class EntityModel { 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/io/github/overrun/mc2d/client/model/EntityModelMgr.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2022 Overrun Organization 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package io.github.overrun.mc2d.client.model; 26 | 27 | /** 28 | * The entity model manager. 29 | * 30 | * @author squid233 31 | * @since 0.6.0 32 | */ 33 | public class EntityModelMgr { 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/io/github/overrun/mc2d/client/model/Polygon.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2022 Overrun Organization 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package io.github.overrun.mc2d.client.model; 26 | 27 | import org.lwjgl.opengl.GL11; 28 | 29 | /** 30 | * @author squid233 31 | * @since 0.6.0 32 | */ 33 | public class Polygon { 34 | private final Vertex[] vertices; 35 | 36 | public Polygon(Vertex... vertices) { 37 | this.vertices = vertices; 38 | } 39 | 40 | public void render() { 41 | for (var v : vertices) { 42 | GL11.glTexCoord2f(v.u(), v.v()); 43 | GL11.glVertex3f(v.x(), v.y(), v.z()); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/io/github/overrun/mc2d/client/model/Vertex.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2022 Overrun Organization 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package io.github.overrun.mc2d.client.model; 26 | 27 | /** 28 | * @author squid233 29 | * @since 0.6.0 30 | */ 31 | public class Vertex { 32 | private final float x, y, z; 33 | private final float u, v; 34 | 35 | public Vertex(float x, float y, float z, float u, float v) { 36 | this.x = x; 37 | this.y = y; 38 | this.z = z; 39 | this.u = u; 40 | this.v = v; 41 | } 42 | 43 | public Vertex(float x, float y, float z) { 44 | this(x, y, z, 0f, 0f); 45 | } 46 | 47 | public Vertex(Vertex vertex) { 48 | x = vertex.x; 49 | y = vertex.y; 50 | z = vertex.z; 51 | u = vertex.u; 52 | v = vertex.v; 53 | } 54 | 55 | public Vertex remap(float u, float v) { 56 | return new Vertex(x(), y(), z(), u, v); 57 | } 58 | 59 | public Vertex position(float x, float y, float z) { 60 | return new Vertex(x, y, z, u(), v()); 61 | } 62 | 63 | public Vertex x(float x) { 64 | return new Vertex(x, y(), z()); 65 | } 66 | 67 | public Vertex y(float y) { 68 | return new Vertex(x(), y, z()); 69 | } 70 | 71 | public Vertex z(float z) { 72 | return new Vertex(x(), y(), z); 73 | } 74 | 75 | public float x() { 76 | return x; 77 | } 78 | 79 | public float y() { 80 | return y; 81 | } 82 | 83 | public float z() { 84 | return z; 85 | } 86 | 87 | public float u() { 88 | return u; 89 | } 90 | 91 | public float v() { 92 | return v; 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /src/main/java/io/github/overrun/mc2d/client/render/ItemRenderer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2022 Overrun Organization 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package io.github.overrun.mc2d.client.render; 26 | 27 | import io.github.overrun.mc2d.client.Mc2dClient; 28 | import io.github.overrun.mc2d.client.TextRenderer; 29 | import io.github.overrun.mc2d.client.model.BlockModelMgr; 30 | import io.github.overrun.mc2d.text.TextColor; 31 | import io.github.overrun.mc2d.world.item.ItemStack; 32 | 33 | import static io.github.overrun.mc2d.client.gui.DrawableHelper.drawTexture; 34 | import static org.lwjgl.opengl.GL11.glColor3f; 35 | 36 | /** 37 | * @author squid233 38 | * @since 0.6.0 39 | */ 40 | public class ItemRenderer { 41 | private final Mc2dClient client; 42 | 43 | public ItemRenderer(Mc2dClient client) { 44 | this.client = client; 45 | } 46 | 47 | public void renderItemStack(TextRenderer textRenderer, 48 | ItemStack stack, 49 | double x, double y) { 50 | if (stack.isEmpty()) return; 51 | glColor3f(1, 1, 1); 52 | // todo: give block and item model 53 | client.getTextureManager().bindTexture(BlockModelMgr.BLOCK_ATLAS); 54 | var tex = BlockModelMgr.blockTexture(stack.getItem().getTexture()); 55 | final var atlas = BlockModelMgr.getBlockAtlas(); 56 | drawTexture(x, y, 57 | atlas.getU0(tex), 58 | atlas.getV0(tex), 59 | atlas.getWidth(tex), 60 | atlas.getHeight(tex), 61 | 16, 16, 62 | atlas.getWidth(), 63 | atlas.getHeight()); 64 | if (stack.getCount() > 1) { 65 | var text = String.valueOf(stack.getCount()); 66 | textRenderer.draw((int) (x + 16 - textRenderer.drawWidth(text)), 67 | (int) (y + textRenderer.drawHeight()), 68 | text, 69 | TextColor.WHITE.bgColor(), 70 | TextColor.WHITE.fgColor(), 71 | true); 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/main/java/io/github/overrun/mc2d/client/render/VertexLayouts.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2022 Overrun Organization 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package io.github.overrun.mc2d.client.render; 26 | 27 | import org.overrun.swgl.core.model.VertexFormat; 28 | import org.overrun.swgl.core.model.VertexLayout; 29 | 30 | /** 31 | * The extent of {@link org.overrun.swgl.core.model.BuiltinVertexLayouts swgl layouts}. 32 | * 33 | * @author squid233 34 | * @since 0.6.0 35 | */ 36 | public class VertexLayouts { 37 | public static final VertexLayout T2F_C3UB_V3F = new VertexLayout(VertexFormat.T2F, VertexFormat.C3UB, VertexFormat.V3F); 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/io/github/overrun/mc2d/event/Event.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2020-2022 Overrun Organization 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package io.github.overrun.mc2d.event; 26 | 27 | import java.util.ArrayList; 28 | import java.util.List; 29 | import java.util.function.Function; 30 | 31 | /** 32 | * Lightweight event system. 33 | * 34 | * @param The event type. 35 | * @author squid233 36 | * @since 2021/01/26 37 | */ 38 | public final class Event { 39 | public final List listeners = new ArrayList<>(); 40 | public final Function, T> invokerFactory; 41 | 42 | public Event(Function, T> invokerFactory) { 43 | this.invokerFactory = invokerFactory; 44 | } 45 | 46 | public void register(T listener) { 47 | if (listener != null) { 48 | listeners.add(listener); 49 | } 50 | } 51 | 52 | public T post() { 53 | return invokerFactory.apply(listeners); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/io/github/overrun/mc2d/event/KeyCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2020-2022 Overrun Organization 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package io.github.overrun.mc2d.event; 26 | 27 | import org.lwjgl.glfw.GLFWKeyCallbackI; 28 | 29 | /** 30 | * @author squid233 31 | * @since 2021/01/26 32 | */ 33 | public interface KeyCallback extends GLFWKeyCallbackI { 34 | Event EVENT = new Event<>(listeners -> (window, key, scancode, action, mods) -> { 35 | for (KeyCallback callback : listeners) { 36 | callback.invoke(window, key, scancode, action, mods); 37 | } 38 | }); 39 | 40 | static void post(long window, int key, int scancode, int action, int mods) { 41 | EVENT.post().invoke(window, key, scancode, action, mods); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/io/github/overrun/mc2d/mod/Mod.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2020-2022 Overrun Organization 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package io.github.overrun.mc2d.mod; 26 | 27 | import java.lang.annotation.ElementType; 28 | import java.lang.annotation.Retention; 29 | import java.lang.annotation.RetentionPolicy; 30 | import java.lang.annotation.Target; 31 | 32 | /** 33 | * @author squid233 34 | * @since 2021/01/27 35 | */ 36 | @Retention(RetentionPolicy.RUNTIME) 37 | public @interface Mod { 38 | /** 39 | * Annotate on a field to autofill by the mod instance. 40 | * 41 | * @author squid233 42 | * @since 0.5.0 43 | */ 44 | @Target(ElementType.FIELD) 45 | @Retention(RetentionPolicy.RUNTIME) 46 | @interface Instance { 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/io/github/overrun/mc2d/mod/ModInfoFile.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2022 Overrun Organization 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package io.github.overrun.mc2d.mod; 26 | 27 | import com.google.gson.TypeAdapter; 28 | import com.google.gson.stream.JsonReader; 29 | import com.google.gson.stream.JsonWriter; 30 | 31 | import java.io.IOException; 32 | 33 | /** 34 | * The mod info file format. 35 | * 36 | * @author squid233 37 | * @since 0.6.0 38 | */ 39 | public class ModInfoFile { 40 | private String namespace; 41 | private String name; 42 | private String version; 43 | private String main; 44 | 45 | /** 46 | * The mod info file json serializer. 47 | * 48 | * @author squid233 49 | * @since 0.6.0 50 | */ 51 | public static final class Serializer extends TypeAdapter { 52 | @Override 53 | public void write(JsonWriter out, ModInfoFile value) { 54 | throw new UnsupportedOperationException(); 55 | } 56 | 57 | @Override 58 | public ModInfoFile read(JsonReader in) throws IOException { 59 | var file = new ModInfoFile(); 60 | in.beginObject(); 61 | while (in.hasNext()) { 62 | switch (in.nextName()) { 63 | case "namespace" -> file.namespace = in.nextString(); 64 | case "name" -> file.name = in.nextString(); 65 | case "version" -> file.version = in.nextString(); 66 | case "main" -> file.main = in.nextString(); 67 | } 68 | } 69 | in.endObject(); 70 | return file; 71 | } 72 | } 73 | 74 | public String getNamespace() { 75 | return namespace; 76 | } 77 | 78 | public String getName() { 79 | return name; 80 | } 81 | 82 | public String getVersion() { 83 | return version; 84 | } 85 | 86 | public String getMain() { 87 | return main; 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /src/main/java/io/github/overrun/mc2d/mod/ModInitializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2020-2022 Overrun Organization 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package io.github.overrun.mc2d.mod; 26 | 27 | /** 28 | * The mod entrypoint. 29 | * 30 | *

Example

31 | *
{@code
32 |  * public class MyMod implements ModInitializer {
33 |  *     @Override
34 |  *     public void onInitialize() { }
35 |  * }}
36 | * 37 | * @author squid233 38 | * @since 2021/01/27 39 | */ 40 | @FunctionalInterface 41 | public interface ModInitializer { 42 | void onInitialize(); 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/io/github/overrun/mc2d/mod/ModInstance.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2022 Overrun Organization 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package io.github.overrun.mc2d.mod; 26 | 27 | import java.net.URLClassLoader; 28 | 29 | /** 30 | * A mod instance. 31 | * 32 | * @author squid233 33 | * @since 0.6.0 34 | */ 35 | public record ModInstance(ModInitializer initializer, URLClassLoader classLoader, String name, String version) { 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/io/github/overrun/mc2d/screen/ItemGroupsScreenHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2020-2022 Overrun Organization 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package io.github.overrun.mc2d.screen; 26 | 27 | import io.github.overrun.mc2d.screen.inv.IInventory; 28 | import io.github.overrun.mc2d.screen.inv.PlayerInventory; 29 | import io.github.overrun.mc2d.screen.slot.Slot; 30 | import io.github.overrun.mc2d.world.entity.player.PlayerEntity; 31 | 32 | /** 33 | * @author squid233 34 | * @since 2021/01/25 35 | */ 36 | public final class ItemGroupsScreenHandler extends ScreenHandler { 37 | public final IInventory inventory; 38 | 39 | public ItemGroupsScreenHandler(PlayerInventory playerInventory, IInventory inventory) { 40 | this.inventory = inventory; 41 | // content 42 | for (int i = 0; i < 45; i++) { 43 | addSlot(new Slot(inventory, Slot.CONTAINER_ID0 + i, 8 + i % 9 * 18, 17 + i / 9 * 18)); 44 | } 45 | // hot-bar 46 | for (int i = 0; i < 10; i++) { 47 | addSlot(new Slot(playerInventory, Slot.HOT_BAR_ID0 + i, 8 + i * 18, 111)); 48 | } 49 | } 50 | 51 | @Override 52 | public boolean canUse(PlayerEntity player) { 53 | return inventory.canPlayerUse(player); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/io/github/overrun/mc2d/screen/ScreenHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2020-2022 Overrun Organization 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package io.github.overrun.mc2d.screen; 26 | 27 | import io.github.overrun.mc2d.screen.slot.Slot; 28 | import io.github.overrun.mc2d.world.entity.player.PlayerEntity; 29 | 30 | import java.util.HashMap; 31 | import java.util.Map; 32 | 33 | /** 34 | * @author squid233 35 | * @since 2021/01/25 36 | */ 37 | public abstract class ScreenHandler { 38 | public final Map slots = new HashMap<>(); 39 | 40 | public ScreenHandler() { 41 | } 42 | 43 | public void addSlot(Slot slot) { 44 | slots.put(slot.id(), slot); 45 | } 46 | 47 | public Slot getSlot(int id) { 48 | return slots.get(id); 49 | } 50 | 51 | public boolean canUse(PlayerEntity player) { 52 | return true; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/io/github/overrun/mc2d/screen/inv/IInventory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2022 Overrun Organization 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package io.github.overrun.mc2d.screen.inv; 26 | 27 | import io.github.overrun.mc2d.world.entity.player.PlayerEntity; 28 | import io.github.overrun.mc2d.world.item.ItemConvertible; 29 | import io.github.overrun.mc2d.world.item.ItemStack; 30 | 31 | import java.util.Map; 32 | 33 | /** 34 | * The inventory. 35 | * 36 | * @author squid233 37 | * @since 0.6.0 38 | */ 39 | public interface IInventory { 40 | Map getItems(); 41 | 42 | int size(); 43 | 44 | boolean isEmpty(); 45 | 46 | /** 47 | * Gets the first slot index of the given item, or -1 if not found. 48 | * 49 | * @param item the item 50 | * @return the slot index or -1 51 | */ 52 | int indexOf(ItemConvertible item); 53 | 54 | /** 55 | * Gets the stack at the given slot id. 56 | * 57 | * @param slot the slot id 58 | * @return the stack 59 | */ 60 | ItemStack getStack(int slot); 61 | 62 | /** 63 | * Removes the stack at the given slot id with the specified count. 64 | * 65 | * @param slot the slot id 66 | * @param count The remove count. If {@code count} is less than the original stack, remove all. 67 | * @return the copy of removed stack 68 | */ 69 | ItemStack removeStack(int slot, int count); 70 | 71 | /** 72 | * Removes all items in the stack at the given slot id. 73 | * 74 | * @param slot the slot id 75 | * @return the copy of original stack 76 | */ 77 | ItemStack removeStack(int slot); 78 | 79 | /** 80 | * Replaces the current stack in an inventory slot with the provided stack. 81 | * 82 | * @param slot The inventory slot of which to replace the item stack. 83 | * @param stack The replacing item stack. If the stack is too big for 84 | * this inventory, 85 | * it gets resized to this inventory's maximum amount. 86 | */ 87 | void setStack(int slot, ItemStack stack); 88 | 89 | void clear(); 90 | 91 | void markDirty(); 92 | 93 | boolean canPlayerUse(PlayerEntity player); 94 | } 95 | -------------------------------------------------------------------------------- /src/main/java/io/github/overrun/mc2d/screen/inv/Inventories.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2022 Overrun Organization 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package io.github.overrun.mc2d.screen.inv; 26 | 27 | import io.github.overrun.mc2d.world.item.ItemStack; 28 | 29 | import java.util.Map; 30 | 31 | /** 32 | * @author squid233 33 | * @since 0.6.0 34 | */ 35 | public final class Inventories { 36 | public static ItemStack splitStack(Map map, 37 | int slot, 38 | int count) { 39 | if (count < 1) return ItemStack.ofEmpty(); 40 | var stack = map.get(slot); 41 | if (stack.isEmpty()) return ItemStack.ofEmpty(); 42 | var copy = stack.copy(); 43 | copy.setCount(count); 44 | if (count >= stack.getCount()) { 45 | stack.setCount(0); 46 | } else { 47 | stack.decrement(count); 48 | } 49 | return copy; 50 | } 51 | 52 | public static ItemStack removeStack(Map map, 53 | int slot) { 54 | var stack = map.get(slot); 55 | var copy = stack.copy(); 56 | map.put(slot, ItemStack.ofEmpty()); 57 | return copy; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/io/github/overrun/mc2d/screen/inv/ItemGroupsInventory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2022 Overrun Organization 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package io.github.overrun.mc2d.screen.inv; 26 | 27 | import io.github.overrun.mc2d.screen.slot.Slot; 28 | import io.github.overrun.mc2d.world.entity.player.PlayerEntity; 29 | import io.github.overrun.mc2d.world.item.ItemConvertible; 30 | import io.github.overrun.mc2d.world.item.ItemGroup; 31 | import io.github.overrun.mc2d.world.item.ItemStack; 32 | 33 | import java.util.HashMap; 34 | import java.util.Map; 35 | 36 | /** 37 | * @author squid233 38 | * @since 0.6.0 39 | */ 40 | public class ItemGroupsInventory implements IInventory { 41 | private final Map stacks = new HashMap<>(); 42 | 43 | @Override 44 | public Map getItems() { 45 | stacks.clear(); 46 | for (int i = 0; i < size(); i++) { 47 | stacks.put(Slot.CONTAINER_ID0 + i, ItemGroup.BUILDING_BLOCKS.getStacks().get(i)); 48 | } 49 | return stacks; 50 | } 51 | 52 | @Override 53 | public int size() { 54 | return 45; 55 | } 56 | 57 | @Override 58 | public boolean isEmpty() { 59 | return false; 60 | } 61 | 62 | @Override 63 | public int indexOf(ItemConvertible item) { 64 | for (int i = 0; i < size(); i++) { 65 | if (ItemGroup.BUILDING_BLOCKS.getStacks().get(i).getItem() == item.asItem()) { 66 | return i; 67 | } 68 | } 69 | return -1; 70 | } 71 | 72 | @Override 73 | public ItemStack getStack(int slot) { 74 | getItems(); 75 | return stacks.get(slot); 76 | } 77 | 78 | @Override 79 | public ItemStack removeStack(int slot, int count) { 80 | return removeStack(slot); 81 | } 82 | 83 | @Override 84 | public ItemStack removeStack(int slot) { 85 | return getStack(slot).copy(); 86 | } 87 | 88 | @Override 89 | public void setStack(int slot, ItemStack stack) { 90 | } 91 | 92 | @Override 93 | public void clear() { 94 | } 95 | 96 | @Override 97 | public void markDirty() { 98 | } 99 | 100 | @Override 101 | public boolean canPlayerUse(PlayerEntity player) { 102 | return true; 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /src/main/java/io/github/overrun/mc2d/screen/inv/PlayerInventory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2022 Overrun Organization 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package io.github.overrun.mc2d.screen.inv; 26 | 27 | import io.github.overrun.mc2d.world.entity.player.PlayerEntity; 28 | import io.github.overrun.mc2d.world.item.ItemConvertible; 29 | import io.github.overrun.mc2d.world.item.ItemStack; 30 | 31 | import java.util.HashMap; 32 | import java.util.Map; 33 | 34 | /** 35 | * @author squid233 36 | * @since 0.6.0 37 | */ 38 | public class PlayerInventory implements IInventory { 39 | private final Map stacks = new HashMap<>(size()); 40 | public final PlayerEntity player; 41 | 42 | public PlayerInventory(PlayerEntity player) { 43 | this.player = player; 44 | } 45 | 46 | @Override 47 | public Map getItems() { 48 | return stacks; 49 | } 50 | 51 | @Override 52 | public int size() { 53 | return 10 + 1 + 27 + 4 + 4 + 1; 54 | } 55 | 56 | @Override 57 | public boolean isEmpty() { 58 | for (var stack : stacks.values()) { 59 | if (!stack.isEmpty()) { 60 | return false; 61 | } 62 | } 63 | return true; 64 | } 65 | 66 | @Override 67 | public int indexOf(ItemConvertible item) { 68 | for (var e : stacks.entrySet()) { 69 | if (e.getValue().getItem() == item.asItem()) { 70 | return e.getKey(); 71 | } 72 | } 73 | return -1; 74 | } 75 | 76 | @Override 77 | public ItemStack getStack(int slot) { 78 | return stacks.getOrDefault(slot, ItemStack.ofEmpty()); 79 | } 80 | 81 | @Override 82 | public ItemStack removeStack(int slot, int count) { 83 | var result = Inventories.splitStack(stacks, slot, count); 84 | if (!result.isEmpty()) { 85 | markDirty(); 86 | } 87 | return result; 88 | } 89 | 90 | @Override 91 | public ItemStack removeStack(int slot) { 92 | return Inventories.removeStack(stacks, slot); 93 | } 94 | 95 | @Override 96 | public void setStack(int slot, ItemStack stack) { 97 | stacks.put(slot, stack); 98 | if (stack.getCount() > stack.getMaxCount()) { 99 | stack.setCount(stack.getMaxCount()); 100 | } 101 | markDirty(); 102 | } 103 | 104 | @Override 105 | public void clear() { 106 | stacks.clear(); 107 | } 108 | 109 | @Override 110 | public void markDirty() { 111 | } 112 | 113 | @Override 114 | public boolean canPlayerUse(PlayerEntity player) { 115 | return true; 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /src/main/java/io/github/overrun/mc2d/screen/slot/Slot.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2020-2022 Overrun Organization 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package io.github.overrun.mc2d.screen.slot; 26 | 27 | import io.github.overrun.mc2d.screen.inv.IInventory; 28 | import io.github.overrun.mc2d.world.item.ItemStack; 29 | 30 | /** 31 | * @author squid233 32 | * @since 2021/01/23 33 | */ 34 | public record Slot(IInventory inventory, int id, int x, int y) { 35 | public static final int HOT_BAR_ID0 = 0; 36 | public static final int HOT_BAR_ID1 = 1; 37 | public static final int HOT_BAR_ID2 = 2; 38 | public static final int HOT_BAR_ID3 = 3; 39 | public static final int HOT_BAR_ID4 = 4; 40 | public static final int HOT_BAR_ID5 = 5; 41 | public static final int HOT_BAR_ID6 = 6; 42 | public static final int HOT_BAR_ID7 = 7; 43 | public static final int HOT_BAR_ID8 = 8; 44 | public static final int HOT_BAR_ID9 = 9; 45 | public static final int OFFHAND_ID = 10; 46 | public static final int PLAYER_INV_ID0 = 11; 47 | public static final int CONTAINER_ID0 = 38; 48 | public static final int WEAR_ID0 = 294; 49 | public static final int ARMOR_ID0 = 298; 50 | public static final int FLYING_ID0 = 302; 51 | 52 | public boolean hasStack() { 53 | return !getStack().isEmpty(); 54 | } 55 | 56 | public ItemStack getStack() { 57 | return inventory.getStack(id); 58 | } 59 | 60 | public void setStack(ItemStack stack) { 61 | inventory.setStack(id, stack); 62 | } 63 | 64 | public void markDirty() { 65 | inventory.markDirty(); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/io/github/overrun/mc2d/text/BaseText.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2020-2022 Overrun Organization 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package io.github.overrun.mc2d.text; 26 | 27 | import io.github.overrun.mc2d.util.Language; 28 | 29 | import java.util.HashMap; 30 | import java.util.Map; 31 | import java.util.StringJoiner; 32 | 33 | /** 34 | * @author squid233 35 | * @since 2021/01/29 36 | */ 37 | public abstract class BaseText implements IText { 38 | protected static final Map FORMATTED_MAP = new HashMap<>(); 39 | protected static final Map TRANSLATABLE_MAP = new HashMap<>(); 40 | protected static final Map FORMAT_TRANSLATABLE_MAP = new HashMap<>(); 41 | protected final String text; 42 | protected final boolean translatable; 43 | protected final boolean formatted; 44 | 45 | protected BaseText(String text, boolean translatable, boolean formatted) { 46 | this.text = text; 47 | this.translatable = translatable; 48 | this.formatted = formatted; 49 | } 50 | 51 | @Override 52 | public String asString(Object... args) { 53 | if (translatable) { 54 | if (formatted) return String.format(Language.getByKey(text), args); 55 | return Language.getByKey(text); 56 | } 57 | if (formatted) return String.format(text, args); 58 | return text; 59 | } 60 | 61 | @Override 62 | public String toString() { 63 | return new StringJoiner(", ", BaseText.class.getSimpleName() + "[", "]") 64 | .add("text='" + text + "'") 65 | .add("translatable=" + translatable) 66 | .toString(); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/main/java/io/github/overrun/mc2d/text/IText.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2020-2022 Overrun Organization 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package io.github.overrun.mc2d.text; 26 | 27 | import org.jetbrains.annotations.NotNull; 28 | 29 | /** 30 | * @author squid233 31 | * @since 2021/01/29 32 | */ 33 | public interface IText { 34 | IText EMPTY = literal(""); 35 | 36 | static IText literal(String text) { 37 | return new StyledText(text, false, false); 38 | } 39 | 40 | static IText formatted(String text) { 41 | return BaseText.FORMATTED_MAP.computeIfAbsent(text, s -> new StyledText(s, false, true)); 42 | } 43 | 44 | static IText translatable(String text) { 45 | return BaseText.TRANSLATABLE_MAP.computeIfAbsent(text, s -> new StyledText(s, true, false)); 46 | } 47 | 48 | static IText formatTranslatable(String text) { 49 | return BaseText.FORMAT_TRANSLATABLE_MAP.computeIfAbsent(text, s -> new StyledText(s, true, true)); 50 | } 51 | 52 | /** 53 | * Cast to string. 54 | *

May be a translated text.

55 | * 56 | * @param args the arguments for formatting 57 | * @return The text. 58 | */ 59 | String asString(Object... args); 60 | 61 | default @NotNull Style getStyle() { 62 | return Style.EMPTY; 63 | } 64 | 65 | IText setStyle(Style style); 66 | 67 | IText copy(); 68 | 69 | default IText withColor(TextColor color) { 70 | return setStyle(getStyle().withColor(color)); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/io/github/overrun/mc2d/text/Style.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2020-2022 Overrun Organization 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package io.github.overrun.mc2d.text; 26 | 27 | /** 28 | * @author squid233 29 | * @since 2021/01/29 30 | */ 31 | public final class Style { 32 | public static final Style EMPTY = new Style(TextColor.WHITE); 33 | private final TextColor color; 34 | 35 | private Style(TextColor color) { 36 | this.color = color; 37 | } 38 | 39 | public TextColor getColor() { 40 | return color; 41 | } 42 | 43 | public Style withColor(TextColor color) { 44 | return new Style(color); 45 | } 46 | 47 | @Override 48 | public String toString() { 49 | return "Style{color=" + color + "}"; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/io/github/overrun/mc2d/text/StyledText.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2022 Overrun Organization 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package io.github.overrun.mc2d.text; 26 | 27 | import org.jetbrains.annotations.NotNull; 28 | 29 | import java.util.StringJoiner; 30 | 31 | /** 32 | * A text with {@link Style}. 33 | * 34 | * @author squid233 35 | * @since 0.6.0 36 | */ 37 | public class StyledText extends BaseText { 38 | protected Style style; 39 | 40 | protected StyledText(String text, boolean translatable, boolean formatted, Style style) { 41 | super(text, translatable, formatted); 42 | this.style = style; 43 | } 44 | 45 | protected StyledText(String text, boolean translatable, boolean formatted) { 46 | this(text, translatable, formatted, null); 47 | } 48 | 49 | @Override 50 | public @NotNull Style getStyle() { 51 | return style == null ? Style.EMPTY : style; 52 | } 53 | 54 | @Override 55 | public IText setStyle(Style style) { 56 | var newText = new StyledText(text, translatable, formatted); 57 | newText.style = style; 58 | return newText; 59 | } 60 | 61 | @Override 62 | public IText copy() { 63 | return new StyledText(text, translatable, formatted, style); 64 | } 65 | 66 | @Override 67 | public String toString() { 68 | return new StringJoiner(", ", StyledText.class.getSimpleName() + "[", "]") 69 | .add("text='" + text + "'") 70 | .add("translatable=" + translatable) 71 | .add("style=" + style) 72 | .toString(); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/main/java/io/github/overrun/mc2d/text/TextColor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2020-2022 Overrun Organization 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package io.github.overrun.mc2d.text; 26 | 27 | import io.github.overrun.mc2d.util.Colors; 28 | 29 | /** 30 | * @author squid233 31 | * @since 2021/01/26 32 | */ 33 | public record TextColor(String name, int fgColor, int bgColor) { 34 | public static final TextColor WHITE = new TextColor("white", Colors.WHITE, 0xff3f3f3f); 35 | private static final TextColor[] VALUES = {WHITE}; 36 | 37 | public static TextColor byName(String name, TextColor defaultColor) { 38 | if (name == null) { 39 | return defaultColor; 40 | } 41 | for (TextColor color : TextColor.VALUES) { 42 | if (color.name.equals(name)) { 43 | return color; 44 | } 45 | } 46 | return defaultColor; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/io/github/overrun/mc2d/util/Colors.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2020-2022 Overrun Organization 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package io.github.overrun.mc2d.util; 26 | 27 | /** 28 | * @author squid233 29 | * @since 2021/01/31 30 | */ 31 | public final class Colors { 32 | public static final int WHITE = 0xffffffff; 33 | public static final int BLACK = 0xff000000; 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/io/github/overrun/mc2d/util/GlUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2020-2022 Overrun Organization 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package io.github.overrun.mc2d.util; 26 | 27 | import org.lwjgl.opengl.GL11; 28 | 29 | import static org.lwjgl.opengl.GL11.*; 30 | 31 | /** 32 | * @author squid233 33 | * @since 2021/01/08 34 | */ 35 | public final class GlUtils { 36 | /** 37 | * Draw a rect. 38 | *

If {@code alpha} is {@code true}, you should 39 | * {@link GL11#glEnable(int) enable} 40 | * {@link GL11#GL_BLEND blend} before using.

41 | * 42 | * @param x1 The left top coord x. 43 | * @param y1 The left top coord y. 44 | * @param x2 The right bottom coord x. 45 | * @param y2 The right bottom coord y. 46 | * @param color The color. ARGB if {@code alpha} is {@code true}, else RGB. 47 | * @param alpha The alpha value. 48 | */ 49 | public static void drawRect(double x1, double y1, double x2, double y2, int color, boolean alpha) { 50 | glBegin(GL_LINE_LOOP); 51 | var r = color << 8 >>> 24; 52 | var g = color << 16 >>> 24; 53 | var b = color << 24 >>> 24; 54 | final float inv = 1f / 255f; 55 | if (alpha) { 56 | glColor4f(r * inv, g * inv, b * inv, (color >>> 24) * inv); 57 | } else { 58 | glColor3f(r * inv, g * inv, b * inv); 59 | } 60 | // Left top 61 | glVertex2d(x1, y1); 62 | // Left down 63 | glVertex2d(x1, y2); 64 | // Right down 65 | glVertex2d(x2, y2); 66 | // Right up 67 | glVertex2d(x2, y1); 68 | glEnd(); 69 | } 70 | 71 | public static void fillRect(double x1, double y1, double x2, double y2, int color, boolean alpha) { 72 | glBegin(GL_QUADS); 73 | var r = color << 8 >>> 24; 74 | var g = color << 16 >>> 24; 75 | var b = color << 24 >>> 24; 76 | if (alpha) { 77 | glColor4f(r / 255f, g / 255f, b / 255f, (color >>> 24) / 255f); 78 | } else { 79 | glColor3f(r / 255f, g / 255f, b / 255f); 80 | } 81 | // Left top 82 | glVertex2d(x1, y1); 83 | // Left down 84 | glVertex2d(x1, y2); 85 | // Right down 86 | glVertex2d(x2, y2); 87 | // Right up 88 | glVertex2d(x2, y1); 89 | glEnd(); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/main/java/io/github/overrun/mc2d/util/Identifier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2020-2022 Overrun Organization 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package io.github.overrun.mc2d.util; 26 | 27 | import java.util.Objects; 28 | 29 | /** 30 | * @author squid233 31 | * @since 2021/01/25 32 | */ 33 | public class Identifier { 34 | public static final String DEFAULT = "mc2d"; 35 | private final String namespace; 36 | private final String path; 37 | 38 | protected Identifier(String[] id) { 39 | if (id.length > 1) { 40 | namespace = id[0]; 41 | path = id[1]; 42 | } else { 43 | namespace = DEFAULT; 44 | path = id[0]; 45 | } 46 | } 47 | 48 | public Identifier(String namespace, String path) { 49 | this(new String[]{namespace, path}); 50 | } 51 | 52 | public Identifier(String id) { 53 | this(id.split(":", 2)); 54 | } 55 | 56 | public String getNamespace() { 57 | return namespace; 58 | } 59 | 60 | public String getPath() { 61 | return path; 62 | } 63 | 64 | public String toAssetsPath() { 65 | return "assets/" + getNamespace() + "/" + getPath(); 66 | } 67 | 68 | public boolean isVanilla() { 69 | return DEFAULT.equals(namespace); 70 | } 71 | 72 | @Override 73 | public boolean equals(Object o) { 74 | if (this == o) return true; 75 | if (o == null || getClass() != o.getClass()) return false; 76 | Identifier that = (Identifier) o; 77 | return Objects.equals(getNamespace(), that.getNamespace()) && Objects.equals(getPath(), that.getPath()); 78 | } 79 | 80 | @Override 81 | public int hashCode() { 82 | return Objects.hash(getNamespace(), getPath()); 83 | } 84 | 85 | @Override 86 | public String toString() { 87 | return namespace + ":" + path; 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /src/main/java/io/github/overrun/mc2d/util/ImageReader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2020-2022 Overrun Organization 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package io.github.overrun.mc2d.util; 26 | 27 | import org.jetbrains.annotations.Nullable; 28 | import org.lwjgl.system.MemoryStack; 29 | import org.overrun.swgl.core.io.IFileProvider; 30 | import org.overrun.swgl.core.util.LogFactory9; 31 | import org.slf4j.Logger; 32 | 33 | import java.nio.ByteBuffer; 34 | import java.util.Objects; 35 | 36 | import static org.lwjgl.stb.STBImage.STBI_rgb_alpha; 37 | import static org.lwjgl.stb.STBImage.stbi_load_from_memory; 38 | 39 | /** 40 | * @author squid233 41 | * @since 2021/01/07 42 | */ 43 | public final class ImageReader { 44 | private static final Logger logger = LogFactory9.getLogger(); 45 | 46 | @Nullable 47 | public static ByteBuffer read(String path, ClassLoader loader) { 48 | try (var is = Objects.requireNonNullElse( 49 | loader, 50 | ClassLoader.getSystemClassLoader() 51 | ).getResourceAsStream(path)) { 52 | if (is == null) { 53 | return null; 54 | } 55 | return IFileProvider.of(loader).resToBuffer(path, 8192); 56 | } catch (Exception e) { 57 | logger.error("Catching reading image buffer", e); 58 | return null; 59 | } 60 | } 61 | 62 | /** 63 | * Read an image as {@link ByteBuffer}. 64 | * 65 | * @param path The image path. 66 | * @return Read {@link ByteBuffer}. 67 | */ 68 | @Nullable 69 | public static ByteBuffer read(String path) { 70 | return read(path, ClassLoader.getSystemClassLoader()); 71 | } 72 | 73 | public static NativeImage readImg(String path) { 74 | try (var stack = MemoryStack.stackPush()) { 75 | var img = read(path); 76 | if (img == null) { 77 | return new NativeImage(2, 2, 78 | stack.malloc(16) 79 | .putInt(0xfff800f8) 80 | .putInt(0xff000000) 81 | .putInt(0xff000000) 82 | .putInt(0xfff800f8) 83 | .flip(), false); 84 | } 85 | var xp = stack.mallocInt(1); 86 | var yp = stack.mallocInt(1); 87 | var cp = stack.mallocInt(1); 88 | var buf = stbi_load_from_memory(img, xp, yp, cp, STBI_rgb_alpha); 89 | return new NativeImage(xp.get(0), yp.get(0), buf, true); 90 | } 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /src/main/java/io/github/overrun/mc2d/util/Language.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2020-2022 Overrun Organization 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package io.github.overrun.mc2d.util; 26 | 27 | import io.github.overrun.mc2d.mod.ModLoader; 28 | import org.overrun.swgl.core.util.LogFactory9; 29 | import org.slf4j.Logger; 30 | 31 | import java.io.InputStream; 32 | import java.io.InputStreamReader; 33 | import java.io.Reader; 34 | import java.nio.charset.StandardCharsets; 35 | import java.util.HashMap; 36 | import java.util.Map; 37 | import java.util.Objects; 38 | import java.util.Properties; 39 | 40 | /** 41 | * @author squid233 42 | * @since 2021/01/29 43 | */ 44 | public final class Language { 45 | private static final Logger logger = LogFactory9.getLogger(); 46 | public static final String EN_US = "en_us"; 47 | public static final String ZH_CN = "zh_cn"; 48 | public static String currentLang; 49 | private static final String[] LANGS_STR = {EN_US, ZH_CN}; 50 | private static final Map> LANGS = new HashMap<>(2); 51 | 52 | static { 53 | for (String lang : LANGS_STR) { 54 | LANGS.put(lang, new HashMap<>()); 55 | } 56 | } 57 | 58 | public static void init() { 59 | for (Map.Entry> entry : LANGS.entrySet()) { 60 | try (InputStream is = Objects.requireNonNull( 61 | ClassLoader.getSystemResourceAsStream( 62 | "assets/" + Identifier.DEFAULT + "/lang/" + entry.getKey() + ".lang" 63 | )); 64 | Reader r = new InputStreamReader(is, StandardCharsets.UTF_8) 65 | ) { 66 | Properties prop = new Properties(); 67 | prop.load(r); 68 | putKv(entry.getKey(), prop); 69 | } catch (Throwable t) { 70 | logger.error("Catching loading language file", t); 71 | } 72 | for (String namespace : ModLoader.getMods().keySet()) { 73 | try (InputStream is = Objects.requireNonNull( 74 | ModLoader.getLoader(namespace).getResourceAsStream( 75 | "assets/" + namespace + "/lang/" + entry.getKey() + ".lang" 76 | )); 77 | Reader r = new InputStreamReader(is, StandardCharsets.UTF_8) 78 | ) { 79 | Properties prop = new Properties(); 80 | prop.load(r); 81 | putKv(entry.getKey(), prop); 82 | } catch (Throwable ignored) { 83 | } 84 | } 85 | } 86 | } 87 | 88 | private static void putKv(String lang, Properties prop) { 89 | for (Map.Entry e : prop.entrySet()) { 90 | LANGS.get(lang).put(String.valueOf(e.getKey()), String.valueOf(e.getValue())); 91 | } 92 | } 93 | 94 | public static String getByKey(String key) { 95 | return LANGS.get(currentLang).getOrDefault(key, key); 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /src/main/java/io/github/overrun/mc2d/util/NativeImage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2020-2022 Overrun Organization 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package io.github.overrun.mc2d.util; 26 | 27 | import org.lwjgl.stb.STBImage; 28 | import org.lwjgl.system.MemoryUtil; 29 | 30 | import java.nio.ByteBuffer; 31 | 32 | /** 33 | * @author squid233 34 | * @since 2021/01/08 35 | */ 36 | public record NativeImage(int width, int height, ByteBuffer buffer, boolean useStb) 37 | implements AutoCloseable { 38 | @Override 39 | public void close() { 40 | if (useStb) STBImage.stbi_image_free(buffer); 41 | else MemoryUtil.memFree(buffer); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/io/github/overrun/mc2d/util/Options.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2020-2022 Overrun Organization 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package io.github.overrun.mc2d.util; 26 | 27 | import org.overrun.swgl.core.util.LogFactory9; 28 | import org.slf4j.Logger; 29 | 30 | import java.io.*; 31 | import java.util.Properties; 32 | 33 | import static org.lwjgl.glfw.GLFW.GLFW_KEY_E; 34 | 35 | /** 36 | * @author squid233 37 | * @since 2021/01/23 38 | */ 39 | public final class Options { 40 | private static final Logger logger = LogFactory9.getLogger(); 41 | private static final File FILE = new File("options.txt"); 42 | 43 | /////////////////////////////////////////////////////////////////////////// 44 | // Keybindings 45 | /////////////////////////////////////////////////////////////////////////// 46 | 47 | public static final String KEY_ITEM_GROUP = "key.itemGroup"; 48 | 49 | public static final String LANG = "lang"; 50 | public static final String GUI_SCALE = "guiScale"; 51 | public static final String VSYNC = "vsync"; 52 | 53 | public final Properties options = new Properties(); 54 | 55 | public Options() { 56 | if (!FILE.exists()) { 57 | init(); 58 | save(); 59 | } 60 | try (var r = new BufferedInputStream(new FileInputStream(FILE))) { 61 | options.load(r); 62 | init(); 63 | save(); 64 | } catch (IOException e) { 65 | logger.error("Catching loading options", e); 66 | } 67 | } 68 | 69 | private void init() { 70 | putIfAbsent(KEY_ITEM_GROUP, GLFW_KEY_E); 71 | putIfAbsent(LANG, "en_us"); 72 | putIfAbsent(GUI_SCALE, 2.0); 73 | putIfAbsent(VSYNC, true); 74 | } 75 | 76 | private void putIfAbsent(String key, Object value) { 77 | options.putIfAbsent(key, String.valueOf(value)); 78 | } 79 | 80 | public void save() { 81 | try (var os = new BufferedOutputStream(new FileOutputStream(FILE))) { 82 | options.store(os, null); 83 | } catch (IOException e) { 84 | logger.error("Catching saving options", e); 85 | } 86 | } 87 | 88 | public boolean getB(String key, boolean def) { 89 | var value = options.getProperty(key); 90 | return value == null ? def : Boolean.parseBoolean(value); 91 | } 92 | 93 | public int getI(String key, int def) { 94 | var value = options.getProperty(key); 95 | return value == null ? def : Integer.parseInt(value); 96 | } 97 | 98 | public double getD(String key, double def) { 99 | var value = options.getProperty(key); 100 | return value == null ? def : Double.parseDouble(value); 101 | } 102 | 103 | public String get(String key, String def) { 104 | return options.getProperty(key, def); 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /src/main/java/io/github/overrun/mc2d/util/Utils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2022 Overrun Organization 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package io.github.overrun.mc2d.util; 26 | 27 | import java.util.function.Consumer; 28 | import java.util.function.Function; 29 | 30 | /** 31 | * The utils. 32 | * 33 | * @author squid233 34 | * @since 0.6.0 35 | */ 36 | public final class Utils { 37 | /** 38 | * Perform an action with the instance. 39 | * 40 | * @param t the instance 41 | * @param function the function 42 | * @param the instance type 43 | * @param the return type 44 | * @return the value from the function 45 | */ 46 | public static R with(T t, Function function) { 47 | return function.apply(t); 48 | } 49 | 50 | /** 51 | * Perform an action with the instance. 52 | * 53 | * @param t the instance 54 | * @param consumer the consumer 55 | * @param the instance and return type 56 | * @return the value from the function 57 | */ 58 | public static T also(T t, Consumer consumer) { 59 | consumer.accept(t); 60 | return t; 61 | } 62 | 63 | /** 64 | * Perform an action in a closure with the instance. 65 | * 66 | * @param t the instance 67 | * @param consumer the consumer 68 | * @param the instance type 69 | */ 70 | public static void let(T t, Consumer consumer) { 71 | consumer.accept(t); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/io/github/overrun/mc2d/util/collect/DefaultedList.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2020-2022 Overrun Organization 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package io.github.overrun.mc2d.util.collect; 26 | 27 | import org.jetbrains.annotations.NotNull; 28 | 29 | import java.io.Serial; 30 | import java.util.ArrayList; 31 | import java.util.Collection; 32 | import java.util.function.Supplier; 33 | 34 | /** 35 | * @author squid233 36 | * @since 2021/01/27 37 | */ 38 | public class DefaultedList extends ArrayList { 39 | @Serial 40 | private static final long serialVersionUID = 1L; 41 | private final Supplier defaultSupplier; 42 | private E defaultEntry; 43 | 44 | public DefaultedList(Supplier defaultEntry, int initialCapacity) { 45 | super(initialCapacity); 46 | defaultSupplier = defaultEntry; 47 | } 48 | 49 | public DefaultedList(Supplier defaultEntry) { 50 | defaultSupplier = defaultEntry; 51 | } 52 | 53 | public DefaultedList(Supplier defaultEntry, @NotNull Collection c) { 54 | super(c); 55 | defaultSupplier = defaultEntry; 56 | } 57 | 58 | public E getDefaultEntry() { 59 | if (defaultEntry == null) { 60 | defaultEntry = defaultSupplier.get(); 61 | } 62 | return defaultEntry; 63 | } 64 | 65 | @Override 66 | public E get(int index) { 67 | return index < 0 || index >= size() ? 68 | getDefaultEntry() : 69 | super.get(index); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/main/java/io/github/overrun/mc2d/util/registry/BaseRegistry.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2020-2022 Overrun Organization 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package io.github.overrun.mc2d.util.registry; 26 | 27 | import io.github.overrun.mc2d.util.Identifier; 28 | 29 | import java.util.Map.Entry; 30 | 31 | /** 32 | * The base registry. 33 | * 34 | * @param the registry entry 35 | * @author squid233 36 | * @since 2021/01/27 37 | */ 38 | public abstract class BaseRegistry implements Iterable> { 39 | /** 40 | * Gets the identifier of the given entry. 41 | * 42 | * @param entry the entry 43 | * @return the identifier 44 | */ 45 | public abstract Identifier getId(T entry); 46 | 47 | /** 48 | * Gets the entry by the given identifier. 49 | * 50 | * @param id the identifier 51 | * @return the entry 52 | */ 53 | public abstract T getById(Identifier id); 54 | 55 | /** 56 | * Gets the raw identifier of the given entry. 57 | * 58 | * @param entry the entry 59 | * @return the raw id number 60 | */ 61 | public abstract int getRawId(T entry); 62 | 63 | /** 64 | * Gets the entry by the given raw identifier. 65 | * 66 | * @param rawId the raw id number 67 | * @return the entry 68 | */ 69 | public abstract T getByRawId(int rawId); 70 | 71 | /** 72 | * Register an entry. 73 | * 74 | * @param id the identifier of the entry 75 | * @param entry the entry 76 | * @param the entry instance type 77 | * @return the entry 78 | */ 79 | public abstract R register(Identifier id, R entry); 80 | } 81 | -------------------------------------------------------------------------------- /src/main/java/io/github/overrun/mc2d/util/registry/DefaultedRegistry.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2020-2022 Overrun Organization 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package io.github.overrun.mc2d.util.registry; 26 | 27 | import io.github.overrun.mc2d.util.Identifier; 28 | 29 | import java.util.function.Supplier; 30 | 31 | /** 32 | * The mapped registry with defaulted entry. 33 | * 34 | * @param the registry entry 35 | * @author squid233 36 | * @since 2021/01/27 37 | */ 38 | public class DefaultedRegistry extends MappedRegistry { 39 | private final Supplier defaultSupplier; 40 | private T defaultEntry; 41 | 42 | public DefaultedRegistry(Supplier defaultEntry) { 43 | defaultSupplier = defaultEntry; 44 | } 45 | 46 | public T getDefaultEntry() { 47 | if (defaultEntry == null) { 48 | defaultEntry = defaultSupplier.get(); 49 | } 50 | return defaultEntry; 51 | } 52 | 53 | @Override 54 | public T getById(Identifier id) { 55 | T e; 56 | return ((e = super.getById(id)) != null || id2entry.containsKey(id)) ? e : getDefaultEntry(); 57 | } 58 | 59 | @Override 60 | public T getByRawId(int rawId) { 61 | T e; 62 | return ((e = super.getByRawId(rawId)) != null || entries.containsKey(rawId)) ? e : getDefaultEntry(); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/io/github/overrun/mc2d/util/registry/MappedRegistry.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2022 Overrun Organization 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package io.github.overrun.mc2d.util.registry; 26 | 27 | import io.github.overrun.mc2d.util.Identifier; 28 | import org.jetbrains.annotations.NotNull; 29 | 30 | import java.util.Iterator; 31 | import java.util.LinkedHashMap; 32 | import java.util.Map; 33 | 34 | /** 35 | * The mutable registry with entry mapping. 36 | * 37 | * @param the registry entry 38 | * @author squid233 39 | * @since 0.6.0 40 | */ 41 | public class MappedRegistry extends MutableRegistry { 42 | protected final Map entry2id = new LinkedHashMap<>(); 43 | protected final Map id2entry = new LinkedHashMap<>(); 44 | protected final Map entry2rawId = new LinkedHashMap<>(); 45 | protected final Map entries = new LinkedHashMap<>(); 46 | protected int nextId = 0; 47 | 48 | public int size() { 49 | return entries.size(); 50 | } 51 | 52 | @Override 53 | public Identifier getId(T entry) { 54 | return entry2id.get(entry); 55 | } 56 | 57 | @Override 58 | public T getById(Identifier id) { 59 | return id2entry.get(id); 60 | } 61 | 62 | @Override 63 | public int getRawId(T entry) { 64 | return entry2rawId.get(entry); 65 | } 66 | 67 | @Override 68 | public T getByRawId(int rawId) { 69 | return entries.get(rawId); 70 | } 71 | 72 | @Override 73 | public R register(Identifier id, R entry) { 74 | return add(id, entry); 75 | } 76 | 77 | @Override 78 | public R add(Identifier id, R entry) { 79 | return set(nextId++, id, entry); 80 | } 81 | 82 | @Override 83 | public R set(int rawId, Identifier id, R entry) { 84 | if (id2entry.containsKey(id)) { 85 | throw new IllegalArgumentException("Registry entry is present!"); 86 | } 87 | id2entry.put(id, entry); 88 | entry2id.put(entry, id); 89 | entries.put(rawId, entry); 90 | entry2rawId.put(entry, rawId); 91 | if (rawId > nextId) { 92 | nextId = rawId + 1; 93 | } 94 | return entry; 95 | } 96 | 97 | @Override 98 | public void remove(T entry) { 99 | id2entry.remove(entry2id.get(entry)); 100 | entry2id.remove(entry); 101 | entries.remove(entry2rawId.get(entry)); 102 | entry2rawId.remove(entry); 103 | } 104 | 105 | @NotNull 106 | @Override 107 | public Iterator> iterator() { 108 | return id2entry.entrySet().iterator(); 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /src/main/java/io/github/overrun/mc2d/util/registry/MutableRegistry.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2020-2022 Overrun Organization 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package io.github.overrun.mc2d.util.registry; 26 | 27 | import io.github.overrun.mc2d.util.Identifier; 28 | 29 | /** 30 | * The mutable registry. 31 | * 32 | * @param the registry entry 33 | * @author squid233 34 | * @since 2021/01/27 35 | */ 36 | public abstract class MutableRegistry extends BaseRegistry { 37 | /** 38 | * Add an entry. 39 | * 40 | * @param id the identifier of the entry 41 | * @param entry entry 42 | * @param the entry instance type 43 | * @return the entry 44 | * @implNote Default implementation used {@link #register(Identifier, T)} 45 | */ 46 | public abstract R add(Identifier id, R entry); 47 | 48 | /** 49 | * Set an entry with the given raw identifier and identifier. 50 | * 51 | * @param rawId the raw id number 52 | * @param id the identifier 53 | * @param entry the entry 54 | * @param the entry instance type 55 | * @return the entry 56 | */ 57 | public abstract R set(int rawId, Identifier id, R entry); 58 | 59 | public abstract void remove(T entry); 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/io/github/overrun/mc2d/util/registry/Registry.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2020-2022 Overrun Organization 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package io.github.overrun.mc2d.util.registry; 26 | 27 | import io.github.overrun.mc2d.world.block.BlockType; 28 | import io.github.overrun.mc2d.world.block.Blocks; 29 | import io.github.overrun.mc2d.world.entity.EntityType; 30 | import io.github.overrun.mc2d.world.item.ItemType; 31 | import io.github.overrun.mc2d.world.item.Items; 32 | import io.github.overrun.mc2d.util.Identifier; 33 | 34 | import java.util.function.Supplier; 35 | 36 | /** 37 | * @author squid233 38 | * @since 2021/01/27 39 | */ 40 | public final class Registry { 41 | public static final DefaultedRegistry BLOCK = of(() -> Blocks.AIR); 42 | public static final DefaultedRegistry ITEM = of(() -> Items.AIR); 43 | public static final MappedRegistry> ENTITY = of(); 44 | 45 | public static DefaultedRegistry of(Supplier defaultEntry) { 46 | return new DefaultedRegistry<>(defaultEntry); 47 | } 48 | 49 | public static MappedRegistry of() { 50 | return new MappedRegistry<>(); 51 | } 52 | 53 | public static T register(BaseRegistry registry, Identifier id, T entry) { 54 | return registry.register(id, entry); 55 | } 56 | 57 | public static T register(BaseRegistry registry, String id, T entry) { 58 | return register(registry, new Identifier(id), entry); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/io/github/overrun/mc2d/util/registry/ScreenHandlerRegistry.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2022 Overrun Organization 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package io.github.overrun.mc2d.util.registry; 26 | 27 | /** 28 | * @author squid233 29 | * @since 0.6.0 30 | */ 31 | public class ScreenHandlerRegistry { 32 | // TODO: 2022/9/7 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/io/github/overrun/mc2d/util/shape/VoxelShape.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2020-2022 Overrun Organization 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package io.github.overrun.mc2d.util.shape; 26 | 27 | /** 28 | * @author squid233 29 | * @since 2021/02/03 30 | */ 31 | public final class VoxelShape { 32 | public final int x0, y0, x1, y1; 33 | 34 | public VoxelShape(int x0, int y0, int x1, int y1) { 35 | this.x0 = x0; 36 | this.y0 = y0; 37 | this.x1 = x1; 38 | this.y1 = y1; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/io/github/overrun/mc2d/util/shape/VoxelShapes.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2020-2022 Overrun Organization 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package io.github.overrun.mc2d.util.shape; 26 | 27 | import org.overrun.swgl.core.phys.p2d.AABRect2f; 28 | 29 | /** 30 | * @author squid233 31 | * @since 2021/02/03 32 | */ 33 | public final class VoxelShapes { 34 | private static final AABRect2f FULL_SQUARE = new AABRect2f(0f, 0f, 1f, 1f); 35 | 36 | public static AABRect2f empty() { 37 | return null; 38 | } 39 | 40 | public static AABRect2f fullSquare() { 41 | return FULL_SQUARE; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/io/github/overrun/mc2d/world/Chunk.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2022 Overrun Organization 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package io.github.overrun.mc2d.world; 26 | 27 | /** 28 | * @author squid233 29 | * @since 0.1.0 30 | */ 31 | public class Chunk { 32 | public static final int CHUNK_SIZE = 32; 33 | public static final double CHUNK_SIZE_INV = 1.0 / CHUNK_SIZE; 34 | public static final float CHUNK_SIZE_INVf = 1.0f / CHUNK_SIZE; 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/io/github/overrun/mc2d/world/HitResult.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2022 Overrun Organization 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package io.github.overrun.mc2d.world; 26 | 27 | import io.github.overrun.mc2d.world.block.BlockType; 28 | import org.jetbrains.annotations.Nullable; 29 | 30 | /** 31 | * @author squid233 32 | * @since 0.6.0 33 | */ 34 | public class HitResult { 35 | @Nullable 36 | public BlockType block; 37 | public int x, y, z; 38 | public boolean miss; 39 | 40 | public HitResult(@Nullable BlockType block, int x, int y, int z, boolean miss) { 41 | this.block = block; 42 | this.x = x; 43 | this.y = y; 44 | this.z = z; 45 | this.miss = miss; 46 | } 47 | 48 | public HitResult(BlockType block, int x, int y, int z) { 49 | this(block, x, y, z, false); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/io/github/overrun/mc2d/world/IWorldFixer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2022 Overrun Organization 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package io.github.overrun.mc2d.world; 26 | 27 | import io.github.overrun.mc2d.world.ibt.IBTValue; 28 | 29 | /** 30 | * @author squid233 31 | * @since 0.6.0 32 | */ 33 | @FunctionalInterface 34 | public interface IWorldFixer { 35 | IBTValue adapt(String name, IBTValue value); 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/io/github/overrun/mc2d/world/IWorldListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2022 Overrun Organization 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package io.github.overrun.mc2d.world; 26 | 27 | /** 28 | * The world listener, performed on change. 29 | * 30 | * @author squid233 31 | * @since 0.1.0 32 | */ 33 | public interface IWorldListener { 34 | void allChanged(); 35 | 36 | void blockChanged(int x, int y, int z); 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/io/github/overrun/mc2d/world/block/AirBlockType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2020-2022 Overrun Organization 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package io.github.overrun.mc2d.world.block; 26 | 27 | import io.github.overrun.mc2d.util.Identifier; 28 | import io.github.overrun.mc2d.util.shape.VoxelShapes; 29 | import org.jetbrains.annotations.Nullable; 30 | import org.overrun.swgl.core.gl.GLFixedBatch; 31 | import org.overrun.swgl.core.phys.p2d.AABRect2f; 32 | 33 | /** 34 | * @author squid233 35 | * @since 2021/01/27 36 | */ 37 | public class AirBlockType extends BlockType { 38 | public AirBlockType(BlockSettings settings) { 39 | super(settings); 40 | } 41 | 42 | @Override 43 | @Nullable 44 | public AABRect2f getOutlineShape() { 45 | return VoxelShapes.fullSquare(); 46 | } 47 | 48 | @Override 49 | @Nullable 50 | public AABRect2f getCollisionShape() { 51 | return VoxelShapes.empty(); 52 | } 53 | 54 | @Override 55 | public boolean isTexTransparency() { 56 | return true; 57 | } 58 | 59 | @Override 60 | public void render(GLFixedBatch t, int x, int y, int z) { 61 | } 62 | 63 | @Override 64 | public Identifier getTexture() { 65 | return null; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/io/github/overrun/mc2d/world/block/BlockSettings.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2022 Overrun Organization 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package io.github.overrun.mc2d.world.block; 26 | 27 | /** 28 | * The block type settings. 29 | * 30 | * @author squid233 31 | * @since 0.6.0 32 | */ 33 | public final class BlockSettings { 34 | boolean isAir = false; 35 | 36 | private BlockSettings() { 37 | } 38 | 39 | public static BlockSettings of() { 40 | return new BlockSettings(); 41 | } 42 | 43 | public static BlockSettings copyOf(BlockSettings settings) { 44 | var s = new BlockSettings(); 45 | s.isAir = settings.isAir; 46 | return s; 47 | } 48 | 49 | public static BlockSettings copyOf(BlockType blockType) { 50 | return copyOf(blockType.settings); 51 | } 52 | 53 | public BlockSettings air() { 54 | isAir = true; 55 | return this; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/io/github/overrun/mc2d/world/block/BlockType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2020-2022 Overrun Organization 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package io.github.overrun.mc2d.world.block; 26 | 27 | import io.github.overrun.mc2d.client.model.BlockModelMgr; 28 | import io.github.overrun.mc2d.util.Identifier; 29 | import io.github.overrun.mc2d.util.registry.Registry; 30 | import io.github.overrun.mc2d.util.shape.VoxelShapes; 31 | import io.github.overrun.mc2d.world.World; 32 | import io.github.overrun.mc2d.world.item.ItemConvertible; 33 | import io.github.overrun.mc2d.world.item.ItemType; 34 | import io.github.overrun.mc2d.world.item.Items; 35 | import org.jetbrains.annotations.Nullable; 36 | import org.overrun.swgl.core.gl.GLFixedBatch; 37 | import org.overrun.swgl.core.phys.p2d.AABRect2f; 38 | 39 | import java.util.HashMap; 40 | import java.util.Map; 41 | 42 | /** 43 | * @author squid233 44 | * @since 2021/01/09 45 | */ 46 | public class BlockType implements ItemConvertible { 47 | public static final Map BLOCK_ITEMS = new HashMap<>(); 48 | final BlockSettings settings; 49 | 50 | public BlockType(BlockSettings settings) { 51 | this.settings = settings; 52 | } 53 | 54 | @Nullable 55 | public AABRect2f getOutlineShape() { 56 | return getCollisionShape(); 57 | } 58 | 59 | @Nullable 60 | public AABRect2f getRayCastingShape() { 61 | return getOutlineShape(); 62 | } 63 | 64 | @Nullable 65 | public AABRect2f getCollisionShape() { 66 | return VoxelShapes.fullSquare(); 67 | } 68 | 69 | public boolean isAir() { 70 | return settings.isAir; 71 | } 72 | 73 | public boolean isTexTransparency() { 74 | return false; 75 | } 76 | 77 | public boolean shouldRender(World world, int x, int y, int z) { 78 | return z == 1 || (world.getBlockStates(x, y, 1).isTexTransparency()); 79 | } 80 | 81 | public void render(GLFixedBatch t, int x, int y, int z) { 82 | var path = BlockModelMgr.blockTexture(getTexture()); 83 | var atlas = BlockModelMgr.getBlockAtlas(); 84 | float u0 = atlas.getU0n(path); 85 | float v0 = atlas.getV0n(path); 86 | float u1 = atlas.getU1n(path); 87 | float v1 = atlas.getV1n(path); 88 | if (z == 0) { 89 | t.color(0.5f, 0.5f, 0.5f); 90 | } else { 91 | t.color(1.0f, 1.0f, 1.0f); 92 | } 93 | t.texCoord(u0, v0).vertex(x, y + 1, z).emit(); 94 | t.texCoord(u0, v1).vertex(x, y, z).emit(); 95 | t.texCoord(u1, v1).vertex(x + 1, y, z).emit(); 96 | t.texCoord(u1, v0).vertex(x + 1, y + 1, z).emit(); 97 | } 98 | 99 | @Deprecated 100 | public Identifier getTexture() { 101 | var id = getId(); 102 | return new Identifier(id.getNamespace(), "block/" + id.getPath()); 103 | } 104 | 105 | public final int getRawId() { 106 | return Registry.BLOCK.getRawId(this); 107 | } 108 | 109 | public final Identifier getId() { 110 | return Registry.BLOCK.getId(this); 111 | } 112 | 113 | @Override 114 | public String toString() { 115 | return getId().toString(); 116 | } 117 | 118 | @Override 119 | public ItemType asItem() { 120 | return BLOCK_ITEMS.getOrDefault(this, Items.AIR); 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /src/main/java/io/github/overrun/mc2d/world/block/Blocks.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2020-2022 Overrun Organization 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package io.github.overrun.mc2d.world.block; 26 | 27 | import io.github.overrun.mc2d.util.Identifier; 28 | import io.github.overrun.mc2d.util.registry.Registry; 29 | 30 | /** 31 | * @author squid233 32 | * @since 2021/01/09 33 | */ 34 | public final class Blocks { 35 | public static final BlockType AIR = register(0, "air", new AirBlockType(BlockSettings.of().air())); 36 | public static final BlockType STONE = register(1, "stone", new BlockType(BlockSettings.of())); 37 | public static final BlockType GRASS_BLOCK = register(2, "grass_block", new BlockType(BlockSettings.of())); 38 | public static final BlockType DIRT = register(3, "dirt", new BlockType(BlockSettings.of())); 39 | public static final BlockType COBBLESTONE = register(4, "cobblestone", new BlockType(BlockSettings.of())); 40 | public static final BlockType BEDROCK = register(5, "bedrock", new BlockType(BlockSettings.of())); 41 | public static final BlockType OAK_LOG = register(6, "oak_log", new BlockType(BlockSettings.of())); 42 | public static final BlockType OAK_LEAVES = register(12, "oak_leaves", new LeavesBlockType(BlockSettings.of())); 43 | public static final BlockType OAK_PLANKS = register(18, "oak_planks", new BlockType(BlockSettings.of())); 44 | 45 | public static void register() { 46 | } 47 | 48 | private static BlockType register(int rawId, String id, BlockType block) { 49 | return Registry.BLOCK.set(rawId, new Identifier(id), block); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/io/github/overrun/mc2d/world/block/LeavesBlockType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2022 Overrun Organization 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package io.github.overrun.mc2d.world.block; 26 | 27 | /** 28 | * @author squid233 29 | * @since 0.6.0 30 | */ 31 | public class LeavesBlockType extends BlockType { 32 | public LeavesBlockType(BlockSettings settings) { 33 | super(settings); 34 | } 35 | 36 | @Override 37 | public boolean isTexTransparency() { 38 | return true; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/io/github/overrun/mc2d/world/entity/EntityType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2022 Overrun Organization 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package io.github.overrun.mc2d.world.entity; 26 | 27 | import io.github.overrun.mc2d.world.IWorldFixer; 28 | import io.github.overrun.mc2d.world.World; 29 | import org.jetbrains.annotations.Nullable; 30 | 31 | /** 32 | * The entity type. 33 | * 34 | * @param the entity instance type 35 | * @author squid233 36 | * @since 0.6.0 37 | */ 38 | public class EntityType { 39 | private final Factory entityFactory; 40 | private final @Nullable IWorldFixer worldFixer; 41 | 42 | EntityType(Factory entityFactory, 43 | @Nullable IWorldFixer worldFixer) { 44 | this.entityFactory = entityFactory; 45 | this.worldFixer = worldFixer; 46 | } 47 | 48 | /** 49 | * The entity type factory. 50 | * 51 | * @param the entity instance type 52 | * @author squid233 53 | * @since 0.6.0 54 | */ 55 | public interface Factory { 56 | T create(World world, EntityType entityType); 57 | } 58 | 59 | public T createEntity(World world) { 60 | return entityFactory.create(world, this); 61 | } 62 | 63 | public @Nullable IWorldFixer worldFixer() { 64 | return worldFixer; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/main/java/io/github/overrun/mc2d/world/entity/EntityTypeBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2022 Overrun Organization 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package io.github.overrun.mc2d.world.entity; 26 | 27 | import io.github.overrun.mc2d.world.IWorldFixer; 28 | import org.jetbrains.annotations.Nullable; 29 | 30 | /** 31 | * The entity type builder. 32 | * 33 | * @param the entity instance type 34 | * @author squid233 35 | * @since 0.6.0 36 | */ 37 | public class EntityTypeBuilder { 38 | private final EntityType.Factory factory; 39 | 40 | public EntityTypeBuilder(EntityType.Factory factory) { 41 | this.factory = factory; 42 | } 43 | 44 | public EntityType build(@Nullable IWorldFixer worldFixer) { 45 | if (factory == null) { 46 | throw new IllegalStateException("Entity type factory is null!"); 47 | } 48 | return new EntityType<>(factory, worldFixer); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/io/github/overrun/mc2d/world/entity/EntityTypes.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2022 Overrun Organization 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package io.github.overrun.mc2d.world.entity; 26 | 27 | import io.github.overrun.mc2d.util.Identifier; 28 | import io.github.overrun.mc2d.util.registry.Registry; 29 | import io.github.overrun.mc2d.world.entity.player.PlayerEntity; 30 | 31 | /** 32 | * The builtin entity types. 33 | * 34 | * @author squid233 35 | * @since 0.6.0 36 | */ 37 | public class EntityTypes { 38 | public static final EntityType PLAYER = register(1, "player", new EntityTypeBuilder<>(PlayerEntity::new).build(PlayerEntity.WORLD_FIXER)); 39 | public static final EntityType HUMAN = register(2, "human", new EntityTypeBuilder<>(HumanEntity::new).build(null)); 40 | 41 | public static void register() { 42 | } 43 | 44 | private static > T register(int rawId, String id, T t) { 45 | return Registry.ENTITY.set(rawId, new Identifier(id), t); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/io/github/overrun/mc2d/world/entity/HumanEntity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2022 Overrun Organization 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package io.github.overrun.mc2d.world.entity; 26 | 27 | import io.github.overrun.mc2d.client.Mc2dClient; 28 | import io.github.overrun.mc2d.client.model.PlayerEntityModel; 29 | import io.github.overrun.mc2d.world.World; 30 | import io.github.overrun.mc2d.world.entity.player.PlayerEntity; 31 | import org.joml.Math; 32 | 33 | import static org.lwjgl.opengl.GL11.*; 34 | 35 | /** 36 | * The testing entity. 37 | * 38 | * @author squid233 39 | * @since 0.6.0 40 | */ 41 | public class HumanEntity extends Entity { 42 | public static final PlayerEntityModel model = new PlayerEntityModel(); 43 | private static final int KEEP_FACING_TICKS = 20; 44 | private boolean facingRight; 45 | private int animation = 0; 46 | private boolean keepFacing = false; 47 | private int currentFacingTicks = 0; 48 | 49 | public HumanEntity(World world, EntityType entityType) { 50 | super(world, entityType); 51 | teleport(Math.random() * world.width, 70, 1.5); 52 | } 53 | 54 | @Override 55 | public void tick() { 56 | super.tick(); 57 | animation++; 58 | double xa = Math.random() * 2 - 1; 59 | if (keepFacing) { 60 | xa = facingRight ? 1.0 : -1.0; 61 | currentFacingTicks++; 62 | if (currentFacingTicks >= KEEP_FACING_TICKS) keepFacing = false; 63 | } else { 64 | currentFacingTicks = 0; 65 | xa = xa > 0.0 ? 1.0 : -1.0; 66 | facingRight = xa >= 0; 67 | keepFacing = true; 68 | } 69 | if (onGround && Math.random() > 0.5) { 70 | velocity.y = 0.5; 71 | } 72 | moveRelative(xa, onGround ? 0.1f : 0.02f); 73 | velocity.y -= 0.08; 74 | move((float) velocity.x(), (float) velocity.y()); 75 | velocity.mul(0.91, 0.98, 0.91); 76 | if (onGround) { 77 | velocity.mul(0.7, 1.0, 0.7); 78 | } 79 | if (position.y < -64) { 80 | remove(); 81 | } 82 | } 83 | 84 | public void render(float delta) { 85 | var client = Mc2dClient.getInstance(); 86 | client.getTextureManager().bindTexture(PlayerEntity.TEXTURE); 87 | glPushMatrix(); 88 | glTranslated(Math.lerp(prevPos.x(), position.x(), delta), 89 | Math.lerp(prevPos.y(), position.y(), delta), 90 | Math.lerp(prevPos.z(), position.z(), delta)); 91 | model.render(delta, facingRight, animation); 92 | glPopMatrix(); 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /src/main/java/io/github/overrun/mc2d/world/item/BlockItemType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2020-2022 Overrun Organization 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package io.github.overrun.mc2d.world.item; 26 | 27 | import io.github.overrun.mc2d.util.Identifier; 28 | import io.github.overrun.mc2d.world.block.BlockType; 29 | 30 | /** 31 | * @author squid233 32 | * @since 2021/01/27 33 | */ 34 | public class BlockItemType extends ItemType { 35 | private final BlockType block; 36 | 37 | public BlockItemType(ItemSettings settings, BlockType block) { 38 | super(settings); 39 | this.block = block; 40 | BlockType.BLOCK_ITEMS.put(block, this); 41 | } 42 | 43 | public BlockType getBlock() { 44 | return block; 45 | } 46 | 47 | @Override 48 | public Identifier getTexture() { 49 | return getBlock().getTexture(); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/io/github/overrun/mc2d/world/item/ItemConvertible.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2020-2022 Overrun Organization 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package io.github.overrun.mc2d.world.item; 26 | 27 | /** 28 | * @author squid233 29 | * @since 2021/01/27 30 | */ 31 | public interface ItemConvertible { 32 | ItemType asItem(); 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/io/github/overrun/mc2d/world/item/ItemGroup.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2022 Overrun Organization 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package io.github.overrun.mc2d.world.item; 26 | 27 | import io.github.overrun.mc2d.util.Identifier; 28 | import io.github.overrun.mc2d.util.collect.DefaultedList; 29 | import io.github.overrun.mc2d.util.registry.MappedRegistry; 30 | import io.github.overrun.mc2d.util.registry.Registry; 31 | 32 | /** 33 | * The item group. 34 | * 35 | * @author squid233 36 | * @since 0.6.0 37 | */ 38 | public class ItemGroup { 39 | public static final MappedRegistry ITEM_GROUP = Registry.of(); 40 | public static final ItemGroup BUILDING_BLOCKS = register(new Identifier("building_blocks"), new ItemGroup()); 41 | 42 | private final DefaultedList stacks = new DefaultedList<>(ItemStack::ofEmpty); 43 | 44 | public static ItemGroup register(Identifier id, ItemGroup group) { 45 | return Registry.register(ITEM_GROUP, id, group); 46 | } 47 | 48 | public void addStack(ItemStack stack) { 49 | stacks.add(stack); 50 | } 51 | 52 | public void addStacks() { 53 | for (var e : Registry.ITEM) { 54 | var item = e.getValue(); 55 | if (item.getGroup() == this) { 56 | addStack(ItemStack.of(e.getValue())); 57 | } 58 | } 59 | } 60 | 61 | public DefaultedList getStacks() { 62 | return stacks; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/io/github/overrun/mc2d/world/item/ItemSettings.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2022 Overrun Organization 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package io.github.overrun.mc2d.world.item; 26 | 27 | /** 28 | * The item settings. 29 | * 30 | * @author squid233 31 | * @since 0.6.0 32 | */ 33 | public class ItemSettings { 34 | ItemGroup group; 35 | 36 | private ItemSettings() { 37 | } 38 | 39 | public static ItemSettings of() { 40 | return new ItemSettings(); 41 | } 42 | 43 | public static ItemSettings copyOf(ItemSettings settings) { 44 | var s = new ItemSettings(); 45 | s.group = settings.group; 46 | return s; 47 | } 48 | 49 | public static ItemSettings copyOf(ItemType itemType) { 50 | return copyOf(itemType.settings); 51 | } 52 | 53 | public ItemSettings group(ItemGroup group) { 54 | this.group = group; 55 | return this; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/io/github/overrun/mc2d/world/item/ItemStack.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2022 Overrun Organization 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package io.github.overrun.mc2d.world.item; 26 | 27 | import org.joml.Math; 28 | 29 | import java.util.Objects; 30 | 31 | /** 32 | * @author squid233 33 | * @since 0.6.0 34 | */ 35 | public final class ItemStack { 36 | private ItemType item; 37 | private int count; 38 | private int maxCount = 999; 39 | 40 | private ItemStack(ItemConvertible item, int count) { 41 | this.item = item.asItem(); 42 | this.count = count; 43 | } 44 | 45 | public static ItemStack of(ItemConvertible item, int count) { 46 | return new ItemStack(item, count); 47 | } 48 | 49 | public static ItemStack of(ItemConvertible item) { 50 | return of(item, 1); 51 | } 52 | 53 | public static ItemStack ofEmpty() { 54 | return of(Items.AIR, 0); 55 | } 56 | 57 | public ItemStack copy(int count) { 58 | var stack = of(getItem(), count); 59 | stack.setMaxCount(getMaxCount()); 60 | stack.setCount(stack.getCount()); 61 | return stack; 62 | } 63 | 64 | public ItemStack copy() { 65 | return copy(getCount()); 66 | } 67 | 68 | public void set(ItemStack stack) { 69 | setItem(stack.getItem()); 70 | setMaxCount(stack.getMaxCount()); 71 | setCount(stack.getCount()); 72 | } 73 | 74 | public void setMaxCount(int maxCount) { 75 | this.maxCount = Math.clamp(0, 999, maxCount); 76 | } 77 | 78 | public int getMaxCount() { 79 | return maxCount; 80 | } 81 | 82 | public void setItem(ItemConvertible item) { 83 | this.item = item != null ? item.asItem() : Items.AIR; 84 | } 85 | 86 | public void setCount(int count) { 87 | this.count = Math.clamp(0, getMaxCount(), count); 88 | } 89 | 90 | public void increment(int count) { 91 | setCount(getCount() + count); 92 | } 93 | 94 | public void increment() { 95 | increment(1); 96 | } 97 | 98 | public void decrement(int count) { 99 | setCount(getCount() - count); 100 | } 101 | 102 | public void decrement() { 103 | decrement(1); 104 | } 105 | 106 | public ItemType getItem() { 107 | return item; 108 | } 109 | 110 | public int getCount() { 111 | return count; 112 | } 113 | 114 | public boolean isEmpty() { 115 | return count < 1 || item == Items.AIR; 116 | } 117 | 118 | @Override 119 | public boolean equals(Object o) { 120 | if (this == o) return true; 121 | if (o == null || getClass() != o.getClass()) return false; 122 | ItemStack stack = (ItemStack) o; 123 | return getCount() == stack.getCount() && getMaxCount() == stack.getMaxCount() && Objects.equals(getItem(), stack.getItem()); 124 | } 125 | 126 | @Override 127 | public int hashCode() { 128 | return Objects.hash(getItem(), getCount(), getMaxCount()); 129 | } 130 | } 131 | -------------------------------------------------------------------------------- /src/main/java/io/github/overrun/mc2d/world/item/ItemType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2020-2022 Overrun Organization 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package io.github.overrun.mc2d.world.item; 26 | 27 | import io.github.overrun.mc2d.util.Identifier; 28 | import io.github.overrun.mc2d.util.registry.Registry; 29 | 30 | /** 31 | * @author squid233 32 | * @since 2021/01/27 33 | */ 34 | public class ItemType implements ItemConvertible { 35 | final ItemSettings settings; 36 | 37 | public ItemType(ItemSettings settings) { 38 | this.settings = settings; 39 | } 40 | 41 | public ItemGroup getGroup() { 42 | return settings.group; 43 | } 44 | 45 | @Deprecated 46 | public Identifier getTexture() { 47 | var id = getId(); 48 | return new Identifier(id.getNamespace(), "item/" + id.getPath()); 49 | } 50 | 51 | public final int getRawId() { 52 | return Registry.ITEM.getRawId(this); 53 | } 54 | 55 | public final Identifier getId() { 56 | return Registry.ITEM.getId(this); 57 | } 58 | 59 | @Override 60 | public String toString() { 61 | return getId().toString(); 62 | } 63 | 64 | @Override 65 | public ItemType asItem() { 66 | return this; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/main/java/io/github/overrun/mc2d/world/item/Items.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2020-2022 Overrun Organization 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package io.github.overrun.mc2d.world.item; 26 | 27 | import io.github.overrun.mc2d.util.Identifier; 28 | import io.github.overrun.mc2d.world.block.BlockType; 29 | import io.github.overrun.mc2d.world.block.Blocks; 30 | import io.github.overrun.mc2d.util.registry.Registry; 31 | 32 | /** 33 | * @author squid233 34 | * @since 2021/01/27 35 | */ 36 | public final class Items { 37 | public static final ItemType AIR = register(0, "air", ItemSettings.of(), Blocks.AIR); 38 | public static final ItemType STONE = register(1, "stone", ItemSettings.of().group(ItemGroup.BUILDING_BLOCKS), Blocks.STONE); 39 | public static final ItemType GRASS_BLOCK = register(2, "grass_block", ItemSettings.of().group(ItemGroup.BUILDING_BLOCKS), Blocks.GRASS_BLOCK); 40 | public static final ItemType DIRT = register(3, "dirt", ItemSettings.of().group(ItemGroup.BUILDING_BLOCKS), Blocks.DIRT); 41 | public static final ItemType COBBLESTONE = register(4, "cobblestone", ItemSettings.of().group(ItemGroup.BUILDING_BLOCKS), Blocks.COBBLESTONE); 42 | public static final ItemType BEDROCK = register(5, "bedrock", ItemSettings.of().group(ItemGroup.BUILDING_BLOCKS), Blocks.BEDROCK); 43 | public static final ItemType OAK_LOG = register(6, "oak_log", ItemSettings.of().group(ItemGroup.BUILDING_BLOCKS), Blocks.OAK_LOG); 44 | public static final ItemType OAK_LEAVES = register(12, "oak_leaves", ItemSettings.of().group(ItemGroup.BUILDING_BLOCKS), Blocks.OAK_LEAVES); 45 | public static final ItemType OAK_PLANKS = register(18, "oak_planks", ItemSettings.of().group(ItemGroup.BUILDING_BLOCKS), Blocks.OAK_PLANKS); 46 | 47 | public static void register() { 48 | } 49 | 50 | private static ItemType register(int rawId, String id, ItemType item) { 51 | return Registry.ITEM.set(rawId, new Identifier(id), item); 52 | } 53 | 54 | private static ItemType register(int rawId, String id, ItemSettings settings, BlockType block) { 55 | return register(rawId, id, new BlockItemType(settings, block)); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/resources/assets/mc2d/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Over-Run/Minecraft2D/e56b400864d7cdc766f652a3863cfa2a8e40f270/src/main/resources/assets/mc2d/icon.png -------------------------------------------------------------------------------- /src/main/resources/assets/mc2d/lang/en_us.lang: -------------------------------------------------------------------------------- 1 | language.name=English (United States) 2 | language.code=en_us 3 | text.screen.singleplayer=Single-player 4 | text.screen.multiplayer=Multi-player 5 | text.screen.mods=Mods 6 | text.screen.options=Options 7 | text.screen.exit_game=Exit Game 8 | itemGroup.mc2d=Item Groups 9 | text.screen.title.pausing=Pausing 10 | text.screen.back_to_game=Back to Game 11 | text.screen.save_and_back=Save and Back to Title Screen 12 | text.screen.world.loading=Loading World 13 | text.screen.world.saving=Saving World 14 | text.debug.player.position=XYZ: %f, %f, %f 15 | text.debug.player.block_position=Block: %d, %d, %d 16 | text.debug.mod_count=Mod count: %d 17 | text.debug.java=Java: %s 18 | text.debug.mem=Mem: %d%% %d/%s 19 | text.debug.cpu=CPU: %s 20 | text.debug.display_0=Display: %dx%d (%s) 21 | text.debug.display_1=%s 22 | text.debug.display_2=%s 23 | text.debug.target_block=Targeted block: %d, %d, %d -------------------------------------------------------------------------------- /src/main/resources/assets/mc2d/lang/zh_cn.lang: -------------------------------------------------------------------------------- 1 | language.name=简体中文 2 | language.code=zh_cn 3 | text.screen.singleplayer=单人游戏 4 | text.screen.multiplayer=多人游戏 5 | text.screen.mods=模组 6 | text.screen.options=选项 7 | text.screen.exit_game=退出游戏 8 | itemGroup.mc2d=物品组 9 | text.screen.title.pausing=暂停中 10 | text.screen.back_to_game=返回游戏 11 | text.screen.save_and_back=保存并返回标题画面 12 | text.screen.world.loading=加载世界中 13 | text.screen.world.saving=保存世界中 14 | text.debug.player.position=XYZ: %f, %f, %f 15 | text.debug.player.block_position=方块: %d, %d, %d 16 | text.debug.mod_count=模组数量: %d 17 | text.debug.java=Java: %s 18 | text.debug.mem=内存: %d%% %d/%s 19 | text.debug.cpu=CPU: %s 20 | text.debug.display_0=显示: %dx%d (%s) 21 | text.debug.display_1=%s 22 | text.debug.display_2=%s 23 | text.debug.target_block=选中方块: %d, %d, %d -------------------------------------------------------------------------------- /src/main/resources/assets/mc2d/textures/block/bedrock.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Over-Run/Minecraft2D/e56b400864d7cdc766f652a3863cfa2a8e40f270/src/main/resources/assets/mc2d/textures/block/bedrock.png -------------------------------------------------------------------------------- /src/main/resources/assets/mc2d/textures/block/cobblestone.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Over-Run/Minecraft2D/e56b400864d7cdc766f652a3863cfa2a8e40f270/src/main/resources/assets/mc2d/textures/block/cobblestone.png -------------------------------------------------------------------------------- /src/main/resources/assets/mc2d/textures/block/dirt.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Over-Run/Minecraft2D/e56b400864d7cdc766f652a3863cfa2a8e40f270/src/main/resources/assets/mc2d/textures/block/dirt.png -------------------------------------------------------------------------------- /src/main/resources/assets/mc2d/textures/block/grass_block.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Over-Run/Minecraft2D/e56b400864d7cdc766f652a3863cfa2a8e40f270/src/main/resources/assets/mc2d/textures/block/grass_block.png -------------------------------------------------------------------------------- /src/main/resources/assets/mc2d/textures/block/oak_leaves.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Over-Run/Minecraft2D/e56b400864d7cdc766f652a3863cfa2a8e40f270/src/main/resources/assets/mc2d/textures/block/oak_leaves.png -------------------------------------------------------------------------------- /src/main/resources/assets/mc2d/textures/block/oak_log.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Over-Run/Minecraft2D/e56b400864d7cdc766f652a3863cfa2a8e40f270/src/main/resources/assets/mc2d/textures/block/oak_log.png -------------------------------------------------------------------------------- /src/main/resources/assets/mc2d/textures/block/oak_planks.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Over-Run/Minecraft2D/e56b400864d7cdc766f652a3863cfa2a8e40f270/src/main/resources/assets/mc2d/textures/block/oak_planks.png -------------------------------------------------------------------------------- /src/main/resources/assets/mc2d/textures/block/stone.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Over-Run/Minecraft2D/e56b400864d7cdc766f652a3863cfa2a8e40f270/src/main/resources/assets/mc2d/textures/block/stone.png -------------------------------------------------------------------------------- /src/main/resources/assets/mc2d/textures/entity/player.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Over-Run/Minecraft2D/e56b400864d7cdc766f652a3863cfa2a8e40f270/src/main/resources/assets/mc2d/textures/entity/player.png -------------------------------------------------------------------------------- /src/main/resources/assets/mc2d/textures/font/unifont_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Over-Run/Minecraft2D/e56b400864d7cdc766f652a3863cfa2a8e40f270/src/main/resources/assets/mc2d/textures/font/unifont_0.png -------------------------------------------------------------------------------- /src/main/resources/assets/mc2d/textures/gui/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Over-Run/Minecraft2D/e56b400864d7cdc766f652a3863cfa2a8e40f270/src/main/resources/assets/mc2d/textures/gui/logo.png -------------------------------------------------------------------------------- /src/main/resources/assets/mc2d/textures/gui/options_background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Over-Run/Minecraft2D/e56b400864d7cdc766f652a3863cfa2a8e40f270/src/main/resources/assets/mc2d/textures/gui/options_background.png -------------------------------------------------------------------------------- /src/main/resources/assets/mc2d/textures/gui/tab_items.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Over-Run/Minecraft2D/e56b400864d7cdc766f652a3863cfa2a8e40f270/src/main/resources/assets/mc2d/textures/gui/tab_items.png -------------------------------------------------------------------------------- /src/main/resources/assets/mc2d/textures/gui/tabs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Over-Run/Minecraft2D/e56b400864d7cdc766f652a3863cfa2a8e40f270/src/main/resources/assets/mc2d/textures/gui/tabs.png -------------------------------------------------------------------------------- /src/main/resources/assets/mc2d/textures/gui/widgets.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Over-Run/Minecraft2D/e56b400864d7cdc766f652a3863cfa2a8e40f270/src/main/resources/assets/mc2d/textures/gui/widgets.png -------------------------------------------------------------------------------- /src/main/resources/log4j2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /src/main/resources/version.json: -------------------------------------------------------------------------------- 1 | { 2 | "versionString": "0.6.0", 3 | "versionNumber": -1, 4 | "worldVersion": 3, 5 | "protocolVersion": 0 6 | } --------------------------------------------------------------------------------