detect paintings

Discussion in 'Plugin Development' started by asdaarg, Mar 20, 2011.

Thread Status:
Not open for further replies.
  1. Offline

    asdaarg

    How do I know whether there is a painting on a block or alternatively how can I detect a painting dropping?
    TIA
     
  2. Offline

    Edward Hand

    Paintings are a pain (as I discovered when making my PaintingSwitch plugin). They're entity not blocks so dont trigger block events, and they're not living entities so don't trigger the entity events.
    With some (rather advanced) minecraft hackery you can search for all paintings within an area. The principals are the same as I layed out in this thread:
    http://forums.bukkit.org/threads/monsters-in-an-area.7386/
     
  3. Offline

    asdaarg

    Awesome stuff. I was thinking about going through the whole entities list at first as a last resort, but this seems like a lot more efficient way of finding it. Thanks a bunch.
    Edit: I had a look at the craftbukkit code and looks like it doesn't actually have the entities but in a list in the first place, so its not like it speeds up anything. Nonetheless I would never had gotten the blocks on which paintings are without the minecraft hackery you taught me here. But it was very tricky to get them since they behave differently in each direction, so in case anyone is interested in the result of my minecraft hackery:
    Code:
    			CraftWorld craftWorld = (CraftWorld)w;
    			bb= AxisAlignedBB.a((double)ns.xs,(double)ns.ys,(double)ns.zs,(double)ns.xl,(double)ns.yl,(double)ns.zl);
    			List entities = craftWorld.getHandle().b(null, bb);
    
    			for(Object o:entities){
    				if (o instanceof EntityPainting){
    					EntityPainting p=(EntityPainting)o;
    					AxisAlignedBB pbb=p.boundingBox;
    					int px=p.b;//block its on
    					int py=p.c;
    					int pz=p.d;
    					int sx=Math.max(1,(int)(pbb.d-pbb.a+0.1));//size
    					int sy=Math.max(1,(int)(pbb.e-pbb.b+0.1));
    					int sz=Math.max(1,(int)(pbb.f-pbb.c+0.1));
    					int xmin,ymin=py,zmin,xmax,ymax=py+sy,zmax;
    					switch(p.a){//direction
    						case 1:
    							zmin=pz;
    							zmax=pz+sz;
    							xmax=1+(xmin=px-1);
    							break;
    						case 2:
    							xmin=px;
    							xmax=px+sx;
    							zmax=(zmin=pz+1)+1;
    							break;
    						case 3:
    							zmin=(zmax=pz+1)-sz;
    							xmax=(xmin=px+1)+1;
    							break;
    						default:
    							xmin=(xmax=px+1)-sx;
    							zmax=1+(zmin=pz-1);
    					}
    
    					for(int x=xmin;x<xmax;x++)
    						for(int y=ymin;y<ymax;y++)
    							for(int z=zmin;z<zmax;z++)
    								paintingBlocks.add(w.getBlockAt(x,y,z));
    				}
    			}
    
     
  4. Offline

    crowebird

    Nice work!
     
  5. Offline

    Edward Hand

    It's actually slightly more efficient than craftbukkit will let you do. It doesn't search the whole entities list. The server keeps separate lists of entities for each chunk. The search only searches through chunks in which the bounding box lies, making it far better than searching every single entity on the server.

    But you are right. Paintings are a pain.
     
  6. Offline

    asdaarg

    That's good to hear, I can already feel my painting handler is speeding up now. Anyways thanks again.
     
Thread Status:
Not open for further replies.

Share This Page