mirror of
https://github.com/Thorfusion/Mekanism-Community-Edition.git
synced 2026-11-28 07:36:01 +00:00
I did it! CTM works, starting with Dynamic Tank blocks
This commit is contained in:
1 parent
251ab596f5
commit
07a7391dfc
2 files changed
+33
-47
No files matched your search
@@ -1,20 +1,15 @@
|
||||
package mekanism.client.render.ctm;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.EnumMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import lombok.SneakyThrows;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.block.model.ModelBlockDefinition.Variant;
|
||||
import net.minecraft.client.renderer.block.statemap.DefaultStateMapper;
|
||||
import net.minecraft.client.renderer.block.statemap.StateMapperBase;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.renderer.texture.TextureMap;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormat;
|
||||
import net.minecraft.client.resources.model.IBakedModel;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
@@ -22,10 +17,7 @@ import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.client.model.IFlexibleBakedModel;
|
||||
import net.minecraftforge.client.model.IModel;
|
||||
import net.minecraftforge.client.model.IModelState;
|
||||
import net.minecraftforge.client.model.ModelLoader;
|
||||
import net.minecraftforge.client.model.ModelLoaderRegistry;
|
||||
import net.minecraftforge.client.model.TRSRTransformation;
|
||||
import net.minecraftforge.common.property.IExtendedBlockState;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
@@ -37,16 +29,12 @@ public class ModelChisel implements IModel {
|
||||
|
||||
private static StateMapperBase mapper = new DefaultStateMapper();
|
||||
|
||||
private Variant model;
|
||||
private Map<String, Variant> models = Maps.newHashMap();;
|
||||
|
||||
private Map<EnumFacing, String> overrides = Maps.newHashMap();
|
||||
|
||||
private transient ChiselFace faceObj;
|
||||
private transient Map<EnumFacing, ChiselFace> overridesObj = new EnumMap<>(EnumFacing.class);
|
||||
private transient IBakedModel modelObj;
|
||||
|
||||
private transient Map<String, IBakedModel> modelsObj = Maps.newHashMap();
|
||||
private transient IBakedModel modelObj;
|
||||
|
||||
private transient Map<IBlockState, IBakedModel> stateMap = Maps.newHashMap();
|
||||
|
||||
@@ -54,16 +42,15 @@ public class ModelChisel implements IModel {
|
||||
|
||||
public String modelName;
|
||||
|
||||
public ModelChisel(String name)
|
||||
public ModelChisel(IBakedModel model, String name)
|
||||
{
|
||||
modelObj = model;
|
||||
modelName = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ResourceLocation> getDependencies() {
|
||||
List<ResourceLocation> list = Lists.newArrayList(model.getModelLocation());
|
||||
list.addAll(models.values().stream().map(v -> v.getModelLocation()).collect(Collectors.toList()));
|
||||
return list;
|
||||
return new ArrayList<ResourceLocation>();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -72,15 +59,8 @@ public class ModelChisel implements IModel {
|
||||
}
|
||||
|
||||
@Override
|
||||
@SneakyThrows
|
||||
public IFlexibleBakedModel bake(IModelState state, VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter) {
|
||||
Function<ResourceLocation, TextureAtlasSprite> dummyGetter = t -> Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(TextureMap.LOCATION_MISSING_TEXTURE.toString());
|
||||
modelObj = ModelLoaderRegistry.getModel(model.getModelLocation()).bake(model.isUvLocked() ? new ModelLoader.UVLock(model.getState()) : model.getState(), format, dummyGetter);
|
||||
for (Entry<String, Variant> e : models.entrySet()) {
|
||||
Variant v = e.getValue();
|
||||
modelsObj.put(e.getKey(), ModelLoaderRegistry.getModel(v.getModelLocation()).bake(v.isUvLocked() ? new ModelLoader.UVLock(v.getState()) : v.getState(), format, dummyGetter));
|
||||
}
|
||||
return new ModelChiselBlock(this);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -107,18 +87,6 @@ public class ModelChisel implements IModel {
|
||||
}
|
||||
|
||||
public IBakedModel getModel(IBlockState state) {
|
||||
if (state instanceof IExtendedBlockState) {
|
||||
state = ((IExtendedBlockState)state).getClean();
|
||||
}
|
||||
String stateStr = mapper.getPropertyString(state.getProperties());
|
||||
stateStr = stateStr.substring(stateStr.indexOf(",") + 1, stateStr.length());
|
||||
|
||||
final String capture = stateStr;
|
||||
if (modelsObj.containsKey(stateStr)) {
|
||||
System.out.println("LOAD STATE MAP")
|
||||
stateMap.computeIfAbsent(state, s -> modelsObj.get(capture));
|
||||
}
|
||||
|
||||
return stateMap.getOrDefault(state, modelObj);
|
||||
return modelObj;
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,9 @@ package mekanism.client.render.ctm;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.resources.model.IBakedModel;
|
||||
@@ -24,7 +26,20 @@ public class TextureStitcher {
|
||||
private IBakedModel baseModel;
|
||||
public static ResourceLocation baseResource = new ResourceLocation("mekanism:block/ctm_block");
|
||||
|
||||
public String[] ctmTypes = new String[] {"dynamic_tank"};
|
||||
public static String[] ctmTypes = new String[] {"dynamic_tank"};
|
||||
|
||||
public static Map<String, ChiselTextureCTM> textureCache = new HashMap<String, ChiselTextureCTM>();
|
||||
|
||||
public TextureStitcher()
|
||||
{
|
||||
if(textureCache.isEmpty())
|
||||
{
|
||||
for(String s : ctmTypes)
|
||||
{
|
||||
textureCache.put(s, createTexture(s));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onTextureStitch(TextureStitchEvent.Pre event) {
|
||||
@@ -34,18 +49,21 @@ public class TextureStitcher {
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onModelBake(ModelBakeEvent event) throws IOException {
|
||||
public void onModelBake(ModelBakeEvent event) throws IOException
|
||||
{
|
||||
IModel model = event.modelLoader.getModel(baseResource);
|
||||
baseModel = model.bake(new TRSRTransformation(ModelRotation.X0_Y0), Attributes.DEFAULT_BAKED_FORMAT, r -> Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(r.toString()));
|
||||
|
||||
for (String ctm : ctmTypes) {
|
||||
ModelChisel chiselModel = new ModelChisel(ctm);
|
||||
for (String ctm : ctmTypes)
|
||||
{
|
||||
ModelChisel chiselModel = new ModelChisel(baseModel, ctm);
|
||||
chiselModel.load();
|
||||
event.modelRegistry.putObject(new ModelResourceLocation("mekanism:" + ctm), new ModelChiselBlock(chiselModel));
|
||||
}
|
||||
}
|
||||
|
||||
public static void register(TextureSpriteCallback callback) {
|
||||
public static void register(TextureSpriteCallback callback)
|
||||
{
|
||||
textures.add(callback);
|
||||
}
|
||||
|
||||
@@ -53,8 +71,8 @@ public class TextureStitcher {
|
||||
{
|
||||
TextureSpriteCallback[] callbacks = new TextureSpriteCallback[CTM.REQUIRED_TEXTURES];
|
||||
|
||||
callbacks[0] = new TextureSpriteCallback(new ResourceLocation("mekanism:textures/blocks/ctm/" + name));
|
||||
callbacks[1] = new TextureSpriteCallback(new ResourceLocation("mekanism:textures/blocks/ctm/" + name + "-ctm"));
|
||||
callbacks[0] = new TextureSpriteCallback(new ResourceLocation("mekanism:blocks/ctm/" + name));
|
||||
callbacks[1] = new TextureSpriteCallback(new ResourceLocation("mekanism:blocks/ctm/" + name + "-ctm"));
|
||||
|
||||
register(callbacks[0]);
|
||||
register(callbacks[1]);
|
||||
@@ -66,7 +84,7 @@ public class TextureStitcher {
|
||||
{
|
||||
ChiselFace face = new ChiselFace();
|
||||
|
||||
face.addTexture(createTexture(name));
|
||||
face.addTexture(textureCache.get(name));
|
||||
face.setLayer(EnumWorldBlockLayer.SOLID);
|
||||
|
||||
return face;
|
||||
|
||||
Reference in new issue
Block a user