Hotbar now displays item names and info
This commit is contained in:
parent
1343535933
commit
a1488570d9
|
|
@ -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);*/
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,6 +1,12 @@
|
||||||
package shootergame.audio;
|
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.AL;
|
||||||
import org.lwjgl.openal.ALC;
|
import org.lwjgl.openal.ALC;
|
||||||
|
|
|
||||||
|
|
@ -93,10 +93,12 @@ public class DisplayRenderUI
|
||||||
|
|
||||||
GlHelpers.end();
|
GlHelpers.end();
|
||||||
|
|
||||||
|
// Get the players inventory
|
||||||
|
Inventory player_inv = player.getInventory();
|
||||||
|
|
||||||
// Render the players inventory
|
// Render the players inventory
|
||||||
for(int i=0;i<6;i++)
|
for(int i=0;i<6;i++)
|
||||||
{
|
{
|
||||||
Inventory player_inv = ((EntityInventory)player).getInventory();
|
|
||||||
ItemStack player_item = player_inv.getItem(i);
|
ItemStack player_item = player_inv.getItem(i);
|
||||||
|
|
||||||
if(!player_item.isEmpty())
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -38,10 +38,6 @@ public class Item
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getLore(short meta) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onPickedUp(ItemStack stack, Layer layer, Chunk chunk, Entity entity)
|
public void onPickedUp(ItemStack stack, Layer layer, Chunk chunk, Entity entity)
|
||||||
{
|
{
|
||||||
// Update the stacks count
|
// Update the stacks count
|
||||||
|
|
|
||||||
|
|
@ -21,14 +21,9 @@ public class ItemDefenceUpgrade extends Item
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getLore(short meta) {
|
|
||||||
return "Upgrade the defence to level " + meta;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName(short meta) {
|
public String getName(short meta) {
|
||||||
return "Defence Upgrade";
|
return "Defence Upgrade level "+meta;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,14 +11,9 @@ public class ItemGunUpgrade extends Item
|
||||||
this.texture = Textures.ITEM_GUN_UPGRADE;
|
this.texture = Textures.ITEM_GUN_UPGRADE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getLore(short meta) {
|
|
||||||
return "Upgrade the gun to level " + meta;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName(short meta) {
|
public String getName(short meta) {
|
||||||
return "Gun Upgrade";
|
return "Gun Upgrade level "+meta;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,12 +17,7 @@ public class ItemHealthPotion extends Item
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName(short meta) {
|
public String getName(short meta) {
|
||||||
return "Health Potion";
|
return "Health Potion "+meta+" HP";
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getLore(short meta) {
|
|
||||||
return "Restores " + Short.toString(meta) + " health points";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue