Before I start - I've spent a few days now looking at other peoples posts, but most seem to be related to rendering which I don't care about yet, are for older versions of minecraft, or when I try to use their solutions they don't work.
I've been working on the same mod (Tutorial Mod) for a long time so it could be a compounded error. Im planning to finish everything before moving the code to a new package with a better name (I haven't decided on the name yet)
I'm trying to create a railgun (currently works perfectly using arrows), and now I need a custom projectile for it - I've tried copying and modifying the arrow code many time but now I trying to at least start off with a projectile that extends EntityThrowable. I've put in basic code for the projectile and it should work.
But I've tried about 5 different ways (with many variations on each) of registering my entity and I can't get any of them to work. Every time I launch the game it crashes when it tries to register my entity.
Im currently using EntityRegistry.registerModEntity in my PreInit
Any help would be greatly appreciated, also - I'm relatively new in java but I do know other Object Oriented languages like PHP, JavaScript (I've previously been doing web design etc) and also OSX Application languages like Swift - so if its something really simple that you think I should know please point it out!
Code:
TutorialMod.java
package com.cadiboo.tutorial;
import com.cadiboo.tutorial.init.ModItems;
import com.cadiboo.tutorial.entities.EntityRailGunProjectile;
import com.cadiboo.tutorial.init.ModBlocks;
import com.cadiboo.tutorial.init.ModEntities;
import com.cadiboo.tutorial.proxy.CommonProxy;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.Instance;
import net.minecraftforge.fml.common.SidedProxy;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.registry.EntityRegistry;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
@Mod(modid = Reference.MOD_ID, name = Reference.MOD_NAME, version = Reference.MOD_VERSION, acceptedMinecraftVersions = Reference.ACCEPTED_VERSIONS)
public class TutorialMod {
@Instance
public static TutorialMod instance;
@SidedProxy(clientSide = Reference.CLIENT_PROXY_CLASS, serverSide = Reference.SERVER_PROXY_CLASS)
public static CommonProxy proxy;
@EventHandler
public void preInit(FMLPreInitializationEvent event)
{
System.out.println("Pre Init");
ModItems.init();
ModBlocks.init();
ModEntities.init();
ModItems.register();
ModBlocks.register();
ModEntities.register();
proxy.preInit();
}
@EventHandler
public void Init(FMLInitializationEvent event)
{
System.out.println("Init");
proxy.init();
}
@EventHandler
public void postInit(FMLPostInitializationEvent event)
{
System.out.println("Post Init");
}
}
Reference.java
package com.cadiboo.tutorial;
public class Reference {
public static final String MOD_ID = "tm";
public static final String MOD_NAME = "Tutorial Mod";
public static final String MOD_VERSION = "0.3";
public static final String ACCEPTED_VERSIONS = "[1.12.2]";
public static final String CLIENT_PROXY_CLASS = "com.cadiboo.tutorial.proxy.ClientProxy";
public static final String SERVER_PROXY_CLASS = "com.cadiboo.tutorial.proxy.ServerProxy";
public static enum TutorialBlocks
{
MORPH ("morph", "BlockMorph"),
BEND ("bend", "BlockBend");
private String unlocalizedName;
private String registryName;
TutorialBlocks(String unlocalizedName, String registryName)
{
this.unlocalizedName = unlocalizedName;
this.registryName = registryName;
}
public String getUnlocalizedName()
{
return unlocalizedName;
}
public String getRegistryName()
{
return registryName;
}
}
public static enum TutorialItems
{
CHEESE ("cheese", "ItemCheese"),
CRACKER ("cracker", "ItemCracker"),
JATZ ("jatz", "ItemJatz"),
RAILGUN ("railgun", "ItemRailGun");
private String unlocalizedName;
private String registryName;
TutorialItems(String unlocalizedName, String registryName)
{
this.unlocalizedName = unlocalizedName;
this.registryName = registryName;
}
public String getUnlocalizedName()
{
return unlocalizedName;
}
public String getRegistryName()
{
return registryName;
}
}
public static enum TutorialEntities
{
RAILGUNPROJECTILE ("railgunprojectile", "RailGunProjectile");
private String unlocalizedName;
private String registryName;
TutorialEntities(String unlocalizedName, String registryName)
{
this.unlocalizedName = unlocalizedName;
this.registryName = registryName;
}
public String getUnlocalizedName()
{
return unlocalizedName;
}
public String getRegistryName()
{
return registryName;
}
}
}
ModEntities.java
package com.cadiboo.tutorial.init;
import com.cadiboo.tutorial.Reference;
import com.cadiboo.tutorial.TutorialMod;
import com.cadiboo.tutorial.entities.EntityRailGunProjectile;
import net.minecraft.client.renderer.entity.Render;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.client.renderer.entity.RenderSnowball;
import net.minecraft.entity.Entity;
import net.minecraft.item.Item;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.client.registry.IRenderFactory;
import net.minecraftforge.fml.client.registry.RenderingRegistry;
import net.minecraftforge.fml.common.registry.EntityEntry;
import net.minecraftforge.fml.common.registry.EntityEntryBuilder;
import net.minecraftforge.fml.common.registry.EntityRegistry;
import net.minecraftforge.fml.common.registry.ForgeRegistries;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.fml.common.registry.EntityRegistry.EntityRegistration;
public class ModEntities {
//public static EntityEntry RailGunProjectile;
public static Entity RailGunProjectile;
/*public static class Factory implements IRenderFactory<EntityRailGunProjectile> {
@Override
public Render<? super EntityRailGunProjectile> createRenderFor(RenderManager manager) {
return new EntityRailGunProjectile(manager);
}*/
public static void init()
{
/*
//RailGunProjectile = new EntityRailGunProjectile();
ResourceLocation RailGunProjectile = new ResourceLocation(Reference.MOD_ID + ":" + "baconbullet" , "inventory");
// EntityHandler.registerModEntity(entitybaconres, EntityBacon.class, "entitybaconres", Bacon.instance, 16, 20, true);
EntityRegistry.registerModEntity(RailGunProjectile, EntityRailGunProjectile.class, "baconbullet", 1, Reference.MOD_ID, 128, 1, true);
RenderingRegistry.registerEntityRenderingHandler(EntityRailGunProjectile.class, new RenderSnowball(renderManagerIn, itemIn, itemRendererIn));
//RenderingRegistry.registerEntityRenderingHandler(EntityBacon.class, new RenderSnowball(ModItems.rawbacon ));
// }
*/
//RenderingRegistry.registerEntityRenderingHandler(EntityBacon.class, new RenderSnowball(ModItems.rawbacon ));
}
public static void register()
{
//ForgeRegistries.ENTITIES.register(RailGunProjectile);
/*EntityEntry entry = EntityEntryBuilder.create()
.entity(EntityRailGunProjectile.class)
.id(new ResourceLocation(null), ID++)
.name("my_entity")
.egg(0xFFFFFF, 0xAAAAAA)
.tracker(64, 20, false)
.build();
event.getRegistry().register(entry);*/
//EntityRegistry.registerModEntity(EntityRailGunProjectile.class, "RailGunProjectile", 0, this, 64, 10, true);
// increment the index for each entity you register
int modEntityIndex = 0;
//(registryName, entityClass, entityName, id, mod, trackingRange, updateFrequency, sendsVelocityUpdates);
// last 3 parameters are tracking range, tracking frequency, and whether to send tracking updates or not
// check the vanilla EntityList (I think) to find a similar entity class and use the same values
// in this case, throwable entities all use '64, 10, true' so I recommend you do the same
/**
* @param entityClass The entity class
* @param entityName A unique name for the entity
* @param id A mod specific ID for the entity
* @param mod The mod
* @param trackingRange The range at which MC will send tracking updates
* @param updateFrequency The frequency of tracking updates
* @param sendsVelocityUpdates Whether to send velocity information packets as well
*/
System.out.println("registering railgun Projectile entity");
//EntityRegistry.registerModEntity(registryName, entityClass, entityName, id, mod, trackingRange, updateFrequency, sendsVelocityUpdates);
//void doModEntityRegistration(ResourceLocation registryName, Class<? extends Entity> entityClass, String entityName, int id, Object mod, int trackingRange, int updateFrequency, boolean sendsVelocityUpdates)
//EntityRegistration er = new EntityRegistration(mc, registryName, entityClass, entityName, id, trackingRange, updateFrequency, sendsVelocityUpdates);
//current //EntityRegistry.registerModEntity(new ResourceLocation (Reference.MOD_ID + ":" + Reference.TutorialEntities.RAILGUNPROJECTILE.getRegistryName()), EntityRailGunProjectile.class, "Railgun Projectile", ++modEntityIndex, TutorialMod.class, 64, 10, true);
EntityRegistry.registerModEntity(
new ResourceLocation(Reference.MOD_ID, Reference.TutorialEntities.RAILGUNPROJECTILE.getRegistryName()),
EntityRailGunProjectile.class, Reference.MOD_ID + ":" + Reference.TutorialEntities.RAILGUNPROJECTILE.getRegistryName(),
++modEntityIndex,
TutorialMod.class,
64, 10, true);
System.out.println("railgun Projectile entity registered");
//EntityRegistry.registerModEntity(registryName, entityClass, entityName, id, mod, trackingRange, updateFrequency, sendsVelocityUpdates);
//EntityRegistry.registerModEntity(EntityRailGunProjectile.class, "Railgun Projectile", ++modEntityIndex, this, 64, 10, true);
}
public static void registerRenders()
{
/*registerRender(cheese);
registerRender(cracker);
registerRender(jatz);
registerRender(railGun);*/
registerRender();
System.out.println("railgun Projectile render registered");
}
private static void registerRender(/*Item item*/)
{
System.out.println("regisering railgun projectile render");
RenderingRegistry.registerEntityRenderingHandler(EntityRailGunProjectile.class, new RenderSnowball(null, ModItems.railGun, null ));
//Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item, 0, new ModelResourceLocation(item.getRegistryName(), "inventory"));
//System.out.println(item.getRegistryName());
}
}
EntityRailGunProjectile.java
package com.cadiboo.tutorial.entities;
import java.util.Random;
import com.cadiboo.tutorial.Reference;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.projectile.EntityThrowable;
import net.minecraft.util.DamageSource;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.World;
public class EntityRailGunProjectile extends EntityThrowable
{
public int projectile;
/*public int xTile = -1;
public int yTile = -1;
public int zTile = -1;
public Block inTile;*/
public int ticksInAir;
private double damage;
private int knockbackStrength;
public EntityRailGunProjectile(World worldIn)
{
super(worldIn);
//this.setSize(0.25F, 0.25F);
}
public EntityRailGunProjectile(World worldIn, EntityLivingBase throwerIn, int ebt)
{
super(worldIn, throwerIn);
projectile = ebt;
}
/**
* Sets the amount of knockback the arrow applies when it hits a mob.
*/
public void setKnockbackStrength(int knockbackStrengthIn)
{
this.knockbackStrength = knockbackStrengthIn;
}
/*@Override
protected void onImpact(RayTraceResult result) {
// TODO Auto-generated method stub
}*/
@Override
protected void onImpact(RayTraceResult result)
{
/*if (result.entityHit != null)
{
if (result.entityHit.isEntityAlive())
{
if (result.entityHit instanceof EntityLivingBase)
{
float x = 10F;
EntityLivingBase b = (EntityLivingBase)result.entityHit;
result.entityHit.setFire(7);
/*if (this.bolt == 0) result.entityHit.setFire(7);
else if (this.bolt == 2) b.addPotionEffect(new PotionEffect(Potion.weakness.getId(), 140, 1));
else if (this.bolt == 3) b.addPotionEffect(new PotionEffect(Potion.poison.getId(), 200, 0));
else if (this.bolt == 4)
{
x += 2F;
b.addPotionEffect(new PotionEffect(Potion.moveSlowdown.getId(), 160, 2));
}
else if (this.bolt == 5) b.addPotionEffect(new PotionEffect(Potion.confusion.getId(), 200, 2));
else if (this.bolt == 6)
{
x += 8F;
}*\/
b.attackEntityFrom(DamageSource.causeMobDamage(b), x);
}
}
}*/
}
public void setDamage(double damageIn)
{
this.damage = damageIn;
}
public double getDamage()
{
return this.damage;
}
@Override
protected float getGravityVelocity()
{
return 0.01F;
}
}
/*
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import java.util.List;
import javax.annotation.Nullable;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.IProjectile;
import net.minecraft.entity.MoverType;
import net.minecraft.entity.monster.EntityEnderman;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.projectile.EntityArrow;
import net.minecraft.init.Enchantments;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.datasync.DataParameter;
import net.minecraft.network.datasync.DataSerializers;
import net.minecraft.network.datasync.EntityDataManager;
import net.minecraft.network.play.server.SPacketChangeGameState;
import net.minecraft.util.DamageSource;
//import net.minecraft.util.EntityDamageSourceIndirect;
import net.minecraft.util.EntitySelectors;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.datafix.DataFixer;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import com.cadiboo.tutorial.ModDamageSources;
import com.cadiboo.tutorial.EntityDamageSourceRailGunProjectile;
public abstract class EntityRailGunProjectile extends Entity implements IProjectile
{
private static final Predicate<Entity> RAILGUNPROJECTILE_TARGETS = Predicates.and(EntitySelectors.NOT_SPECTATING, EntitySelectors.IS_ALIVE, new Predicate<Entity>()
{
public boolean apply(@Nullable Entity p_apply_1_)
{
return p_apply_1_.canBeCollidedWith();
}
});
private static final DataParameter<Byte> CRITICAL = EntityDataManager.<Byte>createKey(EntityRailGunProjectile.class, DataSerializers.BYTE);
private int xTile;
private int yTile;
private int zTile;
private Block inTile;
private int inData;
protected boolean inGround;
protected int timeInGround;
/** 1 if the player can pick up the arrow *\/
public EntityRailGunProjectile.PickupStatus pickupStatus;
/** Seems to be some sort of timer for animating an arrow. *\/
public int arrowShake;
/** The owner of this arrow. *\/
public Entity shootingEntity;
private int ticksInGround;
private int ticksInAir;
private double damage;
/** The amount of knockback an arrow applies when it hits a mob. *\/
private int knockbackStrength;
public EntityRailGunProjectile(World worldIn)
{
super(worldIn);
this.xTile = -1;
this.yTile = -1;
this.zTile = -1;
this.pickupStatus = EntityRailGunProjectile.PickupStatus.DISALLOWED;
this.damage = 2.0D;
this.setSize(0.5F, 0.5F);
}
public EntityRailGunProjectile(World worldIn, double x, double y, double z)
{
this(worldIn);
this.setPosition(x, y, z);
}
public EntityRailGunProjectile(World worldIn, EntityLivingBase shooter)
{
this(worldIn, shooter.posX, shooter.posY + (double)shooter.getEyeHeight() - 0.10000000149011612D, shooter.posZ);
this.shootingEntity = shooter;
if (shooter instanceof EntityPlayer)
{
this.pickupStatus = EntityRailGunProjectile.PickupStatus.ALLOWED;
}
}
/**
* Checks if the entity is in range to render.
*\/
@SideOnly(Side.CLIENT)
public boolean isInRangeToRenderDist(double distance)
{
double d0 = this.getEntityBoundingBox().getAverageEdgeLength() * 10.0D;
if (Double.isNaN(d0))
{
d0 = 1.0D;
}
d0 = d0 * 64.0D * getRenderDistanceWeight();
return distance < d0 * d0;
}
protected void entityInit()
{
this.dataManager.register(CRITICAL, Byte.valueOf((byte)0));
}
public void shoot(Entity shooter, float pitch, float yaw, float p_184547_4_, float velocity, float inaccuracy)
{
float f = -MathHelper.sin(yaw * 0.017453292F) * MathHelper.cos(pitch * 0.017453292F);
float f1 = -MathHelper.sin(pitch * 0.017453292F);
float f2 = MathHelper.cos(yaw * 0.017453292F) * MathHelper.cos(pitch * 0.017453292F);
this.shoot((double)f, (double)f1, (double)f2, velocity, inaccuracy);
this.motionX += shooter.motionX;
this.motionZ += shooter.motionZ;
/*if (!shooter.onGround)
{
this.motionY += shooter.motionY;
}*\/
}
/**
* Similar to setArrowHeading, it's point the throwable entity to a x, y, z direction.
*\/
public void shoot(double x, double y, double z, float velocity, float inaccuracy)
{
float f = MathHelper.sqrt(x * x + y * y + z * z);
x = x / (double)f;
y = y / (double)f;
z = z / (double)f;
x = x + this.rand.nextGaussian() * 0.007499999832361937D * (double)inaccuracy;
y = y + this.rand.nextGaussian() * 0.007499999832361937D * (double)inaccuracy;
z = z + this.rand.nextGaussian() * 0.007499999832361937D * (double)inaccuracy;
x = x * (double)velocity;
y = y * (double)velocity;
z = z * (double)velocity;
this.motionX = x;
this.motionY = y;
this.motionZ = z;
float f1 = MathHelper.sqrt(x * x + z * z);
this.rotationYaw = (float)(MathHelper.atan2(x, z) * (180D / Math.PI));
this.rotationPitch = (float)(MathHelper.atan2(y, (double)f1) * (180D / Math.PI));
this.prevRotationYaw = this.rotationYaw;
this.prevRotationPitch = this.rotationPitch;
this.ticksInGround = 0;
}
/**
* Set the position and rotation values directly without any clamping.
*\/
@SideOnly(Side.CLIENT)
public void setPositionAndRotationDirect(double x, double y, double z, float yaw, float pitch, int posRotationIncrements, boolean teleport)
{
this.setPosition(x, y, z);
this.setRotation(yaw, pitch);
}
/**
* Updates the entity motion clientside, called by packets from the server
*\/
@SideOnly(Side.CLIENT)
public void setVelocity(double x, double y, double z)
{
this.motionX = x;
this.motionY = y;
this.motionZ = z;
if (this.prevRotationPitch == 0.0F && this.prevRotationYaw == 0.0F)
{
float f = MathHelper.sqrt(x * x + z * z);
this.rotationPitch = (float)(MathHelper.atan2(y, (double)f) * (180D / Math.PI));
this.rotationYaw = (float)(MathHelper.atan2(x, z) * (180D / Math.PI));
this.prevRotationPitch = this.rotationPitch;
this.prevRotationYaw = this.rotationYaw;
this.setLocationAndAngles(this.posX, this.posY, this.posZ, this.rotationYaw, this.rotationPitch);
this.ticksInGround = 0;
}
}
/**
* Called to update the entity's position/logic.
*\/
public void onUpdate()
{
super.onUpdate();
if (this.prevRotationPitch == 0.0F && this.prevRotationYaw == 0.0F)
{
float f = MathHelper.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ);
this.rotationYaw = (float)(MathHelper.atan2(this.motionX, this.motionZ) * (180D / Math.PI));
this.rotationPitch = (float)(MathHelper.atan2(this.motionY, (double)f) * (180D / Math.PI));
this.prevRotationYaw = this.rotationYaw;
this.prevRotationPitch = this.rotationPitch;
}
BlockPos blockpos = new BlockPos(this.xTile, this.yTile, this.zTile);
IBlockState iblockstate = this.world.getBlockState(blockpos);
Block block = iblockstate.getBlock();
if (iblockstate.getMaterial() != Material.AIR)
{
AxisAlignedBB axisalignedbb = iblockstate.getCollisionBoundingBox(this.world, blockpos);
if (axisalignedbb != Block.NULL_AABB && axisalignedbb.offset(blockpos).contains(new Vec3d(this.posX, this.posY, this.posZ)))
{
this.inGround = true;
}
}
if (this.arrowShake > 0)
{
--this.arrowShake;
}
if (this.inGround)
{
int j = block.getMetaFromState(iblockstate);
if ((block != this.inTile || j != this.inData) && !this.world.collidesWithAnyBlock(this.getEntityBoundingBox().grow(0.05D)))
{
this.inGround = false;
this.motionX *= (double)(this.rand.nextFloat() * 0.2F);
this.motionY *= (double)(this.rand.nextFloat() * 0.2F);
this.motionZ *= (double)(this.rand.nextFloat() * 0.2F);
this.ticksInGround = 0;
this.ticksInAir = 0;
}
else
{
++this.ticksInGround;
if (this.ticksInGround >= 1200)
{
this.setDead();
}
}
++this.timeInGround;
}
else
{
this.timeInGround = 0;
++this.ticksInAir;
Vec3d vec3d1 = new Vec3d(this.posX, this.posY, this.posZ);
Vec3d vec3d = new Vec3d(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);
RayTraceResult raytraceresult = this.world.rayTraceBlocks(vec3d1, vec3d, false, true, false);
vec3d1 = new Vec3d(this.posX, this.posY, this.posZ);
vec3d = new Vec3d(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);
if (raytraceresult != null)
{
vec3d = new Vec3d(raytraceresult.hitVec.x, raytraceresult.hitVec.y, raytraceresult.hitVec.z);
}
Entity entity = this.findEntityOnPath(vec3d1, vec3d);
if (entity != null)
{
raytraceresult = new RayTraceResult(entity);
}
if (raytraceresult != null && raytraceresult.entityHit instanceof EntityPlayer)
{
EntityPlayer entityplayer = (EntityPlayer)raytraceresult.entityHit;
if (this.shootingEntity instanceof EntityPlayer && !((EntityPlayer)this.shootingEntity).canAttackPlayer(entityplayer))
{
raytraceresult = null;
}
}
if (raytraceresult != null && !net.minecraftforge.event.ForgeEventFactory.onProjectileImpact(this, raytraceresult))
{
this.onHit(raytraceresult);
}
if (this.getIsCritical())
{
for (int k = 0; k < 4; ++k)
{
this.world.spawnParticle(EnumParticleTypes.CRIT, this.posX + this.motionX * (double)k / 4.0D, this.posY + this.motionY * (double)k / 4.0D, this.posZ + this.motionZ * (double)k / 4.0D, -this.motionX, -this.motionY + 0.2D, -this.motionZ);
}
}
this.posX += this.motionX;
this.posY += this.motionY;
this.posZ += this.motionZ;
float f4 = MathHelper.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ);
this.rotationYaw = (float)(MathHelper.atan2(this.motionX, this.motionZ) * (180D / Math.PI));
for (this.rotationPitch = (float)(MathHelper.atan2(this.motionY, (double)f4) * (180D / Math.PI)); this.rotationPitch - this.prevRotationPitch < -180.0F; this.prevRotationPitch -= 360.0F)
{
;
}
while (this.rotationPitch - this.prevRotationPitch >= 180.0F)
{
this.prevRotationPitch += 360.0F;
}
while (this.rotationYaw - this.prevRotationYaw < -180.0F)
{
this.prevRotationYaw -= 360.0F;
}
while (this.rotationYaw - this.prevRotationYaw >= 180.0F)
{
this.prevRotationYaw += 360.0F;
}
this.rotationPitch = this.prevRotationPitch + (this.rotationPitch - this.prevRotationPitch) * 0.2F;
this.rotationYaw = this.prevRotationYaw + (this.rotationYaw - this.prevRotationYaw) * 0.2F;
float f1 = 0.99F;
float f2 = 0.05F;
if (this.isInWater())
{
for (int i = 0; i < 4; ++i)
{
float f3 = 0.25F;
this.world.spawnParticle(EnumParticleTypes.WATER_BUBBLE, this.posX - this.motionX * 0.25D, this.posY - this.motionY * 0.25D, this.posZ - this.motionZ * 0.25D, this.motionX, this.motionY, this.motionZ);
}
f1 = 0.6F;
}
if (this.isWet())
{
this.extinguish();
}
this.motionX *= (double)f1;
this.motionY *= (double)f1;
this.motionZ *= (double)f1;
if (!this.hasNoGravity())
{
this.motionY -= 0.05000000074505806D;
}
this.setPosition(this.posX, this.posY, this.posZ);
this.doBlockCollisions();
}
}
/**
* Called when the arrow hits a block or an entity
*\/
protected void onHit(RayTraceResult raytraceResultIn)
{
Entity entity = raytraceResultIn.entityHit;
if (entity != null)
{
float f = MathHelper.sqrt(this.motionX * this.motionX + this.motionY * this.motionY + this.motionZ * this.motionZ);
int i = MathHelper.ceil((double)f * this.damage);
if (this.getIsCritical())
{
i += this.rand.nextInt(i / 2 + 2);
}
EntityDamageSourceRailGunProjectile damagesource;
//return (new EntityDamageSourceIndirect("arrow", arrow, indirectEntityIn)).setProjectile();
//return (new EntityDamageSourceIndirect("arrow", arrow, indirectEntityIn)).setProjectile();
if (this.shootingEntity == null)
{
damagesource = EntityDamageSourceRailGunProjectile.causeRailGunProjectileDamage(this, this);
//damagesource = DamageSource.causeRailGunProjectileDamage(this, this);
}
else
{
damagesource = EntityDamageSourceRailGunProjectile.causeRailGunProjectileDamage(this, this.shootingEntity);
//damagesource = DamageSource.causeRailGunProjectileDamage(this, this.shootingEntity);
}
if (this.isBurning() && !(entity instanceof EntityEnderman))
{
entity.setFire(5);
}
if (entity.attackEntityFrom(damagesource, (float)i))
{
if (entity instanceof EntityLivingBase)
{
EntityLivingBase entitylivingbase = (EntityLivingBase)entity;
if (!this.world.isRemote)
{
entitylivingbase.setArrowCountInEntity(entitylivingbase.getArrowCountInEntity() + 1);
}
if (this.knockbackStrength > 0)
{
float f1 = MathHelper.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ);
if (f1 > 0.0F)
{
entitylivingbase.addVelocity(this.motionX * (double)this.knockbackStrength * 0.6000000238418579D / (double)f1, 0.1D, this.motionZ * (double)this.knockbackStrength * 0.6000000238418579D / (double)f1);
}
}
if (this.shootingEntity instanceof EntityLivingBase)
{
EnchantmentHelper.applyThornEnchantments(entitylivingbase, this.shootingEntity);
EnchantmentHelper.applyArthropodEnchantments((EntityLivingBase)this.shootingEntity, entitylivingbase);
}
this.arrowHit(entitylivingbase);
if (this.shootingEntity != null && entitylivingbase != this.shootingEntity && entitylivingbase instanceof EntityPlayer && this.shootingEntity instanceof EntityPlayerMP)
{
((EntityPlayerMP)this.shootingEntity).connection.sendPacket(new SPacketChangeGameState(6, 0.0F));
}
}
this.playSound(SoundEvents.ENTITY_ARROW_HIT, 1.0F, 1.2F / (this.rand.nextFloat() * 0.2F + 0.9F));
if (!(entity instanceof EntityEnderman))
{
this.setDead();
}
}
else
{
this.motionX *= -0.10000000149011612D;
this.motionY *= -0.10000000149011612D;
this.motionZ *= -0.10000000149011612D;
this.rotationYaw += 180.0F;
this.prevRotationYaw += 180.0F;
this.ticksInAir = 0;
if (!this.world.isRemote && this.motionX * this.motionX + this.motionY * this.motionY + this.motionZ * this.motionZ < 0.0010000000474974513D)
{
if (this.pickupStatus == EntityRailGunProjectile.PickupStatus.ALLOWED)
{
this.entityDropItem(this.getArrowStack(), 0.1F);
}
this.setDead();
}
}
}
else
{
BlockPos blockpos = raytraceResultIn.getBlockPos();
this.xTile = blockpos.getX();
this.yTile = blockpos.getY();
this.zTile = blockpos.getZ();
IBlockState iblockstate = this.world.getBlockState(blockpos);
this.inTile = iblockstate.getBlock();
this.inData = this.inTile.getMetaFromState(iblockstate);
this.motionX = (double)((float)(raytraceResultIn.hitVec.x - this.posX));
this.motionY = (double)((float)(raytraceResultIn.hitVec.y - this.posY));
this.motionZ = (double)((float)(raytraceResultIn.hitVec.z - this.posZ));
float f2 = MathHelper.sqrt(this.motionX * this.motionX + this.motionY * this.motionY + this.motionZ * this.motionZ);
this.posX -= this.motionX / (double)f2 * 0.05000000074505806D;
this.posY -= this.motionY / (double)f2 * 0.05000000074505806D;
this.posZ -= this.motionZ / (double)f2 * 0.05000000074505806D;
this.playSound(SoundEvents.ENTITY_ARROW_HIT, 1.0F, 1.2F / (this.rand.nextFloat() * 0.2F + 0.9F));
this.inGround = true;
this.arrowShake = 7;
this.setIsCritical(false);
if (iblockstate.getMaterial() != Material.AIR)
{
this.inTile.onEntityCollidedWithBlock(this.world, blockpos, iblockstate, this);
}
}
}
/**
* Tries to move the entity towards the specified location.
*\/
public void move(MoverType type, double x, double y, double z)
{
super.move(type, x, y, z);
if (this.inGround)
{
this.xTile = MathHelper.floor(this.posX);
this.yTile = MathHelper.floor(this.posY);
this.zTile = MathHelper.floor(this.posZ);
}
}
protected void arrowHit(EntityLivingBase living)
{
}
@Nullable
protected Entity findEntityOnPath(Vec3d start, Vec3d end)
{
Entity entity = null;
List<Entity> list = this.world.getEntitiesInAABBexcluding(this, this.getEntityBoundingBox().expand(this.motionX, this.motionY, this.motionZ).grow(1.0D), RAILGUNPROJECTILE_TARGETS);
double d0 = 0.0D;
for (int i = 0; i < list.size(); ++i)
{
Entity entity1 = list.get(i);
if (entity1 != this.shootingEntity || this.ticksInAir >= 5)
{
AxisAlignedBB axisalignedbb = entity1.getEntityBoundingBox().grow(0.30000001192092896D);
RayTraceResult raytraceresult = axisalignedbb.calculateIntercept(start, end);
if (raytraceresult != null)
{
double d1 = start.squareDistanceTo(raytraceresult.hitVec);
if (d1 < d0 || d0 == 0.0D)
{
entity = entity1;
d0 = d1;
}
}
}
}
return entity;
}
public static void registerFixesArrow(DataFixer fixer, String name)
{
}
public static void registerFixesArrow(DataFixer fixer)
{
registerFixesArrow(fixer, "Arrow");
}
/**
* (abstract) Protected helper method to write subclass entity data to NBT.
*\/
public void writeEntityToNBT(NBTTagCompound compound)
{
compound.setInteger("xTile", this.xTile);
compound.setInteger("yTile", this.yTile);
compound.setInteger("zTile", this.zTile);
compound.setShort("life", (short)this.ticksInGround);
ResourceLocation resourcelocation = Block.REGISTRY.getNameForObject(this.inTile);
compound.setString("inTile", resourcelocation == null ? "" : resourcelocation.toString());
compound.setByte("inData", (byte)this.inData);
compound.setByte("shake", (byte)this.arrowShake);
compound.setByte("inGround", (byte)(this.inGround ? 1 : 0));
compound.setByte("pickup", (byte)this.pickupStatus.ordinal());
compound.setDouble("damage", this.damage);
compound.setBoolean("crit", this.getIsCritical());
}
/**
* (abstract) Protected helper method to read subclass entity data from NBT.
*\/
public void readEntityFromNBT(NBTTagCompound compound)
{
this.xTile = compound.getInteger("xTile");
this.yTile = compound.getInteger("yTile");
this.zTile = compound.getInteger("zTile");
this.ticksInGround = compound.getShort("life");
if (compound.hasKey("inTile", 8))
{
this.inTile = Block.getBlockFromName(compound.getString("inTile"));
}
else
{
this.inTile = Block.getBlockById(compound.getByte("inTile") & 255);
}
this.inData = compound.getByte("inData") & 255;
this.arrowShake = compound.getByte("shake") & 255;
this.inGround = compound.getByte("inGround") == 1;
if (compound.hasKey("damage", 99))
{
this.damage = compound.getDouble("damage");
}
if (compound.hasKey("pickup", 99))
{
this.pickupStatus = EntityRailGunProjectile.PickupStatus.getByOrdinal(compound.getByte("pickup"));
}
else if (compound.hasKey("player", 99))
{
this.pickupStatus = compound.getBoolean("player") ? EntityRailGunProjectile.PickupStatus.ALLOWED : EntityRailGunProjectile.PickupStatus.DISALLOWED;
}
this.setIsCritical(compound.getBoolean("crit"));
}
/**
* Called by a player entity when they collide with an entity
*\/
public void onCollideWithPlayer(EntityPlayer entityIn)
{
if (!this.world.isRemote && this.inGround && this.arrowShake <= 0)
{
boolean flag = this.pickupStatus == EntityRailGunProjectile.PickupStatus.ALLOWED || this.pickupStatus == EntityRailGunProjectile.PickupStatus.CREATIVE_ONLY && entityIn.capabilities.isCreativeMode;
if (this.pickupStatus == EntityRailGunProjectile.PickupStatus.ALLOWED && !entityIn.inventory.addItemStackToInventory(this.getArrowStack()))
{
flag = false;
}
if (flag)
{
entityIn.onItemPickup(this, 1);
this.setDead();
}
}
}
protected abstract ItemStack getArrowStack();
/**
* 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 setDamage(double damageIn)
{
this.damage = damageIn;
}
public double getDamage()
{
return this.damage;
}
/**
* Sets the amount of knockback the arrow applies when it hits a mob.
*\/
public void setKnockbackStrength(int knockbackStrengthIn)
{
this.knockbackStrength = knockbackStrengthIn;
}
/**
* Returns true if it's possible to attack this entity with an item.
*\/
public boolean canBeAttackedWithItem()
{
return false;
}
public float getEyeHeight()
{
return 0.0F;
}
/**
* Whether the arrow has a stream of critical hit particles flying behind it.
*\/
public void setIsCritical(boolean critical)
{
byte b0 = ((Byte)this.dataManager.get(CRITICAL)).byteValue();
if (critical)
{
this.dataManager.set(CRITICAL, Byte.valueOf((byte)(b0 | 1)));
}
else
{
this.dataManager.set(CRITICAL, Byte.valueOf((byte)(b0 & -2)));
}
}
/**
* Whether the arrow has a stream of critical hit particles flying behind it.
*\/
public boolean getIsCritical()
{
byte b0 = ((Byte)this.dataManager.get(CRITICAL)).byteValue();
return (b0 & 1) != 0;
}
public void setEnchantmentEffectsFromEntity(EntityLivingBase p_190547_1_, float p_190547_2_)
{
int i = EnchantmentHelper.getMaxEnchantmentLevel(Enchantments.POWER, p_190547_1_);
int j = EnchantmentHelper.getMaxEnchantmentLevel(Enchantments.PUNCH, p_190547_1_);
this.setDamage((double)(p_190547_2_ * 2.0F) + this.rand.nextGaussian() * 0.25D + (double)((float)this.world.getDifficulty().getDifficultyId() * 0.11F));
if (i > 0)
{
this.setDamage(this.getDamage() + (double)i * 0.5D + 0.5D);
}
if (j > 0)
{
this.setKnockbackStrength(j);
}
if (EnchantmentHelper.getMaxEnchantmentLevel(Enchantments.FLAME, p_190547_1_) > 0)
{
this.setFire(100);
}
}
public static enum PickupStatus
{
DISALLOWED,
ALLOWED,
CREATIVE_ONLY;
public static EntityRailGunProjectile.PickupStatus getByOrdinal(int ordinal)
{
if (ordinal < 0 || ordinal > values().length)
{
ordinal = 0;
}
return values()[ordinal];
}
}
}
*/
Also my rendering class though it does nothing
RenderRailGunProjectile.Java
package com.cadiboo.tutorial.renderer;
import net.minecraft.client.renderer.RenderItem;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.client.renderer.entity.RenderSnowball;
import net.minecraft.entity.Entity;
import net.minecraft.item.Item;
public class RenderRailGunProjectile extends RenderSnowball<Entity>{
public RenderRailGunProjectile(RenderManager renderManagerIn, Item itemIn, RenderItem itemRendererIn) {
super(renderManagerIn, itemIn, itemRendererIn);
// TODO Auto-generated constructor stub
}
}
Probably should have put this at the top, my Crash Report - note that it crashes when registering the projectile
----- skipped the forge initialization and everything going smoothly ----------------
[17:39:09] [main/INFO] [STDOUT]: [com.cadiboo.tutorial.init.ModBlocks:register:32]: Registered All Blocks
[17:39:09] [main/INFO] [STDOUT]: [com.cadiboo.tutorial.init.ModEntities:register:75]: registering railgun Projectile entity
[17:39:09] [main/INFO] [FML]: Applying holder lookups
[17:39:09] [main/INFO] [FML]: Holder lookups applied
[17:39:09] [main/INFO] [FML]: Applying holder lookups
[17:39:09] [main/INFO] [FML]: Holder lookups applied
[17:39:09] [main/INFO] [FML]: Applying holder lookups
[17:39:09] [main/INFO] [FML]: Holder lookups applied
[17:39:09] [main/INFO] [FML]: Applying holder lookups
[17:39:09] [main/INFO] [FML]: Holder lookups applied
[17:39:09] [main/INFO] [FML]: Injecting itemstacks
[17:39:09] [main/INFO] [FML]: Itemstack injection complete
[17:39:09] [main/FATAL] [FML]: Fatal errors were detected during the transition from PREINITIALIZATION to INITIALIZATION. Loading cannot continue
[17:39:09] [main/FATAL] [FML]:
States: 'U' = Unloaded 'L' = Loaded 'C' = Constructed 'H' = Pre-initialized 'I' = Initialized 'J' = Post-initialized 'A' = Available 'D' = Disabled 'E' = Errored
| State | ID | Version | Source | Signature |
|:----- |:--------- |:------------ |:-------------------------------- |:--------- |
| UCH | minecraft | 1.12.2 | minecraft.jar | None |
| UCH | mcp | 9.42 | minecraft.jar | None |
| UCH | FML | 8.0.99.99 | forgeSrc-1.12.2-14.23.0.2550.jar | None |
| UCH | forge | 14.23.0.2550 | forgeSrc-1.12.2-14.23.0.2550.jar | None |
| UCE | tm | 0.3 | bin | None |
[17:39:09] [main/FATAL] [FML]: The following problems were captured during this phase
[17:39:09] [main/ERROR] [FML]: Caught exception from tm (java.lang.NullPointerException)
[17:39:09] [main/INFO] [STDOUT]: [net.minecraft.init.Bootstrap:printToSYSOUT:630]: ---- Minecraft Crash Report ----
// Don't be sad. I'll do better next time, I promise!
Time: 2/12/18 5:39 PM
Description: There was a severe problem during mod loading that has caused the game to fail
net.minecraftforge.fml.common.LoaderExceptionModCrash: Caught exception from Tutorial Mod (tm)
Caused by: java.lang.NullPointerException
at net.minecraftforge.fml.common.registry.EntityRegistry.doModEntityRegistration(EntityRegistry.java:185)
at net.minecraftforge.fml.common.registry.EntityRegistry.registerModEntity(EntityRegistry.java:151)
at com.cadiboo.tutorial.init.ModEntities.register(ModEntities.java:81)
at com.cadiboo.tutorial.TutorialMod.preInit(TutorialMod.java:39)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at net.minecraftforge.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:608)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.google.common.eventbus.Subscriber.invokeSubscriberMethod(Subscriber.java:91)
at com.google.common.eventbus.Subscriber$SynchronizedSubscriber.invokeSubscriberMethod(Subscriber.java:150)
at com.google.common.eventbus.Subscriber$1.run(Subscriber.java:76)
at com.google.common.util.concurrent.MoreExecutors$DirectExecutor.execute(MoreExecutors.java:399)
at com.google.common.eventbus.Subscriber.dispatchEvent(Subscriber.java:71)
at com.google.common.eventbus.Dispatcher$PerThreadQueuedDispatcher.dispatch(Dispatcher.java:116)
at com.google.common.eventbus.EventBus.post(EventBus.java:217)
at net.minecraftforge.fml.common.LoadController.sendEventToModContainer(LoadController.java:253)
at net.minecraftforge.fml.common.LoadController.propogateStateMessage(LoadController.java:231)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.google.common.eventbus.Subscriber.invokeSubscriberMethod(Subscriber.java:91)
at com.google.common.eventbus.Subscriber$SynchronizedSubscriber.invokeSubscriberMethod(Subscriber.java:150)
at com.google.common.eventbus.Subscriber$1.run(Subscriber.java:76)
at com.google.common.util.concurrent.MoreExecutors$DirectExecutor.execute(MoreExecutors.java:399)
at com.google.common.eventbus.Subscriber.dispatchEvent(Subscriber.java:71)
at com.google.common.eventbus.Dispatcher$PerThreadQueuedDispatcher.dispatch(Dispatcher.java:116)
at com.google.common.eventbus.EventBus.post(EventBus.java:217)
at net.minecraftforge.fml.common.LoadController.distributeStateMessage(LoadController.java:148)
at net.minecraftforge.fml.common.Loader.preinitializeMods(Loader.java:602)
at net.minecraftforge.fml.client.FMLClientHandler.beginMinecraftLoading(FMLClientHandler.java:270)
at net.minecraft.client.Minecraft.init(Minecraft.java:513)
at net.minecraft.client.Minecraft.run(Minecraft.java:421)
at net.minecraft.client.main.Main.main(Main.java:118)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97)
at GradleStart.main(GradleStart.java:26)
A detailed walkthrough of the error, its code path and all known details is as follows:
---------------------------------------------------------------------------------------
-- System Details --
Details:
Minecraft Version: 1.12.2
Operating System: Mac OS X (x86_64) version 10.13.3
Java Version: 1.8.0_151, Oracle Corporation
Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
Memory: 814403320 bytes (776 MB) / 1038876672 bytes (990 MB) up to 2112618496 bytes (2014 MB)
JVM Flags: 3 total; -Xincgc -Xmx2048M -Xms1024M
IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0
FML: MCP 9.42 Powered by Forge 14.23.0.2550 5 mods loaded, 5 mods active
States: 'U' = Unloaded 'L' = Loaded 'C' = Constructed 'H' = Pre-initialized 'I' = Initialized 'J' = Post-initialized 'A' = Available 'D' = Disabled 'E' = Errored
| State | ID | Version | Source | Signature |
|:----- |:--------- |:------------ |:-------------------------------- |:--------- |
| UCH | minecraft | 1.12.2 | minecraft.jar | None |
| UCH | mcp | 9.42 | minecraft.jar | None |
| UCH | FML | 8.0.99.99 | forgeSrc-1.12.2-14.23.0.2550.jar | None |
| UCH | forge | 14.23.0.2550 | forgeSrc-1.12.2-14.23.0.2550.jar | None |
| UCE | tm | 0.3 | bin | None |
Loaded coremods (and transformers):
GL info: ' Vendor: 'Intel Inc.' Version: '2.1 INTEL-10.30.14' Renderer: 'Intel Iris OpenGL Engine'
[17:39:09] [main/INFO] [STDOUT]: [net.minecraft.init.Bootstrap:printToSYSOUT:630]: #@!@# Game crashed! Crash report saved to: #@!@# /Users