From a1488570d91f3c246cd5098e0b60671564311f68 Mon Sep 17 00:00:00 2001 From: josua Date: Tue, 3 Sep 2019 13:11:12 +1000 Subject: [PATCH] Hotbar now displays item names and info --- src/shootergame/Test.java | 97 ------------------- src/shootergame/audio/AudioEngine.java | 8 +- src/shootergame/display/DisplayRenderUI.java | 13 ++- src/shootergame/items/Item.java | 4 - src/shootergame/items/ItemDefenceUpgrade.java | 7 +- src/shootergame/items/ItemGunUpgrade.java | 7 +- src/shootergame/items/ItemHealthPotion.java | 7 +- 7 files changed, 22 insertions(+), 121 deletions(-) delete mode 100644 src/shootergame/Test.java diff --git a/src/shootergame/Test.java b/src/shootergame/Test.java deleted file mode 100644 index e084a77..0000000 --- a/src/shootergame/Test.java +++ /dev/null @@ -1,97 +0,0 @@ -package shootergame; - -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.alBufferData; -import static org.lwjgl.openal.AL10.alGenBuffers; -import static org.lwjgl.openal.AL10.alGenSources; -import static org.lwjgl.openal.AL10.alSourcePlay; -import static org.lwjgl.openal.AL10.alSourcei; -import static org.lwjgl.openal.ALC10.ALC_DEFAULT_DEVICE_SPECIFIER; -import static org.lwjgl.openal.ALC10.alcCreateContext; -import static org.lwjgl.openal.ALC10.alcGetString; -import static org.lwjgl.openal.ALC10.alcMakeContextCurrent; -import static org.lwjgl.openal.ALC10.alcOpenDevice; -import static org.lwjgl.stb.STBVorbis.stb_vorbis_decode_filename; -import static org.lwjgl.system.MemoryStack.stackPush; - -import java.nio.IntBuffer; -import java.nio.ShortBuffer; - -import org.lwjgl.system.MemoryStack; - -public class Test -{ - public static void main(String[] args) { - //Initialization - String defaultDeviceName = alcGetString(0, ALC_DEFAULT_DEVICE_SPECIFIER); - long device = alcOpenDevice(defaultDeviceName); - - int[] attributes = {0}; - long context = alcCreateContext(device, attributes); - alcMakeContextCurrent(context); - - ShortBuffer rawAudioBuffer; - - int channels; - int sampleRate; - - try (MemoryStack stack = stackPush()) { - //Allocate space to store return information from the function - IntBuffer channelsBuffer = stack.mallocInt(1); - IntBuffer sampleRateBuffer = stack.mallocInt(1); - - rawAudioBuffer = stb_vorbis_decode_filename("resources/sound/gun.ogg", channelsBuffer, sampleRateBuffer); - - //Retreive the extra information that was stored in the buffers by the function - channels = channelsBuffer.get(0); - sampleRate = sampleRateBuffer.get(0); - } - - //Find the correct OpenAL format - int format = -1; - if (channels == 1) { - format = AL_FORMAT_MONO16; - } else if (channels == 2) { - format = AL_FORMAT_STEREO16; - } - - //Request space for the buffer - int bufferPointer = alGenBuffers(); - - //Send the data to OpenAL - alBufferData(bufferPointer, format, rawAudioBuffer, sampleRate); - - //Free the memory allocated by STB - //free(rawAudioBuffer); - - while(true) - { - //Request a source - int sourcePointer = alGenSources(); - - //Assign the sound we just loaded to the source - alSourcei(sourcePointer, AL_BUFFER, bufferPointer); - - //Play the sound - alSourcePlay(sourcePointer); - - System.out.println(sourcePointer); - - try { - //Wait for a second - Thread.sleep(10); - } catch (InterruptedException ignored) { - } - - //alDeleteSources(sourcePointer); - } - - /*//Terminate OpenAL - alDeleteSources(sourcePointer); - alDeleteBuffers(bufferPointer); - alcDestroyContext(context); - alcCloseDevice(device);*/ - } -} \ No newline at end of file diff --git a/src/shootergame/audio/AudioEngine.java b/src/shootergame/audio/AudioEngine.java index 0b16acc..33ced5b 100644 --- a/src/shootergame/audio/AudioEngine.java +++ b/src/shootergame/audio/AudioEngine.java @@ -1,6 +1,12 @@ package shootergame.audio; -import static org.lwjgl.openal.ALC11.*; +import static org.lwjgl.openal.ALC10.ALC_DEFAULT_DEVICE_SPECIFIER; +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.ALC; diff --git a/src/shootergame/display/DisplayRenderUI.java b/src/shootergame/display/DisplayRenderUI.java index 53b8c0a..fd37aac 100644 --- a/src/shootergame/display/DisplayRenderUI.java +++ b/src/shootergame/display/DisplayRenderUI.java @@ -93,10 +93,12 @@ public class DisplayRenderUI GlHelpers.end(); + // Get the players inventory + Inventory player_inv = player.getInventory(); + // Render the players inventory for(int i=0;i<6;i++) { - Inventory player_inv = ((EntityInventory)player).getInventory(); ItemStack player_item = player_inv.getItem(i); if(!player_item.isEmpty()) @@ -110,5 +112,14 @@ public class DisplayRenderUI } } + // Render the active slots text + ItemStack item_active = player_inv.getItem(player.inventory_hand); + if(!item_active.isEmpty()) + { + GlHelpers.pushMatrix(); + GlHelpers.translate(3.8, -7.4, 0); + Text.render(item_active.item.getName(item_active.meta), text_size); + GlHelpers.popMatrix(); + } } } diff --git a/src/shootergame/items/Item.java b/src/shootergame/items/Item.java index a7b448d..3fe8912 100644 --- a/src/shootergame/items/Item.java +++ b/src/shootergame/items/Item.java @@ -38,10 +38,6 @@ public class Item return ""; } - public String getLore(short meta) { - return ""; - } - public void onPickedUp(ItemStack stack, Layer layer, Chunk chunk, Entity entity) { // Update the stacks count diff --git a/src/shootergame/items/ItemDefenceUpgrade.java b/src/shootergame/items/ItemDefenceUpgrade.java index 42e1bd9..003d048 100644 --- a/src/shootergame/items/ItemDefenceUpgrade.java +++ b/src/shootergame/items/ItemDefenceUpgrade.java @@ -21,14 +21,9 @@ public class ItemDefenceUpgrade extends Item } - @Override - public String getLore(short meta) { - return "Upgrade the defence to level " + meta; - } - @Override public String getName(short meta) { - return "Defence Upgrade"; + return "Defence Upgrade level "+meta; } } diff --git a/src/shootergame/items/ItemGunUpgrade.java b/src/shootergame/items/ItemGunUpgrade.java index 4ed19ca..863e409 100644 --- a/src/shootergame/items/ItemGunUpgrade.java +++ b/src/shootergame/items/ItemGunUpgrade.java @@ -11,14 +11,9 @@ public class ItemGunUpgrade extends Item this.texture = Textures.ITEM_GUN_UPGRADE; } - @Override - public String getLore(short meta) { - return "Upgrade the gun to level " + meta; - } - @Override public String getName(short meta) { - return "Gun Upgrade"; + return "Gun Upgrade level "+meta; } } diff --git a/src/shootergame/items/ItemHealthPotion.java b/src/shootergame/items/ItemHealthPotion.java index 1cc0a00..7197dcf 100644 --- a/src/shootergame/items/ItemHealthPotion.java +++ b/src/shootergame/items/ItemHealthPotion.java @@ -17,12 +17,7 @@ public class ItemHealthPotion extends Item @Override public String getName(short meta) { - return "Health Potion"; - } - - @Override - public String getLore(short meta) { - return "Restores " + Short.toString(meta) + " health points"; + return "Health Potion "+meta+" HP"; } @Override