Drop 1.16.5 support to use Mojang mappings
Because there is no option to create a `remapped-mojang` artifact for 1.16.5 and the whole point of the scripts is to save me time, 1.16.5 support is being removed earlier than usual. Also fixes issues with NMS-based shulker collision check. Closes #36
This commit is contained in:
		@@ -24,7 +24,6 @@ import org.bukkit.block.BlockState;
 | 
			
		||||
import org.bukkit.block.EnderChest;
 | 
			
		||||
import org.bukkit.block.ShulkerBox;
 | 
			
		||||
import org.bukkit.block.data.BlockData;
 | 
			
		||||
import org.bukkit.block.data.Directional;
 | 
			
		||||
import org.bukkit.block.data.type.Chest;
 | 
			
		||||
import org.bukkit.entity.Cat;
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
@@ -84,30 +83,9 @@ public interface IAnySilentContainer {
 | 
			
		||||
 | 
			
		||||
        // Shulker boxes require 1/2 a block clear in the direction they open.
 | 
			
		||||
        if (blockState instanceof ShulkerBox) {
 | 
			
		||||
            BoundingBox boundingBox = block.getBoundingBox();
 | 
			
		||||
            if (boundingBox.getVolume() > 1) {
 | 
			
		||||
                // Shulker box is already open.
 | 
			
		||||
                return false;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            BlockData blockData = block.getBlockData();
 | 
			
		||||
            if (!(blockData instanceof Directional)) {
 | 
			
		||||
                // Shouldn't be possible. Just in case, demand AnyChest.
 | 
			
		||||
            if (isShulkerBlocked((ShulkerBox) blockState)) {
 | 
			
		||||
                return true;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            Directional directional = (Directional) blockData;
 | 
			
		||||
            BlockFace face = directional.getFacing();
 | 
			
		||||
            Block relative = block.getRelative(face, 1);
 | 
			
		||||
 | 
			
		||||
            if (isShulkerIgnoreBoundingBox(relative)) {
 | 
			
		||||
                // Certain special cases are ignored. Signs, simple redstone, etc.
 | 
			
		||||
                return false;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            boundingBox.expand(face.getDirection(), 0.5);
 | 
			
		||||
            // Return whether or not bounding boxes overlap.
 | 
			
		||||
            return relative.getBoundingBox().overlaps(boundingBox);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (!(blockState instanceof org.bukkit.block.Chest)) {
 | 
			
		||||
@@ -146,7 +124,7 @@ public interface IAnySilentContainer {
 | 
			
		||||
        return isChestBlocked(relative);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    boolean isShulkerIgnoreBoundingBox(Block block);
 | 
			
		||||
    boolean isShulkerBlocked(ShulkerBox block);
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Determine whether or not a chest is blocked.
 | 
			
		||||
 
 | 
			
		||||
@@ -20,7 +20,6 @@ import com.lishid.openinv.internal.IInventoryAccess;
 | 
			
		||||
import com.lishid.openinv.internal.ISpecialEnderChest;
 | 
			
		||||
import com.lishid.openinv.internal.ISpecialInventory;
 | 
			
		||||
import com.lishid.openinv.internal.ISpecialPlayerInventory;
 | 
			
		||||
import java.lang.reflect.Field;
 | 
			
		||||
import java.lang.reflect.Method;
 | 
			
		||||
import org.bukkit.Bukkit;
 | 
			
		||||
import org.bukkit.inventory.Inventory;
 | 
			
		||||
@@ -81,7 +80,8 @@ public class InventoryAccess implements IInventoryAccess {
 | 
			
		||||
            } catch (ReflectiveOperationException ignored) {}
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        inv = grabFieldOfTypeFromObject(expected, inventory);
 | 
			
		||||
        // Use reflection to find the IInventory
 | 
			
		||||
        inv = ReflectionHelper.grabObjectByType(inventory, expected);
 | 
			
		||||
 | 
			
		||||
        if (expected.isInstance(inv)) {
 | 
			
		||||
            return expected.cast(inv);
 | 
			
		||||
@@ -90,23 +90,6 @@ public class InventoryAccess implements IInventoryAccess {
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private static <T> @Nullable T grabFieldOfTypeFromObject(final Class<T> type, final Object object) {
 | 
			
		||||
        // Use reflection to find the IInventory
 | 
			
		||||
        Class<?> clazz = object.getClass();
 | 
			
		||||
        T result = null;
 | 
			
		||||
        for (Field f : clazz.getDeclaredFields()) {
 | 
			
		||||
            f.setAccessible(true);
 | 
			
		||||
            if (type.isAssignableFrom(f.getDeclaringClass())) {
 | 
			
		||||
                try {
 | 
			
		||||
                    result = type.cast(f.get(object));
 | 
			
		||||
                } catch (Exception e) {
 | 
			
		||||
                    e.printStackTrace();
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        return result;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Deprecated
 | 
			
		||||
    @Override
 | 
			
		||||
    public @Nullable ISpecialEnderChest getSpecialEnderChest(@NotNull Inventory inventory) {
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,75 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2011-2021 lishid. All rights reserved.
 | 
			
		||||
 *
 | 
			
		||||
 * This program is free software: you can redistribute it and/or modify
 | 
			
		||||
 * it under the terms of the GNU General Public License as published by
 | 
			
		||||
 * the Free Software Foundation, version 3.
 | 
			
		||||
 *
 | 
			
		||||
 * This program is distributed in the hope that it will be useful,
 | 
			
		||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 | 
			
		||||
 * GNU General Public License for more details.
 | 
			
		||||
 *
 | 
			
		||||
 * You should have received a copy of the GNU General Public License
 | 
			
		||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
package com.lishid.openinv.util;
 | 
			
		||||
 | 
			
		||||
import java.lang.reflect.Field;
 | 
			
		||||
import org.jetbrains.annotations.Nullable;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * A utility for making reflection easier.
 | 
			
		||||
 */
 | 
			
		||||
public final class ReflectionHelper {
 | 
			
		||||
 | 
			
		||||
    private ReflectionHelper() {}
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Grab an {@link Object} stored in a {@link Field} of another {@code Object}.
 | 
			
		||||
     *
 | 
			
		||||
     * <p>This casts the field to the correct class. Any issues will result in a {@code null} return value.
 | 
			
		||||
     *
 | 
			
		||||
     * @param fieldType the {@link Class} of {@code Object} stored in the {@code Field}
 | 
			
		||||
     * @param holder the containing {@code Object}
 | 
			
		||||
     * @param <T> the type of stored {@code Object}
 | 
			
		||||
     * @return the first matching {@code Object} or {@code null} if none match
 | 
			
		||||
     */
 | 
			
		||||
    public static <T> @Nullable T grabObjectByType(final Object holder, final Class<T> fieldType) {
 | 
			
		||||
        Field field = grabFieldByType(holder.getClass(), fieldType);
 | 
			
		||||
 | 
			
		||||
        if (field != null) {
 | 
			
		||||
            try {
 | 
			
		||||
                return fieldType.cast(field.get(holder));
 | 
			
		||||
            } catch (IllegalAccessException ignored) {
 | 
			
		||||
                // Ignore issues obtaining field
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Grab a {@link Field} of an {@link Object}
 | 
			
		||||
     *
 | 
			
		||||
     * @param fieldType the {@link Class} of the object
 | 
			
		||||
     * @param holderType the containing {@code Class}
 | 
			
		||||
     * @return the first matching object or {@code null} if none match
 | 
			
		||||
     */
 | 
			
		||||
    public static @Nullable Field grabFieldByType(Class<?> holderType, Class<?> fieldType) {
 | 
			
		||||
        for (Field field : holderType.getDeclaredFields()) {
 | 
			
		||||
            field.setAccessible(true);
 | 
			
		||||
            if (fieldType.isAssignableFrom(field.getType())) {
 | 
			
		||||
                return field;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (holderType.getSuperclass() != null) {
 | 
			
		||||
            return grabFieldByType(fieldType, holderType.getSuperclass());
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user