mirror of
https://github.com/GTNewHorizons/Mantle.git
synced 2026-11-19 03:39:18 +00:00
Fix Baked Composite model not caching the quads. Now it can be used as a proper model cache #59
This commit is contained in:
1 parent
33c906a470
commit
70e35d8daf
1 file changed
+52
-7
@@ -1,6 +1,10 @@
|
||||
package slimeknights.mantle.client.model;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
import com.sun.xml.internal.bind.v2.runtime.unmarshaller.IntData;
|
||||
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.renderer.block.model.BakedQuad;
|
||||
@@ -8,28 +12,69 @@ import net.minecraft.client.renderer.block.model.IBakedModel;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import slimeknights.mantle.util.ImmutableConcatList;
|
||||
|
||||
/**
|
||||
* Groups multiple baked models into a single one. Does not respect state etc. when getting quads.
|
||||
* Best use the Builder to create a BakedCompositeModel.
|
||||
*/
|
||||
public class BakedCompositeModel extends BakedWrapper {
|
||||
|
||||
protected final List<IBakedModel> parts;
|
||||
protected final ImmutableMap<Optional<EnumFacing>, ImmutableList<BakedQuad>> parts;
|
||||
|
||||
public BakedCompositeModel(IBakedModel parent, List<IBakedModel> parts) {
|
||||
public BakedCompositeModel(IBakedModel parent, ImmutableMap<Optional<EnumFacing>, ImmutableList<BakedQuad>> parts) {
|
||||
super(parent);
|
||||
|
||||
this.parts = parts;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BakedQuad> getQuads(IBlockState state, EnumFacing side, long rand) {
|
||||
ImmutableList.Builder<List<BakedQuad>> builder = ImmutableList.builder();
|
||||
return parts.get(Optional.fromNullable(side));
|
||||
}
|
||||
|
||||
builder.add(super.getQuads(state, side, rand));
|
||||
public static class Builder {
|
||||
ImmutableList.Builder<BakedQuad>[] builders;
|
||||
IBakedModel parent;
|
||||
|
||||
for(IBakedModel part : parts) {
|
||||
builder.add(part.getQuads(state, side, rand));
|
||||
public Builder() {
|
||||
this.parent = parent;
|
||||
builders = new ImmutableList.Builder[7];
|
||||
for(int i = 0; i < 7; i++) {
|
||||
builders[i] = ImmutableList.builder();
|
||||
}
|
||||
}
|
||||
|
||||
return new ImmutableConcatList<BakedQuad>(builder.build());
|
||||
public void add(IBakedModel model, IBlockState state, long rand) {
|
||||
add(model, state, null, rand);
|
||||
for(EnumFacing side : EnumFacing.values()) {
|
||||
add(model, state, side, rand);
|
||||
}
|
||||
}
|
||||
|
||||
public void add(IBakedModel model, IBlockState state, EnumFacing side, long rand) {
|
||||
int index;
|
||||
if(side == null) {
|
||||
index = 6;
|
||||
}
|
||||
else {
|
||||
index = side.getIndex();
|
||||
}
|
||||
|
||||
builders[index].addAll(model.getQuads(state, side, rand));
|
||||
}
|
||||
|
||||
public BakedCompositeModel build(IBakedModel parent) {
|
||||
ImmutableMap.Builder<Optional<EnumFacing>, ImmutableList<BakedQuad>> map = ImmutableMap.builder();
|
||||
|
||||
map.put(Optional.<EnumFacing>absent(), builders[6].build());
|
||||
for(EnumFacing side : EnumFacing.values()) {
|
||||
map.put(Optional.of(side), builders[side.getIndex()].build());
|
||||
}
|
||||
|
||||
return new BakedCompositeModel(parent, map.build());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user