-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from der-fruhling-entertainment/maintenance/cl…
…ean-up Maintenance/clean up
- Loading branch information
Showing
6 changed files
with
163 additions
and
67 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
91 changes: 91 additions & 0 deletions
91
common/src/main/java/net/derfruhling/minecraft/create/trainperspective/RotationState.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,91 @@ | ||
package net.derfruhling.minecraft.create.trainperspective; | ||
|
||
import com.simibubi.create.content.trains.entity.CarriageContraptionEntity; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public class RotationState implements RotationStateKeeper { | ||
private CarriageContraptionEntity entity; | ||
private float lastYaw; | ||
private final boolean standingState; | ||
private boolean isMounted; | ||
private boolean shouldTickState = true; | ||
private int ticksSinceLastUpdate = 0; | ||
|
||
public RotationState(CarriageContraptionEntity entity, boolean standingState, boolean isMounted) { | ||
this.entity = entity; | ||
lastYaw = entity.yaw; | ||
this.standingState = standingState; | ||
this.isMounted = isMounted; | ||
} | ||
|
||
@Override | ||
public float getYawDelta() { | ||
while (entity.yaw - lastYaw < -180.0f) { | ||
lastYaw -= 360.0f; | ||
} | ||
|
||
while (entity.yaw - lastYaw >= 180.0f) { | ||
lastYaw += 360.0f; | ||
} | ||
|
||
var rotation = entity.yaw - lastYaw; | ||
lastYaw = entity.yaw; | ||
return rotation; | ||
} | ||
|
||
@Override | ||
public @Nullable CarriageContraptionEntity getCarriageEntity() { | ||
return entity; | ||
} | ||
|
||
@Override | ||
public void setCarriageEntity(@Nullable CarriageContraptionEntity entity) { | ||
this.entity = entity; | ||
} | ||
|
||
@Override | ||
public boolean isStanding() { | ||
return standingState; | ||
} | ||
|
||
@Override | ||
public boolean isMounted() { | ||
return isMounted; | ||
} | ||
|
||
@Override | ||
public boolean shouldTickState() { | ||
return shouldTickState; | ||
} | ||
|
||
@Override | ||
public void onMounted() { | ||
this.isMounted = true; | ||
this.shouldTickState = true; | ||
} | ||
|
||
@Override | ||
public void onDismount() { | ||
this.isMounted = false; | ||
} | ||
|
||
@Override | ||
public void setShouldTickState(boolean shouldTickState) { | ||
this.shouldTickState = shouldTickState; | ||
} | ||
|
||
@Override | ||
public int getTicksSinceLastUpdate() { | ||
return ticksSinceLastUpdate; | ||
} | ||
|
||
@Override | ||
public void update() { | ||
ticksSinceLastUpdate = 0; | ||
} | ||
|
||
@Override | ||
public void tick() { | ||
ticksSinceLastUpdate += 1; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
.../src/main/java/net/derfruhling/minecraft/create/trainperspective/RotationStateKeeper.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,19 @@ | ||
package net.derfruhling.minecraft.create.trainperspective; | ||
|
||
import com.simibubi.create.content.trains.entity.CarriageContraptionEntity; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public interface RotationStateKeeper { | ||
@Nullable CarriageContraptionEntity getCarriageEntity(); | ||
void setCarriageEntity(@Nullable CarriageContraptionEntity entity); | ||
boolean isStanding(); | ||
boolean isMounted(); | ||
boolean shouldTickState(); | ||
void onMounted(); | ||
void onDismount(); | ||
void setShouldTickState(boolean value); | ||
int getTicksSinceLastUpdate(); | ||
void update(); | ||
void tick(); | ||
float getYawDelta(); | ||
} |
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