use of net.minecraft.util.math.BlockPos in project Realistic-Terrain-Generation by Team-RTG.
the class TreeRTGCeibaRosea method generateLeaves.
public void generateLeaves(World world, Random rand, float x, float y, float z, float size, float width) {
float dist;
int i, j, k, s = (int) (size - 1f), w = (int) ((size - 1f) * width);
for (i = -w; i <= w; i++) {
for (j = -s + 1; j <= s; j++) {
for (k = -w; k <= w; k++) {
dist = Math.abs((float) i / width) + (float) Math.abs(j) + Math.abs((float) k / width);
if (dist <= size - 0.5f || (dist <= size && rand.nextBoolean())) {
if (dist < 1.3f) {
this.placeLogBlock(world, new BlockPos((int) x + i, (int) y + j, (int) z + k), this.logBlock, this.generateFlag);
}
if (!this.noLeaves) {
this.placeLeavesBlock(world, new BlockPos((int) x + i, (int) y + j, (int) z + k), this.leavesBlock, this.generateFlag);
}
}
}
}
}
}
use of net.minecraft.util.math.BlockPos in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class WorldPhysicsCollider method updatePotentialCollisionCache.
private void updatePotentialCollisionCache() {
final AxisAlignedBB collisionBB = parent.collisionBB.expand(expansion, expansion, expansion).addCoord(calculator.linearMomentum.X * calculator.invMass, calculator.linearMomentum.Y * calculator.invMass, calculator.linearMomentum.Z * calculator.invMass);
ticksSinceCacheUpdate = 0D;
//in the same tick
if (Math.random() > .5) {
ticksSinceCacheUpdate -= .05D;
}
// cachedPotentialHits = new ArrayList<BlockPos>();
cachedPotentialHits = new TIntArrayList();
// Ship is outside of world blockSpace, just skip this all together
if (collisionBB.maxY < 0 || collisionBB.minY > 255) {
// internalCachedPotentialHits = new BlockPos[0];
return;
}
//Has a -1 on the minY value, I hope this helps with preventing things from falling through the floor
final BlockPos min = new BlockPos(collisionBB.minX, Math.max(collisionBB.minY - 1, 0), collisionBB.minZ);
final BlockPos max = new BlockPos(collisionBB.maxX, Math.min(collisionBB.maxY, 255), collisionBB.maxZ);
centerPotentialHit = new BlockPos((min.getX() + max.getX()) / 2D, (min.getY() + max.getY()) / 2D, (min.getZ() + max.getZ()) / 2D);
final ChunkCache cache = parent.surroundingWorldChunksCache;
final Vector inLocal = new Vector();
int maxX, maxY, maxZ, localX, localY, localZ, x, y, z, chunkX, chunkZ;
double rangeCheck = 1.8D;
if (ValkyrienWarfareMod.highAccuracyCollisions) {
rangeCheck = 3D;
}
Chunk chunk, chunkIn;
ExtendedBlockStorage extendedblockstorage;
IBlockState state, localState;
int chunkMinX = min.getX() >> 4;
int chunkMaxX = (max.getX() >> 4) + 1;
int storageMinY = min.getY() >> 4;
int storageMaxY = (max.getY() >> 4) + 1;
int chunkMinZ = min.getZ() >> 4;
int chunkMaxZ = (max.getZ() >> 4) + 1;
int storageY;
int mmX = min.getX(), mmY = min.getY(), mmZ = min.getZ(), mxX = max.getX(), mxY = max.getY(), mxZ = max.getZ();
Vector inBody = new Vector();
Vector speedInBody = new Vector();
for (chunkX = chunkMinX; chunkX < chunkMaxX; chunkX++) {
for (chunkZ = chunkMinZ; chunkZ < chunkMaxZ; chunkZ++) {
int arrayChunkX = chunkX - cache.chunkX;
int arrayChunkZ = chunkZ - cache.chunkZ;
if (!(arrayChunkX < 0 || arrayChunkZ < 0 || arrayChunkX > cache.chunkArray.length - 1 || arrayChunkZ > cache.chunkArray[0].length - 1)) {
chunk = cache.chunkArray[arrayChunkX][arrayChunkZ];
for (storageY = storageMinY; storageY < storageMaxY; storageY++) {
extendedblockstorage = chunk.storageArrays[storageY];
if (extendedblockstorage != null) {
int minStorageX = chunkX << 4;
int minStorageY = storageY << 4;
int minStorageZ = chunkZ << 4;
int maxStorageX = minStorageX + 16;
int maxStorageY = minStorageY + 16;
int maxStorageZ = minStorageZ + 16;
minStorageX = Math.max(minStorageX, mmX);
minStorageY = Math.max(minStorageY, mmY);
minStorageZ = Math.max(minStorageZ, mmZ);
maxStorageX = Math.min(maxStorageX, mxX);
maxStorageY = Math.min(maxStorageY, mxY);
maxStorageZ = Math.min(maxStorageZ, mxZ);
for (x = minStorageX; x < maxStorageX; x++) {
for (y = minStorageY; y < maxStorageY; y++) {
for (z = minStorageZ; z < maxStorageZ; z++) {
state = extendedblockstorage.get(x & 15, y & 15, z & 15);
if (state.getMaterial().isSolid()) {
inLocal.X = x + .5D;
inLocal.Y = y + .5D;
inLocal.Z = z + .5D;
parent.coordTransform.fromGlobalToLocal(inLocal);
inBody.setSubtraction(inLocal, parent.centerCoord);
parent.physicsProcessor.setVectorToVelocityAtPoint(inBody, speedInBody);
speedInBody.multiply(-parent.physicsProcessor.physRawSpeed);
if (ValkyrienWarfareMod.highAccuracyCollisions) {
speedInBody.multiply(20D);
}
// System.out.println(speedInBody);
int minX, minY, minZ;
if (speedInBody.X > 0) {
minX = MathHelper.floor_double(inLocal.X - rangeCheck);
maxX = MathHelper.floor_double(inLocal.X + rangeCheck + speedInBody.X);
} else {
minX = MathHelper.floor_double(inLocal.X - rangeCheck + speedInBody.X);
maxX = MathHelper.floor_double(inLocal.X + rangeCheck);
}
if (speedInBody.Y > 0) {
minY = MathHelper.floor_double(inLocal.Y - rangeCheck);
maxY = MathHelper.floor_double(inLocal.Y + rangeCheck + speedInBody.Y);
} else {
minY = MathHelper.floor_double(inLocal.Y - rangeCheck + speedInBody.Y);
maxY = MathHelper.floor_double(inLocal.Y + rangeCheck);
}
if (speedInBody.Z > 0) {
minZ = MathHelper.floor_double(inLocal.Z - rangeCheck);
maxZ = MathHelper.floor_double(inLocal.Z + rangeCheck + speedInBody.Z);
} else {
minZ = MathHelper.floor_double(inLocal.Z - rangeCheck + speedInBody.Z);
maxZ = MathHelper.floor_double(inLocal.Z + rangeCheck);
}
/** The Old Way of doing things; approx. 33% slower overall when running this code instead of new
for (localX = minX; localX < maxX; localX++) {
for (localZ = minZ; localZ < maxZ; localZ++) {
for (localY = minY; localY < maxY; localY++) {
if (parent.ownsChunk(localX >> 4, localZ >> 4)) {
chunkIn = parent.VKChunkCache.getChunkAt(localX >> 4, localZ >> 4);
localState = chunkIn.getBlockState(localX, localY, localZ);
if (localState.getMaterial().isSolid()) {
cachedPotentialHits.add(SpatialDetector.getHashWithRespectTo(x, y, z, centerPotentialHit));
localX = localY = localZ = Integer.MAX_VALUE - 420;
}
}
}
}
}
**/
int shipChunkMinX = minX >> 4;
int shipChunkMinY = Math.max(minY >> 4, 0);
int shipChunkMinZ = minZ >> 4;
int shipChunkMaxX = maxX >> 4;
int shipChunkMaxY = Math.min(maxY >> 4, 15);
int shipChunkMaxZ = maxZ >> 4;
shipChunkMaxX++;
shipChunkMaxY++;
shipChunkMaxZ++;
if (shipChunkMaxZ - shipChunkMinZ > 200 || shipChunkMaxX - shipChunkMinX > 200) {
System.err.println("Wtf. This fucking error");
return;
}
testForNearbyBlocks: for (int shipChunkX = shipChunkMinX; shipChunkX < shipChunkMaxX; shipChunkX++) {
for (int shipChunkZ = shipChunkMinZ; shipChunkZ < shipChunkMaxZ; shipChunkZ++) {
if (parent.ownsChunk(shipChunkX, shipChunkZ)) {
chunkIn = parent.VKChunkCache.getChunkAt(shipChunkX, shipChunkZ);
for (int shipChunkYStorage = shipChunkMinY; shipChunkYStorage < shipChunkMaxY; shipChunkYStorage++) {
ExtendedBlockStorage storage = chunkIn.storageArrays[shipChunkYStorage];
if (storage != null) {
int shipStorageMinX = shipChunkX << 4;
int shipStorageMinY = shipChunkYStorage << 4;
int shipStorageMinZ = shipChunkZ << 4;
int shipStorageMaxX = shipStorageMinX + 16;
int shipStorageMaxY = shipStorageMinY + 16;
int shipStorageMaxZ = shipStorageMinZ + 16;
shipStorageMinX = Math.max(shipStorageMinX, minX);
shipStorageMinY = Math.max(shipStorageMinY, minY);
shipStorageMinZ = Math.max(shipStorageMinZ, minZ);
shipStorageMaxX = Math.min(shipStorageMaxX, maxX);
shipStorageMaxY = Math.min(shipStorageMaxY, maxY);
shipStorageMaxZ = Math.min(shipStorageMaxZ, maxZ);
for (localX = shipStorageMinX; localX < shipStorageMaxX; localX++) {
for (localY = shipStorageMinY; localY < shipStorageMaxY; localY++) {
for (localZ = shipStorageMinZ; localZ < shipStorageMaxZ; localZ++) {
localState = chunkIn.getBlockState(localX, localY, localZ);
if (localState.getMaterial().isSolid()) {
cachedPotentialHits.add(SpatialDetector.getHashWithRespectTo(x, y, z, centerPotentialHit));
break testForNearbyBlocks;
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
/**
for (x = min.getX(); x <= max.getX(); x++) {
for (z = min.getZ(); z < max.getZ(); z++) {
chunkX = (x >> 4) - cache.chunkX;
chunkZ = (z >> 4) - cache.chunkZ;
if (!(chunkX < 0 || chunkZ < 0 || chunkX > cache.chunkArray.length - 1 || chunkZ > cache.chunkArray[0].length - 1)) {
chunk = cache.chunkArray[chunkX][chunkZ];
for (y = min.getY(); y < max.getY(); y++) {
extendedblockstorage = chunk.storageArrays[y >> 4];
if (extendedblockstorage != null) {
state = extendedblockstorage.get(x & 15, y & 15, z & 15);
if (state.getMaterial().isSolid()) {
inLocal.X = x + .5D;
inLocal.Y = y + .5D;
inLocal.Z = z + .5D;
parent.coordTransform.fromGlobalToLocal(inLocal);
maxX = (int) Math.floor(inLocal.X + rangeCheck);
maxY = (int) Math.floor(inLocal.Y + rangeCheck);
maxZ = (int) Math.floor(inLocal.Z + rangeCheck);
for (localX = MathHelper.floor_double(inLocal.X - rangeCheck); localX < maxX; localX++) {
for (localZ = MathHelper.floor_double(inLocal.Z - rangeCheck); localZ < maxZ; localZ++) {
for (localY = MathHelper.floor_double(inLocal.Y - rangeCheck); localY < maxY; localY++) {
if (parent.ownsChunk(localX >> 4, localZ >> 4)) {
chunkIn = parent.VKChunkCache.getChunkAt(localX >> 4, localZ >> 4);
localState = chunkIn.getBlockState(localX, localY, localZ);
if (localState.getMaterial().isSolid()) {
cachedPotentialHits.add(SpatialDetector.getHashWithRespectTo(x, y, z, centerPotentialHit));
localX = localY = localZ = Integer.MAX_VALUE - 420;
}
}
}
}
}
}
}
}
}
}
}
**/
cachedPotentialHits.shuffle(rand);
}
use of net.minecraft.util.math.BlockPos in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class CallRunnerClient method renderTileEntity.
public static void renderTileEntity(TileEntityRendererDispatcher dispatch, TileEntity tileentityIn, float partialTicks, int destroyStage) {
BlockPos pos = tileentityIn.getPos();
PhysicsWrapperEntity wrapper = ValkyrienWarfareMod.physicsManager.getObjectManagingPos(tileentityIn.getWorld(), pos);
if (wrapper != null && wrapper.wrapping != null && wrapper.wrapping.renderer != null) {
try {
boolean drawingBatchOrig = drawingBatchName.getBoolean(dispatch);
if (drawingBatchOrig) {
dispatch.drawBatch(MinecraftForgeClient.getRenderPass());
dispatch.preDrawBatch();
}
wrapper.wrapping.renderer.setupTranslation(partialTicks);
double playerX = TileEntityRendererDispatcher.instance.staticPlayerX;
double playerY = TileEntityRendererDispatcher.instance.staticPlayerY;
double playerZ = TileEntityRendererDispatcher.instance.staticPlayerZ;
TileEntityRendererDispatcher.instance.staticPlayerX = wrapper.wrapping.renderer.offsetPos.getX();
TileEntityRendererDispatcher.instance.staticPlayerY = wrapper.wrapping.renderer.offsetPos.getY();
TileEntityRendererDispatcher.instance.staticPlayerZ = wrapper.wrapping.renderer.offsetPos.getZ();
if (drawingBatchOrig) {
dispatch.renderTileEntity(tileentityIn, partialTicks, destroyStage);
dispatch.drawBatch(MinecraftForgeClient.getRenderPass());
dispatch.preDrawBatch();
} else {
dispatch.renderTileEntity(tileentityIn, partialTicks, destroyStage);
}
TileEntityRendererDispatcher.instance.staticPlayerX = playerX;
TileEntityRendererDispatcher.instance.staticPlayerY = playerY;
TileEntityRendererDispatcher.instance.staticPlayerZ = playerZ;
wrapper.wrapping.renderer.inverseTransform(partialTicks);
} catch (Exception e) {
e.printStackTrace();
}
} else {
dispatch.renderTileEntity(tileentityIn, partialTicks, destroyStage);
}
}
use of net.minecraft.util.math.BlockPos in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class EventsClient method onDrawBlockHighlightEventFirst.
@SubscribeEvent(priority = EventPriority.HIGHEST, receiveCanceled = true)
public void onDrawBlockHighlightEventFirst(DrawBlockHighlightEvent event) {
BlockPos pos = Minecraft.getMinecraft().objectMouseOver.getBlockPos();
if (pos != null) {
PhysicsWrapperEntity wrapper = ValkyrienWarfareMod.physicsManager.getObjectManagingPos(Minecraft.getMinecraft().theWorld, pos);
if (wrapper != null && wrapper.wrapping != null && wrapper.wrapping.renderer != null && wrapper.wrapping.centerCoord != null) {
// GL11.glPushMatrix();
float partialTicks = event.getPartialTicks();
Entity player = Minecraft.getMinecraft().thePlayer;
wrapper.wrapping.renderer.setupTranslation(partialTicks);
Tessellator tessellator = Tessellator.getInstance();
VertexBuffer vertexbuffer = tessellator.getBuffer();
double xOff = (player.lastTickPosX + (player.posX - player.lastTickPosX) * (double) partialTicks) - wrapper.wrapping.renderer.offsetPos.getX();
double yOff = (player.lastTickPosY + (player.posY - player.lastTickPosY) * (double) partialTicks) - wrapper.wrapping.renderer.offsetPos.getY();
double zOff = (player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * (double) partialTicks) - wrapper.wrapping.renderer.offsetPos.getZ();
vertexbuffer.xOffset += xOff;
vertexbuffer.yOffset += yOff;
vertexbuffer.zOffset += zOff;
}
}
}
use of net.minecraft.util.math.BlockPos in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class EventsCommon method onRightClickBlock.
@SubscribeEvent()
public void onRightClickBlock(RightClickBlock event) {
if (!event.getWorld().isRemote) {
ItemStack stack = event.getItemStack();
if (stack != null && stack.getItem() instanceof ItemNameTag) {
BlockPos posAt = event.getPos();
EntityPlayer player = event.getEntityPlayer();
World world = event.getWorld();
PhysicsWrapperEntity wrapper = ValkyrienWarfareMod.physicsManager.getObjectManagingPos(world, posAt);
if (wrapper != null) {
wrapper.setCustomNameTag(stack.getDisplayName());
--stack.stackSize;
event.setCanceled(true);
}
}
}
}
Aggregations