ExtendedBlockState, Properties generic updates.

This commit is contained in:
RainWarrior 2015-11-13 19:29:44 +03:00
parent 41c3846c51
commit deb26f5c80
2 changed files with 16 additions and 18 deletions

View File

@ -8,22 +8,21 @@ import java.util.Map;
import net.minecraft.block.Block;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.state.BlockState;
import net.minecraft.block.state.BlockState.StateImplementation;
import net.minecraft.block.state.IBlockState;
import com.google.common.base.Optional;
import com.google.common.base.Predicates;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableTable;
import com.google.common.collect.Iterables;
import com.google.common.collect.Maps;
public class ExtendedBlockState extends BlockState
{
private final ImmutableSet<IUnlistedProperty<?>> unlistedProperties;
public ExtendedBlockState(Block blockIn, IProperty[] properties, IUnlistedProperty<?>[] unlistedProperties)
public ExtendedBlockState(Block blockIn, @SuppressWarnings("rawtypes") IProperty[] properties, IUnlistedProperty<?>[] unlistedProperties)
{
super(blockIn, properties, buildUnlistedMap(unlistedProperties));
ImmutableSet.Builder<IUnlistedProperty<?>> builder = ImmutableSet.<IUnlistedProperty<?>>builder();
@ -45,7 +44,7 @@ public class ExtendedBlockState extends BlockState
}
@Override
protected StateImplementation createState(Block block, ImmutableMap properties, ImmutableMap unlistedProperties)
protected StateImplementation createState(Block block, @SuppressWarnings("rawtypes") ImmutableMap<IProperty, Comparable> properties, ImmutableMap<IUnlistedProperty<?>, Optional<?>> unlistedProperties)
{
if (unlistedProperties == null || unlistedProperties.isEmpty()) return super.createState(block, properties, unlistedProperties);
return new ExtendedStateImplementation(block, properties, unlistedProperties, null);
@ -54,9 +53,10 @@ public class ExtendedBlockState extends BlockState
protected static class ExtendedStateImplementation extends StateImplementation implements IExtendedBlockState
{
private final ImmutableMap<IUnlistedProperty<?>, Optional<?>> unlistedProperties;
private Map<Map<IProperty, Comparable>, IBlockState> normalMap;
@SuppressWarnings("rawtypes")
private Map<Map<IProperty, Comparable>, BlockState.StateImplementation> normalMap;
protected ExtendedStateImplementation(Block block, ImmutableMap<IProperty, Comparable> properties, ImmutableMap<IUnlistedProperty<?>, Optional<?>> unlistedProperties, ImmutableTable<IProperty, Comparable, IBlockState> table)
protected ExtendedStateImplementation(Block block, @SuppressWarnings("rawtypes") ImmutableMap<IProperty, Comparable> properties, ImmutableMap<IUnlistedProperty<?>, Optional<?>> unlistedProperties, @SuppressWarnings("rawtypes") ImmutableTable<IProperty, Comparable, IBlockState> table)
{
super(block, properties);
this.unlistedProperties = unlistedProperties;
@ -80,12 +80,14 @@ public class ExtendedBlockState extends BlockState
{
return this;
}
Map<IProperty, Comparable> map = new HashMap<IProperty, Comparable>(getProperties());
@SuppressWarnings("rawtypes")
Map<IProperty, Comparable> map = Maps.newHashMap(getProperties());
map.put(property, value);
if(Iterables.all(unlistedProperties.values(), Predicates.<Optional<?>>equalTo(Optional.absent())))
{ // no dynamic properties present, looking up in the normal table
return (IExtendedBlockState) normalMap.get(map);
}
@SuppressWarnings("rawtypes")
ImmutableTable<IProperty, Comparable, IBlockState> table = propertyValueTable;
table = ((StateImplementation)table.get(property, value)).getPropertyValueTable();
return new ExtendedStateImplementation(getBlock(), ImmutableMap.copyOf(map), unlistedProperties, table).setMap(this.normalMap);
@ -131,13 +133,13 @@ public class ExtendedBlockState extends BlockState
}
@Override
public void buildPropertyValueTable(Map map)
public void buildPropertyValueTable(@SuppressWarnings("rawtypes") Map<Map<IProperty, Comparable>, BlockState.StateImplementation> map)
{
this.normalMap = map;
super.buildPropertyValueTable(map);
}
private ExtendedStateImplementation setMap(Map<Map<IProperty, Comparable>, IBlockState> map)
private ExtendedStateImplementation setMap(@SuppressWarnings("rawtypes") Map<Map<IProperty, Comparable>, BlockState.StateImplementation> map)
{
this.normalMap = map;
return this;

View File

@ -1,23 +1,19 @@
package net.minecraftforge.common.property;
import java.lang.reflect.InvocationTargetException;
import net.minecraft.block.properties.IProperty;
import org.apache.commons.lang3.reflect.ConstructorUtils;
public class Properties
{
public static <P extends IProperty, V>IUnlistedProperty<V> toUnlisted(P property)
public static <V extends Comparable<V>> IUnlistedProperty<V> toUnlisted(IProperty<V> property)
{
return new PropertyAdapter(property);
return new PropertyAdapter<V>(property);
}
public static class PropertyAdapter<V extends Comparable> implements IUnlistedProperty<V>
public static class PropertyAdapter<V extends Comparable<V>> implements IUnlistedProperty<V>
{
private final IProperty parent;
private final IProperty<V> parent;
public PropertyAdapter(IProperty parent)
public PropertyAdapter(IProperty<V> parent)
{
this.parent = parent;
}