-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Made some methods and types available through an API. - Added an entrypoint to define villager trades from outside mods
- Loading branch information
Showing
13 changed files
with
227 additions
and
62 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
7 changes: 5 additions & 2 deletions
7
src/main/java/tk/estecka/shiftingwares/IVillagerEntityDuck.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 |
---|---|---|
@@ -1,6 +1,9 @@ | ||
package tk.estecka.shiftingwares; | ||
|
||
public interface IVillagerEntityDuck | ||
import tk.estecka.shiftingwares.api.IHasItemCache; | ||
|
||
public interface IVillagerEntityDuck | ||
extends IHasItemCache | ||
{ | ||
MapTradesCache shiftingwares$GetTradeCache(); | ||
MapTradesCache shiftingwares$GetItemCache(); | ||
} |
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
41 changes: 41 additions & 0 deletions
41
src/main/java/tk/estecka/shiftingwares/TradeLayouts/VanillaTradeLayout.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,41 @@ | ||
package tk.estecka.shiftingwares.TradeLayouts; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap; | ||
import net.minecraft.entity.passive.VillagerEntity; | ||
import net.minecraft.village.TradeOffers; | ||
import net.minecraft.village.VillagerData; | ||
import net.minecraft.village.VillagerProfession; | ||
import net.minecraft.village.TradeOffers.Factory; | ||
import tk.estecka.shiftingwares.ShiftingWares; | ||
import tk.estecka.shiftingwares.api.ITradeLayoutProvider; | ||
|
||
public class VanillaTradeLayout | ||
implements ITradeLayoutProvider | ||
{ | ||
public List<Factory[]> GetTradeLayout(VillagerEntity villager){ | ||
List<Factory[]> layout = new ArrayList<>(); | ||
VillagerProfession job = villager.getVillagerData().getProfession(); | ||
int jobLevel = villager.getVillagerData().getLevel(); | ||
|
||
Int2ObjectMap<Factory[]> jobPool = TradeOffers.PROFESSION_TO_LEVELED_TRADE.get(job); | ||
|
||
if (jobPool == null){ | ||
ShiftingWares.LOGGER.error("No trade pool for job {}.", job); | ||
return null; | ||
} | ||
|
||
for (int lvl=VillagerData.MIN_LEVEL; lvl<=jobLevel; ++lvl) | ||
{ | ||
var pool = jobPool.get(lvl); | ||
if (pool == null) | ||
ShiftingWares.LOGGER.error("Missing pool for job {} lvl.{}", job, lvl); | ||
else for (int i=0; i<2 && i<pool.length; ++i) | ||
layout.add(pool); | ||
} | ||
|
||
return layout; | ||
} | ||
|
||
} |
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
9 changes: 9 additions & 0 deletions
9
src/main/java/tk/estecka/shiftingwares/api/IHasItemCache.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,9 @@ | ||
package tk.estecka.shiftingwares.api; | ||
|
||
/** | ||
* Implemented by VillagerEntity | ||
*/ | ||
public interface IHasItemCache | ||
{ | ||
PersistentItemCache shiftingwares$GetItemCache(); | ||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/tk/estecka/shiftingwares/api/ITradeLayoutProvider.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,33 @@ | ||
package tk.estecka.shiftingwares.api; | ||
|
||
import java.util.List; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
import net.minecraft.entity.passive.VillagerEntity; | ||
import net.minecraft.village.TradeOffers.Factory; | ||
|
||
/** | ||
* Should be implemented by mods that want to use shifting-ware's entrypoint. | ||
*/ | ||
public interface ITradeLayoutProvider | ||
{ | ||
/** | ||
* @return For each hypothetical slot in the villager's offer listing, this | ||
* provides the pool of trades that can go into that slot. If this instance | ||
* does not know the layout of a specific villager, it can return null in | ||
* order to fall back to the vanilla layout. | ||
* | ||
* The same pool can be assigned to multiple slots in order to avoid | ||
* duplicates. Pool equality is evaluated by identity, i.e by comparing | ||
* pointers. | ||
* | ||
* The size of the returned list needs not match the size of the villager's | ||
* current lising; it should return the intended layout. The villager's | ||
* listing may have its size adjusted so as to match the return value. | ||
* | ||
* This should take into account the villager's current level, and only | ||
* provide trade slots which the villager has unlocked. | ||
* | ||
*/ | ||
@Nullable List<@NotNull Factory @NotNull[]> GetTradeLayout(VillagerEntity villager); | ||
} |
Oops, something went wrong.