How to throw web then make it turn solid

Discussion in 'Plugin Development' started by Michiman, Jul 5, 2015.

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

    Michiman

    I am trying to make it so when someone left clicks it will throw the web in your hand. Then when it hits the ground it turns into a solid web. I made something but when you throw the block it doesn't go were i want it. I want it to go were your looking but if its to far forward without hitting anything then it goes down.
     
  2. Offline

    Creeperzombi3

  3. Offline

    Michiman

    But when the Y is set to 1 it like launches into the air. im trying to get it to launch at the crosshairs. But for the solid web part i do not know how to make it solid

    Code:
    public void onInteract(PlayerInteractEvent event){
        Action a = event.getAction();
        if(a.equals(Action.LEFT_CLICK_AIR)){
            Player p = event.getPlayer();
            ItemStack thrown = p.getItemInHand();
            if(thrown==null) return;
            p.getInventory().remove(thrown);
            Item dropped = p.getWorld().dropItem(p.getLocation(), thrown);
            dropped.setVelocity(p.getLocation().getDirection().setY(1).multiply(1));
     
  4. Offline

    Creeperzombi3

    @Michiman
    I did
    Code:
    public void onInteract(PlayerInteractEvent event) {
            Action a = event.getAction();
            if(a.equals(Action.LEFT_CLICK_AIR)) {
                Player p = event.getPlayer();
                ItemStack thrown = new ItemStack(p.getItemInHand().getType(), 1);
                ItemStack item = p.getItemInHand();
                Material m = thrown.getType();
                int amount = p.getItemInHand().getAmount();
                p.getInventory().remove(item);
                p.getInventory().addItem(new ItemStack(m, amount - 1));
                Item dropped = p.getWorld().dropItem(p.getLocation(), thrown);
                dropped.setVelocity(p.getLocation().getDirection().setY(0.2).multiply(1.8));
            }
        }
    This part is so is only takes 1 of the item ->
    Code:
    Material m = thrown.getType();
    int amount = thrown.getAmount();
    p.getInventory().addItem(new ItemStack(m, amount - 1));
     
    Last edited: Jul 5, 2015
  5. Offline

    Michiman

    Ok Thanks! How do i make it though so it just takes a Web and not other blocks?
     
  6. Offline

    Creeperzombi3

    @Michiman
    I updated the code above because it had a small bug in it and for that, just do
    Code:
    if(m == Material.WEB)
     
  7. Offline

    Michiman

    ok Thanks dude you have been a big help. This may be a lot to ask but do you know how to make the webs solid when they hit the ground?

    Does anyone know how to make it a solid web once it hits the ground? The code works except when you throw it it goes a little weird but that should be easy to fix. Now i just need to it turn to a solid block in the area the web lands.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 12, 2016
Thread Status:
Not open for further replies.

Share This Page