networking bugfixed
Das networking funktioniert jetzt ohne Probleme mit der richtigen ServerPlayerEntity
This commit is contained in:
parent
8db9e9cf06
commit
74e05e6c7e
|
@ -1,13 +1,21 @@
|
||||||
package modchest.networking.packet;
|
package modchest.networking.packet;
|
||||||
|
|
||||||
|
import static net.minecraft.block.Block.getBlockFromItem;
|
||||||
|
|
||||||
/*import modchest.rendering.gridBlockRender;
|
/*import modchest.rendering.gridBlockRender;
|
||||||
import modchest.rendering.gridBlockTexture;*/
|
import modchest.rendering.gridBlockTexture;*/
|
||||||
import net.fabricmc.fabric.api.networking.v1.PacketSender;
|
import net.fabricmc.fabric.api.networking.v1.PacketSender;
|
||||||
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.client.MinecraftClient;
|
import net.minecraft.client.MinecraftClient;
|
||||||
import net.minecraft.client.color.block.BlockColors;
|
import net.minecraft.client.color.block.BlockColors;
|
||||||
import net.minecraft.client.network.ClientPlayNetworkHandler;
|
import net.minecraft.client.network.ClientPlayNetworkHandler;
|
||||||
|
import net.minecraft.client.network.ClientPlayerEntity;
|
||||||
import net.minecraft.client.render.block.BlockModelRenderer;
|
import net.minecraft.client.render.block.BlockModelRenderer;
|
||||||
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
|
import net.minecraft.nbt.NbtCompound;
|
||||||
import net.minecraft.network.PacketByteBuf;
|
import net.minecraft.network.PacketByteBuf;
|
||||||
|
import net.minecraft.text.Text;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
|
||||||
public class gridRenderRequestS2CPacket extends BlockModelRenderer {
|
public class gridRenderRequestS2CPacket extends BlockModelRenderer {
|
||||||
|
|
||||||
|
@ -19,21 +27,19 @@ public class gridRenderRequestS2CPacket extends BlockModelRenderer {
|
||||||
public static void receive(MinecraftClient minecraftClient, ClientPlayNetworkHandler clientPlayNetworkHandler,
|
public static void receive(MinecraftClient minecraftClient, ClientPlayNetworkHandler clientPlayNetworkHandler,
|
||||||
PacketByteBuf buffer, PacketSender PacketSender) {
|
PacketByteBuf buffer, PacketSender PacketSender) {
|
||||||
// clientPlayNetworkHandler.getWorld();
|
// clientPlayNetworkHandler.getWorld();
|
||||||
// modNetworkingClient.grid_block_networking.;
|
NbtCompound nbtgrid = buffer.readNbt();
|
||||||
// PacketByteBuf buf =
|
|
||||||
/*NbtCompound nbtgrid = buffer.readNbt();
|
|
||||||
int[] positionarray = nbtgrid.getIntArray("BlockPosition");
|
int[] positionarray = nbtgrid.getIntArray("BlockPosition");
|
||||||
Integer h = positionarray[0];
|
Integer h = positionarray[0];
|
||||||
Integer i = positionarray[1];
|
Integer i = positionarray[1];
|
||||||
Integer j = positionarray[2];*/
|
Integer j = positionarray[2];
|
||||||
|
|
||||||
|
BlockPos gridBlockPos = new BlockPos(h, i, j);
|
||||||
|
|
||||||
// minecraftClient.getBakedModelManager().getBlockModels();
|
// minecraftClient.getBakedModelManager().getBlockModels();
|
||||||
// minecraftClient.getSpriteAtlas(gridBlockTexture.getBlockInHandId(null));
|
// minecraftClient.getSpriteAtlas(gridBlockTexture.getBlockInHandId(null));
|
||||||
|
|
||||||
//BlockRenderView world = minecraftClient.world;
|
//BlockRenderView world = minecraftClient.world;
|
||||||
|
|
||||||
//BlockPos gridBlockPos = new BlockPos(h, i, j);
|
|
||||||
|
|
||||||
/*@Nullable
|
/*@Nullable
|
||||||
BlockState gridBlockState = getStateFromRawId(FORCE_STATE);
|
BlockState gridBlockState = getStateFromRawId(FORCE_STATE);
|
||||||
MatrixStack matrix = new MatrixStack();
|
MatrixStack matrix = new MatrixStack();
|
||||||
|
@ -41,7 +47,7 @@ public class gridRenderRequestS2CPacket extends BlockModelRenderer {
|
||||||
Random randomGrid = new Random();
|
Random randomGrid = new Random();
|
||||||
long seed = 7756495;*/
|
long seed = 7756495;*/
|
||||||
|
|
||||||
/*PlayerEntity playerEntity = minecraftClient.player;
|
PlayerEntity playerEntity = minecraftClient.player;
|
||||||
Block BlockInHand = getBlockFromItem(playerEntity.getMainHandStack().getItem());
|
Block BlockInHand = getBlockFromItem(playerEntity.getMainHandStack().getItem());
|
||||||
String inHandData = BlockInHand.getDefaultState().toString();
|
String inHandData = BlockInHand.getDefaultState().toString();
|
||||||
playerEntity.sendMessage(Text.of(inHandData));
|
playerEntity.sendMessage(Text.of(inHandData));
|
||||||
|
|
|
@ -1,6 +1,16 @@
|
||||||
package modchest.rendering;
|
package modchest.rendering;
|
||||||
|
|
||||||
/*public class gridBlockRender extends BlockModelRenderer{
|
import net.minecraft.block.BlockState;
|
||||||
|
import net.minecraft.client.color.block.BlockColors;
|
||||||
|
import net.minecraft.client.render.VertexConsumer;
|
||||||
|
import net.minecraft.client.render.block.BlockModelRenderer;
|
||||||
|
import net.minecraft.client.render.model.BakedModel;
|
||||||
|
import net.minecraft.client.util.math.MatrixStack;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.util.math.random.Random;
|
||||||
|
import net.minecraft.world.BlockRenderView;
|
||||||
|
|
||||||
|
public class gridBlockRender extends BlockModelRenderer{
|
||||||
|
|
||||||
public gridBlockRender(BlockColors colors) {
|
public gridBlockRender(BlockColors colors) {
|
||||||
super(colors);
|
super(colors);
|
||||||
|
@ -11,4 +21,4 @@ package modchest.rendering;
|
||||||
MatrixStack matrices, VertexConsumer vertexConsumer, boolean cull, Random random, long seed, int overlay) {
|
MatrixStack matrices, VertexConsumer vertexConsumer, boolean cull, Random random, long seed, int overlay) {
|
||||||
|
|
||||||
}
|
}
|
||||||
}*/
|
}
|
||||||
|
|
|
@ -1,11 +1,21 @@
|
||||||
package modchest.rendering;
|
package modchest.rendering;
|
||||||
|
|
||||||
//public class gridBlockTexture extends TextureManager{
|
import net.minecraft.client.texture.AbstractTexture;
|
||||||
|
import net.minecraft.client.texture.TextureManager;
|
||||||
|
import net.minecraft.resource.ResourceManager;
|
||||||
|
import net.minecraft.util.Identifier;
|
||||||
|
|
||||||
//public gridBlockTexture(ResourceManager resourceManager) {
|
public class gridBlockTexture extends TextureManager{
|
||||||
// super(resourceManager);
|
|
||||||
|
public gridBlockTexture(ResourceManager resourceManager) {
|
||||||
|
super(resourceManager);
|
||||||
//TODO Auto-generated constructor stub
|
//TODO Auto-generated constructor stub
|
||||||
//}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AbstractTexture getTexture(Identifier id) {
|
||||||
|
return super.getTexture(id);
|
||||||
|
}
|
||||||
|
|
||||||
/*public static BlockColors getBlockColors(Block block, BlockRenderView world, BlockPos pos, BlockColors blockColors) {
|
/*public static BlockColors getBlockColors(Block block, BlockRenderView world, BlockPos pos, BlockColors blockColors) {
|
||||||
BlockState state = block.getDefaultState();
|
BlockState state = block.getDefaultState();
|
||||||
|
@ -14,11 +24,6 @@ package modchest.rendering;
|
||||||
return colors;
|
return colors;
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
/*@Override
|
|
||||||
public AbstractTexture getTexture(Identifier id) {
|
|
||||||
return super.getTexture(id);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
/*public static Overlay getOverlayGrid(){
|
/*public static Overlay getOverlayGrid(){
|
||||||
MinecraftClient minecraftClient = MinecraftClient.getInstance();
|
MinecraftClient minecraftClient = MinecraftClient.getInstance();
|
||||||
PlayerEntity player = minecraftClient.player;
|
PlayerEntity player = minecraftClient.player;
|
||||||
|
@ -30,6 +35,6 @@ package modchest.rendering;
|
||||||
|
|
||||||
//stateInHand.getRenderingSeed
|
//stateInHand.getRenderingSeed
|
||||||
|
|
||||||
//}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -3,10 +3,15 @@ package modchest.event;
|
||||||
import static net.minecraft.block.Block.getBlockFromItem;
|
import static net.minecraft.block.Block.getBlockFromItem;
|
||||||
|
|
||||||
import modchest.block.custom.gridBlock;
|
import modchest.block.custom.gridBlock;
|
||||||
|
import modchest.networking.modNetworkingServer;
|
||||||
|
import modchest.networking.packet.gridBlockS2CPacket;
|
||||||
import net.fabricmc.fabric.api.event.player.UseBlockCallback;
|
import net.fabricmc.fabric.api.event.player.UseBlockCallback;
|
||||||
|
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
|
import net.minecraft.server.MinecraftServer;
|
||||||
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.text.Text;
|
||||||
import net.minecraft.util.ActionResult;
|
import net.minecraft.util.ActionResult;
|
||||||
import net.minecraft.util.Hand;
|
import net.minecraft.util.Hand;
|
||||||
|
@ -21,8 +26,8 @@ public class useBlockCallback implements UseBlockCallback {
|
||||||
Block BlockInHand = getBlockFromItem(player.getMainHandStack().getItem());
|
Block BlockInHand = getBlockFromItem(player.getMainHandStack().getItem());
|
||||||
BlockState StateInHand = BlockInHand.getDefaultState();
|
BlockState StateInHand = BlockInHand.getDefaultState();
|
||||||
BlockPos gridBlockPos = hitResult.getBlockPos();
|
BlockPos gridBlockPos = hitResult.getBlockPos();
|
||||||
//PlayerPublicKey playerPublicKey = player.getPublicKey();
|
|
||||||
//ServerPlayerEntity serverPlayer = ((ServerPlayerEntity) player);
|
// PlayerPublicKey playerPublicKey = player.getPublicKey();
|
||||||
if (world.getBlockState(hitResult.getBlockPos()).getBlock().toString().equals("Block{modchest:grid_block}")
|
if (world.getBlockState(hitResult.getBlockPos()).getBlock().toString().equals("Block{modchest:grid_block}")
|
||||||
&& player.isSpectator() == false) {
|
&& player.isSpectator() == false) {
|
||||||
if (BlockInHand instanceof gridBlock) {
|
if (BlockInHand instanceof gridBlock) {
|
||||||
|
@ -34,7 +39,13 @@ public class useBlockCallback implements UseBlockCallback {
|
||||||
player.getMainHandStack().decrement(1);
|
player.getMainHandStack().decrement(1);
|
||||||
player.jump();
|
player.jump();
|
||||||
// player.onLanding(player.playSoundIfNotSilent());
|
// player.onLanding(player.playSoundIfNotSilent());
|
||||||
//gridBlockS2CPacket.sendPacket(serverPlayer, hitResult);
|
if (player instanceof ServerPlayerEntity) { // nötig, um sicherzustellen, dass eine ServerPlayerEntity
|
||||||
|
// fürs networking übergeben wird und nicht eine
|
||||||
|
// PlayerEntity, da sonst Absturz
|
||||||
|
ServerPlayerEntity serverPlayer = (ServerPlayerEntity) player;
|
||||||
|
ServerPlayNetworking.send(serverPlayer, modNetworkingServer.grid_block_networking,
|
||||||
|
gridBlock.writeBuffer(hitResult));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return ActionResult.PASS;
|
return ActionResult.PASS;
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
package modchest.networking.packet;
|
package modchest.networking.packet;
|
||||||
|
|
||||||
|
import net.minecraft.network.PacketByteBuf;
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
|
import net.minecraft.util.Identifier;
|
||||||
import net.minecraft.util.hit.BlockHitResult;
|
import net.minecraft.util.hit.BlockHitResult;
|
||||||
|
|
||||||
public class gridBlockS2CPacket {
|
public class gridBlockS2CPacket {
|
||||||
|
|
||||||
|
|
||||||
public static void sendPacket(ServerPlayerEntity serverPlayerEntity, BlockHitResult hitResult) {
|
public static void sendPacket(ServerPlayerEntity serverPlayerEntity, BlockHitResult hitResult) {
|
||||||
//PacketByteBuf gridBuffer = gridBlock.writeBuffer(hitResult);
|
//PacketByteBuf gridBuffer = gridBlock.writeBuffer(hitResult);
|
||||||
//ServerPlayNetworking.send(serverPlayerEntity, modNetworkingServer.grid_block_networking, gridBuffer);
|
//ServerPlayNetworking.send(serverPlayerEntity, modNetworkingServer.grid_block_networking, gridBuffer);
|
||||||
|
|
Loading…
Reference in New Issue