gridBlock networking basics added

Grundlagen fürs networking und dann auch die (hoffentlich) funktionierende Version vom gridBlock hinzugefügt
This commit is contained in:
Paula 2024-04-24 19:46:16 +02:00
parent fb89700729
commit 3f5c1db8cf
19 changed files with 334 additions and 312 deletions

View File

@ -1,7 +1,13 @@
package modchest;
import modchest.util.clientInitializer;
import modchest.block.custom.gridBlock;
import modchest.networking.modNetworkingClient;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap;
import net.fabricmc.fabric.api.client.model.ModelLoadingRegistry;
import net.minecraft.client.render.RenderLayer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -14,7 +20,13 @@ public class REServerModClient implements ClientModInitializer {
clientInitializer.renderer();
clientInitializer.networking();
modNetworkingClient.registerS2CPackets(); //Identifier unter denen der Client zuhoert werden registriert
//BlockRenderLayerMap.INSTANCE.putBlock(gridBlock.GRID_BLOCK_INSTANCE, RenderLayer.getCutout());
LOGGER.info("Modchest-Client successfully loaded!");
}
}

View File

@ -1,50 +0,0 @@
package modchest.block.custom;
import java.util.Map;
import com.google.common.collect.Maps;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.client.texture.AbstractTexture;
import net.minecraft.client.texture.ResourceTexture;
import net.minecraft.client.texture.TextureManager;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.resource.ResourceManager;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
@Environment(EnvType.CLIENT)
public class gridBlockTexture extends TextureManager {
public gridBlockTexture(ResourceManager resourceManager) {
super(resourceManager);
//TODO Auto-generated constructor stub
}
public BlockState getGridBlockState(Block gridBlock){ //nötig wegen static / non-static
BlockState gridBlockState= gridBlock.getDefaultState();
return gridBlockState;
}
private final Map<Identifier, AbstractTexture> textures = Maps.newHashMap();
public AbstractTexture getGridBlockTexture(Block gridBlock) {
Identifier id = Registry.BLOCK.getId(gridBlock);
AbstractTexture gridBlockTexture = (AbstractTexture)this.textures.get(id);
if (gridBlockTexture == null) {
gridBlockTexture = new ResourceTexture(id);
this.registerTexture(id, (AbstractTexture)gridBlockTexture);
}
return gridBlockTexture;
}
}

View File

@ -1,6 +1,7 @@
package modchest.networking;
import modchest.REServerMod;
import modchest.networking.packet.gridBlockTextureS2CPacket;
import modchest.networking.packet.respawnRequestS2CPacket;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
import net.minecraft.util.Identifier;
@ -9,8 +10,10 @@ public class modNetworkingClient { //Identifier werden eingeführt
public static final Identifier request_respawn = new Identifier(REServerMod.MOD_ID, "request_respawn"); //alle Identifier muessen leider IMMER auf Client und Server (doppelt) eingefuehrt werden
public static final Identifier start_sleeping_call_buttons = new Identifier(REServerMod.MOD_ID, "start_sleeping_call_buttons");
public static final Identifier death_multi_respawn_buttons = new Identifier(REServerMod.MOD_ID, "death_call_respawn_buttons");
public static void registerS2CPackets() { //Identifier fuer packets werden registriert (Identifier die der Server aufruft um beim Client was auszufuehren)
public static final Identifier grid_block_networking = new Identifier(REServerMod.MOD_ID, "grid_block_networking");
public static void registerS2CPackets() { //Identifier fuer packets werden registriert (Identifier die der Server aufruft um beim CLient was auszufuehren)
ClientPlayNetworking.registerGlobalReceiver(request_respawn, respawnRequestS2CPacket::receive); //was der Client dann machen soll steht in der receive Methode
ClientPlayNetworking.registerGlobalReceiver(grid_block_networking, gridBlockTextureS2CPacket::receive);
}
}
}

View File

@ -0,0 +1,87 @@
package modchest.networking.packet;
import static java.lang.Math.random;
import static net.minecraft.block.Block.getStateFromRawId;
import net.minecraft.util.math.random.Random;
import modchest.block.custom.gridBlock;
import modchest.event.useBlockCallback;
import modchest.networking.modNetworkingClient;
import modchest.networking.modNetworkingServer;
import modchest.rendering.gridBlockRenderer;
import net.fabricmc.fabric.api.networking.v1.PacketSender;
import net.minecraft.block.BlockRenderType;
import net.minecraft.block.BlockState;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.color.block.BlockColors;
import net.minecraft.client.network.ClientPlayNetworkHandler;
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.network.PacketByteBuf;
import net.minecraft.util.Identifier;
import net.minecraft.util.crash.CrashException;
import net.minecraft.util.crash.CrashReport;
import net.minecraft.util.crash.CrashReportSection;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.BlockRenderView;
public class gridBlockTextureS2CPacket extends BlockModelRenderer {
public gridBlockTextureS2CPacket(BlockColors colors) {
super(colors);
//TODO Auto-generated constructor stub
}
public static void receive(MinecraftClient minecraftClient, ClientPlayNetworkHandler clientPlayNetworkHandler, PacketByteBuf buf, PacketSender packetSender){
//passiert auf dem Client!!
/* Integer gridBlockStateInt = b.readInt();
BlockState gridBlockState = getStateFromRawId(gridBlockStateInt);
BlockPos gridBlockPos = buf.readBlockPos();
BakedModel model;
BlockRenderView world;
MatrixStack matrices;
VertexConsumer vertexConsumer;
boolean cull;
Random random;
long seed;
int overlay;
BlockRenderType gridBlockRenderType = gridBlockState.getRenderType();*/
modNetworkingServer.grid_block_networking.getPath();
//if (gridBlockRenderType == BlockRenderType.MODEL) {
/* render(world, model, gridBlockState, gridBlockPos, matrices, vertexConsumer, cull, random, seed, overlay) {
boolean bl = MinecraftClient.isAmbientOcclusionEnabled() && gridBlockState.getLuminance() == 0 && model.useAmbientOcclusion();
Vec3d vec3d = gridBlockState.getModelOffset(world, gridBlockPos);
matrices.translate(vec3d.x, vec3d.y, vec3d.z);
try {
if (bl) {
this.renderSmooth(world, model, gridBlockState, gridBlockPos, matrices, vertexConsumer, cull, random, seed, overlay);
} else {
this.renderFlat(world, model, gridBlockState, gridBlockPos, matrices, vertexConsumer, cull, random, seed, overlay);
}
} catch (Throwable var17) {
CrashReport crashReport = CrashReport.create(var17, "Tesselating block model");
CrashReportSection crashReportSection = crashReport.addElement("Block model being tesselated");
CrashReportSection.addBlockInfo(crashReportSection, world, gridBlockPos, gridBlockState);
crashReportSection.add("Using AO", bl);
throw new CrashException(crashReport);
}
//}*/
//gridBlockRenderer.renderBlock(gridBlockState, gridBlockPos, world, matrices, vertexConsumer, cull, random);
}
}

View File

@ -1,6 +1,5 @@
package modchest.networking.packet;
import modchest.REServerModClient;
import net.fabricmc.fabric.api.networking.v1.PacketSender;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayNetworkHandler;

View File

