Merge branch '6.0' into crater
# Conflicts: # core/assets/icons/icons.properties # core/assets/sprites/block_colors.png # core/assets/sprites/sprites.atlas # core/assets/sprites/sprites.png # core/assets/sprites/sprites2.png # core/assets/sprites/sprites4.png # core/assets/sprites/sprites6.png
This commit is contained in:
140
core/src/mindustry/world/blocks/experimental/BlockForge.java
Normal file
140
core/src/mindustry/world/blocks/experimental/BlockForge.java
Normal file
@@ -0,0 +1,140 @@
|
||||
package mindustry.world.blocks.experimental;
|
||||
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.math.*;
|
||||
import arc.scene.ui.layout.*;
|
||||
import arc.struct.*;
|
||||
import arc.util.ArcAnnotate.*;
|
||||
import arc.util.io.*;
|
||||
import mindustry.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.graphics.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.ui.*;
|
||||
import mindustry.world.*;
|
||||
import mindustry.world.blocks.*;
|
||||
import mindustry.world.blocks.payloads.*;
|
||||
|
||||
public class BlockForge extends Block{
|
||||
public float buildSpeed = 0.4f;
|
||||
|
||||
public BlockForge(String name){
|
||||
super(name);
|
||||
|
||||
size = 3;
|
||||
update = true;
|
||||
outputsPayload = true;
|
||||
hasItems = true;
|
||||
configurable = true;
|
||||
hasPower = true;
|
||||
|
||||
config(Block.class, (tile, block) -> ((BlockForgeEntity)tile).recipe = block);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBars(){
|
||||
super.setBars();
|
||||
|
||||
bars.add("progress", entity -> new Bar("bar.progress", Pal.ammo, () -> ((BlockForgeEntity)entity).progress));
|
||||
}
|
||||
|
||||
public class BlockForgeEntity extends TileEntity{
|
||||
public @Nullable Payload payload;
|
||||
public @Nullable Block recipe;
|
||||
public float progress, time, heat;
|
||||
|
||||
@Override
|
||||
public boolean acceptItem(Tilec source, Item item){
|
||||
return items.get(item) < getMaximumAccepted(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaximumAccepted(Item item){
|
||||
if(recipe == null) return 0;
|
||||
for(ItemStack stack : recipe.requirements){
|
||||
if(stack.item == item) return stack.amount * 2;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateTile(){
|
||||
boolean produce = recipe != null && consValid() && payload == null && items.has(recipe.requirements);
|
||||
|
||||
if(produce){
|
||||
progress += buildSpeed * edelta();
|
||||
|
||||
if(progress >= recipe.buildCost){
|
||||
items.remove(recipe.requirements);
|
||||
payload = new BlockPayload(recipe);
|
||||
progress = 0f;
|
||||
}
|
||||
}else{
|
||||
progress = 0;
|
||||
}
|
||||
|
||||
heat = Mathf.lerpDelta(heat, Mathf.num(produce), 0.3f);
|
||||
time += heat * delta();
|
||||
|
||||
if(payload != null && dumpPayload(payload)){
|
||||
payload = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buildConfiguration(Table table){
|
||||
Array<Block> blocks = Vars.content.blocks().select(b -> b.isVisible() && b.size <= 2 && b.requirements.length <= 3);
|
||||
|
||||
ItemSelection.buildTable(table, blocks, () -> recipe, block -> recipe = block);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object config(){
|
||||
return recipe;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(){
|
||||
super.draw();
|
||||
|
||||
if(payload != null){
|
||||
payload.draw(x, y, 0);
|
||||
}
|
||||
|
||||
if(recipe != null){
|
||||
TextureRegion region = recipe.icon(Cicon.full);
|
||||
|
||||
Shaders.build.region = region;
|
||||
Shaders.build.progress = progress / recipe.buildCost;
|
||||
Shaders.build.color.set(Pal.accent);
|
||||
Shaders.build.color.a = heat;
|
||||
Shaders.build.time = -time / 20f;
|
||||
|
||||
Draw.shader(Shaders.build);
|
||||
Draw.rect(region, x, y);
|
||||
Draw.shader();
|
||||
|
||||
Draw.color(Pal.accent);
|
||||
Draw.alpha(heat);
|
||||
|
||||
Lines.lineAngleCenter(x + Mathf.sin(time, 20f, Vars.tilesize / 2f * size - 2f), y, 90, size * Vars.tilesize - 4f);
|
||||
|
||||
Draw.reset();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(Writes write){
|
||||
super.write(write);
|
||||
write.s(recipe == null ? -1 : recipe.id);
|
||||
write.f(progress);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(Reads read, byte revision){
|
||||
super.read(read, revision);
|
||||
recipe = Vars.content.block(read.s());
|
||||
progress = read.f();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
package mindustry.world.blocks.experimental;
|
||||
|
||||
import arc.math.geom.*;
|
||||
import arc.struct.*;
|
||||
import arc.util.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.entities.*;
|
||||
import mindustry.game.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.world.*;
|
||||
import mindustry.world.blocks.payloads.*;
|
||||
import mindustry.world.blocks.production.*;
|
||||
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
//pointless, will definitely be removed eventually
|
||||
public class BlockLauncher extends PayloadAcceptor{
|
||||
static final IntArray positions = new IntArray();
|
||||
|
||||
public float range = 150;
|
||||
|
||||
public BlockLauncher(String name){
|
||||
super(name);
|
||||
|
||||
update = true;
|
||||
size = 3;
|
||||
}
|
||||
|
||||
public class BlockLauncherEntity extends PayloadAcceptorEntity{
|
||||
|
||||
@Override
|
||||
public void draw(){
|
||||
super.draw();
|
||||
|
||||
drawPayload();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptPayload(Tilec source, Payload payload){
|
||||
return this.payload == null && payload instanceof BlockPayload;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateTile(){
|
||||
if(updatePayload() && efficiency() >= 0.99f){
|
||||
Effects.shake(4f, 4f, this);
|
||||
Fx.producesmoke.at(this);
|
||||
|
||||
positions.clear();
|
||||
BlockPayload pay = (BlockPayload)payload;
|
||||
|
||||
Geometry.circle(tileX(), tileY(), world.width(), world.height(), (int)(range / tilesize), (cx, cy) -> {
|
||||
if(Build.validPlace(team, cx, cy, pay.block, 0)){
|
||||
positions.add(Point2.pack(cx, cy));
|
||||
}
|
||||
});
|
||||
|
||||
if(positions.isEmpty()) return;
|
||||
|
||||
int pick = positions.random();
|
||||
LaunchedBlock launch = new LaunchedBlock(Point2.x(pick), Point2.y(pick), pay.block, team);
|
||||
Fx.blockTransfer.at(x, y, 0, launch);
|
||||
Time.run(Fx.blockTransfer.lifetime, () -> {
|
||||
float ex = launch.x * tilesize + launch.block.offset(), ey = launch.y * tilesize + launch.block.offset();
|
||||
if(Build.validPlace(launch.team, launch.x, launch.y, launch.block, 0)){
|
||||
world.tile(launch.x, launch.y).setBlock(launch.block, launch.team);
|
||||
Fx.placeBlock.at(ex, ey, launch.block.size);
|
||||
}else{
|
||||
Fx.breakBlock.at(ex, ey, launch.block.size);
|
||||
Fx.explosion.at(ex, ey);
|
||||
}
|
||||
});
|
||||
payload = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class LaunchedBlock{
|
||||
public final int x, y;
|
||||
public final Block block;
|
||||
public final Team team;
|
||||
|
||||
public LaunchedBlock(int x, int y, Block block, Team team){
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.block = block;
|
||||
this.team = team;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package mindustry.world.blocks.logic;
|
||||
package mindustry.world.blocks.experimental;
|
||||
|
||||
import arc.math.*;
|
||||
import mindustry.gen.*;
|
||||
@@ -1,4 +1,4 @@
|
||||
package mindustry.world.blocks.units;
|
||||
package mindustry.world.blocks.experimental;
|
||||
|
||||
import arc.*;
|
||||
import arc.graphics.g2d.*;
|
||||
@@ -1,4 +1,4 @@
|
||||
package mindustry.world.blocks.logic;
|
||||
package mindustry.world.blocks.experimental;
|
||||
|
||||
import arc.scene.ui.layout.*;
|
||||
import arc.struct.*;
|
||||
22
core/src/mindustry/world/blocks/payloads/BlockPayload.java
Normal file
22
core/src/mindustry/world/blocks/payloads/BlockPayload.java
Normal file
@@ -0,0 +1,22 @@
|
||||
package mindustry.world.blocks.payloads;
|
||||
|
||||
import arc.graphics.g2d.*;
|
||||
import mindustry.graphics.*;
|
||||
import mindustry.ui.*;
|
||||
import mindustry.world.*;
|
||||
|
||||
import static mindustry.Vars.tilesize;
|
||||
|
||||
public class BlockPayload implements Payload{
|
||||
public Block block;
|
||||
|
||||
public BlockPayload(Block block){
|
||||
this.block = block;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(float x, float y, float rotation){
|
||||
Drawf.shadow(x, y, block.size * tilesize * 2f);
|
||||
Draw.rect(block.icon(Cicon.full), x, y, 0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package mindustry.world.blocks.production;
|
||||
|
||||
import arc.math.*;
|
||||
import arc.math.geom.*;
|
||||
import arc.util.ArcAnnotate.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.world.*;
|
||||
import mindustry.world.blocks.payloads.*;
|
||||
|
||||
import static mindustry.Vars.tilesize;
|
||||
|
||||
public class PayloadAcceptor extends Block{
|
||||
|
||||
public PayloadAcceptor(String name){
|
||||
super(name);
|
||||
|
||||
update = true;
|
||||
}
|
||||
|
||||
public class PayloadAcceptorEntity extends TileEntity{
|
||||
public @Nullable Payload payload;
|
||||
public Vec2 inputVector = new Vec2();
|
||||
public float inputRotation;
|
||||
|
||||
@Override
|
||||
public boolean acceptPayload(Tilec source, Payload payload){
|
||||
return this.payload == null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handlePayload(Tilec source, Payload payload){
|
||||
this.payload = payload;
|
||||
this.inputVector.set(source).sub(this).clamp(-size * tilesize / 2f, size * tilesize / 2f, -size * tilesize / 2f, size * tilesize / 2f);
|
||||
this.inputRotation = source.angleTo(this);
|
||||
}
|
||||
|
||||
/** @return true if the payload is in position. */
|
||||
public boolean updatePayload(){
|
||||
if(payload == null) return false;
|
||||
|
||||
inputRotation = Mathf.slerpDelta(inputRotation, 90f, 0.3f);
|
||||
inputVector.lerpDelta(Vec2.ZERO, 0.2f);
|
||||
|
||||
return inputVector.isZero(0.5f);
|
||||
}
|
||||
|
||||
public void drawPayload(){
|
||||
if(payload != null){
|
||||
payload.draw(x + inputVector.x, y + inputVector.y, inputRotation);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -161,6 +161,10 @@ public class ItemModule extends BlockModule{
|
||||
total -= amount;
|
||||
}
|
||||
|
||||
public void remove(ItemStack[] stacks){
|
||||
for(ItemStack stack : stacks) remove(stack.item, stack.amount);
|
||||
}
|
||||
|
||||
public void remove(ItemStack stack){
|
||||
remove(stack.item, stack.amount);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user