Skip to content

Commit

Permalink
1.0.1 update: Added interactions
Browse files Browse the repository at this point in the history
  • Loading branch information
LouisQuepierts committed Jul 31, 2024
1 parent 407551b commit 9b1bdd4
Show file tree
Hide file tree
Showing 51 changed files with 744 additions and 447 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ mapping_version=2023.09.03-1.20.1
mod_id=simple_animator
mod_name=SimpleAnimator
mod_license=MIT
mod_version=1.0-SNAPSHOT
mod_version=1.0.1
mod_group_id=net.quepierts
mod_authors=
mod_description=

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,25 @@
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.player.Player;
import net.quepierts.simple_animator.core.animation.ModelBone;
import net.quepierts.simple_animator.core.animation.Animation;
import net.quepierts.simple_animator.core.animation.Animator;
import net.quepierts.simple_animator.core.client.state.IAnimationState;
import net.quepierts.simple_animator.core.common.PlayerUtils;
import net.quepierts.simple_animator.core.SimpleAnimator;
import net.quepierts.simple_animator.core.animation.AnimationState;
import net.quepierts.simple_animator.core.common.animation.AnimationState;
import net.quepierts.simple_animator.core.common.animation.Animator;
import net.quepierts.simple_animator.core.common.animation.ModelBone;
import net.quepierts.simple_animator.core.network.ModNetwork;
import net.quepierts.simple_animator.core.network.packet.AnimatorPacket;
import net.quepierts.simple_animator.core.network.packet.AnimatorDataPacket;
import org.joml.Matrix4f;
import org.joml.Quaternionf;
import org.joml.Vector3f;

import java.util.*;
import java.util.Collections;
import java.util.EnumMap;
import java.util.UUID;

public class ClientAnimator extends Animator {
private static final ModelPart ROOT = new ModelPart(Collections.EMPTY_LIST, Collections.EMPTY_MAP);
public Player player;
private Animation animation;
//private Animation animation;
private final EnumMap<ModelBone, Cache> cache;
private boolean processed = false;
private boolean shouldUpdate = false;
Expand All @@ -44,29 +44,23 @@ public ClientAnimator(UUID uuid) {
}
}

@Override
public void sync(AnimatorPacket packet) {
super.sync(packet);
this.animation = SimpleAnimator.getInstance().getProxy().getAnimationManager().getAnimation(animationLocation);
}

