-
Posts
34 -
Joined
-
Last visited
-
Days Won
1
Everything posted by andreybadrey
-
I myself spent a lot of time before I managed to do this
-
Working example plugins { //...... } version = '1.0' group = 'com.bodryak.gmod' archivesBaseName = 'gmodmod' jarJar.enable() tasks.jarJar.configure { } minecraft {.....} dependencies { minecraft 'net.minecraftforge:forge:1.19.2-43.2.3' implementation group: 'mysql', name: 'mysql-connector-java', version: '8.0.33' jarJar(group: 'mysql', name: 'mysql-connector-java', version: '[8.0.26,8.0.33)'){ jarJar.pin(it, "8.0.33") } } inser : jarJar.enable() tasks.jarJar.configure { } before minecraf{ } and implementation group: 'mysql', name: 'mysql-connector-java', version: '8.0.33' jarJar(group: 'mysql', name: 'mysql-connector-java', version: '[8.0.26,8.0.33)'){ jarJar.pin(it, "8.0.33") } in dependencies and after compilation the connector will be embroidered into the jar in order for the connector to work in the test environment during runtime, you need edit file runClient_minecraftClasspath insert full path to mysql connector in the first line after that mysql connector will run with the client if that doesn't work, you'll need to deep tune the programming environment, but the point remains the same: you'll need to configure the launch options for the client along with the MSCL library
-
This may not be accurate, I haven’t worked on it yet, I’m just planning, but as far as I managed to understand, to scale individual elements, you need to sequentially write the following methods PoseStack.pushPose(); PoseStack.scale(); PoseStack.translate(); PoseStack.popPose(); I'm not entirely sure what I'm saying Watch this gitHub
-
How to Get the Entity the Player is Looking At 1.19.3
andreybadrey replied to Noxxous's topic in Modder Support
import java.util.function.Predicate; import net.minecraft.client.Minecraft; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.util.Mth; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.projectile.ProjectileUtil; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.ClipContext; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.material.FluidState; import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.EntityHitResult; import net.minecraft.world.phys.HitResult; import net.minecraft.world.phys.Vec3; import net.minecraft.world.phys.shapes.VoxelShape; public class RayTrace implements BlockGetter { private static Predicate<Entity> isVisible = entity -> !entity.isSpectator() && entity.isPickable(); private static Minecraft minecraft = Minecraft.getInstance(); @Override public BlockEntity getBlockEntity(BlockPos pos) { return minecraft.level.getBlockEntity(pos); } @Override public BlockState getBlockState(BlockPos pos) { return minecraft.level.getBlockState(pos); } @Override public FluidState getFluidState(BlockPos pos) { return minecraft.level.getFluidState(pos); } public LivingEntity getEntityInCrosshair(float partialTicks, double reachDistance) { Minecraft client = Minecraft.getInstance(); Entity viewer = client.getCameraEntity(); if (viewer == null) { return null; } Vec3 position = viewer.getEyePosition(partialTicks); Vec3 look = viewer.getViewVector(1.0F); Vec3 max = position.add(look.x * reachDistance, look.y * reachDistance, look.z * reachDistance); AABB searchBox = viewer.getBoundingBox().expandTowards(look.scale(reachDistance)).inflate(1.0D, 1.0D, 1.0D); EntityHitResult result = ProjectileUtil.getEntityHitResult(viewer, position, max, searchBox, isVisible, reachDistance * reachDistance); if (result == null || result.getEntity() == null) { return null; } if (result.getEntity() instanceof LivingEntity) { LivingEntity target = (LivingEntity) result.getEntity(); HitResult blockHit = clip(setupRayTraceContext(client.player, reachDistance, ClipContext.Fluid.NONE)); if (!blockHit.getType().equals(BlockHitResult.Type.MISS)) { double blockDistance = blockHit.getLocation().distanceTo(position); if (blockDistance > target.distanceTo(client.player)) { return target; } } else { return target; } } return null; } private ClipContext setupRayTraceContext(Player player, double distance, ClipContext.Fluid fluidHandling) { float pitch = player.getXRot(); float yaw = player.getYRot(); Vec3 fromPos = player.getEyePosition(1.0F); float float_3 = Mth.cos(-yaw * 0.017453292F - 3.1415927F); float float_4 = Mth.sin(-yaw * 0.017453292F - 3.1415927F); float float_5 = -Mth.cos(-pitch * 0.017453292F); float xComponent = float_4 * float_5; float yComponent = Mth.sin(-pitch * 0.017453292F); float zComponent = float_3 * float_5; Vec3 toPos = fromPos.add((double) xComponent * distance, (double) yComponent * distance, (double) zComponent * distance); return new ClipContext(fromPos, toPos, ClipContext.Block.OUTLINE, fluidHandling, player); } @Override public BlockHitResult clip(ClipContext context) { return BlockGetter.traverseBlocks(context.getFrom(), context.getTo(), context, (c, pos) -> { BlockState block = this.getBlockState(pos); if (!block.canOcclude()) { return null; } VoxelShape voxelshape = c.getBlockShape(block, this, pos); return this.clipWithInteractionOverride(c.getFrom(), c.getTo(), pos, voxelshape, block); }, (c) -> { Vec3 vec3 = c.getFrom().subtract(c.getTo()); return BlockHitResult.miss(c.getTo(), Direction.getNearest(vec3.x, vec3.y, vec3.z), new BlockPos(c.getTo())); }); } @Override public int getHeight() { return 0; } @Override public int getMinBuildHeight() { return 0; } } -
I saw that the forum was also interested in this topic, so I will prescribe the package template import com.bodryak.gmod.variables.client.PDC; import com.google.common.collect.Maps; import net.minecraft.network.FriendlyByteBuf; import net.minecraftforge.network.NetworkEvent; import java.util.Map; import java.util.function.Supplier; public class PDSyncS2CPacket { private final Map<String, Long> toSync ; public PDSyncS2CPacket(Map<String, Long> map) { this.toSync = map; } public PDSyncS2CPacket(FriendlyByteBuf buf) { this.toSync = buf.readMap(Maps::newHashMapWithExpectedSize,FriendlyByteBuf::readUtf, FriendlyByteBuf::readLong); } public void toBytes(FriendlyByteBuf buf) { buf.writeMap(this.toSync, FriendlyByteBuf::writeUtf, FriendlyByteBuf::writeLong); } public boolean handle(Supplier<NetworkEvent.Context> supplier) { NetworkEvent.Context context = supplier.get(); context.enqueueWork(() -> { // HERE WE ARE ON THE CLIENT! if (this.toSync.get("lvl") != null){ PDC.setLvl(this.toSync.get("lvl")); System.out.println("Server send lvl " + this.toSync.get("lvl")); } if (this.toSync.get("exp") != null){ PDC.setExp(this.toSync.get("exp")); System.out.println("server send exp " + this.toSync.get("exp")); } if (this.toSync.get("nlv") != null){ PDC.setNlv(this.toSync.get("nlv")); System.out.println("server send exp to next lvl " + this.toSync.get("nlv")); } }); return true; } } Please, I beg you, if all this is not written correctly, give feedback
-
It seems that I won one part, but still not completely public void toBytes(Map<String, Long> map,FriendlyByteBuf buf) { buf.writeMap(map, (friendlyByteBuf, s) -> {}, (friendlyByteBuf, aLong) -> {}); } But it's still not right, is it? and how to arrange {....} ? following the logic, I wrote this public void toBytes(Map<String, Long> map,FriendlyByteBuf buf) { buf.writeMap(map, FriendlyByteBuf::writeUtf, FriendlyByteBuf::writeLong); } in short, I won
-
Hello everyone, I'm new, I'm working on an RPG mod and have achieved good results now I'm working on compressing the package system, namely, I want to combine all the player variable synchronization packages into one multifunctional package at the moment I have to synchronize each player characteristic with a separate package, because if you combine all the characteristics in one package, then in my opinion this will give a huge load on the server with good online I want to write a package that will send data to the client in the form of a HashMap() something like this: if the player's experience is updated, The server sends to the client Map<"exp", 200 000> If the level of the player has changed during the increase in experience, the server sends to the client Map<"exp", 200 000><"lvl", 3> The client, having received this packet, reads the entire HashMap in turn, and updates only those data that have been changed and transmitted I am facing the following difficulties: 1. buf.writeMap(Map<K, V> p_236832_, FriendlyByteBuf.Writer<K> p_236833_, FriendlyByteBuf.Writer<V> p_236834_) as far as I understand Map<K, V> p_236832_ the read source is passed to this parameter, namely the Map() object, I managed to send it FriendlyByteBuf.Writer<K> & FriendlyByteBuf.Writer<V> I don’t understand how to format it correctly, after many attempts and sorting through everything I already know, it turned out to make these parameters accepted through lambdas and did not cause errors, but most likely it was not correct 2. buf.readMap(FriendlyByteBuf.Reader<K> p_236848_, FriendlyByteBuf.Reader<V> p_236849_) FriendlyByteBuf.Reader<K> & FriendlyByteBuf.Reader<V> What is it? because the method returns this.readMap(Maps::newHashMapWithExpectedSize, p_236848_, p_236849_); I realized that there is a bork in a new map, but again I don’t understand how to count from the transferred map keys & values please help me to write these two methods in correct syntax show any example, at least in which it will be clear what data is passed to these methods