Skip to content

Commit

Permalink
修复了 gui 的 bug, 修复了 AnimateTicker 设置播放速度的 bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
MegumiKasuga committed Oct 22, 2024
1 parent 5b53d02 commit 6ccf19d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
2 changes: 2 additions & 0 deletions src/main/java/kasuga/lib/core/KasugaLibStacks.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public class KasugaLibStacks {
private final FontRegistry FONTS;
private final RandomSource random = RandomSource.create();
private final HashMap<Block, CustomBlockRenderer> BLOCK_RENDERERS;

public final JavascriptApi JAVASCRIPT = new JavascriptApi();

public Optional<GuiEngine> GUI = Optional.empty();
Expand Down Expand Up @@ -94,6 +95,7 @@ public KasugaLibStacks(IEventBus bus) {
GUI = Optional.of(new GuiEngine());
bus.addListener(AnimationModelRegistryEvent::registerAnimations);
if (Envs.isDevEnvironment()) KasugaLibClient.invoke();
DistExecutor.unsafeRunWhenOn(Dist.CLIENT, ()-> TargetsClient::reigster);
}

MinecraftForge.EVENT_BUS.addListener(ServerResourceListener::onServerStarting);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void setPlaySpeed(float speed) {
}

public int getEndTick() {
return (int) Math.ceil(starterTick + animation.length * 20f * Math.abs(playSpeed / 100f));
return (int) Math.ceil((double) this.starterTick + (this.animation.length * 20) * 100f / Math.abs(playSpeed));
}

public int getTick() {
Expand All @@ -85,6 +85,7 @@ public void start() {

public void stop() {
this.moving = false;
this.paused = false;
}

public void pause() {
Expand All @@ -109,9 +110,10 @@ public void setMoving(boolean moving) {
}

public float tickToSec(float partial) {
int offset = tick - starterTick;
float result = ((float) offset + partial) / 20f;
if (playSpeed < 0) result = animation.length - result;
float offset = (float) tick - (float) starterTick + partial;
float percentage = offset / (float) (endTick - starterTick);
float result = percentage * this.animation.length;
if (playSpeed < 0) result = this.animation.length - result;
this.recent = result;
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,17 +149,17 @@ public AnimateTicker getTicker(ResourceLocation file, String name) {
}

public static LazyRecomputable<MultiAnimateTicker> getTickerInstance(
RenderType type, String animName, AnimateTicker.TickerType ticker,
int frameRate, float playSpeed, Pair<ResourceLocation, ResourceLocation>... anims) {
ResourceLocation modelLoc, RenderType type, AnimateTicker.TickerType ticker,
int frameRate, float playSpeed, Pair<ResourceLocation, String>... anims) {
return new LazyRecomputable<>(() -> {
AnimationInstance[] instances = new AnimationInstance[anims.length];
int counter = 0;
for (Pair<ResourceLocation, ResourceLocation> a : anims) {
AnimModel model = BedrockModelLoader.getModel(a.getFirst(), type);
if (model == null) return null;
AnimationFile file = AnimationFile.fromFile(a.getSecond()).get();
AnimModel model = BedrockModelLoader.getModel(modelLoc, type);
if (model == null) return null;
for (Pair<ResourceLocation, String> a : anims) {
AnimationFile file = AnimationFile.fromFile(a.getFirst()).get();
if (file == null) return null;
Animation anim = file.getAnimation(animName);
Animation anim = file.getAnimation(a.getSecond());
if (anim == null) return null;
instances[counter] = anim.getInstance(model, frameRate);
counter++;
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/kasuga/lib/example_env/AllExampleElements.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import kasuga.lib.KasugaLib;
import kasuga.lib.core.util.Envs;
import kasuga.lib.core.config.SimpleConfig;
import kasuga.lib.example_env.block.green_apple.GreenAppleBlock;
import kasuga.lib.example_env.block.green_apple.GreenAppleItem;
import kasuga.lib.example_env.block.green_apple.GreenAppleTile;
Expand All @@ -14,8 +13,6 @@
import kasuga.lib.example_env.client.screens.GreenAppleScreen;
import kasuga.lib.example_env.network.ExampleC2SPacket;
import kasuga.lib.example_env.network.ExampleS2CPacket;
import kasuga.lib.registrations.client.AnimReg;
import kasuga.lib.registrations.client.ModelReg;
import kasuga.lib.registrations.common.*;
import kasuga.lib.registrations.registry.SimpleRegistry;
import net.minecraft.resources.ResourceLocation;
Expand Down

0 comments on commit 6ccf19d

Please sign in to comment.