Skip to content
This repository has been archived by the owner on Dec 28, 2024. It is now read-only.

Commit

Permalink
[Modules] Storage module & moduleable
Browse files Browse the repository at this point in the history
  • Loading branch information
JojoFR1 committed Jul 21, 2024
1 parent 2b68195 commit ed8ff00
Show file tree
Hide file tree
Showing 4 changed files with 181 additions and 11 deletions.
12 changes: 8 additions & 4 deletions src/aeyama/content/AeyamaBlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import mindustry.world.meta.*;

import aeyama.world.block.*;
import aeyama.world.block.module.*;
import aeyama.world.block.storage.*;

import static mindustry.type.ItemStack.*;

Expand Down Expand Up @@ -37,20 +39,22 @@ public static void load() {

requirements(Category.effect, with(Items.copper, 1));
}};
moduleTestTwo = new ModuleBlock("module-testtttt") {{
moduleTestTwo = new ModuleStorage("module-testtttt") {{
health = 20;
size = 1;

tag = "koejrfezoeigjosejengkzjne";
tag = "storage";

requirements(Category.effect, with(Items.copper, 1));
}};

moduleableTest = new ModuleableBlock("moduleable-test", 3) {{
moduleableTest = new ModuleableStorageBlock("moduleable-test", 3) {{
health = 50;
size = 3;

tags.add("efficiency");
itemCapacity = 100;

tags.add("storage");

requirements(Category.effect, with(Items.copper, 1));
}};
Expand Down
16 changes: 9 additions & 7 deletions src/aeyama/world/block/ModuleableBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,22 @@ public void getRegionsToOutline(Seq<TextureRegion> out) {
public class ModuleableBuild extends Building {
public Seq<ModuleBuild> modules = new Seq<ModuleBuild>();

public void setBackVariables() {

}

@Override
public void onProximityUpdate() {
proximity.each(this::isModule, module -> {
((ModuleBuild)module).linkedBuild = this;
modules.add((ModuleBuild)module);
});

setBackVariables();
for (ModuleBuild module : modules) {
module.effect(this, this.block);
}

super.onProximityUpdate();
}

Expand All @@ -135,13 +144,6 @@ public boolean isModule(Building build, Building tile) {
&& modules.size < moduleSlots && !modules.contains(module);
}

@Override
public void updateTile() {
for (ModuleBuild module : modules) {
module.effect(this, this.block);
}
}

@Override
public void draw() {
drawer.draw(this);
Expand Down
25 changes: 25 additions & 0 deletions src/aeyama/world/block/module/ModuleStorage.java
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 src/aeyama/world/block/storage/ModuleableStorageBlock.java
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;
}
}
}

0 comments on commit ed8ff00

Please sign in to comment.