diff options
author | BlueWeabo <ilia.iliev2005@gmail.com> | 2024-01-06 00:41:00 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-05 23:41:00 +0100 |
commit | 02bedd5c0a96a654c6692edd1b7f2765fd9c46b4 (patch) | |
tree | 57dd675f658dda3caba629f15d4708247e702f88 /src/main/java/gregtech/api/util | |
parent | fc63cee4c0284635c601889ce49a892cf73082ff (diff) | |
download | GT5-Unofficial-02bedd5c0a96a654c6692edd1b7f2765fd9c46b4.tar.gz GT5-Unofficial-02bedd5c0a96a654c6692edd1b7f2765fd9c46b4.tar.bz2 GT5-Unofficial-02bedd5c0a96a654c6692edd1b7f2765fd9c46b4.zip |
Merge MuTEMaster into Master (#2431)
* Fix MuTE structure check and power intake (#1975)
* Fixed casing lists being cleared for every checked structure piece
* Fixed power being taken from any side BUT the right one
* ACP Structure - Rebased (#1978)
* Added 2nd structure tier to ACR and make complex parallels depend on it
* Added tier 3 to 8 structure pieces to ACR
* Added disclaimer
* Renamed ACR to ACP because MV CR already is named ACR
* Add autopush functionality to MuTE (#1976) - fix conflict
* Working auto push
* Revert wildcard import
* Addresssed reviews
* Fix reference issue
* Minor MuTE fixes - Rebased (#1983)
* Fixed ACP recipe map
* Fixed controller side being used instead of part side when accessing tanks
* Fix Structure not forming (#1984)
* fix cables not connecting
* fix structure and don't store controller
* Add missing tooltips (#1981)
* Add missing tooltips
* Address blue's change
* Distillation MuTE (#1989)
* Started work on DT MuTE
* Renamed methods so they also make sense when used horizontally
* MuTE Upgrade Casings - Rebased (#1988) - fix conflict
* Added cleanroom upgrade casing
* Added inventory and tank upgrades
* Added tooltips to mute casings
* Added power upgrades
* Set player UUID when placing MuTE
* MuTE fixes (#1991)
* Fixed pipes not connectable to MuTE casings
* Fixed not all things being renamed to ACP
* Fix running in obf
* fix for real yo
* Add a Generic Processing Logic and extract methods - Rebased (#1992)
* add a generic processing logic
* calculate tier in another method
* calculate power logic in another method
* Add Layered Coke Foundry (#1995)
* Add the Foundry class and call it
* Foundry name correction
* Buildable stackable structure
* Fixed min stacks and added motor casings
* checkMachine override for custom checking
* Working checkMachine for all stacks, and recipes
* Fix getOutputFluids
* Change recipe processing to GenericProcessingLogic
* Change inventoryName to protected for override
* Override checkRecipe for multis that consume EU
* Rename class and add inner walls to multi
* Structure update and other fixes
* Fix processing logic being static
* MuTE inventory upgrade logic (#2082)
* Catch potential NPE
* Don't load name when it doesn't exist
* Potentially cause weird non-replicatable issue where registry ends up with different key
* Use proper block removal method
* Validate index before using it
* Don't open controller GUI from inventory upgrade
* semi-working concept
* sync the ID of the inventory upgrade to correctly remove it later
* remove unneeded boolean
---------
Co-authored-by: BlueWeabo <76872108+BlueWeabo@users.noreply.github.com>
* fixed layeredCokeBattery checkMachine to prevent 'already in building state' (#2099)
* MuTE casing structure element (#2105) - fix conflict
* Added class containing MuTE relevant structure elements
* Migrate MuTE to new structure element
* Formatting fix
* Use int array instead of int hashmap, since its expected these arrays will never get long enough to be faster as hashmap
* Delete old code
* Cache MuTEs for non-instance specific actions (#2109)
* Introduce map of cached TEs, which are used to perform actions that don't require a specific instance of the TE. This prevents constant creation of new TEs
* Remove static modifier from map of cached TEs
* First Modular Upgrade Casings Implementation (#2142)
* Base support for Heater MUCs
- Define Heater upgrade casings;
- Create the 5 tiers of Heaters;
- Add method to increase and decrease count.
* Refactor the cache of MUCs in structure
- Change the way that each MUC is counted: since there will be several types, the integer that counted heaters is now a hashmap that divides all MUCs based on their type and tier, to be counted separately from each other.
* Add Insulator MUC
- Add second MUC type (insulator) to test alongside heaters on the Layered Coke Battery.
* Fix MUC count reset
* Refactor MUC implementation into subclass
- Move the new methods and hashmap away from the base classes, and onto a s specific one that won't be used by unrelated multiblocks.
* Remove empty lines
* Refactor MUC implementations into subclasses
* Requested fixes in StackableModularController
* Change hashmap keys to an enum
* Hashmap getter for load order purposes
- Added a getter that generates the default value for the hashmap if it is null, due to problems with load order;
* Apply spotless
* NotNull annotations
* More Additions to MUCs and the LCB (#2215)
* Fix old LCB multi name in some locations
* Refactor mucMap and override checkRecipe
- Refactor mucMap to an array of primitive integers instead of the wrapper type, for ease of use with other methods such as stream;
- Override checkRecipe for custom recipe behavior on MUC multis, to be implemented in a future commit;
* First implementation of bonuses and MUC requirements
- Change EU/t and recipe duration of this multi based on the count of different MUCs in the multi;
- Fail the structure check based on the count of each of the allowed MUCs.
* Parallel count implementation
- Calculate parallels based on the count of base MUCs, the cheapest option amongst the possibilities, in this case heaters;
- Added more abstract methods to require specific values from the multi classes.
* Fix parallel count and processing
- Fixed the handling of parallels by pointing to the corrent maxParallel variable in ProcessingLogic.
* Test of parallels with additional amp input
* Structure fix for the intended LCB
- Changed MUC placements to match what I intended at the beginning, to better test the multi.
* One more comment
* Remove checkRecipe override
* Refactor Item and Fluid to be in separate logic classes (#2178) - fix
conflict
* basics of inventory logic
* mostly working item logic
* working nbt saving/loading
* fluid handler
* FluidSlotHandler WIP
* fluid handler mostly working
* remove fluid handler from gt5u
* prepare for conversion
* use correct imports
* spotless
* more controller logic
* spotless
* final refactor. migration next
* spotless
* add more methods to logic classes
* convert almost everything to use new Logic
* spotless
* make mute casing mode an int
* allow pump cover to work with FluidInventoryLogic
* pumps work
* spotless
* make item inventory logic work with every item input thing
* rework Fluid Inventory Logic to work with all fluid inputs
* spotless
* address annotation reviews
* finish off todos
* missed to dos
* cleanup
Coke oven will get a new GUI when i get to it
* address review
* prevent npes from ControllerXXXLogic
* null checks
* remove accidentally added methods
* fix missed return
* fixes after rebase - fix conflict
* Laser Engraver Multi. (#2223) - fix conflict
* saving.............
* clean up
* savin
* Small fixes + Adding back stuff, Crashes you and spams logs.
* fix stack overflow
* Fixes
* Fixes
---------
Co-authored-by: BlueWeabo <76872108+BlueWeabo@users.noreply.github.com>
* Add TickableTask (#2216)
* Add autopush functionality to MuTE (#1976)
* Working auto push
* Revert wildcard import
* Addresssed reviews
* Fix reference issue
* MuTE Upgrade Casings (#1988)
* Added cleanroom upgrade casing
* Added inventory and tank upgrades
* Added tooltips to mute casings
* Added power upgrades
* Set player UUID when placing MuTE
* Add a Generic Processing Logic and extract methods (#1992)
* add a generic processing logic
* calculate tier in another method
* calculate power logic in another method
* MuTE inventory upgrade logic (#2082)
* Catch potential NPE
* Don't load name when it doesn't exist
* Potentially cause weird non-replicatable issue where registry ends up with different key
* Use proper block removal method
* Validate index before using it
* Don't open controller GUI from inventory upgrade
* semi-working concept
* sync the ID of the inventory upgrade to correctly remove it later
* remove unneeded boolean
---------
Co-authored-by: BlueWeabo <76872108+BlueWeabo@users.noreply.github.com>
* MuTE casing structure element (#2105)
* Added class containing MuTE relevant structure elements
* Migrate MuTE to new structure element
* Formatting fix
* Use int array instead of int hashmap, since its expected these arrays will never get long enough to be faster as hashmap
* Delete old code
* Refactor Item and Fluid to be in separate logic classes (#2178)
* basics of inventory logic
* mostly working item logic
* working nbt saving/loading
* fluid handler
* FluidSlotHandler WIP
* fluid handler mostly working
* remove fluid handler from gt5u
* prepare for conversion
* use correct imports
* spotless
* more controller logic
* spotless
* final refactor. migration next
* spotless
* add more methods to logic classes
* convert almost everything to use new Logic
* spotless
* make mute casing mode an int
* allow pump cover to work with FluidInventoryLogic
* pumps work
* spotless
* make item inventory logic work with every item input thing
* rework Fluid Inventory Logic to work with all fluid inputs
* spotless
* address annotation reviews
* finish off todos
* missed to dos
* cleanup
Coke oven will get a new GUI when i get to it
* address review
* prevent npes from ControllerXXXLogic
* null checks
* Base work
* PollutionTask
* move package
* Fix generics
* Internal -> OverrideOnly
* rebase fix
* Ducttape addPollution
---------
Co-authored-by: Maxim <maxim235@gmx.de>
Co-authored-by: BlueWeabo <ilia.iliev2005@gmail.com>
Co-authored-by: BlueWeabo <76872108+BlueWeabo@users.noreply.github.com>
* Rework a bit of ProcessingLogic to fit MuTEs (#2283) - fix conflicts
* Add a way to enable or disable the crafting buffer on GPL multiblocks (#2218)
* add a way to enable or disable the crafting buffer on GPL multiblocks
* don't register the hatch either
* fix Refractory Capsule (#2219)
* Fix PAs overclocking ulv recipes too much (#2220)
* fix PAs overclocking ulv recipes too much
* make sure we save the returned value
* Fix Digital Tank capacity for Fluid Storage Monitor (#2217)
* Fix Digital Tank capacity for Fluid Storage Monitor
* Annotations
* Blacklist AE2FC drop and packet, and Chisel stones from Recycler (#2222)
* Fix recycler blacklist being sensitive to NBT
* Blacklist AE2FC drop and packet, and Chisel stones
* fix class loader issue
* Add detailed logging for ME hatches (#2224)
* Fix overclock calculator calculating eu/t use for ulv recipe wrong on certain parallel (#2225)
* fix overclock calculator calculating eu/t use for ulv recipe wrong on certain parallel
* make formula into its own method
* Fix drilling rigs, plants and concrete backfiller to fail with multiple energy hatches (#2227)
* max-1-energy-hatch-in-drilling-rigs.-plants-and-concrete-backfiller
* spotlessApply (#2228)
Co-authored-by: GitHub GTNH Actions <>
* revert
---------
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
* clear stale crafting input bus list (#2233)
* add ability to remove item data and use it for clay (#2229)
* Update buildscript (#2232)
* Fix server crash with RecipeFilter (#2231)
* Fix server crash with RecipeFilter
* Make client send filtered machines to server
* Use mUniqueIdentifier
* Fix a NPE w/ injecting into super/quantum chests (#2234)
When simulating an injection, if the stackSize > chest's capacity, it
causes a NPE when the internal chest is empty.
Also fixes a potential bug when void overflow is set; the chest should
return null in such a scenario regardless of simulation/modulation.
* Fix lag caused by getRecipeMap for PA (#2236)
* Experimental fix to prevent infinite loop in Grid destruction (#2235)
Co-authored-by: Firenoo <49818773+firenoo@users.noreply.github.com>
* Fix ME Output Bus and Crafting Input Bus overflow when save/load (#2238)
* Remove fire display from singleblock generator (#2240)
* Fix some output slots allowing insertion (#2230)
* fix overlay zfighting by disable depth test (#2226)
* Crafting input - Optimize isEmpty check to reduce lag (#2239)
* Optimize isEmpty check
* rearrage
* remove broken hsla recipe (#2241)
* Correct PCB Factory Energy Hatch description (#2237)
* Correct PCB Factory Energy Hatch description
Changes the PCB factory description (the one seen when holding shift) which currently says "Energy Hatches: 1+"
I believe this is incorrect and that the correct description is 1-2 energy hatches or 1 TT energy hatch.
I believe the PCB factory uses this, which checks for 1-2 or 1 TT:
public boolean checkExoticAndNormalEnergyHatches() {
if (mExoticEnergyHatches.isEmpty() && mEnergyHatches.isEmpty()) {
return false;
}
if (!mExoticEnergyHatches.isEmpty()) {
if (!mEnergyHatches.isEmpty()) {
return false;
}
if (mExoticEnergyHatches.size() != 1) {
return false;
}
}
return mEnergyHatches.size() <= 2;
}
* gradlew spotlessApply
* Correct file name on resource pack guide (#2242)
* Fix GT_RecipeConstants.Fuel (#2243)
* Update text (#2246)
* Fix startup tier for fusion NEI (#2249)
* Update the conditionals buttons and tooltips on covers to reflect their actual effects (#2244)
* Update redstone buttons and tooltips to better reflect actual use
* Spotless Apply
* Update GT_Cover_FluidRegulator.java
* Update GT_Cover_FluidRegulator.java
* Typo fix, Icon Improved and interactive blocking ui
- Fixed a typo in the world machine
- Fixed double button situation for conveyor belts.
- There was never any issue, the testing methodology gave me invalid results.
- Conveyor behaviour is in line with all the other covers affected by this PR/Branch.
- Updated icon for the machine state to be a miniature machine controller cover.
- Made the block/allow input section more interactive in order to better reflect the actual effect of these buttons.
- In import mode, it actually blocks the machine from outputting from that side.
* typos
I can't write to save myself sometimes
* Better text alignment
- Better text alignment
* fix typos
I swear I can't write to save myself.
---------
Co-authored-by: Martin Robertz <dream-master@gmx.net>
* Fix Orichalcum and Shadowiron smelting (#2251)
* fix orichalcum and shadowiron smelting
* add Alduorite and Chrysotile
* Fix tier display for Fusion NEI header (#2250)
* fix ulv recipes being broken again when under 1 tick calculation is taken (#2254)
* change way to fix zfighting (#2253)
* Crafting input hatches QoLs (#2200)
* Fixes + Detect Inventory Slot Changes
* support rename + check for updates
* add back onChangeListener + fix npe
* ICustomNameObject TileEntity
* Fix NPEs
* Use IInterfaceTerminalSupport
* fix
* register
* dep
* spotless
* General Crafting Input Hatch QoL fixes (#2212)
* feat: refactor naming && include circuit and catalyst in default name
* feat: add 4 more slot to solve my ocd
* fix: formatting
* feat: migrate from 4x8 to 4x9
* spotlessApply (#2213)
Co-authored-by: GitHub GTNH Actions <>
* QoLs
* 9 manual items
* spotless
* feat: open master GUI when used, without holding a data-stick (#2221)
* fix destpos
* optimize empty check
* Fix error when fluidInventory.size() == 0
If the fluidInventory size is 0, there is no element to get. Add a check
for it.
* name in waila + fix int overflow
* unnecssary super
* update deps
---------
Co-authored-by: Fox_white <39846845+foxwhite25@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Firenoo <49818773+firenoo@users.noreply.github.com>
Co-authored-by: Martin Robertz <dream-master@gmx.net>
* Use real stack limit (#2256)
* Fix incorrect data stick behaviors for hatches (#2257)
* Fix pcb factory not applying its roughness multiplier when it doesn't OC (#2258)
* fix PCB Factory not applying its roughness multiplier when it doesn't do any overclocks
* spotless
* Remove duplicate obsidian long rod (#2259)
* disable gt obsidian long rod
* cleaner code
* Add hazmat to ThaumicBoots (#2260)
* Add hazmat to ThaumicBoots
does what it says
* fixed
* fix item names (#2263)
* Fix renaming recipe check might ignore NBT equality (#2261)
* Fix GPL ignoring if the recipe is allowed to be cached (#2262)
* Added bricked blast furnace recipe progress to waila. (#2265)
* Added bricked blast furnace recipe progress to waila.
* fixed formatting issues.
* Fix cutter recipes not being added (#2271)
* add processing task
* clean up item logic host
* temporary fix for GT_StructrureMuTE
* use j9+ feature on pollution task
* prepare complex parallel logic for transition
* feature to ProcessingLogicHost
* fix up multiblock bases
* add processing logic for each multi to prepare for transition
* spotless
* removed debug text from wailaBody of GT_MetaTileEntity_Hatch_CraftingInput_ME (#2272)
* Proper recipe selection for output overflow in LCR and other multiblocks (#2247)
* Implement Stream<FindRecipeResult> findRecipesWithResult for GT_RecipeMap
* Change ProcessingLogic.process to actually use new findRecipesWithResult
* Change ProcessingLogic.process to start finding something only for OUTPUT_FULL result
* Refactor ProcessingLogic.process to make logic more readable
* Replace while with for loop, remove NOT_FOUND return in end of findRecipesWithResult
* Apply spotless
* Make findRecipe use findRecipes, add annotation to GT_Recipe and FindRecipeResult for processRecipe and make method protected, replace wildcard imports
* Remake isRecipeWithOutputFullFound
* Add @Nonnull to methods
* Apply spotless
* Remove Stream version of findRecipeWithResult, replace with predicate one. Add GT_Predicated_Recipe_Map class for utilizing this method. Changes some existent recipe maps to inherit from base class.
* Remove GT_Predicated_Recipe_Map, add Predicate directly to GT_Recipe_Map#findRecipeWithResult. Add AdvancedRecipeValidatorPredicate and FindRecipeWithAdvancedValidatorResult to allow store validation calculations for further use and proper errors displaying.
* Fix InsufficientVoltage errors
* Changes according to review comments. Integrate FindRecipeWithAdvancedValidatorResult to FindRecipeResult, rename AdvancedRecipeValidatorPredicate, encapsulate AdvancedRecipeValidatorPredicate fields, fixes some typos, etc
* Moves InsufficientVoltage check to GT_ParallelHelper. Removes FindRecipeResult#State#INSUFFICIENT_VOLTAGE
* Return an old findRecipeWithResult
* Renames things, call old methods for singleblocks
* Renames things, makes FindRecipeResult ctor private
* Apply spotless
* Move RecipeValidator, fix comments typos
* update deps
* fix up complex processing logic
* add a getter for voiding mode
* fix getAccessibleSlotsFromSide being wrong sometimes
* allow for subtraction of a specific item
* use long for amount
* add a setter for machine host
* initial work on finding recipes and input consumption
* Deprecate PA by removing its controller recipe (#2273)
* Restore PA controller recipe (#2276)
* Restore PA controller recipe
* Remove duplicated recipe
* Add optional description to input hatch constructors (#2278)
* mini fix (#2204)
* [chore] Bump fallback version to 44 (#2274)
* find recipe in theory working
* add some helper methods to inventory logics
* update deps
* use collect not toList
* fix loading crash
* fix complex processing logic using wrong find recipe
* fix up everything and get recipe finding working
* annotate and clean up methods
* spotless
* save things to nbt
* input separation for mutes and fully working processing
* apply mute mode on processing logic
* clean up overrides
---------
Co-authored-by: chochem <40274384+chochem@users.noreply.github.com>
Co-authored-by: miozune <miozune@gmail.com>
Co-authored-by: Pxx500 <81298696+Pxx500@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Glease <4586901+Glease@users.noreply.github.com>
Co-authored-by: firenoo <49818773+firenoo@users.noreply.github.com>
Co-authored-by: Martin Robertz <dream-master@gmx.net>
Co-authored-by: Harry <harryyunull@gmail.com>
Co-authored-by: Eraldoe <Eraldoe@users.noreply.github.com>
Co-authored-by: Jakub <53441451+kuba6000@users.noreply.github.com>
Co-authored-by: Connor-Colenso <52056774+Connor-Colenso@users.noreply.github.com>
Co-authored-by: Guillaume Mercier <C0bra5@users.noreply.github.com>
Co-authored-by: Fox_white <39846845+foxwhite25@users.noreply.github.com>
Co-authored-by: Alastors <78517796+Alastors@users.noreply.github.com>
Co-authored-by: Kyium <43573052+Kyium@users.noreply.github.com>
Co-authored-by: SKProCH <29896317+SKProCH@users.noreply.github.com>
Co-authored-by: Sampsa <69092953+S4mpsa@users.noreply.github.com>
Co-authored-by: Jaiden Baker <jaidencolebaker@gmail.com>
* address minecraft's reviews from #2283
* Refactor MuTE processing logic (#2301) -fix conflicts
* Fix void protection for mutes (#2298) - fix conflicts
* initial variables
* implement working void protection on items and fluids
* Adds a Simple PowerOutput task and cleans up some of the code. (#2303)
* create a power output task which can be used for dynamos
* refactor the controllers and clean up
* add some documentation to power logic
* make a wireless network manager class instead of using an interface
* clean up and add documentation.
* setAmperage to setMaxAmperage
* fix comment
* remove IGlobalWirelessEnergy usage
* getAmperage -> getMaxAmperage
* add todo for future
* Cleanup MuTEMaster code (#2282)
* exit early
* spotless
* better side checking
* make if blocks mutually exclusive
* more exit early
* convert nested ternary operators into if blocks
* remove dead code
* collapse nested if blocks
* add todo to break verylong condition into much smaller ones
* spotless apply
* collapsing nested if blocks and more exit early
* spotless apply
* extract try/catch block to its own utility method
* break down this unreadable condition
* boolean magic (1/5)
* boolean magic (2/5)
Also corrected some logic on the player null check, we want it to be non null
* boolean magic (3/5)
* boolean magic (4/5)
* boolean magic (5/5)
* remove todo
* Fix logic
---------
Co-authored-by: Jason Mitchell <jason@puzzle.io>
Co-authored-by: BlueWeabo <76872108+BlueWeabo@users.noreply.github.com>
* Clean up a lil bit and fix some issues with MuTEs (#2316)
* clean up fixes
* actual fix and remove useless if
* Rework MuTEGUI structure (#2429) - fix conflicts`
Merged to rebase MuTEMaster and fix any non-compile errors and game not launching in there
* some docs on a few methods
* innitial GUI class
* try to implement guis
* almost working - fix comflict
* add UIBuildContext to getGUI method
* make it compile
* sketch gui - fix conflict
* compile and spotless
* add config option to enabling MuTEs
* Spotless apply for branch feature/MuTEMaster for #2431 (#2432)
spotlessApply
Co-authored-by: GitHub GTNH Actions <>
* address reviews on broken processing logic
* spotless
* fix doc and review
---------
Co-authored-by: Maxim <maxim235@gmx.de>
Co-authored-by: RIONDY 'POPlol333' Adam <76914762+POPlol333@users.noreply.github.com>
Co-authored-by: Jason Mitchell <mitchej@gmail.com>
Co-authored-by: Daniel Mendes <70096037+Steelux8@users.noreply.github.com>
Co-authored-by: kstvr32 <109012629+kstvr32@users.noreply.github.com>
Co-authored-by: TheEpicGamer274 <102255081+TheEpicGamer274@users.noreply.github.com>
Co-authored-by: miozune <miozune@gmail.com>
Co-authored-by: chochem <40274384+chochem@users.noreply.github.com>
Co-authored-by: Pxx500 <81298696+Pxx500@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Glease <4586901+Glease@users.noreply.github.com>
Co-authored-by: firenoo <49818773+firenoo@users.noreply.github.com>
Co-authored-by: Martin Robertz <dream-master@gmx.net>
Co-authored-by: Harry <harryyunull@gmail.com>
Co-authored-by: Eraldoe <Eraldoe@users.noreply.github.com>
Co-authored-by: Jakub <53441451+kuba6000@users.noreply.github.com>
Co-authored-by: Connor-Colenso <52056774+Connor-Colenso@users.noreply.github.com>
Co-authored-by: Guillaume Mercier <C0bra5@users.noreply.github.com>
Co-authored-by: Fox_white <39846845+foxwhite25@users.noreply.github.com>
Co-authored-by: Alastors <78517796+Alastors@users.noreply.github.com>
Co-authored-by: Kyium <43573052+Kyium@users.noreply.github.com>
Co-authored-by: SKProCH <29896317+SKProCH@users.noreply.github.com>
Co-authored-by: Sampsa <69092953+S4mpsa@users.noreply.github.com>
Co-authored-by: Jaiden Baker <jaidencolebaker@gmail.com>
Co-authored-by: boubou19 <miisterunknown@gmail.com>
Co-authored-by: Jason Mitchell <jason@puzzle.io>
Diffstat (limited to 'src/main/java/gregtech/api/util')
7 files changed, 723 insertions, 7 deletions
diff --git a/src/main/java/gregtech/api/util/GT_OverclockCalculator.java b/src/main/java/gregtech/api/util/GT_OverclockCalculator.java index 8e896fd8de..1b8748237d 100644 --- a/src/main/java/gregtech/api/util/GT_OverclockCalculator.java +++ b/src/main/java/gregtech/api/util/GT_OverclockCalculator.java @@ -152,6 +152,7 @@ public class GT_OverclockCalculator { /** * @param recipeEUt Sets the Recipe's starting voltage */ + @Nonnull public GT_OverclockCalculator setRecipeEUt(long recipeEUt) { this.recipeVoltage = recipeEUt; return this; @@ -160,6 +161,7 @@ public class GT_OverclockCalculator { /** * @param machineVoltage Sets the EUt that the machine can use. This is the voltage of the machine */ + @Nonnull public GT_OverclockCalculator setEUt(long machineVoltage) { this.machineVoltage = machineVoltage; return this; @@ -168,6 +170,7 @@ public class GT_OverclockCalculator { /** * @param duration Sets the duration of the recipe */ + @Nonnull public GT_OverclockCalculator setDuration(int duration) { this.duration = duration; return this; @@ -176,6 +179,7 @@ public class GT_OverclockCalculator { /** * @param machineAmperage Sets the Amperage that the machine can support */ + @Nonnull public GT_OverclockCalculator setAmperage(long machineAmperage) { this.machineAmperage = machineAmperage; return this; @@ -184,6 +188,7 @@ public class GT_OverclockCalculator { /** * @param recipeAmperage Sets the Amperage of the recipe */ + @Nonnull public GT_OverclockCalculator setRecipeAmperage(long recipeAmperage) { this.recipeAmperage = recipeAmperage; return this; @@ -192,6 +197,7 @@ public class GT_OverclockCalculator { /** * Enables Perfect OC in calculation */ + @Nonnull public GT_OverclockCalculator enablePerfectOC() { this.durationDecreasePerOC = 2; return this; @@ -200,6 +206,7 @@ public class GT_OverclockCalculator { /** * Set if we should be calculating overclocking using EBF's perfectOC */ + @Nonnull public GT_OverclockCalculator setHeatOC(boolean heatOC) { this.heatOC = heatOC; return this; @@ -208,6 +215,7 @@ public class GT_OverclockCalculator { /** * Sets if we should add a heat discount at the end of calculating an overclock, just like the EBF */ + @Nonnull public GT_OverclockCalculator setHeatDiscount(boolean heatDiscount) { this.heatDiscount = heatDiscount; return this; @@ -216,6 +224,7 @@ public class GT_OverclockCalculator { /** * Sets the starting heat of the recipe */ + @Nonnull public GT_OverclockCalculator setRecipeHeat(int recipeHeat) { this.recipeHeat = recipeHeat; return this; @@ -224,6 +233,7 @@ public class GT_OverclockCalculator { /** * Sets the heat of the coils on the machine */ + @Nonnull public GT_OverclockCalculator setMachineHeat(int machineHeat) { this.machineHeat = machineHeat; return this; @@ -232,6 +242,7 @@ public class GT_OverclockCalculator { /** * Sets an EUtDiscount. 0.9 is 10% less energy. 1.1 is 10% more energy */ + @Nonnull public GT_OverclockCalculator setEUtDiscount(float aEUtDiscount) { this.eutDiscount = aEUtDiscount; return this; @@ -240,6 +251,7 @@ public class GT_OverclockCalculator { /** * Sets a Speed Boost for the multiblock. 0.9 is 10% faster. 1.1 is 10% slower */ + @Nonnull public GT_OverclockCalculator setSpeedBoost(float aSpeedBoost) { this.speedBoost = aSpeedBoost; return this; @@ -248,6 +260,7 @@ public class GT_OverclockCalculator { /** * Sets the parallel that the multiblock uses */ + @Nonnull public GT_OverclockCalculator setParallel(int aParallel) { this.parallel = aParallel; return this; @@ -257,6 +270,7 @@ public class GT_OverclockCalculator { * Sets the heat discount during OC calculation if HeatOC is used. Default: 0.95 = 5% discount Used like a EU/t * Discount */ + @Nonnull public GT_OverclockCalculator setHeatDiscountMultiplier(float heatDiscountExponent) { this.heatDiscountExponent = heatDiscountExponent; return this; @@ -266,6 +280,7 @@ public class GT_OverclockCalculator { * Sets the Overclock that should be calculated when one. This uses BitShifting! Default is 2, which is a 4x * decrease */ + @Nonnull public GT_OverclockCalculator setHeatPerfectOC(int heatPerfectOC) { this.durationDecreasePerHeatOC = heatPerfectOC; return this; @@ -274,6 +289,7 @@ public class GT_OverclockCalculator { /** * Sets the amount that the EUt increases per overclock. This uses BitShifting! Default is 2, which is a 4x increase */ + @Nonnull public GT_OverclockCalculator setEUtIncreasePerOC(int aEUtIncreasePerOC) { this.eutIncreasePerOC = aEUtIncreasePerOC; return this; @@ -283,6 +299,7 @@ public class GT_OverclockCalculator { * Sets the amount that the duration decreases per overclock. This uses BitShifting! Default is 1, which halves the * duration */ + @Nonnull public GT_OverclockCalculator setDurationDecreasePerOC(int durationDecreasePerOC) { this.durationDecreasePerOC = durationDecreasePerOC; return this; @@ -292,6 +309,7 @@ public class GT_OverclockCalculator { * Set One Tick Discount on EUt based on Duration Decrease Per Overclock. This functions the same as single * blocks. */ + @Nonnull public GT_OverclockCalculator setOneTickDiscount(boolean oneTickDiscount) { this.oneTickDiscount = oneTickDiscount; return this; @@ -301,22 +319,26 @@ public class GT_OverclockCalculator { * Limit the amount of overclocks that can be performed, regardless of how much power is available. Mainly used for * fusion reactors. */ + @Nonnull public GT_OverclockCalculator limitOverclockCount(int maxOverclocks) { this.limitOverclocks = true; this.maxOverclocks = maxOverclocks; return this; } + @Nonnull public GT_OverclockCalculator setLaserOC(boolean laserOC) { this.laserOC = laserOC; return this; } + @Nonnull public GT_OverclockCalculator setAmperageOC(boolean amperageOC) { this.amperageOC = amperageOC; return this; } + @Nonnull public GT_OverclockCalculator setLaserOCPenalty(double laserOCPenalty) { this.laserOCPenalty = laserOCPenalty; return this; @@ -325,6 +347,7 @@ public class GT_OverclockCalculator { /** * Set a supplier for calculating custom duration for when its needed under one tick */ + @Nonnull public GT_OverclockCalculator setDurationUnderOneTickSupplier(Supplier<Double> supplier) { this.durationUnderOneTickSupplier = supplier; return this; @@ -333,6 +356,7 @@ public class GT_OverclockCalculator { /** * Sets if we should do overclocking or not */ + @Nonnull public GT_OverclockCalculator setNoOverclock(boolean noOverclock) { this.noOverclock = noOverclock; return this; @@ -341,6 +365,7 @@ public class GT_OverclockCalculator { /** * Call this when all values have been put it. */ + @Nonnull public GT_OverclockCalculator calculate() { if (calculated) { throw new IllegalStateException("Tried to calculate overclocks twice"); diff --git a/src/main/java/gregtech/api/util/GT_ParallelHelper.java b/src/main/java/gregtech/api/util/GT_ParallelHelper.java index 6ec736b15f..ff739664f4 100644 --- a/src/main/java/gregtech/api/util/GT_ParallelHelper.java +++ b/src/main/java/gregtech/api/util/GT_ParallelHelper.java @@ -13,6 +13,8 @@ import net.minecraftforge.fluids.FluidStack; import gregtech.api.interfaces.tileentity.IRecipeLockable; import gregtech.api.interfaces.tileentity.IVoidable; +import gregtech.api.logic.FluidInventoryLogic; +import gregtech.api.logic.ItemInventoryLogic; import gregtech.api.objects.XSTR; import gregtech.api.recipe.RecipeMap; import gregtech.api.recipe.check.CheckRecipeResult; @@ -61,6 +63,14 @@ public class GT_ParallelHelper { */ private ItemStack[] itemInputs; /** + * The inputs of the machine for current recipe check + */ + private ItemInventoryLogic itemInputInventory; + /** + * The output item inventory of the machine + */ + private ItemInventoryLogic itemOutputInventory; + /** * The outputs of the recipe with the applied parallel */ private ItemStack[] itemOutputs; @@ -69,6 +79,14 @@ public class GT_ParallelHelper { */ private FluidStack[] fluidInputs; /** + * The inputs of the machine for the current recipe check + */ + private FluidInventoryLogic fluidInputInventory; + /** + * The output fluid inventory of the machine; + */ + private FluidInventoryLogic fluidOutputInventory; + /** * The outputs of the recipe with the applied parallel */ private FluidStack[] fluidOutputs; @@ -117,18 +135,25 @@ public class GT_ParallelHelper { * Calculator to use for overclocking */ private GT_OverclockCalculator calculator; - + @Nonnull private CheckRecipeResult result = CheckRecipeResultRegistry.NONE; private Function<Integer, ItemStack[]> customItemOutputCalculation; private Function<Integer, FluidStack[]> customFluidOutputCalculation; + /** + * MuTE Mode this is a mode for changing how the GT_ParallelHelper works as Mutes don't use ItemStack and FluidStack + * arrays for inputs + */ + private boolean muteMode = false; + public GT_ParallelHelper() {} /** * Sets machine, with current configuration for void protection mode. */ + @Nonnull public GT_ParallelHelper setMachine(IVoidable machine) { return setMachine(machine, machine.protectsExcessItem(), machine.protectsExcessFluid()); } @@ -136,6 +161,7 @@ public class GT_ParallelHelper { /** * Sets machine, with void protection mode forcibly. */ + @Nonnull public GT_ParallelHelper setMachine(IVoidable machine, boolean protectExcessItem, boolean protectExcessFluid) { this.protectExcessItem = protectExcessItem; this.protectExcessFluid = protectExcessFluid; @@ -146,11 +172,13 @@ public class GT_ParallelHelper { /** * Sets the recipe, which will be used for the parallel calculation */ + @Nonnull public GT_ParallelHelper setRecipe(@Nonnull GT_Recipe aRecipe) { recipe = Objects.requireNonNull(aRecipe); return this; } + @Nonnull public GT_ParallelHelper setRecipeLocked(IRecipeLockable singleRecipeMachine, boolean isRecipeLocked) { this.singleRecipeMachine = singleRecipeMachine; this.isRecipeLocked = isRecipeLocked; @@ -160,6 +188,7 @@ public class GT_ParallelHelper { /** * Sets the items available for the recipe check */ + @Nonnull public GT_ParallelHelper setItemInputs(ItemStack... aItemInputs) { this.itemInputs = aItemInputs; return this; @@ -168,6 +197,7 @@ public class GT_ParallelHelper { /** * Sets the fluid inputs available for the recipe check */ + @Nonnull public GT_ParallelHelper setFluidInputs(FluidStack... aFluidInputs) { this.fluidInputs = aFluidInputs; return this; @@ -176,6 +206,7 @@ public class GT_ParallelHelper { /** * Sets the available eut when trying for more parallels */ + @Nonnull public GT_ParallelHelper setAvailableEUt(long aAvailableEUt) { this.availableEUt = aAvailableEUt; return this; @@ -184,11 +215,13 @@ public class GT_ParallelHelper { /** * Sets the modifier for recipe eut. 1 does nothing 0.9 is 10% less. 1.1 is 10% more */ + @Nonnull public GT_ParallelHelper setEUtModifier(float aEUtModifier) { this.eutModifier = aEUtModifier; return this; } + @Nonnull public GT_ParallelHelper setCalculator(GT_OverclockCalculator calculator) { this.calculator = calculator; return this; @@ -199,6 +232,7 @@ public class GT_ParallelHelper { * * @param consume Should we consume inputs */ + @Nonnull public GT_ParallelHelper setConsumption(boolean consume) { this.consume = consume; return this; @@ -207,6 +241,7 @@ public class GT_ParallelHelper { /** * Sets the MaxParallel a multi can handle */ + @Nonnull public GT_ParallelHelper setMaxParallel(int maxParallel) { this.maxParallel = maxParallel; return this; @@ -216,6 +251,7 @@ public class GT_ParallelHelper { * Enables Batch mode. Can do up to an additional processed recipes of mCurrentParallel * mBatchModifier A batch * modifier of 1 does nothing */ + @Nonnull public GT_ParallelHelper enableBatchMode(int batchModifier) { this.batchMode = batchModifier > 1; this.batchModifier = batchModifier; @@ -227,6 +263,7 @@ public class GT_ParallelHelper { * * @param calculateOutputs Should we calculate outputs with the helper or not */ + @Nonnull public GT_ParallelHelper setOutputCalculation(boolean calculateOutputs) { this.calculateOutputs = calculateOutputs; return this; @@ -236,6 +273,7 @@ public class GT_ParallelHelper { * Set a custom way to calculate item outputs. You are given the amount of parallels and must return an ItemStack * array */ + @Nonnull public GT_ParallelHelper setCustomItemOutputCalculation(Function<Integer, ItemStack[]> custom) { customItemOutputCalculation = custom; return this; @@ -245,11 +283,30 @@ public class GT_ParallelHelper { * Set a custom way to calculate item outputs. You are given the amount of parallels and must return a FluidStack * array */ + @Nonnull public GT_ParallelHelper setCustomFluidOutputCalculation(Function<Integer, FluidStack[]> custom) { customFluidOutputCalculation = custom; return this; } + @Nonnull + public GT_ParallelHelper setMuTEMode(boolean muteMode) { + this.muteMode = muteMode; + return this; + } + + @Nonnull + public GT_ParallelHelper setItemInputInventory(ItemInventoryLogic itemInputInventory) { + this.itemInputInventory = itemInputInventory; + return this; + } + + @Nonnull + public GT_ParallelHelper setFluidInputInventory(FluidInventoryLogic fluidInputInventory) { + this.fluidInputInventory = fluidInputInventory; + return this; + } + /** * Sets method for calculating max parallel from given inputs. */ @@ -266,9 +323,22 @@ public class GT_ParallelHelper { return this; } + @Nonnull + public GT_ParallelHelper setItemOutputInventory(ItemInventoryLogic itemOutputInventory) { + this.itemOutputInventory = itemOutputInventory; + return this; + } + + @Nonnull + public GT_ParallelHelper setFluidOutputInventory(FluidInventoryLogic fluidOutputInventory) { + this.fluidOutputInventory = fluidOutputInventory; + return this; + } + /** * Finishes the GT_ParallelHelper. Anything changed after this will not effect anything */ + @Nonnull public GT_ParallelHelper build() { if (built) { throw new IllegalStateException("Tried to build twice"); @@ -407,7 +477,7 @@ public class GT_ParallelHelper { // Let's look at how many parallels we can get with void protection if (protectExcessItem || protectExcessFluid) { - if (machine == null) { + if (machine == null && !muteMode) { throw new IllegalStateException("Tried to calculate void protection, but machine is not set"); } VoidProtectionHelper voidProtectionHelper = new VoidProtectionHelper(); @@ -415,6 +485,9 @@ public class GT_ParallelHelper { .setItemOutputs(truncatedItemOutputs) .setFluidOutputs(truncatedFluidOutputs) .setMaxParallel(maxParallel) + .setItemOutputInventory(itemOutputInventory) + .setFluidOutputInventory(fluidOutputInventory) + .setMuTEMode(muteMode) .build(); maxParallel = Math.min(voidProtectionHelper.getMaxParallel(), maxParallel); if (voidProtectionHelper.isItemFull()) { diff --git a/src/main/java/gregtech/api/util/GT_Recipe.java b/src/main/java/gregtech/api/util/GT_Recipe.java index 159ac1bbd1..0e4ef2162d 100644 --- a/src/main/java/gregtech/api/util/GT_Recipe.java +++ b/src/main/java/gregtech/api/util/GT_Recipe.java @@ -7,6 +7,7 @@ import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -23,6 +24,8 @@ import gregtech.GT_Mod; import gregtech.api.GregTech_API; import gregtech.api.enums.ItemList; import gregtech.api.enums.Materials; +import gregtech.api.logic.FluidInventoryLogic; +import gregtech.api.logic.ItemInventoryLogic; import gregtech.api.objects.GT_ItemStack; import gregtech.api.recipe.RecipeCategory; import gregtech.api.recipe.RecipeMap; @@ -31,6 +34,7 @@ import gregtech.api.recipe.RecipeMetadataKey; import gregtech.api.recipe.metadata.EmptyRecipeMetadataStorage; import gregtech.api.recipe.metadata.IRecipeMetadataStorage; import gregtech.api.util.extensions.ArrayExt; +import gregtech.api.util.item.ItemHolder; import ic2.core.Ic2Items; public class GT_Recipe implements Comparable<GT_Recipe> { @@ -548,6 +552,60 @@ public class GT_Recipe implements Comparable<GT_Recipe> { return currentParallel; } + public boolean isRecipePossible(@Nullable ItemInventoryLogic itemInput, @Nullable FluidInventoryLogic fluidInput) { + return getAmountOfRecipesDone(itemInput, fluidInput, 1, true) > 0; + } + + public long getAmountOfRecipesDone(@Nullable ItemInventoryLogic itemInput, @Nullable FluidInventoryLogic fluidInput, + long maxParallel, boolean simulate) { + if (itemInput == null) { + itemInput = new ItemInventoryLogic(0); + } + + if (fluidInput == null) { + fluidInput = new FluidInventoryLogic(0, 0); + } + + itemInput.startRecipeCheck(); + Map<ItemHolder, Long> recipeItems = getItemInputsAsItemMap(); + for (Entry<ItemHolder, Long> entry : recipeItems.entrySet()) { + maxParallel = Math + .min(maxParallel, itemInput.calculateAmountOfTimesItemCanBeTaken(entry.getKey(), entry.getValue())); + } + + for (FluidStack fluid : mFluidInputs) { + if (fluid == null) continue; + maxParallel = Math + .min(maxParallel, fluidInput.calculateAmountOfTimesFluidCanBeTaken(fluid.getFluid(), fluid.amount)); + } + + if (simulate) { + itemInput.stopRecipeCheck(); + return maxParallel; + } + + for (Entry<ItemHolder, Long> entry : recipeItems.entrySet()) { + itemInput.subtractItemAmount(entry.getKey(), entry.getValue() * maxParallel, false); + } + + for (FluidStack fluid : mFluidInputs) { + if (fluid == null) continue; + fluidInput.drain(fluid.getFluid(), fluid.amount * maxParallel, false); + } + itemInput.stopRecipeCheck(); + return maxParallel; + } + + private Map<ItemHolder, Long> getItemInputsAsItemMap() { + Map<ItemHolder, Long> items = new HashMap<>(); + for (ItemStack item : mInputs) { + if (item == null) continue; + ItemHolder itemHolder = new ItemHolder(item); + items.put(itemHolder, items.getOrDefault(itemHolder, 0L) + item.stackSize); + } + return items; + } + @Override public int compareTo(GT_Recipe recipe) { // first lowest tier recipes @@ -720,6 +778,25 @@ public class GT_Recipe implements Comparable<GT_Recipe> { return this; } + @Override + public boolean equals(Object other) { + if (other == this) return true; + if (!(other instanceof GT_Recipe recipe)) return false; + for (int i = 0; i < Math.min(mInputs.length, recipe.mInputs.length); i++) { + if (mInputs[i] == null && recipe.mInputs[i] == null) continue; + if (mInputs[i] == null || recipe.mInputs[i] == null) return false; + ItemHolder currentIH = new ItemHolder(mInputs[i]); + ItemHolder otherIH = new ItemHolder(recipe.mInputs[i]); + if (!currentIH.equals(otherIH)) return false; + } + for (int i = 0; i < Math.min(mFluidInputs.length, recipe.mFluidInputs.length); i++) { + if (mFluidInputs[i] == null && recipe.mFluidInputs[i] == null) continue; + if (mFluidInputs[i] == null || recipe.mFluidInputs[i] == null) return false; + if (!FluidStack.areFluidStackTagsEqual(mFluidInputs[i], recipe.mFluidInputs[i])) return false; + } + return mDuration == recipe.mDuration && mEUt == recipe.mEUt && mSpecialValue == recipe.mSpecialValue; + } + public static class GT_Recipe_AssemblyLine { public static final ArrayList<GT_Recipe_AssemblyLine> sAssemblylineRecipes = new ArrayList<>(); diff --git a/src/main/java/gregtech/api/util/GT_StructureUtilityMuTE.java b/src/main/java/gregtech/api/util/GT_StructureUtilityMuTE.java new file mode 100644 index 0000000000..8e8d027463 --- /dev/null +++ b/src/main/java/gregtech/api/util/GT_StructureUtilityMuTE.java @@ -0,0 +1,271 @@ +package gregtech.api.util; + +import static gregtech.GT_Mod.GT_FML_LOGGER; +import static gregtech.api.multitileentity.enums.GT_MultiTileComponentCasing.*; +import static gregtech.api.multitileentity.enums.GT_MultiTileUpgradeCasing.*; +import static gregtech.loaders.preload.GT_Loader_MultiTileEntities.*; + +import java.util.Arrays; + +import net.minecraft.block.Block; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.IIcon; +import net.minecraft.world.World; + +import com.gtnewhorizon.structurelib.StructureLibAPI; +import com.gtnewhorizon.structurelib.structure.IStructureElement; + +import gregtech.api.enums.GT_Values; +import gregtech.api.enums.OrePrefixes; +import gregtech.api.enums.TextureSet; +import gregtech.api.multitileentity.MultiTileEntityContainer; +import gregtech.api.multitileentity.MultiTileEntityRegistry; +import gregtech.api.multitileentity.enums.GT_MultiTileUpgradeCasing; +import gregtech.api.multitileentity.interfaces.IMultiBlockController; +import gregtech.api.multitileentity.interfaces.IMultiTileEntity; +import gregtech.api.multitileentity.multiblock.base.Controller; +import gregtech.api.multitileentity.multiblock.base.MultiBlockPart; + +public class GT_StructureUtilityMuTE { + + public static final MuTEStructureCasing MOTOR_CASINGS = FunctionalCasings.Motor.getCasing(); + public static final MuTEStructureCasing PUMP_CASINGS = FunctionalCasings.Pump.getCasing(); + public static final MuTEStructureCasing CONVEYOR_CASINGS = FunctionalCasings.Conveyor.getCasing(); + public static final MuTEStructureCasing PISTON_CASINGS = FunctionalCasings.Piston.getCasing(); + public static final MuTEStructureCasing ROBOT_ARM_CASINGS = FunctionalCasings.RobotArm.getCasing(); + public static final MuTEStructureCasing EMITTER_CASINGS = FunctionalCasings.Emitter.getCasing(); + public static final MuTEStructureCasing SENSOR_CASINGS = FunctionalCasings.Sensor.getCasing(); + public static final MuTEStructureCasing FIELD_GENERATOR_CASINGS = FunctionalCasings.FieldGenerator.getCasing(); + public static final MuTEStructureCasing INVENTORY_CASINGS = UpgradeCasings.Inventory.getCasing(); + public static final MuTEStructureCasing TANK_CASINGS = UpgradeCasings.Tank.getCasing(); + public static final MuTEStructureCasing AMPERAGE_CASINGS = UpgradeCasings.Amperage.getCasing(); + public static final MuTEStructureCasing LASER_CASINGS = UpgradeCasings.Laser.getCasing(); + public static final MuTEStructureCasing WIRELESS_CASINGS = UpgradeCasings.Wireless.getCasing(); + public static final MuTEStructureCasing CLEANROOM_CASINGS = UpgradeCasings.Cleanroom.getCasing(); + public static final MuTEStructureCasing HEATER_CASINGS = UpgradeCasings.Heater.getCasing(); + public static final MuTEStructureCasing INSULATOR_CASINGS = UpgradeCasings.Insulator.getCasing(); + + public enum FunctionalCasings { + + Motor(COMPONENT_CASING_REGISTRY_NAME, LV_Motor.getId(), MV_Motor.getId(), HV_Motor.getId(), EV_Motor.getId(), + IV_Motor.getId(), LuV_Motor.getId(), ZPM_Motor.getId(), UV_Motor.getId(), UHV_Motor.getId(), + UEV_Motor.getId(), UIV_Motor.getId(), UMV_Motor.getId(), UXV_Motor.getId(), MAX_Motor.getId()), + + Pump(COMPONENT_CASING_REGISTRY_NAME, LV_Pump.getId(), MV_Pump.getId(), HV_Pump.getId(), EV_Pump.getId(), + IV_Pump.getId(), LuV_Pump.getId(), ZPM_Pump.getId(), UV_Pump.getId(), UHV_Pump.getId(), UEV_Pump.getId(), + UIV_Pump.getId(), UMV_Pump.getId(), UXV_Pump.getId(), MAX_Pump.getId()), + + Conveyor(COMPONENT_CASING_REGISTRY_NAME, LV_Conveyor.getId(), MV_Conveyor.getId(), HV_Conveyor.getId(), + EV_Conveyor.getId(), IV_Conveyor.getId(), LuV_Conveyor.getId(), ZPM_Conveyor.getId(), UV_Conveyor.getId(), + UHV_Conveyor.getId(), UEV_Conveyor.getId(), UIV_Conveyor.getId(), UMV_Conveyor.getId(), + UXV_Conveyor.getId(), MAX_Conveyor.getId()), + + Piston(COMPONENT_CASING_REGISTRY_NAME, LV_Piston.getId(), MV_Piston.getId(), HV_Piston.getId(), + EV_Piston.getId(), IV_Piston.getId(), LuV_Piston.getId(), ZPM_Piston.getId(), UV_Piston.getId(), + UHV_Piston.getId(), UEV_Piston.getId(), UIV_Piston.getId(), UMV_Piston.getId(), UXV_Piston.getId(), + MAX_Piston.getId()), + + RobotArm(COMPONENT_CASING_REGISTRY_NAME, LV_RobotArm.getId(), MV_RobotArm.getId(), HV_RobotArm.getId(), + EV_RobotArm.getId(), IV_RobotArm.getId(), LuV_RobotArm.getId(), ZPM_RobotArm.getId(), UV_RobotArm.getId(), + UHV_RobotArm.getId(), UEV_RobotArm.getId(), UIV_RobotArm.getId(), UMV_RobotArm.getId(), + UXV_RobotArm.getId(), MAX_RobotArm.getId()), + + Emitter(COMPONENT_CASING_REGISTRY_NAME, LV_Emitter.getId(), MV_Emitter.getId(), HV_Emitter.getId(), + EV_Emitter.getId(), IV_Emitter.getId(), LuV_Emitter.getId(), ZPM_Emitter.getId(), UV_Emitter.getId(), + UHV_Emitter.getId(), UEV_Emitter.getId(), UIV_Emitter.getId(), UMV_Emitter.getId(), UXV_Emitter.getId(), + MAX_Emitter.getId()), + + Sensor(COMPONENT_CASING_REGISTRY_NAME, LV_Sensor.getId(), MV_Sensor.getId(), HV_Sensor.getId(), + EV_Sensor.getId(), IV_Sensor.getId(), LuV_Sensor.getId(), ZPM_Sensor.getId(), UV_Sensor.getId(), + UHV_Sensor.getId(), UEV_Sensor.getId(), UIV_Sensor.getId(), UMV_Sensor.getId(), UXV_Sensor.getId(), + MAX_Sensor.getId()), + + FieldGenerator(COMPONENT_CASING_REGISTRY_NAME, LV_FieldGenerator.getId(), MV_FieldGenerator.getId(), + HV_FieldGenerator.getId(), EV_FieldGenerator.getId(), IV_FieldGenerator.getId(), LuV_FieldGenerator.getId(), + ZPM_FieldGenerator.getId(), UV_FieldGenerator.getId(), UHV_FieldGenerator.getId(), + UEV_FieldGenerator.getId(), UIV_FieldGenerator.getId(), UMV_FieldGenerator.getId(), + UXV_FieldGenerator.getId(), MAX_FieldGenerator.getId()); + + private final MuTEStructureCasing casing; + + FunctionalCasings(String registryName, Integer... validIds) { + casing = createMuTEStructureCasing(registryName, validIds); + } + + public MuTEStructureCasing getCasing() { + return casing; + } + } + + public enum UpgradeCasings { + + Inventory(UPGRADE_CASING_REGISTRY_NAME, ULV_Inventory.getId(), LV_Inventory.getId(), MV_Inventory.getId(), + HV_Inventory.getId(), EV_Inventory.getId(), IV_Inventory.getId(), LuV_Inventory.getId(), + ZPM_Inventory.getId(), UV_Inventory.getId(), UHV_Inventory.getId(), UEV_Inventory.getId(), + UIV_Inventory.getId(), UMV_Inventory.getId(), UXV_Inventory.getId(), MAX_Inventory.getId()), + + Tank(UPGRADE_CASING_REGISTRY_NAME, ULV_Tank.getId(), LV_Tank.getId(), MV_Tank.getId(), HV_Tank.getId(), + EV_Tank.getId(), IV_Tank.getId(), LuV_Tank.getId(), ZPM_Tank.getId(), UV_Tank.getId(), UHV_Tank.getId(), + UEV_Tank.getId(), UIV_Tank.getId(), UMV_Tank.getId(), UXV_Tank.getId(), MAX_Tank.getId()), + + Amperage(UPGRADE_CASING_REGISTRY_NAME, Amp_4.getId(), Amp_16.getId(), Amp_64.getId(), Amp_256.getId(), + Amp_1_024.getId(), Amp_4_096.getId(), Amp_16_384.getId(), Amp_65_536.getId(), Amp_262_144.getId(), + Amp_1_048_576.getId()), + + Laser(UPGRADE_CASING_REGISTRY_NAME, GT_MultiTileUpgradeCasing.Laser.getId()), + + Wireless(UPGRADE_CASING_REGISTRY_NAME, GT_MultiTileUpgradeCasing.Wireless.getId()), + + Cleanroom(UPGRADE_CASING_REGISTRY_NAME, GT_MultiTileUpgradeCasing.Cleanroom.getId()), + + Heater(UPGRADE_CASING_REGISTRY_NAME, Heater_Prototype.getId(), Heater_IndustrialGrade.getId(), + Heater_NextGen.getId(), Heater_Omnipotent.getId(), Heater_OmegaType.getId()), + + Insulator(UPGRADE_CASING_REGISTRY_NAME, Insulator_Prototype.getId(), Insulator_IndustrialGrade.getId(), + Insulator_NextGen.getId(), Insulator_Omnipotent.getId(), Insulator_OmegaType.getId()); + + private final MuTEStructureCasing casing; + + UpgradeCasings(String registryName, Integer... validIds) { + casing = createMuTEStructureCasing(registryName, validIds); + } + + public MuTEStructureCasing getCasing() { + return casing; + } + } + + /** + * Specify all casing sets that are valid for a multiblock structure position. The first casing will be used as + * default when doing auto place + * + * @param modes Allowed modes on the casings + * @param validCasings Allowed casing sets + * @return Structure Element + * @param <T> Multiblock class + */ + public static <T> IStructureElement<T> ofMuTECasings(int modes, MuTEStructureCasing... validCasings) { + if (validCasings == null || validCasings.length == 0) { + throw new IllegalArgumentException(); + } + return new IStructureElement<>() { + + final MuTEStructureCasing[] allowedCasings = validCasings; + private final static short[] DEFAULT = new short[] { 255, 255, 255, 0 }; + private static IIcon[] mIcons = null; + + @Override + public boolean check(T t, World world, int x, int y, int z) { + final TileEntity tileEntity = world.getTileEntity(x, y, z); + if (!(tileEntity instanceof MultiBlockPart part)) return false; + + for (MuTEStructureCasing casing : allowedCasings) { + if (casing.isCasingValid(part.getMultiTileEntityRegistryID(), part.getMultiTileEntityID())) { + final IMultiBlockController tTarget = part.getTarget(false); + if (tTarget != null && tTarget != t) return false; + + part.setTarget((IMultiBlockController) t, modes); + + ((Controller<?, ?>) t).registerSpecialCasings(part); + return true; + } + } + + return false; + } + + @Override + public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { + // Moved here from Controller. TODO: Proper implementation + if (mIcons == null) { + mIcons = new IIcon[6]; + Arrays.fill(mIcons, TextureSet.SET_NONE.mTextures[OrePrefixes.block.mTextureIndex].getIcon()); + } + final short[] RGBA = DEFAULT; + StructureLibAPI.hintParticleTinted(world, x, y, z, mIcons, RGBA); + return true; + } + + @Override + public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { + final MultiTileEntityRegistry tRegistry = MultiTileEntityRegistry + .getRegistry(validCasings[0].getRegistryId()); + if (tRegistry == null) { + GT_FML_LOGGER.error("NULL REGISTRY"); + return false; + } + final MultiTileEntityContainer tContainer = tRegistry + .getNewTileEntityContainer(world, x, y, z, validCasings[0].defaultMeta, null); + if (tContainer == null) { + GT_FML_LOGGER.error("NULL CONTAINER"); + return false; + } + final IMultiTileEntity te = ((IMultiTileEntity) tContainer.mTileEntity); + if (!(te instanceof MultiBlockPart)) { + GT_FML_LOGGER.error("Not a multiblock part"); + return false; + } + if (world.setBlock(x, y, z, tContainer.mBlock, 15 - tContainer.mBlockMetaData, 2)) { + tContainer.setMultiTile(world, x, y, z); + ((MultiBlockPart) te).setTarget((IMultiBlockController) t, modes); + + ((Controller<?, ?>) t).registerSpecialCasings((MultiBlockPart) te); + } + + return false; + } + }; + } + + public static MuTEStructureCasing createMuTEStructureCasing(String registryName, Integer... validIds) { + return new MuTEStructureCasing(registryName, validIds); + } + + /** + * Object used to store a set of casings (e.g. all motor casings) + */ + public static class MuTEStructureCasing { + + private String registryName; + private int registryId = GT_Values.W; + private final int defaultMeta; + private final Integer[] validIds; + + public MuTEStructureCasing(String registryName, Integer... validIds) { + MultiTileEntityRegistry registry = MultiTileEntityRegistry.getRegistry(registryName); + if (validIds == null || validIds.length == 0 || registry == null) { + throw new IllegalArgumentException(); + } + this.registryName = registryName; + this.validIds = validIds; + this.defaultMeta = validIds[0]; + } + + public boolean isCasingValid(int registryId, int id) { + if (getRegistryId() != registryId) { + return false; + } + for (Integer validId : validIds) { + if (validId == id) { + return true; + } + } + return false; + } + + public int getDefaultMeta() { + return defaultMeta; + } + + public int getRegistryId() { + // TODO: MuTE registry seems to somehow shift, probably due to NBT shenanigans. Lazy init circumvents this + // but it should be properly fixed in the future + if (registryId == GT_Values.W) { + MultiTileEntityRegistry registry = MultiTileEntityRegistry.getRegistry(registryName); + registryId = Block.getIdFromBlock(registry.mBlock); + } + return registryId; + } + } +} diff --git a/src/main/java/gregtech/api/util/VoidProtectionHelper.java b/src/main/java/gregtech/api/util/VoidProtectionHelper.java index 3a41bba934..245fc24bda 100644 --- a/src/main/java/gregtech/api/util/VoidProtectionHelper.java +++ b/src/main/java/gregtech/api/util/VoidProtectionHelper.java @@ -10,9 +10,12 @@ import net.minecraft.item.ItemStack; import net.minecraftforge.fluids.FluidStack; import com.gtnewhorizon.gtnhlib.util.map.ItemStackMap; +import com.gtnewhorizons.modularui.api.fluids.IFluidTankLong; import gregtech.api.interfaces.fluid.IFluidStore; import gregtech.api.interfaces.tileentity.IVoidable; +import gregtech.api.logic.FluidInventoryLogic; +import gregtech.api.logic.ItemInventoryLogic; /** * Helper class to calculate how many parallels of items / fluids can fit in the output buses / hatches. @@ -52,9 +55,21 @@ public class VoidProtectionHelper { */ private FluidStack[] fluidOutputs; /** + * The item output inventory + */ + private ItemInventoryLogic itemOutputInventory; + /** + * The fluid output inventory + */ + private FluidInventoryLogic fluidOutputInventory; + /** * Has this helper been built? */ private boolean built; + /** + * Is this helper working for a MuTE? + */ + private boolean muteMode; public VoidProtectionHelper() {} @@ -93,6 +108,21 @@ public class VoidProtectionHelper { return this; } + public VoidProtectionHelper setItemOutputInventory(ItemInventoryLogic itemOutputInventory) { + this.itemOutputInventory = itemOutputInventory; + return this; + } + + public VoidProtectionHelper setFluidOutputInventory(FluidInventoryLogic fluidOutputInventory) { + this.fluidOutputInventory = fluidOutputInventory; + return this; + } + + public VoidProtectionHelper setMuTEMode(boolean muteMode) { + this.muteMode = muteMode; + return this; + } + /** * Finishes the VoidProtectionHelper. Anything changed after this will not affect anything */ @@ -241,11 +271,95 @@ public class VoidProtectionHelper { return aParallelQueue.element().batch; } + private int calculateMaxFluidParallelsMuTE() { + if (fluidOutputs.length > fluidOutputInventory.getInventory() + .getTanks()) { + return 0; + } + + // A map to hold the items we will be 'inputting' into the output hatches. These fluidstacks are actually + // the recipe outputs. + Map<FluidStack, Integer> tFluidOutputMap = new HashMap<>(); + + // Map that keeps track of the number of parallel crafts we can accommodate for each fluid output. + // In the pair, we keep track of number of full crafts plus mb of fluid in a partial craft, to avoid + // issues with floating point math not being completely accurate when summing. + Map<FluidStack, ParallelData> tParallels = new HashMap<>(); + + // Iterate over the outputs, calculating require stack spacing they will require. + for (FluidStack aY : fluidOutputs) { + if (aY == null || aY.amount <= 0) { + continue; + } + tFluidOutputMap.merge(aY, aY.amount, Integer::sum); + tParallels.put(aY, new ParallelData(0, 0)); + } + + if (tFluidOutputMap.isEmpty()) { + // nothing to output, bail early + return maxParallel; + } + + for (int i = 0; i < fluidOutputInventory.getInventory() + .getTanks(); i++) { + IFluidTankLong tank = fluidOutputInventory.getInventory() + .getFluidTank(i); + long tSpaceLeft = tank.getCapacityLong() - tank.getFluidAmountLong(); + // check if hatch filled + if (tSpaceLeft <= 0) continue; + // check if hatch is empty and unrestricted + if (tank.getStoredFluid() == null) continue; + + for (Map.Entry<FluidStack, ParallelData> entry : tParallels.entrySet()) { + FluidStack tFluidOutput = entry.getKey(); + if (tank.fill(tFluidOutput.getFluid(), tFluidOutput.amount, false) == tFluidOutput.amount) continue; + // this fluid is not prevented by restrictions on output hatch + ParallelData tParallel = entry.getValue(); + Integer tCraftSize = tFluidOutputMap.get(tFluidOutput); + tParallel.batch += (tParallel.partial + tSpaceLeft) / tCraftSize; + tParallel.partial = (tParallel.partial + tSpaceLeft) % tCraftSize; + } + } + // now that all partial/restricted hatches have been counted, create a priority queue for our outputs + // the lowest priority fluid is the number of complete parallel crafts we can support + PriorityQueue<ParallelStackInfo<FluidStack>> aParallelQueue = new PriorityQueue<>( + Comparator.comparing(i -> i.batch)); + for (Map.Entry<FluidStack, ParallelData> entry : tParallels.entrySet()) { + aParallelQueue + .add(new ParallelStackInfo<>(entry.getValue().batch, entry.getValue().partial, entry.getKey())); + } + // add extra parallels for open slots as well + for (int i = 0; i < fluidOutputInventory.getInventory() + .getTanks(); i++) { + IFluidTankLong tank = fluidOutputInventory.getInventory() + .getFluidTank(i); + // partially filled or restricted hatch. done in the last pass + if (tank.getStoredFluid() != null) continue; + + ParallelStackInfo<FluidStack> tParallel = aParallelQueue.poll(); + assert tParallel != null; // will always be true, specifying assert here to avoid IDE/compiler warnings + Integer tCraftSize = tFluidOutputMap.get(tParallel.stack); + long tSpaceLeft = tank.getCapacityLong(); + tParallel.batch += (tParallel.partial + tSpaceLeft) / tCraftSize; + tParallel.partial = (tParallel.partial + tSpaceLeft) % tCraftSize; + aParallelQueue.add(tParallel); + } + + return aParallelQueue.element().batch; + } + /** * Calculates the max parallels one can do with items if void protection is on */ private int calculateMaxItemParallels() { - List<ItemStack> busStacks = machine.getItemOutputSlots(itemOutputs); + List<ItemStack> busStacks; + + if (muteMode) { + busStacks = itemOutputInventory.getInventory() + .getStacks(); + } else { + busStacks = machine.getItemOutputSlots(itemOutputs); + } // A map to hold the items we will be 'inputting' into the output buses. These itemstacks are actually the // recipe outputs. Map<ItemStack, Integer> tItemOutputMap = new ItemStackMap<>(); @@ -320,9 +434,9 @@ public class VoidProtectionHelper { private static class ParallelData { private int batch; - private int partial; + private long partial; - private ParallelData(int batch, int partial) { + private ParallelData(int batch, long partial) { this.batch = batch; this.partial = partial; } @@ -331,10 +445,10 @@ public class VoidProtectionHelper { private static class ParallelStackInfo<T> { private int batch; - private int partial; + private long partial; private final T stack; - private ParallelStackInfo(int batch, int partial, T stack) { + private ParallelStackInfo(int batch, long partial, T stack) { this.batch = batch; this.partial = partial; this.stack = stack; diff --git a/src/main/java/gregtech/api/util/item/ItemHolder.java b/src/main/java/gregtech/api/util/item/ItemHolder.java new file mode 100644 index 0000000000..4675d0ba0e --- /dev/null +++ b/src/main/java/gregtech/api/util/item/ItemHolder.java @@ -0,0 +1,79 @@ +package gregtech.api.util.item; + +import static net.minecraftforge.oredict.OreDictionary.getOreIDs; + +import java.util.Arrays; + +import javax.annotation.Nonnull; + +import net.minecraft.init.Items; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; + +import gregtech.api.util.GT_Utility; + +public class ItemHolder { + + private final Item item; + private final int meta; + private final NBTTagCompound tag; + private final int[] oreIDs; + + public ItemHolder(@Nonnull ItemStack item) { + this.item = item.getItem(); + this.meta = Items.feather.getDamage(item); + this.tag = item.getTagCompound(); + this.oreIDs = getOreIDs(item); + } + + public Item getItem() { + return item; + } + + public int getMeta() { + return meta; + } + + public NBTTagCompound getNBT() { + return tag; + } + + public int[] getOreDictTagIDs() { + return oreIDs; + } + + @Override + public boolean equals(Object other) { + if (other == this) return true; + if (!(other instanceof ItemHolder otherIH)) return false; + if (Arrays.stream(oreIDs) + .anyMatch(id -> { + for (int i = 0; i < otherIH.getOreDictTagIDs().length; i++) { + if (id == otherIH.getOreDictTagIDs()[i]) return true; + } + return false; + })) { + return true; + } + + if (item != otherIH.getItem() || meta != otherIH.getMeta()) { + return false; + } + if (this.tag == null && otherIH.getNBT() == null) return true; + if (this.tag == null || otherIH.getNBT() == null) return false; + return this.tag.equals(otherIH); + } + + @Override + public int hashCode() { + return GT_Utility.stackToInt(toStack()); + } + + @Nonnull + private ItemStack toStack() { + ItemStack item = new ItemStack(this.item, 1, meta); + item.stackTagCompound = tag; + return item; + } +} diff --git a/src/main/java/gregtech/api/util/recipe/RecipeInputRequirements.java b/src/main/java/gregtech/api/util/recipe/RecipeInputRequirements.java new file mode 100644 index 0000000000..590c104101 --- /dev/null +++ b/src/main/java/gregtech/api/util/recipe/RecipeInputRequirements.java @@ -0,0 +1,77 @@ +package gregtech.api.util.recipe; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; + +import javax.annotation.Nonnull; + +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidStack; + +import gregtech.api.util.GT_Recipe; +import gregtech.api.util.item.ItemHolder; + +public class RecipeInputRequirements { + + protected Map<ItemHolder, Long> itemInputs = new HashMap<>(); + protected Set<ItemHolder> itemInputsMet = new HashSet<>(); + protected boolean metAllItem = false; + protected Map<Fluid, Long> fluidInputs = new HashMap<>(); + protected Set<Fluid> fluidInputsMet = new HashSet<>(); + protected boolean metAllFluid = false; + + public RecipeInputRequirements(@Nonnull GT_Recipe recipe) { + this(recipe.mInputs, recipe.mFluidInputs); + } + + public RecipeInputRequirements(@Nonnull ItemStack[] itemInputs, @Nonnull FluidStack[] fluidInputs) { + for (ItemStack item : itemInputs) { + if (item == null) continue; + ItemHolder itemIH = new ItemHolder(item); + this.itemInputs.put(itemIH, this.itemInputs.getOrDefault(itemIH, 0L) + item.stackSize); + } + + for (FluidStack fluid : fluidInputs) { + if (fluid == null) continue; + this.fluidInputs.put(fluid.getFluid(), this.fluidInputs.getOrDefault(fluid.getFluid(), 0L) + fluid.amount); + } + } + + /** + * + * @param itemInputs we have and want to fill this request + * @return {@code true} when all item inputs are met + */ + public boolean tryToFillItemRequirements(Map<ItemHolder, Long> itemInputs) { + if (metAllItem) return metAllItem; + for (Entry<ItemHolder, Long> entry : itemInputs.entrySet()) { + if (itemInputsMet.contains(entry.getKey())) continue; + if (!this.itemInputs.containsKey(entry.getKey())) continue; + if (this.itemInputs.get(entry.getKey()) > entry.getValue()) continue; + itemInputsMet.add(entry.getKey()); + } + metAllItem = itemInputsMet.containsAll(this.itemInputs.keySet()); + return metAllItem; + } + + /** + * + * @param fluidInputs we have and want to fill this request + * @return {@code true} when all fluid inputs are met + */ + public boolean tryToFillFluidRequirements(Map<Fluid, Long> fluidInputs) { + if (metAllFluid) return metAllFluid; + for (Entry<Fluid, Long> entry : fluidInputs.entrySet()) { + if (fluidInputsMet.contains(entry.getKey())) continue; + if (!this.fluidInputs.containsKey(entry.getKey())) continue; + if (this.fluidInputs.get(entry.getKey()) > entry.getValue()) continue; + fluidInputsMet.add(entry.getKey()); + } + metAllFluid = fluidInputsMet.containsAll(this.fluidInputs.keySet()); + return metAllFluid; + } +} |