Skip to content
This repository has been archived by the owner on Mar 1, 2023. It is now read-only.

Commit

Permalink
feat: prevent players from using logic on payload conveyors
Browse files Browse the repository at this point in the history
  • Loading branch information
phinner committed Jan 10, 2023
1 parent 3ad5bb5 commit 195c9b7
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 8 deletions.
19 changes: 12 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,27 @@
[![Build status](https://github.com/Xpdustry/TemplatePlugin/actions/workflows/build.yml/badge.svg?branch=master&event=push)](https://github.com/Xpdustry/TemplatePlugin/actions/workflows/build.yml)
[![Mindustry 7.0 ](https://img.shields.io/badge/Mindustry-7.0-ffd37f)](https://github.com/Anuken/Mindustry/releases)

This plugin prevents players from crashing a server by constantly changing the direction of a payload conveyor router.
This plugin prevents players from crashing a server by constantly changing the direction of a payload conveyor.
It accomplishes this by :

> Unlike this [mod](https://github.com/Agzam4/Mindustry-bugfixes-plugin), this plugin doesn't reload the entire game but
> uses reflection
> to change the broken code. It also preserves the binary compatibility with other plugins.
- Replacing the broken blocks with a patched version using reflection, unlike
this [mod](https://github.com/Agzam4/Mindustry-bugfixes-plugin) that does this by reloading the entire game.

- Preventing players from binding logic processors to payload conveyors.

## Installation

This plugin requires :
### Requirements

- Java 17 or above.

- Mindustry v140 or above.

### Deployment

Download the plugin jar in the [releases](https://github.com/Xpdustry/NoPayloadConveyorCrash/releases) and move it in
the `config/mods` directory of your server.

## Building

- `./gradlew shadowJar` to compile the plugin into a usable jar (will be located
Expand All @@ -25,5 +32,3 @@ This plugin requires :
- `./gradlew jar` for a plain jar that contains only the plugin code.

- `./gradlew runMindustryServer` to run the plugin in a local Mindustry server.

- `./gradlew test` to run the unit tests of the plugin.
2 changes: 1 addition & 1 deletion plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"displayName": "NoPayloadConveyorCrashPlugin",
"author": "Xpdustry",
"description": "No more payload conveyor crashes.",
"version": "1.0.0",
"version": "1.1.0",
"minGameVersion": "140",
"hidden": true,
"java": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,31 @@
*/
package fr.xpdustry.patches;

import arc.Events;
import arc.math.geom.Point2;
import arc.struct.IntSet;
import arc.struct.ObjectMap;
import arc.util.Log;
import arc.util.Strings;
import java.util.function.Consumer;
import java.util.function.Function;
import mindustry.Vars;
import mindustry.content.Blocks;
import mindustry.content.Items;
import mindustry.ctype.MappableContent;
import mindustry.game.EventType;
import mindustry.game.EventType.Trigger;
import mindustry.mod.Plugin;
import mindustry.type.Category;
import mindustry.type.ItemStack;
import mindustry.world.Block;
import mindustry.world.blocks.logic.LogicBlock.LogicBuild;
import mindustry.world.blocks.payloads.PayloadConveyor.PayloadConveyorBuild;

@SuppressWarnings("unused")
public final class NoPayloadConveyorCrashPlugin extends Plugin {

private final IntSet processorIndex = new IntSet();
private final ObjectMap<String, MappableContent>[] contentNameMap;

@SuppressWarnings("unchecked")
Expand Down Expand Up @@ -82,6 +92,8 @@ public void init() {
block.researchCostMultiplier = 4f;
block.underBullets = true;
});

this.setupLogicUnlink();
}

private <T extends Block> void replaceBlock(
Expand Down Expand Up @@ -116,4 +128,40 @@ private <T extends Block> void replaceBlock(
throw new RuntimeException(e);
}
}

private void setupLogicUnlink() {
Events.on(EventType.WorldLoadEvent.class, event -> {
processorIndex.clear();
});

Events.on(EventType.TilePreChangeEvent.class, event -> {
processorIndex.remove(event.tile.pos());
});

Events.on(EventType.TileChangeEvent.class, event -> {
if (event.tile.build instanceof LogicBuild building) {
processorIndex.add(building.pos());
}
});

Events.run(Trigger.update, () -> {
final var iterator = processorIndex.iterator();
while (iterator.hasNext) {
final var position = iterator.next();
if (!(Vars.world.build(position) instanceof final LogicBuild processor)) {
Log.warn(
"[NoPayloadConveyorCrashPlugin] Logic processor at @ is not a LogicBuild instance!",
Point2.unpack(position));
iterator.remove();
continue;
}
for (final var link : processor.links) {
// de-configure the link if it is a payload conveyor
if (link.active && Vars.world.build(link.x, link.y) instanceof PayloadConveyorBuild) {
processor.configure(Point2.pack(link.x, link.y));
}
}
}
});
}
}

0 comments on commit 195c9b7

Please sign in to comment.