This repository has been archived by the owner on Dec 28, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Modules] Storage module & moduleable
- Loading branch information
Showing
4 changed files
with
181 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package aeyama.world.block.module; | ||
|
||
import mindustry.gen.*; | ||
import mindustry.world.*; | ||
|
||
import aeyama.world.block.*; | ||
import aeyama.world.block.storage.*; | ||
import aeyama.world.block.storage.ModuleableStorageBlock.*; | ||
|
||
public class ModuleStorage extends ModuleBlock { | ||
|
||
public ModuleStorage(String name) { | ||
super(name); | ||
} | ||
|
||
public class ModuleStorageBuild extends ModuleBuild { | ||
|
||
@Override | ||
public void effect(Building build, Block block) { | ||
if (build instanceof ModuleableStorageBuild storageBuild) { | ||
storageBuild.storageItemCapacity *= 1.1; | ||
} | ||
} | ||
} | ||
} |
139 changes: 139 additions & 0 deletions
139
src/aeyama/world/block/storage/ModuleableStorageBlock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
package aeyama.world.block.storage; | ||
|
||
import arc.math.*; | ||
import arc.struct.*; | ||
import arc.util.*; | ||
|
||
import mindustry.content.*; | ||
import mindustry.gen.*; | ||
import mindustry.type.*; | ||
import mindustry.world.*; | ||
import mindustry.world.blocks.storage.CoreBlock.*; | ||
import mindustry.world.meta.*; | ||
|
||
import aeyama.world.block.*; | ||
|
||
import static mindustry.Vars.*; | ||
|
||
public class ModuleableStorageBlock extends ModuleableBlock { | ||
public boolean coreMerge = true; | ||
|
||
public ModuleableStorageBlock(String name) { | ||
this(name, 0); | ||
} | ||
|
||
public ModuleableStorageBlock(String name, int moduleSlots) { | ||
super(name, moduleSlots); | ||
|
||
hasItems = true; | ||
solid = true; | ||
update = false; | ||
destructible = true; | ||
separateItemCapacity = true; | ||
group = BlockGroup.transportation; | ||
flags = EnumSet.of(BlockFlag.storage); | ||
allowResupply = true; | ||
envEnabled = Env.any; | ||
} | ||
|
||
@Override | ||
public boolean outputsItems(){ | ||
return false; | ||
} | ||
|
||
public static void incinerateEffect(Building self, Building source){ | ||
if(Mathf.chance(0.3)){ | ||
Tile edge = Edges.getFacingEdge(source, self); | ||
Tile edge2 = Edges.getFacingEdge(self, source); | ||
if(edge != null && edge2 != null && self.wasVisible){ | ||
Fx.coreBurn.at((edge.worldx() + edge2.worldx())/2f, (edge.worldy() + edge2.worldy())/2f); | ||
} | ||
} | ||
} | ||
|
||
|
||
public class ModuleableStorageBuild extends ModuleableBuild { | ||
public @Nullable Building linkedCore; | ||
public int storageItemCapacity; | ||
|
||
@Override | ||
public void setBackVariables() { | ||
storageItemCapacity = this.block.itemCapacity; | ||
} | ||
|
||
@Override | ||
public boolean acceptItem(Building source, Item item){ | ||
return linkedCore != null ? linkedCore.acceptItem(source, item) : items.get(item) < getMaximumAccepted(item); | ||
} | ||
|
||
@Override | ||
public void handleItem(Building source, Item item){ | ||
if(linkedCore != null){ | ||
if(linkedCore.items.get(item) >= ((CoreBuild)linkedCore).storageCapacity){ | ||
incinerateEffect(this, source); | ||
} | ||
((CoreBuild)linkedCore).noEffect = true; | ||
linkedCore.handleItem(source, item); | ||
}else{ | ||
super.handleItem(source, item); | ||
} | ||
} | ||
|
||
@Override | ||
public void itemTaken(Item item){ | ||
if(linkedCore != null){ | ||
linkedCore.itemTaken(item); | ||
} | ||
} | ||
|
||
@Override | ||
public int removeStack(Item item, int amount){ | ||
int result = super.removeStack(item, amount); | ||
|
||
if(linkedCore != null && team == state.rules.defaultTeam && state.isCampaign()){ | ||
state.rules.sector.info.handleCoreItem(item, -result); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
@Override | ||
public int getMaximumAccepted(Item item){ | ||
return linkedCore != null ? linkedCore.getMaximumAccepted(item) : this.storageItemCapacity; | ||
} | ||
|
||
@Override | ||
public int explosionItemCap(){ | ||
//when linked to a core, containers/vaults are made significantly less explosive. | ||
return linkedCore != null ? Math.min(this.storageItemCapacity/60, 6) : this.storageItemCapacity; | ||
} | ||
|
||
@Override | ||
public void drawSelect(){ | ||
super.drawSelect(); | ||
|
||
if(linkedCore != null){ | ||
linkedCore.drawSelect(); | ||
} | ||
} | ||
|
||
@Override | ||
public void overwrote(Seq<Building> previous){ | ||
//only add prev items when core is not linked | ||
if(linkedCore == null){ | ||
for(Building other : previous){ | ||
if(other.items != null && other.items != items){ | ||
items.add(other.items); | ||
} | ||
} | ||
|
||
items.each((i, a) -> items.set(i, Math.min(a, this.storageItemCapacity))); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean canPickup(){ | ||
return linkedCore == null; | ||
} | ||
} | ||
} |