<commit_before>package com.creativemd.littletiles.common.structure.directional;

import java.lang.reflect.Field;
import java.util.HashMap;

import com.creativemd.creativecore.common.utils.math.Rotation;
import com.creativemd.creativecore.common.utils.math.RotationUtils;
import com.creativemd.littletiles.common.structure.relative.StructureRelative;
import com.creativemd.littletiles.common.tile.math.box.LittleBox;
import com.creativemd.littletiles.common.tile.math.vec.LittleVec;
import com.creativemd.littletiles.common.tile.place.PlacePreview;
import com.creativemd.littletiles.common.tile.preview.LittlePreviews;
import com.creativemd.littletiles.common.util.grid.LittleGridContext;

import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagInt;
import net.minecraft.nbt.NBTTagIntArray;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumFacing.Axis;

public abstract class StructureDirectionalType<T> {
	
	private static HashMap<Class, StructureDirectionalType> types = new HashMap<>();
	
	public static StructureDirectionalType getType(Field field) {
		StructureDirectionalType type = types.get(field.getType());
		if (type == null)
			throw new RuntimeException("No registered directional type for " + field.getType() + ", " + field.getName());
		return type;
	}
	
	public static <T> void registerType(Class<T> clazz, StructureDirectionalType<T> type) {
		if (types.containsKey(clazz))
			throw new IllegalArgumentException("Type already exists. " + clazz);
		
		types.put(clazz, type);
	}
	
	static {
		registerType(EnumFacing.class, new StructureDirectionalType<EnumFacing>() {
			@Override
			public EnumFacing read(NBTBase nbt) {
				if (nbt instanceof NBTTagInt)
					return EnumFacing.VALUES[((NBTTagInt) nbt).getInt()];
				return null;
			}
			
			@Override
			public NBTBase write(EnumFacing value) {
				return new NBTTagInt(value.ordinal());
			}
			
			@Override
			public EnumFacing move(EnumFacing value, LittleGridContext context, LittleVec offset) {
				return value;
			}
			
			@Override
			public EnumFacing flip(EnumFacing value, LittleGridContext context, Axis axis, LittleVec doubledCenter) {
				if (axis == value.getAxis())
					return value.getOpposite();
				return value;
			}
			
			@Override
			public EnumFacing rotate(EnumFacing value, LittleGridContext context, Rotation rotation, LittleVec doubledCenter) {
				return RotationUtils.rotate(value, rotation);
			}
			
			@Override
			public EnumFacing getDefault() {
				return EnumFacing.EAST;
			}
		});
		registerType(Axis.class, new StructureDirectionalType<Axis>() {
			
			@Override
			public Axis read(NBTBase nbt) {
				if (nbt instanceof NBTTagInt)
					return Axis.values()[((NBTTagInt) nbt).getInt()];
				return null;
			}
			
			@Override
			public NBTBase write(Axis value) {
				return new NBTTagInt(value.ordinal());
			}
			
			@Override
			public Axis move(Axis value, LittleGridContext context, LittleVec offset) {
				return value;
			}
			
			@Override
			public Axis flip(Axis value, LittleGridContext context, Axis axis, LittleVec doubledCenter) {
				return value;
			}
			
			@Override
			public Axis rotate(Axis value, LittleGridContext context, Rotation rotation, LittleVec doubledCenter) {
				return RotationUtils.rotate(value, rotation);
			}
			
			@Override
			public Axis getDefault() {
				return Axis.X;
			}
			
		});
		registerType(StructureRelative.class, new StructureDirectionalType<StructureRelative>() {
			
			@Override
			public StructureRelative read(NBTBase nbt) {
				if (nbt instanceof NBTTagIntArray)
					return new StructureRelative(((NBTTagIntArray) nbt).getIntArray());
				return null;
			}
			
			@Override
			public NBTBase write(StructureRelative value) {
				return new NBTTagIntArray(value.write());
			}
			
			@Override
			public StructureRelative move(StructureRelative value, LittleGridContext context, LittleVec offset) {
				value.move(context, offset);
				return value;
			}
			
			@Override
			public StructureRelative flip(StructureRelative value, LittleGridContext context, Axis axis, LittleVec doubledCenter) {
				value.flip(context, axis, doubledCenter);
				return value;
			}
			
			@Override
			public StructureRelative rotate(StructureRelative value, LittleGridContext context, Rotation rotation, LittleVec doubledCenter) {
				value.rotate(context, rotation, doubledCenter);
				return value;
			}
			
			@Override
			public LittleGridContext getContext(StructureRelative value) {
				return value.getContext();
			}
			
			@Override
			public void convertToSmallest(StructureRelative value) {
				value.convertToSmallest();
			}
			
			@Override
			public PlacePreview getPlacePreview(StructureRelative value, LittlePreviews previews, StructureDirectionalField field) {
				return value.getPlacePreview(previews, field);
			}
			
			@Override
			public StructureRelative getDefault() {
				return new StructureRelative(new LittleBox(0, 0, 0, 1, 1, 1), LittleGridContext.get());
			}
			
		});
	}
	
