mirror of
https://github.com/GTNewHorizons/Chisel.git
synced 2026-11-25 06:34:35 +00:00
Compare commits
10
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7f1602d7b1 | ||
|
|
3d764c434c | ||
|
|
6eed99f030 | ||
|
|
c1e8606629 | ||
|
|
9da5b2b6b5 | ||
|
|
5d33558697 | ||
|
|
36f517cb46 | ||
|
|
68d65d23ed | ||
|
|
ec607a41ed | ||
|
|
3a0676fcf5 |
No files matched your search
@@ -25,7 +25,6 @@ whitelist.json
|
||||
*.iml
|
||||
*.ipr
|
||||
*.iws
|
||||
src/main/resources/mixins.*.json
|
||||
*.bat
|
||||
layout.json
|
||||
.DS_Store
|
||||
+9
-4
@@ -69,7 +69,7 @@ enableModernJavaSyntax = jabel
|
||||
|
||||
# Enables injecting missing generics into the decompiled source code for a better coding experience.
|
||||
# Turns most publicly visible List, Map, etc. into proper List<E>, Map<K, V> types.
|
||||
enableGenericInjection = false
|
||||
enableGenericInjection = true
|
||||
|
||||
# Generate a class with a String field for the mod version named as defined below.
|
||||
# If generateGradleTokenClass is empty or not missing, no such class will be generated.
|
||||
@@ -107,7 +107,7 @@ apiPackage = api
|
||||
accessTransformersFile = chisel_compile_at.cfg
|
||||
|
||||
# Provides setup for Mixins if enabled. If you don't know what mixins are: Keep it disabled!
|
||||
usesMixins = false
|
||||
usesMixins = true
|
||||
|
||||
# Set to a non-empty string to configure mixins in a separate source set under src/VALUE, instead of src/main.
|
||||
# This can speed up compile times thanks to not running the mixin annotation processor on all input sources.
|
||||
@@ -115,7 +115,7 @@ usesMixins = false
|
||||
separateMixinSourceSet =
|
||||
|
||||
# Adds some debug arguments like verbose output and class export.
|
||||
usesMixinDebug = false
|
||||
usesMixinDebug = true
|
||||
|
||||
# Specify the location of your implementation of IMixinConfigPlugin. Leave it empty otherwise.
|
||||
mixinPlugin =
|
||||
@@ -123,7 +123,7 @@ mixinPlugin =
|
||||
# Specify the package that contains all of your Mixins. The package must exist or
|
||||
# the build will fail. If you have a package property defined in your mixins.<modid>.json,
|
||||
# it must match with this or the build will fail.
|
||||
mixinsPackage =
|
||||
mixinsPackage = mixins
|
||||
|
||||
# Specify the core mod entry class if you use a core mod. This class must implement IFMLLoadingPlugin!
|
||||
# This parameter is for legacy compatibility only
|
||||
@@ -186,6 +186,11 @@ modrinthRelations =
|
||||
# Leave this empty if you don't want to publish on CurseForge.
|
||||
curseForgeProjectId =
|
||||
|
||||
# Comma-separated supported CurseForge environments: client, server (case-insensitive).
|
||||
# Use client or server for mods that only support one environment. Defaults to client,server.
|
||||
# These tags describe where the mod can run, not whether installation is required on both sides.
|
||||
curseForgeEnvironments = client,server
|
||||
|
||||
# The project's relations on CurseForge. You can use this to refer to other projects on CurseForge.
|
||||
# Syntax: type1:name1;type2:name2;...
|
||||
# Where type can be one of [requiredDependency, embeddedLibrary, optionalDependency, tool, incompatible],
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
#This file is generated by updateDaemonJvm
|
||||
toolchainUrl.FREE_BSD.AARCH64=https\://api.foojay.io/disco/v3.0/ids/1630f7ebef05444cb27a2709ea0249b3/redirect
|
||||
toolchainUrl.FREE_BSD.X86_64=https\://api.foojay.io/disco/v3.0/ids/cd495626d2ee49a75447e3fdc6afb287/redirect
|
||||
toolchainUrl.LINUX.AARCH64=https\://api.foojay.io/disco/v3.0/ids/1630f7ebef05444cb27a2709ea0249b3/redirect
|
||||
toolchainUrl.LINUX.X86_64=https\://api.foojay.io/disco/v3.0/ids/cd495626d2ee49a75447e3fdc6afb287/redirect
|
||||
toolchainUrl.MAC_OS.AARCH64=https\://api.foojay.io/disco/v3.0/ids/d4fd992c9557644e637ebe98263e0ae7/redirect
|
||||
toolchainUrl.MAC_OS.X86_64=https\://api.foojay.io/disco/v3.0/ids/faa12903720d410b387cc69ccafb1a74/redirect
|
||||
toolchainUrl.UNIX.AARCH64=https\://api.foojay.io/disco/v3.0/ids/1630f7ebef05444cb27a2709ea0249b3/redirect
|
||||
toolchainUrl.UNIX.X86_64=https\://api.foojay.io/disco/v3.0/ids/cd495626d2ee49a75447e3fdc6afb287/redirect
|
||||
toolchainUrl.WINDOWS.AARCH64=https\://api.foojay.io/disco/v3.0/ids/a4c09dd2e2d7079373d30e524bbc2829/redirect
|
||||
toolchainUrl.WINDOWS.X86_64=https\://api.foojay.io/disco/v3.0/ids/8e1d9ee5d0f13e442218f6884a306da1/redirect
|
||||
toolchainUrl.FREE_BSD.AARCH64=https\://api.foojay.io/disco/v3.0/ids/539ea72837c6244075f8ee037babc29e/redirect
|
||||
toolchainUrl.FREE_BSD.X86_64=https\://api.foojay.io/disco/v3.0/ids/876dbbf00bf4ef6190f7da074cee903a/redirect
|
||||
toolchainUrl.LINUX.AARCH64=https\://api.foojay.io/disco/v3.0/ids/539ea72837c6244075f8ee037babc29e/redirect
|
||||
toolchainUrl.LINUX.X86_64=https\://api.foojay.io/disco/v3.0/ids/876dbbf00bf4ef6190f7da074cee903a/redirect
|
||||
toolchainUrl.MAC_OS.AARCH64=https\://api.foojay.io/disco/v3.0/ids/9064f22734b42ac03e85df04b632e167/redirect
|
||||
toolchainUrl.MAC_OS.X86_64=https\://api.foojay.io/disco/v3.0/ids/4d0277c49991306ac78048580fe34bcf/redirect
|
||||
toolchainUrl.UNIX.AARCH64=https\://api.foojay.io/disco/v3.0/ids/539ea72837c6244075f8ee037babc29e/redirect
|
||||
toolchainUrl.UNIX.X86_64=https\://api.foojay.io/disco/v3.0/ids/876dbbf00bf4ef6190f7da074cee903a/redirect
|
||||
toolchainUrl.WINDOWS.AARCH64=https\://api.foojay.io/disco/v3.0/ids/a9fa3b809e484a1e1ac4308a5dda661a/redirect
|
||||
toolchainUrl.WINDOWS.X86_64=https\://api.foojay.io/disco/v3.0/ids/aa99913fa6d767d899ffc96082da01ca/redirect
|
||||
toolchainVersion=25
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-9.4.0-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-9.7.1-bin.zip
|
||||
networkTimeout=10000
|
||||
validateDistributionUrl=true
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@ pluginManagement {
|
||||
}
|
||||
|
||||
plugins {
|
||||
id 'com.gtnewhorizons.gtnhsettingsconvention' version '2.0.24'
|
||||
id 'com.gtnewhorizons.gtnhsettingsconvention' version '2.0.32'
|
||||
}
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ import team.chisel.ctmlib.ISubmapManager;
|
||||
import team.chisel.ctmlib.RenderBlocksCTM;
|
||||
import team.chisel.ctmlib.RenderBlocksColumn;
|
||||
import team.chisel.ctmlib.TextureSubmap;
|
||||
import team.chisel.ctmlib.TextureSubmapCTM;
|
||||
|
||||
/**
|
||||
* Handles all default {@link ISubmapManager} behavior
|
||||
@@ -197,8 +198,8 @@ public enum TextureType {
|
||||
IIcon baseIcon = register.registerIcon(modName + ":" + texturePath);
|
||||
return Triple.of(
|
||||
baseIcon,
|
||||
new TextureSubmap(register.registerIcon(modName + ":" + texturePath + "-ctm"), 4, 4),
|
||||
new TextureSubmap(baseIcon, 2, 2)
|
||||
new TextureSubmapCTM(register.registerIcon(modName + ":" + texturePath + "-ctm"), 4),
|
||||
new TextureSubmapCTM(baseIcon, 2)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
package com.cricketcraft.chisel.mixins;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.client.resources.FallbackResourceManager;
|
||||
import net.minecraft.client.resources.IResource;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
import team.chisel.ctmlib.TextureSubmapResource;
|
||||
|
||||
/**
|
||||
* Provides generated resources for independently stitched CTM submap sprites.
|
||||
* <p>
|
||||
* For example, a request for chisel:textures/blocks/__chisel_submap/2x2/1_0/foo.png is resolved from
|
||||
* chisel:textures/blocks/foo.png and cropped to its top-right tile. This lets Minecraft and other mods treat each
|
||||
* submap sprite like an ordinary texture resource.
|
||||
*/
|
||||
@Mixin(FallbackResourceManager.class)
|
||||
public abstract class MixinFallbackResourceManager {
|
||||
|
||||
@Shadow
|
||||
public abstract IResource getResource(ResourceLocation location) throws IOException;
|
||||
|
||||
@Shadow
|
||||
public abstract List<IResource> getAllResources(ResourceLocation location) throws IOException;
|
||||
|
||||
@Inject(method = "getResource", at = @At("HEAD"), cancellable = true)
|
||||
private void chisel$getSubmapResource(ResourceLocation location, CallbackInfoReturnable<IResource> cir)
|
||||
throws IOException {
|
||||
|
||||
TextureSubmapResource.SubmapLocation submap = TextureSubmapResource.parse(location);
|
||||
if (submap == null) return;
|
||||
|
||||
IResource source = getResource(submap.source());
|
||||
cir.setReturnValue(new TextureSubmapResource(source, submap, true));
|
||||
}
|
||||
|
||||
@Inject(method = "getAllResources", at = @At("HEAD"), cancellable = true)
|
||||
private void chisel$getAllSubmapResources(ResourceLocation location, CallbackInfoReturnable<List<IResource>> cir)
|
||||
throws IOException {
|
||||
|
||||
TextureSubmapResource.SubmapLocation submap = TextureSubmapResource.parse(location);
|
||||
if (submap == null) return;
|
||||
|
||||
List<IResource> sources = getAllResources(submap.source());
|
||||
List<IResource> resources = new ArrayList<>(sources.size());
|
||||
|
||||
for (IResource source : sources) {
|
||||
// Different resource packs may provide different images for the same location, so we can't cache them
|
||||
resources.add(new TextureSubmapResource(source, submap, false));
|
||||
}
|
||||
|
||||
cir.setReturnValue(resources);
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package team.chisel.block.tileentity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -63,6 +64,7 @@ public class TileEntityAutoChisel extends TileEntity implements ISidedInventory
|
||||
|
||||
private int progress = 0;
|
||||
|
||||
private static EntityItem ghostItem;
|
||||
boolean equal = false;
|
||||
private ItemStack[] inventory = new ItemStack[8];
|
||||
private String name = "autoChisel";
|
||||
@@ -405,15 +407,27 @@ public class TileEntityAutoChisel extends TileEntity implements ISidedInventory
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public ItemStack getItemForRendering(int slot) {
|
||||
public EntityItem getItemForRendering(int slot) {
|
||||
if (ghostItem == null) {
|
||||
ghostItem = new EntityItem(worldObj);
|
||||
ghostItem.hoverStart = 0.0F;
|
||||
}
|
||||
|
||||
if (slot == BASE && lastBase != null) {
|
||||
return lastBase.copy();
|
||||
ghostItem.setEntityItemStack(lastBase.copy());
|
||||
return ghostItem;
|
||||
} else if (slot == TARGET) {
|
||||
return getTarget();
|
||||
ItemStack target = getTarget();
|
||||
if (target != null) {
|
||||
ghostItem.setEntityItemStack(target);
|
||||
return ghostItem;
|
||||
}
|
||||
return null;
|
||||
} else if (inventory[slot] == null) {
|
||||
return null;
|
||||
} else {
|
||||
return inventory[slot].copy();
|
||||
ghostItem.setEntityItemStack(inventory[slot].copy());
|
||||
return ghostItem;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ import cpw.mods.fml.relauncher.SideOnly;
|
||||
import team.chisel.ctmlib.Drawing;
|
||||
import team.chisel.ctmlib.RenderBlocksCTM;
|
||||
import team.chisel.ctmlib.TextureSubmap;
|
||||
import team.chisel.ctmlib.TextureSubmapCTM;
|
||||
import team.chisel.init.ChiselBlocks;
|
||||
|
||||
public class SubmapManagerAntiblock extends SubmapManagerBase {
|
||||
@@ -93,8 +94,8 @@ public class SubmapManagerAntiblock extends SubmapManagerBase {
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void registerIcons(String modName, Block block, IIconRegister register) {
|
||||
submap = new TextureSubmap(register.registerIcon(modName + ":antiblock/" + color + "-antiBlock-ctm"), 4, 4);
|
||||
submapSmall = new TextureSubmap(register.registerIcon(modName + ":antiblock/" + color + "-antiBlock"), 2, 2);
|
||||
submap = new TextureSubmapCTM(register.registerIcon(modName + ":antiblock/" + color + "-antiBlock-ctm"), 4);
|
||||
submapSmall = new TextureSubmapCTM(register.registerIcon(modName + ":antiblock/" + color + "-antiBlock"), 2);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -11,6 +11,7 @@ import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import team.chisel.ctmlib.RenderBlocksCTM;
|
||||
import team.chisel.ctmlib.TextureSubmap;
|
||||
import team.chisel.ctmlib.TextureSubmapCTM;
|
||||
|
||||
public class SubmapManagerCarpetFloor extends SubmapManagerBase {
|
||||
|
||||
@@ -39,8 +40,8 @@ public class SubmapManagerCarpetFloor extends SubmapManagerBase {
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void registerIcons(String modName, Block block, IIconRegister register) {
|
||||
String path = modName + ":carpet/" + color;
|
||||
submap = new TextureSubmap(register.registerIcon(path + "-ctm"), 4, 4);
|
||||
submapSmall = new TextureSubmap(register.registerIcon(path), 2, 2);
|
||||
submap = new TextureSubmapCTM(register.registerIcon(path + "-ctm"), 4);
|
||||
submapSmall = new TextureSubmapCTM(register.registerIcon(path), 2);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -3,6 +3,7 @@ package team.chisel.client.render;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.renderer.RenderBlocks;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.client.renderer.texture.TextureMap;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
@@ -89,12 +90,9 @@ public class SubmapManagerCombinedCTM extends SubmapManagerBase {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void texturesStitched() {
|
||||
public void registerSubIcons(TextureMap textureMap) {
|
||||
for (int i = 0; i < icons.length; i++) {
|
||||
for (int j = 0; j < icons[i].length; j++) {
|
||||
icons[i][j] = submap[i][j];
|
||||
submap[i][j].texturesStitched();
|
||||
}
|
||||
System.arraycopy(submap[i], 0, icons[i], 0, icons[i].length);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import cpw.mods.fml.relauncher.SideOnly;
|
||||
import team.chisel.ctmlib.ISubmapManager;
|
||||
import team.chisel.ctmlib.RenderBlocksCTM;
|
||||
import team.chisel.ctmlib.TextureSubmap;
|
||||
import team.chisel.ctmlib.TextureSubmapCTM;
|
||||
|
||||
public class SubmapManagerSlab implements ISubmapManager {
|
||||
|
||||
@@ -42,8 +43,8 @@ public class SubmapManagerSlab implements ISubmapManager {
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void registerIcons(String modName, Block block, IIconRegister register) {
|
||||
String path = modName + ":" + texture;
|
||||
submap = new TextureSubmap(register.registerIcon(path + "-ctm"), 4, 4);
|
||||
submapSmall = new TextureSubmap(register.registerIcon(path), 2, 2);
|
||||
submap = new TextureSubmapCTM(register.registerIcon(path + "-ctm"), 4);
|
||||
submapSmall = new TextureSubmapCTM(register.registerIcon(path), 2);
|
||||
sideTexture = register.registerIcon(path + "-side");
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import team.chisel.ctmlib.RenderBlocksCTM;
|
||||
import team.chisel.ctmlib.TextureSubmap;
|
||||
import team.chisel.ctmlib.TextureSubmapCTM;
|
||||
|
||||
public class SubmapManagerSpecialMaterial extends SubmapManagerBase {
|
||||
|
||||
@@ -71,8 +72,8 @@ public class SubmapManagerSpecialMaterial extends SubmapManagerBase {
|
||||
public void registerIcons(String modName, Block block, IIconRegister register) {
|
||||
String materialName = materialType.name()
|
||||
.toLowerCase();
|
||||
submap = new TextureSubmap(register.registerIcon(modName + ":" + materialName + "/" + color + "-ctm"), 4, 4);
|
||||
submapSmall = new TextureSubmap(register.registerIcon(modName + ":" + materialName + "/" + color), 2, 2);
|
||||
submap = new TextureSubmapCTM(register.registerIcon(modName + ":" + materialName + "/" + color + "-ctm"), 4);
|
||||
submapSmall = new TextureSubmapCTM(register.registerIcon(modName + ":" + materialName + "/" + color), 2);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -27,7 +27,6 @@ import net.minecraft.client.renderer.entity.RenderManager;
|
||||
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
|
||||
import net.minecraft.client.settings.GameSettings;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.IIcon;
|
||||
@@ -161,83 +160,66 @@ public class RenderAutoChisel extends TileEntitySpecialRenderer implements ISimp
|
||||
}
|
||||
|
||||
private static final Random rand = new Random();
|
||||
private final EntityItem entityItem = new EntityItem(null, 0, 0, 0, new ItemStack(Items.apple));
|
||||
|
||||
@Override
|
||||
public void renderTileEntityAt(TileEntity tile, double x, double y, double z, float scale) {
|
||||
|
||||
// Render Blocks
|
||||
try {
|
||||
this.entityItem.setWorld(tile.getWorldObj());
|
||||
TileEntityAutoChisel autoChisel = (TileEntityAutoChisel) tile;
|
||||
EntityItem item = this.getItemForRendering(autoChisel, TileEntityAutoChisel.TARGET);
|
||||
TileEntityAutoChisel autoChisel = (TileEntityAutoChisel) tile;
|
||||
EntityItem item = autoChisel.getItemForRendering(TileEntityAutoChisel.TARGET);
|
||||
|
||||
rand.setSeed(tile.xCoord + tile.yCoord + tile.zCoord);
|
||||
rand.nextBoolean();
|
||||
rand.setSeed(tile.xCoord + tile.yCoord + tile.zCoord);
|
||||
rand.nextBoolean();
|
||||
|
||||
float max = 0.35f;
|
||||
float max = 0.35f;
|
||||
|
||||
if (!Minecraft.getMinecraft()
|
||||
.isGamePaused()) {
|
||||
autoChisel.xRot += (rand.nextFloat() * max) - (max / 2);
|
||||
autoChisel.yRot += (rand.nextFloat() * max) - (max / 2);
|
||||
autoChisel.zRot += (rand.nextFloat() * max) - (max / 2);
|
||||
}
|
||||
if (!Minecraft.getMinecraft()
|
||||
.isGamePaused()) {
|
||||
autoChisel.xRot += (rand.nextFloat() * max) - (max / 2);
|
||||
autoChisel.yRot += (rand.nextFloat() * max) - (max / 2);
|
||||
autoChisel.zRot += (rand.nextFloat() * max) - (max / 2);
|
||||
}
|
||||
|
||||
if (item != null) {
|
||||
glPushMatrix();
|
||||
glPushAttrib(GL_ALL_ATTRIB_BITS);
|
||||
glTranslated(x + 0.5, y + 1.5, z + 0.5);
|
||||
glRotatef(autoChisel.xRot, 1, 0, 0);
|
||||
glRotatef(autoChisel.yRot, 0, 1, 0);
|
||||
glRotatef(autoChisel.zRot, 0, 0, 1);
|
||||
glEnable(GL_BLEND);
|
||||
glDepthMask(false);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_CONSTANT_ALPHA);
|
||||
renderItem.doRender(item, 0, 0, 0, 0, 0);
|
||||
glPopMatrix();
|
||||
glPopAttrib();
|
||||
}
|
||||
if (item != null) {
|
||||
glPushMatrix();
|
||||
glPushAttrib(GL_ALL_ATTRIB_BITS);
|
||||
glTranslated(x + 0.5, y + 1.5, z + 0.5);
|
||||
glRotatef(autoChisel.xRot, 1, 0, 0);
|
||||
glRotatef(autoChisel.yRot, 0, 1, 0);
|
||||
glRotatef(autoChisel.zRot, 0, 0, 1);
|
||||
glEnable(GL_BLEND);
|
||||
glDepthMask(false);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_CONSTANT_ALPHA);
|
||||
renderItem.doRender(item, 0, 0, 0, 0, 0);
|
||||
glPopMatrix();
|
||||
glPopAttrib();
|
||||
}
|
||||
|
||||
item = this.getItemForRendering(autoChisel, TileEntityAutoChisel.BASE);
|
||||
if (item != null) {
|
||||
glPushMatrix();
|
||||
glTranslated(x + 0.35, y + 0.934, z + 0.5);
|
||||
item.getEntityItem().stackSize = autoChisel.getLastBase() == null ? 1
|
||||
: autoChisel.getLastBase().stackSize;
|
||||
renderItem.doRender(item, 0, 0, 0, 0, 0);
|
||||
glPopMatrix();
|
||||
}
|
||||
item = autoChisel.getItemForRendering(TileEntityAutoChisel.BASE);
|
||||
if (item != null) {
|
||||
glPushMatrix();
|
||||
glTranslated(x + 0.35, y + 0.934, z + 0.5);
|
||||
item.getEntityItem().stackSize = autoChisel.getLastBase() == null ? 1 : autoChisel.getLastBase().stackSize;
|
||||
renderItem.doRender(item, 0, 0, 0, 0, 0);
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
GameSettings settings = Minecraft.getMinecraft().gameSettings;
|
||||
item = this.getItemForRendering(autoChisel, TileEntityAutoChisel.CHISEL);
|
||||
if (item != null) {
|
||||
glPushMatrix();
|
||||
glTranslated(x + 0.7, y + 1.01, z + 0.5);
|
||||
float rot = autoChisel.chiselRot == 0 ? 0
|
||||
: autoChisel.chiseling ? autoChisel.chiselRot + (TileEntityAutoChisel.rotAmnt * scale)
|
||||
: autoChisel.chiselRot - (TileEntityAutoChisel.rotAmnt * scale);
|
||||
glRotatef(rot, 0, 0, 1);
|
||||
glTranslated(-0.12, 0, 0);
|
||||
glScalef(0.9f, 0.9f, 0.9f);
|
||||
boolean was = settings.fancyGraphics;
|
||||
settings.fancyGraphics = true;
|
||||
renderItem.doRender(item, 0, 0, 0, 0, 0);
|
||||
settings.fancyGraphics = was;
|
||||
glPopMatrix();
|
||||
}
|
||||
} finally {
|
||||
this.entityItem.setWorld(null);
|
||||
GameSettings settings = Minecraft.getMinecraft().gameSettings;
|
||||
item = autoChisel.getItemForRendering(TileEntityAutoChisel.CHISEL);
|
||||
if (item != null) {
|
||||
glPushMatrix();
|
||||
glTranslated(x + 0.7, y + 1.01, z + 0.5);
|
||||
float rot = autoChisel.chiselRot == 0 ? 0
|
||||
: autoChisel.chiseling ? autoChisel.chiselRot + (TileEntityAutoChisel.rotAmnt * scale)
|
||||
: autoChisel.chiselRot - (TileEntityAutoChisel.rotAmnt * scale);
|
||||
glRotatef(rot, 0, 0, 1);
|
||||
glTranslated(-0.12, 0, 0);
|
||||
glScalef(0.9f, 0.9f, 0.9f);
|
||||
boolean was = settings.fancyGraphics;
|
||||
settings.fancyGraphics = true;
|
||||
renderItem.doRender(item, 0, 0, 0, 0, 0);
|
||||
settings.fancyGraphics = was;
|
||||
glPopMatrix();
|
||||
}
|
||||
}
|
||||
|
||||
private EntityItem getItemForRendering(TileEntityAutoChisel autoChisel, int slot) {
|
||||
final ItemStack stack = autoChisel.getItemForRendering(slot);
|
||||
if (stack != null) {
|
||||
this.entityItem.setEntityItemStack(stack);
|
||||
return this.entityItem;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -48,8 +48,8 @@ public class SubmapManagerCTM implements ISubmapManager {
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void registerIcons(String modName, Block block, IIconRegister register) {
|
||||
submap = new TextureSubmap(register.registerIcon(modName + ":" + textureName + "-ctm"), 4, 4);
|
||||
submapSmall = new TextureSubmap(register.registerIcon(modName + ":" + textureName), 2, 2);
|
||||
submap = new TextureSubmapCTM(register.registerIcon(modName + ":" + textureName + "-ctm"), 4);
|
||||
submapSmall = new TextureSubmapCTM(register.registerIcon(modName + ":" + textureName), 2);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,41 +1,34 @@
|
||||
package team.chisel.ctmlib;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.client.renderer.texture.TextureMap;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.client.event.TextureStitchEvent;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import lombok.experimental.Delegate;
|
||||
|
||||
/**
|
||||
* This class is used to split up a large IIcon into smaller "submapped" icons used for CTM and other texture
|
||||
* manipulation.
|
||||
* Represents a grid of individually accessible texture regions.
|
||||
*/
|
||||
public class TextureSubmap implements IIcon, ISubmap {
|
||||
|
||||
private static List<TextureSubmap> submaps = Lists.newArrayList();
|
||||
private static TextureSubmap dummy = new TextureSubmap(null, 0, 0);
|
||||
static {
|
||||
MinecraftForge.EVENT_BUS.register(dummy);
|
||||
}
|
||||
private static final List<TextureSubmap> submaps = Collections.synchronizedList(new ArrayList<>(128));
|
||||
|
||||
private int width, height;
|
||||
@Delegate
|
||||
private IIcon baseIcon;
|
||||
|
||||
protected IIcon[][] icons;
|
||||
private final IIcon baseIcon;
|
||||
private final int width;
|
||||
private final int height;
|
||||
protected final IIcon[][] icons;
|
||||
|
||||
/**
|
||||
* Construct a new submap. A submap is not required to be square, but it is required to be rectangular.
|
||||
*
|
||||
* @param baseIcon The IIcon to submap.
|
||||
* @param width The width of the map, in icons.
|
||||
* @param height The height of the map, in icons.
|
||||
@@ -48,9 +41,6 @@ public class TextureSubmap implements IIcon, ISubmap {
|
||||
submaps.add(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* The large "base" icon used for the submap.
|
||||
*/
|
||||
public IIcon getBaseIcon() {
|
||||
return baseIcon;
|
||||
}
|
||||
@@ -92,94 +82,161 @@ public class TextureSubmap implements IIcon, ISubmap {
|
||||
|
||||
/* ==== Internal Stitching Logic ==== */
|
||||
|
||||
/**
|
||||
* For internal use only, this is used to create the virtual "subicons" used in the map.
|
||||
*/
|
||||
@SubscribeEvent
|
||||
public final void TexturesStitched(TextureStitchEvent.Post event) {
|
||||
for (TextureSubmap ts : submaps) {
|
||||
ts.texturesStitched();
|
||||
static {
|
||||
MinecraftForge.EVENT_BUS.register(new StitchHandler());
|
||||
}
|
||||
|
||||
public static final class StitchHandler {
|
||||
|
||||
@SubscribeEvent
|
||||
public void onTextureStitchPre(TextureStitchEvent.Pre event) {
|
||||
if (event.map.getTextureType() != 0) return;
|
||||
TextureSubmapResource.beginTextureStitch();
|
||||
for (TextureSubmap submap : submaps) {
|
||||
submap.registerSubIcons(event.map);
|
||||
}
|
||||
submaps.clear();
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onTextureStitchPost(TextureStitchEvent.Post event) {
|
||||
if (event.map.getTextureType() != 0) return;
|
||||
TextureSubmapResource.endTextureStitch();
|
||||
}
|
||||
}
|
||||
|
||||
public void texturesStitched() {
|
||||
public void registerSubIcons(TextureMap textureMap) {
|
||||
registerSpriteGrid(textureMap, width, height);
|
||||
}
|
||||
|
||||
/**
|
||||
* Splits the texture into a grid of atlas sprites and assigns sub-icons to them.
|
||||
* <p>
|
||||
* The number of sub-icons is determined by the submap's width and height,
|
||||
* while spriteColumns and spriteRows determine how many separate atlas sprites
|
||||
* are used. Each sprite can contain one or more sub-icons.
|
||||
* <p>
|
||||
* For example, a 4x4 submap backed by a 2x2 sprite grid uses four atlas sprites,
|
||||
* each containing a 2x2 group of sub-icons.
|
||||
*/
|
||||
protected final void registerSpriteGrid(TextureMap textureMap, int spriteColumns, int spriteRows) {
|
||||
if (baseIcon == null || width <= 0 || height <= 0) {
|
||||
return;
|
||||
}
|
||||
if (spriteColumns <= 0 || spriteRows <= 0 || width % spriteColumns != 0 || height % spriteRows != 0) {
|
||||
throw new IllegalArgumentException(
|
||||
"Logical submap " + width
|
||||
+ "x"
|
||||
+ height
|
||||
+ " cannot be backed by sprite grid "
|
||||
+ spriteColumns
|
||||
+ "x"
|
||||
+ spriteRows);
|
||||
}
|
||||
|
||||
ResourceLocation sourceLocation = new ResourceLocation(baseIcon.getIconName());
|
||||
IIcon[][] sprites = new IIcon[spriteColumns][spriteRows];
|
||||
|
||||
for (int spriteX = 0; spriteX < spriteColumns; spriteX++) {
|
||||
for (int spriteY = 0; spriteY < spriteRows; spriteY++) {
|
||||
sprites[spriteX][spriteY] = getBackingSprite(
|
||||
textureMap,
|
||||
sourceLocation,
|
||||
spriteColumns,
|
||||
spriteRows,
|
||||
spriteX,
|
||||
spriteY);
|
||||
}
|
||||
}
|
||||
|
||||
int cellsPerSpriteX = width / spriteColumns;
|
||||
int cellsPerSpriteY = height / spriteRows;
|
||||
boolean wholeSprite = cellsPerSpriteX == 1 && cellsPerSpriteY == 1;
|
||||
|
||||
for (int x = 0; x < width; x++) {
|
||||
for (int y = 0; y < height; y++) {
|
||||
icons[x][y] = new TextureVirtual(getBaseIcon(), width, height, x, y);
|
||||
IIcon sprite = sprites[x / cellsPerSpriteX][y / cellsPerSpriteY];
|
||||
icons[x][y] = wholeSprite ? sprite
|
||||
: new TextureRegion(
|
||||
sprite,
|
||||
cellsPerSpriteX,
|
||||
cellsPerSpriteY,
|
||||
x % cellsPerSpriteX,
|
||||
y % cellsPerSpriteY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class TextureVirtual implements IIcon {
|
||||
private IIcon getBackingSprite(TextureMap textureMap, ResourceLocation sourceLocation, int columns, int rows, int x,
|
||||
int y) {
|
||||
|
||||
private int width, height;
|
||||
private float umin, umax, vmin, vmax;
|
||||
private IIcon parentIcon;
|
||||
if (columns == 1 && rows == 1) {
|
||||
return baseIcon;
|
||||
}
|
||||
|
||||
private TextureVirtual(IIcon parent, int w, int h, int x, int y) {
|
||||
parentIcon = parent;
|
||||
String name = TextureSubmapResource.getSubIconName(sourceLocation, columns, rows, x, y);
|
||||
return textureMap.registerIcon(name);
|
||||
}
|
||||
|
||||
umin = parentIcon.getInterpolatedU(16.0 * (x) / w);
|
||||
umax = parentIcon.getInterpolatedU(16.0 * (x + 1) / w);
|
||||
vmin = parentIcon.getInterpolatedV(16.0 * (y) / h);
|
||||
vmax = parentIcon.getInterpolatedV(16.0 * (y + 1) / h);
|
||||
private static final class TextureRegion implements IIcon {
|
||||
|
||||
width = parentIcon.getIconWidth();
|
||||
height = parentIcon.getIconHeight();
|
||||
private final IIcon parent;
|
||||
private final int columns;
|
||||
private final int rows;
|
||||
private final int x;
|
||||
private final int y;
|
||||
|
||||
private TextureRegion(IIcon parent, int columns, int rows, int x, int y) {
|
||||
this.parent = parent;
|
||||
this.columns = columns;
|
||||
this.rows = rows;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public float getMinU() {
|
||||
return umin;
|
||||
return getInterpolatedU(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public float getMaxU() {
|
||||
return umax;
|
||||
return getInterpolatedU(16);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public float getInterpolatedU(double d0) {
|
||||
return (float) (umin + (umax - umin) * d0 / 16.0);
|
||||
public float getInterpolatedU(double u) {
|
||||
return parent.getInterpolatedU((16.0 * x + u) / columns);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public float getMinV() {
|
||||
return vmin;
|
||||
return getInterpolatedV(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public float getMaxV() {
|
||||
return vmax;
|
||||
return getInterpolatedV(16);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public float getInterpolatedV(double d0) {
|
||||
return (float) (vmin + (vmax - vmin) * d0 / 16.0);
|
||||
public float getInterpolatedV(double v) {
|
||||
return parent.getInterpolatedV((16.0 * y + v) / rows);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public String getIconName() {
|
||||
return parentIcon.getIconName();
|
||||
return parent.getIconName();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public int getIconWidth() {
|
||||
return width;
|
||||
return parent.getIconWidth() / columns;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public int getIconHeight() {
|
||||
return height;
|
||||
return parent.getIconHeight() / rows;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package team.chisel.ctmlib;
|
||||
|
||||
import net.minecraft.client.renderer.texture.TextureMap;
|
||||
import net.minecraft.util.IIcon;
|
||||
|
||||
/**
|
||||
* A CTM submap that keeps each tile in one atlas sprite while exposing its four quadrants as sub-icons.
|
||||
*/
|
||||
public final class TextureSubmapCTM extends TextureSubmap {
|
||||
|
||||
/**
|
||||
* @param baseIcon The registered texture sheet.
|
||||
* @param size The number of logical quadrants per axis: 4 for the CTM sheet, 2 for the normal texture.
|
||||
*/
|
||||
public TextureSubmapCTM(IIcon baseIcon, int size) {
|
||||
super(baseIcon, size, size);
|
||||
|
||||
if (size <= 0 || (size & 1) != 0) {
|
||||
throw new IllegalArgumentException("CTM submap size must be a positive even number: " + size);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerSubIcons(TextureMap textureMap) {
|
||||
registerSpriteGrid(textureMap, getWidth() / 2, getHeight() / 2);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,280 @@
|
||||
package team.chisel.ctmlib;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.imageio.IIOImage;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.ImageWriteParam;
|
||||
import javax.imageio.ImageWriter;
|
||||
import javax.imageio.stream.ImageOutputStream;
|
||||
import javax.imageio.stream.MemoryCacheImageOutputStream;
|
||||
|
||||
import net.minecraft.client.resources.IResource;
|
||||
import net.minecraft.client.resources.data.AnimationFrame;
|
||||
import net.minecraft.client.resources.data.AnimationMetadataSection;
|
||||
import net.minecraft.client.resources.data.IMetadataSection;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import com.github.bsideup.jabel.Desugar;
|
||||
|
||||
public final class TextureSubmapResource implements IResource {
|
||||
|
||||
@Desugar
|
||||
public record SubmapLocation(ResourceLocation source, int columns, int rows, int cellX, int cellY) {}
|
||||
|
||||
@Desugar
|
||||
private record SubmapCacheKey(ResourceLocation source, int columns, int rows) {}
|
||||
|
||||
@Nullable
|
||||
private static volatile ConcurrentHashMap<SubmapCacheKey, byte[][]> imageCache;
|
||||
|
||||
private static final String PREFIX = "__chisel_submap/";
|
||||
|
||||
private final IResource resource;
|
||||
private final SubmapLocation submap;
|
||||
private final boolean cacheable;
|
||||
private byte[] imageData;
|
||||
|
||||
public TextureSubmapResource(IResource resource, SubmapLocation submap, boolean cacheable) {
|
||||
this.resource = resource;
|
||||
this.submap = submap;
|
||||
this.cacheable = cacheable;
|
||||
}
|
||||
|
||||
public static SubmapLocation parse(ResourceLocation location) {
|
||||
String path = location.getResourcePath();
|
||||
|
||||
int prefix = path.indexOf(PREFIX);
|
||||
if (prefix < 0 || prefix > 0 && path.charAt(prefix - 1) != '/') return null;
|
||||
|
||||
int gridStart = prefix + PREFIX.length();
|
||||
int gridEnd = path.indexOf('/', gridStart);
|
||||
if (gridEnd < 0) return null;
|
||||
|
||||
int cellEnd = path.indexOf('/', gridEnd + 1);
|
||||
if (cellEnd < 0) return null;
|
||||
|
||||
String grid = path.substring(gridStart, gridEnd);
|
||||
String cell = path.substring(gridEnd + 1, cellEnd);
|
||||
|
||||
int gridSeparator = grid.indexOf('x');
|
||||
int cellSeparator = cell.indexOf('_');
|
||||
if (gridSeparator <= 0 || cellSeparator <= 0) return null;
|
||||
|
||||
try {
|
||||
int columns = Integer.parseInt(grid.substring(0, gridSeparator));
|
||||
int rows = Integer.parseInt(grid.substring(gridSeparator + 1));
|
||||
int cellX = Integer.parseInt(cell.substring(0, cellSeparator));
|
||||
int cellY = Integer.parseInt(cell.substring(cellSeparator + 1));
|
||||
|
||||
if (cellX < 0 || cellY < 0 || cellX >= columns || cellY >= rows) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String sourcePath = path.substring(0, prefix) + path.substring(cellEnd + 1);
|
||||
ResourceLocation sourceLocation = new ResourceLocation(location.getResourceDomain(), sourcePath);
|
||||
return new SubmapLocation(sourceLocation, columns, rows, cellX, cellY);
|
||||
} catch (NumberFormatException ignored) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static String getSubIconName(ResourceLocation source, int columns, int rows, int cellX, int cellY) {
|
||||
return source.getResourceDomain() + ":"
|
||||
+ PREFIX
|
||||
+ columns
|
||||
+ "x"
|
||||
+ rows
|
||||
+ "/"
|
||||
+ cellX
|
||||
+ "_"
|
||||
+ cellY
|
||||
+ "/"
|
||||
+ source.getResourcePath();
|
||||
}
|
||||
|
||||
public static void beginTextureStitch() {
|
||||
imageCache = new ConcurrentHashMap<>();
|
||||
}
|
||||
|
||||
public static void endTextureStitch() {
|
||||
imageCache = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getInputStream() {
|
||||
if (imageData == null) {
|
||||
try {
|
||||
imageData = getCachedImageData(resource, submap);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Failed to generate submap resource " + submap.source(), e);
|
||||
}
|
||||
}
|
||||
|
||||
return new ByteArrayInputStream(imageData);
|
||||
}
|
||||
|
||||
private byte[] getCachedImageData(IResource resource, SubmapLocation submap) throws IOException {
|
||||
ConcurrentHashMap<SubmapCacheKey, byte[][]> cache = imageCache;
|
||||
if (!cacheable || cache == null) {
|
||||
return generateCell(resource, submap);
|
||||
}
|
||||
|
||||
SubmapCacheKey key = new SubmapCacheKey(submap.source(), submap.columns(), submap.rows());
|
||||
byte[][] cells = cache.get(key);
|
||||
if (cells == null) {
|
||||
cells = generateSubmap(resource, submap);
|
||||
byte[][] existing = cache.putIfAbsent(key, cells);
|
||||
if (existing != null) {
|
||||
cells = existing;
|
||||
}
|
||||
} else {
|
||||
// generateCell and generateSubmap automatically close the stream, but we also need to close it on cache hit
|
||||
resource.getInputStream()
|
||||
.close();
|
||||
}
|
||||
|
||||
return cells[submap.cellX() * submap.rows() + submap.cellY()];
|
||||
}
|
||||
|
||||
private static byte[][] generateSubmap(IResource resource, SubmapLocation submap) throws IOException {
|
||||
BufferedImage source = read(resource, submap.source());
|
||||
byte[][] cells = new byte[submap.columns() * submap.rows()][];
|
||||
|
||||
for (int x = 0; x < submap.columns(); x++) {
|
||||
for (int y = 0; y < submap.rows(); y++) {
|
||||
BufferedImage cropped = crop(source, submap.columns(), submap.rows(), x, y);
|
||||
cells[x * submap.rows() + y] = encode(cropped);
|
||||
}
|
||||
}
|
||||
|
||||
return cells;
|
||||
}
|
||||
|
||||
private static byte[] generateCell(IResource resource, SubmapLocation submap) throws IOException {
|
||||
BufferedImage source = read(resource, submap.source());
|
||||
BufferedImage cropped = crop(source, submap.columns(), submap.rows(), submap.cellX(), submap.cellY());
|
||||
return encode(cropped);
|
||||
}
|
||||
|
||||
private static BufferedImage read(IResource resource, ResourceLocation location) throws IOException {
|
||||
BufferedImage image;
|
||||
try (InputStream stream = resource.getInputStream()) {
|
||||
image = ImageIO.read(stream);
|
||||
}
|
||||
if (image == null) {
|
||||
throw new IOException("Unable to decode " + location);
|
||||
}
|
||||
return image;
|
||||
}
|
||||
|
||||
private static byte[] encode(BufferedImage image) throws IOException {
|
||||
ByteArrayOutputStream output = new ByteArrayOutputStream();
|
||||
Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("png");
|
||||
ImageWriter writer = writers.next();
|
||||
|
||||
ImageWriteParam param = writer.getDefaultWriteParam();
|
||||
if (param.canWriteCompressed()) {
|
||||
// Disable compression to avoid wasting time compressing images that will immediately be decoded again
|
||||
param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
|
||||
param.setCompressionQuality(1.0f);
|
||||
}
|
||||
|
||||
try (ImageOutputStream imageOutput = new MemoryCacheImageOutputStream(output)) {
|
||||
writer.setOutput(imageOutput);
|
||||
writer.write(null, new IIOImage(image, null, null), param);
|
||||
} finally {
|
||||
writer.dispose();
|
||||
}
|
||||
|
||||
return output.toByteArray();
|
||||
}
|
||||
|
||||
private static BufferedImage crop(BufferedImage source, int columns, int rows, int cellX, int cellY)
|
||||
throws IOException {
|
||||
|
||||
int frameSize = source.getWidth();
|
||||
int sourceHeight = source.getHeight();
|
||||
|
||||
if (frameSize < columns || frameSize < rows
|
||||
|| frameSize % columns != 0
|
||||
|| frameSize % rows != 0
|
||||
|| sourceHeight % frameSize != 0) {
|
||||
|
||||
throw new IOException(
|
||||
"Texture size " + frameSize
|
||||
+ "x"
|
||||
+ sourceHeight
|
||||
+ " cannot be split into submap "
|
||||
+ columns
|
||||
+ "x"
|
||||
+ rows);
|
||||
}
|
||||
|
||||
int cellWidth = frameSize / columns;
|
||||
int cellHeight = frameSize / rows;
|
||||
int frameCount = sourceHeight / frameSize;
|
||||
|
||||
BufferedImage result = new BufferedImage(cellWidth, cellHeight * frameCount, BufferedImage.TYPE_INT_ARGB);
|
||||
int[] pixels = new int[cellWidth * cellHeight];
|
||||
|
||||
for (int frame = 0; frame < frameCount; frame++) {
|
||||
int sourceX = cellX * cellWidth;
|
||||
int sourceY = frame * frameSize + cellY * cellHeight;
|
||||
|
||||
source.getRGB(sourceX, sourceY, cellWidth, cellHeight, pixels, 0, cellWidth);
|
||||
result.setRGB(0, frame * cellHeight, cellWidth, cellHeight, pixels, 0, cellWidth);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasMetadata() {
|
||||
return resource.hasMetadata();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMetadataSection getMetadata(String sectionName) {
|
||||
IMetadataSection metadata = resource.getMetadata(sectionName);
|
||||
if (!(metadata instanceof AnimationMetadataSection animation)) {
|
||||
return metadata;
|
||||
}
|
||||
if (animation.getFrameWidth() < 0 && animation.getFrameHeight() < 0) {
|
||||
return metadata;
|
||||
}
|
||||
|
||||
List<AnimationFrame> frames = new ArrayList<>(animation.getFrameCount());
|
||||
for (int i = 0; i < animation.getFrameCount(); i++) {
|
||||
if (animation.frameHasTime(i)) {
|
||||
frames.add(new AnimationFrame(animation.getFrameIndex(i), animation.getFrameTimeSingle(i)));
|
||||
} else {
|
||||
frames.add(new AnimationFrame(animation.getFrameIndex(i)));
|
||||
}
|
||||
}
|
||||
|
||||
int frameWidth = scaleMetadataDimension(animation.getFrameWidth(), submap.columns());
|
||||
int frameHeight = scaleMetadataDimension(animation.getFrameHeight(), submap.rows());
|
||||
return new AnimationMetadataSection(frames, frameWidth, frameHeight, animation.getFrameTime());
|
||||
}
|
||||
|
||||
private static int scaleMetadataDimension(int dimension, int divisions) {
|
||||
if (dimension < 0) {
|
||||
return dimension;
|
||||
}
|
||||
if (dimension % divisions != 0) {
|
||||
throw new IllegalArgumentException(
|
||||
"Animation frame size " + dimension + " is not divisible by submap size " + divisions);
|
||||
}
|
||||
return dimension / divisions;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"required": true,
|
||||
"minVersion": "0.8.5-GTNH",
|
||||
"package": "com.cricketcraft.chisel.mixins",
|
||||
"refmap": "mixins.chisel.refmap.json",
|
||||
"target": "@env(DEFAULT)",
|
||||
"compatibilityLevel": "JAVA_8",
|
||||
"mixins": [],
|
||||
"client": [
|
||||
"MixinFallbackResourceManager"
|
||||
],
|
||||
"server": []
|
||||
}
|
||||
Reference in new issue
Block a user