-
Notifications
You must be signed in to change notification settings - Fork 913
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Flywheel visuals for bogey block entities
- Loading branch information
1 parent
1935b79
commit d48a504
Showing
9 changed files
with
179 additions
and
40 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
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
95 changes: 95 additions & 0 deletions
95
src/main/java/com/simibubi/create/content/trains/bogey/BogeyBlockEntityVisual.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,95 @@ | ||
package com.simibubi.create.content.trains.bogey; | ||
|
||
import java.util.function.Consumer; | ||
|
||
import org.jetbrains.annotations.Nullable; | ||
|
||
import com.mojang.blaze3d.vertex.PoseStack; | ||
import com.mojang.math.Axis; | ||
import com.simibubi.create.content.trains.bogey.BogeySizes.BogeySize; | ||
|
||
import dev.engine_room.flywheel.api.instance.Instance; | ||
import dev.engine_room.flywheel.api.visualization.VisualizationContext; | ||
import dev.engine_room.flywheel.lib.visual.AbstractBlockEntityVisual; | ||
import dev.engine_room.flywheel.lib.visual.SimpleDynamicVisual; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.core.Direction; | ||
import net.minecraft.nbt.CompoundTag; | ||
|
||
public class BogeyBlockEntityVisual extends AbstractBlockEntityVisual<AbstractBogeyBlockEntity> implements SimpleDynamicVisual { | ||
private final PoseStack poseStack = new PoseStack(); | ||
|
||
@Nullable | ||
private final BogeySize bogeySize; | ||
private BogeyStyle lastStyle; | ||
@Nullable | ||
private BogeyVisual bogey; | ||
|
||
public BogeyBlockEntityVisual(VisualizationContext ctx, AbstractBogeyBlockEntity blockEntity, float partialTick) { | ||
super(ctx, blockEntity, partialTick); | ||
|
||
lastStyle = blockEntity.getStyle(); | ||
|
||
if (!(blockState.getBlock() instanceof AbstractBogeyBlock<?> block)) { | ||
bogeySize = null; | ||
return; | ||
} | ||
|
||
bogeySize = block.getSize(); | ||
|
||
BlockPos visualPos = getVisualPosition(); | ||
poseStack.translate(visualPos.getX(), visualPos.getY(), visualPos.getZ()); | ||
poseStack.translate(.5f, .5f, .5f); | ||
if (blockState.getValue(AbstractBogeyBlock.AXIS) == Direction.Axis.X) | ||
poseStack.mulPose(Axis.YP.rotationDegrees(90)); | ||
poseStack.translate(0, -1.5 - 1 / 128f, 0); | ||
|
||
bogey = lastStyle.createVisual(bogeySize, visualizationContext, partialTick, false); | ||
} | ||
|
||
@Override | ||
public void beginFrame(Context context) { | ||
if (bogeySize == null) { | ||
return; | ||
} | ||
|
||
BogeyStyle style = blockEntity.getStyle(); | ||
if (style != lastStyle) { | ||
if (bogey != null) { | ||
bogey.delete(); | ||
bogey = null; | ||
} | ||
lastStyle = style; | ||
bogey = lastStyle.createVisual(bogeySize, visualizationContext, context.partialTick(), false); | ||
} | ||
|
||
if (bogey == null) { | ||
return; | ||
} | ||
|
||
CompoundTag bogeyData = blockEntity.getBogeyData(); | ||
float angle = blockEntity.getVirtualAngle(context.partialTick()); | ||
bogey.update(bogeyData, angle, poseStack); | ||
} | ||
|
||
@Override | ||
public void collectCrumblingInstances(Consumer<@Nullable Instance> consumer) { | ||
if (bogey != null) { | ||
bogey.collectCrumblingInstances(consumer); | ||
} | ||
} | ||
|
||
@Override | ||
public void updateLight(float partialTick) { | ||
if (bogey != null) { | ||
bogey.updateLight(computePackedLight()); | ||
} | ||
} | ||
|
||
@Override | ||
protected void _delete() { | ||
if (bogey != null) { | ||
bogey.delete(); | ||
} | ||
} | ||
} |
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: 10 additions & 1 deletion
11
src/main/java/com/simibubi/create/content/trains/bogey/BogeyVisual.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,13 +1,22 @@ | ||
package com.simibubi.create.content.trains.bogey; | ||
|
||
import java.util.function.Consumer; | ||
|
||
import org.jetbrains.annotations.Nullable; | ||
|
||
import com.mojang.blaze3d.vertex.PoseStack; | ||
|
||
import dev.engine_room.flywheel.api.instance.Instance; | ||
import net.minecraft.nbt.CompoundTag; | ||
|
||
public interface BogeyVisual { | ||
void update(float wheelAngle, PoseStack poseStack); | ||
void update(CompoundTag bogeyData, float wheelAngle, PoseStack poseStack); | ||
|
||
void hide(); | ||
|
||
void updateLight(int packedLight); | ||
|
||
void collectCrumblingInstances(Consumer<@Nullable Instance> consumer); | ||
|
||
void delete(); | ||
} |
4 changes: 1 addition & 3 deletions
4
src/main/java/com/simibubi/create/content/trains/bogey/BogeyVisualizer.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,8 @@ | ||
package com.simibubi.create.content.trains.bogey; | ||
|
||
import com.simibubi.create.content.trains.entity.CarriageBogey; | ||
|
||
import dev.engine_room.flywheel.api.visualization.VisualizationContext; | ||
|
||
@FunctionalInterface | ||
public interface BogeyVisualizer { | ||
BogeyVisual createVisual(VisualizationContext ctx, CarriageBogey bogey, float partialTick); | ||
BogeyVisual createVisual(VisualizationContext ctx, float partialTick, boolean inContraption); | ||
} |
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.