The Meaning of Life, the Universe, and Everything.
Join Date:
6/27/2011
Posts:
50
Member Details
I'm trying to make a custom albino bat entity. I have the textures ready, I just can't figure out how to make the custom bat use the textures I have. Does anyone know how to do this? I've been reading this over and can't seem to get it to work. Thank you.
EDIT: im using this to register my bat in the main Mod's init
And here is the resource location im trying to use
public static final ResourceLocation ALBINOBAT_TEXTURES = new ResourceLocation(ExlineCraftMain.MODID, "exlinecraft:textures/entity/albinobat/albinobat.png");
I get the spawn egg, but they are all just albino boxes.... the bats that is =P
It would help if you post your bat's entity and render classes so we can see what you've done.
However, you can clearly see in that tutorial that in the render class they use this overrided method:
/**
* Returns the location of an entity's texture. Doesn't seem to be called
* unless you call Render.bindEntityTexture.
*/
@Override
protected ResourceLocation getEntityTexture(Entity par1Entity)
{
return serpentTexture;
}
Please use Pastebin, Gist or GitHub to post the code, and use correct syntax highlighting.
The Meaning of Life, the Universe, and Everything.
Join Date:
6/27/2011
Posts:
50
Member Details
Thank you, here are my files.
EntityAlbinoBat.class, I just copied the EntityBat.class
public class EntityAlbinoBat extends EntityAmbientCreature
{
private static final DataParameter<Byte> HANGING = EntityDataManager.<Byte>createKey(EntityBat.class, DataSerializers.BYTE);
/** Coordinates of where the bat spawned. */
private BlockPos spawnPosition;
public EntityAlbinoBat(World worldIn)
{
super(worldIn);
this.setSize(0.5F, 0.9F);
this.setIsBatHanging(true);
}
protected void entityInit()
{
super.entityInit();
this.dataManager.register(HANGING, Byte.valueOf((byte)0));
}
/**
* Returns the volume for the sounds this mob makes.
*/
protected float getSoundVolume()
{
return 0.1F;
}
/**
* Gets the pitch of living sounds in living entities.
*/
protected float getSoundPitch()
{
return super.getSoundPitch() * 0.95F;
}
@Nullable
protected SoundEvent getAmbientSound()
{
return this.getIsBatHanging() && this.rand.nextInt(4) != 0 ? null : SoundEvents.ENTITY_BAT_AMBIENT;
}
protected SoundEvent getHurtSound()
{
return SoundEvents.ENTITY_BAT_HURT;
}
protected SoundEvent getDeathSound()
{
return SoundEvents.ENTITY_BAT_DEATH;
}
/**
* Returns true if this entity should push and be pushed by other entities when colliding.
*/
public boolean canBePushed()
{
return false;
}
protected void collideWithEntity(Entity entityIn)
{
}
protected void collideWithNearbyEntities()
{
}
protected void applyEntityAttributes()
{
super.applyEntityAttributes();
this.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(6.0D);
}
public boolean getIsBatHanging()
{
return (((Byte)this.dataManager.get(HANGING)).byteValue() & 1) != 0;
}
public void setIsBatHanging(boolean isHanging)
{
byte b0 = ((Byte)this.dataManager.get(HANGING)).byteValue();
if (isHanging)
{
this.dataManager.set(HANGING, Byte.valueOf((byte)(b0 | 1)));
}
else
{
this.dataManager.set(HANGING, Byte.valueOf((byte)(b0 & -2)));
}
}
/**
* Called to update the entity's position/logic.
*/
public void onUpdate()
{
super.onUpdate();
if (this.getIsBatHanging())
{
this.motionX = 0.0D;
this.motionY = 0.0D;
this.motionZ = 0.0D;
this.posY = (double)MathHelper.floor(this.posY) + 1.0D - (double)this.height;
}
else
{
this.motionY *= 0.6000000238418579D;
}
}
protected void updateAITasks()
{
super.updateAITasks();
BlockPos blockpos = new BlockPos(this);
BlockPos blockpos1 = blockpos.up();
if (this.getIsBatHanging())
{
if (this.world.getBlockState(blockpos1).isNormalCube())
{
if (this.rand.nextInt(200) == 0)
{
this.rotationYawHead = (float)this.rand.nextInt(360);
}
if (this.world.getNearestPlayerNotCreative(this, 4.0D) != null)
{
this.setIsBatHanging(false);
this.world.playEvent((EntityPlayer)null, 1025, blockpos, 0);
}
}
else
{
this.setIsBatHanging(false);
this.world.playEvent((EntityPlayer)null, 1025, blockpos, 0);
}
}
else
{
if (this.spawnPosition != null && (!this.world.isAirBlock(this.spawnPosition) || this.spawnPosition.getY() < 1))
{
this.spawnPosition = null;
}
if (this.spawnPosition == null || this.rand.nextInt(30) == 0 || this.spawnPosition.distanceSq((double)((int)this.posX), (double)((int)this.posY), (double)((int)this.posZ)) < 4.0D)
{
this.spawnPosition = new BlockPos((int)this.posX + this.rand.nextInt(7) - this.rand.nextInt(7), (int)this.posY + this.rand.nextInt(6) - 2, (int)this.posZ + this.rand.nextInt(7) - this.rand.nextInt(7));
}
double d0 = (double)this.spawnPosition.getX() + 0.5D - this.posX;
double d1 = (double)this.spawnPosition.getY() + 0.1D - this.posY;
double d2 = (double)this.spawnPosition.getZ() + 0.5D - this.posZ;
this.motionX += (Math.signum(d0) * 0.5D - this.motionX) * 0.10000000149011612D;
this.motionY += (Math.signum(d1) * 0.699999988079071D - this.motionY) * 0.10000000149011612D;
this.motionZ += (Math.signum(d2) * 0.5D - this.motionZ) * 0.10000000149011612D;
float f = (float)(MathHelper.atan2(this.motionZ, this.motionX) * (180D / Math.PI)) - 90.0F;
float f1 = MathHelper.wrapDegrees(f - this.rotationYaw);
this.moveForward = 0.5F;
this.rotationYaw += f1;
if (this.rand.nextInt(100) == 0 && this.world.getBlockState(blockpos1).isNormalCube())
{
this.setIsBatHanging(true);
}
}
}
/**
* returns if this entity triggers Block.onEntityWalking on the blocks they walk on. used for spiders and wolves to
* prevent them from trampling crops
*/
protected boolean canTriggerWalking()
{
return false;
}
public void fall(float distance, float damageMultiplier)
{
}
protected void updateFallState(double y, boolean onGroundIn, IBlockState state, BlockPos pos)
{
}
/**
* Return whether this entity should NOT trigger a pressure plate or a tripwire.
*/
public boolean doesEntityNotTriggerPressurePlate()
{
return true;
}
/**
* Called when the entity is attacked.
*/
public boolean attackEntityFrom(DamageSource source, float amount)
{
if (this.isEntityInvulnerable(source))
{
return false;
}
else
{
if (!this.world.isRemote && this.getIsBatHanging())
{
this.setIsBatHanging(false);
}
return super.attackEntityFrom(source, amount);
}
}
public static void registerFixesBat(DataFixer fixer)
{
EntityLiving.registerFixesMob(fixer, EntityBat.class);
}
/**
* (abstract) Protected helper method to read subclass entity data from NBT.
*/
public void readEntityFromNBT(NBTTagCompound compound)
{
super.readEntityFromNBT(compound);
this.dataManager.set(HANGING, Byte.valueOf(compound.getByte("BatFlags")));
}
/**
* (abstract) Protected helper method to write subclass entity data to NBT.
*/
public void writeEntityToNBT(NBTTagCompound compound)
{
super.writeEntityToNBT(compound);
compound.setByte("BatFlags", ((Byte)this.dataManager.get(HANGING)).byteValue());
}
/**
* Checks if the entity's current position is a valid location to spawn this entity.
*/
public boolean getCanSpawnHere()
{
BlockPos blockpos = new BlockPos(this.posX, this.getEntityBoundingBox().minY, this.posZ);
if (blockpos.getY() >= this.world.getSeaLevel())
{
return false;
}
else
{
int i = this.world.getLightFromNeighbors(blockpos);
int j = 4;
if (this.isDateAroundHalloween(this.world.getCurrentDate()))
{
j = 7;
}
else if (this.rand.nextBoolean())
{
return false;
}
return i > this.rand.nextInt(j) ? false : super.getCanSpawnHere();
}
}
private boolean isDateAroundHalloween(Calendar p_175569_1_)
{
return p_175569_1_.get(2) + 1 == 10 && p_175569_1_.get(5) >= 20 || p_175569_1_.get(2) + 1 == 11 && p_175569_1_.get(5) <= 3;
}
public float getEyeHeight()
{
return this.height / 2.0F;
}
@Nullable
protected ResourceLocation getLootTable()
{
return RenderAlbinoBat.ALBINOBAT_TEXTURES;
}
}
RenderAlbinoBat.class
@SideOnly(Side.CLIENT)
public class RenderAlbinoBat extends RenderLiving<EntityAlbinoBat>
{
public static final ResourceLocation ALBINOBAT_TEXTURES = new ResourceLocation(ExlineCraftMain.MODID, "exlinecraft:textures/entity/albinobat/albinobat.png");
public RenderAlbinoBat(RenderManager p_i47210_1_)
{
super(p_i47210_1_, new ModelBat(), 0.5F);
}
@Override
protected ResourceLocation getEntityTexture(EntityAlbinoBat entity)
{
return ALBINOBAT_TEXTURES;
}
}
You have the modid written twice in the texture resource location. Also you can have the EntityAlbinoBat class simply extend EntityBat, instead of copying.
You have the modid written twice in the texture resource location. Also you can have the EntityAlbinoBat class simply extend EntityBat, instead of copying.
Thank you, I will clean it up and see if it works.
I'm getting a regular bat to appear now, but my texture doesn't seem to register. Here are the updated files
EntityAlbinoBat.class
public class EntityAlbinoBat extends EntityBat
{
public EntityAlbinoBat(World worldIn)
{
super(worldIn);
}
}
RenderAlbinoBat.class
@SideOnly(Side.CLIENT)
public class RenderAlbinoBat extends RenderLiving<EntityAlbinoBat>
{
public static final ResourceLocation ALBINOBAT_TEXTURES = new ResourceLocation(ExlineCraftMain.MODID, "textures/entity/albinobat/albinobat.png");
public RenderAlbinoBat(RenderManager renderManagerIn)
{
super(renderManagerIn, new ModelBat(), 0.25F);
}
@Override
protected ResourceLocation getEntityTexture(EntityAlbinoBat entity)
{
return ALBINOBAT_TEXTURES;
}
}
So, I've also got this in my proxy, but I don't know when to call it? I've tried putting it in my main mod file's init() method but it crashed the game.
@Override
public void renderEntities()
{
RenderingRegistry.registerEntityRenderingHandler(EntityAlbinoBat.class, RenderAlbinoBat::new);
}
Thank you kwerti! I have it int my preInit() now and I get a bat with a purple and black texture. I know this probably means its just looking in the wrong place, but I should be close right?
And I just realized I spelled entity wrong in my textures folder, as enity, so no wonder it was missing the texture. But I wouldn't have been able to figure it out without help so thank you!
I'm trying to make a custom albino bat entity. I have the textures ready, I just can't figure out how to make the custom bat use the textures I have. Does anyone know how to do this? I've been reading this over and can't seem to get it to work. Thank you.
EDIT: im using this to register my bat in the main Mod's init
And here is the resource location im trying to use
I get the spawn egg, but they are all just albino boxes.... the bats that is =P
It would help if you post your bat's entity and render classes so we can see what you've done.
However, you can clearly see in that tutorial that in the render class they use this overrided method:
Please use Pastebin, Gist or GitHub to post the code, and use correct syntax highlighting.
Thank you, here are my files.
EntityAlbinoBat.class, I just copied the EntityBat.class
RenderAlbinoBat.class
You have the modid written twice in the texture resource location. Also you can have the EntityAlbinoBat class simply extend EntityBat, instead of copying.
Putting the CENDENT back in transcendent!
Thank you, I will clean it up and see if it works.
I'm getting a regular bat to appear now, but my texture doesn't seem to register. Here are the updated files
EntityAlbinoBat.class
RenderAlbinoBat.class
So, I've also got this in my proxy, but I don't know when to call it? I've tried putting it in my main mod file's init() method but it crashed the game.
Register in preInit(...).
Putting the CENDENT back in transcendent!
It specifically needs to be the preInit in the Client Proxy though.
Thank you kwerti! I have it int my preInit() now and I get a bat with a purple and black texture. I know this probably means its just looking in the wrong place, but I should be close right?
And I just realized I spelled entity wrong in my textures folder, as enity, so no wonder it was missing the texture. But I wouldn't have been able to figure it out without help so thank you!
Edit: It works now! Thank you both!