-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add rear attachment system and passenger seats for cars
- Loading branch information
1 parent
360ab52
commit 54fc726
Showing
25 changed files
with
1,412 additions
and
68 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
54 changes: 54 additions & 0 deletions
54
...java/io/github/foundationgames/automobility/automobile/attachment/RearAttachmentType.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,54 @@ | ||
package io.github.foundationgames.automobility.automobile.attachment; | ||
|
||
import io.github.foundationgames.automobility.Automobility; | ||
import io.github.foundationgames.automobility.automobile.AutomobileFrame; | ||
import io.github.foundationgames.automobility.automobile.attachment.rear.EmptyRearAttachment; | ||
import io.github.foundationgames.automobility.automobile.attachment.rear.PassengerSeatRearAttachment; | ||
import io.github.foundationgames.automobility.automobile.attachment.rear.RearAttachment; | ||
import io.github.foundationgames.automobility.entity.AutomobileEntity; | ||
import io.github.foundationgames.automobility.render.AutomobilityModels; | ||
import io.github.foundationgames.automobility.util.SimpleMapContentRegistry; | ||
import net.fabricmc.api.EnvType; | ||
import net.fabricmc.api.Environment; | ||
import net.minecraft.client.model.Model; | ||
import net.minecraft.client.render.entity.EntityRendererFactory; | ||
import net.minecraft.util.Identifier; | ||
|
||
import java.util.function.BiFunction; | ||
import java.util.function.Function; | ||
|
||
public record RearAttachmentType<T extends RearAttachment>( | ||
Identifier id, BiFunction<RearAttachmentType<T>, AutomobileEntity, T> constructor, RearAttachmentModel model | ||
) implements SimpleMapContentRegistry.Identifiable { | ||
public static final SimpleMapContentRegistry<RearAttachmentType<?>> REGISTRY = new SimpleMapContentRegistry<>(); | ||
|
||
public static final RearAttachmentType<EmptyRearAttachment> EMPTY = register(new RearAttachmentType<>( | ||
Automobility.id("empty"), EmptyRearAttachment::new, new RearAttachmentModel(new Identifier("empty"), Automobility.id("empty"), 0) | ||
)); | ||
|
||
public static final RearAttachmentType<PassengerSeatRearAttachment> PASSENGER_SEAT = register(new RearAttachmentType<>( | ||
Automobility.id("passenger_seat"), PassengerSeatRearAttachment::new, | ||
new RearAttachmentModel(Automobility.id("textures/entity/automobile/rear_attachment/passenger_seat.png"), Automobility.id("rearatt_passenger_seat"), 11) | ||
)); | ||
|
||
public boolean isEmpty() { | ||
return this == EMPTY; | ||
} | ||
|
||
@Override | ||
public Identifier getId() { | ||
return this.id; | ||
} | ||
|
||
private static <T extends RearAttachment> RearAttachmentType<T> register(RearAttachmentType<T> entry) { | ||
REGISTRY.register(entry); | ||
return entry; | ||
} | ||
|
||
public record RearAttachmentModel(Identifier texture, Identifier modelId, float pivotDistPx) { | ||
@Environment(EnvType.CLIENT) | ||
public Function<EntityRendererFactory.Context, Model> model() { | ||
return AutomobilityModels.MODELS.get(modelId); | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...o/github/foundationgames/automobility/automobile/attachment/rear/EmptyRearAttachment.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,14 @@ | ||
package io.github.foundationgames.automobility.automobile.attachment.rear; | ||
|
||
import io.github.foundationgames.automobility.automobile.attachment.RearAttachmentType; | ||
import io.github.foundationgames.automobility.entity.AutomobileEntity; | ||
|
||
public class EmptyRearAttachment extends RearAttachment { | ||
public EmptyRearAttachment(RearAttachmentType<?> type, AutomobileEntity entity) { | ||
super(type, entity); | ||
} | ||
|
||
@Override | ||
public void tick() { | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
.../foundationgames/automobility/automobile/attachment/rear/PassengerSeatRearAttachment.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,20 @@ | ||
package io.github.foundationgames.automobility.automobile.attachment.rear; | ||
|
||
import io.github.foundationgames.automobility.automobile.attachment.RearAttachmentType; | ||
import io.github.foundationgames.automobility.entity.AutomobileEntity; | ||
|
||
public class PassengerSeatRearAttachment extends RearAttachment { | ||
public PassengerSeatRearAttachment(RearAttachmentType<?> type, AutomobileEntity entity) { | ||
super(type, entity); | ||
} | ||
|
||
@Override | ||
public boolean isRideable() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public double getPassengerHeightOffset() { | ||
return 0.69; | ||
} | ||
} |
95 changes: 95 additions & 0 deletions
95
...ava/io/github/foundationgames/automobility/automobile/attachment/rear/RearAttachment.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 io.github.foundationgames.automobility.automobile.attachment.rear; | ||
|
||
import io.github.foundationgames.automobility.automobile.attachment.RearAttachmentType; | ||
import io.github.foundationgames.automobility.entity.AutomobileEntity; | ||
import net.minecraft.nbt.NbtCompound; | ||
import net.minecraft.util.Identifier; | ||
import net.minecraft.util.math.MathHelper; | ||
import net.minecraft.util.math.Vec3d; | ||
import net.minecraft.world.World; | ||
|
||
public abstract class RearAttachment { | ||
public final RearAttachmentType<?> type; | ||
protected final AutomobileEntity automobile; | ||
private float lastYaw; | ||
|
||
protected RearAttachment(RearAttachmentType<?> type, AutomobileEntity entity) { | ||
this.type = type; | ||
this.automobile = entity; | ||
} | ||
|
||
protected final World world() { | ||
return this.automobile.world; | ||
} | ||
|
||
public final Vec3d yawVec() { | ||
return new Vec3d(0, 0, 1).rotateY((float) Math.toRadians(180 - this.yaw())); | ||
} | ||
|
||
public final Vec3d scaledYawVec() { | ||
return this.yawVec().multiply(this.type.model().pivotDistPx() * 0.0625); | ||
} | ||
|
||
public final Vec3d origin() { | ||
return this.automobile.getTailPos(); | ||
} | ||
|
||
public final Vec3d pos() { | ||
return this.origin().add(this.scaledYawVec()); | ||
} | ||
|
||
public float yaw() { | ||
return this.automobile.getTrackedRearAttachmentYaw(); | ||
} | ||
|
||
public float yaw(float delta) { | ||
return MathHelper.lerpAngleDegrees(delta, this.lastYaw, this.yaw()); | ||
} | ||
|
||
public void setYaw(float yaw) { | ||
float diff = MathHelper.wrapDegrees(yaw - this.automobile.getYaw()); | ||
if (diff < -90 && diff > -180) yaw = this.automobile.getYaw() - 90; | ||
else if (diff > 90 && diff < 180) yaw = this.automobile.getYaw() + 90; | ||
|
||
this.automobile.setTrackedRearAttachmentYaw(yaw); | ||
} | ||
|
||
public final void pull(Vec3d movement) { | ||
var vec = this.scaledYawVec().add(movement); | ||
this.setYaw(180 - (float) Math.toDegrees(Math.atan2(vec.x, vec.z))); | ||
} | ||
|
||
public void tick() { | ||
this.lastYaw = this.yaw(); | ||
} | ||
|
||
public void onRemoved() { | ||
} | ||
|
||
public boolean isRideable() { | ||
return false; | ||
} | ||
|
||
public double getPassengerHeightOffset() { | ||
return 0.5; | ||
} | ||
|
||
public void writeNbt(NbtCompound nbt) { | ||
nbt.putFloat("yaw", this.yaw()); | ||
} | ||
|
||
public void readNbt(NbtCompound nbt) { | ||
this.setYaw(nbt.getFloat("yaw")); | ||
} | ||
|
||
public final NbtCompound toNbt() { | ||
var nbt = new NbtCompound(); | ||
nbt.putString("type", this.type.id().toString()); | ||
this.writeNbt(nbt); | ||
return nbt; | ||
} | ||
|
||
public static RearAttachmentType<?> fromNbt(NbtCompound nbt) { | ||
return RearAttachmentType.REGISTRY.get(Identifier.tryParse(nbt.getString("type"))); | ||
} | ||
} |
8 changes: 0 additions & 8 deletions
8
...io/github/foundationgames/automobility/automobile/attachment/rear/RearAttachmentType.java
This file was deleted.
Oops, something went wrong.
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
18 changes: 18 additions & 0 deletions
18
...n/java/io/github/foundationgames/automobility/automobile/render/RenderableAutomobile.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
Oops, something went wrong.