Skip to content

Commit

Permalink
Fix #795
Browse files Browse the repository at this point in the history
  • Loading branch information
Harleyoc1 committed Jul 20, 2023
1 parent 8c8caee commit 3439b26
Show file tree
Hide file tree
Showing 10 changed files with 106 additions and 169 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.ferreusveritas.dynamictrees.DynamicTrees;
import com.ferreusveritas.dynamictrees.block.PottedSaplingBlock;
import com.ferreusveritas.dynamictrees.models.baked.BakedModelBlockBonsaiPot;
import com.ferreusveritas.dynamictrees.models.baked.BranchBlockBakedModel;
import com.ferreusveritas.dynamictrees.models.loader.BranchBlockModelLoader;
import com.ferreusveritas.dynamictrees.models.loader.RootBlockModelLoader;
import com.ferreusveritas.dynamictrees.models.loader.ThickBranchBlockModelLoader;
Expand Down Expand Up @@ -36,10 +35,6 @@ public static void onModelRegistryEvent(RegisterGeometryLoaders event) {

@SubscribeEvent
public static void onModelBake(BakingCompleted event) {
// Setup branch baked models (bakes cores and sleeves).
BranchBlockBakedModel.INSTANCES.forEach(BranchBlockBakedModel::setupModels);
BranchBlockBakedModel.INSTANCES.clear();

// Put bonsai pot baked model into its model location.
BakedModel flowerPotModel = event.getModelManager().getModel(new ModelResourceLocation(PottedSaplingBlock.REG_NAME, ""));
event.getModels().put(new ModelResourceLocation(PottedSaplingBlock.REG_NAME, ""),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,55 +7,58 @@
import com.google.common.collect.Maps;
import com.mojang.math.Vector3f;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.renderer.block.model.BlockElement;
import net.minecraft.client.renderer.block.model.BlockElementFace;
import net.minecraft.client.renderer.block.model.BlockFaceUV;
import net.minecraft.client.renderer.block.model.ItemOverrides;
import net.minecraft.client.renderer.block.model.*;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.resources.model.BakedModel;
import net.minecraft.client.resources.model.BlockModelRotation;
import net.minecraft.client.resources.model.Material;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.Direction.Axis;
import net.minecraft.core.Direction.AxisDirection;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.RandomSource;
import net.minecraft.world.inventory.InventoryMenu;
import net.minecraft.world.level.BlockAndTintGetter;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.client.model.IDynamicBakedModel;
import net.minecraftforge.client.model.IModelBuilder;
import net.minecraftforge.client.model.data.ModelData;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Function;

@OnlyIn(Dist.CLIENT)
public class BasicBranchBlockBakedModel extends BranchBlockBakedModel {
public class BasicBranchBlockBakedModel implements IDynamicBakedModel {

protected TextureAtlasSprite barkTexture;
protected TextureAtlasSprite ringsTexture;
protected final BlockModel blockModel;

protected final ResourceLocation modelLocation;

protected final TextureAtlasSprite barkTexture;
protected final TextureAtlasSprite ringsTexture;

// 74 Baked models per tree family to achieve this. I guess it's not my problem. Wasn't my idea anyway.
private final BakedModel[][] sleeves = new BakedModel[6][7];
private final BakedModel[][] cores = new BakedModel[3][8]; // 8 Cores for 3 axis with the bark texture all all 6 sides rotated appropriately.
private final BakedModel[] rings = new BakedModel[8]; // 8 Cores with the ring textures on all 6 sides.

public BasicBranchBlockBakedModel(ResourceLocation modelResLoc, ResourceLocation barkResLoc, ResourceLocation ringsResLoc) {
super(modelResLoc, barkResLoc, ringsResLoc);
public BasicBranchBlockBakedModel(ResourceLocation modelLocation, ResourceLocation barkTextureLocation, ResourceLocation ringsTextureLocation,
Function<Material, TextureAtlasSprite> spriteGetter) {
this.blockModel = new BlockModel(null, new ArrayList<>(), new HashMap<>(), false, BlockModel.GuiLight.FRONT,
ItemTransforms.NO_TRANSFORMS, new ArrayList<>());
this.modelLocation = modelLocation;
this.barkTexture = spriteGetter.apply(new Material(InventoryMenu.BLOCK_ATLAS, barkTextureLocation));
this.ringsTexture = spriteGetter.apply(new Material(InventoryMenu.BLOCK_ATLAS, ringsTextureLocation));
initModels();
}

@Override
public void setupModels() {
this.barkTexture = ModelUtils.getTexture(this.barkResLoc);
this.ringsTexture = ModelUtils.getTexture(this.ringsResLoc);

private void initModels() {
for (int i = 0; i < 8; i++) {
int radius = i + 1;
if (radius < 8) {
Expand All @@ -67,7 +70,7 @@ public void setupModels() {
cores[1][i] = bakeCore(radius, Axis.Z, barkTexture); //NORTH<->SOUTH
cores[2][i] = bakeCore(radius, Axis.X, barkTexture); //WEST<->EAST

rings[i] = bakeCore(radius, Axis.Y, this.ringsTexture);
rings[i] = bakeCore(radius, Axis.Y, ringsTexture);
}
}

Expand Down Expand Up @@ -114,7 +117,7 @@ public BakedModel bakeSleeve(int radius, Direction dir, TextureAtlasSprite bark)

for (Map.Entry<Direction, BlockElementFace> e : part.faces.entrySet()) {
Direction face = e.getKey();
builder.addCulledFace(face, ModelUtils.makeBakedQuad(part, e.getValue(), bark, face, BlockModelRotation.X0_Y0, this.modelResLoc));
builder.addCulledFace(face, ModelUtils.makeBakedQuad(part, e.getValue(), bark, face, BlockModelRotation.X0_Y0, this.modelLocation));
}

return builder.build();
Expand All @@ -137,7 +140,7 @@ public BakedModel bakeCore(int radius, Axis axis, TextureAtlasSprite icon) {

for (Map.Entry<Direction, BlockElementFace> e : part.faces.entrySet()) {
Direction face = e.getKey();
builder.addCulledFace(face, ModelUtils.makeBakedQuad(part, e.getValue(), icon, face, BlockModelRotation.X0_Y0, this.modelResLoc));
builder.addCulledFace(face, ModelUtils.makeBakedQuad(part, e.getValue(), icon, face, BlockModelRotation.X0_Y0, this.modelLocation));
}

return builder.build();
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,51 +7,53 @@
import com.google.common.collect.Maps;
import com.mojang.math.Vector3f;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.renderer.block.model.BlockElement;
import net.minecraft.client.renderer.block.model.BlockElementFace;
import net.minecraft.client.renderer.block.model.BlockFaceUV;
import net.minecraft.client.renderer.block.model.ItemOverrides;
import net.minecraft.client.renderer.block.model.*;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.resources.model.BakedModel;
import net.minecraft.client.resources.model.BlockModelRotation;
import net.minecraft.client.resources.model.Material;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth;
import net.minecraft.util.RandomSource;
import net.minecraft.world.inventory.InventoryMenu;
import net.minecraft.world.level.BlockAndTintGetter;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.AABB;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.client.model.IDynamicBakedModel;
import net.minecraftforge.client.model.IModelBuilder;
import net.minecraftforge.client.model.data.ModelData;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.function.Function;

@OnlyIn(Dist.CLIENT)
public class RootBlockBakedModel extends BranchBlockBakedModel {
public class RootBlockBakedModel implements IDynamicBakedModel {

private TextureAtlasSprite barkTexture;
private final BlockModel blockModel;

private final ResourceLocation modelLocation;

private final TextureAtlasSprite barkTexture;

private final BakedModel[][] sleeves = new BakedModel[4][7];
private final BakedModel[][] cores = new BakedModel[2][8]; //8 Cores for 2 axis(X, Z) with the bark texture on all 6 sides rotated appropriately.
private final BakedModel[][] verts = new BakedModel[4][8];

public RootBlockBakedModel(ResourceLocation modelResLoc, ResourceLocation barkResLoc) {
super(modelResLoc, barkResLoc, null);
public RootBlockBakedModel(ResourceLocation modelLocation, ResourceLocation barkTextureLocation, Function<Material, TextureAtlasSprite> spriteGetter) {
this.blockModel = new BlockModel(null, new ArrayList<>(), new HashMap<>(), false, BlockModel.GuiLight.FRONT,
ItemTransforms.NO_TRANSFORMS, new ArrayList<>());
this.modelLocation = modelLocation;
this.barkTexture = spriteGetter.apply(new Material(InventoryMenu.BLOCK_ATLAS, barkTextureLocation));
initModels();
}

@Override
public void setupModels() {
this.barkTexture = ModelUtils.getTexture(this.barkResLoc);

public void initModels() {
for (int r = 0; r < 8; r++) {
int radius = r + 1;
if (radius < 8) {
Expand Down Expand Up @@ -112,7 +114,7 @@ public BakedModel bakeSleeve(int radius, Direction dir) {

for (Map.Entry<Direction, BlockElementFace> e : part.faces.entrySet()) {
Direction face = e.getKey();
builder.addCulledFace(face, ModelUtils.makeBakedQuad(part, e.getValue(), this.barkTexture, face, BlockModelRotation.X0_Y0, this.modelResLoc));
builder.addCulledFace(face, ModelUtils.makeBakedQuad(part, e.getValue(), this.barkTexture, face, BlockModelRotation.X0_Y0, this.modelLocation));
}

return builder.build();
Expand All @@ -137,7 +139,7 @@ private BakedModel bakeVert(int radius, Direction dir) {
Vector3f[] limits = ModelUtils.AABBLimits(pieceBoundary);

BlockElement part = new BlockElement(limits[0], limits[1], mapFacesIn, null, true);
builder.addCulledFace(face, ModelUtils.makeBakedQuad(part, part.faces.get(face), this.barkTexture, face, BlockModelRotation.X0_Y0, this.modelResLoc));
builder.addCulledFace(face, ModelUtils.makeBakedQuad(part, part.faces.get(face), this.barkTexture, face, BlockModelRotation.X0_Y0, this.modelLocation));
}
}

Expand Down Expand Up @@ -169,7 +171,7 @@ public BakedModel bakeCore(int radius, Direction.Axis axis, TextureAtlasSprite i

for (Map.Entry<Direction, BlockElementFace> e : part.faces.entrySet()) {
Direction face = e.getKey();
builder.addCulledFace(face, ModelUtils.makeBakedQuad(part, e.getValue(), icon, face, BlockModelRotation.X0_Y0, this.modelResLoc));
builder.addCulledFace(face, ModelUtils.makeBakedQuad(part, e.getValue(), icon, face, BlockModelRotation.X0_Y0, this.modelLocation));
}

return builder.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.resources.model.BakedModel;
import net.minecraft.client.resources.model.BlockModelRotation;
import net.minecraft.client.resources.model.Material;
import net.minecraft.core.Direction;
import net.minecraft.core.Direction.Axis;
import net.minecraft.core.Vec3i;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth;
import net.minecraft.util.RandomSource;
import net.minecraft.world.inventory.InventoryMenu;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3;
Expand All @@ -37,40 +39,26 @@
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.function.Function;

@OnlyIn(Dist.CLIENT)
public class ThickBranchBlockBakedModel extends BasicBranchBlockBakedModel {

protected final ResourceLocation thickRingsResLoc;

private final BakedModel[] trunksBark = new BakedModel[16]; // The trunk will always feature bark on its sides.
private final BakedModel[] trunksTopBark = new BakedModel[16]; // The trunk will feature bark on its top when there's a branch on top of it.
private final BakedModel[] trunksTopRings = new BakedModel[16]; // The trunk will feature rings on its top when there's no branches on top of it.
private final BakedModel[] trunksBotRings = new BakedModel[16]; // The trunk will always feature rings on its bottom surface if nothing is below it.

public ThickBranchBlockBakedModel(ResourceLocation modelResLoc, ResourceLocation barkResLoc, ResourceLocation ringsResLoc, ResourceLocation thickRingsResLoc) {
super(modelResLoc, barkResLoc, ringsResLoc);
this.thickRingsResLoc = thickRingsResLoc;
}

private boolean isTextureNull(@Nullable TextureAtlasSprite sprite) {
return sprite == null || sprite.equals(ModelUtils.getTexture(new ResourceLocation("")));
public ThickBranchBlockBakedModel(ResourceLocation modelLocation, ResourceLocation barkTextureLocation, ResourceLocation ringsTextureLocation,
ResourceLocation thickRingsTextureLocation, Function<Material, TextureAtlasSprite> spriteGetter) {
super(modelLocation, barkTextureLocation, ringsTextureLocation, spriteGetter);
initThickModels(spriteGetter.apply(new Material(InventoryMenu.BLOCK_ATLAS, thickRingsTextureLocation)));
}

@Override
public void setupModels() {
super.setupModels();

TextureAtlasSprite thickRingsTexture = ModelUtils.getTexture(this.thickRingsResLoc);

//if (isTextureNull(thickRingsTexture)){
//thickRingsTexture = ThickRingTextureManager.uploader.getTextureAtlas().getSprite(thickRingsResLoc);
//thickRingsTexture = ModelUtils.getTexture(thickRingsResLoc, ThickRingTextureManager.LOCATION_THICKRINGS_TEXTURE);

public void initThickModels(TextureAtlasSprite thickRingsTexture) {
if (isTextureNull(thickRingsTexture)) {
thickRingsTexture = this.ringsTexture;
}
//}

for (int i = 0; i < ThickBranchBlock.MAX_RADIUS_THICK - ThickBranchBlock.MAX_RADIUS; i++) {
int radius = i + ThickBranchBlock.MAX_RADIUS + 1;
Expand All @@ -81,6 +69,10 @@ public void setupModels() {
}
}

private boolean isTextureNull(@Nullable TextureAtlasSprite sprite) {
return sprite == null || sprite.getName().equals(new ResourceLocation(""));
}

public BakedModel bakeTrunkBark(int radius, TextureAtlasSprite bark, boolean side) {

IModelBuilder<?> builder = ModelUtils.getModelBuilder(this.blockModel.customData, bark);
Expand Down Expand Up @@ -110,7 +102,7 @@ public BakedModel bakeTrunkBark(int radius, TextureAtlasSprite bark, boolean sid
mapFacesIn.put(face, new BlockElementFace(null, -1, null, uvface));

BlockElement part = new BlockElement(limits[0], limits[1], mapFacesIn, null, true);
builder.addCulledFace(face, ModelUtils.makeBakedQuad(part, part.faces.get(face), bark, face, BlockModelRotation.X0_Y0, this.modelResLoc));
builder.addCulledFace(face, ModelUtils.makeBakedQuad(part, part.faces.get(face), bark, face, BlockModelRotation.X0_Y0, this.modelLocation));
}

}
Expand Down Expand Up @@ -158,7 +150,7 @@ public BakedModel bakeTrunkRings(int radius, TextureAtlasSprite ring, Direction
mapFacesIn.put(face, new BlockElementFace(null, -1, null, uvface));

BlockElement part = new BlockElement(posFrom, posTo, mapFacesIn, null, true);
builder.addCulledFace(face, ModelUtils.makeBakedQuad(part, part.faces.get(face), ring, face, BlockModelRotation.X0_Y0, this.modelResLoc));
builder.addCulledFace(face, ModelUtils.makeBakedQuad(part, part.faces.get(face), ring, face, BlockModelRotation.X0_Y0, this.modelLocation));
}

return builder.build();
Expand Down
Loading

0 comments on commit 3439b26

Please sign in to comment.