mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-12-26 06:57:51 +01:00
Fix up upside down rendering
This commit is contained in:
parent
1e4d5504ee
commit
122fe77afa
10 changed files with 36 additions and 23 deletions
|
@ -162,10 +162,10 @@ public abstract class AbstractBogeyBlock<T extends AbstractBogeyTileEntity> exte
|
||||||
VertexConsumer vb = buffers.getBuffer(RenderType.cutoutMipped());
|
VertexConsumer vb = buffers.getBuffer(RenderType.cutoutMipped());
|
||||||
if (bogeyData == null)
|
if (bogeyData == null)
|
||||||
bogeyData = new CompoundTag();
|
bogeyData = new CompoundTag();
|
||||||
renderer.render(upsideDown, bogeyData, wheelAngle, ms, light, vb, state == null);
|
renderer.render(bogeyData, wheelAngle, ms, light, vb, state == null);
|
||||||
CompoundTag finalBogeyData = bogeyData;
|
CompoundTag finalBogeyData = bogeyData;
|
||||||
commonRenderer.ifPresent(common ->
|
commonRenderer.ifPresent(common ->
|
||||||
common.render(upsideDown, finalBogeyData, wheelAngle, ms, light, vb, state == null));
|
common.render(finalBogeyData, wheelAngle, ms, light, vb, state == null));
|
||||||
}
|
}
|
||||||
|
|
||||||
public BogeySizes.BogeySize getSize() {
|
public BogeySizes.BogeySize getSize() {
|
||||||
|
|
|
@ -69,7 +69,7 @@ public abstract class BogeyRenderer {
|
||||||
* @param vb (Optional) Vertex Consumer used for in-world rendering
|
* @param vb (Optional) Vertex Consumer used for in-world rendering
|
||||||
*/
|
*/
|
||||||
@OnlyIn(Dist.CLIENT)
|
@OnlyIn(Dist.CLIENT)
|
||||||
public abstract void render(boolean upsideDown, CompoundTag bogeyData, float wheelAngle, PoseStack ms, int light, VertexConsumer vb, boolean inContraption);
|
public abstract void render(CompoundTag bogeyData, float wheelAngle, PoseStack ms, int light, VertexConsumer vb, boolean inContraption);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used for calling in-contraption rendering ensuring that falsey data is handled correctly
|
* Used for calling in-contraption rendering ensuring that falsey data is handled correctly
|
||||||
|
@ -79,8 +79,8 @@ public abstract class BogeyRenderer {
|
||||||
* @param ms The posestack to render to
|
* @param ms The posestack to render to
|
||||||
*/
|
*/
|
||||||
@OnlyIn(Dist.CLIENT)
|
@OnlyIn(Dist.CLIENT)
|
||||||
public void render(boolean upsideDown, CompoundTag bogeyData, float wheelAngle, PoseStack ms) {
|
public void render(CompoundTag bogeyData, float wheelAngle, PoseStack ms) {
|
||||||
this.render(upsideDown, bogeyData, wheelAngle, ms, 0, null, true);
|
this.render(bogeyData, wheelAngle, ms, 0, null, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract BogeySizes.BogeySize getSize();
|
public abstract BogeySizes.BogeySize getSize();
|
||||||
|
|
|
@ -36,7 +36,7 @@ public class StandardBogeyRenderer {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(boolean upsideDown, CompoundTag bogeyData, float wheelAngle, PoseStack ms, int light, VertexConsumer vb, boolean inContraption) {
|
public void render(CompoundTag bogeyData, float wheelAngle, PoseStack ms, int light, VertexConsumer vb, boolean inContraption) {
|
||||||
boolean inInstancedContraption = vb == null;
|
boolean inInstancedContraption = vb == null;
|
||||||
Transform<?>[] shafts = getTransformsFromBlockState(AllBlocks.SHAFT.getDefaultState()
|
Transform<?>[] shafts = getTransformsFromBlockState(AllBlocks.SHAFT.getDefaultState()
|
||||||
.setValue(ShaftBlock.AXIS, Direction.Axis.Z), ms, inInstancedContraption, 2);
|
.setValue(ShaftBlock.AXIS, Direction.Axis.Z), ms, inInstancedContraption, 2);
|
||||||
|
@ -69,7 +69,7 @@ public class StandardBogeyRenderer {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(boolean upsideDown, CompoundTag bogeyData, float wheelAngle, PoseStack ms, int light, VertexConsumer vb, boolean inContraption) {
|
public void render(CompoundTag bogeyData, float wheelAngle, PoseStack ms, int light, VertexConsumer vb, boolean inContraption) {
|
||||||
boolean inInstancedContraption = vb == null;
|
boolean inInstancedContraption = vb == null;
|
||||||
Transform<?> transform = getTransformFromPartial(BOGEY_FRAME, ms, inInstancedContraption);
|
Transform<?> transform = getTransformFromPartial(BOGEY_FRAME, ms, inInstancedContraption);
|
||||||
finalize(transform, ms, light, vb);
|
finalize(transform, ms, light, vb);
|
||||||
|
@ -107,7 +107,7 @@ public class StandardBogeyRenderer {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(boolean upsideDown, CompoundTag bogeyData, float wheelAngle, PoseStack ms, int light, VertexConsumer vb, boolean inContraption) {
|
public void render(CompoundTag bogeyData, float wheelAngle, PoseStack ms, int light, VertexConsumer vb, boolean inContraption) {
|
||||||
boolean inInstancedContraption = vb == null;
|
boolean inInstancedContraption = vb == null;
|
||||||
|
|
||||||
Transform<?>[] secondaryShafts = getTransformsFromBlockState(AllBlocks.SHAFT.getDefaultState()
|
Transform<?>[] secondaryShafts = getTransformsFromBlockState(AllBlocks.SHAFT.getDefaultState()
|
||||||
|
|
|
@ -11,7 +11,7 @@ public class BackupBogeyRenderer extends BogeyRenderer.CommonRenderer {
|
||||||
public static BackupBogeyRenderer INSTANCE = new BackupBogeyRenderer();
|
public static BackupBogeyRenderer INSTANCE = new BackupBogeyRenderer();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(boolean upsideDown, CompoundTag bogeyData, float wheelAngle, PoseStack ms, int light, VertexConsumer vb, boolean inContraption) {
|
public void render(CompoundTag bogeyData, float wheelAngle, PoseStack ms, int light, VertexConsumer vb, boolean inContraption) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -46,8 +46,8 @@ public final class BogeyInstance {
|
||||||
}
|
}
|
||||||
|
|
||||||
commonRenderer.ifPresent(bogeyRenderer ->
|
commonRenderer.ifPresent(bogeyRenderer ->
|
||||||
bogeyRenderer.render(bogey.isUpsideDown(), bogey.bogeyData, wheelAngle, ms));
|
bogeyRenderer.render(bogey.bogeyData, wheelAngle, ms));
|
||||||
renderer.render(bogey.isUpsideDown(), bogey.bogeyData, wheelAngle, ms);
|
renderer.render(bogey.bogeyData, wheelAngle, ms);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateLight(BlockAndTintGetter world, CarriageContraptionEntity entity) {
|
public void updateLight(BlockAndTintGetter world, CarriageContraptionEntity entity) {
|
||||||
|
|
|
@ -28,10 +28,13 @@ import net.minecraft.world.level.block.Block;
|
||||||
import net.minecraft.world.phys.Vec3;
|
import net.minecraft.world.phys.Vec3;
|
||||||
import net.minecraftforge.registries.ForgeRegistries;
|
import net.minecraftforge.registries.ForgeRegistries;
|
||||||
|
|
||||||
|
import static com.simibubi.create.content.logistics.trains.track.AbstractBogeyTileEntity.BOGEY_DATA_KEY;
|
||||||
import static com.simibubi.create.content.logistics.trains.track.AbstractBogeyTileEntity.BOGEY_STYLE_KEY;
|
import static com.simibubi.create.content.logistics.trains.track.AbstractBogeyTileEntity.BOGEY_STYLE_KEY;
|
||||||
|
|
||||||
public class CarriageBogey {
|
public class CarriageBogey {
|
||||||
|
|
||||||
|
public static final String UPSIDE_DOWN_KEY = "UpsideDown";
|
||||||
|
|
||||||
public Carriage carriage;
|
public Carriage carriage;
|
||||||
boolean isLeading;
|
boolean isLeading;
|
||||||
|
|
||||||
|
@ -51,12 +54,13 @@ public class CarriageBogey {
|
||||||
|
|
||||||
public CarriageBogey(AbstractBogeyBlock<?> type, boolean upsideDown, CompoundTag bogeyData, TravellingPoint point, TravellingPoint point2) {
|
public CarriageBogey(AbstractBogeyBlock<?> type, boolean upsideDown, CompoundTag bogeyData, TravellingPoint point, TravellingPoint point2) {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
if (bogeyData == null || bogeyData.isEmpty())
|
|
||||||
bogeyData = this.createBogeyData(); // Prevent Crash When Updating
|
|
||||||
this.bogeyData = bogeyData;
|
|
||||||
this.upsideDown = type.canBeUpsideDown() && upsideDown;
|
this.upsideDown = type.canBeUpsideDown() && upsideDown;
|
||||||
point.upsideDown = this.upsideDown;
|
point.upsideDown = this.upsideDown;
|
||||||
point2.upsideDown = this.upsideDown;
|
point2.upsideDown = this.upsideDown;
|
||||||
|
if (bogeyData == null || bogeyData.isEmpty())
|
||||||
|
bogeyData = this.createBogeyData(); // Prevent Crash When Updating
|
||||||
|
bogeyData.putBoolean(UPSIDE_DOWN_KEY, upsideDown);
|
||||||
|
this.bogeyData = bogeyData;
|
||||||
points = Couple.create(point, point2);
|
points = Couple.create(point, point2);
|
||||||
wheelAngle = LerpedFloat.angular();
|
wheelAngle = LerpedFloat.angular();
|
||||||
yaw = LerpedFloat.angular();
|
yaw = LerpedFloat.angular();
|
||||||
|
@ -177,13 +181,15 @@ public class CarriageBogey {
|
||||||
.toString());
|
.toString());
|
||||||
tag.put("Points", points.serializeEach(tp -> tp.write(dimensions)));
|
tag.put("Points", points.serializeEach(tp -> tp.write(dimensions)));
|
||||||
tag.putBoolean("UpsideDown", upsideDown);
|
tag.putBoolean("UpsideDown", upsideDown);
|
||||||
tag.put(BOGEY_STYLE_KEY, bogeyData);
|
bogeyData.putBoolean(UPSIDE_DOWN_KEY, upsideDown);
|
||||||
|
NBTHelper.writeResourceLocation(bogeyData, BOGEY_STYLE_KEY, getStyle().name);
|
||||||
|
tag.put(BOGEY_DATA_KEY, bogeyData);
|
||||||
return tag;
|
return tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static CarriageBogey read(CompoundTag tag, TrackGraph graph, DimensionPalette dimensions) {
|
public static CarriageBogey read(CompoundTag tag, TrackGraph graph, DimensionPalette dimensions) {
|
||||||
ResourceLocation location = new ResourceLocation(tag.getString("Type"));
|
ResourceLocation location = new ResourceLocation(tag.getString("Type"));
|
||||||
AbstractBogeyBlock type = (AbstractBogeyBlock) ForgeRegistries.BLOCKS.getValue(location);
|
AbstractBogeyBlock<?> type = (AbstractBogeyBlock<?>) ForgeRegistries.BLOCKS.getValue(location);
|
||||||
boolean upsideDown = tag.getBoolean("UpsideDown");
|
boolean upsideDown = tag.getBoolean("UpsideDown");
|
||||||
Couple<TravellingPoint> points = Couple.deserializeEach(tag.getList("Points", Tag.TAG_COMPOUND),
|
Couple<TravellingPoint> points = Couple.deserializeEach(tag.getList("Points", Tag.TAG_COMPOUND),
|
||||||
c -> TravellingPoint.read(c, graph, dimensions));
|
c -> TravellingPoint.read(c, graph, dimensions));
|
||||||
|
@ -197,12 +203,15 @@ public class CarriageBogey {
|
||||||
|
|
||||||
public BogeyStyle getStyle() {
|
public BogeyStyle getStyle() {
|
||||||
ResourceLocation location = NBTHelper.readResourceLocation(this.bogeyData, BOGEY_STYLE_KEY);
|
ResourceLocation location = NBTHelper.readResourceLocation(this.bogeyData, BOGEY_STYLE_KEY);
|
||||||
return AllBogeyStyles.BOGEY_STYLES.get(location);
|
BogeyStyle style = AllBogeyStyles.BOGEY_STYLES.get(location);
|
||||||
|
return style != null ? style : AllBogeyStyles.STANDARD; // just for safety
|
||||||
}
|
}
|
||||||
|
|
||||||
private CompoundTag createBogeyData() {
|
private CompoundTag createBogeyData() {
|
||||||
CompoundTag nbt = new CompoundTag();
|
BogeyStyle style = type != null ? type.getDefaultStyle() : AllBogeyStyles.STANDARD;
|
||||||
NBTHelper.writeResourceLocation(nbt, BOGEY_STYLE_KEY, (type != null ? type.getDefaultStyle() : AllBogeyStyles.STANDARD).name);
|
CompoundTag nbt = style.defaultData != null ? style.defaultData : new CompoundTag();
|
||||||
|
NBTHelper.writeResourceLocation(nbt, BOGEY_STYLE_KEY, style.name);
|
||||||
|
nbt.putBoolean(UPSIDE_DOWN_KEY, isUpsideDown());
|
||||||
return nbt;
|
return nbt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,7 @@ public class CarriageSounds {
|
||||||
public CarriageSounds(CarriageContraptionEntity entity) {
|
public CarriageSounds(CarriageContraptionEntity entity) {
|
||||||
this.entity = entity;
|
this.entity = entity;
|
||||||
bogeySounds = entity.getCarriage().bogeys.map(bogey ->
|
bogeySounds = entity.getCarriage().bogeys.map(bogey ->
|
||||||
bogey != null ? bogey.getStyle().getSoundType()
|
bogey != null && bogey.getStyle() != null ? bogey.getStyle().getSoundType()
|
||||||
: AllSoundEvents.TRAIN2.getMainEvent());
|
: AllSoundEvents.TRAIN2.getMainEvent());
|
||||||
closestBogeySound = bogeySounds.getFirst();
|
closestBogeySound = bogeySounds.getFirst();
|
||||||
distanceFactor = LerpedFloat.linear();
|
distanceFactor = LerpedFloat.linear();
|
||||||
|
|
|
@ -558,8 +558,6 @@ public class Navigation {
|
||||||
if (validTypes.isEmpty()) // if there are no valid track types, a route can't be found
|
if (validTypes.isEmpty()) // if there are no valid track types, a route can't be found
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Create.LOGGER.info("Valid types: "+validTypes);
|
|
||||||
|
|
||||||
Map<TrackEdge, Integer> penalties = new IdentityHashMap<>();
|
Map<TrackEdge, Integer> penalties = new IdentityHashMap<>();
|
||||||
boolean costRelevant = maxCost >= 0;
|
boolean costRelevant = maxCost >= 0;
|
||||||
if (costRelevant) {
|
if (costRelevant) {
|
||||||
|
|
|
@ -48,7 +48,7 @@ public class TrainPacket extends SimplePacketBase {
|
||||||
for (boolean isFirst : Iterate.trueAndFalse) {
|
for (boolean isFirst : Iterate.trueAndFalse) {
|
||||||
if (!isFirst && !buffer.readBoolean())
|
if (!isFirst && !buffer.readBoolean())
|
||||||
continue;
|
continue;
|
||||||
AbstractBogeyBlock type = (AbstractBogeyBlock) ForgeRegistries.BLOCKS.getValue(buffer.readResourceLocation());
|
AbstractBogeyBlock<?> type = (AbstractBogeyBlock<?>) ForgeRegistries.BLOCKS.getValue(buffer.readResourceLocation());
|
||||||
boolean upsideDown = buffer.readBoolean();
|
boolean upsideDown = buffer.readBoolean();
|
||||||
CompoundTag data = buffer.readNbt();
|
CompoundTag data = buffer.readNbt();
|
||||||
bogies.set(isFirst, new CarriageBogey(type, upsideDown, data, new TravellingPoint(), new TravellingPoint()));
|
bogies.set(isFirst, new CarriageBogey(type, upsideDown, data, new TravellingPoint(), new TravellingPoint()));
|
||||||
|
|
|
@ -17,6 +17,8 @@ import net.minecraft.world.phys.AABB;
|
||||||
;
|
;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import static com.simibubi.create.content.logistics.trains.entity.CarriageBogey.UPSIDE_DOWN_KEY;
|
||||||
|
|
||||||
public abstract class AbstractBogeyTileEntity extends CachedRenderBBTileEntity {
|
public abstract class AbstractBogeyTileEntity extends CachedRenderBBTileEntity {
|
||||||
public static String BOGEY_STYLE_KEY = "BogeyStyle";
|
public static String BOGEY_STYLE_KEY = "BogeyStyle";
|
||||||
public static String BOGEY_DATA_KEY = "BogeyData";
|
public static String BOGEY_DATA_KEY = "BogeyData";
|
||||||
|
@ -81,6 +83,10 @@ public abstract class AbstractBogeyTileEntity extends CachedRenderBBTileEntity {
|
||||||
private CompoundTag createBogeyData() {
|
private CompoundTag createBogeyData() {
|
||||||
CompoundTag nbt = new CompoundTag();
|
CompoundTag nbt = new CompoundTag();
|
||||||
NBTHelper.writeResourceLocation(nbt, BOGEY_STYLE_KEY, getDefaultStyle().name);
|
NBTHelper.writeResourceLocation(nbt, BOGEY_STYLE_KEY, getDefaultStyle().name);
|
||||||
|
boolean upsideDown = false;
|
||||||
|
if (getBlockState().getBlock() instanceof AbstractBogeyBlock<?> bogeyBlock)
|
||||||
|
upsideDown = bogeyBlock.isUpsideDown(getBlockState());
|
||||||
|
nbt.putBoolean(UPSIDE_DOWN_KEY, upsideDown);
|
||||||
return nbt;
|
return nbt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue