Skip to content
This repository was archived by the owner on Jun 3, 2024. It is now read-only.

Conversation

@Rongmario
Copy link
Contributor

Used @Overwrite in latest commit as injections and redirects got crazy.

Roughly checked, and everything should be working.

These events are so similarly named, don't blame me for the EntityEvents methods, if you have any good ones pls say.

@TheGlitch76 TheGlitch76 self-requested a review June 22, 2020 22:31
@TheGlitch76
Copy link
Member

:concern:

Copy link
Member

@ZNixian ZNixian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there's a good reason for sending the EntityItemPickupEvent from it's own function then go ahead and merge anyway, but IMO it would make the relevant code significantly easier to read.

public void onPlayerCollision(PlayerEntity player) {
if (!this.world.isClient && this.pickupDelay <= 0) {
final ItemEntity entity = (ItemEntity) (Object) this;
int result = EntityEvents.onItemPickup(entity, player);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be easier just to move the event stuff in here? Without checking two different files it's not obvious what the result represents - event.getResult() == Result.ALLOW is much clearer than result == 1?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will be easier to move from EntityEvents back to its respective Hook class to prevent breaking compatibility with mods that use the provided hooks to fire the event.

@TheGlitch76 TheGlitch76 added the in progress This is being worked on and is not ready for final review label Jun 23, 2020
@TheGlitch76
Copy link
Member

On further review I'd like the threadlocal version to be used until we have a better alternative.

@Rongmario
Copy link
Contributor Author

Sure I'll revert to the ThreadLocal commit.

- Added entity.item events, ItemExpireEvent is implemented but ItemTossEvent is a stub right now.
- Implemented 'lifespan', Forge exposed this to modders via IForgeItem/IForgeItemStack. So the injections are commented out at the moment.
- Another injection is commented out, as IForgeItem/IForgeItemStack#onEntityItemUpdate isn't implemented yet.

-NOTE: I changed EntityItemPickupEvent's call's signature, it now returns a boolean as per request (can use Result too).  As it seems like -1 and 1 is returned, and 0 is never returned anywhere.
@Rongmario Rongmario requested a review from TheGlitch76 July 3, 2020 13:34
@Rongmario
Copy link
Contributor Author

Just updated, reverted Overwrite, and implemented rest of the entity.item events. More info see latest commit msg.

* removed from the inventory - and thus removed from the system.
*/
// TODO: Call Location - ForgeHook#onPlayerTossEvent -> PlayerEntity#dropSelectedItem + PlayerEntity#dropItem
public class ItemTossEvent extends ItemEvent {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May as well leave this out if you're not going to implement the hooks for it

Copy link
Contributor Author

@Rongmario Rongmario Jul 3, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can do it in the same PR if its cool :^)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Go ahead

- Scope-creep'd a little out of the PR

@Redirect(method = "onPlayerCollision", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerEntity;sendPickup(Lnet/minecraft/entity/Entity;I)V"))
private void onPlayerItemPickup(PlayerEntity entity, Entity item, int count) {
EntityEvents.firePlayerItemPickupEvent(entity, (ItemEntity) item, getStack().copy());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also implemented this event in #118.
patchwork-events-entity/src/main/java/net/patchworkmc/mixin/event/entity/MixinItemEntity.java

I created PlayerEvents to fire all types of PlayerEvent, so that EntityEvents can be less messy. I would suggest one of us should drop his PlayerEvent.ItemPickupEvent implementation. Sorry for the inconvenience, I didn't know this PR before I started #118.

Something I would like to discuss is that, in 1.14.4 (The yarnforge snapshot), Forge removed the entityIn.sendPickup(this, i); before if (itemstack.isEmpty()) { but in the later version they didnt. However, I don't think firing the PlayerEvent.ItemPickupEvent before or after entityIn.sendPickup(this, i); make any noticable difference.

@TheGlitch76
Copy link
Member

Merge conflicts

@Rongmario
Copy link
Contributor Author

Deprecating for: #118. I'll draft a tiny PR for EntityItemPickupEvent. And ItemTossEvent will have to wait until #118 is PR'd.

@Rongmario Rongmario closed this Jul 29, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

in progress This is being worked on and is not ready for final review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants