Search in sources :

Example 6 with ThreeState

use of pl.asie.charset.lib.utils.ThreeState in project Charset by CharsetMC.

the class CharsetTweakDoubleDoors method onDoubleDoorChange.

public void onDoubleDoorChange(CharsetIMC imc) {
    changeCalled = true;
    Set<BlockDoor> oldAllowedDoors = Sets.newHashSet(allowedDoors);
    allowedDoors.clear();
    for (Block block : ForgeRegistries.BLOCKS) {
        try {
            if (block != null && block instanceof BlockDoor) {
                ThreeState state = imc.allows("doubleDoor", block.getRegistryName());
                boolean allowed = false;
                if (state == ThreeState.MAYBE && !(block.getRegistryName().getResourceDomain().equals("malisisdoors"))) {
                    Class c = block.getClass();
                    Method m = MethodHandleHelper.reflectMethodRecurse(c, "onBlockActivated", "func_180639_a", World.class, BlockPos.class, IBlockState.class, EntityPlayer.class, EnumHand.class, EnumFacing.class, float.class, float.class, float.class);
                    if (m.getDeclaringClass() == BlockDoor.class) {
                        allowed = true;
                    }
                } else if (state == ThreeState.YES) {
                    allowed = true;
                }
                if (allowed) {
                    Collection<IProperty<?>> properties = block.getBlockState().getProperties();
                    if (properties.contains(BlockDoor.FACING) && properties.contains(BlockDoor.OPEN) && properties.contains(BlockDoor.HINGE)) {
                        allowedDoors.add((BlockDoor) block);
                        if (!oldAllowedDoors.contains(block)) {
                            ModCharset.logger.info("[tweak.doubledoors] Allowing " + block.getRegistryName().toString());
                        } else {
                            oldAllowedDoors.remove(block);
                        }
                    }
                }
            }
        } catch (ReflectionHelper.UnableToFindMethodException e) {
        // This is fine.
        }
    }
    for (BlockDoor block : oldAllowedDoors) {
        ModCharset.logger.info("[tweak.doubledoors] Removing " + block.getRegistryName().toString());
    }
}
Also used : BlockDoor(net.minecraft.block.BlockDoor) ThreeState(pl.asie.charset.lib.utils.ThreeState) IProperty(net.minecraft.block.properties.IProperty) ReflectionHelper(net.minecraftforge.fml.relauncher.ReflectionHelper) Block(net.minecraft.block.Block) Method(java.lang.reflect.Method)

Aggregations

ThreeState (pl.asie.charset.lib.utils.ThreeState)6 IBlockState (net.minecraft.block.state.IBlockState)2 TileEntity (net.minecraft.tileentity.TileEntity)2 ResourceLocation (net.minecraft.util.ResourceLocation)2 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)2 Joiner (com.google.common.base.Joiner)1 com.google.common.collect (com.google.common.collect)1 MethodHandle (java.lang.invoke.MethodHandle)1 MethodHandles (java.lang.invoke.MethodHandles)1 MethodType (java.lang.invoke.MethodType)1 Field (java.lang.reflect.Field)1 Method (java.lang.reflect.Method)1 java.util (java.util)1 HashSet (java.util.HashSet)1 BiConsumer (java.util.function.BiConsumer)1 Block (net.minecraft.block.Block)1 BlockDoor (net.minecraft.block.BlockDoor)1 IProperty (net.minecraft.block.properties.IProperty)1 TileEntityLockable (net.minecraft.tileentity.TileEntityLockable)1 MinecraftForge (net.minecraftforge.common.MinecraftForge)1