mmb.content.wireworld.ActuatorPlaceBlock Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of multimachinebuilder Show documentation
Show all versions of multimachinebuilder Show documentation
Dependency for the MultiMachineBuilder, a voxel game about building an industrial empire in a finite world.
THIS RELEASE IS NOT PLAYABLE. To play the game, donwload from >ITCH.IO LINK HERE< or >GH releases link here<
/**
*
*/
package mmb.content.wireworld;
import java.awt.Point;
import com.fasterxml.jackson.databind.node.ObjectNode;
import mmb.NN;
import mmb.Nil;
import mmb.beans.BlockSetting;
import mmb.cgui.BlockActivateListener;
import mmb.content.ContentsBlocks;
import mmb.data.variables.ListenableValue;
import mmb.engine.block.BlockEntry;
import mmb.engine.block.BlockType;
import mmb.engine.debug.Debugger;
import mmb.engine.item.Items;
import mmb.engine.rotate.RotatedImageGroup;
import mmb.engine.texture.Textures;
import mmb.engine.worlds.MapProxy;
import mmb.engine.worlds.world.World;
import mmb.menu.world.window.WorldWindow;
/**
* @author oskar
*
*/
public class ActuatorPlaceBlock extends AbstractActuatorBase implements BlockActivateListener , BlockSetting{
private static final Debugger debug = new Debugger("ACTUATOR-PLACER");
private static final RotatedImageGroup texture = RotatedImageGroup.create(Textures.get("machine/placer.png"));
@Override
protected void save1(ObjectNode node) {
BlockType block = blockSetting();
if(block == null) node.put("place", "mmb.grass");
else node.put("place", block.id());
}
@Override
protected void load1(ObjectNode node) {
setBlockSetting(Items.getExpectType(node.get("place").asText(null), BlockType.class));
}
@Override
public BlockType type() {
return ContentsBlocks.PLACER;
}
@Override
public RotatedImageGroup getImage() {
return texture;
}
@Override
protected void run(Point p, BlockEntry ent, MapProxy proxy) {
BlockType block0 = blockSetting();
if(block0 == null) return;
try {
proxy.place(block0, p);
}catch(Exception e) {
debug.pstm(e, "Failed to place a block");
}
}
@Override
public void click(int blockX, int blockY, World map, @Nil WorldWindow window, double partX, double partY) {
if(window == null) return;
window.openDialogWindow(new SelectBlock(this, window), "["+posX()+","+posY()+"]");
}
@Override
public BlockEntry blockCopy() {
ActuatorPlaceBlock result = new ActuatorPlaceBlock();
result.setChirotation(getChirotation());
result.setBlockSetting(blockSetting());
return result;
}
//Block settings
@NN private static final ListenableValue<@Nil BlockType> bsetting = new ListenableValue<>(null);
@Override
public ListenableValue getBlockVariable() {
return bsetting;
}
}