mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-02-01 20:04:02 +07:00
New ItemTransfer entity
This commit is contained in:
parent
468a6c1dca
commit
8f137eadf0
@ -1,28 +1,55 @@
|
|||||||
package io.anuke.mindustry.entities;
|
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.Vars;
|
||||||
import io.anuke.mindustry.type.Item;
|
import io.anuke.mindustry.type.Item;
|
||||||
import io.anuke.ucore.entities.Entity;
|
import io.anuke.ucore.entities.Entity;
|
||||||
import io.anuke.ucore.entities.TimedEntity;
|
import io.anuke.ucore.entities.TimedEntity;
|
||||||
import io.anuke.ucore.function.Callable;
|
import io.anuke.ucore.function.Callable;
|
||||||
|
import io.anuke.ucore.util.Position;
|
||||||
|
|
||||||
public class ItemTransfer extends TimedEntity {
|
public class ItemTransfer extends TimedEntity{
|
||||||
|
private Vector2 from = new Vector2();
|
||||||
|
private Vector2 current = new Vector2();
|
||||||
public static void create(Item item, float fromx, float fromy, float tox, float toy, Callable done){
|
private Vector2 tovec = new Vector2();
|
||||||
|
private Item item;
|
||||||
|
private Position to;
|
||||||
|
private 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(){}
|
private ItemTransfer(){}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void reset() {
|
||||||
|
super.reset();
|
||||||
|
item = null;
|
||||||
|
to = null;
|
||||||
|
done = null;
|
||||||
|
from.setZero();
|
||||||
|
current.setZero();
|
||||||
|
tovec.setZero();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removed() {
|
public void removed() {
|
||||||
super.removed();
|
Pools.free(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update() {
|
public void update() {
|
||||||
super.update();
|
super.update();
|
||||||
|
current.set(from).lerp(tovec.set(to.getX(), to.getY()), fin());
|
||||||
|
set(current.x, current.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -108,7 +108,7 @@ public abstract class InputHandler extends InputAdapter{
|
|||||||
|
|
||||||
ItemTransfer.create(stack.item,
|
ItemTransfer.create(stack.item,
|
||||||
player.x + Angles.trnsx(rotation + 180f, backTrns), player.y + Angles.trnsy(rotation + 180f, backTrns),
|
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);
|
tile.block().handleStack(stack.item, removed, tile, player);
|
||||||
remaining[1] -= removed;
|
remaining[1] -= removed;
|
||||||
|
@ -146,7 +146,7 @@ public class BlockInventoryFragment implements Fragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void move(Item item, Tile tile, Callable c){
|
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){
|
private String round(float f){
|
||||||
|
Loading…
Reference in New Issue
Block a user