So auskommentiert funktioniert noch alles
This commit is contained in:
Paula 2024-05-17 20:21:33 +02:00
parent 05a176f3c1
commit 8db9e9cf06
7 changed files with 130 additions and 49 deletions

View File

@ -2,6 +2,9 @@ package modchest;
import modchest.networking.modNetworkingClient;
import net.fabricmc.api.ClientModInitializer;
import net.minecraft.client.util.ModelIdentifier;
import net.minecraft.util.Identifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -11,6 +14,7 @@ public class REServerModClient implements ClientModInitializer {
public void onInitializeClient() {
// This entrypoint is suitable for setting up client-specific logic, such as rendering.
modNetworkingClient.registerC2SPackets(); //Identifier unter denen der Client zuhoert werden registriert
LOGGER.info("Modchest-Client successfully loaded!");

View File

@ -1,20 +1,60 @@
package modchest.networking.packet;
import modchest.REServerMod;
import modchest.event.useBlockCallback;
import modchest.networking.modNetworkingClient;
/*import modchest.rendering.gridBlockRender;
import modchest.rendering.gridBlockTexture;*/
import net.fabricmc.fabric.api.networking.v1.PacketSender;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.color.block.BlockColors;
import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.client.render.block.BlockModelRenderer;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.util.Identifier;
public class gridRenderRequestS2CPacket {
public class gridRenderRequestS2CPacket extends BlockModelRenderer {
public static void receive(MinecraftClient minecraftClient, ClientPlayNetworkHandler clientPlayNetworkHandler, PacketByteBuf buffer, PacketSender PacketSender){
//clientPlayNetworkHandler.getWorld();
//modNetworkingClient.grid_block_networking.;
//PacketByteBuf buf =
public gridRenderRequestS2CPacket(BlockColors colors) {
super(colors);
// TODO Auto-generated constructor stub
}
public static void receive(MinecraftClient minecraftClient, ClientPlayNetworkHandler clientPlayNetworkHandler,
PacketByteBuf buffer, PacketSender PacketSender) {
// clientPlayNetworkHandler.getWorld();
// modNetworkingClient.grid_block_networking.;
// PacketByteBuf buf =
/*NbtCompound nbtgrid = buffer.readNbt();
int[] positionarray = nbtgrid.getIntArray("BlockPosition");
Integer h = positionarray[0];
Integer i = positionarray[1];
Integer j = positionarray[2];*/
// minecraftClient.getBakedModelManager().getBlockModels();
// minecraftClient.getSpriteAtlas(gridBlockTexture.getBlockInHandId(null));
//BlockRenderView world = minecraftClient.world;
//BlockPos gridBlockPos = new BlockPos(h, i, j);
/*@Nullable
BlockState gridBlockState = getStateFromRawId(FORCE_STATE);
MatrixStack matrix = new MatrixStack();
MatrixStack.Entry entry;
Random randomGrid = new Random();
long seed = 7756495;*/
/*PlayerEntity playerEntity = minecraftClient.player;
Block BlockInHand = getBlockFromItem(playerEntity.getMainHandStack().getItem());
String inHandData = BlockInHand.getDefaultState().toString();
playerEntity.sendMessage(Text.of(inHandData));
//Identifier testBlockId = new Identifier("modchest", "block/test_block"); // Mod-ID + Blockpfad
//ModelIdentifier testModelId = new ModelIdentifier(testBlockId, "all"); // Verwende "normal" als Variante
//BakedModel gridModel = MinecraftClient.getInstance().getBakedModelManager().getModel(testModelId);
/*
* gridBlockRender.render(world, BakedModel model, gridBlockState, gridBlockPos,
* matrix, gridConsumer, true, randomGrid, seed, overlay);
*/
}
}

View File

@ -0,0 +1,14 @@
package modchest.rendering;
/*public class gridBlockRender extends BlockModelRenderer{
public gridBlockRender(BlockColors colors) {
super(colors);
}
@Override
public void render(BlockRenderView world, BakedModel model, BlockState state, BlockPos pos,
MatrixStack matrices, VertexConsumer vertexConsumer, boolean cull, Random random, long seed, int overlay) {
}
}*/

View File

@ -0,0 +1,35 @@
package modchest.rendering;
//public class gridBlockTexture extends TextureManager{
//public gridBlockTexture(ResourceManager resourceManager) {
// super(resourceManager);
//TODO Auto-generated constructor stub
//}
/*public static BlockColors getBlockColors(Block block, BlockRenderView world, BlockPos pos, BlockColors blockColors) {
BlockState state = block.getDefaultState();
// Verwende die Farbe für deine Zwecke
BlockColors colors = getBlockColors(block, world, pos, blockColors);
return colors;
}*/
/*@Override
public AbstractTexture getTexture(Identifier id) {
return super.getTexture(id);
}*/
/*public static Overlay getOverlayGrid(){
MinecraftClient minecraftClient = MinecraftClient.getInstance();
PlayerEntity player = minecraftClient.player;
ItemStack itemStackInHand = player.getMainHandStack();
Block blockInHand = getBlockFromItem(itemStackInHand.getItem());
BlockState stateInHand = blockInHand.getDefaultState();
RenderLayer inHandRenderLayer = ;*/
//stateInHand.getRenderingSeed
//}

View File

@ -7,9 +7,10 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.block.BlockRenderType;
import net.minecraft.block.BlockState;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.network.PacketByteBuf;
public class gridBlock extends Block{
public class gridBlock extends Block {
public static final String ServerPlayNetworking = null;
@ -28,13 +29,21 @@ public class gridBlock extends Block{
return super.isSideInvisible(state, stateFrom, direction) || (state == stateFrom);
}
public static PacketByteBuf writeBuffer(BlockHitResult hitResult){
public static PacketByteBuf writeBuffer(BlockHitResult hitResult) {
BlockPos gridBlockPos = hitResult.getBlockPos();
int[] gridPos = new int[3];
gridPos[0] = gridBlockPos.getX();
gridPos[1] = gridBlockPos.getY();
gridPos[2] = gridBlockPos.getZ();
NbtCompound Nbtgrid = new NbtCompound();
Nbtgrid.putIntArray("BlockPosition", gridPos);
PacketByteBuf gridBlockBuffer = PacketByteBufs.create();
gridBlockBuffer.writeInt(1);
gridBlockBuffer.writeBlockHitResult(hitResult);
gridBlockBuffer.writeBlockPos(gridBlockPos);
gridBlockBuffer.writeNbt(Nbtgrid);
// gridBlockBuffer.writeBlockHitResult(hitResult);
// gridBlockBuffer.writeBlockPos(gridBlockPos);
return gridBlockBuffer;
}

View File

@ -2,9 +2,6 @@ package modchest.event;
import static net.minecraft.block.Block.getBlockFromItem;
import java.util.LinkedList;
import java.util.List;
import modchest.block.custom.gridBlock;
import net.fabricmc.fabric.api.event.player.UseBlockCallback;
import net.minecraft.block.Block;
@ -15,39 +12,29 @@ import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Position;
import net.minecraft.world.World;
public class useBlockCallback implements UseBlockCallback{
public class useBlockCallback implements UseBlockCallback {
@Override
public ActionResult interact(PlayerEntity player, World world, Hand hand, BlockHitResult hitResult) {
Block BlockInHand = getBlockFromItem(player.getMainHandStack().getItem());
BlockState StateInHand = BlockInHand.getDefaultState();
BlockPos gridBlockPos = hitResult.getBlockPos();
/*PlayerPublicKey playerPublicKey = player.getPublicKey();
GameProfile gameProfile = player.getGameProfile();
MinecraftServer server = player.getServer();
ServerWorld serverWorld = server.getOverworld();
ServerPlayerEntity serverPlayerEntity = new ServerPlayerEntity(server, serverWorld, gameProfile, playerPublicKey);
ServerPlayerEntity sp = ;*/
if (world.getBlockState(hitResult.getBlockPos()).getBlock().toString().equals("Block{modchest:grid_block}") && player.isSpectator()==false) {
//PlayerPublicKey playerPublicKey = player.getPublicKey();
//ServerPlayerEntity serverPlayer = ((ServerPlayerEntity) player);
if (world.getBlockState(hitResult.getBlockPos()).getBlock().toString().equals("Block{modchest:grid_block}")
&& player.isSpectator() == false) {
if (BlockInHand instanceof gridBlock) {
return ActionResult.PASS;
} else {
player.sendMessage(Text.of("gridBlock benutzt"));
world.setBlockState(gridBlockPos, StateInHand); //tauscht die Textur des "benutzten" gridBlocks mit der des Blocks in der Hand
world.setBlockState(gridBlockPos, StateInHand); // tauscht die Textur des "benutzten" gridBlocks mit der
// des Blocks in der Hand
player.getMainHandStack().decrement(1);
//sp.sendMessage(Text.of("das ist der serverplayer"));
player.jump();
//player.onLanding(player.playSoundIfNotSilent());
List<Position> gridBlockList = new LinkedList<Position>();
gridBlockList.add(hitResult.getPos());
//gridBlockS2CPacket.sendPacket(ServerPlayerEntity PlayerEntity, BlockHitResult hitResult);
// player.onLanding(player.playSoundIfNotSilent());
//gridBlockS2CPacket.sendPacket(serverPlayer, hitResult);
}
} else {
return ActionResult.PASS;

View File

@ -1,20 +1,12 @@
package modchest.networking.packet;
import modchest.block.custom.gridBlock;
import modchest.networking.modNetworkingServer;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.hit.BlockHitResult;
public class gridBlockS2CPacket {
public void sendPacket(ServerPlayerEntity serverPlayerEntity, BlockHitResult hitResult){
PacketByteBuf gridBuffer = gridBlock.writeBuffer(hitResult);
ServerPlayNetworking.send(serverPlayerEntity, modNetworkingServer.grid_block_networking, gridBuffer);
//The player in this method is the player the packet will be sent to. The channel name is the Identifier you decided on earlier
//to identify your packet. The PacketByteBuf is what stores the data for the packet.
public static void sendPacket(ServerPlayerEntity serverPlayerEntity, BlockHitResult hitResult) {
//PacketByteBuf gridBuffer = gridBlock.writeBuffer(hitResult);
//ServerPlayNetworking.send(serverPlayerEntity, modNetworkingServer.grid_block_networking, gridBuffer);
}
}