Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Breaking chest doesn't drop items #4

Closed
JakeMalis opened this issue Mar 7, 2021 · 4 comments
Closed

Breaking chest doesn't drop items #4

JakeMalis opened this issue Mar 7, 2021 · 4 comments

Comments

@JakeMalis
Copy link

I put some items into a chest, and then when I broke the chest the items didn't break. Not sure if that is intentional, but it may be a bug.

@SummeryLavaRain
Copy link

I don't think he ever implemented it in the game as a mechanic.

@myriath
Copy link

myriath commented Apr 26, 2021

It seems as though this is supposed to happen, as this code seems to try to do that, the issue is it's in the hit() method instead of the onHit() method, so it never gets called as the chest can't hit something (At least I don't think it can).

// EntityChest.java
@Override
    public boolean hit(Entity e) {
        if (super.hit(e)) {
            for (ItemStack s : this.inventory.stacks) {
                EntityItem.spawn(this.level, s, Level.toCenter(e.tileX), Level.toCenter(e.tileY));
            }
            return true;
        }
        return false;
    }

A potential fix could be Overriding the getDrops() method (which gets called when the furniture item is hit) to also return all of the items inside the chest instead of just the chest item itself.

// EntityFurniture.java
protected List<ItemStack> getDrops() {
        return List.of(new ItemStack(new ItemInstance(this.item)));
    }
// EntityChest.java 
@Override
    protected List<ItemStack> getDrops() {
        List<ItemStack> temp = this.inventory.stacks;
        temp.addAll(super.getDrops());
        return temp;
    }

@steviegt6
Copy link

It seems as though this is supposed to happen, as this code seems to try to do that, the issue is it's in the hit() method instead of the onHit() method, so it never gets called as the chest can't hit something (At least I don't think it can).

// EntityChest.java
@Override
    public boolean hit(Entity e) {
        if (super.hit(e)) {
            for (ItemStack s : this.inventory.stacks) {
                EntityItem.spawn(this.level, s, Level.toCenter(e.tileX), Level.toCenter(e.tileY));
            }
            return true;
        }
        return false;
    }

A potential fix could be Overriding the getDrops() method (which gets called when the furniture item is hit) to also return all of the items inside the chest instead of just the chest item itself.

// EntityFurniture.java
protected List<ItemStack> getDrops() {
        return List.of(new ItemStack(new ItemInstance(this.item)));
    }
// EntityChest.java 
@Override
    protected List<ItemStack> getDrops() {
        List<ItemStack> temp = this.inventory.stacks;
        temp.addAll(super.getDrops());
        return temp;
    }

Can confirm that this is a valid solution.
WorkingChestDrops

@JakeMalis
Copy link
Author

@steviegt6 yes that works, thanks for the info!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants