Add SulfurCubeSwallowEvent#14061
Conversation
Strokkur424
left a comment
There was a problem hiding this comment.
I generally like the QoL this event provides. For anyone following along, with PlayerInteractAtEntityEvent, replacing the cube's contained item on interact can be done like so:
@EventHandler
void onInteractWithSulfurCube(PlayerInteractAtEntityEvent event) {
if (!(event.getRightClicked() instanceof SulfurCube cube)) {
return;
}
ItemStack is = event.getPlayer().getInventory().getItemInMainHand();
if (is.getType().asItemType() == ItemType.SHEARS) {
return;
}
if (!cube.getEquipment().getItem(EquipmentSlot.BODY).isEmpty()) {
return;
}
event.setCancelled(true);
cube.getEquipment().setItem(EquipmentSlot.BODY, ItemType.BIRCH_LOG.createItemStack());
event.getPlayer().swingMainHand();
}With this new event, that is simplified to just this:
@EventHandler
void onSulfurCubeSwallowItem(SulfurCubeSwallowItemEvent event) {
event.setNewItem(ItemType.BIRCH_LOG.createItemStack());
}Generally, a lot of entity interaction stuff is left just as a generic PlayerInteractAtEntityEvent. But in this case I'd argue there are enough lines saved and logical edge-cases (like that top version does not handle the small sulfur cubes not being allowed to swallow items normally) for this event to make sense.
The way it is integrated with NMS code also makes complete sense, for this reason I approve.
|
The punctuation and comments should be all resolved now |
d00ce24 to
9794ee4
Compare
|
Not consuming the original item based on the setter feels weird, that should either just be removed or be a separate method in the event (unless there's many existing events doing the same, but I couldn't think of any) |
|
iirc that's what PlayerItemConsumeEvent does, it doesn't remove the original item if you change it with the setter as said in the javadocs
|
|
I mean both of the implementations will feel weird; removing the item even if it was changed sounds weird since it doesn't use the original item so why remove it? But also not removing feels like something where players could just click on every sulfur cube which is weird too... I guess it's between choosing what is more appropriate and feels less weird |
Add a new event to the sulfur cube swallowing an item after the player interaction.