Uploaded image for project: 'Minecraft: Java Edition'
  1. Minecraft: Java Edition
  2. MC-268011

Hoppers leak the last world they sucked item on

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • 24w09a
    • 1.20.4, 24w03b
    • None
    • Plausible
    • Performance
    • Normal
    • Platform

      Hoppers leak the last world they sucked item on and can keep the unloaded world in the memory until new item is sucked on in a loaded world. This seem to be due to the call to setItem(ItemStack.EMPTY) just before discarding the item. This ends up calling the ItemStack#setEntityRepresentation which then roots the entity to the static ItemStack.EMPTY.

      The fix would be to remove this call and/or adding a guard or a assert to ItemStack#setEntityRepresentation to ignore ItemStack.EMPTY.

      HopperBlockEntity:

      public static boolean addItem(Container $$0, ItemEntity $$1) {
      	boolean $$2 = false;
      	ItemStack $$3 = $$1.getItem().copy();
      	ItemStack $$4 = addItem((Container)null, $$0, $$3, (Direction)null);
      	if ($$4.isEmpty()) {
      		$$2 = true;
      		$$1.setItem(ItemStack.EMPTY); //Remove this?
      		$$1.discard();
      	} else {
      		$$1.setItem($$4);
      	}
      
      	return $$2;
      }
      

       

      ItemEntity:

      public void setItem(ItemStack $$0) {
      	this.getEntityData().set(DATA_ITEM, $$0);
      }
      
      @Override
      public void onSyncedDataUpdated(EntityDataAccessor<?> $$0) {
      	super.onSyncedDataUpdated($$0);
      	if (DATA_ITEM.equals($$0)) {
      		this.getItem().setEntityRepresentation(this);
      	}
      }
      

       
      ItemStack:

      public void setEntityRepresentation(@Nullable Entity $$0) {
      	//Add guard here? Or assert?
      	this.entityRepresentation = $$0;
      }
      

            gegy1000 [Mojang] Gegy
            isokissa3 Joni
            Votes:
            5 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:
              CHK: