Compare commits

...

40 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
Oikmo
b562db6f83 Alpha 0.1.9 2024-05-17 10:07:29 +01:00
Oikmo
860b391993 Ugghh 2024-05-15 21:58:11 +01:00
Oikmo
f58c6da2f7 maths things 2024-05-15 08:24:15 +01:00
Oikmo
dddfc58b2a
how did I miss this
changed project name from "VoxelTest" to BlockBase
2024-05-14 23:30:38 +01:00
Oikmo
a44323f239 bugs 2024-05-14 08:27:42 +01:00
Oikmo
f0eea18497
Update README.md 2024-05-14 07:26:54 +01:00
Oikmo
c6b6a936c2 Alpha 0.1.8 2024-05-13 21:59:00 +01:00
Oikmo
63db0b5c17 Alpha 0.1.7
Check the release to see what the overview of this was
2024-05-12 06:50:24 +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 @@
/**
/**

3
.gitignore vendored
View file

@ -1 +1,2 @@
bin/*
bin/*
doc/*

View file

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>VoxelTest</name>
<name>BlockBase</name>
<comment></comment>
<projects>
</projects>

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

@ -2,7 +2,7 @@
## Voxel game that is NO WAY related to the hit block game with 200 million sales
![image](https://github.com/oikmo/BlockBase/assets/78755068/cb48568d-dc85-4164-9293-b4a9d33db240)
![image](https://github.com/oikmo/BlockBase/assets/78755068/285f2e60-5923-4cff-b67b-063a50d6c4b8)
- Left Click - Destroy selected block
- Right Click - Place block
@ -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

@ -1 +1,58 @@
main.fuckyou=balls
gui.done=Done
gui.delete=Delete
gui.cancel=Cancel
gui.quit=Back to main menu
title.singleplayer=Singleplayer
title.multiplayer=Multiplayer
title.quit=Quit
pause.title=Game menu
pause.players.title=Players
pause.players.identifier=You
options.title=Options
options.fov.low=telescope
options.fov.normal=Normal
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
network.error.noinput=No input given!
network.error.server=Couldn't connect to server!
network.disconnect.l=Login failed.
network.disconnect.p=Wrong protocol! (%s)
network.disconnect.g=disconnected
network.disconnect.u=Unknown
network.disconnect.ux=Unknown (Wrong protocol?)
network.disconnect.n=Network was null!
network.quit.d=Disconnected:
network.quit.k=Kicked:
network.servers.add=Add server
network.servers.refresh=Refresh
network.servers.add.title=Type in server...
network.servers.add.save=Add server
network.servers.add.input.name=Name of server here...
network.servers.add.input.ip=IP of server here...
network.servers.add.quit=Back to server list

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

@ -0,0 +1,20 @@
Jerma my beloved... <3
Hello! My name is email!
I feel so sigma!
Dentist is fucking in my mouth
Nononono the thing in the freezer is definetely not human meat!
If I... If I chopped you up in a meat grinder...
THE DREAM CAST FUCKING SUCKS
Smarties are great, up your urethra.
Everybody say... Loot Get!— OH! Theres Blood in the box! theres blood inside this box!!
Paperairplane… AAAAUGH ICOUGNTMA- THECHARACTERFUCKIN gasp THE CHARACT gasp THE CHARACTER IS LIKE WHYASAFLOSER gasp WHAYAWHA THE CHARACTER- that character is whayuhwhawhat
I'm killing you
If you're good at something, never do it for free!
You little shit, it's not a tumour, okay? I'm gonna strangle your parents!
A jock shocker is like your nuts getting electrocuted... I just realized what I said. Wanna go jock shocking?
Hey, how about you suck a fart out of my ass?
Now, I'm usually not this spicy without a couple of martinis!
No one should ever put cigarettes out on their penis...for any reason.
Name yourself something equally stupid like Dog Shit Burrito.
Hey I'm so good I play sniper I headshot everyone! Gaww yeah Jerma is Mad Part 3 lets put cigarettes out on my dick!
Rats, rats, we are the rats!

View file

@ -1 +1,58 @@
main.fuckyou=balls
gui.done=Done
gui.delete=Delete
gui.cancel=Cancel
gui.quit=Back to main menu
title.singleplayer=Singleplayer
title.multiplayer=Multiplayer
title.quit=Quit
pause.title=Game menu
pause.players.title=Players
pause.players.identifier=You
options.title=Options
options.fov.low=telescope
options.fov.normal=Normal
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
network.error.noinput=No input given!
network.error.server=Couldn't connect to server!
network.disconnect.l=Login failed.
network.disconnect.p=Wrong protocol! (%s)
network.disconnect.g=disconnected
network.disconnect.u=Unknown
network.disconnect.ux=Unknown (Wrong protocol?)
network.disconnect.n=Network was null!
network.quit.d=Disconnected:
network.quit.k=Kicked:
network.servers.add=Add server
network.servers.refresh=Refresh
network.servers.add.title=Type in server...
network.servers.add.save=Add server
network.servers.add.input.name=Name of server here...
network.servers.add.input.ip=IP of server here...
network.servers.add.quit=Back to server list

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.

After

Width:  |  Height:  |  Size: 213 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 213 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 213 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 213 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 213 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 213 KiB

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: 13 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 403 B

After

Width:  |  Height:  |  Size: 5.2 KiB

Before After
Before After

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.4 KiB

After

Width:  |  Height:  |  Size: 223 KiB

Before After
Before After

Binary file not shown.

After

Width:  |  Height:  |  Size: 435 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 752 B

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;
@ -34,8 +34,8 @@ public class Particle extends Entity {
this.xd = this.xd / x * var9 * 0.4F;
this.yd = this.yd / x * var9 * 0.4F + 0.1F;
this.zd = this.zd / x * var9 * 0.4F;
this.uo = (float)Math.random() * 3.0F;
this.vo = (float)Math.random() * 3.0F;
this.uo = (float)Math.random() * 2F;
this.vo = (float)Math.random() * 2F;
this.size = (float)(Math.random() * 0.5D + 0.5D);
this.lifetime = (int)(4.0D / (Math.random() * 0.9D + 0.1D));
this.age = 0;
@ -49,7 +49,7 @@ public class Particle extends Entity {
}
this.yd = (float)((double)this.yd - 0.04D * (double)this.gravity);
this.move(this.xd, this.yd, this.zd, 1);
this.moveWithoutSound(this.xd, this.yd, this.zd, 1);
this.xd *= 0.98F;
this.yd *= 0.98F;
this.zd *= 0.98F;
@ -60,15 +60,15 @@ public class Particle extends Entity {
}
public void render(Tesselator t, float var2, float var3, float var4, float var5, float var6, float var7) {
public void render(Tesselator t, float tickSpeed, float var3, float var4, float var5, float var6, float var7) {
float var8 = ((float)(this.tex % 16) + this.uo / 4.0F) / 16.0F;
float var9 = var8 + 0.999F / 64.0F;
float var9 = var8 + 0.999F / 32.0F;
float var10 = ((float)(this.tex / 16) + this.vo / 4.0F) / 16.0F;
float var11 = var10 + 0.999F / 64.0F;
float var11 = var10 + 0.999F / 32.0F;
float var12 = 0.1F * this.size;
float var13 = getPosition().x * var2;
float var14 = getPosition().y * var2;
float var15 = getPosition().z * var2;
float var13 = getPosition().x * tickSpeed;
float var14 = getPosition().y * tickSpeed;
float var15 = getPosition().z * tickSpeed;
t.vertexUV(var13 - var3 * var12 - var6 * var12, var14 - var4 * var12, var15 - var5 * var12 - var7 * var12, var8, var11);
t.vertexUV(var13 - var3 * var12 + var6 * var12, var14 + var4 * var12, var15 - var5 * var12 + var7 * var12, var8, var10);
t.vertexUV(var13 + var3 * var12 + var6 * var12, var14 + var4 * var12, var15 + var5 * var12 + var7 * var12, var9, var10);

View file

@ -7,7 +7,6 @@ import org.lwjgl.opengl.GL11;
import com.mojang.minecraft.Tesselator;
import net.oikmo.engine.ResourceLoader;
import net.oikmo.engine.entity.Player;
import net.oikmo.engine.renderers.MasterRenderer;
import net.oikmo.toolbox.FastMath;
@ -22,10 +21,10 @@ public final class ParticleEngine {
public final void tick() {
for(int var1 = 0; var1 < this.particles.size(); ++var1) {
Particle var2 = (Particle)this.particles.get(var1);
var2.tick();
Particle particle = (Particle)this.particles.get(var1);
particle.tick();
//System.out.println(particles.size() + " " + var2.remove);
if(var2.remove) {
if(particle.remove) {
this.particles.remove(var1--);
}
}
@ -36,23 +35,26 @@ public final class ParticleEngine {
if(this.particles.size() != 0) {
GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glBindTexture(GL11.GL_TEXTURE_2D, texID);
float var12 = -(FastMath.cos(player.getCamera().getRotation().y * (float)Math.PI / 180.0F));
float var4 = -(FastMath.sin(player.getCamera().getRotation().y * (float)Math.PI / 180.0F));
float var5 = -var4 * FastMath.sin(player.getCamera().getRotation().x * (float)Math.PI / 180.0F);
float var6 = var12 * FastMath.sin(player.getCamera().getRotation().x * (float)Math.PI / 180.0F);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
float lookCosY = -(FastMath.cos(player.getCamera().getRotation().y * (float)Math.PI / 180.0F));
float lookSinY = -(FastMath.sin(player.getCamera().getRotation().y * (float)Math.PI / 180.0F));
float lookSinX = -lookSinY * FastMath.sin(player.getCamera().getRotation().x * (float)Math.PI / 180.0F);
float var6 = lookCosY * FastMath.sin(player.getCamera().getRotation().x * (float)Math.PI / 180.0F);
float var11 = FastMath.cos(player.getCamera().getRotation().x * (float)Math.PI / 180.0F);
Tesselator tess = Tesselator.instance;
tess.begin();
for(int var8 = 0; var8 < this.particles.size(); ++var8) {
Particle particle = (Particle)this.particles.get(var8);
for(int i = 0; i < this.particles.size(); ++i) {
Particle particle = (Particle)this.particles.get(i);
float brightness = 1F * particle.getBrightness();
tess.color(brightness, brightness, brightness);
particle.render(tess, tickSpeed, var12, var11, var4, var5, var6);
particle.render(tess, tickSpeed, lookCosY, var11, lookSinY, lookSinX, var6);
}
tess.end();
GL11.glDisable(GL11.GL_TEXTURE_2D);
GL11.glDisable(GL11.GL_BLEND);
}
}
}

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

@ -35,6 +35,7 @@ public class DisplayManager {
private static int fps, literalfps;
private static long lastFrameTime, lastFPS;
private static float delta;
public static boolean activeDisplay = false;
/**
* Creates window by size (loads cursor and window icon) and sets OpenGL version.
@ -53,6 +54,7 @@ public class DisplayManager {
lastFrameTime = getCurrentTime();
lastFPS = getCurrentTime();
MasterRenderer.getInstance();
activeDisplay = true;
} catch (LWJGLException e) {
Main.error("Display Error!", e);
}
@ -132,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();
@ -166,6 +166,7 @@ public class DisplayManager {
* Destroys the display (not the program)
*/
public static void closeDisplay() {
activeDisplay = false;
Display.destroy();
}

