Jump to content

KGJP

Members
  • Posts

    9
  • Joined

  • Last visited

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

KGJP's Achievements

Tree Puncher

Tree Puncher (2/8)

0

Reputation

  1. I was able to do this by overriding TemptGoal and manipulating AttackTarget and delayTemptCounter. I'm glad there's a great existing class,... Thanks for the pork and carrots.
  2. Assumptions and what we want to achieve No longer a target for MonsterEntity while equipped with an iron chest plate. You also want to make the same motion if you have an iron chest plate in your right or left hand What I've tried As an example, F "Ignored by Zombies" Override the following goal of ZombieEntity this.targetSelector.addGoal(2, new NearestAttackableTargetGoal<>(this, PlayerEntity.class, true)); Extract the goals of zombieEntity.targetSelector. Find the above goal that targets PlayerEntity and extract the targetEntitySelector. private static final Field privateFieldGoals = ObfuscationReflectionHelper .findField(GoalSelector.class, "goals"); private static final Field privateFieldExcludedFieldTargetEntitySelector = ObfuscationReflectionHelper .findField(NearestAttackableTargetGoal.class, "targetEntitySelector"); Set your custom IronChecker in setCustomPredicate EntityPredicate entityPredicate = (EntityPredicate) privateFieldExcludedFieldTargetEntitySelector .get(goal); entityPredicate.setCustomPredicate(new IronChecker()); private static class IronChecker implements Predicate<LivingEntity> { @Override public boolean test(LivingEntity livingEntity) { if (!(livingEntity instanceof PlayerEntity)) { return false; } PlayerEntity playerEntity = (PlayerEntity) livingEntity; if (playerEntity.getHeldItemMainhand() .isItemEqual(Items.DIAMOND_CHESTPLATE.getDefaultInstance())) { System.out.println("HeldItemMainhand"); return false; } System.out.println(playerEntity.inventory.armorInventory); if (playerEntity.inventory.armorInventory .contains(Items.DIAMOND_CHESTPLATE.getDefaultInstance())) { return false; } System.out.println(playerEntity.inventory.offHandInventory); if (playerEntity.inventory.offHandInventory .contains(Items.DIAMOND_CHESTPLATE.getDefaultInstance())) { return false; } return true; } } If you spawn a zombie while holding the iron chest plate, it will ignore you. However, if you don't have the chest plate, you become a target for the zombie. And if you switch to the iron chest plate again, You will continue to be a target for the zombies. (Ideally you want to be untargeted.) supplementary information minecraft version 1.16.3 minecraft forge version 1.16.3 I have looked into various things and tried, but I can't seem to solve the problem and I am having trouble. Please help me out. A similar move is the pig. If you hold a carrot, or a fishing rod with a carrot, the pig will follow the player. But what I would like to implement is an even faster switch. In this case, the moment you hold the chest plate in your hand, it is released from the target. Once the chest plate is removed from the hand, the player becomes the target, just like the existing movement. The moment you hold the chest plate in your hand again, you are released from the target.
  3. Thank you. I love you.
  4. I see, so you're saying that what you're running now is the runClient development environment? So when you write it out to a jar file, the current code won't work?
  5. You mean you have to describe it at the top? Set<PrioritizedGoal> goals = (Set) privateFieldGoals.get(zombie.targetSelector); goals.removeAll(goals.stream() .filter(prioritizedGoal -> prioritizedGoal.getPriority() == 2) .collect(Collectors.toList())); It worked with the code I wrote. What is the benefit of using the ObfuscationReflectionHelper that Forge provides?
  6. http://tutorials.jenkov.com/java-reflection/private-fields-and-methods.html You can do this kind of hack-like coding with Java features. I'd like to try it with this. private static Field privateFieldGoals; static { try { privateFieldGoals = GoalSelector.class.getDeclaredField("goals"); privateFieldGoals.setAccessible(true); } catch (NoSuchFieldException e) { System.err.println("Error"); } }
  7. I went to that page and implemented it. I believe it is as written, but what is wrong with it?
  8. jar { manifest { attributes([ "Specification-Title" : "examplemod", "Specification-Vendor" : "examplemodsareus", "Specification-Version" : "1", // We are version 1 of ourselves "Implementation-Title" : project.name, "Implementation-Version" : "${version}", "Implementation-Vendor" : "examplemodsareus", "Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ") ]) accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg') } } public-f net.minecraft.entity.ai.goal.GoalSelector goals I decided to use Access Transformer. But it doesn't take a gradle build. org.gradle.api.GradleScriptException: A problem occurred evaluating root project 'MyMod'. Caused by: groovy.lang.MissingPropertyException: Could not set unknown property 'accessTransformer' for object of type org.gradle.api.java.archives.internal.DefaultManifest. at org.gradle.internal.metaobject.AbstractDynamicObject.setMissingProperty(AbstractDynamicObject.java:118) at org.gradle.internal.metaobject.ConfigureDelegate.setProperty(ConfigureDelegate.java:105)
  9. Assumptions and what we want to achieve If you can change or delete the goals added to the goalSelector and targetSelector, you can solve this problem. (See below for targetSelector only) What I tried below is an example: "Erase the movement of existing zombies from trying to target the player What I've tried 1. reassign the new instance to targetSelector public final GoalSelector goalSelector; public final GoalSelector targetSelector; → Can't do it for final. 2. writing code to eliminate a specific goal @SubscribeEvent public static void mobEvent(LivingSpawnEvent event) { if (!(event.getEntity() instanceof ZombieEntity)) { return; } ZombieEntity zombie = (ZombieEntity) event.getEntity(); Stream<PrioritizedGoal> pgStream = zombie.targetSelector.getRunningGoals() .filter(prioritizedGoal -> prioritizedGoal.getPriority() == 2); Optional<PrioritizedGoal> prioritizedGoal = pgStream.findAny(); if (prioritizedGoal.isPresent()) { zombie.targetSelector.removeGoal(prioritizedGoal.get().getGoal()); } targetSelector.removeGoal is provided, but it has to be an instance of the target. The goal the zombie targets the player with is set in PrioritizedGoal's Priority 2. The only way to get the existing goal is with targetSelector.getRunningGoals(), so the moment RunningGoal becomes Priority 2 (the moment it tries to target the player), it's forced to remove the Priority 2 goal. code supplementary information minecraft version 1.16.3 minecraft forge version 1.16.3 I have looked into various things and tried, but I can't seem to solve the problem and I am having trouble. Please help me out. What is the best practice coding for overwriting or changing the AI of an existing MOB?
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.