Fix offset calculation (logic derp)

This commit is contained in:
Pahimar 2014-10-21 15:05:11 -04:00
parent 1a6698c073
commit bbfb204472

View file

@ -9,6 +9,7 @@ import com.pahimar.ee3.settings.ChalkSettings;
import com.pahimar.ee3.tileentity.TileEntityDummyArray;
import com.pahimar.ee3.util.EntityHelper;
import com.pahimar.ee3.util.IKeyBound;
import com.pahimar.ee3.util.LogHelper;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
@ -17,14 +18,17 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
public class ItemChalk extends ItemEE implements IKeyBound {
public ItemChalk() {
public class ItemChalk extends ItemEE implements IKeyBound
{
public ItemChalk()
{
super();
this.setUnlocalizedName(Names.Items.CHALK);
}
@Override
public boolean getShareTag() {
public boolean getShareTag()
{
return true;
}
@ -33,23 +37,38 @@ public class ItemChalk extends ItemEE implements IKeyBound {
* True if something happen and false if it don't. This is for ITEMS, not BLOCKS
*/
@Override
public boolean onItemUse(ItemStack itemStack, EntityPlayer entityPlayer, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) {
if (!world.isRemote) {
if (side == 0) {
public boolean onItemUse(ItemStack itemStack, EntityPlayer entityPlayer, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ)
{
if (!world.isRemote)
{
if (side == 0)
{
--y;
} else if (side == 1) {
}
else if (side == 1)
{
++y;
} else if (side == 2) {
}
else if (side == 2)
{
--z;
} else if (side == 3) {
}
else if (side == 3)
{
++z;
} else if (side == 4) {
}
else if (side == 4)
{
--x;
} else if (side == 5) {
}
else if (side == 5)
{
++x;
}
if (canPlaceAlchemyArray(itemStack, entityPlayer, world, x, y, z, side)) {
LogHelper.info(String.format("x: %s, y: %s, z: %s", x, y, z));
if (canPlaceAlchemyArray(itemStack, entityPlayer, world, x, y, z, side))
{
placeAlchemyArray(itemStack, entityPlayer, world, x, y, z, side);
return true;
}
@ -58,36 +77,53 @@ public class ItemChalk extends ItemEE implements IKeyBound {
return false;
}
private boolean canPlaceAlchemyArray(ItemStack itemStack, EntityPlayer entityPlayer, World world, int x, int y, int z, int side) {
if (!world.isRemote) {
private boolean canPlaceAlchemyArray(ItemStack itemStack, EntityPlayer entityPlayer, World world, int x, int y, int z, int side)
{
if (!world.isRemote)
{
NBTTagCompound playerCustomData = EntityHelper.getCustomEntityData(entityPlayer);
ChalkSettings chalkSettings = new ChalkSettings();
chalkSettings.readFromNBT(playerCustomData);
int coordOffset = chalkSettings.getSize() / 2;
int coordOffset = getOffsetForSize(chalkSettings.getSize());
ForgeDirection orientation = ForgeDirection.getOrientation(side);
boolean canPlaceAlchemyArray = ModBlocks.alchemyArray.canPlaceBlockOnSide(world, x, y, z, side);
if (canPlaceAlchemyArray) {
if (orientation == ForgeDirection.UP || orientation == ForgeDirection.DOWN) {
for (int i = x - coordOffset; i <= x + coordOffset; i++) {
for (int j = z - coordOffset; j <= z + coordOffset; j++) {
if ((i != x || j != z) && (!ModBlocks.dummyArray.canPlaceBlockOnSide(world, i, y, j, side) || world.getTileEntity(i, y, j) instanceof TileEntityDummyArray)) {
if (canPlaceAlchemyArray)
{
if (orientation == ForgeDirection.UP || orientation == ForgeDirection.DOWN)
{
for (int i = x - coordOffset; i <= x + coordOffset; i++)
{
for (int j = z - coordOffset; j <= z + coordOffset; j++)
{
if ((i != x || j != z) && (!ModBlocks.dummyArray.canPlaceBlockOnSide(world, i, y, j, side) || world.getTileEntity(i, y, j) instanceof TileEntityDummyArray))
{
canPlaceAlchemyArray = false;
}
}
}
} else if (orientation == ForgeDirection.NORTH || orientation == ForgeDirection.SOUTH) {
for (int i = x - coordOffset; i <= x + coordOffset; i++) {
for (int j = y - coordOffset; j <= y + coordOffset; j++) {
if ((i != x || j != y) && (!ModBlocks.dummyArray.canPlaceBlockOnSide(world, i, j, z, side) || world.getTileEntity(i, j, z) instanceof TileEntityDummyArray)) {
}
else if (orientation == ForgeDirection.NORTH || orientation == ForgeDirection.SOUTH)
{
for (int i = x - coordOffset; i <= x + coordOffset; i++)
{
for (int j = y - coordOffset; j <= y + coordOffset; j++)
{
if ((i != x || j != y) && (!ModBlocks.dummyArray.canPlaceBlockOnSide(world, i, j, z, side) || world.getTileEntity(i, j, z) instanceof TileEntityDummyArray))
{
canPlaceAlchemyArray = false;
}
}
}
} else if (orientation == ForgeDirection.EAST || orientation == ForgeDirection.WEST) {
for (int i = y - coordOffset; i <= y + coordOffset; i++) {
for (int j = z - coordOffset; j <= z + coordOffset; j++) {
if ((i != y || j != z) && (!ModBlocks.dummyArray.canPlaceBlockOnSide(world, x, i, j, side) || world.getTileEntity(x, i, j) instanceof TileEntityDummyArray)) {
}
else if (orientation == ForgeDirection.EAST || orientation == ForgeDirection.WEST)
{
for (int i = y - coordOffset; i <= y + coordOffset; i++)
{
for (int j = z - coordOffset; j <= z + coordOffset; j++)
{
if ((i != y || j != z) && (!ModBlocks.dummyArray.canPlaceBlockOnSide(world, x, i, j, side) || world.getTileEntity(x, i, j) instanceof TileEntityDummyArray))
{
canPlaceAlchemyArray = false;
}
}
@ -101,33 +137,46 @@ public class ItemChalk extends ItemEE implements IKeyBound {
return false;
}
private void placeAlchemyArray(ItemStack itemStack, EntityPlayer entityPlayer, World world, int x, int y, int z, int side) {
if (!world.isRemote) {
private void placeAlchemyArray(ItemStack itemStack, EntityPlayer entityPlayer, World world, int x, int y, int z, int side)
{
if (!world.isRemote)
{
NBTTagCompound playerCustomData = EntityHelper.getCustomEntityData(entityPlayer);
ChalkSettings chalkSettings = new ChalkSettings();
chalkSettings.readFromNBT(playerCustomData);
int coordOffset = chalkSettings.getSize() / 2;
int coordOffset = getOffsetForSize(chalkSettings.getSize());
ForgeDirection orientation = ForgeDirection.getOrientation(side);
boolean canPlaceAlchemyArray = ModBlocks.alchemyArray.canPlaceBlockOnSide(world, x, y, z, side);
placeBlockAt(entityPlayer, itemStack, world, x, y, z, ModBlocks.alchemyArray, side);
if (canPlaceAlchemyArray) {
if (orientation == ForgeDirection.UP || orientation == ForgeDirection.DOWN) {
for (int i = x - coordOffset; i <= x + coordOffset; i++) {
for (int j = z - coordOffset; j <= z + coordOffset; j++) {
if (i != x || j != z) {
if (canPlaceAlchemyArray)
{
if (orientation == ForgeDirection.UP || orientation == ForgeDirection.DOWN)
{
for (int i = x - coordOffset; i <= x + coordOffset; i++)
{
for (int j = z - coordOffset; j <= z + coordOffset; j++)
{
if (i != x || j != z)
{
placeBlockAt(entityPlayer, itemStack, world, i, y, j, ModBlocks.dummyArray, side);
if (world.getTileEntity(i, y, j) instanceof TileEntityDummyArray) {
if (world.getTileEntity(i, y, j) instanceof TileEntityDummyArray)
{
((TileEntityDummyArray) world.getTileEntity(i, y, j)).setTrueCoords(x, y, z);
}
}
}
}
} else if (orientation == ForgeDirection.NORTH || orientation == ForgeDirection.SOUTH) {
for (int i = x - coordOffset; i <= x + coordOffset; i++) {
for (int j = y - coordOffset; j <= y + coordOffset; j++) {
if (i != x || j != y) {
}
else if (orientation == ForgeDirection.NORTH || orientation == ForgeDirection.SOUTH)
{
for (int i = x - coordOffset; i <= x + coordOffset; i++)
{
for (int j = y - coordOffset; j <= y + coordOffset; j++)
{
if (i != x || j != y)
{
placeBlockAt(entityPlayer, itemStack, world, i, j, z, ModBlocks.dummyArray, side);
{
((TileEntityDummyArray) world.getTileEntity(i, j, z)).setTrueCoords(x, y, z);
@ -135,10 +184,15 @@ public class ItemChalk extends ItemEE implements IKeyBound {
}
}
}
} else if (orientation == ForgeDirection.EAST || orientation == ForgeDirection.WEST) {
for (int i = y - coordOffset; i <= y + coordOffset; i++) {
for (int j = z - coordOffset; j <= z + coordOffset; j++) {
if (i != y || j != z) {
}
else if (orientation == ForgeDirection.EAST || orientation == ForgeDirection.WEST)
{
for (int i = y - coordOffset; i <= y + coordOffset; i++)
{
for (int j = z - coordOffset; j <= z + coordOffset; j++)
{
if (i != y || j != z)
{
placeBlockAt(entityPlayer, itemStack, world, x, i, j, ModBlocks.dummyArray, side);
{
((TileEntityDummyArray) world.getTileEntity(x, i, j)).setTrueCoords(x, y, z);
@ -157,12 +211,15 @@ public class ItemChalk extends ItemEE implements IKeyBound {
* @param itemStack The item stack that was used to place the block. This can be changed inside the method.
* @param entityPlayer The entityPlayer who is placing the block. Can be null if the block is not being placed by a entityPlayer.
*/
private boolean placeBlockAt(EntityPlayer entityPlayer, ItemStack itemStack, World world, int x, int y, int z, Block block, int metadata) {
if (!world.setBlock(x, y, z, block, metadata, 3)) {
private boolean placeBlockAt(EntityPlayer entityPlayer, ItemStack itemStack, World world, int x, int y, int z, Block block, int metadata)
{
if (!world.setBlock(x, y, z, block, metadata, 3))
{
return false;
}
if (world.getBlock(x, y, z) == block) {
if (world.getBlock(x, y, z) == block)
{
block.onBlockPlacedBy(world, x, y, z, entityPlayer, itemStack);
block.onPostBlockPlaced(world, x, y, z, metadata);
}
@ -171,28 +228,44 @@ public class ItemChalk extends ItemEE implements IKeyBound {
}
@Override
public void doKeyBindingAction(EntityPlayer entityPlayer, ItemStack itemStack, Key key) {
if (key != Key.UNKNOWN) {
public void doKeyBindingAction(EntityPlayer entityPlayer, ItemStack itemStack, Key key)
{
if (key != Key.UNKNOWN)
{
NBTTagCompound playerCustomData = EntityHelper.getCustomEntityData(entityPlayer);
ChalkSettings chalkSettings = new ChalkSettings();
chalkSettings.readFromNBT(playerCustomData);
if (key == Key.CHARGE) {
if (!entityPlayer.isSneaking()) {
if (key == Key.CHARGE)
{
if (!entityPlayer.isSneaking())
{
chalkSettings.incrementSize();
} else {
}
else
{
chalkSettings.decrementSize();
}
} else if (key == Key.TOGGLE) {
if (!entityPlayer.isSneaking()) {
}
else if (key == Key.TOGGLE)
{
if (!entityPlayer.isSneaking())
{
chalkSettings.incrementIndex();
} else {
}
else
{
chalkSettings.decrementIndex();
}
} else if (key == Key.RELEASE) {
if (!entityPlayer.isSneaking()) {
}
else if (key == Key.RELEASE)
{
if (!entityPlayer.isSneaking())
{
chalkSettings.rotateClockwise();
} else {
}
else
{
chalkSettings.rotateCounterClockwise();
}
}
@ -203,4 +276,25 @@ public class ItemChalk extends ItemEE implements IKeyBound {
}
}
private static int getOffsetForSize(int size)
{
if (size == 1)
{
return 0;
}
else if (size == 2 || size == 3)
{
return 1;
}
else if (size == 4 || size == 5)
{
return 2;
}
else if (size == 6 || size == 7)
{
return 3;
}
return 0;
}
}