Skip to content

Commit

Permalink
Merge PR #3389 by @pollend - block family rotation fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Cervator committed Jun 11, 2018
2 parents c42e530 + e792579 commit eada008
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ public boolean hasCategory(String category) {

@Override
public String toString() {
return "BlockFamily[" + uri.toString() + "]";
String familyType = "";
RegisterBlockFamily registerInfo = this.getClass().getAnnotation(RegisterBlockFamily.class);
if (registerInfo != null) {
familyType = registerInfo.value();
}
return "BlockFamily[" + familyType + "," + uri.toString() + "]";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class FreeformFamily extends AbstractBlockFamily {
private static final Logger logger = LoggerFactory.getLogger(FreeformFamily.class);

private Map<Side, Block> blocks = Maps.newEnumMap(Side.class);
private Block block;
private Block archetypeBlock;

public FreeformFamily(BlockFamilyDefinition definition, BlockShape shape, BlockBuilderHelper blockBuilder) {
super(definition, shape, blockBuilder);
Expand All @@ -52,11 +52,11 @@ public FreeformFamily(BlockFamilyDefinition definition, BlockShape shape, BlockB
uri = new BlockUri(definition.getUrn(), shape.getUrn());
}
if (shape.isCollisionYawSymmetric()) {
block = blockBuilder.constructSimpleBlock(definition, shape, uri, this);
archetypeBlock = blockBuilder.constructSimpleBlock(definition, shape, uri, this);
} else {
for (Rotation rot : Rotation.horizontalRotations()) {
Side side = rot.rotate(Side.FRONT);
block = blockBuilder.constructTransformedBlock(definition, shape, side.toString().toLowerCase(Locale.ENGLISH), rot,
Block block = blockBuilder.constructTransformedBlock(definition, shape, side.toString().toLowerCase(Locale.ENGLISH), rot,
new BlockUri(uri, new Name(side.name())), this);
if (block == null) {
throw new IllegalArgumentException("Missing block for side: " + side.toString());
Expand All @@ -76,7 +76,7 @@ public FreeformFamily(BlockFamilyDefinition blockFamilyDefinition, BlockBuilderH

@Override
public Block getBlockForPlacement(Vector3i location, Side attachmentSide, Side direction) {
if (block == null) {
if (archetypeBlock == null) {
if (attachmentSide.isHorizontal()) {
return blocks.get(attachmentSide);
}
Expand All @@ -86,15 +86,15 @@ public Block getBlockForPlacement(Vector3i location, Side attachmentSide, Side d
return blocks.get(Side.FRONT);
}
}
return block;
return archetypeBlock;
}

@Override
public Block getArchetypeBlock() {
if (block == null) {
if (archetypeBlock == null) {
return blocks.get(this.getArchetypeSide());
}
return block;
return archetypeBlock;
}

protected Side getArchetypeSide() {
Expand All @@ -103,7 +103,7 @@ protected Side getArchetypeSide() {

@Override
public Block getBlockFor(BlockUri blockUri) {
if (block == null && getURI().equals(blockUri.getFamilyUri())) {
if (archetypeBlock == null && getURI().equals(blockUri.getFamilyUri())) {
try {
Side side = Side.valueOf(blockUri.getIdentifier().toString().toUpperCase(Locale.ENGLISH));
return blocks.get(side);
Expand All @@ -113,15 +113,15 @@ public Block getBlockFor(BlockUri blockUri) {
}

}
return block;
return archetypeBlock;
}

@Override
public Iterable<Block> getBlocks() {
if (block == null) {
if (archetypeBlock == null) {
return blocks.values();
}
return Arrays.asList(block);
return Arrays.asList(archetypeBlock);
}

}

0 comments on commit eada008

Please sign in to comment.