@ -1,51 +0,0 @@
package modchest.rendering;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.color.block.BlockColors;
import net.minecraft.client.render.block.BlockModels;
import net.minecraft.client.render.block.BlockRenderManager;
import net.minecraft.client.render.item.BuiltinModelItemRenderer;
@Environment(EnvType.CLIENT)
public class gridBlockEntityRenderer extends BlockRenderManager {
public gridBlockEntityRenderer(BlockModels models, BuiltinModelItemRenderer builtinModelItemRenderer,
BlockColors blockColors) {
super(models, builtinModelItemRenderer, blockColors);
//TODO Auto-generated constructor stub
}
/*private static final int WIDTH = 16;
private static final int HEIGHT = 16;
private static final int ROTATIONS = 16;
public gridBlockEntityRenderer(BlockModels models, BuiltinModelItemRenderer builtinModelItemRenderer, BlockColors blockColors) {
super(models, builtinModelItemRenderer, blockColors);
}
private Sprite customTexture;
// Hier kannst du das Rendering der Block-Entität anpassen
// Zum Beispiel, um eine benutzerdefinierte Textur anzuwenden
@Override
public void renderBlock(BlockState state, BlockPos pos, BlockRenderView world, MatrixStack matrices, VertexConsumer vertexConsumer, boolean cull, Random random) {
try {
BlockRenderType blockRenderType = state.getRenderType();
if (blockRenderType == BlockRenderType.MODEL) {
this.blockModelRenderer.render(world, this.getModel(state), state, pos, matrices, vertexConsumer, cull, random, state.getRenderingSeed(pos), OverlayTexture.DEFAULT_UV);
}
} catch (Throwable var11) {
CrashReport crashReport = CrashReport.create(var11, "Tesselating block in world");
CrashReportSection crashReportSection = crashReport.addElement("Block being tesselated");
CrashReportSection.addBlockInfo(crashReportSection, world, pos, state);
throw new CrashException(crashReport);
}
}*/
}

View File

@ -0,0 +1,52 @@
package modchest.rendering;
import modchest.block.custom.gridBlock;
import modchest.networking.packet.gridBlockTextureS2CPacket;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.block.BlockRenderType;
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.block.BlockModels;
import net.minecraft.client.render.block.BlockRenderManager;
import net.minecraft.client.render.item.BuiltinModelItemRenderer;
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;
@Environment(EnvType.CLIENT)
@SuppressWarnings("deprecation")
public class gridBlockRenderer extends BlockRenderManager{
public gridBlockRenderer(BlockModels models, BuiltinModelItemRenderer builtinModelItemRenderer,
BlockColors blockColors) {
super(models, builtinModelItemRenderer, blockColors);
//TODO Auto-generated constructor stub
}
/*@Override
public void renderBlock(BlockState hitResultBlockState, BlockPos hitResultPos, BlockRenderView world, MatrixStack matrices, VertexConsumer vertexConsumer, boolean cull, Random random) {
try {
BlockRenderType blockRenderType = hitResultBlockState.getRenderType();
if (blockRenderType == BlockRenderType.MODEL) {
BlockModelRenderer.render(world, gridBlock.getModel(hitResultBlockState), hitResultBlockState, hitResultPos, matrices, vertexConsumer, cull, random, gridBlockState.getRenderingSeed(hitResultPos), OverlayTexture.DEFAULT_UV);
}
} catch (Throwable var11) {
CrashReport crashReport = CrashReport.create(var11, "Tesselating block in world");
CrashReportSection crashReportSection = crashReport.addElement("Block being tesselated");
CrashReportSection.addBlockInfo(crashReportSection, world, pos, gridBlockState);
throw new CrashException(crashReport);
}
}*/
}

View File

@ -0,0 +1,58 @@
package modchest.rendering;
import static modchest.block.modBlocks.grid_block;
import modchest.block.modBlocks;
import modchest.event.useBlockCallback;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.client.texture.AbstractTexture;
import net.minecraft.client.texture.TextureManager;
import net.minecraft.resource.ResourceManager;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
@Environment(EnvType.CLIENT)
@SuppressWarnings("deprecation")
public class gridBlockTexture extends TextureManager {
public gridBlockTexture(ResourceManager resourceManager) {
super(resourceManager);
//TODO Auto-generated constructor stub
}
Block gridBlock = modBlocks.grid_block;
BlockState gridBlockState = grid_block.getDefaultState();
Identifier gridBlockTextureId = new Identifier("modchest", "block/grid_block_texture.png"); // Mod-ID-Präfix + Texturpfad
@Override
public AbstractTexture getTexture(Identifier id) {
return super.getTexture(id);
}
//private static final Map<Identifier, AbstractTexture> textures = Maps.newHashMap();
//BlockState gridBlockState = modBlocks.grid_block.getDefaultState();
/*public static AbstractTexture getGridBlockTexture(Identifier identifier) {
Identifier id = Registry.BLOCK.getId(gridBlockTexture);
AbstractTexture gridBlockTexture = textures.get(id);
if (gridBlockTexture == null) {
gridBlockTexture = new ResourceTexture(id);
}
return gridBlockTexture;
}*/
}

View File

@ -23,4 +23,22 @@ BlockRenderManager: kann getModel!!!!!
gridBlockTexture: extends TextureManager
- getTexture(IdentifierID)
- PROBLEM: wie in useBlockCallback/gridBlockEntity auf Server??
- PROBLEM: wie krieg ich gridBlock vom Server?
renderRequestS2C: wird aufgerufen, wenn auf dem Server useBlockCallback ausgeführt wird, verlangt das ändern der gridBlockTextur
gridBlockRegistrySyncC2SPacket: übergibt verschiedene Eigenschaften des gridBlock, wenn wird aufgerufen mit receive
gridBlockTexture: getTexture
public static void receive(MinecraftServer server, ServerPlayerEntity player, ServerPlayNetworkHandler handler, PacketByteBuf buf, PacketSender responseSender){
player.sendMessage(Text.of("das networking funktioniert"));
}
deathScreen: sendet Packets
preferences: open user settings (JSON)
- "java.import.gradle.wrapper.enabled": false,
- "java.import.gradle.version": "8.3"
=> bringt auch nix

View File

@ -1,12 +1,5 @@
package modchest;
import modchest.block.entity.modBlockEntities;
import modchest.event.useBlockCallback;
import modchest.block.modBlocks;
import modchest.item.modItemGroup;
import modchest.item.modItems;
import net.fabricmc.api.ModInitializer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

View File

@ -1,23 +1,18 @@
package modchest.block.custom;
import modchest.block.entity.gridBlockEntity;
import net.minecraft.block.Block;
import net.minecraft.block.BlockEntityProvider;
import net.minecraft.block.BlockRenderType;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
public class gridBlock extends Block implements BlockEntityProvider{
public gridBlock(final Settings settings) {
public class gridBlock extends Block {
public gridBlock(Settings settings) {
super(settings);
}
public static final Block GRID_BLOCK_INSTANCE = new gridBlock(null);
@Override
@Override
public BlockRenderType getRenderType(BlockState state) {
return BlockRenderType.MODEL;
}
@ -28,8 +23,5 @@ public class gridBlock extends Block implements BlockEntityProvider{
return super.isSideInvisible(state, stateFrom, direction) || (state == stateFrom);
}
@Override
public BlockEntity createBlockEntity(BlockPos pos, BlockState state) {
return new gridBlockEntity(pos, state);
}
}

View File

@ -20,7 +20,7 @@ import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;
//gibt dem Block steering_wheel eigenschaften, wie z.B. das Interaktionsmenü, oder Grafiken
public class steeringWheelBlock extends BlockWithEntity implements BlockEntityProvider {
public class steeringWheelBlock extends BlockWithEntity {
public steeringWheelBlock(Settings settings) {
super(settings);
}
@ -30,6 +30,7 @@ public class steeringWheelBlock extends BlockWithEntity implements BlockEntityPr
return BlockRenderType.MODEL;
}
@SuppressWarnings("deprecation")
@Override
public void onStateReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean moved) { //Aufgerufen bei blockstate veraenderung, z.B. restonestaerke
if (state.getBlock() != newState.getBlock()) {

View File

@ -1,62 +0,0 @@
package modchest.block.entity;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.screen.NamedScreenHandlerFactory;
import net.minecraft.screen.PropertyDelegate;
import net.minecraft.screen.ScreenHandler;
import net.minecraft.text.Text;
import net.minecraft.util.collection.DefaultedList;
import net.minecraft.util.math.BlockPos;
public class gridBlockEntity extends BlockEntity implements NamedScreenHandlerFactory, ImplementedInventory{
public final PropertyDelegate propertyDelegate;
public gridBlockEntity( BlockPos pos, BlockState state) {
super(modBlockEntities.GRID_BLOCK_ENTITY, pos, state);
this.propertyDelegate = new PropertyDelegate() {
@Override
public int get(int index) {
return 0;
}
@Override
public void set(int index, int value) {
}
@Override
public int size() {
return 0;
}
};
}
@Override
public ScreenHandler createMenu(int arg0, PlayerInventory arg1, PlayerEntity arg2) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'createMenu'");
}
@Override
public DefaultedList<ItemStack> getItems() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'getItems'");
}
@Override
public Text getDisplayName() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'getDisplayName'");
}
}

View File

@ -10,7 +10,7 @@ import net.minecraft.util.registry.Registry;
//rendert letztendlich die Interaktionsmenüs der Blöcke
public class modBlockEntities {
public static BlockEntityType<steeringWheelEntity> steering_wheel_interface;// Interaktionsmenü wird erstellt
public static BlockEntityType<gridBlockEntity> GRID_BLOCK_ENTITY;
public static void registerBlockEntities() {
@ -18,9 +18,7 @@ public class modBlockEntities {
new Identifier(REServerMod.MOD_ID, "steering_wheel_interface"), // Interkationsmenü wird gerendert
FabricBlockEntityTypeBuilder.create(steeringWheelEntity::new, modBlocks.steering_wheel).build(null));
GRID_BLOCK_ENTITY = Registry.register(Registry.BLOCK_ENTITY_TYPE,
new Identifier(REServerMod.MOD_ID, "grid_block_entity"),
FabricBlockEntityTypeBuilder.create(gridBlockEntity::new, modBlocks.grid_block).build(null));
}

View File

@ -1,32 +0,0 @@
package modchest.event;
import modchest.block.entity.gridBlockEntity;
import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.fabric.api.event.EventFactory;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Position;
import net.minecraft.entity.player.PlayerEntity;
public interface gridBlockAttackCallback {
Event<gridBlockAttackCallback> EVENT = EventFactory.createArrayBacked(gridBlockAttackCallback.class,
(listeners) -> (player, gridBlock, hand, pos, direction, hitResult) -> {
for (gridBlockAttackCallback listener : listeners) {
ActionResult result = listener.interact(player, gridBlock, hand, pos, direction, hitResult);
if(result != ActionResult.PASS) {
return result;
}
}
return ActionResult.PASS;
});
ActionResult interact(PlayerEntity player, gridBlockEntity gridBlock, Hand hand, Position pos, Direction direction, BlockHitResult hitResult);
}

View File

@ -1,139 +1,99 @@
package modchest.event;
import static net.minecraft.block.Block.getBlockFromItem;
import static net.minecraft.block.Block.getRawIdFromState;
import java.util.LinkedList;
import java.util.List;
import modchest.block.modBlocks;
import modchest.block.custom.gridBlock;
import modchest.networking.modNetworkingServer;
import net.fabricmc.fabric.api.event.player.UseBlockCallback;
import net.fabricmc.fabric.api.networking.v1.PacketByteBufs;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.minecraft.block.Block;
import net.minecraft.block.BlockRenderType;
import net.minecraft.block.BlockState;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerEntityManager;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.text.Text;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.Identifier;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Position;
import net.minecraft.util.registry.Registry;
import net.minecraft.world.World;
public class useBlockCallback implements UseBlockCallback {
//wird aufgerufen, wenn ein Block "rechtsgeklickt" wird; überprüft, ob das mit einem gridBlock passiert, wenn ja wird der Block zu einem gridBlock geändert
//speichert die plazierten gridBlöcke in einer Liste
//wird aufgerufen, wenn ein Block "rechtsgeklickt" wird; überprüft, ob das mit einem gridBlock passiert
// wenn ja schickt Packet zum client, dort wird textur geaendert
@SuppressWarnings("deprecation")
@Override
public ActionResult interact(PlayerEntity player, World world, Hand hand, BlockHitResult hitResult) {
Item ItemInHand = player.getMainHandStack().getItem();
Block BlockInHand = getBlockFromItem(ItemInHand);
//ItemStack ItemStackInHand = player.getMainHandStack();
ItemStack ItemStackInHand = player.getMainHandStack();
BlockPos gridBlockPos = hitResult.getBlockPos();
BlockState gridBlockState = world.getBlockState(hitResult.getBlockPos());
Block gridBlock = gridBlockState.getBlock();
Integer gridBlockStateId = getRawIdFromState(gridBlockState);
player.sendMessage(Text.of(world.getBlockState(hitResult.getBlockPos()).getBlock().toString()));
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) { //ueberprueft ob Block gridBlock ist
if (player.isSpectator() == false) {
if (BlockInHand instanceof gridBlock) {
return ActionResult.PASS;
} else {
player.sendMessage(Text.of("es hat funktioniert"));
player.getMainHandStack().decrement(1);
List <Position> gridBlockList = new LinkedList<Position>();
gridBlockList.add(hitResult.getPos());
player.sendMessage(Text.of("sendBlockRegistryDataToClient"));
player.sendMessage(Text.of("gridBlock geaendert"));
player.getMainHandStack().decrement(1);
BlockState StateInHand = BlockInHand.getDefaultState(); //tauscht den blockstate des benutzen gridBlocks mit dem blockstate des blocks in der Hand
world.setBlockState(gridBlockPos, StateInHand);
List <Position> gridBlockList = new LinkedList<Position>();
gridBlockList.add(hitResult.getPos());
// ;hitResult.getClass().getDefaultState().getRawIdFromState();
// String hitResultModelPath = new Identifier().toString();
BlockState gridBlockState = world.getBlockState(hitResult.getBlockPos());
Block gridBlock = gridBlockState.getBlock();
//BlockRenderView gridBlockRenderView;
//BlockState height = world.getBlockState(gridBlockPos).getAppearance(gridBlockRenderView, gridBlockPos, null, gridBlockState, gridBlockPos)
//Identifier gridBlockId = Registry.BLOCK.getId(gridBlock.GRID_BLOCK_INSTANCE);
//Integer gridBlockStateId = gridBlock.getRawIdFromState(modBlocks.grid_block.getDefaultState());
//String gridBlockModelPath = new Identifier("modchest", "modchest/block/grid_block.json").toString();
BlockRenderType gridBlockRender = gridBlock.getRenderType(gridBlockState);
BlockRenderType inHandRenderType = BlockInHand.getRenderType(StateInHand);
PacketByteBuf bufferUseBlockCallback = PacketByteBufs.create();
bufferUseBlockCallback.writeInt(gridBlockStateId);
bufferUseBlockCallback.writeBlockPos(gridBlockPos);
ServerPlayerEntity serverplayer = new ServerPlayerEntity(null, null, null, null);
//soll dem Client die fürs rendern benötigten Informationen vom Server schicken
player.sendMessage(Text.of(gridBlockRender.toString()));
player.sendMessage(Text.of(inHandRenderType.toString())); //return: MODEL
ServerPlayNetworking.send(serverplayer, modNetworkingServer.grid_block_networking, bufferUseBlockCallback); //soll dem Client die fürs rendern benötigten informationen schicken
//BlockRenderManager blockRenderManager = client.getRenderManager();
//BakedModel gridBlockModel = blockRenderManager.getModel(gridBlockState);
//gridBlockRender = FORCE_STATE;
//hitResult.getBlockPos().getClass();
//TODO: wenn Werkzeuge in MainHand NICHT den MainHandStack reduzieren
//TODO: sobald Hammer existiert darf gridBlock nur noch von diesem abgebaut werden können
//minecraft:blockid
/* if (player.getMainHandStack().equals("") ){ //TODO: wenn Werkzeuge in MainHand NICHT den MainHandStack reduzieren
//TODO: sobald Hammer existiert darf gridBlock nur noch von diesem abgebaut werden können
} else {
}*/
// gridBlock.getAppearance(gridBlockState, BlockRenderView renderView,
// gridBlockPos, Direction side, BlockState sourceState, BlockPos sourcePos);
/*
* if (inHandRenderType == gridBlockRender){
* player.sendMessage(Text.of("Das MODEL ist das MODEL - Scheiße"));
* }
*/
// player.sendMessage(Text.of(world.getBlockState(hitResult.getBlockPos()).getBlock().getRenderType(gridBlockState).toString()));
// BlockRenderType inHandRenderType;
// BlockRenderType griBlockRenderType;
// BlockRenderType griBlockRenderType = BlockInHand.getRenderType(StateInHand);
}
}
} else {
return ActionResult.PASS;
}
return ActionResult.SUCCESS;
}// mit SUCCESS; FAIL wird kein Block mehr gesetzt
// mit PASS; CONSUME; CONSUME_PARTIAL werden immer Blöcke gesetzt
}
// mit SUCCESS; FAIL wird kein Block mehr gesetzt
// mit PASS; CONSUME; CONSUME_PARTIAL werden immer Blöcke gesetzt
}

View File

@ -10,10 +10,12 @@ public class modNetworkingServer { //Identifier werden eingeführt
public static final Identifier request_respawn = new Identifier(REServerMod.MOD_ID, "request_respawn"); //alle Identifier muessen leider IMMER auf Client und Server (doppelt) eingefuehrt werden
public static final Identifier start_sleeping_call_buttons = new Identifier(REServerMod.MOD_ID, "start_sleeping_call_buttons");
public static final Identifier death_multi_respawn_buttons = new Identifier(REServerMod.MOD_ID, "death_call_respawn_buttons");
public static final Identifier grid_block_networking = new Identifier(REServerMod.MOD_ID, "grid_block_networking");
public static void registerC2SPackets() { //Identifier fuer packets werden registriert (Identifier die der Client aufruft um beim Server was auszufuehren)
ServerPlayNetworking.registerGlobalReceiver(start_sleeping_call_buttons, setNewRespawnsC2SPacket::receive); //was der Server dann machen soll steht in der receive Methode
ServerPlayNetworking.registerGlobalReceiver(start_sleeping_call_buttons, setNewRespawnsC2SPacket::receive); //was der Server dann machen soll steht in der receive Methode
ServerPlayNetworking.registerGlobalReceiver(death_multi_respawn_buttons, deathScreenMultiButtonsC2SPacket::receive);
}
}
}

