VillagerMixin.java 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. * This file is part of architectury.
  3. * Copyright (C) 2020, 2021 architectury
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Lesser General Public
  7. * License as published by the Free Software Foundation; either
  8. * version 3 of the License, or (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public License
  16. * along with this program; if not, write to the Free Software Foundation,
  17. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. */
  19. package me.shedaniel.architectury.mixin;
  20. import me.shedaniel.architectury.registry.trade.VillagerTradeOfferContext;
  21. import me.shedaniel.architectury.registry.trade.impl.TradeRegistryData;
  22. import net.minecraft.world.entity.EntityType;
  23. import net.minecraft.world.entity.npc.Villager;
  24. import net.minecraft.world.entity.npc.VillagerData;
  25. import net.minecraft.world.item.trading.MerchantOffer;
  26. import net.minecraft.world.level.Level;
  27. import org.jetbrains.annotations.Nullable;
  28. import org.spongepowered.asm.mixin.Mixin;
  29. import org.spongepowered.asm.mixin.Shadow;
  30. @Mixin(Villager.class)
  31. public abstract class VillagerMixin extends AbstractVillagerMixin {
  32. public VillagerMixin(EntityType<?> entityType, Level level) {
  33. super(entityType, level);
  34. }
  35. @Shadow
  36. public abstract VillagerData getVillagerData();
  37. @Override
  38. public MerchantOffer architectury$handleOffer(MerchantOffer offer) {
  39. VillagerData vd = getVillagerData();
  40. VillagerTradeOfferContext context = new VillagerTradeOfferContext(vd, offer, this, random);
  41. boolean removeResult = TradeRegistryData.invokeVillagerOfferRemoving(context);
  42. if (removeResult) {
  43. return null;
  44. }
  45. TradeRegistryData.invokeVillagerOfferModify(context);
  46. return offer;
  47. }
  48. @Override
  49. @Nullable
  50. public Integer architectury$getMaxOfferOverride() {
  51. return TradeRegistryData.getVillagerMaxOffers(getVillagerData().getProfession(), getVillagerData().getLevel());
  52. }
  53. }