Jump to content

fernthedev

Members
  • Posts

    67
  • Joined

  • Last visited

Posts posted by fernthedev

  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:

  2. 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.

  3. 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.

  4. 8 hours ago, Ommina said:

    Player .isSneaking is now .isCrouching

     

     

     

    Ah should have known. 
     

     

    8 hours ago, Draco18s said:

    Yeah, because the mappings you're using are for 1.14.3 and mappings for 1.15 don't exist yet.

    Yeah that was what I assumed. What about the Mojang mappings? Any plans to use them or for legal reasons is it not possible?

  5. 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.

  6. 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

     

  7. 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.

     

  8. 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

  9. 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?

  10. 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

     

     

  11. 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.

  12. Not entirely sure why this is the case, as a config file's use case is for information that can be changed causes this warning and resets the value to default:

    [09:55:03] [Client thread/WARN]: Configuration file .minecraft\config\controller-remap-client.toml is not correct. Correcting
    [09:55:03] [Client thread/WARN]: Incorrect key Controller.sensitivity was corrected from 0.5371126755326987 to 1.0

    Code: 

        private ForgeConfigSpec.DoubleValue sensitivityConfig;
    
        private ForgeConfigSpec.ConfigValue<String> selectedMappingConfig;
    
    public void build(ForgeConfigSpec.Builder builder) {
            builder.push(MAIN_CATEGORY);
    
            sensitivityConfig = builder.comment("The sensitivity of the controller").defineInRange("sensitivity",1.0,-3.0,-3.0);
    
            selectedMappingConfig = builder.comment("The controller mapping that should be used").define("selectedmapping","xboxone");
    
    
    
            builder.pop();
    
            //buildDirectoryMappings();
    
            builder.build();
    
            final IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();
            modEventBus.addListener((ModConfig.ModConfigEvent event) -> {
                new RuntimeException("Got config " + event.getConfig() + " name " + event.getConfig().getModId() + ":" + event.getConfig().getFileName());
                final ModConfig config = event.getConfig();
                if (config.getSpec() == ConfigHandler.getCLIENT_SPEC()) {
                    load(config);
                }
    
                if(onFirstLoad != null) {
                    onFirstLoad.run();
                    onFirstLoad = null;
                }
            });
        }
    
        private void load(ModConfig config) {
            this.modConfig = config;
    
            sensitivity = sensitivityConfig.get();
    
            reloadMappings();
        }
    
        public void reloadMappings() {
            loadedMappingList.clear();
            File dir = new File(FMLPaths.CONFIGDIR.get().toFile(),"mappings");
    
            if(!dir.exists()) {
                dir.mkdir();
            }
    
            String fileMapping = selectedMappingConfig.get();
    
            if(dir.isDirectory() && dir.listFiles() != null) {
    
    
                for (File file : Objects.requireNonNull(dir.listFiles())) {
                    if(!FilenameUtils.isExtension(file.getName(),"mapping")) continue;
    
                    if(FilenameUtils.removeExtension(file.getName()).equalsIgnoreCase("template")) continue;
    
                    if(file.isDirectory()) continue;
    
                    MappingConfig config = MappingConfig.loadConfig(file);
    
                    if(FilenameUtils.removeExtension(file.getName()).equalsIgnoreCase(fileMapping)) {
                        selectedMapping = config;
                    }
    
                    loadedMappingList.add(config);
                }
            }
        }
  13. 2 hours ago, Cadiboo said:

    Run the game in debug mode, open up the config screen, select NoCubes (see the greyed our config button), recompile the GuiModList and hotswap it in (just save it in eclipse). This will put the code from my modified version into the game (the one that enables the config for NoCubes). 

    I’m guessing that doesn’t apply to Intelij?

  14. 20 minutes ago, Cadiboo said:

    With my repo? You need to launch the game, then recompile & hotswap the ModListGui from Forge. This enabled the Config GUI for NoCubes. Then you should be able to open the config menu. I’m thinking of removing the hasConfig method from ModInfo and replacing it with something else instead 

    So by recompile and hotswap, how is that done? Is it a gradle task or something I specify in build.gradle? 

  15. Just now, Cadiboo said:

    I was thinking

    ConfigGuiHandler.getGuiFactoryFor(selectedMod).map(f->f.apply(this.mc, this)).ifPresent(newScreen -> this.mc.displayGuiScreen(newScreen)).orElse(() -> {

       if(selectedMod.hasConfigs())

           this.mc.displayGuiScreen(new GuiConfig(selectedMod.getConfigs()));

    });

    Seems good to me :P I'm just fixing java references and fixing override methods atm. 

  16. Just now, Cadiboo said:

    With my repo? You need to launch the game, then recompile & hotswap the ModListGui from Forge. This enabled the Config GUI for NoCubes. Then you should be able to open the config menu. I’m thinking of removing the hasConfig method from ModInfo and replacing it with something else instead 

    Thanks, how about replace for a list getConfigs() instead of a boolean hasConfig(), and if you want to check if it has a config check if the list is empty :P 

  17. 7 minutes ago, Cadiboo said:

    It’s not really the GUI that’s the issue right now, it’s trying to understand how the old system works and trying to apply that to the slightly incomplete new system. The IConfigElement used by the old system needs significant changes, so do the config elements in the GUI. I’m not sure how to handle categories or the different input types (these changed too) and I haven’t even thought of how to make it save yet. 

    I'll take a look. To test, how would I open the config menu? Just clicking Config or what?

  18. 3 minutes ago, Cadiboo said:

    It’s not implemented yet and cpw doesn’t have the time to work it out with his real world commitments and 1.14. If you’d like to help, I’m trying to do some work on porting it at https://github.com/Cadiboo/NoCubes/tree/1.13.2-config (currently only has the base GUI without any of the config entries implemented).

    I'd love to help, though that would be difficult for me since I'm not very experienced making GUIS. Ill try do atleast something if I can though

×
×
  • Create New...

Important Information

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