change hotbar behaviour
This commit is contained in:
parent
c10996bbda
commit
771a8bfa89
17 changed files with 169 additions and 114 deletions
|
@ -1072,6 +1072,8 @@ public class Client implements IThreadListener {
|
|||
this.displayTick(ExtMath.floord(this.player.posX), ExtMath.floord(this.player.posY), ExtMath.floord(this.player.posZ));
|
||||
}
|
||||
this.effectRenderer.update();
|
||||
if(this.player != null && this.player.getHeldItem() == null)
|
||||
this.select(1);
|
||||
}
|
||||
else if (this.connection != null)
|
||||
{
|
||||
|
@ -1136,10 +1138,20 @@ public class Client implements IThreadListener {
|
|||
final int selected = this.world != null && this.player != null && this.viewEntity == this.player ? this.player.getSelectedIndex() : -1;
|
||||
final int scale = this.scaleHotbar ? 2 : 1;
|
||||
final int size = this.world != null && this.player != null && this.viewEntity == this.player ? this.player.getHotbarSize() : 1;
|
||||
final int width = (this.fbX / scale - 20) / size;
|
||||
int total = 1;
|
||||
if(this.world != null && this.player != null && this.viewEntity == this.player) {
|
||||
total = 0;
|
||||
for(int z = 0; z < this.player.getHotbarSize(); z++) {
|
||||
if(this.player.getStackInSlot(z) != null)
|
||||
++total;
|
||||
}
|
||||
if(total == 0)
|
||||
total = 1;
|
||||
}
|
||||
final int width = (this.fbX / scale - 20) / total;
|
||||
// final int bx = this.fbX / 2 - size * (width >= 20 ? 10 : width / 2) * scale + 2 * scale;
|
||||
final int by = this.fbY - 20 * scale;
|
||||
final int xoff = (this.fbX / scale - (width < 20 ? ((size - 2) * width + 40 + width / 2) : (size * 20 - 2))) / 2 + (width < 20 && selected == 0 ? 20 - width : 0) - 2;
|
||||
final int xoff = (this.fbX / scale - (width < 20 ? ((total - 2) * width + 40 + width / 2) : (total * 20 - 2))) / 2 + (width < 20 && selected == 0 ? 20 - width : 0) - 2;
|
||||
this.setupOverlay();
|
||||
if(this.world != null && !(this.open instanceof GuiConsole) && this.player != null && this.viewEntity == this.player) {
|
||||
if(this.open == null) {
|
||||
|
@ -1162,6 +1174,8 @@ public class Client implements IThreadListener {
|
|||
|
||||
int x = xoff * scale;
|
||||
for(int n = 0; n < size; n++) {
|
||||
if(this.player.getStackInSlot(n) == null)
|
||||
continue;
|
||||
if(selected == n)
|
||||
Drawing.drawRect(x - scale * 2, by - scale * 2, 20 * scale, 20 * scale, 0xffffffff);
|
||||
InventoryButton.drawButton(this, x - scale, by - scale, 18 * scale, 18 * scale, this.scaleHotbar);
|
||||
|
@ -1323,19 +1337,21 @@ public class Client implements IThreadListener {
|
|||
GL15.glScalef(2.0f, 2.0f, 2.0f);
|
||||
|
||||
int xPos = xoff;
|
||||
int cnt = 0;
|
||||
for(int index = 0; index < size; ++index) {
|
||||
ItemStack itemstack = this.player.getStackInSlot(index);
|
||||
if(itemstack != null) {
|
||||
if(width < 20 && selected != index && selected != index + 1 && index != size - 1) {
|
||||
if(width < 20 && selected != index && selected != index + 1 && cnt != total - 1) {
|
||||
this.scissor(xPos * scale, this.fbY - (by + 16 * scale), (width - 1) * scale, 16 * scale);
|
||||
GL15.glEnable(GL15.GL_SCISSOR_TEST);
|
||||
}
|
||||
GlState.enableDepth();
|
||||
this.renderItem.renderItemAndEffectIntoGUI(itemstack, xPos, 0);
|
||||
if(width < 20 && selected != index && selected != index + 1 && index != size - 1)
|
||||
if(width < 20 && selected != index && selected != index + 1 && cnt != total - 1)
|
||||
GL15.glDisable(GL15.GL_SCISSOR_TEST);
|
||||
xPos += width >= 20 || selected == index || selected == index + 1 ? 20 : width;
|
||||
++cnt;
|
||||
}
|
||||
xPos += width >= 20 || selected == index || selected == index + 1 ? 20 : width;
|
||||
}
|
||||
|
||||
if(this.infoOverlay) {
|
||||
|
@ -1372,7 +1388,8 @@ public class Client implements IThreadListener {
|
|||
GuiContainer.renderItemOverlay(itemstack,
|
||||
xPos, by, null, index == this.player.getSelectedIndex() ? this.controller.getUseCooldown() : 0, this.controller.getUseCooldownMax(), scale);
|
||||
}
|
||||
xPos += (width >= 20 || selected == index || selected == index + 1 ? 20 : width) * scale;
|
||||
if(itemstack != null)
|
||||
xPos += (width >= 20 || selected == index || selected == index + 1 ? 20 : width) * scale;
|
||||
}
|
||||
}
|
||||
if(this.open != null)
|
||||
|
@ -1488,14 +1505,22 @@ public class Client implements IThreadListener {
|
|||
public void scroll(int dir) {
|
||||
if(this.zooming)
|
||||
this.zoomLevel = ExtMath.clampf(this.zoomLevel + (dir < 0 ? -0.25f : 0.25f), this.viewEntity != this.player ? 1.0f : 2.0f, 16.0f);
|
||||
else if(this.player != null) {
|
||||
this.player.setSelectedIndex(this.player.getSelectedIndex() - dir);
|
||||
else if(this.player != null)
|
||||
this.select(-dir);
|
||||
}
|
||||
|
||||
private void select(int dir) {
|
||||
int n = 0;
|
||||
do {
|
||||
this.player.setSelectedIndex(this.player.getSelectedIndex() + dir);
|
||||
if(this.player.getSelectedIndex() < 0)
|
||||
this.player.setSelectedIndex(this.player.getHotbarSize() - 1);
|
||||
else if(this.player.getSelectedIndex() >= this.player.getHotbarSize())
|
||||
this.player.setSelectedIndex(0);
|
||||
this.controller.resetUseCooldown();
|
||||
}
|
||||
++n;
|
||||
}
|
||||
while(this.player.getHeldItem() == null && n < this.player.getHotbarSize());
|
||||
this.controller.resetUseCooldown();
|
||||
}
|
||||
|
||||
public void moveCamera(float x, float y) {
|
||||
|
|
|
@ -29,7 +29,7 @@ public class InventoryButton extends Element {
|
|||
|
||||
public static void drawButton(Client gm, int x, int y, int w, int h, boolean border) {
|
||||
if(border)
|
||||
Drawing.drawDoubleRect(x, y, w, h, gm.style.fill_top, gm.style.fill_btm, gm.style.brdr_top, gm.style.brdr_btm);
|
||||
Drawing.drawGradientBorder(x, y, w, h, gm.style.fill_top, gm.style.fill_btm, 0xff000000, gm.style.brdr_top, gm.style.brdr_btm);
|
||||
else
|
||||
Drawing.drawGradient(x, y, w, h, gm.style.fill_top, gm.style.fill_btm, gm.style.brdr_top, gm.style.brdr_btm);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue