diff --git a/eid_api.lua b/eid_api.lua index 749893f6..9c0ea8dd 100644 --- a/eid_api.lua +++ b/eid_api.lua @@ -508,7 +508,9 @@ function EID:hasDescription(entity) isAllowed = isAllowed or (entity.Variant == PickupVariant.PICKUP_TRINKET and EID.Config["DisplayTrinketInfo"]) isAllowed = isAllowed or (entity.Variant == PickupVariant.PICKUP_TAROTCARD and EID.Config["DisplayCardInfo"]) isAllowed = isAllowed or (entity.Variant == PickupVariant.PICKUP_PILL and EID.Config["DisplayPillInfo"]) - return isAllowed and (entity.SubType > 0 or EID:getEntityData(entity, "EID_FlipItemID")) + return isAllowed and (entity.SubType > 0 or + -- For Flip descriptions, allow 5.100.0 pedestals to have descriptions under VERY specific criteria! + (REPENTANCE and EID:getEntityData(entity, "EID_FlipItemID") and EID:PlayersHaveCollectible(CollectibleType.COLLECTIBLE_FLIP))) end if entity.Type == 6 and entity.Variant == 16 and EID.Config["DisplayCraneInfo"] and REPENTANCE then isAllowed = not entity:GetSprite():IsPlaying("Broken") and not entity:GetSprite():IsPlaying("Prize") and EID.CraneItemType[tostring(entity.InitSeed)] diff --git a/eid_tmtrainer.lua b/eid_tmtrainer.lua index 09dc58ab..eb81f2e1 100644 --- a/eid_tmtrainer.lua +++ b/eid_tmtrainer.lua @@ -28,7 +28,7 @@ local function entityToName(e, plural) local name = localizedNames[e] or EID.XMLEntityNames[e] or localizedNames[eWithZero] or EID.XMLEntityNames[eWithZero] or e --print out entities with no name yet - if name == e then print("No name found for " .. e .. " (could be modded)") + if name == e then Isaac.DebugString("No name found for " .. e .. " (could be modded)") elseif plural then name = name .. localizedNames["pluralize"] end return name diff --git a/main.lua b/main.lua index ee3a4358..c7f4ec81 100644 --- a/main.lua +++ b/main.lua @@ -244,13 +244,26 @@ local initialItemNext = false local flipItemNext = false if REPENTANCE then EID.flipItemPositions = {} - local lastGetItemResult = {nil, nil, nil} -- itemID, Frame, gridIndex + + local lastGetItemResult = {nil, nil, nil, nil} -- itemID, Frame, gridIndex, InitSeed function EID:postGetCollectible(selectedCollectible, itemPoolType, decrease, seed) + -- Handle Crane Game + if itemPoolType == ItemPoolType.POOL_CRANE_GAME then + for _, crane in ipairs(Isaac.FindByType(6, 16, -1, true, false)) do + if not crane:GetSprite():IsPlaying("Broken") then + if not EID.CraneItemType[tostring(crane.InitSeed)] then + EID.CraneItemType[tostring(crane.InitSeed)] = selectedCollectible + end + end + end + end + -- Handle Flip item -- PRE_ROOM_ENTITY_SPAWN sets us up to watch for the first POST_GET_COLLECTIBLE for this pedestal -- (Tainted Isaac and Glitched Crown cause additional calls that have to be ignored) -- POST_PICKUP_INIT occurs right before the Flip item is decided, so it sets us up to watch for the Flip item + -- (it also watches for item rerolls to fill the new entity's GetData) -- POST_NEW_ROOM then handles putting the result in the entity's GetData local curFrame = Isaac.GetFrameCount() local curRoomIndex = game:GetLevel():GetCurrentRoomIndex() @@ -260,33 +273,7 @@ if REPENTANCE then if EID.flipItemPositions[curRoomIndex] == nil then EID.flipItemPositions[curRoomIndex] = {} end - EID.flipItemPositions[curRoomIndex][lastGetItemResult[3]] = selectedCollectible - end - end - - -- Check if Flip item pedestals have moved (restock/Greed shops) - -- BUG if you leave the room before the new shop item spawns?? - if EID.flipItemPositions[curRoomIndex] then - local pedestals = Isaac.FindByType(5, 100, -1, true, false) - for _, pedestal in ipairs(pedestals) do - local gridPos = game:GetRoom():GetGridIndex(pedestal.Position) - local oldGridPos = pedestal:GetData()["EID_FlipItemPedestalGrid"] - if EID.flipItemPositions[curRoomIndex][oldGridPos] and gridPos ~= oldGridPos then - EID.flipItemPositions[curRoomIndex][oldGridPos] = nil - EID.flipItemPositions[curRoomIndex][gridPos] = gridPos - pedestal:GetData()["EID_FlipItemPedestalGrid"] = gridPos - end - end - end - - -- Handle Crane Game - if itemPoolType == ItemPoolType.POOL_CRANE_GAME then - for _, crane in ipairs(Isaac.FindByType(6, 16, -1, true, false)) do - if not crane:GetSprite():IsPlaying("Broken") then - if not EID.CraneItemType[tostring(crane.InitSeed)] then - EID.CraneItemType[tostring(crane.InitSeed)] = selectedCollectible - end - end + EID.flipItemPositions[curRoomIndex][lastGetItemResult[4]] = {selectedCollectible, lastGetItemResult[3]} end end @@ -299,7 +286,7 @@ if REPENTANCE then function EID:preRoomEntitySpawn(entityType, variant, subtype, gridIndex, seed) flipItemNext = false if entityType == 5 and (variant == 100 or variant == 150) then - lastGetItemResult = {nil, Isaac.GetFrameCount(), gridIndex} + lastGetItemResult = {nil, Isaac.GetFrameCount(), gridIndex, nil} initialItemNext = true end end @@ -307,32 +294,51 @@ if REPENTANCE then function EID:postPickupInit(entity) flipItemNext = true + lastGetItemResult[4] = entity.InitSeed - -- Keep the Flip item the same for pedestal rerolls local curRoomIndex = game:GetLevel():GetCurrentRoomIndex() local gridPos = game:GetRoom():GetGridIndex(entity.Position) - local flipEntry = EID.flipItemPositions[curRoomIndex] and EID.flipItemPositions[curRoomIndex][gridPos] - if flipEntry then entity:GetData()["EID_FlipItemID"] = flipEntry end + + -- Update a Flip item's init seed after D6 rerolls or using Flip (aka Grid Index didn't change, Init Seed did) + if EID.flipItemPositions[curRoomIndex] and not EID.flipItemPositions[curRoomIndex][entity.InitSeed] then + -- Fix pedestal grid indexes (fixes bugs with restock shops, hopefully it isn't laggy) + EID:CheckFlipGridIndexes() + for k,v in pairs(EID.flipItemPositions[curRoomIndex]) do + if v[2] == gridPos then + EID.flipItemPositions[curRoomIndex][entity.InitSeed] = v + EID.flipItemPositions[curRoomIndex][k] = nil + break + end + end + end + -- Give this new entity its Flip Item data if possible + local flipEntry = EID.flipItemPositions[curRoomIndex] and EID.flipItemPositions[curRoomIndex][entity.InitSeed] + if flipEntry then + entity:GetData()["EID_FlipItemID"] = flipEntry[1] + end end EID:AddCallback(ModCallbacks.MC_POST_PICKUP_INIT, EID.postPickupInit, PickupVariant.PICKUP_COLLECTIBLE) - function EID:preUseFlip(_) + -- Before using Flip, swap all flippable pedestal's current item with the flip one (also, fix grid index if needed) + function EID:CheckFlipGridIndexes(collectibleType) local curRoomIndex = game:GetLevel():GetCurrentRoomIndex() if EID.flipItemPositions[curRoomIndex] then local pedestals = Isaac.FindByType(5, 100, -1, true, false) for _, pedestal in ipairs(pedestals) do - local gridPos = game:GetRoom():GetGridIndex(pedestal.Position) - if EID.flipItemPositions[curRoomIndex][gridPos] then - -- don't swap a flip shadow with an empty pedestal! - if pedestal.SubType == 0 then EID.flipItemPositions[curRoomIndex][gridPos] = nil - else EID.flipItemPositions[curRoomIndex][gridPos] = pedestal.SubType end - --postPickupInit will take care of assigning it to the entity's data + local flipEntry = EID.flipItemPositions[curRoomIndex][pedestal.InitSeed] + if flipEntry then + local gridPos = game:GetRoom():GetGridIndex(pedestal.Position) + flipEntry[2] = gridPos + if collectibleType == CollectibleType.COLLECTIBLE_FLIP then + -- don't swap a flip shadow with an empty pedestal! + if pedestal.SubType == 0 then flipEntry = nil + else flipEntry[1] = pedestal.SubType end + end end - end end end - EID:AddCallback(ModCallbacks.MC_PRE_USE_ITEM, EID.preUseFlip, CollectibleType.COLLECTIBLE_FLIP) + EID:AddCallback(ModCallbacks.MC_PRE_USE_ITEM, EID.CheckFlipGridIndexes, CollectibleType.COLLECTIBLE_FLIP) end --------------------------------------------------------------------------- @@ -514,12 +520,9 @@ if REPENTANCE then if EID:PlayersHaveCollectible(CollectibleType.COLLECTIBLE_FLIP) and EID.flipItemPositions[curRoomIndex] then local pedestals = Isaac.FindByType(5, 100, -1, true, false) for _, pedestal in ipairs(pedestals) do - local gridPos = game:GetRoom():GetGridIndex(pedestal.Position) - local flipEntry = EID.flipItemPositions[curRoomIndex][gridPos] + local flipEntry = EID.flipItemPositions[curRoomIndex][pedestal.InitSeed] if flipEntry then - pedestal:GetData()["EID_FlipItemID"] = flipEntry - pedestal:GetData()["EID_FlipItemPedestalIndex"] = pedestal.Index - pedestal:GetData()["EID_FlipItemPedestalGrid"] = gridPos + pedestal:GetData()["EID_FlipItemID"] = flipEntry[1] end end end