public void update(AnimatorPacket packet) {
public void update(AnimatorDataPacket packet) {
if (!isLocalPlayer())
return;

ModNetwork.update(packet);
}

@Override
public void play(ResourceLocation location) {
super.play(location);
public boolean play(ResourceLocation location) {
if (this.animation == null)
processed = false;

this.animation = SimpleAnimator.getInstance().getProxy().getAnimationManager().getAnimation(location);
if (!super.play(location))
return false;

if (this.animation == null)
return;
return false;

this.nextState = this.animation.hasEnterAnimation() ? AnimationState.ENTER : AnimationState.LOOP;
this.procState = ProcessState.TRANSFER;
Expand All @@ -77,19 +71,18 @@ public void play(ResourceLocation location) {
assert localPlayer != null;
this.player = localPlayer.level().getPlayerByUUID(uuid);
}
}

@Override
public boolean isRunning() {
return this.animation != null && super.isRunning();
return true;
}

public void stop() {
super.stop();
public boolean stop() {
if (!super.stop())
return false;
this.timer = 0;
this.nextState = this.animation.hasExitAnimation() ? AnimationState.EXIT : AnimationState.IDLE;
this.procState = ProcessState.TRANSFER;
this.processed = false;
return true;
}

public void tick(float time) {
Expand All @@ -116,7 +109,7 @@ public void tick(float time) {
impl.exit(this);
this.procState = ProcessState.TRANSFER;
this.shouldUpdate = false;
this.update(new AnimatorPacket(this, false));
this.update(new AnimatorDataPacket(this, false));
}
}
break;
Expand Down Expand Up @@ -174,10 +167,6 @@ private void process(ModelBone bone, ModelPart part) {
part.zRot = pose.zRot + rotation.z;
}

public Animation getAnimation() {
return animation;
}

public boolean canStop() {
return curState == AnimationState.LOOP && nextState == AnimationState.LOOP;
}
Expand All @@ -198,15 +187,14 @@ public boolean isLocalPlayer() {

public void reset() {
super.reset();
this.animation = null;
this.processed = false;

this.cache.forEach((bone, cache) -> {
cache.position.set(0);
cache.rotation.set(0);
});

this.update(new AnimatorPacket(this, false));
this.update(new AnimatorDataPacket(this, false));
}

public void processRoot(PoseStack poseStack) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
import net.minecraft.client.Minecraft;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.quepierts.simple_animator.core.common.AnimatorManager;
import net.quepierts.simple_animator.core.common.animation.AnimatorManager;
import net.quepierts.simple_animator.core.network.packet.AnimatorDataPacket;
import net.quepierts.simple_animator.core.network.packet.batch.ClientUpdateAnimatorPacket;

import javax.annotation.Nonnull;
import java.util.List;
import java.util.UUID;

public class ClientAnimatorManager extends AnimatorManager<ClientAnimator> {
Expand All @@ -20,8 +23,20 @@ public ClientAnimator get(UUID player) {
}

public void tick(float renderTickTime) {
float time = renderTickTime / Minecraft.getInstance().getFps();
for (ClientAnimator animator : animators.values()) {
animator.tick(renderTickTime / Minecraft.getInstance().getFps());
animator.tick(time);
}
}

public void handleUpdateAnimator(ClientUpdateAnimatorPacket packet) {
this.clear();

List<AnimatorDataPacket> list = packet.getAnimators();
for (AnimatorDataPacket data : list) {
this.get(data.getOwner()).sync(data);
}

this.getLocalAnimator();
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package net.quepierts.simple_animator.core.client;

import net.minecraft.client.Minecraft;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.phys.Vec3;
import net.quepierts.simple_animator.core.SimpleAnimator;
import net.quepierts.simple_animator.core.common.PlayerUtils;
import net.quepierts.simple_animator.core.common.animation.InteractionManager;
import net.quepierts.simple_animator.core.network.ModNetwork;
import net.quepierts.simple_animator.core.network.packet.InteractAcceptPacket;
import net.quepierts.simple_animator.core.proxy.ClientProxy;

import java.util.UUID;

public class ClientInteractionManager extends InteractionManager {
private final ClientProxy client;

public ClientInteractionManager(ClientProxy clientProxy) {
this.client = clientProxy;
}

/*
* Receive Invite From Other Player
* */
@Override
public boolean invite(Player requester, Player receiver, ResourceLocation location) {
return super.invite(requester, receiver, location);
}

@Override
public boolean accept(Player requester, Player receiver) {
if (receiver == Minecraft.getInstance().player) {
return tryAccept(requester);
}
return super.accept(requester, receiver);
}

public boolean tryAccept(Player requester) {
SimpleAnimator.LOGGER.info("Try Accept");
LocalPlayer player = Minecraft.getInstance().player;
assert player != null;
UUID uuid = requester.getUUID();

Request request = this.get(uuid);
if (request == null)
return false;

Vec3 position = PlayerUtils.getRelativePosition(requester, 1, 0);
if (player.distanceToSqr(position) > 0.01) {
client.getNavigator().navigateTo(
requester, 1, 0,
() -> ModNetwork.sendToServer(new InteractAcceptPacket(uuid, Minecraft.getInstance().player.getUUID()))
);
return false;
}

return super.accept(requester, player);
}

public boolean requesting() {
return this.exist(Minecraft.getInstance().player.getUUID());
}

protected Request getLocalRequest() {
return get(Minecraft.getInstance().player.getUUID());
}
}
Loading

0 comments on commit 9b1bdd4

Please sign in to comment.