Thread: Item Containers

Page 1 of 2 12 LastLast
Results 1 to 10 of 14
  1. #1 Item Containers 
    ???

    funkE's Avatar
    Join Date
    Feb 2008
    Posts
    2,612
    Thanks given
    255
    Thanks received
    989
    Rep Power
    1366
    I no longer have any interest in sharing anything, really. Mods seem kind of hostile today.

    Better luck next time, if there is one.
    Last edited by funkE; 05-23-2015 at 03:33 PM. Reason: what happened to the title
    .
     

  2. #2  


    Major's Avatar
    Join Date
    Jan 2011
    Posts
    2,997
    Thanks given
    1,293
    Thanks received
    3,556
    Rep Power
    5000
    Why are you using a HashMap to represent zero-based integer-keyed contiguous data?

    Why is this synchronized? Why does this class require thread safety? You don't write thread-safe code because other people are incapable of understanding thread safety, you write it because you actually need to share it between multiple threads: I'm not convinced this is the case.

    Code:
    public class ItemDiscardedException extends RuntimeException {
    	private static final long serialVersionUID = 7130393044046415032L;
    }
    Useless, add the constructors. I don't know what the idea behind the 'disposed' field is, but that seems pointless.

    Code:
    		long destAmount = this.amount + amount; // use long to prevent overflow
    Who knows what's wrong with this?

    Code:
    	public static GamePacket buildResetContainerPacket(int interfaceID) {
    		GamePacketBuilder bldr = new GamePacketBuilder(72, GamePacket.Type.FIXED);
    		bldr.putShort(interfaceID);
    		return bldr.toPacket();
    	}
    
    	public static GamePacket buildContainerItemPacket(int interfaceID, Container container) {
    		GamePacketBuilder bldr = new GamePacketBuilder(53, GamePacket.Type.VARIABLE_SHORT);
    		bldr.putShort(interfaceID);
    		bldr.putShort(container.maximum());
    		
    		synchronized (container.items) {
    			for (int i = 0; i < container.maximum(); i++) {
    				if (container.items.containsKey(i)) {
    					Item item = container.items.get(i);
    					
    					if (item.amount() >= 255) {
    						bldr.put((byte)-1);
    						bldr.putInt2(item.amount());
    					}
    					else {
    						bldr.put((byte)item.amount());
    					}
    				}
    				else {
    					bldr.put((byte)0);
    					bldr.putLEShortA(-1);
    				}
    			}
    		}
    Should be somewhere else

    Code:
    public Container(int maximum, boolean acceptsNotes, boolean forcedItemStacks) {
    		this.maximumContained = maximum;
    		this.acceptsNotes = acceptsNotes;
    		this.forcedStack = forcedItemStacks;
    	}
    Use enums or static constructors, not boolean parameters. Is there actually a container that doesn't allow noted items?

    Code:
    			// stil don't know why we subtract 1
    			ItemInfo info = ItemInfo.forID(id - 1);
    Code:
    		// we don't sync on other object's items because we don't want a deadlock.
    		// unfortunately, the only possibility of deadlock is in this method itself.
    		// if you transfer items between the same two containers in parallel, there's a possibility for deadlock.
    		// thankfully, i can't see the reason there would be transfers between the same two containers at the same time.
    Code:
    			items.put((Integer)existingSlot, end);
    Code:
    			items.put((Integer)slot, new Item(id, 1));
    Code:
    			items.put((Integer)slot, new Item(id, amount));

    Last edited by Major; 05-23-2015 at 04:50 PM.
     

  3. Thankful user:


  4. #3  
    Item Containers



    Scu11's Avatar
    Join Date
    Aug 2007
    Age
    30
    Posts
    16,307
    Thanks given
    7,215
    Thanks received
    12,308
    Rep Power
    5000
    Don't like the boolean parameters

    Attached image
     

  5. #4  
    Registered Member

    Join Date
    Dec 2012
    Posts
    2,999
    Thanks given
    894
    Thanks received
    921
    Rep Power
    2555
    I personally have my Container as an abstract class so I can easily invoke refreshing, and for the constructor I have it as the following:
    • Maximum capacity
    • Stack type (Always stack, stackable items only, never stack)
    • Audience type (One player or loads)


    also that usage of casting to add an item is ugly imo!
    Attached image
     

  6. #5  
    ???

    funkE's Avatar
    Join Date
    Feb 2008
    Posts
    2,612
    Thanks given
    255
    Thanks received
    989
    Rep Power
    1366
    I said.
    .
     

  7. #6  
    Item Containers



    Scu11's Avatar
    Join Date
    Aug 2007
    Age
    30
    Posts
    16,307
    Thanks given
    7,215
    Thanks received
    12,308
    Rep Power
    5000
    Quote Originally Posted by PlatinumWang View Post
    If we could all stop trying to create the best server for a second, and actually solve real problems, that'd be cool.
    why are you trying to solve the non-problem of item containers when we have multiple sufficient implementations (that are better than this too), like you said focus your time on real problems - item containers aren't a problem

    Attached image
     

  8. Thankful user:


  9. #7  
    ???

    funkE's Avatar
    Join Date
    Feb 2008
    Posts
    2,612
    Thanks given
    255
    Thanks received
    989
    Rep Power
    1366
    Since I can't delete the thread, I guess I'm just going to remove my responses.
    .
     

  10. #8  
    Item Containers



    Scu11's Avatar
    Join Date
    Aug 2007
    Age
    30
    Posts
    16,307
    Thanks given
    7,215
    Thanks received
    12,308
    Rep Power
    5000
    Quote Originally Posted by PlatinumWang View Post
    dealing with bad code is a real problem
    why waste your time attempting to patch up a decrepit old base when there's a new base with a better implementation and all of these issues fixed? once again it's a non-problem, we have the solution in newer and better servers

    Attached image
     

  11. Thankful user:


  12. #9  
    ???

    funkE's Avatar
    Join Date
    Feb 2008
    Posts
    2,612
    Thanks given
    255
    Thanks received
    989
    Rep Power
    1366
    jet fuel can't
    .
     

  13. #10  
    Item Containers



    Scu11's Avatar
    Join Date
    Aug 2007
    Age
    30
    Posts
    16,307
    Thanks given
    7,215
    Thanks received
    12,308
    Rep Power
    5000
    Quote Originally Posted by PlatinumWang View Post
    because none of those "newer and better" servers has content comparable. as much as I wish it wasn't the truth, it is.
    so you've successfully deduced where your efforts should be spent: on content for these newer and better servers



    also did you even unit test this implementation? your solution of casting the sum of the two amounts to a long won't work because you didn't individually cast the integers, so it'll add them as integers (thus overflow), then it will cast it to a long - at which point it's too late. you need to individually cast each variable to a long when summing them

    Attached image
     

  14. Thankful user:


Page 1 of 2 12 LastLast

Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. item container
    By jelleplomp in forum Help
    Replies: 0
    Last Post: 05-12-2015, 04:45 PM
  2. Scroll Item Container?
    By relex lawl in forum Help
    Replies: 2
    Last Post: 06-04-2014, 12:53 AM
  3. [Any] Item Container
    By Anezka in forum Snippets
    Replies: 1
    Last Post: 04-30-2014, 04:56 PM
  4. Item Container
    By PlebScapePK in forum Tutorials
    Replies: 19
    Last Post: 03-16-2014, 12:52 AM
  5. 718 Item contains?
    By Ynneh in forum Help
    Replies: 2
    Last Post: 04-17-2013, 11:21 PM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •