[Solved] How to make mining a block turn pigmen aggressive towards player

Started by Sajevius on

Topic category: Help with Minecraft modding (Java Edition)

Joined Aug 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
[Solved] How to make mining a block turn pigmen aggressive towards player
Fri, 09/25/2020 - 11:05 (edited)

I wanna know how to make it so that when a player mines a certain block (e.g. an ore in the Nether), nearby zombie pigmen will get angry at said player.

thanks in advance!

( P.S. I honestly don't know if this is a duplicate forum topic, so please bear with me, for I could not find this topic anywhere else in this site as far as I searched :P )

Edited by Sajevius on Fri, 09/25/2020 - 11:05
Joined Nov 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
you would have to get the…
Sun, 09/20/2020 - 04:50

you would have to get the nearest pigzombie within range, and manually code setRevengeTarget to the player entity

Joined Aug 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
is there anywhere i can find…
Sun, 09/20/2020 - 04:55

is there anywhere i can find a code template? i would appreciate an in-depth explanation if possible as well... so that i don't mess up

Joined Nov 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
which version of mcreator…
Sun, 09/20/2020 - 05:05

which version of mcreator and for which version of minecraft are you making the mod for?

Joined Aug 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
MCreator 2020.4 Forge 1.14.4…
Sun, 09/20/2020 - 05:11

MCreator 2020.4

Forge 1.14.4

 

Joined Aug 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
so... any luck?
Sun, 09/20/2020 - 08:24

so...

any luck?

Joined Nov 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
i'm still using 2020.3 for 1…
Sun, 09/20/2020 - 15:32

i'm still using 2020.3 for 1.12.2, so i don't know if 2020.4 has a new code block that gets the nearest entity or not, so i can only do it in code.

basically you do something like this:

EntityPigZombie entityFound = (EntityPigZombie)world.findNearestEntityWithinAABB(EntityPigZombie.class, entity.getEntityBoundingBox().grow(10), entity);
if (entityFound != null) {
    entityFound.setRevengeTarget(entity);
}

the 10 in .grow(10) is the range for finding pig zombies.

Joined Aug 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
i think there's already a…
Sun, 09/20/2020 - 22:55

i think there's already a code block that gets the nearest entity of a certain (sub)type within a certain range, but as for the one making pigmen aggressive (target a certain entity e.g. player), no such procedure exists yet and isn't part of the block creation wizard settings :/

but i'll try it on 1.14 tho, see what i can do, and if not, tinker with the code a bit, see if some classes/methods/parameters changed even a bit, although i'm an amateur when it comes to Minecraft's source code...

Joined Aug 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
so, if I'm right, would I…
Sun, 09/20/2020 - 22:58

so, if I'm right, would I also have to import net.minecraft.entity.hostile.ZombiePigmanEntity?

Joined Nov 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
if you can use existing code…
Mon, 09/21/2020 - 01:31

if you can use existing code blocks to get the nearest entity in the procedure, then i would just add code snippet blocks in that procedure to set the revenge target, that way you won't need to import anything (mcreator does it automatically), and you won't need to edit source code.

Joined Aug 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
ok, I'll try that. thx
Mon, 09/21/2020 - 02:03

ok, I'll try that. thx

Joined Aug 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
i just keep getting a build…
Thu, 09/24/2020 - 12:33

i just keep getting a build error that says:

C:\Users\USER\MCreatorWorkspaces\deeper_inferno\src\main\java\com\sajevius\infernal_depths\procedures\VulkatiteOreBlockDestroyedByPlayerProcedure.java:44: error: cannot find symbol entity.getEntityBoundingBox().grow(10), entity);
^
symbol: variable entity
location: class VulkatiteOreBlockDestroyedByPlayerProcedure
C:\Users\USER\MCreatorWorkspaces\deeper_inferno\src\main\java\com\sajevius\infernal_depths\procedures\VulkatiteOreBlockDestroyedByPlayerProcedure.java:44: error: cannot find symbol entity.getEntityBoundingBox().grow(10), entity);
^
symbol: variable entity
location: class VulkatiteOreBlockDestroyedByPlayerProcedure
C:\Users\USER\MCreatorWorkspaces\deeper_inferno\src\main\java\com\sajevius\infernal_depths\procedures\VulkatiteOreBlockDestroyedByPlayerProcedure.java:46: error: cannot find symbol entityFound.setRevengeTarget(entity)

 

