Skip to content

Commit

Permalink
Attempt #1 at rotating array
Browse files Browse the repository at this point in the history
  • Loading branch information
mDiyo committed Sep 23, 2013
1 parent ef7b1d9 commit 0f60f5d
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 42 deletions.
103 changes: 72 additions & 31 deletions blockworks/items/CopyWand.java
Expand Up @@ -13,9 +13,6 @@
import java.util.List;
import java.util.Map;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
Expand All @@ -26,7 +23,8 @@
import net.minecraftforge.common.Configuration.UnicodeInputStreamReader;
import net.minecraftforge.common.ForgeDirection;
import blockworks.Blockworks;
import blockworks.util.BKeyHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

/*
* The great copy wand
Expand All @@ -44,9 +42,13 @@ public CopyWand(int id)
super(id);
}

@Override
public ItemStack onItemRightClick (ItemStack stack, World world, EntityPlayer player)
{
copyArea(player, stack);
if (player.isSneaking())
rotateStructure(player);
else
copyArea(player, stack);
return stack;
}

Expand All @@ -57,6 +59,39 @@ public boolean onEntitySwing (EntityLivingBase player, ItemStack stack)
return true;
}

public void rotateStructure (EntityPlayer player)
{

if (!player.worldObj.isRemote && player instanceof EntityPlayer)
((EntityPlayer) player).addChatMessage("Rotating Structure");

int xLength = blockIDs.length;
int yLength = blockIDs[0].length;
int zLength = blockIDs[0][0].length;
int[][][] tempIDs = new int[zLength][yLength][xLength];
int[][][] tempMeta = new int[zLength][yLength][xLength];

for (int y = 0; y < yLength; y++)
{
for (int x = 0; x < xLength; x++)
{
for (int z = 0; z < zLength; z++)
{
tempIDs[zLength - z - 1][y][x] = blockIDs[x][y][z]; //180 degrees?!
tempMeta[zLength - z - 1][y][x] = metadata[x][y][z];
}
}
}

blockIDs = tempIDs;
metadata = tempMeta;
}

boolean inside ()
{
return true;
}

public void copyArea (EntityLivingBase player, ItemStack stack)
{
MovingObjectPosition mop = this.raytraceFromPlayer(player.worldObj, player, false);
Expand All @@ -66,29 +101,32 @@ public void copyArea (EntityLivingBase player, ItemStack stack)
int xPos = mop.blockX;
int yPos = mop.blockY;
int zPos = mop.blockZ;
ForgeDirection sideHit = ForgeDirection.getOrientation(mop.sideHit);
switch (sideHit)
if (!inside())
{
case UP:
yPos += 1;
break;
case DOWN:
yPos -= 1;
break;
case NORTH:
zPos -= 1;
break;
case SOUTH:
zPos += 1;
break;
case EAST:
xPos += 1;
break;
case WEST:
xPos -= 1;
break;
default:
break;
ForgeDirection sideHit = ForgeDirection.getOrientation(mop.sideHit);
switch (sideHit)
{
case UP:
yPos += 1;
break;
case DOWN:
yPos -= 1;
break;
case NORTH:
zPos -= 1;
break;
case SOUTH:
zPos += 1;
break;
case EAST:
xPos += 1;
break;
case WEST:
xPos -= 1;
break;
default:
break;
}
}
NBTTagCompound tags = stack.getTagCompound().getCompoundTag("Wandworks");
byte clicks = tags.getByte("clicks");
Expand Down Expand Up @@ -198,13 +236,18 @@ public void placeCopy (EntityLivingBase player, ItemStack stack)
}
}

String structureName ()
{
return "structure";
}

@Override
public void saveKey ()
{
System.out.println("Saving structure");
if (blockIDs.length > 0)
{
File structure = new File(Blockworks.structureFolder.getAbsolutePath() + "/structure.txt");
File structure = new File(Blockworks.structureFolder.getAbsolutePath() + "/" + structureName() + ".txt");
FileOutputStream fos;
try
{
Expand Down Expand Up @@ -264,7 +307,7 @@ void writeBlockAmounts (BufferedWriter writer) throws IOException
public void loadKey ()
{
System.out.println("Loading structure");
File file = new File(Blockworks.structureFolder.getAbsolutePath() + "/structure.txt");
File file = new File(Blockworks.structureFolder.getAbsolutePath() + "/" + structureName() + ".txt");

BufferedReader reader = null;
UnicodeInputStreamReader input = null;
Expand Down Expand Up @@ -356,7 +399,5 @@ public void addInformation (ItemStack stack, EntityPlayer player, List list, boo
list.add("\u00a7bCopies the world data between two points");
list.add("\u00a7bRight-click: Select two points to copy");
list.add("\u00a7bLeft-click: Paste copied data into the world");
list.add("\u00a7bSave: "+BKeyHandler.save.keyCode);
list.add("\u00a7bLoad: "+BKeyHandler.load.keyCode);
}
}
11 changes: 0 additions & 11 deletions blockworks/util/StructureData.java

This file was deleted.

0 comments on commit 0f60f5d

Please sign in to comment.