implemented capture of existing blueprints for composition, for #1544
This commit is contained in:
parent
416180819b
commit
f814fa67f7
7 changed files with 87 additions and 35 deletions
|
@ -69,46 +69,51 @@ public class BlockBuilder extends BlockContainer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean onBlockActivated(World world, int i, int j, int k, EntityPlayer entityplayer, int par6, float par7, float par8, float par9) {
|
||||
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityplayer, int par6, float par7, float par8, float par9) {
|
||||
|
||||
// Drop through if the player is sneaking
|
||||
if (entityplayer.isSneaking()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
TileEntity tile = world.getTileEntity(i, j, k);
|
||||
TileEntity tile = world.getTileEntity(x, y, z);
|
||||
TileBuilder builder = tile instanceof TileBuilder ? (TileBuilder) tile : null;
|
||||
|
||||
Item equipped = entityplayer.getCurrentEquippedItem() != null ? entityplayer.getCurrentEquippedItem().getItem() : null;
|
||||
if (equipped instanceof IToolWrench && ((IToolWrench) equipped).canWrench(entityplayer, i, j, k)) {
|
||||
|
||||
int meta = world.getBlockMetadata(i, j, k);
|
||||
if (equipped instanceof IToolWrench && ((IToolWrench) equipped).canWrench(entityplayer, x, y, z)) {
|
||||
int meta = world.getBlockMetadata(x, y, z);
|
||||
|
||||
switch (ForgeDirection.values()[meta]) {
|
||||
case WEST:
|
||||
world.setBlockMetadataWithNotify(i, j, k, ForgeDirection.SOUTH.ordinal(), 0);
|
||||
world.setBlockMetadataWithNotify(x, y, z, ForgeDirection.SOUTH.ordinal(), 0);
|
||||
break;
|
||||
case EAST:
|
||||
world.setBlockMetadataWithNotify(i, j, k, ForgeDirection.NORTH.ordinal(), 0);
|
||||
world.setBlockMetadataWithNotify(x, y, z, ForgeDirection.NORTH.ordinal(), 0);
|
||||
break;
|
||||
case NORTH:
|
||||
world.setBlockMetadataWithNotify(i, j, k, ForgeDirection.WEST.ordinal(), 0);
|
||||
world.setBlockMetadataWithNotify(x, y, z, ForgeDirection.WEST.ordinal(), 0);
|
||||
break;
|
||||
case SOUTH:
|
||||
default:
|
||||
world.setBlockMetadataWithNotify(i, j, k, ForgeDirection.EAST.ordinal(), 0);
|
||||
world.setBlockMetadataWithNotify(x, y, z, ForgeDirection.EAST.ordinal(), 0);
|
||||
break;
|
||||
}
|
||||
|
||||
world.markBlockForUpdate(i, j, k);
|
||||
((IToolWrench) equipped).wrenchUsed(entityplayer, i, j, k);
|
||||
world.markBlockForUpdate(x, y, z);
|
||||
((IToolWrench) equipped).wrenchUsed(entityplayer, x, y, z);
|
||||
|
||||
return true;
|
||||
} else if (equipped instanceof ItemConstructionMarker) {
|
||||
if (ItemConstructionMarker.linkStarted(entityplayer.getCurrentEquippedItem())) {
|
||||
ItemConstructionMarker.link(entityplayer.getCurrentEquippedItem(), world, x, y, z);
|
||||
}
|
||||
|
||||
return true;
|
||||
} else if (builder != null && FluidUtils.handleRightClick(builder, ForgeDirection.UNKNOWN, entityplayer, true, false)) {
|
||||
return true;
|
||||
} else {
|
||||
if (!world.isRemote) {
|
||||
entityplayer.openGui(BuildCraftBuilders.instance, GuiIds.BUILDER, world, i, j, k);
|
||||
entityplayer.openGui(BuildCraftBuilders.instance, GuiIds.BUILDER, world, x, y, z);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
|
@ -12,6 +12,7 @@ import net.minecraft.block.Block;
|
|||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
|
@ -58,14 +59,20 @@ public class BlockConstructionMarker extends BlockMarker {
|
|||
|
||||
TileConstructionMarker marker = (TileConstructionMarker) world.getTileEntity(x, y, z);
|
||||
|
||||
if (marker.itemBlueprint == null
|
||||
&& entityplayer.inventory.getCurrentItem() != null
|
||||
&& entityplayer.inventory.getCurrentItem().getItem() instanceof ItemBlueprint) {
|
||||
Item equipped = entityplayer.getCurrentEquippedItem() != null ? entityplayer.getCurrentEquippedItem().getItem()
|
||||
: null;
|
||||
|
||||
marker.setBlueprint(entityplayer.inventory.getCurrentItem().copy());
|
||||
entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem, null);
|
||||
if (equipped instanceof ItemBlueprint) {
|
||||
if (marker.itemBlueprint == null) {
|
||||
marker.setBlueprint(entityplayer.inventory.getCurrentItem().copy());
|
||||
entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem, null);
|
||||
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
} else if (equipped instanceof ItemConstructionMarker) {
|
||||
if (ItemConstructionMarker.linkStarted(entityplayer.getCurrentEquippedItem())) {
|
||||
ItemConstructionMarker.link(entityplayer.getCurrentEquippedItem(), world, x, y, z);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
|
@ -87,6 +87,6 @@ public abstract class ItemBlueprint extends ItemBuildCraft {
|
|||
}
|
||||
|
||||
public static BlueprintBase loadBlueprint(ItemStack stack) {
|
||||
return BuildCraftBuilders.serverDB.load (getId (stack));
|
||||
return BuildCraftBuilders.serverDB.load(getId(stack));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,6 +23,10 @@ public class ItemConstructionMarker extends ItemBlock {
|
|||
super(block);
|
||||
}
|
||||
|
||||
public static boolean linkStarted(ItemStack marker) {
|
||||
return NBTUtils.getItemData(marker).hasKey("x");
|
||||
}
|
||||
|
||||
public static void link(ItemStack marker, World world, int x, int y, int z) {
|
||||
NBTTagCompound nbt = NBTUtils.getItemData(marker);
|
||||
|
||||
|
@ -37,12 +41,16 @@ public class ItemConstructionMarker extends ItemBlock {
|
|||
TileArchitect architect = (TileArchitect) tile1;
|
||||
TileEntity tile2 = world.getTileEntity(x, y, z);
|
||||
|
||||
if (tile1 != tile2 && tile2 != null && (tile2 instanceof TileArchitect)) {
|
||||
architect.addSubBlueprint(tile2);
|
||||
if (tile1 != tile2 && tile2 != null) {
|
||||
if (tile2 instanceof TileArchitect
|
||||
|| tile2 instanceof TileConstructionMarker
|
||||
|| tile2 instanceof TileBuilder) {
|
||||
architect.addSubBlueprint(tile2);
|
||||
|
||||
nbt.removeTag("x");
|
||||
nbt.removeTag("y");
|
||||
nbt.removeTag("z");
|
||||
nbt.removeTag("x");
|
||||
nbt.removeTag("y");
|
||||
nbt.removeTag("z");
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
|
|
|
@ -57,7 +57,7 @@ public class TileConstructionMarker extends TileBuildCraft implements IBuildingI
|
|||
|
||||
@Override
|
||||
public void initialize() {
|
||||
box.kind = Kind.STRIPES;
|
||||
box.kind = Kind.BLUE_STRIPES;
|
||||
|
||||
if (worldObj.isRemote) {
|
||||
RPCHandler.rpcServer(this, "uploadBuildersInAction");
|
||||
|
|
|
@ -10,7 +10,6 @@ package buildcraft.core.blueprints;
|
|||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
|
@ -62,12 +61,9 @@ public class RecursiveBlueprintBuilder {
|
|||
return builder;
|
||||
}
|
||||
|
||||
// Free memory associated with this blueprint
|
||||
blueprint = null;
|
||||
|
||||
if (nextSubBlueprint >= subBlueprints.size()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (current != null) {
|
||||
BptBuilderBase builder = current.nextBuilder();
|
||||
|
||||
|
@ -76,6 +72,10 @@ public class RecursiveBlueprintBuilder {
|
|||
}
|
||||
}
|
||||
|
||||
if (nextSubBlueprint >= subBlueprints.size()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
NBTTagCompound nbt = subBlueprints.get(nextSubBlueprint);
|
||||
BlueprintBase bpt = BlueprintBase.loadBluePrint(nbt.getCompoundTag("bpt"));
|
||||
|
||||
|
@ -85,9 +85,6 @@ public class RecursiveBlueprintBuilder {
|
|||
|
||||
ForgeDirection nbtDir = ForgeDirection.values()[nbt.getByte("dir")];
|
||||
|
||||
// TODO: this is just here for debug, to be removed
|
||||
world.setBlock(nx, ny, nz, Blocks.sponge);
|
||||
|
||||
current = new RecursiveBlueprintBuilder(bpt, world, nx, ny, nz, nbtDir);
|
||||
nextSubBlueprint++;
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
package buildcraft.core.blueprints;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
|
@ -19,6 +20,8 @@ import buildcraft.builders.ItemBlueprint;
|
|||
import buildcraft.builders.ItemBlueprintStandard;
|
||||
import buildcraft.builders.ItemBlueprintTemplate;
|
||||
import buildcraft.builders.TileArchitect;
|
||||
import buildcraft.builders.TileBuilder;
|
||||
import buildcraft.builders.TileConstructionMarker;
|
||||
import buildcraft.core.BlockScanner;
|
||||
|
||||
public class RecursiveBlueprintReader {
|
||||
|
@ -95,9 +98,41 @@ public class RecursiveBlueprintReader {
|
|||
return;
|
||||
} else if (currentSubReader == null && subIndex < architect.subBlueprints.size()) {
|
||||
BlockIndex subBlock = architect.subBlueprints.get(subIndex);
|
||||
TileArchitect subArchitect = (TileArchitect) architect.getWorld().getTileEntity(subBlock.x, subBlock.y,
|
||||
|
||||
TileEntity subTile = architect.getWorld().getTileEntity(subBlock.x, subBlock.y,
|
||||
subBlock.z);
|
||||
currentSubReader = new RecursiveBlueprintReader(subArchitect, writingBlueprint);
|
||||
|
||||
if (subTile instanceof TileArchitect) {
|
||||
TileArchitect subArchitect = (TileArchitect) subTile;
|
||||
currentSubReader = new RecursiveBlueprintReader(subArchitect, writingBlueprint);
|
||||
} else if (subTile instanceof TileConstructionMarker || subTile instanceof TileBuilder) {
|
||||
BlueprintBase blueprint = null;
|
||||
ForgeDirection orientation = ForgeDirection.EAST;
|
||||
|
||||
if (subTile instanceof TileConstructionMarker) {
|
||||
TileConstructionMarker marker = (TileConstructionMarker) subTile;
|
||||
blueprint = ItemBlueprint.loadBlueprint(marker.itemBlueprint);
|
||||
orientation = marker.direction;
|
||||
} else if (subTile instanceof TileBuilder) {
|
||||
TileBuilder builder = (TileBuilder) subTile;
|
||||
blueprint = ItemBlueprint.loadBlueprint(builder.getStackInSlot(0));
|
||||
orientation = ForgeDirection.values()[architect.getWorld().getBlockMetadata(subBlock.x, subBlock.y,
|
||||
subBlock.z)].getOpposite();
|
||||
}
|
||||
|
||||
if (blueprint != null) {
|
||||
writingBlueprint.addSubBlueprint(
|
||||
blueprint,
|
||||
subTile.xCoord - architect.getBox().xMin,
|
||||
subTile.yCoord - architect.getBox().yMin,
|
||||
subTile.zCoord - architect.getBox().zMin,
|
||||
orientation);
|
||||
}
|
||||
|
||||
subIndex++;
|
||||
} else {
|
||||
subIndex++;
|
||||
}
|
||||
} else if (currentSubReader != null) {
|
||||
currentSubReader.iterate();
|
||||
|
||||
|
|
Loading…
Reference in a new issue