Skip to content

Commit

Permalink
More wiki stuff for morejs
Browse files Browse the repository at this point in the history
  • Loading branch information
LLytho committed Jul 26, 2024
1 parent b7c405e commit 5cb037b
Show file tree
Hide file tree
Showing 7 changed files with 305 additions and 36 deletions.
17 changes: 17 additions & 0 deletions wikis/morejs/.vitepress/config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,25 @@ export default defineConfig({
{ text: "Update offer", link: "update-offer" },
],
},
{
text: "Potion brewing",
link: "potion-brewing",
}
],
},
{
text: "Utils",
items: [
{
text: "VillagerUtils",
link: "villager-utils",
},
{
text: "MoreUtils",
link: "more-utils",
}
]
}
],
},
})
6 changes: 6 additions & 0 deletions wikis/morejs/docs/more-utils.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# MoreUtils

## Methods

- `findStructure(pos: BlockPos, level: Level, structure: string | string[] | RegEx, chunkRadius: number)`
- `findBiome(pos: BlockPos, level: Level, biome: string | string[] | RegEx, chunkRadius: number)`
84 changes: 84 additions & 0 deletions wikis/morejs/docs/potion-brewing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# Potion Brewing

## Methods

- `addPotionBrewing(ingredient: Ingredient, input: Potion, output: Potion)`
- `removePotionBrewing(filter: PotionBrewingFilter)`
- `addContainerRecipe(ingredient: Ingredient, input: Item, output: Item)`
- `removeContainer(ingredient: Ingredient)`
- `addCustomBrewing(ingredient: Ingredient, input: Ingredient, output: Item)`
- `removeCustomBrewing(filter: CustomBrewingFilter)`
- `getCustomBrewingRecipes()`
- Returns a mutable list of all custom brewing recipes. Some mods register their own implementation of a custom brewing recipe. This method can be used to remove them or modify them.

## Usage

### Add brewing

::: info
Remember that the arguments for input and output are `Potion` ids and not items!
:::

This will add a brewing recipe which creates a strong regeneration potion when using apples.

```js
MoreJS.registerPotionBrewing((event) => {
event.addPotionBrewing("minecraft:apple", "minecraft:water", "minecraft:strong_regeneration")
})
```

### Add custom brewing

Custom brewing allows to not rely on any potion. We can just use any item to convert.

```js
MoreJS.registerPotionBrewing((event) => {
event.addCustomBrewing("minecraft:emerald", "minecraft:nether_star", "minecraft:diamond")
})
```

### Remove brewing

For removing simple potion brewings we can use a `PotionBrewingFilter` which looks like follow:

```ts
interface PotionBrewingFilter {
ingredient: Ingredient
input: Potion | Potion[] | RegEx
output: Potion | Potion[] | RegEx
}
```

Using the filter does not require to use all the arguments. Arguments which are not given automatically act as wildcards.

```js
MoreJS.registerPotionBrewing((event) => {
event.removePotionBrewing({
ingredient: "minecraft:apple",
input: "minecraft:harming",
output: "minecraft:strong_harming",
})
})
```

### Remove custom brewing

For removing custom potion brewings we can use a `CustomBrewingFilter` which looks like follow:

```ts
interface CustomBrewingFilter {
ingredient: Ingredient
input: Ingredient
output: Ingredient
}
```

```js
MoreJS.registerPotionBrewing((event) => {
event.removeCustomBrewing({
ingredient: "minecraft:emerald",
input: "minecraft:nether_star",
output: "minecraft:diamond",
})
})
```
34 changes: 17 additions & 17 deletions wikis/morejs/docs/update-offer.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,31 @@ Event can be used by using `MoreJS.updateOffer((event) => {...})`

## Methods

- `.getEntity()`
- `.isVillager()`
- `.isWanderer()`
- `.isUnknownTrader()`
- `getEntity()`
- `isVillager()`
- `isWanderer()`
- `isUnknownTrader()`
- Useful for custom traders from mods
- `.getVillagerData()`
- `getVillagerData()`
- Will return `null` if entity is wanderer or some custom trader
- `.isProfession(profession: string)`
- `.getProfession()`
- `isProfession(profession: string)`
- `getProfession()`
- Return the profession of the trader. If no profession exist return `minecraft:none`
- `.getVillagerLevel()`
- `getVillagerLevel()`
- Return `-1` if trader doesn't have a level
- `.getAllOffers()`
- `getAllOffers()`
- Returns a mutable list of all current existing offers from the trader
- `.getOffer()`
- `getOffer()`
- Returns the offer which will be added to the trader
- `.setOffer(offer: Offer)`
- `.getUsedTrades()`
- `setOffer(offer: Offer)`
- `getUsedTrades()`
- Get all trades which are currently used to create offers for the entity.
- `.getRandomOffer()` or `.getRandomOffer(trades: Trade[])`
- `getRandomOffer()` or `getRandomOffer(trades: Trade[])`
- Create a random offer from given trades (If no trades provided, `getUsedTrades` is used automatically). This offer will not be automatically added to the trader!
- `.getVillagerTrades(profession: string)`
- `.getVillagerTrades(profession: string, int level)`
- `.getWandererTrades(int level)`
- `.getRandom()`
- `getVillagerTrades(profession: string)`
- `getVillagerTrades(profession: string, int level)`
- `getWandererTrades(int level)`
- `getRandom()`

## Usage

Expand Down
20 changes: 10 additions & 10 deletions wikis/morejs/docs/villager-trades.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ Event can be used by using `MoreJS.villagerTrades((event) => {...})`

## Methods

- `.addTrade(profession: string, level: number, input: Item | Item[], output: Item)`
- `.addTrade(profession: string, level: number, trade: Trade)`
- `.addCustomTrade(profession: string, level: number, (offer, entity, random) => {})`
- `.removeTrade(filter: TradeFilter)`
- `addTrade(profession: string, level: number, input: Item | Item[], output: Item)`
- `addTrade(profession: string, level: number, trade: Trade)`
- `addCustomTrade(profession: string, level: number, (offer, entity, random) => {})`
- `removeTrade(filter: TradeFilter)`
- Allows better control over trade removal. See [example](#tradefilter) for usage.
- `.removeVanillaTypedTrades(profession: string | string[], level: number | Range)`
- `.removeVanillaTypedTrades(profession: string | string[])`
- `.removeVanillaTypedTrades()`
- `.removeModdedTypedTrades(professions: string | string[], level: number | Range)`
- `.removeModdedTypedTrades(professions: string | string[])`
- `.removeModdedTypedTrades()`
- `removeVanillaTypedTrades(profession: string | string[], level: number | Range)`
- `removeVanillaTypedTrades(profession: string | string[])`
- `removeVanillaTypedTrades()`
- `removeModdedTypedTrades(professions: string | string[], level: number | Range)`
- `removeModdedTypedTrades(professions: string | string[])`
- `removeModdedTypedTrades()`

## Usage

Expand Down
164 changes: 163 additions & 1 deletion wikis/morejs/docs/villager-utils.md
Original file line number Diff line number Diff line change
@@ -1 +1,163 @@
# Villager Utils
# VillagerUtils

## Methods

- `isVanillaTypedTrade(trade: Trade)`
- Checks if given `trade` is using a vanilla trade class internally. Keep in mind that mods can do this too.
- `isModdedTypedTrade(trade: Trade)`
- `isCustomTypedTrade(trade: Trade)`
- Returns `true` for trade classes provided by `MoreJS`
- `createSimpleTrade(input: Item | Item[], output: Item)`
- `createCustomTrade((offer, entity, random) => {})`
- `createStructureMapTrade(input: Item | Item[], structure: string | RegEx | string[])`
- `createBiomeMapTrade(input: Item | Item[], biome: string | RegEx | string[])`
- `createCustomMapTrade(input: Item | Item[], (level, entity) => {})`
- `createEnchantedItemTrade(input: Item | Item[], output: Item)`
- `createEnchantedItemTrade(input: Item | Item[], output: Item, enchantments: string | string[] | RegEx)`
- `createStewTrade(input: Item | Item[])`
- `createPotionTrade(input: Item | Item[])`
- `getVillagerTrades(profession: string)`
- Returns a list of all trades for given profession
- `getVillagerTrades(profession: string, level: number)`
- Returns a list of all trades for given profession and level
- `getRandomVillagerTrade(profession: string)`
- Returns a random trade for given profession
- `getRandomVillagerTrade(profession: string, level: number)`
- Returns a random trade for given profession and level
- `getWandererTrades(level: number)`
- Returns a list of all trades for given level
- `getRandomWandererTrade(level: number)`
- Returns a random trade for given level

## Usage

### Treasure map trades

```js
MoreJS.villagerTrades((event) => {
const trade = VillagerUtils.createStructureMapTrade("minecraft:diamond", "minecraft:stronghold")
event.addTrade("minecraft:cartographer", 1, trade)
})
```

```js
MoreJS.villagerTrades((event) => {
const trade = VillagerUtils.createStructureMapTrade(
["minecraft:diamond", "minecraft:paper"],
"minecraft:stronghold"
)
event.addTrade("minecraft:cartographer", 1, trade)
})
```

We can also use `#` to search for a tag. This works for structures and biomes.

```js
MoreJS.villagerTrades((event) => {
const trade = VillagerUtils.createBiomeMapTrade("5x minecraft:emerald", "#minecraft:is_forest")
event.addTrade("minecraft:cartographer", 1, trade)
})
```

It's also possible to create a custom map trade by providing your own block pos. This example will get a random overworld biome and search for the position of the biome.

```js
MoreJS.villagerTrades((event) => {
const trade = VillagerUtils.createCustomMapTrade(
["10x minecraft:diamond", "minecraft:paper"],
(level, entity) => {
const rndBiome = Registry.of("worldgen/biome")
.getValues("#minecraft:is_overworld")
.getRandom()
return MoreUtils.findBiome(entity.blockPosition(), level, rndBiome, 250)
}
)

event.addTrade("minecraft:cartographer", 1, trade)
})
```

#### Further modify map trades

When creating a map trade we can further modify it. You can find possible map markers [here](https://minecraft.wiki/w/Map#Map_icons)

```js
MoreJS.villagerTrades((event) => {
const trade = VillagerUtils.createBiomeMapTrade("5x minecraft:emerald", "#minecraft:is_forest")
.displayName("Nearest forest")
.marker("banner_orange")
.noPreview()
.scale(4)

event.addTrade("minecraft:cartographer", 1, trade)
})
```

### Enchanted trades

If no enchantments are provided the trade will use `#minecraft:on_traded_equipment` for the enchantments.

```js
MoreJS.villagerTrades((event) => {
const trade = VillagerUtils.createEnchantedItemTrade(
"5x minecraft:emerald",
"minecraft:diamond_pickaxe"
)

event.addTrade("minecraft:weaponsmith", 1, trade)
})
```

We can also provide which enchantments we want.

```js
MoreJS.villagerTrades((event) => {
const trade = VillagerUtils.createEnchantedItemTrade(
"5x minecraft:emerald",
"minecraft:diamond_pickaxe",
"#morejs:our_cool_enchantments"
)

event.addTrade("minecraft:weaponsmith", 1, trade)
})
```

```js
MoreJS.villagerTrades((event) => {
const trade = VillagerUtils.createEnchantedItemTrade(
"5x minecraft:emerald",
"minecraft:diamond_pickaxe",
["minecraft:unbreaking", "minecraft:mending", "minecraft:fortune"]
)

event.addTrade("minecraft:weaponsmith", 1, trade)
})
```

#### Define the enchantment levels

The enchantment trade will enchant the given item by a given level or levels. We can set them by `.levels()`. The default value is `[5, 20]` which is the same as vanilla uses.

```js
MoreJS.villagerTrades((event) => {
const trade = VillagerUtils.createEnchantedItemTrade(
"5x minecraft:emerald",
"minecraft:diamond_pickaxe"
).levels(10)

event.addTrade("minecraft:weaponsmith", 1, trade)
})
```

Or we can set them by `.levels([10, 30])` if we want a random range between the two values.

```js
MoreJS.villagerTrades((event) => {
const trade = VillagerUtils.createEnchantedItemTrade(
"5x minecraft:emerald",
"minecraft:diamond_pickaxe"
).levels([10, 30])

event.addTrade("minecraft:weaponsmith", 1, trade)
})
```
16 changes: 8 additions & 8 deletions wikis/morejs/docs/wanderer-trades.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ Event can be used by using `MoreJS.wandererTrades((event) => {...})`

## Methods

- `.addTrade(level: number, input: Item | Item[], output: Item)`
- `.addTrade(level: number, trade: Trade)`
- `.addCustomTrade(level: number, (offer, entity, random) => {})`
- `.removeTrade(filter: TradeFilter)`
- `addTrade(level: number, input: Item | Item[], output: Item)`
- `addTrade(level: number, trade: Trade)`
- `addCustomTrade(level: number, (offer, entity, random) => {})`
- `removeTrade(filter: TradeFilter)`
- Allows better control over trade removal. See [example](#tradefilter) for usage.
- `.removeVanillaTypedTrades(level: number | Range)`
- `.removeVanillaTypedTrades()`
- `.removeModdedTypedTrades(level: number | Range)`
- `.removeModdedTypedTrades()`
- `removeVanillaTypedTrades(level: number | Range)`
- `removeVanillaTypedTrades()`
- `removeModdedTypedTrades(level: number | Range)`
- `removeModdedTypedTrades()`

## Usage

Expand Down

0 comments on commit 5cb037b

Please sign in to comment.