Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

I'm trying to make a potion which when applied to a zombie will cause it to run away from the player till the effect is over, kind of like how skeletons run away from wolves. But I have currently no idea how do make the zombie do that. Is there a way to do that?

Edited by PadFoot2008

  • Author

Thanks for the help. But I tried doing that but it isn't work. In fact, for some reason, none of the event classes or mixins added by me seem to work. Could there be a specific reason for that? Also adding breakpoints doesn't work too. It did use to work, but it suddenly stopped working. I've also been getting java.io.IOException each time I run the mod. 

Just for extra info, I'm using IntelliJ IDE.

  • Author

Also what I'm trying to do is that holding this particular staff I made would cause Zombies to stay away from the player an eight block radius and any Zombies that're coming towards the player to attack them will quickly go out the radius as soon as the player brings the staff into their main hand. Could you also suggest a way to make that happen?

yeah but it will a little complex 

create an item and in the 

// ########## ########## ########## ##########

@Override

public void inventoryTick(ItemStack helditem, Level warudo, Entity entity, int slot, boolean p_41408_) {

System.out.println("inventoryTick [" + slot + "], " + ((warudo.isClientSide)? "Local World":"Server World")  );

check if its in player hand 

check surrounding area for zombie 

for any zombie finded check distance to player 

any zombie closer than 5 blocks knockback in the oposite direction of the player 

}

  • Author

Thanks for replying. It does work except I can't seem to knock them back away from the player, instead they get pulled towards the player and stay at the player's location and when I switch to another item they get thrown away. How do I knock them back away from the player?

Edited by PadFoot2008

Spoiler

				
			package mercbow.item.rod;				
			import java.util.ArrayList;				
			import mercbow.item.ItemInit;
		import mercbow.util.Postate;
		import mercbow.util.Target;
		import net.minecraft.core.BlockPos;
		import net.minecraft.core.particles.ParticleTypes;
		import net.minecraft.sounds.SoundEvents;
		import net.minecraft.world.InteractionHand;
		import net.minecraft.world.InteractionResultHolder;
		import net.minecraft.world.entity.LivingEntity;
		import net.minecraft.world.entity.ai.attributes.Attributes;
		import net.minecraft.world.entity.item.ItemEntity;
		import net.minecraft.world.entity.player.Player;
		import net.minecraft.world.item.Item;
		import net.minecraft.world.item.ItemStack;
		import net.minecraft.world.level.Level;
		import net.minecraft.world.level.block.AbstractCauldronBlock;
		import net.minecraft.world.level.block.Blocks;
		import net.minecraft.world.level.block.state.properties.BlockStateProperties;
		import net.minecraft.world.level.block.state.properties.DirectionProperty;
		import net.minecraft.world.level.material.Material;
		import net.minecraft.world.phys.AABB;
		import net.minecraft.world.phys.Vec3;				
			public class knockback_rod extends Item {				
			    public static final DirectionProperty FACING = BlockStateProperties.FACING;				
			    // ########## ########## ########## ##########
		    public knockback_rod(Properties propiedad) {
		        super(propiedad);
		    }				
			    // ########## ########## ########## ##########
		    @Override
		    public InteractionResultHolder<ItemStack> use(Level warudo, Player pe, InteractionHand hand) {
		        // System.out.println("\n\n\n\n USE ");				
			        ArrayList<LivingEntity> lista = there_is_LivingEntity_around(warudo, pe.blockPosition());
		        
		        
		        // knockbakear
		        float knockback = 1.0F;				
			        double d0 = Math.max(0.0D, 1.0D);
		        Vec3 vec3 = pe.getDeltaMovement().multiply(1.0D, 0.0D, 1.0D).normalize().scale((double) knockback * 0.6D * d0);				
			        for (LivingEntity coso : lista) {				
			            System.out.println("coso=>" + coso.getName().getString().toString());				
			                coso.push(0.5D, 0.5D, 0.5D); //math need here player pitch/yaw to x y z				
			        }				
			        return InteractionResultHolder.pass(pe.getItemInHand(hand));
		    }				
			    // ########## ########## ########## ##########
		    // @Override
		    public static ArrayList<LivingEntity> there_is_LivingEntity_around(Level warudo, BlockPos pos) {
		        AABB bb = new AABB(pos).inflate(10.0F);				
			        ArrayList<LivingEntity> lista = new ArrayList<LivingEntity>();				
			        for (LivingEntity entity1 : warudo.getEntitiesOfClass(LivingEntity.class, bb)) {
		            if(!(entity1 instanceof Player)) {
		            
		            lista.add(entity1);
		            }
		        }				
			        return lista;
		    }				
			// ########## ########## ########## ##########
		}
		 				
			

knockback-edit.gif

 

this part i also need this for another idea i have

in this point is need to do some math is need to convert the rotation of the player to x/y/z values probably a math.sen math.cos of the player y rot  and multiply it for the streng of the push  

                coso.push(x * str, y * str, z * str); 

 

On 3/15/2023 at 4:23 AM, PadFoot2008 said:

In fact, for some reason, none of the event classes or mixins added by me seem to work. Could there be a specific reason for that?

Are you sure that you have the mixins defined in a mixins file? Are you sure that your build.gradle recognizes the file?

I'm not good at modding, but at least I can read a crash report (well enough). That's something, right?

do not use mixins for this. maybe you'll need access transformers for some fields (where the zombie is trying to walk to) but you do not need mizins.

respond to "entity joins world". add your ai goal to zombies list of goals.

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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.