package org.cyclops.integrateddynamics.core.evaluate.variable;

import org.cyclops.cyclopscore.helper.MinecraftHelpers;
import org.cyclops.integrateddynamics.IntegratedDynamics;
import org.cyclops.integrateddynamics.api.evaluate.variable.IValue;
import org.cyclops.integrateddynamics.api.evaluate.variable.IValueCastRegistry;
import org.cyclops.integrateddynamics.api.evaluate.variable.IValueType;

/**
 * Collection of variable types.
 * @author rubensworks
 */
public class ValueCastMappings {

    public static final IValueCastRegistry REGISTRY = constructRegistry();

    private static IValueCastRegistry constructRegistry() {
        // This also allows this registry to be used outside of a minecraft environment.
        if(MinecraftHelpers.isModdedEnvironment()) {
            return IntegratedDynamics._instance.getRegistryManager().getRegistry(IValueCastRegistry.class);
        } else {
            return ValueCastRegistry.getInstance();
        }
    }

    public static void load() {
        REGISTRY.register(ValueTypes.INTEGER, ValueTypes.DOUBLE, new IValueCastRegistry.IMapping<ValueTypeInteger, ValueTypeDouble, ValueTypeInteger.ValueInteger, ValueTypeDouble.ValueDouble>() {
            @Override
            public ValueTypeDouble.ValueDouble cast(ValueTypeInteger.ValueInteger value) {
                return ValueTypeDouble.ValueDouble.of((double) value.getRawValue());
            }
        });
        REGISTRY.register(ValueTypes.INTEGER, ValueTypes.LONG, new IValueCastRegistry.IMapping<ValueTypeInteger, ValueTypeLong, ValueTypeInteger.ValueInteger, ValueTypeLong.ValueLong>() {
            @Override
            public ValueTypeLong.ValueLong cast(ValueTypeInteger.ValueInteger value) {
                return ValueTypeLong.ValueLong.of((long) value.getRawValue());
            }
        });
        REGISTRY.register(ValueTypes.DOUBLE, ValueTypes.INTEGER, new IValueCastRegistry.IMapping<ValueTypeDouble, ValueTypeInteger, ValueTypeDouble.ValueDouble, ValueTypeInteger.ValueInteger>() {
            @Override
            public ValueTypeInteger.ValueInteger cast(ValueTypeDouble.ValueDouble value) {
                return ValueTypeInteger.ValueInteger.of((int) value.getRawValue());
            }
        });
        REGISTRY.register(ValueTypes.DOUBLE, ValueTypes.LONG, new IValueCastRegistry.IMapping<ValueTypeDouble, ValueTypeLong, ValueTypeDouble.ValueDouble, ValueTypeLong.ValueLong>() {
            @Override
            public ValueTypeLong.ValueLong cast(ValueTypeDouble.ValueDouble value) {
                return ValueTypeLong.ValueLong.of((long) value.getRawValue());
            }
        });
        REGISTRY.register(ValueTypes.LONG, ValueTypes.INTEGER, new IValueCastRegistry.IMapping<ValueTypeLong, ValueTypeInteger, ValueTypeLong.ValueLong, ValueTypeInteger.ValueInteger>() {
            @Override
            public ValueTypeInteger.ValueInteger cast(ValueTypeLong.ValueLong value) {
                return ValueTypeInteger.ValueInteger.of((int) value.getRawValue());
            }
        });
        REGISTRY.register(ValueTypes.LONG, ValueTypes.DOUBLE, new IValueCastRegistry.IMapping<ValueTypeLong, ValueTypeDouble, ValueTypeLong.ValueLong, ValueTypeDouble.ValueDouble>() {
            @Override
            public ValueTypeDouble.ValueDouble cast(ValueTypeLong.ValueLong value) {
                return ValueTypeDouble.ValueDouble.of((double) value.getRawValue());
            }
        });
        for (IValueType<?> valueType : ValueTypes.CATEGORY_NUMBER.getElements()) {
            REGISTRY.register(valueType, ValueTypes.CATEGORY_NUMBER, new IValueCastRegistry.IMapping() {
                @Override
                public IValue cast(IValue value) {
                    return value;
                }
            });
        }

    }

}

@@ -241,160 +241,20 @@
 alue
-;%0Aimport org.cyclops.integrateddynamics.api.evaluate.variable.IValueCastRegistry;%0Aimport org.cyclops.integrateddynamics.api.evaluate.variable.IValueType
+CastRegistry
 ;%0A%0A/
@@ -3303,351 +3303,8 @@
  %7D);
-%0A        for (IValueType%3C?%3E valueType : ValueTypes.CATEGORY_NUMBER.getElements()) %7B%0A            REGISTRY.register(valueType, ValueTypes.CATEGORY_NUMBER, new IValueCastRegistry.IMapping() %7B%0A                @Override%0A                public IValue cast(IValue value) %7B%0A                    return value;%0A                %7D%0A            %7D);%0A        %7D
 %0A%0A  

Remove invalid number casting, Closes #123 This was introduced because of #15, but this was not required after all.