Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.6.4]Making A Hostile Mob Non-Hostile


starwarsmace
 Share

Recommended Posts

Depending upon the mob (if it is vanilla or not), you may be able to simply remove the AI tasks from its AI, or insert/overwrite with your own tasks.  This could be done with the EntityJoinWorld event.

 

Another method might be to handle the LivingSetAttackTargetEvent, cancelling the target/overwriting the target for that entity.  (Haven't played with this one myself...so..it _might_ be viable)

 

A bit of a hackier method would be to use a tick-handler and examine entities near players, and remove/reset their AI target.

 

There may well be other methods as well, as this is not something that I've looked into very much.

 

Edit:  these are methods that should work fine with vanilla entities.  Handling mod entities will be hit-and miss depending upon whether they call the appropriate events and/or use the vanilla AI system.

 

 

Link to comment
Share on other sites

Depending upon the mob (if it is vanilla or not), you may be able to simply remove the AI tasks from its AI, or insert/overwrite with your own tasks.  This could be done with the EntityJoinWorld event.

 

Another method might be to handle the LivingSetAttackTargetEvent, cancelling the target/overwriting the target for that entity.  (Haven't played with this one myself...so..it _might_ be viable)

 

A bit of a hackier method would be to use a tick-handler and examine entities near players, and remove/reset their AI target.

 

There may well be other methods as well, as this is not something that I've looked into very much.

 

Edit:  these are methods that should work fine with vanilla entities.  Handling mod entities will be hit-and miss depending upon whether they call the appropriate events and/or use the vanilla AI system.

 

Can you please give me code how to use those methods to stop vanilla zombies from attacking the player. I would greatly appreciate that.

I'm back from being gone for... I think its been about a year. I'm pretty sure nobody remembers me, but hello anybody who does!

Link to comment
Share on other sites

zombie.targetTasks.removeTask(zombie.targetTasks.taskEntries.get(1));

 

Let me know if it works, I didn't test it.  You'll have an issue if it is supposed to be a "toggle" as the EntityZombie constructor code puts it into the array second, and if you add it back with zombie.targetTasks.addTask(2, new EntityAINearestAttackableTarget(zombie, EntityPlayer.class, 0, true)); it will be third.  Adapt accordingly.

Link to comment
Share on other sites

Giving me errors in Eclipse.

EntityZombie.targetTasks.removeTask(EntityZombie.targetTasks.taskEntries.get(1));

Errors:

Multiple markers at this line

- Cannot make a static reference to the non-static field

EntityZombie.targetTasks

- Cannot make a static reference to the non-static field

EntityZombie.targetTasks

I'm back from being gone for... I think its been about a year. I'm pretty sure nobody remembers me, but hello anybody who does!

Link to comment
Share on other sites

Yeah, I missed that they weren't static...makes it a lot harder for me to test them now too...you'll have to get your item's right click target entity, check if it's a zombie, then run the code from my edit on the casted entity.

 

public boolean itemInteractionForEntity(ItemStack itemStack,EntityPlayer player,EntityLivingBase target) {
	if (target.worldObj.isRemote) return false;

	if (target instanceof EntityZombie && 
			((EntityZombie) target).targetTasks.taskEntries.get(1) instanceof EntityAINearestAttackableTarget)
	{
		((EntityZombie) target).targetTasks.removeTask((EntityAINearestAttackableTarget)((EntityZombie) target).targetTasks.taskEntries.get(1));
	}

	return false;
}

 

Link to comment
Share on other sites

Third time's the charm.  I actually tested it this time.

 

 

@Override
public boolean itemInteractionForEntity(ItemStack itemStack,EntityPlayer player,EntityLivingBase target) {
	player.sendChatToPlayer(ChatMessageComponent.createFromText("Activated."));

	// Run locally only
	if (target.worldObj.isRemote) return false;

	player.sendChatToPlayer(ChatMessageComponent.createFromText("Testing for EntityZombie."));
	if (target instanceof EntityZombie)
	{
		player.sendChatToPlayer(ChatMessageComponent.createFromText("EntityZombie, testing task."));
		EntityZombie zombie = (EntityZombie) target;
		EntityAITaskEntry task = (EntityAITaskEntry) zombie.targetTasks.taskEntries.get(1);
		if (task.action instanceof EntityAINearestAttackableTarget)
		{
			player.sendChatToPlayer(ChatMessageComponent.createFromText("Task."));
			player.sendChatToPlayer(ChatMessageComponent.createFromText("Removing."));
			zombie.targetTasks.removeTask(task.action);

			player.sendChatToPlayer(ChatMessageComponent.createFromText("Tamed."));
		}
	}

	return false;
}

 

Link to comment
Share on other sites

That will still allow a "tamed" zombie to attack villagers after the first right-click.  After the second right-click, they won't attack villagers either.  Cast the task.action and check the targetClass property against EntityPlayer.class to change this.  Sorry for the screwups, still a newb to this and this was actually my first dive into the AI.

Link to comment
Share on other sites

It worked until this error came.

 

---- Minecraft Crash Report ----
// My bad.

Time: 1/16/14 3:42 PM
Description: Ticking memory connection

java.lang.IndexOutOfBoundsException: Index: 1, Size: 1
at java.util.ArrayList.rangeCheck(Unknown Source)
at java.util.ArrayList.get(Unknown Source)
at rotten_flesh_mod.RottenFleshWandZombieTamer.itemInteractionForEntity(RottenFleshWandZombieTamer.java:29)
at net.minecraft.item.ItemStack.func_111282_a(ItemStack.java:421)
at net.minecraft.entity.player.EntityPlayer.interactWith(EntityPlayer.java:1257)
at net.minecraft.network.NetServerHandler.handleUseEntity(NetServerHandler.java:846)
at net.minecraft.network.packet.Packet7UseEntity.processPacket(Packet7UseEntity.java:36)
at net.minecraft.network.MemoryConnection.processReadPackets(MemoryConnection.java:89)
at net.minecraft.network.NetServerHandler.networkTick(NetServerHandler.java:141)
at net.minecraft.network.NetworkListenThread.networkTick(NetworkListenThread.java:54)
at net.minecraft.server.integrated.IntegratedServerListenThread.networkTick(IntegratedServerListenThread.java:109)
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:691)
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:587)
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:129)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:484)
at net.minecraft.server.ThreadMinecraftServer.run(ThreadMinecraftServer.java:583)


A detailed walkthrough of the error, its code path and all known details is as follows:
---------------------------------------------------------------------------------------

-- Head --
Stacktrace:
at java.util.ArrayList.rangeCheck(Unknown Source)
at java.util.ArrayList.get(Unknown Source)
at rotten_flesh_mod.RottenFleshWandZombieTamer.itemInteractionForEntity(RottenFleshWandZombieTamer.java:29)
at net.minecraft.item.ItemStack.func_111282_a(ItemStack.java:421)
at net.minecraft.entity.player.EntityPlayer.interactWith(EntityPlayer.java:1257)
at net.minecraft.network.NetServerHandler.handleUseEntity(NetServerHandler.java:846)
at net.minecraft.network.packet.Packet7UseEntity.processPacket(Packet7UseEntity.java:36)
at net.minecraft.network.MemoryConnection.processReadPackets(MemoryConnection.java:89)
at net.minecraft.network.NetServerHandler.networkTick(NetServerHandler.java:141)

-- Ticking connection --
Details:
Connection: net.minecraft.network.NetServerHandler@a88cdff
Stacktrace:
at net.minecraft.network.NetworkListenThread.networkTick(NetworkListenThread.java:54)
at net.minecraft.server.integrated.IntegratedServerListenThread.networkTick(IntegratedServerListenThread.java:109)
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:691)
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:587)
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:129)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:484)
at net.minecraft.server.ThreadMinecraftServer.run(ThreadMinecraftServer.java:583)

