Skip to content

Commit

Permalink
add(temporary animation solution)
Browse files Browse the repository at this point in the history
  • Loading branch information
JRepo42 committed Aug 27, 2023
1 parent 0c785b6 commit fe6b5b9
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

import elocindev.shield_overhaul.event.ShieldInteraction;
import elocindev.shield_overhaul.registry.EntityRegistry;
import elocindev.shield_overhaul.registry.PacketRegistry;
import net.fabricmc.api.ClientModInitializer;

public class ShieldOverhaulClient implements ClientModInitializer {
@Override
public void onInitializeClient() {
EntityRegistry.registerRenderers();
PacketRegistry.registerS2CPackets();
ShieldInteraction.bashingPacketRegistry();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package elocindev.shield_overhaul.networking;

import elocindev.shield_overhaul.util.ShieldAnimationUtils;
import net.fabricmc.fabric.api.networking.v1.PacketSender;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.network.PacketByteBuf;

public class ShieldBashAnimationS2CPacket {
public static void receive(MinecraftClient client, ClientPlayNetworkHandler handler,
PacketByteBuf buf, PacketSender responseSender) {
ShieldAnimationUtils.playShieldBashAnimation(client.player);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

import elocindev.shield_overhaul.ShieldOverhaul;
import elocindev.shield_overhaul.entity.ShieldBashEntity;
import elocindev.shield_overhaul.registry.PacketRegistry;
import elocindev.shield_overhaul.util.MathUtils;
import elocindev.shield_overhaul.util.ShieldAnimationUtils;
import net.fabricmc.fabric.api.networking.v1.PacketByteBufs;
import net.fabricmc.fabric.api.networking.v1.PacketSender;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayNetworkHandler;
Expand All @@ -23,7 +26,7 @@ public static void receive(MinecraftServer server, ServerPlayerEntity player, Se
entity.setVelocity(player, player.getPitch(), player.getYaw(), 0.0F, 2.0F, 0F);
player.world.spawnEntity(entity);

ShieldAnimationUtils.playShieldBashAnimation(player);
ServerPlayNetworking.send(player, PacketRegistry.SHIELD_BASH_ANIMATION_PACKET, PacketByteBufs.create());

Vec3d velocityVector = MathUtils.getLookingVec(player, 1.5f);
player.addVelocity(velocityVector.x, velocityVector.y, velocityVector.z);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
package elocindev.shield_overhaul.registry;

import elocindev.shield_overhaul.ShieldOverhaul;
import elocindev.shield_overhaul.networking.ShieldBashAnimationS2CPacket;
import elocindev.shield_overhaul.networking.ShieldBashC2SPacket;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.minecraft.util.Identifier;

public class PacketRegistry {
public static final Identifier SHIELD_BASH_PACKET = new Identifier(ShieldOverhaul.MODID, "");
public static final Identifier SHIELD_BASH_PACKET = new Identifier(ShieldOverhaul.MODID, "shield_bash_packet");
public static final Identifier SHIELD_BASH_ANIMATION_PACKET = new Identifier(ShieldOverhaul.MODID, "shield_bash_animation_packet");

public static void registerC2SPackets() {
ServerPlayNetworking.registerGlobalReceiver(SHIELD_BASH_PACKET, ShieldBashC2SPacket::receive);
}

public static void registerS2CPackets() {
ClientPlayNetworking.registerGlobalReceiver(SHIELD_BASH_ANIMATION_PACKET, ShieldBashAnimationS2CPacket::receive);
}
}

0 comments on commit fe6b5b9

Please sign in to comment.