Skip to content

Commit

Permalink
Merge pull request #13 from okocraft/dev/1.21
Browse files Browse the repository at this point in the history
Minecraft 1.21
  • Loading branch information
Siroshun09 authored Aug 4, 2024
2 parents 0bb310b + 44241af commit d8e243d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 17 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
group = "net.okocraft.boxtradestick"
version = "1.6"

val mcVersion = "1.20.6"
val mcVersion = "1.21"
val fullVersion = "${version}-mc${mcVersion}"

repositories {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ private void updateTradeItem(@NotNull AbstractVillager villager, int row, int re
this.inventory.setItem(row * 9 + 2, this.createIngredientIcon(firstIngredient, recipe, true).applyTo(firstIngredient.clone()));

if (size == 2) {
var secondIngredient = ingredients.getFirst();
var secondIngredient = ingredients.get(1);
this.inventory.setItem(row * 9 + 3, this.createIngredientIcon(secondIngredient, recipe, false).applyTo(secondIngredient.clone()));
} else {
this.inventory.setItem(row * 9 + 3, null);
Expand Down
40 changes: 25 additions & 15 deletions src/main/java/net/okocraft/boxtradestick/NMSUtil.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package net.okocraft.boxtradestick;

import io.papermc.paper.event.player.PlayerPurchaseEvent;
import java.util.Objects;
import net.minecraft.util.Mth;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.effect.MobEffects;
Expand Down Expand Up @@ -103,9 +102,16 @@ private static boolean simulateMobInteract(Player player, WanderingTrader wander
return wanderingTrader.getRecipeCount() != 0;
}

// See: net.minecraft.world.entity.npc.Villager#stopTrading
public static void stopTrading(AbstractVillager villager) {
if (villager instanceof CraftAbstractVillager craftVillager) {
craftVillager.getHandle().setTradingPlayer(null);
if (villager instanceof CraftAbstractVillager craftAbstractVillager) {
craftAbstractVillager.getHandle().setTradingPlayer(null);

if (villager instanceof CraftVillager craftVillager) {
for (var merchantOffer : craftVillager.getHandle().getOffers()) {
merchantOffer.resetSpecialPriceDiff();
}
}
}
}

Expand All @@ -121,26 +127,30 @@ private static void updateSpecialPrices(CraftPlayer player, CraftVillager villag
var playerHandle = player.getHandle();
var villagerHandle = villager.getHandle();

int i = villagerHandle.getPlayerReputation(playerHandle);
int playerReputation = villagerHandle.getPlayerReputation(playerHandle);

if (i != 0) {
if (playerReputation != 0) {
for (MerchantOffer merchantrecipe : villagerHandle.getOffers()) {
if (!merchantrecipe.ignoreDiscounts) {
merchantrecipe.addToSpecialPriceDiff(-Mth.floor((float) i * merchantrecipe.getPriceMultiplier()));
merchantrecipe.addToSpecialPriceDiff(-Mth.floor((float) playerReputation * merchantrecipe.getPriceMultiplier()));
}
}
}

if (playerHandle.hasEffect(MobEffects.HERO_OF_THE_VILLAGE)) {
MobEffectInstance mobeffect = playerHandle.getEffect(MobEffects.HERO_OF_THE_VILLAGE);
int j = Objects.requireNonNull(mobeffect).getAmplifier();
for (MerchantOffer merchantrecipe1 : villagerHandle.getOffers()) {
if (merchantrecipe1.ignoreDiscounts) continue; // Paper
double d0 = 0.3D + 0.0625D * (double) j;
int k = (int) Math.floor(d0 * (double) merchantrecipe1.getBaseCostA().getCount());
MobEffectInstance mobeffect = playerHandle.getEffect(MobEffects.HERO_OF_THE_VILLAGE);

merchantrecipe1.addToSpecialPriceDiff(-Math.max(k, 1));
}
if (mobeffect == null) {
return;
}

int amplifier = mobeffect.getAmplifier();

for (MerchantOffer merchantrecipe1 : villagerHandle.getOffers()) {
if (merchantrecipe1.ignoreDiscounts) continue; // Paper
double d = 0.3D + 0.0625D * (double) amplifier;
int i = (int) Math.floor(d * (double) merchantrecipe1.getBaseCostA().getCount());

merchantrecipe1.addToSpecialPriceDiff(-Math.max(i, 1));
}
}

Expand Down

0 comments on commit d8e243d

Please sign in to comment.