mirror of
https://github.com/HbmMods/Hbm-s-Nuclear-Tech-GIT.git
synced 2026-08-10 17:55:44 +00:00
this bitch actually works
This commit is contained in:
parent
ab1e78b2a7
commit
a186c75111
@ -6,13 +6,18 @@ import java.util.Comparator;
|
|||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
import com.hbm.inventory.SlotNonRetarded;
|
import com.hbm.inventory.SlotNonRetarded;
|
||||||
|
import com.hbm.inventory.container.ContainerPneumoStorageAccess.InventoryPneumoStorageAccess;
|
||||||
|
import com.hbm.inventory.container.ContainerPneumoStorageAccess.SlotPneumo;
|
||||||
|
import com.hbm.main.MainRegistry;
|
||||||
import com.hbm.packet.PacketDispatcher;
|
import com.hbm.packet.PacketDispatcher;
|
||||||
import com.hbm.packet.toclient.ContainerNBTCommsPacket;
|
import com.hbm.packet.toclient.ContainerNBTCommsPacket;
|
||||||
import com.hbm.tileentity.network.pneumatic.TileEntityPneumoStorageAccess;
|
import com.hbm.tileentity.network.pneumatic.TileEntityPneumoStorageAccess;
|
||||||
import com.hbm.util.EnumUtil;
|
import com.hbm.util.EnumUtil;
|
||||||
|
import com.hbm.util.InventoryUtil;
|
||||||
|
|
||||||
import api.hbm.ntl.StackCache;
|
import api.hbm.ntl.StackCache;
|
||||||
import api.hbm.ntl.StackCache.CacheSlot;
|
import api.hbm.ntl.StackCache.CacheSlot;
|
||||||
@ -22,7 +27,6 @@ import net.minecraft.entity.player.EntityPlayerMP;
|
|||||||
import net.minecraft.entity.player.InventoryPlayer;
|
import net.minecraft.entity.player.InventoryPlayer;
|
||||||
import net.minecraft.inventory.Container;
|
import net.minecraft.inventory.Container;
|
||||||
import net.minecraft.inventory.ICrafting;
|
import net.minecraft.inventory.ICrafting;
|
||||||
import net.minecraft.inventory.IInventory;
|
|
||||||
import net.minecraft.inventory.Slot;
|
import net.minecraft.inventory.Slot;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
@ -33,12 +37,28 @@ public class ContainerPneumoStorageAccessMK2 extends Container implements ICusto
|
|||||||
|
|
||||||
protected TileEntityPneumoStorageAccess access;
|
protected TileEntityPneumoStorageAccess access;
|
||||||
protected InventoryPneumoStorageAccess inventory;
|
protected InventoryPneumoStorageAccess inventory;
|
||||||
|
protected EntityPlayer player;
|
||||||
|
protected String searchString = "";
|
||||||
|
|
||||||
|
public static boolean detailedSearch = false;
|
||||||
|
|
||||||
/** On the server, this is used to find changes in the system and then send them to the client. On the client, this is just to keep track of all items. */
|
/** On the server, this is used to find changes in the system and then send them to the client. On the client, this is just to keep track of all items. */
|
||||||
protected LinkedHashMap<Long, CacheSlotDummy> cachedEntries = new LinkedHashMap();
|
protected LinkedHashMap<Long, CacheSlotDummy> cachedEntries = new LinkedHashMap();
|
||||||
/** Server to client queue, contains NBT tags that represents deltas yet to be sent to the client */
|
/** Server to client queue, contains NBT tags that represents deltas yet to be sent to the client */
|
||||||
public LinkedList<NBTTagCompound> s2cQueue = new LinkedList();
|
public LinkedList<NBTTagCompound> s2cQueue = new LinkedList();
|
||||||
|
|
||||||
|
public void setSorter(Comparator<CacheSlotDummy> sorter) {
|
||||||
|
this.listingStart = 0;
|
||||||
|
this.sorter = sorter;
|
||||||
|
this.rebuildClientIndex();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSearchString(String search) {
|
||||||
|
this.listingStart = 0;
|
||||||
|
this.searchString = search.toLowerCase(Locale.US);
|
||||||
|
this.rebuildClientIndex();
|
||||||
|
}
|
||||||
|
|
||||||
/** Used to temporarily store the previous CacheSlot contents to calculate deltas with (i.e. detect changes) */
|
/** Used to temporarily store the previous CacheSlot contents to calculate deltas with (i.e. detect changes) */
|
||||||
public static class CacheSlotDummy {
|
public static class CacheSlotDummy {
|
||||||
|
|
||||||
@ -64,11 +84,12 @@ public class ContainerPneumoStorageAccessMK2 extends Container implements ICusto
|
|||||||
|
|
||||||
public static final int GRID_SIZE = 6 * 8;
|
public static final int GRID_SIZE = 6 * 8;
|
||||||
public static final int DELTAS_PER_MSG = 6 * 8;
|
public static final int DELTAS_PER_MSG = 6 * 8;
|
||||||
|
|
||||||
public int listingStart = 0;
|
public int listingStart = 0;
|
||||||
|
public int listingSize = 0;
|
||||||
|
|
||||||
public int getStackCount() {
|
public int getStackCount() {
|
||||||
return cachedEntries.size();
|
return listingSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Serverside, creates a new delta for a new item stack */
|
/** Serverside, creates a new delta for a new item stack */
|
||||||
@ -137,38 +158,79 @@ public class ContainerPneumoStorageAccessMK2 extends Container implements ICusto
|
|||||||
this.pushNewItem(existingCache.displayStack, existingCache.stacksize);
|
this.pushNewItem(existingCache.displayStack, existingCache.stacksize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(player instanceof EntityPlayerMP) processDeltasAndSync((EntityPlayerMP) this.player);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ContainerPneumoStorageAccessMK2(InventoryPlayer invPlayer, TileEntityPneumoStorageAccess access) {
|
public ContainerPneumoStorageAccessMK2(InventoryPlayer invPlayer, TileEntityPneumoStorageAccess access) {
|
||||||
this.access = access;
|
this.access = access;
|
||||||
this.inventory = new InventoryPneumoStorageAccess(access);
|
this.inventory = new InventoryPneumoStorageAccess(access);
|
||||||
|
this.player = invPlayer.player;
|
||||||
|
|
||||||
|
int hOffset = 34;
|
||||||
|
|
||||||
for(int i = 0; i < 6; i++) for(int j = 0; j < 8; j++) {
|
for(int i = 0; i < 6; i++) for(int j = 0; j < 8; j++) {
|
||||||
this.addSlotToContainer(new SlotPneumo(inventory, j + i * 8, 8 + j * 18, 17 + i * 18));
|
this.addSlotToContainer(new SlotPneumo(inventory, j + i * 8, 8 + j * 18 + hOffset, 17 + i * 18));
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int i = 0; i < 3; i++) for(int j = 0; j < 9; j++) {
|
for(int i = 0; i < 3; i++) for(int j = 0; j < 9; j++) {
|
||||||
this.addSlotToContainer(new SlotNonRetarded(invPlayer, j + i * 9 + 9, 8 + j * 18, 169 + i * 18));
|
this.addSlotToContainer(new SlotNonRetarded(invPlayer, j + i * 9 + 9, 8 + j * 18 + hOffset, 169 + i * 18));
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int i = 0; i < 9; i++) {
|
for(int i = 0; i < 9; i++) {
|
||||||
this.addSlotToContainer(new SlotNonRetarded(invPlayer, i, 8 + i * 18, 227));
|
this.addSlotToContainer(new SlotNonRetarded(invPlayer, i, 8 + i * 18 + hOffset, 227));
|
||||||
}
|
}
|
||||||
|
|
||||||
this.detectAndSendChanges();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack slotClick(int index, int button, int mode, EntityPlayer player) {
|
public ItemStack slotClick(int index, int button, int mode, EntityPlayer player) {
|
||||||
if(mode == 6) return null;
|
if(mode == 6) return null;
|
||||||
|
|
||||||
|
if(index == ContainerPneumoStorageAccess.SLOT_CLICK_ID_REFRESH) {
|
||||||
|
this.listingStart = mode;
|
||||||
|
this.detectAndSendChanges();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean client = player.worldObj.isRemote;
|
||||||
boolean leftClick = button == 0 && mode == 0;
|
boolean leftClick = button == 0 && mode == 0;
|
||||||
boolean rightClick = button == 1 && mode == 0;
|
boolean rightClick = button == 1 && mode == 0;
|
||||||
boolean shiftClick = button == 0 && mode == 1;
|
boolean shiftClick = button == 0 && mode == 1;
|
||||||
|
|
||||||
if(index >= 0 && index < GRID_SIZE) {
|
if(index >= 0 && index < GRID_SIZE) {
|
||||||
|
if(!client) return null;
|
||||||
// TODO: in this new version, the server has no fucking idea what slot we are even clicking on
|
SlotPneumo slot = (SlotPneumo) this.getSlot(index);
|
||||||
|
long hash = StackCache.getStackIdentity(slot.getStack());
|
||||||
|
ItemStack held = player.inventory.getItemStack();
|
||||||
|
long heldHash = StackCache.getStackIdentity(held);
|
||||||
|
if(leftClick) {
|
||||||
|
if(held != null && hash != heldHash) held = null;
|
||||||
|
else if(held != null && hash == heldHash) {
|
||||||
|
held.stackSize += slot.amount;
|
||||||
|
held.stackSize = Math.min(held.stackSize, held.getMaxStackSize());
|
||||||
|
} else if(held == null && slot.getHasStack()) {
|
||||||
|
held = slot.getStack().copy();
|
||||||
|
held.stackSize = (int) Math.min(slot.amount, held.getMaxStackSize());
|
||||||
|
}
|
||||||
|
this.player.inventory.setItemStack(held);
|
||||||
|
sendClickToServer(ClickType.LEFT_CLICK, hash);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if(rightClick) {
|
||||||
|
if(held != null && hash != heldHash) held.stackSize--;
|
||||||
|
else if(held != null && hash == heldHash) {
|
||||||
|
held.stackSize += 1;
|
||||||
|
held.stackSize = Math.min(held.stackSize, held.getMaxStackSize());
|
||||||
|
} else if(held == null && slot.getHasStack()) {
|
||||||
|
held = slot.getStack().copy();
|
||||||
|
held.stackSize = 1;
|
||||||
|
}
|
||||||
|
if(held.stackSize <= 0) held = null;
|
||||||
|
this.player.inventory.setItemStack(held);
|
||||||
|
sendClickToServer(ClickType.RIGHT_CLICK, hash);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if(shiftClick) { sendClickToServer(ClickType.SHIFT_CLICK, hash); return null; }
|
||||||
|
|
||||||
// shift clicking an item from the player inv to the storage
|
// shift clicking an item from the player inv to the storage
|
||||||
} else if(index >= GRID_SIZE && index < this.inventorySlots.size()) {
|
} else if(index >= GRID_SIZE && index < this.inventorySlots.size()) {
|
||||||
@ -184,12 +246,21 @@ public class ContainerPneumoStorageAccessMK2 extends Container implements ICusto
|
|||||||
if(remainder <= 0) slot.putStack(null);
|
if(remainder <= 0) slot.putStack(null);
|
||||||
slot.onSlotChanged();
|
slot.onSlotChanged();
|
||||||
detectAndSendChanges();
|
detectAndSendChanges();
|
||||||
|
return null; // technically not needed but we don't have to run 500,000 lines of code that ends up doing nothing
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return super.slotClick(index, button, mode, player);
|
return super.slotClick(index, button, mode, player);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void sendClickToServer(ClickType type, long hash) {
|
||||||
|
|
||||||
|
NBTTagCompound data = new NBTTagCompound();
|
||||||
|
data.setByte("type", (byte) type.ordinal());
|
||||||
|
data.setLong("hash", hash);
|
||||||
|
PacketDispatcher.wrapper.sendToServer(new ContainerNBTCommsPacket(this.windowId, data));
|
||||||
|
}
|
||||||
|
|
||||||
public long[] previousStackSizes = new long[GRID_SIZE];
|
public long[] previousStackSizes = new long[GRID_SIZE];
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -224,11 +295,18 @@ public class ContainerPneumoStorageAccessMK2 extends Container implements ICusto
|
|||||||
return access.getDistanceFrom(player.posX, player.posY, player.posZ) <= 15 * 15;
|
return access.getDistanceFrom(player.posX, player.posY, player.posZ) <= 15 * 15;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** For S2C to send deltas updating the available items */
|
||||||
public static enum DeltaType {
|
public static enum DeltaType {
|
||||||
NEW_TYPE,
|
NEW_TYPE,
|
||||||
COUNT_CHANGE;
|
COUNT_CHANGE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static enum ClickType {
|
||||||
|
LEFT_CLICK,
|
||||||
|
RIGHT_CLICK,
|
||||||
|
SHIFT_CLICK
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void acceptData(Side side, int windowId, NBTTagCompound data) {
|
public void acceptData(Side side, int windowId, NBTTagCompound data) {
|
||||||
if(windowId != this.windowId) return;
|
if(windowId != this.windowId) return;
|
||||||
@ -253,29 +331,107 @@ public class ContainerPneumoStorageAccessMK2 extends Container implements ICusto
|
|||||||
if(dummy != null) dummy.stacksize = line.getLong("amount");
|
if(dummy != null) dummy.stacksize = line.getLong("amount");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rebuildClientIndex();
|
||||||
|
|
||||||
|
} else {
|
||||||
|
if(this.access.cache == null || this.access.cache.hasExpired) return;
|
||||||
|
ClickType type = EnumUtil.grabEnumSafely(ClickType.class, data.getByte("type"));
|
||||||
|
long hash = data.getLong("hash");
|
||||||
|
CacheSlotDummy cache = this.cachedEntries.get(hash);
|
||||||
|
ItemStack held = this.player.inventory.getItemStack();
|
||||||
|
long heldHash = StackCache.getStackIdentity(held);
|
||||||
|
|
||||||
|
// left click
|
||||||
|
if(type == ClickType.LEFT_CLICK || type == ClickType.RIGHT_CLICK) {
|
||||||
|
|
||||||
|
// if we drop an item onto a different stack, or no stack at all, deposit
|
||||||
|
if(hash != heldHash && held != null) {
|
||||||
|
int toDeposit = type == ClickType.LEFT_CLICK ? held.stackSize : 1;
|
||||||
|
held.stackSize -= toDeposit;
|
||||||
|
int leftover = (int) this.access.cache.addItemsAndReturnQuantity(held, toDeposit);
|
||||||
|
held.stackSize += leftover;
|
||||||
|
this.player.inventory.setItemStack(null);
|
||||||
|
if(held.stackSize > 0) InventoryUtil.tryAddItemToInventory(player.inventory.mainInventory, held);
|
||||||
|
detectAndSendChanges();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// if our hand is empty or we have the same type, withdraw
|
||||||
|
if(cache != null && (held == null || hash == heldHash)) {
|
||||||
|
ItemStack stack = cache.displayStack.copy();
|
||||||
|
int alreadyHeld = held == null ? 0 : held.stackSize;
|
||||||
|
int capacity = stack.getMaxStackSize() - alreadyHeld;
|
||||||
|
if(type == ClickType.RIGHT_CLICK && capacity > 1) capacity = 1;
|
||||||
|
int toGrab = (int) Math.min(capacity, cache.stacksize);
|
||||||
|
int grabbed = (int) this.access.cache.consumeItemsAndReturnQuantity(stack, toGrab);
|
||||||
|
stack.stackSize = alreadyHeld + grabbed;
|
||||||
|
this.player.inventory.setItemStack(stack);
|
||||||
|
detectAndSendChanges();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(type == ClickType.SHIFT_CLICK && cache != null) {
|
||||||
|
ItemStack stack = cache.displayStack.copy();
|
||||||
|
int originalStacksize = (int) Math.min(stack.getMaxStackSize(), cache.stacksize);
|
||||||
|
stack.stackSize = originalStacksize;
|
||||||
|
ItemStack ret = InventoryUtil.tryAddItemToInventory(player.inventory.mainInventory, stack);
|
||||||
|
int remainder = ret == null ? 0 : ret.stackSize;
|
||||||
|
int itemsUsed = originalStacksize - remainder;
|
||||||
|
this.access.cache.consumeItemsAndReturnQuantity(stack, itemsUsed);
|
||||||
|
detectAndSendChanges();
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int startingIndex;
|
|
||||||
|
|
||||||
public void rebuildClientIndex() {
|
public void rebuildClientIndex() {
|
||||||
|
|
||||||
List<CacheSlotDummy> cacheSlots = new ArrayList(this.cachedEntries.size());
|
List<CacheSlotDummy> cacheSlots = new ArrayList(this.cachedEntries.size());
|
||||||
cacheSlots.addAll(this.cachedEntries.values());
|
cacheSlots.addAll(this.cachedEntries.values());
|
||||||
cacheSlots.removeIf(x -> { return x.stacksize <= 0; });
|
cacheSlots.removeIf(x -> { return x.stacksize <= 0; });
|
||||||
Collections.sort(cacheSlots, SORT_BY_STACK_SIZE);
|
|
||||||
|
if(this.searchString != null && !this.searchString.isEmpty()) {
|
||||||
|
if(!detailedSearch) {
|
||||||
|
cacheSlots.removeIf(x -> {
|
||||||
|
return !x.displayStack.getDisplayName().toLowerCase(Locale.US).contains(searchString);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
cacheSlots.removeIf(x -> {
|
||||||
|
boolean contains = x.displayStack.getDisplayName().toLowerCase(Locale.US).contains(searchString);
|
||||||
|
List<String> toolTip = new ArrayList();
|
||||||
|
if(!contains) {
|
||||||
|
x.displayStack.getItem().addInformation(x.displayStack, MainRegistry.proxy.me(), toolTip, MainRegistry.proxy.advancedTooltips());
|
||||||
|
for(String string : toolTip) {
|
||||||
|
if(string.toLowerCase(Locale.US).contains(searchString)) {
|
||||||
|
contains = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return !contains;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
listingSize = cacheSlots.size();
|
||||||
|
Collections.sort(cacheSlots, this.sorter);
|
||||||
int size = cacheSlots.size();
|
int size = cacheSlots.size();
|
||||||
|
|
||||||
int offset = startingIndex * 8;
|
int offset = listingStart * 8;
|
||||||
|
|
||||||
for(int i = 0; i < inventory.slots.length; i++) {
|
for(int i = 0; i < inventory.slots.length; i++) {
|
||||||
int grabIndex = offset + i;
|
int grabIndex = offset + i;
|
||||||
if(grabIndex < size) {
|
if(grabIndex < size) {
|
||||||
CacheSlotDummy cacheSlot = cacheSlots.get(grabIndex);
|
CacheSlotDummy cacheSlot = cacheSlots.get(grabIndex);
|
||||||
|
SlotPneumo slot = (SlotPneumo) this.inventorySlots.get(i);
|
||||||
if(cacheSlot.displayStack != null) {
|
if(cacheSlot.displayStack != null) {
|
||||||
inventory.slots[i] = cacheSlot.displayStack.copy();
|
slot.putStack(cacheSlot.displayStack.copy());
|
||||||
|
slot.amount = cacheSlot.stacksize;
|
||||||
} else {
|
} else {
|
||||||
inventory.slots[i] = null;
|
slot.putStack(null);
|
||||||
|
slot.amount = 0;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
inventory.slots[i] = null;
|
inventory.slots[i] = null;
|
||||||
@ -326,59 +482,11 @@ public class ContainerPneumoStorageAccessMK2 extends Container implements ICusto
|
|||||||
return SORT_BY_ID.compare(o1, o2);
|
return SORT_BY_ID.compare(o1, o2);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
protected static Comparator<CacheSlotDummy> sorter = SORT_BY_STACK_SIZE;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack transferStackInSlot(EntityPlayer player, int index) {
|
public ItemStack transferStackInSlot(EntityPlayer player, int index) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class SlotPneumo extends SlotNonRetarded {
|
|
||||||
|
|
||||||
public long amount;
|
|
||||||
|
|
||||||
public SlotPneumo(IInventory inventory, int id, int x, int y) {
|
|
||||||
super(inventory, id, x, y);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canTakeStack(EntityPlayer player) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** This inventory instance only exists to prepare the contents of a StackCache in such a way that we can use it in a container. */
|
|
||||||
public static class InventoryPneumoStorageAccess implements IInventory {
|
|
||||||
|
|
||||||
public StackCache cache;
|
|
||||||
public ItemStack[] slots;
|
|
||||||
|
|
||||||
public InventoryPneumoStorageAccess(TileEntityPneumoStorageAccess access) {
|
|
||||||
this.slots = new ItemStack[getSizeInventory()];
|
|
||||||
this.cache = access.cache;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override public int getSizeInventory() { return GRID_SIZE; }
|
|
||||||
@Override public ItemStack getStackInSlot(int slot) { return slots[slot]; }
|
|
||||||
@Override public int getInventoryStackLimit() { return 1; }
|
|
||||||
@Override public ItemStack decrStackSize(int slot, int amount) { return null; }
|
|
||||||
@Override public void setInventorySlotContents(int slot, ItemStack stack) { this.slots[slot] = stack; }
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ItemStack getStackInSlotOnClosing(int slot) {
|
|
||||||
if(slots[slot] != null) {
|
|
||||||
ItemStack stack = slots[slot];
|
|
||||||
slots[slot] = null;
|
|
||||||
return stack;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override public String getInventoryName() { return "null"; }
|
|
||||||
@Override public boolean hasCustomInventoryName() { return false; }
|
|
||||||
@Override public boolean isItemValidForSlot(int slot, ItemStack stack) { return false; }
|
|
||||||
@Override public void markDirty() { }
|
|
||||||
@Override public boolean isUseableByPlayer(EntityPlayer player) { return true; }
|
|
||||||
@Override public void openInventory() { }
|
|
||||||
@Override public void closeInventory() { }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,11 +8,10 @@ import org.lwjgl.opengl.GL11;
|
|||||||
|
|
||||||
import static com.hbm.inventory.gui.element.GUIElements.*;
|
import static com.hbm.inventory.gui.element.GUIElements.*;
|
||||||
import com.hbm.inventory.container.ContainerPneumoStorageAccessMK2;
|
import com.hbm.inventory.container.ContainerPneumoStorageAccessMK2;
|
||||||
import com.hbm.inventory.container.ContainerPneumoStorageAccessMK2.SlotPneumo;
|
import com.hbm.inventory.container.ContainerPneumoStorageAccess;
|
||||||
|
import com.hbm.inventory.container.ContainerPneumoStorageAccess.SlotPneumo;
|
||||||
import com.hbm.inventory.gui.element.GUIElements;
|
import com.hbm.inventory.gui.element.GUIElements;
|
||||||
import com.hbm.lib.RefStrings;
|
import com.hbm.lib.RefStrings;
|
||||||
import com.hbm.packet.PacketDispatcher;
|
|
||||||
import com.hbm.packet.toclient.ContainerNBTCommsPacket;
|
|
||||||
import com.hbm.tileentity.network.pneumatic.TileEntityPneumoStorageAccess;
|
import com.hbm.tileentity.network.pneumatic.TileEntityPneumoStorageAccess;
|
||||||
import com.hbm.util.BobMathUtil;
|
import com.hbm.util.BobMathUtil;
|
||||||
|
|
||||||
@ -23,7 +22,6 @@ import net.minecraft.client.renderer.RenderHelper;
|
|||||||
import net.minecraft.client.resources.I18n;
|
import net.minecraft.client.resources.I18n;
|
||||||
import net.minecraft.entity.player.InventoryPlayer;
|
import net.minecraft.entity.player.InventoryPlayer;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
|
||||||
import net.minecraft.util.EnumChatFormatting;
|
import net.minecraft.util.EnumChatFormatting;
|
||||||
import net.minecraft.util.MathHelper;
|
import net.minecraft.util.MathHelper;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
@ -32,18 +30,24 @@ public class GUIPneumoStorageAccess extends GuiInfoContainer {
|
|||||||
|
|
||||||
private static ResourceLocation texture = new ResourceLocation(RefStrings.MODID + ":textures/gui/storage/gui_pneumatic_access.png");
|
private static ResourceLocation texture = new ResourceLocation(RefStrings.MODID + ":textures/gui/storage/gui_pneumatic_access.png");
|
||||||
protected TileEntityPneumoStorageAccess access;
|
protected TileEntityPneumoStorageAccess access;
|
||||||
|
protected ContainerPneumoStorageAccessMK2 container;
|
||||||
protected GuiTextField search;
|
protected GuiTextField search;
|
||||||
|
|
||||||
protected int scrollIndex = 0;
|
protected int scrollIndex = 0;
|
||||||
protected int scrollBounds = 0;
|
protected int scrollBounds = 1;
|
||||||
protected boolean wasClicking = false;
|
protected boolean wasClicking = false;
|
||||||
protected boolean draggingScroll = false;
|
protected boolean draggingScroll = false;
|
||||||
|
protected boolean wasMouseinGUI = false;
|
||||||
|
|
||||||
|
protected static int sorting = 0;
|
||||||
|
protected static boolean startFocussed = false;
|
||||||
|
|
||||||
public GUIPneumoStorageAccess(InventoryPlayer invPlayer, TileEntityPneumoStorageAccess access) {
|
public GUIPneumoStorageAccess(InventoryPlayer invPlayer, TileEntityPneumoStorageAccess access) {
|
||||||
super(new ContainerPneumoStorageAccessMK2(invPlayer, access));
|
super(new ContainerPneumoStorageAccessMK2(invPlayer, access));
|
||||||
|
this.container = (ContainerPneumoStorageAccessMK2) this.inventorySlots;
|
||||||
this.access = access;
|
this.access = access;
|
||||||
|
|
||||||
this.xSize = 176;
|
this.xSize = 176 + 34;
|
||||||
this.ySize = 251;
|
this.ySize = 251;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,18 +56,21 @@ public class GUIPneumoStorageAccess extends GuiInfoContainer {
|
|||||||
super.initGui();
|
super.initGui();
|
||||||
|
|
||||||
Keyboard.enableRepeatEvents(true);
|
Keyboard.enableRepeatEvents(true);
|
||||||
search = new GuiTextField(this.fontRendererObj, guiLeft + 43, guiTop + 127, 90, 12);
|
search = new GuiTextField(this.fontRendererObj, guiLeft + 45 + 34, guiTop + 127, 86, 12);
|
||||||
search.setTextColor(0xffffff);
|
search.setTextColor(0xffffff);
|
||||||
search.setDisabledTextColour(0xa0a0a0);
|
search.setDisabledTextColour(0xa0a0a0);
|
||||||
search.setEnableBackgroundDrawing(false);
|
search.setEnableBackgroundDrawing(false);
|
||||||
search.setMaxStringLength(50);
|
search.setMaxStringLength(50);
|
||||||
search.setText("");
|
search.setText("");
|
||||||
|
|
||||||
|
if(this.startFocussed) search.setFocused(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drawScreen(int x, int y, float interp) {
|
public void drawScreen(int x, int y, float interp) {
|
||||||
|
|
||||||
ContainerPneumoStorageAccessMK2 container = (ContainerPneumoStorageAccessMK2) this.inventorySlots;
|
this.wasMouseinGUI = this.checkClick(x, y, 0, 0, xSize, ySize);
|
||||||
|
|
||||||
this.scrollBounds = (int) Math.ceil(container.getStackCount() / 8D - 6D);
|
this.scrollBounds = (int) Math.ceil(container.getStackCount() / 8D - 6D);
|
||||||
if(this.scrollBounds < 1) this.scrollBounds = 1;
|
if(this.scrollBounds < 1) this.scrollBounds = 1;
|
||||||
if(this.scrollIndex < 0) this.setScroll(0);
|
if(this.scrollIndex < 0) this.setScroll(0);
|
||||||
@ -72,7 +79,7 @@ public class GUIPneumoStorageAccess extends GuiInfoContainer {
|
|||||||
boolean isClicking = Mouse.isButtonDown(0);
|
boolean isClicking = Mouse.isButtonDown(0);
|
||||||
if(!isClicking) this.draggingScroll = false;
|
if(!isClicking) this.draggingScroll = false;
|
||||||
|
|
||||||
if(!wasClicking && isClicking && guiLeft + 153 <= x && guiLeft + 153 + 14 > x && guiTop + 16 < y && guiTop + 16 + 108 >= y) {
|
if(!wasClicking && isClicking && guiLeft + 153 + 34 <= x && guiLeft + 153 + 34 + 14 > x && guiTop + 16 < y && guiTop + 16 + 108 >= y) {
|
||||||
draggingScroll = true;
|
draggingScroll = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,34 +94,54 @@ public class GUIPneumoStorageAccess extends GuiInfoContainer {
|
|||||||
this.wasClicking = isClicking;
|
this.wasClicking = isClicking;
|
||||||
|
|
||||||
super.drawScreen(x, y, interp);
|
super.drawScreen(x, y, interp);
|
||||||
|
|
||||||
|
//TODO localization
|
||||||
|
this.drawCustomInfoStat(x, y, guiLeft + 7, guiTop + 7, 18, 18, x, y, "Sorting: " + EnumChatFormatting.YELLOW + "Amount");
|
||||||
|
this.drawCustomInfoStat(x, y, guiLeft + 7, guiTop + 25, 18, 18, x, y, "Sorting: " + EnumChatFormatting.YELLOW + "Item ID");
|
||||||
|
this.drawCustomInfoStat(x, y, guiLeft + 7, guiTop + 43, 18, 18, x, y, "Sorting: " + EnumChatFormatting.YELLOW + "Name");
|
||||||
|
this.drawCustomInfoStat(x, y, guiLeft + 7, guiTop + 61, 18, 18, x, y, "Sorting: " + EnumChatFormatting.YELLOW + "Internal Name");
|
||||||
|
|
||||||
|
this.drawCustomInfoStat(x, y, guiLeft + 7, guiTop + 79, 18, 18, x, y, "Focus search by default: " + (this.startFocussed ? EnumChatFormatting.GREEN + "ON" : EnumChatFormatting.RED + "OFF"));
|
||||||
|
this.drawCustomInfoStat(x, y, guiLeft + 7, guiTop + 97, 18, 18, x, y, "Inlude tooltips in search: " + (this.container.detailedSearch ? EnumChatFormatting.GREEN + "ON" : EnumChatFormatting.RED + "OFF"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void mouseClicked(int x, int y, int i) {
|
protected void mouseClicked(int x, int y, int i) {
|
||||||
super.mouseClicked(x, y, i);
|
super.mouseClicked(x, y, i);
|
||||||
|
|
||||||
|
if(this.checkClick(x, y, 7, 7, 18, 18)) { this.click(); this.sorting = 0; this.scrollIndex = 0; this.container.setSorter(this.container.SORT_BY_STACK_SIZE); }
|
||||||
|
if(this.checkClick(x, y, 7, 25, 18, 18)) { this.click(); this.sorting = 1; this.scrollIndex = 0; this.container.setSorter(this.container.SORT_BY_ID); }
|
||||||
|
if(this.checkClick(x, y, 7, 43, 18, 18)) { this.click(); this.sorting = 2; this.scrollIndex = 0; this.container.setSorter(this.container.SORT_BY_LOCALIZED); }
|
||||||
|
if(this.checkClick(x, y, 7, 61, 18, 18)) { this.click(); this.sorting = 3; this.scrollIndex = 0; this.container.setSorter(this.container.SORT_BY_INTERNAL); }
|
||||||
|
|
||||||
|
if(this.checkClick(x, y, 7, 79, 18, 18)) { this.click(); this.startFocussed = !this.startFocussed; }
|
||||||
|
if(this.checkClick(x, y, 7, 97, 18, 18)) { this.click(); this.container.detailedSearch = !this.container.detailedSearch; container.setSearchString(search.getText()); }
|
||||||
|
|
||||||
search.mouseClicked(x, y, i);
|
search.mouseClicked(x, y, i);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleMouseInput() {
|
public void handleMouseInput() {
|
||||||
super.handleMouseInput();
|
|
||||||
|
|
||||||
int scrollDir = Mouse.getEventDWheel();
|
int scrollDir = Mouse.getEventDWheel();
|
||||||
|
|
||||||
if(scrollDir != 0) {
|
if(scrollDir != 0 && wasMouseinGUI) {
|
||||||
|
|
||||||
if(scrollDir > 0) scrollDir = 1;
|
if(scrollDir > 0) scrollDir = 1;
|
||||||
if(scrollDir < 0) scrollDir = -1;
|
if(scrollDir < 0) scrollDir = -1;
|
||||||
this.setScroll(this.getScroll() - scrollDir);
|
this.setScroll(this.getScroll() - scrollDir);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
super.handleMouseInput();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void drawGuiContainerForegroundLayer(int i, int j) {
|
protected void drawGuiContainerForegroundLayer(int i, int j) {
|
||||||
String name = "container.pneumoStorageAccess";
|
String name = "container.pneumoStorageAccess";
|
||||||
|
|
||||||
this.fontRendererObj.drawString(name, this.xSize / 2 - this.fontRendererObj.getStringWidth(name) / 2, 5, 4210752);
|
this.fontRendererObj.drawString(name, 34 + 176 / 2 - this.fontRendererObj.getStringWidth(name) / 2, 5, 4210752);
|
||||||
this.fontRendererObj.drawString(I18n.format("container.inventory"), 8, this.ySize - 96 + 2, 4210752);
|
this.fontRendererObj.drawString(I18n.format("container.inventory"), 34 + 8, this.ySize - 96 + 2, 4210752);
|
||||||
|
|
||||||
GL11.glPushMatrix();
|
GL11.glPushMatrix();
|
||||||
RenderHelper.disableStandardItemLighting();
|
RenderHelper.disableStandardItemLighting();
|
||||||
@ -142,11 +169,20 @@ public class GUIPneumoStorageAccess extends GuiInfoContainer {
|
|||||||
protected void drawGuiContainerBackgroundLayer(float p_146976_1_, int p_146976_2_, int p_146976_3_) {
|
protected void drawGuiContainerBackgroundLayer(float p_146976_1_, int p_146976_2_, int p_146976_3_) {
|
||||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||||
Minecraft.getMinecraft().getTextureManager().bindTexture(texture);
|
Minecraft.getMinecraft().getTextureManager().bindTexture(texture);
|
||||||
drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize);
|
drawTexturedModalRect(guiLeft + 34, guiTop, 0, 0, 176, ySize);
|
||||||
|
|
||||||
drawTexturedModalRect(guiLeft + getScrollBarXPos(), guiTop + getScrollBarYPos(), draggingScroll ? 188 : 176, 0, 12, 15);
|
drawTexturedModalRect(guiLeft, guiTop, 176, 15, 32, 122);
|
||||||
|
|
||||||
|
drawTexturedModalRect(guiLeft + 7, guiTop + 7 + this.sorting * 18, 208, 0, 18, 18);
|
||||||
|
if(this.startFocussed) drawTexturedModalRect(guiLeft + 7, guiTop + 79, 208, 18, 18, 18);
|
||||||
|
if(this.container.detailedSearch) drawTexturedModalRect(guiLeft + 7, guiTop + 97, 208, 18, 18, 18);
|
||||||
|
|
||||||
|
drawTexturedModalRect(guiLeft + 34 + getScrollBarXPos(), guiTop + getScrollBarYPos(), draggingScroll ? 188 : 176, 0, 12, 15);
|
||||||
|
|
||||||
|
GL11.glPushMatrix();
|
||||||
|
GL11.glTranslated(0, 2, 0);
|
||||||
search.drawTextBox();
|
search.drawTextBox();
|
||||||
|
GL11.glPopMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getScrollBarXPos() {
|
public int getScrollBarXPos() {
|
||||||
@ -154,9 +190,13 @@ public class GUIPneumoStorageAccess extends GuiInfoContainer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int getScrollBarYPos() {
|
public int getScrollBarYPos() {
|
||||||
ContainerPneumoStorageAccessMK2 container = (ContainerPneumoStorageAccessMK2) this.inventorySlots;
|
|
||||||
int scrollArea = 106 - 15; // bar height minus the scroll knob's height
|
int scrollArea = 106 - 15; // bar height minus the scroll knob's height
|
||||||
double scrollProgress = (double) container.listingStart / (double) scrollBounds;
|
double scrollProgress = (double) container.listingStart / (double) scrollBounds;
|
||||||
|
if(scrollProgress > 1) {
|
||||||
|
scrollProgress = 1;
|
||||||
|
this.setScroll(scrollBounds);
|
||||||
|
refreshContainer();
|
||||||
|
}
|
||||||
int scrollYPos = 17 + (int) (scrollProgress * scrollArea);
|
int scrollYPos = 17 + (int) (scrollProgress * scrollArea);
|
||||||
return scrollYPos;
|
return scrollYPos;
|
||||||
}
|
}
|
||||||
@ -172,7 +212,7 @@ public class GUIPneumoStorageAccess extends GuiInfoContainer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void refreshContainer() {
|
public void refreshContainer() {
|
||||||
//this.mc.playerController.windowClick(this.inventorySlots.windowId, ContainerPneumoStorageAccessMK2.SLOT_CLICK_ID_REFRESH, 0, this.scrollIndex, this.mc.thePlayer);
|
this.mc.playerController.windowClick(this.inventorySlots.windowId, ContainerPneumoStorageAccess.SLOT_CLICK_ID_REFRESH, 0, this.scrollIndex, this.mc.thePlayer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -196,9 +236,8 @@ public class GUIPneumoStorageAccess extends GuiInfoContainer {
|
|||||||
protected void keyTyped(char c, int b) {
|
protected void keyTyped(char c, int b) {
|
||||||
|
|
||||||
if(search.textboxKeyTyped(c, b)) {
|
if(search.textboxKeyTyped(c, b)) {
|
||||||
NBTTagCompound data = new NBTTagCompound();
|
this.scrollIndex = 0;
|
||||||
data.setString("search", search.getText());
|
container.setSearchString(search.getText());
|
||||||
PacketDispatcher.wrapper.sendToServer(new ContainerNBTCommsPacket(this.inventorySlots.windowId, data));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -189,6 +189,9 @@ public class ClientProxy extends ServerProxy {
|
|||||||
GunFactoryClient.init();
|
GunFactoryClient.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean advancedTooltips() { return Minecraft.getMinecraft().gameSettings.advancedItemTooltips; }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void registerTileEntitySpecialRenderer() {
|
public void registerTileEntitySpecialRenderer() {
|
||||||
//test crap
|
//test crap
|
||||||
|
|||||||
@ -72,6 +72,8 @@ public class ServerProxy {
|
|||||||
public EntityPlayer me() {
|
public EntityPlayer me() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean advancedTooltips() { return false; }
|
||||||
|
|
||||||
public boolean isVanished(Entity e) {
|
public boolean isVanished(Entity e) {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@ -39,7 +39,7 @@ public class ContainerNBTCommsPacket implements IMessage {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IMessage onMessage(ContainerNBTCommsPacket m, MessageContext ctx) {
|
public IMessage onMessage(ContainerNBTCommsPacket m, MessageContext ctx) {
|
||||||
|
|
||||||
EntityPlayer player = ctx.side.isClient() ? MainRegistry.proxy.me() : ctx.getServerHandler().playerEntity;
|
EntityPlayer player = ctx.side.isClient() ? MainRegistry.proxy.me() : ctx.getServerHandler().playerEntity;
|
||||||
if(player.openContainer instanceof ICustomPayloadReceiver) {
|
if(player.openContainer instanceof ICustomPayloadReceiver) {
|
||||||
ICustomPayloadReceiver cus = (ICustomPayloadReceiver) player.openContainer;
|
ICustomPayloadReceiver cus = (ICustomPayloadReceiver) player.openContainer;
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 2.6 KiB |
Loading…
x
Reference in New Issue
Block a user