New ItemTransfer entity

This commit is contained in:
Anuken 2018-05-21 11:25:41 -04:00
parent 468a6c1dca
commit 8f137eadf0
3 changed files with 34 additions and 7 deletions

View File

@ -1,28 +1,55 @@
package io.anuke.mindustry.entities;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Pools;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.type.Item;
import io.anuke.ucore.entities.Entity;
import io.anuke.ucore.entities.TimedEntity;
import io.anuke.ucore.function.Callable;
import io.anuke.ucore.util.Position;
public class ItemTransfer extends TimedEntity{
private Vector2 from = new Vector2();
private Vector2 current = new Vector2();
private Vector2 tovec = new Vector2();
private Item item;
private Position to;
private Callable done;
public static void create(Item item, float fromx, float fromy, float tox, float toy, Callable done){
public static void create(Item item, float fromx, float fromy, Position to, Callable done){
ItemTransfer tr = Pools.obtain(ItemTransfer.class);
tr.item = item;
tr.from.set(fromx, fromy);
tr.to = to;
tr.done = done;
tr.lifetime = 60f;
tr.add();
}
private ItemTransfer(){}
@Override
public void reset() {
super.reset();
item = null;
to = null;
done = null;
from.setZero();
current.setZero();
tovec.setZero();
}
@Override
public void removed() {
super.removed();
Pools.free(this);
}
@Override
public void update() {
super.update();
current.set(from).lerp(tovec.set(to.getX(), to.getY()), fin());
set(current.x, current.y);
}
@Override

View File

@ -108,7 +108,7 @@ public abstract class InputHandler extends InputAdapter{
ItemTransfer.create(stack.item,
player.x + Angles.trnsx(rotation + 180f, backTrns), player.y + Angles.trnsy(rotation + 180f, backTrns),
tile.drawx() + stackTrns.x, tile.drawy() + stackTrns.y, () -> {
new Translator(tile.drawx() + stackTrns.x, tile.drawy() + stackTrns.y), () -> {
tile.block().handleStack(stack.item, removed, tile, player);
remaining[1] -= removed;

View File

@ -146,7 +146,7 @@ public class BlockInventoryFragment implements Fragment {
}
private void move(Item item, Tile tile, Callable c){
ItemTransfer.create(item, tile.drawx(), tile.drawy(), input.player.x, input.player.y, c);
ItemTransfer.create(item, tile.drawx(), tile.drawy(), input.player, c);
}
private String round(float f){