Skip to content

Commit

Permalink
1.20.4 update (#32)
Browse files Browse the repository at this point in the history
* Various improvements

- Update to 1.20.4
- Replaced `HashMap<k,v>` with `List<Pair<k,v>>` in `getEnchants(...)`
- Reformat enum constants
  • Loading branch information
Big-Iron-Cheems authored Dec 12, 2023
1 parent ad81a6f commit aec87b6
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 76 deletions.
35 changes: 18 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,33 @@
![checks](https://github.com/maxsupermanhd/meteor-villager-roller/actions/workflows/checks.yml/badge.svg)
![devbuild](https://github.com/maxsupermanhd/meteor-villager-roller/actions/workflows/devbuild.yml/badge.svg)

Addon that changes villager profession until desired trade found
Addon that changes villager profession until the desired trade is found.

We have [Discord server](https://discord.com/invite/DFsMKWJJPN)
We have a [Discord server](https://discord.com/invite/DFsMKWJJPN).

## Versions

| Minecraft | Meteor | Supported | Download |
|-------------|------------------|-----------|-----------------------------------------------------------------------------------------------------------------------------------------------|
| 1.20.2 | 0.5.5-dev >1945 | Yes | [1.4.3](https://github.com/maxsupermanhd/meteor-villager-roller/releases/download/1.4.3/villager-roller-1.4.3+mc1.20.2-rev.019b0cc.jar) |
| 1.20.1 | 0.5.4-dev >1846 | No | [1.4.2](https://github.com/maxsupermanhd/meteor-villager-roller/releases/download/1.4.2/villager-roller-1.4.2+mc1.20.1-rev.ac89621.jar) |
| 1.19.4 | 0.5.3-dev >1817 | No | [1.4.2](https://github.com/maxsupermanhd/meteor-villager-roller/releases/download/1.4.2/villager-roller-1.4.2+mc1.19.4-rev.ac89621-dirty.jar) |
| 1.19.3 | 0.5.2-dev >1714 | No | [1.3.6](https://github.com/maxsupermanhd/meteor-villager-roller/releases/download/1.3.6/villager-roller-1.3.6+mc1.19.3-rev.0700d38.jar) |
| 1.19.2 | 0.5.1-dev >1573 | No | [1.3.4](https://github.com/maxsupermanhd/meteor-villager-roller/releases/download/1.3.4/villager-roller-1.3.4+mc1.19.2-rev.f2c071c.jar) |
| 1.19.1 | 0.5.1-dev >1570 | No | [1.3.2](https://github.com/maxsupermanhd/meteor-villager-roller/releases/download/1.3.2/villager-roller-1.3.2+mc1.19.1-rev.bd5aa5e.jar) |
| 1.19 | 0.5.0-dev >=1563 | No | [1.3.1](https://github.com/maxsupermanhd/meteor-villager-roller/releases/download/1.3.1/villager-roller-1.3.1+mc1.19-build.34.jar) |
| 1.19 | 0.5.0-dev <1563 | No | [1.3](https://github.com/maxsupermanhd/meteor-villager-roller/releases/download/1.3/villager-roller-1.3+mc1.19-rev.b16e705.jar) |
| 1.18.2 | 0.4.9 | No | [1.3](https://github.com/maxsupermanhd/meteor-villager-roller/releases/download/1.3/villager-roller-1.3+mc1.18.2-rev.3d6f694.jar) |
| 1.18.1 | ? | No | [1.2.1](https://github.com/maxsupermanhd/meteor-villager-roller/releases/download/1.2.1/villager-roller-1.2.1.jar) |
| Minecraft | Meteor | Supported | Download |
|-----------|------------------|-----------|-----------------------------------------------------------------------------------------------------------------------------------------------|
| 1.20.2 | 0.5.5-dev >1945 | Yes | [1.4.3](https://github.com/maxsupermanhd/meteor-villager-roller/releases/download/1.4.3/villager-roller-1.4.3+mc1.20.2-rev.019b0cc.jar) |
| 1.20.1 | 0.5.4-dev >1846 | No | [1.4.2](https://github.com/maxsupermanhd/meteor-villager-roller/releases/download/1.4.2/villager-roller-1.4.2+mc1.20.1-rev.ac89621.jar) |
| 1.19.4 | 0.5.3-dev >1817 | No | [1.4.2](https://github.com/maxsupermanhd/meteor-villager-roller/releases/download/1.4.2/villager-roller-1.4.2+mc1.19.4-rev.ac89621-dirty.jar) |
| 1.19.3 | 0.5.2-dev >1714 | No | [1.3.6](https://github.com/maxsupermanhd/meteor-villager-roller/releases/download/1.3.6/villager-roller-1.3.6+mc1.19.3-rev.0700d38.jar) |
| 1.19.2 | 0.5.1-dev >1573 | No | [1.3.4](https://github.com/maxsupermanhd/meteor-villager-roller/releases/download/1.3.4/villager-roller-1.3.4+mc1.19.2-rev.f2c071c.jar) |
| 1.19.1 | 0.5.1-dev >1570 | No | [1.3.2](https://github.com/maxsupermanhd/meteor-villager-roller/releases/download/1.3.2/villager-roller-1.3.2+mc1.19.1-rev.bd5aa5e.jar) |
| 1.19 | 0.5.0-dev >=1563 | No | [1.3.1](https://github.com/maxsupermanhd/meteor-villager-roller/releases/download/1.3.1/villager-roller-1.3.1+mc1.19-build.34.jar) |
| 1.19 | 0.5.0-dev <1563 | No | [1.3](https://github.com/maxsupermanhd/meteor-villager-roller/releases/download/1.3/villager-roller-1.3+mc1.19-rev.b16e705.jar) |
| 1.18.2 | 0.4.9 | No | [1.3](https://github.com/maxsupermanhd/meteor-villager-roller/releases/download/1.3/villager-roller-1.3+mc1.18.2-rev.3d6f694.jar) |
| 1.18.1 | ? | No | [1.2.1](https://github.com/maxsupermanhd/meteor-villager-roller/releases/download/1.2.1/villager-roller-1.2.1.jar) |

Download links for older versions are here only for archival reasons, do not use them.

If you want to roll villagers on server that is on different Minecraft version please use [viafabric](https://github.com/ViaVersion/ViaFabric).
If you want to roll villagers on servers running older Minecraft versions please use [ViaFabricPlus](https://github.com/ViaVersion/ViaFabricPlus).

## Solving use-case

Addon is targeted for lazy people that are playing on server and trying to find enchantment on librarians. No functionality about other trades/professions implemented and planned, you can pull request them if you really want to.
Addon is targeted for lazy people that are playing on server and trying to find enchantment on librarians.
No functionality about other trades/professions implemented and planned, you can pull request them if you really want to.

## How-to

Expand Down Expand Up @@ -67,4 +68,4 @@ Integrating Villager Roller into other clients without modifying underlying feat

GPL-3.0, see LICENSE in project root

## I did not gave permission to publish this mod on CurseForge
## I did not give permission to publish this mod on CurseForge
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
org.gradle.jvmargs=-Xmx4G

# Fabric (https://fabricmc.net/versions.html)
minecraft_version=1.20.2
yarn_mappings=1.20.2+build.4
loader_version=0.14.23
minecraft_version=1.20.4
yarn_mappings=1.20.4+build.2
loader_version=0.15.1

# Mod Properties
mod_version=1.4.3
mod_version=1.4.4
maven_group=maxsuperman.addons
archives_base_name=villager-roller

meteor_version=0.5.5-SNAPSHOT
meteor_version=0.5.6-SNAPSHOT
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ class VillagerInteractMixin {
@Inject(at = @At("HEAD"), method = "interactMob(Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/util/Hand;)Lnet/minecraft/util/ActionResult;", cancellable = true)
public void interactMob(CallbackInfoReturnable<ActionResult> cir) {
VillagerRoller roller = Modules.get().get(VillagerRoller.class);
if (roller.currentState == VillagerRoller.State.WaitingForTargetVillager) {
roller.currentState = VillagerRoller.State.RollingBreakingBlock;
if (roller.currentState == VillagerRoller.State.WAITING_FOR_TARGET_VILLAGER) {
roller.currentState = VillagerRoller.State.ROLLING_BREAKING_BLOCK;
roller.rollingVillager = (VillagerEntity) (Object) this;
roller.info("We got your villager");
cir.setReturnValue(ActionResult.CONSUME);
Expand Down
94 changes: 42 additions & 52 deletions src/main/java/maxsuperman/addons/roller/modules/VillagerRoller.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package maxsuperman.addons.roller.modules;

import com.google.common.collect.Maps;
import it.unimi.dsi.fastutil.Pair;
import it.unimi.dsi.fastutil.objects.ObjectIntImmutablePair;
import meteordevelopment.meteorclient.MeteorClient;
import meteordevelopment.meteorclient.events.entity.player.StartBreakingBlockEvent;
import meteordevelopment.meteorclient.events.world.TickEvent;
Expand Down Expand Up @@ -154,17 +155,17 @@ public class VillagerRoller extends Module {
);

public enum State {
Disabled,
WaitingForTargetBlock,
WaitingForTargetVillager,
RollingBreakingBlock,
RollingWaitingForVillagerProfessionClear,
RollingPlacingBlock,
RollingWaitingForVillagerProfessionNew,
RollingWaitingForVillagerTrades
DISABLED,
WAITING_FOR_TARGET_BLOCK,
WAITING_FOR_TARGET_VILLAGER,
ROLLING_BREAKING_BLOCK,
ROLLING_WAITING_FOR_VILLAGER_PROFESSION_CLEAR,
ROLLING_PLACING_BLOCK,
ROLLING_WAITING_FOR_VILLAGER_PROFESSION_NEW,
ROLLING_WAITING_FOR_VILLAGER_TRADES
}

public State currentState = State.Disabled;
public State currentState = State.DISABLED;
public VillagerEntity rollingVillager;
private BlockPos rollingBlockPos;
private Block rollingBlock;
Expand All @@ -178,13 +179,13 @@ public VillagerRoller() {

@Override
public void onActivate() {
currentState = State.WaitingForTargetBlock;
currentState = State.WAITING_FOR_TARGET_BLOCK;
info("Attack block you want to roll");
}

@Override
public void onDeactivate() {
currentState = State.Disabled;
currentState = State.DISABLED;
info("Roller disabled.");
}

Expand Down Expand Up @@ -230,7 +231,7 @@ public boolean loadSearchingFromFile(File f) {
}
NbtCompound r = null;
try {
r = NbtIo.read(f);
r = NbtIo.read(f.toPath());
} catch (IOException e) {
e.printStackTrace();
}
Expand Down Expand Up @@ -262,7 +263,7 @@ public boolean saveSearchingToFile(File f) {
return false;
}
try {
NbtIo.write(c, f);
NbtIo.write(c, f.toPath());
} catch (IOException e) {
e.printStackTrace();
return false;
Expand Down Expand Up @@ -407,8 +408,8 @@ private void fillWidget(GuiTheme theme, WVerticalList list) {
fillWidget(theme, list);
};

WButton create = controls.add(theme.button("Add")).expandX().widget();
create.action = () -> mc.setScreen(new EnchantmentSelectScreen(theme, e -> {
WButton add = controls.add(theme.button("Add")).expandX().widget();
add.action = () -> mc.setScreen(new EnchantmentSelectScreen(theme, e -> {
if (e.isVanilla()) {
e.minLevel = e.getMaxLevel();
e.maxCost = getMinimumPrice(Registries.ENCHANTMENT.get(e.enchantment), e.minLevel);
Expand Down Expand Up @@ -568,47 +569,36 @@ public void triggerInteract() {
}
}

public Map<Identifier, Integer> getEnchants(ItemStack stack) {
Map<Identifier, Integer> ret = Maps.newLinkedHashMap();
if (!stack.isOf(Items.ENCHANTED_BOOK) || stack.getNbt() == null) {
return ret;
}
public List<Pair<Identifier, Integer>> getEnchants(ItemStack stack) {
List<Pair<Identifier, Integer>> ret = new ArrayList<>();
NbtList list = stack.getNbt().getList("StoredEnchantments", NbtElement.COMPOUND_TYPE);
list.addAll(stack.getNbt().getList("Enchantments", NbtElement.COMPOUND_TYPE));
for (int i = 0; i < list.size(); ++i) {
NbtCompound c = list.getCompound(i);
Identifier id = EnchantmentHelper.getIdFromNbt(c);
if (id == null) continue;
ret.put(id, EnchantmentHelper.getLevelFromNbt(c));
}
list = stack.getNbt().getList("Enchantments", NbtElement.COMPOUND_TYPE);
for (int i = 0; i < list.size(); ++i) {
NbtCompound c = list.getCompound(i);
Identifier id = EnchantmentHelper.getIdFromNbt(c);
if (id == null) continue;
ret.put(id, EnchantmentHelper.getLevelFromNbt(c));
ret.add(new ObjectIntImmutablePair<>(id, EnchantmentHelper.getLevelFromNbt(c)));
}
return ret;
}

public void triggerTradeCheck(TradeOfferList l) {
if (currentState != State.RollingWaitingForVillagerTrades) return;
if (currentState != State.ROLLING_WAITING_FOR_VILLAGER_TRADES) return;
for (TradeOffer offer : l) {
// info(String.format("Offer: %s", offer.getSellItem().toString()));
ItemStack sellItem = offer.getSellItem();
if (!sellItem.isOf(Items.ENCHANTED_BOOK) || sellItem.getNbt() == null) break;

Map<Identifier, Integer> sellingEnchants = getEnchants(sellItem);

for (Map.Entry<Identifier, Integer> enchant : sellingEnchants.entrySet()) {
int enchantLevel = enchant.getValue();
Identifier enchantId = enchant.getKey();
for (Pair<Identifier, Integer> enchant : getEnchants(sellItem)) {
int enchantLevel = enchant.right();
Identifier enchantId = enchant.left();
String enchantName = getEnchantmentName(enchantId);
String enchantIdString = enchantId.toString();
// level enchant.getValue()
// enchantment enchant.getKey()
boolean found = false;
for (RollingEnchantment e : searchingEnchants) {
if (!e.enabled) continue;
if (!e.enchantment.toString().equals(enchantIdString)) continue;
if (!e.enabled || !e.enchantment.toString().equals(enchantIdString)) continue;
found = true;
if (e.minLevel <= 0) {
int ml = e.getMaxLevel();
Expand Down Expand Up @@ -640,15 +630,15 @@ public void triggerTradeCheck(TradeOfferList l) {
}
// ((MerchantScreenHandler)mc.player.currentScreenHandler).closeHandledScreen();
mc.player.closeHandledScreen();
currentState = State.RollingBreakingBlock;
currentState = State.ROLLING_BREAKING_BLOCK;
}

@EventHandler(priority = EventPriority.HIGH)
private void onStartBreakingBlockEvent(StartBreakingBlockEvent event) {
if (currentState == State.WaitingForTargetBlock) {
if (currentState == State.WAITING_FOR_TARGET_BLOCK) {
rollingBlockPos = event.blockPos;
rollingBlock = mc.world.getBlockState(rollingBlockPos).getBlock();
currentState = State.WaitingForTargetVillager;
currentState = State.WAITING_FOR_TARGET_VILLAGER;
info("Rolling block selected, now interact with villager you want to roll");
// event.cancel(); //Dirty hack
}
Expand All @@ -665,27 +655,27 @@ private void placeFailed(String msg) {
@EventHandler
private void onTick(TickEvent.Pre event) {
switch (currentState) {
case RollingBreakingBlock -> {
case ROLLING_BREAKING_BLOCK -> {
if (mc.world.getBlockState(rollingBlockPos) == Blocks.AIR.getDefaultState()) {
// info("Block is broken, waiting for villager to clean profession...");
currentState = State.RollingWaitingForVillagerProfessionClear;
currentState = State.ROLLING_WAITING_FOR_VILLAGER_PROFESSION_CLEAR;
} else if (!BlockUtils.breakBlock(rollingBlockPos, true)) {
info("Can not break block");
toggle();
}
}
case RollingWaitingForVillagerProfessionClear -> {
case ROLLING_WAITING_FOR_VILLAGER_PROFESSION_CLEAR -> {
if (mc.world.getBlockState(rollingBlockPos).isOf(Blocks.LECTERN)) {
info("Rolling block mining reverted?");
currentState = State.RollingBreakingBlock;
currentState = State.ROLLING_BREAKING_BLOCK;
return;
}
if (rollingVillager.getVillagerData().getProfession() == VillagerProfession.NONE) {
// info("Profession cleared");
currentState = State.RollingPlacingBlock;
currentState = State.ROLLING_PLACING_BLOCK;
}
}
case RollingPlacingBlock -> {
case ROLLING_PLACING_BLOCK -> {
FindItemResult item = InvUtils.findInHotbar(rollingBlock.asItem());
if (!item.found()) {
placeFailed("Lectern not found in hotbar");
Expand All @@ -699,29 +689,29 @@ private void onTick(TickEvent.Pre event) {
placeFailed("Failed to place lectern");
return;
}
currentState = State.RollingWaitingForVillagerProfessionNew;
currentState = State.ROLLING_WAITING_FOR_VILLAGER_PROFESSION_NEW;
if (maxProfessionWaitTime.get() > 0) {
currentProfessionWaitTime = System.currentTimeMillis();
}
}
case RollingWaitingForVillagerProfessionNew -> {
case ROLLING_WAITING_FOR_VILLAGER_PROFESSION_NEW -> {
if (maxProfessionWaitTime.get() > 0 && (currentProfessionWaitTime + maxProfessionWaitTime.get() <= System.currentTimeMillis())) {
info("Villager did not take profession within the specified time");
currentState = State.RollingBreakingBlock;
currentState = State.ROLLING_BREAKING_BLOCK;
return;
}
if (mc.world.getBlockState(rollingBlockPos) == Blocks.AIR.getDefaultState()) {
info("Lectern placement reverted by server (AC?)");
currentState = State.RollingPlacingBlock;
currentState = State.ROLLING_PLACING_BLOCK;
return;
}
if (!mc.world.getBlockState(rollingBlockPos).isOf(Blocks.LECTERN)) {
info("Placed wrong block?!");
currentState = State.RollingBreakingBlock;
currentState = State.ROLLING_BREAKING_BLOCK;
return;
}
if (rollingVillager.getVillagerData().getProfession() != VillagerProfession.NONE) {
currentState = State.RollingWaitingForVillagerTrades;
currentState = State.ROLLING_WAITING_FOR_VILLAGER_TRADES;
triggerInteract();
}
}
Expand Down

0 comments on commit aec87b6

Please sign in to comment.