	public abstract T read(NBTBase nbt);
	
	public abstract NBTBase write(T value);
	
	public abstract T move(T value, LittleGridContext context, LittleVec offset);
	
	public abstract T flip(T value, LittleGridContext context, Axis axis, LittleVec doubledCenter);
	
	public abstract T rotate(T value, LittleGridContext context, Rotation rotation, LittleVec doubledCenter);
	
	public abstract T getDefault();
	
	public LittleGridContext getContext(T value) {
		return null;
	}
	
	public void convertToSmallest(T value) {
		
	}
	
	public PlacePreview getPlacePreview(T value, LittlePreviews previews, StructureDirectionalField field) {
		return null;
	}
	
}
<commit_msg>Added Vector3f as StructureDirectionalType<commit_after>package com.creativemd.littletiles.common.structure.directional;

import java.lang.reflect.Field;
import java.util.HashMap;

import javax.vecmath.Vector3f;

import com.creativemd.creativecore.common.utils.math.Rotation;
import com.creativemd.creativecore.common.utils.math.RotationUtils;
import com.creativemd.littletiles.common.structure.relative.StructureRelative;
import com.creativemd.littletiles.common.tile.math.box.LittleBox;
import com.creativemd.littletiles.common.tile.math.vec.LittleVec;
import com.creativemd.littletiles.common.tile.place.PlacePreview;
import com.creativemd.littletiles.common.tile.preview.LittlePreviews;
import com.creativemd.littletiles.common.util.grid.LittleGridContext;

import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagInt;
import net.minecraft.nbt.NBTTagIntArray;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumFacing.Axis;

public abstract class StructureDirectionalType<T> {
	
	private static HashMap<Class, StructureDirectionalType> types = new HashMap<>();
	
	public static StructureDirectionalType getType(Field field) {
		StructureDirectionalType type = types.get(field.getType());
		if (type == null)
			throw new RuntimeException("No registered directional type for " + field.getType() + ", " + field.getName());
		return type;
	}
	
	public static <T> void registerType(Class<T> clazz, StructureDirectionalType<T> type) {
		if (types.containsKey(clazz))
			throw new IllegalArgumentException("Type already exists. " + clazz);
		
		types.put(clazz, type);
	}
	
