Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Agzam4 authored Feb 23, 2023
1 parent fb3cf4b commit 202e3e2
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 58 deletions.
4 changes: 2 additions & 2 deletions plugin.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "Agzam's plugin v1.8.0",
"name": "Agzam's plugin v1.8.1",
"author": "Agzam4",
"main": "example.ExamplePlugin",
"description": "New command, core protection from thorium reactors and more",
"description": "New command, events, core protection from thorium reactors and more",
"version": 1.8
}
4 changes: 2 additions & 2 deletions src/example/ExamplePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ public void registerClientCommands(CommandHandler handler){

handler.<Player>register("plugininfo", "info about pluging", (arg, player) -> {
player.sendMessage(""
+ "[green] Agzam's plugin v1.8.0\n"
+ "[green] Agzam's plugin v1.8.1\n"
+ "[gray]========================================================\n"
+ "[white] Added [royal]skip map[white] commands\n"
+ "[white] Added protection from [violet]thorium reactors[white]\n"
Expand Down Expand Up @@ -817,7 +817,7 @@ public void registerClientCommands(CommandHandler handler){
return;
}

Item item = Items.copper;
Item item = null;

String itemname = arg[0].toLowerCase();

Expand Down
125 changes: 71 additions & 54 deletions src/example/events/LivingWorldEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import mindustry.content.Blocks;
import mindustry.game.EventType.PlayerJoin;
import mindustry.game.EventType.TapEvent;
import mindustry.gen.Building;
import mindustry.gen.Call;
import mindustry.world.Block;
Expand All @@ -11,6 +12,8 @@
import java.util.ArrayList;
import java.util.Random;

import arc.util.Log;

import static mindustry.Vars.*;

public class LivingWorldEvent extends ServerEvent {
Expand All @@ -37,6 +40,23 @@ public void playerJoin(PlayerJoin e) {
e.player.sendMessage("[lime]Руда теперь убегает, окружайте ее блоками, чтобы не дать уйти");
}

@Override
public void tap(TapEvent e) {
Log.info(e.tile);
if(e.tile == null) return;
if(e.tile.overlay() == null) return;
if(e.tile.overlay() == Blocks.air) return;
Log.info(e.tile.overlay());

for (int i = 0; i < oreTiles.size(); i++) {
Point p = oreTiles.get(i);
if(p.x == e.tile.centerX() && p.y == e.tile.centerY()) {
moveOre(i);
break;
}
}
}

int updates = 0;

@Override
Expand All @@ -45,55 +65,7 @@ public void update() {
updates++;

if(updates % 6 == 0 && oreTiles.size() > 0) {
int randomIndex = random.nextInt(oreTiles.size());

Point oreTile = oreTiles.get(randomIndex);

ArrayList<Point> canmove = new ArrayList<>();

for (int i = 0; i < nearTiles.length; i++) {
int x = oreTile.x + nearTiles[i].x;
int y = oreTile.y + nearTiles[i].y;
if(!isInArray(x, y)) continue;
Tile tile = world.tile(x, y);
if(tile == null) continue;
Building building = tile.build;
if(building != null) continue;

boolean checkBlock = false;
if(tile.block() == null) {
checkBlock = true;
} else {
if(tile.block() == Blocks.air) {
checkBlock = true;
}
}
boolean checkOverlay = false;
if(tile.overlay() == null) {
checkOverlay = true;
} else {
if(tile.overlay() == Blocks.air) {
checkOverlay = true;
}
}

if(!checkBlock) continue;
if(!checkOverlay) continue;

canmove.add(new Point(x, y));
}

if(canmove.size() > 0) {
int randomMove = random.nextInt(canmove.size());
Point move = canmove.get(randomMove);

Tile current = world.tile(oreTile.x, oreTile.y);
Tile changed = world.tile(move.x, move.y);
oreTile = move;

changed.setFloorNet(changed.floor(), current.overlay());
current.setFloorNet(current.floor(), Blocks.air);
}
moveOre(random.nextInt(oreTiles.size()));
}

// if(lastWaveId != state.wave) {
Expand Down Expand Up @@ -155,17 +127,62 @@ public void update() {
// }
}

private void moveOre(int index) {
Point oreTile = oreTiles.get(index);

ArrayList<Point> canmove = new ArrayList<>();
Log.info("Move");

for (int i = 0; i < nearTiles.length; i++) {
int x = oreTile.x + nearTiles[i].x;
int y = oreTile.y + nearTiles[i].y;
if(!isInArray(x, y)) continue;
Tile tile = world.tile(x, y);
if(tile == null) continue;
Building building = tile.build;
if(building != null) continue;

boolean checkBlock = false;
if(tile.block() == null) {
checkBlock = true;
} else {
if(tile.block() == Blocks.air) {
checkBlock = true;
}
}

if(!checkBlock) continue;
if(tile.overlay() != Blocks.air) continue;

canmove.add(new Point(x, y));
}

if(canmove.size() > 0) {
int randomMove = random.nextInt(canmove.size());
Point move = canmove.get(randomMove);

Tile current = world.tile(oreTile.x, oreTile.y);
Tile changed = world.tile(move.x, move.y);

oreTiles.remove(index);
oreTiles.add(move);

changed.setFloorNet(changed.floor(), current.overlay());
current.setFloorNet(current.floor(), Blocks.air);
}
}

private static final Point[] nearTiles = {
new Point(+1, +1),
// new Point(+1, +1),
new Point( 0, +1),
new Point(-1, +1),
// new Point(-1, +1),

new Point(+1, 0),
new Point(-1, 0),

new Point(+1, -1),
new Point( 0, -1),
new Point(-1, -1)
// new Point(+1, -1),
new Point( 0, -1)
// new Point(-1, -1)
};

private static final Block[] ores = {
Expand Down

0 comments on commit 202e3e2

Please sign in to comment.