Fix item renderer command doing bad things. Now works on a server :)
Final major thing I noticed when trying to split the client and server.
This commit is contained in:
parent
27cc9d0730
commit
7c02024a2d
3 changed files with 24 additions and 10 deletions
|
@ -31,7 +31,6 @@ import com.mojang.brigadier.arguments.StringArgumentType;
|
||||||
import com.mojang.brigadier.context.CommandContext;
|
import com.mojang.brigadier.context.CommandContext;
|
||||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||||
import com.mojang.brigadier.suggestion.SuggestionProvider;
|
import com.mojang.brigadier.suggestion.SuggestionProvider;
|
||||||
import net.fabricmc.api.EnvType;
|
|
||||||
import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback;
|
import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback;
|
||||||
import net.fabricmc.loader.api.FabricLoader;
|
import net.fabricmc.loader.api.FabricLoader;
|
||||||
import net.minecraft.command.CommandSource;
|
import net.minecraft.command.CommandSource;
|
||||||
|
@ -47,7 +46,9 @@ import net.minecraft.server.world.ServerWorld;
|
||||||
import net.minecraft.text.LiteralText;
|
import net.minecraft.text.LiteralText;
|
||||||
import net.minecraft.util.registry.Registry;
|
import net.minecraft.util.registry.Registry;
|
||||||
import net.minecraft.world.chunk.ChunkStatus;
|
import net.minecraft.world.chunk.ChunkStatus;
|
||||||
import reborncore.client.ItemStackRenderManager;
|
import reborncore.common.network.ClientBoundPackets;
|
||||||
|
import reborncore.common.network.IdentifiedPacket;
|
||||||
|
import reborncore.common.network.NetworkManager;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
@ -162,20 +163,20 @@ public class RebornCoreCommands {
|
||||||
.map(ItemStack::new)
|
.map(ItemStack::new)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
queueRender(list);
|
queueRender(list, ctx);
|
||||||
return Command.SINGLE_SUCCESS;
|
return Command.SINGLE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int itemRenderer(CommandContext<ServerCommandSource> ctx) {
|
private static int itemRenderer(CommandContext<ServerCommandSource> ctx) {
|
||||||
Item item = ItemStackArgumentType.getItemStackArgument(ctx, "item").getItem();
|
Item item = ItemStackArgumentType.getItemStackArgument(ctx, "item").getItem();
|
||||||
queueRender(Collections.singletonList(new ItemStack(item)));
|
queueRender(Collections.singletonList(new ItemStack(item)), ctx);
|
||||||
|
|
||||||
return Command.SINGLE_SUCCESS;
|
return Command.SINGLE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int handRenderer(CommandContext<ServerCommandSource> ctx) {
|
private static int handRenderer(CommandContext<ServerCommandSource> ctx) {
|
||||||
try {
|
try {
|
||||||
queueRender(Collections.singletonList(ctx.getSource().getPlayer().getInventory().getMainHandStack()));
|
queueRender(Collections.singletonList(ctx.getSource().getPlayer().getInventory().getMainHandStack()), ctx);
|
||||||
} catch (CommandSyntaxException e) {
|
} catch (CommandSyntaxException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -184,11 +185,13 @@ public class RebornCoreCommands {
|
||||||
return Command.SINGLE_SUCCESS;
|
return Command.SINGLE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void queueRender(List<ItemStack> stacks) {
|
private static void queueRender(List<ItemStack> stacks, CommandContext<ServerCommandSource> ctx) {
|
||||||
if (FabricLoader.getInstance().getEnvironmentType() == EnvType.SERVER) {
|
IdentifiedPacket packet = ClientBoundPackets.createPacketQueueItemStacksToRender(stacks);
|
||||||
System.out.println("Render item only works on the client!");
|
|
||||||
return;
|
try {
|
||||||
|
NetworkManager.sendToPlayer(packet, ctx.getSource().getPlayer());
|
||||||
|
} catch (CommandSyntaxException e) {
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
ItemStackRenderManager.RENDER_QUEUE.addAll(stacks);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -24,6 +24,7 @@
|
||||||
|
|
||||||
package reborncore.common.network;
|
package reborncore.common.network;
|
||||||
|
|
||||||
|
import com.mojang.serialization.Codec;
|
||||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||||
import net.fabricmc.api.EnvType;
|
import net.fabricmc.api.EnvType;
|
||||||
|
@ -33,6 +34,7 @@ import net.minecraft.client.MinecraftClient;
|
||||||
import net.minecraft.client.gui.hud.ChatHud;
|
import net.minecraft.client.gui.hud.ChatHud;
|
||||||
import net.minecraft.client.gui.screen.Screen;
|
import net.minecraft.client.gui.screen.Screen;
|
||||||
import net.minecraft.client.gui.screen.ingame.HandledScreen;
|
import net.minecraft.client.gui.screen.ingame.HandledScreen;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NbtCompound;
|
import net.minecraft.nbt.NbtCompound;
|
||||||
import net.minecraft.screen.ScreenHandler;
|
import net.minecraft.screen.ScreenHandler;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.text.Text;
|
||||||
|
@ -43,6 +45,7 @@ import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import reborncore.RebornCore;
|
import reborncore.RebornCore;
|
||||||
import reborncore.client.ClientChunkManager;
|
import reborncore.client.ClientChunkManager;
|
||||||
|
import reborncore.client.ItemStackRenderManager;
|
||||||
import reborncore.common.blockentity.FluidConfiguration;
|
import reborncore.common.blockentity.FluidConfiguration;
|
||||||
import reborncore.common.blockentity.MachineBaseBlockEntity;
|
import reborncore.common.blockentity.MachineBaseBlockEntity;
|
||||||
import reborncore.common.blockentity.SlotConfiguration;
|
import reborncore.common.blockentity.SlotConfiguration;
|
||||||
|
@ -151,6 +154,8 @@ public class ClientBoundPacketHandlers {
|
||||||
accessorChatHud.invokeAddMessage(text, deleteID);
|
accessorChatHud.invokeAddMessage(text, deleteID);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
NetworkManager.registerClientBoundHandler(new Identifier("reborncore", "stacks_to_render"), Codec.list(ItemStack.CODEC), ItemStackRenderManager.RENDER_QUEUE::addAll);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,8 +24,10 @@
|
||||||
|
|
||||||
package reborncore.common.network;
|
package reborncore.common.network;
|
||||||
|
|
||||||
|
import com.mojang.serialization.Codec;
|
||||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||||
import net.minecraft.block.entity.BlockEntity;
|
import net.minecraft.block.entity.BlockEntity;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NbtCompound;
|
import net.minecraft.nbt.NbtCompound;
|
||||||
import net.minecraft.screen.ScreenHandler;
|
import net.minecraft.screen.ScreenHandler;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.text.Text;
|
||||||
|
@ -86,4 +88,8 @@ public class ClientBoundPackets {
|
||||||
packetBuffer.writeText(text);
|
packetBuffer.writeText(text);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static IdentifiedPacket createPacketQueueItemStacksToRender(List<ItemStack> stacks) {
|
||||||
|
return NetworkManager.createClientBoundPacket(new Identifier("reborncore", "stacks_to_render"), Codec.list(ItemStack.CODEC), stacks);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue