Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ buildscript {
}
plugins {
id 'net.franz-becker.gradle-lombok' version '1.5'
id 'com.matthewprenger.cursegradle' version '1.0.9'
id 'com.matthewprenger.cursegradle' version '1.4.0'
}

apply plugin: 'net.minecraftforge.gradle.forge'
Expand Down Expand Up @@ -75,6 +75,9 @@ eclipse.classpath.file {
}
}

compileJava.options.encoding = 'UTF-8'
javadoc.options.encoding = 'UTF-8'

tasks.eclipse.dependsOn installLombok

processResources {
Expand Down Expand Up @@ -170,11 +173,9 @@ curseforge {
changelog = System.getenv('CHANGELOG') == null || System.getenv('CHANGELOG').equals('none') ? getChangelogText() : System.getenv('CHANGELOG')
changelogType = 'html'
releaseType = project.curse_type
addGameVersion '1.12.1'
addGameVersion '1.12.2'
mainArtifact(jar) {
displayName = "CTM - ${version}"
}
addArtifact(apiJar)
}
}
24 changes: 24 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
1.0.2:
Fixes
- #115 Fix CTM models using the no-layer cache on the incorrect model, should fix the iChisel's preview mode

1.0.1:
Changes
- If no layer is specified, the default will now be null (same as textures with no metadata) rather than SOLID
- Now requires forge 2807 at a minimum (for item lighting fixes)
Fixes
- Eliminated unnecessary memory overhead from model loading (asiekierka)
- Fix ctm models having duplicate quads when rendered as an item and containing null-layer quads
- Cache quad subsets for no-layer cases a bit, should speed up item model rendering marginally

1.0.0:
New
- Added 'use_actual_state' flag to allow connected textures to compare contextual states (such as glass panes)
Changes
- Remove deprecated APIs
Fixes
- Fix models with CTM overrides not inheriting from texture data
- Fix disableCTM config not doing anything
- Fix CTM models not working properly with forge blockstate features (retexture, uvlock, etc.)
- #89 Fix CTM models not considering item overrides

0.3.3:
New
- Models with light data will now render properly in item form. NOTE: This requires Forge 2781 or higher!
Expand Down
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
mod_version=0.4.0
mod_version=1.0.2
minecraft_version=1.12.2
forge_version=14.23.4.2705
forge_version=14.23.5.2807

curse_type=beta
curse_type=release
projectId=267602
github_project=Chisel-Team/ConnectedTexturesMod
3 changes: 2 additions & 1 deletion src/main/java/team/chisel/ctm/CTM.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import team.chisel.ctm.client.util.CTMPackReloadListener;
import team.chisel.ctm.client.util.TextureMetadataHandler;

