item slot refactor
This commit is contained in:
parent
c3f9655338
commit
6fb9ded711
90 changed files with 1177 additions and 1622 deletions
|
@ -124,7 +124,6 @@ import common.init.ItemRegistry;
|
|||
import common.init.Items;
|
||||
import common.init.Registry;
|
||||
import common.init.SoundEvent;
|
||||
import common.inventory.InventoryPlayer;
|
||||
import common.item.Item;
|
||||
import common.item.ItemControl;
|
||||
import common.item.ItemStack;
|
||||
|
@ -871,9 +870,9 @@ public class Client implements IThreadListener {
|
|||
{
|
||||
if (this.keyBindsHotbar[l].isPressed())
|
||||
{
|
||||
if(this.player.inventory.currentItem != l)
|
||||
if(this.player.getSelectedIndex() != l)
|
||||
this.controller.resetUseCooldown();
|
||||
this.player.inventory.currentItem = l;
|
||||
this.player.setSelectedIndex(l);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1065,14 +1064,14 @@ public class Client implements IThreadListener {
|
|||
}
|
||||
}
|
||||
|
||||
int selected = this.player.inventory.currentItem;
|
||||
int selected = this.player.getSelectedIndex();
|
||||
for(int n = 0; n < 9; n++) {
|
||||
int x = this.fbX / 2 - 180 + n * 40 + 4;
|
||||
int y = this.fbY - 40;
|
||||
Drawing.drawRectBorder(x - 1, y - 1, 36, 36, 0xff6f6f6f, selected == n ? 0xffffffff : 0xff000000, 0xffafafaf, 0xff4f4f4f);
|
||||
}
|
||||
|
||||
ItemStack itemstack = this.player.inventory.getCurrentItem();
|
||||
ItemStack itemstack = this.player.getHeldItem();
|
||||
String current = itemstack != null ? itemstack.getItem().getHotbarText(this.player, itemstack) : "";
|
||||
if(!current.isEmpty())
|
||||
Drawing.drawTextUpward(current, this.fbX / 2, this.fbY - 60, 0xffffffff);
|
||||
|
@ -1211,7 +1210,7 @@ public class Client implements IThreadListener {
|
|||
|
||||
for(int index = 0; index < 9; ++index) {
|
||||
int xPos = index * 20;
|
||||
ItemStack itemstack = this.player.inventory.mainInventory[index];
|
||||
ItemStack itemstack = this.player.getStackInSlot(index);
|
||||
if(itemstack != null) {
|
||||
GlState.enableDepth();
|
||||
this.renderItem.renderItemAndEffectIntoGUI(itemstack, xPos, 0);
|
||||
|
@ -1246,10 +1245,10 @@ public class Client implements IThreadListener {
|
|||
GlState.disableDepth();
|
||||
if(this.world != null && this.open == null && this.player != null && this.viewEntity == this.player) {
|
||||
for(int index = 0; index < 9; ++index) {
|
||||
ItemStack itemstack = this.player.inventory.mainInventory[index];
|
||||
ItemStack itemstack = this.player.getStackInSlot(index);
|
||||
if(itemstack != null) {
|
||||
GuiContainer.renderItemOverlay(itemstack,
|
||||
this.fbX / 2 - 180 + 4 + 1 + index * 40, this.fbY - 40 + 1, null, index == this.player.inventory.currentItem ? this.controller.getUseCooldown() : 0, this.controller.getUseCooldownMax(), 2);
|
||||
this.fbX / 2 - 180 + 4 + 1 + index * 40, this.fbY - 40 + 1, null, index == this.player.getSelectedIndex() ? this.controller.getUseCooldown() : 0, this.controller.getUseCooldownMax(), 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1367,7 +1366,11 @@ public class Client implements IThreadListener {
|
|||
if(this.zooming)
|
||||
this.zoomLevel = ExtMath.clampf(this.zoomLevel + (dir < 0 ? -0.25f : 0.25f), 2.0f, 16.0f);
|
||||
else if(this.player != null) {
|
||||
this.player.inventory.changeCurrentItem(dir);
|
||||
this.player.setSelectedIndex(this.player.getSelectedIndex() - dir);
|
||||
if(this.player.getSelectedIndex() < 0)
|
||||
this.player.setSelectedIndex(9 - 1);
|
||||
else if(this.player.getSelectedIndex() >= 9)
|
||||
this.player.setSelectedIndex(0);
|
||||
this.controller.resetUseCooldown();
|
||||
}
|
||||
}
|
||||
|
@ -1384,7 +1387,7 @@ public class Client implements IThreadListener {
|
|||
if(this.player != null) {
|
||||
if(this.getNetHandler() != null)
|
||||
this.getNetHandler().addToSendQueue(new CPacketAction(CPacketAction.Action.CLOSE_CONTAINER, this.player.openContainer.windowId));
|
||||
this.player.inventory.setItemStack(null);
|
||||
this.player.setMouseItem(null);
|
||||
this.player.openContainer = this.player.inventoryContainer;
|
||||
}
|
||||
if (this.open != null)
|
||||
|
@ -1451,13 +1454,13 @@ public class Client implements IThreadListener {
|
|||
}
|
||||
else
|
||||
{
|
||||
ItemStack itemstack = this.player.inventory.getCurrentItem();
|
||||
ItemStack itemstack = this.player.getHeldItem();
|
||||
if ((this.pointed.type != ObjectType.BLOCK || this.world.getState(this.pointed.block).getBlock() == Blocks.air) && itemstack != null && itemstack.getItem().onAction(itemstack, this.player, this.world, ItemControl.PRIMARY, null))
|
||||
{
|
||||
this.player.swingItem();
|
||||
this.player.client.addToSendQueue(new CPacketAction(Action.ITEM_ACTION, ItemControl.PRIMARY.ordinal()));
|
||||
if(this.player.getHeldItem() != null && this.player.getHeldItem().isEmpty())
|
||||
this.player.inventory.mainInventory[this.player.inventory.currentItem] = null;
|
||||
this.player.setHeldItem(null);
|
||||
this.leftClickCounter = 10;
|
||||
return;
|
||||
}
|
||||
|
@ -1493,7 +1496,7 @@ public class Client implements IThreadListener {
|
|||
{
|
||||
this.rightClickTimer = 4;
|
||||
boolean flag = true;
|
||||
ItemStack itemstack = this.player.inventory.getCurrentItem();
|
||||
ItemStack itemstack = this.player.getHeldItem();
|
||||
|
||||
if (itemstack != null && itemstack.getItem() == Items.camera && !this.saving)
|
||||
{
|
||||
|
@ -1511,7 +1514,7 @@ public class Client implements IThreadListener {
|
|||
this.player.swingItem();
|
||||
this.player.client.addToSendQueue(new CPacketAction(Action.ITEM_ACTION, ItemControl.SECONDARY.ordinal()));
|
||||
if(this.player.getHeldItem() != null && this.player.getHeldItem().isEmpty())
|
||||
this.player.inventory.mainInventory[this.player.inventory.currentItem] = null;
|
||||
this.player.setHeldItem(null);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1545,7 +1548,7 @@ public class Client implements IThreadListener {
|
|||
|
||||
if (itemstack.isEmpty())
|
||||
{
|
||||
this.player.inventory.mainInventory[this.player.inventory.currentItem] = null;
|
||||
this.player.setHeldItem(null);
|
||||
}
|
||||
else if (itemstack.getSize() != i)
|
||||
{
|
||||
|
@ -1557,7 +1560,7 @@ public class Client implements IThreadListener {
|
|||
|
||||
if (flag)
|
||||
{
|
||||
ItemStack itemstack1 = this.player.inventory.getCurrentItem();
|
||||
ItemStack itemstack1 = this.player.getHeldItem();
|
||||
|
||||
if (itemstack1 != null && this.controller.sendUseItem(this.player, this.world, itemstack1))
|
||||
{
|
||||
|
@ -1574,7 +1577,7 @@ public class Client implements IThreadListener {
|
|||
if(this.player.getHeldItem() != null && this.player.getHeldItem().getItem().onAction(this.player.getHeldItem(), this.player, this.world, ItemControl.TERTIARY, null)) {
|
||||
this.player.client.addToSendQueue(new CPacketAction(Action.ITEM_ACTION, ItemControl.TERTIARY.ordinal()));
|
||||
if(this.player.getHeldItem() != null && this.player.getHeldItem().isEmpty())
|
||||
this.player.inventory.mainInventory[this.player.inventory.currentItem] = null;
|
||||
this.player.setHeldItem(null);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1586,12 +1589,13 @@ public class Client implements IThreadListener {
|
|||
if(item == null)
|
||||
return;
|
||||
|
||||
InventoryPlayer inventoryplayer = this.player.inventory;
|
||||
|
||||
if(inventoryplayer.setCurrentItem(item))
|
||||
int idx = this.player.getInventorySlotContainItem(item);
|
||||
if(idx >= 0 && idx < 9) {
|
||||
this.player.setSelectedIndex(idx);
|
||||
this.controller.resetUseCooldown();
|
||||
}
|
||||
if(this.itemCheat) {
|
||||
this.player.client.addToSendQueue(new CPacketCheat(item, -2 - inventoryplayer.currentItem, this.ctrl()));
|
||||
this.player.client.addToSendQueue(new CPacketCheat(item, -2 - this.player.getSelectedIndex(), this.ctrl()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1603,7 +1607,7 @@ public class Client implements IThreadListener {
|
|||
if(this.player.getHeldItem() != null && this.player.getHeldItem().getItem().onAction(this.player.getHeldItem(), this.player, this.world, ItemControl.QUARTERNARY, null)) {
|
||||
this.player.client.addToSendQueue(new CPacketAction(Action.ITEM_ACTION, ItemControl.QUARTERNARY.ordinal()));
|
||||
if(this.player.getHeldItem() != null && this.player.getHeldItem().isEmpty())
|
||||
this.player.inventory.mainInventory[this.player.inventory.currentItem] = null;
|
||||
this.player.setHeldItem(null);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue