Skip to content

Commit

Permalink
Better villager interact feat. 2b ac
Browse files Browse the repository at this point in the history
Co-authored-by: Solanum <so1anum@proton.me>
  • Loading branch information
maxsupermanhd and S01anum committed Jul 14, 2024
1 parent 7fdf59e commit ccb4e71
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ yarn_mappings=1.21+build.2
loader_version=0.15.11

# Mod Properties
mod_version=1.4.6
mod_version=1.4.7
maven_group=maxsuperman.addons
archives_base_name=villager-roller

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.enchantment.EnchantmentLevelEntry;
import net.minecraft.entity.Entity;
import net.minecraft.entity.passive.VillagerEntity;
import net.minecraft.entity.projectile.ProjectileUtil;
import net.minecraft.item.EnchantedBookItem;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
Expand All @@ -52,9 +54,12 @@
import net.minecraft.registry.tag.EnchantmentTags;
import net.minecraft.sound.SoundEvent;
import net.minecraft.sound.SoundEvents;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.Identifier;
import net.minecraft.util.hit.EntityHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.village.TradeOffer;
import net.minecraft.village.TradeOfferList;
import net.minecraft.village.VillagerProfession;
Expand Down Expand Up @@ -542,7 +547,18 @@ public void triggerInteract() {
if (pauseOnScreen.get() && mc.currentScreen != null) {
info("Rolling paused, interact with villager to continue");
} else {
mc.interactionManager.interactEntity(mc.player, rollingVillager, Hand.MAIN_HAND);
Vec3d playerPos = mc.player.getEyePos();
Vec3d villagerPos = rollingVillager.getEyePos();
EntityHitResult entityHitResult = ProjectileUtil.raycast(mc.player, playerPos, villagerPos, rollingVillager.getBoundingBox(), Entity::canHit, playerPos.squaredDistanceTo(villagerPos));
if (entityHitResult == null) {
// Raycast didn't find villager entity?
mc.interactionManager.interactEntity(mc.player, rollingVillager, Hand.MAIN_HAND);
} else {
ActionResult actionResult = mc.interactionManager.interactEntityAtLocation(mc.player, rollingVillager, entityHitResult, Hand.MAIN_HAND);
if (!actionResult.isAccepted()) {
mc.interactionManager.interactEntity(mc.player, rollingVillager, Hand.MAIN_HAND);
}
}
}
}

Expand Down

0 comments on commit ccb4e71

Please sign in to comment.