Library MiniBlocks (1.3.5)

Discussion in 'Resources' started by _Ug, Dec 28, 2015.

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

    _Ug

    MINI-BLOCKS v1.3.6:

    [​IMG]

    What is this?

    Ever wanted small or tiny items lying on the ground? Or lesser sized blocks to add more custom designs to your plug-in? This is for you. This is a very simple way to add tiny items to your server that people can walk right though! There are endless uses for this. For example, I just made a stop light plug-in with this library. The possibilities are only limited to that of your imagination.

    Code:
    Code:
    package libs;
    import org.bukkit.*;
    import org.bukkit.entity.*;
    import org.bukkit.inventory.*;
    import org.bukkit.util.*;
    public class MiniBlock {
     
        /**
         * MiniBlock
         *
         * @version 1.3.6
         * @author _Ug
         *
         * No credit is needed. ;)
         */
     
        private Location location;
     
        private ItemStack item;
     
        private int size;
         
        private ArmorStand stand;
     
        private boolean isRemoved;
     
        /**
         * Create a MiniBlock
         *
         * @param location
         *            Location to spawn MiniBlock at
         *          
         * @param item
         *            Item for the MiniBlock
         *          
         * @param size
         *            Size of MiniBlock (1-3 for blocks, 1-2 for items)
         */
        public MiniBlock(Location location, ItemStack item, int size){
                 
            this.location = location;
         
            this.item = item;
         
            if(!isSizeValid (item, size))size = 2;
         
            this.size = size;
         
            this.isRemoved = false;
         
            spawnMiniBlock(location, item, size);
         
        }
     
        /**
         * Teleport MiniBlock
         *
         * @param location
         *          Location to teleport to
         */
        public void teleport(Location location){
         
            this.location = location;
                 
            if(!this.isRemoved){
             
                stand.remove();
             
                spawnMiniBlock(this.location, this.item, this.size);
             
            }
         
        }
     
        /**
         * Set MiniBlock item
         *
         * @param item
         *          Item to insert to MiniBlock
         */
        public void setItem(ItemStack item){
         
            this.item = item;
         
            stand.setItemInHand(item);
         
        }
     
        /**
         * Set MiniBlock size
         *
         * @param size
         *          Size of MiniBlock (1-3 for blocks, 1-2 for items)
         */
        public void setSize(int size){
         
            this.size = size;
         
            if(!this.isRemoved){
             
                stand.remove();
             
                spawnMiniBlock(this.location, this.item, this.size);
             
            }
         
        }
     
        /**
         * Remove MiniBlock
         */
        public void remove(){
                 
            if(!this.isRemoved){
             
                stand.remove();
             
                this.isRemoved = true;
                     
            }
         
        }
     
        /*
         * Getters
         */
     
        /**
         * Get MiniBlock location
         *
         * @return MiniBlock location
         *
         */
        public Location getLocation(){
            return this.location;
        }
     
        /**
         * Get MiniBlock item
         *
         * @return MiniBlock item
         *
         */
        public ItemStack getItem(){
            return this.item;
        }
     
        /**
         * Get Armor Stand
         *
         * @return MiniBlock's Armor Stand
         *
         */
        public ArmorStand getArmorStand(){
            return this.stand;
        }
     
        /**
         * Get MiniBlock size
         *
         * @return MiniBlock size
         *
         */
        public int getSize(){
            return this.size;
        }
    
        /**
         * Get removed status
         *
         * @return true if MiniBlock is removed
         *
         */
        public boolean isRemoved(){
            return this.isRemoved;
        }
     
        /*
         * Private
         */
     
        private void spawnMiniBlock(Location location, ItemStack item, int size){
         
            if(!isSizeValid(item, size))return;
         
            Location l = location;
         
            boolean isBlock = item.getType().isBlock();
         
            EulerAngle angle = new EulerAngle(0,0,0);
         
            boolean small = false;
         
            if(isBlock){
                if(size == 1){
                    l.add(.2, -.445, 0);
                    l.setPitch(45);
                    angle = new EulerAngle(-.6,0,0);
                    small = true;
                }else if(size == 2){
                    l.add(.6, -.65, 0);
                    l.setPitch(45);
                    angle = new EulerAngle(-.25,0,0);
                }else if(size == 3){
                    l.add(0, -.7, 0);
                }
            }else{
                if(size == 1){
                    l.add(.2, -.5, -.1);
                    angle = new EulerAngle(-.35,0,0);
                    small = true;
                }else if(size == 2){
                    l.add(.7, -.8, -.1);
                    angle = new EulerAngle(0,1,0);
                }
            }
         
            ArmorStand stand = (ArmorStand) l.getWorld().spawnEntity(l, EntityType.ARMOR_STAND);
         
            fixup(stand);
         
            stand.setSmall(small);
         
            stand.setRightArmPose(angle);
         
            stand.setItemInHand(item);
         
            this.stand = stand;
        }
     
        private boolean isSizeValid(ItemStack item, int size){
            if(item.getType().isBlock()){
                if(size == 1 || size == 2 || size == 3){
                    return true;
                }else{
                    return false;
                }
            }else{
                if(size == 1 || size == 2){
                    return true;
                }else{
                    return false;
                }
            }
        }
     
        private void fixup(ArmorStand stand){
            stand.setVisible(false);
            stand.setArms(true);
            stand.setGravity(false);
            stand.setCanPickupItems(false);
        }
         
    }

    How to use method?
    Very simple!
    MiniBlock block = new MiniBlock(location, item, size);

    location: Location at which you want the item to spawn.
    item: Item that you wish to spawn at above said location. Be sure you match the item with the right type (block / item).
    size: Determine size of item. Options are 1, 2, and for blocks only, 3. You can see the sizes in the image above.

    Warning!
    It is possible for users to interact with these blocks and remove items / add items to their wishing. I have decided that perhaps someone would want to have a drop plug-in where drops drop like this or something of the sort, so I left this part up to you guys. Be sure to disable it if you don't want this to happen. (You can cancel the EntityInteractAtEntityEvent).

    Update Log:
    v1.3- Huge and long needed update. Changed from an ugly class to an object. Added useful commenting in code along with parameters for those who don't read this post. Removed isBlock and removeTime requirements. Added a teleport and remove feature.

    v1.2- Added size 3 to blocks. Made items more centered than previously.

    Anyone can use this code without any form of thanks or acknowledgement. It is 100% free for the public. Enjoy!
     
    Last edited: Dec 28, 2015
    GamerzKing and teej107 like this.
  2. Offline

    ChipDev

    Wow! Awesome!
    One question: When I spawn at a location, is that where the block is, or where the armor stand is?
     
    teej107 likes this.
  3. Offline

    Zombie_Striker

    @_Ug
    Nice plugin.

    I was looking through the code, do you have the ability to modify the direction of the Item (E.g , a diagonally placed block, or a block tilted on it's side)? Maybe you can add something that would allow us to control what direction the block/item would be facing.
     
  4. Offline

    _Ug

    Have not tested it, but from a glance at the code I can safely assure you that it is the location of the block. It gathers the location from when you initialize the mini block and it updates every time it is teleported.

    It would definitely be possible to add a pitch to the item. If you notice in the code I set the pitch to 45 on the armor stand. Without this the blocks appear to be at a, as you may assume, 45 degree angle. They are not flat nor at requested location though so there will definitely be some work needed to be done to make this work but I'll find a time to do it. As for the blocks being on their sides I love the sound of that. Unfortunately it will not work on the size 3 blocks but I'll get it working on the rest as soon as I find the time.
     
    ChipDev likes this.
  5. Offline

    ChipDev

    Rotation of the head of the armorstand will do.
     
  6. Offline

    Lightspeed

    Quote (open)



    Unfortunly these small small micro blocks with the small armour stand arn't perfect(maybe?).
    2016-02-15_22.58.14.png
    Can the arm angle be different and fix this or is this just a minecraft thing?
    Nice lib btw(Just asking a question about this wierd thing).
     
    Last edited: Feb 16, 2016
  7. Offline

    Mrs. bwfctower

    @_Ug Very nice. I would change the size to an enum since you're only allowing for one of several options. Not only would it eliminate the need for that gnarly isSizeValid method, but it would also make it easier to use.
    Also in your setSize method you don't check if the size is valid.

    Anyways, great idea, love it :)
     
  8. Offline

    crolemol

    I'm having the same issue, the position is not exact
     
  9. Offline

    Lightspeed

    This is due to the body rotation not being exact maybe in 1.9 it fixes it?
    No matter how much you turn the head it will always be off.
    Maybe a very erm whats a word 'advanced' number for the arm angle.
     
  10. Offline

    crolemol

    I made my own version of this lib which supports rotation and stuff but I always put the items in hand so I think it has something to do with the location of the armor stand... Somebody knows something?
     
  11. Offline

    Lightspeed

    No matter what you do the armour stands body will not rotate to the perfect 45 degree(I think thats it) angle.
    Maybe we can yell at microsoft.
     
  12. Offline

    Zombie_Striker

    @Lightspeed
    Microsoft has nothing to do with the development of MC. Mojang are still the only ones developing MineCraft. Microsoft just owns Mojang.
     
  13. Offline

    Lightspeed

    Well you know what I ment. :L
    Yes I do know that I just didn't remember it shhhhh I'm not that stupid. `-`
    edit: I also didn't wana say "Maybe we can yell at minecraft" because that would sound stupid(Yes as much as my replacement did yes XD). . . :L
     
    Last edited: Mar 13, 2016
Thread Status:
Not open for further replies.

Share This Page