All Downloads are FREE. Search and download functionalities are using the official Maven repository.

mmb.content.imachine.PlaceIncomingItems Maven / Gradle / Ivy

Go to download

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<

There is a newer version: 0.6
Show newest version
/**
 * 
 */
package mmb.content.imachine;

import mmb.NN;
import mmb.Nil;
import mmb.content.ContentsBlocks;
import mmb.engine.MMBUtils;
import mmb.engine.block.BlockEntityRotary;
import mmb.engine.block.BlockEntry;
import mmb.engine.block.BlockType;
import mmb.engine.block.Placer;
import mmb.engine.craft.RecipeOutput;
import mmb.engine.debug.Debugger;
import mmb.engine.inv.InvUtils;
import mmb.engine.inv.io.InventoryWriter;
import mmb.engine.item.ItemEntry;
import mmb.engine.rotate.RotatedImageGroup;
import mmb.engine.rotate.Side;

/**
 * @author oskar
 *
 */
public class PlaceIncomingItems extends BlockEntityRotary {
	private static final Debugger debug = new Debugger("BLOCK PLACE MACHINE");
	@NN private InventoryWriter placer = new InventoryWriter() {

		@Override
		public int insert(ItemEntry ent, int amount) {
			if(amount < 1) return 0;
			BlockEntry blk = getAtSide(getRotation().U());
			if(blk.isSurface()) return 0;
			debug.printl("Item given");
			if(ent instanceof Placer) {
				debug.printl("Placer given, placing");
				Placer iplacer = (Placer)ent;
				BlockEntry newBlock = iplacer.place(getRotation().U().offset(posX(), posY()), owner());
				if(newBlock != null) return 1;
			}
			return 0;
		}

		@Override
		public int bulkInsert(RecipeOutput block, int amount) {
			if(block.items().size() > 1) return 0;
			if(block.items().isEmpty()) return amount;
			ItemEntry ent = InvUtils.onlyItem(block);
			BlockEntry blk = getAtSide(getRotation().U());
			if(!blk.isSurface()) return 0;
			debug.printl("Item given");
			if(ent instanceof Placer) {
				debug.printl("Placer given, placing");
				Placer iplacer = (Placer)ent;
				BlockEntry newBlock = iplacer.place(getRotation().U().offset(posX(), posY()), owner());
				if(newBlock != null) return 1;
			}
			return 0;
		}

		@Override
		public int toInsertBulk(RecipeOutput block, int amount) {
			return toInsert(InvUtils.onlyItem(block), amount);
		}

		@Override
		public int toInsert(@Nil ItemEntry item, int amount) {
			if(amount == 0) return 0;
			return MMBUtils.bool2int(item instanceof Placer);
		}
		
	};

	@Override
	public BlockType type() {
		return ContentsBlocks.PLACEITEMS;
	}

	public static final RotatedImageGroup TEXTURE = RotatedImageGroup.create("machine/block place interface.png");
	@Override
	public RotatedImageGroup getImage() {
		return TEXTURE;
	}
	
	@Override
	public InventoryWriter getInput(Side s) {
		if(s == getRotation().D()) return placer;
		return InventoryWriter.NONE;
	}

	@Override
	public BlockEntry blockCopy() {
		PlaceIncomingItems copy = new PlaceIncomingItems();
		copy.setRotation(getRotation());
		return copy;
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy