mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-16 18:45:09 +00:00
Update to 1.15
Due to the massive rendering changes, certain features, such as emissive item rendering and the forge block rendering/lighting pipeline are currently disabled. Co-authored-by: David Quintana <[email protected]> Co-authored-by: tterrag <[email protected]> Co-authored-by: Unnoen <[email protected]>
This commit is contained in:
1 parent
9e5ecaaf75
commit
1933d05e36
565 files changed
+11114
-13142
No files matched your search
@@ -24,9 +24,12 @@ import java.nio.ByteBuffer;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL13;
|
||||
import org.lwjgl.opengl.GL31;
|
||||
|
||||
import com.mojang.blaze3d.platform.GLX;
|
||||
import com.mojang.blaze3d.platform.GlStateManager;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.world.ClientWorld;
|
||||
@@ -49,6 +52,7 @@ import net.minecraftforge.resource.IResourceType;
|
||||
import net.minecraftforge.resource.ISelectiveResourceReloadListener;
|
||||
import net.minecraftforge.resource.VanillaResourceType;
|
||||
|
||||
/* TODO: reimplement using the new rendering system? or remove?
|
||||
public class CloudRenderer implements ISelectiveResourceReloadListener
|
||||
{
|
||||
// Shared constants.
|
||||
@@ -68,7 +72,6 @@ public class CloudRenderer implements ISelectiveResourceReloadListener
|
||||
private final Minecraft mc = Minecraft.getInstance();
|
||||
private final ResourceLocation texture = new ResourceLocation("textures/environment/clouds.png");
|
||||
|
||||
private int displayList = -1;
|
||||
private VertexBuffer vbo;
|
||||
private CloudOption cloudMode = CloudOption.OFF;
|
||||
private int renderDistance = -1;
|
||||
@@ -138,18 +141,18 @@ public class CloudRenderer implements ISelectiveResourceReloadListener
|
||||
float v1 = sectZ1 * sectPx;
|
||||
|
||||
// Bottom
|
||||
buffer.pos(sectX0, 0, sectZ0).tex(u0, v0).color(bCol, bCol, bCol, ALPHA).endVertex();
|
||||
buffer.pos(sectX1, 0, sectZ0).tex(u1, v0).color(bCol, bCol, bCol, ALPHA).endVertex();
|
||||
buffer.pos(sectX1, 0, sectZ1).tex(u1, v1).color(bCol, bCol, bCol, ALPHA).endVertex();
|
||||
buffer.pos(sectX0, 0, sectZ1).tex(u0, v1).color(bCol, bCol, bCol, ALPHA).endVertex();
|
||||
buffer.func_225582_a_(sectX0, 0, sectZ0).func_225583_a_(u0, v0).func_227885_a_(bCol, bCol, bCol, ALPHA).endVertex();
|
||||
buffer.func_225582_a_(sectX1, 0, sectZ0).func_225583_a_(u1, v0).func_227885_a_(bCol, bCol, bCol, ALPHA).endVertex();
|
||||
buffer.func_225582_a_(sectX1, 0, sectZ1).func_225583_a_(u1, v1).func_227885_a_(bCol, bCol, bCol, ALPHA).endVertex();
|
||||
buffer.func_225582_a_(sectX0, 0, sectZ1).func_225583_a_(u0, v1).func_227885_a_(bCol, bCol, bCol, ALPHA).endVertex();
|
||||
|
||||
if (fancy)
|
||||
{
|
||||
// Top
|
||||
buffer.pos(sectX0, HEIGHT, sectZ0).tex(u0, v0).color(1, 1, 1, ALPHA).endVertex();
|
||||
buffer.pos(sectX0, HEIGHT, sectZ1).tex(u0, v1).color(1, 1, 1, ALPHA).endVertex();
|
||||
buffer.pos(sectX1, HEIGHT, sectZ1).tex(u1, v1).color(1, 1, 1, ALPHA).endVertex();
|
||||
buffer.pos(sectX1, HEIGHT, sectZ0).tex(u1, v0).color(1, 1, 1, ALPHA).endVertex();
|
||||
buffer.func_225582_a_(sectX0, HEIGHT, sectZ0).func_225583_a_(u0, v0).func_227885_a_(1, 1, 1, ALPHA).endVertex();
|
||||
buffer.func_225582_a_(sectX0, HEIGHT, sectZ1).func_225583_a_(u0, v1).func_227885_a_(1, 1, 1, ALPHA).endVertex();
|
||||
buffer.func_225582_a_(sectX1, HEIGHT, sectZ1).func_225583_a_(u1, v1).func_227885_a_(1, 1, 1, ALPHA).endVertex();
|
||||
buffer.func_225582_a_(sectX1, HEIGHT, sectZ0).func_225583_a_(u1, v0).func_227885_a_(1, 1, 1, ALPHA).endVertex();
|
||||
|
||||
float slice;
|
||||
float sliceCoord0;
|
||||
@@ -164,10 +167,10 @@ public class CloudRenderer implements ISelectiveResourceReloadListener
|
||||
if (slice > -CULL_DIST)
|
||||
{
|
||||
slice += INSET;
|
||||
buffer.pos(slice, 0, sectZ1).tex(sliceCoord0, v1).color(0.9F, 0.9F, 0.9F, ALPHA).endVertex();
|
||||
buffer.pos(slice, HEIGHT, sectZ1).tex(sliceCoord1, v1).color(0.9F, 0.9F, 0.9F, ALPHA).endVertex();
|
||||
buffer.pos(slice, HEIGHT, sectZ0).tex(sliceCoord1, v0).color(0.9F, 0.9F, 0.9F, ALPHA).endVertex();
|
||||
buffer.pos(slice, 0, sectZ0).tex(sliceCoord0, v0).color(0.9F, 0.9F, 0.9F, ALPHA).endVertex();
|
||||
buffer.func_225582_a_(slice, 0, sectZ1).func_225583_a_(sliceCoord0, v1).func_227885_a_(0.9F, 0.9F, 0.9F, ALPHA).endVertex();
|
||||
buffer.func_225582_a_(slice, HEIGHT, sectZ1).func_225583_a_(sliceCoord1, v1).func_227885_a_(0.9F, 0.9F, 0.9F, ALPHA).endVertex();
|
||||
buffer.func_225582_a_(slice, HEIGHT, sectZ0).func_225583_a_(sliceCoord1, v0).func_227885_a_(0.9F, 0.9F, 0.9F, ALPHA).endVertex();
|
||||
buffer.func_225582_a_(slice, 0, sectZ0).func_225583_a_(sliceCoord0, v0).func_227885_a_(0.9F, 0.9F, 0.9F, ALPHA).endVertex();
|
||||
slice -= INSET;
|
||||
}
|
||||
|
||||
@@ -176,10 +179,10 @@ public class CloudRenderer implements ISelectiveResourceReloadListener
|
||||
if (slice <= CULL_DIST)
|
||||
{
|
||||
slice -= INSET;
|
||||
buffer.pos(slice, 0, sectZ0).tex(sliceCoord0, v0).color(0.9F, 0.9F, 0.9F, ALPHA).endVertex();
|
||||
buffer.pos(slice, HEIGHT, sectZ0).tex(sliceCoord1, v0).color(0.9F, 0.9F, 0.9F, ALPHA).endVertex();
|
||||
buffer.pos(slice, HEIGHT, sectZ1).tex(sliceCoord1, v1).color(0.9F, 0.9F, 0.9F, ALPHA).endVertex();
|
||||
buffer.pos(slice, 0, sectZ1).tex(sliceCoord0, v1).color(0.9F, 0.9F, 0.9F, ALPHA).endVertex();
|
||||
buffer.func_225582_a_(slice, 0, sectZ0).func_225583_a_(sliceCoord0, v0).func_227885_a_(0.9F, 0.9F, 0.9F, ALPHA).endVertex();
|
||||
buffer.func_225582_a_(slice, HEIGHT, sectZ0).func_225583_a_(sliceCoord1, v0).func_227885_a_(0.9F, 0.9F, 0.9F, ALPHA).endVertex();
|
||||
buffer.func_225582_a_(slice, HEIGHT, sectZ1).func_225583_a_(sliceCoord1, v1).func_227885_a_(0.9F, 0.9F, 0.9F, ALPHA).endVertex();
|
||||
buffer.func_225582_a_(slice, 0, sectZ1).func_225583_a_(sliceCoord0, v1).func_227885_a_(0.9F, 0.9F, 0.9F, ALPHA).endVertex();
|
||||
slice += INSET;
|
||||
}
|
||||
}
|
||||
@@ -193,10 +196,10 @@ public class CloudRenderer implements ISelectiveResourceReloadListener
|
||||
if (slice > -CULL_DIST)
|
||||
{
|
||||
slice += INSET;
|
||||
buffer.pos(sectX0, 0, slice).tex(u0, sliceCoord0).color(0.8F, 0.8F, 0.8F, ALPHA).endVertex();
|
||||
buffer.pos(sectX0, HEIGHT, slice).tex(u0, sliceCoord1).color(0.8F, 0.8F, 0.8F, ALPHA).endVertex();
|
||||
buffer.pos(sectX1, HEIGHT, slice).tex(u1, sliceCoord1).color(0.8F, 0.8F, 0.8F, ALPHA).endVertex();
|
||||
buffer.pos(sectX1, 0, slice).tex(u1, sliceCoord0).color(0.8F, 0.8F, 0.8F, ALPHA).endVertex();
|
||||
buffer.func_225582_a_(sectX0, 0, slice).func_225583_a_(u0, sliceCoord0).func_227885_a_(0.8F, 0.8F, 0.8F, ALPHA).endVertex();
|
||||
buffer.func_225582_a_(sectX0, HEIGHT, slice).func_225583_a_(u0, sliceCoord1).func_227885_a_(0.8F, 0.8F, 0.8F, ALPHA).endVertex();
|
||||
buffer.func_225582_a_(sectX1, HEIGHT, slice).func_225583_a_(u1, sliceCoord1).func_227885_a_(0.8F, 0.8F, 0.8F, ALPHA).endVertex();
|
||||
buffer.func_225582_a_(sectX1, 0, slice).func_225583_a_(u1, sliceCoord0).func_227885_a_(0.8F, 0.8F, 0.8F, ALPHA).endVertex();
|
||||
slice -= INSET;
|
||||
}
|
||||
|
||||
@@ -205,10 +208,10 @@ public class CloudRenderer implements ISelectiveResourceReloadListener
|
||||
if (slice <= CULL_DIST)
|
||||
{
|
||||
slice -= INSET;
|
||||
buffer.pos(sectX1, 0, slice).tex(u1, sliceCoord0).color(0.8F, 0.8F, 0.8F, ALPHA).endVertex();
|
||||
buffer.pos(sectX1, HEIGHT, slice).tex(u1, sliceCoord1).color(0.8F, 0.8F, 0.8F, ALPHA).endVertex();
|
||||
buffer.pos(sectX0, HEIGHT, slice).tex(u0, sliceCoord1).color(0.8F, 0.8F, 0.8F, ALPHA).endVertex();
|
||||
buffer.pos(sectX0, 0, slice).tex(u0, sliceCoord0).color(0.8F, 0.8F, 0.8F, ALPHA).endVertex();
|
||||
buffer.func_225582_a_(sectX1, 0, slice).func_225583_a_(u1, sliceCoord0).func_227885_a_(0.8F, 0.8F, 0.8F, ALPHA).endVertex();
|
||||
buffer.func_225582_a_(sectX1, HEIGHT, slice).func_225583_a_(u1, sliceCoord1).func_227885_a_(0.8F, 0.8F, 0.8F, ALPHA).endVertex();
|
||||
buffer.func_225582_a_(sectX0, HEIGHT, slice).func_225583_a_(u0, sliceCoord1).func_227885_a_(0.8F, 0.8F, 0.8F, ALPHA).endVertex();
|
||||
buffer.func_225582_a_(sectX0, 0, slice).func_225583_a_(u0, sliceCoord0).func_227885_a_(0.8F, 0.8F, 0.8F, ALPHA).endVertex();
|
||||
slice += INSET;
|
||||
}
|
||||
}
|
||||
@@ -228,11 +231,6 @@ public class CloudRenderer implements ISelectiveResourceReloadListener
|
||||
vbo.deleteGlBuffers();
|
||||
vbo = null;
|
||||
}
|
||||
if (displayList >= 0)
|
||||
{
|
||||
GLAllocation.deleteDisplayLists(displayList);
|
||||
displayList = -1;
|
||||
}
|
||||
}
|
||||
|
||||
private void build()
|
||||
@@ -240,24 +238,13 @@ public class CloudRenderer implements ISelectiveResourceReloadListener
|
||||
Tessellator tess = Tessellator.getInstance();
|
||||
BufferBuilder buffer = tess.getBuffer();
|
||||
|
||||
if (GLX.useVbo())
|
||||
vbo = new VertexBuffer(FORMAT);
|
||||
else
|
||||
GlStateManager.newList(displayList = GLAllocation.generateDisplayLists(1), GL11.GL_COMPILE);
|
||||
vbo = new VertexBuffer(FORMAT);
|
||||
|
||||
vertices(buffer);
|
||||
|
||||
if (GLX.useVbo())
|
||||
{
|
||||
buffer.finishDrawing();
|
||||
buffer.reset();
|
||||
vbo.bufferData(buffer.getByteBuffer());
|
||||
}
|
||||
else
|
||||
{
|
||||
tess.draw();
|
||||
GlStateManager.endList();
|
||||
}
|
||||
buffer.finishDrawing();
|
||||
buffer.reset();
|
||||
vbo.bufferData(buffer.getByteBuffer());
|
||||
}
|
||||
|
||||
private int fullCoord(double coord, int scale)
|
||||
@@ -267,7 +254,7 @@ public class CloudRenderer implements ISelectiveResourceReloadListener
|
||||
|
||||
private boolean isBuilt()
|
||||
{
|
||||
return GLX.useVbo() ? vbo != null : displayList >= 0;
|
||||
return vbo != null;
|
||||
}
|
||||
|
||||
public void checkSettings()
|
||||
@@ -303,12 +290,12 @@ public class CloudRenderer implements ISelectiveResourceReloadListener
|
||||
|
||||
double totalOffset = cloudTicks + partialTicks;
|
||||
|
||||
double x = entity.prevPosX + (entity.posX - entity.prevPosX) * partialTicks
|
||||
double x = entity.prevPosX + (entity.func_226277_ct_() - entity.prevPosX) * partialTicks
|
||||
+ totalOffset * 0.03;
|
||||
double y = mc.world.dimension.getCloudHeight()
|
||||
- (entity.lastTickPosY + (entity.posY - entity.lastTickPosY) * partialTicks)
|
||||
- (entity.lastTickPosY + (entity.func_226278_cu_() - entity.lastTickPosY) * partialTicks)
|
||||
+ 0.33;
|
||||
double z = entity.prevPosZ + (entity.posZ - entity.prevPosZ) * partialTicks;
|
||||
double z = entity.prevPosZ + (entity.func_226281_cx_() - entity.prevPosZ) * partialTicks;
|
||||
|
||||
int scale = getScale();
|
||||
|
||||
@@ -319,26 +306,24 @@ public class CloudRenderer implements ISelectiveResourceReloadListener
|
||||
int offU = fullCoord(x, scale);
|
||||
int offV = fullCoord(z, scale);
|
||||
|
||||
GlStateManager.pushMatrix();
|
||||
RenderSystem.pushMatrix();
|
||||
|
||||
// Translate by the remainder after the UV offset.
|
||||
GlStateManager.translated((offU * scale) - x, y, (offV * scale) - z);
|
||||
RenderSystem.translated((offU * scale) - x, y, (offV * scale) - z);
|
||||
|
||||
// Modulo to prevent texture samples becoming inaccurate at extreme offsets.
|
||||
offU = offU % texW;
|
||||
offV = offV % texH;
|
||||
|
||||
// Translate the texture.
|
||||
GlStateManager.matrixMode(GL11.GL_TEXTURE);
|
||||
GlStateManager.translatef(offU * PX_SIZE, offV * PX_SIZE, 0);
|
||||
GlStateManager.matrixMode(GL11.GL_MODELVIEW);
|
||||
RenderSystem.matrixMode(GL11.GL_TEXTURE);
|
||||
RenderSystem.translatef(offU * PX_SIZE, offV * PX_SIZE, 0);
|
||||
RenderSystem.matrixMode(GL11.GL_MODELVIEW);
|
||||
|
||||
GlStateManager.disableCull();
|
||||
RenderSystem.disableCull();
|
||||
|
||||
GlStateManager.enableBlend();
|
||||
GlStateManager.blendFuncSeparate(
|
||||
GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA,
|
||||
GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
|
||||
RenderSystem.enableBlend();
|
||||
RenderSystem.defaultBlendFunc();
|
||||
|
||||
// Color multiplier.
|
||||
Vec3d color = mc.world.getCloudColour(partialTicks);
|
||||
@@ -356,94 +341,71 @@ public class CloudRenderer implements ISelectiveResourceReloadListener
|
||||
| (int) (b * 255));
|
||||
COLOR_TEX.updateDynamicTexture();
|
||||
|
||||
GlStateManager.activeTexture(GLX.GL_TEXTURE1);
|
||||
GlStateManager.bindTexture(COLOR_TEX.getGlTextureId());
|
||||
GlStateManager.enableTexture();
|
||||
RenderSystem.activeTexture(GL13.GL_TEXTURE1);
|
||||
RenderSystem.bindTexture(COLOR_TEX.getGlTextureId());
|
||||
RenderSystem.enableTexture();
|
||||
|
||||
// Bind the clouds texture last so the shader's sampler2D is correct.
|
||||
GlStateManager.activeTexture(GLX.GL_TEXTURE0);
|
||||
RenderSystem.activeTexture(GL13.GL_TEXTURE0);
|
||||
mc.textureManager.bindTexture(texture);
|
||||
|
||||
ByteBuffer buffer = Tessellator.getInstance().getBuffer().getByteBuffer();
|
||||
|
||||
// Set up pointers for the display list/VBO.
|
||||
if (GLX.useVbo())
|
||||
{
|
||||
vbo.bindBuffer();
|
||||
vbo.bindBuffer();
|
||||
|
||||
int stride = FORMAT.getSize();
|
||||
GlStateManager.vertexPointer(3, GL11.GL_FLOAT, stride, 0);
|
||||
GlStateManager.enableClientState(GL11.GL_VERTEX_ARRAY);
|
||||
GlStateManager.texCoordPointer(2, GL11.GL_FLOAT, stride, 12);
|
||||
GlStateManager.enableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
|
||||
GlStateManager.colorPointer(4, GL11.GL_UNSIGNED_BYTE, stride, 20);
|
||||
GlStateManager.enableClientState(GL11.GL_COLOR_ARRAY);
|
||||
}
|
||||
else
|
||||
{
|
||||
buffer.limit(FORMAT.getSize());
|
||||
for (int i = 0; i < FORMAT.getElementCount(); i++)
|
||||
FORMAT.getElements().get(i).getUsage().preDraw(FORMAT, i, FORMAT.getSize(), buffer);
|
||||
buffer.position(0);
|
||||
}
|
||||
int stride = FORMAT.getSize();
|
||||
RenderSystem.vertexPointer(3, GL11.GL_FLOAT, stride, 0);
|
||||
RenderSystem.enableClientState(GL11.GL_VERTEX_ARRAY);
|
||||
RenderSystem.texCoordPointer(2, GL11.GL_FLOAT, stride, 12);
|
||||
RenderSystem.enableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
|
||||
RenderSystem.colorPointer(4, GL11.GL_UNSIGNED_BYTE, stride, 20);
|
||||
RenderSystem.enableClientState(GL11.GL_COLOR_ARRAY);
|
||||
|
||||
// Depth pass to prevent insides rendering from the outside.
|
||||
GlStateManager.colorMask(false, false, false, false);
|
||||
if (GLX.useVbo())
|
||||
vbo.drawArrays(GL11.GL_QUADS);
|
||||
else
|
||||
GlStateManager.callList(displayList);
|
||||
RenderSystem.colorMask(false, false, false, false);
|
||||
vbo.drawArrays(GL11.GL_QUADS);
|
||||
|
||||
// Full render.
|
||||
GlStateManager.colorMask(true, true, true, true);
|
||||
RenderSystem.colorMask(true, true, true, true);
|
||||
|
||||
// Wireframe for debug.
|
||||
if (WIREFRAME)
|
||||
{
|
||||
GlStateManager.polygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_LINE);
|
||||
GlStateManager.lineWidth(2.0F);
|
||||
GlStateManager.disableTexture();
|
||||
GlStateManager.depthMask(false);
|
||||
GlStateManager.disableFog();
|
||||
if (GLX.useVbo())
|
||||
vbo.drawArrays(GL11.GL_QUADS);
|
||||
else
|
||||
GlStateManager.callList(displayList);
|
||||
GlStateManager.polygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_FILL);
|
||||
GlStateManager.depthMask(true);
|
||||
GlStateManager.enableTexture();
|
||||
GlStateManager.enableFog();
|
||||
RenderSystem.polygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_LINE);
|
||||
RenderSystem.lineWidth(2.0F);
|
||||
RenderSystem.disableTexture();
|
||||
RenderSystem.depthMask(false);
|
||||
RenderSystem.disableFog();
|
||||
vbo.drawArrays(GL11.GL_QUADS);
|
||||
RenderSystem.polygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_FILL);
|
||||
RenderSystem.depthMask(true);
|
||||
RenderSystem.enableTexture();
|
||||
RenderSystem.enableFog();
|
||||
}
|
||||
|
||||
if (GLX.useVbo())
|
||||
{
|
||||
vbo.drawArrays(GL11.GL_QUADS);
|
||||
vbo.unbindBuffer(); // Unbind buffer and disable pointers.
|
||||
}
|
||||
else
|
||||
{
|
||||
GlStateManager.callList(displayList);
|
||||
}
|
||||
vbo.drawArrays(GL11.GL_QUADS);
|
||||
VertexBuffer.unbindBuffer(); // Unbind buffer and disable pointers.
|
||||
|
||||
buffer.limit(0);
|
||||
for (int i = 0; i < FORMAT.getElementCount(); i++)
|
||||
for (int i = 0; i < FORMAT.func_227894_c_().size(); i++)
|
||||
FORMAT.getElements().get(i).getUsage().postDraw(FORMAT, i, FORMAT.getSize(), buffer);
|
||||
buffer.position(0);
|
||||
|
||||
// Disable our coloring.
|
||||
GlStateManager.activeTexture(GLX.GL_TEXTURE1);
|
||||
GlStateManager.disableTexture();
|
||||
GlStateManager.activeTexture(GLX.GL_TEXTURE0);
|
||||
RenderSystem.activeTexture(GL13.GL_TEXTURE1);
|
||||
RenderSystem.disableTexture();
|
||||
RenderSystem.activeTexture(GL13.GL_TEXTURE0);
|
||||
|
||||
// Reset texture matrix.
|
||||
GlStateManager.matrixMode(GL11.GL_TEXTURE);
|
||||
GlStateManager.loadIdentity();
|
||||
GlStateManager.matrixMode(GL11.GL_MODELVIEW);
|
||||
RenderSystem.matrixMode(GL11.GL_TEXTURE);
|
||||
RenderSystem.loadIdentity();
|
||||
RenderSystem.matrixMode(GL11.GL_MODELVIEW);
|
||||
|
||||
GlStateManager.disableBlend();
|
||||
GlStateManager.enableCull();
|
||||
RenderSystem.disableBlend();
|
||||
RenderSystem.enableCull();
|
||||
|
||||
GlStateManager.popMatrix();
|
||||
RenderSystem.popMatrix();
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -453,8 +415,8 @@ public class CloudRenderer implements ISelectiveResourceReloadListener
|
||||
if (mc.textureManager != null)
|
||||
{
|
||||
mc.textureManager.bindTexture(texture);
|
||||
texW = GlStateManager.getTexLevelParameter(GL11.GL_TEXTURE_2D, 0, GL11.GL_TEXTURE_WIDTH);
|
||||
texH = GlStateManager.getTexLevelParameter(GL11.GL_TEXTURE_2D, 0, GL11.GL_TEXTURE_HEIGHT);
|
||||
texW = GlStateManager.func_227692_c_(GL11.GL_TEXTURE_2D, 0, GL11.GL_TEXTURE_WIDTH);
|
||||
texH = GlStateManager.func_227692_c_(GL11.GL_TEXTURE_2D, 0, GL11.GL_TEXTURE_HEIGHT);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -492,3 +454,4 @@ public class CloudRenderer implements ISelectiveResourceReloadListener
|
||||
}
|
||||
|
||||
}
|
||||
*/
|
||||
@@ -19,9 +19,55 @@
|
||||
|
||||
package net.minecraftforge.client;
|
||||
|
||||
import com.mojang.blaze3d.platform.GLX;
|
||||
import static net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType.BOSSINFO;
|
||||
import static net.minecraftforge.fml.VersionChecker.Status.BETA;
|
||||
import static net.minecraftforge.fml.VersionChecker.Status.BETA_OUTDATED;
|
||||
import static org.lwjgl.opengl.GL11.GL_COLOR_ARRAY;
|
||||
import static org.lwjgl.opengl.GL11.GL_NORMAL_ARRAY;
|
||||
import static org.lwjgl.opengl.GL11.GL_TEXTURE_COORD_ARRAY;
|
||||
import static org.lwjgl.opengl.GL11.GL_VERTEX_ARRAY;
|
||||
import static org.lwjgl.opengl.GL11.glColorPointer;
|
||||
import static org.lwjgl.opengl.GL11.glDisableClientState;
|
||||
import static org.lwjgl.opengl.GL11.glEnableClientState;
|
||||
import static org.lwjgl.opengl.GL11.glMultMatrixf;
|
||||
import static org.lwjgl.opengl.GL11.glNormalPointer;
|
||||
import static org.lwjgl.opengl.GL11.glTexCoordPointer;
|
||||
import static org.lwjgl.opengl.GL11.glVertexPointer;
|
||||
import static org.lwjgl.opengl.GL20.glDisableVertexAttribArray;
|
||||
import static org.lwjgl.opengl.GL20.glEnableVertexAttribArray;
|
||||
import static org.lwjgl.opengl.GL20.glVertexAttribPointer;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Field;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.FloatBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.vecmath.Matrix3f;
|
||||
import javax.vecmath.Matrix4f;
|
||||
import javax.vecmath.Vector3f;
|
||||
import javax.vecmath.Vector4f;
|
||||
|
||||
import net.minecraftforge.client.model.pipeline.LightUtil;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.logging.log4j.core.async.ThreadNameCachingStrategy;
|
||||
import org.apache.logging.log4j.core.impl.ReusableLogEventFactory;
|
||||
import org.lwjgl.BufferUtils;
|
||||
import org.lwjgl.opengl.GL13;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import com.mojang.blaze3d.platform.GlStateManager;
|
||||
import net.minecraft.block.BlockState;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.mojang.blaze3d.vertex.IVertexBuilder;
|
||||
|
||||
import net.minecraft.client.GameSettings;
|
||||
import net.minecraft.client.MainWindow;
|
||||
import net.minecraft.client.Minecraft;
|
||||
@@ -33,11 +79,11 @@ import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.screen.MainMenuScreen;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.renderer.ActiveRenderInfo;
|
||||
import net.minecraft.client.renderer.BufferBuilder;
|
||||
import net.minecraft.client.renderer.FogRenderer;
|
||||
import net.minecraft.client.renderer.FogRenderer.FogType;
|
||||
import net.minecraft.client.renderer.GameRenderer;
|
||||
import net.minecraft.client.renderer.ItemRenderer;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
import net.minecraft.client.renderer.TransformationMatrix;
|
||||
import net.minecraft.client.renderer.WorldRenderer;
|
||||
import net.minecraft.client.renderer.color.BlockColors;
|
||||
import net.minecraft.client.renderer.color.ItemColors;
|
||||
@@ -47,11 +93,12 @@ import net.minecraft.client.renderer.model.BlockFaceUV;
|
||||
import net.minecraft.client.renderer.model.IBakedModel;
|
||||
import net.minecraft.client.renderer.model.ItemCameraTransforms;
|
||||
import net.minecraft.client.renderer.model.ItemTransformVec3f;
|
||||
import net.minecraft.client.renderer.model.Material;
|
||||
import net.minecraft.client.renderer.model.ModelManager;
|
||||
import net.minecraft.client.renderer.model.ModelRotation;
|
||||
import net.minecraft.client.renderer.model.SimpleBakedModel;
|
||||
import net.minecraft.client.renderer.texture.AtlasTexture;
|
||||
import net.minecraft.client.renderer.texture.NativeImage;
|
||||
import net.minecraft.client.renderer.texture.OverlayTexture;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormat;
|
||||
@@ -65,7 +112,6 @@ import net.minecraft.fluid.IFluidState;
|
||||
import net.minecraft.inventory.EquipmentSlotType;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.RecipeManager;
|
||||
import net.minecraft.util.BlockRenderLayer;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.MovementInput;
|
||||
@@ -76,7 +122,7 @@ import net.minecraft.util.math.EntityRayTraceResult;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.math.RayTraceResult;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
import net.minecraft.world.IEnviromentBlockReader;
|
||||
import net.minecraft.world.ILightReader;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import net.minecraftforge.client.event.ColorHandlerEvent;
|
||||
@@ -95,15 +141,12 @@ import net.minecraftforge.client.event.RenderWorldLastEvent;
|
||||
import net.minecraftforge.client.event.ScreenshotEvent;
|
||||
import net.minecraftforge.client.event.TextureStitchEvent;
|
||||
import net.minecraftforge.client.event.sound.PlaySoundEvent;
|
||||
import net.minecraftforge.client.model.ModelDynBucket;
|
||||
import net.minecraftforge.client.model.ModelLoader;
|
||||
import net.minecraftforge.client.model.animation.Animation;
|
||||
import net.minecraftforge.client.model.data.EmptyModelData;
|
||||
import net.minecraftforge.client.model.pipeline.QuadGatheringTransformer;
|
||||
import net.minecraftforge.common.ForgeMod;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.model.IModelPart;
|
||||
import net.minecraftforge.common.model.ITransformation;
|
||||
import net.minecraftforge.common.model.TRSRTransformation;
|
||||
import net.minecraftforge.common.model.TransformationHelper;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import net.minecraftforge.fml.ModLoader;
|
||||
import net.minecraftforge.fml.VersionChecker;
|
||||
@@ -113,29 +156,6 @@ import net.minecraftforge.resource.ReloadRequirements;
|
||||
import net.minecraftforge.resource.SelectiveReloadStateHandler;
|
||||
import net.minecraftforge.resource.VanillaResourceType;
|
||||
import net.minecraftforge.versions.forge.ForgeVersion;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.logging.log4j.core.async.ThreadNameCachingStrategy;
|
||||
import org.apache.logging.log4j.core.impl.ReusableLogEventFactory;
|
||||
import org.lwjgl.BufferUtils;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.vecmath.Matrix3f;
|
||||
import javax.vecmath.Matrix4f;
|
||||
import javax.vecmath.Vector3f;
|
||||
import javax.vecmath.Vector4f;
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Field;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.FloatBuffer;
|
||||
import java.util.*;
|
||||
|
||||
import static net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType.BOSSINFO;
|
||||
import static net.minecraftforge.fml.VersionChecker.Status.BETA;
|
||||
import static net.minecraftforge.fml.VersionChecker.Status.BETA_OUTDATED;
|
||||
import static org.lwjgl.opengl.GL11.*;
|
||||
import static org.lwjgl.opengl.GL20.*;
|
||||
|
||||
public class ForgeHooksClient
|
||||
{
|
||||
@@ -162,26 +182,25 @@ public class ForgeHooksClient
|
||||
return MinecraftForge.EVENT_BUS.post(new DrawBlockHighlightEvent(context, info, target, subID, partialTicks));
|
||||
}
|
||||
|
||||
public static void dispatchRenderLast(WorldRenderer context, float partialTicks)
|
||||
public static void dispatchRenderLast(WorldRenderer context, MatrixStack mat, float partialTicks)
|
||||
{
|
||||
MinecraftForge.EVENT_BUS.post(new RenderWorldLastEvent(context, partialTicks));
|
||||
MinecraftForge.EVENT_BUS.post(new RenderWorldLastEvent(context, mat, partialTicks));
|
||||
}
|
||||
|
||||
public static boolean renderFirstPersonHand(WorldRenderer context, float partialTicks)
|
||||
public static boolean renderFirstPersonHand(WorldRenderer context, MatrixStack mat, float partialTicks)
|
||||
{
|
||||
return MinecraftForge.EVENT_BUS.post(new RenderHandEvent(context, partialTicks));
|
||||
return MinecraftForge.EVENT_BUS.post(new RenderHandEvent(context, mat, partialTicks));
|
||||
}
|
||||
|
||||
public static boolean renderSpecificFirstPersonHand(Hand hand, float partialTicks, float interpPitch, float swingProgress, float equipProgress, ItemStack stack)
|
||||
public static boolean renderSpecificFirstPersonHand(Hand hand, MatrixStack mat, float partialTicks, float interpPitch, float swingProgress, float equipProgress, ItemStack stack)
|
||||
{
|
||||
return MinecraftForge.EVENT_BUS.post(new RenderSpecificHandEvent(hand, partialTicks, interpPitch, swingProgress, equipProgress, stack));
|
||||
return MinecraftForge.EVENT_BUS.post(new RenderSpecificHandEvent(hand, mat, partialTicks, interpPitch, swingProgress, equipProgress, stack));
|
||||
}
|
||||
|
||||
public static void onTextureStitchedPre(AtlasTexture map, Set<ResourceLocation> resourceLocations)
|
||||
{
|
||||
ModLoader.get().postEvent(new TextureStitchEvent.Pre(map, resourceLocations));
|
||||
// ModelLoader.White.INSTANCE.register(map); // TODO Custom TAS
|
||||
ModelDynBucket.LoaderDynBucket.INSTANCE.register(map);
|
||||
}
|
||||
|
||||
public static void onTextureStitchedPost(AtlasTexture map)
|
||||
@@ -199,9 +218,9 @@ public class ForgeHooksClient
|
||||
ModLoader.get().postEvent(new ColorHandlerEvent.Item(itemColors, blockColors));
|
||||
}
|
||||
|
||||
static final ThreadLocal<BlockRenderLayer> renderLayer = new ThreadLocal<BlockRenderLayer>();
|
||||
static final ThreadLocal<RenderType> renderLayer = new ThreadLocal<RenderType>();
|
||||
|
||||
public static void setRenderLayer(BlockRenderLayer layer)
|
||||
public static void setRenderLayer(RenderType layer)
|
||||
{
|
||||
renderLayer.set(layer);
|
||||
}
|
||||
@@ -282,8 +301,8 @@ public class ForgeHooksClient
|
||||
for (int z = -distance; z <= distance; ++z)
|
||||
{
|
||||
BlockPos pos = center.add(x, 0, z);
|
||||
Biome biome = world.getBiome(pos);
|
||||
int colour = biome.getSkyColorByTemp(biome.getTemperature(pos));
|
||||
Biome biome = world.func_225526_b_(pos.getX(), pos.getY(), pos.getZ());
|
||||
int colour = 0xFFFFFF; // TODO: biome.getSkyColorByTemp(biome.getTemperature(pos));
|
||||
r += (colour & 0xFF0000) >> 16;
|
||||
g += (colour & 0x00FF00) >> 8;
|
||||
b += colour & 0x0000FF;
|
||||
@@ -356,21 +375,21 @@ public class ForgeHooksClient
|
||||
MinecraftForge.EVENT_BUS.post(new GuiScreenEvent.DrawScreenEvent.Post(screen, mouseX, mouseY, partialTicks));
|
||||
}
|
||||
|
||||
public static float getFogDensity(FogRenderer fogRenderer, GameRenderer renderer, ActiveRenderInfo info, float partial, float density)
|
||||
public static float getFogDensity(FogType type, ActiveRenderInfo info, float partial, float density)
|
||||
{
|
||||
EntityViewRenderEvent.FogDensity event = new EntityViewRenderEvent.FogDensity(fogRenderer, renderer, info, partial, density);
|
||||
EntityViewRenderEvent.FogDensity event = new EntityViewRenderEvent.FogDensity(type, info, partial, density);
|
||||
if (MinecraftForge.EVENT_BUS.post(event)) return event.getDensity();
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static void onFogRender(FogRenderer fogRenderer, GameRenderer renderer, ActiveRenderInfo info, float partial, int mode, float distance)
|
||||
public static void onFogRender(FogType type, ActiveRenderInfo info, float partial, float distance)
|
||||
{
|
||||
MinecraftForge.EVENT_BUS.post(new EntityViewRenderEvent.RenderFogEvent(fogRenderer, renderer, info, partial, mode, distance));
|
||||
MinecraftForge.EVENT_BUS.post(new EntityViewRenderEvent.RenderFogEvent(type, info, partial, distance));
|
||||
}
|
||||
|
||||
public static EntityViewRenderEvent.CameraSetup onCameraSetup(GameRenderer renderer, ActiveRenderInfo info, float partial, float yaw, float pitch, float roll)
|
||||
|
||||
public static EntityViewRenderEvent.CameraSetup onCameraSetup(GameRenderer renderer, ActiveRenderInfo info, float partial)
|
||||
{
|
||||
EntityViewRenderEvent.CameraSetup event = new EntityViewRenderEvent.CameraSetup(renderer, info, partial, yaw, pitch, roll);
|
||||
EntityViewRenderEvent.CameraSetup event = new EntityViewRenderEvent.CameraSetup(renderer, info, partial, info.getYaw(), info.getPitch(), 0);
|
||||
MinecraftForge.EVENT_BUS.post(event);
|
||||
return event;
|
||||
}
|
||||
@@ -386,7 +405,7 @@ public class ForgeHooksClient
|
||||
{
|
||||
Matrix4f m = new Matrix4f(), t = new Matrix4f();
|
||||
m.setIdentity();
|
||||
m.setTranslation(TRSRTransformation.toVecmath(transform.translation));
|
||||
m.setTranslation(TransformationHelper.toVecmath(transform.translation));
|
||||
t.setIdentity();
|
||||
t.rotY(transform.rotation.getY());
|
||||
m.mul(t);
|
||||
@@ -404,32 +423,40 @@ public class ForgeHooksClient
|
||||
return m;
|
||||
}
|
||||
|
||||
private static final Matrix4f flipX;
|
||||
private static final net.minecraft.client.renderer.Matrix4f flipX;
|
||||
static {
|
||||
flipX = new Matrix4f();
|
||||
flipX.setIdentity();
|
||||
flipX.m00 = -1;
|
||||
|
||||
flipX = new net.minecraft.client.renderer.Matrix4f(new float[]{
|
||||
-1, 0, 0, 0,
|
||||
0, 1, 0, 0,
|
||||
0, 0, 1, 0,
|
||||
0, 0, 0, 1
|
||||
});
|
||||
}
|
||||
|
||||
public static IBakedModel handleCameraTransforms(IBakedModel model, ItemCameraTransforms.TransformType cameraTransformType, boolean leftHandHackery)
|
||||
public static IBakedModel handleCameraTransforms(MatrixStack matrixStack, IBakedModel model, ItemCameraTransforms.TransformType cameraTransformType, boolean leftHandHackery)
|
||||
{
|
||||
Pair<? extends IBakedModel, Matrix4f> pair = model.handlePerspective(cameraTransformType);
|
||||
MatrixStack stack = new MatrixStack();
|
||||
model = model.handlePerspective(cameraTransformType, stack);
|
||||
|
||||
if (pair.getRight() != null)
|
||||
// If the stack is not empty, the code has added a matrix for us to use.
|
||||
if (!stack.func_227867_d_())
|
||||
{
|
||||
Matrix4f matrix = new Matrix4f(pair.getRight());
|
||||
// TODO normal matrix?
|
||||
net.minecraft.client.renderer.Matrix4f tMat = stack.func_227866_c_().func_227870_a_();
|
||||
if (leftHandHackery)
|
||||
{
|
||||
matrix.mul(flipX, matrix);
|
||||
matrix.mul(matrix, flipX);
|
||||
tMat.multiplyBackward(flipX);
|
||||
tMat.func_226595_a_(flipX);
|
||||
}
|
||||
multiplyCurrentGlMatrix(matrix);
|
||||
matrixStack.func_227866_c_().func_227870_a_().func_226595_a_(tMat);
|
||||
}
|
||||
return pair.getLeft();
|
||||
return model;
|
||||
}
|
||||
|
||||
private static final FloatBuffer matrixBuf = BufferUtils.createFloatBuffer(16);
|
||||
|
||||
@Deprecated
|
||||
public static void multiplyCurrentGlMatrix(Matrix4f matrix)
|
||||
{
|
||||
matrixBuf.clear();
|
||||
@@ -447,7 +474,7 @@ public class ForgeHooksClient
|
||||
|
||||
public static void preDraw(Usage attrType, VertexFormat format, int element, int stride, ByteBuffer buffer)
|
||||
{
|
||||
VertexFormatElement attr = format.getElement(element);
|
||||
VertexFormatElement attr = format.func_227894_c_().get(element);
|
||||
int count = attr.getElementCount();
|
||||
int constant = attr.getType().getGlConstant();
|
||||
buffer.position(format.getOffset(element));
|
||||
@@ -470,10 +497,10 @@ public class ForgeHooksClient
|
||||
glEnableClientState(GL_COLOR_ARRAY);
|
||||
break;
|
||||
case UV:
|
||||
GLX.glClientActiveTexture(GLX.GL_TEXTURE0 + attr.getIndex());
|
||||
GL13.glClientActiveTexture(GL13.GL_TEXTURE0 + attr.getIndex());
|
||||
glTexCoordPointer(count, constant, stride, buffer);
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
GLX.glClientActiveTexture(GLX.GL_TEXTURE0);
|
||||
GL13.glClientActiveTexture(GL13.GL_TEXTURE0);
|
||||
break;
|
||||
case PADDING:
|
||||
break;
|
||||
@@ -488,7 +515,7 @@ public class ForgeHooksClient
|
||||
|
||||
public static void postDraw(Usage attrType, VertexFormat format, int element, int stride, ByteBuffer buffer)
|
||||
{
|
||||
VertexFormatElement attr = format.getElement(element);
|
||||
VertexFormatElement attr = format.func_227894_c_().get(element);
|
||||
switch(attrType)
|
||||
{
|
||||
case POSITION:
|
||||
@@ -499,13 +526,11 @@ public class ForgeHooksClient
|
||||
break;
|
||||
case COLOR:
|
||||
glDisableClientState(GL_COLOR_ARRAY);
|
||||
// is this really needed?
|
||||
GlStateManager.clearCurrentColor();
|
||||
break;
|
||||
case UV:
|
||||
GLX.glClientActiveTexture(GLX.GL_TEXTURE0 + attr.getIndex());
|
||||
GL13.glClientActiveTexture(GL13.GL_TEXTURE0 + attr.getIndex());
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
GLX.glClientActiveTexture(GLX.GL_TEXTURE0);
|
||||
GL13.glClientActiveTexture(GL13.GL_TEXTURE0);
|
||||
break;
|
||||
case PADDING:
|
||||
break;
|
||||
@@ -527,7 +552,7 @@ public class ForgeHooksClient
|
||||
|
||||
public static Matrix4f getMatrix(ModelRotation modelRotation)
|
||||
{
|
||||
Matrix4f ret = new Matrix4f(TRSRTransformation.toVecmath(modelRotation.func_217650_a()), new Vector3f(), 1), tmp = new Matrix4f();
|
||||
Matrix4f ret = TransformationHelper.toVecmath(modelRotation.func_225615_b_().func_227988_c_()), tmp = new Matrix4f();
|
||||
tmp.setIdentity();
|
||||
tmp.m03 = tmp.m13 = tmp.m23 = .5f;
|
||||
ret.mul(tmp, ret);
|
||||
@@ -537,15 +562,24 @@ public class ForgeHooksClient
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static void putQuadColor(BufferBuilder renderer, BakedQuad quad, int color)
|
||||
public static int getColorIndex(VertexFormat fmt)
|
||||
{
|
||||
ImmutableList<VertexFormatElement> elements = fmt.func_227894_c_();
|
||||
for(int i=0;i<elements.size();i++)
|
||||
{
|
||||
if (elements.get(i).getUsage() == Usage.COLOR)
|
||||
return i;
|
||||
}
|
||||
throw new IndexOutOfBoundsException("There is no COLOR element in the provided VertexFormat.");
|
||||
}
|
||||
|
||||
// TODO: IVertexBuilder doesn't have a means to modify existing data.
|
||||
/*
|
||||
public static void putQuadColor(IVertexBuilder renderer, BakedQuad quad, float cr, float cg, float cb, float ca)
|
||||
{
|
||||
float cb = color & 0xFF;
|
||||
float cg = (color >>> 8) & 0xFF;
|
||||
float cr = (color >>> 16) & 0xFF;
|
||||
float ca = (color >>> 24) & 0xFF;
|
||||
VertexFormat format = quad.getFormat();
|
||||
int size = format.getIntegerSize();
|
||||
int offset = format.getColorOffset() / 4; // assumes that color is aligned
|
||||
int offset = format.getOffset(getColorIndex(format)) / 4; // assumes that color is aligned
|
||||
boolean hasColor = format.hasColor();
|
||||
for(int i = 0; i < 4; i++)
|
||||
{
|
||||
@@ -560,18 +594,17 @@ public class ForgeHooksClient
|
||||
int nca = Math.min(0xFF, (int)(ca * vca / 0xFF));
|
||||
renderer.putColorRGBA(renderer.getColorIndex(4 - i), ncr, ncg, ncb, nca);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
public static TextureAtlasSprite[] getFluidSprites(IEnviromentBlockReader world, BlockPos pos, IFluidState fluidStateIn)
|
||||
public static TextureAtlasSprite[] getFluidSprites(ILightReader world, BlockPos pos, IFluidState fluidStateIn)
|
||||
{
|
||||
AtlasTexture atlas = Minecraft.getInstance().getTextureMap();
|
||||
return new TextureAtlasSprite[] {
|
||||
atlas.getSprite(fluidStateIn.getFluid().getAttributes().getStill(world, pos)),
|
||||
atlas.getSprite(fluidStateIn.getFluid().getAttributes().getFlowing(world, pos)),
|
||||
fluidStateIn.getFluid().getAttributes().getStillMaterial(world, pos).func_229314_c_(),
|
||||
fluidStateIn.getFluid().getAttributes().getFlowingMaterial(world, pos).func_229314_c_(),
|
||||
};
|
||||
}
|
||||
|
||||
public static void gatherFluidTextures(Set<ResourceLocation> textures)
|
||||
public static void gatherFluidTextures(Set<Material> textures)
|
||||
{
|
||||
ForgeRegistries.FLUIDS.getValues().stream()
|
||||
.flatMap(f -> f.getAttributes().getTextures())
|
||||
@@ -581,7 +614,7 @@ public class ForgeHooksClient
|
||||
|
||||
private static class LightGatheringTransformer extends QuadGatheringTransformer {
|
||||
|
||||
private static final VertexFormat FORMAT = new VertexFormat().addElement(DefaultVertexFormats.TEX_2F).addElement(DefaultVertexFormats.TEX_2S);
|
||||
private static final VertexFormat FORMAT = new VertexFormat(ImmutableList.of(DefaultVertexFormats.TEX_2F, DefaultVertexFormats.TEX_2S));
|
||||
|
||||
int blockLight, skyLight;
|
||||
|
||||
@@ -626,7 +659,8 @@ public class ForgeHooksClient
|
||||
|
||||
private static final LightGatheringTransformer lightGatherer = new LightGatheringTransformer();
|
||||
|
||||
public static void renderLitItem(ItemRenderer ri, IBakedModel model, int color, ItemStack stack)
|
||||
// TODO: Fix: Vanilla now batches rendering items, so our hack of forcing the GL lighting state does not work.
|
||||
public static void renderLitItem(ItemRenderer ri, MatrixStack mat, IVertexBuilder consumer, IBakedModel model, ItemStack stack)
|
||||
{
|
||||
List<BakedQuad> allquads = new ArrayList<>();
|
||||
Random random = new Random();
|
||||
@@ -635,11 +669,11 @@ public class ForgeHooksClient
|
||||
for (Direction enumfacing : Direction.values())
|
||||
{
|
||||
random.setSeed(seed);
|
||||
allquads.addAll(model.getQuads(null, enumfacing, random));
|
||||
allquads.addAll(model.getQuads(null, enumfacing, random, EmptyModelData.INSTANCE));
|
||||
}
|
||||
|
||||
random.setSeed(seed);
|
||||
allquads.addAll(model.getQuads(null, null, random));
|
||||
allquads.addAll(model.getQuads(null, null, random, EmptyModelData.INSTANCE));
|
||||
|
||||
if (allquads.isEmpty()) return;
|
||||
|
||||
@@ -665,10 +699,9 @@ public class ForgeHooksClient
|
||||
int bl = 0;
|
||||
int sl = 0;
|
||||
|
||||
// Fail-fast on ITEM, as it cannot have light data
|
||||
if (q.getFormat() != DefaultVertexFormats.ITEM && q.getFormat().hasUv(1))
|
||||
if (q.getFormat().hasUV(1))
|
||||
{
|
||||
q.pipe(lightGatherer);
|
||||
LightUtil.putBakedQuad(lightGatherer, q);
|
||||
if (lightGatherer.hasLighting())
|
||||
{
|
||||
bl = lightGatherer.blockLight;
|
||||
@@ -685,9 +718,7 @@ public class ForgeHooksClient
|
||||
if (lightingDirty || shadeDirty)
|
||||
{
|
||||
if (i > 0) // Make sure this isn't the first quad being processed
|
||||
{
|
||||
drawSegment(ri, color, stack, segment, segmentBlockLight, segmentSkyLight, segmentShading, segmentLightingDirty && (hasLighting || segment.size() < i), segmentShadingDirty);
|
||||
}
|
||||
drawSegment(ri, mat, consumer, stack, segment, segmentBlockLight, segmentSkyLight, segmentShading, segmentLightingDirty && (hasLighting || segment.size() < i), segmentShadingDirty);
|
||||
segmentBlockLight = bl;
|
||||
segmentSkyLight = sl;
|
||||
segmentShading = shade;
|
||||
@@ -699,50 +730,47 @@ public class ForgeHooksClient
|
||||
segment.add(q);
|
||||
}
|
||||
|
||||
drawSegment(ri, color, stack, segment, segmentBlockLight, segmentSkyLight, segmentShading, segmentLightingDirty && (hasLighting || segment.size() < allquads.size()), segmentShadingDirty);
|
||||
drawSegment(ri, mat, consumer, stack, segment, segmentBlockLight, segmentSkyLight, segmentShading, segmentLightingDirty && (hasLighting || segment.size() < allquads.size()), segmentShadingDirty);
|
||||
|
||||
// Clean up render state if necessary
|
||||
if (hasLighting)
|
||||
{
|
||||
GLX.glMultiTexCoord2f(GLX.GL_TEXTURE1, GLX.lastBrightnessX, GLX.lastBrightnessY);
|
||||
GlStateManager.enableLighting();
|
||||
RenderSystem.glMultiTexCoord2f(GL13.GL_TEXTURE1, GlStateManager.lastBrightnessX, GlStateManager.lastBrightnessY);
|
||||
RenderSystem.enableLighting();
|
||||
}
|
||||
}
|
||||
|
||||
private static void drawSegment(ItemRenderer ri, int baseColor, ItemStack stack, List<BakedQuad> segment, int bl, int sl, boolean shade, boolean updateLighting, boolean updateShading)
|
||||
private static void drawSegment(ItemRenderer ir, MatrixStack mat, IVertexBuilder cons, ItemStack stack, List<BakedQuad> segment, int bl, int sl, boolean shade, boolean updateLighting, boolean updateShading)
|
||||
{
|
||||
BufferBuilder bufferbuilder = Tessellator.getInstance().getBuffer();
|
||||
bufferbuilder.begin(GL_QUADS, DefaultVertexFormats.ITEM);
|
||||
|
||||
float lastBl = GLX.lastBrightnessX;
|
||||
float lastSl = GLX.lastBrightnessY;
|
||||
float lastBl = GlStateManager.lastBrightnessX;
|
||||
float lastSl = GlStateManager.lastBrightnessY;
|
||||
|
||||
if (updateShading)
|
||||
{
|
||||
if (shade)
|
||||
{
|
||||
// (Re-)enable lighting for normal look with shading
|
||||
GlStateManager.enableLighting();
|
||||
RenderSystem.enableLighting();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Disable lighting to simulate a lack of diffuse lighting
|
||||
GlStateManager.disableLighting();
|
||||
RenderSystem.disableLighting();
|
||||
}
|
||||
}
|
||||
|
||||
if (updateLighting)
|
||||
{
|
||||
// Force lightmap coords to simulate synthetic lighting
|
||||
GLX.glMultiTexCoord2f(GLX.GL_TEXTURE1, Math.max(bl, lastBl), Math.max(sl, lastSl));
|
||||
RenderSystem.glMultiTexCoord2f(GL13.GL_TEXTURE1, Math.max(bl, lastBl), Math.max(sl, lastSl));
|
||||
}
|
||||
|
||||
ri.renderQuads(bufferbuilder, segment, baseColor, stack);
|
||||
Tessellator.getInstance().draw();
|
||||
// TODO can we just use this light value ??
|
||||
ir.func_229112_a_(mat, cons, segment, stack, (bl << 16) | sl, OverlayTexture.field_229196_a_);
|
||||
|
||||
// Preserve this as it represents the "world" lighting
|
||||
GLX.lastBrightnessX = lastBl;
|
||||
GLX.lastBrightnessY = lastSl;
|
||||
GlStateManager.lastBrightnessX = lastBl;
|
||||
GlStateManager.lastBrightnessY = lastSl;
|
||||
|
||||
segment.clear();
|
||||
}
|
||||
@@ -769,13 +797,13 @@ public class ForgeHooksClient
|
||||
|
||||
for(int i = 0; i < 4; i++)
|
||||
{
|
||||
faceData[i * 7 + 6] = normal;
|
||||
faceData[i * 8 + 6] = normal;
|
||||
}
|
||||
}
|
||||
|
||||
private static Vector3f getVertexPos(int[] data, int vertex)
|
||||
{
|
||||
int idx = vertex * 7;
|
||||
int idx = vertex * 8;
|
||||
|
||||
float x = Float.intBitsToFloat(data[idx]);
|
||||
float y = Float.intBitsToFloat(data[idx + 1]);
|
||||
@@ -784,25 +812,6 @@ public class ForgeHooksClient
|
||||
return new Vector3f(x, y, z);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static Optional<TRSRTransformation> applyTransform(ItemTransformVec3f transform, Optional<? extends IModelPart> part)
|
||||
{
|
||||
if(part.isPresent()) return Optional.empty();
|
||||
return Optional.of(TRSRTransformation.blockCenterToCorner(TRSRTransformation.from(transform)));
|
||||
}
|
||||
|
||||
public static Optional<TRSRTransformation> applyTransform(ModelRotation rotation, Optional<? extends IModelPart> part)
|
||||
{
|
||||
if(part.isPresent()) return Optional.empty();
|
||||
return Optional.of(TRSRTransformation.from(rotation));
|
||||
}
|
||||
|
||||
public static Optional<TRSRTransformation> applyTransform(Matrix4f matrix, Optional<? extends IModelPart> part)
|
||||
{
|
||||
if(part.isPresent()) return Optional.empty();
|
||||
return Optional.of(new TRSRTransformation(matrix));
|
||||
}
|
||||
|
||||
public static void loadEntityShader(Entity entity, GameRenderer entityRenderer)
|
||||
{
|
||||
if (entity != null)
|
||||
@@ -815,12 +824,6 @@ public class ForgeHooksClient
|
||||
}
|
||||
}
|
||||
|
||||
public static IBakedModel getDamageModel(IBakedModel ibakedmodel, TextureAtlasSprite texture, BlockState state, IEnviromentBlockReader world, BlockPos pos, long randomPosition)
|
||||
{
|
||||
state = state.getBlock().getExtendedState(state, world, pos);
|
||||
return (new SimpleBakedModel.Builder(state, ibakedmodel, texture, new Random(), randomPosition)).build();
|
||||
}
|
||||
|
||||
private static int slotMainHand = 0;
|
||||
|
||||
public static boolean shouldCauseReequipAnimation(@Nonnull ItemStack from, @Nonnull ItemStack to, int slot)
|
||||
@@ -840,10 +843,10 @@ public class ForgeHooksClient
|
||||
return from.getItem().shouldCauseReequipAnimation(from, to, changed);
|
||||
}
|
||||
|
||||
public static BlockFaceUV applyUVLock(BlockFaceUV blockFaceUV, Direction originalSide, ITransformation rotation)
|
||||
public static BlockFaceUV applyUVLock(BlockFaceUV blockFaceUV, Direction originalSide, TransformationMatrix rotation, ResourceLocation p_228824_9_)
|
||||
{
|
||||
TRSRTransformation global = new TRSRTransformation(rotation.getMatrixVec());
|
||||
Matrix4f uv = global.getUVLockTransform(originalSide).getMatrixVec();
|
||||
TransformationMatrix global = new TransformationMatrix(rotation.func_227988_c_());
|
||||
Matrix4f uv = TransformationHelper.toVecmath(TransformationHelper.getUVLockTransform(global, originalSide).func_227988_c_());
|
||||
Vector4f vec = new Vector4f(0, 0, 0, 1);
|
||||
float u0 = blockFaceUV.getVertexU(blockFaceUV.getVertexRotatedRev(0));
|
||||
float v0 = blockFaceUV.getVertexV(blockFaceUV.getVertexRotatedRev(0));
|
||||
@@ -903,12 +906,15 @@ public class ForgeHooksClient
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static Pair<? extends IBakedModel,Matrix4f> handlePerspective(IBakedModel model, ItemCameraTransforms.TransformType type)
|
||||
public static IBakedModel handlePerspective(IBakedModel model, ItemCameraTransforms.TransformType type, MatrixStack stack)
|
||||
{
|
||||
TRSRTransformation tr = TRSRTransformation.from(model.getItemCameraTransforms().getTransform(type));
|
||||
Matrix4f mat = null;
|
||||
if(!tr.equals(TRSRTransformation.identity())) mat = tr.getMatrixVec();
|
||||
return Pair.of(model, mat);
|
||||
if (!model.getItemCameraTransforms().getTransform(type).equals(ItemTransformVec3f.DEFAULT))
|
||||
{
|
||||
// Push to the matrix to make it not empty and indicate that we want to transform things
|
||||
stack.func_227860_a_();
|
||||
model.getItemCameraTransforms().getTransform(type).func_228830_a_(false, stack);
|
||||
}
|
||||
return model;
|
||||
}
|
||||
|
||||
public static void onInputUpdate(PlayerEntity player, MovementInput movementInput)
|
||||
@@ -960,7 +966,7 @@ public class ForgeHooksClient
|
||||
|
||||
public static boolean onGuiMouseScrollPre(MouseHelper mouseHelper, Screen guiScreen, double scrollDelta)
|
||||
{
|
||||
MainWindow mainWindow = guiScreen.getMinecraft().mainWindow;
|
||||
MainWindow mainWindow = guiScreen.getMinecraft().func_228018_at_();
|
||||
double mouseX = mouseHelper.getMouseX() * (double) mainWindow.getScaledWidth() / (double) mainWindow.getWidth();
|
||||
double mouseY = mouseHelper.getMouseY() * (double) mainWindow.getScaledHeight() / (double) mainWindow.getHeight();
|
||||
Event event = new GuiScreenEvent.MouseScrollEvent.Pre(guiScreen, mouseX, mouseY, scrollDelta);
|
||||
@@ -969,7 +975,7 @@ public class ForgeHooksClient
|
||||
|
||||
public static boolean onGuiMouseScrollPost(MouseHelper mouseHelper, Screen guiScreen, double scrollDelta)
|
||||
{
|
||||
MainWindow mainWindow = guiScreen.getMinecraft().mainWindow;
|
||||
MainWindow mainWindow = guiScreen.getMinecraft().func_228018_at_();
|
||||
double mouseX = mouseHelper.getMouseX() * (double) mainWindow.getScaledWidth() / (double) mainWindow.getWidth();
|
||||
double mouseY = mouseHelper.getMouseY() * (double) mainWindow.getScaledHeight() / (double) mainWindow.getHeight();
|
||||
Event event = new GuiScreenEvent.MouseScrollEvent.Post(guiScreen, mouseX, mouseY, scrollDelta);
|
||||
|
||||
@@ -46,20 +46,17 @@ import net.minecraft.client.renderer.chunk.ChunkRenderCache;
|
||||
import net.minecraft.client.renderer.texture.NativeImage;
|
||||
import net.minecraft.resources.IResource;
|
||||
import net.minecraft.resources.IResourceManager;
|
||||
import net.minecraft.util.BlockRenderLayer;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.ChunkPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.client.model.IModel;
|
||||
import net.minecraftforge.client.model.data.IModelData;
|
||||
|
||||
public class MinecraftForgeClient
|
||||
{
|
||||
/* TODO: reimplement
|
||||
public static BlockRenderLayer getRenderLayer()
|
||||
{
|
||||
return ForgeHooksClient.renderLayer.get();
|
||||
}
|
||||
}*/
|
||||
|
||||
/**
|
||||
* returns the Locale set by the player in Minecraft.
|
||||
|
||||
@@ -19,16 +19,11 @@
|
||||
|
||||
package net.minecraftforge.client.event;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.renderer.GameRenderer;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.ActiveRenderInfo;
|
||||
import net.minecraft.client.renderer.FogRenderer;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.fluid.IFluidState;
|
||||
import net.minecraft.client.renderer.FogRenderer.FogType;
|
||||
import net.minecraft.client.renderer.GameRenderer;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
|
||||
import net.minecraftforge.eventbus.api.Event.HasResult;
|
||||
|
||||
/**
|
||||
* Event that hooks into GameRenderer, allowing any feature to customize visual attributes
|
||||
@@ -64,15 +59,14 @@ public abstract class EntityViewRenderEvent extends net.minecraftforge.eventbus.
|
||||
|
||||
private static class FogEvent extends EntityViewRenderEvent
|
||||
{
|
||||
private final FogRenderer fogRenderer;
|
||||
|
||||
protected FogEvent(FogRenderer fogRenderer, GameRenderer renderer, ActiveRenderInfo info, double renderPartialTicks)
|
||||
private final FogType type;
|
||||
protected FogEvent(FogType type, ActiveRenderInfo info, double renderPartialTicks)
|
||||
{
|
||||
super(renderer, info, renderPartialTicks);
|
||||
this.fogRenderer = fogRenderer;
|
||||
super(Minecraft.getInstance().gameRenderer, info, renderPartialTicks);
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public FogRenderer getFogRenderer() { return fogRenderer; }
|
||||
public FogType getType() { return type; }
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -84,9 +78,9 @@ public abstract class EntityViewRenderEvent extends net.minecraftforge.eventbus.
|
||||
{
|
||||
private float density;
|
||||
|
||||
public FogDensity(FogRenderer fogRenderer, GameRenderer renderer, ActiveRenderInfo info, double renderPartialTicks, float density)
|
||||
public FogDensity(FogType type, ActiveRenderInfo info, float partialTicks, float density)
|
||||
{
|
||||
super(fogRenderer, renderer, info, renderPartialTicks);
|
||||
super(type, info, partialTicks);
|
||||
this.setDensity(density);
|
||||
}
|
||||
|
||||
@@ -107,19 +101,12 @@ public abstract class EntityViewRenderEvent extends net.minecraftforge.eventbus.
|
||||
@HasResult
|
||||
public static class RenderFogEvent extends FogEvent
|
||||
{
|
||||
private final int fogMode;
|
||||
private final float farPlaneDistance;
|
||||
|
||||
public RenderFogEvent(FogRenderer fogRenderer, GameRenderer renderer, ActiveRenderInfo info, double renderPartialTicks, int fogMode, float farPlaneDistance)
|
||||
public RenderFogEvent(FogType type, ActiveRenderInfo info, float partialTicks, float distance)
|
||||
{
|
||||
super(fogRenderer, renderer, info, renderPartialTicks);
|
||||
this.fogMode = fogMode;
|
||||
this.farPlaneDistance = farPlaneDistance;
|
||||
}
|
||||
|
||||
public int getFogMode()
|
||||
{
|
||||
return fogMode;
|
||||
super(type, info, partialTicks);
|
||||
this.farPlaneDistance = distance;
|
||||
}
|
||||
|
||||
public float getFarPlaneDistance()
|
||||
@@ -132,15 +119,15 @@ public abstract class EntityViewRenderEvent extends net.minecraftforge.eventbus.
|
||||
* Event that allows any feature to customize the color of fog the player sees.
|
||||
* NOTE: Any change made to one of the color variables will affect the result seen in-game.
|
||||
*/
|
||||
public static class FogColors extends FogEvent
|
||||
public static class FogColors extends EntityViewRenderEvent
|
||||
{
|
||||
private float red;
|
||||
private float green;
|
||||
private float blue;
|
||||
|
||||
public FogColors(FogRenderer fogRenderer, GameRenderer renderer, ActiveRenderInfo info, double renderPartialTicks, float red, float green, float blue)
|
||||
public FogColors(ActiveRenderInfo info, float partialTicks, float red, float green, float blue)
|
||||
{
|
||||
super(fogRenderer, renderer, info, renderPartialTicks);
|
||||
super(Minecraft.getInstance().gameRenderer, info, partialTicks);
|
||||
this.setRed(red);
|
||||
this.setGreen(green);
|
||||
this.setBlue(blue);
|
||||
|
||||
@@ -20,28 +20,30 @@
|
||||
package net.minecraftforge.client.event;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraftforge.event.entity.player.PlayerEvent;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
/**
|
||||
* This event is called before the pushOutOfBlocks calls in EntityPlayerSP.
|
||||
*
|
||||
* Cancelling the event will prevent pushOutOfBlocks from being called.
|
||||
*/
|
||||
@net.minecraftforge.eventbus.api.Cancelable
|
||||
@Cancelable
|
||||
public class PlayerSPPushOutOfBlocksEvent extends PlayerEvent
|
||||
{
|
||||
private AxisAlignedBB entityBoundingBox;
|
||||
private double minY;
|
||||
|
||||
public PlayerSPPushOutOfBlocksEvent(PlayerEntity player, AxisAlignedBB entityBoundingBox)
|
||||
public PlayerSPPushOutOfBlocksEvent(PlayerEntity player)
|
||||
{
|
||||
super(player);
|
||||
this.entityBoundingBox = entityBoundingBox;
|
||||
this.minY = player.func_226278_cu_() + 0.5D;
|
||||
}
|
||||
|
||||
public AxisAlignedBB getEntityBoundingBox() { return entityBoundingBox; }
|
||||
public void setEntityBoundingBox(@Nonnull AxisAlignedBB entityBoundingBox) { this.entityBoundingBox = entityBoundingBox; }
|
||||
public void setMinY(double value) {
|
||||
this.minY = value;
|
||||
}
|
||||
|
||||
public double getMinY() {
|
||||
return this.minY;
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,8 @@
|
||||
|
||||
package net.minecraftforge.client.event;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
@@ -29,8 +30,8 @@ import net.minecraftforge.eventbus.api.Event;
|
||||
/**
|
||||
* Called when a block's texture is going to be overlaid on the player's HUD. Cancel this event to prevent the overlay.
|
||||
*/
|
||||
@net.minecraftforge.eventbus.api.Cancelable
|
||||
public class RenderBlockOverlayEvent extends net.minecraftforge.eventbus.api.Event
|
||||
@Cancelable
|
||||
public class RenderBlockOverlayEvent extends Event
|
||||
{
|
||||
|
||||
public static enum OverlayType {
|
||||
@@ -38,15 +39,15 @@ public class RenderBlockOverlayEvent extends net.minecraftforge.eventbus.api.Eve
|
||||
}
|
||||
|
||||
private final PlayerEntity player;
|
||||
private final float renderPartialTicks;
|
||||
private final MatrixStack mat;
|
||||
private final OverlayType overlayType;
|
||||
private final BlockState blockForOverlay;
|
||||
private final BlockPos blockPos;
|
||||
|
||||
public RenderBlockOverlayEvent(PlayerEntity player, float renderPartialTicks, OverlayType type, BlockState block, BlockPos blockPos)
|
||||
public RenderBlockOverlayEvent(PlayerEntity player, MatrixStack mat, OverlayType type, BlockState block, BlockPos blockPos)
|
||||
{
|
||||
this.player = player;
|
||||
this.renderPartialTicks = renderPartialTicks;
|
||||
this.mat = mat;
|
||||
this.overlayType = type;
|
||||
this.blockForOverlay = block;
|
||||
this.blockPos = blockPos;
|
||||
@@ -57,7 +58,7 @@ public class RenderBlockOverlayEvent extends net.minecraftforge.eventbus.api.Eve
|
||||
* The player which the overlay will apply to
|
||||
*/
|
||||
public PlayerEntity getPlayer() { return player; }
|
||||
public float getRenderPartialTicks() { return renderPartialTicks; }
|
||||
public MatrixStack getMatrixStack() { return mat; }
|
||||
/**
|
||||
* The type of overlay to occur
|
||||
*/
|
||||
|
||||
@@ -19,8 +19,8 @@
|
||||
|
||||
package net.minecraftforge.client.event;
|
||||
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
|
||||
import net.minecraft.client.renderer.WorldRenderer;
|
||||
|
||||
/**
|
||||
@@ -34,10 +34,12 @@ import net.minecraft.client.renderer.WorldRenderer;
|
||||
public class RenderHandEvent extends net.minecraftforge.eventbus.api.Event
|
||||
{
|
||||
private final WorldRenderer context;
|
||||
private final MatrixStack mat;
|
||||
private final float partialTicks;
|
||||
public RenderHandEvent(WorldRenderer context, float partialTicks)
|
||||
public RenderHandEvent(WorldRenderer context, MatrixStack mat, float partialTicks)
|
||||
{
|
||||
this.context = context;
|
||||
this.mat = mat;
|
||||
this.partialTicks = partialTicks;
|
||||
}
|
||||
|
||||
@@ -46,6 +48,11 @@ public class RenderHandEvent extends net.minecraftforge.eventbus.api.Event
|
||||
return context;
|
||||
}
|
||||
|
||||
public MatrixStack getMatrixStack()
|
||||
{
|
||||
return mat;
|
||||
}
|
||||
|
||||
public float getPartialTicks()
|
||||
{
|
||||
return partialTicks;
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
package net.minecraftforge.client.event;
|
||||
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import net.minecraft.client.renderer.entity.LivingRenderer;
|
||||
@@ -30,49 +31,44 @@ public abstract class RenderLivingEvent<T extends LivingEntity, M extends Entity
|
||||
private final LivingEntity entity;
|
||||
private final LivingRenderer<T, M> renderer;
|
||||
private final float partialRenderTick;
|
||||
private final double x;
|
||||
private final double y;
|
||||
private final double z;
|
||||
private final MatrixStack matrixStack;
|
||||
|
||||
public RenderLivingEvent(LivingEntity entity, LivingRenderer<T, M> renderer, float partialRenderTick, double x, double y, double z)
|
||||
public RenderLivingEvent(LivingEntity entity, LivingRenderer<T, M> renderer, float partialRenderTick, MatrixStack matrixStack)
|
||||
{
|
||||
this.entity = entity;
|
||||
this.renderer = renderer;
|
||||
this.partialRenderTick = partialRenderTick;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.matrixStack = matrixStack;
|
||||
}
|
||||
|
||||
public LivingEntity getEntity() { return entity; }
|
||||
public LivingRenderer<T, M> getRenderer() { return renderer; }
|
||||
public float getPartialRenderTick() { return partialRenderTick; }
|
||||
public double getX() { return x; }
|
||||
public double getY() { return y; }
|
||||
public double getZ() { return z; }
|
||||
public MatrixStack getMatrixStack() { return matrixStack; }
|
||||
|
||||
@Cancelable
|
||||
public static class Pre<T extends LivingEntity, M extends EntityModel<T>> extends RenderLivingEvent<T, M>
|
||||
{
|
||||
public Pre(LivingEntity entity, LivingRenderer<T, M> renderer, float partialRenderTick, double x, double y, double z){ super(entity, renderer, partialRenderTick, x, y, z); }
|
||||
public Pre(LivingEntity entity, LivingRenderer<T, M> renderer, float partialRenderTick, MatrixStack matrixStack){ super(entity, renderer, partialRenderTick, matrixStack); }
|
||||
}
|
||||
public static class Post<T extends LivingEntity, M extends EntityModel<T>> extends RenderLivingEvent<T, M>
|
||||
{
|
||||
public Post(LivingEntity entity, LivingRenderer<T, M> renderer, float partialRenderTick, double x, double y, double z){ super(entity, renderer, partialRenderTick, x, y, z); }
|
||||
public Post(LivingEntity entity, LivingRenderer<T, M> renderer, float partialRenderTick, MatrixStack matrixStack){ super(entity, renderer, partialRenderTick, matrixStack); }
|
||||
}
|
||||
|
||||
// TODO: 1.15 moved all name rendering to EntityRenderer, such that there's not a Living-specific feature anymore
|
||||
public abstract static class Specials<T extends LivingEntity, M extends EntityModel<T>> extends RenderLivingEvent<T, M>
|
||||
{
|
||||
public Specials(LivingEntity entity, LivingRenderer<T, M> renderer, double x, double y, double z){ super(entity, renderer, 0, x, y, z); }
|
||||
public Specials(LivingEntity entity, LivingRenderer<T, M> renderer, MatrixStack matrixStack){ super(entity, renderer, 0, matrixStack); }
|
||||
|
||||
@Cancelable
|
||||
public static class Pre<T extends LivingEntity, M extends EntityModel<T>> extends Specials<T, M>
|
||||
{
|
||||
public Pre(LivingEntity entity, LivingRenderer<T, M> renderer, double x, double y, double z){ super(entity, renderer, x, y, z); }
|
||||
public Pre(LivingEntity entity, LivingRenderer<T, M> renderer, MatrixStack matrixStack){ super(entity, renderer, matrixStack); }
|
||||
}
|
||||
public static class Post<T extends LivingEntity, M extends EntityModel<T>> extends Specials<T, M>
|
||||
{
|
||||
public Post(LivingEntity entity, LivingRenderer<T, M> renderer, double x, double y, double z){ super(entity, renderer, x, y, z); }
|
||||
public Post(LivingEntity entity, LivingRenderer<T, M> renderer, MatrixStack matrixStack){ super(entity, renderer, matrixStack); }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
package net.minecraftforge.client.event;
|
||||
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraft.client.renderer.entity.PlayerRenderer;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
@@ -31,35 +32,29 @@ public abstract class RenderPlayerEvent extends PlayerEvent
|
||||
{
|
||||
private final PlayerRenderer renderer;
|
||||
private final float partialRenderTick;
|
||||
private final double x;
|
||||
private final double y;
|
||||
private final double z;
|
||||
private final MatrixStack stack;
|
||||
|
||||
public RenderPlayerEvent(PlayerEntity player, PlayerRenderer renderer, float partialRenderTick, double x, double y, double z)
|
||||
public RenderPlayerEvent(PlayerEntity player, PlayerRenderer renderer, float partialRenderTick, MatrixStack stack)
|
||||
{
|
||||
super(player);
|
||||
this.renderer = renderer;
|
||||
this.partialRenderTick = partialRenderTick;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.stack = stack;
|
||||
}
|
||||
|
||||
public PlayerRenderer getRenderer() { return renderer; }
|
||||
public float getPartialRenderTick() { return partialRenderTick; }
|
||||
public double getX() { return x; }
|
||||
public double getY() { return y; }
|
||||
public double getZ() { return z; }
|
||||
public MatrixStack getMatrixStack() { return stack; }
|
||||
|
||||
@net.minecraftforge.eventbus.api.Cancelable
|
||||
public static class Pre extends RenderPlayerEvent
|
||||
{
|
||||
public Pre(PlayerEntity player, PlayerRenderer renderer, float tick, double x, double y, double z){ super(player, renderer, tick, x, y, z); }
|
||||
public Pre(PlayerEntity player, PlayerRenderer renderer, float tick, MatrixStack stack){ super(player, renderer, tick, stack); }
|
||||
}
|
||||
|
||||
public static class Post extends RenderPlayerEvent
|
||||
{
|
||||
public Post(PlayerEntity player, PlayerRenderer renderer, float tick, double x, double y, double z){ super(player, renderer, tick, x, y, z); }
|
||||
public Post(PlayerEntity player, PlayerRenderer renderer, float tick, MatrixStack stack){ super(player, renderer, tick, stack); }
|
||||
}
|
||||
|
||||
}
|
||||
@@ -19,13 +19,15 @@
|
||||
|
||||
package net.minecraftforge.client.event;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
/**
|
||||
* This event is fired on the {@link net.minecraftforge.common.MinecraftForge#EVENT_BUS}
|
||||
* whenever a hand is rendered in first person.
|
||||
@@ -36,6 +38,7 @@ import javax.annotation.Nonnull;
|
||||
public class RenderSpecificHandEvent extends Event
|
||||
{
|
||||
private final Hand hand;
|
||||
private final MatrixStack mat;
|
||||
private final float partialTicks;
|
||||
private final float interpolatedPitch;
|
||||
private final float swingProgress;
|
||||
@@ -43,9 +46,10 @@ public class RenderSpecificHandEvent extends Event
|
||||
@Nonnull
|
||||
private final ItemStack stack;
|
||||
|
||||
public RenderSpecificHandEvent(Hand hand, float partialTicks, float interpolatedPitch, float swingProgress, float equipProgress, @Nonnull ItemStack stack)
|
||||
public RenderSpecificHandEvent(Hand hand, MatrixStack mat, float partialTicks, float interpolatedPitch, float swingProgress, float equipProgress, @Nonnull ItemStack stack)
|
||||
{
|
||||
this.hand = hand;
|
||||
this.mat = mat;
|
||||
this.partialTicks = partialTicks;
|
||||
this.interpolatedPitch = interpolatedPitch;
|
||||
this.swingProgress = swingProgress;
|
||||
@@ -58,6 +62,11 @@ public class RenderSpecificHandEvent extends Event
|
||||
return hand;
|
||||
}
|
||||
|
||||
public MatrixStack getMatrixStack()
|
||||
{
|
||||
return mat;
|
||||
}
|
||||
|
||||
public float getPartialTicks()
|
||||
{
|
||||
return partialTicks;
|
||||
|
||||
@@ -19,16 +19,19 @@
|
||||
|
||||
package net.minecraftforge.client.event;
|
||||
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
|
||||
import net.minecraft.client.renderer.WorldRenderer;
|
||||
|
||||
public class RenderWorldLastEvent extends net.minecraftforge.eventbus.api.Event
|
||||
{
|
||||
private final WorldRenderer context;
|
||||
private final MatrixStack mat;
|
||||
private final float partialTicks;
|
||||
public RenderWorldLastEvent(WorldRenderer context, float partialTicks)
|
||||
public RenderWorldLastEvent(WorldRenderer context, MatrixStack mat, float partialTicks)
|
||||
{
|
||||
this.context = context;
|
||||
this.mat = mat;
|
||||
this.partialTicks = partialTicks;
|
||||
}
|
||||
|
||||
@@ -37,6 +40,11 @@ public class RenderWorldLastEvent extends net.minecraftforge.eventbus.api.Event
|
||||
return context;
|
||||
}
|
||||
|
||||
public MatrixStack getMatrixStack()
|
||||
{
|
||||
return mat;
|
||||
}
|
||||
|
||||
public float getPartialTicks()
|
||||
{
|
||||
return partialTicks;
|
||||
|
||||
@@ -26,6 +26,7 @@ import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* This event is fired before and after a screenshot is taken
|
||||
@@ -51,6 +52,9 @@ public class ScreenshotEvent extends Event
|
||||
{
|
||||
this.image = image;
|
||||
this.screenshotFile = screenshotFile;
|
||||
try {
|
||||
this.screenshotFile = screenshotFile.getCanonicalFile(); // FORGE: Fix errors on Windows with paths that include \.\
|
||||
} catch (IOException e) {}
|
||||
}
|
||||
|
||||
public NativeImage getImage()
|
||||
|
||||
@@ -24,6 +24,9 @@ import java.util.Random;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.vecmath.Matrix4f;
|
||||
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.renderer.model.BakedQuad;
|
||||
@@ -32,8 +35,9 @@ import net.minecraft.client.renderer.model.ItemCameraTransforms;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IEnviromentBlockReader;
|
||||
import net.minecraft.world.ILightReader;
|
||||
import net.minecraftforge.client.model.data.IModelData;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
public interface IForgeBakedModel
|
||||
{
|
||||
@@ -50,16 +54,21 @@ public interface IForgeBakedModel
|
||||
|
||||
default boolean isAmbientOcclusion(BlockState state) { return getBakedModel().isAmbientOcclusion(); }
|
||||
|
||||
/**
|
||||
* Override to tell the new model loader that it shouldn't wrap this model
|
||||
*/
|
||||
default boolean doesHandlePerspectives() { return false; }
|
||||
|
||||
/*
|
||||
* Returns the pair of the model for the given perspective, and the matrix that
|
||||
* should be applied to the GL state before rendering it (matrix may be null).
|
||||
*/
|
||||
default org.apache.commons.lang3.tuple.Pair<? extends IBakedModel, javax.vecmath.Matrix4f> handlePerspective(ItemCameraTransforms.TransformType cameraTransformType)
|
||||
default IBakedModel handlePerspective(ItemCameraTransforms.TransformType cameraTransformType, MatrixStack mat)
|
||||
{
|
||||
return net.minecraftforge.client.ForgeHooksClient.handlePerspective(getBakedModel(), cameraTransformType);
|
||||
return net.minecraftforge.client.ForgeHooksClient.handlePerspective(getBakedModel(), cameraTransformType, mat);
|
||||
}
|
||||
|
||||
default @Nonnull IModelData getModelData(@Nonnull IEnviromentBlockReader world, @Nonnull BlockPos pos, @Nonnull BlockState state, @Nonnull IModelData tileData)
|
||||
default @Nonnull IModelData getModelData(@Nonnull ILightReader world, @Nonnull BlockPos pos, @Nonnull BlockState state, @Nonnull IModelData tileData)
|
||||
{
|
||||
return tileData;
|
||||
}
|
||||
|
||||
+7
-4
@@ -17,15 +17,15 @@
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package net.minecraftforge.common.model;
|
||||
package net.minecraftforge.client.extensions;
|
||||
|
||||
import java.util.Optional;
|
||||
import net.minecraft.client.renderer.TransformationMatrix;
|
||||
|
||||
/**
|
||||
* An {@code IModelState} is a function from model part to a transformation that should be applied
|
||||
* when that part is baked, thus representing the current "state" of the model and its parts.
|
||||
*/
|
||||
public interface IModelState
|
||||
public interface IForgeModelTransform
|
||||
{
|
||||
/**
|
||||
* @param part Part of the model we are wanting to transform. An empty optional means
|
||||
@@ -33,5 +33,8 @@ public interface IModelState
|
||||
* @return A transformation to apply to the part, if any. The coordinate system of the transform
|
||||
* is determined by the part type.
|
||||
*/
|
||||
Optional<TRSRTransformation> apply(Optional<? extends IModelPart> part);
|
||||
default TransformationMatrix getPartTransformation(Object part)
|
||||
{
|
||||
return TransformationMatrix.func_227983_a_();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* Minecraft Forge
|
||||
* Copyright (c) 2016-2019.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation version 2.1
|
||||
* of the License.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package net.minecraftforge.client.extensions;
|
||||
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import net.minecraft.client.renderer.Matrix4f;
|
||||
import net.minecraft.client.renderer.TransformationMatrix;
|
||||
import net.minecraft.client.renderer.Vector3f;
|
||||
import net.minecraft.client.renderer.Vector4f;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraftforge.common.model.TransformationHelper;
|
||||
|
||||
/*
|
||||
* Replacement interface for ModelRotation to allow custom transformations of vanilla models.
|
||||
* You should probably use TRSRTransformation directly.
|
||||
*/
|
||||
public interface IForgeTransformationMatrix
|
||||
{
|
||||
default TransformationMatrix getTransformaion()
|
||||
{
|
||||
return (TransformationMatrix)this;
|
||||
}
|
||||
|
||||
default boolean isIdentity()
|
||||
{
|
||||
return getTransformaion().equals(TransformationMatrix.func_227983_a_());
|
||||
}
|
||||
|
||||
default void push(MatrixStack stack)
|
||||
{
|
||||
stack.func_227860_a_();
|
||||
stack.func_227863_a_(getTransformaion().func_227989_d_());
|
||||
Vector3f trans = getTransformaion().getTranslation();
|
||||
stack.func_227861_a_(trans.getX(), trans.getY(), trans.getZ());
|
||||
stack.func_227863_a_(getTransformaion().getRightRot());
|
||||
Vector3f scale = getTransformaion().getScale();
|
||||
stack.func_227861_a_(scale.getX(), scale.getY(), scale.getZ());
|
||||
}
|
||||
|
||||
default TransformationMatrix compose(TransformationMatrix other)
|
||||
{
|
||||
if (getTransformaion().isIdentity()) return other;
|
||||
if (other.isIdentity()) return getTransformaion();
|
||||
Matrix4f m = getTransformaion().func_227988_c_();
|
||||
m.func_226595_a_(other.func_227988_c_());
|
||||
return new TransformationMatrix(m);
|
||||
}
|
||||
|
||||
default TransformationMatrix inverse()
|
||||
{
|
||||
if (isIdentity()) return getTransformaion();
|
||||
javax.vecmath.Matrix4f m = TransformationHelper.toVecmath(getTransformaion().func_227988_c_());
|
||||
m.invert();
|
||||
return new TransformationMatrix(TransformationHelper.toMojang(m));
|
||||
}
|
||||
|
||||
default void transformPosition(Vector4f position)
|
||||
{
|
||||
TransformationHelper.transform(getTransformaion().func_227988_c_(), position);
|
||||
}
|
||||
|
||||
default void transformNormal(Vector3f normal)
|
||||
{
|
||||
javax.vecmath.Vector3f copy = TransformationHelper.toVecmath(normal);
|
||||
transformNormal(copy);
|
||||
normal.set(copy.x, copy.y, copy.z);
|
||||
}
|
||||
|
||||
default void transformNormal(javax.vecmath.Vector3f normal)
|
||||
{
|
||||
getTransformaion().getNormalMatrix().transform(normal);
|
||||
normal.normalize();
|
||||
}
|
||||
|
||||
default Direction rotateTransform(Direction facing)
|
||||
{
|
||||
return Direction.func_229385_a_(getTransformaion().func_227988_c_(), facing);
|
||||
}
|
||||
|
||||
}
|
||||
+12
-13
@@ -17,21 +17,20 @@
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package net.minecraftforge.common.model;
|
||||
package net.minecraftforge.client.extensions;
|
||||
|
||||
import javax.vecmath.Matrix4f;
|
||||
import net.minecraftforge.common.model.animation.IClip;
|
||||
|
||||
import net.minecraft.util.Direction;
|
||||
import java.util.Optional;
|
||||
|
||||
/*
|
||||
* Replacement interface for ModelRotation to allow custom transformations of vanilla models.
|
||||
* You should probably use TRSRTransformation directly.
|
||||
*/
|
||||
public interface ITransformation
|
||||
public interface IForgeUnbakedModel
|
||||
{
|
||||
Matrix4f getMatrixVec();
|
||||
|
||||
Direction rotateTransform(Direction facing);
|
||||
|
||||
int rotate(Direction facing, int vertexIndex);
|
||||
/**
|
||||
* Retrieves information about an animation clip in the model.
|
||||
* @param name The clip name
|
||||
* @return
|
||||
*/
|
||||
default Optional<? extends IClip> getClip(String name) {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Minecraft Forge
|
||||
* Copyright (c) 2016-2019.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation version 2.1
|
||||
* of the License.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package net.minecraftforge.client.extensions;
|
||||
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import com.mojang.blaze3d.vertex.IVertexBuilder;
|
||||
import net.minecraft.client.renderer.Matrix4f;
|
||||
import net.minecraft.client.renderer.Vector3f;
|
||||
import net.minecraft.client.renderer.Vector4f;
|
||||
import net.minecraft.client.renderer.model.BakedQuad;
|
||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||
import net.minecraft.util.math.Vec3i;
|
||||
import org.lwjgl.system.MemoryStack;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.IntBuffer;
|
||||
|
||||
public interface IForgeVertexBuilder
|
||||
{
|
||||
// Copy of func_227889_a_ with alpha support
|
||||
default void addVertexData(MatrixStack.Entry matrixEntry, BakedQuad bakedQuad, float red, float green, float blue, float alpha, int lightmapCoord, int overlayColkor) {
|
||||
addVertexData(matrixEntry, bakedQuad, new float[]{1.0F, 1.0F, 1.0F, 1.0F}, red, green, blue, alpha, new int[]{lightmapCoord, lightmapCoord, lightmapCoord, lightmapCoord}, overlayColkor, false);
|
||||
}
|
||||
|
||||
// Copy of func_227890_a_ with alpha support
|
||||
default void addVertexData(MatrixStack.Entry matrixEntry, BakedQuad bakedQuad, float[] baseBrightness, float red, float green, float blue, float alpha, int[] lightmapCoords, int overlayCoords, boolean p_227890_9_) {
|
||||
int[] aint = bakedQuad.getVertexData();
|
||||
Vec3i faceNormal = bakedQuad.getFace().getDirectionVec();
|
||||
Vector3f normal = new Vector3f((float)faceNormal.getX(), (float)faceNormal.getY(), (float)faceNormal.getZ());
|
||||
Matrix4f matrix4f = matrixEntry.func_227870_a_();
|
||||
normal.func_229188_a_(matrixEntry.func_227872_b_());
|
||||
int intSize = DefaultVertexFormats.BLOCK.getIntegerSize();
|
||||
int vertexCount = aint.length / intSize;
|
||||
|
||||
try (MemoryStack memorystack = MemoryStack.stackPush()) {
|
||||
ByteBuffer bytebuffer = memorystack.malloc(DefaultVertexFormats.BLOCK.getSize());
|
||||
IntBuffer intbuffer = bytebuffer.asIntBuffer();
|
||||
|
||||
for(int v = 0; v < vertexCount; ++v) {
|
||||
intbuffer.clear();
|
||||
intbuffer.put(aint, v * 8, 8);
|
||||
float f = bytebuffer.getFloat(0);
|
||||
float f1 = bytebuffer.getFloat(4);
|
||||
float f2 = bytebuffer.getFloat(8);
|
||||
float cr;
|
||||
float cg;
|
||||
float cb;
|
||||
float ca;
|
||||
if (p_227890_9_) {
|
||||
float r = (float)(bytebuffer.get(12) & 255) / 255.0F;
|
||||
float g = (float)(bytebuffer.get(13) & 255) / 255.0F;
|
||||
float b = (float)(bytebuffer.get(14) & 255) / 255.0F;
|
||||
float a = (float)(bytebuffer.get(15) & 255) / 255.0F;
|
||||
cr = r * baseBrightness[v] * red;
|
||||
cg = g * baseBrightness[v] * green;
|
||||
cb = b * baseBrightness[v] * blue;
|
||||
ca = a * alpha;
|
||||
} else {
|
||||
cr = baseBrightness[v] * red;
|
||||
cg = baseBrightness[v] * green;
|
||||
cb = baseBrightness[v] * blue;
|
||||
ca = alpha;
|
||||
}
|
||||
|
||||
int lightmapCoord = lightmapCoords[v];
|
||||
float f9 = bytebuffer.getFloat(16);
|
||||
float f10 = bytebuffer.getFloat(20);
|
||||
Vector4f pos = new Vector4f(f, f1, f2, 1.0F);
|
||||
pos.func_229372_a_(matrix4f);
|
||||
((IVertexBuilder)this).func_225588_a_(pos.getX(), pos.getY(), pos.getZ(), cr, cg, cb, ca, f9, f10, overlayCoords, lightmapCoord, normal.getX(), normal.getY(), normal.getZ());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+68
-69
@@ -17,7 +17,7 @@
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package net.minecraftforge.client;
|
||||
package net.minecraftforge.client.gui;
|
||||
|
||||
import static net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType.*;
|
||||
|
||||
@@ -55,10 +55,10 @@ import net.minecraftforge.client.event.RenderGameOverlayEvent;
|
||||
import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
|
||||
import com.mojang.blaze3d.platform.GlStateManager;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
|
||||
public class ForgeIngameGui extends IngameGui
|
||||
{
|
||||
//private static final ResourceLocation VIGNETTE = new ResourceLocation("textures/misc/vignette.png");
|
||||
@@ -107,9 +107,9 @@ public class ForgeIngameGui extends IngameGui
|
||||
@Override
|
||||
public void renderGameOverlay(float partialTicks)
|
||||
{
|
||||
this.scaledWidth = this.mc.mainWindow.getScaledWidth();
|
||||
this.scaledHeight = this.mc.mainWindow.getScaledHeight();
|
||||
eventParent = new RenderGameOverlayEvent(partialTicks, this.mc.mainWindow);
|
||||
this.scaledWidth = this.mc.func_228018_at_().getScaledWidth();
|
||||
this.scaledHeight = this.mc.func_228018_at_().getScaledHeight();
|
||||
eventParent = new RenderGameOverlayEvent(partialTicks, this.mc.func_228018_at_());
|
||||
renderHealthMount = mc.player.getRidingEntity() instanceof LivingEntity;
|
||||
renderFood = mc.player.getRidingEntity() == null;
|
||||
renderJumpBar = mc.player.isRidingHorse();
|
||||
@@ -121,15 +121,15 @@ public class ForgeIngameGui extends IngameGui
|
||||
|
||||
fontrenderer = mc.fontRenderer;
|
||||
//mc.entityRenderer.setupOverlayRendering();
|
||||
GlStateManager.enableBlend();
|
||||
RenderSystem.enableBlend();
|
||||
if (renderVignette && Minecraft.isFancyGraphicsEnabled())
|
||||
{
|
||||
renderVignette(mc.getRenderViewEntity());
|
||||
}
|
||||
else
|
||||
{
|
||||
GlStateManager.enableDepthTest();
|
||||
GlStateManager.blendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
|
||||
RenderSystem.enableDepthTest();
|
||||
RenderSystem.defaultBlendFunc();
|
||||
}
|
||||
|
||||
if (renderHelmet) renderHelmet(partialTicks);
|
||||
@@ -149,14 +149,14 @@ public class ForgeIngameGui extends IngameGui
|
||||
}
|
||||
|
||||
if (!this.mc.gameSettings.hideGUI) {
|
||||
GlStateManager.color4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
blitOffset = -90;
|
||||
RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
setBlitOffset(-90);
|
||||
rand.setSeed((long)(ticks * 312871));
|
||||
|
||||
if (renderCrosshairs) renderAttackIndicator();
|
||||
if (renderBossHealth) renderBossHealth();
|
||||
|
||||
GlStateManager.color4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
if (this.mc.playerController.shouldDrawHUD() && this.mc.getRenderViewEntity() instanceof PlayerEntity)
|
||||
{
|
||||
if (renderHealth) renderHealth(this.scaledWidth, this.scaledHeight);
|
||||
@@ -207,17 +207,16 @@ public class ForgeIngameGui extends IngameGui
|
||||
this.renderScoreboard(scoreobjective1);
|
||||
}
|
||||
|
||||
GlStateManager.enableBlend();
|
||||
GlStateManager.blendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0);
|
||||
GlStateManager.disableAlphaTest();
|
||||
RenderSystem.enableBlend();
|
||||
RenderSystem.blendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0);
|
||||
RenderSystem.disableAlphaTest();
|
||||
|
||||
renderChat(this.scaledWidth, this.scaledHeight);
|
||||
|
||||
renderPlayerList(this.scaledWidth, this.scaledHeight);
|
||||
|
||||
GlStateManager.color4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
GlStateManager.disableLighting();
|
||||
GlStateManager.enableAlphaTest();
|
||||
RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
RenderSystem.enableAlphaTest();
|
||||
|
||||
post(ALL);
|
||||
}
|
||||
@@ -227,8 +226,8 @@ public class ForgeIngameGui extends IngameGui
|
||||
{
|
||||
if (pre(CROSSHAIRS)) return;
|
||||
bind(AbstractGui.GUI_ICONS_LOCATION);
|
||||
GlStateManager.enableBlend();
|
||||
GlStateManager.enableAlphaTest();
|
||||
RenderSystem.enableBlend();
|
||||
RenderSystem.enableAlphaTest();
|
||||
super.renderAttackIndicator();
|
||||
post(CROSSHAIRS);
|
||||
}
|
||||
@@ -252,11 +251,11 @@ public class ForgeIngameGui extends IngameGui
|
||||
{
|
||||
if (pre(BOSSHEALTH)) return;
|
||||
bind(AbstractGui.GUI_ICONS_LOCATION);
|
||||
GlStateManager.blendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
|
||||
RenderSystem.defaultBlendFunc();
|
||||
mc.getProfiler().startSection("bossHealth");
|
||||
GlStateManager.enableBlend();
|
||||
RenderSystem.enableBlend();
|
||||
this.overlayBoss.render();
|
||||
GlStateManager.disableBlend();
|
||||
RenderSystem.disableBlend();
|
||||
mc.getProfiler().endSection();
|
||||
post(BOSSHEALTH);
|
||||
}
|
||||
@@ -267,8 +266,8 @@ public class ForgeIngameGui extends IngameGui
|
||||
if (pre(VIGNETTE))
|
||||
{
|
||||
// Need to put this here, since Vanilla assumes this state after the vignette was rendered.
|
||||
GlStateManager.enableDepthTest();
|
||||
GlStateManager.blendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
|
||||
RenderSystem.enableDepthTest();
|
||||
RenderSystem.defaultBlendFunc();
|
||||
return;
|
||||
}
|
||||
super.renderVignette(entity);
|
||||
@@ -302,7 +301,7 @@ public class ForgeIngameGui extends IngameGui
|
||||
if (pre(ARMOR)) return;
|
||||
mc.getProfiler().startSection("armor");
|
||||
|
||||
GlStateManager.enableBlend();
|
||||
RenderSystem.enableBlend();
|
||||
int left = width / 2 - 91;
|
||||
int top = height - left_height;
|
||||
|
||||
@@ -325,7 +324,7 @@ public class ForgeIngameGui extends IngameGui
|
||||
}
|
||||
left_height += 10;
|
||||
|
||||
GlStateManager.disableBlend();
|
||||
RenderSystem.disableBlend();
|
||||
mc.getProfiler().endSection();
|
||||
post(ARMOR);
|
||||
}
|
||||
@@ -373,7 +372,7 @@ public class ForgeIngameGui extends IngameGui
|
||||
if (pre(AIR)) return;
|
||||
mc.getProfiler().startSection("air");
|
||||
PlayerEntity player = (PlayerEntity)this.mc.getRenderViewEntity();
|
||||
GlStateManager.enableBlend();
|
||||
RenderSystem.enableBlend();
|
||||
int left = width / 2 + 91;
|
||||
int top = height - right_height;
|
||||
|
||||
@@ -390,7 +389,7 @@ public class ForgeIngameGui extends IngameGui
|
||||
right_height += 10;
|
||||
}
|
||||
|
||||
GlStateManager.disableBlend();
|
||||
RenderSystem.disableBlend();
|
||||
mc.getProfiler().endSection();
|
||||
post(AIR);
|
||||
}
|
||||
@@ -400,7 +399,7 @@ public class ForgeIngameGui extends IngameGui
|
||||
bind(GUI_ICONS_LOCATION);
|
||||
if (pre(HEALTH)) return;
|
||||
mc.getProfiler().startSection("health");
|
||||
GlStateManager.enableBlend();
|
||||
RenderSystem.enableBlend();
|
||||
|
||||
PlayerEntity player = (PlayerEntity)this.mc.getRenderViewEntity();
|
||||
int health = MathHelper.ceil(player.getHealth());
|
||||
@@ -496,7 +495,7 @@ public class ForgeIngameGui extends IngameGui
|
||||
}
|
||||
}
|
||||
|
||||
GlStateManager.disableBlend();
|
||||
RenderSystem.disableBlend();
|
||||
mc.getProfiler().endSection();
|
||||
post(HEALTH);
|
||||
}
|
||||
@@ -507,7 +506,7 @@ public class ForgeIngameGui extends IngameGui
|
||||
mc.getProfiler().startSection("food");
|
||||
|
||||
PlayerEntity player = (PlayerEntity)this.mc.getRenderViewEntity();
|
||||
GlStateManager.enableBlend();
|
||||
RenderSystem.enableBlend();
|
||||
int left = width / 2 + 91;
|
||||
int top = height - right_height;
|
||||
right_height += 10;
|
||||
@@ -543,7 +542,7 @@ public class ForgeIngameGui extends IngameGui
|
||||
else if (idx == level)
|
||||
blit(x, y, icon + 45, 27, 9, 9);
|
||||
}
|
||||
GlStateManager.disableBlend();
|
||||
RenderSystem.disableBlend();
|
||||
mc.getProfiler().endSection();
|
||||
post(FOOD);
|
||||
}
|
||||
@@ -553,8 +552,8 @@ public class ForgeIngameGui extends IngameGui
|
||||
if (mc.player.getSleepTimer() > 0)
|
||||
{
|
||||
mc.getProfiler().startSection("sleep");
|
||||
GlStateManager.disableDepthTest();
|
||||
GlStateManager.disableAlphaTest();
|
||||
RenderSystem.disableDepthTest();
|
||||
RenderSystem.disableAlphaTest();
|
||||
int sleepTime = mc.player.getSleepTimer();
|
||||
float opacity = (float)sleepTime / 100.0F;
|
||||
|
||||
@@ -565,8 +564,8 @@ public class ForgeIngameGui extends IngameGui
|
||||
|
||||
int color = (int)(220.0F * opacity) << 24 | 1052704;
|
||||
fill(0, 0, width, height, color);
|
||||
GlStateManager.enableAlphaTest();
|
||||
GlStateManager.enableDepthTest();
|
||||
RenderSystem.enableAlphaTest();
|
||||
RenderSystem.enableDepthTest();
|
||||
mc.getProfiler().endSection();
|
||||
}
|
||||
}
|
||||
@@ -575,15 +574,15 @@ public class ForgeIngameGui extends IngameGui
|
||||
{
|
||||
bind(GUI_ICONS_LOCATION);
|
||||
if (pre(EXPERIENCE)) return;
|
||||
GlStateManager.color4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
GlStateManager.disableBlend();
|
||||
RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
RenderSystem.disableBlend();
|
||||
|
||||
if (mc.playerController.gameIsSurvivalOrAdventure())
|
||||
{
|
||||
super.renderExpBar(x);
|
||||
}
|
||||
GlStateManager.enableBlend();
|
||||
GlStateManager.color4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
RenderSystem.enableBlend();
|
||||
RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
|
||||
post(EXPERIENCE);
|
||||
}
|
||||
@@ -594,11 +593,11 @@ public class ForgeIngameGui extends IngameGui
|
||||
bind(GUI_ICONS_LOCATION);
|
||||
if (pre(JUMPBAR)) return;
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
GlStateManager.disableBlend();
|
||||
RenderSystem.disableBlend();
|
||||
|
||||
super.renderHorseJumpBar(x);
|
||||
|
||||
GlStateManager.enableBlend();
|
||||
RenderSystem.enableBlend();
|
||||
mc.getProfiler().endSection();
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
|
||||
@@ -608,7 +607,7 @@ public class ForgeIngameGui extends IngameGui
|
||||
protected void renderHUDText(int width, int height)
|
||||
{
|
||||
mc.getProfiler().startSection("forgeHudText");
|
||||
GlStateManager.blendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
|
||||
RenderSystem.defaultBlendFunc();
|
||||
ArrayList<String> listL = new ArrayList<String>();
|
||||
ArrayList<String> listR = new ArrayList<String>();
|
||||
|
||||
@@ -681,14 +680,14 @@ public class ForgeIngameGui extends IngameGui
|
||||
|
||||
if (opacity > 0)
|
||||
{
|
||||
GlStateManager.pushMatrix();
|
||||
GlStateManager.translatef((float)(width / 2), (float)(height - 68), 0.0F);
|
||||
GlStateManager.enableBlend();
|
||||
GlStateManager.blendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
|
||||
RenderSystem.pushMatrix();
|
||||
RenderSystem.translatef((float)(width / 2), (float)(height - 68), 0.0F);
|
||||
RenderSystem.enableBlend();
|
||||
RenderSystem.defaultBlendFunc();
|
||||
int color = (animateOverlayMessageColor ? MathHelper.hsvToRGB(hue / 50.0F, 0.7F, 0.6F) & WHITE : WHITE);
|
||||
fontrenderer.drawStringWithShadow(overlayMessage, -fontrenderer.getStringWidth(overlayMessage) / 2, -4, color | (opacity << 24));
|
||||
GlStateManager.disableBlend();
|
||||
GlStateManager.popMatrix();
|
||||
RenderSystem.disableBlend();
|
||||
RenderSystem.popMatrix();
|
||||
}
|
||||
|
||||
mc.getProfiler().endSection();
|
||||
@@ -714,21 +713,21 @@ public class ForgeIngameGui extends IngameGui
|
||||
|
||||
if (opacity > 8)
|
||||
{
|
||||
GlStateManager.pushMatrix();
|
||||
GlStateManager.translatef((float)(width / 2), (float)(height / 2), 0.0F);
|
||||
GlStateManager.enableBlend();
|
||||
GlStateManager.blendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
|
||||
GlStateManager.pushMatrix();
|
||||
GlStateManager.scalef(4.0F, 4.0F, 4.0F);
|
||||
RenderSystem.pushMatrix();
|
||||
RenderSystem.translatef((float)(width / 2), (float)(height / 2), 0.0F);
|
||||
RenderSystem.enableBlend();
|
||||
RenderSystem.defaultBlendFunc();
|
||||
RenderSystem.pushMatrix();
|
||||
RenderSystem.scalef(4.0F, 4.0F, 4.0F);
|
||||
int l = opacity << 24 & -16777216;
|
||||
this.getFontRenderer().drawStringWithShadow(this.displayedTitle, (float)(-this.getFontRenderer().getStringWidth(this.displayedTitle) / 2), -10.0F, 16777215 | l);
|
||||
GlStateManager.popMatrix();
|
||||
GlStateManager.pushMatrix();
|
||||
GlStateManager.scalef(2.0F, 2.0F, 2.0F);
|
||||
RenderSystem.popMatrix();
|
||||
RenderSystem.pushMatrix();
|
||||
RenderSystem.scalef(2.0F, 2.0F, 2.0F);
|
||||
this.getFontRenderer().drawStringWithShadow(this.displayedSubTitle, (float)(-this.getFontRenderer().getStringWidth(this.displayedSubTitle) / 2), 5.0F, 16777215 | l);
|
||||
GlStateManager.popMatrix();
|
||||
GlStateManager.disableBlend();
|
||||
GlStateManager.popMatrix();
|
||||
RenderSystem.popMatrix();
|
||||
RenderSystem.disableBlend();
|
||||
RenderSystem.popMatrix();
|
||||
}
|
||||
|
||||
this.mc.getProfiler().endSection();
|
||||
@@ -742,10 +741,10 @@ public class ForgeIngameGui extends IngameGui
|
||||
RenderGameOverlayEvent.Chat event = new RenderGameOverlayEvent.Chat(eventParent, 0, height - 48);
|
||||
if (MinecraftForge.EVENT_BUS.post(event)) return;
|
||||
|
||||
GlStateManager.pushMatrix();
|
||||
GlStateManager.translatef((float) event.getPosX(), (float) event.getPosY(), 0.0F);
|
||||
RenderSystem.pushMatrix();
|
||||
RenderSystem.translatef((float) event.getPosX(), (float) event.getPosY(), 0.0F);
|
||||
persistantChatGUI.render(ticks);
|
||||
GlStateManager.popMatrix();
|
||||
RenderSystem.popMatrix();
|
||||
|
||||
post(CHAT);
|
||||
|
||||
@@ -784,7 +783,7 @@ public class ForgeIngameGui extends IngameGui
|
||||
int left_align = width / 2 + 91;
|
||||
|
||||
mc.getProfiler().endStartSection("mountHealth");
|
||||
GlStateManager.enableBlend();
|
||||
RenderSystem.enableBlend();
|
||||
LivingEntity mount = (LivingEntity)tmp;
|
||||
int health = (int)Math.ceil((double)mount.getHealth());
|
||||
float healthMax = mount.getMaxHealth();
|
||||
@@ -817,7 +816,7 @@ public class ForgeIngameGui extends IngameGui
|
||||
|
||||
right_height += 10;
|
||||
}
|
||||
GlStateManager.disableBlend();
|
||||
RenderSystem.disableBlend();
|
||||
post(HEALTHMOUNT);
|
||||
}
|
||||
|
||||
@@ -849,8 +848,8 @@ public class ForgeIngameGui extends IngameGui
|
||||
this.rayTraceBlock = entity.func_213324_a(rayTraceDistance, 0.0F, false);
|
||||
this.rayTraceFluid = entity.func_213324_a(rayTraceDistance, 0.0F, true);
|
||||
}
|
||||
@Override protected void renderDebugInfoLeft(){}
|
||||
@Override protected void renderDebugInfoRight(){}
|
||||
@Override protected void func_230024_c_(){}
|
||||
@Override protected void func_230025_d_(){}
|
||||
private List<String> getLeft()
|
||||
{
|
||||
List<String> ret = this.call();
|
||||
@@ -19,7 +19,7 @@
|
||||
|
||||
package net.minecraftforge.client.gui;
|
||||
|
||||
import com.mojang.blaze3d.platform.GlStateManager;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.widget.button.Button;
|
||||
@@ -28,7 +28,6 @@ import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.text.TranslationTextComponent;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.minecraftforge.common.ForgeMod;
|
||||
import net.minecraftforge.fml.loading.FMLConfig;
|
||||
import net.minecraftforge.versions.forge.ForgeVersion;
|
||||
import net.minecraftforge.fml.VersionChecker;
|
||||
@@ -73,8 +72,8 @@ public class NotificationModUpdateScreen extends Screen
|
||||
}
|
||||
|
||||
Minecraft.getInstance().getTextureManager().bindTexture(VERSION_CHECK_ICONS);
|
||||
GlStateManager.color4f(1, 1, 1, 1);
|
||||
GlStateManager.pushMatrix();
|
||||
RenderSystem.color4f(1, 1, 1, 1);
|
||||
RenderSystem.pushMatrix();
|
||||
|
||||
int x = modButton.x;
|
||||
int y = modButton.y;
|
||||
@@ -82,7 +81,7 @@ public class NotificationModUpdateScreen extends Screen
|
||||
int h = modButton.getHeight();
|
||||
|
||||
blit(x + w - (h / 2 + 4), y + (h / 2 - 4), showNotification.getSheetOffset() * 8, (showNotification.isAnimated() && ((System.currentTimeMillis() / 800 & 1) == 1)) ? 8 : 0, 8, 8, 64, 16);
|
||||
GlStateManager.popMatrix();
|
||||
RenderSystem.popMatrix();
|
||||
}
|
||||
|
||||
public static NotificationModUpdateScreen init(MainMenuScreen guiMainMenu, Button modButton)
|
||||
|
||||
@@ -25,6 +25,7 @@ import java.util.List;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import com.mojang.blaze3d.platform.GlStateManager;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.AbstractGui;
|
||||
@@ -72,8 +73,8 @@ public abstract class ScrollPanel extends FocusableGui implements IRenderable
|
||||
/**
|
||||
* Draw anything special on the screen. GL_SCISSOR is enabled for anything that
|
||||
* is rendered outside of the view box. Do not mess with SCISSOR unless you support this.
|
||||
* @param mouseY
|
||||
* @param mouseX
|
||||
* @param mouseY
|
||||
* @param mouseX
|
||||
*/
|
||||
protected abstract void drawPanel(int entryRight, int relativeY, Tessellator tess, int mouseX, int mouseY);
|
||||
|
||||
@@ -134,7 +135,7 @@ public abstract class ScrollPanel extends FocusableGui implements IRenderable
|
||||
return true;
|
||||
|
||||
this.scrolling = button == 0 && mouseX >= barLeft && mouseX < barLeft + barWidth;
|
||||
if (this.scrolling)
|
||||
if (this.scrolling)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -189,9 +190,9 @@ public abstract class ScrollPanel extends FocusableGui implements IRenderable
|
||||
Tessellator tess = Tessellator.getInstance();
|
||||
BufferBuilder worldr = tess.getBuffer();
|
||||
|
||||
double scale = client.mainWindow.getGuiScaleFactor();
|
||||
double scale = client.func_228018_at_().getGuiScaleFactor();
|
||||
GL11.glEnable(GL11.GL_SCISSOR_TEST);
|
||||
GL11.glScissor((int)(left * scale), (int)(client.mainWindow.getFramebufferHeight() - (bottom * scale)),
|
||||
GL11.glScissor((int)(left * scale), (int)(client.func_228018_at_().getFramebufferHeight() - (bottom * scale)),
|
||||
(int)(width * scale), (int)(height * scale));
|
||||
|
||||
if (this.client.world != null)
|
||||
@@ -200,23 +201,23 @@ public abstract class ScrollPanel extends FocusableGui implements IRenderable
|
||||
}
|
||||
else // Draw dark dirt background
|
||||
{
|
||||
GlStateManager.disableLighting();
|
||||
GlStateManager.disableFog();
|
||||
RenderSystem.disableLighting();
|
||||
RenderSystem.disableFog();
|
||||
this.client.getTextureManager().bindTexture(AbstractGui.BACKGROUND_LOCATION);
|
||||
GlStateManager.color4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
final float texScale = 32.0F;
|
||||
worldr.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_COLOR);
|
||||
worldr.pos(this.left, this.bottom, 0.0D).tex(this.left / texScale, (this.bottom + (int)this.scrollDistance) / texScale).color(0x20, 0x20, 0x20, 0xFF).endVertex();
|
||||
worldr.pos(this.right, this.bottom, 0.0D).tex(this.right / texScale, (this.bottom + (int)this.scrollDistance) / texScale).color(0x20, 0x20, 0x20, 0xFF).endVertex();
|
||||
worldr.pos(this.right, this.top, 0.0D).tex(this.right / texScale, (this.top + (int)this.scrollDistance) / texScale).color(0x20, 0x20, 0x20, 0xFF).endVertex();
|
||||
worldr.pos(this.left, this.top, 0.0D).tex(this.left / texScale, (this.top + (int)this.scrollDistance) / texScale).color(0x20, 0x20, 0x20, 0xFF).endVertex();
|
||||
worldr.func_225582_a_(this.left, this.bottom, 0.0D).func_225583_a_(this.left / texScale, (this.bottom + (int)this.scrollDistance) / texScale).func_225586_a_(0x20, 0x20, 0x20, 0xFF).endVertex();
|
||||
worldr.func_225582_a_(this.right, this.bottom, 0.0D).func_225583_a_(this.right / texScale, (this.bottom + (int)this.scrollDistance) / texScale).func_225586_a_(0x20, 0x20, 0x20, 0xFF).endVertex();
|
||||
worldr.func_225582_a_(this.right, this.top, 0.0D).func_225583_a_(this.right / texScale, (this.top + (int)this.scrollDistance) / texScale).func_225586_a_(0x20, 0x20, 0x20, 0xFF).endVertex();
|
||||
worldr.func_225582_a_(this.left, this.top, 0.0D).func_225583_a_(this.left / texScale, (this.top + (int)this.scrollDistance) / texScale).func_225586_a_(0x20, 0x20, 0x20, 0xFF).endVertex();
|
||||
tess.draw();
|
||||
}
|
||||
|
||||
int baseY = this.top + border - (int)this.scrollDistance;
|
||||
this.drawPanel(right, baseY, tess, mouseX, mouseY);
|
||||
|
||||
GlStateManager.disableDepthTest();
|
||||
RenderSystem.disableDepthTest();
|
||||
|
||||
int extraHeight = (this.getContentHeight() + border) - height;
|
||||
if (extraHeight > 0)
|
||||
@@ -229,31 +230,31 @@ public abstract class ScrollPanel extends FocusableGui implements IRenderable
|
||||
barTop = this.top;
|
||||
}
|
||||
|
||||
GlStateManager.disableTexture();
|
||||
RenderSystem.disableTexture();
|
||||
worldr.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_COLOR);
|
||||
worldr.pos(barLeft, this.bottom, 0.0D).tex(0.0D, 1.0D).color(0x00, 0x00, 0x00, 0xFF).endVertex();
|
||||
worldr.pos(barLeft + barWidth, this.bottom, 0.0D).tex(1.0D, 1.0D).color(0x00, 0x00, 0x00, 0xFF).endVertex();
|
||||
worldr.pos(barLeft + barWidth, this.top, 0.0D).tex(1.0D, 0.0D).color(0x00, 0x00, 0x00, 0xFF).endVertex();
|
||||
worldr.pos(barLeft, this.top, 0.0D).tex(0.0D, 0.0D).color(0x00, 0x00, 0x00, 0xFF).endVertex();
|
||||
worldr.func_225582_a_(barLeft, this.bottom, 0.0D).func_225583_a_(0.0F, 1.0F).func_225586_a_(0x00, 0x00, 0x00, 0xFF).endVertex();
|
||||
worldr.func_225582_a_(barLeft + barWidth, this.bottom, 0.0D).func_225583_a_(1.0F, 1.0F).func_225586_a_(0x00, 0x00, 0x00, 0xFF).endVertex();
|
||||
worldr.func_225582_a_(barLeft + barWidth, this.top, 0.0D).func_225583_a_(1.0F, 0.0F).func_225586_a_(0x00, 0x00, 0x00, 0xFF).endVertex();
|
||||
worldr.func_225582_a_(barLeft, this.top, 0.0D).func_225583_a_(0.0F, 0.0F).func_225586_a_(0x00, 0x00, 0x00, 0xFF).endVertex();
|
||||
tess.draw();
|
||||
worldr.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_COLOR);
|
||||
worldr.pos(barLeft, barTop + barHeight, 0.0D).tex(0.0D, 1.0D).color(0x80, 0x80, 0x80, 0xFF).endVertex();
|
||||
worldr.pos(barLeft + barWidth, barTop + barHeight, 0.0D).tex(1.0D, 1.0D).color(0x80, 0x80, 0x80, 0xFF).endVertex();
|
||||
worldr.pos(barLeft + barWidth, barTop, 0.0D).tex(1.0D, 0.0D).color(0x80, 0x80, 0x80, 0xFF).endVertex();
|
||||
worldr.pos(barLeft, barTop, 0.0D).tex(0.0D, 0.0D).color(0x80, 0x80, 0x80, 0xFF).endVertex();
|
||||
worldr.func_225582_a_(barLeft, barTop + barHeight, 0.0D).func_225583_a_(0.0F, 1.0F).func_225586_a_(0x80, 0x80, 0x80, 0xFF).endVertex();
|
||||
worldr.func_225582_a_(barLeft + barWidth, barTop + barHeight, 0.0D).func_225583_a_(1.0F, 1.0F).func_225586_a_(0x80, 0x80, 0x80, 0xFF).endVertex();
|
||||
worldr.func_225582_a_(barLeft + barWidth, barTop, 0.0D).func_225583_a_(1.0F, 0.0F).func_225586_a_(0x80, 0x80, 0x80, 0xFF).endVertex();
|
||||
worldr.func_225582_a_(barLeft, barTop, 0.0D).func_225583_a_(0.0F, 0.0F).func_225586_a_(0x80, 0x80, 0x80, 0xFF).endVertex();
|
||||
tess.draw();
|
||||
worldr.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_COLOR);
|
||||
worldr.pos(barLeft, barTop + barHeight - 1, 0.0D).tex(0.0D, 1.0D).color(0xC0, 0xC0, 0xC0, 0xFF).endVertex();
|
||||
worldr.pos(barLeft + barWidth - 1, barTop + barHeight - 1, 0.0D).tex(1.0D, 1.0D).color(0xC0, 0xC0, 0xC0, 0xFF).endVertex();
|
||||
worldr.pos(barLeft + barWidth - 1, barTop, 0.0D).tex(1.0D, 0.0D).color(0xC0, 0xC0, 0xC0, 0xFF).endVertex();
|
||||
worldr.pos(barLeft, barTop, 0.0D).tex(0.0D, 0.0D).color(0xC0, 0xC0, 0xC0, 0xFF).endVertex();
|
||||
worldr.func_225582_a_(barLeft, barTop + barHeight - 1, 0.0D).func_225583_a_(0.0F, 1.0F).func_225586_a_(0xC0, 0xC0, 0xC0, 0xFF).endVertex();
|
||||
worldr.func_225582_a_(barLeft + barWidth - 1, barTop + barHeight - 1, 0.0D).func_225583_a_(1.0F, 1.0F).func_225586_a_(0xC0, 0xC0, 0xC0, 0xFF).endVertex();
|
||||
worldr.func_225582_a_(barLeft + barWidth - 1, barTop, 0.0D).func_225583_a_(1.0F, 0.0F).func_225586_a_(0xC0, 0xC0, 0xC0, 0xFF).endVertex();
|
||||
worldr.func_225582_a_(barLeft, barTop, 0.0D).func_225583_a_(0.0F, 0.0F).func_225586_a_(0xC0, 0xC0, 0xC0, 0xFF).endVertex();
|
||||
tess.draw();
|
||||
}
|
||||
|
||||
GlStateManager.enableTexture();
|
||||
GlStateManager.shadeModel(GL11.GL_FLAT);
|
||||
GlStateManager.enableAlphaTest();
|
||||
GlStateManager.disableBlend();
|
||||
RenderSystem.enableTexture();
|
||||
RenderSystem.shadeModel(GL11.GL_FLAT);
|
||||
RenderSystem.enableAlphaTest();
|
||||
RenderSystem.disableBlend();
|
||||
GL11.glDisable(GL11.GL_SCISSOR_TEST);
|
||||
}
|
||||
|
||||
@@ -263,7 +264,7 @@ public abstract class ScrollPanel extends FocusableGui implements IRenderable
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends IGuiEventListener> children()
|
||||
public List<? extends IGuiEventListener> children()
|
||||
{
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@@ -19,6 +19,8 @@
|
||||
|
||||
package net.minecraftforge.client.model;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormat;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormatElement;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormatElement.Type;
|
||||
@@ -29,16 +31,7 @@ public class Attributes
|
||||
/*
|
||||
* Default format of the data in IBakedModel
|
||||
*/
|
||||
public static final VertexFormat DEFAULT_BAKED_FORMAT;
|
||||
|
||||
static
|
||||
{
|
||||
DEFAULT_BAKED_FORMAT = new VertexFormat();
|
||||
DEFAULT_BAKED_FORMAT.addElement(new VertexFormatElement(0, Type.FLOAT, Usage.POSITION, 3));
|
||||
DEFAULT_BAKED_FORMAT.addElement(new VertexFormatElement(0, Type.UBYTE, Usage.COLOR, 4));
|
||||
DEFAULT_BAKED_FORMAT.addElement(new VertexFormatElement(0, Type.FLOAT, Usage.UV, 2));
|
||||
DEFAULT_BAKED_FORMAT.addElement(new VertexFormatElement(0, Type.BYTE, Usage.PADDING, 4));
|
||||
}
|
||||
public static final VertexFormat DEFAULT_BAKED_FORMAT = DefaultVertexFormats.BLOCK;
|
||||
|
||||
/*
|
||||
* Can first format be used where second is expected
|
||||
@@ -50,13 +43,15 @@ public class Attributes
|
||||
|
||||
int padding = 0;
|
||||
int j = 0;
|
||||
for(VertexFormatElement firstAttr : first.getElements())
|
||||
ImmutableList<VertexFormatElement> elementsFirst = first.func_227894_c_();
|
||||
ImmutableList<VertexFormatElement> elementsSecond = second.func_227894_c_();
|
||||
for(VertexFormatElement firstAttr : elementsFirst)
|
||||
{
|
||||
while(j < second.getElementCount() && second.getElement(j).getUsage() == Usage.PADDING)
|
||||
while(j < elementsSecond.size() && elementsSecond.get(j).getUsage() == Usage.PADDING)
|
||||
{
|
||||
padding += second.getElement(j++).getSize();
|
||||
padding += elementsSecond.get(j++).getSize();
|
||||
}
|
||||
if(j >= second.getElementCount() && padding == 0)
|
||||
if(j >= elementsSecond.size() && padding == 0)
|
||||
{
|
||||
// if no padding is left, but there are still elements in first (we're processing one) - it doesn't fit
|
||||
return false;
|
||||
@@ -64,7 +59,7 @@ public class Attributes
|
||||
if(padding == 0)
|
||||
{
|
||||
// no padding - attributes have to match
|
||||
VertexFormatElement secondAttr = second.getElement(j++);
|
||||
VertexFormatElement secondAttr = elementsSecond.get(j++);
|
||||
if(
|
||||
firstAttr.getIndex() != secondAttr.getIndex() ||
|
||||
firstAttr.getElementCount() != secondAttr.getElementCount() ||
|
||||
@@ -82,7 +77,7 @@ public class Attributes
|
||||
}
|
||||
}
|
||||
|
||||
if(padding != 0 || j != second.getElementCount()) return false;
|
||||
if(padding != 0 || j != elementsSecond.size()) return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -27,32 +27,26 @@ import java.util.Random;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.renderer.TransformationMatrix;
|
||||
import net.minecraft.client.renderer.model.BakedQuad;
|
||||
import net.minecraft.client.renderer.model.IBakedModel;
|
||||
import net.minecraft.client.renderer.model.ItemCameraTransforms.TransformType;
|
||||
import net.minecraft.client.renderer.model.ItemOverrideList;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraftforge.common.model.TRSRTransformation;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
public class BakedItemModel implements IBakedModel
|
||||
{
|
||||
protected final ImmutableList<BakedQuad> quads;
|
||||
protected final TextureAtlasSprite particle;
|
||||
protected final ImmutableMap<TransformType, TRSRTransformation> transforms;
|
||||
protected final ImmutableMap<TransformType, TransformationMatrix> transforms;
|
||||
protected final ItemOverrideList overrides;
|
||||
protected final IBakedModel guiModel;
|
||||
|
||||
/** @deprecated use {@link #BakedItemModel(ImmutableList, TextureAtlasSprite, ImmutableMap, ItemOverrideList, boolean)} */
|
||||
@Deprecated // TODO: remove
|
||||
public BakedItemModel(ImmutableList<BakedQuad> quads, TextureAtlasSprite particle, ImmutableMap<TransformType, TRSRTransformation> transforms, ItemOverrideList overrides)
|
||||
{
|
||||
this(quads, particle, transforms, overrides, true);
|
||||
}
|
||||
|
||||
public BakedItemModel(ImmutableList<BakedQuad> quads, TextureAtlasSprite particle, ImmutableMap<TransformType, TRSRTransformation> transforms, ItemOverrideList overrides, boolean untransformed)
|
||||
public BakedItemModel(ImmutableList<BakedQuad> quads, TextureAtlasSprite particle, ImmutableMap<TransformType, TransformationMatrix> transforms, ItemOverrideList overrides, boolean untransformed)
|
||||
{
|
||||
this.quads = quads;
|
||||
this.particle = particle;
|
||||
@@ -61,9 +55,9 @@ public class BakedItemModel implements IBakedModel
|
||||
this.guiModel = untransformed && hasGuiIdentity(transforms) ? new BakedGuiItemModel<>(this) : null;
|
||||
}
|
||||
|
||||
private static boolean hasGuiIdentity(ImmutableMap<TransformType, TRSRTransformation> transforms)
|
||||
private static boolean hasGuiIdentity(ImmutableMap<TransformType, TransformationMatrix> transforms)
|
||||
{
|
||||
TRSRTransformation guiTransform = transforms.get(TransformType.GUI);
|
||||
TransformationMatrix guiTransform = transforms.get(TransformType.GUI);
|
||||
return guiTransform == null || guiTransform.isIdentity();
|
||||
}
|
||||
|
||||
@@ -84,13 +78,13 @@ public class BakedItemModel implements IBakedModel
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pair<? extends IBakedModel, Matrix4f> handlePerspective(TransformType type)
|
||||
public IBakedModel handlePerspective(TransformType type, MatrixStack mat)
|
||||
{
|
||||
if (type == TransformType.GUI && this.guiModel != null)
|
||||
{
|
||||
return this.guiModel.handlePerspective(type);
|
||||
return this.guiModel.handlePerspective(type, mat);
|
||||
}
|
||||
return PerspectiveMapWrapper.handlePerspective(this, transforms, type);
|
||||
return PerspectiveMapWrapper.handlePerspective(this, transforms, type, mat);
|
||||
}
|
||||
|
||||
public static class BakedGuiItemModel<T extends BakedItemModel> extends BakedModelWrapper<T>
|
||||
@@ -122,13 +116,19 @@ public class BakedItemModel implements IBakedModel
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pair<? extends IBakedModel, Matrix4f> handlePerspective(TransformType type)
|
||||
public boolean doesHandlePerspectives()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBakedModel handlePerspective(TransformType type, MatrixStack mat)
|
||||
{
|
||||
if (type == TransformType.GUI)
|
||||
{
|
||||
return PerspectiveMapWrapper.handlePerspective(this, originalModel.transforms, type);
|
||||
return PerspectiveMapWrapper.handlePerspective(this, originalModel.transforms, type, mat);
|
||||
}
|
||||
return this.originalModel.handlePerspective(type);
|
||||
return this.originalModel.handlePerspective(type, mat);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,7 @@ import javax.vecmath.Matrix4f;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.renderer.model.BakedQuad;
|
||||
import net.minecraft.client.renderer.model.IBakedModel;
|
||||
@@ -33,7 +34,7 @@ import net.minecraft.client.renderer.model.ItemOverrideList;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IEnviromentBlockReader;
|
||||
import net.minecraft.world.ILightReader;
|
||||
import net.minecraft.world.IWorldReader;
|
||||
import net.minecraftforge.client.model.data.IModelData;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
@@ -96,9 +97,15 @@ public abstract class BakedModelWrapper<T extends IBakedModel> implements IBaked
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pair<? extends IBakedModel, Matrix4f> handlePerspective(ItemCameraTransforms.TransformType cameraTransformType)
|
||||
public boolean doesHandlePerspectives()
|
||||
{
|
||||
return originalModel.handlePerspective(cameraTransformType);
|
||||
return originalModel.doesHandlePerspectives();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBakedModel handlePerspective(ItemCameraTransforms.TransformType cameraTransformType, MatrixStack mat)
|
||||
{
|
||||
return originalModel.handlePerspective(cameraTransformType, mat);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -116,7 +123,7 @@ public abstract class BakedModelWrapper<T extends IBakedModel> implements IBaked
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public IModelData getModelData(@Nonnull IEnviromentBlockReader world, @Nonnull BlockPos pos, @Nonnull BlockState state, @Nonnull IModelData tileData)
|
||||
public IModelData getModelData(@Nonnull ILightReader world, @Nonnull BlockPos pos, @Nonnull BlockState state, @Nonnull IModelData tileData)
|
||||
{
|
||||
return originalModel.getModelData(world, pos, state, tileData);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,174 @@
|
||||
/*
|
||||
* Minecraft Forge
|
||||
* Copyright (c) 2016-2019.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation version 2.1
|
||||
* of the License.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package net.minecraftforge.client.model;
|
||||
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import net.minecraft.client.renderer.model.*;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.client.model.geometry.IModelGeometry;
|
||||
import net.minecraftforge.client.model.geometry.IModelGeometryPart;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class BlockModelConfiguration implements IModelConfiguration
|
||||
{
|
||||
public final BlockModel owner;
|
||||
public final VisibilityData visibilityData = new VisibilityData();
|
||||
@Nullable
|
||||
private IModelGeometry<?> customGeometry;
|
||||
@Nullable
|
||||
private IModelTransform customModelState;
|
||||
|
||||
public BlockModelConfiguration(BlockModel owner)
|
||||
{
|
||||
this.owner = owner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getModelName()
|
||||
{
|
||||
return owner.name;
|
||||
}
|
||||
|
||||
public boolean hasCustomGeometry()
|
||||
{
|
||||
return getCustomGeometry() != null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public IModelGeometry<?> getCustomGeometry()
|
||||
{
|
||||
return owner.parent != null && customGeometry == null ? owner.parent.customData.getCustomGeometry() : customGeometry;
|
||||
}
|
||||
|
||||
public void setCustomGeometry(IModelGeometry<?> geometry)
|
||||
{
|
||||
this.customGeometry = geometry;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public IModelTransform getCustomModelState()
|
||||
{
|
||||
return owner.parent != null && customModelState == null ? owner.parent.customData.getCustomModelState() : customModelState;
|
||||
}
|
||||
|
||||
public void setCustomModelState(IModelTransform modelState)
|
||||
{
|
||||
this.customModelState = modelState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getPartVisibility(IModelGeometryPart part, boolean fallback)
|
||||
{
|
||||
return owner.parent != null && !visibilityData.hasCustomVisibility(part) ?
|
||||
owner.parent.customData.getPartVisibility(part, fallback):
|
||||
visibilityData.isVisible(part, fallback);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTexturePresent(String name)
|
||||
{
|
||||
return owner.isTexturePresent(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Material resolveTexture(String name)
|
||||
{
|
||||
return owner.func_228816_c_(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isShadedInGui() {
|
||||
return owner.isGui3d();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean useSmoothLighting()
|
||||
{
|
||||
return owner.isAmbientOcclusion();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemCameraTransforms getCameraTransforms()
|
||||
{
|
||||
return owner.getAllTransforms();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IModelTransform getCombinedTransform()
|
||||
{
|
||||
IModelTransform state = getCustomModelState();
|
||||
|
||||
return state != null
|
||||
? new SimpleModelTransform(PerspectiveMapWrapper.getTransformsWithFallback(state, getCameraTransforms()), state.func_225615_b_())
|
||||
: new SimpleModelTransform(PerspectiveMapWrapper.getTransforms(getCameraTransforms()));
|
||||
}
|
||||
|
||||
public void copyFrom(BlockModelConfiguration other)
|
||||
{
|
||||
this.customGeometry = other.customGeometry;
|
||||
this.customModelState = other.customModelState;
|
||||
this.visibilityData.copyFrom(other.visibilityData);
|
||||
}
|
||||
|
||||
public Collection<Material> getTextureDependencies(Function<ResourceLocation, IUnbakedModel> modelGetter, Set<Pair<String, String>> missingTextureErrors)
|
||||
{
|
||||
IModelGeometry<?> geometry = getCustomGeometry();
|
||||
return geometry == null ? Collections.emptySet() :
|
||||
geometry.getTextures(this, modelGetter, missingTextureErrors);
|
||||
}
|
||||
|
||||
public IBakedModel bake(ModelBakery bakery, Function<Material, TextureAtlasSprite> bakedTextureGetter, IModelTransform sprite, ItemOverrideList overrides, ResourceLocation modelLocation)
|
||||
{
|
||||
IModelGeometry<?> geometry = getCustomGeometry();
|
||||
if (geometry == null)
|
||||
throw new IllegalStateException("Can not use custom baking without custom geometry");
|
||||
return geometry.bake(this, bakery, bakedTextureGetter, sprite, overrides, modelLocation);
|
||||
}
|
||||
|
||||
public static class VisibilityData
|
||||
{
|
||||
private final Map<String, Boolean> data = new HashMap<>();
|
||||
|
||||
public boolean hasCustomVisibility(IModelGeometryPart part)
|
||||
{
|
||||
return data.containsKey(part.name());
|
||||
}
|
||||
|
||||
public boolean isVisible(IModelGeometryPart part, boolean fallback)
|
||||
{
|
||||
return data.getOrDefault(part.name(), fallback);
|
||||
}
|
||||
|
||||
public void setVisibilityState(String partName, boolean type)
|
||||
{
|
||||
data.put(partName, type);
|
||||
}
|
||||
|
||||
public void copyFrom(VisibilityData visibilityData)
|
||||
{
|
||||
data.clear();
|
||||
data.putAll(visibilityData.data);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,244 +0,0 @@
|
||||
/*
|
||||
* Minecraft Forge
|
||||
* Copyright (c) 2016-2019.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation version 2.1
|
||||
* of the License.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package net.minecraftforge.client.model;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.Reader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
import net.minecraft.client.renderer.model.*;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.common.model.IModelState;
|
||||
import net.minecraftforge.common.model.TRSRTransformation;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class BlockStateLoader
|
||||
{
|
||||
private static final Gson GSON = (new GsonBuilder())
|
||||
.registerTypeAdapter(ForgeBlockStateV1.class, ForgeBlockStateV1.Deserializer.INSTANCE)
|
||||
.registerTypeAdapter(ForgeBlockStateV1.Variant.class, ForgeBlockStateV1.Variant.Deserializer.INSTANCE)
|
||||
.registerTypeAdapter(TRSRTransformation.class, ForgeBlockStateV1.TRSRDeserializer.INSTANCE)
|
||||
.create();
|
||||
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
|
||||
private static long internalGeneratedModelId = 1;
|
||||
|
||||
/**
|
||||
* Loads a BlockStates json file.
|
||||
* Will attempt to parse it as a Forge Enhanced version if possible.
|
||||
* Will fall back to standard loading if marker is not present.
|
||||
*
|
||||
* Note: This method is NOT thread safe
|
||||
*
|
||||
* @param reader json read
|
||||
* @param location blockstate location
|
||||
* @param vanillaGSON ModelBlockDefinition's GSON reader.
|
||||
*
|
||||
* @return Model definition including variants for all known combinations.
|
||||
*/
|
||||
public static BlockModelDefinition load(Reader reader, ResourceLocation location, final Gson vanillaGSON, ModelBakery bakery, BiConsumer<ResourceLocation, IUnbakedModel> modelConsumer)
|
||||
{
|
||||
try
|
||||
{
|
||||
byte[] data = IOUtils.toByteArray(reader, StandardCharsets.UTF_8);
|
||||
reader = new InputStreamReader(new ByteArrayInputStream(data), StandardCharsets.UTF_8);
|
||||
|
||||
Marker marker = GSON.fromJson(new String(data, StandardCharsets.UTF_8), Marker.class); // Read "forge_marker" to determine what to load.
|
||||
|
||||
switch (marker.forge_marker)
|
||||
{
|
||||
case 1: // Version 1
|
||||
ForgeBlockStateV1 v1 = GSON.fromJson(reader, ForgeBlockStateV1.class);
|
||||
Map<String, VariantList> variants = Maps.newLinkedHashMap();
|
||||
|
||||
for (Entry<String, Collection<ForgeBlockStateV1.Variant>> entry : v1.variants.asMap().entrySet())
|
||||
{ // Convert Version1 variants into vanilla variants for the ModelBlockDefinition.
|
||||
List<Variant> mcVars = Lists.newArrayList();
|
||||
for (ForgeBlockStateV1.Variant var : entry.getValue())
|
||||
{
|
||||
boolean uvLock = var.getUvLock().orElse(false);
|
||||
int weight = var.getWeight().orElse(1);
|
||||
|
||||
ResourceLocation modelLocation = var.getModel();
|
||||
if (!var.isVanillaCompatible() && bakery != null)
|
||||
{
|
||||
modelLocation = new ResourceLocation(
|
||||
"internal",
|
||||
String.format("%d/%s/%s/%s", internalGeneratedModelId++, location.getNamespace(), location.getPath(),
|
||||
entry.getKey().replace("=","_").replace(",","_"))
|
||||
);
|
||||
|
||||
IUnbakedModel model = ForgeVariantHelper.prepareInjectedModel((ModelLoader)bakery, modelLocation, var.getModel(), var.getSmooth(), var.getGui3d(), var.getTextures(), var.getOnlyPartsVariant(), var.getCustomData());
|
||||
|
||||
modelConsumer.accept(modelLocation, model);
|
||||
}
|
||||
|
||||
mcVars.add(new ForgeVariant(modelLocation, var.getState().orElse(ModelRotation.X0_Y0), uvLock, weight));
|
||||
}
|
||||
variants.put(entry.getKey(), new VariantList(mcVars));
|
||||
}
|
||||
|
||||
return new BlockModelDefinition(variants, null);
|
||||
|
||||
default: //Unknown version.. try loading it as normal.
|
||||
return vanillaGSON.fromJson(reader, BlockModelDefinition.class);
|
||||
}
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static class Marker
|
||||
{
|
||||
public int forge_marker = -1;
|
||||
}
|
||||
|
||||
//This is here specifically so that we do not have a hard reference to ForgeBlockStateV1.Variant in this code
|
||||
public static class SubModel
|
||||
{
|
||||
private final IModelState state;
|
||||
private final boolean uvLock;
|
||||
private final boolean smooth;
|
||||
private final boolean gui3d;
|
||||
private final ImmutableMap<String, String> textures;
|
||||
@Nullable
|
||||
private final ResourceLocation model;
|
||||
private final ImmutableMap<String, String> customData;
|
||||
|
||||
public SubModel(IModelState state, boolean uvLock, boolean smooth, boolean gui3d, ImmutableMap<String, String> textures, @Nullable ResourceLocation model, ImmutableMap<String, String> customData)
|
||||
{
|
||||
this.state = state;
|
||||
this.uvLock = uvLock;
|
||||
this.smooth = smooth;
|
||||
this.gui3d = gui3d;
|
||||
this.textures = textures;
|
||||
this.model = model;
|
||||
this.customData = customData;
|
||||
}
|
||||
|
||||
public IModelState getState() { return state; }
|
||||
public boolean isUVLock() { return uvLock; }
|
||||
public ImmutableMap<String, String> getTextures() { return textures; }
|
||||
@Nullable
|
||||
public ResourceLocation getModelLocation() { return model; }
|
||||
public ImmutableMap<String, String> getCustomData() { return customData; }
|
||||
}
|
||||
|
||||
private static class ForgeVariant extends Variant
|
||||
{
|
||||
private final IModelState state;
|
||||
|
||||
ForgeVariant(ResourceLocation model, IModelState state, boolean uvLock, int weight)
|
||||
{
|
||||
super(model, state instanceof ModelRotation ? (ModelRotation)state : ModelRotation.X0_Y0, uvLock, weight);
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IModelState getState()
|
||||
{
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Forge" + super.toString();
|
||||
}
|
||||
}
|
||||
|
||||
private static class ForgeVariantHelper
|
||||
{
|
||||
public static IUnbakedModel prepareInjectedModel(ModelLoader bakery, ResourceLocation blockstateLocation, @Nullable ResourceLocation modelLocation, Optional<Boolean> smooth, Optional<Boolean> gui3d, ImmutableMap<String, String> textures, ImmutableMap<String, SubModel> parts, ImmutableMap<String, String> customData)
|
||||
{
|
||||
int size = parts.size();
|
||||
|
||||
IUnbakedModel base = null;
|
||||
if (modelLocation != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
base = ModelLoaderRegistry.getModel(modelLocation);
|
||||
|
||||
if (base != null)
|
||||
{
|
||||
base = base.process(customData);
|
||||
base = base.retexture(textures);
|
||||
base = smooth.map(base::smoothLighting).orElse(base);
|
||||
base = gui3d.map(base::gui3d).orElse(base);
|
||||
|
||||
if (size <= 0)
|
||||
return base;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LOGGER.error("Error processing base model for forge blockstates pseudo-model: '" + blockstateLocation, e);
|
||||
}
|
||||
}
|
||||
|
||||
ImmutableMap.Builder<String, Pair<IUnbakedModel, IModelState>> models = ImmutableMap.builder();
|
||||
for (Entry<String, SubModel> entry : parts.entrySet())
|
||||
{
|
||||
SubModel part = entry.getValue();
|
||||
|
||||
final ResourceLocation location = part.getModelLocation();
|
||||
final IUnbakedModel model;
|
||||
if (location == null)
|
||||
{
|
||||
LOGGER.error("model not found for variant {} for blockstate {}", entry.getKey(), blockstateLocation);
|
||||
model = ModelLoaderRegistry.getMissingModel(blockstateLocation, new Throwable());
|
||||
}
|
||||
else
|
||||
{
|
||||
model = ModelLoaderRegistry.getModelOrLogError(location, "Unable to load block sub-model '" + entry.getKey() + "': '" + location + "'");
|
||||
}
|
||||
|
||||
IUnbakedModel base1 = model;
|
||||
base1 = base1.process(part.getCustomData());
|
||||
base1 = base1.retexture(part.getTextures());
|
||||
base1 = Optional.of(part.smooth).map(base1::smoothLighting).orElse(base1);
|
||||
base1 = Optional.of(part.gui3d).map(base1::gui3d).orElse(base1);
|
||||
models.put(entry.getKey(), Pair.of(base1, part.getState()));
|
||||
}
|
||||
|
||||
return new MultiModel(modelLocation, base, models.build());
|
||||
}
|
||||
}
|
||||
}
|
||||
+14
-21
@@ -19,32 +19,25 @@
|
||||
|
||||
package net.minecraftforge.client.model;
|
||||
|
||||
import net.minecraft.client.renderer.texture.ISprite;
|
||||
import net.minecraftforge.common.model.IModelState;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* Adapter from {@link IModelState} to the vanilla transform description class {@link ISprite}.
|
||||
* For use when loading a custom model for use in entity/tileentity renderers, or other situations in which the main atlas is not wanted.
|
||||
*/
|
||||
public class BasicState implements ISprite
|
||||
/*
|
||||
public class DummyAtlasSprite extends TextureAtlasSprite
|
||||
{
|
||||
private final IModelState defaultState;
|
||||
private final boolean uvLock;
|
||||
public static final TextureAtlasSprite INSTANCE = new DummyAtlasSprite();
|
||||
public static final Function<ResourceLocation, TextureAtlasSprite> GETTER = t -> INSTANCE;
|
||||
|
||||
public BasicState(IModelState defaultState, boolean uvLock)
|
||||
private DummyAtlasSprite()
|
||||
{
|
||||
this.defaultState = defaultState;
|
||||
this.uvLock = uvLock;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IModelState getState()
|
||||
{
|
||||
return defaultState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUvLock()
|
||||
{
|
||||
return uvLock;
|
||||
super(new ResourceLocation("forge", "dummy"), 1, 1);
|
||||
// Set the min/max coords to 0..1 range, to use the full texture.
|
||||
func_217789_a(0, 0, 1, 1);
|
||||
}
|
||||
}
|
||||
*/
|
||||
@@ -26,24 +26,24 @@ import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.Matrix4f;
|
||||
import net.minecraft.client.renderer.Quaternion;
|
||||
import net.minecraft.client.renderer.TransformationMatrix;
|
||||
import net.minecraft.client.renderer.Vector3f;
|
||||
import net.minecraft.client.renderer.model.*;
|
||||
import net.minecraft.client.renderer.texture.ISprite;
|
||||
import net.minecraft.client.renderer.texture.AtlasTexture;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormat;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.common.ForgeConfig;
|
||||
import net.minecraftforge.common.ForgeMod;
|
||||
import net.minecraftforge.common.model.IModelState;
|
||||
import net.minecraftforge.common.model.TRSRTransformation;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import net.minecraftforge.common.model.TransformationHelper;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.vecmath.Matrix4f;
|
||||
import javax.vecmath.Quat4f;
|
||||
import javax.vecmath.Vector3f;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@@ -53,18 +53,21 @@ import java.util.Set;
|
||||
final class FancyMissingModel implements IUnbakedModel
|
||||
{
|
||||
private static final ResourceLocation font = new ResourceLocation("minecraft", "textures/font/ascii.png");
|
||||
private static final ResourceLocation font2 = new ResourceLocation("minecraft", "font/ascii");
|
||||
private static final TRSRTransformation smallTransformation = TRSRTransformation.blockCenterToCorner(new TRSRTransformation(null, null, new Vector3f(.25f, .25f, .25f), null));
|
||||
private static final Material font2 = new Material(AtlasTexture.LOCATION_BLOCKS_TEXTURE, new ResourceLocation("minecraft", "font/ascii"));
|
||||
private static final TransformationMatrix smallTransformation = TransformationHelper.blockCenterToCorner(new TransformationMatrix(null, null, new Vector3f(.25f, .25f, .25f), null));
|
||||
private static final LoadingCache<VertexFormat, SimpleModelFontRenderer> fontCache = CacheBuilder.newBuilder().maximumSize(3).build(new CacheLoader<VertexFormat, SimpleModelFontRenderer>()
|
||||
{
|
||||
@Override
|
||||
public SimpleModelFontRenderer load(VertexFormat format) throws Exception
|
||||
{
|
||||
Matrix4f m = new Matrix4f();
|
||||
m.m20 = 1f / 128f;
|
||||
m.m01 = m.m12 = -m.m20;
|
||||
m.m33 = 1;
|
||||
m.setTranslation(new Vector3f(1, 1 + 1f / 0x100, 0));
|
||||
float [] mv = new float[16];
|
||||
mv[2*4+0] = 1f / 128f;
|
||||
mv[0*4+1] =mv[1*4+2] = -mv[2*4+0];
|
||||
mv[3*4+3] = 1;
|
||||
mv[0*4+3] = 1;
|
||||
mv[0*4+3] = 1 + 1f / 0x100;
|
||||
mv[0*4+3] = 0;
|
||||
Matrix4f m = new Matrix4f(mv);
|
||||
return new SimpleModelFontRenderer(
|
||||
Minecraft.getInstance().gameSettings,
|
||||
font,
|
||||
@@ -92,7 +95,7 @@ final class FancyMissingModel implements IUnbakedModel
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ResourceLocation> getTextures(Function<ResourceLocation, IUnbakedModel> modelGetter, Set<String> missingTextureErrors)
|
||||
public Collection<Material> func_225614_a_(Function<ResourceLocation, IUnbakedModel> p_225614_1_, Set<com.mojang.datafixers.util.Pair<String, String>> p_225614_2_)
|
||||
{
|
||||
return ImmutableList.of(font2);
|
||||
}
|
||||
@@ -105,12 +108,12 @@ final class FancyMissingModel implements IUnbakedModel
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public IBakedModel bake(ModelBakery bakery, Function<ResourceLocation, TextureAtlasSprite> spriteGetter, ISprite sprite, VertexFormat format)
|
||||
public IBakedModel func_225613_a_(ModelBakery bakery, Function<Material, TextureAtlasSprite> spriteGetter, IModelTransform sprite, ResourceLocation modelLocation)
|
||||
{
|
||||
IBakedModel bigMissing = missingModel.bake(bakery, spriteGetter, sprite, format);
|
||||
ModelStateComposition smallState = new ModelStateComposition(sprite.getState(), smallTransformation);
|
||||
IBakedModel smallMissing = missingModel.bake(bakery, spriteGetter, smallState, format);
|
||||
return new BakedModel(bigMissing, smallMissing, fontCache.getUnchecked(format), message, spriteGetter.apply(font2));
|
||||
IBakedModel bigMissing = missingModel.func_225613_a_(bakery, spriteGetter, sprite, modelLocation);
|
||||
ModelTransformComposition smallState = new ModelTransformComposition(sprite, new SimpleModelTransform(smallTransformation));
|
||||
IBakedModel smallMissing = missingModel.func_225613_a_(bakery, spriteGetter, smallState, modelLocation);
|
||||
return new BakedModel(bigMissing, smallMissing, fontCache.getUnchecked(DefaultVertexFormats.BLOCK), message, spriteGetter.apply(font2));
|
||||
}
|
||||
|
||||
static final class BakedModel implements IBakedModel
|
||||
@@ -188,9 +191,15 @@ final class FancyMissingModel implements IUnbakedModel
|
||||
public ItemOverrideList getOverrides() { return ItemOverrideList.EMPTY; }
|
||||
|
||||
@Override
|
||||
public Pair<? extends IBakedModel, Matrix4f> handlePerspective(ItemCameraTransforms.TransformType cameraTransformType)
|
||||
public boolean doesHandlePerspectives()
|
||||
{
|
||||
TRSRTransformation transform = TRSRTransformation.identity();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBakedModel handlePerspective(ItemCameraTransforms.TransformType cameraTransformType, MatrixStack mat)
|
||||
{
|
||||
TransformationMatrix transform = TransformationMatrix.func_227983_a_();
|
||||
boolean big = true;
|
||||
switch (cameraTransformType)
|
||||
{
|
||||
@@ -200,11 +209,11 @@ final class FancyMissingModel implements IUnbakedModel
|
||||
case THIRD_PERSON_RIGHT_HAND:
|
||||
break;
|
||||
case FIRST_PERSON_LEFT_HAND:
|
||||
transform = new TRSRTransformation(new Vector3f(-0.62f, 0.5f, -.5f), new Quat4f(1, -1, -1, 1), null, null);
|
||||
transform = new TransformationMatrix(new Vector3f(-0.62f, 0.5f, -.5f), new Quaternion(1, -1, -1, 1), null, null);
|
||||
big = false;
|
||||
break;
|
||||
case FIRST_PERSON_RIGHT_HAND:
|
||||
transform = new TRSRTransformation(new Vector3f(-0.5f, 0.5f, -.5f), new Quat4f(1, 1, 1, 1), null, null);
|
||||
transform = new TransformationMatrix(new Vector3f(-0.5f, 0.5f, -.5f), new Quaternion(1, 1, 1, 1), null, null);
|
||||
big = false;
|
||||
break;
|
||||
case HEAD:
|
||||
@@ -212,26 +221,27 @@ final class FancyMissingModel implements IUnbakedModel
|
||||
case GUI:
|
||||
if (ForgeConfig.CLIENT.zoomInMissingModelTextInGui.get())
|
||||
{
|
||||
transform = new TRSRTransformation(null, new Quat4f(1, 1, 1, 1), new Vector3f(4, 4, 4), null);
|
||||
transform = new TransformationMatrix(null, new Quaternion(1, 1, 1, 1), new Vector3f(4, 4, 4), null);
|
||||
big = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
transform = new TRSRTransformation(null, new Quat4f(1, 1, 1, 1), null, null);
|
||||
transform = new TransformationMatrix(null, new Quaternion(1, 1, 1, 1), null, null);
|
||||
big = true;
|
||||
}
|
||||
break;
|
||||
case FIXED:
|
||||
transform = new TRSRTransformation(null, new Quat4f(-1, -1, 1, 1), null, null);
|
||||
transform = new TransformationMatrix(null, new Quaternion(-1, -1, 1, 1), null, null);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
mat.func_227866_c_().func_227870_a_().func_226595_a_(transform.func_227988_c_());
|
||||
if (big != this.big)
|
||||
{
|
||||
return Pair.of(otherModel, transform.getMatrixVec());
|
||||
return otherModel;
|
||||
}
|
||||
return Pair.of(this, transform.getMatrixVec());
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,978 +0,0 @@
|
||||
/*
|
||||
* Minecraft Forge
|
||||
* Copyright (c) 2016-2019.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation version 2.1
|
||||
* of the License.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package net.minecraftforge.client.model;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.vecmath.AxisAngle4d;
|
||||
import javax.vecmath.Matrix4f;
|
||||
import javax.vecmath.Quat4f;
|
||||
import javax.vecmath.Vector3f;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import net.minecraft.client.renderer.model.ItemCameraTransforms.TransformType;
|
||||
import net.minecraft.client.renderer.model.ModelRotation;
|
||||
import net.minecraft.util.JSONUtils;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.client.model.BlockStateLoader.Marker;
|
||||
import net.minecraftforge.client.model.BlockStateLoader.SubModel;
|
||||
import net.minecraftforge.common.model.IModelState;
|
||||
import net.minecraftforge.common.model.TRSRTransformation;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.LinkedHashMultimap;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonDeserializer;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParseException;
|
||||
|
||||
public class ForgeBlockStateV1 extends Marker
|
||||
{
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
ForgeBlockStateV1.Variant defaults;
|
||||
Multimap<String, ForgeBlockStateV1.Variant> variants = LinkedHashMultimap.create();
|
||||
|
||||
public static class Deserializer implements JsonDeserializer<ForgeBlockStateV1>
|
||||
{
|
||||
static ForgeBlockStateV1.Deserializer INSTANCE = new Deserializer();
|
||||
@Override
|
||||
public ForgeBlockStateV1 deserialize(JsonElement element, Type typeOfT, JsonDeserializationContext context) throws JsonParseException
|
||||
{
|
||||
JsonObject json = element.getAsJsonObject();
|
||||
ForgeBlockStateV1 ret = new ForgeBlockStateV1();
|
||||
ret.forge_marker = JSONUtils.getInt(json, "forge_marker");
|
||||
|
||||
if (json.has("defaults")) // Load defaults Variant.
|
||||
{
|
||||
ret.defaults = context.deserialize(json.get("defaults"), ForgeBlockStateV1.Variant.class);
|
||||
|
||||
if (ret.defaults.simpleSubmodels.size() > 0)
|
||||
throw new RuntimeException("\"defaults\" variant cannot contain a simple \"submodel\" definition.");
|
||||
}
|
||||
|
||||
Map<String, Map<String, ForgeBlockStateV1.Variant>> condensed = Maps.newLinkedHashMap(); // map(property name -> map(property value -> variant))
|
||||
Multimap<String, ForgeBlockStateV1.Variant> specified = LinkedHashMultimap.create(); // Multimap containing all the states specified with "property=value".
|
||||
|
||||
for (Entry<String, JsonElement> e : JSONUtils.getJsonObject(json, "variants").entrySet())
|
||||
{
|
||||
if (e.getValue().isJsonArray())
|
||||
{
|
||||
// array of fully-defined variants
|
||||
for (JsonElement a : e.getValue().getAsJsonArray())
|
||||
{
|
||||
Variant.Deserializer.INSTANCE.simpleSubmodelKey = e.getKey();
|
||||
specified.put(e.getKey(), context.deserialize(a, Variant.class));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
JsonObject obj = e.getValue().getAsJsonObject();
|
||||
if(obj.entrySet().iterator().next().getValue().isJsonObject())
|
||||
{
|
||||
// first value is a json object, so we know it's not a fully-defined variant
|
||||
Map<String, ForgeBlockStateV1.Variant> subs = Maps.newLinkedHashMap();
|
||||
condensed.put(e.getKey(), subs);
|
||||
for (Entry<String, JsonElement> se : e.getValue().getAsJsonObject().entrySet())
|
||||
{
|
||||
Variant.Deserializer.INSTANCE.simpleSubmodelKey = e.getKey() + "=" + se.getKey();
|
||||
subs.put(se.getKey(), context.deserialize(se.getValue(), Variant.class));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// fully-defined variant
|
||||
Variant.Deserializer.INSTANCE.simpleSubmodelKey = e.getKey();
|
||||
specified.put(e.getKey(), context.deserialize(e.getValue(), Variant.class));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Multimap<String, ForgeBlockStateV1.Variant> permutations = getPermutations(condensed); // Get permutations of Forge-style states.
|
||||
|
||||
for (Entry<String, Collection<ForgeBlockStateV1.Variant>> e : specified.asMap().entrySet())
|
||||
{ // Make fully-specified variants override Forge variant permutations, inheriting the permutations' values.
|
||||
Collection<ForgeBlockStateV1.Variant> baseVars = permutations.get(e.getKey());
|
||||
List<ForgeBlockStateV1.Variant> addVars = Lists.newArrayList();
|
||||
|
||||
for (ForgeBlockStateV1.Variant specVar : e.getValue())
|
||||
{
|
||||
if (!baseVars.isEmpty())
|
||||
{
|
||||
for (ForgeBlockStateV1.Variant baseVar : baseVars)
|
||||
addVars.add(new Variant(specVar).sync(baseVar));
|
||||
}
|
||||
else
|
||||
addVars.add(specVar);
|
||||
}
|
||||
|
||||
baseVars.clear();
|
||||
baseVars.addAll(addVars);
|
||||
}
|
||||
|
||||
for (Entry<String, ForgeBlockStateV1.Variant> e : permutations.entries()) // Create the output map(state -> Variant).
|
||||
{
|
||||
ForgeBlockStateV1.Variant v = e.getValue();
|
||||
|
||||
if (ret.defaults != null)
|
||||
{
|
||||
v.sync(ret.defaults); // Sync defaults into all permutation variants
|
||||
|
||||
for (Entry<String, Object> partKey : v.simpleSubmodels.entrySet())
|
||||
{ // Sync variant values (including defaults) into simple submodel declarations.
|
||||
if (partKey.getValue() == null)
|
||||
continue;
|
||||
|
||||
if (!v.submodels.containsKey(partKey.getKey()))
|
||||
throw new RuntimeException("This should never happen! Simple submodel is not contained in the submodel map!");
|
||||
List<ForgeBlockStateV1.Variant> partList = v.submodels.get(partKey.getKey());
|
||||
if (partList.size() > 1)
|
||||
throw new RuntimeException("This should never happen! Simple submodel has multiple variants!");
|
||||
|
||||
ForgeBlockStateV1.Variant part = partList.get(0);
|
||||
// Must keep old rotation for the part, because the base variant's rotation is applied to the parts already.
|
||||
Optional<IModelState> state = part.state;
|
||||
part.sync(v);
|
||||
part.simpleSubmodels.clear();
|
||||
part.state = state;
|
||||
}
|
||||
}
|
||||
|
||||
v.submodels.values().removeIf(Objects::isNull);
|
||||
|
||||
if (v.textures != null)
|
||||
{
|
||||
for (Entry<String, String> tex : v.textures.entrySet())
|
||||
{
|
||||
if (tex.getValue() != null && tex.getValue().charAt(0) == '#')
|
||||
{
|
||||
String value = v.textures.get(tex.getValue().substring(1));
|
||||
if (value == null)
|
||||
{
|
||||
LOGGER.fatal("Could not resolve texture name \"{}\" for permutation \"{}\"", tex.getValue(), e.getKey());
|
||||
for (Entry<String, String> t: v.textures.entrySet())
|
||||
LOGGER.fatal("{}={}", t.getKey(), t.getValue());
|
||||
throw new JsonParseException("Could not resolve texture name \"" + tex.getValue() + "\" for permutation \"" + e.getKey() + "\"");
|
||||
}
|
||||
v.textures.put(tex.getKey(), value);
|
||||
}
|
||||
}
|
||||
|
||||
for (List<ForgeBlockStateV1.Variant> part : v.submodels.values()) // Sync base variant's textures (including defaults) into all submodels.
|
||||
{
|
||||
for (ForgeBlockStateV1.Variant partVar : part)
|
||||
{
|
||||
for (Entry<String, String> texEntry : v.textures.entrySet())
|
||||
{
|
||||
if (!partVar.textures.containsKey(texEntry.getKey()))
|
||||
partVar.textures.put(texEntry.getKey(), texEntry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!v.submodels.isEmpty())
|
||||
ret.variants.putAll(e.getKey(), getSubmodelPermutations(v, v.submodels)); // Do permutations of submodel variants.
|
||||
else
|
||||
ret.variants.put(e.getKey(), v);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
private Multimap<String, ForgeBlockStateV1.Variant> getPermutations(List<String> sorted, Map<String, Map<String, ForgeBlockStateV1.Variant>> base, int depth, String prefix, Multimap<String, ForgeBlockStateV1.Variant> ret, @Nullable ForgeBlockStateV1.Variant parent)
|
||||
{
|
||||
if (depth == sorted.size())
|
||||
{
|
||||
if(parent != null)
|
||||
ret.put(prefix, parent);
|
||||
return ret;
|
||||
}
|
||||
|
||||
String name = sorted.get(depth);
|
||||
for (Entry<String, ForgeBlockStateV1.Variant> e : base.get(name).entrySet())
|
||||
{
|
||||
ForgeBlockStateV1.Variant newHead = parent == null ? new Variant(e.getValue()) : new Variant(parent).sync(e.getValue());
|
||||
|
||||
getPermutations(sorted, base, depth + 1, prefix + (depth == 0 ? "" : ",") + name + "=" + e.getKey(), ret, newHead);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
private Multimap<String, ForgeBlockStateV1.Variant> getPermutations(Map<String, Map<String, ForgeBlockStateV1.Variant>> base)
|
||||
{
|
||||
List<String> sorted = Lists.newArrayList(base.keySet());
|
||||
Collections.sort(sorted); // Sort to get consistent results.
|
||||
return getPermutations(sorted, base, 0, "", LinkedHashMultimap.create(), null);
|
||||
}
|
||||
|
||||
private List<ForgeBlockStateV1.Variant> getSubmodelPermutations(ForgeBlockStateV1.Variant baseVar, List<String> sorted, Map<String, List<ForgeBlockStateV1.Variant>> map, int depth, Map<String, ForgeBlockStateV1.Variant> parts, List<ForgeBlockStateV1.Variant> ret)
|
||||
{
|
||||
if (depth >= sorted.size())
|
||||
{
|
||||
ForgeBlockStateV1.Variant add = new Variant(baseVar); // Create a duplicate variant object so modifying it doesn't modify baseVar.
|
||||
for (Entry<String, ForgeBlockStateV1.Variant> part : parts.entrySet()) // Put all the parts with single variants for this permutation.
|
||||
add.submodels.put(part.getKey(), Collections.singletonList(part.getValue()));
|
||||
ret.add(add);
|
||||
return ret;
|
||||
}
|
||||
|
||||
String name = sorted.get(depth);
|
||||
List<ForgeBlockStateV1.Variant> vars = map.get(sorted.get(depth));
|
||||
|
||||
if (vars != null)
|
||||
{
|
||||
for (ForgeBlockStateV1.Variant v : vars)
|
||||
{
|
||||
if (v != null)
|
||||
{ // We put this part variant in the permutation's map to add further in recursion, and then remove it afterward just in case.
|
||||
parts.put(name, v);
|
||||
getSubmodelPermutations(baseVar, sorted, map, depth + 1, parts, ret);
|
||||
parts.remove(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
getSubmodelPermutations(baseVar, sorted, map, depth + 1, parts, ret);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
private List<ForgeBlockStateV1.Variant> getSubmodelPermutations(ForgeBlockStateV1.Variant baseVar, Map<String, List<ForgeBlockStateV1.Variant>> variants)
|
||||
{
|
||||
List<String> sorted = Lists.newArrayList(variants.keySet());
|
||||
Collections.sort(sorted); // Sort to get consistent results.
|
||||
return getSubmodelPermutations(baseVar, sorted, variants, 0, new LinkedHashMap<>(), new ArrayList<>());
|
||||
}
|
||||
}
|
||||
|
||||
public static class Variant
|
||||
{
|
||||
public static final Object SET_VALUE = new Object();
|
||||
|
||||
@Nullable
|
||||
private ResourceLocation model = null;
|
||||
private boolean modelSet = false;
|
||||
private Optional<IModelState> state = Optional.empty();
|
||||
private Optional<Boolean> uvLock = Optional.empty();
|
||||
private Optional<Boolean> smooth = Optional.empty();
|
||||
private Optional<Boolean> gui3d = Optional.empty();
|
||||
private Optional<Integer> weight = Optional.empty();
|
||||
private Map<String, String> textures = Maps.newHashMap();
|
||||
private Map<String, List<ForgeBlockStateV1.Variant>> submodels = Maps.newHashMap();
|
||||
private Map<String, Object> simpleSubmodels = Maps.newHashMap(); // Makeshift Set to allow us to "remove" (replace value with null) singleParts when needed.
|
||||
private Map<String, String> customData = Maps.newHashMap();
|
||||
|
||||
private Variant(){}
|
||||
/**
|
||||
* Clone a variant.
|
||||
* @param other Variant to clone.
|
||||
*/
|
||||
private Variant(ForgeBlockStateV1.Variant other)
|
||||
{
|
||||
this.model = other.model;
|
||||
this.modelSet = other.modelSet;
|
||||
this.state = other.state;
|
||||
this.uvLock = other.uvLock;
|
||||
this.smooth = other.smooth;
|
||||
this.gui3d = other.gui3d;
|
||||
this.weight = other.weight;
|
||||
this.textures.putAll(other.textures);
|
||||
this.mergeModelPartVariants(this.submodels, other.submodels);
|
||||
this.simpleSubmodels.putAll(other.simpleSubmodels);
|
||||
this.customData.putAll(other.customData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets values in this variant to the input's values only if they haven't been set already. Essentially inherits values from o.
|
||||
*/
|
||||
ForgeBlockStateV1.Variant sync(ForgeBlockStateV1.Variant parent)
|
||||
{
|
||||
if (!this.modelSet)
|
||||
{
|
||||
this.model = parent.model;
|
||||
this.modelSet = parent.modelSet;
|
||||
}
|
||||
if (!this.state.isPresent()) this.state = parent.state;
|
||||
if (!this.uvLock.isPresent()) this.uvLock = parent.uvLock;
|
||||
if (!this.smooth.isPresent()) this.smooth = parent.smooth;
|
||||
if (!this.gui3d.isPresent()) this.gui3d = parent.gui3d;
|
||||
if (!this.weight.isPresent()) this.weight = parent.weight;
|
||||
|
||||
for (Entry<String, String> e : parent.textures.entrySet())
|
||||
{
|
||||
if (!this.textures.containsKey(e.getKey()))
|
||||
this.textures.put(e.getKey(), e.getValue());
|
||||
}
|
||||
|
||||
mergeModelPartVariants(this.submodels, parent.submodels);
|
||||
|
||||
for (Entry<String, Object> e : parent.simpleSubmodels.entrySet())
|
||||
{
|
||||
if (!this.simpleSubmodels.containsKey(e.getKey()))
|
||||
this.simpleSubmodels.put(e.getKey(), e.getValue());
|
||||
}
|
||||
|
||||
for (Entry<String, String> e : parent.customData.entrySet())
|
||||
{
|
||||
if (!this.customData.containsKey(e.getKey()))
|
||||
this.customData.put(e.getKey(), e.getValue());
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inherits model parts from a parent, creating deep clones of all Variants.
|
||||
*/
|
||||
Map<String, List<ForgeBlockStateV1.Variant>> mergeModelPartVariants(Map<String, List<ForgeBlockStateV1.Variant>> output, Map<String, List<ForgeBlockStateV1.Variant>> input)
|
||||
{
|
||||
for (Entry<String, List<ForgeBlockStateV1.Variant>> e : input.entrySet())
|
||||
{
|
||||
String key = e.getKey();
|
||||
if (!output.containsKey(key))
|
||||
{
|
||||
List<ForgeBlockStateV1.Variant> variants = e.getValue();
|
||||
|
||||
if (variants != null)
|
||||
{
|
||||
List<ForgeBlockStateV1.Variant> newVariants = Lists.newArrayListWithCapacity(variants.size());
|
||||
|
||||
for (ForgeBlockStateV1.Variant v : variants)
|
||||
newVariants.add(new Variant(v));
|
||||
|
||||
output.put(key, newVariants);
|
||||
}
|
||||
else
|
||||
output.put(key, variants);
|
||||
}
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
boolean isVanillaCompatible()
|
||||
{
|
||||
return model != null && submodels.isEmpty() && textures.isEmpty() && customData.isEmpty() && !smooth.isPresent() && !gui3d.isPresent() && state.orElse(ModelRotation.X0_Y0) instanceof ModelRotation;
|
||||
}
|
||||
|
||||
protected SubModel asGenericSubModel()
|
||||
{
|
||||
return new SubModel(state.orElse(TRSRTransformation.identity()), uvLock.orElse(false), smooth.orElse(true), gui3d.orElse(true), getTextures(), model, getCustomData());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a list containing the single variant of each part.
|
||||
* Will throw an error if this Variant has multiple variants for a submodel.
|
||||
*/
|
||||
public ImmutableMap<String, SubModel> getOnlyPartsVariant()
|
||||
{
|
||||
if (submodels.size() > 0)
|
||||
{
|
||||
ImmutableMap.Builder<String, SubModel> builder = ImmutableMap.builder();
|
||||
|
||||
for (Entry<String, List<ForgeBlockStateV1.Variant>> entry : submodels.entrySet())
|
||||
{
|
||||
List<ForgeBlockStateV1.Variant> part = entry.getValue();
|
||||
|
||||
if (part != null)
|
||||
{
|
||||
if (part.size() == 1)
|
||||
builder.put(entry.getKey(), part.get(0).asGenericSubModel());
|
||||
else
|
||||
throw new RuntimeException("Something attempted to get the list of submodels "
|
||||
+ "for a variant with model \"" + model + "\", when this variant "
|
||||
+ "contains multiple variants for submodel " + entry.getKey());
|
||||
}
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
else {
|
||||
return ImmutableMap.of();
|
||||
}
|
||||
}
|
||||
|
||||
public Optional<Boolean> getSmooth()
|
||||
{
|
||||
return smooth;
|
||||
}
|
||||
|
||||
public Optional<Boolean> getGui3d()
|
||||
{
|
||||
return gui3d;
|
||||
}
|
||||
|
||||
public static class Deserializer implements JsonDeserializer<ForgeBlockStateV1.Variant>
|
||||
{
|
||||
static Variant.Deserializer INSTANCE = new Deserializer();
|
||||
|
||||
/** Used <i>once</i> (then set null) for the key to put a simple submodel declaration under in the submodel map. */
|
||||
public String simpleSubmodelKey = null;
|
||||
|
||||
protected ResourceLocation getBlockLocation(String location)
|
||||
{
|
||||
return new ResourceLocation(location); //Vanilla 1.14 removed automatic block prefixes. See https://github.com/MinecraftForge/MinecraftForge/issues/5892
|
||||
}
|
||||
|
||||
/** Throws an error if there are submodels in this submodel. */
|
||||
private void throwIfNestedSubmodels(ForgeBlockStateV1.Variant submodel)
|
||||
{
|
||||
if (submodel.submodels.size() > 0)
|
||||
throw new UnsupportedOperationException("Forge BlockStateLoader V1 does not support nested submodels.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ForgeBlockStateV1.Variant deserialize(JsonElement element, Type typeOfT, JsonDeserializationContext context) throws JsonParseException
|
||||
{
|
||||
ForgeBlockStateV1.Variant ret = new Variant();
|
||||
JsonObject json = element.getAsJsonObject();
|
||||
|
||||
if (json.has("model"))
|
||||
{ // Load base model location.
|
||||
if (json.get("model").isJsonNull())
|
||||
ret.model = null; // Allow overriding base model to remove it from a state.
|
||||
else
|
||||
ret.model = getBlockLocation(JSONUtils.getString(json, "model"));
|
||||
ret.modelSet = true;
|
||||
}
|
||||
|
||||
if (json.has("textures"))
|
||||
{ // Load textures map.
|
||||
for (Entry<String, JsonElement> e : json.get("textures").getAsJsonObject().entrySet())
|
||||
{
|
||||
if (e.getValue().isJsonNull())
|
||||
ret.textures.put(e.getKey(), ""); // We have to use "" because ImmutableMaps don't allow nulls -.-
|
||||
else
|
||||
ret.textures.put(e.getKey(), e.getValue().getAsString());
|
||||
}
|
||||
}
|
||||
|
||||
if (json.has("x") || json.has("y"))
|
||||
{ // Load rotation values.
|
||||
int x = JSONUtils.getInt(json, "x", 0);
|
||||
int y = JSONUtils.getInt(json, "y", 0);
|
||||
ret.state = Optional.ofNullable(ModelRotation.getModelRotation(x, y));
|
||||
if (!ret.state.isPresent())
|
||||
throw new JsonParseException("Invalid BlockModelRotation x: " + x + " y: " + y);
|
||||
}
|
||||
|
||||
if (json.has("transform"))
|
||||
{
|
||||
if (json.get("transform").isJsonPrimitive() && json.get("transform").getAsJsonPrimitive().isString())
|
||||
{
|
||||
String transform = json.get("transform").getAsString();
|
||||
ret.state = Transforms.get(transform);
|
||||
if (!ret.state.isPresent())
|
||||
{
|
||||
throw new JsonParseException("transform: unknown default string: " + transform);
|
||||
}
|
||||
}
|
||||
else if (!json.get("transform").isJsonObject())
|
||||
{
|
||||
try
|
||||
{
|
||||
TRSRTransformation base = context.deserialize(json.get("transform"), TRSRTransformation.class);
|
||||
ret.state = Optional.of(TRSRTransformation.blockCenterToCorner(base));
|
||||
}
|
||||
catch (JsonParseException e)
|
||||
{
|
||||
throw new JsonParseException("transform: expected a string, object or valid base transformation, got: " + json.get("transform"));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
JsonObject transform = json.get("transform").getAsJsonObject();
|
||||
EnumMap<TransformType, TRSRTransformation> transforms = Maps.newEnumMap(TransformType.class);
|
||||
if(transform.has("thirdperson"))
|
||||
{
|
||||
TRSRTransformation t = context.deserialize(transform.get("thirdperson"), TRSRTransformation.class);
|
||||
transform.remove("thirdperson");
|
||||
transforms.put(TransformType.THIRD_PERSON_RIGHT_HAND, TRSRTransformation.blockCenterToCorner(t));
|
||||
}
|
||||
if(transform.has("thirdperson_righthand"))
|
||||
{
|
||||
TRSRTransformation t = context.deserialize(transform.get("thirdperson_righthand"), TRSRTransformation.class);
|
||||
transform.remove("thirdperson_righthand");
|
||||
transforms.put(TransformType.THIRD_PERSON_RIGHT_HAND, TRSRTransformation.blockCenterToCorner(t));
|
||||
}
|
||||
if(transform.has("thirdperson_lefthand"))
|
||||
{
|
||||
TRSRTransformation t = context.deserialize(transform.get("thirdperson_lefthand"), TRSRTransformation.class);
|
||||
transform.remove("thirdperson_lefthand");
|
||||
transforms.put(TransformType.THIRD_PERSON_LEFT_HAND, TRSRTransformation.blockCenterToCorner(t));
|
||||
}
|
||||
if(transform.has("firstperson"))
|
||||
{
|
||||
TRSRTransformation t = context.deserialize(transform.get("firstperson"), TRSRTransformation.class);
|
||||
transform.remove("firstperson");
|
||||
transforms.put(TransformType.FIRST_PERSON_RIGHT_HAND, TRSRTransformation.blockCenterToCorner(t));
|
||||
}
|
||||
if(transform.has("firstperson_righthand"))
|
||||
{
|
||||
TRSRTransformation t = context.deserialize(transform.get("firstperson_righthand"), TRSRTransformation.class);
|
||||
transform.remove("firstperson_righthand");
|
||||
transforms.put(TransformType.FIRST_PERSON_RIGHT_HAND, TRSRTransformation.blockCenterToCorner(t));
|
||||
}
|
||||
if(transform.has("firstperson_lefthand"))
|
||||
{
|
||||
TRSRTransformation t = context.deserialize(transform.get("firstperson_lefthand"), TRSRTransformation.class);
|
||||
transform.remove("firstperson_lefthand");
|
||||
transforms.put(TransformType.FIRST_PERSON_LEFT_HAND, TRSRTransformation.blockCenterToCorner(t));
|
||||
}
|
||||
if(transform.has("head"))
|
||||
{
|
||||
TRSRTransformation t = context.deserialize(transform.get("head"), TRSRTransformation.class);
|
||||
transform.remove("head");
|
||||
transforms.put(TransformType.HEAD, TRSRTransformation.blockCenterToCorner(t));
|
||||
}
|
||||
if(transform.has("gui"))
|
||||
{
|
||||
TRSRTransformation t = context.deserialize(transform.get("gui"), TRSRTransformation.class);
|
||||
transform.remove("gui");
|
||||
transforms.put(TransformType.GUI, TRSRTransformation.blockCenterToCorner(t));
|
||||
}
|
||||
if(transform.has("ground"))
|
||||
{
|
||||
TRSRTransformation t = context.deserialize(transform.get("ground"), TRSRTransformation.class);
|
||||
transform.remove("ground");
|
||||
transforms.put(TransformType.GROUND, TRSRTransformation.blockCenterToCorner(t));
|
||||
}
|
||||
if(transform.has("fixed"))
|
||||
{
|
||||
TRSRTransformation t = context.deserialize(transform.get("fixed"), TRSRTransformation.class);
|
||||
transform.remove("fixed");
|
||||
transforms.put(TransformType.FIXED, TRSRTransformation.blockCenterToCorner(t));
|
||||
}
|
||||
int k = transform.entrySet().size();
|
||||
if(transform.has("matrix")) k--;
|
||||
if(transform.has("translation")) k--;
|
||||
if(transform.has("rotation")) k--;
|
||||
if(transform.has("scale")) k--;
|
||||
if(transform.has("post-rotation")) k--;
|
||||
if(k > 0)
|
||||
{
|
||||
throw new JsonParseException("transform: allowed keys: 'thirdperson', 'firstperson', 'gui', 'head', 'matrix', 'translation', 'rotation', 'scale', 'post-rotation'");
|
||||
}
|
||||
TRSRTransformation base = TRSRTransformation.identity();
|
||||
if(!transform.entrySet().isEmpty())
|
||||
{
|
||||
base = context.deserialize(transform, TRSRTransformation.class);
|
||||
base = TRSRTransformation.blockCenterToCorner(base);
|
||||
}
|
||||
IModelState state;
|
||||
if(transforms.isEmpty())
|
||||
{
|
||||
state = base;
|
||||
}
|
||||
else
|
||||
{
|
||||
state = new SimpleModelState(Maps.immutableEnumMap(transforms), Optional.of(base));
|
||||
}
|
||||
ret.state = Optional.of(state);
|
||||
}
|
||||
}
|
||||
|
||||
if (json.has("uvlock"))
|
||||
{ // Load uvlock.
|
||||
ret.uvLock = Optional.of(JSONUtils.getBoolean(json, "uvlock"));
|
||||
}
|
||||
|
||||
if (json.has("smooth_lighting"))
|
||||
{
|
||||
ret.smooth = Optional.of(JSONUtils.getBoolean(json, "smooth_lighting"));
|
||||
}
|
||||
|
||||
if (json.has("gui3d"))
|
||||
{
|
||||
ret.gui3d = Optional.of(JSONUtils.getBoolean(json, "gui3d"));
|
||||
}
|
||||
|
||||
if (json.has("weight"))
|
||||
{ // Load weight.
|
||||
ret.weight = Optional.of(JSONUtils.getInt(json, "weight"));
|
||||
}
|
||||
|
||||
if (json.has("submodel"))
|
||||
{ // Load submodels.
|
||||
JsonElement submodels = json.get("submodel");
|
||||
|
||||
if (submodels.isJsonPrimitive())
|
||||
{ // Load a simple submodel declaration.
|
||||
if (simpleSubmodelKey == null)
|
||||
throw new RuntimeException("Attempted to use a simple submodel declaration outside a valid state variant declaration.");
|
||||
String key = simpleSubmodelKey;
|
||||
simpleSubmodelKey = null;
|
||||
|
||||
ret.model = getBlockLocation(submodels.getAsString());
|
||||
ret.modelSet = true;
|
||||
ForgeBlockStateV1.Variant dummyVar = new Variant(); // Create a dummy Variant to use as the owner of the simple submodel.
|
||||
dummyVar.submodels.put(key, Collections.singletonList(ret));
|
||||
dummyVar.simpleSubmodels = Collections.singletonMap(key, Variant.SET_VALUE);
|
||||
return dummyVar;
|
||||
}
|
||||
else
|
||||
{ // Load full submodel declarations.
|
||||
// Clear the simple submodel key so that when deserializing submodels, the deserializer doesn't use the key.
|
||||
simpleSubmodelKey = null;
|
||||
|
||||
for (Entry<String, JsonElement> submodel : submodels.getAsJsonObject().entrySet())
|
||||
{
|
||||
JsonElement varEl = submodel.getValue();
|
||||
List<ForgeBlockStateV1.Variant> submodelVariants;
|
||||
|
||||
if (varEl.isJsonArray())
|
||||
{ // Multiple variants of the submodel.
|
||||
submodelVariants = Lists.newArrayList();
|
||||
for (JsonElement e : varEl.getAsJsonArray())
|
||||
submodelVariants.add(context.deserialize(e, Variant.class));
|
||||
}
|
||||
else if (varEl.isJsonNull())
|
||||
{
|
||||
submodelVariants = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
submodelVariants = Collections.singletonList(context.deserialize(varEl, Variant.class));
|
||||
}
|
||||
|
||||
if (submodelVariants != null) // Throw an error if there are submodels inside a submodel.
|
||||
for (ForgeBlockStateV1.Variant part : submodelVariants)
|
||||
throwIfNestedSubmodels(part);
|
||||
|
||||
ret.submodels.put(submodel.getKey(), submodelVariants);
|
||||
// Put null to remove this submodel from the list of simple submodels when something inherits this submodel.
|
||||
ret.simpleSubmodels.put(submodel.getKey(), null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (json.has("custom"))
|
||||
{
|
||||
for (Entry<String, JsonElement> e : json.get("custom").getAsJsonObject().entrySet())
|
||||
{
|
||||
if (e.getValue().isJsonNull())
|
||||
ret.customData.put(e.getKey(), null);
|
||||
else
|
||||
ret.customData.put(e.getKey(), e.getValue().toString());
|
||||
}
|
||||
}
|
||||
|
||||
simpleSubmodelKey = null;
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public ResourceLocation getModel() { return model; }
|
||||
public boolean isModelSet() { return modelSet; }
|
||||
public Optional<IModelState> getState() { return state; }
|
||||
public Optional<Boolean> getUvLock() { return uvLock; }
|
||||
public Optional<Integer> getWeight() { return weight; }
|
||||
public ImmutableMap<String, String> getTextures() { return ImmutableMap.copyOf(textures); }
|
||||
public ImmutableMap<String, List<ForgeBlockStateV1.Variant>> getSubmodels() { return ImmutableMap.copyOf(submodels); }
|
||||
public ImmutableMap<String, String> getCustomData() { return ImmutableMap.copyOf(customData); }
|
||||
}
|
||||
|
||||
public static class TRSRDeserializer implements JsonDeserializer<TRSRTransformation>
|
||||
{
|
||||
public static final TRSRDeserializer INSTANCE = new TRSRDeserializer();
|
||||
|
||||
@Override
|
||||
public TRSRTransformation deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException
|
||||
{
|
||||
if (json.isJsonPrimitive() && json.getAsJsonPrimitive().isString())
|
||||
{
|
||||
String transform = json.getAsString();
|
||||
if(transform.equals("identity"))
|
||||
{
|
||||
return TRSRTransformation.identity();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new JsonParseException("TRSR: unknown default string: " + transform);
|
||||
}
|
||||
}
|
||||
if (json.isJsonArray())
|
||||
{
|
||||
// direct matrix array
|
||||
return new TRSRTransformation(parseMatrix(json));
|
||||
}
|
||||
if (!json.isJsonObject()) throw new JsonParseException("TRSR: expected array or object, got: " + json);
|
||||
JsonObject obj = json.getAsJsonObject();
|
||||
TRSRTransformation ret;
|
||||
if (obj.has("matrix"))
|
||||
{
|
||||
// matrix as a sole key
|
||||
ret = new TRSRTransformation(parseMatrix(obj.get("matrix")));
|
||||
obj.remove("matrix");
|
||||
if (obj.entrySet().size() != 0)
|
||||
{
|
||||
throw new JsonParseException("TRSR: can't combine matrix and other keys");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
Vector3f translation = null;
|
||||
Quat4f leftRot = null;
|
||||
Vector3f scale = null;
|
||||
Quat4f rightRot = null;
|
||||
if (obj.has("translation"))
|
||||
{
|
||||
translation = new Vector3f(parseFloatArray(obj.get("translation"), 3, "Translation"));
|
||||
obj.remove("translation");
|
||||
}
|
||||
if (obj.has("rotation"))
|
||||
{
|
||||
leftRot = parseRotation(obj.get("rotation"));
|
||||
obj.remove("rotation");
|
||||
}
|
||||
if (obj.has("scale"))
|
||||
{
|
||||
if(!obj.get("scale").isJsonArray())
|
||||
{
|
||||
try
|
||||
{
|
||||
float s = obj.get("scale").getAsNumber().floatValue();
|
||||
scale = new Vector3f(s, s, s);
|
||||
}
|
||||
catch (ClassCastException ex)
|
||||
{
|
||||
throw new JsonParseException("TRSR scale: expected number or array, got: " + obj.get("scale"));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
scale = new Vector3f(parseFloatArray(obj.get("scale"), 3, "Scale"));
|
||||
}
|
||||
obj.remove("scale");
|
||||
}
|
||||
if (obj.has("post-rotation"))
|
||||
{
|
||||
rightRot = parseRotation(obj.get("post-rotation"));
|
||||
obj.remove("post-rotation");
|
||||
}
|
||||
if (!obj.entrySet().isEmpty()) throw new JsonParseException("TRSR: can either have single 'matrix' key, or a combination of 'translation', 'rotation', 'scale', 'post-rotation'");
|
||||
return new TRSRTransformation(translation, leftRot, scale, rightRot);
|
||||
}
|
||||
|
||||
public static Matrix4f parseMatrix(JsonElement e)
|
||||
{
|
||||
if (!e.isJsonArray()) throw new JsonParseException("Matrix: expected an array, got: " + e);
|
||||
JsonArray m = e.getAsJsonArray();
|
||||
if (m.size() != 3) throw new JsonParseException("Matrix: expected an array of length 3, got: " + m.size());
|
||||
Matrix4f ret = new Matrix4f();
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
if (!m.get(i).isJsonArray()) throw new JsonParseException("Matrix row: expected an array, got: " + m.get(i));
|
||||
JsonArray r = m.get(i).getAsJsonArray();
|
||||
if (r.size() != 4) throw new JsonParseException("Matrix row: expected an array of length 4, got: " + r.size());
|
||||
for (int j = 0; j < 4; j++)
|
||||
{
|
||||
try
|
||||
{
|
||||
ret.setElement(i, j, r.get(j).getAsNumber().floatValue());
|
||||
}
|
||||
catch (ClassCastException ex)
|
||||
{
|
||||
throw new JsonParseException("Matrix element: expected number, got: " + r.get(j));
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static float[] parseFloatArray(JsonElement e, int length, String prefix)
|
||||
{
|
||||
if (!e.isJsonArray()) throw new JsonParseException(prefix + ": expected an array, got: " + e);
|
||||
JsonArray t = e.getAsJsonArray();
|
||||
if (t.size() != length) throw new JsonParseException(prefix + ": expected an array of length " + length + ", got: " + t.size());
|
||||
float[] ret = new float[length];
|
||||
for (int i = 0; i < length; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
ret[i] = t.get(i).getAsNumber().floatValue();
|
||||
}
|
||||
catch (ClassCastException ex)
|
||||
{
|
||||
throw new JsonParseException(prefix + " element: expected number, got: " + t.get(i));
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static Quat4f parseAxisRotation(JsonElement e)
|
||||
{
|
||||
if (!e.isJsonObject()) throw new JsonParseException("Axis rotation: object expected, got: " + e);
|
||||
JsonObject obj = e.getAsJsonObject();
|
||||
if (obj.entrySet().size() != 1) throw new JsonParseException("Axis rotation: expected single axis object, got: " + e);
|
||||
Map.Entry<String, JsonElement> entry = obj.entrySet().iterator().next();
|
||||
Quat4f ret = new Quat4f();
|
||||
try
|
||||
{
|
||||
if (entry.getKey().equals("x"))
|
||||
{
|
||||
ret.set(new AxisAngle4d(1, 0, 0, Math.toRadians(entry.getValue().getAsNumber().floatValue())));
|
||||
}
|
||||
else if (entry.getKey().equals("y"))
|
||||
{
|
||||
ret.set(new AxisAngle4d(0, 1, 0, Math.toRadians(entry.getValue().getAsNumber().floatValue())));
|
||||
}
|
||||
else if (entry.getKey().equals("z"))
|
||||
{
|
||||
ret.set(new AxisAngle4d(0, 0, 1, Math.toRadians(entry.getValue().getAsNumber().floatValue())));
|
||||
}
|
||||
else throw new JsonParseException("Axis rotation: expected single axis key, got: " + entry.getKey());
|
||||
}
|
||||
catch(ClassCastException ex)
|
||||
{
|
||||
throw new JsonParseException("Axis rotation value: expected number, got: " + entry.getValue());
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static Quat4f parseRotation(JsonElement e)
|
||||
{
|
||||
if (e.isJsonArray())
|
||||
{
|
||||
if (e.getAsJsonArray().get(0).isJsonObject())
|
||||
{
|
||||
Quat4f ret = new Quat4f(0, 0, 0, 1);
|
||||
for (JsonElement a : e.getAsJsonArray())
|
||||
{
|
||||
ret.mul(parseAxisRotation(a));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
else if (e.isJsonArray())
|
||||
{
|
||||
JsonArray array = e.getAsJsonArray();
|
||||
if (array.size() == 3) //Vanilla rotation
|
||||
return TRSRTransformation.quatFromXYZDegrees(new Vector3f(parseFloatArray(e, 3, "Rotation")));
|
||||
else // quaternion
|
||||
return new Quat4f(parseFloatArray(e, 4, "Rotation"));
|
||||
}
|
||||
else throw new JsonParseException("Rotation: expected array or object, got: " + e);
|
||||
}
|
||||
else if (e.isJsonObject())
|
||||
{
|
||||
return parseAxisRotation(e);
|
||||
}
|
||||
else throw new JsonParseException("Rotation: expected array or object, got: " + e);
|
||||
}
|
||||
}
|
||||
|
||||
public static class Transforms
|
||||
{
|
||||
public static TRSRTransformation convert(float tx, float ty, float tz, float ax, float ay, float az, float s)
|
||||
{
|
||||
return convert(tx, ty, tz, ax, ay, az, s, s, s);
|
||||
}
|
||||
|
||||
public static TRSRTransformation convert(float tx, float ty, float tz, float ax, float ay, float az, float sx, float sy, float sz)
|
||||
{
|
||||
return TRSRTransformation.blockCenterToCorner(new TRSRTransformation(
|
||||
new Vector3f(tx / 16, ty / 16, tz / 16),
|
||||
TRSRTransformation.quatFromXYZDegrees(new Vector3f(ax, ay, az)),
|
||||
new Vector3f(sx, sy, sz),
|
||||
null
|
||||
));
|
||||
}
|
||||
|
||||
private static final TRSRTransformation flipX = new TRSRTransformation(null, null, new Vector3f(-1, 1, 1), null);
|
||||
|
||||
public static TRSRTransformation leftify(TRSRTransformation transform)
|
||||
{
|
||||
return TRSRTransformation.blockCenterToCorner(flipX.compose(TRSRTransformation.blockCornerToCenter(transform)).compose(flipX));
|
||||
}
|
||||
|
||||
public static Optional<IModelState> get(String name)
|
||||
{
|
||||
return Optional.ofNullable(transforms.get(name));
|
||||
}
|
||||
|
||||
// Note: these strings might change to a full-blown resource locations in the future, and move from here to some json somewhere
|
||||
// TODO: vanilla now includes from parent, deprecate?
|
||||
private static final ImmutableMap<String, IModelState> transforms;
|
||||
|
||||
static
|
||||
{
|
||||
ImmutableMap.Builder<String, IModelState> builder = ImmutableMap.builder();
|
||||
|
||||
builder.put("identity", TRSRTransformation.identity());
|
||||
|
||||
// block/block
|
||||
EnumMap<TransformType, TRSRTransformation> block = new EnumMap<>(TransformType.class);
|
||||
TRSRTransformation thirdPersonBlock = convert(0, 2.5f, 0, 75, 45, 0, 0.375f);
|
||||
block.put(TransformType.GUI, convert(0, 0, 0, 30, 225, 0, 0.625f));
|
||||
block.put(TransformType.GROUND, convert(0, 3, 0, 0, 0, 0, 0.25f));
|
||||
block.put(TransformType.FIXED, convert(0, 0, 0, 0, 0, 0, 0.5f));
|
||||
block.put(TransformType.THIRD_PERSON_RIGHT_HAND, thirdPersonBlock);
|
||||
block.put(TransformType.THIRD_PERSON_LEFT_HAND, leftify(thirdPersonBlock));
|
||||
block.put(TransformType.FIRST_PERSON_RIGHT_HAND, convert(0, 0, 0, 0, 45, 0, 0.4f));
|
||||
block.put(TransformType.FIRST_PERSON_LEFT_HAND, convert(0, 0, 0, 0, 225, 0, 0.4f));
|
||||
builder.put("forge:default-block", new SimpleModelState(ImmutableMap.copyOf(block)));
|
||||
|
||||
// item/generated
|
||||
EnumMap<TransformType, TRSRTransformation> item = new EnumMap<>(TransformType.class);
|
||||
TRSRTransformation thirdPersonItem = convert(0, 3, 1, 0, 0, 0, 0.55f);
|
||||
TRSRTransformation firstPersonItem = convert(1.13f, 3.2f, 1.13f, 0, -90, 25, 0.68f);
|
||||
item.put(TransformType.GROUND, convert(0, 2, 0, 0, 0, 0, 0.5f));
|
||||
item.put(TransformType.HEAD, convert(0, 13, 7, 0, 180, 0, 1));
|
||||
item.put(TransformType.THIRD_PERSON_RIGHT_HAND, thirdPersonItem);
|
||||
item.put(TransformType.THIRD_PERSON_LEFT_HAND, leftify(thirdPersonItem));
|
||||
item.put(TransformType.FIRST_PERSON_RIGHT_HAND, firstPersonItem);
|
||||
item.put(TransformType.FIRST_PERSON_LEFT_HAND, leftify(firstPersonItem));
|
||||
item.put(TransformType.FIXED, convert(0, 0, 0, 0, 180, 0, 1));
|
||||
builder.put("forge:default-item", new SimpleModelState(ImmutableMap.copyOf(item)));
|
||||
|
||||
// item/handheld
|
||||
EnumMap<TransformType, TRSRTransformation> tool = new EnumMap<>(TransformType.class);
|
||||
tool.putAll(item);
|
||||
tool.put(TransformType.THIRD_PERSON_RIGHT_HAND, convert(0, 4, 0.5f, 0, -90, 55, 0.85f));
|
||||
tool.put(TransformType.THIRD_PERSON_LEFT_HAND, convert(0, 4, 0.5f, 0, 90, -55, 0.85f));
|
||||
tool.put(TransformType.FIRST_PERSON_RIGHT_HAND, convert(1.13f, 3.2f, 1.13f, 0, -90, 25, 0.68f));
|
||||
tool.put(TransformType.FIRST_PERSON_LEFT_HAND, convert(1.13f, 3.2f, 1.13f, 0, 90, -25, 0.68f));
|
||||
builder.put("forge:default-tool", new SimpleModelState(ImmutableMap.copyOf(tool)));
|
||||
|
||||
transforms = builder.build();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,102 +0,0 @@
|
||||
/*
|
||||
* Minecraft Forge
|
||||
* Copyright (c) 2016-2019.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation version 2.1
|
||||
* of the License.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package net.minecraftforge.client.model;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
import net.minecraft.client.renderer.model.IBakedModel;
|
||||
import net.minecraft.client.renderer.model.ModelBakery;
|
||||
import net.minecraft.client.renderer.texture.ISprite;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormat;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.common.model.IModelState;
|
||||
import net.minecraftforge.common.model.TRSRTransformation;
|
||||
import net.minecraftforge.common.model.animation.IClip;
|
||||
|
||||
/**
|
||||
* General interface for any model that can be baked, superset of vanilla {@link net.minecraft.client.renderer.model.IUnbakedModel}.
|
||||
* Models can be baked to different vertex formats and with different state.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public interface IModel<T extends IModel<T>>
|
||||
{
|
||||
/**
|
||||
* @param spriteGetter Where textures will be looked up when baking
|
||||
* @param sprite Transforms to apply while baking. Usually will be an instance of {@link IModelState}.
|
||||
*/
|
||||
@Nullable
|
||||
IBakedModel bake(ModelBakery bakery, Function<ResourceLocation, TextureAtlasSprite> spriteGetter, ISprite sprite, VertexFormat format);
|
||||
|
||||
/**
|
||||
* Default state this model will be baked with.
|
||||
* @see IModelState
|
||||
*/
|
||||
default IModelState getDefaultState() {
|
||||
return TRSRTransformation.identity();
|
||||
}
|
||||
|
||||
default Optional<? extends IClip> getClip(String name) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows the model to process custom data from the variant definition.
|
||||
* If unknown data is encountered it should be skipped.
|
||||
* @return a new model, with data applied.
|
||||
*/
|
||||
default T process(ImmutableMap<String, String> customData) {
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
default T smoothLighting(boolean value) {
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
default T gui3d(boolean value) {
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies new textures to the model.
|
||||
* The returned model should be independent of the accessed one,
|
||||
* as a model should be able to be retextured multiple times producing
|
||||
* a separate model each time.
|
||||
*
|
||||
* The input map MAY map to an empty string "" which should be used
|
||||
* to indicate the texture was removed. Handling of that is up to
|
||||
* the model itself. Such as using default, missing texture, or
|
||||
* removing vertices.
|
||||
*
|
||||
* The input should be considered a DIFF of the old textures, not a
|
||||
* replacement as it may not contain everything.
|
||||
*
|
||||
* @param textures New
|
||||
* @return Model with textures applied.
|
||||
*/
|
||||
default T retexture(ImmutableMap<String, String> textures) {
|
||||
return (T) this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Minecraft Forge
|
||||
* Copyright (c) 2016-2019.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation version 2.1
|
||||
* of the License.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package net.minecraftforge.client.model;
|
||||
|
||||
import net.minecraft.client.renderer.model.BakedQuad;
|
||||
import net.minecraft.client.renderer.model.IBakedModel;
|
||||
import net.minecraft.client.renderer.model.ItemOverrideList;
|
||||
import net.minecraft.client.renderer.model.SimpleBakedModel;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.util.Direction;
|
||||
|
||||
public interface IModelBuilder<T extends IModelBuilder<T>>
|
||||
{
|
||||
static IModelBuilder<?> of(IModelConfiguration owner, ItemOverrideList overrides, TextureAtlasSprite particle)
|
||||
{
|
||||
return new Simple(new SimpleBakedModel.Builder(owner, overrides).setTexture(particle));
|
||||
}
|
||||
|
||||
T addFaceQuad(Direction facing, BakedQuad quad);
|
||||
T addGeneralQuad(BakedQuad quad);
|
||||
|
||||
IBakedModel build();
|
||||
|
||||
class Simple implements IModelBuilder<Simple> {
|
||||
final SimpleBakedModel.Builder builder;
|
||||
|
||||
Simple(SimpleBakedModel.Builder builder)
|
||||
{
|
||||
this.builder = builder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Simple addFaceQuad(Direction facing, BakedQuad quad)
|
||||
{
|
||||
builder.addFaceQuad(facing, quad);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Simple addGeneralQuad(BakedQuad quad)
|
||||
{
|
||||
builder.addGeneralQuad(quad);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBakedModel build()
|
||||
{
|
||||
return builder.build();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* Minecraft Forge
|
||||
* Copyright (c) 2016-2019.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation version 2.1
|
||||
* of the License.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package net.minecraftforge.client.model;
|
||||
|
||||
import net.minecraft.client.renderer.model.IModelTransform;
|
||||
import net.minecraft.client.renderer.model.ItemCameraTransforms;
|
||||
import net.minecraft.client.renderer.model.Material;
|
||||
import net.minecraftforge.client.model.geometry.IModelGeometryPart;
|
||||
|
||||
/*
|
||||
* Interface that provides generic access to the data within BlockModel,
|
||||
* while allowing non-blockmodel usage of models
|
||||
*/
|
||||
public interface IModelConfiguration {
|
||||
/**
|
||||
* @return The name of the model being baked, for logging and cache purposes.
|
||||
*/
|
||||
String getModelName();
|
||||
|
||||
/**
|
||||
* Checks if a texture is present in the model.
|
||||
* @param name The name of a texture channel.
|
||||
*/
|
||||
boolean isTexturePresent(String name);
|
||||
|
||||
/**
|
||||
* Resolves the final texture name, taking into account texture aliases and replacements.
|
||||
* @param name The name of a texture channel.
|
||||
* @return The location of the texture, or the missing texture if not found.
|
||||
*/
|
||||
Material resolveTexture(String name);
|
||||
|
||||
/**
|
||||
* @return True if the item uses 3D lighting.
|
||||
*/
|
||||
boolean isShadedInGui();
|
||||
|
||||
/**
|
||||
* @return True if the item requires per-vertex lighting.
|
||||
*/
|
||||
boolean useSmoothLighting();
|
||||
|
||||
/**
|
||||
* Gets the vanilla camera transforms data.
|
||||
* Do not use for non-vanilla code. For general usage, prefer getCombinedState.
|
||||
*/
|
||||
@Deprecated
|
||||
ItemCameraTransforms getCameraTransforms();
|
||||
|
||||
/**
|
||||
* @return The combined transformation state including vanilla and forge transforms data.
|
||||
*/
|
||||
IModelTransform getCombinedTransform();
|
||||
|
||||
/**
|
||||
* Queries the visibility information for the model parts.
|
||||
* @param part A part for which to query visibility.
|
||||
* @param fallback A boolean specifying the default visibility if an override isn't found in the model data.
|
||||
* @return The final computed visibility.
|
||||
*/
|
||||
default boolean getPartVisibility(IModelGeometryPart part, boolean fallback) {
|
||||
return fallback;
|
||||
}
|
||||
|
||||
/**
|
||||
* Queries the visibility information for the model parts. Same as above, but defaulting to visible.
|
||||
* @param part A part for which to query visibility.
|
||||
* @return The final computed visibility.
|
||||
*/
|
||||
default boolean getPartVisibility(IModelGeometryPart part) {
|
||||
return getPartVisibility(part, true);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Minecraft Forge
|
||||
* Copyright (c) 2016-2019.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation version 2.1
|
||||
* of the License.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package net.minecraftforge.client.model;
|
||||
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonObject;
|
||||
import net.minecraft.resources.IResourceManager;
|
||||
import net.minecraftforge.client.model.geometry.IModelGeometry;
|
||||
import net.minecraftforge.resource.IResourceType;
|
||||
import net.minecraftforge.resource.ISelectiveResourceReloadListener;
|
||||
import net.minecraftforge.resource.VanillaResourceType;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public interface IModelLoader<T extends IModelGeometry<T>> extends ISelectiveResourceReloadListener
|
||||
{
|
||||
@Override
|
||||
default IResourceType getResourceType()
|
||||
{
|
||||
return VanillaResourceType.MODELS;
|
||||
}
|
||||
|
||||
@Override
|
||||
void onResourceManagerReload(IResourceManager resourceManager);
|
||||
|
||||
@Override
|
||||
default void onResourceManagerReload(IResourceManager resourceManager, Predicate<IResourceType> resourcePredicate)
|
||||
{
|
||||
if (resourcePredicate.test(getResourceType()))
|
||||
{
|
||||
onResourceManagerReload(resourceManager);
|
||||
}
|
||||
}
|
||||
|
||||
T read(JsonDeserializationContext deserializationContext, JsonObject modelContents);
|
||||
}
|
||||
@@ -19,31 +19,25 @@
|
||||
|
||||
package net.minecraftforge.client.model;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.vecmath.Vector4f;
|
||||
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import net.minecraft.client.renderer.TransformationMatrix;
|
||||
import net.minecraft.client.renderer.model.*;
|
||||
import net.minecraft.client.renderer.texture.ISprite;
|
||||
import net.minecraftforge.versions.forge.ForgeVersion;
|
||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||
import net.minecraftforge.client.model.geometry.IModelGeometry;
|
||||
|
||||
import net.minecraft.client.renderer.model.ItemCameraTransforms.TransformType;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormat;
|
||||
import net.minecraft.resources.IResourceManager;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.client.model.pipeline.IVertexConsumer;
|
||||
import net.minecraftforge.client.model.pipeline.TRSRTransformer;
|
||||
import net.minecraftforge.client.model.pipeline.UnpackedBakedQuad;
|
||||
import net.minecraftforge.common.model.IModelState;
|
||||
import net.minecraftforge.common.model.TRSRTransformation;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.BitSet;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumMap;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
|
||||
@@ -58,90 +52,56 @@ import com.google.common.collect.ImmutableMap;
|
||||
* - Various fixes in the baking logic.
|
||||
* - Not limited to 4 layers maximum.
|
||||
*/
|
||||
public final class ItemLayerModel implements IUnbakedModel
|
||||
// TODO: Implement as new model loader
|
||||
public final class ItemLayerModel implements IModelGeometry<ItemLayerModel>
|
||||
{
|
||||
public static final ItemLayerModel INSTANCE = new ItemLayerModel(ImmutableList.of());
|
||||
|
||||
private static final Direction[] HORIZONTALS = {Direction.UP, Direction.DOWN};
|
||||
private static final Direction[] VERTICALS = {Direction.WEST, Direction.EAST};
|
||||
|
||||
private final ImmutableList<ResourceLocation> textures;
|
||||
private final ItemOverrideList overrides;
|
||||
private ImmutableList<Material> textures;
|
||||
|
||||
public ItemLayerModel(ImmutableList<ResourceLocation> textures)
|
||||
{
|
||||
this(textures, ItemOverrideList.EMPTY);
|
||||
}
|
||||
|
||||
public ItemLayerModel(ImmutableList<ResourceLocation> textures, ItemOverrideList overrides)
|
||||
public ItemLayerModel(ImmutableList<Material> textures)
|
||||
{
|
||||
this.textures = textures;
|
||||
this.overrides = overrides;
|
||||
}
|
||||
|
||||
public ItemLayerModel(ModelBakery bakery, BlockModel model, VertexFormat format)
|
||||
public ItemLayerModel()
|
||||
{
|
||||
this(getTextures(model), model.getOverrides(bakery, model, ModelLoader.defaultTextureGetter(), format));
|
||||
this.textures = null;
|
||||
}
|
||||
|
||||
private static ImmutableList<ResourceLocation> getTextures(BlockModel model)
|
||||
private static ImmutableList<Material> getTextures(IModelConfiguration model)
|
||||
{
|
||||
ImmutableList.Builder<ResourceLocation> builder = ImmutableList.builder();
|
||||
ImmutableList.Builder<Material> builder = ImmutableList.builder();
|
||||
for(int i = 0; model.isTexturePresent("layer" + i); i++)
|
||||
{
|
||||
builder.add(new ResourceLocation(model.resolveTextureName("layer" + i)));
|
||||
builder.add(model.resolveTexture("layer" + i));
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ResourceLocation> getTextures(Function<ResourceLocation, IUnbakedModel> modelGetter, Set<String> missingTextureErrors)
|
||||
{
|
||||
return textures;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ResourceLocation> getDependencies()
|
||||
{
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemLayerModel retexture(ImmutableMap<String, String> textures)
|
||||
{
|
||||
ImmutableList.Builder<ResourceLocation> builder = ImmutableList.builder();
|
||||
for(int i = 0; i < textures.size() + this.textures.size(); i++)
|
||||
{
|
||||
if(textures.containsKey("layer" + i))
|
||||
{
|
||||
builder.add(new ResourceLocation(textures.get("layer" + i)));
|
||||
}
|
||||
else if(i < this.textures.size())
|
||||
{
|
||||
builder.add(this.textures.get(i));
|
||||
}
|
||||
}
|
||||
return new ItemLayerModel(builder.build(), overrides);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public IBakedModel bake(ModelBakery bakery, Function<ResourceLocation, TextureAtlasSprite> spriteGetter, ISprite sprite, VertexFormat format)
|
||||
public IBakedModel bake(IModelConfiguration owner, ModelBakery bakery, Function<Material, TextureAtlasSprite> spriteGetter, IModelTransform sprite, ItemOverrideList overrides, ResourceLocation modelLocation)
|
||||
{
|
||||
//TODO: Verify
|
||||
ImmutableList.Builder<BakedQuad> builder = ImmutableList.builder();
|
||||
Optional<TRSRTransformation> transform = sprite.getState().apply(Optional.empty());
|
||||
boolean identity = !transform.isPresent() || transform.get().isIdentity();
|
||||
TransformationMatrix transform = sprite.func_225615_b_();
|
||||
boolean identity = transform.isIdentity();
|
||||
for(int i = 0; i < textures.size(); i++)
|
||||
{
|
||||
TextureAtlasSprite tas = spriteGetter.apply(textures.get(i));
|
||||
builder.addAll(getQuadsForSprite(i, tas, format, transform));
|
||||
builder.addAll(getQuadsForSprite(i, tas, DefaultVertexFormats.BLOCK, transform));
|
||||
}
|
||||
TextureAtlasSprite particle = spriteGetter.apply(textures.isEmpty() ? new ResourceLocation("missingno") : textures.get(0));
|
||||
ImmutableMap<TransformType, TRSRTransformation> map = PerspectiveMapWrapper.getTransforms(sprite.getState());
|
||||
TextureAtlasSprite particle = spriteGetter.apply(
|
||||
owner.isTexturePresent("particle") ? owner.resolveTexture("particle") : textures.get(0)
|
||||
);
|
||||
ImmutableMap<TransformType, TransformationMatrix> map = PerspectiveMapWrapper.getTransforms(sprite);
|
||||
return new BakedItemModel(builder.build(), particle, map, overrides, identity);
|
||||
}
|
||||
|
||||
public static ImmutableList<BakedQuad> getQuadsForSprite(int tint, TextureAtlasSprite sprite, VertexFormat format, Optional<TRSRTransformation> transform)
|
||||
public static ImmutableList<BakedQuad> getQuadsForSprite(int tint, TextureAtlasSprite sprite, VertexFormat format, TransformationMatrix transform)
|
||||
{
|
||||
ImmutableList.Builder<BakedQuad> builder = ImmutableList.builder();
|
||||
|
||||
@@ -316,6 +276,13 @@ public final class ItemLayerModel implements IUnbakedModel
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Material> getTextures(IModelConfiguration owner, Function<ResourceLocation, IUnbakedModel> modelGetter, Set<Pair<String, String>> missingTextureErrors)
|
||||
{
|
||||
textures = getTextures(owner);
|
||||
return textures;
|
||||
}
|
||||
|
||||
private static class FaceData
|
||||
{
|
||||
private final EnumMap<Direction, BitSet> data = new EnumMap<>(Direction.class);
|
||||
@@ -348,7 +315,7 @@ public final class ItemLayerModel implements IUnbakedModel
|
||||
}
|
||||
}
|
||||
|
||||
private static BakedQuad buildSideQuad(VertexFormat format, Optional<TRSRTransformation> transform, Direction side, int tint, TextureAtlasSprite sprite, int u, int v, int size)
|
||||
private static BakedQuad buildSideQuad(VertexFormat format, TransformationMatrix transform, Direction side, int tint, TextureAtlasSprite sprite, int u, int v, int size)
|
||||
{
|
||||
final float eps = 1e-2f;
|
||||
|
||||
@@ -402,7 +369,7 @@ public final class ItemLayerModel implements IUnbakedModel
|
||||
}
|
||||
|
||||
private static BakedQuad buildQuad(
|
||||
VertexFormat format, Optional<TRSRTransformation> transform, Direction side, TextureAtlasSprite sprite, int tint,
|
||||
VertexFormat format, TransformationMatrix transform, Direction side, TextureAtlasSprite sprite, int tint,
|
||||
float x0, float y0, float z0, float u0, float v0,
|
||||
float x1, float y1, float z1, float u1, float v1,
|
||||
float x2, float y2, float z2, float u2, float v2,
|
||||
@@ -414,8 +381,8 @@ public final class ItemLayerModel implements IUnbakedModel
|
||||
builder.setQuadOrientation(side);
|
||||
builder.setTexture(sprite);
|
||||
|
||||
boolean hasTransform = transform.isPresent() && !transform.get().isIdentity();
|
||||
IVertexConsumer consumer = hasTransform ? new TRSRTransformer(builder, transform.get()) : builder;
|
||||
boolean hasTransform = !transform.isIdentity();
|
||||
IVertexConsumer consumer = hasTransform ? new TRSRTransformer(builder, transform) : builder;
|
||||
|
||||
putVertex(consumer, format, side, x0, y0, z0, u0, v0);
|
||||
putVertex(consumer, format, side, x1, y1, z1, u1, v1);
|
||||
@@ -427,9 +394,9 @@ public final class ItemLayerModel implements IUnbakedModel
|
||||
|
||||
private static void putVertex(IVertexConsumer consumer, VertexFormat format, Direction side, float x, float y, float z, float u, float v)
|
||||
{
|
||||
for(int e = 0; e < format.getElementCount(); e++)
|
||||
for(int e = 0; e < format.func_227894_c_().size(); e++)
|
||||
{
|
||||
switch(format.getElement(e).getUsage())
|
||||
switch(format.func_227894_c_().get(e).getUsage())
|
||||
{
|
||||
case POSITION:
|
||||
consumer.put(e, x, y, z, 1f);
|
||||
@@ -444,7 +411,7 @@ public final class ItemLayerModel implements IUnbakedModel
|
||||
consumer.put(e, offX, offY, offZ, 0f);
|
||||
break;
|
||||
case UV:
|
||||
if(format.getElement(e).getIndex() == 0)
|
||||
if(format.func_227894_c_().get(e).getIndex() == 0)
|
||||
{
|
||||
consumer.put(e, u, v, 0f, 1f);
|
||||
break;
|
||||
@@ -456,27 +423,4 @@ public final class ItemLayerModel implements IUnbakedModel
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static enum Loader implements ICustomModelLoader
|
||||
{
|
||||
INSTANCE;
|
||||
|
||||
@Override
|
||||
public void onResourceManagerReload(IResourceManager resourceManager) {}
|
||||
|
||||
@Override
|
||||
public boolean accepts(ResourceLocation modelLocation)
|
||||
{
|
||||
return modelLocation.getNamespace().equals(ForgeVersion.MOD_ID) && (
|
||||
modelLocation.getPath().equals("item-layer") ||
|
||||
modelLocation.getPath().equals("models/block/item-layer") ||
|
||||
modelLocation.getPath().equals("models/item/item-layer"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IUnbakedModel loadModel(ResourceLocation modelLocation)
|
||||
{
|
||||
return ItemLayerModel.INSTANCE;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,14 +21,13 @@ package net.minecraftforge.client.model;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import net.minecraft.client.renderer.texture.NativeImage;
|
||||
import net.minecraft.client.renderer.TransformationMatrix;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormat;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraftforge.client.model.pipeline.IVertexConsumer;
|
||||
import net.minecraftforge.client.model.pipeline.TRSRTransformer;
|
||||
import net.minecraftforge.client.model.pipeline.UnpackedBakedQuad;
|
||||
import net.minecraftforge.common.model.TRSRTransformation;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -52,7 +51,7 @@ public final class ItemTextureQuadConverter
|
||||
* @param sprite The texture whose UVs shall be used
|
||||
* @return The generated quads.
|
||||
*/
|
||||
public static List<UnpackedBakedQuad> convertTexture(VertexFormat format, TRSRTransformation transform, TextureAtlasSprite template, TextureAtlasSprite sprite, float z, Direction facing, int color, int tint)
|
||||
public static List<UnpackedBakedQuad> convertTexture(VertexFormat format, TransformationMatrix transform, TextureAtlasSprite template, TextureAtlasSprite sprite, float z, Direction facing, int color, int tint)
|
||||
{
|
||||
List<UnpackedBakedQuad> horizontal = convertTextureHorizontal(format, transform, template, sprite, z, facing, color, tint);
|
||||
List<UnpackedBakedQuad> vertical = convertTextureVertical(format, transform, template, sprite, z, facing, color, tint);
|
||||
@@ -64,7 +63,7 @@ public final class ItemTextureQuadConverter
|
||||
* Scans a texture and converts it into a list of horizontal strips stacked on top of each other.
|
||||
* The height of the strips is as big as possible.
|
||||
*/
|
||||
public static List<UnpackedBakedQuad> convertTextureHorizontal(VertexFormat format, TRSRTransformation transform, TextureAtlasSprite template, TextureAtlasSprite sprite, float z, Direction facing, int color, int tint)
|
||||
public static List<UnpackedBakedQuad> convertTextureHorizontal(VertexFormat format, TransformationMatrix transform, TextureAtlasSprite template, TextureAtlasSprite sprite, float z, Direction facing, int color, int tint)
|
||||
{
|
||||
int w = template.getWidth();
|
||||
int h = template.getHeight();
|
||||
@@ -135,7 +134,7 @@ public final class ItemTextureQuadConverter
|
||||
* Scans a texture and converts it into a list of vertical strips stacked next to each other from left to right.
|
||||
* The width of the strips is as big as possible.
|
||||
*/
|
||||
public static List<UnpackedBakedQuad> convertTextureVertical(VertexFormat format, TRSRTransformation transform, TextureAtlasSprite template, TextureAtlasSprite sprite, float z, Direction facing, int color, int tint)
|
||||
public static List<UnpackedBakedQuad> convertTextureVertical(VertexFormat format, TransformationMatrix transform, TextureAtlasSprite template, TextureAtlasSprite sprite, float z, Direction facing, int color, int tint)
|
||||
{
|
||||
int w = template.getWidth();
|
||||
int h = template.getHeight();
|
||||
@@ -211,7 +210,7 @@ public final class ItemTextureQuadConverter
|
||||
* Generates a Front/Back quad for an itemmodel. Therefore only supports facing NORTH and SOUTH.
|
||||
* Coordinates are [0,16] to match the usual coordinates used in TextureAtlasSprites
|
||||
*/
|
||||
public static UnpackedBakedQuad genQuad(VertexFormat format, TRSRTransformation transform, float x1, float y1, float x2, float y2, float z, TextureAtlasSprite sprite, Direction facing, int color, int tint)
|
||||
public static UnpackedBakedQuad genQuad(VertexFormat format, TransformationMatrix transform, float x1, float y1, float x2, float y2, float z, TextureAtlasSprite sprite, Direction facing, int color, int tint)
|
||||
{
|
||||
float u1 = sprite.getInterpolatedU(x1);
|
||||
float v1 = sprite.getInterpolatedV(y1);
|
||||
@@ -230,7 +229,7 @@ public final class ItemTextureQuadConverter
|
||||
return putQuad(format, transform, facing, sprite, color, tint, x1, y1, x2, y2, z, u1, v1, u2, v2);
|
||||
}
|
||||
|
||||
private static UnpackedBakedQuad putQuad(VertexFormat format, TRSRTransformation transform, Direction side, TextureAtlasSprite sprite, int color, int tint,
|
||||
private static UnpackedBakedQuad putQuad(VertexFormat format, TransformationMatrix transform, Direction side, TextureAtlasSprite sprite, int color, int tint,
|
||||
float x1, float y1, float x2, float y2, float z,
|
||||
float u1, float v1, float u2, float v2)
|
||||
{
|
||||
@@ -264,9 +263,9 @@ public final class ItemTextureQuadConverter
|
||||
private static void putVertex(IVertexConsumer consumer, VertexFormat format, Direction side,
|
||||
float x, float y, float z, float u, float v, int color)
|
||||
{
|
||||
for (int e = 0; e < format.getElementCount(); e++)
|
||||
for (int e = 0; e < format.func_227894_c_().size(); e++)
|
||||
{
|
||||
switch (format.getElement(e).getUsage())
|
||||
switch (format.func_227894_c_().get(e).getUsage())
|
||||
{
|
||||
case POSITION:
|
||||
consumer.put(e, x, y, z, 1f);
|
||||
@@ -285,7 +284,7 @@ public final class ItemTextureQuadConverter
|
||||
consumer.put(e, offX, offY, offZ, 0f);
|
||||
break;
|
||||
case UV:
|
||||
if (format.getElement(e).getIndex() == 0)
|
||||
if (format.func_227894_c_().get(e).getIndex() == 0)
|
||||
{
|
||||
consumer.put(e, u, v, 0f, 1f);
|
||||
break;
|
||||
|
||||
@@ -20,49 +20,47 @@
|
||||
package net.minecraftforge.client.model;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.vecmath.Quat4f;
|
||||
|
||||
import com.google.common.collect.*;
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.Quaternion;
|
||||
import net.minecraft.client.renderer.TransformationMatrix;
|
||||
import net.minecraft.client.renderer.model.*;
|
||||
import net.minecraft.client.renderer.model.ItemCameraTransforms.TransformType;
|
||||
import net.minecraft.client.renderer.texture.ISprite;
|
||||
import net.minecraft.client.renderer.texture.PngSizeInfo;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.renderer.texture.AtlasTexture;
|
||||
import net.minecraft.client.renderer.texture.*;
|
||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormat;
|
||||
import net.minecraft.client.resources.data.AnimationMetadataSection;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.fluid.Fluid;
|
||||
import net.minecraft.fluid.Fluids;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.resources.IResource;
|
||||
import net.minecraft.resources.IResourceManager;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.client.model.geometry.IModelGeometry;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import net.minecraftforge.resource.IResourceType;
|
||||
import net.minecraftforge.resource.VanillaResourceType;
|
||||
import net.minecraftforge.versions.forge.ForgeVersion;
|
||||
import net.minecraftforge.common.model.IModelState;
|
||||
import net.minecraftforge.common.model.TRSRTransformation;
|
||||
import net.minecraftforge.common.model.TransformationHelper;
|
||||
import net.minecraftforge.fluids.FluidUtil;
|
||||
|
||||
import java.util.function.Function;
|
||||
import java.util.Optional;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Maps;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
public final class ModelDynBucket implements IUnbakedModel
|
||||
public final class ModelDynBucket implements IModelGeometry<ModelDynBucket>
|
||||
{
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
public static final ModelResourceLocation LOCATION = new ModelResourceLocation(new ResourceLocation(ForgeVersion.MOD_ID, "dynbucket"), "inventory");
|
||||
@@ -73,111 +71,28 @@ public final class ModelDynBucket implements IUnbakedModel
|
||||
private static final float NORTH_Z_FLUID = 7.498f / 16f;
|
||||
private static final float SOUTH_Z_FLUID = 8.502f / 16f;
|
||||
|
||||
public static final IUnbakedModel MODEL = new ModelDynBucket();
|
||||
@Deprecated
|
||||
public static final ModelDynBucket MODEL = new ModelDynBucket();
|
||||
|
||||
@Nullable
|
||||
private final ResourceLocation baseLocation;
|
||||
@Nullable
|
||||
private final ResourceLocation liquidLocation;
|
||||
@Nullable
|
||||
private final ResourceLocation coverLocation;
|
||||
@Nullable
|
||||
@Nonnull
|
||||
private final Fluid fluid;
|
||||
|
||||
private final boolean flipGas;
|
||||
private final boolean tint;
|
||||
private final boolean coverIsMask;
|
||||
|
||||
@Deprecated
|
||||
public ModelDynBucket()
|
||||
{
|
||||
this(null, null, null, null, false, true);
|
||||
this(Fluids.EMPTY, false, true, false);
|
||||
}
|
||||
|
||||
public ModelDynBucket(@Nullable ResourceLocation baseLocation, @Nullable ResourceLocation liquidLocation, @Nullable ResourceLocation coverLocation, @Nullable Fluid fluid, boolean flipGas, boolean tint)
|
||||
public ModelDynBucket(Fluid fluid, boolean flipGas, boolean tint, boolean coverIsMask)
|
||||
{
|
||||
this.baseLocation = baseLocation;
|
||||
this.liquidLocation = liquidLocation;
|
||||
this.coverLocation = coverLocation;
|
||||
this.fluid = fluid;
|
||||
this.flipGas = flipGas;
|
||||
this.tint = tint;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ResourceLocation> getTextures(Function<ResourceLocation, IUnbakedModel> modelGetter, Set<String> missingTextureErrors)
|
||||
{
|
||||
ImmutableSet.Builder<ResourceLocation> builder = ImmutableSet.builder();
|
||||
|
||||
if (baseLocation != null)
|
||||
builder.add(baseLocation);
|
||||
if (liquidLocation != null)
|
||||
builder.add(liquidLocation);
|
||||
if (coverLocation != null)
|
||||
builder.add(coverLocation);
|
||||
if (fluid != null)
|
||||
builder.add(fluid.getAttributes().getStillTexture());
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ResourceLocation> getDependencies()
|
||||
{
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public IBakedModel bake(ModelBakery bakery, Function<ResourceLocation, TextureAtlasSprite> spriteGetter, ISprite sprite, VertexFormat format)
|
||||
{
|
||||
IModelState state = sprite.getState();
|
||||
ImmutableMap<TransformType, TRSRTransformation> transformMap = PerspectiveMapWrapper.getTransforms(state);
|
||||
|
||||
// if the fluid is lighter than air, will manipulate the initial state to be rotated 180° to turn it upside down
|
||||
if (flipGas && fluid != null && fluid.getAttributes().isLighterThanAir())
|
||||
{
|
||||
sprite = new ModelStateComposition(state, TRSRTransformation.blockCenterToCorner(new TRSRTransformation(null, new Quat4f(0, 0, 1, 0), null, null)));
|
||||
state = sprite.getState();
|
||||
}
|
||||
|
||||
TRSRTransformation transform = state.apply(Optional.empty()).orElse(TRSRTransformation.identity());
|
||||
TextureAtlasSprite fluidSprite = null;
|
||||
TextureAtlasSprite particleSprite = null;
|
||||
ImmutableList.Builder<BakedQuad> builder = ImmutableList.builder();
|
||||
|
||||
if(fluid != null) {
|
||||
fluidSprite = spriteGetter.apply(fluid.getAttributes().getStillTexture());
|
||||
}
|
||||
|
||||
Random random = new Random();
|
||||
if (baseLocation != null)
|
||||
{
|
||||
// build base (insidest)
|
||||
IBakedModel model = (new ItemLayerModel(ImmutableList.of(baseLocation))).bake(bakery, spriteGetter, sprite, format);
|
||||
random.setSeed(42);
|
||||
builder.addAll(model.getQuads(null, null, random));
|
||||
particleSprite = model.getParticleTexture();
|
||||
}
|
||||
if (liquidLocation != null && fluidSprite != null)
|
||||
{
|
||||
TextureAtlasSprite liquid = spriteGetter.apply(liquidLocation);
|
||||
// build liquid layer (inside)
|
||||
builder.addAll(ItemTextureQuadConverter.convertTexture(format, transform, liquid, fluidSprite, NORTH_Z_FLUID, Direction.NORTH, tint ? fluid.getAttributes().getColor() : 0xFFFFFFFF, 1));
|
||||
builder.addAll(ItemTextureQuadConverter.convertTexture(format, transform, liquid, fluidSprite, SOUTH_Z_FLUID, Direction.SOUTH, tint ? fluid.getAttributes().getColor() : 0xFFFFFFFF, 1));
|
||||
particleSprite = fluidSprite;
|
||||
}
|
||||
if (coverLocation != null)
|
||||
{
|
||||
// cover (the actual item around the other two)
|
||||
TextureAtlasSprite cover = spriteGetter.apply(coverLocation);
|
||||
builder.add(ItemTextureQuadConverter.genQuad(format, transform, 0, 0, 16, 16, NORTH_Z_COVER, cover, Direction.NORTH, 0xFFFFFFFF, 2));
|
||||
builder.add(ItemTextureQuadConverter.genQuad(format, transform, 0, 0, 16, 16, SOUTH_Z_COVER, cover, Direction.SOUTH, 0xFFFFFFFF, 2));
|
||||
if (particleSprite == null)
|
||||
{
|
||||
particleSprite = cover;
|
||||
}
|
||||
}
|
||||
|
||||
return new BakedDynBucket(bakery, this, builder.build(), particleSprite, format, Maps.immutableEnumMap(transformMap), Maps.newHashMap(), transform.isIdentity());
|
||||
this.coverIsMask = coverIsMask;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -188,67 +103,19 @@ public final class ModelDynBucket implements IUnbakedModel
|
||||
* <p/>
|
||||
* If the fluid can't be found, water is used.
|
||||
*/
|
||||
@Override
|
||||
public ModelDynBucket process(ImmutableMap<String, String> customData)
|
||||
@Deprecated
|
||||
public ModelDynBucket withFluid(String newFluid)
|
||||
{
|
||||
ResourceLocation fluidName = new ResourceLocation(customData.get("fluid"));
|
||||
ResourceLocation fluidName = new ResourceLocation(newFluid);
|
||||
Fluid fluid = ForgeRegistries.FLUIDS.getValue(fluidName);
|
||||
|
||||
if (fluid == null) fluid = this.fluid;
|
||||
|
||||
boolean flip = flipGas;
|
||||
if (customData.containsKey("flipGas"))
|
||||
{
|
||||
String flipStr = customData.get("flipGas");
|
||||
if (flipStr.equals("true")) flip = true;
|
||||
else if (flipStr.equals("false")) flip = false;
|
||||
else
|
||||
throw new IllegalArgumentException(String.format("DynBucket custom data \"flipGas\" must have value \'true\' or \'false\' (was \'%s\')", flipStr));
|
||||
}
|
||||
|
||||
boolean tint = this.tint;
|
||||
if (customData.containsKey("applyTint"))
|
||||
{
|
||||
String string = customData.get("applyTint");
|
||||
switch (string)
|
||||
{
|
||||
case "true": tint = true; break;
|
||||
case "false": tint = false; break;
|
||||
default: throw new IllegalArgumentException(String.format("DynBucket custom data \"applyTint\" must have value \'true\' or \'false\' (was \'%s\')", string));
|
||||
}
|
||||
}
|
||||
if (fluid == null)
|
||||
fluid = this.fluid;
|
||||
|
||||
// create new model with correct liquid
|
||||
return new ModelDynBucket(baseLocation, liquidLocation, coverLocation, fluid, flip, tint);
|
||||
return new ModelDynBucket(fluid, flipGas, tint, coverIsMask);
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows to use different textures for the model.
|
||||
* There are 3 layers:
|
||||
* base - The empty bucket/container
|
||||
* fluid - A texture representing the liquid portion. Non-transparent = liquid
|
||||
* cover - An overlay that's put over the liquid (optional)
|
||||
* <p/>
|
||||
* If no liquid is given a hardcoded variant for the bucket is used.
|
||||
*/
|
||||
@Override
|
||||
public ModelDynBucket retexture(ImmutableMap<String, String> textures)
|
||||
{
|
||||
|
||||
ResourceLocation base = baseLocation;
|
||||
ResourceLocation liquid = liquidLocation;
|
||||
ResourceLocation cover = coverLocation;
|
||||
|
||||
if (textures.containsKey("base"))
|
||||
base = new ResourceLocation(textures.get("base"));
|
||||
if (textures.containsKey("fluid"))
|
||||
liquid = new ResourceLocation(textures.get("fluid"));
|
||||
if (textures.containsKey("cover"))
|
||||
cover = new ResourceLocation(textures.get("cover"));
|
||||
|
||||
return new ModelDynBucket(base, liquid, cover, fluid, flipGas, tint);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected static IResource getResource(ResourceLocation resourceLocation)
|
||||
{
|
||||
@@ -274,21 +141,128 @@ public final class ModelDynBucket implements IUnbakedModel
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public enum LoaderDynBucket implements ICustomModelLoader
|
||||
|
||||
@Override
|
||||
public IBakedModel bake(IModelConfiguration owner, ModelBakery bakery, Function<Material, TextureAtlasSprite> spriteGetter, IModelTransform sprite, ItemOverrideList overrides, ResourceLocation modelLocation)
|
||||
{
|
||||
Material particleLocation = owner.resolveTexture("particle");
|
||||
if (MissingTextureSprite.getLocation().toString().equals(particleLocation))
|
||||
{
|
||||
particleLocation = null;
|
||||
}
|
||||
|
||||
Material baseLocation = owner.resolveTexture("base");
|
||||
if (MissingTextureSprite.getLocation().toString().equals(baseLocation))
|
||||
{
|
||||
baseLocation = null;
|
||||
}
|
||||
|
||||
Material fluidMaskLocation = owner.resolveTexture("fluid");
|
||||
if (MissingTextureSprite.getLocation().toString().equals(fluidMaskLocation))
|
||||
{
|
||||
fluidMaskLocation = null;
|
||||
}
|
||||
|
||||
Material coverLocation = owner.resolveTexture("cover");
|
||||
if (!MissingTextureSprite.getLocation().toString().equals(coverLocation))
|
||||
{
|
||||
// cover (the actual item around the other two)
|
||||
coverLocation = null;
|
||||
}
|
||||
|
||||
IModelTransform transformsFromModel = owner.getCombinedTransform();
|
||||
|
||||
IModelTransform state = sprite;
|
||||
ImmutableMap<TransformType, TransformationMatrix> transformMap = transformsFromModel != null ?
|
||||
PerspectiveMapWrapper.getTransforms(new ModelTransformComposition(transformsFromModel, state)) :
|
||||
PerspectiveMapWrapper.getTransforms(state);
|
||||
|
||||
TextureAtlasSprite particleSprite = particleLocation != null ? spriteGetter.apply(particleLocation) : null;
|
||||
|
||||
// if the fluid is lighter than air, will manipulate the initial state to be rotated 180° to turn it upside down
|
||||
if (flipGas && fluid != Fluids.EMPTY && fluid.getAttributes().isLighterThanAir())
|
||||
{
|
||||
sprite = new ModelTransformComposition(state, new SimpleModelTransform(TransformationHelper.blockCenterToCorner(new TransformationMatrix(null, new Quaternion(0, 0, 1, 0), null, null))));
|
||||
state = sprite;
|
||||
}
|
||||
|
||||
TransformationMatrix transform = state.func_225615_b_();
|
||||
|
||||
Material fluidLocation = fluid != Fluids.EMPTY ? fluid.getAttributes().getStillMaterial() : null;
|
||||
TextureAtlasSprite fluidSprite = fluidLocation != null ? spriteGetter.apply(fluidLocation) : null;
|
||||
|
||||
if (particleSprite == null) particleSprite = fluidSprite;
|
||||
|
||||
Random random = new Random();
|
||||
ImmutableList.Builder<BakedQuad> builder = ImmutableList.builder();
|
||||
|
||||
if (baseLocation != null)
|
||||
{
|
||||
// build base (insidest)
|
||||
IBakedModel model = new ItemLayerModel(ImmutableList.of(baseLocation)).bake(owner, bakery, spriteGetter, sprite, ItemOverrideList.EMPTY, modelLocation);
|
||||
random.setSeed(42);
|
||||
builder.addAll(model.getQuads(null, null, random));
|
||||
}
|
||||
|
||||
if (fluidMaskLocation != null && fluidSprite != null)
|
||||
{
|
||||
TextureAtlasSprite templateSprite = spriteGetter.apply(fluidMaskLocation);
|
||||
if (templateSprite != null)
|
||||
{
|
||||
// build liquid layer (inside)
|
||||
builder.addAll(ItemTextureQuadConverter.convertTexture(DefaultVertexFormats.BLOCK, transform, templateSprite, fluidSprite, NORTH_Z_FLUID, Direction.NORTH, tint ? fluid.getAttributes().getColor() : 0xFFFFFFFF, 1));
|
||||
builder.addAll(ItemTextureQuadConverter.convertTexture(DefaultVertexFormats.BLOCK, transform, templateSprite, fluidSprite, SOUTH_Z_FLUID, Direction.SOUTH, tint ? fluid.getAttributes().getColor() : 0xFFFFFFFF, 1));
|
||||
}
|
||||
}
|
||||
|
||||
if (coverLocation != null && (!coverIsMask || baseLocation != null))
|
||||
{
|
||||
// cover (the actual item around the other two)
|
||||
TextureAtlasSprite coverSprite = spriteGetter.apply(coverLocation);
|
||||
if (coverSprite != null)
|
||||
{
|
||||
if (coverIsMask)
|
||||
{
|
||||
TextureAtlasSprite baseSprite = spriteGetter.apply(baseLocation);
|
||||
builder.addAll(ItemTextureQuadConverter.convertTexture(DefaultVertexFormats.BLOCK, transform, coverSprite, baseSprite, NORTH_Z_COVER, Direction.NORTH, 0xFFFFFFFF, 1));
|
||||
builder.addAll(ItemTextureQuadConverter.convertTexture(DefaultVertexFormats.BLOCK, transform, coverSprite, baseSprite, SOUTH_Z_COVER, Direction.SOUTH, 0xFFFFFFFF, 1));
|
||||
}
|
||||
else
|
||||
{
|
||||
builder.add(ItemTextureQuadConverter.genQuad(DefaultVertexFormats.BLOCK, transform, 0, 0, 16, 16, NORTH_Z_COVER, coverSprite, Direction.NORTH, 0xFFFFFFFF, 2));
|
||||
builder.add(ItemTextureQuadConverter.genQuad(DefaultVertexFormats.BLOCK, transform, 0, 0, 16, 16, SOUTH_Z_COVER, coverSprite, Direction.SOUTH, 0xFFFFFFFF, 2));
|
||||
if (particleSprite == null)
|
||||
{
|
||||
particleSprite = coverSprite;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new BakedDynBucket(bakery, owner, this, builder.build(), particleSprite, DefaultVertexFormats.BLOCK, Maps.immutableEnumMap(transformMap), Maps.newHashMap(), transform.isIdentity());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Material> getTextures(IModelConfiguration owner, Function<ResourceLocation, IUnbakedModel> modelGetter, Set<Pair<String, String>> missingTextureErrors)
|
||||
{
|
||||
Set<Material> texs = Sets.newHashSet();
|
||||
|
||||
texs.add(owner.resolveTexture("particle"));
|
||||
texs.add(owner.resolveTexture("base"));
|
||||
texs.add(owner.resolveTexture("fluid"));
|
||||
texs.add(owner.resolveTexture("cover"));
|
||||
|
||||
return texs;
|
||||
}
|
||||
|
||||
public enum LoaderDynBucket2 implements IModelLoader<ModelDynBucket>
|
||||
{
|
||||
INSTANCE;
|
||||
|
||||
@Override
|
||||
public boolean accepts(ResourceLocation modelLocation)
|
||||
public IResourceType getResourceType()
|
||||
{
|
||||
return modelLocation.getNamespace().equals(ForgeVersion.MOD_ID) && modelLocation.getPath().contains("forgebucket");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IUnbakedModel loadModel(ResourceLocation modelLocation)
|
||||
{
|
||||
return MODEL;
|
||||
return VanillaResourceType.MODELS;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -297,27 +271,46 @@ public final class ModelDynBucket implements IUnbakedModel
|
||||
// no need to clear cache since we create a new model instance
|
||||
}
|
||||
|
||||
public void register(AtlasTexture map)
|
||||
@Override
|
||||
public void onResourceManagerReload(IResourceManager resourceManager, Predicate<IResourceType> resourcePredicate)
|
||||
{
|
||||
// only create these textures if they are not added by a resource pack
|
||||
// no need to clear cache since we create a new model instance
|
||||
}
|
||||
|
||||
IResource res;
|
||||
if (getResource(new ResourceLocation(ForgeVersion.MOD_ID, "textures/items/bucket_cover.png")) == null)
|
||||
@Override
|
||||
public ModelDynBucket read(JsonDeserializationContext deserializationContext, JsonObject modelContents)
|
||||
{
|
||||
if (!modelContents.has("fluid"))
|
||||
throw new RuntimeException("Bucket model requires 'fluid' value.");
|
||||
|
||||
ResourceLocation fluidName = new ResourceLocation(modelContents.get("fluid").getAsString());
|
||||
|
||||
Fluid fluid = ForgeRegistries.FLUIDS.getValue(fluidName);
|
||||
|
||||
boolean flip = false;
|
||||
if (modelContents.has("flipGas"))
|
||||
{
|
||||
ResourceLocation bucketCover = new ResourceLocation(ForgeVersion.MOD_ID, "items/bucket_cover");
|
||||
BucketCoverSprite bucketCoverSprite = new BucketCoverSprite(bucketCover);
|
||||
// map.setTextureEntry(bucketCoverSprite);
|
||||
flip = modelContents.get("flipGas").getAsBoolean();
|
||||
}
|
||||
|
||||
if (getResource(new ResourceLocation(ForgeVersion.MOD_ID, "textures/items/bucket_base.png")) == null)
|
||||
boolean tint = true;
|
||||
if (modelContents.has("applyTint"))
|
||||
{
|
||||
ResourceLocation bucketBase = new ResourceLocation(ForgeVersion.MOD_ID, "items/bucket_base");
|
||||
BucketBaseSprite bucketBaseSprite = new BucketBaseSprite(bucketBase);
|
||||
// map.setTextureEntry(bucketBaseSprite);
|
||||
tint = modelContents.get("applyTint").getAsBoolean();
|
||||
}
|
||||
|
||||
boolean coverIsMask = true;
|
||||
if (modelContents.has("coverIsMask"))
|
||||
{
|
||||
coverIsMask = modelContents.get("coverIsMask").getAsBoolean();
|
||||
}
|
||||
|
||||
// create new model with correct liquid
|
||||
return new ModelDynBucket(fluid, flip, tint, coverIsMask);
|
||||
}
|
||||
}
|
||||
|
||||
/* TODO Custom TAS
|
||||
private static final class BucketBaseSprite extends TextureAtlasSprite
|
||||
{
|
||||
private final ResourceLocation bucket = new ResourceLocation("item/bucket");
|
||||
@@ -328,7 +321,6 @@ public final class ModelDynBucket implements IUnbakedModel
|
||||
super(res, getSizeInfo(getResource(new ResourceLocation("textures/item/bucket.png"))), getResource(new ResourceLocation("textures/item/bucket.png")).getMetadata(AnimationMetadataSection.SERIALIZER));
|
||||
}
|
||||
|
||||
/* TODO Custom TAS
|
||||
@Override
|
||||
public boolean hasCustomLoader(@Nonnull IResourceManager manager, @Nonnull ResourceLocation location)
|
||||
{
|
||||
@@ -353,12 +345,13 @@ public final class ModelDynBucket implements IUnbakedModel
|
||||
this.clearFramesTextureData();
|
||||
this.framesTextureData.add(pixels);
|
||||
return false;
|
||||
}*/
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
/**
|
||||
* Creates a bucket cover sprite from the vanilla resource.
|
||||
*/
|
||||
/* TODO Custom TAS
|
||||
private static final class BucketCoverSprite extends TextureAtlasSprite
|
||||
{
|
||||
private final ResourceLocation bucket = new ResourceLocation("item/bucket");
|
||||
@@ -370,7 +363,6 @@ public final class ModelDynBucket implements IUnbakedModel
|
||||
super(res, getSizeInfo(getResource(new ResourceLocation("textures/item/bucket.png"))), getResource(new ResourceLocation("textures/item/bucket.png")).getMetadata(AnimationMetadataSection.SERIALIZER));
|
||||
}
|
||||
|
||||
/* TODO Custom TAS
|
||||
@Override
|
||||
public boolean hasCustomLoader(@Nonnull IResourceManager manager, @Nonnull ResourceLocation location)
|
||||
{
|
||||
@@ -422,8 +414,8 @@ public final class ModelDynBucket implements IUnbakedModel
|
||||
this.clearFramesTextureData();
|
||||
this.framesTextureData.add(pixels);
|
||||
return false;
|
||||
}*/
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
private static final class BakedDynBucketOverrideHandler extends ItemOverrideList
|
||||
{
|
||||
@@ -446,11 +438,8 @@ public final class ModelDynBucket implements IUnbakedModel
|
||||
|
||||
if (!model.cache.containsKey(name))
|
||||
{
|
||||
IUnbakedModel parent = model.parent.process(ImmutableMap.of("fluid", name));
|
||||
Function<ResourceLocation, TextureAtlasSprite> textureGetter;
|
||||
textureGetter = location -> Minecraft.getInstance().getTextureMap().getAtlasSprite(location.toString());
|
||||
|
||||
IBakedModel bakedModel = parent.bake(bakery, textureGetter, new SimpleModelState(model.transforms), model.format);
|
||||
ModelDynBucket parent = model.parent.withFluid(name);
|
||||
IBakedModel bakedModel = parent.bake(model.owner, bakery, ModelLoader.defaultTextureGetter(), new SimpleModelTransform(model.transforms), model.getOverrides(), new ResourceLocation("forge:bucket_override"));
|
||||
model.cache.put(name, bakedModel);
|
||||
return bakedModel;
|
||||
}
|
||||
@@ -465,20 +454,22 @@ public final class ModelDynBucket implements IUnbakedModel
|
||||
// the dynamic bucket is based on the empty bucket
|
||||
private static final class BakedDynBucket extends BakedItemModel
|
||||
{
|
||||
private final IModelConfiguration owner;
|
||||
private final ModelDynBucket parent;
|
||||
private final Map<String, IBakedModel> cache; // contains all the baked models since they'll never change
|
||||
private final VertexFormat format;
|
||||
|
||||
BakedDynBucket(ModelBakery bakery,
|
||||
ModelDynBucket parent,
|
||||
IModelConfiguration owner, ModelDynBucket parent,
|
||||
ImmutableList<BakedQuad> quads,
|
||||
TextureAtlasSprite particle,
|
||||
VertexFormat format,
|
||||
ImmutableMap<TransformType, TRSRTransformation> transforms,
|
||||
ImmutableMap<TransformType, TransformationMatrix> transforms,
|
||||
Map<String, IBakedModel> cache,
|
||||
boolean untransformed)
|
||||
{
|
||||
super(quads, particle, transforms, new BakedDynBucketOverrideHandler(bakery), untransformed);
|
||||
this.owner = owner;
|
||||
this.format = format;
|
||||
this.parent = parent;
|
||||
this.cache = cache;
|
||||
|
||||
@@ -21,7 +21,6 @@ package net.minecraftforge.client.model;
|
||||
|
||||
import java.util.function.Function;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumMap;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
@@ -29,31 +28,27 @@ import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.vecmath.Matrix4f;
|
||||
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.renderer.TransformationMatrix;
|
||||
import net.minecraft.client.renderer.model.*;
|
||||
import net.minecraft.client.renderer.model.ItemCameraTransforms.TransformType;
|
||||
import net.minecraft.client.renderer.texture.ISprite;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormat;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormatElement;
|
||||
import net.minecraft.fluid.Fluid;
|
||||
import net.minecraft.fluid.Fluids;
|
||||
import net.minecraft.resources.IResourceManager;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraftforge.client.model.data.IModelData;
|
||||
import net.minecraftforge.client.model.geometry.IModelGeometry;
|
||||
import net.minecraftforge.client.model.pipeline.IVertexConsumer;
|
||||
import net.minecraftforge.client.model.pipeline.TRSRTransformer;
|
||||
import net.minecraftforge.client.model.pipeline.UnpackedBakedQuad;
|
||||
import net.minecraftforge.fluids.FluidAttributes;
|
||||
import net.minecraftforge.versions.forge.ForgeVersion;
|
||||
import net.minecraftforge.common.model.TRSRTransformation;
|
||||
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
@@ -64,9 +59,8 @@ import com.google.common.collect.ImmutableSet;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonParser;
|
||||
|
||||
public final class ModelFluid implements IUnbakedModel
|
||||
public final class ModelFluid implements IModelGeometry<ModelFluid>
|
||||
{
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
public static final ModelFluid WATER = new ModelFluid(Fluids.WATER);
|
||||
public static final ModelFluid LAVA = new ModelFluid(Fluids.LAVA);
|
||||
|
||||
@@ -78,60 +72,31 @@ public final class ModelFluid implements IUnbakedModel
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ResourceLocation> getTextures(Function<ResourceLocation, IUnbakedModel> modelGetter, Set<String> missingTextureErrors)
|
||||
public Collection<Material> getTextures(IModelConfiguration owner, Function<ResourceLocation, IUnbakedModel> modelGetter, Set<com.mojang.datafixers.util.Pair<String, String>> missingTextureErrors)
|
||||
{
|
||||
FluidAttributes attrs = fluid.getAttributes();
|
||||
return attrs.getOverlayTexture() != null
|
||||
? ImmutableSet.of(attrs.getStillTexture(), attrs.getFlowingTexture(), attrs.getOverlayTexture())
|
||||
: ImmutableSet.of(attrs.getStillTexture(), attrs.getFlowingTexture());
|
||||
return attrs.getOverlayMaterial() != null
|
||||
? ImmutableSet.of(attrs.getStillMaterial(), attrs.getFlowingMaterial(), attrs.getOverlayMaterial())
|
||||
: ImmutableSet.of(attrs.getStillMaterial(), attrs.getFlowingMaterial());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ResourceLocation> getDependencies() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public IBakedModel bake(ModelBakery bakery, Function<ResourceLocation, TextureAtlasSprite> spriteGetter, ISprite sprite, VertexFormat format)
|
||||
public IBakedModel bake(IModelConfiguration owner, ModelBakery bakery, Function<Material, TextureAtlasSprite> spriteGetter, IModelTransform sprite, ItemOverrideList overrides, ResourceLocation modelLocation)
|
||||
{
|
||||
FluidAttributes attrs = fluid.getAttributes();
|
||||
return new CachingBakedFluid(
|
||||
sprite.getState().apply(Optional.empty()),
|
||||
PerspectiveMapWrapper.getTransforms(sprite.getState()),
|
||||
format,
|
||||
sprite.func_225615_b_(),
|
||||
PerspectiveMapWrapper.getTransforms(sprite),
|
||||
modelLocation,
|
||||
attrs.getColor(),
|
||||
spriteGetter.apply(attrs.getStillTexture()),
|
||||
spriteGetter.apply(attrs.getFlowingTexture()),
|
||||
Optional.ofNullable(attrs.getOverlayTexture()).map(spriteGetter),
|
||||
spriteGetter.apply(attrs.getStillMaterial()),
|
||||
spriteGetter.apply(attrs.getFlowingMaterial()),
|
||||
Optional.ofNullable(attrs.getOverlayMaterial()).map(spriteGetter),
|
||||
attrs.isLighterThanAir(),
|
||||
null
|
||||
);
|
||||
}
|
||||
|
||||
public enum FluidLoader implements ICustomModelLoader
|
||||
{
|
||||
INSTANCE;
|
||||
|
||||
@Override
|
||||
public void onResourceManagerReload(IResourceManager resourceManager) {}
|
||||
|
||||
@Override
|
||||
public boolean accepts(ResourceLocation modelLocation)
|
||||
{
|
||||
return modelLocation.getNamespace().equals(ForgeVersion.MOD_ID) && (
|
||||
modelLocation.getPath().equals("fluid") ||
|
||||
modelLocation.getPath().equals("models/block/fluid") ||
|
||||
modelLocation.getPath().equals("models/item/fluid"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IUnbakedModel loadModel(ResourceLocation modelLocation)
|
||||
{
|
||||
return WATER;
|
||||
}
|
||||
}
|
||||
|
||||
private static final class CachingBakedFluid extends BakedFluid
|
||||
{
|
||||
private final LoadingCache<Long, BakedFluid> modelCache = CacheBuilder.newBuilder().maximumSize(200).build(new CacheLoader<Long, BakedFluid>()
|
||||
@@ -155,13 +120,13 @@ public final class ModelFluid implements IUnbakedModel
|
||||
overlaySides[i] = (key & 1) != 0;
|
||||
key >>>= 1;
|
||||
}
|
||||
return new BakedFluid(transformation, transforms, format, color, still, flowing, overlay, gas, statePresent, cornerRound, flowRound, overlaySides);
|
||||
return new BakedFluid(transformation, transforms, modelLocation, color, still, flowing, overlay, gas, statePresent, cornerRound, flowRound, overlaySides);
|
||||
}
|
||||
});
|
||||
|
||||
public CachingBakedFluid(Optional<TRSRTransformation> transformation, ImmutableMap<TransformType, TRSRTransformation> transforms, VertexFormat format, int color, TextureAtlasSprite still, TextureAtlasSprite flowing, Optional<TextureAtlasSprite> overlay, boolean gas, Optional<IModelData> stateOption)
|
||||
public CachingBakedFluid(TransformationMatrix transformation, ImmutableMap<TransformType, TransformationMatrix> transforms, ResourceLocation modelLocation, int color, TextureAtlasSprite still, TextureAtlasSprite flowing, Optional<TextureAtlasSprite> overlay, boolean gas, Optional<IModelData> stateOption)
|
||||
{
|
||||
super(transformation, transforms, format, color, still, flowing, overlay, gas, stateOption.isPresent(), getCorners(stateOption), getFlow(stateOption), getOverlay(stateOption));
|
||||
super(transformation, transforms, modelLocation, color, still, flowing, overlay, gas, stateOption.isPresent(), getCorners(stateOption), getFlow(stateOption), getOverlay(stateOption));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -270,20 +235,20 @@ public final class ModelFluid implements IUnbakedModel
|
||||
private static final int z[] = { 0, 1, 1, 0 };
|
||||
private static final float eps = 1e-3f;
|
||||
|
||||
protected final Optional<TRSRTransformation> transformation;
|
||||
protected final ImmutableMap<TransformType, TRSRTransformation> transforms;
|
||||
protected final VertexFormat format;
|
||||
protected final TransformationMatrix transformation;
|
||||
protected final ImmutableMap<TransformType, TransformationMatrix> transforms;
|
||||
protected final ResourceLocation modelLocation;
|
||||
protected final int color;
|
||||
protected final TextureAtlasSprite still, flowing;
|
||||
protected final Optional<TextureAtlasSprite> overlay;
|
||||
protected final boolean gas;
|
||||
protected final ImmutableMap<Direction, ImmutableList<BakedQuad>> faceQuads;
|
||||
|
||||
public BakedFluid(Optional<TRSRTransformation> transformation, ImmutableMap<TransformType, TRSRTransformation> transforms, VertexFormat format, int color, TextureAtlasSprite still, TextureAtlasSprite flowing, Optional<TextureAtlasSprite> overlay, boolean gas, boolean statePresent, int[] cornerRound, int flowRound, boolean[] sideOverlays)
|
||||
public BakedFluid(TransformationMatrix transformation, ImmutableMap<TransformType, TransformationMatrix> transforms, ResourceLocation modelLocation, int color, TextureAtlasSprite still, TextureAtlasSprite flowing, Optional<TextureAtlasSprite> overlay, boolean gas, boolean statePresent, int[] cornerRound, int flowRound, boolean[] sideOverlays)
|
||||
{
|
||||
this.transformation = transformation;
|
||||
this.transforms = transforms;
|
||||
this.format = format;
|
||||
this.modelLocation = modelLocation;
|
||||
this.color = color;
|
||||
this.still = still;
|
||||
this.flowing = flowing;
|
||||
@@ -401,14 +366,14 @@ public final class ModelFluid implements IUnbakedModel
|
||||
|
||||
private BakedQuad buildQuad(Direction side, TextureAtlasSprite texture, boolean flip, boolean offset, VertexParameter x, VertexParameter y, VertexParameter z, VertexParameter u, VertexParameter v)
|
||||
{
|
||||
UnpackedBakedQuad.Builder builder = new UnpackedBakedQuad.Builder(format);
|
||||
UnpackedBakedQuad.Builder builder = new UnpackedBakedQuad.Builder(DefaultVertexFormats.BLOCK);
|
||||
|
||||
builder.setQuadOrientation(side);
|
||||
builder.setTexture(texture);
|
||||
builder.setQuadTint(0);
|
||||
|
||||
boolean hasTransform = transformation.isPresent() && !transformation.get().isIdentity();
|
||||
IVertexConsumer consumer = hasTransform ? new TRSRTransformer(builder, transformation.get()) : builder;
|
||||
boolean hasTransform = !transformation.isIdentity();
|
||||
IVertexConsumer consumer = hasTransform ? new TRSRTransformer(builder, transformation) : builder;
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
@@ -426,9 +391,11 @@ public final class ModelFluid implements IUnbakedModel
|
||||
|
||||
private void putVertex(IVertexConsumer consumer, Direction side, boolean offset, float x, float y, float z, float u, float v)
|
||||
{
|
||||
for(int e = 0; e < format.getElementCount(); e++)
|
||||
VertexFormat format = DefaultVertexFormats.BLOCK;
|
||||
ImmutableList<VertexFormatElement> elements = format.func_227894_c_();
|
||||
for(int e = 0; e < elements.size(); e++)
|
||||
{
|
||||
switch(format.getElement(e).getUsage())
|
||||
switch(elements.get(e).getUsage())
|
||||
{
|
||||
case POSITION:
|
||||
float dx = offset ? side.getDirectionVec().getX() * eps : 0f;
|
||||
@@ -450,7 +417,7 @@ public final class ModelFluid implements IUnbakedModel
|
||||
consumer.put(e, offX, offY, offZ, 0f);
|
||||
break;
|
||||
case UV:
|
||||
if(format.getElement(e).getIndex() == 0)
|
||||
if(elements.get(e).getIndex() == 0)
|
||||
{
|
||||
consumer.put(e, u, v, 0f, 1f);
|
||||
break;
|
||||
@@ -500,13 +467,18 @@ public final class ModelFluid implements IUnbakedModel
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pair<? extends IBakedModel, Matrix4f> handlePerspective(TransformType type)
|
||||
public boolean doesHandlePerspectives()
|
||||
{
|
||||
return PerspectiveMapWrapper.handlePerspective(this, transforms, type);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBakedModel handlePerspective(TransformType type, MatrixStack mat)
|
||||
{
|
||||
return PerspectiveMapWrapper.handlePerspective(this, transforms, type, mat);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModelFluid process(ImmutableMap<String, String> customData)
|
||||
{
|
||||
if(!customData.containsKey("fluid")) return this;
|
||||
|
||||
@@ -19,102 +19,27 @@
|
||||
|
||||
package net.minecraftforge.client.model;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.BlockModelShapes;
|
||||
import net.minecraft.client.renderer.ItemModelMesher;
|
||||
import net.minecraft.client.renderer.Vector3f;
|
||||
import net.minecraft.client.renderer.color.BlockColors;
|
||||
import net.minecraft.client.renderer.model.BakedQuad;
|
||||
import net.minecraft.client.renderer.model.BlockPart;
|
||||
import net.minecraft.client.renderer.model.BlockPartFace;
|
||||
import net.minecraft.client.renderer.model.BlockPartRotation;
|
||||
import net.minecraft.client.renderer.model.BuiltInModel;
|
||||
import net.minecraft.client.renderer.model.FaceBakery;
|
||||
import net.minecraft.client.renderer.model.IBakedModel;
|
||||
import net.minecraft.client.renderer.model.IUnbakedModel;
|
||||
import net.minecraft.client.renderer.model.ItemCameraTransforms;
|
||||
import net.minecraft.client.renderer.model.ItemCameraTransforms.TransformType;
|
||||
import net.minecraft.client.renderer.model.ItemModelGenerator;
|
||||
import net.minecraft.client.renderer.model.ItemOverrideList;
|
||||
import net.minecraft.client.renderer.model.ModelBakery;
|
||||
import net.minecraft.client.renderer.model.BlockModel;
|
||||
import net.minecraft.client.renderer.model.BlockModelDefinition;
|
||||
import net.minecraft.client.renderer.model.ModelResourceLocation;
|
||||
import net.minecraft.client.renderer.model.ModelRotation;
|
||||
import net.minecraft.client.renderer.model.MultipartBakedModel;
|
||||
import net.minecraft.client.renderer.model.SimpleBakedModel;
|
||||
import net.minecraft.client.renderer.model.Variant;
|
||||
import net.minecraft.client.renderer.model.VariantList;
|
||||
import net.minecraft.client.renderer.model.WeightedBakedModel;
|
||||
import net.minecraft.client.renderer.model.multipart.Multipart;
|
||||
import net.minecraft.client.renderer.model.multipart.Selector;
|
||||
import net.minecraft.client.renderer.texture.ISprite;
|
||||
import net.minecraft.client.renderer.model.*;
|
||||
import net.minecraft.client.renderer.texture.MissingTextureSprite;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.renderer.texture.AtlasTexture;
|
||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormat;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.profiler.IProfiler;
|
||||
import net.minecraft.resources.IResourceManager;
|
||||
import net.minecraft.state.StateContainer;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.client.model.animation.AnimationItemOverrideList;
|
||||
import net.minecraftforge.client.model.animation.ModelBlockAnimation;
|
||||
import net.minecraftforge.client.model.data.IModelData;
|
||||
import net.minecraftforge.common.ForgeMod;
|
||||
import net.minecraftforge.common.model.IModelState;
|
||||
import net.minecraftforge.common.model.Models;
|
||||
import net.minecraftforge.common.model.TRSRTransformation;
|
||||
import net.minecraftforge.common.model.animation.IClip;
|
||||
import net.minecraftforge.common.property.Properties;
|
||||
import net.minecraftforge.fml.client.ClientModLoader;
|
||||
import net.minecraftforge.logging.ModelLoaderErrorMessage;
|
||||
import net.minecraftforge.registries.IRegistryDelegate;
|
||||
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import java.util.function.Function;
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.base.Preconditions;
|
||||
import java.util.Optional;
|
||||
import java.util.Random;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.StreamSupport;
|
||||
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
import com.google.common.collect.HashMultimap;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Multimaps;
|
||||
import com.google.common.collect.Sets;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import static net.minecraftforge.fml.Logging.MODELLOADING;
|
||||
@@ -122,25 +47,29 @@ import static net.minecraftforge.fml.Logging.MODELLOADING;
|
||||
public final class ModelLoader extends ModelBakery
|
||||
{
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
private final Map<ModelResourceLocation, IUnbakedModel> stateModels = Maps.newHashMap();
|
||||
private final Map<ModelResourceLocation, BlockModelDefinition> multipartDefinitions = Maps.newHashMap();
|
||||
private final Map<BlockModelDefinition, IUnbakedModel> multipartModels = Maps.newHashMap();
|
||||
private final Map<ResourceLocation, Exception> loadingExceptions = Maps.newHashMap();
|
||||
private IUnbakedModel missingModel = null;
|
||||
|
||||
private boolean isLoading = false;
|
||||
|
||||
private static ModelLoader instance;
|
||||
|
||||
@Nullable
|
||||
public static ModelLoader instance()
|
||||
{
|
||||
return instance;
|
||||
}
|
||||
|
||||
public boolean isLoading()
|
||||
{
|
||||
return isLoading;
|
||||
}
|
||||
|
||||
public ModelLoader(IResourceManager manager, AtlasTexture map, BlockColors colours, IProfiler profiler)
|
||||
public ModelLoader(IResourceManager manager, BlockColors colours, IProfiler profiler, int p_i226056_4_)
|
||||
{
|
||||
super(manager, map, colours, false);
|
||||
VanillaLoader.INSTANCE.setLoader(this);
|
||||
VariantLoader.INSTANCE.setLoader(this);
|
||||
ModelLoaderRegistry.clearModelCache(manager);
|
||||
processLoading(profiler);
|
||||
super(manager, colours, false);
|
||||
instance = this;
|
||||
processLoading(profiler, p_i226056_4_);
|
||||
}
|
||||
|
||||
private static Set<ResourceLocation> specialModels = new HashSet<>();
|
||||
@@ -178,420 +107,13 @@ public final class ModelLoader extends ModelBakery
|
||||
return new ResourceLocation(model.getNamespace(), model.getPath() + ".json");
|
||||
}
|
||||
|
||||
private final class VanillaModelWrapper implements IUnbakedModel
|
||||
{
|
||||
private final ResourceLocation location;
|
||||
private final BlockModel model;
|
||||
private final boolean uvlock;
|
||||
private final ModelBlockAnimation animation;
|
||||
|
||||
public VanillaModelWrapper(ResourceLocation location, BlockModel model, boolean uvlock, ModelBlockAnimation animation)
|
||||
{
|
||||
this.location = location;
|
||||
this.model = model;
|
||||
this.uvlock = uvlock;
|
||||
this.animation = animation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ResourceLocation> getDependencies()
|
||||
{
|
||||
Set<ResourceLocation> set = Sets.newHashSet();
|
||||
for(ResourceLocation dep : model.getDependencies())
|
||||
{
|
||||
if(!location.equals(dep))
|
||||
{
|
||||
set.add(dep);
|
||||
// TODO: check if this can go somewhere else, random access to global things is bad
|
||||
stateModels.put(getInventoryVariant(dep.toString()), ModelLoaderRegistry.getModelOrLogError(dep, "Could not load override model " + dep + " for model " + location));
|
||||
}
|
||||
}
|
||||
if(model.getParentLocation() != null && !model.getParentLocation().getPath().startsWith("builtin/"))
|
||||
{
|
||||
set.add(model.getParentLocation());
|
||||
}
|
||||
return ImmutableSet.copyOf(set);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ResourceLocation> getTextures(Function<ResourceLocation, IUnbakedModel> modelGetter, Set<String> missingTextureErrors)
|
||||
{
|
||||
// setting parent here to make textures resolve properly
|
||||
if(model.getParentLocation() != null)
|
||||
{
|
||||
if(model.getParentLocation().getPath().equals("builtin/generated"))
|
||||
{
|
||||
model.parent = MODEL_GENERATED;
|
||||
}
|
||||
else
|
||||
{
|
||||
IUnbakedModel parent = ModelLoaderRegistry.getModelOrLogError(model.getParentLocation(), "Could not load vanilla model parent '" + model.getParentLocation() + "' for '" + model);
|
||||
if(parent instanceof VanillaModelWrapper)
|
||||
{
|
||||
model.parent = ((VanillaModelWrapper) parent).model;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new IllegalStateException("vanilla model '" + model + "' can't have non-vanilla parent");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ImmutableSet.Builder<ResourceLocation> builder = ImmutableSet.builder();
|
||||
|
||||
if(model == ModelBakery.MODEL_GENERATED)
|
||||
{
|
||||
for(String s : ItemModelGenerator.LAYERS)
|
||||
{
|
||||
String r = model.resolveTextureName(s);
|
||||
ResourceLocation loc = new ResourceLocation(r);
|
||||
if(!r.equals(s))
|
||||
{
|
||||
builder.add(loc);
|
||||
}
|
||||
}
|
||||
}
|
||||
for(String s : model.textures.values())
|
||||
{
|
||||
if(!s.startsWith("#"))
|
||||
{
|
||||
builder.add(new ResourceLocation(s));
|
||||
}
|
||||
}
|
||||
|
||||
if (model.parent != null)
|
||||
builder.addAll(model.parent.getTextures(modelGetter, missingTextureErrors));
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public IBakedModel bake(ModelBakery bakery, Function<ResourceLocation, TextureAtlasSprite> spriteGetter, ISprite sprite, VertexFormat format)
|
||||
{
|
||||
return VanillaLoader.INSTANCE.modelCache.getUnchecked(new BakedModelCacheKey(this, bakery, spriteGetter, sprite.getState(), uvlock, format));
|
||||
}
|
||||
|
||||
public IBakedModel bakeImpl(ModelBakery bakery, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter, IModelState state, boolean uvlock, VertexFormat format)
|
||||
{
|
||||
if(!Attributes.moreSpecific(format, Attributes.DEFAULT_BAKED_FORMAT))
|
||||
{
|
||||
throw new IllegalArgumentException("can't bake vanilla models to the format that doesn't fit into the default one: " + format);
|
||||
}
|
||||
BlockModel model = this.model;
|
||||
if(model == null) return getMissingModel().bake(bakery, bakedTextureGetter, new BasicState(getMissingModel().getDefaultState(), uvlock), format);
|
||||
|
||||
List<TRSRTransformation> newTransforms = Lists.newArrayList();
|
||||
for(int i = 0; i < model.getElements().size(); i++)
|
||||
{
|
||||
BlockPart part = model.getElements().get(i);
|
||||
newTransforms.add(animation.getPartTransform(state, part, i));
|
||||
}
|
||||
|
||||
ItemCameraTransforms transforms = model.getAllTransforms();
|
||||
Map<TransformType, TRSRTransformation> tMap = Maps.newEnumMap(TransformType.class);
|
||||
tMap.putAll(PerspectiveMapWrapper.getTransforms(transforms));
|
||||
tMap.putAll(PerspectiveMapWrapper.getTransforms(state));
|
||||
IModelState perState = new SimpleModelState(ImmutableMap.copyOf(tMap), state.apply(Optional.empty()));
|
||||
|
||||
if(model == ModelBakery.MODEL_GENERATED)
|
||||
{
|
||||
return new ItemLayerModel(bakery, model, format).bake(bakery, bakedTextureGetter, new BasicState(perState, uvlock), format);
|
||||
}
|
||||
TextureAtlasSprite textureatlassprite = bakedTextureGetter.apply(new ResourceLocation(model.resolveTextureName("particle")));
|
||||
if(model == ModelBakery.MODEL_ENTITY) return new BuiltInModel(transforms, model.getOverrides(bakery, model, bakedTextureGetter, format), textureatlassprite);
|
||||
return bakeNormal(bakery, model, perState, state, newTransforms, format, bakedTextureGetter, uvlock);
|
||||
}
|
||||
|
||||
private IBakedModel bakeNormal(ModelBakery bakery, BlockModel model, IModelState perState, final IModelState modelState, List<TRSRTransformation> newTransforms, final VertexFormat format, final Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter, boolean uvLocked)
|
||||
{
|
||||
final TRSRTransformation baseState = modelState.apply(Optional.empty()).orElse(TRSRTransformation.identity());
|
||||
TextureAtlasSprite particle = bakedTextureGetter.apply(new ResourceLocation(model.resolveTextureName("particle")));
|
||||
SimpleBakedModel.Builder builder = (new SimpleBakedModel.Builder(model, model.getOverrides(bakery, model, bakedTextureGetter, format))).setTexture(particle);
|
||||
for(int i = 0; i < model.getElements().size(); i++)
|
||||
{
|
||||
if(modelState.apply(Optional.of(Models.getHiddenModelPart(ImmutableList.of(Integer.toString(i))))).isPresent())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
BlockPart part = model.getElements().get(i);
|
||||
TRSRTransformation transformation = baseState;
|
||||
if(newTransforms.get(i) != null)
|
||||
{
|
||||
transformation = transformation.compose(newTransforms.get(i));
|
||||
BlockPartRotation rot = part.partRotation;
|
||||
if(rot == null) rot = new BlockPartRotation(new Vector3f(), Direction.Axis.Y, 0, false);
|
||||
part = new BlockPart(part.positionFrom, part.positionTo, part.mapFaces, rot, part.shade);
|
||||
}
|
||||
for(Map.Entry<Direction, BlockPartFace> e : part.mapFaces.entrySet())
|
||||
{
|
||||
TextureAtlasSprite textureatlassprite1 = bakedTextureGetter.apply(new ResourceLocation(model.resolveTextureName(e.getValue().texture)));
|
||||
|
||||
if (e.getValue().cullFace == null || !TRSRTransformation.isInteger(transformation.getMatrixVec()))
|
||||
{
|
||||
builder.addGeneralQuad(BlockModel.makeBakedQuad(part, e.getValue(), textureatlassprite1, e.getKey(), new BasicState(transformation, uvLocked)));
|
||||
}
|
||||
else
|
||||
{
|
||||
builder.addFaceQuad(baseState.rotateTransform(e.getValue().cullFace), BlockModel.makeBakedQuad(part, e.getValue(), textureatlassprite1, e.getKey(), new BasicState(transformation, uvLocked)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new PerspectiveMapWrapper(builder.build(), perState)
|
||||
{
|
||||
private final ItemOverrideList overrides = new AnimationItemOverrideList(bakery, VanillaModelWrapper.this, modelState, format, bakedTextureGetter, super.getOverrides());
|
||||
|
||||
@Override
|
||||
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, Random rand, IModelData modelData)
|
||||
{
|
||||
IModelState newState = modelData.getData(Properties.AnimationProperty);
|
||||
if(newState != null)
|
||||
{
|
||||
return VanillaModelWrapper.this.bake(bakery, bakedTextureGetter, new ModelStateComposition(modelState, newState, uvlock), format).getQuads(state, side, rand, modelData);
|
||||
}
|
||||
return super.getQuads(state, side, rand);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemOverrideList getOverrides()
|
||||
{
|
||||
return overrides;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public VanillaModelWrapper retexture(ImmutableMap<String, String> textures)
|
||||
{
|
||||
if (textures.isEmpty())
|
||||
return this;
|
||||
|
||||
List<BlockPart> elements = Lists.newArrayList(); //We have to duplicate this so we can edit it below.
|
||||
for (BlockPart part : this.model.getElements())
|
||||
{
|
||||
elements.add(new BlockPart(part.positionFrom, part.positionTo, Maps.newHashMap(part.mapFaces), part.partRotation, part.shade));
|
||||
}
|
||||
|
||||
BlockModel newModel = new BlockModel(this.model.getParentLocation(), elements,
|
||||
Maps.newHashMap(this.model.textures), this.model.isAmbientOcclusion(), this.model.isGui3d(), //New Textures man VERY IMPORTANT
|
||||
model.getAllTransforms(), Lists.newArrayList(model.getOverrides()));
|
||||
newModel.name = this.model.name;
|
||||
newModel.parent = this.model.parent;
|
||||
|
||||
Set<String> removed = Sets.newHashSet();
|
||||
|
||||
for (Entry<String, String> e : textures.entrySet())
|
||||
{
|
||||
if ("".equals(e.getValue()))
|
||||
{
|
||||
removed.add(e.getKey());
|
||||
newModel.textures.remove(e.getKey());
|
||||
}
|
||||
else
|
||||
newModel.textures.put(e.getKey(), e.getValue());
|
||||
}
|
||||
|
||||
// Map the model's texture references as if it was the parent of a model with the retexture map as its textures.
|
||||
Map<String, String> remapped = Maps.newHashMap();
|
||||
|
||||
for (Entry<String, String> e : newModel.textures.entrySet())
|
||||
{
|
||||
if (e.getValue().startsWith("#"))
|
||||
{
|
||||
String key = e.getValue().substring(1);
|
||||
if (newModel.textures.containsKey(key))
|
||||
remapped.put(e.getKey(), newModel.textures.get(key));
|
||||
}
|
||||
}
|
||||
|
||||
newModel.textures.putAll(remapped);
|
||||
|
||||
//Remove any faces that use a null texture, this is for performance reasons, also allows some cool layering stuff.
|
||||
for (BlockPart part : newModel.getElements())
|
||||
{
|
||||
part.mapFaces.entrySet().removeIf(entry -> removed.contains(entry.getValue().texture));
|
||||
}
|
||||
|
||||
return new VanillaModelWrapper(location, newModel, uvlock, animation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<? extends IClip> getClip(String name)
|
||||
{
|
||||
if(animation.getClips().containsKey(name))
|
||||
{
|
||||
return Optional.ofNullable(animation.getClips().get(name));
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public VanillaModelWrapper smoothLighting(boolean value)
|
||||
{
|
||||
if(model.ambientOcclusion == value)
|
||||
{
|
||||
return this;
|
||||
}
|
||||
BlockModel newModel = new BlockModel(model.getParentLocation(), model.getElements(), model.textures, value, model.isGui3d(), model.getAllTransforms(), Lists.newArrayList(model.getOverrides()));
|
||||
newModel.parent = model.parent;
|
||||
newModel.name = model.name;
|
||||
return new VanillaModelWrapper(location, newModel, uvlock, animation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VanillaModelWrapper gui3d(boolean value)
|
||||
{
|
||||
if(model.isGui3d() == value)
|
||||
{
|
||||
return this;
|
||||
}
|
||||
BlockModel newModel = new BlockModel(model.getParentLocation(), model.getElements(), model.textures, model.ambientOcclusion, value, model.getAllTransforms(), Lists.newArrayList(model.getOverrides()));
|
||||
newModel.parent = model.parent;
|
||||
newModel.name = model.name;
|
||||
return new VanillaModelWrapper(location, newModel, uvlock, animation);
|
||||
}
|
||||
}
|
||||
|
||||
private static final class WeightedRandomModel implements IUnbakedModel
|
||||
{
|
||||
private final List<Variant> variants;
|
||||
private final List<ResourceLocation> locations;
|
||||
private final Set<ResourceLocation> textures;
|
||||
private final List<IUnbakedModel> models;
|
||||
private final IModelState defaultState;
|
||||
|
||||
public WeightedRandomModel(ResourceLocation parent, VariantList variants) throws Exception
|
||||
{
|
||||
this.variants = variants.getVariantList();
|
||||
this.locations = new ArrayList<>();
|
||||
this.textures = Sets.newHashSet();
|
||||
this.models = new ArrayList<>();
|
||||
ImmutableList.Builder<Pair<IUnbakedModel, IModelState>> builder = ImmutableList.builder();
|
||||
for (Variant v : this.variants)
|
||||
{
|
||||
ResourceLocation loc = v.getModelLocation();
|
||||
locations.add(loc);
|
||||
|
||||
/*
|
||||
* Vanilla eats this, which makes it only show variants that have models.
|
||||
* But that doesn't help debugging, so throw the exception
|
||||
*/
|
||||
IUnbakedModel model;
|
||||
if(loc.equals(MODEL_MISSING))
|
||||
{
|
||||
// explicit missing location, happens if blockstate has "model"=null
|
||||
model = ModelLoaderRegistry.getMissingModel();
|
||||
}
|
||||
else
|
||||
{
|
||||
model = ModelLoaderRegistry.getModel(loc);
|
||||
}
|
||||
|
||||
for(ResourceLocation location : model.getDependencies())
|
||||
{
|
||||
ModelLoaderRegistry.getModelOrMissing(location);
|
||||
}
|
||||
//FMLLog.getLogger().error("Exception resolving indirect dependencies for model" + loc, e);
|
||||
textures.addAll(model.getTextures(ModelLoader.defaultModelGetter(), new HashSet<>())); // Kick this, just in case.
|
||||
|
||||
models.add(model);
|
||||
|
||||
IModelState modelDefaultState = model.getDefaultState();
|
||||
Preconditions.checkNotNull(modelDefaultState, "Model %s returned null as default state", loc);
|
||||
builder.add(Pair.of(model, new ModelStateComposition(v.getState(), modelDefaultState, v.isUvLock())));
|
||||
}
|
||||
|
||||
if (models.size() == 0) //If all variants are missing, add one with the missing model and default rotation.
|
||||
{
|
||||
// FIXME: log this?
|
||||
IUnbakedModel missing = ModelLoaderRegistry.getMissingModel();
|
||||
models.add(missing);
|
||||
builder.add(Pair.of(missing, TRSRTransformation.identity()));
|
||||
}
|
||||
|
||||
defaultState = new MultiModelState(builder.build());
|
||||
}
|
||||
|
||||
private WeightedRandomModel(List<Variant> variants, List<ResourceLocation> locations, Set<ResourceLocation> textures, List<IUnbakedModel> models, IModelState defaultState)
|
||||
{
|
||||
this.variants = variants;
|
||||
this.locations = locations;
|
||||
this.textures = textures;
|
||||
this.models = models;
|
||||
this.defaultState = defaultState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ResourceLocation> getDependencies()
|
||||
{
|
||||
return ImmutableList.copyOf(locations);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ResourceLocation> getTextures(Function<ResourceLocation, IUnbakedModel> modelGetter, Set<String> missingTextureErrors)
|
||||
{
|
||||
return ImmutableSet.copyOf(textures);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public IBakedModel bake(ModelBakery bakery, Function<ResourceLocation, TextureAtlasSprite> spriteGetter, ISprite sprite, VertexFormat format)
|
||||
{
|
||||
if(!Attributes.moreSpecific(format, Attributes.DEFAULT_BAKED_FORMAT))
|
||||
{
|
||||
throw new IllegalArgumentException("can't bake vanilla weighted models to the format that doesn't fit into the default one: " + format);
|
||||
}
|
||||
if(variants.size() == 1)
|
||||
{
|
||||
IUnbakedModel model = models.get(0);
|
||||
return model.bake(bakery, spriteGetter, new BasicState(MultiModelState.getPartState(sprite.getState(), model, 0), sprite.isUvLock()), format);
|
||||
}
|
||||
WeightedBakedModel.Builder builder = new WeightedBakedModel.Builder();
|
||||
for(int i = 0; i < variants.size(); i++)
|
||||
{
|
||||
IUnbakedModel model = models.get(i);
|
||||
builder.add(model.bake(bakery, spriteGetter, new BasicState(MultiModelState.getPartState(sprite.getState(), model, i), sprite.isUvLock()), format), variants.get(i).getWeight());
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IModelState getDefaultState()
|
||||
{
|
||||
return defaultState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WeightedRandomModel retexture(ImmutableMap<String, String> textures)
|
||||
{
|
||||
if (textures.isEmpty())
|
||||
return this;
|
||||
|
||||
// rebuild the texture list taking into account new textures
|
||||
Set<ResourceLocation> modelTextures = Sets.newHashSet();
|
||||
// also recreate the MultiModelState so IModelState data is properly applied to the retextured model
|
||||
ImmutableList.Builder<Pair<IUnbakedModel, IModelState>> builder = ImmutableList.builder();
|
||||
List<IUnbakedModel> retexturedModels = Lists.newArrayList();
|
||||
for(int i = 0; i < this.variants.size(); i++)
|
||||
{
|
||||
IUnbakedModel retextured = this.models.get(i).retexture(textures);
|
||||
modelTextures.addAll(retextured.getTextures(ModelLoader.defaultModelGetter(), new HashSet<>()));
|
||||
retexturedModels.add(retextured);
|
||||
builder.add(Pair.of(retextured, this.variants.get(i).getState()));
|
||||
}
|
||||
|
||||
return new WeightedRandomModel(this.variants, this.locations, modelTextures, retexturedModels, new MultiModelState(builder.build()));
|
||||
}
|
||||
}
|
||||
|
||||
protected IUnbakedModel getMissingModel()
|
||||
{
|
||||
if (missingModel == null)
|
||||
{
|
||||
try
|
||||
{
|
||||
missingModel = VanillaLoader.INSTANCE.loadModel(new ResourceLocation(MODEL_MISSING.getNamespace(), MODEL_MISSING.getPath()));
|
||||
missingModel = getUnbakedModel(MODEL_MISSING);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
@@ -601,122 +123,49 @@ public final class ModelLoader extends ModelBakery
|
||||
return missingModel;
|
||||
}
|
||||
|
||||
protected final class BakedModelCacheKey
|
||||
/**
|
||||
* Use this if you don't care about the exception and want some model anyway.
|
||||
*/
|
||||
public IUnbakedModel getModelOrMissing(ResourceLocation location)
|
||||
{
|
||||
private final VanillaModelWrapper model;
|
||||
private final ModelBakery bakery;
|
||||
private final Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter;
|
||||
private final IModelState state;
|
||||
private final boolean uvlock;
|
||||
private final VertexFormat format;
|
||||
|
||||
public BakedModelCacheKey(VanillaModelWrapper model, ModelBakery bakery, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter, IModelState state, boolean uvlock, VertexFormat format)
|
||||
try
|
||||
{
|
||||
this.model = model;
|
||||
this.bakery = bakery;
|
||||
this.bakedTextureGetter = bakedTextureGetter;
|
||||
this.state = state;
|
||||
this.uvlock = uvlock;
|
||||
this.format = format;
|
||||
return getUnbakedModel(location);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o)
|
||||
catch(Exception e)
|
||||
{
|
||||
if (this == o)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
BakedModelCacheKey that = (BakedModelCacheKey) o;
|
||||
return Objects.equal(model, that.model) && Objects.equal(bakery, that.bakery) && Objects.equal(bakedTextureGetter, that.bakedTextureGetter) && Objects.equal(state, that.state) && uvlock == that.uvlock && Objects.equal(format, that.format);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
return Objects.hashCode(model, state, format, bakedTextureGetter);
|
||||
return getMissingModel();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adapter from the vanilla json model loader to a custom model loader
|
||||
* Use this if you want the model, but need to log the error.
|
||||
*/
|
||||
protected static enum VanillaLoader implements ICustomModelLoader
|
||||
public IUnbakedModel getModelOrLogError(ResourceLocation location, String error)
|
||||
{
|
||||
INSTANCE;
|
||||
|
||||
@Nullable
|
||||
private ModelLoader loader;
|
||||
private LoadingCache<BakedModelCacheKey, IBakedModel> modelCache = CacheBuilder.newBuilder().maximumSize(50).expireAfterWrite(100, TimeUnit.MILLISECONDS).build(new CacheLoader<BakedModelCacheKey, IBakedModel>() {
|
||||
@Override
|
||||
public IBakedModel load(BakedModelCacheKey key) throws Exception
|
||||
{
|
||||
return key.model.bakeImpl(key.bakery, key.bakedTextureGetter, key.state, key.uvlock, key.format);
|
||||
}
|
||||
});
|
||||
|
||||
void setLoader(ModelLoader loader)
|
||||
try
|
||||
{
|
||||
this.loader = loader;
|
||||
return getUnbakedModel(location);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
ModelLoader getLoader()
|
||||
catch(Exception e)
|
||||
{
|
||||
return loader;
|
||||
}
|
||||
|
||||
// NOOP, handled by ModelLoader itself
|
||||
@Override
|
||||
public void onResourceManagerReload(IResourceManager resourceManager) {}
|
||||
|
||||
@Override
|
||||
public boolean accepts(ResourceLocation modelLocation)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IUnbakedModel loadModel(ResourceLocation modelLocation) throws Exception
|
||||
{
|
||||
if(modelLocation.equals(MODEL_MISSING) && loader.missingModel != null)
|
||||
{
|
||||
return loader.getMissingModel();
|
||||
}
|
||||
|
||||
String trimmedPath = modelLocation.getPath();
|
||||
if(modelLocation.getPath().startsWith("models/"))
|
||||
{
|
||||
trimmedPath = trimmedPath.substring("models/".length());
|
||||
}
|
||||
ResourceLocation armatureLocation = new ResourceLocation(modelLocation.getNamespace(), "armatures/" + trimmedPath + ".json");
|
||||
ModelBlockAnimation animation = ModelBlockAnimation.loadVanillaAnimation(loader.resourceManager, armatureLocation);
|
||||
|
||||
ResourceLocation trimmedLocation = new ResourceLocation(modelLocation.getNamespace(), trimmedPath);
|
||||
BlockModel model = loader.loadModel(trimmedLocation);
|
||||
IUnbakedModel iModel = loader.new VanillaModelWrapper(modelLocation, model, false, animation);
|
||||
if(loader.missingModel == null && modelLocation.equals(MODEL_MISSING))
|
||||
{
|
||||
loader.missingModel = iModel;
|
||||
}
|
||||
return iModel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "VanillaLoader.INSTANCE";
|
||||
LOGGER.error(error, e);
|
||||
return getMissingModel();
|
||||
}
|
||||
}
|
||||
|
||||
// Temporary to compile things
|
||||
public static final class White {
|
||||
public static final ResourceLocation LOCATION = new ResourceLocation("white");
|
||||
public static final TextureAtlasSprite INSTANCE = MissingTextureSprite.func_217790_a();
|
||||
private static TextureAtlasSprite instance = null;
|
||||
public static final TextureAtlasSprite instance()
|
||||
{
|
||||
if (instance == null)
|
||||
{
|
||||
instance = new Material(AtlasTexture.LOCATION_BLOCKS_TEXTURE, LOCATION).func_229314_c_();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -762,7 +211,7 @@ public final class ModelLoader extends ModelBakery
|
||||
}
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public static class ItemLoadingException extends ModelLoaderRegistry.LoaderException
|
||||
public static class ItemLoadingException extends ModelLoadingException
|
||||
{
|
||||
private final Exception normalException;
|
||||
private final Exception blockstateException;
|
||||
@@ -808,66 +257,18 @@ public final class ModelLoader extends ModelBakery
|
||||
}
|
||||
*/
|
||||
|
||||
private static enum DefaultTextureGetter implements Function<ResourceLocation, TextureAtlasSprite>
|
||||
{
|
||||
INSTANCE;
|
||||
|
||||
@Override
|
||||
public TextureAtlasSprite apply(ResourceLocation location)
|
||||
{
|
||||
return Minecraft.getInstance().getTextureMap().getAtlasSprite(location.toString());
|
||||
}
|
||||
}
|
||||
|
||||
private static final Function<ResourceLocation, IUnbakedModel> DEFAULT_MODEL_GETTER = ModelLoaderRegistry::getModelOrMissing;
|
||||
private static final Function<ResourceLocation, IUnbakedModel> DEFAULT_MODEL_GETTER = (rl) -> ModelLoader.instance().getModelOrMissing(rl);
|
||||
|
||||
/**
|
||||
* Get the default texture getter the models will be baked with.
|
||||
*/
|
||||
public static Function<ResourceLocation, TextureAtlasSprite> defaultTextureGetter()
|
||||
public static Function<Material, TextureAtlasSprite> defaultTextureGetter()
|
||||
{
|
||||
return DefaultTextureGetter.INSTANCE;
|
||||
return Material::func_229314_c_;
|
||||
}
|
||||
|
||||
public static Function<ResourceLocation, IUnbakedModel> defaultModelGetter()
|
||||
{
|
||||
return DEFAULT_MODEL_GETTER;
|
||||
}
|
||||
|
||||
/**
|
||||
* Exposes the blockstate json loader as a custom model loader
|
||||
*/
|
||||
protected static enum VariantLoader implements ICustomModelLoader
|
||||
{
|
||||
INSTANCE;
|
||||
|
||||
private ModelLoader loader;
|
||||
|
||||
void setLoader(ModelLoader loader)
|
||||
{
|
||||
this.loader = loader;
|
||||
}
|
||||
|
||||
// NOOP, handled in loader
|
||||
@Override
|
||||
public void onResourceManagerReload(IResourceManager resourceManager) {}
|
||||
|
||||
@Override
|
||||
public boolean accepts(ResourceLocation modelLocation)
|
||||
{
|
||||
return modelLocation instanceof ModelResourceLocation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IUnbakedModel loadModel(ResourceLocation modelLocation)
|
||||
{
|
||||
return loader.getUnbakedModel(modelLocation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "VariantLoader.INSTANCE";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,255 +19,345 @@
|
||||
|
||||
package net.minecraftforge.client.model;
|
||||
|
||||
import java.util.Deque;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Queues;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
import com.google.gson.*;
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.model.IUnbakedModel;
|
||||
import net.minecraft.client.renderer.model.ModelResourceLocation;
|
||||
import net.minecraft.client.renderer.TransformationMatrix;
|
||||
import net.minecraft.client.renderer.model.*;
|
||||
import net.minecraft.client.renderer.texture.AtlasTexture;
|
||||
import net.minecraft.client.renderer.texture.MissingTextureSprite;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.resources.IReloadableResourceManager;
|
||||
import net.minecraft.resources.IResourceManager;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.JSONUtils;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.client.model.ModelLoader.VanillaLoader;
|
||||
import net.minecraftforge.client.model.ModelLoader.VariantLoader;
|
||||
import net.minecraftforge.client.model.b3d.B3DLoader;
|
||||
import net.minecraftforge.client.model.composite.CompositeModel;
|
||||
import net.minecraftforge.client.model.geometry.IModelGeometry;
|
||||
import net.minecraftforge.client.model.geometry.ISimpleModelGeometry;
|
||||
import net.minecraftforge.client.model.obj.OBJLoader;
|
||||
import net.minecraftforge.common.animation.ITimeValue;
|
||||
import net.minecraftforge.common.model.animation.AnimationStateMachine;
|
||||
import net.minecraftforge.common.model.animation.IAnimationStateMachine;
|
||||
import net.minecraftforge.common.model.TransformationHelper;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Central hub for custom model loaders.
|
||||
*/
|
||||
public class ModelLoaderRegistry
|
||||
{
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
|
||||
private static final Set<ICustomModelLoader> loaders = Sets.newHashSet();
|
||||
private static final Map<ResourceLocation, IUnbakedModel> cache = Maps.newHashMap();
|
||||
private static final Deque<ResourceLocation> loadingModels = Queues.newArrayDeque();
|
||||
|
||||
private static IResourceManager manager;
|
||||
private static final Map<ResourceLocation, IModelLoader<?>> loaders = Maps.newHashMap();
|
||||
|
||||
// Forge built-in loaders
|
||||
public static void init()
|
||||
{
|
||||
registerLoader(B3DLoader.INSTANCE);
|
||||
registerLoader(OBJLoader.INSTANCE);
|
||||
registerLoader(ModelFluid.FluidLoader.INSTANCE);
|
||||
registerLoader(ItemLayerModel.Loader.INSTANCE);
|
||||
registerLoader(MultiLayerModel.Loader.INSTANCE);
|
||||
registerLoader(ModelDynBucket.LoaderDynBucket.INSTANCE);
|
||||
registerLoader(new ResourceLocation("forge:obj"), OBJLoader.INSTANCE);
|
||||
registerLoader(new ResourceLocation("forge:bucket"), ModelDynBucket.LoaderDynBucket2.INSTANCE);
|
||||
registerLoader(new ResourceLocation("forge:composite"), CompositeModel.Loader.INSTANCE);
|
||||
registerLoader(new ResourceLocation("minecraft:elements"), VanillaProxy.Loader.INSTANCE);
|
||||
|
||||
// TODO: Implement as new model loaders
|
||||
//registerLoader(new ResourceLocation("forge:b3d"), new ModelLoaderAdapter(B3DLoader.INSTANCE));
|
||||
//registerLoader(new ResourceLocation("forge:fluid"), new ModelLoaderAdapter(ModelFluid.FluidLoader.INSTANCE));
|
||||
//registerLoader(new ResourceLocation("forge:multi-layer"), new ModelLoaderAdapter(MultiLayerModel.Loader.INSTANCE));
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes system aware of your loader.
|
||||
*/
|
||||
public static void registerLoader(ICustomModelLoader loader)
|
||||
public static void registerLoader(ResourceLocation id, IModelLoader<?> loader)
|
||||
{
|
||||
loaders.add(loader);
|
||||
loaders.put(id, loader);
|
||||
((IReloadableResourceManager) Minecraft.getInstance().getResourceManager()).addReloadListener(loader);
|
||||
// FIXME: Existing model loaders expect to receive a call as soon as they are registered, which was the old behaviour pre-1.13
|
||||
// without this, their manager field is never initialized.
|
||||
loader.onResourceManagerReload(Minecraft.getInstance().getResourceManager());
|
||||
}
|
||||
|
||||
public static boolean loaded(ResourceLocation location)
|
||||
public static IModelGeometry<?> getModel(ResourceLocation loaderId, JsonDeserializationContext deserializationContext, JsonObject data)
|
||||
{
|
||||
return cache.containsKey(location);
|
||||
}
|
||||
|
||||
|
||||
public static ResourceLocation getActualLocation(ResourceLocation location)
|
||||
{
|
||||
if(location instanceof ModelResourceLocation) return location;
|
||||
if(location.getPath().startsWith("builtin/")) return location;
|
||||
return new ResourceLocation(location.getNamespace(), "models/" + location.getPath());
|
||||
}
|
||||
|
||||
/**
|
||||
* Primary method to get IModel instances.
|
||||
* @param location The path to load, either:
|
||||
* - Pure {@link ResourceLocation}. "models/" will be prepended to the path, then
|
||||
* the path is passed to the {@link ICustomModelLoader}s, which may further modify
|
||||
* the path before asking resource packs for it. For example, the {@link VanillaLoader}
|
||||
* appends ".json" before looking the model up.
|
||||
* - {@link ModelResourceLocation}. The blockstate system will load the model, using {@link VariantLoader}.
|
||||
*/
|
||||
public static IUnbakedModel getModel(ResourceLocation location) throws Exception
|
||||
{
|
||||
IUnbakedModel model;
|
||||
|
||||
IUnbakedModel cached = cache.get(location);
|
||||
if (cached != null) return cached;
|
||||
|
||||
for(ResourceLocation loading : loadingModels)
|
||||
{
|
||||
if(location.getClass() == loading.getClass() && location.equals(loading))
|
||||
{
|
||||
throw new LoaderException("circular model dependencies, stack: [" + Joiner.on(", ").join(loadingModels) + "]");
|
||||
}
|
||||
}
|
||||
loadingModels.addLast(location);
|
||||
try
|
||||
{
|
||||
ResourceLocation actual = getActualLocation(location);
|
||||
ICustomModelLoader accepted = null;
|
||||
for(ICustomModelLoader loader : loaders)
|
||||
{
|
||||
try
|
||||
{
|
||||
if(loader.accepts(actual))
|
||||
{
|
||||
if(accepted != null)
|
||||
{
|
||||
throw new LoaderException(String.format("2 loaders (%s and %s) want to load the same model %s", accepted, loader, location));
|
||||
}
|
||||
accepted = loader;
|
||||
}
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
throw new LoaderException(String.format("Exception checking if model %s can be loaded with loader %s, skipping", location, loader), e);
|
||||
}
|
||||
}
|
||||
if (!loaders.containsKey(loaderId))
|
||||
throw new IllegalStateException(String.format("Model loader '%s' not found.", loaderId));
|
||||
|
||||
// no custom loaders found, try vanilla ones
|
||||
if(accepted == null)
|
||||
{
|
||||
if(VariantLoader.INSTANCE.accepts(actual))
|
||||
{
|
||||
accepted = VariantLoader.INSTANCE;
|
||||
}
|
||||
else if(VanillaLoader.INSTANCE.accepts(actual))
|
||||
{
|
||||
accepted = VanillaLoader.INSTANCE;
|
||||
}
|
||||
}
|
||||
IModelLoader<?> loader = loaders.get(loaderId);
|
||||
|
||||
if(accepted == null)
|
||||
{
|
||||
throw new LoaderException("no suitable loader found for the model " + location + ", skipping");
|
||||
}
|
||||
return loader.read(deserializationContext, data);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static IModelGeometry<?> deserializeGeometry(JsonDeserializationContext deserializationContext, JsonObject object) {
|
||||
if (!object.has("loader")) {
|
||||
return null;
|
||||
}
|
||||
|
||||
ResourceLocation loader = new ResourceLocation(JSONUtils.getString(object,"loader"));
|
||||
return getModel(loader, deserializationContext, object);
|
||||
}
|
||||
|
||||
private static final Pattern FILESYSTEM_PATH_TO_RESLOC = Pattern.compile("(?:.*[\\\\/]assets[\\\\/](?<namespace>[a-z_-]+)[\\\\/]textures[\\\\/])?(?<path>[a-z_\\\\/-]+)\\.png");
|
||||
|
||||
public static Material resolveTexture(@Nullable String tex, IModelConfiguration owner)
|
||||
{
|
||||
if (tex == null)
|
||||
return blockMaterial("forge:white");
|
||||
if (tex.startsWith("#"))
|
||||
return owner.resolveTexture(tex);
|
||||
|
||||
// Attempt to convert a common (windows/linux/mac) filesystem path to a ResourceLocation.
|
||||
// This makes no promises, if it doesn't work, too bad, fix your mtl file.
|
||||
Matcher match = FILESYSTEM_PATH_TO_RESLOC.matcher(tex);
|
||||
if (match.matches())
|
||||
{
|
||||
String namespace = match.group("namespace");
|
||||
String path = match.group("path").replace("\\", "/");
|
||||
if (namespace != null)
|
||||
return blockMaterial(new ResourceLocation(namespace, path));
|
||||
return blockMaterial(path);
|
||||
}
|
||||
|
||||
return blockMaterial(tex);
|
||||
}
|
||||
|
||||
public static Material blockMaterial(String location)
|
||||
{
|
||||
return new Material(AtlasTexture.LOCATION_BLOCKS_TEXTURE, new ResourceLocation(location));
|
||||
}
|
||||
|
||||
public static Material blockMaterial(ResourceLocation location)
|
||||
{
|
||||
return new Material(AtlasTexture.LOCATION_BLOCKS_TEXTURE, location);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static IModelTransform deserializeModelTransforms(JsonDeserializationContext deserializationContext, JsonObject modelData)
|
||||
{
|
||||
if (!modelData.has("transform"))
|
||||
return null;
|
||||
|
||||
return deserializeTransform(deserializationContext, modelData.get("transform")).orElse(null);
|
||||
}
|
||||
|
||||
public static Optional<IModelTransform> deserializeTransform(JsonDeserializationContext context, JsonElement transformData)
|
||||
{
|
||||
if (!transformData.isJsonObject())
|
||||
{
|
||||
try
|
||||
{
|
||||
model = accepted.loadModel(actual);
|
||||
TransformationMatrix base = context.deserialize(transformData, TransformationMatrix.class);
|
||||
return Optional.of(new SimpleModelTransform(ImmutableMap.of(), TransformationHelper.blockCenterToCorner(base)));
|
||||
}
|
||||
catch(Exception e)
|
||||
catch (JsonParseException e)
|
||||
{
|
||||
throw new LoaderException(String.format("Exception loading model %s with loader %s, skipping", location, accepted), e);
|
||||
}
|
||||
if(model == getMissingModel())
|
||||
{
|
||||
throw new LoaderException(String.format("Loader %s returned missing model while loading model %s", accepted, location));
|
||||
}
|
||||
if(model == null)
|
||||
{
|
||||
throw new LoaderException(String.format("Loader %s returned null while loading model %s", accepted, location));
|
||||
throw new JsonParseException("transform: expected a string, object or valid base transformation, got: " + transformData);
|
||||
}
|
||||
}
|
||||
finally
|
||||
else
|
||||
{
|
||||
ResourceLocation popLoc = loadingModels.removeLast();
|
||||
if(popLoc != location)
|
||||
JsonObject transform = transformData.getAsJsonObject();
|
||||
EnumMap<ItemCameraTransforms.TransformType, TransformationMatrix> transforms = Maps.newEnumMap(ItemCameraTransforms.TransformType.class);
|
||||
|
||||
deserializeTRSR(context, transforms, transform, "thirdperson", ItemCameraTransforms.TransformType.THIRD_PERSON_RIGHT_HAND);
|
||||
deserializeTRSR(context, transforms, transform, "thirdperson_righthand", ItemCameraTransforms.TransformType.THIRD_PERSON_RIGHT_HAND);
|
||||
deserializeTRSR(context, transforms, transform, "thirdperson_lefthand", ItemCameraTransforms.TransformType.THIRD_PERSON_LEFT_HAND);
|
||||
|
||||
deserializeTRSR(context, transforms, transform, "firstperson", ItemCameraTransforms.TransformType.FIRST_PERSON_RIGHT_HAND);
|
||||
deserializeTRSR(context, transforms, transform, "firstperson_righthand", ItemCameraTransforms.TransformType.FIRST_PERSON_RIGHT_HAND);
|
||||
deserializeTRSR(context, transforms, transform, "firstperson_lefthand", ItemCameraTransforms.TransformType.FIRST_PERSON_LEFT_HAND);
|
||||
|
||||
deserializeTRSR(context, transforms, transform, "head", ItemCameraTransforms.TransformType.HEAD);
|
||||
deserializeTRSR(context, transforms, transform, "gui", ItemCameraTransforms.TransformType.GUI);
|
||||
deserializeTRSR(context, transforms, transform, "ground", ItemCameraTransforms.TransformType.GROUND);
|
||||
deserializeTRSR(context, transforms, transform, "fixed", ItemCameraTransforms.TransformType.FIXED);
|
||||
|
||||
int k = transform.entrySet().size();
|
||||
if(transform.has("matrix")) k--;
|
||||
if(transform.has("translation")) k--;
|
||||
if(transform.has("rotation")) k--;
|
||||
if(transform.has("scale")) k--;
|
||||
if(transform.has("post-rotation")) k--;
|
||||
if(k > 0)
|
||||
{
|
||||
throw new IllegalStateException("Corrupted loading model stack: " + popLoc + " != " + location);
|
||||
throw new JsonParseException("transform: allowed keys: 'thirdperson', 'firstperson', 'gui', 'head', 'matrix', 'translation', 'rotation', 'scale', 'post-rotation'");
|
||||
}
|
||||
TransformationMatrix base = TransformationMatrix.func_227983_a_();
|
||||
if(!transform.entrySet().isEmpty())
|
||||
{
|
||||
base = context.deserialize(transform, TransformationMatrix.class);
|
||||
base = TransformationHelper.blockCenterToCorner(base);
|
||||
}
|
||||
IModelTransform state = new SimpleModelTransform(Maps.immutableEnumMap(transforms), base);
|
||||
return Optional.of(state);
|
||||
}
|
||||
cache.put(location, model);
|
||||
for (ResourceLocation dep : model.getDependencies())
|
||||
}
|
||||
|
||||
private static void deserializeTRSR(JsonDeserializationContext context, EnumMap<ItemCameraTransforms.TransformType, TransformationMatrix> transforms, JsonObject transform, String name, ItemCameraTransforms.TransformType itemCameraTransform)
|
||||
{
|
||||
if(transform.has(name))
|
||||
{
|
||||
getModelOrMissing(dep);
|
||||
TransformationMatrix t = context.deserialize(transform.remove(name), TransformationMatrix.class);
|
||||
transforms.put(itemCameraTransform, TransformationHelper.blockCenterToCorner(t));
|
||||
}
|
||||
}
|
||||
|
||||
public static IBakedModel bakeHelper(BlockModel blockModel, ModelBakery modelBakery, BlockModel otherModel, Function<Material, TextureAtlasSprite> spriteGetter, IModelTransform sprite, ResourceLocation modelLocation)
|
||||
{
|
||||
IBakedModel model;
|
||||
IModelGeometry<?> customModel = blockModel.customData.getCustomGeometry();
|
||||
IModelTransform customModelState = blockModel.customData.getCustomModelState();
|
||||
if (customModelState != null)
|
||||
{
|
||||
sprite = new ModelTransformComposition(customModelState, sprite, sprite.isUvLock());
|
||||
}
|
||||
if (customModel != null)
|
||||
{
|
||||
model = customModel.bake(blockModel.customData, modelBakery, spriteGetter, sprite, blockModel.getOverrides(modelBakery, otherModel, spriteGetter), modelLocation);
|
||||
}
|
||||
else
|
||||
{
|
||||
model = blockModel.bakeVanilla(modelBakery, otherModel, spriteGetter, sprite, modelLocation);
|
||||
}
|
||||
|
||||
if (customModelState != null && !model.doesHandlePerspectives())
|
||||
{
|
||||
model = new PerspectiveMapWrapper(model, customModelState);
|
||||
}
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this if you don't care about the exception and want some model anyway.
|
||||
*/
|
||||
public static IUnbakedModel getModelOrMissing(ResourceLocation location)
|
||||
public static class VanillaProxy implements ISimpleModelGeometry<VanillaProxy>
|
||||
{
|
||||
try
|
||||
private final List<BlockPart> elements;
|
||||
|
||||
public VanillaProxy(List<BlockPart> list)
|
||||
{
|
||||
return getModel(location);
|
||||
this.elements = list;
|
||||
}
|
||||
catch(Exception e)
|
||||
|
||||
@Override
|
||||
public void addQuads(IModelConfiguration owner, IModelBuilder<?> modelBuilder, ModelBakery bakery, Function<Material, TextureAtlasSprite> spriteGetter, IModelTransform sprite, ResourceLocation modelLocation)
|
||||
{
|
||||
return getMissingModel(location, e);
|
||||
for(BlockPart blockpart : elements) {
|
||||
for(Direction direction : blockpart.mapFaces.keySet()) {
|
||||
BlockPartFace blockpartface = blockpart.mapFaces.get(direction);
|
||||
TextureAtlasSprite textureatlassprite1 = spriteGetter.apply(owner.resolveTexture(blockpartface.texture));
|
||||
if (blockpartface.cullFace == null) {
|
||||
modelBuilder.addGeneralQuad(BlockModel.makeBakedQuad(blockpart, blockpartface, textureatlassprite1, direction, sprite, modelLocation));
|
||||
} else {
|
||||
modelBuilder.addFaceQuad(
|
||||
sprite.func_225615_b_().rotateTransform(blockpartface.cullFace),
|
||||
BlockModel.makeBakedQuad(blockpart, blockpartface, textureatlassprite1, direction, sprite, modelLocation));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Material> getTextures(IModelConfiguration owner, Function<ResourceLocation, IUnbakedModel> modelGetter, Set<Pair<String, String>> missingTextureErrors)
|
||||
{
|
||||
Set<Material> textures = Sets.newHashSet();
|
||||
|
||||
for(BlockPart part : elements) {
|
||||
for(BlockPartFace face : part.mapFaces.values()) {
|
||||
Material texture = owner.resolveTexture(face.texture);
|
||||
if (Objects.equals(texture, MissingTextureSprite.getLocation().toString())) {
|
||||
missingTextureErrors.add(Pair.of(face.texture, owner.getModelName()));
|
||||
}
|
||||
|
||||
textures.add(texture);
|
||||
}
|
||||
}
|
||||
|
||||
return textures;
|
||||
}
|
||||
|
||||
public static class Loader implements IModelLoader<VanillaProxy>
|
||||
{
|
||||
public static final Loader INSTANCE = new Loader();
|
||||
|
||||
private Loader()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResourceManagerReload(IResourceManager resourceManager)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public VanillaProxy read(JsonDeserializationContext deserializationContext, JsonObject modelContents)
|
||||
{
|
||||
List<BlockPart> list = this.getModelElements(deserializationContext, modelContents);
|
||||
return new VanillaProxy(list);
|
||||
}
|
||||
|
||||
private List<BlockPart> getModelElements(JsonDeserializationContext deserializationContext, JsonObject object) {
|
||||
List<BlockPart> list = Lists.newArrayList();
|
||||
if (object.has("elements")) {
|
||||
for(JsonElement jsonelement : JSONUtils.getJsonArray(object, "elements")) {
|
||||
list.add(deserializationContext.deserialize(jsonelement, BlockPart.class));
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this if you want the model, but need to log the error.
|
||||
*/
|
||||
public static IUnbakedModel getModelOrLogError(ResourceLocation location, String error)
|
||||
public static class ExpandedBlockModelDeserializer extends BlockModel.Deserializer
|
||||
{
|
||||
try
|
||||
{
|
||||
return getModel(location);
|
||||
public static final Gson INSTANCE = (new GsonBuilder())
|
||||
.registerTypeAdapter(BlockModel.class, new ExpandedBlockModelDeserializer())
|
||||
.registerTypeAdapter(BlockPart.class, new BlockPart.Deserializer())
|
||||
.registerTypeAdapter(BlockPartFace.class, new BlockPartFace.Deserializer())
|
||||
.registerTypeAdapter(BlockFaceUV.class, new BlockFaceUV.Deserializer())
|
||||
.registerTypeAdapter(ItemTransformVec3f.class, new ItemTransformVec3f.Deserializer())
|
||||
.registerTypeAdapter(ItemCameraTransforms.class, new ItemCameraTransforms.Deserializer())
|
||||
.registerTypeAdapter(ItemOverride.class, new ItemOverride.Deserializer())
|
||||
.registerTypeAdapter(TransformationMatrix.class, new TransformationHelper.Deserializer())
|
||||
.create();
|
||||
|
||||
public BlockModel deserialize(JsonElement element, Type targetType, JsonDeserializationContext deserializationContext) throws JsonParseException {
|
||||
BlockModel model = super.deserialize(element, targetType, deserializationContext);
|
||||
JsonObject jsonobject = element.getAsJsonObject();
|
||||
IModelGeometry<?> geometry = deserializeGeometry(deserializationContext, jsonobject);
|
||||
|
||||
List<BlockPart> elements = model.getElements();
|
||||
if (geometry != null) {
|
||||
elements.clear();
|
||||
model.customData.setCustomGeometry(geometry);
|
||||
}
|
||||
|
||||
IModelTransform modelState = deserializeModelTransforms(deserializationContext, jsonobject);
|
||||
if (modelState != null)
|
||||
{
|
||||
model.customData.setCustomModelState(modelState);
|
||||
}
|
||||
|
||||
if (jsonobject.has("visibility"))
|
||||
{
|
||||
JsonObject visibility = JSONUtils.getJsonObject(jsonobject, "visibility");
|
||||
for(Map.Entry<String, JsonElement> part : visibility.entrySet())
|
||||
{
|
||||
model.customData.visibilityData.setVisibilityState(part.getKey(), part.getValue().getAsBoolean());
|
||||
}
|
||||
}
|
||||
|
||||
return model;
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
LOGGER.error(error, e);
|
||||
return getMissingModel(location, e);
|
||||
}
|
||||
}
|
||||
|
||||
public static IUnbakedModel getMissingModel()
|
||||
{
|
||||
final ModelLoader loader = VanillaLoader.INSTANCE.getLoader();
|
||||
if(loader == null)
|
||||
{
|
||||
throw new IllegalStateException("Using ModelLoaderRegistry too early.");
|
||||
}
|
||||
return loader.getMissingModel();
|
||||
}
|
||||
|
||||
static IUnbakedModel getMissingModel(ResourceLocation location, Throwable cause)
|
||||
{
|
||||
//IModel model = new FancyMissingModel(ExceptionUtils.getStackTrace(cause).replaceAll("\\t", " "));
|
||||
IUnbakedModel model = new FancyMissingModel(getMissingModel(), location.toString());
|
||||
return model;
|
||||
}
|
||||
|
||||
public static void clearModelCache(IResourceManager manager)
|
||||
{
|
||||
ModelLoaderRegistry.manager = manager;
|
||||
cache.clear();
|
||||
// putting the builtin models in
|
||||
cache.put(new ResourceLocation("minecraft:builtin/generated"), ItemLayerModel.INSTANCE);
|
||||
cache.put(new ResourceLocation("minecraft:block/builtin/generated"), ItemLayerModel.INSTANCE);
|
||||
cache.put(new ResourceLocation("minecraft:item/builtin/generated"), ItemLayerModel.INSTANCE);
|
||||
}
|
||||
|
||||
public static class LoaderException extends Exception
|
||||
{
|
||||
public LoaderException(String message)
|
||||
{
|
||||
super(message);
|
||||
}
|
||||
|
||||
public LoaderException(String message, Throwable cause)
|
||||
{
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
||||
|
||||
public static IAnimationStateMachine loadASM(ResourceLocation location, ImmutableMap<String, ITimeValue> customParameters)
|
||||
{
|
||||
return AnimationStateMachine.load(manager, location, customParameters);
|
||||
}
|
||||
}
|
||||
+11
-6
@@ -19,12 +19,17 @@
|
||||
|
||||
package net.minecraftforge.client.model;
|
||||
|
||||
import net.minecraft.client.renderer.model.IUnbakedModel;
|
||||
|
||||
@Deprecated
|
||||
public interface ISmartVariant
|
||||
public class ModelLoadingException extends RuntimeException
|
||||
{
|
||||
default IUnbakedModel process(IUnbakedModel base) {
|
||||
return base;
|
||||
public ModelLoadingException(String message)
|
||||
{
|
||||
super(message);
|
||||
}
|
||||
|
||||
public ModelLoadingException(String message, Throwable cause)
|
||||
{
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
||||
+17
-29
@@ -20,40 +20,30 @@
|
||||
package net.minecraftforge.client.model;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import net.minecraft.client.renderer.texture.ISprite;
|
||||
import net.minecraftforge.common.model.IModelPart;
|
||||
import net.minecraftforge.common.model.IModelState;
|
||||
import net.minecraftforge.common.model.TRSRTransformation;
|
||||
|
||||
import java.util.Optional;
|
||||
import net.minecraft.client.renderer.TransformationMatrix;
|
||||
import net.minecraft.client.renderer.model.IModelTransform;
|
||||
|
||||
/**
|
||||
* An {@link IModelState} that combines the transforms from two child {@link IModelState}.
|
||||
* An {@link IModelTransform} that combines the transforms from two child {@link IModelTransform}.
|
||||
*/
|
||||
public class ModelStateComposition implements IModelState, ISprite
|
||||
public class ModelTransformComposition implements IModelTransform
|
||||
{
|
||||
private final IModelState first;
|
||||
private final IModelState second;
|
||||
private final IModelTransform first;
|
||||
private final IModelTransform second;
|
||||
private final boolean uvLock;
|
||||
|
||||
public ModelStateComposition(IModelState first, IModelState second)
|
||||
public ModelTransformComposition(IModelTransform first, IModelTransform second)
|
||||
{
|
||||
this(first, second, false);
|
||||
}
|
||||
|
||||
public ModelStateComposition(IModelState first, IModelState second, boolean uvLock)
|
||||
public ModelTransformComposition(IModelTransform first, IModelTransform second, boolean uvLock)
|
||||
{
|
||||
this.first = first;
|
||||
this.second = second;
|
||||
this.uvLock = uvLock;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IModelState getState()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUvLock()
|
||||
{
|
||||
@@ -61,17 +51,15 @@ public class ModelStateComposition implements IModelState, ISprite
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<TRSRTransformation> apply(Optional<? extends IModelPart> part)
|
||||
public TransformationMatrix func_225615_b_()
|
||||
{
|
||||
Optional<TRSRTransformation> f = first.apply(part), s = second.apply(part);
|
||||
if(f.isPresent() && s.isPresent())
|
||||
{
|
||||
return Optional.of(f.get().compose(s.get()));
|
||||
}
|
||||
if (f.isPresent()) {
|
||||
return f;
|
||||
}
|
||||
return s;
|
||||
return first.func_225615_b_().compose(second.func_225615_b_());
|
||||
}
|
||||
|
||||
@Override
|
||||
public TransformationMatrix getPartTransformation(Object part)
|
||||
{
|
||||
return first.getPartTransformation(part).compose(second.getPartTransformation(part));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -85,7 +73,7 @@ public class ModelStateComposition implements IModelState, ISprite
|
||||
{
|
||||
return false;
|
||||
}
|
||||
ModelStateComposition that = (ModelStateComposition) o;
|
||||
ModelTransformComposition that = (ModelTransformComposition) o;
|
||||
return Objects.equal(first, that.first) && Objects.equal(second, that.second);
|
||||
}
|
||||
|
||||
@@ -27,19 +27,13 @@ import javax.annotation.Nullable;
|
||||
import javax.vecmath.Matrix4f;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.renderer.TransformationMatrix;
|
||||
import net.minecraft.client.renderer.model.*;
|
||||
import net.minecraft.client.renderer.model.ItemCameraTransforms.TransformType;
|
||||
import net.minecraft.client.renderer.texture.ISprite;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormat;
|
||||
import net.minecraft.resources.IResourceManager;
|
||||
import net.minecraft.util.BlockRenderLayer;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.client.MinecraftForgeClient;
|
||||
import net.minecraftforge.versions.forge.ForgeVersion;
|
||||
import net.minecraftforge.common.model.IModelState;
|
||||
import net.minecraftforge.common.model.TRSRTransformation;
|
||||
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
@@ -58,14 +52,15 @@ import com.google.gson.JsonParser;
|
||||
/**
|
||||
* A model that can be rendered in multiple {@link BlockRenderLayer}.
|
||||
*/
|
||||
/* TODO: reimplement
|
||||
public final class MultiLayerModel implements IUnbakedModel
|
||||
{
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
public static final MultiLayerModel INSTANCE = new MultiLayerModel(ImmutableMap.of());
|
||||
|
||||
private final ImmutableMap<Optional<BlockRenderLayer>, ModelResourceLocation> models;
|
||||
private final ImmutableMap<Optional<BlockRenderLayer>, ResourceLocation> models;
|
||||
|
||||
public MultiLayerModel(ImmutableMap<Optional<BlockRenderLayer>, ModelResourceLocation> models)
|
||||
public MultiLayerModel(ImmutableMap<Optional<BlockRenderLayer>, ResourceLocation> models)
|
||||
{
|
||||
this.models = models;
|
||||
}
|
||||
@@ -75,40 +70,40 @@ public final class MultiLayerModel implements IUnbakedModel
|
||||
{
|
||||
return ImmutableList.copyOf(models.values());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Collection<ResourceLocation> getTextures(Function<ResourceLocation, IUnbakedModel> modelGetter, Set<String> missingTextureErrors)
|
||||
public Collection<Material> func_225614_a_(Function<ResourceLocation, IUnbakedModel> p_225614_1_, Set<com.mojang.datafixers.util.Pair<String, String>> p_225614_2_)
|
||||
{
|
||||
return Collections.emptyList();
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
private static ImmutableMap<Optional<BlockRenderLayer>, IBakedModel> buildModels(ImmutableMap<Optional<BlockRenderLayer>, ModelResourceLocation> models, ISprite sprite, VertexFormat format, ModelBakery bakery, Function<ResourceLocation, TextureAtlasSprite> spriteGetter)
|
||||
|
||||
private static ImmutableMap<Optional<BlockRenderLayer>, IBakedModel> buildModels(ImmutableMap<Optional<BlockRenderLayer>, ResourceLocation> models, IModelTransform sprite, ModelBakery bakery, Function<Material, TextureAtlasSprite> spriteGetter, ResourceLocation p_225613_4_)
|
||||
{
|
||||
ImmutableMap.Builder<Optional<BlockRenderLayer>, IBakedModel> builder = ImmutableMap.builder();
|
||||
for(Optional<BlockRenderLayer> key : models.keySet())
|
||||
{
|
||||
IUnbakedModel model = ModelLoaderRegistry.getModelOrLogError(models.get(key), "Couldn't load MultiLayerModel dependency: " + models.get(key));
|
||||
builder.put(key, model.bake(bakery, spriteGetter, new ModelStateComposition(sprite.getState(), model.getDefaultState(), sprite.isUvLock()), format));
|
||||
IUnbakedModel model = ModelLoader.defaultModelGetter().apply(models.get(key));
|
||||
builder.put(key, model.func_225613_a_(bakery, spriteGetter, sprite, p_225613_4_));
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public IBakedModel bake(ModelBakery bakery, Function<ResourceLocation, TextureAtlasSprite> spriteGetter, ISprite sprite, VertexFormat format)
|
||||
public IBakedModel func_225613_a_(ModelBakery bakery, Function<Material, TextureAtlasSprite> spriteGetter, IModelTransform sprite, ResourceLocation p_225613_4_)
|
||||
{
|
||||
IUnbakedModel missing = ModelLoaderRegistry.getMissingModel();
|
||||
IUnbakedModel missing = ModelLoader.instance().getMissingModel();
|
||||
return new MultiLayerBakedModel(
|
||||
buildModels(models, sprite, format, bakery, spriteGetter),
|
||||
missing.bake(bakery, spriteGetter, new BasicState(missing.getDefaultState(), sprite.isUvLock()), format),
|
||||
PerspectiveMapWrapper.getTransforms(sprite.getState())
|
||||
buildModels(models, sprite, bakery, spriteGetter, p_225613_4_),
|
||||
missing.func_225613_a_(bakery, spriteGetter, sprite, p_225613_4_),
|
||||
PerspectiveMapWrapper.getTransforms(sprite)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MultiLayerModel process(ImmutableMap<String, String> customData)
|
||||
{
|
||||
ImmutableMap.Builder<Optional<BlockRenderLayer>, ModelResourceLocation> builder = ImmutableMap.builder();
|
||||
ImmutableMap.Builder<Optional<BlockRenderLayer>, ResourceLocation> builder = ImmutableMap.builder();
|
||||
for(String key : customData.keySet())
|
||||
{
|
||||
if("base".equals(key))
|
||||
@@ -123,12 +118,12 @@ public final class MultiLayerModel implements IUnbakedModel
|
||||
}
|
||||
}
|
||||
}
|
||||
ImmutableMap<Optional<BlockRenderLayer>, ModelResourceLocation> models = builder.build();
|
||||
ImmutableMap<Optional<BlockRenderLayer>, ResourceLocation> models = builder.build();
|
||||
if(models.isEmpty()) return INSTANCE;
|
||||
return new MultiLayerModel(models);
|
||||
}
|
||||
|
||||
private ModelResourceLocation getLocation(String json)
|
||||
private ResourceLocation getLocation(String json)
|
||||
{
|
||||
JsonElement e = new JsonParser().parse(json);
|
||||
if(e.isJsonPrimitive() && e.getAsJsonPrimitive().isString())
|
||||
@@ -142,11 +137,11 @@ public final class MultiLayerModel implements IUnbakedModel
|
||||
private static final class MultiLayerBakedModel implements IBakedModel
|
||||
{
|
||||
private final ImmutableMap<Optional<BlockRenderLayer>, IBakedModel> models;
|
||||
private final ImmutableMap<TransformType, TRSRTransformation> cameraTransforms;
|
||||
private final ImmutableMap<TransformType, TransformationMatrix> cameraTransforms;
|
||||
private final IBakedModel base;
|
||||
private final IBakedModel missing;
|
||||
|
||||
public MultiLayerBakedModel(ImmutableMap<Optional<BlockRenderLayer>, IBakedModel> models, IBakedModel missing, ImmutableMap<TransformType, TRSRTransformation> cameraTransforms)
|
||||
public MultiLayerBakedModel(ImmutableMap<Optional<BlockRenderLayer>, IBakedModel> models, IBakedModel missing, ImmutableMap<TransformType, TransformationMatrix> cameraTransforms)
|
||||
{
|
||||
this.models = models;
|
||||
this.cameraTransforms = cameraTransforms;
|
||||
@@ -201,6 +196,12 @@ public final class MultiLayerModel implements IUnbakedModel
|
||||
return base.getParticleTexture();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doesHandlePerspectives()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pair<? extends IBakedModel, Matrix4f> handlePerspective(TransformType cameraTransformType)
|
||||
{
|
||||
@@ -213,27 +214,5 @@ public final class MultiLayerModel implements IUnbakedModel
|
||||
return ItemOverrideList.EMPTY;
|
||||
}
|
||||
}
|
||||
|
||||
public static enum Loader implements ICustomModelLoader
|
||||
{
|
||||
INSTANCE;
|
||||
|
||||
@Override
|
||||
public void onResourceManagerReload(IResourceManager resourceManager) {}
|
||||
|
||||
@Override
|
||||
public boolean accepts(ResourceLocation modelLocation)
|
||||
{
|
||||
return modelLocation.getNamespace().equals(ForgeVersion.MOD_ID) && (
|
||||
modelLocation.getPath().equals("multi-layer") ||
|
||||
modelLocation.getPath().equals("models/block/multi-layer") ||
|
||||
modelLocation.getPath().equals("models/item/multi-layer"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IUnbakedModel loadModel(ResourceLocation modelLocation)
|
||||
{
|
||||
return MultiLayerModel.INSTANCE;
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
@@ -1,287 +0,0 @@
|
||||
/*
|
||||
* Minecraft Forge
|
||||
* Copyright (c) 2016-2019.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation version 2.1
|
||||
* of the License.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package net.minecraftforge.client.model;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.EnumMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.vecmath.Matrix4f;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.renderer.model.*;
|
||||
import net.minecraft.client.renderer.model.ItemCameraTransforms.TransformType;
|
||||
import net.minecraft.client.renderer.texture.ISprite;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormat;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.model.IModelState;
|
||||
import net.minecraftforge.common.model.TRSRTransformation;
|
||||
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.util.function.Function;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
// TODO: Switch to vanilla class, or to something similar
|
||||
@Deprecated
|
||||
public final class MultiModel implements IUnbakedModel
|
||||
{
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
|
||||
private static final class Baked implements IBakedModel
|
||||
{
|
||||
private final ResourceLocation location;
|
||||
@Nullable
|
||||
private final IBakedModel base;
|
||||
private final ImmutableMap<String, IBakedModel> parts;
|
||||
|
||||
private final IBakedModel internalBase;
|
||||
private final ImmutableMap<TransformType, Pair<Baked, TRSRTransformation>> transforms;
|
||||
private final ItemOverrideList overrides = new ItemOverrideList()
|
||||
{
|
||||
@Override
|
||||
public IBakedModel getModelWithOverrides(IBakedModel originalModel, ItemStack stack, @Nullable World world, @Nullable LivingEntity entity)
|
||||
{
|
||||
if(originalModel != Baked.this)
|
||||
{
|
||||
return originalModel;
|
||||
}
|
||||
boolean dirty = false;
|
||||
IBakedModel newBase = null;
|
||||
|
||||
if(base != null)
|
||||
{
|
||||
newBase = base.getOverrides().getModelWithOverrides(base, stack, world, entity);
|
||||
if(base != newBase)
|
||||
{
|
||||
dirty = true;
|
||||
}
|
||||
}
|
||||
ImmutableMap.Builder<String, IBakedModel> builder = ImmutableMap.builder();
|
||||
for(Map.Entry<String, IBakedModel> entry : parts.entrySet())
|
||||
{
|
||||
IBakedModel newPart = entry.getValue().getOverrides().getModelWithOverrides(entry.getValue(), stack, world, entity);
|
||||
builder.put(entry.getKey(), newPart);
|
||||
if(entry.getValue() != newPart)
|
||||
{
|
||||
dirty = true;
|
||||
}
|
||||
}
|
||||
if(dirty)
|
||||
{
|
||||
// TODO: caching?
|
||||
return new Baked(location, true, newBase, builder.build());
|
||||
}
|
||||
return Baked.this;
|
||||
}
|
||||
};
|
||||
|
||||
public Baked(ResourceLocation location, boolean perspective, @Nullable IBakedModel base, ImmutableMap<String, IBakedModel> parts)
|
||||
{
|
||||
this.location = location;
|
||||
this.base = base;
|
||||
this.parts = parts;
|
||||
|
||||
if (base != null)
|
||||
internalBase = base;
|
||||
else
|
||||
{
|
||||
Iterator<IBakedModel> iter = parts.values().iterator();
|
||||
if (iter.hasNext())
|
||||
internalBase = iter.next();
|
||||
else
|
||||
throw new IllegalArgumentException("No base model or submodel provided for MultiModel.Baked " + location + ".");
|
||||
}
|
||||
|
||||
// Only changes the base model based on perspective, may recurse for parts in the future.
|
||||
if(base != null && perspective)
|
||||
{
|
||||
EnumMap<TransformType, Pair<Baked, TRSRTransformation>> map = new EnumMap<>(TransformType.class);
|
||||
for(TransformType type : TransformType.values())
|
||||
{
|
||||
Pair<? extends IBakedModel, Matrix4f> p = base.handlePerspective(type);
|
||||
IBakedModel newBase = p.getLeft();
|
||||
Matrix4f matrix = p.getRight();
|
||||
if (newBase != base || matrix != null)
|
||||
{
|
||||
map.put(type, Pair.of(new Baked(location, false, newBase, parts), new TRSRTransformation(matrix)));
|
||||
}
|
||||
}
|
||||
transforms = ImmutableMap.copyOf(map);
|
||||
}
|
||||
else
|
||||
{
|
||||
transforms = ImmutableMap.of();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAmbientOcclusion()
|
||||
{
|
||||
return internalBase.isAmbientOcclusion();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAmbientOcclusion(BlockState state)
|
||||
{
|
||||
return internalBase.isAmbientOcclusion(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGui3d()
|
||||
{
|
||||
return internalBase.isGui3d();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBuiltInRenderer()
|
||||
{
|
||||
return internalBase.isBuiltInRenderer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextureAtlasSprite getParticleTexture()
|
||||
{
|
||||
return internalBase.getParticleTexture();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemCameraTransforms getItemCameraTransforms()
|
||||
{
|
||||
return internalBase.getItemCameraTransforms();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, Random rand)
|
||||
{
|
||||
ImmutableList.Builder<BakedQuad> quads = ImmutableList.builder();
|
||||
if (base != null)
|
||||
{
|
||||
quads.addAll(base.getQuads(state, side, rand));
|
||||
}
|
||||
for (IBakedModel bakedPart : parts.values())
|
||||
{
|
||||
quads.addAll(bakedPart.getQuads(state, side, rand));
|
||||
}
|
||||
return quads.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pair<? extends IBakedModel, Matrix4f> handlePerspective(TransformType cameraTransformType)
|
||||
{
|
||||
Pair<Baked, TRSRTransformation> p = transforms.get(cameraTransformType);
|
||||
if (p == null) return Pair.of(this, null);
|
||||
return Pair.of(p.getLeft(), p.getRight().getMatrixVec());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemOverrideList getOverrides()
|
||||
{
|
||||
return overrides;
|
||||
}
|
||||
}
|
||||
|
||||
private final ResourceLocation location;
|
||||
@Nullable
|
||||
private final IUnbakedModel base;
|
||||
private final Map<String, Pair<IUnbakedModel, IModelState>> parts;
|
||||
|
||||
public MultiModel(ResourceLocation location, @Nullable IUnbakedModel base, ImmutableMap<String, Pair<IUnbakedModel, IModelState>> parts)
|
||||
{
|
||||
this.location = location;
|
||||
this.base = base;
|
||||
this.parts = parts;
|
||||
}
|
||||
|
||||
public MultiModel(ResourceLocation location, IUnbakedModel base, Map<String, Pair<IUnbakedModel, IModelState>> parts)
|
||||
{
|
||||
this(location, base, ImmutableMap.copyOf(parts));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ResourceLocation> getDependencies()
|
||||
{
|
||||
Set<ResourceLocation> deps = Sets.newHashSet();
|
||||
|
||||
if (base != null)
|
||||
deps.addAll(base.getDependencies());
|
||||
|
||||
for (Pair<IUnbakedModel, IModelState> pair : parts.values())
|
||||
deps.addAll(pair.getLeft().getDependencies());
|
||||
|
||||
return deps;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ResourceLocation> getTextures(Function<ResourceLocation, IUnbakedModel> modelGetter, Set<String> missingTextures)
|
||||
{
|
||||
Set<ResourceLocation> deps = Sets.newHashSet();
|
||||
|
||||
if (base != null)
|
||||
deps.addAll(base.getTextures(modelGetter, missingTextures));
|
||||
|
||||
for (Pair<IUnbakedModel, IModelState> pair : parts.values())
|
||||
deps.addAll(pair.getLeft().getTextures(modelGetter, missingTextures));
|
||||
|
||||
return deps;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public IBakedModel bake(ModelBakery bakery, Function<ResourceLocation, TextureAtlasSprite> spriteGetter, ISprite sprite, VertexFormat format)
|
||||
{
|
||||
IBakedModel bakedBase = null;
|
||||
|
||||
if (base != null)
|
||||
bakedBase = base.bake(bakery, spriteGetter, sprite, format);
|
||||
|
||||
ImmutableMap.Builder<String, IBakedModel> mapBuilder = ImmutableMap.builder();
|
||||
|
||||
for (Entry<String, Pair<IUnbakedModel, IModelState>> entry : parts.entrySet())
|
||||
{
|
||||
Pair<IUnbakedModel, IModelState> pair = entry.getValue();
|
||||
mapBuilder.put(entry.getKey(), pair.getLeft().bake(bakery, spriteGetter, new ModelStateComposition(sprite.getState(), pair.getRight(), sprite.isUvLock()), format));
|
||||
}
|
||||
|
||||
if(bakedBase == null && parts.isEmpty())
|
||||
{
|
||||
LOGGER.error("MultiModel {} is empty (no base model or parts were provided/resolved)", location);
|
||||
IUnbakedModel missing = ModelLoaderRegistry.getMissingModel();
|
||||
return missing.bake(bakery, spriteGetter, new BasicState(missing.getDefaultState(), sprite.isUvLock()), format);
|
||||
}
|
||||
return new Baked(location, true, bakedBase, mapBuilder.build());
|
||||
}
|
||||
}
|
||||
@@ -1,156 +0,0 @@
|
||||
/*
|
||||
* Minecraft Forge
|
||||
* Copyright (c) 2016-2019.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation version 2.1
|
||||
* of the License.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package net.minecraftforge.client.model;
|
||||
|
||||
import net.minecraftforge.common.model.IModelPart;
|
||||
import net.minecraftforge.common.model.IModelState;
|
||||
import net.minecraftforge.common.model.TRSRTransformation;
|
||||
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import java.util.Optional;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
public final class MultiModelState implements IModelState
|
||||
{
|
||||
private final ImmutableMap<MultiModelPart, ? extends IModelState> states;
|
||||
|
||||
public <M extends IModel, S extends IModelState> MultiModelState(ImmutableList<Pair<M, S>> states)
|
||||
{
|
||||
ImmutableMap.Builder<MultiModelPart, S> builder = ImmutableMap.builder();
|
||||
for(int i = 0; i < states.size(); i++)
|
||||
{
|
||||
Pair<M, S> pair = states.get(i);
|
||||
builder.put(new MultiModelPart(pair.getLeft(), i), pair.getRight());
|
||||
}
|
||||
this.states = builder.build();
|
||||
}
|
||||
|
||||
public static IModelState getPartState(IModelState state, IModel model, int index)
|
||||
{
|
||||
if(state.apply(Optional.of(new MultiModelPart(model, index))).isPresent())
|
||||
{
|
||||
return new PartState(state, model, index);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<TRSRTransformation> apply(Optional<? extends IModelPart> part)
|
||||
{
|
||||
if(part.isPresent())
|
||||
{
|
||||
if(part.get() instanceof MultiModelPart)
|
||||
{
|
||||
MultiModelPart key = (MultiModelPart)part.get();
|
||||
if(states.containsKey(key))
|
||||
{
|
||||
return Optional.of(states.get(key).apply(Optional.empty()).orElse(TRSRTransformation.identity()));
|
||||
}
|
||||
}
|
||||
else if(part.get() instanceof PartPart)
|
||||
{
|
||||
PartPart partPart = (PartPart)part.get();
|
||||
MultiModelPart key = new MultiModelPart(partPart.model, partPart.index);
|
||||
if(states.containsKey(key))
|
||||
{
|
||||
return states.get(key).apply(partPart.part);
|
||||
}
|
||||
}
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
private static class PartState implements IModelState
|
||||
{
|
||||
private final IModelState state;
|
||||
private final IModel model;
|
||||
private final int index;
|
||||
|
||||
public PartState(IModelState state, IModel model, int index)
|
||||
{
|
||||
this.state = state;
|
||||
this.model = model;
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<TRSRTransformation> apply(Optional<? extends IModelPart> part)
|
||||
{
|
||||
Optional<TRSRTransformation> normal = state.apply(part);
|
||||
Optional<TRSRTransformation> multi = state.apply(Optional.of(new PartPart(model, index, part)));
|
||||
if(normal.isPresent() && multi.isPresent())
|
||||
{
|
||||
return Optional.of(normal.get().compose(multi.get()));
|
||||
}
|
||||
if (normal.isPresent()) {
|
||||
return normal;
|
||||
}
|
||||
return multi;
|
||||
}
|
||||
}
|
||||
|
||||
private static class MultiModelPart implements IModelPart
|
||||
{
|
||||
private final IModel model;
|
||||
private final int index;
|
||||
|
||||
public MultiModelPart(IModel model, int index)
|
||||
{
|
||||
this.model = model;
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
return Objects.hashCode(model, index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
MultiModelPart other = (MultiModelPart)obj;
|
||||
return Objects.equal(this.model, other.model) && this.index == other.index;
|
||||
}
|
||||
}
|
||||
|
||||
private static class PartPart implements IModelPart
|
||||
{
|
||||
private final IModel model;
|
||||
private final int index;
|
||||
private final Optional<? extends IModelPart> part;
|
||||
|
||||
public PartPart(IModel model, int index, Optional<? extends IModelPart> part)
|
||||
{
|
||||
this.model = model;
|
||||
this.index = index;
|
||||
this.part = part;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -20,87 +20,110 @@
|
||||
package net.minecraftforge.client.model;
|
||||
|
||||
import java.util.EnumMap;
|
||||
import java.util.Optional;
|
||||
import java.util.Random;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.renderer.model.BakedQuad;
|
||||
import net.minecraft.client.renderer.model.IBakedModel;
|
||||
import net.minecraft.client.renderer.model.ItemCameraTransforms;
|
||||
import net.minecraft.client.renderer.model.ItemOverrideList;
|
||||
import net.minecraft.client.renderer.TransformationMatrix;
|
||||
import net.minecraft.client.renderer.model.*;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraftforge.common.model.IModelState;
|
||||
import net.minecraftforge.common.model.TRSRTransformation;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.model.TransformationHelper;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.vecmath.Matrix4f;
|
||||
import java.util.List;
|
||||
|
||||
public class PerspectiveMapWrapper implements IBakedModel
|
||||
{
|
||||
private final IBakedModel parent;
|
||||
private final ImmutableMap<ItemCameraTransforms.TransformType, TRSRTransformation> transforms;
|
||||
private final ImmutableMap<ItemCameraTransforms.TransformType, TransformationMatrix> transforms;
|
||||
private final OverrideListWrapper overrides = new OverrideListWrapper();
|
||||
|
||||
public PerspectiveMapWrapper(IBakedModel parent, ImmutableMap<ItemCameraTransforms.TransformType, TRSRTransformation> transforms)
|
||||
public PerspectiveMapWrapper(IBakedModel parent, ImmutableMap<ItemCameraTransforms.TransformType, TransformationMatrix> transforms)
|
||||
{
|
||||
this.parent = parent;
|
||||
this.transforms = transforms;
|
||||
}
|
||||
|
||||
public PerspectiveMapWrapper(IBakedModel parent, IModelState state)
|
||||
public PerspectiveMapWrapper(IBakedModel parent, IModelTransform state)
|
||||
{
|
||||
this(parent, getTransforms(state));
|
||||
}
|
||||
|
||||
public static ImmutableMap<ItemCameraTransforms.TransformType, TRSRTransformation> getTransforms(IModelState state)
|
||||
public static ImmutableMap<ItemCameraTransforms.TransformType, TransformationMatrix> getTransforms(IModelTransform state)
|
||||
{
|
||||
EnumMap<ItemCameraTransforms.TransformType, TRSRTransformation> map = new EnumMap<>(ItemCameraTransforms.TransformType.class);
|
||||
EnumMap<ItemCameraTransforms.TransformType, TransformationMatrix> map = new EnumMap<>(ItemCameraTransforms.TransformType.class);
|
||||
for(ItemCameraTransforms.TransformType type : ItemCameraTransforms.TransformType.values())
|
||||
{
|
||||
Optional<TRSRTransformation> tr = state.apply(Optional.of(type));
|
||||
if(tr.isPresent())
|
||||
TransformationMatrix tr = state.getPartTransformation(type);
|
||||
if(!tr.isIdentity())
|
||||
{
|
||||
map.put(type, tr.get());
|
||||
map.put(type, tr);
|
||||
}
|
||||
}
|
||||
return ImmutableMap.copyOf(map);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static ImmutableMap<ItemCameraTransforms.TransformType, TRSRTransformation> getTransforms(ItemCameraTransforms transforms)
|
||||
public static ImmutableMap<ItemCameraTransforms.TransformType, TransformationMatrix> getTransforms(ItemCameraTransforms transforms)
|
||||
{
|
||||
EnumMap<ItemCameraTransforms.TransformType, TRSRTransformation> map = new EnumMap<>(ItemCameraTransforms.TransformType.class);
|
||||
EnumMap<ItemCameraTransforms.TransformType, TransformationMatrix> map = new EnumMap<>(ItemCameraTransforms.TransformType.class);
|
||||
for(ItemCameraTransforms.TransformType type : ItemCameraTransforms.TransformType.values())
|
||||
{
|
||||
if (transforms.hasCustomTransform(type))
|
||||
{
|
||||
map.put(type, TRSRTransformation.blockCenterToCorner(TRSRTransformation.from(transforms.getTransform(type))));
|
||||
map.put(type, TransformationHelper.blockCenterToCorner(TransformationHelper.toTransformation(transforms.getTransform(type))));
|
||||
}
|
||||
}
|
||||
return ImmutableMap.copyOf(map);
|
||||
}
|
||||
|
||||
public static Pair<? extends IBakedModel, Matrix4f> handlePerspective(IBakedModel model, ImmutableMap<ItemCameraTransforms.TransformType, TRSRTransformation> transforms, ItemCameraTransforms.TransformType cameraTransformType)
|
||||
@SuppressWarnings("deprecation")
|
||||
public static ImmutableMap<ItemCameraTransforms.TransformType, TransformationMatrix> getTransformsWithFallback(IModelTransform state, ItemCameraTransforms transforms)
|
||||
{
|
||||
TRSRTransformation tr = transforms.getOrDefault(cameraTransformType, TRSRTransformation.identity());
|
||||
if (!tr.isIdentity())
|
||||
EnumMap<ItemCameraTransforms.TransformType, TransformationMatrix> map = new EnumMap<>(ItemCameraTransforms.TransformType.class);
|
||||
for(ItemCameraTransforms.TransformType type : ItemCameraTransforms.TransformType.values())
|
||||
{
|
||||
return Pair.of(model, TRSRTransformation.blockCornerToCenter(tr).getMatrixVec());
|
||||
TransformationMatrix tr = state.getPartTransformation(type);
|
||||
if(!tr.isIdentity())
|
||||
{
|
||||
map.put(type, tr);
|
||||
}
|
||||
else if (transforms.hasCustomTransform(type))
|
||||
{
|
||||
map.put(type, TransformationHelper.blockCenterToCorner(TransformationHelper.toTransformation(transforms.getTransform(type))));
|
||||
}
|
||||
}
|
||||
return Pair.of(model, null);
|
||||
return ImmutableMap.copyOf(map);
|
||||
}
|
||||
|
||||
public static Pair<? extends IBakedModel, Matrix4f> handlePerspective(IBakedModel model, IModelState state, ItemCameraTransforms.TransformType cameraTransformType)
|
||||
public static IBakedModel handlePerspective(IBakedModel model, ImmutableMap<ItemCameraTransforms.TransformType, TransformationMatrix> transforms, ItemCameraTransforms.TransformType cameraTransformType, MatrixStack mat)
|
||||
{
|
||||
TRSRTransformation tr = state.apply(Optional.of(cameraTransformType)).orElse(TRSRTransformation.identity());
|
||||
TransformationMatrix tr = transforms.getOrDefault(cameraTransformType, TransformationMatrix.func_227983_a_());
|
||||
if (!tr.isIdentity())
|
||||
{
|
||||
return Pair.of(model, TRSRTransformation.blockCornerToCenter(tr).getMatrixVec());
|
||||
// Push to the matrix to make it not empty and indicate that we want to transform things
|
||||
mat.func_227860_a_();
|
||||
mat.func_227866_c_().func_227870_a_().func_226595_a_(TransformationHelper.blockCornerToCenter(tr).func_227988_c_());
|
||||
}
|
||||
return Pair.of(model, null);
|
||||
return model;
|
||||
}
|
||||
|
||||
public static IBakedModel handlePerspective(IBakedModel model, IModelTransform state, ItemCameraTransforms.TransformType cameraTransformType, MatrixStack mat)
|
||||
{
|
||||
TransformationMatrix tr = state.getPartTransformation(cameraTransformType);
|
||||
if (!tr.isIdentity())
|
||||
{
|
||||
// Push to the matrix to make it not empty and indicate that we want to transform things
|
||||
mat.func_227860_a_();
|
||||
mat.func_227866_c_().func_227870_a_().func_226595_a_(TransformationHelper.blockCornerToCenter(tr).func_227988_c_());
|
||||
}
|
||||
return model;
|
||||
}
|
||||
|
||||
@Override public boolean isAmbientOcclusion() { return parent.isAmbientOcclusion(); }
|
||||
@@ -111,11 +134,45 @@ public class PerspectiveMapWrapper implements IBakedModel
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override public ItemCameraTransforms getItemCameraTransforms() { return parent.getItemCameraTransforms(); }
|
||||
@Override public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, Random rand) { return parent.getQuads(state, side, rand); }
|
||||
@Override public ItemOverrideList getOverrides() { return parent.getOverrides(); }
|
||||
|
||||
|
||||
@Override
|
||||
public Pair<? extends IBakedModel, Matrix4f> handlePerspective(ItemCameraTransforms.TransformType cameraTransformType)
|
||||
public ItemOverrideList getOverrides()
|
||||
{
|
||||
return handlePerspective(this, transforms, cameraTransformType);
|
||||
return overrides;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doesHandlePerspectives()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBakedModel handlePerspective(ItemCameraTransforms.TransformType cameraTransformType, MatrixStack mat)
|
||||
{
|
||||
return handlePerspective(this, transforms, cameraTransformType, mat);
|
||||
}
|
||||
|
||||
private class OverrideListWrapper extends ItemOverrideList
|
||||
{
|
||||
public OverrideListWrapper()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public IBakedModel getModelWithOverrides(IBakedModel model, ItemStack stack, @Nullable World worldIn, @Nullable LivingEntity entityIn)
|
||||
{
|
||||
model = parent.getOverrides().getModelWithOverrides(parent, stack, worldIn, entityIn);
|
||||
return new PerspectiveMapWrapper(model, transforms);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImmutableList<ItemOverride> getOverrides()
|
||||
{
|
||||
return parent.getOverrides().getOverrides();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,200 @@
|
||||
/*
|
||||
* Minecraft Forge
|
||||
* Copyright (c) 2016-2019.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation version 2.1
|
||||
* of the License.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package net.minecraftforge.client.model;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import net.minecraft.client.renderer.TransformationMatrix;
|
||||
import net.minecraft.client.renderer.Vector4f;
|
||||
import net.minecraft.client.renderer.model.BakedQuad;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormat;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormatElement;
|
||||
|
||||
import javax.vecmath.Vector3f;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class QuadTransformer
|
||||
{
|
||||
private final VertexFormat format;
|
||||
private final int positionOffset;
|
||||
private final int normalOffset;
|
||||
private final TransformationMatrix transform;
|
||||
|
||||
public QuadTransformer(VertexFormat format, TransformationMatrix transform)
|
||||
{
|
||||
this.format = format;
|
||||
this.positionOffset = findPositionOffset(format);
|
||||
this.normalOffset = findNormalOffset(format);
|
||||
this.transform = transform;
|
||||
}
|
||||
|
||||
private void processVertices(int[] inData, int[] outData)
|
||||
{
|
||||
// TODO: Extract rotation matrix and fix NORMALs if present.
|
||||
int stride = format.getSize() / 4;
|
||||
for (int i=0;i<4;i++)
|
||||
{
|
||||
int offset = positionOffset + i * stride;
|
||||
float x = Float.intBitsToFloat(inData[offset ]);
|
||||
float y = Float.intBitsToFloat(inData[offset + 1]);
|
||||
float z = Float.intBitsToFloat(inData[offset + 2]);
|
||||
|
||||
Vector4f pos = new Vector4f(x, y, z, 1);
|
||||
transform.transformPosition(pos);
|
||||
pos.func_229374_e_();
|
||||
|
||||
outData[offset] = Float.floatToRawIntBits(pos.getX());
|
||||
outData[offset + 1] = Float.floatToRawIntBits(pos.getY());
|
||||
outData[offset + 2] = Float.floatToRawIntBits(pos.getZ());
|
||||
}
|
||||
|
||||
if (normalOffset >= 0)
|
||||
{
|
||||
for (int i=0;i<4;i++)
|
||||
{
|
||||
int offset = normalOffset + i * stride;
|
||||
int normalIn = inData[offset];
|
||||
float x = (((normalIn)>>24)&0xFF)/255.0f;
|
||||
float y = (((normalIn<<8)>>24)&0xFF)/255.0f;
|
||||
float z = (((normalIn<<16)>>24)&0xFF)/255.0f;
|
||||
|
||||
Vector3f pos = new Vector3f(x, y, z);
|
||||
transform.transformNormal(pos);
|
||||
|
||||
int normalOut =
|
||||
(((int)(x/255.0)&0xFF)<<24) |
|
||||
(((int)(y/255.0)&0xFF)<<16) |
|
||||
(((int)(z/255.0)&0xFF)<<8) |
|
||||
(normalIn&0xFF);
|
||||
|
||||
outData[offset] = normalOut;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static int findPositionOffset(VertexFormat fmt)
|
||||
{
|
||||
int index;
|
||||
VertexFormatElement element = null;
|
||||
for (index = 0; index < fmt.func_227894_c_().size(); index++)
|
||||
{
|
||||
VertexFormatElement el = fmt.func_227894_c_().get(index);
|
||||
if (el.getUsage() == VertexFormatElement.Usage.POSITION)
|
||||
{
|
||||
element = el;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (index == fmt.func_227894_c_().size() || element == null)
|
||||
throw new RuntimeException("Expected vertex format to have a POSITION attribute");
|
||||
if (element.getType() != VertexFormatElement.Type.FLOAT)
|
||||
throw new RuntimeException("Expected POSITION attribute to have data type FLOAT");
|
||||
if (element.getSize() < 3)
|
||||
throw new RuntimeException("Expected POSITION attribute to have at least 3 dimensions");
|
||||
return fmt.getOffset(index);
|
||||
}
|
||||
|
||||
private static int findNormalOffset(VertexFormat fmt)
|
||||
{
|
||||
int index;
|
||||
VertexFormatElement element = null;
|
||||
for (index = 0; index < fmt.func_227894_c_().size(); index++)
|
||||
{
|
||||
VertexFormatElement el = fmt.func_227894_c_().get(index);
|
||||
if (el.getUsage() == VertexFormatElement.Usage.NORMAL)
|
||||
{
|
||||
element = el;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (index == fmt.func_227894_c_().size() || element == null)
|
||||
return -1;
|
||||
if (element.getType() != VertexFormatElement.Type.BYTE)
|
||||
throw new RuntimeException("Expected NORMAL attribute to have data type BYTE");
|
||||
if (element.getSize() < 3)
|
||||
throw new RuntimeException("Expected NORMAL attribute to have at least 3 dimensions");
|
||||
return fmt.getOffset(index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes a single quad, producing a new quad.
|
||||
* @param input A single quad to transform.
|
||||
* @return A new BakedQuad object with the new position.
|
||||
*/
|
||||
public BakedQuad processOne(BakedQuad input)
|
||||
{
|
||||
int[] inData = input.getVertexData();
|
||||
int[] outData = Arrays.copyOf(inData, inData.length);
|
||||
processVertices(inData, outData);
|
||||
|
||||
return new BakedQuad(outData, input.getTintIndex(), input.getFace(), input.getSprite(), input.shouldApplyDiffuseLighting(), format);
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes a single quad, modifying the input quad.
|
||||
* @param input A single quad to transform.
|
||||
* @return The input BakedQuad object with the new position applied.
|
||||
*/
|
||||
public BakedQuad processOneInPlace(BakedQuad input)
|
||||
{
|
||||
int[] data = input.getVertexData();
|
||||
processVertices(data, data);
|
||||
return input;
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes multiple quads, producing a new array of new quads.
|
||||
* @param inputs The list of quads to transform
|
||||
* @return A new array of new BakedQuad objects.
|
||||
*/
|
||||
public List<BakedQuad> processMany(List<BakedQuad> inputs)
|
||||
{
|
||||
if(inputs.size() == 0)
|
||||
return Collections.emptyList();
|
||||
|
||||
List<BakedQuad> outputs = Lists.newArrayList();
|
||||
for(BakedQuad input : inputs)
|
||||
{
|
||||
int[] inData = input.getVertexData();
|
||||
int[] outData = Arrays.copyOf(inData, inData.length);
|
||||
processVertices(inData, outData);
|
||||
|
||||
outputs.add(new BakedQuad(outData, input.getTintIndex(), input.getFace(), input.getSprite(), input.shouldApplyDiffuseLighting(), format));
|
||||
}
|
||||
return outputs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes multiple quads in place, modifying the input quads.
|
||||
* @param inputs The list of quads to transform
|
||||
*/
|
||||
public void processManyInPlace(List<BakedQuad> inputs)
|
||||
{
|
||||
if(inputs.size() == 0)
|
||||
return;
|
||||
|
||||
for(BakedQuad input : inputs)
|
||||
{
|
||||
int[] data = input.getVertexData();
|
||||
processVertices(data, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,17 +19,16 @@
|
||||
|
||||
package net.minecraftforge.client.model;
|
||||
|
||||
import javax.vecmath.Matrix4f;
|
||||
import javax.vecmath.Vector3f;
|
||||
import javax.vecmath.Vector4f;
|
||||
|
||||
import net.minecraft.client.renderer.Matrix4f;
|
||||
import net.minecraft.client.renderer.TransformationMatrix;
|
||||
import net.minecraft.client.renderer.Vector3f;
|
||||
import net.minecraft.client.renderer.Vector4f;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormatElement;
|
||||
import net.minecraftforge.client.model.pipeline.UnpackedBakedQuad;
|
||||
import net.minecraftforge.common.model.TRSRTransformation;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import net.minecraft.client.GameSettings;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.renderer.model.BakedQuad;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
@@ -41,7 +40,7 @@ import net.minecraft.util.ResourceLocation;
|
||||
public abstract class SimpleModelFontRenderer extends FontRenderer {
|
||||
|
||||
private float r, g, b, a;
|
||||
private final TRSRTransformation transform;
|
||||
private final TransformationMatrix transform;
|
||||
private ImmutableList.Builder<BakedQuad> builder = ImmutableList.builder();
|
||||
private final VertexFormat format;
|
||||
private final Vector3f normal = new Vector3f(0, 0, 1);
|
||||
@@ -53,10 +52,10 @@ public abstract class SimpleModelFontRenderer extends FontRenderer {
|
||||
public SimpleModelFontRenderer(GameSettings settings, ResourceLocation font, TextureManager manager, boolean isUnicode, Matrix4f matrix, VertexFormat format)
|
||||
{
|
||||
super(manager, null);
|
||||
this.transform = new TRSRTransformation(matrix);
|
||||
this.transform = new TransformationMatrix(matrix);
|
||||
this.format = format;
|
||||
transform.transformNormal(normal);
|
||||
orientation = Direction.getFacingFromVector(normal.x, normal.y, normal.z);
|
||||
orientation = Direction.getFacingFromVector(normal.getX(), normal.getY(), normal.getZ());
|
||||
}
|
||||
|
||||
public void setSprite(TextureAtlasSprite sprite)
|
||||
@@ -73,14 +72,16 @@ public abstract class SimpleModelFontRenderer extends FontRenderer {
|
||||
|
||||
private void addVertex(UnpackedBakedQuad.Builder quadBuilder, float x, float y, float u, float v)
|
||||
{
|
||||
for(int e = 0; e < format.getElementCount(); e++)
|
||||
ImmutableList<VertexFormatElement> elements = format.func_227894_c_();
|
||||
for(int e = 0; e < elements.size(); e++)
|
||||
{
|
||||
switch(format.getElement(e).getUsage())
|
||||
VertexFormatElement element = elements.get(e);
|
||||
switch(element.getUsage())
|
||||
{
|
||||
case POSITION:
|
||||
vec.set(x, y, 0f, 1f);
|
||||
transform.transformPosition(vec);
|
||||
quadBuilder.put(e, vec.x, vec.y, vec.z, vec.w);
|
||||
quadBuilder.put(e, vec.getX(), vec.getY(), vec.getZ(), vec.getW());
|
||||
break;
|
||||
case COLOR:
|
||||
quadBuilder.put(e, r, g, b, a);
|
||||
@@ -90,7 +91,7 @@ public abstract class SimpleModelFontRenderer extends FontRenderer {
|
||||
quadBuilder.put(e, 0, 0, 1, 1);
|
||||
break;
|
||||
case UV:
|
||||
if(format.getElement(e).getIndex() == 0)
|
||||
if(element.getIndex() == 0)
|
||||
{
|
||||
quadBuilder.put(e, sprite.getInterpolatedU(u * 16), sprite.getInterpolatedV(v * 16), 0, 1);
|
||||
break;
|
||||
|
||||
@@ -19,50 +19,39 @@
|
||||
|
||||
package net.minecraftforge.client.model;
|
||||
|
||||
import net.minecraft.client.renderer.texture.ISprite;
|
||||
import net.minecraftforge.common.model.IModelPart;
|
||||
import net.minecraftforge.common.model.IModelState;
|
||||
import net.minecraftforge.common.model.TRSRTransformation;
|
||||
import net.minecraft.client.renderer.TransformationMatrix;
|
||||
import net.minecraft.client.renderer.model.IModelTransform;
|
||||
|
||||
import java.util.Optional;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
/**
|
||||
* Simple implementation of IModelState via a map and a default value.
|
||||
*/
|
||||
public final class SimpleModelState implements IModelState, ISprite
|
||||
public final class SimpleModelState implements IModelTransform
|
||||
{
|
||||
private final ImmutableMap<? extends IModelPart, TRSRTransformation> map;
|
||||
private final Optional<TRSRTransformation> def;
|
||||
private final ImmutableMap<? extends Object, TransformationMatrix> map;
|
||||
private final TransformationMatrix def;
|
||||
|
||||
public SimpleModelState(ImmutableMap<? extends IModelPart, TRSRTransformation> map)
|
||||
public SimpleModelState(ImmutableMap<? extends Object, TransformationMatrix> map)
|
||||
{
|
||||
this(map, Optional.empty());
|
||||
this(map, TransformationMatrix.func_227983_a_());
|
||||
}
|
||||
|
||||
public SimpleModelState(ImmutableMap<? extends IModelPart, TRSRTransformation> map, Optional<TRSRTransformation> def)
|
||||
public SimpleModelState(ImmutableMap<? extends Object, TransformationMatrix> map, TransformationMatrix def)
|
||||
{
|
||||
this.map = map;
|
||||
this.def = def;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IModelState getState()
|
||||
public TransformationMatrix func_225615_b_()
|
||||
{
|
||||
return this;
|
||||
return def;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<TRSRTransformation> apply(Optional<? extends IModelPart> part)
|
||||
public TransformationMatrix getPartTransformation(Object part)
|
||||
{
|
||||
if(!part.isPresent())
|
||||
{
|
||||
return def;
|
||||
}
|
||||
if(!map.containsKey(part.get()))
|
||||
{
|
||||
return Optional.empty();
|
||||
}
|
||||
return Optional.ofNullable(map.get(part.get()));
|
||||
return map.getOrDefault(part, TransformationMatrix.func_227983_a_());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Minecraft Forge
|
||||
* Copyright (c) 2016-2019.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation version 2.1
|
||||
* of the License.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package net.minecraftforge.client.model;
|
||||
|
||||
import net.minecraft.client.renderer.TransformationMatrix;
|
||||
import net.minecraft.client.renderer.model.IModelTransform;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
/**
|
||||
* Simple implementation of IModelState via a map and a default value.
|
||||
*/
|
||||
public final class SimpleModelTransform implements IModelTransform
|
||||
{
|
||||
public static final SimpleModelTransform IDENTITY = new SimpleModelTransform(TransformationMatrix.func_227983_a_());
|
||||
|
||||
private final ImmutableMap<?, TransformationMatrix> map;
|
||||
private final TransformationMatrix base;
|
||||
|
||||
public SimpleModelTransform(ImmutableMap<?, TransformationMatrix> map)
|
||||
{
|
||||
this(map, TransformationMatrix.func_227983_a_());
|
||||
}
|
||||
|
||||
public SimpleModelTransform(TransformationMatrix base)
|
||||
{
|
||||
this(ImmutableMap.of(), base);
|
||||
}
|
||||
|
||||
public SimpleModelTransform(ImmutableMap<?, TransformationMatrix> map, TransformationMatrix base)
|
||||
{
|
||||
this.map = map;
|
||||
this.base = base;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TransformationMatrix func_225615_b_()
|
||||
{
|
||||
return base;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TransformationMatrix getPartTransformation(Object part)
|
||||
{
|
||||
return map.getOrDefault(part, TransformationMatrix.func_227983_a_());
|
||||
}
|
||||
}
|
||||
+16
-22
@@ -20,13 +20,12 @@
|
||||
package net.minecraftforge.client.model.animation;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.model.IBakedModel;
|
||||
import net.minecraft.client.renderer.model.IUnbakedModel;
|
||||
import net.minecraft.client.renderer.model.ItemOverride;
|
||||
import net.minecraft.client.renderer.model.ItemOverrideList;
|
||||
import net.minecraft.client.renderer.model.ModelBakery;
|
||||
import net.minecraft.client.renderer.model.*;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormat;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
@@ -34,36 +33,31 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.client.model.ModelLoader;
|
||||
import net.minecraftforge.client.model.ModelLoaderRegistry;
|
||||
import net.minecraftforge.client.model.ModelStateComposition;
|
||||
import net.minecraftforge.common.model.IModelState;
|
||||
import net.minecraftforge.client.model.ModelTransformComposition;
|
||||
import net.minecraftforge.common.model.animation.CapabilityAnimation;
|
||||
import net.minecraftforge.common.model.animation.IAnimationStateMachine;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public final class AnimationItemOverrideList extends ItemOverrideList
|
||||
{
|
||||
private final ModelBakery bakery;
|
||||
private final IUnbakedModel model;
|
||||
private final IModelState state;
|
||||
private final VertexFormat format;
|
||||
private final Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter;
|
||||
private final ResourceLocation modelLoc;
|
||||
private final IModelTransform state;
|
||||
|
||||
public AnimationItemOverrideList(ModelBakery bakery, IUnbakedModel model, IModelState state, VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter, ItemOverrideList overrides)
|
||||
|
||||
private final Function<Material, TextureAtlasSprite> bakedTextureGetter;
|
||||
|
||||
public AnimationItemOverrideList(ModelBakery bakery, IUnbakedModel model, ResourceLocation modelLoc, IModelTransform state, Function<Material, TextureAtlasSprite> bakedTextureGetter, ItemOverrideList overrides)
|
||||
{
|
||||
this(bakery, model, state, format, bakedTextureGetter, overrides.getOverrides().reverse());
|
||||
this(bakery, model, modelLoc, state, bakedTextureGetter, overrides.getOverrides().reverse());
|
||||
}
|
||||
|
||||
public AnimationItemOverrideList(ModelBakery bakery, IUnbakedModel model, IModelState state, VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter, List<ItemOverride> overrides)
|
||||
public AnimationItemOverrideList(ModelBakery bakery, IUnbakedModel model, ResourceLocation modelLoc, IModelTransform state, Function<Material, TextureAtlasSprite> bakedTextureGetter, List<ItemOverride> overrides)
|
||||
{
|
||||
super(bakery, model, ModelLoader.defaultModelGetter(), bakedTextureGetter, overrides, format);
|
||||
super(bakery, model, ModelLoader.defaultModelGetter(), bakedTextureGetter, overrides);
|
||||
this.bakery = bakery;
|
||||
this.model = model;
|
||||
this.modelLoc = modelLoc;
|
||||
this.state = state;
|
||||
this.format = format;
|
||||
this.bakedTextureGetter = bakedTextureGetter;
|
||||
}
|
||||
|
||||
@@ -86,7 +80,7 @@ public final class AnimationItemOverrideList extends ItemOverrideList
|
||||
return asm.apply(Animation.getWorldTime(world, Animation.getPartialTickTime())).getLeft();
|
||||
})
|
||||
// TODO where should uvlock data come from?
|
||||
.map(state -> model.bake(bakery, bakedTextureGetter, new ModelStateComposition(state, this.state), format))
|
||||
.map(state -> model.func_225613_a_(bakery, bakedTextureGetter, new ModelTransformComposition(state, this.state), modelLoc))
|
||||
.orElseGet(() -> super.getModelWithOverrides(originalModel, stack, world, entity));
|
||||
}
|
||||
}
|
||||
@@ -35,7 +35,6 @@ import net.minecraft.block.Blocks;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.client.model.BasicState;
|
||||
import net.minecraftforge.client.model.ModelLoader;
|
||||
import net.minecraftforge.client.model.ModelLoaderRegistry;
|
||||
import net.minecraftforge.client.model.pipeline.VertexLighterFlat;
|
||||
|
||||
@@ -33,10 +33,12 @@ import java.util.TreeMap;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.vecmath.AxisAngle4f;
|
||||
import javax.vecmath.Matrix4f;
|
||||
import javax.vecmath.Quat4f;
|
||||
import javax.vecmath.Vector3f;
|
||||
|
||||
import net.minecraft.client.renderer.Matrix4f;
|
||||
import net.minecraft.client.renderer.Quaternion;
|
||||
import net.minecraft.client.renderer.TransformationMatrix;
|
||||
import net.minecraft.client.renderer.Vector3f;
|
||||
import net.minecraft.client.renderer.model.IModelTransform;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@@ -49,8 +51,7 @@ import net.minecraftforge.client.model.animation.ModelBlockAnimation.Parameter.I
|
||||
import net.minecraftforge.client.model.animation.ModelBlockAnimation.Parameter.Type;
|
||||
import net.minecraftforge.client.model.animation.ModelBlockAnimation.Parameter.Variable;
|
||||
import net.minecraftforge.common.animation.Event;
|
||||
import net.minecraftforge.common.model.IModelState;
|
||||
import net.minecraftforge.common.model.TRSRTransformation;
|
||||
import net.minecraftforge.common.model.TransformationHelper;
|
||||
import net.minecraftforge.common.model.animation.IClip;
|
||||
import net.minecraftforge.common.model.animation.IJoint;
|
||||
import net.minecraftforge.common.model.animation.IJointClip;
|
||||
@@ -327,7 +328,7 @@ public class ModelBlockAnimation
|
||||
}
|
||||
|
||||
@Override
|
||||
public TRSRTransformation apply(float time)
|
||||
public TransformationMatrix apply(float time)
|
||||
{
|
||||
time -= Math.floor(time);
|
||||
Vector3f translation = new Vector3f(0, 0, 0);
|
||||
@@ -365,13 +366,13 @@ public class ModelBlockAnimation
|
||||
switch(var.variable)
|
||||
{
|
||||
case X:
|
||||
translation.x = value;
|
||||
translation.setX(value);
|
||||
break;
|
||||
case Y:
|
||||
translation.y = value;
|
||||
translation.setY(value);
|
||||
break;
|
||||
case Z:
|
||||
translation.z = value;
|
||||
translation.setZ(value);
|
||||
break;
|
||||
case XROT:
|
||||
rotation.x = value;
|
||||
@@ -386,35 +387,34 @@ public class ModelBlockAnimation
|
||||
rotation.angle = (float)Math.toRadians(value);
|
||||
break;
|
||||
case SCALE:
|
||||
scale.x = scale.y = scale.z = value;
|
||||
scale.set(value, value, value);
|
||||
break;
|
||||
case XS:
|
||||
scale.x = value;
|
||||
scale.setX(value);
|
||||
break;
|
||||
case YS:
|
||||
scale.y = value;
|
||||
scale.setY(value);
|
||||
break;
|
||||
case ZS:
|
||||
scale.z = value;
|
||||
scale.setX(value);
|
||||
break;
|
||||
case XORIGIN:
|
||||
origin.x = value - 0.5F;
|
||||
origin.setX(value - 0.5F);
|
||||
break;
|
||||
case YORIGIN:
|
||||
origin.y = value - 0.5F;
|
||||
origin.setY(value - 0.5F);
|
||||
break;
|
||||
case ZORIGIN:
|
||||
origin.z = value - 0.5F;
|
||||
origin.setX(value - 0.5F);
|
||||
break;
|
||||
}
|
||||
}
|
||||
Quat4f rot = new Quat4f();
|
||||
rot.set(rotation);
|
||||
TRSRTransformation base = new TRSRTransformation(translation, rot, scale, null);
|
||||
Vector3f negOrigin = new Vector3f(origin);
|
||||
negOrigin.negate();
|
||||
base = new TRSRTransformation(origin, null, null, null).compose(base).compose(new TRSRTransformation(negOrigin, null, null, null));
|
||||
return TRSRTransformation.blockCenterToCorner(base);
|
||||
Quaternion rot = new Quaternion(new Vector3f(rotation.x, rotation.y, rotation.z), rotation.angle, false);
|
||||
TransformationMatrix base = new TransformationMatrix(translation, rot, scale, null);
|
||||
Vector3f negOrigin = origin.func_229195_e_();
|
||||
negOrigin.func_229192_b_(-1,-1,-1);
|
||||
base = new TransformationMatrix(origin, null, null, null).compose(base).compose(new TransformationMatrix(negOrigin, null, null, null));
|
||||
return TransformationHelper.blockCenterToCorner(base);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -429,9 +429,9 @@ public class ModelBlockAnimation
|
||||
}
|
||||
|
||||
@Override
|
||||
public TRSRTransformation getInvBindPose()
|
||||
public TransformationMatrix getInvBindPose()
|
||||
{
|
||||
return TRSRTransformation.identity();
|
||||
return TransformationMatrix.func_227983_a_();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -518,7 +518,13 @@ public class ModelBlockAnimation
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public TRSRTransformation getPartTransform(IModelState state, BlockPart part, int i)
|
||||
public TransformationMatrix getPartTransform(IModelTransform state, BlockPart part, int i)
|
||||
{
|
||||
return getPartTransform(state, i);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public TransformationMatrix getPartTransform(IModelTransform state, int i)
|
||||
{
|
||||
ImmutableCollection<MBJointWeight> infos = getJoint(i);
|
||||
if(!infos.isEmpty())
|
||||
@@ -530,12 +536,12 @@ public class ModelBlockAnimation
|
||||
if(info.getWeights().containsKey(i))
|
||||
{
|
||||
ModelBlockAnimation.MBJoint joint = new ModelBlockAnimation.MBJoint(info.getName());
|
||||
Optional<TRSRTransformation> trOp = state.apply(Optional.of(joint));
|
||||
if(trOp.isPresent() && !trOp.get().isIdentity())
|
||||
TransformationMatrix trOp = state.getPartTransformation(joint);
|
||||
if(!trOp.isIdentity())
|
||||
{
|
||||
float w = info.getWeights().get(i)[0];
|
||||
tmp = trOp.get().getMatrixVec();
|
||||
tmp.mul(w);
|
||||
tmp = trOp.func_227988_c_();
|
||||
tmp.func_226592_a_(w);
|
||||
m.add(tmp);
|
||||
weight += w;
|
||||
}
|
||||
@@ -543,8 +549,8 @@ public class ModelBlockAnimation
|
||||
}
|
||||
if(weight > 1e-5)
|
||||
{
|
||||
m.mul(1f / weight);
|
||||
return new TRSRTransformation(m);
|
||||
m.func_226592_a_(1f / weight);
|
||||
return new TransformationMatrix(m);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
+18
-11
@@ -21,14 +21,19 @@ package net.minecraftforge.client.model.animation;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.Atlases;
|
||||
import net.minecraft.client.renderer.BlockRendererDispatcher;
|
||||
import net.minecraft.client.renderer.BufferBuilder;
|
||||
import net.minecraft.client.renderer.IRenderTypeBuffer;
|
||||
import net.minecraft.client.renderer.model.IBakedModel;
|
||||
import net.minecraft.client.renderer.tileentity.TileEntityRenderer;
|
||||
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IWorldReader;
|
||||
import net.minecraft.world.ILightReader;
|
||||
import net.minecraftforge.client.MinecraftForgeClient;
|
||||
import net.minecraftforge.client.model.ModelDataManager;
|
||||
import net.minecraftforge.client.model.data.IModelData;
|
||||
@@ -42,12 +47,17 @@ import net.minecraftforge.common.util.LazyOptional;
|
||||
/**
|
||||
* Generic {@link TileGameRenderer} that works with the Forge model system and animations.
|
||||
*/
|
||||
public class TileEntityRendererAnimation<T extends TileEntity> extends TileEntityRendererFast<T> implements IEventHandler<T>
|
||||
public class TileEntityRendererAnimation<T extends TileEntity> extends TileEntityRenderer<T> implements IEventHandler<T>
|
||||
{
|
||||
protected static BlockRendererDispatcher blockRenderer;
|
||||
public TileEntityRendererAnimation(TileEntityRendererDispatcher p_i226006_1_)
|
||||
{
|
||||
super(p_i226006_1_);
|
||||
}
|
||||
|
||||
protected static BlockRendererDispatcher blockRenderer;
|
||||
|
||||
@Override
|
||||
public void renderTileEntityFast(T te, double x, double y, double z, float partialTick, int breakStage, BufferBuilder renderer)
|
||||
public void func_225616_a_(T te, float partialTick, MatrixStack mat, IRenderTypeBuffer renderer, int light, int otherlight)
|
||||
{
|
||||
LazyOptional<IAnimationStateMachine> cap = te.getCapability(CapabilityAnimation.ANIMATION_CAPABILITY);
|
||||
if(!cap.isPresent())
|
||||
@@ -56,13 +66,13 @@ public class TileEntityRendererAnimation<T extends TileEntity> extends TileEntit
|
||||
}
|
||||
if(blockRenderer == null) blockRenderer = Minecraft.getInstance().getBlockRendererDispatcher();
|
||||
BlockPos pos = te.getPos();
|
||||
net.minecraft.world.IEnviromentBlockReader world = MinecraftForgeClient.getRegionRenderCache(te.getWorld(), pos);
|
||||
ILightReader world = MinecraftForgeClient.getRegionRenderCache(te.getWorld(), pos);
|
||||
BlockState state = world.getBlockState(pos);
|
||||
IBakedModel model = blockRenderer.getBlockModelShapes().getModel(state);
|
||||
IModelData data = model.getModelData(world, pos, state, ModelDataManager.getModelData(te.getWorld(), pos));
|
||||
if (data.hasProperty(Properties.AnimationProperty))
|
||||
{
|
||||
float time = Animation.getWorldTime(getWorld(), partialTick);
|
||||
float time = Animation.getWorldTime(Minecraft.getInstance().world, partialTick);
|
||||
cap
|
||||
.map(asm -> asm.apply(time))
|
||||
.ifPresent(pair -> {
|
||||
@@ -70,10 +80,7 @@ public class TileEntityRendererAnimation<T extends TileEntity> extends TileEntit
|
||||
|
||||
// TODO: caching?
|
||||
data.setData(Properties.AnimationProperty, pair.getLeft());
|
||||
|
||||
renderer.setTranslation(x - pos.getX(), y - pos.getY(), z - pos.getZ());
|
||||
|
||||
blockRenderer.getBlockModelRenderer().renderModel(world, model, state, pos, renderer, false, new Random(), 42, data);
|
||||
blockRenderer.getBlockModelRenderer().renderModel(world, model, state, pos, mat, renderer.getBuffer(Atlases.func_228782_g_()), false, new Random(), 42, light, data);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,95 +0,0 @@
|
||||
/*
|
||||
* Minecraft Forge
|
||||
* Copyright (c) 2016-2019.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation version 2.1
|
||||
* of the License.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package net.minecraftforge.client.model.animation;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import com.mojang.blaze3d.platform.GlStateManager;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.RenderHelper;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.client.renderer.BufferBuilder;
|
||||
import net.minecraft.client.renderer.texture.AtlasTexture;
|
||||
import net.minecraft.client.renderer.tileentity.TileEntityRenderer;
|
||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormat;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
/**
|
||||
* A special case {@link TileGameRenderer} which can be batched with other
|
||||
* renderers that are also instances of this class.
|
||||
* <p>
|
||||
* Advantages:
|
||||
* <ul>
|
||||
* <li>All batched renderers are drawn with a single draw call</li>
|
||||
* <li>Renderers have their vertices depth sorted for better translucency
|
||||
* support</li>
|
||||
* </ul>
|
||||
* <p>
|
||||
* Disadvantages:
|
||||
* <ul>
|
||||
* <li>OpenGL operations are not permitted</li>
|
||||
* <li>All renderers must use the same {@link VertexFormat}
|
||||
* ({@link DefaultVertexFormats#BLOCK})</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param <T> The type of {@link TileEntity} being rendered.
|
||||
*/
|
||||
public abstract class TileEntityRendererFast<T extends TileEntity> extends TileEntityRenderer<T>
|
||||
{
|
||||
@Override
|
||||
public final void render(T te, double x, double y, double z, float partialTicks, int destroyStage)
|
||||
{
|
||||
Tessellator tessellator = Tessellator.getInstance();
|
||||
BufferBuilder buffer = tessellator.getBuffer();
|
||||
this.bindTexture(AtlasTexture.LOCATION_BLOCKS_TEXTURE);
|
||||
RenderHelper.disableStandardItemLighting();
|
||||
GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
||||
GlStateManager.enableBlend();
|
||||
GlStateManager.disableCull();
|
||||
|
||||
if (Minecraft.isAmbientOcclusionEnabled())
|
||||
{
|
||||
GlStateManager.shadeModel(GL11.GL_SMOOTH);
|
||||
}
|
||||
else
|
||||
{
|
||||
GlStateManager.shadeModel(GL11.GL_FLAT);
|
||||
}
|
||||
|
||||
buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
|
||||
|
||||
renderTileEntityFast(te, x, y, z, partialTicks, destroyStage, buffer);
|
||||
buffer.setTranslation(0, 0, 0);
|
||||
|
||||
tessellator.draw();
|
||||
|
||||
RenderHelper.enableStandardItemLighting();
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw this renderer to the passed {@link BufferBuilder}. <strong>DO
|
||||
* NOT</strong> draw to any buffers other than the one passed, or use any OpenGL
|
||||
* operations as they will not be applied when this renderer is batched.
|
||||
*/
|
||||
@Override
|
||||
public abstract void renderTileEntityFast(T te, double x, double y, double z, float partialTicks, int destroyStage, BufferBuilder buffer);
|
||||
}
|
||||
@@ -19,11 +19,12 @@
|
||||
|
||||
package net.minecraftforge.client.model.b3d;
|
||||
|
||||
import net.minecraft.client.renderer.TransformationMatrix;
|
||||
import net.minecraftforge.client.model.b3d.B3DLoader.NodeJoint;
|
||||
import net.minecraftforge.client.model.b3d.B3DModel.Key;
|
||||
import net.minecraftforge.client.model.b3d.B3DModel.Node;
|
||||
import net.minecraftforge.common.animation.Event;
|
||||
import net.minecraftforge.common.model.TRSRTransformation;
|
||||
import net.minecraftforge.common.model.TransformationHelper;
|
||||
import net.minecraftforge.common.model.animation.IClip;
|
||||
import net.minecraftforge.common.model.animation.IJoint;
|
||||
import net.minecraftforge.common.model.animation.IJointClip;
|
||||
@@ -62,25 +63,25 @@ public enum B3DClip implements IClip
|
||||
}
|
||||
|
||||
@Override
|
||||
public TRSRTransformation apply(float time)
|
||||
public TransformationMatrix apply(float time)
|
||||
{
|
||||
TRSRTransformation ret = TRSRTransformation.identity();
|
||||
TransformationMatrix ret = TransformationMatrix.func_227983_a_();
|
||||
if(node.getAnimation() == null)
|
||||
{
|
||||
return ret.compose(new TRSRTransformation(node.getPos(), node.getRot(), node.getScale(), null));
|
||||
return ret.compose(B3DLoader.fromVecmath(node.getPos(), node.getRot(), node.getScale(), null));
|
||||
}
|
||||
int start = Math.max(1, (int)Math.round(Math.floor(time)));
|
||||
int end = Math.min(start + 1, (int)Math.round(Math.ceil(time)));
|
||||
float progress = time - (float)Math.floor(time);
|
||||
Key keyStart = node.getAnimation().getKeys().get(start, node);
|
||||
Key keyEnd = node.getAnimation().getKeys().get(end, node);
|
||||
TRSRTransformation startTr = keyStart == null ? null : new TRSRTransformation(keyStart.getPos(), keyStart.getRot(),keyStart.getScale(), null);
|
||||
TRSRTransformation endTr = keyEnd == null ? null : new TRSRTransformation(keyEnd.getPos(), keyEnd.getRot(),keyEnd.getScale(), null);
|
||||
TransformationMatrix startTr = keyStart == null ? null : B3DLoader.fromVecmath(keyStart.getPos(), keyStart.getRot(),keyStart.getScale(), null);
|
||||
TransformationMatrix endTr = keyEnd == null ? null : B3DLoader.fromVecmath(keyEnd.getPos(), keyEnd.getRot(),keyEnd.getScale(), null);
|
||||
if(keyStart == null)
|
||||
{
|
||||
if(keyEnd == null)
|
||||
{
|
||||
ret = ret.compose(new TRSRTransformation(node.getPos(), node.getRot(), node.getScale(), null));
|
||||
ret = ret.compose(B3DLoader.fromVecmath(node.getPos(), node.getRot(), node.getScale(), null));
|
||||
}
|
||||
// TODO animated TRSRTransformation for speed?
|
||||
else
|
||||
@@ -94,7 +95,7 @@ public enum B3DClip implements IClip
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = ret.compose(startTr.slerp(endTr, progress));
|
||||
ret = ret.compose(TransformationHelper.slerp(startTr, endTr, progress));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -32,15 +32,25 @@ import java.util.Random;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.vecmath.Matrix4f;
|
||||
import javax.vecmath.Vector3f;
|
||||
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import net.minecraft.client.renderer.TransformationMatrix;
|
||||
import net.minecraft.client.renderer.model.*;
|
||||
import net.minecraft.client.renderer.texture.ISprite;
|
||||
import net.minecraft.client.renderer.texture.AtlasTexture;
|
||||
import net.minecraft.client.renderer.texture.MissingTextureSprite;
|
||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormatElement;
|
||||
import net.minecraftforge.client.model.*;
|
||||
import net.minecraftforge.common.model.*;
|
||||
import net.minecraftforge.resource.IResourceType;
|
||||
import net.minecraftforge.resource.ISelectiveResourceReloadListener;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.apache.commons.lang3.tuple.Triple;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
@@ -49,7 +59,6 @@ import com.google.common.base.Objects;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
import com.google.common.collect.Collections2;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
@@ -65,11 +74,6 @@ import net.minecraft.resources.IResourceManager;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraftforge.client.model.ICustomModelLoader;
|
||||
import net.minecraftforge.client.model.ModelLoader;
|
||||
import net.minecraftforge.client.model.ModelLoaderRegistry;
|
||||
import net.minecraftforge.client.model.ModelStateComposition;
|
||||
import net.minecraftforge.client.model.PerspectiveMapWrapper;
|
||||
import net.minecraftforge.client.model.b3d.B3DModel.Animation;
|
||||
import net.minecraftforge.client.model.b3d.B3DModel.Face;
|
||||
import net.minecraftforge.client.model.b3d.B3DModel.Key;
|
||||
@@ -80,10 +84,6 @@ import net.minecraftforge.client.model.b3d.B3DModel.Vertex;
|
||||
import net.minecraftforge.client.model.data.IDynamicBakedModel;
|
||||
import net.minecraftforge.client.model.data.IModelData;
|
||||
import net.minecraftforge.client.model.pipeline.UnpackedBakedQuad;
|
||||
import net.minecraftforge.common.model.IModelPart;
|
||||
import net.minecraftforge.common.model.IModelState;
|
||||
import net.minecraftforge.common.model.Models;
|
||||
import net.minecraftforge.common.model.TRSRTransformation;
|
||||
import net.minecraftforge.common.model.animation.IClip;
|
||||
import net.minecraftforge.common.model.animation.IJoint;
|
||||
import net.minecraftforge.common.property.Properties;
|
||||
@@ -93,7 +93,8 @@ import net.minecraftforge.common.property.Properties;
|
||||
* To enable for your mod call instance.addDomain(modId).
|
||||
* If you need more control over accepted resources - extend the class, and register a new instance with ModelLoaderRegistry.
|
||||
*/
|
||||
public enum B3DLoader implements ICustomModelLoader
|
||||
// TODO: Implement as a new model loader
|
||||
public enum B3DLoader implements ISelectiveResourceReloadListener
|
||||
{
|
||||
INSTANCE;
|
||||
|
||||
@@ -104,25 +105,13 @@ public enum B3DLoader implements ICustomModelLoader
|
||||
private final Set<String> enabledDomains = new HashSet<>();
|
||||
private final Map<ResourceLocation, B3DModel> cache = new HashMap<>();
|
||||
|
||||
public void addDomain(String domain)
|
||||
{
|
||||
enabledDomains.add(domain.toLowerCase());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResourceManagerReload(IResourceManager manager)
|
||||
public void onResourceManagerReload(IResourceManager manager, Predicate<IResourceType> resourcePredicate)
|
||||
{
|
||||
this.manager = manager;
|
||||
cache.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean accepts(ResourceLocation modelLocation)
|
||||
{
|
||||
return enabledDomains.contains(modelLocation.getNamespace()) && modelLocation.getPath().endsWith(".b3d");
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public IUnbakedModel loadModel(ResourceLocation modelLocation) throws Exception
|
||||
{
|
||||
@@ -159,7 +148,7 @@ public enum B3DLoader implements ICustomModelLoader
|
||||
}
|
||||
}
|
||||
B3DModel model = cache.get(file);
|
||||
if(model == null) throw new ModelLoaderRegistry.LoaderException("Error loading model previously: " + file);
|
||||
if(model == null) throw new ModelLoadingException("Error loading model previously: " + file);
|
||||
if(!(model.getRoot().getKind() instanceof Mesh))
|
||||
{
|
||||
return new ModelWrapper(modelLocation, model, ImmutableSet.of(), true, true, 1);
|
||||
@@ -167,7 +156,13 @@ public enum B3DLoader implements ICustomModelLoader
|
||||
return new ModelWrapper(modelLocation, model, ImmutableSet.of(model.getRoot().getName()), true, true, 1);
|
||||
}
|
||||
|
||||
public static final class B3DState implements IModelState
|
||||
@Deprecated // TODO: Does a lot of unnecessary work converting things, should use the TransformationMatrix constructor directly with mojang vector classes instead.
|
||||
public static TransformationMatrix fromVecmath(javax.vecmath.Vector3f pos, javax.vecmath.Quat4f rot, javax.vecmath.Vector3f scale, javax.vecmath.Quat4f rot2)
|
||||
{
|
||||
return new TransformationMatrix(TransformationHelper.toMojang(pos), TransformationHelper.toMojang(rot), TransformationHelper.toMojang(scale), TransformationHelper.toMojang(rot2));
|
||||
}
|
||||
|
||||
public static final class B3DState implements IModelTransform
|
||||
{
|
||||
@Nullable
|
||||
private final Animation animation;
|
||||
@@ -175,14 +170,14 @@ public enum B3DLoader implements ICustomModelLoader
|
||||
private final int nextFrame;
|
||||
private final float progress;
|
||||
@Nullable
|
||||
private final IModelState parent;
|
||||
private final IModelTransform parent;
|
||||
|
||||
public B3DState(@Nullable Animation animation, int frame)
|
||||
{
|
||||
this(animation, frame, frame, 0);
|
||||
}
|
||||
|
||||
public B3DState(@Nullable Animation animation, int frame, IModelState parent)
|
||||
public B3DState(@Nullable Animation animation, int frame, IModelTransform parent)
|
||||
{
|
||||
this(animation, frame, frame, 0, parent);
|
||||
}
|
||||
@@ -192,7 +187,7 @@ public enum B3DLoader implements ICustomModelLoader
|
||||
this(animation, frame, nextFrame, progress, null);
|
||||
}
|
||||
|
||||
public B3DState(@Nullable Animation animation, int frame, int nextFrame, float progress, @Nullable IModelState parent)
|
||||
public B3DState(@Nullable Animation animation, int frame, int nextFrame, float progress, @Nullable IModelTransform parent)
|
||||
{
|
||||
this.animation = animation;
|
||||
this.frame = frame;
|
||||
@@ -202,7 +197,7 @@ public enum B3DLoader implements ICustomModelLoader
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private IModelState getParent(@Nullable IModelState parent)
|
||||
private IModelTransform getParent(@Nullable IModelTransform parent)
|
||||
{
|
||||
if (parent == null) return null;
|
||||
else if (parent instanceof B3DState) return ((B3DState)parent).parent;
|
||||
@@ -231,29 +226,33 @@ public enum B3DLoader implements ICustomModelLoader
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public IModelState getParent()
|
||||
public IModelTransform getParent()
|
||||
{
|
||||
return parent;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Optional<TRSRTransformation> apply(Optional<? extends IModelPart> part)
|
||||
public TransformationMatrix func_225615_b_()
|
||||
{
|
||||
if(parent != null)
|
||||
{
|
||||
return parent.func_225615_b_();
|
||||
}
|
||||
return TransformationMatrix.func_227983_a_();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TransformationMatrix getPartTransformation(Object part)
|
||||
{
|
||||
// TODO make more use of Optional
|
||||
if(!part.isPresent())
|
||||
|
||||
if(!(part instanceof NodeJoint))
|
||||
{
|
||||
if(parent != null)
|
||||
{
|
||||
return parent.apply(part);
|
||||
}
|
||||
return Optional.empty();
|
||||
return TransformationMatrix.func_227983_a_();
|
||||
}
|
||||
if(!(part.get() instanceof NodeJoint))
|
||||
{
|
||||
return Optional.empty();
|
||||
}
|
||||
Node<?> node = ((NodeJoint)part.get()).getNode();
|
||||
TRSRTransformation nodeTransform;
|
||||
Node<?> node = ((NodeJoint)part).getNode();
|
||||
TransformationMatrix nodeTransform;
|
||||
if(progress < 1e-5 || frame == nextFrame)
|
||||
{
|
||||
nodeTransform = getNodeMatrix(node, frame);
|
||||
@@ -265,40 +264,40 @@ public enum B3DLoader implements ICustomModelLoader
|
||||
else
|
||||
{
|
||||
nodeTransform = getNodeMatrix(node, frame);
|
||||
nodeTransform = nodeTransform.slerp(getNodeMatrix(node, nextFrame), progress);
|
||||
nodeTransform = TransformationHelper.slerp(nodeTransform,getNodeMatrix(node, nextFrame), progress);
|
||||
}
|
||||
if(parent != null && node.getParent() == null)
|
||||
{
|
||||
return Optional.of(parent.apply(part).orElse(TRSRTransformation.identity()).compose(nodeTransform));
|
||||
return parent.getPartTransformation(part).compose(nodeTransform);
|
||||
}
|
||||
return Optional.of(nodeTransform);
|
||||
return nodeTransform;
|
||||
}
|
||||
|
||||
private static LoadingCache<Triple<Animation, Node<?>, Integer>, TRSRTransformation> cache = CacheBuilder.newBuilder()
|
||||
private static LoadingCache<Triple<Animation, Node<?>, Integer>, TransformationMatrix> cache = CacheBuilder.newBuilder()
|
||||
.maximumSize(16384)
|
||||
.expireAfterAccess(2, TimeUnit.MINUTES)
|
||||
.build(new CacheLoader<Triple<Animation, Node<?>, Integer>, TRSRTransformation>()
|
||||
.build(new CacheLoader<Triple<Animation, Node<?>, Integer>, TransformationMatrix>()
|
||||
{
|
||||
@Override
|
||||
public TRSRTransformation load(Triple<Animation, Node<?>, Integer> key) throws Exception
|
||||
public TransformationMatrix load(Triple<Animation, Node<?>, Integer> key) throws Exception
|
||||
{
|
||||
return getNodeMatrix(key.getLeft(), key.getMiddle(), key.getRight());
|
||||
}
|
||||
});
|
||||
|
||||
public TRSRTransformation getNodeMatrix(Node<?> node)
|
||||
public TransformationMatrix getNodeMatrix(Node<?> node)
|
||||
{
|
||||
return getNodeMatrix(node, frame);
|
||||
}
|
||||
|
||||
public TRSRTransformation getNodeMatrix(Node<?> node, int frame)
|
||||
public TransformationMatrix getNodeMatrix(Node<?> node, int frame)
|
||||
{
|
||||
return cache.getUnchecked(Triple.of(animation, node, frame));
|
||||
}
|
||||
|
||||
public static TRSRTransformation getNodeMatrix(@Nullable Animation animation, Node<?> node, int frame)
|
||||
public static TransformationMatrix getNodeMatrix(@Nullable Animation animation, Node<?> node, int frame)
|
||||
{
|
||||
TRSRTransformation ret = TRSRTransformation.identity();
|
||||
TransformationMatrix ret = TransformationMatrix.func_227983_a_();
|
||||
Key key = null;
|
||||
if(animation != null) key = animation.getKeys().get(frame, node);
|
||||
else if(node.getAnimation() != null) key = node.getAnimation().getKeys().get(frame, node);
|
||||
@@ -308,13 +307,13 @@ public enum B3DLoader implements ICustomModelLoader
|
||||
if(parent != null)
|
||||
{
|
||||
// parent model-global current pose
|
||||
TRSRTransformation pm = cache.getUnchecked(Triple.of(animation, node.getParent(), frame));
|
||||
TransformationMatrix pm = cache.getUnchecked(Triple.of(animation, node.getParent(), frame));
|
||||
ret = ret.compose(pm);
|
||||
// joint offset in the parent coords
|
||||
ret = ret.compose(new TRSRTransformation(parent.getPos(), parent.getRot(), parent.getScale(), null));
|
||||
ret = ret.compose(fromVecmath(parent.getPos(), parent.getRot(), parent.getScale(), null));
|
||||
}
|
||||
// current node local pose
|
||||
ret = ret.compose(new TRSRTransformation(key.getPos(), key.getRot(), key.getScale(), null));
|
||||
ret = ret.compose(fromVecmath(key.getPos(), key.getRot(), key.getScale(), null));
|
||||
// this part moved inside the model
|
||||
// inverse bind of the current node
|
||||
/*Matrix4f rm = new TRSRTransformation(node.getPos(), node.getRot(), node.getScale(), null).getMatrix();
|
||||
@@ -328,7 +327,7 @@ public enum B3DLoader implements ICustomModelLoader
|
||||
ret = ret.compose(new TRSRTransformation(rm));
|
||||
}*/
|
||||
// TODO cache
|
||||
TRSRTransformation invBind = new NodeJoint(node).getInvBindPose();
|
||||
TransformationMatrix invBind = new NodeJoint(node).getInvBindPose();
|
||||
ret = ret.compose(invBind);
|
||||
}
|
||||
else
|
||||
@@ -337,14 +336,14 @@ public enum B3DLoader implements ICustomModelLoader
|
||||
if(parent != null)
|
||||
{
|
||||
// parent model-global current pose
|
||||
TRSRTransformation pm = cache.getUnchecked(Triple.of(animation, node.getParent(), frame));
|
||||
TransformationMatrix pm = cache.getUnchecked(Triple.of(animation, node.getParent(), frame));
|
||||
ret = ret.compose(pm);
|
||||
// joint offset in the parent coords
|
||||
ret = ret.compose(new TRSRTransformation(parent.getPos(), parent.getRot(), parent.getScale(), null));
|
||||
ret = ret.compose(fromVecmath(parent.getPos(), parent.getRot(), parent.getScale(), null));
|
||||
}
|
||||
ret = ret.compose(new TRSRTransformation(node.getPos(), node.getRot(), node.getScale(), null));
|
||||
ret = ret.compose(fromVecmath(node.getPos(), node.getRot(), node.getScale(), null));
|
||||
// TODO cache
|
||||
TRSRTransformation invBind = new NodeJoint(node).getInvBindPose();
|
||||
TransformationMatrix invBind = new NodeJoint(node).getInvBindPose();
|
||||
ret = ret.compose(invBind);
|
||||
}
|
||||
return ret;
|
||||
@@ -361,15 +360,15 @@ public enum B3DLoader implements ICustomModelLoader
|
||||
}
|
||||
|
||||
@Override
|
||||
public TRSRTransformation getInvBindPose()
|
||||
public TransformationMatrix getInvBindPose()
|
||||
{
|
||||
Matrix4f m = new TRSRTransformation(node.getPos(), node.getRot(), node.getScale(), null).getMatrixVec();
|
||||
Matrix4f m = TransformationHelper.toVecmath(fromVecmath(node.getPos(), node.getRot(), node.getScale(), null).func_227988_c_());
|
||||
m.invert();
|
||||
TRSRTransformation pose = new TRSRTransformation(m);
|
||||
TransformationMatrix pose = new TransformationMatrix(TransformationHelper.toMojang(m));
|
||||
|
||||
if(node.getParent() != null)
|
||||
{
|
||||
TRSRTransformation parent = new NodeJoint(node.getParent()).getInvBindPose();
|
||||
TransformationMatrix parent = new NodeJoint(node.getParent()).getInvBindPose();
|
||||
pose = pose.compose(parent);
|
||||
}
|
||||
return pose;
|
||||
@@ -410,7 +409,7 @@ public enum B3DLoader implements ICustomModelLoader
|
||||
private final ResourceLocation modelLocation;
|
||||
private final B3DModel model;
|
||||
private final ImmutableSet<String> meshes;
|
||||
private final ImmutableMap<String, ResourceLocation> textures;
|
||||
private final ImmutableMap<String, String> textures;
|
||||
private final boolean smooth;
|
||||
private final boolean gui3d;
|
||||
private final int defaultKey;
|
||||
@@ -420,7 +419,7 @@ public enum B3DLoader implements ICustomModelLoader
|
||||
this(modelLocation, model, meshes, smooth, gui3d, defaultKey, buildTextures(model.getTextures()));
|
||||
}
|
||||
|
||||
public ModelWrapper(ResourceLocation modelLocation, B3DModel model, ImmutableSet<String> meshes, boolean smooth, boolean gui3d, int defaultKey, ImmutableMap<String, ResourceLocation> textures)
|
||||
public ModelWrapper(ResourceLocation modelLocation, B3DModel model, ImmutableSet<String> meshes, boolean smooth, boolean gui3d, int defaultKey, ImmutableMap<String, String> textures)
|
||||
{
|
||||
this.modelLocation = modelLocation;
|
||||
this.model = model;
|
||||
@@ -431,16 +430,16 @@ public enum B3DLoader implements ICustomModelLoader
|
||||
this.defaultKey = defaultKey;
|
||||
}
|
||||
|
||||
private static ImmutableMap<String, ResourceLocation> buildTextures(List<Texture> textures)
|
||||
private static ImmutableMap<String, String> buildTextures(List<Texture> textures)
|
||||
{
|
||||
ImmutableMap.Builder<String, ResourceLocation> builder = ImmutableMap.builder();
|
||||
ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
|
||||
|
||||
for(Texture t : textures)
|
||||
{
|
||||
String path = t.getPath();
|
||||
String location = getLocation(path);
|
||||
if(!location.startsWith("#")) location = "#" + location;
|
||||
builder.put(path, new ResourceLocation(location));
|
||||
builder.put(path, location);
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
@@ -452,9 +451,11 @@ public enum B3DLoader implements ICustomModelLoader
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ResourceLocation> getTextures(Function<ResourceLocation, IUnbakedModel> modelGetter, Set<String> missingTextureErrors)
|
||||
public Collection<Material> func_225614_a_(Function<ResourceLocation, IUnbakedModel> p_225614_1_, Set<com.mojang.datafixers.util.Pair<String, String>> p_225614_2_)
|
||||
{
|
||||
return Collections2.filter(textures.values(), loc -> !loc.getPath().startsWith("#"));
|
||||
return textures.values().stream().filter(loc -> !loc.startsWith("#"))
|
||||
.map(t -> new Material(AtlasTexture.LOCATION_BLOCKS_TEXTURE, new ResourceLocation(t)))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -465,39 +466,41 @@ public enum B3DLoader implements ICustomModelLoader
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public IBakedModel bake(ModelBakery bakery, Function<ResourceLocation, TextureAtlasSprite> spriteGetter, ISprite sprite, VertexFormat format)
|
||||
public IBakedModel func_225613_a_(ModelBakery bakery, Function<Material, TextureAtlasSprite> spriteGetter, IModelTransform sprite, ResourceLocation modelLocation)
|
||||
{
|
||||
ImmutableMap.Builder<String, TextureAtlasSprite> builder = ImmutableMap.builder();
|
||||
TextureAtlasSprite missing = spriteGetter.apply(new ResourceLocation("missingno"));
|
||||
for(Map.Entry<String, ResourceLocation> e : textures.entrySet())
|
||||
TextureAtlasSprite missing = spriteGetter.apply(new Material(AtlasTexture.LOCATION_BLOCKS_TEXTURE, MissingTextureSprite.getLocation()));
|
||||
for(Map.Entry<String, String> e : textures.entrySet())
|
||||
{
|
||||
if(e.getValue().getPath().startsWith("#"))
|
||||
if(e.getValue().startsWith("#"))
|
||||
{
|
||||
LOGGER.fatal("unresolved texture '{}' for b3d model '{}'", e.getValue().getPath(), modelLocation);
|
||||
LOGGER.fatal("unresolved texture '{}' for b3d model '{}'", e.getValue(), this.modelLocation);
|
||||
builder.put(e.getKey(), missing);
|
||||
}
|
||||
else
|
||||
{
|
||||
builder.put(e.getKey(), spriteGetter.apply(e.getValue()));
|
||||
builder.put(e.getKey(), spriteGetter.apply(new Material(AtlasTexture.LOCATION_BLOCKS_TEXTURE, new ResourceLocation(e.getValue()))));
|
||||
}
|
||||
}
|
||||
builder.put("missingno", missing);
|
||||
return new BakedWrapper(model.getRoot(), sprite.getState(), smooth, gui3d, format, meshes, builder.build());
|
||||
return new BakedWrapper(model.getRoot(), sprite, smooth, gui3d, DefaultVertexFormats.BLOCK, meshes, builder.build());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModelWrapper retexture(ImmutableMap<String, String> textures)
|
||||
{
|
||||
ImmutableMap.Builder<String, ResourceLocation> builder = ImmutableMap.builder();
|
||||
for(Map.Entry<String, ResourceLocation> e : this.textures.entrySet())
|
||||
ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
|
||||
for(Map.Entry<String, String> e : this.textures.entrySet())
|
||||
{
|
||||
String path = e.getKey();
|
||||
String loc = getLocation(path);
|
||||
if(textures.containsKey(loc))
|
||||
// FIXME: Backward compatibilty: support finding textures that start with #, even though this is not how vanilla works
|
||||
if(loc.startsWith("#") && (textures.containsKey(loc) || textures.containsKey(loc.substring(1))))
|
||||
{
|
||||
String alt = loc.substring(1);
|
||||
String newLoc = textures.get(loc);
|
||||
if(newLoc == null) newLoc = getLocation(path);
|
||||
builder.put(e.getKey(), new ResourceLocation(newLoc));
|
||||
if(newLoc == null) newLoc = textures.get(alt);
|
||||
if(newLoc == null) newLoc = path.substring(1);
|
||||
builder.put(e.getKey(), newLoc);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -507,7 +510,6 @@ public enum B3DLoader implements ICustomModelLoader
|
||||
return new ModelWrapper(modelLocation, model, meshes, smooth, gui3d, defaultKey, builder.build());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModelWrapper process(ImmutableMap<String, String> data)
|
||||
{
|
||||
ImmutableSet<String> newMeshes = this.meshes;
|
||||
@@ -571,13 +573,11 @@ public enum B3DLoader implements ICustomModelLoader
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IModelState getDefaultState()
|
||||
public IModelTransform getDefaultState()
|
||||
{
|
||||
return new B3DState(model.getRoot().getAnimation(), defaultKey, defaultKey, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModelWrapper smoothLighting(boolean value)
|
||||
{
|
||||
if(value == smooth)
|
||||
@@ -587,7 +587,6 @@ public enum B3DLoader implements ICustomModelLoader
|
||||
return new ModelWrapper(modelLocation, model, meshes, value, gui3d, defaultKey, textures);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModelWrapper gui3d(boolean value)
|
||||
{
|
||||
if(value == gui3d)
|
||||
@@ -601,7 +600,7 @@ public enum B3DLoader implements ICustomModelLoader
|
||||
private static final class BakedWrapper implements IDynamicBakedModel
|
||||
{
|
||||
private final Node<?> node;
|
||||
private final IModelState state;
|
||||
private final IModelTransform state;
|
||||
private final boolean smooth;
|
||||
private final boolean gui3d;
|
||||
private final VertexFormat format;
|
||||
@@ -611,7 +610,7 @@ public enum B3DLoader implements ICustomModelLoader
|
||||
|
||||
private ImmutableList<BakedQuad> quads;
|
||||
|
||||
public BakedWrapper(final Node<?> node, final IModelState state, final boolean smooth, final boolean gui3d, final VertexFormat format, final ImmutableSet<String> meshes, final ImmutableMap<String, TextureAtlasSprite> textures)
|
||||
public BakedWrapper(final Node<?> node, final IModelTransform state, final boolean smooth, final boolean gui3d, final VertexFormat format, final ImmutableSet<String> meshes, final ImmutableMap<String, TextureAtlasSprite> textures)
|
||||
{
|
||||
this(node, state, smooth, gui3d, format, meshes, textures, CacheBuilder.newBuilder()
|
||||
.maximumSize(128)
|
||||
@@ -621,7 +620,7 @@ public enum B3DLoader implements ICustomModelLoader
|
||||
@Override
|
||||
public B3DState load(Integer frame) throws Exception
|
||||
{
|
||||
IModelState parent = state;
|
||||
IModelTransform parent = state;
|
||||
Animation newAnimation = node.getAnimation();
|
||||
if(parent instanceof B3DState)
|
||||
{
|
||||
@@ -633,7 +632,7 @@ public enum B3DLoader implements ICustomModelLoader
|
||||
}));
|
||||
}
|
||||
|
||||
public BakedWrapper(Node<?> node, IModelState state, boolean smooth, boolean gui3d, VertexFormat format, ImmutableSet<String> meshes, ImmutableMap<String, TextureAtlasSprite> textures, LoadingCache<Integer, B3DState> cache)
|
||||
public BakedWrapper(Node<?> node, IModelTransform state, boolean smooth, boolean gui3d, VertexFormat format, ImmutableSet<String> meshes, ImmutableMap<String, TextureAtlasSprite> textures, LoadingCache<Integer, B3DState> cache)
|
||||
{
|
||||
this.node = node;
|
||||
this.state = state;
|
||||
@@ -649,12 +648,12 @@ public enum B3DLoader implements ICustomModelLoader
|
||||
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, Random rand, IModelData data)
|
||||
{
|
||||
if(side != null) return ImmutableList.of();
|
||||
IModelState modelState = this.state;
|
||||
IModelState newState = data.getData(Properties.AnimationProperty);
|
||||
IModelTransform modelState = this.state;
|
||||
IModelTransform newState = data.getData(Properties.AnimationProperty);
|
||||
if(newState != null)
|
||||
{
|
||||
// FIXME: should animation state handle the parent state, or should it remain here?
|
||||
IModelState parent = this.state;
|
||||
IModelTransform parent = this.state;
|
||||
if(parent instanceof B3DState)
|
||||
{
|
||||
B3DState ps = (B3DState)parent;
|
||||
@@ -666,7 +665,7 @@ public enum B3DLoader implements ICustomModelLoader
|
||||
}
|
||||
else
|
||||
{
|
||||
modelState = new ModelStateComposition(parent, newState);
|
||||
modelState = new ModelTransformComposition(parent, newState);
|
||||
}
|
||||
}
|
||||
if(quads == null)
|
||||
@@ -685,7 +684,7 @@ public enum B3DLoader implements ICustomModelLoader
|
||||
return quads;
|
||||
}
|
||||
|
||||
private void generateQuads(ImmutableList.Builder<BakedQuad> builder, Node<?> node, final IModelState state, ImmutableList<String> path)
|
||||
private void generateQuads(ImmutableList.Builder<BakedQuad> builder, Node<?> node, final IModelTransform state, ImmutableList<String> path)
|
||||
{
|
||||
ImmutableList.Builder<String> pathBuilder = ImmutableList.builder();
|
||||
pathBuilder.addAll(path);
|
||||
@@ -695,27 +694,27 @@ public enum B3DLoader implements ICustomModelLoader
|
||||
{
|
||||
generateQuads(builder, child, state, newPath);
|
||||
}
|
||||
if(node.getKind() instanceof Mesh && meshes.contains(node.getName()) && !state.apply(Optional.of(Models.getHiddenModelPart(newPath))).isPresent())
|
||||
if(node.getKind() instanceof Mesh && meshes.contains(node.getName()) && state.getPartTransformation(Models.getHiddenModelPart(newPath)).isIdentity())
|
||||
{
|
||||
Mesh mesh = (Mesh)node.getKind();
|
||||
Collection<Face> faces = mesh.bake(new Function<Node<?>, Matrix4f>()
|
||||
{
|
||||
private final TRSRTransformation global = state.apply(Optional.empty()).orElse(TRSRTransformation.identity());
|
||||
private final LoadingCache<Node<?>, TRSRTransformation> localCache = CacheBuilder.newBuilder()
|
||||
private final TransformationMatrix global = state.func_225615_b_();
|
||||
private final LoadingCache<Node<?>, TransformationMatrix> localCache = CacheBuilder.newBuilder()
|
||||
.maximumSize(32)
|
||||
.build(new CacheLoader<Node<?>, TRSRTransformation>()
|
||||
.build(new CacheLoader<Node<?>, TransformationMatrix>()
|
||||
{
|
||||
@Override
|
||||
public TRSRTransformation load(Node<?> node) throws Exception
|
||||
public TransformationMatrix load(Node<?> node) throws Exception
|
||||
{
|
||||
return state.apply(Optional.of(new NodeJoint(node))).orElse(TRSRTransformation.identity());
|
||||
return state.getPartTransformation(new NodeJoint(node));
|
||||
}
|
||||
});
|
||||
|
||||
@Override
|
||||
public Matrix4f apply(Node<?> node)
|
||||
{
|
||||
return global.compose(localCache.getUnchecked(node)).getMatrixVec();
|
||||
return TransformationHelper.toVecmath(global.compose(localCache.getUnchecked(node)).func_227988_c_());
|
||||
}
|
||||
});
|
||||
for(Face f : faces)
|
||||
@@ -727,7 +726,7 @@ public enum B3DLoader implements ICustomModelLoader
|
||||
if(f.getBrush() != null) textures = f.getBrush().getTextures();
|
||||
TextureAtlasSprite sprite;
|
||||
if(textures == null || textures.isEmpty()) sprite = this.textures.get("missingno");
|
||||
else if(textures.get(0) == B3DModel.Texture.White) sprite = ModelLoader.White.INSTANCE;
|
||||
else if(textures.get(0) == B3DModel.Texture.White) sprite = ModelLoader.White.instance();
|
||||
else sprite = this.textures.get(textures.get(0).getPath());
|
||||
quadBuilder.setTexture(sprite);
|
||||
putVertexData(quadBuilder, f.getV1(), f.getNormal(), sprite);
|
||||
@@ -742,9 +741,10 @@ public enum B3DLoader implements ICustomModelLoader
|
||||
private final void putVertexData(UnpackedBakedQuad.Builder builder, Vertex v, Vector3f faceNormal, TextureAtlasSprite sprite)
|
||||
{
|
||||
// TODO handle everything not handled (texture transformations, bones, transformations, normals, e.t.c)
|
||||
for(int e = 0; e < format.getElementCount(); e++)
|
||||
ImmutableList<VertexFormatElement> vertexFormatElements = format.func_227894_c_();
|
||||
for(int e = 0; e < vertexFormatElements.size(); e++)
|
||||
{
|
||||
switch(format.getElement(e).getUsage())
|
||||
switch(vertexFormatElements.get(e).getUsage())
|
||||
{
|
||||
case POSITION:
|
||||
builder.put(e, v.getPos().x, v.getPos().y, v.getPos().z, 1);
|
||||
@@ -761,7 +761,7 @@ public enum B3DLoader implements ICustomModelLoader
|
||||
break;
|
||||
case UV:
|
||||
// TODO handle more brushes
|
||||
if(format.getElement(e).getIndex() < v.getTexCoords().length)
|
||||
if(vertexFormatElements.get(e).getIndex() < v.getTexCoords().length)
|
||||
{
|
||||
builder.put(e,
|
||||
sprite.getInterpolatedU(v.getTexCoords()[0].x * 16),
|
||||
@@ -817,9 +817,15 @@ public enum B3DLoader implements ICustomModelLoader
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pair<? extends IBakedModel, Matrix4f> handlePerspective(TransformType cameraTransformType)
|
||||
public boolean doesHandlePerspectives()
|
||||
{
|
||||
return PerspectiveMapWrapper.handlePerspective(this, state, cameraTransformType);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBakedModel handlePerspective(TransformType cameraTransformType, MatrixStack mat)
|
||||
{
|
||||
return PerspectiveMapWrapper.handlePerspective(this, state, cameraTransformType, mat);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -43,8 +43,9 @@ import javax.vecmath.Vector2f;
|
||||
import javax.vecmath.Vector3f;
|
||||
import javax.vecmath.Vector4f;
|
||||
|
||||
import net.minecraft.client.renderer.TransformationMatrix;
|
||||
import net.minecraftforge.versions.forge.ForgeVersion;
|
||||
import net.minecraftforge.common.model.TRSRTransformation;
|
||||
import net.minecraftforge.common.model.TransformationHelper;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.apache.commons.lang3.tuple.Triple;
|
||||
@@ -681,12 +682,12 @@ public class B3DModel
|
||||
else t.setIdentity();
|
||||
}
|
||||
|
||||
TRSRTransformation trsr = new TRSRTransformation(t);
|
||||
TransformationMatrix trsr = new TransformationMatrix(TransformationHelper.toMojang(t));
|
||||
|
||||
// pos
|
||||
Vector4f pos = new Vector4f(this.pos);
|
||||
pos.w = 1;
|
||||
trsr.transformPosition(pos);
|
||||
trsr.transformPosition(TransformationHelper.toMojang(pos));
|
||||
Vector3f rPos = new Vector3f(pos.x / pos.w, pos.y / pos.w, pos.z / pos.w);
|
||||
|
||||
// normal
|
||||
|
||||
@@ -0,0 +1,267 @@
|
||||
/*
|
||||
* Minecraft Forge
|
||||
* Copyright (c) 2016-2019.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation version 2.1
|
||||
* of the License.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package net.minecraftforge.client.model.composite;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.renderer.model.*;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormat;
|
||||
import net.minecraft.resources.IResourceManager;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.client.model.*;
|
||||
import net.minecraftforge.client.model.data.EmptyModelData;
|
||||
import net.minecraftforge.client.model.data.IModelData;
|
||||
import net.minecraftforge.client.model.data.ModelProperty;
|
||||
import net.minecraftforge.client.model.geometry.IModelGeometryPart;
|
||||
import net.minecraftforge.client.model.geometry.IMultipartModelGeometry;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class CompositeModel implements IBakedModel
|
||||
{
|
||||
public static final ModelProperty<SubmodelModelData> SUBMODEL_DATA = new ModelProperty<>();
|
||||
|
||||
private final ImmutableMap<String, IBakedModel> bakedParts;
|
||||
private final boolean isAmbientOcclusion;
|
||||
private final boolean isGui3d;
|
||||
private final TextureAtlasSprite particle;
|
||||
private final ItemOverrideList overrides;
|
||||
|
||||
public CompositeModel(boolean isGui3d, boolean isAmbientOcclusion, TextureAtlasSprite particle, ImmutableMap<String, IBakedModel> bakedParts, ItemOverrideList overrides)
|
||||
{
|
||||
this.bakedParts = bakedParts;
|
||||
this.isAmbientOcclusion = isAmbientOcclusion;
|
||||
this.isGui3d = isGui3d;
|
||||
this.particle = particle;
|
||||
this.overrides = overrides;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, @Nonnull Random rand, @Nonnull IModelData extraData)
|
||||
{
|
||||
List<BakedQuad> quads = new ArrayList<>();
|
||||
for(Map.Entry<String, IBakedModel> entry : bakedParts.entrySet())
|
||||
{
|
||||
// TODO: Some way to provide submodel data?
|
||||
quads.addAll(entry.getValue().getQuads(state, side, rand, getSubmodelData(extraData, entry.getKey())));
|
||||
}
|
||||
return quads;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, Random rand)
|
||||
{
|
||||
List<BakedQuad> quads = new ArrayList<>();
|
||||
for(IBakedModel part : bakedParts.values())
|
||||
{
|
||||
quads.addAll(part.getQuads(state, side, rand, EmptyModelData.INSTANCE));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAmbientOcclusion()
|
||||
{
|
||||
return isAmbientOcclusion;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGui3d()
|
||||
{
|
||||
return isGui3d;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBuiltInRenderer()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextureAtlasSprite getParticleTexture()
|
||||
{
|
||||
return particle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemOverrideList getOverrides()
|
||||
{
|
||||
return overrides;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public IBakedModel getPart(String name)
|
||||
{
|
||||
return bakedParts.get(name);
|
||||
}
|
||||
|
||||
private IModelData getSubmodelData(IModelData extraData, String name)
|
||||
{
|
||||
SubmodelModelData data = extraData.getData(SUBMODEL_DATA);
|
||||
if (data == null)
|
||||
return EmptyModelData.INSTANCE;
|
||||
return data.getSubmodelData(name);
|
||||
}
|
||||
|
||||
public static class SubmodelModelData
|
||||
{
|
||||
private final Map<String, IModelData> parts = new HashMap<>();
|
||||
|
||||
public IModelData getSubmodelData(String name)
|
||||
{
|
||||
return parts.getOrDefault(name, EmptyModelData.INSTANCE);
|
||||
}
|
||||
|
||||
public void putSubmodelData(String name, IModelData data)
|
||||
{
|
||||
parts.put(name, data);
|
||||
}
|
||||
}
|
||||
|
||||
private static class Submodel implements IModelGeometryPart
|
||||
{
|
||||
private final String name;
|
||||
private final BlockModel model;
|
||||
private final IModelTransform sprite;
|
||||
|
||||
private Submodel(String name, BlockModel model, IModelTransform sprite)
|
||||
{
|
||||
this.name = name;
|
||||
this.model = model;
|
||||
this.sprite = sprite;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String name()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addQuads(IModelConfiguration owner, IModelBuilder<?> modelBuilder, ModelBakery bakery, Function<Material, TextureAtlasSprite> spriteGetter, IModelTransform sprite, ResourceLocation modelLocation)
|
||||
{
|
||||
throw new UnsupportedOperationException("Attempted to call adQuads on a Submodel instance. Please don't.");
|
||||
}
|
||||
|
||||
public IBakedModel func_225613_a_(ModelBakery bakery, Function<Material, TextureAtlasSprite> spriteGetter, IModelTransform sprite, ResourceLocation modelLocation)
|
||||
{
|
||||
return model.func_225613_a_(bakery, spriteGetter, new ModelTransformComposition(this.sprite, sprite,
|
||||
this.sprite.isUvLock() || sprite.isUvLock()), modelLocation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Material> getTextureDependencies(IModelConfiguration owner, Function<ResourceLocation, IUnbakedModel> modelGetter, Set<Pair<String, String>> missingTextureErrors)
|
||||
{
|
||||
return model.func_225614_a_(modelGetter, missingTextureErrors);
|
||||
}
|
||||
}
|
||||
|
||||
public static class Geometry implements IMultipartModelGeometry<Geometry>
|
||||
{
|
||||
private final ImmutableMap<String, Submodel> parts;
|
||||
|
||||
Geometry(ImmutableMap<String, Submodel> parts)
|
||||
{
|
||||
this.parts = parts;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<? extends IModelGeometryPart> getParts()
|
||||
{
|
||||
return parts.values();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<? extends IModelGeometryPart> getPart(String name)
|
||||
{
|
||||
return Optional.ofNullable(parts.get(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBakedModel bake(IModelConfiguration owner, ModelBakery bakery, Function<Material, TextureAtlasSprite> spriteGetter, IModelTransform sprite, ItemOverrideList overrides, ResourceLocation modelLocation)
|
||||
{
|
||||
Material particleLocation = owner.resolveTexture("particle");
|
||||
TextureAtlasSprite particle = spriteGetter.apply(particleLocation);
|
||||
|
||||
ImmutableMap.Builder<String, IBakedModel> bakedParts = ImmutableMap.builder();
|
||||
for(Map.Entry<String, Submodel> part : parts.entrySet())
|
||||
{
|
||||
Submodel submodel = part.getValue();
|
||||
if (!owner.getPartVisibility(submodel))
|
||||
continue;
|
||||
bakedParts.put(part.getKey(), submodel.func_225613_a_(bakery, spriteGetter, sprite, modelLocation));
|
||||
}
|
||||
return new CompositeModel(owner.isShadedInGui(), owner.useSmoothLighting(), particle, bakedParts.build(), overrides);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Material> getTextures(IModelConfiguration owner, Function<ResourceLocation, IUnbakedModel> modelGetter, Set<Pair<String, String>> missingTextureErrors)
|
||||
{
|
||||
Set<Material> textures = new HashSet<>();
|
||||
for(Submodel part : parts.values())
|
||||
{
|
||||
part.getTextureDependencies(owner, modelGetter, missingTextureErrors);
|
||||
}
|
||||
return textures;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Loader implements IModelLoader<Geometry>
|
||||
{
|
||||
public static final Loader INSTANCE = new Loader();
|
||||
|
||||
private Loader() {}
|
||||
|
||||
@Override
|
||||
public void onResourceManagerReload(IResourceManager resourceManager)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Geometry read(JsonDeserializationContext deserializationContext, JsonObject modelContents)
|
||||
{
|
||||
if (!modelContents.has("parts"))
|
||||
throw new RuntimeException("Composite model requires a \"parts\" element.");
|
||||
ImmutableMap.Builder<String, Submodel> parts = ImmutableMap.builder();
|
||||
for(Map.Entry<String, JsonElement> part : modelContents.get("parts").getAsJsonObject().entrySet())
|
||||
{
|
||||
// TODO: Allow customizing state? If so, how?
|
||||
IModelTransform sprite = SimpleModelTransform.IDENTITY;
|
||||
parts.put(part.getKey(), new Submodel(
|
||||
part.getKey(),
|
||||
ModelLoaderRegistry.ExpandedBlockModelDeserializer.INSTANCE.fromJson(part.getValue(), BlockModel.class),
|
||||
sprite));
|
||||
}
|
||||
return new Geometry(parts.build());
|
||||
}
|
||||
}
|
||||
}
|
||||
+6
-7
@@ -17,11 +17,10 @@
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package net.minecraftforge.common.model;
|
||||
@ParametersAreNonnullByDefault
|
||||
@MethodsReturnNonnullByDefault
|
||||
package net.minecraftforge.client.model.composite;
|
||||
|
||||
/**
|
||||
* Represents some part of a model you can refer to, for example: mesh,
|
||||
* skeleton, bone or some separately animated submodel.
|
||||
* @see IModelState
|
||||
*/
|
||||
public interface IModelPart {}
|
||||
import mcp.MethodsReturnNonnullByDefault;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
@@ -1,3 +1,22 @@
|
||||
/*
|
||||
* Minecraft Forge
|
||||
* Copyright (c) 2016-2019.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation version 2.1
|
||||
* of the License.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package net.minecraftforge.client.model.generators;
|
||||
|
||||
import net.minecraft.data.DataGenerator;
|
||||
|
||||
@@ -1,3 +1,22 @@
|
||||
/*
|
||||
* Minecraft Forge
|
||||
* Copyright (c) 2016-2019.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation version 2.1
|
||||
* of the License.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package net.minecraftforge.client.model.generators;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@@ -1,3 +1,22 @@
|
||||
/*
|
||||
* Minecraft Forge
|
||||
* Copyright (c) 2016-2019.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation version 2.1
|
||||
* of the License.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package net.minecraftforge.client.model.generators;
|
||||
|
||||
import java.io.File;
|
||||
@@ -26,7 +45,7 @@ import net.minecraftforge.fml.event.lifecycle.GatherDataEvent;
|
||||
*/
|
||||
public class ExistingFileHelper {
|
||||
|
||||
private final IResourceManager clientResources, serverData;
|
||||
private final SimpleReloadableResourceManager clientResources, serverData;
|
||||
private final boolean enable;
|
||||
|
||||
public ExistingFileHelper(Collection<Path> existingPacks, boolean enable) {
|
||||
|
||||
@@ -1,3 +1,22 @@
|
||||
/*
|
||||
* Minecraft Forge
|
||||
* Copyright (c) 2016-2019.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation version 2.1
|
||||
* of the License.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package net.minecraftforge.client.model.generators;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
|
||||
@@ -1,3 +1,22 @@
|
||||
/*
|
||||
* Minecraft Forge
|
||||
* Copyright (c) 2016-2019.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation version 2.1
|
||||
* of the License.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package net.minecraftforge.client.model.generators;
|
||||
|
||||
import net.minecraft.data.DataGenerator;
|
||||
|
||||
+19
@@ -1,3 +1,22 @@
|
||||
/*
|
||||
* Minecraft Forge
|
||||
* Copyright (c) 2016-2019.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation version 2.1
|
||||
* of the License.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package net.minecraftforge.client.model.generators;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Minecraft Forge
|
||||
* Copyright (c) 2016-2019.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation version 2.1
|
||||
* of the License.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package net.minecraftforge.client.model.geometry;
|
||||
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import net.minecraft.client.renderer.model.*;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.client.model.IModelConfiguration;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* General interface for any model that can be baked, superset of vanilla {@link net.minecraft.client.renderer.model.IUnbakedModel}.
|
||||
* Models can be baked to different vertex formats and with different state.
|
||||
*/
|
||||
public interface IModelGeometry<T extends IModelGeometry<T>>
|
||||
{
|
||||
default Collection<? extends IModelGeometryPart> getParts() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
default Optional<? extends IModelGeometryPart> getPart(String name) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
IBakedModel bake(IModelConfiguration owner, ModelBakery bakery, Function<Material, TextureAtlasSprite> spriteGetter, IModelTransform sprite, ItemOverrideList overrides, ResourceLocation modelLocation);
|
||||
|
||||
Collection<Material> getTextures(IModelConfiguration owner, Function<ResourceLocation, IUnbakedModel> modelGetter, Set<Pair<String, String>> missingTextureErrors);
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Minecraft Forge
|
||||
* Copyright (c) 2016-2019.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation version 2.1
|
||||
* of the License.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package net.minecraftforge.client.model.geometry;
|
||||
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import net.minecraft.client.renderer.model.IModelTransform;
|
||||
import net.minecraft.client.renderer.model.IUnbakedModel;
|
||||
import net.minecraft.client.renderer.model.Material;
|
||||
import net.minecraft.client.renderer.model.ModelBakery;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormat;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.client.model.IModelBuilder;
|
||||
import net.minecraftforge.client.model.IModelConfiguration;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
|
||||
public interface IModelGeometryPart
|
||||
{
|
||||
String name();
|
||||
|
||||
void addQuads(IModelConfiguration owner, IModelBuilder<?> modelBuilder, ModelBakery bakery, Function<Material, TextureAtlasSprite> spriteGetter, IModelTransform sprite, ResourceLocation modelLocation);
|
||||
|
||||
default Collection<Material> getTextureDependencies(IModelConfiguration owner, Function<ResourceLocation, IUnbakedModel> modelGetter, Set<Pair<String, String>> missingTextureErrors) {
|
||||
// No texture dependencies
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Minecraft Forge
|
||||
* Copyright (c) 2016-2019.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation version 2.1
|
||||
* of the License.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package net.minecraftforge.client.model.geometry;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import net.minecraft.client.renderer.model.IModelTransform;
|
||||
import net.minecraft.client.renderer.model.IUnbakedModel;
|
||||
import net.minecraft.client.renderer.model.Material;
|
||||
import net.minecraft.client.renderer.model.ModelBakery;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.client.model.IModelBuilder;
|
||||
import net.minecraftforge.client.model.IModelConfiguration;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
|
||||
public interface IMultipartModelGeometry<T extends IMultipartModelGeometry<T>> extends ISimpleModelGeometry<T>
|
||||
{
|
||||
@Override
|
||||
Collection<? extends IModelGeometryPart> getParts();
|
||||
|
||||
Optional<? extends IModelGeometryPart> getPart(String name);
|
||||
|
||||
@Override
|
||||
default void addQuads(IModelConfiguration owner, IModelBuilder<?> modelBuilder, ModelBakery bakery, Function<Material, TextureAtlasSprite> spriteGetter, IModelTransform sprite, ResourceLocation modelLocation)
|
||||
{
|
||||
getParts().stream().filter(part -> owner.getPartVisibility(part))
|
||||
.forEach(part -> part.addQuads(owner, modelBuilder, bakery, spriteGetter, sprite, modelLocation));
|
||||
}
|
||||
|
||||
@Override
|
||||
default Collection<Material> getTextures(IModelConfiguration owner, Function<ResourceLocation, IUnbakedModel> modelGetter, Set<Pair<String, String>> missingTextureErrors)
|
||||
{
|
||||
Set<Material> combined = Sets.newHashSet();
|
||||
for (IModelGeometryPart part : getParts())
|
||||
combined.addAll(part.getTextureDependencies(owner, modelGetter, missingTextureErrors));
|
||||
return combined;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Minecraft Forge
|
||||
* Copyright (c) 2016-2019.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation version 2.1
|
||||
* of the License.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package net.minecraftforge.client.model.geometry;
|
||||
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import net.minecraft.client.renderer.model.*;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.client.model.IModelBuilder;
|
||||
import net.minecraftforge.client.model.IModelConfiguration;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
|
||||
public interface ISimpleModelGeometry<T extends ISimpleModelGeometry<T>> extends IModelGeometry<T>
|
||||
{
|
||||
@Override
|
||||
default IBakedModel bake(IModelConfiguration owner, ModelBakery bakery, Function<Material, TextureAtlasSprite> spriteGetter, IModelTransform sprite, ItemOverrideList overrides, ResourceLocation modelLocation)
|
||||
{
|
||||
TextureAtlasSprite particle = spriteGetter.apply(owner.resolveTexture("particle"));
|
||||
|
||||
IModelBuilder<?> builder = IModelBuilder.of(owner, overrides, particle);
|
||||
|
||||
addQuads(owner, builder, bakery, spriteGetter, sprite, modelLocation);
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
void addQuads(IModelConfiguration owner, IModelBuilder<?> modelBuilder, ModelBakery bakery, Function<Material, TextureAtlasSprite> spriteGetter, IModelTransform sprite, ResourceLocation modelLocation);
|
||||
|
||||
@Override
|
||||
Collection<Material> getTextures(IModelConfiguration owner, Function<ResourceLocation, IUnbakedModel> modelGetter, Set<Pair<String, String>> missingTextureErrors);
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
/*
|
||||
* Minecraft Forge
|
||||
* Copyright (c) 2016-2019.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation version 2.1
|
||||
* of the License.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package net.minecraftforge.client.model.obj;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import joptsimple.internal.Strings;
|
||||
|
||||
import javax.vecmath.Vector4f;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
|
||||
public class MaterialLibrary
|
||||
{
|
||||
final Map<String, Material> materials = Maps.newHashMap();
|
||||
|
||||
public MaterialLibrary(OBJLoader.LineReader reader) throws IOException
|
||||
{
|
||||
Material currentMaterial = null;
|
||||
|
||||
String[] line;
|
||||
while((line = reader.readAndSplitLine(true)) != null)
|
||||
{
|
||||
switch(line[0])
|
||||
{
|
||||
case "newmtl":
|
||||
{
|
||||
String name = Strings.join(Arrays.copyOfRange(line, 1, line.length), " ");
|
||||
currentMaterial = new Material(name);
|
||||
materials.put(name, currentMaterial);
|
||||
break;
|
||||
}
|
||||
|
||||
case "Ka":
|
||||
currentMaterial.ambientColor = OBJModel.parseVector4(line);
|
||||
break;
|
||||
|
||||
case "map_Ka":
|
||||
// Ignores all options params
|
||||
currentMaterial.ambientColorMap = line[line.length-1];
|
||||
break;
|
||||
|
||||
case "Kd":
|
||||
currentMaterial.diffuseColor = OBJModel.parseVector4(line);
|
||||
break;
|
||||
|
||||
case "forge_TintIndex":
|
||||
currentMaterial.diffuseTintIndex = Integer.parseInt(line[1]);
|
||||
break;
|
||||
|
||||
case "map_Kd":
|
||||
// Ignores all options params
|
||||
currentMaterial.diffuseColorMap = line[line.length-1];
|
||||
break;
|
||||
|
||||
case "Ks":
|
||||
currentMaterial.specularColor = OBJModel.parseVector4(line);
|
||||
break;
|
||||
|
||||
case "Ns":
|
||||
currentMaterial.specularHighlight = Integer.parseInt(line[1]);
|
||||
break;
|
||||
|
||||
case "map_Ks":
|
||||
// Ignores all options params
|
||||
currentMaterial.specularColorMap = line[line.length-1];
|
||||
break;
|
||||
|
||||
case "d":
|
||||
// Ignores all options params
|
||||
currentMaterial.dissolve = Float.parseFloat(line[1]);
|
||||
break;
|
||||
case "Tr":
|
||||
// Ignores all options params
|
||||
currentMaterial.transparency = Float.parseFloat(line[1]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Material getMaterial(String mat)
|
||||
{
|
||||
return materials.get(mat);
|
||||
}
|
||||
|
||||
public class Material
|
||||
{
|
||||
public final String name;
|
||||
public Vector4f ambientColor = new Vector4f(0,0,0,1);
|
||||
public String ambientColorMap;
|
||||
public Vector4f diffuseColor = new Vector4f(1,1,1,1);
|
||||
public String diffuseColorMap;
|
||||
public Vector4f specularColor = new Vector4f(0,0,0,1);
|
||||
public float specularHighlight = 0;
|
||||
public String specularColorMap;
|
||||
|
||||
public float dissolve = 1.0f;
|
||||
public float transparency = 0.0f;
|
||||
|
||||
// non-standard
|
||||
public int diffuseTintIndex = 0;
|
||||
|
||||
public Material(String name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,101 +19,210 @@
|
||||
|
||||
package net.minecraftforge.client.model.obj;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.client.renderer.model.IUnbakedModel;
|
||||
import com.google.common.base.Charsets;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonObject;
|
||||
import joptsimple.internal.Strings;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.resources.IResource;
|
||||
import net.minecraft.resources.IResourceManager;
|
||||
import net.minecraft.util.JSONUtils;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.client.model.ICustomModelLoader;
|
||||
import net.minecraftforge.client.model.ModelLoaderRegistry;
|
||||
import net.minecraftforge.client.model.IModelLoader;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.logging.log4j.Level;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.*;
|
||||
|
||||
/*
|
||||
* Loader for OBJ models.
|
||||
* To enable your mod call instance.addDomain(modid).
|
||||
* If you need more control over accepted resources - extend the class, and register a new instance with ModelLoaderRegistry.
|
||||
*/
|
||||
public enum OBJLoader implements ICustomModelLoader {
|
||||
INSTANCE;
|
||||
public class OBJLoader implements IModelLoader<OBJModel>
|
||||
{
|
||||
public static OBJLoader INSTANCE = new OBJLoader();
|
||||
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
private IResourceManager manager;
|
||||
private final Set<String> enabledDomains = new HashSet<>();
|
||||
private final Map<ResourceLocation, OBJModel> cache = new HashMap<>();
|
||||
private final Map<ResourceLocation, Exception> errors = new HashMap<>();
|
||||
private final Map<ModelSettings, OBJModel> modelCache = Maps.newHashMap();
|
||||
private final Map<ResourceLocation, MaterialLibrary> materialCache = Maps.newHashMap();
|
||||
|
||||
public void addDomain(String domain)
|
||||
{
|
||||
enabledDomains.add(domain.toLowerCase());
|
||||
LOGGER.info("OBJLoader: Domain {} has been added.", domain.toLowerCase());
|
||||
}
|
||||
private IResourceManager manager = Minecraft.getInstance().getResourceManager();
|
||||
|
||||
@Override
|
||||
public void onResourceManagerReload(IResourceManager resourceManager)
|
||||
{
|
||||
this.manager = resourceManager;
|
||||
cache.clear();
|
||||
errors.clear();
|
||||
modelCache.clear();
|
||||
materialCache.clear();
|
||||
manager = resourceManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean accepts(ResourceLocation modelLocation)
|
||||
public OBJModel read(JsonDeserializationContext deserializationContext, JsonObject modelContents)
|
||||
{
|
||||
return enabledDomains.contains(modelLocation.getNamespace()) && modelLocation.getPath().endsWith(".obj");
|
||||
if (!modelContents.has("model"))
|
||||
throw new RuntimeException("OBJ Loader requires a 'model' key that points to a valid .OBJ model.");
|
||||
|
||||
String modelLocation = modelContents.get("model").getAsString();
|
||||
|
||||
boolean detectCullableFaces = JSONUtils.getBoolean(modelContents, "detectCullableFaces", true);
|
||||
boolean diffuseLighting = JSONUtils.getBoolean(modelContents, "diffuseLighting", false);
|
||||
boolean flipV = JSONUtils.getBoolean(modelContents, "flip-v", false);
|
||||
boolean ambientToFullbright = JSONUtils.getBoolean(modelContents, "ambientToFullbright", true);
|
||||
|
||||
return loadModel(new ResourceLocation(modelLocation), detectCullableFaces, diffuseLighting, flipV, ambientToFullbright);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IUnbakedModel loadModel(ResourceLocation modelLocation) throws Exception
|
||||
public OBJModel loadModel(ResourceLocation modelLocation, boolean detectCullableFaces, boolean diffuseLighting, boolean flipV, boolean ambientToFullbright)
|
||||
{
|
||||
ResourceLocation file = new ResourceLocation(modelLocation.getNamespace(), modelLocation.getPath());
|
||||
if (!cache.containsKey(file))
|
||||
{
|
||||
IResource resource = null;
|
||||
return modelCache.computeIfAbsent(new ModelSettings(modelLocation, detectCullableFaces, diffuseLighting, flipV, ambientToFullbright), (data) -> {
|
||||
IResource resource;
|
||||
try
|
||||
{
|
||||
try
|
||||
{
|
||||
resource = manager.getResource(file);
|
||||
}
|
||||
catch (FileNotFoundException e)
|
||||
{
|
||||
if (modelLocation.getPath().startsWith("models/block/"))
|
||||
resource = manager.getResource(new ResourceLocation(file.getNamespace(), "models/item/" + file.getPath().substring("models/block/".length())));
|
||||
else if (modelLocation.getPath().startsWith("models/item/"))
|
||||
resource = manager.getResource(new ResourceLocation(file.getNamespace(), "models/block/" + file.getPath().substring("models/item/".length())));
|
||||
else throw e;
|
||||
}
|
||||
OBJModel.Parser parser = new OBJModel.Parser(resource, manager);
|
||||
OBJModel model = null;
|
||||
try
|
||||
{
|
||||
model = parser.parse();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
errors.put(modelLocation, e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
cache.put(modelLocation, model);
|
||||
}
|
||||
resource = manager.getResource(modelLocation);
|
||||
}
|
||||
finally
|
||||
catch (IOException e)
|
||||
{
|
||||
IOUtils.closeQuietly(resource);
|
||||
throw new RuntimeException("Could not find OBJ model", e);
|
||||
}
|
||||
|
||||
try(LineReader rdr = new LineReader(resource))
|
||||
{
|
||||
return new OBJModel(modelLocation, rdr, detectCullableFaces, diffuseLighting, flipV, ambientToFullbright);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new RuntimeException("Could not read OBJ model", e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public MaterialLibrary loadMaterialLibrary(ResourceLocation materialLocation)
|
||||
{
|
||||
return materialCache.computeIfAbsent(materialLocation, (location) -> {
|
||||
IResource resource;
|
||||
try
|
||||
{
|
||||
resource = manager.getResource(location);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
throw new RuntimeException("Could not find OBJ material library", e);
|
||||
}
|
||||
|
||||
try(LineReader rdr = new LineReader(resource))
|
||||
{
|
||||
return new MaterialLibrary(rdr);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new RuntimeException("Could not read OBJ material library", e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static class LineReader implements AutoCloseable
|
||||
{
|
||||
InputStreamReader lineStream;
|
||||
BufferedReader lineReader;
|
||||
|
||||
public LineReader(IResource resource)
|
||||
{
|
||||
this.lineStream = new InputStreamReader(resource.getInputStream(), Charsets.UTF_8);
|
||||
this.lineReader = new BufferedReader(lineStream);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String[] readAndSplitLine(boolean ignoreEmptyLines) throws IOException
|
||||
{
|
||||
do
|
||||
{
|
||||
String currentLine = lineReader.readLine();
|
||||
if (currentLine == null)
|
||||
return null;
|
||||
|
||||
List<String> lineParts = new ArrayList<>();
|
||||
|
||||
if (currentLine.startsWith("#"))
|
||||
currentLine = "";
|
||||
|
||||
if (currentLine.length() > 0)
|
||||
{
|
||||
|
||||
boolean hasContinuation;
|
||||
do
|
||||
{
|
||||
hasContinuation = currentLine.endsWith("\\");
|
||||
String tmp = hasContinuation ? currentLine.substring(0, currentLine.length() - 1) : currentLine;
|
||||
|
||||
Arrays.stream(tmp.split("[\t ]+")).filter(s -> !Strings.isNullOrEmpty(s)).forEach(lineParts::add);
|
||||
|
||||
if (hasContinuation)
|
||||
{
|
||||
currentLine = lineReader.readLine();
|
||||
if (currentLine == null)
|
||||
break;
|
||||
|
||||
if (currentLine.length() == 0 || currentLine.startsWith("#"))
|
||||
break;
|
||||
}
|
||||
} while (hasContinuation);
|
||||
}
|
||||
|
||||
if (lineParts.size() > 0)
|
||||
return lineParts.toArray(new String[0]);
|
||||
}
|
||||
while (ignoreEmptyLines); // conditional expression is not updated, yes, I know.
|
||||
|
||||
return new String[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws Exception
|
||||
{
|
||||
lineReader.close();
|
||||
lineStream.close();
|
||||
}
|
||||
}
|
||||
|
||||
private class ModelSettings
|
||||
{
|
||||
@Nonnull
|
||||
private final ResourceLocation modelLocation;
|
||||
private final boolean detectCullableFaces;
|
||||
private final boolean diffuseLighting;
|
||||
private final boolean flipV;
|
||||
private final boolean ambientToFullbright;
|
||||
|
||||
public ModelSettings(@Nonnull ResourceLocation modelLocation, boolean detectCullableFaces, boolean diffuseLighting, boolean flipV, boolean ambientToFullbright)
|
||||
{
|
||||
this.modelLocation = modelLocation;
|
||||
this.detectCullableFaces = detectCullableFaces;
|
||||
this.diffuseLighting = diffuseLighting;
|
||||
this.flipV = flipV;
|
||||
this.ambientToFullbright = ambientToFullbright;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o)
|
||||
{
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
ModelSettings that = (ModelSettings) o;
|
||||
return equals(that);
|
||||
}
|
||||
|
||||
public boolean equals(@Nonnull ModelSettings that)
|
||||
{
|
||||
return detectCullableFaces == that.detectCullableFaces &&
|
||||
diffuseLighting == that.diffuseLighting &&
|
||||
flipV == that.flipV &&
|
||||
ambientToFullbright == that.ambientToFullbright &&
|
||||
modelLocation.equals(that.modelLocation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
return Objects.hash(modelLocation, detectCullableFaces, diffuseLighting, flipV, ambientToFullbright);
|
||||
}
|
||||
OBJModel model = cache.get(file);
|
||||
if (model == null) throw new ModelLoaderRegistry.LoaderException("Error loading model previously: " + file, errors.get(modelLocation));
|
||||
return model;
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -27,14 +27,14 @@ import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.util.math.shapes.VoxelShapes;
|
||||
import net.minecraft.world.IEnviromentBlockReader;
|
||||
import net.minecraft.world.ILightReader;
|
||||
|
||||
public class BlockInfo
|
||||
{
|
||||
private static final Direction[] SIDES = Direction.values();
|
||||
|
||||
private final BlockColors colors;
|
||||
private IEnviromentBlockReader world;
|
||||
private ILightReader world;
|
||||
private BlockState state;
|
||||
private BlockPos blockPos;
|
||||
|
||||
@@ -63,7 +63,7 @@ public class BlockInfo
|
||||
{
|
||||
if(cachedTint == tint) return cachedMultiplier;
|
||||
cachedTint = tint;
|
||||
cachedMultiplier = colors.getColor(state, world, blockPos, tint);
|
||||
cachedMultiplier = colors.func_228054_a_(state, world, blockPos, tint);
|
||||
return cachedMultiplier;
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ public class BlockInfo
|
||||
shz = (float) offset.z;
|
||||
}
|
||||
|
||||
public void setWorld(IEnviromentBlockReader world)
|
||||
public void setWorld(ILightReader world)
|
||||
{
|
||||
this.world = world;
|
||||
cachedTint = -1;
|
||||
@@ -127,7 +127,7 @@ public class BlockInfo
|
||||
BlockPos pos = blockPos.add(x - 1, y - 1, z - 1);
|
||||
BlockState state = world.getBlockState(pos);
|
||||
t[x][y][z] = state.getOpacity(world, pos) < 15;
|
||||
int brightness = state.getPackedLightmapCoords(world, pos);
|
||||
int brightness = 0x00FF00FF; // FIXME: state.getPackedLightmapCoords(world, pos);
|
||||
s[x][y][z] = (brightness >> 0x14) & 0xF;
|
||||
b[x][y][z] = (brightness >> 0x04) & 0xF;
|
||||
ao[x][y][z] = state.func_215703_d(world, pos);
|
||||
@@ -195,16 +195,16 @@ public class BlockInfo
|
||||
public void updateFlatLighting()
|
||||
{
|
||||
full = Block.isOpaque(state.getCollisionShape(world, blockPos));
|
||||
packed[0] = state.getPackedLightmapCoords(world, blockPos);
|
||||
packed[0] = 0x00FF00FF; // FIXME: state.getPackedLightmapCoords(world, blockPos);
|
||||
|
||||
for (Direction side : SIDES)
|
||||
{
|
||||
int i = side.ordinal() + 1;
|
||||
packed[i] = state.getPackedLightmapCoords(world, blockPos.offset(side));
|
||||
packed[i] = 0x00FF00FF; // FIXME: state.getPackedLightmapCoords(world, blockPos.offset(side));
|
||||
}
|
||||
}
|
||||
|
||||
public IEnviromentBlockReader getWorld()
|
||||
public ILightReader getWorld()
|
||||
{
|
||||
return world;
|
||||
}
|
||||
|
||||
+12
-9
@@ -22,19 +22,21 @@ package net.minecraftforge.client.model.pipeline;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import com.mojang.blaze3d.vertex.IVertexBuilder;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.renderer.BlockModelRenderer;
|
||||
import net.minecraft.client.renderer.BufferBuilder;
|
||||
import net.minecraft.client.renderer.model.BakedQuad;
|
||||
import net.minecraft.client.renderer.model.IBakedModel;
|
||||
import net.minecraft.client.renderer.color.BlockColors;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IEnviromentBlockReader;
|
||||
import net.minecraft.world.ILightReader;
|
||||
import net.minecraftforge.client.model.data.IModelData;
|
||||
import net.minecraftforge.common.ForgeConfig;
|
||||
|
||||
/*
|
||||
public class ForgeBlockModelRenderer extends BlockModelRenderer
|
||||
{
|
||||
private final ThreadLocal<VertexLighterFlat> lighterFlat;
|
||||
@@ -50,7 +52,7 @@ public class ForgeBlockModelRenderer extends BlockModelRenderer
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean renderModelFlat(IEnviromentBlockReader world, IBakedModel model, BlockState state, BlockPos pos, BufferBuilder buffer, boolean checkSides, Random rand, long seed, IModelData modelData)
|
||||
public boolean renderModelFlat(ILightReader world, IBakedModel model, BlockState state, BlockPos pos, MatrixStack matrixStack, IVertexBuilder buffer, boolean checkSides, Random rand, long seed, int p_228806_11_, IModelData modelData)
|
||||
{
|
||||
if(ForgeConfig.CLIENT.forgeLightPipelineEnabled.get())
|
||||
{
|
||||
@@ -61,16 +63,16 @@ public class ForgeBlockModelRenderer extends BlockModelRenderer
|
||||
VertexLighterFlat lighter = lighterFlat.get();
|
||||
lighter.setParent(consumer);
|
||||
|
||||
return render(lighter, world, model, state, pos, buffer, checkSides, rand, seed, modelData);
|
||||
return render(lighter, world, model, state, pos, checkSides, rand, seed, modelData);
|
||||
}
|
||||
else
|
||||
{
|
||||
return super.renderModelFlat(world, model, state, pos, buffer, checkSides, rand, seed, modelData);
|
||||
return super.renderModelFlat(world, model, state, pos, matrixStack, buffer, checkSides, rand, seed, p_228806_11_, modelData);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean renderModelSmooth(IEnviromentBlockReader world, IBakedModel model, BlockState state, BlockPos pos, BufferBuilder buffer, boolean checkSides, Random rand, long seed, IModelData modelData)
|
||||
public boolean renderModelSmooth(ILightReader world, IBakedModel model, BlockState state, BlockPos pos, MatrixStack matrixStack, IVertexBuilder buffer, boolean checkSides, Random rand, long seed, int p_228805_11_, IModelData modelData)
|
||||
{
|
||||
if(ForgeConfig.CLIENT.forgeLightPipelineEnabled.get())
|
||||
{
|
||||
@@ -81,15 +83,15 @@ public class ForgeBlockModelRenderer extends BlockModelRenderer
|
||||
VertexLighterSmoothAo lighter = lighterSmooth.get();
|
||||
lighter.setParent(consumer);
|
||||
|
||||
return render(lighter, world, model, state, pos, buffer, checkSides, rand, seed, modelData);
|
||||
return render(lighter, world, model, state, pos, checkSides, rand, seed, modelData);
|
||||
}
|
||||
else
|
||||
{
|
||||
return super.renderModelSmooth(world, model, state, pos, buffer, checkSides, rand, seed, modelData);
|
||||
return super.renderModelSmooth(world, model, state, pos, matrixStack, buffer, checkSides, rand, seed, p_228805_11_, modelData);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean render(VertexLighterFlat lighter, IEnviromentBlockReader world, IBakedModel model, BlockState state, BlockPos pos, BufferBuilder wr, boolean checkSides, Random rand, long seed, IModelData modelData)
|
||||
public static boolean render(VertexLighterFlat lighter, ILightReader world, IBakedModel model, BlockState state, BlockPos pos, boolean checkSides, Random rand, long seed, IModelData modelData)
|
||||
{
|
||||
lighter.setWorld(world);
|
||||
lighter.setState(state);
|
||||
@@ -127,3 +129,4 @@ public class ForgeBlockModelRenderer extends BlockModelRenderer
|
||||
return !empty;
|
||||
}
|
||||
}
|
||||
*/
|
||||
@@ -24,8 +24,8 @@ import net.minecraft.client.renderer.vertex.VertexFormat;
|
||||
import net.minecraft.util.Direction;
|
||||
|
||||
/**
|
||||
* Assumes that the data length is not less than e.getElementCount().
|
||||
* Also assumes that element index passed will increment from 0 to format.getElementCount() - 1.
|
||||
* Assumes that the data length is not less than e.func_227894_c_().size().
|
||||
* Also assumes that element index passed will increment from 0 to format.func_227894_c_().size() - 1.
|
||||
* Normal, Color and UV are assumed to be in 0-1 range.
|
||||
*/
|
||||
public interface IVertexConsumer
|
||||
|
||||
@@ -19,19 +19,23 @@
|
||||
|
||||
package net.minecraftforge.client.model.pipeline;
|
||||
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import com.mojang.blaze3d.vertex.IVertexBuilder;
|
||||
|
||||
import net.minecraft.client.renderer.BufferBuilder;
|
||||
import net.minecraft.client.renderer.model.BakedQuad;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.client.renderer.model.BakedQuad;
|
||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormat;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormatElement;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormatElement.Usage;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraftforge.client.ForgeHooksClient;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
public class LightUtil
|
||||
{
|
||||
@@ -100,8 +104,8 @@ public class LightUtil
|
||||
float[] data = new float[4];
|
||||
VertexFormat formatFrom = consumer.getVertexFormat();
|
||||
VertexFormat formatTo = quad.getFormat();
|
||||
int countFrom = formatFrom.getElementCount();
|
||||
int countTo = formatTo.getElementCount();
|
||||
int countFrom = formatFrom.func_227894_c_().size();
|
||||
int countTo = formatTo.func_227894_c_().size();
|
||||
int[] eMap = mapFormats(formatFrom, formatTo);
|
||||
for(int v = 0; v < 4; v++)
|
||||
{
|
||||
@@ -120,8 +124,9 @@ public class LightUtil
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: probably useless now, remove?
|
||||
private static final VertexFormat DEFAULT_FROM = VertexLighterFlat.withNormal(DefaultVertexFormats.BLOCK);
|
||||
private static final VertexFormat DEFAULT_TO = DefaultVertexFormats.ITEM;
|
||||
private static final VertexFormat DEFAULT_TO = DefaultVertexFormats.BLOCK;
|
||||
private static final int[] DEFAULT_MAPPING = generateMapping(DEFAULT_FROM, DEFAULT_TO);
|
||||
public static int[] mapFormats(VertexFormat from, VertexFormat to)
|
||||
{
|
||||
@@ -133,17 +138,17 @@ public class LightUtil
|
||||
|
||||
private static int[] generateMapping(VertexFormat from, VertexFormat to)
|
||||
{
|
||||
int fromCount = from.getElementCount();
|
||||
int toCount = to.getElementCount();
|
||||
int fromCount = from.func_227894_c_().size();
|
||||
int toCount = to.func_227894_c_().size();
|
||||
int[] eMap = new int[fromCount];
|
||||
|
||||
for(int e = 0; e < fromCount; e++)
|
||||
{
|
||||
VertexFormatElement expected = from.getElement(e);
|
||||
VertexFormatElement expected = from.func_227894_c_().get(e);
|
||||
int e2;
|
||||
for(e2 = 0; e2 < toCount; e2++)
|
||||
{
|
||||
VertexFormatElement current = to.getElement(e2);
|
||||
VertexFormatElement current = to.func_227894_c_().get(e2);
|
||||
if(expected.getUsage() == current.getUsage() && expected.getIndex() == current.getIndex())
|
||||
{
|
||||
break;
|
||||
@@ -157,7 +162,7 @@ public class LightUtil
|
||||
public static void unpack(int[] from, float[] to, VertexFormat formatFrom, int v, int e)
|
||||
{
|
||||
int length = 4 < to.length ? 4 : to.length;
|
||||
VertexFormatElement element = formatFrom.getElement(e);
|
||||
VertexFormatElement element = formatFrom.func_227894_c_().get(e);
|
||||
int vertexStart = v * formatFrom.getSize() + formatFrom.getOffset(e);
|
||||
int count = element.getElementCount();
|
||||
VertexFormatElement.Type type = element.getType();
|
||||
@@ -211,7 +216,7 @@ public class LightUtil
|
||||
|
||||
public static void pack(float[] from, int[] to, VertexFormat formatTo, int v, int e)
|
||||
{
|
||||
VertexFormatElement element = formatTo.getElement(e);
|
||||
VertexFormatElement element = formatTo.func_227894_c_().get(e);
|
||||
int vertexStart = v * formatTo.getSize() + formatTo.getOffset(e);
|
||||
int count = element.getElementCount();
|
||||
VertexFormatElement.Type type = element.getType();
|
||||
@@ -288,36 +293,27 @@ public class LightUtil
|
||||
private static final ThreadLocal<ItemPipeline> itemPipeline = ThreadLocal.withInitial(ItemPipeline::new);
|
||||
|
||||
// renders quad in any Vertex Format, but is slower
|
||||
public static void renderQuadColorSlow(BufferBuilder buffer, BakedQuad quad, int auxColor)
|
||||
/*public static void renderQuadColorSlow(IVertexBuilder buffer, BakedQuad quad, float r, float g, float b, float a)
|
||||
{
|
||||
ItemPipeline pipeline = itemPipeline.get();
|
||||
pipeline.bufferConsumer.setBuffer(buffer);
|
||||
ItemConsumer cons = pipeline.itemConsumer;
|
||||
|
||||
float b = (float)( auxColor & 0xFF) / 0xFF;
|
||||
float g = (float)((auxColor >>> 8) & 0xFF) / 0xFF;
|
||||
float r = (float)((auxColor >>> 16) & 0xFF) / 0xFF;
|
||||
float a = (float)((auxColor >>> 24) & 0xFF) / 0xFF;
|
||||
|
||||
cons.setAuxColor(r, g, b, a);
|
||||
quad.pipe(cons);
|
||||
}
|
||||
|
||||
public static void renderQuadColor(BufferBuilder buffer, BakedQuad quad, int auxColor)
|
||||
public static void renderQuadColor(IVertexBuilder builder, MatrixStack.Entry entry, BakedQuad quad, float r, float g, float b, float a, int light, int overlaylight)
|
||||
{
|
||||
if (quad.getFormat().equals(buffer.getVertexFormat()))
|
||||
if (quad.getFormat().equals(DefaultVertexFormats.BLOCK))
|
||||
{
|
||||
buffer.addVertexData(quad.getVertexData());
|
||||
if (buffer.getVertexFormat().hasColor())
|
||||
{
|
||||
ForgeHooksClient.putQuadColor(buffer, quad, auxColor);
|
||||
}
|
||||
builder.addVertexData(entry, quad, r, g, b, a, light, overlaylight);
|
||||
}
|
||||
else
|
||||
{
|
||||
renderQuadColorSlow(buffer, quad, auxColor);
|
||||
renderQuadColorSlow(builder, quad, r, g, b, a);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
public static class ItemConsumer extends VertexTransformer
|
||||
{
|
||||
@@ -339,7 +335,7 @@ public class LightUtil
|
||||
@Override
|
||||
public void put(int element, float... data)
|
||||
{
|
||||
if(getVertexFormat().getElement(element).getUsage() == Usage.COLOR)
|
||||
if(getVertexFormat().func_227894_c_().get(element).getUsage() == Usage.COLOR)
|
||||
{
|
||||
System.arraycopy(auxColor, 0, buf, 0, buf.length);
|
||||
int n = Math.min(4, data.length);
|
||||
@@ -353,7 +349,7 @@ public class LightUtil
|
||||
{
|
||||
super.put(element, data);
|
||||
}
|
||||
if(element == getVertexFormat().getElementCount() - 1)
|
||||
if(element == getVertexFormat().func_227894_c_().size() - 1)
|
||||
{
|
||||
vertices++;
|
||||
if(vertices == 4)
|
||||
|
||||
+3
-3
@@ -38,8 +38,8 @@ public abstract class QuadGatheringTransformer implements IVertexConsumer
|
||||
public void setVertexFormat(VertexFormat format)
|
||||
{
|
||||
this.format = format;
|
||||
dataLength = new byte[format.getElementCount()];
|
||||
quadData = new float[format.getElementCount()][4][4];
|
||||
dataLength = new byte[format.func_227894_c_().size()];
|
||||
quadData = new float[format.func_227894_c_().size()][4][4];
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -56,7 +56,7 @@ public abstract class QuadGatheringTransformer implements IVertexConsumer
|
||||
{
|
||||
dataLength[element] = (byte)data.length;
|
||||
}
|
||||
if (element == getVertexFormat().getElementCount() - 1)
|
||||
if (element == getVertexFormat().func_227894_c_().size() - 1)
|
||||
{
|
||||
vertices++;
|
||||
}
|
||||
|
||||
@@ -19,16 +19,16 @@
|
||||
|
||||
package net.minecraftforge.client.model.pipeline;
|
||||
|
||||
import net.minecraftforge.common.model.TRSRTransformation;
|
||||
import net.minecraft.client.renderer.TransformationMatrix;
|
||||
import net.minecraft.client.renderer.Vector4f;
|
||||
|
||||
import javax.vecmath.Vector3f;
|
||||
import javax.vecmath.Vector4f;
|
||||
|
||||
public class TRSRTransformer extends VertexTransformer
|
||||
{
|
||||
private final TRSRTransformation transform;
|
||||
private final TransformationMatrix transform;
|
||||
|
||||
public TRSRTransformer(IVertexConsumer parent, TRSRTransformation transform)
|
||||
public TRSRTransformer(IVertexConsumer parent, TransformationMatrix transform)
|
||||
{
|
||||
super(parent);
|
||||
this.transform = transform;
|
||||
@@ -37,12 +37,12 @@ public class TRSRTransformer extends VertexTransformer
|
||||
@Override
|
||||
public void put(int element, float... data)
|
||||
{
|
||||
switch (getVertexFormat().getElement(element).getUsage())
|
||||
switch (getVertexFormat().func_227894_c_().get(element).getUsage())
|
||||
{
|
||||
case POSITION:
|
||||
Vector4f pos = new Vector4f(data);
|
||||
transform.transformPosition(pos);
|
||||
pos.get(data);
|
||||
pos.write(data);
|
||||
break;
|
||||
case NORMAL:
|
||||
Vector3f normal = new Vector3f(data);
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
package net.minecraftforge.client.model.pipeline;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import net.minecraft.client.renderer.model.BakedQuad;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormat;
|
||||
@@ -48,7 +49,7 @@ public class UnpackedBakedQuad extends BakedQuad
|
||||
packed = true;
|
||||
for(int v = 0; v < 4; v++)
|
||||
{
|
||||
for(int e = 0; e < format.getElementCount(); e++)
|
||||
for(int e = 0; e < format.func_227894_c_().size(); e++)
|
||||
{
|
||||
LightUtil.pack(unpackedData[v][e], vertexData, format, v, e);
|
||||
}
|
||||
@@ -57,7 +58,7 @@ public class UnpackedBakedQuad extends BakedQuad
|
||||
return vertexData;
|
||||
}
|
||||
|
||||
@Override
|
||||
//@Override
|
||||
public void pipe(IVertexConsumer consumer)
|
||||
{
|
||||
int[] eMap = LightUtil.mapFormats(consumer.getVertexFormat(), format);
|
||||
@@ -71,9 +72,9 @@ public class UnpackedBakedQuad extends BakedQuad
|
||||
consumer.setQuadOrientation(getFace());
|
||||
for(int v = 0; v < 4; v++)
|
||||
{
|
||||
for(int e = 0; e < consumer.getVertexFormat().getElementCount(); e++)
|
||||
for(int e = 0; e < consumer.getVertexFormat().func_227894_c_().size(); e++)
|
||||
{
|
||||
if(eMap[e] != format.getElementCount())
|
||||
if(eMap[e] != format.func_227894_c_().size())
|
||||
{
|
||||
consumer.put(e, unpackedData[v][eMap[e]]);
|
||||
}
|
||||
@@ -102,7 +103,7 @@ public class UnpackedBakedQuad extends BakedQuad
|
||||
public Builder(VertexFormat format)
|
||||
{
|
||||
this.format = format;
|
||||
unpackedData = new float[4][format.getElementCount()][4];
|
||||
unpackedData = new float[4][format.func_227894_c_().size()][4];
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -155,7 +156,7 @@ public class UnpackedBakedQuad extends BakedQuad
|
||||
}
|
||||
}
|
||||
elements++;
|
||||
if(elements == format.getElementCount())
|
||||
if(elements == format.func_227894_c_().size())
|
||||
{
|
||||
vertices++;
|
||||
elements = 0;
|
||||
@@ -185,16 +186,17 @@ public class UnpackedBakedQuad extends BakedQuad
|
||||
float tS = tX > tY ? tX : tY;
|
||||
float ep = 1f / (tS * 0x100);
|
||||
int uve = 0;
|
||||
while(uve < format.getElementCount())
|
||||
ImmutableList<VertexFormatElement> elements = format.func_227894_c_();
|
||||
while(uve < elements.size())
|
||||
{
|
||||
VertexFormatElement e = format.getElement(uve);
|
||||
VertexFormatElement e = elements.get(uve);
|
||||
if(e.getUsage() == VertexFormatElement.Usage.UV && e.getIndex() == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
uve++;
|
||||
}
|
||||
if(uve == format.getElementCount())
|
||||
if(uve == elements.size())
|
||||
{
|
||||
throw new IllegalStateException("Can't contract UVs: format doesn't contain UVs");
|
||||
}
|
||||
|
||||
@@ -19,8 +19,10 @@
|
||||
|
||||
package net.minecraftforge.client.model.pipeline;
|
||||
|
||||
import com.mojang.blaze3d.vertex.IVertexBuilder;
|
||||
import net.minecraft.client.renderer.BufferBuilder;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormat;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormatElement.Usage;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
@@ -33,14 +35,14 @@ public class VertexBufferConsumer implements IVertexConsumer
|
||||
{
|
||||
private static final float[] dummyColor = new float[]{ 1, 1, 1, 1 };
|
||||
|
||||
private BufferBuilder renderer;
|
||||
private IVertexBuilder renderer;
|
||||
private int[] quadData;
|
||||
private int v = 0;
|
||||
private BlockPos offset = BlockPos.ZERO;
|
||||
|
||||
public VertexBufferConsumer() {}
|
||||
|
||||
public VertexBufferConsumer(BufferBuilder buffer)
|
||||
public VertexBufferConsumer(IVertexBuilder buffer)
|
||||
{
|
||||
setBuffer(buffer);
|
||||
}
|
||||
@@ -48,19 +50,21 @@ public class VertexBufferConsumer implements IVertexConsumer
|
||||
@Override
|
||||
public VertexFormat getVertexFormat()
|
||||
{
|
||||
return renderer.getVertexFormat();
|
||||
return DefaultVertexFormats.BLOCK; // renderer.getVertexFormat();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void put(int e, float... data)
|
||||
{
|
||||
// TODO
|
||||
/*
|
||||
VertexFormat format = getVertexFormat();
|
||||
if(renderer.isColorDisabled() && format.getElement(e).getUsage() == Usage.COLOR)
|
||||
if(renderer.isColorDisabled() && format.func_227894_c_().get(e).getUsage() == Usage.COLOR)
|
||||
{
|
||||
data = dummyColor;
|
||||
}
|
||||
LightUtil.pack(data, quadData, format, v, e);
|
||||
if(e == format.getElementCount() - 1)
|
||||
if(e == format.func_227894_c_().size() - 1)
|
||||
{
|
||||
v++;
|
||||
if(v == 4)
|
||||
@@ -71,17 +75,18 @@ public class VertexBufferConsumer implements IVertexConsumer
|
||||
v = 0;
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
private void checkVertexFormat()
|
||||
{
|
||||
if (quadData == null || renderer.getVertexFormat().getSize() != quadData.length)
|
||||
if (quadData == null || getVertexFormat().getSize() != quadData.length)
|
||||
{
|
||||
quadData = new int[renderer.getVertexFormat().getSize()];
|
||||
quadData = new int[getVertexFormat().getSize()];
|
||||
}
|
||||
}
|
||||
|
||||
public void setBuffer(BufferBuilder buffer)
|
||||
public void setBuffer(IVertexBuilder buffer)
|
||||
{
|
||||
this.renderer = buffer;
|
||||
checkVertexFormat();
|
||||
|
||||
@@ -21,6 +21,8 @@ package net.minecraftforge.client.model.pipeline;
|
||||
|
||||
import javax.vecmath.Vector3f;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Lists;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.renderer.GameRenderer;
|
||||
import net.minecraft.client.renderer.color.BlockColors;
|
||||
@@ -30,9 +32,10 @@ import net.minecraft.client.renderer.vertex.VertexFormat;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormatElement;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IEnviromentBlockReader;
|
||||
import net.minecraft.world.ILightReader;
|
||||
import net.minecraft.world.IWorldReader;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class VertexLighterFlat extends QuadGatheringTransformer
|
||||
@@ -64,9 +67,9 @@ public class VertexLighterFlat extends QuadGatheringTransformer
|
||||
|
||||
private void updateIndices()
|
||||
{
|
||||
for(int i = 0; i < getVertexFormat().getElementCount(); i++)
|
||||
for(int i = 0; i < getVertexFormat().func_227894_c_().size(); i++)
|
||||
{
|
||||
switch(getVertexFormat().getElement(i).getUsage())
|
||||
switch(getVertexFormat().func_227894_c_().get(i).getUsage())
|
||||
{
|
||||
case POSITION:
|
||||
posIndex = i;
|
||||
@@ -78,7 +81,7 @@ public class VertexLighterFlat extends QuadGatheringTransformer
|
||||
colorIndex = i;
|
||||
break;
|
||||
case UV:
|
||||
if(getVertexFormat().getElement(i).getIndex() == 1)
|
||||
if(getVertexFormat().func_227894_c_().get(i).getIndex() == 2)
|
||||
{
|
||||
lightmapIndex = i;
|
||||
}
|
||||
@@ -109,19 +112,21 @@ public class VertexLighterFlat extends QuadGatheringTransformer
|
||||
updateIndices();
|
||||
}
|
||||
|
||||
private static final VertexFormat BLOCK_WITH_NORMAL = withNormalUncached(DefaultVertexFormats.BLOCK);
|
||||
static VertexFormat withNormal(VertexFormat format)
|
||||
{
|
||||
//This is the case in 99.99%. Cache the value, so we don't have to redo it every time, and the speed up the equals check in LightUtil
|
||||
if (format == DefaultVertexFormats.BLOCK)
|
||||
return BLOCK_WITH_NORMAL;
|
||||
return DefaultVertexFormats.BLOCK;
|
||||
return withNormalUncached(format);
|
||||
}
|
||||
|
||||
private static VertexFormat withNormalUncached(VertexFormat format)
|
||||
{
|
||||
if (format == null || format.hasNormal()) return format;
|
||||
return new VertexFormat(format).addElement(NORMAL_4F);
|
||||
if (format == null || format.hasNormal())
|
||||
return format;
|
||||
List<VertexFormatElement> l = Lists.newArrayList(format.func_227894_c_());
|
||||
l.add(NORMAL_4F);
|
||||
return new VertexFormat(ImmutableList.copyOf(l));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -166,7 +171,7 @@ public class VertexLighterFlat extends QuadGatheringTransformer
|
||||
}
|
||||
|
||||
VertexFormat format = parent.getVertexFormat();
|
||||
int count = format.getElementCount();
|
||||
int count = format.func_227894_c_().size();
|
||||
|
||||
for(int v = 0; v < 4; v++)
|
||||
{
|
||||
@@ -205,7 +210,7 @@ public class VertexLighterFlat extends QuadGatheringTransformer
|
||||
// no need for remapping cause all we could've done is add 1 element to the end
|
||||
for(int e = 0; e < count; e++)
|
||||
{
|
||||
VertexFormatElement element = format.getElement(e);
|
||||
VertexFormatElement element = format.func_227894_c_().get(e);
|
||||
switch(element.getUsage())
|
||||
{
|
||||
case POSITION:
|
||||
@@ -286,7 +291,7 @@ public class VertexLighterFlat extends QuadGatheringTransformer
|
||||
this.diffuse = diffuse;
|
||||
}
|
||||
|
||||
public void setWorld(IEnviromentBlockReader world)
|
||||
public void setWorld(ILightReader world)
|
||||
{
|
||||
blockInfo.setWorld(world);
|
||||
}
|
||||
|
||||
@@ -52,10 +52,11 @@ import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.ChunkPos;
|
||||
import net.minecraft.util.registry.MutableRegistry;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.biome.IBiomeMagnifier;
|
||||
import net.minecraft.world.chunk.ChunkStatus;
|
||||
import net.minecraft.world.chunk.listener.IChunkStatusListener;
|
||||
import net.minecraft.world.server.ServerMultiWorld;
|
||||
import net.minecraft.world.server.ServerWorld;
|
||||
import net.minecraft.world.ServerMultiWorld;
|
||||
import net.minecraft.world.dimension.DimensionType;
|
||||
import net.minecraftforge.event.world.RegisterDimensionsEvent;
|
||||
import net.minecraftforge.event.world.WorldEvent;
|
||||
@@ -96,6 +97,7 @@ public class DimensionManager
|
||||
* @param type ModDimension type data
|
||||
* @param data Extra data for the ModDimension
|
||||
* @param hasSkyLight does this dimension have a skylight?
|
||||
* @param magnifier The biome generation processor
|
||||
* @return the DimensionType for the dimension.
|
||||
*/
|
||||
public static DimensionType registerOrGetDimension(ResourceLocation name, ModDimension type, PacketBuffer data, boolean hasSkyLight) {
|
||||
@@ -111,6 +113,7 @@ public class DimensionManager
|
||||
* @param type Dimension Type.
|
||||
* @param data Configuration data for this dimension, passed into
|
||||
* @param hasSkyLight skylight for this dimension
|
||||
* @param magnifier The biome generation processor
|
||||
* @return the DimensionType for the dimension.
|
||||
*/
|
||||
public static DimensionType registerDimension(ResourceLocation name, ModDimension type, PacketBuffer data, boolean hasSkyLight)
|
||||
@@ -129,7 +132,7 @@ public class DimensionManager
|
||||
savedEntries.remove(name);
|
||||
}
|
||||
@SuppressWarnings("deprecation")
|
||||
DimensionType instance = new DimensionType(id, "", name.getNamespace() + "/" + name.getPath(), type.getFactory(), hasSkyLight, type, data);
|
||||
DimensionType instance = new DimensionType(id, "", name.getNamespace() + "/" + name.getPath(), type.getFactory(), hasSkyLight, type.getMagnifier(), type, data);
|
||||
REGISTRY.register(id, name, instance);
|
||||
LOGGER.info(DIMMGR, "Registered dimension {} of type {} and id {}", name.toString(), type.getRegistryName().toString(), id);
|
||||
return instance;
|
||||
@@ -214,7 +217,7 @@ public class DimensionManager
|
||||
Validate.isTrue(REGISTRY.getByValue(id) == null, "Dimension with id " + id + " already registered as name " + REGISTRY.getKey(REGISTRY.getByValue(id)));
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
DimensionType instance = new DimensionType(id, "", name.getNamespace() + "/" + name.getPath(), type.getFactory(), hasSkyLight, type, data);
|
||||
DimensionType instance = new DimensionType(id, "", name.getNamespace() + "/" + name.getPath(), type.getFactory(), hasSkyLight, type.getMagnifier(), type, data);
|
||||
REGISTRY.register(id, name, instance);
|
||||
LOGGER.info(DIMMGR, "Registered dimension {} of type {} and id {}", name.toString(), type.getRegistryName().toString(), id);
|
||||
return instance;
|
||||
|
||||
@@ -46,6 +46,8 @@ import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.advancements.Advancement;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.renderer.model.Material;
|
||||
import net.minecraft.client.renderer.texture.AtlasTexture;
|
||||
import net.minecraft.fluid.*;
|
||||
import net.minecraft.util.CachedBlockInfo;
|
||||
import net.minecraft.block.BlockState;
|
||||
@@ -744,7 +746,7 @@ public class ForgeHooks
|
||||
|
||||
public static ActionResultType onInteractEntityAt(PlayerEntity player, Entity entity, RayTraceResult ray, Hand hand)
|
||||
{
|
||||
Vec3d vec3d = new Vec3d(ray.getHitVec().x - entity.posX, ray.getHitVec().y - entity.posY, ray.getHitVec().z - entity.posZ);
|
||||
Vec3d vec3d = ray.getHitVec().subtract(entity.getPositionVec());
|
||||
return onInteractEntityAt(player, entity, vec3d, hand);
|
||||
}
|
||||
|
||||
@@ -844,15 +846,15 @@ public class ForgeHooks
|
||||
.color(0).density(0).temperature(0).luminosity(0).viscosity(0).build(fluid);
|
||||
if (fluid instanceof WaterFluid)
|
||||
return net.minecraftforge.fluids.FluidAttributes.Water.builder(
|
||||
new net.minecraft.util.ResourceLocation("block/water_still"),
|
||||
new net.minecraft.util.ResourceLocation("block/water_flow"))
|
||||
.overlay(new net.minecraft.util.ResourceLocation("block/water_overlay"))
|
||||
new Material(AtlasTexture.LOCATION_BLOCKS_TEXTURE, new ResourceLocation("block/water_still")),
|
||||
new Material(AtlasTexture.LOCATION_BLOCKS_TEXTURE, new ResourceLocation("block/water_flow")))
|
||||
.overlay(new Material(AtlasTexture.LOCATION_BLOCKS_TEXTURE, new ResourceLocation("block/water_overlay")))
|
||||
.translationKey("block.minecraft.water")
|
||||
.color(0xFF3F76E4).build(fluid);
|
||||
if (fluid instanceof LavaFluid)
|
||||
return net.minecraftforge.fluids.FluidAttributes.builder(
|
||||
new net.minecraft.util.ResourceLocation("block/lava_still"),
|
||||
new net.minecraft.util.ResourceLocation("block/lava_flow"))
|
||||
new Material(AtlasTexture.LOCATION_BLOCKS_TEXTURE, new ResourceLocation("block/lava_still")),
|
||||
new Material(AtlasTexture.LOCATION_BLOCKS_TEXTURE, new ResourceLocation("block/lava_flow")))
|
||||
.translationKey("block.minecraft.lava")
|
||||
.luminosity(15).density(3000).viscosity(6000).temperature(1300).build(fluid);
|
||||
throw new RuntimeException("Mod fluids must override createAttributes.");
|
||||
|
||||
@@ -25,7 +25,6 @@ import net.minecraft.entity.player.ServerPlayerEntity;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.server.ServerWorld;
|
||||
import net.minecraftforge.client.CloudRenderer;
|
||||
import net.minecraftforge.common.util.FakePlayerFactory;
|
||||
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
|
||||
import net.minecraftforge.event.entity.player.PlayerEvent;
|
||||
@@ -79,8 +78,8 @@ public class ForgeInternalHandler
|
||||
@SubscribeEvent
|
||||
public void checkSettings(ClientTickEvent event)
|
||||
{
|
||||
if (event.phase == Phase.END)
|
||||
CloudRenderer.updateCloudSettings();
|
||||
//if (event.phase == Phase.END)
|
||||
// CloudRenderer.updateCloudSettings();
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
|
||||
@@ -23,6 +23,8 @@ import java.util.function.BiFunction;
|
||||
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.biome.ColumnFuzzedBiomeMagnifier;
|
||||
import net.minecraft.world.biome.IBiomeMagnifier;
|
||||
import net.minecraft.world.dimension.Dimension;
|
||||
import net.minecraft.world.dimension.DimensionType;
|
||||
import net.minecraftforge.registries.ForgeRegistryEntry;
|
||||
@@ -55,6 +57,10 @@ public abstract class ModDimension extends ForgeRegistryEntry<ModDimension>
|
||||
*/
|
||||
public void read(PacketBuffer buffer, boolean network){}
|
||||
|
||||
public IBiomeMagnifier getMagnifier() {
|
||||
return ColumnFuzzedBiomeMagnifier.INSTANCE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method for generating a ModDimension with a specific factory but no extra
|
||||
* data handling behaviour. Extend ModDimension to override other methods.
|
||||
|
||||
@@ -57,7 +57,7 @@ public class ForgeBlockTagsProvider extends BlockTagsProvider
|
||||
getBuilder(CHESTS_TRAPPED).add(Blocks.TRAPPED_CHEST);
|
||||
getBuilder(CHESTS_WOODEN).add(Blocks.CHEST, Blocks.TRAPPED_CHEST);
|
||||
getBuilder(COBBLESTONE).add(Blocks.COBBLESTONE, Blocks.INFESTED_COBBLESTONE, Blocks.MOSSY_COBBLESTONE);
|
||||
getBuilder(DIRT).add(Blocks.DIRT, Blocks.COARSE_DIRT, Blocks.PODZOL);
|
||||
getBuilder(DIRT).add(Blocks.DIRT, Blocks.GRASS_BLOCK, Blocks.COARSE_DIRT, Blocks.PODZOL, Blocks.MYCELIUM);
|
||||
getBuilder(END_STONES).add(Blocks.END_STONE);
|
||||
getBuilder(FENCE_GATES).add(FENCE_GATES_WOODEN);
|
||||
getBuilder(FENCE_GATES_WOODEN).add(Blocks.OAK_FENCE_GATE, Blocks.SPRUCE_FENCE_GATE, Blocks.BIRCH_FENCE_GATE, Blocks.JUNGLE_FENCE_GATE, Blocks.ACACIA_FENCE_GATE, Blocks.DARK_OAK_FENCE_GATE);
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package net.minecraftforge.common.data;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
|
||||
@@ -61,7 +61,6 @@ import net.minecraft.state.IProperty;
|
||||
import net.minecraft.state.properties.BedPart;
|
||||
import net.minecraft.tags.BlockTags;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.BlockRenderLayer;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
@@ -71,7 +70,7 @@ import net.minecraft.util.math.RayTraceResult;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.Explosion;
|
||||
import net.minecraft.world.IBlockReader;
|
||||
import net.minecraft.world.IEnviromentBlockReader;
|
||||
import net.minecraft.world.ILightReader;
|
||||
import net.minecraft.world.IWorld;
|
||||
import net.minecraft.world.IWorldReader;
|
||||
import net.minecraft.world.IWorldWriter;
|
||||
@@ -118,7 +117,7 @@ public interface IForgeBlock
|
||||
* @param pos
|
||||
* @return The light value
|
||||
*/
|
||||
default int getLightValue(BlockState state, IEnviromentBlockReader world, BlockPos pos)
|
||||
default int getLightValue(BlockState state, ILightReader world, BlockPos pos)
|
||||
{
|
||||
return state.getLightValue();
|
||||
}
|
||||
@@ -152,7 +151,7 @@ public interface IForgeBlock
|
||||
* @deprecated This is no longer used for rendering logic.
|
||||
*/
|
||||
@Deprecated
|
||||
default boolean doesSideBlockRendering(BlockState state, IEnviromentBlockReader world, BlockPos pos, Direction face)
|
||||
default boolean doesSideBlockRendering(BlockState state, ILightReader world, BlockPos pos, Direction face)
|
||||
{
|
||||
return state.isOpaqueCube(world, pos);
|
||||
}
|
||||
@@ -383,7 +382,7 @@ public interface IForgeBlock
|
||||
*/
|
||||
default boolean canBeReplacedByLogs(BlockState state, IWorldReader world, BlockPos pos)
|
||||
{
|
||||
return (isAir(state, world, pos) || state.isIn(BlockTags.LEAVES)) || this == Blocks.GRASS_BLOCK || Block.isDirt(getBlock())
|
||||
return (isAir(state, world, pos) || state.isIn(BlockTags.LEAVES)) || this == Blocks.GRASS_BLOCK || state.isIn(net.minecraftforge.common.Tags.Blocks.DIRT)
|
||||
|| getBlock().isIn(BlockTags.LOGS) || getBlock().isIn(BlockTags.SAPLINGS) || this == Blocks.VINE;
|
||||
}
|
||||
|
||||
@@ -559,7 +558,7 @@ public interface IForgeBlock
|
||||
*/
|
||||
default void onPlantGrow(BlockState state, IWorld world, BlockPos pos, BlockPos source)
|
||||
{
|
||||
if (Block.isDirt(getBlock()))
|
||||
if (state.isIn(net.minecraftforge.common.Tags.Blocks.DIRT))
|
||||
world.setBlockState(pos, Blocks.DIRT.getDefaultState(), 2);
|
||||
}
|
||||
|
||||
@@ -751,15 +750,6 @@ public interface IForgeBlock
|
||||
return state;
|
||||
}
|
||||
|
||||
/**
|
||||
* Queries if this block should render in a given layer.
|
||||
* A custom {@link IBakedModel} can use {@link net.minecraftforge.client.MinecraftForgeClient#getRenderLayer()} to alter the model based on layer.
|
||||
*/
|
||||
default boolean canRenderInLayer(BlockState state, BlockRenderLayer layer)
|
||||
{
|
||||
return this.getBlock().getRenderLayer() == layer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sensitive version of getSoundType
|
||||
* @param state The state
|
||||
@@ -881,7 +871,16 @@ public interface IForgeBlock
|
||||
@Nullable
|
||||
default PathNodeType getAiPathNodeType(BlockState state, IBlockReader world, BlockPos pos, @Nullable MobEntity entity)
|
||||
{
|
||||
return state.isBurning(world, pos) ? PathNodeType.DAMAGE_FIRE : null;
|
||||
return state.isBurning(world, pos) ? PathNodeType.DANGER_FIRE : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param state The state
|
||||
* @return true if the block is sticky block which used for pull or push adjacent blocks (use by piston)
|
||||
*/
|
||||
default boolean isSlimeBlock(BlockState state)
|
||||
{
|
||||
return state.getBlock() == Blocks.SLIME_BLOCK;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -890,7 +889,20 @@ public interface IForgeBlock
|
||||
*/
|
||||
default boolean isStickyBlock(BlockState state)
|
||||
{
|
||||
return state.getBlock() == Blocks.SLIME_BLOCK;
|
||||
return state.getBlock() == Blocks.SLIME_BLOCK || state.getBlock() == Blocks.field_226907_mc_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if this block can stick to another block when pushed by a piston.
|
||||
* @param state My state
|
||||
* @param other Other block
|
||||
* @return True to link blocks
|
||||
*/
|
||||
default boolean canStickTo(BlockState state, BlockState other)
|
||||
{
|
||||
if (state.getBlock() == Blocks.field_226907_mc_ && other.getBlock() == Blocks.SLIME_BLOCK) return false;
|
||||
if (state.getBlock() == Blocks.SLIME_BLOCK && other.getBlock() == Blocks.field_226907_mc_) return false;
|
||||
return state.isStickyBlock() || other.isStickyBlock();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -45,7 +45,7 @@ import net.minecraft.util.math.RayTraceResult;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.Explosion;
|
||||
import net.minecraft.world.IBlockReader;
|
||||
import net.minecraft.world.IEnviromentBlockReader;
|
||||
import net.minecraft.world.ILightReader;
|
||||
import net.minecraft.world.IWorld;
|
||||
import net.minecraft.world.IWorldReader;
|
||||
import net.minecraft.world.World;
|
||||
@@ -84,7 +84,7 @@ public interface IForgeBlockState
|
||||
/**
|
||||
* Get a light value for this block, taking into account the given state and coordinates, normal ranges are between 0 and 15
|
||||
*/
|
||||
default int getLightValue(IEnviromentBlockReader world, BlockPos pos)
|
||||
default int getLightValue(ILightReader world, BlockPos pos)
|
||||
{
|
||||
return getBlockState().getBlock().getLightValue(getBlockState(), world, pos);
|
||||
}
|
||||
@@ -116,7 +116,7 @@ public interface IForgeBlockState
|
||||
* @deprecated This is no longer used for rendering logic.
|
||||
*/
|
||||
@Deprecated
|
||||
default boolean doesSideBlockRendering(IEnviromentBlockReader world, BlockPos pos, Direction face)
|
||||
default boolean doesSideBlockRendering(ILightReader world, BlockPos pos, Direction face)
|
||||
{
|
||||
return getBlockState().getBlock().doesSideBlockRendering(getBlockState(), world, pos, face);
|
||||
}
|
||||
@@ -632,23 +632,6 @@ public interface IForgeBlockState
|
||||
return getBlockState().getBlock().isToolEffective(getBlockState(), tool);
|
||||
}
|
||||
|
||||
/**
|
||||
* Can return IExtendedBlockState
|
||||
*/
|
||||
default BlockState getExtendedState(IBlockReader world, BlockPos pos)
|
||||
{
|
||||
return getBlockState().getBlock().getExtendedState(getBlockState(), world, pos);
|
||||
}
|
||||
|
||||
/**
|
||||
* Queries if this blockstate should render in a given layer.
|
||||
* A custom {@link IBakedModel} can use {@link net.minecraftforge.client.MinecraftForgeClient#getRenderLayer()} to alter the model based on layer.
|
||||
*/
|
||||
default boolean canRenderInLayer(BlockRenderLayer layer)
|
||||
{
|
||||
return getBlockState().getBlock().canRenderInLayer(getBlockState(), layer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sensitive version of getSoundType
|
||||
* @param world The world
|
||||
@@ -735,6 +718,15 @@ public interface IForgeBlockState
|
||||
return getBlockState().getBlock().canBeConnectedTo(getBlockState(), world, pos, facing);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param state The state
|
||||
* @return true if the block is sticky block which used for pull or push adjacent blocks (use by piston)
|
||||
*/
|
||||
default boolean isSlimeBlock()
|
||||
{
|
||||
return getBlockState().getBlock().isSlimeBlock(getBlockState());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param state The state
|
||||
* @return true if the block is sticky block which used for pull or push adjacent blocks (use by piston)
|
||||
@@ -744,6 +736,16 @@ public interface IForgeBlockState
|
||||
return getBlockState().getBlock().isStickyBlock(getBlockState());
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if this block can stick to another block when pushed by a piston.
|
||||
* @param other Other block
|
||||
* @return True to link blocks
|
||||
*/
|
||||
default boolean canStickTo(BlockState other)
|
||||
{
|
||||
return getBlockState().getBlock().canStickTo(getBlockState(), other);
|
||||
}
|
||||
|
||||
/**
|
||||
* Chance that fire will spread and consume this block.
|
||||
* 300 being a 100% chance, 0, being a 0% chance.
|
||||
@@ -851,6 +853,17 @@ public interface IForgeBlockState
|
||||
return getBlockState().getBlock().isBurning(getBlockState(), world, pos);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the {@code PathNodeType} for this block. Return {@code null} for vanilla behavior.
|
||||
*
|
||||
* @return the PathNodeType
|
||||
*/
|
||||
@Nullable
|
||||
default PathNodeType getAiPathNodeType(IBlockReader world, BlockPos pos)
|
||||
{
|
||||
return getAiPathNodeType(world, pos, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the {@code PathNodeType} for this block. Return {@code null} for vanilla behavior.
|
||||
*
|
||||
|
||||
@@ -22,12 +22,14 @@ package net.minecraftforge.common.extensions;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.client.audio.MusicTicker;
|
||||
import net.minecraft.client.renderer.Vector3f;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import net.minecraft.world.biome.Biomes;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
import net.minecraft.world.dimension.Dimension;
|
||||
import net.minecraft.world.dimension.DimensionType;
|
||||
@@ -114,7 +116,7 @@ public interface IForgeDimension
|
||||
*
|
||||
* @see net.minecraft.client.renderer.GameRenderer#updateLightmap(float)
|
||||
*/
|
||||
default void getLightmapColors(float partialTicks, float sunBrightness, float skyLight, float blockLight, float[] colors) {}
|
||||
default void getLightmapColors(float partialTicks, float sunBrightness, float skyLight, float blockLight, Vector3f colors) {}
|
||||
|
||||
void resetRainAndThunder();
|
||||
|
||||
@@ -149,7 +151,7 @@ public interface IForgeDimension
|
||||
*/
|
||||
default SleepResult canSleepAt(net.minecraft.entity.player.PlayerEntity player, BlockPos pos)
|
||||
{
|
||||
return (getDimension().canRespawnHere() && getWorld().getBiome(pos) != net.minecraft.world.biome.Biomes.NETHER) ? SleepResult.ALLOW : SleepResult.BED_EXPLODES;
|
||||
return (getDimension().canRespawnHere() && getWorld().func_226691_t_(pos) != Biomes.NETHER) ? SleepResult.ALLOW : SleepResult.BED_EXPLODES;
|
||||
}
|
||||
|
||||
enum SleepResult
|
||||
@@ -159,39 +161,9 @@ public interface IForgeDimension
|
||||
BED_EXPLODES;
|
||||
}
|
||||
|
||||
default Biome getBiome(BlockPos pos)
|
||||
{
|
||||
return getWorld().getBiomeBody(pos);
|
||||
}
|
||||
|
||||
default boolean isDaytime()
|
||||
{
|
||||
return getWorld().getSkylightSubtracted() < 4;
|
||||
}
|
||||
|
||||
/**
|
||||
* The current sun brightness factor for this dimension.
|
||||
* 0.0f means no light at all, and 1.0f means maximum sunlight.
|
||||
* This will be used for the "calculateSkylightSubtracted"
|
||||
* which is for Sky light value calculation.
|
||||
*
|
||||
* @return The current brightness factor
|
||||
**/
|
||||
default float getSunBrightness(float partialTicks)
|
||||
{
|
||||
return getWorld().getSunBrightnessBody(partialTicks);
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
default Vec3d getSkyColor(BlockPos cameraPos, float partialTicks)
|
||||
{
|
||||
return getWorld().getSkyColorBody(cameraPos, partialTicks);
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
default Vec3d getCloudColor(float partialTicks)
|
||||
{
|
||||
return getWorld().getCloudColorBody(partialTicks);
|
||||
return getDimension().getType() == DimensionType.OVERWORLD && getWorld().getSkylightSubtracted() < 4;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -204,15 +176,6 @@ public interface IForgeDimension
|
||||
return Dimension.MOON_PHASE_FACTORS[this.getDimension().getMoonPhase(time)];
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Star Brightness for rendering sky.
|
||||
* */
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
default float getStarBrightness(float partialTicks)
|
||||
{
|
||||
return getWorld().getStarBrightnessBody(partialTicks);
|
||||
}
|
||||
|
||||
default void setAllowedSpawnTypes(boolean allowHostile, boolean allowPeaceful) { }
|
||||
|
||||
default void calculateInitialWeather()
|
||||
@@ -258,7 +221,7 @@ public interface IForgeDimension
|
||||
|
||||
default boolean isHighHumidity(BlockPos pos)
|
||||
{
|
||||
return getWorld().getBiome(pos).isHighHumidity();
|
||||
return getWorld().func_226691_t_(pos).isHighHumidity();
|
||||
}
|
||||
|
||||
default int getHeight()
|
||||
@@ -271,11 +234,6 @@ public interface IForgeDimension
|
||||
return getDimension().isNether() ? 128 : 256;
|
||||
}
|
||||
|
||||
default double getHorizon()
|
||||
{
|
||||
return getWorld().getWorldInfo().getGenerator().getHorizon(getWorld());
|
||||
}
|
||||
|
||||
default int getSeaLevel()
|
||||
{
|
||||
return 63;
|
||||
|
||||
@@ -21,11 +21,15 @@ package net.minecraftforge.common.extensions;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.client.gui.AbstractGui;
|
||||
import net.minecraft.client.gui.DisplayEffectsScreen;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.nbt.ListNBT;
|
||||
import net.minecraft.potion.EffectInstance;
|
||||
import net.minecraft.potion.Potion;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
public interface IForgeEffectInstance {
|
||||
|
||||
@@ -33,6 +37,59 @@ public interface IForgeEffectInstance {
|
||||
return (EffectInstance)this;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the Potion effect should be displayed in the players inventory
|
||||
* @return true to display it (default), false to hide it.
|
||||
*/
|
||||
default boolean shouldRender() {
|
||||
return getEffectInstance().getPotion().shouldRender(getEffectInstance());
|
||||
}
|
||||
|
||||
/**
|
||||
* If the standard PotionEffect text (name and duration) should be drawn when this potion is active.
|
||||
* @return true to draw the standard text
|
||||
*/
|
||||
default boolean shouldRenderInvText() {
|
||||
return getEffectInstance().getPotion().shouldRenderInvText(getEffectInstance());
|
||||
}
|
||||
|
||||
/**
|
||||
* If the Potion effect should be displayed in the player's ingame HUD
|
||||
* @return true to display it (default), false to hide it.
|
||||
*/
|
||||
default boolean shouldRenderHUD() {
|
||||
return getEffectInstance().getPotion().shouldRenderHUD(getEffectInstance());
|
||||
}
|
||||
|
||||
/**
|
||||
* Called to draw the this Potion onto the player's inventory when it's active.
|
||||
* This can be used to e.g. render Potion icons from your own texture.
|
||||
*
|
||||
* @param gui the gui instance
|
||||
* @param x the x coordinate
|
||||
* @param y the y coordinate
|
||||
* @param z the z level
|
||||
*/
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
default void renderInventoryEffect(DisplayEffectsScreen<?> gui, int x, int y, float z) {
|
||||
getEffectInstance().getPotion().renderInventoryEffect(getEffectInstance(), gui, x, y, z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called to draw the this Potion onto the player's ingame HUD when it's active.
|
||||
* This can be used to e.g. render Potion icons from your own texture.
|
||||
*
|
||||
* @param gui the gui instance
|
||||
* @param x the x coordinate
|
||||
* @param y the y coordinate
|
||||
* @param z the z level
|
||||
* @param alpha the alpha value, blinks when the potion is about to run out
|
||||
*/
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
default void renderHUDEffect(AbstractGui gui, int x, int y, float z, float alpha) {
|
||||
getEffectInstance().getPotion().renderHUDEffect(getEffectInstance(), gui, x, y, z, alpha);
|
||||
}
|
||||
|
||||
/***
|
||||
* Returns a list of curative items for the potion effect
|
||||
* By default, this list is initialized using {@link Potion#getCurativeItems}
|
||||
|
||||
@@ -19,14 +19,12 @@
|
||||
|
||||
package net.minecraftforge.common.extensions;
|
||||
|
||||
import net.minecraft.entity.MoverType;
|
||||
import net.minecraft.entity.item.minecart.AbstractMinecartEntity;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tags.BlockTags;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraftforge.common.IMinecartCollisionHandler;
|
||||
|
||||
public interface IForgeEntityMinecart
|
||||
@@ -54,9 +52,9 @@ public interface IForgeEntityMinecart
|
||||
*/
|
||||
default BlockPos getCurrentRailPosition()
|
||||
{
|
||||
int x = MathHelper.floor(getMinecart().posX);
|
||||
int y = MathHelper.floor(getMinecart().posY);
|
||||
int z = MathHelper.floor(getMinecart().posZ);
|
||||
int x = MathHelper.floor(getMinecart().func_226277_ct_());
|
||||
int y = MathHelper.floor(getMinecart().func_226278_cu_());
|
||||
int z = MathHelper.floor(getMinecart().func_226281_cx_());
|
||||
BlockPos pos = new BlockPos(x, y - 1, z);
|
||||
if (getMinecart().world.getBlockState(pos).isIn(BlockTags.RAILS)) pos = pos.down();
|
||||
return pos;
|
||||
|
||||
@@ -27,10 +27,8 @@ import net.minecraft.block.material.Material;
|
||||
import net.minecraft.client.renderer.model.IBakedModel;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.fluid.Fluid;
|
||||
import net.minecraft.fluid.Fluids;
|
||||
import net.minecraft.fluid.IFluidState;
|
||||
import net.minecraft.tags.Tag;
|
||||
import net.minecraft.util.BlockRenderLayer;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
@@ -109,10 +107,11 @@ public interface IForgeFluid
|
||||
* Queries if this fluid should render in a given layer.
|
||||
* A custom {@link IBakedModel} can use {@link net.minecraftforge.client.MinecraftForgeClient#getRenderLayer()} to alter the model based on layer.
|
||||
*/
|
||||
/* TODO: reimplement
|
||||
default boolean canRenderInLayer(IFluidState state, BlockRenderLayer layer)
|
||||
{
|
||||
return this.getFluid().getRenderLayer() == layer;
|
||||
}
|
||||
}*/
|
||||
|
||||
/**
|
||||
* Retrieves a list of tags names this is known to be associated with.
|
||||
|
||||
@@ -26,7 +26,6 @@ import net.minecraft.entity.Entity;
|
||||
import net.minecraft.fluid.Fluid;
|
||||
import net.minecraft.fluid.IFluidState;
|
||||
import net.minecraft.tags.Tag;
|
||||
import net.minecraft.util.BlockRenderLayer;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.Explosion;
|
||||
import net.minecraft.world.IWorldReader;
|
||||
@@ -75,8 +74,9 @@ public interface IForgeFluidState
|
||||
* Queries if this fluidstate should render in a given layer.
|
||||
* A custom {@link IBakedModel} can use {@link net.minecraftforge.client.MinecraftForgeClient#getRenderLayer()} to alter the model based on layer.
|
||||
*/
|
||||
/* TODO: reimplement
|
||||
default boolean canRenderInLayer(BlockRenderLayer layer)
|
||||
{
|
||||
return getFluidState().getFluid().canRenderInLayer(getFluidState(), layer);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
@@ -660,7 +660,7 @@ public interface IForgeItem
|
||||
*/
|
||||
default boolean canContinueUsing(ItemStack oldStack, ItemStack newStack)
|
||||
{
|
||||
return oldStack.equals(newStack);
|
||||
return ItemStack.areItemsEqualIgnoreDurability(oldStack, newStack);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -350,6 +350,19 @@ public interface IForgeItemStack extends ICapabilitySerializable<CompoundNBT>
|
||||
return getStack().getItem().onDroppedByPlayer(getStack(), player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Allow the item one last chance to modify its name used for the tool highlight
|
||||
* useful for adding something extra that can't be removed by a user in the
|
||||
* displayed name, such as a mode of operation.
|
||||
*
|
||||
* @param displayName the name that will be displayed unless it is changed in
|
||||
* this method.
|
||||
*/
|
||||
default String getHighlightTip(String displayName)
|
||||
{
|
||||
return getStack().getItem().getHighlightTip(getStack(), displayName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the NBT data to be sent to the client. The Item can control what data is kept in the tag.
|
||||
*
|
||||
|
||||
@@ -119,7 +119,7 @@ public interface IForgeWorldType
|
||||
default <T extends IArea, C extends IExtendedNoiseRandom<T>> IAreaFactory<T> getBiomeLayer(IAreaFactory<T> parentLayer,
|
||||
OverworldGenSettings chunkSettings, LongFunction<C> contextFactory)
|
||||
{
|
||||
parentLayer = (new BiomeLayer(getWorldType(), chunkSettings)).apply(contextFactory.apply(200L), parentLayer);
|
||||
parentLayer = (new BiomeLayer(getWorldType(), chunkSettings.getBiomeId())).apply(contextFactory.apply(200L), parentLayer);
|
||||
parentLayer = AddBambooForestLayer.INSTANCE.apply(contextFactory.apply(1001L), parentLayer);
|
||||
parentLayer = LayerUtil.repeat(1000L, ZoomLayer.NORMAL, parentLayer, 2, contextFactory);
|
||||
parentLayer = EdgeBiomeLayer.INSTANCE.apply(contextFactory.apply(1000L), parentLayer);
|
||||
|
||||
@@ -21,7 +21,7 @@ package net.minecraftforge.common.model;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
final class HiddenModelPart implements IModelPart
|
||||
final class HiddenModelPart
|
||||
{
|
||||
private final ImmutableList<String> path;
|
||||
|
||||
|
||||
@@ -28,12 +28,12 @@ public enum Models
|
||||
{
|
||||
;
|
||||
|
||||
public static IModelPart getHiddenModelPart(ImmutableList<String> path)
|
||||
public static Object getHiddenModelPart(ImmutableList<String> path)
|
||||
{
|
||||
return new HiddenModelPart(path);
|
||||
}
|
||||
|
||||
public static UnmodifiableIterator<String> getParts(IModelPart part)
|
||||
public static UnmodifiableIterator<String> getParts(Object part)
|
||||
{
|
||||
if(part instanceof HiddenModelPart)
|
||||
{
|
||||
|
||||
@@ -1,865 +0,0 @@
|
||||
/*
|
||||
* Minecraft Forge
|
||||
* Copyright (c) 2016-2019.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation version 2.1
|
||||
* of the License.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package net.minecraftforge.common.model;
|
||||
|
||||
import java.util.EnumMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.vecmath.AxisAngle4f;
|
||||
import javax.vecmath.Matrix3f;
|
||||
import javax.vecmath.Matrix4f;
|
||||
import javax.vecmath.Quat4f;
|
||||
import javax.vecmath.SingularMatrixException;
|
||||
import javax.vecmath.Tuple3f;
|
||||
import javax.vecmath.Tuple4f;
|
||||
import javax.vecmath.Vector3f;
|
||||
import javax.vecmath.Vector4f;
|
||||
|
||||
import net.minecraft.client.renderer.model.ItemTransformVec3f;
|
||||
import net.minecraft.client.renderer.model.ModelRotation;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.math.Vec3i;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.minecraftforge.client.ForgeHooksClient;
|
||||
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.apache.commons.lang3.tuple.Triple;
|
||||
|
||||
import com.google.common.base.MoreObjects;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
/*
|
||||
* Interpolation-friendly affine transformation.
|
||||
* If created with matrix, should successfully decompose it to a composition
|
||||
* of easily interpolatable transformations (translation, first rotation, scale
|
||||
* (with generally speaking different factors for each axis) and second rotation.
|
||||
* If the input matrix is a composition of translation, rotation and scale (in
|
||||
* any order), then the interpolation of the derived primitive transformations
|
||||
* should result in the same transformation as the interpolation of the originals.
|
||||
* Decomposition happens lazily (and is hopefully fast enough), so performance
|
||||
* should be comparable to using Matrix4f directly.
|
||||
* Immutable.
|
||||
*/
|
||||
public final class TRSRTransformation implements IModelState, ITransformation
|
||||
{
|
||||
private final Matrix4f matrix;
|
||||
|
||||
private boolean full;
|
||||
private Vector3f translation;
|
||||
private Quat4f leftRot;
|
||||
private Vector3f scale;
|
||||
private Quat4f rightRot;
|
||||
|
||||
private Matrix3f normalTransform;
|
||||
|
||||
public TRSRTransformation(@Nullable Matrix4f matrix)
|
||||
{
|
||||
if(matrix == null)
|
||||
{
|
||||
this.matrix = identity.matrix;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.matrix = matrix;
|
||||
}
|
||||
}
|
||||
|
||||
public TRSRTransformation(@Nullable Vector3f translation, @Nullable Quat4f leftRot, @Nullable Vector3f scale, @Nullable Quat4f rightRot)
|
||||
{
|
||||
this.matrix = mul(translation, leftRot, scale, rightRot);
|
||||
this.translation = translation != null ? translation : new Vector3f();
|
||||
this.leftRot = leftRot != null ? leftRot : new Quat4f(0, 0, 0, 1);
|
||||
this.scale = scale != null ? scale : new Vector3f(1, 1, 1);
|
||||
this.rightRot = rightRot!= null ? rightRot : new Quat4f(0, 0, 0, 1);
|
||||
full = true;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public static TRSRTransformation from(ItemTransformVec3f transform)
|
||||
{
|
||||
return transform.equals(ItemTransformVec3f.DEFAULT) ? identity : new TRSRTransformation(toVecmath(transform.translation), quatFromXYZDegrees(toVecmath(transform.rotation)), toVecmath(transform.scale), null);
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public static TRSRTransformation from(ModelRotation rotation)
|
||||
{
|
||||
return Cache.get(rotation);
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public static TRSRTransformation from(Direction facing)
|
||||
{
|
||||
return Cache.get(getRotation(facing));
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public static Matrix4f getMatrix(Direction facing)
|
||||
{
|
||||
return getRotation(facing).getMatrixVec();
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public static ModelRotation getRotation(Direction facing)
|
||||
{
|
||||
switch (facing)
|
||||
{
|
||||
case DOWN: return ModelRotation.X90_Y0;
|
||||
case UP: return ModelRotation.X270_Y0;
|
||||
case NORTH: return ModelRotation.X0_Y0;
|
||||
case SOUTH: return ModelRotation.X0_Y180;
|
||||
case WEST: return ModelRotation.X0_Y270;
|
||||
case EAST: return ModelRotation.X0_Y90;
|
||||
}
|
||||
throw new IllegalArgumentException(String.valueOf(facing));
|
||||
}
|
||||
|
||||
private static final TRSRTransformation identity;
|
||||
|
||||
static
|
||||
{
|
||||
Matrix4f m = new Matrix4f();
|
||||
m.setIdentity();
|
||||
identity = new TRSRTransformation(m);
|
||||
identity.getLeftRot();
|
||||
}
|
||||
|
||||
public static TRSRTransformation identity()
|
||||
{
|
||||
return identity;
|
||||
}
|
||||
|
||||
public TRSRTransformation compose(TRSRTransformation b)
|
||||
{
|
||||
if (this.isIdentity()) return b;
|
||||
if (b.isIdentity()) return this;
|
||||
Matrix4f m = getMatrixVec();
|
||||
m.mul(b.getMatrixVec());
|
||||
return new TRSRTransformation(m);
|
||||
}
|
||||
|
||||
public TRSRTransformation inverse()
|
||||
{
|
||||
if (this.isIdentity()) return this;
|
||||
Matrix4f m = getMatrixVec();
|
||||
m.invert();
|
||||
return new TRSRTransformation(m);
|
||||
}
|
||||
|
||||
private void genCheck()
|
||||
{
|
||||
if(!full)
|
||||
{
|
||||
Pair<Matrix3f, Vector3f> pair = toAffine(matrix);
|
||||
Triple<Quat4f, Vector3f, Quat4f> triple = svdDecompose(pair.getLeft());
|
||||
this.translation = pair.getRight();
|
||||
this.leftRot = triple.getLeft();
|
||||
this.scale = triple.getMiddle();
|
||||
this.rightRot = triple.getRight();
|
||||
full = true;
|
||||
}
|
||||
}
|
||||
|
||||
public static Quat4f quatFromYXZ(float y, float x, float z)
|
||||
{
|
||||
Quat4f ret = new Quat4f(0, 0, 0, 1), t = new Quat4f();
|
||||
t.set(0, (float)Math.sin(y/2), 0, (float)Math.cos(y/2));
|
||||
ret.mul(t);
|
||||
t.set((float)Math.sin(x/2), 0, 0, (float)Math.cos(x/2));
|
||||
ret.mul(t);
|
||||
t.set(0, 0, (float)Math.sin(z/2), (float)Math.cos(z/2));
|
||||
ret.mul(t);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static Quat4f quatFromXYZDegrees(Vector3f xyz)
|
||||
{
|
||||
return quatFromXYZ((float)Math.toRadians(xyz.x), (float)Math.toRadians(xyz.y), (float)Math.toRadians(xyz.z));
|
||||
}
|
||||
|
||||
public static Quat4f quatFromXYZ(Vector3f xyz)
|
||||
{
|
||||
return quatFromXYZ(xyz.x, xyz.y, xyz.z);
|
||||
}
|
||||
|
||||
public static Quat4f quatFromXYZ(float x, float y, float z)
|
||||
{
|
||||
Quat4f ret = new Quat4f(0, 0, 0, 1), t = new Quat4f();
|
||||
t.set((float)Math.sin(x/2), 0, 0, (float)Math.cos(x/2));
|
||||
ret.mul(t);
|
||||
t.set(0, (float)Math.sin(y/2), 0, (float)Math.cos(y/2));
|
||||
ret.mul(t);
|
||||
t.set(0, 0, (float)Math.sin(z/2), (float)Math.cos(z/2));
|
||||
ret.mul(t);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static Vector3f toYXZDegrees(Quat4f q)
|
||||
{
|
||||
Vector3f yxz = toYXZ(q);
|
||||
return new Vector3f((float)Math.toDegrees(yxz.x), (float)Math.toDegrees(yxz.y), (float)Math.toDegrees(yxz.z));
|
||||
}
|
||||
|
||||
public static Vector3f toYXZ(Quat4f q)
|
||||
{
|
||||
float w2 = q.w * q.w;
|
||||
float x2 = q.x * q.x;
|
||||
float y2 = q.y * q.y;
|
||||
float z2 = q.z * q.z;
|
||||
float l = w2 + x2 + y2 + z2;
|
||||
float sx = 2 * q.w * q.x - 2 * q.y * q.z;
|
||||
float x = (float)Math.asin(sx / l);
|
||||
if(Math.abs(sx) > .999f * l)
|
||||
{
|
||||
return new Vector3f(
|
||||
x,
|
||||
2 * (float)Math.atan2(q.y, q.w),
|
||||
0
|
||||
);
|
||||
}
|
||||
return new Vector3f(
|
||||
x,
|
||||
(float)Math.atan2(2 * q.x * q.z + 2 * q.y * q.w, w2 - x2 - y2 + z2),
|
||||
(float)Math.atan2(2 * q.x * q.y + 2 * q.w * q.z, w2 - x2 + y2 - z2)
|
||||
);
|
||||
}
|
||||
|
||||
public static Vector3f toXYZDegrees(Quat4f q)
|
||||
{
|
||||
Vector3f xyz = toXYZ(q);
|
||||
return new Vector3f((float)Math.toDegrees(xyz.x), (float)Math.toDegrees(xyz.y), (float)Math.toDegrees(xyz.z));
|
||||
}
|
||||
|
||||
public static Vector3f toXYZ(Quat4f q)
|
||||
{
|
||||
float w2 = q.w * q.w;
|
||||
float x2 = q.x * q.x;
|
||||
float y2 = q.y * q.y;
|
||||
float z2 = q.z * q.z;
|
||||
float l = w2 + x2 + y2 + z2;
|
||||
float sy = 2 * q.w * q.x - 2 * q.y * q.z;
|
||||
float y = (float)Math.asin(sy / l);
|
||||
if(Math.abs(sy) > .999f * l)
|
||||
{
|
||||
return new Vector3f(
|
||||
2 * (float)Math.atan2(q.x, q.w),
|
||||
y,
|
||||
0
|
||||
);
|
||||
}
|
||||
return new Vector3f(
|
||||
(float)Math.atan2(2 * q.y * q.z + 2 * q.x * q.w, w2 - x2 - y2 + z2),
|
||||
y,
|
||||
(float)Math.atan2(2 * q.x * q.y + 2 * q.w * q.z, w2 + x2 - y2 - z2)
|
||||
);
|
||||
}
|
||||
|
||||
public static Matrix4f mul(@Nullable Vector3f translation, @Nullable Quat4f leftRot, @Nullable Vector3f scale, @Nullable Quat4f rightRot)
|
||||
{
|
||||
Matrix4f res = new Matrix4f(), t = new Matrix4f();
|
||||
res.setIdentity();
|
||||
if(leftRot != null)
|
||||
{
|
||||
t.set(leftRot);
|
||||
res.mul(t);
|
||||
}
|
||||
if(scale != null)
|
||||
{
|
||||
t.setIdentity();
|
||||
t.m00 = scale.x;
|
||||
t.m11 = scale.y;
|
||||
t.m22 = scale.z;
|
||||
res.mul(t);
|
||||
}
|
||||
if(rightRot != null)
|
||||
{
|
||||
t.set(rightRot);
|
||||
res.mul(t);
|
||||
}
|
||||
if(translation != null) res.setTranslation(translation);
|
||||
return res;
|
||||
}
|
||||
|
||||
/*
|
||||
* Performs SVD decomposition of m, accumulating reflection in the scale (U and V are pure rotations).
|
||||
*/
|
||||
public static Triple<Quat4f, Vector3f, Quat4f> svdDecompose(Matrix3f m)
|
||||
{
|
||||
// determine V by doing 5 steps of Jacobi iteration on MT * M
|
||||
Quat4f u = new Quat4f(0, 0, 0, 1), v = new Quat4f(0, 0, 0, 1), qt = new Quat4f();
|
||||
Matrix3f b = new Matrix3f(m), t = new Matrix3f();
|
||||
t.transpose(m);
|
||||
b.mul(t, b);
|
||||
|
||||
for(int i = 0; i < 5; i++) v.mul(stepJacobi(b));
|
||||
|
||||
v.normalize();
|
||||
t.set(v);
|
||||
b.set(m);
|
||||
b.mul(t);
|
||||
|
||||
// FIXME: this doesn't work correctly for some reason; not crucial, so disabling for now; investigate in the future.
|
||||
//sortSingularValues(b, v);
|
||||
|
||||
Pair<Float, Float> p;
|
||||
|
||||
float ul = 1f;
|
||||
|
||||
p = qrGivensQuat(b.m00, b.m10);
|
||||
qt.set(0, 0, p.getLeft(), p.getRight());
|
||||
u.mul(qt);
|
||||
t.setIdentity();
|
||||
t.m00 = qt.w * qt.w - qt.z * qt.z;
|
||||
t.m11 = t.m00;
|
||||
t.m10 = -2 * qt.z * qt.w;
|
||||
t.m01 = -t.m10;
|
||||
t.m22 = qt.w * qt.w + qt.z * qt.z;
|
||||
ul *= t.m22;
|
||||
b.mul(t, b);
|
||||
|
||||
p = qrGivensQuat(b.m00, b.m20);
|
||||
qt.set(0, -p.getLeft(), 0, p.getRight());
|
||||
u.mul(qt);
|
||||
t.setIdentity();
|
||||
t.m00 = qt.w * qt.w - qt.y * qt.y;
|
||||
t.m22 = t.m00;
|
||||
t.m20 = 2 * qt.y * qt.w;
|
||||
t.m02 = -t.m20;
|
||||
t.m11 = qt.w * qt.w + qt.y * qt.y;
|
||||
ul *= t.m11;
|
||||
b.mul(t, b);
|
||||
|
||||
p = qrGivensQuat(b.m11, b.m21);
|
||||
qt.set(p.getLeft(), 0, 0, p.getRight());
|
||||
u.mul(qt);
|
||||
t.setIdentity();
|
||||
t.m11 = qt.w * qt.w - qt.x * qt.x;
|
||||
t.m22 = t.m11;
|
||||
t.m21 = -2 * qt.x * qt.w;
|
||||
t.m12 = -t.m21;
|
||||
t.m00 = qt.w * qt.w + qt.x * qt.x;
|
||||
ul *= t.m00;
|
||||
b.mul(t, b);
|
||||
|
||||
ul = 1f / ul;
|
||||
u.scale((float)Math.sqrt(ul));
|
||||
|
||||
Vector3f s = new Vector3f(b.m00 * ul, b.m11 * ul, b.m22 * ul);
|
||||
|
||||
return Triple.of(u, s, v);
|
||||
}
|
||||
|
||||
private static float rsqrt(float f)
|
||||
{
|
||||
float f2 = .5f * f;
|
||||
int i = Float.floatToIntBits(f);
|
||||
i = 0x5f3759df - (i >> 1);
|
||||
f = Float.intBitsToFloat(i);
|
||||
f *= 1.5f - f2 * f * f;
|
||||
return f;
|
||||
}
|
||||
|
||||
private static final float eps = 1e-6f;
|
||||
private static final float g = 3f + 2f * (float)Math.sqrt(2);
|
||||
private static final float cs = (float)Math.cos(Math.PI / 8);
|
||||
private static final float ss = (float)Math.sin(Math.PI / 8);
|
||||
private static final float sq2 = 1f / (float)Math.sqrt(2);
|
||||
|
||||
private static Pair<Float, Float> approxGivensQuat(float a11, float a12, float a22)
|
||||
{
|
||||
float ch = 2f * (a11 - a22);
|
||||
float sh = a12;
|
||||
boolean b = g * sh * sh < ch * ch;
|
||||
float w = rsqrt(sh * sh + ch * ch);
|
||||
ch = b ? w * ch : cs;
|
||||
sh = b ? w * sh : ss;
|
||||
return Pair.of(sh, ch);
|
||||
}
|
||||
|
||||
private static final void swapNeg(Matrix3f m, int i, int j)
|
||||
{
|
||||
float[] t = new float[3];
|
||||
m.getColumn(j, t);
|
||||
for(int k = 0; k < 3; k++)
|
||||
{
|
||||
m.setElement(k, j, -m.getElement(k, i));
|
||||
}
|
||||
m.setColumn(i, t);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private static void sortSingularValues(Matrix3f b, Quat4f v)
|
||||
{
|
||||
float p0 = b.m00 * b.m00 + b.m10 * b.m10 + b.m20 * b.m20;
|
||||
float p1 = b.m01 * b.m01 + b.m11 * b.m11 + b.m21 * b.m21;
|
||||
float p2 = b.m02 * b.m02 + b.m12 * b.m12 + b.m22 * b.m22;
|
||||
Quat4f t = new Quat4f();
|
||||
if(p0 < p1)
|
||||
{
|
||||
swapNeg(b, 0, 1);
|
||||
t.set(0, 0, sq2, sq2);
|
||||
v.mul(t);
|
||||
float f = p0;
|
||||
p0 = p1;
|
||||
p1 = f;
|
||||
}
|
||||
if(p0 < p2)
|
||||
{
|
||||
swapNeg(b, 0, 2);
|
||||
t.set(0, sq2, 0, sq2);
|
||||
v.mul(t);
|
||||
float f = p0;
|
||||
p0 = p2;
|
||||
p2 = f;
|
||||
}
|
||||
if(p1 < p2)
|
||||
{
|
||||
swapNeg(b, 1, 2);
|
||||
t.set(sq2, 0, 0, sq2);
|
||||
v.mul(t);
|
||||
}
|
||||
}
|
||||
|
||||
private static Pair<Float, Float> qrGivensQuat(float a1, float a2)
|
||||
{
|
||||
float p = (float)Math.sqrt(a1 * a1 + a2 * a2);
|
||||
float sh = p > eps ? a2 : 0;
|
||||
float ch = Math.abs(a1) + Math.max(p, eps);
|
||||
if(a1 < 0)
|
||||
{
|
||||
float f = sh;
|
||||
sh = ch;
|
||||
ch = f;
|
||||
}
|
||||
//float w = 1.f / (float)Math.sqrt(ch * ch + sh * sh);
|
||||
float w = rsqrt(ch * ch + sh * sh);
|
||||
ch *= w;
|
||||
sh *= w;
|
||||
return Pair.of(sh, ch);
|
||||
}
|
||||
|
||||
private static Quat4f stepJacobi(Matrix3f m)
|
||||
{
|
||||
Matrix3f t = new Matrix3f();
|
||||
Quat4f qt = new Quat4f(), ret = new Quat4f(0, 0, 0, 1);
|
||||
Pair<Float, Float> p;
|
||||
// 01
|
||||
if(m.m01 * m.m01 + m.m10 * m.m10 > eps)
|
||||
{
|
||||
p = approxGivensQuat(m.m00, .5f * (m.m01 + m.m10), m.m11);
|
||||
qt.set(0, 0, p.getLeft(), p.getRight());
|
||||
//qt.normalize();
|
||||
ret.mul(qt);
|
||||
//t.set(qt);
|
||||
t.setIdentity();
|
||||
t.m00 = qt.w * qt.w - qt.z * qt.z;
|
||||
t.m11 = t.m00;
|
||||
t.m10 = 2 * qt.z * qt.w;
|
||||
t.m01 = -t.m10;
|
||||
t.m22 = qt.w * qt.w + qt.z * qt.z;
|
||||
m.mul(m, t);
|
||||
t.transpose();
|
||||
m.mul(t, m);
|
||||
}
|
||||
// 02
|
||||
if(m.m02 * m.m02 + m.m20 * m.m20 > eps)
|
||||
{
|
||||
p = approxGivensQuat(m.m00, .5f * (m.m02 + m.m20), m.m22);
|
||||
qt.set(0, -p.getLeft(), 0, p.getRight());
|
||||
//qt.normalize();
|
||||
ret.mul(qt);
|
||||
//t.set(qt);
|
||||
t.setIdentity();
|
||||
t.m00 = qt.w * qt.w - qt.y * qt.y;
|
||||
t.m22 = t.m00;
|
||||
t.m20 = -2 * qt.y * qt.w;
|
||||
t.m02 = -t.m20;
|
||||
t.m11 = qt.w * qt.w + qt.y * qt.y;
|
||||
m.mul(m, t);
|
||||
t.transpose();
|
||||
m.mul(t, m);
|
||||
}
|
||||
// 12
|
||||
if(m.m12 * m.m12 + m.m21 * m.m21 > eps)
|
||||
{
|
||||
p = approxGivensQuat(m.m11, .5f * (m.m12 + m.m21), m.m22);
|
||||
qt.set(p.getLeft(), 0, 0, p.getRight());
|
||||
//qt.normalize();
|
||||
ret.mul(qt);
|
||||
//t.set(qt);
|
||||
t.setIdentity();
|
||||
t.m11 = qt.w * qt.w - qt.x * qt.x;
|
||||
t.m22 = t.m11;
|
||||
t.m21 = 2 * qt.x * qt.w;
|
||||
t.m12 = -t.m21;
|
||||
t.m00 = qt.w * qt.w + qt.x * qt.x;
|
||||
m.mul(m, t);
|
||||
t.transpose();
|
||||
m.mul(t, m);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* Divides m by m33, sets last row to (0, 0, 0, 1), extracts linear and translation parts
|
||||
*/
|
||||
public static Pair<Matrix3f, Vector3f> toAffine(Matrix4f m)
|
||||
{
|
||||
m.mul(1.f / m.m33);
|
||||
Vector3f trans = new Vector3f(m.m03, m.m13, m.m23);
|
||||
Matrix3f linear = new Matrix3f(m.m00, m.m01, m.m02, m.m10, m.m11, m.m12, m.m20, m.m21, m.m22);
|
||||
return Pair.of(linear, trans);
|
||||
}
|
||||
|
||||
/*
|
||||
* Don't use this if you don't need to, conversion is lossy (second rotation component is lost).
|
||||
*/
|
||||
@Deprecated
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public net.minecraft.client.renderer.model.ItemTransformVec3f toItemTransform()
|
||||
{
|
||||
return new ItemTransformVec3f(toMojang(toXYZDegrees(getLeftRot())), toMojang(getTranslation()), toMojang(getScale()));
|
||||
}
|
||||
|
||||
public boolean isIdentity()
|
||||
{
|
||||
return this.equals(identity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Matrix4f getMatrixVec()
|
||||
{
|
||||
return (Matrix4f)matrix.clone();
|
||||
}
|
||||
|
||||
public Vector3f getTranslation()
|
||||
{
|
||||
genCheck();
|
||||
return (Vector3f)translation.clone();
|
||||
}
|
||||
|
||||
public Quat4f getLeftRot()
|
||||
{
|
||||
genCheck();
|
||||
return (Quat4f)leftRot.clone();
|
||||
}
|
||||
|
||||
public Vector3f getScale()
|
||||
{
|
||||
genCheck();
|
||||
return (Vector3f)scale.clone();
|
||||
}
|
||||
|
||||
public Quat4f getRightRot()
|
||||
{
|
||||
genCheck();
|
||||
return (Quat4f)rightRot.clone();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<TRSRTransformation> apply(Optional<? extends IModelPart> part)
|
||||
{
|
||||
if(part.isPresent())
|
||||
{
|
||||
return Optional.empty();
|
||||
}
|
||||
return Optional.of(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Direction rotateTransform(Direction facing)
|
||||
{
|
||||
return rotate(matrix, facing);
|
||||
}
|
||||
|
||||
public static Direction rotate(Matrix4f matrix, Direction facing)
|
||||
{
|
||||
Vec3i dir = facing.getDirectionVec();
|
||||
Vector4f vec = new Vector4f(dir.getX(), dir.getY(), dir.getZ(), 0);
|
||||
matrix.transform(vec);
|
||||
return Direction.getFacingFromVector(vec.x, vec.y, vec.z);
|
||||
}
|
||||
|
||||
public static boolean isInteger(Matrix4f matrix)
|
||||
{
|
||||
Matrix4f m = new Matrix4f();
|
||||
m.setIdentity();
|
||||
m.m30 = m.m31 = m.m32 = 1;
|
||||
m.m33 = 0;
|
||||
m.mul(matrix, m);
|
||||
for(int i = 0; i < 3; i++)
|
||||
{
|
||||
for(int j = 0; j < 3; j++)
|
||||
{
|
||||
float v = m.getElement(i, j) / m.getElement(3, j);
|
||||
if(Math.abs(v - Math.round(v)) > 1e-5) return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int rotate(Direction facing, int vertexIndex)
|
||||
{
|
||||
// FIXME check if this is good enough
|
||||
return vertexIndex;
|
||||
}
|
||||
|
||||
public void transformPosition(Vector4f position)
|
||||
{
|
||||
matrix.transform(position);
|
||||
}
|
||||
|
||||
public void transformNormal(Vector3f normal)
|
||||
{
|
||||
checkNormalTransform();
|
||||
normalTransform.transform(normal);
|
||||
normal.normalize();
|
||||
}
|
||||
|
||||
private void checkNormalTransform()
|
||||
{
|
||||
if (normalTransform == null)
|
||||
{
|
||||
normalTransform = new Matrix3f();
|
||||
matrix.getRotationScale(normalTransform);
|
||||
normalTransform.invert();
|
||||
normalTransform.transpose();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
genCheck();
|
||||
return MoreObjects.toStringHelper(this.getClass())
|
||||
.add("matrix", matrix)
|
||||
.add("translation", translation)
|
||||
.add("leftRot", leftRot)
|
||||
.add("scale", scale)
|
||||
.add("rightRot", rightRot)
|
||||
.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* convert transformation from assuming center-block system to corner-block system
|
||||
*/
|
||||
public static TRSRTransformation blockCenterToCorner(TRSRTransformation transform)
|
||||
{
|
||||
if (transform.isIdentity()) return transform;
|
||||
|
||||
Matrix4f ret = new Matrix4f(transform.getMatrixVec()), tmp = new Matrix4f();
|
||||
tmp.setIdentity();
|
||||
tmp.m03 = tmp.m13 = tmp.m23 = .5f;
|
||||
ret.mul(tmp, ret);
|
||||
tmp.m03 = tmp.m13 = tmp.m23 = -.5f;
|
||||
ret.mul(tmp);
|
||||
return new TRSRTransformation(ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* convert transformation from assuming corner-block system to center-block system
|
||||
*/
|
||||
public static TRSRTransformation blockCornerToCenter(TRSRTransformation transform)
|
||||
{
|
||||
if (transform.isIdentity()) return transform;
|
||||
|
||||
Matrix4f ret = new Matrix4f(transform.getMatrixVec()), tmp = new Matrix4f();
|
||||
tmp.setIdentity();
|
||||
tmp.m03 = tmp.m13 = tmp.m23 = -.5f;
|
||||
ret.mul(tmp, ret);
|
||||
tmp.m03 = tmp.m13 = tmp.m23 = .5f;
|
||||
ret.mul(tmp);
|
||||
return new TRSRTransformation(ret);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + Objects.hashCode(matrix);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
if (this == obj) return true;
|
||||
if (obj == null) return false;
|
||||
if (getClass() != obj.getClass()) return false;
|
||||
TRSRTransformation other = (TRSRTransformation) obj;
|
||||
return Objects.equals(matrix, other.matrix);
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public static Vector3f toVecmath(net.minecraft.client.renderer.Vector3f vec)
|
||||
{
|
||||
return new Vector3f(vec.getX(), vec.getY(), vec.getZ());
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public static Vector4f toVecmath(net.minecraft.client.renderer.Vector4f vec)
|
||||
{
|
||||
return new Vector4f(vec.getX(), vec.getY(), vec.getZ(), vec.getW());
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public static Matrix4f toVecmath(net.minecraft.client.renderer.Matrix4f m)
|
||||
{
|
||||
return new Matrix4f(
|
||||
m.get(0, 0), m.get(1, 0), m.get(2, 0), m.get(3, 0),
|
||||
m.get(0, 1), m.get(1, 1), m.get(2, 1), m.get(3, 1),
|
||||
m.get(0, 2), m.get(1, 2), m.get(2, 2), m.get(3, 2),
|
||||
m.get(0, 3), m.get(1, 3), m.get(2, 3), m.get(3, 3));
|
||||
}
|
||||
|
||||
public static Quat4f toVecmath(net.minecraft.client.renderer.Quaternion q)
|
||||
{
|
||||
return new Quat4f(q.getX(), q.getY(), q.getZ(), q.getW());
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public static net.minecraft.client.renderer.Vector3f toMojang(Vector3f vec)
|
||||
{
|
||||
return new net.minecraft.client.renderer.Vector3f(vec.x, vec.y, vec.z);
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public static net.minecraft.client.renderer.Vector4f toMojang(Vector4f vec)
|
||||
{
|
||||
return new net.minecraft.client.renderer.Vector4f(vec.x, vec.y, vec.z, vec.w);
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public static net.minecraft.client.renderer.Matrix4f toMojang(Matrix4f m)
|
||||
{
|
||||
net.minecraft.client.renderer.Matrix4f r = new net.minecraft.client.renderer.Matrix4f();
|
||||
float[] row = new float[4];
|
||||
for (int x = 0; x < 4; x++)
|
||||
{
|
||||
m.getRow(x, row);
|
||||
for (int y = 0; y < 4; y++)
|
||||
{
|
||||
r.set(x, y, row[y]);
|
||||
}
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
public static Vector3f lerp(Tuple3f from, Tuple3f to, float progress)
|
||||
{
|
||||
Vector3f res = new Vector3f(from);
|
||||
res.interpolate(from, to, progress);
|
||||
return res;
|
||||
}
|
||||
|
||||
public static Vector4f lerp(Tuple4f from, Tuple4f to, float progress)
|
||||
{
|
||||
Vector4f res = new Vector4f(from);
|
||||
res.interpolate(from, to, progress);
|
||||
return res;
|
||||
}
|
||||
|
||||
public static Quat4f slerp(Quat4f from, Quat4f to, float progress)
|
||||
{
|
||||
Quat4f res = new Quat4f();
|
||||
res.interpolate(from, to, progress);
|
||||
return res;
|
||||
}
|
||||
|
||||
public TRSRTransformation slerp(TRSRTransformation that, float progress)
|
||||
{
|
||||
return new TRSRTransformation(
|
||||
lerp(this.getTranslation(), that.getTranslation(), progress),
|
||||
slerp(this.getLeftRot(), that.getLeftRot(), progress),
|
||||
lerp(this.getScale(), that.getScale(), progress),
|
||||
slerp(this.getRightRot(), that.getRightRot(), progress)
|
||||
);
|
||||
}
|
||||
|
||||
private static final EnumMap<Direction, TRSRTransformation> vanillaUvTransformLocalToGlobal = Maps.newEnumMap(Direction.class);
|
||||
private static final EnumMap<Direction, TRSRTransformation> vanillaUvTransformGlobalToLocal = Maps.newEnumMap(Direction.class);
|
||||
|
||||
static
|
||||
{
|
||||
vanillaUvTransformLocalToGlobal.put(Direction.SOUTH, identity);
|
||||
Quat4f tmp = new Quat4f();
|
||||
tmp.set(new AxisAngle4f(0, 1, 0, (float)Math.toRadians(90)));
|
||||
vanillaUvTransformLocalToGlobal.put(Direction.EAST, new TRSRTransformation(null, new Quat4f(tmp), null, null));
|
||||
tmp.set(new AxisAngle4f(0, 1, 0, (float)Math.toRadians(-90)));
|
||||
vanillaUvTransformLocalToGlobal.put(Direction.WEST, new TRSRTransformation(null, new Quat4f(tmp), null, null));
|
||||
tmp.set(new AxisAngle4f(0, 1, 0, (float)Math.toRadians(180)));
|
||||
vanillaUvTransformLocalToGlobal.put(Direction.NORTH, new TRSRTransformation(null, new Quat4f(tmp), null, null));
|
||||
tmp.set(new AxisAngle4f(1, 0, 0, (float)Math.toRadians(-90)));
|
||||
vanillaUvTransformLocalToGlobal.put(Direction.UP, new TRSRTransformation(null, new Quat4f(tmp), null, null));
|
||||
tmp.set(new AxisAngle4f(1, 0, 0, (float)Math.toRadians(90)));
|
||||
vanillaUvTransformLocalToGlobal.put(Direction.DOWN, new TRSRTransformation(null, new Quat4f(tmp), null, null));
|
||||
|
||||
for(Direction side : Direction.values())
|
||||
{
|
||||
vanillaUvTransformGlobalToLocal.put(side, vanillaUvTransformLocalToGlobal.get(side).inverse());
|
||||
}
|
||||
}
|
||||
|
||||
public static TRSRTransformation getVanillaUvTransformLocalToGlobal(Direction side)
|
||||
{
|
||||
return vanillaUvTransformLocalToGlobal.get(side);
|
||||
}
|
||||
|
||||
public static TRSRTransformation getVanillaUvTransformGlobalToLocal(Direction side)
|
||||
{
|
||||
return vanillaUvTransformGlobalToLocal.get(side);
|
||||
}
|
||||
|
||||
public TRSRTransformation getUVLockTransform(Direction originalSide)
|
||||
{
|
||||
Direction newSide = rotateTransform(originalSide);
|
||||
try
|
||||
{
|
||||
return blockCenterToCorner(vanillaUvTransformGlobalToLocal.get(originalSide).compose(blockCornerToCenter(this.inverse())).compose(vanillaUvTransformLocalToGlobal.get(newSide)));
|
||||
}
|
||||
catch(SingularMatrixException e)
|
||||
{
|
||||
return new TRSRTransformation(null, null, new Vector3f(0, 0, 0), null);
|
||||
}
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
private static final class Cache
|
||||
{
|
||||
private static final Map<ModelRotation, TRSRTransformation> rotations = new EnumMap<>(ModelRotation.class);
|
||||
|
||||
static
|
||||
{
|
||||
rotations.put(ModelRotation.X0_Y0, identity());
|
||||
}
|
||||
|
||||
static TRSRTransformation get(ModelRotation rotation)
|
||||
{
|
||||
return rotations.computeIfAbsent(rotation, r -> new TRSRTransformation(ForgeHooksClient.getMatrix(r)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,436 @@
|
||||
/*
|
||||
* Minecraft Forge
|
||||
* Copyright (c) 2016-2019.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation version 2.1
|
||||
* of the License.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package net.minecraftforge.common.model;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.EnumMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.google.gson.*;
|
||||
import net.minecraft.client.renderer.*;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.apache.commons.lang3.tuple.Triple;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import net.minecraft.client.renderer.model.ItemTransformVec3f;
|
||||
import net.minecraft.client.renderer.model.ModelRotation;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.math.Vec3i;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.minecraftforge.client.ForgeHooksClient;
|
||||
|
||||
public final class TransformationHelper
|
||||
{
|
||||
@Deprecated
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public static TransformationMatrix toTransformation(ItemTransformVec3f transform)
|
||||
{
|
||||
if (transform.equals(ItemTransformVec3f.DEFAULT)) return TransformationMatrix.func_227983_a_();
|
||||
|
||||
return new TransformationMatrix(transform.translation, quatFromXYZ(transform.rotation, true), transform.scale, null);
|
||||
}
|
||||
|
||||
public static void transform(Matrix4f matrix, Vector4f vector)
|
||||
{
|
||||
javax.vecmath.Vector4f copy = toVecmath(vector);
|
||||
toVecmath(matrix).transform(copy);
|
||||
vector.set(copy.x, copy.y, copy.z, copy.w);
|
||||
}
|
||||
|
||||
public static Quaternion quatFromXYZ(Vector3f xyz, boolean degrees)
|
||||
{
|
||||
return new Quaternion(xyz.getX(), xyz.getY(), xyz.getZ(), degrees);
|
||||
}
|
||||
|
||||
public static Direction rotate(Matrix4f matrix, Direction facing)
|
||||
{
|
||||
Vec3i dir = facing.getDirectionVec();
|
||||
javax.vecmath.Vector4f vec = new javax.vecmath.Vector4f(dir.getX(), dir.getY(), dir.getZ(), 0);
|
||||
toVecmath(matrix).transform(vec);
|
||||
return Direction.getFacingFromVector(vec.x, vec.y, vec.z);
|
||||
}
|
||||
|
||||
/**
|
||||
* convert transformation from assuming center-block system to corner-block system
|
||||
*/
|
||||
public static TransformationMatrix blockCenterToCorner(TransformationMatrix transform)
|
||||
{
|
||||
if (transform.isIdentity()) return TransformationMatrix.func_227983_a_();
|
||||
|
||||
javax.vecmath.Matrix4f ret = toVecmath(transform.func_227988_c_()), tmp = new javax.vecmath.Matrix4f();
|
||||
tmp.setIdentity();
|
||||
tmp.m03 = tmp.m13 = tmp.m23 = .5f;
|
||||
ret.mul(tmp, ret);
|
||||
tmp.m03 = tmp.m13 = tmp.m23 = -.5f;
|
||||
ret.mul(tmp);
|
||||
return new TransformationMatrix(toMojang(ret));
|
||||
}
|
||||
|
||||
/**
|
||||
* convert transformation from assuming corner-block system to center-block system
|
||||
*/
|
||||
public static TransformationMatrix blockCornerToCenter(TransformationMatrix transform)
|
||||
{
|
||||
if (transform.isIdentity()) return TransformationMatrix.func_227983_a_();
|
||||
|
||||
javax.vecmath.Matrix4f ret = toVecmath(transform.func_227988_c_()), tmp = new javax.vecmath.Matrix4f();
|
||||
tmp.setIdentity();
|
||||
tmp.m03 = tmp.m13 = tmp.m23 = -.5f;
|
||||
ret.mul(tmp, ret);
|
||||
tmp.m03 = tmp.m13 = tmp.m23 = .5f;
|
||||
ret.mul(tmp);
|
||||
return new TransformationMatrix(toMojang(ret));
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public static javax.vecmath.Vector3f toVecmath(Vector3f vec)
|
||||
{
|
||||
return new javax.vecmath.Vector3f(vec.getX(), vec.getY(), vec.getZ());
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public static javax.vecmath.Vector4f toVecmath(Vector4f vec)
|
||||
{
|
||||
return new javax.vecmath.Vector4f(vec.getX(), vec.getY(), vec.getZ(), vec.getW());
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public static javax.vecmath.Matrix4f toVecmath(Matrix4f m)
|
||||
{
|
||||
float[] all = new float[16];
|
||||
m.write(all);
|
||||
return new javax.vecmath.Matrix4f(all);
|
||||
}
|
||||
|
||||
public static javax.vecmath.Quat4f toVecmath(Quaternion q)
|
||||
{
|
||||
return new javax.vecmath.Quat4f(q.getX(), q.getY(), q.getZ(), q.getW());
|
||||
}
|
||||
|
||||
public static Quaternion toMojang(javax.vecmath.Quat4f q)
|
||||
{
|
||||
return new Quaternion(q.getX(), q.getY(), q.getZ(), q.getW());
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public static Vector3f toMojang(javax.vecmath.Vector3f vec)
|
||||
{
|
||||
return new Vector3f(vec.x, vec.y, vec.z);
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public static Vector4f toMojang(javax.vecmath.Vector4f vec)
|
||||
{
|
||||
return new Vector4f(vec.x, vec.y, vec.z, vec.w);
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public static Matrix4f toMojang(javax.vecmath.Matrix4f m)
|
||||
{
|
||||
Matrix4f r = new Matrix4f();
|
||||
float[] row = new float[4];
|
||||
float[] all = new float[16];
|
||||
for (int x = 0; x < 4; x++)
|
||||
{
|
||||
m.getRow(x, row);
|
||||
for (int y = 0; y < 4; y++)
|
||||
{
|
||||
all[y*4+x] = row[y];
|
||||
}
|
||||
}
|
||||
r.set(all);
|
||||
return r;
|
||||
}
|
||||
|
||||
public static javax.vecmath.Vector3f lerp(javax.vecmath.Tuple3f from, javax.vecmath.Tuple3f to, float progress)
|
||||
{
|
||||
javax.vecmath.Vector3f res = new javax.vecmath.Vector3f(from);
|
||||
res.interpolate(from, to, progress);
|
||||
return res;
|
||||
}
|
||||
|
||||
public static javax.vecmath.Vector4f lerp(javax.vecmath.Tuple4f from, javax.vecmath.Tuple4f to, float progress)
|
||||
{
|
||||
javax.vecmath.Vector4f res = new javax.vecmath.Vector4f(from);
|
||||
res.interpolate(from, to, progress);
|
||||
return res;
|
||||
}
|
||||
|
||||
public static Vector3f lerp(Vector3f from, Vector3f to, float progress)
|
||||
{
|
||||
Vector3f res = from.func_229195_e_();
|
||||
res.func_229190_a_(to, progress);
|
||||
return res;
|
||||
}
|
||||
|
||||
public static Quaternion slerp(Quaternion from, Quaternion to, float progress)
|
||||
{
|
||||
javax.vecmath.Quat4f res = new javax.vecmath.Quat4f();
|
||||
res.interpolate(toVecmath(from), toVecmath(to), progress);
|
||||
return toMojang(res);
|
||||
}
|
||||
|
||||
public static TransformationMatrix slerp(TransformationMatrix one, TransformationMatrix that, float progress)
|
||||
{
|
||||
return new TransformationMatrix(
|
||||
lerp(one.getTranslation(), that.getTranslation(), progress),
|
||||
slerp(one.func_227989_d_(), that.func_227989_d_(), progress),
|
||||
lerp(one.getScale(), that.getScale(), progress),
|
||||
slerp(one.getRightRot(), that.getRightRot(), progress)
|
||||
);
|
||||
}
|
||||
|
||||
private static final EnumMap<Direction, TransformationMatrix> vanillaUvTransformLocalToGlobal = Maps.newEnumMap(Direction.class);
|
||||
private static final EnumMap<Direction, TransformationMatrix> vanillaUvTransformGlobalToLocal = Maps.newEnumMap(Direction.class);
|
||||
|
||||
static
|
||||
{
|
||||
vanillaUvTransformLocalToGlobal.put(Direction.SOUTH, TransformationMatrix.func_227983_a_());
|
||||
javax.vecmath.Quat4f tmp = new javax.vecmath.Quat4f();
|
||||
tmp.set(new javax.vecmath.AxisAngle4f(0, 1, 0, (float)Math.toRadians(90)));
|
||||
vanillaUvTransformLocalToGlobal.put(Direction.EAST, new TransformationMatrix(null, toMojang(tmp), null, null));
|
||||
tmp.set(new javax.vecmath.AxisAngle4f(0, 1, 0, (float)Math.toRadians(-90)));
|
||||
vanillaUvTransformLocalToGlobal.put(Direction.WEST, new TransformationMatrix(null, toMojang(tmp), null, null));
|
||||
tmp.set(new javax.vecmath.AxisAngle4f(0, 1, 0, (float)Math.toRadians(180)));
|
||||
vanillaUvTransformLocalToGlobal.put(Direction.NORTH, new TransformationMatrix(null, toMojang(tmp), null, null));
|
||||
tmp.set(new javax.vecmath.AxisAngle4f(1, 0, 0, (float)Math.toRadians(-90)));
|
||||
vanillaUvTransformLocalToGlobal.put(Direction.UP, new TransformationMatrix(null, toMojang(tmp), null, null));
|
||||
tmp.set(new javax.vecmath.AxisAngle4f(1, 0, 0, (float)Math.toRadians(90)));
|
||||
vanillaUvTransformLocalToGlobal.put(Direction.DOWN, new TransformationMatrix(null, toMojang(tmp), null, null));
|
||||
|
||||
for(Direction side : Direction.values())
|
||||
{
|
||||
vanillaUvTransformGlobalToLocal.put(side, vanillaUvTransformLocalToGlobal.get(side).inverse());
|
||||
}
|
||||
}
|
||||
|
||||
public static TransformationMatrix getVanillaUvTransformLocalToGlobal(Direction side)
|
||||
{
|
||||
return vanillaUvTransformLocalToGlobal.get(side);
|
||||
}
|
||||
|
||||
public static TransformationMatrix getVanillaUvTransformGlobalToLocal(Direction side)
|
||||
{
|
||||
return vanillaUvTransformGlobalToLocal.get(side);
|
||||
}
|
||||
|
||||
public static TransformationMatrix getUVLockTransform(TransformationMatrix matrix, Direction originalSide)
|
||||
{
|
||||
Direction newSide = matrix.rotateTransform(originalSide);
|
||||
try
|
||||
{
|
||||
return blockCenterToCorner(vanillaUvTransformGlobalToLocal.get(originalSide).compose(blockCornerToCenter(matrix.inverse())).compose(vanillaUvTransformLocalToGlobal.get(newSide)));
|
||||
}
|
||||
catch(javax.vecmath.SingularMatrixException e)
|
||||
{
|
||||
return new TransformationMatrix(null, null, new Vector3f(0, 0, 0), null);
|
||||
}
|
||||
}
|
||||
|
||||
public static class Deserializer implements JsonDeserializer<TransformationMatrix>
|
||||
{
|
||||
@Override
|
||||
public TransformationMatrix deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException
|
||||
{
|
||||
if (json.isJsonPrimitive() && json.getAsJsonPrimitive().isString())
|
||||
{
|
||||
String transform = json.getAsString();
|
||||
if(transform.equals("identity"))
|
||||
{
|
||||
return TransformationMatrix.func_227983_a_();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new JsonParseException("TRSR: unknown default string: " + transform);
|
||||
}
|
||||
}
|
||||
if (json.isJsonArray())
|
||||
{
|
||||
// direct matrix array
|
||||
return new TransformationMatrix(parseMatrix(json));
|
||||
}
|
||||
if (!json.isJsonObject()) throw new JsonParseException("TRSR: expected array or object, got: " + json);
|
||||
JsonObject obj = json.getAsJsonObject();
|
||||
TransformationMatrix ret;
|
||||
if (obj.has("matrix"))
|
||||
{
|
||||
// matrix as a sole key
|
||||
ret = new TransformationMatrix(parseMatrix(obj.get("matrix")));
|
||||
obj.remove("matrix");
|
||||
if (obj.entrySet().size() != 0)
|
||||
{
|
||||
throw new JsonParseException("TRSR: can't combine matrix and other keys");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
Vector3f translation = null;
|
||||
Quaternion leftRot = null;
|
||||
Vector3f scale = null;
|
||||
Quaternion rightRot = null;
|
||||
if (obj.has("translation"))
|
||||
{
|
||||
translation = new Vector3f(parseFloatArray(obj.get("translation"), 3, "Translation"));
|
||||
obj.remove("translation");
|
||||
}
|
||||
if (obj.has("rotation"))
|
||||
{
|
||||
leftRot = parseRotation(obj.get("rotation"));
|
||||
obj.remove("rotation");
|
||||
}
|
||||
if (obj.has("scale"))
|
||||
{
|
||||
if(!obj.get("scale").isJsonArray())
|
||||
{
|
||||
try
|
||||
{
|
||||
float s = obj.get("scale").getAsNumber().floatValue();
|
||||
scale = new Vector3f(s, s, s);
|
||||
}
|
||||
catch (ClassCastException ex)
|
||||
{
|
||||
throw new JsonParseException("TRSR scale: expected number or array, got: " + obj.get("scale"));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
scale = new Vector3f(parseFloatArray(obj.get("scale"), 3, "Scale"));
|
||||
}
|
||||
obj.remove("scale");
|
||||
}
|
||||
if (obj.has("post-rotation"))
|
||||
{
|
||||
rightRot = parseRotation(obj.get("post-rotation"));
|
||||
obj.remove("post-rotation");
|
||||
}
|
||||
if (!obj.entrySet().isEmpty()) throw new JsonParseException("TRSR: can either have single 'matrix' key, or a combination of 'translation', 'rotation', 'scale', 'post-rotation'");
|
||||
return new TransformationMatrix(translation, leftRot, scale, rightRot);
|
||||
}
|
||||
|
||||
public static Matrix4f parseMatrix(JsonElement e)
|
||||
{
|
||||
if (!e.isJsonArray()) throw new JsonParseException("Matrix: expected an array, got: " + e);
|
||||
JsonArray m = e.getAsJsonArray();
|
||||
if (m.size() != 3) throw new JsonParseException("Matrix: expected an array of length 3, got: " + m.size());
|
||||
javax.vecmath.Matrix4f ret = new javax.vecmath.Matrix4f();
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
if (!m.get(i).isJsonArray()) throw new JsonParseException("Matrix row: expected an array, got: " + m.get(i));
|
||||
JsonArray r = m.get(i).getAsJsonArray();
|
||||
if (r.size() != 4) throw new JsonParseException("Matrix row: expected an array of length 4, got: " + r.size());
|
||||
for (int j = 0; j < 4; j++)
|
||||
{
|
||||
try
|
||||
{
|
||||
ret.setElement(i, j, r.get(j).getAsNumber().floatValue());
|
||||
}
|
||||
catch (ClassCastException ex)
|
||||
{
|
||||
throw new JsonParseException("Matrix element: expected number, got: " + r.get(j));
|
||||
}
|
||||
}
|
||||
}
|
||||
return toMojang(ret);
|
||||
}
|
||||
|
||||
public static float[] parseFloatArray(JsonElement e, int length, String prefix)
|
||||
{
|
||||
if (!e.isJsonArray()) throw new JsonParseException(prefix + ": expected an array, got: " + e);
|
||||
JsonArray t = e.getAsJsonArray();
|
||||
if (t.size() != length) throw new JsonParseException(prefix + ": expected an array of length " + length + ", got: " + t.size());
|
||||
float[] ret = new float[length];
|
||||
for (int i = 0; i < length; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
ret[i] = t.get(i).getAsNumber().floatValue();
|
||||
}
|
||||
catch (ClassCastException ex)
|
||||
{
|
||||
throw new JsonParseException(prefix + " element: expected number, got: " + t.get(i));
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static Quaternion parseAxisRotation(JsonElement e)
|
||||
{
|
||||
if (!e.isJsonObject()) throw new JsonParseException("Axis rotation: object expected, got: " + e);
|
||||
JsonObject obj = e.getAsJsonObject();
|
||||
if (obj.entrySet().size() != 1) throw new JsonParseException("Axis rotation: expected single axis object, got: " + e);
|
||||
Map.Entry<String, JsonElement> entry = obj.entrySet().iterator().next();
|
||||
Quaternion ret;
|
||||
try
|
||||
{
|
||||
if (entry.getKey().equals("x"))
|
||||
{
|
||||
ret = new Quaternion(new Vector3f(1, 0, 0), entry.getValue().getAsNumber().floatValue(), true);
|
||||
}
|
||||
else if (entry.getKey().equals("y"))
|
||||
{
|
||||
ret = new Quaternion(new Vector3f(0, 1, 0), entry.getValue().getAsNumber().floatValue(), true);
|
||||
}
|
||||
else if (entry.getKey().equals("z"))
|
||||
{
|
||||
ret = new Quaternion(new Vector3f(0, 0, 1), entry.getValue().getAsNumber().floatValue(), true);
|
||||
}
|
||||
else throw new JsonParseException("Axis rotation: expected single axis key, got: " + entry.getKey());
|
||||
}
|
||||
catch(ClassCastException ex)
|
||||
{
|
||||
throw new JsonParseException("Axis rotation value: expected number, got: " + entry.getValue());
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static Quaternion parseRotation(JsonElement e)
|
||||
{
|
||||
if (e.isJsonArray())
|
||||
{
|
||||
if (e.getAsJsonArray().get(0).isJsonObject())
|
||||
{
|
||||
Quaternion ret = new Quaternion(0, 0, 0, 1);
|
||||
for (JsonElement a : e.getAsJsonArray())
|
||||
{
|
||||
ret.multiply(parseAxisRotation(a));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
else if (e.isJsonArray())
|
||||
{
|
||||
JsonArray array = e.getAsJsonArray();
|
||||
if (array.size() == 3) //Vanilla rotation
|
||||
return quatFromXYZ(new Vector3f(parseFloatArray(e, 3, "Rotation")), true);
|
||||
else // quaternion
|
||||
return new Quaternion(parseFloatArray(e, 4, "Rotation"));
|
||||
}
|
||||
else throw new JsonParseException("Rotation: expected array or object, got: " + e);
|
||||
}
|
||||
else if (e.isJsonObject())
|
||||
{
|
||||
return parseAxisRotation(e);
|
||||
}
|
||||
else throw new JsonParseException("Rotation: expected array or object, got: " + e);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loaded 100 of 565 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user