-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
132 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 9 additions & 2 deletions
11
src/main/java/net/ludocrypt/limlib/access/BakedModelAccess.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,19 @@ | ||
package net.ludocrypt.limlib.access; | ||
|
||
import java.util.Map; | ||
import java.util.List; | ||
|
||
import org.jetbrains.annotations.Nullable; | ||
|
||
import com.mojang.datafixers.util.Pair; | ||
|
||
import net.minecraft.block.BlockState; | ||
import net.minecraft.client.render.model.BakedModel; | ||
import net.minecraft.util.Identifier; | ||
|
||
public interface BakedModelAccess { | ||
|
||
public Map<Identifier, BakedModel> getSubModels(); | ||
public List<Pair<Identifier, BakedModel>> getModels(@Nullable BlockState state); | ||
|
||
public void addModel(Identifier rendererId, @Nullable BlockState state, BakedModel model); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 11 additions & 4 deletions
15
src/main/java/net/ludocrypt/limlib/mixin/client/render/model/BakedModelMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,28 @@ | ||
package net.ludocrypt.limlib.mixin.client.render.model; | ||
|
||
import java.util.Map; | ||
import java.util.List; | ||
|
||
import org.jetbrains.annotations.Nullable; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
|
||
import com.google.common.collect.Maps; | ||
import com.google.common.collect.Lists; | ||
import com.mojang.datafixers.util.Pair; | ||
|
||
import net.ludocrypt.limlib.access.BakedModelAccess; | ||
import net.minecraft.block.BlockState; | ||
import net.minecraft.client.render.model.BakedModel; | ||
import net.minecraft.util.Identifier; | ||
|
||
@Mixin(BakedModel.class) | ||
public interface BakedModelMixin extends BakedModelAccess { | ||
|
||
@Override | ||
default Map<Identifier, BakedModel> getSubModels() { | ||
return Maps.newHashMap(); | ||
default List<Pair<Identifier, BakedModel>> getModels(@Nullable BlockState state) { | ||
return Lists.newArrayList(); | ||
} | ||
|
||
@Override | ||
default void addModel(Identifier rendererId, @Nullable BlockState state, BakedModel model) { | ||
} | ||
|
||
} |
31 changes: 25 additions & 6 deletions
31
src/main/java/net/ludocrypt/limlib/mixin/client/render/model/GeneralBakedModelMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,44 @@ | ||
package net.ludocrypt.limlib.mixin.client.render.model; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.jetbrains.annotations.Nullable; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Unique; | ||
|
||
import com.google.common.collect.Lists; | ||
import com.google.common.collect.Maps; | ||
import com.mojang.datafixers.util.Pair; | ||
|
||
import net.ludocrypt.limlib.access.BakedModelAccess; | ||
import net.minecraft.block.BlockState; | ||
import net.minecraft.client.render.model.BakedModel; | ||
import net.minecraft.util.Identifier; | ||
|
||
@Mixin(targets = { "net/minecraft/client/render/model/BasicBakedModel", "net/minecraft/client/render/model/BuiltinBakedModel", "net/minecraft/client/render/model/MultipartBakedModel", "net/minecraft/client/render/model/WeightedBakedModel", "net/fabricmc/fabric/api/renderer/v1/model/ForwardingBakedModel" }) | ||
@Mixin(targets = { "net/minecraft/client/render/model/BasicBakedModel", "net/minecraft/client/render/model/BuiltinBakedModel", "net/minecraft/client/render/model/WeightedBakedModel", "net/fabricmc/fabric/api/renderer/v1/model/ForwardingBakedModel" }) | ||
public class GeneralBakedModelMixin implements BakedModelAccess { | ||
|
||
@Unique | ||
private Map<Identifier, BakedModel> subQuads = Maps.newHashMap(); | ||
private final Map<BlockState, List<Pair<Identifier, BakedModel>>> modelsMap = Maps.newHashMap(); | ||
private List<Pair<Identifier, BakedModel>> defaultModels = Lists.newArrayList(); | ||
|
||
@Override | ||
public Map<Identifier, BakedModel> getSubModels() { | ||
return subQuads; | ||
public List<Pair<Identifier, BakedModel>> getModels(@Nullable BlockState state) { | ||
return modelsMap.getOrDefault(state, defaultModels); | ||
} | ||
|
||
@Override | ||
public void addModel(Identifier rendererId, @Nullable BlockState state, BakedModel model) { | ||
if (state == null) { | ||
defaultModels.add(Pair.of(rendererId, model)); | ||
} else { | ||
List<Pair<Identifier, BakedModel>> list = modelsMap.get(state); | ||
if (list == null) { | ||
list = Lists.newArrayList(); | ||
modelsMap.put(state, list); | ||
} | ||
|
||
list.add(Pair.of(rendererId, model)); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
src/main/java/net/ludocrypt/limlib/mixin/client/render/model/MultipartBakedModelMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package net.ludocrypt.limlib.mixin.client.render.model; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.function.Predicate; | ||
|
||
import org.jetbrains.annotations.Nullable; | ||
import org.spongepowered.asm.mixin.Final; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.Unique; | ||
|
||
import com.google.common.collect.Lists; | ||
import com.mojang.datafixers.util.Pair; | ||
|
||
import it.unimi.dsi.fastutil.objects.Reference2ReferenceOpenHashMap; | ||
import net.ludocrypt.limlib.access.BakedModelAccess; | ||
import net.minecraft.block.BlockState; | ||
import net.minecraft.client.render.model.BakedModel; | ||
import net.minecraft.client.render.model.MultipartBakedModel; | ||
import net.minecraft.util.Identifier; | ||
|
||
@Mixin(MultipartBakedModel.class) | ||
public class MultipartBakedModelMixin implements BakedModelAccess { | ||
|
||
@Shadow | ||
@Final | ||
private List<org.apache.commons.lang3.tuple.Pair<Predicate<BlockState>, BakedModel>> components; | ||
|
||
@Unique | ||
private final Map<BlockState, List<Pair<Identifier, BakedModel>>> subModelCache = new Reference2ReferenceOpenHashMap<>(); | ||
|
||
@Override | ||
public List<Pair<Identifier, BakedModel>> getModels(@Nullable BlockState state) { | ||
if (state == null) { | ||
return Lists.newArrayList(); | ||
} | ||
|
||
List<Pair<Identifier, BakedModel>> models; | ||
synchronized (this.subModelCache) { | ||
models = this.subModelCache.get(state); | ||
|
||
if (models == null) { | ||
models = new ArrayList<>(this.components.size()); | ||
|
||
for (org.apache.commons.lang3.tuple.Pair<Predicate<BlockState>, BakedModel> pair : this.components) { | ||
if ((pair.getLeft()).test(state)) { | ||
models.addAll(((BakedModelAccess) pair.getRight()).getModels(state)); | ||
} | ||
} | ||
|
||
this.subModelCache.put(state, models); | ||
} | ||
} | ||
|
||
return models; | ||
} | ||
|
||
@Override | ||
public void addModel(Identifier rendererId, @Nullable BlockState state, BakedModel model) { | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters