Fixed issues whilst running on a dedicated server

This commit is contained in:
Sollace 2021-01-21 10:41:28 +02:00
parent f537079b1b
commit afe820b704
7 changed files with 46 additions and 17 deletions

View file

@ -51,7 +51,7 @@ public interface Toxics {
Toxic toxic = new Toxic(action, type, lowerBound, upperbound);
ToxicHolder holder = (ToxicHolder)target;
holder.setToxic(toxic);
holder.setFood(Objects.requireNonNull(food, target.getName().toString() + " food"));
holder.setFood(Objects.requireNonNull(food, target.getTranslationKey() + " food"));
return toxic;
}

View file

@ -1,26 +1,20 @@
package com.minelittlepony.unicopia.mixin;
import java.util.List;
import java.util.Optional;
import javax.annotation.Nullable;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import com.minelittlepony.unicopia.item.toxin.Toxic;
import com.minelittlepony.unicopia.item.toxin.ToxicHolder;
import net.minecraft.client.item.TooltipContext;
import net.minecraft.entity.LivingEntity;
import net.minecraft.item.FoodComponent;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.text.Text;
import net.minecraft.world.World;
@Mixin(Item.class)
@ -42,11 +36,6 @@ abstract class MixinItem implements ToxicHolder {
return toxic;
}
@Inject(method = "appendTooltip", at = @At("RETURN"))
private void onAppendTooltip(ItemStack stack, @Nullable World world, List<Text> tooltip, TooltipContext context, CallbackInfo into) {
toxic.ifPresent(t -> tooltip.add(t.getTooltip(stack)));
}
@Inject(method = "finishUsing", at = @At("HEAD"), cancellable = true)
private void finishUsing(ItemStack stack, World world, LivingEntity entity, CallbackInfoReturnable<ItemStack> info) {
if (getToxic().isPresent()) {

View file

@ -17,8 +17,10 @@ abstract class MixinItems {
index = 1,
argsOnly = true)
private static Item modifyItem(Item item, Identifier id, Item itemAlso) {
if (VanillaOverrides.REGISTRY.containsId(id)) {
return VanillaOverrides.REGISTRY.get(id);
// Registry#containsId is client-only :thonkjang:
Item replacement = VanillaOverrides.REGISTRY.get(id);
if (replacement != null) {
return replacement;
}
return item;
}

View file

@ -0,0 +1,24 @@
package com.minelittlepony.unicopia.mixin.client;
import java.util.List;
import javax.annotation.Nullable;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import com.minelittlepony.unicopia.item.toxin.ToxicHolder;
import net.minecraft.client.item.TooltipContext;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.text.Text;
import net.minecraft.world.World;
@Mixin(Item.class)
abstract class MixinItem implements ToxicHolder {
@Inject(method = "appendTooltip", at = @At("RETURN"))
private void onAppendTooltip(ItemStack stack, @Nullable World world, List<Text> tooltip, TooltipContext context, CallbackInfo into) {
getToxic().ifPresent(t -> tooltip.add(t.getTooltip(stack)));
}
}

View file

@ -3,9 +3,11 @@ package com.minelittlepony.unicopia.network;
import java.util.function.Function;
import io.netty.buffer.Unpooled;
import net.fabricmc.api.EnvType;
import net.fabricmc.fabric.api.network.ClientSidePacketRegistry;
import net.fabricmc.fabric.api.network.PacketContext;
import net.fabricmc.fabric.api.network.ServerSidePacketRegistry;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.Identifier;
import net.minecraft.network.PacketByteBuf;
@ -14,6 +16,7 @@ public interface Channel {
SPacketType<MsgPlayerAbility<?>> CLIENT_PLAYER_ABILITY = clientToServer(new Identifier("unicopia", "player_ability"), MsgPlayerAbility::new);
SPacketType<MsgRequestCapabilities> CLIENT_REQUEST_CAPABILITIES = clientToServer(new Identifier("unicopia", "request_capabilities"), MsgRequestCapabilities::new);
CPacketType<MsgPlayerCapabilities> SERVER_PLAYER_CAPABILITIES = serverToClient(new Identifier("unicopia", "player_capabilities"), MsgPlayerCapabilities::new);
MPacketType<MsgOtherPlayerCapabilities> SERVER_OTHER_PLAYER_CAPABILITIES = serverToClients(new Identifier("unicopia", "other_player_capabilities"), MsgOtherPlayerCapabilities::new);
CPacketType<MsgSpawnProjectile> SERVER_SPAWN_PROJECTILE = serverToClient(new Identifier("unicopia", "projectile_entity"), MsgSpawnProjectile::new);
@ -26,12 +29,16 @@ public interface Channel {
}
static <T extends Packet> MPacketType<T> serverToClients(Identifier id, Function<PacketByteBuf, T> factory) {
if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) {
ClientSidePacketRegistry.INSTANCE.register(id, (context, buffer) -> factory.apply(buffer).handleOnMain(context));
}
return () -> id;
}
static <T extends Packet> CPacketType<T> serverToClient(Identifier id, Function<PacketByteBuf, T> factory) {
if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) {
ClientSidePacketRegistry.INSTANCE.register(id, (context, buffer) -> factory.apply(buffer).handleOnMain(context));
}
return () -> id;
}
@ -67,10 +74,16 @@ public interface Channel {
Identifier getId();
default void send(T packet) {
if (FabricLoader.getInstance().getEnvironmentType() != EnvType.CLIENT) {
throw new RuntimeException("Client packet send called by the server");
}
ClientSidePacketRegistry.INSTANCE.sendToServer(getId(), packet.toBuffer());
}
default net.minecraft.network.Packet<?> toPacket(T packet) {
if (FabricLoader.getInstance().getEnvironmentType() != EnvType.CLIENT) {
throw new RuntimeException("Client packet send called by the server");
}
return ClientSidePacketRegistry.INSTANCE.toPacket(getId(), packet.toBuffer());
}
}

View file

@ -17,7 +17,7 @@ public class MsgPlayerAbility<T extends Hit> implements Channel.Packet {
@SuppressWarnings("unchecked")
MsgPlayerAbility(PacketByteBuf buffer) {
power = (Ability<T>) Abilities.REGISTRY.get(new Identifier(buffer.readString()));
power = (Ability<T>) Abilities.REGISTRY.get(new Identifier(buffer.readString(32767)));
data = power.getSerializer().fromBuffer(buffer);
}

View file

@ -27,6 +27,7 @@
"client.MixinEntityRenderDispatcher",
"client.MixinGameRenderer",
"client.MixinInGameHud",
"client.MixinItem",
"client.MixinItemModels",
"client.MixinKeyboardInput",
"client.MixinLightmapTextureManager",