-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
completed kyoyu placement meta saving
- Loading branch information
1 parent
d600b0d
commit 33fce54
Showing
12 changed files
with
192 additions
and
38 deletions.
There are no files selected for viewing
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
11 changes: 11 additions & 0 deletions
11
src/main/java/com/vulpeus/kyoyu/client/ISchematicPlacement.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.vulpeus.kyoyu.client; | ||
|
||
import java.util.UUID; | ||
|
||
public interface ISchematicPlacement { | ||
|
||
void kyoyu$setKyoyuId(UUID uuid); | ||
|
||
UUID kyoyu$getKyoyuId(); | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
src/main/java/com/vulpeus/kyoyu/client/LitematicHelper.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.vulpeus.kyoyu.client; | ||
|
||
//? if client { | ||
import com.vulpeus.kyoyu.placement.KyoyuPlacement; | ||
import com.vulpeus.kyoyu.placement.KyoyuRegion; | ||
import fi.dy.masa.litematica.data.DataManager; | ||
import fi.dy.masa.litematica.schematic.placement.SchematicPlacement; | ||
|
||
public class LitematicHelper { | ||
|
||
public static void newSchematicPlacementFromKyoyuPlacement(SchematicPlacement schematicPlacement, KyoyuPlacement kyoyuPlacement) { | ||
|
||
changeSchematicPlacementFromKyoyuPlacement(schematicPlacement, kyoyuPlacement); | ||
DataManager.getSchematicPlacementManager().addSchematicPlacement(schematicPlacement, true); | ||
((ISchematicPlacement) schematicPlacement).kyoyu$setKyoyuId(kyoyuPlacement.getUuid()); | ||
|
||
} | ||
|
||
public static void changeSchematicPlacementFromKyoyuPlacement(SchematicPlacement schematicPlacement, KyoyuPlacement kyoyuPlacement) { | ||
|
||
if (schematicPlacement.isLocked()) { | ||
schematicPlacement.toggleLocked(); | ||
} | ||
|
||
schematicPlacement.setMirror(kyoyuPlacement.getRegion().getMirror(), null); | ||
schematicPlacement.setRotation(kyoyuPlacement.getRegion().getRotation(), null); | ||
for (KyoyuRegion subRegion: kyoyuPlacement.getSubRegions()) { | ||
String subRegionName = subRegion.getName(); | ||
|
||
schematicPlacement.moveSubRegionTo(subRegionName, subRegion.getPos(), null); | ||
schematicPlacement.setSubRegionMirror(subRegionName, subRegion.getMirror(), null); | ||
schematicPlacement.setSubRegionRotation(subRegionName, subRegion.getRotation(), null); | ||
} | ||
schematicPlacement.toggleLocked(); | ||
|
||
} | ||
} | ||
//?} |
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
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
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
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
52 changes: 51 additions & 1 deletion
52
src/main/java/com/vulpeus/kyoyu/client/mixins/litematica/SchematicPlacementMixin.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,70 @@ | ||
package com.vulpeus.kyoyu.client.mixins.litematica; | ||
|
||
//? if client { | ||
import com.google.gson.JsonObject; | ||
import com.google.gson.JsonPrimitive; | ||
import com.vulpeus.kyoyu.Kyoyu; | ||
import com.vulpeus.kyoyu.client.ISchematicPlacement; | ||
import com.vulpeus.kyoyu.client.LitematicHelper; | ||
import com.vulpeus.kyoyu.placement.KyoyuPlacement; | ||
import fi.dy.masa.litematica.schematic.placement.SchematicPlacement; | ||
import fi.dy.masa.litematica.schematic.placement.SchematicPlacementManager; | ||
import fi.dy.masa.malilib.util.JsonUtils; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Unique; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
|
||
import java.util.UUID; | ||
|
||
@Mixin(SchematicPlacement.class) | ||
public class SchematicPlacementMixin { | ||
public class SchematicPlacementMixin implements ISchematicPlacement { | ||
|
||
@Unique | ||
private UUID kyoyu_id; | ||
|
||
@Override | ||
public void kyoyu$setKyoyuId(UUID uuid) { | ||
kyoyu_id = uuid; | ||
} | ||
|
||
@Override | ||
public UUID kyoyu$getKyoyuId() { | ||
return kyoyu_id; | ||
} | ||
|
||
@Inject(method = "onModified(Lfi/dy/masa/litematica/schematic/placement/SchematicPlacementManager;)V", at = @At("HEAD"), remap = false) | ||
public void onModified(SchematicPlacementManager manager, CallbackInfo ci) { | ||
// TODO | ||
// attention when connecting server is compatible | ||
// if (getClient() != null) | ||
} | ||
|
||
@Inject(method = "toJson", at = @At("RETURN"), remap = false) | ||
public void saveToJson(CallbackInfoReturnable<JsonObject> cir) { | ||
JsonObject saveData = cir.getReturnValue(); | ||
if (saveData != null) { | ||
saveData.add("kyoyu_id", new JsonPrimitive(kyoyu_id.toString())); | ||
} | ||
} | ||
|
||
@Inject(method = "fromJson", at = @At("RETURN"), remap = false, cancellable = true) | ||
private static void loadFromJson(JsonObject obj, CallbackInfoReturnable<SchematicPlacement> cir) { | ||
if (JsonUtils.hasString(obj, "kyoyu_id")) { | ||
SchematicPlacement self = cir.getReturnValue(); | ||
if (self != null) { | ||
UUID uuid = UUID.fromString(obj.get("kyoyu_id").getAsString()); | ||
((ISchematicPlacement) self).kyoyu$setKyoyuId(uuid); | ||
cir.setReturnValue(null); | ||
|
||
KyoyuPlacement kyoyuPlacement = Kyoyu.findPlacement(uuid); | ||
if (kyoyuPlacement != null) { | ||
LitematicHelper.newSchematicPlacementFromKyoyuPlacement(self, kyoyuPlacement); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
//?} |
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
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
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
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