Jump to content

Further Entity Help


Lua

Recommended Posts

Hi,

 

So I'm here again, requesting further help on this entity, although the past two times I managed to work the problem out myself. But this, this one is just weird. I'm not sure if its me, or mc code. Anway, this mp4 describes the problem. http://gyazo.com/7077bbd220c167afdff66df647b84659 This only happens if you stand in a specific position, and it can sometimes happen when it trys to jump and hit you. As you can see, the mob is clearly hitting the player but the player isn't taking damage. I must stress, this is only if you stand like this, most of the time you wouldn't notice it in combat. Could this minecrafts bad attacking AI's fault? Anyway, just to be certain, my codes below for you to check over.

 

package mcub.entities;

import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.boss.IBossDisplayData;
import net.minecraft.entity.monster.EntitySpider;
import net.minecraft.util.DamageSource;
import net.minecraft.world.World;

public class OS_EntityQueenSpider extends EntitySpider implements IBossDisplayData
{

private int healAtDifferentDifficulties;

public OS_EntityQueenSpider(World world)
{
	super(world);
	this.setSize(2.8F, 1.5F);
	this.isImmuneToFire = true;
	this.experienceValue = 100;
}

@Override
protected void applyEntityAttributes()
{
	super.applyEntityAttributes();
	this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setAttribute(100.0D);
	this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setAttribute(1.99900011920929D);
	this.getEntityAttribute(SharedMonsterAttributes.attackDamage).setAttribute(9.0D);
	this.getEntityAttribute(SharedMonsterAttributes.followRange).setAttribute(40.0D);
	this.getEntityAttribute(SharedMonsterAttributes.knockbackResistance).setAttribute(1.0);
}

private void playHealthEffect()
{

	for(int i = 0; i < 4; ++i)
	{
		double d0 = this.rand.nextGaussian() * 0.02D;
		double d1 = this.rand.nextGaussian() * 0.02D;
		double d2 = this.rand.nextGaussian() * 0.02D;
		this.worldObj.spawnParticle("heart", this.posX + (double) (this.rand.nextFloat() * this.width * 2.0F) - (double) this.width, this.posY + 0.5D + (double) (this.rand.nextFloat() * this.height), this.posZ + (double) (this.rand.nextFloat() * this.width * 2.0F) - (double) this.width, d0, d1,
				d2);
	}
}

//Removed the check for daylight. 
@Override
protected Entity findPlayerToAttack()
{
	return this.worldObj.getClosestVulnerablePlayerToEntity(this, 40);
}

@Override
public boolean attackEntityAsMob(Entity ent)
{
	if(super.attackEntityAsMob(ent))
	{
		if(ent instanceof EntityLivingBase)
		{
			//TODO add potion
			super.attackEntityAsMob(ent);
		}
		return true;
	}
	else
	{
		return false;
	}
}

@Override
public void onLivingUpdate()
{
	switch(Minecraft.getMinecraft().gameSettings.difficulty)
	{
	case 1:
		healAtDifferentDifficulties = 20;
		break;
	case 2:
		healAtDifferentDifficulties = 40;
		break;
	case 3:
		healAtDifferentDifficulties = 60;
		break;
	}
	if(this.getHealth() < healAtDifferentDifficulties && this.ticksExisted % 20 == 0)
	{
		this.heal(2.0F);
		playHealthEffect();
	}
	super.onLivingUpdate();
}

@Override
public void onDeath(DamageSource damageSource)
{
	OS_EntityEnderSpider enderSpider = new OS_EntityEnderSpider(this.worldObj);
	enderSpider.setPosition(this.posX, this.posY, this.posZ);
	this.worldObj.spawnEntityInWorld(enderSpider);
}

}

 

Results from my debugging:

- It's not because I'm extending EntitySpider

- It's not because i've up-scaled the mob.

- It's not because of the onLivingUpdate method somehow causing it to bug out.

 

 

The chance of it being a hitbox problem crossed my mind too, so heres a picture of the mobs hitbox.  http://gyazo.com/37d0d67b0fc30eea7a560cedde63f1c3

Link to comment
Share on other sites

Hi

 

