hell yeah, i have the power of god *pulls gun on cops*

This commit is contained in:
HbmMods 2026-06-16 19:40:09 +02:00
parent bb688e2f4b
commit 2e292f2a20
5 changed files with 133 additions and 12 deletions

View File

@ -37,9 +37,11 @@ public class SlotMonitor {
public NBTTagCompound nbt;
protected boolean hasAvailabilityChanged = false;
protected boolean forceTypeUpdate = false;
public SlotMonitor(int index, ISlotMonitorProvider parent) {
this.hasAvailabilityChanged = true;
this.forceTypeUpdate = true;
this.index = index;
this.parent = parent;
}
@ -101,7 +103,7 @@ public class SlotMonitor {
else if(nbt != null && stack.hasTagCompound() && !nbt.equals(stack.stackTagCompound)) hasTypeChanged = true;
}
if(hasTypeChanged) {
if(hasTypeChanged || forceTypeUpdate) {
// remove from all existing monitors
Iterator<CacheSlot> iterator = viewedBy.iterator();
@ -134,6 +136,7 @@ public class SlotMonitor {
}
}
forceTypeUpdate = false;
return;
}

View File

@ -44,6 +44,8 @@ public class StackCache {
}
cache.addMonitor(monitor);
System.out.println(monitor.toZeroStack() + " " + cache.monitors.size());
}
public CacheSlot getSlotFromStack(ItemStack stack) {
@ -195,6 +197,7 @@ public class StackCache {
}
public static long getStackIdentity(Item item, int meta, NBTTagCompound nbt) {
if(item == null) return getNullIdentity();
long identity = Item.getIdFromItem(item) * 27644437;
identity += meta * 27644437;
if(nbt != null) identity += nbt.toString().hashCode();

View File

@ -4,9 +4,14 @@ import com.hbm.main.MainRegistry;
import com.hbm.tileentity.network.pneumatic.TileEntityPneumoStorageClutter;
import cpw.mods.fml.common.network.internal.FMLNetworkHandler;
import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
@ -30,4 +35,36 @@ public class PneumoStorageClutter extends BlockContainer {
}
return false;
}
@Override
public void breakBlock(World world, int x, int y, int z, Block block, int meta) {
TileEntity te = world.getTileEntity(x, y, z);
if(!(te instanceof ISidedInventory)) return;
ISidedInventory tileentityfurnace = (ISidedInventory) te;
if(tileentityfurnace != null) {
for(int i1 = 0; i1 < tileentityfurnace.getSizeInventory(); ++i1) {
ItemStack itemstack = tileentityfurnace.getStackInSlot(i1);
if(itemstack != null) {
float f = world.rand.nextFloat() * 0.8F + 0.1F;
float f1 = world.rand.nextFloat() * 0.8F + 0.1F;
float f2 = world.rand.nextFloat() * 0.8F + 0.1F;
while(itemstack.stackSize > 0) {
int j1 = world.rand.nextInt(21) + 10;
if(j1 > itemstack.stackSize) j1 = itemstack.stackSize;
itemstack.stackSize -= j1;
EntityItem entityitem = new EntityItem(world, x + f, y + f1, z + f2, new ItemStack(itemstack.getItem(), j1, itemstack.getItemDamage()));
if(itemstack.hasTagCompound()) entityitem.getEntityItem().setTagCompound((NBTTagCompound) itemstack.getTagCompound().copy());
float f3 = 0.05F;
entityitem.motionX = world.rand.nextGaussian() * f3;
entityitem.motionY = world.rand.nextGaussian() * f3 + 0.2F;
entityitem.motionZ = world.rand.nextGaussian() * f3;
world.spawnEntityInWorld(entityitem);
}
}
}
world.func_147453_f(x, y, z, block);
}
super.breakBlock(world, x, y, z, block, meta);
}
}

View File

@ -32,10 +32,12 @@ public class ContainerPneumoStorageAccess extends Container implements ICustomPa
protected TileEntityPneumoStorageAccess access;
protected InventoryPneumoStorageAccess inventory;
public static final int SLOT_CLICK_ID_REFRESH = -666;
public static final int GRID_SIZE = 6 * 8;
public static final String STACK_SIZE_KEY = "PNEUMO_STACK_SIZE";
public int itemCountForClient = 0; // TODO
public int itemCountForClient = 0;
public int listingStart = 0;
public ContainerPneumoStorageAccess(InventoryPlayer invPlayer, TileEntityPneumoStorageAccess access) {
this.access = access;
@ -57,11 +59,11 @@ public class ContainerPneumoStorageAccess extends Container implements ICustomPa
this.addSlotToContainer(new SlotNonRetarded(invPlayer, i, 8 + i * 18, 227));
}
updateListing();
updateListing(0);
this.detectAndSendChanges();
}
public void updateListing() { // DEMO
public void updateListing(int startingIndex) { // DEMO
if(this.access.cache == null || this.access.cache.hasExpired) return;
StackCache cache = this.access.cache;
List<CacheSlot> cacheSlots = new ArrayList(cache.cacheSlots.size());
@ -70,11 +72,16 @@ public class ContainerPneumoStorageAccess extends Container implements ICustomPa
Collections.sort(cacheSlots, SORT_BY_STACK_SIZE);
int size = cacheSlots.size();
int offset = startingIndex * 8;
for(int i = 0; i < inventory.slots.length; i++) {
if(i < size) {
CacheSlot cacheSlot = cacheSlots.get(i);
int grabIndex = offset + i;
if(grabIndex < size) {
CacheSlot cacheSlot = cacheSlots.get(grabIndex);
if(cacheSlot.displayStack != null) {
inventory.slots[i] = cacheSlot.displayStack.copy();
} else {
inventory.slots[i] = null;
}
} else {
inventory.slots[i] = null;
@ -102,6 +109,13 @@ public class ContainerPneumoStorageAccess extends Container implements ICustomPa
public ItemStack slotClick(int index, int button, int mode, EntityPlayer player) {
if(mode == 6) return null;
if(index == SLOT_CLICK_ID_REFRESH) {
if(player.worldObj.isRemote) return null;
this.listingStart = mode;
this.detectAndSendChanges();
return null;
}
boolean leftClick = button == 0 && mode == 0;
boolean rightClick = button == 1 && mode == 0;
boolean shiftClick = button == 0 && mode == 1;
@ -162,6 +176,7 @@ public class ContainerPneumoStorageAccess extends Container implements ICustomPa
ItemStack copy = held.copy();
copy.stackSize = remainder;
InventoryUtil.tryAddItemToInventory(player.inventory.mainInventory, copy);
detectAndSendChanges();
}
}
@ -210,7 +225,7 @@ public class ContainerPneumoStorageAccess extends Container implements ICustomPa
*/
@Override
public void detectAndSendChanges() {
this.updateListing();
this.updateListing(listingStart);
// skip the first 6*8 slots, i.e. all the ones visible in the access grid
for(int i = GRID_SIZE; i < this.inventorySlots.size(); i++) {
@ -270,6 +285,7 @@ public class ContainerPneumoStorageAccess extends Container implements ICustomPa
// if a null stack is indiced, skip
boolean hasNullStack = this.access.cache.cacheSlots.containsKey(this.access.cache.getNullIdentity());
masterTag.setInteger("itemCount", this.access.cache.cacheSlots.size() - (hasNullStack ? 1 : 0));
masterTag.setInteger("listingStart", this.listingStart);
masterTag.setTag("list", list);
for(Object o : this.crafters) {
if(o instanceof EntityPlayerMP) {
@ -294,6 +310,7 @@ public class ContainerPneumoStorageAccess extends Container implements ICustomPa
if(windowId != this.windowId) return;
this.itemCountForClient = data.getInteger("itemCount");
this.listingStart = data.getInteger("listingStart");
NBTTagList list = data.getTagList("list", 10);

View File

@ -2,6 +2,7 @@ package com.hbm.inventory.gui;
import java.util.List;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.GL11;
import static com.hbm.inventory.gui.element.GUIElements.*;
@ -19,6 +20,7 @@ import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.MathHelper;
import net.minecraft.util.ResourceLocation;
public class GUIPneumoStorageAccess extends GuiInfoContainer {
@ -43,10 +45,27 @@ public class GUIPneumoStorageAccess extends GuiInfoContainer {
public void drawScreen(int x, int y, float interp) {
ContainerPneumoStorageAccess container = (ContainerPneumoStorageAccess) this.inventorySlots;
this.scrollBounds = (container.itemCountForClient / 8 - 7);
if(this.scrollBounds < 0) this.scrollBounds = 0;
if(this.scrollIndex < 0) this.scrollIndex = 0;
if(this.scrollIndex > scrollBounds) this.scrollIndex = scrollBounds;
this.scrollBounds = (int) Math.ceil(container.itemCountForClient / 8D - 6D);
if(this.scrollBounds < 1) this.scrollBounds = 1;
if(this.scrollIndex < 0) this.setScroll(0);
if(this.scrollIndex > scrollBounds) this.setScroll(scrollBounds);
boolean isClicking = Mouse.isButtonDown(0);
if(!isClicking) this.draggingScroll = false;
if(!wasClicking && isClicking && guiLeft + 153 <= x && guiLeft + 153 + 14 > x && guiTop + 16 < y && guiTop + 16 + 108 >= y) {
draggingScroll = true;
}
if(draggingScroll) {
int range = 92; // 106 scroll bar size, -7 pixels on top and bottom
int sY = MathHelper.clamp_int(y - guiTop - 24, 0, 92);
double scrollFrac = (double) sY / (double) range;
int row = (int) Math.round(scrollBounds * scrollFrac);
this.setScroll(row);
}
this.wasClicking = isClicking;
super.drawScreen(x, y, interp);
}
@ -56,6 +75,20 @@ public class GUIPneumoStorageAccess extends GuiInfoContainer {
super.mouseClicked(x, y, i);
}
@Override
public void handleMouseInput() {
super.handleMouseInput();
int scrollDir = Mouse.getEventDWheel();
if(scrollDir != 0) {
if(scrollDir > 0) scrollDir = 1;
if(scrollDir < 0) scrollDir = -1;
this.setScroll(this.getScroll() - scrollDir);
}
}
@Override
protected void drawGuiContainerForegroundLayer(int i, int j) {
String name = "container.pneumoStorageAccess";
@ -90,6 +123,34 @@ public class GUIPneumoStorageAccess extends GuiInfoContainer {
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
Minecraft.getMinecraft().getTextureManager().bindTexture(texture);
drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize);
drawTexturedModalRect(guiLeft + getScrollBarXPos(), guiTop + getScrollBarYPos(), draggingScroll ? 188 : 176, 0, 12, 15);
}
public int getScrollBarXPos() {
return 154;
}
public int getScrollBarYPos() {
ContainerPneumoStorageAccess container = (ContainerPneumoStorageAccess) this.inventorySlots;
int scrollArea = 106 - 15; // bar height minus the scroll knob's height
double scrollProgress = (double) container.listingStart / (double) scrollBounds;
int scrollYPos = 17 + (int) (scrollProgress * scrollArea);
return scrollYPos;
}
public int getScroll() {
return MathHelper.clamp_int(scrollIndex, 0, scrollBounds);
}
public void setScroll(int scroll) {
int prevScroll = getScroll();
this.scrollIndex = MathHelper.clamp_int(scroll, 0, scrollBounds);
if(prevScroll != this.scrollIndex) refreshContainer();
}
public void refreshContainer() {
this.mc.playerController.windowClick(this.inventorySlots.windowId, ContainerPneumoStorageAccess.SLOT_CLICK_ID_REFRESH, 0, this.scrollIndex, this.mc.thePlayer);
}
@Override