diff --git a/gradle.properties b/gradle.properties index 535cc3e..6f0681d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,7 +6,7 @@ minecraft_version=1.17.1 yarn_mappings=1.17.1+build.65 loader_version=0.13.3 # Mod Properties -mod_version=1.1.0 +mod_version=1.1.1 maven_group=net.hyper_pigeon archives_base_name=polaroidcamera # Dependencies diff --git a/src/main/java/net/hyper_pigeon/polaroidcamera/PolaroidCamera.java b/src/main/java/net/hyper_pigeon/polaroidcamera/PolaroidCamera.java index 183c6f9..1b2e569 100644 --- a/src/main/java/net/hyper_pigeon/polaroidcamera/PolaroidCamera.java +++ b/src/main/java/net/hyper_pigeon/polaroidcamera/PolaroidCamera.java @@ -61,6 +61,8 @@ public void onInitialize() { if(player.getInventory().contains(new ItemStack(Items.MAP)) || player.isCreative()) { try { BufferedImage bufferedImage = ImageIO.read(new ByteArrayInputStream(ImagePersistentState.get(player.getServerWorld()).getByteArray(identifier))); + bufferedImage = this.crop(bufferedImage,1080,1080); + ItemStack mapItemStack = MapRenderer.render(bufferedImage, Image2Map.DitherMode.FLOYD,(ServerWorld) player.getEntityWorld(), player.getX(), player.getZ(), player); ItemEntity itemEntity = new ItemEntity(player.world, player.getPos().x, player.getPos().y, player.getPos().z, mapItemStack); @@ -79,4 +81,22 @@ public void onInitialize() { } + + public BufferedImage crop(BufferedImage bufferedImage,int targetWidth, int targetHeight) throws IOException { + int height = bufferedImage.getHeight(); + int width = bufferedImage.getWidth(); + + // Coordinates of the image's middle + int xc = (width - targetWidth) / 2; + int yc = (height - targetHeight) / 2; + + // Crop + BufferedImage croppedImage = bufferedImage.getSubimage( + xc, + yc, + targetWidth, // width + targetHeight // height + ); + return croppedImage; + } }