What I mean is -  you put a breakpoint in (say) attackEntityAsMob, and then when your player is attacked the code stops executing and you step through your code one line at a time.  At some point it will do something different to what you expect (i.e. won't cause damage) and give you a clue what's wrong.

 

Have you used breakpoints and watches like this before?  They are extremely useful, not just for crashes, for example see here

http://www.vogella.com/articles/EclipseDebugging/article.html

 

Alternatively you can add logging statements to key points in your code, for example you might use:

 

	@Override
public boolean attackEntityAsMob(Entity ent)
{
System.out.println("attackEntityAsMob entered");
	if(super.attackEntityAsMob(ent))
	{
System.out.println("attackEntityAsMob -A ");

		if(ent instanceof EntityLivingBase)
		{
System.out.println("ent instanceof EntityLivingBase ");
			//TODO add potion
			super.attackEntityAsMob(ent);
		}
System.out.println("attackEntityAsMob returning true ");
		return true;
	}
	else
	{
System.out.println("attackEntityAsMob returning false ");
		return false;
	}
}

That's a bit overdone but you get the idea.  Any time you're not sure which parts of your code are being executed, or you want to know what the value of a variable is at a certain point, you add a logging statement.  If you've chosen well, the logging statements will either confirm that a part of your code is working correctly or will show that it's not doing what you assumed.  Once you narrow it down a bit, you add some more statements, recompile and run again, and keep doing that until you have tracked down the problem. You can add logging statements to the vanilla code too, just remember to remove them again later.

 

-TGG

 

 

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

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • how to make animated doors?, maybe geckolib, but i don't know how to code it?
    • For crash 1, set max-tick-time to -1 in your server.properties Crash 2 shows a conflict or incompatibility between LuckPerms and the mod boh-0.0.6.1-forge-1.20.1_2.jar
    • Add the crash-report or latest.log (logs-folder) with sites like https://mclo.gs/ and paste the link to it here  
    • so my minecraft crashes when opening my world, i played without any troubles for about 5 days and today it started tweaking.. pls help me
    • Hi guys! I am having some issues with the server crashing over and over and I was hoping to get some guidance.  Thanks in advance! Crash 1: java.lang.Error: ServerHangWatchdog detected that a single server tick took 60.00 seconds (should be max 0.05)     at net.minecraft.server.dedicated.ServerWatchdog.run(ServerWatchdog.java:43) ~[server-1.20.1-20230612.114412-srg.jar%23217!/:?] {re:classloading}     at java.lang.Thread.run(Thread.java:840) ~[?:?] { Crash 2: java.lang.IllegalStateException: Capability missing for eeb7f026-34b4-42f5-9164-e7736461df83     at me.lucko.luckperms.forge.capabilities.UserCapabilityImpl.lambda$get$0(UserCapabilityImpl.java:66) ~[?:?] {re:classloading,re:classloading,re:classloading}     at net.minecraftforge.common.util.LazyOptional.orElseThrow(LazyOptional.java:261) ~[forge-1.20.1-47.3.10-universal.jar%23222!/:?] {re:mixin,re:classloading}     at me.lucko.luckperms.forge.capabilities.UserCapabilityImpl.get(UserCapabilityImpl.java:66) ~[?:?] {re:classloading,re:classloading,re:classloading}     at me.lucko.luckperms.forge.util.BrigadierInjector$InjectedPermissionRequirement.test(BrigadierInjector.java:143) ~[?:?] {}     at me.lucko.luckperms.forge.util.BrigadierInjector$InjectedPermissionRequirement.test(BrigadierInjector.java:129) ~[?:?] {}     at com.mojang.brigadier.tree.CommandNode.canUse(CommandNode.java:65) ~[brigadier-1.1.8.jar%2376!/:?] {}     at com.mojang.brigadier.CommandDispatcher.parseNodes(CommandDispatcher.java:359) ~[brigadier-1.1.8.jar%2376!/:?] {}     at com.mojang.brigadier.CommandDispatcher.parse(CommandDispatcher.java:349) ~[brigadier-1.1.8.jar%2376!/:?] {}     at com.mojang.brigadier.CommandDispatcher.parse(CommandDispatcher.java:317) ~[brigadier-1.1.8.jar%2376!/:?] {}     at net.minecraft.commands.Commands.m_230957_(Commands.java:237) ~[server-1.20.1-20230612.114412-srg.jar%23217!/:?] {re:classloading}     at net.mcreator.boh.procedures.TeleportbenProcedure.lambda$execute$2(TeleportbenProcedure.java:65) ~[boh-0.0.6.1-forge-1.20.1_2.jar%23165!/:?] {re:classloading}     at net.mcreator.boh.BohMod.lambda$tick$2(BohMod.java:96) ~[boh-0.0.6.1-forge-1.20.1_2.jar%23165!/:?] {re:classloading}     at java.util.ArrayList.forEach(ArrayList.java:1511) ~[?:?] {re:mixin}     at net.mcreator.boh.BohMod.tick(BohMod.java:96) ~[boh-0.0.6.1-forge-1.20.1_2.jar%23165!/:?] {re:classloading}     at net.mcreator.boh.__BohMod_tick_ServerTickEvent.invoke(.dynamic) ~[boh-0.0.6.1-forge-1.20.1_2.jar%23165!/:?] {re:classloading,pl:eventbus:B}     at net.minecraftforge.eventbus.ASMEventHandler.invoke(ASMEventHandler.java:73) ~[eventbus-6.0.5.jar%2352!/:?] {}     at net.minecraftforge.eventbus.EventBus.post(EventBus.java:315) ~[eventbus-6.0.5.jar%2352!/:?] {}     at net.minecraftforge.eventbus.EventBus.post(EventBus.java:296) ~[eventbus-6.0.5.jar%2352!/:?] {}     at net.minecraftforge.event.ForgeEventFactory.onPostServerTick(ForgeEventFactory.java:950) ~[forge-1.20.1-47.3.10-universal.jar%23222!/:?] {re:classloading}     at net.minecraft.server.MinecraftServer.m_5705_(MinecraftServer.java:835) ~[server-1.20.1-20230612.114412-srg.jar%23217!/:?] {re:mixin,pl:accesstransformer:B,xf:fml:xaerominimap:xaero_minecraftserver,re:classloading,pl:accesstransformer:B,xf:fml:xaerominimap:xaero_minecraftserver,pl:mixin:A}     at net.minecraft.server.MinecraftServer.m_130011_(MinecraftServer.java:661) ~[server-1.20.1-20230612.114412-srg.jar%23217!/:?] {re:mixin,pl:accesstransformer:B,xf:fml:xaerominimap:xaero_minecraftserver,re:classloading,pl:accesstransformer:B,xf:fml:xaerominimap:xaero_minecraftserver,pl:mixin:A}     at net.minecraft.server.MinecraftServer.m_206580_(MinecraftServer.java:251) ~[server-1.20.1-20230612.114412-srg.jar%23217!/:?] {re:mixin,pl:accesstransformer:B,xf:fml:xaerominimap:xaero_minecraftserver,re:classloading,pl:accesstransformer:B,xf:fml:xaerominimap:xaero_minecraftserver,pl:mixin:A}     at java.lang.Thread.run(Thread.java:840) ~[?:?] {}
  • Topics

×
×
  • Create New...

Important Information

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