# [1.15.2] Smoothly interpolating Power Generation

## Recommended Posts

Hello all!
So i have a bit of a odd question.
I have a Power generator that works all fine, but the power being all added in at the end of the burn time is not exactly what I want to do.
Let's say i want to add... 2500 power units over 1600 ticks. How would i go about doing that when the power system only accepts Integers to add?

I have tried

```int power = 2500 / 1600;

but obviously this won't work because it rounds the result to a Integer, only generating 1600 and not 2500 power units.

Any help on this would be great, thank you!

##### Share on other sites

if addPower() accepts floats, just use a float

I don't know how that power system works but

int power = 2500/1600;

float powerLeft = 2500;
for(int i=1600; i>0; i--){ //make this run once every tick instead of this for loop, but remember to make i work the same
power = powerLeft/i;
powerLeft -= power;
}

##### Share on other sites

I'm using the built in ForgeEnergy system and the issue is that it only allows power as a int.
So i'm trying to make it so power is added smoothly over time rather then all at once.

##### Share on other sites

Disclaimer: I haven't used any energy system in my mods yet.

```private int ratePerTick = 20; // adjust if needed
private int powerRemaining = 2500; // will be changed by other code

public void tick() {
if (powerRemaining > ratePerTick) {
powerRemaining -= ratePerTick;
} else {
if (powerRemaining > 0) {
}
powerRemaining = 0;
}
}```

##### Share on other sites

Howdy

The basic algorithm for doing things like this is to add a different amount each tick.

For example, if you wanted to add 30 power units over 20 ticks, you would add

2 units on the first tick

1 unit on the second tick

2 units on the third tick

1 unit on the fourth tick

(etc) for 20 ticks in total.

You need to track the fractional part yourself

INITIALISING:

float ratePerTick = 2500.0/1600.0;

float remainder = 0.0;

EVERY TICK:

remainder += ratePerTick;

-TGG

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

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

×   Pasted as rich text.   Restore formatting

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

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

×

• ### Posts

• sadly, despite everything I'm still facing the same problem. Does anyone have any other suggestions?
• Hey i know you might not be needing this anymore, but it may be useful for people who might look into this, this occurs because you ran out of IDs for blocks,biomes,items and so on, minecraft limits the amount of IDs you can have at once to fix this you can either download NotEnoughIDs at: https://legacy.curseforge.com/minecraft/mc-mods/notenoughids Or Roughly Enough IDs at https://www.curseforge.com/minecraft/mc-mods/reid Both mods increase the limit for IDs ingame. Hope I help anyone who had the same troubles I had the same time!
• so i try ed installing better mc to my minecraft server and when i start the server it crashes can somebody hel me please ? [11:55:10] [main/ERROR] [mixin/]: Mixin config debugify-common.mixins.json does not specify "minVersion" property

• ### Who's Online (See full list)

×

• #### Activity

×
• Create New...