Created
May 21, 2016 16:55
-
-
Save DarkArc/d71908458cd0c55ae6340b32c714c58a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SpongeBlockRegistry implements BlockRegistry<BlockSnapshot> { | |
private Map<BlockType, Integer> blockTypeMapping = new HashMap<>(); | |
private List<List<Set<BlockTrait<?>>>> typeVariants = new ArrayList<>(); | |
private List<BlockType> blockTypes = new ArrayList<>(); | |
@Override | |
public BaseBlock getType(BlockSnapshot nativeType) { | |
BlockType targetType = nativeType.getState().getType(); | |
Set<BlockTrait<?>> traitSet = new HashSet<>(nativeType.getState().getTraits()); | |
if (!blockTypeMapping.containsKey(targetType)) { | |
blockTypes.add(targetType); | |
typeVariants.add(new ArrayList<>()); | |
blockTypeMapping.put(targetType, typeVariants.size() - 1); | |
} | |
int blockId = blockTypeMapping.get(targetType); | |
List<Set<BlockTrait<?>>> blockVariants = typeVariants.get(blockId); | |
int variantId = blockVariants.indexOf(traitSet); | |
if (variantId == -1) { | |
blockVariants.add(traitSet); | |
variantId = blockVariants.size() - 1; | |
} | |
return WorldEdit.getInstance().getBaseBlockFactory().getBaseBlock(blockId, variantId); | |
} | |
@Override | |
public BlockSnapshot toNative(BaseBlock worldEditType) { | |
BlockType type = blockTypes.get(worldEditType.getType()); | |
Set<BlockTrait<?>> traitSet = typeVariants.get(worldEditType.getId()).get(worldEditType.getData()); | |
for (BlockTrait<?> trait : traitSet) { | |
BlockState.builder().blockType(type).build().withTrait(trait); | |
} | |
BlockSnapshot.builder() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment