-
-
Save SanAndreaP/42b4c72c09eb508ec1b4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package SanAndreasP.mods.ClaySoldiersMod; | |
import net.minecraft.client.Minecraft; | |
import net.minecraft.src.*; | |
import java.util.List; | |
import cpw.mods.fml.common.FMLCommonHandler; | |
import cpw.mods.fml.common.Side; | |
import cpw.mods.fml.common.asm.SideOnly; | |
public class CSM_EntityHorse extends EntityCreature implements IAnimals, CSM_IMount { | |
public CSM_EntityHorse(World world) { | |
super(world); | |
this.dataWatcher.addObject(10, (short)0); // horseType | |
this.dataWatcher.addObject(11, (byte)0); // isNightmare | |
postInit = true; | |
health = 30; | |
yOffset = 0.0F; | |
stepHeight = 0.1F; | |
moveSpeed = 0.6F; | |
setSize(0.25F, 0.4F); | |
setPosition(posX, posY, posZ); | |
texture = dirtHorseTexture(0); | |
renderDistanceWeight = 5D; | |
} | |
public CSM_EntityHorse(World world, double x, double y, double z, int i) { | |
this(world); | |
this.dataWatcher.updateObject(10, (short)i); | |
setPosition(x, y, z); | |
if(rand.nextInt(8192) == 0) | |
{ | |
this.dataWatcher.updateObject(11, (byte)1); | |
} | |
texture = dirtHorseTexture(i); | |
setHorseSpecs(i);/*ADDED*/ | |
renderDistanceWeight = 5D; | |
worldObj.playSoundAtEntity(this, "step.gravel", 0.8F, ((rand.nextFloat() - rand.nextFloat()) * 0.2F + 1.0F) * 0.9F); | |
} | |
public String dirtHorseTexture(int i) { | |
String epona = "/SanAndreasP/mods/ClaySoldiersMod/claymans/horse/horse"; | |
if(this.dataWatcher.getWatchableObjectByte(11) > 0) { | |
epona = epona + "Nightmare"; | |
} else if(i == 0) { | |
epona = epona + "Dirt"; | |
} else if(i == 1) { | |
epona = epona + "Sand"; | |
} else if(i == 2) { | |
epona = epona + "Gravel"; | |
} else if(i == 3) { | |
epona = epona + "Snow"; | |
} else if(i == 4) { | |
epona = epona + "Grass"; | |
} else if(i == 5) { | |
epona = epona + "Lapis"; | |
} else if(i == 6) { | |
epona = epona + "Clay"; | |
} | |
return epona + ".png"; | |
} | |
@Override | |
@SideOnly(Side.CLIENT) | |
public String getTexture() { | |
return dirtHorseTexture(this.dataWatcher.getWatchableObjectShort(10)); | |
} | |
@Override | |
public void onUpdate() { | |
super.onUpdate(); | |
if(gotRider) { | |
if(riddenByEntity != null) { | |
gotRider = false; | |
return; | |
} | |
List list = worldObj.getEntitiesWithinAABBExcludingEntity(this, boundingBox.expand(0.1D, 0.1D, 0.1D)); | |
for(int i = 0; i < list.size(); i++) { | |
Entity entity = (Entity)list.get(i); | |
if(!(entity instanceof CSM_EntityClayMan)) { | |
continue; | |
} | |
EntityLiving entityliving = (EntityLiving)entity; | |
if(entityliving.ridingEntity != null || entityliving.riddenByEntity == this) { | |
continue; | |
} | |
entity.mountEntity(this); | |
break; | |
} | |
gotRider = false; | |
} | |
} | |
@Override | |
public void updateEntityActionState() { | |
if(riddenByEntity == null || !(riddenByEntity instanceof CSM_EntityClayMan)) { | |
super.updateEntityActionState(); | |
} else { | |
CSM_EntityClayMan rider = (CSM_EntityClayMan)riddenByEntity; | |
isJumping = rider.getIsJumping() || handleWaterMovement(); | |
moveForward = rider.getMoveForward() * (rider.sugarTime > 0 ? 1F : 2F); | |
moveStrafing = rider.getMoveStrafing() * (rider.sugarTime > 0 ? 1F : 2F); | |
rotationYaw = prevRotationYaw = rider.rotationYaw; | |
rotationPitch = prevRotationPitch = rider.rotationPitch; | |
// if(rider.hasPath()) { | |
// setPathToEntity(rider.getPathToEntity()); | |
// } | |
rider.renderYawOffset = renderYawOffset; | |
riddenByEntity.fallDistance = 0.0F; | |
if(rider.isDead || rider.getHealth() <= 0) { | |
rider.mountEntity(null); | |
} | |
} | |
} | |
public void setHorseSpecs(int i) { /*ADDED*/ | |
if(i == 0) { | |
setEntityHealth(35); | |
moveSpeed = 0.6f; | |
} else if(i == 1) { | |
setEntityHealth(30); | |
moveSpeed = 0.7f; | |
} else if(i == 2) { | |
setEntityHealth(45); | |
moveSpeed = 0.4f; | |
} else if(i == 3) { | |
setEntityHealth(40); | |
moveSpeed = 0.5f; | |
} else if(i == 4) { | |
setEntityHealth(20); | |
moveSpeed = 0.9f; | |
} else if(i == 5) { | |
setEntityHealth(35); | |
moveSpeed = 0.9f; | |
} else if(i == 6) { | |
setEntityHealth(35); | |
moveSpeed = 0.6f; | |
} if(this.dataWatcher.getWatchableObjectByte(11) > 0) { | |
setEntityHealth(50); | |
moveSpeed = 1.2f; | |
} | |
} | |
@Override | |
public void writeToNBT(NBTTagCompound nbttagcompound) | |
{ | |
super.writeToNBT(nbttagcompound); | |
gotRider = (riddenByEntity == null); | |
nbttagcompound.setBoolean("IsFromNexus", spawnedFromNexus); | |
nbttagcompound.setBoolean("GotRider", gotRider); | |
nbttagcompound.setBoolean("Nightmare", this.dataWatcher.getWatchableObjectByte(11) > 0); | |
nbttagcompound.setShort("HorseType", this.dataWatcher.getWatchableObjectShort(10)); | |
} | |
@Override | |
public void readFromNBT(NBTTagCompound nbttagcompound) | |
{ | |
super.readFromNBT(nbttagcompound); | |
gotRider = nbttagcompound.getBoolean("GotRider"); | |
this.dataWatcher.updateObject(11, nbttagcompound.getBoolean("Nightmare") ? (byte) 1 : (byte) 0); | |
if(nbttagcompound.hasKey("HorseType")) | |
this.dataWatcher.updateObject(10, nbttagcompound.getShort("HorseType")); | |
texture = dirtHorseTexture(this.dataWatcher.getWatchableObjectShort(10)); | |
spawnedFromNexus = nbttagcompound.getBoolean("IsFromNexus"); | |
setHorseSpecs(this.dataWatcher.getWatchableObjectShort(10)); | |
} | |
@Override | |
protected String getHurtSound() | |
{ | |
worldObj.playSoundAtEntity(this, "step.gravel", 0.6F, 1.0F / (rand.nextFloat() * 0.2F + 0.9F)); | |
return ""; | |
} | |
@Override | |
protected String getDeathSound() | |
{ | |
return "step.gravel"; | |
} | |
@Override | |
protected void jump() | |
{ | |
motionY = 0.4D; | |
} | |
@Override | |
public void mountEntity(Entity e) { | |
if(!(e != null && e instanceof EntityMinecart)) { | |
super.mountEntity(e); | |
} | |
} | |
@Override | |
protected boolean canDespawn() | |
{ | |
return false; | |
} | |
@Override | |
protected void dropFewItems(boolean flag, int i) { | |
Item item1 = CSM_ModRegistry.horseDoll; | |
dropItem(item1.shiftedIndex, 1, this.dataWatcher.getWatchableObjectShort(10)); | |
} | |
protected void dropItem(int shiftedIndex, int i, int j) { | |
entityDropItem(new ItemStack(shiftedIndex, i, j), 0.0F); | |
} | |
@Override | |
public EntityItem entityDropItem(ItemStack par1ItemStack, float par2) { | |
return spawnedFromNexus ? null : super.entityDropItem(par1ItemStack, par2); | |
} | |
@Override | |
public boolean attackEntityFrom(DamageSource damagesource, int i) { | |
int origDmg = i; | |
Entity e = damagesource.getSourceOfDamage(); | |
if((e == null || !(e instanceof CSM_EntityClayMan)) && !damagesource.fireDamage()) { | |
i = 100; | |
} if(damagesource.fireDamage() && this.dataWatcher.getWatchableObjectByte(11) > 0) { | |
i = 0; | |
} | |
if(riddenByEntity != null && riddenByEntity instanceof CSM_EntityClayMan) { | |
if(e instanceof CSM_EntityGravelChunk) { | |
if(((CSM_EntityGravelChunk)e).getClayTeam() == ((CSM_EntityClayMan)riddenByEntity).getDataWatcherShort("clayTeam")) | |
return false; | |
else | |
i = origDmg; | |
} | |
if(e instanceof CSM_EntityFireball) { | |
if(((CSM_EntityFireball)e).getClayTeam() == ((CSM_EntityClayMan)riddenByEntity).getDataWatcherShort("clayTeam")) | |
return false; | |
else | |
i = origDmg; | |
} | |
if(e instanceof CSM_EntitySnowball) { | |
if(((CSM_EntitySnowball)e).getClayTeam() == ((CSM_EntityClayMan)riddenByEntity).getDataWatcherShort("clayTeam")) | |
return false; | |
else | |
i = origDmg; | |
} | |
} | |
boolean fred = super.attackEntityFrom(damagesource, i); | |
if(fred && health <= 0) { | |
Item item1 = CSM_ModRegistry.horseDoll; | |
for(int j = 0; j < 4; j++) { | |
double a = posX + ((rand.nextFloat() - rand.nextFloat()) * 0.125D); | |
double b = boundingBox.minY + 0.125D + ((rand.nextFloat() - rand.nextFloat()) * 0.25D); | |
double c = posZ + ((rand.nextFloat() - rand.nextFloat()) * 0.125D); | |
if(FMLCommonHandler.instance().getSide().isClient()) | |
Minecraft.getMinecraft().effectRenderer.addEffect((new EntityDiggingFX(Minecraft.getMinecraft().theWorld, a, b, c, 0.0D, 0.0D, 0.0D, Block.dirt, 0, 0))); | |
} | |
if(damagesource.fireDamage() && this.dataWatcher.getWatchableObjectByte(11) <= 0 && health <= 2 && rand.nextInt(16) == 0) { | |
this.dataWatcher.updateObject(11, (byte)1); | |
texture = dirtHorseTexture(this.dataWatcher.getWatchableObjectShort(10)); | |
setHorseSpecs(this.dataWatcher.getWatchableObjectShort(10)); | |
} else { | |
isDead = true; | |
} | |
} | |
return fred; | |
} | |
@Override | |
public void knockBack(Entity entity, int i, double d, double d1) | |
{ | |
super.knockBack(entity, i, d, d1); | |
if(entity != null && entity instanceof CSM_EntityClayMan) { | |
motionX *= 0.6D; | |
motionY *= 0.75D; | |
motionZ *= 0.6D; | |
} | |
} | |
@Override | |
public boolean isOnLadder() { | |
return false; | |
} | |
@Override | |
public boolean canBreatheUnderwater() | |
{ | |
short horseType = this.dataWatcher.getWatchableObjectShort(10); | |
if((horseType == 5 || horseType == 6) && this.dataWatcher.getWatchableObjectByte(11) <= 0) { | |
return true; | |
} else { | |
return false; | |
} | |
} | |
@Override | |
public boolean interact(EntityPlayer e) { | |
return false; | |
} | |
@Override | |
public CSM_EntityHorse setSpawnedFromNexus() { | |
spawnedFromNexus = true; | |
return this; | |
} | |
@Override | |
public int getMaxHealth() { | |
if(!postInit) | |
return 30; | |
switch (this.dataWatcher.getWatchableObjectShort(10)) { | |
case 0: return 35; | |
case 1: return 30; | |
case 2: return 45; | |
case 3: return 40; | |
case 4: return 20; | |
case 5: return 35; | |
case 6: return 35; | |
default: return 30; | |
} | |
} | |
public boolean gotRider, spawnedFromNexus = false; | |
public boolean postInit = false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment