JCox
Members-
Posts
9 -
Joined
-
Last visited
Recent Profile Visitors
17129 profile views
JCox's Achievements
Tree Puncher (2/8)
0
Reputation
-
[1.19] Baked Model working in inventory but not in world
JCox replied to JCox's topic in Modder Support
I have just solved the issue. I knew it was going to be something really simple and it was. In my ClientSetup.java I had set the render layer to be translucent. -
JCox started following [Solved] Help with quickMoveStack , [1.19] Baked Model working in inventory but not in world , [1.19] Adding an item in a translucent block and 1 other
-
Hi, I have been closely following along with McJty's 1.18 tutorials. I am trying to make my own baked model in which a blockstate can be rendered inside. So far I have been able to render the actual model and textures but when I want to render a second blockstate inside the model it only appears in the hotbar, inventory and as a dropped item, when placing it on the ground as a block, it doesn't render. (For debugging purposes, I have set the blockstate to render as an iron block) I will include some pictures to better explain: As you can see, the iron block is only visible when the item is dropped (or in the inventory) and not when it is placed as a block. Files and Git Repo https://github.com/JCox06/AdvancedFarming Registration is done under the setup/Registration The PlantVessel block and tile entity ascioated with the baked model are in block/PlantVessel and be/PlantVesselBE The following file below is the bakedmodel (for more context this file is under the cient/model package) package uk.co.jcox.advancedfarming.client.model; import com.mojang.math.Matrix4f; import com.mojang.math.Transformation; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.block.model.BakedQuad; import net.minecraft.client.renderer.block.model.ItemOverrides; import net.minecraft.client.renderer.block.model.ItemTransforms; import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.client.resources.model.BakedModel; import net.minecraft.client.resources.model.Material; import net.minecraft.client.resources.model.ModelState; import net.minecraft.core.Direction; import net.minecraft.util.RandomSource; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.state.BlockState; import net.minecraftforge.client.model.IDynamicBakedModel; import net.minecraftforge.client.model.IQuadTransformer; import net.minecraftforge.client.model.QuadTransformers; import net.minecraftforge.client.model.data.ModelData; import uk.co.jcox.advancedfarming.block.PlantVessel; import uk.co.jcox.advancedfarming.util.ClientTools; import javax.annotation.Nonnull; import javax.annotation.Nullable; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.function.Function; import static uk.co.jcox.advancedfarming.util.ClientTools.v; public class PlantVesselBakedModel implements IDynamicBakedModel { private final ModelState modelState; private final Function<Material, TextureAtlasSprite> spriteGetter; private List<BakedQuad> quads = new ArrayList<>(); private final ItemOverrides overrides; private final ItemTransforms itemTransforms; public PlantVesselBakedModel(ModelState modelState, Function<Material, TextureAtlasSprite> spriteGetter, ItemOverrides overrides, ItemTransforms itemTransforms) { this.modelState = modelState; this.spriteGetter = spriteGetter; this.overrides = overrides; this.itemTransforms = itemTransforms; generateQuadCache(); } @Override public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, @Nonnull RandomSource rand, @Nonnull ModelData extraData, @Nullable RenderType layer) { if (side != null || (layer != null && layer.equals(RenderType.solid()))) { return Collections.emptyList(); } List<BakedQuad> combined = new ArrayList<>(quads); combined.addAll(getQuadsOfIncubatingBlock(state, rand, extraData, layer)); return combined; } private void generateQuadCache() { Transformation rotation = modelState.getRotation(); TextureAtlasSprite textureSide = spriteGetter.apply(PlantVesselModelLoader.MATERIAL_SIDE); TextureAtlasSprite textureBase = spriteGetter.apply(PlantVesselModelLoader.MATERIAL_BOTTOM); TextureAtlasSprite textureOutsideBase = spriteGetter.apply(PlantVesselModelLoader.MATERIAL_BASE); TextureAtlasSprite textureBottomBase = spriteGetter.apply(PlantVesselModelLoader.MATERIAL_BOTTOM_BASE); float l = 2f / 16f; float r = 14f / 16f; float a = 1; float b = 0; //Base var quads = new ArrayList<BakedQuad>(); quads.add(ClientTools.createQuad(v(r, r, r), v(r, r, l), v(l, r, l), v(l, r, r), rotation, textureSide)); // Top side quads.add(ClientTools.createQuad(v(a, l, a), v(a, l, b), v(b, l, b), v(b, l, a), rotation, textureBase)); // Inside texture quads.add(ClientTools.createQuad(v(r, r, r), v(r, l, r), v(r, l, l), v(r, r, l), rotation, textureSide)); quads.add(ClientTools.createQuad(v(l, r, l), v(l, l, l), v(l, l, r), v(l, r, r), rotation, textureSide)); quads.add(ClientTools.createQuad(v(r, r, l), v(r, l, l), v(l, l, l), v(l, r, l), rotation, textureSide)); quads.add(ClientTools.createQuad(v(l, r, r), v(l, l, r), v(r, l, r), v(r, r, r), rotation, textureSide)); quads.add(ClientTools.createQuad(v(b, b, b), v(a, b, b), v(a, b, a), v(b, b, a), rotation, textureOutsideBase)); //Outside quads.add(ClientTools.createQuad(v(b, l, b), v(b, b, b), v(b, b, a), v(b, l, a), rotation, textureBottomBase)); quads.add(ClientTools.createQuad(v(a, l, b), v(a, b, b), v(b, b, b), v(b, l, b), rotation, textureBottomBase)); quads.add(ClientTools.createQuad(v(b, l, a), v(b, b, a), v(a, b, a), v(a, l, a), rotation, textureBottomBase)); quads.add(ClientTools.createQuad(v(a, l, a), v(a, b, a), v(a, b, b), v(a, l, b), rotation, textureBottomBase)); this.quads = quads; } private List<BakedQuad> getQuadsOfIncubatingBlock(@Nullable BlockState state, @Nullable RandomSource rand, @Nullable ModelData extraData, RenderType layer) { List<BakedQuad> incubatingBlockQuads = new ArrayList<>(); BlockState crop = Blocks.IRON_BLOCK.defaultBlockState(); if (crop != null && !(crop.getBlock() instanceof PlantVessel)) { if (layer == null || getRenderTypes(crop, rand, extraData).contains(layer)) { BakedModel model = Minecraft.getInstance().getBlockRenderer().getBlockModelShaper().getBlockModel(crop); try { Transformation translate = new Transformation(Matrix4f.createScaleMatrix(0.5f, 0.5f, 0.5f)); IQuadTransformer transformer = QuadTransformers.applying(translate); //Get the quad of every side, transform it, and add it to the list of quads to render for (Direction s : Direction.values()) { List<BakedQuad> modelQuads = model.getQuads(crop, s, rand, ModelData.EMPTY, layer); for (BakedQuad quad : modelQuads) { incubatingBlockQuads.add(transformer.process(quad)); } } } catch (Exception e) { e.printStackTrace(); } } } return incubatingBlockQuads; } @Override public boolean usesBlockLight() { return false; } @Override public boolean useAmbientOcclusion() { return false; } @Override public boolean isGui3d() { return false; } @Override public boolean isCustomRenderer() { return false; } @Override public TextureAtlasSprite getParticleIcon() { return this.spriteGetter.apply(PlantVesselModelLoader.MATERIAL_SIDE); } @Override public ItemOverrides getOverrides() { return this.overrides; } @Override public ItemTransforms getTransforms() { return this.itemTransforms; } } If anyone has an idea why this is happening that would be greatly appreciated. Thank you.
-
Hi, I am currently trying to make a translucent block that can have a blockstate inside. What I ideally want to achieve is a block which a crop inside (imagine a glass block with a smaller version of a wheat block inside or a berry bush block inside). However I am not too sure how to go about doing this. I would also like to manipulate the blockstate (change the age of the block) I have seen this could be possible with a baked model and store a BlockSate in a model property but I do not know how baked models work and so I would preferably avoid them.
-
Thanks for the quick reply. From what I have gathered is, you just add an extra paremeter for your container constructor for the ContainerData. Then you just add the container data using addDataSlots. I was trying to use addDataSlot() but using addDataSlots() is much easier.
-
Hi, as I understand a container/menu class is used for the syncing of data between the client and the server. I have a value in my BlockEntity class that will change and update that I want to show on my GUI screen on the client. However I don't understand why I have to use addDataSlot() so the client can get the value from the BlockEntity, why can't the client just call a method in the container class that returns a value from the BlockEntity? I also don't understand how I would go about implementing the getters and setters that are required when instantiating a new DataSlot() for the addDataSlot method. For example, how would I sync an integer from a BlockEntity Class and display that number as a label on the GUI on the client? Thanks.
-
Yes thank you. That has worked.
-
Thanks so if you have two slots in your custom inventory and add them at index 0 and index 1. And then you start adding your player inventory slots (starting at index 0) The first hotbar item slot in the quickMoveStack method will be at index 2?
-
When you subclass AbstractContainerMenu you have to implement quickMoveStack. I don't understand the int paremeter. I assume it is the index of the slot you clicked, but are there not two inventories, the player and the custom container? I don't know how to reference an index slot on the custom inventory and move an item to a index slot on the player inventory. Would someone mind explaining the second parameter for this method. Thanks.