Added EntityItemMergeEvent#setResult

This commit is contained in:
Felix Cravic 2020-06-02 14:54:33 +02:00
parent 0da78193c5
commit bd08676525
2 changed files with 26 additions and 4 deletions

View File

@ -99,10 +99,11 @@ public class ItemEntity extends ObjectEntity {
if (!canApply)
continue;
EntityItemMergeEvent entityItemMergeEvent = new EntityItemMergeEvent(this, itemEntity);
final ItemStack result = stackingRule.apply(itemStack.clone(), totalAmount);
EntityItemMergeEvent entityItemMergeEvent = new EntityItemMergeEvent(this, itemEntity, result);
callCancellableEvent(EntityItemMergeEvent.class, entityItemMergeEvent, () -> {
ItemStack result = stackingRule.apply(itemStack.clone(), totalAmount);
setItemStack(result);
setItemStack(entityItemMergeEvent.getResult());
itemEntity.remove();
});
}

View File

@ -2,6 +2,7 @@ package net.minestom.server.event.entity;
import net.minestom.server.entity.ItemEntity;
import net.minestom.server.event.CancellableEvent;
import net.minestom.server.item.ItemStack;
/**
* Called when two {@link ItemEntity} are merging their ItemStack together to form a sole entity
@ -11,7 +12,9 @@ public class EntityItemMergeEvent extends CancellableEvent {
private ItemEntity source;
private ItemEntity merged;
public EntityItemMergeEvent(ItemEntity source, ItemEntity merged) {
private ItemStack result;
public EntityItemMergeEvent(ItemEntity source, ItemEntity merged, ItemStack result) {
this.source = source;
this.merged = merged;
}
@ -37,4 +40,22 @@ public class EntityItemMergeEvent extends CancellableEvent {
public ItemEntity getMerged() {
return merged;
}
/**
* Get the final item stack on the ground
*
* @return the item stack
*/
public ItemStack getResult() {
return result;
}
/**
* Change the item stack which will appear on the ground
*
* @param result the new item stack
*/
public void setResult(ItemStack result) {
this.result = result;
}
}