├── .gitattributes ├── sounds ├── hurt.ogg ├── oink.ogg ├── button.ogg ├── credits.ogg ├── dirt_1.ogg ├── dirt_2.ogg ├── dirt_3.ogg ├── pickup.ogg ├── sand_1.ogg ├── sand_2.ogg ├── sand_3.ogg ├── sheep_1.ogg ├── sheep_2.ogg ├── sheep_3.ogg ├── stone_1.ogg ├── stone_2.ogg ├── stone_3.ogg ├── wood_1.ogg ├── wood_2.ogg ├── door_open.ogg ├── leaves_1.ogg ├── leaves_2.ogg ├── leaves_3.ogg ├── main_menu.ogg ├── cow_grazing.ogg ├── cow_hurt_1.ogg ├── cow_hurt_2.ogg ├── door_close.ogg ├── easter_egg_1.ogg ├── tnt_explode.ogg ├── tnt_ignite.ogg └── Attributes.txt ├── textures ├── cloud.png ├── cow.png ├── debug.png ├── door.png ├── font.png ├── glfw.png ├── heart.png ├── icon.png ├── lwjgl.png ├── moon.png ├── pig.png ├── sun.png ├── torch.png ├── button.png ├── chicken.png ├── hotbar.png ├── menu_bg.png ├── openal.png ├── player.png ├── zombie.png ├── boatitem.png ├── chat_box.png ├── crosshair.png ├── exploder.png ├── freesound.png ├── inventory.png ├── items │ ├── coal.png │ ├── gold.png │ ├── iron.png │ ├── ruby.png │ ├── lapis.png │ ├── stick.png │ ├── diamond.png │ ├── emerald.png │ └── sapphire.png ├── mineclone2.png ├── raindrop.png ├── selection.png ├── sheep_wool.png ├── skeleton.png ├── text_box.png ├── dark_reaven.png ├── font_backup.png ├── heart_shadow.png ├── sheep_shaved.png ├── textureAtlas.png ├── button_pushed.png ├── button_selected.png ├── crack_anylength.png ├── hotbar_selected.png ├── inventory_slot.png ├── jordan4ibanez.png ├── minetest_logo.png ├── stone_pickaxe.png ├── tools │ ├── coalaxe.png │ ├── coalpick.png │ ├── goldaxe.png │ ├── goldpick.png │ ├── ironaxe.png │ ├── ironpick.png │ ├── lapisaxe.png │ ├── lapispick.png │ ├── rubyaxe.png │ ├── rubypick.png │ ├── stoneaxe.png │ ├── stonepick.png │ ├── woodaxe.png │ ├── woodpick.png │ ├── coalshovel.png │ ├── diamondaxe.png │ ├── diamondpick.png │ ├── emeraldaxe.png │ ├── emeraldpick.png │ ├── goldshovel.png │ ├── ironshovel.png │ ├── lapisshovel.png │ ├── rubyshovel.png │ ├── sapphireaxe.png │ ├── stoneshovel.png │ ├── woodshovel.png │ ├── diamondshovel.png │ ├── emeraldshovel.png │ ├── sapphirepick.png │ └── sapphireshovel.png ├── water_overlay.png ├── text_box_selected.png ├── inventory_backdrop.png ├── title_screen_block.png ├── inventory_slot_selected.png ├── title_screen_background.png └── Attributes.txt ├── src └── main │ └── java │ ├── engine │ ├── scene │ │ └── Scene.java │ ├── disk │ │ ├── SaveVector3D.java │ │ ├── PlayerData.java │ │ └── PrimitiveChunkObject.java │ ├── network │ │ ├── ThrowItemUpdate.java │ │ ├── NetChunk.java │ │ ├── TimeSend.java │ │ ├── HotBarSlotUpdate.java │ │ ├── ChatMessage.java │ │ ├── ItemDeletionSender.java │ │ ├── NetworkHandshake.java │ │ ├── PlayerPosObject.java │ │ ├── BlockBreakUpdate.java │ │ ├── NetworkInventory.java │ │ ├── NetworkMovePositionDemand.java │ │ ├── ItemPickupNotification.java │ │ ├── ChunkRequest.java │ │ ├── BlockPlaceUpdate.java │ │ └── ItemSendingObject.java │ ├── MemorySweeper.java │ ├── settings │ │ ├── SettingsObject.java │ │ └── Settings.java │ ├── time │ │ ├── Delta.java │ │ └── Timer.java │ ├── sound │ │ ├── SoundListener.java │ │ ├── SoundSource.java │ │ ├── SoundBuffer.java │ │ ├── SoundAPI.java │ │ └── SoundManager.java │ ├── FancyMath.java │ ├── highPerformanceContainers │ │ ├── MicroIntArray.java │ │ ├── HyperIntArray.java │ │ ├── MicroFloatArray.java │ │ └── HyperFloatArray.java │ ├── Utils.java │ ├── debug │ │ └── RuntimeInfo.java │ ├── graphics │ │ ├── Texture.java │ │ ├── ShaderProgram.java │ │ ├── Mesh.java │ │ └── Camera.java │ ├── compression │ │ └── Compression.java │ ├── gui │ │ ├── MeshCreator2D.java │ │ └── GUIObject.java │ └── Mouse.java │ └── game │ ├── player │ ├── PlayerObject.java │ └── ViewBobbing.java │ ├── chunk │ ├── ChunkData.java │ ├── ChunkMeshData.java │ ├── ChunkObject.java │ └── ChunkUpdateHandler.java │ ├── blocks │ └── BlockModifier.java │ ├── light │ └── LightUpdate.java │ ├── entity │ ├── weather │ │ ├── RainDropEntity.java │ │ └── Weather.java │ ├── EntityContainer.java │ ├── mob │ │ ├── MobInterface.java │ │ ├── MobSpawning.java │ │ ├── MobDefinition.java │ │ └── MobMeshBuilder.java │ ├── EntityInterface.java │ ├── tnt │ │ └── Explosion.java │ ├── Entity.java │ ├── collision │ │ ├── CollisionObject.java │ │ └── MobCollision.java │ ├── itemEntity │ │ └── ItemEntity.java │ └── particle │ │ └── Particle.java │ ├── item │ └── ItemModifier.java │ ├── crafting │ ├── CraftRecipeObject.java │ └── InventoryObject.java │ ├── clouds │ ├── Cloud.java │ └── CloudMesh.java │ ├── mainMenu │ └── Credits.java │ └── falling │ └── FallingEntity.java ├── .gitignore ├── resources ├── fragment.fs ├── hud_vertex.vs ├── entity_fragment.fs ├── glasslike_fragment.fs ├── hud_fragment.fs ├── vertex.vs ├── glasslike_vertex.vs └── entity_vertex.vs ├── README.md ├── Crafter.iml └── LICENSE /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /sounds/hurt.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/sounds/hurt.ogg -------------------------------------------------------------------------------- /sounds/oink.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/sounds/oink.ogg -------------------------------------------------------------------------------- /sounds/button.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/sounds/button.ogg -------------------------------------------------------------------------------- /sounds/credits.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/sounds/credits.ogg -------------------------------------------------------------------------------- /sounds/dirt_1.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/sounds/dirt_1.ogg -------------------------------------------------------------------------------- /sounds/dirt_2.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/sounds/dirt_2.ogg -------------------------------------------------------------------------------- /sounds/dirt_3.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/sounds/dirt_3.ogg -------------------------------------------------------------------------------- /sounds/pickup.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/sounds/pickup.ogg -------------------------------------------------------------------------------- /sounds/sand_1.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/sounds/sand_1.ogg -------------------------------------------------------------------------------- /sounds/sand_2.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/sounds/sand_2.ogg -------------------------------------------------------------------------------- /sounds/sand_3.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/sounds/sand_3.ogg -------------------------------------------------------------------------------- /sounds/sheep_1.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/sounds/sheep_1.ogg -------------------------------------------------------------------------------- /sounds/sheep_2.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/sounds/sheep_2.ogg -------------------------------------------------------------------------------- /sounds/sheep_3.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/sounds/sheep_3.ogg -------------------------------------------------------------------------------- /sounds/stone_1.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/sounds/stone_1.ogg -------------------------------------------------------------------------------- /sounds/stone_2.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/sounds/stone_2.ogg -------------------------------------------------------------------------------- /sounds/stone_3.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/sounds/stone_3.ogg -------------------------------------------------------------------------------- /sounds/wood_1.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/sounds/wood_1.ogg -------------------------------------------------------------------------------- /sounds/wood_2.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/sounds/wood_2.ogg -------------------------------------------------------------------------------- /textures/cloud.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/textures/cloud.png -------------------------------------------------------------------------------- /textures/cow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/textures/cow.png -------------------------------------------------------------------------------- /textures/debug.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/textures/debug.png -------------------------------------------------------------------------------- /textures/door.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/textures/door.png -------------------------------------------------------------------------------- /textures/font.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/textures/font.png -------------------------------------------------------------------------------- /textures/glfw.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/textures/glfw.png -------------------------------------------------------------------------------- /textures/heart.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/textures/heart.png -------------------------------------------------------------------------------- /textures/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/textures/icon.png -------------------------------------------------------------------------------- /textures/lwjgl.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/textures/lwjgl.png -------------------------------------------------------------------------------- /textures/moon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/textures/moon.png -------------------------------------------------------------------------------- /textures/pig.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/textures/pig.png -------------------------------------------------------------------------------- /textures/sun.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/textures/sun.png -------------------------------------------------------------------------------- /textures/torch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/textures/torch.png -------------------------------------------------------------------------------- /sounds/door_open.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/sounds/door_open.ogg -------------------------------------------------------------------------------- /sounds/leaves_1.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/sounds/leaves_1.ogg -------------------------------------------------------------------------------- /sounds/leaves_2.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/sounds/leaves_2.ogg -------------------------------------------------------------------------------- /sounds/leaves_3.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/sounds/leaves_3.ogg -------------------------------------------------------------------------------- /sounds/main_menu.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/sounds/main_menu.ogg -------------------------------------------------------------------------------- /src/main/java/engine/scene/Scene.java: -------------------------------------------------------------------------------- 1 | package engine.scene; 2 | 3 | public interface Scene { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /textures/button.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/textures/button.png -------------------------------------------------------------------------------- /textures/chicken.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/textures/chicken.png -------------------------------------------------------------------------------- /textures/hotbar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/textures/hotbar.png -------------------------------------------------------------------------------- /textures/menu_bg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/textures/menu_bg.png -------------------------------------------------------------------------------- /textures/openal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/textures/openal.png -------------------------------------------------------------------------------- /textures/player.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/textures/player.png -------------------------------------------------------------------------------- /textures/zombie.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/textures/zombie.png -------------------------------------------------------------------------------- /sounds/cow_grazing.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/sounds/cow_grazing.ogg -------------------------------------------------------------------------------- /sounds/cow_hurt_1.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/sounds/cow_hurt_1.ogg -------------------------------------------------------------------------------- /sounds/cow_hurt_2.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/sounds/cow_hurt_2.ogg -------------------------------------------------------------------------------- /sounds/door_close.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/sounds/door_close.ogg -------------------------------------------------------------------------------- /sounds/easter_egg_1.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/sounds/easter_egg_1.ogg -------------------------------------------------------------------------------- /sounds/tnt_explode.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/sounds/tnt_explode.ogg -------------------------------------------------------------------------------- /sounds/tnt_ignite.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/sounds/tnt_ignite.ogg -------------------------------------------------------------------------------- /textures/boatitem.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/textures/boatitem.png -------------------------------------------------------------------------------- /textures/chat_box.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/textures/chat_box.png -------------------------------------------------------------------------------- /textures/crosshair.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/textures/crosshair.png -------------------------------------------------------------------------------- /textures/exploder.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/textures/exploder.png -------------------------------------------------------------------------------- /textures/freesound.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/textures/freesound.png -------------------------------------------------------------------------------- /textures/inventory.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/textures/inventory.png -------------------------------------------------------------------------------- /textures/items/coal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/textures/items/coal.png -------------------------------------------------------------------------------- /textures/items/gold.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/textures/items/gold.png -------------------------------------------------------------------------------- /textures/items/iron.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/textures/items/iron.png -------------------------------------------------------------------------------- /textures/items/ruby.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/textures/items/ruby.png -------------------------------------------------------------------------------- /textures/mineclone2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/textures/mineclone2.png -------------------------------------------------------------------------------- /textures/raindrop.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/textures/raindrop.png -------------------------------------------------------------------------------- /textures/selection.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/textures/selection.png -------------------------------------------------------------------------------- /textures/sheep_wool.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/textures/sheep_wool.png -------------------------------------------------------------------------------- /textures/skeleton.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/textures/skeleton.png -------------------------------------------------------------------------------- /textures/text_box.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/textures/text_box.png -------------------------------------------------------------------------------- /textures/dark_reaven.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/textures/dark_reaven.png -------------------------------------------------------------------------------- /textures/font_backup.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/textures/font_backup.png -------------------------------------------------------------------------------- /textures/heart_shadow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/textures/heart_shadow.png -------------------------------------------------------------------------------- /textures/items/lapis.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/textures/items/lapis.png -------------------------------------------------------------------------------- /textures/items/stick.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/textures/items/stick.png -------------------------------------------------------------------------------- /textures/sheep_shaved.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/textures/sheep_shaved.png -------------------------------------------------------------------------------- /textures/textureAtlas.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/textures/textureAtlas.png -------------------------------------------------------------------------------- /textures/button_pushed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/textures/button_pushed.png -------------------------------------------------------------------------------- /textures/button_selected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/textures/button_selected.png -------------------------------------------------------------------------------- /textures/crack_anylength.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/textures/crack_anylength.png -------------------------------------------------------------------------------- /textures/hotbar_selected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/textures/hotbar_selected.png -------------------------------------------------------------------------------- /textures/inventory_slot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/textures/inventory_slot.png -------------------------------------------------------------------------------- /textures/items/diamond.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/textures/items/diamond.png -------------------------------------------------------------------------------- /textures/items/emerald.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/textures/items/emerald.png -------------------------------------------------------------------------------- /textures/items/sapphire.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/textures/items/sapphire.png -------------------------------------------------------------------------------- /textures/jordan4ibanez.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/textures/jordan4ibanez.png -------------------------------------------------------------------------------- /textures/minetest_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/textures/minetest_logo.png -------------------------------------------------------------------------------- /textures/stone_pickaxe.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/textures/stone_pickaxe.png -------------------------------------------------------------------------------- /textures/tools/coalaxe.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/textures/tools/coalaxe.png -------------------------------------------------------------------------------- /textures/tools/coalpick.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/textures/tools/coalpick.png -------------------------------------------------------------------------------- /textures/tools/goldaxe.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/textures/tools/goldaxe.png -------------------------------------------------------------------------------- /textures/tools/goldpick.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/textures/tools/goldpick.png -------------------------------------------------------------------------------- /textures/tools/ironaxe.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/textures/tools/ironaxe.png -------------------------------------------------------------------------------- /textures/tools/ironpick.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/textures/tools/ironpick.png -------------------------------------------------------------------------------- /textures/tools/lapisaxe.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/textures/tools/lapisaxe.png -------------------------------------------------------------------------------- /textures/tools/lapispick.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/textures/tools/lapispick.png -------------------------------------------------------------------------------- /textures/tools/rubyaxe.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/textures/tools/rubyaxe.png -------------------------------------------------------------------------------- /textures/tools/rubypick.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/textures/tools/rubypick.png -------------------------------------------------------------------------------- /textures/tools/stoneaxe.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/textures/tools/stoneaxe.png -------------------------------------------------------------------------------- /textures/tools/stonepick.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/textures/tools/stonepick.png -------------------------------------------------------------------------------- /textures/tools/woodaxe.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/textures/tools/woodaxe.png -------------------------------------------------------------------------------- /textures/tools/woodpick.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/textures/tools/woodpick.png -------------------------------------------------------------------------------- /textures/water_overlay.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/textures/water_overlay.png -------------------------------------------------------------------------------- /textures/text_box_selected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/textures/text_box_selected.png -------------------------------------------------------------------------------- /textures/tools/coalshovel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/textures/tools/coalshovel.png -------------------------------------------------------------------------------- /textures/tools/diamondaxe.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/textures/tools/diamondaxe.png -------------------------------------------------------------------------------- /textures/tools/diamondpick.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/textures/tools/diamondpick.png -------------------------------------------------------------------------------- /textures/tools/emeraldaxe.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/textures/tools/emeraldaxe.png -------------------------------------------------------------------------------- /textures/tools/emeraldpick.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/textures/tools/emeraldpick.png -------------------------------------------------------------------------------- /textures/tools/goldshovel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/textures/tools/goldshovel.png -------------------------------------------------------------------------------- /textures/tools/ironshovel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/textures/tools/ironshovel.png -------------------------------------------------------------------------------- /textures/tools/lapisshovel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/textures/tools/lapisshovel.png -------------------------------------------------------------------------------- /textures/tools/rubyshovel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/textures/tools/rubyshovel.png -------------------------------------------------------------------------------- /textures/tools/sapphireaxe.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/textures/tools/sapphireaxe.png -------------------------------------------------------------------------------- /textures/tools/stoneshovel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/textures/tools/stoneshovel.png -------------------------------------------------------------------------------- /textures/tools/woodshovel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/textures/tools/woodshovel.png -------------------------------------------------------------------------------- /textures/inventory_backdrop.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/textures/inventory_backdrop.png -------------------------------------------------------------------------------- /textures/title_screen_block.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/textures/title_screen_block.png -------------------------------------------------------------------------------- /textures/tools/diamondshovel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/textures/tools/diamondshovel.png -------------------------------------------------------------------------------- /textures/tools/emeraldshovel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/textures/tools/emeraldshovel.png -------------------------------------------------------------------------------- /textures/tools/sapphirepick.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/textures/tools/sapphirepick.png -------------------------------------------------------------------------------- /textures/tools/sapphireshovel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/textures/tools/sapphireshovel.png -------------------------------------------------------------------------------- /textures/inventory_slot_selected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/textures/inventory_slot_selected.png -------------------------------------------------------------------------------- /textures/title_screen_background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordan4ibanez/Crafter-Ja-OLD-va/HEAD/textures/title_screen_background.png -------------------------------------------------------------------------------- /textures/Attributes.txt: -------------------------------------------------------------------------------- 1 | Textures are from: 2 | Mineclone 2 (https://git.minetest.land/MineClone2/MineClone2) 3 | Gerold55 (https://github.com/Gerold55/MineClone-2-Textures) -------------------------------------------------------------------------------- /src/main/java/engine/disk/SaveVector3D.java: -------------------------------------------------------------------------------- 1 | package engine.disk; 2 | 3 | public class SaveVector3D{ 4 | public double x; 5 | public double y; 6 | public double z; 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/engine/network/ThrowItemUpdate.java: -------------------------------------------------------------------------------- 1 | package engine.network; 2 | 3 | public class ThrowItemUpdate { 4 | public boolean truth = true; 5 | public ThrowItemUpdate(){ 6 | 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/engine/network/NetChunk.java: -------------------------------------------------------------------------------- 1 | package engine.network; 2 | 3 | public class NetChunk { 4 | public byte[] b; 5 | public NetChunk(){ 6 | 7 | } 8 | 9 | public NetChunk(byte[] b){ 10 | this.b = b; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Project exclude paths 2 | /out/ 3 | *.log 4 | /Worlds/ 5 | Settings.conf 6 | /target/ 7 | nbactions-lwjgl-natives-windows-amd64.xml 8 | nbactions-lwjgl-natives-linux-amd64.xml 9 | nbactions.xml 10 | nb-configuration.xml 11 | /BUILD_OUTPUT/ 12 | /.idea/ -------------------------------------------------------------------------------- /src/main/java/engine/network/TimeSend.java: -------------------------------------------------------------------------------- 1 | package engine.network; 2 | 3 | public class TimeSend { 4 | public float time; 5 | 6 | public TimeSend(){ 7 | 8 | } 9 | 10 | public TimeSend(double time){ 11 | this.time = (float)time; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/engine/network/HotBarSlotUpdate.java: -------------------------------------------------------------------------------- 1 | package engine.network; 2 | 3 | public class HotBarSlotUpdate { 4 | public int slot; 5 | 6 | public HotBarSlotUpdate(){ 7 | 8 | } 9 | 10 | public HotBarSlotUpdate(int i){ 11 | this.slot = i; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/engine/network/ChatMessage.java: -------------------------------------------------------------------------------- 1 | package engine.network; 2 | 3 | public class ChatMessage { 4 | public String message; 5 | 6 | public ChatMessage(){ 7 | 8 | } 9 | 10 | public ChatMessage(String message){ 11 | this.message = message; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/engine/network/ItemDeletionSender.java: -------------------------------------------------------------------------------- 1 | package engine.network; 2 | 3 | public class ItemDeletionSender { 4 | public int ID; 5 | 6 | public ItemDeletionSender(){ 7 | 8 | } 9 | 10 | public ItemDeletionSender(int ID){ 11 | this.ID = ID; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/engine/network/NetworkHandshake.java: -------------------------------------------------------------------------------- 1 | package engine.network; 2 | 3 | public class NetworkHandshake { 4 | public String name = "false"; 5 | public NetworkHandshake(){ 6 | } 7 | public NetworkHandshake(String name){ 8 | this.name = name; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/engine/network/PlayerPosObject.java: -------------------------------------------------------------------------------- 1 | package engine.network; 2 | 3 | import org.joml.Vector3d; 4 | import org.joml.Vector3f; 5 | 6 | public class PlayerPosObject { 7 | public int ID; 8 | public String name; 9 | public Vector3d pos; 10 | public Vector3f cameraRot; 11 | } 12 | -------------------------------------------------------------------------------- /resources/fragment.fs: -------------------------------------------------------------------------------- 1 | #version 440 2 | 3 | in vec3 exColor; 4 | in vec2 outTexCoord; 5 | 6 | out vec4 fragColor; 7 | 8 | uniform sampler2D texture_sampler; 9 | 10 | //the basic no frills fast graphics mode 11 | void main() 12 | { 13 | fragColor = texture( texture_sampler, outTexCoord) * vec4(exColor, 1.0); 14 | } -------------------------------------------------------------------------------- /sounds/Attributes.txt: -------------------------------------------------------------------------------- 1 | Hurt: https://freesound.org/people/thecheeseman/sounds/44429/ 2 | Oink: https://freesound.org/people/qubodup/sounds/442907/ 3 | sheep: https://freesound.org/people/acclivity/sounds/39947/ 4 | cow grazing: https://freesound.org/people/Benboncan/sounds/58277/ 5 | cow hurt: https://freesound.org/people/Benboncan/sounds/63618/ 6 | -------------------------------------------------------------------------------- /src/main/java/engine/network/BlockBreakUpdate.java: -------------------------------------------------------------------------------- 1 | package engine.network; 2 | 3 | import org.joml.Vector3i; 4 | 5 | public class BlockBreakUpdate { 6 | public Vector3i pos; 7 | 8 | public BlockBreakUpdate(){ 9 | 10 | } 11 | 12 | public BlockBreakUpdate(Vector3i pos){ 13 | this.pos = pos; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/engine/network/NetworkInventory.java: -------------------------------------------------------------------------------- 1 | package engine.network; 2 | 3 | public class NetworkInventory { 4 | public String name; 5 | public String[][] inventory; 6 | 7 | public NetworkInventory(){ 8 | 9 | } 10 | 11 | public NetworkInventory(int x, int y){ 12 | this.inventory = new String[x][y]; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/game/player/PlayerObject.java: -------------------------------------------------------------------------------- 1 | package game.player; 2 | 3 | import org.joml.Vector3d; 4 | import org.joml.Vector3f; 5 | 6 | public class PlayerObject { 7 | public int ID; 8 | public String name; 9 | 10 | public Vector3d pos; 11 | public Vector3d goalPos; 12 | 13 | public Vector3f camRot; 14 | public Vector3f goalCamRot; 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/game/chunk/ChunkData.java: -------------------------------------------------------------------------------- 1 | package game.chunk; 2 | //the bare minimum "tuple" return 3 | public class ChunkData { 4 | public int x; 5 | public int z; 6 | public byte [] block = new byte[32768]; 7 | public byte[] rotation = new byte[32768]; 8 | public byte[] light = new byte[32768]; 9 | public byte[] heightMap = new byte[256]; 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/engine/network/NetworkMovePositionDemand.java: -------------------------------------------------------------------------------- 1 | package engine.network; 2 | 3 | import org.joml.Vector3d; 4 | 5 | public class NetworkMovePositionDemand { 6 | public Vector3d newPos; 7 | 8 | public NetworkMovePositionDemand(){ 9 | 10 | } 11 | 12 | public NetworkMovePositionDemand(Vector3d newPos){ 13 | this.newPos = newPos; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/engine/network/ItemPickupNotification.java: -------------------------------------------------------------------------------- 1 | package engine.network; 2 | 3 | public class ItemPickupNotification { 4 | public String name; 5 | public int stack; 6 | 7 | public ItemPickupNotification(){ 8 | } 9 | 10 | public ItemPickupNotification(String name, int stack){ 11 | this.name = name; 12 | this.stack = stack; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /resources/hud_vertex.vs: -------------------------------------------------------------------------------- 1 | #version 440 2 | 3 | layout (location =0) in vec3 position; 4 | layout (location =1) in vec3 inColor; 5 | layout (location =2) in vec2 texCoord; 6 | 7 | out vec3 exColor; 8 | out vec2 outTexCoord; 9 | 10 | uniform mat4 modelViewMatrix; 11 | 12 | void main() 13 | { 14 | gl_Position = modelViewMatrix * vec4(position, 1.0); 15 | exColor = inColor; 16 | outTexCoord = texCoord; 17 | } -------------------------------------------------------------------------------- /resources/entity_fragment.fs: -------------------------------------------------------------------------------- 1 | #version 440 2 | 3 | in vec3 exColor; 4 | in vec2 outTexCoord; 5 | 6 | out vec4 fragColor; 7 | 8 | uniform sampler2D texture_sampler; 9 | 10 | 11 | void main() 12 | { 13 | //export the processed matrix to a pixel 14 | vec4 p = texture( texture_sampler, outTexCoord); 15 | 16 | if (p.a == 0.0) { 17 | discard; 18 | } 19 | 20 | fragColor = p * vec4(exColor, 1.0); 21 | } -------------------------------------------------------------------------------- /resources/glasslike_fragment.fs: -------------------------------------------------------------------------------- 1 | #version 440 2 | 3 | in vec3 exColor; 4 | in vec2 outTexCoord; 5 | 6 | out vec4 fragColor; 7 | 8 | uniform sampler2D texture_sampler; 9 | 10 | void main() 11 | { 12 | 13 | //export the processed matrix to a pixel 14 | vec4 p = texture( texture_sampler, outTexCoord); 15 | 16 | if (p.a == 0) { 17 | discard; 18 | } 19 | 20 | fragColor = p * vec4(exColor, 1.0); 21 | } -------------------------------------------------------------------------------- /src/main/java/engine/network/ChunkRequest.java: -------------------------------------------------------------------------------- 1 | package engine.network; 2 | public class ChunkRequest { 3 | public String name; 4 | public int x; 5 | public int z; 6 | 7 | //null creation 8 | public ChunkRequest(){ 9 | } 10 | 11 | //data creation 12 | public ChunkRequest(int x, int z, String name){ 13 | this.name = name; 14 | this.x = x; 15 | this.z = z; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/game/blocks/BlockModifier.java: -------------------------------------------------------------------------------- 1 | package game.blocks; 2 | 3 | import game.chunk.Chunk; 4 | 5 | public interface BlockModifier { 6 | 7 | default void onDig(double posX, double posY, double posZ, Chunk chunk) { 8 | 9 | } 10 | 11 | default void onPlace(int posX, int posY, int posZ, Chunk chunk) { 12 | 13 | } 14 | 15 | default void onRightClick(int posX, int posY, int posZ, Chunk chunk){ 16 | 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /resources/hud_fragment.fs: -------------------------------------------------------------------------------- 1 | #version 440 2 | 3 | in vec3 exColor; 4 | in vec2 outTexCoord; 5 | 6 | out vec4 fragColor; 7 | 8 | uniform sampler2D texture_sampler; 9 | 10 | 11 | //this is performed parallel in the GPU 12 | void main() 13 | { 14 | //export the processed matrix to a pixel 15 | vec4 p = texture( texture_sampler, outTexCoord); 16 | 17 | if (p.a == 0) { 18 | discard; 19 | } 20 | 21 | fragColor = p * vec4(exColor, 1.0); 22 | } -------------------------------------------------------------------------------- /resources/vertex.vs: -------------------------------------------------------------------------------- 1 | #version 440 2 | 3 | layout (location =0) in vec3 position; 4 | layout (location =1) in vec3 inColor; 5 | layout (location =2) in vec2 texCoord; 6 | 7 | out vec3 exColor; 8 | out vec2 outTexCoord; 9 | 10 | uniform mat4 modelViewMatrix; 11 | uniform mat4 projectionMatrix; 12 | 13 | void main() 14 | { 15 | gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0); 16 | exColor = inColor; 17 | outTexCoord = texCoord; 18 | } -------------------------------------------------------------------------------- /resources/glasslike_vertex.vs: -------------------------------------------------------------------------------- 1 | #version 440 2 | 3 | layout (location =0) in vec3 position; 4 | layout (location =1) in vec3 inColor; 5 | layout (location =2) in vec2 texCoord; 6 | 7 | out vec3 exColor; 8 | out vec2 outTexCoord; 9 | 10 | uniform mat4 modelViewMatrix; 11 | uniform mat4 projectionMatrix; 12 | 13 | void main() 14 | { 15 | gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0); 16 | exColor = inColor; 17 | outTexCoord = texCoord; 18 | } -------------------------------------------------------------------------------- /src/main/java/engine/network/BlockPlaceUpdate.java: -------------------------------------------------------------------------------- 1 | package engine.network; 2 | 3 | import org.joml.Vector3i; 4 | 5 | public class BlockPlaceUpdate { 6 | public Vector3i pos; 7 | public byte ID; 8 | public byte rot; 9 | 10 | public BlockPlaceUpdate(){ 11 | 12 | } 13 | 14 | public BlockPlaceUpdate(Vector3i newReceivedPos, byte ID, byte rot){ 15 | this.pos = newReceivedPos; 16 | this.ID = ID; 17 | this.rot = rot; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/engine/network/ItemSendingObject.java: -------------------------------------------------------------------------------- 1 | package engine.network; 2 | 3 | import org.joml.Vector3d; 4 | 5 | public class ItemSendingObject { 6 | public Vector3d pos; 7 | public String name; 8 | public int ID; 9 | 10 | //null initializer 11 | public ItemSendingObject(){ 12 | 13 | } 14 | 15 | public ItemSendingObject(Vector3d pos, int ID, String name){ 16 | this.pos = pos; 17 | this.ID = ID; 18 | this.name = name; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/engine/MemorySweeper.java: -------------------------------------------------------------------------------- 1 | package engine; 2 | 3 | 4 | public class MemorySweeper { 5 | public void cleanMemory(){ 6 | //System.out.println("sweeping memory!"); 7 | /* 8 | cleanItemMemory(); 9 | cleanChunkDataMemory(); 10 | cleanChatMemory(); 11 | cleanCloudMemory(); 12 | cleanInventoryMemory(); 13 | cleanFallingEntities(); 14 | cleanParticleMemory(); 15 | cleanOtherPLayerMemory(); 16 | */ 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/engine/settings/SettingsObject.java: -------------------------------------------------------------------------------- 1 | package engine.settings; 2 | 3 | public class SettingsObject { 4 | public boolean vSync; 5 | public boolean graphicsMode; 6 | public int renderDistance; 7 | public int keyForward; 8 | public int keyBack; 9 | public int keyLeft; 10 | public int keyRight; 11 | public int keySneak; 12 | public int keyDrop; 13 | public int keyJump; 14 | public int keyInventory; 15 | 16 | public SettingsObject(){ 17 | 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/game/light/LightUpdate.java: -------------------------------------------------------------------------------- 1 | package game.light; 2 | 3 | public class LightUpdate { 4 | public int x; 5 | public int y; 6 | public int z; 7 | public byte level; 8 | 9 | public LightUpdate(int x, int y, int z){ 10 | this.x = x; 11 | this.y = y; 12 | this.z = z; 13 | } 14 | 15 | public LightUpdate(int x, int y, int z, byte level){ 16 | this.x = x; 17 | this.y = y; 18 | this.z = z; 19 | this.level = level; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/game/entity/weather/RainDropEntity.java: -------------------------------------------------------------------------------- 1 | package game.entity.weather; 2 | 3 | import org.joml.Vector3d; 4 | import org.joml.Vector3f; 5 | 6 | public class RainDropEntity { 7 | public Vector3d pos; 8 | public Vector3f inertia; 9 | public float timer; 10 | public int key; 11 | 12 | public RainDropEntity(Vector3d pos, Vector3f inertia, int key){ 13 | this.pos = pos; 14 | this.inertia = inertia; 15 | this.timer = (float)Math.random()*2f; 16 | this.key = key; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/game/item/ItemModifier.java: -------------------------------------------------------------------------------- 1 | package game.item; 2 | 3 | import game.blocks.BlockDefinitionContainer; 4 | import org.joml.Vector3i; 5 | 6 | public interface ItemModifier { 7 | default void onPlace(Vector3i pos, Vector3i posAbove, BlockDefinitionContainer blockDefinitionContainer){ 8 | System.out.println("placing interface worked"); 9 | } 10 | default void onPickUp(Vector3i pos, Vector3i posAbove, BlockDefinitionContainer blockDefinitionContainer){ 11 | System.out.println("I'm picked up woooo"); 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/engine/disk/PlayerData.java: -------------------------------------------------------------------------------- 1 | package engine.disk; 2 | 3 | import org.joml.Vector3d; 4 | 5 | public class PlayerData { 6 | public String name; 7 | public String[][] inventory; 8 | public int[][] count; 9 | public Vector3d pos; 10 | public byte health; 11 | 12 | public PlayerData(String name, String[][] inventory, int[][] count, Vector3d pos, byte health){ 13 | this.name = name; 14 | this.inventory = inventory; 15 | this.count = count; 16 | this.pos = pos; 17 | this.health = health; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/engine/time/Delta.java: -------------------------------------------------------------------------------- 1 | package engine.time; 2 | 3 | import static java.lang.System.nanoTime; 4 | 5 | public class Delta { 6 | 7 | private double lastLoopTime = nanoTime(); 8 | private double delta; 9 | 10 | private double getTime() { 11 | return nanoTime(); 12 | } 13 | 14 | public void calculateDelta() { 15 | double time = getTime(); 16 | delta = (time - lastLoopTime) / 1_000_000_000; 17 | lastLoopTime = time; 18 | } 19 | 20 | public double getDelta() { 21 | return(delta); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/game/entity/EntityContainer.java: -------------------------------------------------------------------------------- 1 | package game.entity; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | public class EntityContainer { 7 | 8 | private final List entities = new ArrayList<>(); 9 | 10 | public void remove(Entity entity){ 11 | entities.remove(entity); 12 | } 13 | 14 | public void add(Entity entity){ 15 | entities.add(entity); 16 | } 17 | 18 | public List getAll(){ 19 | return entities; 20 | } 21 | 22 | public void onTick(){ 23 | 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/engine/disk/PrimitiveChunkObject.java: -------------------------------------------------------------------------------- 1 | package engine.disk; 2 | 3 | import org.joml.Vector2i; 4 | 5 | public class PrimitiveChunkObject { 6 | public Vector2i pos; 7 | public byte[] block; 8 | public byte[] rotation; 9 | public byte[] light; 10 | public byte[] heightMap; 11 | 12 | public PrimitiveChunkObject(Vector2i pos, byte[] block, byte[] rotation, byte[] light, byte[] heightMap){ 13 | this.pos = pos; 14 | this.block = block; 15 | this.rotation = rotation; 16 | this.light = light; 17 | this.heightMap = heightMap; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/game/crafting/CraftRecipeObject.java: -------------------------------------------------------------------------------- 1 | package game.crafting; 2 | 3 | public class CraftRecipeObject { 4 | private final String[][] recipe; 5 | private final String output; 6 | private final int amount; 7 | 8 | public CraftRecipeObject(String[][] recipe, String output, int amount){ 9 | this.recipe = recipe; 10 | this.output = output; 11 | this.amount = amount; 12 | } 13 | 14 | public String[][] getRecipe(){ 15 | return recipe; 16 | } 17 | 18 | public String getOutput(){ 19 | return output; 20 | } 21 | 22 | public int getAmount(){ 23 | return amount; 24 | } 25 | } -------------------------------------------------------------------------------- /resources/entity_vertex.vs: -------------------------------------------------------------------------------- 1 | #version 440 2 | 3 | layout (location =0) in vec3 position; 4 | layout (location =1) in vec3 inColor; 5 | layout (location =2) in vec2 texCoord; 6 | 7 | out vec3 exColor; 8 | out vec2 outTexCoord; 9 | 10 | uniform mat4 modelViewMatrix; 11 | uniform mat4 projectionMatrix; 12 | uniform float light; 13 | 14 | void main() 15 | { 16 | gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0); 17 | 18 | //turn the entity red if over 15 19 | if ( light > 15.0 ){ 20 | float newLight = light - 15; 21 | exColor = inColor * vec3(2,0.5,0.5) * pow(pow((newLight / 15.0),1.5),1.5); 22 | } else { 23 | exColor = inColor * pow(pow((light / 15.0),1.5),1.5); 24 | } 25 | outTexCoord = texCoord; 26 | } -------------------------------------------------------------------------------- /src/main/java/game/chunk/ChunkMeshData.java: -------------------------------------------------------------------------------- 1 | package game.chunk; 2 | 3 | public class ChunkMeshData { 4 | 5 | int chunkX; 6 | int chunkZ; 7 | int yHeight; 8 | 9 | //regular 10 | float[] positionsArray ; 11 | float[] lightArray; 12 | int[] indicesArray; 13 | float[] textureCoordArray; 14 | boolean normalMeshIsNull = false; 15 | 16 | //liquid 17 | float[] liquidPositionsArray ; 18 | float[] liquidLightArray; 19 | int[] liquidIndicesArray; 20 | float[] liquidTextureCoordArray; 21 | boolean liquidMeshIsNull = false; 22 | 23 | //allFaces 24 | float[] allFacesPositionsArray ; 25 | float[] allFacesLightArray; 26 | int[] allFacesIndicesArray; 27 | float[] allFacesTextureCoordArray; 28 | boolean allFacesMeshIsNull = false; 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/game/entity/mob/MobInterface.java: -------------------------------------------------------------------------------- 1 | package game.entity.mob; 2 | 3 | import engine.time.Delta; 4 | import game.chunk.Chunk; 5 | import game.entity.collision.Collision; 6 | 7 | //this is an Object which holds methods, amazing 8 | public interface MobInterface { 9 | //what a mob does each tick 10 | default void onTick(Chunk chunk, Collision collision, Mob thisMob, Delta delta){ 11 | 12 | } 13 | //what happens when a mob is spawned 14 | default void onSpawn(Mob mob, Delta delta){ 15 | 16 | } 17 | 18 | //what the mob does when right-clicked 19 | default void onRightClick(Mob thisMob, Delta delta){ 20 | 21 | } 22 | 23 | //what happens when the mob dies 24 | default void onDeath(Mob thisMob, Delta delta){ 25 | 26 | } 27 | 28 | //what the mob does when punched 29 | default void onPunch(Mob thisMob, Delta delta){ 30 | 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/game/entity/EntityInterface.java: -------------------------------------------------------------------------------- 1 | package game.entity; 2 | 3 | public interface EntityInterface { 4 | 5 | default void onSpawn(){ 6 | System.out.println("Welp I'm here now!"); 7 | } 8 | 9 | default void onTick(){ 10 | System.out.println("tick tock!"); 11 | } 12 | 13 | default void hurt(int damage){ 14 | System.out.println("That hurt " + damage + " amount!"); 15 | } 16 | 17 | default void onHeal(){ 18 | System.out.println("I'm feeling a bit better!"); 19 | } 20 | 21 | default void onHurt(){ 22 | System.out.println("Ouch!"); 23 | } 24 | 25 | default void onDeath(){ 26 | System.out.println("Oof I am le dead!"); 27 | } 28 | 29 | default void sayHi(){ 30 | System.out.println("hello hello hello hello"); 31 | } 32 | 33 | default void sayBye(){ 34 | System.out.println("Welp see you later!"); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/engine/sound/SoundListener.java: -------------------------------------------------------------------------------- 1 | package engine.sound; 2 | 3 | import org.joml.Vector3d; 4 | 5 | import static org.lwjgl.openal.AL10.*; 6 | 7 | final public class SoundListener { 8 | 9 | //0,0,0 is initial position 10 | public SoundListener(){ 11 | alListener3f(AL_POSITION, 0,0,0); 12 | alListener3f(AL_VELOCITY, 0,0,0); 13 | } 14 | 15 | public void setSoundSpeed(float speedX, float speedY, float speedZ){ 16 | alListener3f(AL_VELOCITY, speedX, speedY, speedZ); 17 | } 18 | 19 | //auto casted, sound imprecision is less noticeable 20 | public void setSoundPosition(Vector3d position){ 21 | alListener3f(AL_POSITION, (float)position.x,(float)position.y,(float)position.z); 22 | } 23 | 24 | public void setSoundOrientation(double atX, double atY, double atZ, double upX, double upY, double upZ){ 25 | float[] data = new float[]{ 26 | (float)atX, (float)atY, (float)atZ, 27 | (float)upX, (float)upY, (float)upZ 28 | }; 29 | alListenerfv(AL_ORIENTATION, data); 30 | } 31 | 32 | 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/engine/FancyMath.java: -------------------------------------------------------------------------------- 1 | package engine; 2 | 3 | import java.util.Random; 4 | 5 | public class FancyMath { 6 | private final Random random = new Random(); 7 | private final int[] dirArray = new int[]{-1,1}; 8 | 9 | 10 | 11 | public byte randomByte(byte value){ 12 | return (byte)random.nextInt(value); 13 | } 14 | 15 | //this variable does an int from min to max, but, it can also give you -max to -min 16 | //example: 5 to 10 can return -10 through -5 17 | //this is specifically designed for the mob spawning algorithm 18 | //this also has a horrible name 19 | public int randomIntFromMinToMaxNegativePositive(int min, int max){ 20 | int x = min + random.nextInt(max - min + 1); 21 | return x * dirArray[random.nextInt(2)]; 22 | } 23 | 24 | public float randomDirFloat(){ 25 | return dirArray[random.nextInt(2)]; 26 | } 27 | 28 | public float randomNumber(float x){ 29 | return (float)Math.random() * x; 30 | } 31 | 32 | public float randomForceValue(float x){ 33 | return randomNumber(x) * randomDirFloat(); 34 | } 35 | 36 | public double getDistance(double x1, double y1, double z1, double x2, double y2, double z2){ 37 | return Math.hypot((x1 - x2), Math.hypot((y1 - y2),(z1 - z2))); 38 | } 39 | 40 | public float convertLight(byte lightValue){ 41 | return (float) Math.pow(1.25, lightValue)/28.42171f; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/engine/sound/SoundSource.java: -------------------------------------------------------------------------------- 1 | package engine.sound; 2 | 3 | import static org.lwjgl.openal.AL10.*; 4 | 5 | public class SoundSource { 6 | private final int sourceId; 7 | 8 | public SoundSource(boolean loop, boolean relative){ 9 | this.sourceId = alGenSources(); 10 | 11 | if (loop){ 12 | alSourcei(sourceId, AL_LOOPING, AL_TRUE); 13 | } 14 | 15 | if(relative){ 16 | alSourcei(sourceId, AL_SOURCE_RELATIVE, AL_TRUE); 17 | } 18 | } 19 | 20 | public void setBuffer(int bufferId){ 21 | stop(); 22 | alSourcei(sourceId, AL_BUFFER, bufferId); 23 | } 24 | 25 | public void setPosition(float posX, float posY, float posZ){ 26 | alSource3f(sourceId, AL_POSITION, posX, posY, posZ); 27 | } 28 | 29 | public void setGain(float gain){ 30 | alSourcef(sourceId, AL_GAIN, gain); 31 | } 32 | 33 | public void setProperty(int param, float value){ 34 | alSourcef(sourceId, param, value); 35 | } 36 | 37 | public void play(){ 38 | alSourcePlay(sourceId); 39 | } 40 | 41 | public boolean isPlaying(){ 42 | return alGetSourcei(sourceId, AL_SOURCE_STATE) == AL_PLAYING; 43 | } 44 | 45 | public void pause(){ 46 | alSourcePause(sourceId); 47 | } 48 | 49 | public void stop(){ 50 | alSourceStop(sourceId); 51 | } 52 | 53 | public void cleanUp(){ 54 | stop(); 55 | alDeleteSources(sourceId); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/game/entity/tnt/Explosion.java: -------------------------------------------------------------------------------- 1 | package game.entity.tnt; 2 | 3 | import game.chunk.Chunk; 4 | import org.joml.Vector3d; 5 | import org.joml.Vector3i; 6 | 7 | public class Explosion { 8 | 9 | public void boom(Vector3d pos, int boomDistance, Chunk chunk) { 10 | //playSound("tnt_explode", pos.x, pos.y, pos.z, false); 11 | 12 | for (int x = (int)Math.floor(pos.x) - boomDistance; x < (int)Math.floor(pos.x) + boomDistance; x++) { 13 | for (int y = (int)Math.floor(pos.y) - boomDistance; y < (int)Math.floor(pos.y) + boomDistance; y++) { 14 | for (int z = (int)Math.floor(pos.z) - boomDistance; z < (int)Math.floor(pos.z) + boomDistance; z++) { 15 | if (getDistance(pos.x, pos.y, pos.z, x, y, z) <= boomDistance) { 16 | byte currentBlock = chunk.getBlock(new Vector3i(x, y, z)); 17 | //don't destroy bedrock 18 | if(currentBlock != 5) { 19 | chunk.setBlock(new Vector3i(x, y, z), (byte) 0, (byte) 0); 20 | if (currentBlock > 0 && currentBlock != 6 && Math.random() > 0.994) { 21 | //throwItem(getBlockName(currentBlock), x,y,z, 1,0); 22 | } else if (currentBlock == 6){ 23 | //createTNT(x, y, z, (float)(Math.random() * 1f) + 1.0f, false); 24 | } 25 | } 26 | } 27 | } 28 | } 29 | } 30 | 31 | //lightFloodFill((int)pos.x,(int)pos.y,(int)pos.z); 32 | } 33 | private double getDistance(double x1, double y1, double z1, double x2, double y2, double z2){ 34 | return Math.hypot((x1 - x2), Math.hypot((y1 - y2),(z1 - z2))); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/engine/highPerformanceContainers/MicroIntArray.java: -------------------------------------------------------------------------------- 1 | package engine.highPerformanceContainers; 2 | 3 | public class MicroIntArray { 4 | //growth rate defines how big the cache trim is 5 | //defines the initial size, limit of currentPos before it expands 6 | //and when it does expand, the array will grow to CURRENTSIZE + growthRate 7 | private final int growthRate; 8 | 9 | int[] dataContainer; 10 | 11 | int currentPos = 0; 12 | int maxSize; 13 | 14 | public MicroIntArray(int growthRate){ 15 | this.growthRate = growthRate; 16 | dataContainer = new int[growthRate]; 17 | maxSize = growthRate; 18 | } 19 | 20 | private void put(int data){ 21 | if (currentPos == maxSize){ 22 | grow(); 23 | } 24 | dataContainer[currentPos] = data; 25 | currentPos++; 26 | } 27 | 28 | //for the indices 29 | public void pack(int a, int b, int c, int d, int e, int f) { 30 | put(a); 31 | put(b); 32 | put(c); 33 | put(d); 34 | put(e); 35 | put(f); 36 | } 37 | 38 | public int size(){ 39 | return currentPos; 40 | } 41 | 42 | private void grow(){ 43 | int[] newContainer = new int[maxSize + growthRate]; 44 | 45 | if (maxSize >= 0) System.arraycopy(dataContainer, 0, newContainer, 0, maxSize); 46 | 47 | dataContainer = null; //send to GC 48 | dataContainer = newContainer; 49 | 50 | maxSize += growthRate; 51 | } 52 | 53 | 54 | public int[] values(){ 55 | int[] returningContainer = new int[currentPos]; 56 | System.arraycopy(dataContainer, 0, returningContainer, 0, currentPos); 57 | return returningContainer; 58 | } 59 | 60 | public void clear(){ 61 | dataContainer = null; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/engine/time/Timer.java: -------------------------------------------------------------------------------- 1 | package engine.time; 2 | 3 | import engine.Window; 4 | import engine.graphics.Mesh; 5 | import engine.gui.TextHandling; 6 | 7 | public class Timer { 8 | 9 | private final TextHandling textHandling = new TextHandling(); 10 | 11 | private Window window; 12 | private String versionName; 13 | private Mesh fpsMesh; 14 | 15 | public void setWindow(Window window){ 16 | if (this.window == null){ 17 | this.window = window; 18 | } 19 | } 20 | public void setVersionName(String versionName){ 21 | if (this.versionName == null){ 22 | this.versionName = versionName; 23 | } 24 | } 25 | 26 | private double lastFPSTime = System.nanoTime(); 27 | private double elapsedTime = 0; 28 | private int framesPerSecond = 0; 29 | 30 | public Timer(){ 31 | } 32 | 33 | 34 | private double getTime(){ 35 | return System.nanoTime(); 36 | } 37 | 38 | public void countFPS() { 39 | double time = getTime(); 40 | double currentElapsedTime = time - lastFPSTime; 41 | lastFPSTime = time; 42 | elapsedTime += currentElapsedTime; 43 | framesPerSecond++; 44 | if (elapsedTime >= 1_000_000_000) { 45 | window.updateTitle(versionName + " | FPS: " + framesPerSecond); 46 | //dumpHeapSize(); 47 | buildFPSMesh(framesPerSecond); 48 | framesPerSecond = 0; 49 | elapsedTime = 0; 50 | } 51 | } 52 | 53 | public void buildFPSMesh(int framesPerSecond) { 54 | if (fpsMesh != null) { 55 | fpsMesh.cleanUp(false); 56 | } 57 | fpsMesh = textHandling.createTextWithShadow("FPS: " + framesPerSecond, 1f, 1f, 1f); 58 | } 59 | 60 | public Mesh getFpsMesh(){ 61 | return this.fpsMesh; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/game/entity/mob/MobSpawning.java: -------------------------------------------------------------------------------- 1 | package game.entity.mob; 2 | 3 | import engine.time.Delta; 4 | import game.chunk.Chunk; 5 | import game.entity.EntityContainer; 6 | import game.player.Player; 7 | import org.joml.Vector3d; 8 | import org.joml.Vector3f; 9 | 10 | import java.util.Random; 11 | 12 | public class MobSpawning { 13 | private double spawnTimer = 1f; 14 | private final Random random = new Random(); 15 | 16 | public void runSpawningAlgorithm(Player player, Chunk chunk, Delta delta, MobMeshBuilder mobMeshBuilder, EntityContainer entityContainer){ 17 | int spawnLimit = 20; 18 | //having this not count up allows a minor cool down 19 | spawnTimer += delta.getDelta(); 20 | 21 | //every 3 seconds 22 | float spawnGoal = 3f; 23 | if (spawnTimer >= spawnGoal){ 24 | //CHANGE THIS TO CHECK FOR PLAYERS POSITION WHEN TRANSLATING TO MULTIPLAYER 25 | trySpawn(player.getPos(), chunk, mobMeshBuilder, entityContainer); 26 | spawnTimer = 0; 27 | } 28 | } 29 | 30 | 31 | //this is a square distance, acceptable is 24-56 blocks away from the player 32 | private void trySpawn(Vector3d pos, Chunk chunk, MobMeshBuilder mobMeshBuilder, EntityContainer entityContainer){ 33 | //BLARF 34 | if (true){ 35 | return; 36 | } 37 | //a 2d calculation 38 | int x = (int)pos.x + randomInt(24,56); 39 | int z = (int)pos.z + randomInt(24,56); 40 | int yPos = chunk.getMobSpawnYPos(x,z); 41 | if (yPos > 0){ 42 | //randomByte(9){ 43 | //} 44 | //spawnMob(randomByte((byte) 9), x, yPos, z, 0, 0, 0); 45 | new Zombie(mobMeshBuilder, entityContainer, new Vector3d(x, yPos, z), new Vector3f(0,0,0)); 46 | } 47 | } 48 | private final int[] dirArray = new int[]{-1,1}; 49 | 50 | public int randomInt(int min, int max){ 51 | int x = min + random.nextInt(max - min + 1); 52 | return x * dirArray[random.nextInt(2)]; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/engine/highPerformanceContainers/HyperIntArray.java: -------------------------------------------------------------------------------- 1 | package engine.highPerformanceContainers; 2 | 3 | //this container is specifically optimized for ChunkMeshGenerator 4 | //cache happy 5 | public class HyperIntArray { 6 | //growth rate defines how big the cache trim is 7 | //defines the initial size, limit of currentPos before it expands 8 | //and when it does expand, the array will grow to CURRENTSIZE + growthRate 9 | private final int growthRate; 10 | 11 | int[] dataContainer; 12 | 13 | int currentPos = 0; 14 | int maxSize; 15 | 16 | public HyperIntArray(int growthRate){ 17 | this.growthRate = growthRate; 18 | dataContainer = new int[growthRate]; 19 | maxSize = growthRate; 20 | } 21 | 22 | private void put(int data){ 23 | if (currentPos == maxSize){ 24 | grow(); 25 | } 26 | dataContainer[currentPos] = data; 27 | currentPos++; 28 | } 29 | 30 | //for the indices 31 | public void pack(int a, int b, int c, int d, int e, int f) { 32 | put(a); 33 | put(b); 34 | put(c); 35 | put(d); 36 | put(e); 37 | put(f); 38 | } 39 | 40 | public int size(){ 41 | return currentPos; 42 | } 43 | 44 | private void grow(){ 45 | int[] newContainer = new int[maxSize + growthRate]; 46 | 47 | if (maxSize >= 0) System.arraycopy(dataContainer, 0, newContainer, 0, maxSize); 48 | 49 | dataContainer = null; //send to GC 50 | dataContainer = newContainer; 51 | 52 | maxSize += growthRate; 53 | } 54 | 55 | 56 | public int[] values(){ 57 | int[] returningContainer = new int[currentPos]; 58 | System.arraycopy(dataContainer, 0, returningContainer, 0, currentPos); 59 | return returningContainer; 60 | } 61 | 62 | //is used to qualify the object for GC 63 | public void clear(){ 64 | dataContainer = null; 65 | } 66 | 67 | //is used to recycle the array - just resets the index to 0 68 | public void reset(){ 69 | currentPos = 0; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Crafter 0.08a 2 | 3 | A blocky game written in java with LWJGL 3 4 | 5 | Based off of what I've learned from Minetest's engine and lua api 6 | 7 | Discord: https://discord.gg/dRPyvubfyg 8 | 9 | IRC: #crafter on Libera (https://libera.chat/) 10 | 11 | Required Java version (JRE): 17 12 | 13 | You can get this version at: https://jdk.java.net/17/ 14 | 15 | Or you can install openJDK on most linux distros. 16 | 17 | Ubuntu: ``sudo apt install openjdk-17-jdk`` 18 | 19 | Fedora: ``sudo dnf install java-latest-openjdk-devel.x86_64`` 20 | 21 | To update default JRE: `sudo update-alternatives --config java` 22 | 23 | You can try these flags for a performance boost, if you want. These are experimental. 24 | 25 | ` 26 | -Xmx1G -XX:-UseAdaptiveSizePolicy -XX:-UseParallelGC -Xmn128M 27 | ` 28 | 29 | # Building with ANT: 30 | 31 | ### If you know how to improve the ant build script, feel free to. 32 | 33 | You must install ANT (Another Neat Tool) for the build to work. 34 | 35 | Once you have ANT installed, you can simply CD to the Crafter directory. 36 | 37 | Check build.properties to make sure that ``jdk.home.17=`` is pointing to your openJDK 17 install. 38 | 39 | You can find this with: ``readlink -f $(which java)`` (Don't copy the bin/java part) 40 | 41 | Run ``ant -keep-going`` 42 | 43 | Once it says build successful, you must create a folder for the game, preferably on your desktop. 44 | 45 | Drop the jar from the build directory (WHEREVER/Crafter/out/artifacts/Crafter_jar/Crafter.jar) to your new folder directory. 46 | 47 | Copy the /textures/ and /sounds/ folders into the new directory. 48 | 49 | You should now be able to run the game using java -jar Crafter.jar in the folder you created, or double clicking the jar in Windows. 50 | 51 | # Todo List: (This is probably outdated) 52 | 53 | 1. Modularize things - less hardcoded implementations 54 | 55 | 56 | ## Stargazers over time 57 | 58 | [![Stargazers over time](https://starchart.cc/jordan4ibanez/Crafter.svg)](https://starchart.cc/jordan4ibanez/Crafter) 59 | 60 | If you want to see the first ever commit done to this project: 61 | 62 | https://github.com/oilboi/Crafter/commit/282313ab6d3f3041e385161907d0b551240f3cbd 63 | 64 | This was done on my secondary account. -------------------------------------------------------------------------------- /src/main/java/game/player/ViewBobbing.java: -------------------------------------------------------------------------------- 1 | package game.player; 2 | 3 | import engine.time.Delta; 4 | import org.joml.Vector3f; 5 | 6 | 7 | public class ViewBobbing { 8 | 9 | private final Player player; 10 | private final Delta delta; 11 | 12 | public ViewBobbing(Player player, Delta delta){ 13 | this.player = player; 14 | this.delta = delta; 15 | } 16 | 17 | private final Vector3f viewBobbing = new Vector3f(0,0,0); 18 | private boolean xPositive = true; 19 | private float xBobPos = 0; 20 | private float yBobPos = 0; 21 | 22 | public void applyViewBobbing() { 23 | 24 | double delta = this.delta.getDelta(); 25 | 26 | double viewBobbingAddition = delta * 250f; 27 | 28 | //System.out.println(viewBobbingAddition); 29 | 30 | if (player.isRunning()){ 31 | viewBobbingAddition = delta * 290f; 32 | } 33 | 34 | if (xPositive) { 35 | xBobPos += viewBobbingAddition; 36 | if (xBobPos >= 50f){ 37 | xBobPos = 50f; 38 | xPositive = false; 39 | //playSound("dirt_" + (int)(Math.ceil(Math.random()*3))); 40 | } 41 | } else { 42 | xBobPos -= viewBobbingAddition; 43 | if (xBobPos <= -50f){ 44 | xBobPos = -50f; 45 | xPositive = true; 46 | //playSound("dirt_" + (int)(Math.ceil(Math.random()*3))); 47 | } 48 | } 49 | 50 | yBobPos = Math.abs(xBobPos); 51 | 52 | viewBobbing.x = xBobPos/700f; 53 | viewBobbing.y = yBobPos/800f; 54 | } 55 | 56 | public void returnPlayerViewBobbing(){ 57 | 58 | double delta = this.delta.getDelta(); 59 | 60 | if ((Math.abs(xBobPos)) <= 300 * delta){ 61 | xBobPos = 0; 62 | } 63 | 64 | if (xBobPos > 0){ 65 | xBobPos -= 300 * delta; 66 | } else if (xBobPos < 0){ 67 | xBobPos += 300 * delta; 68 | } 69 | 70 | yBobPos = Math.abs(xBobPos); 71 | 72 | viewBobbing.x = xBobPos/700f; 73 | viewBobbing.y = yBobPos/800f; 74 | } 75 | 76 | public Vector3f getPlayerViewBobbing(){ 77 | return viewBobbing; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/main/java/game/clouds/Cloud.java: -------------------------------------------------------------------------------- 1 | package game.clouds; 2 | 3 | import engine.FastNoise; 4 | import engine.graphics.Mesh; 5 | import engine.time.Delta; 6 | import org.joml.Vector2i; 7 | 8 | public class Cloud { 9 | 10 | private Delta delta; 11 | 12 | public void setDelta(Delta delta){ 13 | if (this.delta == null){ 14 | this.delta = delta; 15 | } 16 | } 17 | 18 | private final CloudMesh cloudMesh = new CloudMesh(this); 19 | 20 | //this holds the data from when the clouds are generated overhead 21 | private final boolean[][] cloudData = new boolean[16][16]; 22 | 23 | private final Vector2i cloudPos = new Vector2i(0,0); 24 | 25 | private int cloudOffset = 0; 26 | private float cloudScroll = 0f; 27 | 28 | public void cleanCloudMemory(){ 29 | cloudScroll = 0; 30 | cloudOffset = 0; 31 | cloudPos.x = 0; 32 | cloudPos.y = 0; 33 | } 34 | 35 | public void makeCloudsMove(){ 36 | cloudScroll += delta.getDelta(); 37 | 38 | if (cloudScroll >= cloudScale){ 39 | 40 | cloudScroll -= cloudScale; 41 | 42 | cloudOffset--; 43 | 44 | generateCloudData(); 45 | } 46 | } 47 | 48 | public float getCloudScroll(){ 49 | return cloudScroll; 50 | } 51 | 52 | public void setCloudPos(int x, int z){ 53 | cloudPos.set(x,z); 54 | generateCloudData(); 55 | } 56 | 57 | public Vector2i getCloudPos(){ 58 | return cloudPos; 59 | } 60 | 61 | final private float cloudScale = 16f; 62 | 63 | public float getCloudScale(){ 64 | return cloudScale; 65 | } 66 | 67 | private final Mesh cloud2DMesh = this.cloudMesh.buildCloud2DMesh(); 68 | private final Mesh cloud3DMesh = this.cloudMesh.buildCloud3DMesh(); 69 | 70 | public Mesh getCloud2DMesh(){ 71 | return cloud2DMesh; 72 | } 73 | 74 | public Mesh getCloud3DMesh(){ 75 | return cloud3DMesh; 76 | } 77 | 78 | 79 | public boolean[][] getCloudData(){ 80 | return cloudData; 81 | } 82 | 83 | private final FastNoise noise = new FastNoise(); 84 | 85 | 86 | public void generateCloudData(){ 87 | for (byte x = 0; x < 16; x++){ 88 | for (byte z = 0; z < 16; z++){ 89 | cloudData[x][z] = noise.GetWhiteNoise(x + cloudPos.x, z + cloudPos.y + cloudOffset) > 0.6f; 90 | } 91 | } 92 | } 93 | 94 | 95 | } 96 | -------------------------------------------------------------------------------- /src/main/java/game/entity/mob/MobDefinition.java: -------------------------------------------------------------------------------- 1 | package game.entity.mob; 2 | 3 | import engine.graphics.Mesh; 4 | import org.joml.Vector3f; 5 | 6 | 7 | final public class MobDefinition { 8 | 9 | 10 | private final Mesh[] bodyMeshes; 11 | private final MobInterface mobInterface; 12 | private final String name; 13 | private final Vector3f[] bodyOffsets; 14 | private final Vector3f[] bodyRotations; 15 | private final float height; 16 | private final float width; 17 | private final String hurtSound; 18 | private final byte baseHealth; 19 | private final boolean backFaceCulling; 20 | 21 | public MobDefinition(String name, String hurtSound, boolean backFaceCulling, byte baseHealth, Mesh[] bodyMeshes,Vector3f[] bodyOffsets, Vector3f[] bodyRotations, float height, float width, MobInterface mobInterface){ 22 | this.bodyMeshes = bodyMeshes; 23 | this.mobInterface = mobInterface; 24 | this.name = name; 25 | this.bodyOffsets = bodyOffsets; 26 | this.bodyRotations = bodyRotations; 27 | this.height = height; 28 | this.width = width; 29 | this.hurtSound = hurtSound; 30 | this.baseHealth = baseHealth; 31 | this.backFaceCulling = backFaceCulling; 32 | } 33 | 34 | //entry point 35 | //todo: make this not a confusing linkage 36 | /* 37 | public void registerMobs(){ 38 | Human.registerHumanMob(); 39 | Pig.registerPigMob(); 40 | Zombie.registerZombieMob(); 41 | Exploder.registerExploderMob(); 42 | Skeleton.registerSkeletonMob(); 43 | Sheep.registerSheepMob(); 44 | Chicken.registerChickenMob(); 45 | Cow.registerCowMob(); 46 | } 47 | */ 48 | 49 | public Mesh[] getBodyMeshes(){ 50 | return bodyMeshes; 51 | } 52 | public MobInterface getInterface(){ 53 | return mobInterface; 54 | } 55 | public String getName(){ 56 | return name; 57 | } 58 | public Vector3f[] getBodyOffsets(){ 59 | return bodyOffsets; 60 | } 61 | public Vector3f[] getBodyRotations(){ 62 | return bodyRotations; 63 | } 64 | public float getHeight(){ 65 | return height; 66 | } 67 | public float getWidth(){ 68 | return width; 69 | } 70 | public String getHurtSound(){ 71 | return hurtSound; 72 | } 73 | public byte getBaseHealth(){ 74 | return baseHealth; 75 | } 76 | public boolean getBackFaceCulling(){ 77 | return backFaceCulling; 78 | } 79 | 80 | } 81 | -------------------------------------------------------------------------------- /src/main/java/engine/highPerformanceContainers/MicroFloatArray.java: -------------------------------------------------------------------------------- 1 | package engine.highPerformanceContainers; 2 | 3 | public class MicroFloatArray { 4 | //growth rate defines how big the cache trim is 5 | //defines the initial size, limit of currentPos before it expands 6 | //and when it does expand, the array will grow to CURRENTSIZE + growthRate 7 | private final int growthRate; 8 | 9 | float[] dataContainer; 10 | 11 | int currentPos = 0; 12 | int maxSize; 13 | 14 | public MicroFloatArray(int growthRate){ 15 | this.growthRate = growthRate; 16 | dataContainer = new float[growthRate]; 17 | maxSize = growthRate; 18 | } 19 | 20 | 21 | //this is old delete it 22 | private void put(float data){ 23 | if (currentPos == maxSize){ 24 | grow(); 25 | } 26 | dataContainer[currentPos] = data; 27 | currentPos++; 28 | } 29 | 30 | //for positions 31 | public void pack(float a, float b, float c, float d, float e, float f, float g, float h, float i, float j, float k, float l){ 32 | put(a); 33 | put(b); 34 | put(c); 35 | put(d); 36 | put(e); 37 | put(f); 38 | put(g); 39 | put(h); 40 | put(i); 41 | put(j); 42 | put(k); 43 | put(l); 44 | } 45 | 46 | //for texture coord 47 | public void pack(float a, float b, float c, float d, float e, float f, float g, float h){ 48 | put(a); 49 | put(b); 50 | put(c); 51 | put(d); 52 | put(e); 53 | put(f); 54 | put(g); 55 | put(h); 56 | } 57 | 58 | //for light data 59 | public void pack(float a){ 60 | for (byte i = 0; i < 12; i++){ 61 | put(a); 62 | } 63 | } 64 | 65 | 66 | 67 | public int size(){ 68 | return currentPos; 69 | } 70 | 71 | private void grow(){ 72 | float[] newContainer = new float[maxSize + growthRate]; 73 | 74 | if (maxSize >= 0) System.arraycopy(dataContainer, 0, newContainer, 0, maxSize); 75 | 76 | dataContainer = null; //send to GC 77 | dataContainer = newContainer; 78 | 79 | maxSize += growthRate; 80 | } 81 | 82 | public float[] values(){ 83 | float[] returningContainer = new float[currentPos]; 84 | System.arraycopy(dataContainer, 0, returningContainer, 0, currentPos); 85 | return returningContainer; 86 | } 87 | 88 | public void clear(){ 89 | dataContainer = null; 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/main/java/engine/sound/SoundBuffer.java: -------------------------------------------------------------------------------- 1 | package engine.sound; 2 | 3 | import engine.Utils; 4 | import org.lwjgl.stb.STBVorbisInfo; 5 | import org.lwjgl.system.MemoryStack; 6 | import org.lwjgl.system.MemoryUtil; 7 | 8 | import java.nio.ByteBuffer; 9 | import java.nio.IntBuffer; 10 | import java.nio.ShortBuffer; 11 | 12 | import static org.lwjgl.openal.AL10.*; 13 | import static org.lwjgl.stb.STBVorbis.*; 14 | import static org.lwjgl.system.MemoryUtil.NULL; 15 | 16 | public class SoundBuffer { 17 | 18 | private final Utils utils = new Utils(); 19 | public final int bufferId; 20 | 21 | private ShortBuffer pcm = null; 22 | private boolean lock = false; 23 | 24 | public SoundBuffer(String file) throws Exception{ 25 | this.bufferId = alGenBuffers(); 26 | try (STBVorbisInfo info = STBVorbisInfo.malloc()){ 27 | ShortBuffer pcm = readVorbis(file, 16 * 1024, info); 28 | 29 | //copy to buffer 30 | alBufferData(bufferId, info.channels() == 1 ? AL_FORMAT_MONO16 : AL_FORMAT_STEREO16, pcm, info.sample_rate()); 31 | } 32 | } 33 | 34 | public boolean isLocked(){ 35 | return lock; 36 | } 37 | 38 | public void setLock(boolean isLocked){ 39 | this.lock = isLocked; 40 | } 41 | 42 | public int getBufferId(){ 43 | return this.bufferId; 44 | } 45 | 46 | public void cleanUp() { 47 | alDeleteBuffers(this.bufferId); 48 | if (pcm != null){ 49 | MemoryUtil.memFree(pcm); 50 | } 51 | } 52 | 53 | private ShortBuffer readVorbis(String resource, int bufferSize, STBVorbisInfo info) throws Exception{ 54 | try(MemoryStack stack = MemoryStack.stackPush()) { 55 | ByteBuffer vorbis = utils.ioResourceToByteBuffer(resource, bufferSize); 56 | IntBuffer error = stack.mallocInt(1); 57 | long decoder = stb_vorbis_open_memory(vorbis, error, null); 58 | 59 | if (decoder == NULL) { 60 | throw new RuntimeException("Failed to open Ogg vorbis file. Error: " + error.get(0)); 61 | 62 | } 63 | 64 | stb_vorbis_get_info(decoder, info); 65 | 66 | int channels = info.channels(); 67 | 68 | int lengthSamples = stb_vorbis_stream_length_in_samples(decoder); 69 | 70 | pcm = MemoryUtil.memAllocShort(lengthSamples); 71 | 72 | pcm.limit(stb_vorbis_get_samples_short_interleaved(decoder, channels, pcm) * channels); 73 | 74 | stb_vorbis_close(decoder); 75 | 76 | return pcm; 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/main/java/game/mainMenu/Credits.java: -------------------------------------------------------------------------------- 1 | package game.mainMenu; 2 | 3 | 4 | import engine.graphics.Mesh; 5 | import engine.gui.MeshCreator2D; 6 | import engine.gui.TextHandling; 7 | 8 | public class Credits { 9 | 10 | private final TextHandling textHandling = new TextHandling(); 11 | private final MeshCreator2D meshCreator2D = new MeshCreator2D(); 12 | 13 | //all the stuff for the credits are stored here 14 | private final Mesh[] creditParts = new Mesh[19]; 15 | 16 | public Credits(){ 17 | this.initializeCredits(); 18 | } 19 | 20 | public Mesh[] getCreditMeshArray(){ 21 | return creditParts; 22 | } 23 | 24 | public Mesh getCreditMesh(int ID){ 25 | return creditParts[ID]; 26 | } 27 | 28 | private void initializeCredits() { 29 | creditParts[0] = textHandling.createTextCenteredWithShadow("Inspired by:", 1,1,1); 30 | creditParts[1] = meshCreator2D.create2DMesh(8.4375f,1f,"textures/minetest_logo.png"); 31 | creditParts[2] = meshCreator2D.create2DMesh(9.34782608696f,1f,"textures/mineclone2.png"); 32 | 33 | creditParts[3] = textHandling.createTextCenteredWithShadow("Programmer: jordan4ibanez", 1,1,1); 34 | creditParts[4] = meshCreator2D.create2DMesh(2f,2f,"textures/jordan4ibanez.png"); 35 | 36 | creditParts[5] = textHandling.createTextCenteredWithShadow("Textures: gerold55", 1,1,1); 37 | creditParts[6] = meshCreator2D.create2DMesh(2f,2f,"textures/tools/stonepick.png"); 38 | 39 | creditParts[7] = textHandling.createTextCenteredWithShadow("Textures: MineClone 2", 1,1,1); 40 | creditParts[8] = meshCreator2D.create2DMesh(9.34782608696f,1f,"textures/mineclone2.png"); 41 | 42 | creditParts[9] = textHandling.createTextCenteredWithShadow("Title Music: Dark Reaven Music", 1,1,1); 43 | creditParts[10] = meshCreator2D.create2DMesh(2f,2f,"textures/dark_reaven.png"); 44 | 45 | creditParts[11] = textHandling.createTextCenteredWithShadow("Java Library: LWJGL", 1,1,1); 46 | creditParts[12] = meshCreator2D.create2DMesh(2f,2f,"textures/lwjgl.png"); 47 | 48 | creditParts[13] = textHandling.createTextCenteredWithShadow("Sound Library: OpenAL", 1,1,1); 49 | creditParts[14] = meshCreator2D.create2DMesh(1.84049079755f,1f,"textures/openal.png"); 50 | 51 | creditParts[15] = textHandling.createTextCenteredWithShadow("OpenGL Library: GLFW", 1,1,1); 52 | creditParts[16] = meshCreator2D.create2DMesh(2f,2f,"textures/glfw.png"); 53 | 54 | creditParts[17] = textHandling.createTextCenteredWithShadow("Thank you for playing my game! :]", 1,1,1); 55 | creditParts[18] = meshCreator2D.create2DMesh(2f,2f,"textures/icon.png"); 56 | } 57 | } -------------------------------------------------------------------------------- /src/main/java/engine/highPerformanceContainers/HyperFloatArray.java: -------------------------------------------------------------------------------- 1 | package engine.highPerformanceContainers; 2 | 3 | //this container is specifically optimized for ChunkMeshGenerator 4 | //cache happy 5 | public class HyperFloatArray { 6 | //growth rate defines how big the cache trim is 7 | //defines the initial size, limit of currentPos before it expands 8 | //and when it does expand, the array will grow to CURRENTSIZE + growthRate 9 | private final int growthRate; 10 | 11 | float[] dataContainer; 12 | 13 | int currentPos = 0; 14 | int maxSize; 15 | 16 | public HyperFloatArray(int growthRate){ 17 | this.growthRate = growthRate; 18 | dataContainer = new float[growthRate]; 19 | maxSize = growthRate; 20 | } 21 | 22 | 23 | //this is old delete it 24 | private void put(float data){ 25 | if (currentPos == maxSize){ 26 | grow(); 27 | } 28 | dataContainer[currentPos] = data; 29 | currentPos++; 30 | } 31 | 32 | //for positions 33 | public void pack(float a, float b, float c, float d, float e, float f, float g, float h, float i, float j, float k, float l){ 34 | put(a); 35 | put(b); 36 | put(c); 37 | put(d); 38 | put(e); 39 | put(f); 40 | put(g); 41 | put(h); 42 | put(i); 43 | put(j); 44 | put(k); 45 | put(l); 46 | } 47 | 48 | //for texture coord 49 | public void pack(float a, float b, float c, float d, float e, float f, float g, float h){ 50 | put(a); 51 | put(b); 52 | put(c); 53 | put(d); 54 | put(e); 55 | put(f); 56 | put(g); 57 | put(h); 58 | } 59 | 60 | //for light data 61 | public void pack(float a){ 62 | for (byte i = 0; i < 12; i++){ 63 | put(a); 64 | } 65 | } 66 | 67 | 68 | 69 | public int size(){ 70 | return currentPos; 71 | } 72 | 73 | private void grow(){ 74 | float[] newContainer = new float[maxSize + growthRate]; 75 | 76 | if (maxSize >= 0) System.arraycopy(dataContainer, 0, newContainer, 0, maxSize); 77 | 78 | dataContainer = null; //send to GC 79 | dataContainer = newContainer; 80 | 81 | maxSize += growthRate; 82 | } 83 | 84 | public float[] values(){ 85 | float[] returningContainer = new float[currentPos]; 86 | System.arraycopy(dataContainer, 0, returningContainer, 0, currentPos); 87 | return returningContainer; 88 | } 89 | 90 | //is used to qualify the object for GC 91 | public void clear(){ 92 | dataContainer = null; 93 | } 94 | 95 | //is used to recycle the array - just resets the index to 0 96 | public void reset(){ 97 | currentPos = 0; 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /Crafter.iml: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /src/main/java/game/entity/Entity.java: -------------------------------------------------------------------------------- 1 | package game.entity; 2 | 3 | import engine.time.Delta; 4 | import game.chunk.Chunk; 5 | import org.joml.Vector3d; 6 | import org.joml.Vector3f; 7 | import org.joml.Vector3i; 8 | 9 | import java.util.UUID; 10 | 11 | import static org.joml.Math.floor; 12 | 13 | public abstract class Entity { 14 | 15 | private final EntityContainer entityContainer; 16 | 17 | private final Vector3d pos = new Vector3d(); 18 | private final Vector3d oldPos = new Vector3d(); 19 | private final Vector3i flooredPos = new Vector3i(); 20 | private final Vector3i oldFlooredPos = new Vector3i(); 21 | 22 | private final Vector3f inertia = new Vector3f(); 23 | 24 | private final UUID uuid = UUID.randomUUID(); 25 | 26 | private float timer = 0; 27 | private byte light = 15; 28 | private float lightUpdateTimer = 0f; 29 | 30 | private final float width; 31 | private final float height; 32 | 33 | private final boolean item; 34 | private final boolean mob; 35 | private final boolean particle; 36 | 37 | public Entity(EntityContainer entityContainer, Vector3d pos, Vector3f inertia, float width, float height, boolean item, boolean mob, boolean particle){ 38 | 39 | this.width = width; 40 | this.height = height; 41 | 42 | this.item = item; 43 | this.mob = mob; 44 | this.particle = particle; 45 | 46 | this.entityContainer = entityContainer; 47 | this.entityContainer.add(this); 48 | 49 | this.pos.set(pos); 50 | this.inertia.set(inertia); 51 | this.flooredPos.set((int) floor(pos.x), (int) floor(pos.y), (int) floor(pos.z)); 52 | this.oldFlooredPos.set((int) floor(pos.x), (int) floor(pos.y), (int) floor(pos.z)); 53 | } 54 | 55 | public void onTick(Chunk chunk, Delta delta) { 56 | 57 | lightUpdateTimer += delta.getDelta(); 58 | 59 | flooredPos.set((int) floor(getPos().x), (int) floor(getPos().y), (int) floor(getPos().z)); 60 | 61 | //poll local light every quarter second 62 | if (lightUpdateTimer >= 0.25f || !flooredPos.equals(oldFlooredPos)){ 63 | 64 | light = chunk.getLight(flooredPos.x, flooredPos.y, flooredPos.z); 65 | 66 | lightUpdateTimer = 0f; 67 | } 68 | 69 | oldFlooredPos.set(flooredPos); 70 | } 71 | public byte getLight() { 72 | return light; 73 | } 74 | 75 | public float getWidth(){ 76 | return width; 77 | } 78 | 79 | public float getHeight(){ 80 | return height; 81 | } 82 | 83 | public void delete(){ 84 | entityContainer.remove(this); 85 | } 86 | 87 | public UUID getUuid(){ 88 | return uuid; 89 | } 90 | 91 | public boolean isItem(){ 92 | return item; 93 | } 94 | 95 | public boolean isMob(){ 96 | return mob; 97 | } 98 | 99 | public boolean isParticle() { 100 | return particle; 101 | } 102 | 103 | public float getTimer(){ 104 | return timer; 105 | } 106 | 107 | public void setTimer(float timer){ 108 | this.timer = timer; 109 | } 110 | 111 | public Vector3d getPos(){ 112 | return pos; 113 | } 114 | 115 | public void setPos(Vector3d pos){ 116 | this.pos.set(pos); 117 | } 118 | 119 | public Vector3f getInertia(){ 120 | return inertia; 121 | } 122 | 123 | public void setInertia(Vector3f inertia){ 124 | this.inertia.set(inertia); 125 | } 126 | 127 | public Vector3d getOldPos() { 128 | return oldPos; 129 | } 130 | 131 | public void setOldPos(Vector3d pos){ 132 | oldPos.set(pos); 133 | } 134 | } 135 | -------------------------------------------------------------------------------- /src/main/java/game/entity/collision/CollisionObject.java: -------------------------------------------------------------------------------- 1 | package game.entity.collision; 2 | 3 | //collision object 4 | final public class CollisionObject { 5 | //these are two exclusive actors so that you can actually read implemented usage of this class 6 | //IE, if you only had block, when working with entities you read pointIsWithinBlock it'll make no sense 7 | final private double[] blockAABB = new double[6]; 8 | final private double[] entityAABB = new double[6]; 9 | 10 | //sets the REUSED memory object which is a simple double array 11 | //the Y point is the BASE of the object, the height is added to this 12 | //the X point is the CENTER of the object, with the width adding NEGATIVE and POSITIVE to the object <- might need to be refactored to half 13 | //the Z point is the CENTER of the object, with the width adding NEGATIVE and POSITIVE to the object <- might need to be refactored to half 14 | // 15 | //with this implementation, technically entities can utilize the AABB physics system that is used to 16 | //collide entities with blocks 17 | 18 | /* reuse this for entity solid collision if ever needed 19 | //rename the other method EntitySecond or something if this is ever required 20 | public void setAABBEntityFirst(double x, double y, double z, float width, float height){ 21 | blockAABB[0] = x-width; //left 22 | blockAABB[1] = y; //bottom 23 | blockAABB[2] = z-width; //back 24 | blockAABB[3] = x+width; //right 25 | blockAABB[4] = y+height; //top 26 | blockAABB[5] = z+width; //front 27 | } 28 | */ 29 | 30 | //autosetter for blockshapes - uses literal position and block shape 31 | public void setAABBBlock(float[] blockBox, int x, int y, int z){ 32 | blockAABB[0] = blockBox[0] + (double)x; //left 33 | blockAABB[1] = blockBox[1] + (double)y; //bottom 34 | blockAABB[2] = blockBox[2] + (double)z; //back 35 | blockAABB[3] = blockBox[3] + (double)x; //right 36 | blockAABB[4] = blockBox[4] + (double)y; //top 37 | blockAABB[5] = blockBox[5] + (double)z; //front 38 | } 39 | 40 | 41 | public void setAABBEntity(double x, double y, double z, float width, float height){ 42 | entityAABB[0] = x-width; //left 43 | entityAABB[1] = y; //bottom 44 | entityAABB[2] = z-width; //back 45 | entityAABB[3] = x+width; //right 46 | entityAABB[4] = y+height; //top 47 | entityAABB[5] = z+width; //front 48 | } 49 | 50 | //exclusive AABB for block to entity collision detection 51 | public boolean intersectsAABB() { 52 | 53 | return !( entityAABB[0] > blockAABB[3] || 54 | entityAABB[1] > blockAABB[4] || 55 | entityAABB[2] > blockAABB[5] || 56 | entityAABB[3] < blockAABB[0] || 57 | entityAABB[4] < blockAABB[1] || 58 | entityAABB[5] < blockAABB[2] ); 59 | 60 | } 61 | 62 | 63 | //exclusion AABB for single point in space for blocks 64 | public boolean pointIsWithinBlock(double x, double y, double z){ 65 | return !(blockAABB[0] > x || 66 | blockAABB[3] < x || 67 | blockAABB[1] > y || 68 | blockAABB[4] < y || 69 | blockAABB[2] > z || 70 | blockAABB[5] < z); 71 | } 72 | 73 | //exlusion AABB for single point in space for entities 74 | public boolean pointIsWithinEntity(double x, double y, double z){ 75 | return !(entityAABB[0] > x || 76 | entityAABB[3] < x || 77 | entityAABB[1] > y || 78 | entityAABB[4] < y || 79 | entityAABB[2] > z || 80 | entityAABB[5] < z); 81 | } 82 | 83 | 84 | } 85 | -------------------------------------------------------------------------------- /src/main/java/engine/Utils.java: -------------------------------------------------------------------------------- 1 | package engine; 2 | 3 | import java.io.*; 4 | import java.nio.ByteBuffer; 5 | import java.nio.channels.Channels; 6 | import java.nio.channels.ReadableByteChannel; 7 | import java.nio.channels.SeekableByteChannel; 8 | import java.nio.charset.StandardCharsets; 9 | import java.nio.file.Files; 10 | import java.nio.file.Path; 11 | import java.nio.file.Paths; 12 | import java.util.ArrayList; 13 | import java.util.List; 14 | import java.util.Objects; 15 | import java.util.Scanner; 16 | 17 | import static org.lwjgl.BufferUtils.createByteBuffer; 18 | 19 | public class Utils { 20 | 21 | //load plain text file - external from JAR 22 | public String loadResource(String fileName){ 23 | File text = new File(fileName); 24 | Scanner scanner = null; 25 | try { 26 | scanner = new Scanner(text, StandardCharsets.UTF_8.name()); 27 | } catch (FileNotFoundException e) { 28 | e.printStackTrace(); 29 | } 30 | assert scanner != null; 31 | return scanner.useDelimiter("\\A").next(); 32 | } 33 | 34 | //save string as plain text - external from JAR 35 | public void saveResource(String fileName, String data) throws IOException{ 36 | FileWriter writer = new FileWriter(fileName); 37 | 38 | try (BufferedWriter bufferedWriter = new BufferedWriter(writer)) { 39 | bufferedWriter.write(data); 40 | } 41 | } 42 | 43 | //internal to JAR - needs refactor 44 | public List readAllLines(String fileName) throws Exception { 45 | List list = new ArrayList<>(); 46 | try (BufferedReader br = new BufferedReader(new InputStreamReader(Objects.requireNonNull(Class.forName(Utils.class.getName()).getResourceAsStream(fileName))))) { 47 | String line; 48 | while ((line = br.readLine()) != null) { 49 | list.add(line); 50 | } 51 | } 52 | return list; 53 | } 54 | 55 | public float[] listToArray(List list) { 56 | int size = list != null ? list.size() : 0; 57 | 58 | assert list != null; 59 | 60 | float[] floatArr = new float[size]; 61 | for (int i = 0; i < size; i++) { 62 | floatArr[i] = list.get(i); 63 | } 64 | return floatArr; 65 | } 66 | 67 | @SuppressWarnings("empty-statement") 68 | public ByteBuffer ioResourceToByteBuffer(String resource, int bufferSize) throws IOException{ 69 | ByteBuffer buffer; 70 | 71 | Path path = Paths.get(resource); 72 | 73 | if(Files.isReadable(path)){ 74 | try (SeekableByteChannel fc = Files.newByteChannel(path)){ 75 | buffer = createByteBuffer((int)fc.size()+1); 76 | 77 | while (fc.read(buffer) != -1); 78 | } 79 | } else{ 80 | try(InputStream source = Utils.class.getResourceAsStream(resource); ReadableByteChannel rbc = Channels.newChannel(source)){ 81 | buffer = createByteBuffer(bufferSize); 82 | 83 | while(true){ 84 | int bytes = rbc.read(buffer); 85 | if(bytes == -1){ 86 | break; 87 | } 88 | if(buffer.remaining() == 0){ 89 | buffer = resizeBuffer(buffer, buffer.capacity() * 2); 90 | } 91 | } 92 | } 93 | } 94 | 95 | buffer.flip(); 96 | return buffer; 97 | } 98 | 99 | private ByteBuffer resizeBuffer(ByteBuffer buffer, int newCapacity){ 100 | ByteBuffer newBuffer = createByteBuffer(newCapacity); 101 | buffer.flip(); 102 | newBuffer.put(buffer); 103 | return newBuffer; 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /src/main/java/engine/debug/RuntimeInfo.java: -------------------------------------------------------------------------------- 1 | package engine.debug; 2 | 3 | import engine.graphics.Mesh; 4 | import engine.time.Delta; 5 | 6 | public class RuntimeInfo { 7 | private final Mesh[] runtimeInfoText = new Mesh[6]; 8 | private long heapSize = 0; 9 | private long heapMaxSize = 0; 10 | private long heapFreeSize = 0; 11 | private long availableProcessors = 0; 12 | private int currentAmountOfThreads = 0; 13 | private int cpuHealth = 100; 14 | 15 | public RuntimeInfo(){ 16 | 17 | } 18 | 19 | public Mesh[] getRuntimeInfoText(){ 20 | return runtimeInfoText; 21 | } 22 | 23 | private float timer = 0f; 24 | 25 | private void doRuntimeInfoUpdate(Delta delta){ 26 | timer += delta.getDelta(); 27 | 28 | if (timer >= 0.5){ 29 | timer = 0f; 30 | updateRuntimeInfoText(); 31 | currentAmountOfThreads = 0; 32 | } 33 | 34 | //do THREAD and HEALTH calculation in real time 35 | 36 | /* 37 | if (Thread.activeCount() > currentAmountOfThreads) { 38 | // Get number of threads currently being utilized 39 | currentAmountOfThreads = Thread.activeCount(); 40 | // Show how much effort the CPU is exerting (Higher is better/Less cpu resources being used) 41 | cpuHealth = Math.round((((float)availableProcessors-((float)currentAmountOfThreads-1f)) / (float)availableProcessors) * 100.f); 42 | } 43 | */ 44 | } 45 | 46 | private void updateRuntimeInfoText(){ 47 | //update the info 48 | getHeapInfo(); 49 | 50 | /* 51 | //update the info text 52 | for (int i = 0; i < 6; i++) { 53 | if (runtimeInfoText[i] != null) { 54 | runtimeInfoText[i].cleanUp(false); 55 | } 56 | } 57 | runtimeInfoText[0] = createTextWithShadow("HEAP SIZE: " + formatSize(heapSize), 1,1,1); 58 | runtimeInfoText[1] = createTextWithShadow("HEAP MAX: " + formatSize(heapMaxSize), 1,1,1); 59 | runtimeInfoText[2] = createTextWithShadow("HEAP FREE: " + formatSize(heapFreeSize), 1,1,1); 60 | runtimeInfoText[3] = createTextWithShadow("# CPU UNITS: " + availableProcessors, 1,1,1); 61 | runtimeInfoText[4] = createTextWithShadow("# OF THREADS: " + currentAmountOfThreads, 1,1,1); 62 | if (cpuHealth < 30){ 63 | runtimeInfoText[5] = createTextWithShadow("CPU HEALTH: " + cpuHealth + "% (WARNING! CPU OVERLOAD!)", 1, 1, 1); 64 | } else { 65 | runtimeInfoText[5] = createTextWithShadow("CPU HEALTH: " + cpuHealth + "%", 1, 1, 1); 66 | } 67 | 68 | */ 69 | } 70 | 71 | //this is from: 72 | //https://stackoverflow.com/questions/2015463/how-to-view-the-current-heap-size-that-an-application-is-using 73 | private void getHeapInfo() { 74 | heapSize = Runtime.getRuntime().totalMemory(); 75 | // Get maximum size of heap in bytes. The heap cannot grow beyond this size.// Any attempt will result in an OutOfMemoryException. 76 | heapMaxSize = Runtime.getRuntime().maxMemory(); 77 | // Get amount of free memory within the heap in bytes. This size will increase // after garbage collection and decrease as new objects are created. 78 | heapFreeSize = Runtime.getRuntime().freeMemory(); 79 | 80 | System.out.println("---------------"); 81 | System.out.println("heap size: " + formatSize(heapSize)); 82 | System.out.println("heap max: " + formatSize(heapMaxSize)); 83 | System.out.println("heap free: " + formatSize(heapFreeSize)); 84 | 85 | // Get number of cpu threads available 86 | availableProcessors = Runtime.getRuntime().availableProcessors(); 87 | } 88 | 89 | private String formatSize(long v) { 90 | if (v < 1024) return v + " B"; 91 | int z = (63 - Long.numberOfLeadingZeros(v)) / 10; 92 | return String.format("%.1f %sB", (double)v / (1L << (z*10)), " KMGTPE".charAt(z)); 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /src/main/java/engine/graphics/Texture.java: -------------------------------------------------------------------------------- 1 | package engine.graphics; 2 | 3 | import org.lwjgl.system.MemoryStack; 4 | 5 | import java.nio.ByteBuffer; 6 | import java.nio.IntBuffer; 7 | 8 | import static org.lwjgl.opengl.GL44.*; 9 | import static org.lwjgl.stb.STBImage.*; 10 | 11 | final public class Texture { 12 | 13 | private final int ID; 14 | 15 | private final int width ; 16 | private final int height ; 17 | 18 | public Texture(String fileName) { 19 | 20 | final ByteBuffer buf; 21 | 22 | // Load Texture file 23 | try (MemoryStack stack = MemoryStack.stackPush()) { 24 | final IntBuffer w = stack.mallocInt(1); 25 | final IntBuffer h = stack.mallocInt(1); 26 | final IntBuffer channels = stack.mallocInt(1); 27 | 28 | buf = stbi_load(fileName, w, h, channels, 4); 29 | if (buf == null) { 30 | System.out.println("Image file [" + fileName + "] not loaded: " + stbi_failure_reason()); 31 | //throw new Exception("Image file [" + fileName + "] not loaded: " + stbi_failure_reason()); 32 | } 33 | 34 | this.width = w.get(); 35 | this.height = h.get(); 36 | } 37 | 38 | this.ID = createGLTexture(buf, this.width, this.height); 39 | 40 | //crash with assertion error instead of throwing exception 41 | assert buf != null; 42 | 43 | stbi_image_free(buf); 44 | } 45 | 46 | //create texture from image buffer 47 | public Texture(ByteBuffer imageBuffer) { 48 | final ByteBuffer buf; 49 | 50 | // Load Texture file 51 | try (MemoryStack stack = MemoryStack.stackPush()) { 52 | final IntBuffer w = stack.mallocInt(1); 53 | final IntBuffer h = stack.mallocInt(1); 54 | final IntBuffer channels = stack.mallocInt(1); 55 | 56 | buf = stbi_load_from_memory(imageBuffer, w, h, channels, 4); 57 | if (buf == null) { 58 | System.out.println("Image file not loaded: " + stbi_failure_reason()); 59 | //throw new Exception("Image file not loaded: " + stbi_failure_reason()); 60 | } 61 | 62 | this.width = w.get(); 63 | this.height = h.get(); 64 | } 65 | 66 | this.ID = createGLTexture(buf, this.width,this.height); 67 | 68 | //crash with assertion error instead of throwing exception 69 | assert buf != null; 70 | 71 | stbi_image_free(buf); 72 | } 73 | 74 | private int createGLTexture(ByteBuffer buf, int thisWidth, int thisHeight) { 75 | // Create a new OpenGL texture 76 | int textureId = glGenTextures(); 77 | // Bind the texture 78 | glBindTexture(GL_TEXTURE_2D, textureId); 79 | 80 | // Tell OpenGL how to unpack the RGBA bytes. Each component is 1 byte size 81 | glPixelStorei(GL_UNPACK_ALIGNMENT, 1); 82 | 83 | //GL LINEAR gives it a smoothened look like an n64 game 84 | //GL NEAREST gives it a blocky look 85 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 86 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 87 | 88 | //Do not repeat texture 89 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 90 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 91 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE); 92 | 93 | 94 | // Generate Mip Map 95 | //glGenerateMipmap(GL_TEXTURE_2D); 96 | 97 | // Upload the texture data 98 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, thisWidth, thisHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, buf); 99 | 100 | return textureId; 101 | } 102 | 103 | public int getID(){ 104 | return this.ID; 105 | } 106 | 107 | public int getWidth() { 108 | return this.width; 109 | } 110 | 111 | public int getHeight() { 112 | return this.height; 113 | } 114 | 115 | public void cleanUp() { 116 | glDeleteTextures(this.ID); 117 | } 118 | } -------------------------------------------------------------------------------- /src/main/java/game/crafting/InventoryObject.java: -------------------------------------------------------------------------------- 1 | package game.crafting; 2 | 3 | import org.joml.Vector2d; 4 | import org.joml.Vector2i; 5 | 6 | public class InventoryObject { 7 | 8 | private final String name; 9 | 10 | private final String[][] inventory; 11 | private final int[][] count; 12 | 13 | private final Vector2i selection = new Vector2i(-1,-1); 14 | private final Vector2d pos; 15 | private final Vector2i size; 16 | 17 | private final boolean mainInventory; 18 | 19 | public InventoryObject(String name, Vector2i size, Vector2d pos, boolean mainInventory){ 20 | this.name = name; 21 | this.inventory = new String[size.y][size.x]; 22 | this.count = new int[size.y][size.x]; 23 | this.size = new Vector2i(); 24 | this.pos = new Vector2d(pos); 25 | this.mainInventory = mainInventory; 26 | } 27 | 28 | public void setItem(int x, int y, String newItem, int newCount){ 29 | inventory[y][x] = newItem; 30 | count[y][x] = newCount; 31 | } 32 | 33 | public String getItem(int x, int y){ 34 | return inventory[y][x]; 35 | } 36 | 37 | public int getCount(int x, int y){ 38 | return count[y][x]; 39 | } 40 | 41 | public void setCount(int x, int y, int newCount){ 42 | count[y][x] = newCount; 43 | } 44 | 45 | public String[][] getInventoryAsArray(){ 46 | return inventory; 47 | } 48 | 49 | public int[][] getCountAsArray(){ 50 | return count; 51 | } 52 | 53 | public void deleteItem(int x, int y){ 54 | inventory[y][x] = null; 55 | count[y][x] = 0; 56 | } 57 | 58 | public void clear(){ 59 | for (int y = 0; y < size.y; y++) { 60 | for (int x = 0; x < size.x; x++) { 61 | inventory[y][x] = null; 62 | count[y][x] = 0; 63 | } 64 | } 65 | } 66 | 67 | 68 | public Vector2i getSelection(){ 69 | return selection; 70 | } 71 | public void setSelection(int x, int y){ 72 | selection.set(x,y); 73 | } 74 | 75 | 76 | public Vector2d getPos(){ 77 | return pos; 78 | } 79 | 80 | public Vector2i getSize(){ 81 | return size; 82 | } 83 | 84 | public String getName(){ 85 | return name; 86 | } 87 | 88 | public boolean addItem(String item){ 89 | //check whole inventory 90 | for (int y = 0; y < size.y; y++) { 91 | for (int x = 0; x < size.x; x++) { 92 | if (inventory[y][x] != null && inventory[y][x].equals(item) && count[y][x] < 64){ 93 | tickUpStack(x,y); 94 | /* 95 | if (getIfMultiplayer()){ 96 | System.out.println("oh nuuuu gotta fix this"); 97 | //sendServerUpdatedInventory(); 98 | } 99 | */ 100 | return true; 101 | } 102 | } 103 | } 104 | //failed to find one, create new stack 105 | for (int y = 0; y < 4; y++) { 106 | for (int x = 0; x < 9; x++) { 107 | if (inventory[y][x] == null){ 108 | inventory[y][x] = item; 109 | count[y][x] = 1; 110 | /* 111 | if (getIfMultiplayer()){ 112 | System.out.println("oh nuuuu gotta fix this"); 113 | //sendServerUpdatedInventory(); 114 | } 115 | */ 116 | return true; 117 | } 118 | } 119 | } 120 | return false; 121 | } 122 | 123 | public void removeItem(int x, int y){ 124 | if (count[y][x] > 0) { 125 | count[y][x]--; 126 | if (count[y][x] <= 0) { 127 | inventory[y][x] = null; 128 | count[y][x] = 0; 129 | } 130 | } else { 131 | inventory[y][x] = null; 132 | } 133 | } 134 | 135 | //internal 136 | private void tickUpStack(int x, int y){ 137 | count[y][x]++; 138 | } 139 | 140 | } 141 | -------------------------------------------------------------------------------- /src/main/java/engine/compression/Compression.java: -------------------------------------------------------------------------------- 1 | package engine.compression; 2 | 3 | import com.fasterxml.jackson.databind.ObjectMapper; 4 | import engine.disk.PrimitiveChunkObject; 5 | import game.chunk.ChunkData; 6 | import org.joml.Vector2i; 7 | 8 | import java.io.ByteArrayInputStream; 9 | import java.io.ByteArrayOutputStream; 10 | import java.io.IOException; 11 | import java.util.zip.GZIPInputStream; 12 | import java.util.zip.GZIPOutputStream; 13 | 14 | public class Compression { 15 | 16 | private final ObjectMapper mapper = new ObjectMapper(); 17 | 18 | public byte[] convertChunkToCompressedByteArray(ChunkData thisChunk) throws IOException { 19 | PrimitiveChunkObject savingObject = new PrimitiveChunkObject(new Vector2i(thisChunk.x, thisChunk.z), thisChunk.block, thisChunk.rotation, thisChunk.light, thisChunk.heightMap); 20 | 21 | String stringedChunk = mapper.writeValueAsString(savingObject); 22 | 23 | //data byte conversions 24 | ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(stringedChunk.getBytes()); 25 | 26 | 27 | //compression data stream 28 | ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); 29 | GZIPOutputStream gzipOutputStream = new GZIPOutputStream(byteArrayOutputStream); 30 | 31 | //walk through raw bytes 32 | byte[] buffer = new byte[4096]; 33 | int len; 34 | while((len=byteArrayInputStream.read(buffer)) != -1){ 35 | gzipOutputStream.write(buffer, 0, len); 36 | } 37 | 38 | //close resources 39 | //this needs to be before the final send 40 | //this is because the final pieces of data are written 41 | //when you close them 42 | gzipOutputStream.close(); 43 | byteArrayOutputStream.close(); 44 | byteArrayInputStream.close(); 45 | 46 | return byteArrayOutputStream.toByteArray(); 47 | } 48 | 49 | public ChunkData decompressByteArrayToChunkObject(byte[] bytes) throws IOException { 50 | 51 | //decoded output stream 52 | ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); 53 | 54 | //raw data and decompression data input streams 55 | ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes); 56 | GZIPInputStream gzipInputStream = new GZIPInputStream(byteArrayInputStream); 57 | 58 | //walk through raw bytes 59 | byte[] buffer = new byte[4096]; 60 | int len; 61 | while((len = gzipInputStream.read(buffer)) != -1){ 62 | byteArrayOutputStream.write(buffer, 0, len); 63 | } 64 | 65 | 66 | //close resources 67 | //this needs to be before the final send 68 | //this is because the final pieces of data are written 69 | //when you close them 70 | gzipInputStream.close(); 71 | byteArrayInputStream.close(); 72 | byteArrayOutputStream.close(); 73 | 74 | //create new generic chunk saving object 75 | PrimitiveChunkObject thisChunkLoaded; 76 | 77 | //attempt to convert it from the decompressed string using Jackson 78 | try { 79 | thisChunkLoaded = this.mapper.readValue(byteArrayOutputStream.toString(), PrimitiveChunkObject.class); 80 | } catch (IOException e) { 81 | //silently return null 82 | return null; 83 | } 84 | 85 | //double safety 86 | if (thisChunkLoaded == null){ 87 | return null; 88 | } 89 | 90 | //triple safety 91 | if (thisChunkLoaded.block == null){ 92 | return null; 93 | } 94 | 95 | //assign compressed variables to full variable names 96 | ChunkData abstractedChunk = new ChunkData(); 97 | 98 | abstractedChunk.x = thisChunkLoaded.pos.x; 99 | abstractedChunk.z = thisChunkLoaded.pos.y; 100 | abstractedChunk.block = thisChunkLoaded.block; 101 | abstractedChunk.rotation = thisChunkLoaded.rotation; 102 | abstractedChunk.light = thisChunkLoaded.light; 103 | abstractedChunk.heightMap = thisChunkLoaded.heightMap; 104 | 105 | return abstractedChunk; 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /src/main/java/game/entity/collision/MobCollision.java: -------------------------------------------------------------------------------- 1 | package game.entity.collision; 2 | 3 | import game.entity.Entity; 4 | import game.entity.EntityContainer; 5 | import game.entity.mob.Mob; 6 | import game.player.Player; 7 | import org.joml.Vector2d; 8 | import org.joml.Vector3d; 9 | import org.joml.Vector3f; 10 | 11 | import java.util.List; 12 | 13 | //basically cylindrical magnetic 2d collision detection class 14 | public class MobCollision { 15 | 16 | private EntityContainer entityContainer; 17 | 18 | public MobCollision(){ 19 | 20 | } 21 | 22 | public void setEntityContainer(EntityContainer entityContainer){ 23 | if (this.entityContainer == null){ 24 | this.entityContainer = entityContainer; 25 | } 26 | } 27 | 28 | private final Vector2d workerVec2D = new Vector2d(); 29 | private final Vector2d workerVec2D2 = new Vector2d(); 30 | private final Vector2d normalizedPos = new Vector2d(); 31 | 32 | /* 33 | public void mobSoftCollisionDetect(Entity thisEntity, Vector3d thisMobPos, float thisMobHeight, float thisMobWidth){ 34 | //get this mob's info 35 | workerVec2D.set(thisMobPos.x, thisMobPos.z); 36 | double thisBottom = thisMobPos.y; 37 | double thisTop = thisMobHeight + thisMobPos.y; 38 | 39 | List test = entityContainer.getAll(); 40 | 41 | for (Mob otherEntity : test){ 42 | 43 | if (!otherEntity.isMob() || otherEntity == thisEntity || otherEntity.getHealth() <= 0){ 44 | continue; 45 | } 46 | 47 | //get other mob's info 48 | float otherWidth = otherEntity.getWidth(); 49 | Vector3d otherPos = otherEntity.getPos(); 50 | workerVec2D2.set(otherPos.x, otherPos.z); 51 | 52 | //only continue if within 2D radius 53 | if (workerVec2D.distance(workerVec2D2) <= thisMobWidth + otherWidth) { 54 | 55 | float otherHeight = otherEntity.getHeight(); 56 | double otherBottom = otherPos.y; 57 | double otherTop = otherHeight + otherPos.y; 58 | 59 | //only continue if within - Y 1D collision detection 60 | if (!(thisTop < otherBottom) && !(thisBottom > otherTop)){ 61 | 62 | //success! 63 | 64 | //normalize values and make it not shoot mobs out 65 | normalizedPos.set(workerVec2D2).sub(workerVec2D).normalize().mul(0.05f); 66 | 67 | if (normalizedPos.isFinite()) { 68 | thisEntity.getInertia().add((float)normalizedPos.x,0,(float)normalizedPos.y); 69 | } 70 | } 71 | } 72 | } 73 | } 74 | */ 75 | public void mobSoftPlayerCollisionDetect(Entity thisMob, Vector3d thisMobPos, float thisMobHeight, float thisMobWidth, Player player){ 76 | //get this mob's info 77 | workerVec2D.set(thisMobPos.x, thisMobPos.z); 78 | double thisBottom = thisMobPos.y; 79 | double thisTop = thisMobHeight + thisMobPos.y; 80 | 81 | 82 | //get player's info 83 | float otherWidth = player.getWidth(); 84 | Vector3d otherPos = player.getPos(); 85 | workerVec2D2.set(otherPos.x, otherPos.z); 86 | 87 | //only continue if within 2D radius 88 | if (workerVec2D.distance(workerVec2D2) <= thisMobWidth + otherWidth) { 89 | 90 | float otherHeight = player.getHeight(); 91 | double otherBottom = otherPos.y; 92 | double otherTop = otherHeight + otherPos.y; 93 | 94 | //only continue if within - Y 1D collision detection 95 | if (!(thisTop < otherBottom) && !(thisBottom > otherTop)) { 96 | 97 | //success! 98 | 99 | //normalize values and make it not shoot mobs out 100 | normalizedPos.set(workerVec2D).sub(workerVec2D2).normalize().mul(0.05f); 101 | 102 | if (normalizedPos.isFinite()) { 103 | thisMob.getInertia().add((float)normalizedPos.x,0,(float)normalizedPos.y); 104 | player.addInertia(new Vector3f((float) -normalizedPos.x, 0, (float) -normalizedPos.y)); 105 | } 106 | } 107 | } 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /src/main/java/game/entity/weather/Weather.java: -------------------------------------------------------------------------------- 1 | package game.entity.weather; 2 | 3 | public class Weather { 4 | 5 | /* 6 | 7 | private final Map rainDrops = new HashMap<>(); 8 | private final Deque deletionQueue = new ArrayDeque<>(); 9 | private final Mesh rainDropMesh = createRainDropMesh(); 10 | private int currentID = 0; 11 | 12 | public void rainDropsOnTick(){ 13 | for (RainDropEntity thisParticle : rainDrops.values()){ 14 | boolean onGround = applyParticleInertia(thisParticle.pos, thisParticle.inertia, true,true); 15 | thisParticle.timer += 0.01f; 16 | if (thisParticle.timer > 10f || onGround){ 17 | deletionQueue.add(thisParticle.key); 18 | } 19 | } 20 | 21 | while (!deletionQueue.isEmpty()){ 22 | rainDrops.remove(deletionQueue.pop()); 23 | } 24 | } 25 | 26 | public void createRainDrop(Vector3d pos, Vector3f inertia){ 27 | rainDrops.put(currentID, new RainDropEntity(pos, inertia, currentID)); 28 | currentID++; 29 | } 30 | 31 | 32 | public Collection getRainDrops(){ 33 | return rainDrops.values(); 34 | } 35 | 36 | public Mesh getRainDropMesh(){ 37 | return rainDropMesh; 38 | } 39 | 40 | private Mesh createRainDropMesh() { 41 | float pixelScale = 0.25f; 42 | 43 | ArrayList positions = new ArrayList<>(); 44 | ArrayList textureCoord = new ArrayList<>(); 45 | ArrayList indices = new ArrayList<>(); 46 | ArrayList light = new ArrayList<>(); 47 | 48 | 49 | int indicesCount = 0; 50 | 51 | 52 | //front 53 | positions.add(pixelScale); 54 | positions.add(pixelScale*2); 55 | positions.add(0f); 56 | 57 | positions.add(-pixelScale); 58 | positions.add(pixelScale*2); 59 | positions.add(0f); 60 | 61 | positions.add(-pixelScale); 62 | positions.add(0f); 63 | positions.add(0f); 64 | 65 | positions.add(pixelScale); 66 | positions.add(0f); 67 | positions.add(0f); 68 | 69 | //front 70 | float frontLight = 1f;//getLight(x, y, z + 1, chunkX, chunkZ) / maxLight; 71 | 72 | //front 73 | for (int i = 0; i < 12; i++) { 74 | light.add(frontLight); 75 | } 76 | //front 77 | indices.add(0); 78 | indices.add(1 + indicesCount); 79 | indices.add(2 + indicesCount); 80 | indices.add(0); 81 | indices.add(2 + indicesCount); 82 | indices.add(3 + indicesCount); 83 | 84 | //-x +x -y +y 85 | // 0 1 2 3 86 | 87 | // 0, 1, 2, 3 88 | //-x,+x, -y,+y 89 | 90 | //front 91 | textureCoord.add(1f);//1 92 | textureCoord.add(0f);//2 93 | textureCoord.add(0f);//0 94 | textureCoord.add(0f);//2 95 | textureCoord.add(0f);//0 96 | textureCoord.add(1f);//3 97 | textureCoord.add(1f);//1 98 | textureCoord.add(1f);//3 99 | 100 | 101 | //convert the position objects into usable array 102 | float[] positionsArray = new float[positions.size()]; 103 | for (int i = 0; i < positions.size(); i++) { 104 | positionsArray[i] = positions.get(i); 105 | } 106 | 107 | //convert the light objects into usable array 108 | float[] lightArray = new float[light.size()]; 109 | for (int i = 0; i < light.size(); i++) { 110 | lightArray[i] = light.get(i); 111 | } 112 | 113 | //convert the indices objects into usable array 114 | int[] indicesArray = new int[indices.size()]; 115 | for (int i = 0; i < indices.size(); i++) { 116 | indicesArray[i] = indices.get(i); 117 | } 118 | 119 | //convert the textureCoord objects into usable array 120 | float[] textureCoordArray = new float[textureCoord.size()]; 121 | for (int i = 0; i < textureCoord.size(); i++) { 122 | textureCoordArray[i] = textureCoord.get(i); 123 | } 124 | 125 | return new Mesh(positionsArray, lightArray, indicesArray, textureCoordArray,new Texture("textures/raindrop.png")); 126 | } 127 | */ 128 | } 129 | -------------------------------------------------------------------------------- /src/main/java/engine/gui/MeshCreator2D.java: -------------------------------------------------------------------------------- 1 | package engine.gui; 2 | 3 | import engine.graphics.Mesh; 4 | import engine.graphics.Texture; 5 | 6 | public class MeshCreator2D { 7 | public Mesh create2DMesh(float width, float height, String texture) { 8 | float[] positions = new float[12]; 9 | float[] textureCoord = new float[8]; 10 | int[] indices = new int[6]; 11 | float[] light = new float[12]; 12 | 13 | positions[0] = (width); 14 | positions[1] = (height); 15 | positions[2] = (0f); 16 | positions[3] = (-width); 17 | positions[4] = (height); 18 | positions[5] = (0f); 19 | positions[6] = (-width); 20 | positions[7] = (-height); 21 | positions[8] = (0f); 22 | positions[9] = (width); 23 | positions[10] = (-height); 24 | positions[11] = (0f); 25 | 26 | for (int i = 0; i < 12; i++) { 27 | light[i] = 1f; 28 | } 29 | 30 | indices[0] = (0); 31 | indices[1] = (1); 32 | indices[2] = (2); 33 | indices[3] = (0); 34 | indices[4] = (2); 35 | indices[5] = (3); 36 | 37 | textureCoord[0] = (1f); 38 | textureCoord[1] = (0f); 39 | textureCoord[2] = (0f); 40 | textureCoord[3] = (0f); 41 | textureCoord[4] = (0f); 42 | textureCoord[5] = (1f); 43 | textureCoord[6] = (1f); 44 | textureCoord[7] = (1f); 45 | 46 | return new Mesh(positions, light, indices, textureCoord, new Texture(texture)); 47 | } 48 | 49 | public Mesh create2DMeshOffsetRight() { 50 | float[] positions = new float[12]; 51 | float[] textureCoord = new float[8]; 52 | int[] indices = new int[6]; 53 | float[] light = new float[12]; 54 | 55 | positions[0] = ((float) 0.5 *2f); 56 | positions[1] = ((float) 0.5); 57 | positions[2] = (0f); 58 | 59 | positions[3] = (0); 60 | positions[4] = ((float) 0.5); 61 | positions[5] = (0f); 62 | 63 | positions[6] = (0); 64 | positions[7] = (-(float) 0.5); 65 | positions[8] = (0f); 66 | 67 | positions[9] = ((float) 0.5 *2f); 68 | positions[10] = (-(float) 0.5); 69 | positions[11] = (0f); 70 | 71 | for (int i = 0; i < 12; i++) { 72 | light[i] = 1f; 73 | } 74 | 75 | indices[0] = (0); 76 | indices[1] = (1); 77 | indices[2] = (2); 78 | indices[3] = (0); 79 | indices[4] = (2); 80 | indices[5] = (3); 81 | 82 | textureCoord[0] = (1f); 83 | textureCoord[1] = (0f); 84 | textureCoord[2] = (0f); 85 | textureCoord[3] = (0f); 86 | textureCoord[4] = (0f); 87 | textureCoord[5] = (1f); 88 | textureCoord[6] = (1f); 89 | textureCoord[7] = (1f); 90 | 91 | return new Mesh(positions, light, indices, textureCoord, new Texture("textures/chat_box.png")); 92 | } 93 | 94 | //overloaded for texture width (used for half hearts) 95 | public Mesh createHalf2DMesh(float width, float height, float textureWidth, String texture) { 96 | float[] positions = new float[12]; 97 | float[] textureCoord = new float[8]; 98 | int[] indices = new int[6]; 99 | float[] light = new float[12]; 100 | 101 | positions[0] = (width - textureWidth); 102 | positions[1] = (height); 103 | positions[2] = (0f); 104 | positions[3] = (-width); 105 | positions[4] = (height); 106 | positions[5] = (0f); 107 | positions[6] = (-width); 108 | positions[7] = (-height); 109 | positions[8] = (0f); 110 | positions[9] = (width - textureWidth); 111 | positions[10] = (-height); 112 | positions[11] = (0f); 113 | 114 | for (int i = 0; i < 12; i++) { 115 | light[i] = 1f; 116 | } 117 | 118 | indices[0] = (0); 119 | indices[1] = (1); 120 | indices[2] = (2); 121 | indices[3] = (0); 122 | indices[4] = (2); 123 | indices[5] = (3); 124 | 125 | textureCoord[0] = (textureWidth); 126 | textureCoord[1] = (0f); 127 | textureCoord[2] = (0f); 128 | textureCoord[3] = (0f); 129 | textureCoord[4] = (0f); 130 | textureCoord[5] = (1f); 131 | textureCoord[6] = (textureWidth); 132 | textureCoord[7] = (1f); 133 | 134 | return new Mesh(positions, light, indices, textureCoord, new Texture(texture)); 135 | } 136 | } 137 | -------------------------------------------------------------------------------- /src/main/java/engine/graphics/ShaderProgram.java: -------------------------------------------------------------------------------- 1 | package engine.graphics; 2 | 3 | import org.joml.Matrix4d; 4 | import org.lwjgl.system.MemoryStack; 5 | 6 | import java.util.HashMap; 7 | import java.util.Map; 8 | 9 | import static org.lwjgl.opengl.GL44.*; 10 | 11 | public class ShaderProgram { 12 | private final int programId; 13 | private final int vertexShaderId; 14 | private final int fragmentShaderId; 15 | private final Map uniforms; 16 | 17 | public ShaderProgram(String vertexCode, String fragmentCode){ 18 | programId = glCreateProgram(); 19 | uniforms = new HashMap<>(); 20 | if (programId == 0){ 21 | try { 22 | throw new Exception("Could not create shader!"); 23 | } catch (Exception e) { 24 | e.printStackTrace(); 25 | } 26 | } 27 | vertexShaderId = createVertexShader(vertexCode); 28 | fragmentShaderId = createFragmentShader(fragmentCode); 29 | 30 | this.link(); 31 | } 32 | 33 | public void createUniform(String uniformName){ 34 | int uniformLocation = glGetUniformLocation(programId, uniformName); 35 | 36 | if (uniformLocation < 0) { 37 | try { 38 | throw new Exception("Could not find uniform: " + uniformName); 39 | } catch (Exception e) { 40 | e.printStackTrace(); 41 | } 42 | } 43 | uniforms.put(uniformName, uniformLocation); 44 | } 45 | 46 | public void setUniform(String uniformName, Matrix4d value){ 47 | // dump the matrix into a float buffer 48 | try(MemoryStack stack = MemoryStack.stackPush()){ 49 | glUniformMatrix4fv(uniforms.get(uniformName), false, value.get(stack.mallocFloat(16))); 50 | } 51 | } 52 | 53 | public void setLightUniform(String uniformName, float value){ 54 | // dump the byte into the new float buffer 55 | glUniform1f( uniforms.get(uniformName), value); 56 | 57 | } 58 | 59 | public void setUniform(String uniformName, int value) { 60 | glUniform1i(uniforms.get(uniformName), value); 61 | } 62 | 63 | private int createVertexShader(String shaderCode){ 64 | return createShader(shaderCode, GL_VERTEX_SHADER); 65 | } 66 | 67 | private int createFragmentShader(String shaderCode){ 68 | return createShader(shaderCode, GL_FRAGMENT_SHADER); 69 | } 70 | 71 | protected int createShader(String shaderCode, int shaderType){ 72 | int shaderId = glCreateShader(shaderType); 73 | if (shaderId == 0){ 74 | try { 75 | throw new Exception("Error creating shader. Type: " + shaderType); 76 | } catch (Exception e) { 77 | e.printStackTrace(); 78 | } 79 | } 80 | 81 | glShaderSource(shaderId, shaderCode); 82 | glCompileShader(shaderId); 83 | 84 | if (glGetShaderi(shaderId, GL_COMPILE_STATUS) == 0){ 85 | try { 86 | throw new Exception("Error compiling shader code: " + glGetShaderInfoLog(shaderId, 1024)); 87 | } catch (Exception e) { 88 | e.printStackTrace(); 89 | } 90 | } 91 | 92 | glAttachShader(programId, shaderId); 93 | 94 | return shaderId; 95 | } 96 | 97 | private void link(){ 98 | glLinkProgram(programId); 99 | if (glGetProgrami(programId, GL_LINK_STATUS) == 0){ 100 | try { 101 | throw new Exception("Error linking shader code: " + glGetProgramInfoLog(programId, 1024)); 102 | } catch (Exception e) { 103 | e.printStackTrace(); 104 | } 105 | } 106 | 107 | if(vertexShaderId != 0){ 108 | glDetachShader(programId, vertexShaderId); 109 | } 110 | 111 | if (fragmentShaderId != 0){ 112 | glDetachShader(programId, fragmentShaderId); 113 | } 114 | 115 | glValidateProgram(programId); 116 | 117 | if (glGetProgrami(programId, GL_VALIDATE_STATUS) == 0){ 118 | System.err.println("Warning validating shader code: " + glGetProgramInfoLog(programId, 1024)); 119 | } 120 | } 121 | 122 | public void bind(){ 123 | glUseProgram(programId); 124 | } 125 | 126 | public void unbind(){ 127 | glUseProgram(0); 128 | } 129 | 130 | public void cleanup(){ 131 | unbind(); 132 | if (programId != 0){ 133 | glDeleteProgram(programId); 134 | } 135 | } 136 | } 137 | -------------------------------------------------------------------------------- /src/main/java/engine/sound/SoundAPI.java: -------------------------------------------------------------------------------- 1 | package engine.sound; 2 | 3 | import engine.Window; 4 | import engine.graphics.Camera; 5 | import org.joml.Math; 6 | import org.joml.Vector3d; 7 | 8 | import static org.lwjgl.openal.AL10.AL_PITCH; 9 | 10 | public class SoundAPI { 11 | 12 | private SoundManager soundManager; 13 | private Camera camera; 14 | private Window window; 15 | 16 | public SoundAPI(){ 17 | 18 | } 19 | 20 | public void setCamera(Camera camera){ 21 | if (this.camera == null){ 22 | this.camera = camera; 23 | } 24 | } 25 | public void setWindow(Window window){ 26 | if (this.window == null){ 27 | this.window = window; 28 | this.soundManager = new SoundManager(this.camera, this.window); 29 | } 30 | } 31 | 32 | public void updateListenerPos(){ 33 | this.soundManager.updateListenerPosition(); 34 | } 35 | 36 | public void playSound(String name, float posX, float posY, float posZ, boolean randomPitch) { 37 | SoundBuffer soundBuffer = null; 38 | try { 39 | soundBuffer = new SoundBuffer("sounds/" + name + ".ogg"); 40 | } catch (Exception e) { 41 | e.printStackTrace(); 42 | } 43 | SoundSource thisSource = new SoundSource(false, false); 44 | assert soundBuffer != null; 45 | 46 | thisSource.setBuffer(soundBuffer.getBufferId()); 47 | 48 | thisSource.setPosition(posX, posY, posZ); 49 | 50 | if (randomPitch){ 51 | thisSource.setProperty(AL_PITCH, 0.75f + (float)(Math.random()/2f)); 52 | } 53 | 54 | soundManager.playSoundSource(soundBuffer, thisSource); 55 | } 56 | 57 | //overload for ease of use 58 | //intakes doubles XYZ and casts to float XYZ 59 | //precision is lost 60 | public void playSound(String name, double posX, double posY, double posZ, boolean randomPitch) { 61 | SoundBuffer soundBuffer = null; 62 | try { 63 | soundBuffer = new SoundBuffer("sounds/" + name + ".ogg"); 64 | } catch (Exception e) { 65 | e.printStackTrace(); 66 | } 67 | SoundSource thisSource = new SoundSource(false, false); 68 | 69 | assert soundBuffer != null; 70 | 71 | thisSource.setBuffer(soundBuffer.getBufferId()); 72 | 73 | thisSource.setPosition((float) posX, (float) posY, (float) posZ); 74 | 75 | if (randomPitch){ 76 | thisSource.setProperty(AL_PITCH, 0.75f + (float)(Math.random()/2f)); 77 | } 78 | 79 | soundManager.playSoundSource(soundBuffer, thisSource); 80 | } 81 | 82 | 83 | //locationless sound playing 84 | public SoundSource playSound(String name) { 85 | SoundBuffer soundBuffer = null; 86 | try { 87 | soundBuffer = new SoundBuffer("sounds/" + name + ".ogg"); 88 | } catch (Exception e) { 89 | e.printStackTrace(); 90 | } 91 | 92 | SoundSource thisSource = new SoundSource(false, true); 93 | 94 | assert soundBuffer != null; 95 | thisSource.setBuffer(soundBuffer.getBufferId()); 96 | 97 | soundManager.playSoundSource(soundBuffer, thisSource); 98 | 99 | return thisSource; 100 | } 101 | 102 | //puts music into the music buffer 103 | public SoundSource playMusic(String name) { 104 | SoundBuffer soundBuffer = null; 105 | try { 106 | soundBuffer = new SoundBuffer("sounds/" + name + ".ogg"); 107 | } catch (Exception e) { 108 | e.printStackTrace(); 109 | } 110 | assert soundBuffer != null; 111 | soundBuffer.setLock(true); 112 | SoundSource thisSource = new SoundSource(false, true); 113 | thisSource.setBuffer(soundBuffer.getBufferId()); 114 | soundManager.playSoundSource(soundBuffer, thisSource); 115 | return thisSource; 116 | } 117 | 118 | //play sound locationless with random pitch? 119 | public void playSound(String name, boolean randomPitch) { 120 | SoundBuffer soundBuffer = null; 121 | try { 122 | soundBuffer = new SoundBuffer("sounds/" + name + ".ogg"); 123 | } catch (Exception e) { 124 | e.printStackTrace(); 125 | } 126 | 127 | SoundSource thisSource = new SoundSource(false, true); 128 | 129 | assert soundBuffer != null; 130 | thisSource.setBuffer(soundBuffer.getBufferId()); 131 | thisSource.setProperty(AL_PITCH, 0.75f + (float)(Math.random()/2f)); 132 | 133 | soundManager.playSoundSource(soundBuffer, thisSource); 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /src/main/java/engine/sound/SoundManager.java: -------------------------------------------------------------------------------- 1 | package engine.sound; 2 | 3 | import engine.Window; 4 | import engine.graphics.Camera; 5 | import engine.graphics.Transformation; 6 | import org.joml.Vector3d; 7 | import org.lwjgl.openal.AL; 8 | import org.lwjgl.openal.AL11; 9 | import org.lwjgl.openal.ALC; 10 | import org.lwjgl.openal.ALCCapabilities; 11 | 12 | import java.nio.ByteBuffer; 13 | import java.nio.IntBuffer; 14 | 15 | import static org.lwjgl.openal.AL10.alDistanceModel; 16 | import static org.lwjgl.openal.ALC10.*; 17 | import static org.lwjgl.system.MemoryUtil.NULL; 18 | 19 | public class SoundManager { 20 | private final SoundListener soundListener; 21 | private final Window window; 22 | private final Transformation transformation; 23 | private final Camera camera; 24 | 25 | private long device; 26 | private long context; 27 | private int currentIndex = 0; 28 | private final int maxSounds = 64; 29 | 30 | private SoundBuffer[] soundBufferList = new SoundBuffer[maxSounds]; 31 | private SoundSource[] soundSourceArray = new SoundSource[maxSounds]; 32 | 33 | private final Vector3d at = new Vector3d(); 34 | private final Vector3d up = new Vector3d(); 35 | 36 | public SoundManager(Camera camera, Window window) { 37 | this.camera = camera; 38 | this.window = window; 39 | this.transformation = new Transformation(camera, window); 40 | 41 | device = alcOpenDevice((ByteBuffer) null); 42 | 43 | if(device == NULL){ 44 | throw new IllegalStateException("Failed to open the default OpenAL device"); 45 | } 46 | 47 | ALCCapabilities deviceCaps = ALC.createCapabilities(device); 48 | 49 | context = alcCreateContext(device, (IntBuffer) null); 50 | 51 | if(context == NULL){ 52 | throw new IllegalStateException("Failed to create OpenAL context"); 53 | } 54 | 55 | alcMakeContextCurrent(context); 56 | 57 | AL.createCapabilities(deviceCaps); 58 | 59 | setAttenuationModel(AL11.AL_LINEAR_DISTANCE); 60 | 61 | soundListener = new SoundListener(); 62 | } 63 | 64 | public void playSoundSource(SoundBuffer soundBuffer, SoundSource soundSource) { 65 | //THIS IS PRETTY HORRIBLE AND CAN CAUSE A FREEZE IF YOU PLAY 64 MUSIC TRACKS somehow 66 | //todo: make this better somehow 67 | boolean found = false; 68 | while (!found) { 69 | if (soundBufferList[currentIndex] != null && soundBufferList[currentIndex].isLocked()) { 70 | currentIndex++; 71 | if (currentIndex >= maxSounds) { 72 | currentIndex = 0; 73 | } 74 | continue; 75 | } 76 | found = true; 77 | if (soundBufferList[currentIndex] != null) { 78 | soundBufferList[currentIndex].cleanUp(); 79 | } 80 | soundBufferList[currentIndex] = soundBuffer; 81 | 82 | 83 | if (soundSourceArray[currentIndex] != null) { 84 | soundSourceArray[currentIndex].stop(); 85 | soundSourceArray[currentIndex].cleanUp(); 86 | } 87 | soundSourceArray[currentIndex] = soundSource; 88 | soundSourceArray[currentIndex].play(); 89 | 90 | currentIndex++; 91 | if (currentIndex >= maxSounds) { 92 | currentIndex = 0; 93 | } 94 | } 95 | } 96 | 97 | public void updateListenerPosition() { 98 | // Update camera matrix with camera data 99 | transformation.updateOpenALSoundMatrix(camera.getCameraPosition(), camera.getCameraRotation()); 100 | soundListener.setSoundPosition(camera.getCameraPosition()); 101 | transformation.getOpenALMatrix().positiveZ(at).negate(); 102 | transformation.getOpenALMatrix().positiveY(up); 103 | soundListener.setSoundOrientation(at.x, at.y, at.z, up.x, up.y, up.z); 104 | } 105 | 106 | public void setAttenuationModel(int model) { 107 | alDistanceModel(model); 108 | } 109 | 110 | public void cleanupSoundManager() { 111 | for (SoundSource soundSource : soundSourceArray) { 112 | if (soundSource != null) { 113 | soundSource.cleanUp(); 114 | } 115 | } 116 | 117 | soundSourceArray = null; 118 | 119 | for (SoundBuffer soundBuffer : soundBufferList) { 120 | if (soundBuffer != null) { 121 | soundBuffer.cleanUp(); 122 | } 123 | } 124 | 125 | soundBufferList = null; 126 | 127 | if (context != NULL) { 128 | alcDestroyContext(context); 129 | } 130 | 131 | if (device != NULL) { 132 | alcCloseDevice(device); 133 | } 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /src/main/java/engine/gui/GUIObject.java: -------------------------------------------------------------------------------- 1 | package engine.gui; 2 | 3 | import engine.graphics.Mesh; 4 | import org.joml.Vector2d; 5 | import org.joml.Vector2f; 6 | 7 | public class GUIObject { 8 | /* 9 | types: 10 | 0 - button 11 | 1 - text input 12 | 2 - just text 13 | */ 14 | 15 | private final TextHandling textHandling = new TextHandling(); 16 | public byte type; 17 | public Mesh textMesh; 18 | public Vector2d pos; 19 | public Vector2f buttonScale = new Vector2f(); 20 | public boolean selected; 21 | public String inputText; 22 | public char pointer; 23 | public float pointerTimer; 24 | 25 | //initializer for button (auto-scaled width) 26 | public GUIObject(String text, Vector2d pos){ 27 | this.textMesh = textHandling.createTextCentered(text, 1,1,1); 28 | float totalLengthReal = 0; 29 | //pre-poll the actual length 30 | for (char letter : text.toCharArray()) { 31 | float[] thisCharacterArray = textHandling.translateCharToArray(letter); 32 | totalLengthReal += thisCharacterArray[4] + 0.1f; 33 | } 34 | this.buttonScale.x = (totalLengthReal/2f) * 2.1f; 35 | this.buttonScale.y = 1.6f; 36 | this.pos = pos; 37 | this.type = 0; 38 | this.selected = false; 39 | } 40 | 41 | //initializer for button with fixed width 42 | public GUIObject(String text, Vector2d pos, float width){ 43 | this.textMesh = textHandling.createTextCenteredWithShadow(text, 1,1,1); 44 | this.buttonScale.x = width * 2.1f; 45 | this.buttonScale.y = 1.6f; 46 | this.pos = pos; 47 | this.type = 0; 48 | this.selected = false; 49 | } 50 | 51 | //initializer for generic text object 52 | public GUIObject(String text, boolean isJustText, Vector2d pos){ 53 | this.textMesh = textHandling.createTextCenteredWithShadow(text, 1,1,1); 54 | this.pos = pos; 55 | this.type = 2; 56 | this.selected = false; 57 | } 58 | 59 | //initializer for button with fixed width and height 60 | public GUIObject(String text, Vector2d pos, float width, float height){ 61 | this.textMesh = textHandling.createTextCenteredWithShadow(text, 1,1,1); 62 | this.buttonScale.x = width * 2.1f; 63 | this.buttonScale.y = height * 2.1f; 64 | this.pos = pos; 65 | this.type = 0; 66 | this.selected = false; 67 | } 68 | 69 | //initializer for text input box 70 | public GUIObject(Vector2d pos, float width, float height){ 71 | this.inputText = ""; 72 | this.textMesh = textHandling.createText(this.inputText, 1,1,1); 73 | this.buttonScale.x = width * 2.1f; 74 | this.buttonScale.y = height * 2.1f; 75 | this.pos = pos; 76 | this.type = 1; 77 | this.selected = false; 78 | this.pointerTimer = 0.5f; 79 | } 80 | 81 | 82 | 83 | //initializer for text input box with preset text 84 | public GUIObject(Vector2d pos, float width, float height, String existingText){ 85 | this.inputText = existingText; 86 | this.textMesh = textHandling.createText(this.inputText, 1,1,1); 87 | this.buttonScale.x = width * 2.1f; 88 | this.buttonScale.y = height * 2.1f; 89 | this.pos = pos; 90 | this.type = 1; 91 | this.selected = false; 92 | this.pointerTimer = 0.5f; 93 | } 94 | 95 | //updater for text input box 96 | public void updateInputBoxText(String text){ 97 | this.textMesh.cleanUp(false); 98 | this.textMesh = textHandling.createText(text, 1,1,1); 99 | } 100 | 101 | public String getInputText(){ 102 | return this.inputText; 103 | } 104 | 105 | //update statically scaled button text 106 | public void updateTextCenteredFixed(String text){ 107 | this.textMesh.cleanUp(false); 108 | this.textMesh = textHandling.createTextCenteredWithShadow(text, 1,1,1); 109 | } 110 | 111 | public void updateTextStandard(String text){ 112 | this.textMesh.cleanUp(false); 113 | this.textMesh = textHandling.createTextWithShadow(text, 1,1,1); 114 | } 115 | 116 | //updating dynamically scaled button text 117 | public void updateTextDynamic(String text){ 118 | this.textMesh.cleanUp(false); 119 | this.textMesh = textHandling.createTextCentered(text, 1,1,1); 120 | float totalLengthReal = 0; 121 | //pre-poll the actual length 122 | for (char letter : text.toCharArray()) { 123 | float[] thisCharacterArray = textHandling.translateCharToArray(letter); 124 | totalLengthReal += thisCharacterArray[4] + 0.1f; 125 | } 126 | this.buttonScale.x = (totalLengthReal/2f) * 2.1f; 127 | this.buttonScale.y = 1.6f; 128 | } 129 | } 130 | -------------------------------------------------------------------------------- /src/main/java/engine/Mouse.java: -------------------------------------------------------------------------------- 1 | package engine; 2 | 3 | import org.joml.Vector2d; 4 | import org.joml.Vector2f; 5 | 6 | import static org.lwjgl.glfw.GLFW.*; 7 | 8 | 9 | public class Mouse { 10 | 11 | private Window window; 12 | 13 | public Mouse(){ 14 | pos = new Vector2d(0); 15 | oldPos = new Vector2d(-1); 16 | displVec = new Vector2f(0); 17 | } 18 | 19 | public void setWindow(Window window){ 20 | if (this.window == null){ 21 | this.window = window; 22 | glfwSetCursorPosCallback(window.getHandle(), (windowHandle, xPos, yPos) -> { 23 | this.pos.x = xPos; 24 | this.pos.y = yPos; 25 | }); 26 | 27 | glfwSetCursorEnterCallback(window.getHandle(), (windowHandle, entered) -> inWindow = entered); 28 | 29 | glfwSetMouseButtonCallback(window.getHandle(), (windowHandle, button, action, mode) -> { 30 | leftButtonPressed = button == GLFW_MOUSE_BUTTON_1 && action == GLFW_PRESS; 31 | rightButtonPressed = button == GLFW_MOUSE_BUTTON_2 && action == GLFW_PRESS; 32 | }); 33 | 34 | glfwSetScrollCallback(window.getHandle(), (windowHandle, xOffset, yOffset) -> scroll = (float)yOffset); 35 | } 36 | } 37 | 38 | private final Vector2d oldPos; 39 | private final Vector2d pos; 40 | private final Vector2f displVec; 41 | 42 | 43 | private boolean inWindow = false; 44 | private boolean leftButtonPressed = false; 45 | private boolean rightButtonPressed = false; 46 | private boolean locked = true; 47 | private float scroll = 0; 48 | 49 | public void resetMousePosVector(){ 50 | glfwSetCursorPos(window.getHandle(),window.getWidth() / 2f,window.getHeight() / 2f ); 51 | 52 | double[] testx = new double[1]; 53 | double[] testy = new double[1]; 54 | 55 | glfwGetCursorPos(window.getHandle(), testx, testy); 56 | 57 | pos.set(window.getWidth() / 2f, window.getHeight() / 2f); 58 | 59 | oldPos.set(pos); 60 | } 61 | 62 | public Vector2f getDisplVec(){ 63 | return displVec; 64 | } 65 | 66 | private final double[] testX = new double[1]; 67 | private final double[] testY = new double[1]; 68 | 69 | public void mouseInput(){ 70 | 71 | glfwGetCursorPos(window.getHandle(), testX, testY); 72 | 73 | pos.set(testX[0], testY[0]); 74 | 75 | if (locked) { 76 | displVec.set(0); 77 | glfwSetCursorPos(window.getHandle(), window.getWidth() / 2d, window.getHeight() / 2d); 78 | if (oldPos.x > 0 && oldPos.y > 0 && inWindow) { 79 | double deltaX = pos.x - window.getWidth() / 2f; 80 | double deltaY = pos.y - window.getHeight() / 2f; 81 | 82 | boolean rotateX = deltaX != 0; 83 | boolean rotateY = deltaY != 0; 84 | 85 | if (rotateX) { 86 | displVec.y = (float) deltaX; 87 | } 88 | 89 | if (rotateY) { 90 | displVec.x = (float) deltaY; 91 | } 92 | } 93 | 94 | oldPos.set(pos); 95 | } else { 96 | displVec.set(0); 97 | } 98 | } 99 | 100 | public boolean isLeftButtonPressed(){ 101 | return leftButtonPressed; 102 | } 103 | 104 | public boolean isRightButtonPressed(){ 105 | return rightButtonPressed; 106 | } 107 | 108 | public void setLocked(boolean lock){ 109 | if(!lock) { 110 | glfwSetInputMode(window.getHandle(), GLFW_CURSOR, GLFW_CURSOR_NORMAL); 111 | } else{ 112 | glfwSetInputMode(window.getHandle(), GLFW_CURSOR, GLFW_CURSOR_DISABLED); 113 | } 114 | locked = lock; 115 | resetMousePosVector(); 116 | } 117 | 118 | public boolean isLocked(){ 119 | return locked; 120 | } 121 | 122 | public float getMouseScroll(){ 123 | float thisScroll = scroll; 124 | scroll = 0.0f; 125 | return thisScroll; 126 | } 127 | 128 | public Vector2d getPos(){ 129 | return this.pos; 130 | } 131 | 132 | //SPECIAL gui management tool for mouse position 133 | public double getMousePosCenteredX(){ 134 | return pos.x - (window.getWidth() / 2f); 135 | } 136 | public double getMousePosCenteredY(){ 137 | return (pos.y - (window.getHeight() / 2f)) * -1; 138 | } 139 | 140 | public void toggleMouseLock(){ 141 | locked = !locked; 142 | if(!isLocked()) { 143 | glfwSetInputMode(window.getHandle(), GLFW_CURSOR, GLFW_CURSOR_NORMAL); 144 | } else{ 145 | glfwSetInputMode(window.getHandle(), GLFW_CURSOR, GLFW_CURSOR_DISABLED); 146 | } 147 | resetMousePosVector(); 148 | } 149 | } 150 | -------------------------------------------------------------------------------- /src/main/java/game/chunk/ChunkObject.java: -------------------------------------------------------------------------------- 1 | package game.chunk; 2 | 3 | import engine.disk.PrimitiveChunkObject; 4 | import engine.graphics.Mesh; 5 | import org.joml.Vector2i; 6 | import org.joml.Vector3i; 7 | 8 | public class ChunkObject{ 9 | 10 | private final Vector2i pos = new Vector2i(); 11 | 12 | private final byte[] block = new byte[32768]; 13 | private final byte[] rotation = new byte[32768]; 14 | private final byte[] light = new byte[32768]; 15 | private final byte[] heightMap = new byte[32768]; 16 | 17 | private final Mesh[] normalMesh = new Mesh[8]; 18 | private final Mesh[] liquidMesh = new Mesh[8]; 19 | private final Mesh[] allFaceMesh = new Mesh[8]; 20 | 21 | private boolean saveToDisk = false; 22 | private float hover = -128; 23 | 24 | public ChunkObject(Vector2i pos, byte[] block, byte[] rotation, byte[] light, byte[] heightMap){ 25 | this.pos.set(pos); 26 | System.arraycopy(block, 0, this.block, 0, block.length); 27 | System.arraycopy(rotation, 0, this.rotation, 0, rotation.length); 28 | System.arraycopy(light, 0, this.light, 0, light.length); 29 | System.arraycopy(heightMap, 0, this.heightMap, 0, heightMap.length); 30 | } 31 | 32 | public ChunkObject(PrimitiveChunkObject primitiveChunkObject){ 33 | this.pos.set(primitiveChunkObject.pos); 34 | System.arraycopy(primitiveChunkObject.block, 0, this.block, 0, primitiveChunkObject.block.length); 35 | System.arraycopy(primitiveChunkObject.rotation, 0, this.rotation, 0, primitiveChunkObject.rotation.length); 36 | System.arraycopy(primitiveChunkObject.light, 0, this.light, 0, primitiveChunkObject.light.length); 37 | System.arraycopy(primitiveChunkObject.heightMap, 0, this.heightMap, 0, primitiveChunkObject.heightMap.length); 38 | } 39 | 40 | public Vector2i getPos(){ 41 | return this.pos; 42 | } 43 | 44 | public Mesh getNormalMesh(int yHeight){ 45 | return normalMesh[yHeight]; 46 | } 47 | 48 | public Mesh getLiquidMesh(int yHeight){ 49 | return liquidMesh[yHeight]; 50 | } 51 | 52 | public Mesh getAllFaceMesh(int yHeight){ 53 | return allFaceMesh[yHeight]; 54 | } 55 | 56 | public Mesh[] getNormalMeshArray(){ 57 | return normalMesh; 58 | } 59 | 60 | public Mesh[] getLiquidMeshArray(){ 61 | return liquidMesh; 62 | } 63 | 64 | public Mesh[] getAllFaceMeshArray(){ 65 | return allFaceMesh; 66 | } 67 | 68 | public byte[] getBlock() { 69 | return this.block; 70 | } 71 | 72 | public byte[] getRotation() { 73 | return this.rotation; 74 | } 75 | 76 | public byte[] getLight() { 77 | return this.light; 78 | } 79 | 80 | public byte[] getHeightMap() { 81 | return this.heightMap; 82 | } 83 | 84 | public boolean getSaveToDisk() { 85 | return this.saveToDisk; 86 | } 87 | 88 | public void setSaveToDisk(boolean truth){ 89 | this.saveToDisk = truth; 90 | } 91 | 92 | public float getHover(){ 93 | return this.hover; 94 | } 95 | 96 | public void setHover(float hover){ 97 | this.hover = hover; 98 | } 99 | 100 | public void replaceOrSetNormalMesh(int yHeight, Mesh newMesh){ 101 | Mesh currentMesh = normalMesh[yHeight]; 102 | if (currentMesh != null){ 103 | currentMesh.cleanUp(false); 104 | } 105 | normalMesh[yHeight] = newMesh; 106 | 107 | } 108 | 109 | public void replaceOrSetLiquidMesh(int yHeight, Mesh newMesh){ 110 | Mesh currentMesh = liquidMesh[yHeight]; 111 | if (currentMesh != null){ 112 | currentMesh.cleanUp(false); 113 | } 114 | liquidMesh[yHeight] = newMesh; 115 | } 116 | 117 | public void replaceOrSetAllFaceMesh(int yHeight, Mesh newMesh){ 118 | Mesh currentMesh = allFaceMesh[yHeight]; 119 | if (currentMesh != null){ 120 | currentMesh.cleanUp(false); 121 | } 122 | allFaceMesh[yHeight] = newMesh; 123 | } 124 | 125 | //internal 3D/2D to 1D calculations 126 | 127 | //internal chunk math 128 | private Vector3i indexToPos(int i ) { 129 | final int z = i / 2048; 130 | i -= (z * 2048); 131 | final int y = i / 16; 132 | final int x = i % 16; 133 | return new Vector3i( x, y, z); 134 | } 135 | 136 | private int posToIndex2D(int x, int z){ 137 | return (z * 16) + x; 138 | } 139 | 140 | private int posToIndex2D(Vector2i pos){ 141 | return (pos.y * 16) + pos.x; 142 | } 143 | 144 | private int posToIndex( int x, int y, int z ) { 145 | return (z * 2048) + (y * 16) + x; 146 | } 147 | 148 | private int posToIndex( Vector3i pos ) { 149 | return (pos.z * 2048) + (pos.y * 16) + pos.x; 150 | } 151 | } 152 | -------------------------------------------------------------------------------- /src/main/java/engine/settings/Settings.java: -------------------------------------------------------------------------------- 1 | package engine.settings; 2 | 3 | import engine.Window; 4 | import engine.disk.Disk; 5 | import game.chunk.Chunk; 6 | 7 | import static org.lwjgl.glfw.GLFW.*; 8 | 9 | public class Settings { 10 | 11 | private Window window; 12 | private Disk disk; 13 | 14 | private SettingsObject settingsObject; 15 | 16 | private Chunk chunk; 17 | private boolean debugInfo; //assigned false 18 | 19 | public Settings(){ 20 | } 21 | 22 | public void setChunk(Chunk chunk){ 23 | if (this.chunk == null) { 24 | this.chunk = chunk; 25 | } 26 | } 27 | 28 | public void setWindow(Window window){ 29 | if (this.window == null){ 30 | this.window = window; 31 | } 32 | } 33 | public void setDisk(Disk disk){ 34 | if (this.disk == null){ 35 | this.disk = disk; 36 | 37 | SettingsObject loadedSettings = disk.loadSettingsFromDisk(); 38 | 39 | if (loadedSettings == null) { 40 | this.settingsObject = new SettingsObject(); 41 | this.settingsObject.vSync = true; 42 | this.settingsObject.graphicsMode = true; 43 | this.settingsObject.renderDistance = 5; 44 | this.settingsObject.keyForward = GLFW_KEY_W; 45 | this.settingsObject.keyBack = GLFW_KEY_S; 46 | this.settingsObject.keyLeft = GLFW_KEY_A; 47 | this.settingsObject.keyRight = GLFW_KEY_D; 48 | this.settingsObject.keySneak = GLFW_KEY_LEFT_SHIFT; 49 | this.settingsObject.keyDrop = GLFW_KEY_Q; 50 | this.settingsObject.keyJump = GLFW_KEY_SPACE; 51 | this.settingsObject.keyInventory = GLFW_KEY_E; 52 | 53 | //save default values 54 | disk.saveSettingsToDisk(settingsObject); 55 | 56 | } else { 57 | //dump new settings in 58 | this.settingsObject = loadedSettings; 59 | //manually update vsync as it's loaded in 60 | window.setVSync(this.settingsObject.vSync); 61 | } 62 | } 63 | } 64 | 65 | //debug info 66 | public boolean getDebugInfo(){ 67 | return this.debugInfo; 68 | } 69 | 70 | public void setDebugInfo(boolean truth){ 71 | debugInfo = truth; 72 | } 73 | 74 | //render distance 75 | public int getRenderDistance(){ 76 | return this.settingsObject.renderDistance; 77 | } 78 | 79 | public void setRenderDistance(int newRenderDistance, boolean inGame){ 80 | this.settingsObject.renderDistance = newRenderDistance; 81 | if (inGame) { 82 | chunk.generateNewChunks(); 83 | } 84 | } 85 | 86 | public void setSettingsVsync(boolean truth){ 87 | this.settingsObject.vSync = truth; 88 | window.setVSync(truth); 89 | } 90 | 91 | public boolean getSettingsVsync(){ 92 | return settingsObject.vSync; 93 | } 94 | 95 | public void setGraphicsMode(boolean newGraphicsMode){ 96 | this.settingsObject.graphicsMode = newGraphicsMode; 97 | } 98 | 99 | public boolean getGraphicsMode(){ 100 | return this.settingsObject.graphicsMode; 101 | } 102 | 103 | public void setKeyForward(int newKey){ 104 | this.settingsObject.keyForward = newKey; 105 | } 106 | 107 | public int getKeyForward(){ 108 | return this.settingsObject.keyForward; 109 | } 110 | 111 | public void setKeyBack(int newKey){ 112 | this.settingsObject.keyBack = newKey; 113 | } 114 | 115 | public int getKeyBack(){ 116 | return this.settingsObject.keyBack; 117 | } 118 | 119 | public void setKeyLeft(int newKey){ 120 | this.settingsObject.keyLeft = newKey; 121 | } 122 | 123 | public int getKeyLeft(){ 124 | return this.settingsObject.keyLeft; 125 | } 126 | 127 | public void setKeyRight(int newKey){ 128 | this.settingsObject.keyRight = newKey; 129 | } 130 | 131 | public int getKeyRight(){ 132 | return this.settingsObject.keyRight; 133 | } 134 | 135 | public void setKeySneak(int newKey){ 136 | this.settingsObject.keySneak = newKey; 137 | } 138 | 139 | public int getKeySneak(){ 140 | return this.settingsObject.keySneak; 141 | } 142 | 143 | public void setKeyDrop(int newKey){ 144 | this.settingsObject.keyDrop = newKey; 145 | } 146 | 147 | public int getKeyDrop(){ 148 | return this.settingsObject.keyDrop; 149 | } 150 | 151 | public void setKeyJump(int newKey){ 152 | this.settingsObject.keyJump = newKey; 153 | } 154 | 155 | public int getKeyJump(){ 156 | return this.settingsObject.keyJump; 157 | } 158 | 159 | public void setKeyInventory(int newKey){ 160 | this.settingsObject.keyInventory = newKey; 161 | } 162 | 163 | public int getKeyInventory(){ 164 | return this.settingsObject.keyInventory; 165 | } 166 | 167 | public void saveSettings(){ 168 | disk.saveSettingsToDisk(settingsObject); 169 | } 170 | } 171 | -------------------------------------------------------------------------------- /src/main/java/game/entity/itemEntity/ItemEntity.java: -------------------------------------------------------------------------------- 1 | package game.entity.itemEntity; 2 | 3 | public class ItemEntity { 4 | 5 | /* 6 | final private Vector3f normalizedPos = new Vector3f(); 7 | 8 | private final String itemName; 9 | private int stack; 10 | 11 | private float hover = 0f; 12 | private boolean floatUp = true; 13 | private boolean collecting = false; 14 | private float collectionTimer = 0f; 15 | private float rotation = 0f; 16 | 17 | 18 | public ItemEntity(Chunk chunk, EntityContainer entityContainer, Vector3d pos, Vector3f inertia, String itemName, int stack) { 19 | super(chunk, entityContainer, pos, inertia, true, false, false); 20 | this.itemName = itemName; 21 | this.stack = stack; 22 | } 23 | 24 | public void setStack(int stack){ 25 | this.stack = stack; 26 | } 27 | 28 | public int getStack(){ 29 | return stack; 30 | } 31 | 32 | public float getHover(){ 33 | return hover; 34 | } 35 | 36 | public float getRotation(){ 37 | return rotation; 38 | } 39 | 40 | public String getItem(){ 41 | return itemName; 42 | } 43 | 44 | 45 | @Override 46 | public float getWidth() { 47 | return 0.2f; 48 | } 49 | 50 | @Override 51 | public float getHeight() { 52 | return 0.2f; 53 | } 54 | 55 | @Override 56 | public int getHealth() { 57 | return 0; 58 | } 59 | 60 | @Override 61 | public int getHurtAdder() { 62 | return 0; 63 | } 64 | 65 | @Override 66 | public void hurt(int damage) { 67 | 68 | } 69 | 70 | @Override 71 | public void onTick(Entity entity, Player player, Delta delta) { 72 | 73 | } 74 | 75 | @Override 76 | public void onTick(Entity entity, InventoryLogic inventoryLogic, Player player, Delta delta) { 77 | 78 | } 79 | 80 | @Override 81 | public void onTick(Entity entity, SoundAPI soundAPI, InventoryLogic inventoryLogic, Player player, Delta delta) { 82 | 83 | } 84 | 85 | @Override 86 | public void onTick(Collision collision, Entity entity, SoundAPI soundAPI, InventoryLogic inventoryLogic, Player player, Delta delta) { 87 | 88 | double dtime = delta.getDelta(); 89 | 90 | 91 | if (collectionTimer > 0f){ 92 | 93 | collectionTimer -= dtime; 94 | 95 | if (collectionTimer <= 0){ 96 | this.delete(); 97 | return; 98 | } 99 | } 100 | 101 | float timer = this.getTimer(); 102 | timer += dtime; 103 | this.setTimer(timer); 104 | 105 | 106 | //delete items that are too old 107 | if (timer > 50f){ 108 | this.delete(); 109 | return; 110 | } 111 | 112 | boolean thisCollecting = this.collecting; 113 | boolean oldCollecting = thisCollecting; 114 | 115 | //collect items after 3 seconds 116 | if (timer > 3f){ 117 | if (this.getPos().distance(player.getPlayerPosWithCollectionHeight()) < 3f){ 118 | if (!thisCollecting){ 119 | if (inventoryLogic.getInventory().getMain().addItem(this.itemName)) { 120 | soundAPI.playSound("pickup"); 121 | thisCollecting = true; 122 | collectionTimer = 0.1f; 123 | } 124 | //an extreme edge case so a completely full inventory does not 125 | //hammer the player's RAM 126 | else { 127 | collectionTimer = 2; 128 | } 129 | } 130 | //do not do else-if here, can go straight to this logic 131 | if (thisCollecting) { 132 | this.setInertia(normalizedPos.set(player.getPlayerPosWithCollectionHeight().sub(this.getPos()).normalize().mul(15f))); 133 | } 134 | } 135 | 136 | if (this.getPos().distance(player.getPlayerPosWithCollectionHeight()) < 0.2f){ 137 | this.delete(); 138 | return; 139 | } 140 | } 141 | 142 | if (thisCollecting != oldCollecting){ 143 | collecting = true; 144 | } 145 | 146 | if (thisCollecting) { 147 | collision.applyInertia(this.getPos(), this.getInertia(), false, this.getWidth(), this.getHeight(), false, false, false, false, false); 148 | } else { 149 | collision.applyInertia(this.getPos(), this.getInertia(), false, this.getWidth(), this.getHeight(), true, false, true, false, false); 150 | } 151 | 152 | 153 | rotation += dtime * 50; 154 | 155 | if (rotation > 360f) { 156 | rotation -= 360f; 157 | } 158 | 159 | 160 | 161 | if (floatUp){ 162 | hover += dtime / 10; 163 | if (hover >= 0.5f){ 164 | floatUp = false; 165 | } 166 | } else { 167 | hover -= dtime / 10; 168 | if (hover <= 0.0f){ 169 | floatUp = true; 170 | } 171 | } 172 | 173 | //fallen out of the world 174 | if (this.getPos().y < 0){ 175 | this.delete(); 176 | } 177 | } 178 | 179 | */ 180 | } -------------------------------------------------------------------------------- /src/main/java/game/chunk/ChunkUpdateHandler.java: -------------------------------------------------------------------------------- 1 | package game.chunk; 2 | 3 | import engine.graphics.Mesh; 4 | import engine.graphics.Texture; 5 | import engine.time.Delta; 6 | import org.joml.Vector3i; 7 | 8 | import java.util.Random; 9 | import java.util.concurrent.ConcurrentLinkedDeque; 10 | 11 | public class ChunkUpdateHandler { 12 | private Chunk chunk; 13 | private Delta delta; 14 | private ChunkMeshGenerator chunkMeshGenerator; 15 | 16 | private final ConcurrentLinkedDeque generationQueue = new ConcurrentLinkedDeque<>(); 17 | private final ConcurrentLinkedDeque dataQueue = new ConcurrentLinkedDeque<>(); 18 | 19 | private final Texture textureAtlas = new Texture("textures/textureAtlas.png"); 20 | private float chunkUpdateTimer = 0; 21 | 22 | private final Random random = new Random(); 23 | 24 | public ChunkUpdateHandler(){ 25 | 26 | } 27 | 28 | public void setChunk(Chunk chunk){ 29 | if (this.chunk == null) { 30 | this.chunk = chunk; 31 | } 32 | } 33 | public void setDelta(Delta delta){ 34 | if (this.delta == null){ 35 | this.delta = delta; 36 | } 37 | } 38 | public void setChunkMeshGenerator(ChunkMeshGenerator chunkMeshGenerator){ 39 | if (this.chunkMeshGenerator == null){ 40 | this.chunkMeshGenerator = chunkMeshGenerator; 41 | } 42 | } 43 | 44 | public void chunkUpdate( int x, int z , int y){ 45 | if (!generationQueue.contains(new Vector3i(x, y, z))) { 46 | generationQueue.add(new Vector3i(x, y, z)); 47 | } 48 | } 49 | 50 | //chunk mesh generator handling 51 | public void addToChunkMeshQueue(ChunkMeshData chunkMeshData){ 52 | dataQueue.add(chunkMeshData); 53 | } 54 | 55 | public void chunkUpdater() { 56 | if (generationQueue.isEmpty()){ 57 | return; 58 | } 59 | for (int i = 0; i < 200; i++) { 60 | if (generationQueue.isEmpty()) { 61 | return; 62 | } 63 | 64 | Vector3i key; 65 | try { 66 | Object[] queueAsArray = generationQueue.toArray(); 67 | key = (Vector3i) queueAsArray[random.nextInt(queueAsArray.length)]; 68 | 69 | if (key == null){ 70 | return; 71 | } 72 | } catch (Exception ignored){ 73 | continue; //let's just keep going 74 | } 75 | 76 | //sometimes it is null 77 | /* 78 | if (this.chunk.chunkStackContainsBlock(key.x, key.z, key.y)) { 79 | 80 | } 81 | */ 82 | 83 | chunkMeshGenerator.generateChunkMesh(key.x, key.z, key.y); 84 | 85 | //can attempt to remove null, so it's okay 86 | generationQueue.remove(key); 87 | } 88 | } 89 | 90 | 91 | public void popChunkMeshQueue(){ 92 | if (dataQueue.isEmpty()){ 93 | return; 94 | } 95 | 96 | chunkUpdateTimer += delta.getDelta(); 97 | int updateAmount = 0; 98 | 99 | float goalTimer = 0.0003f; 100 | if (chunkUpdateTimer >= goalTimer){ 101 | updateAmount = (int)(Math.ceil(chunkUpdateTimer / goalTimer)); 102 | chunkUpdateTimer = 0; 103 | } 104 | 105 | 106 | for (int i = 0; i < updateAmount; i++) { 107 | if (dataQueue.isEmpty()) { 108 | return; 109 | } 110 | 111 | //System.out.println("ChunkMesh Setting QueueSize: " + dataQueue.size()); 112 | 113 | ChunkMeshData newChunkMeshData = dataQueue.pop(); 114 | 115 | if (newChunkMeshData != null) { 116 | 117 | if (!newChunkMeshData.normalMeshIsNull) { 118 | chunk.setChunkNormalMesh(newChunkMeshData.chunkX, newChunkMeshData.chunkZ, newChunkMeshData.yHeight, new Mesh(newChunkMeshData.positionsArray, newChunkMeshData.lightArray, newChunkMeshData.indicesArray, newChunkMeshData.textureCoordArray, textureAtlas)); 119 | } else { 120 | chunk.setChunkNormalMesh(newChunkMeshData.chunkX, newChunkMeshData.chunkZ, newChunkMeshData.yHeight, null); 121 | } 122 | 123 | 124 | if (!newChunkMeshData.liquidMeshIsNull) { 125 | chunk.setChunkLiquidMesh(newChunkMeshData.chunkX, newChunkMeshData.chunkZ, newChunkMeshData.yHeight, new Mesh(newChunkMeshData.liquidPositionsArray, newChunkMeshData.liquidLightArray, newChunkMeshData.liquidIndicesArray, newChunkMeshData.liquidTextureCoordArray, textureAtlas)); 126 | } else { 127 | chunk.setChunkLiquidMesh(newChunkMeshData.chunkX, newChunkMeshData.chunkZ, newChunkMeshData.yHeight, null); 128 | } 129 | 130 | if (!newChunkMeshData.allFacesMeshIsNull) { 131 | chunk.setChunkAllFacesMesh(newChunkMeshData.chunkX, newChunkMeshData.chunkZ, newChunkMeshData.yHeight, new Mesh(newChunkMeshData.allFacesPositionsArray, newChunkMeshData.allFacesLightArray, newChunkMeshData.allFacesIndicesArray, newChunkMeshData.allFacesTextureCoordArray, textureAtlas)); 132 | } else { 133 | chunk.setChunkAllFacesMesh(newChunkMeshData.chunkX, newChunkMeshData.chunkZ, newChunkMeshData.yHeight, null); 134 | } 135 | } 136 | } 137 | } 138 | } 139 | -------------------------------------------------------------------------------- /src/main/java/game/entity/particle/Particle.java: -------------------------------------------------------------------------------- 1 | package game.entity.particle; 2 | 3 | import engine.graphics.Mesh; 4 | import engine.graphics.Texture; 5 | import engine.sound.SoundAPI; 6 | import engine.time.Delta; 7 | import game.blocks.BlockDefinitionContainer; 8 | import game.chunk.Chunk; 9 | import game.crafting.InventoryLogic; 10 | import game.entity.Entity; 11 | import game.entity.EntityContainer; 12 | import game.entity.collision.Collision; 13 | import game.entity.collision.ParticleCollision; 14 | import game.player.Player; 15 | import org.joml.Vector3d; 16 | import org.joml.Vector3f; 17 | import org.joml.Vector3i; 18 | 19 | import java.util.*; 20 | 21 | public class Particle extends Entity { 22 | 23 | private final Mesh mesh; 24 | 25 | 26 | private final Vector3i currentFlooredPos = new Vector3i(); 27 | 28 | private final Deque deletionQueue = new ArrayDeque<>(); 29 | 30 | public Particle(EntityContainer entityContainer, Vector3d pos, Vector3f inertia, float width, float height, boolean item, boolean mob, boolean particle) { 31 | super(entityContainer, pos, inertia, width, height, item, mob, particle); 32 | 33 | BlockDefinitionContainer blockDefinitionContainer = new BlockDefinitionContainer(); 34 | mesh = createParticleMesh(blockDefinitionContainer, 5, new Texture("textures/textureAtlas.png")); 35 | } 36 | 37 | public void onTick(BlockDefinitionContainer blockDefinitionContainer, ParticleCollision collision, Delta delta){ 38 | 39 | double dtime = delta.getDelta(); 40 | 41 | 42 | collision.applyInertia(this.getPos(), this.getInertia(), true,true); 43 | 44 | float timer = (float) (this.getTimer() + dtime); 45 | 46 | this.setTimer(timer); 47 | 48 | if (timer > 1f){ 49 | this.delete(); 50 | } 51 | 52 | 53 | } 54 | 55 | 56 | public Mesh getMesh(){ 57 | return mesh; 58 | } 59 | 60 | private Mesh createParticleMesh(BlockDefinitionContainer blockDefinitionContainer, int blockID, Texture textureAtlas) { 61 | 62 | final float textureScale = (float)Math.ceil(Math.random() * 3f); 63 | final float pixelScale = (float)(int)textureScale / 25f; 64 | 65 | final float pixelX = (float)Math.floor(Math.random()*(16f-(textureScale+1f))); 66 | final float pixelY = (float)Math.floor(Math.random()*(16f-(textureScale+1f))); 67 | 68 | final float pixelXMin = pixelX/16f/32f; 69 | final float pixelXMax = (pixelX+textureScale)/16f/32f; 70 | 71 | final float pixelYMin = pixelY/16f/32f; 72 | final float pixelYMax = (pixelY+textureScale)/16f/32f; 73 | 74 | 75 | final float[] positions = new float[12]; 76 | final float[] textureCoord = new float[8]; 77 | final int[] indices = new int[6]; 78 | final float[] light = new float[12]; 79 | 80 | //front 81 | positions[0] = (pixelScale); 82 | positions[1] = (pixelScale*2); 83 | positions[2] = (0f); 84 | positions[3] = (-pixelScale); 85 | positions[4] = (pixelScale*2); 86 | positions[5] = (0f); 87 | positions[6] = (-pixelScale); 88 | positions[7] = (0f); 89 | positions[8] = (0f); 90 | positions[9] = (pixelScale); 91 | positions[10] = (0f); 92 | positions[11] = (0f); 93 | 94 | //front 95 | for (int i = 0; i < 12; i++) { 96 | light[i] = 1; 97 | } 98 | //front 99 | indices[0] = (0); 100 | indices[1] = (1); 101 | indices[2] = (2); 102 | indices[3] = (0); 103 | indices[4] = (2); 104 | indices[5] = (3); 105 | 106 | final int selection = (int)Math.floor(Math.random()*6f); 107 | 108 | float[] texturePoints = switch (selection) { 109 | case 1 -> blockDefinitionContainer.getBackTexturePoints(blockID, (byte) 0); 110 | case 2 -> blockDefinitionContainer.getRightTexturePoints(blockID, (byte) 0); 111 | case 3 -> blockDefinitionContainer.getLeftTexturePoints(blockID, (byte) 0); 112 | case 4 -> blockDefinitionContainer.getTopTexturePoints(blockID); 113 | case 5 -> blockDefinitionContainer.getBottomTexturePoints(blockID); 114 | default -> blockDefinitionContainer.getFrontTexturePoints(blockID, (byte) 0); 115 | }; 116 | 117 | 118 | //front 119 | textureCoord[0] = (texturePoints[0] + pixelXMax);//1 120 | textureCoord[1] = (texturePoints[2] + pixelYMin);//2 121 | textureCoord[2] = (texturePoints[0] + pixelXMin);//0 122 | textureCoord[3] = (texturePoints[2] + pixelYMin);//2 123 | textureCoord[4] = (texturePoints[0] + pixelXMin);//0 124 | textureCoord[5] = (texturePoints[2] + pixelYMax);//3 125 | textureCoord[6] = (texturePoints[0] + pixelXMax);//1 126 | textureCoord[7] = (texturePoints[2] + pixelYMax);//3 127 | 128 | return new Mesh(positions, light, indices, textureCoord, textureAtlas); 129 | } 130 | 131 | /* 132 | @Override 133 | public void onTick(Entity entity, Player player, Delta delta) { 134 | 135 | } 136 | 137 | @Override 138 | public void onTick(Entity entity, InventoryLogic inventoryLogic, Player player, Delta delta) { 139 | 140 | } 141 | 142 | @Override 143 | public void onTick(Entity entity, SoundAPI soundAPI, InventoryLogic inventoryLogic, Player player, Delta delta) { 144 | 145 | } 146 | 147 | @Override 148 | public void onTick(Collision collision, Entity entity, SoundAPI soundAPI, InventoryLogic inventoryLogic, Player player, Delta delta) { 149 | 150 | } 151 | 152 | */ 153 | } -------------------------------------------------------------------------------- /src/main/java/engine/graphics/Mesh.java: -------------------------------------------------------------------------------- 1 | package engine.graphics; 2 | 3 | import java.nio.FloatBuffer; 4 | import java.nio.IntBuffer; 5 | 6 | import static org.lwjgl.opengl.ARBVertexArrayObject.glBindVertexArray; 7 | import static org.lwjgl.opengl.ARBVertexArrayObject.glGenVertexArrays; 8 | import static org.lwjgl.opengl.GL44.*; 9 | import static org.lwjgl.system.MemoryUtil.*; 10 | 11 | public class Mesh { 12 | 13 | //most of these acronyms can be learned as to what they're referring to on the Khronos wiki 14 | //https://www.khronos.org/opengl/wiki/Vertex_Specification 15 | 16 | private final int vaoId ; 17 | 18 | //openGL VAO array attribution field IDs 19 | private final int posVboId ; 20 | private final int colorVboId ; 21 | private final int textureVboId ; 22 | private final int idxVboId ; 23 | private final int vertexCount ; 24 | //texture ID field 25 | private final Texture texture ; 26 | 27 | 28 | public Mesh (float[] positions, float[] colors, int[] indices, float[] textCoords, Texture newTexture) { 29 | 30 | //the key for the mesh 31 | //Vertex Array Object (VAO) 32 | this.vaoId = glGenVertexArrays(); 33 | 34 | glBindVertexArray(this.vaoId); 35 | 36 | //position VBO 37 | this.posVboId = glGenBuffers(); 38 | 39 | final FloatBuffer posBuffer = memAllocFloat(positions.length); 40 | posBuffer.put(positions).flip(); 41 | 42 | glBindBuffer(GL_ARRAY_BUFFER, this.posVboId); 43 | glBufferData(GL_ARRAY_BUFFER, posBuffer, GL_STATIC_DRAW); 44 | glEnableVertexAttribArray(0); 45 | glVertexAttribPointer(0, 3, GL_FLOAT, false, 0, 0); 46 | 47 | // color VBO 48 | this.colorVboId = glGenBuffers(); 49 | 50 | final FloatBuffer colorBuffer = memAllocFloat(colors.length); 51 | colorBuffer.put(colors).flip(); 52 | 53 | glBindBuffer(GL_ARRAY_BUFFER, this.colorVboId); 54 | glBufferData(GL_ARRAY_BUFFER, colorBuffer, GL_STATIC_DRAW); 55 | glEnableVertexAttribArray(1); 56 | glVertexAttribPointer(1, 3, GL_FLOAT, false, 0, 0); 57 | 58 | //texture coordinates vbo 59 | this.textureVboId = glGenBuffers(); 60 | 61 | FloatBuffer textCoordsBuffer = memAllocFloat(textCoords.length); 62 | textCoordsBuffer.put(textCoords).flip(); 63 | 64 | glBindBuffer(GL_ARRAY_BUFFER, this.textureVboId); 65 | glBufferData(GL_ARRAY_BUFFER, textCoordsBuffer, GL_STATIC_DRAW); 66 | glEnableVertexAttribArray(2); 67 | glVertexAttribPointer(2, 2, GL_FLOAT, false, 0, 0); 68 | 69 | 70 | //index vbo 71 | this.idxVboId = glGenBuffers(); 72 | 73 | IntBuffer indicesBuffer = memAllocInt(indices.length); 74 | indicesBuffer.put(indices).flip(); 75 | 76 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, this.idxVboId); 77 | glBufferData(GL_ELEMENT_ARRAY_BUFFER, indicesBuffer, GL_STATIC_DRAW); 78 | 79 | glBindBuffer(GL_ARRAY_BUFFER, 0); 80 | glBindVertexArray(0); 81 | 82 | //clean memory 83 | memFree(posBuffer); 84 | memFree(colorBuffer); 85 | memFree(textCoordsBuffer); 86 | memFree(indicesBuffer); 87 | 88 | //next add the vertex count to it's int 89 | this.vertexCount = indices.length; 90 | 91 | //finally, store the texture ID 92 | this.texture = newTexture; 93 | } 94 | 95 | public void render(){ 96 | //activate first texture bank 97 | glActiveTexture(GL_TEXTURE0); 98 | 99 | //bind the texture 100 | glBindTexture(GL_TEXTURE_2D, this.texture.getID()); 101 | 102 | //bind the mesh vertex array 103 | glBindVertexArray(this.vaoId); 104 | //glEnableVertexAttribArray(0); 105 | //glEnableVertexAttribArray(1); 106 | 107 | //draw the mesh 108 | glDrawElements(GL_TRIANGLES, this.vertexCount, GL_UNSIGNED_INT, 0); 109 | 110 | //restore data 111 | //glDisableVertexAttribArray(0); 112 | //glDisableVertexAttribArray(1); 113 | glBindVertexArray(0); 114 | } 115 | 116 | public void cleanUp(boolean deleteTexture){ 117 | 118 | //this is directly talking to the C library 119 | 120 | //binding to buffer 0 121 | //what this means is, unbind any previously bound buffer 122 | glBindBuffer(GL_ARRAY_BUFFER, 0); 123 | 124 | //disable all previously enabled vertex attribution arrays 125 | glDisableVertexAttribArray(2); 126 | glDisableVertexAttribArray(1); 127 | glDisableVertexAttribArray(0); 128 | 129 | //clear the buffer data in memory - basically destroy all mesh variables in your GPU 130 | glDeleteBuffers(this.posVboId); 131 | glDeleteBuffers(this.colorVboId); 132 | glDeleteBuffers(this.textureVboId); 133 | glDeleteBuffers(this.idxVboId); 134 | 135 | 136 | 137 | //explicitly break the previous bindings 138 | //you can read more about this here https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glBindVertexArray.xhtml 139 | glBindVertexArray(0); 140 | //delete the whole object (VAO) - final OpenGL memory interaction for VAO 141 | glDeleteVertexArrays(this.vaoId); 142 | 143 | //simple OpenGL error check - if this is ever triggered, something has gone SERIOUSLY wrong 144 | int errorCheckValue = glGetError(); 145 | if (glGetError() != GL_NO_ERROR) { 146 | System.out.println("Error could not destroy the mesh! Error value: " + errorCheckValue); 147 | } 148 | 149 | //delete the texture - if explicitly specified to 150 | if (deleteTexture) { 151 | texture.cleanUp(); 152 | } 153 | } 154 | } -------------------------------------------------------------------------------- /src/main/java/engine/graphics/Camera.java: -------------------------------------------------------------------------------- 1 | package engine.graphics; 2 | 3 | import engine.Mouse; 4 | import game.player.Player; 5 | import game.ray.Ray; 6 | import org.joml.Math; 7 | import org.joml.Vector3d; 8 | import org.joml.Vector3f; 9 | 10 | public class Camera { 11 | 12 | private Ray ray; 13 | private Player player; 14 | private Mouse mouse; 15 | 16 | public Camera(){ 17 | 18 | } 19 | 20 | public void setRay(Ray ray){ 21 | if (this.ray == null){ 22 | this.ray = ray; 23 | } 24 | } 25 | 26 | public void setPlayer(Player player){ 27 | if (this.player == null){ 28 | this.player = player; 29 | } 30 | } 31 | 32 | public void setMouse(Mouse mouse){ 33 | if (this.mouse == null){ 34 | this.mouse = mouse; 35 | } 36 | } 37 | 38 | 39 | private final Vector3d position = new Vector3d(); 40 | private final Vector3f rotation = new Vector3f(); 41 | private final Vector3f rotationVector = new Vector3f(); 42 | 43 | private byte cameraPerspective = 0; 44 | 45 | public Vector3d getCameraPosition(){ 46 | return position; 47 | } 48 | 49 | public void setCameraPosition(Vector3d newPos){ 50 | position.set(newPos); 51 | } 52 | 53 | public void moveCameraPosition(float offsetX, float offsetY, float offsetZ){ 54 | if ( offsetZ != 0){ 55 | position.x += Math.sin(Math.toRadians(rotation.y)) * -1.0f * offsetZ; 56 | position.z += Math.cos(Math.toRadians(rotation.y)) * offsetZ; 57 | } 58 | 59 | if ( offsetX != 0) { 60 | position.x += Math.sin(Math.toRadians(rotation.y - 90f)) * -1.0f * offsetX; 61 | position.z += Math.cos(Math.toRadians(rotation.y - 90f)) * offsetX; 62 | } 63 | 64 | if (offsetY != 0) { 65 | position.y += offsetY; 66 | } 67 | } 68 | 69 | public void toggleCameraPerspective(){ 70 | cameraPerspective++; 71 | 72 | //flip camera 73 | if (cameraPerspective == 2){ 74 | rotation.x *= -1; 75 | rotation.y += 180; 76 | } 77 | //reset 78 | if (cameraPerspective > 2){ 79 | cameraPerspective = 0; 80 | 81 | //flip camera 82 | rotation.x *= -1; 83 | rotation.y += 180; 84 | } 85 | } 86 | 87 | public void setCameraPerspective(byte perspective){ 88 | cameraPerspective = perspective; 89 | } 90 | 91 | public byte getCameraPerspective(){ 92 | return cameraPerspective; 93 | } 94 | 95 | public Vector3f getCameraRotation(){ 96 | return rotation; 97 | } 98 | 99 | public void setCameraRotation(Vector3f rotation){ 100 | rotation.set(rotation); 101 | } 102 | 103 | public void moveCameraRotation(Vector3f offset){ 104 | rotation.add(offset); 105 | } 106 | 107 | 108 | public Vector3f getCameraRotationVector(){ 109 | float xzLen = Math.cos(Math.toRadians(rotation.x + 180f)); 110 | rotationVector.z = xzLen * Math.cos(Math.toRadians(rotation.y)); 111 | rotationVector.y = Math.sin(Math.toRadians(rotation.x + 180f)); 112 | rotationVector.x = xzLen * Math.sin(Math.toRadians(-rotation.y)); 113 | return rotationVector; 114 | } 115 | 116 | public Vector3f getInvertedCameraRotationVector(){ 117 | float xzLen = Math.cos(Math.toRadians(rotation.x + 180f)); 118 | rotationVector.z = (xzLen * Math.cos(Math.toRadians(rotation.y))) * -1; 119 | rotationVector.y = (Math.sin(Math.toRadians(rotation.x + 180f))) * -1; 120 | rotationVector.x = (xzLen * Math.sin(Math.toRadians(-rotation.y))) * -1; 121 | return rotationVector; 122 | } 123 | 124 | public float getCameraRotationVectorX(){ 125 | float xzLen = Math.cos(Math.toRadians(rotation.x + 180f)); 126 | return xzLen * Math.sin(Math.toRadians(-rotation.y)); 127 | } 128 | 129 | public float getCameraRotationVectorY(){ 130 | return Math.sin(Math.toRadians(rotation.x + 180f)); 131 | } 132 | 133 | public float getCameraRotationVectorZ(){ 134 | float xzLen = Math.cos(Math.toRadians(rotation.x + 180f)); 135 | return xzLen * Math.cos(Math.toRadians(rotation.y)); 136 | } 137 | 138 | 139 | 140 | 141 | 142 | public void updateCamera(){ 143 | 144 | if (cameraPerspective == 0) { 145 | setCameraPosition(player.getPlayerPosWithViewBobbing()); 146 | } 147 | 148 | //update camera based on mouse 149 | //make this adjustable 0.2 to 1.0 maybe - implement slider in menu system! 150 | float MOUSE_SENSITIVITY = 0.09f; 151 | moveCameraRotation(new Vector3f(mouse.getDisplVec().x * MOUSE_SENSITIVITY, mouse.getDisplVec().y * MOUSE_SENSITIVITY, (float)0)); 152 | 153 | //limit camera pitch 154 | if (getCameraRotation().x < -90f) { 155 | moveCameraRotation(new Vector3f((90f + getCameraRotation().x) * -1f, 0, 0)); 156 | } 157 | if (getCameraRotation().x > 90f){ 158 | moveCameraRotation(new Vector3f((getCameraRotation().x - 90f) * -1f , 0, 0)); 159 | } 160 | 161 | //loop camera yaw 162 | if (getCameraRotation().y < -180f){ 163 | moveCameraRotation(new Vector3f(0,360f, 0)); 164 | } 165 | if (getCameraRotation().y > 180f){ 166 | moveCameraRotation(new Vector3f(0,-360f, 0)); 167 | } 168 | 169 | //these must go after camera rotation 170 | //or weird inertia effect happens 171 | if (cameraPerspective > 0){ 172 | setCameraPosition(ray.cameraRayCast(player.getPlayerPosWithEyeHeight(), getCameraRotationVector().mul(-1), 3)); 173 | } 174 | } 175 | } 176 | -------------------------------------------------------------------------------- /src/main/java/game/falling/FallingEntity.java: -------------------------------------------------------------------------------- 1 | package game.falling; 2 | 3 | import engine.graphics.Mesh; 4 | import org.joml.Vector3d; 5 | import org.joml.Vector3f; 6 | 7 | import java.util.Arrays; 8 | 9 | public class FallingEntity { 10 | /* 11 | private final int initialSize = 10; 12 | private int currentSize = 10; 13 | 14 | private boolean[] exists = new boolean[initialSize]; 15 | private Vector3d[] position = new Vector3d[initialSize]; 16 | private Vector3f[] inertia = new Vector3f[initialSize]; 17 | private byte[] light = new byte[initialSize]; 18 | private float[] lightUpdateTimer = new float[initialSize]; 19 | private Mesh[] mesh = new Mesh[initialSize]; 20 | private byte[] ID = new byte[initialSize]; 21 | 22 | private int getFreeSlot(){ 23 | for (int i = 0; i < currentSize; i++){ 24 | if (!exists[i]){ 25 | return i; 26 | } 27 | } 28 | 29 | //inlined container growth 30 | return growContainer(); 31 | } 32 | 33 | private int growContainer(){ 34 | //System.out.println("particle table is growing to: " + (currentSize + 10)); 35 | //ints are only created if arrays need to expand 36 | //can return current size because it is +1 index of the old size 37 | int returningSize = currentSize; 38 | currentSize += 10; 39 | 40 | //new arrays are only created if arrays need to expand 41 | boolean[] newExists = new boolean[currentSize]; 42 | Vector3d[] newPosition = new Vector3d[currentSize]; 43 | Vector3f[] newInertia = new Vector3f[currentSize]; 44 | Mesh[] newMesh = new Mesh[currentSize]; 45 | byte[] newLight = new byte[currentSize]; 46 | float[] newLightUpdateTimer = new float[currentSize]; 47 | byte[] newID = new byte[currentSize]; 48 | 49 | //clone data 50 | System.arraycopy(exists, 0, newExists, 0, exists.length); 51 | for (int i = 0; i < position.length; i++){ 52 | newPosition[i] = new Vector3d(position[i]); 53 | } 54 | for (int i = 0; i < inertia.length; i++){ 55 | newInertia[i] = new Vector3f(inertia[i]); 56 | } 57 | 58 | System.arraycopy(mesh, 0, newMesh, 0, exists.length); 59 | System.arraycopy(light, 0, newLight, 0, exists.length); 60 | System.arraycopy(lightUpdateTimer, 0, newLightUpdateTimer, 0, exists.length); 61 | System.arraycopy(ID, 0, newID, 0, ID.length); 62 | 63 | //set data 64 | exists = newExists; 65 | position = newPosition; 66 | inertia = newInertia; 67 | mesh = newMesh; 68 | light = newLight; 69 | lightUpdateTimer = newLightUpdateTimer; 70 | ID = newID; 71 | 72 | return returningSize; 73 | } 74 | 75 | public void createFallingEntity(double posX, double posY, double posZ, float inertiaX, float inertiaY, float inertiaZ, byte newID){ 76 | int thisID = getFreeSlot(); 77 | exists[thisID] = true; 78 | position[thisID] = new Vector3d(posX, posY, posZ); 79 | inertia[thisID] = new Vector3f(inertiaX, inertiaY, inertiaZ); 80 | light[thisID] = getLight((int) Math.floor(posX), (int) Math.floor(posY), (int) Math.floor(posZ)); 81 | ID[thisID] = newID; 82 | } 83 | 84 | 85 | public void fallingEntityOnStep(){ 86 | int index = 0; 87 | for (boolean thisExists : exists){ 88 | if (!thisExists){ 89 | index++; 90 | continue; 91 | } 92 | boolean onGround = applyInertia(position[index], inertia[index], false, 0.45f, 1f, true, false, true, false, false); 93 | if (inertia[index].y == 0 || onGround){ 94 | placeBlock((int)Math.floor(position[index].x), (int)Math.floor(position[index].y), (int)Math.floor(position[index].z), ID[index], (byte) 0); 95 | destroyFallingEntity(index); 96 | } 97 | index++; 98 | } 99 | } 100 | 101 | private void destroyFallingEntity( int thisIndex){ 102 | 103 | mesh[thisIndex].cleanUp(false); 104 | 105 | exists[thisIndex] = false; 106 | position[thisIndex] = null; 107 | inertia[thisIndex] = null; 108 | light[thisIndex] = 0; 109 | lightUpdateTimer[thisIndex] = 0; 110 | mesh[thisIndex] = null; 111 | ID[thisIndex] = 0; 112 | } 113 | 114 | public void cleanFallingEntities() { 115 | int index = 0; 116 | //clean openGL memory 117 | for (boolean thisExists : exists) { 118 | if (!thisExists){ 119 | index++; 120 | continue; 121 | } 122 | mesh[index].cleanUp(false); 123 | index++; 124 | } 125 | 126 | //clear memory for GC 127 | Arrays.fill(exists, false); 128 | Arrays.fill(position, null); 129 | Arrays.fill(inertia, null); 130 | Arrays.fill(mesh, null); 131 | Arrays.fill(light, (byte) 0); 132 | Arrays.fill(lightUpdateTimer, 0); 133 | Arrays.fill(ID, (byte) 0); 134 | 135 | 136 | //reset memory 137 | exists = new boolean[initialSize]; 138 | position = new Vector3d[initialSize]; 139 | inertia = new Vector3f[initialSize]; 140 | mesh = new Mesh[initialSize]; 141 | light = new byte[initialSize]; 142 | lightUpdateTimer = new float[initialSize]; 143 | ID = new byte[initialSize]; 144 | } 145 | 146 | public boolean[] getFallingEntities(){ 147 | return exists; 148 | } 149 | 150 | public Vector3d getFallingEntityPos(int index){ 151 | return position[index]; 152 | } 153 | 154 | public byte getFallingEntityBlockID(int index){ 155 | return ID[index]; 156 | } 157 | 158 | public byte getFallingEntityLight(int index){ 159 | return light[index]; 160 | } 161 | */ 162 | } 163 | -------------------------------------------------------------------------------- /src/main/java/game/entity/mob/MobMeshBuilder.java: -------------------------------------------------------------------------------- 1 | package game.entity.mob; 2 | 3 | import engine.graphics.Mesh; 4 | import engine.graphics.Texture; 5 | import engine.highPerformanceContainers.MicroFloatArray; 6 | import engine.highPerformanceContainers.MicroIntArray; 7 | 8 | public class MobMeshBuilder { 9 | 10 | public Mesh[] createMobMesh(float[][][] modelPieceArray, float[][][] textureArrayArray, String texturePath){ 11 | 12 | 13 | Mesh[] bodyMeshes = new Mesh[modelPieceArray.length]; 14 | 15 | int bodyMeshesIndex = 0; //this is the float[THISPART] which holds the float[THISPART]{x,y,z,x,y,z} 16 | 17 | //allow multiple meshes to be welded together 18 | for (float[][] thisModelSegment : modelPieceArray) { 19 | 20 | MicroFloatArray positions = new MicroFloatArray(12); 21 | MicroFloatArray textureCoord = new MicroFloatArray(8); 22 | MicroIntArray indices = new MicroIntArray(6); 23 | MicroFloatArray light = new MicroFloatArray(12); 24 | 25 | int indicesCount = 0; 26 | int textureCounter = 0; 27 | 28 | for (float[] thisBlockBox : thisModelSegment) { 29 | 30 | //back 31 | positions.pack(thisBlockBox[3], thisBlockBox[4], thisBlockBox[5], thisBlockBox[0], thisBlockBox[4], thisBlockBox[5], thisBlockBox[0], thisBlockBox[1], thisBlockBox[5], thisBlockBox[3], thisBlockBox[1], thisBlockBox[5]); 32 | light.pack(1f); 33 | indices.pack(indicesCount, 1 + indicesCount, 2 + indicesCount, indicesCount, 2 + indicesCount, 3 + indicesCount); 34 | indicesCount += 4; 35 | float[] textureFront = textureArrayArray[bodyMeshesIndex][textureCounter]; 36 | textureCoord.pack(textureFront[1], textureFront[2], textureFront[0], textureFront[2], textureFront[0], textureFront[3], textureFront[1], textureFront[3]); 37 | textureCounter++; 38 | 39 | //front 40 | positions.pack(thisBlockBox[0], thisBlockBox[4], thisBlockBox[2], thisBlockBox[3], thisBlockBox[4], thisBlockBox[2], thisBlockBox[3], thisBlockBox[1], thisBlockBox[2], thisBlockBox[0], thisBlockBox[1], thisBlockBox[2]); 41 | light.pack(1f); 42 | indices.pack(indicesCount, 1 + indicesCount, 2 + indicesCount, indicesCount, 2 + indicesCount, 3 + indicesCount); 43 | indicesCount += 4; 44 | float[] textureBack = textureArrayArray[bodyMeshesIndex][textureCounter]; 45 | textureCoord.pack(textureBack[1], textureBack[2], textureBack[0], textureBack[2], textureBack[0], textureBack[3], textureBack[1], textureBack[3]); 46 | textureCounter++; 47 | 48 | //right 49 | positions.pack(thisBlockBox[3], thisBlockBox[4], thisBlockBox[2], thisBlockBox[3], thisBlockBox[4], thisBlockBox[5], thisBlockBox[3], thisBlockBox[1], thisBlockBox[5], thisBlockBox[3], thisBlockBox[1], thisBlockBox[2]); 50 | light.pack(1f); 51 | indices.pack(indicesCount, 1 + indicesCount, 2 + indicesCount, indicesCount, 2 + indicesCount, 3 + indicesCount); 52 | indicesCount += 4; 53 | float[] textureRight = textureArrayArray[bodyMeshesIndex][textureCounter]; 54 | textureCoord.pack(textureRight[1], textureRight[2], textureRight[0], textureRight[2], textureRight[0], textureRight[3], textureRight[1], textureRight[3]); 55 | textureCounter++; 56 | 57 | //left 58 | positions.pack(thisBlockBox[0], thisBlockBox[4], thisBlockBox[5], thisBlockBox[0], thisBlockBox[4], thisBlockBox[2], thisBlockBox[0], thisBlockBox[1], thisBlockBox[2], thisBlockBox[0], thisBlockBox[1], thisBlockBox[5]); 59 | light.pack(1f); 60 | indices.pack(indicesCount, 1 + indicesCount, 2 + indicesCount, indicesCount, 2 + indicesCount, 3 + indicesCount); 61 | indicesCount += 4; 62 | float[] textureLeft = textureArrayArray[bodyMeshesIndex][textureCounter]; 63 | textureCoord.pack(textureLeft[1], textureLeft[2], textureLeft[0], textureLeft[2], textureLeft[0], textureLeft[3], textureLeft[1], textureLeft[3]); 64 | textureCounter++; 65 | 66 | //top 67 | positions.pack(thisBlockBox[0], thisBlockBox[4], thisBlockBox[2], thisBlockBox[0], thisBlockBox[4], thisBlockBox[5], thisBlockBox[3], thisBlockBox[4], thisBlockBox[5], thisBlockBox[3], thisBlockBox[4], thisBlockBox[2]); 68 | light.pack(1f); 69 | indices.pack(indicesCount, 1 + indicesCount, 2 + indicesCount, indicesCount, 2 + indicesCount, 3 + indicesCount); 70 | indicesCount += 4; 71 | float[] textureTop = textureArrayArray[bodyMeshesIndex][textureCounter]; 72 | textureCoord.pack(textureTop[1], textureTop[2], textureTop[0], textureTop[2], textureTop[0], textureTop[3], textureTop[1], textureTop[3]); 73 | textureCounter++; 74 | 75 | //bottom 76 | positions.pack(thisBlockBox[0], thisBlockBox[1], thisBlockBox[5], thisBlockBox[0], thisBlockBox[1], thisBlockBox[2], thisBlockBox[3], thisBlockBox[1], thisBlockBox[2], thisBlockBox[3], thisBlockBox[1], thisBlockBox[5]); 77 | light.pack(1f); 78 | indices.pack(indicesCount, 1 + indicesCount, 2 + indicesCount, indicesCount, 2 + indicesCount, 3 + indicesCount); 79 | indicesCount += 4; 80 | float[] textureBottom = textureArrayArray[bodyMeshesIndex][textureCounter]; 81 | textureCoord.pack(textureBottom[1], textureBottom[2], textureBottom[0], textureBottom[2], textureBottom[0], textureBottom[3], textureBottom[1], textureBottom[3]); 82 | textureCounter++; 83 | } 84 | 85 | Texture playerTexture = new Texture(texturePath); 86 | 87 | bodyMeshes[bodyMeshesIndex] = new Mesh(positions.values(), light.values(), indices.values(), textureCoord.values(), playerTexture); 88 | 89 | positions.clear(); 90 | 91 | bodyMeshesIndex++; 92 | } 93 | 94 | return bodyMeshes; 95 | } 96 | 97 | public float[] calculateMobTexture(int xMin, int yMin, int xMax, int yMax, float textureWidth, float textureHeight){ 98 | float[] texturePoints = new float[4]; 99 | 100 | texturePoints[0] = (float)xMin/textureWidth; //min x (-) 101 | texturePoints[1] = (float)xMax/textureWidth; //max x (+) 102 | 103 | texturePoints[2] = (float)yMin/textureHeight; //min y (-) 104 | texturePoints[3] = (float)yMax/textureHeight; //max y (+) 105 | return texturePoints; 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | CC0 1.0 Universal 2 | 3 | Official translations of this legal tool are available 4 | CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED HEREUNDER. 5 | Statement of Purpose 6 | The laws of most jurisdictions throughout the world automatically confer exclusive Copyright and Related Rights (defined below) upon the creator and subsequent owner(s) (each and all, an "owner") of an original work of authorship and/or a database (each, a "Work"). 7 | 8 | Certain owners wish to permanently relinquish those rights to a Work for the purpose of contributing to a commons of creative, cultural and scientific works ("Commons") that the public can reliably and without fear of later claims of infringement build upon, modify, incorporate in other works, reuse and redistribute as freely as possible in any form whatsoever and for any purposes, including without limitation commercial purposes. These owners may contribute to the Commons to promote the ideal of a free culture and the further production of creative, cultural and scientific works, or to gain reputation or greater distribution for their Work in part through the use and efforts of others. 9 | 10 | For these and/or other purposes and motivations, and without any expectation of additional consideration or compensation, the person associating CC0 with a Work (the "Affirmer"), to the extent that he or she is an owner of Copyright and Related Rights in the Work, voluntarily elects to apply CC0 to the Work and publicly distribute the Work under its terms, with knowledge of his or her Copyright and Related Rights in the Work and the meaning and intended legal effect of CC0 on those rights. 11 | 12 | 1. Copyright and Related Rights. A Work made available under CC0 may be protected by copyright and related or neighboring rights ("Copyright and Related Rights"). Copyright and Related Rights include, but are not limited to, the following: 13 | 14 | the right to reproduce, adapt, distribute, perform, display, communicate, and translate a Work; 15 | moral rights retained by the original author(s) and/or performer(s); 16 | publicity and privacy rights pertaining to a person's image or likeness depicted in a Work; 17 | rights protecting against unfair competition in regards to a Work, subject to the limitations in paragraph 4(a), below; 18 | rights protecting the extraction, dissemination, use and reuse of data in a Work; 19 | database rights (such as those arising under Directive 96/9/EC of the European Parliament and of the Council of 11 March 1996 on the legal protection of databases, and under any national implementation thereof, including any amended or successor version of such directive); and 20 | other similar, equivalent or corresponding rights throughout the world based on applicable law or treaty, and any national implementations thereof. 21 | 2. Waiver. To the greatest extent permitted by, but not in contravention of, applicable law, Affirmer hereby overtly, fully, permanently, irrevocably and unconditionally waives, abandons, and surrenders all of Affirmer's Copyright and Related Rights and associated claims and causes of action, whether now known or unknown (including existing as well as future claims and causes of action), in the Work (i) in all territories worldwide, (ii) for the maximum duration provided by applicable law or treaty (including future time extensions), (iii) in any current or future medium and for any number of copies, and (iv) for any purpose whatsoever, including without limitation commercial, advertising or promotional purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each member of the public at large and to the detriment of Affirmer's heirs and successors, fully intending that such Waiver shall not be subject to revocation, rescission, cancellation, termination, or any other legal or equitable action to disrupt the quiet enjoyment of the Work by the public as contemplated by Affirmer's express Statement of Purpose. 22 | 23 | 3. Public License Fallback. Should any part of the Waiver for any reason be judged legally invalid or ineffective under applicable law, then the Waiver shall be preserved to the maximum extent permitted taking into account Affirmer's express Statement of Purpose. In addition, to the extent the Waiver is so judged Affirmer hereby grants to each affected person a royalty-free, non transferable, non sublicensable, non exclusive, irrevocable and unconditional license to exercise Affirmer's Copyright and Related Rights in the Work (i) in all territories worldwide, (ii) for the maximum duration provided by applicable law or treaty (including future time extensions), (iii) in any current or future medium and for any number of copies, and (iv) for any purpose whatsoever, including without limitation commercial, advertising or promotional purposes (the "License"). The License shall be deemed effective as of the date CC0 was applied by Affirmer to the Work. Should any part of the License for any reason be judged legally invalid or ineffective under applicable law, such partial invalidity or ineffectiveness shall not invalidate the remainder of the License, and in such case Affirmer hereby affirms that he or she will not (i) exercise any of his or her remaining Copyright and Related Rights in the Work or (ii) assert any associated claims and causes of action with respect to the Work, in either case contrary to Affirmer's express Statement of Purpose. 24 | 25 | 4. Limitations and Disclaimers. 26 | 27 | No trademark or patent rights held by Affirmer are waived, abandoned, surrendered, licensed or otherwise affected by this document. 28 | Affirmer offers the Work as-is and makes no representations or warranties of any kind concerning the Work, express, implied, statutory or otherwise, including without limitation warranties of title, merchantability, fitness for a particular purpose, non infringement, or the absence of latent or other defects, accuracy, or the present or absence of errors, whether or not discoverable, all to the greatest extent permissible under applicable law. 29 | Affirmer disclaims responsibility for clearing rights of other persons that may apply to the Work or any use thereof, including without limitation any person's Copyright and Related Rights in the Work. Further, Affirmer disclaims responsibility for obtaining any necessary consents, permissions or other rights required for any use of the Work. 30 | Affirmer understands and acknowledges that Creative Commons is not a party to this document and has no duty or obligation with respect to this CC0 or use of the Work. 31 | -------------------------------------------------------------------------------- /src/main/java/game/clouds/CloudMesh.java: -------------------------------------------------------------------------------- 1 | package game.clouds; 2 | 3 | import engine.graphics.Mesh; 4 | import engine.graphics.Texture; 5 | import engine.highPerformanceContainers.HyperFloatArray; 6 | import engine.highPerformanceContainers.HyperIntArray; 7 | 8 | public class CloudMesh { 9 | 10 | private final Cloud cloud; 11 | 12 | public CloudMesh(Cloud cloud){ 13 | this.cloud = cloud; 14 | } 15 | 16 | 17 | 18 | public Mesh buildCloud3DMesh(){ 19 | final HyperFloatArray positions = new HyperFloatArray(12); 20 | final HyperFloatArray textureCoord = new HyperFloatArray(8); 21 | final HyperIntArray indices = new HyperIntArray(6); 22 | final HyperFloatArray light = new HyperFloatArray(12); 23 | 24 | float[] textureWorker; 25 | 26 | 27 | float height = 0.2f * cloud.getCloudScale(); 28 | float width = cloud.getCloudScale(); 29 | 30 | int indicesCount = 0; 31 | 32 | //front 33 | positions.pack(width, height, width, 0f, height, width, 0f, 0f, width, width, 0f, width); 34 | 35 | //front 36 | light.pack(1); 37 | 38 | 39 | //front 40 | indices.pack(indicesCount, 1 + indicesCount, 2 + indicesCount, indicesCount, 2 + indicesCount, 3 + indicesCount); 41 | 42 | indicesCount += 4; 43 | 44 | textureWorker = calculateTexture(2); 45 | 46 | //front 47 | textureCoord.pack(textureWorker[1], textureWorker[2], textureWorker[0], textureWorker[2], textureWorker[0], textureWorker[3], textureWorker[1], textureWorker[3]); 48 | 49 | 50 | 51 | //back 52 | positions.pack(0f, height, 0f, width, height, 0f, width, 0f, 0f, 0f, 0f, 0f); 53 | 54 | light.pack(1); 55 | 56 | 57 | //back 58 | indices.pack(indicesCount, 1 + indicesCount, 2 + indicesCount, indicesCount, 2 + indicesCount, 3 + indicesCount); 59 | indicesCount += 4; 60 | 61 | textureWorker = calculateTexture(2); 62 | //back 63 | textureCoord.pack(textureWorker[1], textureWorker[2], textureWorker[0], textureWorker[2], textureWorker[0], textureWorker[3], textureWorker[1], textureWorker[3]); 64 | 65 | 66 | //right 67 | positions.pack(width, height, 0f, width, height, width, width, 0f, width, width, 0f, 0f); 68 | 69 | light.pack(1); 70 | 71 | //right 72 | indices.pack(indicesCount, 1 + indicesCount, 2 + indicesCount, indicesCount, 2 + indicesCount, 3 + indicesCount); 73 | 74 | indicesCount += 4; 75 | 76 | textureWorker = calculateTexture(2); 77 | //right 78 | textureCoord.pack(textureWorker[1], textureWorker[2], textureWorker[0], textureWorker[2], textureWorker[0], textureWorker[3], textureWorker[1], textureWorker[3]); 79 | 80 | 81 | 82 | 83 | //left 84 | positions.pack(0f, height, width, 0f, height, 0f, 0f, 0f, 0f, 0f, 0f, width); 85 | 86 | //left 87 | light.pack(1); 88 | 89 | //left 90 | indices.pack(indicesCount, 1 + indicesCount, 2 + indicesCount, indicesCount, 2 + indicesCount, 3 + indicesCount); 91 | indicesCount += 4; 92 | 93 | textureWorker = calculateTexture(2); 94 | //left 95 | textureCoord.pack(textureWorker[1], textureWorker[2], textureWorker[0], textureWorker[2], textureWorker[0], textureWorker[3], textureWorker[1], textureWorker[3]); 96 | 97 | 98 | //top 99 | positions.pack(0f, height, 0f, 0f, height, width, width, height, width, width, height, 0f); 100 | 101 | 102 | 103 | light.pack(1); 104 | 105 | 106 | //top 107 | indices.pack(indicesCount, 1 + indicesCount, 2 + indicesCount, indicesCount, 2 + indicesCount, 3 + indicesCount); 108 | indicesCount += 4; 109 | 110 | textureWorker = calculateTexture(1); 111 | //top 112 | textureCoord.pack(textureWorker[1], textureWorker[2], textureWorker[0], textureWorker[2], textureWorker[0], textureWorker[3], textureWorker[1], textureWorker[3]); 113 | 114 | 115 | 116 | //bottom 117 | positions.pack(0f, 0f, width, 0f, 0f, 0f, width, 0f, 0f, width, 0f, width); 118 | 119 | light.pack(1); 120 | 121 | 122 | //bottom 123 | indices.pack(indicesCount, 1 + indicesCount, 2 + indicesCount, indicesCount, 2 + indicesCount, 3 + indicesCount); 124 | 125 | textureWorker = calculateTexture(0); 126 | //bottom 127 | textureCoord.pack(textureWorker[1], textureWorker[2], textureWorker[0], textureWorker[2], textureWorker[0], textureWorker[3], textureWorker[1], textureWorker[3]); 128 | 129 | 130 | Mesh cloud3DMesh = new Mesh(positions.values(), light.values(), indices.values(), textureCoord.values(), new Texture("textures/cloud.png")); 131 | 132 | positions.clear(); 133 | light.clear(); 134 | indices.clear(); 135 | textureCoord.clear(); 136 | 137 | return cloud3DMesh; 138 | } 139 | 140 | public Mesh buildCloud2DMesh() { 141 | float[] positions = new float[12]; 142 | float[] textureCoord = new float[8]; 143 | int[] indices = new int[6]; 144 | float[] light = new float[12]; 145 | 146 | 147 | float width = cloud.getCloudScale(); 148 | 149 | positions[0] = (width); 150 | positions[1] = (0); 151 | positions[2] = (width); 152 | 153 | positions[3] = (0); 154 | positions[4] = (0); 155 | positions[5] = (width); 156 | 157 | positions[6] = (0); 158 | positions[7] = (0); 159 | positions[8] = (0); 160 | 161 | positions[9] = (width); 162 | positions[10] = (0); 163 | positions[11] = (0); 164 | 165 | for (int i = 0; i < 12; i++) { 166 | light[i] = 1; 167 | } 168 | 169 | indices[0] = (0); 170 | indices[1] = (1); 171 | indices[2] = (2); 172 | indices[3] = (0); 173 | indices[4] = (2); 174 | indices[5] = (3); 175 | 176 | float[] textureWorker = calculateTexture(1); 177 | textureCoord[0] = (textureWorker[1]); 178 | textureCoord[1] = (textureWorker[2]); 179 | textureCoord[2] = (textureWorker[0]); 180 | textureCoord[3] = (textureWorker[2]); 181 | textureCoord[4] = (textureWorker[0]); 182 | textureCoord[5] = (textureWorker[3]); 183 | textureCoord[6] = (textureWorker[1]); 184 | textureCoord[7] = (textureWorker[3]); 185 | 186 | return new Mesh(positions, light, indices, textureCoord, new Texture("textures/cloud.png")); 187 | } 188 | 189 | private float[] calculateTexture(int x){ 190 | float[] texturePoints = new float[4]; 191 | byte atlasSizeX = 3; 192 | texturePoints[0] = (float)x/(float) atlasSizeX; //min x (-) 193 | texturePoints[1] = (float)(x+1)/(float) atlasSizeX; //max x (+) 194 | 195 | byte atlasSizeY = 1; 196 | texturePoints[2] = (float) 0 /(float) atlasSizeY; //min y (-) 197 | texturePoints[3] = (float)(1)/(float) atlasSizeY; //max y (+) 198 | return texturePoints; 199 | } 200 | } 201 | --------------------------------------------------------------------------------