Skip to content

Commit

Permalink
- reduced dimensions of buffered image used to create filled map to f…
Browse files Browse the repository at this point in the history
…rom 1920x1080 to 1080x1080
  • Loading branch information
HyperPigeon committed Mar 31, 2022
1 parent 5e4607e commit 77cf28b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/net/hyper_pigeon/polaroidcamera/PolaroidCamera.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
}
}

0 comments on commit 77cf28b

Please sign in to comment.