package ru.justagod.jam.helper;
/**
* Created by JustAGod on 18.11.17.
*/
public enum BlockSide {
UP(1), DOWN(0), FRONT(3), BACK(2), LEFT(4), RIGHT(5);
public final int side;
BlockSide(int side) {
this.side = side;
}
public static BlockSide getBySide(int side) {
if (side == 1) {
return UP;
} else if (side == 0) {
return DOWN;
} else if (side == 2) {
return BACK;
} else if (side == 3) {
return FRONT;
} else if (side == 4) {
return LEFT;
} else if (side == 5) {
return RIGHT;
}...
package ru.justagod.jam.helper;
/**
* Created by JustAGod on 18.11.17.
*/
public enum BlockSide {
UP(1), DOWN(0), FRONT(3), BACK(2), LEFT(4), RIGHT(5);
public final int side;
BlockSide(int side) {
this.side = side;
}
public static BlockSide getBySide(int side) {
if (side == 1) {
return UP;
} else if (side == 0) {
return DOWN;
} else if (side == 2) {
return BACK;
} else if (side == 3) {
return FRONT;
} else if (side == 4) {
return LEFT;
} else if (side == 5) {
return RIGHT;
} else return null;
}
public Vector modifyVector(Vector vector) {
switch (this) {
case UP:
return new Vector(vector.getX(), vector.getY() + 1, vector.getZ());
case DOWN:
return new Vector(vector.getX(), vector.getY() - 1, vector.getZ());
case FRONT:
return new Vector(vector.getX(), vector.getY(), vector.getZ() + 1);
case BACK:
return new Vector(vector.getX(), vector.getY(), vector.getZ() - 1);
case LEFT:
return new Vector(vector.getX() - 1, vector.getY(), vector.getZ());
case RIGHT:
return new Vector(vector.getX() + 1, vector.getY(), vector.getZ());
default:
return null;
}
}
}
package ru.justagod.jam.helper;
import static java.lang.Math.pow;
import static java.lang.Math.sqrt;
/**
* Created by JustAGod on 19.11.17.
*/
public class Vector {
private double x, y, z;
public Vector(double x, double y, double z) {
this.x = x;
this.y = y;
this.z = z;
}
public Vector(double x, double y) {
this.x = x;
this.y = y;
this.z = 0;
}
public double getX() {
return x;
}
public double getY() {
return y;
}
public double getZ() {
return z;
}
public int getIntX() {
return (int) x;
}
public int getIntY() {
return (int) y;
}
public int getIntZ() {
return (int) z;
}
public Vector substract(Vector v) {
return new Vector(x - v.x, y - v.y, z - v.z);
}
public Vector add(Vector v) {
return new Vector(x + v.x, y + v.y, z + v.z);
}
public double length() {
return sqrt(pow(x, 2) + pow(y, 2) + pow(z, 2));
}
public Vector multiply(double speed) {
return new Vector(x * speed, y * speed, z * speed);
}
public Vector normalize() {
return new Vector(x / length(), y / length(), z / length());
}
}
package ru.justagod.jam.common.block;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.block.material.Material;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.MathHelper;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import ru.justagod.jam.common.tile.TileHelp;
import static ru.justagod.jam.helper.BlockSide.*;
/**
* Created by JustAGod on 27.11.17.
*/
public class BlockHelp extends BlockJam implements ITileEntityProvider{
public BlockHelp(Material material) {
super(material);
}
@Override
public void setBlockBoundsBasedOnState(IBlockAccess world, int x, int y, int z) {
TileHelp tile = (TileHelp) world.getTileEntity(x, y, z);
setBlockBounds(tile.decreases[LEFT.side] * 0.1f,tile.decreases[DOWN.side] * 0.1f, tile.decreases[BACK.side] * 0.1f, 1 - tile.decreases[RIGHT.side] * 0.1f, 1 - tile.decreases[UP.side] * 0.1f, 1 - tile.decreases[FRONT.side] * 0.1f);
}
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) {
TileHelp tile = (TileHelp) world.getTileEntity(x, y, z);
tile.decreases[side] = MathHelper.clamp_int(tile.decreases[side] + 1, 0, 5);
return true;
}
@Override
public TileEntity createNewTileEntity(World p_149915_1_, int p_149915_2_) {
return new TileHelp();
}
}
package ru.justagod.jam.common.tile;
import net.minecraft.nbt.NBTTagCompound;
/**
* Created by JustAGod on 27.11.17.
*/
public class TileHelp extends JamTile {
public int[] decreases = new int[6];
@Override
protected void readExtra(NBTTagCompound compound) {
decreases = compound.getIntArray("decreases");
}
@Override
protected void writeExtra(NBTTagCompound compound) {
compound.setIntArray("decreases", decreases);
}
}
package ru.justagod.jam.common.tile;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.Packet;
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;
import ru.justagod.jam.helper.Vector;
/**
* Created by JustAGod on 18.11.17.
*/
public abstract class JamTile extends TileEntity {
@Override
public final void writeToNBT(NBTTagCompound compound) {
super.writeToNBT(compound);
writeExtra(compound);
}
@Override
public final void readFromNBT(NBTTagCompound compound) {
super.readFromNBT(compound);
readExtra(compound);
}
@Override
public Packet getDescriptionPacket() {
NBTTagCompound compound = new NBTTagCompound();
writeToNBT(compound);
return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, blockMetadata, compound);
}
public Vector getPos() {
return new Vector(xCoord, yCoord, zCoord);
}
@Override
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) {
readFromNBT(pkt.func_148857_g());
}
protected abstract void readExtra(NBTTagCompound compound);
protected abstract void writeExtra(NBTTagCompound compound);
}
У меня глаза на лоб полезли, прости. Почему у тебя вектор из трёх координат здесь внезапно превращается в двумерный вектор, и возвращает неправильную длину для случая с ненулевой z координатой?Java:public class Vector { public double length() { return sqrt(pow(x, 2) + pow(y, 2)); } public Vector multiply(double speed) { return new Vector(x * speed, y * speed); } public Vector normalize() { return new Vector(x / length(), y / length()); } }