Jump to content

Recommended Posts

Posted

Whenever I spawn my entity in water after a few seconds it will just sink to the bottom of the water and stay there until it drowns just bobbing along as if it were above the water. I don't really know why as I copied the AI straight from the wolf class and the wolves don't sink like that. Could it be to do with the fact the size of the entity changes as it grows when it levels up, I really don't know.

Posted

This is all of it, however a lot is probably not relevant.

 

package com.blocklings.entity;

import java.util.List;
import java.util.Random;

import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityAgeable;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.EntityAIAttackOnCollide;
import net.minecraft.entity.ai.EntityAIFollowOwner;
import net.minecraft.entity.ai.EntityAIHurtByTarget;
import net.minecraft.entity.ai.EntityAILookIdle;
import net.minecraft.entity.ai.EntityAIOwnerHurtByTarget;
import net.minecraft.entity.ai.EntityAIOwnerHurtTarget;
import net.minecraft.entity.ai.EntityAISwimming;
import net.minecraft.entity.ai.EntityAIWander;
import net.minecraft.entity.ai.EntityAIWatchClosest;
import net.minecraft.entity.passive.EntityTameable;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.inventory.IInvBasic;
import net.minecraft.inventory.InventoryBasic;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.pathfinding.PathEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.DamageSource;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;

import com.blocklings.gui.InventoryBlockling;
import com.blocklings.main.Blocklings;
import com.blocklings.network.CreatePacketServerSide;

