Skip to content

Commit 59752a3

Browse files
authored
Merge pull request #566 from rfresh2/containerpreview
ContainerPreview: EChest caching, nested locking, item frames
2 parents e13b451 + 59e2a2d commit 59752a3

File tree

10 files changed

+500
-162
lines changed

10 files changed

+500
-162
lines changed

src/main/java/com/lambda/mixin/gui/MixinGuiChest.java

-20
This file was deleted.

src/main/java/com/lambda/mixin/gui/MixinGuiScreen.java

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.lambda.mixin.gui;
22

3-
import com.lambda.client.module.modules.render.ContainerPreview;
43
import com.lambda.client.module.modules.render.MapPreview;
54
import com.lambda.client.module.modules.render.NoRender;
65
import com.lambda.client.util.Wrapper;
@@ -25,8 +24,6 @@ public void renderToolTip(ItemStack stack, int x, int y, CallbackInfo ci) {
2524
ci.cancel();
2625
MapPreview.drawMap(stack, mapData, x, y);
2726
}
28-
} else if (ContainerPreview.INSTANCE.isEnabled()) {
29-
ContainerPreview.INSTANCE.renderTooltips(stack, x, y, ci);
3027
}
3128
}
3229

src/main/java/com/lambda/mixin/network/MixinNetHandlerPlayClient.java

+9
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
import com.lambda.client.event.LambdaEventBus;
44
import com.lambda.client.event.events.ChunkDataEvent;
5+
import com.lambda.client.manager.managers.CachedContainerManager;
56
import net.minecraft.client.multiplayer.WorldClient;
67
import net.minecraft.client.network.NetHandlerPlayClient;
78
import net.minecraft.network.play.server.SPacketChunkData;
9+
import net.minecraft.network.play.server.SPacketWindowItems;
810
import org.spongepowered.asm.mixin.Mixin;
911
import org.spongepowered.asm.mixin.Shadow;
1012
import org.spongepowered.asm.mixin.injection.At;
@@ -20,4 +22,11 @@ public class MixinNetHandlerPlayClient {
2022
public void handleChunkData(SPacketChunkData packetIn, CallbackInfo ci) {
2123
LambdaEventBus.INSTANCE.post(new ChunkDataEvent(packetIn.isFullChunk(), this.world.getChunk(packetIn.getChunkX(), packetIn.getChunkZ())));
2224
}
25+
26+
@Inject(method = "handleWindowItems", at = @At(value = "RETURN"))
27+
public void handleItems(SPacketWindowItems packetIn, CallbackInfo ci) {
28+
if (packetIn.getWindowId() != 0) {
29+
CachedContainerManager.updateContainerInventory(packetIn.getWindowId());
30+
}
31+
}
2332
}

src/main/java/com/lambda/mixin/player/MixinEntityPlayerSP.java

+9
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.lambda.client.event.events.PlayerMoveEvent;
77
import com.lambda.client.event.events.PushOutOfBlocksEvent;
88
import com.lambda.client.gui.mc.LambdaGuiBeacon;
9+
import com.lambda.client.manager.managers.CachedContainerManager;
910
import com.lambda.client.manager.managers.MessageManager;
1011
import com.lambda.client.manager.managers.PlayerPacketManager;
1112
import com.lambda.client.module.modules.chat.PortalChat;
@@ -18,6 +19,7 @@
1819
import net.minecraft.client.Minecraft;
1920
import net.minecraft.client.entity.EntityPlayerSP;
2021
import net.minecraft.client.gui.GuiScreen;
22+
import net.minecraft.client.gui.inventory.GuiChest;
2123
import net.minecraft.client.network.NetHandlerPlayClient;
2224
import net.minecraft.entity.MoverType;
2325
import net.minecraft.entity.player.EntityPlayer;
@@ -68,6 +70,13 @@ public MixinEntityPlayerSP(World worldIn, GameProfile gameProfileIn) {
6870
@Shadow
6971
protected abstract void updateAutoJump(float p_189810_1_, float p_189810_2_);
7072

73+
@Inject(method = "closeScreen", at = @At("HEAD"))
74+
public void onCloseScreen(CallbackInfo ci) {
75+
if (mc.currentScreen instanceof GuiChest) {
76+
CachedContainerManager.onGuiChestClosed();
77+
}
78+
}
79+
7180
@Redirect(method = "onLivingUpdate", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/entity/EntityPlayerSP;closeScreen()V"))
7281
public void closeScreen(EntityPlayerSP player) {
7382
if (PortalChat.INSTANCE.isDisabled()) player.closeScreen();

src/main/kotlin/com/lambda/client/event/ForgeEventProcessor.kt

+10
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,16 @@ internal object ForgeEventProcessor {
102102
}
103103
}
104104

105+
@SubscribeEvent
106+
fun onDrawScreenEvent(event: GuiScreenEvent.DrawScreenEvent) {
107+
LambdaEventBus.post(event)
108+
}
109+
110+
@SubscribeEvent
111+
fun onRenderTooltipEvent(event: RenderTooltipEvent.Pre) {
112+
LambdaEventBus.post(event)
113+
}
114+
105115
/**
106116
* Includes events of subclasses like ChunkEvent and GetCollisionBoxesEvent
107117
*/

src/main/kotlin/com/lambda/client/gui/hudgui/elements/player/InventoryViewer.kt

+21-58
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,20 @@
11
package com.lambda.client.gui.hudgui.elements.player
22

33
import com.lambda.client.event.SafeClientEvent
4-
import com.lambda.client.event.events.ConnectionEvent
54
import com.lambda.client.event.events.PacketEvent
65
import com.lambda.client.gui.hudgui.HudElement
7-
import com.lambda.client.mixin.extension.windowID
8-
import com.lambda.client.module.modules.client.ClickGUI
9-
import com.lambda.client.module.modules.client.GuiColors
6+
import com.lambda.client.manager.managers.CachedContainerManager
7+
import com.lambda.client.util.color.ColorHolder
108
import com.lambda.client.util.graphics.GlStateUtils
119
import com.lambda.client.util.graphics.RenderUtils2D
1210
import com.lambda.client.util.graphics.VertexHelper
1311
import com.lambda.client.util.items.storageSlots
1412
import com.lambda.client.util.math.Vec2d
1513
import com.lambda.client.util.threads.runSafe
1614
import com.lambda.client.util.threads.safeListener
17-
import net.minecraft.client.gui.inventory.GuiContainer
1815
import net.minecraft.client.renderer.GlStateManager
1916
import net.minecraft.client.renderer.Tessellator
2017
import net.minecraft.client.renderer.vertex.DefaultVertexFormats
21-
import net.minecraft.init.Blocks
22-
import net.minecraft.inventory.ContainerChest
23-
import net.minecraft.inventory.InventoryBasic
24-
import net.minecraft.item.ItemStack
25-
import net.minecraft.network.play.client.CPacketCloseWindow
2618
import net.minecraft.network.play.server.SPacketOpenWindow
2719
import net.minecraft.util.ResourceLocation
2820
import net.minecraft.util.text.TextComponentTranslation
@@ -38,33 +30,32 @@ internal object InventoryViewer : HudElement(
3830
private val showIcon by setting("Show Icon", false, { !mcTexture })
3931
private val iconScale by setting("Icon Scale", 0.5f, 0.1f..1.0f, 0.1f, { !mcTexture && showIcon })
4032
private val background by setting("Background", true, { !mcTexture })
41-
private val alpha by setting("Alpha", 150, 0..255, 1, { !mcTexture })
33+
private val backgroundColor by setting("Background Color", ColorHolder(0, 0, 0, 150), visibility = { !mcTexture && background })
34+
private val outline by setting("Outline", true, visibility = { !mcTexture })
35+
private val outlineColor by setting("Outline Color", ColorHolder(255, 255, 255, 150), visibility = { !mcTexture && outline })
36+
private val outlineThickness by setting("Outline Thickness", 1.0f, 0.5f..5.0f, 0.5f, { !mcTexture && outline })
4237
private val containerTexture = ResourceLocation("textures/gui/container/inventory.png")
4338
private val lambdaIcon = ResourceLocation("lambda/lambda_icon.png")
44-
private var enderChestContents: MutableList<ItemStack> = MutableList(27) { ItemStack(Blocks.AIR) }
4539

4640
override val hudWidth: Float = 162.0f
4741
override val hudHeight: Float = 54.0f
4842

49-
private var openedEnderChest: Int = -1
50-
5143
override fun renderHud(vertexHelper: VertexHelper) {
5244
super.renderHud(vertexHelper)
5345
runSafe {
5446
drawFrame(vertexHelper)
5547
drawFrameTexture()
56-
checkEnderChest()
5748
drawItems()
5849
}
5950
}
6051

6152
private fun drawFrame(vertexHelper: VertexHelper) {
6253
if (!mcTexture) {
6354
if (background) {
64-
RenderUtils2D.drawRectFilled(vertexHelper, posEnd = Vec2d(162.0, 54.0), color = GuiColors.backGround.apply { a = alpha })
55+
RenderUtils2D.drawRectFilled(vertexHelper, posEnd = Vec2d(hudWidth.toDouble(), hudHeight.toDouble()), color = backgroundColor)
6556
}
66-
if (ClickGUI.windowOutline) {
67-
RenderUtils2D.drawRectOutline(vertexHelper, posEnd = Vec2d(162.0, 54.0), lineWidth = ClickGUI.outlineWidth, color = GuiColors.outline.apply { a = alpha })
57+
if (outline) {
58+
RenderUtils2D.drawRectOutline(vertexHelper, posEnd = Vec2d(hudWidth.toDouble(), hudHeight.toDouble()), lineWidth = outlineThickness, color = outlineColor)
6859
}
6960
}
7061
}
@@ -78,15 +69,15 @@ internal object InventoryViewer : HudElement(
7869
mc.renderEngine.bindTexture(containerTexture)
7970
buffer.begin(GL_TRIANGLE_STRIP, DefaultVertexFormats.POSITION_TEX)
8071
buffer.pos(0.0, 0.0, 0.0).tex(0.02734375, 0.32421875).endVertex() // (7 / 256), (83 / 256)
81-
buffer.pos(0.0, 54.0, 0.0).tex(0.02734375, 0.53125).endVertex() // (7 / 256), (136 / 256)
82-
buffer.pos(162.0, 0.0, 0.0).tex(0.65625, 0.32421875).endVertex() // (168 / 256), (83 / 256)
83-
buffer.pos(162.0, 54.0, 0.0).tex(0.65625, 0.53125).endVertex() // (168 / 256), (136 / 256)
72+
buffer.pos(0.0, hudHeight.toDouble(), 0.0).tex(0.02734375, 0.53125).endVertex() // (7 / 256), (136 / 256)
73+
buffer.pos(hudWidth.toDouble(), 0.0, 0.0).tex(0.65625, 0.32421875).endVertex() // (168 / 256), (83 / 256)
74+
buffer.pos(hudWidth.toDouble(), hudHeight.toDouble(), 0.0).tex(0.65625, 0.53125).endVertex() // (168 / 256), (136 / 256)
8475
tessellator.draw()
8576
} else if (showIcon) {
8677
mc.renderEngine.bindTexture(lambdaIcon)
8778
GlStateManager.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
8879

89-
val center = Vec2d(81.0, 27.0)
80+
val center = Vec2d(hudWidth / 2.0, hudHeight / 2.0)
9081
val halfWidth = iconScale * 50.0
9182
val halfHeight = iconScale * 50.0
9283

@@ -103,61 +94,33 @@ internal object InventoryViewer : HudElement(
10394

10495

10596
init {
106-
safeListener<ConnectionEvent.Disconnect> {
107-
openedEnderChest = -1
108-
}
109-
11097
safeListener<PacketEvent.Receive> {
11198
if (it.packet !is SPacketOpenWindow) return@safeListener
11299
if (it.packet.guiId != "minecraft:container") return@safeListener
113100
val title = it.packet.windowTitle
114101
if (title !is TextComponentTranslation) return@safeListener
115102
if (title.key != "container.enderchest") return@safeListener
116103

117-
openedEnderChest = it.packet.windowId
118-
}
119-
120-
safeListener<PacketEvent.PostSend> {
121-
if (it.packet !is CPacketCloseWindow) return@safeListener
122-
if (it.packet.windowID != openedEnderChest) return@safeListener
123-
124-
checkEnderChest()
125-
openedEnderChest = -1
126-
}
127-
}
128-
129-
private fun checkEnderChest() {
130-
val guiScreen = mc.currentScreen
131-
132-
if (guiScreen !is GuiContainer) return
133-
134-
val container = guiScreen.inventorySlots
135-
136-
if (container is ContainerChest && container.lowerChestInventory is InventoryBasic) {
137-
if (container.windowId == openedEnderChest) {
138-
for (i in 0..26) enderChestContents[i] = container.inventory[i]
139-
}
140104
}
141105
}
142106

143107
private fun SafeClientEvent.drawItems() {
144108
if (enderChest == SlotType.ENDER_CHEST) {
145-
for ((index, stack) in enderChestContents.withIndex()) {
146-
if (stack.isEmpty) continue
147-
148-
val slotX = index % 9 * 18 + 1
149-
val slotY = index / 9 * 18 + 1
150-
RenderUtils2D.drawItem(stack, slotX, slotY)
109+
CachedContainerManager.getEnderChestInventory().forEachIndexed { index, stack ->
110+
if (stack.isEmpty) return@forEachIndexed
111+
val slotX = index % 9 * (hudWidth / 9.0) + 1
112+
val slotY = index / 9 * (hudWidth / 9.0) + 1
113+
RenderUtils2D.drawItem(stack, slotX.toInt(), slotY.toInt())
151114
}
152115
} else {
153116
for ((index, slot) in player.storageSlots.withIndex()) {
154117
val itemStack = slot.stack
155118
if (itemStack.isEmpty) continue
156119

157-
val slotX = index % 9 * 18 + 1
158-
val slotY = index / 9 * 18 + 1
120+
val slotX = index % 9 * (hudWidth / 9.0) + 1
121+
val slotY = index / 9 * (hudWidth / 9.0) + 1
159122

160-
RenderUtils2D.drawItem(itemStack, slotX, slotY)
123+
RenderUtils2D.drawItem(itemStack, slotX.toInt(), slotY.toInt())
161124
}
162125
}
163126
}

0 commit comments

Comments
 (0)