Jump to content

[1.15] How to cast a shadow on my custom model


Zemelua

Recommended Posts

public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, Random rand, IModelData extraData) {
			Collection<Property<?>> properties = state.getProperties();
			List<BakedQuad> quads = new ArrayList<>();
			for (Map.Entry<String, JsonElement> variantElements : variants.entrySet()) {
				//String JSONVariants = variantElement.getAsString();
				String[] JSONProperties = variantElements.getKey().split(",", 0);
				for (String JSONProperty : JSONProperties) {
					String propertyName = JSONProperty.split("=", 2)[0];
					Integer propertyValue = Integer.valueOf(JSONProperty.split("=", 2)[1]);
					for (Property<?> property : properties) {
						if (!property.getName().equalsIgnoreCase(propertyName) && state.get(property) == propertyValue) {
							TextureAtlasSprite sprite = new RenderMaterial(AtlasTexture.LOCATION_BLOCKS_TEXTURE, new ResourceLocation(/*variantElements.getValue().getAsJsonObject().get("top").getAsString()*/"block/oak_planks")).getSprite();
							List<TextureAtlasSprite> sprites = new ArrayList<>();

							ExpansionMod.LOGGER.debug(sprite.toString());


							quads.add(buildQuad(Direction.NORTH, sprite,
								1, 1, 0, sprite.getMinU(), sprite.getMinV(),
								1, 0, 0, sprite.getMinU(), sprite.getMaxV(),
								0, 0, 0, sprite.getMaxU(), sprite.getMaxV(),
								0, 1, 0, sprite.getMaxU(), sprite.getMinV()
							));
							quads.add(buildQuad(Direction.SOUTH, sprite,
								0, 1, 1, sprite.getMinU(), sprite.getMinV(),
								0, 0, 1, sprite.getMinU(), sprite.getMaxV(),
								1, 0, 1, sprite.getMaxU(), sprite.getMaxV(),
								1, 1, 1, sprite.getMaxU(), sprite.getMinV()
							));
						}
					}
				}
			}
			ExpansionMod.LOGGER.debug(quads);
			return quads;
		}

private BakedQuad buildQuad(Direction side, TextureAtlasSprite sprite,
		                                   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,
		                                   float x3, float y3, float z3, float u3, float v3) {
			BakedQuadBuilder builder = new BakedQuadBuilder(sprite);
			builder.setApplyDiffuseLighting(true);
			builder.setContractUVs(true);
			boolean hasTransform = this.modelTransform.getRotation().isIdentity();
			IVertexConsumer consumer = hasTransform ? new TRSRTransformer(builder, this.modelTransform.getRotation()) : builder;

			builder.setQuadOrientation(side);

			putVertex(consumer, side, x0, y0, z0, u0, v0);
			putVertex(consumer, side, x1, y1, z1, u1, v1);
			putVertex(consumer, side, x2, y2, z2, u2, v2);
			putVertex(consumer, side, x3, y3, z3, u3, v3);

			return builder.build();
		}

		private static void putVertex(IVertexConsumer consumer, Direction side, float x, float y, float z, float u, float v) {
			ImmutableList<VertexFormatElement> elements = consumer.getVertexFormat().getElements();
			for(int e = 0; e <= elements.size() - 1; e ++){
				VertexFormatElement element = elements.get(e);
				switch(element.getUsage()){
					case POSITION :
						consumer.put(e, x, y, z, 1.0f);
						break;
					case COLOR :
						consumer.put(e, 1.0f, 1.0f, 1.0f, 1.0f);
						break;
					case NORMAL :
						float offX = (float) side.getXOffset();
						float offY = (float) side.getYOffset();
						float offZ = (float) side.getZOffset();
						consumer.put(e, offX, offY, offZ, 0.0f);
						break;
					case UV :
						if(element.getIndex() == 0){
							consumer.put(e, u, v, 0f, 1f);
							break;
						}
					default :
						consumer.put(e);
						break;
				}
			}
		}

1894760391_(51).png.f70f8f366e2e9bee7da37ced71d7a2e7.png

With the above code, I'm trying to model the block on the right side of the image. The block on the left is oak_planks. As you can see, the custom model on the right has a single color and no shade. How can I shade this model?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.