-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
139 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/main/java/com/almostreliable/morejs/features/villager/events/PostUpdateOfferEventJS.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.almostreliable.morejs.features.villager.events; | ||
|
||
import com.almostreliable.morejs.core.Events; | ||
import net.minecraft.world.entity.npc.AbstractVillager; | ||
import net.minecraft.world.entity.npc.Villager; | ||
import net.minecraft.world.entity.npc.VillagerProfession; | ||
import net.minecraft.world.entity.npc.VillagerTrades; | ||
import net.minecraft.world.item.trading.MerchantOffer; | ||
import net.minecraft.world.item.trading.MerchantOffers; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
public class PostUpdateOfferEventJS extends UpdateOfferEventJS { | ||
|
||
@SuppressWarnings("ConstantValue") | ||
public static void invoke(AbstractVillager villager, MerchantOffers allOffers) { | ||
if (villager instanceof Villager v) { | ||
var data = v.getVillagerData(); | ||
if (data == null) { | ||
return; | ||
} | ||
|
||
if (data.getProfession() == VillagerProfession.NONE) { | ||
return; | ||
} | ||
} | ||
|
||
Events.POST_UPDATE_OFFERS.post(new PostUpdateOfferEventJS(villager, allOffers)); | ||
} | ||
|
||
public PostUpdateOfferEventJS(AbstractVillager villager, MerchantOffers allOffers) { | ||
super(villager, allOffers); | ||
} | ||
|
||
public void addOffer(@Nullable MerchantOffer offer) { | ||
if (offer != null) { | ||
getAllOffers().add(offer); | ||
} | ||
} | ||
|
||
public void addTrade(VillagerTrades.ItemListing trade) { | ||
var offer = trade.getOffer(getEntity(), getRandom()); | ||
addOffer(offer); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
...ain/java/com/almostreliable/morejs/features/villager/events/SingleUpdateOfferEventJS.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.almostreliable.morejs.features.villager.events; | ||
|
||
import com.google.common.base.Preconditions; | ||
import net.minecraft.world.entity.npc.AbstractVillager; | ||
import net.minecraft.world.entity.npc.VillagerTrades; | ||
import net.minecraft.world.item.trading.MerchantOffer; | ||
import net.minecraft.world.item.trading.MerchantOffers; | ||
|
||
import javax.annotation.Nullable; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
public class SingleUpdateOfferEventJS extends UpdateOfferEventJS { | ||
|
||
private final VillagerTrades.ItemListing[] possibleTrades; | ||
private MerchantOffer offer; | ||
@Nullable private List<VillagerTrades.ItemListing> cachedWandererTrades; | ||
|
||
public SingleUpdateOfferEventJS(AbstractVillager villager, MerchantOffers allOffers, VillagerTrades.ItemListing[] possibleTrades, MerchantOffer offer) { | ||
super(villager, allOffers); | ||
this.possibleTrades = possibleTrades; | ||
this.offer = offer; | ||
} | ||
|
||
public List<VillagerTrades.ItemListing> getUsedTrades() { | ||
return Arrays.asList(possibleTrades); | ||
} | ||
|
||
public MerchantOffer getOffer() { | ||
return offer; | ||
} | ||
|
||
public void setOffer(MerchantOffer offer) { | ||
Preconditions.checkNotNull(offer, "Offer must not be null"); | ||
this.offer = offer; | ||
} | ||
|
||
public void setOffer(VillagerTrades.ItemListing trade) { | ||
MerchantOffer newOffer = trade.getOffer(getEntity(), getLevel().getRandom()); | ||
if (newOffer != null) { | ||
this.offer = newOffer; | ||
} | ||
} | ||
|
||
@Nullable | ||
public MerchantOffer createRandomOffer() { | ||
return createRandomOffer(getUsedTrades()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/main/java/com/almostreliable/morejs/mixin/villager/VillagerMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.almostreliable.morejs.mixin.villager; | ||
|
||
import com.almostreliable.morejs.features.villager.events.PostUpdateOfferEventJS; | ||
import net.minecraft.world.entity.npc.AbstractVillager; | ||
import net.minecraft.world.entity.npc.Villager; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
@Mixin(Villager.class) | ||
public class VillagerMixin { | ||
|
||
@Inject(method = "updateTrades", at = @At(value = "RETURN")) | ||
private void morejs$invokePostUpdateOffer(CallbackInfo ci) { | ||
var self = (AbstractVillager) (Object) this; | ||
PostUpdateOfferEventJS.invoke(self, self.getOffers()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters