Compare commits

..

No commits in common. "main" and "a0.1.9" have entirely different histories.

View file

@ -15,13 +15,14 @@
<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-Client/libraries/native/windows"/>
<attribute name="org.eclipse.jdt.launching.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY" value="BlockBase/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"/>

View file

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

2
.gitignore vendored
View file

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

View file

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

View file

@ -1,7 +1,12 @@
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
View file

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

View file

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

View file

@ -13,24 +13,12 @@ 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.fov.high=QUAKE FOV!!!
options.volume=Volume
options.distance=View Distance
options.distance.tiny=TINY
options.distance.small=SMALL
options.distance.normal=NORMAL
options.distance.far=FAR
options.fov=FOV
inventory.title=Blocks
world.create.superflat=Superflat
world.create.seed=Seed here...
world.create=Create world
world.select.create=Create new world...
network.connecting=Connecting

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

View file

@ -0,0 +1,100 @@
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.

After

Width:  |  Height:  |  Size: 86 KiB

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -13,24 +13,12 @@ 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.fov.high=QUAKE FOV!!!
options.volume=Volume
options.distance=View Distance
options.distance.tiny=TINY
options.distance.small=SMALL
options.distance.normal=NORMAL
options.distance.far=FAR
options.fov=FOV
inventory.title=Blocks
world.create.superflat=Superflat
world.create.seed=Seed here...
world.create=Create world
world.select.create=Create new world...
network.connecting=Connecting

View file

@ -1,49 +0,0 @@
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,79 +136,4 @@ 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!
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.
Now with friends!

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

View file

Before

Width:  |  Height:  |  Size: 81 B

After

Width:  |  Height:  |  Size: 81 B

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 223 KiB

After

Width:  |  Height:  |  Size: 210 KiB

Before After
Before After

View file

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

View file