	static {
		registerType(EnumFacing.class, new StructureDirectionalType<EnumFacing>() {
			@Override
			public EnumFacing read(NBTBase nbt) {
				if (nbt instanceof NBTTagInt)
					return EnumFacing.VALUES[((NBTTagInt) nbt).getInt()];
				return null;
			}
			
			@Override
			public NBTBase write(EnumFacing value) {
				return new NBTTagInt(value.ordinal());
			}
			
			@Override
			public EnumFacing move(EnumFacing value, LittleGridContext context, LittleVec offset) {
				return value;
			}
			
			@Override
			public EnumFacing flip(EnumFacing value, LittleGridContext context, Axis axis, LittleVec doubledCenter) {
				if (axis == value.getAxis())
					return value.getOpposite();
				return value;
			}
			
			@Override
			public EnumFacing rotate(EnumFacing value, LittleGridContext context, Rotation rotation, LittleVec doubledCenter) {
				return RotationUtils.rotate(value, rotation);
			}
			
			@Override
			public EnumFacing getDefault() {
				return EnumFacing.EAST;
			}
		});
		registerType(Axis.class, new StructureDirectionalType<Axis>() {
			
			@Override
			public Axis read(NBTBase nbt) {
				if (nbt instanceof NBTTagInt)
					return Axis.values()[((NBTTagInt) nbt).getInt()];
				return null;
			}
			
			@Override
			public NBTBase write(Axis value) {
				return new NBTTagInt(value.ordinal());
			}
			
			@Override
			public Axis move(Axis value, LittleGridContext context, LittleVec offset) {
				return value;
			}
			
			@Override
			public Axis flip(Axis value, LittleGridContext context, Axis axis, LittleVec doubledCenter) {
				return value;
			}
			
			@Override
			public Axis rotate(Axis value, LittleGridContext context, Rotation rotation, LittleVec doubledCenter) {
				return RotationUtils.rotate(value, rotation);
			}
			
			@Override
			public Axis getDefault() {
				return Axis.X;
			}
			
		});
		registerType(StructureRelative.class, new StructureDirectionalType<StructureRelative>() {
			
			@Override
			public StructureRelative read(NBTBase nbt) {
				if (nbt instanceof NBTTagIntArray)
					return new StructureRelative(((NBTTagIntArray) nbt).getIntArray());
				return null;
			}
			
			@Override
			public NBTBase write(StructureRelative value) {
				return new NBTTagIntArray(value.write());
			}
			
			@Override
			public StructureRelative move(StructureRelative value, LittleGridContext context, LittleVec offset) {
				value.move(context, offset);
				return value;
			}
			
			@Override
			public StructureRelative flip(StructureRelative value, LittleGridContext context, Axis axis, LittleVec doubledCenter) {
				value.flip(context, axis, doubledCenter);
				return value;
			}
			
			@Override
			public StructureRelative rotate(StructureRelative value, LittleGridContext context, Rotation rotation, LittleVec doubledCenter) {
				value.rotate(context, rotation, doubledCenter);
				return value;
			}
			
			@Override
			public LittleGridContext getContext(StructureRelative value) {
				return value.getContext();
			}
			
			@Override
			public void convertToSmallest(StructureRelative value) {
				value.convertToSmallest();
			}
			
			@Override
			public PlacePreview getPlacePreview(StructureRelative value, LittlePreviews previews, StructureDirectionalField field) {
				return value.getPlacePreview(previews, field);
			}
			
			@Override
			public StructureRelative getDefault() {
				return new StructureRelative(new LittleBox(0, 0, 0, 1, 1, 1), LittleGridContext.get());
			}
			
		});
		registerType(Vector3f.class, new StructureDirectionalType<Vector3f>() {
			
			@Override
			public Vector3f read(NBTBase nbt) {
				if (nbt instanceof NBTTagIntArray) {
					int[] array = ((NBTTagIntArray) nbt).getIntArray();
					if (array.length == 3)
						return new Vector3f(Float.intBitsToFloat(array[0]), Float.intBitsToFloat(array[1]), Float.intBitsToFloat(array[2]));
				}
				return null;
			}
			
			@Override
			public NBTBase write(Vector3f value) {
				return new NBTTagIntArray(new int[] { Float.floatToIntBits(value.x), Float.floatToIntBits(value.y), Float.floatToIntBits(value.z) });
			}
			
			@Override
			public Vector3f move(Vector3f value, LittleGridContext context, LittleVec offset) {
				return value;
			}
			
			@Override
			public Vector3f flip(Vector3f value, LittleGridContext context, Axis axis, LittleVec doubledCenter) {
				RotationUtils.flip(value, axis);
				return value;
			}
			
			@Override
			public Vector3f rotate(Vector3f value, LittleGridContext context, Rotation rotation, LittleVec doubledCenter) {
				RotationUtils.rotate(value, rotation);
				return value;
			}
			
			@Override
			public Vector3f getDefault() {
				return new Vector3f();
			}
		});
	}
	
	public abstract T read(NBTBase nbt);
	
	public abstract NBTBase write(T value);
	
	public abstract T move(T value, LittleGridContext context, LittleVec offset);
	
	public abstract T flip(T value, LittleGridContext context, Axis axis, LittleVec doubledCenter);
	
	public abstract T rotate(T value, LittleGridContext context, Rotation rotation, LittleVec doubledCenter);
	
	public abstract T getDefault();
	
	public LittleGridContext getContext(T value) {
		return null;
	}
	
	public void convertToSmallest(T value) {
		
	}
	
	public PlacePreview getPlacePreview(T value, LittlePreviews previews, StructureDirectionalField field) {
		return null;
	}
	
}

{'fraction_non_alphanumeric': 0.09222451900143107, 'fraction_numerical': 0.0024646207664175543, 'mean_word_length': 4.178674351585014, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5941372', 'n_tokens_mistral': 4519, 'n_tokens_neox': 3669, 'n_words': 895}