-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for method=cycle in the enchantment type
Fixes #15
- Loading branch information
Showing
5 changed files
with
120 additions
and
33 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
17 changes: 17 additions & 0 deletions
17
src/main/java/shcm/shsupercm/fabric/citresewn/mixin/citenchantment/MinecraftClientMixin.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,17 @@ | ||
package shcm.shsupercm.fabric.citresewn.mixin.citenchantment; | ||
|
||
import net.minecraft.client.MinecraftClient; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
import static shcm.shsupercm.fabric.citresewn.pack.cits.CITEnchantment.MergeMethod.ticks; | ||
|
||
@Mixin(MinecraftClient.class) | ||
public class MinecraftClientMixin { | ||
@Inject(method = "tick", at = @At("HEAD")) | ||
public void onTick(CallbackInfo ci) { | ||
ticks++; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package shcm.shsupercm.util.logic; | ||
|
||
import java.util.*; | ||
|
||
/** | ||
* This class(or class portion) is a part of SHCM's utilities. Feel free to use without credit. | ||
*/ | ||
public class Loops { | ||
/** | ||
* Creates a loop of T with linked intensities allowing for fading between the elements. | ||
* @param items list of items and pause durations(in time units) ordered as they are in the loop | ||
* @param fade time in units to fade between each item | ||
* @param ticks positive raising counter | ||
* @param tpu the amount of ticks per time unit | ||
* @param <T> element type | ||
* @return map of elements and their respective intensities(between 0.0f and 1.0f) | ||
*/ | ||
public static <T> Map<T, Float> statelessFadingLoop(List<Map.Entry<T, Float>> items, float fade, int ticks, int tpu) { | ||
Map<T, Float> itemValues = new HashMap<>(); | ||
|
||
if (items == null || items.size() == 0) | ||
return itemValues; | ||
|
||
if (items.size() == 1) { | ||
itemValues.put(items.get(0).getKey(), 1f); | ||
return itemValues; | ||
} | ||
|
||
float totalUnitsInLoop = 0f; | ||
for (Map.Entry<T, Float> item : items) { | ||
itemValues.put(item.getKey(), 0f); | ||
totalUnitsInLoop += item.getValue() + fade; | ||
} | ||
|
||
float unitInLoop = (ticks % (tpu * totalUnitsInLoop)) / tpu; | ||
|
||
for (int i = 0; i < items.size(); i++) { | ||
Map.Entry<T, Float> item = items.get(i); | ||
if (unitInLoop < item.getValue()) { | ||
itemValues.put(item.getKey(), 1f); | ||
break; | ||
} else | ||
unitInLoop -= item.getValue(); | ||
|
||
if (unitInLoop < fade) { | ||
Map.Entry<T, Float> nextItem = items.get(i + 1 >= items.size() ? 0 : i + 1); | ||
|
||
unitInLoop /= fade; | ||
|
||
itemValues.put(item.getKey(), 1f - unitInLoop); | ||
itemValues.put(nextItem.getKey(), unitInLoop); | ||
|
||
break; | ||
} else | ||
unitInLoop -= fade; | ||
} | ||
|
||
return itemValues; | ||
} | ||
} |
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