View File

@ -0,0 +1,40 @@
package modchest.networking.packet;
import modchest.networking.modNetworkingServer;
import net.fabricmc.fabric.api.networking.v1.PacketByteBufs;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
import net.minecraft.util.math.BlockPos;
public class TestPacket {
/*PlayerEntity playerEntity;
ServerPlayerEntity serverPlayerEntity;
public final BlockPos blockPos;
public final Text text;
public TestPacket (BlockPos blockPos, Text text){
this.blockPos=blockPos;
this.text =text;
}
public TestPacket(PacketByteBuf buffer2) {
this(buffer2.readBlockPos(), buffer2.readText());
}
public void write(PacketByteBuf buffer2) {
buffer2.writeBlockPos(this.blockPos);
buffer2.writeText(this.text);
}
public PacketByteBuf getBuffer2(PacketByteBuf buffer2){
ServerPlayNetworking.send(serverPlayerEntity, modNetworkingServer.grid_block_networking, buffer2);
return buffer2;
}*/
}

View File

@ -4,6 +4,7 @@ import modchest.block.entity.modBlockEntities;
import modchest.block.modBlocks;
import modchest.event.playerAfterRespawnEvent;
import modchest.event.playerBreakBlockEvents;
import modchest.event.useBlockCallback;
import modchest.item.modItemGroup;
import modchest.item.modItems;
import modchest.networking.modNetworkingServer;
@ -25,6 +26,7 @@ public class initializer {
public static void events() { //Events, bei denen custom Code ausgefuehrt wird, werden eingefuehrt
ServerPlayerEvents.AFTER_RESPAWN.register(new playerAfterRespawnEvent());
PlayerBlockBreakEvents.BEFORE.register(new playerBreakBlockEvents());
useBlockCallback.EVENT.register(new useBlockCallback());
}
public static void networking() { //Identifier unter denen der Server zuhoert werden registriert