use of net.minecraft.world.level.storage.loot.LootTable in project SpongeCommon by SpongePowered.
the class FishingHookMixin method retrieve.
/**
* @author Aaron1011 - February 6th, 2015
* @author Minecrell - December 24th, 2016 (Updated to Minecraft 1.11.2)
* @author Minecrell - June 14th, 2017 (Rewritten to handle cases where no items are dropped)
* @reason This needs to handle for both cases where a fish and/or an entity is being caught.
*/
@Overwrite
public int retrieve(final ItemStack stack) {
final Player playerEntity = this.shadow$getPlayerOwner();
if (!this.level.isClientSide && playerEntity != null) {
int i = 0;
// Sponge start
final List<Transaction<@NonNull ItemStackSnapshot>> transactions;
if (this.nibble > 0) {
// Moved from below
final LootContext.Builder lootcontext$builder = new LootContext.Builder((ServerLevel) this.level).withParameter(LootContextParams.ORIGIN, this.shadow$position()).withParameter(LootContextParams.TOOL, stack).withParameter(LootContextParams.THIS_ENTITY, (FishingHook) (Object) this).withRandom(this.random).withLuck((float) this.luck + playerEntity.getLuck());
final LootTable lootTable = this.level.getServer().getLootTables().get(BuiltInLootTables.FISHING);
final List<ItemStack> list = lootTable.getRandomItems(lootcontext$builder.create(LootContextParamSets.FISHING));
transactions = list.stream().map(ItemStackUtil::snapshotOf).map(snapshot -> new Transaction<>(snapshot, snapshot)).collect(Collectors.toList());
CriteriaTriggers.FISHING_ROD_HOOKED.trigger((ServerPlayer) playerEntity, stack, (FishingHook) (Object) this, list);
} else {
transactions = new ArrayList<>();
}
PhaseTracker.getCauseStackManager().pushCause(playerEntity);
if (SpongeCommon.post(SpongeEventFactory.createFishingEventStop(PhaseTracker.getCauseStackManager().currentCause(), ((FishingBobber) this), transactions))) {
// Event is cancelled
return 0;
}
if (this.hookedIn != null) {
this.bringInHookedEntity();
CriteriaTriggers.FISHING_ROD_HOOKED.trigger((ServerPlayer) playerEntity, stack, (FishingHook) (Object) this, Collections.emptyList());
this.level.broadcastEntityEvent((FishingHook) (Object) this, (byte) 31);
i = this.hookedIn instanceof ItemEntity ? 3 : 5;
}
// Sponge start - Moved up to event call
if (!transactions.isEmpty()) {
// Use transactions
for (final Transaction<@NonNull ItemStackSnapshot> transaction : transactions) {
if (!transaction.isValid()) {
continue;
}
final ItemStack itemstack = (ItemStack) (Object) transaction.finalReplacement().createStack();
// Sponge end
final ItemEntity entityitem = new ItemEntity(this.level, this.shadow$getX(), this.shadow$getY(), this.shadow$getZ(), itemstack);
final double d0 = playerEntity.getX() - this.shadow$getX();
final double d1 = playerEntity.getY() - this.shadow$getY();
final double d2 = playerEntity.getZ() - this.shadow$getZ();
final double d3 = Mth.sqrt(d0 * d0 + d1 * d1 + d2 * d2);
// double d4 = 0.1D;
entityitem.setDeltaMovement(d0 * 0.1D, d1 * 0.1D + Mth.sqrt(d3) * 0.08D, d2 * 0.1D);
this.level.addFreshEntity(entityitem);
playerEntity.level.addFreshEntity(new ExperienceOrb(playerEntity.level, playerEntity.getX(), playerEntity.getY() + 0.5D, playerEntity.getZ() + 0.5D, this.random.nextInt(6) + 1));
final Item item = itemstack.getItem();
if (item.is(ItemTags.FISHES)) {
playerEntity.awardStat(Stats.FISH_CAUGHT, 1);
}
}
PhaseTracker.getCauseStackManager().popCause();
// Sponge: Don't lower damage if we've also caught an entity
i = Math.max(i, 1);
}
if (this.onGround) {
i = 2;
}
this.shadow$remove();
return i;
} else {
return 0;
}
}
Aggregations