Need assistance with Generators and Hoppers

  • Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the community!

    Now, what are you waiting for? Join the community now!

  • LOOKING FOR A VERSION OF SKRIPT?

    You can always check out skUnity Downloads for downloads and any other information about Skript!

BlackJackx

Member
Oct 11, 2024
1
0
1
Hi!

I'm sorry if i bother you all.

I'm slowly learning Skript since some days and i'm making some good progresses, i've already created two custom currencies, dynamic bossbars, dynamic scoreboards, i mean... simple stuffs for now, but i'm having huge issues while dealing with hoppers and generators.

I need to make sure that dropped items from Generators will get on top of the higher generator, also if a hopper is above those generators the generator's drops should get directly into the hopper and delete the physical drop. But after several attempts i've been failing.

The main issue i'm having is with this plugin named NextGens: dropped items are getting thrown away from generators, instead of spawning on top of generators and laying there. Since i didn't want to create a complex Skript for generators, i decided to use this plugin but got stuck with these annoying problems :/


Any suggestion for all these issues i'm facing?


This is the Skript i've tried to write, but i think it's needed to completely revamp it or drastically change logic of it.


Code:
import:
    org.bukkit.Location
    org.bukkit.inventory.ItemStack
    org.bukkit.entity.Item
    org.bukkit.util.Vector

on item spawn:
    set {_entity} to event-entity

    # Check if it's a generator drop by checking NBT tag
    if "%nbt of {_entity}%" contains "nextgens:nextgens_drop_value":
        send "&e[Debug] Generator drop detected" to console
     
        set {_dropLocation} to location of {_entity}
        set {_x} to x-coordinate of {_dropLocation}
        set {_y} to y-coordinate of {_dropLocation}
        set {_z} to z-coordinate of {_dropLocation}

        # Search for the first air block above the generator within a limited height range
        loop 16 times:
            set {_yAbove} to {_y} + loop-number
            set {_locationAbove} to location at {_x}, {_yAbove}, {_z}

            if block at {_locationAbove} is air:
                send "&e[Debug] Found air block at: %location of {_locationAbove}%" to console
                # Set the drop position at the center of the air block
                set {_dropPosition} to {_locationAbove}
                add 0.5 to x-coordinate of {_dropPosition}
                add 0.5 to z-coordinate of {_dropPosition}
                add 0.1 to y-coordinate of {_dropPosition}  # Slight adjustment

                # Retrieve the item stack of the original entity
                set {_itemStack} to {_entity}.getItemStack()
                send "&e[Debug] Spawning new drop at: %location of {_dropPosition}%" to console

                # Spawn the new item at the precise location with no velocity
                set {_world} to {_locationAbove}.getWorld()
                set {_newEntity} to {_world}.dropItem({_dropPosition}, {_itemStack})

                # Ensure it does not move or fall
                {_newEntity}.setVelocity(new Vector(0, 0, 0))
                {_newEntity}.setGravity(false)

                # Remove the old entity
                {_entity}.remove()
                send "&e[Debug] Old drop removed" to console
                stop loop
        else:
            send "&e[Debug] No air block found above generator" to console
    else:
        send "&e[Debug] Not a generator drop" to console
 
Last edited: