
HeroBear
Members-
Content Count
1 -
Joined
-
Last visited
Community Reputation
0 NeutralAbout HeroBear
-
Rank
Tree Puncher
Recent Profile Visitors
The recent visitors block is disabled and is not being shown to other users.
-
HeroBear started following [1.16.4] Connect 2D textures in IBakedModel
-
So i just started modding and tried to make a Tinkers' Construct "copy" mod and run into 2 issues (for now) I used TheGreyGhost's code making a dynamic model for my combined sword textures and as you can see: 1. I dont know how to make the sword thicker 2. How can i "rotate" this side (North) without making a different rotated texture and add that cuz i think there is better ways to do it I dont fully understand the code it self but here is it: package com.mod.blacksmithsreborn.base_sword; import java.awt.Color; import java.util.ArrayList; import java.util.List; import java.util.Random; import javax.annotation.Nullable; import com.google.common.primitives.Ints; import com.mod.blacksmithsreborn.BlacksmithsReborn; import net.minecraft.block.BlockState; import net.minecraft.client.renderer.LightTexture; 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.texture.AtlasTexture; import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.util.Direction; import net.minecraft.util.ResourceLocation; import net.minecraftforge.client.event.TextureStitchEvent; import net.minecraftforge.client.model.ModelLoader; import net.minecraftforge.eventbus.api.SubscribeEvent; public class BaseSwordFinalisedModel implements IBakedModel { private IBakedModel originalModel; private String handlePath, bindPath, headPath; public BaseSwordFinalisedModel(IBakedModel IOriginalModel, String IHandlePath, String IBindPath, String IHeadPath) { originalModel = IOriginalModel; handlePath = IHandlePath; bindPath = IBindPath; headPath = IHeadPath; } @SuppressWarnings({ "deprecation", "unchecked", "rawtypes" }) @Override public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, Random rand) { if (side != null) { return originalModel.getQuads(state, side, rand); } List<BakedQuad> combinedQuadsList = new ArrayList(originalModel.getQuads(state, side, rand)); combinedQuadsList.addAll(getAllQuads(handlePath, bindPath, headPath)); return combinedQuadsList; //FaceBakery.makeBakedQuad(); } @Override public boolean isAmbientOcclusion() { return originalModel.isAmbientOcclusion(); } @Override public boolean isGui3d() { return originalModel.isGui3d(); } @Override public boolean isSideLit() { return false; } @Override public boolean isBuiltInRenderer() { return originalModel.isBuiltInRenderer(); } @SuppressWarnings("deprecation") @Override public TextureAtlasSprite getParticleTexture() { return originalModel.getParticleTexture(); } @SuppressWarnings("deprecation") @Override public ItemCameraTransforms getItemCameraTransforms() { return originalModel.getItemCameraTransforms(); } @Override public ItemOverrideList getOverrides() { throw new UnsupportedOperationException("The finalised model does not have an override list."); } @SubscribeEvent public static void onTextureStitchEvent(TextureStitchEvent.Pre event) { event.addSprite(new ResourceLocation(BlacksmithsReborn.MOD_ID + ":items/tin_handle")); //ModelLoader.addSpecialModel(new ResourceLocation(BlacksmithsReborn.MOD_ID + ":items/tin_handle")); event.addSprite(new ResourceLocation(BlacksmithsReborn.MOD_ID + ":items/tin_sword_bind")); event.addSprite(new ResourceLocation(BlacksmithsReborn.MOD_ID + ":items/tin_sword_head")); event.addSprite(new ResourceLocation(BlacksmithsReborn.MOD_ID + ":items/aluminium_handle")); event.addSprite(new ResourceLocation(BlacksmithsReborn.MOD_ID + ":items/aluminium_sword_bind")); event.addSprite(new ResourceLocation(BlacksmithsReborn.MOD_ID + ":items/aluminium_sword_head")); } @SuppressWarnings("deprecation") private List<BakedQuad> getAllQuads(String handlePath, String bindPath, String headPath) { int numberOfParts = 3; List<BakedQuad> returnList = new ArrayList<BakedQuad>(numberOfParts); if (handlePath != null && bindPath != null && headPath != null) { AtlasTexture blocksStitchedTextures = ModelLoader.instance().getSpriteMap().getAtlasTexture(AtlasTexture.LOCATION_BLOCKS_TEXTURE); ResourceLocation handleTextureResLoc = new ResourceLocation(handlePath); TextureAtlasSprite handleTexture = blocksStitchedTextures.getSprite(handleTextureResLoc); ResourceLocation bindTextureResLoc = new ResourceLocation(bindPath); TextureAtlasSprite bindTexture = blocksStitchedTextures.getSprite(bindTextureResLoc); ResourceLocation headTextureResLoc = new ResourceLocation(headPath); TextureAtlasSprite headTexture = blocksStitchedTextures.getSprite(headTextureResLoc); // "builtin/generated" item, which are generated from the 2D texture by adding a thickness in the z direction TODO // (i.e. north<-->south thickness), are centred around the z=0.5 plane. final float builtin_thickness = 1 / 16.0F; final float builtin_z_centre = 0.5F; final float builtin_z_max = builtin_z_centre + builtin_thickness / 2.0F; final float builtin_z_min = builtin_z_centre - builtin_thickness / 2.0F; final float south_face_pos = 1.0F; final float north_face_pos = 0.0F; final float dist_south_face = south_face_pos - builtin_z_max; final float dist_north_face = builtin_z_min - north_face_pos; final float width = 1.0F; final float height = 1.0F; final float column_centre_pos = 0.5F; final float row_centre_pos = 0.5F; final float olo = 0.001F; final int handleLayer = 0; final int bindLayer = 1; final int headLayer = 2; //HANDLE BakedQuad handleFront = createBakedQuadForFace(column_centre_pos, width, row_centre_pos, height, -dist_south_face + olo, handleLayer, handleTexture, Direction.SOUTH); BakedQuad handleBack = createBakedQuadForFace(column_centre_pos, width, row_centre_pos, height, -dist_north_face + olo, handleLayer, handleTexture, Direction.NORTH); returnList.add(handleFront); returnList.add(handleBack); //BIND BakedQuad bindFront = createBakedQuadForFace(column_centre_pos, width, row_centre_pos, height, -dist_south_face + olo, bindLayer, bindTexture, Direction.SOUTH); BakedQuad bindBack = createBakedQuadForFace(column_centre_pos, width, row_centre_pos, height, -dist_north_face + olo, bindLayer, bindTexture, Direction.NORTH); returnList.add(bindFront); returnList.add(bindBack); //HEAD BakedQuad headFront = createBakedQuadForFace(column_centre_pos, width, row_centre_pos, height, -dist_south_face + olo, headLayer, headTexture, Direction.SOUTH); BakedQuad headBack = createBakedQuadForFace(column_centre_pos, width, row_centre_pos, height, -dist_north_face + olo, headLayer, headTexture, Direction.NORTH); returnList.add(headFront); returnList.add(headBack); } return returnList; } private BakedQuad createBakedQuadForFace(float centreLR, float width, float centreUD, float height, float forwardDisplacement, int itemRenderLayer, TextureAtlasSprite texture, Direction face) { float x1, x2, x3, x4; float y1, y2, y3, y4; float z1, z2, z3, z4; int packednormal; final float CUBE_MIN = 0.0F; final float CUBE_MAX = 1.0F; switch (face) { case UP: { x1 = x2 = centreLR + width / 2.0F; x3 = x4 = centreLR - width / 2.0F; z1 = z4 = centreUD + height / 2.0F; z2 = z3 = centreUD - height / 2.0F; y1 = y2 = y3 = y4 = CUBE_MAX + forwardDisplacement; break; } case DOWN: { x1 = x2 = centreLR + width / 2.0F; x3 = x4 = centreLR - width / 2.0F; z1 = z4 = centreUD - height / 2.0F; z2 = z3 = centreUD + height / 2.0F; y1 = y2 = y3 = y4 = CUBE_MIN - forwardDisplacement; break; } case WEST: { z1 = z2 = centreLR + width / 2.0F; z3 = z4 = centreLR - width / 2.0F; y1 = y4 = centreUD - height / 2.0F; y2 = y3 = centreUD + height / 2.0F; x1 = x2 = x3 = x4 = CUBE_MIN - forwardDisplacement; break; } case EAST: { z1 = z2 = centreLR - width / 2.0F; z3 = z4 = centreLR + width / 2.0F; y1 = y4 = centreUD - height / 2.0F; y2 = y3 = centreUD + height / 2.0F; x1 = x2 = x3 = x4 = CUBE_MAX + forwardDisplacement; break; } case NORTH: { x1 = x2 = centreLR - width / 2.0F; x3 = x4 = centreLR + width / 2.0F; y1 = y4 = centreUD - height / 2.0F; y2 = y3 = centreUD + height / 2.0F; z1 = z2 = z3 = z4 = CUBE_MIN - forwardDisplacement; break; } case SOUTH: { x1 = x2 = centreLR + width / 2.0F; x3 = x4 = centreLR - width / 2.0F; y1 = y4 = centreUD - height / 2.0F; y2 = y3 = centreUD + height / 2.0F; z1 = z2 = z3 = z4 = CUBE_MAX + forwardDisplacement; break; } default: { throw new AssertionError("Unexpected Direction in createBakedQuadForFace:" + face); }} packednormal = calculatePackedNormal(x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4); final int BLOCK_LIGHT = 15; final int SKY_LIGHT = 15; int lightMapValue = LightTexture.packLight(BLOCK_LIGHT, SKY_LIGHT); final int minU = 0; final int maxU = 16; final int minV = 0; final int maxV = 16; int [] vertexData1 = vertexToInts(x1, y1, z1, Color.WHITE.getRGB(), texture, maxU, maxV, lightMapValue, packednormal); int [] vertexData2 = vertexToInts(x2, y2, z2, Color.WHITE.getRGB(), texture, maxU, minV, lightMapValue, packednormal); int [] vertexData3 = vertexToInts(x3, y3, z3, Color.WHITE.getRGB(), texture, minU, minV, lightMapValue, packednormal); int [] vertexData4 = vertexToInts(x4, y4, z4, Color.WHITE.getRGB(), texture, minU, maxV, lightMapValue, packednormal); int [] vertexDataAll = Ints.concat(vertexData1, vertexData2, vertexData3, vertexData4); final boolean APPLY_DIFFUSE_LIGHTING = true; return new BakedQuad(vertexDataAll, itemRenderLayer, face, texture, APPLY_DIFFUSE_LIGHTING); } @SuppressWarnings("unused") private int[] vertexToInts(float x, float y, float z, int color, TextureAtlasSprite texture, float u, float v, int lightmapvalue, int normal) { //based on FaceBakery::storeVertexData and FaceBakery::fillVertexData final int DUMMY_LIGHTMAP_VALUE = 0xffff; return new int[] { Float.floatToRawIntBits(x), Float.floatToRawIntBits(y), Float.floatToRawIntBits(z), color, Float.floatToRawIntBits(texture.getInterpolatedU(u)), Float.floatToRawIntBits(texture.getInterpolatedV(v)), lightmapvalue, normal }; } private int calculatePackedNormal(float x1, float y1, float z1,float x2, float y2, float z2, float x3, float y3, float z3, float x4, float y4, float z4) { float xp = x4 - x2; float yp = y4 - y2; float zp = z4 - z2; float xq = x3 - x1; float yq = y3 - y1; float zq = z3 - z1; //Cross Product float xn = yq * zp - zq * yp; float yn = zq * xp - xq * zp; float zn = xq * yp - yq * xp; //Normalize float norm = (float) Math.sqrt(xn * xn + yn * yn + zn * zn); final float SMALL_LENGTH = 1.0E-4F; if (norm < SMALL_LENGTH) norm = 1.0F; norm = 1.0F / norm; xn *= norm; yn *= norm; zn *= norm; int x = ((byte) (xn * 127)) & 0xFF; int y = ((byte) (yn * 127)) & 0xFF; int z = ((byte) (zn * 127)) & 0xFF; return x | (y << 0x08) | (z << 0x10); } }