Compare commits
106 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
197a753558 | |
|
|
2057d78cd0 | |
|
|
01a86a5a1e | |
|
|
8489503192 | |
|
|
8f3c65633e | |
|
|
51c5e52057 | |
|
|
69eacab225 | |
|
|
6ef6277148 | |
|
|
02355bfedc | |
|
|
8ca2fe6b91 | |
|
|
9394ae9ac1 | |
|
|
1e1cc5fb5b | |
|
|
ce06e1bb53 | |
|
|
76fce435b1 | |
|
|
c5e36b6f79 | |
|
|
a6b8edcd67 | |
|
|
877c5371a0 | |
|
|
0cbb9c8551 | |
|
|
5de32258ca | |
|
|
70d7faaf98 | |
|
|
25314cfebb | |
|
|
7c176bbcde | |
|
|
e08cdf66fc | |
|
|
6ee17375a6 | |
|
|
20b1dac4a6 | |
|
|
d5815eef50 | |
|
|
6e69fe2fcd | |
|
|
505a09a4ff | |
|
|
261ba8c69b | |
|
|
d88b0946b5 | |
|
|
af72420f9d | |
|
|
c60d03428d | |
|
|
507e1ada0e | |
|
|
fdf5fad146 | |
|
|
96eb85d55a | |
|
|
16b04a62ba | |
|
|
2946a7ec9e | |
|
|
96a0f0fdb9 | |
|
|
c4250dcfff | |
|
|
3cf6f0cc1e | |
|
|
5bd3984997 | |
|
|
ff3bb85d7c | |
|
|
135d6ef185 | |
|
|
fe1f97f248 | |
|
|
55ea5e6c55 | |
|
|
afd16a7389 | |
|
|
3838754611 | |
|
|
4f7b499217 | |
|
|
4b527a0db0 | |
|
|
321d07ceb6 | |
|
|
a0d6d87dcf | |
|
|
0ee4243011 | |
|
|
ecfb03d62d | |
|
|
7ffa6c1023 | |
|
|
4f9cb191c4 | |
|
|
878410abbf | |
|
|
0098d22927 | |
|
|
01d221c94a | |
|
|
8c29c924f6 | |
|
|
3b612fc61d | |
|
|
7b8de0fa63 | |
|
|
eacf39f27b | |
|
|
b483234d9c | |
|
|
b553923a3d | |
|
|
95bd4df7ef | |
|
|
7dbe75a497 | |
|
|
9e6ef227cc | |
|
|
400746b88a | |
|
|
3c9b7a23e9 | |
|
|
d24f9296a5 | |
|
|
5aa5a6a989 | |
|
|
fe759d7b28 | |
|
|
7ca1d80e6a | |
|
|
b2f26fd838 | |
|
|
5f83236d3b | |
|
|
b8d6f2720b | |
|
|
9584f7c882 | |
|
|
f26416a6d5 | |
|
|
25e4123d7a | |
|
|
1fe8670169 | |
|
|
4a53342a73 | |
|
|
868b3481ee | |
|
|
40a0c6474d | |
|
|
ace02dbddf | |
|
|
90c7707e5a | |
|
|
3a25f34520 | |
|
|
bc43eade55 | |
|
|
ef6fe56c89 | |
|
|
d88b433b11 | |
|
|
1acd28662c | |
|
|
4b9ee51690 | |
|
|
d4426b8b3c | |
|
|
26d55ab6ca | |
|
|
51ece50ac0 | |
|
|
85728d450b | |
|
|
54b6262813 | |
|
|
b672a176b8 | |
|
|
b15b396935 | |
|
|
888e359f9c | |
|
|
a1488570d9 | |
|
|
1343535933 | |
|
|
e48d0cfc6c | |
|
|
121c6f10eb | |
|
|
745305e2f3 | |
|
|
44a6cedf3a | |
|
|
bb13aaa09f |
|
|
@ -1,9 +1,47 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<classpath>
|
<classpath>
|
||||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="module" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
<classpathentry kind="src" path="src"/>
|
<classpathentry kind="src" path="src"/>
|
||||||
<classpathentry kind="lib" path="/home/josua/code/Java Libraries/binary-data-format-v1.3.jar"/>
|
<classpathentry kind="lib" path="/home/josua/code/Java Libraries/binary-data-format-v3.0.jar"/>
|
||||||
|
<classpathentry kind="lib" path="/home/josua/code/Java Libraries/GlEngine.jar"/>
|
||||||
<classpathentry kind="lib" path="/home/josua/code/Java Libraries/mainloop.jar"/>
|
<classpathentry kind="lib" path="/home/josua/code/Java Libraries/mainloop.jar"/>
|
||||||
<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/LWJGL"/>
|
<classpathentry kind="lib" path="/home/josua/code/Java Libraries/lwjgl-3.2.2-lightweight/lwjgl.jar"/>
|
||||||
|
<classpathentry kind="lib" path="/home/josua/code/Java Libraries/lwjgl-3.2.2-lightweight/lwjgl-glfw.jar"/>
|
||||||
|
<classpathentry kind="lib" path="/home/josua/code/Java Libraries/lwjgl-3.2.2-lightweight/lwjgl-glfw-javadoc.jar"/>
|
||||||
|
<classpathentry kind="lib" path="/home/josua/code/Java Libraries/lwjgl-3.2.2-lightweight/lwjgl-glfw-natives-linux.jar"/>
|
||||||
|
<classpathentry kind="lib" path="/home/josua/code/Java Libraries/lwjgl-3.2.2-lightweight/lwjgl-glfw-natives-macos.jar"/>
|
||||||
|
<classpathentry kind="lib" path="/home/josua/code/Java Libraries/lwjgl-3.2.2-lightweight/lwjgl-glfw-natives-windows.jar"/>
|
||||||
|
<classpathentry kind="lib" path="/home/josua/code/Java Libraries/lwjgl-3.2.2-lightweight/lwjgl-glfw-sources.jar"/>
|
||||||
|
<classpathentry kind="lib" path="/home/josua/code/Java Libraries/lwjgl-3.2.2-lightweight/lwjgl-natives-linux.jar"/>
|
||||||
|
<classpathentry kind="lib" path="/home/josua/code/Java Libraries/lwjgl-3.2.2-lightweight/lwjgl-natives-macos.jar"/>
|
||||||
|
<classpathentry kind="lib" path="/home/josua/code/Java Libraries/lwjgl-3.2.2-lightweight/lwjgl-natives-windows.jar"/>
|
||||||
|
<classpathentry kind="lib" path="/home/josua/code/Java Libraries/lwjgl-3.2.2-lightweight/lwjgl-openal.jar"/>
|
||||||
|
<classpathentry kind="lib" path="/home/josua/code/Java Libraries/lwjgl-3.2.2-lightweight/lwjgl-openal-javadoc.jar"/>
|
||||||
|
<classpathentry kind="lib" path="/home/josua/code/Java Libraries/lwjgl-3.2.2-lightweight/lwjgl-openal-natives-linux.jar"/>
|
||||||
|
<classpathentry kind="lib" path="/home/josua/code/Java Libraries/lwjgl-3.2.2-lightweight/lwjgl-openal-natives-macos.jar"/>
|
||||||
|
<classpathentry kind="lib" path="/home/josua/code/Java Libraries/lwjgl-3.2.2-lightweight/lwjgl-openal-natives-windows.jar"/>
|
||||||
|
<classpathentry kind="lib" path="/home/josua/code/Java Libraries/lwjgl-3.2.2-lightweight/lwjgl-openal-sources.jar"/>
|
||||||
|
<classpathentry kind="lib" path="/home/josua/code/Java Libraries/lwjgl-3.2.2-lightweight/lwjgl-opengl.jar"/>
|
||||||
|
<classpathentry kind="lib" path="/home/josua/code/Java Libraries/lwjgl-3.2.2-lightweight/lwjgl-opengles.jar"/>
|
||||||
|
<classpathentry kind="lib" path="/home/josua/code/Java Libraries/lwjgl-3.2.2-lightweight/lwjgl-opengles-javadoc.jar"/>
|
||||||
|
<classpathentry kind="lib" path="/home/josua/code/Java Libraries/lwjgl-3.2.2-lightweight/lwjgl-opengles-natives-linux.jar"/>
|
||||||
|
<classpathentry kind="lib" path="/home/josua/code/Java Libraries/lwjgl-3.2.2-lightweight/lwjgl-opengles-natives-macos.jar"/>
|
||||||
|
<classpathentry kind="lib" path="/home/josua/code/Java Libraries/lwjgl-3.2.2-lightweight/lwjgl-opengles-natives-windows.jar"/>
|
||||||
|
<classpathentry kind="lib" path="/home/josua/code/Java Libraries/lwjgl-3.2.2-lightweight/lwjgl-opengles-sources.jar"/>
|
||||||
|
<classpathentry kind="lib" path="/home/josua/code/Java Libraries/lwjgl-3.2.2-lightweight/lwjgl-opengl-javadoc.jar"/>
|
||||||
|
<classpathentry kind="lib" path="/home/josua/code/Java Libraries/lwjgl-3.2.2-lightweight/lwjgl-opengl-natives-linux.jar"/>
|
||||||
|
<classpathentry kind="lib" path="/home/josua/code/Java Libraries/lwjgl-3.2.2-lightweight/lwjgl-opengl-natives-macos.jar"/>
|
||||||
|
<classpathentry kind="lib" path="/home/josua/code/Java Libraries/lwjgl-3.2.2-lightweight/lwjgl-opengl-natives-windows.jar"/>
|
||||||
|
<classpathentry kind="lib" path="/home/josua/code/Java Libraries/lwjgl-3.2.2-lightweight/lwjgl-opengl-sources.jar"/>
|
||||||
|
<classpathentry kind="lib" path="/home/josua/code/Java Libraries/lwjgl-3.2.2-lightweight/lwjgl-stb.jar"/>
|
||||||
|
<classpathentry kind="lib" path="/home/josua/code/Java Libraries/lwjgl-3.2.2-lightweight/lwjgl-stb-javadoc.jar"/>
|
||||||
|
<classpathentry kind="lib" path="/home/josua/code/Java Libraries/lwjgl-3.2.2-lightweight/lwjgl-stb-natives-linux.jar"/>
|
||||||
|
<classpathentry kind="lib" path="/home/josua/code/Java Libraries/lwjgl-3.2.2-lightweight/lwjgl-stb-natives-macos.jar"/>
|
||||||
|
<classpathentry kind="lib" path="/home/josua/code/Java Libraries/lwjgl-3.2.2-lightweight/lwjgl-stb-natives-windows.jar"/>
|
||||||
|
<classpathentry kind="lib" path="/home/josua/code/Java Libraries/lwjgl-3.2.2-lightweight/lwjgl-stb-sources.jar"/>
|
||||||
<classpathentry kind="output" path="bin"/>
|
<classpathentry kind="output" path="bin"/>
|
||||||
</classpath>
|
</classpath>
|
||||||
|
|
|
||||||
|
|
@ -1 +1,3 @@
|
||||||
/bin/
|
/bin/
|
||||||
|
/run/
|
||||||
|
hs_err_pid*
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<projectDescription>
|
<projectDescription>
|
||||||
<name>ShooterGame</name>
|
<name>ProjectZombie</name>
|
||||||
<comment></comment>
|
<comment></comment>
|
||||||
<projects>
|
<projects>
|
||||||
</projects>
|
</projects>
|
||||||
|
|
|
||||||
Binary file not shown.
Binary file not shown.
|
Before Width: | Height: | Size: 56 KiB |
Binary file not shown.
1120
hs_err_pid31967.log
1120
hs_err_pid31967.log
File diff suppressed because it is too large
Load Diff
1119
hs_err_pid613.log
1119
hs_err_pid613.log
File diff suppressed because it is too large
Load Diff
1120
hs_err_pid675.log
1120
hs_err_pid675.log
File diff suppressed because it is too large
Load Diff
1120
hs_err_pid713.log
1120
hs_err_pid713.log
File diff suppressed because it is too large
Load Diff
1120
hs_err_pid792.log
1120
hs_err_pid792.log
File diff suppressed because it is too large
Load Diff
1121
hs_err_pid832.log
1121
hs_err_pid832.log
File diff suppressed because it is too large
Load Diff
1147
hs_err_pid982.log
1147
hs_err_pid982.log
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
Before Width: | Height: | Size: 59 KiB |
Binary file not shown.
|
|
@ -0,0 +1,153 @@
|
||||||
|
package projectzombie;
|
||||||
|
|
||||||
|
import java.awt.Toolkit;
|
||||||
|
import java.awt.datatransfer.Clipboard;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
import bdf.types.BdfReader;
|
||||||
|
import gl_engine.MathHelpers;
|
||||||
|
import mainloop.manager.MainloopManager;
|
||||||
|
import projectzombie.audio.AudioEngine;
|
||||||
|
import projectzombie.audio.AudioSources;
|
||||||
|
import projectzombie.display.DisplayStatsEventHandler;
|
||||||
|
import projectzombie.display.DisplayWindow;
|
||||||
|
import projectzombie.entity.EntityEventHandler;
|
||||||
|
import projectzombie.entity.player.EntityPlayer;
|
||||||
|
import projectzombie.init.Entities;
|
||||||
|
import projectzombie.init.ItemModifiers;
|
||||||
|
import projectzombie.init.Items;
|
||||||
|
import projectzombie.init.LayerGenerators;
|
||||||
|
import projectzombie.init.Recipes;
|
||||||
|
import projectzombie.init.Resources;
|
||||||
|
import projectzombie.init.Sounds;
|
||||||
|
import projectzombie.init.Tasks;
|
||||||
|
import projectzombie.init.Tiles;
|
||||||
|
import projectzombie.input.JoystickCallback;
|
||||||
|
import projectzombie.input.KeyCallback;
|
||||||
|
import projectzombie.mainloop.MainloopEventHandler;
|
||||||
|
import projectzombie.menu.Menu;
|
||||||
|
import projectzombie.menu.MenuMain;
|
||||||
|
import projectzombie.settings.Cheats;
|
||||||
|
import projectzombie.settings.Environment;
|
||||||
|
import projectzombie.settings.Settings;
|
||||||
|
import projectzombie.time.GameTimer;
|
||||||
|
import projectzombie.time.NoSleep;
|
||||||
|
import projectzombie.util.SaveSystem;
|
||||||
|
import projectzombie.worker.WorkerTasks;
|
||||||
|
import projectzombie.worker.WorkerLighting;
|
||||||
|
import projectzombie.world.World;
|
||||||
|
import projectzombie.world.chunk.ChunkEventHandler;
|
||||||
|
|
||||||
|
public class Main
|
||||||
|
{
|
||||||
|
public static BdfReader bdf_saves;
|
||||||
|
|
||||||
|
public static Clipboard clipboard;
|
||||||
|
public static MainloopManager mainloop;
|
||||||
|
public static DisplayWindow window;
|
||||||
|
public static EntityPlayer player;
|
||||||
|
public static World world;
|
||||||
|
public static AudioEngine audio;
|
||||||
|
public static Random rand = new Random();
|
||||||
|
public static Menu menu;
|
||||||
|
public static WorkerLighting workerLighting;
|
||||||
|
public static WorkerTasks[] workerChunks;
|
||||||
|
public static boolean game_paused = false;
|
||||||
|
public static boolean running = true;
|
||||||
|
public static int tickrate = 10;
|
||||||
|
|
||||||
|
public static void main(String[] args) throws IOException
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Environment.init(args);
|
||||||
|
File global_dir = new File(Environment.gdir);
|
||||||
|
|
||||||
|
// Make this directory if it doesn't exist
|
||||||
|
if(!global_dir.isDirectory())
|
||||||
|
{
|
||||||
|
if(global_dir.exists()) {
|
||||||
|
global_dir.delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
global_dir.mkdirs();
|
||||||
|
}
|
||||||
|
|
||||||
|
Runtime runtime = Runtime.getRuntime();
|
||||||
|
int cores = runtime.availableProcessors();
|
||||||
|
|
||||||
|
clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
|
||||||
|
|
||||||
|
workerLighting = new WorkerLighting();
|
||||||
|
workerLighting.start();
|
||||||
|
|
||||||
|
int workers = cores - 2;
|
||||||
|
if(workers < 1) {
|
||||||
|
workers = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
workerChunks = new WorkerTasks[workers];
|
||||||
|
|
||||||
|
for(int i=0;i<workerChunks.length;i++) {
|
||||||
|
workerChunks[i] = new WorkerTasks();
|
||||||
|
workerChunks[i].start();
|
||||||
|
}
|
||||||
|
|
||||||
|
MathHelpers.init();
|
||||||
|
Settings.init();
|
||||||
|
Cheats.init(args);
|
||||||
|
|
||||||
|
Items.init();
|
||||||
|
ItemModifiers.init();
|
||||||
|
Entities.init();
|
||||||
|
Tasks.init();
|
||||||
|
Tiles.init();
|
||||||
|
LayerGenerators.init();
|
||||||
|
Recipes.init();
|
||||||
|
|
||||||
|
bdf_saves = SaveSystem.readBDF("./saves.bdf.gz");
|
||||||
|
|
||||||
|
// Create the display
|
||||||
|
window = new DisplayWindow();
|
||||||
|
window.init();
|
||||||
|
|
||||||
|
// Load the resources
|
||||||
|
Resources.loadResources();
|
||||||
|
|
||||||
|
// Initialize the sound engine
|
||||||
|
audio = new AudioEngine();
|
||||||
|
audio.init();
|
||||||
|
|
||||||
|
// Initialise the sounds
|
||||||
|
AudioSources.init();
|
||||||
|
Sounds.init();
|
||||||
|
|
||||||
|
// Initialize the gamepad
|
||||||
|
JoystickCallback.JOYSTICK_CALLBACK.init();
|
||||||
|
|
||||||
|
// Create the mainloop
|
||||||
|
mainloop = new MainloopManager(MainloopEventHandler.MAINLOOP_EVENT_HANDLER);
|
||||||
|
mainloop.register(DisplayStatsEventHandler.DISPLAY_STATS_EVENT_HANDLER);
|
||||||
|
mainloop.register(MainloopEventHandler.MAINLOOP_EVENT_HANDLER);
|
||||||
|
mainloop.register(EntityEventHandler.ENTITY_EVENT_HANDLER);
|
||||||
|
mainloop.register(ChunkEventHandler.CHUNK_EVENT_HANDLER);
|
||||||
|
mainloop.register(JoystickCallback.JOYSTICK_CALLBACK);
|
||||||
|
mainloop.register(new KeyCallback());
|
||||||
|
mainloop.register(new GameTimer());
|
||||||
|
mainloop.register(new NoSleep());
|
||||||
|
mainloop.register(window);
|
||||||
|
|
||||||
|
// Start the mainloop
|
||||||
|
menu = new MenuMain();
|
||||||
|
mainloop.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
// Kill the worker threads
|
||||||
|
running = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
13
src/shootergame/audio/AudioEngine.java → src/projectzombie/audio/AudioEngine.java
Normal file → Executable file
13
src/shootergame/audio/AudioEngine.java → src/projectzombie/audio/AudioEngine.java
Normal file → Executable file
|
|
@ -1,15 +1,18 @@
|
||||||
package shootergame.audio;
|
package projectzombie.audio;
|
||||||
|
|
||||||
import static org.lwjgl.openal.ALC11.*;
|
import static org.lwjgl.openal.ALC10.ALC_DEFAULT_DEVICE_SPECIFIER;
|
||||||
import static org.lwjgl.openal.AL11.*;
|
import static org.lwjgl.openal.ALC10.alcCloseDevice;
|
||||||
|
import static org.lwjgl.openal.ALC10.alcCreateContext;
|
||||||
|
import static org.lwjgl.openal.ALC10.alcDestroyContext;
|
||||||
|
import static org.lwjgl.openal.ALC10.alcGetString;
|
||||||
|
import static org.lwjgl.openal.ALC10.alcMakeContextCurrent;
|
||||||
|
import static org.lwjgl.openal.ALC10.alcOpenDevice;
|
||||||
|
|
||||||
import org.lwjgl.openal.AL;
|
import org.lwjgl.openal.AL;
|
||||||
import org.lwjgl.openal.ALC;
|
import org.lwjgl.openal.ALC;
|
||||||
import org.lwjgl.openal.ALCCapabilities;
|
import org.lwjgl.openal.ALCCapabilities;
|
||||||
import org.lwjgl.openal.ALCapabilities;
|
import org.lwjgl.openal.ALCapabilities;
|
||||||
|
|
||||||
import shootergame.util.math.vec.Vec3d;
|
|
||||||
|
|
||||||
public class AudioEngine
|
public class AudioEngine
|
||||||
{
|
{
|
||||||
String deviceName;
|
String deviceName;
|
||||||
75
src/shootergame/audio/AudioObject.java → src/projectzombie/audio/AudioObject.java
Normal file → Executable file
75
src/shootergame/audio/AudioObject.java → src/projectzombie/audio/AudioObject.java
Normal file → Executable file
|
|
@ -1,44 +1,47 @@
|
||||||
package shootergame.audio;
|
package projectzombie.audio;
|
||||||
|
|
||||||
|
import static org.lwjgl.openal.AL10.AL_BUFFER;
|
||||||
|
import static org.lwjgl.openal.AL10.AL_FORMAT_MONO16;
|
||||||
|
import static org.lwjgl.openal.AL10.AL_FORMAT_STEREO16;
|
||||||
|
import static org.lwjgl.openal.AL10.AL_GAIN;
|
||||||
|
import static org.lwjgl.openal.AL10.AL_POSITION;
|
||||||
|
import static org.lwjgl.openal.AL10.alBufferData;
|
||||||
|
import static org.lwjgl.openal.AL10.alGenBuffers;
|
||||||
|
import static org.lwjgl.openal.AL10.alSource3f;
|
||||||
|
import static org.lwjgl.openal.AL10.alSourcePlay;
|
||||||
|
import static org.lwjgl.openal.AL10.alSourceStop;
|
||||||
|
import static org.lwjgl.openal.AL10.alSourcef;
|
||||||
|
import static org.lwjgl.openal.AL10.alSourcei;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.IntBuffer;
|
import java.nio.IntBuffer;
|
||||||
import java.nio.ShortBuffer;
|
import java.nio.ShortBuffer;
|
||||||
|
|
||||||
import org.lwjgl.openal.AL10;
|
|
||||||
import org.lwjgl.openal.AL11;
|
|
||||||
import org.lwjgl.openal.ALC10;
|
|
||||||
import org.lwjgl.stb.STBVorbis;
|
import org.lwjgl.stb.STBVorbis;
|
||||||
import org.lwjgl.system.MemoryStack;
|
import org.lwjgl.system.MemoryStack;
|
||||||
import org.lwjgl.system.libc.LibCStdlib;
|
|
||||||
|
|
||||||
import static org.lwjgl.openal.AL10.AL_BUFFER;
|
import gl_engine.matrix.Matrix4;
|
||||||
import static org.lwjgl.openal.AL10.AL_GAIN;
|
import gl_engine.vec.Vec3d;
|
||||||
import static org.lwjgl.openal.AL10.AL_POSITION;
|
import projectzombie.Main;
|
||||||
import static org.lwjgl.openal.AL10.alSource3f;
|
import projectzombie.display.Camera;
|
||||||
import static org.lwjgl.openal.AL10.alSourcePlay;
|
import projectzombie.resources.Resource;
|
||||||
import static org.lwjgl.openal.AL10.alSourcef;
|
|
||||||
import static org.lwjgl.openal.AL10.alSourcei;
|
|
||||||
import static org.lwjgl.openal.AL11.*;
|
|
||||||
|
|
||||||
import shootergame.Main;
|
|
||||||
import shootergame.display.Camera;
|
|
||||||
import shootergame.resources.Resource;
|
|
||||||
import shootergame.util.math.MathHelpers;
|
|
||||||
import shootergame.util.math.vec.Vec2d;
|
|
||||||
import shootergame.util.math.vec.Vec3d;
|
|
||||||
|
|
||||||
public class AudioObject
|
public class AudioObject
|
||||||
{
|
{
|
||||||
|
double volume;
|
||||||
int bufferPointer;
|
int bufferPointer;
|
||||||
Resource resource;
|
Resource resource;
|
||||||
|
boolean error;
|
||||||
int channels;
|
int channels;
|
||||||
int sample_rate;
|
int sample_rate;
|
||||||
int output;
|
int output;
|
||||||
|
|
||||||
public AudioObject(Resource resource)
|
public AudioObject(Resource resource, double volume)
|
||||||
{
|
{
|
||||||
// Store the argument values
|
// Store the argument values
|
||||||
this.resource = resource;
|
this.resource = resource;
|
||||||
|
this.volume = volume;
|
||||||
|
this.error = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void init()
|
public void init()
|
||||||
|
|
@ -52,6 +55,11 @@ public class AudioObject
|
||||||
ByteBuffer resource_buffer = resource.getByteBuffer();
|
ByteBuffer resource_buffer = resource.getByteBuffer();
|
||||||
ShortBuffer audio = STBVorbis.stb_vorbis_decode_memory(resource_buffer, channels_buf, sample_rate_buf);
|
ShortBuffer audio = STBVorbis.stb_vorbis_decode_memory(resource_buffer, channels_buf, sample_rate_buf);
|
||||||
|
|
||||||
|
if(audio == null) {
|
||||||
|
error = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Get the channels and the sample rate
|
// Get the channels and the sample rate
|
||||||
channels = channels_buf.get();
|
channels = channels_buf.get();
|
||||||
sample_rate = sample_rate_buf.get();
|
sample_rate = sample_rate_buf.get();
|
||||||
|
|
@ -66,6 +74,7 @@ public class AudioObject
|
||||||
|
|
||||||
// Send the data to OpenAL
|
// Send the data to OpenAL
|
||||||
bufferPointer = alGenBuffers();
|
bufferPointer = alGenBuffers();
|
||||||
|
|
||||||
alBufferData(bufferPointer, format, audio, sample_rate);
|
alBufferData(bufferPointer, format, audio, sample_rate);
|
||||||
|
|
||||||
// Free some c buffers
|
// Free some c buffers
|
||||||
|
|
@ -75,28 +84,20 @@ public class AudioObject
|
||||||
|
|
||||||
public void play(Vec3d pos, double volume)
|
public void play(Vec3d pos, double volume)
|
||||||
{
|
{
|
||||||
// Get the player pos
|
if(error) {
|
||||||
Vec2d p_pos = Main.player.pos;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Convert the angle to radians
|
// Calculate the position relative to the player
|
||||||
double angle_r = Math.toRadians(Main.player.angle + 90);
|
Matrix4 matrix = Camera.camera.matrix;
|
||||||
|
Vec3d vec = Matrix4.multiply(matrix, pos.subtract(Main.player.getPos())).multiply(0.125);
|
||||||
// Calculate the translation
|
|
||||||
double x = ( pos.x - p_pos.x );
|
|
||||||
double y = ( pos.y - p_pos.y );
|
|
||||||
double z = pos.z;
|
|
||||||
|
|
||||||
// Calculate the rotation
|
|
||||||
Vec2d rotated = MathHelpers.rotate2(new Vec2d(x, y), angle_r);
|
|
||||||
x = rotated.x;
|
|
||||||
y = rotated.y;
|
|
||||||
|
|
||||||
// Play the sound with a new source
|
// Play the sound with a new source
|
||||||
int source = AudioSources.getSource();
|
int source = AudioSources.getSource();
|
||||||
alSourceStop(source);
|
alSourceStop(source);
|
||||||
alSourcei(source, AL_BUFFER, bufferPointer);
|
alSourcei(source, AL_BUFFER, bufferPointer);
|
||||||
alSourcef(source, AL_GAIN, (float)volume);
|
alSourcef(source, AL_GAIN, (float)(volume * this.volume));
|
||||||
alSource3f(source, AL_POSITION, (float)x, (float)y, (float)z);
|
alSource3f(source, AL_POSITION, (float)vec.x, (float)vec.y, (float)vec.z);
|
||||||
alSourcePlay(source);
|
alSourcePlay(source);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
7
src/shootergame/audio/AudioRandom.java → src/projectzombie/audio/AudioRandom.java
Normal file → Executable file
7
src/shootergame/audio/AudioRandom.java → src/projectzombie/audio/AudioRandom.java
Normal file → Executable file
|
|
@ -1,9 +1,8 @@
|
||||||
package shootergame.audio;
|
package projectzombie.audio;
|
||||||
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
import shootergame.resources.Resource;
|
import gl_engine.vec.Vec3d;
|
||||||
import shootergame.util.math.vec.Vec3d;
|
|
||||||
|
|
||||||
public class AudioRandom extends AudioObject
|
public class AudioRandom extends AudioObject
|
||||||
{
|
{
|
||||||
|
|
@ -11,7 +10,7 @@ public class AudioRandom extends AudioObject
|
||||||
private static Random rand = new Random();
|
private static Random rand = new Random();
|
||||||
|
|
||||||
public AudioRandom(AudioObject ... audioObjects) {
|
public AudioRandom(AudioObject ... audioObjects) {
|
||||||
super(null);
|
super(null, 0);
|
||||||
|
|
||||||
// Set the specified parameters
|
// Set the specified parameters
|
||||||
this.audioObjects = audioObjects;
|
this.audioObjects = audioObjects;
|
||||||
7
src/shootergame/audio/AudioSources.java → src/projectzombie/audio/AudioSources.java
Normal file → Executable file
7
src/shootergame/audio/AudioSources.java → src/projectzombie/audio/AudioSources.java
Normal file → Executable file
|
|
@ -1,10 +1,9 @@
|
||||||
package shootergame.audio;
|
package projectzombie.audio;
|
||||||
|
|
||||||
|
import static org.lwjgl.openal.AL10.alGenSources;
|
||||||
|
|
||||||
import java.nio.IntBuffer;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import static org.lwjgl.openal.AL11.*;
|
|
||||||
|
|
||||||
public class AudioSources
|
public class AudioSources
|
||||||
{
|
{
|
||||||
static ArrayList<Integer> sources = new ArrayList<Integer>();
|
static ArrayList<Integer> sources = new ArrayList<Integer>();
|
||||||
|
|
@ -0,0 +1,47 @@
|
||||||
|
package projectzombie.display;
|
||||||
|
|
||||||
|
import gl_engine.MathHelpers;
|
||||||
|
import gl_engine.matrix.Matrix4;
|
||||||
|
import gl_engine.vec.Vec3d;
|
||||||
|
import projectzombie.Main;
|
||||||
|
import projectzombie.world.chunk.Chunk;
|
||||||
|
|
||||||
|
public class Camera
|
||||||
|
{
|
||||||
|
public double x, y;
|
||||||
|
public double angle = 45;
|
||||||
|
|
||||||
|
public Matrix4 matrix;
|
||||||
|
public Matrix4 projection;
|
||||||
|
public Matrix4 projection_sun;
|
||||||
|
|
||||||
|
public static Camera camera;
|
||||||
|
|
||||||
|
public Camera(int w, int h)
|
||||||
|
{
|
||||||
|
matrix = Matrix4.identity();
|
||||||
|
Vec3d pos = Main.player.getPos();
|
||||||
|
angle = Main.player.angle;
|
||||||
|
|
||||||
|
x = pos.x - 0.5;
|
||||||
|
y = pos.z - 0.5;
|
||||||
|
|
||||||
|
matrix = Matrix4.multiply(matrix, Matrix4.rotate(angle + 180, 0, 1, 0));
|
||||||
|
matrix = Matrix4.multiply(matrix, Matrix4.rotate(-45, 1, 0, 0));
|
||||||
|
matrix = Matrix4.multiply(matrix, Matrix4.translate(0, 0, -16));
|
||||||
|
|
||||||
|
projection = Matrix4.projection((double)w / (double)h, 45, 0.1, Chunk.RENDER_DISTANCE*16+32);
|
||||||
|
projection = Matrix4.multiply(matrix, projection);
|
||||||
|
|
||||||
|
double time = Main.world.getLayer().layergen.getSunPosition();
|
||||||
|
|
||||||
|
projection_sun = Matrix4.identity();
|
||||||
|
projection_sun = Matrix4.multiply(projection_sun, Matrix4.rotate(angle + 180, 0, 1, 0));
|
||||||
|
projection_sun = Matrix4.multiply(projection_sun, Matrix4.translate(0, 0, 8));
|
||||||
|
projection_sun = Matrix4.multiply(projection_sun, Matrix4.rotate(-angle - 180, 0, 1, 0));
|
||||||
|
projection_sun = Matrix4.multiply(projection_sun, Matrix4.rotate(20, 0, 0, 1));
|
||||||
|
projection_sun = Matrix4.multiply(projection_sun, Matrix4.rotate(-time, 1, 0, 0));
|
||||||
|
projection_sun = Matrix4.multiply(projection_sun, Matrix4.translate(0, 0, -(16*Chunk.RENDER_DISTANCE+16)));
|
||||||
|
projection_sun = Matrix4.multiply(projection_sun, Matrix4.scale(new Vec3d(1.0/20.0, 1.0/20.0, -1.0/(32*Chunk.RENDER_DISTANCE+32))));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,345 @@
|
||||||
|
package projectzombie.display;
|
||||||
|
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
|
import org.lwjgl.BufferUtils;
|
||||||
|
import org.lwjgl.opengl.GL33;
|
||||||
|
|
||||||
|
import bdf.types.BdfNamedList;
|
||||||
|
import bdf.types.BdfObject;
|
||||||
|
import gl_engine.MathHelpers;
|
||||||
|
import gl_engine.vec.Vec2d;
|
||||||
|
import gl_engine.vec.Vec2i;
|
||||||
|
import projectzombie.Main;
|
||||||
|
import projectzombie.entity.Entity;
|
||||||
|
import projectzombie.entity.player.EntityPlayer;
|
||||||
|
import projectzombie.util.TileState;
|
||||||
|
import projectzombie.world.chunk.Chunk;
|
||||||
|
import projectzombie.world.chunk.ChunkEventHandler;
|
||||||
|
import projectzombie.world.layer.Layer;
|
||||||
|
|
||||||
|
public class DisplayLighting
|
||||||
|
{
|
||||||
|
private static class Lighting {
|
||||||
|
float[] p;
|
||||||
|
int w, h;
|
||||||
|
int x, y;
|
||||||
|
|
||||||
|
private int getID(int x, int y) {
|
||||||
|
return (x + y * w) * 3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int lighting_last_x = 0;
|
||||||
|
private static int lighting_last_y = 0;
|
||||||
|
private static boolean lighting_dirty = false;
|
||||||
|
public static int lightmap;
|
||||||
|
|
||||||
|
private static AtomicBoolean lighting_new = new AtomicBoolean(false);
|
||||||
|
private static AtomicReference<Lighting> lighting = new AtomicReference<DisplayLighting.Lighting>();
|
||||||
|
|
||||||
|
public static void setDirty() {
|
||||||
|
lighting_dirty = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Lighting getLighting() {
|
||||||
|
return lighting.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void setLighting(Lighting lighting) {
|
||||||
|
DisplayLighting.lighting.set(lighting);
|
||||||
|
lighting_new.set(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DisplayLighting() {
|
||||||
|
lightmap = GL33.glGenTextures();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void update()
|
||||||
|
{
|
||||||
|
if(Camera.camera == null) return;
|
||||||
|
if(!ChunkEventHandler.loaded) return;
|
||||||
|
Layer layer = Main.world.getLayer();
|
||||||
|
EntityPlayer player = Main.player;
|
||||||
|
Vec2d ppos = player.getPos().xz();
|
||||||
|
|
||||||
|
boolean dirty = lighting_dirty;
|
||||||
|
|
||||||
|
if(!dirty)
|
||||||
|
{
|
||||||
|
for(int cx=-Chunk.RENDER_DISTANCE;cx<=Chunk.RENDER_DISTANCE;cx++) {
|
||||||
|
for(int cy=-Chunk.RENDER_DISTANCE;cy<=Chunk.RENDER_DISTANCE;cy++) {
|
||||||
|
Vec2i cpos = new Vec2i(
|
||||||
|
cx + MathHelpers.floor(ppos.x / 16),
|
||||||
|
cy + MathHelpers.floor(ppos.y / 16));
|
||||||
|
Chunk chunk = layer.chunks.get(cpos);
|
||||||
|
if(chunk.isLightDirty()) {
|
||||||
|
chunk.resetLightDirty();
|
||||||
|
dirty = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!dirty) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
lighting_dirty = false;
|
||||||
|
int size = (Chunk.RENDER_DISTANCE * 2 + 1) * 16;
|
||||||
|
float[] lights = new float[size * size * 2];
|
||||||
|
|
||||||
|
for(int cx=-Chunk.RENDER_DISTANCE;cx<=Chunk.RENDER_DISTANCE;cx++) {
|
||||||
|
for(int cy=-Chunk.RENDER_DISTANCE;cy<=Chunk.RENDER_DISTANCE;cy++)
|
||||||
|
{
|
||||||
|
Vec2i cpos = new Vec2i(
|
||||||
|
cx + MathHelpers.floor(ppos.x / 16),
|
||||||
|
cy + MathHelpers.floor(ppos.y / 16));
|
||||||
|
|
||||||
|
Chunk chunk = layer.chunks.get(cpos);
|
||||||
|
|
||||||
|
for(int x=0;x<16;x++) {
|
||||||
|
for(int y=0;y<16;y++)
|
||||||
|
{
|
||||||
|
Vec2i tpos = new Vec2i(x, y);
|
||||||
|
int tid = tpos.getId(Chunk.CHUNK_SIZE);
|
||||||
|
|
||||||
|
TileState ft = chunk.getFrontTile(tid);
|
||||||
|
TileState bt = chunk.getBackTile(tid);
|
||||||
|
|
||||||
|
float transparency = (float)MathHelpers.biggest(
|
||||||
|
ft.tile.getLightDissipation(ft),
|
||||||
|
bt.tile.getLightDissipation(bt));
|
||||||
|
|
||||||
|
float lightSrc = (float)MathHelpers.biggest(
|
||||||
|
ft.tile.getLightLevel(ft, tpos),
|
||||||
|
bt.tile.getLightLevel(bt, tpos));
|
||||||
|
|
||||||
|
int id = ((cx * 16 + x + Chunk.RENDER_DISTANCE * 16) +
|
||||||
|
(cy * 16 + y + Chunk.RENDER_DISTANCE * 16) * size) * 2;
|
||||||
|
|
||||||
|
lights[id+0] = lightSrc;
|
||||||
|
lights[id+1] = transparency;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Main.workerLighting.processLighting(lights, size, size,
|
||||||
|
MathHelpers.floor(ppos.x / 16.0) - Chunk.RENDER_DISTANCE,
|
||||||
|
MathHelpers.floor(ppos.y / 16.0) - Chunk.RENDER_DISTANCE);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void calculateLight(Layer layer, Lighting lighting, float[] pixels, int x, int y, float level)
|
||||||
|
{
|
||||||
|
if(x < 0 || y < 0 || x >= lighting.w || y >= lighting.h || level <= 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int id = lighting.getID(x, y);
|
||||||
|
float level_current = pixels[id];
|
||||||
|
|
||||||
|
Vec2i tpos = new Vec2i(x + lighting.x * 16, y + lighting.y * 16);
|
||||||
|
int tid = tpos.getId(Chunk.CHUNK_SIZE);
|
||||||
|
|
||||||
|
if(level_current >= level) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
pixels[id] = level;
|
||||||
|
|
||||||
|
Chunk chunk = layer.getChunk(tpos);
|
||||||
|
TileState ft = chunk.getFrontTile(tid);
|
||||||
|
TileState bt = chunk.getBackTile(tid);
|
||||||
|
|
||||||
|
float dissipation = (float)Math.max(ft.tile.getLightDissipation(ft), bt.tile.getLightDissipation(bt));
|
||||||
|
float level_next = level - dissipation;
|
||||||
|
|
||||||
|
int[] adjacent = new int[] {
|
||||||
|
x+1, y+0,
|
||||||
|
x+0, y+1,
|
||||||
|
x-1, y-0,
|
||||||
|
x-0, y-1,
|
||||||
|
};
|
||||||
|
|
||||||
|
for(int i=0;i<8;i+=2) {
|
||||||
|
calculateLight(layer, lighting, pixels, adjacent[i], adjacent[i+1], level_next);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void calculateEntityLighting(Layer layer, Lighting lighting, Entity entity, float[] pixels)
|
||||||
|
{
|
||||||
|
if(!entity.emitsLight) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
double level = entity.getLightLevel();
|
||||||
|
|
||||||
|
if(level <= 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(level > 1) {
|
||||||
|
level = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int[] positions = {
|
||||||
|
0, 0,
|
||||||
|
1, 0,
|
||||||
|
1, 1,
|
||||||
|
0, 1
|
||||||
|
};
|
||||||
|
|
||||||
|
Vec2d epos = entity.getPos().xz();
|
||||||
|
|
||||||
|
for(int i=0;i<positions.length;i+=2)
|
||||||
|
{
|
||||||
|
int x = (int)Math.round(epos.x) - positions[i+0];
|
||||||
|
int y = (int)Math.round(epos.y) - positions[i+1];
|
||||||
|
|
||||||
|
Vec2i lpos = new Vec2i(x, y).subtract(new Vec2i(lighting.x * 16, lighting.y * 16));
|
||||||
|
|
||||||
|
if(lpos.x < 0 || lpos.y < 0 || lpos.x >= lighting.w || lpos.y >= lighting.h) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
int id = lighting.getID(lpos.x, lpos.y);
|
||||||
|
float level_current = pixels[id];
|
||||||
|
|
||||||
|
Vec2i tpos = new Vec2i(x, y);
|
||||||
|
int tid = tpos.getId(Chunk.CHUNK_SIZE);
|
||||||
|
|
||||||
|
if(level_current >= level) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
Chunk chunk = layer.getChunk(tpos);
|
||||||
|
TileState ft = chunk.getFrontTile(tid);
|
||||||
|
TileState bt = chunk.getBackTile(tid);
|
||||||
|
|
||||||
|
double dissipation = Math.max(ft.tile.getLightDissipation(ft), bt.tile.getLightDissipation(bt));
|
||||||
|
double level2 = level - dissipation * (Math.abs(x + 0.5 - epos.x) + Math.abs(y + 0.5 - epos.y));
|
||||||
|
|
||||||
|
calculateLight(layer, lighting, pixels, lpos.x, lpos.y, (float)level2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void updateLighting()
|
||||||
|
{
|
||||||
|
Lighting lighting = getLighting();
|
||||||
|
Layer layer = Main.world.getLayer();
|
||||||
|
|
||||||
|
if(lighting_new.getAndSet(false))
|
||||||
|
{
|
||||||
|
for(int i=0;i<lighting.p.length/3;i++)
|
||||||
|
{
|
||||||
|
int i3 = i*3;
|
||||||
|
int x = i % lighting.w;
|
||||||
|
int y = i / lighting.w;
|
||||||
|
|
||||||
|
Vec2i tpos = new Vec2i(x + lighting.x * 16, y + lighting.y * 16);
|
||||||
|
|
||||||
|
// Store light level data from the image
|
||||||
|
layer.setLightLevel(lighting.p[i3+0], tpos);
|
||||||
|
|
||||||
|
// Store temperature and humidity data
|
||||||
|
lighting.p[i3+1] = (float)layer.getTemperature(new Vec2i(x + lighting.x * 16, y + lighting.y * 16));
|
||||||
|
lighting.p[i3+2] = (float)layer.getHumidity(new Vec2i(x + lighting.x * 16, y + lighting.y * 16));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copy the pixels
|
||||||
|
float[] pixels = new float[lighting.p.length];
|
||||||
|
for(int i=0;i<pixels.length;i++) {
|
||||||
|
pixels[i] = lighting.p[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
Vec2d ppos = Main.player.getPos().xz();
|
||||||
|
|
||||||
|
calculateEntityLighting(layer, lighting, Main.player, pixels);
|
||||||
|
|
||||||
|
for(int cx=-Chunk.RENDER_DISTANCE;cx<=Chunk.RENDER_DISTANCE;cx++) {
|
||||||
|
for(int cy=-Chunk.RENDER_DISTANCE;cy<=Chunk.RENDER_DISTANCE;cy++)
|
||||||
|
{
|
||||||
|
Vec2i cpos = new Vec2i(
|
||||||
|
cx + MathHelpers.floor(ppos.x / 16),
|
||||||
|
cy + MathHelpers.floor(ppos.y / 16));
|
||||||
|
|
||||||
|
Chunk chunk = layer.chunks.get(cpos);
|
||||||
|
|
||||||
|
for(Entity entity : chunk.entities) {
|
||||||
|
calculateEntityLighting(layer, lighting, entity, pixels);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ByteBuffer pixels_b = BufferUtils.createByteBuffer(pixels.length);
|
||||||
|
|
||||||
|
for(int i=0;i<pixels.length;i++) {
|
||||||
|
pixels_b.put(i, (byte)(pixels[i]*255));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update the texture
|
||||||
|
GL33.glBindTexture(GL33.GL_TEXTURE_2D, lightmap);
|
||||||
|
|
||||||
|
if(lighting_last_x != lighting.w || lighting_last_y != lighting.h)
|
||||||
|
{
|
||||||
|
GL33.glTexImage2D(GL33.GL_TEXTURE_2D, 0, GL33.GL_RGB,
|
||||||
|
lighting.w, lighting.h, 0, GL33.GL_RGB, GL33.GL_UNSIGNED_BYTE, pixels_b);
|
||||||
|
|
||||||
|
lighting_last_x = lighting.w;
|
||||||
|
lighting_last_y = lighting.h;
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
GL33.glTexSubImage2D(GL33.GL_TEXTURE_2D, 0, 0, 0,
|
||||||
|
lighting.w, lighting.h, GL33.GL_RGB, GL33.GL_UNSIGNED_BYTE, pixels_b);
|
||||||
|
}
|
||||||
|
|
||||||
|
GL33.glGenerateMipmap(GL33.GL_TEXTURE_2D);
|
||||||
|
|
||||||
|
// Set the texture location data
|
||||||
|
GL33.glUniform2f(Main.window.glsl_lightmap_size, lighting.w, lighting.h);
|
||||||
|
|
||||||
|
if(Camera.camera != null) {
|
||||||
|
GL33.glUniform2f(Main.window.glsl_lightmap_offset,
|
||||||
|
(float)(lighting.x * 16 - Camera.camera.x - 0.5),
|
||||||
|
(float)(lighting.y * 16 - Camera.camera.y - 0.5));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void clearLighting()
|
||||||
|
{
|
||||||
|
Lighting lighting = new Lighting();
|
||||||
|
lighting.p = new float[3];
|
||||||
|
lighting.w = 1;
|
||||||
|
lighting.h = 1;
|
||||||
|
lighting.x = 0;
|
||||||
|
lighting.y = 0;
|
||||||
|
|
||||||
|
setLighting(lighting);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void updateLighting(float[] light, int x, int y, int width, int height)
|
||||||
|
{
|
||||||
|
float[] pixels = new float[width*height*3];
|
||||||
|
|
||||||
|
for(int i=0;i<width*height;i++) {
|
||||||
|
pixels[i*3] = light[i*2];
|
||||||
|
}
|
||||||
|
|
||||||
|
Lighting lighting = new Lighting();
|
||||||
|
lighting.p = pixels;
|
||||||
|
lighting.w = width;
|
||||||
|
lighting.h = height;
|
||||||
|
lighting.x = x;
|
||||||
|
lighting.y = y;
|
||||||
|
|
||||||
|
setLighting(lighting);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,178 @@
|
||||||
|
package projectzombie.display;
|
||||||
|
|
||||||
|
import static org.lwjgl.opengl.GL11.GL_COLOR_BUFFER_BIT;
|
||||||
|
import static org.lwjgl.opengl.GL11.GL_DEPTH_BUFFER_BIT;
|
||||||
|
import static org.lwjgl.opengl.GL11.glClear;
|
||||||
|
import static org.lwjgl.opengl.GL11.glViewport;
|
||||||
|
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
|
||||||
|
import org.lwjgl.opengl.GL33;
|
||||||
|
|
||||||
|
import gl_engine.matrix.Matrix4;
|
||||||
|
import projectzombie.Main;
|
||||||
|
import projectzombie.entity.player.EntityPlayer;
|
||||||
|
import projectzombie.settings.SettingQuality;
|
||||||
|
import projectzombie.util.ColorRange;
|
||||||
|
import projectzombie.world.chunk.ChunkEventHandler;
|
||||||
|
import projectzombie.world.layer.layergen.LayerGen;
|
||||||
|
|
||||||
|
public class DisplayRender
|
||||||
|
{
|
||||||
|
public static int shadow_fbo;
|
||||||
|
public static int shadow_depth;
|
||||||
|
public static int shadow_size;
|
||||||
|
private static SettingQuality shadow_quality;
|
||||||
|
|
||||||
|
public static SettingQuality setShadowQuality(SettingQuality quality)
|
||||||
|
{
|
||||||
|
int size;
|
||||||
|
|
||||||
|
switch(quality)
|
||||||
|
{
|
||||||
|
case LOWEST:
|
||||||
|
size = 1024;
|
||||||
|
break;
|
||||||
|
case LOW:
|
||||||
|
size = 2048;
|
||||||
|
break;
|
||||||
|
case MEDIUM:
|
||||||
|
size = 4096;
|
||||||
|
break;
|
||||||
|
case HIGH:
|
||||||
|
size = 8192;
|
||||||
|
break;
|
||||||
|
case EXTREME:
|
||||||
|
size = 16384;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
size = 2048;
|
||||||
|
quality = SettingQuality.LOW;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(Main.window != null && size > Main.window.texture_max_size) {
|
||||||
|
quality = SettingQuality.LOWEST;
|
||||||
|
size = 1024;
|
||||||
|
}
|
||||||
|
|
||||||
|
shadow_size = size;
|
||||||
|
shadow_quality = quality;
|
||||||
|
|
||||||
|
return quality;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static SettingQuality getShadowQuality() {
|
||||||
|
return shadow_quality;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void updateShadowQuality()
|
||||||
|
{
|
||||||
|
GL33.glBindFramebuffer(GL33.GL_FRAMEBUFFER, shadow_fbo);
|
||||||
|
GL33.glDeleteTextures(shadow_depth);
|
||||||
|
|
||||||
|
shadow_depth = generateDepthTexture(shadow_size, shadow_size);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int generateDepthTexture(int width, int height)
|
||||||
|
{
|
||||||
|
int depth = GL33.glGenTextures();
|
||||||
|
|
||||||
|
GL33.glBindTexture(GL33.GL_TEXTURE_2D, depth);
|
||||||
|
|
||||||
|
GL33.glTexImage2D(
|
||||||
|
GL33.GL_TEXTURE_2D, 0, GL33.GL_DEPTH_COMPONENT32, width, height,
|
||||||
|
0, GL33.GL_DEPTH_COMPONENT, GL33.GL_FLOAT, (ByteBuffer) null);
|
||||||
|
|
||||||
|
GL33.glTexParameteri(GL33.GL_TEXTURE_2D, GL33.GL_TEXTURE_MIN_FILTER, GL33.GL_LINEAR);
|
||||||
|
GL33.glTexParameteri(GL33.GL_TEXTURE_2D, GL33.GL_TEXTURE_MAG_FILTER, GL33.GL_LINEAR);
|
||||||
|
GL33.glTexParameteri(GL33.GL_TEXTURE_2D, GL33.GL_TEXTURE_WRAP_S, GL33.GL_CLAMP_TO_BORDER);
|
||||||
|
GL33.glTexParameteri(GL33.GL_TEXTURE_2D, GL33.GL_TEXTURE_WRAP_T, GL33.GL_CLAMP_TO_BORDER);
|
||||||
|
GL33.glTexParameterfv(GL33.GL_TEXTURE_2D, GL33.GL_TEXTURE_BORDER_COLOR, new float[] {1, 1, 1, 1});
|
||||||
|
GL33.glFramebufferTexture(GL33.GL_FRAMEBUFFER, GL33.GL_DEPTH_ATTACHMENT, depth, 0);
|
||||||
|
|
||||||
|
return depth;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void init()
|
||||||
|
{
|
||||||
|
shadow_fbo = GL33.glGenFramebuffers();
|
||||||
|
GL33.glBindFramebuffer(GL33.GL_FRAMEBUFFER, shadow_fbo);
|
||||||
|
GL33.glDrawBuffer(GL33.GL_NONE);
|
||||||
|
GL33.glReadBuffer(GL33.GL_NONE);
|
||||||
|
|
||||||
|
shadow_depth = generateDepthTexture(shadow_size, shadow_size);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void render(int w, int h)
|
||||||
|
{
|
||||||
|
// Setup GL and clear the colour
|
||||||
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
glViewport(0, 0, w, h);
|
||||||
|
|
||||||
|
GL33.glEnable(GL33.GL_DEPTH_TEST);
|
||||||
|
GL33.glUniform4f(Main.window.glsl_color, 1, 1, 1, 1);
|
||||||
|
GL33.glUniform1i(Main.window.glsl_do_discard_coords, 0);
|
||||||
|
|
||||||
|
ColorRange range = Main.world.getLayer().layergen.getLightLevel();
|
||||||
|
|
||||||
|
GL33.glUniform3f(Main.window.glsl_day_low, (float)range.min.x, (float)range.min.y, (float)range.min.z);
|
||||||
|
GL33.glUniform3f(Main.window.glsl_day_high, (float)range.max.x, (float)range.max.y, (float)range.max.z);
|
||||||
|
|
||||||
|
if(Main.menu.doGameRender)
|
||||||
|
{
|
||||||
|
if(ChunkEventHandler.loaded)
|
||||||
|
{
|
||||||
|
EntityPlayer player = Main.player;
|
||||||
|
Camera camera = new Camera(w, h);
|
||||||
|
Camera.camera = camera;
|
||||||
|
|
||||||
|
Matrix4 rotated = Matrix4.rotate(-camera.angle, 0, 1, 0);
|
||||||
|
Matrix4 billboard = Matrix4.multiply(Matrix4.rotate(-45, 1, 0, 0), rotated);
|
||||||
|
|
||||||
|
Main.window.environmentRenderer.use();
|
||||||
|
GL33.glUniformMatrix4fv(Main.window.glsl_camera, true, Camera.camera.matrix.getArray());
|
||||||
|
GL33.glUniformMatrix4fv(Main.window.glsl_billboard, true, billboard.getArray());
|
||||||
|
GL33.glUniformMatrix4fv(Main.window.glsl_rotated, true, rotated.getArray());
|
||||||
|
GL33.glUniformMatrix4fv(Main.window.glsl_projection_sun, true, Camera.camera.projection_sun.getArray());
|
||||||
|
GL33.glUniform1i(Main.window.glsl_time, (int)((System.currentTimeMillis() / 10) % 1000));
|
||||||
|
GL33.glUniform1i(Main.window.glsl_do_lighting, 1);
|
||||||
|
|
||||||
|
Main.world.markPoolDirty();
|
||||||
|
|
||||||
|
LayerGen layergen = Main.world.getLayer().layergen;
|
||||||
|
//double sunPosition = MathHelpers.mod(layergen.getSunPosition(), 360);
|
||||||
|
|
||||||
|
if(layergen.hasSun() /*&& sunPosition > 0 && sunPosition < 180*/ && shadow_size != 1)
|
||||||
|
{
|
||||||
|
// Set up the suns frame buffer
|
||||||
|
GL33.glBindFramebuffer(GL33.GL_FRAMEBUFFER, shadow_fbo);
|
||||||
|
glClear(GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
|
// Set up the suns perspective
|
||||||
|
GL33.glUniformMatrix4fv(Main.window.glsl_projection, true,
|
||||||
|
Camera.camera.projection_sun.getArray());
|
||||||
|
GL33.glUniform1i(Main.window.glsl_mode, 1);
|
||||||
|
|
||||||
|
// Render from the suns perspective
|
||||||
|
glViewport(0, 0, shadow_size, shadow_size);
|
||||||
|
Main.world.render(camera);
|
||||||
|
|
||||||
|
// Set back to the players frame buffer
|
||||||
|
GL33.glBindFramebuffer(GL33.GL_FRAMEBUFFER, 0);
|
||||||
|
glViewport(0, 0, w, h);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set to the players perspective and render
|
||||||
|
GL33.glUniform1i(Main.window.glsl_mode, 0);
|
||||||
|
GL33.glUniformMatrix4fv(Main.window.glsl_projection, true, camera.projection.getArray());
|
||||||
|
|
||||||
|
Main.world.render(camera);
|
||||||
|
|
||||||
|
player.chunk = Main.world.getLayer().getChunk(player.getPos().xz());
|
||||||
|
|
||||||
|
GL33.glUniform1i(Main.window.glsl_do_lighting, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,227 @@
|
||||||
|
package projectzombie.display;
|
||||||
|
|
||||||
|
import java.text.DecimalFormat;
|
||||||
|
|
||||||
|
import org.lwjgl.opengl.GL33;
|
||||||
|
|
||||||
|
import gl_engine.MathHelpers;
|
||||||
|
import gl_engine.matrix.Matrix4;
|
||||||
|
import gl_engine.vec.Vec2d;
|
||||||
|
import gl_engine.vec.Vec3d;
|
||||||
|
import projectzombie.Main;
|
||||||
|
import projectzombie.init.Models;
|
||||||
|
import projectzombie.inventory.Inventory;
|
||||||
|
import projectzombie.model.Model;
|
||||||
|
import projectzombie.model.ModelGui;
|
||||||
|
import projectzombie.text.Text;
|
||||||
|
import projectzombie.util.ItemStack;
|
||||||
|
import projectzombie.util.gl.GlHelpers;
|
||||||
|
import projectzombie.world.chunk.ChunkEventHandler;
|
||||||
|
import projectzombie.world.layer.Layer;
|
||||||
|
|
||||||
|
public class DisplayRenderUI
|
||||||
|
{
|
||||||
|
public static boolean showFPS = false;
|
||||||
|
public static boolean debug = false;
|
||||||
|
public static int guiScale = 2;
|
||||||
|
|
||||||
|
public static Matrix4 camera, projection;
|
||||||
|
|
||||||
|
private static float calculateGreen(double a) {
|
||||||
|
return (float)(-2 * a * (a - 1) + 0.25 * a * a);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void renderGameGui()
|
||||||
|
{
|
||||||
|
{
|
||||||
|
Matrix4 matrix = Matrix4.translate(-Models.UI_ITEM_SLOTS.getWidth() / 2, -9.5, 0);
|
||||||
|
Inventory inventory = Main.player.getInventory();
|
||||||
|
|
||||||
|
int slot = Main.player.inventory_hand;
|
||||||
|
double offset = Models.UI_ITEM_SLOTS.getWidth() / 10;
|
||||||
|
Matrix4 matrix_slot = Matrix4.multiply(matrix, Matrix4.translate(offset * slot, 0, 0));
|
||||||
|
|
||||||
|
Models.UI_ITEM_SLOTS.setModel(matrix);
|
||||||
|
Models.UI_ITEM_SLOTS.render();
|
||||||
|
|
||||||
|
Models.UI_ACTIVE_SLOT.setModel(matrix_slot);
|
||||||
|
Models.UI_ACTIVE_SLOT.render();
|
||||||
|
|
||||||
|
for(int i = 0; i < 10; i++)
|
||||||
|
{
|
||||||
|
ItemStack stack = inventory.getItem(i);
|
||||||
|
|
||||||
|
if(stack.isEmpty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
Model model_item = stack.item.getModel(stack).getGuiModel();
|
||||||
|
double item_offset = (Models.UI_ACTIVE_SLOT.getHeight() - model_item.getHeight()) / 2;
|
||||||
|
|
||||||
|
Matrix4 matrix_item = Matrix4.multiply(matrix, Matrix4.translate(i * offset + item_offset, item_offset, 0));
|
||||||
|
|
||||||
|
model_item.setModel(matrix_item);
|
||||||
|
model_item.render();
|
||||||
|
|
||||||
|
double damage = stack.item.getDamage(stack);
|
||||||
|
|
||||||
|
if(damage > 0)
|
||||||
|
{
|
||||||
|
Matrix4 matrix_damage = Matrix4.multiply(matrix_item, Matrix4.translate(0, -0.85 / 16, 0));
|
||||||
|
matrix_damage = Matrix4.multiply(Matrix4.scale(new Vec3d(damage * 0.85, 0.85 / 16, 0)), matrix_damage);
|
||||||
|
|
||||||
|
GL33.glUniform4f(Main.window.glsl_color,
|
||||||
|
1 - (float)MathHelpers.squared(1 - damage),
|
||||||
|
1 - (float)MathHelpers.squared(damage), 0, 1);
|
||||||
|
|
||||||
|
Models.UI_PIXEL_WHITE.setModel(matrix_damage);
|
||||||
|
Models.UI_PIXEL_WHITE.render();
|
||||||
|
|
||||||
|
GL33.glUniform4f(Main.window.glsl_color, 1, 1, 1, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(stack.count > 1)
|
||||||
|
{
|
||||||
|
Matrix4 matrix_text = Matrix4.multiply(matrix, Matrix4.translate(i * offset + 0.25, 0.28125, 0));
|
||||||
|
matrix_text = Matrix4.multiply(Matrix4.scale(new Vec3d(0.4, 0.4, 0.4)), matrix_text);
|
||||||
|
|
||||||
|
Text.render("" + stack.count, matrix_text);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
ModelGui model_health_f = Models.UI_HEALTH_FG;
|
||||||
|
ModelGui model_health_b = Models.UI_HEALTH_BG;
|
||||||
|
ModelGui model_temperature = Models.UI_TEMPERATURE;
|
||||||
|
ModelGui model_water = Models.UI_WATER;
|
||||||
|
Matrix4 matrix;
|
||||||
|
|
||||||
|
{
|
||||||
|
double offset = -(79 * 15.0) / 160;
|
||||||
|
matrix = Matrix4.translate(offset, -9.5 + (1.5 * 17) / 16, 0);
|
||||||
|
|
||||||
|
model_health_b.setModel(matrix);
|
||||||
|
model_health_b.render();
|
||||||
|
|
||||||
|
GL33.glUniform1i(Main.window.glsl_do_discard_coords, 1);
|
||||||
|
GL33.glUniform4f(Main.window.glsl_discard_coords, -10, -10, (float)MathHelpers.map(
|
||||||
|
Main.player.getHealth(),
|
||||||
|
0, Main.player.maxHealth(),
|
||||||
|
offset, offset + model_health_f.getWidth()), 10);
|
||||||
|
|
||||||
|
model_health_f.setModel(matrix);
|
||||||
|
model_health_f.render();
|
||||||
|
}
|
||||||
|
|
||||||
|
double temperature = MathHelpers.smoothStep(Main.player.getTemperature());
|
||||||
|
double hydration = MathHelpers.smoothStep(1 - Main.player.getHydration());
|
||||||
|
|
||||||
|
{
|
||||||
|
Vec2d offset = new Vec2d((1 * 0.75) / 8, -9.5 + (1.5 * 17) / 16);
|
||||||
|
|
||||||
|
matrix = Matrix4.translate(offset.x, offset.y, 0);
|
||||||
|
|
||||||
|
GL33.glUniform1i(Main.window.glsl_do_discard_coords, 0);
|
||||||
|
GL33.glUniform4f(Main.window.glsl_color, 0.65f, 0.65f, 0.65f, 1);
|
||||||
|
|
||||||
|
model_water.setModel(matrix);
|
||||||
|
model_water.render();
|
||||||
|
|
||||||
|
GL33.glUniform1i(Main.window.glsl_do_discard_coords, 1);
|
||||||
|
|
||||||
|
GL33.glUniform4f(Main.window.glsl_discard_coords,
|
||||||
|
(float)offset.x, (float)offset.y,
|
||||||
|
(float)(offset.x + model_water.getWidth()),
|
||||||
|
(float)(offset.y + model_water.getHeight() * Main.player.getHydration()));
|
||||||
|
|
||||||
|
GL33.glUniform4f(Main.window.glsl_color,
|
||||||
|
(float)hydration * 0.75f, calculateGreen(hydration), 1 - (float)hydration, 1);
|
||||||
|
|
||||||
|
model_water.render();
|
||||||
|
|
||||||
|
GL33.glUniform1i(Main.window.glsl_do_discard_coords, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
GL33.glUniform4f(Main.window.glsl_color,
|
||||||
|
(float)temperature, calculateGreen(temperature), 1 - (float)temperature, 1);
|
||||||
|
|
||||||
|
matrix = Matrix4.translate(-(9 * 0.75) / 8, -9.5 + (1.5 * 17) / 16, 0);
|
||||||
|
|
||||||
|
model_temperature.setModel(matrix);
|
||||||
|
model_temperature.render();
|
||||||
|
}
|
||||||
|
|
||||||
|
GL33.glUniform4f(Main.window.glsl_color, 1, 1, 1, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void render()
|
||||||
|
{
|
||||||
|
DecimalFormat dec = new DecimalFormat("0.####");
|
||||||
|
|
||||||
|
camera = Matrix4.identity();
|
||||||
|
projection = Matrix4.scale(new Vec3d(0.1/GlHelpers.getAspectRatio(), 0.1, 1));
|
||||||
|
|
||||||
|
GL33.glUniform3f(Main.window.glsl_day_low, 1, 1, 1);
|
||||||
|
GL33.glUniform3f(Main.window.glsl_day_high, 1, 1, 1);
|
||||||
|
|
||||||
|
GL33.glUniformMatrix4fv(Main.window.glsl_projection, true, projection.getArray());
|
||||||
|
|
||||||
|
GL33.glDisable(GL33.GL_DEPTH_TEST);
|
||||||
|
|
||||||
|
if(Main.menu.doGameRender && Main.menu.showIngameGUI && ChunkEventHandler.loaded) {
|
||||||
|
renderGameGui();
|
||||||
|
}
|
||||||
|
|
||||||
|
double aspect = (double)Main.window.getWidth() / (double)Main.window.getHeight();
|
||||||
|
Matrix4 matrix = Matrix4.scale(new Vec3d(0.35, 0.35, 0.35));
|
||||||
|
matrix = Matrix4.multiply(matrix, Matrix4.translate(-10 * aspect, 9.5, 0));
|
||||||
|
|
||||||
|
if(showFPS) {
|
||||||
|
|
||||||
|
float fps = DisplayStatsEventHandler.fps;
|
||||||
|
|
||||||
|
if(fps >= 120) {
|
||||||
|
GL33.glUniform4f(Main.window.glsl_color, 0, 1, 0, 1);
|
||||||
|
} else if(fps >= 60) {
|
||||||
|
GL33.glUniform4f(Main.window.glsl_color, 1, 1, 0, 1);
|
||||||
|
} else {
|
||||||
|
GL33.glUniform4f(Main.window.glsl_color, 1, 0, 0, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
Text.render("Fps: " + DisplayStatsEventHandler.fps, matrix);
|
||||||
|
matrix = Matrix4.multiply(matrix, Matrix4.translate(0, -0.7, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
if(debug) {
|
||||||
|
Layer layer = Main.world.getLayer();
|
||||||
|
Vec3d pos = Main.player.getPos();
|
||||||
|
|
||||||
|
GL33.glUniform4f(Main.window.glsl_color, 1, 1, 0, 1);
|
||||||
|
|
||||||
|
if(ChunkEventHandler.loaded)
|
||||||
|
{
|
||||||
|
Text.render("temperature: " + dec.format(
|
||||||
|
layer.getTemperature(Main.player.getPos().xz().toInt())), matrix);
|
||||||
|
matrix = Matrix4.multiply(matrix, Matrix4.translate(0, -0.35, 0));
|
||||||
|
Text.render("humidity: " + dec.format(
|
||||||
|
layer.getHumidity(Main.player.getPos().xz().toInt())), matrix);
|
||||||
|
matrix = Matrix4.multiply(matrix, Matrix4.translate(0, -0.7, 0));
|
||||||
|
|
||||||
|
Text.render("x: "+dec.format(pos.x), matrix);
|
||||||
|
matrix = Matrix4.multiply(matrix, Matrix4.translate(0, -0.35, 0));
|
||||||
|
Text.render("y: "+dec.format(pos.y), matrix);
|
||||||
|
matrix = Matrix4.multiply(matrix, Matrix4.translate(0, -0.35, 0));
|
||||||
|
Text.render("z: "+dec.format(pos.z), matrix);
|
||||||
|
matrix = Matrix4.multiply(matrix, Matrix4.translate(0, -0.7, 0));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
GL33.glUniform4f(Main.window.glsl_color, 1, 1, 1, 1);
|
||||||
|
|
||||||
|
// Render the loaded menu
|
||||||
|
Main.menu.render();
|
||||||
|
}
|
||||||
|
}
|
||||||
10
src/shootergame/display/DisplayStatsEventHandler.java → src/projectzombie/display/DisplayStatsEventHandler.java
Normal file → Executable file
10
src/shootergame/display/DisplayStatsEventHandler.java → src/projectzombie/display/DisplayStatsEventHandler.java
Normal file → Executable file
|
|
@ -1,7 +1,7 @@
|
||||||
package shootergame.display;
|
package projectzombie.display;
|
||||||
|
|
||||||
import mainloop.task.IMainloopTask;
|
import mainloop.task.IMainloopTask;
|
||||||
import shootergame.mainloop.MainloopEventHandler;
|
import projectzombie.Main;
|
||||||
|
|
||||||
public class DisplayStatsEventHandler implements IMainloopTask
|
public class DisplayStatsEventHandler implements IMainloopTask
|
||||||
{
|
{
|
||||||
|
|
@ -22,9 +22,9 @@ public class DisplayStatsEventHandler implements IMainloopTask
|
||||||
@Override
|
@Override
|
||||||
public void MainLoopUpdate()
|
public void MainLoopUpdate()
|
||||||
{
|
{
|
||||||
// Set the fps from mspf every second
|
// Display the fps
|
||||||
long mspf = MainloopEventHandler.MAINLOOP_EVENT_HANDLER.mspf;
|
fps = DisplayWindow.fps;
|
||||||
fps = (int)(1000 / mspf);
|
DisplayWindow.fps = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,371 @@
|
||||||
|
package projectzombie.display;
|
||||||
|
|
||||||
|
import java.nio.IntBuffer;
|
||||||
|
|
||||||
|
import org.lwjgl.BufferUtils;
|
||||||
|
import org.lwjgl.glfw.GLFW;
|
||||||
|
import org.lwjgl.opengl.GL33;
|
||||||
|
|
||||||
|
import gl_engine.graphics.GraphicsHelpers;
|
||||||
|
import gl_engine.graphics.GraphicsShader;
|
||||||
|
import mainloop.task.IMainloopTask;
|
||||||
|
import projectzombie.Main;
|
||||||
|
import projectzombie.init.Resources;
|
||||||
|
import projectzombie.input.CursorEnterCallback;
|
||||||
|
import projectzombie.input.CursorPosCallback;
|
||||||
|
import projectzombie.input.JoystickCallback;
|
||||||
|
import projectzombie.input.KeyCallback;
|
||||||
|
import projectzombie.input.KeyCharCallback;
|
||||||
|
import projectzombie.input.MouseButtonCallback;
|
||||||
|
import projectzombie.input.ScrollWheelCallback;
|
||||||
|
import projectzombie.mainloop.MainloopEventHandler;
|
||||||
|
import projectzombie.menu.MenuSettings;
|
||||||
|
import projectzombie.settings.Settings;
|
||||||
|
|
||||||
|
public class DisplayWindow implements IMainloopTask
|
||||||
|
{
|
||||||
|
public static boolean fullscreen;
|
||||||
|
public static boolean vsync;
|
||||||
|
|
||||||
|
private long window;
|
||||||
|
private long monitor;
|
||||||
|
private int width;
|
||||||
|
private int height;
|
||||||
|
private boolean mouseVisibility_last = false;
|
||||||
|
public int texture_max_size;
|
||||||
|
|
||||||
|
public static int fps = 0;
|
||||||
|
|
||||||
|
public GraphicsShader environmentRenderer;
|
||||||
|
public GraphicsShader effectRenderer;
|
||||||
|
|
||||||
|
public int effect_vao;
|
||||||
|
|
||||||
|
public int glsl_mist;
|
||||||
|
public int glsl_color;
|
||||||
|
public int glsl_contrast;
|
||||||
|
public int glsl_discard_coords;
|
||||||
|
public int glsl_do_discard_coords;
|
||||||
|
public int glsl_do_lighting;
|
||||||
|
public int glsl_do_texture;
|
||||||
|
public int glsl_model;
|
||||||
|
public int glsl_camera;
|
||||||
|
public int glsl_projection;
|
||||||
|
public int glsl_projection_sun;
|
||||||
|
public int glsl_rotated;
|
||||||
|
public int glsl_billboard;
|
||||||
|
public int glsl_mode;
|
||||||
|
public int glsl_time;
|
||||||
|
|
||||||
|
public int glsl_day_low;
|
||||||
|
public int glsl_day_high;
|
||||||
|
|
||||||
|
public int glsl_lightmap_offset;
|
||||||
|
public int glsl_lightmap_size;
|
||||||
|
|
||||||
|
public int glsl_effect_time;
|
||||||
|
public int glsl_effect_red;
|
||||||
|
public int glsl_effect_vortex;
|
||||||
|
public int glsl_effect_vsnow;
|
||||||
|
public int glsl_effect_red_freq;
|
||||||
|
public int glsl_effect_chill;
|
||||||
|
|
||||||
|
public static void setVSync(boolean status)
|
||||||
|
{
|
||||||
|
vsync = status;
|
||||||
|
GLFW.glfwSwapInterval(vsync ? 1 : 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getWidth() {
|
||||||
|
return this.width;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getHeight() {
|
||||||
|
return this.height;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setWidth(int w) {
|
||||||
|
width = w;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setHeight(int h) {
|
||||||
|
height = h;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void init()
|
||||||
|
{
|
||||||
|
// Initialize GLFW
|
||||||
|
if(!GLFW.glfwInit()) {
|
||||||
|
throw new RuntimeException("Failed to initialize GLFW");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the monitor size
|
||||||
|
IntBuffer w = BufferUtils.createIntBuffer(1);
|
||||||
|
IntBuffer h = BufferUtils.createIntBuffer(1);
|
||||||
|
monitor = GLFW.glfwGetPrimaryMonitor();
|
||||||
|
GLFW.glfwGetMonitorPhysicalSize(monitor, w, h);
|
||||||
|
width = w.get()*4;
|
||||||
|
height = h.get()*4;
|
||||||
|
|
||||||
|
//GLFW.glfwWindowHint(GLFW.GLFW_DOUBLEBUFFER, GLFW.GLFW_FALSE);
|
||||||
|
|
||||||
|
// Create the window
|
||||||
|
window = GraphicsHelpers.initWindow("Project Zombie", width, height, fullscreen ? monitor : 0);
|
||||||
|
|
||||||
|
// Make the context current
|
||||||
|
GLFW.glfwMakeContextCurrent(this.window);
|
||||||
|
|
||||||
|
// Set the key handlers
|
||||||
|
GLFW.glfwSetCursorPosCallback(this.window, new CursorPosCallback());
|
||||||
|
GLFW.glfwSetCharCallback(this.window, new KeyCharCallback());
|
||||||
|
GLFW.glfwSetCursorEnterCallback(this.window, new CursorEnterCallback());
|
||||||
|
GLFW.glfwSetMouseButtonCallback(this.window, new MouseButtonCallback());
|
||||||
|
GLFW.glfwSetKeyCallback(this.window, new KeyCallback());
|
||||||
|
GLFW.glfwSetJoystickCallback(JoystickCallback.JOYSTICK_CALLBACK);
|
||||||
|
GLFW.glfwSetScrollCallback(this.window, new ScrollWheelCallback());
|
||||||
|
|
||||||
|
// Make the cursor invisible
|
||||||
|
GLFW.glfwSetInputMode(this.window, GLFW.GLFW_CURSOR, GLFW.GLFW_CURSOR_HIDDEN);
|
||||||
|
|
||||||
|
setVSync(vsync);
|
||||||
|
|
||||||
|
// Show the window
|
||||||
|
//GLFW.glfwShowWindow(this.window);
|
||||||
|
|
||||||
|
environmentRenderer = new GraphicsShader("/resources/shader/environmentRenderer");
|
||||||
|
environmentRenderer.use();
|
||||||
|
|
||||||
|
glsl_mist = GL33.glGetUniformLocation(environmentRenderer.program, "mist");
|
||||||
|
glsl_model = GL33.glGetUniformLocation(environmentRenderer.program, "model");
|
||||||
|
glsl_camera = GL33.glGetUniformLocation(environmentRenderer.program, "camera");
|
||||||
|
glsl_rotated = GL33.glGetUniformLocation(environmentRenderer.program, "rotated");
|
||||||
|
glsl_projection = GL33.glGetUniformLocation(environmentRenderer.program, "projection");
|
||||||
|
glsl_projection_sun = GL33.glGetUniformLocation(environmentRenderer.program, "projection_sun");
|
||||||
|
glsl_time = GL33.glGetUniformLocation(environmentRenderer.program, "time");
|
||||||
|
glsl_discard_coords = GL33.glGetUniformLocation(environmentRenderer.program, "discard_coords");
|
||||||
|
glsl_do_discard_coords = GL33.glGetUniformLocation(environmentRenderer.program, "do_discard_coords");
|
||||||
|
glsl_do_lighting = GL33.glGetUniformLocation(environmentRenderer.program, "do_lighting");
|
||||||
|
glsl_do_texture = GL33.glGetUniformLocation(environmentRenderer.program, "do_texture");
|
||||||
|
glsl_color = GL33.glGetUniformLocation(environmentRenderer.program, "color");
|
||||||
|
glsl_contrast = GL33.glGetUniformLocation(environmentRenderer.program, "contrast");
|
||||||
|
glsl_billboard = GL33.glGetUniformLocation(environmentRenderer.program, "billboard");
|
||||||
|
glsl_mode = GL33.glGetUniformLocation(environmentRenderer.program, "mode");
|
||||||
|
|
||||||
|
glsl_day_low = GL33.glGetUniformLocation(environmentRenderer.program, "lighting_day_low");
|
||||||
|
glsl_day_high = GL33.glGetUniformLocation(environmentRenderer.program, "lighting_day_high");
|
||||||
|
|
||||||
|
glsl_lightmap_offset = GL33.glGetUniformLocation(environmentRenderer.program, "lightmap_offset");
|
||||||
|
glsl_lightmap_size = GL33.glGetUniformLocation(environmentRenderer.program, "lightmap_size");
|
||||||
|
|
||||||
|
int glsl_atlas = GL33.glGetUniformLocation(environmentRenderer.program, "atlas");
|
||||||
|
int glsl_lightmap = GL33.glGetUniformLocation(environmentRenderer.program, "lightmap");
|
||||||
|
int glsl_depthmap = GL33.glGetUniformLocation(environmentRenderer.program, "depthmap");
|
||||||
|
|
||||||
|
GL33.glUniform1i(glsl_atlas, 0);
|
||||||
|
GL33.glUniform1i(glsl_lightmap, 1);
|
||||||
|
GL33.glUniform1i(glsl_depthmap, 2);
|
||||||
|
|
||||||
|
effectRenderer = new GraphicsShader("/resources/shader/effectRenderer");
|
||||||
|
effectRenderer.use();
|
||||||
|
|
||||||
|
glsl_effect_time = GL33.glGetUniformLocation(effectRenderer.program, "time");
|
||||||
|
glsl_effect_red = GL33.glGetUniformLocation(effectRenderer.program, "red");
|
||||||
|
glsl_effect_vsnow = GL33.glGetUniformLocation(effectRenderer.program, "vsnow");
|
||||||
|
glsl_effect_vortex = GL33.glGetUniformLocation(effectRenderer.program, "vortex");
|
||||||
|
glsl_effect_red_freq = GL33.glGetUniformLocation(effectRenderer.program, "red_freq");
|
||||||
|
glsl_effect_chill = GL33.glGetUniformLocation(effectRenderer.program, "chill");
|
||||||
|
|
||||||
|
//GL33.glUniform1i(GL33.glGetUniformLocation(effectRenderer.program, "shadowMap"), 2);
|
||||||
|
|
||||||
|
effect_vao = GL33.glGenVertexArrays();
|
||||||
|
GL33.glBindVertexArray(effect_vao);
|
||||||
|
|
||||||
|
int effect_vbo = GL33.glGenBuffers();
|
||||||
|
GL33.glBindBuffer(GL33.GL_ARRAY_BUFFER, effect_vbo);
|
||||||
|
GL33.glBufferData(GL33.GL_ARRAY_BUFFER, new float[] {
|
||||||
|
-1, -1,
|
||||||
|
-1, 1,
|
||||||
|
1, 1,
|
||||||
|
|
||||||
|
-1, -1,
|
||||||
|
1, -1,
|
||||||
|
1, 1,
|
||||||
|
}, GL33.GL_STATIC_DRAW);
|
||||||
|
|
||||||
|
GL33.glVertexAttribPointer(0, 2, GL33.GL_FLOAT, false, Float.BYTES * 2, 0);
|
||||||
|
GL33.glEnableVertexAttribArray(0);
|
||||||
|
|
||||||
|
int[] ptr = new int[1];
|
||||||
|
GL33.glGetIntegerv(GL33.GL_MAX_TEXTURE_SIZE, ptr);
|
||||||
|
|
||||||
|
texture_max_size = ptr[0];
|
||||||
|
System.out.println("Max texture size: " + texture_max_size);
|
||||||
|
|
||||||
|
DisplayRender.init();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void render()
|
||||||
|
{
|
||||||
|
// Set the framebuffer size
|
||||||
|
int w[] = {0};
|
||||||
|
int h[] = {0};
|
||||||
|
GLFW.glfwGetFramebufferSize(this.window, w, h);
|
||||||
|
width = w[0];
|
||||||
|
height = h[0];
|
||||||
|
|
||||||
|
environmentRenderer.use();
|
||||||
|
DisplayLighting.updateLighting();
|
||||||
|
|
||||||
|
GL33.glUniform1f(glsl_mist, 1f/256f);
|
||||||
|
GL33.glUniform1i(glsl_do_texture, 1);
|
||||||
|
|
||||||
|
if(Main.player.getHydration() < 0.2) {
|
||||||
|
GL33.glUniform1f(glsl_contrast, (float)(0.2 - Main.player.getHydration()) * 1.6f);
|
||||||
|
} else {
|
||||||
|
GL33.glUniform1f(glsl_contrast, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bind the texture atlas
|
||||||
|
GL33.glActiveTexture(GL33.GL_TEXTURE0);
|
||||||
|
Resources.ATLAS.bind();
|
||||||
|
|
||||||
|
// Bind the lightmap
|
||||||
|
GL33.glActiveTexture(GL33.GL_TEXTURE1);
|
||||||
|
GL33.glBindTexture(GL33.GL_TEXTURE_2D, DisplayLighting.lightmap);
|
||||||
|
|
||||||
|
// Bind the shadow depth map
|
||||||
|
GL33.glActiveTexture(GL33.GL_TEXTURE2);
|
||||||
|
GL33.glBindTexture(GL33.GL_TEXTURE_2D, DisplayRender.shadow_depth);
|
||||||
|
|
||||||
|
// Render everything
|
||||||
|
DisplayRender.render(w[0], h[0]);
|
||||||
|
|
||||||
|
// Use the effect shader
|
||||||
|
effectRenderer.use();
|
||||||
|
|
||||||
|
// Bind the shadow depth map
|
||||||
|
GL33.glActiveTexture(GL33.GL_TEXTURE0);
|
||||||
|
GL33.glBindTexture(GL33.GL_TEXTURE_2D, DisplayRender.shadow_depth);
|
||||||
|
|
||||||
|
// Send extra data to the shader
|
||||||
|
if(!Main.player.dead && Main.menu.doGameloop) {
|
||||||
|
GL33.glUniform1i(glsl_effect_time, (int)System.currentTimeMillis());
|
||||||
|
}
|
||||||
|
|
||||||
|
if(Main.player.getHydration() < 0.2) {
|
||||||
|
GL33.glUniform1f(glsl_effect_vsnow, (float)(0.2 - Main.player.getHydration()));
|
||||||
|
GL33.glUniform1f(glsl_effect_vortex, (float)(0.2 - Main.player.getHydration()) / 10);
|
||||||
|
} else {
|
||||||
|
GL33.glUniform1f(glsl_effect_vsnow, 0);
|
||||||
|
GL33.glUniform1f(glsl_effect_vortex, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
double player_health = Main.player.getHealth() / Main.player.maxHealth();
|
||||||
|
|
||||||
|
if(player_health < 0.25) {
|
||||||
|
GL33.glUniform1f(glsl_effect_red, (float)Math.min(2 * (0.25 - player_health), 0.5));
|
||||||
|
GL33.glUniform1i(glsl_effect_red_freq, 20);
|
||||||
|
} else {
|
||||||
|
GL33.glUniform1f(glsl_effect_red, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(Main.player.getTemperature() < 0.3) {
|
||||||
|
GL33.glUniform1f(glsl_effect_chill, (float)(0.3 - Main.player.getTemperature()) / 3 * 10);
|
||||||
|
} else {
|
||||||
|
GL33.glUniform1f(glsl_effect_chill, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Draw a quad to the whole screen for the effects
|
||||||
|
GL33.glBindVertexArray(effect_vao);
|
||||||
|
GL33.glDrawArrays(GL33.GL_TRIANGLES, 0, 6);
|
||||||
|
|
||||||
|
environmentRenderer.use();
|
||||||
|
DisplayLighting.updateLighting();
|
||||||
|
|
||||||
|
GL33.glUniform1i(glsl_do_texture, 1);
|
||||||
|
|
||||||
|
// Bind the texture atlas
|
||||||
|
GL33.glActiveTexture(GL33.GL_TEXTURE0);
|
||||||
|
Resources.ATLAS.bind();
|
||||||
|
|
||||||
|
// Render the user interface
|
||||||
|
DisplayRenderUI.render();
|
||||||
|
|
||||||
|
// Swap the framebuffers and poll events
|
||||||
|
GLFW.glfwSwapBuffers(window);
|
||||||
|
GLFW.glfwPollEvents();
|
||||||
|
|
||||||
|
fps += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void toggleFullscreen()
|
||||||
|
{
|
||||||
|
// Exit fullscreen if the window is in fullscreen
|
||||||
|
if(fullscreen)
|
||||||
|
{
|
||||||
|
fullscreen = false;
|
||||||
|
GLFW.glfwSetWindowMonitor(window, 0, 1, 1, width, height, GLFW.GLFW_DONT_CARE);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Enter fullscreen if the window is windowed
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Get the monitor size
|
||||||
|
IntBuffer w = BufferUtils.createIntBuffer(1);
|
||||||
|
IntBuffer h = BufferUtils.createIntBuffer(1);
|
||||||
|
GLFW.glfwGetMonitorPhysicalSize(monitor, w, h);
|
||||||
|
width = w.get()*4;
|
||||||
|
height = h.get()*4;
|
||||||
|
|
||||||
|
// Enter fullscreen mode
|
||||||
|
fullscreen = true;
|
||||||
|
GLFW.glfwSetWindowMonitor(window, monitor, 0, 0, width, height, GLFW.GLFW_DONT_CARE);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update the settings file
|
||||||
|
Settings.update();
|
||||||
|
|
||||||
|
if(Main.menu instanceof MenuSettings) {
|
||||||
|
((MenuSettings) Main.menu).buttonFullscreen.setText(
|
||||||
|
"Fullscreen: " + (fullscreen ? "On" : "Off"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMouseVisibility(boolean status) {
|
||||||
|
if(status != mouseVisibility_last) {
|
||||||
|
mouseVisibility_last = status;
|
||||||
|
if(status) {
|
||||||
|
GLFW.glfwSetInputMode(window, GLFW.GLFW_CURSOR, GLFW.GLFW_CURSOR_NORMAL);
|
||||||
|
} else {
|
||||||
|
GLFW.glfwSetInputMode(window, GLFW.GLFW_CURSOR, GLFW.GLFW_CURSOR_HIDDEN);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean shouldClose() {
|
||||||
|
return GLFW.glfwWindowShouldClose(window);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void makeContextCurrent() {
|
||||||
|
GLFW.glfwMakeContextCurrent(window);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean MainLoopDelay(long millis) {
|
||||||
|
return millis > MainloopEventHandler.MAINLOOP_EVENT_HANDLER.mspf;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean MainLoopRepeat() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void MainLoopUpdate() {
|
||||||
|
this.render();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTitle(String string) {
|
||||||
|
GLFW.glfwSetWindowTitle(window, string);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,55 @@
|
||||||
|
package projectzombie.display.bossbar;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
public class BossBars
|
||||||
|
{
|
||||||
|
private static final ArrayList<IBossBar> bossbars = new ArrayList<IBossBar>();
|
||||||
|
|
||||||
|
public static void register(IBossBar bossbar) {
|
||||||
|
bossbars.add(bossbar);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void clear() {
|
||||||
|
bossbars.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void render()
|
||||||
|
{
|
||||||
|
/*TextureReference health_fg = Models.UI_HEALTH_FG;
|
||||||
|
TextureReference health_bg = Models.UI_HEALTH_BG;
|
||||||
|
ArrayList<IBossBar> toRemove = new ArrayList<IBossBar>();
|
||||||
|
|
||||||
|
double s = GlHelpers.getScale() / 10.0;
|
||||||
|
|
||||||
|
// Render the boss bars
|
||||||
|
int i = 0;
|
||||||
|
for(IBossBar bossbar : bossbars)
|
||||||
|
{
|
||||||
|
double max_health = bossbar.maxHealth();
|
||||||
|
double a = 1 - (bossbar.getHealth() / max_health);
|
||||||
|
GlHelpers.begin();
|
||||||
|
|
||||||
|
health_bg.texCoord(0, 1); GlHelpers.vertex2(-4*s, 8.5*s - i);
|
||||||
|
health_bg.texCoord(0, 0); GlHelpers.vertex2(-4*s, 9.0*s - i);
|
||||||
|
health_bg.texCoord(1, 0); GlHelpers.vertex2(4*s, 9.0*s - i);
|
||||||
|
health_bg.texCoord(1, 1); GlHelpers.vertex2(4*s, 8.5*s - i);
|
||||||
|
|
||||||
|
health_fg.texCoord(0, 1); GlHelpers.vertex2(-4*s, 8.5*s - i);
|
||||||
|
health_fg.texCoord(0, 0); GlHelpers.vertex2(-4*s, 9.0*s - i);
|
||||||
|
health_fg.texCoord(1-a, 0); GlHelpers.vertex2(4*s-a*8*s, 9.0*s - i);
|
||||||
|
health_fg.texCoord(1-a, 1); GlHelpers.vertex2(4*s-a*8*s, 8.5*s - i);
|
||||||
|
|
||||||
|
GlHelpers.end();
|
||||||
|
i += 1;
|
||||||
|
|
||||||
|
if(!bossbar.displayBossBar()) {
|
||||||
|
toRemove.add(bossbar);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for(IBossBar bossbar : toRemove) {
|
||||||
|
bossbars.remove(bossbar);
|
||||||
|
}*/
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,9 @@
|
||||||
|
package projectzombie.display.bossbar;
|
||||||
|
|
||||||
|
import projectzombie.entity.EntityAlive;
|
||||||
|
|
||||||
|
public interface IBossBar extends EntityAlive
|
||||||
|
{
|
||||||
|
public String getName();
|
||||||
|
public boolean displayBossBar();
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,389 @@
|
||||||
|
package projectzombie.entity;
|
||||||
|
|
||||||
|
import java.lang.reflect.Constructor;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
import projectzombie.util.ClassBdf;
|
||||||
|
import projectzombie.util.TileState;
|
||||||
|
import bdf.types.BdfNamedList;
|
||||||
|
import bdf.types.BdfObject;
|
||||||
|
import gl_engine.MathHelpers;
|
||||||
|
import gl_engine.vec.Vec2d;
|
||||||
|
import gl_engine.vec.Vec2i;
|
||||||
|
import gl_engine.vec.Vec3d;
|
||||||
|
import projectzombie.Main;
|
||||||
|
import projectzombie.init.Entities;
|
||||||
|
import projectzombie.model.IModel;
|
||||||
|
import projectzombie.tiles.Tile;
|
||||||
|
import projectzombie.world.chunk.Chunk;
|
||||||
|
import projectzombie.world.layer.Layer;
|
||||||
|
|
||||||
|
public abstract class Entity implements ClassBdf
|
||||||
|
{
|
||||||
|
public double hitbox = 1;
|
||||||
|
public boolean isSolid = false;
|
||||||
|
public Chunk chunk;
|
||||||
|
private TileState tile_front;
|
||||||
|
private TileState tile_back;
|
||||||
|
protected static final Random rand = new Random();
|
||||||
|
public boolean emitsLight = false;
|
||||||
|
private boolean isDead = false;
|
||||||
|
protected boolean hasGravity = true;
|
||||||
|
|
||||||
|
private Vec3d pos;
|
||||||
|
private Vec3d velocity;
|
||||||
|
|
||||||
|
public abstract IModel getModel();
|
||||||
|
|
||||||
|
public boolean isDead() {
|
||||||
|
return isDead;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Vec3d getPos() {
|
||||||
|
return pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPos(Vec3d pos) {
|
||||||
|
this.pos = pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Vec3d getVelocity() {
|
||||||
|
return velocity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setVelocity(Vec3d velocity) {
|
||||||
|
this.velocity = velocity;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected double getTilesLightDissipation() {
|
||||||
|
if(chunk == null) return 0;
|
||||||
|
TileState tsf = chunk.getFrontTile(pos.xz().toInt());
|
||||||
|
TileState tsb = chunk.getBackTile(pos.xz().toInt());
|
||||||
|
return MathHelpers.biggest(
|
||||||
|
tsf.tile.getLightDissipation(tsf),
|
||||||
|
tsb.tile.getLightDissipation(tsb));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected double getLightWithHeight(double light) {
|
||||||
|
double height = Math.abs(getVelocity().y) + 1;
|
||||||
|
return light - (this.getTilesLightDissipation() * height);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getID() {
|
||||||
|
for(int i=0;i<Entities.ENTITIES.size();i++) {
|
||||||
|
Class<? extends Entity> ec = Entities.ENTITIES.get(i);
|
||||||
|
if(ec == this.getClass()) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Entity loadEntity(BdfObject bdf)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// Load the entity id
|
||||||
|
BdfNamedList nl = bdf.getNamedList();
|
||||||
|
int id = nl.get("id").getInteger();
|
||||||
|
|
||||||
|
// Send back null if the id is out of range
|
||||||
|
if(id < 0 || id >= Entities.ENTITIES.size()) {
|
||||||
|
System.out.println("Warning: Invalid ID detected: " + id);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the class and the constructor
|
||||||
|
Class<? extends Entity> ecl = Entities.ENTITIES.get(id);
|
||||||
|
Constructor<? extends Entity> econ = ecl.getConstructor(BdfObject.class);
|
||||||
|
|
||||||
|
// Send back the new entity
|
||||||
|
return econ.newInstance(bdf);
|
||||||
|
}
|
||||||
|
|
||||||
|
catch(
|
||||||
|
NoSuchMethodException |
|
||||||
|
SecurityException |
|
||||||
|
InstantiationException |
|
||||||
|
IllegalAccessException |
|
||||||
|
IllegalArgumentException |
|
||||||
|
InvocationTargetException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
|
||||||
|
// Send null if there was an issue
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Entity(Vec3d pos, Vec3d velocity)
|
||||||
|
{
|
||||||
|
// Store the specified values
|
||||||
|
this.velocity = velocity.copy();
|
||||||
|
this.pos = pos.copy();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Entity() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void BdfClassLoad(BdfObject bdf) {
|
||||||
|
BdfNamedList nl = bdf.getNamedList();
|
||||||
|
pos = new Vec3d(nl.get("pos"));
|
||||||
|
velocity = new Vec3d(nl.get("velocity"));
|
||||||
|
hitbox = nl.get("hitbox").getDouble();
|
||||||
|
isSolid = nl.get("isSolid").getBoolean();
|
||||||
|
emitsLight = nl.get("emitsLight").getBoolean();
|
||||||
|
hasGravity = nl.get("hasGravity").getBoolean();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void BdfClassSave(BdfObject bdf)
|
||||||
|
{
|
||||||
|
// Get the ID and return if its invalid (entity can't be saved)
|
||||||
|
int id = getID();
|
||||||
|
if(id == -1) return;
|
||||||
|
|
||||||
|
BdfNamedList nl = bdf.getNamedList();
|
||||||
|
nl.set("id", bdf.newObject().setInteger(getID()));
|
||||||
|
|
||||||
|
BdfObject pos_bdf = bdf.newObject();
|
||||||
|
pos.BdfClassSave(pos_bdf);
|
||||||
|
|
||||||
|
BdfObject velocity_bdf = bdf.newObject();
|
||||||
|
velocity.BdfClassSave(velocity_bdf);
|
||||||
|
|
||||||
|
nl.set("pos", pos_bdf);
|
||||||
|
nl.set("velocity", velocity_bdf);
|
||||||
|
nl.set("hitbox", bdf.newObject().setDouble(hitbox));
|
||||||
|
nl.set("isSolid", bdf.newObject().setBoolean(isSolid));
|
||||||
|
nl.set("emitsLight", bdf.newObject().setBoolean(emitsLight));
|
||||||
|
nl.set("hasGravity", bdf.newObject().setBoolean(hasGravity));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void tick(Chunk chunk, Layer layer)
|
||||||
|
{
|
||||||
|
//speed = 1;
|
||||||
|
//angle = MathHelpers.mod(angle, 360);
|
||||||
|
if(chunk == null) chunk = layer.getChunk(pos.xz());
|
||||||
|
this.chunk = chunk;
|
||||||
|
|
||||||
|
Vec2i tpos = pos.xz().toInt();
|
||||||
|
boolean pos_is_legal = moveIsLegal(pos.xz());
|
||||||
|
|
||||||
|
tile_back = chunk.getBackTile(tpos);
|
||||||
|
tile_front = chunk.getFrontTile(tpos);
|
||||||
|
|
||||||
|
if(velocity.x != 0 || velocity.y != 0 || velocity.z != 0)
|
||||||
|
{
|
||||||
|
Vec3d new_pos = pos.add(velocity);
|
||||||
|
|
||||||
|
double slipperiness = Math.max(
|
||||||
|
tile_back.tile.getSlipperiness(tile_back),
|
||||||
|
tile_front.tile.getSlipperiness(tile_front));
|
||||||
|
|
||||||
|
if(isSolid) {
|
||||||
|
|
||||||
|
if(moveIsLegal(new Vec2d(new_pos.x, pos.z)) || !pos_is_legal) {
|
||||||
|
pos.x = new_pos.x;
|
||||||
|
} else {
|
||||||
|
velocity.x *= -0.25;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(moveIsLegal(new Vec2d(pos.x, new_pos.z)) || !pos_is_legal) {
|
||||||
|
pos.z = new_pos.z;
|
||||||
|
} else {
|
||||||
|
velocity.z *= -0.25;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
pos.x = new_pos.x;
|
||||||
|
pos.z = new_pos.z;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(new_pos.y > 0) {
|
||||||
|
pos.y = new_pos.y;
|
||||||
|
} else if(pos.y >= 0) {
|
||||||
|
velocity.y *= -0.25;
|
||||||
|
velocity.x *= slipperiness;
|
||||||
|
velocity.z *= slipperiness;
|
||||||
|
pos.y = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(hasGravity) {
|
||||||
|
velocity.y -= MathHelpers.FallSpeed;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(isSolid)
|
||||||
|
{
|
||||||
|
moveAwayFromSolidEntities(layer);
|
||||||
|
|
||||||
|
if(pos.y <= 0) {
|
||||||
|
tile_back.tile.onWalkedOn(chunk, layer, tpos, this, tile_back);
|
||||||
|
tile_front.tile.onWalkedOn(chunk, layer, tpos, this, tile_front);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Move the player out of a solid area
|
||||||
|
if(!pos_is_legal)
|
||||||
|
{
|
||||||
|
Vec2i collision_pos = pos.xz().toInt();
|
||||||
|
Vec2d direction = pos.xz().subtract(collision_pos.toDouble()).subtract(0.5);
|
||||||
|
|
||||||
|
// Do this to prevent division by zero, just move in an arbitrary direction
|
||||||
|
if(direction.x == 0 && direction.y == 0) {
|
||||||
|
push(new Vec3d(0.1, 0, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
push(direction.multiply(0.1).xny());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void moveAwayFromSolidEntities(Layer layer)
|
||||||
|
{
|
||||||
|
if(isSolid)
|
||||||
|
{
|
||||||
|
for(Entity e : layer.getNearbyEntities(pos.xz(), hitbox))
|
||||||
|
{
|
||||||
|
if(e.isSolid && e != this)
|
||||||
|
{
|
||||||
|
double distance = pos.distance(e.pos);
|
||||||
|
double angle = MathHelpers.atan2(e.pos.z - pos.z, e.pos.x - pos.x);
|
||||||
|
|
||||||
|
Vec3d vec_push = MathHelpers.moveTowards2(distance == 0 ? 1 : (0.5 / distance), angle).xny();
|
||||||
|
|
||||||
|
push(vec_push.multiply(-0.125));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void push(Vec3d vec)
|
||||||
|
{
|
||||||
|
if(pos.y <= 0)
|
||||||
|
{
|
||||||
|
Layer layer = Main.world.getLayer();
|
||||||
|
|
||||||
|
Vec2i tpos = pos.xz().toInt();
|
||||||
|
tile_back = layer.getBackTile(tpos);
|
||||||
|
tile_front = layer.getFrontTile(tpos);
|
||||||
|
|
||||||
|
double slipperiness = Math.max(
|
||||||
|
tile_back.tile.getSlipperiness(tile_back),
|
||||||
|
tile_front.tile.getSlipperiness(tile_front));
|
||||||
|
|
||||||
|
double resistance = Math.max(
|
||||||
|
tile_back.tile.getResistance(tile_back),
|
||||||
|
tile_front.tile.getResistance(tile_front));
|
||||||
|
|
||||||
|
velocity = velocity.add(vec.multiply((1 - slipperiness) * (1 - resistance)));
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
velocity = velocity.add(vec);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void kill() {
|
||||||
|
chunk.killEntity(this);
|
||||||
|
isDead = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean activateTile(Vec2i tpos)
|
||||||
|
{
|
||||||
|
// Get the tile position and the layer
|
||||||
|
Layer layer = Main.world.getLayer();
|
||||||
|
TileState tile_front = layer.getFrontTile(tpos);
|
||||||
|
TileState tile_back = layer.getBackTile(tpos);
|
||||||
|
|
||||||
|
// Activate both tiles
|
||||||
|
return (
|
||||||
|
tile_front.tile.onActivated(layer, tpos, this, tile_front) ||
|
||||||
|
tile_back.tile.onActivated(layer, tpos, this, tile_back));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void activateSteppedOnTile()
|
||||||
|
{
|
||||||
|
// Get the tile position and the layer
|
||||||
|
Layer layer = Main.world.getLayer();
|
||||||
|
Vec2i tpos = new Vec2i(MathHelpers.floor(pos.x)+0, MathHelpers.floor(pos.z)+0);
|
||||||
|
|
||||||
|
// Activate both tiles
|
||||||
|
tile_front.tile.onWalkedOn(chunk, layer, tpos, this, tile_front);
|
||||||
|
tile_back.tile.onWalkedOn(chunk, layer, tpos, this, tile_back);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean moveIsLegal(Vec2d pos)
|
||||||
|
{
|
||||||
|
Layer layer = Main.world.getLayer();
|
||||||
|
|
||||||
|
// Is this entity solid
|
||||||
|
if(isSolid)
|
||||||
|
{
|
||||||
|
final Vec2i[] positions = {
|
||||||
|
new Vec2i(-1, -1),
|
||||||
|
new Vec2i(1, -1),
|
||||||
|
new Vec2i(1, 1),
|
||||||
|
new Vec2i(-1, 1),
|
||||||
|
new Vec2i(1, 0),
|
||||||
|
new Vec2i(0, 1),
|
||||||
|
new Vec2i(-1, 0),
|
||||||
|
new Vec2i(0, -1),
|
||||||
|
new Vec2i(0, 0),
|
||||||
|
};
|
||||||
|
|
||||||
|
for(Vec2i tpos_offset : positions)
|
||||||
|
{
|
||||||
|
// Check the tile the player is standing on
|
||||||
|
Vec2i tpos = new Vec2i(
|
||||||
|
MathHelpers.floor(pos.x) + tpos_offset.x,
|
||||||
|
MathHelpers.floor(pos.y) + tpos_offset.y);
|
||||||
|
|
||||||
|
TileState tile_back = layer.getBackTile(tpos);
|
||||||
|
TileState tile_front = layer.getFrontTile(tpos);
|
||||||
|
|
||||||
|
{
|
||||||
|
// Get the tile
|
||||||
|
Tile t = tile_back.tile;
|
||||||
|
|
||||||
|
// Check the tiles hitbox if the tile is solid
|
||||||
|
if(t.tileSolid)
|
||||||
|
{
|
||||||
|
// Is the entity in the tiles hitbox
|
||||||
|
Vec2d check = pos.subtract(tpos.toDouble());
|
||||||
|
if(t.inHitbox(tile_back, check)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
// Get the front tile
|
||||||
|
Tile t = tile_front.tile;
|
||||||
|
|
||||||
|
// Check the tiles hitbox if the tile is solid
|
||||||
|
if(t.tileSolid)
|
||||||
|
{
|
||||||
|
// Is the entity in the tiles hitbox
|
||||||
|
Vec2d check = pos.subtract(tpos.toDouble());
|
||||||
|
if(t.inHitbox(tile_front, check)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Send back true if everything passes
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getLightLevel() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,21 @@
|
||||||
|
package projectzombie.entity;
|
||||||
|
|
||||||
|
import projectzombie.world.layer.Layer;
|
||||||
|
|
||||||
|
public interface EntityAlive
|
||||||
|
{
|
||||||
|
public void addHealth(double amount);
|
||||||
|
public double getHealth();
|
||||||
|
public void resetHealth();
|
||||||
|
public void clearHealth();
|
||||||
|
public double maxHealth();
|
||||||
|
public void setHealth(double health);
|
||||||
|
public int bloodParticles();
|
||||||
|
|
||||||
|
public void addDamage(double amount);
|
||||||
|
public void addFireDamage(double amount);
|
||||||
|
public void addBlastDamage(double amount);
|
||||||
|
|
||||||
|
public default void onDeath(Layer layer) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,265 @@
|
||||||
|
package projectzombie.entity;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
import bdf.types.BdfNamedList;
|
||||||
|
import bdf.types.BdfObject;
|
||||||
|
import gl_engine.MathHelpers;
|
||||||
|
import gl_engine.vec.Vec2d;
|
||||||
|
import gl_engine.vec.Vec2i;
|
||||||
|
import gl_engine.vec.Vec3d;
|
||||||
|
import projectzombie.Main;
|
||||||
|
import projectzombie.display.bossbar.BossBars;
|
||||||
|
import projectzombie.display.bossbar.IBossBar;
|
||||||
|
import projectzombie.init.Items;
|
||||||
|
import projectzombie.init.Models;
|
||||||
|
import projectzombie.init.Tiles;
|
||||||
|
import projectzombie.items.modifier.ItemModifierMeta;
|
||||||
|
import projectzombie.model.Model;
|
||||||
|
import projectzombie.time.GameTimer;
|
||||||
|
import projectzombie.util.ItemStack;
|
||||||
|
import projectzombie.util.math.random.OpenSimplexNoise;
|
||||||
|
import projectzombie.util.math.random.RandomHelpers;
|
||||||
|
import projectzombie.world.chunk.Chunk;
|
||||||
|
import projectzombie.world.layer.Layer;
|
||||||
|
|
||||||
|
public class EntityBoss extends Entity implements IBossBar, EntityKillWithParticles
|
||||||
|
{
|
||||||
|
private boolean moving = false;
|
||||||
|
private boolean firing = false;
|
||||||
|
private double max_health = 25000;
|
||||||
|
private double health = max_health;
|
||||||
|
private int bullet_frequency = 0;
|
||||||
|
private int spawn_frequency = 0;
|
||||||
|
private double time = 0;
|
||||||
|
|
||||||
|
private OpenSimplexNoise noise_gun;
|
||||||
|
private OpenSimplexNoise noise_walk;
|
||||||
|
private OpenSimplexNoise noise_spawn;
|
||||||
|
protected OpenSimplexNoise noise_target_x;
|
||||||
|
protected OpenSimplexNoise noise_target_y;
|
||||||
|
|
||||||
|
private long seed;
|
||||||
|
|
||||||
|
public EntityBoss(BdfObject bdf) {
|
||||||
|
BdfClassLoad(bdf);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void BdfClassLoad(BdfObject bdf) {
|
||||||
|
super.BdfClassLoad(bdf);
|
||||||
|
|
||||||
|
BdfNamedList nl = bdf.getNamedList();
|
||||||
|
health = nl.get("health").getDouble();
|
||||||
|
bullet_frequency = nl.get("bullet_freq").getInteger();
|
||||||
|
spawn_frequency = nl.get("spawn_frq").getInteger();
|
||||||
|
|
||||||
|
this.isSolid = true;
|
||||||
|
this.hitbox = 2;
|
||||||
|
|
||||||
|
long seed = nl.get("seed").getLong();
|
||||||
|
Random rand = new Random(seed);
|
||||||
|
this.noise_gun = new OpenSimplexNoise(rand.nextLong());
|
||||||
|
this.noise_walk = new OpenSimplexNoise(rand.nextLong());
|
||||||
|
this.noise_spawn = new OpenSimplexNoise(rand.nextLong());
|
||||||
|
this.noise_target_x = new OpenSimplexNoise(rand.nextLong());
|
||||||
|
this.noise_target_y = new OpenSimplexNoise(rand.nextLong());
|
||||||
|
|
||||||
|
BossBars.register(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void BdfClassSave(BdfObject bdf) {
|
||||||
|
super.BdfClassSave(bdf);
|
||||||
|
|
||||||
|
BdfNamedList nl = bdf.getNamedList();
|
||||||
|
nl.set("health", bdf.newObject().setDouble(health));
|
||||||
|
nl.set("bullet_freq", bdf.newObject().setInteger(bullet_frequency));
|
||||||
|
nl.set("spawn_freq", bdf.newObject().setInteger(spawn_frequency));
|
||||||
|
nl.set("seed", bdf.newObject().setLong(seed));
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityBoss(Vec3d pos, Vec3d velocity) {
|
||||||
|
super(pos, velocity);
|
||||||
|
|
||||||
|
this.isSolid = true;
|
||||||
|
this.hitbox = 2;
|
||||||
|
|
||||||
|
long seed = rand.nextLong();
|
||||||
|
Random rand = new Random(seed);
|
||||||
|
this.noise_gun = new OpenSimplexNoise(rand.nextLong());
|
||||||
|
this.noise_walk = new OpenSimplexNoise(rand.nextLong());
|
||||||
|
this.noise_spawn = new OpenSimplexNoise(rand.nextLong());
|
||||||
|
this.noise_target_x = new OpenSimplexNoise(rand.nextLong());
|
||||||
|
this.noise_target_y = new OpenSimplexNoise(rand.nextLong());
|
||||||
|
|
||||||
|
BossBars.register(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void tick(Chunk chunk, Layer layer) {
|
||||||
|
super.tick(chunk, layer);
|
||||||
|
|
||||||
|
Vec3d bpos = getPos();
|
||||||
|
Vec3d ppos = Main.player.getPos();
|
||||||
|
|
||||||
|
double angle = Math.atan2(
|
||||||
|
bpos.x - ppos.x + noise_target_x.eval(
|
||||||
|
time*2, ppos.x/25, ppos.z/25)*10,
|
||||||
|
bpos.z - ppos.z + noise_target_y.eval(
|
||||||
|
time*2, ppos.x/25, ppos.z/25)*10);
|
||||||
|
angle = Math.toDegrees(angle) + 180;
|
||||||
|
|
||||||
|
if(this.noise_spawn.eval(GameTimer.getTime() / 500.0, 0) > 0.2) {
|
||||||
|
if(spawn_frequency == 0) {
|
||||||
|
int r = 2, m = 1000;
|
||||||
|
Vec2d zombie_pos = new Vec2d(
|
||||||
|
RandomHelpers.randrange(rand, -r*m, r*m)/(double)m,
|
||||||
|
RandomHelpers.randrange(rand, -r*m, r*m)/(double)m);
|
||||||
|
Vec2i zombie_tpos = zombie_pos.toInt();
|
||||||
|
if(
|
||||||
|
layer.getBackTile(zombie_tpos).tile == layer.layergen.getTileDestroyed(layer, zombie_tpos).tile &&
|
||||||
|
layer.getFrontTile(zombie_tpos).tile == Tiles.VOID) {
|
||||||
|
layer.spawnEntity(new EntityZombie(bpos.add(zombie_pos.xny()), getVelocity()));
|
||||||
|
}
|
||||||
|
spawn_frequency = 50;
|
||||||
|
}
|
||||||
|
spawn_frequency -= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(this.noise_gun.eval(GameTimer.getTime() / 500.0, 0) > 0 && !Main.player.dead && !Main.player.in_animation) {
|
||||||
|
|
||||||
|
if(bullet_frequency == 0) {
|
||||||
|
chunk.spawnEntity(new EntityBullet(bpos, bpos.subtract(ppos).normalize(), this, 20, 1000));
|
||||||
|
bullet_frequency = 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
bullet_frequency -= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(this.noise_gun.eval(GameTimer.getTime() / 500.0, 0) > -0.2) {
|
||||||
|
this.firing = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
this.firing = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(this.noise_walk.eval(GameTimer.getTime() / 500.0, 0) > -0.4) {
|
||||||
|
this.moveTowards(angle);
|
||||||
|
this.moving = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
this.moving = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Increase time
|
||||||
|
time += 0.001;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addHealth(double amount) {
|
||||||
|
this.health += amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addDamage(double amount) {
|
||||||
|
this.health -= amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addFireDamage(double amount) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addBlastDamage(double amount) {
|
||||||
|
addDamage(amount);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double getHealth() {
|
||||||
|
return health;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void resetHealth() {
|
||||||
|
this.health = max_health;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void clearHealth() {
|
||||||
|
this.health = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double maxHealth() {
|
||||||
|
return max_health;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setHealth(double health) {
|
||||||
|
this.health = health;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int bloodParticles() {
|
||||||
|
return 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "Final Boss";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean displayBossBar() {
|
||||||
|
return health >= 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void moveTowards(double angle) {
|
||||||
|
this.push(MathHelpers.moveTowards2(0.04, Math.toRadians(angle)).xny());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDeath(Layer layer) {
|
||||||
|
IBossBar.super.onDeath(layer);
|
||||||
|
|
||||||
|
/*
|
||||||
|
Drop some powerful loot
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Spawn the loot
|
||||||
|
layer.spawnEntity(new EntityItem(getPos(), getVelocity(), new ItemStack(
|
||||||
|
Items.HEALTH_POTION, RandomHelpers.randrange(rand, 20), new ItemModifierMeta(50))));
|
||||||
|
layer.spawnEntity(new EntityItem(getPos(), getVelocity(), new ItemStack(
|
||||||
|
Items.AMMO, RandomHelpers.randrange(rand, 200), new ItemModifierMeta(50))));
|
||||||
|
layer.spawnEntity(new EntityItem(getPos(), getVelocity(), new ItemStack(
|
||||||
|
Items.GRAPPLING_HOOK, 1, new ItemModifierMeta(2))));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void moveAwayFromSolidEntities(Layer layer) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void killWithParticles() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Model getModel()
|
||||||
|
{
|
||||||
|
if(moving && firing) {
|
||||||
|
return Models.ENTITY_BOSS_WALKING_AND_FIRING;
|
||||||
|
} else if(moving) {
|
||||||
|
return Models.ENTITY_BOSS_WALKING;
|
||||||
|
} else if(firing) {
|
||||||
|
return Models.ENTITY_BOSS_FIRING;
|
||||||
|
} else {
|
||||||
|
return Models.ENTITY_BOSS_IDLE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,156 @@
|
||||||
|
package projectzombie.entity;
|
||||||
|
|
||||||
|
import bdf.types.BdfNamedList;
|
||||||
|
import bdf.types.BdfObject;
|
||||||
|
import gl_engine.texture.TextureRef3D;
|
||||||
|
import gl_engine.vec.Vec2d;
|
||||||
|
import gl_engine.vec.Vec2i;
|
||||||
|
import gl_engine.vec.Vec3d;
|
||||||
|
import projectzombie.entity.particle.ParticleBlood;
|
||||||
|
import projectzombie.init.Resources;
|
||||||
|
import projectzombie.init.Sounds;
|
||||||
|
import projectzombie.tiles.Tile;
|
||||||
|
import projectzombie.tiles.TileBulletBreakable;
|
||||||
|
import projectzombie.util.math.random.RandomHelpers;
|
||||||
|
import projectzombie.world.chunk.Chunk;
|
||||||
|
import projectzombie.world.layer.Layer;
|
||||||
|
|
||||||
|
public class EntityBullet extends EntityParticle
|
||||||
|
{
|
||||||
|
private static final TextureRef3D BULLET = Resources.ATLAS.get("/particle/bullet.png");
|
||||||
|
|
||||||
|
private int time = 0;
|
||||||
|
private Entity parent;
|
||||||
|
|
||||||
|
private double damage;
|
||||||
|
|
||||||
|
public EntityBullet(BdfObject bdf) {
|
||||||
|
BdfClassLoad(bdf);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void BdfClassLoad(BdfObject bdf) {
|
||||||
|
super.BdfClassLoad(bdf);
|
||||||
|
|
||||||
|
BdfNamedList nl = bdf.getNamedList();
|
||||||
|
time = nl.get("time").getInteger();
|
||||||
|
damage = nl.get("damage").getDouble();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void BdfClassSave(BdfObject bdf) {
|
||||||
|
super.BdfClassSave(bdf);
|
||||||
|
|
||||||
|
BdfNamedList nl = bdf.getNamedList();
|
||||||
|
nl.set("time", bdf.newObject().setInteger(time));
|
||||||
|
nl.set("damage", bdf.newObject().setDouble(damage));
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityBullet(Vec3d pos, Vec3d velocity, Entity parent, double damage, int despawn_time) {
|
||||||
|
super(pos, velocity);
|
||||||
|
|
||||||
|
// Store some specified values
|
||||||
|
this.parent = parent;
|
||||||
|
this.damage = damage;
|
||||||
|
this.time = despawn_time;
|
||||||
|
this.hasGravity = false;
|
||||||
|
|
||||||
|
// Play the gun sound
|
||||||
|
Sounds.GUN.play(pos, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void tick(Chunk chunk, Layer layer) {
|
||||||
|
super.tick(chunk, layer);
|
||||||
|
|
||||||
|
chunk = layer.getChunk(getPos().xz());
|
||||||
|
|
||||||
|
// Is the bullets new position intersecting a solid object
|
||||||
|
{
|
||||||
|
// Get the position of the tile the bullet is over
|
||||||
|
Vec2i tpos = getPos().xz().toInt();
|
||||||
|
|
||||||
|
// Get the foreground tile and the background tile
|
||||||
|
Tile tile_f = chunk.getFrontTile(tpos).tile;
|
||||||
|
Tile tile_b = chunk.getBackTile(tpos).tile;
|
||||||
|
|
||||||
|
// Is the tile solid and has the bullet crashed into it
|
||||||
|
if(tile_f.tileSolid) {
|
||||||
|
if(getPos().xz().squareDistance(new Vec2d(tpos.x + 0.5, tpos.y + 0.5)) < tile_f.tileHitbox)
|
||||||
|
{
|
||||||
|
// Break the block
|
||||||
|
if(tile_f instanceof TileBulletBreakable && RandomHelpers.randrange(rand,
|
||||||
|
((TileBulletBreakable)tile_f).getBulletBreakChance()) == 0) {
|
||||||
|
chunk.breakFrontTile(tpos);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete the bullet
|
||||||
|
kill();
|
||||||
|
}
|
||||||
|
} if(tile_b.tileSolid) {
|
||||||
|
if(getPos().xz().squareDistance(new Vec2d(tpos.x + 0.5, tpos.y + 0.5)) < tile_b.tileHitbox)
|
||||||
|
{
|
||||||
|
// Break the block
|
||||||
|
if(tile_f instanceof TileBulletBreakable && RandomHelpers.randrange(rand,
|
||||||
|
((TileBulletBreakable)tile_f).getBulletBreakChance()) == 0) {
|
||||||
|
chunk.breakBackTile(tpos);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete the bullet
|
||||||
|
kill();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Loop over the nearby entities
|
||||||
|
for(Entity e : layer.getNearbyEntities(getPos().xz(), 1))
|
||||||
|
{
|
||||||
|
// Is this entity alive and not the parent
|
||||||
|
if(e instanceof EntityAlive && e != parent && e.getPos().squareDistance(this.getPos()) < e.hitbox)
|
||||||
|
{
|
||||||
|
// Get the alive entity
|
||||||
|
EntityAlive ea = (EntityAlive)e;
|
||||||
|
|
||||||
|
// Spawn some blood particles
|
||||||
|
chunk.spawnEntity(new ParticleBlood(getPos(), e.getVelocity().add(getVelocity()).divide(8)));
|
||||||
|
|
||||||
|
// Knock the entity back abit
|
||||||
|
e.push(getVelocity());
|
||||||
|
|
||||||
|
Vec3d pos = getPos();
|
||||||
|
|
||||||
|
// Play the hit noise
|
||||||
|
Sounds.HIT.play(new Vec3d(pos.x, pos.y, pos.z), 1);
|
||||||
|
|
||||||
|
// Harm the entity
|
||||||
|
ea.addDamage(damage);
|
||||||
|
|
||||||
|
// Kill the bullet
|
||||||
|
chunk.killEntity(this);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Decrease time
|
||||||
|
time -= 1;
|
||||||
|
|
||||||
|
if(time <= 0) {
|
||||||
|
chunk.killEntity(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getParticleCount() {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean shouldKillParticle() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EntityParticlePart getParticleAt(int id) {
|
||||||
|
return new EntityParticlePart(BULLET, getPos(), 0.1, 0b1000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,98 @@
|
||||||
|
package projectzombie.entity;
|
||||||
|
|
||||||
|
import bdf.types.BdfArray;
|
||||||
|
import bdf.types.BdfNamedList;
|
||||||
|
import bdf.types.BdfObject;
|
||||||
|
import gl_engine.vec.Vec3d;
|
||||||
|
import projectzombie.init.Models;
|
||||||
|
import projectzombie.model.Model;
|
||||||
|
import projectzombie.world.chunk.Chunk;
|
||||||
|
import projectzombie.world.layer.Layer;
|
||||||
|
|
||||||
|
public class EntityContainer extends Entity implements EntityHoldsEntities
|
||||||
|
{
|
||||||
|
private Entity[] entities;
|
||||||
|
|
||||||
|
public EntityContainer(BdfObject bdf) {
|
||||||
|
BdfClassLoad(bdf);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityContainer(Vec3d pos, Vec3d velocity, Entity[] entities) {
|
||||||
|
super(pos, velocity);
|
||||||
|
|
||||||
|
this.entities = entities;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Model getModel() {
|
||||||
|
return Models.EMPTY;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Entity[] getEntities() {
|
||||||
|
return this.entities;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void tick(Chunk chunk, Layer layer) {
|
||||||
|
super.tick(chunk, layer);
|
||||||
|
|
||||||
|
int dead = 0;
|
||||||
|
|
||||||
|
for(Entity entity : entities)
|
||||||
|
{
|
||||||
|
if(entity == null || entity.isDead()) {
|
||||||
|
dead += 1;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
entity.tick(chunk, layer);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(dead == entities.length - 1) {
|
||||||
|
kill();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void BdfClassLoad(BdfObject bdf) {
|
||||||
|
super.BdfClassLoad(bdf);
|
||||||
|
|
||||||
|
BdfNamedList nl = bdf.getNamedList();
|
||||||
|
BdfArray array = nl.get("entities").getArray();
|
||||||
|
|
||||||
|
entities = new Entity[array.size()];
|
||||||
|
|
||||||
|
for(int i=0;i<entities.length;i++)
|
||||||
|
{
|
||||||
|
Entity entity = Entity.loadEntity(array.get(i));
|
||||||
|
if(entity != null) {
|
||||||
|
entities[i] = entity;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void BdfClassSave(BdfObject bdf) {
|
||||||
|
super.BdfClassSave(bdf);
|
||||||
|
|
||||||
|
BdfNamedList nl = bdf.getNamedList();
|
||||||
|
BdfArray array = bdf.newArray();
|
||||||
|
|
||||||
|
nl.set("entities", bdf.newObject().setArray(array));
|
||||||
|
|
||||||
|
for(int i=0;i<entities.length;i++)
|
||||||
|
{
|
||||||
|
Entity e = entities[i];
|
||||||
|
|
||||||
|
if(e == null || e.getID() == -1) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
BdfObject e_bdf = bdf.newObject();
|
||||||
|
e.BdfClassSave(e_bdf);
|
||||||
|
|
||||||
|
array.add(e_bdf);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,78 @@
|
||||||
|
package projectzombie.entity;
|
||||||
|
|
||||||
|
import bdf.types.BdfObject;
|
||||||
|
import gl_engine.vec.Vec3d;
|
||||||
|
import projectzombie.init.Models;
|
||||||
|
import projectzombie.model.Model;
|
||||||
|
|
||||||
|
public class EntityDummy extends Entity implements EntityAlive
|
||||||
|
{
|
||||||
|
public EntityDummy(BdfObject bdf) {
|
||||||
|
BdfClassLoad(bdf);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityDummy(Vec3d pos, Vec3d velocity) {
|
||||||
|
super(pos, velocity);
|
||||||
|
|
||||||
|
this.hitbox = 0.5;
|
||||||
|
this.isSolid = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addHealth(double amount) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addDamage(double amount) {
|
||||||
|
int l = 4;
|
||||||
|
amount = amount / (l / 2.5 + 1);
|
||||||
|
System.out.println("Dummy Damage Aount: "+amount);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addFireDamage(double amount) {
|
||||||
|
int l = 4;
|
||||||
|
amount = amount / (l / 2.5 + 1);
|
||||||
|
System.out.println("Dummy Fire Damage Aount: "+amount);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addBlastDamage(double amount) {
|
||||||
|
int l = 4;
|
||||||
|
amount = amount / (l / 2.5 + 1);
|
||||||
|
System.out.println("Dummy Blast Damage Aount: "+amount);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double getHealth() {
|
||||||
|
return 100;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void resetHealth() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void clearHealth() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double maxHealth() {
|
||||||
|
return 100;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setHealth(double health) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int bloodParticles() {
|
||||||
|
return 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Model getModel() {
|
||||||
|
return Models.ENTITY_DUMMY;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
24
src/shootergame/entity/EntityEventHandler.java → src/projectzombie/entity/EntityEventHandler.java
Normal file → Executable file
24
src/shootergame/entity/EntityEventHandler.java → src/projectzombie/entity/EntityEventHandler.java
Normal file → Executable file
|
|
@ -1,26 +1,16 @@
|
||||||
package shootergame.entity;
|
package projectzombie.entity;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
import mainloop.task.IMainloopTask;
|
import mainloop.task.IMainloopTask;
|
||||||
import shootergame.Main;
|
import projectzombie.Main;
|
||||||
import shootergame.init.Entities;
|
import projectzombie.world.chunk.ChunkEventHandler;
|
||||||
import shootergame.mainloop.MainloopEventHandler;
|
|
||||||
import shootergame.util.math.map.Map2DElement;
|
|
||||||
import shootergame.util.math.random.RandomHelpers;
|
|
||||||
import shootergame.world.chunk.Chunk;
|
|
||||||
import shootergame.world.layer.Layer;
|
|
||||||
|
|
||||||
public class EntityEventHandler implements IMainloopTask
|
public class EntityEventHandler implements IMainloopTask
|
||||||
{
|
{
|
||||||
public static final EntityEventHandler ENTITY_EVENT_HANDLER = new EntityEventHandler();
|
public static final EntityEventHandler ENTITY_EVENT_HANDLER = new EntityEventHandler();
|
||||||
|
|
||||||
private Random rand = new Random();
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean MainLoopDelay(long millis) {
|
public boolean MainLoopDelay(long millis) {
|
||||||
return millis > 10;
|
return millis > Main.tickrate;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -31,6 +21,12 @@ public class EntityEventHandler implements IMainloopTask
|
||||||
@Override
|
@Override
|
||||||
public void MainLoopUpdate()
|
public void MainLoopUpdate()
|
||||||
{
|
{
|
||||||
|
Main.menu.update();
|
||||||
|
|
||||||
|
if(!Main.menu.doGameloop || !ChunkEventHandler.loaded) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Update the world and spawn random entities
|
// Update the world and spawn random entities
|
||||||
Main.world.tickEntities();
|
Main.world.tickEntities();
|
||||||
Main.world.spawnRandomEntities();
|
Main.world.spawnRandomEntities();
|
||||||
|
|
@ -0,0 +1,162 @@
|
||||||
|
package projectzombie.entity;
|
||||||
|
|
||||||
|
import bdf.types.BdfNamedList;
|
||||||
|
import bdf.types.BdfObject;
|
||||||
|
import gl_engine.MathHelpers;
|
||||||
|
import gl_engine.vec.Vec2d;
|
||||||
|
import gl_engine.vec.Vec2i;
|
||||||
|
import gl_engine.vec.Vec3d;
|
||||||
|
import projectzombie.Main;
|
||||||
|
import projectzombie.entity.particle.ParticleBlood;
|
||||||
|
import projectzombie.entity.particle.ParticleSmoke;
|
||||||
|
import projectzombie.init.Models;
|
||||||
|
import projectzombie.init.Sounds;
|
||||||
|
import projectzombie.init.Tiles;
|
||||||
|
import projectzombie.model.Model;
|
||||||
|
import projectzombie.util.TileState;
|
||||||
|
import projectzombie.world.chunk.Chunk;
|
||||||
|
import projectzombie.world.layer.Layer;
|
||||||
|
|
||||||
|
public class EntityExplosion extends Entity
|
||||||
|
{
|
||||||
|
private double damage;
|
||||||
|
private int radius;
|
||||||
|
|
||||||
|
public EntityExplosion(BdfObject bdf) {
|
||||||
|
BdfClassLoad(bdf);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityExplosion(Vec3d pos, int radius, double damage) {
|
||||||
|
super(pos, new Vec3d(0, 0, 0));
|
||||||
|
this.damage = damage;
|
||||||
|
this.radius = radius;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void BdfClassLoad(BdfObject bdf) {
|
||||||
|
super.BdfClassLoad(bdf);
|
||||||
|
|
||||||
|
BdfNamedList nl = bdf.getNamedList();
|
||||||
|
damage = nl.get("damage").getDouble();
|
||||||
|
radius = nl.get("radius").getInteger();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void BdfClassSave(BdfObject bdf) {
|
||||||
|
super.BdfClassSave(bdf);
|
||||||
|
|
||||||
|
BdfNamedList nl = bdf.getNamedList();
|
||||||
|
nl.set("damage", bdf.newObject().setDouble(damage));
|
||||||
|
nl.set("radius", bdf.newObject().setInteger(radius));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void tick(Chunk chunk, Layer layer) {
|
||||||
|
super.tick(chunk, layer);
|
||||||
|
|
||||||
|
boolean killed_entities = false;
|
||||||
|
Vec2d pos = getPos().xz();
|
||||||
|
|
||||||
|
// Kill all the nearby entities
|
||||||
|
for(Entity e : layer.getNearbyEntities(pos, radius))
|
||||||
|
{
|
||||||
|
// Is this entity alive
|
||||||
|
if(e instanceof EntityAlive)
|
||||||
|
{
|
||||||
|
EntityAlive ea = (EntityAlive)e;
|
||||||
|
|
||||||
|
// Remove some health from the entity based on were the entity is
|
||||||
|
killed_entities = true;
|
||||||
|
double distance = e.getPos().distance(getPos());
|
||||||
|
|
||||||
|
if(distance == 0) {
|
||||||
|
ea.addBlastDamage(damage);
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
ea.addBlastDamage(damage / distance);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int multiplier = killed_entities ? 2 : 1;
|
||||||
|
Entity[] entities = new Entity[(int)(Math.PI * radius * radius) * multiplier];
|
||||||
|
int upto = 0;
|
||||||
|
|
||||||
|
// Loop over the tiles around the tnt
|
||||||
|
for(int ex=-radius;ex<radius;ex++) {
|
||||||
|
for(int ey=-radius;ey<radius;ey++)
|
||||||
|
{
|
||||||
|
// Calculate the distance from the explosion centre
|
||||||
|
double distance = Math.sqrt(ex*ex + ey*ey);
|
||||||
|
|
||||||
|
// Is the point within the distance from the explosion centre
|
||||||
|
if(distance < radius)
|
||||||
|
{
|
||||||
|
// Get the actual tile position
|
||||||
|
double px = ex + pos.x;
|
||||||
|
double py = ey + pos.y;
|
||||||
|
|
||||||
|
// Get the layer
|
||||||
|
Layer l = Main.world.getLayer();
|
||||||
|
|
||||||
|
// Get the front and back tile
|
||||||
|
Vec2i tpos = new Vec2i(MathHelpers.floor(px), MathHelpers.floor(py));
|
||||||
|
TileState bts = l.getBackTile(tpos);
|
||||||
|
TileState fts = l.getFrontTile(tpos);
|
||||||
|
|
||||||
|
// Is this tile the same as the "empty" tile
|
||||||
|
TileState ets = l.layergen.getTileDestroyed(layer, tpos);
|
||||||
|
|
||||||
|
// Set the tiles
|
||||||
|
if(!bts.tile.unbreakable) {
|
||||||
|
l.setBackTile(ets, tpos);
|
||||||
|
//if(fts.tile instanceof IHasTexture)
|
||||||
|
//l.spawnEntity(new ParticleBreak(new Vec2d(tpos.x+rand.nextDouble(), tpos.y+rand.nextDouble()), bts, 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!fts.tile.unbreakable) {
|
||||||
|
l.setFrontTile(Tiles.VOID.getDefaultState(), tpos);
|
||||||
|
//if(fts.tile instanceof IHasTexture)
|
||||||
|
//l.spawnEntity(new ParticleBreak(new Vec2d(tpos.x+rand.nextDouble(), tpos.y+rand.nextDouble()), fts, 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
if(upto + multiplier > entities.length) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vec3d spos = new Vec3d(px, 0, py);
|
||||||
|
Vec3d svel;
|
||||||
|
|
||||||
|
if(distance == 0) {
|
||||||
|
svel = MathHelpers.moveTowards2(0.01, Math.random() * MathHelpers.TWO_PI).xny();
|
||||||
|
} else {
|
||||||
|
svel = spos.xz().subtract(pos).divide(distance * 100).xny();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Spawn some blood if entities were killed
|
||||||
|
if(killed_entities)
|
||||||
|
entities[upto + 1] = new ParticleBlood(new Vec3d(px, 0, py), new Vec3d(0, 0, 0), 1);
|
||||||
|
|
||||||
|
// Spawn some smoke
|
||||||
|
entities[upto] = new ParticleSmoke(spos, svel);
|
||||||
|
|
||||||
|
upto += multiplier;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
layer.spawnEntity(new EntityContainer(getPos(), getVelocity(), entities));
|
||||||
|
|
||||||
|
// Play the explosion sound
|
||||||
|
Sounds.EXPLOSION.play(new Vec3d(pos.x, 0, pos.y), 1);
|
||||||
|
|
||||||
|
// Kill the explosion entity
|
||||||
|
kill();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Model getModel() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,36 @@
|
||||||
|
package projectzombie.entity;
|
||||||
|
|
||||||
|
import bdf.types.BdfObject;
|
||||||
|
import gl_engine.vec.Vec3d;
|
||||||
|
import projectzombie.init.Models;
|
||||||
|
import projectzombie.model.Model;
|
||||||
|
import projectzombie.world.layer.Layer;
|
||||||
|
|
||||||
|
public class EntityFlare extends EntityTnt
|
||||||
|
{
|
||||||
|
public EntityFlare(BdfObject bdf) {
|
||||||
|
super(bdf);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void explode(Layer layer) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityFlare(Vec3d pos, Vec3d velocity, double angle) {
|
||||||
|
super(pos, velocity, angle, 0, 0);
|
||||||
|
|
||||||
|
this.explode_time = 2000;
|
||||||
|
this.emitsLight = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double getLightLevel() {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Model getModel() {
|
||||||
|
return active ? Models.ENTITY_FLARE : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,108 @@
|
||||||
|
package projectzombie.entity;
|
||||||
|
|
||||||
|
import bdf.types.BdfNamedList;
|
||||||
|
import bdf.types.BdfObject;
|
||||||
|
import gl_engine.vec.Vec3d;
|
||||||
|
import projectzombie.Main;
|
||||||
|
import projectzombie.entity.player.EntityPlayer;
|
||||||
|
import projectzombie.init.Models;
|
||||||
|
import projectzombie.model.Model;
|
||||||
|
import projectzombie.world.chunk.Chunk;
|
||||||
|
import projectzombie.world.layer.Layer;
|
||||||
|
import projectzombie.world.layer.layergen.LayerGenRememberPlayerPos;
|
||||||
|
|
||||||
|
public class EntityGrapplingHook extends Entity
|
||||||
|
{
|
||||||
|
private int layerId;
|
||||||
|
private double height;
|
||||||
|
private Entity entity;
|
||||||
|
|
||||||
|
public EntityGrapplingHook(BdfObject bdf) {
|
||||||
|
BdfClassLoad(bdf);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void BdfClassLoad(BdfObject bdf) {
|
||||||
|
super.BdfClassLoad(bdf);
|
||||||
|
|
||||||
|
BdfNamedList nl = bdf.getNamedList();
|
||||||
|
layerId = nl.get("layer").getInteger();
|
||||||
|
height = nl.get("height").getDouble();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void BdfClassSave(BdfObject bdf) {
|
||||||
|
super.BdfClassSave(bdf);
|
||||||
|
|
||||||
|
BdfNamedList nl = bdf.getNamedList();
|
||||||
|
nl.set("layer", bdf.newObject().setInteger(layerId));
|
||||||
|
nl.set("height", bdf.newObject().setDouble(height));
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityGrapplingHook(Vec3d pos, int layerId, Entity entity) {
|
||||||
|
super(pos, new Vec3d(0, 0, 0));
|
||||||
|
|
||||||
|
this.layerId = layerId;
|
||||||
|
this.height = -16;
|
||||||
|
this.entity = entity;
|
||||||
|
|
||||||
|
if(entity instanceof EntityPlayer) {
|
||||||
|
EntityPlayer ep = (EntityPlayer)entity;
|
||||||
|
ep.in_animation = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void tick(Chunk chunk, Layer layer) {
|
||||||
|
super.tick(chunk, layer);
|
||||||
|
|
||||||
|
if(height >= -8)
|
||||||
|
{
|
||||||
|
Vec3d epos = entity.getPos();
|
||||||
|
|
||||||
|
double h = epos.y;
|
||||||
|
epos.y += 0.02;
|
||||||
|
|
||||||
|
if(entity instanceof EntityPlayer) {
|
||||||
|
EntityPlayer ep = (EntityPlayer)entity;
|
||||||
|
ep.moving = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(h >= 8)
|
||||||
|
{
|
||||||
|
epos.y = 0;
|
||||||
|
Main.world.setLayer(layerId);
|
||||||
|
|
||||||
|
if(layer.layergen.destroyOnLeave) {
|
||||||
|
Main.world.removeLayer(layerId);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(entity instanceof EntityPlayer)
|
||||||
|
{
|
||||||
|
EntityPlayer ep = (EntityPlayer)entity;
|
||||||
|
ep.in_animation = false;
|
||||||
|
ep.moving = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if(layer.layergen instanceof LayerGenRememberPlayerPos) {
|
||||||
|
LayerGenRememberPlayerPos lgrpp = (LayerGenRememberPlayerPos)layer.layergen;
|
||||||
|
entity.setPos(lgrpp.getPlayerPos());
|
||||||
|
}
|
||||||
|
|
||||||
|
kill();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
height += 0.05;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Model getModel() {
|
||||||
|
return Models.ENTITY_GRAPPLING_HOOK;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
package projectzombie.entity;
|
||||||
|
|
||||||
|
import projectzombie.inventory.IInventoryArmor;
|
||||||
|
|
||||||
|
public interface EntityHasArmor {
|
||||||
|
public IInventoryArmor getInventoryArmor();
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
package projectzombie.entity;
|
||||||
|
|
||||||
|
import projectzombie.inventory.IInventoryClothing;
|
||||||
|
|
||||||
|
public interface EntityHasClothing {
|
||||||
|
public IInventoryClothing getInventoryClothing();
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
package projectzombie.entity;
|
||||||
|
|
||||||
|
import projectzombie.inventory.IInventory;
|
||||||
|
|
||||||
|
public interface EntityHasInventory
|
||||||
|
{
|
||||||
|
public IInventory getInventory();
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
package projectzombie.entity;
|
||||||
|
|
||||||
|
import projectzombie.task.Task;
|
||||||
|
|
||||||
|
public interface EntityHasTasks
|
||||||
|
{
|
||||||
|
public void addTask(Task task);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
package projectzombie.entity;
|
||||||
|
|
||||||
|
public interface EntityHoldsEntities
|
||||||
|
{
|
||||||
|
public Entity[] getEntities();
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,134 @@
|
||||||
|
package projectzombie.entity;
|
||||||
|
|
||||||
|
import bdf.types.BdfNamedList;
|
||||||
|
import bdf.types.BdfObject;
|
||||||
|
import gl_engine.MathHelpers;
|
||||||
|
import gl_engine.vec.Vec3d;
|
||||||
|
import projectzombie.model.ModelItem;
|
||||||
|
import projectzombie.util.ItemStack;
|
||||||
|
import projectzombie.world.chunk.Chunk;
|
||||||
|
import projectzombie.world.layer.Layer;
|
||||||
|
|
||||||
|
public class EntityItem extends EntityParticle
|
||||||
|
{
|
||||||
|
private ItemStack stack;
|
||||||
|
private int pickup_time = 200;
|
||||||
|
private long age = 0;
|
||||||
|
|
||||||
|
public EntityItem(BdfObject bdf) {
|
||||||
|
BdfClassLoad(bdf);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void BdfClassLoad(BdfObject bdf) {
|
||||||
|
super.BdfClassLoad(bdf);
|
||||||
|
|
||||||
|
BdfNamedList nl = bdf.getNamedList();
|
||||||
|
|
||||||
|
stack = new ItemStack(nl.get("stack"));
|
||||||
|
|
||||||
|
pickup_time = nl.get("pickup").getInteger();
|
||||||
|
age = nl.get("age").getLong();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void BdfClassSave(BdfObject bdf) {
|
||||||
|
super.BdfClassSave(bdf);
|
||||||
|
|
||||||
|
BdfNamedList nl = bdf.getNamedList();
|
||||||
|
|
||||||
|
stack.BdfClassSave(nl.get("stack"));
|
||||||
|
|
||||||
|
nl.set("pickup", bdf.newObject().setInteger(pickup_time));
|
||||||
|
nl.set("age", bdf.newObject().setLong(age));
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityItem(Vec3d pos, Vec3d velocity, ItemStack stack, double angle) {
|
||||||
|
super(pos, velocity);
|
||||||
|
|
||||||
|
this.emitsLight = true;
|
||||||
|
this.stack = stack;
|
||||||
|
|
||||||
|
push(MathHelpers.moveTowards2(0.05, angle).xny().add(new Vec3d(0, 0.1, 0)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityItem(Vec3d pos, Vec3d velocity, ItemStack stack) {
|
||||||
|
this(pos, velocity, stack, rand.nextDouble() * MathHelpers.TWO_PI);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double getLightLevel() {
|
||||||
|
if(stack.isEmpty()) return 0;
|
||||||
|
return getLightWithHeight(stack.item.getLightLevel(stack));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void tick(Chunk chunk, Layer layer) {
|
||||||
|
super.tick(chunk, layer);
|
||||||
|
|
||||||
|
age += 1;
|
||||||
|
pickup_time -= 1;
|
||||||
|
|
||||||
|
// Merge nearby stacks
|
||||||
|
for(Entity e : layer.getNearbyEntities(getPos().xz(), 2))
|
||||||
|
{
|
||||||
|
if(e instanceof EntityItem && e != this) {
|
||||||
|
EntityItem ei = (EntityItem) e;
|
||||||
|
|
||||||
|
if(
|
||||||
|
ei.stack.stackEquals(this.stack) &&
|
||||||
|
ei.stack.count + this.stack.count <= this.stack.item.max &&
|
||||||
|
ei.age > this.age
|
||||||
|
) {
|
||||||
|
if(ei.getPos().squareDistance(getPos()) < 0.1) {
|
||||||
|
this.pickup_time = 200;
|
||||||
|
this.stack.count += ei.stack.count;
|
||||||
|
setPos(ei.getPos().divide(2).add(getPos().divide(2)));
|
||||||
|
setVelocity(ei.getVelocity().divide(2).add(getVelocity().divide(2)));
|
||||||
|
ei.kill();
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
push(ei.getPos().subtract(getPos()).normalize().multiply(0.001));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(pickup_time <= 0 && e instanceof EntityHasInventory)
|
||||||
|
{
|
||||||
|
if(e.getPos().squareDistance(getPos()) < 0.5) {
|
||||||
|
stack.item.onPickedUp(stack, layer, chunk, e);
|
||||||
|
} else {
|
||||||
|
push(e.getPos().subtract(getPos()).normalize().multiply(0.05));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Kill this entity if the stack is empty
|
||||||
|
if(stack.isEmpty()) {
|
||||||
|
kill();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean shouldKillParticle() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EntityParticlePart getParticleAt(int id) {
|
||||||
|
ModelItem model = stack.item.getModel(stack);
|
||||||
|
EntityParticlePart particle = new EntityParticlePart(model.tex, getPos().add(new Vec3d(0, 0.25, 0)), 0.5, 0b1000);
|
||||||
|
particle.animationSize = model.animationSize;
|
||||||
|
particle.animationSpeed = model.animationSpeed;
|
||||||
|
return particle;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getParticleCount() {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
package projectzombie.entity;
|
||||||
|
|
||||||
|
public interface EntityKillWithParticles
|
||||||
|
{
|
||||||
|
public void killWithParticles();
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,38 @@
|
||||||
|
package projectzombie.entity;
|
||||||
|
|
||||||
|
import bdf.types.BdfObject;
|
||||||
|
import gl_engine.vec.Vec3d;
|
||||||
|
import projectzombie.Main;
|
||||||
|
import projectzombie.model.IModel;
|
||||||
|
import projectzombie.world.chunk.Chunk;
|
||||||
|
import projectzombie.world.layer.Layer;
|
||||||
|
|
||||||
|
public abstract class EntityParticle extends Entity
|
||||||
|
{
|
||||||
|
public abstract int getParticleCount();
|
||||||
|
public abstract EntityParticlePart getParticleAt(int id);
|
||||||
|
|
||||||
|
protected EntityParticle() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityParticle(Vec3d pos, Vec3d velocity) {
|
||||||
|
super(pos, velocity);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void tick(Chunk chunk, Layer layer) {
|
||||||
|
super.tick(chunk, layer);
|
||||||
|
|
||||||
|
// Kill the particle if the player can't see it to reduce lag
|
||||||
|
if(shouldKillParticle()) this.kill();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean shouldKillParticle() {
|
||||||
|
return Main.player.getPos().squareDistance(getPos()) > Chunk.RENDER_DISTANCE * 16;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IModel getModel() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,29 @@
|
||||||
|
package projectzombie.entity;
|
||||||
|
|
||||||
|
import gl_engine.texture.TextureRef3D;
|
||||||
|
import gl_engine.vec.Vec3d;
|
||||||
|
|
||||||
|
public class EntityParticlePart
|
||||||
|
{
|
||||||
|
public int animationSize = 1;
|
||||||
|
public int animationSpeed = 1;
|
||||||
|
public TextureRef3D tex;
|
||||||
|
public double size;
|
||||||
|
public Vec3d pos;
|
||||||
|
public int flags;
|
||||||
|
|
||||||
|
public double getFade() {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isFlat() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityParticlePart(TextureRef3D tex, Vec3d pos, double size, int flags) {
|
||||||
|
this.tex = tex;
|
||||||
|
this.pos = pos;
|
||||||
|
this.size = size;
|
||||||
|
this.flags = flags;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,105 @@
|
||||||
|
package projectzombie.entity;
|
||||||
|
|
||||||
|
import bdf.types.BdfNamedList;
|
||||||
|
import bdf.types.BdfObject;
|
||||||
|
import gl_engine.MathHelpers;
|
||||||
|
import gl_engine.vec.Vec2d;
|
||||||
|
import gl_engine.vec.Vec3d;
|
||||||
|
import projectzombie.entity.particle.ParticleSmokeTrail;
|
||||||
|
import projectzombie.init.Models;
|
||||||
|
import projectzombie.model.Model;
|
||||||
|
import projectzombie.world.chunk.Chunk;
|
||||||
|
import projectzombie.world.layer.Layer;
|
||||||
|
|
||||||
|
public class EntityTnt extends Entity implements EntityHoldsEntities
|
||||||
|
{
|
||||||
|
protected boolean active = true;
|
||||||
|
protected int explode_time;
|
||||||
|
private int explode_radius;
|
||||||
|
private double explode_damage;
|
||||||
|
private ParticleSmokeTrail smoke_particles;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Entity[] getEntities() {
|
||||||
|
return new Entity[] {smoke_particles};
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityTnt(BdfObject bdf) {
|
||||||
|
smoke_particles = new ParticleSmokeTrail(this);
|
||||||
|
BdfClassLoad(bdf);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void BdfClassLoad(BdfObject bdf) {
|
||||||
|
super.BdfClassLoad(bdf);
|
||||||
|
|
||||||
|
BdfNamedList nl = bdf.getNamedList();
|
||||||
|
BdfNamedList explode = nl.get("explosion").getNamedList();
|
||||||
|
explode_time = explode.get("time").getInteger();
|
||||||
|
explode_radius = explode.get("radius").getInteger();
|
||||||
|
explode_damage = explode.get("damage").getDouble();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void BdfClassSave(BdfObject bdf) {
|
||||||
|
super.BdfClassSave(bdf);
|
||||||
|
|
||||||
|
BdfNamedList nl = bdf.getNamedList();
|
||||||
|
BdfNamedList explode = nl.get("explosion").getNamedList();
|
||||||
|
explode.set("time", bdf.newObject().setInteger(explode_time));
|
||||||
|
explode.set("radius", bdf.newObject().setInteger(explode_radius));
|
||||||
|
explode.set("damage", bdf.newObject().setDouble(explode_damage));
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityTnt(Vec3d pos, Vec3d velocity, double angle, int explode_radius, double explode_damage) {
|
||||||
|
super(pos, velocity.add(new Vec3d(0, 0.1, 0)));
|
||||||
|
|
||||||
|
Vec2d v = MathHelpers.moveTowards2(0.05, Math.toRadians(angle));
|
||||||
|
velocity = velocity.add(new Vec3d(v.x, v.y, 0.01));
|
||||||
|
this.explode_radius = explode_radius;
|
||||||
|
this.explode_damage = explode_damage;
|
||||||
|
this.smoke_particles = new ParticleSmokeTrail(this);
|
||||||
|
|
||||||
|
// Set to 2.5 seconds
|
||||||
|
this.explode_time = 250;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void explode(Layer layer)
|
||||||
|
{
|
||||||
|
layer.spawnEntity(new EntityExplosion(getPos(), explode_radius, explode_damage));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void tick(Chunk chunk, Layer layer) {
|
||||||
|
super.tick(chunk, layer);
|
||||||
|
|
||||||
|
smoke_particles.tick(chunk, layer);
|
||||||
|
|
||||||
|
if(!active)
|
||||||
|
{
|
||||||
|
if(smoke_particles.noMoreParticles()) {
|
||||||
|
kill();
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Explode if it is time for the tnt to blow up
|
||||||
|
explode_time -= 1;
|
||||||
|
if(explode_time < 0) {
|
||||||
|
smoke_particles.stopParticles();
|
||||||
|
active = false;
|
||||||
|
explode(layer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void moveAwayFromSolidEntities(Layer layer) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Model getModel() {
|
||||||
|
return active ? Models.ENTITY_TNT : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,230 @@
|
||||||
|
package projectzombie.entity;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
import bdf.types.BdfNamedList;
|
||||||
|
import bdf.types.BdfObject;
|
||||||
|
import gl_engine.vec.Vec2i;
|
||||||
|
import gl_engine.vec.Vec3d;
|
||||||
|
import projectzombie.Main;
|
||||||
|
import projectzombie.init.Models;
|
||||||
|
import projectzombie.model.Model;
|
||||||
|
import projectzombie.util.math.astar.AStar;
|
||||||
|
import projectzombie.util.math.astar.AStarSearcher;
|
||||||
|
import projectzombie.util.math.random.OpenSimplexNoise;
|
||||||
|
import projectzombie.world.chunk.Chunk;
|
||||||
|
import projectzombie.world.layer.Layer;
|
||||||
|
|
||||||
|
public class EntityZombie extends Entity implements EntityAlive, EntityKillWithParticles
|
||||||
|
{
|
||||||
|
protected OpenSimplexNoise noise_movement;
|
||||||
|
protected OpenSimplexNoise noise_gun_fire;
|
||||||
|
protected OpenSimplexNoise noise_gun_angle;
|
||||||
|
protected OpenSimplexNoise noise_target_x;
|
||||||
|
protected OpenSimplexNoise noise_target_y;
|
||||||
|
|
||||||
|
protected long seed;
|
||||||
|
|
||||||
|
protected double time;
|
||||||
|
protected double health_max = 100;
|
||||||
|
protected double health = health_max;
|
||||||
|
protected int gun_interval = 0;
|
||||||
|
protected int gun_level = 0;
|
||||||
|
|
||||||
|
private Vec3d walk_to;
|
||||||
|
private int walk_scan_cooldown = 0;
|
||||||
|
private boolean can_see_player = false;
|
||||||
|
protected boolean crossUnwalkable = false;
|
||||||
|
private int walking_for = 0;
|
||||||
|
|
||||||
|
public EntityZombie(BdfObject bdf)
|
||||||
|
{
|
||||||
|
// Set some settings
|
||||||
|
hitbox = 0.5;
|
||||||
|
isSolid = true;
|
||||||
|
|
||||||
|
BdfClassLoad(bdf);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void BdfClassLoad(BdfObject bdf) {
|
||||||
|
super.BdfClassLoad(bdf);
|
||||||
|
|
||||||
|
BdfNamedList nl = bdf.getNamedList();
|
||||||
|
health_max = nl.get("max_health").getDouble();
|
||||||
|
health = nl.get("health").getDouble();
|
||||||
|
gun_interval = nl.get("gun_interval").getInteger();
|
||||||
|
gun_level = nl.get("gun_level").getInteger();
|
||||||
|
seed = nl.get("seed").getLong();
|
||||||
|
|
||||||
|
|
||||||
|
Random rand = new Random(seed);
|
||||||
|
|
||||||
|
noise_movement = new OpenSimplexNoise(rand.nextLong());
|
||||||
|
noise_gun_fire = new OpenSimplexNoise(rand.nextLong());
|
||||||
|
noise_gun_angle = new OpenSimplexNoise(rand.nextLong());
|
||||||
|
noise_target_x = new OpenSimplexNoise(rand.nextLong());
|
||||||
|
noise_target_y = new OpenSimplexNoise(rand.nextLong());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void BdfClassSave(BdfObject bdf) {
|
||||||
|
super.BdfClassSave(bdf);
|
||||||
|
|
||||||
|
BdfNamedList nl = bdf.getNamedList();
|
||||||
|
nl.set("max_health", bdf.newObject().setDouble(health_max));
|
||||||
|
nl.set("health", bdf.newObject().setDouble(health));
|
||||||
|
nl.set("gun_interval", bdf.newObject().setInteger(gun_interval));
|
||||||
|
nl.set("gun_level", bdf.newObject().setInteger(gun_level));
|
||||||
|
nl.set("seed", bdf.newObject().setLong(seed));
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityZombie(Vec3d pos, Vec3d velocity) {
|
||||||
|
super(pos, velocity);
|
||||||
|
|
||||||
|
seed = rand.nextLong();
|
||||||
|
Random rand = new Random(seed);
|
||||||
|
|
||||||
|
noise_movement = new OpenSimplexNoise(rand.nextLong());
|
||||||
|
noise_gun_fire = new OpenSimplexNoise(rand.nextLong());
|
||||||
|
noise_gun_angle = new OpenSimplexNoise(rand.nextLong());
|
||||||
|
noise_target_x = new OpenSimplexNoise(rand.nextLong());
|
||||||
|
noise_target_y = new OpenSimplexNoise(rand.nextLong());
|
||||||
|
time = 0;
|
||||||
|
|
||||||
|
// Set some settings
|
||||||
|
hitbox = 0.5;
|
||||||
|
isSolid = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void tick(Chunk chunk, Layer layer) {
|
||||||
|
super.tick(chunk, layer);
|
||||||
|
|
||||||
|
//System.out.println(walk_direction != null ? (walk_direction.x + ", " + walk_direction.y + ": " + pos.toInt().x + ", " + pos.toInt().y) : "null");
|
||||||
|
|
||||||
|
if(walk_to == null) {
|
||||||
|
walk_scan_cooldown -= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
double player_distance = getPos().squareDistance(Main.player.getPos());
|
||||||
|
|
||||||
|
// Only pathfind if in range of the player
|
||||||
|
if(player_distance < 16)
|
||||||
|
{
|
||||||
|
if(
|
||||||
|
(walk_to != null && getPos().toInt().equal(walk_to.toInt()) &&
|
||||||
|
player_distance > 2) || walk_scan_cooldown < 1 || walking_for > 200)
|
||||||
|
{
|
||||||
|
AStar astar = new AStar(getPos().xz().toInt(), 16, new AStarSearcher(layer));
|
||||||
|
Vec2i path[] = astar.getPath(Main.player.getPos().xz().toInt());
|
||||||
|
|
||||||
|
walk_scan_cooldown = 100;
|
||||||
|
walking_for = 0;
|
||||||
|
|
||||||
|
if(path != null && path.length > 1) {
|
||||||
|
walk_to = new Vec3d(path[0].x, 0, path[0].y);
|
||||||
|
} else {
|
||||||
|
walk_to = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
can_see_player = (path != null);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Walk towards the player
|
||||||
|
if(walk_to != null)
|
||||||
|
{
|
||||||
|
push(walk_to.subtract(getPos()).normalize().multiply(0.064));
|
||||||
|
|
||||||
|
walking_for += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(can_see_player && noise_gun_fire.eval(time, 0) > 0 && !Main.player.dead && !Main.player.in_animation)
|
||||||
|
{
|
||||||
|
gun_interval += 1;
|
||||||
|
gun_interval %= 10;
|
||||||
|
|
||||||
|
if(gun_interval == 0)
|
||||||
|
{
|
||||||
|
// Fire the gun
|
||||||
|
int d = (int)(1 + gun_level / 5.0);
|
||||||
|
Vec3d bullet_velocity = getVelocity().add(Main.player.getPos().subtract(getPos())).normalize().multiply(0.2);
|
||||||
|
Vec3d bullet_pos = getPos().add(new Vec3d(0, 0.4, 0));
|
||||||
|
Main.world.getLayer().spawnEntity(new EntityBullet(bullet_pos, bullet_velocity, this, 20*d*d, 60));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Despawn
|
||||||
|
if(player_distance > 128) {
|
||||||
|
kill();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Increase time
|
||||||
|
time += 0.001;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Model getModel() {
|
||||||
|
return Models.ENTITY_ZOMBIE_F;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addHealth(double amount) {
|
||||||
|
health += amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addDamage(double amount) {
|
||||||
|
health -= amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addBlastDamage(double amount) {
|
||||||
|
addDamage(amount);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addFireDamage(double amount) {
|
||||||
|
addDamage(amount);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double getHealth() {
|
||||||
|
return health;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void resetHealth() {
|
||||||
|
health = health_max;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void clearHealth() {
|
||||||
|
health = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double maxHealth() {
|
||||||
|
return health_max;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setHealth(double health) {
|
||||||
|
this.health = health;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int bloodParticles() {
|
||||||
|
return 12;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void killWithParticles() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,33 @@
|
||||||
|
package projectzombie.entity;
|
||||||
|
|
||||||
|
import bdf.types.BdfObject;
|
||||||
|
import gl_engine.vec.Vec3d;
|
||||||
|
import projectzombie.init.Models;
|
||||||
|
import projectzombie.model.Model;
|
||||||
|
|
||||||
|
public class EntityZombieArmored extends EntityZombie
|
||||||
|
{
|
||||||
|
public EntityZombieArmored(BdfObject bdf) {
|
||||||
|
super(bdf);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityZombieArmored(Vec3d pos, Vec3d velocity) {
|
||||||
|
super(pos, velocity);
|
||||||
|
this.health_max *= 5;
|
||||||
|
this.health = this.health_max;
|
||||||
|
this.gun_level = 3;
|
||||||
|
|
||||||
|
this.crossUnwalkable = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int bloodParticles() {
|
||||||
|
return 6;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Model getModel() {
|
||||||
|
return Models.ENTITY_ZOMBIE_F_ARMORED;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,21 @@
|
||||||
|
package projectzombie.entity.particle;
|
||||||
|
|
||||||
|
import gl_engine.vec.Vec3d;
|
||||||
|
import projectzombie.init.Models;
|
||||||
|
|
||||||
|
public class ParticleBlood extends ParticleBreak
|
||||||
|
{
|
||||||
|
public ParticleBlood(Vec3d pos, Vec3d velocity, int size) {
|
||||||
|
super(pos, velocity, Models.PARTICLE_BLOOD, size, 0.25);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ParticleBlood(Vec3d pos, Vec3d velocity) {
|
||||||
|
this(pos, velocity, 20);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double getParticleSize() {
|
||||||
|
return 0.05;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,184 @@
|
||||||
|
package projectzombie.entity.particle;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
import gl_engine.MathHelpers;
|
||||||
|
import gl_engine.texture.TextureRef3D;
|
||||||
|
import gl_engine.vec.Vec3d;
|
||||||
|
import projectzombie.Main;
|
||||||
|
import projectzombie.entity.EntityParticle;
|
||||||
|
import projectzombie.entity.EntityParticlePart;
|
||||||
|
import projectzombie.model.IModel;
|
||||||
|
import projectzombie.model.Model;
|
||||||
|
import projectzombie.world.chunk.Chunk;
|
||||||
|
import projectzombie.world.layer.Layer;
|
||||||
|
|
||||||
|
public class ParticleBreak extends EntityParticle
|
||||||
|
{
|
||||||
|
protected static final Random rand = new Random();
|
||||||
|
|
||||||
|
protected class Break extends EntityParticlePart
|
||||||
|
{
|
||||||
|
public Vec3d velocity;
|
||||||
|
public boolean moving;
|
||||||
|
|
||||||
|
public Break(TextureRef3D tex, Vec3d pos, Vec3d velocity, boolean moving, double size, int flags) {
|
||||||
|
super(tex, pos, size, flags);
|
||||||
|
|
||||||
|
this.velocity = velocity;
|
||||||
|
this.moving = moving;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isFlat() {
|
||||||
|
return isStill(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double getFade() {
|
||||||
|
return getParticleFade();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Break[] particles;
|
||||||
|
protected int still, time;
|
||||||
|
protected double still_ypos;
|
||||||
|
|
||||||
|
protected double getParticleFade() {
|
||||||
|
return time / 1000.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getParticleSize() {
|
||||||
|
return 0.1;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected double getParticleSpeed() {
|
||||||
|
return 0.01;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ParticleBreak(Vec3d pos, Vec3d velocity, IModel model) {
|
||||||
|
this(pos, velocity, model, 100, 0.05);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ParticleBreak(Vec3d pos, Vec3d velocity, IModel model, int count) {
|
||||||
|
this(pos, velocity, model, count, 0.05);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ParticleBreak(Vec3d pos, Vec3d velocity, IModel model, int count, double velocity_up_multiplier) {
|
||||||
|
super(new Vec3d(pos.x, 0, pos.z), new Vec3d(0, 0, 0));
|
||||||
|
|
||||||
|
if(pos.squareDistance(Main.player.getPos()) > 32) {
|
||||||
|
count = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.hasGravity = false;
|
||||||
|
|
||||||
|
double model_height = getHeight(model);
|
||||||
|
float[] verticies = model.getVerticies();
|
||||||
|
|
||||||
|
if(model_height > 1) {
|
||||||
|
count *= model_height;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(model.getSize() == 0) {
|
||||||
|
count = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
particles = new Break[count];
|
||||||
|
|
||||||
|
for(int i=0;i<particles.length;i++)
|
||||||
|
{
|
||||||
|
int[] tex_id = {0};
|
||||||
|
TextureRef3D ref = model.getRandomChunk(tex_id);
|
||||||
|
|
||||||
|
Break particle = new Break(ref,
|
||||||
|
pos.add(new Vec3d(0, rand.nextDouble() * model_height, 0)),
|
||||||
|
velocity.multiply(rand.nextDouble()).add(
|
||||||
|
MathHelpers.moveTowards2(getParticleSpeed(), rand.nextDouble() * MathHelpers.TWO_PI).xny().add(
|
||||||
|
new Vec3d(0, rand.nextDouble() * velocity_up_multiplier, 0))), true, getParticleSize(),
|
||||||
|
((int)verticies[tex_id[0] * Model.SIZE + Model.SIZE - 1] & 0b0110) | 0b1000);
|
||||||
|
|
||||||
|
particles[i] = particle;
|
||||||
|
}
|
||||||
|
|
||||||
|
still_ypos = 1/256.0;
|
||||||
|
time = 1000;
|
||||||
|
still = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected double getHeight(IModel model) {
|
||||||
|
return model.getHeight();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void onAllStill() {
|
||||||
|
if(time < 0) {
|
||||||
|
onAllDead();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void onAllDead() {
|
||||||
|
kill();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean isStill(Break particle) {
|
||||||
|
return particle.pos.y <= still_ypos;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void onStill(Break particle) {
|
||||||
|
particle.moving = false;
|
||||||
|
particle.pos.y = still_ypos;
|
||||||
|
particle.flags &= 0b0110;
|
||||||
|
still += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void tick(Chunk chunk, Layer layer) {
|
||||||
|
super.tick(chunk, layer);
|
||||||
|
|
||||||
|
if(isDead()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
time -= 1;
|
||||||
|
|
||||||
|
if(still == particles.length) {
|
||||||
|
onAllStill();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int i=0;i<particles.length;i++)
|
||||||
|
{
|
||||||
|
Break particle = particles[i];
|
||||||
|
|
||||||
|
if(!particle.moving) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(isStill(particle)) {
|
||||||
|
onStill(particle);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
particle.velocity.y -= MathHelpers.FallSpeed;
|
||||||
|
particle.pos = particle.pos.add(particle.velocity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IModel getModel() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getParticleCount() {
|
||||||
|
return particles.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EntityParticlePart getParticleAt(int id) {
|
||||||
|
return particles[id];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,24 @@
|
||||||
|
package projectzombie.entity.particle;
|
||||||
|
|
||||||
|
import gl_engine.vec.Vec3d;
|
||||||
|
import projectzombie.init.Models;
|
||||||
|
|
||||||
|
public class ParticleLava extends ParticleBreak
|
||||||
|
{
|
||||||
|
public ParticleLava(Vec3d pos, Vec3d velocity) {
|
||||||
|
this(pos, velocity, 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ParticleLava(Vec3d pos, Vec3d velocity, int count) {
|
||||||
|
super(pos, velocity, Models.TILE_LAVA, count, 0.1);
|
||||||
|
|
||||||
|
this.still_ypos = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean isStill(Break particle) {
|
||||||
|
return particle.pos.y <= -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,43 @@
|
||||||
|
package projectzombie.entity.particle;
|
||||||
|
|
||||||
|
import gl_engine.vec.Vec3d;
|
||||||
|
import projectzombie.entity.EntityParticle;
|
||||||
|
import projectzombie.entity.EntityParticlePart;
|
||||||
|
import projectzombie.init.Models;
|
||||||
|
import projectzombie.model.Model;
|
||||||
|
import projectzombie.util.math.random.RandomHelpers;
|
||||||
|
import projectzombie.world.chunk.Chunk;
|
||||||
|
import projectzombie.world.layer.Layer;
|
||||||
|
|
||||||
|
public class ParticleSmoke extends EntityParticle
|
||||||
|
{
|
||||||
|
private Model model;
|
||||||
|
|
||||||
|
public ParticleSmoke(Vec3d pos, Vec3d velocity) {
|
||||||
|
super(pos.add(new Vec3d(
|
||||||
|
RandomHelpers.randrange(rand, 1000)/1000.0 - 0.5, 0,
|
||||||
|
RandomHelpers.randrange(rand, 1000)/1000.0 - 0.5)),
|
||||||
|
velocity.add(new Vec3d(0, (rand.nextDouble() + 0.5) / 100, 0)));
|
||||||
|
|
||||||
|
hasGravity = false;
|
||||||
|
model = Models.PARTICLE_SMOKE_RANDOM.getModel();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void tick(Chunk chunk, Layer layer) {
|
||||||
|
super.tick(chunk, layer);
|
||||||
|
|
||||||
|
setVelocity(getVelocity().multiply(new Vec3d(0.995, 1, 0.995)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getParticleCount() {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EntityParticlePart getParticleAt(int id) {
|
||||||
|
return new EntityParticlePart(model.getTextures()[0], getPos(), 1, 0b1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,133 @@
|
||||||
|
package projectzombie.entity.particle;
|
||||||
|
|
||||||
|
import gl_engine.MathHelpers;
|
||||||
|
import gl_engine.texture.TextureRef3D;
|
||||||
|
import gl_engine.vec.Vec2d;
|
||||||
|
import gl_engine.vec.Vec3d;
|
||||||
|
import projectzombie.entity.Entity;
|
||||||
|
import projectzombie.entity.EntityParticle;
|
||||||
|
import projectzombie.entity.EntityParticlePart;
|
||||||
|
import projectzombie.init.Models;
|
||||||
|
import projectzombie.world.chunk.Chunk;
|
||||||
|
import projectzombie.world.layer.Layer;
|
||||||
|
|
||||||
|
public class ParticleSmokeTrail extends EntityParticle
|
||||||
|
{
|
||||||
|
protected class SmokeTrail extends EntityParticlePart
|
||||||
|
{
|
||||||
|
Vec3d velocity;
|
||||||
|
int time;
|
||||||
|
|
||||||
|
SmokeTrail(TextureRef3D tex, Vec3d pos, Vec3d velocity) {
|
||||||
|
super(tex, pos.add(new Vec3d(0, 0.5, 0)), 0, 0b1000);
|
||||||
|
|
||||||
|
time = 500;
|
||||||
|
|
||||||
|
this.velocity = velocity;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean isDead() {
|
||||||
|
return time <= 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void update()
|
||||||
|
{
|
||||||
|
if(time <= 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
time -= 1;
|
||||||
|
pos = pos.add(velocity);
|
||||||
|
size = time / 10000.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double getFade() {
|
||||||
|
return 0.5;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Entity parent;
|
||||||
|
private int dead;
|
||||||
|
|
||||||
|
private boolean generating_particles = true;
|
||||||
|
private SmokeTrail[] particles;
|
||||||
|
|
||||||
|
public ParticleSmokeTrail(Entity parent) {
|
||||||
|
this(parent, 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
private ParticleSmokeTrail(Entity parent, int size) {
|
||||||
|
super(parent.getPos(), new Vec3d(0, 0, 0));
|
||||||
|
|
||||||
|
dead = size;
|
||||||
|
particles = new SmokeTrail[size];
|
||||||
|
|
||||||
|
this.parent = parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void tick(Chunk chunk, Layer layer) {
|
||||||
|
super.tick(chunk, layer);
|
||||||
|
|
||||||
|
setPos(parent.getPos());
|
||||||
|
|
||||||
|
Vec3d wind = layer.layergen.getWind(layer, getPos().xz());
|
||||||
|
|
||||||
|
for(int i=0;i<particles.length;i++)
|
||||||
|
{
|
||||||
|
if(particles[i] == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(particles[i].isDead()) {
|
||||||
|
particles[i] = null;
|
||||||
|
dead += 1;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
particles[i].update();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!generating_particles) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int i=0;i<particles.length;i++) {
|
||||||
|
if(particles[i] == null)
|
||||||
|
{
|
||||||
|
int[] tex_id = {0};
|
||||||
|
TextureRef3D tex = Models.PARTICLE_SMOKE_TRAIL.getRandomChunk(tex_id);
|
||||||
|
|
||||||
|
particles[i] = new SmokeTrail(tex, parent.getPos().copy(),
|
||||||
|
parent.getVelocity().add(MathHelpers.moveTowards3(0.01, new Vec2d(
|
||||||
|
rand.nextDouble() * MathHelpers.TWO_PI,
|
||||||
|
rand.nextDouble() * MathHelpers.PI - MathHelpers.HALF_PI)))
|
||||||
|
.add(wind).multiply(0.5));
|
||||||
|
|
||||||
|
dead -= 1;
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void stopParticles() {
|
||||||
|
generating_particles = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean noMoreParticles() {
|
||||||
|
return dead == particles.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getParticleCount() {
|
||||||
|
return particles.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EntityParticlePart getParticleAt(int id) {
|
||||||
|
return particles[id];
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,39 @@
|
||||||
|
package projectzombie.entity.particle;
|
||||||
|
|
||||||
|
import gl_engine.vec.Vec3d;
|
||||||
|
import projectzombie.init.Models;
|
||||||
|
import projectzombie.model.IModel;
|
||||||
|
|
||||||
|
public class ParticleWater extends ParticleBreak
|
||||||
|
{
|
||||||
|
public ParticleWater(Vec3d pos, Vec3d velocity) {
|
||||||
|
this(pos, velocity, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ParticleWater(Vec3d pos, Vec3d velocity, int count) {
|
||||||
|
super(pos, velocity, Models.PARTICLE_WATER, count, 0.04);
|
||||||
|
|
||||||
|
still_ypos = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isDead() {
|
||||||
|
return still == particles.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected double getHeight(IModel model) {
|
||||||
|
return 0.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected double getParticleSpeed() {
|
||||||
|
return 0.05;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected double getParticleFade() {
|
||||||
|
return 0.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,557 @@
|
||||||
|
package projectzombie.entity.player;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import org.lwjgl.opengl.GL33;
|
||||||
|
|
||||||
|
import bdf.types.BdfNamedList;
|
||||||
|
import bdf.types.BdfObject;
|
||||||
|
import gl_engine.MathHelpers;
|
||||||
|
import gl_engine.matrix.Matrix4;
|
||||||
|
import gl_engine.vec.Vec2d;
|
||||||
|
import gl_engine.vec.Vec2i;
|
||||||
|
import gl_engine.vec.Vec3d;
|
||||||
|
import projectzombie.Main;
|
||||||
|
import projectzombie.display.DisplayLighting;
|
||||||
|
import projectzombie.entity.Entity;
|
||||||
|
import projectzombie.entity.EntityAlive;
|
||||||
|
import projectzombie.entity.EntityHasArmor;
|
||||||
|
import projectzombie.entity.EntityHasClothing;
|
||||||
|
import projectzombie.entity.EntityHasInventory;
|
||||||
|
import projectzombie.entity.EntityHasTasks;
|
||||||
|
import projectzombie.entity.EntityItem;
|
||||||
|
import projectzombie.entity.particle.ParticleBreak;
|
||||||
|
import projectzombie.init.Items;
|
||||||
|
import projectzombie.init.Models;
|
||||||
|
import projectzombie.init.Tiles;
|
||||||
|
import projectzombie.inventory.Inventory;
|
||||||
|
import projectzombie.inventory.InventoryArmor;
|
||||||
|
import projectzombie.inventory.InventoryClothing;
|
||||||
|
import projectzombie.items.ItemTool;
|
||||||
|
import projectzombie.items.modifier.ItemModifierMeta;
|
||||||
|
import projectzombie.model.Model;
|
||||||
|
import projectzombie.model.ModelPlayer;
|
||||||
|
import projectzombie.settings.Cheats;
|
||||||
|
import projectzombie.task.Task;
|
||||||
|
import projectzombie.task.TaskDeathScreen;
|
||||||
|
import projectzombie.tiles.TileSapling;
|
||||||
|
import projectzombie.util.ItemStack;
|
||||||
|
import projectzombie.util.TileState;
|
||||||
|
import projectzombie.world.chunk.Chunk;
|
||||||
|
import projectzombie.world.layer.Layer;
|
||||||
|
|
||||||
|
public class EntityPlayer extends Entity implements
|
||||||
|
EntityAlive, EntityHasInventory, EntityHasArmor, EntityHasClothing, EntityHasTasks
|
||||||
|
{
|
||||||
|
public boolean MOVE_FORWARD = false;
|
||||||
|
public boolean MOVE_BACKWARD = false;
|
||||||
|
public boolean MOVE_LEFT = false;
|
||||||
|
public boolean MOVE_RIGHT = false;
|
||||||
|
|
||||||
|
public boolean moving = false;
|
||||||
|
|
||||||
|
public ModelPlayer MODEL = Models.ENTITY_PLAYER_W;
|
||||||
|
|
||||||
|
private double health_max = 1000;
|
||||||
|
private double health = health_max;
|
||||||
|
private double temperature = 0.5;
|
||||||
|
private double hydration = 1;
|
||||||
|
private double break_progress = 0;
|
||||||
|
private Vec2i break_pos = new Vec2i(0, 0);
|
||||||
|
public boolean dead = false;
|
||||||
|
public boolean in_animation = false;
|
||||||
|
public int attackedCooldown = 0;
|
||||||
|
private int particle_spawn_cooldown = 0;
|
||||||
|
|
||||||
|
private ArrayList<Task> tasks;
|
||||||
|
private Inventory inventory;
|
||||||
|
private InventoryArmor armor;
|
||||||
|
private InventoryClothing clothing;
|
||||||
|
|
||||||
|
public int inventory_hand = 0;
|
||||||
|
|
||||||
|
public double angle;
|
||||||
|
|
||||||
|
private Vec2i last_chunk;
|
||||||
|
|
||||||
|
public EntityPlayer(BdfObject bdf) {
|
||||||
|
BdfClassLoad(bdf);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void BdfClassLoad(BdfObject bdf) {
|
||||||
|
super.BdfClassLoad(bdf);
|
||||||
|
BdfNamedList nl = bdf.getNamedList();
|
||||||
|
health = nl.get("health").getDouble();
|
||||||
|
dead = nl.get("dead").getBoolean();
|
||||||
|
inventory = new Inventory(nl.get("inventory"));
|
||||||
|
armor = new InventoryArmor(nl.get("armor"));
|
||||||
|
clothing = new InventoryClothing(nl.get("clothing"));
|
||||||
|
angle = nl.get("angle").getDouble();
|
||||||
|
temperature = nl.get("temperature").getDouble();
|
||||||
|
hydration = nl.get("hydration").getDouble();
|
||||||
|
inventory_hand = nl.get("hand").getInteger();
|
||||||
|
attackedCooldown = nl.get("attackedCooldown").getInteger();
|
||||||
|
|
||||||
|
tasks = new ArrayList<Task>();
|
||||||
|
|
||||||
|
Task[] tasks = Task.loadTasks(this, nl.get("tasks"));
|
||||||
|
|
||||||
|
for(int i=0;i<tasks.length;i++) {
|
||||||
|
this.tasks.add(tasks[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(hydration > 1) {
|
||||||
|
hydration = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getAmmo() {
|
||||||
|
return inventory.getItemCount(new ItemStack(Items.AMMO, 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void BdfClassSave(BdfObject bdf) {
|
||||||
|
super.BdfClassSave(bdf);
|
||||||
|
BdfNamedList nl = bdf.getNamedList();
|
||||||
|
nl.set("health", bdf.newObject().setDouble(health));
|
||||||
|
nl.set("dead", bdf.newObject().setBoolean(dead));
|
||||||
|
inventory.BdfClassSave(nl.get("inventory"));
|
||||||
|
armor.BdfClassSave(nl.get("armor"));
|
||||||
|
clothing.BdfClassSave(nl.get("clothing"));
|
||||||
|
nl.set("angle", bdf.newObject().setDouble(angle));
|
||||||
|
nl.set("temperature", bdf.newObject().setDouble(temperature));
|
||||||
|
nl.set("hydration", bdf.newObject().setDouble(hydration));
|
||||||
|
nl.set("tasks", Task.saveTasks(bdf.newObject(), tasks.toArray(new Task[0])));
|
||||||
|
nl.set("hand", bdf.newObject().setInteger(inventory_hand));
|
||||||
|
nl.set("attackedCooldown", bdf.newObject().setInteger(attackedCooldown));
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityPlayer() {
|
||||||
|
super(new Vec3d(0, 0, 0), new Vec3d(0, 0, 0));
|
||||||
|
|
||||||
|
this.angle = 45;
|
||||||
|
|
||||||
|
// Set some settings
|
||||||
|
hitbox = 0.5;
|
||||||
|
isSolid = true;
|
||||||
|
emitsLight = true;
|
||||||
|
|
||||||
|
tasks = new ArrayList<Task>();
|
||||||
|
|
||||||
|
// Create the inventory
|
||||||
|
inventory = new Inventory(42);
|
||||||
|
armor = new InventoryArmor();
|
||||||
|
clothing = new InventoryClothing();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double getLightLevel()
|
||||||
|
{
|
||||||
|
ItemStack item = inventory.getItem(inventory_hand);
|
||||||
|
|
||||||
|
if(!item.isEmpty()) {
|
||||||
|
return getLightWithHeight(item.item.getLightLevel(item));
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void tick(Chunk chunk, Layer layer)
|
||||||
|
{
|
||||||
|
chunk = layer.getChunk(getPos().xz());
|
||||||
|
|
||||||
|
if(chunk != null && chunk.c_pos != null && (last_chunk == null || !chunk.c_pos.equal(last_chunk))) {
|
||||||
|
last_chunk = chunk.c_pos;
|
||||||
|
DisplayLighting.setDirty();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle player deaths
|
||||||
|
if(health <= 0 && !dead)
|
||||||
|
{
|
||||||
|
chunk.spawnEntity(new ParticleBreak(getPos(), getVelocity(), getModel()));
|
||||||
|
|
||||||
|
if(Cheats.god_mode) {
|
||||||
|
this.resetHealth();
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
dead = true;
|
||||||
|
health = 0;
|
||||||
|
addTask(new TaskDeathScreen(this));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int i=0;i<tasks.size();i++) {
|
||||||
|
Task task = tasks.get(i);
|
||||||
|
if(task.isDone()) {
|
||||||
|
tasks.remove(i);
|
||||||
|
i -= 1;
|
||||||
|
} else {
|
||||||
|
task.update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Is the player dead or in an animation
|
||||||
|
if(dead || in_animation) return;
|
||||||
|
|
||||||
|
// Call super
|
||||||
|
super.tick(chunk, layer);
|
||||||
|
|
||||||
|
if(attackedCooldown > 0) {
|
||||||
|
attackedCooldown -= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
double temp_diff = MathHelpers.biggest(
|
||||||
|
layer.layergen.getTemperature(layer, getPos().xz()),
|
||||||
|
chunk.getLightLevel(getPos().xz().toInt()) * 0.6) - temperature;
|
||||||
|
|
||||||
|
temperature += temp_diff / 1000;
|
||||||
|
hydration -= MathHelpers.smoothStep(Math.abs(temperature - 0.4) * 0.75 + 0.1) / 4000;
|
||||||
|
|
||||||
|
if(temperature < 0.3) {
|
||||||
|
health -= 2 * (0.3 - temperature);
|
||||||
|
resetAttackTimer();
|
||||||
|
}
|
||||||
|
|
||||||
|
else if(temperature > 0.7) {
|
||||||
|
health -= 4 * (temperature - 0.7);
|
||||||
|
resetAttackTimer();
|
||||||
|
}
|
||||||
|
|
||||||
|
else if(attackedCooldown == 0 && health < health_max) {
|
||||||
|
health += 0.1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(hydration <= 0) {
|
||||||
|
hydration = 0;
|
||||||
|
health -= 0.1;
|
||||||
|
resetAttackTimer();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rotate left
|
||||||
|
if(MOVE_LEFT) {
|
||||||
|
this.angle -= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rotate right
|
||||||
|
if(MOVE_RIGHT) {
|
||||||
|
this.angle += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.angle = MathHelpers.mod(this.angle, 360);
|
||||||
|
|
||||||
|
// Move forward
|
||||||
|
if(MOVE_FORWARD) {
|
||||||
|
this.moveTowards(this.angle);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Move backward
|
||||||
|
if(MOVE_BACKWARD) {
|
||||||
|
this.moveTowards(this.angle + 180);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void kill()
|
||||||
|
{
|
||||||
|
// Is god mode inactive; kill the player
|
||||||
|
if(Cheats.god_mode) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
chunk.spawnEntity(new ParticleBreak(getPos(), getVelocity(), getModel()));
|
||||||
|
|
||||||
|
dead = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void moveTowards(double angle, double speed) {
|
||||||
|
if(dead || in_animation) return;
|
||||||
|
super.push(MathHelpers.moveTowards2(speed, Math.toRadians(angle)).xny());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void moveTowards(double angle) {
|
||||||
|
this.moveTowards(angle, 0.08);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void leftClick() {
|
||||||
|
if(dead || in_animation) return;
|
||||||
|
|
||||||
|
Layer layer = Main.world.getLayer();
|
||||||
|
ItemStack is = inventory.getItem(inventory_hand);
|
||||||
|
Vec2d place_pos = getPos().xz().add(MathHelpers.moveTowards2(0.5, Math.toRadians(angle)));
|
||||||
|
|
||||||
|
if(is.isEmpty() || !is.item.onPlayerLeftClick(is, Main.world.getLayer(), this, place_pos))
|
||||||
|
{
|
||||||
|
boolean isTool = !is.isEmpty() && is.item instanceof ItemTool;
|
||||||
|
ItemTool tool = isTool ? (ItemTool) is.item : null;
|
||||||
|
double speed = isTool ? ((ItemTool) is.item).toolSpeed(is) : 1;
|
||||||
|
Vec2i pos = place_pos.toInt();
|
||||||
|
|
||||||
|
for(int ti=0;ti<2;ti++)
|
||||||
|
{
|
||||||
|
TileState ts;
|
||||||
|
|
||||||
|
if(ti == 0) {
|
||||||
|
ts = layer.getFrontTile(pos);
|
||||||
|
} else {
|
||||||
|
ts = layer.getBackTile(pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(ts.tile.canTileBreak(ts, is, tool))
|
||||||
|
{
|
||||||
|
break_progress += speed;
|
||||||
|
|
||||||
|
if(!pos.equal(break_pos)) {
|
||||||
|
break_progress = 0;
|
||||||
|
break_pos = pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
particle_spawn_cooldown += 1;
|
||||||
|
|
||||||
|
if(particle_spawn_cooldown > 10) {
|
||||||
|
particle_spawn_cooldown -= 10;
|
||||||
|
|
||||||
|
layer.spawnEntity(new ParticleBreak(
|
||||||
|
new Vec3d(pos.x + 0.5, 0, pos.y + 0.5),
|
||||||
|
new Vec3d(0, 0, 0), ts.tile.getModel(ts.meta), 2));
|
||||||
|
}
|
||||||
|
|
||||||
|
if(break_progress > ts.tile.hardness)
|
||||||
|
{
|
||||||
|
ItemStack[] stacks = ts.tile.getTileDrops(ts);
|
||||||
|
|
||||||
|
for(ItemStack stack : stacks) {
|
||||||
|
layer.spawnEntity(new EntityItem(
|
||||||
|
pos.toDouble().add(new Vec2d(0.5, 0.5)).xny(),
|
||||||
|
new Vec3d(0, 0, 0), stack));
|
||||||
|
}
|
||||||
|
|
||||||
|
if(ts.tile.doBreak(layer, chunk, ts, pos)) {
|
||||||
|
if(ti == 0) {
|
||||||
|
layer.breakFrontTile(pos);
|
||||||
|
} else {
|
||||||
|
layer.breakBackTile(pos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
break_progress = 0;
|
||||||
|
|
||||||
|
if(tool != null) {
|
||||||
|
tool.toolOnUse(is);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void rightClick() {
|
||||||
|
if(dead || in_animation) return;
|
||||||
|
|
||||||
|
ItemStack is = inventory.getItem(inventory_hand);
|
||||||
|
Vec2d movement = MathHelpers.moveTowards2(1, Math.toRadians(angle));
|
||||||
|
Vec2d place_pos = getPos().xz().add(movement);
|
||||||
|
|
||||||
|
if(!activateTile(getPos().xz().add(movement.multiply(0.5)).toInt()) && !is.isEmpty()) {
|
||||||
|
is.item.onPlayerRightClick(is, Main.world.getLayer(), this, place_pos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addHealth(double amount) {
|
||||||
|
health += amount;
|
||||||
|
if(health > health_max) health = health_max;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addDamage(double amount) {
|
||||||
|
health -= amount;
|
||||||
|
resetAttackTimer();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void resetAttackTimer() {
|
||||||
|
attackedCooldown = 3000; // Don't heal for 30 seconds
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addFireDamage(double amount) {
|
||||||
|
addDamage(amount);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addBlastDamage(double amount) {
|
||||||
|
addDamage(amount);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double getHealth() {
|
||||||
|
return health;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void resetHealth() {
|
||||||
|
health = health_max;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void clearHealth() {
|
||||||
|
health = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double maxHealth() {
|
||||||
|
return health_max;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setHealth(double health) {
|
||||||
|
this.health = health;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Inventory getInventory() {
|
||||||
|
return inventory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void dropItem()
|
||||||
|
{
|
||||||
|
ItemStack i = inventory.getItem(inventory_hand);
|
||||||
|
|
||||||
|
if(!i.isEmpty())
|
||||||
|
{
|
||||||
|
ItemStack stack = i.copy();
|
||||||
|
stack.count = 1;
|
||||||
|
|
||||||
|
EntityItem e = new EntityItem(getPos(), getVelocity(), stack, Math.toRadians(angle));
|
||||||
|
Main.world.getLayer().spawnEntity(e);
|
||||||
|
i.count -= 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void render()
|
||||||
|
{
|
||||||
|
Layer layer = Main.world.getLayer();
|
||||||
|
Model model = getModel();
|
||||||
|
model.setModel(Matrix4.translate(0, getPos().y, 0));
|
||||||
|
model.render();
|
||||||
|
|
||||||
|
ItemStack holding = inventory.getItem(inventory_hand);
|
||||||
|
Vec2d place_pos = getPos().xz().add(MathHelpers.moveTowards2(0.5, Math.toRadians(angle)));
|
||||||
|
Vec3d ppos = getPos();
|
||||||
|
|
||||||
|
{
|
||||||
|
boolean isTool = !holding.isEmpty() && holding.item instanceof ItemTool;
|
||||||
|
ItemTool tool = isTool ? (ItemTool) holding.item : null;
|
||||||
|
Vec2i pos = place_pos.toInt();
|
||||||
|
|
||||||
|
for(int ti=0;ti<2;ti++)
|
||||||
|
{
|
||||||
|
TileState ts;
|
||||||
|
|
||||||
|
if(ti == 0) {
|
||||||
|
ts = layer.getFrontTile(pos);
|
||||||
|
} else {
|
||||||
|
ts = layer.getBackTile(pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(ts.tile.canTileBreak(ts, holding, tool) || ts.tile.canUse(ts))
|
||||||
|
{
|
||||||
|
Models.TILE_BORDER.setModel(Matrix4.translate(
|
||||||
|
new Vec3d(pos.x - ppos.x, 0, pos.y - ppos.z)));
|
||||||
|
Models.TILE_BORDER.render();
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(holding != null && !holding.isEmpty())
|
||||||
|
{
|
||||||
|
Model model_place = holding.item.getPlaceModel(holding);
|
||||||
|
Model model_spawn = holding.item.getSpawnModel(holding);
|
||||||
|
Vec2d pos = ppos.xz().add(MathHelpers.moveTowards2(1, Math.toRadians(angle)));
|
||||||
|
boolean render_place_model = model_place != null &&
|
||||||
|
holding.item.showPlaceModel(layer, pos.toInt(), holding);
|
||||||
|
|
||||||
|
if(render_place_model || model_spawn != null)
|
||||||
|
{
|
||||||
|
GL33.glUniform4f(Main.window.glsl_color, 0.5f, 0.75f, 0.5f, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(render_place_model)
|
||||||
|
{
|
||||||
|
model_place.setModel(Matrix4.translate(new Vec3d(
|
||||||
|
MathHelpers.floor(pos.x) + 0.5 - ppos.x, 0.00390625,
|
||||||
|
MathHelpers.floor(pos.y) + 0.5 - ppos.z)));
|
||||||
|
model_place.render();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(model_spawn != null)
|
||||||
|
{
|
||||||
|
model_spawn.setModel(Matrix4.translate(pos.x - ppos.x, 0, pos.y - ppos.z));
|
||||||
|
model_spawn.render();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(render_place_model || model_spawn != null)
|
||||||
|
{
|
||||||
|
GL33.glUniform4f(Main.window.glsl_color, 1, 1, 1, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int bloodParticles() {
|
||||||
|
return 12;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Model getModel() {
|
||||||
|
return moving ? MODEL.model_back_moving : MODEL.model_back_still;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getTemperature() {
|
||||||
|
return temperature;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getHydration() {
|
||||||
|
return hydration;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setInAnimation(boolean status)
|
||||||
|
{
|
||||||
|
in_animation = status;
|
||||||
|
hasGravity = !status;
|
||||||
|
isSolid = !status;
|
||||||
|
moving = status;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addTask(Task task) {
|
||||||
|
tasks.add(task);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void rehydrate()
|
||||||
|
{
|
||||||
|
hydration += 0.001;
|
||||||
|
|
||||||
|
if(hydration > 1) {
|
||||||
|
hydration = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public InventoryClothing getInventoryClothing() {
|
||||||
|
return clothing;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public InventoryArmor getInventoryArmor() {
|
||||||
|
return armor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,19 @@
|
||||||
|
package projectzombie.entity.tileentity;
|
||||||
|
|
||||||
|
import gl_engine.vec.Vec2i;
|
||||||
|
import gl_engine.vec.Vec3d;
|
||||||
|
import projectzombie.entity.Entity;
|
||||||
|
import projectzombie.init.Models;
|
||||||
|
import projectzombie.model.IModel;
|
||||||
|
|
||||||
|
public abstract class TileEntity extends Entity
|
||||||
|
{
|
||||||
|
public TileEntity() {
|
||||||
|
super(new Vec3d(0, 0, 0), new Vec3d(0, 0, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IModel getModel() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,265 @@
|
||||||
|
package projectzombie.entity.tileentity;
|
||||||
|
|
||||||
|
import bdf.types.BdfNamedList;
|
||||||
|
import bdf.types.BdfObject;
|
||||||
|
import gl_engine.vec.Vec2i;
|
||||||
|
import projectzombie.Main;
|
||||||
|
import projectzombie.init.Items;
|
||||||
|
import projectzombie.init.Tiles;
|
||||||
|
import projectzombie.inventory.Inventory;
|
||||||
|
import projectzombie.items.ItemBurnable;
|
||||||
|
import projectzombie.items.ItemSmeltable;
|
||||||
|
import projectzombie.items.ItemSmeltable;
|
||||||
|
import projectzombie.items.ItemFlint;
|
||||||
|
import projectzombie.items.ItemSmeltable;
|
||||||
|
import projectzombie.items.modifier.ItemModifierDamage;
|
||||||
|
import projectzombie.menu.MenuInventoryStorage;
|
||||||
|
import projectzombie.menu.gui.GUIItemSlotGetter;
|
||||||
|
import projectzombie.util.ItemStack;
|
||||||
|
import projectzombie.util.TileState;
|
||||||
|
import projectzombie.world.chunk.Chunk;
|
||||||
|
import projectzombie.world.layer.Layer;
|
||||||
|
|
||||||
|
public class TileEntityBlastFurnace extends TileEntity
|
||||||
|
{
|
||||||
|
private ItemStack burning;
|
||||||
|
private Inventory inventory;
|
||||||
|
private int next_level;
|
||||||
|
private int burn_time;
|
||||||
|
private int cook_time;
|
||||||
|
private int cook_slot;
|
||||||
|
private int level;
|
||||||
|
|
||||||
|
public TileEntityBlastFurnace(BdfObject bdf) {
|
||||||
|
BdfClassLoad(bdf);
|
||||||
|
}
|
||||||
|
|
||||||
|
public TileEntityBlastFurnace(Vec2i pos) {
|
||||||
|
inventory = new Inventory(8);
|
||||||
|
burning = ItemStack.getEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void BdfClassLoad(BdfObject bdf) {
|
||||||
|
super.BdfClassLoad(bdf);
|
||||||
|
|
||||||
|
BdfNamedList nl = bdf.getNamedList();
|
||||||
|
|
||||||
|
inventory = new Inventory(nl.get("inventory"));
|
||||||
|
burning = new ItemStack(nl.get("burning"));
|
||||||
|
|
||||||
|
burn_time = nl.get("burnTime").getInteger();
|
||||||
|
cook_time = nl.get("cookTime").getInteger();
|
||||||
|
cook_slot = nl.get("cookSlot").getInteger();
|
||||||
|
next_level = nl.get("nextLevel").getInteger();
|
||||||
|
level = nl.get("level").getInteger();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void BdfClassSave(BdfObject bdf) {
|
||||||
|
super.BdfClassSave(bdf);
|
||||||
|
|
||||||
|
BdfNamedList nl = bdf.getNamedList();
|
||||||
|
|
||||||
|
inventory.BdfClassSave(nl.get("inventory"));
|
||||||
|
burning.BdfClassSave(nl.get("burning"));
|
||||||
|
|
||||||
|
nl.set("burnTime", bdf.newObject().setInteger(burn_time));
|
||||||
|
nl.set("cookTime", bdf.newObject().setInteger(cook_time));
|
||||||
|
nl.set("cookSlot", bdf.newObject().setInteger(cook_slot));
|
||||||
|
nl.set("nextLevel", bdf.newObject().setInteger(next_level));
|
||||||
|
nl.set("level", bdf.newObject().setInteger(level));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateTile() {
|
||||||
|
chunk.setFrontTile(new TileState(Tiles.BLAST_FURNACE, (byte)level), getPos().xz().toInt());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkForFuel()
|
||||||
|
{
|
||||||
|
for(int i=0;i<inventory.getSlotCount();i++)
|
||||||
|
{
|
||||||
|
ItemStack stack = inventory.getItem(i);
|
||||||
|
|
||||||
|
if(stack.isEmpty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(stack.item instanceof ItemBurnable)
|
||||||
|
{
|
||||||
|
stack.count -= 1;
|
||||||
|
|
||||||
|
burning = stack.copy();
|
||||||
|
burning.count = 1;
|
||||||
|
|
||||||
|
burn_time = ((ItemBurnable)stack.item).getBurnTime(burning);
|
||||||
|
|
||||||
|
if(level < 4)
|
||||||
|
{
|
||||||
|
level = 4;
|
||||||
|
updateTile();
|
||||||
|
|
||||||
|
Vec2i tpos = getPos().xz().toInt();
|
||||||
|
|
||||||
|
if(chunk.getBackTile(tpos).tile == Tiles.GRASS) {
|
||||||
|
chunk.setBackTile(Tiles.GRASS_BURNT.getDefaultState(), tpos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void tick(Chunk chunk, Layer layer)
|
||||||
|
{
|
||||||
|
super.tick(chunk, layer);
|
||||||
|
|
||||||
|
// Check for fuel if the fuel has run out
|
||||||
|
if(burning.isEmpty())
|
||||||
|
{
|
||||||
|
// Check for fuel and possibly add it if its available
|
||||||
|
checkForFuel();
|
||||||
|
|
||||||
|
if(!burning.isEmpty()) {
|
||||||
|
next_level = 1600;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if there is fuel
|
||||||
|
// This could have changed since
|
||||||
|
// the last check for fuel
|
||||||
|
if(!burning.isEmpty())
|
||||||
|
{
|
||||||
|
burn_time -= 1;
|
||||||
|
|
||||||
|
if(burn_time < 0)
|
||||||
|
{
|
||||||
|
burn_time = 0;
|
||||||
|
burning.count = 0;
|
||||||
|
|
||||||
|
for(ItemStack stack : ((ItemBurnable)burning.item).getBurnProducts(burning)) {
|
||||||
|
inventory.addItem(stack);
|
||||||
|
}
|
||||||
|
|
||||||
|
checkForFuel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(level > 0)
|
||||||
|
{
|
||||||
|
ItemStack stack = inventory.getItem(cook_slot);
|
||||||
|
|
||||||
|
// Check for cookable items if things aren't being cooked
|
||||||
|
if(stack.isEmpty() || !(stack.item instanceof ItemSmeltable))
|
||||||
|
{
|
||||||
|
cook_time = 1600;
|
||||||
|
|
||||||
|
for(int i=0;i<inventory.getSlotCount();i++)
|
||||||
|
{
|
||||||
|
ItemStack check = inventory.getItem(i);
|
||||||
|
|
||||||
|
if(check.isEmpty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(check.item instanceof ItemSmeltable) {
|
||||||
|
cook_slot = i;
|
||||||
|
cook_time = 1600;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cook the item thats currently being cooked
|
||||||
|
// and process them if they have finished cooking.
|
||||||
|
// Make sure any non-cookable items don't get cooked.
|
||||||
|
|
||||||
|
stack = inventory.getItem(cook_slot);
|
||||||
|
|
||||||
|
if(!stack.isEmpty() && stack.item instanceof ItemSmeltable)
|
||||||
|
{
|
||||||
|
cook_time -= 1;
|
||||||
|
|
||||||
|
if(cook_time < 0)
|
||||||
|
{
|
||||||
|
stack.count -= 1;
|
||||||
|
cook_time = 1600;
|
||||||
|
|
||||||
|
ItemStack[] result = ((ItemSmeltable)stack.item).getSmeltProducts(stack);
|
||||||
|
|
||||||
|
for(int i=0;i<result.length;i++) {
|
||||||
|
inventory.addItem(result[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
next_level -= 1;
|
||||||
|
|
||||||
|
// Make the fire burn brighter/darker based on whether there is fuel or not
|
||||||
|
if(next_level < 0)
|
||||||
|
{
|
||||||
|
if(burning.isEmpty())
|
||||||
|
{
|
||||||
|
next_level = 200;
|
||||||
|
level -= 1;
|
||||||
|
|
||||||
|
if(level < 0) {
|
||||||
|
level = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
updateTile();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
next_level = 1600;
|
||||||
|
level += 1;
|
||||||
|
|
||||||
|
if(level > 16) {
|
||||||
|
level = 16;
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
updateTile();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Inventory getInventory() {
|
||||||
|
return inventory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onOpened() {
|
||||||
|
Main.menu = new MenuInventoryStorage(Main.menu, inventory, new GUIItemSlotGetter() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setItemStack(ItemStack stack) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isAllowed(ItemStack stack)
|
||||||
|
{
|
||||||
|
if(stack.item instanceof ItemBurnable) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(stack.item instanceof ItemSmeltable) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ItemStack getItemStack() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,264 @@
|
||||||
|
package projectzombie.entity.tileentity;
|
||||||
|
|
||||||
|
import bdf.types.BdfNamedList;
|
||||||
|
import bdf.types.BdfObject;
|
||||||
|
import gl_engine.vec.Vec2i;
|
||||||
|
import projectzombie.Main;
|
||||||
|
import projectzombie.init.Items;
|
||||||
|
import projectzombie.init.Tiles;
|
||||||
|
import projectzombie.inventory.Inventory;
|
||||||
|
import projectzombie.items.ItemBurnable;
|
||||||
|
import projectzombie.items.ItemCookable;
|
||||||
|
import projectzombie.items.ItemFlint;
|
||||||
|
import projectzombie.items.ItemSmeltable;
|
||||||
|
import projectzombie.items.modifier.ItemModifierDamage;
|
||||||
|
import projectzombie.menu.MenuInventoryStorage;
|
||||||
|
import projectzombie.menu.gui.GUIItemSlotGetter;
|
||||||
|
import projectzombie.util.ItemStack;
|
||||||
|
import projectzombie.util.TileState;
|
||||||
|
import projectzombie.world.chunk.Chunk;
|
||||||
|
import projectzombie.world.layer.Layer;
|
||||||
|
|
||||||
|
public class TileEntityCampfire extends TileEntity
|
||||||
|
{
|
||||||
|
private ItemStack burning;
|
||||||
|
private Inventory inventory;
|
||||||
|
private int next_level;
|
||||||
|
private int burn_time;
|
||||||
|
private int cook_time;
|
||||||
|
private int cook_slot;
|
||||||
|
private int level;
|
||||||
|
|
||||||
|
public TileEntityCampfire(BdfObject bdf) {
|
||||||
|
BdfClassLoad(bdf);
|
||||||
|
}
|
||||||
|
|
||||||
|
public TileEntityCampfire(Vec2i pos) {
|
||||||
|
inventory = new Inventory(8);
|
||||||
|
burning = ItemStack.getEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void BdfClassLoad(BdfObject bdf) {
|
||||||
|
super.BdfClassLoad(bdf);
|
||||||
|
|
||||||
|
BdfNamedList nl = bdf.getNamedList();
|
||||||
|
|
||||||
|
inventory = new Inventory(nl.get("inventory"));
|
||||||
|
burning = new ItemStack(nl.get("burning"));
|
||||||
|
|
||||||
|
burn_time = nl.get("burnTime").getInteger();
|
||||||
|
cook_time = nl.get("cookTime").getInteger();
|
||||||
|
cook_slot = nl.get("cookSlot").getInteger();
|
||||||
|
next_level = nl.get("nextLevel").getInteger();
|
||||||
|
level = nl.get("level").getInteger();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void BdfClassSave(BdfObject bdf) {
|
||||||
|
super.BdfClassSave(bdf);
|
||||||
|
|
||||||
|
BdfNamedList nl = bdf.getNamedList();
|
||||||
|
|
||||||
|
inventory.BdfClassSave(nl.get("inventory"));
|
||||||
|
burning.BdfClassSave(nl.get("burning"));
|
||||||
|
|
||||||
|
nl.set("burnTime", bdf.newObject().setInteger(burn_time));
|
||||||
|
nl.set("cookTime", bdf.newObject().setInteger(cook_time));
|
||||||
|
nl.set("cookSlot", bdf.newObject().setInteger(cook_slot));
|
||||||
|
nl.set("nextLevel", bdf.newObject().setInteger(next_level));
|
||||||
|
nl.set("level", bdf.newObject().setInteger(level));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateTile() {
|
||||||
|
chunk.setFrontTile(new TileState(Tiles.CAMPFIRE, (byte)level), getPos().xz().toInt());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkForFuel()
|
||||||
|
{
|
||||||
|
for(int i=0;i<inventory.getSlotCount();i++)
|
||||||
|
{
|
||||||
|
ItemStack stack = inventory.getItem(i);
|
||||||
|
|
||||||
|
if(stack.isEmpty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(stack.item instanceof ItemBurnable)
|
||||||
|
{
|
||||||
|
stack.count -= 1;
|
||||||
|
|
||||||
|
burning = stack.copy();
|
||||||
|
burning.count = 1;
|
||||||
|
|
||||||
|
burn_time = ((ItemBurnable)stack.item).getBurnTime(burning);
|
||||||
|
|
||||||
|
if(level < 4)
|
||||||
|
{
|
||||||
|
level = 4;
|
||||||
|
updateTile();
|
||||||
|
|
||||||
|
Vec2i tpos = getPos().xz().toInt();
|
||||||
|
|
||||||
|
if(chunk.getBackTile(tpos).tile == Tiles.GRASS) {
|
||||||
|
chunk.setBackTile(Tiles.GRASS_BURNT.getDefaultState(), tpos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void tick(Chunk chunk, Layer layer)
|
||||||
|
{
|
||||||
|
super.tick(chunk, layer);
|
||||||
|
|
||||||
|
// Check for fuel if the fuel has run out
|
||||||
|
if(burning.isEmpty())
|
||||||
|
{
|
||||||
|
// Check for fuel and possibly add it if its available
|
||||||
|
checkForFuel();
|
||||||
|
|
||||||
|
if(!burning.isEmpty()) {
|
||||||
|
next_level = 1600;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if there is fuel
|
||||||
|
// This could have changed since
|
||||||
|
// the last check for fuel
|
||||||
|
if(!burning.isEmpty())
|
||||||
|
{
|
||||||
|
burn_time -= 1;
|
||||||
|
|
||||||
|
if(burn_time < 0)
|
||||||
|
{
|
||||||
|
burn_time = 0;
|
||||||
|
burning.count = 0;
|
||||||
|
|
||||||
|
for(ItemStack stack : ((ItemBurnable)burning.item).getBurnProducts(burning)) {
|
||||||
|
inventory.addItem(stack);
|
||||||
|
}
|
||||||
|
|
||||||
|
checkForFuel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(level > 0)
|
||||||
|
{
|
||||||
|
ItemStack stack = inventory.getItem(cook_slot);
|
||||||
|
|
||||||
|
// Check for cookable items if things aren't being cooked
|
||||||
|
if(stack.isEmpty() || !(stack.item instanceof ItemCookable))
|
||||||
|
{
|
||||||
|
cook_time = 1600;
|
||||||
|
|
||||||
|
for(int i=0;i<inventory.getSlotCount();i++)
|
||||||
|
{
|
||||||
|
ItemStack check = inventory.getItem(i);
|
||||||
|
|
||||||
|
if(check.isEmpty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(check.item instanceof ItemCookable) {
|
||||||
|
cook_slot = i;
|
||||||
|
cook_time = 1600;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cook the item thats currently being cooked
|
||||||
|
// and process them if they have finished cooking.
|
||||||
|
// Make sure any non-cookable items don't get cooked.
|
||||||
|
|
||||||
|
stack = inventory.getItem(cook_slot);
|
||||||
|
|
||||||
|
if(!stack.isEmpty() && stack.item instanceof ItemCookable)
|
||||||
|
{
|
||||||
|
cook_time -= 1;
|
||||||
|
|
||||||
|
if(cook_time < 0)
|
||||||
|
{
|
||||||
|
stack.count -= 1;
|
||||||
|
cook_time = 1600;
|
||||||
|
|
||||||
|
ItemStack[] result = ((ItemCookable)stack.item).getCookProducts(stack);
|
||||||
|
|
||||||
|
for(int i=0;i<result.length;i++) {
|
||||||
|
inventory.addItem(result[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
next_level -= 1;
|
||||||
|
|
||||||
|
// Make the fire burn brighter/darker based on whether there is fuel or not
|
||||||
|
if(next_level < 0)
|
||||||
|
{
|
||||||
|
if(burning.isEmpty())
|
||||||
|
{
|
||||||
|
next_level = 200;
|
||||||
|
level -= 1;
|
||||||
|
|
||||||
|
if(level < 0) {
|
||||||
|
level = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
updateTile();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
next_level = 1600;
|
||||||
|
level += 1;
|
||||||
|
|
||||||
|
if(level > 16) {
|
||||||
|
level = 16;
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
updateTile();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Inventory getInventory() {
|
||||||
|
return inventory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onOpened() {
|
||||||
|
Main.menu = new MenuInventoryStorage(Main.menu, inventory, new GUIItemSlotGetter() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setItemStack(ItemStack stack) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isAllowed(ItemStack stack)
|
||||||
|
{
|
||||||
|
if(stack.item instanceof ItemBurnable) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(stack.item instanceof ItemCookable) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ItemStack getItemStack() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,42 @@
|
||||||
|
package projectzombie.entity.tileentity;
|
||||||
|
|
||||||
|
import bdf.types.BdfNamedList;
|
||||||
|
import bdf.types.BdfObject;
|
||||||
|
import projectzombie.util.ItemStack;
|
||||||
|
|
||||||
|
public class TileEntityClayPot extends TileEntity
|
||||||
|
{
|
||||||
|
private double volume;
|
||||||
|
|
||||||
|
public TileEntityClayPot(double volume) {
|
||||||
|
this.volume = volume;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TileEntityClayPot(BdfObject bdf) {
|
||||||
|
BdfClassLoad(bdf);
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getVolume() {
|
||||||
|
return volume;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setVolume(double volume) {
|
||||||
|
this.volume = volume;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void BdfClassLoad(BdfObject bdf) {
|
||||||
|
super.BdfClassLoad(bdf);
|
||||||
|
|
||||||
|
BdfNamedList nl = bdf.getNamedList();
|
||||||
|
volume = nl.get("volume").getDouble();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void BdfClassSave(BdfObject bdf) {
|
||||||
|
super.BdfClassSave(bdf);
|
||||||
|
|
||||||
|
BdfNamedList nl = bdf.getNamedList();
|
||||||
|
nl.set("volume", bdf.newObject().setDouble(volume));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,57 @@
|
||||||
|
package projectzombie.init;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import bdf.types.BdfObject;
|
||||||
|
import projectzombie.entity.Entity;
|
||||||
|
import projectzombie.entity.EntityBoss;
|
||||||
|
import projectzombie.entity.EntityBullet;
|
||||||
|
import projectzombie.entity.EntityContainer;
|
||||||
|
import projectzombie.entity.EntityDummy;
|
||||||
|
import projectzombie.entity.EntityExplosion;
|
||||||
|
import projectzombie.entity.EntityFlare;
|
||||||
|
import projectzombie.entity.EntityGrapplingHook;
|
||||||
|
import projectzombie.entity.EntityItem;
|
||||||
|
import projectzombie.entity.EntityTnt;
|
||||||
|
import projectzombie.entity.EntityZombie;
|
||||||
|
import projectzombie.entity.EntityZombieArmored;
|
||||||
|
import projectzombie.entity.player.EntityPlayer;
|
||||||
|
import projectzombie.entity.tileentity.TileEntityBlastFurnace;
|
||||||
|
import projectzombie.entity.tileentity.TileEntityCampfire;
|
||||||
|
import projectzombie.entity.tileentity.TileEntityClayPot;
|
||||||
|
|
||||||
|
public class Entities
|
||||||
|
{
|
||||||
|
public static final ArrayList<Class<? extends Entity>> ENTITIES = new ArrayList<>();
|
||||||
|
|
||||||
|
private static void register(Class<? extends Entity> e)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
e.getConstructor(BdfObject.class);
|
||||||
|
} catch (NoSuchMethodException | SecurityException err) {
|
||||||
|
err.printStackTrace();
|
||||||
|
System.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
ENTITIES.add(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void init()
|
||||||
|
{
|
||||||
|
register(EntityZombie.class);
|
||||||
|
register(EntityZombieArmored.class);
|
||||||
|
register(EntityTnt.class);
|
||||||
|
register(EntityItem.class);
|
||||||
|
register(EntityGrapplingHook.class);
|
||||||
|
register(EntityFlare.class);
|
||||||
|
register(EntityExplosion.class);
|
||||||
|
register(EntityDummy.class);
|
||||||
|
register(EntityBullet.class);
|
||||||
|
register(EntityBoss.class);
|
||||||
|
register(EntityPlayer.class);
|
||||||
|
register(EntityContainer.class);
|
||||||
|
register(TileEntityCampfire.class);
|
||||||
|
register(TileEntityBlastFurnace.class);
|
||||||
|
register(TileEntityClayPot.class);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,39 @@
|
||||||
|
package projectzombie.init;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import bdf.types.BdfObject;
|
||||||
|
import projectzombie.items.modifier.ItemModifier;
|
||||||
|
import projectzombie.items.modifier.ItemModifierDamage;
|
||||||
|
import projectzombie.items.modifier.ItemModifierFluidStorage;
|
||||||
|
import projectzombie.items.modifier.ItemModifierMeta;
|
||||||
|
import projectzombie.items.modifier.ItemModifierTimer;
|
||||||
|
import projectzombie.items.modifier.ItemModifierTimerPaused;
|
||||||
|
import projectzombie.items.modifier.ItemModifierWater;
|
||||||
|
|
||||||
|
public class ItemModifiers
|
||||||
|
{
|
||||||
|
public static final ArrayList<Class<? extends ItemModifier>> MODIFIERS = new ArrayList<>();
|
||||||
|
|
||||||
|
private static void register(Class<? extends ItemModifier> m)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
m.getConstructor(BdfObject.class);
|
||||||
|
} catch (NoSuchMethodException | SecurityException err) {
|
||||||
|
err.printStackTrace();
|
||||||
|
System.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
MODIFIERS.add(m);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void init()
|
||||||
|
{
|
||||||
|
register(ItemModifierMeta.class);
|
||||||
|
register(ItemModifierDamage.class);
|
||||||
|
register(ItemModifierFluidStorage.class);
|
||||||
|
register(ItemModifierWater.class);
|
||||||
|
register(ItemModifierTimer.class);
|
||||||
|
register(ItemModifierTimerPaused.class);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,120 @@
|
||||||
|
package projectzombie.init;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import projectzombie.items.Item;
|
||||||
|
import projectzombie.items.ItemAcorn;
|
||||||
|
import projectzombie.items.ItemAmmo;
|
||||||
|
import projectzombie.items.ItemAsh;
|
||||||
|
import projectzombie.items.ItemBlastFurnace;
|
||||||
|
import projectzombie.items.ItemCampfire;
|
||||||
|
import projectzombie.items.ItemCharcoal;
|
||||||
|
import projectzombie.items.ItemClayPot;
|
||||||
|
import projectzombie.items.ItemClayPotWet;
|
||||||
|
import projectzombie.items.ItemCoal;
|
||||||
|
import projectzombie.items.ItemEmpty;
|
||||||
|
import projectzombie.items.ItemFlare;
|
||||||
|
import projectzombie.items.ItemFlint;
|
||||||
|
import projectzombie.items.ItemFlintHatchet;
|
||||||
|
import projectzombie.items.ItemGrapplingHook;
|
||||||
|
import projectzombie.items.ItemHealthPotion;
|
||||||
|
import projectzombie.items.ItemHempSeed;
|
||||||
|
import projectzombie.items.ItemInfestation;
|
||||||
|
import projectzombie.items.ItemLantern;
|
||||||
|
import projectzombie.items.ItemLog;
|
||||||
|
import projectzombie.items.ItemMetal;
|
||||||
|
import projectzombie.items.ItemOre;
|
||||||
|
import projectzombie.items.ItemPlantFibre;
|
||||||
|
import projectzombie.items.ItemRock;
|
||||||
|
import projectzombie.items.ItemStoneHatchet;
|
||||||
|
import projectzombie.items.ItemStonePick;
|
||||||
|
import projectzombie.items.ItemStoneShovel;
|
||||||
|
import projectzombie.items.ItemTnt;
|
||||||
|
import projectzombie.items.ItemTorch;
|
||||||
|
import projectzombie.items.ItemWoodPlanks;
|
||||||
|
import projectzombie.items.ItemWoodWall;
|
||||||
|
import projectzombie.items.ItemWorkbench;
|
||||||
|
import projectzombie.items.spawner.ItemSpawnDummy;
|
||||||
|
import projectzombie.items.spawner.ItemSpawnZombie;
|
||||||
|
|
||||||
|
public class Items
|
||||||
|
{
|
||||||
|
public static ArrayList<Item> items = new ArrayList<Item>();
|
||||||
|
|
||||||
|
private static void register(Item item) {
|
||||||
|
item.id = items.size();
|
||||||
|
items.add(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void init()
|
||||||
|
{
|
||||||
|
register(EMPTY);
|
||||||
|
register(AMMO);
|
||||||
|
register(HEALTH_POTION);
|
||||||
|
register(TNT);
|
||||||
|
register(LANTERN);
|
||||||
|
register(FLARE);
|
||||||
|
register(GRAPPLING_HOOK);
|
||||||
|
register(SPAWN_ZOMBIE);
|
||||||
|
register(SPAWN_DUMMY);
|
||||||
|
register(ROCK);
|
||||||
|
register(FLINT);
|
||||||
|
register(LOG);
|
||||||
|
register(ACORN);
|
||||||
|
register(PLANT_FIBRE);
|
||||||
|
register(HEMP_SEED);
|
||||||
|
register(AMMO);
|
||||||
|
register(INFESTATION);
|
||||||
|
register(FLINT_HATCHET);
|
||||||
|
register(CAMPFIRE);
|
||||||
|
register(CHARCOAL);
|
||||||
|
register(ASH);
|
||||||
|
register(WORKBENCH);
|
||||||
|
register(STONE_HATCHET);
|
||||||
|
register(STONE_PICK);
|
||||||
|
register(STONE_SHOVEL);
|
||||||
|
register(METAL);
|
||||||
|
register(ORE);
|
||||||
|
register(BLAST_FURNACE);
|
||||||
|
register(CLAY_POT);
|
||||||
|
register(CLAY_POT_WET);
|
||||||
|
register(TORCH);
|
||||||
|
register(COAL);
|
||||||
|
register(WOOD_PLANKS);
|
||||||
|
register(WOOD_WALL);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final Item AMMO = new ItemAmmo();
|
||||||
|
public static final Item HEALTH_POTION = new ItemHealthPotion();
|
||||||
|
public static final Item EMPTY = new ItemEmpty();
|
||||||
|
public static final Item TNT = new ItemTnt();
|
||||||
|
public static final Item LANTERN = new ItemLantern();
|
||||||
|
public static final Item FLARE = new ItemFlare();
|
||||||
|
public static final Item GRAPPLING_HOOK = new ItemGrapplingHook();
|
||||||
|
public static final Item SPAWN_ZOMBIE = new ItemSpawnZombie();
|
||||||
|
public static final Item SPAWN_DUMMY = new ItemSpawnDummy();
|
||||||
|
public static final Item ROCK = new ItemRock();
|
||||||
|
public static final Item FLINT = new ItemFlint();
|
||||||
|
public static final Item LOG = new ItemLog();
|
||||||
|
public static final Item ACORN = new ItemAcorn();
|
||||||
|
public static final Item HEMP_SEED = new ItemHempSeed();
|
||||||
|
public static final Item PLANT_FIBRE = new ItemPlantFibre();
|
||||||
|
public static final Item CAMPFIRE = new ItemCampfire();
|
||||||
|
public static final Item FLINT_HATCHET = new ItemFlintHatchet();
|
||||||
|
public static final Item INFESTATION = new ItemInfestation();
|
||||||
|
public static final Item CHARCOAL = new ItemCharcoal();
|
||||||
|
public static final Item ASH = new ItemAsh();
|
||||||
|
public static final Item WORKBENCH = new ItemWorkbench();
|
||||||
|
public static final Item STONE_SHOVEL = new ItemStoneShovel();
|
||||||
|
public static final Item STONE_PICK = new ItemStonePick();
|
||||||
|
public static final Item STONE_HATCHET = new ItemStoneHatchet();
|
||||||
|
public static final Item METAL = new ItemMetal();
|
||||||
|
public static final Item ORE = new ItemOre();
|
||||||
|
public static final Item BLAST_FURNACE = new ItemBlastFurnace();
|
||||||
|
public static final Item CLAY_POT = new ItemClayPot();
|
||||||
|
public static final Item CLAY_POT_WET = new ItemClayPotWet();
|
||||||
|
public static final Item TORCH = new ItemTorch();
|
||||||
|
public static final Item COAL = new ItemCoal();
|
||||||
|
public static final Item WOOD_PLANKS = new ItemWoodPlanks();
|
||||||
|
public static final Item WOOD_WALL = new ItemWoodWall();
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,46 @@
|
||||||
|
package projectzombie.init;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import projectzombie.world.layer.layergen.LayerGen;
|
||||||
|
import projectzombie.world.layer.layergen.LayerGenBossArena;
|
||||||
|
import projectzombie.world.layer.layergen.LayerGenCaves;
|
||||||
|
import projectzombie.world.layer.layergen.LayerGenEarth;
|
||||||
|
import projectzombie.world.layer.layergen.LayerGenLavaCaves;
|
||||||
|
|
||||||
|
public class LayerGenerators
|
||||||
|
{
|
||||||
|
private static final ArrayList<LayerGen> lgens = new ArrayList<LayerGen>();
|
||||||
|
|
||||||
|
private static void register(LayerGen lg) {
|
||||||
|
lg.id = lgens.size();
|
||||||
|
lgens.add(lg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void init()
|
||||||
|
{
|
||||||
|
register(EARTH);
|
||||||
|
register(CAVES);
|
||||||
|
register(LAVA_CAVES);
|
||||||
|
register(BOSS_ARENA);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static LayerGen loadFromID(int id) {
|
||||||
|
return lgens.get(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getLGID(LayerGen lg) {
|
||||||
|
for(int i=0;i<lgens.size();i++) {
|
||||||
|
LayerGen lgi = lgens.get(i);
|
||||||
|
if(lgi == lg) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final LayerGen EARTH = new LayerGenEarth();
|
||||||
|
public static final LayerGen CAVES = new LayerGenCaves();
|
||||||
|
public static final LayerGen LAVA_CAVES = new LayerGenLavaCaves();
|
||||||
|
public static final LayerGen BOSS_ARENA = new LayerGenBossArena();
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
package projectzombie.init;
|
||||||
|
|
||||||
|
import projectzombie.world.layer.Layer;
|
||||||
|
|
||||||
|
public class Layers
|
||||||
|
{
|
||||||
|
public static Layer EARTH;
|
||||||
|
public static Layer CAVES;
|
||||||
|
public static Layer LAVA_CAVES;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,243 @@
|
||||||
|
package projectzombie.init;
|
||||||
|
|
||||||
|
import gl_engine.vec.Vec2d;
|
||||||
|
import projectzombie.model.Model;
|
||||||
|
import projectzombie.model.ModelBox;
|
||||||
|
import projectzombie.model.ModelCactus;
|
||||||
|
import projectzombie.model.ModelChunkBorder;
|
||||||
|
import projectzombie.model.ModelCross;
|
||||||
|
import projectzombie.model.ModelEmpty;
|
||||||
|
import projectzombie.model.ModelGrass;
|
||||||
|
import projectzombie.model.ModelGui;
|
||||||
|
import projectzombie.model.ModelItem;
|
||||||
|
import projectzombie.model.ModelPlayer;
|
||||||
|
import projectzombie.model.ModelRandom;
|
||||||
|
import projectzombie.model.ModelRock;
|
||||||
|
import projectzombie.model.ModelTallGrass;
|
||||||
|
import projectzombie.model.ModelTile;
|
||||||
|
import projectzombie.model.ModelTileBorder;
|
||||||
|
import projectzombie.model.ModelTree;
|
||||||
|
import projectzombie.model.ModelTreeSnow;
|
||||||
|
import projectzombie.model.ModelVertical;
|
||||||
|
import projectzombie.model.ModelWall;
|
||||||
|
|
||||||
|
public class Models
|
||||||
|
{
|
||||||
|
public static final Model EMPTY = new ModelEmpty();
|
||||||
|
public static final Model TILE_MISSING = new ModelTile(Resources.TEX_EMPTY);
|
||||||
|
public static final Model TILE_BORDER = new ModelTileBorder();
|
||||||
|
|
||||||
|
public static final Model TILE_TALL_GRASS = new ModelTallGrass();
|
||||||
|
public static final Model TILE_GRASS = new ModelGrass();
|
||||||
|
public static final Model TILE_TREE = new ModelTree();
|
||||||
|
public static final Model TILE_TREE_SNOW = new ModelTreeSnow();
|
||||||
|
|
||||||
|
public static final Model TILE_CAMPFIRE_LIT = new ModelCross(Resources.ATLAS.get("/tile/campfire_lit.png"), 4, 20);
|
||||||
|
public static final Model TILE_CAMPFIRE_UNLIT = new ModelCross(Resources.ATLAS.get("/tile/campfire_unlit.png"));
|
||||||
|
public static final Model TILE_BLAST_FURNACE = new ModelBox(Resources.ATLAS.get("/tile/blast_furnace.png"));
|
||||||
|
public static final Model TILE_WORKBENCH = new ModelBox(Resources.ATLAS.get("/tile/workbench.png"));
|
||||||
|
public static final Model TILE_CLAY_POT_EMPTY = new ModelBox(Resources.ATLAS.get("/tile/clay_pot_empty.png"));
|
||||||
|
public static final Model TILE_CLAY_POT_WATER_1 = new ModelBox(Resources.ATLAS.get("/tile/clay_pot_water_1.png"));
|
||||||
|
public static final Model TILE_CLAY_POT_WATER_2 = new ModelBox(Resources.ATLAS.get("/tile/clay_pot_water_2.png"));
|
||||||
|
public static final Model TILE_CLAY_POT_WATER_3 = new ModelBox(Resources.ATLAS.get("/tile/clay_pot_water_3.png"));
|
||||||
|
|
||||||
|
public static final Model TILE_SAPLING_1 = new ModelCross(Resources.ATLAS.get("/tile/sapling1.png"));
|
||||||
|
public static final Model TILE_SAPLING_2 = new ModelCross(Resources.ATLAS.get("/tile/sapling2.png"));
|
||||||
|
public static final Model TILE_SAPLING_3 = new ModelCross(Resources.ATLAS.get("/tile/sapling3.png"));
|
||||||
|
public static final Model TILE_SAPLING_4 = new ModelCross(Resources.ATLAS.get("/tile/sapling4.png"));
|
||||||
|
|
||||||
|
public static final Model TILE_CACTUS_1 = new ModelCactus(Resources.ATLAS.get("/tile/cactus1.png"), 0.5);
|
||||||
|
public static final Model TILE_CACTUS_2 = new ModelCactus(Resources.ATLAS.get("/tile/cactus2.png"), 1.0);
|
||||||
|
public static final Model TILE_CACTUS_3 = new ModelCactus(Resources.ATLAS.get("/tile/cactus3.png"), 1.5);
|
||||||
|
public static final Model TILE_CACTUS_4 = new ModelCactus(Resources.ATLAS.get("/tile/cactus4.png"), 2.0);
|
||||||
|
|
||||||
|
public static final Model[] TILE_HEMP = new Model[] {
|
||||||
|
new ModelBox(Resources.ATLAS.get("/tile/hemp1.png")),
|
||||||
|
new ModelBox(Resources.ATLAS.get("/tile/hemp2.png")),
|
||||||
|
new ModelBox(Resources.ATLAS.get("/tile/hemp3.png")),
|
||||||
|
new ModelBox(Resources.ATLAS.get("/tile/hemp4.png")),
|
||||||
|
new ModelBox(Resources.ATLAS.get("/tile/hemp5.png"), new Vec2d(1, 2)),
|
||||||
|
new ModelBox(Resources.ATLAS.get("/tile/hemp6.png"), new Vec2d(1, 2)),
|
||||||
|
new ModelBox(Resources.ATLAS.get("/tile/hemp7.png"), new Vec2d(1, 2)),
|
||||||
|
new ModelBox(Resources.ATLAS.get("/tile/hemp8.png"), new Vec2d(1, 2)),
|
||||||
|
};
|
||||||
|
|
||||||
|
public static final Model TILE_SNOW = new ModelTile(Resources.ATLAS.get("/tile/snow.png"));
|
||||||
|
public static final Model TILE_ICE = new ModelTile(Resources.ATLAS.get("/tile/ice.png"));
|
||||||
|
public static final Model TILE_ICE_WALL = new ModelTile(Resources.ATLAS.get("/tile/ice_wall.png"));
|
||||||
|
public static final Model TILE_SANDSTONE = new ModelTile(Resources.ATLAS.get("/tile/sandstone.png"));
|
||||||
|
public static final Model TILE_SANDSTONE_WALL = new ModelTile(Resources.ATLAS.get("/tile/sandstone_wall.png"));
|
||||||
|
public static final Model TILE_GRASS_INFESTED = new ModelTile(Resources.ATLAS.get("/tile/grass_infested.png"));
|
||||||
|
public static final Model TILE_GRASS_BURNT = new ModelTile(Resources.ATLAS.get("/tile/grass_burnt.png"));
|
||||||
|
public static final Model TILE_SAND = new ModelTile(Resources.ATLAS.get("/tile/sand.png"));
|
||||||
|
public static final Model TILE_STONE = new ModelTile(Resources.ATLAS.get("/tile/stone.png"));
|
||||||
|
public static final Model TILE_DIRT = new ModelTile(Resources.ATLAS.get("/tile/dirt.png"));
|
||||||
|
public static final Model TILE_ROCK = new ModelRock(Resources.ATLAS.get("/tile/rock.png"));
|
||||||
|
public static final Model TILE_ROCK_ICE = new ModelRock(Resources.ATLAS.get("/tile/rock_ice.png"));
|
||||||
|
public static final Model TILE_ROCK_SANDSTONE = new ModelRock(Resources.ATLAS.get("/tile/rock_sandstone.png"));
|
||||||
|
public static final Model TILE_LADDER = new ModelVertical(Resources.ATLAS.get("/tile/ladder.png"));
|
||||||
|
public static final Model TILE_PORTAL = new ModelTile(Resources.ATLAS.get("/tile/tunnel_down.png"));
|
||||||
|
public static final Model TILE_WALL = new ModelTile(Resources.ATLAS.get("/tile/wall.png"));
|
||||||
|
public static final Model TILE_LADDER_UP = new ModelVertical(Resources.ATLAS.get("/tile/ladder_up.png"), new Vec2d(1, 16));
|
||||||
|
public static final Model TILE_CHEST = new ModelVertical(Resources.ATLAS.get("/tile/chest.png"));
|
||||||
|
public static final Model TILE_BOSS_PORTAL = new ModelVertical(Resources.ATLAS.get("/tile/boss_portal.png"), new Vec2d(2, 2));
|
||||||
|
public static final Model TILE_WATER = new ModelTile(Resources.ATLAS.get("/tile/water.png"), 16, 10);
|
||||||
|
public static final Model TILE_LAVA = new ModelTile(Resources.ATLAS.get("/tile/lava.png"), 16, 50);
|
||||||
|
public static final Model TILE_LAVA_FLOW = new ModelTile(Resources.ATLAS.get("/tile/lava_flow.png"), 16, 50);
|
||||||
|
public static final Model TILE_LANTERN = new ModelVertical(Resources.ATLAS.get("/tile/lantern.png"), 4, 5);
|
||||||
|
public static final Model TILE_ROCK_IRON = new ModelRock(Resources.ATLAS.get("/tile/rock_iron.png"));
|
||||||
|
public static final Model TILE_ROCK_GOLD = new ModelRock(Resources.ATLAS.get("/tile/rock_gold.png"));
|
||||||
|
public static final Model TILE_ROCK_TIN = new ModelRock(Resources.ATLAS.get("/tile/rock_tin.png"));
|
||||||
|
public static final Model TILE_ROCK_COPPER = new ModelRock(Resources.ATLAS.get("/tile/rock_copper.png"));
|
||||||
|
public static final Model TILE_ROCK_COAL = new ModelRock(Resources.ATLAS.get("/tile/rock_coal.png"));
|
||||||
|
public static final Model TILE_ROCK_URANIUM = new ModelRock(Resources.ATLAS.get("/tile/rock_uranium.png"));
|
||||||
|
|
||||||
|
public static final Model TILE_WOOD_FLOOR = new ModelTile(Resources.ATLAS.get("/tile/wood_floor.png"));
|
||||||
|
public static final Model TILE_WOOD_SNOW_FLOOR = new ModelTile(Resources.ATLAS.get("/tile/wood_snow_floor.png"));
|
||||||
|
|
||||||
|
public static final Model[] TILE_WOOD_WALL = ModelWall.rotationArray(
|
||||||
|
Resources.ATLAS.get("/tile/wood_wall_front.png"),
|
||||||
|
Resources.ATLAS.get("/tile/wood_wall_top.png"),
|
||||||
|
Resources.ATLAS.get("/tile/wood_wall_side.png"));
|
||||||
|
|
||||||
|
public static final Model[] TILE_WOOD_SNOW_WALL = ModelWall.rotationArray(
|
||||||
|
Resources.ATLAS.get("/tile/wood_snow_wall_front.png"),
|
||||||
|
Resources.ATLAS.get("/tile/wood_snow_wall_top.png"),
|
||||||
|
Resources.ATLAS.get("/tile/wood_snow_wall_side.png"));
|
||||||
|
|
||||||
|
public static final Model ENTITY_BOSS_IDLE = new ModelVertical(Resources.ATLAS.get("/entity/boss1/boss_still.png"), new Vec2d(4, 4));
|
||||||
|
public static final Model ENTITY_BOSS_FIRING = new ModelVertical(Resources.ATLAS.get("/entity/boss1/boss_firing.png"), new Vec2d(4, 4), 4, 50);
|
||||||
|
public static final Model ENTITY_BOSS_WALKING = new ModelVertical(Resources.ATLAS.get("/entity/boss1/boss_walking.png"), new Vec2d(4, 4), 4, 50);
|
||||||
|
public static final Model ENTITY_BOSS_WALKING_AND_FIRING = new ModelVertical(Resources.ATLAS.get("/entity/boss1/boss_walking_firing.png"), new Vec2d(4, 4), 4, 50);
|
||||||
|
public static final Model ENTITY_TNT = new ModelVertical(Resources.ATLAS.get("/entity/tnt.png"), new Vec2d(0.5, 0.5));
|
||||||
|
public static final Model ENTITY_FLARE = new ModelVertical(Resources.ATLAS.get("/entity/flare.png"), new Vec2d(0.5, 0.5));
|
||||||
|
public static final Model ENTITY_DUMMY = new ModelVertical(Resources.ATLAS.get("/entity/dummy.png"));
|
||||||
|
public static final Model ENTITY_GRAPPLING_HOOK = new ModelVertical(Resources.ATLAS.get("/entity/grappling_hook.png"));
|
||||||
|
|
||||||
|
public static final Model PARTICLE_BLOOD = new ModelVertical(Resources.ATLAS.get("/particle/blood.png"), new Vec2d(1, 1));
|
||||||
|
public static final Model PARTICLE_WATER = new ModelVertical(Resources.ATLAS.get("/particle/water.png"), new Vec2d(1, 1));
|
||||||
|
public static final Model PARTICLE_SMOKE_TRAIL = new ModelVertical(Resources.ATLAS.get("/particle/smoke_trail.png"), new Vec2d(1, 1));
|
||||||
|
|
||||||
|
|
||||||
|
public static final ModelRandom PARTICLE_SMOKE_RANDOM = new ModelRandom(
|
||||||
|
new ModelVertical(Resources.ATLAS.get("/particle/smoke_0.png")),
|
||||||
|
new ModelVertical(Resources.ATLAS.get("/particle/smoke_1.png")),
|
||||||
|
new ModelVertical(Resources.ATLAS.get("/particle/smoke_2.png")),
|
||||||
|
new ModelVertical(Resources.ATLAS.get("/particle/smoke_3.png")),
|
||||||
|
new ModelVertical(Resources.ATLAS.get("/particle/smoke_4.png")),
|
||||||
|
new ModelVertical(Resources.ATLAS.get("/particle/smoke_5.png")));
|
||||||
|
|
||||||
|
public static final ModelGui UI_PIXEL_WHITE = new ModelGui(Resources.ATLAS.get("/gui/pixel_white.png"));
|
||||||
|
public static final ModelGui UI_PIXEL_BLACK = new ModelGui(Resources.ATLAS.get("/gui/pixel_black.png"));
|
||||||
|
public static final ModelGui UI_BUTTON = new ModelGui(Resources.ATLAS.get("/gui/button_normal.png"), new Vec2d(12, 1.5));
|
||||||
|
public static final ModelGui UI_BUTTON_HOVER = new ModelGui(Resources.ATLAS.get("/gui/button_hover.png"), new Vec2d(12, 1.5));
|
||||||
|
public static final ModelGui UI_BUTTON_DELETE = new ModelGui(Resources.ATLAS.get("/gui/button_delete.png"), new Vec2d(1.875, 1.875));
|
||||||
|
public static final ModelGui UI_BUTTON_DELETE_HOVER = new ModelGui(Resources.ATLAS.get("/gui/button_delete_hover.png"), new Vec2d(1.875, 1.875));
|
||||||
|
public static final ModelGui UI_BUTTON_PLAY = new ModelGui(Resources.ATLAS.get("/gui/button_play.png"), new Vec2d(1.875, 1.875));
|
||||||
|
public static final ModelGui UI_BUTTON_PLAY_HOVER = new ModelGui(Resources.ATLAS.get("/gui/button_play_hover.png"), new Vec2d(1.875, 1.875));
|
||||||
|
public static final ModelGui UI_LABEL = new ModelGui(Resources.ATLAS.get("/gui/label.png"), new Vec2d(24, 3));
|
||||||
|
public static final ModelGui UI_LABEL_RECIPE = new ModelGui(Resources.ATLAS.get("/gui/label_recipe.png"), new Vec2d(12, 3));
|
||||||
|
public static final ModelGui UI_TEXT_BOX = new ModelGui(Resources.ATLAS.get("/gui/text_box.png"), new Vec2d(12, 1.5));
|
||||||
|
public static final ModelGui UI_TEXT_CURSOR = new ModelGui(Resources.ATLAS.get("/gui/text_cursor.png"), 2, 50);
|
||||||
|
|
||||||
|
public static final ModelGui UI_SELECTION_BOX_WIDE = new ModelGui(Resources.ATLAS.get("/gui/selection_box_wide.png"), new Vec2d(24, 12));
|
||||||
|
public static final ModelGui UI_SELECTION_BOX_CRAFTING = new ModelGui(Resources.ATLAS.get("/gui/selection_box_crafting.png"), new Vec2d(12, 12));
|
||||||
|
public static final ModelGui UI_SELECTION_BOX_STORAGE = new ModelGui(Resources.ATLAS.get("/gui/selection_box_storage.png"), new Vec2d(12, 12));
|
||||||
|
public static final ModelGui UI_ITEM_SLOT_STORAGE = new ModelGui(Resources.ATLAS.get("/gui/item_slot_storage.png"), new Vec2d(1.5, 1.5));
|
||||||
|
|
||||||
|
public static final ModelGui UI_HEALTH_FG = new ModelGui(Resources.ATLAS.get("/gui/health_full.png"), new Vec2d(6, 0.375));
|
||||||
|
public static final ModelGui UI_HEALTH_BG = new ModelGui(Resources.ATLAS.get("/gui/health_empty.png"), new Vec2d(6, 0.375));
|
||||||
|
public static final ModelGui UI_ITEM_SLOTS = new ModelGui(Resources.ATLAS.get("/gui/hotbar.png"), new Vec2d(15, 1.5));
|
||||||
|
public static final ModelGui UI_ACTIVE_SLOT = new ModelGui(Resources.ATLAS.get("/gui/hotbar_selected.png"), new Vec2d(1.5, 1.5));
|
||||||
|
public static final ModelGui UI_INVENTORY = new ModelGui(Resources.ATLAS.get("/gui/inventory.png"), new Vec2d(12, 12));
|
||||||
|
public static final ModelGui UI_TEMPERATURE = new ModelGui(Resources.ATLAS.get("/gui/temperature.png"), new Vec2d(0.75, 0.75));
|
||||||
|
public static final ModelGui UI_WATER = new ModelGui(Resources.ATLAS.get("/gui/water.png"), new Vec2d(0.75, 0.75));
|
||||||
|
public static final ModelGui UI_ITEM_HOVER = new ModelGui(Resources.ATLAS.get("/gui/pixel_black.png")).setOpacity(0.25);
|
||||||
|
public static final ModelGui UI_TEXT_BG = new ModelGui(Resources.ATLAS.get("/gui/pixel_white.png")).setColor(0.5f, 0.5f, 0.5f);
|
||||||
|
public static final ModelGui UI_STONE_BG = new ModelGui(Resources.ATLAS.get("/tile/stone.png"));
|
||||||
|
|
||||||
|
public static final ModelItem UI_SLOT_ARMOR_HELMET = new ModelItem(Resources.ATLAS.get("/gui/slot_armor_helmet.png"));
|
||||||
|
public static final ModelItem UI_SLOT_ARMOR_CHEST = new ModelItem(Resources.ATLAS.get("/gui/slot_armor_chest.png"));
|
||||||
|
public static final ModelItem UI_SLOT_ARMOR_LEGS = new ModelItem(Resources.ATLAS.get("/gui/slot_armor_legs.png"));
|
||||||
|
public static final ModelItem UI_SLOT_CLOTHING_SHIRT = new ModelItem(Resources.ATLAS.get("/gui/slot_clothing_shirt.png"));
|
||||||
|
public static final ModelItem UI_SLOT_CLOTHING_PANTS = new ModelItem(Resources.ATLAS.get("/gui/slot_clothing_pants.png"));
|
||||||
|
public static final ModelItem UI_SLOT_CLOTHING_BOOTS = new ModelItem(Resources.ATLAS.get("/gui/slot_clothing_boots.png"));
|
||||||
|
|
||||||
|
public static final ModelItem ITEM_EMPTY = ModelItem.createEmpty();
|
||||||
|
public static final ModelItem ITEM_MISSING = new ModelItem(Resources.TEX_EMPTY);
|
||||||
|
public static final ModelItem ITEM_CAMPFIRE = new ModelItem(Resources.ATLAS.get("/tile/campfire_unlit.png"));
|
||||||
|
public static final ModelItem ITEM_BLAST_FURNACE = new ModelItem(Resources.ATLAS.get("/item/blast_furnace.png"));
|
||||||
|
public static final ModelItem ITEM_WORKBENCH = new ModelItem(Resources.ATLAS.get("/item/workbench.png"));
|
||||||
|
public static final ModelItem ITEM_GRAPPLING_HOOK = new ModelItem(Resources.ATLAS.get("/item/grappling_hook.png"));
|
||||||
|
public static final ModelItem ITEM_HEALTH_POTION = new ModelItem(Resources.ATLAS.get("/item/health_potion.png"));
|
||||||
|
public static final ModelItem ITEM_AMMO_BOX = new ModelItem(Resources.ATLAS.get("/item/ammo_box.png"));
|
||||||
|
public static final ModelItem ITEM_TNT = new ModelItem(Resources.ATLAS.get("/entity/tnt.png"));
|
||||||
|
public static final ModelItem ITEM_FLARE = new ModelItem(Resources.ATLAS.get("/entity/flare.png"));
|
||||||
|
public static final ModelItem ITEM_LANTERN = new ModelItem(Resources.ATLAS.get("/tile/lantern.png"), 4, 5);
|
||||||
|
public static final ModelItem ITEM_TORCH_LIT = new ModelItem(Resources.ATLAS.get("/item/torch_lit.png"), 4, 50);
|
||||||
|
public static final ModelItem ITEM_TORCH_UNLIT = new ModelItem(Resources.ATLAS.get("/item/torch_unlit.png"));
|
||||||
|
|
||||||
|
public static final ModelItem ITEM_CLAY_POT_WET = new ModelItem(Resources.ATLAS.get("/item/clay_pot_wet.png"));
|
||||||
|
public static final ModelItem ITEM_CLAY_POT_EMPTY = new ModelItem(Resources.ATLAS.get("/item/clay_pot_empty.png"));
|
||||||
|
public static final ModelItem ITEM_CLAY_POT_WATER_1 = new ModelItem(Resources.ATLAS.get("/item/clay_pot_water1.png"));
|
||||||
|
public static final ModelItem ITEM_CLAY_POT_WATER_2 = new ModelItem(Resources.ATLAS.get("/item/clay_pot_water2.png"));
|
||||||
|
public static final ModelItem ITEM_CLAY_POT_WATER_3 = new ModelItem(Resources.ATLAS.get("/item/clay_pot_water3.png"));
|
||||||
|
|
||||||
|
public static final ModelItem ITEM_FLINT_HATCHET = new ModelItem(Resources.ATLAS.get("/item/flint_hatchet.png"));
|
||||||
|
public static final ModelItem ITEM_STONE_HATCHET = new ModelItem(Resources.ATLAS.get("/item/stone_hatchet.png"));
|
||||||
|
public static final ModelItem ITEM_STONE_PICK = new ModelItem(Resources.ATLAS.get("/item/stone_pick.png"));
|
||||||
|
public static final ModelItem ITEM_STONE_SHOVEL = new ModelItem(Resources.ATLAS.get("/item/stone_shovel.png"));
|
||||||
|
|
||||||
|
public static final ModelItem ITEM_ORE_IRON = new ModelItem(Resources.ATLAS.get("/item/ore_iron.png"));
|
||||||
|
public static final ModelItem ITEM_ORE_COPPER = new ModelItem(Resources.ATLAS.get("/item/ore_copper.png"));
|
||||||
|
public static final ModelItem ITEM_ORE_TIN = new ModelItem(Resources.ATLAS.get("/item/ore_tin.png"));
|
||||||
|
public static final ModelItem ITEM_ORE_GOLD = new ModelItem(Resources.ATLAS.get("/item/ore_gold.png"));
|
||||||
|
|
||||||
|
public static final ModelItem ITEM_SPAWN_ZOMBIE = new ModelItem(Resources.ATLAS.get("/entity/zombie_front_moving.png"), 4, 10);
|
||||||
|
public static final ModelItem ITEM_SPAWN_DUMMY = new ModelItem(Resources.ATLAS.get("/entity/dummy.png"));
|
||||||
|
|
||||||
|
public static final ModelItem ITEM_ROCK = new ModelItem(Resources.ATLAS.get("/item/rock.png"));
|
||||||
|
public static final ModelItem ITEM_SNOW_PILE = new ModelItem(Resources.ATLAS.get("/item/snow_pile.png"));
|
||||||
|
public static final ModelItem ITEM_SANDSTONE = new ModelItem(Resources.ATLAS.get("/item/sandstone.png"));
|
||||||
|
public static final ModelItem ITEM_FLINT = new ModelItem(Resources.ATLAS.get("/item/flint.png"));
|
||||||
|
public static final ModelItem ITEM_CLAY = new ModelItem(Resources.ATLAS.get("/item/clay.png"));
|
||||||
|
public static final ModelItem ITEM_IRON = new ModelItem(Resources.ATLAS.get("/item/iron.png"));
|
||||||
|
public static final ModelItem ITEM_COPPER = new ModelItem(Resources.ATLAS.get("/item/copper.png"));
|
||||||
|
public static final ModelItem ITEM_TIN = new ModelItem(Resources.ATLAS.get("/item/tin.png"));
|
||||||
|
public static final ModelItem ITEM_GOLD = new ModelItem(Resources.ATLAS.get("/item/gold.png"));
|
||||||
|
public static final ModelItem ITEM_SLAG = new ModelItem(Resources.ATLAS.get("/item/slag.png"));
|
||||||
|
public static final ModelItem ITEM_COAL = new ModelItem(Resources.ATLAS.get("/item/coal.png"));
|
||||||
|
|
||||||
|
public static final ModelItem ITEM_PLANT_FIBRE = new ModelItem(Resources.ATLAS.get("/item/plant_fibre.png"));
|
||||||
|
public static final ModelItem ITEM_HEMP_SEED = new ModelItem(Resources.ATLAS.get("/item/hemp_seed.png"));
|
||||||
|
public static final ModelItem ITEM_ACORN = new ModelItem(Resources.ATLAS.get("/item/acorn.png"));
|
||||||
|
public static final ModelItem ITEM_LOG = new ModelItem(Resources.ATLAS.get("/item/log.png"));
|
||||||
|
public static final ModelItem ITEM_LOG_SNOW = new ModelItem(Resources.ATLAS.get("/item/log_snow.png"));
|
||||||
|
public static final ModelItem ITEM_CHARCOAL = new ModelItem(Resources.ATLAS.get("/item/charcoal.png"));
|
||||||
|
public static final ModelItem ITEM_ASH = new ModelItem(Resources.ATLAS.get("/item/ash.png"));
|
||||||
|
public static final ModelItem ITEM_WOOD_WALL = new ModelItem(Resources.ATLAS.get("/item/wood_wall.png"));
|
||||||
|
public static final ModelItem ITEM_WOOD_SNOW_WALL = new ModelItem(Resources.ATLAS.get("/item/wood_snow_wall.png"));
|
||||||
|
public static final ModelItem ITEM_WOOD_PLANKS = new ModelItem(Resources.ATLAS.get("/item/wood_planks.png"));
|
||||||
|
public static final ModelItem ITEM_WOOD_SNOW_PLANKS = new ModelItem(Resources.ATLAS.get("/item/wood_snow_planks.png"));
|
||||||
|
|
||||||
|
// Player varients
|
||||||
|
public static final ModelPlayer ENTITY_PLAYER_W = new ModelPlayer(
|
||||||
|
Resources.ATLAS.get("/player/player_white_back_still.png"),
|
||||||
|
Resources.ATLAS.get("/player/player_white_back_moving.png"),
|
||||||
|
Resources.ATLAS.get("/player/player_white_front_still.png"),
|
||||||
|
Resources.ATLAS.get("/player/player_white_front_moving.png"));
|
||||||
|
|
||||||
|
public static final ModelPlayer ENTITY_PLAYER_B = new ModelPlayer(
|
||||||
|
Resources.ATLAS.get("/player/player_black_back_still.png"),
|
||||||
|
Resources.ATLAS.get("/player/player_black_back_moving.png"),
|
||||||
|
Resources.ATLAS.get("/player/player_black_front_still.png"),
|
||||||
|
Resources.ATLAS.get("/player/player_black_front_moving.png"));
|
||||||
|
|
||||||
|
|
||||||
|
public static final Model ENTITY_ZOMBIE_B = new ModelVertical(Resources.ATLAS.get("/entity/zombie_back_moving.png"), 4, 10);
|
||||||
|
public static final Model ENTITY_ZOMBIE_F = new ModelVertical(Resources.ATLAS.get("/entity/zombie_front_moving.png"), 4, 10);
|
||||||
|
public static final Model ENTITY_ZOMBIE_B_ARMORED = new ModelVertical(Resources.ATLAS.get("/entity/armored_zombie_back_moving.png"), 4, 10);
|
||||||
|
public static final Model ENTITY_ZOMBIE_F_ARMORED = new ModelVertical(Resources.ATLAS.get("/entity/armored_zombie_front_moving.png"), 4, 10);
|
||||||
|
|
||||||
|
public static final ModelChunkBorder CHUNK_BORDER = new ModelChunkBorder();
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,138 @@
|
||||||
|
package projectzombie.init;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import projectzombie.inventory.Crafting;
|
||||||
|
import projectzombie.inventory.recipe.Recipe;
|
||||||
|
import projectzombie.inventory.recipe.RecipeBasic;
|
||||||
|
import projectzombie.items.modifier.ItemModifierDamage;
|
||||||
|
import projectzombie.items.modifier.ItemModifierMeta;
|
||||||
|
import projectzombie.util.ItemStack;
|
||||||
|
|
||||||
|
public class Recipes
|
||||||
|
{
|
||||||
|
public static ArrayList<Recipe> recipies;
|
||||||
|
|
||||||
|
public static Recipe[] getCraftableRecipies(Crafting tool)
|
||||||
|
{
|
||||||
|
int size = 0;
|
||||||
|
|
||||||
|
for(Recipe recipe : recipies) {
|
||||||
|
size += recipe.canCraft(tool) ? 1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int upto = 0;
|
||||||
|
Recipe[] craftable_recipies = new Recipe[size];
|
||||||
|
|
||||||
|
for(Recipe recipe : recipies)
|
||||||
|
{
|
||||||
|
if(recipe.canCraft(tool)) {
|
||||||
|
craftable_recipies[upto] = recipe;
|
||||||
|
upto += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return craftable_recipies;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void init()
|
||||||
|
{
|
||||||
|
recipies = new ArrayList<Recipe>();
|
||||||
|
|
||||||
|
// Basic crafting items
|
||||||
|
|
||||||
|
recipies.add(new RecipeBasic(
|
||||||
|
new ItemStack[] {
|
||||||
|
new ItemStack(Items.LOG, 1),
|
||||||
|
}, new Crafting[] {
|
||||||
|
Crafting.BASIC,
|
||||||
|
}, new ItemStack(Items.WOOD_PLANKS, 2)));
|
||||||
|
|
||||||
|
recipies.add(new RecipeBasic(
|
||||||
|
new ItemStack[] {
|
||||||
|
new ItemStack(Items.LOG, 2),
|
||||||
|
}, new Crafting[] {
|
||||||
|
Crafting.BASIC,
|
||||||
|
}, new ItemStack(Items.WOOD_WALL, 1)));
|
||||||
|
|
||||||
|
recipies.add(new RecipeBasic(
|
||||||
|
new ItemStack[] {
|
||||||
|
new ItemStack(Items.FLINT, 2),
|
||||||
|
new ItemStack(Items.PLANT_FIBRE, 5),
|
||||||
|
}, new Crafting[] {
|
||||||
|
Crafting.BASIC,
|
||||||
|
}, new ItemStack(Items.FLINT_HATCHET, 1)));
|
||||||
|
|
||||||
|
recipies.add(new RecipeBasic(
|
||||||
|
new ItemStack[] {
|
||||||
|
new ItemStack(Items.LOG, 12),
|
||||||
|
new ItemStack(Items.ROCK, 8, new ItemModifierMeta(0)),
|
||||||
|
}, new Crafting[] {
|
||||||
|
Crafting.BASIC,
|
||||||
|
}, new ItemStack(Items.CAMPFIRE, 1)));
|
||||||
|
|
||||||
|
recipies.add(new RecipeBasic(
|
||||||
|
new ItemStack[] {
|
||||||
|
new ItemStack(Items.LOG, 16),
|
||||||
|
new ItemStack(Items.ROCK, 4, new ItemModifierMeta(0)),
|
||||||
|
new ItemStack(Items.PLANT_FIBRE, 8),
|
||||||
|
}, new Crafting[] {
|
||||||
|
Crafting.BASIC,
|
||||||
|
}, new ItemStack(Items.WORKBENCH, 1)));
|
||||||
|
|
||||||
|
recipies.add(new RecipeBasic(
|
||||||
|
new ItemStack[] {
|
||||||
|
new ItemStack(Items.LOG, 1),
|
||||||
|
new ItemStack(Items.COAL, 1),
|
||||||
|
new ItemStack(Items.PLANT_FIBRE, 2),
|
||||||
|
}, new Crafting[] {
|
||||||
|
Crafting.BASIC,
|
||||||
|
}, new ItemStack(Items.TORCH, 1)));
|
||||||
|
|
||||||
|
|
||||||
|
// Workbench items
|
||||||
|
|
||||||
|
recipies.add(new RecipeBasic(
|
||||||
|
new ItemStack[] {
|
||||||
|
new ItemStack(Items.LOG, 4),
|
||||||
|
new ItemStack(Items.ROCK, 3, new ItemModifierMeta(0)),
|
||||||
|
new ItemStack(Items.PLANT_FIBRE, 3),
|
||||||
|
}, new Crafting[] {
|
||||||
|
Crafting.WOODEN_WORKBENCH,
|
||||||
|
}, new ItemStack(Items.STONE_PICK, 1)));
|
||||||
|
|
||||||
|
recipies.add(new RecipeBasic(
|
||||||
|
new ItemStack[] {
|
||||||
|
new ItemStack(Items.LOG, 4),
|
||||||
|
new ItemStack(Items.ROCK, 2, new ItemModifierMeta(0)),
|
||||||
|
new ItemStack(Items.PLANT_FIBRE, 3),
|
||||||
|
}, new Crafting[] {
|
||||||
|
Crafting.WOODEN_WORKBENCH,
|
||||||
|
}, new ItemStack(Items.STONE_SHOVEL, 1)));
|
||||||
|
|
||||||
|
recipies.add(new RecipeBasic(
|
||||||
|
new ItemStack[] {
|
||||||
|
new ItemStack(Items.LOG, 4),
|
||||||
|
new ItemStack(Items.ROCK, 3, new ItemModifierMeta(0)),
|
||||||
|
new ItemStack(Items.PLANT_FIBRE, 3),
|
||||||
|
}, new Crafting[] {
|
||||||
|
Crafting.WOODEN_WORKBENCH,
|
||||||
|
}, new ItemStack(Items.STONE_HATCHET, 1)));
|
||||||
|
|
||||||
|
recipies.add(new RecipeBasic(
|
||||||
|
new ItemStack[] {
|
||||||
|
new ItemStack(Items.ROCK, 8, new ItemModifierMeta(3)),
|
||||||
|
}, new Crafting[] {
|
||||||
|
Crafting.WOODEN_WORKBENCH,
|
||||||
|
}, new ItemStack(Items.CLAY_POT_WET, 1)));
|
||||||
|
|
||||||
|
recipies.add(new RecipeBasic(
|
||||||
|
new ItemStack[] {
|
||||||
|
new ItemStack(Items.ROCK, 32, new ItemModifierMeta(3)),
|
||||||
|
}, new Crafting[] {
|
||||||
|
Crafting.WOODEN_WORKBENCH,
|
||||||
|
}, new ItemStack(Items.BLAST_FURNACE, 1)));
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,65 @@
|
||||||
|
package projectzombie.init;
|
||||||
|
|
||||||
|
import gl_engine.texture.TextureAtlas3D;
|
||||||
|
import gl_engine.texture.TextureRef3D;
|
||||||
|
import projectzombie.resources.Resource;
|
||||||
|
|
||||||
|
public class Resources
|
||||||
|
{
|
||||||
|
public static void loadResources()
|
||||||
|
{
|
||||||
|
ATLAS = TextureAtlas3D.loadAll("/resources/texture/list.txt");
|
||||||
|
ATLAS.generate();
|
||||||
|
|
||||||
|
TEX_EMPTY = ATLAS.get("");
|
||||||
|
|
||||||
|
GUN_OGG_0.load();
|
||||||
|
GUN_OGG_1.load();
|
||||||
|
GUN_OGG_2.load();
|
||||||
|
GUN_OGG_3.load();
|
||||||
|
GUN_OGG_4.load();
|
||||||
|
GUN_OGG_5.load();
|
||||||
|
GUN_OGG_6.load();
|
||||||
|
GUN_OGG_7.load();
|
||||||
|
GUN_OGG_8.load();
|
||||||
|
GUN_OGG_9.load();
|
||||||
|
|
||||||
|
HIT_OGG_0.load();
|
||||||
|
HIT_OGG_1.load();
|
||||||
|
HIT_OGG_2.load();
|
||||||
|
|
||||||
|
WALK_STONE_0.load();
|
||||||
|
WALK_STONE_1.load();
|
||||||
|
WALK_STONE_2.load();
|
||||||
|
WALK_STONE_3.load();
|
||||||
|
|
||||||
|
EXPLOSION_OGG.load();
|
||||||
|
FUSE_OGG.load();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static TextureAtlas3D ATLAS;
|
||||||
|
public static TextureRef3D TEX_EMPTY;
|
||||||
|
|
||||||
|
public static final Resource GUN_OGG_0 = new Resource("/sound/gun0.ogg");
|
||||||
|
public static final Resource GUN_OGG_1 = new Resource("/sound/gun1.ogg");
|
||||||
|
public static final Resource GUN_OGG_2 = new Resource("/sound/gun2.ogg");
|
||||||
|
public static final Resource GUN_OGG_3 = new Resource("/sound/gun3.ogg");
|
||||||
|
public static final Resource GUN_OGG_4 = new Resource("/sound/gun4.ogg");
|
||||||
|
public static final Resource GUN_OGG_5 = new Resource("/sound/gun5.ogg");
|
||||||
|
public static final Resource GUN_OGG_6 = new Resource("/sound/gun6.ogg");
|
||||||
|
public static final Resource GUN_OGG_7 = new Resource("/sound/gun7.ogg");
|
||||||
|
public static final Resource GUN_OGG_8 = new Resource("/sound/gun8.ogg");
|
||||||
|
public static final Resource GUN_OGG_9 = new Resource("/sound/gun9.ogg");
|
||||||
|
|
||||||
|
public static final Resource HIT_OGG_0 = new Resource("/sound/hit0.ogg");
|
||||||
|
public static final Resource HIT_OGG_1 = new Resource("/sound/hit1.ogg");
|
||||||
|
public static final Resource HIT_OGG_2 = new Resource("/sound/hit2.ogg");
|
||||||
|
|
||||||
|
public static final Resource WALK_STONE_0 = new Resource("/sound/walk_stone_0.ogg");
|
||||||
|
public static final Resource WALK_STONE_1 = new Resource("/sound/walk_stone_1.ogg");
|
||||||
|
public static final Resource WALK_STONE_2 = new Resource("/sound/walk_stone_2.ogg");
|
||||||
|
public static final Resource WALK_STONE_3 = new Resource("/sound/walk_stone_3.ogg");
|
||||||
|
|
||||||
|
public static final Resource EXPLOSION_OGG = new Resource("/sound/explosion.ogg");
|
||||||
|
public static final Resource FUSE_OGG = new Resource("/sound/fuse.ogg");
|
||||||
|
}
|
||||||
34
src/shootergame/init/Sounds.java → src/projectzombie/init/Sounds.java
Normal file → Executable file
34
src/shootergame/init/Sounds.java → src/projectzombie/init/Sounds.java
Normal file → Executable file
|
|
@ -1,7 +1,7 @@
|
||||||
package shootergame.init;
|
package projectzombie.init;
|
||||||
|
|
||||||
import shootergame.audio.AudioObject;
|
import projectzombie.audio.AudioObject;
|
||||||
import shootergame.audio.AudioRandom;
|
import projectzombie.audio.AudioRandom;
|
||||||
|
|
||||||
public class Sounds
|
public class Sounds
|
||||||
{
|
{
|
||||||
|
|
@ -25,27 +25,27 @@ public class Sounds
|
||||||
EXPLOSION.init();
|
EXPLOSION.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final AudioObject GUN_0 = new AudioObject(Resources.GUN_OGG_0);
|
public static final AudioObject GUN_0 = new AudioObject(Resources.GUN_OGG_0, 1);
|
||||||
public static final AudioObject GUN_1 = new AudioObject(Resources.GUN_OGG_1);
|
public static final AudioObject GUN_1 = new AudioObject(Resources.GUN_OGG_1, 1);
|
||||||
public static final AudioObject GUN_2 = new AudioObject(Resources.GUN_OGG_2);
|
public static final AudioObject GUN_2 = new AudioObject(Resources.GUN_OGG_2, 1);
|
||||||
public static final AudioObject GUN_3 = new AudioObject(Resources.GUN_OGG_3);
|
public static final AudioObject GUN_3 = new AudioObject(Resources.GUN_OGG_3, 1);
|
||||||
public static final AudioObject GUN_4 = new AudioObject(Resources.GUN_OGG_4);
|
public static final AudioObject GUN_4 = new AudioObject(Resources.GUN_OGG_4, 1);
|
||||||
public static final AudioObject GUN_5 = new AudioObject(Resources.GUN_OGG_5);
|
public static final AudioObject GUN_5 = new AudioObject(Resources.GUN_OGG_5, 1);
|
||||||
public static final AudioObject GUN_6 = new AudioObject(Resources.GUN_OGG_6);
|
public static final AudioObject GUN_6 = new AudioObject(Resources.GUN_OGG_6, 1);
|
||||||
public static final AudioObject GUN_7 = new AudioObject(Resources.GUN_OGG_7);
|
public static final AudioObject GUN_7 = new AudioObject(Resources.GUN_OGG_7, 1);
|
||||||
public static final AudioObject GUN_8 = new AudioObject(Resources.GUN_OGG_8);
|
public static final AudioObject GUN_8 = new AudioObject(Resources.GUN_OGG_8, 1);
|
||||||
public static final AudioObject GUN_9 = new AudioObject(Resources.GUN_OGG_9);
|
public static final AudioObject GUN_9 = new AudioObject(Resources.GUN_OGG_9, 1);
|
||||||
|
|
||||||
public static final AudioObject GUN = new AudioRandom(
|
public static final AudioObject GUN = new AudioRandom(
|
||||||
GUN_0,GUN_1,GUN_2,GUN_3,GUN_4,
|
GUN_0,GUN_1,GUN_2,GUN_3,GUN_4,
|
||||||
GUN_5,GUN_6,GUN_7,GUN_8,GUN_9);
|
GUN_5,GUN_6,GUN_7,GUN_8,GUN_9);
|
||||||
|
|
||||||
public static final AudioObject HIT_0 = new AudioObject(Resources.HIT_OGG_0);
|
public static final AudioObject HIT_0 = new AudioObject(Resources.HIT_OGG_0, 1);
|
||||||
public static final AudioObject HIT_1 = new AudioObject(Resources.HIT_OGG_1);
|
public static final AudioObject HIT_1 = new AudioObject(Resources.HIT_OGG_1, 1);
|
||||||
public static final AudioObject HIT_2 = new AudioObject(Resources.HIT_OGG_2);
|
public static final AudioObject HIT_2 = new AudioObject(Resources.HIT_OGG_2, 1);
|
||||||
|
|
||||||
public static final AudioObject HIT = new AudioRandom(
|
public static final AudioObject HIT = new AudioRandom(
|
||||||
HIT_0, HIT_1, HIT_2);
|
HIT_0, HIT_1, HIT_2);
|
||||||
|
|
||||||
public static final AudioObject EXPLOSION = new AudioObject(Resources.EXPLOSION_OGG);
|
public static final AudioObject EXPLOSION = new AudioObject(Resources.EXPLOSION_OGG, 10);
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,34 @@
|
||||||
|
package projectzombie.init;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import bdf.types.BdfObject;
|
||||||
|
import projectzombie.entity.Entity;
|
||||||
|
import projectzombie.task.Task;
|
||||||
|
import projectzombie.task.TaskDeathScreen;
|
||||||
|
import projectzombie.task.TaskLadderDown;
|
||||||
|
import projectzombie.task.TaskLadderUp;
|
||||||
|
|
||||||
|
public class Tasks
|
||||||
|
{
|
||||||
|
public static final ArrayList<Class<? extends Task>> TASKS = new ArrayList<>();
|
||||||
|
|
||||||
|
private static void register(Class<? extends Task> t)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
t.getConstructor(Entity.class, BdfObject.class);
|
||||||
|
} catch (NoSuchMethodException | SecurityException err) {
|
||||||
|
err.printStackTrace();
|
||||||
|
System.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
TASKS.add(t);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void init()
|
||||||
|
{
|
||||||
|
register(TaskLadderDown.class);
|
||||||
|
register(TaskLadderUp.class);
|
||||||
|
register(TaskDeathScreen.class);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,133 @@
|
||||||
|
package projectzombie.init;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import projectzombie.tiles.Tile;
|
||||||
|
import projectzombie.tiles.TileBlastFurnace;
|
||||||
|
import projectzombie.tiles.TileBossPortal;
|
||||||
|
import projectzombie.tiles.TileCactus;
|
||||||
|
import projectzombie.tiles.TileCampfire;
|
||||||
|
import projectzombie.tiles.TileChest;
|
||||||
|
import projectzombie.tiles.TileClayPot;
|
||||||
|
import projectzombie.tiles.TileCoal;
|
||||||
|
import projectzombie.tiles.TileDirt;
|
||||||
|
import projectzombie.tiles.TileGrass;
|
||||||
|
import projectzombie.tiles.TileGrassBurnt;
|
||||||
|
import projectzombie.tiles.TileGrassInfested;
|
||||||
|
import projectzombie.tiles.TileHemp;
|
||||||
|
import projectzombie.tiles.TileIce;
|
||||||
|
import projectzombie.tiles.TileIceWall;
|
||||||
|
import projectzombie.tiles.TileLadder;
|
||||||
|
import projectzombie.tiles.TileLadderUp;
|
||||||
|
import projectzombie.tiles.TileLantern;
|
||||||
|
import projectzombie.tiles.TileLava;
|
||||||
|
import projectzombie.tiles.TileLavaFlow;
|
||||||
|
import projectzombie.tiles.TileOre;
|
||||||
|
import projectzombie.tiles.TilePortalDown;
|
||||||
|
import projectzombie.tiles.TileRock;
|
||||||
|
import projectzombie.tiles.TileSand;
|
||||||
|
import projectzombie.tiles.TileSandstone;
|
||||||
|
import projectzombie.tiles.TileSandstoneWall;
|
||||||
|
import projectzombie.tiles.TileSapling;
|
||||||
|
import projectzombie.tiles.TileSnow;
|
||||||
|
import projectzombie.tiles.TileStone;
|
||||||
|
import projectzombie.tiles.TileTallGrass;
|
||||||
|
import projectzombie.tiles.TileTree;
|
||||||
|
import projectzombie.tiles.TileVoid;
|
||||||
|
import projectzombie.tiles.TileWall;
|
||||||
|
import projectzombie.tiles.TileWater;
|
||||||
|
import projectzombie.tiles.TileWoodFloor;
|
||||||
|
import projectzombie.tiles.TileWoodWall;
|
||||||
|
import projectzombie.tiles.TileWorkbench;
|
||||||
|
|
||||||
|
public class Tiles
|
||||||
|
{
|
||||||
|
public static ArrayList<Tile> tiles = new ArrayList<Tile>();
|
||||||
|
|
||||||
|
private static void register(Tile tile)
|
||||||
|
{
|
||||||
|
int id = tiles.size();
|
||||||
|
|
||||||
|
if(id > Short.MAX_VALUE) {
|
||||||
|
throw new RuntimeException("Too many tiles registered. Maximum tiles: " + Short.MAX_VALUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
tile.id = (short)id;
|
||||||
|
tiles.add(tile);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void init() {
|
||||||
|
register(VOID);
|
||||||
|
register(GRASS);
|
||||||
|
register(SNOW);
|
||||||
|
register(SAND);
|
||||||
|
register(STONE);
|
||||||
|
register(DIRT);
|
||||||
|
register(TREE);
|
||||||
|
register(CACTUS);
|
||||||
|
register(ROCK);
|
||||||
|
register(LAVA);
|
||||||
|
register(WATER);
|
||||||
|
register(LAVA_FLOW);
|
||||||
|
register(LADDER);
|
||||||
|
register(PORTAL_DOWN);
|
||||||
|
register(WALL);
|
||||||
|
register(LADDER_UP);
|
||||||
|
register(CHEST);
|
||||||
|
register(LANTERN);
|
||||||
|
register(BOSS_PORTAL);
|
||||||
|
register(ICE);
|
||||||
|
register(ICE_WALL);
|
||||||
|
register(SANDSTONE);
|
||||||
|
register(SANDSTONE_WALL);
|
||||||
|
register(GRASS_INFESTED);
|
||||||
|
register(TALL_GRASS);
|
||||||
|
register(SAPLING);
|
||||||
|
register(CAMPFIRE);
|
||||||
|
register(GRASS_BURNT);
|
||||||
|
register(WORKBENCH);
|
||||||
|
register(BLAST_FURNACE);
|
||||||
|
register(CLAY_POT);
|
||||||
|
register(ORE);
|
||||||
|
register(COAL);
|
||||||
|
register(WOOD_FLOOR);
|
||||||
|
register(WOOD_WALL);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final Tile GRASS = new TileGrass();
|
||||||
|
public static final Tile SNOW = new TileSnow();
|
||||||
|
public static final Tile SAND = new TileSand();
|
||||||
|
public static final Tile STONE = new TileStone();
|
||||||
|
public static final Tile DIRT = new TileDirt();
|
||||||
|
public static final Tile CACTUS = new TileCactus();
|
||||||
|
public static final Tile TREE = new TileTree();
|
||||||
|
public static final Tile VOID = new TileVoid();
|
||||||
|
public static final Tile ROCK = new TileRock();
|
||||||
|
public static final Tile LAVA = new TileLava();
|
||||||
|
public static final Tile WATER = new TileWater();
|
||||||
|
public static final Tile LAVA_FLOW = new TileLavaFlow();
|
||||||
|
public static final Tile LADDER = new TileLadder();
|
||||||
|
public static final Tile PORTAL_DOWN = new TilePortalDown();
|
||||||
|
public static final Tile WALL = new TileWall();
|
||||||
|
public static final Tile LADDER_UP = new TileLadderUp();
|
||||||
|
public static final Tile CHEST = new TileChest();
|
||||||
|
public static final Tile LANTERN = new TileLantern();
|
||||||
|
public static final Tile BOSS_PORTAL = new TileBossPortal();
|
||||||
|
public static final Tile ICE = new TileIce();
|
||||||
|
public static final Tile ICE_WALL = new TileIceWall();
|
||||||
|
public static final Tile SANDSTONE = new TileSandstone();
|
||||||
|
public static final Tile SANDSTONE_WALL = new TileSandstoneWall();
|
||||||
|
public static final Tile GRASS_INFESTED = new TileGrassInfested();
|
||||||
|
public static final Tile TALL_GRASS = new TileTallGrass();
|
||||||
|
public static final Tile SAPLING = new TileSapling();
|
||||||
|
public static final Tile HEMP = new TileHemp();
|
||||||
|
public static final Tile CAMPFIRE = new TileCampfire();
|
||||||
|
public static final Tile GRASS_BURNT = new TileGrassBurnt();
|
||||||
|
public static final Tile WORKBENCH = new TileWorkbench();
|
||||||
|
public static final Tile BLAST_FURNACE = new TileBlastFurnace();
|
||||||
|
public static final Tile CLAY_POT = new TileClayPot();
|
||||||
|
public static final Tile ORE = new TileOre();
|
||||||
|
public static final Tile COAL = new TileCoal();
|
||||||
|
public static final Tile WOOD_FLOOR = new TileWoodFloor();
|
||||||
|
public static final Tile WOOD_WALL = new TileWoodWall();
|
||||||
|
}
|
||||||
2
src/shootergame/input/CursorEnterCallback.java → src/projectzombie/input/CursorEnterCallback.java
Normal file → Executable file
2
src/shootergame/input/CursorEnterCallback.java → src/projectzombie/input/CursorEnterCallback.java
Normal file → Executable file
|
|
@ -1,4 +1,4 @@
|
||||||
package shootergame.input;
|
package projectzombie.input;
|
||||||
|
|
||||||
import org.lwjgl.glfw.GLFWCursorEnterCallbackI;
|
import org.lwjgl.glfw.GLFWCursorEnterCallbackI;
|
||||||
|
|
||||||
|
|
@ -0,0 +1,41 @@
|
||||||
|
package projectzombie.input;
|
||||||
|
|
||||||
|
import org.lwjgl.glfw.GLFW;
|
||||||
|
import org.lwjgl.glfw.GLFWCursorPosCallbackI;
|
||||||
|
|
||||||
|
import gl_engine.vec.Vec2d;
|
||||||
|
import projectzombie.Main;
|
||||||
|
import projectzombie.util.gl.GlHelpers;
|
||||||
|
|
||||||
|
public class CursorPosCallback implements GLFWCursorPosCallbackI
|
||||||
|
{
|
||||||
|
public static double mx, my;
|
||||||
|
|
||||||
|
public static Vec2d getCursorPos() {
|
||||||
|
return new Vec2d(mx, my);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void invoke(long window, double x, double y)
|
||||||
|
{
|
||||||
|
Main.window.setMouseVisibility(!Main.menu.keepMouse);
|
||||||
|
InputMode.Controller = false;
|
||||||
|
|
||||||
|
int wx = Main.window.getWidth();
|
||||||
|
int wy = Main.window.getHeight();
|
||||||
|
|
||||||
|
mx = (x / Main.window.getWidth() * 20 - 10) * GlHelpers.getAspectRatio();
|
||||||
|
my = -y / Main.window.getHeight() * 20 + 10;
|
||||||
|
|
||||||
|
if(!Main.menu.keepMouse) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
x = (x / wx - 0.5);
|
||||||
|
y = (y / wy - 0.5);
|
||||||
|
|
||||||
|
Main.menu.input.camera(true, x * 60);
|
||||||
|
GLFW.glfwSetCursorPos(window, wx / 2, wy / 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,24 @@
|
||||||
|
package projectzombie.input;
|
||||||
|
|
||||||
|
class GameInput
|
||||||
|
{
|
||||||
|
static boolean activateItem_last = false;
|
||||||
|
static boolean activateTile_last = false;
|
||||||
|
static boolean dropItem_last = false;
|
||||||
|
static boolean move_last = false;
|
||||||
|
|
||||||
|
static boolean hotbar_l = false;
|
||||||
|
static boolean hotbar_r = false;
|
||||||
|
|
||||||
|
static boolean startButton_last = false;
|
||||||
|
static boolean backButton_last = false;
|
||||||
|
static boolean activate_last = false;
|
||||||
|
|
||||||
|
static boolean moveLeft = false;
|
||||||
|
static boolean moveRight = false;
|
||||||
|
static boolean moveUp = false;
|
||||||
|
static boolean moveDown = false;
|
||||||
|
|
||||||
|
static boolean buttonL = false;
|
||||||
|
static boolean buttonR = false;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
package projectzombie.input;
|
||||||
|
|
||||||
|
public class InputMode {
|
||||||
|
public static boolean Controller = false;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,279 @@
|
||||||
|
package projectzombie.input;
|
||||||
|
|
||||||
|
import static projectzombie.input.GameInput.activateItem_last;
|
||||||
|
import static projectzombie.input.GameInput.activate_last;
|
||||||
|
import static projectzombie.input.GameInput.backButton_last;
|
||||||
|
import static projectzombie.input.GameInput.dropItem_last;
|
||||||
|
import static projectzombie.input.GameInput.hotbar_l;
|
||||||
|
import static projectzombie.input.GameInput.hotbar_r;
|
||||||
|
import static projectzombie.input.GameInput.moveDown;
|
||||||
|
import static projectzombie.input.GameInput.moveUp;
|
||||||
|
import static projectzombie.input.GameInput.move_last;
|
||||||
|
import static projectzombie.input.GameInput.startButton_last;
|
||||||
|
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.FloatBuffer;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import org.lwjgl.glfw.GLFW;
|
||||||
|
import org.lwjgl.glfw.GLFWJoystickCallbackI;
|
||||||
|
|
||||||
|
import mainloop.task.IMainloopTask;
|
||||||
|
import projectzombie.Main;
|
||||||
|
import projectzombie.input.types.Input;
|
||||||
|
|
||||||
|
public class JoystickCallback implements GLFWJoystickCallbackI, IMainloopTask
|
||||||
|
{
|
||||||
|
public static final JoystickCallback JOYSTICK_CALLBACK = new JoystickCallback();
|
||||||
|
private ArrayList<Integer> connections = new ArrayList<Integer>();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void invoke(int jid, int event)
|
||||||
|
{
|
||||||
|
// Gamepad connect
|
||||||
|
if(event == GLFW.GLFW_CONNECTED)
|
||||||
|
{
|
||||||
|
// Log the event and add the connection
|
||||||
|
System.out.println("Gamepad "+jid+" connected");
|
||||||
|
connections.add(jid);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Gamepad disconnect
|
||||||
|
else if(event == GLFW.GLFW_DISCONNECTED)
|
||||||
|
{
|
||||||
|
// Log the event and remove the connection
|
||||||
|
System.out.println("Gamepad "+jid+" disconnected");
|
||||||
|
connections.remove((Object) jid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void init()
|
||||||
|
{
|
||||||
|
// Loop over all the gamepads
|
||||||
|
for(int i=0;i<=GLFW.GLFW_JOYSTICK_LAST;i++)
|
||||||
|
{
|
||||||
|
// Is this gamepad present; add the gamepad
|
||||||
|
if(GLFW.glfwJoystickPresent(i)) {
|
||||||
|
if(GLFW.glfwJoystickIsGamepad(i)) {
|
||||||
|
System.out.println("Gamepad "+i+" connected");
|
||||||
|
connections.add(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean MainLoopDelay(long millis) {
|
||||||
|
return millis > Main.tickrate;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean MainLoopRepeat() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private float combineJoystickAxis(float a, float b)
|
||||||
|
{
|
||||||
|
if(b > 0.3 || b < -0.3) a += b;
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void MainLoopUpdate()
|
||||||
|
{
|
||||||
|
// Gamepad properties
|
||||||
|
float left_x = 0;
|
||||||
|
float left_y = 0;
|
||||||
|
float left_trigger = 0;
|
||||||
|
float right_x = 0;
|
||||||
|
float right_y = 0;
|
||||||
|
float right_trigger = 0;
|
||||||
|
boolean left_stick_button = false;
|
||||||
|
boolean right_stick_button = false;
|
||||||
|
boolean button_a = false;
|
||||||
|
boolean button_b = false;
|
||||||
|
boolean button_x = false;
|
||||||
|
boolean button_y = false;
|
||||||
|
boolean button_start = false;
|
||||||
|
boolean button_back = false;
|
||||||
|
boolean button_home = false;
|
||||||
|
boolean dpad_up = false;
|
||||||
|
boolean dpad_down = false;
|
||||||
|
boolean dpad_left = false;
|
||||||
|
boolean dpad_right = false;
|
||||||
|
boolean shoulder_left = false;
|
||||||
|
boolean shoulder_right = false;
|
||||||
|
|
||||||
|
int jid2 = 0;
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Loop over all the connected gamepads
|
||||||
|
for(int jid : connections)
|
||||||
|
{
|
||||||
|
// Get all the axes
|
||||||
|
jid2 = jid;
|
||||||
|
FloatBuffer axes = GLFW.glfwGetJoystickAxes(jid);
|
||||||
|
|
||||||
|
// Store all the axes data
|
||||||
|
left_x = combineJoystickAxis(left_x, axes.get(0));
|
||||||
|
left_y = combineJoystickAxis(left_y, axes.get(1));
|
||||||
|
right_x = combineJoystickAxis(right_x, axes.get(3));
|
||||||
|
right_y = combineJoystickAxis(right_y, axes.get(4));
|
||||||
|
left_trigger = combineJoystickAxis(left_trigger, axes.get(2));
|
||||||
|
right_trigger = combineJoystickAxis(right_trigger, axes.get(5));
|
||||||
|
|
||||||
|
// Get all the buttons
|
||||||
|
ByteBuffer buttons = GLFW.glfwGetJoystickButtons(jid);
|
||||||
|
|
||||||
|
// Store all the button data
|
||||||
|
button_a = buttons.get(0) == 1 || button_a;
|
||||||
|
button_b = buttons.get(1) == 1 || button_b;
|
||||||
|
button_x = buttons.get(2) == 1 || button_x;
|
||||||
|
button_y = buttons.get(3) == 1 || button_y;
|
||||||
|
shoulder_left = buttons.get(4) == 1 || shoulder_left;
|
||||||
|
shoulder_right = buttons.get(5) == 1 || shoulder_right;
|
||||||
|
button_back = buttons.get(6) == 1 || button_back;
|
||||||
|
button_start = buttons.get(7) == 1 || button_start;
|
||||||
|
button_home = buttons.get(8) == 1 || button_home;
|
||||||
|
left_stick_button = buttons.get(9) == 1 || left_stick_button;
|
||||||
|
right_stick_button = buttons.get(10) == 1 || right_stick_button;
|
||||||
|
dpad_left = buttons.get(11) == 1 || dpad_left;
|
||||||
|
dpad_right = buttons.get(12) == 1 || dpad_right;
|
||||||
|
dpad_up = buttons.get(13) == 1 || dpad_up;
|
||||||
|
dpad_down = buttons.get(14) == 1 || dpad_down;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
catch(Exception e) {
|
||||||
|
connections.remove((Object) jid2);
|
||||||
|
System.err.println("Removed controller "+jid2+" due to "+e.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
Input input = Main.menu.input;
|
||||||
|
|
||||||
|
// Is the left stick moved into a position (movement stick)
|
||||||
|
if((left_x > 0.3 || left_x < -0.3 || left_y > 0.3 || left_y < -0.3) && !moveUp && !moveDown)
|
||||||
|
{
|
||||||
|
// Get the the angle
|
||||||
|
double angle = Math.toDegrees(Math.atan2(left_y, left_x)) + 90;
|
||||||
|
input.move(true, angle);
|
||||||
|
move_last = true;
|
||||||
|
|
||||||
|
InputMode.Controller = true;
|
||||||
|
Main.window.setMouseVisibility(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set the players moving to false
|
||||||
|
else if(move_last && !moveUp && !moveDown) {
|
||||||
|
move_last = false;
|
||||||
|
input.move(false, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Is the right x axis stick moved into a position (camera stick)
|
||||||
|
if(right_x > 0.3 || right_x < -0.3) {
|
||||||
|
input.camera(true, right_x);
|
||||||
|
InputMode.Controller = true;
|
||||||
|
Main.window.setMouseVisibility(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Gun trigger
|
||||||
|
if(right_trigger > 0.3) {
|
||||||
|
input.fire(true);
|
||||||
|
InputMode.Controller = true;
|
||||||
|
Main.window.setMouseVisibility(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Item trigger
|
||||||
|
if(left_trigger > 0.3) {
|
||||||
|
InputMode.Controller = true;
|
||||||
|
Main.window.setMouseVisibility(false);
|
||||||
|
input.itemAction(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
activateItem_last = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(shoulder_left) {
|
||||||
|
InputMode.Controller = true;
|
||||||
|
Main.window.setMouseVisibility(false);
|
||||||
|
if(!hotbar_l) {
|
||||||
|
hotbar_l = true;
|
||||||
|
input.hotbarShift(true, -1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else if(hotbar_l) {
|
||||||
|
hotbar_l = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(shoulder_right) {
|
||||||
|
InputMode.Controller = true;
|
||||||
|
Main.window.setMouseVisibility(false);
|
||||||
|
if(!hotbar_r) {
|
||||||
|
hotbar_r = true;
|
||||||
|
input.hotbarShift(true, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else if(hotbar_r) {
|
||||||
|
hotbar_r = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Activate button (A Button)
|
||||||
|
if(button_a) {
|
||||||
|
InputMode.Controller = true;
|
||||||
|
Main.window.setMouseVisibility(false);
|
||||||
|
if(!activate_last) {
|
||||||
|
input.activate(true);
|
||||||
|
activate_last = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else if(activate_last) {
|
||||||
|
activate_last = false;
|
||||||
|
input.activate(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Drop item
|
||||||
|
if(button_b) {
|
||||||
|
InputMode.Controller = true;
|
||||||
|
Main.window.setMouseVisibility(false);
|
||||||
|
if(!dropItem_last) {
|
||||||
|
input.itemDrop(true);
|
||||||
|
dropItem_last = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else if(dropItem_last) {
|
||||||
|
dropItem_last = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Back button
|
||||||
|
if(button_b) {
|
||||||
|
if(!backButton_last) {
|
||||||
|
input.back(true);
|
||||||
|
backButton_last = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else if(backButton_last) {
|
||||||
|
backButton_last = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pause the game
|
||||||
|
if(button_start) {
|
||||||
|
Main.window.setMouseVisibility(false);
|
||||||
|
InputMode.Controller = true;
|
||||||
|
if(!startButton_last) {
|
||||||
|
startButton_last = true;
|
||||||
|
input.pause(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else if(startButton_last) {
|
||||||
|
startButton_last = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,240 @@
|
||||||
|
package projectzombie.input;
|
||||||
|
|
||||||
|
import static org.lwjgl.glfw.GLFW.GLFW_KEY_0;
|
||||||
|
import static org.lwjgl.glfw.GLFW.GLFW_KEY_1;
|
||||||
|
import static org.lwjgl.glfw.GLFW.GLFW_KEY_2;
|
||||||
|
import static org.lwjgl.glfw.GLFW.GLFW_KEY_3;
|
||||||
|
import static org.lwjgl.glfw.GLFW.GLFW_KEY_4;
|
||||||
|
import static org.lwjgl.glfw.GLFW.GLFW_KEY_5;
|
||||||
|
import static org.lwjgl.glfw.GLFW.GLFW_KEY_6;
|
||||||
|
import static org.lwjgl.glfw.GLFW.GLFW_KEY_7;
|
||||||
|
import static org.lwjgl.glfw.GLFW.GLFW_KEY_8;
|
||||||
|
import static org.lwjgl.glfw.GLFW.GLFW_KEY_9;
|
||||||
|
import static org.lwjgl.glfw.GLFW.GLFW_KEY_A;
|
||||||
|
import static org.lwjgl.glfw.GLFW.GLFW_KEY_D;
|
||||||
|
import static org.lwjgl.glfw.GLFW.GLFW_KEY_E;
|
||||||
|
import static org.lwjgl.glfw.GLFW.GLFW_KEY_ESCAPE;
|
||||||
|
import static org.lwjgl.glfw.GLFW.GLFW_KEY_F11;
|
||||||
|
import static org.lwjgl.glfw.GLFW.GLFW_KEY_LEFT_CONTROL;
|
||||||
|
import static org.lwjgl.glfw.GLFW.GLFW_KEY_Q;
|
||||||
|
import static org.lwjgl.glfw.GLFW.GLFW_KEY_RIGHT_CONTROL;
|
||||||
|
import static org.lwjgl.glfw.GLFW.GLFW_KEY_S;
|
||||||
|
import static org.lwjgl.glfw.GLFW.GLFW_KEY_W;
|
||||||
|
import static org.lwjgl.glfw.GLFW.GLFW_RELEASE;
|
||||||
|
import static projectzombie.input.GameInput.backButton_last;
|
||||||
|
import static projectzombie.input.GameInput.buttonL;
|
||||||
|
import static projectzombie.input.GameInput.buttonR;
|
||||||
|
import static projectzombie.input.GameInput.moveDown;
|
||||||
|
import static projectzombie.input.GameInput.moveLeft;
|
||||||
|
import static projectzombie.input.GameInput.moveRight;
|
||||||
|
import static projectzombie.input.GameInput.moveUp;
|
||||||
|
import static projectzombie.input.GameInput.move_last;
|
||||||
|
|
||||||
|
import org.lwjgl.glfw.GLFWKeyCallbackI;
|
||||||
|
|
||||||
|
import gl_engine.vec.Vec2d;
|
||||||
|
import mainloop.task.IMainloopTask;
|
||||||
|
import projectzombie.Main;
|
||||||
|
import projectzombie.input.types.Input;
|
||||||
|
|
||||||
|
public class KeyCallback implements GLFWKeyCallbackI, IMainloopTask
|
||||||
|
{
|
||||||
|
private boolean itemDrop_last = false;
|
||||||
|
private boolean esc_last = false;
|
||||||
|
private boolean fullscreen_last = false;
|
||||||
|
private boolean buttonL_last = false;
|
||||||
|
private boolean buttonR_last = false;
|
||||||
|
private boolean inventory_last = false;
|
||||||
|
private boolean lctrl_pressed = false;
|
||||||
|
private boolean rctrl_pressed = false;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void invoke(long window, int key, int scancode, int action, int mods)
|
||||||
|
{
|
||||||
|
Input input = Main.menu.input;
|
||||||
|
boolean pressed = ! ( action == GLFW_RELEASE );
|
||||||
|
|
||||||
|
InputMode.Controller = false;
|
||||||
|
|
||||||
|
if(key == GLFW_KEY_LEFT_CONTROL) {
|
||||||
|
lctrl_pressed = pressed;
|
||||||
|
}
|
||||||
|
if(key == GLFW_KEY_RIGHT_CONTROL) {
|
||||||
|
rctrl_pressed = pressed;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == GLFW_KEY_W) {
|
||||||
|
moveUp = pressed;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == GLFW_KEY_S) {
|
||||||
|
moveDown = pressed;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == GLFW_KEY_A) {
|
||||||
|
moveLeft = pressed;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == GLFW_KEY_D) {
|
||||||
|
moveRight = pressed;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(pressed)
|
||||||
|
{
|
||||||
|
input.key(key);
|
||||||
|
|
||||||
|
if(lctrl_pressed || rctrl_pressed) {
|
||||||
|
input.keyCtrl(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == GLFW_KEY_1) {
|
||||||
|
input.hotbarGoto(true, 0);
|
||||||
|
}
|
||||||
|
if(key == GLFW_KEY_2) {
|
||||||
|
input.hotbarGoto(true, 1);
|
||||||
|
}
|
||||||
|
if(key == GLFW_KEY_3) {
|
||||||
|
input.hotbarGoto(true, 2);
|
||||||
|
}
|
||||||
|
if(key == GLFW_KEY_4) {
|
||||||
|
input.hotbarGoto(true, 3);
|
||||||
|
}
|
||||||
|
if(key == GLFW_KEY_5) {
|
||||||
|
input.hotbarGoto(true, 4);
|
||||||
|
}
|
||||||
|
if(key == GLFW_KEY_6) {
|
||||||
|
input.hotbarGoto(true, 5);
|
||||||
|
}
|
||||||
|
if(key == GLFW_KEY_7) {
|
||||||
|
input.hotbarGoto(true, 6);
|
||||||
|
}
|
||||||
|
if(key == GLFW_KEY_8) {
|
||||||
|
input.hotbarGoto(true, 7);
|
||||||
|
}
|
||||||
|
if(key == GLFW_KEY_9) {
|
||||||
|
input.hotbarGoto(true, 8);
|
||||||
|
}
|
||||||
|
if(key == GLFW_KEY_0) {
|
||||||
|
input.hotbarGoto(true, 9);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == GLFW_KEY_Q) {
|
||||||
|
if(pressed) {
|
||||||
|
if(!itemDrop_last) {
|
||||||
|
itemDrop_last = true;
|
||||||
|
input.itemDrop(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(itemDrop_last) {
|
||||||
|
itemDrop_last = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == GLFW_KEY_E) {
|
||||||
|
if(pressed) {
|
||||||
|
if(!inventory_last) {
|
||||||
|
inventory_last = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(inventory_last) {
|
||||||
|
inventory_last = false;
|
||||||
|
input.openInventory();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == GLFW_KEY_ESCAPE) {
|
||||||
|
if(pressed) {
|
||||||
|
if(!esc_last) {
|
||||||
|
esc_last = true;
|
||||||
|
input.pause(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(esc_last) {
|
||||||
|
esc_last = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(pressed) {
|
||||||
|
if(!backButton_last) {
|
||||||
|
backButton_last = true;
|
||||||
|
input.back(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(backButton_last) {
|
||||||
|
backButton_last = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == GLFW_KEY_F11) {
|
||||||
|
if(pressed) {
|
||||||
|
if(!fullscreen_last) {
|
||||||
|
fullscreen_last = true;
|
||||||
|
Main.window.toggleFullscreen();
|
||||||
|
}
|
||||||
|
} else if(fullscreen_last) {
|
||||||
|
fullscreen_last = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean MainLoopDelay(long millis) {
|
||||||
|
return millis > Main.tickrate;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean MainLoopRepeat() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void MainLoopUpdate()
|
||||||
|
{
|
||||||
|
Input input = Main.menu.input;
|
||||||
|
|
||||||
|
Vec2d move_point = new Vec2d(0, 0);
|
||||||
|
|
||||||
|
if(moveUp) {
|
||||||
|
move_point.x += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(moveDown) {
|
||||||
|
move_point.x -= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(moveLeft) {
|
||||||
|
move_point.y += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(moveRight) {
|
||||||
|
move_point.y -= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(move_point.x != 0 || move_point.y != 0) {
|
||||||
|
move_last = true;
|
||||||
|
double angle = Math.toDegrees(Math.atan2(move_point.y, move_point.x));
|
||||||
|
input.move(true, angle);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(buttonL) {
|
||||||
|
buttonL_last = true;
|
||||||
|
input.fire(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
else if(buttonL_last) {
|
||||||
|
buttonL_last = false;
|
||||||
|
input.fire(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(buttonR) {
|
||||||
|
buttonR_last = true;
|
||||||
|
input.itemAction(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
else if(buttonR_last) {
|
||||||
|
buttonR_last = false;
|
||||||
|
input.itemAction(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,16 @@
|
||||||
|
package projectzombie.input;
|
||||||
|
|
||||||
|
import org.lwjgl.glfw.GLFWCharCallbackI;
|
||||||
|
|
||||||
|
import projectzombie.Main;
|
||||||
|
|
||||||
|
public class KeyCharCallback implements GLFWCharCallbackI
|
||||||
|
{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void invoke(long window, int character) {
|
||||||
|
InputMode.Controller = false;
|
||||||
|
Main.menu.input.type((char)(character));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,23 @@
|
||||||
|
package projectzombie.input;
|
||||||
|
|
||||||
|
import org.lwjgl.glfw.GLFW;
|
||||||
|
import org.lwjgl.glfw.GLFWMouseButtonCallbackI;
|
||||||
|
|
||||||
|
public class MouseButtonCallback implements GLFWMouseButtonCallbackI
|
||||||
|
{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void invoke(long window, int button, int action, int mods)
|
||||||
|
{
|
||||||
|
InputMode.Controller = false;
|
||||||
|
|
||||||
|
if(button == GLFW.GLFW_MOUSE_BUTTON_LEFT) {
|
||||||
|
GameInput.buttonL = action == 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(button == GLFW.GLFW_MOUSE_BUTTON_RIGHT) {
|
||||||
|
GameInput.buttonR = action == 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,22 @@
|
||||||
|
package projectzombie.input;
|
||||||
|
|
||||||
|
import org.lwjgl.glfw.GLFWScrollCallbackI;
|
||||||
|
|
||||||
|
import projectzombie.Main;
|
||||||
|
|
||||||
|
public class ScrollWheelCallback implements GLFWScrollCallbackI
|
||||||
|
{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void invoke(long window, double x, double y)
|
||||||
|
{
|
||||||
|
InputMode.Controller = false;
|
||||||
|
|
||||||
|
if(y > 0) {
|
||||||
|
Main.menu.input.hotbarShift(true, 1);
|
||||||
|
} if(y < 0) {
|
||||||
|
Main.menu.input.hotbarShift(true, -1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,21 @@
|
||||||
|
package projectzombie.input.types;
|
||||||
|
|
||||||
|
import gl_engine.vec.Vec2d;
|
||||||
|
|
||||||
|
public interface Input
|
||||||
|
{
|
||||||
|
public void type(char character);
|
||||||
|
public void move(boolean state, double angle);
|
||||||
|
public void fire(boolean state);
|
||||||
|
public void camera(boolean state, double amount);
|
||||||
|
public void itemAction(boolean state);
|
||||||
|
public void itemDrop(boolean state);
|
||||||
|
public void pause(boolean state);
|
||||||
|
public void hotbarGoto(boolean state, int pos);
|
||||||
|
public void hotbarShift(boolean state, int amount);
|
||||||
|
public void back(boolean state);
|
||||||
|
public void activate(boolean state);
|
||||||
|
public void openInventory();
|
||||||
|
public void key(int key);
|
||||||
|
public void keyCtrl(int key);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,97 @@
|
||||||
|
package projectzombie.input.types;
|
||||||
|
|
||||||
|
import gl_engine.vec.Vec2d;
|
||||||
|
import projectzombie.Main;
|
||||||
|
import projectzombie.menu.gui.GUI;
|
||||||
|
import projectzombie.util.gl.GlHelpers;
|
||||||
|
|
||||||
|
public class InputGUI implements Input
|
||||||
|
{
|
||||||
|
private GUI gui;
|
||||||
|
private boolean gunStateLast = false;
|
||||||
|
private boolean actionStateLast = false;
|
||||||
|
|
||||||
|
public InputGUI(GUI gui) {
|
||||||
|
this.gui = gui;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GUI getGUI() {
|
||||||
|
return gui;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void move(boolean state, double angle) {
|
||||||
|
this.gui.onMove(state, angle);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void fire(boolean state) {
|
||||||
|
if(state) {
|
||||||
|
gunStateLast = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
else if(gunStateLast) {
|
||||||
|
gunStateLast = false;
|
||||||
|
gui.onMouseClick();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void camera(boolean state, double amount) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void itemAction(boolean state) {
|
||||||
|
if(state) {
|
||||||
|
actionStateLast = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
else if(actionStateLast) {
|
||||||
|
actionStateLast = false;
|
||||||
|
gui.onRightClick();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void itemDrop(boolean state) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void pause(boolean state) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void hotbarGoto(boolean state, int pos) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void hotbarShift(boolean state, int amount) {
|
||||||
|
gui.onScroll(amount);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void back(boolean state) {
|
||||||
|
gui.onBack();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void activate(boolean state) {
|
||||||
|
gui.onActivate();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void openInventory() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void type(char character) {
|
||||||
|
gui.type(character);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void key(int key) {
|
||||||
|
gui.keyPress(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void keyCtrl(int key) {
|
||||||
|
gui.keyPressCtrl(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,12 @@
|
||||||
|
package projectzombie.input.types;
|
||||||
|
|
||||||
|
public interface InputGUITextBox {
|
||||||
|
public void onBackspace();
|
||||||
|
public void onDelete();
|
||||||
|
public void onPressed(char character);
|
||||||
|
public void onMoveCursor(int direction);
|
||||||
|
public void setFocus(boolean focus);
|
||||||
|
public void onPaste();
|
||||||
|
public void onHome();
|
||||||
|
public void onEnd();
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,100 @@
|
||||||
|
package projectzombie.input.types;
|
||||||
|
|
||||||
|
import gl_engine.MathHelpers;
|
||||||
|
import gl_engine.vec.Vec2d;
|
||||||
|
import projectzombie.Main;
|
||||||
|
import projectzombie.inventory.Crafting;
|
||||||
|
import projectzombie.inventory.Inventory;
|
||||||
|
import projectzombie.menu.MenuGamePause;
|
||||||
|
import projectzombie.menu.MenuInventory;
|
||||||
|
import projectzombie.menu.MenuInventoryBasic;
|
||||||
|
import projectzombie.menu.MenuInventoryStorage;
|
||||||
|
import projectzombie.menu.gui.GUIItemSlotGetter;
|
||||||
|
import projectzombie.util.ItemStack;
|
||||||
|
import projectzombie.world.chunk.ChunkEventHandler;
|
||||||
|
|
||||||
|
public class InputGame implements Input
|
||||||
|
{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void move(boolean state, double angle)
|
||||||
|
{
|
||||||
|
if(state)
|
||||||
|
{
|
||||||
|
// Move the player in the left sticks angle
|
||||||
|
if(ChunkEventHandler.loaded) {
|
||||||
|
Main.player.moveTowards(angle + Main.player.angle);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set the players moving to true
|
||||||
|
Main.player.moving = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
Main.player.moving = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void fire(boolean state) {
|
||||||
|
Main.player.leftClick();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void camera(boolean state, double amount) {
|
||||||
|
Main.player.angle -= amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void itemAction(boolean state) {
|
||||||
|
Main.player.rightClick();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void itemDrop(boolean state) {
|
||||||
|
Main.player.dropItem();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void pause(boolean state) {
|
||||||
|
Main.menu = new MenuGamePause();
|
||||||
|
Main.game_paused = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void hotbarGoto(boolean state, int pos) {
|
||||||
|
Main.player.inventory_hand = pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void hotbarShift(boolean state, int amount) {
|
||||||
|
Main.player.inventory_hand += amount;
|
||||||
|
Main.player.inventory_hand = MathHelpers.mod(Main.player.inventory_hand, 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void back(boolean state) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void activate(boolean state) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void openInventory() {
|
||||||
|
Main.menu = new MenuInventoryBasic(Main.menu, Crafting.BASIC);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void type(char character) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void key(int key) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void keyCtrl(int key) {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
package projectzombie.inventory;
|
||||||
|
|
||||||
|
public enum Crafting {
|
||||||
|
BASIC, WOODEN_WORKBENCH
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
package projectzombie.inventory;
|
||||||
|
|
||||||
|
import projectzombie.util.ItemStack;
|
||||||
|
|
||||||
|
public interface IInventory
|
||||||
|
{
|
||||||
|
public int getSlotCount();
|
||||||
|
public ItemStack getItem(int slot);
|
||||||
|
|
||||||
|
public void addItem(ItemStack stack);
|
||||||
|
public void setItem(ItemStack stack, int slot);
|
||||||
|
|
||||||
|
public ItemStack removeItem(int slot);
|
||||||
|
public void removeItem(ItemStack stack);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,14 @@
|
||||||
|
package projectzombie.inventory;
|
||||||
|
|
||||||
|
import projectzombie.util.ItemStack;
|
||||||
|
|
||||||
|
public interface IInventoryArmor
|
||||||
|
{
|
||||||
|
public ItemStack getHelmet();
|
||||||
|
public ItemStack getChest();
|
||||||
|
public ItemStack getLeggings();
|
||||||
|
|
||||||
|
public void setHelmet(ItemStack stack);
|
||||||
|
public void setChest(ItemStack stack);
|
||||||
|
public void setLeggings(ItemStack stack);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,14 @@
|
||||||
|
package projectzombie.inventory;
|
||||||
|
|
||||||
|
import projectzombie.util.ItemStack;
|
||||||
|
|
||||||
|
public interface IInventoryClothing
|
||||||
|
{
|
||||||
|
public ItemStack getShirt();
|
||||||
|
public ItemStack getPants();
|
||||||
|
public ItemStack getBoots();
|
||||||
|
|
||||||
|
public void setShirt(ItemStack stack);
|
||||||
|
public void setPants(ItemStack stack);
|
||||||
|
public void setBoots(ItemStack stack);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,170 @@
|
||||||
|
package projectzombie.inventory;
|
||||||
|
|
||||||
|
import projectzombie.util.ClassBdf;
|
||||||
|
import projectzombie.util.ItemStack;
|
||||||
|
import bdf.types.BdfArray;
|
||||||
|
import bdf.types.BdfNamedList;
|
||||||
|
import bdf.types.BdfObject;
|
||||||
|
import gl_engine.vec.Vec2d;
|
||||||
|
import gl_engine.vec.Vec3d;
|
||||||
|
import projectzombie.entity.EntityItem;
|
||||||
|
import projectzombie.items.Item;
|
||||||
|
import projectzombie.items.modifier.ItemModifier;
|
||||||
|
import projectzombie.world.chunk.Chunk;
|
||||||
|
import projectzombie.world.layer.Layer;
|
||||||
|
|
||||||
|
public class Inventory implements IInventory, ClassBdf
|
||||||
|
{
|
||||||
|
protected ItemStack[] items;
|
||||||
|
|
||||||
|
public Inventory(int size)
|
||||||
|
{
|
||||||
|
items = new ItemStack[size];
|
||||||
|
|
||||||
|
for(int i=0;i<size;i++) {
|
||||||
|
items[i] = ItemStack.getEmpty();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ItemStack getItem(int slot) {
|
||||||
|
return items[slot];
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getSlotCount() {
|
||||||
|
return items.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setItem(ItemStack stack, int slot) {
|
||||||
|
items[slot] = stack;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ItemStack removeItem(int slot) {
|
||||||
|
ItemStack stack = items[slot];
|
||||||
|
items[slot] = ItemStack.getEmpty();
|
||||||
|
return stack;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getItemCount(ItemStack item)
|
||||||
|
{
|
||||||
|
int count = 0;
|
||||||
|
|
||||||
|
for(ItemStack check : items) {
|
||||||
|
if(check.stackAbstractEquals(item) && !check.isEmpty()) {
|
||||||
|
count += check.count;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addItem(ItemStack stack)
|
||||||
|
{
|
||||||
|
if(stack.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(ItemStack check : items)
|
||||||
|
{
|
||||||
|
if(stack.stackEquals(check) && !check.isEmpty())
|
||||||
|
{
|
||||||
|
if(check.count + stack.count > check.item.max) {
|
||||||
|
stack.count = (check.count + stack.count) - check.item.max;
|
||||||
|
check.count = check.item.max;
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
check.count += stack.count;
|
||||||
|
stack.count = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for(ItemStack check : items)
|
||||||
|
{
|
||||||
|
if(check.isEmpty())
|
||||||
|
{
|
||||||
|
ItemModifier[] modifiers = new ItemModifier[stack.modifiers.length];
|
||||||
|
|
||||||
|
for(int i=0;i<modifiers.length;i++) {
|
||||||
|
modifiers[i] = stack.modifiers[i].copy();
|
||||||
|
}
|
||||||
|
|
||||||
|
check.item = stack.item;
|
||||||
|
check.count = stack.count;
|
||||||
|
check.modifiers = modifiers;
|
||||||
|
stack.count = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void dropInventory(Layer layer, Chunk chunk, Vec3d pos, Vec3d velocity)
|
||||||
|
{
|
||||||
|
for(int i=0;i<items.length;i++)
|
||||||
|
{
|
||||||
|
if(!items[i].isEmpty())
|
||||||
|
{
|
||||||
|
chunk.spawnEntity(new EntityItem(pos, velocity, items[i]));
|
||||||
|
|
||||||
|
items[i] = ItemStack.getEmpty();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeItem(ItemStack stack)
|
||||||
|
{
|
||||||
|
for(ItemStack check : items) {
|
||||||
|
if(check.stackAbstractEquals(stack) && !stack.isEmpty())
|
||||||
|
{
|
||||||
|
if(check.count < stack.count) {
|
||||||
|
stack.count -= check.count;
|
||||||
|
check.count = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
check.count -= stack.count;
|
||||||
|
stack.count = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void BdfClassLoad(BdfObject bdf)
|
||||||
|
{
|
||||||
|
BdfNamedList nl = bdf.getNamedList();
|
||||||
|
items = new ItemStack[nl.get("size").getInteger()];
|
||||||
|
|
||||||
|
BdfArray array = nl.get("items").getArray();
|
||||||
|
|
||||||
|
for(int i=0;i<items.length;i++) {
|
||||||
|
items[i] = new ItemStack(array.get(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void BdfClassSave(BdfObject bdf)
|
||||||
|
{
|
||||||
|
BdfNamedList nl = bdf.getNamedList();
|
||||||
|
|
||||||
|
nl.set("size", bdf.newObject().setInteger(items.length));
|
||||||
|
BdfArray array = nl.get("items").getArray();
|
||||||
|
|
||||||
|
for(ItemStack stack : items) {
|
||||||
|
BdfObject stack_bdf = bdf.newObject();
|
||||||
|
stack.BdfClassSave(stack_bdf);
|
||||||
|
array.add(stack_bdf);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Inventory(BdfObject bdf) {
|
||||||
|
BdfClassLoad(bdf);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,69 @@
|
||||||
|
package projectzombie.inventory;
|
||||||
|
|
||||||
|
import projectzombie.util.ClassBdf;
|
||||||
|
import projectzombie.util.ItemStack;
|
||||||
|
import bdf.types.BdfNamedList;
|
||||||
|
import bdf.types.BdfObject;
|
||||||
|
|
||||||
|
public class InventoryArmor implements ClassBdf, IInventoryArmor
|
||||||
|
{
|
||||||
|
private ItemStack helmet, chest, leggings;
|
||||||
|
|
||||||
|
public InventoryArmor() {
|
||||||
|
helmet = ItemStack.getEmpty();
|
||||||
|
chest = ItemStack.getEmpty();
|
||||||
|
leggings = ItemStack.getEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
public InventoryArmor(BdfObject bdf) {
|
||||||
|
BdfClassLoad(bdf);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ItemStack getHelmet() {
|
||||||
|
return helmet;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ItemStack getChest() {
|
||||||
|
return chest;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ItemStack getLeggings() {
|
||||||
|
return leggings;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setHelmet(ItemStack stack) {
|
||||||
|
helmet = stack;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setChest(ItemStack stack) {
|
||||||
|
chest = stack;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setLeggings(ItemStack stack) {
|
||||||
|
leggings = stack;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void BdfClassLoad(BdfObject bdf) {
|
||||||
|
BdfNamedList nl = bdf.getNamedList();
|
||||||
|
helmet = new ItemStack(nl.get("helmet"));
|
||||||
|
chest = new ItemStack(nl.get("chest"));
|
||||||
|
leggings = new ItemStack(nl.get("leggings"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void BdfClassSave(BdfObject bdf) {
|
||||||
|
BdfNamedList nl = bdf.newNamedList();
|
||||||
|
helmet.BdfClassSave(nl.get("helmet"));
|
||||||
|
chest.BdfClassSave(nl.get("chest"));
|
||||||
|
leggings.BdfClassSave(nl.get("leggings"));
|
||||||
|
bdf.setNamedList(nl);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,68 @@
|
||||||
|
package projectzombie.inventory;
|
||||||
|
|
||||||
|
import projectzombie.util.ClassBdf;
|
||||||
|
import projectzombie.util.ItemStack;
|
||||||
|
import bdf.types.BdfNamedList;
|
||||||
|
import bdf.types.BdfObject;
|
||||||
|
|
||||||
|
public class InventoryClothing implements ClassBdf, IInventoryClothing
|
||||||
|
{
|
||||||
|
private ItemStack shirt, pants, boots;
|
||||||
|
|
||||||
|
public InventoryClothing() {
|
||||||
|
shirt = ItemStack.getEmpty();
|
||||||
|
pants = ItemStack.getEmpty();
|
||||||
|
boots = ItemStack.getEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
public InventoryClothing(BdfObject bdf) {
|
||||||
|
BdfClassLoad(bdf);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ItemStack getShirt() {
|
||||||
|
return shirt;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ItemStack getPants() {
|
||||||
|
return pants;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ItemStack getBoots() {
|
||||||
|
return boots;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setShirt(ItemStack stack) {
|
||||||
|
shirt = stack;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setPants(ItemStack stack) {
|
||||||
|
pants = stack;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setBoots(ItemStack stack) {
|
||||||
|
boots = stack;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void BdfClassLoad(BdfObject bdf) {
|
||||||
|
BdfNamedList nl = bdf.getNamedList();
|
||||||
|
shirt = new ItemStack(nl.get("shirt"));
|
||||||
|
pants = new ItemStack(nl.get("pants"));
|
||||||
|
boots = new ItemStack(nl.get("boots"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void BdfClassSave(BdfObject bdf) {
|
||||||
|
BdfNamedList nl = bdf.newNamedList();
|
||||||
|
shirt.BdfClassSave(nl.get("shirt"));
|
||||||
|
pants.BdfClassSave(nl.get("pants"));
|
||||||
|
boots.BdfClassSave(nl.get("boots"));
|
||||||
|
bdf.setNamedList(nl);
|
||||||
|
}
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue