-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(doesnt work)
- Loading branch information
Showing
5 changed files
with
157 additions
and
56 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
src/main/java/gregtech/api/capability/impl/ActiveTransformerBuffer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package gregtech.api.capability.impl; | ||
|
||
import gregtech.api.capability.ILaserContainer; | ||
import net.minecraft.util.EnumFacing; | ||
|
||
public class ActiveTransformerBuffer implements ILaserContainer { | ||
private final long capacity; | ||
private long stored = 0L; | ||
|
||
public ActiveTransformerBuffer(long capacity) { | ||
this.capacity = capacity; | ||
} | ||
|
||
@Override | ||
public long acceptEnergy(EnumFacing side, long amount) { | ||
return changeEnergy(amount); | ||
} | ||
|
||
@Override | ||
public long changeEnergy(long amount) { | ||
if (amount > capacity - stored) { | ||
amount = capacity - stored; | ||
} else if (-amount > stored) { | ||
amount = -stored; | ||
} | ||
stored += amount; | ||
return amount; | ||
} | ||
|
||
@Override | ||
public boolean inputsEnergy(EnumFacing side) { | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean outputsEnergy(EnumFacing side) { | ||
return true; | ||
} | ||
|
||
@Override | ||
public long getEnergyStored() { | ||
return stored; | ||
} | ||
|
||
@Override | ||
public long getEnergyCapacity() { | ||
return capacity; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/test/java/gregtech/api/capability/impl/ActiveTransformerBufferTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package gregtech.api.capability.impl; | ||
|
||
import org.hamcrest.MatcherAssert; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
|
||
class ActiveTransformerBufferTest { | ||
|
||
@Test | ||
void changeEnergy() { | ||
ActiveTransformerBuffer buffer = new ActiveTransformerBuffer(1024L); | ||
MatcherAssert.assertThat(buffer.getEnergyCapacity(), is(1024L)); | ||
|
||
MatcherAssert.assertThat(buffer.changeEnergy(128), is(128L)); | ||
MatcherAssert.assertThat(buffer.getEnergyStored(), is(128L)); | ||
|
||
MatcherAssert.assertThat(buffer.changeEnergy(-64), is(-64L)); | ||
MatcherAssert.assertThat(buffer.getEnergyStored(), is(64L)); | ||
|
||
MatcherAssert.assertThat(buffer.changeEnergy(-16384), is(-64L)); | ||
MatcherAssert.assertThat(buffer.getEnergyStored(), is(0L)); | ||
|
||
MatcherAssert.assertThat(buffer.changeEnergy(2048), is(1024L)); | ||
MatcherAssert.assertThat(buffer.getEnergyStored(), is(1024L)); | ||
} | ||
} |