@ -1,34 +1,14 @@
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;
@ -38,13 +18,6 @@ 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;
@ -78,15 +51,7 @@ 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;
@ -96,12 +61,7 @@ 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) {
@ -129,11 +89,6 @@ 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) {
@ -161,11 +116,6 @@ 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) {
@ -193,20 +143,10 @@ public class AABB {
}
}
/**
* Returns whether the given bounding box intersects with this one
* @param c other bounding box
* @return {@link Boolean}
*/
public boolean intersects(AABB c) {
return c.maxX > this.minX && c.minX < this.maxX ? (c.maxY > this.minY && c.minY < this.maxY ? c.maxZ > this.minZ && c.minZ < this.maxZ : false) : false;
}
/** Moves this bounding box by specified vector
* @param xa X to move by
* @param ya Y to move by
* @param za Z to move by
*/
public void move(float xa, float ya, float za) {
this.minX += xa;
this.minY += ya;

View file

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

View file

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

View file

@ -20,6 +20,7 @@ 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;
@ -43,6 +44,34 @@ 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);
@ -65,6 +94,15 @@ 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);
@ -89,15 +127,6 @@ 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();
@ -149,17 +178,15 @@ public class Loader {
GL20.glVertexAttribPointer(attributeNumber, dimensions, GL11.GL_FLOAT, false, 0, 0);
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
}
private static void storeDataInAttributeList(int[] data, int attributeNumber, int dimensions) {
private static void bindIndicesBuffer(int[] indices) {
int vboID = GL15.glGenBuffers();
vbos.add(vboID);
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);
GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vboID);
IntBuffer buffer = storeDataInIntBuffer(indices);
GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, buffer, GL15.GL_STATIC_DRAW);
}
private static IntBuffer storeDataInIntBuffer(int[] data) {
IntBuffer buffer = BufferUtils.createIntBuffer(data.length);
buffer.put(data);

View file

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

View file

@ -2,13 +2,11 @@ package net.oikmo.engine.entity;
import java.util.Random;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
import org.lwjgl.util.vector.Vector3f;
import com.mojang.minecraft.phys.AABB;
import net.oikmo.engine.DisplayManager;
import net.oikmo.engine.inventory.Item;
import net.oikmo.engine.world.blocks.Block;
import net.oikmo.main.GameSettings;
@ -19,58 +17,31 @@ import net.oikmo.toolbox.Maths;
/**
* Camera class. Allows the player to see the world.
*
* @author Oikmo
* @author <i>Oikmo</i>
*/
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;
/** 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 */
public float yaw = 0;
public float roll = 0;
private boolean mouseLocked = true;
/** Action locker to prevent the action being done multiple times each frame */
private boolean lockInCam;
/** For currently selected blocks */
private TargetedAABB aabb;
/** For block picking */
public Vector3f forward;
/** Third person or not */
private boolean perspective = false;
/** How far should the camera be from the player if in third person */
public float distanceFromPlayer = 5;
/** X rotation around the player */
public float angleAroundPlayer = 0;
/** Action locker to prevent the action being done multiple times each frame */
private boolean mouseClickLeft = false;
/** Action locker to prevent the action being done multiple times each frame */
private boolean mouseClickRight = false;
/** Action locker to prevent the action being done multiple times each frame */
private boolean perspectiveLock = false;
/** Only true if the player is in first person and has a line of sight at a block */
private boolean shouldRenderAABB = false;
/**
* Camera constructor. Sets position and rotation.
* @param position Where camera should be at
* @param rotation Where camera should look at
*
* @param position
* @param rotation
* @param scale
*/
public Camera(Vector3f position, Vector3f rotation) {
this.position = position;
@ -82,113 +53,102 @@ public class Camera {
mouseLocked = true;
}
/**
* Instantiates a camera at [0,0,0] without locking the mouse
*/
public Camera() {
this.position = new Vector3f();
mouseLocked = false;
}
float multiplier = 100;
boolean inventory = false;
boolean mouseClickLeft = false;
boolean mouseClickRight = false;
boolean shouldRenderAABB = false;
/**
* Attaches to the player
* @param player Player to attach to
* Fly cam
* @param heightOffset
*/
public void update(Player player) {
if(Keyboard.isKeyDown(Keyboard.KEY_F5)) {
if(!perspectiveLock) {
perspective = !perspective;
perspectiveLock = true;
}
} else {
perspectiveLock = false;
}
if(!perspective) {
Vector3f position = new Vector3f(player.getPosition());
this.position = position;
this.prevPosition = new Vector3f(position);
this.position.x = Maths.lerp(this.position.x, position.x, 0.1f);
this.position.z = Maths.lerp(this.position.z, position.z, 0.1f);
this.position.y = position.y + player.heightOffset;
int reachDistance = player.reachDistance;
this.prevYaw = yaw;
if(mouseLocked && Main.theWorld != null && Main.thePlayer.tick) {
this.updateForwardVector();
Vector3f position = new Vector3f(player.getPosition());
this.position = position;
this.prevPosition = new Vector3f(position);
this.position.x = Maths.lerp(this.position.x, position.x, 0.1f);
this.position.z = Maths.lerp(this.position.z, position.z, 0.1f);
this.position.y = position.y + player.heightOffset;
int reachDistance = player.reachDistance;
this.prevYaw = yaw;
if(mouseLocked && Main.theWorld != null && Main.thePlayer.tick) {
this.updateVectors();
Vector3f currentPoint = Main.theWorld.raycast(getPosition(), forward, reachDistance, false);
if(currentPoint != null) {
int blockX = (int)(currentPoint.x);
int blockY = (int)(currentPoint.y);
int blockZ = (int)(currentPoint.z);
Vector3f blockPos = new Vector3f(blockX,blockY,blockZ);
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;
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());
}
} else {
mouseClickRight = false;
mouseClickRight = true;
}
} else {
mouseClickRight = false;
}
if(Mouse.isButtonDown(0)) {
if(!mouseClickLeft) {
Block block = Main.theWorld.getBlock(blockPos);
if(block != null) {
/*Vector3f v = new Vector3f(picker.getPointRounded());
v.y += 1f;
ItemBlock item = new ItemBlock(block, v);
Main.theWorld.addEntity(item);*/
Vector3f pos = new Vector3f(currentPoint);
if(block.getByteType() == Block.tnt.getType() && Main.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);
if(Mouse.isButtonDown(0)) {
if(!mouseClickLeft) {
Block block = Main.theWorld.getBlock(blockPos);
if(block != null) {
/*Vector3f v = new Vector3f(picker.getPointRounded());
v.y += 1f;
ItemBlock item = new ItemBlock(block, v);
Main.theWorld.addEntity(item);*/
Vector3f pos = new Vector3f(currentPoint);
if(block.getByteType() == Block.tnt.getType()) {
Main.theWorld.addEntity(new PrimedTNT(pos, new Random().nextInt(10)/10f, 0.1f, new Random().nextInt(10)/10f, true));
}
mouseClickLeft = true;
Main.theWorld.setBlock(blockPos, null);
}
} else {
mouseClickLeft = false;
mouseClickLeft = true;
}
if(Mouse.isButtonDown(2)) {
Block toBeSelected = Main.theWorld.getBlock(blockPos);
if(toBeSelected != null) {
Main.inGameGUI.setSelectedItem(Item.blockToItem(toBeSelected));
}
} 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;
}
}
Block thatBlock = Main.theWorld.getBlock(blockPos);
if(thatBlock != null) {
aabb.setPosition(blockPos);
shouldRenderAABB = true;
} else {
shouldRenderAABB = false;
}
} else {
shouldRenderAABB = false;
}
}
this.move(player);
this.move();
}
/**
* Updates the {@link #forward} vector for picking blocks
*/
private void updateForwardVector() {
private void updateVectors() {
float yaw = (float) Math.toRadians(this.yaw + 90);
float pitch = (float) Math.toRadians(this.pitch);
this.forward.x = FastMath.cos(yaw) * FastMath.cos(pitch);
@ -200,25 +160,11 @@ public class Camera {
forward.z *= -1;
}
/**
* Returns the selected block's bounding box
* @return {@link TargetedAABB}
*/
public TargetedAABB getAABB() {
return aabb;
}
/**
* Is the player in third person or not
* @return {@link Boolean}
*/
public boolean isPerspective() {
return perspective;
}
/**
* Toggles the locking of the mouse
*/
public void toggleMouseLock() {
if(!lockInCam) {
mouseLocked = !mouseLocked;
@ -226,10 +172,6 @@ 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) {
@ -237,17 +179,13 @@ public class Camera {
}
}
/**
* 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) {
private void move() {
/*if(Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)) {
toggleMouseLock();
} else {
lockInCam = false;
}*/
if(Mouse.isGrabbed() != mouseLocked) {
Mouse.setGrabbed(mouseLocked);
}
@ -259,27 +197,15 @@ 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 Distance X to move by
* @param dy Distance Y to move by
* @param dz Distance Z to move by
* @param dx
* @param dy
* @param dz
*/
public void increasePosition(float dx, float dy, float dz) {
this.position.x += dx;
@ -288,9 +214,9 @@ public class Camera {
}
/**
* Rotates the camera based on given values.
* @param dx Rotational X to move by
* @param dy Rotational Y to move by
* @param dz Rotational Z to move by
* @param dx
* @param dy
* @param dz
*/
public void increaseRotation(float dx, float dy, float dz) {
this.pitch += dx;
@ -299,9 +225,9 @@ public class Camera {
}
/**
* Sets the rotation of the camera based on given values.
* @param dx Rotational X to set to
* @param dy Rotational Y to set to
* @param dz Rotational Z to set to
* @param dx
* @param dy
* @param dz
*/
public void setRotation(float dx, float dy, float dz) {
this.pitch = dx;
@ -309,121 +235,45 @@ 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 v Vector to set position to
* @param vector
*/
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;
@ -432,10 +282,6 @@ public class Camera {
this.aabb = new AABB(x, y, z, x + 1f, y + 1f, z + 1f);
}
/**
* Sets the position and calculates the bounding box from given position
* @param position Position to set to and calculate from
*/
public void setPosition(Vector3f position) {
this.position = position;
float x = this.position.x;
@ -443,19 +289,11 @@ public class Camera {
float z = this.position.z;
this.aabb = new AABB(x, y, z, x + 1f, y + 1f, z + 1f);
}
/**
* Returns the bounding box
* @return {@link AABB}
*/
public AABB getAABB() {
return aabb;
}
/**
* Returns the position
* @return {@link Vector3f}
*/
public Vector3f getPosition() {
return position;
}

View file

@ -8,15 +8,11 @@ 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;
@ -37,9 +33,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;
@ -48,7 +44,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();
@ -88,32 +84,29 @@ public class Entity {
double prevX = position.x;
double prevZ = position.z;
moveWithoutSound(xa,ya,za, size);
double offsetX = position.x - prevX;
double offsetZ = position.z - prevZ;
distanceWalkedModified += (double)FastMath.sqrt((float) (offsetX * offsetX + offsetZ * offsetZ)) * 0.7D;
int posX = (int)(position.x-0.5f);
int posX = (int)(position.x);
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);
}
int posZ = (int)(position.z);
Block block = Main.theWorld.getBlock(new Vector3f(posX,posY,posZ));
if(distanceWalkedModified > (float)nextStepDistance && block != null) {
nextStepDistance++;
SoundMaster.playBlockPlaceSFX(block, posX, posY, posZ);
if(Main.theNetwork != null) {
PacketPlaySoundAt packet = new PacketPlaySoundAt();
packet.place = true;
packet.blockID = block.getByteType();
packet.x = posX;
packet.y = posY;
packet.z = posZ;
Main.theNetwork.client.sendTCP(packet);
}
}
}
public void moveWithoutSound(float xa, float ya, float za, int size) {
float xaOrg = xa;
float yaOrg = ya;
@ -121,7 +114,7 @@ public class Entity {
if(Main.theWorld != null) {
List<AABB> aabbs = Main.theWorld.getSurroundingAABBsPhys(this.aabb, size);
int i;
for(i = 0; i < aabbs.size(); ++i) {
ya = aabbs.get(i).clipYCollide(this.aabb, ya);
@ -153,7 +146,7 @@ public class Entity {
this.motion.z = 0.0F;
}
}
if(this instanceof Player) {
this.position.x = ((this.aabb.minX + this.aabb.maxX) / 2.0F);
this.position.y = this.aabb.minY + this.heightOffset;
@ -163,33 +156,13 @@ public class Entity {
this.position.y = this.aabb.minY + this.heightOffset;
this.position.z = ((this.aabb.minZ + this.aabb.maxZ) / 2.0F)-0.5f;
}
updateFallState(ya, onGround);
}
protected void fall(float distance) {}
protected void updateFallState(double d, boolean flag) {
if(flag) {
if(fallDistance > 0.0F) {
fall(fallDistance);
fallDistance = 0.0F;
}
} else {
if(d < 0.0D) {
fallDistance -= d;
}
}
}
public float getBrightness() {
int x = (int)this.position.x;
int y = (int)(this.position.y + this.heightOffset / 2.0F);
int z = (int)this.position.z;
if(Main.theWorld.getChunkFromPosition(getCurrentChunkPosition()) != null) {
return Main.theWorld.getChunkFromPosition(getCurrentChunkPosition()).getChunk().getBrightness(x, y, z);
}
return 1;
return Main.theWorld.getChunkFromPosition(getCurrentChunkPosition()).getChunk().getBrightness(x, y, z);
}
/**
@ -223,53 +196,6 @@ 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);
}
@ -335,8 +261,9 @@ public class Entity {
return scale;
}
public ChunkCoordinates getCurrentChunkPosition() {
return Maths.calculateChunkPosition(position);
public Vector3f getCurrentChunkPosition() {
getCurrentChunk();
return chunkPos;
}
public void resetMotion() {
@ -350,17 +277,19 @@ public class Entity {
Maths.roundVector(getPosition(), roundPos);
return roundPos;
}
public boolean shouldBeRemoved() {
return remove;
}
public MasterChunk getCurrentChunk() {
if(chunkPos == null) { chunkPos = new Vector3f(); }
ChunkCoordinates chunkPos = Maths.calculateChunkPosition(position);
Maths.calculateChunkPosition(getPosition(), chunkPos);
if(Main.theWorld != null) {
synchronized(Main.theWorld.chunkMap) {
return Main.theWorld.getChunkFromPosition(chunkPos);
synchronized(Main.theWorld.usedPositions) {
return Main.theWorld.getChunkFromPosition(chunkPos);
}
}
}
return null;

View file

@ -4,12 +4,10 @@ import org.lwjgl.input.Keyboard;
import org.lwjgl.util.vector.Vector3f;
import net.oikmo.engine.inventory.Container;
import net.oikmo.engine.models.PlayerModel;
import net.oikmo.engine.models.CubeModel;
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.renderers.MasterRenderer;
import net.oikmo.engine.textures.ModelTexture;
import net.oikmo.engine.world.blocks.Block;
import net.oikmo.engine.world.chunk.MasterChunk;
import net.oikmo.main.Main;
import net.oikmo.main.gui.GuiChat;
@ -17,15 +15,13 @@ import net.oikmo.main.gui.GuiChat;
public class Player extends Entity {
public boolean tick = true;
private Vector3f modelPosition = new Vector3f();
private Vector3f modelRotation = new Vector3f();
private Camera camera;
private Container inventory;
public int reachDistance = 5;
public Player(Vector3f position, Vector3f rotation) {
super(new TexturedModel(PlayerModel.getRawModel(), MasterRenderer.invisibleTexture), position, rotation,1f);
super(new TexturedModel(CubeModel.getRawModel(Block.obsidian), ModelTexture.create("textures/transparent")), position, rotation,1f);
resetPos();
this.heightOffset = 0.81f;
this.camera = new Camera(position, rotation);
@ -33,14 +29,7 @@ public class Player extends Entity {
}
public void tick() {
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);
}
if(!tick) {return;}
float xa = 0.0F;
float za = 0.0F;
@ -67,24 +56,12 @@ public class Player extends Entity {
}
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.setRotation(0.0f, camera.yaw, 0.0f);
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) {
//resetPos();
if(this.getPosition().y < 0 && Main.theNetwork == null) {
resetPos();
}
this.motion.x *= 0.91F;
@ -96,27 +73,6 @@ 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;
}
@ -129,8 +85,9 @@ public class Player extends Entity {
public void resetPos() {
MasterChunk currentChunk = getCurrentChunk();
if(currentChunk != null) {
this.setPos(1, currentChunk.getChunk().getHeightFromPosition(getPosition()), 1);
this.setPos(getPosition().x, currentChunk.getChunk().getHeightFromPosition(currentChunk.getOrigin(), getPosition()), getPosition().z);
}
}
public Camera getCamera() {
@ -140,6 +97,4 @@ public class Player extends Entity {
public void setInventory(Container cont) {
this.inventory = cont;
}
}
}

View file

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

View file

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

View file

@ -3,23 +3,12 @@ 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;
@ -29,9 +18,6 @@ public class ChatMessage {
}
}
/**
* Every tick it counts down (decrements {@link #timer}) and removes itself from
*/
public void tick() {
timer--;
if(timer <= 0) {
@ -39,18 +25,10 @@ public class ChatMessage {
}
}
/**
* Returns the message string
* @return {@link String}
*/
public String getMessage() {
return message;
}
/**
* Returns true if it is yellow text
* @return {@link Boolean}
*/
public boolean isSpecial() {
return special;
}

View file

@ -35,7 +35,7 @@ public class Gui {
protected static UnicodeFont font;
private static Font awtFont = null;
protected static int fontSize = 16;
protected static int fontSize = 18;
protected static Cursor cursor;
@ -68,14 +68,12 @@ 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);
}
@ -193,7 +191,6 @@ 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,34 +9,18 @@ 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;
@ -80,20 +64,11 @@ public class BlockSlot extends Gui implements GuiComponent {
drawImage(item.getImage(), x, y, width, height);
}
/**
* Sets the position of the slot
* @param x X position to be set to
* @param y Y position to be set to
*/
public void setPosition(int x, int y) {
this.x = x;
this.y = y;
}
/**
* Returns the stored item
* @return {@link Item}
*/
public Item getItem() {
return item;
}
@ -101,9 +76,5 @@ public class BlockSlot extends Gui implements GuiComponent {
@Override
public void onCleanUp() {}
/** Drops the active static instance */
public static void dropCurrent() {
currentlyHoveringSlot = null;
lockedRightNow = false;
}
}

View file

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

View file

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

View file

@ -56,17 +56,8 @@ 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());
@ -105,9 +96,6 @@ public class GuiTextField extends Gui implements GuiComponent {
if(grabbed) {
handleKeyboardInput();
} else {
ticks = 0;
showMarker = false;
}
drawTexture(backgroundTexture, x, y, width, height);
@ -115,11 +103,7 @@ public class GuiTextField extends Gui implements GuiComponent {
if(inputText.length() == 0 && current != this) {
drawShadowString(Color.darkGray, (x+3)-width/2, y-fontSize/2, backgroundText);
} else {
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 ? "_" : ""));
drawShadowString((x+3)-width/2, y-fontSize/2, inputText);
}
}
@ -137,7 +121,7 @@ public class GuiTextField extends Gui implements GuiComponent {
protected void keyTyped(char c, int i) {
if(isValidCharacter(c)) {
if(getInputText().length() < 255) {
if(x+width > x+font.getWidth(getInputText() + c)) {
setInputText(getInputText() + c);
}
}

View file

@ -17,18 +17,16 @@ public class CubeModel {
public static float[] vertices;
private static Vector2f[][] UVS;
private static Vector3f[][] VERTS;
private static Map<Block, RawModel> models = new HashMap<>();
static Vector2f[][] UVS;
static Vector3f[][] VERTS;
public static Vector3f[] PX_POS = {
new Vector3f(1f,0f,1f),
new Vector3f(1f,1f,0f),
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),
new Vector3f(1f,0f,1f),
new Vector3f(1f,1f,1f),
new Vector3f(1f,1f,0f)
};
public static Vector3f[] NX_POS = {
new Vector3f(0f,1f,0f),
@ -40,11 +38,11 @@ public class CubeModel {
};
public static Vector3f[] PY_POS = {
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),
new Vector3f(1f,1f,0f),
new Vector3f(1f,1f,0f),
new Vector3f(1f,1f,1f),
new Vector3f(0f,1f,1f)
};
public static Vector3f[] NY_POS = {
new Vector3f(0f,0f,1f),
@ -64,11 +62,11 @@ public class CubeModel {
};
public static Vector3f[] NZ_POS = {
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),
new Vector3f(1f,0f,0f),
new Vector3f(1f,0f,0f),
new Vector3f(1f,1f,0f),
new Vector3f(0f,1f,0f)
};
public static Vector2f[] UV_PX;
@ -134,24 +132,25 @@ public class CubeModel {
public static Vector2f[] setupUVPX() {
Vector2f[] uvArray = new Vector2f[blockCount * texturesPerBlock];
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);
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);
return uvArray;
}
@ -175,6 +174,7 @@ 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,6 +197,7 @@ 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;
}
@ -219,6 +220,7 @@ 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;
}
@ -242,31 +244,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];
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);
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);
return uvArray;
}
@ -307,60 +309,22 @@ public class CubeModel {
}
}
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;
public static int addTextureFromXY(Vector2f[] uv, int index, int x, int y) {
float xOffset = (float) x / 16.f;
float yOffset = (float) y / 16.f;
int privIndex = new Integer(index*6);
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;
}
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;
}
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

@ -1,278 +0,0 @@
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,11 +11,6 @@ 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

@ -1,149 +0,0 @@
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

@ -1,41 +0,0 @@
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

@ -1,44 +0,0 @@
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

@ -1,221 +0,0 @@
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

@ -1,41 +0,0 @@
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

@ -1,32 +0,0 @@
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

@ -1,41 +0,0 @@
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

@ -1,41 +0,0 @@
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

@ -1,78 +0,0 @@
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

@ -1,41 +0,0 @@
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

@ -1,41 +0,0 @@
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

@ -1,48 +0,0 @@
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

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,11 +1,5 @@
package net.oikmo.engine.world;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
@ -24,22 +18,18 @@ import net.oikmo.engine.entity.Camera;
import net.oikmo.engine.entity.Entity;
import net.oikmo.engine.entity.ItemEntity;
import net.oikmo.engine.entity.Player;
import net.oikmo.engine.inventory.Container;
import net.oikmo.engine.models.RawModel;
import net.oikmo.engine.models.TexturedModel;
import net.oikmo.engine.nbt.NBTTagCompound;
import net.oikmo.engine.network.packet.PacketRequestChunk;
import net.oikmo.engine.renderers.MasterRenderer;
import net.oikmo.engine.renderers.chunk.ChunkEntity;
import net.oikmo.engine.sound.SoundMaster;
import net.oikmo.engine.save.ChunkSaveData;
import net.oikmo.engine.save.SaveData;
import net.oikmo.engine.save.SaveSystem;
import net.oikmo.engine.world.blocks.Block;
import net.oikmo.engine.world.chunk.Chunk;
import net.oikmo.engine.world.chunk.ChunkLoader;
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.GuiMainMenu;
import net.oikmo.toolbox.CompressedStreamTools;
import net.oikmo.network.shared.PacketRequestChunk;
import net.oikmo.toolbox.FastMath;
import net.oikmo.toolbox.Logger;
import net.oikmo.toolbox.Logger.LogLevel;
@ -50,12 +40,13 @@ public class World {
public static final int WORLD_HEIGHT = 128;
public static int RENDER_SIZE = 4;
public static final int WORLD_SIZE = RENDER_SIZE*8;
public Map<ChunkCoordinates, MasterChunk> chunkMap = new HashMap<>();
public Map<Vector3f, MasterChunk> chunkMap = new HashMap<>();
public List<Vector3f> usedPositions = new ArrayList<>();
private List<MasterChunk> currentMasterChunks = Collections.synchronizedList(new ArrayList<MasterChunk>());
private List<Entity> entities = new ArrayList<>();
private List<ChunkCoordinates> hasAsked = new ArrayList<>();
public ParticleEngine particleEngine;
@ -64,21 +55,9 @@ public class World {
private Thread chunkCreator;
private File worldDir;
private ChunkLoader provider;
private long lockTimestamp;
public long sizeOnDisk;
public boolean superFlat = false;
public static void updateRenderSize(int size) {
RENDER_SIZE = size;
}
public World(String seed) {
init(Maths.getSeedFromName(seed));
}
public World(long seed) {
init(seed);
}
@ -90,211 +69,78 @@ public class World {
this.seed = seed;
this.noise = new OpenSimplexNoise(this.seed);
particleEngine = new ParticleEngine();
}
public void initLevelLoader(String world) {
GuiMainMenu.stopMusic();
SoundMaster.stopMusic();
lockTimestamp = System.currentTimeMillis();
worldDir = new File(Main.getWorkingDirectory()+"/saves/"+world+"/");
worldDir.mkdirs();
try {
File lockFile = new File(worldDir, "session.lock");
DataOutputStream dos = new DataOutputStream(new FileOutputStream(lockFile));
try {
dos.writeLong(lockTimestamp);
} finally {
dos.close();
}
} catch(IOException e) {
e.printStackTrace();
throw new RuntimeException("Failed to check session lock, aborting");
}
File level = new File(worldDir, "level.dat");
boolean isNewWorld = !level.exists();
if(level.exists()) {
try {
NBTTagCompound baseTag = CompressedStreamTools.readCompressed(new FileInputStream(level));
NBTTagCompound nbttagcompound1 = baseTag.getCompoundTag("Data");
this.seed = nbttagcompound1.getLong("Seed");
this.sizeOnDisk = nbttagcompound1.getLong("SizeOnDisk");
this.noise = new OpenSimplexNoise(this.seed);
this.superFlat = nbttagcompound1.getBoolean("Superflat");
Main.thePlayer = new Player(new Vector3f(), new Vector3f());
Main.thePlayer.tick = false;
Main.thePlayer.readFromNBT(nbttagcompound1.getCompoundTag("Player"));
//worldTime = nbttagcompound1.getLong("Time");
} catch(Exception e) {
e.printStackTrace();
}
} else {
Main.thePlayer = new Player(new Vector3f(0, 120, 0), new Vector3f());
}
provider = new ChunkLoader(worldDir, !isNewWorld);
}
private void saveLevel() {
checkSessionLock();
NBTTagCompound base = new NBTTagCompound();
base.setLong("Seed", seed);
base.setLong("SizeOnDisk", sizeOnDisk);
base.setBoolean("Superflat", superFlat);
//nbttagcompound.setLong("Time", worldTime);*/
base.setLong("LastPlayed", System.currentTimeMillis());
/*EntityPlayer entityplayer = null;
if(playerEntities.size() > 0)
{
entityplayer = (EntityPlayer)playerEntities.get(0);
}*/
if(Main.thePlayer != null) {
NBTTagCompound playerCompound = new NBTTagCompound();
Main.thePlayer.writeToNBT(playerCompound);
base.setCompoundTag("Player", playerCompound);
}
NBTTagCompound dataTag = new NBTTagCompound();
dataTag.setTag("Data", base);
try {
File newLevel = new File(worldDir, "level.dat_new");
File oldLevel = new File(worldDir, "level.dat_old");
File currentLevel = new File(worldDir, "level.dat");
CompressedStreamTools.writeGzippedCompoundToOutputStream(dataTag, new FileOutputStream(newLevel));
if(oldLevel.exists()) {
oldLevel.delete();
}
currentLevel.renameTo(oldLevel);
if(currentLevel.exists()) {
currentLevel.delete();
}
newLevel.renameTo(currentLevel);
if(newLevel.exists()) {
newLevel.delete();
}
} catch(Exception exception) {
exception.printStackTrace();
}
}
public void checkSessionLock() {
try {
File file = new File(worldDir, "session.lock");
DataInputStream datainputstream = new DataInputStream(new FileInputStream(file));
try {
if(datainputstream.readLong() != lockTimestamp) {
Main.error("The save is being accessed from another location, aborting", new Exception());
}
} finally {
datainputstream.close();
}
} catch(IOException ioexception) {
Main.error("Failed to check session lock, aborting", new Exception());
}
}
}
public void update(Camera camera) {
currentMasterChunks.clear();
for (int x = -RENDER_SIZE; x < RENDER_SIZE; x++) {
for (int z = -RENDER_SIZE; z < RENDER_SIZE; z++) {
if(FastMath.abs(x) + FastMath.abs(z) > RENDER_SIZE) continue;
if(Main.thePlayer.getCurrentChunkPosition() != null) {
ChunkCoordinates playerChunk = Main.thePlayer.getCurrentChunkPosition();
ChunkCoordinates chunkPos = ChunkCoordHelper.create((int)(playerChunk.x + (x*16)), (int)(playerChunk.z + (z*16)));
synchronized(chunkMap) {
if(chunkMap.get(chunkPos) != null) {
MasterChunk master = getChunkFromPosition(chunkPos);
if(master != null) {
if(isInValidRange(master.getOrigin())) {
if(Main.theNetwork != null) {
master.timer = MasterChunk.networkMaxTime;
} else {
master.timer = MasterChunk.localMaxTime;
}
for (int x = (int) (Main.camPos.x - WORLD_SIZE) / 16; x < (Main.camPos.x + WORLD_SIZE) / 16; x++) {
for (int z = (int) (Main.camPos.z - WORLD_SIZE) / 16; z < (Main.camPos.z + WORLD_SIZE) / 16; z++) {
int chunkX = x * 16;
int chunkZ = z * 16;
Vector3f chunkPos = new Vector3f(chunkX, 0, chunkZ);
if(master.dirty) {
if(master.getMesh() != null) {
if(master.getMesh().hasMeshInfo()) {
RawModel raw = Loader.loadToVAO(master.getMesh().positions, master.getMesh().uvs, master.getMesh().normals);
TexturedModel texModel = new TexturedModel(raw, MasterRenderer.currentTexturePack);
ChunkEntity entity = new ChunkEntity(texModel, master.getOrigin());
master.setEntity(entity);
if(master.getMesh() != null) {
master.getMesh().removeMeshInfo();
}
master.destroyMesh();
master.dirty = false;
}
} else {
master.createMesh();
}
}
}
}
if(master != null) {
if(!currentMasterChunks.contains(master)) {
currentMasterChunks.add(master);
synchronized(usedPositions) {
if(isPositionUsed(chunkPos)) {
MasterChunk master = getChunkFromPosition(chunkPos);
if(master != null) {
if(isInValidRange(master.getOrigin())) {
if(Main.theNetwork != null) {
master.timer = MasterChunk.maxTime;
}
if(master.getEntity() == null) {
if(master.getMesh() != null) {
if(master.getMesh().hasMeshInfo()) {
RawModel raw = Loader.loadToVAO(master.getMesh().positions, master.getMesh().uvs, master.getMesh().normals);
TexturedModel texModel = new TexturedModel(raw, MasterRenderer.currentTexturePack);
Entity entity = new Entity(texModel, master.getOrigin(), new Vector3f(0,0,0),1);
master.setEntity(entity);
master.getMesh().removeMeshInfo();
}
} else {
master.createMesh();
}
}
}
}
if(master != null) {
if(!currentMasterChunks.contains(master)) {
currentMasterChunks.add(master);
}
}
}
}
}
}
}
}
if(Main.theNetwork != null) {
try {
for(int m = 0; m < chunkMap.values().size(); m++) {
MasterChunk master = (MasterChunk) chunkMap.values().toArray()[m];
for(int m = 0; m < chunkMap.values().size(); m++) {
MasterChunk master = (MasterChunk) chunkMap.values().toArray()[m];
if(master != null) {
if(!isInValidRange(2, master.getOrigin())) {
if(master.timer > 0) {
master.timer--;
}
if(master.timer <= 0) {
System.out.println("BYE BITCH AT " + master.getOrigin());
chunkMap.remove(master.getOrigin());
hasAsked.remove(master.getOrigin());
}
if(master != null) {
if(!isInValidRange(master.getOrigin())) {
if(Main.theNetwork != null) {
if(master.timer > 0) {
master.timer--;
}
if(master.timer <= 0) {
System.out.println("removing chunk at " + master.getOrigin() + " as 5s has passed");
chunkMap.remove(master.getOrigin());
hasAsked.remove(master.getOrigin());
}
}
}
} catch(Exception e) {}
} else {
try {
for(int m = 0; m < chunkMap.values().size(); m++) {
MasterChunk master = (MasterChunk) chunkMap.values().toArray()[m];
if(master != null) {
if(!isInValidRange(master.getOrigin())) {
if(master.timer > 0) {
master.timer--;
}
if(master.timer <= 0) {
provider.saveChunk(master);
chunkMap.remove(master.getOrigin());
}
}
}
}
} catch(java.util.ConcurrentModificationException e) {}
}
}
for(MasterChunk master : currentMasterChunks) {
if(master.getEntity() != null) {
MasterRenderer.getInstance().addChunkEntity(master.getEntity());
MasterRenderer.getInstance().addEntity(master.getEntity());
}
}
for(Entity entity : entities) {
MasterRenderer.getInstance().addEntity(entity);
if(isInValidRange(entity.getPosition())) {
MasterRenderer.getInstance().addEntity(entity);
}
}
MasterRenderer.getInstance().render(camera);
particleEngine.render(Main.thePlayer, 1f);
@ -347,77 +193,78 @@ public class World {
}
}
}
return surroundingAABBs;
}
public Vector3f raycast(Vector3f position, Vector3f direction, float distance, boolean isPlace) {
float xPos = (float) Math.floor(position.x);
float yPos = (float) Math.floor(position.y);
float zPos = (float) Math.floor(position.z);
float xPos = (float) Math.floor(position.x);
float yPos = (float) Math.floor(position.y);
float zPos = (float) Math.floor(position.z);
if (direction.length() == 0)
return null;
if (direction.length() == 0)
return null;
direction = (Vector3f)direction.normalise();
direction = (Vector3f)direction.normalise();
int stepX = Maths.signum(direction.x);
int stepY = Maths.signum(direction.y);
int stepZ = Maths.signum(direction.z);
Vector3f tMax = new Vector3f(Maths.intbound(position.x, direction.x), Maths.intbound(position.y, direction.y), Maths.intbound(position.z, direction.z));
Vector3f tDelta = new Vector3f((float)stepX / direction.x, (float)stepY / direction.y, (float)stepZ / direction.z);
float faceX = 0;
float faceY = 0;
float faceZ = 0;
int stepX = Maths.signum(direction.x);
int stepY = Maths.signum(direction.y);
int stepZ = Maths.signum(direction.z);
Vector3f tMax = new Vector3f(Maths.intbound(position.x, direction.x), Maths.intbound(position.y, direction.y), Maths.intbound(position.z, direction.z));
Vector3f tDelta = new Vector3f((float)stepX / direction.x, (float)stepY / direction.y, (float)stepZ / direction.z);
float faceX = 0;
float faceY = 0;
float faceZ = 0;
do {
if (getBlock((int)xPos, (int)yPos, (int)zPos) != null) {
if (!isPlace) {
return new Vector3f(xPos, yPos, zPos);
} else {
return new Vector3f((int)(xPos + faceX), (int)(yPos + faceY), (int)(zPos + faceZ));
}
}
if (tMax.x < tMax.y) {
if (tMax.x < tMax.z) {
if (tMax.x > distance) break;
do {
if (getBlock((int)xPos, (int)yPos, (int)zPos) != null) {
if (!isPlace) {
return new Vector3f(xPos, yPos, zPos);
} else {
return new Vector3f((int)(xPos + faceX), (int)(yPos + faceY), (int)(zPos + faceZ));
}
}
if (tMax.x < tMax.y) {
if (tMax.x < tMax.z) {
if (tMax.x > distance) break;
xPos += stepX;
tMax.x += tDelta.x;
xPos += stepX;
tMax.x += tDelta.x;
faceX = -stepX;
faceY = 0;
faceZ = 0;
} else {
if (tMax.z > distance) break;
zPos += stepZ;
tMax.z += tDelta.z;
faceX = 0;
faceY = 0;
faceZ = -stepZ;
}
} else {
if (tMax.y < tMax.z) {
if (tMax.y > distance) break;
yPos += stepY;
tMax.y += tDelta.y;
faceX = 0;
faceY = -stepY;
faceZ = 0;
} else {
if (tMax.z > distance) break;
zPos += stepZ;
tMax.z += tDelta.z;
faceX = 0;
faceY = 0;
faceZ = -stepZ;
}
}
} while (true);
faceX = -stepX;
faceY = 0;
faceZ = 0;
} else {
if (tMax.z > distance) break;
zPos += stepZ;
tMax.z += tDelta.z;
faceX = 0;
faceY = 0;
faceZ = -stepZ;
}
} else {
if (tMax.y < tMax.z) {
if (tMax.y > distance) break;
yPos += stepY;
tMax.y += tDelta.y;
faceX = 0;
faceY = -stepY;
faceZ = 0;
} else {
if (tMax.z > distance) break;
zPos += stepZ;
tMax.z += tDelta.z;
faceX = 0;
faceY = 0;
faceZ = -stepZ;
}
}
} while (true);
return null;
}
public Block getBlock(int xPos, int yPos, int zPos) {
return null;
}
private Block getBlock(int xPos, int yPos, int zPos) {
return getBlock(new Vector3f(xPos, yPos, zPos));
}
/* if(entity instanceof ItemEntity) {
@ -433,67 +280,16 @@ public class World {
}
}
*/
public void addEntity(Entity ent) {
if(!entities.contains(ent)) {
entities.add(ent);
}
}
public MasterChunk setBlockNoUpdate(Vector3f position, Block block) {
ChunkCoordinates chunkPos = Maths.calculateChunkPosition(position);
MasterChunk m = getChunkFromPosition(chunkPos);
if(m != null) {
m.setBlockNoUpdate(position, block);
if(Main.theNetwork != null) {
Main.theNetwork.updateChunk(position,block, false);
}
}
return m;
}
public MasterChunk setBlockNoUpdateNoNet(Vector3f position, Block block) {
ChunkCoordinates chunkPos = Maths.calculateChunkPosition(position);
MasterChunk m = getChunkFromPosition(chunkPos);
if(m != null) {
m.setBlockNoUpdate(position, block);
}
return m;
}
public boolean setBlock(Vector3f position, Block block) {
ChunkCoordinates chunkPos = Maths.calculateChunkPosition(position);
MasterChunk m = getChunkFromPosition(chunkPos);
if(m != null) {
m.setBlock(position, block, true);
if(Main.theNetwork != null) {
Main.theNetwork.updateChunk(position,block, true);
}
return true;
}
return false;
}
public boolean setBlockNoNet(Vector3f position, Block block) {
ChunkCoordinates chunkPos = Maths.calculateChunkPosition(position);
MasterChunk m = getChunkFromPosition(chunkPos);
if(m != null) {
m.setBlock(position, block, false);
return true;
}
return false;
}
public Block getBlock(Vector3f position) {
ChunkCoordinates chunkPos = Maths.calculateChunkPosition(position);
MasterChunk m = getChunkFromPosition(chunkPos);
if(m != null) {
return m.getBlock(position);
}
return null;
}
public Vector3f getBlockPositionFromCalculatedChunk(int x, int y, int z) {
ChunkCoordinates chunkPos = Maths.calculateChunkPosition(new Vector3f(x,y,z));
Vector3f chunkPos = new Vector3f();
Maths.calculateChunkPosition(new Vector3f(x,y,z), chunkPos);
MasterChunk m = getChunkFromPosition(chunkPos);
if(m != null) {
@ -513,8 +309,67 @@ public class World {
return null;
}
public MasterChunk setBlockNoUpdate(Vector3f position, Block block) {
Vector3f chunkPos = new Vector3f();
Maths.calculateChunkPosition(position, chunkPos);
MasterChunk m = getChunkFromPosition(chunkPos);
if(m != null) {
m.setBlockNoUpdate(position, block);
if(Main.theNetwork != null) {
Main.theNetwork.updateChunk(position,block, false);
}
}
return m;
}
public MasterChunk setBlockNoUpdateNoNet(Vector3f position, Block block) {
Vector3f chunkPos = new Vector3f();
Maths.calculateChunkPosition(position, chunkPos);
MasterChunk m = getChunkFromPosition(chunkPos);
if(m != null) {
m.setBlockNoUpdate(position, block);
}
return m;
}
public boolean setBlock(Vector3f position, Block block) {
Vector3f chunkPos = new Vector3f();
Maths.calculateChunkPosition(position, chunkPos);
MasterChunk m = getChunkFromPosition(chunkPos);
if(m != null) {
m.setBlock(position, block, true);
if(Main.theNetwork != null) {
Main.theNetwork.updateChunk(position,block, true);
}
return true;
}
return false;
}
public boolean setBlockNoNet(Vector3f position, Block block) {
Vector3f chunkPos = new Vector3f();
Maths.calculateChunkPosition(position, chunkPos);
MasterChunk m = getChunkFromPosition(chunkPos);
if(m != null) {
m.setBlock(position, block, false);
return true;
}
return false;
}
public Block getBlock(Vector3f position) {
Vector3f chunkPos = new Vector3f();
Maths.calculateChunkPosition(position, chunkPos);
MasterChunk m = getChunkFromPosition(chunkPos);
if(m != null) {
return m.getBlock(position);
}
return null;
}
public boolean blockHasNeighbours(Vector3f position) {
ChunkCoordinates chunkPos = Maths.calculateChunkPosition(position);
Vector3f chunkPos = new Vector3f();
Maths.calculateChunkPosition(position, chunkPos);
MasterChunk m = getChunkFromPosition(chunkPos);
if(m != null) {
@ -545,7 +400,7 @@ public class World {
}
if(Maths.isWithinChunk(x, y, z)) {
if(m.getChunk().getBlock(x, y, z) != -1) {
if(m.getChunk().blocks[x][y][z] != -1) {
return true;
}
}
@ -559,6 +414,7 @@ public class World {
return getBlock(new Vector3f(x,y,z)) != null;
}
Vector3f holder = new Vector3f();
public void createRadiusFromBlock(int r, Block block, int x, int y, int z) {
List<MasterChunk> chunksToRefresh = new ArrayList<>();
@ -582,46 +438,26 @@ public class World {
}
}
for(MasterChunk m : chunksToRefresh) {
m.dirty = true;
//setBlock(new Vector3f(m.getOrigin().x, -1, m.getOrigin().z),null);
refreshChunk(m);
setBlock(new Vector3f(m.getOrigin().x, -1, m.getOrigin().z),null);
}
}
public void startChunkCreator() {
this.chunkCreator = new Thread(new Runnable() {
public void run() {
boolean debug = false;
while (!Main.displayRequest) {
for (int x = (int) (Main.camPos.x - WORLD_SIZE) / 16; x < (Main.camPos.x + WORLD_SIZE) / 16; x++) {
for (int z = (int) (Main.camPos.z - WORLD_SIZE) / 16; z < (Main.camPos.z + WORLD_SIZE) / 16; z++) {
int chunkX = x * 16;
int chunkZ = z * 16;
if(debug) {
MasterChunk m = new MasterChunk(noise, ChunkCoordHelper.create(0,0));
addChunk(m);
} else {
while (!Main.displayRequest) {
if(Main.thePlayer != null && Main.thePlayer.getCurrentChunk() != null && !Main.thePlayer.tick) {
Main.thePlayer.tick = true;
} else if(Main.thePlayer != null && Main.thePlayer.getCurrentChunk() == null) {
Main.thePlayer.tick = false;
}
for (int x = -RENDER_SIZE; x < RENDER_SIZE; x++) {
for (int z = -RENDER_SIZE; z < RENDER_SIZE; z++) {
if(FastMath.abs(x) + FastMath.abs(z) > RENDER_SIZE) continue;
if(Main.thePlayer == null) {
return;
Vector3f chunkPos = new Vector3f(chunkX, 0, chunkZ);
synchronized(usedPositions) {
if(!isPositionUsed(chunkPos) && getChunkFromPosition(chunkPos) == null) {
MasterChunk m = new MasterChunk(noise, chunkPos);
addChunk(m);
}
if(Main.thePlayer.getCurrentChunkPosition() != null) {
ChunkCoordinates playerChunk = Main.thePlayer.getCurrentChunkPosition();
ChunkCoordinates chunkPos = ChunkCoordHelper.create((int)(playerChunk.x + (x*16)), (int)(playerChunk.z + (z*16)));
synchronized(chunkMap) {
if(chunkMap.get(chunkPos) == null && getChunkFromPosition(chunkPos) == null) {
if(provider.loadChunk(chunkPos.x, chunkPos.z) != null) {
addChunk(provider.loadChunk(chunkPos.x, chunkPos.z));
} else {
addChunk(new MasterChunk(noise, chunkPos));
}
}
}
}
}
}
}
@ -631,47 +467,35 @@ public class World {
this.chunkCreator.setName("Chunk Creator");
this.chunkCreator.start();
}
private List<Vector3f> hasAsked = new ArrayList<>();
public void startChunkRetriever() {
this.chunkCreator = new Thread(new Runnable() {
public void run() {
while (!Main.displayRequest) {
if(Main.thePlayer != null) {
if(Main.thePlayer.getCurrentChunk() != null && !Main.thePlayer.tick) {
Main.thePlayer.tick = true;
} else if(Main.thePlayer.getCurrentChunk() == null && Main.thePlayer.tick) {
Main.thePlayer.tick = false;
}
if(Main.thePlayer != null && Main.thePlayer.getCurrentChunk() != null && !Main.thePlayer.tick) {
Main.thePlayer.tick = true;
}
for (int x = -RENDER_SIZE; x < RENDER_SIZE; x++) {
for (int z = -RENDER_SIZE; z < RENDER_SIZE; z++) {
if(FastMath.abs(x) + FastMath.abs(z) > RENDER_SIZE) { continue; }
if(Main.thePlayer == null) { continue; }
if(Main.thePlayer.getCurrentChunkPosition() != null) {
ChunkCoordinates playerChunk = Main.thePlayer.getCurrentChunkPosition();
ChunkCoordinates chunkPos = ChunkCoordHelper.create((int)(playerChunk.x + (x*16)), (int)(playerChunk.z + (z*16)));
synchronized(hasAsked) {
if(!hasAsked.contains(chunkPos) || chunkMap.get(chunkPos) == null) {
hasAsked.add(chunkPos);
for (int x = (int) (Main.camPos.x - WORLD_SIZE) / 16; x < (Main.camPos.x + WORLD_SIZE) / 16; x++) {
for (int z = (int) (Main.camPos.z - WORLD_SIZE) / 16; z < (Main.camPos.z + WORLD_SIZE) / 16; z++) {
int chunkX = x * 16;
int chunkZ = z * 16;
PacketRequestChunk packet = new PacketRequestChunk();
packet.x = chunkPos.x;
packet.z = chunkPos.z;
if(Main.theNetwork != null && Main.theNetwork.client != null) {
Main.theNetwork.client.sendTCP(packet);
}
try {
Thread.sleep(100);
} catch (InterruptedException e) {}
//System.out.println("sent request for my pookie boo server " + chunkPos);
} else {
continue;
}
}
Vector3f chunkPos = new Vector3f(chunkX, 0, chunkZ);
synchronized(hasAsked) {
if(!hasAsked.contains(chunkPos)) {
hasAsked.add(chunkPos);
PacketRequestChunk packet = new PacketRequestChunk();
packet.x = chunkX;
packet.z = chunkZ;
Main.theNetwork.client.sendTCP(packet);
} else {
continue;
}
}
}
}
}
}
});
@ -687,50 +511,77 @@ public class World {
}
public void addChunk(MasterChunk m) {
usedPositions.add(m.getOrigin());
chunkMap.put(m.getOrigin(), m);
}
public void handleLoad(SaveData data) {
if(Main.thePlayer == null) {
Main.thePlayer = new Player(new Vector3f(data.x, data.y, data.z), new Vector3f(data.rotX, data.rotY, data.rotZ));
}
if(data.cont != null) {
Main.thePlayer.setInventory(Container.loadSavedContainer(data.cont));
}
Main.thePlayer.resetMotion();
Vector3f v = Main.thePlayer.getPosition();
v.y = getHeightFromPosition(Main.thePlayer.getRoundedPosition());
if(v.y != -1) {
v.y++;
Main.thePlayer.setPosition(v);
}
Main.thePlayer.getCamera().setRotation(data.rotX, data.rotY, data.rotZ);
}
public void refreshChunk(MasterChunk master) {
master.getChunk().calcLightDepths(0, 0, Chunk.CHUNK_SIZE, Chunk.CHUNK_SIZE);
if(master.getMesh() != null) {
master.getMesh().removeMeshInfo();
master.destroyMesh();
master.setEntity(null);
master.createMesh();
}
}
public void refreshChunks() {
Logger.log(LogLevel.INFO, "Clearing " + currentMasterChunks.size() + " chunks!");
try {
for(int i = 0; i < currentMasterChunks.size(); i++) {
MasterChunk master = currentMasterChunks.get(i);
if(master != null) {
//master.getChunk().calcLightDepths(0, 0, Chunk.CHUNK_SIZE, Chunk.CHUNK_SIZE);
master.dirty = true;
master.getChunk().calcLightDepths(0, 0, Chunk.CHUNK_SIZE, Chunk.CHUNK_SIZE);
if(master.getMesh() != null) {
master.getMesh().removeMeshInfo();
master.destroyMesh();
master.setEntity(null);
master.createMesh();
}
}
}
} catch(Exception e) {e.printStackTrace();}
}
public int getHeightFromPosition(Vector3f position) {
MasterChunk m = getChunkFromPosition(Maths.calculateChunkPosition(position));
Vector3f chunkPos = new Vector3f();
Maths.calculateChunkPosition(position, chunkPos);
MasterChunk m = getChunkFromPosition(chunkPos);
if(m != null) {
return m.getChunk().getHeightFromPosition(position);
return m.getChunk().getHeightFromPosition(chunkPos, position);
}
return -1;
}
public boolean isInValidRange(Vector3f origin) {
return isInValidRange(1, origin.x, origin.z);
return isInValidRange(1, origin);
}
public boolean isInValidRange(int size, Vector3f origin) {
int distX = (int) FastMath.abs((Main.camPos.x * size) - origin.x);
int distZ = (int) FastMath.abs((Main.camPos.z * size) - origin.z);
public boolean isInValidRange(ChunkCoordinates origin) {
return isInValidRange(1, origin.x, origin.z);
}
public boolean isInValidRange(int size, ChunkCoordinates origin) {
return isInValidRange(size, origin.x, origin.z);
}
public boolean isInValidRange(int size, float x, float z) {
int distX = (int) FastMath.abs((Main.camPos.x) - x);
int distZ = (int) FastMath.abs((Main.camPos.z) - z);
//int renderSize = size*RENDER_SIZE;
if((distX <= RENDER_SIZE*16*size) && (distZ <= RENDER_SIZE*16*size)) {
if((distX <= WORLD_SIZE) && (distZ <= WORLD_SIZE)) {
return true;
}
@ -738,48 +589,122 @@ public class World {
}
public MasterChunk getChunkFromPosition(Vector3f position) {
return getChunkFromPosition(ChunkCoordHelper.create((int)position.x, (int)position.z));
return chunkMap.get(getPosition(position));
}
public MasterChunk getChunkFromPosition(ChunkCoordinates position) {
return chunkMap.get(position);
private MasterChunk prevChunk;
public MasterChunk getChunkFromPositionOther(Vector3f position) {
if(prevChunk == null) {
for(MasterChunk chunk : chunkMap.values()) {
if((int)chunk.getOrigin().x == (int)position.x && (int)chunk.getOrigin().z == (int)position.z) {
prevChunk = chunk;
}
}
} else if(!((int)prevChunk.getOrigin().x == (int)position.x && (int)prevChunk.getOrigin().z == (int)position.z)){
for(MasterChunk chunk : chunkMap.values()) {
if((int)chunk.getOrigin().x == (int)position.x && (int)chunk.getOrigin().z == (int)position.z) {
prevChunk = chunk;
}
}
}
return prevChunk;
}
public boolean isPositionUsed(Vector3f pos) {
boolean result = false;
synchronized(usedPositions) {
result = usedPositions.contains(new Vector3f(pos.x, 0, pos.z));
}
return result;
}
public Vector3f getPosition(Vector3f pos) {
Vector3f result = null;
synchronized(usedPositions) {
for(int i = 0; i < usedPositions.size(); i++) {
try {
usedPositions.get(i);
} catch(IndexOutOfBoundsException e) {
continue;
}
if(usedPositions.get(i) != null) {
if((int)usedPositions.get(i).x == (int)pos.x && (int)usedPositions.get(i).z == (int)pos.z) {
result = usedPositions.get(i);
}
}
}
}
return result;
}
public Vector3f getPositionFromMap(Vector3f pos) {
Vector3f result = null;
synchronized(this.hasAsked) {
for(int i = 0; i < this.hasAsked.size(); i++) {
Vector3f key = this.hasAsked.get(i);
if(key != null) {
if((int)key.x == (int)pos.x && key.z == (int)pos.z) {
result = key;
}
}
}
}
return result;
}
public void saveWorld() {
//this.chunkCreator.interrupt();
for(Map.Entry<ChunkCoordinates, MasterChunk> entry : chunkMap.entrySet()) {
public void saveWorld(String world) {
List<ChunkSaveData> chunks = new ArrayList<>();
for(Map.Entry<Vector3f, MasterChunk> entry : chunkMap.entrySet()) {
MasterChunk master = entry.getValue();
provider.saveChunk(master);
chunks.add(new ChunkSaveData(master.getOrigin(), master.getChunk().blocks));
}
saveLevel();
SaveSystem.save(world, new SaveData(seed, chunks, Main.thePlayer));
chunks.clear();
}
@SuppressWarnings("deprecation")
public void saveWorldAndQuit(String world) {
saveWorld(world);
public void saveWorldAndQuit() {
saveWorld();
quitWorld();
}
public void quitWorld() {
if(this.chunkCreator != null) {
this.chunkCreator.interrupt();
}
this.chunkCreator.interrupt();
this.chunkCreator.stop();
Main.inGameGUI = null;
Main.thePlayer = null;
ChunkCoordHelper.cleanUp();
System.gc();
Main.theWorld = null;
}
@SuppressWarnings("deprecation")
public void quitWorld() {
this.chunkCreator.interrupt();
this.chunkCreator.stop();
Main.inGameGUI = null;
Main.thePlayer = null;
Main.theWorld = null;
}
public static World loadWorld(String world) {
Logger.log(LogLevel.WARN, "Loading world!");
SaveData data = SaveSystem.load(world);
if(data != null) {
Logger.log(LogLevel.WARN, "Loading world!");
World w = null;
w = new World();
w.initLevelLoader(world);
w.startChunkCreator();
World w = new World(data.seed);
return w;
for(ChunkSaveData s : data.chunks) {
w.addChunk(new MasterChunk(new Vector3f(s.x,0,s.z), s.blocks));
}
w.handleLoad(data);
w.startChunkCreator();
return w;
} else {
Logger.log(LogLevel.WARN, "World couldn't be loaded!");
return new World();
}
}
}

View file

@ -1,159 +1,78 @@
package net.oikmo.engine.world.blocks;
/**
* Those tiny voxels you can interact with
* @author Oikmo
*/
public abstract class Block {
/** Blocks list (for looping and rendering) */
public static final Block[] blocks = new Block[18];
/** Grass block */
public static final Block grass = new BlockGrass(Type.GRASS);
/** Dirt block */
public static final Block dirt = new BlockDirt(Type.DIRT);
/** Stone block */
public static final Block stone = new BlockStone(Type.STONE);
/** Bedrock block */
public static final Block bedrock = new BlockBedrock(Type.BEDROCK);
/** Cobblestone block */
public static final Block cobble = new BlockCobble(Type.COBBLE);
/** Mossy cobblestone block */
public static final Block mossycobble = new BlockMossyCobble(Type.MOSSYCOBBLE);
/** Obsidian block */
public static final Block obsidian = new BlockObsidian(Type.OBSIDIAN);
/** Oak log block */
public static final Block oaklog = new BlockOakLog(Type.WOOD);
/** Oak leaves block */
public static final Block oakleaf = new BlockOakLeaves(Type.LEAVES);
/** Oak plank block */
public static final Block oakleaf = new BlockOakLeaf(Type.LEAVES);
public static final Block oakplanks = new BlockOakPlanks(Type.PLANKS);
/** Glass block */
public static final Block glass = new BlockGlass(Type.GLASS);
/** Smooth stone block */
public static final Block smoothstone = new BlockSmoothStone(Type.SMOOTHSTONE);
/** Brick block */
public static final Block brick = new BlockBrick(Type.BRICK);
/** Iron block */
public static final Block ironBlock = new BlockIronBlock(Type.IRONBLOCK);
/** Gold block */
public static final Block goldBlock = new BlockGoldBlock(Type.GOLDBLOCK);
/** Diamond block */
public static final Block diamondBlock = new BlockDiamondBlock(Type.DIAMONDBLOCK);
/** TNT block */
public static final Block tnt = new BlockTNT(Type.TNT);
public static final Block obsidianPlayer = new BlockObsidian(Type.OBSIDIANPLAYER);
/**
* The type of block...
* @author Oikmo
*/
public static enum Type {
/** Air */
AIR,
/** Grass */
GRASS,
/** Dirt */
DIRT,
/** Stone */
STONE,
/** Bedrock */
BEDROCK,
/** Cobblestone */
COBBLE,
/** Mossy Cobblestone */
MOSSYCOBBLE,
/** Obsidian */
OBSIDIAN,
/** Leaves */
LEAVES,
/** Wood */
WOOD,
/** Planks */
PLANKS,
/** Glass */
GLASS,
/** Smooth Stone */
SMOOTHSTONE,
/** Brick */
BRICK,
/** Tnt */
TNT,
/** Iron Block */
IRONBLOCK,
/** Gold Block */
GOLDBLOCK,
/** Diamond Block */
DIAMONDBLOCK,
OBSIDIANPLAYER,
};
/** What type is the block? */
public Type type;
/**
* Block constructor
* @param type What type should the block be?
*/
public Block(Type type) {
blocks[type.ordinal()] = this;
this.type = type;
}
/**
* Returns a {@link Block} based on the index of block given
* @param type Index of block
* @return {@link Block}
*/
public static Block getBlockFromOrdinal(byte type) {
return type != -1 ? blocks[type] : null;
}
/**
* Sets the {@link Type} of the Block
* @param type Type to be set to
*/
public void setType(Block.Type type) {
this.type = type;
}
/**
* Returns the index of the type (ordinal)
* @return {@link Byte}
*/
public byte getByteType() {
return (byte)type.ordinal();
}
/**
* Returns the enum of the type
* @return {@link Type}
*/
public Type getEnumType() {
return type;
}
/**
* Returns the integer index of the type
* @return {@link Integer}
*/
public int getType() {
return type.ordinal();
}
/**
* How long does it take for it break?<br>How much can it resist explosions?
* @return {@link Float}
*/
public abstract float getStrength();
/**
* Should light pass through or not.
* @return {@link Boolean}
*/
public abstract boolean blocksLight();
/**
* Can it be collided with or not?
* @return {@link Boolean}
*/
public abstract boolean isSolid();
}

View file

@ -1,15 +1,7 @@
package net.oikmo.engine.world.blocks;
/**
* Indestructible (maybe)
* @author Oikmo
*/
public class BlockBedrock extends Block {
/**
* Bedrock block constructor
* @param type Block type
*/
public BlockBedrock(Type type) {
super(type);
}

View file

@ -1,15 +1,7 @@
package net.oikmo.engine.world.blocks;
/**
* Bricks, nice in style, could make great homes
* @author Oikmo
*/
public class BlockBrick extends Block {
/**
* Brick constructor
* @param type Block tyoe
*/
public BlockBrick(Type type) {
super(type);
}

View file

@ -1,16 +1,7 @@
package net.oikmo.engine.world.blocks;
/**
* Cobblestone... cool i guess
* @author Oikmo
*
*/
public class BlockCobble extends Block {
/**
* Cobble contructor
* @param type Block type
*/
public BlockCobble(Type type) {
super(type);
}

View file

@ -1,15 +1,7 @@
package net.oikmo.engine.world.blocks;
/**
* Walk round them... bills
* @author Oikmo
*/
public class BlockDiamondBlock extends Block {
/**
* Diamond block constructor
* @param type Block type
*/
public BlockDiamondBlock(Type type) {
super(type);
}

View file

@ -1,15 +1,7 @@
package net.oikmo.engine.world.blocks;
/**
* A block of dirt... wow...
* @author Oikmo
*/
public class BlockDirt extends Block {
/**
* Dirt block constructor
* @param type Block type
*/
public BlockDirt(Type type) {
super(type);
}

View file

@ -1,15 +1,7 @@
package net.oikmo.engine.world.blocks;
/**
* You can look through this one!
* @author Oikmo
*/
public class BlockGlass extends Block {
/**
* Glass block
* @param type Block type
*/
public BlockGlass(Type type) {
super(type);
}
@ -19,7 +11,7 @@ public class BlockGlass extends Block {
}
public float getStrength() {
return 0.4f;
return 0.6f;
}
public boolean blocksLight() {

View file

@ -1,15 +1,7 @@
package net.oikmo.engine.world.blocks;
/**
* Walk round them... bills
* @author Oikmo
*/
public class BlockGoldBlock extends Block {
/**
* Gold block constructor
* @param type Block type
*/
public BlockGoldBlock(Type type) {
super(type);
}
@ -19,7 +11,7 @@ public class BlockGoldBlock extends Block {
}
public float getStrength() {
return 0.6f;
return 1f;
}
public boolean blocksLight() {

View file

@ -1,15 +1,7 @@
package net.oikmo.engine.world.blocks;
/**
* Dirt with a nice green blanket
* @author Oikmo
*/
public class BlockGrass extends Block {
/**
* Grass block constructor
* @param type Block type
*/
public BlockGrass(Type type) {
super(type);
}
@ -19,7 +11,7 @@ public class BlockGrass extends Block {
}
public float getStrength() {
return 0.2f;
return 0.3f;
}
public boolean blocksLight() {

View file

@ -1,15 +1,7 @@
package net.oikmo.engine.world.blocks;
/**
* Iron block, holds iron
* @author Oikmo
*/
public class BlockIronBlock extends Block {
/**
* Iron block constructor
* @param type Block type
*/
public BlockIronBlock(Type type) {
super(type);
}
@ -19,7 +11,7 @@ public class BlockIronBlock extends Block {
}
public float getStrength() {
return 0.6f;
return 1f;
}
public boolean blocksLight() {

View file

@ -1,15 +1,7 @@
package net.oikmo.engine.world.blocks;
/**
* Mossy cobblestone?? Ewww
* @author Oikmo
*/
public class BlockMossyCobble extends Block {
/**
* Mossy cobblestone constructor
* @param type Block type
*/
public BlockMossyCobble(Type type) {
super(type);
}
@ -19,7 +11,7 @@ public class BlockMossyCobble extends Block {
}
public float getStrength() {
return 0.4f;
return 0.6f;
}
public boolean blocksLight() {

View file

@ -1,16 +1,8 @@
package net.oikmo.engine.world.blocks;
/**
* Leaves from a tree... now imagine that as a block.
* @author Oikmo
*/
public class BlockOakLeaves extends Block {
public class BlockOakLeaf extends Block {
/**
* Oak leaves
* @param type Block type
*/
public BlockOakLeaves(Type type) {
public BlockOakLeaf(Type type) {
super(type);
}

View file

@ -1,15 +1,7 @@
package net.oikmo.engine.world.blocks;
/**
* Oak logs of a oak tree
* @author Oikmo
*/
public class BlockOakLog extends Block {
/**
* Oak log contructor
* @param type Block type
*/
public BlockOakLog(Type type) {
super(type);
}

View file

@ -1,15 +1,7 @@
package net.oikmo.engine.world.blocks;
/**
* Planks from an oak tree
* @author Oikmo
*/
public class BlockOakPlanks extends Block {
/**
* Oak planks constructor
* @param type Block type
*/
public BlockOakPlanks(Type type) {
super(type);
}

View file

@ -1,15 +1,7 @@
package net.oikmo.engine.world.blocks;
/**
* Isn't this meant to be sharp?
* @author Oikmo
*/
public class BlockObsidian extends Block {
/**
* Obsidian block constructor
* @param type Block type
*/
public BlockObsidian(Type type) {
super(type);
}
@ -19,10 +11,10 @@ public class BlockObsidian extends Block {
}
public float getStrength() {
return 1f;
return 0.6f;
}
public boolean blocksLight() {
return false;
return true;
}
}

View file

@ -1,15 +1,7 @@
package net.oikmo.engine.world.blocks;
/**
* Stone block but smooth...
* @author Oikmo
*/
public class BlockSmoothStone extends Block {
/**
* Smooth stone constructor
* @param type Block type
*/
public BlockSmoothStone(Type type) {
super(type);
}

View file

@ -1,15 +1,7 @@
package net.oikmo.engine.world.blocks;
/**
* Stone block... The rock...
* @author Oikmo
*/
public class BlockStone extends Block {
/**
* Stone block constructor
* @param type Block type
*/
public BlockStone(Type type) {
super(type);
}

View file

@ -1,15 +1,7 @@
package net.oikmo.engine.world.blocks;
/**
* This one EXPLODES!!!!
* @author Oikmo
*/
public class BlockTNT extends Block {
/**
* TNT block constructor
* @param type Block type
*/
public BlockTNT(Type type) {
super(type);
}

View file

@ -6,8 +6,6 @@ import org.lwjgl.util.vector.Vector3f;
import net.oikmo.engine.world.World;
import net.oikmo.engine.world.blocks.Block;
import net.oikmo.engine.world.chunk.coordinate.ChunkCoordinates;
import net.oikmo.main.Main;
import net.oikmo.toolbox.Maths;
import net.oikmo.toolbox.noise.OpenSimplexNoise;
@ -17,131 +15,77 @@ import net.oikmo.toolbox.noise.OpenSimplexNoise;
* @author Oikmo
*/
public class Chunk {
/** Static size for all chunks */
public static final byte CHUNK_SIZE = 16;
/** Position of chunk in the world */
ChunkCoordinates origin;
/** Blocks array (holds block indexes) */
private byte[] blocks;
/** Holds the highest block heights */
public byte[][][] blocks;
private int[][] heights;
/** Light values */
private int[][][] lightDepths;
/**
* Creates an entirely new chunk in which it calls {@link #generateChunk(OpenSimplexNoise)} and generates light values {@link #calcLightDepths(int, int, int, int)}
* @param noiseGen Noise generator to use
* @param origin Position of chunk in the world
*/
public Chunk(OpenSimplexNoise noiseGen, ChunkCoordinates origin) {
blocks = new byte[32768];
public Chunk(OpenSimplexNoise noiseGen, Vector3f origin) {
blocks = new byte[CHUNK_SIZE][World.WORLD_HEIGHT][CHUNK_SIZE];
heights = new int[CHUNK_SIZE][CHUNK_SIZE];
this.origin = origin;
generateChunk(noiseGen);
generateChunk(origin, noiseGen);
this.lightDepths = new int[CHUNK_SIZE][World.WORLD_HEIGHT][CHUNK_SIZE];
}
/**
* Loads chunk using bytes
* @param blocks Given blocks array
* @param origin Position of chunk in the world
*/
public Chunk(byte[] blocks, ChunkCoordinates origin) {
this.blocks = blocks;
if(Maths.indexOf(blocks, new byte[] { -1 }) != -1) {
for(int i = 0; i < blocks.length; i++) {
blocks[i] = (byte) (blocks[i] + 1);
}
}
heights = new int[CHUNK_SIZE][CHUNK_SIZE];
this.lightDepths = new int[CHUNK_SIZE][World.WORLD_HEIGHT][CHUNK_SIZE];
this.origin = origin;
//calculateHeights();
this.calcLightDepths(0, 0, CHUNK_SIZE, CHUNK_SIZE);
}
/**
* Creates blocks from the top layer (given by {@link net.oikmo.toolbox.noise.OpenSimplexNoise}) and is extended down to YLevel 0 in which it is refactored by it's height.
* @param noiseGen The noise generator used to have the heights
*/
private void generateChunk(OpenSimplexNoise noiseGen) {
for (byte x = 0; x < CHUNK_SIZE; x++) {
for (byte z = 0; z < CHUNK_SIZE; z++) {
if(!Main.theWorld.superFlat) {
int actualX = origin.x + x;
int actualZ = origin.z + z;
int height = (int) ((noiseGen.noise(actualX/14f, actualZ/14f)*7f) + (noiseGen.noise((-actualZ)/16f,(-actualX)/16f)*12f) + (noiseGen.noise((actualZ)/6f,(actualX)/6f)*4f))+60;
//int height = 30;
setBlock(x, height, z, Block.grass.getByteType());
heights[x][z] = height+1;
for (int y = 0; y < World.WORLD_HEIGHT; y++) {
if(y < height) {
if(y > height - 4) {
setBlock(x, y, z, Block.dirt.getByteType());
} else if(y == 0) {
setBlock(x, y, z, Block.bedrock.getByteType());
} else {
setBlock(x, y, z, Block.stone.getByteType());
}
}
}
} else {
setBlock(x, 3, z, Block.grass.getByteType());
heights[x][z] = 3+1;
setBlock(x, 2, z, Block.dirt.getByteType());
setBlock(x, 1, z, Block.dirt.getByteType());
setBlock(x, 0, z, Block.bedrock.getByteType());
}
}
}
if(!Main.theWorld.superFlat) {
generateTrees(noiseGen.getSeed());
}
//alculateHeights();
public Chunk(byte[][][] blocks) {
this.blocks = blocks;
heights = new int[CHUNK_SIZE][CHUNK_SIZE];
this.lightDepths = new int[CHUNK_SIZE][World.WORLD_HEIGHT][CHUNK_SIZE];
this.calcLightDepths(0, 0, CHUNK_SIZE, CHUNK_SIZE);
calculateHeights();
calculateHeights();
}
/**
* Gets the brightness values from given vector
*
* @param x X position of block to check
* @param y Y position of block to check
* @param z Z position of block to check
* @return {@link Float}
* Creates blocks from the top layer (given by {@link PerlinNoiseGenerator}) and is extended down to YLevel 0 in which it is refactored via {@link #calculateBlockType(int)}
* @param origin
* @param noiseGen
*/
public float getBrightness(int x, int y, int z) {
if(x == -1 || y == -1 || z == -1 || x == CHUNK_SIZE || y == CHUNK_SIZE || z == CHUNK_SIZE) {
int actualX = origin.x + x;
int actualZ = origin.z + z;
ChunkCoordinates chunkPos = Maths.calculateChunkPosition(new Vector3f(actualX, y, actualZ));
MasterChunk m = Main.theWorld.getChunkFromPosition(chunkPos);
if(m != null) {
return m.getChunk().isLit(actualX-chunkPos.x, y, actualZ-chunkPos.z) ? 1.0F : 0.6F;
private void generateChunk(Vector3f origin, OpenSimplexNoise noiseGen) {
for (byte x = 0; x < CHUNK_SIZE; x++) {
for (byte z = 0; z < CHUNK_SIZE; z++) {
int actualX = (int) (origin.x + x);
int actualZ = (int) (origin.z + z);
int height = (int) ((noiseGen.noise(actualX/14f, actualZ/14f)*7f) + (noiseGen.noise((-actualZ)/16f,(-actualX)/16f)*12f) + (noiseGen.noise((actualZ)/6f,(actualX)/6f)*4f))+60;
blocks[x][height][z] = Block.grass.getByteType();
heights[x][z] = height+1;
for (int y = 0; y < World.WORLD_HEIGHT; y++) {
if(y < height) {
if(y > height - 4) {
blocks[x][y][z] = Block.dirt.getByteType();
} else if(y == 0) {
blocks[x][y][z] = Block.bedrock.getByteType();
} else {
blocks[x][y][z] = Block.stone.getByteType();
}
} else {
if(y != height) {
blocks[x][y][z] = -1;
}
}
}
}
}
generateTrees(noiseGen.getSeed());
calculateHeights();
}
public float getBrightness(int x, int y, int z) {
return this.isLit(x, y, z) ? 1.0F : 0.6F;
}
/**
* Calculates light brightness from a certain area in the chunk (going from the top to the bottom)
* @param minX Minimum X
* @param minZ Minimum Z
* @param maxX Maximum X
* @param maxZ Maximum Z
*/
public void calcLightDepths(int minX, int minZ, int maxX, int maxZ) {
for(int x = minX; x < minX + maxX; ++x) {
for(int z = minZ; z < minZ + maxZ; ++z) {
public void calcLightDepths(int x0, int y0, int x1, int y1) {
for(int x = x0; x < x0 + x1; ++x) {
for(int z = y0; z < y0 + y1; ++z) {
for(int y = 0; y < World.WORLD_HEIGHT; y++) {
int oldDepth = this.lightDepths[x][y][z];
int calculatedY;
for(calculatedY = World.WORLD_HEIGHT - 1; calculatedY > 0 && !this.isLightBlocker(x, calculatedY, z); --calculatedY) {}
for(calculatedY = World.WORLD_HEIGHT - 1; calculatedY > 0 && !this.isLightBlocker(x, calculatedY, z); --calculatedY) {
}
this.lightDepths[x][y][z] = calculatedY;
if(oldDepth != y) {
@ -152,33 +96,15 @@ public class Chunk {
}
}
/**
* Returns if the block at the given vector blocks the light
* @param x X position of block
* @param y Y position of block
* @param z Z position of block
* @return {@link Boolean}
*/
public boolean isLightBlocker(int x, int y, int z) {
Block block = Block.getBlockFromOrdinal((byte)getBlock(x, y, z));
return block == null ? false : block.blocksLight();
}
/**
* Checks if the specified vector has light or not
* @param x X position of block
* @param y Y position of block
* @param z Z position of block
* @return {@link Boolean}
*/
public boolean isLit(int x, int y, int z) {
return x >= 0 && y >= 0 && z >= 0 && x < CHUNK_SIZE && y < World.WORLD_HEIGHT && z < CHUNK_SIZE ? y >= this.lightDepths[x][y][z] : false;
}
/**
* Chooses a random area of the chunk and attempts to generate at that position
* @param seed World seed
*/
private void generateTrees(long seed) {
Random rand = new Random(seed);
@ -186,25 +112,21 @@ public class Chunk {
int x = new Random().nextInt(CHUNK_SIZE);
int z = new Random().nextInt(CHUNK_SIZE);
checkAndGenerateTree(x, z);
checkForTree(x, z);
}
}
/**
* Checks if it is in a valid range and has no oak leaves nearby, if so generate tree
* @param x X position of tree
* @param z Z position of tree
*/
private void checkAndGenerateTree(int x, int z) {
private void checkForTree(int x, int z) {
if(x > 2 && x < CHUNK_SIZE-2 && z > 2 && z < CHUNK_SIZE-2) {
int height = heights[x][z];
if(!blockHasSpecificNeighbours(Block.oaklog, x,height,z)) {
setBlock(x, height++, z, Block.oaklog.getByteType());
setBlock(x, height++, z, Block.oaklog.getByteType());
setBlock(x, height++, z, Block.oaklog.getByteType());
setBlock(x, height++, z, Block.oaklog.getByteType());
blocks[x][height++][z] = Block.oaklog.getByteType();
blocks[x][height++][z] = Block.oaklog.getByteType();
blocks[x][height++][z] = Block.oaklog.getByteType();
blocks[x][height++][z] = Block.oaklog.getByteType();
for(int j = 0; j < new Random().nextInt(2);j++) {
setBlock(x, height++, z, Block.oaklog.getByteType());
blocks[x][height++][z] = Block.oaklog.getByteType();
}
int index = height;
setBlock(Block.oakleaf, x, index, z);
@ -292,13 +214,13 @@ public class Chunk {
} else {
x = new Random().nextInt(CHUNK_SIZE);
z = new Random().nextInt(CHUNK_SIZE);
checkAndGenerateTree(x, z);
checkForTree(x, z);
}
}
private void setBlock(Block block, int x, int y, int z) {
if(getBlock(x,y,z) == Block.Type.AIR.ordinal()) {
setBlock(x,y,z, block.getByteType());
if(blocks[x][y][z] == -1) {
blocks[x][y][z] = block.getByteType();
}
}
@ -311,7 +233,7 @@ public class Chunk {
int checkerY = y + dy;
int checkerZ = z + dz;
if(getBlock(checkerX,checkerY,checkerZ) == block.getByteType()) {
if(blocks[checkerX][checkerY][checkerZ] == block.getByteType()) {
return true;
}
}
@ -324,7 +246,7 @@ public class Chunk {
for (byte x = 0; x < CHUNK_SIZE; x++) {
for (byte z = 0; z < CHUNK_SIZE; z++) {
for (int y = World.WORLD_HEIGHT - 1; y >= 0; y--) {
if (getBlock(x,y,z) != -1) {
if (blocks[x][y][z] != -1) {
heights[x][z] = y;
break;
}
@ -335,20 +257,14 @@ public class Chunk {
public void recalculateHeight(int x, int z) {
for (int y = World.WORLD_HEIGHT - 1; y >= 0; y--) {
if (getBlock(x,y,z) != Block.Type.AIR.ordinal()) {
if (blocks[x][y][z] != -1) {
heights[x][z] = y;
break;
}
}
}
/**
* Returns the height from
* @param origin
* @param position
* @return
*/
public int getHeightFromPosition(Vector3f position) {
public int getHeightFromPosition(Vector3f origin, Vector3f position) {
Vector3f rounded = Maths.roundVectorTo(position);
int x = (int) (rounded.x - origin.x);
if(x < 0) {x = 0;}
@ -359,43 +275,11 @@ public class Chunk {
return heights[x][z] + 2;
}
/**
* Returns the heighest point on specified coordinates
* @param x X coordinate
* @param z Y coordinate
* @return {@link Integer}
*/
public int getHeightFromPosition(int x, int z) {
return heights[x][z];
}
/**
* Sets a block ID for a position in the chunk.
* @param x X position of block
* @param y Y position of block
* @param z Z position of block
* @param block ID of block to be set to
*/
public void setBlock(int x, int y, int z, int block) {
blocks[x << 11 | z << 7 | y] = (byte)block;
}
/**
* Return the ID of a block in the chunk.
* @param x X position of block
* @param y Y position of block
* @param z Z position of block
* @return {@link Byte}
*/
public byte getBlock(int x, int y, int z) {
return blocks[x << 11 | z << 7 | y];
}
/**
* Returns the {@link #blocks} array
* @return {@link #blocks}[]
*/
public byte[] getBlocks() {
return blocks;
public int getBlock(int x, int y, int z) {
return blocks[x][y][z];
}
}

View file

@ -1,215 +0,0 @@
package net.oikmo.engine.world.chunk;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import net.oikmo.engine.nbt.NBTTagCompound;
import net.oikmo.engine.world.chunk.coordinate.ChunkCoordHelper;
import net.oikmo.main.Main;
import net.oikmo.toolbox.CompressedStreamTools;
public class ChunkLoader {
public ChunkLoader(File saveDir, boolean createIfNecessary) {
this.saveDir = saveDir;
if(!this.saveDir.exists()) {
this.saveDir.mkdirs();
}
this.createIfNecessary = !createIfNecessary;
}
private File chunkFileForXZ(int x, int z) {
String s = "c."+Integer.toString(x, 36)+"."+Integer.toString(z, 36)+".dat";
String s1 = Integer.toString(x & 0x3f, 36);
String s2 = Integer.toString(z & 0x3f, 36);
File file = new File(saveDir, s1);
if(!file.exists()) {
if(createIfNecessary) {
file.mkdir();
} else {
return null;
}
}
file = new File(file, s2);
if(!file.exists()) {
if(createIfNecessary) {
file.mkdir();
} else {
return null;
}
}
file = new File(file, s);
if(!file.exists() && !createIfNecessary) {
return null;
} else {
return file;
}
}
public MasterChunk loadChunk(int x, int z) {
File file = chunkFileForXZ(x, z);
if(file != null && file.exists()) {
try {
FileInputStream fileinputstream = new FileInputStream(file);
NBTTagCompound nbttagcompound = CompressedStreamTools.readCompressed(fileinputstream);
if(!nbttagcompound.hasKey("Level")) {
System.out.println((new StringBuilder()).append("Chunk file at ").append(x).append(",").append(z).append(" is missing level data, skipping").toString());
return null;
}
if(!nbttagcompound.getCompoundTag("Level").hasKey("Blocks")) {
System.out.println((new StringBuilder()).append("Chunk file at ").append(x).append(",").append(z).append(" is missing block data, skipping").toString());
return null;
}
MasterChunk chunk = loadChunkIntoWorldFromCompound(nbttagcompound.getCompoundTag("Level"));
if(!((int)chunk.getOrigin().x == x && (int)chunk.getOrigin().z == z)) {
System.out.println("Chunk file at "+x+","+z+" is in the wrong location; relocating. (Expected "+x+", "+z+", got "+chunk.getOrigin()+")");
nbttagcompound.setInteger("xPos", x);
nbttagcompound.setInteger("zPos", z);
chunk = loadChunkIntoWorldFromCompound(nbttagcompound.getCompoundTag("Level"));
}
return chunk;
} catch(Exception exception) {
exception.printStackTrace();
}
}
return null;
}
public void saveChunk(MasterChunk chunk) {
Main.theWorld.checkSessionLock();
File file = chunkFileForXZ((int)chunk.getOrigin().x, (int)chunk.getOrigin().z);
if(file != null && file.exists())
{
Main.theWorld.sizeOnDisk -= file.length();
}
try {
File file1 = new File(saveDir, "tmp_chunk.dat");
FileOutputStream fileoutputstream = new FileOutputStream(file1);
NBTTagCompound nbttagcompound = new NBTTagCompound();
NBTTagCompound nbttagcompound1 = new NBTTagCompound();
nbttagcompound.setTag("Level", nbttagcompound1);
storeChunkInCompound(chunk, nbttagcompound1);
CompressedStreamTools.writeGzippedCompoundToOutputStream(nbttagcompound, fileoutputstream);
fileoutputstream.close();
if(file != null) {
if(file.exists()) {
file.delete();
}
file1.renameTo(file);
Main.theWorld.sizeOnDisk += file.length();
}
} catch(Exception e) {
e.printStackTrace();
}
}
public void storeChunkInCompound(MasterChunk chunk, NBTTagCompound nbttagcompound) {
nbttagcompound.setInteger("xPos", chunk.getOrigin().x);
nbttagcompound.setInteger("zPos", chunk.getOrigin().z);
nbttagcompound.setByteArray("Blocks", chunk.getChunk().getBlocks());
/*
nbttagcompound.setLong("LastUpdate", world.worldTime);
nbttagcompound.setByteArray("Data", chunk.data.data);
nbttagcompound.setByteArray("SkyLight", chunk.skylightMap.data);
nbttagcompound.setByteArray("BlockLight", chunk.blocklightMap.data);
nbttagcompound.setByteArray("HeightMap", chunk.heightMap);
nbttagcompound.setBoolean("TerrainPopulated", chunk.isTerrainPopulated);
chunk.hasEntities = false;
NBTTagList nbttaglist = new NBTTagList();
for(int i = 0; i < chunk.entities.length; i++)
{
Iterator<?> iterator = chunk.entities[i].iterator();
do
{
if(!iterator.hasNext())
{
continue label0;
}
Entity entity = (Entity)iterator.next();
chunk.hasEntities = true;
NBTTagCompound nbttagcompound1 = new NBTTagCompound();
if(entity.func_358_c(nbttagcompound1))
{
nbttaglist.setTag(nbttagcompound1);
}
} while(true);
}
nbttagcompound.setTag("Entities", nbttaglist);
NBTTagList nbttaglist1 = new NBTTagList();
NBTTagCompound nbttagcompound2;
for(Iterator<?> iterator1 = chunk.chunkTileEntityMap.values().iterator(); iterator1.hasNext(); nbttaglist1.setTag(nbttagcompound2))
{
TileEntity tileentity = (TileEntity)iterator1.next();
nbttagcompound2 = new NBTTagCompound();
tileentity.writeToNBT(nbttagcompound2);
}
nbttagcompound.setTag("TileEntities", nbttaglist1);*/
}
public static MasterChunk loadChunkIntoWorldFromCompound(NBTTagCompound nbttagcompound) {
int x = nbttagcompound.getInteger("xPos");
int z = nbttagcompound.getInteger("zPos");
MasterChunk chunk = new MasterChunk(ChunkCoordHelper.create(x,z), nbttagcompound.getByteArray("Blocks"));
/*chunk.data = new NibbleArray(nbttagcompound.getByteArray("Data"));
chunk.skylightMap = new NibbleArray(nbttagcompound.getByteArray("SkyLight"));
chunk.blocklightMap = new NibbleArray(nbttagcompound.getByteArray("BlockLight"));
chunk.heightMap = nbttagcompound.getByteArray("HeightMap");
chunk.isTerrainPopulated = nbttagcompound.getBoolean("TerrainPopulated");
if(!chunk.data.isValid())
{
chunk.data = new NibbleArray(chunk.blocks.length);
}
if(chunk.heightMap == null || !chunk.skylightMap.isValid())
{
chunk.heightMap = new byte[256];
chunk.skylightMap = new NibbleArray(chunk.blocks.length);
chunk.func_1024_c();
}
if(!chunk.blocklightMap.isValid())
{
chunk.blocklightMap = new NibbleArray(chunk.blocks.length);
chunk.func_1014_a();
}
NBTTagList nbttaglist = nbttagcompound.getTagList("Entities");
if(nbttaglist != null)
{
for(int k = 0; k < nbttaglist.tagCount(); k++)
{
NBTTagCompound nbttagcompound1 = (NBTTagCompound)nbttaglist.tagAt(k);
Entity entity = EntityList.createEntityFromNBT(nbttagcompound1, world);
chunk.hasEntities = true;
if(entity != null)
{
chunk.addEntity(entity);
}
}
}
NBTTagList nbttaglist1 = nbttagcompound.getTagList("TileEntities");
if(nbttaglist1 != null)
{
for(int l = 0; l < nbttaglist1.tagCount(); l++)
{
NBTTagCompound nbttagcompound2 = (NBTTagCompound)nbttaglist1.tagAt(l);
TileEntity tileentity = TileEntity.createAndLoadEntity(nbttagcompound2);
if(tileentity != null)
{
chunk.func_1001_a(tileentity);
}
}
}*/
return chunk;
}
private File saveDir;
private boolean createIfNecessary;
}

View file

@ -13,12 +13,14 @@ import net.oikmo.engine.world.blocks.Block;
public class ChunkMesh {
private List<Vertex> vertices;
public int[] positions, normals;
public float[] uvs;
private HashMap<Vector3f, Vertex> uniqueVertices = new HashMap<>();
public float[] positions, uvs, normals;
public ChunkMesh(Chunk chunk) {
vertices = new ArrayList<Vertex>();
buildMesh(chunk);
populateLists();
}
private void buildMesh(Chunk chunk) {
@ -26,10 +28,10 @@ public class ChunkMesh {
for (byte x = 0; x < Chunk.CHUNK_SIZE; x++) {
for (int y = 0; y < World.WORLD_HEIGHT; y++) {
for (byte z = 0; z < Chunk.CHUNK_SIZE; z++) {
byte blockI = chunk.getBlock(x, y, z);
byte blockI = chunk.blocks[x][y][z];
boolean px = false, nx = false, py = false, ny = false, pz = false, nz = false;
if(blockI == Block.Type.AIR.ordinal()) { continue; } //skip it
if(blockI == -1) { continue; } //skip it
// Loop through the neighbouring blocks
for (byte dx = -1; dx <= 1; dx++) {
@ -49,9 +51,9 @@ public class ChunkMesh {
if (neighborX >= 0 && neighborX < Chunk.CHUNK_SIZE &&
neighborY >= 0 && neighborY < World.WORLD_HEIGHT &&
neighborZ >= 0 && neighborZ < Chunk.CHUNK_SIZE) {
byte blockJ = chunk.getBlock(neighborX, neighborY, neighborZ);
if(blockJ == Block.Type.AIR.ordinal() || (blockI != Block.glass.getByteType() && blockJ == Block.glass.getByteType()) || (blockI == Block.oakleaf.getByteType() || blockJ == Block.oakleaf.getByteType())) { continue; } //skip it
byte blockJ = chunk.blocks[neighborX][neighborY][neighborZ];
if(blockJ == -1 || (blockI != Block.glass.getByteType() && blockJ == Block.glass.getByteType()) || (blockI == Block.oakleaf.getByteType() || blockJ == Block.oakleaf.getByteType())) { continue; } //skip it
//PX
if(((x + 1) == (neighborX)) && ((y) == (neighborY)) && ((z) == (neighborZ))) {
@ -77,7 +79,6 @@ public class ChunkMesh {
if(((x) == (neighborX)) && ((y) == (neighborY)) && ((z - 1) == (neighborZ))) {
nz = true;
}
} else {
}
}
}
@ -91,79 +92,60 @@ public class ChunkMesh {
if (!px) {
c = chunk.getBrightness(x+1,y,z);
addFaceVertices(chunk, blockI, x, y, z, CubeModel.PX_POS, CubeModel.UV_PX, c3*c);
Vector3f lightVec = new Vector3f(c3*c,c3*c,c3*c);
addFaceVertices(blockI, x, y, z, CubeModel.PX_POS, CubeModel.UV_PX, lightVec);
}
if (!nx) {
c = chunk.getBrightness(x-1,y,z);
addFaceVertices(chunk, blockI, x, y, z, CubeModel.NX_POS, CubeModel.UV_NX, c*c3);
Vector3f lightVec = new Vector3f(c*c3,c*c3,c*c3);
addFaceVertices(blockI, x, y, z, CubeModel.NX_POS, CubeModel.UV_NX, lightVec);
}
if (!py) {
c = chunk.getBrightness(x, y+1, z);
addFaceVertices(chunk, blockI, x, y, z, CubeModel.PY_POS, CubeModel.UV_PY, c*1f);
Vector3f lightVec = new Vector3f(c*1f,c*1f,c*1f);
addFaceVertices(blockI, x, y, z, CubeModel.PY_POS, CubeModel.UV_PY, lightVec);
}
if (!ny) {
c = chunk.getBrightness(x, y-1, z);
addFaceVertices(chunk, blockI, x, y, z, CubeModel.NY_POS, CubeModel.UV_NY, c*c1);
Vector3f lightVec = new Vector3f(c*c1,c*c1,c*c1);
addFaceVertices(blockI, x, y, z, CubeModel.NY_POS, CubeModel.UV_NY, lightVec);
}
if (!pz) {
c = chunk.getBrightness(x,y,z+1);
addFaceVertices(chunk, blockI, x, y, z, CubeModel.PZ_POS, CubeModel.UV_PZ, c*c2);
Vector3f lightVec = new Vector3f(c*c2,c*c2,c*c2);
addFaceVertices(blockI, x, y, z, CubeModel.PZ_POS, CubeModel.UV_PZ, lightVec);
}
if (!nz) {
c = chunk.getBrightness(x,y,z-1);
addFaceVertices(chunk, blockI, x, y, z, CubeModel.NZ_POS, CubeModel.UV_NZ, c*c2);
Vector3f lightVec = new Vector3f(c*c2,c*c2,c*c2);
addFaceVertices(blockI, x, y, z, CubeModel.NZ_POS, CubeModel.UV_NZ, lightVec);
}
}
}
}
int numVertices = vertices.size();
positions = new int[numVertices]; // Each vertex has 3 position components
uvs = new float[numVertices * 2]; // Each vertex has 2 uv components
normals = new int[numVertices]; // Each vertex has 3 normal components
for(int i = 0; i < numVertices; i++) {
Vertex vertex = vertices.get(i);
int positionIndex = i;
int uvIndex = i * 2;
int normalIndex = i;
positions[positionIndex] = vertex.posX;
positions[positionIndex] += (vertex.posY << 8);
positions[positionIndex] += (vertex.posZ << 16);
uvs[uvIndex] = vertex.uvs.x;
uvs[uvIndex + 1] = vertex.uvs.y;
normals[normalIndex] = vertex.normal;
}
//uniqueVertices.get(chunk).clear();
//uniqueVertices.remove(chunk);
vertices.clear();
}
private void addFaceVertices(Chunk chunk, byte block, int x, int y, int z, Vector3f[] positions, Vector2f[] uvs, float normal) {
private void addFaceVertices(byte block, int x, int y, int z, Vector3f[] positions, Vector2f[] uvs, Vector3f normals) {
byte type = block;
int startIndex = type * 6;
for (int k = 0; k < 6; k++) {
Vector3f position = new Vector3f(positions[k].x + x, positions[k].y + y, positions[k].z + z);
/*Vertex vertex = uniqueVertices.get(chunk).get(position);
if(vertex == null) {
vertex = new Vertex(position, normal, uvs[startIndex + k]);
uniqueVertices.get(chunk).put(position,vertex);
}*/
vertices.add(new Vertex(position, normal, uvs[startIndex + k]));
Vertex vertex = uniqueVertices.get(position);
if (vertex == null) {
vertex = new Vertex(position, normals, uvs[startIndex + k]);
uniqueVertices.put(position, vertex);
vertices.add(vertex);
}
//block.setFaceIndex(k, vertices.indexOf(vertex));
}
}
@ -171,10 +153,35 @@ public class ChunkMesh {
public void removeMeshInfo() {
this.positions = null;
this.uvs = null;
this.normals = null;
this.normals = null;
}
public boolean hasMeshInfo() {
return this.positions != null && this.uvs != null && this.normals != null;
}
private void populateLists() {
int numVertices = vertices.size();
positions = new float[numVertices * 3]; // Each vertex has 3 position components
uvs = new float[numVertices * 2]; // Each vertex has 2 uv components
normals = new float[numVertices * 3]; // Each vertex has 3 normal components
for(int i = 0; i < numVertices; i++) {
Vertex vertex = vertices.get(i);
int positionIndex = i * 3;
int uvIndex = i * 2;
int normalIndex = i * 3;
positions[positionIndex] = vertex.positions.x;
positions[positionIndex + 1] = vertex.positions.y;
positions[positionIndex + 2] = vertex.positions.z;
uvs[uvIndex] = vertex.uvs.x;
uvs[uvIndex + 1] = vertex.uvs.y;
normals[normalIndex] = vertex.normals.x;
normals[normalIndex + 1] = vertex.normals.y;
normals[normalIndex + 2] = vertex.normals.z;
}
}
}

View file

@ -7,36 +7,32 @@ import org.lwjgl.util.vector.Vector3f;
import com.mojang.minecraft.particle.Particle;
import net.oikmo.engine.entity.Entity;
import net.oikmo.engine.entity.PrimedTNT;
import net.oikmo.engine.network.packet.PacketPlaySoundAt;
import net.oikmo.engine.renderers.chunk.ChunkEntity;
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.coordinate.ChunkCoordinates;
import net.oikmo.main.Main;
import net.oikmo.network.shared.PacketPlaySoundAt;
import net.oikmo.toolbox.Maths;
import net.oikmo.toolbox.noise.OpenSimplexNoise;
public class MasterChunk {
private ChunkCoordinates origin;
private Vector3f origin;
private Chunk chunk;
private ChunkMesh mesh;
private ChunkEntity entity;
public static final int networkMaxTime = 60*(5);
public static final int localMaxTime = 60*(30);
public int timer = networkMaxTime;
private Entity entity;
public static final int maxTime = 60*(5);
public int timer = maxTime;
public boolean dirty = true;
public MasterChunk(OpenSimplexNoise noiseGen, ChunkCoordinates origin) {
public MasterChunk(OpenSimplexNoise noiseGen, Vector3f origin) {
this.origin = origin;
this.chunk = new Chunk(noiseGen, origin);
}
public MasterChunk(ChunkCoordinates origin, byte[] blocks) {
public MasterChunk(Vector3f origin, byte[][][] blocks) {
this.origin = origin;
this.chunk = new Chunk(blocks, origin);
this.chunk = new Chunk(blocks);
}
public Block getBlock(Vector3f position) {
@ -53,7 +49,7 @@ public class MasterChunk {
}
if(Maths.isWithinChunk(localX, localY, localZ)) {
Block block = Block.getBlockFromOrdinal(chunk.getBlock(localX, localY, localZ));
Block block = Block.getBlockFromOrdinal(chunk.blocks[localX][localY][localZ]);
return block;
}
return null;
@ -61,9 +57,7 @@ public class MasterChunk {
public void setBlockNoUpdate(Vector3f position, Block block) {
Chunk chunk = getChunk();
int x = (int)position.x;
int y = (int)position.y;
int z = (int)position.z;
//Main.theWorld.refreshChunk(this);
int localX = (int)(position.x + getOrigin().x)%16;
int localY = (int) position.y;
int localZ = (int)(position.z + getOrigin().z)%16;
@ -77,25 +71,15 @@ public class MasterChunk {
if (Maths.isWithinChunk(localX, localY, localZ)) {
if (block != null) {
if (chunk.getBlock(localX, localY, localZ) == Block.Type.AIR.ordinal()) {
if(chunk.getBlock(localX, localY, localZ) != block.getByteType()) {
chunk.setBlock(localX, localY, localZ, block.getByteType());
dirty = true;
if (chunk.blocks[localX][localY][localZ] == -1) {
if(chunk.blocks[localX][localY][localZ] != block.getByteType()) {
chunk.blocks[localX][localY][localZ] = block.getByteType();
}
}
} else {
if(chunk.getBlock(localX, localY, localZ) != Block.Type.AIR.ordinal() && localY != 0) {
byte blockID = chunk.getBlock(localX, localY, localZ);
if(Main.theNetwork == null) {
if(blockID == Block.tnt.getType()) {
Main.theWorld.addEntity(new PrimedTNT(new Vector3f(x, y, z), new Random().nextInt(10)/10f, 0.1f, new Random().nextInt(10)/10f, true));
}
}
chunk.setBlock(localX, localY, localZ, Block.Type.AIR.ordinal());
dirty = true;
if(chunk.blocks[localX][localY][localZ] != -1 && chunk.blocks[localX][localY][localZ] != Block.bedrock.getByteType()) {
chunk.blocks[localX][localY][localZ] = -1;
}
}
}
}
@ -124,11 +108,16 @@ public class MasterChunk {
localZ = localZ+16;
}
if(localY == -1) {
Main.theWorld.refreshChunk(this);
}
if (Maths.isWithinChunk(localX, localY, localZ)) {
if (block != null) {
if(chunk.getBlock(localX, localY, localZ) == Block.Type.AIR.ordinal()) {
if(chunk.getBlock(localX, localY, localZ) != block.getByteType()) {
chunk.setBlock(localX, localY, localZ, block.getByteType());
if (chunk.blocks[localX][localY][localZ] == -1 ) {
if(chunk.blocks[localX][localY][localZ] != block.getByteType()) {
chunk.blocks[localX][localY][localZ] = block.getByteType();
if(chunk.getHeightFromPosition(localX, localZ) < localY) {
chunk.recalculateHeight(localX, localZ);
}
@ -144,41 +133,47 @@ public class MasterChunk {
Main.theNetwork.client.sendTCP(packet);
}
getChunk().calcLightDepths(localX, localZ, 1, 1);
dirty = true;
Main.theWorld.refreshChunk(this);
}
} else {
return;
}
} else {
if(localY != 0) {
byte blockID = chunk.getBlock(localX, localY, localZ);
if(chunk.getBlock(localX, localY, localZ) != Block.Type.AIR.ordinal()) {
chunk.setBlock(localX, localY, localZ, Block.Type.AIR.ordinal());
if(chunk.blocks[localX][localY][localZ] != Block.bedrock.getByteType()) {
Block whatUsedToBeThere = Block.getBlockFromOrdinal(chunk.blocks[localX][localY][localZ]);
if(chunk.blocks[localX][localY][localZ] != -1) {
chunk.blocks[localX][localY][localZ] = -1;
}
if(blockID != -1) {
SoundMaster.playBlockBreakSFX(Block.getBlockFromOrdinal(blockID), x,y,z);
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.125f, particleY+0.125f, particleZ+0.125f, particleX - (float)x, particleY - (float)y, particleZ - (float)z, Block.getBlockFromOrdinal(blockID));
Main.theWorld.spawnParticle(particle);
}
SoundMaster.playBlockBreakSFX(whatUsedToBeThere, x,y,z);
if(Main.theNetwork != null) {
PacketPlaySoundAt packet = new PacketPlaySoundAt();
packet.blockID = whatUsedToBeThere.getByteType();
packet.x = x;
packet.y = y;
packet.z = z;
Main.theNetwork.client.sendTCP(packet);
}
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.125f, particleY+0.125f, particleZ+0.125f, particleX - (float)x, particleY - (float)y, particleZ - (float)z, whatUsedToBeThere);
Main.theWorld.spawnParticle(particle);
}
}
}
if(Main.theNetwork != null) {
if(blockID == Block.tnt.getType()) {
Main.theWorld.addEntity(new PrimedTNT(new Vector3f(x, y, z), new Random().nextInt(10)/10f, 0.1f, new Random().nextInt(10)/10f, true));
if(Main.theNetwork != null && !owner) {
if(whatUsedToBeThere.getByteType() == Block.tnt.getType()) {
Main.theWorld.addEntity(new PrimedTNT(new Vector3f(x,y,z), new Random().nextInt(10)/10f, 0.1f, new Random().nextInt(10)/10f, false));
}
}
getChunk().calcLightDepths(localX, localZ, 1, 1);
dirty = true;
Main.theWorld.refreshChunk(this);
}
}
@ -196,10 +191,10 @@ public class MasterChunk {
if(Maths.isWithinChunk(localX, localZ)) {
for (int y = World.WORLD_HEIGHT - 1; y >= 0; y--) {
try {
if(getChunk().getBlock(localX, y, localZ) != -1) {
if(getChunk().getBlock(localX, y, localZ) != block.getByteType()) {
getChunk().setBlock(localX, y - 0, localZ, block.getByteType());
dirty = true;
if (getChunk().blocks[localX][y][localZ] != -1) {
if(getChunk().blocks[localX][y][localZ] != block.getByteType()) {
getChunk().blocks[localX][y - 0][localZ] = block.getByteType();
Main.theWorld.refreshChunk(this);
break;
}
}
@ -209,13 +204,13 @@ public class MasterChunk {
}
}
public void replaceBlocks(byte[] blocks) {
this.chunk = new Chunk(blocks, origin);
public void replaceBlocks(byte[][][] blocks) {
this.chunk = new Chunk(blocks);
this.mesh = new ChunkMesh(chunk);
this.entity = null;
}
public ChunkCoordinates getOrigin() {
public Vector3f getOrigin() {
return origin;
}
@ -235,11 +230,11 @@ public class MasterChunk {
this.mesh = new ChunkMesh(this.chunk);
}
public ChunkEntity getEntity() {
public Entity getEntity() {
return entity;
}
public void setEntity(ChunkEntity entity) {
public void setEntity(Entity entity) {
this.entity = entity;
}
}

View file

@ -5,15 +5,11 @@ import org.lwjgl.util.vector.Vector3f;
public class Vertex {
public int posX, posY, posZ;
public int normal;
public Vector3f positions, normals;
public Vector2f uvs;
public Vertex(Vector3f positions, float normal, Vector2f uvs) {
posX = (int)positions.x;
posY = (int)positions.y;
posZ = (int)positions.z;
this.normal = (int)(normal*100f);
public Vertex(Vector3f positions, Vector3f normals, Vector2f uvs) {
this.positions = positions;
this.normals = normals;
this.uvs = uvs;
}

View file

@ -1,30 +0,0 @@
package net.oikmo.engine.world.chunk.coordinate;
import java.util.ArrayList;
import java.util.List;
public class ChunkCoordHelper {
private static List<ChunkCoordinates> coords = new ArrayList<>();
public static ChunkCoordinates create(int x, int z) {
ChunkCoordinates coord = new ChunkCoordinates(x, z);
if(coords.contains(coord)) {
if(coords.indexOf(coord) == -1) {
coords.add(coord);
return coord;
}
return coords.get(coords.indexOf(coord));
} else {
//System.gc();
coords.add(coord);
return coord;
}
}
public static void cleanUp() {
System.out.println("clean");
coords.clear();
System.gc();
}
}

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