Placing an item inside a block. (Showcase before 1.6.5)

Discussion in 'Plugin Development' started by Samkio, Oct 23, 2011.

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

    Samkio

    Grettings!
    I am currently working on a project that requires items to be placed in blocks.
    Well to be honest food inside microwaves:
    [​IMG]

    The Problem:
    • Food Jumps out of the block if a block nearby block is destroyed. (One of the 9 blocks it is sitting on).
    Teh Code:
    Code:
        public void setLocation(Location location) {
            location.add(0.5, 0, 0.5);
            this.location = location;
            item.teleport(location);
            item.setVelocity(new Vector(0, 0.1, 0));
        }
    
        public void respawn() {
            ItemStack stack = new ItemStack(item.getItemStack().getType());
            item = item.getLocation().getWorld().dropItemNaturally(location, stack);
            item.setVelocity(new Vector(0, 0.1, 0));
            updatedPosition = false;
        }
    
        public void updatePosition() {
            if (!updatedPosition) {
                item.teleport(location);
                item.setVelocity(new Vector(0, 0.1, 0));
                updatedPosition = true;
            }
        }
    setLocation is called when it is created.
    Then updatePosition is called shortly after and all works hunky dory.
    Then a block is destroyed and the item comes flying out :p
    I have also tried updatePosition when a block nearby is destroyed this dosn't work either.

    I have tried setting the bounding box to that of a half step.
    This works but the item jumps up and down as it is still a glass block.

    Any help will be appreciated!
    Regards
    Samkio
     
  2. As far as I remember, that issue is client-side. For a couple of updates, items inside of a block will automatically be assumed to be pushed out of that block.
    I don't know how the server currently handles items stuck in blocks by default, but the client will always render the item flying out of the block until it realizes that it isn't actually there.
     
  3. Offline

    Samkio

    @Bone008
    I see. That's a shame :/
    Thanks though :)
     
  4. Offline

    md_5

    hmm does @Afforess allow floating items inside blocks?
     
Thread Status:
Not open for further replies.

Share This Page