mojira.dev
MC-65029

Hopper minecart collects items far too quickly / ignores TransferCooldown

The bug

MinecartHoppers completely ignore the TransferCooldown tag.

The reason

The variable field_174900_c (BlockPos) is only set in the constructor but after that never changed:

EntityMinecartHopper.java (1.8)

public EntityMinecartHopper(World worldIn, double p_i1721_2_, double p_i1721_4_, double p_i1721_6_) {
        super(worldIn, p_i1721_2_, p_i1721_4_, p_i1721_6_);
        this.field_174900_c = BlockPos.ORIGIN;
    }

BlockPos.ORIGIN is new BlockPos(0, 0, 0). So when it later tests if the current BlockPos of the minecart is equal to the stored block pos it will fail (unless it is at 0, 0, 0).
So is sets the TransferCooldown to 0 and after that tests if it can transfer, so the test will always (unless it is at 0, 0, 0) succeed, causing it to pick up items with a speed of 1 item per tick.
The reason why the BlockPos is tested might be because the TransferCooldown is initialized with -1, but as the canTransfer() (rather cannotTransfer()) method would then return false it would work anyways.

EntityMinecartHopper.java (1.8)

/**
 * Returns whether the hopper cart can currently transfer an item.
 */
public boolean canTransfer() {
	// Probably wrong method name from MCP, it is rather cannotTransfer()
	return this.transferTicker > 0;
}

/**
 * Called to update the entity's position/logic.
 */
public void onUpdate() {
    super.onUpdate();

    if (!this.worldObj.isRemote && this.isEntityAlive() && this.getBlocked()) {
        BlockPos var1 = new BlockPos(this);

        if (var1.equals(this.field_174900_c)) {
           // This tests if the stored block position (field_174900_c) equals the actual block position and this fails ALWAYS
            --this.transferTicker;
        }
        else {
            this.setTransferTicker(0);
        }

        if (!this.canTransfer()) {
            this.setTransferTicker(0);

	    // Tries to transfer the items
            if (this.func_96112_aD()) {
                this.setTransferTicker(4);
                this.markDirty();
            }
        }
    }
}

Note

Testing for getBlocked() seems to be not needed as onUpdate() seems to be called only when the MinecartHopper is not blocked.

Wrong names

The wrong names can be caused by MCP as isRemote() is described as
"This is set to true for client worlds, and false for server worlds."
which would mean that hopper minecarts would not work in client worlds.
The method getBlocked() is described like this:
"Get whether this hopper minecart is being blocked by an activator rail."
Which makes no sense as well as then a blocked MinecartHopper would collect items.

I hope it is alright, that I added that much code from Minecraft here

Linked issues

Attachments

Comments 13

I think this may to do with the fact hopper minecarts can be used to vacuum items along the way (~18.5 items/second according to the wiki).

IMO any fix for the superfast unloading (if that's even necessary), should not affect the minecart vacuuming ability or they become pretty useless for (farm) loot collection.

Original reporter is inactive, giving this ticket to reporter of MC-89735.

Confirmed for 17w06a

Before I post a separate bug report, I want to make sure I am not duplicating this one.

Scenario, track with one powered activator rail with a hopper above pointing away from the rail (perpendicular to track, if it makes a difference). Minecart with hopper passes under the hopper and pulls items from the hopper, which it should not do. (If I have 3 powered activator rails with a hopper above the center, nothing gets pulled by the hopper minecart as expected.) Same bug?

@@unknown that appears to be a different bug. I created MC-117477 for it.

3 more comments

Still exists in 1.16.3. This causes 'erratic' behavior when placing a hopper minecart in the end at 0/0/0 on top of a trapdoor. (also in vanilla singleplayer)

[media]

Can confirm in 1.17.1. Never knew this was a bug, I always thought this was intentional.

Note: the setup by @unknown causes the minecart with hopper to transfer items at the expected speed.

Created MC-235260 as follow-up report, describing the behavior @unknown mentioned, since this report here was resolved as "Works As Intended"

This issue being marked as works as intended makes very little sense in regards to the logic, especially as with Mojangs mappings we can see the intent of the field in play, at least by the name: `lastPosition`. The only way I could see this as being WAI is if it's just an "acceptable bug" given its age.

The logic pulled out in this issue generally intends to demonstrate that the minecart should behave like a hopper when standing still, but should serve to slurp items away when moving around, as this field is not updated, the cart just follows through assuming its a new block and skips the cooldown, unless it's in 0, 0, 0, in which case the cooldowns work as logically expected here.

Kevin Zhu

marcono1234

(Unassigned)

Confirmed

Entities

Minecraft 14w31a, Minecraft 1.8, Minecraft 15w40b, Minecraft 15w46a, Minecraft 16w33a, ..., Minecraft 1.13.1, 1.15.2, 20w22a, 1.16.3, 1.17.1

Retrieved