Compare commits

...

32 commits

Author SHA1 Message Date
ab7cf3e760 Fixes 2025-08-26 22:15:39 +01:00
65f51cfe69 Optimisations 2025-07-24 00:25:20 +01:00
Oikmo
48614643e6 Create LICENSE 2024-09-10 15:55:06 +01:00
Oikmo
ea705a4194 Update SoundMaster.java 2024-09-10 07:46:07 +01:00
Oikmo
01694314d9 error fixes 2024-09-08 22:58:26 +01:00
Oikmo
1b47d2b37f Update Main.java 2024-09-08 22:33:26 +01:00
Oikmo
3d56f68c51 back face culling 2024-09-08 22:31:52 +01:00
Oikmo
75ba2c68a1 more documentation 2024-09-07 20:14:27 +01:00
Oikmo
9401b87615 the beginning of misery
javadocs
2024-09-07 01:47:06 +01:00
Oikmo
87da16fd08 sub dev 3 2024-09-05 07:19:26 +01:00
Oikmo
5214e7fac9 servers are back up
also increased scan size for isInValidRange
2024-07-10 21:44:19 +01:00
Oikmo
40ba07ef58 Update World.java 2024-07-10 05:02:42 +01:00
Oikmo
33393324a2 Better world rendering
no mo WORLD_SIZE and also network protocol 7 and networkhandler should be less prone to nulling or something
2024-07-10 05:01:22 +01:00
Oikmo
9329b8f9b5 Update Main.java 2024-07-09 04:13:55 +01:00
Oikmo
ab67558754 lotta things
I'm back!
What's up vros...

So changed the blocks to be 0 indexed rather than -1 as it took longer to load/generate chunks (now loading times are about less than 1s)

Changed the server list to be NBT
Made it so transparent skins will show black. (fuck you epic)
2024-07-08 15:26:32 +01:00
Oikmo
aaf321a23c changed to blockbase.gurdit.com 2024-06-11 17:18:52 +01:00
Oikmo
0e74ddad64 fonts 2024-06-01 00:33:34 +01:00
Oikmo
fafc4d1078 added loading screen at launch 2024-05-29 01:55:43 +01:00
Oikmo
62e4bcaf87 more optimizations and nbt saving 2024-05-27 17:47:04 +01:00
Oikmo
04803a4abf more fixes
- footsteps still need to be worked on
- added stop music to network handler
- slayyyTick is now runTick
2024-05-24 01:42:07 +01:00
Oikmo
ffe5d0bd53 dev version update 2024-05-24 01:07:01 +01:00
Oikmo
5ddf8be70c nbt, faster chunk rendering, jack block
that and improved chunk searcher along with view distance option
2024-05-24 00:52:06 +01:00
Oikmo
27f13d999b added vsync and added lerp to camera in F5
also changed it so that the movement is smoother but the rotations updated at every 5 ticks (5/60th of a sec)
2024-05-23 08:17:23 +01:00
Oikmo
44edb2d252 removed ogg length retriever and added F5 perspective 2024-05-22 17:31:32 +01:00
Oikmo
4686d4c406 network update and save player position based on username 2024-05-22 08:28:37 +01:00
Oikmo
ef1e985f12 players now have skins connected to the website 2024-05-22 08:11:11 +01:00
Oikmo
5b61a82416 adding afs.gurdit.com connections 2024-05-21 21:31:51 +01:00
Oikmo
6d2cec6ffa update 2024-05-20 21:51:57 +01:00
Oikmo
cc8cc36e2b disabled tnt
network protocol updated
2024-05-18 22:21:48 +01:00
Oikmo
7dae197797
Update README.md 2024-05-18 00:40:25 +01:00
Oikmo
a92c4932b1 Alpha 0.1.9
the real one 😔
this was just a whole lotta bug fixes
2024-05-18 00:12:35 +01:00
Oikmo
eb6536db74 Alpha 0.1.9 fix 2024-05-17 11:27:48 +01:00

View file

@ -15,14 +15,13 @@
<classpathentry kind="lib" path="libraries/jar/lwjgl.jar">
<attributes>
<attribute name="javadoc_location" value="jar:platform:/resource/BlockBase/libraries/jar/javadoc/lwjgl-2.9.3-javadoc.jar!/"/>
<attribute name="org.eclipse.jdt.launching.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY" value="BlockBase/libraries/native/windows"/>
<attribute name="org.eclipse.jdt.launching.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY" value="BlockBase-Client/libraries/native/windows"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="libraries/jar/PNGDecoder.jar"/>
<classpathentry kind="lib" path="libraries/jar/soundsystem.jar"/>
<classpathentry kind="lib" path="libraries/jar/ss-codecs.jar"/>
<classpathentry kind="lib" path="libraries/jar/ss-libraries.jar"/>
<classpathentry kind="lib" path="libraries/jar/jaudiotagger-3.0.1.jar"/>
<classpathentry kind="lib" path="libraries/jar/slick.jar"/>
<classpathentry kind="lib" path="libraries/jar/kryonet-all-2.21.jar"/>
<classpathentry kind="output" path="bin"/>

2
.codetogether.ignore Normal file
View file

@ -0,0 +1,2 @@
/**
/**

2
.gitignore vendored
View file

@ -1,2 +1,2 @@
bin/*
src/net/oikmo/test/RoundingTest.java
doc/*

View file

@ -1,3 +0,0 @@
eclipse.preferences.version=1
encoding//res/assets/splashes.txt=UTF-8
encoding/<project>=windows-1252

View file

@ -1,12 +1,7 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=1.8

11
LICENSE Normal file
View file

@ -0,0 +1,11 @@
ManiaticDevs License
> Version 1.0, September 2024
> Copyright (C) 2024 ManiaticDevs
Permission of using this project's source code is granted but under specific terms:
1. Give credits where credit is due, ALWAYS.
2. Not to allow this project's source code anywhere in any Generative AI training data.
That is all. Thank you.

View file

@ -19,3 +19,8 @@
- F2 - take screenshot
- F3 - toggle debug ui
- F11 - toggle fullscreen
Credits
- Reon Fourie voxel engine tutorials (head start)
- ThinMatrix (for the reason I know how to make these)
- Mojang for the assets (and erm particles)

View file

@ -13,12 +13,24 @@ pause.players.identifier=You
options.title=Options
options.fov.low=telescope
options.fov.normal=Normal
options.fov.high=QUAKE FOV!!!
options.volume=Volume
options.fov.high=QUAKE PRO!!!
options.fov=FOV
options.sensitivity.low=*yawn*
options.sensitivity.high=hyperspeed!!!
options.sensitivity=Sensitivity
options.vsync=VSYNC
options.volume=Volume
options.distance=View Distance
options.distance.tiny=TINY
options.distance.small=SMALL
options.distance.normal=NORMAL
options.distance.far=FAR
inventory.title=Blocks
world.create.superflat=Superflat
world.create.seed=Seed here...
world.create=Create world
world.select.create=Create new world...
network.connecting=Connecting

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

View file

@ -1,100 +0,0 @@
info face="Minecraft Regular" size=49 bold=0 italic=0 charset="" unicode=0 stretchH=100 smooth=1 aa=1 padding=8,8,8,8 spacing=0,0
common lineHeight=79 base=56 scaleW=512 scaleH=512 pages=1 packed=0
page id=0 file="minecraft.png"
chars count=95
char id=32 x=0 y=0 width=0 height=0 xoffset=0 yoffset=56 xadvance=28 page=0 chnl=0
char id=106 x=0 y=0 width=48 height=66 xoffset=-7 yoffset=5 xadvance=53 page=0 chnl=0
char id=127 x=48 y=0 width=84 height=60 xoffset=-7 yoffset=5 xadvance=34 page=0 chnl=0
char id=38 x=132 y=0 width=48 height=60 xoffset=-7 yoffset=5 xadvance=53 page=0 chnl=0
char id=35 x=180 y=0 width=48 height=60 xoffset=-7 yoffset=5 xadvance=53 page=0 chnl=0
char id=37 x=228 y=0 width=48 height=60 xoffset=-7 yoffset=5 xadvance=53 page=0 chnl=0
char id=36 x=276 y=0 width=48 height=60 xoffset=-7 yoffset=5 xadvance=53 page=0 chnl=0
char id=92 x=324 y=0 width=48 height=60 xoffset=-7 yoffset=5 xadvance=53 page=0 chnl=0
char id=64 x=372 y=0 width=54 height=60 xoffset=-7 yoffset=5 xadvance=59 page=0 chnl=0
char id=47 x=426 y=0 width=48 height=60 xoffset=-7 yoffset=5 xadvance=53 page=0 chnl=0
char id=124 x=474 y=0 width=24 height=60 xoffset=-7 yoffset=5 xadvance=28 page=0 chnl=0
char id=62 x=0 y=66 width=42 height=60 xoffset=-7 yoffset=5 xadvance=46 page=0 chnl=0
char id=60 x=42 y=66 width=42 height=60 xoffset=-7 yoffset=5 xadvance=46 page=0 chnl=0
char id=125 x=84 y=66 width=42 height=60 xoffset=-7 yoffset=5 xadvance=46 page=0 chnl=0
char id=123 x=126 y=66 width=42 height=60 xoffset=-7 yoffset=5 xadvance=46 page=0 chnl=0
char id=93 x=168 y=66 width=36 height=60 xoffset=-7 yoffset=5 xadvance=40 page=0 chnl=0
char id=91 x=204 y=66 width=36 height=60 xoffset=-7 yoffset=5 xadvance=41 page=0 chnl=0
char id=41 x=240 y=66 width=42 height=60 xoffset=-7 yoffset=5 xadvance=46 page=0 chnl=0
char id=40 x=282 y=66 width=42 height=60 xoffset=-7 yoffset=5 xadvance=46 page=0 chnl=0
char id=59 x=324 y=66 width=24 height=60 xoffset=-7 yoffset=11 xadvance=28 page=0 chnl=0
char id=63 x=348 y=66 width=48 height=60 xoffset=-7 yoffset=5 xadvance=53 page=0 chnl=0
char id=33 x=396 y=66 width=24 height=60 xoffset=-7 yoffset=5 xadvance=28 page=0 chnl=0
char id=48 x=420 y=66 width=48 height=60 xoffset=-7 yoffset=5 xadvance=53 page=0 chnl=0
char id=57 x=0 y=126 width=48 height=60 xoffset=-7 yoffset=5 xadvance=53 page=0 chnl=0
char id=56 x=48 y=126 width=48 height=60 xoffset=-7 yoffset=5 xadvance=53 page=0 chnl=0
char id=55 x=96 y=126 width=48 height=60 xoffset=-7 yoffset=5 xadvance=53 page=0 chnl=0
char id=54 x=144 y=126 width=48 height=60 xoffset=-7 yoffset=5 xadvance=53 page=0 chnl=0
char id=53 x=192 y=126 width=48 height=60 xoffset=-7 yoffset=5 xadvance=53 page=0 chnl=0
char id=52 x=240 y=126 width=48 height=60 xoffset=-7 yoffset=5 xadvance=53 page=0 chnl=0
char id=51 x=288 y=126 width=48 height=60 xoffset=-7 yoffset=5 xadvance=53 page=0 chnl=0
char id=50 x=336 y=126 width=48 height=60 xoffset=-7 yoffset=5 xadvance=53 page=0 chnl=0
char id=49 x=384 y=126 width=48 height=60 xoffset=-7 yoffset=5 xadvance=53 page=0 chnl=0
char id=116 x=432 y=126 width=36 height=60 xoffset=-7 yoffset=5 xadvance=40 page=0 chnl=0
char id=108 x=468 y=126 width=30 height=60 xoffset=-7 yoffset=5 xadvance=34 page=0 chnl=0
char id=107 x=0 y=186 width=42 height=60 xoffset=-7 yoffset=5 xadvance=46 page=0 chnl=0
char id=105 x=42 y=186 width=24 height=60 xoffset=-7 yoffset=5 xadvance=28 page=0 chnl=0
char id=104 x=66 y=186 width=48 height=60 xoffset=-7 yoffset=5 xadvance=53 page=0 chnl=0
char id=102 x=114 y=186 width=41 height=60 xoffset=-7 yoffset=5 xadvance=46 page=0 chnl=0
char id=100 x=155 y=186 width=48 height=60 xoffset=-7 yoffset=5 xadvance=53 page=0 chnl=0
char id=98 x=203 y=186 width=48 height=60 xoffset=-7 yoffset=5 xadvance=53 page=0 chnl=0
char id=90 x=251 y=186 width=48 height=60 xoffset=-7 yoffset=5 xadvance=53 page=0 chnl=0
char id=89 x=299 y=186 width=48 height=60 xoffset=-7 yoffset=5 xadvance=53 page=0 chnl=0
char id=88 x=347 y=186 width=48 height=60 xoffset=-7 yoffset=5 xadvance=53 page=0 chnl=0
char id=87 x=395 y=186 width=48 height=60 xoffset=-7 yoffset=5 xadvance=53 page=0 chnl=0
char id=86 x=443 y=186 width=48 height=60 xoffset=-7 yoffset=5 xadvance=53 page=0 chnl=0
char id=85 x=0 y=246 width=48 height=60 xoffset=-7 yoffset=5 xadvance=53 page=0 chnl=0
char id=84 x=48 y=246 width=48 height=60 xoffset=-7 yoffset=5 xadvance=53 page=0 chnl=0
char id=83 x=96 y=246 width=48 height=60 xoffset=-7 yoffset=5 xadvance=53 page=0 chnl=0
char id=82 x=144 y=246 width=48 height=60 xoffset=-7 yoffset=5 xadvance=53 page=0 chnl=0
char id=81 x=192 y=246 width=48 height=60 xoffset=-7 yoffset=5 xadvance=53 page=0 chnl=0
char id=80 x=240 y=246 width=48 height=60 xoffset=-7 yoffset=5 xadvance=53 page=0 chnl=0
char id=79 x=288 y=246 width=48 height=60 xoffset=-7 yoffset=5 xadvance=53 page=0 chnl=0
char id=78 x=336 y=246 width=48 height=60 xoffset=-7 yoffset=5 xadvance=53 page=0 chnl=0
char id=77 x=384 y=246 width=48 height=60 xoffset=-7 yoffset=5 xadvance=53 page=0 chnl=0
char id=76 x=432 y=246 width=48 height=60 xoffset=-7 yoffset=5 xadvance=53 page=0 chnl=0
char id=75 x=0 y=306 width=48 height=60 xoffset=-7 yoffset=5 xadvance=53 page=0 chnl=0
char id=74 x=48 y=306 width=48 height=60 xoffset=-7 yoffset=5 xadvance=53 page=0 chnl=0
char id=73 x=96 y=306 width=35 height=60 xoffset=-7 yoffset=5 xadvance=40 page=0 chnl=0
char id=72 x=131 y=306 width=48 height=60 xoffset=-7 yoffset=5 xadvance=53 page=0 chnl=0
char id=71 x=179 y=306 width=48 height=60 xoffset=-7 yoffset=5 xadvance=53 page=0 chnl=0
char id=70 x=227 y=306 width=48 height=60 xoffset=-7 yoffset=5 xadvance=53 page=0 chnl=0
char id=69 x=275 y=306 width=48 height=60 xoffset=-7 yoffset=5 xadvance=53 page=0 chnl=0
char id=68 x=323 y=306 width=48 height=60 xoffset=-7 yoffset=5 xadvance=53 page=0 chnl=0
char id=67 x=371 y=306 width=48 height=60 xoffset=-7 yoffset=5 xadvance=53 page=0 chnl=0
char id=66 x=419 y=306 width=48 height=60 xoffset=-7 yoffset=5 xadvance=53 page=0 chnl=0
char id=65 x=0 y=366 width=48 height=60 xoffset=-7 yoffset=5 xadvance=53 page=0 chnl=0
char id=58 x=48 y=366 width=24 height=54 xoffset=-7 yoffset=11 xadvance=28 page=0 chnl=0
char id=121 x=72 y=366 width=48 height=54 xoffset=-7 yoffset=17 xadvance=53 page=0 chnl=0
char id=113 x=120 y=366 width=48 height=54 xoffset=-7 yoffset=17 xadvance=53 page=0 chnl=0
char id=112 x=168 y=366 width=48 height=54 xoffset=-7 yoffset=17 xadvance=53 page=0 chnl=0
char id=103 x=216 y=366 width=48 height=54 xoffset=-7 yoffset=17 xadvance=53 page=0 chnl=0
char id=43 x=264 y=366 width=48 height=48 xoffset=-7 yoffset=17 xadvance=53 page=0 chnl=0
char id=122 x=312 y=366 width=48 height=48 xoffset=-7 yoffset=17 xadvance=53 page=0 chnl=0
char id=120 x=360 y=366 width=48 height=48 xoffset=-7 yoffset=17 xadvance=53 page=0 chnl=0
char id=119 x=408 y=366 width=48 height=48 xoffset=-7 yoffset=17 xadvance=53 page=0 chnl=0
char id=118 x=456 y=366 width=48 height=48 xoffset=-7 yoffset=17 xadvance=53 page=0 chnl=0
char id=117 x=0 y=426 width=48 height=48 xoffset=-7 yoffset=17 xadvance=53 page=0 chnl=0
char id=115 x=48 y=426 width=48 height=48 xoffset=-7 yoffset=17 xadvance=53 page=0 chnl=0
char id=114 x=96 y=426 width=48 height=48 xoffset=-7 yoffset=17 xadvance=53 page=0 chnl=0
char id=111 x=144 y=426 width=48 height=48 xoffset=-7 yoffset=17 xadvance=53 page=0 chnl=0
char id=110 x=192 y=426 width=48 height=48 xoffset=-7 yoffset=17 xadvance=53 page=0 chnl=0
char id=109 x=240 y=426 width=48 height=48 xoffset=-7 yoffset=17 xadvance=53 page=0 chnl=0
char id=101 x=288 y=426 width=48 height=48 xoffset=-7 yoffset=17 xadvance=53 page=0 chnl=0
char id=99 x=336 y=426 width=48 height=48 xoffset=-7 yoffset=17 xadvance=53 page=0 chnl=0
char id=97 x=384 y=426 width=48 height=48 xoffset=-7 yoffset=17 xadvance=53 page=0 chnl=0
char id=61 x=432 y=426 width=48 height=42 xoffset=-7 yoffset=17 xadvance=53 page=0 chnl=0
char id=42 x=0 y=474 width=42 height=36 xoffset=-7 yoffset=17 xadvance=46 page=0 chnl=0
char id=94 x=42 y=474 width=48 height=36 xoffset=-7 yoffset=4 xadvance=53 page=0 chnl=0
char id=44 x=90 y=474 width=24 height=36 xoffset=-7 yoffset=35 xadvance=28 page=0 chnl=0
char id=126 x=114 y=474 width=54 height=30 xoffset=-7 yoffset=4 xadvance=59 page=0 chnl=0
char id=96 x=168 y=474 width=30 height=30 xoffset=-7 yoffset=4 xadvance=34 page=0 chnl=0
char id=46 x=198 y=474 width=24 height=29 xoffset=-7 yoffset=36 xadvance=28 page=0 chnl=0
char id=39 x=222 y=474 width=24 height=29 xoffset=-7 yoffset=5 xadvance=28 page=0 chnl=0
char id=34 x=246 y=474 width=36 height=29 xoffset=-7 yoffset=5 xadvance=40 page=0 chnl=0
char id=95 x=282 y=474 width=48 height=24 xoffset=-7 yoffset=47 xadvance=53 page=0 chnl=0
char id=45 x=330 y=474 width=48 height=24 xoffset=-7 yoffset=29 xadvance=53 page=0 chnl=0

Binary file not shown.

Before

Width:  |  Height:  |  Size: 86 KiB

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
res/assets/gu-l_menu.ogg Normal file

Binary file not shown.

View file

@ -13,12 +13,24 @@ pause.players.identifier=You
options.title=Options
options.fov.low=telescope
options.fov.normal=Normal
options.fov.high=QUAKE FOV!!!
options.volume=Volume
options.fov.high=QUAKE PRO!!!
options.fov=FOV
options.sensitivity.low=*yawn*
options.sensitivity.high=hyperspeed!!!
options.sensitivity=Sensitivity
options.vsync=VSYNC
options.volume=Volume
options.distance=View Distance
options.distance.tiny=TINY
options.distance.small=SMALL
options.distance.normal=NORMAL
options.distance.far=FAR
inventory.title=Blocks
world.create.superflat=Superflat
world.create.seed=Seed here...
world.create=Create world
world.select.create=Create new world...
network.connecting=Connecting

View file

@ -0,0 +1,49 @@
gui.done=Skończ
gui.delete=Usuń
gui.cancel=Powrót
gui.quit=Wróć do menu głównego
title.singleplayer=Jeden gracz
title.multiplayer=Tryb wieloosobowy
title.quit=Opuśc
pause.title=Gra zamrożona
pause.players.title=Gracze
pause.players.identifier=Ty
options.title=Opcje
options.fov.low=Bardzo ciasne
options.fov.normal=Normalne
options.fov.high=Jakbyś grał w Quake'a
options.fov=Pole widzenia
options.sensitivity.low=Wolne
options.sensitivity.szybkie
options.sensitivity=Wrażliwość
options.volume=Dźwięk
inventory.title=Bloki
world.select.create=Stworzyć nowy świat...
network.connecting=łączysz się
network.error.noinput=Nie podałeś adresu!
network.error.server=Nie można połączyć się z serwerem!
network.disconnect.l=Nie udało się zalogować
network.disconnect.p=Zły protokół! (%s)
network.disconnect.g=Rozłączyłeś się
network.disconnect.u=Nieznane
network.disconnect.ux=Nieznane (Zły protokół?)
network.disconnect.n=Sieć nie działała!
network.quit.d=Rozłączyłeś się:
network.quit.k=Wyrzucony z gry:
network.servers.add=Dodaj serwer
network.servers.refresh=Odśwież
network.servers.add.title=Zarejestruj serwer...
network.servers.add.save=Dodaj serwer
network.servers.add.input.name=Nazwa serwera tutaj...
network.servers.add.input.ip=Adres serwera tutaj...
network.servers.add.quit=Wracając do serwerów

View file

@ -136,4 +136,79 @@ Not a .scr file!
9/10 Gamers recommend!
Oh uh well.. I have 7 trillion power in-!
Half-way through being high.
Now with friends!
Now with friends!
oi oi oi
once criminal, always a criminal... Elijah be like........
Jay never confesed his gay love...
Doors remake
Lilginger likes miners.
BlockBased.
Chuckeebees
MatPatmorphisis
Baba like balls
Look Gordon! Explosives!
You are a week away from your trial ending.
There's no pee breaks allowed during gameplay!
Linux support coming in 2078!
I've made a severe and continuous lapse in my judgement...
Wee uuu I look just like buddy holly
I killed John Lenin.
Going once! Going twice! Won't these gentlemen suffice?
Look you, you too uptight, y'know
"But I'm a creep" - uncle
Juno was mad. He knew he'd been had...
One secondary smile! To go that extra mile!
Do you like how I walk? Do you like how I talk?
Do you like how my face disintergrates into chalk?
How richboys dress... with Zirconium of course!
Beam me up Scotty!
mm I love to shit on the holodeck
Was that the bite of 87?!
Bazinga!
Hey Schat!
John pork is calling...
Now 100% more controversial!
69 is the only dinner for two.
Not a zip bomb!
Individually.
Watch the Tally Hall Internet Show!
Now with 50% nitroglycerin!
Dispenser going up!
*Laughs in demolition scottish*
Can I get a hit of that glue stick?
wocanitbenou?
Sequel to the hit game: Five Nights in Anime 3D
4Chan Proof!
INSERT CASH OR SELECT PAYMENT TYPE
Alone... At the edge of the universe, humming a tune...
All... for nothing at all...
All my fellas! *epic piano*
Good morning USAAAAAAAAA
New PC who dis?
:3
There was this town... "Silent Hill"
Letting the days go by, water flowing underground!
Once in a lifetime! (same as it ever was)
Saorise is gay
#Cancel Caitlin #Discrimination
"There's no gays in Ireland Cathleen!" - some bloke
You look like an overriped turnip...
Caitlin's balding!
*deranged screaming*
I got my hand stuck in a bin!
Now, you maybe wondering how I got myself into this situation...
Malaria! *WWE entrance*
"If Mr.Collins asks, I fought a junior for this." - Saorise with Caitlin's bag
Gordon, you lousy motherfucker!
Get your dork ass down to the test chamber or else I'll shove that sample up your ass!
STOP FUCKING WITH THE MICROWAVE!!!!!!
Gordon doesn't need to hear any of this, he is a highly trained professional!
Didn't see you get on the train...
*Eli Vance groan*
I AM NOT A MORON!
100% filled with bugs!
Did you know? On June 4th 2023, BlockBase was created!
Titanfall... Engage!
The horngus of a dongfish is attached by a scungle to a kind of dillsack (the nutte sac).
Self love is gay. Always hate yourself.
Be the reason the IT guy is called.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

View file

Before

Width:  |  Height:  |  Size: 81 B

After

Width:  |  Height:  |  Size: 81 B

Before After
Before After

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 210 KiB

After

Width:  |  Height:  |  Size: 223 KiB

Before After
Before After

View file

@ -21,7 +21,7 @@ public class Particle extends Entity {
public Particle(float x, float y, float z, float velX, float var6, float var7, Block block) {
super(new Vector3f(), new Vector3f(), 0.2f);
this.tex = block.getType();
this.tex = block.getType()-1;
this.gravity = 0.5f;
this.setSize(0.2F, 0.2F);
this.heightOffset = this.bbHeight / 2.0F;

View file

@ -1,14 +1,34 @@
package com.mojang.minecraft.phys;
/**
* Bounding boxes
* @author Notch
*/
public class AABB {
/** Amount of error */
private float epsilon = 0.0F;
/** The first x coordinate of a bounding box. */
public float minX;
/** The first y coordinate of a bounding box. */
public float minY;
/** The first z coordinate of a bounding box. */
public float minZ;
/** The second x coordinate of a bounding box. */
public float maxX;
/** The second y coordinate of a bounding box. */
public float maxY;
/** The second z coordinate of a bounding box. */
public float maxZ;
/**
* AABB Constructor
* @param x0 The first x coordinate of a bounding box.
* @param y0 The first y coordinate of a bounding box.
* @param z0 The first z coordinate of a bounding box.
* @param x1 The second x coordinate of a bounding box.
* @param y1 The second y coordinate of a bounding box.
* @param z1 The second z coordinate of a bounding box.
*/
public AABB(float x0, float y0, float z0, float x1, float y1, float z1) {
this.minX = x0;
this.minY = y0;
@ -18,6 +38,13 @@ public class AABB {
this.maxZ = z1;
}
/**
* Returns a bounding box expanded by the specified vector (if negative numbers are given it will shrink).
* @param xa X size to expand to
* @param ya Y size to expand to
* @param za Z size to expand to
* @return {@link AABB}
*/
public AABB expand(float xa, float ya, float za) {
float _x0 = this.minX;
float _y0 = this.minY;
@ -51,7 +78,15 @@ public class AABB {
return new AABB(_x0, _y0, _z0, _x1, _y1, _z1);
}
/**
* Same as {@link #expand(float, float, float)}
* @param xa X size to grow to
* @param ya Y size to grow to
* @param za Z size to grow to
* @return {@link AABB}
*/
public AABB grow(float xa, float ya, float za) {
float _x0 = this.minX - xa;
float _y0 = this.minY - ya;
@ -61,7 +96,12 @@ public class AABB {
float _z1 = this.maxZ + za;
return new AABB(_x0, _y0, _z0, _x1, _y1, _z1);
}
/** Returns the amount of clipping occuring between two AABBs (and it's expected xa)
* @param c other bounding box
* @param xa predicted move to
* @return {@link Float}
*/
public float clipXCollide(AABB c, float xa) {
if(c.maxY > this.minY && c.minY < this.maxY) {
if(c.maxZ > this.minZ && c.minZ < this.maxZ) {
@ -89,6 +129,11 @@ public class AABB {
}
}
/** Returns the amount of clipping occurring between two AABBs (and it's expected ya)
* @param c other bounding box
* @param ya predicted move to
* @return {@link Float}
*/
public float clipYCollide(AABB c, float ya) {
if(c.maxX > this.minX && c.minX < this.maxX) {
if(c.maxZ > this.minZ && c.minZ < this.maxZ) {
@ -116,6 +161,11 @@ public class AABB {
}
}
/** Returns the amount of clipping occuring between two AABBs (and it's expected za)
* @param c other bounding box
* @param za predicted move to
* @return {@link Float}
*/
public float clipZCollide(AABB c, float za) {
if(c.maxX > this.minX && c.minX < this.maxX) {
if(c.maxY > this.minY && c.minY < this.maxY) {
@ -143,10 +193,20 @@ public class AABB {
}
}
/**
* Returns whether the given bounding box intersects with this one
* @param c other bounding box
* @return {@link Boolean}
*/
public boolean intersects(AABB c) {
return c.maxX > this.minX && c.minX < this.maxX ? (c.maxY > this.minY && c.minY < this.maxY ? c.maxZ > this.minZ && c.minZ < this.maxZ : false) : false;
}
/** Moves this bounding box by specified vector
* @param xa X to move by
* @param ya Y to move by
* @param za Z to move by
*/
public void move(float xa, float ya, float za) {
this.minX += xa;
this.minY += ya;

View file

@ -134,12 +134,10 @@ public class DisplayManager {
/**
* Captures a frame of the screen (getImage()) and saves it to the screenshots folder.
*
* @see getImage()
* @see getImage(BufferedImage, ByteBuffer)
*/
public static void saveScreenshot() {
File saveDirectory = new File(Main.getDir().getPath()+"/screenshots/");
File saveDirectory = new File(Main.getWorkingDirectory().getPath()+"/screenshots/");
if (!saveDirectory.exists()) {
try {
saveDirectory.mkdir();

View file

@ -7,6 +7,7 @@ import net.oikmo.engine.renderers.MasterRenderer;
import net.oikmo.main.Main;
import net.oikmo.main.gui.GuiChat;
import net.oikmo.main.gui.GuiInventory;
import net.oikmo.main.gui.GuiOptions;
import net.oikmo.main.gui.GuiPauseMenu;
public class InputManager {
@ -114,13 +115,18 @@ public class InputManager {
}
}
if((Main.inGameGUI != null) && (Main.currentScreen instanceof GuiPauseMenu || Main.currentScreen instanceof GuiInventory || Main.currentScreen == null || Main.currentScreen instanceof GuiChat)) {
if((Main.inGameGUI != null) && (Main.currentScreen instanceof GuiPauseMenu || Main.currentScreen instanceof GuiInventory || Main.currentScreen == null || Main.currentScreen instanceof GuiChat || Main.currentScreen instanceof GuiOptions)) {
if(!lockInPause) {
if(Keyboard.isKeyDown(pauseEscapeKey)) {
if(Main.currentScreen != null) {
Main.currentScreen.prepareCleanUp();
Main.currentScreen = null;
if(Main.currentScreen instanceof GuiOptions) {
Main.currentScreen.prepareCleanUp();
Main.currentScreen = new GuiPauseMenu();
} else {
Main.currentScreen.prepareCleanUp();
Main.currentScreen = null;
}
} else {
Main.currentScreen = new GuiPauseMenu();
}

View file

@ -20,7 +20,6 @@ import org.lwjgl.opengl.GL13;
import org.lwjgl.opengl.GL15;
import org.lwjgl.opengl.GL20;
import org.lwjgl.opengl.GL30;
import org.lwjgl.opengl.GL33;
import de.matthiasmann.twl.utils.PNGDecoder;
import de.matthiasmann.twl.utils.PNGDecoder.Format;
@ -44,34 +43,6 @@ public class Loader {
private static List<Integer> vbos = new ArrayList<Integer>();
private static List<Integer> textures = new ArrayList<Integer>();
public static int createEmptyVBO(int floatCount) {
int vbo = GL15.glGenBuffers();
vbos.add(vbo);
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbo);
GL15.glBufferData(GL15.GL_ARRAY_BUFFER, floatCount * 4, GL15.GL_STREAM_DRAW);
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
return vbo;
}
public static void addInstancedAttribute(int vao, int vbo, int attribute, int dataSize, int instancedDataLength, int offset) {
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbo);
GL30.glBindVertexArray(vao);
GL20.glVertexAttribPointer(attribute, dataSize, GL11.GL_FLOAT, false, instancedDataLength * 4, offset * 4);
GL33.glVertexAttribDivisor(attribute, 1);
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
GL30.glBindVertexArray(0);
}
public static void updateVBO(int vbo, float[] data, FloatBuffer buffer) {
buffer.clear();
buffer.put(data);
buffer.flip();
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbo);
GL15.glBufferData(GL15.GL_ARRAY_BUFFER, buffer.capacity() * 4, GL15.GL_STREAM_DRAW);
GL15.glBufferSubData(GL15.GL_ARRAY_BUFFER, 0, buffer);
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
}
private static int createVAO() {
int vaoID = GL30.glGenVertexArrays();
vaos.add(vaoID);
@ -94,15 +65,6 @@ public class Loader {
return new RawModel(vaoID, positions.length / dimensions);
}
public static RawModel loadToVAO(float[] vertices, int[] indices, float[] uv) {
int vaoID = createVAO();
storeDataInAttributeList(vertices, 0, 3);
storeDataInAttributeList(uv, 1, 2);
bindIndicesBuffer(indices);
unbindVAO();
return new RawModel(vaoID, indices.length);
}
public static RawModel loadToVAO(float[] vertices, float[] uv) {
int vaoID = createVAO();
storeDataInAttributeList(vertices, 0, 3);
@ -127,6 +89,15 @@ public class Loader {
unbindVAO();
return new RawModel(vaoID, positions.length);
}
public static RawModel loadToVAO(int[] positions, float[] textureCoords, int[] normals) {
int vaoID = createVAO();
storeDataInAttributeList(positions, 0, 1);
storeDataInAttributeList(textureCoords, 1, 2);
storeDataInAttributeList(normals, 2, 1);
unbindVAO();
return new RawModel(vaoID, positions.length);
}
public static int loadCubeMap(String[] textureFiles) {
int texID = GL11.glGenTextures();
@ -178,15 +149,17 @@ public class Loader {
GL20.glVertexAttribPointer(attributeNumber, dimensions, GL11.GL_FLOAT, false, 0, 0);
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
}
private static void bindIndicesBuffer(int[] indices) {
private static void storeDataInAttributeList(int[] data, int attributeNumber, int dimensions) {
int vboID = GL15.glGenBuffers();
vbos.add(vboID);
GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vboID);
IntBuffer buffer = storeDataInIntBuffer(indices);
GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, buffer, GL15.GL_STATIC_DRAW);
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboID);
IntBuffer buffer = storeDataInIntBuffer(data);
GL15.glBufferData(GL15.GL_ARRAY_BUFFER, buffer, GL15.GL_STATIC_DRAW);
GL30.glVertexAttribIPointer(attributeNumber, dimensions, GL11.GL_INT, 0, 0);
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
}
private static IntBuffer storeDataInIntBuffer(int[] data) {
IntBuffer buffer = BufferUtils.createIntBuffer(data.length);
buffer.put(data);

View file

@ -95,7 +95,7 @@ public class ResourceLoader {
}
uiTextures.clear();
for(int id : textures.values()) {
GL11.glDeleteTextures(id);
//GL11.glDeleteTextures(id);
}
textures.clear();
audioFiles.clear();

View file

@ -2,11 +2,13 @@ package net.oikmo.engine.entity;
import java.util.Random;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
import org.lwjgl.util.vector.Vector3f;
import com.mojang.minecraft.phys.AABB;
import net.oikmo.engine.DisplayManager;
import net.oikmo.engine.inventory.Item;
import net.oikmo.engine.world.blocks.Block;
import net.oikmo.main.GameSettings;
@ -17,31 +19,58 @@ import net.oikmo.toolbox.Maths;
/**
* Camera class. Allows the player to see the world.
*
* @author <i>Oikmo</i>
* @author Oikmo
*/
public class Camera {
/** The limit of looking up or down */
private int maxVerticalTurn = 90;
/** Sound listener reasons (stores camera's previous position) */
public Vector3f prevPosition;
/** Camera's current position */
private Vector3f position;
/** Pitch of the camera */
public float pitch = 0;
public float prevYaw;
/** Yaw of the camera */
public float yaw = 0;
/** Roll of the camera */
public float roll = 0;
/** Previous yaw of the camera */
public float prevYaw;
/** Dictates whether or not the mouse should be locked */
private boolean mouseLocked = true;
/** Action locker to prevent the action being done multiple times each frame */
private boolean lockInCam;
/** For currently selected blocks */
private TargetedAABB aabb;
/** For block picking */
public Vector3f forward;
/** Third person or not */
private boolean perspective = false;
/** How far should the camera be from the player if in third person */
public float distanceFromPlayer = 5;
/** X rotation around the player */
public float angleAroundPlayer = 0;
/** Action locker to prevent the action being done multiple times each frame */
private boolean mouseClickLeft = false;
/** Action locker to prevent the action being done multiple times each frame */
private boolean mouseClickRight = false;
/** Action locker to prevent the action being done multiple times each frame */
private boolean perspectiveLock = false;
/** Only true if the player is in first person and has a line of sight at a block */
private boolean shouldRenderAABB = false;
/**
* Camera constructor. Sets position and rotation.
*
* @param position
* @param rotation
* @param scale
* @param position Where camera should be at
* @param rotation Where camera should look at
*/
public Camera(Vector3f position, Vector3f rotation) {
this.position = position;
@ -53,102 +82,113 @@ public class Camera {
mouseLocked = true;
}
/**
* Instantiates a camera at [0,0,0] without locking the mouse
*/
public Camera() {
this.position = new Vector3f();
mouseLocked = false;
}
float multiplier = 100;
boolean inventory = false;
boolean mouseClickLeft = false;
boolean mouseClickRight = false;
boolean shouldRenderAABB = false;
/**
* Fly cam
* @param heightOffset
* Attaches to the player
* @param player Player to attach to
*/
public void update(Player player) {
Vector3f position = new Vector3f(player.getPosition());
this.position = position;
this.prevPosition = new Vector3f(position);
this.position.x = Maths.lerp(this.position.x, position.x, 0.1f);
this.position.z = Maths.lerp(this.position.z, position.z, 0.1f);
this.position.y = position.y + player.heightOffset;
int reachDistance = player.reachDistance;
this.prevYaw = yaw;
if(mouseLocked && Main.theWorld != null && Main.thePlayer.tick) {
this.updateVectors();
Vector3f currentPoint = Main.theWorld.raycast(getPosition(), forward, reachDistance, false);
if(currentPoint != null) {
int blockX = (int)(currentPoint.x);
int blockY = (int)(currentPoint.y);
int blockZ = (int)(currentPoint.z);
Vector3f blockPos = new Vector3f(blockX,blockY,blockZ);
if(Keyboard.isKeyDown(Keyboard.KEY_F5)) {
if(!perspectiveLock) {
perspective = !perspective;
perspectiveLock = true;
}
} else {
perspectiveLock = false;
}
if(!perspective) {
Vector3f position = new Vector3f(player.getPosition());
this.position = position;
this.prevPosition = new Vector3f(position);
this.position.x = Maths.lerp(this.position.x, position.x, 0.1f);
this.position.z = Maths.lerp(this.position.z, position.z, 0.1f);
this.position.y = position.y + player.heightOffset;
int reachDistance = player.reachDistance;
this.prevYaw = yaw;
if(mouseLocked && Main.theWorld != null && Main.thePlayer.tick) {
this.updateForwardVector();
if(Mouse.isButtonDown(1)) {
if(!mouseClickRight) {
if(Main.inGameGUI.getSelectedItem() != null) {
Vector3f point = Main.theWorld.raycast(getPosition(), forward, reachDistance, true);
int bx = (int)(point.x);
int by = (int)(point.y);
int bz = (int)(point.z);
Main.theWorld.setBlock(new Vector3f(bx,by,bz), Main.inGameGUI.getSelectedItem());
}
mouseClickRight = true;
}
} else {
mouseClickRight = false;
}
if(Mouse.isButtonDown(0)) {
if(!mouseClickLeft) {
Block block = Main.theWorld.getBlock(blockPos);
if(block != null) {
/*Vector3f v = new Vector3f(picker.getPointRounded());
v.y += 1f;
ItemBlock item = new ItemBlock(block, v);
Main.theWorld.addEntity(item);*/
Vector3f pos = new Vector3f(currentPoint);
if(block.getByteType() == Block.tnt.getType()) {
Main.theWorld.addEntity(new PrimedTNT(pos, new Random().nextInt(10)/10f, 0.1f, new Random().nextInt(10)/10f, true));
Vector3f currentPoint = Main.theWorld.raycast(getPosition(), forward, reachDistance, false);
if(currentPoint != null) {
int blockX = (int)(currentPoint.x);
int blockY = (int)(currentPoint.y);
int blockZ = (int)(currentPoint.z);
Vector3f blockPos = new Vector3f(blockX,blockY,blockZ);
if(Mouse.isButtonDown(1)) {
if(!mouseClickRight) {
if(Main.inGameGUI.getSelectedItem() != null) {
Vector3f point = Main.theWorld.raycast(getPosition(), forward, reachDistance, true);
int bx = (int)(point.x);
int by = (int)(point.y);
int bz = (int)(point.z);
Main.theWorld.setBlock(new Vector3f(bx,by,bz), Main.inGameGUI.getSelectedItem());
}
Main.theWorld.setBlock(blockPos, null);
mouseClickRight = true;
}
mouseClickLeft = true;
} else {
mouseClickRight = false;
}
} else {
mouseClickLeft = false;
}
if(Mouse.isButtonDown(2)) {
Block toBeSelected = Main.theWorld.getBlock(blockPos);
if(toBeSelected != null) {
Main.inGameGUI.setSelectedItem(Item.blockToItem(toBeSelected));
if(Mouse.isButtonDown(0)) {
if(!mouseClickLeft) {
Block block = Main.theWorld.getBlock(blockPos);
if(block != null) {
/*Vector3f v = new Vector3f(picker.getPointRounded());
v.y += 1f;
ItemBlock item = new ItemBlock(block, v);
Main.theWorld.addEntity(item);*/
Vector3f pos = new Vector3f(currentPoint);
if(block.getByteType() == Block.tnt.getType() && Main.theNetwork == null) {
Main.theWorld.addEntity(new PrimedTNT(pos, new Random().nextInt(10)/10f, 0.1f, new Random().nextInt(10)/10f, true));
}
Main.theWorld.setBlock(blockPos, null);
}
mouseClickLeft = true;
}
} else {
mouseClickLeft = false;
}
}
Block thatBlock = Main.theWorld.getBlock(blockPos);
if(thatBlock != null) {
aabb.setPosition(blockPos);
shouldRenderAABB = true;
if(Mouse.isButtonDown(2)) {
Block toBeSelected = Main.theWorld.getBlock(blockPos);
if(toBeSelected != null) {
Main.inGameGUI.setSelectedItem(Item.blockToItem(toBeSelected));
}
}
Block thatBlock = Main.theWorld.getBlock(blockPos);
if(thatBlock != null) {
aabb.setPosition(blockPos);
shouldRenderAABB = true;
} else {
shouldRenderAABB = false;
}
} else {
shouldRenderAABB = false;
}
} else {
shouldRenderAABB = false;
}
}
}
this.move();
this.move(player);
}
private void updateVectors() {
/**
* Updates the {@link #forward} vector for picking blocks
*/
private void updateForwardVector() {
float yaw = (float) Math.toRadians(this.yaw + 90);
float pitch = (float) Math.toRadians(this.pitch);
this.forward.x = FastMath.cos(yaw) * FastMath.cos(pitch);
@ -160,11 +200,25 @@ public class Camera {
forward.z *= -1;
}
/**
* Returns the selected block's bounding box
* @return {@link TargetedAABB}
*/
public TargetedAABB getAABB() {
return aabb;
}
/**
* Is the player in third person or not
* @return {@link Boolean}
*/
public boolean isPerspective() {
return perspective;
}
/**
* Toggles the locking of the mouse
*/
public void toggleMouseLock() {
if(!lockInCam) {
mouseLocked = !mouseLocked;
@ -172,6 +226,10 @@ public class Camera {
}
}
/**
* Sets the {@link #mouseLocked} variable directly (and sets the lock state of mouse)
* @param mouseLocked Should the mouse be locked?
*/
public void setMouseLock(boolean mouseLocked) {
this.mouseLocked = mouseLocked;
if(Mouse.isGrabbed() != mouseLocked) {
@ -179,13 +237,17 @@ public class Camera {
}
}
private void move() {
/**
* Despite the name, it doesn't move, rather it calculates limits and the perspective positions
* @param player Player to check against.
*/
private void move(Player player) {
/*if(Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)) {
toggleMouseLock();
} else {
lockInCam = false;
}*/
if(Mouse.isGrabbed() != mouseLocked) {
Mouse.setGrabbed(mouseLocked);
}
@ -197,15 +259,27 @@ public class Camera {
}else if(pitch > maxVerticalTurn){
pitch = maxVerticalTurn;
}
if(perspective) {
calculateAngleAroundPlayer();
float horizontalDistance = calculateHorizontalDistance();
float verticalDistance = calculateVerticalDistance();
calculateCameraPosition(player, horizontalDistance, verticalDistance);
shouldRenderAABB = false;
}
yaw += Mouse.getDX() * GameSettings.sensitivity;
} else {
shouldRenderAABB = false;
}
}
/**
* Moves camera based on given values.
* @param dx
* @param dy
* @param dz
* @param dx Distance X to move by
* @param dy Distance Y to move by
* @param dz Distance Z to move by
*/
public void increasePosition(float dx, float dy, float dz) {
this.position.x += dx;
@ -214,9 +288,9 @@ public class Camera {
}
/**
* Rotates the camera based on given values.
* @param dx
* @param dy
* @param dz
* @param dx Rotational X to move by
* @param dy Rotational Y to move by
* @param dz Rotational Z to move by
*/
public void increaseRotation(float dx, float dy, float dz) {
this.pitch += dx;
@ -225,9 +299,9 @@ public class Camera {
}
/**
* Sets the rotation of the camera based on given values.
* @param dx
* @param dy
* @param dz
* @param dx Rotational X to set to
* @param dy Rotational Y to set to
* @param dz Rotational Z to set to
*/
public void setRotation(float dx, float dy, float dz) {
this.pitch = dx;
@ -235,45 +309,121 @@ public class Camera {
this.roll = dz;
}
/**
* If camera is looking at a valid block, this returns true (allows rendering of the outline)
* @return {@link Boolean}
*/
public boolean shouldRenderAABB() {
return shouldRenderAABB;
}
/**
* Sets position to given 3D Vector
* @param vector
* @param v Vector to set position to
*/
public void setPosition(Vector3f v) {
this.position = v;
}
/**
* Returns camera position
* @return {@link Vector3f}
*/
public Vector3f getPosition() {
return position;
}
/**
* Returns camera's look rotation
* @return {@link Vector3f}
*/
public Vector3f getRotation() {
return new Vector3f(pitch,yaw,roll);
}
/**
* Returns the {@link #pitch} of the camera
* @return {@link Float}
*/
public float getPitch() {
return pitch;
}
/**
* Returns the {@link #yaw} of the camera
* @return {@link Float}
*/
public float getYaw() {
return yaw;
}
/**
* Returns the {@link #roll} of the camera
* @return {@link Float}
*/
public float getRoll() {
return roll;
}
/**
* Locked in window or not
* @return {@link Boolean}
*/
public boolean isLocked() {
return mouseLocked;
}
/**
* Calculates the third person position of the camera from the player
* @param player Player to rotate around
* @param horizontalDistance Given from {@link #calculateHorizontalDistance()}
* @param verticalDistance Given from {@link #calculateVerticalDistance()}
*/
private void calculateCameraPosition(Player player, float horizontalDistance, float verticalDistance){
float offsetX = (float) (horizontalDistance * Math.sin(Math.toRadians(angleAroundPlayer)));
float offsetZ = (float) (horizontalDistance * Math.cos(Math.toRadians(angleAroundPlayer)));
position.x = Maths.lerp(position.x, player.getPosition().x - offsetX, 20f * DisplayManager.getFrameTimeSeconds());
position.z = Maths.lerp(position.z, player.getPosition().z - offsetZ, 20f * DisplayManager.getFrameTimeSeconds());
position.y = Maths.lerp(position.y, player.getPosition().y + verticalDistance + player.heightOffset, 20f * DisplayManager.getFrameTimeSeconds());
this.yaw = 180 - angleAroundPlayer;
}
/**
* Returns the vertical {@link #distanceFromPlayer} using trigonometry (AAAH)
* @return {@link Float}
*/
private float calculateVerticalDistance(){
return (float) (distanceFromPlayer * Math.sin(Math.toRadians(pitch+2)));
}
/**
* Returns the horizontal {@link #distanceFromPlayer} using trigonometry (AAAH)
* @return {@link Float}
*/
private float calculateHorizontalDistance(){
return (float) (distanceFromPlayer * Math.cos(Math.toRadians(pitch+2)));
}
/**
* Calculates X Rotation around the player
*/
private void calculateAngleAroundPlayer() {
float angleChange = Mouse.getDX() * GameSettings.sensitivity;
angleAroundPlayer -= angleChange;
}
/**
* Easy bounding box class to render the block outline
* @author Oikmo
*/
public static class TargetedAABB {
/** Actual bounding box */
private AABB aabb;
/** Position of bounding box */
private Vector3f position;
/**
* Calculates the bounding box from given position (has a size of 1)
* @param position Position to calculate from
*/
public TargetedAABB(Vector3f position) {
this.position = position;
float x = this.position.x;
@ -282,6 +432,10 @@ public class Camera {
this.aabb = new AABB(x, y, z, x + 1f, y + 1f, z + 1f);
}
/**
* Sets the position and calculates the bounding box from given position
* @param position Position to set to and calculate from
*/
public void setPosition(Vector3f position) {
this.position = position;
float x = this.position.x;
@ -289,11 +443,19 @@ public class Camera {
float z = this.position.z;
this.aabb = new AABB(x, y, z, x + 1f, y + 1f, z + 1f);
}
/**
* Returns the bounding box
* @return {@link AABB}
*/
public AABB getAABB() {
return aabb;
}
/**
* Returns the position
* @return {@link Vector3f}
*/
public Vector3f getPosition() {
return position;
}

View file

@ -8,11 +8,15 @@ import com.mojang.minecraft.phys.AABB;
import net.oikmo.engine.models.RawModel;
import net.oikmo.engine.models.TexturedModel;
import net.oikmo.engine.nbt.NBTTagCompound;
import net.oikmo.engine.nbt.NBTTagFloat;
import net.oikmo.engine.nbt.NBTTagList;
import net.oikmo.engine.network.packet.PacketPlaySoundAt;
import net.oikmo.engine.sound.SoundMaster;
import net.oikmo.engine.world.blocks.Block;
import net.oikmo.engine.world.chunk.MasterChunk;
import net.oikmo.engine.world.chunk.coordinate.ChunkCoordinates;
import net.oikmo.main.Main;
import net.oikmo.network.shared.PacketPlaySoundAt;
import net.oikmo.toolbox.FastMath;
import net.oikmo.toolbox.Maths;
@ -33,9 +37,9 @@ public class Entity {
protected float heightOffset = 0.0F;
protected float bbWidth = 0.6F;
protected float bbHeight = 1.8F;
protected boolean remove = false;
public Entity(TexturedModel model, Vector3f position, Vector3f rotation, float scale) {
this.model = model;
this.position = position;
@ -44,7 +48,7 @@ public class Entity {
this.scale = scale;
setPos(position.x, position.y, position.z);
}
public Entity(Vector3f position, Vector3f rotation, float scale) {
this.position = position;
this.motion = new Vector3f();
@ -84,29 +88,32 @@ public class Entity {
double prevX = position.x;
double prevZ = position.z;
moveWithoutSound(xa,ya,za, size);
double offsetX = position.x - prevX;
double offsetZ = position.z - prevZ;
distanceWalkedModified += (double)FastMath.sqrt((float) (offsetX * offsetX + offsetZ * offsetZ)) * 0.7D;
int posX = (int)(position.x);
int posX = (int)(position.x-0.5f);
int posY = (int)(position.y)-1;
int posZ = (int)(position.z);
Block block = Main.theWorld.getBlock(new Vector3f(posX,posY,posZ));
if(distanceWalkedModified > (float)nextStepDistance && block != null) {
nextStepDistance++;
SoundMaster.playBlockPlaceSFX(block, posX, posY, posZ);
if(Main.theNetwork != null) {
PacketPlaySoundAt packet = new PacketPlaySoundAt();
packet.place = true;
packet.blockID = block.getByteType();
packet.x = posX;
packet.y = posY;
packet.z = posZ;
Main.theNetwork.client.sendTCP(packet);
int posZ = (int)(position.z-0.5f);
if(Main.theWorld != null) {
Block block = Main.theWorld.getBlock(new Vector3f(posX,posY,posZ));
if(distanceWalkedModified > (float)nextStepDistance && block != null) {
nextStepDistance++;
SoundMaster.playBlockPlaceSFX(block, posX, posY, posZ);
if(Main.theNetwork != null) {
PacketPlaySoundAt packet = new PacketPlaySoundAt();
packet.place = true;
packet.blockID = block.getByteType();
packet.x = posX;
packet.y = posY;
packet.z = posZ;
Main.theNetwork.client.sendTCP(packet);
}
}
}
}
public void moveWithoutSound(float xa, float ya, float za, int size) {
float xaOrg = xa;
float yaOrg = ya;
@ -114,7 +121,7 @@ public class Entity {
if(Main.theWorld != null) {
List<AABB> aabbs = Main.theWorld.getSurroundingAABBsPhys(this.aabb, size);
int i;
for(i = 0; i < aabbs.size(); ++i) {
ya = aabbs.get(i).clipYCollide(this.aabb, ya);
@ -146,7 +153,7 @@ public class Entity {
this.motion.z = 0.0F;
}
}
if(this instanceof Player) {
this.position.x = ((this.aabb.minX + this.aabb.maxX) / 2.0F);
this.position.y = this.aabb.minY + this.heightOffset;
@ -156,13 +163,33 @@ public class Entity {
this.position.y = this.aabb.minY + this.heightOffset;
this.position.z = ((this.aabb.minZ + this.aabb.maxZ) / 2.0F)-0.5f;
}
updateFallState(ya, onGround);
}
protected void fall(float distance) {}
protected void updateFallState(double d, boolean flag) {
if(flag) {
if(fallDistance > 0.0F) {
fall(fallDistance);
fallDistance = 0.0F;
}
} else {
if(d < 0.0D) {
fallDistance -= d;
}
}
}
public float getBrightness() {
int x = (int)this.position.x;
int y = (int)(this.position.y + this.heightOffset / 2.0F);
int z = (int)this.position.z;
return Main.theWorld.getChunkFromPosition(getCurrentChunkPosition()).getChunk().getBrightness(x, y, z);
if(Main.theWorld.getChunkFromPosition(getCurrentChunkPosition()) != null) {
return Main.theWorld.getChunkFromPosition(getCurrentChunkPosition()).getChunk().getBrightness(x, y, z);
}
return 1;
}
/**
@ -196,6 +223,53 @@ public class Entity {
}
}
public void writeToNBT(NBTTagCompound base) {
base.setTag("Position", newFloatNBTList(new float[] {
position.x, position.y, position.z
}));
base.setTag("Motion", newFloatNBTList(new float[] {
motion.x, motion.y, motion.z
}));
base.setFloat("FallDistance", fallDistance);
//nbttagcompound.setShort("Fire", (short)fire);
//nbttagcompound.setShort("Air", (short)air);
base.setBoolean("OnGround", onGround);
writeEntityToNBT(base);
}
public void readFromNBT(NBTTagCompound base) {
NBTTagList positionNBT = base.getTagList("Position");
NBTTagList motionNBT = base.getTagList("Motion");
motion.x = ((NBTTagFloat)motionNBT.tagAt(0)).value;
motion.y = ((NBTTagFloat)motionNBT.tagAt(1)).value;
motion.z = ((NBTTagFloat)motionNBT.tagAt(2)).value;
float posX = ((NBTTagFloat)positionNBT.tagAt(0)).value;
float posY = ((NBTTagFloat)positionNBT.tagAt(1)).value;
float posZ = ((NBTTagFloat)positionNBT.tagAt(2)).value;
fallDistance = base.getFloat("FallDistance");
//fire = nbttagcompound.getShort("Fire");
//air = nbttagcompound.getShort("Air");
onGround = base.getBoolean("OnGround");
setPos(posX, posY, posZ);
readEntityFromNBT(base);
}
protected void readEntityFromNBT(NBTTagCompound nbttagcompound) {}
protected void writeEntityToNBT(NBTTagCompound nbttagcompound) {}
protected NBTTagList newFloatNBTList(float af[]) {
NBTTagList nbttaglist = new NBTTagList();
float af1[] = af;
int i = af1.length;
for(int j = 0; j < i; j++) {
float f = af1[j];
nbttaglist.setTag(new NBTTagFloat(f));
}
return nbttaglist;
}
public void setRawModel(RawModel model) {
this.model.setRawModel(model);
}
@ -261,9 +335,8 @@ public class Entity {
return scale;
}
public Vector3f getCurrentChunkPosition() {
getCurrentChunk();
return chunkPos;
public ChunkCoordinates getCurrentChunkPosition() {
return Maths.calculateChunkPosition(position);
}
public void resetMotion() {
@ -277,19 +350,17 @@ public class Entity {
Maths.roundVector(getPosition(), roundPos);
return roundPos;
}
public boolean shouldBeRemoved() {
return remove;
}
public MasterChunk getCurrentChunk() {
if(chunkPos == null) { chunkPos = new Vector3f(); }
Maths.calculateChunkPosition(getPosition(), chunkPos);
ChunkCoordinates chunkPos = Maths.calculateChunkPosition(position);
if(Main.theWorld != null) {
synchronized(Main.theWorld.chunkMap) {
synchronized(Main.theWorld.usedPositions) {
return Main.theWorld.getChunkFromPosition(chunkPos);
}
return Main.theWorld.getChunkFromPosition(chunkPos);
}
}
return null;

View file

@ -4,10 +4,12 @@ import org.lwjgl.input.Keyboard;
import org.lwjgl.util.vector.Vector3f;
import net.oikmo.engine.inventory.Container;
import net.oikmo.engine.models.CubeModel;
import net.oikmo.engine.models.PlayerModel;
import net.oikmo.engine.models.TexturedModel;
import net.oikmo.engine.textures.ModelTexture;
import net.oikmo.engine.world.blocks.Block;
import net.oikmo.engine.nbt.NBTTagCompound;
import net.oikmo.engine.nbt.NBTTagFloat;
import net.oikmo.engine.nbt.NBTTagList;
import net.oikmo.engine.renderers.MasterRenderer;
import net.oikmo.engine.world.chunk.MasterChunk;
import net.oikmo.main.Main;
import net.oikmo.main.gui.GuiChat;
@ -15,13 +17,15 @@ import net.oikmo.main.gui.GuiChat;
public class Player extends Entity {
public boolean tick = true;
private Vector3f modelPosition = new Vector3f();
private Vector3f modelRotation = new Vector3f();
private Camera camera;
private Container inventory;
public int reachDistance = 5;
public Player(Vector3f position, Vector3f rotation) {
super(new TexturedModel(CubeModel.getRawModel(Block.obsidian), ModelTexture.create("textures/transparent")), position, rotation,1f);
super(new TexturedModel(PlayerModel.getRawModel(), MasterRenderer.invisibleTexture), position, rotation,1f);
resetPos();
this.heightOffset = 0.81f;
this.camera = new Camera(position, rotation);
@ -29,7 +33,14 @@ public class Player extends Entity {
}
public void tick() {
if(!tick) {return;}
if(!tick) { return; }
if(camera.isPerspective() && this.getModel().getTexture().getTextureID() != Main.playerSkin) {
this.getModel().getTexture().setTextureID(Main.playerSkin);
} else if(!camera.isPerspective() && this.getModel().getTexture().getTextureID() != MasterRenderer.invisibleTexture) {
this.getModel().getTexture().setTextureID(MasterRenderer.invisibleTexture);
}
float xa = 0.0F;
float za = 0.0F;
@ -56,12 +67,24 @@ public class Player extends Entity {
}
this.setRotation(0.0f, camera.yaw, 0.0f);
this.setRotation(0f, camera.yaw, 0f);
if(camera.isPerspective()) {
this.setRotation(0f, camera.yaw-180, 0f);
modelRotation.x = 0;
modelRotation.y = -camera.getYaw()+90;
modelRotation.z = -camera.getPitch();
modelPosition.x = getPosition().x;
modelPosition.y = getPosition().y+heightOffset;
modelPosition.z = getPosition().z;
xa = -xa;
}
this.moveRelative(xa, za, this.isOnGround() ? 0.015F : 0.005F);
this.motion.y = (float)((double)this.motion.y - 0.008D);
this.move(this.motion.x, this.motion.y, this.motion.z);
if(this.getPosition().y < 0 && Main.theNetwork == null) {
resetPos();
if(this.getPosition().y < 0) {
//resetPos();
}
this.motion.x *= 0.91F;
@ -73,6 +96,27 @@ public class Player extends Entity {
}
}
protected void writeEntityToNBT(NBTTagCompound base) {
base.setTag("Camera", newFloatNBTList(new float[] {
camera.getPitch(), camera.getYaw()
}));
}
protected void readEntityFromNBT(NBTTagCompound base) {
NBTTagList cameraNBT = base.getTagList("Camera");
float crx = ((NBTTagFloat)cameraNBT.tagAt(0)).value;
float cry = ((NBTTagFloat)cameraNBT.tagAt(1)).value;
camera.setRotation(crx, cry, 0);
}
public Vector3f getModelPosition() {
return modelPosition;
}
public Vector3f getModelRotation() {
return modelRotation;
}
public Container getInventory() {
return inventory;
}
@ -85,9 +129,8 @@ public class Player extends Entity {
public void resetPos() {
MasterChunk currentChunk = getCurrentChunk();
if(currentChunk != null) {
this.setPos(getPosition().x, currentChunk.getChunk().getHeightFromPosition(currentChunk.getOrigin(), getPosition()), getPosition().z);
this.setPos(1, currentChunk.getChunk().getHeightFromPosition(getPosition()), 1);
}
}
public Camera getCamera() {
@ -97,4 +140,6 @@ public class Player extends Entity {
public void setInventory(Container cont) {
this.inventory = cont;
}
}
}

View file

@ -4,11 +4,11 @@ import org.lwjgl.util.vector.Vector3f;
import net.oikmo.engine.models.CubeModel;
import net.oikmo.engine.models.TexturedModel;
import net.oikmo.engine.network.packet.PacketPlaySoundAt;
import net.oikmo.engine.renderers.MasterRenderer;
import net.oikmo.engine.sound.SoundMaster;
import net.oikmo.engine.world.blocks.Block;
import net.oikmo.main.Main;
import net.oikmo.network.shared.PacketPlaySoundAt;
public class PrimedTNT extends Entity {
@ -57,6 +57,10 @@ public class PrimedTNT extends Entity {
this.setWhiteOffset(0);
}
if(getPosition().y < 0) {
remove = true;
}
if(timer >= 60*5 && !remove) {
if(actuallyExplode) {
Main.theWorld.createRadiusFromBlock(5, null, x, y, z);

View file

@ -0,0 +1,5 @@
/**
* All entities you can think of!
* @author Oikmo
*/
package net.oikmo.engine.entity;

View file

@ -3,12 +3,23 @@ package net.oikmo.engine.gui;
import net.oikmo.main.Main;
import net.oikmo.main.gui.GuiChat;
/**
* Those messages you get that disappear after a bit in chat
* @author Oikmo
*/
public class ChatMessage {
/** How long the message should last... (in ticks) */
private int timer = 60*6;
/** What the message is */
private String message;
/** Yellow text! */
private boolean special;
/**
* Adds itself to {@link net.oikmo.engine.network.client.NetworkHandler#currentlyShownMessages}
* @param message The message itself
* @param special Yellow text or nah
*/
public ChatMessage(String message, boolean special) {
this.message = message;
this.special = special;
@ -18,6 +29,9 @@ public class ChatMessage {
}
}
/**
* Every tick it counts down (decrements {@link #timer}) and removes itself from
*/
public void tick() {
timer--;
if(timer <= 0) {
@ -25,10 +39,18 @@ public class ChatMessage {
}
}
/**
* Returns the message string
* @return {@link String}
*/
public String getMessage() {
return message;
}
/**
* Returns true if it is yellow text
* @return {@link Boolean}
*/
public boolean isSpecial() {
return special;
}

View file

@ -35,7 +35,7 @@ public class Gui {
protected static UnicodeFont font;
private static Font awtFont = null;
protected static int fontSize = 18;
protected static int fontSize = 16;
protected static Cursor cursor;
@ -68,12 +68,14 @@ public class Gui {
GL11.glOrtho(0,Display.getWidth(), Display.getHeight(), 0, -1, 1);
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glLoadIdentity();
GL11.glDisable(GL11.GL_CULL_FACE);
GL11.glEnable(GL11.GL_BLEND);
GL11.glDisable(GL11.GL_DEPTH_TEST);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
}
private void dropGL() {
GL11.glEnable(GL11.GL_CULL_FACE);
GL11.glDisable(GL11.GL_BLEND);
GL11.glEnable(GL11.GL_DEPTH_TEST);
}
@ -191,6 +193,7 @@ public class Gui {
}
protected void drawImage(Image image, float x, float y, float width, float height) {
if(image == null) { return; }
setupGL();
image.draw(x-width/2, y-height/2, width, height);
dropGL();

View file

@ -9,18 +9,34 @@ import net.oikmo.engine.inventory.Item;
import net.oikmo.engine.sound.SoundMaster;
import net.oikmo.main.Main;
/**
* The block item that shows in the creative menu
* @author Oikmo
*/
public class BlockSlot extends Gui implements GuiComponent {
/** Actively hovering slot */
public static BlockSlot currentlyHoveringSlot;
/** True if any instance of the slot is being selected */
private static boolean lockedRightNow = false;
/** If the mouse is hovering over the slot */
private boolean isHovering;
/** What item does it hold */
private Item item;
/** Dimensions of the slot */
private float x, y, width=32, height=32;
/** To prevent action being repeated in multiple frames at once */
private boolean lockButton = false;
/**
* BlockSlot constructor
* @param item Item to store in slot
* @param x X coordinate of where slot should be
* @param y Y coordinate of where slot should be
*/
public BlockSlot(Item item, float x, float y) {
this.item = item;
this.x = x;
@ -64,11 +80,20 @@ public class BlockSlot extends Gui implements GuiComponent {
drawImage(item.getImage(), x, y, width, height);
}
/**
* Sets the position of the slot
* @param x X position to be set to
* @param y Y position to be set to
*/
public void setPosition(int x, int y) {
this.x = x;
this.y = y;
}
/**
* Returns the stored item
* @return {@link Item}
*/
public Item getItem() {
return item;
}
@ -76,5 +101,9 @@ public class BlockSlot extends Gui implements GuiComponent {
@Override
public void onCleanUp() {}
/** Drops the active static instance */
public static void dropCurrent() {
currentlyHoveringSlot = null;
lockedRightNow = false;
}
}

View file

@ -2,11 +2,18 @@ package net.oikmo.engine.gui.component.slick;
import java.util.ArrayList;
/**
* Interface for Gui components
* @author Oikmo
*/
public interface GuiComponent {
/** All actively loaded (and rendered) components */
public static ArrayList<GuiComponent> components = new ArrayList<>();
/** Remove textures and what not */
public abstract void onCleanUp();
/** Called when display is resized */
public abstract void updateComponent();
/** Logic function */
public abstract void tick();
}

View file

@ -29,9 +29,9 @@ import org.newdawn.slick.opengl.TextureLoader;
import net.oikmo.engine.ResourceLoader;
import net.oikmo.engine.gui.Gui;
import net.oikmo.engine.gui.component.slick.button.GuiButton;
import net.oikmo.engine.network.Server;
import net.oikmo.engine.sound.SoundMaster;
import net.oikmo.main.gui.GuiServerList;
import net.oikmo.network.client.Server;
import net.oikmo.toolbox.Maths;
public class GuiServer extends Gui implements GuiComponent {
@ -191,7 +191,7 @@ public class GuiServer extends Gui implements GuiComponent {
public void tick(boolean delete, boolean shouldTicky) {
if(useImage) {
if(imageFile.exists() && imageFile.length() != 0) {
if(imageFile != null && imageFile.exists() && imageFile.length() != 0) {
try {
image = TextureLoader.getTexture("PNG", new FileInputStream(imageFile), Image.FILTER_NEAREST);
} catch (Exception e) {

View file

@ -56,8 +56,17 @@ public class GuiTextField extends Gui implements GuiComponent {
components.add(this);
}
private int ticks;
private boolean showMarker = true;
@Override
public void tick() {
ticks++;
if(ticks > 30) {
showMarker = !showMarker;
ticks = 0;
}
float mouseX = Mouse.getX();
float mouseY = Math.abs(Display.getHeight()-Mouse.getY());
@ -96,6 +105,9 @@ public class GuiTextField extends Gui implements GuiComponent {
if(grabbed) {
handleKeyboardInput();
} else {
ticks = 0;
showMarker = false;
}
drawTexture(backgroundTexture, x, y, width, height);
@ -103,7 +115,11 @@ public class GuiTextField extends Gui implements GuiComponent {
if(inputText.length() == 0 && current != this) {
drawShadowString(Color.darkGray, (x+3)-width/2, y-fontSize/2, backgroundText);
} else {
drawShadowString((x+3)-width/2, y-fontSize/2, inputText);
String text = getInputText();
if(text.length() > 17) {
text = text.substring(text.length()-17, text.length());
}
drawShadowString((x+3)-width/2, y-fontSize/2, text + (showMarker ? "_" : ""));
}
}
@ -121,7 +137,7 @@ public class GuiTextField extends Gui implements GuiComponent {
protected void keyTyped(char c, int i) {
if(isValidCharacter(c)) {
if(x+width > x+font.getWidth(getInputText() + c)) {
if(getInputText().length() < 255) {
setInputText(getInputText() + c);
}
}

View file

@ -17,16 +17,18 @@ public class CubeModel {
public static float[] vertices;
static Vector2f[][] UVS;
static Vector3f[][] VERTS;
private static Vector2f[][] UVS;
private static Vector3f[][] VERTS;
private static Map<Block, RawModel> models = new HashMap<>();
public static Vector3f[] PX_POS = {
new Vector3f(1f,1f,0f),
new Vector3f(1f,0f,1f),
new Vector3f(1f,0f,0f),
new Vector3f(1f,0f,1f),
new Vector3f(1f,0f,1f),
new Vector3f(1f,1f,0f),
new Vector3f(1f,1f,0f),
new Vector3f(1f,1f,1f),
new Vector3f(1f,1f,0f)
new Vector3f(1f,0f,1f),
};
public static Vector3f[] NX_POS = {
new Vector3f(0f,1f,0f),
@ -38,11 +40,11 @@ public class CubeModel {
};
public static Vector3f[] PY_POS = {
new Vector3f(0f,1f,1f),
new Vector3f(0f,1f,0f),
new Vector3f(1f,1f,0f),
new Vector3f(1f,1f,0f),
new Vector3f(1f,1f,1f),
new Vector3f(0f,1f,1f)
new Vector3f(1f,1f,0f),
new Vector3f(1f,1f,0f),
new Vector3f(0f,1f,0f),
new Vector3f(0f,1f,1f),
};
public static Vector3f[] NY_POS = {
new Vector3f(0f,0f,1f),
@ -62,11 +64,11 @@ public class CubeModel {
};
public static Vector3f[] NZ_POS = {
new Vector3f(0f,1f,0f),
new Vector3f(0f,0f,0f),
new Vector3f(1f,0f,0f),
new Vector3f(1f,0f,0f),
new Vector3f(1f,1f,0f),
new Vector3f(0f,1f,0f)
new Vector3f(1f,0f,0f),
new Vector3f(1f,0f,0f),
new Vector3f(0f,0f,0f),
new Vector3f(0f,1f,0f),
};
public static Vector2f[] UV_PX;
@ -132,25 +134,24 @@ public class CubeModel {
public static Vector2f[] setupUVPX() {
Vector2f[] uvArray = new Vector2f[blockCount * texturesPerBlock];
addTextureFromXY(uvArray, Block.grass.getType(), 1, 0);
addTextureFromXY(uvArray, Block.dirt.getType(), 2, 0);
addTextureFromXY(uvArray, Block.stone.getType(), 3, 0);
addTextureFromXY(uvArray, Block.bedrock.getType(), 4, 0);
addTextureFromXY(uvArray, Block.cobble.getType(), 5, 0);
addTextureFromXY(uvArray, Block.mossycobble.getType(), 6, 0);
addTextureFromXY(uvArray, Block.obsidian.getType(), 7, 0);
addTextureFromXY(uvArray, Block.oakleaf.getType(), 0, 2);
addTextureFromXY(uvArray, Block.oaklog.getType(), 1, 2);
addTextureFromXY(uvArray, Block.oakplanks.getType(), 3, 2);
addTextureFromXY(uvArray, Block.glass.getType(), 0, 3);
addTextureFromXY(uvArray, Block.smoothstone.getType(), 1, 3);
addTextureFromXY(uvArray, Block.brick.getType(), 3, 3);
addTextureFromXY(uvArray, Block.ironBlock.getType(), 14, 0);
addTextureFromXY(uvArray, Block.goldBlock.getType(), 14, 1);
addTextureFromXY(uvArray, Block.diamondBlock.getType(), 14, 2);
addTextureFromXY(uvArray, Block.tnt.getType(), 0, 4);
addTextureFromXY(uvArray, Block.obsidianPlayer.getType(), 7, 0);
boolean flip = false;
addTextureFromXYWeird(uvArray, Block.grass.getType(), 1, 0, flip);
addTextureFromXYWeird(uvArray, Block.dirt.getType(), 2, 0, flip);
addTextureFromXYWeird(uvArray, Block.stone.getType(), 3, 0, flip);
addTextureFromXYWeird(uvArray, Block.bedrock.getType(), 4, 0, flip);
addTextureFromXYWeird(uvArray, Block.cobble.getType(), 5, 0, flip);
addTextureFromXYWeird(uvArray, Block.mossycobble.getType(), 6, 0, flip);
addTextureFromXYWeird(uvArray, Block.obsidian.getType(), 7, 0, flip);
addTextureFromXYWeird(uvArray, Block.oakleaf.getType(), 0, 2, flip);
addTextureFromXYWeird(uvArray, Block.oaklog.getType(), 1, 2, flip);
addTextureFromXYWeird(uvArray, Block.oakplanks.getType(), 3, 2, flip);
addTextureFromXYWeird(uvArray, Block.glass.getType(), 0, 3, flip);
addTextureFromXYWeird(uvArray, Block.smoothstone.getType(), 1, 3, flip);
addTextureFromXYWeird(uvArray, Block.brick.getType(), 3, 3, flip);
addTextureFromXYWeird(uvArray, Block.ironBlock.getType(), 14, 0, flip);
addTextureFromXYWeird(uvArray, Block.goldBlock.getType(), 14, 1, flip);
addTextureFromXYWeird(uvArray, Block.diamondBlock.getType(), 14, 2, flip);
addTextureFromXYWeird(uvArray, Block.tnt.getType(), 0, 4, flip);
return uvArray;
}
@ -174,7 +175,6 @@ public class CubeModel {
addTextureFromXY(uvArray, Block.goldBlock.getType(), 14, 1);
addTextureFromXY(uvArray, Block.diamondBlock.getType(), 14, 2);
addTextureFromXY(uvArray, Block.tnt.getType(), 0, 4);
addTextureFromXY(uvArray, Block.obsidianPlayer.getType(), 0, 15);
return uvArray;
}
@ -197,7 +197,6 @@ public class CubeModel {
addTextureFromXY(uvArray, Block.goldBlock.getType(), 13, 1);
addTextureFromXY(uvArray, Block.diamondBlock.getType(), 13, 2);
addTextureFromXY(uvArray, Block.tnt.getType(), 1, 4);
addTextureFromXY(uvArray, Block.obsidianPlayer.getType(), 7, 0);
return uvArray;
}
@ -220,7 +219,6 @@ public class CubeModel {
addTextureFromXY(uvArray, Block.goldBlock.getType(), 15, 1);
addTextureFromXY(uvArray, Block.diamondBlock.getType(), 15, 2);
addTextureFromXY(uvArray, Block.tnt.getType(), 2, 4);
addTextureFromXY(uvArray, Block.obsidianPlayer.getType(), 7, 0);
return uvArray;
}
@ -244,31 +242,31 @@ public class CubeModel {
addTextureFromXY(uvArray, Block.goldBlock.getType(), 14, 1);
addTextureFromXY(uvArray, Block.diamondBlock.getType(), 14, 2);
addTextureFromXY(uvArray, Block.tnt.getType(), 0, 4);
addTextureFromXY(uvArray, Block.obsidianPlayer.getType(), 7, 0);
return uvArray;
}
public static Vector2f[] setupUVNZ() {
Vector2f[] uvArray = new Vector2f[blockCount * texturesPerBlock];
addTextureFromXY(uvArray, Block.grass.getType(), 1, 0);
addTextureFromXY(uvArray, Block.dirt.getType(), 2, 0);
addTextureFromXY(uvArray, Block.stone.getType(), 3, 0);
addTextureFromXY(uvArray, Block.bedrock.getType(), 4, 0);
addTextureFromXY(uvArray, Block.cobble.getType(), 5, 0);
addTextureFromXY(uvArray, Block.mossycobble.getType(), 6, 0);
addTextureFromXY(uvArray, Block.obsidian.getType(), 7, 0);
addTextureFromXY(uvArray, Block.oakleaf.getType(), 0, 2);
addTextureFromXY(uvArray, Block.oaklog.getType(), 1, 2);
addTextureFromXY(uvArray, Block.oakplanks.getType(), 3, 2);
addTextureFromXY(uvArray, Block.glass.getType(), 0, 3);
addTextureFromXY(uvArray, Block.smoothstone.getType(), 1, 3);
addTextureFromXY(uvArray, Block.brick.getType(), 3, 3);
addTextureFromXY(uvArray, Block.ironBlock.getType(), 14, 0);
addTextureFromXY(uvArray, Block.goldBlock.getType(), 14, 1);
addTextureFromXY(uvArray, Block.diamondBlock.getType(), 14, 2);
addTextureFromXY(uvArray, Block.tnt.getType(), 0, 4);
addTextureFromXY(uvArray, Block.obsidianPlayer.getType(), 7, 0);
boolean flip = true;
addTextureFromXY(uvArray, Block.grass.getType(), 1, 0, flip);
addTextureFromXY(uvArray, Block.dirt.getType(), 2, 0, flip);
addTextureFromXY(uvArray, Block.stone.getType(), 3, 0, flip);
addTextureFromXY(uvArray, Block.bedrock.getType(), 4, 0, flip);
addTextureFromXY(uvArray, Block.cobble.getType(), 5, 0, flip);
addTextureFromXY(uvArray, Block.mossycobble.getType(), 6, 0, flip);
addTextureFromXY(uvArray, Block.obsidian.getType(), 7, 0, flip);
addTextureFromXY(uvArray, Block.oakleaf.getType(), 0, 2, flip);
addTextureFromXY(uvArray, Block.oaklog.getType(), 1, 2, flip);
addTextureFromXY(uvArray, Block.oakplanks.getType(), 3, 2, flip);
addTextureFromXY(uvArray, Block.glass.getType(), 0, 3, flip);
addTextureFromXY(uvArray, Block.smoothstone.getType(), 1, 3, flip);
addTextureFromXY(uvArray, Block.brick.getType(), 3, 3, flip);
addTextureFromXY(uvArray, Block.ironBlock.getType(), 14, 0, flip);
addTextureFromXY(uvArray, Block.goldBlock.getType(), 14, 1, flip);
addTextureFromXY(uvArray, Block.diamondBlock.getType(), 14, 2, flip);
addTextureFromXY(uvArray, Block.tnt.getType(), 0, 4, flip);
return uvArray;
}
@ -309,22 +307,60 @@ public class CubeModel {
}
}
public static int addTextureFromXY(Vector2f[] uv, int index, int x, int y) {
public static void addTextureFromXY(Vector2f[] uv, int index, int x, int y) {
addTextureFromXY(uv, index, x, y, false);
}
public static void addTextureFromXYWeird(Vector2f[] uv, int index, int x, int y, boolean flip) {
y = (int) (sizeOfAtlas-y)-1;
float xOffset = (float) x / 16f;
float yOffset = (float) y / 16f;
int privIndex = new Integer(index*6);
System.out.println(privIndex);
uv[privIndex+0] = new Vector2f(xOffset, yOffset);
uv[privIndex+0].y = -uv[privIndex+0].y;
uv[privIndex+1] = new Vector2f((x + 1) / sizeOfAtlas, yOffset);
uv[privIndex+1].y = -uv[privIndex+1].y;
uv[privIndex+2] = new Vector2f((x + 1) / sizeOfAtlas, (y + 1) / sizeOfAtlas);
uv[privIndex+2].y = -uv[privIndex+2].y;
uv[privIndex+3] = new Vector2f((x + 1) / sizeOfAtlas, (y + 1) / sizeOfAtlas);
uv[privIndex+3].y = -uv[privIndex+3].y;
uv[privIndex+4] = new Vector2f(xOffset, (float) (y + 1) / sizeOfAtlas);
uv[privIndex+4].y = -uv[privIndex+4].y;
uv[privIndex+5] = new Vector2f(xOffset, yOffset);
uv[privIndex+5].y = -uv[privIndex+5].y;
}
public static void addTextureFromXY(Vector2f[] uv, int index, int x, int y, boolean flip) {
x = flip ? (int) (sizeOfAtlas-x)-1 : x;
float xOffset = (float) x / 16.f;
float yOffset = (float) y / 16.f;
int privIndex = new Integer(index*6);
uv[privIndex++] = new Vector2f(xOffset, yOffset);
uv[privIndex++] = new Vector2f(xOffset, (float) (y + 1) / sizeOfAtlas);
uv[privIndex++] = new Vector2f((float) (x + 1) / sizeOfAtlas, (float) (y + 1) / sizeOfAtlas);
uv[privIndex++] = new Vector2f((float) (x + 1) / sizeOfAtlas, (float) (y + 1) / sizeOfAtlas);
uv[privIndex++] = new Vector2f((float) (x + 1) / sizeOfAtlas, yOffset);
uv[privIndex++] = new Vector2f(xOffset, yOffset);
return index;
if(!flip) {
uv[privIndex++] = new Vector2f(xOffset, yOffset);
uv[privIndex++] = new Vector2f(xOffset, (float) (y + 1) / sizeOfAtlas);
uv[privIndex++] = new Vector2f((float) (x + 1) / sizeOfAtlas, (float) (y + 1) / sizeOfAtlas);
uv[privIndex++] = new Vector2f((float) (x + 1) / sizeOfAtlas, (float) (y + 1) / sizeOfAtlas);
uv[privIndex++] = new Vector2f((float) (x + 1) / sizeOfAtlas, yOffset);
uv[privIndex++] = new Vector2f(xOffset, yOffset);
} else {
uv[privIndex] = new Vector2f(xOffset, yOffset);
uv[privIndex].x = -uv[privIndex].x;
uv[privIndex+1] = new Vector2f((x + 1) / sizeOfAtlas, yOffset);
uv[privIndex+1].x = -uv[privIndex+1].x;
uv[privIndex+2] = new Vector2f((x + 1) / sizeOfAtlas, (y + 1) / sizeOfAtlas);
uv[privIndex+2].x = -uv[privIndex+2].x;
uv[privIndex+3] = new Vector2f((x + 1) / sizeOfAtlas, (y + 1) / sizeOfAtlas);
uv[privIndex+3].x = -uv[privIndex+3].x;
uv[privIndex+4] = new Vector2f(xOffset, (float) (y + 1) / sizeOfAtlas);
uv[privIndex+4].x = -uv[privIndex+4].x;
uv[privIndex+5] = new Vector2f(xOffset, yOffset);
uv[privIndex+5].x = -uv[privIndex+5].x;
}
}
private static Map<Block, RawModel> models = new HashMap<>();
public static RawModel getRawModel(Block block) {
if(models.get(block) == null) {
models.put(block, Loader.loadToVAO(vertices, getUVs(block.getByteType()), normals));

View file

@ -0,0 +1,278 @@
package net.oikmo.engine.models;
import org.lwjgl.util.vector.Vector2f;
import org.lwjgl.util.vector.Vector3f;
import net.oikmo.engine.Loader;
public class PlayerModel {
private static int texturesPerBlock = 6;
private static float sizeOfAtlas = 4f;
public static float[] vertices;
static Vector2f[][] UVS;
static Vector3f[][] VERTS;
public static Vector3f[] PX_POS = {
new Vector3f(0.5f,-0.5f,0.5f),
new Vector3f(0.5f,-0.5f,-0.5f),
new Vector3f(0.5f,0.5f,-0.5f),
new Vector3f(0.5f,0.5f,-0.5f),
new Vector3f(0.5f,0.5f,0.5f),
new Vector3f(0.5f,-0.5f,0.5f),
};
public static Vector3f[] NX_POS = {
new Vector3f(-0.5f,0.5f,-0.5f),
new Vector3f(-0.5f,-0.5f,-0.5f),
new Vector3f(-0.5f,-0.5f,0.5f),
new Vector3f(-0.5f,-0.5f,0.5f),
new Vector3f(-0.5f,0.5f,0.5f),
new Vector3f(-0.5f,0.5f,-0.5f)
};
public static Vector3f[] PY_POS = {
new Vector3f(-0.5f,0.5f,0.5f),
new Vector3f(0.5f,0.5f,0.5f),
new Vector3f(0.5f,0.5f,-0.5f),
new Vector3f(0.5f,0.5f,-0.5f),
new Vector3f(-0.5f,0.5f,-0.5f),
new Vector3f(-0.5f,0.5f,0.5f),
};
public static Vector3f[] NY_POS = {
new Vector3f(-0.5f,-0.5f,0.5f),
new Vector3f(-0.5f,-0.5f,-0.5f),
new Vector3f(0.5f,-0.5f,-0.5f),
new Vector3f(0.5f,-0.5f,-0.5f),
new Vector3f(0.5f,-0.5f,0.5f),
new Vector3f(-0.5f,-0.5f,0.5f)
};
public static Vector3f[] PZ_POS = {
new Vector3f(-0.5f,0.5f,0.5f),
new Vector3f(-0.5f,-0.5f,0.5f),
new Vector3f(0.5f,-0.5f,0.5f),
new Vector3f(0.5f,-0.5f,0.5f),
new Vector3f(0.5f,0.5f,0.5f),
new Vector3f(-0.5f,0.5f,0.5f)
};
public static Vector3f[] NZ_POS = {
new Vector3f(-0.5f,0.5f,-0.5f),
new Vector3f(0.5f,0.5f,-0.5f),
new Vector3f(0.5f,-0.5f,-0.5f),
new Vector3f(0.5f,-0.5f,-0.5f),
new Vector3f(-0.5f,-0.5f,-0.5f),
new Vector3f(-0.5f,0.5f,-0.5f),
};
public static Vector2f[] UV_PX;
public static Vector2f[] UV_NX;
public static Vector2f[] UV_PY;
public static Vector2f[] UV_NY;
public static Vector2f[] UV_PZ;
public static Vector2f[] UV_NZ;
public static float[] normals = {
0.8f, 0.8f, 0.8f,
0.8f, 0.8f, 0.8f,
0.8f, 0.8f, 0.8f,
0.8f, 0.8f, 0.8f,
0.8f, 0.8f, 0.8f,
0.8f, 0.8f, 0.8f,
0.65f, 0.65f, 0.65f,
0.65f, 0.65f, 0.65f,
0.65f, 0.65f, 0.65f,
0.65f, 0.65f, 0.65f,
0.65f, 0.65f, 0.65f,
0.65f, 0.65f, 0.65f,
1f, 1f, 1f,
1f, 1f, 1f,
1f, 1f, 1f,
1f, 1f, 1f,
1f, 1f, 1f,
1f, 1f, 1f,
1f, 1f, 1f,
1f, 1f, 1f,
1f, 1f, 1f,
1f, 1f, 1f,
1f, 1f, 1f,
1f, 1f, 1f,
0.8f, 0.8f, 0.8f,
0.8f, 0.8f, 0.8f,
0.8f, 0.8f, 0.8f,
0.8f, 0.8f, 0.8f,
0.8f, 0.8f, 0.8f,
0.8f, 0.8f, 0.8f,
0.65f, 0.65f, 0.65f,
0.65f, 0.65f, 0.65f,
0.65f, 0.65f, 0.65f,
0.65f, 0.65f, 0.65f,
0.65f, 0.65f, 0.65f,
0.65f, 0.65f, 0.65f,
};
private static RawModel model;
public static void setup() {
UV_PX = new Vector2f[texturesPerBlock];
UV_NX = new Vector2f[texturesPerBlock];
UV_PY = new Vector2f[texturesPerBlock];
UV_NY = new Vector2f[texturesPerBlock];
UV_PZ = new Vector2f[texturesPerBlock];
UV_NZ = new Vector2f[texturesPerBlock];
addTextureFromXYWeird(UV_PX, 0, 1, false); //back
addTextureFromXY(UV_NX, 2, 1); //front
addTextureFromXYWeird(UV_PY, 2, 0, false); //top
addTextureFromXYWeird(UV_NY, 2, 2, true); //bottom
addTextureFromXY(UV_PZ, 3, 1); //right
addTextureFromXY(UV_NZ, 1, 1, true); //left
/*addTextureFromXY(UV_PX, 0, 1); //back
addTextureFromXY(UV_NX, 2, 1); //front
addTextureFromXY(UV_PY, 2, 0); //top
addTextureFromXY(UV_NY, 2, 2); //bottom
addTextureFromXY(UV_PZ, 3, 1); //right
addTextureFromXY(UV_NZ, 1, 1);*/ //left
createVertices();
//
}
public static RawModel getRawModel() {
if(model == null) {
model = Loader.loadToVAO(vertices, getUVs(), normals);
}
return model;
}
public static float[] getUVs() {
UVS = UVS == null ? new Vector2f[][]{PlayerModel.UV_PX, PlayerModel.UV_NX, PlayerModel.UV_PY, PlayerModel.UV_NY, PlayerModel.UV_PZ, PlayerModel.UV_NZ} : UVS;
int totalLength = UVS.length * 6 * 2; // 5 vectors for each array
float[] result = new float[totalLength];
int index = 0;
int startIndex = 0;
for (Vector2f[] uvArray : UVS) {
for (int i = startIndex; i < startIndex + 6; i++) {
Vector2f uv = uvArray[i];
result[index++] = uv.x;
result[index++] = uv.y;
}
}
return result;
}
public static void createVertices() {
VERTS = VERTS == null ? new Vector3f[][]{PlayerModel.PX_POS, PlayerModel.NX_POS, PlayerModel.PY_POS, PlayerModel.NY_POS, PlayerModel.PZ_POS, PlayerModel.NZ_POS} : VERTS;
int totalLength = VERTS.length * 6 * 3; // 6 vectors for each array
vertices = new float[totalLength];
int index = 0;
for (Vector3f[] uvArray : VERTS) {
for (int i = 0; i < 6; i++) {
Vector3f uv = uvArray[i];
vertices[index++] = uv.x;
vertices[index++] = uv.y;
vertices[index++] = uv.z;
}
}
}
public static void addTextureFromXYReversed(Vector2f[] uv, int x, int y) {
float xOffset = (float) x / 4.f;
float yOffset = (float) y / 4.f;
int privIndex = 0;
uv[privIndex++] = new Vector2f(xOffset, yOffset);
uv[privIndex++] = new Vector2f((float) (x + 1) / sizeOfAtlas, yOffset);
uv[privIndex++] = new Vector2f((float) (x + 1) / sizeOfAtlas, (float) (y + 1) / sizeOfAtlas);
uv[privIndex++] = new Vector2f((float) (x + 1) / sizeOfAtlas, (float) (y + 1) / sizeOfAtlas);
uv[privIndex++] = new Vector2f(xOffset, (float) (y + 1) / sizeOfAtlas);
uv[privIndex++] = new Vector2f(xOffset, yOffset);
}
public static float[] getUVs(int is) {
UVS = UVS == null ? new Vector2f[][]{CubeModel.UV_PX, CubeModel.UV_NX, CubeModel.UV_PY, CubeModel.UV_NY, CubeModel.UV_PZ, CubeModel.UV_NZ} : UVS;
int totalLength = UVS.length * 6 * 2; // 5 vectors for each array
float[] result = new float[totalLength];
int index = 0;
int startIndex = is * 6;
for (Vector2f[] uvArray : UVS) {
for (int i = startIndex; i < startIndex + 6; i++) {
Vector2f uv = uvArray[i];
result[index++] = uv.x;
result[index++] = uv.y;
}
}
return result;
}
public static void addTextureFromXY(Vector2f[] uv, int x, int y) {
addTextureFromXY(uv, x, y, false);
}
public static void addTextureFromXYWeird(Vector2f[] uv, int x, int y, boolean flip) {
y = (int) (sizeOfAtlas-y)-1;
float xOffset = (float) x / 4f;
float yOffset = (float) y / 4f;
int privIndex = new Integer(0);
System.out.println(privIndex);
uv[privIndex+0] = new Vector2f(xOffset, yOffset);
uv[privIndex+0].y = -uv[privIndex+0].y;
uv[privIndex+1] = new Vector2f((x + 1) / sizeOfAtlas, yOffset);
uv[privIndex+1].y = -uv[privIndex+1].y;
uv[privIndex+2] = new Vector2f((x + 1) / sizeOfAtlas, (y + 1) / sizeOfAtlas);
uv[privIndex+2].y = -uv[privIndex+2].y;
uv[privIndex+3] = new Vector2f((x + 1) / sizeOfAtlas, (y + 1) / sizeOfAtlas);
uv[privIndex+3].y = -uv[privIndex+3].y;
uv[privIndex+4] = new Vector2f(xOffset, (float) (y + 1) / sizeOfAtlas);
uv[privIndex+4].y = -uv[privIndex+4].y;
uv[privIndex+5] = new Vector2f(xOffset, yOffset);
uv[privIndex+5].y = -uv[privIndex+5].y;
}
public static void addTextureFromXY(Vector2f[] uv, int x, int y, boolean flip) {
x = flip ? (int) (sizeOfAtlas-x)-1 : x;
float xOffset = (float) x / 4.f;
float yOffset = (float) y / 4.f;
int privIndex = new Integer(0);
if(!flip) {
uv[privIndex++] = new Vector2f(xOffset, yOffset);
uv[privIndex++] = new Vector2f(xOffset, (float) (y + 1) / sizeOfAtlas);
uv[privIndex++] = new Vector2f((float) (x + 1) / sizeOfAtlas, (float) (y + 1) / sizeOfAtlas);
uv[privIndex++] = new Vector2f((float) (x + 1) / sizeOfAtlas, (float) (y + 1) / sizeOfAtlas);
uv[privIndex++] = new Vector2f((float) (x + 1) / sizeOfAtlas, yOffset);
uv[privIndex++] = new Vector2f(xOffset, yOffset);
} else {
uv[privIndex] = new Vector2f(xOffset, yOffset);
uv[privIndex].x = -uv[privIndex].x;
uv[privIndex+1] = new Vector2f((x + 1) / sizeOfAtlas, yOffset);
uv[privIndex+1].x = -uv[privIndex+1].x;
uv[privIndex+2] = new Vector2f((x + 1) / sizeOfAtlas, (y + 1) / sizeOfAtlas);
uv[privIndex+2].x = -uv[privIndex+2].x;
uv[privIndex+3] = new Vector2f((x + 1) / sizeOfAtlas, (y + 1) / sizeOfAtlas);
uv[privIndex+3].x = -uv[privIndex+3].x;
uv[privIndex+4] = new Vector2f(xOffset, (float) (y + 1) / sizeOfAtlas);
uv[privIndex+4].x = -uv[privIndex+4].x;
uv[privIndex+5] = new Vector2f(xOffset, yOffset);
uv[privIndex+5].x = -uv[privIndex+5].x;
}
}
}

View file

@ -11,6 +11,11 @@ public class TexturedModel {
this.model = model;
this.texture = texture;
}
public TexturedModel(RawModel model, int texture) {
this.model = model;
this.texture = new ModelTexture(texture);
}
public RawModel getRawModel() {
return model;

View file

@ -0,0 +1,149 @@
package net.oikmo.engine.nbt;
// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) braces deadcode
import java.io.*;
public abstract class NBTBase
{
public NBTBase()
{
key = null;
}
abstract void writeTagContents(DataOutput dataoutput) throws IOException;
abstract void readTagContents(DataInput datainput) throws IOException;
public abstract byte getType();
public String getKey()
{
if(key == null)
{
return "";
} else
{
return key;
}
}
public NBTBase setKey(String s)
{
key = s;
return this;
}
public static NBTBase readTag(DataInput datainput) throws IOException
{
byte byte0 = datainput.readByte();
if(byte0 == 0)
{
return new NBTTagEnd();
} else
{
NBTBase nbtbase = createTagOfType(byte0);
nbtbase.key = datainput.readUTF();
nbtbase.readTagContents(datainput);
return nbtbase;
}
}
public static void writeTag(NBTBase nbtbase, DataOutput dataoutput) throws IOException
{
dataoutput.writeByte(nbtbase.getType());
if(nbtbase.getType() == 0)
{
return;
} else
{
dataoutput.writeUTF(nbtbase.getKey());
nbtbase.writeTagContents(dataoutput);
return;
}
}
public static NBTBase createTagOfType(byte byte0)
{
switch(byte0)
{
case 0: // '\0'
return new NBTTagEnd();
case 1: // '\001'
return new NBTTagByte();
case 2: // '\002'
return new NBTTagShort();
case 3: // '\003'
return new NBTTagInt();
case 4: // '\004'
return new NBTTagLong();
case 5: // '\005'
return new NBTTagFloat();
case 6: // '\006'
return new NBTTagDouble();
case 7: // '\007'
return new NBTTagByteArray();
case 8: // '\b'
return new NBTTagString();
case 9: // '\t'
return new NBTTagList();
case 10: // '\n'
return new NBTTagCompound();
}
return null;
}
public static String getTagName(byte byte0)
{
switch(byte0)
{
case 0: // '\0'
return "TAG_End";
case 1: // '\001'
return "TAG_Byte";
case 2: // '\002'
return "TAG_Short";
case 3: // '\003'
return "TAG_Int";
case 4: // '\004'
return "TAG_Long";
case 5: // '\005'
return "TAG_Float";
case 6: // '\006'
return "TAG_Double";
case 7: // '\007'
return "TAG_Byte_Array";
case 8: // '\b'
return "TAG_String";
case 9: // '\t'
return "TAG_List";
case 10: // '\n'
return "TAG_Compound";
}
return "UNKNOWN";
}
private String key;
}

View file

@ -0,0 +1,41 @@
package net.oikmo.engine.nbt;
// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) braces deadcode
import java.io.*;
public class NBTTagByte extends NBTBase
{
public NBTTagByte()
{
}
public NBTTagByte(byte byte0)
{
byteValue = byte0;
}
void writeTagContents(DataOutput dataoutput) throws IOException
{
dataoutput.writeByte(byteValue);
}
void readTagContents(DataInput datainput) throws IOException
{
byteValue = datainput.readByte();
}
public byte getType()
{
return 1;
}
public String toString()
{
return (new StringBuilder()).append("").append(byteValue).toString();
}
public byte byteValue;
}

View file

@ -0,0 +1,44 @@
package net.oikmo.engine.nbt;
// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) braces deadcode
import java.io.*;
public class NBTTagByteArray extends NBTBase
{
public NBTTagByteArray()
{
}
public NBTTagByteArray(byte abyte0[])
{
byteArray = abyte0;
}
void writeTagContents(DataOutput dataoutput) throws IOException
{
dataoutput.writeInt(byteArray.length);
dataoutput.write(byteArray);
}
void readTagContents(DataInput datainput) throws IOException
{
int i = datainput.readInt();
byteArray = new byte[i];
datainput.readFully(byteArray);
}
public byte getType()
{
return 7;
}
public String toString()
{
return (new StringBuilder()).append("[").append(byteArray.length).append(" bytes]").toString();
}
public byte byteArray[];
}

View file

@ -0,0 +1,221 @@
package net.oikmo.engine.nbt;
// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) braces deadcode
import java.io.*;
import java.util.*;
public class NBTTagCompound extends NBTBase
{
public NBTTagCompound()
{
tagMap = new HashMap<String, NBTBase>();
}
void writeTagContents(DataOutput dataoutput) throws IOException
{
NBTBase nbtbase;
for(Iterator<NBTBase> iterator = tagMap.values().iterator(); iterator.hasNext(); NBTBase.writeTag(nbtbase, dataoutput))
{
nbtbase = (NBTBase)iterator.next();
}
dataoutput.writeByte(0);
}
void readTagContents(DataInput datainput) throws IOException
{
tagMap.clear();
NBTBase nbtbase;
for(; (nbtbase = NBTBase.readTag(datainput)).getType() != 0; tagMap.put(nbtbase.getKey(), nbtbase)) { }
}
public byte getType()
{
return 10;
}
public void setTag(String s, NBTBase nbtbase)
{
tagMap.put(s, nbtbase.setKey(s));
}
public void setByte(String s, byte byte0)
{
tagMap.put(s, (new NBTTagByte(byte0)).setKey(s));
}
public void setShort(String s, short word0)
{
tagMap.put(s, (new NBTTagShort(word0)).setKey(s));
}
public void setInteger(String s, int i)
{
tagMap.put(s, (new NBTTagInt(i)).setKey(s));
}
public void setLong(String s, long l)
{
tagMap.put(s, (new NBTTagLong(l)).setKey(s));
}
public void setFloat(String s, float f)
{
tagMap.put(s, (new NBTTagFloat(f)).setKey(s));
}
public void setDouble(String s, double d)
{
tagMap.put(s, (new NBTTagDouble(d)).setKey(s));
}
public void setString(String s, String s1)
{
tagMap.put(s, (new NBTTagString(s1)).setKey(s));
}
public void setByteArray(String s, byte abyte0[])
{
tagMap.put(s, (new NBTTagByteArray(abyte0)).setKey(s));
}
public void setCompoundTag(String s, NBTTagCompound nbttagcompound)
{
tagMap.put(s, nbttagcompound.setKey(s));
}
public void setBoolean(String s, boolean flag)
{
setByte(s, ((byte)(flag ? 1 : 0)));
}
public boolean hasKey(String s)
{
return tagMap.containsKey(s);
}
public byte getByte(String s)
{
if(!tagMap.containsKey(s))
{
return 0;
} else
{
return ((NBTTagByte)tagMap.get(s)).byteValue;
}
}
public short getShort(String s)
{
if(!tagMap.containsKey(s))
{
return 0;
} else
{
return ((NBTTagShort)tagMap.get(s)).shortValue;
}
}
public int getInteger(String s)
{
if(!tagMap.containsKey(s))
{
return 0;
} else
{
return ((NBTTagInt)tagMap.get(s)).intValue;
}
}
public long getLong(String s)
{
if(!tagMap.containsKey(s))
{
return 0L;
} else
{
return ((NBTTagLong)tagMap.get(s)).longValue;
}
}
public float getFloat(String s)
{
if(!tagMap.containsKey(s))
{
return 0.0F;
} else
{
return ((NBTTagFloat)tagMap.get(s)).value;
}
}
public double getDouble(String s)
{
if(!tagMap.containsKey(s))
{
return 0.0D;
} else
{
return ((NBTTagDouble)tagMap.get(s)).doubleValue;
}
}
public String getString(String s)
{
if(!tagMap.containsKey(s))
{
return "";
} else
{
return ((NBTTagString)tagMap.get(s)).stringValue;
}
}
public byte[] getByteArray(String s)
{
if(!tagMap.containsKey(s))
{
return new byte[0];
} else
{
return ((NBTTagByteArray)tagMap.get(s)).byteArray;
}
}
public NBTTagCompound getCompoundTag(String s)
{
if(!tagMap.containsKey(s))
{
return new NBTTagCompound();
} else
{
return (NBTTagCompound)tagMap.get(s);
}
}
public NBTTagList getTagList(String s)
{
if(!tagMap.containsKey(s))
{
return new NBTTagList();
} else
{
return (NBTTagList)tagMap.get(s);
}
}
public boolean getBoolean(String s)
{
return getByte(s) != 0;
}
public String toString()
{
return (new StringBuilder()).append("").append(tagMap.size()).append(" entries").toString();
}
private Map<String, NBTBase> tagMap;
}

View file

@ -0,0 +1,41 @@
package net.oikmo.engine.nbt;
// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) braces deadcode
import java.io.*;
public class NBTTagDouble extends NBTBase
{
public NBTTagDouble()
{
}
public NBTTagDouble(double d)
{
doubleValue = d;
}
void writeTagContents(DataOutput dataoutput) throws IOException
{
dataoutput.writeDouble(doubleValue);
}
void readTagContents(DataInput datainput) throws IOException
{
doubleValue = datainput.readDouble();
}
public byte getType()
{
return 6;
}
public String toString()
{
return (new StringBuilder()).append("").append(doubleValue).toString();
}
public double doubleValue;
}

View file

@ -0,0 +1,32 @@
package net.oikmo.engine.nbt;
// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) braces deadcode
import java.io.*;
public class NBTTagEnd extends NBTBase
{
public NBTTagEnd()
{
}
void readTagContents(DataInput datainput) throws IOException
{
}
void writeTagContents(DataOutput dataoutput) throws IOException
{
}
public byte getType()
{
return 0;
}
public String toString()
{
return "END";
}
}

View file

@ -0,0 +1,41 @@
package net.oikmo.engine.nbt;
// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) braces deadcode
import java.io.*;
public class NBTTagFloat extends NBTBase
{
public NBTTagFloat()
{
}
public NBTTagFloat(float f)
{
value = f;
}
void writeTagContents(DataOutput dataoutput) throws IOException
{
dataoutput.writeFloat(value);
}
void readTagContents(DataInput datainput) throws IOException
{
value = datainput.readFloat();
}
public byte getType()
{
return 5;
}
public String toString()
{
return (new StringBuilder()).append("").append(value).toString();
}
public float value;
}

View file

@ -0,0 +1,41 @@
package net.oikmo.engine.nbt;
// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) braces deadcode
import java.io.*;
public class NBTTagInt extends NBTBase
{
public NBTTagInt()
{
}
public NBTTagInt(int i)
{
intValue = i;
}
void writeTagContents(DataOutput dataoutput) throws IOException
{
dataoutput.writeInt(intValue);
}
void readTagContents(DataInput datainput) throws IOException
{
intValue = datainput.readInt();
}
public byte getType()
{
return 3;
}
public String toString()
{
return (new StringBuilder()).append("").append(intValue).toString();
}
public int intValue;
}

View file

@ -0,0 +1,78 @@
package net.oikmo.engine.nbt;
// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) braces deadcode
import java.io.*;
import java.util.ArrayList;
import java.util.List;
public class NBTTagList extends NBTBase
{
public NBTTagList()
{
tagList = new ArrayList<NBTBase>();
}
void writeTagContents(DataOutput dataoutput) throws IOException
{
if(tagList.size() > 0)
{
tagType = ((NBTBase)tagList.get(0)).getType();
} else
{
tagType = 1;
}
dataoutput.writeByte(tagType);
dataoutput.writeInt(tagList.size());
for(int i = 0; i < tagList.size(); i++)
{
((NBTBase)tagList.get(i)).writeTagContents(dataoutput);
}
}
void readTagContents(DataInput datainput) throws IOException
{
tagType = datainput.readByte();
int i = datainput.readInt();
tagList = new ArrayList<NBTBase>();
for(int j = 0; j < i; j++)
{
NBTBase nbtbase = NBTBase.createTagOfType(tagType);
nbtbase.readTagContents(datainput);
tagList.add(nbtbase);
}
}
public byte getType()
{
return 9;
}
public String toString()
{
return (new StringBuilder()).append("").append(tagList.size()).append(" entries of type ").append(NBTBase.getTagName(tagType)).toString();
}
public void setTag(NBTBase nbtbase)
{
tagType = nbtbase.getType();
tagList.add(nbtbase);
}
public NBTBase tagAt(int i)
{
return (NBTBase)tagList.get(i);
}
public int tagCount()
{
return tagList.size();
}
private List<NBTBase> tagList;
private byte tagType;
}

View file

@ -0,0 +1,41 @@
package net.oikmo.engine.nbt;
// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) braces deadcode
import java.io.*;
public class NBTTagLong extends NBTBase
{
public NBTTagLong()
{
}
public NBTTagLong(long l)
{
longValue = l;
}
void writeTagContents(DataOutput dataoutput) throws IOException
{
dataoutput.writeLong(longValue);
}
void readTagContents(DataInput datainput) throws IOException
{
longValue = datainput.readLong();
}
public byte getType()
{
return 4;
}
public String toString()
{
return (new StringBuilder()).append("").append(longValue).toString();
}
public long longValue;
}

View file

@ -0,0 +1,41 @@
package net.oikmo.engine.nbt;
// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) braces deadcode
import java.io.*;
public class NBTTagShort extends NBTBase
{
public NBTTagShort()
{
}
public NBTTagShort(short word0)
{
shortValue = word0;
}
void writeTagContents(DataOutput dataoutput) throws IOException
{
dataoutput.writeShort(shortValue);
}
void readTagContents(DataInput datainput) throws IOException
{
shortValue = datainput.readShort();
}
public byte getType()
{
return 2;
}
public String toString()
{
return (new StringBuilder()).append("").append(shortValue).toString();
}
public short shortValue;
}

View file

@ -0,0 +1,48 @@
package net.oikmo.engine.nbt;
// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) braces deadcode
import java.io.*;
public class NBTTagString extends NBTBase
{
public NBTTagString()
{
}
public NBTTagString(String s)
{
stringValue = s;
if(s == null)
{
throw new IllegalArgumentException("Empty string not allowed");
} else
{
return;
}
}
void writeTagContents(DataOutput dataoutput) throws IOException
{
dataoutput.writeUTF(stringValue);
}
void readTagContents(DataInput datainput) throws IOException
{
stringValue = datainput.readUTF();
}
public byte getType()
{
return 8;
}
public String toString()
{
return (new StringBuilder()).append("").append(stringValue).toString();
}
public String stringValue;
}

View file

@ -0,0 +1,59 @@
package net.oikmo.engine.network;
import org.newdawn.slick.ImageBuffer;
import com.esotericsoftware.kryonet.Connection;
import net.oikmo.engine.models.TexturedModel;
/**
* Represents players on a server
* @author Oikmo
*/
public class OtherPlayer {
/** Active connection */
public Connection c;
/** Active connection id */
public int id;
/** Player name */
public String userName;
/** World position */
public float x, y, z;
/** Model rotation */
public float rotX, rotY, rotZ;
/** Texture buffer for the model */
public ImageBuffer buffer;
/** The player model with texture */
public TexturedModel model;
/** Currently selected block (shows on top of the head of the player) */
public byte block = -1;
/**
* Sets the position to given parameters
* @param x X position
* @param y Y position
* @param x Z position
*/
public void updatePosition(float x, float y, float z) {
this.x = x;
this.y = y;
this.z = z;
}
/**
* Sets the rotation to given parameters
* @param rotX X rotation
* @param rotY Y rotation
* @param rotZ Z rotation
*/
public void updateRotation(float rotX, float rotY, float rotZ) {
this.rotX = rotX;
this.rotY = rotY;
this.rotZ = rotZ;
}
}

View file

@ -1,4 +1,4 @@
package net.oikmo.network.client;
package net.oikmo.engine.network;
import java.io.Serializable;

View file

@ -1,4 +1,4 @@
package net.oikmo.network.client;
package net.oikmo.engine.network.client;
import java.util.ArrayList;
import java.util.HashMap;
@ -13,36 +13,39 @@ import org.lwjgl.util.vector.Vector3f;
import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryonet.Client;
import net.oikmo.engine.InputManager;
import net.oikmo.engine.gui.ChatMessage;
import net.oikmo.engine.network.OtherPlayer;
import net.oikmo.engine.network.packet.LoginRequest;
import net.oikmo.engine.network.packet.LoginResponse;
import net.oikmo.engine.network.packet.Message;
import net.oikmo.engine.network.packet.PacketAddPlayer;
import net.oikmo.engine.network.packet.PacketChatMessage;
import net.oikmo.engine.network.packet.PacketChunk;
import net.oikmo.engine.network.packet.PacketGameOver;
import net.oikmo.engine.network.packet.PacketModifyChunk;
import net.oikmo.engine.network.packet.PacketPlaySoundAt;
import net.oikmo.engine.network.packet.PacketRemovePlayer;
import net.oikmo.engine.network.packet.PacketRequestChunk;
import net.oikmo.engine.network.packet.PacketSavePlayerPosition;
import net.oikmo.engine.network.packet.PacketTickPlayer;
import net.oikmo.engine.network.packet.PacketUpdateRotX;
import net.oikmo.engine.network.packet.PacketUpdateRotY;
import net.oikmo.engine.network.packet.PacketUpdateRotZ;
import net.oikmo.engine.network.packet.PacketUpdateWithheldBlock;
import net.oikmo.engine.network.packet.PacketUpdateX;
import net.oikmo.engine.network.packet.PacketUpdateY;
import net.oikmo.engine.network.packet.PacketUpdateZ;
import net.oikmo.engine.network.packet.PacketUserName;
import net.oikmo.engine.network.packet.PacketWorldJoin;
import net.oikmo.engine.network.packet.RandomNumber;
import net.oikmo.engine.sound.SoundMaster;
import net.oikmo.engine.world.World;
import net.oikmo.engine.world.blocks.Block;
import net.oikmo.main.Main;
import net.oikmo.network.shared.LoginRequest;
import net.oikmo.network.shared.LoginResponse;
import net.oikmo.network.shared.Message;
import net.oikmo.network.shared.PacketAddPlayer;
import net.oikmo.network.shared.PacketChatMessage;
import net.oikmo.network.shared.PacketChunk;
import net.oikmo.network.shared.PacketGameOver;
import net.oikmo.network.shared.PacketModifyChunk;
import net.oikmo.network.shared.PacketPlaySoundAt;
import net.oikmo.network.shared.PacketRemovePlayer;
import net.oikmo.network.shared.PacketRequestChunk;
import net.oikmo.network.shared.PacketSavePlayerPosition;
import net.oikmo.network.shared.PacketTickPlayer;
import net.oikmo.network.shared.PacketUpdateRotX;
import net.oikmo.network.shared.PacketUpdateRotY;
import net.oikmo.network.shared.PacketUpdateRotZ;
import net.oikmo.network.shared.PacketUpdateWithheldBlock;
import net.oikmo.network.shared.PacketUpdateX;
import net.oikmo.network.shared.PacketUpdateY;
import net.oikmo.network.shared.PacketUpdateZ;
import net.oikmo.network.shared.PacketUserName;
import net.oikmo.network.shared.PacketWorldJoin;
import net.oikmo.network.shared.RandomNumber;
import net.oikmo.main.gui.GuiMainMenu;
import net.oikmo.toolbox.Logger;
import net.oikmo.toolbox.Maths;
import net.oikmo.toolbox.Logger.LogLevel;
import net.oikmo.toolbox.properties.OptionsHandler;
public class NetworkHandler {
@ -65,7 +68,7 @@ public class NetworkHandler {
public List<ChatMessage> currentlyShownMessages = new ArrayList<ChatMessage>();
private int tickTimer = 0;
public static final int NETWORK_PROTOCOL = 4;
public static final int NETWORK_PROTOCOL = 7;
private static void registerKryoClasses() {
kryo.register(LoginRequest.class);
@ -103,15 +106,14 @@ public class NetworkHandler {
this.timeout = 500000;
players = new HashMap<Integer, OtherPlayer>();
player = new OtherPlayer();
String name = "Player"+new Random().nextInt(256);
if(Main.playerName == null ) {
Main.playerName = name;
}
player.userName = Main.playerName;
currentlyShownMessages = new ArrayList<>();
client = new Client();
kryo = client.getKryo();
registerKryoClasses();
World.updateRenderSize(4);
GuiMainMenu.stopMusic();
SoundMaster.stopMusic();
connect(ip);
}
@ -133,19 +135,22 @@ public class NetworkHandler {
Logger.log(LogLevel.INFO, "Test disconnected.");
}
private float degreesOffsetX = -90;
public void tick() {
synchronized(currentlyShownMessages) {
for(int i = 0; i < currentlyShownMessages.size(); i++) {
currentlyShownMessages.get(i).tick();
}
}
if(tickTimer <= 60) {
if(tickTimer <= 5) {
tickTimer++;
} else {
tickTimer = 0;
if(!InputManager.hasMouseMoved()) {
if(!Main.thePlayer.getCamera().isPerspective()) {
Vector3f rot = Main.thePlayer.getCamera().getRotation();
player.updateRotation(rot.x, rot.y-degreesOffsetX, rot.z);
@ -153,13 +158,11 @@ public class NetworkHandler {
packetRotX.x = player.rotX;
client.sendUDP(packetRotX);
PacketUpdateRotY packetRotY = new PacketUpdateRotY();
packetRotY.y = player.rotY;
packetRotY.y = player.rotY-degreesOffsetX;
client.sendUDP(packetRotY);
PacketUpdateRotZ packetRotZ = new PacketUpdateRotZ();
packetRotZ.z = player.rotZ;
client.sendUDP(packetRotZ);
}
if(!InputManager.isMoving()) {
Vector3f pos = Main.thePlayer.getCamera().getPosition();
player.updatePosition(pos.x, pos.y, pos.z);
@ -172,18 +175,38 @@ public class NetworkHandler {
PacketUpdateZ packetZ = new PacketUpdateZ();
packetZ.z = player.z;
client.sendUDP(packetZ);
} else {
Vector3f rot = Main.thePlayer.getModelRotation();
player.updateRotation(rot.x, rot.y-degreesOffsetX, rot.z);
PacketUpdateRotX packetRotX = new PacketUpdateRotX();
packetRotX.x = player.rotX;
client.sendUDP(packetRotX);
PacketUpdateRotY packetRotY = new PacketUpdateRotY();
packetRotY.y = player.rotY-degreesOffsetX;
client.sendUDP(packetRotY);
PacketUpdateRotZ packetRotZ = new PacketUpdateRotZ();
packetRotZ.z = player.rotZ;
client.sendUDP(packetRotZ);
Vector3f pos = Main.thePlayer.getModelPosition();
player.updatePosition(pos.x, pos.y, pos.z);
PacketUpdateX packetX = new PacketUpdateX();
packetX.x = player.x;
client.sendUDP(packetX);
PacketUpdateY packetY = new PacketUpdateY();
packetY.y = player.y;
client.sendUDP(packetY);
PacketUpdateZ packetZ = new PacketUpdateZ();
packetZ.z = player.z;
client.sendUDP(packetZ);
}
}
}
private float degreesOffsetX = -90;
public void update() {
if(!client.isConnected()) {
System.out.println("Yeahhh");
}
if(!client.isConnected()) {
this.disconnect();
Main.disconnect(false, Main.lang.translateKey("network.disconnect.ux"));
return;
}
@ -199,69 +222,63 @@ public class NetworkHandler {
}
}
float x = player.x;
float y = player.y;
float z = player.z;
float rotX = player.rotX;
float rotY = player.rotY-degreesOffsetX;
float rotZ = player.rotZ;
Vector3f pos = Main.thePlayer.getCamera().getPosition();
Vector3f rot = Main.thePlayer.getCamera().getRotation();
player.updatePosition(pos.x, pos.y, pos.z);
player.updateRotation(rot.x, rot.y-degreesOffsetX, rot.z);
if(x != player.x) {
PacketUpdateX packetX = new PacketUpdateX();
packetX.x = player.x;
client.sendUDP(packetX);
if(!Main.thePlayer.getCamera().isPerspective()) {
Vector3f pos = Main.thePlayer.getCamera().getPosition();
player.updatePosition(pos.x, pos.y, pos.z);
if(x != player.x) {
PacketUpdateX packetX = new PacketUpdateX();
packetX.x = player.x;
client.sendUDP(packetX);
}
if(y != player.y) {
PacketUpdateY packetY = new PacketUpdateY();
packetY.y = player.y;
client.sendUDP(packetY);
}
if(z != player.z) {
PacketUpdateZ packetZ = new PacketUpdateZ();
packetZ.z = player.z;
client.sendUDP(packetZ);
}
} else {
Vector3f pos = Main.thePlayer.getModelPosition();
player.updatePosition(pos.x, pos.y, pos.z);
if(x != player.x) {
PacketUpdateX packetX = new PacketUpdateX();
packetX.x = player.x;
client.sendUDP(packetX);
}
if(y != player.y) {
PacketUpdateY packetY = new PacketUpdateY();
packetY.y = player.y;
client.sendUDP(packetY);
}
if(z != player.z) {
PacketUpdateZ packetZ = new PacketUpdateZ();
packetZ.z = player.z;
client.sendUDP(packetZ);
}
}
if(y != player.y) {
PacketUpdateY packetY = new PacketUpdateY();
packetY.y = player.y;
client.sendUDP(packetY);
}
if(z != player.z) {
PacketUpdateZ packetZ = new PacketUpdateZ();
packetZ.z = player.z;
client.sendUDP(packetZ);
}
if(rotX != player.rotX) {
PacketUpdateRotX packetX = new PacketUpdateRotX();
packetX.x = player.rotX;
client.sendUDP(packetX);
}
if(rotY != player.rotY) {
PacketUpdateRotY packetY = new PacketUpdateRotY();
packetY.y = player.rotY;
client.sendUDP(packetY);
}
if(rotZ != player.rotZ) {
PacketUpdateRotZ packetZ = new PacketUpdateRotZ();
packetZ.z = player.rotZ;
client.sendUDP(packetZ);
}
}
Vector3f lastRecordedPosition = new Vector3f();
byte lastBlock;
public void updateChunk(Vector3f position, Block block, boolean refresh) {
byte b = block != null ? block.getByteType() : -1;
if(!Maths.isVectorEqualTo(lastRecordedPosition, position) && b != lastBlock) {
PacketModifyChunk packet = new PacketModifyChunk();
packet.refresh = refresh;
packet.x = (int) position.x;
packet.y = (int) position.y;
packet.z = (int) position.z;
packet.block = b;
client.sendTCP(packet);
}
byte b = block != null ? block.getByteType() : 0;
PacketModifyChunk packet = new PacketModifyChunk();
packet.refresh = refresh;
packet.x = (int) position.x;
packet.y = (int) position.y;
packet.z = (int) position.z;
packet.block = b;
client.sendTCP(packet);
}
public void connect(String ip) throws Exception {
@ -282,20 +299,29 @@ public class NetworkHandler {
public void disconnect() {
if(Main.thePlayer != null) {
PacketSavePlayerPosition data = new PacketSavePlayerPosition();
data.x = (int) Main.thePlayer.getPosition().x;
data.y = (int) Main.thePlayer.getPosition().y+1;
data.z = (int) Main.thePlayer.getPosition().z;
data.userName = Main.playerName;
data.x = Main.thePlayer.getPosition().x;
data.y = Main.thePlayer.getPosition().y+1;
data.z = Main.thePlayer.getPosition().z;
data.rotX = Main.thePlayer.getCamera().getPitch();
data.rotY = Main.thePlayer.getCamera().getYaw();
data.rotZ = Main.thePlayer.getCamera().getRoll();
client.sendTCP(data);
}
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Logger.log(LogLevel.INFO, "Disconnecting...");
client.stop();
Logger.log(LogLevel.INFO, "Disconnected.");
try {
World.updateRenderSize(Integer.parseInt(OptionsHandler.getInstance().translateKey("graphics.distance"))*2);
} catch(NumberFormatException e) {
OptionsHandler.getInstance().insertKey("graphics.distance", 2+"");
}
}
}

View file

@ -1,53 +1,67 @@
package net.oikmo.network.client;
package net.oikmo.engine.network.client;
import java.io.IOException;
import java.awt.image.BufferedImage;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import java.util.HashMap;
import javax.imageio.ImageIO;
import org.lwjgl.util.vector.Vector3f;
import org.newdawn.slick.ImageBuffer;
import com.esotericsoftware.kryonet.Connection;
import com.esotericsoftware.kryonet.Listener;
import net.oikmo.engine.entity.Player;
import net.oikmo.engine.gui.ChatMessage;
import net.oikmo.engine.network.OtherPlayer;
import net.oikmo.engine.network.packet.LoginResponse;
import net.oikmo.engine.network.packet.PacketAddPlayer;
import net.oikmo.engine.network.packet.PacketChatMessage;
import net.oikmo.engine.network.packet.PacketChunk;
import net.oikmo.engine.network.packet.PacketModifyChunk;
import net.oikmo.engine.network.packet.PacketPlaySoundAt;
import net.oikmo.engine.network.packet.PacketRemovePlayer;
import net.oikmo.engine.network.packet.PacketTickPlayer;
import net.oikmo.engine.network.packet.PacketUpdateRotX;
import net.oikmo.engine.network.packet.PacketUpdateRotY;
import net.oikmo.engine.network.packet.PacketUpdateRotZ;
import net.oikmo.engine.network.packet.PacketUpdateWithheldBlock;
import net.oikmo.engine.network.packet.PacketUpdateX;
import net.oikmo.engine.network.packet.PacketUpdateY;
import net.oikmo.engine.network.packet.PacketUpdateZ;
import net.oikmo.engine.network.packet.PacketUserName;
import net.oikmo.engine.network.packet.PacketWorldJoin;
import net.oikmo.engine.sound.SoundMaster;
import net.oikmo.engine.world.World;
import net.oikmo.engine.world.blocks.Block;
import net.oikmo.engine.world.chunk.MasterChunk;
import net.oikmo.engine.world.chunk.coordinate.ChunkCoordHelper;
import net.oikmo.engine.world.chunk.coordinate.ChunkCoordinates;
import net.oikmo.main.Main;
import net.oikmo.main.gui.GuiChat;
import net.oikmo.network.shared.LoginResponse;
import net.oikmo.network.shared.PacketAddPlayer;
import net.oikmo.network.shared.PacketChatMessage;
import net.oikmo.network.shared.PacketChunk;
import net.oikmo.network.shared.PacketModifyChunk;
import net.oikmo.network.shared.PacketPlaySoundAt;
import net.oikmo.network.shared.PacketRemovePlayer;
import net.oikmo.network.shared.PacketTickPlayer;
import net.oikmo.network.shared.PacketUpdateRotX;
import net.oikmo.network.shared.PacketUpdateRotY;
import net.oikmo.network.shared.PacketUpdateRotZ;
import net.oikmo.network.shared.PacketUpdateWithheldBlock;
import net.oikmo.network.shared.PacketUpdateX;
import net.oikmo.network.shared.PacketUpdateY;
import net.oikmo.network.shared.PacketUpdateZ;
import net.oikmo.network.shared.PacketUserName;
import net.oikmo.network.shared.PacketWorldJoin;
import net.oikmo.toolbox.Logger;
import net.oikmo.toolbox.Logger.LogLevel;
import net.oikmo.toolbox.Maths;
public class PlayerClientListener extends Listener {
public static World theWorld;
public void received(Connection connection, Object object){
//System.out.println(object);
if(!Thread.currentThread().getName().contentEquals("PlayerClientListener Thread")) {
Thread.currentThread().setName("PlayerClientListener Thread");
}
if(object instanceof LoginResponse){
LoginResponse response = (LoginResponse) object;
if(response.getResponseText().equalsIgnoreCase("ok")){
Logger.log(LogLevel.INFO,"Login Ok");
} else {
Main.theNetwork.disconnect();
System.out.println(response.PROTOCOL + " " + NetworkHandler.NETWORK_PROTOCOL);
if(response.PROTOCOL != NetworkHandler.NETWORK_PROTOCOL) {
Main.disconnect(false, Main.lang.translateKey("network.disconnect.p").replace("%s", ""+response.PROTOCOL));
@ -63,9 +77,9 @@ public class PlayerClientListener extends Listener {
PacketAddPlayer packet = (PacketAddPlayer) object;
OtherPlayer newPlayer = new OtherPlayer();
System.out.println(Main.theNetwork + " network is?");
if(Main.theNetwork == null) {
Main.disconnect(false, Main.lang.translateKey("network.disconnect.g"));
System.out.println("return at PacketAddPlayer");
return;
} else {
if(!Main.theNetwork.players.containsKey(packet.id)) {
Main.theNetwork.players.put(packet.id, newPlayer);
@ -96,8 +110,8 @@ public class PlayerClientListener extends Listener {
else if(object instanceof PacketUserName){
PacketUserName packet = (PacketUserName) object;
if(Main.theNetwork == null) {
Main.theNetwork.disconnect();
Main.disconnect(false, Main.lang.translateKey("network.disconnect.u"));
System.out.println("return at PacketUserName");
return;
} else if(Main.theNetwork.players == null) {
Main.theNetwork.players = new HashMap<>();
}
@ -106,6 +120,32 @@ public class PlayerClientListener extends Listener {
Main.theNetwork.players.put(packet.id, new OtherPlayer());
OtherPlayer p = Main.theNetwork.players.get(packet.id);
p.userName = packet.userName;
BufferedImage image = null;
try {
URL url = new URL("http://blockbase.gurdit.com/users/"+packet.userName+"/skin_"+ packet.userName + ".png");
URLConnection conn = url.openConnection();
InputStream in = conn.getInputStream();
image = ImageIO.read(in);
} catch(Exception e) {}
ImageBuffer buf = new ImageBuffer(64,64);
if(image != null) {
for(int x = 0; x < 64; x++) {
for(int y = 0; y < 64; y++) {
int rgba = image.getRGB(x, y);
if((rgba & 0xff000000) == 0) {
image.setRGB(x,y, (java.awt.Color.black.getRGB()));
}
java.awt.Color c = new java.awt.Color(image.getRGB(x, y), true);
buf.setRGBA(x, y, c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha());
}
}
p.buffer = buf;
}
p.id = connection.getID();
if(Main.thePlayer != null) {
if(packet.userName != null) {
if(!Main.theNetwork.players.get(packet.id).userName.contentEquals(Main.theNetwork.player.userName)) {
@ -116,6 +156,9 @@ public class PlayerClientListener extends Listener {
}
if(Main.theNetwork.players.get(packet.id).userName == null) {
Main.theNetwork.players.get(packet.id).userName = packet.userName;
if(image != null) {
p.buffer = buf;
}
}
}
@ -124,6 +167,31 @@ public class PlayerClientListener extends Listener {
} else if(Main.theNetwork.players.containsKey(packet.id)) {
OtherPlayer p = Main.theNetwork.players.get(packet.id);
p.userName = packet.userName;
BufferedImage image = null;
try {
URL url = new URL("http://blockbase.gurdit.com/users/"+packet.userName+"/skin_"+ packet.userName + ".png");
URLConnection conn = url.openConnection();
InputStream in = conn.getInputStream();
image = ImageIO.read(in);
} catch(Exception e) {}
ImageBuffer buf = new ImageBuffer(64,64);
if(image != null) {
for(int x = 0; x < 64; x++) {
for(int y = 0; y < 64; y++) {
int rgba = image.getRGB(x, y);
if((rgba & 0xff000000) == 0) {
image.setRGB(x,y, (java.awt.Color.black.getRGB()));
}
java.awt.Color c = new java.awt.Color(image.getRGB(x, y), true);
buf.setRGBA(x, y, c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha());
}
}
p.buffer = buf;
}
if(Main.thePlayer != null) {
if(packet.userName != null) {
if(!Main.theNetwork.players.get(packet.id).userName.contentEquals(Main.theNetwork.player.userName)) {
@ -132,12 +200,12 @@ public class PlayerClientListener extends Listener {
((GuiChat)Main.currentScreen).updateMessages();
}
if(Main.theNetwork.players.get(packet.id).userName == null) {
Main.theNetwork.players.get(packet.id).userName = packet.userName;
Main.theNetwork.players.get(packet.id).userName = packet.userName;
if(image != null) {
p.buffer = buf;
}
}
}
}
}
}
@ -168,6 +236,9 @@ public class PlayerClientListener extends Listener {
}
else if(object instanceof PacketUpdateRotX){
PacketUpdateRotX packet = (PacketUpdateRotX) object;
if(Main.theNetwork == null) {
Main.disconnect(false, "");
}
if(Main.theNetwork.players.get(packet.id) != null) {
Main.theNetwork.players.get(packet.id).rotX = packet.x;
} else {
@ -175,7 +246,7 @@ public class PlayerClientListener extends Listener {
}
}
else if(object instanceof PacketUpdateRotY){
PacketUpdateRotY packet = (PacketUpdateRotY) object;
if(Main.theNetwork.players.get(packet.id) != null) {
Main.theNetwork.players.get(packet.id).rotY = packet.y;
@ -202,15 +273,9 @@ public class PlayerClientListener extends Listener {
else if(object instanceof PacketChunk) {
PacketChunk packet = (PacketChunk) object;
byte[][][] blocks = new byte[1][1][1];
try {
blocks = (byte[][][])Maths.uncompressStream(packet.data);
} catch (ClassNotFoundException | IOException e) {
e.printStackTrace();
}
Vector3f chunkPos = new Vector3f(packet.x, 0, packet.z);
byte[] blocks = new byte[1];
blocks = (byte[])Maths.uncompressStream(packet.data);
ChunkCoordinates chunkPos = ChunkCoordHelper.create(packet.x, packet.z);
Main.theWorld.addChunk(new MasterChunk(chunkPos, blocks));
}
else if(object instanceof PacketModifyChunk) {
@ -219,28 +284,26 @@ public class PlayerClientListener extends Listener {
Block block = Block.getBlockFromOrdinal(packet.block);
if(packet.refresh) {
Main.theWorld.setBlockNoNet(blockPos, block);
theWorld.setBlockNoNet(blockPos, block);
} else {
Main.theWorld.setBlockNoUpdateNoNet(blockPos, block);
theWorld.setBlockNoUpdateNoNet(blockPos, block);
}
}
else if(object instanceof PacketWorldJoin) {
PacketWorldJoin packet = (PacketWorldJoin) object;
Main.theWorld = new World(packet.seed);
theWorld = new World(packet.seed);
Main.theWorld = theWorld;
if(Main.thePlayer == null) {
Main.thePlayer = new Player(new Vector3f(0,120,0),new Vector3f(0,0,0));
}
Main.thePlayer.setPos(packet.x,packet.y,packet.z);
System.out.println("Server world seed:" + packet.seed + " pos:" + packet.x + " " + packet.y + " " + packet.z);
Main.thePlayer.getCamera().setRotation(packet.rotX, packet.rotY, packet.rotZ);
}
else if(object instanceof PacketTickPlayer) {
PacketTickPlayer packet = (PacketTickPlayer) object;
Main.thePlayer.tick = packet.shouldTick;
}
else if(object instanceof PacketPlaySoundAt) {
PacketPlaySoundAt packet = (PacketPlaySoundAt) object;
Block block = Block.getBlockFromOrdinal(packet.blockID);
@ -259,9 +322,14 @@ public class PlayerClientListener extends Listener {
else if(object instanceof PacketChatMessage) {
PacketChatMessage packet = (PacketChatMessage) object;
Main.theNetwork.rawMessages.add(new ChatMessage(packet.message, false));
if(Main.theNetwork.players.get(packet.id).userName == null) {
Main.theNetwork.players.get(packet.id).userName = packet.message.split(">")[0].replace("<", "").replace(">","").trim();
if(!packet.message.startsWith(" [SERVER]")) {
if(Main.theNetwork.players.get(packet.id) != null) {
if(Main.theNetwork.players.get(packet.id).userName == null) {
Main.theNetwork.players.get(packet.id).userName = packet.message.split(">")[0].replace("<", "").replace(">","").trim();
}
}
}
if(Main.currentScreen instanceof GuiChat) {
((GuiChat)Main.currentScreen).updateMessages();
}
@ -270,7 +338,7 @@ public class PlayerClientListener extends Listener {
private void requestInfo(Connection connection) {
if(!Main.theNetwork.players.keySet().contains(connection.getID())) {
Main.theNetwork.players.put(connection.getID(), new OtherPlayer());
//Main.theNetwork.players.put(connection.getID(), new OtherPlayer());
}
}
}

View file

@ -0,0 +1,5 @@
/**
* Client network code, embedded with server.
* @author Oikmo
*/
package net.oikmo.engine.network.client;

View file

@ -0,0 +1,5 @@
/**
* network code, so you and people and play the game with people and the people play game in which the game plays you
* @author Oikmo
*/
package net.oikmo.engine.network;

View file

@ -1,4 +1,4 @@
package net.oikmo.network.shared;
package net.oikmo.engine.network.packet;
public class LoginRequest {

View file

@ -1,4 +1,4 @@
package net.oikmo.network.shared;
package net.oikmo.engine.network.packet;
public class LoginResponse {

View file

@ -1,4 +1,4 @@
package net.oikmo.network.shared;
package net.oikmo.engine.network.packet;
public class Message {

View file

@ -1,4 +1,4 @@
package net.oikmo.network.shared;
package net.oikmo.engine.network.packet;
public class PacketAddPlayer {

View file

@ -1,4 +1,4 @@
package net.oikmo.network.shared;
package net.oikmo.engine.network.packet;
public class PacketChatMessage {
public int id;

View file

@ -1,9 +1,8 @@
package net.oikmo.network.shared;
package net.oikmo.engine.network.packet;
public class PacketChunk {
public int id;
public float x;
public float z;
public int x,z;
public byte[] data;
}

View file

@ -1,4 +1,4 @@
package net.oikmo.network.shared;
package net.oikmo.engine.network.packet;
public class PacketGameOver {

View file

@ -1,4 +1,4 @@
package net.oikmo.network.shared;
package net.oikmo.engine.network.packet;
public class PacketModifyChunk {
public int id;

View file

@ -1,4 +1,4 @@
package net.oikmo.network.shared;
package net.oikmo.engine.network.packet;
public class PacketPlaySoundAt {

View file

@ -1,4 +1,4 @@
package net.oikmo.network.shared;
package net.oikmo.engine.network.packet;
public class PacketRemovePlayer {

View file

@ -1,4 +1,4 @@
package net.oikmo.network.shared;
package net.oikmo.engine.network.packet;
public class PacketRequestChunk {

View file

@ -0,0 +1,8 @@
package net.oikmo.engine.network.packet;
public class PacketSavePlayerPosition {
public int id;
public String userName;
public float x, y, z;
public float rotX, rotY, rotZ;
}

View file

@ -1,4 +1,4 @@
package net.oikmo.network.shared;
package net.oikmo.engine.network.packet;
public class PacketTickPlayer {

View file

@ -1,4 +1,4 @@
package net.oikmo.network.shared;
package net.oikmo.engine.network.packet;
public class PacketUpdateRotX {

View file

@ -1,4 +1,4 @@
package net.oikmo.network.shared;
package net.oikmo.engine.network.packet;
public class PacketUpdateRotY {

View file

@ -1,4 +1,4 @@
package net.oikmo.network.shared;
package net.oikmo.engine.network.packet;
public class PacketUpdateRotZ {

View file

@ -1,4 +1,4 @@
package net.oikmo.network.shared;
package net.oikmo.engine.network.packet;
public class PacketUpdateWithheldBlock {
public int id;

View file

@ -1,4 +1,4 @@
package net.oikmo.network.shared;
package net.oikmo.engine.network.packet;
public class PacketUpdateX {

View file

@ -1,4 +1,4 @@
package net.oikmo.network.shared;
package net.oikmo.engine.network.packet;
public class PacketUpdateY {

View file

@ -1,4 +1,4 @@
package net.oikmo.network.shared;
package net.oikmo.engine.network.packet;
public class PacketUpdateZ {

View file

@ -1,4 +1,4 @@
package net.oikmo.network.shared;
package net.oikmo.engine.network.packet;
public class PacketUserName {

View file

@ -1,4 +1,4 @@
package net.oikmo.network.shared;
package net.oikmo.engine.network.packet;
public class PacketWorldJoin {
@ -6,4 +6,5 @@ public class PacketWorldJoin {
public long seed;
public float x, y, z;
public float rotX, rotY, rotZ;
}

View file

@ -1,4 +1,4 @@
package net.oikmo.network.shared;
package net.oikmo.engine.network.packet;
public class RandomNumber {

View file

@ -0,0 +1,5 @@
/**
* Tiny little pieces of data that get sent to and back by server
* @author Oikmo
*/
package net.oikmo.engine.network.packet;

View file

@ -24,6 +24,8 @@ import net.oikmo.engine.entity.Camera.TargetedAABB;
import net.oikmo.engine.entity.Entity;
import net.oikmo.engine.gui.Gui;
import net.oikmo.engine.models.TexturedModel;
import net.oikmo.engine.renderers.chunk.ChunkEntity;
import net.oikmo.engine.renderers.chunk.ChunkRenderer;
import net.oikmo.engine.renderers.entity.EntityRenderer;
import net.oikmo.engine.renderers.skybox.SkyBoxRenderer;
import net.oikmo.engine.textures.ModelTexture;
@ -50,30 +52,34 @@ public class MasterRenderer {
private SkyBoxRenderer skyboxRenderer;
private EntityRenderer entityRenderer;
private ChunkRenderer chunkRenderer;
public static ModelTexture currentTexturePack;
public static int defaultTexturePack;
public static int customTexturePack;
public static int particleTexture;
public static int invisibleTexture;
private Map<TexturedModel, List<Entity>> entities = new HashMap<TexturedModel, List<Entity>>();
private Map<TexturedModel, List<ChunkEntity>> chunkEntities = new HashMap<TexturedModel, List<ChunkEntity>>();
public MasterRenderer() {
createProjectionMatrix();
float offset = 0.2f;
skyboxRenderer = new SkyBoxRenderer((Main.jmode ? "jerma" : "panorama"), projectionMatrix);
entityRenderer = new EntityRenderer(projectionMatrix, 0.4f+offset, 0.7f+offset, 1.0f+offset);
defaultTexturePack = ResourceLoader.loadTexture("textures/defaultPack");
chunkRenderer = new ChunkRenderer(projectionMatrix, 0.4f+offset, 0.7f+offset, 1.0f+offset);
defaultTexturePack = ResourceLoader.loadTexture("textures/terrain");
invisibleTexture = ResourceLoader.loadTexture("textures/invisible");
File dir = new File(Main.getResources() + "/custom/textures/");
if(!dir.exists()) {
dir.mkdirs();
} else {
File customPack = new File(dir + "/customPack.png");
File customPack = new File(dir + "/terrain.png");
if(customPack.exists()) {
customTexturePack = ResourceLoader.loadCustomTexture("customPack");
customTexturePack = ResourceLoader.loadCustomTexture("terrain");
} else {
customTexturePack = defaultTexturePack;
Logger.log(LogLevel.WARN, "customPack.png was not found! Defaulting to defaultPack.png");
@ -85,8 +91,8 @@ public class MasterRenderer {
try {
readme.createNewFile();
try {
BufferedImage example = ImageIO.read(MasterRenderer.class.getResourceAsStream("/assets/textures/defaultPack.png"));
File examplePng = new File(dir+"/examplePack.png");
BufferedImage example = ImageIO.read(MasterRenderer.class.getResourceAsStream("/assets/textures/terrain.png"));
File examplePng = new File(dir+"/example_terrain.png");
ImageIO.write(example, "png", examplePng);
} catch (IOException e) {
// TODO Auto-generated catch block
@ -114,6 +120,10 @@ public class MasterRenderer {
Gui.initFont();
}
public void setupSkybox() {
skyboxRenderer = new SkyBoxRenderer((Main.jmode ? "jerma" : "panorama"), projectionMatrix);
}
public void setTexturePack(int texture) {
currentTexturePack.setTextureID(texture);
}
@ -122,6 +132,8 @@ public class MasterRenderer {
GL11.glEnable(GL11.GL_DEPTH_TEST);
GL11.glClearColor(0.4f, 0.7f, 1.0f, 1);
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT );
GL11.glEnable(GL11.GL_CULL_FACE);
GL11.glCullFace(GL11.GL_BACK);
}
public void render(Camera camera) {
@ -131,13 +143,17 @@ public class MasterRenderer {
skyboxRenderer.render(camera, projectionMatrix, 0.4f, 0.7f, 1.0f);
}
entityRenderer.render(entities, camera);
if(Main.thePlayer != null) {
initGL();
if(Main.thePlayer.getCamera().shouldRenderAABB() && Main.thePlayer != null) {
MasterRenderer.getInstance().renderAABB(Main.thePlayer.getCamera().getAABB());
}
}
entityRenderer.render(entities, camera);
chunkRenderer.render(chunkEntities, camera);
chunkEntities.clear();
entities.clear();
}
@ -158,8 +174,7 @@ public class MasterRenderer {
GL11.glTranslatef(-position.x, -position.y, -position.z);
}
public void renderAABB(TargetedAABB ent) {
public void renderAABB(TargetedAABB ent) {
float wb2 = 0.501f, hb2 = 0.501f;
GL11.glColor3f(0, 0, 0);
GL11.glTranslatef(ent.getPosition().x+0.5f, ent.getPosition().y+0.5f, ent.getPosition().z+0.5f);
@ -206,6 +221,22 @@ public class MasterRenderer {
}
}
public void addChunkEntity(ChunkEntity entity) {
TexturedModel model = entity.getModel();
List<ChunkEntity> batch = chunkEntities.get(model);
if(batch != null) {
if(!batch.contains(entity)) {
batch.add(entity);
}
} else {
List<ChunkEntity> newBatch = new ArrayList<>();
newBatch.add(entity);
chunkEntities.put(model, newBatch);
}
}
public void createProjectionMatrix() {
projectionMatrix = new Matrix4f();
@ -227,6 +258,7 @@ public class MasterRenderer {
public void updateProjectionMatrix() {
createProjectionMatrix();
entityRenderer.updateProjectionMatrix(projectionMatrix);
chunkRenderer.updateProjectionMatrix(projectionMatrix);
}
public Matrix4f getProjectionMatrix() {

View file

@ -0,0 +1,24 @@
package net.oikmo.engine.renderers.chunk;
import net.oikmo.engine.models.TexturedModel;
import net.oikmo.engine.world.chunk.coordinate.ChunkCoordinates;
public class ChunkEntity {
private TexturedModel model;
private ChunkCoordinates position;
protected boolean remove = false;
public ChunkEntity(TexturedModel model, ChunkCoordinates position) {
this.model = model;
this.position = position;
}
public ChunkCoordinates getPosition() {
return position;
}
public TexturedModel getModel() {
return model;
}
}

View file

@ -0,0 +1,70 @@
package net.oikmo.engine.renderers.chunk;
import java.util.List;
import java.util.Map;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL13;
import org.lwjgl.opengl.GL20;
import org.lwjgl.opengl.GL30;
import org.lwjgl.util.vector.Matrix4f;
import org.lwjgl.util.vector.Vector3f;
import net.oikmo.engine.entity.Camera;
import net.oikmo.engine.models.TexturedModel;
import net.oikmo.toolbox.Maths;
public class ChunkRenderer {
private ChunkShader shader;
public ChunkRenderer(Matrix4f projectionMatrix, float r, float g, float b) {
shader = new ChunkShader();
shader.start();
shader.loadProjectionMatrix(projectionMatrix);
shader.loadSkyColour(r, g, b);
shader.stop();
}
public void render(Map<TexturedModel, List<ChunkEntity>> chunkEntities, Camera camera) {
synchronized(chunkEntities) {
for(TexturedModel model : chunkEntities.keySet()) {
shader.start();
shader.loadViewMatrix(camera);
GL30.glBindVertexArray(model.getRawModel().getVaoID());
GL20.glEnableVertexAttribArray(0);
GL20.glEnableVertexAttribArray(1);
GL20.glEnableVertexAttribArray(2);
GL13.glActiveTexture(GL13.GL_TEXTURE0);
GL11.glBindTexture(GL11.GL_TEXTURE_2D, model.getTexture().getTextureID());
List<ChunkEntity> batch = chunkEntities.get(model);
for(int i = 0; i < batch.size(); i++) {
ChunkEntity chunk = batch.get(i);
Vector3f position = new Vector3f(chunk.getPosition().x, 0, chunk.getPosition().z);
Matrix4f transformationMatrix = Maths.createTransformationMatrix(position, new Vector3f(0,0,0), 1);
shader.loadTransformationMatrix(transformationMatrix);
GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, model.getRawModel().getVertexCount());
}
GL20.glDisableVertexAttribArray(0);
GL20.glDisableVertexAttribArray(1);
GL20.glDisableVertexAttribArray(2);
GL30.glBindVertexArray(0);
shader.stop();
}
}
}
public void updateProjectionMatrix(Matrix4f projectionMatrix) {
shader.start();
shader.loadProjectionMatrix(projectionMatrix);
shader.stop();
}
}

View file

@ -0,0 +1,53 @@
package net.oikmo.engine.renderers.chunk;
import org.lwjgl.util.vector.Matrix4f;
import org.lwjgl.util.vector.Vector3f;
import net.oikmo.engine.entity.Camera;
import net.oikmo.engine.renderers.ShaderProgram;
import net.oikmo.toolbox.Maths;
public class ChunkShader extends ShaderProgram {
private static String vertexFile = "/net/oikmo/engine/renderers/chunk/chunkVertex.glsl";
private static String fragmentFile = "/net/oikmo/engine/renderers/chunk/chunkFragment.glsl";
private int location_transformationMatrix;
private int location_projectionMatrix;
private int location_viewMatrix;
private int location_skyColour;
public ChunkShader() {
super(vertexFile, fragmentFile);
}
@Override
protected void bindAttributes() {
super.bindAttribute(0, "position");
super.bindAttribute(1, "textureCoords");
super.bindAttribute(2, "normal");
}
@Override
protected void getAllUniformLocations() {
location_transformationMatrix = super.getUniformLocation("transformationMatrix");
location_projectionMatrix = super.getUniformLocation("projectionMatrix");
location_viewMatrix = super.getUniformLocation("viewMatrix");
location_skyColour = super.getUniformLocation("skyColour");
}
public void loadSkyColour(float r, float g, float b) {
super.load3DVector(location_skyColour, new Vector3f(r,g,b));
}
public void loadTransformationMatrix(Matrix4f matrix) {
super.loadMatrix(location_transformationMatrix, matrix);
}
public void loadProjectionMatrix(Matrix4f matrix) {
super.loadMatrix(location_projectionMatrix, matrix);
}
public void loadViewMatrix(Camera camera) {
super.loadMatrix(location_viewMatrix, Maths.createViewMatrix(camera));
}
}

View file

@ -0,0 +1,31 @@
#version 150
in vec2 pass_textureCoords;
in float visibility;
in vec3 surfaceNormal;
out vec4 out_Colour;
uniform sampler2D textureS;
uniform float whiteOffset;
uniform vec3 skyColour;
uniform float shouldFakeIt;
void main(void) {
vec4 texture = texture(textureS, pass_textureCoords);
if(texture.a < 0.5) {
discard;
}
texture.rgb += whiteOffset;
vec3 unitNormal = normalize(surfaceNormal);
float nDot1 = dot(unitNormal, surfaceNormal);
float f = 0.65;
vec3 diffuse = nDot1 * vec3(f,f,f);
out_Colour = vec4(diffuse, 1.0) * texture;
if(shouldFakeIt < 0.5) {
out_Colour = mix(vec4(skyColour,1.0), out_Colour, visibility);
}
}

View file

@ -0,0 +1,47 @@
#version 140
in int position;
in vec2 textureCoords;
in int normal;
out vec2 pass_textureCoords;
out vec3 surfaceNormal;
out float visibility;
uniform mat4 transformationMatrix;
uniform mat4 projectionMatrix;
uniform mat4 viewMatrix;
uniform float shouldFakeIt;
const float density = 0.015;
const float gradient = 1.5;
void main(void) {
int posX = position & 0xFF;
int posY = position >> 8 & 0xFF;
int posZ = position >> 16 & 0xFF;
float nor = normal/100.0f;
vec4 worldPosition = transformationMatrix * vec4(posX,posY,posZ,1.0);
vec4 positionRelativeToCam = viewMatrix * worldPosition;
gl_Position = projectionMatrix * positionRelativeToCam;
pass_textureCoords = textureCoords;
vec3 norm = vec3(nor, nor, nor);
if(shouldFakeIt > 0.5) {
vec3 damn = norm + 1.5;
surfaceNormal = (transformationMatrix * vec4(damn, 0.0)).xyz;
} else {
surfaceNormal = (transformationMatrix * vec4(norm, 0.0)).xyz;
}
float distance = length(positionRelativeToCam.xyz);
visibility = exp(-pow((distance*density), gradient));
visibility = clamp(visibility,0.0,1.0);
}

View file

@ -8,12 +8,15 @@ import org.lwjgl.opengl.GL13;
import org.lwjgl.opengl.GL20;
import org.lwjgl.opengl.GL30;
import org.lwjgl.util.vector.Matrix4f;
import org.lwjgl.util.vector.Vector3f;
import net.oikmo.engine.entity.Camera;
import net.oikmo.engine.entity.Entity;
import net.oikmo.engine.entity.ItemBlock;
import net.oikmo.engine.entity.ItemEntity;
import net.oikmo.engine.entity.Player;
import net.oikmo.engine.models.TexturedModel;
import net.oikmo.engine.renderers.MasterRenderer;
import net.oikmo.toolbox.Maths;
public class EntityRenderer {
@ -31,6 +34,9 @@ public class EntityRenderer {
synchronized(entities) {
for(TexturedModel model : entities.keySet()) {
if(model.getTexture().getTextureID() == MasterRenderer.invisibleTexture) {
continue;
}
shader.start();
shader.loadViewMatrix(camera);
GL30.glBindVertexArray(model.getRawModel().getVaoID());
@ -46,7 +52,22 @@ public class EntityRenderer {
Entity entity = batch.get(i);
Matrix4f transformationMatrix = Maths.createTransformationMatrix(entity.getPosition(), entity.getRotation(), entity.getScale());
Vector3f position = entity.getPosition();
Vector3f rotation = entity.getRotation();
if(entity instanceof Player) {
Vector3f playerModelPosition = ((Player)entity).getModelPosition();
if(playerModelPosition != null) {
position = playerModelPosition;
}
Vector3f playerModelRotation = ((Player)entity).getModelRotation();
if(playerModelRotation != null) {
rotation = playerModelRotation;
}
}
Matrix4f transformationMatrix = Maths.createTransformationMatrix(position, rotation, entity.getScale());
shader.loadTransformationMatrix(transformationMatrix);
shader.loadWhiteOffset(entity.getWhiteOffset()/10);
if(entity instanceof ItemEntity || entity instanceof ItemBlock) {

View file

@ -1,20 +0,0 @@
package net.oikmo.engine.save;
import java.io.Serializable;
import org.lwjgl.util.vector.Vector3f;
public class ChunkSaveData implements Serializable {
private static final long serialVersionUID = 1L;
public int x;
public int z;
public byte[][][] blocks;
public ChunkSaveData(Vector3f vec, byte[][][] blocks) {
this.x = (int)vec.x;
this.z = (int)vec.z;
this.blocks = blocks;
}
}

View file

@ -1,32 +0,0 @@
package net.oikmo.engine.save;
import java.io.Serializable;
import java.util.List;
import net.oikmo.engine.entity.Player;
public class SaveData implements Serializable {
private static final long serialVersionUID = 1L;
public long time;
public long seed;
public ChunkSaveData[] chunks;
public float x, y, z;
public float rotX, rotY, rotZ;
public InventorySaveData cont;
public SaveData(long seed, List<ChunkSaveData> chunks, Player player) {
this.seed = seed;
this.chunks = new ChunkSaveData[chunks.size()];
for(int i = 0; i < chunks.size(); i++) {
this.chunks[i] = chunks.get(i);
}
this.x = player.getPosition().x;
this.y = player.getPosition().y;
this.z = player.getPosition().z;
this.rotX = player.getCamera().getPitch();
this.rotY = player.getCamera().getYaw();
this.rotZ = player.getCamera().getRoll();
this.cont = player.getInventory().saveContainer();
}
}

View file

@ -13,59 +13,9 @@ import net.oikmo.main.Main;
public class SaveSystem {
public static void save(String name, SaveData data) {
try {
File directory = new File(Main.getDir()+ "/saves/");
if(!directory.exists()) {
directory.mkdir();
}
File save = new File(directory + "/" + name + ".dat");
save.delete();
//save.createNewFile();
FileOutputStream fos = new FileOutputStream(save);
GZIPOutputStream gzip = new GZIPOutputStream(fos);
ObjectOutputStream oos = new ObjectOutputStream(gzip);
oos.writeObject(data);
oos.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static SaveData load(String name) {
File directory = new File(Main.getDir()+ "/saves/");
if(directory.exists()) {
File save = new File(directory + "/" + name + ".dat");
if(save.exists()) {
ObjectInputStream obj;
try {
FileInputStream fis = new FileInputStream(save);
GZIPInputStream gzip = new GZIPInputStream(fis);
obj = new ObjectInputStream(gzip);
SaveData data = (SaveData) obj.readObject();
obj.close();
return data;
} catch (IOException | ClassNotFoundException e) {
e.printStackTrace();
}
} else {
return null;
}
} else {
directory.mkdir();
return null;
}
return null;
}
public static void saveServers(ServerListData data) {
try {
File directory = Main.getDir();
File directory = Main.getWorkingDirectory();
File save = new File(directory + "/servers.dat");
save.delete();
@ -82,7 +32,7 @@ public class SaveSystem {
}
public static ServerListData loadServers() {
File directory = Main.getDir();
File directory = Main.getWorkingDirectory();
File save = new File(directory + "/servers.dat");

View file

@ -3,7 +3,7 @@ package net.oikmo.engine.save;
import java.io.Serializable;
import java.util.List;
import net.oikmo.network.client.Server;
import net.oikmo.engine.network.Server;
public class ServerListData implements Serializable {
private static final long serialVersionUID = 1L;

View file

@ -12,7 +12,6 @@ import java.util.Random;
import org.lwjgl.util.vector.Vector3f;
import net.oikmo.engine.DisplayManager;
import net.oikmo.engine.entity.Camera;
import net.oikmo.engine.world.blocks.Block;
import net.oikmo.main.GameSettings;
@ -24,7 +23,6 @@ import paulscode.sound.SoundSystem;
import paulscode.sound.SoundSystemConfig;
import paulscode.sound.SoundSystemException;
import paulscode.sound.codecs.CodecJOrbis;
import paulscode.sound.libraries.LibraryJavaSound;
import paulscode.sound.libraries.LibraryLWJGLOpenAL;
public class SoundMaster {
@ -32,19 +30,21 @@ public class SoundMaster {
private static Map<String, SoundByte> music = new HashMap<>();
private static Map<String, SoundByte> sfx = new HashMap<>();
private static Map<String, SoundEffect> sfxCollection = new HashMap<>();
private static SoundSystem soundSystem = null;
public static SoundSystem soundSystem = null;
private static File customMusic = new File(Main.getResources()+"/custom/music");
private static Thread musicThread;
private static int ticksBeforeMusic;
public static void init() {
ticksBeforeMusic = new Random().nextInt(12000);
//Initalises soundsystem
/**
* Initalises soundsystem along
*/
public static void init() {
ticksBeforeMusic = 12000 + new Random().nextInt(12000);
try {
SoundSystemConfig.addLibrary(LibraryLWJGLOpenAL.class);
SoundSystemConfig.addLibrary(LibraryJavaSound.class);
SoundSystemConfig.setCodec("ogg", CodecJOrbis.class);
} catch( SoundSystemException e ) {
System.err.println("error linking with the plug-ins");
@ -81,14 +81,13 @@ public class SoundMaster {
registerMusic();
registerSFX();
}
public static void doMusic() {
soundSystem.activate("music");
doRandomMusic();
}
/**
* Reads audio files from {@link Main#getResources()}/music/
*/
private static void registerMusic() {
//registerMusicByte("music.jackblack", "jackblock.ogg");
registerMusicByte("music.jackblack", "jackblock.ogg");
registerMusicByte("music.minecraft", "calm1.ogg");
registerMusicByte("music.clark", "calm2.ogg");
@ -135,62 +134,34 @@ public class SoundMaster {
registerSFX("block.wood.break", "dig/wood");
registerSFX("block.glass.break", "dig/glass");
}
private static void doRandomMusic() {
List<SoundByte> bytes = new ArrayList<>();
for(Map.Entry<String, SoundByte> entry : music.entrySet()) {
SoundByte b = entry.getValue();
if(!b.getFileName().contains("menu")) {
bytes.add(entry.getValue());
}
}
Collections.shuffle(bytes);
musicThread = new Thread(new Runnable(){
public void run() {
while(DisplayManager.activeDisplay) {
if(Main.slayyyTick) {
playRandomMusicIfReady();
}
}
}
});
musicThread.setName("Music Player (BG)");
musicThread.start();
}
@SuppressWarnings("static-access")
private static void playRandomMusicIfReady() {
public static void playRandomMusicIfReady() {
if(GameSettings.globalVolume == 0.0F) {
return;
}
if(!soundSystem.playing("music")) {
if(ticksBeforeMusic > 0) {
ticksBeforeMusic--;
return;
}
List<SoundByte> bytes = new ArrayList<>();
for(Map.Entry<String, SoundByte> entry : music.entrySet()) {
SoundByte b = entry.getValue();
if(!b.getFileName().contains("menu")) {
bytes.add(entry.getValue());
} else {
List<SoundByte> bytes = new ArrayList<>();
for(Map.Entry<String, SoundByte> entry : music.entrySet()) {
SoundByte b = entry.getValue();
if(!b.getFileName().contains("menu")) {
bytes.add(entry.getValue());
}
}
}
Collections.shuffle(bytes);
SoundByte music = bytes.get(0);
ticksBeforeMusic = new Random().nextInt(12000) + 12000;
soundSystem.backgroundMusic("music", music.getFileLocation(), music.getFileName(), false);
soundSystem.setVolume("music", GameSettings.globalVolume);
soundSystem.play("music");
Logger.log(LogLevel.INFO, ("Playing {0} ({1})".format("", music.getFileName(),music.getID())));
Collections.shuffle(bytes);
SoundByte music = bytes.get(0);
ticksBeforeMusic = new Random().nextInt(12000) + 12000;
soundSystem.backgroundMusic("music", music.getFileLocation(), music.getFileName(), false);
soundSystem.setVolume("music", GameSettings.globalVolume);
soundSystem.play("music");
Logger.log(LogLevel.INFO, (String.format("Playing %s (%s)", music.getFileName(),music.getID())));
}
}
}
private static float lastVolume = -1;
public static void setVolume() {
@ -300,22 +271,20 @@ public class SoundMaster {
soundSystem.setListenerPosition((float)x, (float)y, (float)z);
soundSystem.setListenerOrientation(lookX, lookY, lookZ, upX, upY, upZ);
}
@SuppressWarnings("deprecation")
public static void cleanUp() {
if(soundSystem != null) {
soundSystem.cleanup();
}
if(musicThread != null) {
musicThread.stop();
musicThread.interrupt();
}
}
@SuppressWarnings("deprecation")
public static void stopMusic() {
if(musicThread != null) {
musicThread.stop();
musicThread.interrupt();
}
soundSystem.stop("music");
}

Some files were not shown because too many files have changed in this diff Show more