Skip to content

Commit

Permalink
Add bridge conveyors of custom length
Browse files Browse the repository at this point in the history
  • Loading branch information
Mars committed May 3, 2023
1 parent 43d3454 commit 15f31f9
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 17 deletions.
15 changes: 0 additions & 15 deletions src/me/mars/BlockHandler.java

This file was deleted.

1 change: 1 addition & 0 deletions src/me/mars/Bridges.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import arc.struct.IntSeq;
import arc.struct.Seq;
import arc.util.*;
import me.mars.blocks.BlockHandler;
import mindustry.Vars;
import mindustry.game.EventType.*;
import mindustry.gen.Groups;
Expand Down
26 changes: 26 additions & 0 deletions src/me/mars/blocks/BlockHandler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package me.mars.blocks;

import arc.Events;
import mindustry.content.Blocks;
import mindustry.game.EventType.ContentInitEvent;
import mindustry.world.Block;
import mindustry.world.blocks.distribution.BufferedItemBridge;
import mindustry.world.blocks.power.PowerNode;

public class BlockHandler {
public static void init() {
Events.on(ContentInitEvent.class, contentInitEvent -> {
new WeavedNode((PowerNode) Blocks.powerNode);
new ShortBridge((BufferedItemBridge) Blocks.itemBridge, 2);
new ShortBridge((BufferedItemBridge) Blocks.itemBridge, 3);
});
}

public static void cloneStats(Block block, Block target) {
block.health = target.health;
block.size = target.size;
block.buildCost = target.buildCost;
block.requirements(target.category, target.requirements.clone());

}
}
42 changes: 42 additions & 0 deletions src/me/mars/blocks/ShortBridge.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package me.mars.blocks;

import arc.util.Reflect;
import mindustry.ctype.MappableContent;
import mindustry.entities.units.BuildPlan;
import mindustry.world.blocks.distribution.BufferedItemBridge;

public class ShortBridge extends BufferedItemBridge {
BufferedItemBridge parent;
public ShortBridge(BufferedItemBridge parent, int range) {
super(parent.name+"["+range+"]");
this.parent = parent;
BlockHandler.cloneStats(this, parent);
this.range = Math.min(parent.range-1, range);
this.itemCapacity = parent.itemCapacity;
this.bufferCapacity = parent.bufferCapacity;
this.init();
}

@Override
public void load() {
String name = this.name;
Reflect.set(MappableContent.class, this, "name", parent.name);
super.load();
Reflect.set(MappableContent.class, this, "name", name);
this.region = parent.region;
}

@Override
public void loadIcon() {
String name = this.name;
Reflect.set(MappableContent.class, this, "name", parent.name);
super.loadIcon();
Reflect.set(MappableContent.class, this, "name", name);
this.region = parent.region;
}

@Override
public void onNewPlan(BuildPlan plan) {
plan.block = this.parent;
}
}
3 changes: 1 addition & 2 deletions src/me/mars/blocks/WeavedNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import mindustry.Vars;
import mindustry.ctype.MappableContent;
import mindustry.entities.units.BuildPlan;
import mindustry.type.Category;
import mindustry.world.blocks.power.PowerNode;

public class WeavedNode extends PowerNode {
Expand All @@ -15,7 +14,7 @@ public class WeavedNode extends PowerNode {
public WeavedNode(PowerNode parent) {
super("weaved-"+parent.name);
this.parent = parent;
requirements(Category.power, parent.requirements.clone());
BlockHandler.cloneStats(this, parent);
this.maxNodes = parent.maxNodes;
this.init();
}
Expand Down

0 comments on commit 15f31f9

Please sign in to comment.