Jump to content

fernthedev

Members
  • Posts

    67
  • Joined

  • Last visited

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

fernthedev's Achievements

Stone Miner

Stone Miner (3/8)

0

Reputation

  1. I am trying to make an entity look at another entity but I can't seem to get the math working. My current code is basically a copy-paste of the LookController however when using it on a player it causes the player to keep spinning and does not stop. The pitch is also incorrect causing it to look either at the sky or at the floor. Excuse me in advance for the extremely messy code, but I've been playing around with lots of numbers trying to get different results. My code is found here however the main code is these lines: Set yaw and pitch Find yaw and pitch target Set player's yaw and pitch (This is just for demonstration of code. It is not broken)
  2. Bump and edited post with new code. The code for pitch value is working acceptably fine, all I need to get fixed is the yaw value which does not correctly follow the boundary box according to the camera's orientation and side of the boundary box.
  3. Well basically I want to make the player, when looking at an entity's bounding box, to slowly move to the center. I've got most of it working except I can't get it to move to the center as it can't determine whether it should move the crosshair left of the center or right. My code is currently this: private Vec2f handleAimAssist(float targetYaw, float targetPitch) { Minecraft mc = Minecraft.getInstance(); PlayerEntity player = mc.player; if(player == null) { return new Vec2f(targetPitch, targetYaw); } float resultPitch = targetPitch; float resultYaw = targetYaw; if(mc.objectMouseOver != null && mc.objectMouseOver.getType() == RayTraceResult.Type.ENTITY) { EntityRayTraceResult entityRayTraceResult = (EntityRayTraceResult) mc.objectMouseOver; Entity entity = entityRayTraceResult.getEntity(); ControllerOptions.AimAssistMode mode = getMode(entity); // Config setting option if(entity instanceof LivingEntity && mode != null && mode != ControllerOptions.AimAssistMode.NONE) // Avoid checking entities such as drops or tnt { Vec3d rayHit = entityRayTraceResult.getHitVec(); // Look where the raytrace of the player's view hits AxisAlignedBB targetBox = entity.getBoundingBox().shrink(5); Vec3d targetCoords = targetBox.getCenter(); // Get the center of the entity which is a good starting point double assistIntensity = (Controllable.getOptions().getAimAssistIntensity() / 100.0); // Can be substituted for 1 for debugging code if(mode.sensitivity()) { resultYaw *= (float) (0.14 * assistIntensity); // Slows the sensitivity to stop slingshotting the bounding box. It can still be slingshotted though if attempted. resultPitch *= (float) (0.12 * assistIntensity); // Slows the sensitivity to stop slingshotting the bounding box. It can still be slingshotted though if attempted. } if(mode.aim()) { Vec3d targetXCoords = new Vec3d(targetCoords.x, 0, 0); // To accurately measure distance Vec3d rayXCoords = new Vec3d(rayHit.x, 0, 0); // Measure accurately distance Vec3d targetYCoords = new Vec3d(0, targetCoords.y, 0); // Measure accurately distance Vec3d rayYCoords = new Vec3d(0, rayHit.y, 0); // Measure accurately distance double xDir = changeYDirection(rayHit.x, entity.getBoundingBox().minX, entity.getBoundingBox().maxX, 0.5); // Only modify X if it's leaving box if(xDir != 0) { resultYaw = (float) (toTarget(resultYaw, (float) ((targetXCoords.distanceTo(rayXCoords)) * xDir /* interpolateNegatives(playerLookVec.getX()))*/), (float) targetXCoords.x < rayXCoords.x, 18.0 * assistIntensity) * 0.5); // TODO: Apply rotation to assist since it does not follow the boundary correctly to the orientation of the camera. } double yDir = changeYDirection(rayHit.y, entity.getBoundingBox().minY, entity.getBoundingBox().maxY, 0.25); // Only modify Y level if it's about to leave box if(yDir != 0) { resultPitch = toTarget(resultPitch, (float) (targetYCoords.distanceTo(rayYCoords) * yDir), true, 5.0 * assistIntensity); } } } } return new Vec2f(resultPitch, resultYaw); } private ControllerOptions.AimAssistMode getMode(Entity entity) { if(entity instanceof PlayerEntity) { return Controllable.getOptions().getPlayerAimMode(); } if(entity instanceof MonsterEntity) { return Controllable.getOptions().getHostileAimMode(); } if(entity instanceof AnimalEntity || entity instanceof AmbientEntity) { return Controllable.getOptions().getAnimalAimMode(); } return null; } private float toTarget(float current, float distance, boolean direction, double multiplier) { if(direction) { return (float) ((current - distance) * multiplier); } else { return (float) ((current + distance) * multiplier); } } private double changeYDirection(double hit, double min, double max, double offset) { if(hit <= min + offset) { return 1; } else if(hit >= max - offset) { return -1; } else return 0; } This isn't used for hacking, but rather for a controller mod in which to make it easier to kill entities. Edit: The code for pitch value is working acceptably fine, all I need to get fixed is the yaw value which does not correctly follow the boundary box according to the camera's orientation and side of the boundary box.
  4. For those who don't really understand what is " Fortnite aim-assist", it is basically a feature implemented for controller players to make it harder to miss targets by doing the following: - Lowering sensitivity when moving crosshair away from target exponentially to lower chances of slingshotting the cross hair. - Automatically moving the crosshair relative to the hitbox of the target for an amount of time and strength (meaning you still need to move the joystick to keep up with the movement of the target) I'm not necessarily asking for spoon feeding me all the code, just asking what solutions I could use to implement this. Should it be done on render event or tick event and should it be interpolated to ticks to avoid being frame-bound or not. What math equations or methods for accomplishing this with Minecraft's engine. Note: I am in NO WAY trying to support or create hacks for pvp, I am simply trying to level the field with players using a controller mod. The feature will be toggleable so it will be at the user's discretion and risk.
  5. Ah should have known. Yeah that was what I assumed. What about the Mojang mappings? Any plans to use them or for legal reasons is it not possible?
  6. I'm on Forge version: 1.15.1-30.0.4 Mapping version: mappings channel: 'snapshot', version: '20190807-1.14.3' Some functions like keybindSneak (currently Minecraft.getInstance().gameSettings.field_228046_af_()) is not named keybindSneak Though I can't find anywhere in PlayerEntity or usage of Minecraft.getInstance().gameSettings.field_228046_af_() so I'm not sure if I'm able to check if the player is sneaking at the moment or should I wait for newer Forge releases of the MDK and mappings.
  7. So, last time I made a forum post on how to move the camera with a joystick. My best recommendation was interpolation with Minecraft's renderPartialTicks. However, I seem to find an issue where it would randomly make it move faster or slower or just stop completely, though it did accomplish my task even if inefficient. My goal is to make the camera move at a constant speed, non-dependent on the fps while also making it render smoothly. I'm pretty sure Fortnite has done this, allowing players to move the camera at a constant speed (smoother with more fps obviously) How can I do this or achieve something similar. My code: (currently it is frame-bound in the code) https://github.com/Fernthedev/controller-remap/blob/5de2c0a5085f0defadf3fc7a3361d9ec83411fc0/mod-core/src/main/java/com/github/fernthedev/controllerremapmod/core/ControllerHandler.java#L380-L42
  8. Nevermind, I was quite stupid and didn't realize what I needed to do until I read your response a thousand times in my head. I basically stored the last tick every input movement event and moved the camera every render update event. Thanks a lot for your help, correct me if this practice isn't what you meant and if it does what I was trying to avoid. Aaaaaaaand 5 minutes later after posting this, I realize it's still exactly what I didn't want. Well whoops, should have troubleshooted before posting .-. Well kinda, it works but randomly the camera just stops and starts over as if I let go my joystick and started moving it again immediately A video showing this can be found here, showing the problem and how it's affected in different framerates.
  9. Bump Also if you didn't notice, I edited the reply before this with a new github commit if that helps. https://github.com/Fernthedev/controller-remap/blob/4d883367b92317c47b33d38b88523d4769b2164d/mod-core/src/main/java/com/github/fernthedev/controllerremapmod/core/ControllerHandler.java#L302-L331 It seems to kinda work, it still stutters a lot and moves very little.
  10. So, by old value you mean the old pitch value or old partial ticks? Also is this correct? Because it is too slow at moving and stuttery (Tested with sensitivity = 5 and moves VERY slowly) double deadzoneAmount = updateSettings().getDeadzoneRight(); double oldPitch = player.getRotationPitch(); double oldYaw = player.getRotationYaw(); double newPitch = oldPitch + controller.getAxes().getHORIZONTAL_RIGHT_STICKER().getValue() * updateSettings().getSensitivity(); double newYaw = oldYaw + controller.getAxes().getVERTICAL_RIGHT_STICKER().getValue() * updateSettings().getSensitivity(); double interpolatedPitch = oldPitch + (newPitch - oldPitch) * handler.partialTicks(); // Is Minecraft.getInstance().getRenderPartialTicks(); 1.13 forge double interpolatedYaw = oldYaw + (newYaw - oldYaw) * handler.partialTicks(); // Is Minecraft.getInstance().getRenderPartialTicks(); 1.13 forge // (Ignore this, old comment) Equivalent to (Minecraft.getMinecraft().thePlayer.rotationPitch += controller.getAxes().getHORIZONTAL_RIGHT_STICKER().getValue();) if (!deadzone(controller.getAxes().getHORIZONTAL_RIGHT_STICKER().getValue(), deadzoneAmount)) { interpolatedPitch = (float) oldPitch; } // player.addRotationPitch((float) (controller.getAxes().getHORIZONTAL_RIGHT_STICKER().getValue() * updateSettings().getSensitivity())); // -1 is down, 1 is up, 0 is stateless if (!deadzone(controller.getAxes().getVERTICAL_RIGHT_STICKER().getValue(), deadzoneAmount)) { interpolatedYaw = (float) oldYaw; } setRotation(interpolatedYaw, interpolatedPitch); @Override public void setRotation(double yaw, double pitch) { player.rotationYaw = (float) yaw; player.rotationPitch = (float) pitch; } Edit: As of time of writing this, I have pushed the changes to github here: https://github.com/Fernthedev/controller-remap/blob/4d883367b92317c47b33d38b88523d4769b2164d/mod-core/src/main/java/com/github/fernthedev/controllerremapmod/core/ControllerHandler.java#L302-L331
  11. I've been trying to figure this out for a long time and it's been trivial. I have gotten it to place blocks, though actions such as bows or shields are basically spam clicked and block placement seems faster than it should be. Left click works basically perfectly (as of writing this) My right click code is https://github.com/Fernthedev/controller-remap/blob/aa18ba99264d40fcf509f8907c5bc8b729fdce15/mod-core/src/main/java/com/github/fernthedev/controllerremapmod/core/ControllerHandler.java#L447-L474 Should I try to find a way to modify the useItemKeybind/attackKeybind values rather than mimic the actions instead?
  12. I'm sorry for necroing this post, if it's better to make a new post I will, but I have a few questions to ask. First I did accomplish smooth camera movement though it was just adding to rotationYaw/rotationPitch every render update, which if I understand it correctly, is per frame. This would mean that movement is going to be inconsistent due to it being basically frame bound if I am correct. In other words someone with 200 fps will move the camera faster than someone with 60 fps with the same sensitivity and movement. So as you said I have to use linear interpretation, though I am not entirely sure how to accomplish that. Should I use Minecraft's code to do this or do I have to create my own implementation? I've been looking through Minecraft's code and I've seen values such as (EntityPlayer class) this.interpTargetYaw = (double)yaw; this.interpTargetPitch = (double)pitch; which are modified in setPositionAndRotationDirect(double x, double y, double z, float yaw, float pitch, int posRotationIncrements, boolean teleport) Or do I have to do something such as this: https://stackoverflow.com/questions/36523396/interpolate-function-using-apache-commons-math or https://stackoverflow.com/questions/28961352/java-image-move-along-points-in-list-and-use-linear-interpolation If so, how do I accomplish that when I only have the pitch/yaw value achieved from sensitivity * movementAmount
  13. Nevermind I'm stupid, didn't realize you were using InitGuiEvent
  14. What about 1.13 though? Is there any equivalent to the code uses above or is getChildren() what I have to use?
  15. So I believe you used to be able in 1.12 or pre (I don't really remember) you could add buttons with something as gui.addButton(); or something like that. Is there a replacement for that or should I use reflection? Because as far as I see I don't see any public method for adding buttons. I want to avoid using classes implement other GUIs to fix this due to other mods trying to do the same. I believe a method to add to a list rather than replace the GUI is better since multiple mods can take advantage of it.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.