Jump to content

strumshot

Members
  • Posts

    133
  • Joined

  • Last visited

Everything posted by strumshot

  1. No problem. I thought that was the better decision, for organizational purposes, as the issue was not resolved. I see it was not. edit: http://www.minecraftforge.net/forum/index.php/topic,23706.0.html
  2. I will let you know if I find anything, as my approach is slightly different. I want to interrupt any explosions in an area that is marked as locked. The locked Boolean in this case is calculated based on the map coordinates. I don't want the block to determine if the explosion happens or not because I want tnt outside of the locked area to still explode blocks inside the locked area. This will thus disable cannons firing into locked zones but allow for perimeter breaching! I just want to interrupt exploding in a locked area without overriding base TNT. maybe I will get lucky and find something.
  3. Im coming across this same issue. Im curious as to what your final solution ended up being; did you manage to avoid a core mod?
  4. Hah! I was hoping to find it before you did, and technically I did... but you posted first! I set the size in the initialization, and it drew the gui as it existed in memory, which showed that bottom row hanging off the end of the gui, and clicking there was tossing the item! Problem solved, now to remove tons of debug lines and re-apply my undoings. Thanks again! edit: it was realizing it was based off the y value of my click that clued me into where to look. Funny how posting here is usually the pre-cursor to the self-solve, regardless of how long I struggled up until then...
  5. ...and this only occurs on the lower, 'main' player inventory. I bound 9 inventory slots just like a traditional chest, and it only occurs on these 9 slots, not the upper 27, and not on my custom container slots. Am I overlapping slots or something that I am not seeing? this has been a 24-hour goose chase...
  6. UPDATE: the erratic behavior is NOT random, but still unexplainable. Clicking the lower half of the item icon causes the odd behavior, but not the top half. Quite literal. The icons are I believe 16 pixels, clicking on y=8-15 of the icon causes the item to be thrown on the ground. What?!
  7. Ok, I am building a custom container for a gui based shop mod. I had previously been much farther along until I started to hit strange behavior in the item clicking, so I began backing out code to find the issue. Now I seem to have basic overrides of typical containers, and have backed out my custom slots, etc. Long story short, the click behavior is erratic at best. I can shift-click items as usual transferring back and forth from container to inventory, but occasionally the shift click will toss the item on the ground. Same with right clicking. I have tested it a thousand ways and the same stack in the same slot wont behave the same way twice. With a full row of items in the player inventory and running through shift-clicking the stacks, a random stack will show this behavior. At this point this stack seems to be flagged as "odd" and any clicking acts strangely until I've picked up the items that were thrown, at which point it seems to return to normal. I had previously been using custom slots and had modified the click behavior functions but only to interrupt the picking up of the stack if it were in the custom slot, and for the check between right-click and left-click to always return a left-click on the custom slot, but have since backed these out. Unfortunately I can't find any debugging method or breakpoint that is unusual, and there are a decent number of classes involved so I will have to share them all. Big thanks to anyone willing to dig! NetworkRegistry.INSTANCE.registerGuiHandler(IShop.INSTANCE, new ShopGuiHandler()); ShopGuiHandler: @Override public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { // if(ID == 0){ TileEntityShopChest tileEntityShop = (TileEntityShopChest) world.getTileEntity(x, y, z); if(ID == 0) return new ContainerShop(player.inventory, tileEntityShop); else return new ContainerShopper(player.inventory, tileEntityShop); // } // return null; } @Override public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { TileEntityShopChest tileEntityContainer = (TileEntityShopChest) world.getTileEntity(x, y, z); if(ID == 0) return new GuiShop(player.inventory, tileEntityContainer); else return new GuiShopper(player.inventory, tileEntityContainer); } *currently guishopper is the only gui/container being 'chosen': to save you some debug time. GuiShopper: @SideOnly(Side.CLIENT) public class GuiShopper extends GuiContainer { public ContainerShopper container; private static final ResourceLocation field_147085_u = new ResourceLocation(IShop.MODID + ":textures/gui/shopper.png"); public GuiShopper(InventoryPlayer p_i1092_1_, TileEntityShopChest tileEntityTestContainer) { super(new ContainerShopper(p_i1092_1_, tileEntityTestContainer)); container = (ContainerShopper) this.inventorySlots; } @Override protected void drawGuiContainerBackgroundLayer(float p_146976_1_, int p_146976_2_, int p_146976_3_) { mc.renderEngine.bindTexture(field_147085_u); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); xSize = 176; ySize = 138; int x = (width - xSize) / 2; int y = (height - ySize) / 2; this.drawTexturedModalRect(x, y, 0, 0, xSize, ySize); int ix = width / 2 - xSize / 2; int iy = height / 2 - ySize / 2; this.drawCenteredString(fontRendererObj, container.tileEntity.Cost + "", 43 + ix, 35 + iy, 0xFFFFFF); } ContainerShopper: public TileEntityShopChest tileEntity; public ContainerShopper(InventoryPlayer inventory, TileEntityShopChest tileEntityT) { //super(inventory, tileEntityT); tileEntity = tileEntityT; // add shop inv for (int j = 0; j < 2; j++) { for (int i = 0; i < 6; i++) { this.addSlotToContainer(new Slot(tileEntity, i + j * 6, 62 + i * 18, 27 + j * 18)); } } bindPlayerInventory(inventory); } protected void bindPlayerInventory(InventoryPlayer inventoryPlayer) { for (int i = 0; i < 3; i++) { for (int j = 0; j < 9; j++) { addSlotToContainer(new Slot(inventoryPlayer, j + i * 9 + 9, 8 + j * 18, 70 + i * 18)); } } for (int i = 0; i < 9; i++) { addSlotToContainer(new Slot(inventoryPlayer, i, 8 + i * 18, 128)); } } @Override public ItemStack transferStackInSlot(EntityPlayer player, int slotnum) { ItemStack itemstack = null; Slot slot = (Slot)this.inventorySlots.get(slotnum); if (slot != null && slot.getHasStack()) { ItemStack itemstack1 = slot.getStack(); itemstack = itemstack1.copy(); if (slotnum < 12) { if (!this.mergeItemStack(itemstack1, 12, this.inventorySlots.size(), true)) { return null; } } else if (!this.mergeItemStack(itemstack1, 0, 12, false)) { return null; } if (itemstack1.stackSize == 0) { slot.putStack((ItemStack)null); } else { slot.onSlotChanged(); } } return itemstack; } and the big one, the TileEntity: private ItemStack[] chestContents = new ItemStack[12]; private String customName; public int numPlayersUsing; public float prevLidAngle; public float lidAngle; private int ticksSinceSync; private Object adjacentChestZNeg; private Object adjacentChestXNeg; private Object adjacentChestZPos; private Object adjacentChestXPos; public int Cost; public UUID Owner; /** * Returns the name of the inventory */ public String getInventoryName() { return this.hasCustomInventoryName() ? this.customName : "Shop Inventory"; } /** * Returns the stack in slot i */ public ItemStack getStackInSlot(int p_70301_1_) { return this.chestContents[p_70301_1_]; } /** * Removes from an inventory slot (first arg) up to a specified number (second arg) of items and returns them in a * new stack. */ public ItemStack decrStackSize(int p_70298_1_, int p_70298_2_) { if (this.chestContents[p_70298_1_] != null) { ItemStack itemstack; if (this.chestContents[p_70298_1_].stackSize <= p_70298_2_) { itemstack = this.chestContents[p_70298_1_]; this.chestContents[p_70298_1_] = null; this.markDirty(); return itemstack; } else { itemstack = this.chestContents[p_70298_1_].splitStack(p_70298_2_); if (this.chestContents[p_70298_1_].stackSize == 0) { this.chestContents[p_70298_1_] = null; } this.markDirty(); return itemstack; } } else { return null; } } /** * When some containers are closed they call this on each slot, then drop whatever it returns as an EntityItem - * like when you close a workbench GUI. */ public ItemStack getStackInSlotOnClosing(int p_70304_1_) { if (this.chestContents[p_70304_1_] != null) { ItemStack itemstack = this.chestContents[p_70304_1_]; this.chestContents[p_70304_1_] = null; return itemstack; } else { return null; } } /** * Sets the given item stack to the specified slot in the inventory (can be crafting or armor sections). */ public void setInventorySlotContents(int p_70299_1_, ItemStack p_70299_2_) { this.chestContents[p_70299_1_] = p_70299_2_; if (p_70299_2_ != null && p_70299_2_.stackSize > this.getInventoryStackLimit()) { p_70299_2_.stackSize = this.getInventoryStackLimit(); } this.markDirty(); } public void readFromNBT(NBTTagCompound p_145839_1_) { super.readFromNBT(p_145839_1_); NBTTagList nbttaglist = p_145839_1_.getTagList("Items", 10); this.chestContents = new ItemStack[this.getSizeInventory()]; if (p_145839_1_.hasKey("Shop Chest", ) { this.customName = p_145839_1_.getString("Shop Chest"); } this.Cost = p_145839_1_.getByte("Cost"); this.Owner = UUID.fromString(p_145839_1_.getString("Owner")); for (int i = 0; i < nbttaglist.tagCount(); ++i) { NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i); int j = nbttagcompound1.getByte("Slot") & 255; if (j >= 0 && j < this.chestContents.length) { this.chestContents[j] = ItemStack.loadItemStackFromNBT(nbttagcompound1); } } } public void writeToNBT(NBTTagCompound p_145841_1_) { super.writeToNBT(p_145841_1_); NBTTagList nbttaglist = new NBTTagList(); for (int i = 0; i < this.chestContents.length; ++i) { if (this.chestContents[i] != null) { NBTTagCompound nbttagcompound1 = new NBTTagCompound(); nbttagcompound1.setByte("Slot", (byte)i); this.chestContents[i].writeToNBT(nbttagcompound1); nbttaglist.appendTag(nbttagcompound1); } } p_145841_1_.setTag("Items", nbttaglist); p_145841_1_.setByte("Cost", (byte)this.Cost); p_145841_1_.setString("Owner", this.Owner.toString()); if (this.hasCustomInventoryName()) { p_145841_1_.setString("Shop Chest", this.customName); } } public void func_145976_a(String p_145976_1_) { this.customName = p_145976_1_; } public void openInventory() { if (this.numPlayersUsing < 0) { this.numPlayersUsing = 0; } ++this.numPlayersUsing; this.worldObj.addBlockEvent(this.xCoord, this.yCoord, this.zCoord, this.getBlockType(), 1, this.numPlayersUsing); this.worldObj.notifyBlocksOfNeighborChange(this.xCoord, this.yCoord, this.zCoord, this.getBlockType()); this.worldObj.notifyBlocksOfNeighborChange(this.xCoord, this.yCoord - 1, this.zCoord, this.getBlockType()); } public void closeInventory() { if (this.getBlockType() instanceof ShopChest) { --this.numPlayersUsing; this.worldObj.addBlockEvent(this.xCoord, this.yCoord, this.zCoord, this.getBlockType(), 1, this.numPlayersUsing); this.worldObj.notifyBlocksOfNeighborChange(this.xCoord, this.yCoord, this.zCoord, this.getBlockType()); this.worldObj.notifyBlocksOfNeighborChange(this.xCoord, this.yCoord - 1, this.zCoord, this.getBlockType()); } } @Override public int getSizeInventory() { // TODO Auto-generated method stub return this.chestContents.length; } @Override public boolean hasCustomInventoryName() { // TODO Auto-generated method stub return false; } @Override public int getInventoryStackLimit() { // TODO Auto-generated method stub return 64; } @Override public boolean isUseableByPlayer(EntityPlayer p_70300_1_) { return this.worldObj.getTileEntity(this.xCoord, this.yCoord, this.zCoord) != this ? false : p_70300_1_.getDistanceSq((double)this.xCoord + 0.5D, (double)this.yCoord + 0.5D, (double)this.zCoord + 0.5D) <= 64.0D; } @Override public boolean isItemValidForSlot(int p_94041_1_, ItemStack p_94041_2_) { // TODO Auto-generated method stub return true; } public void updateEntity() { super.updateEntity(); ++this.ticksSinceSync; float f; if (!this.worldObj.isRemote && this.numPlayersUsing != 0 && (this.ticksSinceSync + this.xCoord + this.yCoord + this.zCoord) % 200 == 0) { this.numPlayersUsing = 0; f = 5.0F; List list = this.worldObj.getEntitiesWithinAABB(EntityPlayer.class, AxisAlignedBB.getBoundingBox((double)((float)this.xCoord - f), (double)((float)this.yCoord - f), (double)((float)this.zCoord - f), (double)((float)(this.xCoord + 1) + f), (double)((float)(this.yCoord + 1) + f), (double)((float)(this.zCoord + 1) + f))); Iterator iterator = list.iterator(); while (iterator.hasNext()) { EntityPlayer entityplayer = (EntityPlayer)iterator.next(); if (entityplayer.openContainer instanceof ContainerShop) { ++this.numPlayersUsing; } } } this.prevLidAngle = this.lidAngle; f = 0.1F; double d2; if (this.numPlayersUsing > 0 && this.lidAngle == 0.0F && this.adjacentChestZNeg == null && this.adjacentChestXNeg == null) { double d1 = (double)this.xCoord + 0.5D; d2 = (double)this.zCoord + 0.5D; if (this.adjacentChestZPos != null) { d2 += 0.5D; } if (this.adjacentChestXPos != null) { d1 += 0.5D; } this.worldObj.playSoundEffect(d1, (double)this.yCoord + 0.5D, d2, "random.chestopen", 0.5F, this.worldObj.rand.nextFloat() * 0.1F + 0.9F); } if (this.numPlayersUsing == 0 && this.lidAngle > 0.0F || this.numPlayersUsing > 0 && this.lidAngle < 1.0F) { float f1 = this.lidAngle; if (this.numPlayersUsing > 0) { this.lidAngle += f; } else { this.lidAngle -= f; } if (this.lidAngle > 1.0F) { this.lidAngle = 1.0F; } float f2 = 0.5F; if (this.lidAngle < f2 && f1 >= f2 && this.adjacentChestZNeg == null && this.adjacentChestXNeg == null) { d2 = (double)this.xCoord + 0.5D; double d0 = (double)this.zCoord + 0.5D; if (this.adjacentChestZPos != null) { d0 += 0.5D; } if (this.adjacentChestXPos != null) { d2 += 0.5D; } this.worldObj.playSoundEffect(d2, (double)this.yCoord + 0.5D, d0, "random.chestclosed", 0.5F, this.worldObj.rand.nextFloat() * 0.1F + 0.9F); } if (this.lidAngle < 0.0F) { this.lidAngle = 0.0F; } } } public boolean isOwnedBy(EntityPlayer player) { // if(this.Owner.equals(player.getPersistentID())) // return true; return false; } Also, if it is related at all - and I doubt it is - the itemblock of the ShopChest, when in the inventory, "greys out" any items after it in the inventory; the "grey" that you see when you pick up an item. JIC, here is the ShopChest class: private final Random field_149955_b = new Random(); public ShopChest(int p_i45397_1_) { super(Material.wood); this.setHardness(2.0f); this.setResistance(10f); } /** * Is this block (a) opaque and (b) a full 1m cube? This determines whether or not to render the shared face of two * adjacent blocks and also whether the player can attach torches, redstone wire, etc to this block. */ public boolean isOpaqueCube() { return false; } /** * If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc) */ public boolean renderAsNormalBlock() { return false; } /** * The type of render function that is called for this block */ public int getRenderType() { return 22; } private void OnPlace(EntityLivingBase entity, int x, int y, int z, World world) { if(entity != null && entity instanceof EntityPlayer){ EntityPlayer player = (EntityPlayer) entity; TileEntity tileEntity = world.getTileEntity(x, y, z); if (tileEntity instanceof TileEntityShopChest) { TileEntityShopChest chest = (TileEntityShopChest) tileEntity; chest.Owner = player.getPersistentID(); } } } /** * Called upon block activation (right click on the block.) */ public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int p_149727_6_, float p_149727_7_, float p_149727_8_, float p_149727_9_) { if (world.isRemote) { return true; } else { IInventory iinventory = this.func_149951_m(world, x, y, z); TileEntity tileEntity = world.getTileEntity(x, y, z); if (tileEntity == null || player.isSneaking()|| !(tileEntity instanceof TileEntityShopChest)) { return false; } TileEntityShopChest chest = (TileEntityShopChest) tileEntity; if (iinventory != null) { //if owner, open owner gui, id = 0? if (chest.isOwnedBy(player)) { FMLNetworkHandler.openGui(player, IShop.INSTANCE, 0, world, x, y, z); IShop.network.sendToServer(new RequestCost()); } else { FMLNetworkHandler.openGui(player, IShop.INSTANCE, 1, world, x, y, z); IShop.network.sendToServer(new RequestCost()); } //else open shopper gui, id = 1? } return true; } } public void onBlockPlacedBy(World p_149689_1_, int p_149689_2_, int p_149689_3_, int p_149689_4_, EntityLivingBase p_149689_5_, ItemStack p_149689_6_) { this.OnPlace(p_149689_5_, p_149689_2_, p_149689_3_, p_149689_4_, p_149689_1_); Block block = p_149689_1_.getBlock(p_149689_2_, p_149689_3_, p_149689_4_ - 1); Block block1 = p_149689_1_.getBlock(p_149689_2_, p_149689_3_, p_149689_4_ + 1); Block block2 = p_149689_1_.getBlock(p_149689_2_ - 1, p_149689_3_, p_149689_4_); Block block3 = p_149689_1_.getBlock(p_149689_2_ + 1, p_149689_3_, p_149689_4_); byte b0 = 0; int l = MathHelper.floor_double((double)(p_149689_5_.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3; if (l == 0) { b0 = 2; } if (l == 1) { b0 = 5; } if (l == 2) { b0 = 3; } if (l == 3) { b0 = 4; } if (block != this && block1 != this && block2 != this && block3 != this) { p_149689_1_.setBlockMetadataWithNotify(p_149689_2_, p_149689_3_, p_149689_4_, b0, 3); } else { if ((block == this || block1 == this) && (b0 == 4 || b0 == 5)) { if (block == this) { p_149689_1_.setBlockMetadataWithNotify(p_149689_2_, p_149689_3_, p_149689_4_ - 1, b0, 3); } else { p_149689_1_.setBlockMetadataWithNotify(p_149689_2_, p_149689_3_, p_149689_4_ + 1, b0, 3); } p_149689_1_.setBlockMetadataWithNotify(p_149689_2_, p_149689_3_, p_149689_4_, b0, 3); } if ((block2 == this || block3 == this) && (b0 == 2 || b0 == 3)) { if (block2 == this) { p_149689_1_.setBlockMetadataWithNotify(p_149689_2_ - 1, p_149689_3_, p_149689_4_, b0, 3); } else { p_149689_1_.setBlockMetadataWithNotify(p_149689_2_ + 1, p_149689_3_, p_149689_4_, b0, 3); } p_149689_1_.setBlockMetadataWithNotify(p_149689_2_, p_149689_3_, p_149689_4_, b0, 3); } } if (p_149689_6_.hasDisplayName()) { ((TileEntityShopChest)p_149689_1_.getTileEntity(p_149689_2_, p_149689_3_, p_149689_4_)).func_145976_a(p_149689_6_.getDisplayName()); } } /** * Lets the block know when one of its neighbor changes. Doesn't know which neighbor changed (coordinates passed are * their own) Args: x, y, z, neighbor Block */ public void onNeighborBlockChange(World p_149695_1_, int p_149695_2_, int p_149695_3_, int p_149695_4_, Block p_149695_5_) { super.onNeighborBlockChange(p_149695_1_, p_149695_2_, p_149695_3_, p_149695_4_, p_149695_5_); TileEntityShopChest tileentitychest = (TileEntityShopChest)p_149695_1_.getTileEntity(p_149695_2_, p_149695_3_, p_149695_4_); if (tileentitychest != null) { tileentitychest.updateContainingBlockInfo(); } } public void breakBlock(World p_149749_1_, int p_149749_2_, int p_149749_3_, int p_149749_4_, Block p_149749_5_, int p_149749_6_) { TileEntityShopChest tileentitychest = (TileEntityShopChest)p_149749_1_.getTileEntity(p_149749_2_, p_149749_3_, p_149749_4_); if (tileentitychest != null) { for (int i1 = 0; i1 < tileentitychest.getSizeInventory(); ++i1) { ItemStack itemstack = tileentitychest.getStackInSlot(i1); if (itemstack != null) { float f = this.field_149955_b.nextFloat() * 0.8F + 0.1F; float f1 = this.field_149955_b.nextFloat() * 0.8F + 0.1F; EntityItem entityitem; for (float f2 = this.field_149955_b.nextFloat() * 0.8F + 0.1F; itemstack.stackSize > 0; p_149749_1_.spawnEntityInWorld(entityitem)) { int j1 = this.field_149955_b.nextInt(21) + 10; if (j1 > itemstack.stackSize) { j1 = itemstack.stackSize; } itemstack.stackSize -= j1; entityitem = new EntityItem(p_149749_1_, (double)((float)p_149749_2_ + f), (double)((float)p_149749_3_ + f1), (double)((float)p_149749_4_ + f2), new ItemStack(itemstack.getItem(), j1, itemstack.getItemDamage())); float f3 = 0.05F; entityitem.motionX = (double)((float)this.field_149955_b.nextGaussian() * f3); entityitem.motionY = (double)((float)this.field_149955_b.nextGaussian() * f3 + 0.2F); entityitem.motionZ = (double)((float)this.field_149955_b.nextGaussian() * f3); if (itemstack.hasTagCompound()) { entityitem.getEntityItem().setTagCompound((NBTTagCompound)itemstack.getTagCompound().copy()); } } } } p_149749_1_.func_147453_f(p_149749_2_, p_149749_3_, p_149749_4_, p_149749_5_); } super.breakBlock(p_149749_1_, p_149749_2_, p_149749_3_, p_149749_4_, p_149749_5_, p_149749_6_); } public IInventory func_149951_m(World p_149951_1_, int p_149951_2_, int p_149951_3_, int p_149951_4_) { Object object = (TileEntityShopChest)p_149951_1_.getTileEntity(p_149951_2_, p_149951_3_, p_149951_4_); if (object == null) { return null; } else if (p_149951_1_.isSideSolid(p_149951_2_, p_149951_3_ + 1, p_149951_4_, DOWN)) { return null; } else if (func_149953_o(p_149951_1_, p_149951_2_, p_149951_3_, p_149951_4_)) { return null; } else if (p_149951_1_.getBlock(p_149951_2_ - 1, p_149951_3_, p_149951_4_) == this && (p_149951_1_.isSideSolid(p_149951_2_ - 1, p_149951_3_ + 1, p_149951_4_, DOWN) || func_149953_o(p_149951_1_, p_149951_2_ - 1, p_149951_3_, p_149951_4_))) { return null; } else if (p_149951_1_.getBlock(p_149951_2_ + 1, p_149951_3_, p_149951_4_) == this && (p_149951_1_.isSideSolid(p_149951_2_ + 1, p_149951_3_ + 1, p_149951_4_, DOWN) || func_149953_o(p_149951_1_, p_149951_2_ + 1, p_149951_3_, p_149951_4_))) { return null; } else if (p_149951_1_.getBlock(p_149951_2_, p_149951_3_, p_149951_4_ - 1) == this && (p_149951_1_.isSideSolid(p_149951_2_, p_149951_3_ + 1, p_149951_4_ - 1, DOWN) || func_149953_o(p_149951_1_, p_149951_2_, p_149951_3_, p_149951_4_ - 1))) { return null; } else if (p_149951_1_.getBlock(p_149951_2_, p_149951_3_, p_149951_4_ + 1) == this && (p_149951_1_.isSideSolid(p_149951_2_, p_149951_3_ + 1, p_149951_4_ + 1, DOWN) || func_149953_o(p_149951_1_, p_149951_2_, p_149951_3_, p_149951_4_ + 1))) { return null; } else { if (p_149951_1_.getBlock(p_149951_2_ - 1, p_149951_3_, p_149951_4_) == this) { object = new InventoryLargeChest("Shop Chest", (TileEntityShopChest)p_149951_1_.getTileEntity(p_149951_2_ - 1, p_149951_3_, p_149951_4_), (IInventory)object); } if (p_149951_1_.getBlock(p_149951_2_ + 1, p_149951_3_, p_149951_4_) == this) { object = new InventoryLargeChest("Shop Chest", (IInventory)object, (TileEntityShopChest)p_149951_1_.getTileEntity(p_149951_2_ + 1, p_149951_3_, p_149951_4_)); } if (p_149951_1_.getBlock(p_149951_2_, p_149951_3_, p_149951_4_ - 1) == this) { object = new InventoryLargeChest("Shop Chest", (TileEntityShopChest)p_149951_1_.getTileEntity(p_149951_2_, p_149951_3_, p_149951_4_ - 1), (IInventory)object); } if (p_149951_1_.getBlock(p_149951_2_, p_149951_3_, p_149951_4_ + 1) == this) { object = new InventoryLargeChest("Shop Chest", (IInventory)object, (TileEntityShopChest)p_149951_1_.getTileEntity(p_149951_2_, p_149951_3_, p_149951_4_ + 1)); } return (IInventory)object; } } public TileEntity createNewTileEntity(World p_149915_1_, int p_149915_2_) { TileEntityShopChest tileentitychest = new TileEntityShopChest(); return tileentitychest; } public int isProvidingWeakPower(IBlockAccess p_149709_1_, int p_149709_2_, int p_149709_3_, int p_149709_4_, int p_149709_5_) { if (!this.canProvidePower()) { return 0; } else { int i1 = ((TileEntityShopChest)p_149709_1_.getTileEntity(p_149709_2_, p_149709_3_, p_149709_4_)).numPlayersUsing; return MathHelper.clamp_int(i1, 0, 15); } } private static boolean func_149953_o(World p_149953_0_, int p_149953_1_, int p_149953_2_, int p_149953_3_) { Iterator iterator = p_149953_0_.getEntitiesWithinAABB(EntityOcelot.class, AxisAlignedBB.getBoundingBox((double)p_149953_1_, (double)(p_149953_2_ + 1), (double)p_149953_3_, (double)(p_149953_1_ + 1), (double)(p_149953_2_ + 2), (double)(p_149953_3_ + 1))).iterator(); EntityOcelot entityocelot; do { if (!iterator.hasNext()) { return false; } Entity entity = (Entity)iterator.next(); entityocelot = (EntityOcelot)entity; } while (!entityocelot.isSitting()); return true; } /** * Checks to see if its valid to put this block at the specified coordinates. Args: world, x, y, z */ public boolean canPlaceBlockAt(World p_149742_1_, int p_149742_2_, int p_149742_3_, int p_149742_4_) { return true; } private boolean func_149952_n(World p_149952_1_, int p_149952_2_, int p_149952_3_, int p_149952_4_) { return p_149952_1_.getBlock(p_149952_2_, p_149952_3_, p_149952_4_) != this ? false : (p_149952_1_.getBlock(p_149952_2_ - 1, p_149952_3_, p_149952_4_) == this ? true : (p_149952_1_.getBlock(p_149952_2_ + 1, p_149952_3_, p_149952_4_) == this ? true : (p_149952_1_.getBlock(p_149952_2_, p_149952_3_, p_149952_4_ - 1) == this ? true : p_149952_1_.getBlock(p_149952_2_, p_149952_3_, p_149952_4_ + 1) == this))); } @SideOnly(Side.CLIENT) public void registerBlockIcons(IIconRegister p_149651_1_) { this.blockIcon = p_149651_1_.registerIcon(IShop.MODID + ":shopchest"); } public void RenderHelper(World p_149954_1_, int p_149954_2_, int p_149954_3_, int p_149954_4_) { if (!p_149954_1_.isRemote) { Block block = p_149954_1_.getBlock(p_149954_2_, p_149954_3_, p_149954_4_ - 1); Block block1 = p_149954_1_.getBlock(p_149954_2_, p_149954_3_, p_149954_4_ + 1); Block block2 = p_149954_1_.getBlock(p_149954_2_ - 1, p_149954_3_, p_149954_4_); Block block3 = p_149954_1_.getBlock(p_149954_2_ + 1, p_149954_3_, p_149954_4_); boolean flag = true; int l; Block block4; int i1; Block block5; boolean flag1; byte b0; int j1; if (block != this && block1 != this) { if (block2 != this && block3 != this) { b0 = 3; if (block.func_149730_j() && !block1.func_149730_j()) { b0 = 3; } if (block1.func_149730_j() && !block.func_149730_j()) { b0 = 2; } if (block2.func_149730_j() && !block3.func_149730_j()) { b0 = 5; } if (block3.func_149730_j() && !block2.func_149730_j()) { b0 = 4; } } else { l = block2 == this ? p_149954_2_ - 1 : p_149954_2_ + 1; block4 = p_149954_1_.getBlock(l, p_149954_3_, p_149954_4_ - 1); i1 = block2 == this ? p_149954_2_ - 1 : p_149954_2_ + 1; block5 = p_149954_1_.getBlock(i1, p_149954_3_, p_149954_4_ + 1); b0 = 3; flag1 = true; if (block2 == this) { j1 = p_149954_1_.getBlockMetadata(p_149954_2_ - 1, p_149954_3_, p_149954_4_); } else { j1 = p_149954_1_.getBlockMetadata(p_149954_2_ + 1, p_149954_3_, p_149954_4_); } if (j1 == 2) { b0 = 2; } if ((block.func_149730_j() || block4.func_149730_j()) && !block1.func_149730_j() && !block5.func_149730_j()) { b0 = 3; } if ((block1.func_149730_j() || block5.func_149730_j()) && !block.func_149730_j() && !block4.func_149730_j()) { b0 = 2; } } } else { l = block == this ? p_149954_4_ - 1 : p_149954_4_ + 1; block4 = p_149954_1_.getBlock(p_149954_2_ - 1, p_149954_3_, l); i1 = block == this ? p_149954_4_ - 1 : p_149954_4_ + 1; block5 = p_149954_1_.getBlock(p_149954_2_ + 1, p_149954_3_, i1); b0 = 5; flag1 = true; if (block == this) { j1 = p_149954_1_.getBlockMetadata(p_149954_2_, p_149954_3_, p_149954_4_ - 1); } else { j1 = p_149954_1_.getBlockMetadata(p_149954_2_, p_149954_3_, p_149954_4_ + 1); } if (j1 == 4) { b0 = 4; } if ((block2.func_149730_j() || block4.func_149730_j()) && !block3.func_149730_j() && !block5.func_149730_j()) { b0 = 5; } if ((block3.func_149730_j() || block5.func_149730_j()) && !block2.func_149730_j() && !block4.func_149730_j()) { b0 = 4; } } p_149954_1_.setBlockMetadataWithNotify(p_149954_2_, p_149954_3_, p_149954_4_, b0, 3); } } /** * Updates the blocks bounds based on its current state. Args: world, x, y, z */ public void setBlockBoundsBasedOnState(IBlockAccess p_149719_1_, int p_149719_2_, int p_149719_3_, int p_149719_4_) { if (p_149719_1_.getBlock(p_149719_2_, p_149719_3_, p_149719_4_ - 1) == this) { this.setBlockBounds(0.0625F, 0.0F, 0.0F, 0.9375F, 0.875F, 0.9375F); } else if (p_149719_1_.getBlock(p_149719_2_, p_149719_3_, p_149719_4_ + 1) == this) { this.setBlockBounds(0.0625F, 0.0F, 0.0625F, 0.9375F, 0.875F, 1.0F); } else if (p_149719_1_.getBlock(p_149719_2_ - 1, p_149719_3_, p_149719_4_) == this) { this.setBlockBounds(0.0F, 0.0F, 0.0625F, 0.9375F, 0.875F, 0.9375F); } else if (p_149719_1_.getBlock(p_149719_2_ + 1, p_149719_3_, p_149719_4_) == this) { this.setBlockBounds(0.0625F, 0.0F, 0.0625F, 1.0F, 0.875F, 0.9375F); } else { this.setBlockBounds(0.0625F, 0.0F, 0.0625F, 0.9375F, 0.875F, 0.9375F); } }
  8. Sure enough, I had a lost tileEntity,Cost = 0; initialization in my Container of all places from an earlier approach! Search and replace caused the issue, and search fixed the issue! Thanks again for your continued help!
  9. Well when I get at my computer I will post my container, gui, and packets; TileEntity is above. Surely the issue is there or missing from there. Maybe I have a lost line of code that reinitialized Coin somewhere I am overlooking or something. Are there any classes that could be related that I am not thinking of?
  10. Thats actually exactly what I have done. The server side thread prints out the value immediately after incrementing in the server packet handler, and I can watch it climb with each bitton click. I can also watch the client reflect the change visually on the gui, which is only adjusted in the SendCost handler as shown above, which is the return value of successfully handling the server packet. Then I close the chest, reopen, and its at 0. My current guesses are that Coin gets reinitialized somehow or I am changing a temporary instance/clone of the TileEntity? I tried MarkDirty, markforUpdate. .. im lost for words!
  11. TileEntity there are other variables in this class such as the contents that save just fine when closing the chest, but I cant find anywhere they are referenced that the 'Cost' is not... could it be associated to it being updated within the network handler? Like its another instance of the TileEntity or something?
  12. Update: of course, the moment I posted I solved the issue of getting the info back to the client... at least I think. player.worldObj.markBlockForUpdate(container.tileEntity.xCoord, container.tileEntity.yCoord, container.tileEntity.zCoord); return new SendCost(container.tileEntity.Cost); public static class Handler implements IMessageHandler<SendCost, IMessage> { @Override public IMessage onMessage(SendCost message, MessageContext ctx) { EntityPlayer player = Minecraft.getMinecraft().thePlayer; ContainerShop container = (ContainerShop)player.openContainer; container.tileEntity.Cost = message.value; But the value is still resetting upon close.
  13. Okay.. Setting up the custom packets and sending safe information to the server upon button click, I'm good. But that's as far as I can get! Ugh. I have a few issues. Ultimately I'm not sure how to send that update back to the client (and others who may open this container.) I've played with many methods and approaches, such as simply reversing the process; but there seems to be no direct access to the player through the client side of the handler to grab the open container from. Also, upon closing the container, the value seems to reset on the server side - I am logging the server-side value every time the server receives the packet. I'm writing the value to NBT in the generic writeToNBT method, which doesn't seem to affect it. Again, I'm sure there's some simple mechanism already in place for updating custom values in a TileEntity and then propogating that update back to nearby clients; maybe through a custom packet and sendToAllAround()? Any tutorials I've found near this topic are deprecated which is frustrating!
  14. right that is basically my point. I guess I could make 2 separate packet classes as there are two different buttons. I was using one packet for both buttons; the character would be either a plus or a minus - or whatever. An increment button and a decrement button. i 100% see your point although in this scenario cheating isn't really possible but I will still take that advice!
  15. this is extra nice because I can shorten the message to one character - no numbers - and do all the logic on the server side! whenever I find my code getting long and myself inventing solutions there is usually a simpler already available approach.and it usually gets pointed out to me by you. Haha at this point you have virtually written half of my mods and I'm sure I'm not the only one on this forum with that experience.
  16. Aha! I hadn't found that in the context, and was therefore trying to invent a solution. Thank you so much!
  17. Thanks for the quick responses! I should clarify that when I say 'button' I mean a clickable gui control. And then my follow-up question is such: my packet handling method currently has no objects to access aside from the packet class and the message text. That is why I imagined I would be sending an ID of sorts in the string, and then looking that ID up in a static server list. Does that make sense? Something like... protected void actionPerformed(GuiButton button) { ++chest.Cost; IShop.network.sendToServer(new ChangeCost(chest.hashCode() + ":" + chest.Cost)); break; public static class Handler implements IMessageHandler<ChangeCost, IMessage> { @Override public IMessage onMessage(ChangeCost message, MessageContext ctx) { String[] incoming = message.text.split(":"); if(incoming != null && incoming.length == 2){ int hash = Integer.parseInt(incoming[0]); int cost = Integer.parseInt(incoming[1]); // lookup chest # here and adjust value of 'cost'
  18. ..so at the end of the day I know the button clicks happen privately on the client, but I need them to adjust the value on the server so any other player would see the updated value when opening the gui. Maybe I misunderstand what automatically gets synced to the server, and maybe I am storing the value in the wrong spot (I have options. Container, gui, TileEntity...) but I can't find a solution and its a hard topic to google!
  19. Yeah, it sure does. I'd be happy to share code, but I have no errors so to speak.. Its a block, TileEntity, Container, and gui. The setup displays the player inventory, the 12-slot 'inventory' of the container, the 'value' in question (currently held by the TileEntity) and buttons to change the value. I have a blank string packet sent to server upon button click.
  20. So I'm working with a custom block/gui and have some buttons on the gui that are changing a value stored in a TileEntity. Unless I am mistaken the button actions and therefore the value changes corresponding to pressing them occur on client side only. I have, then, set up a packet to be sent to the server so this value can be updated globally and other players "see" the updated values. I am using the SimpleNetworkWrapper so I am simply sending a string. I imagine I will be sending a constructed string containing an id for the TileEntity and the updated value, and then grabbing that TileEntity by that id on the server/packet receive? Should I be using hashCode? And what list/map am I looking it up in? Or should I be approaching this some other way... thanks for any pointers! (I mean tips, not programmatic 'pointers' lol - bad programming joke)
  21. Tonight I am my own hero!! A warning to all the kids: keep your packages lowercase, and upon ANY refactoring, navigate to your build folder and delete both the 'classes' and 'sources' folders before compiling. Can I thank myself?
  22. Once again, I'm sure there's something so blaringly obvious to any other pair of eyes than mine, but I have been cruising with some capitalized packages for a while and it never caused issues, so I let it be. I eventually refactored and now my classes can't be found - only when compiled. After two hours of head-wall-banging, I am here. Please help my wall take no more damage from my head! and the crash:
  23. This is pretty wise, especially if you plan on your server almost never restarting. Unless you are saving this list to file, it will clear out every time you restart the server. Edit: Although if you remove a player from the list every time you find a null, it will be self-cleaning anyway, and the "new name" (when that feature comes available) will be used the next time that individual player logs in. So if all you are using this list for is notifying players of login, you will only run into issues for one specific player, during the specific session in which they changed their name. If you want a list for more sophisticated and long-term uses, then you should most definitely take larsgerrits' advice. If it were me I would start simple and work up, since it's pretty much all stilla challenge for you. I am not making this mod for the server- this is a bukkit server and I am not the owner Is it going to work if the mod isnt install on the server? That's a big no. It will work in single player. Or if you are the server, any client who also has the mod will be able to log in and it will work. If it is installed on the server a client can not log in unless they have it installed also. Simple as that. ? Issue already solved, and that's not it...
  24. This is pretty wise, especially if you plan on your server almost never restarting. Unless you are saving this list to file, it will clear out every time you restart the server. Edit: Although if you remove a player from the list every time you find a null, it will be self-cleaning anyway, and the "new name" (when that feature comes available) will be used the next time that individual player logs in. So if all you are using this list for is notifying players of login, you will only run into issues for one specific player, during the specific session in which they changed their name. If you want a list for more sophisticated and long-term uses, then you should most definitely take larsgerrits' advice. If it were me I would start simple and work up, since it's pretty much all stilla challenge for you.
  25. If you are new to forge but interested in learning more, then subscribing to events and maybe writing a custom save file should be within your scope/a good learning experience and easy enough to find basic outlines and tutorials about them. My first thoughts on your approach would be as follows: create a static String[] to store currently online player names. subscribe to the EntityJoinWorldEvent https://github.com/MinecraftForge/MinecraftForge/blob/master/src/main/java/net/minecraftforge/event/entity/EntityJoinWorldEvent.java and add that player to the list, and also broadcast any messages to any other players on that list. You'll be using a lot of World.getPlayerEntityByName() and null checks.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.