Jump to content

[1.11.2] Gui drawScreen not with FPS


SuperHB

Recommended Posts

I'm currently working on a mod that adds arcade machines into minecraft. I currently have the gui to render based on ticks. This isn't the best as depending on the FPS the game could run too fast or too slow. I was wondering if it is possible to render parts in GuiScreen#drawScreen consistently at different FPS?

Link to comment
Share on other sites

4 minutes ago, SuperHB said:

I currently have the gui to render based on ticks

Could you please elaborate on that? You can't render anything as a tick happens as rending must happen each frame due to buffers being cleared. A tick is a semi-constant 1/20th of a second. A frame is any numerical value depending on a magnitude of factors. 

Edited by V0idWa1k3r
Link to comment
Share on other sites

Considering above, there is a way to render based on ticks, and it is used by Vanilla entities, chests, etc... Very often in the render/draw method, you get a float parameter partialTick. It is between 0 and 1 and it represents how much in-between 2 ticks the current frame is. Use it to interpolate between previous and next tick and you get smooth transitions / animations.

Link to comment
Share on other sites

The updateScreen method in GuiScreen is called once per tick and can be overridden in your custom GUI.

If you were to make a spinning wheel, for example, you would update the rotation of the wheel every tick in the updateScreen method and then make the wheel spin look smoother in the drawScreen method by using partialTicks.

catch(Exception e)

{

 

}

Yay, Pokémon exception handling, gotta catch 'em all (and then do nothing with 'em).

Link to comment
Share on other sites

18 hours ago, V0idWa1k3r said:

Could you please elaborate on that? You can't render anything as a tick happens as rending must happen each frame due to buffers being cleared. A tick is a semi-constant 1/20th of a second. A frame is any numerical value depending on a magnitude of factors. 

I have a tick counter variable and when that reaches a certain number, the code inside the if statement will run. The problem with this is that the speed of the animation now changes depending on FPS.

Lets say that every 20 ticks I have the code run. In game, if I get 20 FPS the animation will be slow, but if I have 200 FPS the animation will speed up. I'm wondering how I can stop it from doing this, to keep a consistent speed when the game is running at different FPS.

Link to comment
Share on other sites

24 minutes ago, V0idWa1k3r said:

As @Earthcomputer said GuiScreen::updateScreen gets called each tick so operate on your timer there. You still have to render each frame obviously.

This is my first time working with partialTicks. I'm guessing I have to use this formula?

partialTick + partialTick * (currentTick - previousTick)

I have the previousTick and currentTick updated in updateScreen like so:

@Override
public void updateScreen () {
    previousTick = currentTick;
    currentTick++;
}

But I'm not really sure what to do in drawScreen to make sure it runs the animation consistently

Link to comment
Share on other sites

partialTicks is the amount of a single tick that had passed. Using it depends on the way your animation is done. For example if you have a wheel a rotation of which equals to the amount of ticks the GUI is open you would get it's rotation angledeg like this:

ticksExisted + partialTicks.

You don't need to store a previousTick in this case as previousTick always equals currentTick - 1.

Edited by V0idWa1k3r
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Hello everyone, I'm making this post to seek help for my modded block, It's a special block called FrozenBlock supposed to take the place of an old block, then after a set amount of ticks, it's supposed to revert its Block State, Entity, data... to the old block like this :  The problem I have is that the system breaks when handling multi blocks (I tried some fix but none of them worked) :  The bug I have identified is that the function "setOldBlockFields" in the item's "setFrozenBlock" function gets called once for the 1st block of multiblock getting frozen (as it should), but gets called a second time BEFORE creating the first FrozenBlock with the data of the 1st block, hence giving the same data to the two FrozenBlock :   Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=head] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@73681674 BlockEntityData : id:"minecraft:bed",x:3,y:-60,z:-6} Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=3, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=2, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} here is the code inside my custom "freeze" item :    @Override     public @NotNull InteractionResult useOn(@NotNull UseOnContext pContext) {         if (!pContext.getLevel().isClientSide() && pContext.getHand() == InteractionHand.MAIN_HAND) {             BlockPos blockPos = pContext.getClickedPos();             BlockPos secondBlockPos = getMultiblockPos(blockPos, pContext.getLevel().getBlockState(blockPos));             if (secondBlockPos != null) {                 createFrozenBlock(pContext, secondBlockPos);             }             createFrozenBlock(pContext, blockPos);             return InteractionResult.SUCCESS;         }         return super.useOn(pContext);     }     public static void createFrozenBlock(UseOnContext pContext, BlockPos blockPos) {         BlockState oldState = pContext.getLevel().getBlockState(blockPos);         BlockEntity oldBlockEntity = oldState.hasBlockEntity() ? pContext.getLevel().getBlockEntity(blockPos) : null;         CompoundTag oldBlockEntityData = oldState.hasBlockEntity() ? oldBlockEntity.serializeNBT() : null;         if (oldBlockEntity != null) {             pContext.getLevel().removeBlockEntity(blockPos);         }         BlockState FrozenBlock = setFrozenBlock(oldState, oldBlockEntity, oldBlockEntityData);         pContext.getLevel().setBlockAndUpdate(blockPos, FrozenBlock);     }     public static BlockState setFrozenBlock(BlockState blockState, @Nullable BlockEntity blockEntity, @Nullable CompoundTag blockEntityData) {         BlockState FrozenBlock = BlockRegister.FROZEN_BLOCK.get().defaultBlockState();         ((FrozenBlock) FrozenBlock.getBlock()).setOldBlockFields(blockState, blockEntity, blockEntityData);         return FrozenBlock;     }  
    • It is an issue with quark - update it to this build: https://www.curseforge.com/minecraft/mc-mods/quark/files/3642325
    • Remove Instant Massive Structures Mod from your server     Add new crash-reports with sites like https://paste.ee/  
    • Update your drivers: https://www.amd.com/en/support/graphics/amd-radeon-r9-series/amd-radeon-r9-200-series/amd-radeon-r9-280x
  • Topics

×
×
  • Create New...

Important Information

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