any way to fix it and information about the "entity" variable? (is the "entity" variable referring to the player? how should i declare it in code?)

Joined Nov 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
how did you put the custom…
Thu, 09/24/2020 - 21:13

how did you put the custom code in, using code snippet blocks or locking the element and manually editing code? be helpful if you posted the code blocks or source code.

for 1.14.4 it should be getBoundingBox() instead of getEntityBoundingBox(). as for the other error, i need to know which symbol was not found, "entityFound" or "setRevengeTarget".

Joined Aug 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
i used code snippets on my…
Fri, 09/25/2020 - 05:24

i used code snippets on my 1st attempt, and when i found out it didn't work despite the ZombiePigmanEntity class being already imported, I proceeded to lock the code on 2nd attempt. ("EntityPigZombie" has been changed to "ZombiePigmanEntity") The only symbol that can't be found according to the error in console logs is "entity", and it looks like "entity" refers to the player, right? anyway, here's the src code:

package com.sajevius.infernal_depths.procedures;

import net.minecraft.world.World;
import net.minecraft.world.IWorld;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.entity.monster.ZombiePigmanEntity;

import java.util.Map;
import java.util.Comparator;

import com.sajevius.infernal_depths.InfernalDepthsModElements;

@InfernalDepthsModElements.ModElement.Tag
public class VulkatiteOreBlockDestroyedByPlayerProcedure extends InfernalDepthsModElements.ModElement {
	public VulkatiteOreBlockDestroyedByPlayerProcedure(InfernalDepthsModElements instance) {
		super(instance, 159);
	}

	public static void executeProcedure(Map<String, Object> dependencies) {
		if (dependencies.get("x") == null) {
			System.err.println("Failed to load dependency x for procedure VulkatiteOreBlockDestroyedByPlayer!");
			return;
		}
		if (dependencies.get("y") == null) {
			System.err.println("Failed to load dependency y for procedure VulkatiteOreBlockDestroyedByPlayer!");
			return;
		}
		if (dependencies.get("z") == null) {
			System.err.println("Failed to load dependency z for procedure VulkatiteOreBlockDestroyedByPlayer!");
			return;
		}
		if (dependencies.get("world") == null) {
			System.err.println("Failed to load dependency world for procedure VulkatiteOreBlockDestroyedByPlayer!");
			return;
		}
		double x = dependencies.get("x") instanceof Integer ? (int) dependencies.get("x") : (double) dependencies.get("x");
		double y = dependencies.get("y") instanceof Integer ? (int) dependencies.get("y") : (double) dependencies.get("y");
		double z = dependencies.get("z") instanceof Integer ? (int) dependencies.get("z") : (double) dependencies.get("z");
		IWorld world = (IWorld) dependencies.get("world");
		
		ZombiePigmanEntity entityFound = (ZombiePigmanEntity)world.findNearestEntityWithinAABB(ZombiePigmanEntity.class, entity.getBoundingBox().grow(10), entity);
		if (entityFound != null) {
    		entityFound.setRevengeTarget(entity);
		}
	}
}

i'm quite curious about how to use the "entity" symbol here. should I add an entity dependency as well, to make it work and make pigmen target the player?

Joined Aug 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
also it seems that …
Fri, 09/25/2020 - 05:29

also it seems that "findNearestEntityWithinAABB" has now been renamed to "getClosestEntityWithinAABB"...