Asleeepp / skript-itemsadder

GNU General Public License v3.0
8 stars 1 forks source link

Request to add location of placed custom blocks/furniture/etc #8

Closed Zaphara94 closed 7 months ago

Zaphara94 commented 8 months ago

Is your feature request related to a problem? Please describe. I have added a few custom items that I would like to use skript to add virtual inventories to that are persistent. The only way to do this is to have a location tied to the block in the world so you can set an ID to it, or a variable location to it. So far using the following:

on place of custom furniture "furnitureid": set {_loc} to location of event-entity

returns the location the player is standing at, rather than the location of the furniture that was placed.

Describe the solution you'd like I would like some way to call the location of a custom block that was placed in the world. I know that the ItemsAdder API has public Block getPlacedAgainst() as part of its CustomBlockPlaceEvent, so I imagine it's at least possible.

Describe alternatives you've considered I have considered using the mechanics plugin with the storagemechanics addon, but the author has ditched the entire project. I have tried everything from setting each block to its own id, to trying to get the location of the block under the placed furniture but everything comes back as an error, or just flat out does not work. Using "get clicked block" does not work either, since it was on place of custom furniture, which is not an on click event.

Asleeepp commented 8 months ago

I'll look into adding this! Thanks for the request. You may see a PR mention this issue in a day or two :)

Edit: This is actually easier to add then I expected. Expect a PR in the next 10-20 minutes.

Edit Edit: Nevermind, weirdly, the FurniturePlaceEvent doesn't seem to provide a way to get the entity placed.

Zaphara94 commented 8 months ago

I'll reach out to the plugin author and see if they can make a slight API change, then? I assume there has to be a way for the plugin to know where the custom items are in the world and which they are, since when you break them they are able to drop just fine. I'll keep you posted. Thank you for working with me, though!

Edit: Just created a discussion in the author's forum that linked back to this github thread. Thank you both again for being so wonderful to work with!

Asleeepp commented 8 months ago

Hey! I figured out how to do it. for whatever reason, there are two events, the event skript-itemsadder uses, FurniturePlaceEvent and another one which skript-itemsadder doesn't use, FurniturePlaceSucessEvent, which has the methods i'm looking for. I assume you also want this for blocks too? Which is fine, because they also have those methods.

I will be adding this event to skript-itemsadder in Version 1.5. (it will be a different event entirely)

I found this out quite late last night, wrote some quick code and forgot to reply to this issue (whoops)

I've made a PR for it, so you can keep track on the progress. https://github.com/Asleeepp/skript-itemsadder/pull/9

also if you can, I would delete that forum message, sorry for the delayed message

Zaphara94 commented 8 months ago

You are perfectly fine! Will do! Thank you so much.

Zaphara94 commented 8 months ago

It's looking pretty good so far :3 I use SkBee and base Skript for my inventory creation. The following code works, but acts more like an ender chest than its own inventory; meaning any "kitchen fridge" in the world will have the same inventory for each player.

options:
    fridgename: &b&lFridge 
    stovename: &c&lStove
    cabinetname: &e&lCabinet
    countername: &e&lCounter
    microwavename: &c&lMicrowave
    nsfwworlds: "Acheron", "acheron_nether", "acheron_the_end", "farm_nether_acheron" or "farm_acheron"
    size: 6 

on interact with custom furniture "kitchen:kitchen_fridge":
    if player's world is {@nsfwworlds}:
        set {_fridge.nsfw.%player's uuid%} to chest inventory with {@size} rows named "{@fridgename}"
        loop {@size}*9 times:
            set slot (loop-value)-1 of {_fridge.nsfw.%player's uuid%} to {fridge::nsfw::%player's uuid%::%loop-value%}
        open {_fridge.nsfw.%player's uuid%} to player
    else:
        set {_fridge.sfw.%player's uuid%} to chest inventory with {@size} rows named "{@fridgename}"
        loop {@size}*9 times:
            set slot (loop-value)-1 of {_fridge.sfw.%player's uuid%} to {fridge::sfw::%player's uuid%::%loop-value%}
        open {_fridge.sfw.%player's uuid%} to player

on inventory close: 
    if event-inventory's name = "{@fridgename}":
        if player's world is {@nsfwworlds}:
            loop {@size}*9 times:
                set {fridge::nsfw::%player's uuid%::%loop-value%} to slot (loop-value)-1 of event-inventory
        else:
            loop {@size}*9 times:
                set {fridge::sfw::%player's uuid%::%loop-value%} to slot (loop-value)-1 of event-inventory

I can't wait to be able to bind an inventory to a location in the world so that we can have individual inventories :3

Asleeepp commented 8 months ago

Haha yeah, inventories are tough work, especially in Java. Losing my mind tryna figure this stuff out lol. I'll get it done eventually tho 😉

Zaphara94 commented 8 months ago

Even if you just get the location aspect of the itemsadder items, that'd be more than plenty for me! It'd give me something to anchor a virtual chest to other than a player.