-- System Details --
Details:
Minecraft Version: 1.6.4
Operating System: Windows 8 (amd64) version 6.2
Java Version: 1.7.0_45, Oracle Corporation
Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
Memory: 211564048 bytes (201 MB) / 562561024 bytes (536 MB) up to 1301282816 bytes (1241 MB)
JVM Flags: 0 total; 
AABB Pool Size: 1937 (108472 bytes; 0 MB) allocated, 1682 (94192 bytes; 0 MB) used
Suspicious classes: FML and Forge are installed
IntCache: cache: 3, tcache: 0, allocated: 3, tallocated: 63
FML: MCP v8.11 FML v6.99.19.964 Minecraft Forge 9.11.1.964 5 mods loaded, 5 mods active
mcp{8.09} [Minecraft Coder Pack] (minecraft.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
FML{6.99.19.964} [Forge Mod Loader] (forge-1.6.4-9.11.1.964-mcp.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
Forge{9.11.1.964} [Minecraft Forge] (forge-1.6.4-9.11.1.964-mcp.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
examplemod{1.0} [Example Mod] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
rotten_flesh_mod{1.3} [Rotten Flesh Mod] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
Profiler Position: N/A (disabled)
Vec3 Pool Size: 765 (42840 bytes; 0 MB) allocated, 433 (24248 bytes; 0 MB) used
Player Count: 1 / 8; [EntityPlayerMP['Player343'/282, l='Test World', x=-38.45, y=63.79, z=12.70]]
Type: Integrated Server (map_client.txt)
Is Modded: Definitely; Client brand changed to 'fml,forge'

Note: For some reason this error just comes up at random and crashed the game.

I'm back from being gone for... I think its been about a year. I'm pretty sure nobody remembers me, but hello anybody who does!

Link to comment
Share on other sites

This was my code orignally

 

public class RottenFleshWandZombieTamer extends Item{

public RottenFleshWandZombieTamer(int par1) {
	super(par1);
}
@Override
public boolean itemInteractionForEntity(ItemStack itemStack,EntityPlayer player,EntityLivingBase target) {
	player.sendChatToPlayer(ChatMessageComponent.createFromText("Activated."));

	// Run locally only
	if (target.worldObj.isRemote) return false;

	if (target instanceof EntityZombie)
	{
		player.sendChatToPlayer(ChatMessageComponent.createFromText("EntityZombie, testing task."));
		EntityZombie zombie = (EntityZombie) target;
		EntityAITaskEntry task = (EntityAITaskEntry) zombie.targetTasks.taskEntries.get(1);
	        if (task.action instanceof EntityAINearestAttackableTarget)
			{
				zombie.targetTasks.removeTask(task.action);

			}
		}

	}else{
		return false;
	}

	return false;
}
}

 

I changed it to this:

 

public class RottenFleshWandZombieTamer extends Item{

public RottenFleshWandZombieTamer(int par1) {
	super(par1);
}
@Override
public boolean itemInteractionForEntity(ItemStack itemStack,EntityPlayer player,EntityLivingBase target) {
	player.sendChatToPlayer(ChatMessageComponent.createFromText("Activated."));

	// Run locally only
	if (target.worldObj.isRemote) return false;

	if (target instanceof EntityZombie)
	{
		player.sendChatToPlayer(ChatMessageComponent.createFromText("EntityZombie, testing task."));
		EntityZombie zombie = (EntityZombie) target;
		if (zombie.targetTasks.taskEntries.size()!=0){
			EntityAITaskEntry task = (EntityAITaskEntry) zombie.targetTasks.taskEntries.get(1);
			if (task.action instanceof EntityAINearestAttackableTarget)
			{
				zombie.targetTasks.removeTask(task.action);

			}
		}

	}else{
		return false;
	}

	return false;
}
}

 

It still doesn't work and gives me the same error.

 

Please Help!!!

I'm back from being gone for... I think its been about a year. I'm pretty sure nobody remembers me, but hello anybody who does!

Link to comment
Share on other sites

It's happening on the third click after the tasks targeting players and villagers have both been removed.  At that point, you only have one item left in the targetTasks list, and it's at index 0.  If you change your conditional to:

 

if (zombie.targetTasks.taskEntries.size() > 1){

 

Then it won't try to remove the task at index 1 when it doesn't exist.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Currently, I'm trying to figure out how to read in data from a custom datapack.  The intention is to have the Item have a reference to this pack (IE "modname:material/materialname") as an NBT tag, and i would overwrite some use functions based off of that.  How should I go about reading in the data from the datapack?
    • Game version is 1.16.5, no mods were installed, using Java8 while it happened. And I have multiple different versions of Java including Java8, 11, 12, 13, 14, 15, 16, 18 were installed in my system, but there is only Java8's path inside the environment variable. Could them be one of the reasons? I'm new here so I almost don't know anythings about forge server. Please tell me if you need other files or logs. Following is the output inside CMD after I open the "start.bat": ECHO 处于打开状态。 C:\Users\30121\Desktop\N0u3_OL_server>"C:\Program Files\Java\jre1.8.0_321\bin\java.exe" -Xms2G -Xmx2G -jar forge-1.16.5-36.2.35.jar nogui 2022-05-25 12:42:52,637 main ERROR Error processing element Queue ([Appenders: null]): CLASS_NOT_FOUND 2022-05-25 12:42:52,670 main WARN Advanced terminal features are not available in this environment 2022-05-25 12:42:52,709 main ERROR Unable to locate appender "ServerGuiConsole" for logger config "root" [12:42:52] [main/INFO] [cp.mo.mo.Launcher/MODLAUNCHER]: ModLauncher running: args [--gameDir, ., --launchTarget, fmlserver, --fml.forgeVersion, 36.2.35, --fml.mcpVersion, 20210115.111550, --fml.mcVersion, 1.16.5, --fml.forgeGroup, net.minecraftforge, nogui] [12:42:52] [main/INFO] [cp.mo.mo.Launcher/MODLAUNCHER]: ModLauncher 8.1.3+8.1.3+main-8.1.x.c94d18ec starting: java version 1.8.0_321 by Oracle Corporation [12:42:53] [main/INFO] [ne.mi.fm.lo.FixSSL/CORE]: Added Lets Encrypt root certificates as additional trust Exception in thread "main" [12:42:53] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:-1]: java.lang.NoClassDefFoundError: com/google/common/base/Preconditions [12:42:53] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:-1]:         at org.spongepowered.asm.service.modlauncher.MixinTransformationHandler.offer(MixinTransformationHandler.java:67) [12:42:53] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:-1]:         at org.spongepowered.asm.service.modlauncher.MixinServiceModLauncher.offer(MixinServiceModLauncher.java:162) [12:42:53] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:-1]:         at org.spongepowered.asm.launch.MixinBootstrap.offerInternals(MixinBootstrap.java:227) [12:42:53] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:-1]:         at org.spongepowered.asm.launch.MixinBootstrap.start(MixinBootstrap.java:148) [12:42:53] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:-1]:         at org.spongepowered.asm.launch.MixinTransformationServiceAbstract.initialize(MixinTransformationServiceAbstract.java:88) [12:42:53] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:-1]:         at cpw.mods.modlauncher.TransformationServiceDecorator.onInitialize(TransformationServiceDecorator.java:68) [12:42:53] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:-1]:         at cpw.mods.modlauncher.TransformationServicesHandler.lambda$initialiseTransformationServices$7(TransformationServicesHandler.java:107) [12:42:53] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:-1]:         at java.util.HashMap$Values.forEach(Unknown Source) [12:42:53] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:-1]:         at cpw.mods.modlauncher.TransformationServicesHandler.initialiseTransformationServices(TransformationServicesHandler.java:107) [12:42:53] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:-1]:         at cpw.mods.modlauncher.TransformationServicesHandler.initializeTransformationServices(TransformationServicesHandler.java:59) [12:42:53] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:-1]:         at cpw.mods.modlauncher.Launcher.run(Launcher.java:76) [12:42:53] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:-1]:         at cpw.mods.modlauncher.Launcher.main(Launcher.java:66) [12:42:53] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:-1]:         at net.minecraftforge.server.ServerMain$Runner.runLauncher(ServerMain.java:49) [12:42:53] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:-1]:         at net.minecraftforge.server.ServerMain$Runner.access$100(ServerMain.java:46) [12:42:53] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:-1]:         at net.minecraftforge.server.ServerMain.main(ServerMain.java:43) [12:42:53] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:-1]: Caused by: java.lang.ClassNotFoundException: com.google.common.base.Preconditions [12:42:53] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:-1]:         at java.net.URLClassLoader.findClass(Unknown Source) [12:42:53] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:-1]:         at java.lang.ClassLoader.loadClass(Unknown Source) [12:42:53] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:-1]:         at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) [12:42:53] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:-1]:         at java.lang.ClassLoader.loadClass(Unknown Source) [12:42:53] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:-1]:         ... 15 more C:\Users\30121\Desktop\N0u3_OL_server>pause 请按任意键继续. . .
    • Although I am not exactly sure how a try-finally block would help (i.e. what code I should run even if a runtime exception is thrown), I have made some progress. The custom mob renders, but it does not rotate--even when I apply rotations to it before calling render(). private static boolean renderingCustomEntity = false; private static CustomEntity customEntity; private static void initializeCustomEntityIfNull(LocalPlayer localPlayer) { if (customEntity == null) { customEntity = ModEntities.CUSTOM_ENTITY.get().create(localPlayer.clientLevel); } } @SubscribeEvent public static void replaceMobModel(RenderLivingEvent.Pre<LivingEntity, EntityModel<LivingEntity>> event) { LocalPlayer localPlayer = Minecraft.getInstance().player; if (localPlayer != null && event.getEntity() instanceof Mob mob) { try { if (!renderingCustomEntity) { renderingCustomEntity = true; event.setCanceled(true); initializeCustomEntityIfNull(localPlayer); // I try to apply rotations to the custom entity before it rendered, but it still does not rotate at all. customEntity.setYRot(mob.getYRot()); customEntity.setYHeadRot(mob.getYHeadRot()); customEntity.setPose(mob.getPose()); // For some reason, the custom mob did not render when I called EntityRenderDispatcher#render. // So I called render() from EntityRenderDispatcher#getRenderer instead. Minecraft.getInstance().getEntityRenderDispatcher().getRenderer(customEntity).render( customEntity, customEntity.getYRot(), event.getPartialTick(), event.getPoseStack(), event.getMultiBufferSource(), event.getPackedLight() ); } } finally { renderingCustomEntity = false; } } } What would I be missing? Thank you for the help.
    • https://ileanafilio.com/cong-ty-co-phan-dau-tu-lien-doanh-viet-anh/ https://ileanafilio.com/tu-dong-viet-hoa-dau-dong-trong-excel-2007/ https://ileanafilio.com/tai-bai-hat-yeu-lai-tu-dau/ https://ileanafilio.com/phan-ky-dau-tu-du-an/ https://ileanafilio.com/su-lua-chon-so-phan-tap-62/ https://ileanafilio.com/cong-ty-co-phan-thuong-mai-dau-tu-va-phat-trien-cong-nghe-sctt/ https://ileanafilio.com/karate-co-nguon-goc-tu-dau/ https://ileanafilio.com/tap-doan-co-khi-xay-dung-thuong-mai-dai-dung/ https://ileanafilio.com/cach-tinh-dau-tu-tai-san-co-dinh/
    • Yes, I used it. And when I deleted the unnecessary parts and ran it again, I got an error. Now when I repaired that error and ran it, it worked fine. Thanks!
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.