forked from Gaider10/GravityChanger
-
Notifications
You must be signed in to change notification settings - Fork 3
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 Gaider10#7 from qouteall/1.19
A lot of improvements
- Loading branch information
Showing
9 changed files
with
229 additions
and
394 deletions.
There are no files selected for viewing
68 changes: 68 additions & 0 deletions
68
src/main/java/com/fusionflux/gravity_api/RotationAnimation.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,68 @@ | ||
package com.fusionflux.gravity_api; | ||
|
||
import com.fusionflux.gravity_api.util.RotationUtil; | ||
import net.fabricmc.api.EnvType; | ||
import net.fabricmc.api.Environment; | ||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.util.math.Direction; | ||
import net.minecraft.util.math.MathHelper; | ||
import net.minecraft.util.math.Quaternion; | ||
|
||
@Environment(EnvType.CLIENT) | ||
public class RotationAnimation { | ||
private static boolean inAnimation = false; | ||
private static Quaternion startGravityRotation; | ||
private static Quaternion endGravityRotation; | ||
private static long startTimeMs; | ||
private static long endTimeMs; | ||
|
||
public static void applyRotationAnimation(Direction newGravity, Direction prevGravity, int durationTimeMs) { | ||
if (durationTimeMs == 0) { | ||
inAnimation = false; | ||
return; | ||
} | ||
|
||
long now = getTimeMs(); | ||
|
||
Quaternion currentGravityRotation = getCurrentGravityRotation(prevGravity); | ||
|
||
Quaternion targetGravityRotation = RotationUtil.getWorldRotationQuaternion(newGravity); | ||
|
||
inAnimation = true; | ||
startGravityRotation = currentGravityRotation; | ||
endGravityRotation = targetGravityRotation; | ||
startTimeMs = now; | ||
endTimeMs = now + durationTimeMs; | ||
} | ||
|
||
private static long getTimeMs() { | ||
return System.currentTimeMillis(); | ||
} | ||
|
||
public static Quaternion getCurrentGravityRotation(Direction currentGravity) { | ||
|
||
long now = getTimeMs(); | ||
|
||
if (now > endTimeMs) { | ||
inAnimation = false; | ||
} | ||
|
||
if (!inAnimation) { | ||
return RotationUtil.getWorldRotationQuaternion(currentGravity); | ||
} | ||
|
||
double delta = ((double) (now - startTimeMs)) / (endTimeMs - startTimeMs); | ||
|
||
// make sure that frustum culling updates when running rotation animation | ||
MinecraftClient.getInstance().worldRenderer.scheduleTerrainUpdate(); | ||
|
||
return RotationUtil.interpolate( | ||
startGravityRotation, endGravityRotation, | ||
mapProgress((float) delta) | ||
); | ||
} | ||
|
||
private static float mapProgress(float delta) { | ||
return MathHelper.clamp((delta * delta * (3 - 2 * delta)), 0, 1); | ||
} | ||
} |
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
13 changes: 13 additions & 0 deletions
13
src/main/java/com/fusionflux/gravity_api/util/EntityTags.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,11 +1,24 @@ | ||
package com.fusionflux.gravity_api.util; | ||
|
||
import net.minecraft.entity.Entity; | ||
import net.minecraft.entity.EntityType; | ||
import net.minecraft.entity.LivingEntity; | ||
import net.minecraft.entity.mob.MobEntity; | ||
import net.minecraft.entity.projectile.ProjectileEntity; | ||
import net.minecraft.tag.TagKey; | ||
import net.minecraft.util.Identifier; | ||
import net.minecraft.util.registry.Registry; | ||
|
||
public class EntityTags { | ||
public static final TagKey<EntityType<?>> FORBIDDEN_ENTITIES = TagKey.of(Registry.ENTITY_TYPE_KEY, new Identifier("gravitychanger", "forbidden_entities")); | ||
public static final TagKey<EntityType<?>> FORBIDDEN_ENTITY_RENDERING = TagKey.of(Registry.ENTITY_TYPE_KEY, new Identifier("gravitychanger", "forbidden_entity_rendering")); | ||
|
||
public static boolean canChangeGravity(Entity entity) { | ||
if (entity instanceof LivingEntity || entity instanceof ProjectileEntity) { | ||
return !entity.getType().getRegistryEntry().isIn(FORBIDDEN_ENTITIES); | ||
} | ||
else { | ||
return false; | ||
} | ||
} | ||
} |
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.