1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Solved MOB_HEAD - Apply custom skin ?

Discussion in 'Development' started by benda95280, Aug 25, 2019.

  1. benda95280

    benda95280 Witch

    Messages:
    53
    GitHub:
    benda95280
    A big thanks, animation is perfect !

    But ... placement of the entity is still strange, look :
    [​IMG]
    [​IMG]


    ## Beta 3 ##

    - New animation when entity break (Thanks @HimbeersaftLP)
    - New management of head skins (Config.yml with errors management) (Thanks @Kenn Fatt, still using what i've learn)
    - WIP for Entity Type (? :) ) and Size

    So, working on size now ...
     
    HimbeersaftLP likes this.
  2. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
  3. Kenn Fatt

    Kenn Fatt Slime

    Messages:
    82
    GitHub:
    kennfatt
    Since I've never actively developed a plugin anymore, at this time. I can't give try-and-error with your project. But all this correction may help you in development:

    1. Invalid @var data type, at line 47:
    PHP:
    /** @var string */
    private static $instance;
    // the document will not impact runtime, but its help on development.
    This will make IntelliSense measure invalid data type of $instance variable. This does not matter if you are developing a plugin, not for the community. SOLUTION: Change it into its correct data type which is your PlayerHeadObj class.

    2. Use $this instead, at line 70:
    Your code:
    PHP:
    $pathSkinsHead PlayerHeadObj::getInstance()->getDataFolder()."skins\\";
    From the code above, we can use this way instead:
    Suggestion:
    PHP:
    $pathSkinsHead $this->getDataFolder() . "skins\\";
    // or, DIRECTORY_SEPARATOR is PHP's special constant for directory separator. It takes more time to write, by the way.
    $pathSkinsHead $this->getDataFolder() . "skins" DIRECTORY_SEPARATOR;
    Let me explain, you are calling method getDataFolder() which is an API (a method) from PluginBase class. You can call any public methods or properties of parent class by using $this variable. I wrote basic analogy about inheritance: here.

    As future information about the static method, when and why we should it: PHP Static methods and properties

    3. Size of the entity, at line 109:
    I'm just guessing, but it might work (i hope so). For anyone that can give a better solution, please correct me.
    Your code, at PlayerHeadObj line 109:
    PHP:
    (new HeadEntityObj($player->level$nbt))->spawnToAll();
    Suggestion, and the way how to scaling an entity:
    PHP:
    $headEntityObject = new HeadEntityObj($player->getLevel(), $nbt);
    $headEntityObject->setScale(0.5); // you can change the parameter 0.5 to another float value. I.e. 1.5, 1.2, or any value higher than 0 (zero).
    $headEntityObject->spawnToAll();
    Talking about scale parameter, it must be a float type and higher than zero.
    1 means default size (As i remember).
     
  4. benda95280

    benda95280 Witch

    Messages:
    53
    GitHub:
    benda95280
    Thanks a lot for your support / help
    I've just saw your message, so my last update don't take it in consideration, i read it ASAP !

    ## Beta 3 ##
    - Added new item: Rotator -> Rotate item
    - Added function to get Item(s) -> \pho item rotator
    - Head Entity support rotation (45°)
    - Modified Prefix for message
    - Modified way to get entity: \pho entity book_1
    - New error messages :)
    - Added log level support (3 level) -> More cleaner log when loaded by default

    ! Thanks to everybody !
     
  5. benda95280

    benda95280 Witch

    Messages:
    53
    GitHub:
    benda95280
    I've done some modification, hope to do it right.

    I've saw your 'Basic inheritance implementation. PHP.', interesting, but it implies to know parents, i need to work harder :)
    Modification to the code done.

    Yes, i've found similar information.
    But my problem is how to get the skinName, inside the onPlace event (to get size information inside $skinsList), or better, store it in ?Item? (Idea is if i have the head in inventory, but it have been removed from config, should be able to place it ...)
    I'm looking to add OwnerName inside the entity, don't know yet how to. (Add new parameter, for protection of entity)
    (And maybe other informations)
     
    Last edited: Sep 2, 2019
  6. benda95280

    benda95280 Witch

    Messages:
    53
    GitHub:
    benda95280
    No success tonight.

    Wasn't able to do anything with NBT, many try like:
    - here to load NBT info ( var_dump($nbt->getNamedTag()); )
    - here to set info ( new IntTag('Size', $skinSize), ) -> Seems work
    [EDIT] : My inspiration for NBT came from this tutorial

    My reflexion tonight was about the way to do it, was thinking to pass the size this way:
    Code:
    public static function getPlayerHeadItem(string $name,string $nameFinal, $skinSize) : Item{
    
    But, doesn't seems to me a good way to do it.

    Maybe pass something like DATA (Array?) with all Data parameter of the skin.
    This implies to add a new section DATA to the config.

    Any reflexion is welcome :)
     
  7. benda95280

    benda95280 Witch

    Messages:
    53
    GitHub:
    benda95280
    Still no luck, i'm dealing with NBT:
    PHP:
        public static function getPlayerHeadItem(string $name,string $nameFinal,array $param) : Item{
            return (
    ItemFactory::get(Item::MOB_HEAD3))
                ->
    setCustomBlockData(new CompoundTag('Skin', [
                    new 
    StringTag('Name'$name),
                    new 
    ByteArrayTag('Data'PlayerHeadObj::createSkin($name)),
                    
    PlayerHeadObj::arrayToCompTag($param)
                ]))
                ->
    setCustomName(TextFormat::colorize('&r'.$nameFinal'&'));
        }
        public static function 
    arrayToCompTag($array){
            
    $tag = new CompoundTag("", []);
            foreach(
    $array as $key => $value){
                if (
    is_int($value)) $tag->setTag(new IntTag($key$value));
                elseif (
    is_string($value)) $tag->setTag(new StringTag($key$value));
            }
            return 
    $tag;
        }
    If i try to read what's inside "$item->getCustomBlockData()" below, my data is missing, but the return of the fonction "arrayToCompTag($array)" is correct !
    PHP:
        public function onPlace(BlockPlaceEvent $event) : void{
            
    $player $event->getPlayer();
            if(
    $player->hasPermission('PlayerHeadObj.spawn') and ($item $player->getInventory()->getItemInHand())->getId() === Item::MOB_HEAD and ($blockData $item->getCustomBlockData()) !== null){
                
    var_dump($item->getCustomBlockData());
                
    $nbt Entity::createBaseNBT($event->getBlock()->add(0.500.5), nullself::getYaw($event->getBlock()->add(0.500.5), $player)); // Add 0.5 because block center is at half coordinate
                
    $blockData->setName('Skin');
                
    $nbt->setTag($blockData);
                (new 
    HeadEntityObj($player->level$nbt))->spawnToAll();
                if(!
    $player->isCreative()){
                    
    $player->getInventory()->setItemInHand($item->setCount($item->getCount() - 1));
                }
                
    $event->setCancelled();
            }
        }
     
  8. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    I think a CompoundTag shouldn't have an empty name.
     
  9. benda95280

    benda95280 Witch

    Messages:
    53
    GitHub:
    benda95280
    I've deleted my previous post, was dumb question.
    I'm still not able to push my new CompoundTag inside my setCustomBlockData.

    How can i push my data, inside this :
    PHP:
            $item = (ItemFactory::get(Item::MOB_HEAD3))
                ->
    setCustomBlockData(new CompoundTag('skin', [
                    new 
    StringTag('Name'$name),
                    new 
    ByteArrayTag('Data'PlayerHeadObj::createSkin($name)),
                ]))
                ->
    setCustomName(TextFormat::colorize('&r'.$nameFinal'&'));
    I've try many thing, like create a new CompoundTag, call another time setCustomBlockData, ...
    Sometimes i lost my skin-CompoundTag, sometimes i can't place the item ...
    I just want to store it inside, but not inside 'skin', i've been able to do that, useless :(

    My last try was working on that (i'm desperate, isn't it ? )
    PHP:
            $item = (ItemFactory::get(Item::MOB_HEAD3))
                ->
    setCustomBlockData(new CompoundTag('skin', [
                    new 
    StringTag('Name'$name),
                    new 
    ByteArrayTag('Data'PlayerHeadObj::createSkin($name)),
                ]))
                ->
    setCustomName(TextFormat::colorize('&r'.$nameFinal'&'));
            
    $tags $item->getNamedTag();
            
    $tags->BlockEntityTag->setTag(PlayerHeadObj::arrayToCompTag($param));
            
    $item->setNamedTag($tags);
    PS: i know "Cannot access dynamic field" it's just my last dumb try and test example, to show you where i'm going ...
     
    Last edited: Sep 5, 2019
  10. benda95280

    benda95280 Witch

    Messages:
    53
    GitHub:
    benda95280
    Hello,
    Sorry, plugin is still in Dev, and it evolve with the time

    It's my mistake ! I haven't post any information about command or other thing about it !
    For now, command are :
    \pho entity book_1
    \pho item rotator
    (You could put your issue on Github too)

    Any comments are always welcome.
     
  11. TheWalkingDrift

    TheWalkingDrift Silverfish

    Messages:
    23
    Is it possible, to make the heads like Blocks?
     
  12. TheWalkingDrift

    TheWalkingDrift Silverfish

    Messages:
    23
    Like in this Video:
     
  13. TheWalkingDrift

    TheWalkingDrift Silverfish

    Messages:
    23
    I think, there is a head block under the Entity
     
  14. benda95280

    benda95280 Witch

    Messages:
    53
    GitHub:
    benda95280
    I'm on my way ...

    Update Is Coming
     
  15. benda95280

    benda95280 Witch

    Messages:
    53
    GitHub:
    benda95280
    I don't know if it possible.

    Anyone know if it possible for an entity to act as a block ?
    If not, maybe it's possible to have Collision ?

    If possible, i will try it !
     
  16. benda95280

    benda95280 Witch

    Messages:
    53
    GitHub:
    benda95280
    ## Beta 4 ##
    • New tool: Remover
    • New type: Small / Block
    • Config file changed
    • New parameter: Health / Unbreakable
    • Verification added for new type when plugin loaded

    [​IMG]

    When block created, it's only placed on 90° axe, need to find a FIX.
    You need to use rotate tool to do the rotation

    What's next ?
    • Interract command (Max Use / Autodestruction? / Change Skin when reach max use)
    • Custom entity loader (I want a new shower, seems very useful ... :D)
    • Looking for information about: Entity act as a Block (If possible, see prev. post)
    • Is it possible to added floating effect ? (Like a cloud)

    Big Thanks To Everybody !
     
    Last edited: Sep 6, 2019
  17. benda95280

    benda95280 Witch

    Messages:
    53
    GitHub:
    benda95280
    @TheWalkingDrift :
    Dear, about issues or ideas, could you post it on GitHub ?
    I'll do my best to add new features, as far as i can with my knowledge or with the help of the forum members.

    Could you consider to do it, and remove your Post ?
    (Better visibility inside the topic about the work on the plugin and question i may ask to other members)
     
  18. benda95280

    benda95280 Witch

    Messages:
    53
    GitHub:
    benda95280
    ## Beta 5 ##

    Entity can be usable:
    • Max time usable
    • Actions: Message / Teleport / Heal / Effects
    • ChangeSkin when no more usable
    • AutoDestruction when no more usable
    • Show message when used
    • AutoDestruction message
    • Infinite actions (Array)
    • One random action from all actions possible


    What's next ?
    • Custom entity loader (I want a new shower, seems very useful ... :D)
    • Looking for information about: Entity act as a Block (If possible, see prev. post #35)
    • Is it possible to added floating effect to the entity ? (Like a cloud)
    • Control what's dropped
    • Prevent spam of the entity (per player)
    • Looking for help for the reload function. I've to use a Task, but i want a task that check ALL of my entity that need to be updated, and not a task per entity.
    Know bug :
    • Orientation of normal and small entity when created is 90° instead of 45°

    Big Thanks To Everybody !
     
    Last edited: Sep 7, 2019
    HimbeersaftLP likes this.
  19. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    If you mean custom skins, take a look at my fork's branch.
    However I plan to scrap that and make a SkinTools virion instead, that way the code can be more modular and other plugins can make use of that functionality.
     
  20. benda95280

    benda95280 Witch

    Messages:
    53
    GitHub:
    benda95280
    I mean custom Skin + Custom Json => Custom Entity :)
    Something very easy to use, just add skin + json, declare inside config, and you'r ready !
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.