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=
|
||||
|
||||
# Dependencies
|
||||
fabwork_version=1.0.1
|
||||
fabwork_version=1.1.0
|
||||
modmenu_version=5.0.0-alpha.3
|
||||
minelp_version=4.7.2
|
||||
kirin_version=1.13.2
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.minelittlepony.unicopia;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
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.block.data.Ether;
|
||||
import com.minelittlepony.unicopia.entity.player.dummy.DummyPlayerEntity;
|
||||
import com.minelittlepony.unicopia.network.handler.ClientNetworkHandler;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.network.PacketByteBuf;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.world.BlockView;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
|
@ -41,11 +43,8 @@ public class InteractionManager {
|
|||
return Optional.empty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the client network handler, or throws if called on the server.
|
||||
*/
|
||||
public ClientNetworkHandler getClientNetworkHandler() {
|
||||
throw new NullPointerException("Client network handler called by the server");
|
||||
public Map<Identifier, ?> readChapters(PacketByteBuf buf) {
|
||||
throw new RuntimeException("Method not supported");
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.minelittlepony.unicopia.client;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
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.block.data.Ether;
|
||||
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.entity.player.PlayerPhysics;
|
||||
import com.minelittlepony.unicopia.entity.player.Pony;
|
||||
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 net.minecraft.client.MinecraftClient;
|
||||
|
@ -31,16 +31,17 @@ import net.minecraft.entity.LivingEntity;
|
|||
import net.minecraft.entity.passive.BeeEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.vehicle.AbstractMinecartEntity;
|
||||
import net.minecraft.network.PacketByteBuf;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.sound.SoundCategory;
|
||||
import net.minecraft.sound.SoundEvents;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.random.Random;
|
||||
import net.minecraft.world.BlockView;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class ClientInteractionManager extends InteractionManager {
|
||||
|
||||
private final ClientNetworkHandler handler = new ClientNetworkHandlerImpl();
|
||||
private final MinecraftClient client = MinecraftClient.getInstance();
|
||||
|
||||
private final Optional<CasterView> clientWorld = Optional.of(() -> MinecraftClient.getInstance().world);
|
||||
|
@ -54,9 +55,8 @@ public class ClientInteractionManager extends InteractionManager {
|
|||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public ClientNetworkHandler getClientNetworkHandler() {
|
||||
return handler;
|
||||
public Map<Identifier, ?> readChapters(PacketByteBuf buffer) {
|
||||
return buffer.readMap(PacketByteBuf::readIdentifier, ClientChapters::loadChapter);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -16,6 +16,8 @@ import com.minelittlepony.unicopia.client.render.shader.ViewportShader;
|
|||
import com.minelittlepony.unicopia.container.*;
|
||||
import com.minelittlepony.unicopia.entity.player.PlayerCamera;
|
||||
import com.minelittlepony.unicopia.entity.player.Pony;
|
||||
import com.minelittlepony.unicopia.network.handler.ClientNetworkHandlerImpl;
|
||||
|
||||
import net.fabricmc.api.ClientModInitializer;
|
||||
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
|
||||
import net.fabricmc.fabric.api.client.item.v1.ItemTooltipCallback;
|
||||
|
@ -60,6 +62,7 @@ public class UnicopiaClient implements ClientModInitializer {
|
|||
@Override
|
||||
public void onInitializeClient() {
|
||||
InteractionManager.INSTANCE = new ClientInteractionManager();
|
||||
new ClientNetworkHandlerImpl();
|
||||
|
||||
KeyBindingsHandler.bootstrap();
|
||||
URenderers.bootstrap();
|
||||
|
|
|
@ -78,7 +78,7 @@ public class TribeSelectionScreen extends GameGui implements HidesHud {
|
|||
finished = false;
|
||||
|
||||
if (result) {
|
||||
Channel.CLIENT_REQUEST_SPECIES_CHANGE.sendToServer(new MsgRequestSpeciesChange(race, true));
|
||||
Channel.CLIENT_REQUEST_SPECIES_CHANGE.sendToServer(new MsgRequestSpeciesChange(true, race));
|
||||
finish();
|
||||
} else {
|
||||
client.setScreen(this);
|
||||
|
|
|
@ -9,7 +9,7 @@ import net.minecraft.entity.player.PlayerEntity;
|
|||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
|
||||
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<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);
|
||||
|
@ -17,7 +17,7 @@ public interface Channel {
|
|||
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<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<MsgTribeSelect> SERVER_SELECT_TRIBE = SimpleNetworking.serverToClient(Unicopia.id("select_tribe"), MsgTribeSelect::new);
|
||||
|
@ -42,7 +42,7 @@ public interface Channel {
|
|||
pony.setSpecies(race);
|
||||
Unicopia.LOGGER.info("Setting {}'s race to {} due to host setting", handler.player.getDisplayName().getString(), Race.REGISTRY.getId(race).toString());
|
||||
} 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());
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package com.minelittlepony.unicopia.network;
|
||||
|
||||
import com.minelittlepony.unicopia.InteractionManager;
|
||||
import com.sollace.fabwork.api.packets.Packet;
|
||||
|
||||
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.
|
||||
*/
|
||||
public class MsgBlockDestruction implements Packet<PlayerEntity> {
|
||||
|
||||
private final Long2ObjectMap<Float> destructions;
|
||||
|
||||
public record MsgBlockDestruction (Long2ObjectMap<Float> destructions) implements Packet<PlayerEntity> {
|
||||
MsgBlockDestruction(PacketByteBuf buffer) {
|
||||
destructions = new Long2ObjectOpenHashMap<>();
|
||||
this(new Long2ObjectOpenHashMap<>());
|
||||
int size = buffer.readInt();
|
||||
for (int i = 0; i < size; i++) {
|
||||
destructions.put(buffer.readLong(), (Float)buffer.readFloat());
|
||||
}
|
||||
}
|
||||
|
||||
public MsgBlockDestruction(Long2ObjectMap<Float> destructions) {
|
||||
this.destructions = destructions;
|
||||
}
|
||||
|
||||
public Long2ObjectMap<Float> getDestructions() {
|
||||
return destructions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBuffer(PacketByteBuf buffer) {
|
||||
buffer.writeInt(destructions.size());
|
||||
|
@ -41,7 +29,5 @@ public class MsgBlockDestruction implements Packet<PlayerEntity> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handle(PlayerEntity sender) {
|
||||
InteractionManager.instance().getClientNetworkHandler().handleBlockDestruction(this);
|
||||
}
|
||||
public void handle(PlayerEntity sender) {}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package com.minelittlepony.unicopia.network;
|
||||
|
||||
import com.minelittlepony.unicopia.InteractionManager;
|
||||
import com.sollace.fabwork.api.packets.Packet;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
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.
|
||||
*/
|
||||
public class MsgCancelPlayerAbility implements Packet<PlayerEntity> {
|
||||
public final class MsgCancelPlayerAbility implements Packet<PlayerEntity> {
|
||||
static final MsgCancelPlayerAbility INSTANCE = new MsgCancelPlayerAbility();
|
||||
|
||||
MsgCancelPlayerAbility(PacketByteBuf buffer) {
|
||||
}
|
||||
|
||||
public MsgCancelPlayerAbility() {
|
||||
static MsgCancelPlayerAbility read(PacketByteBuf buffer) {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBuffer(PacketByteBuf buffer) {
|
||||
}
|
||||
public void toBuffer(PacketByteBuf buffer) { }
|
||||
|
||||
@Override
|
||||
public void handle(PlayerEntity sender) {
|
||||
InteractionManager.instance().getClientNetworkHandler().handleCancelAbility(this);
|
||||
}
|
||||
public void handle(PlayerEntity sender) { }
|
||||
}
|
||||
|
|
|
@ -10,21 +10,15 @@ import com.sollace.fabwork.api.packets.Packet;
|
|||
import net.minecraft.network.PacketByteBuf;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
|
||||
public class MsgMarkTraitRead implements Packet<ServerPlayerEntity> {
|
||||
|
||||
public final Set<Trait> traits = new HashSet<>();
|
||||
|
||||
public record MsgMarkTraitRead (Set<Trait> traits) implements Packet<ServerPlayerEntity> {
|
||||
MsgMarkTraitRead(PacketByteBuf buffer) {
|
||||
this(new HashSet<>());
|
||||
int length = buffer.readInt();
|
||||
for (int i = 0; i < length; i++) {
|
||||
Trait.fromId(buffer.readIdentifier()).ifPresent(traits::add);
|
||||
}
|
||||
}
|
||||
|
||||
public MsgMarkTraitRead(Set<Trait> traits) {
|
||||
this.traits.addAll(traits);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBuffer(PacketByteBuf buffer) {
|
||||
buffer.writeInt(traits.size());
|
||||
|
|
|
@ -17,7 +17,6 @@ public class MsgOtherPlayerCapabilities extends MsgPlayerCapabilities {
|
|||
|
||||
public MsgOtherPlayerCapabilities(Pony player) {
|
||||
super(player);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -15,22 +15,20 @@ import net.minecraft.server.network.ServerPlayerEntity;
|
|||
/**
|
||||
* Sent to the server when a player activates an ability.
|
||||
*/
|
||||
public class MsgPlayerAbility<T extends Hit> implements Packet<ServerPlayerEntity> {
|
||||
private final Ability<T> power;
|
||||
private final Optional<T> data;
|
||||
private final ActivationType type;
|
||||
public record MsgPlayerAbility<T extends Hit> (
|
||||
Ability<T> power,
|
||||
Optional<T> data,
|
||||
ActivationType type
|
||||
) implements Packet<ServerPlayerEntity> {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
MsgPlayerAbility(PacketByteBuf buffer) {
|
||||
power = (Ability<T>) Abilities.REGISTRY.get(buffer.readIdentifier());
|
||||
data = buffer.readOptional(power.getSerializer()::fromBuffer);
|
||||
type = ActivationType.of(buffer.readInt());
|
||||
}
|
||||
|
||||
public MsgPlayerAbility(Ability<T> power, Optional<T> data, ActivationType type) {
|
||||
this.power = power;
|
||||
this.data = data;
|
||||
this.type = type;
|
||||
static <T extends Hit> MsgPlayerAbility<T> read(PacketByteBuf buffer) {
|
||||
Ability<T> power = (Ability<T>) Abilities.REGISTRY.get(buffer.readIdentifier());
|
||||
return new MsgPlayerAbility<>(
|
||||
power,
|
||||
buffer.readOptional(power.getSerializer()::fromBuffer),
|
||||
ActivationType.of(buffer.readInt())
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -13,21 +13,18 @@ import net.minecraft.network.PacketByteBuf;
|
|||
/**
|
||||
* Sent to the client when a player's animation changes.
|
||||
*/
|
||||
public class MsgPlayerAnimationChange implements Packet<PlayerEntity> {
|
||||
private final UUID playerId;
|
||||
private final Animation animation;
|
||||
private final int duration;
|
||||
public record MsgPlayerAnimationChange (
|
||||
UUID playerId,
|
||||
Animation animation,
|
||||
int duration
|
||||
) implements Packet<PlayerEntity> {
|
||||
|
||||
MsgPlayerAnimationChange(PacketByteBuf buffer) {
|
||||
playerId = buffer.readUuid();
|
||||
animation = Animation.values()[buffer.readInt()];
|
||||
duration = buffer.readInt();
|
||||
this(buffer.readUuid(), buffer.readEnumConstant(Animation.class), buffer.readInt());
|
||||
}
|
||||
|
||||
public MsgPlayerAnimationChange(Pony player, Animation animation, int duration) {
|
||||
this.playerId = player.asEntity().getUuid();
|
||||
this.animation = animation;
|
||||
this.duration = duration;
|
||||
this(player.asEntity().getUuid(), animation, duration);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -12,15 +12,13 @@ import net.minecraft.server.network.ServerPlayerEntity;
|
|||
/**
|
||||
* Sent to the server when a player activates an ability.
|
||||
*/
|
||||
public class MsgRemoveSpell implements Packet<ServerPlayerEntity> {
|
||||
private final UUID id;
|
||||
|
||||
public record MsgRemoveSpell (UUID id) implements Packet<ServerPlayerEntity> {
|
||||
MsgRemoveSpell(PacketByteBuf buffer) {
|
||||
id = buffer.readUuid();
|
||||
this(buffer.readUuid());
|
||||
}
|
||||
|
||||
public MsgRemoveSpell(Spell spell) {
|
||||
id = spell.getUuid();
|
||||
this(spell.getUuid());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -14,23 +14,13 @@ import net.minecraft.server.world.ServerWorld;
|
|||
* <p>
|
||||
* 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> {
|
||||
|
||||
private final boolean force;
|
||||
private final Race newRace;
|
||||
public record MsgRequestSpeciesChange (
|
||||
boolean force,
|
||||
Race newRace
|
||||
) implements Packet<ServerPlayerEntity> {
|
||||
|
||||
MsgRequestSpeciesChange(PacketByteBuf buffer) {
|
||||
force = buffer.readBoolean();
|
||||
newRace = buffer.readRegistryValue(Race.REGISTRY);
|
||||
}
|
||||
|
||||
public MsgRequestSpeciesChange(Race newRace) {
|
||||
this(newRace, false);
|
||||
}
|
||||
|
||||
public MsgRequestSpeciesChange(Race newRace, boolean force) {
|
||||
this.newRace = newRace;
|
||||
this.force = force;
|
||||
this(buffer.readBoolean(), buffer.readRegistryValue(Race.REGISTRY));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -12,21 +12,25 @@ import net.minecraft.entity.player.PlayerEntity;
|
|||
import net.minecraft.network.PacketByteBuf;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
public class MsgServerResources implements Packet<PlayerEntity> {
|
||||
public final Map<Identifier, SpellTraits> traits;
|
||||
public final Map<Identifier, ?> chapters;
|
||||
public final Map<Identifier, TreeTypeLoader.TreeTypeDef> treeTypes;
|
||||
|
||||
public record MsgServerResources (
|
||||
Map<Identifier, SpellTraits> traits,
|
||||
Map<Identifier, ?> chapters,
|
||||
Map<Identifier, TreeTypeLoader.TreeTypeDef> treeTypes
|
||||
) implements Packet<PlayerEntity> {
|
||||
public MsgServerResources() {
|
||||
traits = SpellTraits.all();
|
||||
chapters = SpellbookChapterLoader.INSTANCE.getChapters();
|
||||
treeTypes = TreeTypeLoader.INSTANCE.getEntries();
|
||||
this(
|
||||
SpellTraits.all(),
|
||||
SpellbookChapterLoader.INSTANCE.getChapters(),
|
||||
TreeTypeLoader.INSTANCE.getEntries()
|
||||
);
|
||||
}
|
||||
|
||||
public MsgServerResources(PacketByteBuf buffer) {
|
||||
traits = buffer.readMap(PacketByteBuf::readIdentifier, SpellTraits::fromPacket);
|
||||
chapters = InteractionManager.instance().getClientNetworkHandler().readChapters(buffer);
|
||||
treeTypes = buffer.readMap(PacketByteBuf::readIdentifier, TreeTypeLoader.TreeTypeDef::new);
|
||||
this(
|
||||
buffer.readMap(PacketByteBuf::readIdentifier, SpellTraits::fromPacket),
|
||||
InteractionManager.instance().readChapters(buffer),
|
||||
buffer.readMap(PacketByteBuf::readIdentifier, TreeTypeLoader.TreeTypeDef::new)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -37,7 +41,5 @@ public class MsgServerResources implements Packet<PlayerEntity> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handle(PlayerEntity sender) {
|
||||
InteractionManager.instance().getClientNetworkHandler().handleServerResources(this);
|
||||
}
|
||||
public void handle(PlayerEntity sender) { }
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@ package com.minelittlepony.unicopia.network;
|
|||
|
||||
import java.util.Optional;
|
||||
|
||||
import com.minelittlepony.unicopia.InteractionManager;
|
||||
import com.minelittlepony.unicopia.Owned;
|
||||
import com.sollace.fabwork.api.packets.Packet;
|
||||
|
||||
|
@ -30,9 +29,6 @@ public class MsgSpawnProjectile extends EntitySpawnS2CPacket implements Packet<P
|
|||
write(buffer);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handle(PlayerEntity sender) {
|
||||
InteractionManager.instance().getClientNetworkHandler().handleSpawnProjectile(this);
|
||||
}
|
||||
public void handle(PlayerEntity sender) {}
|
||||
}
|
||||
|
|
|
@ -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 client when another player changes the shared spellbook's state
|
||||
*/
|
||||
public class MsgSpellbookStateChanged<T extends PlayerEntity> implements Packet<T> {
|
||||
|
||||
private final int syncId;
|
||||
private final SpellbookState state;
|
||||
|
||||
public MsgSpellbookStateChanged(int syncId, SpellbookState state) {
|
||||
this.syncId = syncId;
|
||||
this.state = state;
|
||||
}
|
||||
public record MsgSpellbookStateChanged<T extends PlayerEntity> (
|
||||
int syncId,
|
||||
SpellbookState state
|
||||
) implements Packet<T> {
|
||||
|
||||
public MsgSpellbookStateChanged(PacketByteBuf buffer) {
|
||||
syncId = buffer.readInt();
|
||||
state = new SpellbookState().fromPacket(buffer);
|
||||
this(buffer.readInt(), new SpellbookState().fromPacket(buffer));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -35,7 +29,6 @@ public class MsgSpellbookStateChanged<T extends PlayerEntity> implements Packet<
|
|||
|
||||
@Override
|
||||
public void handle(T sender) {
|
||||
|
||||
if (sender.currentScreenHandler.syncId != syncId) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -3,32 +3,21 @@ package com.minelittlepony.unicopia.network;
|
|||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import com.minelittlepony.unicopia.InteractionManager;
|
||||
import com.minelittlepony.unicopia.Race;
|
||||
import com.sollace.fabwork.api.packets.Packet;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.network.PacketByteBuf;
|
||||
|
||||
public class MsgTribeSelect implements Packet<PlayerEntity> {
|
||||
private final Set<Race> availableRaces;
|
||||
|
||||
public MsgTribeSelect(PlayerEntity player) {
|
||||
availableRaces = Race.allPermitted(player);
|
||||
}
|
||||
|
||||
public record MsgTribeSelect (Set<Race> availableRaces) implements Packet<PlayerEntity> {
|
||||
public MsgTribeSelect(PacketByteBuf buffer) {
|
||||
this(new HashSet<>());
|
||||
int len = buffer.readInt();
|
||||
availableRaces = new HashSet<>();
|
||||
while (len-- > 0) {
|
||||
availableRaces.add(buffer.readRegistryValue(Race.REGISTRY));
|
||||
}
|
||||
}
|
||||
|
||||
public Set<Race> getRaces() {
|
||||
return availableRaces;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBuffer(PacketByteBuf buffer) {
|
||||
buffer.writeInt(availableRaces.size());
|
||||
|
@ -36,7 +25,5 @@ public class MsgTribeSelect implements Packet<PlayerEntity> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handle(PlayerEntity sender) {
|
||||
InteractionManager.instance().getClientNetworkHandler().handleTribeScreen(this);
|
||||
}
|
||||
public void handle(PlayerEntity sender) {}
|
||||
}
|
||||
|
|
|
@ -3,18 +3,15 @@ package com.minelittlepony.unicopia.network;
|
|||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import com.minelittlepony.unicopia.InteractionManager;
|
||||
import com.minelittlepony.unicopia.ability.magic.spell.trait.Trait;
|
||||
import com.sollace.fabwork.api.packets.Packet;
|
||||
|
||||
import net.minecraft.network.PacketByteBuf;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
|
||||
public class MsgUnlockTraits implements Packet<PlayerEntity> {
|
||||
|
||||
public final Set<Trait> traits = new HashSet<>();
|
||||
|
||||
public record MsgUnlockTraits (Set<Trait> traits) implements Packet<PlayerEntity> {
|
||||
MsgUnlockTraits(PacketByteBuf buffer) {
|
||||
this(new HashSet<>());
|
||||
int length = buffer.readInt();
|
||||
for (int i = 0; i < length; i++) {
|
||||
Trait.fromId(buffer.readIdentifier()).ifPresent(traits::add);
|
||||
|
@ -22,7 +19,7 @@ public class MsgUnlockTraits implements Packet<PlayerEntity> {
|
|||
}
|
||||
|
||||
public MsgUnlockTraits(Set<Trait> traits) {
|
||||
this.traits.addAll(traits);
|
||||
this.traits = new HashSet<>(traits);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -32,7 +29,5 @@ public class MsgUnlockTraits implements Packet<PlayerEntity> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handle(PlayerEntity sender) {
|
||||
InteractionManager.instance().getClientNetworkHandler().handleUnlockTraits(this);
|
||||
}
|
||||
public void handle(PlayerEntity sender) { }
|
||||
}
|
||||
|
|
|
@ -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.world.ClientWorld;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.network.PacketByteBuf;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
public class ClientNetworkHandlerImpl implements ClientNetworkHandler {
|
||||
|
||||
public class ClientNetworkHandlerImpl {
|
||||
private final MinecraftClient client = MinecraftClient.getInstance();
|
||||
|
||||
@Override
|
||||
public void handleTribeScreen(MsgTribeSelect packet) {
|
||||
client.setScreen(new TribeSelectionScreen(packet.getRaces()));
|
||||
public ClientNetworkHandlerImpl() {
|
||||
Channel.SERVER_SELECT_TRIBE.receiver().addPersistentListener(this::handleTribeScreen);
|
||||
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")
|
||||
@Override
|
||||
public void handleSpawnProjectile(MsgSpawnProjectile packet) {
|
||||
private void handleSpawnProjectile(PlayerEntity sender, MsgSpawnProjectile packet) {
|
||||
ClientWorld world = client.world;
|
||||
Entity entity = packet.getEntityType().create(world);
|
||||
|
||||
|
@ -57,38 +63,29 @@ public class ClientNetworkHandlerImpl implements ClientNetworkHandler {
|
|||
world.addEntity(packet.getId(), entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleBlockDestruction(MsgBlockDestruction packet) {
|
||||
private void handleBlockDestruction(PlayerEntity sender, MsgBlockDestruction packet) {
|
||||
ClientBlockDestructionManager destr = ((ClientBlockDestructionManager.Source)client.worldRenderer).getDestructionManager();
|
||||
|
||||
packet.getDestructions().forEach((i, d) -> {
|
||||
packet.destructions().forEach((i, d) -> {
|
||||
destr.setBlockDestruction(i, d);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleCancelAbility(MsgCancelPlayerAbility packet) {
|
||||
private void handleCancelAbility(PlayerEntity sender, MsgCancelPlayerAbility packet) {
|
||||
client.player.playSound(USounds.GUI_ABILITY_FAIL, 1, 1);
|
||||
Pony.of(client.player).getAbilities().getStats().forEach(s -> s.setCooldown(0));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleUnlockTraits(MsgUnlockTraits packet) {
|
||||
for (Trait trait : packet.traits) {
|
||||
private void handleUnlockTraits(PlayerEntity sender, MsgUnlockTraits packet) {
|
||||
for (Trait trait : packet.traits()) {
|
||||
DiscoveryToast.show(client.getToastManager(), trait.getSprite());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Identifier, ?> readChapters(PacketByteBuf buffer) {
|
||||
return buffer.readMap(PacketByteBuf::readIdentifier, ClientChapters::loadChapter);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void handleServerResources(MsgServerResources packet) {
|
||||
SpellTraits.load(packet.traits);
|
||||
ClientChapters.load((Map<Identifier, Chapter>)packet.chapters);
|
||||
TreeTypes.load(packet.treeTypes);
|
||||
private void handleServerResources(PlayerEntity sender, MsgServerResources packet) {
|
||||
SpellTraits.load(packet.traits());
|
||||
ClientChapters.load((Map<Identifier, Chapter>)packet.chapters());
|
||||
TreeTypes.load(packet.treeTypes());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue