Making torches stick to air

Discussion in 'Plugin Development' started by mjmr89, Jan 31, 2011.

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

    mjmr89

    Hi guys, I've been working on a simple plugin that allows users to place torches on things like fences and glass. I was excited when it worked... When the torch block was touching something that it could normally attach onto. It LOOKED like it was attached to the glass or whatever (because I changed the data for it) but if I took away that non glass/fence block, it would pop off into item form. Is there any way to prevent this? I know it has to do with the Attachable implementation, but I'm not sure how to go about bypassing it if I can at all. Anyone have any ideas?
     
  2. Offline

    Raphfrk

    Hmm, what is probably happening is that when you break a block it checks for torches in any adjacent blocks. The causes the game to "notice" that the torch shouldn't work.

    Maybe one of the ON_PHYSICS hooks might trigger when you remove a block. However, my understanding is that it isn't possible to make torches stick to glass.
     
  3. Offline

    mjmr89

    I forgot to add something in the first post... Whenever I try to attach it to glass or a fence, with no normal attachable block around, it just spits out a torch item as well. So while I think that may be whats happening when I destroy a block around it, it also checks right when I place it somehow. Maybe cancelling the event after I'm done? I'll go check.

    Eh, I've never cancelled an event before, how do I do it? I expected there to be some method in the event, but I can't find it.
     
  4. Offline

    JoeMaximum

    event.setCancelled(true);
     
  5. Offline

    mjmr89

    Tried that, I think its because, for whatever reason, BlockRightClickEvent isn't cancellable, its not even in the javadocs.
     
  6. Offline

    JoeMaximum

    yeah, BlockRightClickEvent doesnt seem to be cancellable ..

    Maybe you could achieve what you want with the OnPlayerItem event ... not sure.
     
  7. Offline

    mjmr89

    I just tested it, and it doesnt seem like trying to place a torch triggers that event :(
     
  8. Offline

    sk89q

    It should be the "can build" event.
     
  9. Offline

    mjmr89

    Sounds simple enough, but when I try it it doesn't seem to work with this code in the block listener:
    Code:
    @Override
        public void onBlockCanBuild(BlockCanBuildEvent e){
        	debug("Block: " + e.getBlock().getType());
        	debug("Material: " + e.getMaterial());
        	debug("Buildable? " + e.isBuildable());
        	debug("----------");
        	if(!e.isBuildable()){
        		e.setBuildable(true);
        	}
        }
    
    The debug lines work fine. If I try to place it on something like a fence with no block beneath or to its sides (otherwise unplacable), it spits out:
    Block: FENCE
    Material: TORCH
    Buildable? FALSE
    ----------

    And doesn't show up in any form :( Am I missing something here?
     
  10. Offline

    Schirf

    sk89q, before you fixed the extended data (orientation) in WorldEdit, would a rotation leave the torch hanging in the air? I know that MCEdit does.
     
Thread Status:
Not open for further replies.

Share This Page