Cut it out

- Remove CutoutPartial
- Set render_type in models than need cutout
- Fix TrackVisual going invisible when renderers reload
- Fix TrackVisual not getting re-lit in some cases
- Bump flywheel version
This commit is contained in:
Jozufozu 2024-03-23 14:13:53 -05:00
parent 42b1e19fc8
commit 26074dc3df
9 changed files with 71 additions and 168 deletions

View file

@ -23,7 +23,7 @@ use_parchment = true
# dependency versions
registrate_version = MC1.20-1.3.3
flywheel_minecraft_version = 1.20.1
flywheel_version = 1.0.0-alpha-66
flywheel_version = 1.0.0-alpha-67
jei_minecraft_version = 1.20.1
jei_version = 15.2.0.22
curios_minecraft_version = 1.20.1

View file

@ -8,7 +8,6 @@ import java.util.Map;
import com.jozufozu.flywheel.lib.model.baked.PartialModel;
import com.simibubi.create.content.fluids.FluidTransportBehaviour;
import com.simibubi.create.foundation.render.CutoutPartial;
import com.simibubi.create.foundation.utility.Couple;
import com.simibubi.create.foundation.utility.Iterate;
import com.simibubi.create.foundation.utility.Lang;
@ -36,7 +35,7 @@ public class AllPartialModels {
ANDESITE_BELT_COVER_Z = block("belt_cover/andesite_belt_cover_z"),
BRASS_BELT_COVER_Z = block("belt_cover/brass_belt_cover_z"),
ENCASED_FAN_INNER = cutoutBlock("encased_fan/propeller"), HAND_CRANK_HANDLE = block("hand_crank/handle"),
ENCASED_FAN_INNER = block("encased_fan/propeller"), HAND_CRANK_HANDLE = block("hand_crank/handle"),
MECHANICAL_PRESS_HEAD = block("mechanical_press/head"), MECHANICAL_MIXER_POLE = block("mechanical_mixer/pole"),
MECHANICAL_MIXER_HEAD = block("mechanical_mixer/head"),
MECHANICAL_CRAFTER_LID = block("mechanical_crafter/lid"),
@ -52,7 +51,7 @@ public class AllPartialModels {
GAUGE_INDICATOR = block("gauge/indicator"), GAUGE_HEAD_SPEED = block("gauge/speedometer/head"),
GAUGE_HEAD_STRESS = block("gauge/stressometer/head"), BEARING_TOP = block("bearing/top"),
BEARING_TOP_WOODEN = block("bearing/top_wooden"), DRILL_HEAD = block("mechanical_drill/head"),
HARVESTER_BLADE = cutoutBlock("mechanical_harvester/blade"), DEPLOYER_POLE = block("deployer/pole"),
HARVESTER_BLADE = block("mechanical_harvester/blade"), DEPLOYER_POLE = block("deployer/pole"),
DEPLOYER_HAND_POINTING = block("deployer/hand_pointing"),
DEPLOYER_HAND_PUNCHING = block("deployer/hand_punching"),
DEPLOYER_HAND_HOLDING = block("deployer/hand_holding"), ANALOG_LEVER_HANDLE = block("analog_lever/handle"),
@ -204,7 +203,7 @@ public class AllPartialModels {
PIPE_ATTACHMENTS.put(type, map);
}
for (DyeColor color : DyeColor.values())
TOOLBOX_LIDS.put(color, cutoutBlock("toolbox/lid/" + Lang.asId(color.name())));
TOOLBOX_LIDS.put(color, block("toolbox/lid/" + Lang.asId(color.name())));
for (Direction d : Iterate.horizontalDirections)
METAL_GIRDER_BRACKETS.put(d, block("metal_girder/bracket_" + Lang.asId(d.name())));
for (int i = 0; i < 8; i++)
@ -223,10 +222,6 @@ public class AllPartialModels {
return new PartialModel(Create.asResource("block/" + path));
}
private static PartialModel cutoutBlock(String path) {
return new CutoutPartial(Create.asResource("block/" + path));
}
private static PartialModel entity(String path) {
return new PartialModel(Create.asResource("entity/" + path));
}

View file

@ -1,16 +1,14 @@
package com.simibubi.create.content.trains.track;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.function.Consumer;
import java.util.function.LongConsumer;
import javax.annotation.Nullable;
import com.jozufozu.flywheel.api.instance.Instance;
import com.jozufozu.flywheel.api.visualization.VisualizationContext;
import com.jozufozu.flywheel.lib.box.Box;
import com.jozufozu.flywheel.lib.box.MutableBox;
import com.jozufozu.flywheel.lib.instance.InstanceTypes;
import com.jozufozu.flywheel.lib.instance.TransformedInstance;
import com.jozufozu.flywheel.lib.model.Models;
@ -25,6 +23,7 @@ import com.simibubi.create.foundation.utility.Couple;
import com.simibubi.create.foundation.utility.Iterate;
import net.minecraft.core.BlockPos;
import net.minecraft.core.SectionPos;
public class TrackVisual extends AbstractBlockEntityVisual<TrackBlockEntity> {
@ -34,24 +33,25 @@ public class TrackVisual extends AbstractBlockEntityVisual<TrackBlockEntity> {
super(context, track);
}
@Override
public void init(float partialTick) {
visuals = blockEntity.connections.values()
.stream()
.map(this::createInstance)
.filter(Objects::nonNull)
.toList();
super.init(partialTick);
}
@Override
public void update(float pt) {
if (blockEntity.connections.isEmpty())
return;
_delete();
visuals = blockEntity.connections.values()
.stream()
.map(this::createInstance)
.filter(Objects::nonNull)
.toList();
}
public Box getVolume() {
List<BlockPos> out = new ArrayList<>();
out.addAll(blockEntity.connections.keySet());
out.addAll(blockEntity.connections.keySet());
return MutableBox.containingAll(out);
init(pt);
notifier.notifySectionsChanged();
}
@Override
@ -75,6 +75,30 @@ public class TrackVisual extends AbstractBlockEntityVisual<TrackBlockEntity> {
visuals.forEach(BezierTrackVisual::delete);
}
@Override
public void collectLightSections(LongConsumer consumer) {
if (blockEntity.connections.isEmpty()) {
return;
}
int minX = Integer.MAX_VALUE;
int minY = Integer.MAX_VALUE;
int minZ = Integer.MAX_VALUE;
int maxX = Integer.MIN_VALUE;
int maxY = Integer.MIN_VALUE;
int maxZ = Integer.MIN_VALUE;
for (BlockPos pos : blockEntity.connections.keySet()) {
minX = Math.min(minX, pos.getX());
minY = Math.min(minY, pos.getY());
minZ = Math.min(minZ, pos.getZ());
maxX = Math.max(maxX, pos.getX());
maxY = Math.max(maxY, pos.getY());
maxZ = Math.max(maxZ, pos.getZ());
}
SectionPos.betweenClosedStream(SectionPos.blockToSectionCoord(minX), SectionPos.blockToSectionCoord(minY), SectionPos.blockToSectionCoord(minZ), SectionPos.blockToSectionCoord(maxX), SectionPos.blockToSectionCoord(maxY), SectionPos.blockToSectionCoord(maxZ))
.mapToLong(SectionPos::asLong)
.forEach(consumer);
}
@Override
public void collectCrumblingInstances(Consumer<Instance> consumer) {
if (visuals == null)
@ -126,15 +150,15 @@ public class TrackVisual extends AbstractBlockEntityVisual<TrackBlockEntity> {
var modelIndex = i - 1;
ties[modelIndex].setTransform(pose)
.mulPose(segment.tieTransform.pose())
.mulNormal(segment.tieTransform.normal());
.transform(segment.tieTransform)
.setChanged();
tiesLightPos[modelIndex] = segment.lightPosition.offset(tePosition);
for (boolean first : Iterate.trueAndFalse) {
Pose transform = segment.railTransforms.get(first);
(first ? this.left : this.right)[modelIndex].setTransform(pose)
.mulPose(transform.pose())
.mulNormal(transform.normal());
.transform(transform)
.setChanged();
(first ? leftLightPos : rightLightPos)[modelIndex] = segment.lightPosition.offset(tePosition);
}
}
@ -155,11 +179,14 @@ public class TrackVisual extends AbstractBlockEntityVisual<TrackBlockEntity> {
void updateLight() {
for (int i = 0; i < ties.length; i++)
ties[i].updateLight(level, tiesLightPos[i]);
ties[i].updateLight(level, tiesLightPos[i])
.setChanged();
for (int i = 0; i < left.length; i++)
left[i].updateLight(level, leftLightPos[i]);
left[i].updateLight(level, leftLightPos[i])
.setChanged();
for (int i = 0; i < right.length; i++)
right[i].updateLight(level, rightLightPos[i]);
right[i].updateLight(level, rightLightPos[i])
.setChanged();
if (girder != null)
girder.updateLight();
}
@ -208,15 +235,15 @@ public class TrackVisual extends AbstractBlockEntityVisual<TrackBlockEntity> {
for (boolean first : Iterate.trueAndFalse) {
Pose beamTransform = segment.beams.get(first);
beams.get(first)[modelIndex].setTransform(pose)
.mulPose(beamTransform.pose())
.mulNormal(beamTransform.normal());
.transform(beamTransform)
.setChanged();
for (boolean top : Iterate.trueAndFalse) {
Pose beamCapTransform = segment.beamCaps.get(top)
.get(first);
beamCaps.get(top)
.get(first)[modelIndex].setTransform(pose)
.mulPose(beamCapTransform.pose())
.mulNormal(beamCapTransform.normal());
.transform(beamCapTransform)
.setChanged();
}
}
}
@ -238,11 +265,13 @@ public class TrackVisual extends AbstractBlockEntityVisual<TrackBlockEntity> {
void updateLight() {
beams.forEach(arr -> {
for (int i = 0; i < arr.length; i++)
arr[i].updateLight(level, lightPos[i]);
arr[i].updateLight(level, lightPos[i])
.setChanged();
});
beamCaps.forEach(c -> c.forEach(arr -> {
for (int i = 0; i < arr.length; i++)
arr[i].updateLight(level, lightPos[i]);
arr[i].updateLight(level, lightPos[i])
.setChanged();
}));
}

View file

@ -1,126 +0,0 @@
package com.simibubi.create.foundation.render;
import java.util.List;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import com.jozufozu.flywheel.lib.model.baked.PartialModel;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.renderer.block.model.ItemOverrides;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.resources.model.BakedModel;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.RandomSource;
import net.minecraft.world.item.ItemDisplayContext;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.BlockAndTintGetter;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraftforge.client.ChunkRenderTypeSet;
import net.minecraftforge.client.model.data.ModelData;
public class CutoutPartial extends PartialModel {
public CutoutPartial(ResourceLocation modelLocation) {
super(modelLocation);
}
@Override
protected void set(BakedModel bakedModel) {
super.set(new Wrapper(bakedModel));
}
private record Wrapper(BakedModel inner) implements BakedModel {
private static final ChunkRenderTypeSet CUTOUT = ChunkRenderTypeSet.of(RenderType.cutout());
@Override
public @NotNull List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, @NotNull RandomSource rand, @NotNull ModelData data, @Nullable RenderType renderType) {
if (renderType == null) {
return inner.getQuads(state, side, rand, data, null);
} else if (renderType == RenderType.cutout()) {
return inner.getQuads(state, side, rand, data, renderType);
} else {
return List.of();
}
}
@Override
public ChunkRenderTypeSet getRenderTypes(@NotNull BlockState state, @NotNull RandomSource rand, @NotNull ModelData data) {
return CUTOUT;
}
@Override
public List<BakedQuad> getQuads(@Nullable BlockState pState, @Nullable Direction pDirection, RandomSource pRandom) {
return inner.getQuads(pState, pDirection, pRandom);
}
@Override
public boolean useAmbientOcclusion(BlockState state) {
return inner.useAmbientOcclusion(state);
}
@Override
public boolean useAmbientOcclusion(BlockState state, RenderType renderType) {
return inner.useAmbientOcclusion(state, renderType);
}
@Override
public BakedModel applyTransform(ItemDisplayContext transformType, PoseStack poseStack, boolean applyLeftHandTransform) {
return inner.applyTransform(transformType, poseStack, applyLeftHandTransform);
}
@Override
public @NotNull ModelData getModelData(@NotNull BlockAndTintGetter level, @NotNull BlockPos pos, @NotNull BlockState state, @NotNull ModelData modelData) {
return inner.getModelData(level, pos, state, modelData);
}
@Override
public TextureAtlasSprite getParticleIcon(@NotNull ModelData data) {
return inner.getParticleIcon(data);
}
@Override
public List<RenderType> getRenderTypes(ItemStack itemStack, boolean fabulous) {
return inner.getRenderTypes(itemStack, fabulous);
}
@Override
public List<BakedModel> getRenderPasses(ItemStack itemStack, boolean fabulous) {
return inner.getRenderPasses(itemStack, fabulous);
}
@Override
public boolean useAmbientOcclusion() {
return inner.useAmbientOcclusion();
}
@Override
public boolean isGui3d() {
return inner.isGui3d();
}
@Override
public boolean usesBlockLight() {
return inner.usesBlockLight();
}
@Override
public boolean isCustomRenderer() {
return inner.isCustomRenderer();
}
@Override
public TextureAtlasSprite getParticleIcon() {
return inner.getParticleIcon();
}
@Override
public ItemOverrides getOverrides() {
return inner.getOverrides();
}
}
}

View file

@ -5,6 +5,7 @@
"fan_blades": "create:block/fan_blades",
"axis": "create:block/axis"
},
"render_type": "minecraft:cutout",
"elements": [
{
"name": "Shaft",

View file

@ -5,6 +5,7 @@
"anvil": "minecraft:block/anvil",
"andesite_casing_short": "create:block/andesite_casing_short"
},
"render_type": "minecraft:cutout",
"elements": [
{
"name": "Wheel",

View file

@ -5,7 +5,8 @@
"textures": {
"6": "create:block/mixer_head"
},
"elements": [
"render_type": "minecraft:cutout",
"elements": [
{
"name": "MixerCenter",
"from": [7, -4, 7],

View file

@ -5,7 +5,8 @@
"0": "create:block/toolbox/brown",
"particle": "block/dark_oak_planks"
},
"elements": [
"render_type": "minecraft:cutout",
"elements": [
{
"from": [1, 6, 4],
"to": [15, 9, 12],

View file

@ -2,5 +2,6 @@
"parent": "create:block/track/obj_track",
"loader": "forge:obj",
"flip_v": true,
"render_type": "minecraft:cutout_mipped",
"model": "create:models/block/track/tie.obj"
}