/*
 * This file is part of Sponge, licensed under the MIT License (MIT).
 *
 * Copyright (c) SpongePowered <https://www.spongepowered.org>
 * Copyright (c) contributors
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
package org.spongepowered.common.mixin.optimization.block.state;

import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableTable;
import net.minecraft.block.Block;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.state.BlockState;
import net.minecraft.block.state.BlockStateBase;
import net.minecraft.block.state.IBlockState;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;

@Mixin(BlockState.StateImplementation.class)
public abstract class MixinStateImplementation extends BlockStateBase {

    @Shadow @Final private Block block;
    @Shadow @Final private ImmutableMap<IProperty<?>, Comparable<?>> properties;
    @Shadow private ImmutableTable<IProperty<?>, Comparable<?>, IBlockState> propertyValueTable;

    /**
     * @author gabizou - April 8th, 2016
     *
     * This is done to improve the performance of the method by removing an
     * unnecessary hash lookup. The same logic can be computed with 1 hash
     * lookup instead of 2.
     *
     * <p>This is partially contributed code from Aikar in PaperSpigot.</p>
     *
     * @param property The property requested
     * @param <T> The type of comparable
     * @return The value for the property
     */
    @Overwrite
    @Final
    @Override
    public <T extends Comparable<T>> T getValue(IProperty<T> property) {
        // Sponge Rewrite this to ignore validation steps
        final Comparable<?> value = this.properties.get(property);
        if (value == null) {
            // Still throws an exception if the property didn't have a mapping
            throw new IllegalArgumentException("Cannot get property " + property + " as it does not exist in " + this.block.getBlockState());
        }
        return property.getValueClass().cast(value);
    }

    /**
     * @author gabizou - April 8th, 2016
     *
     * This is done to improve the performance of the method by removing an
     * unnecessary hash lookup. The same logic can be computed with 1 hash
     * lookup instead of 2.
     *
     * <p>Normally, all lookups are with proper properties anyways, the only corner
     * cases that they fail will result in null block states. Throwing exceptions
     * is an option, however, for the sake of speed, these methods are otherwise
     * patched for speed. If issues arrise, disabling this mixin is easily done
     * in the sponge global config.</p>
     *
     * <p>This is partially contributed code from Aikar in PaperSpigot.</p>
     *
     * @param property The property to use
     * @param value The value keyed to the property
     * @param <T> The type of property
     * @param <V> The type of value
     * @return The block state, if not already this block state
     */
    @Overwrite
    @Final
    @Override
    public <T extends Comparable<T>, V extends T> IBlockState withProperty(IProperty<T> property, V value) {
        // Sponge - eliminate the hash lookups and validation lookups
        if (this.properties.get(property) == value) {
            return this;
        } else {
            final IBlockState blockState = this.propertyValueTable.get(property, value);
            if (blockState == null) {
                throw new IllegalArgumentException("No mapping found for the blockstate: " + Block.blockRegistry.getNameForObject(this.block) + " of property: " + property.getName() + " and value: " + value);
            }
            return blockState;
        }
    }

}

@@ -2512,49 +2512,8 @@
 ted%0A
-     * @param %3CT%3E The type of comparable%0A
     
@@ -2563,36 +2563,59 @@
 */%0A    @
-Overwrite%0A    @Final
+SuppressWarnings(%22unchecked%22)%0A    @Override
 %0A    @Ov
@@ -2620,34 +2620,35 @@
 Over
+w
 ri
-d
+t
 e%0A    
-public %3CT extends
+@Final%0A    public
  Com
@@ -2659,13 +2659,10 @@
 ble%3C
-T%3E%3E T
+?%3E
  get
@@ -2668,35 +2668,32 @@
 tValue(IProperty
-%3CT%3E
  property) %7B%0A   
@@ -3088,16 +3088,32 @@
   return
+ (Comparable%3C?%3E)
  propert
@@ -3948,83 +3948,8 @@
 rty%0A
-     * @param %3CT%3E The type of property%0A     * @param %3CV%3E The type of value%0A
     
@@ -4012,24 +4012,38 @@
 ate%0A     */%0A
+    @Override%0A
     @Overwri
@@ -4064,67 +4064,14 @@
     
-@Override%0A    public %3CT extends Comparable%3CT%3E, V extends T%3E
+public
  IBl
@@ -4105,11 +4105,8 @@
 erty
-%3CT%3E
  pro
@@ -4112,17 +4112,26 @@
 operty, 
-V
+Comparable
  value) 

Remove generics from MixinStateImplementation