mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-27 15:17:59 +01:00
Update fabwork and switch a lot of the packets to records and replace the client handler with the new receiver method of registering callbacks
This commit is contained in:
parent
1763f433d4
commit
83932bfea1
21 changed files with 109 additions and 205 deletions
|
@ -20,7 +20,7 @@ org.gradle.daemon=false
|
||||||
modrinth_project_id=
|
modrinth_project_id=
|
||||||
|
|
||||||
# Dependencies
|
# Dependencies
|
||||||
fabwork_version=1.0.1
|
fabwork_version=1.1.0
|
||||||
modmenu_version=5.0.0-alpha.3
|
modmenu_version=5.0.0-alpha.3
|
||||||
minelp_version=4.7.2
|
minelp_version=4.7.2
|
||||||
kirin_version=1.13.2
|
kirin_version=1.13.2
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.minelittlepony.unicopia;
|
package com.minelittlepony.unicopia;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
@ -8,12 +9,13 @@ import org.jetbrains.annotations.Nullable;
|
||||||
import com.minelittlepony.unicopia.ability.magic.CasterView;
|
import com.minelittlepony.unicopia.ability.magic.CasterView;
|
||||||
import com.minelittlepony.unicopia.block.data.Ether;
|
import com.minelittlepony.unicopia.block.data.Ether;
|
||||||
import com.minelittlepony.unicopia.entity.player.dummy.DummyPlayerEntity;
|
import com.minelittlepony.unicopia.entity.player.dummy.DummyPlayerEntity;
|
||||||
import com.minelittlepony.unicopia.network.handler.ClientNetworkHandler;
|
|
||||||
import com.mojang.authlib.GameProfile;
|
import com.mojang.authlib.GameProfile;
|
||||||
|
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
|
import net.minecraft.network.PacketByteBuf;
|
||||||
import net.minecraft.server.world.ServerWorld;
|
import net.minecraft.server.world.ServerWorld;
|
||||||
|
import net.minecraft.util.Identifier;
|
||||||
import net.minecraft.world.BlockView;
|
import net.minecraft.world.BlockView;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
|
@ -41,11 +43,8 @@ public class InteractionManager {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public Map<Identifier, ?> readChapters(PacketByteBuf buf) {
|
||||||
* Returns the client network handler, or throws if called on the server.
|
throw new RuntimeException("Method not supported");
|
||||||
*/
|
|
||||||
public ClientNetworkHandler getClientNetworkHandler() {
|
|
||||||
throw new NullPointerException("Client network handler called by the server");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.minelittlepony.unicopia.client;
|
package com.minelittlepony.unicopia.client;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
|
@ -12,12 +13,11 @@ import com.minelittlepony.unicopia.USounds;
|
||||||
import com.minelittlepony.unicopia.ability.magic.CasterView;
|
import com.minelittlepony.unicopia.ability.magic.CasterView;
|
||||||
import com.minelittlepony.unicopia.block.data.Ether;
|
import com.minelittlepony.unicopia.block.data.Ether;
|
||||||
import com.minelittlepony.unicopia.client.gui.DismissSpellScreen;
|
import com.minelittlepony.unicopia.client.gui.DismissSpellScreen;
|
||||||
|
import com.minelittlepony.unicopia.client.gui.spellbook.ClientChapters;
|
||||||
import com.minelittlepony.unicopia.client.sound.*;
|
import com.minelittlepony.unicopia.client.sound.*;
|
||||||
import com.minelittlepony.unicopia.entity.player.PlayerPhysics;
|
import com.minelittlepony.unicopia.entity.player.PlayerPhysics;
|
||||||
import com.minelittlepony.unicopia.entity.player.Pony;
|
import com.minelittlepony.unicopia.entity.player.Pony;
|
||||||
import com.minelittlepony.unicopia.entity.player.dummy.DummyClientPlayerEntity;
|
import com.minelittlepony.unicopia.entity.player.dummy.DummyClientPlayerEntity;
|
||||||
import com.minelittlepony.unicopia.network.handler.ClientNetworkHandler;
|
|
||||||
import com.minelittlepony.unicopia.network.handler.ClientNetworkHandlerImpl;
|
|
||||||
import com.mojang.authlib.GameProfile;
|
import com.mojang.authlib.GameProfile;
|
||||||
|
|
||||||
import net.minecraft.client.MinecraftClient;
|
import net.minecraft.client.MinecraftClient;
|
||||||
|
@ -31,16 +31,17 @@ import net.minecraft.entity.LivingEntity;
|
||||||
import net.minecraft.entity.passive.BeeEntity;
|
import net.minecraft.entity.passive.BeeEntity;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.entity.vehicle.AbstractMinecartEntity;
|
import net.minecraft.entity.vehicle.AbstractMinecartEntity;
|
||||||
|
import net.minecraft.network.PacketByteBuf;
|
||||||
import net.minecraft.server.world.ServerWorld;
|
import net.minecraft.server.world.ServerWorld;
|
||||||
import net.minecraft.sound.SoundCategory;
|
import net.minecraft.sound.SoundCategory;
|
||||||
import net.minecraft.sound.SoundEvents;
|
import net.minecraft.sound.SoundEvents;
|
||||||
|
import net.minecraft.util.Identifier;
|
||||||
import net.minecraft.util.math.random.Random;
|
import net.minecraft.util.math.random.Random;
|
||||||
import net.minecraft.world.BlockView;
|
import net.minecraft.world.BlockView;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
public class ClientInteractionManager extends InteractionManager {
|
public class ClientInteractionManager extends InteractionManager {
|
||||||
|
|
||||||
private final ClientNetworkHandler handler = new ClientNetworkHandlerImpl();
|
|
||||||
private final MinecraftClient client = MinecraftClient.getInstance();
|
private final MinecraftClient client = MinecraftClient.getInstance();
|
||||||
|
|
||||||
private final Optional<CasterView> clientWorld = Optional.of(() -> MinecraftClient.getInstance().world);
|
private final Optional<CasterView> clientWorld = Optional.of(() -> MinecraftClient.getInstance().world);
|
||||||
|
@ -54,9 +55,8 @@ public class ClientInteractionManager extends InteractionManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Nullable
|
public Map<Identifier, ?> readChapters(PacketByteBuf buffer) {
|
||||||
public ClientNetworkHandler getClientNetworkHandler() {
|
return buffer.readMap(PacketByteBuf::readIdentifier, ClientChapters::loadChapter);
|
||||||
return handler;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -16,6 +16,8 @@ import com.minelittlepony.unicopia.client.render.shader.ViewportShader;
|
||||||
import com.minelittlepony.unicopia.container.*;
|
import com.minelittlepony.unicopia.container.*;
|
||||||
import com.minelittlepony.unicopia.entity.player.PlayerCamera;
|
import com.minelittlepony.unicopia.entity.player.PlayerCamera;
|
||||||
import com.minelittlepony.unicopia.entity.player.Pony;
|
import com.minelittlepony.unicopia.entity.player.Pony;
|
||||||
|
import com.minelittlepony.unicopia.network.handler.ClientNetworkHandlerImpl;
|
||||||
|
|
||||||
import net.fabricmc.api.ClientModInitializer;
|
import net.fabricmc.api.ClientModInitializer;
|
||||||
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
|
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
|
||||||
import net.fabricmc.fabric.api.client.item.v1.ItemTooltipCallback;
|
import net.fabricmc.fabric.api.client.item.v1.ItemTooltipCallback;
|
||||||
|
@ -60,6 +62,7 @@ public class UnicopiaClient implements ClientModInitializer {
|
||||||
@Override
|
@Override
|
||||||
public void onInitializeClient() {
|
public void onInitializeClient() {
|
||||||
InteractionManager.INSTANCE = new ClientInteractionManager();
|
InteractionManager.INSTANCE = new ClientInteractionManager();
|
||||||
|
new ClientNetworkHandlerImpl();
|
||||||
|
|
||||||
KeyBindingsHandler.bootstrap();
|
KeyBindingsHandler.bootstrap();
|
||||||
URenderers.bootstrap();
|
URenderers.bootstrap();
|
||||||
|
|
|
@ -78,7 +78,7 @@ public class TribeSelectionScreen extends GameGui implements HidesHud {
|
||||||
finished = false;
|
finished = false;
|
||||||
|
|
||||||
if (result) {
|
if (result) {
|
||||||
Channel.CLIENT_REQUEST_SPECIES_CHANGE.sendToServer(new MsgRequestSpeciesChange(race, true));
|
Channel.CLIENT_REQUEST_SPECIES_CHANGE.sendToServer(new MsgRequestSpeciesChange(true, race));
|
||||||
finish();
|
finish();
|
||||||
} else {
|
} else {
|
||||||
client.setScreen(this);
|
client.setScreen(this);
|
||||||
|
|
|
@ -9,7 +9,7 @@ import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
|
|
||||||
public interface Channel {
|
public interface Channel {
|
||||||
C2SPacketType<MsgPlayerAbility<?>> CLIENT_PLAYER_ABILITY = SimpleNetworking.clientToServer(Unicopia.id("player_ability"), MsgPlayerAbility::new);
|
C2SPacketType<MsgPlayerAbility<?>> CLIENT_PLAYER_ABILITY = SimpleNetworking.clientToServer(Unicopia.id("player_ability"), MsgPlayerAbility::read);
|
||||||
C2SPacketType<MsgRequestSpeciesChange> CLIENT_REQUEST_SPECIES_CHANGE = SimpleNetworking.clientToServer(Unicopia.id("request_capabilities"), MsgRequestSpeciesChange::new);
|
C2SPacketType<MsgRequestSpeciesChange> CLIENT_REQUEST_SPECIES_CHANGE = SimpleNetworking.clientToServer(Unicopia.id("request_capabilities"), MsgRequestSpeciesChange::new);
|
||||||
C2SPacketType<MsgMarkTraitRead> MARK_TRAIT_READ = SimpleNetworking.clientToServer(Unicopia.id("mark_trait_read"), MsgMarkTraitRead::new);
|
C2SPacketType<MsgMarkTraitRead> MARK_TRAIT_READ = SimpleNetworking.clientToServer(Unicopia.id("mark_trait_read"), MsgMarkTraitRead::new);
|
||||||
C2SPacketType<MsgRemoveSpell> REMOVE_SPELL = SimpleNetworking.clientToServer(Unicopia.id("remove_spell"), MsgRemoveSpell::new);
|
C2SPacketType<MsgRemoveSpell> REMOVE_SPELL = SimpleNetworking.clientToServer(Unicopia.id("remove_spell"), MsgRemoveSpell::new);
|
||||||
|
@ -17,7 +17,7 @@ public interface Channel {
|
||||||
S2CPacketType<MsgPlayerCapabilities> SERVER_PLAYER_CAPABILITIES = SimpleNetworking.serverToClient(Unicopia.id("player_capabilities"), MsgPlayerCapabilities::new);
|
S2CPacketType<MsgPlayerCapabilities> SERVER_PLAYER_CAPABILITIES = SimpleNetworking.serverToClient(Unicopia.id("player_capabilities"), MsgPlayerCapabilities::new);
|
||||||
S2CPacketType<MsgSpawnProjectile> SERVER_SPAWN_PROJECTILE = SimpleNetworking.serverToClient(Unicopia.id("projectile_entity"), MsgSpawnProjectile::new);
|
S2CPacketType<MsgSpawnProjectile> SERVER_SPAWN_PROJECTILE = SimpleNetworking.serverToClient(Unicopia.id("projectile_entity"), MsgSpawnProjectile::new);
|
||||||
S2CPacketType<MsgBlockDestruction> SERVER_BLOCK_DESTRUCTION = SimpleNetworking.serverToClient(Unicopia.id("block_destruction"), MsgBlockDestruction::new);
|
S2CPacketType<MsgBlockDestruction> SERVER_BLOCK_DESTRUCTION = SimpleNetworking.serverToClient(Unicopia.id("block_destruction"), MsgBlockDestruction::new);
|
||||||
S2CPacketType<MsgCancelPlayerAbility> CANCEL_PLAYER_ABILITY = SimpleNetworking.serverToClient(Unicopia.id("player_ability_cancel"), MsgCancelPlayerAbility::new);
|
S2CPacketType<MsgCancelPlayerAbility> CANCEL_PLAYER_ABILITY = SimpleNetworking.serverToClient(Unicopia.id("player_ability_cancel"), MsgCancelPlayerAbility::read);
|
||||||
S2CPacketType<MsgUnlockTraits> UNLOCK_TRAITS = SimpleNetworking.serverToClient(Unicopia.id("unlock_traits"), MsgUnlockTraits::new);
|
S2CPacketType<MsgUnlockTraits> UNLOCK_TRAITS = SimpleNetworking.serverToClient(Unicopia.id("unlock_traits"), MsgUnlockTraits::new);
|
||||||
|
|
||||||
S2CPacketType<MsgTribeSelect> SERVER_SELECT_TRIBE = SimpleNetworking.serverToClient(Unicopia.id("select_tribe"), MsgTribeSelect::new);
|
S2CPacketType<MsgTribeSelect> SERVER_SELECT_TRIBE = SimpleNetworking.serverToClient(Unicopia.id("select_tribe"), MsgTribeSelect::new);
|
||||||
|
@ -42,7 +42,7 @@ public interface Channel {
|
||||||
pony.setSpecies(race);
|
pony.setSpecies(race);
|
||||||
Unicopia.LOGGER.info("Setting {}'s race to {} due to host setting", handler.player.getDisplayName().getString(), Race.REGISTRY.getId(race).toString());
|
Unicopia.LOGGER.info("Setting {}'s race to {} due to host setting", handler.player.getDisplayName().getString(), Race.REGISTRY.getId(race).toString());
|
||||||
} else {
|
} else {
|
||||||
sender.sendPacket(SERVER_SELECT_TRIBE.id(), new MsgTribeSelect(handler.player).toBuffer());
|
sender.sendPacket(SERVER_SELECT_TRIBE.id(), new MsgTribeSelect(Race.allPermitted(handler.player)).toBuffer());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sender.sendPacket(SERVER_RESOURCES_SEND.id(), new MsgServerResources().toBuffer());
|
sender.sendPacket(SERVER_RESOURCES_SEND.id(), new MsgServerResources().toBuffer());
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package com.minelittlepony.unicopia.network;
|
package com.minelittlepony.unicopia.network;
|
||||||
|
|
||||||
import com.minelittlepony.unicopia.InteractionManager;
|
|
||||||
import com.sollace.fabwork.api.packets.Packet;
|
import com.sollace.fabwork.api.packets.Packet;
|
||||||
|
|
||||||
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
|
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
|
||||||
|
@ -11,26 +10,15 @@ import net.minecraft.entity.player.PlayerEntity;
|
||||||
/**
|
/**
|
||||||
* Sent by the server to update block destruction progress on the client.
|
* Sent by the server to update block destruction progress on the client.
|
||||||
*/
|
*/
|
||||||
public class MsgBlockDestruction implements Packet<PlayerEntity> {
|
public record MsgBlockDestruction (Long2ObjectMap<Float> destructions) implements Packet<PlayerEntity> {
|
||||||
|
|
||||||
private final Long2ObjectMap<Float> destructions;
|
|
||||||
|
|
||||||
MsgBlockDestruction(PacketByteBuf buffer) {
|
MsgBlockDestruction(PacketByteBuf buffer) {
|
||||||
destructions = new Long2ObjectOpenHashMap<>();
|
this(new Long2ObjectOpenHashMap<>());
|
||||||
int size = buffer.readInt();
|
int size = buffer.readInt();
|
||||||
for (int i = 0; i < size; i++) {
|
for (int i = 0; i < size; i++) {
|
||||||
destructions.put(buffer.readLong(), (Float)buffer.readFloat());
|
destructions.put(buffer.readLong(), (Float)buffer.readFloat());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public MsgBlockDestruction(Long2ObjectMap<Float> destructions) {
|
|
||||||
this.destructions = destructions;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Long2ObjectMap<Float> getDestructions() {
|
|
||||||
return destructions;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void toBuffer(PacketByteBuf buffer) {
|
public void toBuffer(PacketByteBuf buffer) {
|
||||||
buffer.writeInt(destructions.size());
|
buffer.writeInt(destructions.size());
|
||||||
|
@ -41,7 +29,5 @@ public class MsgBlockDestruction implements Packet<PlayerEntity> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handle(PlayerEntity sender) {
|
public void handle(PlayerEntity sender) {}
|
||||||
InteractionManager.instance().getClientNetworkHandler().handleBlockDestruction(this);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package com.minelittlepony.unicopia.network;
|
package com.minelittlepony.unicopia.network;
|
||||||
|
|
||||||
import com.minelittlepony.unicopia.InteractionManager;
|
|
||||||
import com.sollace.fabwork.api.packets.Packet;
|
import com.sollace.fabwork.api.packets.Packet;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.network.PacketByteBuf;
|
import net.minecraft.network.PacketByteBuf;
|
||||||
|
@ -8,20 +7,16 @@ import net.minecraft.network.PacketByteBuf;
|
||||||
/**
|
/**
|
||||||
* Sent to the client when an ability fails its server-side activation checks.
|
* Sent to the client when an ability fails its server-side activation checks.
|
||||||
*/
|
*/
|
||||||
public class MsgCancelPlayerAbility implements Packet<PlayerEntity> {
|
public final class MsgCancelPlayerAbility implements Packet<PlayerEntity> {
|
||||||
|
static final MsgCancelPlayerAbility INSTANCE = new MsgCancelPlayerAbility();
|
||||||
|
|
||||||
MsgCancelPlayerAbility(PacketByteBuf buffer) {
|
static MsgCancelPlayerAbility read(PacketByteBuf buffer) {
|
||||||
}
|
return INSTANCE;
|
||||||
|
|
||||||
public MsgCancelPlayerAbility() {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void toBuffer(PacketByteBuf buffer) {
|
public void toBuffer(PacketByteBuf buffer) { }
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handle(PlayerEntity sender) {
|
public void handle(PlayerEntity sender) { }
|
||||||
InteractionManager.instance().getClientNetworkHandler().handleCancelAbility(this);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,21 +10,15 @@ import com.sollace.fabwork.api.packets.Packet;
|
||||||
import net.minecraft.network.PacketByteBuf;
|
import net.minecraft.network.PacketByteBuf;
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
|
|
||||||
public class MsgMarkTraitRead implements Packet<ServerPlayerEntity> {
|
public record MsgMarkTraitRead (Set<Trait> traits) implements Packet<ServerPlayerEntity> {
|
||||||
|
|
||||||
public final Set<Trait> traits = new HashSet<>();
|
|
||||||
|
|
||||||
MsgMarkTraitRead(PacketByteBuf buffer) {
|
MsgMarkTraitRead(PacketByteBuf buffer) {
|
||||||
|
this(new HashSet<>());
|
||||||
int length = buffer.readInt();
|
int length = buffer.readInt();
|
||||||
for (int i = 0; i < length; i++) {
|
for (int i = 0; i < length; i++) {
|
||||||
Trait.fromId(buffer.readIdentifier()).ifPresent(traits::add);
|
Trait.fromId(buffer.readIdentifier()).ifPresent(traits::add);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public MsgMarkTraitRead(Set<Trait> traits) {
|
|
||||||
this.traits.addAll(traits);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void toBuffer(PacketByteBuf buffer) {
|
public void toBuffer(PacketByteBuf buffer) {
|
||||||
buffer.writeInt(traits.size());
|
buffer.writeInt(traits.size());
|
||||||
|
|
|
@ -17,7 +17,6 @@ public class MsgOtherPlayerCapabilities extends MsgPlayerCapabilities {
|
||||||
|
|
||||||
public MsgOtherPlayerCapabilities(Pony player) {
|
public MsgOtherPlayerCapabilities(Pony player) {
|
||||||
super(player);
|
super(player);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -15,22 +15,20 @@ import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
/**
|
/**
|
||||||
* Sent to the server when a player activates an ability.
|
* Sent to the server when a player activates an ability.
|
||||||
*/
|
*/
|
||||||
public class MsgPlayerAbility<T extends Hit> implements Packet<ServerPlayerEntity> {
|
public record MsgPlayerAbility<T extends Hit> (
|
||||||
private final Ability<T> power;
|
Ability<T> power,
|
||||||
private final Optional<T> data;
|
Optional<T> data,
|
||||||
private final ActivationType type;
|
ActivationType type
|
||||||
|
) implements Packet<ServerPlayerEntity> {
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
MsgPlayerAbility(PacketByteBuf buffer) {
|
static <T extends Hit> MsgPlayerAbility<T> read(PacketByteBuf buffer) {
|
||||||
power = (Ability<T>) Abilities.REGISTRY.get(buffer.readIdentifier());
|
Ability<T> power = (Ability<T>) Abilities.REGISTRY.get(buffer.readIdentifier());
|
||||||
data = buffer.readOptional(power.getSerializer()::fromBuffer);
|
return new MsgPlayerAbility<>(
|
||||||
type = ActivationType.of(buffer.readInt());
|
power,
|
||||||
}
|
buffer.readOptional(power.getSerializer()::fromBuffer),
|
||||||
|
ActivationType.of(buffer.readInt())
|
||||||
public MsgPlayerAbility(Ability<T> power, Optional<T> data, ActivationType type) {
|
);
|
||||||
this.power = power;
|
|
||||||
this.data = data;
|
|
||||||
this.type = type;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -13,21 +13,18 @@ import net.minecraft.network.PacketByteBuf;
|
||||||
/**
|
/**
|
||||||
* Sent to the client when a player's animation changes.
|
* Sent to the client when a player's animation changes.
|
||||||
*/
|
*/
|
||||||
public class MsgPlayerAnimationChange implements Packet<PlayerEntity> {
|
public record MsgPlayerAnimationChange (
|
||||||
private final UUID playerId;
|
UUID playerId,
|
||||||
private final Animation animation;
|
Animation animation,
|
||||||
private final int duration;
|
int duration
|
||||||
|
) implements Packet<PlayerEntity> {
|
||||||
|
|
||||||
MsgPlayerAnimationChange(PacketByteBuf buffer) {
|
MsgPlayerAnimationChange(PacketByteBuf buffer) {
|
||||||
playerId = buffer.readUuid();
|
this(buffer.readUuid(), buffer.readEnumConstant(Animation.class), buffer.readInt());
|
||||||
animation = Animation.values()[buffer.readInt()];
|
|
||||||
duration = buffer.readInt();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public MsgPlayerAnimationChange(Pony player, Animation animation, int duration) {
|
public MsgPlayerAnimationChange(Pony player, Animation animation, int duration) {
|
||||||
this.playerId = player.asEntity().getUuid();
|
this(player.asEntity().getUuid(), animation, duration);
|
||||||
this.animation = animation;
|
|
||||||
this.duration = duration;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -12,15 +12,13 @@ import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
/**
|
/**
|
||||||
* Sent to the server when a player activates an ability.
|
* Sent to the server when a player activates an ability.
|
||||||
*/
|
*/
|
||||||
public class MsgRemoveSpell implements Packet<ServerPlayerEntity> {
|
public record MsgRemoveSpell (UUID id) implements Packet<ServerPlayerEntity> {
|
||||||
private final UUID id;
|
|
||||||
|
|
||||||
MsgRemoveSpell(PacketByteBuf buffer) {
|
MsgRemoveSpell(PacketByteBuf buffer) {
|
||||||
id = buffer.readUuid();
|
this(buffer.readUuid());
|
||||||
}
|
}
|
||||||
|
|
||||||
public MsgRemoveSpell(Spell spell) {
|
public MsgRemoveSpell(Spell spell) {
|
||||||
id = spell.getUuid();
|
this(spell.getUuid());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -14,23 +14,13 @@ import net.minecraft.server.world.ServerWorld;
|
||||||
* <p>
|
* <p>
|
||||||
* The server responds back with the accepted capabilities and the race the client should use (if the preferred was not permitted)
|
* The server responds back with the accepted capabilities and the race the client should use (if the preferred was not permitted)
|
||||||
*/
|
*/
|
||||||
public class MsgRequestSpeciesChange implements Packet<ServerPlayerEntity> {
|
public record MsgRequestSpeciesChange (
|
||||||
|
boolean force,
|
||||||
private final boolean force;
|
Race newRace
|
||||||
private final Race newRace;
|
) implements Packet<ServerPlayerEntity> {
|
||||||
|
|
||||||
MsgRequestSpeciesChange(PacketByteBuf buffer) {
|
MsgRequestSpeciesChange(PacketByteBuf buffer) {
|
||||||
force = buffer.readBoolean();
|
this(buffer.readBoolean(), buffer.readRegistryValue(Race.REGISTRY));
|
||||||
newRace = buffer.readRegistryValue(Race.REGISTRY);
|
|
||||||
}
|
|
||||||
|
|
||||||
public MsgRequestSpeciesChange(Race newRace) {
|
|
||||||
this(newRace, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public MsgRequestSpeciesChange(Race newRace, boolean force) {
|
|
||||||
this.newRace = newRace;
|
|
||||||
this.force = force;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -12,21 +12,25 @@ import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.network.PacketByteBuf;
|
import net.minecraft.network.PacketByteBuf;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
|
|
||||||
public class MsgServerResources implements Packet<PlayerEntity> {
|
public record MsgServerResources (
|
||||||
public final Map<Identifier, SpellTraits> traits;
|
Map<Identifier, SpellTraits> traits,
|
||||||
public final Map<Identifier, ?> chapters;
|
Map<Identifier, ?> chapters,
|
||||||
public final Map<Identifier, TreeTypeLoader.TreeTypeDef> treeTypes;
|
Map<Identifier, TreeTypeLoader.TreeTypeDef> treeTypes
|
||||||
|
) implements Packet<PlayerEntity> {
|
||||||
public MsgServerResources() {
|
public MsgServerResources() {
|
||||||
traits = SpellTraits.all();
|
this(
|
||||||
chapters = SpellbookChapterLoader.INSTANCE.getChapters();
|
SpellTraits.all(),
|
||||||
treeTypes = TreeTypeLoader.INSTANCE.getEntries();
|
SpellbookChapterLoader.INSTANCE.getChapters(),
|
||||||
|
TreeTypeLoader.INSTANCE.getEntries()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public MsgServerResources(PacketByteBuf buffer) {
|
public MsgServerResources(PacketByteBuf buffer) {
|
||||||
traits = buffer.readMap(PacketByteBuf::readIdentifier, SpellTraits::fromPacket);
|
this(
|
||||||
chapters = InteractionManager.instance().getClientNetworkHandler().readChapters(buffer);
|
buffer.readMap(PacketByteBuf::readIdentifier, SpellTraits::fromPacket),
|
||||||
treeTypes = buffer.readMap(PacketByteBuf::readIdentifier, TreeTypeLoader.TreeTypeDef::new);
|
InteractionManager.instance().readChapters(buffer),
|
||||||
|
buffer.readMap(PacketByteBuf::readIdentifier, TreeTypeLoader.TreeTypeDef::new)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -37,7 +41,5 @@ public class MsgServerResources implements Packet<PlayerEntity> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handle(PlayerEntity sender) {
|
public void handle(PlayerEntity sender) { }
|
||||||
InteractionManager.instance().getClientNetworkHandler().handleServerResources(this);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@ package com.minelittlepony.unicopia.network;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import com.minelittlepony.unicopia.InteractionManager;
|
|
||||||
import com.minelittlepony.unicopia.Owned;
|
import com.minelittlepony.unicopia.Owned;
|
||||||
import com.sollace.fabwork.api.packets.Packet;
|
import com.sollace.fabwork.api.packets.Packet;
|
||||||
|
|
||||||
|
@ -30,9 +29,6 @@ public class MsgSpawnProjectile extends EntitySpawnS2CPacket implements Packet<P
|
||||||
write(buffer);
|
write(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handle(PlayerEntity sender) {
|
public void handle(PlayerEntity sender) {}
|
||||||
InteractionManager.instance().getClientNetworkHandler().handleSpawnProjectile(this);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,19 +12,13 @@ import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
* Received by the server when a player changes their opened spellbook's state
|
* Received by the server when a player changes their opened spellbook's state
|
||||||
* Received by the client when another player changes the shared spellbook's state
|
* Received by the client when another player changes the shared spellbook's state
|
||||||
*/
|
*/
|
||||||
public class MsgSpellbookStateChanged<T extends PlayerEntity> implements Packet<T> {
|
public record MsgSpellbookStateChanged<T extends PlayerEntity> (
|
||||||
|
int syncId,
|
||||||
private final int syncId;
|
SpellbookState state
|
||||||
private final SpellbookState state;
|
) implements Packet<T> {
|
||||||
|
|
||||||
public MsgSpellbookStateChanged(int syncId, SpellbookState state) {
|
|
||||||
this.syncId = syncId;
|
|
||||||
this.state = state;
|
|
||||||
}
|
|
||||||
|
|
||||||
public MsgSpellbookStateChanged(PacketByteBuf buffer) {
|
public MsgSpellbookStateChanged(PacketByteBuf buffer) {
|
||||||
syncId = buffer.readInt();
|
this(buffer.readInt(), new SpellbookState().fromPacket(buffer));
|
||||||
state = new SpellbookState().fromPacket(buffer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -35,7 +29,6 @@ public class MsgSpellbookStateChanged<T extends PlayerEntity> implements Packet<
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handle(T sender) {
|
public void handle(T sender) {
|
||||||
|
|
||||||
if (sender.currentScreenHandler.syncId != syncId) {
|
if (sender.currentScreenHandler.syncId != syncId) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,32 +3,21 @@ package com.minelittlepony.unicopia.network;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import com.minelittlepony.unicopia.InteractionManager;
|
|
||||||
import com.minelittlepony.unicopia.Race;
|
import com.minelittlepony.unicopia.Race;
|
||||||
import com.sollace.fabwork.api.packets.Packet;
|
import com.sollace.fabwork.api.packets.Packet;
|
||||||
|
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.network.PacketByteBuf;
|
import net.minecraft.network.PacketByteBuf;
|
||||||
|
|
||||||
public class MsgTribeSelect implements Packet<PlayerEntity> {
|
public record MsgTribeSelect (Set<Race> availableRaces) implements Packet<PlayerEntity> {
|
||||||
private final Set<Race> availableRaces;
|
|
||||||
|
|
||||||
public MsgTribeSelect(PlayerEntity player) {
|
|
||||||
availableRaces = Race.allPermitted(player);
|
|
||||||
}
|
|
||||||
|
|
||||||
public MsgTribeSelect(PacketByteBuf buffer) {
|
public MsgTribeSelect(PacketByteBuf buffer) {
|
||||||
|
this(new HashSet<>());
|
||||||
int len = buffer.readInt();
|
int len = buffer.readInt();
|
||||||
availableRaces = new HashSet<>();
|
|
||||||
while (len-- > 0) {
|
while (len-- > 0) {
|
||||||
availableRaces.add(buffer.readRegistryValue(Race.REGISTRY));
|
availableRaces.add(buffer.readRegistryValue(Race.REGISTRY));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<Race> getRaces() {
|
|
||||||
return availableRaces;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void toBuffer(PacketByteBuf buffer) {
|
public void toBuffer(PacketByteBuf buffer) {
|
||||||
buffer.writeInt(availableRaces.size());
|
buffer.writeInt(availableRaces.size());
|
||||||
|
@ -36,7 +25,5 @@ public class MsgTribeSelect implements Packet<PlayerEntity> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handle(PlayerEntity sender) {
|
public void handle(PlayerEntity sender) {}
|
||||||
InteractionManager.instance().getClientNetworkHandler().handleTribeScreen(this);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,18 +3,15 @@ package com.minelittlepony.unicopia.network;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import com.minelittlepony.unicopia.InteractionManager;
|
|
||||||
import com.minelittlepony.unicopia.ability.magic.spell.trait.Trait;
|
import com.minelittlepony.unicopia.ability.magic.spell.trait.Trait;
|
||||||
import com.sollace.fabwork.api.packets.Packet;
|
import com.sollace.fabwork.api.packets.Packet;
|
||||||
|
|
||||||
import net.minecraft.network.PacketByteBuf;
|
import net.minecraft.network.PacketByteBuf;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
|
|
||||||
public class MsgUnlockTraits implements Packet<PlayerEntity> {
|
public record MsgUnlockTraits (Set<Trait> traits) implements Packet<PlayerEntity> {
|
||||||
|
|
||||||
public final Set<Trait> traits = new HashSet<>();
|
|
||||||
|
|
||||||
MsgUnlockTraits(PacketByteBuf buffer) {
|
MsgUnlockTraits(PacketByteBuf buffer) {
|
||||||
|
this(new HashSet<>());
|
||||||
int length = buffer.readInt();
|
int length = buffer.readInt();
|
||||||
for (int i = 0; i < length; i++) {
|
for (int i = 0; i < length; i++) {
|
||||||
Trait.fromId(buffer.readIdentifier()).ifPresent(traits::add);
|
Trait.fromId(buffer.readIdentifier()).ifPresent(traits::add);
|
||||||
|
@ -22,7 +19,7 @@ public class MsgUnlockTraits implements Packet<PlayerEntity> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public MsgUnlockTraits(Set<Trait> traits) {
|
public MsgUnlockTraits(Set<Trait> traits) {
|
||||||
this.traits.addAll(traits);
|
this.traits = new HashSet<>(traits);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -32,7 +29,5 @@ public class MsgUnlockTraits implements Packet<PlayerEntity> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handle(PlayerEntity sender) {
|
public void handle(PlayerEntity sender) { }
|
||||||
InteractionManager.instance().getClientNetworkHandler().handleUnlockTraits(this);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,25 +0,0 @@
|
||||||
package com.minelittlepony.unicopia.network.handler;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import com.minelittlepony.unicopia.network.*;
|
|
||||||
|
|
||||||
import net.minecraft.network.PacketByteBuf;
|
|
||||||
import net.minecraft.util.Identifier;
|
|
||||||
|
|
||||||
public interface ClientNetworkHandler {
|
|
||||||
|
|
||||||
void handleTribeScreen(MsgTribeSelect packet);
|
|
||||||
|
|
||||||
void handleSpawnProjectile(MsgSpawnProjectile packet);
|
|
||||||
|
|
||||||
void handleBlockDestruction(MsgBlockDestruction packet);
|
|
||||||
|
|
||||||
void handleCancelAbility(MsgCancelPlayerAbility packet);
|
|
||||||
|
|
||||||
void handleUnlockTraits(MsgUnlockTraits packet);
|
|
||||||
|
|
||||||
void handleServerResources(MsgServerResources packet);
|
|
||||||
|
|
||||||
Map<Identifier, ?> readChapters(PacketByteBuf buf);
|
|
||||||
}
|
|
|
@ -20,21 +20,27 @@ import com.minelittlepony.unicopia.network.*;
|
||||||
import net.minecraft.client.MinecraftClient;
|
import net.minecraft.client.MinecraftClient;
|
||||||
import net.minecraft.client.world.ClientWorld;
|
import net.minecraft.client.world.ClientWorld;
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.network.PacketByteBuf;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
|
|
||||||
public class ClientNetworkHandlerImpl implements ClientNetworkHandler {
|
public class ClientNetworkHandlerImpl {
|
||||||
|
|
||||||
private final MinecraftClient client = MinecraftClient.getInstance();
|
private final MinecraftClient client = MinecraftClient.getInstance();
|
||||||
|
|
||||||
@Override
|
public ClientNetworkHandlerImpl() {
|
||||||
public void handleTribeScreen(MsgTribeSelect packet) {
|
Channel.SERVER_SELECT_TRIBE.receiver().addPersistentListener(this::handleTribeScreen);
|
||||||
client.setScreen(new TribeSelectionScreen(packet.getRaces()));
|
Channel.SERVER_SPAWN_PROJECTILE.receiver().addPersistentListener(this::handleSpawnProjectile);
|
||||||
|
Channel.SERVER_BLOCK_DESTRUCTION.receiver().addPersistentListener(this::handleBlockDestruction);
|
||||||
|
Channel.CANCEL_PLAYER_ABILITY.receiver().addPersistentListener(this::handleCancelAbility);
|
||||||
|
Channel.UNLOCK_TRAITS.receiver().addPersistentListener(this::handleUnlockTraits);
|
||||||
|
Channel.SERVER_RESOURCES_SEND.receiver().addPersistentListener(this::handleServerResources);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleTribeScreen(PlayerEntity sender, MsgTribeSelect packet) {
|
||||||
|
client.setScreen(new TribeSelectionScreen(packet.availableRaces()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
private void handleSpawnProjectile(PlayerEntity sender, MsgSpawnProjectile packet) {
|
||||||
public void handleSpawnProjectile(MsgSpawnProjectile packet) {
|
|
||||||
ClientWorld world = client.world;
|
ClientWorld world = client.world;
|
||||||
Entity entity = packet.getEntityType().create(world);
|
Entity entity = packet.getEntityType().create(world);
|
||||||
|
|
||||||
|
@ -57,38 +63,29 @@ public class ClientNetworkHandlerImpl implements ClientNetworkHandler {
|
||||||
world.addEntity(packet.getId(), entity);
|
world.addEntity(packet.getId(), entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private void handleBlockDestruction(PlayerEntity sender, MsgBlockDestruction packet) {
|
||||||
public void handleBlockDestruction(MsgBlockDestruction packet) {
|
|
||||||
ClientBlockDestructionManager destr = ((ClientBlockDestructionManager.Source)client.worldRenderer).getDestructionManager();
|
ClientBlockDestructionManager destr = ((ClientBlockDestructionManager.Source)client.worldRenderer).getDestructionManager();
|
||||||
|
|
||||||
packet.getDestructions().forEach((i, d) -> {
|
packet.destructions().forEach((i, d) -> {
|
||||||
destr.setBlockDestruction(i, d);
|
destr.setBlockDestruction(i, d);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private void handleCancelAbility(PlayerEntity sender, MsgCancelPlayerAbility packet) {
|
||||||
public void handleCancelAbility(MsgCancelPlayerAbility packet) {
|
|
||||||
client.player.playSound(USounds.GUI_ABILITY_FAIL, 1, 1);
|
client.player.playSound(USounds.GUI_ABILITY_FAIL, 1, 1);
|
||||||
Pony.of(client.player).getAbilities().getStats().forEach(s -> s.setCooldown(0));
|
Pony.of(client.player).getAbilities().getStats().forEach(s -> s.setCooldown(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private void handleUnlockTraits(PlayerEntity sender, MsgUnlockTraits packet) {
|
||||||
public void handleUnlockTraits(MsgUnlockTraits packet) {
|
for (Trait trait : packet.traits()) {
|
||||||
for (Trait trait : packet.traits) {
|
|
||||||
DiscoveryToast.show(client.getToastManager(), trait.getSprite());
|
DiscoveryToast.show(client.getToastManager(), trait.getSprite());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Map<Identifier, ?> readChapters(PacketByteBuf buffer) {
|
|
||||||
return buffer.readMap(PacketByteBuf::readIdentifier, ClientChapters::loadChapter);
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
private void handleServerResources(PlayerEntity sender, MsgServerResources packet) {
|
||||||
public void handleServerResources(MsgServerResources packet) {
|
SpellTraits.load(packet.traits());
|
||||||
SpellTraits.load(packet.traits);
|
ClientChapters.load((Map<Identifier, Chapter>)packet.chapters());
|
||||||
ClientChapters.load((Map<Identifier, Chapter>)packet.chapters);
|
TreeTypes.load(packet.treeTypes());
|
||||||
TreeTypes.load(packet.treeTypes);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue