use of com.builtbroken.mc.imp.transform.vector.Pos in project ICBM-Classic by BuiltBrokenModding.
the class TileCruiseLauncher method onPlayerActivated.
@Override
public boolean onPlayerActivated(EntityPlayer player, int side, Pos hit) {
if (isServer()) {
boolean notNull = player.getHeldItem() != null;
if (notNull && player.getHeldItem().getItem() == Items.redstone) {
if (canLaunch()) {
launch();
} else {
player.addChatComponentMessage(new ChatComponentText(LanguageUtility.getLocal("chat.launcher.failedToFire")));
String translation = LanguageUtility.getLocal("chat.launcher.status");
translation = translation.replace("%1", getStatus());
player.addChatComponentMessage(new ChatComponentText(translation));
}
} else if (notNull && player.getHeldItem().getItem() instanceof IWorldPosItem) {
IWorldPosition location = ((IWorldPosItem) player.getHeldItem().getItem()).getLocation(player.getHeldItem());
if (location != null) {
if (location.world() == world()) {
setTarget(new Pos(location.x(), location.y(), location.z()));
player.addChatComponentMessage(new ChatComponentText(LanguageUtility.getLocal("chat.launcher.toolTargetSet")));
} else {
player.addChatComponentMessage(new ChatComponentText(LanguageUtility.getLocal("chat.launcher.toolWorldNotMatch")));
}
} else {
player.addChatComponentMessage(new ChatComponentText(LanguageUtility.getLocal("chat.launcher.noTargetInTool")));
}
} else {
player.openGui(ICBMClassic.INSTANCE, 0, this.worldObj, this.xCoord, this.yCoord, this.zCoord);
}
}
return true;
}
use of com.builtbroken.mc.imp.transform.vector.Pos in project Engine by VoltzEngine-Project.
the class Selection method getBlockLocations.
/**
* Grabs all blocks in the cube that match
*
* @param block - block instance to match against, if null will match all
* @param meta - meta value to match, if -1 will match all meta
* @param size - limiter for the list in case only a few blocks are wanted.
* If zero or less will not limit size
* @return list of blocks, never null but can be empty
*/
public List<Pos> getBlockLocations(Block block, int meta, int size) {
List<Pos> list = new LinkedList<>();
for (int y = min().yi(); y <= max().yi(); y++) {
for (int x = min().xi(); x <= max().xi(); x++) {
for (int z = min().zi(); z <= max().zi(); z++) {
if (size > 0 && list.size() > size)
return list;
Pos Pos = new Pos(x, y, z);
Block b = Pos.getBlock(world);
int m = Pos.getBlockMetadata(world);
if (block == null || b == block && (meta == -1 || m == meta)) {
list.add(Pos);
}
}
}
}
return list;
}
use of com.builtbroken.mc.imp.transform.vector.Pos in project Engine by VoltzEngine-Project.
the class RenderTaggedTile method renderTileEntityAt.
@Override
public void renderTileEntityAt(TileEntity t, double x, double y, double z, float f) {
if (t != null) {
if (t instanceof ITagRender && this.getPlayer().getDistance(t.xCoord, t.yCoord, t.zCoord) <= RendererLivingEntity.NAME_TAG_RANGE) {
HashMap<String, Integer> tags = new HashMap<>();
float height = ((ITagRender) t).addInformation(tags, this.getPlayer());
EntityPlayer player = Minecraft.getMinecraft().thePlayer;
if (player.ridingEntity == null) {
MovingObjectPosition objectPosition = player.rayTrace(8, 1);
if (objectPosition != null) {
boolean isLooking = false;
for (int h = 0; h < height; h++) {
if (objectPosition.blockX == t.xCoord && objectPosition.blockY == t.yCoord + h && objectPosition.blockZ == t.zCoord) {
isLooking = true;
}
}
if (isLooking) {
Iterator<Entry<String, Integer>> it = tags.entrySet().iterator();
int i = 0;
while (it.hasNext()) {
Entry<String, Integer> entry = it.next();
if (entry.getKey() != null) {
RenderUtility.renderFloatingText(entry.getKey(), new Pos(x, y, z).add(new Pos(0.5, i * 0.25f + height, 0.5f)), entry.getValue());
}
i++;
}
}
}
}
}
}
}
use of com.builtbroken.mc.imp.transform.vector.Pos in project Engine by VoltzEngine-Project.
the class OreGenReplace method generateBranch.
/**
* Picks a random location in the chunk based on a random rotation and Y value
*
* @param world - world
* @param rand - random
* @param varX - randomX
* @param varY - randomY
* @param varZ - randomZ
* @return true if it placed blocks
*/
public int generateBranch(World world, Random rand, int chunkCornerX, int chunkCornerZ, int varX, int varY, int varZ) {
int blocksPlaced = 0;
//MC default ore gen code, doesn't work well.... avoid
if (generatorType == 0) {
float angle = rand.nextFloat() * (float) Math.PI;
double rxUpper = varX + 8 + MathHelper.sin(angle) * settings.amountPerBranch / 8.0F;
double rxLower = varX + 8 - MathHelper.sin(angle) * settings.amountPerBranch / 8.0F;
double rzUpper = varZ + 8 + MathHelper.cos(angle) * settings.amountPerBranch / 8.0F;
double rzLower = varZ + 8 - MathHelper.cos(angle) * settings.amountPerBranch / 8.0F;
double randomY = varY + rand.nextInt(3) - 2;
double randomY2 = varY + rand.nextInt(3) - 2;
for (int b = 0; b <= settings.amountPerBranch; ++b) {
double var20 = rxUpper + (rxLower - rxUpper) * b / settings.amountPerBranch;
double var22 = randomY + (randomY2 - randomY) * b / settings.amountPerBranch;
double var24 = rzUpper + (rzLower - rzUpper) * b / settings.amountPerBranch;
double var26 = rand.nextDouble() * settings.amountPerBranch / 16.0D;
double var28 = (MathHelper.sin(b * (float) Math.PI / settings.amountPerBranch) + 1.0F) * var26 + 1.0D;
double var30 = (MathHelper.sin(b * (float) Math.PI / settings.amountPerBranch) + 1.0F) * var26 + 1.0D;
int startX = MathHelper.floor_double(var20 - var28 / 2.0D);
int startY = MathHelper.floor_double(var22 - var30 / 2.0D);
int startZ = MathHelper.floor_double(var24 - var28 / 2.0D);
int endX = MathHelper.floor_double(var20 + var28 / 2.0D);
int endY = MathHelper.floor_double(var22 + var30 / 2.0D);
int endZ = MathHelper.floor_double(var24 + var28 / 2.0D);
for (int px = startX; px <= endX; ++px) {
double deltaX = (px + 0.5D - var20) / (var28 / 2.0D);
if (deltaX * deltaX < 1.0D) {
for (int py = startY; py <= endY; ++py) {
double dy = (py + 0.5D - var22) / (var30 / 2.0D);
if (deltaX * deltaX + dy * dy < 1.0D) {
for (int pz = startZ; pz <= endZ; ++pz) {
double dz = (pz + 0.5D - var24) / (var28 / 2.0D);
Block block = world.getBlock(px, py, pz);
if (deltaX * deltaX + dy * dy + dz * dz < 1.0D && (settings.replaceBlock == null || block == settings.replaceBlock)) {
if (world.setBlock(px, py, pz, this.oreBlock, this.oreMeta, 2)) {
blocksPlaced++;
}
}
}
}
}
}
}
}
} else //Path finder ore gen
if (generatorType == 1) {
//Positions already pathed
List<Pos> pathed = new ArrayList();
//Positions to path next
Queue<Pos> toPath = new LinkedList();
//First location to path
toPath.add(new Pos(varX, varY, varZ));
List<ForgeDirection> directions = new ArrayList();
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
directions.add(dir);
}
//Breadth first search
while (!toPath.isEmpty() && blocksPlaced < settings.amountPerBranch) {
Pos next = toPath.poll();
pathed.add(next);
//Place block
Block block = next.getBlock(world);
if (settings.replaceBlock == null || block == settings.replaceBlock) {
if (next.setBlock(world, oreBlock, oreMeta, 2)) {
blocksPlaced += 1;
}
}
//Find new locations to place blocks
Collections.shuffle(directions);
for (ForgeDirection direction : directions) {
//TODO randomize next path
Pos pos = next.add(direction);
if (!pathed.contains(pos) && world.rand.nextBoolean()) {
if (pos.isInsideMap()) {
boolean insideX = pos.xi() >= chunkCornerX && pos.xi() < (chunkCornerX + 16);
boolean insideZ = pos.zi() >= chunkCornerZ && pos.zi() < (chunkCornerZ + 16);
boolean insideY = pos.yi() >= settings.minGenerateLevel && pos.yi() <= settings.maxGenerateLevel;
if (insideX && insideZ && insideY) {
block = pos.getBlock(world);
if (settings.replaceBlock == null || block == settings.replaceBlock) {
toPath.add(pos);
}
}
}
if (!toPath.contains(pos)) {
pathed.add(pos);
}
}
}
}
} else //Pre-cache ore gen
if (generatorType == 2) {
int blockToPlace = 1 + com.builtbroken.jlib.helpers.MathHelper.rand.nextInt(Math.max(1, settings.amountPerBranch - 1));
//TODO find templates that match block count
}
return blocksPlaced;
}
use of com.builtbroken.mc.imp.transform.vector.Pos in project Engine by VoltzEngine-Project.
the class FXElectricBolt method split.
/**
* Slits a large segment into multiple smaller ones.
*
* @param splitAmount - The amount of splits
* @param offset - The multiplier multiply for the offset.
* @param splitChance - The chance of creating a split.
* @param splitLength - The length of each split.
* @param splitAngle - The angle of the split.
*/
public void split(int splitAmount, double offset, float splitChance, float splitLength, float splitAngle) {
if (!this.isCalculated) {
/** Temporarily store old segments in a new array */
ArrayList<BoltSegment> oldSegments = this.segments;
this.segments = new ArrayList();
/** Previous segment */
BoltSegment prev = null;
for (BoltSegment segment : oldSegments) {
prev = segment.prevSegment;
Pos subSegment = segment.difference.multiply(1.0F / splitAmount);
/** Creates an array of new bolt points. The first and last points of the bolts are
* the respected start and end points of the current segment. */
BoltPoint[] newPoints = new BoltPoint[splitAmount + 1];
Pos startPoint = segment.startBolt.point;
newPoints[0] = segment.startBolt;
newPoints[splitAmount] = segment.endBolt;
for (int i = 1; i < splitAmount; i++) {
//Vector3 offsetVec = segment.difference.perpendicular().rotate(this.rand.nextFloat() * 360.0F, segment.difference).multiply((this.rand.nextFloat() - 0.5F) * offset);
Pos offsetVec = new Pos(segment.difference.perpendicular().transform(new Quaternion(this.rand.nextFloat() * 360.0F, segment.difference))).multiply((this.rand.nextFloat() - 0.5F) * offset);
Pos basepoint = startPoint.clone().add(subSegment.clone().multiply(i));
newPoints[i] = new BoltPoint(basepoint, offsetVec);
}
for (int i = 0; i < splitAmount; i++) {
BoltSegment next = new BoltSegment(newPoints[i], newPoints[(i + 1)], segment.weight, segment.segmentID * splitAmount + i, segment.splitID);
next.prevSegment = prev;
if (prev != null) {
prev.nextSegment = next;
}
if ((i != 0) && (this.rand.nextFloat() < splitChance)) {
//Vector3 splitrot = next.difference.xCross().rotate(this.rand.nextFloat() * 360.0F, next.difference);
Pos splitrot = new Pos(next.difference.xCross().transform(new Quaternion(this.rand.nextFloat() * 360.0F, next.difference)));
//Vector3 diff = next.difference.clone().rotate((this.rand.nextFloat() * 0.66F + 0.33F) * splitAngle, splitrot).multiply(splitLength);
Pos diff = new Pos(next.difference.clone().transform(new Quaternion((this.rand.nextFloat() * 0.66F + 0.33F) * splitAngle, splitrot))).multiply(splitLength);
this.maxSplitID += 1;
this.splitparents.put(this.maxSplitID, next.splitID);
BoltSegment split = new BoltSegment(newPoints[i], new BoltPoint(newPoints[(i + 1)].basePoint, newPoints[(i + 1)].offSet.clone().add(diff)), segment.weight / 2.0F, next.segmentID, this.maxSplitID);
split.prevSegment = prev;
this.segments.add(split);
}
prev = next;
this.segments.add(next);
}
if (segment.nextSegment != null) {
segment.nextSegment.prevSegment = prev;
}
}
this.segmentCount *= splitAmount;
}
}
Aggregations