-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
31a77f5
commit a4c7037
Showing
6 changed files
with
74 additions
and
10 deletions.
There are no files selected for viewing
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
14 changes: 14 additions & 0 deletions
14
src/main/kotlin/atm/bloodworkxgaming/bloodyLib/BloodyLibConfig.kt
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,14 @@ | ||
package atm.bloodworkxgaming.bloodyLib | ||
|
||
import net.minecraftforge.common.config.Config | ||
|
||
@Config(modid = BloodyLib.MOD_ID, name = "bloodymods/bloodylib") | ||
object BloodyLibConfig { | ||
@Config.Comment("How many ticks to wait in between sending the changed NBT to the clients") | ||
@JvmStatic | ||
var incrementalNbtUpdateInterval = 5 | ||
|
||
@Config.Comment("How many ticks to wait in between sending the full NBT to the clients") | ||
@JvmStatic | ||
var fullNbtUpdateInterval = 40 | ||
} |
29 changes: 23 additions & 6 deletions
29
src/main/kotlin/atm/bloodworkxgaming/bloodyLib/cache/SortingLinkedList.kt
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 |
---|---|---|
@@ -1,27 +1,44 @@ | ||
package atm.bloodworkxgaming.bloodyLib.cache | ||
|
||
import net.minecraft.item.ItemStack | ||
import java.util.* | ||
|
||
abstract class SortingLinkedList<T>(c: Collection<T>, private inline val loader: (T, ItemStack) -> Boolean) { | ||
/** | ||
* This is a delegation of a linked list: | ||
* It is only efficient in the following cases: (or atleast more efficient than a set or arraylist) | ||
* There are no hashcode or eqauls method | ||
* The loader function is not expensive to compute and therefore doesn't make much sense to cache | ||
* | ||
* @param nonMoveCount How many elements from the front the element can be before starting it should start to move it to the front | ||
*/ | ||
class SortingLinkedList<K, T>(private inline val loader: (iterator: K, listElement: T) -> Boolean, private val nonMoveCount: Int = 3, c: Collection<T> = emptyList()) : Iterable<T>{ | ||
|
||
private val list = LinkedList<T>(c) | ||
|
||
fun get(stack: ItemStack): T? { | ||
fun get(stack: K): T? { | ||
val iter = list.iterator() | ||
var result: T? = null | ||
var counter = 0 | ||
while (iter.hasNext()) { | ||
val next = iter.next() | ||
if (loader(next, stack)) { | ||
counter++ | ||
|
||
if (loader(stack, next)) { | ||
result = next | ||
iter.remove() | ||
|
||
if (counter > nonMoveCount) | ||
iter.remove() | ||
break | ||
} | ||
|
||
} | ||
|
||
result ?: return null | ||
|
||
list.addFirst(result) | ||
if (counter > nonMoveCount) | ||
list.addFirst(result) | ||
|
||
return result | ||
} | ||
|
||
override fun iterator(): Iterator<T> = list.iterator() | ||
} |
30 changes: 30 additions & 0 deletions
30
src/main/kotlin/atm/bloodworkxgaming/bloodyLib/fluid/FluidTankBase.kt
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,30 @@ | ||
package atm.bloodworkxgaming.bloodyLib.fluid | ||
|
||
import atm.bloodworkxgaming.bloodyLib.networking.NBTSerializationState | ||
import com.sun.org.apache.xpath.internal.operations.Bool | ||
import net.minecraft.nbt.NBTTagCompound | ||
import net.minecraftforge.common.util.INBTSerializable | ||
import net.minecraftforge.fluids.Fluid | ||
import net.minecraftforge.fluids.FluidStack | ||
import net.minecraftforge.fluids.FluidTank | ||
|
||
class FluidTankBase(private val nbtState: NBTSerializationState, capacity: Int, fluid: FluidStack? = null, canFill: Boolean = true, canDrain: Boolean = true) | ||
: FluidTank(fluid, capacity), INBTSerializable<NBTTagCompound> { | ||
|
||
init { | ||
this.canDrain = canDrain | ||
this.canFill = canFill | ||
} | ||
|
||
constructor(nbtState: NBTSerializationState, capacity: Int, fluid: Fluid, amount: Int) : this(nbtState, capacity, FluidStack(fluid, amount)) | ||
|
||
override fun deserializeNBT(nbt: NBTTagCompound?) { | ||
this.readFromNBT(nbt) | ||
} | ||
|
||
override fun serializeNBT(): NBTTagCompound = writeToNBT(NBTTagCompound()) | ||
|
||
override fun onContentsChanged() { | ||
nbtState.scheduleUpdate() | ||
} | ||
} |
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