use of io.izzel.arclight.common.bridge.entity.player.PlayerInventoryBridge in project Arclight by IzzelAliz.
the class ItemEntityMixin method onCollideWithPlayer.
/**
* @author IzzelAliz
* @reason
*/
@Overwrite
public void onCollideWithPlayer(final PlayerEntity entity) {
if (!this.world.isRemote) {
final ItemStack itemstack = this.getItem();
final net.minecraft.item.Item item = itemstack.getItem();
final int i = itemstack.getCount();
int hook = net.minecraftforge.event.ForgeEventFactory.onItemPickup((ItemEntity) (Object) this, entity);
if (hook < 0)
return;
ItemStack copy = itemstack.copy();
final int canHold = ((PlayerInventoryBridge) entity.inventory).bridge$canHold(itemstack);
final int remaining = i - canHold;
if (this.pickupDelay <= 0 && (hook == 1 || canHold > 0)) {
copy.setCount(canHold);
net.minecraftforge.fml.hooks.BasicEventHooks.firePlayerItemPickupEvent(entity, (ItemEntity) (Object) this, copy);
itemstack.setCount(canHold);
final PlayerPickupItemEvent playerEvent = new PlayerPickupItemEvent(((ServerPlayerEntityBridge) entity).bridge$getBukkitEntity(), (Item) this.getBukkitEntity(), remaining);
playerEvent.setCancelled(!((PlayerEntityBridge) entity).bridge$canPickUpLoot());
Bukkit.getPluginManager().callEvent(playerEvent);
if (playerEvent.isCancelled()) {
itemstack.setCount(i);
return;
}
final EntityPickupItemEvent entityEvent = new EntityPickupItemEvent(((LivingEntityBridge) entity).bridge$getBukkitEntity(), (Item) this.getBukkitEntity(), remaining);
entityEvent.setCancelled(!((PlayerEntityBridge) entity).bridge$canPickUpLoot());
Bukkit.getPluginManager().callEvent(entityEvent);
if (entityEvent.isCancelled()) {
itemstack.setCount(i);
return;
}
itemstack.setCount(canHold + remaining);
this.pickupDelay = 0;
} else if (this.pickupDelay == 0) {
this.pickupDelay = -1;
}
if (this.pickupDelay == 0 && (this.owner == null || /*|| 6000 - this.age <= 200*/
this.owner.equals(entity.getUniqueID())) && entity.inventory.addItemStackToInventory(itemstack)) {
entity.onItemPickup((ItemEntity) (Object) this, i);
if (itemstack.isEmpty()) {
this.remove();
itemstack.setCount(i);
}
entity.addStat(Stats.ITEM_PICKED_UP.get(item), i);
}
}
}
use of io.izzel.arclight.common.bridge.entity.player.PlayerInventoryBridge in project Arclight by IzzelAliz.
the class AbstractArrowEntityMixin method onCollideWithPlayer.
/**
* @author IzzelAliz
* @reason
*/
@Overwrite
public void onCollideWithPlayer(final PlayerEntity entityhuman) {
if (!this.world.isRemote && (this.inGround || this.getNoClip()) && this.arrowShake <= 0) {
ItemStack itemstack = this.getArrowStack();
if (this.pickupStatus == AbstractArrowEntity.PickupStatus.ALLOWED && !itemstack.isEmpty() && ((PlayerInventoryBridge) entityhuman.inventory).bridge$canHold(itemstack) > 0) {
final ItemEntity item = new ItemEntity(this.world, this.posX, this.posY, this.posZ, itemstack);
final PlayerPickupArrowEvent event = new PlayerPickupArrowEvent(((ServerPlayerEntityBridge) entityhuman).bridge$getBukkitEntity(), new CraftItem(((CraftServer) Bukkit.getServer()), (AbstractArrowEntity) (Object) this, item), (AbstractArrow) this.getBukkitEntity());
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
return;
}
itemstack = item.getItem();
}
boolean flag = this.pickupStatus == AbstractArrowEntity.PickupStatus.ALLOWED || (this.pickupStatus == AbstractArrowEntity.PickupStatus.CREATIVE_ONLY && entityhuman.abilities.isCreativeMode) || (this.getNoClip() && this.getShooter().getUniqueID() == entityhuman.getUniqueID());
if (this.pickupStatus == AbstractArrowEntity.PickupStatus.ALLOWED && !entityhuman.inventory.addItemStackToInventory(itemstack)) {
flag = false;
}
if (flag) {
entityhuman.onItemPickup((AbstractArrowEntity) (Object) this, 1);
this.remove();
}
}
}
Aggregations