Created CustomObjectRenderer to allow for BufferedImages to be rendered at a given Position. This supports Zoom and Rotation on all 3 axes.

This commit is contained in:
CrushedPixel
2015-07-06 00:28:57 +02:00
parent 49e391555c
commit 013d5963ff
6 changed files with 208 additions and 7 deletions

View File

@@ -0,0 +1,57 @@
package eu.crushedpixel.replaymod.holders;
import eu.crushedpixel.replaymod.registry.ResourceHelper;
import lombok.Getter;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.texture.DynamicTexture;
import net.minecraft.util.ResourceLocation;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
public class CustomImageObject {
public CustomImageObject(Position position, String name, File imageSource) throws IOException {
BufferedImage bufferedImage = ImageIO.read(imageSource);
this.textureWidth = bufferedImage.getWidth();
this.textureHeight = bufferedImage.getHeight();
float w;
float h;
if(bufferedImage.getWidth() > bufferedImage.getHeight()) {
w = 1;
h = (bufferedImage.getHeight()/(float)bufferedImage.getWidth());
} else {
w = (bufferedImage.getWidth()/(float)bufferedImage.getHeight());
h = 1;
}
this.position = new ExtendedPosition(position.getX(), position.getY(), position.getZ(), w, h);
this.name = name;
this.resourceLocation = new ResourceLocation("customImages/"+imageSource.getAbsolutePath());
this.dynamicTexture = new DynamicTexture(bufferedImage);
}
@Getter private ExtendedPosition position;
@Getter private String name;
private ResourceLocation resourceLocation;
private DynamicTexture dynamicTexture;
@Getter private float textureWidth, textureHeight;
public ResourceLocation getResourceLocation() {
if(!ResourceHelper.isRegistered(resourceLocation)) {
ResourceHelper.registerResource(resourceLocation);
Minecraft.getMinecraft().getTextureManager().loadTexture(resourceLocation, dynamicTexture);
dynamicTexture.updateDynamicTexture();
}
return resourceLocation;
}
}

View File

@@ -0,0 +1,18 @@
package eu.crushedpixel.replaymod.holders;
import lombok.Data;
@Data
public class ExtendedPosition extends Position {
public ExtendedPosition(double x, double y, double z, float width, float height) {
super(x, y, z, 0, 0);
this.width = width;
this.height = height;
}
private float anchorX, anchorY;
private float width, height;
private float scale = 1f;
}