Implemented conveyor item access
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
#Autogenerated file. Do not modify.
|
#Autogenerated file. Do not modify.
|
||||||
#Sat Apr 14 21:49:43 EDT 2018
|
#Sun Apr 15 13:03:00 EDT 2018
|
||||||
version=release
|
version=release
|
||||||
androidBuildCode=923
|
androidBuildCode=925
|
||||||
name=Mindustry
|
name=Mindustry
|
||||||
code=3.5
|
code=3.5
|
||||||
build=custom build
|
build=custom build
|
||||||
|
|||||||
@@ -544,7 +544,7 @@ public class Renderer extends RendererModule{
|
|||||||
|
|
||||||
Tile tile = world.tileWorld(v.x, v.y);
|
Tile tile = world.tileWorld(v.x, v.y);
|
||||||
if(tile != null) tile = tile.target();
|
if(tile != null) tile = tile.target();
|
||||||
if(tile != null && tile.block().acceptStack(player.inventory.getItem(), tile, player)){
|
if(tile != null && tile.block().acceptStack(player.inventory.getItem().item, player.inventory.getItem().amount, tile, player) > 0){
|
||||||
Draw.color("place");
|
Draw.color("place");
|
||||||
Lines.square(tile.drawx(), tile.drawy(), tile.block().size*tilesize/2f + 1 + Mathf.absin(Timers.time(), 5f, 1f));
|
Lines.square(tile.drawx(), tile.drawy(), tile.block().size*tilesize/2f + 1 + Mathf.absin(Timers.time(), 5f, 1f));
|
||||||
Draw.color();
|
Draw.color();
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import io.anuke.mindustry.Vars;
|
|||||||
import io.anuke.mindustry.resource.Item;
|
import io.anuke.mindustry.resource.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.graphics.Draw;
|
import io.anuke.ucore.graphics.Draw;
|
||||||
import io.anuke.ucore.util.Mathf;
|
import io.anuke.ucore.util.Mathf;
|
||||||
|
|
||||||
@@ -16,19 +17,27 @@ public class ItemAnimationEffect extends TimedEntity {
|
|||||||
private final Vector2 from = new Vector2();
|
private final Vector2 from = new Vector2();
|
||||||
private final Vector2 to = new Vector2();
|
private final Vector2 to = new Vector2();
|
||||||
private final Item item;
|
private final Item item;
|
||||||
|
private final Callable removed;
|
||||||
|
|
||||||
public Interpolation interp = Interpolation.fade;
|
public Interpolation interp = Interpolation.fade;
|
||||||
public float endSize = 0.8f;
|
public float endSize = 0.9f;
|
||||||
|
|
||||||
public ItemAnimationEffect(Item item, float x, float y, float tox, float toy) {
|
public ItemAnimationEffect(Item item, float x, float y, float tox, float toy, Callable removed) {
|
||||||
this.x = x;
|
this.x = x;
|
||||||
this.y = y;
|
this.y = y;
|
||||||
this.item = item;
|
this.item = item;
|
||||||
|
this.removed = removed;
|
||||||
from.set(x, y);
|
from.set(x, y);
|
||||||
to.set(tox, toy);
|
to.set(tox, toy);
|
||||||
lifetime = 40f;
|
lifetime = 40f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void removed() {
|
||||||
|
super.removed();
|
||||||
|
removed.run();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update() {
|
public void update() {
|
||||||
super.update();
|
super.update();
|
||||||
|
|||||||
@@ -2,10 +2,8 @@ package io.anuke.mindustry.input;
|
|||||||
|
|
||||||
import com.badlogic.gdx.Gdx;
|
import com.badlogic.gdx.Gdx;
|
||||||
import com.badlogic.gdx.InputAdapter;
|
import com.badlogic.gdx.InputAdapter;
|
||||||
import com.badlogic.gdx.math.GridPoint2;
|
|
||||||
import com.badlogic.gdx.math.Interpolation;
|
import com.badlogic.gdx.math.Interpolation;
|
||||||
import com.badlogic.gdx.math.Vector2;
|
import com.badlogic.gdx.math.Vector2;
|
||||||
import io.anuke.mindustry.content.blocks.Blocks;
|
|
||||||
import io.anuke.mindustry.entities.ItemAnimationEffect;
|
import io.anuke.mindustry.entities.ItemAnimationEffect;
|
||||||
import io.anuke.mindustry.net.Net;
|
import io.anuke.mindustry.net.Net;
|
||||||
import io.anuke.mindustry.net.NetEvents;
|
import io.anuke.mindustry.net.NetEvents;
|
||||||
@@ -19,6 +17,7 @@ import io.anuke.ucore.core.Timers;
|
|||||||
import io.anuke.ucore.scene.ui.layout.Unit;
|
import io.anuke.ucore.scene.ui.layout.Unit;
|
||||||
import io.anuke.ucore.util.Angles;
|
import io.anuke.ucore.util.Angles;
|
||||||
import io.anuke.ucore.util.Mathf;
|
import io.anuke.ucore.util.Mathf;
|
||||||
|
import io.anuke.ucore.util.Translator;
|
||||||
|
|
||||||
import static io.anuke.mindustry.Vars.*;
|
import static io.anuke.mindustry.Vars.*;
|
||||||
|
|
||||||
@@ -34,6 +33,8 @@ public abstract class InputHandler extends InputAdapter{
|
|||||||
public boolean shooting;
|
public boolean shooting;
|
||||||
public float playerSelectRange = Unit.dp.scl(60f);
|
public float playerSelectRange = Unit.dp.scl(60f);
|
||||||
|
|
||||||
|
private Translator stackTrns = new Translator();
|
||||||
|
|
||||||
public abstract void update();
|
public abstract void update();
|
||||||
public abstract float getCursorX();
|
public abstract float getCursorX();
|
||||||
public abstract float getCursorY();
|
public abstract float getCursorY();
|
||||||
@@ -65,25 +66,36 @@ public abstract class InputHandler extends InputAdapter{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void dropItem(Tile tile, ItemStack stack){
|
public void dropItem(Tile tile, ItemStack stack){
|
||||||
if(tile.block().acceptStack(stack, tile, player)){
|
int accepted = tile.block().acceptStack(stack.item, stack.amount, tile, player);
|
||||||
|
|
||||||
|
if(accepted > 0){
|
||||||
if(transferring) return;
|
if(transferring) return;
|
||||||
|
|
||||||
transferring = true;
|
transferring = true;
|
||||||
int accepted = tile.block().handleStack(stack, tile, player);
|
|
||||||
boolean clear = stack.amount == accepted;
|
boolean clear = stack.amount == accepted;
|
||||||
|
|
||||||
float backTrns = 3f;
|
float backTrns = 3f;
|
||||||
|
|
||||||
int sent = Mathf.clamp(accepted/4, 1, 8);
|
int sent = Mathf.clamp(accepted/4, 1, 8);
|
||||||
int removed = accepted/sent;
|
int removed = accepted/sent;
|
||||||
int[] remaining = {accepted};
|
int[] remaining = {accepted, accepted};
|
||||||
|
|
||||||
for(int i = 0; i < sent; i ++){
|
for(int i = 0; i < sent; i ++){
|
||||||
boolean end = i == sent-1;
|
boolean end = i == sent-1;
|
||||||
Timers.run(i * 3, () -> {
|
Timers.run(i * 3, () -> {
|
||||||
|
tile.block().getStackOffset(stack.item, tile, stackTrns);
|
||||||
|
|
||||||
new ItemAnimationEffect(stack.item,
|
new ItemAnimationEffect(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(), tile.drawy()).add();
|
tile.drawx() + stackTrns.x, tile.drawy() + stackTrns.y, () -> {
|
||||||
|
|
||||||
|
tile.block().handleStack(stack.item, removed, tile, player);
|
||||||
|
remaining[1] -= removed;
|
||||||
|
|
||||||
|
if(end && remaining[1] > 0) {
|
||||||
|
tile.block().handleStack(stack.item, remaining[1], tile, player);
|
||||||
|
}
|
||||||
|
}).add();
|
||||||
|
|
||||||
stack.amount -= removed;
|
stack.amount -= removed;
|
||||||
remaining[0] -= removed;
|
remaining[0] -= removed;
|
||||||
@@ -107,7 +119,7 @@ public abstract class InputHandler extends InputAdapter{
|
|||||||
y = player.y + Angles.trnsy(rotation + 180f, backTrns);
|
y = player.y + Angles.trnsy(rotation + 180f, backTrns);
|
||||||
|
|
||||||
ItemAnimationEffect e = new ItemAnimationEffect(stack.item,
|
ItemAnimationEffect e = new ItemAnimationEffect(stack.item,
|
||||||
x, y, x + Mathf.range(20f), y + Mathf.range(20f)).add();
|
x, y, x + Mathf.range(20f), y + Mathf.range(20f), () -> {}).add();
|
||||||
e.interp = Interpolation.pow3Out;
|
e.interp = Interpolation.pow3Out;
|
||||||
e.endSize = 0.5f;
|
e.endSize = 0.5f;
|
||||||
e.lifetime = 20;
|
e.lifetime = 20;
|
||||||
@@ -151,43 +163,10 @@ public abstract class InputHandler extends InputAdapter{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean validPlace(int x, int y, Block type){
|
public boolean validPlace(int x, int y, Block type){
|
||||||
|
|
||||||
if(!type.isMultiblock() && control.tutorial().active() &&
|
|
||||||
control.tutorial().showBlock()){
|
|
||||||
|
|
||||||
//TODO placepoint control, make sure it's correct.
|
|
||||||
GridPoint2 point = control.tutorial().getPlacePoint();
|
|
||||||
int rotation = control.tutorial().getPlaceRotation();
|
|
||||||
Block block = control.tutorial().getPlaceBlock();
|
|
||||||
|
|
||||||
if(type != block || (rotation != -1 && rotation != this.rotation)){
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}else if(control.tutorial().active()){
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return Placement.validPlace(player.team, x, y, type, rotation);
|
return Placement.validPlace(player.team, x, y, type, rotation);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean validBreak(int x, int y){
|
public boolean validBreak(int x, int y){
|
||||||
if(control.tutorial().active()){
|
|
||||||
|
|
||||||
if(control.tutorial().showBlock()){
|
|
||||||
//TODO placepoint control, make sure it's correct
|
|
||||||
GridPoint2 point = control.tutorial().getPlacePoint();
|
|
||||||
int rotation = control.tutorial().getPlaceRotation();
|
|
||||||
Block block = control.tutorial().getPlaceBlock();
|
|
||||||
|
|
||||||
if(block != Blocks.air
|
|
||||||
|| (rotation != -1 && rotation != this.rotation)){
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return Placement.validBreak(player.team, x, y);
|
return Placement.validBreak(player.team, x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -135,7 +135,7 @@ public class BlockInventoryFragment implements Fragment {
|
|||||||
if(!canPick.get()) return;
|
if(!canPick.get()) return;
|
||||||
if (items[f] > 0) {
|
if (items[f] > 0) {
|
||||||
int amount = Math.min(Inputs.keyDown("item_withdraw") ? items[f] : 1, player.inventory.itemCapacityUsed(item));
|
int amount = Math.min(Inputs.keyDown("item_withdraw") ? items[f] : 1, player.inventory.itemCapacityUsed(item));
|
||||||
items[f] -= amount;
|
tile.block().removeStack(tile, item, amount);
|
||||||
|
|
||||||
int sent = Mathf.clamp(amount/3, 1, 8);
|
int sent = Mathf.clamp(amount/3, 1, 8);
|
||||||
int per = Math.min(amount/sent, 5);
|
int per = Math.min(amount/sent, 5);
|
||||||
|
|||||||
@@ -3,9 +3,9 @@ package io.anuke.mindustry.world;
|
|||||||
import com.badlogic.gdx.math.GridPoint2;
|
import com.badlogic.gdx.math.GridPoint2;
|
||||||
import io.anuke.mindustry.entities.Unit;
|
import io.anuke.mindustry.entities.Unit;
|
||||||
import io.anuke.mindustry.resource.Item;
|
import io.anuke.mindustry.resource.Item;
|
||||||
import io.anuke.mindustry.resource.ItemStack;
|
|
||||||
import io.anuke.mindustry.resource.Liquid;
|
import io.anuke.mindustry.resource.Liquid;
|
||||||
import io.anuke.ucore.util.Mathf;
|
import io.anuke.ucore.util.Mathf;
|
||||||
|
import io.anuke.ucore.util.Translator;
|
||||||
|
|
||||||
public abstract class BaseBlock {
|
public abstract class BaseBlock {
|
||||||
public boolean hasInventory = true;
|
public boolean hasInventory = true;
|
||||||
@@ -17,15 +17,29 @@ public abstract class BaseBlock {
|
|||||||
public float liquidFlowFactor = 4.9f;
|
public float liquidFlowFactor = 4.9f;
|
||||||
public float powerCapacity = 10f;
|
public float powerCapacity = 10f;
|
||||||
|
|
||||||
public boolean acceptStack(ItemStack item, Tile tile, Unit source){
|
/**Returns the amount of items this block can accept.*/
|
||||||
return acceptItem(item.item, tile, tile) && hasInventory && source.team == tile.getTeam();
|
public int acceptStack(Item item, int amount, Tile tile, Unit source){
|
||||||
|
if(acceptItem(item, tile, tile) && hasInventory && source.team == tile.getTeam()){
|
||||||
|
return Math.min(itemCapacity - tile.entity.inventory.totalItems(), amount);
|
||||||
|
}else{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int handleStack(ItemStack item, Tile tile, Unit source){
|
/**Remove a stack from this inventory, and return the amount removed.*/
|
||||||
int total = tile.entity.inventory.totalItems();
|
public int removeStack(Tile tile, Item item, int amount){
|
||||||
int canAccept = Math.min(itemCapacity - total, item.amount);
|
tile.entity.inventory.removeItem(item, amount);
|
||||||
tile.entity.inventory.addItem(item.item, canAccept);
|
return amount;
|
||||||
return canAccept;
|
}
|
||||||
|
|
||||||
|
/**Handle a stack input.*/
|
||||||
|
public void handleStack(Item item, int amount, Tile tile, Unit source){
|
||||||
|
tile.entity.inventory.addItem(item, amount);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**Returns offset for stack placement.*/
|
||||||
|
public void getStackOffset(Item item, Tile tile, Translator trns){
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleItem(Item item, Tile tile, Tile source){
|
public void handleItem(Item item, Tile tile, Tile source){
|
||||||
|
|||||||
@@ -155,10 +155,8 @@ public class Placement {
|
|||||||
|
|
||||||
if (tile == null || tile.block().unbreakable) return false;
|
if (tile == null || tile.block().unbreakable) return false;
|
||||||
|
|
||||||
if(tile.isLinked() && tile.getLinked().block().unbreakable){
|
return (!tile.isLinked() || !tile.getLinked().block().unbreakable) && tile.breakable()
|
||||||
return false;
|
&& (tile.getTeam() == Team.none || tile.getTeam() == team);
|
||||||
}
|
|
||||||
|
|
||||||
return tile.breakable() && (tile.getTeam() == Team.none || tile.getTeam() == team);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
package io.anuke.mindustry.world.blocks.types.distribution;
|
package io.anuke.mindustry.world.blocks.types.distribution;
|
||||||
|
|
||||||
import com.badlogic.gdx.utils.LongArray;
|
import com.badlogic.gdx.utils.LongArray;
|
||||||
|
import io.anuke.mindustry.content.Items;
|
||||||
import io.anuke.mindustry.entities.TileEntity;
|
import io.anuke.mindustry.entities.TileEntity;
|
||||||
import io.anuke.mindustry.entities.Unit;
|
import io.anuke.mindustry.entities.Unit;
|
||||||
|
import io.anuke.mindustry.graphics.Layer;
|
||||||
import io.anuke.mindustry.resource.Item;
|
import io.anuke.mindustry.resource.Item;
|
||||||
import io.anuke.mindustry.content.Items;
|
|
||||||
import io.anuke.mindustry.world.Block;
|
import io.anuke.mindustry.world.Block;
|
||||||
import io.anuke.mindustry.world.BlockGroup;
|
import io.anuke.mindustry.world.BlockGroup;
|
||||||
import io.anuke.mindustry.graphics.Layer;
|
|
||||||
import io.anuke.mindustry.world.Tile;
|
import io.anuke.mindustry.world.Tile;
|
||||||
import io.anuke.ucore.core.Timers;
|
import io.anuke.ucore.core.Timers;
|
||||||
import io.anuke.ucore.graphics.Draw;
|
import io.anuke.ucore.graphics.Draw;
|
||||||
@@ -16,9 +16,6 @@ import io.anuke.ucore.util.*;
|
|||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
import java.io.DataOutputStream;
|
import java.io.DataOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.AbstractList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static io.anuke.mindustry.Vars.tilesize;
|
import static io.anuke.mindustry.Vars.tilesize;
|
||||||
|
|
||||||
@@ -26,11 +23,11 @@ public class Conveyor extends Block{
|
|||||||
private static ItemPos drawpos = new ItemPos();
|
private static ItemPos drawpos = new ItemPos();
|
||||||
private static ItemPos pos1 = new ItemPos();
|
private static ItemPos pos1 = new ItemPos();
|
||||||
private static ItemPos pos2 = new ItemPos();
|
private static ItemPos pos2 = new ItemPos();
|
||||||
|
|
||||||
private static final float itemSpace = 0.135f * 2.2f;
|
private static final float itemSpace = 0.135f * 2.2f;
|
||||||
private static final float offsetScl = 128f*3f;
|
private static final float offsetScl = 128f*3f;
|
||||||
private static final float minmove = 1f / (Short.MAX_VALUE - 2);
|
private static final float minmove = 1f / (Short.MAX_VALUE - 2);
|
||||||
|
private static final float itemSize = 5f;
|
||||||
public static final float itemSize = 5f;
|
|
||||||
|
|
||||||
private final Translator tr1 = new Translator();
|
private final Translator tr1 = new Translator();
|
||||||
private final Translator tr2 = new Translator();
|
private final Translator tr2 = new Translator();
|
||||||
@@ -44,9 +41,12 @@ public class Conveyor extends Block{
|
|||||||
update = true;
|
update = true;
|
||||||
layer = Layer.overlay;
|
layer = Layer.overlay;
|
||||||
group = BlockGroup.transportation;
|
group = BlockGroup.transportation;
|
||||||
hasInventory = false;
|
hasInventory = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setBars() {}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setStats(){
|
public void setStats(){
|
||||||
super.setStats();
|
super.setStats();
|
||||||
@@ -119,7 +119,7 @@ public class Conveyor extends Block{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(Tile tile){
|
public synchronized void update(Tile tile){
|
||||||
|
|
||||||
ConveyorEntity entity = tile.entity();
|
ConveyorEntity entity = tile.entity();
|
||||||
entity.minitem = 1f;
|
entity.minitem = 1f;
|
||||||
@@ -154,6 +154,7 @@ public class Conveyor extends Block{
|
|||||||
|
|
||||||
if (pos.y >= 0.9999f && offloadDir(tile, pos.item)) {
|
if (pos.y >= 0.9999f && offloadDir(tile, pos.item)) {
|
||||||
minremove = Math.min(i, minremove);
|
minremove = Math.min(i, minremove);
|
||||||
|
tile.entity.inventory.removeItem(pos.item, 1);
|
||||||
} else {
|
} else {
|
||||||
value = pos.pack();
|
value = pos.pack();
|
||||||
|
|
||||||
@@ -167,11 +168,52 @@ public class Conveyor extends Block{
|
|||||||
entity.minCarry = 2f;
|
entity.minCarry = 2f;
|
||||||
|
|
||||||
if (minremove != Integer.MAX_VALUE) entity.convey.truncate(minremove);
|
if (minremove != Integer.MAX_VALUE) entity.convey.truncate(minremove);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TileEntity getEntity(){
|
public boolean isAccessible(){
|
||||||
return new ConveyorEntity();
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public synchronized int removeStack(Tile tile, Item item, int amount) {
|
||||||
|
ConveyorEntity entity = tile.entity();
|
||||||
|
int removed = 0;
|
||||||
|
|
||||||
|
for(int j = 0; j < amount; j ++) {
|
||||||
|
for (int i = 0; i < entity.convey.size; i++) {
|
||||||
|
long val = entity.convey.get(i);
|
||||||
|
ItemPos pos = pos1.set(val, ItemPos.drawShorts);
|
||||||
|
if(pos.item == item){
|
||||||
|
entity.convey.removeValue(val);
|
||||||
|
entity.inventory.removeItem(item, 1);
|
||||||
|
removed ++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return removed;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void getStackOffset(Item item, Tile tile, Translator trns) {
|
||||||
|
trns.trns(tile.getRotation()*90 + 180f, tilesize/2f);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public synchronized int acceptStack(Item item, int amount, Tile tile, Unit source) {
|
||||||
|
ConveyorEntity entity = tile.entity();
|
||||||
|
return entity.minitem > itemSpace ? 1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public synchronized void handleStack(Item item, int amount, Tile tile, Unit source) {
|
||||||
|
ConveyorEntity entity = tile.entity();
|
||||||
|
|
||||||
|
long result = ItemPos.packItem(item, 0f, 0f, (byte)Mathf.random(255));
|
||||||
|
entity.convey.insert(0, result);
|
||||||
|
entity.inventory.addItem(item, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -196,6 +238,8 @@ public class Conveyor extends Block{
|
|||||||
long result = ItemPos.packItem(item, y*0.9f, pos, (byte)Mathf.random(255));
|
long result = ItemPos.packItem(item, y*0.9f, pos, (byte)Mathf.random(255));
|
||||||
boolean inserted = false;
|
boolean inserted = false;
|
||||||
|
|
||||||
|
tile.entity.inventory.addItem(item, 1);
|
||||||
|
|
||||||
for(int i = 0; i < entity.convey.size; i ++){
|
for(int i = 0; i < entity.convey.size; i ++){
|
||||||
if(compareItems(result, entity.convey.get(i)) < 0){
|
if(compareItems(result, entity.convey.get(i)) < 0){
|
||||||
entity.convey.insert(i, result);
|
entity.convey.insert(i, result);
|
||||||
@@ -210,6 +254,11 @@ public class Conveyor extends Block{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TileEntity getEntity(){
|
||||||
|
return new ConveyorEntity();
|
||||||
|
}
|
||||||
|
|
||||||
public static class ConveyorEntity extends TileEntity{
|
public static class ConveyorEntity extends TileEntity{
|
||||||
|
|
||||||
LongArray convey = new LongArray();
|
LongArray convey = new LongArray();
|
||||||
@@ -235,35 +284,9 @@ public class Conveyor extends Block{
|
|||||||
for(int i = 0; i < amount; i ++){
|
for(int i = 0; i < amount; i ++){
|
||||||
convey.add(ItemPos.toLong(stream.readInt()));
|
convey.add(ItemPos.toLong(stream.readInt()));
|
||||||
}
|
}
|
||||||
|
|
||||||
sort(convey.items, convey.size);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void sort(long[] elements, int length){
|
|
||||||
List<Long> wrapper = new AbstractList<Long>() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Long get(int index) {
|
|
||||||
return elements[index];
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int size() {
|
|
||||||
return length;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Long set(int index, Long element) {
|
|
||||||
long v = elements[index];
|
|
||||||
elements[index] = element;
|
|
||||||
return v;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
Collections.sort(wrapper, Conveyor::compareItems);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static int compareItems(Long a, Long b){
|
private static int compareItems(Long a, Long b){
|
||||||
pos1.set(a, ItemPos.packShorts);
|
pos1.set(a, ItemPos.packShorts);
|
||||||
pos2.set(b, ItemPos.packShorts);
|
pos2.set(b, ItemPos.packShorts);
|
||||||
|
|||||||
Reference in New Issue
Block a user