-
-
Save ReDestroyDeR/82b773a3a8b6d7d388d792eee4ddd14a to your computer and use it in GitHub Desktop.
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
package ru.red.sorting.items | |
import net.minecraft.client.Minecraft | |
import net.minecraft.nbt.CompoundTag | |
import net.minecraft.world.{InteractionHand, InteractionResultHolder} | |
import net.minecraft.world.entity.player.Player | |
import net.minecraft.world.item.{Item, ItemStack, Rarity} | |
import net.minecraft.world.level.Level | |
import net.minecraftforge.event.TickEvent | |
import net.minecraftforge.eventbus.api.SubscribeEvent | |
import ru.red.sorting.manager.SortingManager | |
import java.util.Timer | |
import scala.util.Random | |
import scala.util.control.Breaks.break | |
object Shuffle extends Item(new Item.Properties() | |
.rarity(Rarity.EPIC) | |
.stacksTo(1) | |
.fireResistant() | |
) { | |
{ | |
this.setRegistryName("shuffle") | |
} | |
override def use(pLevel: Level, | |
pPlayer: Player, | |
pUsedHand: InteractionHand): InteractionResultHolder[ItemStack] = { | |
val itemStack = pPlayer.getItemInHand(pUsedHand) | |
val plain = SortingManager.getById( | |
itemStack.getTag | |
.getInt("sortingPlainId") | |
) | |
val random = new Random() | |
val array = plain.getArray | |
var i = 0 | |
val level = Minecraft.getInstance().level | |
def shuffle(): Unit = { | |
while (true) { | |
if (level != null && level.getLevelData.getGameTime % 5 == 0) { | |
val j = random.nextInt(array.length) | |
val t = array(j) | |
array(j) = array(i) | |
array(i) = t | |
plain.sync(array) | |
i += 1 | |
if (i >= array.length) { | |
return | |
} | |
} | |
} | |
} | |
shuffle() | |
InteractionResultHolder.success(itemStack) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment