Supplementaries

Supplementaries

110M Downloads

[1.16-Bug] Gunpowder rightclicking on locks from "locks" mod allows to bypass them, and simply open block

karwsz opened this issue ยท 3 comments

commented
commented

unfortunately i dropped support for 1.16 more than a year ago

commented

`
Optional<?> locked = Optional.empty();

        try {

        Capability<?> locksCapabilities =
                (Capability<?>) Class.forName("melonslise.locks.common.init.LocksCapabilities"
                ).getDeclaredField("LOCKABLE_HANDLER").get(null);

        Object handler = world.getCapability(locksCapabilities).orElse(null);


        Class<?> lockableClass = Class.forName("melonslise.locks.common.util.Lockable");
        Field bbField = lockableClass.getDeclaredField("bb");

        Class<?> cuboid6iClass = Class.forName("melonslise.locks.common.util.Cuboid6i");
        Method intersectsMethod = cuboid6iClass.getDeclaredMethod("intersects", BlockPos.class);




        Object[] intersect = ((List<?>) ((Int2ObjectMap) handler.getClass().getDeclaredMethod("getInChunk", BlockPos.class).invoke(handler, pos)
        ).values().stream().filter(lkb -> {
            try {
                return (boolean) intersectsMethod.invoke(bbField.get(lkb), pos);
            } catch (
                    IllegalAccessException |
                    InvocationTargetException e) {

            }
            return false;
        }).collect(Collectors.toList())).toArray();


        Method isLockedMethod = Class.forName("melonslise.locks.common.util.Lock").getDeclaredMethod("isLocked");
        Field lockField = Class.forName("melonslise.locks.common.util.Lockable").getField("lock");

        locked = Arrays.stream(intersect).filter(lck -> {
                    try {
                        return (boolean) isLockedMethod.invoke(lockField.get(lck));
                    } catch (
                            IllegalAccessException |
                            InvocationTargetException e) {
                        throw new RuntimeException(e);
                    }
                }
                ).findFirst();


        } catch (
                ClassNotFoundException |
                NoSuchFieldException |
                IllegalAccessException |
                NoSuchMethodException |
                InvocationTargetException ignored) {

        }


        if (!player.isShiftKeyDown() && !isRanged && !locked.isPresent()) {
            BlockState blockstate = world.getBlockState(pos);
            result = blockstate.use(world, player, hand, raytrace);
        }`

Unspeakable things were done, but it is working.

commented

You can also check if the mod is loaded and call it's classes directly from another class