public class EntityBlockling extends EntityTameable implements IInvBasic{

Random random = new Random();

public int currentXP = 0;
public int currentLevel = 1;

public int requiredXP = 200;

public double maxHealth = 2.0F;
public double attackDamage = 1.0D;
public double moveSpeed = 0.20D;

public float moveTimer = 0.0F;
public boolean moveTimerSwitch = true;

public float attackTimer = 0.0F;
public boolean attackTimerSwitch = true;
public boolean isAttacking = false;

public boolean hasSword = false;

public float width = 0.5F;
public float height = 0.55F;

public InventoryBlockling gear;

public EntityBlockling(World world) {

	super(world);

	this.setSize(this.width, this.height);

	this.getNavigator().setAvoidsWater(true);
	this.getNavigator().setCanSwim(true);

	this.tasks.addTask(1, new EntityAISwimming(this));
	this.tasks.addTask(2, this.aiSit);
	this.tasks.addTask(3, new EntityAIAttackOnCollide(this, 1.0D, false));
	this.tasks.addTask(4, new EntityAIFollowOwner(this, 1.0D, 6.0F, 3.0F));
	this.tasks.addTask(5, new EntityAIWander(this, 1.0D));
	this.tasks.addTask(6, new EntityAIWatchClosest(this, EntityPlayer.class, 8.0F));
	this.tasks.addTask(7, new EntityAILookIdle(this));

	this.targetTasks.addTask(1, new EntityAIHurtByTarget(this, true));
	this.targetTasks.addTask(2, new EntityAIOwnerHurtByTarget(this));
	this.targetTasks.addTask(3, new EntityAIOwnerHurtTarget(this));

	this.setTamed(false);

	this.currentLevel = random.nextInt(10) + 1;

	this.setupGear();

}

@Override
protected void applyEntityAttributes() {

	super.applyEntityAttributes();

	this.maxHealth = 20.0D;
	this.attackDamage = 1.0D;
	this.moveSpeed = 0.20D;

	this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(this.maxHealth);
	this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(this.moveSpeed);
	this.getAttributeMap().registerAttribute(SharedMonsterAttributes.attackDamage);
	this.getEntityAttribute(SharedMonsterAttributes.attackDamage).setBaseValue(this.attackDamage);

}

@Override
public void onLivingUpdate() {

	super.onLivingUpdate();

	if (this.attackTimer > 0.0F) {

		this.attackTimer -= 1.0F;

	}

	this.hasSword = true;

	this.setEntitySize();

	this.setBlocklingLevel();

	this.calculateRequiredXP();

	this.setMaxHealth();
	this.setAttackDamage();
	this.setMoveSpeed();

	if(!this.worldObj.isRemote) {

		CreatePacketServerSide.sendS2CEntitySync(this);

	}

}

@Override
public boolean attackEntityAsMob(Entity entity) {

	this.setXP(((int) this.attackDamage + random.nextInt(5) + 1) + this.currentXP);

	if (this.attackTimer <= 1.0F) {

		this.attackTimer = (float) random.nextInt(4) + 8;

	}

	return entity.attackEntityFrom(DamageSource.causeMobDamage(this), (float) getEntityAttribute(SharedMonsterAttributes.attackDamage).getAttributeValue());

}

@Override
public boolean interact(EntityPlayer entityPlayer) {

	ItemStack itemstack = entityPlayer.inventory.getCurrentItem();
	Item yellowFlower = Item.getItemFromBlock(Blocks.yellow_flower);
	Item redFlower = Item.getItemFromBlock(Blocks.red_flower);
	Item tallFlower = Item.getItemFromBlock(Blocks.double_plant);

	if(itemstack != null && (itemstack.getItem() == yellowFlower || itemstack.getItem() == redFlower || itemstack.getItem() == tallFlower) && !this.isTamed() && !this.worldObj.isRemote) {

		if(random.nextInt(3) == 0) {

			this.setTamed(true);
			this.setPathToEntity((PathEntity) null);
			this.setAttackTarget((EntityLivingBase) null);
			this.func_152115_b(entityPlayer.getUniqueID().toString());
			this.playTameEffect(true);
			this.worldObj.setEntityState(this, (byte) 7);

		} else {

			this.playTameEffect(false);
			this.worldObj.setEntityState(this, (byte) 6);

		}

	}

	if(this.func_152114_e(entityPlayer) && entityPlayer.isSneaking() && !this.worldObj.isRemote) {

		if(this.getCustomNameTag().length() > 0) {

			entityPlayer.openGui(Blocklings.modInstance, 0, this.worldObj, this.getEntityId(), 0, 0);

		} else {

			entityPlayer.openGui(Blocklings.modInstance, 0, this.worldObj, this.getEntityId(), 0, 0);

		}

	}

	if (this.func_152114_e(entityPlayer) && !entityPlayer.isSneaking() && !this.worldObj.isRemote) {

		this.aiSit.setSitting(!this.isSitting());

	}

	return super.interact(entityPlayer);

}

/*@Override
protected float applyArmorCalculations(DamageSource p_70655_1_, float p_70655_2_) {

	return 1.0F;

}*/

@Override
public boolean isAIEnabled() {

	return true;

}

@Override
public boolean getCanSpawnHere() {

	int i = MathHelper.floor_double(this.posX);
	int j = MathHelper.floor_double(this.boundingBox.minY);
	int k = MathHelper.floor_double(this.posZ);

	int l = this.worldObj.getFullBlockLightValue(i, j, k);
	boolean s = this.worldObj.canBlockSeeTheSky(i, j, k);
	boolean b = this.worldObj.getBlock(i, j - 1, k) == Blocks.grass;

	List list = worldObj.getEntitiesWithinAABB(Entity.class, AxisAlignedBB.getBoundingBox(posX, posY, posZ, posX + 1, posY + 1, posZ + 1).expand(16D, 512D, 16D));

	return list.size() < 5 && l > 8 && b && s;

}

@Override
public void onDeath(DamageSource ds) {
	super.onDeath(ds);

	if (gear != null && !this.worldObj.isRemote) {

		for (int i = 0; i < gear.getSizeInventory(); ++i) {

			ItemStack itemstack = gear.getStackInSlot(i);

			if (itemstack != null) {

				this.entityDropItem(itemstack, 0.0F);

			}

		}

	}

}

@Override
public void onInventoryChanged(InventoryBasic var1) {

}

@Override
public void writeEntityToNBT(NBTTagCompound compound) {

	super.writeEntityToNBT(compound);

	compound.setInteger("currentXP", this.currentXP);
	compound.setInteger("currentLevel", this.currentLevel);

	compound.setInteger("requiredXP", this.requiredXP);

	compound.setDouble("maxHealth", this.maxHealth);

	compound.setFloat("moveTimer", this.moveTimer);

	NBTTagList nbttaglist = new NBTTagList();

	for (int i = 0; i < this.gear.getSizeInventory(); ++i) {

		ItemStack itemstack = this.gear.getStackInSlot(i);

		if (itemstack != null) {

			NBTTagCompound nbttagcompound1 = new NBTTagCompound();
			nbttagcompound1.setByte("Slot", (byte) i);
			itemstack.writeToNBT(nbttagcompound1);
			nbttaglist.appendTag(nbttagcompound1);

		}

		compound.setTag("Items", nbttaglist);

	}

}

@Override
public void readEntityFromNBT(NBTTagCompound compound) {

	super.readEntityFromNBT(compound);

	this.currentXP = compound.getInteger("currentXP");
	this.currentLevel = compound.getInteger("currentLevel");

	this.requiredXP = compound.getInteger("requiredXP");

	this.maxHealth = compound.getDouble("maxHealth");

	this.moveTimer = compound.getFloat("moveTimer");

	NBTTagList nbttaglist = compound.getTagList("Items", 10);

	this.setupGear();

	for (int i = 0; i < nbttaglist.tagCount(); ++i) {

		NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i);
		int j = nbttagcompound1.getByte("Slot") & 255;

		if (j >= 0 && j < this.gear.getSizeInventory()) {

			this.gear.setInventorySlotContents(j, ItemStack.loadItemStackFromNBT(nbttagcompound1));

		}

	}

}


@Override
public EntityAgeable createChild(EntityAgeable entityAgeable) {

	return null;

}

public void calculateRequiredXP() {

	this.requiredXP = (50 * (this.currentLevel * this.currentLevel) + (150 * this.currentLevel));

}

public void setBlocklingLevel() {

	if (this.currentXP > this.requiredXP) {

		this.currentLevel = this.currentLevel + 1;

		this.calculateRequiredXP();

		this.currentXP = 0;

		if(!this.worldObj.isRemote) {

			CreatePacketServerSide.sendS2CEntitySync(this);

		}

	}

}

public void setEntitySize() {

	if(this.currentLevel <= 10) {

		this.width = (float) (this.currentLevel * 0.14F) + 0.35F;
		this.height = (float) (this.currentLevel * 0.14F) + 0.4F;

	} else if(this.currentLevel > 10) {

		this.width = (float) (10 * 0.14F) + 0.35F;
		this.height = (float) (10 * 0.14F) + 0.4F;

	}

	setSize(this.width, this.height);

}

public void setMaxHealth() {

	if(this.currentLevel <= 10) {

		this.maxHealth = this.currentLevel * 2;

	} else if(this.currentLevel > 10) {

		this.maxHealth = 20;

	}

	this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(this.maxHealth);

	if(this.getHealth() > this.maxHealth) {

		this.heal(0.0F);

	}

}

public void setAttackDamage() {

	if(this.currentLevel <= 10) {

		this.attackDamage = this.currentLevel;

	} else if(this.currentLevel > 10) {

		this.attackDamage = 10;

	}

	this.getEntityAttribute(SharedMonsterAttributes.attackDamage).setBaseValue(this.attackDamage);

}

public void setMoveSpeed() {

	if(this.currentLevel <= 10) {

		this.moveSpeed = 0.20D + ((double) this.currentLevel / 100);

	} else if(this.currentLevel > 10) {

		this.moveSpeed = 0.30D;

	}

	this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(this.moveSpeed);

}

private void setupGear() {

	InventoryBlockling gear1 = this.gear;

	this.gear = new InventoryBlockling("Inventory", howManySlots());

	this.gear.func_110133_a(this.getCommandSenderName());

	if (gear1 != null) {

		gear1.func_110132_b(this);

		int i = Math.min(gear1.getSizeInventory(), this.gear.getSizeInventory());

		for (int j = 0; j < i; ++j) {

			ItemStack itemstack = gear1.getStackInSlot(j);

			if (itemstack != null) {

				this.gear.setInventorySlotContents(j, itemstack.copy());

			}

		}

		gear1 = null;
	}

	this.gear.func_110134_a(this);

}

public int howManySlots() {

	return 22;

}

public int getLevel() {

	return this.currentLevel;

}

public void setLevel(int currentLevel) {

	this.currentLevel = currentLevel;

}

public int getXP() {

	return this.currentXP;

}

public void setXP(int currentXP) {

	this.currentXP = currentXP;

}

public double getMaximumHealth() {

	return this.maxHealth;

}

public void setMaximumHealth(double maxHealth) {

	this.maxHealth = maxHealth;

}

public double getAttackDamage() {

	return this.attackDamage;

}

public void setAttackDamage(double attackDamage) {

	this.attackDamage = attackDamage;

}

public int getRequiredXP() {

	return this.requiredXP;

}

public void setRequiredXP(int requiredXP) {

	this.requiredXP = requiredXP;

}

public float getAttackTimer() {

	return this.attackTimer;

}

public void setAttackTimer(float attackTimer) {

	this.attackTimer = attackTimer;

}

public boolean getHasSword() {

	return this.hasSword;

}

public void setHasSword(boolean hasSword) {

	this.hasSword = hasSword;

}

}

Posted

I don't have enough experience about entities to help further  :'( sorry... I searched all the way till class Entity starting from Skeleton, Zombie and Cow, but no clue.. :-\ You might try pathfinding if it has something related, but not really sure

Check out my blog!

http://www.whov.altervista.org

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

    • I am trying to make a custom item that converts to another custom item when eaten. The food properties includes "usingConvertsTo(ModItems.ITEM_NAME.get())", however since the item is not yet registered during the registration process, the get() method returns null. Is there any way to work around this?
    • Having problems with forge installation on headless arch linux, regardless of forge-server from yay or manual wget, Cant find class error and results in net/minecraft/world/waypoints/Waypoint$Icon.class   net/minecraft/world/waypoints/Waypoint.class   net/minecraft/world/waypoints/WaypointManager.class   net/minecraft/world/waypoints/WaypointStyleAsset.class   net/minecraft/world/waypoints/WaypointStyleAssets.class   net/minecraft/world/waypoints/WaypointTransmitter$BlockConnection.class   net/minecraft/world/waypoints/WaypointTransmitter$ChunkConnection.class   net/minecraft/world/waypoints/WaypointTransmitter$Connection.class   net/minecraft/world/waypoints/WaypointTransmitter$EntityAzimuthConnection.class   net/minecraft/world/waypoints/WaypointTransmitter$EntityBlockConnection.class   net/minecraft/world/waypoints/WaypointTransmitter$EntityChunkConnection.class   net/minecraft/world/waypoints/WaypointTransmitter.class   version.json   Processor failed, invalid outputs:     /srv/minecraft/./libraries/net/minecraft/server/1.21.6/server-1.21.6-official.jar       Expected: b1448d2c947e923ccd63224defc3b51e5a72a98d       Actual:   5f30bf411bd0d1208baca6b7be1584442f4f6579 There was an error during installation
    • This is my first time setting up a minecraft server, and I had wanted to add modding capabilities with forge but I keep getting errors while installing? I have tried installing several versions of forge but i have ended up getting unable to find class and checksum errors? Same thing when trying yay -S forge-server The only thing that works is installing the vanilla minecraft server from minecraft itself?   net/minecraft/util/parsing/packrat/Atom.class   net/minecraft/util/parsing/packrat/CachedParseState$CacheEntry.class   net/minecraft/util/parsing/packrat/CachedParseState$PositionCache.class   net/minecraft/util/parsing/packrat/CachedParseState$Silent.class   net/minecraft/util/parsing/packrat/CachedParseState$SimpleControl.class   net/minecraft/util/parsing/packrat/CachedParseState.class   net/minecraft/util/parsing/packrat/Control$1.class   net/minecraft/util/parsing/packrat/Control.class   net/minecraft/util/parsing/packrat/DelayedException.class   net/minecraft/util/parsing/packrat/Dictionary$Entry.class   net/minecraft/util/parsing/packrat/Dictionary$Reference.class   net/minecraft/util/parsing/packrat/Dictionary.class   net/minecraft/util/parsing/packrat/ErrorCollector$LongestOnly$MutableErrorEntry.class   net/minecraft/util/parsing/packrat/ErrorCollector$LongestOnly.class   net/minecraft/util/parsing/packrat/ErrorCollector$Nop.class   net/minecraft/util/parsing/packrat/ErrorCollector.class   net/minecraft/util/parsing/packrat/ErrorEntry.class   net/minecraft/util/parsing/packrat/NamedRule.class   net/minecraft/util/parsing/packrat/ParseState.class   net/minecraft/util/parsing/packrat/Rule$RuleAction.class   net/minecraft/util/parsing/packrat/Rule$SimpleRuleAction.class   net/minecraft/util/parsing/packrat/Rule$WrappedTerm.class Processor failed, invalid outputs:     /srv/minecraft/./libraries/net/minecraft/server/1.21.6/server-1.21.6-official.jar       Expected: b1448d2c947e923ccd63224defc3b51e5a72a98d       Actual:   5f30bf411bd0d1208baca6b7be1584442f4f6579 There was an error during installation  
    • Fight with others to gain more hearts.
    • I wanted to try out Immersive railroading mod + Miszko's train resource pack, but everytime i create a world. it just gives me saving world after the map icon shows 100% and then crashes..   latest.log here https://drive.google.com/file/d/14v1pGCoytqyDvVwPayfUkYolmxcZ7z6-/view?usp=sharing
  • Topics

×
×
  • Create New...

Important Information

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