@Mod(name = MOD_NAME, modid = MOD_ID, version = VERSION, dependencies = "before:chisel;after:forge@[14.23,)", clientSideOnly = true)
@Mod(name = MOD_NAME, modid = MOD_ID, version = VERSION, dependencies = "before:chisel;after:forge@[14.23.5.2807,)", clientSideOnly = true)
public class CTM {

public static final String MOD_ID = "ctm";
Expand All @@ -38,6 +38,7 @@ public void preInit(FMLPreInitializationEvent event) {
TextureTypeRegistry.preInit(event);

ModelLoaderRegistry.registerLoader(ModelLoaderCTM.INSTANCE);
MinecraftForge.EVENT_BUS.register(ModelLoaderCTM.INSTANCE);
Minecraft.getMinecraft().metadataSerializer_.registerMetadataSectionType(new IMetadataSectionCTM.Serializer(), IMetadataSectionCTM.class);

MinecraftForge.EVENT_BUS.register(TextureMetadataHandler.INSTANCE);
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/team/chisel/ctm/Configurations.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
package team.chisel.ctm;

import net.minecraft.client.Minecraft;
import net.minecraftforge.common.config.Config;
import net.minecraftforge.common.config.Config.Type;
import net.minecraftforge.common.config.ConfigManager;
import net.minecraftforge.fml.client.event.ConfigChangedEvent;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import team.chisel.ctm.client.model.AbstractCTMBakedModel;

@Config(modid = CTM.MOD_ID)
@EventBusSubscriber(modid = CTM.MOD_ID)
public class Configurations {

@Config.Comment("Disable connected textures entirely.")
Expand All @@ -11,4 +19,12 @@ public class Configurations {
@Config.Comment("Choose whether the inside corner is disconnected on a CTM block - http://imgur.com/eUywLZ4")
public static boolean connectInsideCTM = false;

@SubscribeEvent
public static void onConfigChange(ConfigChangedEvent event) {
if (event.getModID().equals(CTM.MOD_ID)) {
ConfigManager.sync(CTM.MOD_ID, Type.INSTANCE);
AbstractCTMBakedModel.invalidateCaches();
Minecraft.getMinecraft().renderGlobal.loadRenderers();
}
}
}
2 changes: 1 addition & 1 deletion src/main/java/team/chisel/ctm/api/IFacade.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public interface IFacade {
* The Blocks position
* @param side
* The side being rendered, NOT the side being connected from.
* <p/>
* <p>
* This value can be null if no side is specified. Please handle this appropriately.
* @param connection
* The position of the block being connected to.
Expand Down
19 changes: 18 additions & 1 deletion src/main/java/team/chisel/ctm/api/model/IModelCTM.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,35 @@
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.client.model.IModel;
import team.chisel.ctm.api.texture.ICTMTexture;
import team.chisel.ctm.api.texture.IChiselFace;

public interface IModelCTM extends IModel {

IModel getVanillaParent();

void load();

Collection<ICTMTexture<?>> getCTMTextures();
@Deprecated
Collection<ICTMTexture<?>> getChiselTextures();

default Collection<ICTMTexture<?>> getCTMTextures() {
return getChiselTextures();
}

ICTMTexture<?> getTexture(String iconName);

@Deprecated
default IChiselFace getFace(EnumFacing facing) {
return null;
}

@Deprecated
default IChiselFace getDefaultFace() {
return null;
}

boolean canRenderInLayer(IBlockState state, BlockRenderLayer layer);

Expand Down
11 changes: 6 additions & 5 deletions src/main/java/team/chisel/ctm/api/texture/ICTMTexture.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,12 @@ public interface ICTMTexture<T extends ITextureType> {

/**
* The layer this texture requires. The layers will be prioritized for a face in the order:
* <p>
* {@link BlockRenderLayer#TRANSLUCENT}<br/>
* {@link BlockRenderLayer#CUTOUT}<br/>
* {@link BlockRenderLayer#SOLID}<br/>
*
* <ul>
* <li>{@link BlockRenderLayer#TRANSLUCENT}</li>
* <li>{@link BlockRenderLayer#CUTOUT}</li>
* <li>{@link BlockRenderLayer#SOLID}</li>
* </ul>
*
* @return The layer of this texture.
*/
@Nullable
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/team/chisel/ctm/api/texture/IChiselFace.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package team.chisel.ctm.api.texture;

import java.util.List;

import javax.annotation.Nonnull;

import net.minecraft.client.renderer.texture.TextureAtlasSprite;

@Deprecated
public interface IChiselFace {

List<ICTMTexture<?>> getTextureList();

@Nonnull TextureAtlasSprite getParticle();
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package team.chisel.ctm.client.model;

import java.util.Collection;
import java.util.EnumMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import java.util.stream.Collectors;

import javax.annotation.Nonnull;
Expand All @@ -15,6 +18,7 @@

import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ListMultimap;
import com.google.common.collect.Lists;
Expand Down Expand Up @@ -44,11 +48,14 @@
import net.minecraft.item.ItemStack;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import net.minecraftforge.client.MinecraftForgeClient;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.common.model.TRSRTransformation;
import team.chisel.ctm.api.model.IModelCTM;
import team.chisel.ctm.api.texture.ICTMTexture;
import team.chisel.ctm.api.texture.IChiselFace;
import team.chisel.ctm.api.util.RenderContextList;
import team.chisel.ctm.client.asm.CTMCoreMethods;
import team.chisel.ctm.client.state.CTMExtendedState;
Expand Down Expand Up @@ -81,6 +88,16 @@ public IBakedModel handleItemState(IBakedModel originalModel, ItemStack stack, W
block = ((ItemBlock) stack.getItem()).getBlock();
}
final IBlockState state = block == null ? null : block.getDefaultState();
if (!stack.isEmpty() && stack.getItem().hasCustomProperties()) { // Handle parent model's overrides
@SuppressWarnings("deprecation") // Duplicate super logic, but called on the parent model overrides
ResourceLocation location = parent.getOverrides().applyOverride(stack, world, entity);
if (location != null) {
// Use the override's location as cache key
ModelResourceLocation overrideLoc = ModelLoader.getInventoryVariant(location.toString());
IBakedModel newParent = Minecraft.getMinecraft().getRenderItem().getItemModelMesher().getModelManager().getModel(overrideLoc);
return itemcache.get(overrideLoc, () -> withNewParent(newParent).createModel(state, model, null, 0));
}
}
ModelResourceLocation mrl = ModelUtil.getMesh(stack);
if (mrl == null) {
// this must be a missing/invalid model
Expand Down Expand Up @@ -145,6 +162,9 @@ public int hashCode() {

protected final ListMultimap<BlockRenderLayer, BakedQuad> genQuads = MultimapBuilder.enumKeys(BlockRenderLayer.class).arrayListValues().build();
protected final Table<BlockRenderLayer, EnumFacing, List<BakedQuad>> faceQuads = Tables.newCustomTable(Maps.newEnumMap(BlockRenderLayer.class), () -> Maps.newEnumMap(EnumFacing.class));

private final EnumMap<EnumFacing, ImmutableList<BakedQuad>> noLayerCache = new EnumMap<>(EnumFacing.class);
private ImmutableList<BakedQuad> noSideNoLayerCache;

@Override
@SneakyThrows
Expand All @@ -163,7 +183,7 @@ public int hashCode() {
if (Minecraft.getMinecraft().world != null && state instanceof CTMExtendedState) {
ProfileUtil.start("state_creation");
CTMExtendedState ext = (CTMExtendedState) state;
RenderContextList ctxList = ext.getContextList(ext.getClean(), model);
RenderContextList ctxList = ext.getContextList(ext.getClean(), baked);

Object2LongMap<ICTMTexture<?>> serialized = ctxList.serialized();
ProfileUtil.endAndStart("model_creation");
Expand All @@ -180,11 +200,22 @@ public int hashCode() {
if (side != null && layer != null) {
ret = baked.faceQuads.get(layer, side);
} else if (side != null) {
ret = baked.faceQuads.column(side).values().stream().flatMap(List::stream).collect(Collectors.toList());
final AbstractCTMBakedModel _baked = baked;
ret = baked.noLayerCache.computeIfAbsent(side, f -> ImmutableList.copyOf(_baked.faceQuads.column(f).values()
.stream()
.flatMap(List::stream)
.distinct()
.collect(Collectors.toList())));
} else if (layer != null) {
ret = baked.genQuads.get(layer);
} else {
ret = Lists.newArrayList(baked.genQuads.values());
ret = baked.noSideNoLayerCache;
if (ret == null) {
ret = baked.noSideNoLayerCache = ImmutableList.copyOf(baked.genQuads.values()
.stream()
.distinct()
.collect(Collectors.toList()));
}
}
ProfileUtil.end();

Expand Down Expand Up @@ -223,9 +254,11 @@ public boolean isBuiltInRenderer() {
return false;
}

@SuppressWarnings("deprecation")
@Override
public @Nonnull TextureAtlasSprite getParticleTexture() {
return this.parent.getParticleTexture();
IChiselFace face = this.model.getDefaultFace();
return face != null ? face.getParticle() : this.parent.getParticleTexture();
}

@Override
Expand Down Expand Up @@ -261,5 +294,49 @@ public Pair<? extends IBakedModel, Matrix4f> handlePerspective(ItemCameraTransfo
protected static final BlockRenderLayer[] LAYERS = BlockRenderLayer.values();

protected abstract AbstractCTMBakedModel createModel(IBlockState state, @Nonnull IModelCTM model, RenderContextList ctx, long rand);

protected /* abstract */ AbstractCTMBakedModel withNewParent(@Nonnull IBakedModel parent) {
return new ModelBakedCTM(getModel(), parent);
}

private <T> T applyToParent(long rand, Function<AbstractCTMBakedModel, T> func) {
IBakedModel parent = getParent(rand);
if (parent instanceof AbstractCTMBakedModel) {
return func.apply((AbstractCTMBakedModel) parent);
}
return null;
}

protected ICTMTexture<?> getOverrideTexture(long rand, int tintIndex, String iconName) {
ICTMTexture<?> ret = getModel().getOverrideTexture(tintIndex, iconName);
if (ret == null) {
ret = applyToParent(rand, parent -> parent.getOverrideTexture(rand, tintIndex, iconName));
}
return ret;
}

protected ICTMTexture<?> getTexture(long rand, String iconName) {
ICTMTexture<?> ret = getModel().getTexture(iconName);
if (ret == null) {
ret = applyToParent(rand, parent -> parent.getTexture(rand, iconName));
}
return ret;
}

protected TextureAtlasSprite getOverrideSprite(long rand, int tintIndex) {
TextureAtlasSprite ret = getModel().getOverrideSprite(tintIndex);
if (ret == null) {
ret = applyToParent(rand, parent -> parent.getOverrideSprite(rand, tintIndex));
}
return ret;
}

public Collection<ICTMTexture<?>> getCTMTextures() {
ImmutableList.Builder<ICTMTexture<?>> builder = ImmutableList.builder();
builder.addAll(getModel().getCTMTextures());
if (getParent() instanceof AbstractCTMBakedModel) {
builder.addAll(((AbstractCTMBakedModel)getParent()).getCTMTextures());
}
return builder.build();
}
}
8 changes: 4 additions & 4 deletions src/main/java/team/chisel/ctm/client/model/ModelBakedCTM.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ protected AbstractCTMBakedModel createModel(@Nullable IBlockState state, IModelC
// Gather all quads and map them to their textures
// All quads should have an associated ICTMTexture, so ignore any that do not
for (BakedQuad q : parentQuads) {
ICTMTexture<?> tex = this.getModel().getOverrideTexture(q.getTintIndex(), q.getSprite().getIconName());
ICTMTexture<?> tex = this.getOverrideTexture(rand, q.getTintIndex(), q.getSprite().getIconName());
if (tex == null) {
tex = this.getModel().getTexture(q.getSprite().getIconName());
tex = this.getTexture(rand, q.getSprite().getIconName());
}

if (tex != null) {
TextureAtlasSprite spriteReplacement = getModel().getOverrideSprite(q.getTintIndex());
TextureAtlasSprite spriteReplacement = this.getOverrideSprite(rand, q.getTintIndex());
if (spriteReplacement != null) {
q = new BakedQuadRetextured(q, spriteReplacement);
}
Expand All @@ -91,7 +91,7 @@ protected AbstractCTMBakedModel createModel(@Nullable IBlockState state, IModelC
}
return ret;
}

@Override
public @Nonnull TextureAtlasSprite getParticleTexture() {
return Optional.ofNullable(getModel().getTexture(getParent().getParticleTexture().getIconName()))
Expand Down
Loading