mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-03 23:17:48 +01:00
Added EntityItemMergeEvent#setResult
This commit is contained in:
parent
0da78193c5
commit
bd08676525
@ -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();
|
||||
});
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user