Advertisement
1m1m0
Feb 3rd, 2025
10
0
Never
This is comment for paste Blackhole v5 Alpha Modular Simplified
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local BlackHoleCore = {}
  2.  
  3. -- Hi, welcome to the main works of Blackhole v5 Alpha! I guess you know these stuff, so feel free to break it!
  4.  
  5. -- Logger for one-time messages
  6. local logger = {
  7.     bodyForce = false,
  8.     velocity = false,
  9.     sizeProp = false,
  10.     zeroGrav = false,
  11.     consuming = false,
  12.     gravEngine = false
  13. }
  14.  
  15. function BlackHoleCore.Setup(config)
  16.     local self = {}
  17.  
  18.     -- Store configuration values
  19.     self.hole = config.hole
  20.     self.gravitationalConstant = config.gravitationalConstant
  21.     self.updateInterval = config.updateInterval
  22.     self.damping = config.damping
  23.     self.rangeFactor = config.rangeFactor
  24.     self.transparencySteps = config.transparencySteps
  25.     self.dematerializeDuration = config.dematerializeDuration
  26.     self.sizeProportion = config.sizeProportion
  27.     self.rangeProportion = config.rangeProportion
  28.     self.partColor = config.partColor
  29.     self.partMaterialTransform = config.partMaterialTransform
  30.     self.absorption = config.absorption
  31.     self.growth = config.growth
  32.     self.killPlayers = config.killPlayers
  33.     self.collision = config.collision
  34.     self.fixedPosition = config.fixedPosition
  35.     self.toggleMicroGravity = config.toggleMicroGravity
  36.     self.infinityHandler = config.infinityHandler
  37.     self.paradoxHandler = config.paradoxHandler
  38.     self.mergeBlackholes = config.mergeBlackholes
  39.     self.gravityEngine = config.gravityEngine
  40.     self.glint = config.glint
  41.     self.glintProportion = config.glintProportion
  42.     self.rocheLimitFactor = config.rocheLimitFactor
  43.     self.gravitySync = config.gravitySync
  44.  
  45.     -- Internal variables
  46.     self.lastUpdateTime = 0
  47.     self.logger = logger
  48.     self.CollectionService = game:GetService("CollectionService")
  49.     self.previousSize = self.hole.Size.X
  50.     self.glintProportions = self.previousSize * self.glintProportion
  51.  
  52.     ---------------------------------------------------------------------
  53.     -- CORE FUNCTIONS
  54.     ---------------------------------------------------------------------
  55.     -- Destroy joints within the Roche limit
  56.     function self.DestroyJointsWithinRocheLimit(object)
  57.         local distance = (self.hole.Position - object.Position).Magnitude
  58.         local rocheLimit = (self.hole.Size.Magnitude / 2) * self.rocheLimitFactor
  59.         if distance <= rocheLimit then
  60.             for _, descendant in pairs(object:GetDescendants()) do
  61.                 if descendant:IsA("JointInstance") then descendant:Destroy() end
  62.             end
  63.         end
  64.     end
  65.  
  66.     -- Apply gravity to a given object
  67.     function self.ApplyGravity(object)
  68.         local currentTime = tick()
  69.         if currentTime - self.lastUpdateTime < self.updateInterval then return end
  70.         self.lastUpdateTime = currentTime
  71.  
  72.         local direction = self.hole.Position - object.Position
  73.         local distance = direction.Magnitude
  74.         local holeRadius = self.hole.Size.Magnitude / 2
  75.         local distanceSquared = (distance / ((self.rangeFactor / 100) + ((self.rangeFactor / 100) * (1 / 64))))^2
  76.         local magnitude = self.gravitationalConstant / distanceSquared
  77.  
  78.         -- Dampening for velocity-based gravity when gravitySync is enabled
  79.         local engineType = string.lower(self.gravityEngine)
  80.         if (engineType == "velocity" or engineType == "speed" or engineType == "2") and self.gravitySync then
  81.             magnitude = magnitude / (self.gravitationalConstant * 0.1)
  82.         end
  83.  
  84.         local force = direction.Unit * magnitude * object:GetMass()
  85.  
  86.         -- Infinity handler: neutralize force inside inner radius
  87.         if self.infinityHandler and distance < holeRadius then
  88.             force = Vector3.zero
  89.             direction = Vector3.zero
  90.         end
  91.  
  92.         -- Apply force/velocity based on gravity engine
  93.         if engineType == "bodyforce" or engineType == "force" or engineType == "1" then
  94.             local bodyForce = object:FindFirstChild("BlackHoleBodyForce") or Instance.new("BodyForce", object)
  95.             bodyForce.Name = "BlackHoleBodyForce"
  96.             bodyForce.Force = (bodyForce.Force + force) * self.damping
  97.             if not self.logger.bodyForce then
  98.                 print("{BHv5A} Using FORCE-based gravity (+Stability, -Accuracy) MODEL SUPPORTED")
  99.                 self.logger.bodyForce = true
  100.             end
  101.  
  102.         elseif engineType == "velocity" or engineType == "speed" or engineType == "2" then
  103.             local blackHoleRadius = self.hole.Size.X / 2
  104.             if distance < blackHoleRadius then return end
  105.             object.Velocity = object.Velocity + force * self.damping
  106.             if not self.logger.velocity then
  107.                 print("{BHv5A} Using VELOCITY-based gravity (-Stability, +Accuracy) DOES NOT SUPPORT MODELS!!!")
  108.                 self.logger.velocity = true
  109.             end
  110.  
  111.         else
  112.             print("{BHv5A} Invalid Gravity Engine request! Switching to default (Force-based Gravity)")
  113.             self.logger.gravEngine = true
  114.             self.gravityEngine = "1"
  115.         end
  116.     end
  117.  
  118.     -- Check and apply gravity to an object if appropriate
  119.     function self.CheckAndApplyGravity(obj)
  120.         if not obj:IsDescendantOf(game.Workspace) or not obj:IsA("BasePart") then return end
  121.         if obj == self.hole or obj.Parent:IsA("Player") or obj.Anchored then return end
  122.         self.DestroyJointsWithinRocheLimit(obj)
  123.         self.ApplyGravity(obj)
  124.     end
  125.  
  126.     -- Absorb smaller black holes
  127.     function self.AbsorbSmallerBlackHole(otherBlackHole)
  128.         local function AverageSize(part)
  129.             return (part.Size.X + part.Size.Y + part.Size.Z) / 3
  130.         end
  131.         local thisSize = AverageSize(self.hole)
  132.         local otherSize = AverageSize(otherBlackHole)
  133.         local sizeDifference = math.floor((thisSize - otherSize) * 1000 + 0.5) / 1000
  134.  
  135.         local function resetForces(blackHole)
  136.             local bf = blackHole:FindFirstChild("BlackHoleBodyForce")
  137.             if bf then bf.Force = Vector3.new(0, 0, 0) end
  138.         end
  139.         local function applyNewForce(blackHole)
  140.             local newBF = Instance.new("BodyForce", blackHole)
  141.             newBF.Force = Vector3.new(0, blackHole.Size.Magnitude * 2, 0)
  142.         end
  143.  
  144.         if sizeDifference > 0.001 then
  145.             self.CollectionService:RemoveTag(otherBlackHole, "Blackholev5")
  146.             task.wait(0.01)
  147.             resetForces(otherBlackHole)
  148.             self.hole.Size = otherBlackHole.Size * 0.5
  149.             self.rangeFactor = (self.hole.Size.Magnitude * 0.5) * (self.rangeProportion / self.sizeProportion)
  150.             otherBlackHole:Destroy()
  151.             resetForces(self.hole)
  152.             applyNewForce(self.hole)
  153.         elseif sizeDifference < -0.001 then
  154.             task.wait(0.1)
  155.             resetForces(otherBlackHole)
  156.             applyNewForce(otherBlackHole)
  157.             self.hole:Destroy()
  158.         else
  159.             local unifiedSize = self.hole.Size * 2
  160.             local newBlackHole = self.hole:Clone()
  161.             newBlackHole.Size = unifiedSize
  162.             newBlackHole.Position = self.hole.Position
  163.             newBlackHole.Parent = self.hole.Parent
  164.             self.CollectionService:AddTag(newBlackHole, "Blackholev5")
  165.             local newGlintSize = self.glint.Size.Keypoints[1].Value * 2
  166.             newBlackHole.VFX.Glint.Size = NumberSequence.new(newGlintSize)
  167.             self.hole:Destroy()
  168.             otherBlackHole:Destroy()
  169.             resetForces(newBlackHole)
  170.             applyNewForce(newBlackHole)
  171.             self.hole = newBlackHole
  172.         end
  173.     end
  174.  
  175.     -- Damage players when they touch the black hole
  176.     function self.onTouch(part)
  177.         local humanoid = part.Parent:FindFirstChild("Humanoid")
  178.         if humanoid then humanoid.Health = 0 end
  179.     end
  180.  
  181.     -- Update Glint's size based on the black hole's size
  182.     function self.updateGlintSize()
  183.         local currentSize = self.hole.Size.X
  184.         if currentSize ~= self.previousSize then
  185.             local scaleFactor = currentSize / self.previousSize
  186.             local newSize = self.glint.Size.Keypoints[1].Value * scaleFactor
  187.             self.glint.Size = NumberSequence.new(newSize)
  188.             self.previousSize = currentSize
  189.         end
  190.     end
  191.  
  192.     ---------------------------------------------------------------------
  193.     -- RUN FUNCTION: SET UP LOOP & EVENT CONNECTIONS (INCLUDING ABSORPTION)
  194.     ---------------------------------------------------------------------
  195.     function self.Run()
  196.         local RunService = game:GetService("RunService")
  197.  
  198.         -- Set up absorption events if enabled
  199.         if self.absorption then
  200.             self.hole.Touched:Connect(function(part)
  201.                 if self.CollectionService:HasTag(part, "Blackholev5") and self.mergeBlackholes then
  202.                     self.AbsorbSmallerBlackHole(part)
  203.                     return
  204.                 end
  205.                 if part.Anchored or (self.CollectionService:HasTag(part, "Blackholev5") and self.paradoxHandler) then
  206.                     return
  207.                 end
  208.  
  209.                 local function CalculateAverageSize(part)
  210.                     return (part.Size.X + part.Size.Y + part.Size.Z) / 3
  211.                 end
  212.  
  213.                 local objectAverageSize = CalculateAverageSize(part)
  214.                 local blackHoleSize = self.hole.Size.X
  215.                 local sizeIncrement = objectAverageSize / (blackHoleSize * self.sizeProportion)
  216.  
  217.                 part.BrickColor = self.partColor
  218.                 part.Material = self.partMaterialTransform
  219.                 part.CanCollide = self.collision
  220.                 part.Anchored = self.fixedPosition
  221.  
  222.                 for _, transparency in ipairs(self.transparencySteps) do
  223.                     part.Transparency = transparency
  224.                     wait(self.dematerializeDuration)
  225.                 end
  226.  
  227.                 part:Destroy()
  228.  
  229.                 if self.growth then
  230.                     self.hole.Size = self.hole.Size + Vector3.new(sizeIncrement, sizeIncrement, sizeIncrement)
  231.                     self.rangeFactor = self.rangeFactor + sizeIncrement * self.rangeProportion
  232.                 end
  233.             end)
  234.             print("{BHv5A} Absorption is ENABLED")
  235.         else
  236.             print("{BHv5A} Absorption is DISABLED")
  237.         end
  238.  
  239.         -- Main gravitational loop
  240.         RunService.Heartbeat:Connect(function()
  241.             for _, obj in pairs(workspace:GetDescendants()) do
  242.                 self.CheckAndApplyGravity(obj)
  243.             end
  244.             self.updateGlintSize()
  245.         end)
  246.  
  247.         -- Connect kill-player logic if enabled
  248.         if self.killPlayers then
  249.             self.hole.Touched:Connect(self.onTouch)
  250.         end
  251.  
  252.         -- Toggle micro gravity
  253.         workspace.Gravity = self.toggleMicroGravity and 0 or workspace.Gravity
  254.         print("{BHv5A} Gravity is " .. (self.toggleMicroGravity and "DISABLED" or "ENABLED"))
  255.     end
  256.  
  257.     return self
  258. end
  259.  
  260. return BlackHoleCore
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement