-
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.
Merge branch 'main' of github.com:SpiritGameStudios/Snapper
- Loading branch information
Showing
9 changed files
with
164 additions
and
10 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
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
20 changes: 20 additions & 0 deletions
20
src/client/java/dev/spiritstudios/snapper/mixin/CameraMixin.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,20 @@ | ||
package dev.spiritstudios.snapper.mixin; | ||
|
||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.client.render.Camera; | ||
import net.minecraft.entity.Entity; | ||
import net.minecraft.world.BlockView; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
@Mixin(Camera.class) | ||
public class CameraMixin { | ||
@Inject(method = "update", at = @At("HEAD"), cancellable = true) | ||
private void blockUpdateDuringPanoRender(BlockView area, Entity focusedEntity, boolean thirdPerson, boolean inverseView, float tickDelta, CallbackInfo ci) { | ||
if (MinecraftClient.getInstance().gameRenderer.isRenderingPanorama() && thirdPerson) { | ||
ci.cancel(); | ||
} | ||
} | ||
} |
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
44 changes: 44 additions & 0 deletions
44
src/client/java/dev/spiritstudios/snapper/mixin/ScreenshotRecorderMixin.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,44 @@ | ||
package dev.spiritstudios.snapper.mixin; | ||
|
||
import dev.spiritstudios.snapper.mixinsupport.ImageTransferable; | ||
import net.minecraft.client.texture.NativeImage; | ||
import net.minecraft.client.util.ScreenshotRecorder; | ||
import net.minecraft.text.Text; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
import javax.imageio.ImageIO; | ||
import java.awt.*; | ||
import java.awt.datatransfer.Clipboard; | ||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.function.Consumer; | ||
|
||
@Mixin(ScreenshotRecorder.class) | ||
public class ScreenshotRecorderMixin { | ||
/** | ||
* @author hama | ||
* @reason check if pano file exists before writing to it | ||
*/ | ||
@Inject( | ||
method = "method_1661", | ||
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/texture/NativeImage;writeTo(Ljava/io/File;)V") | ||
) | ||
private static void lookBeforeYouLeap(NativeImage nativeImage, File screenshotFile, Consumer<Text> messageReceiver, CallbackInfo ci) throws IOException { | ||
screenshotFile.getParentFile().mkdirs(); | ||
screenshotFile.createNewFile(); | ||
} | ||
|
||
@Inject( | ||
method = "method_1661", | ||
at = @At(value = "INVOKE", target = "Lnet/minecraft/text/Text;literal(Ljava/lang/String;)Lnet/minecraft/text/MutableText;", shift = At.Shift.AFTER) | ||
) | ||
private static void saveWrittenFileToClipboard(NativeImage nativeImage, File screenshotFile, Consumer<Text> messageReceiver, CallbackInfo ci) throws IOException { | ||
if (!screenshotFile.getAbsolutePath().contains("/panorama/")) { | ||
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); | ||
clipboard.setContents(new ImageTransferable(ImageIO.read(screenshotFile)), null); | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/client/java/dev/spiritstudios/snapper/mixin/accessor/CameraAccessor.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 dev.spiritstudios.snapper.mixin.accessor; | ||
|
||
import net.minecraft.client.render.Camera; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.gen.Invoker; | ||
|
||
@Mixin(Camera.class) | ||
public interface CameraAccessor { | ||
@Invoker | ||
void invokeSetRotation(float yaw, float pitch); | ||
} |
36 changes: 36 additions & 0 deletions
36
src/client/java/dev/spiritstudios/snapper/mixinsupport/ImageTransferable.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,36 @@ | ||
package dev.spiritstudios.snapper.mixinsupport; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.awt.*; | ||
import java.awt.datatransfer.DataFlavor; | ||
import java.awt.datatransfer.Transferable; | ||
import java.awt.datatransfer.UnsupportedFlavorException; | ||
import java.io.IOException; | ||
|
||
public class ImageTransferable implements Transferable { | ||
private static final DataFlavor[] flavors = {DataFlavor.imageFlavor}; | ||
|
||
private final Image image; | ||
|
||
public ImageTransferable(Image im) { | ||
this.image = im; | ||
} | ||
|
||
@Override | ||
public DataFlavor[] getTransferDataFlavors() { | ||
return flavors; | ||
} | ||
|
||
@Override | ||
public boolean isDataFlavorSupported(DataFlavor flavor) { | ||
return flavor.equals(DataFlavor.imageFlavor); | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException { | ||
if (!isDataFlavorSupported(flavor)) throw new UnsupportedFlavorException(flavor); | ||
return image; | ||
} | ||
} |
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