package org.squiddev.plethora.integration.vanilla.meta;

import com.google.common.collect.Maps;
import net.minecraft.block.Block;
import net.minecraft.block.material.MapColor;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.state.IBlockState;
import org.squiddev.plethora.api.PlethoraAPI;
import org.squiddev.plethora.api.meta.BaseMetaProvider;
import org.squiddev.plethora.api.meta.IMetaProvider;
import org.squiddev.plethora.api.method.IPartialContext;

import javax.annotation.Nonnull;
import java.util.HashMap;
import java.util.Map;

@IMetaProvider.Inject(value = IBlockState.class)
public class MetaBlockState extends BaseMetaProvider<IBlockState> {
	@Nonnull
	@Override
	public Map<Object, Object> getMeta(@Nonnull IPartialContext<IBlockState> context) {
		HashMap<Object, Object> data = Maps.newHashMap();

		IBlockState state = context.getTarget();
		Block block = state.getBlock();
		if (block != null) data.put("metadata", block.getMetaFromState(state));

		HashMap<Object, Object> stateProperties = Maps.newHashMap();
		data.put("state", state);
		for (Map.Entry<IProperty<?>, Comparable<?>> item : state.getProperties().entrySet()) {
			Object value = item.getValue();
			if (!(value instanceof String) && !(value instanceof Number) && !(value instanceof Boolean)) {
				value = value.toString();
			}
			stateProperties.put(item.getKey().getName(), value);
		}

		Material material = state.getMaterial();
		data.put("material", PlethoraAPI.instance().metaRegistry().getMeta(context.makePartialChild(material)));

		int level = block.getHarvestLevel(state);
		if (level >= 0) data.put("harvestLevel", level);
		data.put("harvestTool", block.getHarvestTool(state));

		MapColor mapCol = state.getMapColor();
		if (mapCol != null) {
			int colour = mapCol.colorValue;
			data.put("colour", colour);
			data.put("color", colour);
		}

		return data;
	}
}

@@ -1117,24 +1117,34 @@
 tate%22, state
+Properties
 );%0A%09%09for (Ma

Fix state properties not being used