Improved Discord RPC, refactored Input and fixed net crash

This commit is contained in:
Anuken
2018-01-03 20:15:05 -05:00
parent 0063e32f6f
commit 169b9cddc5
29 changed files with 373 additions and 330 deletions

View File

@@ -27,7 +27,7 @@ public class Mindustry extends ModuleCore {
@Override public String format(int number){ return number + ""; }
@Override public void openLink(String link){ }
@Override public void addDialog(TextField field){}
@Override public void onSceneChange(String state, String details, String icon) {}
@Override public void updateRPC() {}
@Override public void onGameExit() {}
@Override public void openDonations() {}
@Override public void requestWritePerms() {}

View File

@@ -299,8 +299,6 @@ public class Control extends Module{
});
Timers.run(18, ()-> ui.hideLoading());
Mindustry.platforms.onSceneChange("Playing on map: " + map.name, "Wave 1", "fight");
}
public GameMode getMode(){
@@ -350,10 +348,9 @@ public class Control extends Module{
int spawnamount = spawn.evaluate(wave, lane);
for(int i = 0; i < spawnamount; i ++){
int index = i;
float range = 12f;
Timers.run(index*5f, ()->{
Timers.run(i*5f, ()->{
Enemy enemy = new Enemy(spawn.type);
enemy.set(tile.worldx() + Mathf.range(range), tile.worldy() + Mathf.range(range));
@@ -383,8 +380,7 @@ public class Control extends Module{
wavetime = waveSpacing();
extrawavetime = maxwavespace;
Mindustry.platforms.onSceneChange("Playing on map: "
+ Vars.world.getMap().name, "Wave " + wave, "fight");
Mindustry.platforms.updateRPC();
}
public void enemyDeath(){
@@ -399,9 +395,7 @@ public class Control extends Module{
Effects.shake(5, 6, Core.camera.position.x, Core.camera.position.y);
Sounds.play("corexplode");
for(int i = 0; i < 16; i ++){
Timers.run(i*2, ()->{
Effects.effect(Fx.explosion, core.worldx()+Mathf.range(40), core.worldy()+Mathf.range(40));
});
Timers.run(i*2, ()-> Effects.effect(Fx.explosion, core.worldx()+Mathf.range(40), core.worldy()+Mathf.range(40)));
}
Effects.effect(Fx.coreexplosion, core.worldx(), core.worldy());
@@ -516,7 +510,9 @@ public class Control extends Module{
Entities.initPhysics();
Entities.setCollider(tilesize, (x, y) -> world.solid(x, y));
Entities.setCollider(tilesize, world::solid);
Mindustry.platforms.updateRPC();
}
@Override

View File

@@ -1,9 +1,17 @@
package io.anuke.mindustry.core;
import io.anuke.mindustry.Mindustry;
import io.anuke.ucore.core.Timers;
public class GameState{
private static State state = State.menu;
public static void set(State astate){
if((astate == State.playing && state == State.menu) || (astate == State.menu && state != State.menu)){
Timers.runTask(5f, Mindustry.platforms::updateRPC);
}
state = astate;
}
@@ -11,7 +19,7 @@ public class GameState{
return state == astate;
}
public static enum State{
public enum State{
paused, playing, menu, dead
}
}

View File

@@ -3,14 +3,13 @@ package io.anuke.mindustry.core;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.utils.TimeUtils;
import com.badlogic.gdx.utils.compression.Lzma;
import com.badlogic.gdx.utils.reflect.ClassReflection;
import com.badlogic.gdx.utils.reflect.ReflectionException;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.entities.Bullet;
import io.anuke.mindustry.entities.BulletType;
import io.anuke.mindustry.entities.Player;
import io.anuke.mindustry.entities.enemies.Enemy;
import io.anuke.mindustry.entities.enemies.EnemyType;
import io.anuke.mindustry.graphics.Fx;
import io.anuke.mindustry.io.NetworkIO;
import io.anuke.mindustry.net.Net;
@@ -178,18 +177,14 @@ public class NetClient extends Module {
Net.handle(EnemySpawnPacket.class, spawn -> {
Gdx.app.postRunnable(() -> {
try{
Enemy enemy = ClassReflection.newInstance(spawn.type);
enemy.set(spawn.x, spawn.y);
enemy.tier = spawn.tier;
enemy.lane = spawn.lane;
enemy.id = spawn.id;
enemy.add();
Enemy enemy = new Enemy(EnemyType.getByID(spawn.type));
enemy.set(spawn.x, spawn.y);
enemy.tier = spawn.tier;
enemy.lane = spawn.lane;
enemy.id = spawn.id;
enemy.add();
Effects.effect(Fx.spawn, enemy);
}catch (ReflectionException e){
throw new RuntimeException(e);
}
Effects.effect(Fx.spawn, enemy);
});
});

View File

@@ -201,7 +201,7 @@ public class NetServer extends Module{
public void handleEnemySpawn(Enemy enemy){
EnemySpawnPacket packet = new EnemySpawnPacket();
packet.type = enemy.getClass();
packet.type = enemy.type.id;
packet.lane = (byte)enemy.lane;
packet.tier = (byte)enemy.tier;
packet.x = enemy.x;

View File

@@ -13,6 +13,7 @@ import io.anuke.mindustry.entities.Player;
import io.anuke.mindustry.entities.enemies.Enemy;
import io.anuke.mindustry.graphics.BlockRenderer;
import io.anuke.mindustry.graphics.Shaders;
import io.anuke.mindustry.input.InputHandler;
import io.anuke.mindustry.input.PlaceMode;
import io.anuke.mindustry.ui.fragments.ToolFragment;
import io.anuke.mindustry.world.SpawnPoint;
@@ -334,11 +335,13 @@ public class Renderer extends RendererModule{
tiley = Mathf.scl2(vec.y, tilesize);
}
InputHandler input = control.getInput();
//draw placement box
if((player.recipe != null && Vars.control.hasItems(player.recipe.requirements) && (!ui.hasMouse() || android)
if((input.recipe != null && Vars.control.hasItems(input.recipe.requirements) && (!ui.hasMouse() || android)
&& control.input.drawPlace())){
player.placeMode.draw(control.input.getBlockX(), control.input.getBlockY(), control.input.getBlockEndX(), control.input.getBlockEndY());
input.placeMode.draw(control.input.getBlockX(), control.input.getBlockY(), control.input.getBlockEndX(), control.input.getBlockEndY());
Draw.thickness(1f);
Draw.color(Color.SCARLET);
@@ -346,11 +349,11 @@ public class Renderer extends RendererModule{
Draw.dashCircle(spawn.start.worldx(), spawn.start.worldy(), enemyspawnspace);
}
if(player.breakMode == PlaceMode.holdDelete)
player.breakMode.draw(tilex, tiley, 0, 0);
if(input.breakMode == PlaceMode.holdDelete)
input.breakMode.draw(tilex, tiley, 0, 0);
}else if(player.breakMode.delete && control.input.drawPlace() && player.recipe == null){ //TODO test!
player.breakMode.draw(control.input.getBlockX(), control.input.getBlockY(),
}else if(input.breakMode.delete && control.input.drawPlace() && input.recipe == null){ //TODO test!
input.breakMode.draw(control.input.getBlockX(), control.input.getBlockY(),
control.input.getBlockEndX(), control.input.getBlockEndY());
}
@@ -362,7 +365,7 @@ public class Renderer extends RendererModule{
Draw.reset();
//draw selected block health
if(player.recipe == null && !ui.hasMouse()){
if(input.recipe == null && !ui.hasMouse()){
Tile tile = world.tile(tilex, tiley);
if(tile != null && tile.block() != Blocks.air){

View File

@@ -1,9 +1,6 @@
package io.anuke.mindustry.core;
import static io.anuke.mindustry.Vars.*;
import com.badlogic.gdx.math.GridPoint2;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.resource.Item;
@@ -22,6 +19,9 @@ import io.anuke.ucore.util.Bundles;
import io.anuke.ucore.util.Mathf;
import io.anuke.ucore.util.Tmp;
import static io.anuke.mindustry.Vars.control;
import static io.anuke.mindustry.Vars.world;
public class Tutorial{
private Stage stage;
private Label info;
@@ -274,7 +274,7 @@ public class Tutorial{
}
void onSwitch(){
Vars.player.recipe = null;
control.getInput().recipe = null;
}
},
drillInfo{
@@ -348,7 +348,8 @@ public class Tutorial{
for(int i = 0; i < 4; i ++){
world.tile(control.core.x + 2, control.core.y - 2 + i).setBlock(DistributionBlocks.conveyor, 1);
}
Vars.player.recipe = null;
control.getInput().recipe = null;
}
},
turretExplanation{

View File

@@ -2,10 +2,8 @@ package io.anuke.mindustry.entities;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.graphics.Fx;
import io.anuke.mindustry.input.PlaceMode;
import io.anuke.mindustry.net.Syncable;
import io.anuke.mindustry.resource.Mech;
import io.anuke.mindustry.resource.Recipe;
import io.anuke.mindustry.resource.Weapon;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.Blocks;
@@ -32,12 +30,6 @@ public class Player extends DestructibleEntity implements Syncable{
public transient int clientid;
public transient boolean isLocal = false;
public transient Interpolator<Player> inter = new Interpolator<>(SyncType.player);
public transient float breaktime = 0;
public transient Recipe recipe;
public transient int placerot;
public transient PlaceMode placeMode = android ? PlaceMode.cursor : PlaceMode.hold;
public transient PlaceMode breakMode = android ? PlaceMode.none : PlaceMode.holdDelete;
public Player(){
hitbox.setSize(5);
@@ -132,7 +124,7 @@ public class Player extends DestructibleEntity implements Syncable{
vector.y += ya*speed;
vector.x += xa*speed;
boolean shooting = !Inputs.keyDown("dash") && Inputs.keyDown("shootInternal") && recipe == null
boolean shooting = !Inputs.keyDown("dash") && Inputs.keyDown("shootInternal") && control.getInput().recipe == null
&& !ui.hasMouse() && !control.getInput().onConfigurable();
if(shooting && Timers.get(this, "reload", weapon.reload)){

View File

@@ -1,11 +1,8 @@
package io.anuke.mindustry.input;
import static io.anuke.mindustry.Vars.*;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.input.GestureDetector;
import com.badlogic.gdx.math.Vector2;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.core.GameState;
import io.anuke.mindustry.core.GameState.State;
@@ -20,6 +17,8 @@ import io.anuke.ucore.scene.ui.layout.Unit;
import io.anuke.ucore.scene.utils.Cursors;
import io.anuke.ucore.util.Mathf;
import static io.anuke.mindustry.Vars.*;
public class AndroidInput extends InputHandler{
public float lmousex, lmousey;
public float mousex, mousey;
@@ -38,7 +37,7 @@ public class AndroidInput extends InputHandler{
@Override public float getCursorEndY(){ return Gdx.input.getY(0); }
@Override public float getCursorX(){ return mousex; }
@Override public float getCursorY(){ return mousey; }
@Override public boolean drawPlace(){ return (placing && !brokeBlock) || (player.placeMode.pan && player.recipe != null); }
@Override public boolean drawPlace(){ return (placing && !brokeBlock) || (placeMode.pan && recipe != null); }
@Override
public boolean touchUp(int screenX, int screenY, int pointer, int button){
@@ -47,10 +46,10 @@ public class AndroidInput extends InputHandler{
return false;
}
if(placing && pointer == 0 && !player.placeMode.pan && !breaking()){
player.placeMode.released(getBlockX(), getBlockY(), getBlockEndX(), getBlockEndY());
}else if(pointer == 0 && !player.breakMode.pan && breaking() && drawPlace()){
player.breakMode.released(getBlockX(), getBlockY(), getBlockEndX(), getBlockEndY());
if(placing && pointer == 0 && !placeMode.pan && !breaking()){
placeMode.released(getBlockX(), getBlockY(), getBlockEndX(), getBlockEndY());
}else if(pointer == 0 && !breakMode.pan && breaking() && drawPlace()){
breakMode.released(getBlockX(), getBlockY(), getBlockEndX(), getBlockEndY());
}
placing = false;
return false;
@@ -64,7 +63,7 @@ public class AndroidInput extends InputHandler{
lmousex = screenX;
lmousey = screenY;
if((!player.placeMode.pan || breaking()) && pointer == 0){
if((!placeMode.pan || breaking()) && pointer == 0){
mousex = screenX;
mousey = screenY;
}
@@ -105,18 +104,18 @@ public class AndroidInput extends InputHandler{
public void breakBlock(){
Tile tile = selected();
player.breaktime += Timers.delta();
breaktime += Timers.delta();
if(player.breaktime >= tile.block().breaktime){
if(breaktime >= tile.block().breaktime){
brokeBlock = true;
breakBlock(tile.x, tile.y, true);
player.breaktime = 0f;
breaktime = 0f;
}
}
@Override
public void update(){
enableHold = player.breakMode == PlaceMode.holdDelete;
enableHold = breakMode == PlaceMode.holdDelete;
float scl = Settings.getInt("sensitivity")/100f * Unit.dp.scl(1f);
float xa = Inputs.getAxis("move_x");
@@ -127,9 +126,9 @@ public class AndroidInput extends InputHandler{
player.x += xa * 4f;
player.y += ya * 4f;
player.placerot += Inputs.getAxis("rotate_alt");
player.placerot += Inputs.getAxis("rotate");
player.placerot = Mathf.mod(player.placerot, 4);
rotation += Inputs.getAxis("rotate_alt");
rotation += Inputs.getAxis("rotate");
rotation = Mathf.mod(rotation, 4);
if(enableHold && Gdx.input.isTouched(0) && Mathf.near2d(lmousex, lmousey, Gdx.input.getX(0), Gdx.input.getY(0), Unit.dp.scl(50))
&& !ui.hasMouse()){
@@ -146,11 +145,11 @@ public class AndroidInput extends InputHandler{
return;
if(warmup > warmupDelay && validBreak(sel.x, sel.y)){
player.breaktime += Timers.delta();
breaktime += Timers.delta();
if(player.breaktime > selected().block().breaktime){
if(breaktime > selected().block().breaktime){
breakBlock();
player.breaktime = 0;
breaktime = 0;
}
}
@@ -158,7 +157,7 @@ public class AndroidInput extends InputHandler{
mousey = ly;
}else{
warmup = 0;
player.breaktime = 0;
breaktime = 0;
mousex = Mathf.clamp(mousex, 0, Gdx.graphics.getWidth());
mousey = Mathf.clamp(mousey, 0, Gdx.graphics.getHeight());
@@ -167,17 +166,17 @@ public class AndroidInput extends InputHandler{
@Override
public boolean tryPlaceBlock(int x, int y, boolean sound){
if(player.recipe != null &&
validPlace(x, y, player.recipe.result) && cursorNear() &&
Vars.control.hasItems(player.recipe.requirements)){
if(recipe != null &&
validPlace(x, y, recipe.result) && cursorNear() &&
Vars.control.hasItems(recipe.requirements)){
placeBlock(x, y, player.recipe.result, player.placerot, true, sound);
placeBlock(x, y, recipe.result, rotation, true, sound);
for(ItemStack stack : player.recipe.requirements){
for(ItemStack stack : recipe.requirements){
Vars.control.removeItem(stack);
}
if(!Vars.control.hasItems(player.recipe.requirements)){
if(!Vars.control.hasItems(recipe.requirements)){
Cursors.restoreCursor();
}
return true;
@@ -186,6 +185,6 @@ public class AndroidInput extends InputHandler{
}
public boolean breaking(){
return player.recipe == null;
return recipe == null;
}
}

View File

@@ -1,10 +1,7 @@
package io.anuke.mindustry.input;
import static io.anuke.mindustry.Vars.*;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.math.Vector2;
import io.anuke.mindustry.core.GameState;
import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.resource.Weapon;
@@ -16,6 +13,8 @@ import io.anuke.ucore.core.Timers;
import io.anuke.ucore.scene.utils.Cursors;
import io.anuke.ucore.util.Mathf;
import static io.anuke.mindustry.Vars.*;
public class DesktopInput extends InputHandler{
int mousex, mousey;
int endx, endy;
@@ -34,14 +33,14 @@ public class DesktopInput extends InputHandler{
if(player.isDead()) return;
if(Inputs.keyRelease("select")){
player.placeMode.released(getBlockX(), getBlockY(), getBlockEndX(), getBlockEndY());
placeMode.released(getBlockX(), getBlockY(), getBlockEndX(), getBlockEndY());
}
if(Inputs.keyRelease("break") && !beganBreak){
player.breakMode.released(getBlockX(), getBlockY(), getBlockEndX(), getBlockEndY());
breakMode.released(getBlockX(), getBlockY(), getBlockEndX(), getBlockEndY());
}
if((Inputs.keyTap("select") && player.recipe != null) || Inputs.keyTap("break")){
if((Inputs.keyTap("select") && recipe != null) || Inputs.keyTap("break")){
Vector2 vec = Graphics.world(Gdx.input.getX(), Gdx.input.getY());
mousex = (int)vec.x;
mousey = (int)vec.y;
@@ -60,23 +59,23 @@ public class DesktopInput extends InputHandler{
}
if(!rotated) {
player.placerot += Inputs.getAxis("rotate_alt");
rotation += Inputs.getAxis("rotate_alt");
rotated = true;
}
if(!Inputs.getAxisActive("rotate_alt")) rotated = false;
if(!rotatedAlt) {
player.placerot += Inputs.getAxis("rotate");
rotation += Inputs.getAxis("rotate");
rotatedAlt = true;
}
if(!Inputs.getAxisActive("rotate")) rotatedAlt = false;
player.placerot = Mathf.mod(player.placerot, 4);
rotation = Mathf.mod(rotation, 4);
if(Inputs.keyDown("break")){
player.breakMode = PlaceMode.areaDelete;
breakMode = PlaceMode.areaDelete;
}else{
player.breakMode = PlaceMode.hold;
breakMode = PlaceMode.hold;
}
for(int i = 1; i <= 6 && i <= control.getWeapons().size; i ++){
@@ -105,41 +104,41 @@ public class DesktopInput extends InputHandler{
beganBreak = false;
}
if(player.recipe != null && Inputs.keyTap("break")){
if(recipe != null && Inputs.keyTap("break")){
beganBreak = true;
player.recipe = null;
recipe = null;
Cursors.restoreCursor();
}
//block breaking
if(enableHold && Inputs.keyDown("break") && cursor != null && validBreak(tilex(), tiley())){
player.breaktime += Timers.delta();
if(player.breaktime >= cursor.getBreakTime()){
breaktime += Timers.delta();
if(breaktime >= cursor.getBreakTime()){
breakBlock(cursor.x, cursor.y, true);
player.breaktime = 0f;
breaktime = 0f;
}
}else{
player.breaktime = 0f;
breaktime = 0f;
}
}
public int tilex(){
return (player.recipe != null && player.recipe.result.isMultiblock() &&
player.recipe.result.width % 2 == 0) ?
return (recipe != null && recipe.result.isMultiblock() &&
recipe.result.width % 2 == 0) ?
Mathf.scl(Graphics.mouseWorld().x, tilesize) : Mathf.scl2(Graphics.mouseWorld().x, tilesize);
}
public int tiley(){
return (player.recipe != null && player.recipe.result.isMultiblock() &&
player.recipe.result.height % 2 == 0) ?
return (recipe != null && recipe.result.isMultiblock() &&
recipe.result.height % 2 == 0) ?
Mathf.scl(Graphics.mouseWorld().y, tilesize) : Mathf.scl2(Graphics.mouseWorld().y, tilesize);
}
public int currentWeapon(){
int i = 0;
for(Weapon weapon : control.getWeapons()){
if(player.weapon == weapon)
if(weapon == weapon)
return i;
i ++;
}

View File

@@ -31,14 +31,14 @@ public class GestureHandler extends GestureAdapter{
public boolean tap (float x, float y, int count, int button) {
if(ui.hasMouse() || input.brokeBlock) return false;
if(!player.placeMode.pan || player.recipe == null){
if(!control.getInput().placeMode.pan || control.getInput().recipe == null){
input.mousex = x;
input.mousey = y;
if(player.recipe == null)
player.breakMode.tapped(input.getBlockX(), input.getBlockY());
if(control.getInput().recipe == null)
control.getInput().breakMode.tapped(input.getBlockX(), input.getBlockY());
else
player.placeMode.tapped(input.getBlockX(), input.getBlockY());
control.getInput().placeMode.tapped(input.getBlockX(), input.getBlockY());
}
return false;
}
@@ -47,13 +47,13 @@ public class GestureHandler extends GestureAdapter{
public boolean pan(float x, float y, float deltaX, float deltaY){
if(Vars.control.showCursor() && !Inputs.keyDown("select")) return false;
if(!Vars.control.showCursor() && !(player.recipe != null && Vars.control.hasItems(player.recipe.requirements) && player.placeMode.lockCamera) &&
!(player.recipe == null && player.breakMode.lockCamera)){
if(!Vars.control.showCursor() && !(control.getInput().recipe != null && Vars.control.hasItems(control.getInput().recipe.requirements) && control.getInput().placeMode.lockCamera) &&
!(control.getInput().recipe == null && control.getInput().breakMode.lockCamera)){
float dx = deltaX*Core.camera.zoom/Core.cameraScale, dy = deltaY*Core.camera.zoom/Core.cameraScale;
player.x -= dx;
player.y += dy;
player.targetAngle = Mathf.atan2(dx, -dy);
}else if(player.placeMode.lockCamera && (player.placeMode.pan && player.recipe != null)){
}else if(control.getInput().placeMode.lockCamera && (control.getInput().placeMode.pan && control.getInput().recipe != null)){
input.mousex += deltaX;
input.mousey += deltaY;
}
@@ -63,7 +63,7 @@ public class GestureHandler extends GestureAdapter{
@Override
public boolean pinch (Vector2 initialPointer1, Vector2 initialPointer2, Vector2 pointer1, Vector2 pointer2) {
if(player.recipe == null && !player.breakMode.lockCamera)
if(control.getInput().recipe == null && !control.getInput().breakMode.lockCamera)
return false;
if(pinch1.x < 0){

View File

@@ -28,6 +28,12 @@ import io.anuke.ucore.util.Tmp;
import static io.anuke.mindustry.Vars.*;
public abstract class InputHandler extends InputAdapter{
public float breaktime = 0;
public Recipe recipe;
public int rotation;
public PlaceMode placeMode = android ? PlaceMode.cursor : PlaceMode.hold;
public PlaceMode breakMode = android ? PlaceMode.none : PlaceMode.holdDelete;
public abstract void update();
public abstract float getCursorX();
public abstract float getCursorY();
@@ -50,17 +56,17 @@ public abstract class InputHandler extends InputAdapter{
}
public boolean tryPlaceBlock(int x, int y, boolean sound){
if(player.recipe != null &&
validPlace(x, y, player.recipe.result) && !ui.hasMouse() && cursorNear() &&
Vars.control.hasItems(player.recipe.requirements)){
if(recipe != null &&
validPlace(x, y, recipe.result) && !ui.hasMouse() && cursorNear() &&
Vars.control.hasItems(recipe.requirements)){
placeBlock(x, y, player.recipe.result, player.placerot, true, sound);
placeBlock(x, y, recipe.result, rotation, true, sound);
for(ItemStack stack : player.recipe.requirements){
for(ItemStack stack : recipe.requirements){
Vars.control.removeItem(stack);
}
if(!Vars.control.hasItems(player.recipe.requirements)){
if(!Vars.control.hasItems(recipe.requirements)){
Cursors.restoreCursor();
}
return true;
@@ -77,7 +83,7 @@ public abstract class InputHandler extends InputAdapter{
}
public boolean round2(){
return !(player.recipe != null && player.recipe.result.isMultiblock() && player.recipe.result.height % 2 == 0);
return !(recipe != null && recipe.result.isMultiblock() && recipe.result.height % 2 == 0);
}
public boolean validPlace(int x, int y, Block type){
@@ -116,7 +122,7 @@ public abstract class InputHandler extends InputAdapter{
Block block = Vars.control.getTutorial().getPlaceBlock();
if(type != block || point.x != x - control.getCore().x || point.y != y - control.getCore().y
|| (rotation != -1 && rotation != Vars.player.placerot)){
|| (rotation != -1 && rotation != this.rotation)){
return false;
}
}else if(Vars.control.getTutorial().active()){
@@ -160,7 +166,7 @@ public abstract class InputHandler extends InputAdapter{
Block block = Vars.control.getTutorial().getPlaceBlock();
if(block != Blocks.air || point.x != x - control.getCore().x || point.y != y - control.getCore().y
|| (rotation != -1 && rotation != Vars.player.placerot)){
|| (rotation != -1 && rotation != this.rotation)){
return false;
}
}else{

View File

@@ -1,14 +1,11 @@
package io.anuke.mindustry.input;
import static io.anuke.mindustry.Vars.*;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input.Buttons;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Colors;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Vector2;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.ui.fragments.ToolFragment;
import io.anuke.mindustry.world.Block;
@@ -20,6 +17,8 @@ import io.anuke.ucore.scene.utils.Cursors;
import io.anuke.ucore.util.Mathf;
import io.anuke.ucore.util.Tmp;
import static io.anuke.mindustry.Vars.*;
public enum PlaceMode{
cursor{
{
@@ -32,23 +31,23 @@ public enum PlaceMode{
float x = tilex * Vars.tilesize;
float y = tiley * Vars.tilesize;
boolean valid = control.getInput().validPlace(tilex, tiley, player.recipe.result) && (android || control.getInput().cursorNear());
boolean valid = control.getInput().validPlace(tilex, tiley, control.getInput().recipe.result) && (android || control.getInput().cursorNear());
Vector2 offset = player.recipe.result.getPlaceOffset();
Vector2 offset = control.getInput().recipe.result.getPlaceOffset();
float si = MathUtils.sin(Timers.time() / 6f) + 1.5f;
Draw.color(valid ? Colors.get("place") : Colors.get("placeInvalid"));
Draw.thickness(2f);
Draw.linecrect(x + offset.x, y + offset.y, tilesize * player.recipe.result.width + si,
tilesize * player.recipe.result.height + si);
Draw.linecrect(x + offset.x, y + offset.y, tilesize * control.getInput().recipe.result.width + si,
tilesize * control.getInput().recipe.result.height + si);
player.recipe.result.drawPlace(tilex, tiley, player.placerot, valid);
control.getInput().recipe.result.drawPlace(tilex, tiley, control.getInput().rotation, valid);
Draw.thickness(2f);
if(player.recipe.result.rotate){
if(control.getInput().recipe.result.rotate){
Draw.color(Colors.get("placeRotate"));
Tmp.v1.set(7, 0).rotate(player.placerot * 90);
Tmp.v1.set(7, 0).rotate(control.getInput().rotation * 90);
Draw.line(x, y, x + Tmp.v1.x, y + Tmp.v1.y);
}
@@ -95,12 +94,12 @@ public enum PlaceMode{
if(tile.isLinked())
tile = tile.getLinked();
Vector2 offset = tile.block().getPlaceOffset();
float fract = player.breaktime / tile.getBreakTime();
float fract = control.getInput().breaktime / tile.getBreakTime();
if(Inputs.buttonDown(Buttons.RIGHT)){
Draw.color(Color.YELLOW, Color.SCARLET, fract);
Draw.linecrect(tile.worldx() + offset.x, tile.worldy() + offset.y, tile.block().width * Vars.tilesize, tile.block().height * Vars.tilesize);
}else if(android && player.breaktime > 0){
}else if(android && control.getInput().breaktime > 0){
Draw.color(Colors.get("breakStart"), Colors.get("break"), fract);
Draw.polygon(25, tile.worldx() + offset.x, tile.worldy() + offset.y, 4 + (1f - fract) * 26);
}
@@ -254,7 +253,7 @@ public enum PlaceMode{
}
float t = Vars.tilesize;
Block block = player.recipe.result;
Block block = control.getInput().recipe.result;
Vector2 offset = block.getPlaceOffset();
process(tilex, tiley, endx, endy);
@@ -296,15 +295,15 @@ public enum PlaceMode{
int px = tx + cx * Mathf.sign(ex - tx),
py = ty + cy * Mathf.sign(ey - ty);
if(!control.getInput().validPlace(px, py, player.recipe.result)
|| !control.hasItems(player.recipe.requirements, amount)){
if(!control.getInput().validPlace(px, py, control.getInput().recipe.result)
|| !control.hasItems(control.getInput().recipe.requirements, amount)){
Draw.linecrect(px * t + offset.x, py * t + offset.y, t*block.width, t*block.height);
}
amount ++;
}
}
if(player.recipe.result.rotate){
if(control.getInput().recipe.result.rotate){
float cx = tx * t, cy = ty * t;
Draw.color(Colors.get("placeRotate"));
Tmp.v1.set(7, 0).rotate(rotation * 90);
@@ -317,7 +316,7 @@ public enum PlaceMode{
public void released(int tilex, int tiley, int endx, int endy){
process(tilex, tiley, endx, endy);
player.placerot = this.rotation;
control.getInput().rotation = this.rotation;
boolean first = true;
for(int x = 0; x <= Math.abs(this.endx - this.tilex); x ++){
@@ -356,7 +355,7 @@ public enum PlaceMode{
else if(endy < tiley)
rotation = 3;
else
rotation = player.placerot;
rotation = control.getInput().rotation;
if(endx < tilex){
int t = endx;

View File

@@ -9,7 +9,7 @@ public interface PlatformFunction{
public String format(int number);
public void openLink(String link);
public void addDialog(TextField field);
public void onSceneChange(String state, String details, String icon);
public void updateRPC();
public void onGameExit();
public void openDonations();
public void requestWritePerms();

View File

@@ -265,7 +265,7 @@ public class Save12 extends SaveFileVersion {
stream.writeInt(tile.block().id); //block ID
if(tile.entity != null){
stream.writeByte(tile.getRotation()); //placerot
stream.writeByte(tile.getRotation()); //rotation
stream.writeInt(tile.entity.health); //health
int amount = 0;
for(int i = 0; i < tile.entity.items.length; i ++){

View File

@@ -293,7 +293,7 @@ public class Save13 extends SaveFileVersion {
if(tile.block() instanceof BlockPart) stream.writeByte(tile.link);
if(tile.entity != null){
stream.writeByte(tile.getRotation()); //placerot
stream.writeByte(tile.getRotation()); //rotation
stream.writeShort(tile.entity.health); //health
byte amount = 0;
for(int i = 0; i < tile.entity.items.length; i ++){

View File

@@ -322,7 +322,7 @@ public class Save14 extends SaveFileVersion{
if(tile.block() instanceof BlockPart) stream.writeByte(tile.link);
if(tile.entity != null){
stream.writeByte(tile.getRotation()); //placerot
stream.writeByte(tile.getRotation()); //rotation
stream.writeShort(tile.entity.health); //health
byte amount = 0;
for(int i = 0; i < tile.entity.items.length; i ++){

View File

@@ -6,9 +6,11 @@ import com.badlogic.gdx.utils.IntArray;
import com.badlogic.gdx.utils.IntMap;
import com.badlogic.gdx.utils.ObjectMap;
import com.badlogic.gdx.utils.async.AsyncExecutor;
import io.anuke.mindustry.Mindustry;
import io.anuke.mindustry.net.Streamable.StreamBegin;
import io.anuke.mindustry.net.Streamable.StreamBuilder;
import io.anuke.mindustry.net.Streamable.StreamChunk;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.function.Consumer;
import java.io.IOException;
@@ -31,6 +33,8 @@ public class Net{
clientProvider.connect(ip, port);
active = true;
server = false;
Timers.runTask(60f, Mindustry.platforms::updateRPC);
}
/**Host a server at an address*/
@@ -38,6 +42,8 @@ public class Net{
serverProvider.host(port);
active = true;
server = true;
Timers.runTask(60f, Mindustry.platforms::updateRPC);
}
/**Closes the server.*/

View File

@@ -1,7 +1,6 @@
package io.anuke.mindustry.net;
import io.anuke.mindustry.entities.Player;
import io.anuke.mindustry.entities.enemies.Enemy;
/**Class for storing all packets.*/
public class Packets {
@@ -86,8 +85,7 @@ public class Packets {
}
public static class EnemySpawnPacket{
public Class<? extends Enemy> type;
public byte lane, tier;
public byte type, lane, tier;
public float x, y;
public int id;
}

View File

@@ -1,40 +1,34 @@
package io.anuke.mindustry.ui.fragments;
import static io.anuke.mindustry.Vars.*;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Colors;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.Interpolation;
import com.badlogic.gdx.utils.Align;
import com.badlogic.gdx.utils.Array;
import io.anuke.mindustry.Mindustry;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.core.GameState;
import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.input.InputHandler;
import io.anuke.mindustry.resource.Item;
import io.anuke.mindustry.resource.ItemStack;
import io.anuke.mindustry.resource.Recipe;
import io.anuke.mindustry.resource.Section;
import io.anuke.mindustry.ui.FloatingDialog;
import io.anuke.ucore.UCore;
import io.anuke.ucore.core.Core;
import io.anuke.ucore.core.Draw;
import io.anuke.ucore.graphics.Hue;
import io.anuke.ucore.scene.actions.Actions;
import io.anuke.ucore.scene.builders.button;
import io.anuke.ucore.scene.builders.imagebutton;
import io.anuke.ucore.scene.builders.table;
import io.anuke.ucore.scene.event.Touchable;
import io.anuke.ucore.scene.ui.*;
import io.anuke.ucore.scene.ui.layout.Stack;
import io.anuke.ucore.scene.ui.layout.Table;
import io.anuke.ucore.scene.ui.layout.Value;
import io.anuke.ucore.util.Bundles;
import io.anuke.ucore.util.Mathf;
import io.anuke.ucore.util.Strings;
import static io.anuke.mindustry.Vars.control;
import static io.anuke.mindustry.Vars.fontscale;
public class BlocksFragment implements Fragment{
private Table desctable, itemtable, blocks;
private Stack stack = new Stack();
@@ -42,6 +36,7 @@ public class BlocksFragment implements Fragment{
private boolean shown = true;
public void build(){
InputHandler input = control.getInput();
new table(){{
abottom();
@@ -52,12 +47,12 @@ public class BlocksFragment implements Fragment{
blocks = new table(){{
itemtable = new Table("button");
itemtable.setVisible(() -> player.recipe == null);
itemtable.setVisible(() -> input.recipe == null);
desctable = new Table("button");
desctable.setVisible(() -> player.recipe != null);
desctable.setVisible(() -> input.recipe != null);
desctable.update(() -> {
if(player.recipe == null && desctable.getChildren().size != 0){
if(input.recipe == null && desctable.getChildren().size != 0){
desctable.clear();
}
});
@@ -93,8 +88,8 @@ public class BlocksFragment implements Fragment{
ImageButton button = new ImageButton("icon-" + sec.name(), "toggle");
button.clicked(() -> {
if (!table.isVisible() && player.recipe != null) {
player.recipe = null;
if (!table.isVisible() && input.recipe != null) {
input.recipe = null;
}
});
button.setName("sectionbutton" + sec.name());
@@ -117,10 +112,10 @@ public class BlocksFragment implements Fragment{
ImageButton image = new ImageButton(region, "select");
image.clicked(() -> {
if (player.recipe == r) {
player.recipe = null;
if (input.recipe == r) {
input.recipe = null;
} else {
player.recipe = r;
input.recipe = r;
updateRecipe();
}
});
@@ -131,7 +126,7 @@ public class BlocksFragment implements Fragment{
image.update(() -> {
boolean canPlace = !control.getTutorial().active() || control.getTutorial().canPlace();
boolean has = (control.hasItems(r.requirements)) && canPlace;
image.setChecked(player.recipe == r);
image.setChecked(input.recipe == r);
image.setTouchable(canPlace ? Touchable.enabled : Touchable.disabled);
image.getImage().setColor(has ? Color.WHITE : Hue.lightness(0.33f));
});
@@ -174,7 +169,7 @@ public class BlocksFragment implements Fragment{
}
void updateRecipe(){
Recipe recipe = player.recipe;
Recipe recipe = Vars.control.getInput().recipe;
desctable.clear();
desctable.setTouchable(Touchable.enabled);

View File

@@ -1,161 +1,161 @@
package io.anuke.mindustry.ui.fragments;
import static io.anuke.mindustry.Vars.*;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.math.Interpolation;
import com.badlogic.gdx.utils.Align;
import io.anuke.mindustry.core.GameState;
import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.input.InputHandler;
import io.anuke.mindustry.input.PlaceMode;
import io.anuke.ucore.core.Core;
import io.anuke.ucore.scene.actions.Actions;
import io.anuke.ucore.scene.builders.*;
import io.anuke.ucore.scene.builders.imagebutton;
import io.anuke.ucore.scene.builders.table;
import io.anuke.ucore.scene.event.Touchable;
import io.anuke.ucore.scene.ui.ButtonGroup;
import io.anuke.ucore.scene.ui.ImageButton;
import io.anuke.ucore.scene.ui.layout.Table;
import io.anuke.ucore.util.Mathf;
import static io.anuke.mindustry.Vars.control;
public class PlacementFragment implements Fragment{
boolean shown = false;
Table breaktable, next;
public void build(){
if(android){
InputHandler input = control.getInput();
float s = 50f;
float s = 50f;
new table(){{
visible(() -> !GameState.is(State.menu));
abottom();
aleft();
ButtonGroup<ImageButton> placeGroup = new ButtonGroup<>();
ButtonGroup<ImageButton> breakGroup = new ButtonGroup<>();
update(t -> {
if(!input.placeMode.delete){
placeGroup.setMinCheckCount(1);
for(ImageButton button : placeGroup.getButtons()){
if(button.getName().equals(input.placeMode.name())){
button.setChecked(true);
break;
}
}
}else{
placeGroup.setMinCheckCount(0);
for(ImageButton button : placeGroup.getButtons())
button.setChecked(false);
}
if(input.placeMode.delete || input.breakMode.both){
PlaceMode mode = input.breakMode;
breakGroup.setMinCheckCount(1);
for(ImageButton button : breakGroup.getButtons()){
if(button.getName().equals(mode.name())){
button.setChecked(true);
break;
}
}
}else{
breakGroup.setMinCheckCount(0);
for(ImageButton button : breakGroup.getButtons())
button.setChecked(false);
}
});
new table(){{
visible(() -> !GameState.is(State.menu));
visible(() -> input.recipe != null);
touchable(Touchable.enabled);
aleft();
new table("pane"){{
margin(5f);
aleft();
defaults().size(s, s + 4).padBottom(-5.5f);
Color color = Color.GRAY;
new imagebutton("icon-cancel", 14*3, ()->{
input.recipe = null;
}).imageColor(color)
.visible(()->input.recipe != null);
for(PlaceMode mode : PlaceMode.values()){
if(!mode.shown || mode.delete) continue;
new imagebutton("icon-" + mode.name(), "toggle", 10*3, ()->{
control.getInput().resetCursor();
input.placeMode = mode;
}).group(placeGroup).get().setName(mode.name());
}
new imagebutton("icon-arrow", 14*3, ()->{
input.rotation = Mathf.mod(input.rotation + 1, 4);
}).imageColor(color).visible(() -> input.recipe != null).update(image ->{
image.getImage().setRotation(input.rotation *90);
image.getImage().setOrigin(Align.center);
});
}}.padBottom(-5).left().end();
}}.left().end();
row();
new table(){{
abottom();
aleft();
ButtonGroup<ImageButton> placeGroup = new ButtonGroup<>();
ButtonGroup<ImageButton> breakGroup = new ButtonGroup<>();
height(s+5+4);
update(t -> {
next = new table("pane"){{
margin(5f);
if(!player.placeMode.delete){
placeGroup.setMinCheckCount(1);
for(ImageButton button : placeGroup.getButtons()){
if(button.getName().equals(player.placeMode.name())){
button.setChecked(true);
break;
}
}
}else{
placeGroup.setMinCheckCount(0);
for(ImageButton button : placeGroup.getButtons())
button.setChecked(false);
}
defaults().padBottom(-5.5f);
if(player.placeMode.delete || player.breakMode.both){
PlaceMode mode = player.breakMode;
breakGroup.setMinCheckCount(1);
for(ImageButton button : breakGroup.getButtons()){
if(button.getName().equals(mode.name())){
button.setChecked(true);
break;
}
}
}else{
breakGroup.setMinCheckCount(0);
for(ImageButton button : breakGroup.getButtons())
button.setChecked(false);
}
});
new imagebutton("icon-arrow-right", 10 * 3, () -> {
toggle(!shown);
}).update(l -> l.getStyle().imageUp = Core.skin.getDrawable(shown ? "icon-arrow-left" : "icon-" + input.breakMode.name())).size(s, s+4);
new table(){{
visible(() -> player.recipe != null);
}}.end().get();
breaktable = new table("pane"){{
visible(() -> shown);
margin(5f);
marginLeft(0f);
touchable(Touchable.enabled);
aleft();
new table("pane"){{
margin(5f);
aleft();
defaults().size(s, s+4);
defaults().size(s, s + 4).padBottom(-5.5f);
for(PlaceMode mode : PlaceMode.values()){
if(!mode.shown || !mode.delete) continue;
Color color = Color.GRAY;
defaults().padBottom(-5.5f);
new imagebutton("icon-cancel", 14*3, ()->{
player.recipe = null;
}).imageColor(color)
.visible(()->player.recipe != null);
new imagebutton("icon-" + mode.name(), "toggle", 10*3, ()->{
control.getInput().resetCursor();
input.breakMode = mode;
if(!mode.both) input.placeMode = mode;
}).group(breakGroup).get().setName(mode.name());
}
for(PlaceMode mode : PlaceMode.values()){
if(!mode.shown || mode.delete) continue;
}}.end().get();
new imagebutton("icon-" + mode.name(), "toggle", 10*3, ()->{
control.getInput().resetCursor();
player.placeMode = mode;
}).group(placeGroup).get().setName(mode.name());
}
breaktable.getParent().swapActor(breaktable, next);
new imagebutton("icon-arrow", 14*3, ()->{
player.placerot = Mathf.mod(player.placerot + 1, 4);
}).imageColor(color).visible(() -> player.recipe != null).update(image ->{
image.getImage().setRotation(player.placerot *90);
image.getImage().setOrigin(Align.center);
});
breaktable.getTranslation().set(-breaktable.getPrefWidth(), 0);
}}.padBottom(-5).left().end();
}}.left().end();
}}.end().get();
row();
new table(){{
abottom();
aleft();
height(s+5+4);
next = new table("pane"){{
margin(5f);
defaults().padBottom(-5.5f);
new imagebutton("icon-arrow-right", 10 * 3, () -> {
toggle(!shown);
}).update(l -> l.getStyle().imageUp = Core.skin.getDrawable(shown ? "icon-arrow-left" : "icon-" + player.breakMode.name())).size(s, s+4);
}}.end().get();
breaktable = new table("pane"){{
visible(() -> shown);
margin(5f);
marginLeft(0f);
touchable(Touchable.enabled);
aleft();
defaults().size(s, s+4);
for(PlaceMode mode : PlaceMode.values()){
if(!mode.shown || !mode.delete) continue;
defaults().padBottom(-5.5f);
new imagebutton("icon-" + mode.name(), "toggle", 10*3, ()->{
control.getInput().resetCursor();
player.breakMode = mode;
if(!mode.both) player.placeMode = mode;
}).group(breakGroup).get().setName(mode.name());
}
}}.end().get();
breaktable.getParent().swapActor(breaktable, next);
breaktable.getTranslation().set(-breaktable.getPrefWidth(), 0);
}}.end().get();
}}.end();
}
}}.end();
}
private void toggle(boolean show){

View File

@@ -1,56 +1,58 @@
package io.anuke.mindustry.ui.fragments;
import static io.anuke.mindustry.Vars.*;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Align;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.core.GameState;
import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.input.InputHandler;
import io.anuke.mindustry.input.PlaceMode;
import io.anuke.ucore.core.Core;
import io.anuke.ucore.core.Graphics;
import io.anuke.ucore.scene.ui.layout.Table;
import static io.anuke.mindustry.Vars.*;
public class ToolFragment implements Fragment{
private Table tools;
public int px, py, px2, py2;
public boolean confirming;
public void build(){
InputHandler input = control.getInput();
float isize = 14*3;
tools = new Table();
tools.addIButton("icon-cancel", isize, () -> {
if(player.placeMode == PlaceMode.areaDelete && confirming){
if(input.placeMode == PlaceMode.areaDelete && confirming){
confirming = false;
}else{
player.recipe = null;
input.recipe = null;
}
});
tools.addIButton("icon-rotate", isize, () -> {
player.placerot++;
player.placerot %= 4;
input.rotation++;
input.rotation %= 4;
});
tools.addIButton("icon-check", isize, () -> {
if(player.placeMode == PlaceMode.areaDelete && confirming){
player.placeMode.released(px, py, px2, py2);
if(input.placeMode == PlaceMode.areaDelete && confirming){
input.placeMode.released(px, py, px2, py2);
confirming = false;
}else{
player.placeMode.tapped(control.getInput().getBlockX(), control.getInput().getBlockY());
input.placeMode.tapped(control.getInput().getBlockX(), control.getInput().getBlockY());
}
});
Core.scene.add(tools);
tools.setVisible(() ->
!GameState.is(State.menu) && android && ((player.recipe != null && control.hasItems(player.recipe.requirements) &&
player.placeMode == PlaceMode.cursor) || confirming)
!GameState.is(State.menu) && android && ((input.recipe != null && control.hasItems(input.recipe.requirements) &&
input.placeMode == PlaceMode.cursor) || confirming)
);
tools.update(() -> {
@@ -63,7 +65,7 @@ public class ToolFragment implements Fragment{
Gdx.graphics.getHeight() - control.getInput().getCursorY() - 15*Core.cameraScale, Align.top);
}
if(player.placeMode != PlaceMode.areaDelete){
if(input.placeMode != PlaceMode.areaDelete){
confirming = false;
}
});

View File

@@ -227,7 +227,7 @@ public class Block{
}
public void draw(Tile tile){
//note: multiblocks do not support placerot
//note: multiblocks do not support rotation
if(!isMultiblock()){
Draw.rect(variants > 0 ? (name() + Mathf.randomSeed(tile.id(), 1, variants)) : name(),
tile.worldx(), tile.worldy(), rotate ? tile.getRotation() * 90 : 0);

View File

@@ -16,7 +16,7 @@ public class Tile{
/**Packed block data. Left is floor, right is block.*/
private short blocks;
/**Packed data. Left is placerot, right is extra data, packed into two half-bytes: left is dump, right is extra.*/
/**Packed data. Left is rotation, right is extra data, packed into two half-bytes: left is dump, right is extra.*/
private short data;
/**The coordinates of the core tile this is linked to, in the form of two bytes packed into one.
* This is relative to the block it is linked to; negate coords to find the link.*/
@@ -56,7 +56,7 @@ public class Tile{
return Bits.getLeftByte(blocks);
}
/**Return relative placerot to a coordinate. Returns -1 if the coordinate is not near this tile.*/
/**Return relative rotation to a coordinate. Returns -1 if the coordinate is not near this tile.*/
public int relativeTo(int cx, int cy){
if(x == cx && y == cy - 1) return 1;
if(x == cx && y == cy + 1) return 3;

View File

@@ -1,14 +1,11 @@
package io.anuke.mindustry.world.blocks;
import io.anuke.mindustry.entities.TileEntity;
import io.anuke.mindustry.graphics.Fx;
import io.anuke.mindustry.resource.Item;
import io.anuke.mindustry.resource.Liquid;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.types.defense.CoreBlock;
import io.anuke.mindustry.world.blocks.types.production.*;
import io.anuke.ucore.core.Effects;
public class ProductionBlocks{
public static final Block
@@ -152,32 +149,8 @@ public class ProductionBlocks{
}
},
omnidrill = new Drill("omnidrill"){
{
drillEffect = Fx.sparkbig;
resource = null;
result = null;
time = 3;
}
@Override
public void update(Tile tile){
TileEntity entity = tile.entity;
omnidrill = new Omnidrill("omnidrill"){
if(tile.floor().drops != null && entity.timer.get(timerDrill, 60 * time)){
offloadNear(tile, tile.floor().drops.item);
Effects.effect(drillEffect, tile.worldx(), tile.worldy());
}
if(entity.timer.get(timerDump, 30)){
tryDump(tile);
}
}
@Override
public boolean isLayer(Tile tile){
return tile.floor().drops == null;
}
},
coalgenerator = new ItemPowerGenerator("coalgenerator"){
{

View File

@@ -0,0 +1,59 @@
package io.anuke.mindustry.world.blocks.types.production;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import io.anuke.mindustry.entities.TileEntity;
import io.anuke.mindustry.graphics.Fx;
import io.anuke.mindustry.resource.Item;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.Tile;
import io.anuke.ucore.core.Draw;
import io.anuke.ucore.core.Effects;
import io.anuke.ucore.util.Tmp;
public class Omnidrill extends Drill {
public Omnidrill(String name){
super(name);
drillEffect = Fx.sparkbig;
resource = null;
result = null;
time = 3;
}
@Override
public void draw(Tile tile){
super.draw(tile);
if(tile.floor().drops == null) return;
Item item = tile.floor().drops.item;
TextureRegion region = Draw.region("icon-" + item.name);
Tmp.tr1.setRegion(region, 4, 4, 1, 1);
Draw.rect(Tmp.tr1, tile.worldx(), tile.worldy(), 2f, 2f);
}
@Override
public boolean canReplace(Block other) {
return other instanceof Drill && other != this;
}
@Override
public void update(Tile tile){
TileEntity entity = tile.entity;
if(tile.floor().drops != null && entity.timer.get(timerDrill, 60 * time)){
offloadNear(tile, tile.floor().drops.item);
Effects.effect(drillEffect, tile.worldx(), tile.worldy());
}
if(entity.timer.get(timerDump, 30)){
tryDump(tile);
}
}
@Override
public boolean isLayer(Tile tile){
return tile.floor().drops == null;
}
}