//MainModFile.class @SidedProxy(clientSide="mod.proxy.ClientProxy", serverSide="mod.proxy.ServerProxy") public static CommonProxy proxy; @EventHandler public void init(FMLInitializationEvent event) { proxy.init(); } //CommonProxy.class public void init() { EntityRegistry.registerModEntity(EntityRopeKnot.class, "rope", 1, Mod.instance, 160, Integer.MAX_VALUE, false); } //ClientProxy.class //This extends CommonProxy.class public void init() { super.init(); RenderingRegistry.registerEntityRenderingHandler(EntityRopeKnot.class, new RenderRopeKnot()); } //ItemRope.class public class ItemRope extends Item { public ItemRope(String name) { this.setUnlocalizedName(Mod.MODID + "." + name); this.setCreativeTab(Mod.creativeTab); } @Override public boolean onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ) { Block block = worldIn.getBlockState(pos).getBlock(); if (block instanceof BlockFence) { if (worldIn.isRemote) { return true; } else { return attach(playerIn, worldIn, pos); } } else { return false; } } //checks if the fence already has a rope or leash attached to it private boolean attach(EntityPlayer player, World worldIn, BlockPos fence) { EntityLeashKnot leash = EntityLeashKnot.getKnotForPosition(worldIn, fence); EntityRopeKnot rope = EntityRopeKnot.getKnotForPosition(worldIn, fence); if (leash == null && rope == null) { rope = EntityRopeKnot.createKnot(worldIn, fence); return true; } return false; } } //EntityRopeKnot.class //Direct copy (+minor changes such as renaming etc.) of the EntityLeashKnot.class //The System.out.println("here") on onUpdate() is being called, meaning that the entity spawned. public class EntityRopeKnot extends EntityHanging { public EntityRopeKnot(World worldIn) { super(worldIn); } public EntityRopeKnot(World worldIn, BlockPos pos) { super(worldIn, pos); this.setPosition((double)pos.getX() + 0.5D, (double)pos.getY() + 0.5D, (double)pos.getZ() + 0.5D); float f = 0.125F; float f1 = 0.1875F; float f2 = 0.25F; this.setEntityBoundingBox(new AxisAlignedBB(this.posX - 0.1875D, this.posY - 0.25D + 0.125D, this.posZ - 0.1875D, this.posX + 0.1875D, this.posY + 0.25D + 0.125D, this.posZ + 0.1875D)); } @Override public void onUpdate() { super.onUpdate(); System.out.println("here"); } @Override protected void entityInit() { super.entityInit(); } @Override public void func_174859_a(EnumFacing enumfacing) {} @Override public int getWidthPixels() { return 9; } @Override public int getHeightPixels() { return 9; } @Override public float getEyeHeight() { return -0.0625F; } @Override @SideOnly(Side.CLIENT) public boolean isInRangeToRenderDist(double distance) { return distance < 1024.0D; } @Override public void onBroken(Entity entity) {} @Override public boolean writeToNBTOptional(NBTTagCompound tagCompund) { return false; } @Override public void writeEntityToNBT(NBTTagCompound tagCompound) {} @Override public void readEntityFromNBT(NBTTagCompound tagCompund) {} //Todo later //@Override //public boolean interactFirst(EntityPlayer playerIn) //{ // if (!this.worldObj.isRemote) // { // System.out.println("dead"); // this.setDead(); // this.dropItem(Mod.ropeItem, 1); // } // // return true; //} @Override public boolean onValidSurface() { return this.worldObj.getBlockState(this.hangingPosition).getBlock() instanceof BlockFence; } public static EntityRopeKnot createKnot(World worldIn, BlockPos fence) { EntityRopeKnot entityropeknot = new EntityRopeKnot(worldIn, fence); entityropeknot.forceSpawn = true; System.out.println("spawn"); worldIn.spawnEntityInWorld(entityropeknot); return entityropeknot; } public static EntityRopeKnot getKnotForPosition(World worldIn, BlockPos pos) { int i = pos.getX(); int j = pos.getY(); int k = pos.getZ(); List list = worldIn.getEntitiesWithinAABB(EntityRopeKnot.class, new AxisAlignedBB((double)i - 1.0D, (double)j - 1.0D, (double)k - 1.0D, (double)i + 1.0D, (double)j + 1.0D, (double)k + 1.0D)); Iterator iterator = list.iterator(); EntityRopeKnot entityropeknot; do { if (!iterator.hasNext()) { return null; } entityropeknot = (EntityRopeKnot)iterator.next(); } while (!entityropeknot.func_174857_n().equals(pos)); return entityropeknot; } } //RenderRopeKnot.class //Again, a direct copy of RenderLeashKnot.class (just changed names and stuff) //Take a look at doRender(args). //The System.out.println("render"); never gets called. @SideOnly(Side.CLIENT) public class RenderRopeKnot extends Render { private static final ResourceLocation TEXTURE = new ResourceLocation(Mod.MODID, "textures/entity/rope_knot.png"); private ModelRopeKnot MODEL = new ModelRopeKnot(); public RenderRopeKnot() { super(Minecraft.getMinecraft().getRenderManager()); } private void render(EntityRopeKnot entityropeknot, double x, double y, double z, float f, float partialTicks) { GlStateManager.pushMatrix(); GlStateManager.disableCull(); GlStateManager.translate((float)x, (float)y, (float)z); float f2 = 0.0625F; GlStateManager.enableRescaleNormal(); GlStateManager.scale(-1.0F, -1.0F, 1.0F); GlStateManager.enableAlpha(); this.bindEntityTexture(entityropeknot); this.MODEL.render(entityropeknot, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, f2); GlStateManager.popMatrix(); super.doRender(entityropeknot, x, y, z, f, partialTicks); } protected ResourceLocation getEntityTexture(EntityRopeKnot entity) { return TEXTURE; } @Override protected ResourceLocation getEntityTexture(Entity entity) { return this.getEntityTexture((EntityRopeKnot)entity); } @Override public void doRender(Entity entity, double x, double y, double z, float f, float partialTicks) { System.out.println("render"); this.render((EntityRopeKnot)entity, x, y, z, f, partialTicks); } } //ModelRopeKnot.class //Yet another direct copy of ModelLeashKnot.class (just changed names and stuff) @SideOnly(Side.CLIENT) public class ModelRopeKnot extends ModelBase { public ModelRenderer MODEL_RENDERER; public ModelRopeKnot() { this(0, 0, 32, 32); } public ModelRopeKnot(int u1, int v1, int u2, int v2) { this.textureWidth = u2; this.textureHeight = v2; this.MODEL_RENDERER = new ModelRenderer(this, u1, v1); this.MODEL_RENDERER.addBox(-3.0F, -6.0F, -3.0F, 6, 8, 6, 0.0F); this.MODEL_RENDERER.setRotationPoint(0.0F, 0.0F, 0.0F); } @Override public void render(Entity entity, float f1, float f2, float f3, float f4, float f5, float f6) { this.setRotationAngles(f1, f2, f3, f4, f5, f6, entity); this.MODEL_RENDERER.render(f6); } @Override public void setRotationAngles(float f, float f1, float f2, float f3, float f4, float f5, Entity entity) { super.setRotationAngles(f, f1, f2, f3, f4, f5, entity); this.MODEL_RENDERER.rotateAngleY = f3 / (180F / (float)Math.PI); this.MODEL_RENDERER.rotateAngleX = f4 / (180F / (float)Math.PI); } }