-
Notifications
You must be signed in to change notification settings - Fork 20
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
18 changed files
with
289 additions
and
233 deletions.
There are no files selected for viewing
5 changes: 3 additions & 2 deletions
5
src/main/java/com/fusionflux/portalcubed/accessor/BakedQuadExt.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,10 +1,11 @@ | ||
package com.fusionflux.portalcubed.accessor; | ||
|
||
import net.fabricmc.fabric.api.renderer.v1.material.RenderMaterial; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public interface BakedQuadExt { | ||
@Nullable | ||
String portalcubed$getRenderType(); | ||
RenderMaterial portalcubed$getRenderMaterial(); | ||
|
||
void portalcubed$setRenderType(String type); | ||
void portalcubed$setRenderMaterial(RenderMaterial material); | ||
} |
10 changes: 8 additions & 2 deletions
10
src/main/java/com/fusionflux/portalcubed/accessor/BlockElementExt.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,10 +1,16 @@ | ||
package com.fusionflux.portalcubed.accessor; | ||
|
||
import net.fabricmc.fabric.api.renderer.v1.material.RenderMaterial; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public interface BlockElementExt { | ||
@Nullable | ||
String portalcubed$getRenderType(); | ||
String portalcubed$getName(); | ||
|
||
void portalcubed$setRenderType(String type); | ||
void portalcubed$setName(String name); | ||
|
||
@Nullable | ||
RenderMaterial portalcubed$getRenderMaterial(); | ||
|
||
void portalcubed$setRenderMaterial(RenderMaterial material); | ||
} |
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
36 changes: 0 additions & 36 deletions
36
src/main/java/com/fusionflux/portalcubed/client/render/block/RenderMaterials.java
This file was deleted.
Oops, something went wrong.
66 changes: 0 additions & 66 deletions
66
src/main/java/com/fusionflux/portalcubed/client/render/block/entity/QuadrantModel.java
This file was deleted.
Oops, something went wrong.
51 changes: 51 additions & 0 deletions
51
...n/java/com/fusionflux/portalcubed/client/render/models/PortalCubedModelLoadingPlugin.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,51 @@ | ||
package com.fusionflux.portalcubed.client.render.models; | ||
|
||
import com.fusionflux.portalcubed.accessor.BlockElementExt; | ||
import com.fusionflux.portalcubed.client.render.models.rendertype.MultiRenderTypeUnbakedModel; | ||
import net.fabricmc.fabric.api.client.model.loading.v1.ModelLoadingPlugin; | ||
import net.fabricmc.fabric.api.client.model.loading.v1.ModelModifier; | ||
import net.fabricmc.fabric.api.client.model.loading.v1.ModelModifier.BeforeBake; | ||
import net.fabricmc.fabric.api.event.Event; | ||
import net.fabricmc.fabric.api.renderer.v1.material.RenderMaterial; | ||
|
||
import net.minecraft.client.renderer.block.model.BlockElement; | ||
import net.minecraft.client.renderer.block.model.BlockModel; | ||
import net.minecraft.client.resources.model.UnbakedModel; | ||
|
||
public enum PortalCubedModelLoadingPlugin implements ModelLoadingPlugin { | ||
INSTANCE; | ||
|
||
@Override | ||
public void onInitializeModelLoader(Context ctx) { | ||
Event<BeforeBake> beforeBake = ctx.modifyModelBeforeBake(); | ||
beforeBake.register(ModelModifier.WRAP_PHASE, MultiRenderTypeWrapper.INSTANCE); | ||
beforeBake.register(ModelModifier.WRAP_PHASE, EmissiveWrapper.INSTANCE); | ||
} | ||
|
||
private enum MultiRenderTypeWrapper implements BeforeBake { | ||
INSTANCE; | ||
|
||
@Override | ||
public UnbakedModel modifyModelBeforeBake(UnbakedModel model, Context context) { | ||
if (model instanceof BlockModel blockModel) { | ||
for (BlockElement element : blockModel.getElements()) { | ||
RenderMaterial material = ((BlockElementExt) element).portalcubed$getRenderMaterial(); | ||
if (material != null) { | ||
return new MultiRenderTypeUnbakedModel(blockModel); | ||
} | ||
} | ||
} | ||
|
||
return model; | ||
} | ||
} | ||
|
||
private enum EmissiveWrapper implements BeforeBake { | ||
INSTANCE; | ||
|
||
@Override | ||
public UnbakedModel modifyModelBeforeBake(UnbakedModel model, Context context) { | ||
return model; | ||
} | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
src/main/java/com/fusionflux/portalcubed/client/render/models/RenderMaterials.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,77 @@ | ||
package com.fusionflux.portalcubed.client.render.models; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import com.fusionflux.portalcubed.PortalCubed; | ||
import com.google.gson.JsonParseException; | ||
import net.fabricmc.fabric.api.renderer.v1.Renderer; | ||
import net.fabricmc.fabric.api.renderer.v1.RendererAccess; | ||
import net.fabricmc.fabric.api.renderer.v1.material.BlendMode; | ||
import net.fabricmc.fabric.api.renderer.v1.material.MaterialFinder; | ||
import net.fabricmc.fabric.api.renderer.v1.material.RenderMaterial; | ||
import net.fabricmc.fabric.api.util.TriState; | ||
|
||
public class RenderMaterials { | ||
private static final Renderer renderer = RendererAccess.INSTANCE.getRenderer(); | ||
private static final MaterialFinder finder = renderer == null ? null : renderer.materialFinder(); | ||
|
||
public static final boolean ARE_SUPPORTED = checkSupport(); | ||
|
||
public static final Map<String, RenderMaterial> BY_NAME = new HashMap<>(); | ||
|
||
public static final RenderMaterial DEFAULT = makeMaterial("default", BlendMode.DEFAULT, false); | ||
public static final RenderMaterial SOLID = makeMaterial("solid", BlendMode.SOLID, false); | ||
public static final RenderMaterial CUTOUT = makeMaterial("cutout", BlendMode.CUTOUT, false); | ||
public static final RenderMaterial CUTOUT_MIPPED = makeMaterial("cutout_mipped", BlendMode.CUTOUT_MIPPED, false); | ||
public static final RenderMaterial TRANSLUCENT = makeMaterial("translucent", BlendMode.TRANSLUCENT, false); | ||
|
||
public static final RenderMaterial DEFAULT_EMISSIVE = makeMaterial("default_emissive", BlendMode.DEFAULT, true); | ||
public static final RenderMaterial SOLID_EMISSIVE = makeMaterial("solid_emissive", BlendMode.SOLID, true); | ||
public static final RenderMaterial CUTOUT_EMISSIVE = makeMaterial("cutout_emissive", BlendMode.CUTOUT, true); | ||
public static final RenderMaterial CUTOUT_MIPPED_EMISSIVE = makeMaterial("cutout_mipped_emissive", BlendMode.CUTOUT_MIPPED, true); | ||
public static final RenderMaterial TRANSLUCENT_EMISSIVE = makeMaterial("translucent_emissive", BlendMode.TRANSLUCENT, true); | ||
|
||
public static final String SUPPORTED_TYPES = String.join(", ", BY_NAME.keySet()); | ||
|
||
public static RenderMaterial get(BlendMode mode, boolean emissive) { | ||
return switch (mode) { | ||
case DEFAULT -> emissive ? DEFAULT_EMISSIVE : DEFAULT; | ||
case SOLID -> emissive ? SOLID_EMISSIVE : SOLID; | ||
case CUTOUT -> emissive ? CUTOUT_EMISSIVE : CUTOUT; | ||
case CUTOUT_MIPPED -> emissive ? CUTOUT_MIPPED_EMISSIVE : CUTOUT_MIPPED; | ||
case TRANSLUCENT -> emissive ? TRANSLUCENT_EMISSIVE : TRANSLUCENT; | ||
}; | ||
} | ||
|
||
public static RenderMaterial parse(String name) { | ||
RenderMaterial material = BY_NAME.get(name); | ||
if (material == null) { | ||
throw new JsonParseException("Invalid render material \"" + name + "\"; must be one of: " + SUPPORTED_TYPES); | ||
} | ||
return material; | ||
} | ||
|
||
private static RenderMaterial makeMaterial(String name, BlendMode mode, boolean emissive) { | ||
if (finder == null) | ||
return null; | ||
|
||
finder.clear().blendMode(mode); | ||
if (emissive) { | ||
finder.emissive(true) | ||
.disableDiffuse(true) | ||
.ambientOcclusion(TriState.FALSE); | ||
} | ||
RenderMaterial material = finder.find(); | ||
BY_NAME.put(name, material); | ||
return material; | ||
} | ||
|
||
private static boolean checkSupport() { | ||
if (renderer == null) { | ||
PortalCubed.LOGGER.error("No renderer present, rendering will be wrong. If you have Sodium, install Indium!"); | ||
return false; | ||
} | ||
return true; | ||
} | ||
} |
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
Oops, something went wrong.