#Dependent blocks

1 messages · Page 1 of 1 (latest)

violet mica
#

Anyone able to help here?

short mountain
#

I don't think such a thing exists

#

you can probably just make a Set and add dependent blocks

violet mica
#

I had hoped that wasn't the solution, since I'd then have to hard code each dependent block type

short mountain
#

Its not a huge deal

#

there is some material checks that may help, but they don't really give a list

#

Material#hasGravity

#

but thats specific to sand gravel and concrete powder

violet mica
#

aye

short mountain
#

for a better solution I'd reccomend just making a hashset

#

and hard coding it

violet mica
#

I need to take a material and figure out what direction it is dependent on (if any), so a map is probably what I'll use

short mountain
#

well you'd use a HashSet to check whether its dependent

#

than you'd check its data to see where its connected at if any

#

in cases like sand you know its always below

#

Map seems unneeded here

violet mica
#

right, so the map would always return something like "DOWN" (or whatever the spigot directional is) for sand

#

and "DIRECTIONAL" or something for wall torches and wall signs

short mountain
#

you shouldn't use a map for that you should just do a method like

@Nullable
public DIRECTIONAL getDependentDirection(@NonNull final Block block){
  if(!relySet.contains(block.getType())){
    return null;
  }

  return block.getDirectionAttachedOrWhatver();
}
violet mica
#

you could need two sets for your implementation then, one to tell if it is dependent, and one to tell if it is down or directional

short mountain
#

than worst case you make your own enum

violet mica
#

they need to be, I need to know what direction it's dependent on and know that block

#

and a custom enum is likely what I would have for the result of my map

short mountain
#

I don't see the need for a map here, but go ahead

violet mica
#

the input here is a block, so we'd have a map from the material to the type of dependency (UP, DOWN, SIDE, NONE)

#

anything with gravity would be DOWN obviously, but wall signs/torches would be SIDE, and hanging things (like those new hanging signs) would be UP

short mountain
#

looks like there is no easy way to do what you want

#

I'm not sure of your application, but I don't really think you will beable to achieve what you want

violet mica
#

it should be doable, I was just questioning if there's a method already for it or if I'd need to roll my own

#

the application is placing in structures block by block, including fragile materials (like wall signs) which are dependent on the block beside them

#

I've got all the other logic and queue ready, it's just this left

covert finch
violet mica
#

I already am, but players have a habit of going in and messing with it while building

violet mica
#

I gave up on using a map since I wanted to use the tag system to accelerate it:

private enum Dependency {
    NONE,
    UP,
    SIDE,
    DOWN,
    ANY,
    UNKNOWN
}

private static Dependency getDependencyType(Material material) {
    switch (material) {
        case LEVER:
            return Dependency.ANY;
        case LADDER:
            return Dependency.SIDE;
        case WALL_TORCH:
            return Dependency.SIDE;
        case TORCH:
            return Dependency.DOWN;
        case REDSTONE_WALL_TORCH:
            return Dependency.SIDE;
        case REDSTONE_TORCH:
            return Dependency.DOWN;
        case REPEATER:
            return Dependency.DOWN;
        case COMPARATOR:
            return Dependency.DOWN;
        case HEAVY_WEIGHTED_PRESSURE_PLATE:
            return Dependency.DOWN;
        case LIGHT_WEIGHTED_PRESSURE_PLATE:
            return Dependency.DOWN;
        case SNOW:
            return Dependency.DOWN;
        case TRIPWIRE_HOOK:
            return Dependency.SIDE;
        case TRIPWIRE:
            return Dependency.DOWN;
        default:
            break;
    }

    if (material.hasGravity())
        return Dependency.DOWN;

    if (Tag.WALL_SIGNS.isTagged(material))
        return Dependency.SIDE;
    else if (Tag.SIGNS.isTagged(material))
        return Dependency.DOWN;

    if (Tag.BUTTONS.isTagged(material))
        return Dependency.ANY;

    if (Tag.CARPETS.isTagged(material))
        return Dependency.DOWN;
    if (Tags.FLUID.contains(material))
        return Dependency.DOWN;
    if (Tag.DOORS.isTagged(material))
        return Dependency.DOWN;
    if (Tag.BEDS.isTagged(material))
        return Dependency.DOWN;
    if (Tag.WOODEN_PRESSURE_PLATES.isTagged(material))
        return Dependency.DOWN;
    if (Tag.BANNERS.isTagged(material))
        return Dependency.ANY;
    if (Tag.RAILS.isTagged(material))
        return Dependency.DOWN;

    return Dependency.UNKNOWN;
}
#

I'm well aware that the list is not complete, but it should cover most cases

#

disappointing that it's not in the API anywhere

covert finch
#

I’m assuming you already know the region the blocks are being placed in