View file

@ -7,9 +7,8 @@ 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.GuiMainMenu;
import net.oikmo.main.gui.GuiOptions;
import net.oikmo.main.gui.GuiPauseMenu;
import net.oikmo.main.gui.GuiSelectWorld;
public class InputManager {
@ -100,7 +99,7 @@ public class InputManager {
}
}
if(Main.network != null && Keyboard.isKeyDown(chatKey) && Main.currentScreen == null) {
if(Main.theNetwork != null && Keyboard.isKeyDown(chatKey) && Main.currentScreen == null) {
Main.currentScreen = new GuiChat();
}
}
@ -116,13 +115,18 @@ public class InputManager {
}
}
if(!(Main.currentScreen instanceof GuiMainMenu) && !(Main.currentScreen instanceof GuiSelectWorld)) {
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

@ -8,6 +8,7 @@ import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Map;
import org.lwjgl.opengl.GL11;
import org.newdawn.slick.opengl.Texture;
import org.newdawn.slick.opengl.TextureLoader;
@ -87,4 +88,16 @@ public class ResourceLoader {
return uiTextures.get(name);
}
public static void cleanUp() {
for(Texture t : uiTextures.values()) {
t.release();
}
uiTextures.clear();
for(int id : textures.values()) {
//GL11.glDeleteTextures(id);
}
textures.clear();
audioFiles.clear();
}
}

View file

@ -2,235 +2,223 @@ 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.particle.Particle;
import com.mojang.minecraft.phys.AABB;
import net.oikmo.engine.DisplayManager;
import net.oikmo.engine.inventory.Item;
import net.oikmo.engine.renderers.MasterRenderer;
import net.oikmo.engine.sound.SoundMaster;
import net.oikmo.engine.world.blocks.Block;
import net.oikmo.main.GameSettings;
import net.oikmo.main.Main;
import net.oikmo.network.shared.PacketPlaySoundAt;
import net.oikmo.toolbox.FastMath;
import net.oikmo.toolbox.Maths;
import net.oikmo.toolbox.MousePicker;
/**
* 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;
private MousePicker picker;
/** 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;
this.prevPosition = position;
this.pitch = rotation.x;
this.roll = rotation.z;
this.picker = new MousePicker(this, MasterRenderer.getInstance().getProjectionMatrix());
this.aabb = new TargetedAABB(new Vector3f());
this.forward = new Vector3f();
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(Vector3f position, float heightOffset) {
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 + heightOffset;
this.prevYaw = yaw;
if(mouseLocked && Main.theWorld != null && Main.thePlayer.tick) {
picker.update();
picker.distance = picker.BASE_DISTANCE;
for(int i = 0; i < picker.BASE_DISTANCE; i++) {
Block block = Main.theWorld.getBlock(picker.getPointRounded(i));
if(block != null) {
picker.distance = i;
break;
}
public void update(Player player) {
if(Keyboard.isKeyDown(Keyboard.KEY_F5)) {
if(!perspectiveLock) {
perspective = !perspective;
perspectiveLock = true;
}
int blockX = (int) this.picker.getPointRounded().x;
int blockY = (int) this.picker.getPointRounded().y;
int blockZ = (int) this.picker.getPointRounded().z;
/**/
if(Mouse.isButtonDown(1)) {
if(this.picker.distance == 0) {
--blockY;
}
if(this.picker.distance == 1) {
++blockY;
}
if(this.picker.distance == 2) {
--blockZ;
}
if(this.picker.distance == 3) {
++blockZ;
}
if(this.picker.distance == 4) {
--blockX;
}
if(this.picker.distance == 5) {
++blockX;
}
if(!mouseClickRight) {
Block block1 = Main.theWorld.getBlock(picker.getPointRounded());
if(Main.inGameGUI.getSelectedItem() != null) {
if(block1 == null) {
if(Main.theWorld.blockHasNeighbours(picker.getPointRounded())) {
int x = (int) picker.getPointRounded().x;
int y = (int) picker.getPointRounded().y;
int z = (int) picker.getPointRounded().z;
SoundMaster.playBlockPlaceSFX(Main.inGameGUI.getSelectedItem(), x, y, z);
if(Main.network != null) {
PacketPlaySoundAt packet = new PacketPlaySoundAt();
packet.place = true;
packet.blockID = Main.inGameGUI.getSelectedItem().getByteType();
packet.x = x;
packet.y = y;
packet.z = z;
Main.network.client.sendTCP(packet);
}
Main.theWorld.setBlock(picker.getPointRounded(), Main.inGameGUI.getSelectedItem());
}
} else {
if(Main.theWorld.blockHasNeighbours(picker.getPointRounded(picker.distance-1))) {
int x = (int) picker.getPointRounded().x;
int y = (int) picker.getPointRounded().y;
int z = (int) picker.getPointRounded().z;
SoundMaster.playBlockPlaceSFX(Main.inGameGUI.getSelectedItem(), x, y, z);
if(Main.network != null) {
PacketPlaySoundAt packet = new PacketPlaySoundAt();
packet.place = true;
packet.blockID = Main.inGameGUI.getSelectedItem().getByteType();
packet.x = x;
packet.y = y;
packet.z = z;
Main.network.client.sendTCP(packet);
}
Main.theWorld.setBlock(picker.getPointRounded(picker.distance-1), Main.inGameGUI.getSelectedItem());
}
}
}
mouseClickRight = true;
}
} else {
mouseClickRight = false;
}
if(Mouse.isButtonDown(0)) {
if(!mouseClickLeft) {
Block block = Main.theWorld.getBlock(picker.getPointRounded());
if(block != null) {
/*Vector3f v = new Vector3f(picker.getPointRounded());
v.y += 1f;
ItemBlock item = new ItemBlock(block, v);
Main.theWorld.addEntity(item);*/
int x = blockX;
int y = blockY;
int z = blockZ;
SoundMaster.playBlockBreakSFX(block, blockX, blockY, blockZ);
for(int px = 0; px < 4; ++px) {
for(int py = 0; py < 4; ++py) {
for(int pz = 0; pz < 4; ++pz) {
float particleX = (float)x + ((float)px) / (float)4;
float particleY = (float)y + ((float)py) / (float)4;
float particleZ = (float)z + ((float)pz) / (float)4;
Particle particle = new Particle(particleX-0.5f, particleY-0.5f, particleZ-0.5f, particleX - (float)x, particleY - (float)y, particleZ - (float)z, block);
Main.theWorld.spawnParticle(particle);
}
}
}
if(Main.network != null) {
PacketPlaySoundAt packet = new PacketPlaySoundAt();
packet.blockID = block.getByteType();
packet.x = x;
packet.y = y;
packet.z = z;
Main.network.client.sendTCP(packet);
}
Main.theWorld.setBlock(new Vector3f(blockX,blockY,blockZ), null);
if(block.getType() == Block.tnt.getType()) {
Main.theWorld.addEntity(new PrimedTNT(new Vector3f(blockX,blockY,blockZ), new Random().nextInt(10)/10f, 0.1f, new Random().nextInt(10)/10f));
}
}
mouseClickLeft = true;
}
} else {
mouseClickLeft = false;
}
if(Mouse.isButtonDown(2)) {
Block toBeSelected = Main.theWorld.getBlock(picker.getPointRounded());
if(toBeSelected != null) {
Main.inGameGUI.setSelectedItem(Item.blockToItem(toBeSelected));
}
}
Block thatBlock = Main.theWorld.getBlock(picker.getPointRounded());
if(thatBlock != null) {
aabb.setPosition(picker.getPointRounded());
shouldRenderAABB = true;
} else {
shouldRenderAABB = false;
}
} 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();
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());
}
mouseClickRight = true;
}
} else {
mouseClickRight = false;
}
this.move();
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;
}
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;
}
}
}
this.move(player);
}
/**
* 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);
this.forward.y = FastMath.sin(pitch);
this.forward.z = FastMath.sin(yaw) * FastMath.cos(pitch);
forward = (Vector3f)forward.normalise();
forward.x *= -1;
forward.y *= -1;
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;
@ -238,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) {
@ -245,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);
}
@ -263,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;
@ -280,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;
@ -291,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;
@ -301,72 +309,153 @@ 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;
float y = this.position.y;
float z = this.position.z;
this.aabb = new AABB(x - 0.5f, y - 0.5f, z - 0.5f, x + 0.5f, y + 0.5f, z + 0.5f);
}
public void setPosition(float x, float y, float z) {
this.position.x = x;
this.position.y = y ;
this.position.z = z;
this.aabb = new AABB(x - 0.5f, y - 0.5f, z - 0.5f, x + 0.5f, y + 0.5f, z + 0.5f);
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;
float y = this.position.y;
float z = this.position.z;
this.aabb = new AABB(x - 0.5f, y - 0.5f,z - 0.5f, x + 0.5f, y + 0.5f,z + 0.5f);
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();
@ -59,18 +63,18 @@ public class Entity {
float x = position.x;
float y = position.y;
float z = position.z;
float w = this.getBBWidth() / 2.0F;
float h = this.getBBHeight() / 2.0F;
this.aabb = new AABB(x - w, y - h, z - w, x + w, y + h, z + w);
float w = this.getBBWidth() / 1.0F;
float h = this.getBBHeight() / 1.0F;
this.aabb = new AABB(x, y, z, x + w, y + h, z + w);
}
public void setPos(float x, float y, float z) {
this.position.x = x;
this.position.y = y;
this.position.z = z;
float w = this.getBBWidth() / 2.0F;
float h = this.getBBHeight() / 2.0F;
this.aabb = new AABB(x - w, y - h, z - w, x + w, y + h, z + w);
float w = this.getBBWidth() / 1.0F;
float h = this.getBBHeight() / 1.0F;
this.aabb = new AABB(x, y, z, x + w, y + h, z + w);
}
/**
@ -83,13 +87,41 @@ public class Entity {
public void move(float xa, float ya, float za, int size) {
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-0.5f);
int posY = (int)(position.y)-1;
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;
float zaOrg = za;
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);
@ -122,36 +154,42 @@ public class Entity {
}
}
this.position.x = (this.aabb.minX + this.aabb.maxX) / 2.0F;
this.position.y = this.aabb.minY + this.heightOffset;
this.position.z = (this.aabb.minZ + this.aabb.maxZ) / 2.0F;
double offsetX = position.x - prevX;
double offsetZ = position.z - prevZ;
distanceWalkedModified += (double)FastMath.sqrt((float) (offsetX * offsetX + offsetZ * offsetZ)) * 0.7D;
int posX = FastMath.floor_double(position.x);
int posY = Maths.roundFloat(position.y)-1;
int posZ = FastMath.floor_double(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.network != null) {
PacketPlaySoundAt packet = new PacketPlaySoundAt();
packet.place = true;
packet.blockID = block.getByteType();
packet.x = posX;
packet.y = posY;
packet.z = posZ;
Main.network.client.sendTCP(packet);
if(this instanceof Player) {
this.position.x = ((this.aabb.minX + this.aabb.maxX) / 2.0F);
this.position.y = this.aabb.minY + this.heightOffset;
this.position.z = ((this.aabb.minZ + this.aabb.maxZ) / 2.0F);
} else {
this.position.x = ((this.aabb.minX + this.aabb.maxX) / 2.0F)-0.5f;
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;
}
/**
@ -185,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);
}
@ -250,9 +335,8 @@ public class Entity {
return scale;
}
public Vector3f getCurrentChunkPosition() {
getCurrentChunk();
return chunkPos;
public ChunkCoordinates getCurrentChunkPosition() {
return Maths.calculateChunkPosition(position);
}
public void resetMotion() {
@ -266,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,23 +4,28 @@ 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;
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 boolean tick = true;
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);
@ -28,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;
@ -55,14 +67,25 @@ 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.network == null) {
resetPos();
if(this.getPosition().y < 0) {
//resetPos();
}
//System.out.println(xa + " " + za);
this.motion.x *= 0.91F;
this.motion.y *= 0.98F;
@ -73,21 +96,41 @@ 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;
}
public void updateCamera() {
if(tick)
camera.update(new Vector3f(getPosition()), heightOffset);
camera.update(this);
}
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

@ -1,73 +1,81 @@
package net.oikmo.engine.entity;
import java.util.Random;
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 {
private int timer = 0;
private boolean actuallyExplode;
public PrimedTNT(Vector3f position, float xa, float ya, float za) {
super(new TexturedModel(CubeModel.getRawModel(Block.tnt),MasterRenderer.currentTexturePack), position, new Vector3f(), 1);
this.setSize(1, 1);
this.setRotation(0.0f, new Random().nextInt(4)*90, 0.0f);
this.heightOffset = 0.5f;
public PrimedTNT(Vector3f position, float xa, float ya, float za, boolean actuallyExplode) {
super(new TexturedModel(CubeModel.getRawModel(Block.tnt),MasterRenderer.currentTexturePack), new Vector3f(position), new Vector3f(), 1);
int x = (int) (position.x);
int y = (int) (position.y);
int z = (int) (position.z);
this.setSize(1f, 1f);
//this.setRotation(0.0f, new Random().nextInt(4)*90, 0.0f);
motion.y = ya;
int x = (int) getPosition().x;
int y = (int) getPosition().y;
int z = (int) getPosition().z;
//this.moveRelative(xa, za, this.isOnGround() ? 0.015F : 0.005F);
SoundMaster.playSFX("entity.tnt.primed");
if(Main.network != null) {
PacketPlaySoundAt packet = new PacketPlaySoundAt();
packet.blockID = -1;
packet.sfxID = "entity.tnt.primed";
packet.x = x;
packet.y = y;
packet.z = z;
Main.network.client.sendTCP(packet);
if(actuallyExplode) {
SoundMaster.playSFX("entity.tnt.primed");
if(Main.theNetwork != null) {
PacketPlaySoundAt packet = new PacketPlaySoundAt();
packet.blockID = -1;
packet.sfxID = "entity.tnt.primed";
packet.x = x;
packet.y = y;
packet.z = z;
Main.theNetwork.client.sendTCP(packet);
}
}
this.actuallyExplode = actuallyExplode;
}
public void tick() {
timer++;
this.motion.y = (float)((double)this.motion.y - 0.008D);
this.move(this.motion.x, this.motion.y, this.motion.z,1);
this.moveWithoutSound(this.motion.x, this.motion.y, this.motion.z,1);
int x = (int) getPosition().x;
int y = (int) getPosition().y;
int z = (int) getPosition().z;
//System.out.println((timer % 30f)/30f);
if((timer % 45f)/45f <= 0.5f) {
this.setWhiteOffset(15);
} else {
this.setWhiteOffset(0);
}
if(getPosition().y < 0) {
remove = true;
}
if(timer >= 60*5 && !remove) {
Main.theWorld.createRadiusFromBlock(5, null, x, y, z);
SoundMaster.playSFX("entity.generic.explode");
if(Main.network != null) {
PacketPlaySoundAt packet = new PacketPlaySoundAt();
packet.blockID = -1;
packet.sfxID = "entity.generic.explode";
packet.x = x;
packet.y = y;
packet.z = z;
Main.network.client.sendTCP(packet);
if(actuallyExplode) {
Main.theWorld.createRadiusFromBlock(5, null, x, y, z);
SoundMaster.playSFX("entity.generic.explode");
if(Main.theNetwork != null) {
PacketPlaySoundAt packet = new PacketPlaySoundAt();
packet.blockID = -1;
packet.sfxID = "entity.generic.explode";
packet.x = x;
packet.y = y;
packet.z = z;
Main.theNetwork.client.sendTCP(packet);
}
}
remove = true;
}
}

View file

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

View file

@ -3,32 +3,54 @@ 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;
Main.network.currentlyShownMessages.add(this);
Main.theNetwork.currentlyShownMessages.add(this);
if(Main.currentScreen instanceof GuiChat) {
((GuiChat)Main.currentScreen).updateMessages();
}
}
/**
* Every tick it counts down (decrements {@link #timer}) and removes itself from
*/
public void tick() {
timer--;
if(timer <= 0) {
Main.network.currentlyShownMessages.remove(this);
Main.theNetwork.currentlyShownMessages.remove(this);
}
}
/**
* 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

@ -3,6 +3,8 @@ package net.oikmo.engine.gui;
import java.awt.Font;
import java.awt.FontFormatException;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.GL11;
@ -21,7 +23,9 @@ import net.oikmo.engine.gui.component.slick.GuiComponent;
import net.oikmo.main.Main;
public class Gui {
private static Map<Integer, UnicodeFont> fontSizes = new HashMap<>();
public static GuiComponent current = null;
public static boolean lockedRightNow = false;
@ -31,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;
@ -40,10 +44,8 @@ public class Gui {
try {
awtFont = Font.createFont(Font.TRUETYPE_FONT, Main.class.getResourceAsStream("/assets/fonts/minecraft.ttf"));
} catch (FontFormatException | IOException e) {}
ColorEffect effect = new ColorEffect();
font = new UnicodeFont(awtFont.deriveFont(Font.PLAIN, fontSize));
font.getEffects().add(effect);
font.getEffects().add(new ColorEffect());
font.addAsciiGlyphs();
try {
@ -52,6 +54,8 @@ public class Gui {
e1.printStackTrace();
}
fontSizes.put(fontSize, font);
guiAtlas = new Image(ResourceLoader.loadUITexture("ui/gui"));
cursor = new Cursor();
}
@ -64,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);
}
@ -137,22 +143,20 @@ public class Gui {
}
protected void drawShadowString(float x, float y, String text) {
drawShadowString(null, Color.white, x, y, text);
drawShadowString(font, Color.white, x, y, text);
}
protected void drawShadowString(Color c, float x, float y, String text) {
setupGL();
font.drawString(x+2, y+2, text, Color.gray);
font.drawString(x, y, text, c);
dropGL();
drawShadowString(font, c, x, y, text);
}
protected void drawShadowString(UnicodeFont font, int x, int y, String text) {
drawShadowString(font, Color.white, x, y, text);
}
protected void drawShadowString(UnicodeFont font, Color c, float x, float y, String text) {
protected void drawShadowString(UnicodeFont f, Color c, float x, float y, String text) {
setupGL();
UnicodeFont font = f;
if(font == null) {
font = Gui.font;
}
@ -163,16 +167,23 @@ public class Gui {
dropGL();
}
@SuppressWarnings("unchecked")
protected UnicodeFont calculateFont(float fontSize) {
UnicodeFont font = new UnicodeFont(awtFont.deriveFont(fontSize));
font.getEffects().add(new ColorEffect());
protected UnicodeFont calculateFont(int fontSize) {
UnicodeFont font = fontSizes.get(fontSize);
font.addAsciiGlyphs();
try {
font.loadGlyphs();
} catch (SlickException e1) {
e1.printStackTrace();
if(font == null) {
font = new UnicodeFont(awtFont.deriveFont(Font.PLAIN, fontSize));
font.getEffects().add(new ColorEffect());
font.addAsciiGlyphs();
try {
font.loadGlyphs();
} catch (SlickException e1) {
e1.printStackTrace();
}
fontSizes.put(fontSize, font);
}
return font;
}
@ -182,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,13 +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;
@ -31,7 +52,7 @@ public class BlockSlot extends Gui implements GuiComponent {
float mouseY = Math.abs(Display.getHeight()-Mouse.getY());
if(y + height/2 > mouseY && y-height/2 < mouseY && x + width/2 > mouseX && x-width/2 < mouseX) {
isHovering = true;
if(Mouse.isButtonDown(0)) {
if(!lockButton) {
SoundMaster.playSFX("ui.button.click");
@ -41,17 +62,38 @@ public class BlockSlot extends Gui implements GuiComponent {
} else {
lockButton = false;
}
} else {
isHovering = false;
}
if(isHovering && !lockedRightNow && currentlyHoveringSlot != this) {
currentlyHoveringSlot = this;
lockedRightNow = true;
}
if(!isHovering && lockedRightNow && currentlyHoveringSlot == this) {
currentlyHoveringSlot = null;
lockedRightNow = false;
}
drawSquareFilled(Color.black, x-(width/2), y-(height/2), width, height);
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;
}
@ -59,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

@ -18,6 +18,21 @@ public class Cursor extends Gui implements GuiComponent {
public void tick() {
x = Mouse.getX() + 10;
if(BlockSlot.currentlyHoveringSlot != null) {
String name = BlockSlot.currentlyHoveringSlot.getItem().getName();
int width = font.getWidth(name) + 12;
int nameHeight = font.getHeight(name);
int height = nameHeight + 4;
y = Math.abs(Display.getHeight()-Mouse.getY()) -2-height;
this.drawSquareFilled(x, y, width, height+4);
this.drawSquare(Color.white, 5f, x, y, width, height+4);
this.drawString(x+4, y+2, name);
}
if(InventorySlot.currentlyHoveringSlot != null) {
String name = InventorySlot.currentlyHoveringSlot.getSlot().getItem().getName()+ " (" + InventorySlot.currentlyHoveringSlot.getSlot().getCurrentAmount() + ")";
List<String> strings = splitEqually(InventorySlot.currentlyHoveringSlot.getSlot().getItem().getDescription(), 16);

View file

@ -26,6 +26,7 @@ public class GuiChatBar extends Gui implements GuiComponent {
current = this;
}
}
this.inputText = "";
}
@Override

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

@ -0,0 +1,297 @@
package net.oikmo.engine.gui.component.slick;
import java.awt.image.BufferedImage;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.RandomAccessFile;
import java.net.Socket;
import java.nio.channels.FileLock;
import java.util.HashMap;
import java.util.Map;
import javax.imageio.ImageIO;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.Display;
import org.newdawn.slick.Color;
import org.newdawn.slick.Image;
import org.newdawn.slick.UnicodeFont;
import org.newdawn.slick.opengl.Texture;
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.toolbox.Maths;
public class GuiServer extends Gui implements GuiComponent {
private static Map<String, File> tempFiles = new HashMap<>();
private Image trashClosed = new Image(ResourceLoader.loadUITexture("ui/trash")).getSubImage(0, 0, 16, 16);
private Image trashOpen = new Image(ResourceLoader.loadUITexture("ui/trash")).getSubImage(17, 0, 16, 16);
private GuiCommand command;
private float x, y, width, height;
private boolean lockButton = false;
private boolean isHovering = false;
private GuiButton trashCan;
private Server server;
private Thread textureThread;
private Texture image;
private File imageFile;
private boolean useImage = false;
private String playerCount = null;
private int playerFontSize = (int) (Gui.fontSize/1.5f);
private int serverFontSize = (int) (Gui.fontSize/1.25f);
private UnicodeFont playersFontSize = this.calculateFont(playerFontSize);
private UnicodeFont serversFontSize = this.calculateFont(serverFontSize);
public GuiServer(float x, float y, float width, float height, Server server) {
this.server = server;
this.x = x;
this.y = y;
this.width = width;
this.height = height;
components.add(this);
trashCan = new GuiButton(trashClosed, trashOpen, x+(width/2)-(height/2), y-(height/2)+(height/2), height-6, height-6, "");
trashCan.setGuiCommand(new GuiCommand(){
public void invoke() {
GuiServerList.servers.remove(server);
Gui.cleanUp();
}
public void update() {
x = x+(width/2)-(height/2)-6;
y = y-(height/2)+(height/2);
}
});
refresh();
}
Socket socket;
InputStream in;
DataOutputStream dOut;
BufferedReader br;
public void refresh() {
textureThread = new Thread(new Runnable() {
public void run() {
try {
socket = new Socket(server.getIP(), 25555);
InputStream in = socket.getInputStream();
DataOutputStream dOut = new DataOutputStream(socket.getOutputStream());
br = new BufferedReader(new InputStreamReader(in));
// request image info
dOut.writeByte(2);
dOut.flush(); // Send off the data
byte[] b = new byte[30];
int len = in.read(b);
int filesize = Integer.parseInt(new String(b).substring(0, len));
byte[] imgBytes = Maths.readExactly(in, filesize);
ByteArrayInputStream bais = new ByteArrayInputStream(imgBytes);
BufferedImage img = ImageIO.read(bais);
ImageIO.write(img, "PNG", imageFile);
dOut.writeByte(-1);
dOut.flush(); // Send off the data
socket.close();
useImage = true;
socket = null;
imageFile.deleteOnExit();
} catch (Exception e) {
//StringWriter writer = new StringWriter();
e.printStackTrace();
//System.out.println(writer.toString() + " " + server.getIP());*/
socket = null;
useImage = true;
}
imageFile.deleteOnExit();
}
});
if(playerCount == null) {
playerCount = "Failed to get players...";
}
if(tempFiles.get(server.getIP()) == null) {
try {
imageFile = File.createTempFile("tmp-", ".tmp");
tempFiles.put(server.getIP(), imageFile);
textureThread.start();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else {
imageFile = tempFiles.get(server.getIP());
useImage = true;
textureThread = null;
System.gc();
}
new Thread(new Runnable() {
public void run() {
try {
Thread.sleep(500);
socket = new Socket(server.getIP(), 25555);
InputStream in = socket.getInputStream();
DataOutputStream dOut = new DataOutputStream(socket.getOutputStream());
br = new BufferedReader(new InputStreamReader(in));
// request players
dOut.writeByte(1);
dOut.flush(); // Send off the data
int playersOnline = Integer.parseInt(br.readLine());
if(playersOnline == 0) {
playerCount = "No players!";
} else if(playersOnline == 1) {
playerCount = "1 player";
} else {
playerCount = playersOnline + " players";
}
in.close();
br.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}).start();
imageFile.deleteOnExit();
image = ResourceLoader.loadUITexture("pack");
}
private Color nothing = new Color(0,0,0,255/4);
private Color highlight = new Color(0,0,0,255/2);
private Color outline = new Color(255,255,255,255/2);
public void tick(boolean delete, boolean shouldTicky) {
if(useImage) {
if(imageFile != null && imageFile.exists() && imageFile.length() != 0) {
try {
image = TextureLoader.getTexture("PNG", new FileInputStream(imageFile), Image.FILTER_NEAREST);
} catch (Exception e) {
e.printStackTrace();
}
try {
@SuppressWarnings("resource")
FileLock fl = new RandomAccessFile(imageFile, "rwd").getChannel().tryLock();
fl.release();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
imageFile.deleteOnExit();
}
} else {
image = ResourceLoader.loadUITexture("pack");
}
useImage = false;
}
float mouseX = Mouse.getX();
float mouseY = Math.abs(Display.getHeight()-Mouse.getY());
Color base = nothing;
if(y + height/2 > mouseY && y-height/2 < mouseY && x + width/2 > mouseX && x-width/2 < mouseX) {
base = highlight;
isHovering = true;
if(Mouse.isButtonDown(0) && shouldTicky) {
if(command != null && !trashCan.isHovering()) {
if(!lockButton) {
if(!lockedRightNow && current != this) {
lockedRightNow = true;
current = this;
command.invoke();
SoundMaster.playSFX("ui.button.click");
}
}
}
} else {
lockButton = false;
}
} else {
isHovering = false;
base = nothing;
if(lockedRightNow && current == this) {
lockedRightNow = false;
current = null;
}
}
this.drawSquareFilled(base, x-(width/2), y-(height/2), width, height);
this.drawSquare(isHovering ? Color.white : outline, 1, x-(width/2), y-(height/2), width, height);
if(!delete) {
if(image != null)
this.drawTexture(image, x+(width/2)-(height/2), y-(height/2)+(height/2), height-6, height-6);
} else{
trashCan.tick();
}
//Color c = isHovering ? new Color(0.9f,0.9f,0.1f,1f) : Color.white;
drawShadowStringCentered(Color.white, x-(width/2)+(font.getWidth(server.getName())/2)+5, y-(height/2)+(playerFontSize/2)+5, server.getName());
drawShadowStringCentered(serversFontSize, Color.lightGray, x-(width/2)+(serversFontSize.getWidth(server.getIP())/2)+5, y-(height/2)+(serverFontSize/2)+10+serverFontSize, server.getIP());
drawShadowStringCentered(playersFontSize, playerCount.contains("Failed") ? Color.red : Color.yellow, x-(width/2)+(playersFontSize.getWidth(playerCount)/2)+5, y+(height/2)-(playerFontSize/2), playerCount);
}
public void updateComponent() {
command.update();
this.x = command.getX();
this.y = command.getY();
}
@Override
public void onCleanUp() {
if(textureThread != null) {
textureThread.interrupt();
textureThread = null;
}
imageFile = null;
System.gc();
components.remove(this);
}
public boolean isHovering() {
return isHovering;
}
public void setPosition(float x, float y) {
this.x = x;
this.y = y;
}
public void setGuiCommand(GuiCommand command) {
this.command = command;
}
@Override
public void tick() {}
}

View file

@ -12,8 +12,8 @@ import net.oikmo.engine.sound.SoundMaster;
public class GuiButton extends Gui implements GuiComponent {
private static Image normalTexture;
private static Image hoveredTexture;
private Image normalTexture;
private Image hoveredTexture;
private Image texture = normalTexture;
@ -26,14 +26,19 @@ public class GuiButton extends Gui implements GuiComponent {
private boolean isHovering = false;
private void onInit() {
if(normalTexture == null) {
normalTexture = Gui.guiAtlas.getSubImage(0, 66, 200, 20);
normalTexture.clampTexture();
}
if(hoveredTexture == null) {
hoveredTexture = Gui.guiAtlas.getSubImage(0, 86, 200, 20);
normalTexture.clampTexture();
try {
if(normalTexture == null) {
normalTexture = Gui.guiAtlas.getSubImage(0, 66, 200, 20);
normalTexture.clampTexture();
}
if(hoveredTexture == null) {
hoveredTexture = Gui.guiAtlas.getSubImage(0, 86, 200, 20);
normalTexture.clampTexture();
}
} catch(Exception e) {
}
}
public GuiButton(float x, float y, float width, float height, String text, GuiCommand command) {
@ -56,6 +61,20 @@ public class GuiButton extends Gui implements GuiComponent {
this.height = height;
components.add(this);
}
public GuiButton(Image normalTexture, Image hoveredTexture, float x, float y, float width, float height, String text) {
this.normalTexture = normalTexture;
this.hoveredTexture = hoveredTexture;
this.normalTexture.setFilter(Image.FILTER_NEAREST);
this.hoveredTexture.setFilter(Image.FILTER_NEAREST);
this.text = text;
this.x = x;
this.y = y;
this.width = width;
this.height = height;
components.add(this);
}
@Override
public void tick() {
@ -66,20 +85,24 @@ public class GuiButton extends Gui implements GuiComponent {
texture = hoveredTexture;
isHovering = true;
if(Mouse.isButtonDown(0)) {
if(command != null) {
if(!lockButton) {
if(!lockedRightNow && current != this) {
lockedRightNow = true;
current = this;
SoundMaster.playSFX("ui.button.click");
command.invoke();
}
if(!lockButton) {
if(!lockedRightNow && current != this) {
lockedRightNow = true;
current = this;
SoundMaster.playSFX("ui.button.click");
command.invoke();
}
} else {
lockedRightNow = false;
current = null;
}
} else {
lockedRightNow = false;
current = null;
lockButton = false;
}
} else {
lockButton = false;
isHovering = false;
texture = normalTexture;
if(lockedRightNow && current == this) {

View file

@ -43,20 +43,6 @@ public class GuiSlider extends Gui implements GuiComponent {
}
}
public GuiSlider(float x, float y, float width, float height, String text, GuiCommand command) {
onInit();
this.text = text;
this.command = command;
this.x = x;
this.y = y;
this.width = width;
this.height = height;
this.width2 = 8;
this.x2 = x-(width/2)+width2/2;
components.add(this);
}
public GuiSlider(float x, float y, float width, float height, String text) {
onInit();
this.text = text;
@ -92,7 +78,7 @@ public class GuiSlider extends Gui implements GuiComponent {
}
}
command.invoke(sliderValue);
}
} else {
lockButton = false;
@ -105,7 +91,7 @@ public class GuiSlider extends Gui implements GuiComponent {
if (grabbing && Mouse.isButtonDown(0)) {
isHovering = true;
command.invoke(sliderValue);
float handleHalfWidth = width2 / 2;
float minSliderX = x - (width / 2) + handleHalfWidth;
@ -181,5 +167,14 @@ public class GuiSlider extends Gui implements GuiComponent {
return text;
}
public void setText(String text) {
this.text = text;
}
public float getValue() {
return sliderValue;
}
}

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,14 +105,21 @@ public class GuiTextField extends Gui implements GuiComponent {
if(grabbed) {
handleKeyboardInput();
} else {
ticks = 0;
showMarker = false;
}
drawTexture(backgroundTexture, x, y, width, height);
if(inputText.length() == 0 && current != this) {
drawShadowString(Color.darkGray, (x+3)-width/2, y-font.getHeight(backgroundText)/2, backgroundText);
drawShadowString(Color.darkGray, (x+3)-width/2, y-fontSize/2, backgroundText);
} else {
drawShadowString((x+3)-width/2, y-font.getHeight(inputText)/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,56 +17,58 @@ 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(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)
new Vector3f(1f,0f,1f),
new Vector3f(1f,0f,0f),
new Vector3f(1f,1f,0f),
new Vector3f(1f,1f,0f),
new Vector3f(1f,1f,1f),
new Vector3f(1f,0f,1f),
};
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)
new Vector3f(0f,1f,0f),
new Vector3f(0f,0f,0f),
new Vector3f(0f,0f,1f),
new Vector3f(0f,0f,1f),
new Vector3f(0f,1f,1f),
new Vector3f(0f,1f,0f)
};
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)
new Vector3f(0f,1f,1f),
new Vector3f(1f,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(-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)
new Vector3f(0f,0f,1f),
new Vector3f(0f,0f,0f),
new Vector3f(1f,0f,0f),
new Vector3f(1f,0f,0f),
new Vector3f(1f,0f,1f),
new Vector3f(0f,0f,1f)
};
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)
new Vector3f(0f,1f,1f),
new Vector3f(0f,0f,1f),
new Vector3f(1f,0f,1f),
new Vector3f(1f,0f,1f),
new Vector3f(1f,1f,1f),
new Vector3f(0f,1f,1f)
};
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)
new Vector3f(0f,1f,0f),
new Vector3f(1f,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;
@ -98,12 +100,12 @@ public class CubeModel {
1f, 1f, 1f,
1f, 1f, 1f,
0.5f, 0.5f, 0.5f,
0.5f, 0.5f, 0.5f,
0.5f, 0.5f, 0.5f,
0.5f, 0.5f, 0.5f,
0.5f, 0.5f, 0.5f,
0.5f, 0.5f, 0.5f,
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,
@ -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

@ -0,0 +1,23 @@
package net.oikmo.engine.network;
import java.io.Serializable;
public class Server implements Serializable {
private static final long serialVersionUID = 1L;
private String ip;
private String name;
public Server(String name, String ip) {
this.ip = ip;
this.name = name;
}
public String getIP() {
return ip;
}
public String getName() {
return name;
}
}

View file

@ -1,6 +1,5 @@
package net.oikmo.network.client;
package net.oikmo.engine.network.client;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@ -14,35 +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.world.chunk.MasterChunk;
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.PacketGameOver;
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.PacketUpdateChunk;
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.Logger.LogLevel;
import net.oikmo.toolbox.Maths;
import net.oikmo.toolbox.properties.OptionsHandler;
public class NetworkHandler {
@ -65,15 +68,18 @@ 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() {
private static void registerKryoClasses() {
kryo.register(LoginRequest.class);
kryo.register(LoginResponse.class);
kryo.register(Message.class);
kryo.register(OtherPlayer.class);
kryo.register(float[].class);
kryo.register(byte[].class);
kryo.register(PacketChunk.class);
kryo.register(PacketRequestChunk.class);
kryo.register(PacketModifyChunk.class);
kryo.register(PacketUpdateX.class);
kryo.register(PacketUpdateY.class);
kryo.register(PacketUpdateZ.class);
@ -81,7 +87,6 @@ public class NetworkHandler {
kryo.register(PacketUpdateRotY.class);
kryo.register(PacketUpdateRotZ.class);
kryo.register(PacketWorldJoin.class);
kryo.register(PacketUpdateChunk.class);
kryo.register(PacketAddPlayer.class);
kryo.register(PacketRemovePlayer.class);
kryo.register(PacketUserName.class);
@ -89,7 +94,6 @@ public class NetworkHandler {
kryo.register(PacketGameOver.class);
kryo.register(PacketTickPlayer.class);
kryo.register(PacketUpdateWithheldBlock.class);
kryo.register(PacketRequestChunk.class);
kryo.register(PacketSavePlayerPosition.class);
kryo.register(PacketPlaySoundAt.class);
kryo.register(PacketChatMessage.class);
@ -102,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);
}
@ -132,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);
@ -152,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);
@ -171,19 +175,39 @@ 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, "Unknown (Wrong protocol?)");
Main.disconnect(false, Main.lang.translateKey("network.disconnect.ux"));
return;
}
if(Main.theWorld != null) {
@ -192,64 +216,70 @@ public class NetworkHandler {
}
}
if(player.c != null) {
if(players.containsKey(player.c.getID())) {
players.remove(player.c.getID());
}
}
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);
}
}
public void updateChunk(MasterChunk master) {
PacketUpdateChunk packet = new PacketUpdateChunk();
packet.add = false;
try {
packet.data = Maths.compressObject(master.getChunk().blocks);
} catch (IOException e) {}
packet.x = master.getOrigin().x;
packet.z = master.getOrigin().z;
client.sendUDP(packet);
}
public void updateChunk(Vector3f position, Block block, boolean refresh) {
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 {
Main.thePlayer.tick = false;
@ -257,7 +287,7 @@ public class NetworkHandler {
client.start();
client.connect(timeout, ip, tcpPort, udpPort);
client.addListener(new PlayerClientListener());
players = new HashMap<Integer, OtherPlayer>();
LoginRequest request = new LoginRequest();
request.setUserName(player.userName);
request.PROTOCOL = NetworkHandler.NETWORK_PROTOCOL;
@ -269,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

@ -0,0 +1,344 @@
package net.oikmo.engine.network.client;
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.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 {
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));
} else {
Main.disconnect(false, Main.lang.translateKey("network.disconnect.l"));
}
Logger.log(LogLevel.WARN,"Login failed");
}
}
if(object instanceof PacketAddPlayer){
PacketAddPlayer packet = (PacketAddPlayer) object;
OtherPlayer newPlayer = new OtherPlayer();
if(Main.theNetwork == null) {
System.out.println("return at PacketAddPlayer");
return;
} else {
if(!Main.theNetwork.players.containsKey(packet.id)) {
Main.theNetwork.players.put(packet.id, newPlayer);
}
}
}
else if(object instanceof PacketRemovePlayer){
PacketRemovePlayer packet = (PacketRemovePlayer) object;
if(packet.id == Main.theNetwork.client.getID()) {
Main.theNetwork.disconnect();
Main.disconnect(packet.kick, packet.message);
} else {
if(Main.thePlayer != null) {
if(Main.theNetwork.players.get(packet.id) != null && Main.theNetwork.players.get(packet.id).userName != null) {
if(!Main.theNetwork.players.get(packet.id).userName.contentEquals(Main.theNetwork.player.userName)) {
Main.theNetwork.rawMessages.add(new ChatMessage(Main.theNetwork.players.get(packet.id).userName + " left the game", true));
if(Main.currentScreen instanceof GuiChat) {
((GuiChat)Main.currentScreen).updateMessages();
}
}
}
}
Main.theNetwork.players.remove(packet.id);
}
}
else if(object instanceof PacketUserName){
PacketUserName packet = (PacketUserName) object;
if(Main.theNetwork == null) {
System.out.println("return at PacketUserName");
return;
} else if(Main.theNetwork.players == null) {
Main.theNetwork.players = new HashMap<>();
}
if(!Main.theNetwork.players.containsKey(packet.id) && packet.id != Main.theNetwork.client.getID()) {
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)) {
Main.theNetwork.rawMessages.add(new ChatMessage(packet.userName + " joined the game", true));
if(Main.currentScreen instanceof GuiChat) {
((GuiChat)Main.currentScreen).updateMessages();
}
if(Main.theNetwork.players.get(packet.id).userName == null) {
Main.theNetwork.players.get(packet.id).userName = packet.userName;
if(image != null) {
p.buffer = buf;
}
}
}
}
}
} 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)) {
Main.theNetwork.rawMessages.add(new ChatMessage(packet.userName + " joined the game", true));
if(Main.currentScreen instanceof GuiChat) {
((GuiChat)Main.currentScreen).updateMessages();
}
if(Main.theNetwork.players.get(packet.id).userName == null) {
Main.theNetwork.players.get(packet.id).userName = packet.userName;
if(image != null) {
p.buffer = buf;
}
}
}
}
}
}
}
else if(object instanceof PacketUpdateX){
PacketUpdateX packet = (PacketUpdateX) object;
if(Main.theNetwork.players.get(packet.id) != null) {
Main.theNetwork.players.get(packet.id).x = packet.x;
} else {
requestInfo(connection);
}
}
else if(object instanceof PacketUpdateY){
PacketUpdateY packet = (PacketUpdateY) object;
if(Main.theNetwork.players.get(packet.id) != null) {
Main.theNetwork.players.get(packet.id).y = packet.y;
} else {
requestInfo(connection);
}
}
else if(object instanceof PacketUpdateZ){
PacketUpdateZ packet = (PacketUpdateZ) object;
if(Main.theNetwork.players.get(packet.id) != null) {
Main.theNetwork.players.get(packet.id).z = packet.z;
} else {
requestInfo(connection);
}
}
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 {
requestInfo(connection);
}
}
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;
} else {
requestInfo(connection);
}
}
else if(object instanceof PacketUpdateRotZ){
PacketUpdateRotZ packet = (PacketUpdateRotZ) object;
if(Main.theNetwork.players.get(packet.id) != null) {
Main.theNetwork.players.get(packet.id).rotZ = packet.z;
} else {
requestInfo(connection);
}
}
else if(object instanceof PacketUpdateWithheldBlock) {
PacketUpdateWithheldBlock packet = (PacketUpdateWithheldBlock) object;
if(Main.theNetwork.players.get(packet.id) != null) {
Main.theNetwork.players.get(packet.id).block = packet.block;
} else {
requestInfo(connection);
}
}
else if(object instanceof PacketChunk) {
PacketChunk packet = (PacketChunk) object;
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) {
PacketModifyChunk packet = (PacketModifyChunk) object;
Vector3f blockPos = new Vector3f(packet.x,packet.y,packet.z);
Block block = Block.getBlockFromOrdinal(packet.block);
if(packet.refresh) {
theWorld.setBlockNoNet(blockPos, block);
} else {
theWorld.setBlockNoUpdateNoNet(blockPos, block);
}
}
else if(object instanceof PacketWorldJoin) {
PacketWorldJoin packet = (PacketWorldJoin) object;
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);
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);
if(block != null) {
if(packet.place) {
SoundMaster.playBlockPlaceSFX(block, packet.x, packet.y, packet.z);
} else {
SoundMaster.playBlockBreakSFX(block, packet.x, packet.y, packet.z);
}
} else {
if(packet.sfxID != null) {
SoundMaster.playSFX(packet.sfxID);
}
}
}
else if(object instanceof PacketChatMessage) {
PacketChatMessage packet = (PacketChatMessage) object;
Main.theNetwork.rawMessages.add(new ChatMessage(packet.message, false));
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();
}
}
}
private void requestInfo(Connection connection) {
if(!Main.theNetwork.players.keySet().contains(connection.getID())) {
//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

@ -0,0 +1,8 @@
package net.oikmo.engine.network.packet;
public class PacketChunk {
public int id;
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

@ -0,0 +1,10 @@
package net.oikmo.engine.network.packet;
public class PacketModifyChunk {
public int id;
public boolean refresh;
public int x;
public int y;
public int z;
public byte block;
}

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 {

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