Skip to content

Commit

Permalink
fix auto upgrade to level 5 when resolving rotation
Browse files Browse the repository at this point in the history
  • Loading branch information
Raycoms committed Sep 12, 2024
1 parent 4448b3f commit 4a9275f
Showing 1 changed file with 35 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ public RotationMirror getRotationMirror()
{
if (rotationMirror == null)
{
processBlueprint(StructurePacks.getBlueprint(this.packMeta, this.path.replace("0.blueprint", "1.blueprint"), level.registryAccess()));
calcRotation(StructurePacks.getBlueprint(this.packMeta, this.path.replace("0.blueprint", "1.blueprint"), level.registryAccess()));
}
return rotationMirror;
}
Expand Down Expand Up @@ -681,42 +681,46 @@ private void processBlueprint(final Blueprint blueprint)
return;
}

final BlockState structureState = blueprint.getBlockState(blueprint.getPrimaryBlockOffset());
if (structureState != null)
calcRotation(blueprint);

final BlockInfo info = blueprint.getBlockInfoAsMap().getOrDefault(blueprint.getPrimaryBlockOffset(), null);

if (info.getTileEntityData() != null)
{
if (!(structureState.getBlock() instanceof AbstractBlockHut) || !(level.getBlockState(this.getPosition()).getBlock() instanceof AbstractBlockHut))
{
Log.getLogger().error(String.format("Schematic %s doesn't have a correct Primary Offset", blueprint.getName()));
return;
}
final int structureRotation = structureState.getValue(AbstractBlockHut.FACING).get2DDataValue();
final int worldRotation = level.getBlockState(this.getPosition()).getValue(AbstractBlockHut.FACING).get2DDataValue();
final CompoundTag teCompound = info.getTileEntityData().copy();
final CompoundTag tagData = teCompound.getCompound(TAG_BLUEPRINTDATA);

final int rotation;
if (structureRotation <= worldRotation)
{
rotation = worldRotation - structureRotation;
}
else
{
rotation = 4 + worldRotation - structureRotation;
}
tagData.putString(TAG_PACK, blueprint.getPackName());
final String location = StructurePacks.getStructurePack(blueprint.getPackName()).getSubPath(blueprint.getFilePath().resolve(blueprint.getFileName()));
tagData.putString(TAG_NAME, location);
this.readSchematicDataFromNBT(teCompound);
}
}

rotationMirror = RotationMirror.of(Rotation.values()[rotation], rotationMirror == null ? Mirror.NONE : rotationMirror.mirror());
blueprint.setRotationMirror(rotationMirror, level);
final BlockInfo info = blueprint.getBlockInfoAsMap().getOrDefault(blueprint.getPrimaryBlockOffset(), null);
private void calcRotation(final Blueprint blueprint)
{
final BlockState structureState = blueprint.getBlockState(blueprint.getPrimaryBlockOffset());
if (structureState == null || !(structureState.getBlock() instanceof AbstractBlockHut) || !(level.getBlockState(this.getPosition()).getBlock() instanceof AbstractBlockHut))
{
rotationMirror = RotationMirror.NONE;
return;
}

if (info.getTileEntityData() != null)
{
final CompoundTag teCompound = info.getTileEntityData().copy();
final CompoundTag tagData = teCompound.getCompound(TAG_BLUEPRINTDATA);
final int structureRotation = structureState.getValue(AbstractBlockHut.FACING).get2DDataValue();
final int worldRotation = level.getBlockState(this.getPosition()).getValue(AbstractBlockHut.FACING).get2DDataValue();

tagData.putString(TAG_PACK, blueprint.getPackName());
final String location = StructurePacks.getStructurePack(blueprint.getPackName()).getSubPath(blueprint.getFilePath().resolve(blueprint.getFileName()));
tagData.putString(TAG_NAME, location);
this.readSchematicDataFromNBT(teCompound);
}
final int rotation;
if (structureRotation <= worldRotation)
{
rotation = worldRotation - structureRotation;
}
else
{
rotation = 4 + worldRotation - structureRotation;
}

rotationMirror = RotationMirror.of(Rotation.values()[rotation], rotationMirror == null ? Mirror.NONE : rotationMirror.mirror());
blueprint.setRotationMirror(rotationMirror, level);
}

/**
Expand Down

0 comments on commit 4a9275f

Please sign in to comment.