So I'm trying to make mobs drop money like XP when killed, and I tried looking through vanilla code, but I can't get heads or tails on how to make this work.
Okay, I got that part done, but now I need to make XP Orb-like entities and I'm not sure how to go about that since there's almost nothing on it anywhere.
Okay, I got that part done, but now I need to make XP Orb-like entities and I'm not sure how to go about that since there's almost nothing on it anywhere.
There are the vanilla XP orbs - surely that counts as something and it would pretty much be a copy/paste solution to your problem, or you could even implement them as items that drop.
package dialgex.SburbCraft.Events;
import java.util.Random;
import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.IEntityLivingData;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.item.Item;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
import net.minecraftforge.event.entity.living.LivingDropsEvent;
import dialgex.SburbCraft.Entities.Boondollars.*;
import dialgex.SburbCraft.Items.Grist.*;
import net.minecraft.entity.passive.*;
public class GristDropEvent{
private static int rNum(int min, int max) {
Random r = new Random();
int randomNum = r.nextInt((max - min) + 1) + min;
return randomNum;
}
public static double rand;
private World world = FMLClientHandler.instance().getWorldClient();
@SubscribeEvent
public void onEntityDrop(LivingDropsEvent event){
int r4 = rNum(1,4);
int r3 = rNum(1,3);
int r2 = rNum(1,2);
if (event.source.getDamageType().equals("player")){
rand = Math.random();
if (event.entityLiving instanceof EntityPig){
double tx = event.entityLiving.posX;
double ty = event.entityLiving.posY;
double tz = event.entityLiving.posZ;
Boondollar b = new Boondollar(world, tx, ty, tz, 125);
world.spawnEntityInWorld(b);
/*event.entityLiving.dropItem(Boondollar.Boondollar10, r2);
event.entityLiving.dropItem(Boondollar.Boondollar25, 1);
if(rand < 0.66d){
event.entityLiving.dropItem(Boondollar.Boondollar5, r4);
if(rand < 0.33d){
event.entityLiving.dropItem(Boondollar.Boondollar10, r2);
}
}*/
}
if (event.entityLiving instanceof EntityCow){
event.entityLiving.dropItem(Grist.BuildGrist, 1);
/*event.entityLiving.dropItem(Boondollar.Boondollar50, 1);
if(rand < 0.66d){
event.entityLiving.dropItem(Boondollar.Boondollar5, r4);
if(rand < 0.33d){
event.entityLiving.dropItem(Boondollar.Boondollar10, r2);
}
}*/
}
if (event.entityLiving instanceof EntityChicken){
event.entityLiving.dropItem(Grist.BuildGrist, 3);
/*event.entityLiving.dropItem(Boondollar.Boondollar25, 1);
if(rand < 0.66d){
event.entityLiving.dropItem(Boondollar.Boondollar5, r4);
if(rand < 0.33d){
event.entityLiving.dropItem(Boondollar.Boondollar10, r2);
}
}*/
}
if (event.entityLiving instanceof EntitySheep){
event.entityLiving.dropItem(Grist.BuildGrist, 1);
/*event.entityLiving.dropItem(Boondollar.Boondollar50, 1);
if(rand < 0.66d){
event.entityLiving.dropItem(Boondollar.Boondollar5, r4);
if(rand < 0.33d){
event.entityLiving.dropItem(Boondollar.Boondollar10, r2);
}
}*/
}
if (event.entityLiving instanceof EntityHorse){
event.entityLiving.dropItem(Grist.BuildGrist, 1);
/*event.entityLiving.dropItem(Boondollar.Boondollar10, 2);
event.entityLiving.dropItem(Boondollar.Boondollar50, 2);
if(rand < 0.66d){
event.entityLiving.dropItem(Boondollar.Boondollar5, r4);
if(rand < 0.33d){
event.entityLiving.dropItem(Boondollar.Boondollar10, r2);
}
}*/
}
///////////////////////////////////////////
}
}
}
The Entity file:
package dialgex.SburbCraft.Entities.Boondollars;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.material.Material;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.DamageSource;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import dialgex.SburbCraft.Events.PlayerPickupBoondollarEvent;
public class Boondollar extends Entity
{
/**
* A constantly increasing value that RenderXPOrb uses to control the colour shifting (Green / yellow)
*/
public int xpColor;
/** The age of the XP orb in ticks. */
public int xpOrbAge;
public int field_70532_c;
/** The health of this XP orb. */
private int xpOrbHealth = 5;
/** This is how much XP this orb has. */
public int xpValue;
/** The closest EntityPlayer to this orb. */
private EntityPlayer closestPlayer;
/** Threshold color for tracking players */
private int xpTargetColor;
private static final String __OBFID = "CL_00001544";
public Boondollar(World p_i1585_1_, double p_i1585_2_, double p_i1585_4_, double p_i1585_6_, int p_i1585_8_)
{
super(p_i1585_1_);
this.setSize(0.5F, 0.5F);
this.yOffset = this.height / 2.0F;
this.setPosition(p_i1585_2_, p_i1585_4_, p_i1585_6_);
this.rotationYaw = (float)(Math.random() * 360.0D);
this.motionX = (double)((float)(Math.random() * 0.20000000298023224D - 0.10000000149011612D) * 2.0F);
this.motionY = (double)((float)(Math.random() * 0.2D) * 2.0F);
this.motionZ = (double)((float)(Math.random() * 0.20000000298023224D - 0.10000000149011612D) * 2.0F);
this.xpValue = p_i1585_8_;
}
/**
* 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 Boondollar(World p_i1586_1_)
{
super(p_i1586_1_);
this.setSize(0.25F, 0.25F);
this.yOffset = this.height / 2.0F;
}
protected void entityInit() {}
@SideOnly(Side.CLIENT)
public int getBrightnessForRender(float p_70070_1_)
{
float f1 = 0.5F;
if (f1 < 0.0F)
{
f1 = 0.0F;
}
if (f1 > 1.0F)
{
f1 = 1.0F;
}
int i = super.getBrightnessForRender(p_70070_1_);
int j = i & 255;
int k = i >> 16 & 255;
j += (int)(f1 * 15.0F * 16.0F);
if (j > 240)
{
j = 240;
}
return j | k << 16;
}
/**
* Called to update the entity's position/logic.
*/
public void onUpdate()
{
super.onUpdate();
if (this.field_70532_c > 0)
{
--this.field_70532_c;
}
this.prevPosX = this.posX;
this.prevPosY = this.posY;
this.prevPosZ = this.posZ;
this.motionY -= 0.029999999329447746D;
if (this.worldObj.getBlock(MathHelper.floor_double(this.posX), MathHelper.floor_double(this.posY), MathHelper.floor_double(this.posZ)).getMaterial() == Material.lava)
{
this.motionY = 0.20000000298023224D;
this.motionX = (double)((this.rand.nextFloat() - this.rand.nextFloat()) * 0.2F);
this.motionZ = (double)((this.rand.nextFloat() - this.rand.nextFloat()) * 0.2F);
this.playSound("random.fizz", 0.4F, 2.0F + this.rand.nextFloat() * 0.4F);
}
this.func_145771_j(this.posX, (this.boundingBox.minY + this.boundingBox.maxY) / 2.0D, this.posZ);
double d0 = 8.0D;
if (this.xpTargetColor < this.xpColor - 20 + this.getEntityId() % 100)
{
if (this.closestPlayer == null || this.closestPlayer.getDistanceSqToEntity(this) > d0 * d0)
{
this.closestPlayer = this.worldObj.getClosestPlayerToEntity(this, d0);
}
this.xpTargetColor = this.xpColor;
}
if (this.closestPlayer != null)
{
double d1 = (this.closestPlayer.posX - this.posX) / d0;
double d2 = (this.closestPlayer.posY + (double)this.closestPlayer.getEyeHeight() - this.posY) / d0;
double d3 = (this.closestPlayer.posZ - this.posZ) / d0;
double d4 = Math.sqrt(d1 * d1 + d2 * d2 + d3 * d3);
double d5 = 1.0D - d4;
if (d5 > 0.0D)
{
d5 *= d5;
this.motionX += d1 / d4 * d5 * 0.1D;
this.motionY += d2 / d4 * d5 * 0.1D;
this.motionZ += d3 / d4 * d5 * 0.1D;
}
}
this.moveEntity(this.motionX, this.motionY, this.motionZ);
float f = 0.98F;
if (this.onGround)
{
f = this.worldObj.getBlock(MathHelper.floor_double(this.posX), MathHelper.floor_double(this.boundingBox.minY) - 1, MathHelper.floor_double(this.posZ)).slipperiness * 0.98F;
}
this.motionX *= (double)f;
this.motionY *= 0.9800000190734863D;
this.motionZ *= (double)f;
if (this.onGround)
{
this.motionY *= -0.8999999761581421D;
}
++this.xpColor;
++this.xpOrbAge;
if (this.xpOrbAge >= 6000)
{
this.setDead();
}
}
/**
* Returns if this entity is in water and will end up adding the waters velocity to the entity
*/
public boolean handleWaterMovement()
{
return this.worldObj.handleMaterialAcceleration(this.boundingBox, Material.water, this);
}
/**
* Will deal the specified amount of damage to the entity if the entity isn't immune to fire damage. Args:
* amountDamage
*/
protected void dealFireDamage(int p_70081_1_)
{
this.attackEntityFrom(DamageSource.inFire, (float)p_70081_1_);
}
/**
* Called when the entity is attacked.
*/
public boolean attackEntityFrom(DamageSource p_70097_1_, float p_70097_2_)
{
if (this.isEntityInvulnerable())
{
return false;
}
else
{
this.setBeenAttacked();
this.xpOrbHealth = (int)((float)this.xpOrbHealth - p_70097_2_);
if (this.xpOrbHealth <= 0)
{
this.setDead();
}
return false;
}
}
/**
* (abstract) Protected helper method to write subclass entity data to NBT.
*/
public void writeEntityToNBT(NBTTagCompound p_70014_1_)
{
p_70014_1_.setShort("Health", (short)((byte)this.xpOrbHealth));
p_70014_1_.setShort("Age", (short)this.xpOrbAge);
p_70014_1_.setShort("Value", (short)this.xpValue);
}
/**
* (abstract) Protected helper method to read subclass entity data from NBT.
*/
public void readEntityFromNBT(NBTTagCompound p_70037_1_)
{
this.xpOrbHealth = p_70037_1_.getShort("Health") & 255;
this.xpOrbAge = p_70037_1_.getShort("Age");
this.xpValue = p_70037_1_.getShort("Value");
}
/**
* Called by a player entity when they collide with an entity
*/
public void onCollideWithPlayer(EntityPlayer p_70100_1_)
{
if (!this.worldObj.isRemote)
{
if (this.field_70532_c == 0 && p_70100_1_.xpCooldown == 0)
{
if (MinecraftForge.EVENT_BUS.post(new PlayerPickupBoondollarEvent(p_70100_1_, this))) return;
p_70100_1_.xpCooldown = 2;
this.worldObj.playSoundAtEntity(p_70100_1_, "random.orb", 0.1F, 0.5F * ((this.rand.nextFloat() - this.rand.nextFloat()) * 0.7F + 1.8F));
p_70100_1_.onItemPickup(this, 1);
p_70100_1_.addExperience(this.xpValue);
this.setDead();
}
}
}
/**
* Returns the XP value of this XP orb.
*/
public int getXpValue()
{
return this.xpValue;
}
/**
* Returns a number from 1 to 10 based on how much XP this orb is worth. This is used by RenderXPOrb to determine
* what texture to use.
*/
@SideOnly(Side.CLIENT)
public int getTextureByXP()
{
return this.xpValue >= 2477 ? 10 : (this.xpValue >= 1237 ? 9 : (this.xpValue >= 617 ? 8 : (this.xpValue >= 307 ? 7 : (this.xpValue >= 149 ? 6 : (this.xpValue >= 73 ? 5 : (this.xpValue >= 37 ? 4 : (this.xpValue >= 17 ? 3 : (this.xpValue >= 7 ? 2 : (this.xpValue >= 3 ? 1 : 0)))))))));
}
/**
* Get a fragment of the maximum experience points value for the supplied value of experience points value.
*/
public static int getXPSplit(int p_70527_0_)
{
return p_70527_0_ >= 2477 ? 2477 : (p_70527_0_ >= 1237 ? 1237 : (p_70527_0_ >= 617 ? 617 : (p_70527_0_ >= 307 ? 307 : (p_70527_0_ >= 149 ? 149 : (p_70527_0_ >= 73 ? 73 : (p_70527_0_ >= 37 ? 37 : (p_70527_0_ >= 17 ? 17 : (p_70527_0_ >= 7 ? 7 : (p_70527_0_ >= 3 ? 3 : 1)))))))));
}
/**
* If returns false, the item will not inflict any damage against entities.
*/
public boolean canAttackWithItem()
{
return false;
}
}
The Render file:
package dialgex.SburbCraft.Render;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.entity.Render;
import net.minecraft.entity.Entity;
import net.minecraft.util.MathHelper;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;
import dialgex.SburbCraft.Entities.Boondollars.Boondollar;
@SideOnly(Side.CLIENT)
public class RenderBoondollar extends Render
{
private static final ResourceLocation BoondollarTextures = new ResourceLocation("SburbCraft", "textures/entities/Boondollar.png");
private static final String __OBFID = "CL_00000993";
public RenderBoondollar()
{
this.shadowSize = 0.15F;
this.shadowOpaque = 0.75F;
}
/**
* Actually renders the given argument. This is a synthetic bridge method, always casting down its argument and then
* handing it off to a worker function which does the actual work. In all probabilty, the class Render is generic
* (Render * double d2, float f, float f1). But JAD is pre 1.5 so doesn't do that.
*/
public void doRender(Boondollar p_76986_1_, double p_76986_2_, double p_76986_4_, double p_76986_6_, float p_76986_8_, float p_76986_9_)
{
GL11.glPushMatrix();
GL11.glTranslatef((float)p_76986_2_, (float)p_76986_4_, (float)p_76986_6_);
this.bindEntityTexture(p_76986_1_);
int i = p_76986_1_.getTextureByXP();
float f2 = (float)(i % 4 * 16 + 0) / 64.0F;
float f3 = (float)(i % 4 * 16 + 16) / 64.0F;
float f4 = (float)(i / 4 * 16 + 0) / 64.0F;
float f5 = (float)(i / 4 * 16 + 16) / 64.0F;
float f6 = 1.0F;
float f7 = 0.5F;
float f8 = 0.25F;
int j = p_76986_1_.getBrightnessForRender(p_76986_9_);
int k = j % 65536;
int l = j / 65536;
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, (float)k / 1.0F, (float)l / 1.0F);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
float f10 = 255.0F;
float f11 = ((float)p_76986_1_.xpColor + p_76986_9_) / 2.0F;
l = (int)((MathHelper.sin(f11 + 0.0F) + 1.0F) * 0.5F * f10);
int i1 = (int)f10;
int j1 = (int)((MathHelper.sin(f11 + 4.1887903F) + 1.0F) * 0.1F * f10);
int k1 = l << 16 | i1 << 8 | j1;
GL11.glRotatef(180.0F - this.renderManager.playerViewY, 0.0F, 1.0F, 0.0F);
GL11.glRotatef(-this.renderManager.playerViewX, 1.0F, 0.0F, 0.0F);
float f9 = 0.3F;
GL11.glScalef(f9, f9, f9);
Tessellator tessellator = Tessellator.instance;
tessellator.startDrawingQuads();
tessellator.setColorRGBA_I(k1, 128);
tessellator.setNormal(0.0F, 1.0F, 0.0F);
tessellator.addVertexWithUV((double)(0.0F - f7), (double)(0.0F - f8), 0.0D, (double)f2, (double)f5);
tessellator.addVertexWithUV((double)(f6 - f7), (double)(0.0F - f8), 0.0D, (double)f3, (double)f5);
tessellator.addVertexWithUV((double)(f6 - f7), (double)(1.0F - f8), 0.0D, (double)f3, (double)f4);
tessellator.addVertexWithUV((double)(0.0F - f7), (double)(1.0F - f8), 0.0D, (double)f2, (double)f4);
tessellator.draw();
GL11.glDisable(GL11.GL_BLEND);
GL11.glDisable(GL12.GL_RESCALE_NORMAL);
GL11.glPopMatrix();
}
/**
* Returns the location of an entity's texture. Doesn't seem to be called unless you call Render.bindEntityTexture.
*/
protected ResourceLocation getEntityTexture(Boondollar p_110775_1_)
{
return BoondollarTextures;
}
/**
* Returns the location of an entity's texture. Doesn't seem to be called unless you call Render.bindEntityTexture.
*/
protected ResourceLocation getEntityTexture(Entity p_110775_1_)
{
return this.getEntityTexture((Boondollar)p_110775_1_);
}
/**
* Actually renders the given argument. This is a synthetic bridge method, always casting down its argument and then
* handing it off to a worker function which does the actual work. In all probability, the class Render is generic
* (Render * double d2, float f, float f1). But JAD is pre 1.5 so doesn't do that.
*/
public void doRender(Entity p_76986_1_, double p_76986_2_, double p_76986_4_, double p_76986_6_, float p_76986_8_, float p_76986_9_)
{
this.doRender((Boondollar)p_76986_1_, p_76986_2_, p_76986_4_, p_76986_6_, p_76986_8_, p_76986_9_);
}
}
And the Crash report:
java.lang.NullPointerException: Ticking memory connection
at dialgex.SburbCraft.Events.GristDropEvent.onEntityDrop(GristDropEvent.java:47)
at cpw.mods.fml.common.eventhandler.ASMEventHandler_5_GristDropEvent_onEntityDrop_LivingDropsEvent.invoke(.dynamic)
at cpw.mods.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:51)
at cpw.mods.fml.common.eventhandler.EventBus.post(EventBus.java:122)
at net.minecraftforge.common.ForgeHooks.onLivingDrops(ForgeHooks.java:298)
at net.minecraft.entity.EntityLivingBase.onDeath(EntityLivingBase.java:1040)
at net.minecraft.entity.EntityLivingBase.attackEntityFrom(EntityLivingBase.java:950)
at net.minecraft.entity.passive.EntityAnimal.attackEntityFrom(EntityAnimal.java:224)
at net.minecraft.entity.player.EntityPlayer.attackTargetEntityWithCurrentItem(EntityPlayer.java:1400)
at net.minecraft.network.NetHandlerPlayServer.processUseEntity(NetHandlerPlayServer.java:876)
at net.minecraft.network.play.client.C02PacketUseEntity.processPacket(C02PacketUseEntity.java:51)
at net.minecraft.network.play.client.C02PacketUseEntity.processPacket(C02PacketUseEntity.java:69)
at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:247)
at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:182)
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:736)
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:624)
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:495)
at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:762)
private World world = FMLClientHandler.instance().getWorldClient();
Big NO right there. NEVER do this, why? Because every entity already has a world object, and that code is specifically getting a client-sided version of the world, and it's just plain fugly. Use 'event.entity.worldObj' or whatever entity you have available (player, cow, even tile entities have worldObj, though they are unrelated to entity...).
Did you register your render class? In your ClientProxy, you should either already have or create a method such as 'registerRenderers' or whatever, the name doesn't matter, and in there should be something like this for your Boondollar entity:
RenderingRegistry.registerEntityRenderingHandler(Boondollar.class, new RenderBoondollar());
Yes, but you never call that method. You need to add 'proxy.registerRenderers()' to your main class during pre-init, after you register the entity, of course.
Also, you should only have ONE proxy instance, your CommonProxy, because ClientProxy extends it already:
// NO:
public static ClientProxy cproxy;
public static CommonProxy sproxy;
// YES:
public static CommonProxy proxy; // ClientProxy gets called by extension
@coolAlias
Fixed, but Eclipse is saying that the method doesn't exist.
That's because you have to have it in your CommonProxy class, too, but empty:
public class CommonProxy {
public void registerRenderers() {}
}
public class ClientProxy extends CommonProxy {
@Override
public void registerRenderers() {
// register render classes here
}
}
All the code and stuff is working flawlessly, but the texture I'm using is 64x64 and only a corner of it is showing up.
Any way I can resize the texture use?
All the code and stuff is working flawlessly, but the texture I'm using is 64x64 and only a corner of it is showing up.
Any way I can resize the texture use?
That's caused by the render code you copied from RenderXPOrb - nothing wrong with that, but you'll have to tinker with the numbers to get the correct vertices and such for drawing with the tessellator, which will end up making your entity bigger, and then you have to scale it... depending on what your texture is supposed to look like, it might be easier using the standard Item render code (or EntityItem) rather than the xp orb render code.
Nah, I'll just tinker with the XP code, because each different Boondollar has a different texture.
I'm sure I can figure this one out on my own. Thanks for all the help thus far!
Okay, need to revive this thread because a new issue came up.
All the files and such are working flawlessly, but for some reason, the getTextureFromXP method isn't getting the xpValue, so the texture doesn't change in regards to the Renderer
DropEvent:
package dialgex.SburbCraft.Events;
import java.util.Random;
import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.common.FMLLog;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.IEntityLivingData;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.item.Item;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
import net.minecraftforge.event.entity.living.LivingDropsEvent;
import dialgex.SburbCraft.Entities.Boondollars.*;
import dialgex.SburbCraft.Items.Grist.*;
import net.minecraft.entity.passive.*;
public class GristDropEvent{
private static int rNum(int min, int max) {
Random r = new Random();
int randomNum = r.nextInt((max - min) + 1) + min;
return randomNum;
}
public static double rand;
@SubscribeEvent
public void onEntityDrop(LivingDropsEvent event){
World world = event.entity.worldObj;
int r4 = rNum(1,4);
int r3 = rNum(1,3);
int r2 = rNum(1,2);
if (event.source.getDamageType().equals("player")){
double tx = event.entityLiving.posX;
double ty = event.entityLiving.posY;
double tz = event.entityLiving.posZ;
rand = Math.random();
if (event.entityLiving instanceof EntityPig){
Boondollar b0 = new Boondollar(world, tx, ty, tz, 5);
Boondollar b1 = new Boondollar(world, tx, ty, tz, 10);
Boondollar b2 = new Boondollar(world, tx, ty, tz, 25);
Boondollar b3 = new Boondollar(world, tx, ty, tz, 50);
world.spawnEntityInWorld(b0);
world.spawnEntityInWorld(b1);
world.spawnEntityInWorld(b2);
world.spawnEntityInWorld(b3);
/*if(rand < 0.66d){
if(rand < 0.33d){
Boondollar b4 = new Boondollar(world, tx, ty, tz, 10);
world.spawnEntityInWorld(b4);
}
}*/
}
if (event.entityLiving instanceof EntityCow){
event.entityLiving.dropItem(Grist.BuildGrist, 1);
/*event.entityLiving.dropItem(Boondollar.Boondollar50, 1);
if(rand < 0.66d){
event.entityLiving.dropItem(Boondollar.Boondollar5, r4);
if(rand < 0.33d){
event.entityLiving.dropItem(Boondollar.Boondollar10, r2);
}
}*/
}
if (event.entityLiving instanceof EntityChicken){
event.entityLiving.dropItem(Grist.BuildGrist, 3);
/*event.entityLiving.dropItem(Boondollar.Boondollar25, 1);
if(rand < 0.66d){
event.entityLiving.dropItem(Boondollar.Boondollar5, r4);
if(rand < 0.33d){
event.entityLiving.dropItem(Boondollar.Boondollar10, r2);
}
}*/
}
if (event.entityLiving instanceof EntitySheep){
event.entityLiving.dropItem(Grist.BuildGrist, 1);
/*event.entityLiving.dropItem(Boondollar.Boondollar50, 1);
if(rand < 0.66d){
event.entityLiving.dropItem(Boondollar.Boondollar5, r4);
if(rand < 0.33d){
event.entityLiving.dropItem(Boondollar.Boondollar10, r2);
}
}*/
}
if (event.entityLiving instanceof EntityHorse){
event.entityLiving.dropItem(Grist.BuildGrist, 1);
/*event.entityLiving.dropItem(Boondollar.Boondollar10, 2);
event.entityLiving.dropItem(Boondollar.Boondollar50, 2);
if(rand < 0.66d){
event.entityLiving.dropItem(Boondollar.Boondollar5, r4);
if(rand < 0.33d){
event.entityLiving.dropItem(Boondollar.Boondollar10, r2);
}
}*/
}
///////////////////////////////////////////
}
}
}
EntityFile (getTextureFromXp is here towards the bottom):
package dialgex.SburbCraft.Entities.Boondollars;
import cpw.mods.fml.common.FMLLog;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.material.Material;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.DamageSource;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import dialgex.SburbCraft.Events.PlayerPickupBoondollarEvent;
public class Boondollar extends Entity
{
/**
* A constantly increasing value that RenderXPOrb uses to control the colour shifting (Green / yellow)
*/
public int xpColor;
/** The age of the XP orb in ticks. */
public int xpOrbAge;
public int field_70532_c;
/** The health of this XP orb. */
private int xpOrbHealth = 5;
/** This is how much XP this orb has. */
public int xpValue;
/** The closest EntityPlayer to this orb. */
private EntityPlayer closestPlayer;
/** Threshold color for tracking players */
private int xpTargetColor;
private static final String __OBFID = "CL_00001544";
public Boondollar(World p_i1585_1_, double p_i1585_2_, double p_i1585_4_, double p_i1585_6_, int p_i1585_8_)
{
super(p_i1585_1_);
this.setSize(0.5F, 0.5F);
this.yOffset = this.height / 2.0F;
this.setPosition(p_i1585_2_, p_i1585_4_, p_i1585_6_);
this.rotationYaw = (float)(Math.random() * 360.0D);
this.motionX = (double)((float)(Math.random() * 0.20000000298023224D - 0.10000000149011612D) * 2.0F);
this.motionY = (double)((float)(Math.random() * 0.2D) * 2.0F);
this.motionZ = (double)((float)(Math.random() * 0.20000000298023224D - 0.10000000149011612D) * 2.0F);
xpValue = p_i1585_8_;
}
/**
* 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 Boondollar(World p_i1586_1_)
{
super(p_i1586_1_);
this.setSize(0.25F, 0.25F);
this.yOffset = this.height / 2.0F;
}
protected void entityInit() {}
@SideOnly(Side.CLIENT)
public int getBrightnessForRender(float p_70070_1_)
{
float f1 = 0.5F;
if (f1 < 0.0F)
{
f1 = 0.0F;
}
if (f1 > 1.0F)
{
f1 = 1.0F;
}
int i = super.getBrightnessForRender(p_70070_1_);
int j = i & 255;
int k = i >> 16 & 255;
j += (int)(f1 * 15.0F * 16.0F);
if (j > 240)
{
j = 240;
}
return j | k << 16;
}
/**
* Called to update the entity's position/logic.
*/
public void onUpdate()
{
super.onUpdate();
if (this.field_70532_c > 0)
{
--this.field_70532_c;
}
this.prevPosX = this.posX;
this.prevPosY = this.posY;
this.prevPosZ = this.posZ;
this.motionY -= 0.029999999329447746D;
if (this.worldObj.getBlock(MathHelper.floor_double(this.posX), MathHelper.floor_double(this.posY), MathHelper.floor_double(this.posZ)).getMaterial() == Material.lava)
{
this.motionY = 0.20000000298023224D;
this.motionX = (double)((this.rand.nextFloat() - this.rand.nextFloat()) * 0.2F);
this.motionZ = (double)((this.rand.nextFloat() - this.rand.nextFloat()) * 0.2F);
this.playSound("random.fizz", 0.4F, 2.0F + this.rand.nextFloat() * 0.4F);
}
this.func_145771_j(this.posX, (this.boundingBox.minY + this.boundingBox.maxY) / 2.0D, this.posZ);
double d0 = 8.0D;
if (this.xpTargetColor < this.xpColor - 20 + this.getEntityId() % 100)
{
if (this.closestPlayer == null || this.closestPlayer.getDistanceSqToEntity(this) > d0 * d0)
{
this.closestPlayer = this.worldObj.getClosestPlayerToEntity(this, d0);
}
this.xpTargetColor = this.xpColor;
}
if (this.closestPlayer != null)
{
double d1 = (this.closestPlayer.posX - this.posX) / d0;
double d2 = (this.closestPlayer.posY + (double)this.closestPlayer.getEyeHeight() - this.posY) / d0;
double d3 = (this.closestPlayer.posZ - this.posZ) / d0;
double d4 = Math.sqrt(d1 * d1 + d2 * d2 + d3 * d3);
double d5 = 1.0D - d4;
if (d5 > 0.0D)
{
d5 *= d5;
this.motionX += d1 / d4 * d5 * 0.1D;
this.motionY += d2 / d4 * d5 * 0.1D;
this.motionZ += d3 / d4 * d5 * 0.1D;
}
}
this.moveEntity(this.motionX, this.motionY, this.motionZ);
float f = 0.98F;
if (this.onGround)
{
f = this.worldObj.getBlock(MathHelper.floor_double(this.posX), MathHelper.floor_double(this.boundingBox.minY) - 1, MathHelper.floor_double(this.posZ)).slipperiness * 0.98F;
}
this.motionX *= (double)f;
this.motionY *= 0.9800000190734863D;
this.motionZ *= (double)f;
if (this.onGround)
{
this.motionY *= -0.8999999761581421D;
}
++this.xpColor;
++this.xpOrbAge;
if (this.xpOrbAge >= 6000)
{
this.setDead();
}
}
/**
* Returns if this entity is in water and will end up adding the waters velocity to the entity
*/
public boolean handleWaterMovement()
{
return this.worldObj.handleMaterialAcceleration(this.boundingBox, Material.water, this);
}
/**
* Will deal the specified amount of damage to the entity if the entity isn't immune to fire damage. Args:
* amountDamage
*/
protected void dealFireDamage(int p_70081_1_)
{
this.attackEntityFrom(DamageSource.inFire, (float)p_70081_1_);
}
/**
* Called when the entity is attacked.
*/
public boolean attackEntityFrom(DamageSource p_70097_1_, float p_70097_2_)
{
if (this.isEntityInvulnerable())
{
return false;
}
else
{
this.setBeenAttacked();
this.xpOrbHealth = (int)((float)this.xpOrbHealth - p_70097_2_);
if (this.xpOrbHealth <= 0)
{
this.setDead();
}
return false;
}
}
/**
* (abstract) Protected helper method to write subclass entity data to NBT.
*/
public void writeEntityToNBT(NBTTagCompound p_70014_1_)
{
p_70014_1_.setShort("Health", (short)((byte)this.xpOrbHealth));
p_70014_1_.setShort("Age", (short)this.xpOrbAge);
p_70014_1_.setShort("Value", (short)this.xpValue);
}
/**
* (abstract) Protected helper method to read subclass entity data from NBT.
*/
public void readEntityFromNBT(NBTTagCompound p_70037_1_)
{
this.xpOrbHealth = p_70037_1_.getShort("Health") & 255;
this.xpOrbAge = p_70037_1_.getShort("Age");
this.xpValue = p_70037_1_.getShort("Value");
}
/**
* Called by a player entity when they collide with an entity
*/
public void onCollideWithPlayer(EntityPlayer p_70100_1_)
{
if (!this.worldObj.isRemote)
{
if (this.field_70532_c == 0 && p_70100_1_.xpCooldown == 0)
{
if (MinecraftForge.EVENT_BUS.post(new PlayerPickupBoondollarEvent(p_70100_1_, this))) return;
p_70100_1_.xpCooldown = 2;
this.worldObj.playSoundAtEntity(p_70100_1_, "random.orb", 0.1F, 0.5F * ((this.rand.nextFloat() - this.rand.nextFloat()) * 0.7F + 1.8F));
p_70100_1_.onItemPickup(this, 1);
p_70100_1_.addExperience(this.xpValue);
this.setDead();
}
}
}
/**
* Returns the XP value of this XP orb.
*/
public int getXpValue()
{
return this.xpValue;
}
/**
* Returns a number from 1 to 10 based on how much XP this orb is worth. This is used by RenderXPOrb to determine
* what texture to use.
*/
@SideOnly(Side.CLIENT)
public int getTextureByXP(){
int returnxp = 0;
if(this.xpValue == 50){
FMLLog.info(""+this.xpValue);
returnxp = 4;
}else if(this.xpValue == 25){
FMLLog.info(""+this.xpValue);
returnxp = 3;
}else if(this.xpValue == 10){
FMLLog.info(""+this.xpValue);
returnxp = 2;
}else if(this.xpValue == 5){
FMLLog.info(""+this.xpValue);
returnxp = 1;
}else if(this.xpValue == 0){
FMLLog.info("Something is wrong here");
returnxp = 0;
}
return returnxp;
}
/**
* Get a fragment of the maximum experience points value for the supplied value of experience points value.
*/
public static int getXPSplit(int p_70527_0_)
{
return p_70527_0_ == 4 ? 4 : (p_70527_0_ == 3 ? 3 : (p_70527_0_ == 2 ? 2 : (p_70527_0_ == 1 ? 1 : 0)));
}
/**
* If returns false, the item will not inflict any damage against entities.
*/
public boolean canAttackWithItem()
{
return false;
}
}
RenderFile:
package dialgex.SburbCraft.Render;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.entity.Render;
import net.minecraft.entity.Entity;
import net.minecraft.util.MathHelper;
import net.minecraft.util.ResourceLocation;
import cpw.mods.fml.common.FMLLog;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;
import dialgex.SburbCraft.Entities.Boondollars.Boondollar;
@SideOnly(Side.CLIENT)
public class RenderBoondollar extends Render
{
private static final ResourceLocation BoondollarTextures = new ResourceLocation("sburbsurvival", "textures/entities/BoondollarTex.png");
private static final String __OBFID = "CL_00000993";
public RenderBoondollar()
{
this.shadowSize = 0.15F;
this.shadowOpaque = 0.75F;
}
/**
* Actually renders the given argument. This is a synthetic bridge method, always casting down its argument and then
* handing it off to a worker function which does the actual work. In all probabilty, the class Render is generic
* (Render<T extends Entity) and this method has signature public void func_76986_a(T entity, double d, double d1,
* double d2, float f, float f1). But JAD is pre 1.5 so doesn't do that.
*/
public void doRender(Boondollar p_76986_1_, double p_76986_2_, double p_76986_4_, double p_76986_6_, float p_76986_8_, float p_76986_9_)
{
GL11.glPushMatrix();
GL11.glTranslatef((float)p_76986_2_, (float)p_76986_4_, (float)p_76986_6_);
this.bindEntityTexture(p_76986_1_);
int i = p_76986_1_.getTextureByXP();
FMLLog.info("i = "+i);
float f2 = (float)(i * 64 + 0) / 256.0F;
float f3 = (float)(i * 64 + 64) / 256.0F;
float f4 = (float)(i * 256 + 0) / 256.0F;
float f5 = (float)(i * 256 + 256) / 256.0F;
float f6 = 1.0F;
float f7 = 0.5F;
float f8 = 0.25F;
int j = p_76986_1_.getBrightnessForRender(p_76986_9_);
int k = j % 65536;
int l = j / 65536;
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, (float)k / 1.0F, (float)l / 1.0F);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
float f10 = 255.0F;
float f11 = ((float)p_76986_1_.xpColor + p_76986_9_) / 2.0F;
l = (int)((MathHelper.sin(f11 + 0.0F) + 1.0F) * 0.5F * f10);
int i1 = (int)f10;
int j1 = (int)((MathHelper.sin(f11 + 4.1887903F) + 1.0F) * 0.1F * f10);
int k1 = l << 16 | i1 << 8 | j1;
GL11.glRotatef(180.0F - this.renderManager.playerViewY, 0.0F, 1.0F, 0.0F);
GL11.glRotatef(-this.renderManager.playerViewX, 1.0F, 0.0F, 0.0F);
float f9 = 0.9F;
GL11.glScalef(f9, f9, f9);
Tessellator tessellator = Tessellator.instance;
tessellator.startDrawingQuads();
tessellator.setColorRGBA_I(k1, 128);
tessellator.setNormal(0.0F, 1.0F, 0.0F);
tessellator.addVertexWithUV((double)(0.0F - f7), (double)(0.0F - f8), 0.0D, (double)f2, (double)f5);
tessellator.addVertexWithUV((double)(f6 - f7), (double)(0.0F - f8), 0.0D, (double)f3, (double)f5);
tessellator.addVertexWithUV((double)(f6 - f7), (double)(1.0F - f8), 0.0D, (double)f3, (double)f4);
tessellator.addVertexWithUV((double)(0.0F - f7), (double)(1.0F - f8), 0.0D, (double)f2, (double)f4);
tessellator.draw();
GL11.glDisable(GL11.GL_BLEND);
GL11.glDisable(GL12.GL_RESCALE_NORMAL);
GL11.glPopMatrix();
}
/**
* Returns the location of an entity's texture. Doesn't seem to be called unless you call Render.bindEntityTexture.
*/
protected ResourceLocation getEntityTexture(Boondollar p_110775_1_)
{
return BoondollarTextures;
}
/**
* Returns the location of an entity's texture. Doesn't seem to be called unless you call Render.bindEntityTexture.
*/
protected ResourceLocation getEntityTexture(Entity p_110775_1_)
{
return this.getEntityTexture((Boondollar)p_110775_1_);
}
/**
* Actually renders the given argument. This is a synthetic bridge method, always casting down its argument and then
* handing it off to a worker function which does the actual work. In all probability, the class Render is generic
* (Render<T extends Entity) and this method has signature public void func_76986_a(T entity, double d, double d1,
* double d2, float f, float f1). But JAD is pre 1.5 so doesn't do that.
*/
public void doRender(Entity p_76986_1_, double p_76986_2_, double p_76986_4_, double p_76986_6_, float p_76986_8_, float p_76986_9_)
{
this.doRender((Boondollar)p_76986_1_, p_76986_2_, p_76986_4_, p_76986_6_, p_76986_8_, p_76986_9_);
}
}
Can anyone please help out?
EDIT: Click here to get the results
教えて教えてよその仕組みを。
Event Handler
There are the vanilla XP orbs - surely that counts as something and it would pretty much be a copy/paste solution to your problem, or you could even implement them as items that drop.
Here's the DropEvent code:
The Entity file:
The Render file:
And the Crash report:
This is line 47:
So yeah, I'm at a loss of what I'm doing wrong...
@coolAlias Big thanks
Also moved the definition into the actual event.
Now it's spawning, but it's just spawning a white non-textured block, and I need to create the custom XP holder/HUD display for the player
EDIT: Here's the block
ClientProxy:
ModFile:
Also, you should only have ONE proxy instance, your CommonProxy, because ClientProxy extends it already:
Fixed, but Eclipse is saying that the method doesn't exist.
EDIT: Moved render register to Common and that fixed it, but now I'm just getting a cube that shifts colorsThat's because you have to have it in your CommonProxy class, too, but empty:
All the code and stuff is working flawlessly, but the texture I'm using is 64x64 and only a corner of it is showing up.
Any way I can resize the texture use?
That's caused by the render code you copied from RenderXPOrb - nothing wrong with that, but you'll have to tinker with the numbers to get the correct vertices and such for drawing with the tessellator, which will end up making your entity bigger, and then you have to scale it... depending on what your texture is supposed to look like, it might be easier using the standard Item render code (or EntityItem) rather than the xp orb render code.
I'm sure I can figure this one out on my own. Thanks for all the help thus far!
[PLACEHOLDER FOR END-RESULT CODE]
All the files and such are working flawlessly, but for some reason, the getTextureFromXP method isn't getting the xpValue, so the texture doesn't change in regards to the Renderer
DropEvent:
EntityFile (getTextureFromXp is here towards the bottom):
RenderFile:
Further help would be much appreciated
Can anyone at all help me out? (bump)Browser was being stupid and didn't update on refresh
Boondollars should really only have 4 values:
My problem is that it's spawning, and with the proper values, but the renderer isn't getting the values, and so it isn't using the right textures