-
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
Showing
6 changed files
with
183 additions
and
2 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
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
110 changes: 110 additions & 0 deletions
110
src/main/java/com/cleanroommc/neverenoughanimations/animations/ItemPickupThrowAnimation.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,110 @@ | ||
package com.cleanroommc.neverenoughanimations.animations; | ||
|
||
import com.cleanroommc.neverenoughanimations.IItemLocation; | ||
import com.cleanroommc.neverenoughanimations.NEAConfig; | ||
import it.unimi.dsi.fastutil.objects.Object2LongOpenHashMap; | ||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.client.gui.FontRenderer; | ||
import net.minecraft.client.gui.inventory.GuiContainer; | ||
import net.minecraft.client.renderer.GlStateManager; | ||
import net.minecraft.client.renderer.RenderItem; | ||
import net.minecraft.inventory.Slot; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraftforge.client.event.GuiOpenEvent; | ||
import org.jetbrains.annotations.ApiStatus; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
|
||
public class ItemPickupThrowAnimation { | ||
|
||
private static final Object2LongOpenHashMap<IItemLocation> animated = new Object2LongOpenHashMap<>(); | ||
private static final List<IItemLocation> removalAnimation = new ArrayList<>(); | ||
private static GuiContainer lastGui; | ||
|
||
@ApiStatus.Internal | ||
public static void onGuiOpen(GuiOpenEvent event) { | ||
if (NEAConfig.hoverAnimationTime > 0) { | ||
if (!(event.getGui() instanceof GuiContainer)) { | ||
if (lastGui != null) { | ||
lastGui = null; | ||
animated.clear(); | ||
} | ||
return; | ||
} | ||
if (!NEAConfig.isBlacklisted(event.getGui())) { | ||
lastGui = (GuiContainer) event.getGui(); | ||
animated.clear(); | ||
} | ||
} | ||
} | ||
|
||
public static void animate(Slot slot) { | ||
if (lastGui == null) return; | ||
animate(IItemLocation.of(slot)); | ||
} | ||
|
||
public static void animate(IItemLocation slot) { | ||
if (lastGui == null) return; | ||
animated.put(slot, Minecraft.getSystemTime()); | ||
if (slot.nea$getSlotNumber() < 0) removalAnimation.add(slot); | ||
} | ||
|
||
public static void animate(int x, int y, ItemStack stack, boolean absolutePos) { | ||
if (lastGui == null) return; | ||
if (absolutePos) { | ||
x -= lastGui.getGuiLeft(); | ||
y -= lastGui.getGuiTop(); | ||
} | ||
animate(new IItemLocation.Impl(x, y, stack)); | ||
} | ||
|
||
public static float getValue(GuiContainer container, Slot slot) { | ||
return getValue(container, IItemLocation.of(slot)); | ||
} | ||
|
||
public static float getValue(GuiContainer container, IItemLocation slot) { | ||
if (lastGui != container || !animated.containsKey(slot)) return 1f; | ||
long time = animated.getLong(slot); | ||
float val = (Minecraft.getSystemTime() - time) / (float) NEAConfig.appearAnimationTime; | ||
if (val >= 1f) { | ||
animated.removeLong(slot); | ||
return 1f; | ||
} | ||
return NEAConfig.appearAnimationCurve.interpolate(0f, 1f, val); | ||
} | ||
|
||
public static void drawIndependentAnimations(GuiContainer container, RenderItem itemRender, FontRenderer fontRenderer) { | ||
for (Iterator<IItemLocation> iterator = removalAnimation.iterator(); iterator.hasNext(); ) { | ||
IItemLocation slot = iterator.next(); | ||
int x = slot.nea$getX(); | ||
int y = slot.nea$getY(); | ||
float value = 1f - getValue(container, slot); | ||
if (value <= 0f) { | ||
iterator.remove(); | ||
continue; | ||
} | ||
GlStateManager.translate(x, y, 0); | ||
if (value <= 1f) { | ||
GlStateManager.pushMatrix(); | ||
GlStateManager.translate(8, 8, 0); | ||
GlStateManager.scale(value, value, 1); | ||
GlStateManager.translate(-8, -8, 0); | ||
} else if (!animated.containsKey(slot)) { | ||
iterator.remove(); | ||
GlStateManager.translate(-x, -y, 0); | ||
continue; | ||
} | ||
GlStateManager.translate(0, 0, 32f); | ||
FontRenderer font = slot.nea$getStack().getItem().getFontRenderer(slot.nea$getStack()); | ||
if (font == null) font = fontRenderer; | ||
itemRender.renderItemAndEffectIntoGUI(Minecraft.getMinecraft().player, slot.nea$getStack(), 0, 0); | ||
itemRender.renderItemOverlayIntoGUI(font, slot.nea$getStack(), 0, 0, null); | ||
if (value <= 1f) { | ||
GlStateManager.popMatrix(); | ||
} | ||
GlStateManager.translate(-x, -y, 0); | ||
} | ||
} | ||
} |
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